/src/open5gs/lib/sbi/openapi/model/ncgi_tai.c
Line | Count | Source |
1 | | |
2 | | #include <stdlib.h> |
3 | | #include <string.h> |
4 | | #include <stdio.h> |
5 | | #include "ncgi_tai.h" |
6 | | |
7 | | OpenAPI_ncgi_tai_t *OpenAPI_ncgi_tai_create( |
8 | | OpenAPI_tai_t *tai, |
9 | | OpenAPI_list_t *cell_list |
10 | | ) |
11 | 0 | { |
12 | 0 | OpenAPI_ncgi_tai_t *ncgi_tai_local_var = ogs_malloc(sizeof(OpenAPI_ncgi_tai_t)); |
13 | 0 | ogs_assert(ncgi_tai_local_var); |
14 | | |
15 | 0 | ncgi_tai_local_var->tai = tai; |
16 | 0 | ncgi_tai_local_var->cell_list = cell_list; |
17 | |
|
18 | 0 | return ncgi_tai_local_var; |
19 | 0 | } |
20 | | |
21 | | void OpenAPI_ncgi_tai_free(OpenAPI_ncgi_tai_t *ncgi_tai) |
22 | 0 | { |
23 | 0 | OpenAPI_lnode_t *node = NULL; |
24 | |
|
25 | 0 | if (NULL == ncgi_tai) { |
26 | 0 | return; |
27 | 0 | } |
28 | 0 | if (ncgi_tai->tai) { |
29 | 0 | OpenAPI_tai_free(ncgi_tai->tai); |
30 | 0 | ncgi_tai->tai = NULL; |
31 | 0 | } |
32 | 0 | if (ncgi_tai->cell_list) { |
33 | 0 | OpenAPI_list_for_each(ncgi_tai->cell_list, node) { |
34 | 0 | OpenAPI_ncgi_free(node->data); |
35 | 0 | } |
36 | 0 | OpenAPI_list_free(ncgi_tai->cell_list); |
37 | 0 | ncgi_tai->cell_list = NULL; |
38 | 0 | } |
39 | 0 | ogs_free(ncgi_tai); |
40 | 0 | } |
41 | | |
42 | | cJSON *OpenAPI_ncgi_tai_convertToJSON(OpenAPI_ncgi_tai_t *ncgi_tai) |
43 | 0 | { |
44 | 0 | cJSON *item = NULL; |
45 | 0 | OpenAPI_lnode_t *node = NULL; |
46 | |
|
47 | 0 | if (ncgi_tai == NULL) { |
48 | 0 | ogs_error("OpenAPI_ncgi_tai_convertToJSON() failed [NcgiTai]"); |
49 | 0 | return NULL; |
50 | 0 | } |
51 | | |
52 | 0 | item = cJSON_CreateObject(); |
53 | 0 | if (!ncgi_tai->tai) { |
54 | 0 | ogs_error("OpenAPI_ncgi_tai_convertToJSON() failed [tai]"); |
55 | 0 | return NULL; |
56 | 0 | } |
57 | 0 | cJSON *tai_local_JSON = OpenAPI_tai_convertToJSON(ncgi_tai->tai); |
58 | 0 | if (tai_local_JSON == NULL) { |
59 | 0 | ogs_error("OpenAPI_ncgi_tai_convertToJSON() failed [tai]"); |
60 | 0 | goto end; |
61 | 0 | } |
62 | 0 | cJSON_AddItemToObject(item, "tai", tai_local_JSON); |
63 | 0 | if (item->child == NULL) { |
64 | 0 | ogs_error("OpenAPI_ncgi_tai_convertToJSON() failed [tai]"); |
65 | 0 | goto end; |
66 | 0 | } |
67 | | |
68 | 0 | if (!ncgi_tai->cell_list) { |
69 | 0 | ogs_error("OpenAPI_ncgi_tai_convertToJSON() failed [cell_list]"); |
70 | 0 | return NULL; |
71 | 0 | } |
72 | 0 | cJSON *cell_listList = cJSON_AddArrayToObject(item, "cellList"); |
73 | 0 | if (cell_listList == NULL) { |
74 | 0 | ogs_error("OpenAPI_ncgi_tai_convertToJSON() failed [cell_list]"); |
75 | 0 | goto end; |
76 | 0 | } |
77 | 0 | OpenAPI_list_for_each(ncgi_tai->cell_list, node) { |
78 | 0 | cJSON *itemLocal = OpenAPI_ncgi_convertToJSON(node->data); |
79 | 0 | if (itemLocal == NULL) { |
80 | 0 | ogs_error("OpenAPI_ncgi_tai_convertToJSON() failed [cell_list]"); |
81 | 0 | goto end; |
82 | 0 | } |
83 | 0 | cJSON_AddItemToArray(cell_listList, itemLocal); |
84 | 0 | } |
85 | | |
86 | 0 | end: |
87 | 0 | return item; |
88 | 0 | } |
89 | | |
90 | | OpenAPI_ncgi_tai_t *OpenAPI_ncgi_tai_parseFromJSON(cJSON *ncgi_taiJSON) |
91 | 66 | { |
92 | 66 | OpenAPI_ncgi_tai_t *ncgi_tai_local_var = NULL; |
93 | 66 | OpenAPI_lnode_t *node = NULL; |
94 | 66 | cJSON *tai = NULL; |
95 | 66 | OpenAPI_tai_t *tai_local_nonprim = NULL; |
96 | 66 | cJSON *cell_list = NULL; |
97 | 66 | OpenAPI_list_t *cell_listList = NULL; |
98 | 66 | tai = cJSON_GetObjectItemCaseSensitive(ncgi_taiJSON, "tai"); |
99 | 66 | if (!tai) { |
100 | 66 | ogs_error("OpenAPI_ncgi_tai_parseFromJSON() failed [tai]"); |
101 | 66 | goto end; |
102 | 66 | } |
103 | 0 | tai_local_nonprim = OpenAPI_tai_parseFromJSON(tai); |
104 | 0 | if (!tai_local_nonprim) { |
105 | 0 | ogs_error("OpenAPI_tai_parseFromJSON failed [tai]"); |
106 | 0 | goto end; |
107 | 0 | } |
108 | | |
109 | 0 | cell_list = cJSON_GetObjectItemCaseSensitive(ncgi_taiJSON, "cellList"); |
110 | 0 | if (!cell_list) { |
111 | 0 | ogs_error("OpenAPI_ncgi_tai_parseFromJSON() failed [cell_list]"); |
112 | 0 | goto end; |
113 | 0 | } |
114 | 0 | cJSON *cell_list_local = NULL; |
115 | 0 | if (!cJSON_IsArray(cell_list)) { |
116 | 0 | ogs_error("OpenAPI_ncgi_tai_parseFromJSON() failed [cell_list]"); |
117 | 0 | goto end; |
118 | 0 | } |
119 | | |
120 | 0 | cell_listList = OpenAPI_list_create(); |
121 | |
|
122 | 0 | cJSON_ArrayForEach(cell_list_local, cell_list) { |
123 | 0 | if (!cJSON_IsObject(cell_list_local)) { |
124 | 0 | ogs_error("OpenAPI_ncgi_tai_parseFromJSON() failed [cell_list]"); |
125 | 0 | goto end; |
126 | 0 | } |
127 | 0 | OpenAPI_ncgi_t *cell_listItem = OpenAPI_ncgi_parseFromJSON(cell_list_local); |
128 | 0 | if (!cell_listItem) { |
129 | 0 | ogs_error("No cell_listItem"); |
130 | 0 | goto end; |
131 | 0 | } |
132 | 0 | OpenAPI_list_add(cell_listList, cell_listItem); |
133 | 0 | } |
134 | | |
135 | 0 | ncgi_tai_local_var = OpenAPI_ncgi_tai_create ( |
136 | 0 | tai_local_nonprim, |
137 | 0 | cell_listList |
138 | 0 | ); |
139 | |
|
140 | 0 | return ncgi_tai_local_var; |
141 | 66 | end: |
142 | 66 | if (tai_local_nonprim) { |
143 | 0 | OpenAPI_tai_free(tai_local_nonprim); |
144 | 0 | tai_local_nonprim = NULL; |
145 | 0 | } |
146 | 66 | if (cell_listList) { |
147 | 0 | OpenAPI_list_for_each(cell_listList, node) { |
148 | 0 | OpenAPI_ncgi_free(node->data); |
149 | 0 | } |
150 | 0 | OpenAPI_list_free(cell_listList); |
151 | 0 | cell_listList = NULL; |
152 | 0 | } |
153 | 66 | return NULL; |
154 | 0 | } |
155 | | |
156 | | OpenAPI_ncgi_tai_t *OpenAPI_ncgi_tai_copy(OpenAPI_ncgi_tai_t *dst, OpenAPI_ncgi_tai_t *src) |
157 | 0 | { |
158 | 0 | cJSON *item = NULL; |
159 | 0 | char *content = NULL; |
160 | |
|
161 | 0 | ogs_assert(src); |
162 | 0 | item = OpenAPI_ncgi_tai_convertToJSON(src); |
163 | 0 | if (!item) { |
164 | 0 | ogs_error("OpenAPI_ncgi_tai_convertToJSON() failed"); |
165 | 0 | return NULL; |
166 | 0 | } |
167 | | |
168 | 0 | content = cJSON_Print(item); |
169 | 0 | cJSON_Delete(item); |
170 | |
|
171 | 0 | if (!content) { |
172 | 0 | ogs_error("cJSON_Print() failed"); |
173 | 0 | return NULL; |
174 | 0 | } |
175 | | |
176 | 0 | item = cJSON_Parse(content); |
177 | 0 | ogs_free(content); |
178 | 0 | if (!item) { |
179 | 0 | ogs_error("cJSON_Parse() failed"); |
180 | 0 | return NULL; |
181 | 0 | } |
182 | | |
183 | 0 | OpenAPI_ncgi_tai_free(dst); |
184 | 0 | dst = OpenAPI_ncgi_tai_parseFromJSON(item); |
185 | 0 | cJSON_Delete(item); |
186 | |
|
187 | 0 | return dst; |
188 | 0 | } |
189 | | |