/src/open5gs/lib/sbi/openapi/model/nsacf_info.c
Line | Count | Source |
1 | | |
2 | | #include <stdlib.h> |
3 | | #include <string.h> |
4 | | #include <stdio.h> |
5 | | #include "nsacf_info.h" |
6 | | |
7 | | OpenAPI_nsacf_info_t *OpenAPI_nsacf_info_create( |
8 | | OpenAPI_nsacf_capability_t *nsacf_capability, |
9 | | OpenAPI_list_t *snssai_list_for_entire_plmn, |
10 | | OpenAPI_list_t *tai_list, |
11 | | OpenAPI_list_t *tai_range_list, |
12 | | OpenAPI_list_t *nsac_sai_list |
13 | | ) |
14 | 1.58k | { |
15 | 1.58k | OpenAPI_nsacf_info_t *nsacf_info_local_var = ogs_malloc(sizeof(OpenAPI_nsacf_info_t)); |
16 | 1.58k | ogs_assert(nsacf_info_local_var); |
17 | | |
18 | 1.58k | nsacf_info_local_var->nsacf_capability = nsacf_capability; |
19 | 1.58k | nsacf_info_local_var->snssai_list_for_entire_plmn = snssai_list_for_entire_plmn; |
20 | 1.58k | nsacf_info_local_var->tai_list = tai_list; |
21 | 1.58k | nsacf_info_local_var->tai_range_list = tai_range_list; |
22 | 1.58k | nsacf_info_local_var->nsac_sai_list = nsac_sai_list; |
23 | | |
24 | 1.58k | return nsacf_info_local_var; |
25 | 1.58k | } |
26 | | |
27 | | void OpenAPI_nsacf_info_free(OpenAPI_nsacf_info_t *nsacf_info) |
28 | 5.66k | { |
29 | 5.66k | OpenAPI_lnode_t *node = NULL; |
30 | | |
31 | 5.66k | if (NULL == nsacf_info) { |
32 | 4.07k | return; |
33 | 4.07k | } |
34 | 1.58k | if (nsacf_info->nsacf_capability) { |
35 | 1.58k | OpenAPI_nsacf_capability_free(nsacf_info->nsacf_capability); |
36 | 1.58k | nsacf_info->nsacf_capability = NULL; |
37 | 1.58k | } |
38 | 1.58k | if (nsacf_info->snssai_list_for_entire_plmn) { |
39 | 194 | OpenAPI_list_for_each(nsacf_info->snssai_list_for_entire_plmn, node) { |
40 | 0 | OpenAPI_ext_snssai_free(node->data); |
41 | 0 | } |
42 | 194 | OpenAPI_list_free(nsacf_info->snssai_list_for_entire_plmn); |
43 | 194 | nsacf_info->snssai_list_for_entire_plmn = NULL; |
44 | 194 | } |
45 | 1.58k | if (nsacf_info->tai_list) { |
46 | 195 | OpenAPI_list_for_each(nsacf_info->tai_list, node) { |
47 | 0 | OpenAPI_tai_free(node->data); |
48 | 0 | } |
49 | 195 | OpenAPI_list_free(nsacf_info->tai_list); |
50 | 195 | nsacf_info->tai_list = NULL; |
51 | 195 | } |
52 | 1.58k | if (nsacf_info->tai_range_list) { |
53 | 194 | OpenAPI_list_for_each(nsacf_info->tai_range_list, node) { |
54 | 0 | OpenAPI_tai_range_free(node->data); |
55 | 0 | } |
56 | 194 | OpenAPI_list_free(nsacf_info->tai_range_list); |
57 | 194 | nsacf_info->tai_range_list = NULL; |
58 | 194 | } |
59 | 1.58k | if (nsacf_info->nsac_sai_list) { |
60 | 510 | OpenAPI_list_for_each(nsacf_info->nsac_sai_list, node) { |
61 | 510 | ogs_free(node->data); |
62 | 510 | } |
63 | 396 | OpenAPI_list_free(nsacf_info->nsac_sai_list); |
64 | 396 | nsacf_info->nsac_sai_list = NULL; |
65 | 396 | } |
66 | 1.58k | ogs_free(nsacf_info); |
67 | 1.58k | } |
68 | | |
69 | | cJSON *OpenAPI_nsacf_info_convertToJSON(OpenAPI_nsacf_info_t *nsacf_info) |
70 | 0 | { |
71 | 0 | cJSON *item = NULL; |
72 | 0 | OpenAPI_lnode_t *node = NULL; |
73 | |
|
74 | 0 | if (nsacf_info == NULL) { |
75 | 0 | ogs_error("OpenAPI_nsacf_info_convertToJSON() failed [NsacfInfo]"); |
76 | 0 | return NULL; |
77 | 0 | } |
78 | | |
79 | 0 | item = cJSON_CreateObject(); |
80 | 0 | if (!nsacf_info->nsacf_capability) { |
81 | 0 | ogs_error("OpenAPI_nsacf_info_convertToJSON() failed [nsacf_capability]"); |
82 | 0 | return NULL; |
83 | 0 | } |
84 | 0 | cJSON *nsacf_capability_local_JSON = OpenAPI_nsacf_capability_convertToJSON(nsacf_info->nsacf_capability); |
85 | 0 | if (nsacf_capability_local_JSON == NULL) { |
86 | 0 | ogs_error("OpenAPI_nsacf_info_convertToJSON() failed [nsacf_capability]"); |
87 | 0 | goto end; |
88 | 0 | } |
89 | 0 | cJSON_AddItemToObject(item, "nsacfCapability", nsacf_capability_local_JSON); |
90 | 0 | if (item->child == NULL) { |
91 | 0 | ogs_error("OpenAPI_nsacf_info_convertToJSON() failed [nsacf_capability]"); |
92 | 0 | goto end; |
93 | 0 | } |
94 | | |
95 | 0 | if (nsacf_info->snssai_list_for_entire_plmn) { |
96 | 0 | cJSON *snssai_list_for_entire_plmnList = cJSON_AddArrayToObject(item, "snssaiListForEntirePlmn"); |
97 | 0 | if (snssai_list_for_entire_plmnList == NULL) { |
98 | 0 | ogs_error("OpenAPI_nsacf_info_convertToJSON() failed [snssai_list_for_entire_plmn]"); |
99 | 0 | goto end; |
100 | 0 | } |
101 | 0 | OpenAPI_list_for_each(nsacf_info->snssai_list_for_entire_plmn, node) { |
102 | 0 | cJSON *itemLocal = OpenAPI_ext_snssai_convertToJSON(node->data); |
103 | 0 | if (itemLocal == NULL) { |
104 | 0 | ogs_error("OpenAPI_nsacf_info_convertToJSON() failed [snssai_list_for_entire_plmn]"); |
105 | 0 | goto end; |
106 | 0 | } |
107 | 0 | cJSON_AddItemToArray(snssai_list_for_entire_plmnList, itemLocal); |
108 | 0 | } |
109 | 0 | } |
110 | | |
111 | 0 | if (nsacf_info->tai_list) { |
112 | 0 | cJSON *tai_listList = cJSON_AddArrayToObject(item, "taiList"); |
113 | 0 | if (tai_listList == NULL) { |
114 | 0 | ogs_error("OpenAPI_nsacf_info_convertToJSON() failed [tai_list]"); |
115 | 0 | goto end; |
116 | 0 | } |
117 | 0 | OpenAPI_list_for_each(nsacf_info->tai_list, node) { |
118 | 0 | cJSON *itemLocal = OpenAPI_tai_convertToJSON(node->data); |
119 | 0 | if (itemLocal == NULL) { |
120 | 0 | ogs_error("OpenAPI_nsacf_info_convertToJSON() failed [tai_list]"); |
121 | 0 | goto end; |
122 | 0 | } |
123 | 0 | cJSON_AddItemToArray(tai_listList, itemLocal); |
124 | 0 | } |
125 | 0 | } |
126 | | |
127 | 0 | if (nsacf_info->tai_range_list) { |
128 | 0 | cJSON *tai_range_listList = cJSON_AddArrayToObject(item, "taiRangeList"); |
129 | 0 | if (tai_range_listList == NULL) { |
130 | 0 | ogs_error("OpenAPI_nsacf_info_convertToJSON() failed [tai_range_list]"); |
131 | 0 | goto end; |
132 | 0 | } |
133 | 0 | OpenAPI_list_for_each(nsacf_info->tai_range_list, node) { |
134 | 0 | cJSON *itemLocal = OpenAPI_tai_range_convertToJSON(node->data); |
135 | 0 | if (itemLocal == NULL) { |
136 | 0 | ogs_error("OpenAPI_nsacf_info_convertToJSON() failed [tai_range_list]"); |
137 | 0 | goto end; |
138 | 0 | } |
139 | 0 | cJSON_AddItemToArray(tai_range_listList, itemLocal); |
140 | 0 | } |
141 | 0 | } |
142 | | |
143 | 0 | if (nsacf_info->nsac_sai_list) { |
144 | 0 | cJSON *nsac_sai_listList = cJSON_AddArrayToObject(item, "nsacSaiList"); |
145 | 0 | if (nsac_sai_listList == NULL) { |
146 | 0 | ogs_error("OpenAPI_nsacf_info_convertToJSON() failed [nsac_sai_list]"); |
147 | 0 | goto end; |
148 | 0 | } |
149 | 0 | OpenAPI_list_for_each(nsacf_info->nsac_sai_list, node) { |
150 | 0 | if (cJSON_AddStringToObject(nsac_sai_listList, "", (char*)node->data) == NULL) { |
151 | 0 | ogs_error("OpenAPI_nsacf_info_convertToJSON() failed [nsac_sai_list]"); |
152 | 0 | goto end; |
153 | 0 | } |
154 | 0 | } |
155 | 0 | } |
156 | | |
157 | 0 | end: |
158 | 0 | return item; |
159 | 0 | } |
160 | | |
161 | | OpenAPI_nsacf_info_t *OpenAPI_nsacf_info_parseFromJSON(cJSON *nsacf_infoJSON) |
162 | 5.35k | { |
163 | 5.35k | OpenAPI_nsacf_info_t *nsacf_info_local_var = NULL; |
164 | 5.35k | OpenAPI_lnode_t *node = NULL; |
165 | 5.35k | cJSON *nsacf_capability = NULL; |
166 | 5.35k | OpenAPI_nsacf_capability_t *nsacf_capability_local_nonprim = NULL; |
167 | 5.35k | cJSON *snssai_list_for_entire_plmn = NULL; |
168 | 5.35k | OpenAPI_list_t *snssai_list_for_entire_plmnList = NULL; |
169 | 5.35k | cJSON *tai_list = NULL; |
170 | 5.35k | OpenAPI_list_t *tai_listList = NULL; |
171 | 5.35k | cJSON *tai_range_list = NULL; |
172 | 5.35k | OpenAPI_list_t *tai_range_listList = NULL; |
173 | 5.35k | cJSON *nsac_sai_list = NULL; |
174 | 5.35k | OpenAPI_list_t *nsac_sai_listList = NULL; |
175 | 5.35k | nsacf_capability = cJSON_GetObjectItemCaseSensitive(nsacf_infoJSON, "nsacfCapability"); |
176 | 5.35k | if (!nsacf_capability) { |
177 | 1.32k | ogs_error("OpenAPI_nsacf_info_parseFromJSON() failed [nsacf_capability]"); |
178 | 1.32k | goto end; |
179 | 1.32k | } |
180 | 4.03k | nsacf_capability_local_nonprim = OpenAPI_nsacf_capability_parseFromJSON(nsacf_capability); |
181 | 4.03k | if (!nsacf_capability_local_nonprim) { |
182 | 492 | ogs_error("OpenAPI_nsacf_capability_parseFromJSON failed [nsacf_capability]"); |
183 | 492 | goto end; |
184 | 492 | } |
185 | | |
186 | 3.53k | snssai_list_for_entire_plmn = cJSON_GetObjectItemCaseSensitive(nsacf_infoJSON, "snssaiListForEntirePlmn"); |
187 | 3.53k | if (snssai_list_for_entire_plmn) { |
188 | 649 | cJSON *snssai_list_for_entire_plmn_local = NULL; |
189 | 649 | if (!cJSON_IsArray(snssai_list_for_entire_plmn)) { |
190 | 195 | ogs_error("OpenAPI_nsacf_info_parseFromJSON() failed [snssai_list_for_entire_plmn]"); |
191 | 195 | goto end; |
192 | 195 | } |
193 | | |
194 | 454 | snssai_list_for_entire_plmnList = OpenAPI_list_create(); |
195 | | |
196 | 454 | cJSON_ArrayForEach(snssai_list_for_entire_plmn_local, snssai_list_for_entire_plmn) { |
197 | 260 | if (!cJSON_IsObject(snssai_list_for_entire_plmn_local)) { |
198 | 66 | ogs_error("OpenAPI_nsacf_info_parseFromJSON() failed [snssai_list_for_entire_plmn]"); |
199 | 66 | goto end; |
200 | 66 | } |
201 | 194 | OpenAPI_ext_snssai_t *snssai_list_for_entire_plmnItem = OpenAPI_ext_snssai_parseFromJSON(snssai_list_for_entire_plmn_local); |
202 | 194 | if (!snssai_list_for_entire_plmnItem) { |
203 | 194 | ogs_error("No snssai_list_for_entire_plmnItem"); |
204 | 194 | goto end; |
205 | 194 | } |
206 | 0 | OpenAPI_list_add(snssai_list_for_entire_plmnList, snssai_list_for_entire_plmnItem); |
207 | 0 | } |
208 | 454 | } |
209 | | |
210 | 3.08k | tai_list = cJSON_GetObjectItemCaseSensitive(nsacf_infoJSON, "taiList"); |
211 | 3.08k | if (tai_list) { |
212 | 777 | cJSON *tai_list_local = NULL; |
213 | 777 | if (!cJSON_IsArray(tai_list)) { |
214 | 194 | ogs_error("OpenAPI_nsacf_info_parseFromJSON() failed [tai_list]"); |
215 | 194 | goto end; |
216 | 194 | } |
217 | | |
218 | 583 | tai_listList = OpenAPI_list_create(); |
219 | | |
220 | 583 | cJSON_ArrayForEach(tai_list_local, tai_list) { |
221 | 388 | if (!cJSON_IsObject(tai_list_local)) { |
222 | 194 | ogs_error("OpenAPI_nsacf_info_parseFromJSON() failed [tai_list]"); |
223 | 194 | goto end; |
224 | 194 | } |
225 | 194 | OpenAPI_tai_t *tai_listItem = OpenAPI_tai_parseFromJSON(tai_list_local); |
226 | 194 | if (!tai_listItem) { |
227 | 194 | ogs_error("No tai_listItem"); |
228 | 194 | goto end; |
229 | 194 | } |
230 | 0 | OpenAPI_list_add(tai_listList, tai_listItem); |
231 | 0 | } |
232 | 583 | } |
233 | | |
234 | 2.50k | tai_range_list = cJSON_GetObjectItemCaseSensitive(nsacf_infoJSON, "taiRangeList"); |
235 | 2.50k | if (tai_range_list) { |
236 | 648 | cJSON *tai_range_list_local = NULL; |
237 | 648 | if (!cJSON_IsArray(tai_range_list)) { |
238 | 66 | ogs_error("OpenAPI_nsacf_info_parseFromJSON() failed [tai_range_list]"); |
239 | 66 | goto end; |
240 | 66 | } |
241 | | |
242 | 582 | tai_range_listList = OpenAPI_list_create(); |
243 | | |
244 | 582 | cJSON_ArrayForEach(tai_range_list_local, tai_range_list) { |
245 | 388 | if (!cJSON_IsObject(tai_range_list_local)) { |
246 | 194 | ogs_error("OpenAPI_nsacf_info_parseFromJSON() failed [tai_range_list]"); |
247 | 194 | goto end; |
248 | 194 | } |
249 | 194 | OpenAPI_tai_range_t *tai_range_listItem = OpenAPI_tai_range_parseFromJSON(tai_range_list_local); |
250 | 194 | if (!tai_range_listItem) { |
251 | 194 | ogs_error("No tai_range_listItem"); |
252 | 194 | goto end; |
253 | 194 | } |
254 | 0 | OpenAPI_list_add(tai_range_listList, tai_range_listItem); |
255 | 0 | } |
256 | 582 | } |
257 | | |
258 | 2.04k | nsac_sai_list = cJSON_GetObjectItemCaseSensitive(nsacf_infoJSON, "nsacSaiList"); |
259 | 2.04k | if (nsac_sai_list) { |
260 | 858 | cJSON *nsac_sai_list_local = NULL; |
261 | 858 | if (!cJSON_IsArray(nsac_sai_list)) { |
262 | 194 | ogs_error("OpenAPI_nsacf_info_parseFromJSON() failed [nsac_sai_list]"); |
263 | 194 | goto end; |
264 | 194 | } |
265 | | |
266 | 664 | nsac_sai_listList = OpenAPI_list_create(); |
267 | | |
268 | 1.05k | cJSON_ArrayForEach(nsac_sai_list_local, nsac_sai_list) { |
269 | 1.05k | double *localDouble = NULL; |
270 | 1.05k | int *localInt = NULL; |
271 | 1.05k | if (!cJSON_IsString(nsac_sai_list_local)) { |
272 | 268 | ogs_error("OpenAPI_nsacf_info_parseFromJSON() failed [nsac_sai_list]"); |
273 | 268 | goto end; |
274 | 268 | } |
275 | 782 | OpenAPI_list_add(nsac_sai_listList, ogs_strdup(nsac_sai_list_local->valuestring)); |
276 | 782 | } |
277 | 664 | } |
278 | | |
279 | 1.58k | nsacf_info_local_var = OpenAPI_nsacf_info_create ( |
280 | 1.58k | nsacf_capability_local_nonprim, |
281 | 1.58k | snssai_list_for_entire_plmn ? snssai_list_for_entire_plmnList : NULL, |
282 | 1.58k | tai_list ? tai_listList : NULL, |
283 | 1.58k | tai_range_list ? tai_range_listList : NULL, |
284 | 1.58k | nsac_sai_list ? nsac_sai_listList : NULL |
285 | 1.58k | ); |
286 | | |
287 | 1.58k | return nsacf_info_local_var; |
288 | 3.77k | end: |
289 | 3.77k | if (nsacf_capability_local_nonprim) { |
290 | 1.95k | OpenAPI_nsacf_capability_free(nsacf_capability_local_nonprim); |
291 | 1.95k | nsacf_capability_local_nonprim = NULL; |
292 | 1.95k | } |
293 | 3.77k | if (snssai_list_for_entire_plmnList) { |
294 | 260 | OpenAPI_list_for_each(snssai_list_for_entire_plmnList, node) { |
295 | 0 | OpenAPI_ext_snssai_free(node->data); |
296 | 0 | } |
297 | 260 | OpenAPI_list_free(snssai_list_for_entire_plmnList); |
298 | 260 | snssai_list_for_entire_plmnList = NULL; |
299 | 260 | } |
300 | 3.77k | if (tai_listList) { |
301 | 388 | OpenAPI_list_for_each(tai_listList, node) { |
302 | 0 | OpenAPI_tai_free(node->data); |
303 | 0 | } |
304 | 388 | OpenAPI_list_free(tai_listList); |
305 | 388 | tai_listList = NULL; |
306 | 388 | } |
307 | 3.77k | if (tai_range_listList) { |
308 | 388 | OpenAPI_list_for_each(tai_range_listList, node) { |
309 | 0 | OpenAPI_tai_range_free(node->data); |
310 | 0 | } |
311 | 388 | OpenAPI_list_free(tai_range_listList); |
312 | 388 | tai_range_listList = NULL; |
313 | 388 | } |
314 | 3.77k | if (nsac_sai_listList) { |
315 | 272 | OpenAPI_list_for_each(nsac_sai_listList, node) { |
316 | 272 | ogs_free(node->data); |
317 | 272 | } |
318 | 268 | OpenAPI_list_free(nsac_sai_listList); |
319 | 268 | nsac_sai_listList = NULL; |
320 | 268 | } |
321 | 3.77k | return NULL; |
322 | 2.04k | } |
323 | | |
324 | | OpenAPI_nsacf_info_t *OpenAPI_nsacf_info_copy(OpenAPI_nsacf_info_t *dst, OpenAPI_nsacf_info_t *src) |
325 | 0 | { |
326 | 0 | cJSON *item = NULL; |
327 | 0 | char *content = NULL; |
328 | |
|
329 | 0 | ogs_assert(src); |
330 | 0 | item = OpenAPI_nsacf_info_convertToJSON(src); |
331 | 0 | if (!item) { |
332 | 0 | ogs_error("OpenAPI_nsacf_info_convertToJSON() failed"); |
333 | 0 | return NULL; |
334 | 0 | } |
335 | | |
336 | 0 | content = cJSON_Print(item); |
337 | 0 | cJSON_Delete(item); |
338 | |
|
339 | 0 | if (!content) { |
340 | 0 | ogs_error("cJSON_Print() failed"); |
341 | 0 | return NULL; |
342 | 0 | } |
343 | | |
344 | 0 | item = cJSON_Parse(content); |
345 | 0 | ogs_free(content); |
346 | 0 | if (!item) { |
347 | 0 | ogs_error("cJSON_Parse() failed"); |
348 | 0 | return NULL; |
349 | 0 | } |
350 | | |
351 | 0 | OpenAPI_nsacf_info_free(dst); |
352 | 0 | dst = OpenAPI_nsacf_info_parseFromJSON(item); |
353 | 0 | cJSON_Delete(item); |
354 | |
|
355 | 0 | return dst; |
356 | 0 | } |
357 | | |