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