2020-03-18 17:24:33 +08:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include "v1_portworx_volume_source.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-02-11 19:36:46 +00:00
|
|
|
static v1_portworx_volume_source_t *v1_portworx_volume_source_create_internal(
|
2020-03-18 17:24:33 +08:00
|
|
|
char *fs_type,
|
|
|
|
|
int read_only,
|
|
|
|
|
char *volume_id
|
|
|
|
|
) {
|
|
|
|
|
v1_portworx_volume_source_t *v1_portworx_volume_source_local_var = malloc(sizeof(v1_portworx_volume_source_t));
|
|
|
|
|
if (!v1_portworx_volume_source_local_var) {
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
v1_portworx_volume_source_local_var->fs_type = fs_type;
|
|
|
|
|
v1_portworx_volume_source_local_var->read_only = read_only;
|
|
|
|
|
v1_portworx_volume_source_local_var->volume_id = volume_id;
|
|
|
|
|
|
2025-02-11 19:36:46 +00:00
|
|
|
v1_portworx_volume_source_local_var->_library_owned = 1;
|
2020-03-18 17:24:33 +08:00
|
|
|
return v1_portworx_volume_source_local_var;
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-11 19:36:46 +00:00
|
|
|
__attribute__((deprecated)) v1_portworx_volume_source_t *v1_portworx_volume_source_create(
|
|
|
|
|
char *fs_type,
|
|
|
|
|
int read_only,
|
|
|
|
|
char *volume_id
|
|
|
|
|
) {
|
|
|
|
|
return v1_portworx_volume_source_create_internal (
|
|
|
|
|
fs_type,
|
|
|
|
|
read_only,
|
|
|
|
|
volume_id
|
|
|
|
|
);
|
|
|
|
|
}
|
2020-03-18 17:24:33 +08:00
|
|
|
|
|
|
|
|
void v1_portworx_volume_source_free(v1_portworx_volume_source_t *v1_portworx_volume_source) {
|
|
|
|
|
if(NULL == v1_portworx_volume_source){
|
|
|
|
|
return ;
|
|
|
|
|
}
|
2025-02-11 19:36:46 +00:00
|
|
|
if(v1_portworx_volume_source->_library_owned != 1){
|
|
|
|
|
fprintf(stderr, "WARNING: %s() does NOT free objects allocated by the user\n", "v1_portworx_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_portworx_volume_source->fs_type) {
|
|
|
|
|
free(v1_portworx_volume_source->fs_type);
|
|
|
|
|
v1_portworx_volume_source->fs_type = NULL;
|
|
|
|
|
}
|
|
|
|
|
if (v1_portworx_volume_source->volume_id) {
|
|
|
|
|
free(v1_portworx_volume_source->volume_id);
|
|
|
|
|
v1_portworx_volume_source->volume_id = NULL;
|
|
|
|
|
}
|
2020-03-18 17:24:33 +08:00
|
|
|
free(v1_portworx_volume_source);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cJSON *v1_portworx_volume_source_convertToJSON(v1_portworx_volume_source_t *v1_portworx_volume_source) {
|
|
|
|
|
cJSON *item = cJSON_CreateObject();
|
|
|
|
|
|
|
|
|
|
// v1_portworx_volume_source->fs_type
|
2022-04-18 09:29:02 +08:00
|
|
|
if(v1_portworx_volume_source->fs_type) {
|
2020-03-18 17:24:33 +08:00
|
|
|
if(cJSON_AddStringToObject(item, "fsType", v1_portworx_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_portworx_volume_source->read_only
|
2022-04-18 09:29:02 +08:00
|
|
|
if(v1_portworx_volume_source->read_only) {
|
2020-03-18 17:24:33 +08:00
|
|
|
if(cJSON_AddBoolToObject(item, "readOnly", v1_portworx_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_portworx_volume_source->volume_id
|
|
|
|
|
if (!v1_portworx_volume_source->volume_id) {
|
|
|
|
|
goto fail;
|
|
|
|
|
}
|
|
|
|
|
if(cJSON_AddStringToObject(item, "volumeID", v1_portworx_volume_source->volume_id) == NULL) {
|
|
|
|
|
goto fail; //String
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return item;
|
|
|
|
|
fail:
|
|
|
|
|
if (item) {
|
|
|
|
|
cJSON_Delete(item);
|
|
|
|
|
}
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
v1_portworx_volume_source_t *v1_portworx_volume_source_parseFromJSON(cJSON *v1_portworx_volume_sourceJSON){
|
|
|
|
|
|
|
|
|
|
v1_portworx_volume_source_t *v1_portworx_volume_source_local_var = NULL;
|
|
|
|
|
|
|
|
|
|
// v1_portworx_volume_source->fs_type
|
|
|
|
|
cJSON *fs_type = cJSON_GetObjectItemCaseSensitive(v1_portworx_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_portworx_volume_source->read_only
|
|
|
|
|
cJSON *read_only = cJSON_GetObjectItemCaseSensitive(v1_portworx_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_portworx_volume_source->volume_id
|
|
|
|
|
cJSON *volume_id = cJSON_GetObjectItemCaseSensitive(v1_portworx_volume_sourceJSON, "volumeID");
|
2025-02-11 19:36:46 +00:00
|
|
|
if (cJSON_IsNull(volume_id)) {
|
|
|
|
|
volume_id = NULL;
|
|
|
|
|
}
|
2020-03-18 17:24:33 +08:00
|
|
|
if (!volume_id) {
|
|
|
|
|
goto end;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(!cJSON_IsString(volume_id))
|
|
|
|
|
{
|
|
|
|
|
goto end; //String
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2025-02-11 19:36:46 +00:00
|
|
|
v1_portworx_volume_source_local_var = v1_portworx_volume_source_create_internal (
|
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
|
|
|
read_only ? read_only->valueint : 0,
|
|
|
|
|
strdup(volume_id->valuestring)
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return v1_portworx_volume_source_local_var;
|
|
|
|
|
end:
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
}
|