diff options
author | ng0 <ng0@n0.is> | 2019-09-08 12:33:09 +0000 |
---|---|---|
committer | ng0 <ng0@n0.is> | 2019-09-08 12:33:09 +0000 |
commit | d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb (patch) | |
tree | 9efd18ea7d425652085ed0bd5e8e45604bc5f6b9 /src/reclaim/json_reclaim.c | |
parent | a0fce305c565c0937d917a92712f15e9c5736260 (diff) | |
download | gnunet-d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb.tar.gz gnunet-d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb.zip |
uncrustify as demanded.
Diffstat (limited to 'src/reclaim/json_reclaim.c')
-rw-r--r-- | src/reclaim/json_reclaim.c | 244 |
1 files changed, 124 insertions, 120 deletions
diff --git a/src/reclaim/json_reclaim.c b/src/reclaim/json_reclaim.c index 557caafe2..a98dec717 100644 --- a/src/reclaim/json_reclaim.c +++ b/src/reclaim/json_reclaim.c | |||
@@ -16,7 +16,7 @@ | |||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file rest-plugins/json_reclaim.c | 22 | * @file rest-plugins/json_reclaim.c |
@@ -41,7 +41,7 @@ | |||
41 | * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error | 41 | * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error |
42 | */ | 42 | */ |
43 | static int | 43 | static int |
44 | parse_attr (void *cls, json_t *root, struct GNUNET_JSON_Specification *spec) | 44 | parse_attr(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec) |
45 | { | 45 | { |
46 | struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr; | 46 | struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr; |
47 | const char *name_str = NULL; | 47 | const char *name_str = NULL; |
@@ -53,52 +53,52 @@ parse_attr (void *cls, json_t *root, struct GNUNET_JSON_Specification *spec) | |||
53 | uint32_t type; | 53 | uint32_t type; |
54 | size_t data_size; | 54 | size_t data_size; |
55 | 55 | ||
56 | GNUNET_assert (NULL != root); | 56 | GNUNET_assert(NULL != root); |
57 | 57 | ||
58 | if (! json_is_object (root)) | 58 | if (!json_is_object(root)) |
59 | { | 59 | { |
60 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 60 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
61 | "Error json is not array nor object!\n"); | 61 | "Error json is not array nor object!\n"); |
62 | return GNUNET_SYSERR; | 62 | return GNUNET_SYSERR; |
63 | } | 63 | } |
64 | // interpret single attribute | 64 | // interpret single attribute |
65 | unpack_state = json_unpack (root, | 65 | unpack_state = json_unpack(root, |
66 | "{s:s, s?s, s:s, s:s!}", | 66 | "{s:s, s?s, s:s, s:s!}", |
67 | "name", | 67 | "name", |
68 | &name_str, | 68 | &name_str, |
69 | "id", | 69 | "id", |
70 | &id_str, | 70 | &id_str, |
71 | "type", | 71 | "type", |
72 | &type_str, | 72 | &type_str, |
73 | "value", | 73 | "value", |
74 | &val_str); | 74 | &val_str); |
75 | if ((0 != unpack_state) || (NULL == name_str) || (NULL == val_str) || | 75 | if ((0 != unpack_state) || (NULL == name_str) || (NULL == val_str) || |
76 | (NULL == type_str)) | 76 | (NULL == type_str)) |
77 | { | 77 | { |
78 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 78 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
79 | "Error json object has a wrong format!\n"); | 79 | "Error json object has a wrong format!\n"); |
80 | return GNUNET_SYSERR; | 80 | return GNUNET_SYSERR; |
81 | } | 81 | } |
82 | type = GNUNET_RECLAIM_ATTRIBUTE_typename_to_number (type_str); | 82 | type = GNUNET_RECLAIM_ATTRIBUTE_typename_to_number(type_str); |
83 | if (GNUNET_SYSERR == | 83 | if (GNUNET_SYSERR == |
84 | (GNUNET_RECLAIM_ATTRIBUTE_string_to_value (type, | 84 | (GNUNET_RECLAIM_ATTRIBUTE_string_to_value(type, |
85 | val_str, | 85 | val_str, |
86 | (void **) &data, | 86 | (void **)&data, |
87 | &data_size))) | 87 | &data_size))) |
88 | { | 88 | { |
89 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Attribute value invalid!\n"); | 89 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Attribute value invalid!\n"); |
90 | return GNUNET_SYSERR; | 90 | return GNUNET_SYSERR; |
91 | } | 91 | } |
92 | attr = GNUNET_RECLAIM_ATTRIBUTE_claim_new (name_str, type, data, data_size); | 92 | attr = GNUNET_RECLAIM_ATTRIBUTE_claim_new(name_str, type, data, data_size); |
93 | if ((NULL == id_str) || (0 == strlen (id_str))) | 93 | if ((NULL == id_str) || (0 == strlen(id_str))) |
94 | attr->id = 0; | 94 | attr->id = 0; |
95 | else | 95 | else |
96 | GNUNET_STRINGS_string_to_data (id_str, | 96 | GNUNET_STRINGS_string_to_data(id_str, |
97 | strlen (id_str), | 97 | strlen(id_str), |
98 | &attr->id, | 98 | &attr->id, |
99 | sizeof (uint64_t)); | 99 | sizeof(uint64_t)); |
100 | 100 | ||
101 | *(struct GNUNET_RECLAIM_ATTRIBUTE_Claim **) spec->ptr = attr; | 101 | *(struct GNUNET_RECLAIM_ATTRIBUTE_Claim **)spec->ptr = attr; |
102 | return GNUNET_OK; | 102 | return GNUNET_OK; |
103 | } | 103 | } |
104 | 104 | ||
@@ -109,15 +109,16 @@ parse_attr (void *cls, json_t *root, struct GNUNET_JSON_Specification *spec) | |||
109 | * @param[out] spec where to free the data | 109 | * @param[out] spec where to free the data |
110 | */ | 110 | */ |
111 | static void | 111 | static void |
112 | clean_attr (void *cls, struct GNUNET_JSON_Specification *spec) | 112 | clean_attr(void *cls, struct GNUNET_JSON_Specification *spec) |
113 | { | 113 | { |
114 | struct GNUNET_RECLAIM_ATTRIBUTE_Claim **attr; | 114 | struct GNUNET_RECLAIM_ATTRIBUTE_Claim **attr; |
115 | attr = (struct GNUNET_RECLAIM_ATTRIBUTE_Claim **) spec->ptr; | 115 | |
116 | attr = (struct GNUNET_RECLAIM_ATTRIBUTE_Claim **)spec->ptr; | ||
116 | if (NULL != *attr) | 117 | if (NULL != *attr) |
117 | { | 118 | { |
118 | GNUNET_free (*attr); | 119 | GNUNET_free(*attr); |
119 | *attr = NULL; | 120 | *attr = NULL; |
120 | } | 121 | } |
121 | } | 122 | } |
122 | 123 | ||
123 | /** | 124 | /** |
@@ -127,15 +128,16 @@ clean_attr (void *cls, struct GNUNET_JSON_Specification *spec) | |||
127 | * @return JSON Specification | 128 | * @return JSON Specification |
128 | */ | 129 | */ |
129 | struct GNUNET_JSON_Specification | 130 | struct GNUNET_JSON_Specification |
130 | GNUNET_RECLAIM_JSON_spec_claim (struct GNUNET_RECLAIM_ATTRIBUTE_Claim **attr) | 131 | GNUNET_RECLAIM_JSON_spec_claim(struct GNUNET_RECLAIM_ATTRIBUTE_Claim **attr) |
131 | { | 132 | { |
132 | struct GNUNET_JSON_Specification ret = {.parser = &parse_attr, | 133 | struct GNUNET_JSON_Specification ret = { .parser = &parse_attr, |
133 | .cleaner = &clean_attr, | 134 | .cleaner = &clean_attr, |
134 | .cls = NULL, | 135 | .cls = NULL, |
135 | .field = NULL, | 136 | .field = NULL, |
136 | .ptr = attr, | 137 | .ptr = attr, |
137 | .ptr_size = 0, | 138 | .ptr_size = 0, |
138 | .size_ptr = NULL}; | 139 | .size_ptr = NULL }; |
140 | |||
139 | *attr = NULL; | 141 | *attr = NULL; |
140 | return ret; | 142 | return ret; |
141 | } | 143 | } |
@@ -148,7 +150,7 @@ GNUNET_RECLAIM_JSON_spec_claim (struct GNUNET_RECLAIM_ATTRIBUTE_Claim **attr) | |||
148 | * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error | 150 | * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error |
149 | */ | 151 | */ |
150 | static int | 152 | static int |
151 | parse_ticket (void *cls, json_t *root, struct GNUNET_JSON_Specification *spec) | 153 | parse_ticket(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec) |
152 | { | 154 | { |
153 | struct GNUNET_RECLAIM_Ticket *ticket; | 155 | struct GNUNET_RECLAIM_Ticket *ticket; |
154 | const char *rnd_str; | 156 | const char *rnd_str; |
@@ -156,63 +158,63 @@ parse_ticket (void *cls, json_t *root, struct GNUNET_JSON_Specification *spec) | |||
156 | const char *id_str; | 158 | const char *id_str; |
157 | int unpack_state; | 159 | int unpack_state; |
158 | 160 | ||
159 | GNUNET_assert (NULL != root); | 161 | GNUNET_assert(NULL != root); |
160 | 162 | ||
161 | if (! json_is_object (root)) | 163 | if (!json_is_object(root)) |
162 | { | 164 | { |
163 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 165 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
164 | "Error json is not array nor object!\n"); | 166 | "Error json is not array nor object!\n"); |
165 | return GNUNET_SYSERR; | 167 | return GNUNET_SYSERR; |
166 | } | 168 | } |
167 | // interpret single ticket | 169 | // interpret single ticket |
168 | unpack_state = json_unpack (root, | 170 | unpack_state = json_unpack(root, |
169 | "{s:s, s:s, s:s!}", | 171 | "{s:s, s:s, s:s!}", |
170 | "rnd", | 172 | "rnd", |
171 | &rnd_str, | 173 | &rnd_str, |
172 | "audience", | 174 | "audience", |
173 | &aud_str, | 175 | &aud_str, |
174 | "issuer", | 176 | "issuer", |
175 | &id_str); | 177 | &id_str); |
176 | if (0 != unpack_state) | 178 | if (0 != unpack_state) |
177 | { | 179 | { |
178 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 180 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
179 | "Error json object has a wrong format!\n"); | 181 | "Error json object has a wrong format!\n"); |
180 | return GNUNET_SYSERR; | 182 | return GNUNET_SYSERR; |
181 | } | 183 | } |
182 | ticket = GNUNET_new (struct GNUNET_RECLAIM_Ticket); | 184 | ticket = GNUNET_new(struct GNUNET_RECLAIM_Ticket); |
183 | if (GNUNET_OK != GNUNET_STRINGS_string_to_data (rnd_str, | 185 | if (GNUNET_OK != GNUNET_STRINGS_string_to_data(rnd_str, |
184 | strlen (rnd_str), | 186 | strlen(rnd_str), |
185 | &ticket->rnd, | 187 | &ticket->rnd, |
186 | sizeof (uint64_t))) | 188 | sizeof(uint64_t))) |
187 | { | 189 | { |
188 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Rnd invalid\n"); | 190 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Rnd invalid\n"); |
189 | GNUNET_free (ticket); | 191 | GNUNET_free(ticket); |
190 | return GNUNET_SYSERR; | 192 | return GNUNET_SYSERR; |
191 | } | 193 | } |
192 | if (GNUNET_OK != | 194 | if (GNUNET_OK != |
193 | GNUNET_STRINGS_string_to_data (id_str, | 195 | GNUNET_STRINGS_string_to_data(id_str, |
194 | strlen (id_str), | 196 | strlen(id_str), |
195 | &ticket->identity, | 197 | &ticket->identity, |
196 | sizeof ( | 198 | sizeof( |
197 | struct GNUNET_CRYPTO_EcdsaPublicKey))) | 199 | struct GNUNET_CRYPTO_EcdsaPublicKey))) |
198 | { | 200 | { |
199 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Identity invalid\n"); | 201 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Identity invalid\n"); |
200 | GNUNET_free (ticket); | 202 | GNUNET_free(ticket); |
201 | return GNUNET_SYSERR; | 203 | return GNUNET_SYSERR; |
202 | } | 204 | } |
203 | 205 | ||
204 | if (GNUNET_OK != | 206 | if (GNUNET_OK != |
205 | GNUNET_STRINGS_string_to_data (aud_str, | 207 | GNUNET_STRINGS_string_to_data(aud_str, |
206 | strlen (aud_str), | 208 | strlen(aud_str), |
207 | &ticket->audience, | 209 | &ticket->audience, |
208 | sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey))) | 210 | sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey))) |
209 | { | 211 | { |
210 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Audience invalid\n"); | 212 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Audience invalid\n"); |
211 | GNUNET_free (ticket); | 213 | GNUNET_free(ticket); |
212 | return GNUNET_SYSERR; | 214 | return GNUNET_SYSERR; |
213 | } | 215 | } |
214 | 216 | ||
215 | *(struct GNUNET_RECLAIM_Ticket **) spec->ptr = ticket; | 217 | *(struct GNUNET_RECLAIM_Ticket **)spec->ptr = ticket; |
216 | return GNUNET_OK; | 218 | return GNUNET_OK; |
217 | } | 219 | } |
218 | 220 | ||
@@ -223,15 +225,16 @@ parse_ticket (void *cls, json_t *root, struct GNUNET_JSON_Specification *spec) | |||
223 | * @param[out] spec where to free the data | 225 | * @param[out] spec where to free the data |
224 | */ | 226 | */ |
225 | static void | 227 | static void |
226 | clean_ticket (void *cls, struct GNUNET_JSON_Specification *spec) | 228 | clean_ticket(void *cls, struct GNUNET_JSON_Specification *spec) |
227 | { | 229 | { |
228 | struct GNUNET_RECLAIM_Ticket **ticket; | 230 | struct GNUNET_RECLAIM_Ticket **ticket; |
229 | ticket = (struct GNUNET_RECLAIM_Ticket **) spec->ptr; | 231 | |
232 | ticket = (struct GNUNET_RECLAIM_Ticket **)spec->ptr; | ||
230 | if (NULL != *ticket) | 233 | if (NULL != *ticket) |
231 | { | 234 | { |
232 | GNUNET_free (*ticket); | 235 | GNUNET_free(*ticket); |
233 | *ticket = NULL; | 236 | *ticket = NULL; |
234 | } | 237 | } |
235 | } | 238 | } |
236 | 239 | ||
237 | /** | 240 | /** |
@@ -241,15 +244,16 @@ clean_ticket (void *cls, struct GNUNET_JSON_Specification *spec) | |||
241 | * @return JSON Specification | 244 | * @return JSON Specification |
242 | */ | 245 | */ |
243 | struct GNUNET_JSON_Specification | 246 | struct GNUNET_JSON_Specification |
244 | GNUNET_RECLAIM_JSON_spec_ticket (struct GNUNET_RECLAIM_Ticket **ticket) | 247 | GNUNET_RECLAIM_JSON_spec_ticket(struct GNUNET_RECLAIM_Ticket **ticket) |
245 | { | 248 | { |
246 | struct GNUNET_JSON_Specification ret = {.parser = &parse_ticket, | 249 | struct GNUNET_JSON_Specification ret = { .parser = &parse_ticket, |
247 | .cleaner = &clean_ticket, | 250 | .cleaner = &clean_ticket, |
248 | .cls = NULL, | 251 | .cls = NULL, |
249 | .field = NULL, | 252 | .field = NULL, |
250 | .ptr = ticket, | 253 | .ptr = ticket, |
251 | .ptr_size = 0, | 254 | .ptr_size = 0, |
252 | .size_ptr = NULL}; | 255 | .size_ptr = NULL }; |
256 | |||
253 | *ticket = NULL; | 257 | *ticket = NULL; |
254 | return ret; | 258 | return ret; |
255 | } | 259 | } |