From 1eadd51205794a18e74f135672c96613d4f8734b Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Thu, 2 May 2019 22:24:42 +0200 Subject: preparatory change to GNUNET_JSON_post_parser() API for future compression support --- src/include/gnunet_json_lib.h | 64 ++++++++++++++++++------------------------- 1 file changed, 26 insertions(+), 38 deletions(-) (limited to 'src/include') diff --git a/src/include/gnunet_json_lib.h b/src/include/gnunet_json_lib.h index c8f09d4e4..32de2208a 100644 --- a/src/include/gnunet_json_lib.h +++ b/src/include/gnunet_json_lib.h @@ -30,7 +30,7 @@ #include "gnunet_util_lib.h" #include "gnunet_gnsrecord_lib.h" #include - +#include /* ****************** Generic parser interface ******************* */ @@ -49,10 +49,9 @@ struct GNUNET_JSON_Specification; * @return #GNUNET_SYSERR on error, * #GNUNET_OK on success */ -typedef int -(*GNUNET_JSON_Parser)(void *cls, - json_t *root, - struct GNUNET_JSON_Specification *spec); +typedef int (*GNUNET_JSON_Parser) (void *cls, + json_t *root, + struct GNUNET_JSON_Specification *spec); /** @@ -61,9 +60,8 @@ typedef int * @param cls closure * @param spec our specification entry with data to clean. */ -typedef void -(*GNUNET_JSON_Cleaner)(void *cls, - struct GNUNET_JSON_Specification *spec); +typedef void (*GNUNET_JSON_Cleaner) (void *cls, + struct GNUNET_JSON_Specification *spec); /** @@ -106,7 +104,6 @@ struct GNUNET_JSON_Specification * Where should we store the final size of @e ptr. */ size_t *size_ptr; - }; @@ -140,7 +137,6 @@ void GNUNET_JSON_parse_free (struct GNUNET_JSON_Specification *spec); - /* ****************** Canonical parser specifications ******************* */ @@ -160,9 +156,7 @@ GNUNET_JSON_spec_end (void); * @param size number of bytes expected in @a obj */ struct GNUNET_JSON_Specification -GNUNET_JSON_spec_fixed (const char *name, - void *obj, - size_t size); +GNUNET_JSON_spec_fixed (const char *name, void *obj, size_t size); /** @@ -172,7 +166,8 @@ GNUNET_JSON_spec_fixed (const char *name, * @param name name of the JSON field * @param obj pointer where to write the data (type of `*obj` will determine size) */ -#define GNUNET_JSON_spec_fixed_auto(name,obj) GNUNET_JSON_spec_fixed (name, obj, sizeof (*obj)) +#define GNUNET_JSON_spec_fixed_auto(name, obj) \ + GNUNET_JSON_spec_fixed (name, obj, sizeof (*obj)) /** @@ -184,9 +179,7 @@ GNUNET_JSON_spec_fixed (const char *name, * @param[out] size where to store the number of bytes allocated for @a obj */ struct GNUNET_JSON_Specification -GNUNET_JSON_spec_varsize (const char *name, - void **obj, - size_t *size); +GNUNET_JSON_spec_varsize (const char *name, void **obj, size_t *size); /** @@ -196,8 +189,7 @@ GNUNET_JSON_spec_varsize (const char *name, * @param strptr where to store a pointer to the field */ struct GNUNET_JSON_Specification -GNUNET_JSON_spec_string (const char *name, - const char **strptr); +GNUNET_JSON_spec_string (const char *name, const char **strptr); /** * JSON object. @@ -206,8 +198,7 @@ GNUNET_JSON_spec_string (const char *name, * @param[out] jsonp where to store the JSON found under @a name */ struct GNUNET_JSON_Specification -GNUNET_JSON_spec_json (const char *name, - json_t **jsonp); +GNUNET_JSON_spec_json (const char *name, json_t **jsonp); /** @@ -217,8 +208,7 @@ GNUNET_JSON_spec_json (const char *name, * @param[out] u8 where to store the integer found under @a name */ struct GNUNET_JSON_Specification -GNUNET_JSON_spec_uint8 (const char *name, - uint8_t *u8); +GNUNET_JSON_spec_uint8 (const char *name, uint8_t *u8); /** @@ -228,8 +218,7 @@ GNUNET_JSON_spec_uint8 (const char *name, * @param[out] u16 where to store the integer found under @a name */ struct GNUNET_JSON_Specification -GNUNET_JSON_spec_uint16 (const char *name, - uint16_t *u16); +GNUNET_JSON_spec_uint16 (const char *name, uint16_t *u16); /** @@ -239,8 +228,7 @@ GNUNET_JSON_spec_uint16 (const char *name, * @param[out] u32 where to store the integer found under @a name */ struct GNUNET_JSON_Specification -GNUNET_JSON_spec_uint32 (const char *name, - uint32_t *u32); +GNUNET_JSON_spec_uint32 (const char *name, uint32_t *u32); /** @@ -250,8 +238,7 @@ GNUNET_JSON_spec_uint32 (const char *name, * @param[out] u64 where to store the integer found under @a name */ struct GNUNET_JSON_Specification -GNUNET_JSON_spec_uint64 (const char *name, - uint64_t *u64); +GNUNET_JSON_spec_uint64 (const char *name, uint64_t *u64); /** * Boolean (true mapped to GNUNET_YES, false mapped to GNUNET_NO). @@ -260,8 +247,7 @@ GNUNET_JSON_spec_uint64 (const char *name, * @param[out] boolean where to store the boolean found under @a name */ struct GNUNET_JSON_Specification -GNUNET_JSON_spec_boolean (const char *name, - int *boolean); +GNUNET_JSON_spec_boolean (const char *name, int *boolean); /* ************ GNUnet-specific parser specifications ******************* */ @@ -285,7 +271,7 @@ GNUNET_JSON_spec_absolute_time (const char *name, */ struct GNUNET_JSON_Specification GNUNET_JSON_spec_absolute_time_nbo (const char *name, - struct GNUNET_TIME_AbsoluteNBO *at); + struct GNUNET_TIME_AbsoluteNBO *at); /** @@ -321,7 +307,6 @@ GNUNET_JSON_spec_rsa_signature (const char *name, struct GNUNET_CRYPTO_RsaSignature **sig); - /** * JSON Specification for GNS Records. * @@ -346,8 +331,7 @@ GNUNET_JSON_spec_gnsrecord (struct GNUNET_GNSRECORD_Data **rd, * @return json string that encodes @a data */ json_t * -GNUNET_JSON_from_data (const void *data, - size_t size); +GNUNET_JSON_from_data (const void *data, size_t size); /** @@ -357,7 +341,8 @@ GNUNET_JSON_from_data (const void *data, * @param ptr binary data, sizeof (*ptr) must yield correct size * @return json string that encodes @a data */ -#define GNUNET_JSON_from_data_auto(ptr) GNUNET_JSON_from_data(ptr, sizeof (*ptr)) +#define GNUNET_JSON_from_data_auto(ptr) \ + GNUNET_JSON_from_data (ptr, sizeof (*ptr)) /** @@ -417,7 +402,7 @@ GNUNET_JSON_from_rsa_signature (const struct GNUNET_CRYPTO_RsaSignature *sig); * @return corresponding JSON encoding */ json_t * -GNUNET_JSON_from_gnsrecord (const char* rname, +GNUNET_JSON_from_gnsrecord (const char *rname, const struct GNUNET_GNSRECORD_Data *rd, unsigned int rd_count); @@ -426,7 +411,8 @@ GNUNET_JSON_from_gnsrecord (const char* rname, /** * Return codes from #GNUNET_JSON_post_parser(). */ -enum GNUNET_JSON_PostResult { +enum GNUNET_JSON_PostResult +{ /** * Parsing successful, JSON result is in `*json`. */ @@ -462,6 +448,7 @@ enum GNUNET_JSON_PostResult { * #GNUNET_JSON_post_parser_callback(). * * @param buffer_max maximum allowed size for the buffer + * @param connection MHD connection handle (for meta data about the upload) * @param con_cls the closure (will point to a `struct Buffer *`) * @param upload_data the POST data * @param upload_data_size number of bytes in @a upload_data @@ -470,6 +457,7 @@ enum GNUNET_JSON_PostResult { */ enum GNUNET_JSON_PostResult GNUNET_JSON_post_parser (size_t buffer_max, + struct MHD_Connection *connection, void **con_cls, const char *upload_data, size_t *upload_data_size, -- cgit v1.2.3