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/tunnel_info.c
Line
Count
Source
1
2
#include <stdlib.h>
3
#include <string.h>
4
#include <stdio.h>
5
#include "tunnel_info.h"
6
7
OpenAPI_tunnel_info_t *OpenAPI_tunnel_info_create(
8
    char *ipv4_addr,
9
    char *ipv6_addr,
10
    char *gtp_teid,
11
    OpenAPI_access_type_e an_type
12
)
13
0
{
14
0
    OpenAPI_tunnel_info_t *tunnel_info_local_var = ogs_malloc(sizeof(OpenAPI_tunnel_info_t));
15
0
    ogs_assert(tunnel_info_local_var);
16
17
0
    tunnel_info_local_var->ipv4_addr = ipv4_addr;
18
0
    tunnel_info_local_var->ipv6_addr = ipv6_addr;
19
0
    tunnel_info_local_var->gtp_teid = gtp_teid;
20
0
    tunnel_info_local_var->an_type = an_type;
21
22
0
    return tunnel_info_local_var;
23
0
}
24
25
void OpenAPI_tunnel_info_free(OpenAPI_tunnel_info_t *tunnel_info)
26
0
{
27
0
    OpenAPI_lnode_t *node = NULL;
28
29
0
    if (NULL == tunnel_info) {
30
0
        return;
31
0
    }
32
0
    if (tunnel_info->ipv4_addr) {
33
0
        ogs_free(tunnel_info->ipv4_addr);
34
0
        tunnel_info->ipv4_addr = NULL;
35
0
    }
36
0
    if (tunnel_info->ipv6_addr) {
37
0
        ogs_free(tunnel_info->ipv6_addr);
38
0
        tunnel_info->ipv6_addr = NULL;
39
0
    }
40
0
    if (tunnel_info->gtp_teid) {
41
0
        ogs_free(tunnel_info->gtp_teid);
42
0
        tunnel_info->gtp_teid = NULL;
43
0
    }
44
0
    ogs_free(tunnel_info);
45
0
}
46
47
cJSON *OpenAPI_tunnel_info_convertToJSON(OpenAPI_tunnel_info_t *tunnel_info)
48
0
{
49
0
    cJSON *item = NULL;
50
0
    OpenAPI_lnode_t *node = NULL;
51
52
0
    if (tunnel_info == NULL) {
53
0
        ogs_error("OpenAPI_tunnel_info_convertToJSON() failed [TunnelInfo]");
54
0
        return NULL;
55
0
    }
56
57
0
    item = cJSON_CreateObject();
58
0
    if (tunnel_info->ipv4_addr) {
59
0
    if (cJSON_AddStringToObject(item, "ipv4Addr", tunnel_info->ipv4_addr) == NULL) {
60
0
        ogs_error("OpenAPI_tunnel_info_convertToJSON() failed [ipv4_addr]");
61
0
        goto end;
62
0
    }
63
0
    }
64
65
0
    if (tunnel_info->ipv6_addr) {
66
0
    if (cJSON_AddStringToObject(item, "ipv6Addr", tunnel_info->ipv6_addr) == NULL) {
67
0
        ogs_error("OpenAPI_tunnel_info_convertToJSON() failed [ipv6_addr]");
68
0
        goto end;
69
0
    }
70
0
    }
71
72
0
    if (!tunnel_info->gtp_teid) {
73
0
        ogs_error("OpenAPI_tunnel_info_convertToJSON() failed [gtp_teid]");
74
0
        return NULL;
75
0
    }
76
0
    if (cJSON_AddStringToObject(item, "gtpTeid", tunnel_info->gtp_teid) == NULL) {
77
0
        ogs_error("OpenAPI_tunnel_info_convertToJSON() failed [gtp_teid]");
78
0
        goto end;
79
0
    }
80
81
0
    if (tunnel_info->an_type != OpenAPI_access_type_NULL) {
82
0
    if (cJSON_AddStringToObject(item, "anType", OpenAPI_access_type_ToString(tunnel_info->an_type)) == NULL) {
83
0
        ogs_error("OpenAPI_tunnel_info_convertToJSON() failed [an_type]");
84
0
        goto end;
85
0
    }
86
0
    }
87
88
0
end:
89
0
    return item;
90
0
}
91
92
OpenAPI_tunnel_info_t *OpenAPI_tunnel_info_parseFromJSON(cJSON *tunnel_infoJSON)
93
0
{
94
0
    OpenAPI_tunnel_info_t *tunnel_info_local_var = NULL;
95
0
    OpenAPI_lnode_t *node = NULL;
96
0
    cJSON *ipv4_addr = NULL;
97
0
    cJSON *ipv6_addr = NULL;
98
0
    cJSON *gtp_teid = NULL;
99
0
    cJSON *an_type = NULL;
100
0
    OpenAPI_access_type_e an_typeVariable = 0;
101
0
    ipv4_addr = cJSON_GetObjectItemCaseSensitive(tunnel_infoJSON, "ipv4Addr");
102
0
    if (ipv4_addr) {
103
0
    if (!cJSON_IsString(ipv4_addr) && !cJSON_IsNull(ipv4_addr)) {
104
0
        ogs_error("OpenAPI_tunnel_info_parseFromJSON() failed [ipv4_addr]");
105
0
        goto end;
106
0
    }
107
0
    }
108
109
0
    ipv6_addr = cJSON_GetObjectItemCaseSensitive(tunnel_infoJSON, "ipv6Addr");
110
0
    if (ipv6_addr) {
111
0
    if (!cJSON_IsString(ipv6_addr) && !cJSON_IsNull(ipv6_addr)) {
112
0
        ogs_error("OpenAPI_tunnel_info_parseFromJSON() failed [ipv6_addr]");
113
0
        goto end;
114
0
    }
115
0
    }
116
117
0
    gtp_teid = cJSON_GetObjectItemCaseSensitive(tunnel_infoJSON, "gtpTeid");
118
0
    if (!gtp_teid) {
119
0
        ogs_error("OpenAPI_tunnel_info_parseFromJSON() failed [gtp_teid]");
120
0
        goto end;
121
0
    }
122
0
    if (!cJSON_IsString(gtp_teid)) {
123
0
        ogs_error("OpenAPI_tunnel_info_parseFromJSON() failed [gtp_teid]");
124
0
        goto end;
125
0
    }
126
127
0
    an_type = cJSON_GetObjectItemCaseSensitive(tunnel_infoJSON, "anType");
128
0
    if (an_type) {
129
0
    if (!cJSON_IsString(an_type)) {
130
0
        ogs_error("OpenAPI_tunnel_info_parseFromJSON() failed [an_type]");
131
0
        goto end;
132
0
    }
133
0
    an_typeVariable = OpenAPI_access_type_FromString(an_type->valuestring);
134
0
    }
135
136
0
    tunnel_info_local_var = OpenAPI_tunnel_info_create (
137
0
        ipv4_addr && !cJSON_IsNull(ipv4_addr) ? ogs_strdup(ipv4_addr->valuestring) : NULL,
138
0
        ipv6_addr && !cJSON_IsNull(ipv6_addr) ? ogs_strdup(ipv6_addr->valuestring) : NULL,
139
0
        ogs_strdup(gtp_teid->valuestring),
140
0
        an_type ? an_typeVariable : 0
141
0
    );
142
143
0
    return tunnel_info_local_var;
144
0
end:
145
0
    return NULL;
146
0
}
147
148
OpenAPI_tunnel_info_t *OpenAPI_tunnel_info_copy(OpenAPI_tunnel_info_t *dst, OpenAPI_tunnel_info_t *src)
149
0
{
150
0
    cJSON *item = NULL;
151
0
    char *content = NULL;
152
153
0
    ogs_assert(src);
154
0
    item = OpenAPI_tunnel_info_convertToJSON(src);
155
0
    if (!item) {
156
0
        ogs_error("OpenAPI_tunnel_info_convertToJSON() failed");
157
0
        return NULL;
158
0
    }
159
160
0
    content = cJSON_Print(item);
161
0
    cJSON_Delete(item);
162
163
0
    if (!content) {
164
0
        ogs_error("cJSON_Print() failed");
165
0
        return NULL;
166
0
    }
167
168
0
    item = cJSON_Parse(content);
169
0
    ogs_free(content);
170
0
    if (!item) {
171
0
        ogs_error("cJSON_Parse() failed");
172
0
        return NULL;
173
0
    }
174
175
0
    OpenAPI_tunnel_info_free(dst);
176
0
    dst = OpenAPI_tunnel_info_parseFromJSON(item);
177
0
    cJSON_Delete(item);
178
179
0
    return dst;
180
0
}
181