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