summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2022-07-11 12:45:16 +0200
committerChristian Grothoff <christian@grothoff.org>2022-07-11 12:45:16 +0200
commit145ed59d9aff58e705790f9bda7e1ef80b069d4e (patch)
tree5ff028a02aa6ff2772455ef27918dedae015a30c /src
parent2466c779f3524f2f1227e77519d33e0708e369cb (diff)
downloadmerchant-145ed59d9aff58e705790f9bda7e1ef80b069d4e.tar.gz
merchant-145ed59d9aff58e705790f9bda7e1ef80b069d4e.tar.bz2
merchant-145ed59d9aff58e705790f9bda7e1ef80b069d4e.zip
-add product validation logic
Diffstat (limited to 'src')
-rw-r--r--src/backend/taler-merchant-httpd_private-post-orders.c64
1 files changed, 58 insertions, 6 deletions
diff --git a/src/backend/taler-merchant-httpd_private-post-orders.c b/src/backend/taler-merchant-httpd_private-post-orders.c
index 22dded0b..10a8d503 100644
--- a/src/backend/taler-merchant-httpd_private-post-orders.c
+++ b/src/backend/taler-merchant-httpd_private-post-orders.c
@@ -71,14 +71,48 @@ check_products (const json_t *products)
}
json_array_foreach (products, index, value) {
const char *description;
+ const char *product_id = NULL;
+ uint64_t quantity;
+ const char *unit = NULL;
+ struct TALER_Amount price;
+ const char *image = NULL;
+ json_t *taxes = NULL;
+ struct GNUNET_TIME_Timestamp delivery_date;
const char *error_name;
unsigned int error_line;
enum GNUNET_GenericReturnValue res;
struct GNUNET_JSON_Specification spec[] = {
- // FIXME: parse and format-validate all
- // optional fields of a product and check validity
- GNUNET_JSON_spec_string ("description",
- &description),
+ GNUNET_JSON_spec_mark_optional (
+ GNUNET_JSON_spec_string ("product_id",
+ &product_id),
+ NULL),
+ TALER_JSON_spec_i18n_str ("description",
+ &description),
+ GNUNET_JSON_spec_mark_optional (
+ GNUNET_JSON_spec_uint64 ("quantity",
+ &quantity),
+ NULL),
+ GNUNET_JSON_spec_mark_optional (
+ GNUNET_JSON_spec_string ("unit",
+ &unit),
+ NULL),
+ GNUNET_JSON_spec_mark_optional (
+ TALER_JSON_spec_amount ("price",
+ TMH_currency,
+ &price),
+ NULL),
+ GNUNET_JSON_spec_mark_optional (
+ GNUNET_JSON_spec_string ("image",
+ &image),
+ NULL),
+ GNUNET_JSON_spec_mark_optional (
+ GNUNET_JSON_spec_json ("taxes",
+ &taxes),
+ NULL),
+ GNUNET_JSON_spec_mark_optional (
+ GNUNET_JSON_spec_timestamp ("delivery_date",
+ &delivery_date),
+ NULL),
GNUNET_JSON_spec_end ()
};
@@ -90,13 +124,31 @@ check_products (const json_t *products)
if (GNUNET_OK != res)
{
GNUNET_break (0);
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
"Product parsing failed at #%u: %s:%u\n",
(unsigned int) index,
error_name,
error_line);
return GNUNET_SYSERR;
}
+ if ( (NULL != taxes) &&
+ (! TMH_taxes_array_valid (taxes) ) )
+ {
+ GNUNET_break (0);
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Product parsing failed for taxes\n");
+ GNUNET_JSON_parse_free (spec);
+ return GNUNET_SYSERR;
+ }
+ if ( (NULL != image) &&
+ (! TMH_image_data_url_valid (image) ) )
+ {
+ GNUNET_break (0);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Product parsing failed for image\n");
+ GNUNET_JSON_parse_free (spec);
+ return GNUNET_SYSERR;
+ }
GNUNET_JSON_parse_free (spec);
}
return GNUNET_OK;
@@ -1099,7 +1151,7 @@ patch_order (struct MHD_Connection *connection,
{
case GNUNET_SYSERR:
GNUNET_break (0);
- GNUNET_JSON_parse_free (spec);
+ GNUNET_JSON_parse_free (spec);
return TALER_MHD_reply_with_error (
connection,
MHD_HTTP_INTERNAL_SERVER_ERROR,