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