Coverage Report

Created: 2026-11-12 06:28

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
4.40k
{
16
4.40k
    OpenAPI_chf_info_t *chf_info_local_var = ogs_malloc(sizeof(OpenAPI_chf_info_t));
17
4.40k
    ogs_assert(chf_info_local_var);
18
19
4.40k
    chf_info_local_var->supi_range_list = supi_range_list;
20
4.40k
    chf_info_local_var->gpsi_range_list = gpsi_range_list;
21
4.40k
    chf_info_local_var->plmn_range_list = plmn_range_list;
22
4.40k
    chf_info_local_var->group_id = group_id;
23
4.40k
    chf_info_local_var->primary_chf_instance = primary_chf_instance;
24
4.40k
    chf_info_local_var->secondary_chf_instance = secondary_chf_instance;
25
26
4.40k
    return chf_info_local_var;
27
4.40k
}
28
29
void OpenAPI_chf_info_free(OpenAPI_chf_info_t *chf_info)
30
7.57k
{
31
7.57k
    OpenAPI_lnode_t *node = NULL;
32
33
7.57k
    if (NULL == chf_info) {
34
3.16k
        return;
35
3.16k
    }
36
4.40k
    if (chf_info->supi_range_list) {
37
705
        OpenAPI_list_for_each(chf_info->supi_range_list, node) {
38
705
            OpenAPI_supi_range_free(node->data);
39
705
        }
40
399
        OpenAPI_list_free(chf_info->supi_range_list);
41
399
        chf_info->supi_range_list = NULL;
42
399
    }
43
4.40k
    if (chf_info->gpsi_range_list) {
44
328
        OpenAPI_list_for_each(chf_info->gpsi_range_list, node) {
45
328
            OpenAPI_identity_range_free(node->data);
46
328
        }
47
257
        OpenAPI_list_free(chf_info->gpsi_range_list);
48
257
        chf_info->gpsi_range_list = NULL;
49
257
    }
50
4.40k
    if (chf_info->plmn_range_list) {
51
533
        OpenAPI_list_for_each(chf_info->plmn_range_list, node) {
52
533
            OpenAPI_plmn_range_free(node->data);
53
533
        }
54
140
        OpenAPI_list_free(chf_info->plmn_range_list);
55
140
        chf_info->plmn_range_list = NULL;
56
140
    }
57
4.40k
    if (chf_info->group_id) {
58
196
        ogs_free(chf_info->group_id);
59
196
        chf_info->group_id = NULL;
60
196
    }
61
4.40k
    if (chf_info->primary_chf_instance) {
62
194
        ogs_free(chf_info->primary_chf_instance);
63
194
        chf_info->primary_chf_instance = NULL;
64
194
    }
65
4.40k
    if (chf_info->secondary_chf_instance) {
66
194
        ogs_free(chf_info->secondary_chf_instance);
67
194
        chf_info->secondary_chf_instance = NULL;
68
194
    }
69
4.40k
    ogs_free(chf_info);
70
4.40k
}
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
6.94k
{
158
6.94k
    OpenAPI_chf_info_t *chf_info_local_var = NULL;
159
6.94k
    OpenAPI_lnode_t *node = NULL;
160
6.94k
    cJSON *supi_range_list = NULL;
161
6.94k
    OpenAPI_list_t *supi_range_listList = NULL;
162
6.94k
    cJSON *gpsi_range_list = NULL;
163
6.94k
    OpenAPI_list_t *gpsi_range_listList = NULL;
164
6.94k
    cJSON *plmn_range_list = NULL;
165
6.94k
    OpenAPI_list_t *plmn_range_listList = NULL;
166
6.94k
    cJSON *group_id = NULL;
167
6.94k
    cJSON *primary_chf_instance = NULL;
168
6.94k
    cJSON *secondary_chf_instance = NULL;
169
6.94k
    supi_range_list = cJSON_GetObjectItemCaseSensitive(chf_infoJSON, "supiRangeList");
170
6.94k
    if (supi_range_list) {
171
884
        cJSON *supi_range_list_local = NULL;
172
884
        if (!cJSON_IsArray(supi_range_list)) {
173
194
            ogs_error("OpenAPI_chf_info_parseFromJSON() failed [supi_range_list]");
174
194
            goto end;
175
194
        }
176
177
690
        supi_range_listList = OpenAPI_list_create();
178
179
1.55k
        cJSON_ArrayForEach(supi_range_list_local, supi_range_list) {
180
1.55k
            if (!cJSON_IsObject(supi_range_list_local)) {
181
273
                ogs_error("OpenAPI_chf_info_parseFromJSON() failed [supi_range_list]");
182
273
                goto end;
183
273
            }
184
1.28k
            OpenAPI_supi_range_t *supi_range_listItem = OpenAPI_supi_range_parseFromJSON(supi_range_list_local);
185
1.28k
            if (!supi_range_listItem) {
186
18
                ogs_error("No supi_range_listItem");
187
18
                goto end;
188
18
            }
189
1.26k
            OpenAPI_list_add(supi_range_listList, supi_range_listItem);
190
1.26k
        }
191
690
    }
192
193
6.45k
    gpsi_range_list = cJSON_GetObjectItemCaseSensitive(chf_infoJSON, "gpsiRangeList");
194
6.45k
    if (gpsi_range_list) {
195
1.06k
        cJSON *gpsi_range_list_local = NULL;
196
1.06k
        if (!cJSON_IsArray(gpsi_range_list)) {
197
195
            ogs_error("OpenAPI_chf_info_parseFromJSON() failed [gpsi_range_list]");
198
195
            goto end;
199
195
        }
200
201
869
        gpsi_range_listList = OpenAPI_list_create();
202
203
1.67k
        cJSON_ArrayForEach(gpsi_range_list_local, gpsi_range_list) {
204
1.67k
            if (!cJSON_IsObject(gpsi_range_list_local)) {
205
418
                ogs_error("OpenAPI_chf_info_parseFromJSON() failed [gpsi_range_list]");
206
418
                goto end;
207
418
            }
208
1.25k
            OpenAPI_identity_range_t *gpsi_range_listItem = OpenAPI_identity_range_parseFromJSON(gpsi_range_list_local);
209
1.25k
            if (!gpsi_range_listItem) {
210
194
                ogs_error("No gpsi_range_listItem");
211
194
                goto end;
212
194
            }
213
1.06k
            OpenAPI_list_add(gpsi_range_listList, gpsi_range_listItem);
214
1.06k
        }
215
869
    }
216
217
5.64k
    plmn_range_list = cJSON_GetObjectItemCaseSensitive(chf_infoJSON, "plmnRangeList");
218
5.64k
    if (plmn_range_list) {
219
788
        cJSON *plmn_range_list_local = NULL;
220
788
        if (!cJSON_IsArray(plmn_range_list)) {
221
194
            ogs_error("OpenAPI_chf_info_parseFromJSON() failed [plmn_range_list]");
222
194
            goto end;
223
194
        }
224
225
594
        plmn_range_listList = OpenAPI_list_create();
226
227
2.58k
        cJSON_ArrayForEach(plmn_range_list_local, plmn_range_list) {
228
2.58k
            if (!cJSON_IsObject(plmn_range_list_local)) {
229
256
                ogs_error("OpenAPI_chf_info_parseFromJSON() failed [plmn_range_list]");
230
256
                goto end;
231
256
            }
232
2.33k
            OpenAPI_plmn_range_t *plmn_range_listItem = OpenAPI_plmn_range_parseFromJSON(plmn_range_list_local);
233
2.33k
            if (!plmn_range_listItem) {
234
198
                ogs_error("No plmn_range_listItem");
235
198
                goto end;
236
198
            }
237
2.13k
            OpenAPI_list_add(plmn_range_listList, plmn_range_listItem);
238
2.13k
        }
239
594
    }
240
241
5.00k
    group_id = cJSON_GetObjectItemCaseSensitive(chf_infoJSON, "groupId");
242
5.00k
    if (group_id) {
243
593
    if (!cJSON_IsString(group_id) && !cJSON_IsNull(group_id)) {
244
203
        ogs_error("OpenAPI_chf_info_parseFromJSON() failed [group_id]");
245
203
        goto end;
246
203
    }
247
593
    }
248
249
4.79k
    primary_chf_instance = cJSON_GetObjectItemCaseSensitive(chf_infoJSON, "primaryChfInstance");
250
4.79k
    if (primary_chf_instance) {
251
582
    if (!cJSON_IsString(primary_chf_instance) && !cJSON_IsNull(primary_chf_instance)) {
252
194
        ogs_error("OpenAPI_chf_info_parseFromJSON() failed [primary_chf_instance]");
253
194
        goto end;
254
194
    }
255
582
    }
256
257
4.60k
    secondary_chf_instance = cJSON_GetObjectItemCaseSensitive(chf_infoJSON, "secondaryChfInstance");
258
4.60k
    if (secondary_chf_instance) {
259
584
    if (!cJSON_IsString(secondary_chf_instance) && !cJSON_IsNull(secondary_chf_instance)) {
260
196
        ogs_error("OpenAPI_chf_info_parseFromJSON() failed [secondary_chf_instance]");
261
196
        goto end;
262
196
    }
263
584
    }
264
265
4.40k
    chf_info_local_var = OpenAPI_chf_info_create (
266
4.40k
        supi_range_list ? supi_range_listList : NULL,
267
4.40k
        gpsi_range_list ? gpsi_range_listList : NULL,
268
4.40k
        plmn_range_list ? plmn_range_listList : NULL,
269
4.40k
        group_id && !cJSON_IsNull(group_id) ? ogs_strdup(group_id->valuestring) : NULL,
270
4.40k
        primary_chf_instance && !cJSON_IsNull(primary_chf_instance) ? ogs_strdup(primary_chf_instance->valuestring) : NULL,
271
4.40k
        secondary_chf_instance && !cJSON_IsNull(secondary_chf_instance) ? ogs_strdup(secondary_chf_instance->valuestring) : NULL
272
4.40k
    );
273
274
4.40k
    return chf_info_local_var;
275
2.53k
end:
276
2.53k
    if (supi_range_listList) {
277
561
        OpenAPI_list_for_each(supi_range_listList, node) {
278
561
            OpenAPI_supi_range_free(node->data);
279
561
        }
280
291
        OpenAPI_list_free(supi_range_listList);
281
291
        supi_range_listList = NULL;
282
291
    }
283
2.53k
    if (gpsi_range_listList) {
284
733
        OpenAPI_list_for_each(gpsi_range_listList, node) {
285
733
            OpenAPI_identity_range_free(node->data);
286
733
        }
287
612
        OpenAPI_list_free(gpsi_range_listList);
288
612
        gpsi_range_listList = NULL;
289
612
    }
290
2.53k
    if (plmn_range_listList) {
291
1.60k
        OpenAPI_list_for_each(plmn_range_listList, node) {
292
1.60k
            OpenAPI_plmn_range_free(node->data);
293
1.60k
        }
294
454
        OpenAPI_list_free(plmn_range_listList);
295
454
        plmn_range_listList = NULL;
296
454
    }
297
2.53k
    return NULL;
298
4.60k
}
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