/src/open5gs/lib/sbi/openapi/model/user_location.c
Line | Count | Source |
1 | | |
2 | | #include <stdlib.h> |
3 | | #include <string.h> |
4 | | #include <stdio.h> |
5 | | #include "user_location.h" |
6 | | |
7 | | OpenAPI_user_location_t *OpenAPI_user_location_create( |
8 | | OpenAPI_eutra_location_t *eutra_location, |
9 | | OpenAPI_nr_location_t *nr_location, |
10 | | OpenAPI_n3ga_location_t *n3ga_location, |
11 | | OpenAPI_utra_location_t *utra_location, |
12 | | OpenAPI_gera_location_t *gera_location |
13 | | ) |
14 | 0 | { |
15 | 0 | OpenAPI_user_location_t *user_location_local_var = ogs_malloc(sizeof(OpenAPI_user_location_t)); |
16 | 0 | ogs_assert(user_location_local_var); |
17 | | |
18 | 0 | user_location_local_var->eutra_location = eutra_location; |
19 | 0 | user_location_local_var->nr_location = nr_location; |
20 | 0 | user_location_local_var->n3ga_location = n3ga_location; |
21 | 0 | user_location_local_var->utra_location = utra_location; |
22 | 0 | user_location_local_var->gera_location = gera_location; |
23 | |
|
24 | 0 | return user_location_local_var; |
25 | 0 | } |
26 | | |
27 | | void OpenAPI_user_location_free(OpenAPI_user_location_t *user_location) |
28 | 0 | { |
29 | 0 | OpenAPI_lnode_t *node = NULL; |
30 | |
|
31 | 0 | if (NULL == user_location) { |
32 | 0 | return; |
33 | 0 | } |
34 | 0 | if (user_location->eutra_location) { |
35 | 0 | OpenAPI_eutra_location_free(user_location->eutra_location); |
36 | 0 | user_location->eutra_location = NULL; |
37 | 0 | } |
38 | 0 | if (user_location->nr_location) { |
39 | 0 | OpenAPI_nr_location_free(user_location->nr_location); |
40 | 0 | user_location->nr_location = NULL; |
41 | 0 | } |
42 | 0 | if (user_location->n3ga_location) { |
43 | 0 | OpenAPI_n3ga_location_free(user_location->n3ga_location); |
44 | 0 | user_location->n3ga_location = NULL; |
45 | 0 | } |
46 | 0 | if (user_location->utra_location) { |
47 | 0 | OpenAPI_utra_location_free(user_location->utra_location); |
48 | 0 | user_location->utra_location = NULL; |
49 | 0 | } |
50 | 0 | if (user_location->gera_location) { |
51 | 0 | OpenAPI_gera_location_free(user_location->gera_location); |
52 | 0 | user_location->gera_location = NULL; |
53 | 0 | } |
54 | 0 | ogs_free(user_location); |
55 | 0 | } |
56 | | |
57 | | cJSON *OpenAPI_user_location_convertToJSON(OpenAPI_user_location_t *user_location) |
58 | 0 | { |
59 | 0 | cJSON *item = NULL; |
60 | 0 | OpenAPI_lnode_t *node = NULL; |
61 | |
|
62 | 0 | if (user_location == NULL) { |
63 | 0 | ogs_error("OpenAPI_user_location_convertToJSON() failed [UserLocation]"); |
64 | 0 | return NULL; |
65 | 0 | } |
66 | | |
67 | 0 | item = cJSON_CreateObject(); |
68 | 0 | if (user_location->eutra_location) { |
69 | 0 | cJSON *eutra_location_local_JSON = OpenAPI_eutra_location_convertToJSON(user_location->eutra_location); |
70 | 0 | if (eutra_location_local_JSON == NULL) { |
71 | 0 | ogs_error("OpenAPI_user_location_convertToJSON() failed [eutra_location]"); |
72 | 0 | goto end; |
73 | 0 | } |
74 | 0 | cJSON_AddItemToObject(item, "eutraLocation", eutra_location_local_JSON); |
75 | 0 | if (item->child == NULL) { |
76 | 0 | ogs_error("OpenAPI_user_location_convertToJSON() failed [eutra_location]"); |
77 | 0 | goto end; |
78 | 0 | } |
79 | 0 | } |
80 | | |
81 | 0 | if (user_location->nr_location) { |
82 | 0 | cJSON *nr_location_local_JSON = OpenAPI_nr_location_convertToJSON(user_location->nr_location); |
83 | 0 | if (nr_location_local_JSON == NULL) { |
84 | 0 | ogs_error("OpenAPI_user_location_convertToJSON() failed [nr_location]"); |
85 | 0 | goto end; |
86 | 0 | } |
87 | 0 | cJSON_AddItemToObject(item, "nrLocation", nr_location_local_JSON); |
88 | 0 | if (item->child == NULL) { |
89 | 0 | ogs_error("OpenAPI_user_location_convertToJSON() failed [nr_location]"); |
90 | 0 | goto end; |
91 | 0 | } |
92 | 0 | } |
93 | | |
94 | 0 | if (user_location->n3ga_location) { |
95 | 0 | cJSON *n3ga_location_local_JSON = OpenAPI_n3ga_location_convertToJSON(user_location->n3ga_location); |
96 | 0 | if (n3ga_location_local_JSON == NULL) { |
97 | 0 | ogs_error("OpenAPI_user_location_convertToJSON() failed [n3ga_location]"); |
98 | 0 | goto end; |
99 | 0 | } |
100 | 0 | cJSON_AddItemToObject(item, "n3gaLocation", n3ga_location_local_JSON); |
101 | 0 | if (item->child == NULL) { |
102 | 0 | ogs_error("OpenAPI_user_location_convertToJSON() failed [n3ga_location]"); |
103 | 0 | goto end; |
104 | 0 | } |
105 | 0 | } |
106 | | |
107 | 0 | if (user_location->utra_location) { |
108 | 0 | cJSON *utra_location_local_JSON = OpenAPI_utra_location_convertToJSON(user_location->utra_location); |
109 | 0 | if (utra_location_local_JSON == NULL) { |
110 | 0 | ogs_error("OpenAPI_user_location_convertToJSON() failed [utra_location]"); |
111 | 0 | goto end; |
112 | 0 | } |
113 | 0 | cJSON_AddItemToObject(item, "utraLocation", utra_location_local_JSON); |
114 | 0 | if (item->child == NULL) { |
115 | 0 | ogs_error("OpenAPI_user_location_convertToJSON() failed [utra_location]"); |
116 | 0 | goto end; |
117 | 0 | } |
118 | 0 | } |
119 | | |
120 | 0 | if (user_location->gera_location) { |
121 | 0 | cJSON *gera_location_local_JSON = OpenAPI_gera_location_convertToJSON(user_location->gera_location); |
122 | 0 | if (gera_location_local_JSON == NULL) { |
123 | 0 | ogs_error("OpenAPI_user_location_convertToJSON() failed [gera_location]"); |
124 | 0 | goto end; |
125 | 0 | } |
126 | 0 | cJSON_AddItemToObject(item, "geraLocation", gera_location_local_JSON); |
127 | 0 | if (item->child == NULL) { |
128 | 0 | ogs_error("OpenAPI_user_location_convertToJSON() failed [gera_location]"); |
129 | 0 | goto end; |
130 | 0 | } |
131 | 0 | } |
132 | | |
133 | 0 | end: |
134 | 0 | return item; |
135 | 0 | } |
136 | | |
137 | | OpenAPI_user_location_t *OpenAPI_user_location_parseFromJSON(cJSON *user_locationJSON) |
138 | 0 | { |
139 | 0 | OpenAPI_user_location_t *user_location_local_var = NULL; |
140 | 0 | OpenAPI_lnode_t *node = NULL; |
141 | 0 | cJSON *eutra_location = NULL; |
142 | 0 | OpenAPI_eutra_location_t *eutra_location_local_nonprim = NULL; |
143 | 0 | cJSON *nr_location = NULL; |
144 | 0 | OpenAPI_nr_location_t *nr_location_local_nonprim = NULL; |
145 | 0 | cJSON *n3ga_location = NULL; |
146 | 0 | OpenAPI_n3ga_location_t *n3ga_location_local_nonprim = NULL; |
147 | 0 | cJSON *utra_location = NULL; |
148 | 0 | OpenAPI_utra_location_t *utra_location_local_nonprim = NULL; |
149 | 0 | cJSON *gera_location = NULL; |
150 | 0 | OpenAPI_gera_location_t *gera_location_local_nonprim = NULL; |
151 | 0 | eutra_location = cJSON_GetObjectItemCaseSensitive(user_locationJSON, "eutraLocation"); |
152 | 0 | if (eutra_location) { |
153 | 0 | eutra_location_local_nonprim = OpenAPI_eutra_location_parseFromJSON(eutra_location); |
154 | 0 | if (!eutra_location_local_nonprim) { |
155 | 0 | ogs_error("OpenAPI_eutra_location_parseFromJSON failed [eutra_location]"); |
156 | 0 | goto end; |
157 | 0 | } |
158 | 0 | } |
159 | | |
160 | 0 | nr_location = cJSON_GetObjectItemCaseSensitive(user_locationJSON, "nrLocation"); |
161 | 0 | if (nr_location) { |
162 | 0 | nr_location_local_nonprim = OpenAPI_nr_location_parseFromJSON(nr_location); |
163 | 0 | if (!nr_location_local_nonprim) { |
164 | 0 | ogs_error("OpenAPI_nr_location_parseFromJSON failed [nr_location]"); |
165 | 0 | goto end; |
166 | 0 | } |
167 | 0 | } |
168 | | |
169 | 0 | n3ga_location = cJSON_GetObjectItemCaseSensitive(user_locationJSON, "n3gaLocation"); |
170 | 0 | if (n3ga_location) { |
171 | 0 | n3ga_location_local_nonprim = OpenAPI_n3ga_location_parseFromJSON(n3ga_location); |
172 | 0 | if (!n3ga_location_local_nonprim) { |
173 | 0 | ogs_error("OpenAPI_n3ga_location_parseFromJSON failed [n3ga_location]"); |
174 | 0 | goto end; |
175 | 0 | } |
176 | 0 | } |
177 | | |
178 | 0 | utra_location = cJSON_GetObjectItemCaseSensitive(user_locationJSON, "utraLocation"); |
179 | 0 | if (utra_location) { |
180 | 0 | utra_location_local_nonprim = OpenAPI_utra_location_parseFromJSON(utra_location); |
181 | 0 | if (!utra_location_local_nonprim) { |
182 | 0 | ogs_error("OpenAPI_utra_location_parseFromJSON failed [utra_location]"); |
183 | 0 | goto end; |
184 | 0 | } |
185 | 0 | } |
186 | | |
187 | 0 | gera_location = cJSON_GetObjectItemCaseSensitive(user_locationJSON, "geraLocation"); |
188 | 0 | if (gera_location) { |
189 | 0 | gera_location_local_nonprim = OpenAPI_gera_location_parseFromJSON(gera_location); |
190 | 0 | if (!gera_location_local_nonprim) { |
191 | 0 | ogs_error("OpenAPI_gera_location_parseFromJSON failed [gera_location]"); |
192 | 0 | goto end; |
193 | 0 | } |
194 | 0 | } |
195 | | |
196 | 0 | user_location_local_var = OpenAPI_user_location_create ( |
197 | 0 | eutra_location ? eutra_location_local_nonprim : NULL, |
198 | 0 | nr_location ? nr_location_local_nonprim : NULL, |
199 | 0 | n3ga_location ? n3ga_location_local_nonprim : NULL, |
200 | 0 | utra_location ? utra_location_local_nonprim : NULL, |
201 | 0 | gera_location ? gera_location_local_nonprim : NULL |
202 | 0 | ); |
203 | |
|
204 | 0 | return user_location_local_var; |
205 | 0 | end: |
206 | 0 | if (eutra_location_local_nonprim) { |
207 | 0 | OpenAPI_eutra_location_free(eutra_location_local_nonprim); |
208 | 0 | eutra_location_local_nonprim = NULL; |
209 | 0 | } |
210 | 0 | if (nr_location_local_nonprim) { |
211 | 0 | OpenAPI_nr_location_free(nr_location_local_nonprim); |
212 | 0 | nr_location_local_nonprim = NULL; |
213 | 0 | } |
214 | 0 | if (n3ga_location_local_nonprim) { |
215 | 0 | OpenAPI_n3ga_location_free(n3ga_location_local_nonprim); |
216 | 0 | n3ga_location_local_nonprim = NULL; |
217 | 0 | } |
218 | 0 | if (utra_location_local_nonprim) { |
219 | 0 | OpenAPI_utra_location_free(utra_location_local_nonprim); |
220 | 0 | utra_location_local_nonprim = NULL; |
221 | 0 | } |
222 | 0 | if (gera_location_local_nonprim) { |
223 | 0 | OpenAPI_gera_location_free(gera_location_local_nonprim); |
224 | 0 | gera_location_local_nonprim = NULL; |
225 | 0 | } |
226 | 0 | return NULL; |
227 | 0 | } |
228 | | |
229 | | OpenAPI_user_location_t *OpenAPI_user_location_copy(OpenAPI_user_location_t *dst, OpenAPI_user_location_t *src) |
230 | 0 | { |
231 | 0 | cJSON *item = NULL; |
232 | 0 | char *content = NULL; |
233 | |
|
234 | 0 | ogs_assert(src); |
235 | 0 | item = OpenAPI_user_location_convertToJSON(src); |
236 | 0 | if (!item) { |
237 | 0 | ogs_error("OpenAPI_user_location_convertToJSON() failed"); |
238 | 0 | return NULL; |
239 | 0 | } |
240 | | |
241 | 0 | content = cJSON_Print(item); |
242 | 0 | cJSON_Delete(item); |
243 | |
|
244 | 0 | if (!content) { |
245 | 0 | ogs_error("cJSON_Print() failed"); |
246 | 0 | return NULL; |
247 | 0 | } |
248 | | |
249 | 0 | item = cJSON_Parse(content); |
250 | 0 | ogs_free(content); |
251 | 0 | if (!item) { |
252 | 0 | ogs_error("cJSON_Parse() failed"); |
253 | 0 | return NULL; |
254 | 0 | } |
255 | | |
256 | 0 | OpenAPI_user_location_free(dst); |
257 | 0 | dst = OpenAPI_user_location_parseFromJSON(item); |
258 | 0 | cJSON_Delete(item); |
259 | |
|
260 | 0 | return dst; |
261 | 0 | } |
262 | | |