2020-03-18 17:24:33 +08:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include "v1_api_group_list.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
v1_api_group_list_t *v1_api_group_list_create(
|
|
|
|
|
char *api_version,
|
|
|
|
|
list_t *groups,
|
|
|
|
|
char *kind
|
|
|
|
|
) {
|
|
|
|
|
v1_api_group_list_t *v1_api_group_list_local_var = malloc(sizeof(v1_api_group_list_t));
|
|
|
|
|
if (!v1_api_group_list_local_var) {
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
v1_api_group_list_local_var->api_version = api_version;
|
|
|
|
|
v1_api_group_list_local_var->groups = groups;
|
|
|
|
|
v1_api_group_list_local_var->kind = kind;
|
|
|
|
|
|
|
|
|
|
return v1_api_group_list_local_var;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void v1_api_group_list_free(v1_api_group_list_t *v1_api_group_list) {
|
|
|
|
|
if(NULL == v1_api_group_list){
|
|
|
|
|
return ;
|
|
|
|
|
}
|
|
|
|
|
listEntry_t *listEntry;
|
2021-01-05 15:42:34 +08:00
|
|
|
if (v1_api_group_list->api_version) {
|
|
|
|
|
free(v1_api_group_list->api_version);
|
|
|
|
|
v1_api_group_list->api_version = NULL;
|
|
|
|
|
}
|
|
|
|
|
if (v1_api_group_list->groups) {
|
|
|
|
|
list_ForEach(listEntry, v1_api_group_list->groups) {
|
|
|
|
|
v1_api_group_free(listEntry->data);
|
|
|
|
|
}
|
2022-03-09 10:56:53 +08:00
|
|
|
list_freeList(v1_api_group_list->groups);
|
2021-01-05 15:42:34 +08:00
|
|
|
v1_api_group_list->groups = NULL;
|
|
|
|
|
}
|
|
|
|
|
if (v1_api_group_list->kind) {
|
|
|
|
|
free(v1_api_group_list->kind);
|
|
|
|
|
v1_api_group_list->kind = NULL;
|
2020-03-18 17:24:33 +08:00
|
|
|
}
|
|
|
|
|
free(v1_api_group_list);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cJSON *v1_api_group_list_convertToJSON(v1_api_group_list_t *v1_api_group_list) {
|
|
|
|
|
cJSON *item = cJSON_CreateObject();
|
|
|
|
|
|
|
|
|
|
// v1_api_group_list->api_version
|
2022-04-18 09:29:02 +08:00
|
|
|
if(v1_api_group_list->api_version) {
|
2020-03-18 17:24:33 +08:00
|
|
|
if(cJSON_AddStringToObject(item, "apiVersion", v1_api_group_list->api_version) == NULL) {
|
|
|
|
|
goto fail; //String
|
|
|
|
|
}
|
2022-04-18 09:29:02 +08:00
|
|
|
}
|
2020-03-18 17:24:33 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
// v1_api_group_list->groups
|
|
|
|
|
if (!v1_api_group_list->groups) {
|
|
|
|
|
goto fail;
|
|
|
|
|
}
|
|
|
|
|
cJSON *groups = cJSON_AddArrayToObject(item, "groups");
|
|
|
|
|
if(groups == NULL) {
|
|
|
|
|
goto fail; //nonprimitive container
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
listEntry_t *groupsListEntry;
|
|
|
|
|
if (v1_api_group_list->groups) {
|
|
|
|
|
list_ForEach(groupsListEntry, v1_api_group_list->groups) {
|
|
|
|
|
cJSON *itemLocal = v1_api_group_convertToJSON(groupsListEntry->data);
|
|
|
|
|
if(itemLocal == NULL) {
|
|
|
|
|
goto fail;
|
|
|
|
|
}
|
|
|
|
|
cJSON_AddItemToArray(groups, itemLocal);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// v1_api_group_list->kind
|
2022-04-18 09:29:02 +08:00
|
|
|
if(v1_api_group_list->kind) {
|
2020-03-18 17:24:33 +08:00
|
|
|
if(cJSON_AddStringToObject(item, "kind", v1_api_group_list->kind) == NULL) {
|
|
|
|
|
goto fail; //String
|
|
|
|
|
}
|
2022-04-18 09:29:02 +08:00
|
|
|
}
|
2020-03-18 17:24:33 +08:00
|
|
|
|
|
|
|
|
return item;
|
|
|
|
|
fail:
|
|
|
|
|
if (item) {
|
|
|
|
|
cJSON_Delete(item);
|
|
|
|
|
}
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
v1_api_group_list_t *v1_api_group_list_parseFromJSON(cJSON *v1_api_group_listJSON){
|
|
|
|
|
|
|
|
|
|
v1_api_group_list_t *v1_api_group_list_local_var = NULL;
|
|
|
|
|
|
2022-03-29 10:12:05 +08:00
|
|
|
// define the local list for v1_api_group_list->groups
|
|
|
|
|
list_t *groupsList = NULL;
|
|
|
|
|
|
2020-03-18 17:24:33 +08:00
|
|
|
// v1_api_group_list->api_version
|
|
|
|
|
cJSON *api_version = cJSON_GetObjectItemCaseSensitive(v1_api_group_listJSON, "apiVersion");
|
|
|
|
|
if (api_version) {
|
2022-12-29 10:58:47 +08:00
|
|
|
if(!cJSON_IsString(api_version) && !cJSON_IsNull(api_version))
|
2020-03-18 17:24:33 +08:00
|
|
|
{
|
|
|
|
|
goto end; //String
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// v1_api_group_list->groups
|
|
|
|
|
cJSON *groups = cJSON_GetObjectItemCaseSensitive(v1_api_group_listJSON, "groups");
|
|
|
|
|
if (!groups) {
|
|
|
|
|
goto end;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2022-03-29 10:12:05 +08:00
|
|
|
cJSON *groups_local_nonprimitive = NULL;
|
2020-03-18 17:24:33 +08:00
|
|
|
if(!cJSON_IsArray(groups)){
|
|
|
|
|
goto end; //nonprimitive container
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-09 10:56:53 +08:00
|
|
|
groupsList = list_createList();
|
2020-03-18 17:24:33 +08:00
|
|
|
|
|
|
|
|
cJSON_ArrayForEach(groups_local_nonprimitive,groups )
|
|
|
|
|
{
|
|
|
|
|
if(!cJSON_IsObject(groups_local_nonprimitive)){
|
|
|
|
|
goto end;
|
|
|
|
|
}
|
|
|
|
|
v1_api_group_t *groupsItem = v1_api_group_parseFromJSON(groups_local_nonprimitive);
|
|
|
|
|
|
|
|
|
|
list_addElement(groupsList, groupsItem);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// v1_api_group_list->kind
|
|
|
|
|
cJSON *kind = cJSON_GetObjectItemCaseSensitive(v1_api_group_listJSON, "kind");
|
|
|
|
|
if (kind) {
|
2022-12-29 10:58:47 +08:00
|
|
|
if(!cJSON_IsString(kind) && !cJSON_IsNull(kind))
|
2020-03-18 17:24:33 +08:00
|
|
|
{
|
|
|
|
|
goto end; //String
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
v1_api_group_list_local_var = v1_api_group_list_create (
|
2022-12-29 10:58:47 +08:00
|
|
|
api_version && !cJSON_IsNull(api_version) ? strdup(api_version->valuestring) : NULL,
|
2020-03-18 17:24:33 +08:00
|
|
|
groupsList,
|
2022-12-29 10:58:47 +08:00
|
|
|
kind && !cJSON_IsNull(kind) ? strdup(kind->valuestring) : NULL
|
2020-03-18 17:24:33 +08:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return v1_api_group_list_local_var;
|
|
|
|
|
end:
|
2022-03-29 10:12:05 +08:00
|
|
|
if (groupsList) {
|
|
|
|
|
listEntry_t *listEntry = NULL;
|
|
|
|
|
list_ForEach(listEntry, groupsList) {
|
|
|
|
|
v1_api_group_free(listEntry->data);
|
|
|
|
|
listEntry->data = NULL;
|
|
|
|
|
}
|
|
|
|
|
list_freeList(groupsList);
|
|
|
|
|
groupsList = NULL;
|
|
|
|
|
}
|
2020-03-18 17:24:33 +08:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
}
|