Coverage Report

Created: 2026-06-30 06:14

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/open5gs/lib/sbi/openapi/model/pfd_data.c
Line
Count
Source
1
2
#include <stdlib.h>
3
#include <string.h>
4
#include <stdio.h>
5
#include "pfd_data.h"
6
7
OpenAPI_pfd_data_t *OpenAPI_pfd_data_create(
8
    OpenAPI_list_t *app_ids,
9
    OpenAPI_list_t *af_ids
10
)
11
0
{
12
0
    OpenAPI_pfd_data_t *pfd_data_local_var = ogs_malloc(sizeof(OpenAPI_pfd_data_t));
13
0
    ogs_assert(pfd_data_local_var);
14
15
0
    pfd_data_local_var->app_ids = app_ids;
16
0
    pfd_data_local_var->af_ids = af_ids;
17
18
0
    return pfd_data_local_var;
19
0
}
20
21
void OpenAPI_pfd_data_free(OpenAPI_pfd_data_t *pfd_data)
22
0
{
23
0
    OpenAPI_lnode_t *node = NULL;
24
25
0
    if (NULL == pfd_data) {
26
0
        return;
27
0
    }
28
0
    if (pfd_data->app_ids) {
29
0
        OpenAPI_list_for_each(pfd_data->app_ids, node) {
30
0
            ogs_free(node->data);
31
0
        }
32
0
        OpenAPI_list_free(pfd_data->app_ids);
33
0
        pfd_data->app_ids = NULL;
34
0
    }
35
0
    if (pfd_data->af_ids) {
36
0
        OpenAPI_list_for_each(pfd_data->af_ids, node) {
37
0
            ogs_free(node->data);
38
0
        }
39
0
        OpenAPI_list_free(pfd_data->af_ids);
40
0
        pfd_data->af_ids = NULL;
41
0
    }
42
0
    ogs_free(pfd_data);
43
0
}
44
45
cJSON *OpenAPI_pfd_data_convertToJSON(OpenAPI_pfd_data_t *pfd_data)
46
0
{
47
0
    cJSON *item = NULL;
48
0
    OpenAPI_lnode_t *node = NULL;
49
50
0
    if (pfd_data == NULL) {
51
0
        ogs_error("OpenAPI_pfd_data_convertToJSON() failed [PfdData]");
52
0
        return NULL;
53
0
    }
54
55
0
    item = cJSON_CreateObject();
56
0
    if (pfd_data->app_ids) {
57
0
    cJSON *app_idsList = cJSON_AddArrayToObject(item, "appIds");
58
0
    if (app_idsList == NULL) {
59
0
        ogs_error("OpenAPI_pfd_data_convertToJSON() failed [app_ids]");
60
0
        goto end;
61
0
    }
62
0
    OpenAPI_list_for_each(pfd_data->app_ids, node) {
63
0
        if (cJSON_AddStringToObject(app_idsList, "", (char*)node->data) == NULL) {
64
0
            ogs_error("OpenAPI_pfd_data_convertToJSON() failed [app_ids]");
65
0
            goto end;
66
0
        }
67
0
    }
68
0
    }
69
70
0
    if (pfd_data->af_ids) {
71
0
    cJSON *af_idsList = cJSON_AddArrayToObject(item, "afIds");
72
0
    if (af_idsList == NULL) {
73
0
        ogs_error("OpenAPI_pfd_data_convertToJSON() failed [af_ids]");
74
0
        goto end;
75
0
    }
76
0
    OpenAPI_list_for_each(pfd_data->af_ids, node) {
77
0
        if (cJSON_AddStringToObject(af_idsList, "", (char*)node->data) == NULL) {
78
0
            ogs_error("OpenAPI_pfd_data_convertToJSON() failed [af_ids]");
79
0
            goto end;
80
0
        }
81
0
    }
82
0
    }
83
84
0
end:
85
0
    return item;
86
0
}
87
88
OpenAPI_pfd_data_t *OpenAPI_pfd_data_parseFromJSON(cJSON *pfd_dataJSON)
89
0
{
90
0
    OpenAPI_pfd_data_t *pfd_data_local_var = NULL;
91
0
    OpenAPI_lnode_t *node = NULL;
92
0
    cJSON *app_ids = NULL;
93
0
    OpenAPI_list_t *app_idsList = NULL;
94
0
    cJSON *af_ids = NULL;
95
0
    OpenAPI_list_t *af_idsList = NULL;
96
0
    app_ids = cJSON_GetObjectItemCaseSensitive(pfd_dataJSON, "appIds");
97
0
    if (app_ids) {
98
0
        cJSON *app_ids_local = NULL;
99
0
        if (!cJSON_IsArray(app_ids)) {
100
0
            ogs_error("OpenAPI_pfd_data_parseFromJSON() failed [app_ids]");
101
0
            goto end;
102
0
        }
103
104
0
        app_idsList = OpenAPI_list_create();
105
106
0
        cJSON_ArrayForEach(app_ids_local, app_ids) {
107
0
            double *localDouble = NULL;
108
0
            int *localInt = NULL;
109
0
            if (!cJSON_IsString(app_ids_local)) {
110
0
                ogs_error("OpenAPI_pfd_data_parseFromJSON() failed [app_ids]");
111
0
                goto end;
112
0
            }
113
0
            OpenAPI_list_add(app_idsList, ogs_strdup(app_ids_local->valuestring));
114
0
        }
115
0
    }
116
117
0
    af_ids = cJSON_GetObjectItemCaseSensitive(pfd_dataJSON, "afIds");
118
0
    if (af_ids) {
119
0
        cJSON *af_ids_local = NULL;
120
0
        if (!cJSON_IsArray(af_ids)) {
121
0
            ogs_error("OpenAPI_pfd_data_parseFromJSON() failed [af_ids]");
122
0
            goto end;
123
0
        }
124
125
0
        af_idsList = OpenAPI_list_create();
126
127
0
        cJSON_ArrayForEach(af_ids_local, af_ids) {
128
0
            double *localDouble = NULL;
129
0
            int *localInt = NULL;
130
0
            if (!cJSON_IsString(af_ids_local)) {
131
0
                ogs_error("OpenAPI_pfd_data_parseFromJSON() failed [af_ids]");
132
0
                goto end;
133
0
            }
134
0
            OpenAPI_list_add(af_idsList, ogs_strdup(af_ids_local->valuestring));
135
0
        }
136
0
    }
137
138
0
    pfd_data_local_var = OpenAPI_pfd_data_create (
139
0
        app_ids ? app_idsList : NULL,
140
0
        af_ids ? af_idsList : NULL
141
0
    );
142
143
0
    return pfd_data_local_var;
144
0
end:
145
0
    if (app_idsList) {
146
0
        OpenAPI_list_for_each(app_idsList, node) {
147
0
            ogs_free(node->data);
148
0
        }
149
0
        OpenAPI_list_free(app_idsList);
150
0
        app_idsList = NULL;
151
0
    }
152
0
    if (af_idsList) {
153
0
        OpenAPI_list_for_each(af_idsList, node) {
154
0
            ogs_free(node->data);
155
0
        }
156
0
        OpenAPI_list_free(af_idsList);
157
0
        af_idsList = NULL;
158
0
    }
159
0
    return NULL;
160
0
}
161
162
OpenAPI_pfd_data_t *OpenAPI_pfd_data_copy(OpenAPI_pfd_data_t *dst, OpenAPI_pfd_data_t *src)
163
0
{
164
0
    cJSON *item = NULL;
165
0
    char *content = NULL;
166
167
0
    ogs_assert(src);
168
0
    item = OpenAPI_pfd_data_convertToJSON(src);
169
0
    if (!item) {
170
0
        ogs_error("OpenAPI_pfd_data_convertToJSON() failed");
171
0
        return NULL;
172
0
    }
173
174
0
    content = cJSON_Print(item);
175
0
    cJSON_Delete(item);
176
177
0
    if (!content) {
178
0
        ogs_error("cJSON_Print() failed");
179
0
        return NULL;
180
0
    }
181
182
0
    item = cJSON_Parse(content);
183
0
    ogs_free(content);
184
0
    if (!item) {
185
0
        ogs_error("cJSON_Parse() failed");
186
0
        return NULL;
187
0
    }
188
189
0
    OpenAPI_pfd_data_free(dst);
190
0
    dst = OpenAPI_pfd_data_parseFromJSON(item);
191
0
    cJSON_Delete(item);
192
193
0
    return dst;
194
0
}
195