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