/src/open5gs/lib/sbi/openapi/model/suci_info.c
Line | Count | Source |
1 | | |
2 | | #include <stdlib.h> |
3 | | #include <string.h> |
4 | | #include <stdio.h> |
5 | | #include "suci_info.h" |
6 | | |
7 | | OpenAPI_suci_info_t *OpenAPI_suci_info_create( |
8 | | OpenAPI_list_t *routing_inds, |
9 | | OpenAPI_list_t *h_nw_pub_key_ids |
10 | | ) |
11 | 0 | { |
12 | 0 | OpenAPI_suci_info_t *suci_info_local_var = ogs_malloc(sizeof(OpenAPI_suci_info_t)); |
13 | 0 | ogs_assert(suci_info_local_var); |
14 | | |
15 | 0 | suci_info_local_var->routing_inds = routing_inds; |
16 | 0 | suci_info_local_var->h_nw_pub_key_ids = h_nw_pub_key_ids; |
17 | |
|
18 | 0 | return suci_info_local_var; |
19 | 0 | } |
20 | | |
21 | | void OpenAPI_suci_info_free(OpenAPI_suci_info_t *suci_info) |
22 | 0 | { |
23 | 0 | OpenAPI_lnode_t *node = NULL; |
24 | |
|
25 | 0 | if (NULL == suci_info) { |
26 | 0 | return; |
27 | 0 | } |
28 | 0 | if (suci_info->routing_inds) { |
29 | 0 | OpenAPI_list_for_each(suci_info->routing_inds, node) { |
30 | 0 | ogs_free(node->data); |
31 | 0 | } |
32 | 0 | OpenAPI_list_free(suci_info->routing_inds); |
33 | 0 | suci_info->routing_inds = NULL; |
34 | 0 | } |
35 | 0 | if (suci_info->h_nw_pub_key_ids) { |
36 | 0 | OpenAPI_list_for_each(suci_info->h_nw_pub_key_ids, node) { |
37 | 0 | ogs_free(node->data); |
38 | 0 | } |
39 | 0 | OpenAPI_list_free(suci_info->h_nw_pub_key_ids); |
40 | 0 | suci_info->h_nw_pub_key_ids = NULL; |
41 | 0 | } |
42 | 0 | ogs_free(suci_info); |
43 | 0 | } |
44 | | |
45 | | cJSON *OpenAPI_suci_info_convertToJSON(OpenAPI_suci_info_t *suci_info) |
46 | 0 | { |
47 | 0 | cJSON *item = NULL; |
48 | 0 | OpenAPI_lnode_t *node = NULL; |
49 | |
|
50 | 0 | if (suci_info == NULL) { |
51 | 0 | ogs_error("OpenAPI_suci_info_convertToJSON() failed [SuciInfo]"); |
52 | 0 | return NULL; |
53 | 0 | } |
54 | | |
55 | 0 | item = cJSON_CreateObject(); |
56 | 0 | if (suci_info->routing_inds) { |
57 | 0 | cJSON *routing_indsList = cJSON_AddArrayToObject(item, "routingInds"); |
58 | 0 | if (routing_indsList == NULL) { |
59 | 0 | ogs_error("OpenAPI_suci_info_convertToJSON() failed [routing_inds]"); |
60 | 0 | goto end; |
61 | 0 | } |
62 | 0 | OpenAPI_list_for_each(suci_info->routing_inds, node) { |
63 | 0 | if (cJSON_AddStringToObject(routing_indsList, "", (char*)node->data) == NULL) { |
64 | 0 | ogs_error("OpenAPI_suci_info_convertToJSON() failed [routing_inds]"); |
65 | 0 | goto end; |
66 | 0 | } |
67 | 0 | } |
68 | 0 | } |
69 | | |
70 | 0 | if (suci_info->h_nw_pub_key_ids) { |
71 | 0 | cJSON *h_nw_pub_key_idsList = cJSON_AddArrayToObject(item, "hNwPubKeyIds"); |
72 | 0 | if (h_nw_pub_key_idsList == NULL) { |
73 | 0 | ogs_error("OpenAPI_suci_info_convertToJSON() failed [h_nw_pub_key_ids]"); |
74 | 0 | goto end; |
75 | 0 | } |
76 | 0 | OpenAPI_list_for_each(suci_info->h_nw_pub_key_ids, node) { |
77 | 0 | if (node->data == NULL) { |
78 | 0 | ogs_error("OpenAPI_suci_info_convertToJSON() failed [h_nw_pub_key_ids]"); |
79 | 0 | goto end; |
80 | 0 | } |
81 | 0 | if (cJSON_AddNumberToObject(h_nw_pub_key_idsList, "", *(double *)node->data) == NULL) { |
82 | 0 | ogs_error("OpenAPI_suci_info_convertToJSON() failed [h_nw_pub_key_ids]"); |
83 | 0 | goto end; |
84 | 0 | } |
85 | 0 | } |
86 | 0 | } |
87 | | |
88 | 0 | end: |
89 | 0 | return item; |
90 | 0 | } |
91 | | |
92 | | OpenAPI_suci_info_t *OpenAPI_suci_info_parseFromJSON(cJSON *suci_infoJSON) |
93 | 0 | { |
94 | 0 | OpenAPI_suci_info_t *suci_info_local_var = NULL; |
95 | 0 | OpenAPI_lnode_t *node = NULL; |
96 | 0 | cJSON *routing_inds = NULL; |
97 | 0 | OpenAPI_list_t *routing_indsList = NULL; |
98 | 0 | cJSON *h_nw_pub_key_ids = NULL; |
99 | 0 | OpenAPI_list_t *h_nw_pub_key_idsList = NULL; |
100 | 0 | routing_inds = cJSON_GetObjectItemCaseSensitive(suci_infoJSON, "routingInds"); |
101 | 0 | if (routing_inds) { |
102 | 0 | cJSON *routing_inds_local = NULL; |
103 | 0 | if (!cJSON_IsArray(routing_inds)) { |
104 | 0 | ogs_error("OpenAPI_suci_info_parseFromJSON() failed [routing_inds]"); |
105 | 0 | goto end; |
106 | 0 | } |
107 | | |
108 | 0 | routing_indsList = OpenAPI_list_create(); |
109 | |
|
110 | 0 | cJSON_ArrayForEach(routing_inds_local, routing_inds) { |
111 | 0 | double *localDouble = NULL; |
112 | 0 | int *localInt = NULL; |
113 | 0 | if (!cJSON_IsString(routing_inds_local)) { |
114 | 0 | ogs_error("OpenAPI_suci_info_parseFromJSON() failed [routing_inds]"); |
115 | 0 | goto end; |
116 | 0 | } |
117 | 0 | OpenAPI_list_add(routing_indsList, ogs_strdup(routing_inds_local->valuestring)); |
118 | 0 | } |
119 | 0 | } |
120 | | |
121 | 0 | h_nw_pub_key_ids = cJSON_GetObjectItemCaseSensitive(suci_infoJSON, "hNwPubKeyIds"); |
122 | 0 | if (h_nw_pub_key_ids) { |
123 | 0 | cJSON *h_nw_pub_key_ids_local = NULL; |
124 | 0 | if (!cJSON_IsArray(h_nw_pub_key_ids)) { |
125 | 0 | ogs_error("OpenAPI_suci_info_parseFromJSON() failed [h_nw_pub_key_ids]"); |
126 | 0 | goto end; |
127 | 0 | } |
128 | | |
129 | 0 | h_nw_pub_key_idsList = OpenAPI_list_create(); |
130 | |
|
131 | 0 | cJSON_ArrayForEach(h_nw_pub_key_ids_local, h_nw_pub_key_ids) { |
132 | 0 | double *localDouble = NULL; |
133 | 0 | int *localInt = NULL; |
134 | 0 | if (!cJSON_IsNumber(h_nw_pub_key_ids_local)) { |
135 | 0 | ogs_error("OpenAPI_suci_info_parseFromJSON() failed [h_nw_pub_key_ids]"); |
136 | 0 | goto end; |
137 | 0 | } |
138 | 0 | localDouble = (double *)ogs_calloc(1, sizeof(double)); |
139 | 0 | if (!localDouble) { |
140 | 0 | ogs_error("OpenAPI_suci_info_parseFromJSON() failed [h_nw_pub_key_ids]"); |
141 | 0 | goto end; |
142 | 0 | } |
143 | 0 | *localDouble = h_nw_pub_key_ids_local->valuedouble; |
144 | 0 | OpenAPI_list_add(h_nw_pub_key_idsList, localDouble); |
145 | 0 | } |
146 | 0 | } |
147 | | |
148 | 0 | suci_info_local_var = OpenAPI_suci_info_create ( |
149 | 0 | routing_inds ? routing_indsList : NULL, |
150 | 0 | h_nw_pub_key_ids ? h_nw_pub_key_idsList : NULL |
151 | 0 | ); |
152 | |
|
153 | 0 | return suci_info_local_var; |
154 | 0 | end: |
155 | 0 | if (routing_indsList) { |
156 | 0 | OpenAPI_list_for_each(routing_indsList, node) { |
157 | 0 | ogs_free(node->data); |
158 | 0 | } |
159 | 0 | OpenAPI_list_free(routing_indsList); |
160 | 0 | routing_indsList = NULL; |
161 | 0 | } |
162 | 0 | if (h_nw_pub_key_idsList) { |
163 | 0 | OpenAPI_list_for_each(h_nw_pub_key_idsList, node) { |
164 | 0 | ogs_free(node->data); |
165 | 0 | } |
166 | 0 | OpenAPI_list_free(h_nw_pub_key_idsList); |
167 | 0 | h_nw_pub_key_idsList = NULL; |
168 | 0 | } |
169 | 0 | return NULL; |
170 | 0 | } |
171 | | |
172 | | OpenAPI_suci_info_t *OpenAPI_suci_info_copy(OpenAPI_suci_info_t *dst, OpenAPI_suci_info_t *src) |
173 | 0 | { |
174 | 0 | cJSON *item = NULL; |
175 | 0 | char *content = NULL; |
176 | |
|
177 | 0 | ogs_assert(src); |
178 | 0 | item = OpenAPI_suci_info_convertToJSON(src); |
179 | 0 | if (!item) { |
180 | 0 | ogs_error("OpenAPI_suci_info_convertToJSON() failed"); |
181 | 0 | return NULL; |
182 | 0 | } |
183 | | |
184 | 0 | content = cJSON_Print(item); |
185 | 0 | cJSON_Delete(item); |
186 | |
|
187 | 0 | if (!content) { |
188 | 0 | ogs_error("cJSON_Print() failed"); |
189 | 0 | return NULL; |
190 | 0 | } |
191 | | |
192 | 0 | item = cJSON_Parse(content); |
193 | 0 | ogs_free(content); |
194 | 0 | if (!item) { |
195 | 0 | ogs_error("cJSON_Parse() failed"); |
196 | 0 | return NULL; |
197 | 0 | } |
198 | | |
199 | 0 | OpenAPI_suci_info_free(dst); |
200 | 0 | dst = OpenAPI_suci_info_parseFromJSON(item); |
201 | 0 | cJSON_Delete(item); |
202 | |
|
203 | 0 | return dst; |
204 | 0 | } |
205 | | |