Coverage Report

Created: 2026-11-06 06:15

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/open5gs/lib/sbi/openapi/model/cag_data.c
Line
Count
Source
1
2
#include <stdlib.h>
3
#include <string.h>
4
#include <stdio.h>
5
#include "cag_data.h"
6
7
OpenAPI_cag_data_t *OpenAPI_cag_data_create(
8
    OpenAPI_list_t* cag_infos,
9
    OpenAPI_list_t* conditional_cag_infos,
10
    char *provisioning_time
11
)
12
0
{
13
0
    OpenAPI_cag_data_t *cag_data_local_var = ogs_malloc(sizeof(OpenAPI_cag_data_t));
14
0
    ogs_assert(cag_data_local_var);
15
16
0
    cag_data_local_var->cag_infos = cag_infos;
17
0
    cag_data_local_var->conditional_cag_infos = conditional_cag_infos;
18
0
    cag_data_local_var->provisioning_time = provisioning_time;
19
20
0
    return cag_data_local_var;
21
0
}
22
23
void OpenAPI_cag_data_free(OpenAPI_cag_data_t *cag_data)
24
0
{
25
0
    OpenAPI_lnode_t *node = NULL;
26
27
0
    if (NULL == cag_data) {
28
0
        return;
29
0
    }
30
0
    if (cag_data->cag_infos) {
31
0
        OpenAPI_list_for_each(cag_data->cag_infos, node) {
32
0
            OpenAPI_map_t *localKeyValue = (OpenAPI_map_t*)node->data;
33
0
            ogs_free(localKeyValue->key);
34
0
            OpenAPI_cag_info_free(localKeyValue->value);
35
0
            OpenAPI_map_free(localKeyValue);
36
0
        }
37
0
        OpenAPI_list_free(cag_data->cag_infos);
38
0
        cag_data->cag_infos = NULL;
39
0
    }
40
0
    if (cag_data->conditional_cag_infos) {
41
0
        OpenAPI_list_for_each(cag_data->conditional_cag_infos, node) {
42
0
            OpenAPI_map_t *localKeyValue = (OpenAPI_map_t*)node->data;
43
0
            ogs_free(localKeyValue->key);
44
0
            OpenAPI_conditional_cag_info_free(localKeyValue->value);
45
0
            OpenAPI_map_free(localKeyValue);
46
0
        }
47
0
        OpenAPI_list_free(cag_data->conditional_cag_infos);
48
0
        cag_data->conditional_cag_infos = NULL;
49
0
    }
50
0
    if (cag_data->provisioning_time) {
51
0
        ogs_free(cag_data->provisioning_time);
52
0
        cag_data->provisioning_time = NULL;
53
0
    }
54
0
    ogs_free(cag_data);
55
0
}
56
57
cJSON *OpenAPI_cag_data_convertToJSON(OpenAPI_cag_data_t *cag_data)
58
0
{
59
0
    cJSON *item = NULL;
60
0
    OpenAPI_lnode_t *node = NULL;
61
62
0
    if (cag_data == NULL) {
63
0
        ogs_error("OpenAPI_cag_data_convertToJSON() failed [CagData]");
64
0
        return NULL;
65
0
    }
66
67
0
    item = cJSON_CreateObject();
68
0
    if (!cag_data->cag_infos) {
69
0
        ogs_error("OpenAPI_cag_data_convertToJSON() failed [cag_infos]");
70
0
        return NULL;
71
0
    }
72
0
    cJSON *cag_infos = cJSON_AddObjectToObject(item, "cagInfos");
73
0
    if (cag_infos == NULL) {
74
0
        ogs_error("OpenAPI_cag_data_convertToJSON() failed [cag_infos]");
75
0
        goto end;
76
0
    }
77
0
    cJSON *localMapObject = cag_infos;
78
0
    if (cag_data->cag_infos) {
79
0
        OpenAPI_list_for_each(cag_data->cag_infos, node) {
80
0
            OpenAPI_map_t *localKeyValue = (OpenAPI_map_t*)node->data;
81
0
            if (localKeyValue == NULL) {
82
0
                ogs_error("OpenAPI_cag_data_convertToJSON() failed [cag_infos]");
83
0
                goto end;
84
0
            }
85
0
            if (localKeyValue->key == NULL) {
86
0
                ogs_error("OpenAPI_cag_data_convertToJSON() failed [cag_infos]");
87
0
                goto end;
88
0
            }
89
0
            cJSON *itemLocal = localKeyValue->value ?
90
0
                OpenAPI_cag_info_convertToJSON(localKeyValue->value) :
91
0
                cJSON_CreateNull();
92
0
            if (itemLocal == NULL) {
93
0
                ogs_error("OpenAPI_cag_data_convertToJSON() failed [inner]");
94
0
                goto end;
95
0
            }
96
0
            cJSON_AddItemToObject(localMapObject, localKeyValue->key, itemLocal);
97
0
        }
98
0
    }
99
100
0
    if (cag_data->conditional_cag_infos) {
101
0
    cJSON *conditional_cag_infos = cJSON_AddObjectToObject(item, "conditionalCagInfos");
102
0
    if (conditional_cag_infos == NULL) {
103
0
        ogs_error("OpenAPI_cag_data_convertToJSON() failed [conditional_cag_infos]");
104
0
        goto end;
105
0
    }
106
0
    cJSON *localMapObject = conditional_cag_infos;
107
0
    if (cag_data->conditional_cag_infos) {
108
0
        OpenAPI_list_for_each(cag_data->conditional_cag_infos, node) {
109
0
            OpenAPI_map_t *localKeyValue = (OpenAPI_map_t*)node->data;
110
0
            if (localKeyValue == NULL) {
111
0
                ogs_error("OpenAPI_cag_data_convertToJSON() failed [conditional_cag_infos]");
112
0
                goto end;
113
0
            }
114
0
            if (localKeyValue->key == NULL) {
115
0
                ogs_error("OpenAPI_cag_data_convertToJSON() failed [conditional_cag_infos]");
116
0
                goto end;
117
0
            }
118
0
            cJSON *itemLocal = localKeyValue->value ?
119
0
                OpenAPI_conditional_cag_info_convertToJSON(localKeyValue->value) :
120
0
                cJSON_CreateNull();
121
0
            if (itemLocal == NULL) {
122
0
                ogs_error("OpenAPI_cag_data_convertToJSON() failed [inner]");
123
0
                goto end;
124
0
            }
125
0
            cJSON_AddItemToObject(localMapObject, localKeyValue->key, itemLocal);
126
0
        }
127
0
    }
128
0
    }
129
130
0
    if (cag_data->provisioning_time) {
131
0
    if (cJSON_AddStringToObject(item, "provisioningTime", cag_data->provisioning_time) == NULL) {
132
0
        ogs_error("OpenAPI_cag_data_convertToJSON() failed [provisioning_time]");
133
0
        goto end;
134
0
    }
135
0
    }
136
137
0
end:
138
0
    return item;
139
0
}
140
141
OpenAPI_cag_data_t *OpenAPI_cag_data_parseFromJSON(cJSON *cag_dataJSON)
142
4
{
143
4
    OpenAPI_cag_data_t *cag_data_local_var = NULL;
144
4
    OpenAPI_lnode_t *node = NULL;
145
4
    cJSON *cag_infos = NULL;
146
4
    OpenAPI_list_t *cag_infosList = NULL;
147
4
    cJSON *conditional_cag_infos = NULL;
148
4
    OpenAPI_list_t *conditional_cag_infosList = NULL;
149
4
    cJSON *provisioning_time = NULL;
150
4
    cag_infos = cJSON_GetObjectItemCaseSensitive(cag_dataJSON, "cagInfos");
151
4
    if (!cag_infos) {
152
4
        ogs_error("OpenAPI_cag_data_parseFromJSON() failed [cag_infos]");
153
4
        goto end;
154
4
    }
155
0
        cJSON *cag_infos_local_map = NULL;
156
0
        if (!cJSON_IsObject(cag_infos) && !cJSON_IsNull(cag_infos)) {
157
0
            ogs_error("OpenAPI_cag_data_parseFromJSON() failed [cag_infos]");
158
0
            goto end;
159
0
        }
160
0
        if (cJSON_IsObject(cag_infos)) {
161
0
            cag_infosList = OpenAPI_list_create();
162
0
            OpenAPI_map_t *localMapKeyPair = NULL;
163
0
            cJSON_ArrayForEach(cag_infos_local_map, cag_infos) {
164
0
                cJSON *localMapObject = cag_infos_local_map;
165
0
                if (cJSON_IsObject(localMapObject)) {
166
0
                    localMapKeyPair = OpenAPI_map_create(
167
0
                        ogs_strdup(localMapObject->string), OpenAPI_cag_info_parseFromJSON(localMapObject));
168
0
                } else if (cJSON_IsNull(localMapObject)) {
169
0
                    localMapKeyPair = OpenAPI_map_create(ogs_strdup(localMapObject->string), NULL);
170
0
                } else {
171
0
                    ogs_error("OpenAPI_cag_data_parseFromJSON() failed [inner]");
172
0
                    goto end;
173
0
                }
174
0
                if (localMapKeyPair == NULL) {
175
0
                    ogs_error("OpenAPI_cag_data_parseFromJSON() failed [cag_infos]");
176
0
                    goto end;
177
0
                }
178
0
                OpenAPI_list_add(cag_infosList, localMapKeyPair);
179
0
            }
180
0
        }
181
182
0
    conditional_cag_infos = cJSON_GetObjectItemCaseSensitive(cag_dataJSON, "conditionalCagInfos");
183
0
    if (conditional_cag_infos) {
184
0
        cJSON *conditional_cag_infos_local_map = NULL;
185
0
        if (!cJSON_IsObject(conditional_cag_infos) && !cJSON_IsNull(conditional_cag_infos)) {
186
0
            ogs_error("OpenAPI_cag_data_parseFromJSON() failed [conditional_cag_infos]");
187
0
            goto end;
188
0
        }
189
0
        if (cJSON_IsObject(conditional_cag_infos)) {
190
0
            conditional_cag_infosList = OpenAPI_list_create();
191
0
            OpenAPI_map_t *localMapKeyPair = NULL;
192
0
            cJSON_ArrayForEach(conditional_cag_infos_local_map, conditional_cag_infos) {
193
0
                cJSON *localMapObject = conditional_cag_infos_local_map;
194
0
                if (cJSON_IsObject(localMapObject)) {
195
0
                    localMapKeyPair = OpenAPI_map_create(
196
0
                        ogs_strdup(localMapObject->string), OpenAPI_conditional_cag_info_parseFromJSON(localMapObject));
197
0
                } else if (cJSON_IsNull(localMapObject)) {
198
0
                    localMapKeyPair = OpenAPI_map_create(ogs_strdup(localMapObject->string), NULL);
199
0
                } else {
200
0
                    ogs_error("OpenAPI_cag_data_parseFromJSON() failed [inner]");
201
0
                    goto end;
202
0
                }
203
0
                if (localMapKeyPair == NULL) {
204
0
                    ogs_error("OpenAPI_cag_data_parseFromJSON() failed [conditional_cag_infos]");
205
0
                    goto end;
206
0
                }
207
0
                OpenAPI_list_add(conditional_cag_infosList, localMapKeyPair);
208
0
            }
209
0
        }
210
0
    }
211
212
0
    provisioning_time = cJSON_GetObjectItemCaseSensitive(cag_dataJSON, "provisioningTime");
213
0
    if (provisioning_time) {
214
0
    if (!cJSON_IsString(provisioning_time) && !cJSON_IsNull(provisioning_time)) {
215
0
        ogs_error("OpenAPI_cag_data_parseFromJSON() failed [provisioning_time]");
216
0
        goto end;
217
0
    }
218
0
    }
219
220
0
    cag_data_local_var = OpenAPI_cag_data_create (
221
0
        cag_infosList,
222
0
        conditional_cag_infos ? conditional_cag_infosList : NULL,
223
0
        provisioning_time && !cJSON_IsNull(provisioning_time) ? ogs_strdup(provisioning_time->valuestring) : NULL
224
0
    );
225
226
0
    return cag_data_local_var;
227
4
end:
228
4
    if (cag_infosList) {
229
0
        OpenAPI_list_for_each(cag_infosList, node) {
230
0
            OpenAPI_map_t *localKeyValue = (OpenAPI_map_t*)node->data;
231
0
            ogs_free(localKeyValue->key);
232
0
            OpenAPI_cag_info_free(localKeyValue->value);
233
0
            OpenAPI_map_free(localKeyValue);
234
0
        }
235
0
        OpenAPI_list_free(cag_infosList);
236
0
        cag_infosList = NULL;
237
0
    }
238
4
    if (conditional_cag_infosList) {
239
0
        OpenAPI_list_for_each(conditional_cag_infosList, node) {
240
0
            OpenAPI_map_t *localKeyValue = (OpenAPI_map_t*)node->data;
241
0
            ogs_free(localKeyValue->key);
242
0
            OpenAPI_conditional_cag_info_free(localKeyValue->value);
243
0
            OpenAPI_map_free(localKeyValue);
244
0
        }
245
0
        OpenAPI_list_free(conditional_cag_infosList);
246
0
        conditional_cag_infosList = NULL;
247
0
    }
248
4
    return NULL;
249
0
}
250
251
OpenAPI_cag_data_t *OpenAPI_cag_data_copy(OpenAPI_cag_data_t *dst, OpenAPI_cag_data_t *src)
252
0
{
253
0
    cJSON *item = NULL;
254
0
    char *content = NULL;
255
256
0
    ogs_assert(src);
257
0
    item = OpenAPI_cag_data_convertToJSON(src);
258
0
    if (!item) {
259
0
        ogs_error("OpenAPI_cag_data_convertToJSON() failed");
260
0
        return NULL;
261
0
    }
262
263
0
    content = cJSON_Print(item);
264
0
    cJSON_Delete(item);
265
266
0
    if (!content) {
267
0
        ogs_error("cJSON_Print() failed");
268
0
        return NULL;
269
0
    }
270
271
0
    item = cJSON_Parse(content);
272
0
    ogs_free(content);
273
0
    if (!item) {
274
0
        ogs_error("cJSON_Parse() failed");
275
0
        return NULL;
276
0
    }
277
278
0
    OpenAPI_cag_data_free(dst);
279
0
    dst = OpenAPI_cag_data_parseFromJSON(item);
280
0
    cJSON_Delete(item);
281
282
0
    return dst;
283
0
}
284