/src/open5gs/lib/sbi/openapi/model/ranking_criterion.c
Line | Count | Source |
1 | | |
2 | | #include <stdlib.h> |
3 | | #include <string.h> |
4 | | #include <stdio.h> |
5 | | #include "ranking_criterion.h" |
6 | | |
7 | | OpenAPI_ranking_criterion_t *OpenAPI_ranking_criterion_create( |
8 | | int high_base, |
9 | | int low_base |
10 | | ) |
11 | 0 | { |
12 | 0 | OpenAPI_ranking_criterion_t *ranking_criterion_local_var = ogs_malloc(sizeof(OpenAPI_ranking_criterion_t)); |
13 | 0 | ogs_assert(ranking_criterion_local_var); |
14 | | |
15 | 0 | ranking_criterion_local_var->high_base = high_base; |
16 | 0 | ranking_criterion_local_var->low_base = low_base; |
17 | |
|
18 | 0 | return ranking_criterion_local_var; |
19 | 0 | } |
20 | | |
21 | | void OpenAPI_ranking_criterion_free(OpenAPI_ranking_criterion_t *ranking_criterion) |
22 | 0 | { |
23 | 0 | OpenAPI_lnode_t *node = NULL; |
24 | |
|
25 | 0 | if (NULL == ranking_criterion) { |
26 | 0 | return; |
27 | 0 | } |
28 | 0 | ogs_free(ranking_criterion); |
29 | 0 | } |
30 | | |
31 | | cJSON *OpenAPI_ranking_criterion_convertToJSON(OpenAPI_ranking_criterion_t *ranking_criterion) |
32 | 0 | { |
33 | 0 | cJSON *item = NULL; |
34 | 0 | OpenAPI_lnode_t *node = NULL; |
35 | |
|
36 | 0 | if (ranking_criterion == NULL) { |
37 | 0 | ogs_error("OpenAPI_ranking_criterion_convertToJSON() failed [RankingCriterion]"); |
38 | 0 | return NULL; |
39 | 0 | } |
40 | | |
41 | 0 | item = cJSON_CreateObject(); |
42 | 0 | if (cJSON_AddNumberToObject(item, "highBase", ranking_criterion->high_base) == NULL) { |
43 | 0 | ogs_error("OpenAPI_ranking_criterion_convertToJSON() failed [high_base]"); |
44 | 0 | goto end; |
45 | 0 | } |
46 | | |
47 | 0 | if (cJSON_AddNumberToObject(item, "lowBase", ranking_criterion->low_base) == NULL) { |
48 | 0 | ogs_error("OpenAPI_ranking_criterion_convertToJSON() failed [low_base]"); |
49 | 0 | goto end; |
50 | 0 | } |
51 | | |
52 | 0 | end: |
53 | 0 | return item; |
54 | 0 | } |
55 | | |
56 | | OpenAPI_ranking_criterion_t *OpenAPI_ranking_criterion_parseFromJSON(cJSON *ranking_criterionJSON) |
57 | 0 | { |
58 | 0 | OpenAPI_ranking_criterion_t *ranking_criterion_local_var = NULL; |
59 | 0 | OpenAPI_lnode_t *node = NULL; |
60 | 0 | cJSON *high_base = NULL; |
61 | 0 | cJSON *low_base = NULL; |
62 | 0 | high_base = cJSON_GetObjectItemCaseSensitive(ranking_criterionJSON, "highBase"); |
63 | 0 | if (!high_base) { |
64 | 0 | ogs_error("OpenAPI_ranking_criterion_parseFromJSON() failed [high_base]"); |
65 | 0 | goto end; |
66 | 0 | } |
67 | 0 | if (!cJSON_IsNumber(high_base)) { |
68 | 0 | ogs_error("OpenAPI_ranking_criterion_parseFromJSON() failed [high_base]"); |
69 | 0 | goto end; |
70 | 0 | } |
71 | | |
72 | 0 | low_base = cJSON_GetObjectItemCaseSensitive(ranking_criterionJSON, "lowBase"); |
73 | 0 | if (!low_base) { |
74 | 0 | ogs_error("OpenAPI_ranking_criterion_parseFromJSON() failed [low_base]"); |
75 | 0 | goto end; |
76 | 0 | } |
77 | 0 | if (!cJSON_IsNumber(low_base)) { |
78 | 0 | ogs_error("OpenAPI_ranking_criterion_parseFromJSON() failed [low_base]"); |
79 | 0 | goto end; |
80 | 0 | } |
81 | | |
82 | 0 | ranking_criterion_local_var = OpenAPI_ranking_criterion_create ( |
83 | | |
84 | 0 | high_base->valuedouble, |
85 | | |
86 | 0 | low_base->valuedouble |
87 | 0 | ); |
88 | |
|
89 | 0 | return ranking_criterion_local_var; |
90 | 0 | end: |
91 | 0 | return NULL; |
92 | 0 | } |
93 | | |
94 | | OpenAPI_ranking_criterion_t *OpenAPI_ranking_criterion_copy(OpenAPI_ranking_criterion_t *dst, OpenAPI_ranking_criterion_t *src) |
95 | 0 | { |
96 | 0 | cJSON *item = NULL; |
97 | 0 | char *content = NULL; |
98 | |
|
99 | 0 | ogs_assert(src); |
100 | 0 | item = OpenAPI_ranking_criterion_convertToJSON(src); |
101 | 0 | if (!item) { |
102 | 0 | ogs_error("OpenAPI_ranking_criterion_convertToJSON() failed"); |
103 | 0 | return NULL; |
104 | 0 | } |
105 | | |
106 | 0 | content = cJSON_Print(item); |
107 | 0 | cJSON_Delete(item); |
108 | |
|
109 | 0 | if (!content) { |
110 | 0 | ogs_error("cJSON_Print() failed"); |
111 | 0 | return NULL; |
112 | 0 | } |
113 | | |
114 | 0 | item = cJSON_Parse(content); |
115 | 0 | ogs_free(content); |
116 | 0 | if (!item) { |
117 | 0 | ogs_error("cJSON_Parse() failed"); |
118 | 0 | return NULL; |
119 | 0 | } |
120 | | |
121 | 0 | OpenAPI_ranking_criterion_free(dst); |
122 | 0 | dst = OpenAPI_ranking_criterion_parseFromJSON(item); |
123 | 0 | cJSON_Delete(item); |
124 | |
|
125 | 0 | return dst; |
126 | 0 | } |
127 | | |