Coverage Report

Created: 2026-09-27 06:19

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/open5gs/lib/sbi/openapi/model/twif_info.c
Line
Count
Source
1
2
#include <stdlib.h>
3
#include <string.h>
4
#include <stdio.h>
5
#include "twif_info.h"
6
7
OpenAPI_twif_info_t *OpenAPI_twif_info_create(
8
    OpenAPI_list_t *ipv4_endpoint_addresses,
9
    OpenAPI_list_t *ipv6_endpoint_addresses,
10
    char *endpoint_fqdn
11
)
12
2.92k
{
13
2.92k
    OpenAPI_twif_info_t *twif_info_local_var = ogs_malloc(sizeof(OpenAPI_twif_info_t));
14
2.92k
    ogs_assert(twif_info_local_var);
15
16
2.92k
    twif_info_local_var->ipv4_endpoint_addresses = ipv4_endpoint_addresses;
17
2.92k
    twif_info_local_var->ipv6_endpoint_addresses = ipv6_endpoint_addresses;
18
2.92k
    twif_info_local_var->endpoint_fqdn = endpoint_fqdn;
19
20
2.92k
    return twif_info_local_var;
21
2.92k
}
22
23
void OpenAPI_twif_info_free(OpenAPI_twif_info_t *twif_info)
24
2.92k
{
25
2.92k
    OpenAPI_lnode_t *node = NULL;
26
27
2.92k
    if (NULL == twif_info) {
28
0
        return;
29
0
    }
30
2.92k
    if (twif_info->ipv4_endpoint_addresses) {
31
436
        OpenAPI_list_for_each(twif_info->ipv4_endpoint_addresses, node) {
32
436
            ogs_free(node->data);
33
436
        }
34
398
        OpenAPI_list_free(twif_info->ipv4_endpoint_addresses);
35
398
        twif_info->ipv4_endpoint_addresses = NULL;
36
398
    }
37
2.92k
    if (twif_info->ipv6_endpoint_addresses) {
38
425
        OpenAPI_list_for_each(twif_info->ipv6_endpoint_addresses, node) {
39
425
            ogs_free(node->data);
40
425
        }
41
404
        OpenAPI_list_free(twif_info->ipv6_endpoint_addresses);
42
404
        twif_info->ipv6_endpoint_addresses = NULL;
43
404
    }
44
2.92k
    if (twif_info->endpoint_fqdn) {
45
194
        ogs_free(twif_info->endpoint_fqdn);
46
194
        twif_info->endpoint_fqdn = NULL;
47
194
    }
48
2.92k
    ogs_free(twif_info);
49
2.92k
}
50
51
cJSON *OpenAPI_twif_info_convertToJSON(OpenAPI_twif_info_t *twif_info)
52
0
{
53
0
    cJSON *item = NULL;
54
0
    OpenAPI_lnode_t *node = NULL;
55
56
0
    if (twif_info == NULL) {
57
0
        ogs_error("OpenAPI_twif_info_convertToJSON() failed [TwifInfo]");
58
0
        return NULL;
59
0
    }
60
61
0
    item = cJSON_CreateObject();
62
0
    if (twif_info->ipv4_endpoint_addresses) {
63
0
    cJSON *ipv4_endpoint_addressesList = cJSON_AddArrayToObject(item, "ipv4EndpointAddresses");
64
0
    if (ipv4_endpoint_addressesList == NULL) {
65
0
        ogs_error("OpenAPI_twif_info_convertToJSON() failed [ipv4_endpoint_addresses]");
66
0
        goto end;
67
0
    }
68
0
    OpenAPI_list_for_each(twif_info->ipv4_endpoint_addresses, node) {
69
0
        if (cJSON_AddStringToObject(ipv4_endpoint_addressesList, "", (char*)node->data) == NULL) {
70
0
            ogs_error("OpenAPI_twif_info_convertToJSON() failed [ipv4_endpoint_addresses]");
71
0
            goto end;
72
0
        }
73
0
    }
74
0
    }
75
76
0
    if (twif_info->ipv6_endpoint_addresses) {
77
0
    cJSON *ipv6_endpoint_addressesList = cJSON_AddArrayToObject(item, "ipv6EndpointAddresses");
78
0
    if (ipv6_endpoint_addressesList == NULL) {
79
0
        ogs_error("OpenAPI_twif_info_convertToJSON() failed [ipv6_endpoint_addresses]");
80
0
        goto end;
81
0
    }
82
0
    OpenAPI_list_for_each(twif_info->ipv6_endpoint_addresses, node) {
83
0
        if (cJSON_AddStringToObject(ipv6_endpoint_addressesList, "", (char*)node->data) == NULL) {
84
0
            ogs_error("OpenAPI_twif_info_convertToJSON() failed [ipv6_endpoint_addresses]");
85
0
            goto end;
86
0
        }
87
0
    }
88
0
    }
89
90
0
    if (twif_info->endpoint_fqdn) {
91
0
    if (cJSON_AddStringToObject(item, "endpointFqdn", twif_info->endpoint_fqdn) == NULL) {
92
0
        ogs_error("OpenAPI_twif_info_convertToJSON() failed [endpoint_fqdn]");
93
0
        goto end;
94
0
    }
95
0
    }
96
97
0
end:
98
0
    return item;
99
0
}
100
101
OpenAPI_twif_info_t *OpenAPI_twif_info_parseFromJSON(cJSON *twif_infoJSON)
102
3.43k
{
103
3.43k
    OpenAPI_twif_info_t *twif_info_local_var = NULL;
104
3.43k
    OpenAPI_lnode_t *node = NULL;
105
3.43k
    cJSON *ipv4_endpoint_addresses = NULL;
106
3.43k
    OpenAPI_list_t *ipv4_endpoint_addressesList = NULL;
107
3.43k
    cJSON *ipv6_endpoint_addresses = NULL;
108
3.43k
    OpenAPI_list_t *ipv6_endpoint_addressesList = NULL;
109
3.43k
    cJSON *endpoint_fqdn = NULL;
110
3.43k
    ipv4_endpoint_addresses = cJSON_GetObjectItemCaseSensitive(twif_infoJSON, "ipv4EndpointAddresses");
111
3.43k
    if (ipv4_endpoint_addresses) {
112
604
        cJSON *ipv4_endpoint_addresses_local = NULL;
113
604
        if (!cJSON_IsArray(ipv4_endpoint_addresses)) {
114
66
            ogs_error("OpenAPI_twif_info_parseFromJSON() failed [ipv4_endpoint_addresses]");
115
66
            goto end;
116
66
        }
117
118
538
        ipv4_endpoint_addressesList = OpenAPI_list_create();
119
120
898
        cJSON_ArrayForEach(ipv4_endpoint_addresses_local, ipv4_endpoint_addresses) {
121
898
            double *localDouble = NULL;
122
898
            int *localInt = NULL;
123
898
            if (!cJSON_IsString(ipv4_endpoint_addresses_local)) {
124
140
                ogs_error("OpenAPI_twif_info_parseFromJSON() failed [ipv4_endpoint_addresses]");
125
140
                goto end;
126
140
            }
127
758
            OpenAPI_list_add(ipv4_endpoint_addressesList, ogs_strdup(ipv4_endpoint_addresses_local->valuestring));
128
758
        }
129
538
    }
130
131
3.22k
    ipv6_endpoint_addresses = cJSON_GetObjectItemCaseSensitive(twif_infoJSON, "ipv6EndpointAddresses");
132
3.22k
    if (ipv6_endpoint_addresses) {
133
611
        cJSON *ipv6_endpoint_addresses_local = NULL;
134
611
        if (!cJSON_IsArray(ipv6_endpoint_addresses)) {
135
67
            ogs_error("OpenAPI_twif_info_parseFromJSON() failed [ipv6_endpoint_addresses]");
136
67
            goto end;
137
67
        }
138
139
544
        ipv6_endpoint_addressesList = OpenAPI_list_create();
140
141
875
        cJSON_ArrayForEach(ipv6_endpoint_addresses_local, ipv6_endpoint_addresses) {
142
875
            double *localDouble = NULL;
143
875
            int *localInt = NULL;
144
875
            if (!cJSON_IsString(ipv6_endpoint_addresses_local)) {
145
140
                ogs_error("OpenAPI_twif_info_parseFromJSON() failed [ipv6_endpoint_addresses]");
146
140
                goto end;
147
140
            }
148
735
            OpenAPI_list_add(ipv6_endpoint_addressesList, ogs_strdup(ipv6_endpoint_addresses_local->valuestring));
149
735
        }
150
544
    }
151
152
3.01k
    endpoint_fqdn = cJSON_GetObjectItemCaseSensitive(twif_infoJSON, "endpointFqdn");
153
3.01k
    if (endpoint_fqdn) {
154
478
    if (!cJSON_IsString(endpoint_fqdn) && !cJSON_IsNull(endpoint_fqdn)) {
155
90
        ogs_error("OpenAPI_twif_info_parseFromJSON() failed [endpoint_fqdn]");
156
90
        goto end;
157
90
    }
158
478
    }
159
160
2.92k
    twif_info_local_var = OpenAPI_twif_info_create (
161
2.92k
        ipv4_endpoint_addresses ? ipv4_endpoint_addressesList : NULL,
162
2.92k
        ipv6_endpoint_addresses ? ipv6_endpoint_addressesList : NULL,
163
2.92k
        endpoint_fqdn && !cJSON_IsNull(endpoint_fqdn) ? ogs_strdup(endpoint_fqdn->valuestring) : NULL
164
2.92k
    );
165
166
2.92k
    return twif_info_local_var;
167
503
end:
168
503
    if (ipv4_endpoint_addressesList) {
169
322
        OpenAPI_list_for_each(ipv4_endpoint_addressesList, node) {
170
322
            ogs_free(node->data);
171
322
        }
172
140
        OpenAPI_list_free(ipv4_endpoint_addressesList);
173
140
        ipv4_endpoint_addressesList = NULL;
174
140
    }
175
503
    if (ipv6_endpoint_addressesList) {
176
310
        OpenAPI_list_for_each(ipv6_endpoint_addressesList, node) {
177
310
            ogs_free(node->data);
178
310
        }
179
140
        OpenAPI_list_free(ipv6_endpoint_addressesList);
180
140
        ipv6_endpoint_addressesList = NULL;
181
140
    }
182
503
    return NULL;
183
3.01k
}
184
185
OpenAPI_twif_info_t *OpenAPI_twif_info_copy(OpenAPI_twif_info_t *dst, OpenAPI_twif_info_t *src)
186
0
{
187
0
    cJSON *item = NULL;
188
0
    char *content = NULL;
189
190
0
    ogs_assert(src);
191
0
    item = OpenAPI_twif_info_convertToJSON(src);
192
0
    if (!item) {
193
0
        ogs_error("OpenAPI_twif_info_convertToJSON() failed");
194
0
        return NULL;
195
0
    }
196
197
0
    content = cJSON_Print(item);
198
0
    cJSON_Delete(item);
199
200
0
    if (!content) {
201
0
        ogs_error("cJSON_Print() failed");
202
0
        return NULL;
203
0
    }
204
205
0
    item = cJSON_Parse(content);
206
0
    ogs_free(content);
207
0
    if (!item) {
208
0
        ogs_error("cJSON_Parse() failed");
209
0
        return NULL;
210
0
    }
211
212
0
    OpenAPI_twif_info_free(dst);
213
0
    dst = OpenAPI_twif_info_parseFromJSON(item);
214
0
    cJSON_Delete(item);
215
216
0
    return dst;
217
0
}
218