aboutsummaryrefslogtreecommitdiff
path: root/src/json/json_helper.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2019-10-05 15:09:28 +0200
committerChristian Grothoff <christian@grothoff.org>2019-10-05 15:09:28 +0200
commitc4e9ba925ffd758aaa3feee2ccfc0b76f26fe207 (patch)
treecac3ce030d77b4cbe7c7dc62ed58cfe6d24f73e1 /src/json/json_helper.c
parentfbb71d527c7d6babf269a8fefce1db291b9f7068 (diff)
downloadgnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.tar.gz
gnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.zip
global reindent, now with uncrustify hook enabled
Diffstat (limited to 'src/json/json_helper.c')
-rw-r--r--src/json/json_helper.c648
1 files changed, 324 insertions, 324 deletions
diff --git a/src/json/json_helper.c b/src/json/json_helper.c
index a732219c1..c3ba9c555 100644
--- a/src/json/json_helper.c
+++ b/src/json/json_helper.c
@@ -32,7 +32,7 @@
32 * End of a parser specification. 32 * End of a parser specification.
33 */ 33 */
34struct GNUNET_JSON_Specification 34struct GNUNET_JSON_Specification
35GNUNET_JSON_spec_end() 35GNUNET_JSON_spec_end ()
36{ 36{
37 struct GNUNET_JSON_Specification ret = { 37 struct GNUNET_JSON_Specification ret = {
38 .parser = NULL, 38 .parser = NULL,
@@ -53,33 +53,33 @@ GNUNET_JSON_spec_end()
53 * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error 53 * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error
54 */ 54 */
55static int 55static int
56parse_fixed_data(void *cls, 56parse_fixed_data (void *cls,
57 json_t *root, 57 json_t *root,
58 struct GNUNET_JSON_Specification *spec) 58 struct GNUNET_JSON_Specification *spec)
59{ 59{
60 const char *enc; 60 const char *enc;
61 unsigned int len; 61 unsigned int len;
62 62
63 if (NULL == (enc = json_string_value(root))) 63 if (NULL == (enc = json_string_value (root)))
64 { 64 {
65 GNUNET_break_op(0); 65 GNUNET_break_op (0);
66 return GNUNET_SYSERR; 66 return GNUNET_SYSERR;
67 } 67 }
68 len = strlen(enc); 68 len = strlen (enc);
69 if (((len * 5) / 8) != spec->ptr_size) 69 if (((len * 5) / 8) != spec->ptr_size)
70 { 70 {
71 GNUNET_break_op(0); 71 GNUNET_break_op (0);
72 return GNUNET_SYSERR; 72 return GNUNET_SYSERR;
73 } 73 }
74 if (GNUNET_OK != 74 if (GNUNET_OK !=
75 GNUNET_STRINGS_string_to_data(enc, 75 GNUNET_STRINGS_string_to_data (enc,
76 len, 76 len,
77 spec->ptr, 77 spec->ptr,
78 spec->ptr_size)) 78 spec->ptr_size))
79 { 79 {
80 GNUNET_break_op(0); 80 GNUNET_break_op (0);
81 return GNUNET_SYSERR; 81 return GNUNET_SYSERR;
82 } 82 }
83 return GNUNET_OK; 83 return GNUNET_OK;
84} 84}
85 85
@@ -93,9 +93,9 @@ parse_fixed_data(void *cls,
93 * @param size number of bytes expected in @a obj 93 * @param size number of bytes expected in @a obj
94 */ 94 */
95struct GNUNET_JSON_Specification 95struct GNUNET_JSON_Specification
96GNUNET_JSON_spec_fixed(const char *name, 96GNUNET_JSON_spec_fixed (const char *name,
97 void *obj, 97 void *obj,
98 size_t size) 98 size_t size)
99{ 99{
100 struct GNUNET_JSON_Specification ret = { 100 struct GNUNET_JSON_Specification ret = {
101 .parser = &parse_fixed_data, 101 .parser = &parse_fixed_data,
@@ -120,39 +120,39 @@ GNUNET_JSON_spec_fixed(const char *name,
120 * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error 120 * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error
121 */ 121 */
122static int 122static int
123parse_variable_data(void *cls, 123parse_variable_data (void *cls,
124 json_t *root, 124 json_t *root,
125 struct GNUNET_JSON_Specification *spec) 125 struct GNUNET_JSON_Specification *spec)
126{ 126{
127 const char *str; 127 const char *str;
128 size_t size; 128 size_t size;
129 void *data; 129 void *data;
130 int res; 130 int res;
131 131
132 str = json_string_value(root); 132 str = json_string_value (root);
133 if (NULL == str) 133 if (NULL == str)
134 { 134 {
135 GNUNET_break_op(0); 135 GNUNET_break_op (0);
136 return GNUNET_SYSERR; 136 return GNUNET_SYSERR;
137 } 137 }
138 size = (strlen(str) * 5) / 8; 138 size = (strlen (str) * 5) / 8;
139 if (size >= 1024) 139 if (size >= 1024)
140 { 140 {
141 GNUNET_break_op(0); 141 GNUNET_break_op (0);
142 return GNUNET_SYSERR; 142 return GNUNET_SYSERR;
143 } 143 }
144 data = GNUNET_malloc(size); 144 data = GNUNET_malloc (size);
145 res = GNUNET_STRINGS_string_to_data(str, 145 res = GNUNET_STRINGS_string_to_data (str,
146 strlen(str), 146 strlen (str),
147 data, 147 data,
148 size); 148 size);
149 if (GNUNET_OK != res) 149 if (GNUNET_OK != res)
150 { 150 {
151 GNUNET_break_op(0); 151 GNUNET_break_op (0);
152 GNUNET_free(data); 152 GNUNET_free (data);
153 return GNUNET_SYSERR; 153 return GNUNET_SYSERR;
154 } 154 }
155 *(void**)spec->ptr = data; 155 *(void**) spec->ptr = data;
156 *spec->size_ptr = size; 156 *spec->size_ptr = size;
157 return GNUNET_OK; 157 return GNUNET_OK;
158} 158}
@@ -165,15 +165,15 @@ parse_variable_data(void *cls,
165 * @param[out] spec where to free the data 165 * @param[out] spec where to free the data
166 */ 166 */
167static void 167static void
168clean_variable_data(void *cls, 168clean_variable_data (void *cls,
169 struct GNUNET_JSON_Specification *spec) 169 struct GNUNET_JSON_Specification *spec)
170{ 170{
171 if (0 != *spec->size_ptr) 171 if (0 != *spec->size_ptr)
172 { 172 {
173 GNUNET_free(*(void **)spec->ptr); 173 GNUNET_free (*(void **) spec->ptr);
174 *(void**)spec->ptr = NULL; 174 *(void**) spec->ptr = NULL;
175 *spec->size_ptr = 0; 175 *spec->size_ptr = 0;
176 } 176 }
177} 177}
178 178
179 179
@@ -186,9 +186,9 @@ clean_variable_data(void *cls,
186 * @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
187 */ 187 */
188struct GNUNET_JSON_Specification 188struct GNUNET_JSON_Specification
189GNUNET_JSON_spec_varsize(const char *name, 189GNUNET_JSON_spec_varsize (const char *name,
190 void **obj, 190 void **obj,
191 size_t *size) 191 size_t *size)
192{ 192{
193 struct GNUNET_JSON_Specification ret = { 193 struct GNUNET_JSON_Specification ret = {
194 .parser = &parse_variable_data, 194 .parser = &parse_variable_data,
@@ -215,19 +215,19 @@ GNUNET_JSON_spec_varsize(const char *name,
215 * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error 215 * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error
216 */ 216 */
217static int 217static int
218parse_string(void *cls, 218parse_string (void *cls,
219 json_t *root, 219 json_t *root,
220 struct GNUNET_JSON_Specification *spec) 220 struct GNUNET_JSON_Specification *spec)
221{ 221{
222 const char *str; 222 const char *str;
223 223
224 str = json_string_value(root); 224 str = json_string_value (root);
225 if (NULL == str) 225 if (NULL == str)
226 { 226 {
227 GNUNET_break_op(0); 227 GNUNET_break_op (0);
228 return GNUNET_SYSERR; 228 return GNUNET_SYSERR;
229 } 229 }
230 *(const char **)spec->ptr = str; 230 *(const char **) spec->ptr = str;
231 return GNUNET_OK; 231 return GNUNET_OK;
232} 232}
233 233
@@ -239,8 +239,8 @@ parse_string(void *cls,
239 * @param strptr where to store a pointer to the field 239 * @param strptr where to store a pointer to the field
240 */ 240 */
241struct GNUNET_JSON_Specification 241struct GNUNET_JSON_Specification
242GNUNET_JSON_spec_string(const char *name, 242GNUNET_JSON_spec_string (const char *name,
243 const char **strptr) 243 const char **strptr)
244{ 244{
245 struct GNUNET_JSON_Specification ret = { 245 struct GNUNET_JSON_Specification ret = {
246 .parser = &parse_string, 246 .parser = &parse_string,
@@ -266,17 +266,17 @@ GNUNET_JSON_spec_string(const char *name,
266 * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error 266 * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error
267 */ 267 */
268static int 268static int
269parse_object(void *cls, 269parse_object (void *cls,
270 json_t *root, 270 json_t *root,
271 struct GNUNET_JSON_Specification *spec) 271 struct GNUNET_JSON_Specification *spec)
272{ 272{
273 if (!(json_is_object(root) || json_is_array(root))) 273 if (! (json_is_object (root) || json_is_array (root)))
274 { 274 {
275 GNUNET_break_op(0); 275 GNUNET_break_op (0);
276 return GNUNET_SYSERR; 276 return GNUNET_SYSERR;
277 } 277 }
278 json_incref(root); 278 json_incref (root);
279 *(json_t **)spec->ptr = root; 279 *(json_t **) spec->ptr = root;
280 return GNUNET_OK; 280 return GNUNET_OK;
281} 281}
282 282
@@ -288,16 +288,16 @@ parse_object(void *cls,
288 * @param[out] spec where to free the data 288 * @param[out] spec where to free the data
289 */ 289 */
290static void 290static void
291clean_object(void *cls, 291clean_object (void *cls,
292 struct GNUNET_JSON_Specification *spec) 292 struct GNUNET_JSON_Specification *spec)
293{ 293{
294 json_t **ptr = (json_t **)spec->ptr; 294 json_t **ptr = (json_t **) spec->ptr;
295 295
296 if (NULL != *ptr) 296 if (NULL != *ptr)
297 { 297 {
298 json_decref(*ptr); 298 json_decref (*ptr);
299 *ptr = NULL; 299 *ptr = NULL;
300 } 300 }
301} 301}
302 302
303 303
@@ -308,8 +308,8 @@ clean_object(void *cls,
308 * @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
309 */ 309 */
310struct GNUNET_JSON_Specification 310struct GNUNET_JSON_Specification
311GNUNET_JSON_spec_json(const char *name, 311GNUNET_JSON_spec_json (const char *name,
312 json_t **jsonp) 312 json_t **jsonp)
313{ 313{
314 struct GNUNET_JSON_Specification ret = { 314 struct GNUNET_JSON_Specification ret = {
315 .parser = &parse_object, 315 .parser = &parse_object,
@@ -335,25 +335,25 @@ GNUNET_JSON_spec_json(const char *name,
335 * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error 335 * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error
336 */ 336 */
337static int 337static int
338parse_u8(void *cls, 338parse_u8 (void *cls,
339 json_t *root, 339 json_t *root,
340 struct GNUNET_JSON_Specification *spec) 340 struct GNUNET_JSON_Specification *spec)
341{ 341{
342 json_int_t val; 342 json_int_t val;
343 uint8_t *up = spec->ptr; 343 uint8_t *up = spec->ptr;
344 344
345 if (!json_is_integer(root)) 345 if (! json_is_integer (root))
346 { 346 {
347 GNUNET_break_op(0); 347 GNUNET_break_op (0);
348 return GNUNET_SYSERR; 348 return GNUNET_SYSERR;
349 } 349 }
350 val = json_integer_value(root); 350 val = json_integer_value (root);
351 if ((0 > val) || (val > UINT8_MAX)) 351 if ((0 > val) || (val > UINT8_MAX))
352 { 352 {
353 GNUNET_break_op(0); 353 GNUNET_break_op (0);
354 return GNUNET_SYSERR; 354 return GNUNET_SYSERR;
355 } 355 }
356 *up = (uint8_t)val; 356 *up = (uint8_t) val;
357 return GNUNET_OK; 357 return GNUNET_OK;
358} 358}
359 359
@@ -365,8 +365,8 @@ parse_u8(void *cls,
365 * @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
366 */ 366 */
367struct GNUNET_JSON_Specification 367struct GNUNET_JSON_Specification
368GNUNET_JSON_spec_uint8(const char *name, 368GNUNET_JSON_spec_uint8 (const char *name,
369 uint8_t *u8) 369 uint8_t *u8)
370{ 370{
371 struct GNUNET_JSON_Specification ret = { 371 struct GNUNET_JSON_Specification ret = {
372 .parser = &parse_u8, 372 .parser = &parse_u8,
@@ -391,25 +391,25 @@ GNUNET_JSON_spec_uint8(const char *name,
391 * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error 391 * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error
392 */ 392 */
393static int 393static int
394parse_u16(void *cls, 394parse_u16 (void *cls,
395 json_t *root, 395 json_t *root,
396 struct GNUNET_JSON_Specification *spec) 396 struct GNUNET_JSON_Specification *spec)
397{ 397{
398 json_int_t val; 398 json_int_t val;
399 uint16_t *up = spec->ptr; 399 uint16_t *up = spec->ptr;
400 400
401 if (!json_is_integer(root)) 401 if (! json_is_integer (root))
402 { 402 {
403 GNUNET_break_op(0); 403 GNUNET_break_op (0);
404 return GNUNET_SYSERR; 404 return GNUNET_SYSERR;
405 } 405 }
406 val = json_integer_value(root); 406 val = json_integer_value (root);
407 if ((0 > val) || (val > UINT16_MAX)) 407 if ((0 > val) || (val > UINT16_MAX))
408 { 408 {
409 GNUNET_break_op(0); 409 GNUNET_break_op (0);
410 return GNUNET_SYSERR; 410 return GNUNET_SYSERR;
411 } 411 }
412 *up = (uint16_t)val; 412 *up = (uint16_t) val;
413 return GNUNET_OK; 413 return GNUNET_OK;
414} 414}
415 415
@@ -421,8 +421,8 @@ parse_u16(void *cls,
421 * @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
422 */ 422 */
423struct GNUNET_JSON_Specification 423struct GNUNET_JSON_Specification
424GNUNET_JSON_spec_uint16(const char *name, 424GNUNET_JSON_spec_uint16 (const char *name,
425 uint16_t *u16) 425 uint16_t *u16)
426{ 426{
427 struct GNUNET_JSON_Specification ret = { 427 struct GNUNET_JSON_Specification ret = {
428 .parser = &parse_u16, 428 .parser = &parse_u16,
@@ -447,25 +447,25 @@ GNUNET_JSON_spec_uint16(const char *name,
447 * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error 447 * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error
448 */ 448 */
449static int 449static int
450parse_u32(void *cls, 450parse_u32 (void *cls,
451 json_t *root, 451 json_t *root,
452 struct GNUNET_JSON_Specification *spec) 452 struct GNUNET_JSON_Specification *spec)
453{ 453{
454 json_int_t val; 454 json_int_t val;
455 uint32_t *up = spec->ptr; 455 uint32_t *up = spec->ptr;
456 456
457 if (!json_is_integer(root)) 457 if (! json_is_integer (root))
458 { 458 {
459 GNUNET_break_op(0); 459 GNUNET_break_op (0);
460 return GNUNET_SYSERR; 460 return GNUNET_SYSERR;
461 } 461 }
462 val = json_integer_value(root); 462 val = json_integer_value (root);
463 if ((0 > val) || (val > UINT32_MAX)) 463 if ((0 > val) || (val > UINT32_MAX))
464 { 464 {
465 GNUNET_break_op(0); 465 GNUNET_break_op (0);
466 return GNUNET_SYSERR; 466 return GNUNET_SYSERR;
467 } 467 }
468 *up = (uint32_t)val; 468 *up = (uint32_t) val;
469 return GNUNET_OK; 469 return GNUNET_OK;
470} 470}
471 471
@@ -477,8 +477,8 @@ parse_u32(void *cls,
477 * @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
478 */ 478 */
479struct GNUNET_JSON_Specification 479struct GNUNET_JSON_Specification
480GNUNET_JSON_spec_uint32(const char *name, 480GNUNET_JSON_spec_uint32 (const char *name,
481 uint32_t *u32) 481 uint32_t *u32)
482{ 482{
483 struct GNUNET_JSON_Specification ret = { 483 struct GNUNET_JSON_Specification ret = {
484 .parser = &parse_u32, 484 .parser = &parse_u32,
@@ -503,20 +503,20 @@ GNUNET_JSON_spec_uint32(const char *name,
503 * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error 503 * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error
504 */ 504 */
505static int 505static int
506parse_u64(void *cls, 506parse_u64 (void *cls,
507 json_t *root, 507 json_t *root,
508 struct GNUNET_JSON_Specification *spec) 508 struct GNUNET_JSON_Specification *spec)
509{ 509{
510 json_int_t val; 510 json_int_t val;
511 uint64_t *up = spec->ptr; 511 uint64_t *up = spec->ptr;
512 512
513 if (!json_is_integer(root)) 513 if (! json_is_integer (root))
514 { 514 {
515 GNUNET_break_op(0); 515 GNUNET_break_op (0);
516 return GNUNET_SYSERR; 516 return GNUNET_SYSERR;
517 } 517 }
518 val = json_integer_value(root); 518 val = json_integer_value (root);
519 *up = (uint64_t)val; 519 *up = (uint64_t) val;
520 return GNUNET_OK; 520 return GNUNET_OK;
521} 521}
522 522
@@ -528,8 +528,8 @@ parse_u64(void *cls,
528 * @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
529 */ 529 */
530struct GNUNET_JSON_Specification 530struct GNUNET_JSON_Specification
531GNUNET_JSON_spec_uint64(const char *name, 531GNUNET_JSON_spec_uint64 (const char *name,
532 uint64_t *u64) 532 uint64_t *u64)
533{ 533{
534 struct GNUNET_JSON_Specification ret = { 534 struct GNUNET_JSON_Specification ret = {
535 .parser = &parse_u64, 535 .parser = &parse_u64,
@@ -556,45 +556,45 @@ GNUNET_JSON_spec_uint64(const char *name,
556 * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error 556 * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error
557 */ 557 */
558static int 558static int
559parse_abs_time(void *cls, 559parse_abs_time (void *cls,
560 json_t *root, 560 json_t *root,
561 struct GNUNET_JSON_Specification *spec) 561 struct GNUNET_JSON_Specification *spec)
562{ 562{
563 struct GNUNET_TIME_Absolute *abs = spec->ptr; 563 struct GNUNET_TIME_Absolute *abs = spec->ptr;
564 const char *val; 564 const char *val;
565 unsigned long long int tval; 565 unsigned long long int tval;
566 566
567 val = json_string_value(root); 567 val = json_string_value (root);
568 if (NULL == val) 568 if (NULL == val)
569 { 569 {
570 GNUNET_break_op(0); 570 GNUNET_break_op (0);
571 return GNUNET_SYSERR; 571 return GNUNET_SYSERR;
572 } 572 }
573 if ((0 == strcasecmp(val, 573 if ((0 == strcasecmp (val,
574 "/forever/")) || 574 "/forever/")) ||
575 (0 == strcasecmp(val, 575 (0 == strcasecmp (val,
576 "/end of time/")) || 576 "/end of time/")) ||
577 (0 == strcasecmp(val, 577 (0 == strcasecmp (val,
578 "/never/"))) 578 "/never/")))
579 { 579 {
580 *abs = GNUNET_TIME_UNIT_FOREVER_ABS; 580 *abs = GNUNET_TIME_UNIT_FOREVER_ABS;
581 return GNUNET_OK; 581 return GNUNET_OK;
582 } 582 }
583 if (1 != sscanf(val, 583 if (1 != sscanf (val,
584 "/Date(%llu)/", 584 "/Date(%llu)/",
585 &tval)) 585 &tval))
586 { 586 {
587 GNUNET_break_op(0); 587 GNUNET_break_op (0);
588 return GNUNET_SYSERR; 588 return GNUNET_SYSERR;
589 } 589 }
590 /* 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 */
591 abs->abs_value_us = tval * 1000LL * 1000LL; 591 abs->abs_value_us = tval * 1000LL * 1000LL;
592 if ((abs->abs_value_us) / 1000LL / 1000LL != tval) 592 if ((abs->abs_value_us) / 1000LL / 1000LL != tval)
593 { 593 {
594 /* Integer overflow */ 594 /* Integer overflow */
595 GNUNET_break_op(0); 595 GNUNET_break_op (0);
596 return GNUNET_SYSERR; 596 return GNUNET_SYSERR;
597 } 597 }
598 return GNUNET_OK; 598 return GNUNET_OK;
599} 599}
600 600
@@ -606,8 +606,8 @@ parse_abs_time(void *cls,
606 * @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
607 */ 607 */
608struct GNUNET_JSON_Specification 608struct GNUNET_JSON_Specification
609GNUNET_JSON_spec_absolute_time(const char *name, 609GNUNET_JSON_spec_absolute_time (const char *name,
610 struct GNUNET_TIME_Absolute *at) 610 struct GNUNET_TIME_Absolute *at)
611{ 611{
612 struct GNUNET_JSON_Specification ret = { 612 struct GNUNET_JSON_Specification ret = {
613 .parser = &parse_abs_time, 613 .parser = &parse_abs_time,
@@ -632,47 +632,47 @@ GNUNET_JSON_spec_absolute_time(const char *name,
632 * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error 632 * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error
633 */ 633 */
634static int 634static int
635parse_abs_time_nbo(void *cls, 635parse_abs_time_nbo (void *cls,
636 json_t *root, 636 json_t *root,
637 struct GNUNET_JSON_Specification *spec) 637 struct GNUNET_JSON_Specification *spec)
638{ 638{
639 struct GNUNET_TIME_AbsoluteNBO *abs = spec->ptr; 639 struct GNUNET_TIME_AbsoluteNBO *abs = spec->ptr;
640 const char *val; 640 const char *val;
641 unsigned long long int tval; 641 unsigned long long int tval;
642 struct GNUNET_TIME_Absolute a; 642 struct GNUNET_TIME_Absolute a;
643 643
644 val = json_string_value(root); 644 val = json_string_value (root);
645 if (NULL == val) 645 if (NULL == val)
646 { 646 {
647 GNUNET_break_op(0); 647 GNUNET_break_op (0);
648 return GNUNET_SYSERR; 648 return GNUNET_SYSERR;
649 } 649 }
650 if ((0 == strcasecmp(val, 650 if ((0 == strcasecmp (val,
651 "/forever/")) || 651 "/forever/")) ||
652 (0 == strcasecmp(val, 652 (0 == strcasecmp (val,
653 "/end of time/")) || 653 "/end of time/")) ||
654 (0 == strcasecmp(val, 654 (0 == strcasecmp (val,
655 "/never/"))) 655 "/never/")))
656 { 656 {
657 *abs = GNUNET_TIME_absolute_hton(GNUNET_TIME_UNIT_FOREVER_ABS); 657 *abs = GNUNET_TIME_absolute_hton (GNUNET_TIME_UNIT_FOREVER_ABS);
658 return GNUNET_OK; 658 return GNUNET_OK;
659 } 659 }
660 if (1 != sscanf(val, 660 if (1 != sscanf (val,
661 "/Date(%llu)/", 661 "/Date(%llu)/",
662 &tval)) 662 &tval))
663 { 663 {
664 GNUNET_break_op(0); 664 GNUNET_break_op (0);
665 return GNUNET_SYSERR; 665 return GNUNET_SYSERR;
666 } 666 }
667 /* 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 */
668 a.abs_value_us = tval * 1000LL * 1000LL; 668 a.abs_value_us = tval * 1000LL * 1000LL;
669 if ((a.abs_value_us) / 1000LL / 1000LL != tval) 669 if ((a.abs_value_us) / 1000LL / 1000LL != tval)
670 { 670 {
671 /* Integer overflow */ 671 /* Integer overflow */
672 GNUNET_break_op(0); 672 GNUNET_break_op (0);
673 return GNUNET_SYSERR; 673 return GNUNET_SYSERR;
674 } 674 }
675 *abs = GNUNET_TIME_absolute_hton(a); 675 *abs = GNUNET_TIME_absolute_hton (a);
676 return GNUNET_OK; 676 return GNUNET_OK;
677} 677}
678 678
@@ -684,8 +684,8 @@ parse_abs_time_nbo(void *cls,
684 * @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
685 */ 685 */
686struct GNUNET_JSON_Specification 686struct GNUNET_JSON_Specification
687GNUNET_JSON_spec_absolute_time_nbo(const char *name, 687GNUNET_JSON_spec_absolute_time_nbo (const char *name,
688 struct GNUNET_TIME_AbsoluteNBO *at) 688 struct GNUNET_TIME_AbsoluteNBO *at)
689{ 689{
690 struct GNUNET_JSON_Specification ret = { 690 struct GNUNET_JSON_Specification ret = {
691 .parser = &parse_abs_time_nbo, 691 .parser = &parse_abs_time_nbo,
@@ -710,41 +710,41 @@ GNUNET_JSON_spec_absolute_time_nbo(const char *name,
710 * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error 710 * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error
711 */ 711 */
712static int 712static int
713parse_rel_time(void *cls, 713parse_rel_time (void *cls,
714 json_t *root, 714 json_t *root,
715 struct GNUNET_JSON_Specification *spec) 715 struct GNUNET_JSON_Specification *spec)
716{ 716{
717 struct GNUNET_TIME_Relative *rel = spec->ptr; 717 struct GNUNET_TIME_Relative *rel = spec->ptr;
718 const char *val; 718 const char *val;
719 unsigned long long int tval; 719 unsigned long long int tval;
720 720
721 val = json_string_value(root); 721 val = json_string_value (root);
722 if (NULL == val) 722 if (NULL == val)
723 { 723 {
724 GNUNET_break_op(0); 724 GNUNET_break_op (0);
725 return GNUNET_SYSERR; 725 return GNUNET_SYSERR;
726 } 726 }
727 if ((0 == strcasecmp(val, 727 if ((0 == strcasecmp (val,
728 "/forever/"))) 728 "/forever/")))
729 { 729 {
730 *rel = GNUNET_TIME_UNIT_FOREVER_REL; 730 *rel = GNUNET_TIME_UNIT_FOREVER_REL;
731 return GNUNET_OK; 731 return GNUNET_OK;
732 } 732 }
733 if (1 != sscanf(val, 733 if (1 != sscanf (val,
734 "/Delay(%llu)/", 734 "/Delay(%llu)/",
735 &tval)) 735 &tval))
736 { 736 {
737 GNUNET_break_op(0); 737 GNUNET_break_op (0);
738 return GNUNET_SYSERR; 738 return GNUNET_SYSERR;
739 } 739 }
740 /* 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 */
741 rel->rel_value_us = tval * 1000LL * 1000LL; 741 rel->rel_value_us = tval * 1000LL * 1000LL;
742 if ((rel->rel_value_us) / 1000LL / 1000LL != tval) 742 if ((rel->rel_value_us) / 1000LL / 1000LL != tval)
743 { 743 {
744 /* Integer overflow */ 744 /* Integer overflow */
745 GNUNET_break_op(0); 745 GNUNET_break_op (0);
746 return GNUNET_SYSERR; 746 return GNUNET_SYSERR;
747 } 747 }
748 return GNUNET_OK; 748 return GNUNET_OK;
749} 749}
750 750
@@ -756,8 +756,8 @@ parse_rel_time(void *cls,
756 * @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
757 */ 757 */
758struct GNUNET_JSON_Specification 758struct GNUNET_JSON_Specification
759GNUNET_JSON_spec_relative_time(const char *name, 759GNUNET_JSON_spec_relative_time (const char *name,
760 struct GNUNET_TIME_Relative *rt) 760 struct GNUNET_TIME_Relative *rt)
761{ 761{
762 struct GNUNET_JSON_Specification ret = { 762 struct GNUNET_JSON_Specification ret = {
763 .parser = &parse_rel_time, 763 .parser = &parse_rel_time,
@@ -782,9 +782,9 @@ GNUNET_JSON_spec_relative_time(const char *name,
782 * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error 782 * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error
783 */ 783 */
784static int 784static int
785parse_rsa_public_key(void *cls, 785parse_rsa_public_key (void *cls,
786 json_t *root, 786 json_t *root,
787 struct GNUNET_JSON_Specification *spec) 787 struct GNUNET_JSON_Specification *spec)
788{ 788{
789 struct GNUNET_CRYPTO_RsaPublicKey **pk = spec->ptr; 789 struct GNUNET_CRYPTO_RsaPublicKey **pk = spec->ptr;
790 const char *enc; 790 const char *enc;
@@ -792,32 +792,32 @@ parse_rsa_public_key(void *cls,
792 size_t len; 792 size_t len;
793 size_t buf_len; 793 size_t buf_len;
794 794
795 if (NULL == (enc = json_string_value(root))) 795 if (NULL == (enc = json_string_value (root)))
796 { 796 {
797 GNUNET_break_op(0); 797 GNUNET_break_op (0);
798 return GNUNET_SYSERR; 798 return GNUNET_SYSERR;
799 } 799 }
800 len = strlen(enc); 800 len = strlen (enc);
801 buf_len = (len * 5) / 8; 801 buf_len = (len * 5) / 8;
802 buf = GNUNET_malloc(buf_len); 802 buf = GNUNET_malloc (buf_len);
803 if (GNUNET_OK != 803 if (GNUNET_OK !=
804 GNUNET_STRINGS_string_to_data(enc, 804 GNUNET_STRINGS_string_to_data (enc,
805 len, 805 len,
806 buf, 806 buf,
807 buf_len)) 807 buf_len))
808 { 808 {
809 GNUNET_break_op(0); 809 GNUNET_break_op (0);
810 GNUNET_free(buf); 810 GNUNET_free (buf);
811 return GNUNET_SYSERR; 811 return GNUNET_SYSERR;
812 } 812 }
813 if (NULL == (*pk = GNUNET_CRYPTO_rsa_public_key_decode(buf, 813 if (NULL == (*pk = GNUNET_CRYPTO_rsa_public_key_decode (buf,
814 buf_len))) 814 buf_len)))
815 { 815 {
816 GNUNET_break_op(0); 816 GNUNET_break_op (0);
817 GNUNET_free(buf); 817 GNUNET_free (buf);
818 return GNUNET_SYSERR; 818 return GNUNET_SYSERR;
819 } 819 }
820 GNUNET_free(buf); 820 GNUNET_free (buf);
821 return GNUNET_OK; 821 return GNUNET_OK;
822} 822}
823 823
@@ -829,16 +829,16 @@ parse_rsa_public_key(void *cls,
829 * @param[out] spec where to free the data 829 * @param[out] spec where to free the data
830 */ 830 */
831static void 831static void
832clean_rsa_public_key(void *cls, 832clean_rsa_public_key (void *cls,
833 struct GNUNET_JSON_Specification *spec) 833 struct GNUNET_JSON_Specification *spec)
834{ 834{
835 struct GNUNET_CRYPTO_RsaPublicKey **pk = spec->ptr; 835 struct GNUNET_CRYPTO_RsaPublicKey **pk = spec->ptr;
836 836
837 if (NULL != *pk) 837 if (NULL != *pk)
838 { 838 {
839 GNUNET_CRYPTO_rsa_public_key_free(*pk); 839 GNUNET_CRYPTO_rsa_public_key_free (*pk);
840 *pk = NULL; 840 *pk = NULL;
841 } 841 }
842} 842}
843 843
844 844
@@ -849,8 +849,8 @@ clean_rsa_public_key(void *cls,
849 * @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
850 */ 850 */
851struct GNUNET_JSON_Specification 851struct GNUNET_JSON_Specification
852GNUNET_JSON_spec_rsa_public_key(const char *name, 852GNUNET_JSON_spec_rsa_public_key (const char *name,
853 struct GNUNET_CRYPTO_RsaPublicKey **pk) 853 struct GNUNET_CRYPTO_RsaPublicKey **pk)
854{ 854{
855 struct GNUNET_JSON_Specification ret = { 855 struct GNUNET_JSON_Specification ret = {
856 .parser = &parse_rsa_public_key, 856 .parser = &parse_rsa_public_key,
@@ -876,9 +876,9 @@ GNUNET_JSON_spec_rsa_public_key(const char *name,
876 * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error 876 * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error
877 */ 877 */
878static int 878static int
879parse_rsa_signature(void *cls, 879parse_rsa_signature (void *cls,
880 json_t *root, 880 json_t *root,
881 struct GNUNET_JSON_Specification *spec) 881 struct GNUNET_JSON_Specification *spec)
882{ 882{
883 struct GNUNET_CRYPTO_RsaSignature **sig = spec->ptr; 883 struct GNUNET_CRYPTO_RsaSignature **sig = spec->ptr;
884 size_t size; 884 size_t size;
@@ -886,32 +886,32 @@ parse_rsa_signature(void *cls,
886 int res; 886 int res;
887 void *buf; 887 void *buf;
888 888
889 str = json_string_value(root); 889 str = json_string_value (root);
890 if (NULL == str) 890 if (NULL == str)
891 { 891 {
892 GNUNET_break_op(0); 892 GNUNET_break_op (0);
893 return GNUNET_SYSERR; 893 return GNUNET_SYSERR;
894 } 894 }
895 size = (strlen(str) * 5) / 8; 895 size = (strlen (str) * 5) / 8;
896 buf = GNUNET_malloc(size); 896 buf = GNUNET_malloc (size);
897 res = GNUNET_STRINGS_string_to_data(str, 897 res = GNUNET_STRINGS_string_to_data (str,
898 strlen(str), 898 strlen (str),
899 buf, 899 buf,
900 size); 900 size);
901 if (GNUNET_OK != res) 901 if (GNUNET_OK != res)
902 { 902 {
903 GNUNET_free(buf); 903 GNUNET_free (buf);
904 GNUNET_break_op(0); 904 GNUNET_break_op (0);
905 return GNUNET_SYSERR; 905 return GNUNET_SYSERR;
906 } 906 }
907 if (NULL == (*sig = GNUNET_CRYPTO_rsa_signature_decode(buf, 907 if (NULL == (*sig = GNUNET_CRYPTO_rsa_signature_decode (buf,
908 size))) 908 size)))
909 { 909 {
910 GNUNET_break_op(0); 910 GNUNET_break_op (0);
911 GNUNET_free(buf); 911 GNUNET_free (buf);
912 return GNUNET_SYSERR; 912 return GNUNET_SYSERR;
913 } 913 }
914 GNUNET_free(buf); 914 GNUNET_free (buf);
915 return GNUNET_OK; 915 return GNUNET_OK;
916} 916}
917 917
@@ -923,16 +923,16 @@ parse_rsa_signature(void *cls,
923 * @param[out] spec where to free the data 923 * @param[out] spec where to free the data
924 */ 924 */
925static void 925static void
926clean_rsa_signature(void *cls, 926clean_rsa_signature (void *cls,
927 struct GNUNET_JSON_Specification *spec) 927 struct GNUNET_JSON_Specification *spec)
928{ 928{
929 struct GNUNET_CRYPTO_RsaSignature **sig = spec->ptr; 929 struct GNUNET_CRYPTO_RsaSignature **sig = spec->ptr;
930 930
931 if (NULL != *sig) 931 if (NULL != *sig)
932 { 932 {
933 GNUNET_CRYPTO_rsa_signature_free(*sig); 933 GNUNET_CRYPTO_rsa_signature_free (*sig);
934 *sig = NULL; 934 *sig = NULL;
935 } 935 }
936} 936}
937 937
938 938
@@ -943,8 +943,8 @@ clean_rsa_signature(void *cls,
943 * @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
944 */ 944 */
945struct GNUNET_JSON_Specification 945struct GNUNET_JSON_Specification
946GNUNET_JSON_spec_rsa_signature(const char *name, 946GNUNET_JSON_spec_rsa_signature (const char *name,
947 struct GNUNET_CRYPTO_RsaSignature **sig) 947 struct GNUNET_CRYPTO_RsaSignature **sig)
948{ 948{
949 struct GNUNET_JSON_Specification ret = { 949 struct GNUNET_JSON_Specification ret = {
950 .parser = &parse_rsa_signature, 950 .parser = &parse_rsa_signature,
@@ -970,18 +970,18 @@ GNUNET_JSON_spec_rsa_signature(const char *name,
970 * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error 970 * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error
971 */ 971 */
972static int 972static int
973parse_boolean(void *cls, 973parse_boolean (void *cls,
974 json_t *root, 974 json_t *root,
975 struct GNUNET_JSON_Specification *spec) 975 struct GNUNET_JSON_Specification *spec)
976{ 976{
977 int *bp = spec->ptr; 977 int *bp = spec->ptr;
978 978
979 if (!json_is_boolean(root)) 979 if (! json_is_boolean (root))
980 { 980 {
981 GNUNET_break_op(0); 981 GNUNET_break_op (0);
982 return GNUNET_SYSERR; 982 return GNUNET_SYSERR;
983 } 983 }
984 *bp = json_boolean_value(root) ? GNUNET_YES : GNUNET_NO; 984 *bp = json_boolean_value (root) ? GNUNET_YES : GNUNET_NO;
985 return GNUNET_OK; 985 return GNUNET_OK;
986} 986}
987 987
@@ -993,8 +993,8 @@ parse_boolean(void *cls,
993 * @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
994 */ 994 */
995struct GNUNET_JSON_Specification 995struct GNUNET_JSON_Specification
996GNUNET_JSON_spec_boolean(const char *name, 996GNUNET_JSON_spec_boolean (const char *name,
997 int *boolean) 997 int *boolean)
998{ 998{
999 struct GNUNET_JSON_Specification ret = { 999 struct GNUNET_JSON_Specification ret = {
1000 .parser = &parse_boolean, 1000 .parser = &parse_boolean,