Coverage Report

Created: 2026-09-28 06:22

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/open5gs/lib/sbi/openapi/model/plmn_oauth2.c
Line
Count
Source
1
2
#include <stdlib.h>
3
#include <string.h>
4
#include <stdio.h>
5
#include "plmn_oauth2.h"
6
7
OpenAPI_plmn_oauth2_t *OpenAPI_plmn_oauth2_create(
8
    OpenAPI_list_t *oauth2_required_plmn_id_list,
9
    OpenAPI_list_t *oauth2_not_required_plmn_id_list
10
)
11
67
{
12
67
    OpenAPI_plmn_oauth2_t *plmn_oauth2_local_var = ogs_malloc(sizeof(OpenAPI_plmn_oauth2_t));
13
67
    ogs_assert(plmn_oauth2_local_var);
14
15
67
    plmn_oauth2_local_var->oauth2_required_plmn_id_list = oauth2_required_plmn_id_list;
16
67
    plmn_oauth2_local_var->oauth2_not_required_plmn_id_list = oauth2_not_required_plmn_id_list;
17
18
67
    return plmn_oauth2_local_var;
19
67
}
20
21
void OpenAPI_plmn_oauth2_free(OpenAPI_plmn_oauth2_t *plmn_oauth2)
22
67
{
23
67
    OpenAPI_lnode_t *node = NULL;
24
25
67
    if (NULL == plmn_oauth2) {
26
0
        return;
27
0
    }
28
67
    if (plmn_oauth2->oauth2_required_plmn_id_list) {
29
0
        OpenAPI_list_for_each(plmn_oauth2->oauth2_required_plmn_id_list, node) {
30
0
            OpenAPI_plmn_id_free(node->data);
31
0
        }
32
0
        OpenAPI_list_free(plmn_oauth2->oauth2_required_plmn_id_list);
33
0
        plmn_oauth2->oauth2_required_plmn_id_list = NULL;
34
0
    }
35
67
    if (plmn_oauth2->oauth2_not_required_plmn_id_list) {
36
0
        OpenAPI_list_for_each(plmn_oauth2->oauth2_not_required_plmn_id_list, node) {
37
0
            OpenAPI_plmn_id_free(node->data);
38
0
        }
39
0
        OpenAPI_list_free(plmn_oauth2->oauth2_not_required_plmn_id_list);
40
0
        plmn_oauth2->oauth2_not_required_plmn_id_list = NULL;
41
0
    }
42
67
    ogs_free(plmn_oauth2);
43
67
}
44
45
cJSON *OpenAPI_plmn_oauth2_convertToJSON(OpenAPI_plmn_oauth2_t *plmn_oauth2)
46
0
{
47
0
    cJSON *item = NULL;
48
0
    OpenAPI_lnode_t *node = NULL;
49
50
0
    if (plmn_oauth2 == NULL) {
51
0
        ogs_error("OpenAPI_plmn_oauth2_convertToJSON() failed [PlmnOauth2]");
52
0
        return NULL;
53
0
    }
54
55
0
    item = cJSON_CreateObject();
56
0
    if (plmn_oauth2->oauth2_required_plmn_id_list) {
57
0
    cJSON *oauth2_required_plmn_id_listList = cJSON_AddArrayToObject(item, "oauth2RequiredPlmnIdList");
58
0
    if (oauth2_required_plmn_id_listList == NULL) {
59
0
        ogs_error("OpenAPI_plmn_oauth2_convertToJSON() failed [oauth2_required_plmn_id_list]");
60
0
        goto end;
61
0
    }
62
0
    OpenAPI_list_for_each(plmn_oauth2->oauth2_required_plmn_id_list, node) {
63
0
        cJSON *itemLocal = OpenAPI_plmn_id_convertToJSON(node->data);
64
0
        if (itemLocal == NULL) {
65
0
            ogs_error("OpenAPI_plmn_oauth2_convertToJSON() failed [oauth2_required_plmn_id_list]");
66
0
            goto end;
67
0
        }
68
0
        cJSON_AddItemToArray(oauth2_required_plmn_id_listList, itemLocal);
69
0
    }
70
0
    }
71
72
0
    if (plmn_oauth2->oauth2_not_required_plmn_id_list) {
73
0
    cJSON *oauth2_not_required_plmn_id_listList = cJSON_AddArrayToObject(item, "oauth2NotRequiredPlmnIdList");
74
0
    if (oauth2_not_required_plmn_id_listList == NULL) {
75
0
        ogs_error("OpenAPI_plmn_oauth2_convertToJSON() failed [oauth2_not_required_plmn_id_list]");
76
0
        goto end;
77
0
    }
78
0
    OpenAPI_list_for_each(plmn_oauth2->oauth2_not_required_plmn_id_list, node) {
79
0
        cJSON *itemLocal = OpenAPI_plmn_id_convertToJSON(node->data);
80
0
        if (itemLocal == NULL) {
81
0
            ogs_error("OpenAPI_plmn_oauth2_convertToJSON() failed [oauth2_not_required_plmn_id_list]");
82
0
            goto end;
83
0
        }
84
0
        cJSON_AddItemToArray(oauth2_not_required_plmn_id_listList, itemLocal);
85
0
    }
86
0
    }
87
88
0
end:
89
0
    return item;
90
0
}
91
92
OpenAPI_plmn_oauth2_t *OpenAPI_plmn_oauth2_parseFromJSON(cJSON *plmn_oauth2JSON)
93
67
{
94
67
    OpenAPI_plmn_oauth2_t *plmn_oauth2_local_var = NULL;
95
67
    OpenAPI_lnode_t *node = NULL;
96
67
    cJSON *oauth2_required_plmn_id_list = NULL;
97
67
    OpenAPI_list_t *oauth2_required_plmn_id_listList = NULL;
98
67
    cJSON *oauth2_not_required_plmn_id_list = NULL;
99
67
    OpenAPI_list_t *oauth2_not_required_plmn_id_listList = NULL;
100
67
    oauth2_required_plmn_id_list = cJSON_GetObjectItemCaseSensitive(plmn_oauth2JSON, "oauth2RequiredPlmnIdList");
101
67
    if (oauth2_required_plmn_id_list) {
102
0
        cJSON *oauth2_required_plmn_id_list_local = NULL;
103
0
        if (!cJSON_IsArray(oauth2_required_plmn_id_list)) {
104
0
            ogs_error("OpenAPI_plmn_oauth2_parseFromJSON() failed [oauth2_required_plmn_id_list]");
105
0
            goto end;
106
0
        }
107
108
0
        oauth2_required_plmn_id_listList = OpenAPI_list_create();
109
110
0
        cJSON_ArrayForEach(oauth2_required_plmn_id_list_local, oauth2_required_plmn_id_list) {
111
0
            if (!cJSON_IsObject(oauth2_required_plmn_id_list_local)) {
112
0
                ogs_error("OpenAPI_plmn_oauth2_parseFromJSON() failed [oauth2_required_plmn_id_list]");
113
0
                goto end;
114
0
            }
115
0
            OpenAPI_plmn_id_t *oauth2_required_plmn_id_listItem = OpenAPI_plmn_id_parseFromJSON(oauth2_required_plmn_id_list_local);
116
0
            if (!oauth2_required_plmn_id_listItem) {
117
0
                ogs_error("No oauth2_required_plmn_id_listItem");
118
0
                goto end;
119
0
            }
120
0
            OpenAPI_list_add(oauth2_required_plmn_id_listList, oauth2_required_plmn_id_listItem);
121
0
        }
122
0
    }
123
124
67
    oauth2_not_required_plmn_id_list = cJSON_GetObjectItemCaseSensitive(plmn_oauth2JSON, "oauth2NotRequiredPlmnIdList");
125
67
    if (oauth2_not_required_plmn_id_list) {
126
0
        cJSON *oauth2_not_required_plmn_id_list_local = NULL;
127
0
        if (!cJSON_IsArray(oauth2_not_required_plmn_id_list)) {
128
0
            ogs_error("OpenAPI_plmn_oauth2_parseFromJSON() failed [oauth2_not_required_plmn_id_list]");
129
0
            goto end;
130
0
        }
131
132
0
        oauth2_not_required_plmn_id_listList = OpenAPI_list_create();
133
134
0
        cJSON_ArrayForEach(oauth2_not_required_plmn_id_list_local, oauth2_not_required_plmn_id_list) {
135
0
            if (!cJSON_IsObject(oauth2_not_required_plmn_id_list_local)) {
136
0
                ogs_error("OpenAPI_plmn_oauth2_parseFromJSON() failed [oauth2_not_required_plmn_id_list]");
137
0
                goto end;
138
0
            }
139
0
            OpenAPI_plmn_id_t *oauth2_not_required_plmn_id_listItem = OpenAPI_plmn_id_parseFromJSON(oauth2_not_required_plmn_id_list_local);
140
0
            if (!oauth2_not_required_plmn_id_listItem) {
141
0
                ogs_error("No oauth2_not_required_plmn_id_listItem");
142
0
                goto end;
143
0
            }
144
0
            OpenAPI_list_add(oauth2_not_required_plmn_id_listList, oauth2_not_required_plmn_id_listItem);
145
0
        }
146
0
    }
147
148
67
    plmn_oauth2_local_var = OpenAPI_plmn_oauth2_create (
149
67
        oauth2_required_plmn_id_list ? oauth2_required_plmn_id_listList : NULL,
150
67
        oauth2_not_required_plmn_id_list ? oauth2_not_required_plmn_id_listList : NULL
151
67
    );
152
153
67
    return plmn_oauth2_local_var;
154
0
end:
155
0
    if (oauth2_required_plmn_id_listList) {
156
0
        OpenAPI_list_for_each(oauth2_required_plmn_id_listList, node) {
157
0
            OpenAPI_plmn_id_free(node->data);
158
0
        }
159
0
        OpenAPI_list_free(oauth2_required_plmn_id_listList);
160
0
        oauth2_required_plmn_id_listList = NULL;
161
0
    }
162
0
    if (oauth2_not_required_plmn_id_listList) {
163
0
        OpenAPI_list_for_each(oauth2_not_required_plmn_id_listList, node) {
164
0
            OpenAPI_plmn_id_free(node->data);
165
0
        }
166
0
        OpenAPI_list_free(oauth2_not_required_plmn_id_listList);
167
0
        oauth2_not_required_plmn_id_listList = NULL;
168
0
    }
169
0
    return NULL;
170
67
}
171
172
OpenAPI_plmn_oauth2_t *OpenAPI_plmn_oauth2_copy(OpenAPI_plmn_oauth2_t *dst, OpenAPI_plmn_oauth2_t *src)
173
0
{
174
0
    cJSON *item = NULL;
175
0
    char *content = NULL;
176
177
0
    ogs_assert(src);
178
0
    item = OpenAPI_plmn_oauth2_convertToJSON(src);
179
0
    if (!item) {
180
0
        ogs_error("OpenAPI_plmn_oauth2_convertToJSON() failed");
181
0
        return NULL;
182
0
    }
183
184
0
    content = cJSON_Print(item);
185
0
    cJSON_Delete(item);
186
187
0
    if (!content) {
188
0
        ogs_error("cJSON_Print() failed");
189
0
        return NULL;
190
0
    }
191
192
0
    item = cJSON_Parse(content);
193
0
    ogs_free(content);
194
0
    if (!item) {
195
0
        ogs_error("cJSON_Parse() failed");
196
0
        return NULL;
197
0
    }
198
199
0
    OpenAPI_plmn_oauth2_free(dst);
200
0
    dst = OpenAPI_plmn_oauth2_parseFromJSON(item);
201
0
    cJSON_Delete(item);
202
203
0
    return dst;
204
0
}
205