/src/open5gs/lib/sbi/openapi/model/circumstance_description.c
Line | Count | Source |
1 | | |
2 | | #include <stdlib.h> |
3 | | #include <string.h> |
4 | | #include <stdio.h> |
5 | | #include "circumstance_description.h" |
6 | | |
7 | | OpenAPI_circumstance_description_t *OpenAPI_circumstance_description_create( |
8 | | bool is_freq, |
9 | | float freq, |
10 | | char *tm, |
11 | | OpenAPI_network_area_info_t *loc_area, |
12 | | bool is_vol, |
13 | | long vol |
14 | | ) |
15 | 0 | { |
16 | 0 | OpenAPI_circumstance_description_t *circumstance_description_local_var = ogs_malloc(sizeof(OpenAPI_circumstance_description_t)); |
17 | 0 | ogs_assert(circumstance_description_local_var); |
18 | | |
19 | 0 | circumstance_description_local_var->is_freq = is_freq; |
20 | 0 | circumstance_description_local_var->freq = freq; |
21 | 0 | circumstance_description_local_var->tm = tm; |
22 | 0 | circumstance_description_local_var->loc_area = loc_area; |
23 | 0 | circumstance_description_local_var->is_vol = is_vol; |
24 | 0 | circumstance_description_local_var->vol = vol; |
25 | |
|
26 | 0 | return circumstance_description_local_var; |
27 | 0 | } |
28 | | |
29 | | void OpenAPI_circumstance_description_free(OpenAPI_circumstance_description_t *circumstance_description) |
30 | 0 | { |
31 | 0 | OpenAPI_lnode_t *node = NULL; |
32 | |
|
33 | 0 | if (NULL == circumstance_description) { |
34 | 0 | return; |
35 | 0 | } |
36 | 0 | if (circumstance_description->tm) { |
37 | 0 | ogs_free(circumstance_description->tm); |
38 | 0 | circumstance_description->tm = NULL; |
39 | 0 | } |
40 | 0 | if (circumstance_description->loc_area) { |
41 | 0 | OpenAPI_network_area_info_free(circumstance_description->loc_area); |
42 | 0 | circumstance_description->loc_area = NULL; |
43 | 0 | } |
44 | 0 | ogs_free(circumstance_description); |
45 | 0 | } |
46 | | |
47 | | cJSON *OpenAPI_circumstance_description_convertToJSON(OpenAPI_circumstance_description_t *circumstance_description) |
48 | 0 | { |
49 | 0 | cJSON *item = NULL; |
50 | 0 | OpenAPI_lnode_t *node = NULL; |
51 | |
|
52 | 0 | if (circumstance_description == NULL) { |
53 | 0 | ogs_error("OpenAPI_circumstance_description_convertToJSON() failed [CircumstanceDescription]"); |
54 | 0 | return NULL; |
55 | 0 | } |
56 | | |
57 | 0 | item = cJSON_CreateObject(); |
58 | 0 | if (circumstance_description->is_freq) { |
59 | 0 | if (cJSON_AddNumberToObject(item, "freq", circumstance_description->freq) == NULL) { |
60 | 0 | ogs_error("OpenAPI_circumstance_description_convertToJSON() failed [freq]"); |
61 | 0 | goto end; |
62 | 0 | } |
63 | 0 | } |
64 | | |
65 | 0 | if (circumstance_description->tm) { |
66 | 0 | if (cJSON_AddStringToObject(item, "tm", circumstance_description->tm) == NULL) { |
67 | 0 | ogs_error("OpenAPI_circumstance_description_convertToJSON() failed [tm]"); |
68 | 0 | goto end; |
69 | 0 | } |
70 | 0 | } |
71 | | |
72 | 0 | if (circumstance_description->loc_area) { |
73 | 0 | cJSON *loc_area_local_JSON = OpenAPI_network_area_info_convertToJSON(circumstance_description->loc_area); |
74 | 0 | if (loc_area_local_JSON == NULL) { |
75 | 0 | ogs_error("OpenAPI_circumstance_description_convertToJSON() failed [loc_area]"); |
76 | 0 | goto end; |
77 | 0 | } |
78 | 0 | cJSON_AddItemToObject(item, "locArea", loc_area_local_JSON); |
79 | 0 | if (item->child == NULL) { |
80 | 0 | ogs_error("OpenAPI_circumstance_description_convertToJSON() failed [loc_area]"); |
81 | 0 | goto end; |
82 | 0 | } |
83 | 0 | } |
84 | | |
85 | 0 | if (circumstance_description->is_vol) { |
86 | 0 | if (cJSON_AddNumberToObject(item, "vol", circumstance_description->vol) == NULL) { |
87 | 0 | ogs_error("OpenAPI_circumstance_description_convertToJSON() failed [vol]"); |
88 | 0 | goto end; |
89 | 0 | } |
90 | 0 | } |
91 | | |
92 | 0 | end: |
93 | 0 | return item; |
94 | 0 | } |
95 | | |
96 | | OpenAPI_circumstance_description_t *OpenAPI_circumstance_description_parseFromJSON(cJSON *circumstance_descriptionJSON) |
97 | 0 | { |
98 | 0 | OpenAPI_circumstance_description_t *circumstance_description_local_var = NULL; |
99 | 0 | OpenAPI_lnode_t *node = NULL; |
100 | 0 | cJSON *freq = NULL; |
101 | 0 | cJSON *tm = NULL; |
102 | 0 | cJSON *loc_area = NULL; |
103 | 0 | OpenAPI_network_area_info_t *loc_area_local_nonprim = NULL; |
104 | 0 | cJSON *vol = NULL; |
105 | 0 | freq = cJSON_GetObjectItemCaseSensitive(circumstance_descriptionJSON, "freq"); |
106 | 0 | if (freq) { |
107 | 0 | if (!cJSON_IsNumber(freq)) { |
108 | 0 | ogs_error("OpenAPI_circumstance_description_parseFromJSON() failed [freq]"); |
109 | 0 | goto end; |
110 | 0 | } |
111 | 0 | } |
112 | | |
113 | 0 | tm = cJSON_GetObjectItemCaseSensitive(circumstance_descriptionJSON, "tm"); |
114 | 0 | if (tm) { |
115 | 0 | if (!cJSON_IsString(tm) && !cJSON_IsNull(tm)) { |
116 | 0 | ogs_error("OpenAPI_circumstance_description_parseFromJSON() failed [tm]"); |
117 | 0 | goto end; |
118 | 0 | } |
119 | 0 | } |
120 | | |
121 | 0 | loc_area = cJSON_GetObjectItemCaseSensitive(circumstance_descriptionJSON, "locArea"); |
122 | 0 | if (loc_area) { |
123 | 0 | loc_area_local_nonprim = OpenAPI_network_area_info_parseFromJSON(loc_area); |
124 | 0 | if (!loc_area_local_nonprim) { |
125 | 0 | ogs_error("OpenAPI_network_area_info_parseFromJSON failed [loc_area]"); |
126 | 0 | goto end; |
127 | 0 | } |
128 | 0 | } |
129 | | |
130 | 0 | vol = cJSON_GetObjectItemCaseSensitive(circumstance_descriptionJSON, "vol"); |
131 | 0 | if (vol) { |
132 | 0 | if (!cJSON_IsNumber(vol)) { |
133 | 0 | ogs_error("OpenAPI_circumstance_description_parseFromJSON() failed [vol]"); |
134 | 0 | goto end; |
135 | 0 | } |
136 | 0 | } |
137 | | |
138 | 0 | circumstance_description_local_var = OpenAPI_circumstance_description_create ( |
139 | 0 | freq ? true : false, |
140 | 0 | freq ? freq->valuedouble : 0, |
141 | 0 | tm && !cJSON_IsNull(tm) ? ogs_strdup(tm->valuestring) : NULL, |
142 | 0 | loc_area ? loc_area_local_nonprim : NULL, |
143 | 0 | vol ? true : false, |
144 | 0 | vol ? vol->valuedouble : 0 |
145 | 0 | ); |
146 | |
|
147 | 0 | return circumstance_description_local_var; |
148 | 0 | end: |
149 | 0 | if (loc_area_local_nonprim) { |
150 | 0 | OpenAPI_network_area_info_free(loc_area_local_nonprim); |
151 | 0 | loc_area_local_nonprim = NULL; |
152 | 0 | } |
153 | 0 | return NULL; |
154 | 0 | } |
155 | | |
156 | | OpenAPI_circumstance_description_t *OpenAPI_circumstance_description_copy(OpenAPI_circumstance_description_t *dst, OpenAPI_circumstance_description_t *src) |
157 | 0 | { |
158 | 0 | cJSON *item = NULL; |
159 | 0 | char *content = NULL; |
160 | |
|
161 | 0 | ogs_assert(src); |
162 | 0 | item = OpenAPI_circumstance_description_convertToJSON(src); |
163 | 0 | if (!item) { |
164 | 0 | ogs_error("OpenAPI_circumstance_description_convertToJSON() failed"); |
165 | 0 | return NULL; |
166 | 0 | } |
167 | | |
168 | 0 | content = cJSON_Print(item); |
169 | 0 | cJSON_Delete(item); |
170 | |
|
171 | 0 | if (!content) { |
172 | 0 | ogs_error("cJSON_Print() failed"); |
173 | 0 | return NULL; |
174 | 0 | } |
175 | | |
176 | 0 | item = cJSON_Parse(content); |
177 | 0 | ogs_free(content); |
178 | 0 | if (!item) { |
179 | 0 | ogs_error("cJSON_Parse() failed"); |
180 | 0 | return NULL; |
181 | 0 | } |
182 | | |
183 | 0 | OpenAPI_circumstance_description_free(dst); |
184 | 0 | dst = OpenAPI_circumstance_description_parseFromJSON(item); |
185 | 0 | cJSON_Delete(item); |
186 | |
|
187 | 0 | return dst; |
188 | 0 | } |
189 | | |