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