Coverage Report

Created: 2026-07-14 06:05

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/open5gs/lib/sbi/openapi/model/aiotf_info.c
Line
Count
Source
1
2
#include <stdlib.h>
3
#include <string.h>
4
#include <stdio.h>
5
#include "aiotf_info.h"
6
7
OpenAPI_aiotf_info_t *OpenAPI_aiotf_info_create(
8
    OpenAPI_list_t *aiot_area_id_list
9
)
10
528
{
11
528
    OpenAPI_aiotf_info_t *aiotf_info_local_var = ogs_malloc(sizeof(OpenAPI_aiotf_info_t));
12
528
    ogs_assert(aiotf_info_local_var);
13
14
528
    aiotf_info_local_var->aiot_area_id_list = aiot_area_id_list;
15
16
528
    return aiotf_info_local_var;
17
528
}
18
19
void OpenAPI_aiotf_info_free(OpenAPI_aiotf_info_t *aiotf_info)
20
1.22k
{
21
1.22k
    OpenAPI_lnode_t *node = NULL;
22
23
1.22k
    if (NULL == aiotf_info) {
24
697
        return;
25
697
    }
26
528
    if (aiotf_info->aiot_area_id_list) {
27
72
        OpenAPI_list_for_each(aiotf_info->aiot_area_id_list, node) {
28
0
            OpenAPI_aiot_area_id_free(node->data);
29
0
        }
30
72
        OpenAPI_list_free(aiotf_info->aiot_area_id_list);
31
72
        aiotf_info->aiot_area_id_list = NULL;
32
72
    }
33
528
    ogs_free(aiotf_info);
34
528
}
35
36
cJSON *OpenAPI_aiotf_info_convertToJSON(OpenAPI_aiotf_info_t *aiotf_info)
37
0
{
38
0
    cJSON *item = NULL;
39
0
    OpenAPI_lnode_t *node = NULL;
40
41
0
    if (aiotf_info == NULL) {
42
0
        ogs_error("OpenAPI_aiotf_info_convertToJSON() failed [AiotfInfo]");
43
0
        return NULL;
44
0
    }
45
46
0
    item = cJSON_CreateObject();
47
0
    if (aiotf_info->aiot_area_id_list) {
48
0
    cJSON *aiot_area_id_listList = cJSON_AddArrayToObject(item, "aiotAreaIDList");
49
0
    if (aiot_area_id_listList == NULL) {
50
0
        ogs_error("OpenAPI_aiotf_info_convertToJSON() failed [aiot_area_id_list]");
51
0
        goto end;
52
0
    }
53
0
    OpenAPI_list_for_each(aiotf_info->aiot_area_id_list, node) {
54
0
        cJSON *itemLocal = OpenAPI_aiot_area_id_convertToJSON(node->data);
55
0
        if (itemLocal == NULL) {
56
0
            ogs_error("OpenAPI_aiotf_info_convertToJSON() failed [aiot_area_id_list]");
57
0
            goto end;
58
0
        }
59
0
        cJSON_AddItemToArray(aiot_area_id_listList, itemLocal);
60
0
    }
61
0
    }
62
63
0
end:
64
0
    return item;
65
0
}
66
67
OpenAPI_aiotf_info_t *OpenAPI_aiotf_info_parseFromJSON(cJSON *aiotf_infoJSON)
68
800
{
69
800
    OpenAPI_aiotf_info_t *aiotf_info_local_var = NULL;
70
800
    OpenAPI_lnode_t *node = NULL;
71
800
    cJSON *aiot_area_id_list = NULL;
72
800
    OpenAPI_list_t *aiot_area_id_listList = NULL;
73
800
    aiot_area_id_list = cJSON_GetObjectItemCaseSensitive(aiotf_infoJSON, "aiotAreaIDList");
74
800
    if (aiot_area_id_list) {
75
344
        cJSON *aiot_area_id_list_local = NULL;
76
344
        if (!cJSON_IsArray(aiot_area_id_list)) {
77
73
            ogs_error("OpenAPI_aiotf_info_parseFromJSON() failed [aiot_area_id_list]");
78
73
            goto end;
79
73
        }
80
81
271
        aiot_area_id_listList = OpenAPI_list_create();
82
83
271
        cJSON_ArrayForEach(aiot_area_id_list_local, aiot_area_id_list) {
84
199
            if (!cJSON_IsObject(aiot_area_id_list_local)) {
85
130
                ogs_error("OpenAPI_aiotf_info_parseFromJSON() failed [aiot_area_id_list]");
86
130
                goto end;
87
130
            }
88
69
            OpenAPI_aiot_area_id_t *aiot_area_id_listItem = OpenAPI_aiot_area_id_parseFromJSON(aiot_area_id_list_local);
89
69
            if (!aiot_area_id_listItem) {
90
69
                ogs_error("No aiot_area_id_listItem");
91
69
                goto end;
92
69
            }
93
0
            OpenAPI_list_add(aiot_area_id_listList, aiot_area_id_listItem);
94
0
        }
95
271
    }
96
97
528
    aiotf_info_local_var = OpenAPI_aiotf_info_create (
98
528
        aiot_area_id_list ? aiot_area_id_listList : NULL
99
528
    );
100
101
528
    return aiotf_info_local_var;
102
272
end:
103
272
    if (aiot_area_id_listList) {
104
199
        OpenAPI_list_for_each(aiot_area_id_listList, node) {
105
0
            OpenAPI_aiot_area_id_free(node->data);
106
0
        }
107
199
        OpenAPI_list_free(aiot_area_id_listList);
108
199
        aiot_area_id_listList = NULL;
109
199
    }
110
272
    return NULL;
111
800
}
112
113
OpenAPI_aiotf_info_t *OpenAPI_aiotf_info_copy(OpenAPI_aiotf_info_t *dst, OpenAPI_aiotf_info_t *src)
114
0
{
115
0
    cJSON *item = NULL;
116
0
    char *content = NULL;
117
118
0
    ogs_assert(src);
119
0
    item = OpenAPI_aiotf_info_convertToJSON(src);
120
0
    if (!item) {
121
0
        ogs_error("OpenAPI_aiotf_info_convertToJSON() failed");
122
0
        return NULL;
123
0
    }
124
125
0
    content = cJSON_Print(item);
126
0
    cJSON_Delete(item);
127
128
0
    if (!content) {
129
0
        ogs_error("cJSON_Print() failed");
130
0
        return NULL;
131
0
    }
132
133
0
    item = cJSON_Parse(content);
134
0
    ogs_free(content);
135
0
    if (!item) {
136
0
        ogs_error("cJSON_Parse() failed");
137
0
        return NULL;
138
0
    }
139
140
0
    OpenAPI_aiotf_info_free(dst);
141
0
    dst = OpenAPI_aiotf_info_parseFromJSON(item);
142
0
    cJSON_Delete(item);
143
144
0
    return dst;
145
0
}
146