functions to parse JSON snippets we receive via MHD More...
Go to the source code of this file.
Data Structures | |
struct | Buffer |
Buffer for POST requests. More... | |
Macros | |
#define | REQUEST_BUFFER_INITIAL (2 * 1024) |
Initial size for POST request buffers. More... | |
Functions | |
static int | buffer_init (struct Buffer *buf, const void *data, size_t data_size, size_t alloc_size, size_t max_size) |
Initialize a buffer. More... | |
static void | buffer_deinit (struct Buffer *buf) |
Free the data in a buffer. More... | |
static int | buffer_append (struct Buffer *buf, const void *data, size_t data_size, size_t max_size) |
Append data to a buffer, growing the buffer if necessary. More... | |
static enum GNUNET_JSON_PostResult | inflate_data (struct Buffer *buf) |
Decompress data in buf. More... | |
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, json_t **json) |
Process a POST request containing a JSON object. More... | |
void | GNUNET_JSON_post_parser_cleanup (void *con_cls) |
Function called whenever we are done with a request to clean up our state. More... | |
functions to parse JSON snippets we receive via MHD
Definition in file json_mhd.c.
#define REQUEST_BUFFER_INITIAL (2 * 1024) |
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.
Definition at line 37 of file json_mhd.c.
|
static |
Initialize a buffer.
buf | the buffer to initialize |
data | the initial data |
data_size | size of the initial data |
alloc_size | size of the buffer |
max_size | maximum size that the buffer can grow to |
Definition at line 78 of file json_mhd.c.
References Buffer::alloc, data, Buffer::data, data_size, Buffer::fill, GNUNET_malloc, GNUNET_memcpy, GNUNET_OK, GNUNET_SYSERR, Buffer::max, and max_size.
Referenced by GNUNET_JSON_post_parser().
|
static |
Free the data in a buffer.
Does not free the buffer object itself.
buf | buffer to de-initialize |
Definition at line 104 of file json_mhd.c.
References Buffer::data, and GNUNET_free.
Referenced by GNUNET_JSON_post_parser(), and GNUNET_JSON_post_parser_cleanup().
|
static |
Append data to a buffer, growing the buffer if necessary.
buf | the buffer to append to |
data | the data to append |
data_size | the size of data |
max_size | maximum size that the buffer can grow to |
Definition at line 122 of file json_mhd.c.
References Buffer::alloc, data, Buffer::data, data_size, Buffer::fill, GNUNET_free, GNUNET_malloc, GNUNET_memcpy, GNUNET_NO, GNUNET_OK, and max_size.
Referenced by GNUNET_JSON_post_parser().
|
static |
Decompress data in buf.
buf | input data to inflate |
Definition at line 156 of file json_mhd.c.
References Buffer::alloc, Buffer::data, Buffer::fill, GNUNET_break, GNUNET_break_op, GNUNET_free, GNUNET_JSON_PR_JSON_INVALID, GNUNET_JSON_PR_OUT_OF_MEMORY, GNUNET_JSON_PR_SUCCESS, GNUNET_malloc, GNUNET_MIN, GNUNET_realloc, Buffer::max, and ret.
Referenced by GNUNET_JSON_post_parser().
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, | ||
json_t ** | json | ||
) |
Process a POST request containing a JSON object.
This function realizes an MHD POST processor that will (incrementally) process JSON data uploaded to the HTTP server. It will store the required state in the con_cls, which must be cleaned up using #GNUNET_JSON_post_parser_callback().
buffer_max | maximum allowed size for the buffer |
connection | MHD connection handle (for meta data about the upload) |
con_cls | the closure (will point to a struct Buffer * ) |
upload_data | the POST data |
upload_data_size | number of bytes in upload_data |
json | the JSON object for a completed request |
Definition at line 265 of file json_mhd.c.
References buffer_append(), buffer_deinit(), buffer_init(), Buffer::data, Buffer::fill, GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_JSON_PR_CONTINUE, GNUNET_JSON_PR_JSON_INVALID, GNUNET_JSON_PR_OUT_OF_MEMORY, GNUNET_JSON_PR_REQUEST_TOO_LARGE, GNUNET_JSON_PR_SUCCESS, GNUNET_log, GNUNET_new, GNUNET_OK, inflate_data(), REQUEST_BUFFER_INITIAL, and ret.
void GNUNET_JSON_post_parser_cleanup | ( | void * | con_cls | ) |
Function called whenever we are done with a request to clean up our state.
con_cls | value as it was left by GNUNET_JSON_post_parser(), to be cleaned up |
Definition at line 367 of file json_mhd.c.
References buffer_deinit(), and GNUNET_free.