diff options
Diffstat (limited to 'src/json/json_helper.c')
-rw-r--r-- | src/json/json_helper.c | 48 |
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 | */ | ||
954 | static int | ||
955 | parse_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 | */ | ||
977 | struct GNUNET_JSON_Specification | ||
978 | GNUNET_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 */ |