/src/open5gs/lib/sbi/openapi/model/condition_data.c
Line | Count | Source |
1 | | |
2 | | #include <stdlib.h> |
3 | | #include <string.h> |
4 | | #include <stdio.h> |
5 | | #include "condition_data.h" |
6 | | |
7 | | OpenAPI_condition_data_t *OpenAPI_condition_data_create( |
8 | | char *cond_id, |
9 | | bool is_activation_time_null, |
10 | | char *activation_time, |
11 | | bool is_deactivation_time_null, |
12 | | char *deactivation_time, |
13 | | OpenAPI_access_type_e access_type, |
14 | | OpenAPI_rat_type_e rat_type |
15 | | ) |
16 | 0 | { |
17 | 0 | OpenAPI_condition_data_t *condition_data_local_var = ogs_malloc(sizeof(OpenAPI_condition_data_t)); |
18 | 0 | ogs_assert(condition_data_local_var); |
19 | | |
20 | 0 | condition_data_local_var->cond_id = cond_id; |
21 | 0 | condition_data_local_var->is_activation_time_null = is_activation_time_null; |
22 | 0 | condition_data_local_var->activation_time = activation_time; |
23 | 0 | condition_data_local_var->is_deactivation_time_null = is_deactivation_time_null; |
24 | 0 | condition_data_local_var->deactivation_time = deactivation_time; |
25 | 0 | condition_data_local_var->access_type = access_type; |
26 | 0 | condition_data_local_var->rat_type = rat_type; |
27 | |
|
28 | 0 | return condition_data_local_var; |
29 | 0 | } |
30 | | |
31 | | void OpenAPI_condition_data_free(OpenAPI_condition_data_t *condition_data) |
32 | 0 | { |
33 | 0 | OpenAPI_lnode_t *node = NULL; |
34 | |
|
35 | 0 | if (NULL == condition_data) { |
36 | 0 | return; |
37 | 0 | } |
38 | 0 | if (condition_data->cond_id) { |
39 | 0 | ogs_free(condition_data->cond_id); |
40 | 0 | condition_data->cond_id = NULL; |
41 | 0 | } |
42 | 0 | if (condition_data->activation_time) { |
43 | 0 | ogs_free(condition_data->activation_time); |
44 | 0 | condition_data->activation_time = NULL; |
45 | 0 | } |
46 | 0 | if (condition_data->deactivation_time) { |
47 | 0 | ogs_free(condition_data->deactivation_time); |
48 | 0 | condition_data->deactivation_time = NULL; |
49 | 0 | } |
50 | 0 | ogs_free(condition_data); |
51 | 0 | } |
52 | | |
53 | | cJSON *OpenAPI_condition_data_convertToJSON(OpenAPI_condition_data_t *condition_data) |
54 | 0 | { |
55 | 0 | cJSON *item = NULL; |
56 | 0 | OpenAPI_lnode_t *node = NULL; |
57 | |
|
58 | 0 | if (condition_data == NULL) { |
59 | 0 | ogs_error("OpenAPI_condition_data_convertToJSON() failed [ConditionData]"); |
60 | 0 | return NULL; |
61 | 0 | } |
62 | | |
63 | 0 | item = cJSON_CreateObject(); |
64 | 0 | if (!condition_data->cond_id) { |
65 | 0 | ogs_error("OpenAPI_condition_data_convertToJSON() failed [cond_id]"); |
66 | 0 | return NULL; |
67 | 0 | } |
68 | 0 | if (cJSON_AddStringToObject(item, "condId", condition_data->cond_id) == NULL) { |
69 | 0 | ogs_error("OpenAPI_condition_data_convertToJSON() failed [cond_id]"); |
70 | 0 | goto end; |
71 | 0 | } |
72 | | |
73 | 0 | if (condition_data->activation_time) { |
74 | 0 | if (cJSON_AddStringToObject(item, "activationTime", condition_data->activation_time) == NULL) { |
75 | 0 | ogs_error("OpenAPI_condition_data_convertToJSON() failed [activation_time]"); |
76 | 0 | goto end; |
77 | 0 | } |
78 | 0 | } else if (condition_data->is_activation_time_null) { |
79 | 0 | if (cJSON_AddNullToObject(item, "activationTime") == NULL) { |
80 | 0 | ogs_error("OpenAPI_condition_data_convertToJSON() failed [activation_time]"); |
81 | 0 | goto end; |
82 | 0 | } |
83 | 0 | } |
84 | | |
85 | 0 | if (condition_data->deactivation_time) { |
86 | 0 | if (cJSON_AddStringToObject(item, "deactivationTime", condition_data->deactivation_time) == NULL) { |
87 | 0 | ogs_error("OpenAPI_condition_data_convertToJSON() failed [deactivation_time]"); |
88 | 0 | goto end; |
89 | 0 | } |
90 | 0 | } else if (condition_data->is_deactivation_time_null) { |
91 | 0 | if (cJSON_AddNullToObject(item, "deactivationTime") == NULL) { |
92 | 0 | ogs_error("OpenAPI_condition_data_convertToJSON() failed [deactivation_time]"); |
93 | 0 | goto end; |
94 | 0 | } |
95 | 0 | } |
96 | | |
97 | 0 | if (condition_data->access_type != OpenAPI_access_type_NULL) { |
98 | 0 | if (cJSON_AddStringToObject(item, "accessType", OpenAPI_access_type_ToString(condition_data->access_type)) == NULL) { |
99 | 0 | ogs_error("OpenAPI_condition_data_convertToJSON() failed [access_type]"); |
100 | 0 | goto end; |
101 | 0 | } |
102 | 0 | } |
103 | | |
104 | 0 | if (condition_data->rat_type != OpenAPI_rat_type_NULL) { |
105 | 0 | if (cJSON_AddStringToObject(item, "ratType", OpenAPI_rat_type_ToString(condition_data->rat_type)) == NULL) { |
106 | 0 | ogs_error("OpenAPI_condition_data_convertToJSON() failed [rat_type]"); |
107 | 0 | goto end; |
108 | 0 | } |
109 | 0 | } |
110 | | |
111 | 0 | end: |
112 | 0 | return item; |
113 | 0 | } |
114 | | |
115 | | OpenAPI_condition_data_t *OpenAPI_condition_data_parseFromJSON(cJSON *condition_dataJSON) |
116 | 0 | { |
117 | 0 | OpenAPI_condition_data_t *condition_data_local_var = NULL; |
118 | 0 | OpenAPI_lnode_t *node = NULL; |
119 | 0 | cJSON *cond_id = NULL; |
120 | 0 | cJSON *activation_time = NULL; |
121 | 0 | cJSON *deactivation_time = NULL; |
122 | 0 | cJSON *access_type = NULL; |
123 | 0 | OpenAPI_access_type_e access_typeVariable = 0; |
124 | 0 | cJSON *rat_type = NULL; |
125 | 0 | OpenAPI_rat_type_e rat_typeVariable = 0; |
126 | 0 | cond_id = cJSON_GetObjectItemCaseSensitive(condition_dataJSON, "condId"); |
127 | 0 | if (!cond_id) { |
128 | 0 | ogs_error("OpenAPI_condition_data_parseFromJSON() failed [cond_id]"); |
129 | 0 | goto end; |
130 | 0 | } |
131 | 0 | if (!cJSON_IsString(cond_id)) { |
132 | 0 | ogs_error("OpenAPI_condition_data_parseFromJSON() failed [cond_id]"); |
133 | 0 | goto end; |
134 | 0 | } |
135 | | |
136 | 0 | activation_time = cJSON_GetObjectItemCaseSensitive(condition_dataJSON, "activationTime"); |
137 | 0 | if (activation_time) { |
138 | 0 | if (!cJSON_IsNull(activation_time)) { |
139 | 0 | if (!cJSON_IsString(activation_time) && !cJSON_IsNull(activation_time)) { |
140 | 0 | ogs_error("OpenAPI_condition_data_parseFromJSON() failed [activation_time]"); |
141 | 0 | goto end; |
142 | 0 | } |
143 | 0 | } |
144 | 0 | } |
145 | | |
146 | 0 | deactivation_time = cJSON_GetObjectItemCaseSensitive(condition_dataJSON, "deactivationTime"); |
147 | 0 | if (deactivation_time) { |
148 | 0 | if (!cJSON_IsNull(deactivation_time)) { |
149 | 0 | if (!cJSON_IsString(deactivation_time) && !cJSON_IsNull(deactivation_time)) { |
150 | 0 | ogs_error("OpenAPI_condition_data_parseFromJSON() failed [deactivation_time]"); |
151 | 0 | goto end; |
152 | 0 | } |
153 | 0 | } |
154 | 0 | } |
155 | | |
156 | 0 | access_type = cJSON_GetObjectItemCaseSensitive(condition_dataJSON, "accessType"); |
157 | 0 | if (access_type) { |
158 | 0 | if (!cJSON_IsString(access_type)) { |
159 | 0 | ogs_error("OpenAPI_condition_data_parseFromJSON() failed [access_type]"); |
160 | 0 | goto end; |
161 | 0 | } |
162 | 0 | access_typeVariable = OpenAPI_access_type_FromString(access_type->valuestring); |
163 | 0 | } |
164 | | |
165 | 0 | rat_type = cJSON_GetObjectItemCaseSensitive(condition_dataJSON, "ratType"); |
166 | 0 | if (rat_type) { |
167 | 0 | if (!cJSON_IsString(rat_type)) { |
168 | 0 | ogs_error("OpenAPI_condition_data_parseFromJSON() failed [rat_type]"); |
169 | 0 | goto end; |
170 | 0 | } |
171 | 0 | rat_typeVariable = OpenAPI_rat_type_FromString(rat_type->valuestring); |
172 | 0 | } |
173 | | |
174 | 0 | condition_data_local_var = OpenAPI_condition_data_create ( |
175 | 0 | ogs_strdup(cond_id->valuestring), |
176 | 0 | activation_time && cJSON_IsNull(activation_time) ? true : false, |
177 | 0 | activation_time && !cJSON_IsNull(activation_time) ? ogs_strdup(activation_time->valuestring) : NULL, |
178 | 0 | deactivation_time && cJSON_IsNull(deactivation_time) ? true : false, |
179 | 0 | deactivation_time && !cJSON_IsNull(deactivation_time) ? ogs_strdup(deactivation_time->valuestring) : NULL, |
180 | 0 | access_type ? access_typeVariable : 0, |
181 | 0 | rat_type ? rat_typeVariable : 0 |
182 | 0 | ); |
183 | |
|
184 | 0 | return condition_data_local_var; |
185 | 0 | end: |
186 | 0 | return NULL; |
187 | 0 | } |
188 | | |
189 | | OpenAPI_condition_data_t *OpenAPI_condition_data_copy(OpenAPI_condition_data_t *dst, OpenAPI_condition_data_t *src) |
190 | 0 | { |
191 | 0 | cJSON *item = NULL; |
192 | 0 | char *content = NULL; |
193 | |
|
194 | 0 | ogs_assert(src); |
195 | 0 | item = OpenAPI_condition_data_convertToJSON(src); |
196 | 0 | if (!item) { |
197 | 0 | ogs_error("OpenAPI_condition_data_convertToJSON() failed"); |
198 | 0 | return NULL; |
199 | 0 | } |
200 | | |
201 | 0 | content = cJSON_Print(item); |
202 | 0 | cJSON_Delete(item); |
203 | |
|
204 | 0 | if (!content) { |
205 | 0 | ogs_error("cJSON_Print() failed"); |
206 | 0 | return NULL; |
207 | 0 | } |
208 | | |
209 | 0 | item = cJSON_Parse(content); |
210 | 0 | ogs_free(content); |
211 | 0 | if (!item) { |
212 | 0 | ogs_error("cJSON_Parse() failed"); |
213 | 0 | return NULL; |
214 | 0 | } |
215 | | |
216 | 0 | OpenAPI_condition_data_free(dst); |
217 | 0 | dst = OpenAPI_condition_data_parseFromJSON(item); |
218 | 0 | cJSON_Delete(item); |
219 | |
|
220 | 0 | return dst; |
221 | 0 | } |
222 | | |