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/chf_info.c
Line
Count
Source
1
2
#include <stdlib.h>
3
#include <string.h>
4
#include <stdio.h>
5
#include "chf_info.h"
6
7
OpenAPI_chf_info_t *OpenAPI_chf_info_create(
8
    OpenAPI_list_t *supi_range_list,
9
    OpenAPI_list_t *gpsi_range_list,
10
    OpenAPI_list_t *plmn_range_list,
11
    char *group_id,
12
    char *primary_chf_instance,
13
    char *secondary_chf_instance
14
)
15
1.94k
{
16
1.94k
    OpenAPI_chf_info_t *chf_info_local_var = ogs_malloc(sizeof(OpenAPI_chf_info_t));
17
1.94k
    ogs_assert(chf_info_local_var);
18
19
1.94k
    chf_info_local_var->supi_range_list = supi_range_list;
20
1.94k
    chf_info_local_var->gpsi_range_list = gpsi_range_list;
21
1.94k
    chf_info_local_var->plmn_range_list = plmn_range_list;
22
1.94k
    chf_info_local_var->group_id = group_id;
23
1.94k
    chf_info_local_var->primary_chf_instance = primary_chf_instance;
24
1.94k
    chf_info_local_var->secondary_chf_instance = secondary_chf_instance;
25
26
1.94k
    return chf_info_local_var;
27
1.94k
}
28
29
void OpenAPI_chf_info_free(OpenAPI_chf_info_t *chf_info)
30
2.94k
{
31
2.94k
    OpenAPI_lnode_t *node = NULL;
32
33
2.94k
    if (NULL == chf_info) {
34
1.00k
        return;
35
1.00k
    }
36
1.94k
    if (chf_info->supi_range_list) {
37
0
        OpenAPI_list_for_each(chf_info->supi_range_list, node) {
38
0
            OpenAPI_supi_range_free(node->data);
39
0
        }
40
0
        OpenAPI_list_free(chf_info->supi_range_list);
41
0
        chf_info->supi_range_list = NULL;
42
0
    }
43
1.94k
    if (chf_info->gpsi_range_list) {
44
0
        OpenAPI_list_for_each(chf_info->gpsi_range_list, node) {
45
0
            OpenAPI_identity_range_free(node->data);
46
0
        }
47
0
        OpenAPI_list_free(chf_info->gpsi_range_list);
48
0
        chf_info->gpsi_range_list = NULL;
49
0
    }
50
1.94k
    if (chf_info->plmn_range_list) {
51
0
        OpenAPI_list_for_each(chf_info->plmn_range_list, node) {
52
0
            OpenAPI_plmn_range_free(node->data);
53
0
        }
54
0
        OpenAPI_list_free(chf_info->plmn_range_list);
55
0
        chf_info->plmn_range_list = NULL;
56
0
    }
57
1.94k
    if (chf_info->group_id) {
58
465
        ogs_free(chf_info->group_id);
59
465
        chf_info->group_id = NULL;
60
465
    }
61
1.94k
    if (chf_info->primary_chf_instance) {
62
70
        ogs_free(chf_info->primary_chf_instance);
63
70
        chf_info->primary_chf_instance = NULL;
64
70
    }
65
1.94k
    if (chf_info->secondary_chf_instance) {
66
75
        ogs_free(chf_info->secondary_chf_instance);
67
75
        chf_info->secondary_chf_instance = NULL;
68
75
    }
69
1.94k
    ogs_free(chf_info);
70
1.94k
}
71
72
cJSON *OpenAPI_chf_info_convertToJSON(OpenAPI_chf_info_t *chf_info)
73
0
{
74
0
    cJSON *item = NULL;
75
0
    OpenAPI_lnode_t *node = NULL;
76
77
0
    if (chf_info == NULL) {
78
0
        ogs_error("OpenAPI_chf_info_convertToJSON() failed [ChfInfo]");
79
0
        return NULL;
80
0
    }
81
82
0
    item = cJSON_CreateObject();
83
0
    if (chf_info->supi_range_list) {
84
0
    cJSON *supi_range_listList = cJSON_AddArrayToObject(item, "supiRangeList");
85
0
    if (supi_range_listList == NULL) {
86
0
        ogs_error("OpenAPI_chf_info_convertToJSON() failed [supi_range_list]");
87
0
        goto end;
88
0
    }
89
0
    OpenAPI_list_for_each(chf_info->supi_range_list, node) {
90
0
        cJSON *itemLocal = OpenAPI_supi_range_convertToJSON(node->data);
91
0
        if (itemLocal == NULL) {
92
0
            ogs_error("OpenAPI_chf_info_convertToJSON() failed [supi_range_list]");
93
0
            goto end;
94
0
        }
95
0
        cJSON_AddItemToArray(supi_range_listList, itemLocal);
96
0
    }
97
0
    }
98
99
0
    if (chf_info->gpsi_range_list) {
100
0
    cJSON *gpsi_range_listList = cJSON_AddArrayToObject(item, "gpsiRangeList");
101
0
    if (gpsi_range_listList == NULL) {
102
0
        ogs_error("OpenAPI_chf_info_convertToJSON() failed [gpsi_range_list]");
103
0
        goto end;
104
0
    }
105
0
    OpenAPI_list_for_each(chf_info->gpsi_range_list, node) {
106
0
        cJSON *itemLocal = OpenAPI_identity_range_convertToJSON(node->data);
107
0
        if (itemLocal == NULL) {
108
0
            ogs_error("OpenAPI_chf_info_convertToJSON() failed [gpsi_range_list]");
109
0
            goto end;
110
0
        }
111
0
        cJSON_AddItemToArray(gpsi_range_listList, itemLocal);
112
0
    }
113
0
    }
114
115
0
    if (chf_info->plmn_range_list) {
116
0
    cJSON *plmn_range_listList = cJSON_AddArrayToObject(item, "plmnRangeList");
117
0
    if (plmn_range_listList == NULL) {
118
0
        ogs_error("OpenAPI_chf_info_convertToJSON() failed [plmn_range_list]");
119
0
        goto end;
120
0
    }
121
0
    OpenAPI_list_for_each(chf_info->plmn_range_list, node) {
122
0
        cJSON *itemLocal = OpenAPI_plmn_range_convertToJSON(node->data);
123
0
        if (itemLocal == NULL) {
124
0
            ogs_error("OpenAPI_chf_info_convertToJSON() failed [plmn_range_list]");
125
0
            goto end;
126
0
        }
127
0
        cJSON_AddItemToArray(plmn_range_listList, itemLocal);
128
0
    }
129
0
    }
130
131
0
    if (chf_info->group_id) {
132
0
    if (cJSON_AddStringToObject(item, "groupId", chf_info->group_id) == NULL) {
133
0
        ogs_error("OpenAPI_chf_info_convertToJSON() failed [group_id]");
134
0
        goto end;
135
0
    }
136
0
    }
137
138
0
    if (chf_info->primary_chf_instance) {
139
0
    if (cJSON_AddStringToObject(item, "primaryChfInstance", chf_info->primary_chf_instance) == NULL) {
140
0
        ogs_error("OpenAPI_chf_info_convertToJSON() failed [primary_chf_instance]");
141
0
        goto end;
142
0
    }
143
0
    }
144
145
0
    if (chf_info->secondary_chf_instance) {
146
0
    if (cJSON_AddStringToObject(item, "secondaryChfInstance", chf_info->secondary_chf_instance) == NULL) {
147
0
        ogs_error("OpenAPI_chf_info_convertToJSON() failed [secondary_chf_instance]");
148
0
        goto end;
149
0
    }
150
0
    }
151
152
0
end:
153
0
    return item;
154
0
}
155
156
OpenAPI_chf_info_t *OpenAPI_chf_info_parseFromJSON(cJSON *chf_infoJSON)
157
2.67k
{
158
2.67k
    OpenAPI_chf_info_t *chf_info_local_var = NULL;
159
2.67k
    OpenAPI_lnode_t *node = NULL;
160
2.67k
    cJSON *supi_range_list = NULL;
161
2.67k
    OpenAPI_list_t *supi_range_listList = NULL;
162
2.67k
    cJSON *gpsi_range_list = NULL;
163
2.67k
    OpenAPI_list_t *gpsi_range_listList = NULL;
164
2.67k
    cJSON *plmn_range_list = NULL;
165
2.67k
    OpenAPI_list_t *plmn_range_listList = NULL;
166
2.67k
    cJSON *group_id = NULL;
167
2.67k
    cJSON *primary_chf_instance = NULL;
168
2.67k
    cJSON *secondary_chf_instance = NULL;
169
2.67k
    supi_range_list = cJSON_GetObjectItemCaseSensitive(chf_infoJSON, "supiRangeList");
170
2.67k
    if (supi_range_list) {
171
73
        cJSON *supi_range_list_local = NULL;
172
73
        if (!cJSON_IsArray(supi_range_list)) {
173
73
            ogs_error("OpenAPI_chf_info_parseFromJSON() failed [supi_range_list]");
174
73
            goto end;
175
73
        }
176
177
0
        supi_range_listList = OpenAPI_list_create();
178
179
0
        cJSON_ArrayForEach(supi_range_list_local, supi_range_list) {
180
0
            if (!cJSON_IsObject(supi_range_list_local)) {
181
0
                ogs_error("OpenAPI_chf_info_parseFromJSON() failed [supi_range_list]");
182
0
                goto end;
183
0
            }
184
0
            OpenAPI_supi_range_t *supi_range_listItem = OpenAPI_supi_range_parseFromJSON(supi_range_list_local);
185
0
            if (!supi_range_listItem) {
186
0
                ogs_error("No supi_range_listItem");
187
0
                goto end;
188
0
            }
189
0
            OpenAPI_list_add(supi_range_listList, supi_range_listItem);
190
0
        }
191
0
    }
192
193
2.60k
    gpsi_range_list = cJSON_GetObjectItemCaseSensitive(chf_infoJSON, "gpsiRangeList");
194
2.60k
    if (gpsi_range_list) {
195
36
        cJSON *gpsi_range_list_local = NULL;
196
36
        if (!cJSON_IsArray(gpsi_range_list)) {
197
36
            ogs_error("OpenAPI_chf_info_parseFromJSON() failed [gpsi_range_list]");
198
36
            goto end;
199
36
        }
200
201
0
        gpsi_range_listList = OpenAPI_list_create();
202
203
0
        cJSON_ArrayForEach(gpsi_range_list_local, gpsi_range_list) {
204
0
            if (!cJSON_IsObject(gpsi_range_list_local)) {
205
0
                ogs_error("OpenAPI_chf_info_parseFromJSON() failed [gpsi_range_list]");
206
0
                goto end;
207
0
            }
208
0
            OpenAPI_identity_range_t *gpsi_range_listItem = OpenAPI_identity_range_parseFromJSON(gpsi_range_list_local);
209
0
            if (!gpsi_range_listItem) {
210
0
                ogs_error("No gpsi_range_listItem");
211
0
                goto end;
212
0
            }
213
0
            OpenAPI_list_add(gpsi_range_listList, gpsi_range_listItem);
214
0
        }
215
0
    }
216
217
2.56k
    plmn_range_list = cJSON_GetObjectItemCaseSensitive(chf_infoJSON, "plmnRangeList");
218
2.56k
    if (plmn_range_list) {
219
0
        cJSON *plmn_range_list_local = NULL;
220
0
        if (!cJSON_IsArray(plmn_range_list)) {
221
0
            ogs_error("OpenAPI_chf_info_parseFromJSON() failed [plmn_range_list]");
222
0
            goto end;
223
0
        }
224
225
0
        plmn_range_listList = OpenAPI_list_create();
226
227
0
        cJSON_ArrayForEach(plmn_range_list_local, plmn_range_list) {
228
0
            if (!cJSON_IsObject(plmn_range_list_local)) {
229
0
                ogs_error("OpenAPI_chf_info_parseFromJSON() failed [plmn_range_list]");
230
0
                goto end;
231
0
            }
232
0
            OpenAPI_plmn_range_t *plmn_range_listItem = OpenAPI_plmn_range_parseFromJSON(plmn_range_list_local);
233
0
            if (!plmn_range_listItem) {
234
0
                ogs_error("No plmn_range_listItem");
235
0
                goto end;
236
0
            }
237
0
            OpenAPI_list_add(plmn_range_listList, plmn_range_listItem);
238
0
        }
239
0
    }
240
241
2.56k
    group_id = cJSON_GetObjectItemCaseSensitive(chf_infoJSON, "groupId");
242
2.56k
    if (group_id) {
243
1.01k
    if (!cJSON_IsString(group_id) && !cJSON_IsNull(group_id)) {
244
339
        ogs_error("OpenAPI_chf_info_parseFromJSON() failed [group_id]");
245
339
        goto end;
246
339
    }
247
1.01k
    }
248
249
2.22k
    primary_chf_instance = cJSON_GetObjectItemCaseSensitive(chf_infoJSON, "primaryChfInstance");
250
2.22k
    if (primary_chf_instance) {
251
276
    if (!cJSON_IsString(primary_chf_instance) && !cJSON_IsNull(primary_chf_instance)) {
252
203
        ogs_error("OpenAPI_chf_info_parseFromJSON() failed [primary_chf_instance]");
253
203
        goto end;
254
203
    }
255
276
    }
256
257
2.02k
    secondary_chf_instance = cJSON_GetObjectItemCaseSensitive(chf_infoJSON, "secondaryChfInstance");
258
2.02k
    if (secondary_chf_instance) {
259
152
    if (!cJSON_IsString(secondary_chf_instance) && !cJSON_IsNull(secondary_chf_instance)) {
260
77
        ogs_error("OpenAPI_chf_info_parseFromJSON() failed [secondary_chf_instance]");
261
77
        goto end;
262
77
    }
263
152
    }
264
265
1.94k
    chf_info_local_var = OpenAPI_chf_info_create (
266
1.94k
        supi_range_list ? supi_range_listList : NULL,
267
1.94k
        gpsi_range_list ? gpsi_range_listList : NULL,
268
1.94k
        plmn_range_list ? plmn_range_listList : NULL,
269
1.94k
        group_id && !cJSON_IsNull(group_id) ? ogs_strdup(group_id->valuestring) : NULL,
270
1.94k
        primary_chf_instance && !cJSON_IsNull(primary_chf_instance) ? ogs_strdup(primary_chf_instance->valuestring) : NULL,
271
1.94k
        secondary_chf_instance && !cJSON_IsNull(secondary_chf_instance) ? ogs_strdup(secondary_chf_instance->valuestring) : NULL
272
1.94k
    );
273
274
1.94k
    return chf_info_local_var;
275
728
end:
276
728
    if (supi_range_listList) {
277
0
        OpenAPI_list_for_each(supi_range_listList, node) {
278
0
            OpenAPI_supi_range_free(node->data);
279
0
        }
280
0
        OpenAPI_list_free(supi_range_listList);
281
0
        supi_range_listList = NULL;
282
0
    }
283
728
    if (gpsi_range_listList) {
284
0
        OpenAPI_list_for_each(gpsi_range_listList, node) {
285
0
            OpenAPI_identity_range_free(node->data);
286
0
        }
287
0
        OpenAPI_list_free(gpsi_range_listList);
288
0
        gpsi_range_listList = NULL;
289
0
    }
290
728
    if (plmn_range_listList) {
291
0
        OpenAPI_list_for_each(plmn_range_listList, node) {
292
0
            OpenAPI_plmn_range_free(node->data);
293
0
        }
294
0
        OpenAPI_list_free(plmn_range_listList);
295
0
        plmn_range_listList = NULL;
296
0
    }
297
728
    return NULL;
298
2.02k
}
299
300
OpenAPI_chf_info_t *OpenAPI_chf_info_copy(OpenAPI_chf_info_t *dst, OpenAPI_chf_info_t *src)
301
0
{
302
0
    cJSON *item = NULL;
303
0
    char *content = NULL;
304
305
0
    ogs_assert(src);
306
0
    item = OpenAPI_chf_info_convertToJSON(src);
307
0
    if (!item) {
308
0
        ogs_error("OpenAPI_chf_info_convertToJSON() failed");
309
0
        return NULL;
310
0
    }
311
312
0
    content = cJSON_Print(item);
313
0
    cJSON_Delete(item);
314
315
0
    if (!content) {
316
0
        ogs_error("cJSON_Print() failed");
317
0
        return NULL;
318
0
    }
319
320
0
    item = cJSON_Parse(content);
321
0
    ogs_free(content);
322
0
    if (!item) {
323
0
        ogs_error("cJSON_Parse() failed");
324
0
        return NULL;
325
0
    }
326
327
0
    OpenAPI_chf_info_free(dst);
328
0
    dst = OpenAPI_chf_info_parseFromJSON(item);
329
0
    cJSON_Delete(item);
330
331
0
    return dst;
332
0
}
333