Coverage Report

Created: 2026-08-14 06:04

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/open5gs/lib/sbi/openapi/model/ambr.c
Line
Count
Source
1
2
#include <stdlib.h>
3
#include <string.h>
4
#include <stdio.h>
5
#include "ambr.h"
6
7
OpenAPI_ambr_t *OpenAPI_ambr_create(
8
    char *uplink,
9
    char *downlink
10
)
11
0
{
12
0
    OpenAPI_ambr_t *ambr_local_var = ogs_malloc(sizeof(OpenAPI_ambr_t));
13
0
    ogs_assert(ambr_local_var);
14
15
0
    ambr_local_var->uplink = uplink;
16
0
    ambr_local_var->downlink = downlink;
17
18
0
    return ambr_local_var;
19
0
}
20
21
void OpenAPI_ambr_free(OpenAPI_ambr_t *ambr)
22
0
{
23
0
    OpenAPI_lnode_t *node = NULL;
24
25
0
    if (NULL == ambr) {
26
0
        return;
27
0
    }
28
0
    if (ambr->uplink) {
29
0
        ogs_free(ambr->uplink);
30
0
        ambr->uplink = NULL;
31
0
    }
32
0
    if (ambr->downlink) {
33
0
        ogs_free(ambr->downlink);
34
0
        ambr->downlink = NULL;
35
0
    }
36
0
    ogs_free(ambr);
37
0
}
38
39
cJSON *OpenAPI_ambr_convertToJSON(OpenAPI_ambr_t *ambr)
40
0
{
41
0
    cJSON *item = NULL;
42
0
    OpenAPI_lnode_t *node = NULL;
43
44
0
    if (ambr == NULL) {
45
0
        ogs_error("OpenAPI_ambr_convertToJSON() failed [Ambr]");
46
0
        return NULL;
47
0
    }
48
49
0
    item = cJSON_CreateObject();
50
0
    if (!ambr->uplink) {
51
0
        ogs_error("OpenAPI_ambr_convertToJSON() failed [uplink]");
52
0
        return NULL;
53
0
    }
54
0
    if (cJSON_AddStringToObject(item, "uplink", ambr->uplink) == NULL) {
55
0
        ogs_error("OpenAPI_ambr_convertToJSON() failed [uplink]");
56
0
        goto end;
57
0
    }
58
59
0
    if (!ambr->downlink) {
60
0
        ogs_error("OpenAPI_ambr_convertToJSON() failed [downlink]");
61
0
        return NULL;
62
0
    }
63
0
    if (cJSON_AddStringToObject(item, "downlink", ambr->downlink) == NULL) {
64
0
        ogs_error("OpenAPI_ambr_convertToJSON() failed [downlink]");
65
0
        goto end;
66
0
    }
67
68
0
end:
69
0
    return item;
70
0
}
71
72
OpenAPI_ambr_t *OpenAPI_ambr_parseFromJSON(cJSON *ambrJSON)
73
0
{
74
0
    OpenAPI_ambr_t *ambr_local_var = NULL;
75
0
    OpenAPI_lnode_t *node = NULL;
76
0
    cJSON *uplink = NULL;
77
0
    cJSON *downlink = NULL;
78
0
    uplink = cJSON_GetObjectItemCaseSensitive(ambrJSON, "uplink");
79
0
    if (!uplink) {
80
0
        ogs_error("OpenAPI_ambr_parseFromJSON() failed [uplink]");
81
0
        goto end;
82
0
    }
83
0
    if (!cJSON_IsString(uplink)) {
84
0
        ogs_error("OpenAPI_ambr_parseFromJSON() failed [uplink]");
85
0
        goto end;
86
0
    }
87
88
0
    downlink = cJSON_GetObjectItemCaseSensitive(ambrJSON, "downlink");
89
0
    if (!downlink) {
90
0
        ogs_error("OpenAPI_ambr_parseFromJSON() failed [downlink]");
91
0
        goto end;
92
0
    }
93
0
    if (!cJSON_IsString(downlink)) {
94
0
        ogs_error("OpenAPI_ambr_parseFromJSON() failed [downlink]");
95
0
        goto end;
96
0
    }
97
98
0
    ambr_local_var = OpenAPI_ambr_create (
99
0
        ogs_strdup(uplink->valuestring),
100
0
        ogs_strdup(downlink->valuestring)
101
0
    );
102
103
0
    return ambr_local_var;
104
0
end:
105
0
    return NULL;
106
0
}
107
108
OpenAPI_ambr_t *OpenAPI_ambr_copy(OpenAPI_ambr_t *dst, OpenAPI_ambr_t *src)
109
0
{
110
0
    cJSON *item = NULL;
111
0
    char *content = NULL;
112
113
0
    ogs_assert(src);
114
0
    item = OpenAPI_ambr_convertToJSON(src);
115
0
    if (!item) {
116
0
        ogs_error("OpenAPI_ambr_convertToJSON() failed");
117
0
        return NULL;
118
0
    }
119
120
0
    content = cJSON_Print(item);
121
0
    cJSON_Delete(item);
122
123
0
    if (!content) {
124
0
        ogs_error("cJSON_Print() failed");
125
0
        return NULL;
126
0
    }
127
128
0
    item = cJSON_Parse(content);
129
0
    ogs_free(content);
130
0
    if (!item) {
131
0
        ogs_error("cJSON_Parse() failed");
132
0
        return NULL;
133
0
    }
134
135
0
    OpenAPI_ambr_free(dst);
136
0
    dst = OpenAPI_ambr_parseFromJSON(item);
137
0
    cJSON_Delete(item);
138
139
0
    return dst;
140
0
}
141