diff options
Diffstat (limited to 'src/json/json_helper.c')
-rw-r--r-- | src/json/json_helper.c | 725 |
1 files changed, 370 insertions, 355 deletions
diff --git a/src/json/json_helper.c b/src/json/json_helper.c index fdbb13267..a732219c1 100644 --- a/src/json/json_helper.c +++ b/src/json/json_helper.c | |||
@@ -1,22 +1,22 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet | 2 | This file is part of GNUnet |
3 | Copyright (C) 2014, 2015, 2016 GNUnet e.V. | 3 | Copyright (C) 2014, 2015, 2016 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software: you can redistribute it and/or modify it | 5 | GNUnet is free software: you can redistribute it and/or modify it |
6 | under the terms of the GNU Affero General Public License as published | 6 | under the terms of the GNU Affero General Public License as published |
7 | by the Free Software Foundation, either version 3 of the License, | 7 | by the Free Software Foundation, either version 3 of the License, |
8 | or (at your option) any later version. | 8 | or (at your option) any later version. |
9 | 9 | ||
10 | GNUnet is distributed in the hope that it will be useful, but | 10 | GNUnet is distributed in the hope that it will be useful, but |
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
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 | * @file json/json_helper.c | 21 | * @file json/json_helper.c |
22 | * @brief functions to generate specifciations for JSON parsing | 22 | * @brief functions to generate specifciations for JSON parsing |
@@ -32,13 +32,14 @@ | |||
32 | * End of a parser specification. | 32 | * End of a parser specification. |
33 | */ | 33 | */ |
34 | struct GNUNET_JSON_Specification | 34 | struct GNUNET_JSON_Specification |
35 | GNUNET_JSON_spec_end () | 35 | GNUNET_JSON_spec_end() |
36 | { | 36 | { |
37 | struct GNUNET_JSON_Specification ret = { | 37 | struct GNUNET_JSON_Specification ret = { |
38 | .parser = NULL, | 38 | .parser = NULL, |
39 | .cleaner = NULL, | 39 | .cleaner = NULL, |
40 | .cls = NULL | 40 | .cls = NULL |
41 | }; | 41 | }; |
42 | |||
42 | return ret; | 43 | return ret; |
43 | } | 44 | } |
44 | 45 | ||
@@ -52,33 +53,33 @@ GNUNET_JSON_spec_end () | |||
52 | * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error | 53 | * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error |
53 | */ | 54 | */ |
54 | static int | 55 | static int |
55 | parse_fixed_data (void *cls, | 56 | parse_fixed_data(void *cls, |
56 | json_t *root, | 57 | json_t *root, |
57 | struct GNUNET_JSON_Specification *spec) | 58 | struct GNUNET_JSON_Specification *spec) |
58 | { | 59 | { |
59 | const char *enc; | 60 | const char *enc; |
60 | unsigned int len; | 61 | unsigned int len; |
61 | 62 | ||
62 | if (NULL == (enc = json_string_value (root))) | 63 | if (NULL == (enc = json_string_value(root))) |
63 | { | 64 | { |
64 | GNUNET_break_op (0); | 65 | GNUNET_break_op(0); |
65 | return GNUNET_SYSERR; | 66 | return GNUNET_SYSERR; |
66 | } | 67 | } |
67 | len = strlen (enc); | 68 | len = strlen(enc); |
68 | if (((len * 5) / 8) != spec->ptr_size) | 69 | if (((len * 5) / 8) != spec->ptr_size) |
69 | { | 70 | { |
70 | GNUNET_break_op (0); | 71 | GNUNET_break_op(0); |
71 | return GNUNET_SYSERR; | 72 | return GNUNET_SYSERR; |
72 | } | 73 | } |
73 | if (GNUNET_OK != | 74 | if (GNUNET_OK != |
74 | GNUNET_STRINGS_string_to_data (enc, | 75 | GNUNET_STRINGS_string_to_data(enc, |
75 | len, | 76 | len, |
76 | spec->ptr, | 77 | spec->ptr, |
77 | spec->ptr_size)) | 78 | spec->ptr_size)) |
78 | { | 79 | { |
79 | GNUNET_break_op (0); | 80 | GNUNET_break_op(0); |
80 | return GNUNET_SYSERR; | 81 | return GNUNET_SYSERR; |
81 | } | 82 | } |
82 | return GNUNET_OK; | 83 | return GNUNET_OK; |
83 | } | 84 | } |
84 | 85 | ||
@@ -92,9 +93,9 @@ parse_fixed_data (void *cls, | |||
92 | * @param size number of bytes expected in @a obj | 93 | * @param size number of bytes expected in @a obj |
93 | */ | 94 | */ |
94 | struct GNUNET_JSON_Specification | 95 | struct GNUNET_JSON_Specification |
95 | GNUNET_JSON_spec_fixed (const char *name, | 96 | GNUNET_JSON_spec_fixed(const char *name, |
96 | void *obj, | 97 | void *obj, |
97 | size_t size) | 98 | size_t size) |
98 | { | 99 | { |
99 | struct GNUNET_JSON_Specification ret = { | 100 | struct GNUNET_JSON_Specification ret = { |
100 | .parser = &parse_fixed_data, | 101 | .parser = &parse_fixed_data, |
@@ -105,6 +106,7 @@ GNUNET_JSON_spec_fixed (const char *name, | |||
105 | .ptr_size = size, | 106 | .ptr_size = size, |
106 | .size_ptr = NULL | 107 | .size_ptr = NULL |
107 | }; | 108 | }; |
109 | |||
108 | return ret; | 110 | return ret; |
109 | } | 111 | } |
110 | 112 | ||
@@ -118,39 +120,39 @@ GNUNET_JSON_spec_fixed (const char *name, | |||
118 | * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error | 120 | * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error |
119 | */ | 121 | */ |
120 | static int | 122 | static int |
121 | parse_variable_data (void *cls, | 123 | parse_variable_data(void *cls, |
122 | json_t *root, | 124 | json_t *root, |
123 | struct GNUNET_JSON_Specification *spec) | 125 | struct GNUNET_JSON_Specification *spec) |
124 | { | 126 | { |
125 | const char *str; | 127 | const char *str; |
126 | size_t size; | 128 | size_t size; |
127 | void *data; | 129 | void *data; |
128 | int res; | 130 | int res; |
129 | 131 | ||
130 | str = json_string_value (root); | 132 | str = json_string_value(root); |
131 | if (NULL == str) | 133 | if (NULL == str) |
132 | { | 134 | { |
133 | GNUNET_break_op (0); | 135 | GNUNET_break_op(0); |
134 | return GNUNET_SYSERR; | 136 | return GNUNET_SYSERR; |
135 | } | 137 | } |
136 | size = (strlen (str) * 5) / 8; | 138 | size = (strlen(str) * 5) / 8; |
137 | if (size >= 1024) | 139 | if (size >= 1024) |
138 | { | 140 | { |
139 | GNUNET_break_op (0); | 141 | GNUNET_break_op(0); |
140 | return GNUNET_SYSERR; | 142 | return GNUNET_SYSERR; |
141 | } | 143 | } |
142 | data = GNUNET_malloc (size); | 144 | data = GNUNET_malloc(size); |
143 | res = GNUNET_STRINGS_string_to_data (str, | 145 | res = GNUNET_STRINGS_string_to_data(str, |
144 | strlen (str), | 146 | strlen(str), |
145 | data, | 147 | data, |
146 | size); | 148 | size); |
147 | if (GNUNET_OK != res) | 149 | if (GNUNET_OK != res) |
148 | { | 150 | { |
149 | GNUNET_break_op (0); | 151 | GNUNET_break_op(0); |
150 | GNUNET_free (data); | 152 | GNUNET_free(data); |
151 | return GNUNET_SYSERR; | 153 | return GNUNET_SYSERR; |
152 | } | 154 | } |
153 | *(void**) spec->ptr = data; | 155 | *(void**)spec->ptr = data; |
154 | *spec->size_ptr = size; | 156 | *spec->size_ptr = size; |
155 | return GNUNET_OK; | 157 | return GNUNET_OK; |
156 | } | 158 | } |
@@ -163,15 +165,15 @@ parse_variable_data (void *cls, | |||
163 | * @param[out] spec where to free the data | 165 | * @param[out] spec where to free the data |
164 | */ | 166 | */ |
165 | static void | 167 | static void |
166 | clean_variable_data (void *cls, | 168 | clean_variable_data(void *cls, |
167 | struct GNUNET_JSON_Specification *spec) | 169 | struct GNUNET_JSON_Specification *spec) |
168 | { | 170 | { |
169 | if (0 != *spec->size_ptr) | 171 | if (0 != *spec->size_ptr) |
170 | { | 172 | { |
171 | GNUNET_free (*(void **) spec->ptr); | 173 | GNUNET_free(*(void **)spec->ptr); |
172 | *(void**) spec->ptr = NULL; | 174 | *(void**)spec->ptr = NULL; |
173 | *spec->size_ptr = 0; | 175 | *spec->size_ptr = 0; |
174 | } | 176 | } |
175 | } | 177 | } |
176 | 178 | ||
177 | 179 | ||
@@ -184,9 +186,9 @@ clean_variable_data (void *cls, | |||
184 | * @param[out] size where to store the number of bytes allocated for @a obj | 186 | * @param[out] size where to store the number of bytes allocated for @a obj |
185 | */ | 187 | */ |
186 | struct GNUNET_JSON_Specification | 188 | struct GNUNET_JSON_Specification |
187 | GNUNET_JSON_spec_varsize (const char *name, | 189 | GNUNET_JSON_spec_varsize(const char *name, |
188 | void **obj, | 190 | void **obj, |
189 | size_t *size) | 191 | size_t *size) |
190 | { | 192 | { |
191 | struct GNUNET_JSON_Specification ret = { | 193 | struct GNUNET_JSON_Specification ret = { |
192 | .parser = &parse_variable_data, | 194 | .parser = &parse_variable_data, |
@@ -197,6 +199,7 @@ GNUNET_JSON_spec_varsize (const char *name, | |||
197 | .ptr_size = 0, | 199 | .ptr_size = 0, |
198 | .size_ptr = size | 200 | .size_ptr = size |
199 | }; | 201 | }; |
202 | |||
200 | *obj = NULL; | 203 | *obj = NULL; |
201 | *size = 0; | 204 | *size = 0; |
202 | return ret; | 205 | return ret; |
@@ -212,19 +215,19 @@ GNUNET_JSON_spec_varsize (const char *name, | |||
212 | * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error | 215 | * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error |
213 | */ | 216 | */ |
214 | static int | 217 | static int |
215 | parse_string (void *cls, | 218 | parse_string(void *cls, |
216 | json_t *root, | 219 | json_t *root, |
217 | struct GNUNET_JSON_Specification *spec) | 220 | struct GNUNET_JSON_Specification *spec) |
218 | { | 221 | { |
219 | const char *str; | 222 | const char *str; |
220 | 223 | ||
221 | str = json_string_value (root); | 224 | str = json_string_value(root); |
222 | if (NULL == str) | 225 | if (NULL == str) |
223 | { | 226 | { |
224 | GNUNET_break_op (0); | 227 | GNUNET_break_op(0); |
225 | return GNUNET_SYSERR; | 228 | return GNUNET_SYSERR; |
226 | } | 229 | } |
227 | *(const char **) spec->ptr = str; | 230 | *(const char **)spec->ptr = str; |
228 | return GNUNET_OK; | 231 | return GNUNET_OK; |
229 | } | 232 | } |
230 | 233 | ||
@@ -236,8 +239,8 @@ parse_string (void *cls, | |||
236 | * @param strptr where to store a pointer to the field | 239 | * @param strptr where to store a pointer to the field |
237 | */ | 240 | */ |
238 | struct GNUNET_JSON_Specification | 241 | struct GNUNET_JSON_Specification |
239 | GNUNET_JSON_spec_string (const char *name, | 242 | GNUNET_JSON_spec_string(const char *name, |
240 | const char **strptr) | 243 | const char **strptr) |
241 | { | 244 | { |
242 | struct GNUNET_JSON_Specification ret = { | 245 | struct GNUNET_JSON_Specification ret = { |
243 | .parser = &parse_string, | 246 | .parser = &parse_string, |
@@ -248,6 +251,7 @@ GNUNET_JSON_spec_string (const char *name, | |||
248 | .ptr_size = 0, | 251 | .ptr_size = 0, |
249 | .size_ptr = NULL | 252 | .size_ptr = NULL |
250 | }; | 253 | }; |
254 | |||
251 | *strptr = NULL; | 255 | *strptr = NULL; |
252 | return ret; | 256 | return ret; |
253 | } | 257 | } |
@@ -262,17 +266,17 @@ GNUNET_JSON_spec_string (const char *name, | |||
262 | * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error | 266 | * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error |
263 | */ | 267 | */ |
264 | static int | 268 | static int |
265 | parse_object (void *cls, | 269 | parse_object(void *cls, |
266 | json_t *root, | 270 | json_t *root, |
267 | struct GNUNET_JSON_Specification *spec) | 271 | struct GNUNET_JSON_Specification *spec) |
268 | { | 272 | { |
269 | if (! (json_is_object (root) || json_is_array (root)) ) | 273 | if (!(json_is_object(root) || json_is_array(root))) |
270 | { | 274 | { |
271 | GNUNET_break_op (0); | 275 | GNUNET_break_op(0); |
272 | return GNUNET_SYSERR; | 276 | return GNUNET_SYSERR; |
273 | } | 277 | } |
274 | json_incref (root); | 278 | json_incref(root); |
275 | *(json_t **) spec->ptr = root; | 279 | *(json_t **)spec->ptr = root; |
276 | return GNUNET_OK; | 280 | return GNUNET_OK; |
277 | } | 281 | } |
278 | 282 | ||
@@ -284,16 +288,16 @@ parse_object (void *cls, | |||
284 | * @param[out] spec where to free the data | 288 | * @param[out] spec where to free the data |
285 | */ | 289 | */ |
286 | static void | 290 | static void |
287 | clean_object (void *cls, | 291 | clean_object(void *cls, |
288 | struct GNUNET_JSON_Specification *spec) | 292 | struct GNUNET_JSON_Specification *spec) |
289 | { | 293 | { |
290 | json_t **ptr = (json_t **) spec->ptr; | 294 | json_t **ptr = (json_t **)spec->ptr; |
291 | 295 | ||
292 | if (NULL != *ptr) | 296 | if (NULL != *ptr) |
293 | { | 297 | { |
294 | json_decref (*ptr); | 298 | json_decref(*ptr); |
295 | *ptr = NULL; | 299 | *ptr = NULL; |
296 | } | 300 | } |
297 | } | 301 | } |
298 | 302 | ||
299 | 303 | ||
@@ -304,8 +308,8 @@ clean_object (void *cls, | |||
304 | * @param[out] jsonp where to store the JSON found under @a name | 308 | * @param[out] jsonp where to store the JSON found under @a name |
305 | */ | 309 | */ |
306 | struct GNUNET_JSON_Specification | 310 | struct GNUNET_JSON_Specification |
307 | GNUNET_JSON_spec_json (const char *name, | 311 | GNUNET_JSON_spec_json(const char *name, |
308 | json_t **jsonp) | 312 | json_t **jsonp) |
309 | { | 313 | { |
310 | struct GNUNET_JSON_Specification ret = { | 314 | struct GNUNET_JSON_Specification ret = { |
311 | .parser = &parse_object, | 315 | .parser = &parse_object, |
@@ -316,6 +320,7 @@ GNUNET_JSON_spec_json (const char *name, | |||
316 | .ptr_size = 0, | 320 | .ptr_size = 0, |
317 | .size_ptr = NULL | 321 | .size_ptr = NULL |
318 | }; | 322 | }; |
323 | |||
319 | *jsonp = NULL; | 324 | *jsonp = NULL; |
320 | return ret; | 325 | return ret; |
321 | } | 326 | } |
@@ -330,25 +335,25 @@ GNUNET_JSON_spec_json (const char *name, | |||
330 | * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error | 335 | * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error |
331 | */ | 336 | */ |
332 | static int | 337 | static int |
333 | parse_u8 (void *cls, | 338 | parse_u8(void *cls, |
334 | json_t *root, | 339 | json_t *root, |
335 | struct GNUNET_JSON_Specification *spec) | 340 | struct GNUNET_JSON_Specification *spec) |
336 | { | 341 | { |
337 | json_int_t val; | 342 | json_int_t val; |
338 | uint8_t *up = spec->ptr; | 343 | uint8_t *up = spec->ptr; |
339 | 344 | ||
340 | if (! json_is_integer (root)) | 345 | if (!json_is_integer(root)) |
341 | { | 346 | { |
342 | GNUNET_break_op (0); | 347 | GNUNET_break_op(0); |
343 | return GNUNET_SYSERR; | 348 | return GNUNET_SYSERR; |
344 | } | 349 | } |
345 | val = json_integer_value (root); | 350 | val = json_integer_value(root); |
346 | if ( (0 > val) || (val > UINT8_MAX) ) | 351 | if ((0 > val) || (val > UINT8_MAX)) |
347 | { | 352 | { |
348 | GNUNET_break_op (0); | 353 | GNUNET_break_op(0); |
349 | return GNUNET_SYSERR; | 354 | return GNUNET_SYSERR; |
350 | } | 355 | } |
351 | *up = (uint8_t) val; | 356 | *up = (uint8_t)val; |
352 | return GNUNET_OK; | 357 | return GNUNET_OK; |
353 | } | 358 | } |
354 | 359 | ||
@@ -360,8 +365,8 @@ parse_u8 (void *cls, | |||
360 | * @param[out] u8 where to store the integer found under @a name | 365 | * @param[out] u8 where to store the integer found under @a name |
361 | */ | 366 | */ |
362 | struct GNUNET_JSON_Specification | 367 | struct GNUNET_JSON_Specification |
363 | GNUNET_JSON_spec_uint8 (const char *name, | 368 | GNUNET_JSON_spec_uint8(const char *name, |
364 | uint8_t *u8) | 369 | uint8_t *u8) |
365 | { | 370 | { |
366 | struct GNUNET_JSON_Specification ret = { | 371 | struct GNUNET_JSON_Specification ret = { |
367 | .parser = &parse_u8, | 372 | .parser = &parse_u8, |
@@ -369,9 +374,10 @@ GNUNET_JSON_spec_uint8 (const char *name, | |||
369 | .cls = NULL, | 374 | .cls = NULL, |
370 | .field = name, | 375 | .field = name, |
371 | .ptr = u8, | 376 | .ptr = u8, |
372 | .ptr_size = sizeof (uint8_t), | 377 | .ptr_size = sizeof(uint8_t), |
373 | .size_ptr = NULL | 378 | .size_ptr = NULL |
374 | }; | 379 | }; |
380 | |||
375 | return ret; | 381 | return ret; |
376 | } | 382 | } |
377 | 383 | ||
@@ -385,25 +391,25 @@ GNUNET_JSON_spec_uint8 (const char *name, | |||
385 | * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error | 391 | * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error |
386 | */ | 392 | */ |
387 | static int | 393 | static int |
388 | parse_u16 (void *cls, | 394 | parse_u16(void *cls, |
389 | json_t *root, | 395 | json_t *root, |
390 | struct GNUNET_JSON_Specification *spec) | 396 | struct GNUNET_JSON_Specification *spec) |
391 | { | 397 | { |
392 | json_int_t val; | 398 | json_int_t val; |
393 | uint16_t *up = spec->ptr; | 399 | uint16_t *up = spec->ptr; |
394 | 400 | ||
395 | if (! json_is_integer (root)) | 401 | if (!json_is_integer(root)) |
396 | { | 402 | { |
397 | GNUNET_break_op (0); | 403 | GNUNET_break_op(0); |
398 | return GNUNET_SYSERR; | 404 | return GNUNET_SYSERR; |
399 | } | 405 | } |
400 | val = json_integer_value (root); | 406 | val = json_integer_value(root); |
401 | if ( (0 > val) || (val > UINT16_MAX) ) | 407 | if ((0 > val) || (val > UINT16_MAX)) |
402 | { | 408 | { |
403 | GNUNET_break_op (0); | 409 | GNUNET_break_op(0); |
404 | return GNUNET_SYSERR; | 410 | return GNUNET_SYSERR; |
405 | } | 411 | } |
406 | *up = (uint16_t) val; | 412 | *up = (uint16_t)val; |
407 | return GNUNET_OK; | 413 | return GNUNET_OK; |
408 | } | 414 | } |
409 | 415 | ||
@@ -415,8 +421,8 @@ parse_u16 (void *cls, | |||
415 | * @param[out] u16 where to store the integer found under @a name | 421 | * @param[out] u16 where to store the integer found under @a name |
416 | */ | 422 | */ |
417 | struct GNUNET_JSON_Specification | 423 | struct GNUNET_JSON_Specification |
418 | GNUNET_JSON_spec_uint16 (const char *name, | 424 | GNUNET_JSON_spec_uint16(const char *name, |
419 | uint16_t *u16) | 425 | uint16_t *u16) |
420 | { | 426 | { |
421 | struct GNUNET_JSON_Specification ret = { | 427 | struct GNUNET_JSON_Specification ret = { |
422 | .parser = &parse_u16, | 428 | .parser = &parse_u16, |
@@ -424,9 +430,10 @@ GNUNET_JSON_spec_uint16 (const char *name, | |||
424 | .cls = NULL, | 430 | .cls = NULL, |
425 | .field = name, | 431 | .field = name, |
426 | .ptr = u16, | 432 | .ptr = u16, |
427 | .ptr_size = sizeof (uint16_t), | 433 | .ptr_size = sizeof(uint16_t), |
428 | .size_ptr = NULL | 434 | .size_ptr = NULL |
429 | }; | 435 | }; |
436 | |||
430 | return ret; | 437 | return ret; |
431 | } | 438 | } |
432 | 439 | ||
@@ -440,25 +447,25 @@ GNUNET_JSON_spec_uint16 (const char *name, | |||
440 | * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error | 447 | * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error |
441 | */ | 448 | */ |
442 | static int | 449 | static int |
443 | parse_u32 (void *cls, | 450 | parse_u32(void *cls, |
444 | json_t *root, | 451 | json_t *root, |
445 | struct GNUNET_JSON_Specification *spec) | 452 | struct GNUNET_JSON_Specification *spec) |
446 | { | 453 | { |
447 | json_int_t val; | 454 | json_int_t val; |
448 | uint32_t *up = spec->ptr; | 455 | uint32_t *up = spec->ptr; |
449 | 456 | ||
450 | if (! json_is_integer (root)) | 457 | if (!json_is_integer(root)) |
451 | { | 458 | { |
452 | GNUNET_break_op (0); | 459 | GNUNET_break_op(0); |
453 | return GNUNET_SYSERR; | 460 | return GNUNET_SYSERR; |
454 | } | 461 | } |
455 | val = json_integer_value (root); | 462 | val = json_integer_value(root); |
456 | if ( (0 > val) || (val > UINT32_MAX) ) | 463 | if ((0 > val) || (val > UINT32_MAX)) |
457 | { | 464 | { |
458 | GNUNET_break_op (0); | 465 | GNUNET_break_op(0); |
459 | return GNUNET_SYSERR; | 466 | return GNUNET_SYSERR; |
460 | } | 467 | } |
461 | *up = (uint32_t) val; | 468 | *up = (uint32_t)val; |
462 | return GNUNET_OK; | 469 | return GNUNET_OK; |
463 | } | 470 | } |
464 | 471 | ||
@@ -470,8 +477,8 @@ parse_u32 (void *cls, | |||
470 | * @param[out] u32 where to store the integer found under @a name | 477 | * @param[out] u32 where to store the integer found under @a name |
471 | */ | 478 | */ |
472 | struct GNUNET_JSON_Specification | 479 | struct GNUNET_JSON_Specification |
473 | GNUNET_JSON_spec_uint32 (const char *name, | 480 | GNUNET_JSON_spec_uint32(const char *name, |
474 | uint32_t *u32) | 481 | uint32_t *u32) |
475 | { | 482 | { |
476 | struct GNUNET_JSON_Specification ret = { | 483 | struct GNUNET_JSON_Specification ret = { |
477 | .parser = &parse_u32, | 484 | .parser = &parse_u32, |
@@ -479,9 +486,10 @@ GNUNET_JSON_spec_uint32 (const char *name, | |||
479 | .cls = NULL, | 486 | .cls = NULL, |
480 | .field = name, | 487 | .field = name, |
481 | .ptr = u32, | 488 | .ptr = u32, |
482 | .ptr_size = sizeof (uint32_t), | 489 | .ptr_size = sizeof(uint32_t), |
483 | .size_ptr = NULL | 490 | .size_ptr = NULL |
484 | }; | 491 | }; |
492 | |||
485 | return ret; | 493 | return ret; |
486 | } | 494 | } |
487 | 495 | ||
@@ -495,20 +503,20 @@ GNUNET_JSON_spec_uint32 (const char *name, | |||
495 | * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error | 503 | * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error |
496 | */ | 504 | */ |
497 | static int | 505 | static int |
498 | parse_u64 (void *cls, | 506 | parse_u64(void *cls, |
499 | json_t *root, | 507 | json_t *root, |
500 | struct GNUNET_JSON_Specification *spec) | 508 | struct GNUNET_JSON_Specification *spec) |
501 | { | 509 | { |
502 | json_int_t val; | 510 | json_int_t val; |
503 | uint64_t *up = spec->ptr; | 511 | uint64_t *up = spec->ptr; |
504 | 512 | ||
505 | if (! json_is_integer (root)) | 513 | if (!json_is_integer(root)) |
506 | { | 514 | { |
507 | GNUNET_break_op (0); | 515 | GNUNET_break_op(0); |
508 | return GNUNET_SYSERR; | 516 | return GNUNET_SYSERR; |
509 | } | 517 | } |
510 | val = json_integer_value (root); | 518 | val = json_integer_value(root); |
511 | *up = (uint64_t) val; | 519 | *up = (uint64_t)val; |
512 | return GNUNET_OK; | 520 | return GNUNET_OK; |
513 | } | 521 | } |
514 | 522 | ||
@@ -520,8 +528,8 @@ parse_u64 (void *cls, | |||
520 | * @param[out] u64 where to store the integer found under @a name | 528 | * @param[out] u64 where to store the integer found under @a name |
521 | */ | 529 | */ |
522 | struct GNUNET_JSON_Specification | 530 | struct GNUNET_JSON_Specification |
523 | GNUNET_JSON_spec_uint64 (const char *name, | 531 | GNUNET_JSON_spec_uint64(const char *name, |
524 | uint64_t *u64) | 532 | uint64_t *u64) |
525 | { | 533 | { |
526 | struct GNUNET_JSON_Specification ret = { | 534 | struct GNUNET_JSON_Specification ret = { |
527 | .parser = &parse_u64, | 535 | .parser = &parse_u64, |
@@ -529,9 +537,10 @@ GNUNET_JSON_spec_uint64 (const char *name, | |||
529 | .cls = NULL, | 537 | .cls = NULL, |
530 | .field = name, | 538 | .field = name, |
531 | .ptr = u64, | 539 | .ptr = u64, |
532 | .ptr_size = sizeof (uint64_t), | 540 | .ptr_size = sizeof(uint64_t), |
533 | .size_ptr = NULL | 541 | .size_ptr = NULL |
534 | }; | 542 | }; |
543 | |||
535 | return ret; | 544 | return ret; |
536 | } | 545 | } |
537 | 546 | ||
@@ -547,45 +556,45 @@ GNUNET_JSON_spec_uint64 (const char *name, | |||
547 | * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error | 556 | * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error |
548 | */ | 557 | */ |
549 | static int | 558 | static int |
550 | parse_abs_time (void *cls, | 559 | parse_abs_time(void *cls, |
551 | json_t *root, | 560 | json_t *root, |
552 | struct GNUNET_JSON_Specification *spec) | 561 | struct GNUNET_JSON_Specification *spec) |
553 | { | 562 | { |
554 | struct GNUNET_TIME_Absolute *abs = spec->ptr; | 563 | struct GNUNET_TIME_Absolute *abs = spec->ptr; |
555 | const char *val; | 564 | const char *val; |
556 | unsigned long long int tval; | 565 | unsigned long long int tval; |
557 | 566 | ||
558 | val = json_string_value (root); | 567 | val = json_string_value(root); |
559 | if (NULL == val) | 568 | if (NULL == val) |
560 | { | 569 | { |
561 | GNUNET_break_op (0); | 570 | GNUNET_break_op(0); |
562 | return GNUNET_SYSERR; | 571 | return GNUNET_SYSERR; |
563 | } | 572 | } |
564 | if ( (0 == strcasecmp (val, | 573 | if ((0 == strcasecmp(val, |
565 | "/forever/")) || | 574 | "/forever/")) || |
566 | (0 == strcasecmp (val, | 575 | (0 == strcasecmp(val, |
567 | "/end of time/")) || | 576 | "/end of time/")) || |
568 | (0 == strcasecmp (val, | 577 | (0 == strcasecmp(val, |
569 | "/never/")) ) | 578 | "/never/"))) |
570 | { | 579 | { |
571 | *abs = GNUNET_TIME_UNIT_FOREVER_ABS; | 580 | *abs = GNUNET_TIME_UNIT_FOREVER_ABS; |
572 | return GNUNET_OK; | 581 | return GNUNET_OK; |
573 | } | 582 | } |
574 | if (1 != sscanf (val, | 583 | if (1 != sscanf(val, |
575 | "/Date(%llu)/", | 584 | "/Date(%llu)/", |
576 | &tval)) | 585 | &tval)) |
577 | { | 586 | { |
578 | GNUNET_break_op (0); | 587 | GNUNET_break_op(0); |
579 | return GNUNET_SYSERR; | 588 | return GNUNET_SYSERR; |
580 | } | 589 | } |
581 | /* Time is in seconds in JSON, but in microseconds in GNUNET_TIME_Absolute */ | 590 | /* Time is in seconds in JSON, but in microseconds in GNUNET_TIME_Absolute */ |
582 | abs->abs_value_us = tval * 1000LL * 1000LL; | 591 | abs->abs_value_us = tval * 1000LL * 1000LL; |
583 | if ( (abs->abs_value_us) / 1000LL / 1000LL != tval) | 592 | if ((abs->abs_value_us) / 1000LL / 1000LL != tval) |
584 | { | 593 | { |
585 | /* Integer overflow */ | 594 | /* Integer overflow */ |
586 | GNUNET_break_op (0); | 595 | GNUNET_break_op(0); |
587 | return GNUNET_SYSERR; | 596 | return GNUNET_SYSERR; |
588 | } | 597 | } |
589 | return GNUNET_OK; | 598 | return GNUNET_OK; |
590 | } | 599 | } |
591 | 600 | ||
@@ -597,8 +606,8 @@ parse_abs_time (void *cls, | |||
597 | * @param[out] at where to store the absolute time found under @a name | 606 | * @param[out] at where to store the absolute time found under @a name |
598 | */ | 607 | */ |
599 | struct GNUNET_JSON_Specification | 608 | struct GNUNET_JSON_Specification |
600 | GNUNET_JSON_spec_absolute_time (const char *name, | 609 | GNUNET_JSON_spec_absolute_time(const char *name, |
601 | struct GNUNET_TIME_Absolute *at) | 610 | struct GNUNET_TIME_Absolute *at) |
602 | { | 611 | { |
603 | struct GNUNET_JSON_Specification ret = { | 612 | struct GNUNET_JSON_Specification ret = { |
604 | .parser = &parse_abs_time, | 613 | .parser = &parse_abs_time, |
@@ -606,9 +615,10 @@ GNUNET_JSON_spec_absolute_time (const char *name, | |||
606 | .cls = NULL, | 615 | .cls = NULL, |
607 | .field = name, | 616 | .field = name, |
608 | .ptr = at, | 617 | .ptr = at, |
609 | .ptr_size = sizeof (uint64_t), | 618 | .ptr_size = sizeof(uint64_t), |
610 | .size_ptr = NULL | 619 | .size_ptr = NULL |
611 | }; | 620 | }; |
621 | |||
612 | return ret; | 622 | return ret; |
613 | } | 623 | } |
614 | 624 | ||
@@ -622,47 +632,47 @@ GNUNET_JSON_spec_absolute_time (const char *name, | |||
622 | * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error | 632 | * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error |
623 | */ | 633 | */ |
624 | static int | 634 | static int |
625 | parse_abs_time_nbo (void *cls, | 635 | parse_abs_time_nbo(void *cls, |
626 | json_t *root, | 636 | json_t *root, |
627 | struct GNUNET_JSON_Specification *spec) | 637 | struct GNUNET_JSON_Specification *spec) |
628 | { | 638 | { |
629 | struct GNUNET_TIME_AbsoluteNBO *abs = spec->ptr; | 639 | struct GNUNET_TIME_AbsoluteNBO *abs = spec->ptr; |
630 | const char *val; | 640 | const char *val; |
631 | unsigned long long int tval; | 641 | unsigned long long int tval; |
632 | struct GNUNET_TIME_Absolute a; | 642 | struct GNUNET_TIME_Absolute a; |
633 | 643 | ||
634 | val = json_string_value (root); | 644 | val = json_string_value(root); |
635 | if (NULL == val) | 645 | if (NULL == val) |
636 | { | 646 | { |
637 | GNUNET_break_op (0); | 647 | GNUNET_break_op(0); |
638 | return GNUNET_SYSERR; | 648 | return GNUNET_SYSERR; |
639 | } | 649 | } |
640 | if ( (0 == strcasecmp (val, | 650 | if ((0 == strcasecmp(val, |
641 | "/forever/")) || | 651 | "/forever/")) || |
642 | (0 == strcasecmp (val, | 652 | (0 == strcasecmp(val, |
643 | "/end of time/")) || | 653 | "/end of time/")) || |
644 | (0 == strcasecmp (val, | 654 | (0 == strcasecmp(val, |
645 | "/never/")) ) | 655 | "/never/"))) |
646 | { | 656 | { |
647 | *abs = GNUNET_TIME_absolute_hton (GNUNET_TIME_UNIT_FOREVER_ABS); | 657 | *abs = GNUNET_TIME_absolute_hton(GNUNET_TIME_UNIT_FOREVER_ABS); |
648 | return GNUNET_OK; | 658 | return GNUNET_OK; |
649 | } | 659 | } |
650 | if (1 != sscanf (val, | 660 | if (1 != sscanf(val, |
651 | "/Date(%llu)/", | 661 | "/Date(%llu)/", |
652 | &tval)) | 662 | &tval)) |
653 | { | 663 | { |
654 | GNUNET_break_op (0); | 664 | GNUNET_break_op(0); |
655 | return GNUNET_SYSERR; | 665 | return GNUNET_SYSERR; |
656 | } | 666 | } |
657 | /* Time is in seconds in JSON, but in microseconds in GNUNET_TIME_Absolute */ | 667 | /* Time is in seconds in JSON, but in microseconds in GNUNET_TIME_Absolute */ |
658 | a.abs_value_us = tval * 1000LL * 1000LL; | 668 | a.abs_value_us = tval * 1000LL * 1000LL; |
659 | if ( (a.abs_value_us) / 1000LL / 1000LL != tval) | 669 | if ((a.abs_value_us) / 1000LL / 1000LL != tval) |
660 | { | 670 | { |
661 | /* Integer overflow */ | 671 | /* Integer overflow */ |
662 | GNUNET_break_op (0); | 672 | GNUNET_break_op(0); |
663 | return GNUNET_SYSERR; | 673 | return GNUNET_SYSERR; |
664 | } | 674 | } |
665 | *abs = GNUNET_TIME_absolute_hton (a); | 675 | *abs = GNUNET_TIME_absolute_hton(a); |
666 | return GNUNET_OK; | 676 | return GNUNET_OK; |
667 | } | 677 | } |
668 | 678 | ||
@@ -674,8 +684,8 @@ parse_abs_time_nbo (void *cls, | |||
674 | * @param[out] at where to store the absolute time found under @a name | 684 | * @param[out] at where to store the absolute time found under @a name |
675 | */ | 685 | */ |
676 | struct GNUNET_JSON_Specification | 686 | struct GNUNET_JSON_Specification |
677 | GNUNET_JSON_spec_absolute_time_nbo (const char *name, | 687 | GNUNET_JSON_spec_absolute_time_nbo(const char *name, |
678 | struct GNUNET_TIME_AbsoluteNBO *at) | 688 | struct GNUNET_TIME_AbsoluteNBO *at) |
679 | { | 689 | { |
680 | struct GNUNET_JSON_Specification ret = { | 690 | struct GNUNET_JSON_Specification ret = { |
681 | .parser = &parse_abs_time_nbo, | 691 | .parser = &parse_abs_time_nbo, |
@@ -683,9 +693,10 @@ GNUNET_JSON_spec_absolute_time_nbo (const char *name, | |||
683 | .cls = NULL, | 693 | .cls = NULL, |
684 | .field = name, | 694 | .field = name, |
685 | .ptr = at, | 695 | .ptr = at, |
686 | .ptr_size = sizeof (uint64_t), | 696 | .ptr_size = sizeof(uint64_t), |
687 | .size_ptr = NULL | 697 | .size_ptr = NULL |
688 | }; | 698 | }; |
699 | |||
689 | return ret; | 700 | return ret; |
690 | } | 701 | } |
691 | 702 | ||
@@ -699,41 +710,41 @@ GNUNET_JSON_spec_absolute_time_nbo (const char *name, | |||
699 | * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error | 710 | * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error |
700 | */ | 711 | */ |
701 | static int | 712 | static int |
702 | parse_rel_time (void *cls, | 713 | parse_rel_time(void *cls, |
703 | json_t *root, | 714 | json_t *root, |
704 | struct GNUNET_JSON_Specification *spec) | 715 | struct GNUNET_JSON_Specification *spec) |
705 | { | 716 | { |
706 | struct GNUNET_TIME_Relative *rel = spec->ptr; | 717 | struct GNUNET_TIME_Relative *rel = spec->ptr; |
707 | const char *val; | 718 | const char *val; |
708 | unsigned long long int tval; | 719 | unsigned long long int tval; |
709 | 720 | ||
710 | val = json_string_value (root); | 721 | val = json_string_value(root); |
711 | if (NULL == val) | 722 | if (NULL == val) |
712 | { | 723 | { |
713 | GNUNET_break_op (0); | 724 | GNUNET_break_op(0); |
714 | return GNUNET_SYSERR; | 725 | return GNUNET_SYSERR; |
715 | } | 726 | } |
716 | if ( (0 == strcasecmp (val, | 727 | if ((0 == strcasecmp(val, |
717 | "/forever/")) ) | 728 | "/forever/"))) |
718 | { | 729 | { |
719 | *rel = GNUNET_TIME_UNIT_FOREVER_REL; | 730 | *rel = GNUNET_TIME_UNIT_FOREVER_REL; |
720 | return GNUNET_OK; | 731 | return GNUNET_OK; |
721 | } | 732 | } |
722 | if (1 != sscanf (val, | 733 | if (1 != sscanf(val, |
723 | "/Delay(%llu)/", | 734 | "/Delay(%llu)/", |
724 | &tval)) | 735 | &tval)) |
725 | { | 736 | { |
726 | GNUNET_break_op (0); | 737 | GNUNET_break_op(0); |
727 | return GNUNET_SYSERR; | 738 | return GNUNET_SYSERR; |
728 | } | 739 | } |
729 | /* Time is in seconds in JSON, but in microseconds in GNUNET_TIME_Relative */ | 740 | /* Time is in seconds in JSON, but in microseconds in GNUNET_TIME_Relative */ |
730 | rel->rel_value_us = tval * 1000LL * 1000LL; | 741 | rel->rel_value_us = tval * 1000LL * 1000LL; |
731 | if ( (rel->rel_value_us) / 1000LL / 1000LL != tval) | 742 | if ((rel->rel_value_us) / 1000LL / 1000LL != tval) |
732 | { | 743 | { |
733 | /* Integer overflow */ | 744 | /* Integer overflow */ |
734 | GNUNET_break_op (0); | 745 | GNUNET_break_op(0); |
735 | return GNUNET_SYSERR; | 746 | return GNUNET_SYSERR; |
736 | } | 747 | } |
737 | return GNUNET_OK; | 748 | return GNUNET_OK; |
738 | } | 749 | } |
739 | 750 | ||
@@ -745,8 +756,8 @@ parse_rel_time (void *cls, | |||
745 | * @param[out] rt where to store the relative time found under @a name | 756 | * @param[out] rt where to store the relative time found under @a name |
746 | */ | 757 | */ |
747 | struct GNUNET_JSON_Specification | 758 | struct GNUNET_JSON_Specification |
748 | GNUNET_JSON_spec_relative_time (const char *name, | 759 | GNUNET_JSON_spec_relative_time(const char *name, |
749 | struct GNUNET_TIME_Relative *rt) | 760 | struct GNUNET_TIME_Relative *rt) |
750 | { | 761 | { |
751 | struct GNUNET_JSON_Specification ret = { | 762 | struct GNUNET_JSON_Specification ret = { |
752 | .parser = &parse_rel_time, | 763 | .parser = &parse_rel_time, |
@@ -754,9 +765,10 @@ GNUNET_JSON_spec_relative_time (const char *name, | |||
754 | .cls = NULL, | 765 | .cls = NULL, |
755 | .field = name, | 766 | .field = name, |
756 | .ptr = rt, | 767 | .ptr = rt, |
757 | .ptr_size = sizeof (uint64_t), | 768 | .ptr_size = sizeof(uint64_t), |
758 | .size_ptr = NULL | 769 | .size_ptr = NULL |
759 | }; | 770 | }; |
771 | |||
760 | return ret; | 772 | return ret; |
761 | } | 773 | } |
762 | 774 | ||
@@ -770,9 +782,9 @@ GNUNET_JSON_spec_relative_time (const char *name, | |||
770 | * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error | 782 | * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error |
771 | */ | 783 | */ |
772 | static int | 784 | static int |
773 | parse_rsa_public_key (void *cls, | 785 | parse_rsa_public_key(void *cls, |
774 | json_t *root, | 786 | json_t *root, |
775 | struct GNUNET_JSON_Specification *spec) | 787 | struct GNUNET_JSON_Specification *spec) |
776 | { | 788 | { |
777 | struct GNUNET_CRYPTO_RsaPublicKey **pk = spec->ptr; | 789 | struct GNUNET_CRYPTO_RsaPublicKey **pk = spec->ptr; |
778 | const char *enc; | 790 | const char *enc; |
@@ -780,32 +792,32 @@ parse_rsa_public_key (void *cls, | |||
780 | size_t len; | 792 | size_t len; |
781 | size_t buf_len; | 793 | size_t buf_len; |
782 | 794 | ||
783 | if (NULL == (enc = json_string_value (root))) | 795 | if (NULL == (enc = json_string_value(root))) |
784 | { | 796 | { |
785 | GNUNET_break_op (0); | 797 | GNUNET_break_op(0); |
786 | return GNUNET_SYSERR; | 798 | return GNUNET_SYSERR; |
787 | } | 799 | } |
788 | len = strlen (enc); | 800 | len = strlen(enc); |
789 | buf_len = (len * 5) / 8; | 801 | buf_len = (len * 5) / 8; |
790 | buf = GNUNET_malloc (buf_len); | 802 | buf = GNUNET_malloc(buf_len); |
791 | if (GNUNET_OK != | 803 | if (GNUNET_OK != |
792 | GNUNET_STRINGS_string_to_data (enc, | 804 | GNUNET_STRINGS_string_to_data(enc, |
793 | len, | 805 | len, |
794 | buf, | 806 | buf, |
795 | buf_len)) | 807 | buf_len)) |
796 | { | 808 | { |
797 | GNUNET_break_op (0); | 809 | GNUNET_break_op(0); |
798 | GNUNET_free (buf); | 810 | GNUNET_free(buf); |
799 | return GNUNET_SYSERR; | 811 | return GNUNET_SYSERR; |
800 | } | 812 | } |
801 | if (NULL == (*pk = GNUNET_CRYPTO_rsa_public_key_decode (buf, | 813 | if (NULL == (*pk = GNUNET_CRYPTO_rsa_public_key_decode(buf, |
802 | buf_len))) | 814 | buf_len))) |
803 | { | 815 | { |
804 | GNUNET_break_op (0); | 816 | GNUNET_break_op(0); |
805 | GNUNET_free (buf); | 817 | GNUNET_free(buf); |
806 | return GNUNET_SYSERR; | 818 | return GNUNET_SYSERR; |
807 | } | 819 | } |
808 | GNUNET_free (buf); | 820 | GNUNET_free(buf); |
809 | return GNUNET_OK; | 821 | return GNUNET_OK; |
810 | } | 822 | } |
811 | 823 | ||
@@ -817,16 +829,16 @@ parse_rsa_public_key (void *cls, | |||
817 | * @param[out] spec where to free the data | 829 | * @param[out] spec where to free the data |
818 | */ | 830 | */ |
819 | static void | 831 | static void |
820 | clean_rsa_public_key (void *cls, | 832 | clean_rsa_public_key(void *cls, |
821 | struct GNUNET_JSON_Specification *spec) | 833 | struct GNUNET_JSON_Specification *spec) |
822 | { | 834 | { |
823 | struct GNUNET_CRYPTO_RsaPublicKey **pk = spec->ptr; | 835 | struct GNUNET_CRYPTO_RsaPublicKey **pk = spec->ptr; |
824 | 836 | ||
825 | if (NULL != *pk) | 837 | if (NULL != *pk) |
826 | { | 838 | { |
827 | GNUNET_CRYPTO_rsa_public_key_free (*pk); | 839 | GNUNET_CRYPTO_rsa_public_key_free(*pk); |
828 | *pk = NULL; | 840 | *pk = NULL; |
829 | } | 841 | } |
830 | } | 842 | } |
831 | 843 | ||
832 | 844 | ||
@@ -837,8 +849,8 @@ clean_rsa_public_key (void *cls, | |||
837 | * @param pk where to store the RSA key found under @a name | 849 | * @param pk where to store the RSA key found under @a name |
838 | */ | 850 | */ |
839 | struct GNUNET_JSON_Specification | 851 | struct GNUNET_JSON_Specification |
840 | GNUNET_JSON_spec_rsa_public_key (const char *name, | 852 | GNUNET_JSON_spec_rsa_public_key(const char *name, |
841 | struct GNUNET_CRYPTO_RsaPublicKey **pk) | 853 | struct GNUNET_CRYPTO_RsaPublicKey **pk) |
842 | { | 854 | { |
843 | struct GNUNET_JSON_Specification ret = { | 855 | struct GNUNET_JSON_Specification ret = { |
844 | .parser = &parse_rsa_public_key, | 856 | .parser = &parse_rsa_public_key, |
@@ -849,6 +861,7 @@ GNUNET_JSON_spec_rsa_public_key (const char *name, | |||
849 | .ptr_size = 0, | 861 | .ptr_size = 0, |
850 | .size_ptr = NULL | 862 | .size_ptr = NULL |
851 | }; | 863 | }; |
864 | |||
852 | *pk = NULL; | 865 | *pk = NULL; |
853 | return ret; | 866 | return ret; |
854 | } | 867 | } |
@@ -863,9 +876,9 @@ GNUNET_JSON_spec_rsa_public_key (const char *name, | |||
863 | * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error | 876 | * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error |
864 | */ | 877 | */ |
865 | static int | 878 | static int |
866 | parse_rsa_signature (void *cls, | 879 | parse_rsa_signature(void *cls, |
867 | json_t *root, | 880 | json_t *root, |
868 | struct GNUNET_JSON_Specification *spec) | 881 | struct GNUNET_JSON_Specification *spec) |
869 | { | 882 | { |
870 | struct GNUNET_CRYPTO_RsaSignature **sig = spec->ptr; | 883 | struct GNUNET_CRYPTO_RsaSignature **sig = spec->ptr; |
871 | size_t size; | 884 | size_t size; |
@@ -873,32 +886,32 @@ parse_rsa_signature (void *cls, | |||
873 | int res; | 886 | int res; |
874 | void *buf; | 887 | void *buf; |
875 | 888 | ||
876 | str = json_string_value (root); | 889 | str = json_string_value(root); |
877 | if (NULL == str) | 890 | if (NULL == str) |
878 | { | 891 | { |
879 | GNUNET_break_op (0); | 892 | GNUNET_break_op(0); |
880 | return GNUNET_SYSERR; | 893 | return GNUNET_SYSERR; |
881 | } | 894 | } |
882 | size = (strlen (str) * 5) / 8; | 895 | size = (strlen(str) * 5) / 8; |
883 | buf = GNUNET_malloc (size); | 896 | buf = GNUNET_malloc(size); |
884 | res = GNUNET_STRINGS_string_to_data (str, | 897 | res = GNUNET_STRINGS_string_to_data(str, |
885 | strlen (str), | 898 | strlen(str), |
886 | buf, | 899 | buf, |
887 | size); | 900 | size); |
888 | if (GNUNET_OK != res) | 901 | if (GNUNET_OK != res) |
889 | { | 902 | { |
890 | GNUNET_free (buf); | 903 | GNUNET_free(buf); |
891 | GNUNET_break_op (0); | 904 | GNUNET_break_op(0); |
892 | return GNUNET_SYSERR; | 905 | return GNUNET_SYSERR; |
893 | } | 906 | } |
894 | if (NULL == (*sig = GNUNET_CRYPTO_rsa_signature_decode (buf, | 907 | if (NULL == (*sig = GNUNET_CRYPTO_rsa_signature_decode(buf, |
895 | size))) | 908 | size))) |
896 | { | 909 | { |
897 | GNUNET_break_op (0); | 910 | GNUNET_break_op(0); |
898 | GNUNET_free (buf); | 911 | GNUNET_free(buf); |
899 | return GNUNET_SYSERR; | 912 | return GNUNET_SYSERR; |
900 | } | 913 | } |
901 | GNUNET_free (buf); | 914 | GNUNET_free(buf); |
902 | return GNUNET_OK; | 915 | return GNUNET_OK; |
903 | } | 916 | } |
904 | 917 | ||
@@ -910,16 +923,16 @@ parse_rsa_signature (void *cls, | |||
910 | * @param[out] spec where to free the data | 923 | * @param[out] spec where to free the data |
911 | */ | 924 | */ |
912 | static void | 925 | static void |
913 | clean_rsa_signature (void *cls, | 926 | clean_rsa_signature(void *cls, |
914 | struct GNUNET_JSON_Specification *spec) | 927 | struct GNUNET_JSON_Specification *spec) |
915 | { | 928 | { |
916 | struct GNUNET_CRYPTO_RsaSignature **sig = spec->ptr; | 929 | struct GNUNET_CRYPTO_RsaSignature **sig = spec->ptr; |
917 | 930 | ||
918 | if (NULL != *sig) | 931 | if (NULL != *sig) |
919 | { | 932 | { |
920 | GNUNET_CRYPTO_rsa_signature_free (*sig); | 933 | GNUNET_CRYPTO_rsa_signature_free(*sig); |
921 | *sig = NULL; | 934 | *sig = NULL; |
922 | } | 935 | } |
923 | } | 936 | } |
924 | 937 | ||
925 | 938 | ||
@@ -930,8 +943,8 @@ clean_rsa_signature (void *cls, | |||
930 | * @param sig where to store the RSA signature found under @a name | 943 | * @param sig where to store the RSA signature found under @a name |
931 | */ | 944 | */ |
932 | struct GNUNET_JSON_Specification | 945 | struct GNUNET_JSON_Specification |
933 | GNUNET_JSON_spec_rsa_signature (const char *name, | 946 | GNUNET_JSON_spec_rsa_signature(const char *name, |
934 | struct GNUNET_CRYPTO_RsaSignature **sig) | 947 | struct GNUNET_CRYPTO_RsaSignature **sig) |
935 | { | 948 | { |
936 | struct GNUNET_JSON_Specification ret = { | 949 | struct GNUNET_JSON_Specification ret = { |
937 | .parser = &parse_rsa_signature, | 950 | .parser = &parse_rsa_signature, |
@@ -942,6 +955,7 @@ GNUNET_JSON_spec_rsa_signature (const char *name, | |||
942 | .ptr_size = 0, | 955 | .ptr_size = 0, |
943 | .size_ptr = NULL | 956 | .size_ptr = NULL |
944 | }; | 957 | }; |
958 | |||
945 | *sig = NULL; | 959 | *sig = NULL; |
946 | return ret; | 960 | return ret; |
947 | } | 961 | } |
@@ -956,18 +970,18 @@ GNUNET_JSON_spec_rsa_signature (const char *name, | |||
956 | * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error | 970 | * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error |
957 | */ | 971 | */ |
958 | static int | 972 | static int |
959 | parse_boolean (void *cls, | 973 | parse_boolean(void *cls, |
960 | json_t *root, | 974 | json_t *root, |
961 | struct GNUNET_JSON_Specification *spec) | 975 | struct GNUNET_JSON_Specification *spec) |
962 | { | 976 | { |
963 | int *bp = spec->ptr; | 977 | int *bp = spec->ptr; |
964 | 978 | ||
965 | if (! json_is_boolean (root)) | 979 | if (!json_is_boolean(root)) |
966 | { | 980 | { |
967 | GNUNET_break_op (0); | 981 | GNUNET_break_op(0); |
968 | return GNUNET_SYSERR; | 982 | return GNUNET_SYSERR; |
969 | } | 983 | } |
970 | *bp = json_boolean_value (root) ? GNUNET_YES : GNUNET_NO; | 984 | *bp = json_boolean_value(root) ? GNUNET_YES : GNUNET_NO; |
971 | return GNUNET_OK; | 985 | return GNUNET_OK; |
972 | } | 986 | } |
973 | 987 | ||
@@ -979,8 +993,8 @@ parse_boolean (void *cls, | |||
979 | * @param[out] boolean where to store the boolean found under @a name | 993 | * @param[out] boolean where to store the boolean found under @a name |
980 | */ | 994 | */ |
981 | struct GNUNET_JSON_Specification | 995 | struct GNUNET_JSON_Specification |
982 | GNUNET_JSON_spec_boolean (const char *name, | 996 | GNUNET_JSON_spec_boolean(const char *name, |
983 | int *boolean) | 997 | int *boolean) |
984 | { | 998 | { |
985 | struct GNUNET_JSON_Specification ret = { | 999 | struct GNUNET_JSON_Specification ret = { |
986 | .parser = &parse_boolean, | 1000 | .parser = &parse_boolean, |
@@ -988,9 +1002,10 @@ GNUNET_JSON_spec_boolean (const char *name, | |||
988 | .cls = NULL, | 1002 | .cls = NULL, |
989 | .field = name, | 1003 | .field = name, |
990 | .ptr = boolean, | 1004 | .ptr = boolean, |
991 | .ptr_size = sizeof (int), | 1005 | .ptr_size = sizeof(int), |
992 | .size_ptr = NULL | 1006 | .size_ptr = NULL |
993 | }; | 1007 | }; |
1008 | |||
994 | return ret; | 1009 | return ret; |
995 | } | 1010 | } |
996 | 1011 | ||