/src/open5gs/lib/sbi/openapi/model/ssm_1.c
Line | Count | Source |
1 | | |
2 | | #include <stdlib.h> |
3 | | #include <string.h> |
4 | | #include <stdio.h> |
5 | | #include "ssm_1.h" |
6 | | |
7 | | OpenAPI_ssm_1_t *OpenAPI_ssm_1_create( |
8 | | OpenAPI_ip_addr_1_t *source_ip_addr, |
9 | | OpenAPI_ip_addr_1_t *dest_ip_addr |
10 | | ) |
11 | 0 | { |
12 | 0 | OpenAPI_ssm_1_t *ssm_1_local_var = ogs_malloc(sizeof(OpenAPI_ssm_1_t)); |
13 | 0 | ogs_assert(ssm_1_local_var); |
14 | | |
15 | 0 | ssm_1_local_var->source_ip_addr = source_ip_addr; |
16 | 0 | ssm_1_local_var->dest_ip_addr = dest_ip_addr; |
17 | |
|
18 | 0 | return ssm_1_local_var; |
19 | 0 | } |
20 | | |
21 | | void OpenAPI_ssm_1_free(OpenAPI_ssm_1_t *ssm_1) |
22 | 0 | { |
23 | 0 | OpenAPI_lnode_t *node = NULL; |
24 | |
|
25 | 0 | if (NULL == ssm_1) { |
26 | 0 | return; |
27 | 0 | } |
28 | 0 | if (ssm_1->source_ip_addr) { |
29 | 0 | OpenAPI_ip_addr_1_free(ssm_1->source_ip_addr); |
30 | 0 | ssm_1->source_ip_addr = NULL; |
31 | 0 | } |
32 | 0 | if (ssm_1->dest_ip_addr) { |
33 | 0 | OpenAPI_ip_addr_1_free(ssm_1->dest_ip_addr); |
34 | 0 | ssm_1->dest_ip_addr = NULL; |
35 | 0 | } |
36 | 0 | ogs_free(ssm_1); |
37 | 0 | } |
38 | | |
39 | | cJSON *OpenAPI_ssm_1_convertToJSON(OpenAPI_ssm_1_t *ssm_1) |
40 | 0 | { |
41 | 0 | cJSON *item = NULL; |
42 | 0 | OpenAPI_lnode_t *node = NULL; |
43 | |
|
44 | 0 | if (ssm_1 == NULL) { |
45 | 0 | ogs_error("OpenAPI_ssm_1_convertToJSON() failed [Ssm_1]"); |
46 | 0 | return NULL; |
47 | 0 | } |
48 | | |
49 | 0 | item = cJSON_CreateObject(); |
50 | 0 | if (!ssm_1->source_ip_addr) { |
51 | 0 | ogs_error("OpenAPI_ssm_1_convertToJSON() failed [source_ip_addr]"); |
52 | 0 | return NULL; |
53 | 0 | } |
54 | 0 | cJSON *source_ip_addr_local_JSON = OpenAPI_ip_addr_1_convertToJSON(ssm_1->source_ip_addr); |
55 | 0 | if (source_ip_addr_local_JSON == NULL) { |
56 | 0 | ogs_error("OpenAPI_ssm_1_convertToJSON() failed [source_ip_addr]"); |
57 | 0 | goto end; |
58 | 0 | } |
59 | 0 | cJSON_AddItemToObject(item, "sourceIpAddr", source_ip_addr_local_JSON); |
60 | 0 | if (item->child == NULL) { |
61 | 0 | ogs_error("OpenAPI_ssm_1_convertToJSON() failed [source_ip_addr]"); |
62 | 0 | goto end; |
63 | 0 | } |
64 | | |
65 | 0 | if (!ssm_1->dest_ip_addr) { |
66 | 0 | ogs_error("OpenAPI_ssm_1_convertToJSON() failed [dest_ip_addr]"); |
67 | 0 | return NULL; |
68 | 0 | } |
69 | 0 | cJSON *dest_ip_addr_local_JSON = OpenAPI_ip_addr_1_convertToJSON(ssm_1->dest_ip_addr); |
70 | 0 | if (dest_ip_addr_local_JSON == NULL) { |
71 | 0 | ogs_error("OpenAPI_ssm_1_convertToJSON() failed [dest_ip_addr]"); |
72 | 0 | goto end; |
73 | 0 | } |
74 | 0 | cJSON_AddItemToObject(item, "destIpAddr", dest_ip_addr_local_JSON); |
75 | 0 | if (item->child == NULL) { |
76 | 0 | ogs_error("OpenAPI_ssm_1_convertToJSON() failed [dest_ip_addr]"); |
77 | 0 | goto end; |
78 | 0 | } |
79 | | |
80 | 0 | end: |
81 | 0 | return item; |
82 | 0 | } |
83 | | |
84 | | OpenAPI_ssm_1_t *OpenAPI_ssm_1_parseFromJSON(cJSON *ssm_1JSON) |
85 | 0 | { |
86 | 0 | OpenAPI_ssm_1_t *ssm_1_local_var = NULL; |
87 | 0 | OpenAPI_lnode_t *node = NULL; |
88 | 0 | cJSON *source_ip_addr = NULL; |
89 | 0 | OpenAPI_ip_addr_1_t *source_ip_addr_local_nonprim = NULL; |
90 | 0 | cJSON *dest_ip_addr = NULL; |
91 | 0 | OpenAPI_ip_addr_1_t *dest_ip_addr_local_nonprim = NULL; |
92 | 0 | source_ip_addr = cJSON_GetObjectItemCaseSensitive(ssm_1JSON, "sourceIpAddr"); |
93 | 0 | if (!source_ip_addr) { |
94 | 0 | ogs_error("OpenAPI_ssm_1_parseFromJSON() failed [source_ip_addr]"); |
95 | 0 | goto end; |
96 | 0 | } |
97 | 0 | source_ip_addr_local_nonprim = OpenAPI_ip_addr_1_parseFromJSON(source_ip_addr); |
98 | 0 | if (!source_ip_addr_local_nonprim) { |
99 | 0 | ogs_error("OpenAPI_ip_addr_1_parseFromJSON failed [source_ip_addr]"); |
100 | 0 | goto end; |
101 | 0 | } |
102 | | |
103 | 0 | dest_ip_addr = cJSON_GetObjectItemCaseSensitive(ssm_1JSON, "destIpAddr"); |
104 | 0 | if (!dest_ip_addr) { |
105 | 0 | ogs_error("OpenAPI_ssm_1_parseFromJSON() failed [dest_ip_addr]"); |
106 | 0 | goto end; |
107 | 0 | } |
108 | 0 | dest_ip_addr_local_nonprim = OpenAPI_ip_addr_1_parseFromJSON(dest_ip_addr); |
109 | 0 | if (!dest_ip_addr_local_nonprim) { |
110 | 0 | ogs_error("OpenAPI_ip_addr_1_parseFromJSON failed [dest_ip_addr]"); |
111 | 0 | goto end; |
112 | 0 | } |
113 | | |
114 | 0 | ssm_1_local_var = OpenAPI_ssm_1_create ( |
115 | 0 | source_ip_addr_local_nonprim, |
116 | 0 | dest_ip_addr_local_nonprim |
117 | 0 | ); |
118 | |
|
119 | 0 | return ssm_1_local_var; |
120 | 0 | end: |
121 | 0 | if (source_ip_addr_local_nonprim) { |
122 | 0 | OpenAPI_ip_addr_1_free(source_ip_addr_local_nonprim); |
123 | 0 | source_ip_addr_local_nonprim = NULL; |
124 | 0 | } |
125 | 0 | if (dest_ip_addr_local_nonprim) { |
126 | 0 | OpenAPI_ip_addr_1_free(dest_ip_addr_local_nonprim); |
127 | 0 | dest_ip_addr_local_nonprim = NULL; |
128 | 0 | } |
129 | 0 | return NULL; |
130 | 0 | } |
131 | | |
132 | | OpenAPI_ssm_1_t *OpenAPI_ssm_1_copy(OpenAPI_ssm_1_t *dst, OpenAPI_ssm_1_t *src) |
133 | 0 | { |
134 | 0 | cJSON *item = NULL; |
135 | 0 | char *content = NULL; |
136 | |
|
137 | 0 | ogs_assert(src); |
138 | 0 | item = OpenAPI_ssm_1_convertToJSON(src); |
139 | 0 | if (!item) { |
140 | 0 | ogs_error("OpenAPI_ssm_1_convertToJSON() failed"); |
141 | 0 | return NULL; |
142 | 0 | } |
143 | | |
144 | 0 | content = cJSON_Print(item); |
145 | 0 | cJSON_Delete(item); |
146 | |
|
147 | 0 | if (!content) { |
148 | 0 | ogs_error("cJSON_Print() failed"); |
149 | 0 | return NULL; |
150 | 0 | } |
151 | | |
152 | 0 | item = cJSON_Parse(content); |
153 | 0 | ogs_free(content); |
154 | 0 | if (!item) { |
155 | 0 | ogs_error("cJSON_Parse() failed"); |
156 | 0 | return NULL; |
157 | 0 | } |
158 | | |
159 | 0 | OpenAPI_ssm_1_free(dst); |
160 | 0 | dst = OpenAPI_ssm_1_parseFromJSON(item); |
161 | 0 | cJSON_Delete(item); |
162 | |
|
163 | 0 | return dst; |
164 | 0 | } |
165 | | |