/src/open5gs/lib/sbi/openapi/model/v2x_capability.c
Line | Count | Source |
1 | | |
2 | | #include <stdlib.h> |
3 | | #include <string.h> |
4 | | #include <stdio.h> |
5 | | #include "v2x_capability.h" |
6 | | |
7 | | OpenAPI_v2x_capability_t *OpenAPI_v2x_capability_create( |
8 | | bool is_lte_v2x, |
9 | | int lte_v2x, |
10 | | bool is_nr_v2x, |
11 | | int nr_v2x |
12 | | ) |
13 | 111 | { |
14 | 111 | OpenAPI_v2x_capability_t *v2x_capability_local_var = ogs_malloc(sizeof(OpenAPI_v2x_capability_t)); |
15 | 111 | ogs_assert(v2x_capability_local_var); |
16 | | |
17 | 111 | v2x_capability_local_var->is_lte_v2x = is_lte_v2x; |
18 | 111 | v2x_capability_local_var->lte_v2x = lte_v2x; |
19 | 111 | v2x_capability_local_var->is_nr_v2x = is_nr_v2x; |
20 | 111 | v2x_capability_local_var->nr_v2x = nr_v2x; |
21 | | |
22 | 111 | return v2x_capability_local_var; |
23 | 111 | } |
24 | | |
25 | | void OpenAPI_v2x_capability_free(OpenAPI_v2x_capability_t *v2x_capability) |
26 | 111 | { |
27 | 111 | OpenAPI_lnode_t *node = NULL; |
28 | | |
29 | 111 | if (NULL == v2x_capability) { |
30 | 0 | return; |
31 | 0 | } |
32 | 111 | ogs_free(v2x_capability); |
33 | 111 | } |
34 | | |
35 | | cJSON *OpenAPI_v2x_capability_convertToJSON(OpenAPI_v2x_capability_t *v2x_capability) |
36 | 0 | { |
37 | 0 | cJSON *item = NULL; |
38 | 0 | OpenAPI_lnode_t *node = NULL; |
39 | |
|
40 | 0 | if (v2x_capability == NULL) { |
41 | 0 | ogs_error("OpenAPI_v2x_capability_convertToJSON() failed [V2xCapability]"); |
42 | 0 | return NULL; |
43 | 0 | } |
44 | | |
45 | 0 | item = cJSON_CreateObject(); |
46 | 0 | if (v2x_capability->is_lte_v2x) { |
47 | 0 | if (cJSON_AddBoolToObject(item, "lteV2x", v2x_capability->lte_v2x) == NULL) { |
48 | 0 | ogs_error("OpenAPI_v2x_capability_convertToJSON() failed [lte_v2x]"); |
49 | 0 | goto end; |
50 | 0 | } |
51 | 0 | } |
52 | | |
53 | 0 | if (v2x_capability->is_nr_v2x) { |
54 | 0 | if (cJSON_AddBoolToObject(item, "nrV2x", v2x_capability->nr_v2x) == NULL) { |
55 | 0 | ogs_error("OpenAPI_v2x_capability_convertToJSON() failed [nr_v2x]"); |
56 | 0 | goto end; |
57 | 0 | } |
58 | 0 | } |
59 | | |
60 | 0 | end: |
61 | 0 | return item; |
62 | 0 | } |
63 | | |
64 | | OpenAPI_v2x_capability_t *OpenAPI_v2x_capability_parseFromJSON(cJSON *v2x_capabilityJSON) |
65 | 111 | { |
66 | 111 | OpenAPI_v2x_capability_t *v2x_capability_local_var = NULL; |
67 | 111 | OpenAPI_lnode_t *node = NULL; |
68 | 111 | cJSON *lte_v2x = NULL; |
69 | 111 | cJSON *nr_v2x = NULL; |
70 | 111 | lte_v2x = cJSON_GetObjectItemCaseSensitive(v2x_capabilityJSON, "lteV2x"); |
71 | 111 | if (lte_v2x) { |
72 | 0 | if (!cJSON_IsBool(lte_v2x)) { |
73 | 0 | ogs_error("OpenAPI_v2x_capability_parseFromJSON() failed [lte_v2x]"); |
74 | 0 | goto end; |
75 | 0 | } |
76 | 0 | } |
77 | | |
78 | 111 | nr_v2x = cJSON_GetObjectItemCaseSensitive(v2x_capabilityJSON, "nrV2x"); |
79 | 111 | if (nr_v2x) { |
80 | 0 | if (!cJSON_IsBool(nr_v2x)) { |
81 | 0 | ogs_error("OpenAPI_v2x_capability_parseFromJSON() failed [nr_v2x]"); |
82 | 0 | goto end; |
83 | 0 | } |
84 | 0 | } |
85 | | |
86 | 111 | v2x_capability_local_var = OpenAPI_v2x_capability_create ( |
87 | 111 | lte_v2x ? true : false, |
88 | 111 | lte_v2x ? lte_v2x->valueint : 0, |
89 | 111 | nr_v2x ? true : false, |
90 | 111 | nr_v2x ? nr_v2x->valueint : 0 |
91 | 111 | ); |
92 | | |
93 | 111 | return v2x_capability_local_var; |
94 | 0 | end: |
95 | 0 | return NULL; |
96 | 111 | } |
97 | | |
98 | | OpenAPI_v2x_capability_t *OpenAPI_v2x_capability_copy(OpenAPI_v2x_capability_t *dst, OpenAPI_v2x_capability_t *src) |
99 | 0 | { |
100 | 0 | cJSON *item = NULL; |
101 | 0 | char *content = NULL; |
102 | |
|
103 | 0 | ogs_assert(src); |
104 | 0 | item = OpenAPI_v2x_capability_convertToJSON(src); |
105 | 0 | if (!item) { |
106 | 0 | ogs_error("OpenAPI_v2x_capability_convertToJSON() failed"); |
107 | 0 | return NULL; |
108 | 0 | } |
109 | | |
110 | 0 | content = cJSON_Print(item); |
111 | 0 | cJSON_Delete(item); |
112 | |
|
113 | 0 | if (!content) { |
114 | 0 | ogs_error("cJSON_Print() failed"); |
115 | 0 | return NULL; |
116 | 0 | } |
117 | | |
118 | 0 | item = cJSON_Parse(content); |
119 | 0 | ogs_free(content); |
120 | 0 | if (!item) { |
121 | 0 | ogs_error("cJSON_Parse() failed"); |
122 | 0 | return NULL; |
123 | 0 | } |
124 | | |
125 | 0 | OpenAPI_v2x_capability_free(dst); |
126 | 0 | dst = OpenAPI_v2x_capability_parseFromJSON(item); |
127 | 0 | cJSON_Delete(item); |
128 | |
|
129 | 0 | return dst; |
130 | 0 | } |
131 | | |