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/callee_info.c
Line
Count
Source
1
2
#include <stdlib.h>
3
#include <string.h>
4
#include <stdio.h>
5
#include "callee_info.h"
6
7
OpenAPI_callee_info_t *OpenAPI_callee_info_create(
8
    char *called_party_addr,
9
    OpenAPI_list_t *request_party_addrs,
10
    OpenAPI_list_t *called_assert_ids
11
)
12
0
{
13
0
    OpenAPI_callee_info_t *callee_info_local_var = ogs_malloc(sizeof(OpenAPI_callee_info_t));
14
0
    ogs_assert(callee_info_local_var);
15
16
0
    callee_info_local_var->called_party_addr = called_party_addr;
17
0
    callee_info_local_var->request_party_addrs = request_party_addrs;
18
0
    callee_info_local_var->called_assert_ids = called_assert_ids;
19
20
0
    return callee_info_local_var;
21
0
}
22
23
void OpenAPI_callee_info_free(OpenAPI_callee_info_t *callee_info)
24
0
{
25
0
    OpenAPI_lnode_t *node = NULL;
26
27
0
    if (NULL == callee_info) {
28
0
        return;
29
0
    }
30
0
    if (callee_info->called_party_addr) {
31
0
        ogs_free(callee_info->called_party_addr);
32
0
        callee_info->called_party_addr = NULL;
33
0
    }
34
0
    if (callee_info->request_party_addrs) {
35
0
        OpenAPI_list_for_each(callee_info->request_party_addrs, node) {
36
0
            ogs_free(node->data);
37
0
        }
38
0
        OpenAPI_list_free(callee_info->request_party_addrs);
39
0
        callee_info->request_party_addrs = NULL;
40
0
    }
41
0
    if (callee_info->called_assert_ids) {
42
0
        OpenAPI_list_for_each(callee_info->called_assert_ids, node) {
43
0
            ogs_free(node->data);
44
0
        }
45
0
        OpenAPI_list_free(callee_info->called_assert_ids);
46
0
        callee_info->called_assert_ids = NULL;
47
0
    }
48
0
    ogs_free(callee_info);
49
0
}
50
51
cJSON *OpenAPI_callee_info_convertToJSON(OpenAPI_callee_info_t *callee_info)
52
0
{
53
0
    cJSON *item = NULL;
54
0
    OpenAPI_lnode_t *node = NULL;
55
56
0
    if (callee_info == NULL) {
57
0
        ogs_error("OpenAPI_callee_info_convertToJSON() failed [CalleeInfo]");
58
0
        return NULL;
59
0
    }
60
61
0
    item = cJSON_CreateObject();
62
0
    if (callee_info->called_party_addr) {
63
0
    if (cJSON_AddStringToObject(item, "calledPartyAddr", callee_info->called_party_addr) == NULL) {
64
0
        ogs_error("OpenAPI_callee_info_convertToJSON() failed [called_party_addr]");
65
0
        goto end;
66
0
    }
67
0
    }
68
69
0
    if (callee_info->request_party_addrs) {
70
0
    cJSON *request_party_addrsList = cJSON_AddArrayToObject(item, "requestPartyAddrs");
71
0
    if (request_party_addrsList == NULL) {
72
0
        ogs_error("OpenAPI_callee_info_convertToJSON() failed [request_party_addrs]");
73
0
        goto end;
74
0
    }
75
0
    OpenAPI_list_for_each(callee_info->request_party_addrs, node) {
76
0
        if (cJSON_AddStringToObject(request_party_addrsList, "", (char*)node->data) == NULL) {
77
0
            ogs_error("OpenAPI_callee_info_convertToJSON() failed [request_party_addrs]");
78
0
            goto end;
79
0
        }
80
0
    }
81
0
    }
82
83
0
    if (callee_info->called_assert_ids) {
84
0
    cJSON *called_assert_idsList = cJSON_AddArrayToObject(item, "calledAssertIds");
85
0
    if (called_assert_idsList == NULL) {
86
0
        ogs_error("OpenAPI_callee_info_convertToJSON() failed [called_assert_ids]");
87
0
        goto end;
88
0
    }
89
0
    OpenAPI_list_for_each(callee_info->called_assert_ids, node) {
90
0
        if (cJSON_AddStringToObject(called_assert_idsList, "", (char*)node->data) == NULL) {
91
0
            ogs_error("OpenAPI_callee_info_convertToJSON() failed [called_assert_ids]");
92
0
            goto end;
93
0
        }
94
0
    }
95
0
    }
96
97
0
end:
98
0
    return item;
99
0
}
100
101
OpenAPI_callee_info_t *OpenAPI_callee_info_parseFromJSON(cJSON *callee_infoJSON)
102
0
{
103
0
    OpenAPI_callee_info_t *callee_info_local_var = NULL;
104
0
    OpenAPI_lnode_t *node = NULL;
105
0
    cJSON *called_party_addr = NULL;
106
0
    cJSON *request_party_addrs = NULL;
107
0
    OpenAPI_list_t *request_party_addrsList = NULL;
108
0
    cJSON *called_assert_ids = NULL;
109
0
    OpenAPI_list_t *called_assert_idsList = NULL;
110
0
    called_party_addr = cJSON_GetObjectItemCaseSensitive(callee_infoJSON, "calledPartyAddr");
111
0
    if (called_party_addr) {
112
0
    if (!cJSON_IsString(called_party_addr) && !cJSON_IsNull(called_party_addr)) {
113
0
        ogs_error("OpenAPI_callee_info_parseFromJSON() failed [called_party_addr]");
114
0
        goto end;
115
0
    }
116
0
    }
117
118
0
    request_party_addrs = cJSON_GetObjectItemCaseSensitive(callee_infoJSON, "requestPartyAddrs");
119
0
    if (request_party_addrs) {
120
0
        cJSON *request_party_addrs_local = NULL;
121
0
        if (!cJSON_IsArray(request_party_addrs)) {
122
0
            ogs_error("OpenAPI_callee_info_parseFromJSON() failed [request_party_addrs]");
123
0
            goto end;
124
0
        }
125
126
0
        request_party_addrsList = OpenAPI_list_create();
127
128
0
        cJSON_ArrayForEach(request_party_addrs_local, request_party_addrs) {
129
0
            double *localDouble = NULL;
130
0
            int *localInt = NULL;
131
0
            if (!cJSON_IsString(request_party_addrs_local)) {
132
0
                ogs_error("OpenAPI_callee_info_parseFromJSON() failed [request_party_addrs]");
133
0
                goto end;
134
0
            }
135
0
            OpenAPI_list_add(request_party_addrsList, ogs_strdup(request_party_addrs_local->valuestring));
136
0
        }
137
0
    }
138
139
0
    called_assert_ids = cJSON_GetObjectItemCaseSensitive(callee_infoJSON, "calledAssertIds");
140
0
    if (called_assert_ids) {
141
0
        cJSON *called_assert_ids_local = NULL;
142
0
        if (!cJSON_IsArray(called_assert_ids)) {
143
0
            ogs_error("OpenAPI_callee_info_parseFromJSON() failed [called_assert_ids]");
144
0
            goto end;
145
0
        }
146
147
0
        called_assert_idsList = OpenAPI_list_create();
148
149
0
        cJSON_ArrayForEach(called_assert_ids_local, called_assert_ids) {
150
0
            double *localDouble = NULL;
151
0
            int *localInt = NULL;
152
0
            if (!cJSON_IsString(called_assert_ids_local)) {
153
0
                ogs_error("OpenAPI_callee_info_parseFromJSON() failed [called_assert_ids]");
154
0
                goto end;
155
0
            }
156
0
            OpenAPI_list_add(called_assert_idsList, ogs_strdup(called_assert_ids_local->valuestring));
157
0
        }
158
0
    }
159
160
0
    callee_info_local_var = OpenAPI_callee_info_create (
161
0
        called_party_addr && !cJSON_IsNull(called_party_addr) ? ogs_strdup(called_party_addr->valuestring) : NULL,
162
0
        request_party_addrs ? request_party_addrsList : NULL,
163
0
        called_assert_ids ? called_assert_idsList : NULL
164
0
    );
165
166
0
    return callee_info_local_var;
167
0
end:
168
0
    if (request_party_addrsList) {
169
0
        OpenAPI_list_for_each(request_party_addrsList, node) {
170
0
            ogs_free(node->data);
171
0
        }
172
0
        OpenAPI_list_free(request_party_addrsList);
173
0
        request_party_addrsList = NULL;
174
0
    }
175
0
    if (called_assert_idsList) {
176
0
        OpenAPI_list_for_each(called_assert_idsList, node) {
177
0
            ogs_free(node->data);
178
0
        }
179
0
        OpenAPI_list_free(called_assert_idsList);
180
0
        called_assert_idsList = NULL;
181
0
    }
182
0
    return NULL;
183
0
}
184
185
OpenAPI_callee_info_t *OpenAPI_callee_info_copy(OpenAPI_callee_info_t *dst, OpenAPI_callee_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_callee_info_convertToJSON(src);
192
0
    if (!item) {
193
0
        ogs_error("OpenAPI_callee_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_callee_info_free(dst);
213
0
    dst = OpenAPI_callee_info_parseFromJSON(item);
214
0
    cJSON_Delete(item);
215
216
0
    return dst;
217
0
}
218