aboutsummaryrefslogtreecommitdiff
path: root/src
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
parente0f650cbf41490b3f58476f0696783058798c63d (diff)
downloadgnunet-50db224938033455429d17fce85ed77292d4c29a.tar.gz
gnunet-50db224938033455429d17fce85ed77292d4c29a.zip
add logic to parse JSON uploads
Diffstat (limited to 'src')
-rw-r--r--src/arm/gnunet-service-arm.c4
-rw-r--r--src/include/gnunet_json_lib.h66
-rw-r--r--src/util/program.c8
3 files changed, 72 insertions, 6 deletions
diff --git a/src/arm/gnunet-service-arm.c b/src/arm/gnunet-service-arm.c
index 0ffda9331..ea89b2989 100644
--- a/src/arm/gnunet-service-arm.c
+++ b/src/arm/gnunet-service-arm.c
@@ -213,13 +213,13 @@ static char *final_option;
213/** 213/**
214 * ID of task called whenever we get a SIGCHILD. 214 * ID of task called whenever we get a SIGCHILD.
215 */ 215 */
216static struct GNUNET_SCHEDULER_Task * child_death_task; 216static struct GNUNET_SCHEDULER_Task *child_death_task;
217 217
218/** 218/**
219 * ID of task called whenever the timeout for restarting a child 219 * ID of task called whenever the timeout for restarting a child
220 * expires. 220 * expires.
221 */ 221 */
222static struct GNUNET_SCHEDULER_Task * child_restart_task; 222static struct GNUNET_SCHEDULER_Task *child_restart_task;
223 223
224/** 224/**
225 * Pipe used to communicate shutdown via signal. 225 * Pipe used to communicate shutdown via signal.
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 */
diff --git a/src/util/program.c b/src/util/program.c
index b24f3ed70..7023552f6 100644
--- a/src/util/program.c
+++ b/src/util/program.c
@@ -129,10 +129,10 @@ cmd_sorter (const void *a1, const void *a2)
129 */ 129 */
130int 130int
131GNUNET_PROGRAM_run2 (int argc, char *const *argv, const char *binaryName, 131GNUNET_PROGRAM_run2 (int argc, char *const *argv, const char *binaryName,
132 const char *binaryHelp, 132 const char *binaryHelp,
133 const struct GNUNET_GETOPT_CommandLineOption *options, 133 const struct GNUNET_GETOPT_CommandLineOption *options,
134 GNUNET_PROGRAM_Main task, void *task_cls, 134 GNUNET_PROGRAM_Main task, void *task_cls,
135 int run_without_scheduler) 135 int run_without_scheduler)
136{ 136{
137 struct CommandContext cc; 137 struct CommandContext cc;
138#if ENABLE_NLS 138#if ENABLE_NLS