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