forked from acouzens/open5gs
314 lines
11 KiB
C
314 lines
11 KiB
C
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <stdio.h>
|
|
#include "af_routing_requirement.h"
|
|
|
|
OpenAPI_af_routing_requirement_t *OpenAPI_af_routing_requirement_create(
|
|
bool is_app_reloc,
|
|
int app_reloc,
|
|
OpenAPI_list_t *route_to_locs,
|
|
OpenAPI_spatial_validity_t *sp_val,
|
|
OpenAPI_list_t *temp_vals,
|
|
OpenAPI_up_path_chg_event_t *up_path_chg_sub,
|
|
bool is_addr_preser_ind,
|
|
int addr_preser_ind
|
|
)
|
|
{
|
|
OpenAPI_af_routing_requirement_t *af_routing_requirement_local_var = ogs_malloc(sizeof(OpenAPI_af_routing_requirement_t));
|
|
ogs_assert(af_routing_requirement_local_var);
|
|
|
|
af_routing_requirement_local_var->is_app_reloc = is_app_reloc;
|
|
af_routing_requirement_local_var->app_reloc = app_reloc;
|
|
af_routing_requirement_local_var->route_to_locs = route_to_locs;
|
|
af_routing_requirement_local_var->sp_val = sp_val;
|
|
af_routing_requirement_local_var->temp_vals = temp_vals;
|
|
af_routing_requirement_local_var->up_path_chg_sub = up_path_chg_sub;
|
|
af_routing_requirement_local_var->is_addr_preser_ind = is_addr_preser_ind;
|
|
af_routing_requirement_local_var->addr_preser_ind = addr_preser_ind;
|
|
|
|
return af_routing_requirement_local_var;
|
|
}
|
|
|
|
void OpenAPI_af_routing_requirement_free(OpenAPI_af_routing_requirement_t *af_routing_requirement)
|
|
{
|
|
OpenAPI_lnode_t *node = NULL;
|
|
|
|
if (NULL == af_routing_requirement) {
|
|
return;
|
|
}
|
|
if (af_routing_requirement->route_to_locs) {
|
|
OpenAPI_list_for_each(af_routing_requirement->route_to_locs, node) {
|
|
OpenAPI_route_to_location_free(node->data);
|
|
}
|
|
OpenAPI_list_free(af_routing_requirement->route_to_locs);
|
|
af_routing_requirement->route_to_locs = NULL;
|
|
}
|
|
if (af_routing_requirement->sp_val) {
|
|
OpenAPI_spatial_validity_free(af_routing_requirement->sp_val);
|
|
af_routing_requirement->sp_val = NULL;
|
|
}
|
|
if (af_routing_requirement->temp_vals) {
|
|
OpenAPI_list_for_each(af_routing_requirement->temp_vals, node) {
|
|
OpenAPI_temporal_validity_free(node->data);
|
|
}
|
|
OpenAPI_list_free(af_routing_requirement->temp_vals);
|
|
af_routing_requirement->temp_vals = NULL;
|
|
}
|
|
if (af_routing_requirement->up_path_chg_sub) {
|
|
OpenAPI_up_path_chg_event_free(af_routing_requirement->up_path_chg_sub);
|
|
af_routing_requirement->up_path_chg_sub = NULL;
|
|
}
|
|
ogs_free(af_routing_requirement);
|
|
}
|
|
|
|
cJSON *OpenAPI_af_routing_requirement_convertToJSON(OpenAPI_af_routing_requirement_t *af_routing_requirement)
|
|
{
|
|
cJSON *item = NULL;
|
|
OpenAPI_lnode_t *node = NULL;
|
|
|
|
if (af_routing_requirement == NULL) {
|
|
ogs_error("OpenAPI_af_routing_requirement_convertToJSON() failed [AfRoutingRequirement]");
|
|
return NULL;
|
|
}
|
|
|
|
item = cJSON_CreateObject();
|
|
if (af_routing_requirement->is_app_reloc) {
|
|
if (cJSON_AddBoolToObject(item, "appReloc", af_routing_requirement->app_reloc) == NULL) {
|
|
ogs_error("OpenAPI_af_routing_requirement_convertToJSON() failed [app_reloc]");
|
|
goto end;
|
|
}
|
|
}
|
|
|
|
if (af_routing_requirement->route_to_locs) {
|
|
cJSON *route_to_locsList = cJSON_AddArrayToObject(item, "routeToLocs");
|
|
if (route_to_locsList == NULL) {
|
|
ogs_error("OpenAPI_af_routing_requirement_convertToJSON() failed [route_to_locs]");
|
|
goto end;
|
|
}
|
|
OpenAPI_list_for_each(af_routing_requirement->route_to_locs, node) {
|
|
cJSON *itemLocal = OpenAPI_route_to_location_convertToJSON(node->data);
|
|
if (itemLocal == NULL) {
|
|
ogs_error("OpenAPI_af_routing_requirement_convertToJSON() failed [route_to_locs]");
|
|
goto end;
|
|
}
|
|
cJSON_AddItemToArray(route_to_locsList, itemLocal);
|
|
}
|
|
}
|
|
|
|
if (af_routing_requirement->sp_val) {
|
|
cJSON *sp_val_local_JSON = OpenAPI_spatial_validity_convertToJSON(af_routing_requirement->sp_val);
|
|
if (sp_val_local_JSON == NULL) {
|
|
ogs_error("OpenAPI_af_routing_requirement_convertToJSON() failed [sp_val]");
|
|
goto end;
|
|
}
|
|
cJSON_AddItemToObject(item, "spVal", sp_val_local_JSON);
|
|
if (item->child == NULL) {
|
|
ogs_error("OpenAPI_af_routing_requirement_convertToJSON() failed [sp_val]");
|
|
goto end;
|
|
}
|
|
}
|
|
|
|
if (af_routing_requirement->temp_vals) {
|
|
cJSON *temp_valsList = cJSON_AddArrayToObject(item, "tempVals");
|
|
if (temp_valsList == NULL) {
|
|
ogs_error("OpenAPI_af_routing_requirement_convertToJSON() failed [temp_vals]");
|
|
goto end;
|
|
}
|
|
OpenAPI_list_for_each(af_routing_requirement->temp_vals, node) {
|
|
cJSON *itemLocal = OpenAPI_temporal_validity_convertToJSON(node->data);
|
|
if (itemLocal == NULL) {
|
|
ogs_error("OpenAPI_af_routing_requirement_convertToJSON() failed [temp_vals]");
|
|
goto end;
|
|
}
|
|
cJSON_AddItemToArray(temp_valsList, itemLocal);
|
|
}
|
|
}
|
|
|
|
if (af_routing_requirement->up_path_chg_sub) {
|
|
cJSON *up_path_chg_sub_local_JSON = OpenAPI_up_path_chg_event_convertToJSON(af_routing_requirement->up_path_chg_sub);
|
|
if (up_path_chg_sub_local_JSON == NULL) {
|
|
ogs_error("OpenAPI_af_routing_requirement_convertToJSON() failed [up_path_chg_sub]");
|
|
goto end;
|
|
}
|
|
cJSON_AddItemToObject(item, "upPathChgSub", up_path_chg_sub_local_JSON);
|
|
if (item->child == NULL) {
|
|
ogs_error("OpenAPI_af_routing_requirement_convertToJSON() failed [up_path_chg_sub]");
|
|
goto end;
|
|
}
|
|
}
|
|
|
|
if (af_routing_requirement->is_addr_preser_ind) {
|
|
if (cJSON_AddBoolToObject(item, "addrPreserInd", af_routing_requirement->addr_preser_ind) == NULL) {
|
|
ogs_error("OpenAPI_af_routing_requirement_convertToJSON() failed [addr_preser_ind]");
|
|
goto end;
|
|
}
|
|
}
|
|
|
|
end:
|
|
return item;
|
|
}
|
|
|
|
OpenAPI_af_routing_requirement_t *OpenAPI_af_routing_requirement_parseFromJSON(cJSON *af_routing_requirementJSON)
|
|
{
|
|
OpenAPI_af_routing_requirement_t *af_routing_requirement_local_var = NULL;
|
|
OpenAPI_lnode_t *node = NULL;
|
|
cJSON *app_reloc = NULL;
|
|
cJSON *route_to_locs = NULL;
|
|
OpenAPI_list_t *route_to_locsList = NULL;
|
|
cJSON *sp_val = NULL;
|
|
OpenAPI_spatial_validity_t *sp_val_local_nonprim = NULL;
|
|
cJSON *temp_vals = NULL;
|
|
OpenAPI_list_t *temp_valsList = NULL;
|
|
cJSON *up_path_chg_sub = NULL;
|
|
OpenAPI_up_path_chg_event_t *up_path_chg_sub_local_nonprim = NULL;
|
|
cJSON *addr_preser_ind = NULL;
|
|
app_reloc = cJSON_GetObjectItemCaseSensitive(af_routing_requirementJSON, "appReloc");
|
|
if (app_reloc) {
|
|
if (!cJSON_IsBool(app_reloc)) {
|
|
ogs_error("OpenAPI_af_routing_requirement_parseFromJSON() failed [app_reloc]");
|
|
goto end;
|
|
}
|
|
}
|
|
|
|
route_to_locs = cJSON_GetObjectItemCaseSensitive(af_routing_requirementJSON, "routeToLocs");
|
|
if (route_to_locs) {
|
|
cJSON *route_to_locs_local = NULL;
|
|
if (!cJSON_IsArray(route_to_locs)) {
|
|
ogs_error("OpenAPI_af_routing_requirement_parseFromJSON() failed [route_to_locs]");
|
|
goto end;
|
|
}
|
|
|
|
route_to_locsList = OpenAPI_list_create();
|
|
|
|
cJSON_ArrayForEach(route_to_locs_local, route_to_locs) {
|
|
if (!cJSON_IsObject(route_to_locs_local)) {
|
|
ogs_error("OpenAPI_af_routing_requirement_parseFromJSON() failed [route_to_locs]");
|
|
goto end;
|
|
}
|
|
OpenAPI_route_to_location_t *route_to_locsItem = OpenAPI_route_to_location_parseFromJSON(route_to_locs_local);
|
|
if (!route_to_locsItem) {
|
|
ogs_error("No route_to_locsItem");
|
|
OpenAPI_list_free(route_to_locsList);
|
|
goto end;
|
|
}
|
|
OpenAPI_list_add(route_to_locsList, route_to_locsItem);
|
|
}
|
|
}
|
|
|
|
sp_val = cJSON_GetObjectItemCaseSensitive(af_routing_requirementJSON, "spVal");
|
|
if (sp_val) {
|
|
sp_val_local_nonprim = OpenAPI_spatial_validity_parseFromJSON(sp_val);
|
|
}
|
|
|
|
temp_vals = cJSON_GetObjectItemCaseSensitive(af_routing_requirementJSON, "tempVals");
|
|
if (temp_vals) {
|
|
cJSON *temp_vals_local = NULL;
|
|
if (!cJSON_IsArray(temp_vals)) {
|
|
ogs_error("OpenAPI_af_routing_requirement_parseFromJSON() failed [temp_vals]");
|
|
goto end;
|
|
}
|
|
|
|
temp_valsList = OpenAPI_list_create();
|
|
|
|
cJSON_ArrayForEach(temp_vals_local, temp_vals) {
|
|
if (!cJSON_IsObject(temp_vals_local)) {
|
|
ogs_error("OpenAPI_af_routing_requirement_parseFromJSON() failed [temp_vals]");
|
|
goto end;
|
|
}
|
|
OpenAPI_temporal_validity_t *temp_valsItem = OpenAPI_temporal_validity_parseFromJSON(temp_vals_local);
|
|
if (!temp_valsItem) {
|
|
ogs_error("No temp_valsItem");
|
|
OpenAPI_list_free(temp_valsList);
|
|
goto end;
|
|
}
|
|
OpenAPI_list_add(temp_valsList, temp_valsItem);
|
|
}
|
|
}
|
|
|
|
up_path_chg_sub = cJSON_GetObjectItemCaseSensitive(af_routing_requirementJSON, "upPathChgSub");
|
|
if (up_path_chg_sub) {
|
|
up_path_chg_sub_local_nonprim = OpenAPI_up_path_chg_event_parseFromJSON(up_path_chg_sub);
|
|
}
|
|
|
|
addr_preser_ind = cJSON_GetObjectItemCaseSensitive(af_routing_requirementJSON, "addrPreserInd");
|
|
if (addr_preser_ind) {
|
|
if (!cJSON_IsBool(addr_preser_ind)) {
|
|
ogs_error("OpenAPI_af_routing_requirement_parseFromJSON() failed [addr_preser_ind]");
|
|
goto end;
|
|
}
|
|
}
|
|
|
|
af_routing_requirement_local_var = OpenAPI_af_routing_requirement_create (
|
|
app_reloc ? true : false,
|
|
app_reloc ? app_reloc->valueint : 0,
|
|
route_to_locs ? route_to_locsList : NULL,
|
|
sp_val ? sp_val_local_nonprim : NULL,
|
|
temp_vals ? temp_valsList : NULL,
|
|
up_path_chg_sub ? up_path_chg_sub_local_nonprim : NULL,
|
|
addr_preser_ind ? true : false,
|
|
addr_preser_ind ? addr_preser_ind->valueint : 0
|
|
);
|
|
|
|
return af_routing_requirement_local_var;
|
|
end:
|
|
if (route_to_locsList) {
|
|
OpenAPI_list_for_each(route_to_locsList, node) {
|
|
OpenAPI_route_to_location_free(node->data);
|
|
}
|
|
OpenAPI_list_free(route_to_locsList);
|
|
route_to_locsList = NULL;
|
|
}
|
|
if (sp_val_local_nonprim) {
|
|
OpenAPI_spatial_validity_free(sp_val_local_nonprim);
|
|
sp_val_local_nonprim = NULL;
|
|
}
|
|
if (temp_valsList) {
|
|
OpenAPI_list_for_each(temp_valsList, node) {
|
|
OpenAPI_temporal_validity_free(node->data);
|
|
}
|
|
OpenAPI_list_free(temp_valsList);
|
|
temp_valsList = NULL;
|
|
}
|
|
if (up_path_chg_sub_local_nonprim) {
|
|
OpenAPI_up_path_chg_event_free(up_path_chg_sub_local_nonprim);
|
|
up_path_chg_sub_local_nonprim = NULL;
|
|
}
|
|
return NULL;
|
|
}
|
|
|
|
OpenAPI_af_routing_requirement_t *OpenAPI_af_routing_requirement_copy(OpenAPI_af_routing_requirement_t *dst, OpenAPI_af_routing_requirement_t *src)
|
|
{
|
|
cJSON *item = NULL;
|
|
char *content = NULL;
|
|
|
|
ogs_assert(src);
|
|
item = OpenAPI_af_routing_requirement_convertToJSON(src);
|
|
if (!item) {
|
|
ogs_error("OpenAPI_af_routing_requirement_convertToJSON() failed");
|
|
return NULL;
|
|
}
|
|
|
|
content = cJSON_Print(item);
|
|
cJSON_Delete(item);
|
|
|
|
if (!content) {
|
|
ogs_error("cJSON_Print() failed");
|
|
return NULL;
|
|
}
|
|
|
|
item = cJSON_Parse(content);
|
|
ogs_free(content);
|
|
if (!item) {
|
|
ogs_error("cJSON_Parse() failed");
|
|
return NULL;
|
|
}
|
|
|
|
OpenAPI_af_routing_requirement_free(dst);
|
|
dst = OpenAPI_af_routing_requirement_parseFromJSON(item);
|
|
cJSON_Delete(item);
|
|
|
|
return dst;
|
|
}
|
|
|