2020-03-18 17:24:33 +08:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include "v1_volume_attachment_source.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
v1_volume_attachment_source_t *v1_volume_attachment_source_create(
|
|
|
|
|
v1_persistent_volume_spec_t *inline_volume_spec,
|
|
|
|
|
char *persistent_volume_name
|
|
|
|
|
) {
|
|
|
|
|
v1_volume_attachment_source_t *v1_volume_attachment_source_local_var = malloc(sizeof(v1_volume_attachment_source_t));
|
|
|
|
|
if (!v1_volume_attachment_source_local_var) {
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
v1_volume_attachment_source_local_var->inline_volume_spec = inline_volume_spec;
|
|
|
|
|
v1_volume_attachment_source_local_var->persistent_volume_name = persistent_volume_name;
|
|
|
|
|
|
|
|
|
|
return v1_volume_attachment_source_local_var;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void v1_volume_attachment_source_free(v1_volume_attachment_source_t *v1_volume_attachment_source) {
|
|
|
|
|
if(NULL == v1_volume_attachment_source){
|
|
|
|
|
return ;
|
|
|
|
|
}
|
|
|
|
|
listEntry_t *listEntry;
|
2021-01-05 15:42:34 +08:00
|
|
|
if (v1_volume_attachment_source->inline_volume_spec) {
|
|
|
|
|
v1_persistent_volume_spec_free(v1_volume_attachment_source->inline_volume_spec);
|
|
|
|
|
v1_volume_attachment_source->inline_volume_spec = NULL;
|
|
|
|
|
}
|
|
|
|
|
if (v1_volume_attachment_source->persistent_volume_name) {
|
|
|
|
|
free(v1_volume_attachment_source->persistent_volume_name);
|
|
|
|
|
v1_volume_attachment_source->persistent_volume_name = NULL;
|
|
|
|
|
}
|
2020-03-18 17:24:33 +08:00
|
|
|
free(v1_volume_attachment_source);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cJSON *v1_volume_attachment_source_convertToJSON(v1_volume_attachment_source_t *v1_volume_attachment_source) {
|
|
|
|
|
cJSON *item = cJSON_CreateObject();
|
|
|
|
|
|
|
|
|
|
// v1_volume_attachment_source->inline_volume_spec
|
2022-04-18 09:29:02 +08:00
|
|
|
if(v1_volume_attachment_source->inline_volume_spec) {
|
2020-03-18 17:24:33 +08:00
|
|
|
cJSON *inline_volume_spec_local_JSON = v1_persistent_volume_spec_convertToJSON(v1_volume_attachment_source->inline_volume_spec);
|
|
|
|
|
if(inline_volume_spec_local_JSON == NULL) {
|
|
|
|
|
goto fail; //model
|
|
|
|
|
}
|
|
|
|
|
cJSON_AddItemToObject(item, "inlineVolumeSpec", inline_volume_spec_local_JSON);
|
|
|
|
|
if(item->child == NULL) {
|
|
|
|
|
goto fail;
|
|
|
|
|
}
|
2022-04-18 09:29:02 +08:00
|
|
|
}
|
2020-03-18 17:24:33 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
// v1_volume_attachment_source->persistent_volume_name
|
2022-04-18 09:29:02 +08:00
|
|
|
if(v1_volume_attachment_source->persistent_volume_name) {
|
2020-03-18 17:24:33 +08:00
|
|
|
if(cJSON_AddStringToObject(item, "persistentVolumeName", v1_volume_attachment_source->persistent_volume_name) == 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_volume_attachment_source_t *v1_volume_attachment_source_parseFromJSON(cJSON *v1_volume_attachment_sourceJSON){
|
|
|
|
|
|
|
|
|
|
v1_volume_attachment_source_t *v1_volume_attachment_source_local_var = NULL;
|
|
|
|
|
|
2021-11-05 14:13:35 +08:00
|
|
|
// define the local variable for v1_volume_attachment_source->inline_volume_spec
|
|
|
|
|
v1_persistent_volume_spec_t *inline_volume_spec_local_nonprim = NULL;
|
|
|
|
|
|
2020-03-18 17:24:33 +08:00
|
|
|
// v1_volume_attachment_source->inline_volume_spec
|
|
|
|
|
cJSON *inline_volume_spec = cJSON_GetObjectItemCaseSensitive(v1_volume_attachment_sourceJSON, "inlineVolumeSpec");
|
|
|
|
|
if (inline_volume_spec) {
|
|
|
|
|
inline_volume_spec_local_nonprim = v1_persistent_volume_spec_parseFromJSON(inline_volume_spec); //nonprimitive
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// v1_volume_attachment_source->persistent_volume_name
|
|
|
|
|
cJSON *persistent_volume_name = cJSON_GetObjectItemCaseSensitive(v1_volume_attachment_sourceJSON, "persistentVolumeName");
|
|
|
|
|
if (persistent_volume_name) {
|
2022-12-29 10:58:47 +08:00
|
|
|
if(!cJSON_IsString(persistent_volume_name) && !cJSON_IsNull(persistent_volume_name))
|
2020-03-18 17:24:33 +08:00
|
|
|
{
|
|
|
|
|
goto end; //String
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
v1_volume_attachment_source_local_var = v1_volume_attachment_source_create (
|
|
|
|
|
inline_volume_spec ? inline_volume_spec_local_nonprim : NULL,
|
2022-12-29 10:58:47 +08:00
|
|
|
persistent_volume_name && !cJSON_IsNull(persistent_volume_name) ? strdup(persistent_volume_name->valuestring) : NULL
|
2020-03-18 17:24:33 +08:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return v1_volume_attachment_source_local_var;
|
|
|
|
|
end:
|
2021-01-11 12:15:24 +08:00
|
|
|
if (inline_volume_spec_local_nonprim) {
|
|
|
|
|
v1_persistent_volume_spec_free(inline_volume_spec_local_nonprim);
|
|
|
|
|
inline_volume_spec_local_nonprim = NULL;
|
|
|
|
|
}
|
2020-03-18 17:24:33 +08:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
}
|