/src/open5gs/lib/sbi/openapi/model/steering_container.c
Line | Count | Source |
1 | | |
2 | | #include <stdlib.h> |
3 | | #include <string.h> |
4 | | #include <stdio.h> |
5 | | #include "steering_container.h" |
6 | | |
7 | | OpenAPI_steering_container_t *OpenAPI_steering_container_create( |
8 | | OpenAPI_list_t *steering_info_list, |
9 | | char *secured_packet |
10 | | ) |
11 | 0 | { |
12 | 0 | OpenAPI_steering_container_t *steering_container_local_var = ogs_malloc(sizeof(OpenAPI_steering_container_t)); |
13 | 0 | ogs_assert(steering_container_local_var); |
14 | | |
15 | 0 | steering_container_local_var->steering_info_list = steering_info_list; |
16 | 0 | steering_container_local_var->secured_packet = secured_packet; |
17 | |
|
18 | 0 | return steering_container_local_var; |
19 | 0 | } |
20 | | |
21 | | void OpenAPI_steering_container_free(OpenAPI_steering_container_t *steering_container) |
22 | 0 | { |
23 | 0 | OpenAPI_lnode_t *node = NULL; |
24 | |
|
25 | 0 | if (NULL == steering_container) { |
26 | 0 | return; |
27 | 0 | } |
28 | 0 | if (steering_container->steering_info_list) { |
29 | 0 | OpenAPI_list_for_each(steering_container->steering_info_list, node) { |
30 | 0 | OpenAPI_steering_info_free(node->data); |
31 | 0 | } |
32 | 0 | OpenAPI_list_free(steering_container->steering_info_list); |
33 | 0 | steering_container->steering_info_list = NULL; |
34 | 0 | } |
35 | 0 | if (steering_container->secured_packet) { |
36 | 0 | ogs_free(steering_container->secured_packet); |
37 | 0 | steering_container->secured_packet = NULL; |
38 | 0 | } |
39 | 0 | ogs_free(steering_container); |
40 | 0 | } |
41 | | |
42 | | /* |
43 | | * oneOf union (x-open5gs-union): the members are the alternatives of the |
44 | | * original oneOf. Exactly one is set, and it is the JSON value itself |
45 | | * rather than a property of a wrapper object. |
46 | | */ |
47 | | cJSON *OpenAPI_steering_container_convertToJSON(OpenAPI_steering_container_t *steering_container) |
48 | 0 | { |
49 | 0 | cJSON *item = NULL; |
50 | 0 | OpenAPI_lnode_t *node = NULL; |
51 | |
|
52 | 0 | if (steering_container == NULL) { |
53 | 0 | ogs_error("OpenAPI_steering_container_convertToJSON() failed [SteeringContainer]"); |
54 | 0 | return NULL; |
55 | 0 | } |
56 | | |
57 | 0 | if ((steering_container->steering_info_list != NULL) + |
58 | 0 | (steering_container->secured_packet != NULL) != 1) { |
59 | 0 | ogs_error("OpenAPI_steering_container_convertToJSON() failed [SteeringContainer]: exactly one alternative must be set"); |
60 | 0 | return NULL; |
61 | 0 | } |
62 | | |
63 | 0 | if (steering_container->steering_info_list) { |
64 | 0 | item = cJSON_CreateArray(); |
65 | 0 | if (item == NULL) { |
66 | 0 | ogs_error("OpenAPI_steering_container_convertToJSON() failed [steering_info_list]"); |
67 | 0 | return NULL; |
68 | 0 | } |
69 | 0 | OpenAPI_list_for_each(steering_container->steering_info_list, node) { |
70 | 0 | cJSON *itemLocal = OpenAPI_steering_info_convertToJSON(node->data); |
71 | 0 | if (itemLocal == NULL) { |
72 | 0 | ogs_error("OpenAPI_steering_container_convertToJSON() failed [steering_info_list]"); |
73 | 0 | cJSON_Delete(item); |
74 | 0 | return NULL; |
75 | 0 | } |
76 | 0 | cJSON_AddItemToArray(item, itemLocal); |
77 | 0 | } |
78 | 0 | return item; |
79 | 0 | } |
80 | 0 | if (steering_container->secured_packet) { |
81 | 0 | return cJSON_CreateString(steering_container->secured_packet); |
82 | 0 | } |
83 | | |
84 | 0 | ogs_error("OpenAPI_steering_container_convertToJSON() failed [SteeringContainer]"); |
85 | 0 | return NULL; |
86 | 0 | } |
87 | | |
88 | | OpenAPI_steering_container_t *OpenAPI_steering_container_parseFromJSON(cJSON *steering_containerJSON) |
89 | 0 | { |
90 | 0 | OpenAPI_lnode_t *node = NULL; |
91 | 0 | OpenAPI_list_t *steering_info_list = NULL; |
92 | 0 | char *secured_packet = NULL; |
93 | |
|
94 | 0 | if (cJSON_IsArray(steering_containerJSON)) { |
95 | 0 | cJSON *steering_info_list_local = NULL; |
96 | |
|
97 | 0 | steering_info_list = OpenAPI_list_create(); |
98 | |
|
99 | 0 | cJSON_ArrayForEach(steering_info_list_local, steering_containerJSON) { |
100 | 0 | if (!cJSON_IsObject(steering_info_list_local)) { |
101 | 0 | ogs_error("OpenAPI_steering_container_parseFromJSON() failed [steering_info_list]"); |
102 | 0 | goto end; |
103 | 0 | } |
104 | 0 | OpenAPI_steering_info_t *steering_info_listItem = OpenAPI_steering_info_parseFromJSON(steering_info_list_local); |
105 | 0 | if (!steering_info_listItem) { |
106 | 0 | ogs_error("No steering_info_listItem"); |
107 | 0 | goto end; |
108 | 0 | } |
109 | 0 | OpenAPI_list_add(steering_info_list, steering_info_listItem); |
110 | 0 | } |
111 | 0 | } else if (cJSON_IsString(steering_containerJSON)) { |
112 | 0 | secured_packet = ogs_strdup(steering_containerJSON->valuestring); |
113 | 0 | ogs_assert(secured_packet); |
114 | 0 | } else { |
115 | 0 | ogs_error("OpenAPI_steering_container_parseFromJSON() failed [SteeringContainer]"); |
116 | 0 | goto end; |
117 | 0 | } |
118 | | |
119 | 0 | return OpenAPI_steering_container_create(steering_info_list, secured_packet); |
120 | 0 | end: |
121 | 0 | if (steering_info_list) { |
122 | 0 | OpenAPI_list_for_each(steering_info_list, node) { |
123 | 0 | OpenAPI_steering_info_free(node->data); |
124 | 0 | } |
125 | 0 | OpenAPI_list_free(steering_info_list); |
126 | 0 | steering_info_list = NULL; |
127 | 0 | } |
128 | 0 | if (secured_packet) { |
129 | 0 | ogs_free(secured_packet); |
130 | 0 | secured_packet = NULL; |
131 | 0 | } |
132 | 0 | return NULL; |
133 | 0 | } |
134 | | |
135 | | OpenAPI_steering_container_t *OpenAPI_steering_container_copy(OpenAPI_steering_container_t *dst, OpenAPI_steering_container_t *src) |
136 | 0 | { |
137 | 0 | cJSON *item = NULL; |
138 | 0 | char *content = NULL; |
139 | |
|
140 | 0 | ogs_assert(src); |
141 | 0 | item = OpenAPI_steering_container_convertToJSON(src); |
142 | 0 | if (!item) { |
143 | 0 | ogs_error("OpenAPI_steering_container_convertToJSON() failed"); |
144 | 0 | return NULL; |
145 | 0 | } |
146 | | |
147 | 0 | content = cJSON_Print(item); |
148 | 0 | cJSON_Delete(item); |
149 | |
|
150 | 0 | if (!content) { |
151 | 0 | ogs_error("cJSON_Print() failed"); |
152 | 0 | return NULL; |
153 | 0 | } |
154 | | |
155 | 0 | item = cJSON_Parse(content); |
156 | 0 | ogs_free(content); |
157 | 0 | if (!item) { |
158 | 0 | ogs_error("cJSON_Parse() failed"); |
159 | 0 | return NULL; |
160 | 0 | } |
161 | | |
162 | 0 | OpenAPI_steering_container_free(dst); |
163 | 0 | dst = OpenAPI_steering_container_parseFromJSON(item); |
164 | 0 | cJSON_Delete(item); |
165 | |
|
166 | 0 | return dst; |
167 | 0 | } |
168 | | |