/src/open5gs/lib/sbi/openapi/model/lcs_privacy.c
Line | Count | Source |
1 | | |
2 | | #include <stdlib.h> |
3 | | #include <string.h> |
4 | | #include <stdio.h> |
5 | | #include "lcs_privacy.h" |
6 | | |
7 | | OpenAPI_lcs_privacy_t *OpenAPI_lcs_privacy_create( |
8 | | char *af_instance_id, |
9 | | bool is_reference_id, |
10 | | int reference_id, |
11 | | OpenAPI_lpi_t *lpi, |
12 | | char *mtc_provider_information, |
13 | | OpenAPI_geographic_area_t *evt_rpt_expected_area, |
14 | | OpenAPI_area_usage_ind_e area_usage_ind, |
15 | | OpenAPI_up_loc_rep_ind_af_e up_loc_rep_ind_af |
16 | | ) |
17 | 0 | { |
18 | 0 | OpenAPI_lcs_privacy_t *lcs_privacy_local_var = ogs_malloc(sizeof(OpenAPI_lcs_privacy_t)); |
19 | 0 | ogs_assert(lcs_privacy_local_var); |
20 | | |
21 | 0 | lcs_privacy_local_var->af_instance_id = af_instance_id; |
22 | 0 | lcs_privacy_local_var->is_reference_id = is_reference_id; |
23 | 0 | lcs_privacy_local_var->reference_id = reference_id; |
24 | 0 | lcs_privacy_local_var->lpi = lpi; |
25 | 0 | lcs_privacy_local_var->mtc_provider_information = mtc_provider_information; |
26 | 0 | lcs_privacy_local_var->evt_rpt_expected_area = evt_rpt_expected_area; |
27 | 0 | lcs_privacy_local_var->area_usage_ind = area_usage_ind; |
28 | 0 | lcs_privacy_local_var->up_loc_rep_ind_af = up_loc_rep_ind_af; |
29 | |
|
30 | 0 | return lcs_privacy_local_var; |
31 | 0 | } |
32 | | |
33 | | void OpenAPI_lcs_privacy_free(OpenAPI_lcs_privacy_t *lcs_privacy) |
34 | 0 | { |
35 | 0 | OpenAPI_lnode_t *node = NULL; |
36 | |
|
37 | 0 | if (NULL == lcs_privacy) { |
38 | 0 | return; |
39 | 0 | } |
40 | 0 | if (lcs_privacy->af_instance_id) { |
41 | 0 | ogs_free(lcs_privacy->af_instance_id); |
42 | 0 | lcs_privacy->af_instance_id = NULL; |
43 | 0 | } |
44 | 0 | if (lcs_privacy->lpi) { |
45 | 0 | OpenAPI_lpi_free(lcs_privacy->lpi); |
46 | 0 | lcs_privacy->lpi = NULL; |
47 | 0 | } |
48 | 0 | if (lcs_privacy->mtc_provider_information) { |
49 | 0 | ogs_free(lcs_privacy->mtc_provider_information); |
50 | 0 | lcs_privacy->mtc_provider_information = NULL; |
51 | 0 | } |
52 | 0 | if (lcs_privacy->evt_rpt_expected_area) { |
53 | 0 | OpenAPI_geographic_area_free(lcs_privacy->evt_rpt_expected_area); |
54 | 0 | lcs_privacy->evt_rpt_expected_area = NULL; |
55 | 0 | } |
56 | 0 | ogs_free(lcs_privacy); |
57 | 0 | } |
58 | | |
59 | | cJSON *OpenAPI_lcs_privacy_convertToJSON(OpenAPI_lcs_privacy_t *lcs_privacy) |
60 | 0 | { |
61 | 0 | cJSON *item = NULL; |
62 | 0 | OpenAPI_lnode_t *node = NULL; |
63 | |
|
64 | 0 | if (lcs_privacy == NULL) { |
65 | 0 | ogs_error("OpenAPI_lcs_privacy_convertToJSON() failed [LcsPrivacy]"); |
66 | 0 | return NULL; |
67 | 0 | } |
68 | | |
69 | 0 | item = cJSON_CreateObject(); |
70 | 0 | if (lcs_privacy->af_instance_id) { |
71 | 0 | if (cJSON_AddStringToObject(item, "afInstanceId", lcs_privacy->af_instance_id) == NULL) { |
72 | 0 | ogs_error("OpenAPI_lcs_privacy_convertToJSON() failed [af_instance_id]"); |
73 | 0 | goto end; |
74 | 0 | } |
75 | 0 | } |
76 | | |
77 | 0 | if (lcs_privacy->is_reference_id) { |
78 | 0 | if (cJSON_AddNumberToObject(item, "referenceId", lcs_privacy->reference_id) == NULL) { |
79 | 0 | ogs_error("OpenAPI_lcs_privacy_convertToJSON() failed [reference_id]"); |
80 | 0 | goto end; |
81 | 0 | } |
82 | 0 | } |
83 | | |
84 | 0 | if (lcs_privacy->lpi) { |
85 | 0 | cJSON *lpi_local_JSON = OpenAPI_lpi_convertToJSON(lcs_privacy->lpi); |
86 | 0 | if (lpi_local_JSON == NULL) { |
87 | 0 | ogs_error("OpenAPI_lcs_privacy_convertToJSON() failed [lpi]"); |
88 | 0 | goto end; |
89 | 0 | } |
90 | 0 | cJSON_AddItemToObject(item, "lpi", lpi_local_JSON); |
91 | 0 | if (item->child == NULL) { |
92 | 0 | ogs_error("OpenAPI_lcs_privacy_convertToJSON() failed [lpi]"); |
93 | 0 | goto end; |
94 | 0 | } |
95 | 0 | } |
96 | | |
97 | 0 | if (lcs_privacy->mtc_provider_information) { |
98 | 0 | if (cJSON_AddStringToObject(item, "mtcProviderInformation", lcs_privacy->mtc_provider_information) == NULL) { |
99 | 0 | ogs_error("OpenAPI_lcs_privacy_convertToJSON() failed [mtc_provider_information]"); |
100 | 0 | goto end; |
101 | 0 | } |
102 | 0 | } |
103 | | |
104 | 0 | if (lcs_privacy->evt_rpt_expected_area) { |
105 | 0 | cJSON *evt_rpt_expected_area_local_JSON = OpenAPI_geographic_area_convertToJSON(lcs_privacy->evt_rpt_expected_area); |
106 | 0 | if (evt_rpt_expected_area_local_JSON == NULL) { |
107 | 0 | ogs_error("OpenAPI_lcs_privacy_convertToJSON() failed [evt_rpt_expected_area]"); |
108 | 0 | goto end; |
109 | 0 | } |
110 | 0 | cJSON_AddItemToObject(item, "evtRptExpectedArea", evt_rpt_expected_area_local_JSON); |
111 | 0 | if (item->child == NULL) { |
112 | 0 | ogs_error("OpenAPI_lcs_privacy_convertToJSON() failed [evt_rpt_expected_area]"); |
113 | 0 | goto end; |
114 | 0 | } |
115 | 0 | } |
116 | | |
117 | 0 | if (lcs_privacy->area_usage_ind != OpenAPI_area_usage_ind_NULL) { |
118 | 0 | if (cJSON_AddStringToObject(item, "areaUsageInd", OpenAPI_area_usage_ind_ToString(lcs_privacy->area_usage_ind)) == NULL) { |
119 | 0 | ogs_error("OpenAPI_lcs_privacy_convertToJSON() failed [area_usage_ind]"); |
120 | 0 | goto end; |
121 | 0 | } |
122 | 0 | } |
123 | | |
124 | 0 | if (lcs_privacy->up_loc_rep_ind_af != OpenAPI_up_loc_rep_ind_af_NULL) { |
125 | 0 | if (cJSON_AddStringToObject(item, "upLocRepIndAf", OpenAPI_up_loc_rep_ind_af_ToString(lcs_privacy->up_loc_rep_ind_af)) == NULL) { |
126 | 0 | ogs_error("OpenAPI_lcs_privacy_convertToJSON() failed [up_loc_rep_ind_af]"); |
127 | 0 | goto end; |
128 | 0 | } |
129 | 0 | } |
130 | | |
131 | 0 | end: |
132 | 0 | return item; |
133 | 0 | } |
134 | | |
135 | | OpenAPI_lcs_privacy_t *OpenAPI_lcs_privacy_parseFromJSON(cJSON *lcs_privacyJSON) |
136 | 0 | { |
137 | 0 | OpenAPI_lcs_privacy_t *lcs_privacy_local_var = NULL; |
138 | 0 | OpenAPI_lnode_t *node = NULL; |
139 | 0 | cJSON *af_instance_id = NULL; |
140 | 0 | cJSON *reference_id = NULL; |
141 | 0 | cJSON *lpi = NULL; |
142 | 0 | OpenAPI_lpi_t *lpi_local_nonprim = NULL; |
143 | 0 | cJSON *mtc_provider_information = NULL; |
144 | 0 | cJSON *evt_rpt_expected_area = NULL; |
145 | 0 | OpenAPI_geographic_area_t *evt_rpt_expected_area_local_nonprim = NULL; |
146 | 0 | cJSON *area_usage_ind = NULL; |
147 | 0 | OpenAPI_area_usage_ind_e area_usage_indVariable = 0; |
148 | 0 | cJSON *up_loc_rep_ind_af = NULL; |
149 | 0 | OpenAPI_up_loc_rep_ind_af_e up_loc_rep_ind_afVariable = 0; |
150 | 0 | af_instance_id = cJSON_GetObjectItemCaseSensitive(lcs_privacyJSON, "afInstanceId"); |
151 | 0 | if (af_instance_id) { |
152 | 0 | if (!cJSON_IsString(af_instance_id) && !cJSON_IsNull(af_instance_id)) { |
153 | 0 | ogs_error("OpenAPI_lcs_privacy_parseFromJSON() failed [af_instance_id]"); |
154 | 0 | goto end; |
155 | 0 | } |
156 | 0 | } |
157 | | |
158 | 0 | reference_id = cJSON_GetObjectItemCaseSensitive(lcs_privacyJSON, "referenceId"); |
159 | 0 | if (reference_id) { |
160 | 0 | if (!cJSON_IsNumber(reference_id)) { |
161 | 0 | ogs_error("OpenAPI_lcs_privacy_parseFromJSON() failed [reference_id]"); |
162 | 0 | goto end; |
163 | 0 | } |
164 | 0 | } |
165 | | |
166 | 0 | lpi = cJSON_GetObjectItemCaseSensitive(lcs_privacyJSON, "lpi"); |
167 | 0 | if (lpi) { |
168 | 0 | lpi_local_nonprim = OpenAPI_lpi_parseFromJSON(lpi); |
169 | 0 | if (!lpi_local_nonprim) { |
170 | 0 | ogs_error("OpenAPI_lpi_parseFromJSON failed [lpi]"); |
171 | 0 | goto end; |
172 | 0 | } |
173 | 0 | } |
174 | | |
175 | 0 | mtc_provider_information = cJSON_GetObjectItemCaseSensitive(lcs_privacyJSON, "mtcProviderInformation"); |
176 | 0 | if (mtc_provider_information) { |
177 | 0 | if (!cJSON_IsString(mtc_provider_information) && !cJSON_IsNull(mtc_provider_information)) { |
178 | 0 | ogs_error("OpenAPI_lcs_privacy_parseFromJSON() failed [mtc_provider_information]"); |
179 | 0 | goto end; |
180 | 0 | } |
181 | 0 | } |
182 | | |
183 | 0 | evt_rpt_expected_area = cJSON_GetObjectItemCaseSensitive(lcs_privacyJSON, "evtRptExpectedArea"); |
184 | 0 | if (evt_rpt_expected_area) { |
185 | 0 | evt_rpt_expected_area_local_nonprim = OpenAPI_geographic_area_parseFromJSON(evt_rpt_expected_area); |
186 | 0 | if (!evt_rpt_expected_area_local_nonprim) { |
187 | 0 | ogs_error("OpenAPI_geographic_area_parseFromJSON failed [evt_rpt_expected_area]"); |
188 | 0 | goto end; |
189 | 0 | } |
190 | 0 | } |
191 | | |
192 | 0 | area_usage_ind = cJSON_GetObjectItemCaseSensitive(lcs_privacyJSON, "areaUsageInd"); |
193 | 0 | if (area_usage_ind) { |
194 | 0 | if (!cJSON_IsString(area_usage_ind)) { |
195 | 0 | ogs_error("OpenAPI_lcs_privacy_parseFromJSON() failed [area_usage_ind]"); |
196 | 0 | goto end; |
197 | 0 | } |
198 | 0 | area_usage_indVariable = OpenAPI_area_usage_ind_FromString(area_usage_ind->valuestring); |
199 | 0 | } |
200 | | |
201 | 0 | up_loc_rep_ind_af = cJSON_GetObjectItemCaseSensitive(lcs_privacyJSON, "upLocRepIndAf"); |
202 | 0 | if (up_loc_rep_ind_af) { |
203 | 0 | if (!cJSON_IsString(up_loc_rep_ind_af)) { |
204 | 0 | ogs_error("OpenAPI_lcs_privacy_parseFromJSON() failed [up_loc_rep_ind_af]"); |
205 | 0 | goto end; |
206 | 0 | } |
207 | 0 | up_loc_rep_ind_afVariable = OpenAPI_up_loc_rep_ind_af_FromString(up_loc_rep_ind_af->valuestring); |
208 | 0 | } |
209 | | |
210 | 0 | lcs_privacy_local_var = OpenAPI_lcs_privacy_create ( |
211 | 0 | af_instance_id && !cJSON_IsNull(af_instance_id) ? ogs_strdup(af_instance_id->valuestring) : NULL, |
212 | 0 | reference_id ? true : false, |
213 | 0 | reference_id ? reference_id->valuedouble : 0, |
214 | 0 | lpi ? lpi_local_nonprim : NULL, |
215 | 0 | mtc_provider_information && !cJSON_IsNull(mtc_provider_information) ? ogs_strdup(mtc_provider_information->valuestring) : NULL, |
216 | 0 | evt_rpt_expected_area ? evt_rpt_expected_area_local_nonprim : NULL, |
217 | 0 | area_usage_ind ? area_usage_indVariable : 0, |
218 | 0 | up_loc_rep_ind_af ? up_loc_rep_ind_afVariable : 0 |
219 | 0 | ); |
220 | |
|
221 | 0 | return lcs_privacy_local_var; |
222 | 0 | end: |
223 | 0 | if (lpi_local_nonprim) { |
224 | 0 | OpenAPI_lpi_free(lpi_local_nonprim); |
225 | 0 | lpi_local_nonprim = NULL; |
226 | 0 | } |
227 | 0 | if (evt_rpt_expected_area_local_nonprim) { |
228 | 0 | OpenAPI_geographic_area_free(evt_rpt_expected_area_local_nonprim); |
229 | 0 | evt_rpt_expected_area_local_nonprim = NULL; |
230 | 0 | } |
231 | 0 | return NULL; |
232 | 0 | } |
233 | | |
234 | | OpenAPI_lcs_privacy_t *OpenAPI_lcs_privacy_copy(OpenAPI_lcs_privacy_t *dst, OpenAPI_lcs_privacy_t *src) |
235 | 0 | { |
236 | 0 | cJSON *item = NULL; |
237 | 0 | char *content = NULL; |
238 | |
|
239 | 0 | ogs_assert(src); |
240 | 0 | item = OpenAPI_lcs_privacy_convertToJSON(src); |
241 | 0 | if (!item) { |
242 | 0 | ogs_error("OpenAPI_lcs_privacy_convertToJSON() failed"); |
243 | 0 | return NULL; |
244 | 0 | } |
245 | | |
246 | 0 | content = cJSON_Print(item); |
247 | 0 | cJSON_Delete(item); |
248 | |
|
249 | 0 | if (!content) { |
250 | 0 | ogs_error("cJSON_Print() failed"); |
251 | 0 | return NULL; |
252 | 0 | } |
253 | | |
254 | 0 | item = cJSON_Parse(content); |
255 | 0 | ogs_free(content); |
256 | 0 | if (!item) { |
257 | 0 | ogs_error("cJSON_Parse() failed"); |
258 | 0 | return NULL; |
259 | 0 | } |
260 | | |
261 | 0 | OpenAPI_lcs_privacy_free(dst); |
262 | 0 | dst = OpenAPI_lcs_privacy_parseFromJSON(item); |
263 | 0 | cJSON_Delete(item); |
264 | |
|
265 | 0 | return dst; |
266 | 0 | } |
267 | | |