/src/open5gs/lib/sbi/openapi/model/trace_data.c
Line | Count | Source |
1 | | |
2 | | #include <stdlib.h> |
3 | | #include <string.h> |
4 | | #include <stdio.h> |
5 | | #include "trace_data.h" |
6 | | |
7 | | OpenAPI_trace_data_t *OpenAPI_trace_data_create( |
8 | | char *trace_ref, |
9 | | OpenAPI_trace_depth_e trace_depth, |
10 | | char *ne_type_list, |
11 | | char *event_list, |
12 | | char *collection_entity_ipv4_addr, |
13 | | char *collection_entity_ipv6_addr, |
14 | | char *trace_reporting_consumer_uri, |
15 | | char *interface_list, |
16 | | OpenAPI_job_type_e job_type |
17 | | ) |
18 | 186 | { |
19 | 186 | OpenAPI_trace_data_t *trace_data_local_var = ogs_malloc(sizeof(OpenAPI_trace_data_t)); |
20 | 186 | ogs_assert(trace_data_local_var); |
21 | | |
22 | 186 | trace_data_local_var->trace_ref = trace_ref; |
23 | 186 | trace_data_local_var->trace_depth = trace_depth; |
24 | 186 | trace_data_local_var->ne_type_list = ne_type_list; |
25 | 186 | trace_data_local_var->event_list = event_list; |
26 | 186 | trace_data_local_var->collection_entity_ipv4_addr = collection_entity_ipv4_addr; |
27 | 186 | trace_data_local_var->collection_entity_ipv6_addr = collection_entity_ipv6_addr; |
28 | 186 | trace_data_local_var->trace_reporting_consumer_uri = trace_reporting_consumer_uri; |
29 | 186 | trace_data_local_var->interface_list = interface_list; |
30 | 186 | trace_data_local_var->job_type = job_type; |
31 | | |
32 | 186 | return trace_data_local_var; |
33 | 186 | } |
34 | | |
35 | | void OpenAPI_trace_data_free(OpenAPI_trace_data_t *trace_data) |
36 | 151 | { |
37 | 151 | OpenAPI_lnode_t *node = NULL; |
38 | | |
39 | 151 | if (NULL == trace_data) { |
40 | 0 | return; |
41 | 0 | } |
42 | 151 | if (trace_data->trace_ref) { |
43 | 151 | ogs_free(trace_data->trace_ref); |
44 | 151 | trace_data->trace_ref = NULL; |
45 | 151 | } |
46 | 151 | if (trace_data->ne_type_list) { |
47 | 151 | ogs_free(trace_data->ne_type_list); |
48 | 151 | trace_data->ne_type_list = NULL; |
49 | 151 | } |
50 | 151 | if (trace_data->event_list) { |
51 | 151 | ogs_free(trace_data->event_list); |
52 | 151 | trace_data->event_list = NULL; |
53 | 151 | } |
54 | 151 | if (trace_data->collection_entity_ipv4_addr) { |
55 | 27 | ogs_free(trace_data->collection_entity_ipv4_addr); |
56 | 27 | trace_data->collection_entity_ipv4_addr = NULL; |
57 | 27 | } |
58 | 151 | if (trace_data->collection_entity_ipv6_addr) { |
59 | 18 | ogs_free(trace_data->collection_entity_ipv6_addr); |
60 | 18 | trace_data->collection_entity_ipv6_addr = NULL; |
61 | 18 | } |
62 | 151 | if (trace_data->trace_reporting_consumer_uri) { |
63 | 0 | ogs_free(trace_data->trace_reporting_consumer_uri); |
64 | 0 | trace_data->trace_reporting_consumer_uri = NULL; |
65 | 0 | } |
66 | 151 | if (trace_data->interface_list) { |
67 | 0 | ogs_free(trace_data->interface_list); |
68 | 0 | trace_data->interface_list = NULL; |
69 | 0 | } |
70 | 151 | ogs_free(trace_data); |
71 | 151 | } |
72 | | |
73 | | cJSON *OpenAPI_trace_data_convertToJSON(OpenAPI_trace_data_t *trace_data) |
74 | 0 | { |
75 | 0 | cJSON *item = NULL; |
76 | 0 | OpenAPI_lnode_t *node = NULL; |
77 | |
|
78 | 0 | if (trace_data == NULL) { |
79 | 0 | ogs_error("OpenAPI_trace_data_convertToJSON() failed [TraceData]"); |
80 | 0 | return NULL; |
81 | 0 | } |
82 | | |
83 | 0 | item = cJSON_CreateObject(); |
84 | 0 | if (!trace_data->trace_ref) { |
85 | 0 | ogs_error("OpenAPI_trace_data_convertToJSON() failed [trace_ref]"); |
86 | 0 | return NULL; |
87 | 0 | } |
88 | 0 | if (cJSON_AddStringToObject(item, "traceRef", trace_data->trace_ref) == NULL) { |
89 | 0 | ogs_error("OpenAPI_trace_data_convertToJSON() failed [trace_ref]"); |
90 | 0 | goto end; |
91 | 0 | } |
92 | | |
93 | 0 | if (trace_data->trace_depth == OpenAPI_trace_depth_NULL) { |
94 | 0 | ogs_error("OpenAPI_trace_data_convertToJSON() failed [trace_depth]"); |
95 | 0 | return NULL; |
96 | 0 | } |
97 | 0 | if (cJSON_AddStringToObject(item, "traceDepth", OpenAPI_trace_depth_ToString(trace_data->trace_depth)) == NULL) { |
98 | 0 | ogs_error("OpenAPI_trace_data_convertToJSON() failed [trace_depth]"); |
99 | 0 | goto end; |
100 | 0 | } |
101 | | |
102 | 0 | if (!trace_data->ne_type_list) { |
103 | 0 | ogs_error("OpenAPI_trace_data_convertToJSON() failed [ne_type_list]"); |
104 | 0 | return NULL; |
105 | 0 | } |
106 | 0 | if (cJSON_AddStringToObject(item, "neTypeList", trace_data->ne_type_list) == NULL) { |
107 | 0 | ogs_error("OpenAPI_trace_data_convertToJSON() failed [ne_type_list]"); |
108 | 0 | goto end; |
109 | 0 | } |
110 | | |
111 | 0 | if (!trace_data->event_list) { |
112 | 0 | ogs_error("OpenAPI_trace_data_convertToJSON() failed [event_list]"); |
113 | 0 | return NULL; |
114 | 0 | } |
115 | 0 | if (cJSON_AddStringToObject(item, "eventList", trace_data->event_list) == NULL) { |
116 | 0 | ogs_error("OpenAPI_trace_data_convertToJSON() failed [event_list]"); |
117 | 0 | goto end; |
118 | 0 | } |
119 | | |
120 | 0 | if (trace_data->collection_entity_ipv4_addr) { |
121 | 0 | if (cJSON_AddStringToObject(item, "collectionEntityIpv4Addr", trace_data->collection_entity_ipv4_addr) == NULL) { |
122 | 0 | ogs_error("OpenAPI_trace_data_convertToJSON() failed [collection_entity_ipv4_addr]"); |
123 | 0 | goto end; |
124 | 0 | } |
125 | 0 | } |
126 | | |
127 | 0 | if (trace_data->collection_entity_ipv6_addr) { |
128 | 0 | if (cJSON_AddStringToObject(item, "collectionEntityIpv6Addr", trace_data->collection_entity_ipv6_addr) == NULL) { |
129 | 0 | ogs_error("OpenAPI_trace_data_convertToJSON() failed [collection_entity_ipv6_addr]"); |
130 | 0 | goto end; |
131 | 0 | } |
132 | 0 | } |
133 | | |
134 | 0 | if (trace_data->trace_reporting_consumer_uri) { |
135 | 0 | if (cJSON_AddStringToObject(item, "traceReportingConsumerUri", trace_data->trace_reporting_consumer_uri) == NULL) { |
136 | 0 | ogs_error("OpenAPI_trace_data_convertToJSON() failed [trace_reporting_consumer_uri]"); |
137 | 0 | goto end; |
138 | 0 | } |
139 | 0 | } |
140 | | |
141 | 0 | if (trace_data->interface_list) { |
142 | 0 | if (cJSON_AddStringToObject(item, "interfaceList", trace_data->interface_list) == NULL) { |
143 | 0 | ogs_error("OpenAPI_trace_data_convertToJSON() failed [interface_list]"); |
144 | 0 | goto end; |
145 | 0 | } |
146 | 0 | } |
147 | | |
148 | 0 | if (trace_data->job_type != OpenAPI_job_type_NULL) { |
149 | 0 | if (cJSON_AddStringToObject(item, "jobType", OpenAPI_job_type_ToString(trace_data->job_type)) == NULL) { |
150 | 0 | ogs_error("OpenAPI_trace_data_convertToJSON() failed [job_type]"); |
151 | 0 | goto end; |
152 | 0 | } |
153 | 0 | } |
154 | | |
155 | 0 | end: |
156 | 0 | return item; |
157 | 0 | } |
158 | | |
159 | | OpenAPI_trace_data_t *OpenAPI_trace_data_parseFromJSON(cJSON *trace_dataJSON) |
160 | 776 | { |
161 | 776 | OpenAPI_trace_data_t *trace_data_local_var = NULL; |
162 | 776 | OpenAPI_lnode_t *node = NULL; |
163 | 776 | cJSON *trace_ref = NULL; |
164 | 776 | cJSON *trace_depth = NULL; |
165 | 776 | OpenAPI_trace_depth_e trace_depthVariable = 0; |
166 | 776 | cJSON *ne_type_list = NULL; |
167 | 776 | cJSON *event_list = NULL; |
168 | 776 | cJSON *collection_entity_ipv4_addr = NULL; |
169 | 776 | cJSON *collection_entity_ipv6_addr = NULL; |
170 | 776 | cJSON *trace_reporting_consumer_uri = NULL; |
171 | 776 | cJSON *interface_list = NULL; |
172 | 776 | cJSON *job_type = NULL; |
173 | 776 | OpenAPI_job_type_e job_typeVariable = 0; |
174 | 776 | trace_ref = cJSON_GetObjectItemCaseSensitive(trace_dataJSON, "traceRef"); |
175 | 776 | if (!trace_ref) { |
176 | 104 | ogs_error("OpenAPI_trace_data_parseFromJSON() failed [trace_ref]"); |
177 | 104 | goto end; |
178 | 104 | } |
179 | 672 | if (!cJSON_IsString(trace_ref)) { |
180 | 20 | ogs_error("OpenAPI_trace_data_parseFromJSON() failed [trace_ref]"); |
181 | 20 | goto end; |
182 | 20 | } |
183 | | |
184 | 652 | trace_depth = cJSON_GetObjectItemCaseSensitive(trace_dataJSON, "traceDepth"); |
185 | 652 | if (!trace_depth) { |
186 | 33 | ogs_error("OpenAPI_trace_data_parseFromJSON() failed [trace_depth]"); |
187 | 33 | goto end; |
188 | 33 | } |
189 | 619 | if (!cJSON_IsString(trace_depth)) { |
190 | 16 | ogs_error("OpenAPI_trace_data_parseFromJSON() failed [trace_depth]"); |
191 | 16 | goto end; |
192 | 16 | } |
193 | 603 | trace_depthVariable = OpenAPI_trace_depth_FromString(trace_depth->valuestring); |
194 | | |
195 | 603 | ne_type_list = cJSON_GetObjectItemCaseSensitive(trace_dataJSON, "neTypeList"); |
196 | 603 | if (!ne_type_list) { |
197 | 351 | ogs_error("OpenAPI_trace_data_parseFromJSON() failed [ne_type_list]"); |
198 | 351 | goto end; |
199 | 351 | } |
200 | 252 | if (!cJSON_IsString(ne_type_list)) { |
201 | 11 | ogs_error("OpenAPI_trace_data_parseFromJSON() failed [ne_type_list]"); |
202 | 11 | goto end; |
203 | 11 | } |
204 | | |
205 | 241 | event_list = cJSON_GetObjectItemCaseSensitive(trace_dataJSON, "eventList"); |
206 | 241 | if (!event_list) { |
207 | 22 | ogs_error("OpenAPI_trace_data_parseFromJSON() failed [event_list]"); |
208 | 22 | goto end; |
209 | 22 | } |
210 | 219 | if (!cJSON_IsString(event_list)) { |
211 | 10 | ogs_error("OpenAPI_trace_data_parseFromJSON() failed [event_list]"); |
212 | 10 | goto end; |
213 | 10 | } |
214 | | |
215 | 209 | collection_entity_ipv4_addr = cJSON_GetObjectItemCaseSensitive(trace_dataJSON, "collectionEntityIpv4Addr"); |
216 | 209 | if (collection_entity_ipv4_addr) { |
217 | 58 | if (!cJSON_IsString(collection_entity_ipv4_addr) && !cJSON_IsNull(collection_entity_ipv4_addr)) { |
218 | 10 | ogs_error("OpenAPI_trace_data_parseFromJSON() failed [collection_entity_ipv4_addr]"); |
219 | 10 | goto end; |
220 | 10 | } |
221 | 58 | } |
222 | | |
223 | 199 | collection_entity_ipv6_addr = cJSON_GetObjectItemCaseSensitive(trace_dataJSON, "collectionEntityIpv6Addr"); |
224 | 199 | if (collection_entity_ipv6_addr) { |
225 | 43 | if (!cJSON_IsString(collection_entity_ipv6_addr) && !cJSON_IsNull(collection_entity_ipv6_addr)) { |
226 | 10 | ogs_error("OpenAPI_trace_data_parseFromJSON() failed [collection_entity_ipv6_addr]"); |
227 | 10 | goto end; |
228 | 10 | } |
229 | 43 | } |
230 | | |
231 | 189 | trace_reporting_consumer_uri = cJSON_GetObjectItemCaseSensitive(trace_dataJSON, "traceReportingConsumerUri"); |
232 | 189 | if (trace_reporting_consumer_uri) { |
233 | 3 | if (!cJSON_IsString(trace_reporting_consumer_uri) && !cJSON_IsNull(trace_reporting_consumer_uri)) { |
234 | 0 | ogs_error("OpenAPI_trace_data_parseFromJSON() failed [trace_reporting_consumer_uri]"); |
235 | 0 | goto end; |
236 | 0 | } |
237 | 3 | } |
238 | | |
239 | 189 | interface_list = cJSON_GetObjectItemCaseSensitive(trace_dataJSON, "interfaceList"); |
240 | 189 | if (interface_list) { |
241 | 0 | if (!cJSON_IsString(interface_list) && !cJSON_IsNull(interface_list)) { |
242 | 0 | ogs_error("OpenAPI_trace_data_parseFromJSON() failed [interface_list]"); |
243 | 0 | goto end; |
244 | 0 | } |
245 | 0 | } |
246 | | |
247 | 189 | job_type = cJSON_GetObjectItemCaseSensitive(trace_dataJSON, "jobType"); |
248 | 189 | if (job_type) { |
249 | 18 | if (!cJSON_IsString(job_type)) { |
250 | 3 | ogs_error("OpenAPI_trace_data_parseFromJSON() failed [job_type]"); |
251 | 3 | goto end; |
252 | 3 | } |
253 | 15 | job_typeVariable = OpenAPI_job_type_FromString(job_type->valuestring); |
254 | 15 | } |
255 | | |
256 | 186 | trace_data_local_var = OpenAPI_trace_data_create ( |
257 | 186 | ogs_strdup(trace_ref->valuestring), |
258 | 186 | trace_depthVariable, |
259 | 186 | ogs_strdup(ne_type_list->valuestring), |
260 | 186 | ogs_strdup(event_list->valuestring), |
261 | 186 | collection_entity_ipv4_addr && !cJSON_IsNull(collection_entity_ipv4_addr) ? ogs_strdup(collection_entity_ipv4_addr->valuestring) : NULL, |
262 | 186 | collection_entity_ipv6_addr && !cJSON_IsNull(collection_entity_ipv6_addr) ? ogs_strdup(collection_entity_ipv6_addr->valuestring) : NULL, |
263 | 186 | trace_reporting_consumer_uri && !cJSON_IsNull(trace_reporting_consumer_uri) ? ogs_strdup(trace_reporting_consumer_uri->valuestring) : NULL, |
264 | 186 | interface_list && !cJSON_IsNull(interface_list) ? ogs_strdup(interface_list->valuestring) : NULL, |
265 | 186 | job_type ? job_typeVariable : 0 |
266 | 186 | ); |
267 | | |
268 | 186 | return trace_data_local_var; |
269 | 590 | end: |
270 | 590 | return NULL; |
271 | 189 | } |
272 | | |
273 | | OpenAPI_trace_data_t *OpenAPI_trace_data_copy(OpenAPI_trace_data_t *dst, OpenAPI_trace_data_t *src) |
274 | 0 | { |
275 | 0 | cJSON *item = NULL; |
276 | 0 | char *content = NULL; |
277 | |
|
278 | 0 | ogs_assert(src); |
279 | 0 | item = OpenAPI_trace_data_convertToJSON(src); |
280 | 0 | if (!item) { |
281 | 0 | ogs_error("OpenAPI_trace_data_convertToJSON() failed"); |
282 | 0 | return NULL; |
283 | 0 | } |
284 | | |
285 | 0 | content = cJSON_Print(item); |
286 | 0 | cJSON_Delete(item); |
287 | |
|
288 | 0 | if (!content) { |
289 | 0 | ogs_error("cJSON_Print() failed"); |
290 | 0 | return NULL; |
291 | 0 | } |
292 | | |
293 | 0 | item = cJSON_Parse(content); |
294 | 0 | ogs_free(content); |
295 | 0 | if (!item) { |
296 | 0 | ogs_error("cJSON_Parse() failed"); |
297 | 0 | return NULL; |
298 | 0 | } |
299 | | |
300 | 0 | OpenAPI_trace_data_free(dst); |
301 | 0 | dst = OpenAPI_trace_data_parseFromJSON(item); |
302 | 0 | cJSON_Delete(item); |
303 | |
|
304 | 0 | return dst; |
305 | 0 | } |
306 | | |