Coverage Report

Created: 2026-08-14 06:04

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/open5gs/lib/sbi/openapi/model/suci_info.c
Line
Count
Source
1
2
#include <stdlib.h>
3
#include <string.h>
4
#include <stdio.h>
5
#include "suci_info.h"
6
7
OpenAPI_suci_info_t *OpenAPI_suci_info_create(
8
    OpenAPI_list_t *routing_inds,
9
    OpenAPI_list_t *h_nw_pub_key_ids
10
)
11
5.73k
{
12
5.73k
    OpenAPI_suci_info_t *suci_info_local_var = ogs_malloc(sizeof(OpenAPI_suci_info_t));
13
5.73k
    ogs_assert(suci_info_local_var);
14
15
5.73k
    suci_info_local_var->routing_inds = routing_inds;
16
5.73k
    suci_info_local_var->h_nw_pub_key_ids = h_nw_pub_key_ids;
17
18
5.73k
    return suci_info_local_var;
19
5.73k
}
20
21
void OpenAPI_suci_info_free(OpenAPI_suci_info_t *suci_info)
22
5.73k
{
23
5.73k
    OpenAPI_lnode_t *node = NULL;
24
25
5.73k
    if (NULL == suci_info) {
26
0
        return;
27
0
    }
28
5.73k
    if (suci_info->routing_inds) {
29
921
        OpenAPI_list_for_each(suci_info->routing_inds, node) {
30
570
            ogs_free(node->data);
31
570
        }
32
921
        OpenAPI_list_free(suci_info->routing_inds);
33
921
        suci_info->routing_inds = NULL;
34
921
    }
35
5.73k
    if (suci_info->h_nw_pub_key_ids) {
36
546
        OpenAPI_list_for_each(suci_info->h_nw_pub_key_ids, node) {
37
546
            ogs_free(node->data);
38
546
        }
39
474
        OpenAPI_list_free(suci_info->h_nw_pub_key_ids);
40
474
        suci_info->h_nw_pub_key_ids = NULL;
41
474
    }
42
5.73k
    ogs_free(suci_info);
43
5.73k
}
44
45
cJSON *OpenAPI_suci_info_convertToJSON(OpenAPI_suci_info_t *suci_info)
46
0
{
47
0
    cJSON *item = NULL;
48
0
    OpenAPI_lnode_t *node = NULL;
49
50
0
    if (suci_info == NULL) {
51
0
        ogs_error("OpenAPI_suci_info_convertToJSON() failed [SuciInfo]");
52
0
        return NULL;
53
0
    }
54
55
0
    item = cJSON_CreateObject();
56
0
    if (suci_info->routing_inds) {
57
0
    cJSON *routing_indsList = cJSON_AddArrayToObject(item, "routingInds");
58
0
    if (routing_indsList == NULL) {
59
0
        ogs_error("OpenAPI_suci_info_convertToJSON() failed [routing_inds]");
60
0
        goto end;
61
0
    }
62
0
    OpenAPI_list_for_each(suci_info->routing_inds, node) {
63
0
        if (cJSON_AddStringToObject(routing_indsList, "", (char*)node->data) == NULL) {
64
0
            ogs_error("OpenAPI_suci_info_convertToJSON() failed [routing_inds]");
65
0
            goto end;
66
0
        }
67
0
    }
68
0
    }
69
70
0
    if (suci_info->h_nw_pub_key_ids) {
71
0
    cJSON *h_nw_pub_key_idsList = cJSON_AddArrayToObject(item, "hNwPubKeyIds");
72
0
    if (h_nw_pub_key_idsList == NULL) {
73
0
        ogs_error("OpenAPI_suci_info_convertToJSON() failed [h_nw_pub_key_ids]");
74
0
        goto end;
75
0
    }
76
0
    OpenAPI_list_for_each(suci_info->h_nw_pub_key_ids, node) {
77
0
        if (node->data == NULL) {
78
0
            ogs_error("OpenAPI_suci_info_convertToJSON() failed [h_nw_pub_key_ids]");
79
0
            goto end;
80
0
        }
81
0
        if (cJSON_AddNumberToObject(h_nw_pub_key_idsList, "", *(double *)node->data) == NULL) {
82
0
            ogs_error("OpenAPI_suci_info_convertToJSON() failed [h_nw_pub_key_ids]");
83
0
            goto end;
84
0
        }
85
0
    }
86
0
    }
87
88
0
end:
89
0
    return item;
90
0
}
91
92
OpenAPI_suci_info_t *OpenAPI_suci_info_parseFromJSON(cJSON *suci_infoJSON)
93
6.47k
{
94
6.47k
    OpenAPI_suci_info_t *suci_info_local_var = NULL;
95
6.47k
    OpenAPI_lnode_t *node = NULL;
96
6.47k
    cJSON *routing_inds = NULL;
97
6.47k
    OpenAPI_list_t *routing_indsList = NULL;
98
6.47k
    cJSON *h_nw_pub_key_ids = NULL;
99
6.47k
    OpenAPI_list_t *h_nw_pub_key_idsList = NULL;
100
6.47k
    routing_inds = cJSON_GetObjectItemCaseSensitive(suci_infoJSON, "routingInds");
101
6.47k
    if (routing_inds) {
102
1.31k
        cJSON *routing_inds_local = NULL;
103
1.31k
        if (!cJSON_IsArray(routing_inds)) {
104
243
            ogs_error("OpenAPI_suci_info_parseFromJSON() failed [routing_inds]");
105
243
            goto end;
106
243
        }
107
108
1.07k
        routing_indsList = OpenAPI_list_create();
109
110
1.07k
        cJSON_ArrayForEach(routing_inds_local, routing_inds) {
111
1.03k
            double *localDouble = NULL;
112
1.03k
            int *localInt = NULL;
113
1.03k
            if (!cJSON_IsString(routing_inds_local)) {
114
151
                ogs_error("OpenAPI_suci_info_parseFromJSON() failed [routing_inds]");
115
151
                goto end;
116
151
            }
117
885
            OpenAPI_list_add(routing_indsList, ogs_strdup(routing_inds_local->valuestring));
118
885
        }
119
1.07k
    }
120
121
6.08k
    h_nw_pub_key_ids = cJSON_GetObjectItemCaseSensitive(suci_infoJSON, "hNwPubKeyIds");
122
6.08k
    if (h_nw_pub_key_ids) {
123
815
        cJSON *h_nw_pub_key_ids_local = NULL;
124
815
        if (!cJSON_IsArray(h_nw_pub_key_ids)) {
125
66
            ogs_error("OpenAPI_suci_info_parseFromJSON() failed [h_nw_pub_key_ids]");
126
66
            goto end;
127
66
        }
128
129
749
        h_nw_pub_key_idsList = OpenAPI_list_create();
130
131
2.14k
        cJSON_ArrayForEach(h_nw_pub_key_ids_local, h_nw_pub_key_ids) {
132
2.14k
            double *localDouble = NULL;
133
2.14k
            int *localInt = NULL;
134
2.14k
            if (!cJSON_IsNumber(h_nw_pub_key_ids_local)) {
135
275
                ogs_error("OpenAPI_suci_info_parseFromJSON() failed [h_nw_pub_key_ids]");
136
275
                goto end;
137
275
            }
138
1.86k
            localDouble = (double *)ogs_calloc(1, sizeof(double));
139
1.86k
            if (!localDouble) {
140
0
                ogs_error("OpenAPI_suci_info_parseFromJSON() failed [h_nw_pub_key_ids]");
141
0
                goto end;
142
0
            }
143
1.86k
            *localDouble = h_nw_pub_key_ids_local->valuedouble;
144
1.86k
            OpenAPI_list_add(h_nw_pub_key_idsList, localDouble);
145
1.86k
        }
146
749
    }
147
148
5.73k
    suci_info_local_var = OpenAPI_suci_info_create (
149
5.73k
        routing_inds ? routing_indsList : NULL,
150
5.73k
        h_nw_pub_key_ids ? h_nw_pub_key_idsList : NULL
151
5.73k
    );
152
153
5.73k
    return suci_info_local_var;
154
735
end:
155
735
    if (routing_indsList) {
156
315
        OpenAPI_list_for_each(routing_indsList, node) {
157
315
            ogs_free(node->data);
158
315
        }
159
151
        OpenAPI_list_free(routing_indsList);
160
151
        routing_indsList = NULL;
161
151
    }
162
735
    if (h_nw_pub_key_idsList) {
163
1.31k
        OpenAPI_list_for_each(h_nw_pub_key_idsList, node) {
164
1.31k
            ogs_free(node->data);
165
1.31k
        }
166
275
        OpenAPI_list_free(h_nw_pub_key_idsList);
167
275
        h_nw_pub_key_idsList = NULL;
168
275
    }
169
735
    return NULL;
170
6.08k
}
171
172
OpenAPI_suci_info_t *OpenAPI_suci_info_copy(OpenAPI_suci_info_t *dst, OpenAPI_suci_info_t *src)
173
0
{
174
0
    cJSON *item = NULL;
175
0
    char *content = NULL;
176
177
0
    ogs_assert(src);
178
0
    item = OpenAPI_suci_info_convertToJSON(src);
179
0
    if (!item) {
180
0
        ogs_error("OpenAPI_suci_info_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_suci_info_free(dst);
200
0
    dst = OpenAPI_suci_info_parseFromJSON(item);
201
0
    cJSON_Delete(item);
202
203
0
    return dst;
204
0
}
205