/src/open5gs/lib/sbi/openapi/model/spatial_validity.c
Line | Count | Source |
1 | | |
2 | | #include <stdlib.h> |
3 | | #include <string.h> |
4 | | #include <stdio.h> |
5 | | #include "spatial_validity.h" |
6 | | |
7 | | OpenAPI_spatial_validity_t *OpenAPI_spatial_validity_create( |
8 | | OpenAPI_list_t* presence_info_list |
9 | | ) |
10 | 0 | { |
11 | 0 | OpenAPI_spatial_validity_t *spatial_validity_local_var = ogs_malloc(sizeof(OpenAPI_spatial_validity_t)); |
12 | 0 | ogs_assert(spatial_validity_local_var); |
13 | | |
14 | 0 | spatial_validity_local_var->presence_info_list = presence_info_list; |
15 | |
|
16 | 0 | return spatial_validity_local_var; |
17 | 0 | } |
18 | | |
19 | | void OpenAPI_spatial_validity_free(OpenAPI_spatial_validity_t *spatial_validity) |
20 | 0 | { |
21 | 0 | OpenAPI_lnode_t *node = NULL; |
22 | |
|
23 | 0 | if (NULL == spatial_validity) { |
24 | 0 | return; |
25 | 0 | } |
26 | 0 | if (spatial_validity->presence_info_list) { |
27 | 0 | OpenAPI_list_for_each(spatial_validity->presence_info_list, node) { |
28 | 0 | OpenAPI_map_t *localKeyValue = (OpenAPI_map_t*)node->data; |
29 | 0 | ogs_free(localKeyValue->key); |
30 | 0 | OpenAPI_presence_info_free(localKeyValue->value); |
31 | 0 | OpenAPI_map_free(localKeyValue); |
32 | 0 | } |
33 | 0 | OpenAPI_list_free(spatial_validity->presence_info_list); |
34 | 0 | spatial_validity->presence_info_list = NULL; |
35 | 0 | } |
36 | 0 | ogs_free(spatial_validity); |
37 | 0 | } |
38 | | |
39 | | cJSON *OpenAPI_spatial_validity_convertToJSON(OpenAPI_spatial_validity_t *spatial_validity) |
40 | 0 | { |
41 | 0 | cJSON *item = NULL; |
42 | 0 | OpenAPI_lnode_t *node = NULL; |
43 | |
|
44 | 0 | if (spatial_validity == NULL) { |
45 | 0 | ogs_error("OpenAPI_spatial_validity_convertToJSON() failed [SpatialValidity]"); |
46 | 0 | return NULL; |
47 | 0 | } |
48 | | |
49 | 0 | item = cJSON_CreateObject(); |
50 | 0 | if (!spatial_validity->presence_info_list) { |
51 | 0 | ogs_error("OpenAPI_spatial_validity_convertToJSON() failed [presence_info_list]"); |
52 | 0 | return NULL; |
53 | 0 | } |
54 | 0 | cJSON *presence_info_list = cJSON_AddObjectToObject(item, "presenceInfoList"); |
55 | 0 | if (presence_info_list == NULL) { |
56 | 0 | ogs_error("OpenAPI_spatial_validity_convertToJSON() failed [presence_info_list]"); |
57 | 0 | goto end; |
58 | 0 | } |
59 | 0 | cJSON *localMapObject = presence_info_list; |
60 | 0 | if (spatial_validity->presence_info_list) { |
61 | 0 | OpenAPI_list_for_each(spatial_validity->presence_info_list, node) { |
62 | 0 | OpenAPI_map_t *localKeyValue = (OpenAPI_map_t*)node->data; |
63 | 0 | if (localKeyValue == NULL) { |
64 | 0 | ogs_error("OpenAPI_spatial_validity_convertToJSON() failed [presence_info_list]"); |
65 | 0 | goto end; |
66 | 0 | } |
67 | 0 | if (localKeyValue->key == NULL) { |
68 | 0 | ogs_error("OpenAPI_spatial_validity_convertToJSON() failed [presence_info_list]"); |
69 | 0 | goto end; |
70 | 0 | } |
71 | 0 | cJSON *itemLocal = localKeyValue->value ? |
72 | 0 | OpenAPI_presence_info_convertToJSON(localKeyValue->value) : |
73 | 0 | cJSON_CreateNull(); |
74 | 0 | if (itemLocal == NULL) { |
75 | 0 | ogs_error("OpenAPI_spatial_validity_convertToJSON() failed [inner]"); |
76 | 0 | goto end; |
77 | 0 | } |
78 | 0 | cJSON_AddItemToObject(localMapObject, localKeyValue->key, itemLocal); |
79 | 0 | } |
80 | 0 | } |
81 | | |
82 | 0 | end: |
83 | 0 | return item; |
84 | 0 | } |
85 | | |
86 | | OpenAPI_spatial_validity_t *OpenAPI_spatial_validity_parseFromJSON(cJSON *spatial_validityJSON) |
87 | 0 | { |
88 | 0 | OpenAPI_spatial_validity_t *spatial_validity_local_var = NULL; |
89 | 0 | OpenAPI_lnode_t *node = NULL; |
90 | 0 | cJSON *presence_info_list = NULL; |
91 | 0 | OpenAPI_list_t *presence_info_listList = NULL; |
92 | 0 | presence_info_list = cJSON_GetObjectItemCaseSensitive(spatial_validityJSON, "presenceInfoList"); |
93 | 0 | if (!presence_info_list) { |
94 | 0 | ogs_error("OpenAPI_spatial_validity_parseFromJSON() failed [presence_info_list]"); |
95 | 0 | goto end; |
96 | 0 | } |
97 | 0 | cJSON *presence_info_list_local_map = NULL; |
98 | 0 | if (!cJSON_IsObject(presence_info_list) && !cJSON_IsNull(presence_info_list)) { |
99 | 0 | ogs_error("OpenAPI_spatial_validity_parseFromJSON() failed [presence_info_list]"); |
100 | 0 | goto end; |
101 | 0 | } |
102 | 0 | if (cJSON_IsObject(presence_info_list)) { |
103 | 0 | presence_info_listList = OpenAPI_list_create(); |
104 | 0 | OpenAPI_map_t *localMapKeyPair = NULL; |
105 | 0 | cJSON_ArrayForEach(presence_info_list_local_map, presence_info_list) { |
106 | 0 | cJSON *localMapObject = presence_info_list_local_map; |
107 | 0 | if (cJSON_IsObject(localMapObject)) { |
108 | 0 | localMapKeyPair = OpenAPI_map_create( |
109 | 0 | ogs_strdup(localMapObject->string), OpenAPI_presence_info_parseFromJSON(localMapObject)); |
110 | 0 | } else if (cJSON_IsNull(localMapObject)) { |
111 | 0 | localMapKeyPair = OpenAPI_map_create(ogs_strdup(localMapObject->string), NULL); |
112 | 0 | } else { |
113 | 0 | ogs_error("OpenAPI_spatial_validity_parseFromJSON() failed [inner]"); |
114 | 0 | goto end; |
115 | 0 | } |
116 | 0 | if (localMapKeyPair == NULL) { |
117 | 0 | ogs_error("OpenAPI_spatial_validity_parseFromJSON() failed [presence_info_list]"); |
118 | 0 | goto end; |
119 | 0 | } |
120 | 0 | OpenAPI_list_add(presence_info_listList, localMapKeyPair); |
121 | 0 | } |
122 | 0 | } |
123 | | |
124 | 0 | spatial_validity_local_var = OpenAPI_spatial_validity_create ( |
125 | 0 | presence_info_listList |
126 | 0 | ); |
127 | |
|
128 | 0 | return spatial_validity_local_var; |
129 | 0 | end: |
130 | 0 | if (presence_info_listList) { |
131 | 0 | OpenAPI_list_for_each(presence_info_listList, node) { |
132 | 0 | OpenAPI_map_t *localKeyValue = (OpenAPI_map_t*)node->data; |
133 | 0 | ogs_free(localKeyValue->key); |
134 | 0 | OpenAPI_presence_info_free(localKeyValue->value); |
135 | 0 | OpenAPI_map_free(localKeyValue); |
136 | 0 | } |
137 | 0 | OpenAPI_list_free(presence_info_listList); |
138 | 0 | presence_info_listList = NULL; |
139 | 0 | } |
140 | 0 | return NULL; |
141 | 0 | } |
142 | | |
143 | | OpenAPI_spatial_validity_t *OpenAPI_spatial_validity_copy(OpenAPI_spatial_validity_t *dst, OpenAPI_spatial_validity_t *src) |
144 | 0 | { |
145 | 0 | cJSON *item = NULL; |
146 | 0 | char *content = NULL; |
147 | |
|
148 | 0 | ogs_assert(src); |
149 | 0 | item = OpenAPI_spatial_validity_convertToJSON(src); |
150 | 0 | if (!item) { |
151 | 0 | ogs_error("OpenAPI_spatial_validity_convertToJSON() failed"); |
152 | 0 | return NULL; |
153 | 0 | } |
154 | | |
155 | 0 | content = cJSON_Print(item); |
156 | 0 | cJSON_Delete(item); |
157 | |
|
158 | 0 | if (!content) { |
159 | 0 | ogs_error("cJSON_Print() failed"); |
160 | 0 | return NULL; |
161 | 0 | } |
162 | | |
163 | 0 | item = cJSON_Parse(content); |
164 | 0 | ogs_free(content); |
165 | 0 | if (!item) { |
166 | 0 | ogs_error("cJSON_Parse() failed"); |
167 | 0 | return NULL; |
168 | 0 | } |
169 | | |
170 | 0 | OpenAPI_spatial_validity_free(dst); |
171 | 0 | dst = OpenAPI_spatial_validity_parseFromJSON(item); |
172 | 0 | cJSON_Delete(item); |
173 | |
|
174 | 0 | return dst; |
175 | 0 | } |
176 | | |