2020-03-18 17:24:33 +08:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include "v1_resource_attributes.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
v1_resource_attributes_t *v1_resource_attributes_create(
|
|
|
|
|
char *group,
|
|
|
|
|
char *name,
|
2021-01-05 15:42:34 +08:00
|
|
|
char *_namespace,
|
2020-03-18 17:24:33 +08:00
|
|
|
char *resource,
|
|
|
|
|
char *subresource,
|
|
|
|
|
char *verb,
|
|
|
|
|
char *version
|
|
|
|
|
) {
|
|
|
|
|
v1_resource_attributes_t *v1_resource_attributes_local_var = malloc(sizeof(v1_resource_attributes_t));
|
|
|
|
|
if (!v1_resource_attributes_local_var) {
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
v1_resource_attributes_local_var->group = group;
|
|
|
|
|
v1_resource_attributes_local_var->name = name;
|
2021-01-05 15:42:34 +08:00
|
|
|
v1_resource_attributes_local_var->_namespace = _namespace;
|
2020-03-18 17:24:33 +08:00
|
|
|
v1_resource_attributes_local_var->resource = resource;
|
|
|
|
|
v1_resource_attributes_local_var->subresource = subresource;
|
|
|
|
|
v1_resource_attributes_local_var->verb = verb;
|
|
|
|
|
v1_resource_attributes_local_var->version = version;
|
|
|
|
|
|
|
|
|
|
return v1_resource_attributes_local_var;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void v1_resource_attributes_free(v1_resource_attributes_t *v1_resource_attributes) {
|
|
|
|
|
if(NULL == v1_resource_attributes){
|
|
|
|
|
return ;
|
|
|
|
|
}
|
|
|
|
|
listEntry_t *listEntry;
|
2021-01-05 15:42:34 +08:00
|
|
|
if (v1_resource_attributes->group) {
|
|
|
|
|
free(v1_resource_attributes->group);
|
|
|
|
|
v1_resource_attributes->group = NULL;
|
|
|
|
|
}
|
|
|
|
|
if (v1_resource_attributes->name) {
|
|
|
|
|
free(v1_resource_attributes->name);
|
|
|
|
|
v1_resource_attributes->name = NULL;
|
|
|
|
|
}
|
|
|
|
|
if (v1_resource_attributes->_namespace) {
|
|
|
|
|
free(v1_resource_attributes->_namespace);
|
|
|
|
|
v1_resource_attributes->_namespace = NULL;
|
|
|
|
|
}
|
|
|
|
|
if (v1_resource_attributes->resource) {
|
|
|
|
|
free(v1_resource_attributes->resource);
|
|
|
|
|
v1_resource_attributes->resource = NULL;
|
|
|
|
|
}
|
|
|
|
|
if (v1_resource_attributes->subresource) {
|
|
|
|
|
free(v1_resource_attributes->subresource);
|
|
|
|
|
v1_resource_attributes->subresource = NULL;
|
|
|
|
|
}
|
|
|
|
|
if (v1_resource_attributes->verb) {
|
|
|
|
|
free(v1_resource_attributes->verb);
|
|
|
|
|
v1_resource_attributes->verb = NULL;
|
|
|
|
|
}
|
|
|
|
|
if (v1_resource_attributes->version) {
|
|
|
|
|
free(v1_resource_attributes->version);
|
|
|
|
|
v1_resource_attributes->version = NULL;
|
|
|
|
|
}
|
2020-03-18 17:24:33 +08:00
|
|
|
free(v1_resource_attributes);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cJSON *v1_resource_attributes_convertToJSON(v1_resource_attributes_t *v1_resource_attributes) {
|
|
|
|
|
cJSON *item = cJSON_CreateObject();
|
|
|
|
|
|
|
|
|
|
// v1_resource_attributes->group
|
|
|
|
|
if(v1_resource_attributes->group) {
|
|
|
|
|
if(cJSON_AddStringToObject(item, "group", v1_resource_attributes->group) == NULL) {
|
|
|
|
|
goto fail; //String
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// v1_resource_attributes->name
|
|
|
|
|
if(v1_resource_attributes->name) {
|
|
|
|
|
if(cJSON_AddStringToObject(item, "name", v1_resource_attributes->name) == NULL) {
|
|
|
|
|
goto fail; //String
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2021-01-05 15:42:34 +08:00
|
|
|
// v1_resource_attributes->_namespace
|
|
|
|
|
if(v1_resource_attributes->_namespace) {
|
|
|
|
|
if(cJSON_AddStringToObject(item, "namespace", v1_resource_attributes->_namespace) == NULL) {
|
2020-03-18 17:24:33 +08:00
|
|
|
goto fail; //String
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// v1_resource_attributes->resource
|
|
|
|
|
if(v1_resource_attributes->resource) {
|
|
|
|
|
if(cJSON_AddStringToObject(item, "resource", v1_resource_attributes->resource) == NULL) {
|
|
|
|
|
goto fail; //String
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// v1_resource_attributes->subresource
|
|
|
|
|
if(v1_resource_attributes->subresource) {
|
|
|
|
|
if(cJSON_AddStringToObject(item, "subresource", v1_resource_attributes->subresource) == NULL) {
|
|
|
|
|
goto fail; //String
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// v1_resource_attributes->verb
|
|
|
|
|
if(v1_resource_attributes->verb) {
|
|
|
|
|
if(cJSON_AddStringToObject(item, "verb", v1_resource_attributes->verb) == NULL) {
|
|
|
|
|
goto fail; //String
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// v1_resource_attributes->version
|
|
|
|
|
if(v1_resource_attributes->version) {
|
|
|
|
|
if(cJSON_AddStringToObject(item, "version", v1_resource_attributes->version) == NULL) {
|
|
|
|
|
goto fail; //String
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return item;
|
|
|
|
|
fail:
|
|
|
|
|
if (item) {
|
|
|
|
|
cJSON_Delete(item);
|
|
|
|
|
}
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
v1_resource_attributes_t *v1_resource_attributes_parseFromJSON(cJSON *v1_resource_attributesJSON){
|
|
|
|
|
|
|
|
|
|
v1_resource_attributes_t *v1_resource_attributes_local_var = NULL;
|
|
|
|
|
|
|
|
|
|
// v1_resource_attributes->group
|
|
|
|
|
cJSON *group = cJSON_GetObjectItemCaseSensitive(v1_resource_attributesJSON, "group");
|
|
|
|
|
if (group) {
|
|
|
|
|
if(!cJSON_IsString(group))
|
|
|
|
|
{
|
|
|
|
|
goto end; //String
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// v1_resource_attributes->name
|
|
|
|
|
cJSON *name = cJSON_GetObjectItemCaseSensitive(v1_resource_attributesJSON, "name");
|
|
|
|
|
if (name) {
|
|
|
|
|
if(!cJSON_IsString(name))
|
|
|
|
|
{
|
|
|
|
|
goto end; //String
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-05 15:42:34 +08:00
|
|
|
// v1_resource_attributes->_namespace
|
|
|
|
|
cJSON *_namespace = cJSON_GetObjectItemCaseSensitive(v1_resource_attributesJSON, "namespace");
|
|
|
|
|
if (_namespace) {
|
|
|
|
|
if(!cJSON_IsString(_namespace))
|
2020-03-18 17:24:33 +08:00
|
|
|
{
|
|
|
|
|
goto end; //String
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// v1_resource_attributes->resource
|
|
|
|
|
cJSON *resource = cJSON_GetObjectItemCaseSensitive(v1_resource_attributesJSON, "resource");
|
|
|
|
|
if (resource) {
|
|
|
|
|
if(!cJSON_IsString(resource))
|
|
|
|
|
{
|
|
|
|
|
goto end; //String
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// v1_resource_attributes->subresource
|
|
|
|
|
cJSON *subresource = cJSON_GetObjectItemCaseSensitive(v1_resource_attributesJSON, "subresource");
|
|
|
|
|
if (subresource) {
|
|
|
|
|
if(!cJSON_IsString(subresource))
|
|
|
|
|
{
|
|
|
|
|
goto end; //String
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// v1_resource_attributes->verb
|
|
|
|
|
cJSON *verb = cJSON_GetObjectItemCaseSensitive(v1_resource_attributesJSON, "verb");
|
|
|
|
|
if (verb) {
|
|
|
|
|
if(!cJSON_IsString(verb))
|
|
|
|
|
{
|
|
|
|
|
goto end; //String
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// v1_resource_attributes->version
|
|
|
|
|
cJSON *version = cJSON_GetObjectItemCaseSensitive(v1_resource_attributesJSON, "version");
|
|
|
|
|
if (version) {
|
|
|
|
|
if(!cJSON_IsString(version))
|
|
|
|
|
{
|
|
|
|
|
goto end; //String
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
v1_resource_attributes_local_var = v1_resource_attributes_create (
|
|
|
|
|
group ? strdup(group->valuestring) : NULL,
|
|
|
|
|
name ? strdup(name->valuestring) : NULL,
|
2021-01-05 15:42:34 +08:00
|
|
|
_namespace ? strdup(_namespace->valuestring) : NULL,
|
2020-03-18 17:24:33 +08:00
|
|
|
resource ? strdup(resource->valuestring) : NULL,
|
|
|
|
|
subresource ? strdup(subresource->valuestring) : NULL,
|
|
|
|
|
verb ? strdup(verb->valuestring) : NULL,
|
|
|
|
|
version ? strdup(version->valuestring) : NULL
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return v1_resource_attributes_local_var;
|
|
|
|
|
end:
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
}
|