aboutsummaryrefslogtreecommitdiff
path: root/src/include/gnunet_json_lib.h
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2016-04-04 12:02:59 +0000
committerChristian Grothoff <christian@grothoff.org>2016-04-04 12:02:59 +0000
commit50db224938033455429d17fce85ed77292d4c29a (patch)
tree808d234f2e8bcf001766ba8422554863a591fc92 /src/include/gnunet_json_lib.h
parente0f650cbf41490b3f58476f0696783058798c63d (diff)
downloadgnunet-50db224938033455429d17fce85ed77292d4c29a.tar.gz
gnunet-50db224938033455429d17fce85ed77292d4c29a.zip
add logic to parse JSON uploads
Diffstat (limited to 'src/include/gnunet_json_lib.h')
-rw-r--r--src/include/gnunet_json_lib.h66
1 files changed, 66 insertions, 0 deletions
diff --git a/src/include/gnunet_json_lib.h b/src/include/gnunet_json_lib.h
index 15e85c411..8b21c01dd 100644
--- a/src/include/gnunet_json_lib.h
+++ b/src/include/gnunet_json_lib.h
@@ -351,6 +351,72 @@ json_t *
351GNUNET_JSON_from_rsa_signature (const struct GNUNET_CRYPTO_RsaSignature *sig); 351GNUNET_JSON_from_rsa_signature (const struct GNUNET_CRYPTO_RsaSignature *sig);
352 352
353 353
354/* ******************* Helpers for MHD upload handling ******************* */
355
356/**
357 * Return codes from #GNUNET_JSON_post_parser().
358 */
359enum GNUNET_JSON_PostResult {
360 /**
361 * Parsing successful, JSON result is in `*json`.
362 */
363 GNUNET_JSON_PR_SUCCESS,
364
365 /**
366 * Parsing continues, call again soon!
367 */
368 GNUNET_JSON_PR_CONTINUE,
369
370 /**
371 * Sorry, memory allocation (malloc()) failed.
372 */
373 GNUNET_JSON_PR_OUT_OF_MEMORY,
374
375 /**
376 * Request size exceeded `buffer_max` argument.
377 */
378 GNUNET_JSON_PR_REQUEST_TOO_LARGE,
379
380 /**
381 * JSON parsing failed. This was not a JSON upload.
382 */
383 GNUNET_JSON_PR_JSON_INVALID
384};
385
386
387/**
388 * Process a POST request containing a JSON object. This function
389 * realizes an MHD POST processor that will (incrementally) process
390 * JSON data uploaded to the HTTP server. It will store the required
391 * state in the @a con_cls, which must be cleaned up using
392 * #GNUNET_JSON_post_parser_callback().
393 *
394 * @param buffer_max maximum allowed size for the buffer
395 * @param con_cls the closure (will point to a `struct Buffer *`)
396 * @param upload_data the POST data
397 * @param upload_data_size number of bytes in @a upload_data
398 * @param json the JSON object for a completed request
399 * @return result code indicating the status of the operation
400 */
401enum GNUNET_JSON_PostResult
402GNUNET_JSON_post_parser (size_t buffer_max,
403 void **con_cls,
404 const char *upload_data,
405 size_t *upload_data_size,
406 json_t **json);
407
408
409/**
410 * Function called whenever we are done with a request
411 * to clean up our state.
412 *
413 * @param con_cls value as it was left by
414 * #GNUNET_JSON_post_parser(), to be cleaned up
415 */
416void
417GNUNET_JSON_post_parser_cleanup (void *con_cls);
418
419
354#endif 420#endif
355 421
356/* end of gnunet_json_lib.h */ 422/* end of gnunet_json_lib.h */