summaryrefslogtreecommitdiff
path: root/src/mint/taler-mint-httpd_parsing.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2015-01-19 21:04:58 +0100
committerChristian Grothoff <christian@grothoff.org>2015-01-19 21:04:58 +0100
commita1f20a92a0578e63b2b5d764ac802dbe45ab08e0 (patch)
tree4c07a81b40a2eac0ce1b412d7c3a3376a27ef533 /src/mint/taler-mint-httpd_parsing.c
parent3553e60733e4ad2c71a3daa4148182443958dd04 (diff)
downloadexchange-a1f20a92a0578e63b2b5d764ac802dbe45ab08e0.tar.gz
exchange-a1f20a92a0578e63b2b5d764ac802dbe45ab08e0.tar.bz2
exchange-a1f20a92a0578e63b2b5d764ac802dbe45ab08e0.zip
restructuring more of deposit logic towards desired flow structure
Diffstat (limited to 'src/mint/taler-mint-httpd_parsing.c')
-rw-r--r--src/mint/taler-mint-httpd_parsing.c149
1 files changed, 143 insertions, 6 deletions
diff --git a/src/mint/taler-mint-httpd_parsing.c b/src/mint/taler-mint-httpd_parsing.c
index f61049b5e..56744c6b0 100644
--- a/src/mint/taler-mint-httpd_parsing.c
+++ b/src/mint/taler-mint-httpd_parsing.c
@@ -269,9 +269,10 @@ TALER_MINT_parse_post_cleanup_callback (void *con_cls)
* @param connection the connection to send an error response to
* @param root the JSON node to start the navigation at.
* @param ... navigation specification (see `enum TALER_MINT_JsonNavigationCommand`)
- * @return GNUNET_YES if navigation was successful
- * GNUNET_NO if json is malformed, error response was generated
- * GNUNET_SYSERR on internal error (no response was generated,
+ * @return
+ * #GNUNET_YES if navigation was successful
+ * #GNUNET_NO if json is malformed, error response was generated
+ * #GNUNET_SYSERR on internal error (no response was generated,
* connection must be closed)
*/
int
@@ -462,6 +463,142 @@ GNUNET_MINT_parse_navigate_json (struct MHD_Connection *connection,
/**
+ * Find a fixed-size field in the top-level of the JSON tree and store
+ * it in @a data.
+ *
+ * Sends an error response if navigation is impossible (i.e.
+ * the JSON object is invalid)
+ *
+ * @param connection the connection to send an error response to
+ * @param root the JSON node to start the navigation at.
+ * @param field name of the field to navigate to
+ * @param data where to store the extracted data
+ * @param data_size size of the @a data field
+ * @param[IN|OUT] ret return value, function does nothing if @a ret is not #GNUNET_YES
+ * on entry; will set @a ret to:
+ * #GNUNET_YES if navigation was successful
+ * #GNUNET_NO if json is malformed, error response was generated
+ * #GNUNET_SYSERR on internal error
+ */
+static void
+parse_fixed_json_data (struct MHD_Connection *connection,
+ const json_t *root,
+ const char *field,
+ void *data,
+ size_t data_size,
+ int *ret)
+{
+ if (GNUNET_YES != *ret)
+ return;
+ *ret = GNUNET_MINT_parse_navigate_json (connection,
+ root,
+ JNAV_FIELD, field,
+ JNAV_RET_DATA, data, data_size);
+}
+
+
+/**
+ * Find a variable-size field in the top-level of the JSON tree and store
+ * it in @a data.
+ *
+ * Sends an error response if navigation is impossible (i.e.
+ * the JSON object is invalid)
+ *
+ * @param connection the connection to send an error response to
+ * @param root the JSON node to start the navigation at.
+ * @param field name of the field to navigate to
+ * @param data where to store a pointer to memory allocated for the extracted data
+ * @param[IN|OUT] ret return value, function does nothing if @a ret is not #GNUNET_YES
+ * on entry; will set @a ret to:
+ * #GNUNET_YES if navigation was successful
+ * #GNUNET_NO if json is malformed, error response was generated
+ * #GNUNET_SYSERR on internal error
+ */
+static void
+parse_variable_json_data (struct MHD_Connection *connection,
+ const json_t *root,
+ const char *field,
+ void **data,
+ size_t *data_size,
+ int *ret)
+{
+ if (GNUNET_YES != *ret)
+ return;
+ *ret = GNUNET_MINT_parse_navigate_json (connection,
+ root,
+ JNAV_FIELD, field,
+ JNAV_RET_DATA_VAR, data, data_size);
+
+}
+
+
+/**
+ * Parse JSON object into components based on the given field
+ * specification.
+ *
+ * @param connection the connection to send an error response to
+ * @param root the JSON node to start the navigation at.
+ * @param spec field specification for the parser
+ * @return
+ * #GNUNET_YES if navigation was successful (caller is responsible
+ * for freeing allocated variable-size data using
+ * #TALER_MINT_release_parsed_data() when done)
+ * #GNUNET_NO if json is malformed, error response was generated
+ * #GNUNET_SYSERR on internal error
+ */
+int
+TALER_MINT_parse_json_data (struct MHD_Connection *connection,
+ const json_t *root,
+ struct GNUNET_MINT_ParseFieldSpec *spec)
+{
+ unsigned int i;
+ int ret;
+
+ ret = GNUNET_YES;
+ for (i=0; NULL != spec[i].field_name; i++)
+ {
+ if (0 == spec[i].destination_size_in)
+ parse_variable_json_data (connection, root,
+ spec[i].field_name,
+ (void **) spec[i].destination,
+ &spec[i].destination_size_out,
+ &ret);
+ else
+ parse_fixed_json_data (connection, root,
+ spec[i].field_name,
+ spec[i].destination,
+ spec[i].destination_size_in,
+ &ret);
+ }
+ if (GNUNET_YES != ret)
+ TALER_MINT_release_parsed_data (spec);
+ return ret;
+}
+
+
+/**
+ * Release all memory allocated for the variable-size fields in
+ * the parser specification.
+ *
+ * @param spec specification to free
+ */
+void
+TALER_MINT_release_parsed_data (struct GNUNET_MINT_ParseFieldSpec *spec)
+{
+ unsigned int i;
+
+ for (i=0; NULL != spec[i].field_name; i++)
+ if ( (0 == spec[i].destination_size_in) &&
+ (0 != spec[i].destination_size_out) )
+ {
+ GNUNET_free (spec[i].destination);
+ spec[i].destination = NULL;
+ spec[i].destination_size_out = 0;
+ }
+}
+
+
+/**
* Extract base32crockford encoded data from request.
*
* Queues an error response to the connection if the parameter is missing or
@@ -472,9 +609,9 @@ GNUNET_MINT_parse_navigate_json (struct MHD_Connection *connection,
* @param[out] out_data pointer to store the result
* @param out_size expected size of data
* @return
- * GNUNET_YES if the the argument is present
- * GNUNET_NO if the argument is absent or malformed
- * GNUNET_SYSERR on internal error (error response could not be sent)
+ * #GNUNET_YES if the the argument is present
+ * #GNUNET_NO if the argument is absent or malformed
+ * #GNUNET_SYSERR on internal error (error response could not be sent)
*/
int
TALER_MINT_mhd_request_arg_data (struct MHD_Connection *connection,