/src/open5gs/lib/sbi/openapi/model/imsas_info.c
Line | Count | Source |
1 | | |
2 | | #include <stdlib.h> |
3 | | #include <string.h> |
4 | | #include <stdio.h> |
5 | | #include "imsas_info.h" |
6 | | |
7 | | OpenAPI_imsas_info_t *OpenAPI_imsas_info_create( |
8 | | OpenAPI_list_t *ims_event_list |
9 | | ) |
10 | 0 | { |
11 | 0 | OpenAPI_imsas_info_t *imsas_info_local_var = ogs_malloc(sizeof(OpenAPI_imsas_info_t)); |
12 | 0 | ogs_assert(imsas_info_local_var); |
13 | | |
14 | 0 | imsas_info_local_var->ims_event_list = ims_event_list; |
15 | |
|
16 | 0 | return imsas_info_local_var; |
17 | 0 | } |
18 | | |
19 | | void OpenAPI_imsas_info_free(OpenAPI_imsas_info_t *imsas_info) |
20 | 0 | { |
21 | 0 | OpenAPI_lnode_t *node = NULL; |
22 | |
|
23 | 0 | if (NULL == imsas_info) { |
24 | 0 | return; |
25 | 0 | } |
26 | 0 | if (imsas_info->ims_event_list) { |
27 | 0 | OpenAPI_list_free(imsas_info->ims_event_list); |
28 | 0 | imsas_info->ims_event_list = NULL; |
29 | 0 | } |
30 | 0 | ogs_free(imsas_info); |
31 | 0 | } |
32 | | |
33 | | cJSON *OpenAPI_imsas_info_convertToJSON(OpenAPI_imsas_info_t *imsas_info) |
34 | 0 | { |
35 | 0 | cJSON *item = NULL; |
36 | 0 | OpenAPI_lnode_t *node = NULL; |
37 | |
|
38 | 0 | if (imsas_info == NULL) { |
39 | 0 | ogs_error("OpenAPI_imsas_info_convertToJSON() failed [ImsasInfo]"); |
40 | 0 | return NULL; |
41 | 0 | } |
42 | | |
43 | 0 | item = cJSON_CreateObject(); |
44 | 0 | if (imsas_info->ims_event_list == OpenAPI_ims_event_NULL) { |
45 | 0 | ogs_error("OpenAPI_imsas_info_convertToJSON() failed [ims_event_list]"); |
46 | 0 | return NULL; |
47 | 0 | } |
48 | 0 | cJSON *ims_event_listList = cJSON_AddArrayToObject(item, "imsEventList"); |
49 | 0 | if (ims_event_listList == NULL) { |
50 | 0 | ogs_error("OpenAPI_imsas_info_convertToJSON() failed [ims_event_list]"); |
51 | 0 | goto end; |
52 | 0 | } |
53 | 0 | OpenAPI_list_for_each(imsas_info->ims_event_list, node) { |
54 | 0 | if (cJSON_AddStringToObject(ims_event_listList, "", OpenAPI_ims_event_ToString((intptr_t)node->data)) == NULL) { |
55 | 0 | ogs_error("OpenAPI_imsas_info_convertToJSON() failed [ims_event_list]"); |
56 | 0 | goto end; |
57 | 0 | } |
58 | 0 | } |
59 | | |
60 | 0 | end: |
61 | 0 | return item; |
62 | 0 | } |
63 | | |
64 | | OpenAPI_imsas_info_t *OpenAPI_imsas_info_parseFromJSON(cJSON *imsas_infoJSON) |
65 | 3 | { |
66 | 3 | OpenAPI_imsas_info_t *imsas_info_local_var = NULL; |
67 | 3 | OpenAPI_lnode_t *node = NULL; |
68 | 3 | cJSON *ims_event_list = NULL; |
69 | 3 | OpenAPI_list_t *ims_event_listList = NULL; |
70 | 3 | ims_event_list = cJSON_GetObjectItemCaseSensitive(imsas_infoJSON, "imsEventList"); |
71 | 3 | if (!ims_event_list) { |
72 | 3 | ogs_error("OpenAPI_imsas_info_parseFromJSON() failed [ims_event_list]"); |
73 | 3 | goto end; |
74 | 3 | } |
75 | 0 | cJSON *ims_event_list_local = NULL; |
76 | 0 | if (!cJSON_IsArray(ims_event_list)) { |
77 | 0 | ogs_error("OpenAPI_imsas_info_parseFromJSON() failed [ims_event_list]"); |
78 | 0 | goto end; |
79 | 0 | } |
80 | | |
81 | 0 | ims_event_listList = OpenAPI_list_create(); |
82 | |
|
83 | 0 | cJSON_ArrayForEach(ims_event_list_local, ims_event_list) { |
84 | 0 | OpenAPI_ims_event_e localEnum = OpenAPI_ims_event_NULL; |
85 | 0 | if (!cJSON_IsString(ims_event_list_local)) { |
86 | 0 | ogs_error("OpenAPI_imsas_info_parseFromJSON() failed [ims_event_list]"); |
87 | 0 | goto end; |
88 | 0 | } |
89 | 0 | localEnum = OpenAPI_ims_event_FromString(ims_event_list_local->valuestring); |
90 | 0 | if (!localEnum) { |
91 | 0 | ogs_info("Enum value \"%s\" for field \"ims_event_list\" is not supported. Ignoring it ...", |
92 | 0 | ims_event_list_local->valuestring); |
93 | 0 | } else { |
94 | 0 | OpenAPI_list_add(ims_event_listList, (void *)localEnum); |
95 | 0 | } |
96 | 0 | } |
97 | 0 | if (ims_event_listList->count == 0) { |
98 | 0 | ogs_error("OpenAPI_imsas_info_parseFromJSON() failed: Expected ims_event_listList to not be empty (after ignoring unsupported enum values)."); |
99 | 0 | goto end; |
100 | 0 | } |
101 | | |
102 | 0 | imsas_info_local_var = OpenAPI_imsas_info_create ( |
103 | 0 | ims_event_listList |
104 | 0 | ); |
105 | |
|
106 | 0 | return imsas_info_local_var; |
107 | 3 | end: |
108 | 3 | if (ims_event_listList) { |
109 | 0 | OpenAPI_list_free(ims_event_listList); |
110 | 0 | ims_event_listList = NULL; |
111 | 0 | } |
112 | 3 | return NULL; |
113 | 0 | } |
114 | | |
115 | | OpenAPI_imsas_info_t *OpenAPI_imsas_info_copy(OpenAPI_imsas_info_t *dst, OpenAPI_imsas_info_t *src) |
116 | 0 | { |
117 | 0 | cJSON *item = NULL; |
118 | 0 | char *content = NULL; |
119 | |
|
120 | 0 | ogs_assert(src); |
121 | 0 | item = OpenAPI_imsas_info_convertToJSON(src); |
122 | 0 | if (!item) { |
123 | 0 | ogs_error("OpenAPI_imsas_info_convertToJSON() failed"); |
124 | 0 | return NULL; |
125 | 0 | } |
126 | | |
127 | 0 | content = cJSON_Print(item); |
128 | 0 | cJSON_Delete(item); |
129 | |
|
130 | 0 | if (!content) { |
131 | 0 | ogs_error("cJSON_Print() failed"); |
132 | 0 | return NULL; |
133 | 0 | } |
134 | | |
135 | 0 | item = cJSON_Parse(content); |
136 | 0 | ogs_free(content); |
137 | 0 | if (!item) { |
138 | 0 | ogs_error("cJSON_Parse() failed"); |
139 | 0 | return NULL; |
140 | 0 | } |
141 | | |
142 | 0 | OpenAPI_imsas_info_free(dst); |
143 | 0 | dst = OpenAPI_imsas_info_parseFromJSON(item); |
144 | 0 | cJSON_Delete(item); |
145 | |
|
146 | 0 | return dst; |
147 | 0 | } |
148 | | |