diff options
Diffstat (limited to 'src/json/json_helper.c')
-rw-r--r-- | src/json/json_helper.c | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/src/json/json_helper.c b/src/json/json_helper.c index 74a92ce9f..02bd6bfab 100644 --- a/src/json/json_helper.c +++ b/src/json/json_helper.c | |||
@@ -327,6 +327,60 @@ GNUNET_JSON_spec_json (const char *name, | |||
327 | 327 | ||
328 | 328 | ||
329 | /** | 329 | /** |
330 | * Parse given JSON object to a bool. | ||
331 | * | ||
332 | * @param cls closure, NULL | ||
333 | * @param root the json object representing data | ||
334 | * @param[out] spec where to write the data | ||
335 | * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error | ||
336 | */ | ||
337 | static int | ||
338 | parse_bool (void *cls, | ||
339 | json_t *root, | ||
340 | struct GNUNET_JSON_Specification *spec) | ||
341 | { | ||
342 | bool *b = spec->ptr; | ||
343 | |||
344 | if (json_true () == root) | ||
345 | { | ||
346 | *b = true; | ||
347 | return GNUNET_OK; | ||
348 | } | ||
349 | if (json_false () == root) | ||
350 | { | ||
351 | *b = false; | ||
352 | return GNUNET_OK; | ||
353 | } | ||
354 | GNUNET_break_op (0); | ||
355 | return GNUNET_SYSERR; | ||
356 | } | ||
357 | |||
358 | |||
359 | /** | ||
360 | * boolean. | ||
361 | * | ||
362 | * @param name name of the JSON field | ||
363 | * @param[out] b where to store the boolean found under @a name | ||
364 | */ | ||
365 | struct GNUNET_JSON_Specification | ||
366 | GNUNET_JSON_spec_bool (const char *name, | ||
367 | bool *b) | ||
368 | { | ||
369 | struct GNUNET_JSON_Specification ret = { | ||
370 | .parser = &parse_bool, | ||
371 | .cleaner = NULL, | ||
372 | .cls = NULL, | ||
373 | .field = name, | ||
374 | .ptr = b, | ||
375 | .ptr_size = sizeof(bool), | ||
376 | .size_ptr = NULL | ||
377 | }; | ||
378 | |||
379 | return ret; | ||
380 | } | ||
381 | |||
382 | |||
383 | /** | ||
330 | * Parse given JSON object to a uint8_t. | 384 | * Parse given JSON object to a uint8_t. |
331 | * | 385 | * |
332 | * @param cls closure, NULL | 386 | * @param cls closure, NULL |