Use GNU printf format
[oweals/gnunet.git] / src / include / gnunet_json_lib.h
index 8d8a6ee783327e10250a029a3481b2d5b4a017b7..9e5f9e28486fe19dce48d77bb75905ca337ff268 100644 (file)
@@ -23,7 +23,7 @@
 #ifndef GNUNET_JSON_LIB_H
 #define GNUNET_JSON_LIB_H
 
-#include <gnunet/gnunet_util_lib.h>
+#include "gnunet_util_lib.h"
 #include <jansson.h>
 
 
@@ -281,7 +281,7 @@ GNUNET_JSON_spec_relative_time (const char *name,
  */
 struct GNUNET_JSON_Specification
 GNUNET_JSON_spec_rsa_public_key (const char *name,
-                                 struct GNUNET_CRYPTO_rsa_PublicKey **pk);
+                                 struct GNUNET_CRYPTO_RsaPublicKey **pk);
 
 
 /**
@@ -292,7 +292,7 @@ GNUNET_JSON_spec_rsa_public_key (const char *name,
  */
 struct GNUNET_JSON_Specification
 GNUNET_JSON_spec_rsa_signature (const char *name,
-                                struct GNUNET_CRYPTO_rsa_Signature **sig);
+                                struct GNUNET_CRYPTO_RsaSignature **sig);
 
 
 /* ****************** Generic generator interface ******************* */
@@ -311,6 +311,16 @@ GNUNET_JSON_from_data (const void *data,
                        size_t size);
 
 
+/**
+ * Convert binary data to a JSON string with the base32crockford
+ * encoding.
+ *
+ * @param ptr binary data, sizeof (*ptr) must yield correct size
+ * @return json string that encodes @a data
+ */
+#define GNUNET_JSON_from_data_auto(ptr) GNUNET_JSON_from_data(ptr, sizeof (*ptr))
+
+
 /**
  * Convert absolute timestamp to a json string.
  *
@@ -338,7 +348,7 @@ GNUNET_JSON_from_time_rel (struct GNUNET_TIME_Relative stamp);
  * @return corresponding JSON encoding
  */
 json_t *
-GNUNET_JSON_from_rsa_public_key (const struct GNUNET_CRYPTO_rsa_PublicKey *pk);
+GNUNET_JSON_from_rsa_public_key (const struct GNUNET_CRYPTO_RsaPublicKey *pk);
 
 
 /**
@@ -348,7 +358,73 @@ GNUNET_JSON_from_rsa_public_key (const struct GNUNET_CRYPTO_rsa_PublicKey *pk);
  * @return corresponding JSON encoding
  */
 json_t *
-GNUNET_JSON_from_rsa_signature (const struct GNUNET_CRYPTO_rsa_Signature *sig);
+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