/src/open5gs/lib/sbi/openapi/model/identity_range.c
Line | Count | Source |
1 | | |
2 | | #include <stdlib.h> |
3 | | #include <string.h> |
4 | | #include <stdio.h> |
5 | | #include "identity_range.h" |
6 | | |
7 | | OpenAPI_identity_range_t *OpenAPI_identity_range_create( |
8 | | char *start, |
9 | | char *end, |
10 | | char *pattern |
11 | | ) |
12 | 22.6k | { |
13 | 22.6k | OpenAPI_identity_range_t *identity_range_local_var = ogs_malloc(sizeof(OpenAPI_identity_range_t)); |
14 | 22.6k | ogs_assert(identity_range_local_var); |
15 | | |
16 | 22.6k | identity_range_local_var->start = start; |
17 | 22.6k | identity_range_local_var->end = end; |
18 | 22.6k | identity_range_local_var->pattern = pattern; |
19 | | |
20 | 22.6k | return identity_range_local_var; |
21 | 22.6k | } |
22 | | |
23 | | void OpenAPI_identity_range_free(OpenAPI_identity_range_t *identity_range) |
24 | 23.1k | { |
25 | 23.1k | OpenAPI_lnode_t *node = NULL; |
26 | | |
27 | 23.1k | if (NULL == identity_range) { |
28 | 479 | return; |
29 | 479 | } |
30 | 22.6k | if (identity_range->start) { |
31 | 214 | ogs_free(identity_range->start); |
32 | 214 | identity_range->start = NULL; |
33 | 214 | } |
34 | 22.6k | if (identity_range->end) { |
35 | 194 | ogs_free(identity_range->end); |
36 | 194 | identity_range->end = NULL; |
37 | 194 | } |
38 | 22.6k | if (identity_range->pattern) { |
39 | 234 | ogs_free(identity_range->pattern); |
40 | 234 | identity_range->pattern = NULL; |
41 | 234 | } |
42 | 22.6k | ogs_free(identity_range); |
43 | 22.6k | } |
44 | | |
45 | | cJSON *OpenAPI_identity_range_convertToJSON(OpenAPI_identity_range_t *identity_range) |
46 | 0 | { |
47 | 0 | cJSON *item = NULL; |
48 | 0 | OpenAPI_lnode_t *node = NULL; |
49 | |
|
50 | 0 | if (identity_range == NULL) { |
51 | 0 | ogs_error("OpenAPI_identity_range_convertToJSON() failed [IdentityRange]"); |
52 | 0 | return NULL; |
53 | 0 | } |
54 | | |
55 | 0 | item = cJSON_CreateObject(); |
56 | 0 | if (identity_range->start) { |
57 | 0 | if (cJSON_AddStringToObject(item, "start", identity_range->start) == NULL) { |
58 | 0 | ogs_error("OpenAPI_identity_range_convertToJSON() failed [start]"); |
59 | 0 | goto end; |
60 | 0 | } |
61 | 0 | } |
62 | | |
63 | 0 | if (identity_range->end) { |
64 | 0 | if (cJSON_AddStringToObject(item, "end", identity_range->end) == NULL) { |
65 | 0 | ogs_error("OpenAPI_identity_range_convertToJSON() failed [end]"); |
66 | 0 | goto end; |
67 | 0 | } |
68 | 0 | } |
69 | | |
70 | 0 | if (identity_range->pattern) { |
71 | 0 | if (cJSON_AddStringToObject(item, "pattern", identity_range->pattern) == NULL) { |
72 | 0 | ogs_error("OpenAPI_identity_range_convertToJSON() failed [pattern]"); |
73 | 0 | goto end; |
74 | 0 | } |
75 | 0 | } |
76 | | |
77 | 0 | end: |
78 | 0 | return item; |
79 | 0 | } |
80 | | |
81 | | OpenAPI_identity_range_t *OpenAPI_identity_range_parseFromJSON(cJSON *identity_rangeJSON) |
82 | 26.0k | { |
83 | 26.0k | OpenAPI_identity_range_t *identity_range_local_var = NULL; |
84 | 26.0k | OpenAPI_lnode_t *node = NULL; |
85 | 26.0k | cJSON *start = NULL; |
86 | 26.0k | cJSON *end = NULL; |
87 | 26.0k | cJSON *pattern = NULL; |
88 | 26.0k | start = cJSON_GetObjectItemCaseSensitive(identity_rangeJSON, "start"); |
89 | 26.0k | if (start) { |
90 | 652 | if (!cJSON_IsString(start) && !cJSON_IsNull(start)) { |
91 | 237 | ogs_error("OpenAPI_identity_range_parseFromJSON() failed [start]"); |
92 | 237 | goto end; |
93 | 237 | } |
94 | 652 | } |
95 | | |
96 | 25.7k | end = cJSON_GetObjectItemCaseSensitive(identity_rangeJSON, "end"); |
97 | 25.7k | if (end) { |
98 | 2.99k | if (!cJSON_IsString(end) && !cJSON_IsNull(end)) { |
99 | 2.59k | ogs_error("OpenAPI_identity_range_parseFromJSON() failed [end]"); |
100 | 2.59k | goto end; |
101 | 2.59k | } |
102 | 2.99k | } |
103 | | |
104 | 23.1k | pattern = cJSON_GetObjectItemCaseSensitive(identity_rangeJSON, "pattern"); |
105 | 23.1k | if (pattern) { |
106 | 1.11k | if (!cJSON_IsString(pattern) && !cJSON_IsNull(pattern)) { |
107 | 498 | ogs_error("OpenAPI_identity_range_parseFromJSON() failed [pattern]"); |
108 | 498 | goto end; |
109 | 498 | } |
110 | 1.11k | } |
111 | | |
112 | 22.6k | identity_range_local_var = OpenAPI_identity_range_create ( |
113 | 22.6k | start && !cJSON_IsNull(start) ? ogs_strdup(start->valuestring) : NULL, |
114 | 22.6k | end && !cJSON_IsNull(end) ? ogs_strdup(end->valuestring) : NULL, |
115 | 22.6k | pattern && !cJSON_IsNull(pattern) ? ogs_strdup(pattern->valuestring) : NULL |
116 | 22.6k | ); |
117 | | |
118 | 22.6k | return identity_range_local_var; |
119 | 3.33k | end: |
120 | 3.33k | return NULL; |
121 | 23.1k | } |
122 | | |
123 | | OpenAPI_identity_range_t *OpenAPI_identity_range_copy(OpenAPI_identity_range_t *dst, OpenAPI_identity_range_t *src) |
124 | 0 | { |
125 | 0 | cJSON *item = NULL; |
126 | 0 | char *content = NULL; |
127 | |
|
128 | 0 | ogs_assert(src); |
129 | 0 | item = OpenAPI_identity_range_convertToJSON(src); |
130 | 0 | if (!item) { |
131 | 0 | ogs_error("OpenAPI_identity_range_convertToJSON() failed"); |
132 | 0 | return NULL; |
133 | 0 | } |
134 | | |
135 | 0 | content = cJSON_Print(item); |
136 | 0 | cJSON_Delete(item); |
137 | |
|
138 | 0 | if (!content) { |
139 | 0 | ogs_error("cJSON_Print() failed"); |
140 | 0 | return NULL; |
141 | 0 | } |
142 | | |
143 | 0 | item = cJSON_Parse(content); |
144 | 0 | ogs_free(content); |
145 | 0 | if (!item) { |
146 | 0 | ogs_error("cJSON_Parse() failed"); |
147 | 0 | return NULL; |
148 | 0 | } |
149 | | |
150 | 0 | OpenAPI_identity_range_free(dst); |
151 | 0 | dst = OpenAPI_identity_range_parseFromJSON(item); |
152 | 0 | cJSON_Delete(item); |
153 | |
|
154 | 0 | return dst; |
155 | 0 | } |
156 | | |