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