aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/include/gnunet_json_lib.h11
-rw-r--r--src/json/json_helper.c54
2 files changed, 65 insertions, 0 deletions
diff --git a/src/include/gnunet_json_lib.h b/src/include/gnunet_json_lib.h
index f6cabd589..27996f18d 100644
--- a/src/include/gnunet_json_lib.h
+++ b/src/include/gnunet_json_lib.h
@@ -219,6 +219,17 @@ GNUNET_JSON_spec_json (const char *name, json_t **jsonp);
219 219
220 220
221/** 221/**
222 * boolean.
223 *
224 * @param name name of the JSON field
225 * @param[out] b where to store the boolean found under @a name
226 */
227struct GNUNET_JSON_Specification
228GNUNET_JSON_spec_bool (const char *name,
229 bool *b);
230
231
232/**
222 * 8-bit integer. 233 * 8-bit integer.
223 * 234 *
224 * @param name name of the JSON field 235 * @param name name of the JSON field
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