/src/open5gs/lib/sbi/openapi/model/geographical_area.c
Line | Count | Source |
1 | | |
2 | | #include <stdlib.h> |
3 | | #include <string.h> |
4 | | #include <stdio.h> |
5 | | #include "geographical_area.h" |
6 | | |
7 | | OpenAPI_geographical_area_t *OpenAPI_geographical_area_create( |
8 | | OpenAPI_civic_address_t *civic_address, |
9 | | OpenAPI_geographic_area_t *shapes |
10 | | ) |
11 | 535 | { |
12 | 535 | OpenAPI_geographical_area_t *geographical_area_local_var = ogs_malloc(sizeof(OpenAPI_geographical_area_t)); |
13 | 535 | ogs_assert(geographical_area_local_var); |
14 | | |
15 | 535 | geographical_area_local_var->civic_address = civic_address; |
16 | 535 | geographical_area_local_var->shapes = shapes; |
17 | | |
18 | 535 | return geographical_area_local_var; |
19 | 535 | } |
20 | | |
21 | | void OpenAPI_geographical_area_free(OpenAPI_geographical_area_t *geographical_area) |
22 | 535 | { |
23 | 535 | OpenAPI_lnode_t *node = NULL; |
24 | | |
25 | 535 | if (NULL == geographical_area) { |
26 | 0 | return; |
27 | 0 | } |
28 | 535 | if (geographical_area->civic_address) { |
29 | 69 | OpenAPI_civic_address_free(geographical_area->civic_address); |
30 | 69 | geographical_area->civic_address = NULL; |
31 | 69 | } |
32 | 535 | if (geographical_area->shapes) { |
33 | 0 | OpenAPI_geographic_area_free(geographical_area->shapes); |
34 | 0 | geographical_area->shapes = NULL; |
35 | 0 | } |
36 | 535 | ogs_free(geographical_area); |
37 | 535 | } |
38 | | |
39 | | cJSON *OpenAPI_geographical_area_convertToJSON(OpenAPI_geographical_area_t *geographical_area) |
40 | 0 | { |
41 | 0 | cJSON *item = NULL; |
42 | 0 | OpenAPI_lnode_t *node = NULL; |
43 | |
|
44 | 0 | if (geographical_area == NULL) { |
45 | 0 | ogs_error("OpenAPI_geographical_area_convertToJSON() failed [GeographicalArea]"); |
46 | 0 | return NULL; |
47 | 0 | } |
48 | | |
49 | 0 | item = cJSON_CreateObject(); |
50 | 0 | if (geographical_area->civic_address) { |
51 | 0 | cJSON *civic_address_local_JSON = OpenAPI_civic_address_convertToJSON(geographical_area->civic_address); |
52 | 0 | if (civic_address_local_JSON == NULL) { |
53 | 0 | ogs_error("OpenAPI_geographical_area_convertToJSON() failed [civic_address]"); |
54 | 0 | goto end; |
55 | 0 | } |
56 | 0 | cJSON_AddItemToObject(item, "civicAddress", civic_address_local_JSON); |
57 | 0 | if (item->child == NULL) { |
58 | 0 | ogs_error("OpenAPI_geographical_area_convertToJSON() failed [civic_address]"); |
59 | 0 | goto end; |
60 | 0 | } |
61 | 0 | } |
62 | | |
63 | 0 | if (geographical_area->shapes) { |
64 | 0 | cJSON *shapes_local_JSON = OpenAPI_geographic_area_convertToJSON(geographical_area->shapes); |
65 | 0 | if (shapes_local_JSON == NULL) { |
66 | 0 | ogs_error("OpenAPI_geographical_area_convertToJSON() failed [shapes]"); |
67 | 0 | goto end; |
68 | 0 | } |
69 | 0 | cJSON_AddItemToObject(item, "shapes", shapes_local_JSON); |
70 | 0 | if (item->child == NULL) { |
71 | 0 | ogs_error("OpenAPI_geographical_area_convertToJSON() failed [shapes]"); |
72 | 0 | goto end; |
73 | 0 | } |
74 | 0 | } |
75 | | |
76 | 0 | end: |
77 | 0 | return item; |
78 | 0 | } |
79 | | |
80 | | OpenAPI_geographical_area_t *OpenAPI_geographical_area_parseFromJSON(cJSON *geographical_areaJSON) |
81 | 536 | { |
82 | 536 | OpenAPI_geographical_area_t *geographical_area_local_var = NULL; |
83 | 536 | OpenAPI_lnode_t *node = NULL; |
84 | 536 | cJSON *civic_address = NULL; |
85 | 536 | OpenAPI_civic_address_t *civic_address_local_nonprim = NULL; |
86 | 536 | cJSON *shapes = NULL; |
87 | 536 | OpenAPI_geographic_area_t *shapes_local_nonprim = NULL; |
88 | 536 | civic_address = cJSON_GetObjectItemCaseSensitive(geographical_areaJSON, "civicAddress"); |
89 | 536 | if (civic_address) { |
90 | 69 | civic_address_local_nonprim = OpenAPI_civic_address_parseFromJSON(civic_address); |
91 | 69 | if (!civic_address_local_nonprim) { |
92 | 0 | ogs_error("OpenAPI_civic_address_parseFromJSON failed [civic_address]"); |
93 | 0 | goto end; |
94 | 0 | } |
95 | 69 | } |
96 | | |
97 | 536 | shapes = cJSON_GetObjectItemCaseSensitive(geographical_areaJSON, "shapes"); |
98 | 536 | if (shapes) { |
99 | 1 | shapes_local_nonprim = OpenAPI_geographic_area_parseFromJSON(shapes); |
100 | 1 | if (!shapes_local_nonprim) { |
101 | 1 | ogs_error("OpenAPI_geographic_area_parseFromJSON failed [shapes]"); |
102 | 1 | goto end; |
103 | 1 | } |
104 | 1 | } |
105 | | |
106 | 535 | geographical_area_local_var = OpenAPI_geographical_area_create ( |
107 | 535 | civic_address ? civic_address_local_nonprim : NULL, |
108 | 535 | shapes ? shapes_local_nonprim : NULL |
109 | 535 | ); |
110 | | |
111 | 535 | return geographical_area_local_var; |
112 | 1 | end: |
113 | 1 | if (civic_address_local_nonprim) { |
114 | 0 | OpenAPI_civic_address_free(civic_address_local_nonprim); |
115 | 0 | civic_address_local_nonprim = NULL; |
116 | 0 | } |
117 | 1 | if (shapes_local_nonprim) { |
118 | 0 | OpenAPI_geographic_area_free(shapes_local_nonprim); |
119 | 0 | shapes_local_nonprim = NULL; |
120 | 0 | } |
121 | 1 | return NULL; |
122 | 536 | } |
123 | | |
124 | | OpenAPI_geographical_area_t *OpenAPI_geographical_area_copy(OpenAPI_geographical_area_t *dst, OpenAPI_geographical_area_t *src) |
125 | 0 | { |
126 | 0 | cJSON *item = NULL; |
127 | 0 | char *content = NULL; |
128 | |
|
129 | 0 | ogs_assert(src); |
130 | 0 | item = OpenAPI_geographical_area_convertToJSON(src); |
131 | 0 | if (!item) { |
132 | 0 | ogs_error("OpenAPI_geographical_area_convertToJSON() failed"); |
133 | 0 | return NULL; |
134 | 0 | } |
135 | | |
136 | 0 | content = cJSON_Print(item); |
137 | 0 | cJSON_Delete(item); |
138 | |
|
139 | 0 | if (!content) { |
140 | 0 | ogs_error("cJSON_Print() failed"); |
141 | 0 | return NULL; |
142 | 0 | } |
143 | | |
144 | 0 | item = cJSON_Parse(content); |
145 | 0 | ogs_free(content); |
146 | 0 | if (!item) { |
147 | 0 | ogs_error("cJSON_Parse() failed"); |
148 | 0 | return NULL; |
149 | 0 | } |
150 | | |
151 | 0 | OpenAPI_geographical_area_free(dst); |
152 | 0 | dst = OpenAPI_geographical_area_parseFromJSON(item); |
153 | 0 | cJSON_Delete(item); |
154 | |
|
155 | 0 | return dst; |
156 | 0 | } |
157 | | |