/src/open5gs/lib/sbi/openapi/model/cag_info.c
Line | Count | Source |
1 | | |
2 | | #include <stdlib.h> |
3 | | #include <string.h> |
4 | | #include <stdio.h> |
5 | | #include "cag_info.h" |
6 | | |
7 | | OpenAPI_cag_info_t *OpenAPI_cag_info_create( |
8 | | OpenAPI_list_t *allowed_cag_list, |
9 | | bool is_cag_only_indicator, |
10 | | int cag_only_indicator |
11 | | ) |
12 | 0 | { |
13 | 0 | OpenAPI_cag_info_t *cag_info_local_var = ogs_malloc(sizeof(OpenAPI_cag_info_t)); |
14 | 0 | ogs_assert(cag_info_local_var); |
15 | | |
16 | 0 | cag_info_local_var->allowed_cag_list = allowed_cag_list; |
17 | 0 | cag_info_local_var->is_cag_only_indicator = is_cag_only_indicator; |
18 | 0 | cag_info_local_var->cag_only_indicator = cag_only_indicator; |
19 | |
|
20 | 0 | return cag_info_local_var; |
21 | 0 | } |
22 | | |
23 | | void OpenAPI_cag_info_free(OpenAPI_cag_info_t *cag_info) |
24 | 0 | { |
25 | 0 | OpenAPI_lnode_t *node = NULL; |
26 | |
|
27 | 0 | if (NULL == cag_info) { |
28 | 0 | return; |
29 | 0 | } |
30 | 0 | if (cag_info->allowed_cag_list) { |
31 | 0 | OpenAPI_list_for_each(cag_info->allowed_cag_list, node) { |
32 | 0 | ogs_free(node->data); |
33 | 0 | } |
34 | 0 | OpenAPI_list_free(cag_info->allowed_cag_list); |
35 | 0 | cag_info->allowed_cag_list = NULL; |
36 | 0 | } |
37 | 0 | ogs_free(cag_info); |
38 | 0 | } |
39 | | |
40 | | cJSON *OpenAPI_cag_info_convertToJSON(OpenAPI_cag_info_t *cag_info) |
41 | 0 | { |
42 | 0 | cJSON *item = NULL; |
43 | 0 | OpenAPI_lnode_t *node = NULL; |
44 | |
|
45 | 0 | if (cag_info == NULL) { |
46 | 0 | ogs_error("OpenAPI_cag_info_convertToJSON() failed [CagInfo]"); |
47 | 0 | return NULL; |
48 | 0 | } |
49 | | |
50 | 0 | item = cJSON_CreateObject(); |
51 | 0 | if (!cag_info->allowed_cag_list) { |
52 | 0 | ogs_error("OpenAPI_cag_info_convertToJSON() failed [allowed_cag_list]"); |
53 | 0 | return NULL; |
54 | 0 | } |
55 | 0 | cJSON *allowed_cag_listList = cJSON_AddArrayToObject(item, "allowedCagList"); |
56 | 0 | if (allowed_cag_listList == NULL) { |
57 | 0 | ogs_error("OpenAPI_cag_info_convertToJSON() failed [allowed_cag_list]"); |
58 | 0 | goto end; |
59 | 0 | } |
60 | 0 | OpenAPI_list_for_each(cag_info->allowed_cag_list, node) { |
61 | 0 | if (cJSON_AddStringToObject(allowed_cag_listList, "", (char*)node->data) == NULL) { |
62 | 0 | ogs_error("OpenAPI_cag_info_convertToJSON() failed [allowed_cag_list]"); |
63 | 0 | goto end; |
64 | 0 | } |
65 | 0 | } |
66 | | |
67 | 0 | if (cag_info->is_cag_only_indicator) { |
68 | 0 | if (cJSON_AddBoolToObject(item, "cagOnlyIndicator", cag_info->cag_only_indicator) == NULL) { |
69 | 0 | ogs_error("OpenAPI_cag_info_convertToJSON() failed [cag_only_indicator]"); |
70 | 0 | goto end; |
71 | 0 | } |
72 | 0 | } |
73 | | |
74 | 0 | end: |
75 | 0 | return item; |
76 | 0 | } |
77 | | |
78 | | OpenAPI_cag_info_t *OpenAPI_cag_info_parseFromJSON(cJSON *cag_infoJSON) |
79 | 0 | { |
80 | 0 | OpenAPI_cag_info_t *cag_info_local_var = NULL; |
81 | 0 | OpenAPI_lnode_t *node = NULL; |
82 | 0 | cJSON *allowed_cag_list = NULL; |
83 | 0 | OpenAPI_list_t *allowed_cag_listList = NULL; |
84 | 0 | cJSON *cag_only_indicator = NULL; |
85 | 0 | allowed_cag_list = cJSON_GetObjectItemCaseSensitive(cag_infoJSON, "allowedCagList"); |
86 | 0 | if (!allowed_cag_list) { |
87 | 0 | ogs_error("OpenAPI_cag_info_parseFromJSON() failed [allowed_cag_list]"); |
88 | 0 | goto end; |
89 | 0 | } |
90 | 0 | cJSON *allowed_cag_list_local = NULL; |
91 | 0 | if (!cJSON_IsArray(allowed_cag_list)) { |
92 | 0 | ogs_error("OpenAPI_cag_info_parseFromJSON() failed [allowed_cag_list]"); |
93 | 0 | goto end; |
94 | 0 | } |
95 | | |
96 | 0 | allowed_cag_listList = OpenAPI_list_create(); |
97 | |
|
98 | 0 | cJSON_ArrayForEach(allowed_cag_list_local, allowed_cag_list) { |
99 | 0 | double *localDouble = NULL; |
100 | 0 | int *localInt = NULL; |
101 | 0 | if (!cJSON_IsString(allowed_cag_list_local)) { |
102 | 0 | ogs_error("OpenAPI_cag_info_parseFromJSON() failed [allowed_cag_list]"); |
103 | 0 | goto end; |
104 | 0 | } |
105 | 0 | OpenAPI_list_add(allowed_cag_listList, ogs_strdup(allowed_cag_list_local->valuestring)); |
106 | 0 | } |
107 | | |
108 | 0 | cag_only_indicator = cJSON_GetObjectItemCaseSensitive(cag_infoJSON, "cagOnlyIndicator"); |
109 | 0 | if (cag_only_indicator) { |
110 | 0 | if (!cJSON_IsBool(cag_only_indicator)) { |
111 | 0 | ogs_error("OpenAPI_cag_info_parseFromJSON() failed [cag_only_indicator]"); |
112 | 0 | goto end; |
113 | 0 | } |
114 | 0 | } |
115 | | |
116 | 0 | cag_info_local_var = OpenAPI_cag_info_create ( |
117 | 0 | allowed_cag_listList, |
118 | 0 | cag_only_indicator ? true : false, |
119 | 0 | cag_only_indicator ? cag_only_indicator->valueint : 0 |
120 | 0 | ); |
121 | |
|
122 | 0 | return cag_info_local_var; |
123 | 0 | end: |
124 | 0 | if (allowed_cag_listList) { |
125 | 0 | OpenAPI_list_for_each(allowed_cag_listList, node) { |
126 | 0 | ogs_free(node->data); |
127 | 0 | } |
128 | 0 | OpenAPI_list_free(allowed_cag_listList); |
129 | 0 | allowed_cag_listList = NULL; |
130 | 0 | } |
131 | 0 | return NULL; |
132 | 0 | } |
133 | | |
134 | | OpenAPI_cag_info_t *OpenAPI_cag_info_copy(OpenAPI_cag_info_t *dst, OpenAPI_cag_info_t *src) |
135 | 0 | { |
136 | 0 | cJSON *item = NULL; |
137 | 0 | char *content = NULL; |
138 | |
|
139 | 0 | ogs_assert(src); |
140 | 0 | item = OpenAPI_cag_info_convertToJSON(src); |
141 | 0 | if (!item) { |
142 | 0 | ogs_error("OpenAPI_cag_info_convertToJSON() failed"); |
143 | 0 | return NULL; |
144 | 0 | } |
145 | | |
146 | 0 | content = cJSON_Print(item); |
147 | 0 | cJSON_Delete(item); |
148 | |
|
149 | 0 | if (!content) { |
150 | 0 | ogs_error("cJSON_Print() failed"); |
151 | 0 | return NULL; |
152 | 0 | } |
153 | | |
154 | 0 | item = cJSON_Parse(content); |
155 | 0 | ogs_free(content); |
156 | 0 | if (!item) { |
157 | 0 | ogs_error("cJSON_Parse() failed"); |
158 | 0 | return NULL; |
159 | 0 | } |
160 | | |
161 | 0 | OpenAPI_cag_info_free(dst); |
162 | 0 | dst = OpenAPI_cag_info_parseFromJSON(item); |
163 | 0 | cJSON_Delete(item); |
164 | |
|
165 | 0 | return dst; |
166 | 0 | } |
167 | | |