Coverage Report

Created: 2026-08-17 06:12

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/open5gs/lib/sbi/openapi/model/trigger.c
Line
Count
Source
1
2
#include <stdlib.h>
3
#include <string.h>
4
#include <stdio.h>
5
#include "trigger.h"
6
7
OpenAPI_trigger_t *OpenAPI_trigger_create(
8
    OpenAPI_trigger_type_e trigger_type,
9
    OpenAPI_trigger_category_e trigger_category,
10
    bool is_time_limit,
11
    int time_limit,
12
    bool is_volume_limit,
13
    int volume_limit,
14
    bool is_volume_limit64,
15
    int volume_limit64,
16
    bool is_event_limit,
17
    int event_limit,
18
    bool is_max_number_ofccc,
19
    int max_number_ofccc,
20
    char *tariff_time_change
21
)
22
0
{
23
0
    OpenAPI_trigger_t *trigger_local_var = ogs_malloc(sizeof(OpenAPI_trigger_t));
24
0
    ogs_assert(trigger_local_var);
25
26
0
    trigger_local_var->trigger_type = trigger_type;
27
0
    trigger_local_var->trigger_category = trigger_category;
28
0
    trigger_local_var->is_time_limit = is_time_limit;
29
0
    trigger_local_var->time_limit = time_limit;
30
0
    trigger_local_var->is_volume_limit = is_volume_limit;
31
0
    trigger_local_var->volume_limit = volume_limit;
32
0
    trigger_local_var->is_volume_limit64 = is_volume_limit64;
33
0
    trigger_local_var->volume_limit64 = volume_limit64;
34
0
    trigger_local_var->is_event_limit = is_event_limit;
35
0
    trigger_local_var->event_limit = event_limit;
36
0
    trigger_local_var->is_max_number_ofccc = is_max_number_ofccc;
37
0
    trigger_local_var->max_number_ofccc = max_number_ofccc;
38
0
    trigger_local_var->tariff_time_change = tariff_time_change;
39
40
0
    return trigger_local_var;
41
0
}
42
43
void OpenAPI_trigger_free(OpenAPI_trigger_t *trigger)
44
0
{
45
0
    OpenAPI_lnode_t *node = NULL;
46
47
0
    if (NULL == trigger) {
48
0
        return;
49
0
    }
50
0
    if (trigger->tariff_time_change) {
51
0
        ogs_free(trigger->tariff_time_change);
52
0
        trigger->tariff_time_change = NULL;
53
0
    }
54
0
    ogs_free(trigger);
55
0
}
56
57
cJSON *OpenAPI_trigger_convertToJSON(OpenAPI_trigger_t *trigger)
58
0
{
59
0
    cJSON *item = NULL;
60
0
    OpenAPI_lnode_t *node = NULL;
61
62
0
    if (trigger == NULL) {
63
0
        ogs_error("OpenAPI_trigger_convertToJSON() failed [Trigger]");
64
0
        return NULL;
65
0
    }
66
67
0
    item = cJSON_CreateObject();
68
0
    if (trigger->trigger_type != OpenAPI_trigger_type_NULL) {
69
0
    if (cJSON_AddStringToObject(item, "triggerType", OpenAPI_trigger_type_ToString(trigger->trigger_type)) == NULL) {
70
0
        ogs_error("OpenAPI_trigger_convertToJSON() failed [trigger_type]");
71
0
        goto end;
72
0
    }
73
0
    }
74
75
0
    if (trigger->trigger_category == OpenAPI_trigger_category_NULL) {
76
0
        ogs_error("OpenAPI_trigger_convertToJSON() failed [trigger_category]");
77
0
        return NULL;
78
0
    }
79
0
    if (cJSON_AddStringToObject(item, "triggerCategory", OpenAPI_trigger_category_ToString(trigger->trigger_category)) == NULL) {
80
0
        ogs_error("OpenAPI_trigger_convertToJSON() failed [trigger_category]");
81
0
        goto end;
82
0
    }
83
84
0
    if (trigger->is_time_limit) {
85
0
    if (cJSON_AddNumberToObject(item, "timeLimit", trigger->time_limit) == NULL) {
86
0
        ogs_error("OpenAPI_trigger_convertToJSON() failed [time_limit]");
87
0
        goto end;
88
0
    }
89
0
    }
90
91
0
    if (trigger->is_volume_limit) {
92
0
    if (cJSON_AddNumberToObject(item, "volumeLimit", trigger->volume_limit) == NULL) {
93
0
        ogs_error("OpenAPI_trigger_convertToJSON() failed [volume_limit]");
94
0
        goto end;
95
0
    }
96
0
    }
97
98
0
    if (trigger->is_volume_limit64) {
99
0
    if (cJSON_AddNumberToObject(item, "volumeLimit64", trigger->volume_limit64) == NULL) {
100
0
        ogs_error("OpenAPI_trigger_convertToJSON() failed [volume_limit64]");
101
0
        goto end;
102
0
    }
103
0
    }
104
105
0
    if (trigger->is_event_limit) {
106
0
    if (cJSON_AddNumberToObject(item, "eventLimit", trigger->event_limit) == NULL) {
107
0
        ogs_error("OpenAPI_trigger_convertToJSON() failed [event_limit]");
108
0
        goto end;
109
0
    }
110
0
    }
111
112
0
    if (trigger->is_max_number_ofccc) {
113
0
    if (cJSON_AddNumberToObject(item, "maxNumberOfccc", trigger->max_number_ofccc) == NULL) {
114
0
        ogs_error("OpenAPI_trigger_convertToJSON() failed [max_number_ofccc]");
115
0
        goto end;
116
0
    }
117
0
    }
118
119
0
    if (trigger->tariff_time_change) {
120
0
    if (cJSON_AddStringToObject(item, "tariffTimeChange", trigger->tariff_time_change) == NULL) {
121
0
        ogs_error("OpenAPI_trigger_convertToJSON() failed [tariff_time_change]");
122
0
        goto end;
123
0
    }
124
0
    }
125
126
0
end:
127
0
    return item;
128
0
}
129
130
OpenAPI_trigger_t *OpenAPI_trigger_parseFromJSON(cJSON *triggerJSON)
131
0
{
132
0
    OpenAPI_trigger_t *trigger_local_var = NULL;
133
0
    OpenAPI_lnode_t *node = NULL;
134
0
    cJSON *trigger_type = NULL;
135
0
    OpenAPI_trigger_type_e trigger_typeVariable = 0;
136
0
    cJSON *trigger_category = NULL;
137
0
    OpenAPI_trigger_category_e trigger_categoryVariable = 0;
138
0
    cJSON *time_limit = NULL;
139
0
    cJSON *volume_limit = NULL;
140
0
    cJSON *volume_limit64 = NULL;
141
0
    cJSON *event_limit = NULL;
142
0
    cJSON *max_number_ofccc = NULL;
143
0
    cJSON *tariff_time_change = NULL;
144
0
    trigger_type = cJSON_GetObjectItemCaseSensitive(triggerJSON, "triggerType");
145
0
    if (trigger_type) {
146
0
    if (!cJSON_IsString(trigger_type)) {
147
0
        ogs_error("OpenAPI_trigger_parseFromJSON() failed [trigger_type]");
148
0
        goto end;
149
0
    }
150
0
    trigger_typeVariable = OpenAPI_trigger_type_FromString(trigger_type->valuestring);
151
0
    }
152
153
0
    trigger_category = cJSON_GetObjectItemCaseSensitive(triggerJSON, "triggerCategory");
154
0
    if (!trigger_category) {
155
0
        ogs_error("OpenAPI_trigger_parseFromJSON() failed [trigger_category]");
156
0
        goto end;
157
0
    }
158
0
    if (!cJSON_IsString(trigger_category)) {
159
0
        ogs_error("OpenAPI_trigger_parseFromJSON() failed [trigger_category]");
160
0
        goto end;
161
0
    }
162
0
    trigger_categoryVariable = OpenAPI_trigger_category_FromString(trigger_category->valuestring);
163
164
0
    time_limit = cJSON_GetObjectItemCaseSensitive(triggerJSON, "timeLimit");
165
0
    if (time_limit) {
166
0
    if (!cJSON_IsNumber(time_limit)) {
167
0
        ogs_error("OpenAPI_trigger_parseFromJSON() failed [time_limit]");
168
0
        goto end;
169
0
    }
170
0
    }
171
172
0
    volume_limit = cJSON_GetObjectItemCaseSensitive(triggerJSON, "volumeLimit");
173
0
    if (volume_limit) {
174
0
    if (!cJSON_IsNumber(volume_limit)) {
175
0
        ogs_error("OpenAPI_trigger_parseFromJSON() failed [volume_limit]");
176
0
        goto end;
177
0
    }
178
0
    }
179
180
0
    volume_limit64 = cJSON_GetObjectItemCaseSensitive(triggerJSON, "volumeLimit64");
181
0
    if (volume_limit64) {
182
0
    if (!cJSON_IsNumber(volume_limit64)) {
183
0
        ogs_error("OpenAPI_trigger_parseFromJSON() failed [volume_limit64]");
184
0
        goto end;
185
0
    }
186
0
    }
187
188
0
    event_limit = cJSON_GetObjectItemCaseSensitive(triggerJSON, "eventLimit");
189
0
    if (event_limit) {
190
0
    if (!cJSON_IsNumber(event_limit)) {
191
0
        ogs_error("OpenAPI_trigger_parseFromJSON() failed [event_limit]");
192
0
        goto end;
193
0
    }
194
0
    }
195
196
0
    max_number_ofccc = cJSON_GetObjectItemCaseSensitive(triggerJSON, "maxNumberOfccc");
197
0
    if (max_number_ofccc) {
198
0
    if (!cJSON_IsNumber(max_number_ofccc)) {
199
0
        ogs_error("OpenAPI_trigger_parseFromJSON() failed [max_number_ofccc]");
200
0
        goto end;
201
0
    }
202
0
    }
203
204
0
    tariff_time_change = cJSON_GetObjectItemCaseSensitive(triggerJSON, "tariffTimeChange");
205
0
    if (tariff_time_change) {
206
0
    if (!cJSON_IsString(tariff_time_change) && !cJSON_IsNull(tariff_time_change)) {
207
0
        ogs_error("OpenAPI_trigger_parseFromJSON() failed [tariff_time_change]");
208
0
        goto end;
209
0
    }
210
0
    }
211
212
0
    trigger_local_var = OpenAPI_trigger_create (
213
0
        trigger_type ? trigger_typeVariable : 0,
214
0
        trigger_categoryVariable,
215
0
        time_limit ? true : false,
216
0
        time_limit ? time_limit->valuedouble : 0,
217
0
        volume_limit ? true : false,
218
0
        volume_limit ? volume_limit->valuedouble : 0,
219
0
        volume_limit64 ? true : false,
220
0
        volume_limit64 ? volume_limit64->valuedouble : 0,
221
0
        event_limit ? true : false,
222
0
        event_limit ? event_limit->valuedouble : 0,
223
0
        max_number_ofccc ? true : false,
224
0
        max_number_ofccc ? max_number_ofccc->valuedouble : 0,
225
0
        tariff_time_change && !cJSON_IsNull(tariff_time_change) ? ogs_strdup(tariff_time_change->valuestring) : NULL
226
0
    );
227
228
0
    return trigger_local_var;
229
0
end:
230
0
    return NULL;
231
0
}
232
233
OpenAPI_trigger_t *OpenAPI_trigger_copy(OpenAPI_trigger_t *dst, OpenAPI_trigger_t *src)
234
0
{
235
0
    cJSON *item = NULL;
236
0
    char *content = NULL;
237
238
0
    ogs_assert(src);
239
0
    item = OpenAPI_trigger_convertToJSON(src);
240
0
    if (!item) {
241
0
        ogs_error("OpenAPI_trigger_convertToJSON() failed");
242
0
        return NULL;
243
0
    }
244
245
0
    content = cJSON_Print(item);
246
0
    cJSON_Delete(item);
247
248
0
    if (!content) {
249
0
        ogs_error("cJSON_Print() failed");
250
0
        return NULL;
251
0
    }
252
253
0
    item = cJSON_Parse(content);
254
0
    ogs_free(content);
255
0
    if (!item) {
256
0
        ogs_error("cJSON_Parse() failed");
257
0
        return NULL;
258
0
    }
259
260
0
    OpenAPI_trigger_free(dst);
261
0
    dst = OpenAPI_trigger_parseFromJSON(item);
262
0
    cJSON_Delete(item);
263
264
0
    return dst;
265
0
}
266