2020-03-18 17:24:33 +08:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include "v1_csi_volume_source.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-02-11 19:36:46 +00:00
|
|
|
static v1_csi_volume_source_t *v1_csi_volume_source_create_internal(
|
2020-03-18 17:24:33 +08:00
|
|
|
char *driver,
|
|
|
|
|
char *fs_type,
|
|
|
|
|
v1_local_object_reference_t *node_publish_secret_ref,
|
|
|
|
|
int read_only,
|
|
|
|
|
list_t* volume_attributes
|
|
|
|
|
) {
|
|
|
|
|
v1_csi_volume_source_t *v1_csi_volume_source_local_var = malloc(sizeof(v1_csi_volume_source_t));
|
|
|
|
|
if (!v1_csi_volume_source_local_var) {
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
v1_csi_volume_source_local_var->driver = driver;
|
|
|
|
|
v1_csi_volume_source_local_var->fs_type = fs_type;
|
|
|
|
|
v1_csi_volume_source_local_var->node_publish_secret_ref = node_publish_secret_ref;
|
|
|
|
|
v1_csi_volume_source_local_var->read_only = read_only;
|
|
|
|
|
v1_csi_volume_source_local_var->volume_attributes = volume_attributes;
|
|
|
|
|
|
2025-02-11 19:36:46 +00:00
|
|
|
v1_csi_volume_source_local_var->_library_owned = 1;
|
2020-03-18 17:24:33 +08:00
|
|
|
return v1_csi_volume_source_local_var;
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-11 19:36:46 +00:00
|
|
|
__attribute__((deprecated)) v1_csi_volume_source_t *v1_csi_volume_source_create(
|
|
|
|
|
char *driver,
|
|
|
|
|
char *fs_type,
|
|
|
|
|
v1_local_object_reference_t *node_publish_secret_ref,
|
|
|
|
|
int read_only,
|
|
|
|
|
list_t* volume_attributes
|
|
|
|
|
) {
|
|
|
|
|
return v1_csi_volume_source_create_internal (
|
|
|
|
|
driver,
|
|
|
|
|
fs_type,
|
|
|
|
|
node_publish_secret_ref,
|
|
|
|
|
read_only,
|
|
|
|
|
volume_attributes
|
|
|
|
|
);
|
|
|
|
|
}
|
2020-03-18 17:24:33 +08:00
|
|
|
|
|
|
|
|
void v1_csi_volume_source_free(v1_csi_volume_source_t *v1_csi_volume_source) {
|
|
|
|
|
if(NULL == v1_csi_volume_source){
|
|
|
|
|
return ;
|
|
|
|
|
}
|
2025-02-11 19:36:46 +00:00
|
|
|
if(v1_csi_volume_source->_library_owned != 1){
|
|
|
|
|
fprintf(stderr, "WARNING: %s() does NOT free objects allocated by the user\n", "v1_csi_volume_source_free");
|
|
|
|
|
return ;
|
|
|
|
|
}
|
2020-03-18 17:24:33 +08:00
|
|
|
listEntry_t *listEntry;
|
2021-01-05 15:42:34 +08:00
|
|
|
if (v1_csi_volume_source->driver) {
|
|
|
|
|
free(v1_csi_volume_source->driver);
|
|
|
|
|
v1_csi_volume_source->driver = NULL;
|
|
|
|
|
}
|
|
|
|
|
if (v1_csi_volume_source->fs_type) {
|
|
|
|
|
free(v1_csi_volume_source->fs_type);
|
|
|
|
|
v1_csi_volume_source->fs_type = NULL;
|
|
|
|
|
}
|
|
|
|
|
if (v1_csi_volume_source->node_publish_secret_ref) {
|
|
|
|
|
v1_local_object_reference_free(v1_csi_volume_source->node_publish_secret_ref);
|
|
|
|
|
v1_csi_volume_source->node_publish_secret_ref = NULL;
|
|
|
|
|
}
|
|
|
|
|
if (v1_csi_volume_source->volume_attributes) {
|
|
|
|
|
list_ForEach(listEntry, v1_csi_volume_source->volume_attributes) {
|
2025-02-11 19:36:46 +00:00
|
|
|
keyValuePair_t *localKeyValue = listEntry->data;
|
2021-01-05 15:42:34 +08:00
|
|
|
free (localKeyValue->key);
|
|
|
|
|
free (localKeyValue->value);
|
|
|
|
|
keyValuePair_free(localKeyValue);
|
|
|
|
|
}
|
2022-03-09 10:56:53 +08:00
|
|
|
list_freeList(v1_csi_volume_source->volume_attributes);
|
2021-01-05 15:42:34 +08:00
|
|
|
v1_csi_volume_source->volume_attributes = NULL;
|
2020-03-18 17:24:33 +08:00
|
|
|
}
|
|
|
|
|
free(v1_csi_volume_source);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cJSON *v1_csi_volume_source_convertToJSON(v1_csi_volume_source_t *v1_csi_volume_source) {
|
|
|
|
|
cJSON *item = cJSON_CreateObject();
|
|
|
|
|
|
|
|
|
|
// v1_csi_volume_source->driver
|
|
|
|
|
if (!v1_csi_volume_source->driver) {
|
|
|
|
|
goto fail;
|
|
|
|
|
}
|
|
|
|
|
if(cJSON_AddStringToObject(item, "driver", v1_csi_volume_source->driver) == NULL) {
|
|
|
|
|
goto fail; //String
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// v1_csi_volume_source->fs_type
|
2022-04-18 09:29:02 +08:00
|
|
|
if(v1_csi_volume_source->fs_type) {
|
2020-03-18 17:24:33 +08:00
|
|
|
if(cJSON_AddStringToObject(item, "fsType", v1_csi_volume_source->fs_type) == NULL) {
|
|
|
|
|
goto fail; //String
|
|
|
|
|
}
|
2022-04-18 09:29:02 +08:00
|
|
|
}
|
2020-03-18 17:24:33 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
// v1_csi_volume_source->node_publish_secret_ref
|
2022-04-18 09:29:02 +08:00
|
|
|
if(v1_csi_volume_source->node_publish_secret_ref) {
|
2020-03-18 17:24:33 +08:00
|
|
|
cJSON *node_publish_secret_ref_local_JSON = v1_local_object_reference_convertToJSON(v1_csi_volume_source->node_publish_secret_ref);
|
|
|
|
|
if(node_publish_secret_ref_local_JSON == NULL) {
|
|
|
|
|
goto fail; //model
|
|
|
|
|
}
|
|
|
|
|
cJSON_AddItemToObject(item, "nodePublishSecretRef", node_publish_secret_ref_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_csi_volume_source->read_only
|
2022-04-18 09:29:02 +08:00
|
|
|
if(v1_csi_volume_source->read_only) {
|
2020-03-18 17:24:33 +08:00
|
|
|
if(cJSON_AddBoolToObject(item, "readOnly", v1_csi_volume_source->read_only) == NULL) {
|
|
|
|
|
goto fail; //Bool
|
|
|
|
|
}
|
2022-04-18 09:29:02 +08:00
|
|
|
}
|
2020-03-18 17:24:33 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
// v1_csi_volume_source->volume_attributes
|
2022-04-18 09:29:02 +08:00
|
|
|
if(v1_csi_volume_source->volume_attributes) {
|
2020-03-18 17:24:33 +08:00
|
|
|
cJSON *volume_attributes = cJSON_AddObjectToObject(item, "volumeAttributes");
|
|
|
|
|
if(volume_attributes == NULL) {
|
|
|
|
|
goto fail; //primitive map container
|
|
|
|
|
}
|
|
|
|
|
cJSON *localMapObject = volume_attributes;
|
|
|
|
|
listEntry_t *volume_attributesListEntry;
|
|
|
|
|
if (v1_csi_volume_source->volume_attributes) {
|
|
|
|
|
list_ForEach(volume_attributesListEntry, v1_csi_volume_source->volume_attributes) {
|
2025-02-11 19:36:46 +00:00
|
|
|
keyValuePair_t *localKeyValue = volume_attributesListEntry->data;
|
|
|
|
|
if(cJSON_AddStringToObject(localMapObject, localKeyValue->key, localKeyValue->value) == NULL)
|
2020-03-18 17:24:33 +08:00
|
|
|
{
|
|
|
|
|
goto fail;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
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_csi_volume_source_t *v1_csi_volume_source_parseFromJSON(cJSON *v1_csi_volume_sourceJSON){
|
|
|
|
|
|
|
|
|
|
v1_csi_volume_source_t *v1_csi_volume_source_local_var = NULL;
|
|
|
|
|
|
2021-11-05 14:13:35 +08:00
|
|
|
// define the local variable for v1_csi_volume_source->node_publish_secret_ref
|
|
|
|
|
v1_local_object_reference_t *node_publish_secret_ref_local_nonprim = NULL;
|
|
|
|
|
|
2022-03-29 10:12:05 +08:00
|
|
|
// define the local map for v1_csi_volume_source->volume_attributes
|
|
|
|
|
list_t *volume_attributesList = NULL;
|
|
|
|
|
|
2020-03-18 17:24:33 +08:00
|
|
|
// v1_csi_volume_source->driver
|
|
|
|
|
cJSON *driver = cJSON_GetObjectItemCaseSensitive(v1_csi_volume_sourceJSON, "driver");
|
2025-02-11 19:36:46 +00:00
|
|
|
if (cJSON_IsNull(driver)) {
|
|
|
|
|
driver = NULL;
|
|
|
|
|
}
|
2020-03-18 17:24:33 +08:00
|
|
|
if (!driver) {
|
|
|
|
|
goto end;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(!cJSON_IsString(driver))
|
|
|
|
|
{
|
|
|
|
|
goto end; //String
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// v1_csi_volume_source->fs_type
|
|
|
|
|
cJSON *fs_type = cJSON_GetObjectItemCaseSensitive(v1_csi_volume_sourceJSON, "fsType");
|
2025-02-11 19:36:46 +00:00
|
|
|
if (cJSON_IsNull(fs_type)) {
|
|
|
|
|
fs_type = NULL;
|
|
|
|
|
}
|
2020-03-18 17:24:33 +08:00
|
|
|
if (fs_type) {
|
2022-12-29 10:58:47 +08:00
|
|
|
if(!cJSON_IsString(fs_type) && !cJSON_IsNull(fs_type))
|
2020-03-18 17:24:33 +08:00
|
|
|
{
|
|
|
|
|
goto end; //String
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// v1_csi_volume_source->node_publish_secret_ref
|
|
|
|
|
cJSON *node_publish_secret_ref = cJSON_GetObjectItemCaseSensitive(v1_csi_volume_sourceJSON, "nodePublishSecretRef");
|
2025-02-11 19:36:46 +00:00
|
|
|
if (cJSON_IsNull(node_publish_secret_ref)) {
|
|
|
|
|
node_publish_secret_ref = NULL;
|
|
|
|
|
}
|
2020-03-18 17:24:33 +08:00
|
|
|
if (node_publish_secret_ref) {
|
|
|
|
|
node_publish_secret_ref_local_nonprim = v1_local_object_reference_parseFromJSON(node_publish_secret_ref); //nonprimitive
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// v1_csi_volume_source->read_only
|
|
|
|
|
cJSON *read_only = cJSON_GetObjectItemCaseSensitive(v1_csi_volume_sourceJSON, "readOnly");
|
2025-02-11 19:36:46 +00:00
|
|
|
if (cJSON_IsNull(read_only)) {
|
|
|
|
|
read_only = NULL;
|
|
|
|
|
}
|
2020-03-18 17:24:33 +08:00
|
|
|
if (read_only) {
|
|
|
|
|
if(!cJSON_IsBool(read_only))
|
|
|
|
|
{
|
|
|
|
|
goto end; //Bool
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// v1_csi_volume_source->volume_attributes
|
|
|
|
|
cJSON *volume_attributes = cJSON_GetObjectItemCaseSensitive(v1_csi_volume_sourceJSON, "volumeAttributes");
|
2025-02-11 19:36:46 +00:00
|
|
|
if (cJSON_IsNull(volume_attributes)) {
|
|
|
|
|
volume_attributes = NULL;
|
|
|
|
|
}
|
2020-03-18 17:24:33 +08:00
|
|
|
if (volume_attributes) {
|
2022-03-29 10:12:05 +08:00
|
|
|
cJSON *volume_attributes_local_map = NULL;
|
2022-09-09 10:18:51 +08:00
|
|
|
if(!cJSON_IsObject(volume_attributes) && !cJSON_IsNull(volume_attributes))
|
|
|
|
|
{
|
2020-03-18 17:24:33 +08:00
|
|
|
goto end;//primitive map container
|
|
|
|
|
}
|
2022-09-09 10:18:51 +08:00
|
|
|
if(cJSON_IsObject(volume_attributes))
|
2020-03-18 17:24:33 +08:00
|
|
|
{
|
2022-09-09 10:18:51 +08:00
|
|
|
volume_attributesList = list_createList();
|
|
|
|
|
keyValuePair_t *localMapKeyPair;
|
|
|
|
|
cJSON_ArrayForEach(volume_attributes_local_map, volume_attributes)
|
2020-03-18 17:24:33 +08:00
|
|
|
{
|
2022-09-09 10:18:51 +08:00
|
|
|
cJSON *localMapObject = volume_attributes_local_map;
|
|
|
|
|
if(!cJSON_IsString(localMapObject))
|
|
|
|
|
{
|
|
|
|
|
goto end;
|
|
|
|
|
}
|
|
|
|
|
localMapKeyPair = keyValuePair_create(strdup(localMapObject->string),strdup(localMapObject->valuestring));
|
|
|
|
|
list_addElement(volume_attributesList , localMapKeyPair);
|
2020-03-18 17:24:33 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2025-02-11 19:36:46 +00:00
|
|
|
v1_csi_volume_source_local_var = v1_csi_volume_source_create_internal (
|
2020-03-18 17:24:33 +08:00
|
|
|
strdup(driver->valuestring),
|
2022-12-29 10:58:47 +08:00
|
|
|
fs_type && !cJSON_IsNull(fs_type) ? strdup(fs_type->valuestring) : NULL,
|
2020-03-18 17:24:33 +08:00
|
|
|
node_publish_secret_ref ? node_publish_secret_ref_local_nonprim : NULL,
|
|
|
|
|
read_only ? read_only->valueint : 0,
|
|
|
|
|
volume_attributes ? volume_attributesList : NULL
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return v1_csi_volume_source_local_var;
|
|
|
|
|
end:
|
2021-01-11 12:15:24 +08:00
|
|
|
if (node_publish_secret_ref_local_nonprim) {
|
|
|
|
|
v1_local_object_reference_free(node_publish_secret_ref_local_nonprim);
|
|
|
|
|
node_publish_secret_ref_local_nonprim = NULL;
|
|
|
|
|
}
|
2022-03-29 10:12:05 +08:00
|
|
|
if (volume_attributesList) {
|
|
|
|
|
listEntry_t *listEntry = NULL;
|
|
|
|
|
list_ForEach(listEntry, volume_attributesList) {
|
2025-02-11 19:36:46 +00:00
|
|
|
keyValuePair_t *localKeyValue = listEntry->data;
|
2022-03-29 10:12:05 +08:00
|
|
|
free(localKeyValue->key);
|
|
|
|
|
localKeyValue->key = NULL;
|
|
|
|
|
free(localKeyValue->value);
|
|
|
|
|
localKeyValue->value = NULL;
|
|
|
|
|
keyValuePair_free(localKeyValue);
|
|
|
|
|
localKeyValue = NULL;
|
|
|
|
|
}
|
|
|
|
|
list_freeList(volume_attributesList);
|
|
|
|
|
volume_attributesList = NULL;
|
|
|
|
|
}
|
2020-03-18 17:24:33 +08:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
}
|