/src/open5gs/lib/sbi/openapi/model/unrelated_class.c
Line | Count | Source |
1 | | |
2 | | #include <stdlib.h> |
3 | | #include <string.h> |
4 | | #include <stdio.h> |
5 | | #include "unrelated_class.h" |
6 | | |
7 | | OpenAPI_unrelated_class_t *OpenAPI_unrelated_class_create( |
8 | | OpenAPI_default_unrelated_class_t *default_unrelated_class, |
9 | | OpenAPI_external_unrelated_class_t *external_unrelated_class, |
10 | | OpenAPI_list_t *service_type_unrelated_classes |
11 | | ) |
12 | 0 | { |
13 | 0 | OpenAPI_unrelated_class_t *unrelated_class_local_var = ogs_malloc(sizeof(OpenAPI_unrelated_class_t)); |
14 | 0 | ogs_assert(unrelated_class_local_var); |
15 | | |
16 | 0 | unrelated_class_local_var->default_unrelated_class = default_unrelated_class; |
17 | 0 | unrelated_class_local_var->external_unrelated_class = external_unrelated_class; |
18 | 0 | unrelated_class_local_var->service_type_unrelated_classes = service_type_unrelated_classes; |
19 | |
|
20 | 0 | return unrelated_class_local_var; |
21 | 0 | } |
22 | | |
23 | | void OpenAPI_unrelated_class_free(OpenAPI_unrelated_class_t *unrelated_class) |
24 | 0 | { |
25 | 0 | OpenAPI_lnode_t *node = NULL; |
26 | |
|
27 | 0 | if (NULL == unrelated_class) { |
28 | 0 | return; |
29 | 0 | } |
30 | 0 | if (unrelated_class->default_unrelated_class) { |
31 | 0 | OpenAPI_default_unrelated_class_free(unrelated_class->default_unrelated_class); |
32 | 0 | unrelated_class->default_unrelated_class = NULL; |
33 | 0 | } |
34 | 0 | if (unrelated_class->external_unrelated_class) { |
35 | 0 | OpenAPI_external_unrelated_class_free(unrelated_class->external_unrelated_class); |
36 | 0 | unrelated_class->external_unrelated_class = NULL; |
37 | 0 | } |
38 | 0 | if (unrelated_class->service_type_unrelated_classes) { |
39 | 0 | OpenAPI_list_for_each(unrelated_class->service_type_unrelated_classes, node) { |
40 | 0 | OpenAPI_service_type_unrelated_class_free(node->data); |
41 | 0 | } |
42 | 0 | OpenAPI_list_free(unrelated_class->service_type_unrelated_classes); |
43 | 0 | unrelated_class->service_type_unrelated_classes = NULL; |
44 | 0 | } |
45 | 0 | ogs_free(unrelated_class); |
46 | 0 | } |
47 | | |
48 | | cJSON *OpenAPI_unrelated_class_convertToJSON(OpenAPI_unrelated_class_t *unrelated_class) |
49 | 0 | { |
50 | 0 | cJSON *item = NULL; |
51 | 0 | OpenAPI_lnode_t *node = NULL; |
52 | |
|
53 | 0 | if (unrelated_class == NULL) { |
54 | 0 | ogs_error("OpenAPI_unrelated_class_convertToJSON() failed [UnrelatedClass]"); |
55 | 0 | return NULL; |
56 | 0 | } |
57 | | |
58 | 0 | item = cJSON_CreateObject(); |
59 | 0 | if (!unrelated_class->default_unrelated_class) { |
60 | 0 | ogs_error("OpenAPI_unrelated_class_convertToJSON() failed [default_unrelated_class]"); |
61 | 0 | return NULL; |
62 | 0 | } |
63 | 0 | cJSON *default_unrelated_class_local_JSON = OpenAPI_default_unrelated_class_convertToJSON(unrelated_class->default_unrelated_class); |
64 | 0 | if (default_unrelated_class_local_JSON == NULL) { |
65 | 0 | ogs_error("OpenAPI_unrelated_class_convertToJSON() failed [default_unrelated_class]"); |
66 | 0 | goto end; |
67 | 0 | } |
68 | 0 | cJSON_AddItemToObject(item, "defaultUnrelatedClass", default_unrelated_class_local_JSON); |
69 | 0 | if (item->child == NULL) { |
70 | 0 | ogs_error("OpenAPI_unrelated_class_convertToJSON() failed [default_unrelated_class]"); |
71 | 0 | goto end; |
72 | 0 | } |
73 | | |
74 | 0 | if (unrelated_class->external_unrelated_class) { |
75 | 0 | cJSON *external_unrelated_class_local_JSON = OpenAPI_external_unrelated_class_convertToJSON(unrelated_class->external_unrelated_class); |
76 | 0 | if (external_unrelated_class_local_JSON == NULL) { |
77 | 0 | ogs_error("OpenAPI_unrelated_class_convertToJSON() failed [external_unrelated_class]"); |
78 | 0 | goto end; |
79 | 0 | } |
80 | 0 | cJSON_AddItemToObject(item, "externalUnrelatedClass", external_unrelated_class_local_JSON); |
81 | 0 | if (item->child == NULL) { |
82 | 0 | ogs_error("OpenAPI_unrelated_class_convertToJSON() failed [external_unrelated_class]"); |
83 | 0 | goto end; |
84 | 0 | } |
85 | 0 | } |
86 | | |
87 | 0 | if (unrelated_class->service_type_unrelated_classes) { |
88 | 0 | cJSON *service_type_unrelated_classesList = cJSON_AddArrayToObject(item, "serviceTypeUnrelatedClasses"); |
89 | 0 | if (service_type_unrelated_classesList == NULL) { |
90 | 0 | ogs_error("OpenAPI_unrelated_class_convertToJSON() failed [service_type_unrelated_classes]"); |
91 | 0 | goto end; |
92 | 0 | } |
93 | 0 | OpenAPI_list_for_each(unrelated_class->service_type_unrelated_classes, node) { |
94 | 0 | cJSON *itemLocal = OpenAPI_service_type_unrelated_class_convertToJSON(node->data); |
95 | 0 | if (itemLocal == NULL) { |
96 | 0 | ogs_error("OpenAPI_unrelated_class_convertToJSON() failed [service_type_unrelated_classes]"); |
97 | 0 | goto end; |
98 | 0 | } |
99 | 0 | cJSON_AddItemToArray(service_type_unrelated_classesList, itemLocal); |
100 | 0 | } |
101 | 0 | } |
102 | | |
103 | 0 | end: |
104 | 0 | return item; |
105 | 0 | } |
106 | | |
107 | | OpenAPI_unrelated_class_t *OpenAPI_unrelated_class_parseFromJSON(cJSON *unrelated_classJSON) |
108 | 0 | { |
109 | 0 | OpenAPI_unrelated_class_t *unrelated_class_local_var = NULL; |
110 | 0 | OpenAPI_lnode_t *node = NULL; |
111 | 0 | cJSON *default_unrelated_class = NULL; |
112 | 0 | OpenAPI_default_unrelated_class_t *default_unrelated_class_local_nonprim = NULL; |
113 | 0 | cJSON *external_unrelated_class = NULL; |
114 | 0 | OpenAPI_external_unrelated_class_t *external_unrelated_class_local_nonprim = NULL; |
115 | 0 | cJSON *service_type_unrelated_classes = NULL; |
116 | 0 | OpenAPI_list_t *service_type_unrelated_classesList = NULL; |
117 | 0 | default_unrelated_class = cJSON_GetObjectItemCaseSensitive(unrelated_classJSON, "defaultUnrelatedClass"); |
118 | 0 | if (!default_unrelated_class) { |
119 | 0 | ogs_error("OpenAPI_unrelated_class_parseFromJSON() failed [default_unrelated_class]"); |
120 | 0 | goto end; |
121 | 0 | } |
122 | 0 | default_unrelated_class_local_nonprim = OpenAPI_default_unrelated_class_parseFromJSON(default_unrelated_class); |
123 | 0 | if (!default_unrelated_class_local_nonprim) { |
124 | 0 | ogs_error("OpenAPI_default_unrelated_class_parseFromJSON failed [default_unrelated_class]"); |
125 | 0 | goto end; |
126 | 0 | } |
127 | | |
128 | 0 | external_unrelated_class = cJSON_GetObjectItemCaseSensitive(unrelated_classJSON, "externalUnrelatedClass"); |
129 | 0 | if (external_unrelated_class) { |
130 | 0 | external_unrelated_class_local_nonprim = OpenAPI_external_unrelated_class_parseFromJSON(external_unrelated_class); |
131 | 0 | if (!external_unrelated_class_local_nonprim) { |
132 | 0 | ogs_error("OpenAPI_external_unrelated_class_parseFromJSON failed [external_unrelated_class]"); |
133 | 0 | goto end; |
134 | 0 | } |
135 | 0 | } |
136 | | |
137 | 0 | service_type_unrelated_classes = cJSON_GetObjectItemCaseSensitive(unrelated_classJSON, "serviceTypeUnrelatedClasses"); |
138 | 0 | if (service_type_unrelated_classes) { |
139 | 0 | cJSON *service_type_unrelated_classes_local = NULL; |
140 | 0 | if (!cJSON_IsArray(service_type_unrelated_classes)) { |
141 | 0 | ogs_error("OpenAPI_unrelated_class_parseFromJSON() failed [service_type_unrelated_classes]"); |
142 | 0 | goto end; |
143 | 0 | } |
144 | | |
145 | 0 | service_type_unrelated_classesList = OpenAPI_list_create(); |
146 | |
|
147 | 0 | cJSON_ArrayForEach(service_type_unrelated_classes_local, service_type_unrelated_classes) { |
148 | 0 | if (!cJSON_IsObject(service_type_unrelated_classes_local)) { |
149 | 0 | ogs_error("OpenAPI_unrelated_class_parseFromJSON() failed [service_type_unrelated_classes]"); |
150 | 0 | goto end; |
151 | 0 | } |
152 | 0 | OpenAPI_service_type_unrelated_class_t *service_type_unrelated_classesItem = OpenAPI_service_type_unrelated_class_parseFromJSON(service_type_unrelated_classes_local); |
153 | 0 | if (!service_type_unrelated_classesItem) { |
154 | 0 | ogs_error("No service_type_unrelated_classesItem"); |
155 | 0 | goto end; |
156 | 0 | } |
157 | 0 | OpenAPI_list_add(service_type_unrelated_classesList, service_type_unrelated_classesItem); |
158 | 0 | } |
159 | 0 | } |
160 | | |
161 | 0 | unrelated_class_local_var = OpenAPI_unrelated_class_create ( |
162 | 0 | default_unrelated_class_local_nonprim, |
163 | 0 | external_unrelated_class ? external_unrelated_class_local_nonprim : NULL, |
164 | 0 | service_type_unrelated_classes ? service_type_unrelated_classesList : NULL |
165 | 0 | ); |
166 | |
|
167 | 0 | return unrelated_class_local_var; |
168 | 0 | end: |
169 | 0 | if (default_unrelated_class_local_nonprim) { |
170 | 0 | OpenAPI_default_unrelated_class_free(default_unrelated_class_local_nonprim); |
171 | 0 | default_unrelated_class_local_nonprim = NULL; |
172 | 0 | } |
173 | 0 | if (external_unrelated_class_local_nonprim) { |
174 | 0 | OpenAPI_external_unrelated_class_free(external_unrelated_class_local_nonprim); |
175 | 0 | external_unrelated_class_local_nonprim = NULL; |
176 | 0 | } |
177 | 0 | if (service_type_unrelated_classesList) { |
178 | 0 | OpenAPI_list_for_each(service_type_unrelated_classesList, node) { |
179 | 0 | OpenAPI_service_type_unrelated_class_free(node->data); |
180 | 0 | } |
181 | 0 | OpenAPI_list_free(service_type_unrelated_classesList); |
182 | 0 | service_type_unrelated_classesList = NULL; |
183 | 0 | } |
184 | 0 | return NULL; |
185 | 0 | } |
186 | | |
187 | | OpenAPI_unrelated_class_t *OpenAPI_unrelated_class_copy(OpenAPI_unrelated_class_t *dst, OpenAPI_unrelated_class_t *src) |
188 | 0 | { |
189 | 0 | cJSON *item = NULL; |
190 | 0 | char *content = NULL; |
191 | |
|
192 | 0 | ogs_assert(src); |
193 | 0 | item = OpenAPI_unrelated_class_convertToJSON(src); |
194 | 0 | if (!item) { |
195 | 0 | ogs_error("OpenAPI_unrelated_class_convertToJSON() failed"); |
196 | 0 | return NULL; |
197 | 0 | } |
198 | | |
199 | 0 | content = cJSON_Print(item); |
200 | 0 | cJSON_Delete(item); |
201 | |
|
202 | 0 | if (!content) { |
203 | 0 | ogs_error("cJSON_Print() failed"); |
204 | 0 | return NULL; |
205 | 0 | } |
206 | | |
207 | 0 | item = cJSON_Parse(content); |
208 | 0 | ogs_free(content); |
209 | 0 | if (!item) { |
210 | 0 | ogs_error("cJSON_Parse() failed"); |
211 | 0 | return NULL; |
212 | 0 | } |
213 | | |
214 | 0 | OpenAPI_unrelated_class_free(dst); |
215 | 0 | dst = OpenAPI_unrelated_class_parseFromJSON(item); |
216 | 0 | cJSON_Delete(item); |
217 | |
|
218 | 0 | return dst; |
219 | 0 | } |
220 | | |