aboutsummaryrefslogtreecommitdiff
path: root/src/json/json_helper.c
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2018-01-22 17:05:38 +0100
committerFlorian Dold <florian.dold@gmail.com>2018-01-22 17:08:27 +0100
commit407e79aca5cc2caadb9c9a916fcb91c3e9f3c244 (patch)
tree5f2474b997452fb9a66ca2d4519eabed1d205dfb /src/json/json_helper.c
parente22c9d7e579210f39008923937e15b45fb226319 (diff)
downloadgnunet-407e79aca5cc2caadb9c9a916fcb91c3e9f3c244.tar.gz
gnunet-407e79aca5cc2caadb9c9a916fcb91c3e9f3c244.zip
implement boolean json spec
Diffstat (limited to 'src/json/json_helper.c')
-rw-r--r--src/json/json_helper.c48
1 files changed, 48 insertions, 0 deletions
diff --git a/src/json/json_helper.c b/src/json/json_helper.c
index 194ec5c76..c7eca97ec 100644
--- a/src/json/json_helper.c
+++ b/src/json/json_helper.c
@@ -943,4 +943,52 @@ GNUNET_JSON_spec_rsa_signature (const char *name,
943} 943}
944 944
945 945
946/**
947 * Parse given JSON object to an int as a boolean.
948 *
949 * @param cls closure, NULL
950 * @param root the json object representing data
951 * @param[out] spec where to write the data
952 * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error
953 */
954static int
955parse_boolean (void *cls,
956 json_t *root,
957 struct GNUNET_JSON_Specification *spec)
958{
959 int *bp = spec->ptr;
960
961 if (! json_is_boolean (root))
962 {
963 GNUNET_break_op (0);
964 return GNUNET_SYSERR;
965 }
966 *bp = json_boolean_value (root) ? GNUNET_YES : GNUNET_NO;
967 return GNUNET_OK;
968}
969
970
971/**
972 * Boolean (true mapped to GNUNET_YES, false mapped to GNUNET_NO).
973 *
974 * @param name name of the JSON field
975 * @param[out] boolean where to store the boolean found under @a name
976 */
977struct GNUNET_JSON_Specification
978GNUNET_JSON_spec_boolean (const char *name,
979 int *boolean)
980{
981 struct GNUNET_JSON_Specification ret = {
982 .parser = &parse_boolean,
983 .cleaner = NULL,
984 .cls = NULL,
985 .field = name,
986 .ptr = boolean,
987 .ptr_size = sizeof (int),
988 .size_ptr = NULL
989 };
990 return ret;
991}
992
993
946/* end of json_helper.c */ 994/* end of json_helper.c */