38#define REQUEST_BUFFER_INITIAL (2 * 1024)
91 buf->
alloc = alloc_size;
140 size_t new_size = buf->
alloc;
142 while ( (new_size < buf->fill +
data_size) &&
150 buf->
alloc = new_size;
177 z.next_in = (Bytef *) buf->
data;
178 z.avail_in = buf->
fill;
182 z.next_out = (Bytef *) tmp;
183 z.avail_out = tmp_size;
184 ret = inflateInit (&z);
223 if ( (0 < z.avail_out) &&
235 if (tmp_size == buf->
max)
243 if (tmp_size * 2 < tmp_size)
250 z.next_out = (Bytef *) &tmp[z.total_out];
251 z.avail_out = tmp_size - z.total_out;
257 buf->
alloc = tmp_size;
258 buf->
fill = z.total_out;
283 struct MHD_Connection *connection,
285 const char *upload_data,
286 size_t *upload_data_size,
289 struct Buffer *r = *con_cls;
293 if (NULL == *con_cls)
310 *upload_data_size = 0;
314 if (0 != *upload_data_size)
331 *upload_data_size = 0;
336 ce = MHD_lookup_connection_value (connection,
338 MHD_HTTP_HEADER_CONTENT_ENCODING);
340 (0 == strcasecmp (
"deflate",
358 *json = json_loadb (r->
data,
365 "Failed to parse JSON request body of %u byte at offset %d: %s\n",
366 (
unsigned int) r->
fill,
392 struct Buffer *r = con_cls;
static int ret
Final status code.
static char * data
The data to insert into the dht.
static size_t data_size
Number of bytes in data.
static size_t max_size
The maximal size the extended sampler elements should grow to.
functions to parse HTTP uploads with MHD
GNUNET_MHD_PostResult
Return codes from GNUNET_MHD_post_parser().
@ GNUNET_MHD_PR_CONTINUE
Parsing continues, call again soon!
@ GNUNET_MHD_PR_SUCCESS
Parsing successful, JSON result is in *json.
@ GNUNET_MHD_PR_OUT_OF_MEMORY
Sorry, memory allocation (malloc()) failed.
@ GNUNET_MHD_PR_REQUEST_TOO_LARGE
Request size exceeded buffer_max argument.
@ GNUNET_MHD_PR_JSON_INVALID
JSON parsing failed.
#define GNUNET_log(kind,...)
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
GNUNET_GenericReturnValue
Named constants for return values.
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
@ GNUNET_ERROR_TYPE_WARNING
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_realloc(ptr, size)
Wrapper around realloc.
#define GNUNET_free(ptr)
Wrapper around free.
static enum GNUNET_MHD_PostResult inflate_data(struct Buffer *buf)
Decompress data in buf.
#define REQUEST_BUFFER_INITIAL
Initial size for POST request buffers.
enum GNUNET_MHD_PostResult GNUNET_MHD_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.
static enum GNUNET_GenericReturnValue 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.
void GNUNET_MHD_post_parser_cleanup(void *con_cls)
Function called whenever we are done with a request to clean up our state.
static void buffer_deinit(struct Buffer *buf)
Free the data in a buffer.
static enum GNUNET_GenericReturnValue buffer_init(struct Buffer *buf, const void *data, size_t data_size, size_t alloc_size, size_t max_size)
Initialize a buffer.
Buffer for POST requests.
size_t max
Maximum buffer size allowed.
size_t fill
Number of valid bytes in buffer.
size_t alloc
Number of allocated bytes in buffer.
char * data
Allocated memory.