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