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/ec_restriction.c
Line
Count
Source
1
2
#include <stdlib.h>
3
#include <string.h>
4
#include <stdio.h>
5
#include "ec_restriction.h"
6
7
OpenAPI_ec_restriction_t *OpenAPI_ec_restriction_create(
8
    char *af_instance_id,
9
    int reference_id,
10
    OpenAPI_list_t *plmn_ec_infos,
11
    char *mtc_provider_information
12
)
13
0
{
14
0
    OpenAPI_ec_restriction_t *ec_restriction_local_var = ogs_malloc(sizeof(OpenAPI_ec_restriction_t));
15
0
    ogs_assert(ec_restriction_local_var);
16
17
0
    ec_restriction_local_var->af_instance_id = af_instance_id;
18
0
    ec_restriction_local_var->reference_id = reference_id;
19
0
    ec_restriction_local_var->plmn_ec_infos = plmn_ec_infos;
20
0
    ec_restriction_local_var->mtc_provider_information = mtc_provider_information;
21
22
0
    return ec_restriction_local_var;
23
0
}
24
25
void OpenAPI_ec_restriction_free(OpenAPI_ec_restriction_t *ec_restriction)
26
0
{
27
0
    OpenAPI_lnode_t *node = NULL;
28
29
0
    if (NULL == ec_restriction) {
30
0
        return;
31
0
    }
32
0
    if (ec_restriction->af_instance_id) {
33
0
        ogs_free(ec_restriction->af_instance_id);
34
0
        ec_restriction->af_instance_id = NULL;
35
0
    }
36
0
    if (ec_restriction->plmn_ec_infos) {
37
0
        OpenAPI_list_for_each(ec_restriction->plmn_ec_infos, node) {
38
0
            OpenAPI_plmn_ec_info_free(node->data);
39
0
        }
40
0
        OpenAPI_list_free(ec_restriction->plmn_ec_infos);
41
0
        ec_restriction->plmn_ec_infos = NULL;
42
0
    }
43
0
    if (ec_restriction->mtc_provider_information) {
44
0
        ogs_free(ec_restriction->mtc_provider_information);
45
0
        ec_restriction->mtc_provider_information = NULL;
46
0
    }
47
0
    ogs_free(ec_restriction);
48
0
}
49
50
cJSON *OpenAPI_ec_restriction_convertToJSON(OpenAPI_ec_restriction_t *ec_restriction)
51
0
{
52
0
    cJSON *item = NULL;
53
0
    OpenAPI_lnode_t *node = NULL;
54
55
0
    if (ec_restriction == NULL) {
56
0
        ogs_error("OpenAPI_ec_restriction_convertToJSON() failed [EcRestriction]");
57
0
        return NULL;
58
0
    }
59
60
0
    item = cJSON_CreateObject();
61
0
    if (!ec_restriction->af_instance_id) {
62
0
        ogs_error("OpenAPI_ec_restriction_convertToJSON() failed [af_instance_id]");
63
0
        return NULL;
64
0
    }
65
0
    if (cJSON_AddStringToObject(item, "afInstanceId", ec_restriction->af_instance_id) == NULL) {
66
0
        ogs_error("OpenAPI_ec_restriction_convertToJSON() failed [af_instance_id]");
67
0
        goto end;
68
0
    }
69
70
0
    if (cJSON_AddNumberToObject(item, "referenceId", ec_restriction->reference_id) == NULL) {
71
0
        ogs_error("OpenAPI_ec_restriction_convertToJSON() failed [reference_id]");
72
0
        goto end;
73
0
    }
74
75
0
    if (ec_restriction->plmn_ec_infos) {
76
0
    cJSON *plmn_ec_infosList = cJSON_AddArrayToObject(item, "plmnEcInfos");
77
0
    if (plmn_ec_infosList == NULL) {
78
0
        ogs_error("OpenAPI_ec_restriction_convertToJSON() failed [plmn_ec_infos]");
79
0
        goto end;
80
0
    }
81
0
    OpenAPI_list_for_each(ec_restriction->plmn_ec_infos, node) {
82
0
        cJSON *itemLocal = OpenAPI_plmn_ec_info_convertToJSON(node->data);
83
0
        if (itemLocal == NULL) {
84
0
            ogs_error("OpenAPI_ec_restriction_convertToJSON() failed [plmn_ec_infos]");
85
0
            goto end;
86
0
        }
87
0
        cJSON_AddItemToArray(plmn_ec_infosList, itemLocal);
88
0
    }
89
0
    }
90
91
0
    if (ec_restriction->mtc_provider_information) {
92
0
    if (cJSON_AddStringToObject(item, "mtcProviderInformation", ec_restriction->mtc_provider_information) == NULL) {
93
0
        ogs_error("OpenAPI_ec_restriction_convertToJSON() failed [mtc_provider_information]");
94
0
        goto end;
95
0
    }
96
0
    }
97
98
0
end:
99
0
    return item;
100
0
}
101
102
OpenAPI_ec_restriction_t *OpenAPI_ec_restriction_parseFromJSON(cJSON *ec_restrictionJSON)
103
0
{
104
0
    OpenAPI_ec_restriction_t *ec_restriction_local_var = NULL;
105
0
    OpenAPI_lnode_t *node = NULL;
106
0
    cJSON *af_instance_id = NULL;
107
0
    cJSON *reference_id = NULL;
108
0
    cJSON *plmn_ec_infos = NULL;
109
0
    OpenAPI_list_t *plmn_ec_infosList = NULL;
110
0
    cJSON *mtc_provider_information = NULL;
111
0
    af_instance_id = cJSON_GetObjectItemCaseSensitive(ec_restrictionJSON, "afInstanceId");
112
0
    if (!af_instance_id) {
113
0
        ogs_error("OpenAPI_ec_restriction_parseFromJSON() failed [af_instance_id]");
114
0
        goto end;
115
0
    }
116
0
    if (!cJSON_IsString(af_instance_id)) {
117
0
        ogs_error("OpenAPI_ec_restriction_parseFromJSON() failed [af_instance_id]");
118
0
        goto end;
119
0
    }
120
121
0
    reference_id = cJSON_GetObjectItemCaseSensitive(ec_restrictionJSON, "referenceId");
122
0
    if (!reference_id) {
123
0
        ogs_error("OpenAPI_ec_restriction_parseFromJSON() failed [reference_id]");
124
0
        goto end;
125
0
    }
126
0
    if (!cJSON_IsNumber(reference_id)) {
127
0
        ogs_error("OpenAPI_ec_restriction_parseFromJSON() failed [reference_id]");
128
0
        goto end;
129
0
    }
130
131
0
    plmn_ec_infos = cJSON_GetObjectItemCaseSensitive(ec_restrictionJSON, "plmnEcInfos");
132
0
    if (plmn_ec_infos) {
133
0
        cJSON *plmn_ec_infos_local = NULL;
134
0
        if (!cJSON_IsArray(plmn_ec_infos)) {
135
0
            ogs_error("OpenAPI_ec_restriction_parseFromJSON() failed [plmn_ec_infos]");
136
0
            goto end;
137
0
        }
138
139
0
        plmn_ec_infosList = OpenAPI_list_create();
140
141
0
        cJSON_ArrayForEach(plmn_ec_infos_local, plmn_ec_infos) {
142
0
            if (!cJSON_IsObject(plmn_ec_infos_local)) {
143
0
                ogs_error("OpenAPI_ec_restriction_parseFromJSON() failed [plmn_ec_infos]");
144
0
                goto end;
145
0
            }
146
0
            OpenAPI_plmn_ec_info_t *plmn_ec_infosItem = OpenAPI_plmn_ec_info_parseFromJSON(plmn_ec_infos_local);
147
0
            if (!plmn_ec_infosItem) {
148
0
                ogs_error("No plmn_ec_infosItem");
149
0
                goto end;
150
0
            }
151
0
            OpenAPI_list_add(plmn_ec_infosList, plmn_ec_infosItem);
152
0
        }
153
0
    }
154
155
0
    mtc_provider_information = cJSON_GetObjectItemCaseSensitive(ec_restrictionJSON, "mtcProviderInformation");
156
0
    if (mtc_provider_information) {
157
0
    if (!cJSON_IsString(mtc_provider_information) && !cJSON_IsNull(mtc_provider_information)) {
158
0
        ogs_error("OpenAPI_ec_restriction_parseFromJSON() failed [mtc_provider_information]");
159
0
        goto end;
160
0
    }
161
0
    }
162
163
0
    ec_restriction_local_var = OpenAPI_ec_restriction_create (
164
0
        ogs_strdup(af_instance_id->valuestring),
165
        
166
0
        reference_id->valuedouble,
167
0
        plmn_ec_infos ? plmn_ec_infosList : NULL,
168
0
        mtc_provider_information && !cJSON_IsNull(mtc_provider_information) ? ogs_strdup(mtc_provider_information->valuestring) : NULL
169
0
    );
170
171
0
    return ec_restriction_local_var;
172
0
end:
173
0
    if (plmn_ec_infosList) {
174
0
        OpenAPI_list_for_each(plmn_ec_infosList, node) {
175
0
            OpenAPI_plmn_ec_info_free(node->data);
176
0
        }
177
0
        OpenAPI_list_free(plmn_ec_infosList);
178
0
        plmn_ec_infosList = NULL;
179
0
    }
180
0
    return NULL;
181
0
}
182
183
OpenAPI_ec_restriction_t *OpenAPI_ec_restriction_copy(OpenAPI_ec_restriction_t *dst, OpenAPI_ec_restriction_t *src)
184
0
{
185
0
    cJSON *item = NULL;
186
0
    char *content = NULL;
187
188
0
    ogs_assert(src);
189
0
    item = OpenAPI_ec_restriction_convertToJSON(src);
190
0
    if (!item) {
191
0
        ogs_error("OpenAPI_ec_restriction_convertToJSON() failed");
192
0
        return NULL;
193
0
    }
194
195
0
    content = cJSON_Print(item);
196
0
    cJSON_Delete(item);
197
198
0
    if (!content) {
199
0
        ogs_error("cJSON_Print() failed");
200
0
        return NULL;
201
0
    }
202
203
0
    item = cJSON_Parse(content);
204
0
    ogs_free(content);
205
0
    if (!item) {
206
0
        ogs_error("cJSON_Parse() failed");
207
0
        return NULL;
208
0
    }
209
210
0
    OpenAPI_ec_restriction_free(dst);
211
0
    dst = OpenAPI_ec_restriction_parseFromJSON(item);
212
0
    cJSON_Delete(item);
213
214
0
    return dst;
215
0
}
216