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