38#define REQUEST_BUFFER_INITIAL (2 * 1024)
90 buf->
alloc = alloc_size;
133 size_t new_size = buf->
alloc;
142 buf->
alloc = new_size;
164 memset (&z, 0,
sizeof(z));
165 z.next_in = (Bytef *) buf->
data;
166 z.avail_in = buf->
fill;
169 z.next_out = (Bytef *) tmp;
170 z.avail_out = tmp_size;
171 ret = inflateInit (&z);
187 ret = inflate (&z, 0);
211 if ((0 < z.avail_out) && (0 == z.avail_in))
222 if (tmp_size == buf->
max)
230 if (tmp_size * 2 < tmp_size)
235 z.next_out = (Bytef *) &tmp[z.total_out];
241 buf->
alloc = tmp_size;
242 buf->
fill = z.total_out;
267 struct MHD_Connection *connection,
269 const char *upload_data,
270 size_t *upload_data_size,
273 struct Buffer *r = *con_cls;
278 if (NULL == *con_cls)
294 *upload_data_size = 0;
298 if (0 != *upload_data_size)
303 buffer_append (r, upload_data, *upload_data_size, buffer_max))
312 *upload_data_size = 0;
317 ce = MHD_lookup_connection_value (connection,
319 MHD_HTTP_HEADER_CONTENT_ENCODING);
320 if ((NULL != ce) && (0 == strcasecmp (
"deflate", ce)))
335 *json = json_loadb (r->
data,
342 "Failed to parse JSON request body of %u byte at offset %d: %s\n",
343 (
unsigned int) r->
fill,
370 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.
#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.
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.
#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.
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 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.
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.