/src/open5gs/lib/sbi/openapi/model/status_info.c
Line | Count | Source |
1 | | |
2 | | #include <stdlib.h> |
3 | | #include <string.h> |
4 | | #include <stdio.h> |
5 | | #include "status_info.h" |
6 | | |
7 | | OpenAPI_status_info_t *OpenAPI_status_info_create( |
8 | | OpenAPI_resource_status_e resource_status, |
9 | | OpenAPI_cause_e cause, |
10 | | bool is_remote_error, |
11 | | int remote_error, |
12 | | OpenAPI_cn_assisted_ran_para_t *cn_assisted_ran_para, |
13 | | OpenAPI_access_type_e an_type |
14 | | ) |
15 | 0 | { |
16 | 0 | OpenAPI_status_info_t *status_info_local_var = ogs_malloc(sizeof(OpenAPI_status_info_t)); |
17 | 0 | ogs_assert(status_info_local_var); |
18 | | |
19 | 0 | status_info_local_var->resource_status = resource_status; |
20 | 0 | status_info_local_var->cause = cause; |
21 | 0 | status_info_local_var->is_remote_error = is_remote_error; |
22 | 0 | status_info_local_var->remote_error = remote_error; |
23 | 0 | status_info_local_var->cn_assisted_ran_para = cn_assisted_ran_para; |
24 | 0 | status_info_local_var->an_type = an_type; |
25 | |
|
26 | 0 | return status_info_local_var; |
27 | 0 | } |
28 | | |
29 | | void OpenAPI_status_info_free(OpenAPI_status_info_t *status_info) |
30 | 0 | { |
31 | 0 | OpenAPI_lnode_t *node = NULL; |
32 | |
|
33 | 0 | if (NULL == status_info) { |
34 | 0 | return; |
35 | 0 | } |
36 | 0 | if (status_info->cn_assisted_ran_para) { |
37 | 0 | OpenAPI_cn_assisted_ran_para_free(status_info->cn_assisted_ran_para); |
38 | 0 | status_info->cn_assisted_ran_para = NULL; |
39 | 0 | } |
40 | 0 | ogs_free(status_info); |
41 | 0 | } |
42 | | |
43 | | cJSON *OpenAPI_status_info_convertToJSON(OpenAPI_status_info_t *status_info) |
44 | 0 | { |
45 | 0 | cJSON *item = NULL; |
46 | 0 | OpenAPI_lnode_t *node = NULL; |
47 | |
|
48 | 0 | if (status_info == NULL) { |
49 | 0 | ogs_error("OpenAPI_status_info_convertToJSON() failed [StatusInfo]"); |
50 | 0 | return NULL; |
51 | 0 | } |
52 | | |
53 | 0 | item = cJSON_CreateObject(); |
54 | 0 | if (status_info->resource_status == OpenAPI_resource_status_NULL) { |
55 | 0 | ogs_error("OpenAPI_status_info_convertToJSON() failed [resource_status]"); |
56 | 0 | return NULL; |
57 | 0 | } |
58 | 0 | if (cJSON_AddStringToObject(item, "resourceStatus", OpenAPI_resource_status_ToString(status_info->resource_status)) == NULL) { |
59 | 0 | ogs_error("OpenAPI_status_info_convertToJSON() failed [resource_status]"); |
60 | 0 | goto end; |
61 | 0 | } |
62 | | |
63 | 0 | if (status_info->cause != OpenAPI_cause_NULL) { |
64 | 0 | if (cJSON_AddStringToObject(item, "cause", OpenAPI_cause_ToString(status_info->cause)) == NULL) { |
65 | 0 | ogs_error("OpenAPI_status_info_convertToJSON() failed [cause]"); |
66 | 0 | goto end; |
67 | 0 | } |
68 | 0 | } |
69 | | |
70 | 0 | if (status_info->is_remote_error) { |
71 | 0 | if (cJSON_AddBoolToObject(item, "remoteError", status_info->remote_error) == NULL) { |
72 | 0 | ogs_error("OpenAPI_status_info_convertToJSON() failed [remote_error]"); |
73 | 0 | goto end; |
74 | 0 | } |
75 | 0 | } |
76 | | |
77 | 0 | if (status_info->cn_assisted_ran_para) { |
78 | 0 | cJSON *cn_assisted_ran_para_local_JSON = OpenAPI_cn_assisted_ran_para_convertToJSON(status_info->cn_assisted_ran_para); |
79 | 0 | if (cn_assisted_ran_para_local_JSON == NULL) { |
80 | 0 | ogs_error("OpenAPI_status_info_convertToJSON() failed [cn_assisted_ran_para]"); |
81 | 0 | goto end; |
82 | 0 | } |
83 | 0 | cJSON_AddItemToObject(item, "cnAssistedRanPara", cn_assisted_ran_para_local_JSON); |
84 | 0 | if (item->child == NULL) { |
85 | 0 | ogs_error("OpenAPI_status_info_convertToJSON() failed [cn_assisted_ran_para]"); |
86 | 0 | goto end; |
87 | 0 | } |
88 | 0 | } |
89 | | |
90 | 0 | if (status_info->an_type != OpenAPI_access_type_NULL) { |
91 | 0 | if (cJSON_AddStringToObject(item, "anType", OpenAPI_access_type_ToString(status_info->an_type)) == NULL) { |
92 | 0 | ogs_error("OpenAPI_status_info_convertToJSON() failed [an_type]"); |
93 | 0 | goto end; |
94 | 0 | } |
95 | 0 | } |
96 | | |
97 | 0 | end: |
98 | 0 | return item; |
99 | 0 | } |
100 | | |
101 | | OpenAPI_status_info_t *OpenAPI_status_info_parseFromJSON(cJSON *status_infoJSON) |
102 | 0 | { |
103 | 0 | OpenAPI_status_info_t *status_info_local_var = NULL; |
104 | 0 | OpenAPI_lnode_t *node = NULL; |
105 | 0 | cJSON *resource_status = NULL; |
106 | 0 | OpenAPI_resource_status_e resource_statusVariable = 0; |
107 | 0 | cJSON *cause = NULL; |
108 | 0 | OpenAPI_cause_e causeVariable = 0; |
109 | 0 | cJSON *remote_error = NULL; |
110 | 0 | cJSON *cn_assisted_ran_para = NULL; |
111 | 0 | OpenAPI_cn_assisted_ran_para_t *cn_assisted_ran_para_local_nonprim = NULL; |
112 | 0 | cJSON *an_type = NULL; |
113 | 0 | OpenAPI_access_type_e an_typeVariable = 0; |
114 | 0 | resource_status = cJSON_GetObjectItemCaseSensitive(status_infoJSON, "resourceStatus"); |
115 | 0 | if (!resource_status) { |
116 | 0 | ogs_error("OpenAPI_status_info_parseFromJSON() failed [resource_status]"); |
117 | 0 | goto end; |
118 | 0 | } |
119 | 0 | if (!cJSON_IsString(resource_status)) { |
120 | 0 | ogs_error("OpenAPI_status_info_parseFromJSON() failed [resource_status]"); |
121 | 0 | goto end; |
122 | 0 | } |
123 | 0 | resource_statusVariable = OpenAPI_resource_status_FromString(resource_status->valuestring); |
124 | |
|
125 | 0 | cause = cJSON_GetObjectItemCaseSensitive(status_infoJSON, "cause"); |
126 | 0 | if (cause) { |
127 | 0 | if (!cJSON_IsString(cause)) { |
128 | 0 | ogs_error("OpenAPI_status_info_parseFromJSON() failed [cause]"); |
129 | 0 | goto end; |
130 | 0 | } |
131 | 0 | causeVariable = OpenAPI_cause_FromString(cause->valuestring); |
132 | 0 | } |
133 | | |
134 | 0 | remote_error = cJSON_GetObjectItemCaseSensitive(status_infoJSON, "remoteError"); |
135 | 0 | if (remote_error) { |
136 | 0 | if (!cJSON_IsBool(remote_error)) { |
137 | 0 | ogs_error("OpenAPI_status_info_parseFromJSON() failed [remote_error]"); |
138 | 0 | goto end; |
139 | 0 | } |
140 | 0 | } |
141 | | |
142 | 0 | cn_assisted_ran_para = cJSON_GetObjectItemCaseSensitive(status_infoJSON, "cnAssistedRanPara"); |
143 | 0 | if (cn_assisted_ran_para) { |
144 | 0 | cn_assisted_ran_para_local_nonprim = OpenAPI_cn_assisted_ran_para_parseFromJSON(cn_assisted_ran_para); |
145 | 0 | if (!cn_assisted_ran_para_local_nonprim) { |
146 | 0 | ogs_error("OpenAPI_cn_assisted_ran_para_parseFromJSON failed [cn_assisted_ran_para]"); |
147 | 0 | goto end; |
148 | 0 | } |
149 | 0 | } |
150 | | |
151 | 0 | an_type = cJSON_GetObjectItemCaseSensitive(status_infoJSON, "anType"); |
152 | 0 | if (an_type) { |
153 | 0 | if (!cJSON_IsString(an_type)) { |
154 | 0 | ogs_error("OpenAPI_status_info_parseFromJSON() failed [an_type]"); |
155 | 0 | goto end; |
156 | 0 | } |
157 | 0 | an_typeVariable = OpenAPI_access_type_FromString(an_type->valuestring); |
158 | 0 | } |
159 | | |
160 | 0 | status_info_local_var = OpenAPI_status_info_create ( |
161 | 0 | resource_statusVariable, |
162 | 0 | cause ? causeVariable : 0, |
163 | 0 | remote_error ? true : false, |
164 | 0 | remote_error ? remote_error->valueint : 0, |
165 | 0 | cn_assisted_ran_para ? cn_assisted_ran_para_local_nonprim : NULL, |
166 | 0 | an_type ? an_typeVariable : 0 |
167 | 0 | ); |
168 | |
|
169 | 0 | return status_info_local_var; |
170 | 0 | end: |
171 | 0 | if (cn_assisted_ran_para_local_nonprim) { |
172 | 0 | OpenAPI_cn_assisted_ran_para_free(cn_assisted_ran_para_local_nonprim); |
173 | 0 | cn_assisted_ran_para_local_nonprim = NULL; |
174 | 0 | } |
175 | 0 | return NULL; |
176 | 0 | } |
177 | | |
178 | | OpenAPI_status_info_t *OpenAPI_status_info_copy(OpenAPI_status_info_t *dst, OpenAPI_status_info_t *src) |
179 | 0 | { |
180 | 0 | cJSON *item = NULL; |
181 | 0 | char *content = NULL; |
182 | |
|
183 | 0 | ogs_assert(src); |
184 | 0 | item = OpenAPI_status_info_convertToJSON(src); |
185 | 0 | if (!item) { |
186 | 0 | ogs_error("OpenAPI_status_info_convertToJSON() failed"); |
187 | 0 | return NULL; |
188 | 0 | } |
189 | | |
190 | 0 | content = cJSON_Print(item); |
191 | 0 | cJSON_Delete(item); |
192 | |
|
193 | 0 | if (!content) { |
194 | 0 | ogs_error("cJSON_Print() failed"); |
195 | 0 | return NULL; |
196 | 0 | } |
197 | | |
198 | 0 | item = cJSON_Parse(content); |
199 | 0 | ogs_free(content); |
200 | 0 | if (!item) { |
201 | 0 | ogs_error("cJSON_Parse() failed"); |
202 | 0 | return NULL; |
203 | 0 | } |
204 | | |
205 | 0 | OpenAPI_status_info_free(dst); |
206 | 0 | dst = OpenAPI_status_info_parseFromJSON(item); |
207 | 0 | cJSON_Delete(item); |
208 | |
|
209 | 0 | return dst; |
210 | 0 | } |
211 | | |