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