37#define REQUEST_BUFFER_INITIAL (2 * 1024)
89 buf->
alloc = alloc_size;
132 size_t new_size = buf->
alloc;
141 buf->
alloc = new_size;
163 memset (&z, 0,
sizeof(z));
164 z.next_in = (Bytef *) buf->
data;
165 z.avail_in = buf->
fill;
168 z.next_out = (Bytef *) tmp;
169 z.avail_out = tmp_size;
170 ret = inflateInit (&z);
186 ret = inflate (&z, 0);
210 if ((0 < z.avail_out) && (0 == z.avail_in))
221 if (tmp_size == buf->
max)
229 if (tmp_size * 2 < tmp_size)
234 z.next_out = (Bytef *) &tmp[z.total_out];
240 buf->
alloc = tmp_size;
241 buf->
fill = z.total_out;
266 struct MHD_Connection *connection,
268 const char *upload_data,
269 size_t *upload_data_size,
272 struct Buffer *r = *con_cls;
277 if (NULL == *con_cls)
293 *upload_data_size = 0;
297 if (0 != *upload_data_size)
302 buffer_append (r, upload_data, *upload_data_size, buffer_max))
311 *upload_data_size = 0;
316 ce = MHD_lookup_connection_value (connection,
318 MHD_HTTP_HEADER_CONTENT_ENCODING);
319 if ((NULL != ce) && (0 == strcasecmp (
"deflate", ce)))
334 *json = json_loadb (r->
data,
341 "Failed to parse JSON request body of %u byte at offset %d: %s\n",
342 (
unsigned int) r->
fill,
369 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 JSON objects into GNUnet objects
GNUNET_JSON_PostResult
Return codes from GNUNET_JSON_post_parser().
@ GNUNET_JSON_PR_CONTINUE
Parsing continues, call again soon!
@ GNUNET_JSON_PR_OUT_OF_MEMORY
Sorry, memory allocation (malloc()) failed.
@ GNUNET_JSON_PR_JSON_INVALID
JSON parsing failed.
@ GNUNET_JSON_PR_REQUEST_TOO_LARGE
Request size exceeded buffer_max argument.
@ GNUNET_JSON_PR_SUCCESS
Parsing successful, JSON result is in *json.
#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 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_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.
static enum GNUNET_JSON_PostResult inflate_data(struct Buffer *buf)
Decompress data in buf.
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.
void GNUNET_JSON_post_parser_cleanup(void *con_cls)
Function called whenever we are done with a request to clean up our state.
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.