Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check cJSON_IsNull when the data type is datetime #157

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions examples/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ all:
cd exec_pod; make
cd list_secret; make
cd configmap; make
cd list_event; make

clean:
cd create_pod; make clean
Expand All @@ -25,6 +26,7 @@ clean:
cd exec_pod; make clean
cd list_secret; make clean
cd configmap; make clean
cd list_event; make clean

test:
cd create_pod; make test;
Expand All @@ -34,6 +36,7 @@ test:
kubectl wait --for=delete pod/test-pod-6 -n default --timeout=120s
cd list_secret; make test
cd configmap; make test
cd list_event; make test
cd generic; make test
cd multi_thread; make test;
kubectl wait --for=condition=ready pod/test-pod-8 -n default --timeout=60s
Expand All @@ -48,6 +51,7 @@ memcheck:
kubectl wait --for=delete pod/test-pod-6 -n default --timeout=120s
cd list_secret; make memcheck
cd configmap; make memcheck
cd list_event; make test
cd generic; make memcheck
cd multi_thread; make memcheck;
kubectl wait --for=condition=ready pod/test-pod-8 -n default --timeout=60s
Expand Down
1 change: 1 addition & 0 deletions examples/list_event/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
list_event_bin
17 changes: 17 additions & 0 deletions examples/list_event/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
INCLUDE:=-I../../kubernetes/
LIBS:=-L../../kubernetes/build -lyaml -lwebsockets -lkubernetes -L/usr/local/lib
CFLAGS:=-g
BIN:=list_event_bin

.PHONY : all clean test memcheck
all:
gcc main.c $(CFLAGS) $(INCLUDE) $(LIBS) -o $(BIN)

test:
./$(BIN)

memcheck:
valgrind --tool=memcheck --leak-check=full ./$(BIN)

clean:
rm ./$(BIN)
76 changes: 76 additions & 0 deletions examples/list_event/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#include <config/kube_config.h>
#include <api/CoreV1API.h>
#include <stdio.h>

#include <config/kube_config.h>
#include <api/CoreV1API.h>
#include <stdio.h>

void list_event(apiClient_t * apiClient)
{
core_v1_event_list_t *event_list = CoreV1API_listNamespacedEvent(apiClient, "default", /*namespace */
"true", /* pretty */
0, /* allowWatchBookmarks */
NULL, /* continue */
NULL, /* fieldSelector */
NULL, /* labelSelector */
0, /* limit */
NULL, /* resourceVersion */
NULL, /* resourceVersionMatch */
0, /* timeoutSeconds */
0 /* watch */
);
printf("The return code of HTTP request=%ld\n", apiClient->response_code);
if (event_list) {
if (event_list->items) {
listEntry_t *listEntry = NULL;
core_v1_event_t *event = NULL;
list_ForEach(listEntry, event_list->items) {
event = listEntry->data;
if (event) {
if (event->type) {
printf("Event Type: %s\n", event->type);
}
if (event->message) {
printf("Event Message: %s\n", event->message);
}
}
}
} else {
fprintf(stderr, "There are no events in event list.\n");
}
core_v1_event_list_free(event_list);
event_list = NULL;
} else {
fprintf(stderr, "Cannot get event list.\n");
}
}

int main()
{
char *basePath = NULL;
sslConfig_t *sslConfig = NULL;
list_t *apiKeys = NULL;
int rc = load_kube_config(&basePath, &sslConfig, &apiKeys, NULL); /* NULL means loading configuration from $HOME/.kube/config */
if (rc != 0) {
fprintf(stderr, "Cannot load kubernetes configuration.\n");
return -1;
}
apiClient_t *apiClient = apiClient_create_with_base_path(basePath, sslConfig, apiKeys);
if (!apiClient) {
fprintf(stderr, "Cannot create a kubernetes client.\n");
return -1;
}

list_event(apiClient);

apiClient_free(apiClient);
apiClient = NULL;
free_client_config(basePath, sslConfig, apiKeys);
basePath = NULL;
sslConfig = NULL;
apiKeys = NULL;
apiClient_unsetupGlobalEnv();

return 0;
}
12 changes: 6 additions & 6 deletions kubernetes/model/core_v1_event.c
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ core_v1_event_t *core_v1_event_parseFromJSON(cJSON *core_v1_eventJSON){
// core_v1_event->event_time
cJSON *event_time = cJSON_GetObjectItemCaseSensitive(core_v1_eventJSON, "eventTime");
if (event_time) {
if(!cJSON_IsString(event_time))
if(!cJSON_IsString(event_time) && !cJSON_IsNull(event_time))
{
goto end; //DateTime
}
Expand All @@ -353,7 +353,7 @@ core_v1_event_t *core_v1_event_parseFromJSON(cJSON *core_v1_eventJSON){
// core_v1_event->first_timestamp
cJSON *first_timestamp = cJSON_GetObjectItemCaseSensitive(core_v1_eventJSON, "firstTimestamp");
if (first_timestamp) {
if(!cJSON_IsString(first_timestamp))
if(!cJSON_IsString(first_timestamp) && !cJSON_IsNull(first_timestamp))
{
goto end; //DateTime
}
Expand All @@ -380,7 +380,7 @@ core_v1_event_t *core_v1_event_parseFromJSON(cJSON *core_v1_eventJSON){
// core_v1_event->last_timestamp
cJSON *last_timestamp = cJSON_GetObjectItemCaseSensitive(core_v1_eventJSON, "lastTimestamp");
if (last_timestamp) {
if(!cJSON_IsString(last_timestamp))
if(!cJSON_IsString(last_timestamp) && !cJSON_IsNull(last_timestamp))
{
goto end; //DateTime
}
Expand Down Expand Up @@ -463,11 +463,11 @@ core_v1_event_t *core_v1_event_parseFromJSON(cJSON *core_v1_eventJSON){
action ? strdup(action->valuestring) : NULL,
api_version ? strdup(api_version->valuestring) : NULL,
count ? count->valuedouble : 0,
event_time ? strdup(event_time->valuestring) : NULL,
first_timestamp ? strdup(first_timestamp->valuestring) : NULL,
event_time && !cJSON_IsNull(event_time) ? strdup(event_time->valuestring) : NULL,
first_timestamp && !cJSON_IsNull(first_timestamp) ? strdup(first_timestamp->valuestring) : NULL,
involved_object_local_nonprim,
kind ? strdup(kind->valuestring) : NULL,
last_timestamp ? strdup(last_timestamp->valuestring) : NULL,
last_timestamp && !cJSON_IsNull(last_timestamp) ? strdup(last_timestamp->valuestring) : NULL,
message ? strdup(message->valuestring) : NULL,
metadata_local_nonprim,
reason ? strdup(reason->valuestring) : NULL,
Expand Down
4 changes: 2 additions & 2 deletions kubernetes/model/core_v1_event_series.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ core_v1_event_series_t *core_v1_event_series_parseFromJSON(cJSON *core_v1_event_
// core_v1_event_series->last_observed_time
cJSON *last_observed_time = cJSON_GetObjectItemCaseSensitive(core_v1_event_seriesJSON, "lastObservedTime");
if (last_observed_time) {
if(!cJSON_IsString(last_observed_time))
if(!cJSON_IsString(last_observed_time) && !cJSON_IsNull(last_observed_time))
{
goto end; //DateTime
}
Expand All @@ -83,7 +83,7 @@ core_v1_event_series_t *core_v1_event_series_parseFromJSON(cJSON *core_v1_event_

core_v1_event_series_local_var = core_v1_event_series_create (
count ? count->valuedouble : 0,
last_observed_time ? strdup(last_observed_time->valuestring) : NULL
last_observed_time && !cJSON_IsNull(last_observed_time) ? strdup(last_observed_time->valuestring) : NULL
);

return core_v1_event_series_local_var;
Expand Down
10 changes: 5 additions & 5 deletions kubernetes/model/events_v1_event.c
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ events_v1_event_t *events_v1_event_parseFromJSON(cJSON *events_v1_eventJSON){
// events_v1_event->deprecated_first_timestamp
cJSON *deprecated_first_timestamp = cJSON_GetObjectItemCaseSensitive(events_v1_eventJSON, "deprecatedFirstTimestamp");
if (deprecated_first_timestamp) {
if(!cJSON_IsString(deprecated_first_timestamp))
if(!cJSON_IsString(deprecated_first_timestamp) && !cJSON_IsNull(deprecated_first_timestamp))
{
goto end; //DateTime
}
Expand All @@ -352,7 +352,7 @@ events_v1_event_t *events_v1_event_parseFromJSON(cJSON *events_v1_eventJSON){
// events_v1_event->deprecated_last_timestamp
cJSON *deprecated_last_timestamp = cJSON_GetObjectItemCaseSensitive(events_v1_eventJSON, "deprecatedLastTimestamp");
if (deprecated_last_timestamp) {
if(!cJSON_IsString(deprecated_last_timestamp))
if(!cJSON_IsString(deprecated_last_timestamp) && !cJSON_IsNull(deprecated_last_timestamp))
{
goto end; //DateTime
}
Expand All @@ -371,7 +371,7 @@ events_v1_event_t *events_v1_event_parseFromJSON(cJSON *events_v1_eventJSON){
}


if(!cJSON_IsString(event_time))
if(!cJSON_IsString(event_time) && !cJSON_IsNull(event_time))
{
goto end; //DateTime
}
Expand Down Expand Up @@ -459,8 +459,8 @@ events_v1_event_t *events_v1_event_parseFromJSON(cJSON *events_v1_eventJSON){
action ? strdup(action->valuestring) : NULL,
api_version ? strdup(api_version->valuestring) : NULL,
deprecated_count ? deprecated_count->valuedouble : 0,
deprecated_first_timestamp ? strdup(deprecated_first_timestamp->valuestring) : NULL,
deprecated_last_timestamp ? strdup(deprecated_last_timestamp->valuestring) : NULL,
deprecated_first_timestamp && !cJSON_IsNull(deprecated_first_timestamp) ? strdup(deprecated_first_timestamp->valuestring) : NULL,
deprecated_last_timestamp && !cJSON_IsNull(deprecated_last_timestamp) ? strdup(deprecated_last_timestamp->valuestring) : NULL,
deprecated_source ? deprecated_source_local_nonprim : NULL,
strdup(event_time->valuestring),
kind ? strdup(kind->valuestring) : NULL,
Expand Down
2 changes: 1 addition & 1 deletion kubernetes/model/events_v1_event_series.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ events_v1_event_series_t *events_v1_event_series_parseFromJSON(cJSON *events_v1_
}


if(!cJSON_IsString(last_observed_time))
if(!cJSON_IsString(last_observed_time) && !cJSON_IsNull(last_observed_time))
{
goto end; //DateTime
}
Expand Down
4 changes: 2 additions & 2 deletions kubernetes/model/v1_api_service_condition.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ v1_api_service_condition_t *v1_api_service_condition_parseFromJSON(cJSON *v1_api
// v1_api_service_condition->last_transition_time
cJSON *last_transition_time = cJSON_GetObjectItemCaseSensitive(v1_api_service_conditionJSON, "lastTransitionTime");
if (last_transition_time) {
if(!cJSON_IsString(last_transition_time))
if(!cJSON_IsString(last_transition_time) && !cJSON_IsNull(last_transition_time))
{
goto end; //DateTime
}
Expand Down Expand Up @@ -163,7 +163,7 @@ v1_api_service_condition_t *v1_api_service_condition_parseFromJSON(cJSON *v1_api


v1_api_service_condition_local_var = v1_api_service_condition_create (
last_transition_time ? strdup(last_transition_time->valuestring) : NULL,
last_transition_time && !cJSON_IsNull(last_transition_time) ? strdup(last_transition_time->valuestring) : NULL,
message ? strdup(message->valuestring) : NULL,
reason ? strdup(reason->valuestring) : NULL,
strdup(status->valuestring),
Expand Down
8 changes: 4 additions & 4 deletions kubernetes/model/v1_certificate_signing_request_condition.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ v1_certificate_signing_request_condition_t *v1_certificate_signing_request_condi
// v1_certificate_signing_request_condition->last_transition_time
cJSON *last_transition_time = cJSON_GetObjectItemCaseSensitive(v1_certificate_signing_request_conditionJSON, "lastTransitionTime");
if (last_transition_time) {
if(!cJSON_IsString(last_transition_time))
if(!cJSON_IsString(last_transition_time) && !cJSON_IsNull(last_transition_time))
{
goto end; //DateTime
}
Expand All @@ -136,7 +136,7 @@ v1_certificate_signing_request_condition_t *v1_certificate_signing_request_condi
// v1_certificate_signing_request_condition->last_update_time
cJSON *last_update_time = cJSON_GetObjectItemCaseSensitive(v1_certificate_signing_request_conditionJSON, "lastUpdateTime");
if (last_update_time) {
if(!cJSON_IsString(last_update_time))
if(!cJSON_IsString(last_update_time) && !cJSON_IsNull(last_update_time))
{
goto end; //DateTime
}
Expand Down Expand Up @@ -186,8 +186,8 @@ v1_certificate_signing_request_condition_t *v1_certificate_signing_request_condi


v1_certificate_signing_request_condition_local_var = v1_certificate_signing_request_condition_create (
last_transition_time ? strdup(last_transition_time->valuestring) : NULL,
last_update_time ? strdup(last_update_time->valuestring) : NULL,
last_transition_time && !cJSON_IsNull(last_transition_time) ? strdup(last_transition_time->valuestring) : NULL,
last_update_time && !cJSON_IsNull(last_update_time) ? strdup(last_update_time->valuestring) : NULL,
message ? strdup(message->valuestring) : NULL,
reason ? strdup(reason->valuestring) : NULL,
strdup(status->valuestring),
Expand Down
2 changes: 1 addition & 1 deletion kubernetes/model/v1_condition.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ v1_condition_t *v1_condition_parseFromJSON(cJSON *v1_conditionJSON){
}


if(!cJSON_IsString(last_transition_time))
if(!cJSON_IsString(last_transition_time) && !cJSON_IsNull(last_transition_time))
{
goto end; //DateTime
}
Expand Down
4 changes: 2 additions & 2 deletions kubernetes/model/v1_container_state_running.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,15 @@ v1_container_state_running_t *v1_container_state_running_parseFromJSON(cJSON *v1
// v1_container_state_running->started_at
cJSON *started_at = cJSON_GetObjectItemCaseSensitive(v1_container_state_runningJSON, "startedAt");
if (started_at) {
if(!cJSON_IsString(started_at))
if(!cJSON_IsString(started_at) && !cJSON_IsNull(started_at))
{
goto end; //DateTime
}
}


v1_container_state_running_local_var = v1_container_state_running_create (
started_at ? strdup(started_at->valuestring) : NULL
started_at && !cJSON_IsNull(started_at) ? strdup(started_at->valuestring) : NULL
);

return v1_container_state_running_local_var;
Expand Down
8 changes: 4 additions & 4 deletions kubernetes/model/v1_container_state_terminated.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ v1_container_state_terminated_t *v1_container_state_terminated_parseFromJSON(cJS
// v1_container_state_terminated->finished_at
cJSON *finished_at = cJSON_GetObjectItemCaseSensitive(v1_container_state_terminatedJSON, "finishedAt");
if (finished_at) {
if(!cJSON_IsString(finished_at))
if(!cJSON_IsString(finished_at) && !cJSON_IsNull(finished_at))
{
goto end; //DateTime
}
Expand Down Expand Up @@ -189,7 +189,7 @@ v1_container_state_terminated_t *v1_container_state_terminated_parseFromJSON(cJS
// v1_container_state_terminated->started_at
cJSON *started_at = cJSON_GetObjectItemCaseSensitive(v1_container_state_terminatedJSON, "startedAt");
if (started_at) {
if(!cJSON_IsString(started_at))
if(!cJSON_IsString(started_at) && !cJSON_IsNull(started_at))
{
goto end; //DateTime
}
Expand All @@ -199,11 +199,11 @@ v1_container_state_terminated_t *v1_container_state_terminated_parseFromJSON(cJS
v1_container_state_terminated_local_var = v1_container_state_terminated_create (
container_id ? strdup(container_id->valuestring) : NULL,
exit_code->valuedouble,
finished_at ? strdup(finished_at->valuestring) : NULL,
finished_at && !cJSON_IsNull(finished_at) ? strdup(finished_at->valuestring) : NULL,
message ? strdup(message->valuestring) : NULL,
reason ? strdup(reason->valuestring) : NULL,
signal ? signal->valuedouble : 0,
started_at ? strdup(started_at->valuestring) : NULL
started_at && !cJSON_IsNull(started_at) ? strdup(started_at->valuestring) : NULL
);

return v1_container_state_terminated_local_var;
Expand Down
8 changes: 4 additions & 4 deletions kubernetes/model/v1_cron_job_status.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ v1_cron_job_status_t *v1_cron_job_status_parseFromJSON(cJSON *v1_cron_job_status
// v1_cron_job_status->last_schedule_time
cJSON *last_schedule_time = cJSON_GetObjectItemCaseSensitive(v1_cron_job_statusJSON, "lastScheduleTime");
if (last_schedule_time) {
if(!cJSON_IsString(last_schedule_time))
if(!cJSON_IsString(last_schedule_time) && !cJSON_IsNull(last_schedule_time))
{
goto end; //DateTime
}
Expand All @@ -131,7 +131,7 @@ v1_cron_job_status_t *v1_cron_job_status_parseFromJSON(cJSON *v1_cron_job_status
// v1_cron_job_status->last_successful_time
cJSON *last_successful_time = cJSON_GetObjectItemCaseSensitive(v1_cron_job_statusJSON, "lastSuccessfulTime");
if (last_successful_time) {
if(!cJSON_IsString(last_successful_time))
if(!cJSON_IsString(last_successful_time) && !cJSON_IsNull(last_successful_time))
{
goto end; //DateTime
}
Expand All @@ -140,8 +140,8 @@ v1_cron_job_status_t *v1_cron_job_status_parseFromJSON(cJSON *v1_cron_job_status

v1_cron_job_status_local_var = v1_cron_job_status_create (
active ? activeList : NULL,
last_schedule_time ? strdup(last_schedule_time->valuestring) : NULL,
last_successful_time ? strdup(last_successful_time->valuestring) : NULL
last_schedule_time && !cJSON_IsNull(last_schedule_time) ? strdup(last_schedule_time->valuestring) : NULL,
last_successful_time && !cJSON_IsNull(last_successful_time) ? strdup(last_successful_time->valuestring) : NULL
);

return v1_cron_job_status_local_var;
Expand Down
4 changes: 2 additions & 2 deletions kubernetes/model/v1_custom_resource_definition_condition.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ v1_custom_resource_definition_condition_t *v1_custom_resource_definition_conditi
// v1_custom_resource_definition_condition->last_transition_time
cJSON *last_transition_time = cJSON_GetObjectItemCaseSensitive(v1_custom_resource_definition_conditionJSON, "lastTransitionTime");
if (last_transition_time) {
if(!cJSON_IsString(last_transition_time))
if(!cJSON_IsString(last_transition_time) && !cJSON_IsNull(last_transition_time))
{
goto end; //DateTime
}
Expand Down Expand Up @@ -163,7 +163,7 @@ v1_custom_resource_definition_condition_t *v1_custom_resource_definition_conditi


v1_custom_resource_definition_condition_local_var = v1_custom_resource_definition_condition_create (
last_transition_time ? strdup(last_transition_time->valuestring) : NULL,
last_transition_time && !cJSON_IsNull(last_transition_time) ? strdup(last_transition_time->valuestring) : NULL,
message ? strdup(message->valuestring) : NULL,
reason ? strdup(reason->valuestring) : NULL,
strdup(status->valuestring),
Expand Down
Loading