/src/open5gs/lib/sbi/openapi/model/roaming_info.c
Line | Count | Source |
1 | | |
2 | | #include <stdlib.h> |
3 | | #include <string.h> |
4 | | #include <stdio.h> |
5 | | #include "roaming_info.h" |
6 | | |
7 | | OpenAPI_roaming_info_t *OpenAPI_roaming_info_create( |
8 | | OpenAPI_plmn_id_nid_t *plmn_id, |
9 | | OpenAPI_list_t *aois, |
10 | | OpenAPI_list_t *serving_nf_ids, |
11 | | OpenAPI_list_t *serving_nf_set_ids |
12 | | ) |
13 | 0 | { |
14 | 0 | OpenAPI_roaming_info_t *roaming_info_local_var = ogs_malloc(sizeof(OpenAPI_roaming_info_t)); |
15 | 0 | ogs_assert(roaming_info_local_var); |
16 | | |
17 | 0 | roaming_info_local_var->plmn_id = plmn_id; |
18 | 0 | roaming_info_local_var->aois = aois; |
19 | 0 | roaming_info_local_var->serving_nf_ids = serving_nf_ids; |
20 | 0 | roaming_info_local_var->serving_nf_set_ids = serving_nf_set_ids; |
21 | |
|
22 | 0 | return roaming_info_local_var; |
23 | 0 | } |
24 | | |
25 | | void OpenAPI_roaming_info_free(OpenAPI_roaming_info_t *roaming_info) |
26 | 0 | { |
27 | 0 | OpenAPI_lnode_t *node = NULL; |
28 | |
|
29 | 0 | if (NULL == roaming_info) { |
30 | 0 | return; |
31 | 0 | } |
32 | 0 | if (roaming_info->plmn_id) { |
33 | 0 | OpenAPI_plmn_id_nid_free(roaming_info->plmn_id); |
34 | 0 | roaming_info->plmn_id = NULL; |
35 | 0 | } |
36 | 0 | if (roaming_info->aois) { |
37 | 0 | OpenAPI_list_for_each(roaming_info->aois, node) { |
38 | 0 | OpenAPI_geographical_area_free(node->data); |
39 | 0 | } |
40 | 0 | OpenAPI_list_free(roaming_info->aois); |
41 | 0 | roaming_info->aois = NULL; |
42 | 0 | } |
43 | 0 | if (roaming_info->serving_nf_ids) { |
44 | 0 | OpenAPI_list_for_each(roaming_info->serving_nf_ids, node) { |
45 | 0 | ogs_free(node->data); |
46 | 0 | } |
47 | 0 | OpenAPI_list_free(roaming_info->serving_nf_ids); |
48 | 0 | roaming_info->serving_nf_ids = NULL; |
49 | 0 | } |
50 | 0 | if (roaming_info->serving_nf_set_ids) { |
51 | 0 | OpenAPI_list_for_each(roaming_info->serving_nf_set_ids, node) { |
52 | 0 | ogs_free(node->data); |
53 | 0 | } |
54 | 0 | OpenAPI_list_free(roaming_info->serving_nf_set_ids); |
55 | 0 | roaming_info->serving_nf_set_ids = NULL; |
56 | 0 | } |
57 | 0 | ogs_free(roaming_info); |
58 | 0 | } |
59 | | |
60 | | cJSON *OpenAPI_roaming_info_convertToJSON(OpenAPI_roaming_info_t *roaming_info) |
61 | 0 | { |
62 | 0 | cJSON *item = NULL; |
63 | 0 | OpenAPI_lnode_t *node = NULL; |
64 | |
|
65 | 0 | if (roaming_info == NULL) { |
66 | 0 | ogs_error("OpenAPI_roaming_info_convertToJSON() failed [RoamingInfo]"); |
67 | 0 | return NULL; |
68 | 0 | } |
69 | | |
70 | 0 | item = cJSON_CreateObject(); |
71 | 0 | if (roaming_info->plmn_id) { |
72 | 0 | cJSON *plmn_id_local_JSON = OpenAPI_plmn_id_nid_convertToJSON(roaming_info->plmn_id); |
73 | 0 | if (plmn_id_local_JSON == NULL) { |
74 | 0 | ogs_error("OpenAPI_roaming_info_convertToJSON() failed [plmn_id]"); |
75 | 0 | goto end; |
76 | 0 | } |
77 | 0 | cJSON_AddItemToObject(item, "plmnId", plmn_id_local_JSON); |
78 | 0 | if (item->child == NULL) { |
79 | 0 | ogs_error("OpenAPI_roaming_info_convertToJSON() failed [plmn_id]"); |
80 | 0 | goto end; |
81 | 0 | } |
82 | 0 | } |
83 | | |
84 | 0 | if (roaming_info->aois) { |
85 | 0 | cJSON *aoisList = cJSON_AddArrayToObject(item, "aois"); |
86 | 0 | if (aoisList == NULL) { |
87 | 0 | ogs_error("OpenAPI_roaming_info_convertToJSON() failed [aois]"); |
88 | 0 | goto end; |
89 | 0 | } |
90 | 0 | OpenAPI_list_for_each(roaming_info->aois, node) { |
91 | 0 | cJSON *itemLocal = OpenAPI_geographical_area_convertToJSON(node->data); |
92 | 0 | if (itemLocal == NULL) { |
93 | 0 | ogs_error("OpenAPI_roaming_info_convertToJSON() failed [aois]"); |
94 | 0 | goto end; |
95 | 0 | } |
96 | 0 | cJSON_AddItemToArray(aoisList, itemLocal); |
97 | 0 | } |
98 | 0 | } |
99 | | |
100 | 0 | if (roaming_info->serving_nf_ids) { |
101 | 0 | cJSON *serving_nf_idsList = cJSON_AddArrayToObject(item, "servingNfIds"); |
102 | 0 | if (serving_nf_idsList == NULL) { |
103 | 0 | ogs_error("OpenAPI_roaming_info_convertToJSON() failed [serving_nf_ids]"); |
104 | 0 | goto end; |
105 | 0 | } |
106 | 0 | OpenAPI_list_for_each(roaming_info->serving_nf_ids, node) { |
107 | 0 | if (cJSON_AddStringToObject(serving_nf_idsList, "", (char*)node->data) == NULL) { |
108 | 0 | ogs_error("OpenAPI_roaming_info_convertToJSON() failed [serving_nf_ids]"); |
109 | 0 | goto end; |
110 | 0 | } |
111 | 0 | } |
112 | 0 | } |
113 | | |
114 | 0 | if (roaming_info->serving_nf_set_ids) { |
115 | 0 | cJSON *serving_nf_set_idsList = cJSON_AddArrayToObject(item, "servingNfSetIds"); |
116 | 0 | if (serving_nf_set_idsList == NULL) { |
117 | 0 | ogs_error("OpenAPI_roaming_info_convertToJSON() failed [serving_nf_set_ids]"); |
118 | 0 | goto end; |
119 | 0 | } |
120 | 0 | OpenAPI_list_for_each(roaming_info->serving_nf_set_ids, node) { |
121 | 0 | if (cJSON_AddStringToObject(serving_nf_set_idsList, "", (char*)node->data) == NULL) { |
122 | 0 | ogs_error("OpenAPI_roaming_info_convertToJSON() failed [serving_nf_set_ids]"); |
123 | 0 | goto end; |
124 | 0 | } |
125 | 0 | } |
126 | 0 | } |
127 | | |
128 | 0 | end: |
129 | 0 | return item; |
130 | 0 | } |
131 | | |
132 | | OpenAPI_roaming_info_t *OpenAPI_roaming_info_parseFromJSON(cJSON *roaming_infoJSON) |
133 | 0 | { |
134 | 0 | OpenAPI_roaming_info_t *roaming_info_local_var = NULL; |
135 | 0 | OpenAPI_lnode_t *node = NULL; |
136 | 0 | cJSON *plmn_id = NULL; |
137 | 0 | OpenAPI_plmn_id_nid_t *plmn_id_local_nonprim = NULL; |
138 | 0 | cJSON *aois = NULL; |
139 | 0 | OpenAPI_list_t *aoisList = NULL; |
140 | 0 | cJSON *serving_nf_ids = NULL; |
141 | 0 | OpenAPI_list_t *serving_nf_idsList = NULL; |
142 | 0 | cJSON *serving_nf_set_ids = NULL; |
143 | 0 | OpenAPI_list_t *serving_nf_set_idsList = NULL; |
144 | 0 | plmn_id = cJSON_GetObjectItemCaseSensitive(roaming_infoJSON, "plmnId"); |
145 | 0 | if (plmn_id) { |
146 | 0 | plmn_id_local_nonprim = OpenAPI_plmn_id_nid_parseFromJSON(plmn_id); |
147 | 0 | if (!plmn_id_local_nonprim) { |
148 | 0 | ogs_error("OpenAPI_plmn_id_nid_parseFromJSON failed [plmn_id]"); |
149 | 0 | goto end; |
150 | 0 | } |
151 | 0 | } |
152 | | |
153 | 0 | aois = cJSON_GetObjectItemCaseSensitive(roaming_infoJSON, "aois"); |
154 | 0 | if (aois) { |
155 | 0 | cJSON *aois_local = NULL; |
156 | 0 | if (!cJSON_IsArray(aois)) { |
157 | 0 | ogs_error("OpenAPI_roaming_info_parseFromJSON() failed [aois]"); |
158 | 0 | goto end; |
159 | 0 | } |
160 | | |
161 | 0 | aoisList = OpenAPI_list_create(); |
162 | |
|
163 | 0 | cJSON_ArrayForEach(aois_local, aois) { |
164 | 0 | if (!cJSON_IsObject(aois_local)) { |
165 | 0 | ogs_error("OpenAPI_roaming_info_parseFromJSON() failed [aois]"); |
166 | 0 | goto end; |
167 | 0 | } |
168 | 0 | OpenAPI_geographical_area_t *aoisItem = OpenAPI_geographical_area_parseFromJSON(aois_local); |
169 | 0 | if (!aoisItem) { |
170 | 0 | ogs_error("No aoisItem"); |
171 | 0 | goto end; |
172 | 0 | } |
173 | 0 | OpenAPI_list_add(aoisList, aoisItem); |
174 | 0 | } |
175 | 0 | } |
176 | | |
177 | 0 | serving_nf_ids = cJSON_GetObjectItemCaseSensitive(roaming_infoJSON, "servingNfIds"); |
178 | 0 | if (serving_nf_ids) { |
179 | 0 | cJSON *serving_nf_ids_local = NULL; |
180 | 0 | if (!cJSON_IsArray(serving_nf_ids)) { |
181 | 0 | ogs_error("OpenAPI_roaming_info_parseFromJSON() failed [serving_nf_ids]"); |
182 | 0 | goto end; |
183 | 0 | } |
184 | | |
185 | 0 | serving_nf_idsList = OpenAPI_list_create(); |
186 | |
|
187 | 0 | cJSON_ArrayForEach(serving_nf_ids_local, serving_nf_ids) { |
188 | 0 | double *localDouble = NULL; |
189 | 0 | int *localInt = NULL; |
190 | 0 | if (!cJSON_IsString(serving_nf_ids_local)) { |
191 | 0 | ogs_error("OpenAPI_roaming_info_parseFromJSON() failed [serving_nf_ids]"); |
192 | 0 | goto end; |
193 | 0 | } |
194 | 0 | OpenAPI_list_add(serving_nf_idsList, ogs_strdup(serving_nf_ids_local->valuestring)); |
195 | 0 | } |
196 | 0 | } |
197 | | |
198 | 0 | serving_nf_set_ids = cJSON_GetObjectItemCaseSensitive(roaming_infoJSON, "servingNfSetIds"); |
199 | 0 | if (serving_nf_set_ids) { |
200 | 0 | cJSON *serving_nf_set_ids_local = NULL; |
201 | 0 | if (!cJSON_IsArray(serving_nf_set_ids)) { |
202 | 0 | ogs_error("OpenAPI_roaming_info_parseFromJSON() failed [serving_nf_set_ids]"); |
203 | 0 | goto end; |
204 | 0 | } |
205 | | |
206 | 0 | serving_nf_set_idsList = OpenAPI_list_create(); |
207 | |
|
208 | 0 | cJSON_ArrayForEach(serving_nf_set_ids_local, serving_nf_set_ids) { |
209 | 0 | double *localDouble = NULL; |
210 | 0 | int *localInt = NULL; |
211 | 0 | if (!cJSON_IsString(serving_nf_set_ids_local)) { |
212 | 0 | ogs_error("OpenAPI_roaming_info_parseFromJSON() failed [serving_nf_set_ids]"); |
213 | 0 | goto end; |
214 | 0 | } |
215 | 0 | OpenAPI_list_add(serving_nf_set_idsList, ogs_strdup(serving_nf_set_ids_local->valuestring)); |
216 | 0 | } |
217 | 0 | } |
218 | | |
219 | 0 | roaming_info_local_var = OpenAPI_roaming_info_create ( |
220 | 0 | plmn_id ? plmn_id_local_nonprim : NULL, |
221 | 0 | aois ? aoisList : NULL, |
222 | 0 | serving_nf_ids ? serving_nf_idsList : NULL, |
223 | 0 | serving_nf_set_ids ? serving_nf_set_idsList : NULL |
224 | 0 | ); |
225 | |
|
226 | 0 | return roaming_info_local_var; |
227 | 0 | end: |
228 | 0 | if (plmn_id_local_nonprim) { |
229 | 0 | OpenAPI_plmn_id_nid_free(plmn_id_local_nonprim); |
230 | 0 | plmn_id_local_nonprim = NULL; |
231 | 0 | } |
232 | 0 | if (aoisList) { |
233 | 0 | OpenAPI_list_for_each(aoisList, node) { |
234 | 0 | OpenAPI_geographical_area_free(node->data); |
235 | 0 | } |
236 | 0 | OpenAPI_list_free(aoisList); |
237 | 0 | aoisList = NULL; |
238 | 0 | } |
239 | 0 | if (serving_nf_idsList) { |
240 | 0 | OpenAPI_list_for_each(serving_nf_idsList, node) { |
241 | 0 | ogs_free(node->data); |
242 | 0 | } |
243 | 0 | OpenAPI_list_free(serving_nf_idsList); |
244 | 0 | serving_nf_idsList = NULL; |
245 | 0 | } |
246 | 0 | if (serving_nf_set_idsList) { |
247 | 0 | OpenAPI_list_for_each(serving_nf_set_idsList, node) { |
248 | 0 | ogs_free(node->data); |
249 | 0 | } |
250 | 0 | OpenAPI_list_free(serving_nf_set_idsList); |
251 | 0 | serving_nf_set_idsList = NULL; |
252 | 0 | } |
253 | 0 | return NULL; |
254 | 0 | } |
255 | | |
256 | | OpenAPI_roaming_info_t *OpenAPI_roaming_info_copy(OpenAPI_roaming_info_t *dst, OpenAPI_roaming_info_t *src) |
257 | 0 | { |
258 | 0 | cJSON *item = NULL; |
259 | 0 | char *content = NULL; |
260 | |
|
261 | 0 | ogs_assert(src); |
262 | 0 | item = OpenAPI_roaming_info_convertToJSON(src); |
263 | 0 | if (!item) { |
264 | 0 | ogs_error("OpenAPI_roaming_info_convertToJSON() failed"); |
265 | 0 | return NULL; |
266 | 0 | } |
267 | | |
268 | 0 | content = cJSON_Print(item); |
269 | 0 | cJSON_Delete(item); |
270 | |
|
271 | 0 | if (!content) { |
272 | 0 | ogs_error("cJSON_Print() failed"); |
273 | 0 | return NULL; |
274 | 0 | } |
275 | | |
276 | 0 | item = cJSON_Parse(content); |
277 | 0 | ogs_free(content); |
278 | 0 | if (!item) { |
279 | 0 | ogs_error("cJSON_Parse() failed"); |
280 | 0 | return NULL; |
281 | 0 | } |
282 | | |
283 | 0 | OpenAPI_roaming_info_free(dst); |
284 | 0 | dst = OpenAPI_roaming_info_parseFromJSON(item); |
285 | 0 | cJSON_Delete(item); |
286 | |
|
287 | 0 | return dst; |
288 | 0 | } |
289 | | |