aboutsummaryrefslogtreecommitdiff
path: root/src/mint/taler-mint-httpd_parsing.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/mint/taler-mint-httpd_parsing.c')
-rw-r--r--src/mint/taler-mint-httpd_parsing.c84
1 files changed, 78 insertions, 6 deletions
diff --git a/src/mint/taler-mint-httpd_parsing.c b/src/mint/taler-mint-httpd_parsing.c
index c4e28bba7..066f18913 100644
--- a/src/mint/taler-mint-httpd_parsing.c
+++ b/src/mint/taler-mint-httpd_parsing.c
@@ -110,8 +110,8 @@ buffer_deinit (struct Buffer *buf)
110 * @param data the data to append 110 * @param data the data to append
111 * @param size the size of @a data 111 * @param size the size of @a data
112 * @param max_size maximum size that the buffer can grow to 112 * @param max_size maximum size that the buffer can grow to
113 * @return GNUNET_OK on success, 113 * @return #GNUNET_OK on success,
114 * GNUNET_NO if the buffer can't accomodate for the new data 114 * #GNUNET_NO if the buffer can't accomodate for the new data
115 */ 115 */
116static int 116static int
117buffer_append (struct Buffer *buf, 117buffer_append (struct Buffer *buf,
@@ -153,14 +153,14 @@ buffer_append (struct Buffer *buf,
153 * @param upload_data the POST data 153 * @param upload_data the POST data
154 * @param upload_data_size number of bytes in @a upload_data 154 * @param upload_data_size number of bytes in @a upload_data
155 * @param json the JSON object for a completed request 155 * @param json the JSON object for a completed request
156 * @returns 156 * @return
157 * GNUNET_YES if json object was parsed or at least 157 * #GNUNET_YES if json object was parsed or at least
158 * may be parsed in the future (call again); 158 * may be parsed in the future (call again);
159 * `*json` will be NULL if we need to be called again, 159 * `*json` will be NULL if we need to be called again,
160 * and non-NULL if we are done. 160 * and non-NULL if we are done.
161 * GNUNET_NO is request incomplete or invalid 161 * #GNUNET_NO is request incomplete or invalid
162 * (error message was generated) 162 * (error message was generated)
163 * GNUNET_SYSERR on internal error 163 * #GNUNET_SYSERR on internal error
164 * (we could not even queue an error message, 164 * (we could not even queue an error message,
165 * close HTTP session with MHD_NO) 165 * close HTTP session with MHD_NO)
166 */ 166 */
@@ -606,6 +606,78 @@ TALER_MINT_release_parsed_data (struct GNUNET_MINT_ParseFieldSpec *spec)
606 606
607 607
608/** 608/**
609 * Parse amount specified in JSON format.
610 *
611 * @param connection the MHD connection (to report errors)
612 * @param f json specification of the amount
613 * @param amount[OUT] set to the amount specified in @a f
614 * @return
615 * #GNUNET_YES if parsing was successful
616 * #GNUNET_NO if json is malformed, error response was generated
617 * #GNUNET_SYSERR on internal error, error response was not generated
618 */
619int
620TALER_MINT_parse_amount_json (struct MHD_Connection *connection,
621 json_t *f,
622 struct TALER_Amount *amount)
623{
624 json_int_t value;
625 json_int_t fraction;
626 const char *currency;
627 struct TALER_Amount a;
628
629 if (-1 == json_unpack (f,
630 "{s:I, s:I, s:s}",
631 "value", &value,
632 "fraction", &fraction,
633 "currency", &currency))
634 {
635 LOG_WARNING ("Failed to parse JSON amount specification\n");
636 if (MHD_YES !=
637 TALER_MINT_reply_json_pack (connection,
638 MHD_HTTP_BAD_REQUEST,
639 "{s:s}",
640 "error", "Bad format"))
641 return GNUNET_SYSERR;
642 return GNUNET_NO;
643 }
644 if ( (value < 0) ||
645 (fraction < 0) ||
646 (value > UINT32_MAX) ||
647 (fraction > UINT32_MAX) )
648 {
649 LOG_WARNING ("Amount specified not in allowed range\n");
650 if (MHD_YES !=
651 TALER_MINT_reply_json_pack (connection,
652 MHD_HTTP_BAD_REQUEST,
653 "{s:s}",
654 "error", "Amount outside of allowed range"))
655 return GNUNET_SYSERR;
656 return GNUNET_NO;
657 }
658 if (0 != strcmp (currency,
659 MINT_CURRENCY))
660 {
661 LOG_WARNING ("Currency specified not supported by this mint\n");
662 if (MHD_YES !=
663 TALER_MINT_reply_json_pack (connection,
664 MHD_HTTP_BAD_REQUEST,
665 "{s:s, s:s}",
666 "error", "Currency not supported",
667 "currency", currency))
668 return GNUNET_SYSERR;
669 return GNUNET_NO;
670 }
671 a.value = (uint32_t) value;
672 a.fraction = (uint32_t) fraction;
673 GNUNET_assert (strlen (MINT_CURRENCY) < TALER_CURRENCY_LEN);
674 strcpy (a.currency, MINT_CURRENCY);
675 *amount = TALER_amount_normalize (a);
676 return GNUNET_OK;
677}
678
679
680/**
609 * Extract base32crockford encoded data from request. 681 * Extract base32crockford encoded data from request.
610 * 682 *
611 * Queues an error response to the connection if the parameter is missing or 683 * Queues an error response to the connection if the parameter is missing or