aboutsummaryrefslogtreecommitdiff
path: root/src/json/json_helper.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2020-04-21 12:15:16 +0200
committerChristian Grothoff <christian@grothoff.org>2020-04-21 12:15:16 +0200
commit5f5a1c7b44f659058175da1f69abfa709f688890 (patch)
treec3494f5b9442a2403fab9cbf094a45e7adfaef19 /src/json/json_helper.c
parent30361fe0e89a72e2dd248a93824b06d858e4e81a (diff)
downloadgnunet-5f5a1c7b44f659058175da1f69abfa709f688890.tar.gz
gnunet-5f5a1c7b44f659058175da1f69abfa709f688890.zip
add JSON spec'er for booleans
Diffstat (limited to 'src/json/json_helper.c')
-rw-r--r--src/json/json_helper.c54
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 */
337static int
338parse_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 */
365struct GNUNET_JSON_Specification
366GNUNET_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