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