/src/open5gs/lib/sbi/openapi/model/congestion_info.c
Line | Count | Source |
1 | | |
2 | | #include <stdlib.h> |
3 | | #include <string.h> |
4 | | #include <stdio.h> |
5 | | #include "congestion_info.h" |
6 | | |
7 | | OpenAPI_congestion_info_t *OpenAPI_congestion_info_create( |
8 | | OpenAPI_congestion_type_e cong_type, |
9 | | OpenAPI_time_window_t *time_intev, |
10 | | OpenAPI_threshold_level_t *nsi, |
11 | | bool is_confidence, |
12 | | int confidence, |
13 | | OpenAPI_list_t *top_app_list_ul, |
14 | | OpenAPI_list_t *top_app_list_dl |
15 | | ) |
16 | 0 | { |
17 | 0 | OpenAPI_congestion_info_t *congestion_info_local_var = ogs_malloc(sizeof(OpenAPI_congestion_info_t)); |
18 | 0 | ogs_assert(congestion_info_local_var); |
19 | | |
20 | 0 | congestion_info_local_var->cong_type = cong_type; |
21 | 0 | congestion_info_local_var->time_intev = time_intev; |
22 | 0 | congestion_info_local_var->nsi = nsi; |
23 | 0 | congestion_info_local_var->is_confidence = is_confidence; |
24 | 0 | congestion_info_local_var->confidence = confidence; |
25 | 0 | congestion_info_local_var->top_app_list_ul = top_app_list_ul; |
26 | 0 | congestion_info_local_var->top_app_list_dl = top_app_list_dl; |
27 | |
|
28 | 0 | return congestion_info_local_var; |
29 | 0 | } |
30 | | |
31 | | void OpenAPI_congestion_info_free(OpenAPI_congestion_info_t *congestion_info) |
32 | 0 | { |
33 | 0 | OpenAPI_lnode_t *node = NULL; |
34 | |
|
35 | 0 | if (NULL == congestion_info) { |
36 | 0 | return; |
37 | 0 | } |
38 | 0 | if (congestion_info->time_intev) { |
39 | 0 | OpenAPI_time_window_free(congestion_info->time_intev); |
40 | 0 | congestion_info->time_intev = NULL; |
41 | 0 | } |
42 | 0 | if (congestion_info->nsi) { |
43 | 0 | OpenAPI_threshold_level_free(congestion_info->nsi); |
44 | 0 | congestion_info->nsi = NULL; |
45 | 0 | } |
46 | 0 | if (congestion_info->top_app_list_ul) { |
47 | 0 | OpenAPI_list_for_each(congestion_info->top_app_list_ul, node) { |
48 | 0 | OpenAPI_top_application_free(node->data); |
49 | 0 | } |
50 | 0 | OpenAPI_list_free(congestion_info->top_app_list_ul); |
51 | 0 | congestion_info->top_app_list_ul = NULL; |
52 | 0 | } |
53 | 0 | if (congestion_info->top_app_list_dl) { |
54 | 0 | OpenAPI_list_for_each(congestion_info->top_app_list_dl, node) { |
55 | 0 | OpenAPI_top_application_free(node->data); |
56 | 0 | } |
57 | 0 | OpenAPI_list_free(congestion_info->top_app_list_dl); |
58 | 0 | congestion_info->top_app_list_dl = NULL; |
59 | 0 | } |
60 | 0 | ogs_free(congestion_info); |
61 | 0 | } |
62 | | |
63 | | cJSON *OpenAPI_congestion_info_convertToJSON(OpenAPI_congestion_info_t *congestion_info) |
64 | 0 | { |
65 | 0 | cJSON *item = NULL; |
66 | 0 | OpenAPI_lnode_t *node = NULL; |
67 | |
|
68 | 0 | if (congestion_info == NULL) { |
69 | 0 | ogs_error("OpenAPI_congestion_info_convertToJSON() failed [CongestionInfo]"); |
70 | 0 | return NULL; |
71 | 0 | } |
72 | | |
73 | 0 | item = cJSON_CreateObject(); |
74 | 0 | if (congestion_info->cong_type == OpenAPI_congestion_type_NULL) { |
75 | 0 | ogs_error("OpenAPI_congestion_info_convertToJSON() failed [cong_type]"); |
76 | 0 | return NULL; |
77 | 0 | } |
78 | 0 | if (cJSON_AddStringToObject(item, "congType", OpenAPI_congestion_type_ToString(congestion_info->cong_type)) == NULL) { |
79 | 0 | ogs_error("OpenAPI_congestion_info_convertToJSON() failed [cong_type]"); |
80 | 0 | goto end; |
81 | 0 | } |
82 | | |
83 | 0 | if (!congestion_info->time_intev) { |
84 | 0 | ogs_error("OpenAPI_congestion_info_convertToJSON() failed [time_intev]"); |
85 | 0 | return NULL; |
86 | 0 | } |
87 | 0 | cJSON *time_intev_local_JSON = OpenAPI_time_window_convertToJSON(congestion_info->time_intev); |
88 | 0 | if (time_intev_local_JSON == NULL) { |
89 | 0 | ogs_error("OpenAPI_congestion_info_convertToJSON() failed [time_intev]"); |
90 | 0 | goto end; |
91 | 0 | } |
92 | 0 | cJSON_AddItemToObject(item, "timeIntev", time_intev_local_JSON); |
93 | 0 | if (item->child == NULL) { |
94 | 0 | ogs_error("OpenAPI_congestion_info_convertToJSON() failed [time_intev]"); |
95 | 0 | goto end; |
96 | 0 | } |
97 | | |
98 | 0 | if (!congestion_info->nsi) { |
99 | 0 | ogs_error("OpenAPI_congestion_info_convertToJSON() failed [nsi]"); |
100 | 0 | return NULL; |
101 | 0 | } |
102 | 0 | cJSON *nsi_local_JSON = OpenAPI_threshold_level_convertToJSON(congestion_info->nsi); |
103 | 0 | if (nsi_local_JSON == NULL) { |
104 | 0 | ogs_error("OpenAPI_congestion_info_convertToJSON() failed [nsi]"); |
105 | 0 | goto end; |
106 | 0 | } |
107 | 0 | cJSON_AddItemToObject(item, "nsi", nsi_local_JSON); |
108 | 0 | if (item->child == NULL) { |
109 | 0 | ogs_error("OpenAPI_congestion_info_convertToJSON() failed [nsi]"); |
110 | 0 | goto end; |
111 | 0 | } |
112 | | |
113 | 0 | if (congestion_info->is_confidence) { |
114 | 0 | if (cJSON_AddNumberToObject(item, "confidence", congestion_info->confidence) == NULL) { |
115 | 0 | ogs_error("OpenAPI_congestion_info_convertToJSON() failed [confidence]"); |
116 | 0 | goto end; |
117 | 0 | } |
118 | 0 | } |
119 | | |
120 | 0 | if (congestion_info->top_app_list_ul) { |
121 | 0 | cJSON *top_app_list_ulList = cJSON_AddArrayToObject(item, "topAppListUl"); |
122 | 0 | if (top_app_list_ulList == NULL) { |
123 | 0 | ogs_error("OpenAPI_congestion_info_convertToJSON() failed [top_app_list_ul]"); |
124 | 0 | goto end; |
125 | 0 | } |
126 | 0 | OpenAPI_list_for_each(congestion_info->top_app_list_ul, node) { |
127 | 0 | cJSON *itemLocal = OpenAPI_top_application_convertToJSON(node->data); |
128 | 0 | if (itemLocal == NULL) { |
129 | 0 | ogs_error("OpenAPI_congestion_info_convertToJSON() failed [top_app_list_ul]"); |
130 | 0 | goto end; |
131 | 0 | } |
132 | 0 | cJSON_AddItemToArray(top_app_list_ulList, itemLocal); |
133 | 0 | } |
134 | 0 | } |
135 | | |
136 | 0 | if (congestion_info->top_app_list_dl) { |
137 | 0 | cJSON *top_app_list_dlList = cJSON_AddArrayToObject(item, "topAppListDl"); |
138 | 0 | if (top_app_list_dlList == NULL) { |
139 | 0 | ogs_error("OpenAPI_congestion_info_convertToJSON() failed [top_app_list_dl]"); |
140 | 0 | goto end; |
141 | 0 | } |
142 | 0 | OpenAPI_list_for_each(congestion_info->top_app_list_dl, node) { |
143 | 0 | cJSON *itemLocal = OpenAPI_top_application_convertToJSON(node->data); |
144 | 0 | if (itemLocal == NULL) { |
145 | 0 | ogs_error("OpenAPI_congestion_info_convertToJSON() failed [top_app_list_dl]"); |
146 | 0 | goto end; |
147 | 0 | } |
148 | 0 | cJSON_AddItemToArray(top_app_list_dlList, itemLocal); |
149 | 0 | } |
150 | 0 | } |
151 | | |
152 | 0 | end: |
153 | 0 | return item; |
154 | 0 | } |
155 | | |
156 | | OpenAPI_congestion_info_t *OpenAPI_congestion_info_parseFromJSON(cJSON *congestion_infoJSON) |
157 | 0 | { |
158 | 0 | OpenAPI_congestion_info_t *congestion_info_local_var = NULL; |
159 | 0 | OpenAPI_lnode_t *node = NULL; |
160 | 0 | cJSON *cong_type = NULL; |
161 | 0 | OpenAPI_congestion_type_e cong_typeVariable = 0; |
162 | 0 | cJSON *time_intev = NULL; |
163 | 0 | OpenAPI_time_window_t *time_intev_local_nonprim = NULL; |
164 | 0 | cJSON *nsi = NULL; |
165 | 0 | OpenAPI_threshold_level_t *nsi_local_nonprim = NULL; |
166 | 0 | cJSON *confidence = NULL; |
167 | 0 | cJSON *top_app_list_ul = NULL; |
168 | 0 | OpenAPI_list_t *top_app_list_ulList = NULL; |
169 | 0 | cJSON *top_app_list_dl = NULL; |
170 | 0 | OpenAPI_list_t *top_app_list_dlList = NULL; |
171 | 0 | cong_type = cJSON_GetObjectItemCaseSensitive(congestion_infoJSON, "congType"); |
172 | 0 | if (!cong_type) { |
173 | 0 | ogs_error("OpenAPI_congestion_info_parseFromJSON() failed [cong_type]"); |
174 | 0 | goto end; |
175 | 0 | } |
176 | 0 | if (!cJSON_IsString(cong_type)) { |
177 | 0 | ogs_error("OpenAPI_congestion_info_parseFromJSON() failed [cong_type]"); |
178 | 0 | goto end; |
179 | 0 | } |
180 | 0 | cong_typeVariable = OpenAPI_congestion_type_FromString(cong_type->valuestring); |
181 | |
|
182 | 0 | time_intev = cJSON_GetObjectItemCaseSensitive(congestion_infoJSON, "timeIntev"); |
183 | 0 | if (!time_intev) { |
184 | 0 | ogs_error("OpenAPI_congestion_info_parseFromJSON() failed [time_intev]"); |
185 | 0 | goto end; |
186 | 0 | } |
187 | 0 | time_intev_local_nonprim = OpenAPI_time_window_parseFromJSON(time_intev); |
188 | 0 | if (!time_intev_local_nonprim) { |
189 | 0 | ogs_error("OpenAPI_time_window_parseFromJSON failed [time_intev]"); |
190 | 0 | goto end; |
191 | 0 | } |
192 | | |
193 | 0 | nsi = cJSON_GetObjectItemCaseSensitive(congestion_infoJSON, "nsi"); |
194 | 0 | if (!nsi) { |
195 | 0 | ogs_error("OpenAPI_congestion_info_parseFromJSON() failed [nsi]"); |
196 | 0 | goto end; |
197 | 0 | } |
198 | 0 | nsi_local_nonprim = OpenAPI_threshold_level_parseFromJSON(nsi); |
199 | 0 | if (!nsi_local_nonprim) { |
200 | 0 | ogs_error("OpenAPI_threshold_level_parseFromJSON failed [nsi]"); |
201 | 0 | goto end; |
202 | 0 | } |
203 | | |
204 | 0 | confidence = cJSON_GetObjectItemCaseSensitive(congestion_infoJSON, "confidence"); |
205 | 0 | if (confidence) { |
206 | 0 | if (!cJSON_IsNumber(confidence)) { |
207 | 0 | ogs_error("OpenAPI_congestion_info_parseFromJSON() failed [confidence]"); |
208 | 0 | goto end; |
209 | 0 | } |
210 | 0 | } |
211 | | |
212 | 0 | top_app_list_ul = cJSON_GetObjectItemCaseSensitive(congestion_infoJSON, "topAppListUl"); |
213 | 0 | if (top_app_list_ul) { |
214 | 0 | cJSON *top_app_list_ul_local = NULL; |
215 | 0 | if (!cJSON_IsArray(top_app_list_ul)) { |
216 | 0 | ogs_error("OpenAPI_congestion_info_parseFromJSON() failed [top_app_list_ul]"); |
217 | 0 | goto end; |
218 | 0 | } |
219 | | |
220 | 0 | top_app_list_ulList = OpenAPI_list_create(); |
221 | |
|
222 | 0 | cJSON_ArrayForEach(top_app_list_ul_local, top_app_list_ul) { |
223 | 0 | if (!cJSON_IsObject(top_app_list_ul_local)) { |
224 | 0 | ogs_error("OpenAPI_congestion_info_parseFromJSON() failed [top_app_list_ul]"); |
225 | 0 | goto end; |
226 | 0 | } |
227 | 0 | OpenAPI_top_application_t *top_app_list_ulItem = OpenAPI_top_application_parseFromJSON(top_app_list_ul_local); |
228 | 0 | if (!top_app_list_ulItem) { |
229 | 0 | ogs_error("No top_app_list_ulItem"); |
230 | 0 | goto end; |
231 | 0 | } |
232 | 0 | OpenAPI_list_add(top_app_list_ulList, top_app_list_ulItem); |
233 | 0 | } |
234 | 0 | } |
235 | | |
236 | 0 | top_app_list_dl = cJSON_GetObjectItemCaseSensitive(congestion_infoJSON, "topAppListDl"); |
237 | 0 | if (top_app_list_dl) { |
238 | 0 | cJSON *top_app_list_dl_local = NULL; |
239 | 0 | if (!cJSON_IsArray(top_app_list_dl)) { |
240 | 0 | ogs_error("OpenAPI_congestion_info_parseFromJSON() failed [top_app_list_dl]"); |
241 | 0 | goto end; |
242 | 0 | } |
243 | | |
244 | 0 | top_app_list_dlList = OpenAPI_list_create(); |
245 | |
|
246 | 0 | cJSON_ArrayForEach(top_app_list_dl_local, top_app_list_dl) { |
247 | 0 | if (!cJSON_IsObject(top_app_list_dl_local)) { |
248 | 0 | ogs_error("OpenAPI_congestion_info_parseFromJSON() failed [top_app_list_dl]"); |
249 | 0 | goto end; |
250 | 0 | } |
251 | 0 | OpenAPI_top_application_t *top_app_list_dlItem = OpenAPI_top_application_parseFromJSON(top_app_list_dl_local); |
252 | 0 | if (!top_app_list_dlItem) { |
253 | 0 | ogs_error("No top_app_list_dlItem"); |
254 | 0 | goto end; |
255 | 0 | } |
256 | 0 | OpenAPI_list_add(top_app_list_dlList, top_app_list_dlItem); |
257 | 0 | } |
258 | 0 | } |
259 | | |
260 | 0 | congestion_info_local_var = OpenAPI_congestion_info_create ( |
261 | 0 | cong_typeVariable, |
262 | 0 | time_intev_local_nonprim, |
263 | 0 | nsi_local_nonprim, |
264 | 0 | confidence ? true : false, |
265 | 0 | confidence ? confidence->valuedouble : 0, |
266 | 0 | top_app_list_ul ? top_app_list_ulList : NULL, |
267 | 0 | top_app_list_dl ? top_app_list_dlList : NULL |
268 | 0 | ); |
269 | |
|
270 | 0 | return congestion_info_local_var; |
271 | 0 | end: |
272 | 0 | if (time_intev_local_nonprim) { |
273 | 0 | OpenAPI_time_window_free(time_intev_local_nonprim); |
274 | 0 | time_intev_local_nonprim = NULL; |
275 | 0 | } |
276 | 0 | if (nsi_local_nonprim) { |
277 | 0 | OpenAPI_threshold_level_free(nsi_local_nonprim); |
278 | 0 | nsi_local_nonprim = NULL; |
279 | 0 | } |
280 | 0 | if (top_app_list_ulList) { |
281 | 0 | OpenAPI_list_for_each(top_app_list_ulList, node) { |
282 | 0 | OpenAPI_top_application_free(node->data); |
283 | 0 | } |
284 | 0 | OpenAPI_list_free(top_app_list_ulList); |
285 | 0 | top_app_list_ulList = NULL; |
286 | 0 | } |
287 | 0 | if (top_app_list_dlList) { |
288 | 0 | OpenAPI_list_for_each(top_app_list_dlList, node) { |
289 | 0 | OpenAPI_top_application_free(node->data); |
290 | 0 | } |
291 | 0 | OpenAPI_list_free(top_app_list_dlList); |
292 | 0 | top_app_list_dlList = NULL; |
293 | 0 | } |
294 | 0 | return NULL; |
295 | 0 | } |
296 | | |
297 | | OpenAPI_congestion_info_t *OpenAPI_congestion_info_copy(OpenAPI_congestion_info_t *dst, OpenAPI_congestion_info_t *src) |
298 | 0 | { |
299 | 0 | cJSON *item = NULL; |
300 | 0 | char *content = NULL; |
301 | |
|
302 | 0 | ogs_assert(src); |
303 | 0 | item = OpenAPI_congestion_info_convertToJSON(src); |
304 | 0 | if (!item) { |
305 | 0 | ogs_error("OpenAPI_congestion_info_convertToJSON() failed"); |
306 | 0 | return NULL; |
307 | 0 | } |
308 | | |
309 | 0 | content = cJSON_Print(item); |
310 | 0 | cJSON_Delete(item); |
311 | |
|
312 | 0 | if (!content) { |
313 | 0 | ogs_error("cJSON_Print() failed"); |
314 | 0 | return NULL; |
315 | 0 | } |
316 | | |
317 | 0 | item = cJSON_Parse(content); |
318 | 0 | ogs_free(content); |
319 | 0 | if (!item) { |
320 | 0 | ogs_error("cJSON_Parse() failed"); |
321 | 0 | return NULL; |
322 | 0 | } |
323 | | |
324 | 0 | OpenAPI_congestion_info_free(dst); |
325 | 0 | dst = OpenAPI_congestion_info_parseFromJSON(item); |
326 | 0 | cJSON_Delete(item); |
327 | |
|
328 | 0 | return dst; |
329 | 0 | } |
330 | | |