2020-03-18 17:24:33 +08:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include "v1_service_status.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-02-11 19:36:46 +00:00
|
|
|
static v1_service_status_t *v1_service_status_create_internal(
|
2021-09-14 21:52:06 +08:00
|
|
|
list_t *conditions,
|
2020-03-18 17:24:33 +08:00
|
|
|
v1_load_balancer_status_t *load_balancer
|
|
|
|
|
) {
|
|
|
|
|
v1_service_status_t *v1_service_status_local_var = malloc(sizeof(v1_service_status_t));
|
|
|
|
|
if (!v1_service_status_local_var) {
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2021-09-14 21:52:06 +08:00
|
|
|
v1_service_status_local_var->conditions = conditions;
|
2020-03-18 17:24:33 +08:00
|
|
|
v1_service_status_local_var->load_balancer = load_balancer;
|
|
|
|
|
|
2025-02-11 19:36:46 +00:00
|
|
|
v1_service_status_local_var->_library_owned = 1;
|
2020-03-18 17:24:33 +08:00
|
|
|
return v1_service_status_local_var;
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-11 19:36:46 +00:00
|
|
|
__attribute__((deprecated)) v1_service_status_t *v1_service_status_create(
|
|
|
|
|
list_t *conditions,
|
|
|
|
|
v1_load_balancer_status_t *load_balancer
|
|
|
|
|
) {
|
|
|
|
|
return v1_service_status_create_internal (
|
|
|
|
|
conditions,
|
|
|
|
|
load_balancer
|
|
|
|
|
);
|
|
|
|
|
}
|
2020-03-18 17:24:33 +08:00
|
|
|
|
|
|
|
|
void v1_service_status_free(v1_service_status_t *v1_service_status) {
|
|
|
|
|
if(NULL == v1_service_status){
|
|
|
|
|
return ;
|
|
|
|
|
}
|
2025-02-11 19:36:46 +00:00
|
|
|
if(v1_service_status->_library_owned != 1){
|
|
|
|
|
fprintf(stderr, "WARNING: %s() does NOT free objects allocated by the user\n", "v1_service_status_free");
|
|
|
|
|
return ;
|
|
|
|
|
}
|
2020-03-18 17:24:33 +08:00
|
|
|
listEntry_t *listEntry;
|
2021-09-14 21:52:06 +08:00
|
|
|
if (v1_service_status->conditions) {
|
|
|
|
|
list_ForEach(listEntry, v1_service_status->conditions) {
|
|
|
|
|
v1_condition_free(listEntry->data);
|
|
|
|
|
}
|
2022-03-09 10:56:53 +08:00
|
|
|
list_freeList(v1_service_status->conditions);
|
2021-09-14 21:52:06 +08:00
|
|
|
v1_service_status->conditions = NULL;
|
|
|
|
|
}
|
2021-01-05 15:42:34 +08:00
|
|
|
if (v1_service_status->load_balancer) {
|
|
|
|
|
v1_load_balancer_status_free(v1_service_status->load_balancer);
|
|
|
|
|
v1_service_status->load_balancer = NULL;
|
|
|
|
|
}
|
2020-03-18 17:24:33 +08:00
|
|
|
free(v1_service_status);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cJSON *v1_service_status_convertToJSON(v1_service_status_t *v1_service_status) {
|
|
|
|
|
cJSON *item = cJSON_CreateObject();
|
|
|
|
|
|
2021-09-14 21:52:06 +08:00
|
|
|
// v1_service_status->conditions
|
2022-04-18 09:29:02 +08:00
|
|
|
if(v1_service_status->conditions) {
|
2021-09-14 21:52:06 +08:00
|
|
|
cJSON *conditions = cJSON_AddArrayToObject(item, "conditions");
|
|
|
|
|
if(conditions == NULL) {
|
|
|
|
|
goto fail; //nonprimitive container
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
listEntry_t *conditionsListEntry;
|
|
|
|
|
if (v1_service_status->conditions) {
|
|
|
|
|
list_ForEach(conditionsListEntry, v1_service_status->conditions) {
|
|
|
|
|
cJSON *itemLocal = v1_condition_convertToJSON(conditionsListEntry->data);
|
|
|
|
|
if(itemLocal == NULL) {
|
|
|
|
|
goto fail;
|
|
|
|
|
}
|
|
|
|
|
cJSON_AddItemToArray(conditions, itemLocal);
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-04-18 09:29:02 +08:00
|
|
|
}
|
2021-09-14 21:52:06 +08:00
|
|
|
|
|
|
|
|
|
2020-03-18 17:24:33 +08:00
|
|
|
// v1_service_status->load_balancer
|
2022-04-18 09:29:02 +08:00
|
|
|
if(v1_service_status->load_balancer) {
|
2020-03-18 17:24:33 +08:00
|
|
|
cJSON *load_balancer_local_JSON = v1_load_balancer_status_convertToJSON(v1_service_status->load_balancer);
|
|
|
|
|
if(load_balancer_local_JSON == NULL) {
|
|
|
|
|
goto fail; //model
|
|
|
|
|
}
|
|
|
|
|
cJSON_AddItemToObject(item, "loadBalancer", load_balancer_local_JSON);
|
|
|
|
|
if(item->child == NULL) {
|
|
|
|
|
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_service_status_t *v1_service_status_parseFromJSON(cJSON *v1_service_statusJSON){
|
|
|
|
|
|
|
|
|
|
v1_service_status_t *v1_service_status_local_var = NULL;
|
|
|
|
|
|
2022-03-29 10:12:05 +08:00
|
|
|
// define the local list for v1_service_status->conditions
|
|
|
|
|
list_t *conditionsList = NULL;
|
|
|
|
|
|
2021-11-05 14:13:35 +08:00
|
|
|
// define the local variable for v1_service_status->load_balancer
|
|
|
|
|
v1_load_balancer_status_t *load_balancer_local_nonprim = NULL;
|
|
|
|
|
|
2021-09-14 21:52:06 +08:00
|
|
|
// v1_service_status->conditions
|
|
|
|
|
cJSON *conditions = cJSON_GetObjectItemCaseSensitive(v1_service_statusJSON, "conditions");
|
2025-02-11 19:36:46 +00:00
|
|
|
if (cJSON_IsNull(conditions)) {
|
|
|
|
|
conditions = NULL;
|
|
|
|
|
}
|
2021-09-14 21:52:06 +08:00
|
|
|
if (conditions) {
|
2022-03-29 10:12:05 +08:00
|
|
|
cJSON *conditions_local_nonprimitive = NULL;
|
2021-09-14 21:52:06 +08:00
|
|
|
if(!cJSON_IsArray(conditions)){
|
|
|
|
|
goto end; //nonprimitive container
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-09 10:56:53 +08:00
|
|
|
conditionsList = list_createList();
|
2021-09-14 21:52:06 +08:00
|
|
|
|
|
|
|
|
cJSON_ArrayForEach(conditions_local_nonprimitive,conditions )
|
|
|
|
|
{
|
|
|
|
|
if(!cJSON_IsObject(conditions_local_nonprimitive)){
|
|
|
|
|
goto end;
|
|
|
|
|
}
|
|
|
|
|
v1_condition_t *conditionsItem = v1_condition_parseFromJSON(conditions_local_nonprimitive);
|
|
|
|
|
|
|
|
|
|
list_addElement(conditionsList, conditionsItem);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-18 17:24:33 +08:00
|
|
|
// v1_service_status->load_balancer
|
|
|
|
|
cJSON *load_balancer = cJSON_GetObjectItemCaseSensitive(v1_service_statusJSON, "loadBalancer");
|
2025-02-11 19:36:46 +00:00
|
|
|
if (cJSON_IsNull(load_balancer)) {
|
|
|
|
|
load_balancer = NULL;
|
|
|
|
|
}
|
2020-03-18 17:24:33 +08:00
|
|
|
if (load_balancer) {
|
|
|
|
|
load_balancer_local_nonprim = v1_load_balancer_status_parseFromJSON(load_balancer); //nonprimitive
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2025-02-11 19:36:46 +00:00
|
|
|
v1_service_status_local_var = v1_service_status_create_internal (
|
2021-09-14 21:52:06 +08:00
|
|
|
conditions ? conditionsList : NULL,
|
2020-03-18 17:24:33 +08:00
|
|
|
load_balancer ? load_balancer_local_nonprim : NULL
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return v1_service_status_local_var;
|
|
|
|
|
end:
|
2022-03-29 10:12:05 +08:00
|
|
|
if (conditionsList) {
|
|
|
|
|
listEntry_t *listEntry = NULL;
|
|
|
|
|
list_ForEach(listEntry, conditionsList) {
|
|
|
|
|
v1_condition_free(listEntry->data);
|
|
|
|
|
listEntry->data = NULL;
|
|
|
|
|
}
|
|
|
|
|
list_freeList(conditionsList);
|
|
|
|
|
conditionsList = NULL;
|
|
|
|
|
}
|
2021-01-11 12:15:24 +08:00
|
|
|
if (load_balancer_local_nonprim) {
|
|
|
|
|
v1_load_balancer_status_free(load_balancer_local_nonprim);
|
|
|
|
|
load_balancer_local_nonprim = NULL;
|
|
|
|
|
}
|
2020-03-18 17:24:33 +08:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
}
|