Coverage Report

Created: 2026-11-06 06:15

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/open5gs/lib/sbi/openapi/model/sac_event.c
Line
Count
Source
1
2
#include <stdlib.h>
3
#include <string.h>
4
#include <stdio.h>
5
#include "sac_event.h"
6
7
OpenAPI_sac_event_t *OpenAPI_sac_event_create(
8
    OpenAPI_sac_event_type_e event_type,
9
    OpenAPI_sac_event_trigger_e event_trigger,
10
    OpenAPI_list_t *event_filter,
11
    bool is_notification_period,
12
    int notification_period,
13
    OpenAPI_sac_info_t *notif_threshold,
14
    bool is_immediate_flag,
15
    int immediate_flag,
16
    OpenAPI_list_t *var_rep_period_info,
17
    OpenAPI_plmn_id_nid_t *plmn_id_nid,
18
    OpenAPI_list_t *access_type_filter,
19
    OpenAPI_list_t *service_area_filter
20
)
21
0
{
22
0
    OpenAPI_sac_event_t *sac_event_local_var = ogs_malloc(sizeof(OpenAPI_sac_event_t));
23
0
    ogs_assert(sac_event_local_var);
24
25
0
    sac_event_local_var->event_type = event_type;
26
0
    sac_event_local_var->event_trigger = event_trigger;
27
0
    sac_event_local_var->event_filter = event_filter;
28
0
    sac_event_local_var->is_notification_period = is_notification_period;
29
0
    sac_event_local_var->notification_period = notification_period;
30
0
    sac_event_local_var->notif_threshold = notif_threshold;
31
0
    sac_event_local_var->is_immediate_flag = is_immediate_flag;
32
0
    sac_event_local_var->immediate_flag = immediate_flag;
33
0
    sac_event_local_var->var_rep_period_info = var_rep_period_info;
34
0
    sac_event_local_var->plmn_id_nid = plmn_id_nid;
35
0
    sac_event_local_var->access_type_filter = access_type_filter;
36
0
    sac_event_local_var->service_area_filter = service_area_filter;
37
38
0
    return sac_event_local_var;
39
0
}
40
41
void OpenAPI_sac_event_free(OpenAPI_sac_event_t *sac_event)
42
0
{
43
0
    OpenAPI_lnode_t *node = NULL;
44
45
0
    if (NULL == sac_event) {
46
0
        return;
47
0
    }
48
0
    if (sac_event->event_filter) {
49
0
        OpenAPI_list_for_each(sac_event->event_filter, node) {
50
0
            OpenAPI_snssai_free(node->data);
51
0
        }
52
0
        OpenAPI_list_free(sac_event->event_filter);
53
0
        sac_event->event_filter = NULL;
54
0
    }
55
0
    if (sac_event->notif_threshold) {
56
0
        OpenAPI_sac_info_free(sac_event->notif_threshold);
57
0
        sac_event->notif_threshold = NULL;
58
0
    }
59
0
    if (sac_event->var_rep_period_info) {
60
0
        OpenAPI_list_for_each(sac_event->var_rep_period_info, node) {
61
0
            OpenAPI_var_rep_period_free(node->data);
62
0
        }
63
0
        OpenAPI_list_free(sac_event->var_rep_period_info);
64
0
        sac_event->var_rep_period_info = NULL;
65
0
    }
66
0
    if (sac_event->plmn_id_nid) {
67
0
        OpenAPI_plmn_id_nid_free(sac_event->plmn_id_nid);
68
0
        sac_event->plmn_id_nid = NULL;
69
0
    }
70
0
    if (sac_event->access_type_filter) {
71
0
        OpenAPI_list_free(sac_event->access_type_filter);
72
0
        sac_event->access_type_filter = NULL;
73
0
    }
74
0
    if (sac_event->service_area_filter) {
75
0
        OpenAPI_list_for_each(sac_event->service_area_filter, node) {
76
0
            ogs_free(node->data);
77
0
        }
78
0
        OpenAPI_list_free(sac_event->service_area_filter);
79
0
        sac_event->service_area_filter = NULL;
80
0
    }
81
0
    ogs_free(sac_event);
82
0
}
83
84
cJSON *OpenAPI_sac_event_convertToJSON(OpenAPI_sac_event_t *sac_event)
85
0
{
86
0
    cJSON *item = NULL;
87
0
    OpenAPI_lnode_t *node = NULL;
88
89
0
    if (sac_event == NULL) {
90
0
        ogs_error("OpenAPI_sac_event_convertToJSON() failed [SACEvent]");
91
0
        return NULL;
92
0
    }
93
94
0
    item = cJSON_CreateObject();
95
0
    if (sac_event->event_type == OpenAPI_sac_event_type_NULL) {
96
0
        ogs_error("OpenAPI_sac_event_convertToJSON() failed [event_type]");
97
0
        return NULL;
98
0
    }
99
0
    if (cJSON_AddStringToObject(item, "eventType", OpenAPI_sac_event_type_ToString(sac_event->event_type)) == NULL) {
100
0
        ogs_error("OpenAPI_sac_event_convertToJSON() failed [event_type]");
101
0
        goto end;
102
0
    }
103
104
0
    if (sac_event->event_trigger != OpenAPI_sac_event_trigger_NULL) {
105
0
    if (cJSON_AddStringToObject(item, "eventTrigger", OpenAPI_sac_event_trigger_ToString(sac_event->event_trigger)) == NULL) {
106
0
        ogs_error("OpenAPI_sac_event_convertToJSON() failed [event_trigger]");
107
0
        goto end;
108
0
    }
109
0
    }
110
111
0
    if (!sac_event->event_filter) {
112
0
        ogs_error("OpenAPI_sac_event_convertToJSON() failed [event_filter]");
113
0
        return NULL;
114
0
    }
115
0
    cJSON *event_filterList = cJSON_AddArrayToObject(item, "eventFilter");
116
0
    if (event_filterList == NULL) {
117
0
        ogs_error("OpenAPI_sac_event_convertToJSON() failed [event_filter]");
118
0
        goto end;
119
0
    }
120
0
    OpenAPI_list_for_each(sac_event->event_filter, node) {
121
0
        cJSON *itemLocal = OpenAPI_snssai_convertToJSON(node->data);
122
0
        if (itemLocal == NULL) {
123
0
            ogs_error("OpenAPI_sac_event_convertToJSON() failed [event_filter]");
124
0
            goto end;
125
0
        }
126
0
        cJSON_AddItemToArray(event_filterList, itemLocal);
127
0
    }
128
129
0
    if (sac_event->is_notification_period) {
130
0
    if (cJSON_AddNumberToObject(item, "notificationPeriod", sac_event->notification_period) == NULL) {
131
0
        ogs_error("OpenAPI_sac_event_convertToJSON() failed [notification_period]");
132
0
        goto end;
133
0
    }
134
0
    }
135
136
0
    if (sac_event->notif_threshold) {
137
0
    cJSON *notif_threshold_local_JSON = OpenAPI_sac_info_convertToJSON(sac_event->notif_threshold);
138
0
    if (notif_threshold_local_JSON == NULL) {
139
0
        ogs_error("OpenAPI_sac_event_convertToJSON() failed [notif_threshold]");
140
0
        goto end;
141
0
    }
142
0
    cJSON_AddItemToObject(item, "notifThreshold", notif_threshold_local_JSON);
143
0
    if (item->child == NULL) {
144
0
        ogs_error("OpenAPI_sac_event_convertToJSON() failed [notif_threshold]");
145
0
        goto end;
146
0
    }
147
0
    }
148
149
0
    if (sac_event->is_immediate_flag) {
150
0
    if (cJSON_AddBoolToObject(item, "immediateFlag", sac_event->immediate_flag) == NULL) {
151
0
        ogs_error("OpenAPI_sac_event_convertToJSON() failed [immediate_flag]");
152
0
        goto end;
153
0
    }
154
0
    }
155
156
0
    if (sac_event->var_rep_period_info) {
157
0
    cJSON *var_rep_period_infoList = cJSON_AddArrayToObject(item, "varRepPeriodInfo");
158
0
    if (var_rep_period_infoList == NULL) {
159
0
        ogs_error("OpenAPI_sac_event_convertToJSON() failed [var_rep_period_info]");
160
0
        goto end;
161
0
    }
162
0
    OpenAPI_list_for_each(sac_event->var_rep_period_info, node) {
163
0
        cJSON *itemLocal = OpenAPI_var_rep_period_convertToJSON(node->data);
164
0
        if (itemLocal == NULL) {
165
0
            ogs_error("OpenAPI_sac_event_convertToJSON() failed [var_rep_period_info]");
166
0
            goto end;
167
0
        }
168
0
        cJSON_AddItemToArray(var_rep_period_infoList, itemLocal);
169
0
    }
170
0
    }
171
172
0
    if (sac_event->plmn_id_nid) {
173
0
    cJSON *plmn_id_nid_local_JSON = OpenAPI_plmn_id_nid_convertToJSON(sac_event->plmn_id_nid);
174
0
    if (plmn_id_nid_local_JSON == NULL) {
175
0
        ogs_error("OpenAPI_sac_event_convertToJSON() failed [plmn_id_nid]");
176
0
        goto end;
177
0
    }
178
0
    cJSON_AddItemToObject(item, "plmnIdNid", plmn_id_nid_local_JSON);
179
0
    if (item->child == NULL) {
180
0
        ogs_error("OpenAPI_sac_event_convertToJSON() failed [plmn_id_nid]");
181
0
        goto end;
182
0
    }
183
0
    }
184
185
0
    if (sac_event->access_type_filter != OpenAPI_access_type_NULL) {
186
0
    cJSON *access_type_filterList = cJSON_AddArrayToObject(item, "accessTypeFilter");
187
0
    if (access_type_filterList == NULL) {
188
0
        ogs_error("OpenAPI_sac_event_convertToJSON() failed [access_type_filter]");
189
0
        goto end;
190
0
    }
191
0
    OpenAPI_list_for_each(sac_event->access_type_filter, node) {
192
0
        if (cJSON_AddStringToObject(access_type_filterList, "", OpenAPI_access_type_ToString((intptr_t)node->data)) == NULL) {
193
0
            ogs_error("OpenAPI_sac_event_convertToJSON() failed [access_type_filter]");
194
0
            goto end;
195
0
        }
196
0
    }
197
0
    }
198
199
0
    if (sac_event->service_area_filter) {
200
0
    cJSON *service_area_filterList = cJSON_AddArrayToObject(item, "serviceAreaFilter");
201
0
    if (service_area_filterList == NULL) {
202
0
        ogs_error("OpenAPI_sac_event_convertToJSON() failed [service_area_filter]");
203
0
        goto end;
204
0
    }
205
0
    OpenAPI_list_for_each(sac_event->service_area_filter, node) {
206
0
        if (cJSON_AddStringToObject(service_area_filterList, "", (char*)node->data) == NULL) {
207
0
            ogs_error("OpenAPI_sac_event_convertToJSON() failed [service_area_filter]");
208
0
            goto end;
209
0
        }
210
0
    }
211
0
    }
212
213
0
end:
214
0
    return item;
215
0
}
216
217
OpenAPI_sac_event_t *OpenAPI_sac_event_parseFromJSON(cJSON *sac_eventJSON)
218
0
{
219
0
    OpenAPI_sac_event_t *sac_event_local_var = NULL;
220
0
    OpenAPI_lnode_t *node = NULL;
221
0
    cJSON *event_type = NULL;
222
0
    OpenAPI_sac_event_type_e event_typeVariable = 0;
223
0
    cJSON *event_trigger = NULL;
224
0
    OpenAPI_sac_event_trigger_e event_triggerVariable = 0;
225
0
    cJSON *event_filter = NULL;
226
0
    OpenAPI_list_t *event_filterList = NULL;
227
0
    cJSON *notification_period = NULL;
228
0
    cJSON *notif_threshold = NULL;
229
0
    OpenAPI_sac_info_t *notif_threshold_local_nonprim = NULL;
230
0
    cJSON *immediate_flag = NULL;
231
0
    cJSON *var_rep_period_info = NULL;
232
0
    OpenAPI_list_t *var_rep_period_infoList = NULL;
233
0
    cJSON *plmn_id_nid = NULL;
234
0
    OpenAPI_plmn_id_nid_t *plmn_id_nid_local_nonprim = NULL;
235
0
    cJSON *access_type_filter = NULL;
236
0
    OpenAPI_list_t *access_type_filterList = NULL;
237
0
    cJSON *service_area_filter = NULL;
238
0
    OpenAPI_list_t *service_area_filterList = NULL;
239
0
    event_type = cJSON_GetObjectItemCaseSensitive(sac_eventJSON, "eventType");
240
0
    if (!event_type) {
241
0
        ogs_error("OpenAPI_sac_event_parseFromJSON() failed [event_type]");
242
0
        goto end;
243
0
    }
244
0
    if (!cJSON_IsString(event_type)) {
245
0
        ogs_error("OpenAPI_sac_event_parseFromJSON() failed [event_type]");
246
0
        goto end;
247
0
    }
248
0
    event_typeVariable = OpenAPI_sac_event_type_FromString(event_type->valuestring);
249
250
0
    event_trigger = cJSON_GetObjectItemCaseSensitive(sac_eventJSON, "eventTrigger");
251
0
    if (event_trigger) {
252
0
    if (!cJSON_IsString(event_trigger)) {
253
0
        ogs_error("OpenAPI_sac_event_parseFromJSON() failed [event_trigger]");
254
0
        goto end;
255
0
    }
256
0
    event_triggerVariable = OpenAPI_sac_event_trigger_FromString(event_trigger->valuestring);
257
0
    }
258
259
0
    event_filter = cJSON_GetObjectItemCaseSensitive(sac_eventJSON, "eventFilter");
260
0
    if (!event_filter) {
261
0
        ogs_error("OpenAPI_sac_event_parseFromJSON() failed [event_filter]");
262
0
        goto end;
263
0
    }
264
0
        cJSON *event_filter_local = NULL;
265
0
        if (!cJSON_IsArray(event_filter)) {
266
0
            ogs_error("OpenAPI_sac_event_parseFromJSON() failed [event_filter]");
267
0
            goto end;
268
0
        }
269
270
0
        event_filterList = OpenAPI_list_create();
271
272
0
        cJSON_ArrayForEach(event_filter_local, event_filter) {
273
0
            if (!cJSON_IsObject(event_filter_local)) {
274
0
                ogs_error("OpenAPI_sac_event_parseFromJSON() failed [event_filter]");
275
0
                goto end;
276
0
            }
277
0
            OpenAPI_snssai_t *event_filterItem = OpenAPI_snssai_parseFromJSON(event_filter_local);
278
0
            if (!event_filterItem) {
279
0
                ogs_error("No event_filterItem");
280
0
                goto end;
281
0
            }
282
0
            OpenAPI_list_add(event_filterList, event_filterItem);
283
0
        }
284
285
0
    notification_period = cJSON_GetObjectItemCaseSensitive(sac_eventJSON, "notificationPeriod");
286
0
    if (notification_period) {
287
0
    if (!cJSON_IsNumber(notification_period)) {
288
0
        ogs_error("OpenAPI_sac_event_parseFromJSON() failed [notification_period]");
289
0
        goto end;
290
0
    }
291
0
    }
292
293
0
    notif_threshold = cJSON_GetObjectItemCaseSensitive(sac_eventJSON, "notifThreshold");
294
0
    if (notif_threshold) {
295
0
    notif_threshold_local_nonprim = OpenAPI_sac_info_parseFromJSON(notif_threshold);
296
0
    if (!notif_threshold_local_nonprim) {
297
0
        ogs_error("OpenAPI_sac_info_parseFromJSON failed [notif_threshold]");
298
0
        goto end;
299
0
    }
300
0
    }
301
302
0
    immediate_flag = cJSON_GetObjectItemCaseSensitive(sac_eventJSON, "immediateFlag");
303
0
    if (immediate_flag) {
304
0
    if (!cJSON_IsBool(immediate_flag)) {
305
0
        ogs_error("OpenAPI_sac_event_parseFromJSON() failed [immediate_flag]");
306
0
        goto end;
307
0
    }
308
0
    }
309
310
0
    var_rep_period_info = cJSON_GetObjectItemCaseSensitive(sac_eventJSON, "varRepPeriodInfo");
311
0
    if (var_rep_period_info) {
312
0
        cJSON *var_rep_period_info_local = NULL;
313
0
        if (!cJSON_IsArray(var_rep_period_info)) {
314
0
            ogs_error("OpenAPI_sac_event_parseFromJSON() failed [var_rep_period_info]");
315
0
            goto end;
316
0
        }
317
318
0
        var_rep_period_infoList = OpenAPI_list_create();
319
320
0
        cJSON_ArrayForEach(var_rep_period_info_local, var_rep_period_info) {
321
0
            if (!cJSON_IsObject(var_rep_period_info_local)) {
322
0
                ogs_error("OpenAPI_sac_event_parseFromJSON() failed [var_rep_period_info]");
323
0
                goto end;
324
0
            }
325
0
            OpenAPI_var_rep_period_t *var_rep_period_infoItem = OpenAPI_var_rep_period_parseFromJSON(var_rep_period_info_local);
326
0
            if (!var_rep_period_infoItem) {
327
0
                ogs_error("No var_rep_period_infoItem");
328
0
                goto end;
329
0
            }
330
0
            OpenAPI_list_add(var_rep_period_infoList, var_rep_period_infoItem);
331
0
        }
332
0
    }
333
334
0
    plmn_id_nid = cJSON_GetObjectItemCaseSensitive(sac_eventJSON, "plmnIdNid");
335
0
    if (plmn_id_nid) {
336
0
    plmn_id_nid_local_nonprim = OpenAPI_plmn_id_nid_parseFromJSON(plmn_id_nid);
337
0
    if (!plmn_id_nid_local_nonprim) {
338
0
        ogs_error("OpenAPI_plmn_id_nid_parseFromJSON failed [plmn_id_nid]");
339
0
        goto end;
340
0
    }
341
0
    }
342
343
0
    access_type_filter = cJSON_GetObjectItemCaseSensitive(sac_eventJSON, "accessTypeFilter");
344
0
    if (access_type_filter) {
345
0
        cJSON *access_type_filter_local = NULL;
346
0
        if (!cJSON_IsArray(access_type_filter)) {
347
0
            ogs_error("OpenAPI_sac_event_parseFromJSON() failed [access_type_filter]");
348
0
            goto end;
349
0
        }
350
351
0
        access_type_filterList = OpenAPI_list_create();
352
353
0
        cJSON_ArrayForEach(access_type_filter_local, access_type_filter) {
354
0
            OpenAPI_access_type_e localEnum = OpenAPI_access_type_NULL;
355
0
            if (!cJSON_IsString(access_type_filter_local)) {
356
0
                ogs_error("OpenAPI_sac_event_parseFromJSON() failed [access_type_filter]");
357
0
                goto end;
358
0
            }
359
0
            localEnum = OpenAPI_access_type_FromString(access_type_filter_local->valuestring);
360
0
            if (!localEnum) {
361
0
                ogs_info("Enum value \"%s\" for field \"access_type_filter\" is not supported. Ignoring it ...",
362
0
                         access_type_filter_local->valuestring);
363
0
            } else {
364
0
                OpenAPI_list_add(access_type_filterList, (void *)localEnum);
365
0
            }
366
0
        }
367
0
        if (access_type_filterList->count == 0) {
368
0
            ogs_error("OpenAPI_sac_event_parseFromJSON() failed: Expected access_type_filterList to not be empty (after ignoring unsupported enum values).");
369
0
            goto end;
370
0
        }
371
0
    }
372
373
0
    service_area_filter = cJSON_GetObjectItemCaseSensitive(sac_eventJSON, "serviceAreaFilter");
374
0
    if (service_area_filter) {
375
0
        cJSON *service_area_filter_local = NULL;
376
0
        if (!cJSON_IsArray(service_area_filter)) {
377
0
            ogs_error("OpenAPI_sac_event_parseFromJSON() failed [service_area_filter]");
378
0
            goto end;
379
0
        }
380
381
0
        service_area_filterList = OpenAPI_list_create();
382
383
0
        cJSON_ArrayForEach(service_area_filter_local, service_area_filter) {
384
0
            double *localDouble = NULL;
385
0
            int *localInt = NULL;
386
0
            if (!cJSON_IsString(service_area_filter_local)) {
387
0
                ogs_error("OpenAPI_sac_event_parseFromJSON() failed [service_area_filter]");
388
0
                goto end;
389
0
            }
390
0
            OpenAPI_list_add(service_area_filterList, ogs_strdup(service_area_filter_local->valuestring));
391
0
        }
392
0
    }
393
394
0
    sac_event_local_var = OpenAPI_sac_event_create (
395
0
        event_typeVariable,
396
0
        event_trigger ? event_triggerVariable : 0,
397
0
        event_filterList,
398
0
        notification_period ? true : false,
399
0
        notification_period ? notification_period->valuedouble : 0,
400
0
        notif_threshold ? notif_threshold_local_nonprim : NULL,
401
0
        immediate_flag ? true : false,
402
0
        immediate_flag ? immediate_flag->valueint : 0,
403
0
        var_rep_period_info ? var_rep_period_infoList : NULL,
404
0
        plmn_id_nid ? plmn_id_nid_local_nonprim : NULL,
405
0
        access_type_filter ? access_type_filterList : NULL,
406
0
        service_area_filter ? service_area_filterList : NULL
407
0
    );
408
409
0
    return sac_event_local_var;
410
0
end:
411
0
    if (event_filterList) {
412
0
        OpenAPI_list_for_each(event_filterList, node) {
413
0
            OpenAPI_snssai_free(node->data);
414
0
        }
415
0
        OpenAPI_list_free(event_filterList);
416
0
        event_filterList = NULL;
417
0
    }
418
0
    if (notif_threshold_local_nonprim) {
419
0
        OpenAPI_sac_info_free(notif_threshold_local_nonprim);
420
0
        notif_threshold_local_nonprim = NULL;
421
0
    }
422
0
    if (var_rep_period_infoList) {
423
0
        OpenAPI_list_for_each(var_rep_period_infoList, node) {
424
0
            OpenAPI_var_rep_period_free(node->data);
425
0
        }
426
0
        OpenAPI_list_free(var_rep_period_infoList);
427
0
        var_rep_period_infoList = NULL;
428
0
    }
429
0
    if (plmn_id_nid_local_nonprim) {
430
0
        OpenAPI_plmn_id_nid_free(plmn_id_nid_local_nonprim);
431
0
        plmn_id_nid_local_nonprim = NULL;
432
0
    }
433
0
    if (access_type_filterList) {
434
0
        OpenAPI_list_free(access_type_filterList);
435
0
        access_type_filterList = NULL;
436
0
    }
437
0
    if (service_area_filterList) {
438
0
        OpenAPI_list_for_each(service_area_filterList, node) {
439
0
            ogs_free(node->data);
440
0
        }
441
0
        OpenAPI_list_free(service_area_filterList);
442
0
        service_area_filterList = NULL;
443
0
    }
444
0
    return NULL;
445
0
}
446
447
OpenAPI_sac_event_t *OpenAPI_sac_event_copy(OpenAPI_sac_event_t *dst, OpenAPI_sac_event_t *src)
448
0
{
449
0
    cJSON *item = NULL;
450
0
    char *content = NULL;
451
452
0
    ogs_assert(src);
453
0
    item = OpenAPI_sac_event_convertToJSON(src);
454
0
    if (!item) {
455
0
        ogs_error("OpenAPI_sac_event_convertToJSON() failed");
456
0
        return NULL;
457
0
    }
458
459
0
    content = cJSON_Print(item);
460
0
    cJSON_Delete(item);
461
462
0
    if (!content) {
463
0
        ogs_error("cJSON_Print() failed");
464
0
        return NULL;
465
0
    }
466
467
0
    item = cJSON_Parse(content);
468
0
    ogs_free(content);
469
0
    if (!item) {
470
0
        ogs_error("cJSON_Parse() failed");
471
0
        return NULL;
472
0
    }
473
474
0
    OpenAPI_sac_event_free(dst);
475
0
    dst = OpenAPI_sac_event_parseFromJSON(item);
476
0
    cJSON_Delete(item);
477
478
0
    return dst;
479
0
}
480