Coverage Report

Created: 2026-06-30 06:14

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/open5gs/lib/sbi/openapi/model/qos_requirement.c
Line
Count
Source
1
2
#include <stdlib.h>
3
#include <string.h>
4
#include <stdio.h>
5
#include "qos_requirement.h"
6
7
OpenAPI_qos_requirement_t *OpenAPI_qos_requirement_create(
8
    bool is__5qi,
9
    int _5qi,
10
    char *gfbr_ul,
11
    char *gfbr_dl,
12
    OpenAPI_qos_resource_type_e res_type,
13
    bool is_pdb,
14
    int pdb,
15
    char *per,
16
    OpenAPI_velocity_estimate_t *device_speed,
17
    OpenAPI_device_type_e device_type
18
)
19
0
{
20
0
    OpenAPI_qos_requirement_t *qos_requirement_local_var = ogs_malloc(sizeof(OpenAPI_qos_requirement_t));
21
0
    ogs_assert(qos_requirement_local_var);
22
23
0
    qos_requirement_local_var->is__5qi = is__5qi;
24
0
    qos_requirement_local_var->_5qi = _5qi;
25
0
    qos_requirement_local_var->gfbr_ul = gfbr_ul;
26
0
    qos_requirement_local_var->gfbr_dl = gfbr_dl;
27
0
    qos_requirement_local_var->res_type = res_type;
28
0
    qos_requirement_local_var->is_pdb = is_pdb;
29
0
    qos_requirement_local_var->pdb = pdb;
30
0
    qos_requirement_local_var->per = per;
31
0
    qos_requirement_local_var->device_speed = device_speed;
32
0
    qos_requirement_local_var->device_type = device_type;
33
34
0
    return qos_requirement_local_var;
35
0
}
36
37
void OpenAPI_qos_requirement_free(OpenAPI_qos_requirement_t *qos_requirement)
38
0
{
39
0
    OpenAPI_lnode_t *node = NULL;
40
41
0
    if (NULL == qos_requirement) {
42
0
        return;
43
0
    }
44
0
    if (qos_requirement->gfbr_ul) {
45
0
        ogs_free(qos_requirement->gfbr_ul);
46
0
        qos_requirement->gfbr_ul = NULL;
47
0
    }
48
0
    if (qos_requirement->gfbr_dl) {
49
0
        ogs_free(qos_requirement->gfbr_dl);
50
0
        qos_requirement->gfbr_dl = NULL;
51
0
    }
52
0
    if (qos_requirement->per) {
53
0
        ogs_free(qos_requirement->per);
54
0
        qos_requirement->per = NULL;
55
0
    }
56
0
    if (qos_requirement->device_speed) {
57
0
        OpenAPI_velocity_estimate_free(qos_requirement->device_speed);
58
0
        qos_requirement->device_speed = NULL;
59
0
    }
60
0
    ogs_free(qos_requirement);
61
0
}
62
63
cJSON *OpenAPI_qos_requirement_convertToJSON(OpenAPI_qos_requirement_t *qos_requirement)
64
0
{
65
0
    cJSON *item = NULL;
66
0
    OpenAPI_lnode_t *node = NULL;
67
68
0
    if (qos_requirement == NULL) {
69
0
        ogs_error("OpenAPI_qos_requirement_convertToJSON() failed [QosRequirement]");
70
0
        return NULL;
71
0
    }
72
73
0
    item = cJSON_CreateObject();
74
0
    if (qos_requirement->is__5qi) {
75
0
    if (cJSON_AddNumberToObject(item, "5qi", qos_requirement->_5qi) == NULL) {
76
0
        ogs_error("OpenAPI_qos_requirement_convertToJSON() failed [_5qi]");
77
0
        goto end;
78
0
    }
79
0
    }
80
81
0
    if (qos_requirement->gfbr_ul) {
82
0
    if (cJSON_AddStringToObject(item, "gfbrUl", qos_requirement->gfbr_ul) == NULL) {
83
0
        ogs_error("OpenAPI_qos_requirement_convertToJSON() failed [gfbr_ul]");
84
0
        goto end;
85
0
    }
86
0
    }
87
88
0
    if (qos_requirement->gfbr_dl) {
89
0
    if (cJSON_AddStringToObject(item, "gfbrDl", qos_requirement->gfbr_dl) == NULL) {
90
0
        ogs_error("OpenAPI_qos_requirement_convertToJSON() failed [gfbr_dl]");
91
0
        goto end;
92
0
    }
93
0
    }
94
95
0
    if (qos_requirement->res_type != OpenAPI_qos_resource_type_NULL) {
96
0
    if (cJSON_AddStringToObject(item, "resType", OpenAPI_qos_resource_type_ToString(qos_requirement->res_type)) == NULL) {
97
0
        ogs_error("OpenAPI_qos_requirement_convertToJSON() failed [res_type]");
98
0
        goto end;
99
0
    }
100
0
    }
101
102
0
    if (qos_requirement->is_pdb) {
103
0
    if (cJSON_AddNumberToObject(item, "pdb", qos_requirement->pdb) == NULL) {
104
0
        ogs_error("OpenAPI_qos_requirement_convertToJSON() failed [pdb]");
105
0
        goto end;
106
0
    }
107
0
    }
108
109
0
    if (qos_requirement->per) {
110
0
    if (cJSON_AddStringToObject(item, "per", qos_requirement->per) == NULL) {
111
0
        ogs_error("OpenAPI_qos_requirement_convertToJSON() failed [per]");
112
0
        goto end;
113
0
    }
114
0
    }
115
116
0
    if (qos_requirement->device_speed) {
117
0
    cJSON *device_speed_local_JSON = OpenAPI_velocity_estimate_convertToJSON(qos_requirement->device_speed);
118
0
    if (device_speed_local_JSON == NULL) {
119
0
        ogs_error("OpenAPI_qos_requirement_convertToJSON() failed [device_speed]");
120
0
        goto end;
121
0
    }
122
0
    cJSON_AddItemToObject(item, "deviceSpeed", device_speed_local_JSON);
123
0
    if (item->child == NULL) {
124
0
        ogs_error("OpenAPI_qos_requirement_convertToJSON() failed [device_speed]");
125
0
        goto end;
126
0
    }
127
0
    }
128
129
0
    if (qos_requirement->device_type != OpenAPI_device_type_NULL) {
130
0
    if (cJSON_AddStringToObject(item, "deviceType", OpenAPI_device_type_ToString(qos_requirement->device_type)) == NULL) {
131
0
        ogs_error("OpenAPI_qos_requirement_convertToJSON() failed [device_type]");
132
0
        goto end;
133
0
    }
134
0
    }
135
136
0
end:
137
0
    return item;
138
0
}
139
140
OpenAPI_qos_requirement_t *OpenAPI_qos_requirement_parseFromJSON(cJSON *qos_requirementJSON)
141
0
{
142
0
    OpenAPI_qos_requirement_t *qos_requirement_local_var = NULL;
143
0
    OpenAPI_lnode_t *node = NULL;
144
0
    cJSON *_5qi = NULL;
145
0
    cJSON *gfbr_ul = NULL;
146
0
    cJSON *gfbr_dl = NULL;
147
0
    cJSON *res_type = NULL;
148
0
    OpenAPI_qos_resource_type_e res_typeVariable = 0;
149
0
    cJSON *pdb = NULL;
150
0
    cJSON *per = NULL;
151
0
    cJSON *device_speed = NULL;
152
0
    OpenAPI_velocity_estimate_t *device_speed_local_nonprim = NULL;
153
0
    cJSON *device_type = NULL;
154
0
    OpenAPI_device_type_e device_typeVariable = 0;
155
0
    _5qi = cJSON_GetObjectItemCaseSensitive(qos_requirementJSON, "5qi");
156
0
    if (_5qi) {
157
0
    if (!cJSON_IsNumber(_5qi)) {
158
0
        ogs_error("OpenAPI_qos_requirement_parseFromJSON() failed [_5qi]");
159
0
        goto end;
160
0
    }
161
0
    }
162
163
0
    gfbr_ul = cJSON_GetObjectItemCaseSensitive(qos_requirementJSON, "gfbrUl");
164
0
    if (gfbr_ul) {
165
0
    if (!cJSON_IsString(gfbr_ul) && !cJSON_IsNull(gfbr_ul)) {
166
0
        ogs_error("OpenAPI_qos_requirement_parseFromJSON() failed [gfbr_ul]");
167
0
        goto end;
168
0
    }
169
0
    }
170
171
0
    gfbr_dl = cJSON_GetObjectItemCaseSensitive(qos_requirementJSON, "gfbrDl");
172
0
    if (gfbr_dl) {
173
0
    if (!cJSON_IsString(gfbr_dl) && !cJSON_IsNull(gfbr_dl)) {
174
0
        ogs_error("OpenAPI_qos_requirement_parseFromJSON() failed [gfbr_dl]");
175
0
        goto end;
176
0
    }
177
0
    }
178
179
0
    res_type = cJSON_GetObjectItemCaseSensitive(qos_requirementJSON, "resType");
180
0
    if (res_type) {
181
0
    if (!cJSON_IsString(res_type)) {
182
0
        ogs_error("OpenAPI_qos_requirement_parseFromJSON() failed [res_type]");
183
0
        goto end;
184
0
    }
185
0
    res_typeVariable = OpenAPI_qos_resource_type_FromString(res_type->valuestring);
186
0
    }
187
188
0
    pdb = cJSON_GetObjectItemCaseSensitive(qos_requirementJSON, "pdb");
189
0
    if (pdb) {
190
0
    if (!cJSON_IsNumber(pdb)) {
191
0
        ogs_error("OpenAPI_qos_requirement_parseFromJSON() failed [pdb]");
192
0
        goto end;
193
0
    }
194
0
    }
195
196
0
    per = cJSON_GetObjectItemCaseSensitive(qos_requirementJSON, "per");
197
0
    if (per) {
198
0
    if (!cJSON_IsString(per) && !cJSON_IsNull(per)) {
199
0
        ogs_error("OpenAPI_qos_requirement_parseFromJSON() failed [per]");
200
0
        goto end;
201
0
    }
202
0
    }
203
204
0
    device_speed = cJSON_GetObjectItemCaseSensitive(qos_requirementJSON, "deviceSpeed");
205
0
    if (device_speed) {
206
0
    device_speed_local_nonprim = OpenAPI_velocity_estimate_parseFromJSON(device_speed);
207
0
    if (!device_speed_local_nonprim) {
208
0
        ogs_error("OpenAPI_velocity_estimate_parseFromJSON failed [device_speed]");
209
0
        goto end;
210
0
    }
211
0
    }
212
213
0
    device_type = cJSON_GetObjectItemCaseSensitive(qos_requirementJSON, "deviceType");
214
0
    if (device_type) {
215
0
    if (!cJSON_IsString(device_type)) {
216
0
        ogs_error("OpenAPI_qos_requirement_parseFromJSON() failed [device_type]");
217
0
        goto end;
218
0
    }
219
0
    device_typeVariable = OpenAPI_device_type_FromString(device_type->valuestring);
220
0
    }
221
222
0
    qos_requirement_local_var = OpenAPI_qos_requirement_create (
223
0
        _5qi ? true : false,
224
0
        _5qi ? _5qi->valuedouble : 0,
225
0
        gfbr_ul && !cJSON_IsNull(gfbr_ul) ? ogs_strdup(gfbr_ul->valuestring) : NULL,
226
0
        gfbr_dl && !cJSON_IsNull(gfbr_dl) ? ogs_strdup(gfbr_dl->valuestring) : NULL,
227
0
        res_type ? res_typeVariable : 0,
228
0
        pdb ? true : false,
229
0
        pdb ? pdb->valuedouble : 0,
230
0
        per && !cJSON_IsNull(per) ? ogs_strdup(per->valuestring) : NULL,
231
0
        device_speed ? device_speed_local_nonprim : NULL,
232
0
        device_type ? device_typeVariable : 0
233
0
    );
234
235
0
    return qos_requirement_local_var;
236
0
end:
237
0
    if (device_speed_local_nonprim) {
238
0
        OpenAPI_velocity_estimate_free(device_speed_local_nonprim);
239
0
        device_speed_local_nonprim = NULL;
240
0
    }
241
0
    return NULL;
242
0
}
243
244
OpenAPI_qos_requirement_t *OpenAPI_qos_requirement_copy(OpenAPI_qos_requirement_t *dst, OpenAPI_qos_requirement_t *src)
245
0
{
246
0
    cJSON *item = NULL;
247
0
    char *content = NULL;
248
249
0
    ogs_assert(src);
250
0
    item = OpenAPI_qos_requirement_convertToJSON(src);
251
0
    if (!item) {
252
0
        ogs_error("OpenAPI_qos_requirement_convertToJSON() failed");
253
0
        return NULL;
254
0
    }
255
256
0
    content = cJSON_Print(item);
257
0
    cJSON_Delete(item);
258
259
0
    if (!content) {
260
0
        ogs_error("cJSON_Print() failed");
261
0
        return NULL;
262
0
    }
263
264
0
    item = cJSON_Parse(content);
265
0
    ogs_free(content);
266
0
    if (!item) {
267
0
        ogs_error("cJSON_Parse() failed");
268
0
        return NULL;
269
0
    }
270
271
0
    OpenAPI_qos_requirement_free(dst);
272
0
    dst = OpenAPI_qos_requirement_parseFromJSON(item);
273
0
    cJSON_Delete(item);
274
275
0
    return dst;
276
0
}
277