Coverage Report

Created: 2026-08-17 06:12

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/open5gs/lib/sbi/openapi/model/dnn_info.c
Line
Count
Source
1
2
#include <stdlib.h>
3
#include <string.h>
4
#include <stdio.h>
5
#include "dnn_info.h"
6
7
OpenAPI_dnn_info_t *OpenAPI_dnn_info_create(
8
    char *dnn,
9
    bool is_default_dnn_indicator,
10
    int default_dnn_indicator,
11
    bool is_lbo_roaming_allowed,
12
    int lbo_roaming_allowed,
13
    bool is_iwk_eps_ind,
14
    int iwk_eps_ind,
15
    bool is_dnn_barred,
16
    int dnn_barred,
17
    bool is_invoke_nef_ind,
18
    int invoke_nef_ind,
19
    OpenAPI_list_t *smf_list,
20
    OpenAPI_ip_index_t *ipv4_index,
21
    OpenAPI_ip_index_t *ipv6_index,
22
    bool is_same_smf_ind,
23
    int same_smf_ind,
24
    bool is_hr_sbo_allowed,
25
    int hr_sbo_allowed,
26
    OpenAPI_additional_smf_selection_info_t *additional_smf_selection_info,
27
    bool is_local_offloading_mngt_ind,
28
    int local_offloading_mngt_ind
29
)
30
0
{
31
0
    OpenAPI_dnn_info_t *dnn_info_local_var = ogs_malloc(sizeof(OpenAPI_dnn_info_t));
32
0
    ogs_assert(dnn_info_local_var);
33
34
0
    dnn_info_local_var->dnn = dnn;
35
0
    dnn_info_local_var->is_default_dnn_indicator = is_default_dnn_indicator;
36
0
    dnn_info_local_var->default_dnn_indicator = default_dnn_indicator;
37
0
    dnn_info_local_var->is_lbo_roaming_allowed = is_lbo_roaming_allowed;
38
0
    dnn_info_local_var->lbo_roaming_allowed = lbo_roaming_allowed;
39
0
    dnn_info_local_var->is_iwk_eps_ind = is_iwk_eps_ind;
40
0
    dnn_info_local_var->iwk_eps_ind = iwk_eps_ind;
41
0
    dnn_info_local_var->is_dnn_barred = is_dnn_barred;
42
0
    dnn_info_local_var->dnn_barred = dnn_barred;
43
0
    dnn_info_local_var->is_invoke_nef_ind = is_invoke_nef_ind;
44
0
    dnn_info_local_var->invoke_nef_ind = invoke_nef_ind;
45
0
    dnn_info_local_var->smf_list = smf_list;
46
0
    dnn_info_local_var->ipv4_index = ipv4_index;
47
0
    dnn_info_local_var->ipv6_index = ipv6_index;
48
0
    dnn_info_local_var->is_same_smf_ind = is_same_smf_ind;
49
0
    dnn_info_local_var->same_smf_ind = same_smf_ind;
50
0
    dnn_info_local_var->is_hr_sbo_allowed = is_hr_sbo_allowed;
51
0
    dnn_info_local_var->hr_sbo_allowed = hr_sbo_allowed;
52
0
    dnn_info_local_var->additional_smf_selection_info = additional_smf_selection_info;
53
0
    dnn_info_local_var->is_local_offloading_mngt_ind = is_local_offloading_mngt_ind;
54
0
    dnn_info_local_var->local_offloading_mngt_ind = local_offloading_mngt_ind;
55
56
0
    return dnn_info_local_var;
57
0
}
58
59
void OpenAPI_dnn_info_free(OpenAPI_dnn_info_t *dnn_info)
60
0
{
61
0
    OpenAPI_lnode_t *node = NULL;
62
63
0
    if (NULL == dnn_info) {
64
0
        return;
65
0
    }
66
0
    if (dnn_info->dnn) {
67
0
        ogs_free(dnn_info->dnn);
68
0
        dnn_info->dnn = NULL;
69
0
    }
70
0
    if (dnn_info->smf_list) {
71
0
        OpenAPI_list_for_each(dnn_info->smf_list, node) {
72
0
            ogs_free(node->data);
73
0
        }
74
0
        OpenAPI_list_free(dnn_info->smf_list);
75
0
        dnn_info->smf_list = NULL;
76
0
    }
77
0
    if (dnn_info->ipv4_index) {
78
0
        OpenAPI_ip_index_free(dnn_info->ipv4_index);
79
0
        dnn_info->ipv4_index = NULL;
80
0
    }
81
0
    if (dnn_info->ipv6_index) {
82
0
        OpenAPI_ip_index_free(dnn_info->ipv6_index);
83
0
        dnn_info->ipv6_index = NULL;
84
0
    }
85
0
    if (dnn_info->additional_smf_selection_info) {
86
0
        OpenAPI_additional_smf_selection_info_free(dnn_info->additional_smf_selection_info);
87
0
        dnn_info->additional_smf_selection_info = NULL;
88
0
    }
89
0
    ogs_free(dnn_info);
90
0
}
91
92
cJSON *OpenAPI_dnn_info_convertToJSON(OpenAPI_dnn_info_t *dnn_info)
93
0
{
94
0
    cJSON *item = NULL;
95
0
    OpenAPI_lnode_t *node = NULL;
96
97
0
    if (dnn_info == NULL) {
98
0
        ogs_error("OpenAPI_dnn_info_convertToJSON() failed [DnnInfo]");
99
0
        return NULL;
100
0
    }
101
102
0
    item = cJSON_CreateObject();
103
0
    if (!dnn_info->dnn) {
104
0
        ogs_error("OpenAPI_dnn_info_convertToJSON() failed [dnn]");
105
0
        return NULL;
106
0
    }
107
0
    if (cJSON_AddStringToObject(item, "dnn", dnn_info->dnn) == NULL) {
108
0
        ogs_error("OpenAPI_dnn_info_convertToJSON() failed [dnn]");
109
0
        goto end;
110
0
    }
111
112
0
    if (dnn_info->is_default_dnn_indicator) {
113
0
    if (cJSON_AddBoolToObject(item, "defaultDnnIndicator", dnn_info->default_dnn_indicator) == NULL) {
114
0
        ogs_error("OpenAPI_dnn_info_convertToJSON() failed [default_dnn_indicator]");
115
0
        goto end;
116
0
    }
117
0
    }
118
119
0
    if (dnn_info->is_lbo_roaming_allowed) {
120
0
    if (cJSON_AddBoolToObject(item, "lboRoamingAllowed", dnn_info->lbo_roaming_allowed) == NULL) {
121
0
        ogs_error("OpenAPI_dnn_info_convertToJSON() failed [lbo_roaming_allowed]");
122
0
        goto end;
123
0
    }
124
0
    }
125
126
0
    if (dnn_info->is_iwk_eps_ind) {
127
0
    if (cJSON_AddBoolToObject(item, "iwkEpsInd", dnn_info->iwk_eps_ind) == NULL) {
128
0
        ogs_error("OpenAPI_dnn_info_convertToJSON() failed [iwk_eps_ind]");
129
0
        goto end;
130
0
    }
131
0
    }
132
133
0
    if (dnn_info->is_dnn_barred) {
134
0
    if (cJSON_AddBoolToObject(item, "dnnBarred", dnn_info->dnn_barred) == NULL) {
135
0
        ogs_error("OpenAPI_dnn_info_convertToJSON() failed [dnn_barred]");
136
0
        goto end;
137
0
    }
138
0
    }
139
140
0
    if (dnn_info->is_invoke_nef_ind) {
141
0
    if (cJSON_AddBoolToObject(item, "invokeNefInd", dnn_info->invoke_nef_ind) == NULL) {
142
0
        ogs_error("OpenAPI_dnn_info_convertToJSON() failed [invoke_nef_ind]");
143
0
        goto end;
144
0
    }
145
0
    }
146
147
0
    if (dnn_info->smf_list) {
148
0
    cJSON *smf_listList = cJSON_AddArrayToObject(item, "smfList");
149
0
    if (smf_listList == NULL) {
150
0
        ogs_error("OpenAPI_dnn_info_convertToJSON() failed [smf_list]");
151
0
        goto end;
152
0
    }
153
0
    OpenAPI_list_for_each(dnn_info->smf_list, node) {
154
0
        if (cJSON_AddStringToObject(smf_listList, "", (char*)node->data) == NULL) {
155
0
            ogs_error("OpenAPI_dnn_info_convertToJSON() failed [smf_list]");
156
0
            goto end;
157
0
        }
158
0
    }
159
0
    }
160
161
0
    if (dnn_info->ipv4_index) {
162
0
    cJSON *ipv4_index_local_JSON = OpenAPI_ip_index_convertToJSON(dnn_info->ipv4_index);
163
0
    if (ipv4_index_local_JSON == NULL) {
164
0
        ogs_error("OpenAPI_dnn_info_convertToJSON() failed [ipv4_index]");
165
0
        goto end;
166
0
    }
167
0
    cJSON_AddItemToObject(item, "ipv4Index", ipv4_index_local_JSON);
168
0
    if (item->child == NULL) {
169
0
        ogs_error("OpenAPI_dnn_info_convertToJSON() failed [ipv4_index]");
170
0
        goto end;
171
0
    }
172
0
    }
173
174
0
    if (dnn_info->ipv6_index) {
175
0
    cJSON *ipv6_index_local_JSON = OpenAPI_ip_index_convertToJSON(dnn_info->ipv6_index);
176
0
    if (ipv6_index_local_JSON == NULL) {
177
0
        ogs_error("OpenAPI_dnn_info_convertToJSON() failed [ipv6_index]");
178
0
        goto end;
179
0
    }
180
0
    cJSON_AddItemToObject(item, "ipv6Index", ipv6_index_local_JSON);
181
0
    if (item->child == NULL) {
182
0
        ogs_error("OpenAPI_dnn_info_convertToJSON() failed [ipv6_index]");
183
0
        goto end;
184
0
    }
185
0
    }
186
187
0
    if (dnn_info->is_same_smf_ind) {
188
0
    if (cJSON_AddBoolToObject(item, "sameSmfInd", dnn_info->same_smf_ind) == NULL) {
189
0
        ogs_error("OpenAPI_dnn_info_convertToJSON() failed [same_smf_ind]");
190
0
        goto end;
191
0
    }
192
0
    }
193
194
0
    if (dnn_info->is_hr_sbo_allowed) {
195
0
    if (cJSON_AddBoolToObject(item, "hrSboAllowed", dnn_info->hr_sbo_allowed) == NULL) {
196
0
        ogs_error("OpenAPI_dnn_info_convertToJSON() failed [hr_sbo_allowed]");
197
0
        goto end;
198
0
    }
199
0
    }
200
201
0
    if (dnn_info->additional_smf_selection_info) {
202
0
    cJSON *additional_smf_selection_info_local_JSON = OpenAPI_additional_smf_selection_info_convertToJSON(dnn_info->additional_smf_selection_info);
203
0
    if (additional_smf_selection_info_local_JSON == NULL) {
204
0
        ogs_error("OpenAPI_dnn_info_convertToJSON() failed [additional_smf_selection_info]");
205
0
        goto end;
206
0
    }
207
0
    cJSON_AddItemToObject(item, "additionalSmfSelectionInfo", additional_smf_selection_info_local_JSON);
208
0
    if (item->child == NULL) {
209
0
        ogs_error("OpenAPI_dnn_info_convertToJSON() failed [additional_smf_selection_info]");
210
0
        goto end;
211
0
    }
212
0
    }
213
214
0
    if (dnn_info->is_local_offloading_mngt_ind) {
215
0
    if (cJSON_AddBoolToObject(item, "localOffloadingMngtInd", dnn_info->local_offloading_mngt_ind) == NULL) {
216
0
        ogs_error("OpenAPI_dnn_info_convertToJSON() failed [local_offloading_mngt_ind]");
217
0
        goto end;
218
0
    }
219
0
    }
220
221
0
end:
222
0
    return item;
223
0
}
224
225
OpenAPI_dnn_info_t *OpenAPI_dnn_info_parseFromJSON(cJSON *dnn_infoJSON)
226
0
{
227
0
    OpenAPI_dnn_info_t *dnn_info_local_var = NULL;
228
0
    OpenAPI_lnode_t *node = NULL;
229
0
    cJSON *dnn = NULL;
230
0
    cJSON *default_dnn_indicator = NULL;
231
0
    cJSON *lbo_roaming_allowed = NULL;
232
0
    cJSON *iwk_eps_ind = NULL;
233
0
    cJSON *dnn_barred = NULL;
234
0
    cJSON *invoke_nef_ind = NULL;
235
0
    cJSON *smf_list = NULL;
236
0
    OpenAPI_list_t *smf_listList = NULL;
237
0
    cJSON *ipv4_index = NULL;
238
0
    OpenAPI_ip_index_t *ipv4_index_local_nonprim = NULL;
239
0
    cJSON *ipv6_index = NULL;
240
0
    OpenAPI_ip_index_t *ipv6_index_local_nonprim = NULL;
241
0
    cJSON *same_smf_ind = NULL;
242
0
    cJSON *hr_sbo_allowed = NULL;
243
0
    cJSON *additional_smf_selection_info = NULL;
244
0
    OpenAPI_additional_smf_selection_info_t *additional_smf_selection_info_local_nonprim = NULL;
245
0
    cJSON *local_offloading_mngt_ind = NULL;
246
0
    dnn = cJSON_GetObjectItemCaseSensitive(dnn_infoJSON, "dnn");
247
0
    if (!dnn) {
248
0
        ogs_error("OpenAPI_dnn_info_parseFromJSON() failed [dnn]");
249
0
        goto end;
250
0
    }
251
0
    if (!cJSON_IsString(dnn)) {
252
0
        ogs_error("OpenAPI_dnn_info_parseFromJSON() failed [dnn]");
253
0
        goto end;
254
0
    }
255
256
0
    default_dnn_indicator = cJSON_GetObjectItemCaseSensitive(dnn_infoJSON, "defaultDnnIndicator");
257
0
    if (default_dnn_indicator) {
258
0
    if (!cJSON_IsBool(default_dnn_indicator)) {
259
0
        ogs_error("OpenAPI_dnn_info_parseFromJSON() failed [default_dnn_indicator]");
260
0
        goto end;
261
0
    }
262
0
    }
263
264
0
    lbo_roaming_allowed = cJSON_GetObjectItemCaseSensitive(dnn_infoJSON, "lboRoamingAllowed");
265
0
    if (lbo_roaming_allowed) {
266
0
    if (!cJSON_IsBool(lbo_roaming_allowed)) {
267
0
        ogs_error("OpenAPI_dnn_info_parseFromJSON() failed [lbo_roaming_allowed]");
268
0
        goto end;
269
0
    }
270
0
    }
271
272
0
    iwk_eps_ind = cJSON_GetObjectItemCaseSensitive(dnn_infoJSON, "iwkEpsInd");
273
0
    if (iwk_eps_ind) {
274
0
    if (!cJSON_IsBool(iwk_eps_ind)) {
275
0
        ogs_error("OpenAPI_dnn_info_parseFromJSON() failed [iwk_eps_ind]");
276
0
        goto end;
277
0
    }
278
0
    }
279
280
0
    dnn_barred = cJSON_GetObjectItemCaseSensitive(dnn_infoJSON, "dnnBarred");
281
0
    if (dnn_barred) {
282
0
    if (!cJSON_IsBool(dnn_barred)) {
283
0
        ogs_error("OpenAPI_dnn_info_parseFromJSON() failed [dnn_barred]");
284
0
        goto end;
285
0
    }
286
0
    }
287
288
0
    invoke_nef_ind = cJSON_GetObjectItemCaseSensitive(dnn_infoJSON, "invokeNefInd");
289
0
    if (invoke_nef_ind) {
290
0
    if (!cJSON_IsBool(invoke_nef_ind)) {
291
0
        ogs_error("OpenAPI_dnn_info_parseFromJSON() failed [invoke_nef_ind]");
292
0
        goto end;
293
0
    }
294
0
    }
295
296
0
    smf_list = cJSON_GetObjectItemCaseSensitive(dnn_infoJSON, "smfList");
297
0
    if (smf_list) {
298
0
        cJSON *smf_list_local = NULL;
299
0
        if (!cJSON_IsArray(smf_list)) {
300
0
            ogs_error("OpenAPI_dnn_info_parseFromJSON() failed [smf_list]");
301
0
            goto end;
302
0
        }
303
304
0
        smf_listList = OpenAPI_list_create();
305
306
0
        cJSON_ArrayForEach(smf_list_local, smf_list) {
307
0
            double *localDouble = NULL;
308
0
            int *localInt = NULL;
309
0
            if (!cJSON_IsString(smf_list_local)) {
310
0
                ogs_error("OpenAPI_dnn_info_parseFromJSON() failed [smf_list]");
311
0
                goto end;
312
0
            }
313
0
            OpenAPI_list_add(smf_listList, ogs_strdup(smf_list_local->valuestring));
314
0
        }
315
0
    }
316
317
0
    ipv4_index = cJSON_GetObjectItemCaseSensitive(dnn_infoJSON, "ipv4Index");
318
0
    if (ipv4_index) {
319
0
    ipv4_index_local_nonprim = OpenAPI_ip_index_parseFromJSON(ipv4_index);
320
0
    if (!ipv4_index_local_nonprim) {
321
0
        ogs_error("OpenAPI_ip_index_parseFromJSON failed [ipv4_index]");
322
0
        goto end;
323
0
    }
324
0
    }
325
326
0
    ipv6_index = cJSON_GetObjectItemCaseSensitive(dnn_infoJSON, "ipv6Index");
327
0
    if (ipv6_index) {
328
0
    ipv6_index_local_nonprim = OpenAPI_ip_index_parseFromJSON(ipv6_index);
329
0
    if (!ipv6_index_local_nonprim) {
330
0
        ogs_error("OpenAPI_ip_index_parseFromJSON failed [ipv6_index]");
331
0
        goto end;
332
0
    }
333
0
    }
334
335
0
    same_smf_ind = cJSON_GetObjectItemCaseSensitive(dnn_infoJSON, "sameSmfInd");
336
0
    if (same_smf_ind) {
337
0
    if (!cJSON_IsBool(same_smf_ind)) {
338
0
        ogs_error("OpenAPI_dnn_info_parseFromJSON() failed [same_smf_ind]");
339
0
        goto end;
340
0
    }
341
0
    }
342
343
0
    hr_sbo_allowed = cJSON_GetObjectItemCaseSensitive(dnn_infoJSON, "hrSboAllowed");
344
0
    if (hr_sbo_allowed) {
345
0
    if (!cJSON_IsBool(hr_sbo_allowed)) {
346
0
        ogs_error("OpenAPI_dnn_info_parseFromJSON() failed [hr_sbo_allowed]");
347
0
        goto end;
348
0
    }
349
0
    }
350
351
0
    additional_smf_selection_info = cJSON_GetObjectItemCaseSensitive(dnn_infoJSON, "additionalSmfSelectionInfo");
352
0
    if (additional_smf_selection_info) {
353
0
    additional_smf_selection_info_local_nonprim = OpenAPI_additional_smf_selection_info_parseFromJSON(additional_smf_selection_info);
354
0
    if (!additional_smf_selection_info_local_nonprim) {
355
0
        ogs_error("OpenAPI_additional_smf_selection_info_parseFromJSON failed [additional_smf_selection_info]");
356
0
        goto end;
357
0
    }
358
0
    }
359
360
0
    local_offloading_mngt_ind = cJSON_GetObjectItemCaseSensitive(dnn_infoJSON, "localOffloadingMngtInd");
361
0
    if (local_offloading_mngt_ind) {
362
0
    if (!cJSON_IsBool(local_offloading_mngt_ind)) {
363
0
        ogs_error("OpenAPI_dnn_info_parseFromJSON() failed [local_offloading_mngt_ind]");
364
0
        goto end;
365
0
    }
366
0
    }
367
368
0
    dnn_info_local_var = OpenAPI_dnn_info_create (
369
0
        ogs_strdup(dnn->valuestring),
370
0
        default_dnn_indicator ? true : false,
371
0
        default_dnn_indicator ? default_dnn_indicator->valueint : 0,
372
0
        lbo_roaming_allowed ? true : false,
373
0
        lbo_roaming_allowed ? lbo_roaming_allowed->valueint : 0,
374
0
        iwk_eps_ind ? true : false,
375
0
        iwk_eps_ind ? iwk_eps_ind->valueint : 0,
376
0
        dnn_barred ? true : false,
377
0
        dnn_barred ? dnn_barred->valueint : 0,
378
0
        invoke_nef_ind ? true : false,
379
0
        invoke_nef_ind ? invoke_nef_ind->valueint : 0,
380
0
        smf_list ? smf_listList : NULL,
381
0
        ipv4_index ? ipv4_index_local_nonprim : NULL,
382
0
        ipv6_index ? ipv6_index_local_nonprim : NULL,
383
0
        same_smf_ind ? true : false,
384
0
        same_smf_ind ? same_smf_ind->valueint : 0,
385
0
        hr_sbo_allowed ? true : false,
386
0
        hr_sbo_allowed ? hr_sbo_allowed->valueint : 0,
387
0
        additional_smf_selection_info ? additional_smf_selection_info_local_nonprim : NULL,
388
0
        local_offloading_mngt_ind ? true : false,
389
0
        local_offloading_mngt_ind ? local_offloading_mngt_ind->valueint : 0
390
0
    );
391
392
0
    return dnn_info_local_var;
393
0
end:
394
0
    if (smf_listList) {
395
0
        OpenAPI_list_for_each(smf_listList, node) {
396
0
            ogs_free(node->data);
397
0
        }
398
0
        OpenAPI_list_free(smf_listList);
399
0
        smf_listList = NULL;
400
0
    }
401
0
    if (ipv4_index_local_nonprim) {
402
0
        OpenAPI_ip_index_free(ipv4_index_local_nonprim);
403
0
        ipv4_index_local_nonprim = NULL;
404
0
    }
405
0
    if (ipv6_index_local_nonprim) {
406
0
        OpenAPI_ip_index_free(ipv6_index_local_nonprim);
407
0
        ipv6_index_local_nonprim = NULL;
408
0
    }
409
0
    if (additional_smf_selection_info_local_nonprim) {
410
0
        OpenAPI_additional_smf_selection_info_free(additional_smf_selection_info_local_nonprim);
411
0
        additional_smf_selection_info_local_nonprim = NULL;
412
0
    }
413
0
    return NULL;
414
0
}
415
416
OpenAPI_dnn_info_t *OpenAPI_dnn_info_copy(OpenAPI_dnn_info_t *dst, OpenAPI_dnn_info_t *src)
417
0
{
418
0
    cJSON *item = NULL;
419
0
    char *content = NULL;
420
421
0
    ogs_assert(src);
422
0
    item = OpenAPI_dnn_info_convertToJSON(src);
423
0
    if (!item) {
424
0
        ogs_error("OpenAPI_dnn_info_convertToJSON() failed");
425
0
        return NULL;
426
0
    }
427
428
0
    content = cJSON_Print(item);
429
0
    cJSON_Delete(item);
430
431
0
    if (!content) {
432
0
        ogs_error("cJSON_Print() failed");
433
0
        return NULL;
434
0
    }
435
436
0
    item = cJSON_Parse(content);
437
0
    ogs_free(content);
438
0
    if (!item) {
439
0
        ogs_error("cJSON_Parse() failed");
440
0
        return NULL;
441
0
    }
442
443
0
    OpenAPI_dnn_info_free(dst);
444
0
    dst = OpenAPI_dnn_info_parseFromJSON(item);
445
0
    cJSON_Delete(item);
446
447
0
    return dst;
448
0
}
449