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