[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] [gnunet] branch master updated: preparatory change to GNUNE
From: |
gnunet |
Subject: |
[GNUnet-SVN] [gnunet] branch master updated: preparatory change to GNUNET_JSON_post_parser() API for future compression support |
Date: |
Thu, 02 May 2019 22:26:07 +0200 |
This is an automated email from the git hooks/post-receive script.
grothoff pushed a commit to branch master
in repository gnunet.
The following commit(s) were added to refs/heads/master by this push:
new 1eadd5120 preparatory change to GNUNET_JSON_post_parser() API for
future compression support
1eadd5120 is described below
commit 1eadd51205794a18e74f135672c96613d4f8734b
Author: Christian Grothoff <address@hidden>
AuthorDate: Thu May 2 22:24:42 2019 +0200
preparatory change to GNUNET_JSON_post_parser() API for future compression
support
---
src/include/gnunet_json_lib.h | 64 ++++++++++++++++++-------------------------
src/json/json_mhd.c | 31 +++++++++------------
2 files changed, 39 insertions(+), 56 deletions(-)
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 <jansson.h>
-
+#include <microhttpd.h>
/* ****************** 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,
diff --git a/src/json/json_mhd.c b/src/json/json_mhd.c
index f095e1011..30b29b88e 100644
--- a/src/json/json_mhd.c
+++ b/src/json/json_mhd.c
@@ -11,7 +11,7 @@
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Affero General Public License for more details.
-
+
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
@@ -27,12 +27,13 @@
#include "platform.h"
#include "gnunet_json_lib.h"
+
/**
* Initial size for POST request buffers. Should be big enough to
* usually not require a reallocation, but not so big that it hurts in
* terms of memory use.
*/
-#define REQUEST_BUFFER_INITIAL (2*1024)
+#define REQUEST_BUFFER_INITIAL (2 * 1024)
/**
@@ -74,8 +75,7 @@ buffer_init (struct Buffer *buf,
size_t alloc_size,
size_t max_size)
{
- if ( (data_size > max_size) ||
- (alloc_size > max_size) )
+ if ((data_size > max_size) || (alloc_size > max_size))
return GNUNET_SYSERR;
if (data_size > alloc_size)
alloc_size = data_size;
@@ -145,6 +145,7 @@ buffer_append (struct Buffer *buf,
* #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
@@ -153,6 +154,7 @@ buffer_append (struct Buffer *buf,
*/
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,
@@ -165,12 +167,11 @@ GNUNET_JSON_post_parser (size_t buffer_max,
{
/* We are seeing a fresh POST request. */
r = GNUNET_new (struct Buffer);
- if (GNUNET_OK !=
- buffer_init (r,
- upload_data,
- *upload_data_size,
- REQUEST_BUFFER_INITIAL,
- buffer_max))
+ if (GNUNET_OK != buffer_init (r,
+ upload_data,
+ *upload_data_size,
+ REQUEST_BUFFER_INITIAL,
+ buffer_max))
{
*con_cls = NULL;
buffer_deinit (r);
@@ -187,10 +188,7 @@ GNUNET_JSON_post_parser (size_t buffer_max,
/* We are seeing an old request with more data available. */
if (GNUNET_OK !=
- buffer_append (r,
- upload_data,
- *upload_data_size,
- buffer_max))
+ buffer_append (r, upload_data, *upload_data_size, buffer_max))
{
/* Request too long */
*con_cls = NULL;
@@ -205,10 +203,7 @@ GNUNET_JSON_post_parser (size_t buffer_max,
/* We have seen the whole request. */
- *json = json_loadb (r->data,
- r->fill,
- 0,
- NULL);
+ *json = json_loadb (r->data, r->fill, 0, NULL);
if (NULL == *json)
{
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
--
To stop receiving notification emails like this one, please contact
address@hidden
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] [gnunet] branch master updated: preparatory change to GNUNET_JSON_post_parser() API for future compression support,
gnunet <=