gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r36977 - in gnunet/src: arm include util


From: gnunet
Subject: [GNUnet-SVN] r36977 - in gnunet/src: arm include util
Date: Mon, 4 Apr 2016 14:03:00 +0200

Author: grothoff
Date: 2016-04-04 14:02:59 +0200 (Mon, 04 Apr 2016)
New Revision: 36977

Modified:
   gnunet/src/arm/gnunet-service-arm.c
   gnunet/src/include/gnunet_json_lib.h
   gnunet/src/util/program.c
Log:
add logic to parse JSON uploads

Modified: gnunet/src/arm/gnunet-service-arm.c
===================================================================
--- gnunet/src/arm/gnunet-service-arm.c 2016-04-03 19:35:52 UTC (rev 36976)
+++ gnunet/src/arm/gnunet-service-arm.c 2016-04-04 12:02:59 UTC (rev 36977)
@@ -213,13 +213,13 @@
 /**
  * ID of task called whenever we get a SIGCHILD.
  */
-static struct GNUNET_SCHEDULER_Task * child_death_task;
+static struct GNUNET_SCHEDULER_Task *child_death_task;
 
 /**
  * ID of task called whenever the timeout for restarting a child
  * expires.
  */
-static struct GNUNET_SCHEDULER_Task * child_restart_task;
+static struct GNUNET_SCHEDULER_Task *child_restart_task;
 
 /**
  * Pipe used to communicate shutdown via signal.

Modified: gnunet/src/include/gnunet_json_lib.h
===================================================================
--- gnunet/src/include/gnunet_json_lib.h        2016-04-03 19:35:52 UTC (rev 
36976)
+++ gnunet/src/include/gnunet_json_lib.h        2016-04-04 12:02:59 UTC (rev 
36977)
@@ -351,6 +351,72 @@
 GNUNET_JSON_from_rsa_signature (const struct GNUNET_CRYPTO_RsaSignature *sig);
 
 
+/* ******************* Helpers for MHD upload handling ******************* */
+
+/**
+ * Return codes from #GNUNET_JSON_post_parser().
+ */
+enum GNUNET_JSON_PostResult {
+  /**
+   * Parsing successful, JSON result is in `*json`.
+   */
+  GNUNET_JSON_PR_SUCCESS,
+
+  /**
+   * Parsing continues, call again soon!
+   */
+  GNUNET_JSON_PR_CONTINUE,
+
+  /**
+   * Sorry, memory allocation (malloc()) failed.
+   */
+  GNUNET_JSON_PR_OUT_OF_MEMORY,
+
+  /**
+   * Request size exceeded `buffer_max` argument.
+   */
+  GNUNET_JSON_PR_REQUEST_TOO_LARGE,
+
+  /**
+   * JSON parsing failed. This was not a JSON upload.
+   */
+  GNUNET_JSON_PR_JSON_INVALID
+};
+
+
+/**
+ * Process a POST request containing a JSON object.  This function
+ * realizes an MHD POST processor that will (incrementally) process
+ * JSON data uploaded to the HTTP server.  It will store the required
+ * state in the @a con_cls, which must be cleaned up using
+ * #GNUNET_JSON_post_parser_callback().
+ *
+ * @param buffer_max maximum allowed size for the buffer
+ * @param con_cls the closure (will point to a `struct Buffer *`)
+ * @param upload_data the POST data
+ * @param upload_data_size number of bytes in @a upload_data
+ * @param json the JSON object for a completed request
+ * @return result code indicating the status of the operation
+ */
+enum GNUNET_JSON_PostResult
+GNUNET_JSON_post_parser (size_t buffer_max,
+                         void **con_cls,
+                         const char *upload_data,
+                         size_t *upload_data_size,
+                         json_t **json);
+
+
+/**
+ * Function called whenever we are done with a request
+ * to clean up our state.
+ *
+ * @param con_cls value as it was left by
+ *        #GNUNET_JSON_post_parser(), to be cleaned up
+ */
+void
+GNUNET_JSON_post_parser_cleanup (void *con_cls);
+
+
 #endif
 
 /* end of gnunet_json_lib.h */

Modified: gnunet/src/util/program.c
===================================================================
--- gnunet/src/util/program.c   2016-04-03 19:35:52 UTC (rev 36976)
+++ gnunet/src/util/program.c   2016-04-04 12:02:59 UTC (rev 36977)
@@ -129,10 +129,10 @@
  */
 int
 GNUNET_PROGRAM_run2 (int argc, char *const *argv, const char *binaryName,
-                    const char *binaryHelp,
-                    const struct GNUNET_GETOPT_CommandLineOption *options,
-                    GNUNET_PROGRAM_Main task, void *task_cls,
-                    int run_without_scheduler)
+                     const char *binaryHelp,
+                     const struct GNUNET_GETOPT_CommandLineOption *options,
+                     GNUNET_PROGRAM_Main task, void *task_cls,
+                     int run_without_scheduler)
 {
   struct CommandContext cc;
 #if ENABLE_NLS




reply via email to

[Prev in Thread] Current Thread [Next in Thread]