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/area.c
Line
Count
Source
1
2
#include <stdlib.h>
3
#include <string.h>
4
#include <stdio.h>
5
#include "area.h"
6
7
OpenAPI_area_t *OpenAPI_area_create(
8
    OpenAPI_list_t *tacs,
9
    char *area_code
10
)
11
3.36k
{
12
3.36k
    OpenAPI_area_t *area_local_var = ogs_malloc(sizeof(OpenAPI_area_t));
13
3.36k
    ogs_assert(area_local_var);
14
15
3.36k
    area_local_var->tacs = tacs;
16
3.36k
    area_local_var->area_code = area_code;
17
18
3.36k
    return area_local_var;
19
3.36k
}
20
21
void OpenAPI_area_free(OpenAPI_area_t *area)
22
3.31k
{
23
3.31k
    OpenAPI_lnode_t *node = NULL;
24
25
3.31k
    if (NULL == area) {
26
0
        return;
27
0
    }
28
3.31k
    if (area->tacs) {
29
920
        OpenAPI_list_for_each(area->tacs, node) {
30
920
            ogs_free(node->data);
31
920
        }
32
583
        OpenAPI_list_free(area->tacs);
33
583
        area->tacs = NULL;
34
583
    }
35
3.31k
    if (area->area_code) {
36
2
        ogs_free(area->area_code);
37
2
        area->area_code = NULL;
38
2
    }
39
3.31k
    ogs_free(area);
40
3.31k
}
41
42
cJSON *OpenAPI_area_convertToJSON(OpenAPI_area_t *area)
43
0
{
44
0
    cJSON *item = NULL;
45
0
    OpenAPI_lnode_t *node = NULL;
46
47
0
    if (area == NULL) {
48
0
        ogs_error("OpenAPI_area_convertToJSON() failed [Area]");
49
0
        return NULL;
50
0
    }
51
52
0
    item = cJSON_CreateObject();
53
0
    if (area->tacs) {
54
0
    cJSON *tacsList = cJSON_AddArrayToObject(item, "tacs");
55
0
    if (tacsList == NULL) {
56
0
        ogs_error("OpenAPI_area_convertToJSON() failed [tacs]");
57
0
        goto end;
58
0
    }
59
0
    OpenAPI_list_for_each(area->tacs, node) {
60
0
        if (cJSON_AddStringToObject(tacsList, "", (char*)node->data) == NULL) {
61
0
            ogs_error("OpenAPI_area_convertToJSON() failed [tacs]");
62
0
            goto end;
63
0
        }
64
0
    }
65
0
    }
66
67
0
    if (area->area_code) {
68
0
    if (cJSON_AddStringToObject(item, "areaCode", area->area_code) == NULL) {
69
0
        ogs_error("OpenAPI_area_convertToJSON() failed [area_code]");
70
0
        goto end;
71
0
    }
72
0
    }
73
74
0
end:
75
0
    return item;
76
0
}
77
78
OpenAPI_area_t *OpenAPI_area_parseFromJSON(cJSON *areaJSON)
79
3.67k
{
80
3.67k
    OpenAPI_area_t *area_local_var = NULL;
81
3.67k
    OpenAPI_lnode_t *node = NULL;
82
3.67k
    cJSON *tacs = NULL;
83
3.67k
    OpenAPI_list_t *tacsList = NULL;
84
3.67k
    cJSON *area_code = NULL;
85
3.67k
    tacs = cJSON_GetObjectItemCaseSensitive(areaJSON, "tacs");
86
3.67k
    if (tacs) {
87
932
        cJSON *tacs_local = NULL;
88
932
        if (!cJSON_IsArray(tacs)) {
89
140
            ogs_error("OpenAPI_area_parseFromJSON() failed [tacs]");
90
140
            goto end;
91
140
        }
92
93
792
        tacsList = OpenAPI_list_create();
94
95
1.55k
        cJSON_ArrayForEach(tacs_local, tacs) {
96
1.55k
            double *localDouble = NULL;
97
1.55k
            int *localInt = NULL;
98
1.55k
            if (!cJSON_IsString(tacs_local)) {
99
173
                ogs_error("OpenAPI_area_parseFromJSON() failed [tacs]");
100
173
                goto end;
101
173
            }
102
1.38k
            OpenAPI_list_add(tacsList, ogs_strdup(tacs_local->valuestring));
103
1.38k
        }
104
792
    }
105
106
3.36k
    area_code = cJSON_GetObjectItemCaseSensitive(areaJSON, "areaCode");
107
3.36k
    if (area_code) {
108
6
    if (!cJSON_IsString(area_code) && !cJSON_IsNull(area_code)) {
109
4
        ogs_error("OpenAPI_area_parseFromJSON() failed [area_code]");
110
4
        goto end;
111
4
    }
112
6
    }
113
114
3.36k
    area_local_var = OpenAPI_area_create (
115
3.36k
        tacs ? tacsList : NULL,
116
3.36k
        area_code && !cJSON_IsNull(area_code) ? ogs_strdup(area_code->valuestring) : NULL
117
3.36k
    );
118
119
3.36k
    return area_local_var;
120
317
end:
121
317
    if (tacsList) {
122
431
        OpenAPI_list_for_each(tacsList, node) {
123
431
            ogs_free(node->data);
124
431
        }
125
176
        OpenAPI_list_free(tacsList);
126
176
        tacsList = NULL;
127
176
    }
128
317
    return NULL;
129
3.36k
}
130
131
OpenAPI_area_t *OpenAPI_area_copy(OpenAPI_area_t *dst, OpenAPI_area_t *src)
132
0
{
133
0
    cJSON *item = NULL;
134
0
    char *content = NULL;
135
136
0
    ogs_assert(src);
137
0
    item = OpenAPI_area_convertToJSON(src);
138
0
    if (!item) {
139
0
        ogs_error("OpenAPI_area_convertToJSON() failed");
140
0
        return NULL;
141
0
    }
142
143
0
    content = cJSON_Print(item);
144
0
    cJSON_Delete(item);
145
146
0
    if (!content) {
147
0
        ogs_error("cJSON_Print() failed");
148
0
        return NULL;
149
0
    }
150
151
0
    item = cJSON_Parse(content);
152
0
    ogs_free(content);
153
0
    if (!item) {
154
0
        ogs_error("cJSON_Parse() failed");
155
0
        return NULL;
156
0
    }
157
158
0
    OpenAPI_area_free(dst);
159
0
    dst = OpenAPI_area_parseFromJSON(item);
160
0
    cJSON_Delete(item);
161
162
0
    return dst;
163
0
}
164