gnunet-svn
[Top][All Lists]
Advanced

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

[taler-merchant] branch master updated: -add product validation logic


From: gnunet
Subject: [taler-merchant] branch master updated: -add product validation logic
Date: Mon, 11 Jul 2022 12:45:19 +0200

This is an automated email from the git hooks/post-receive script.

grothoff pushed a commit to branch master
in repository merchant.

The following commit(s) were added to refs/heads/master by this push:
     new 145ed59d -add product validation logic
145ed59d is described below

commit 145ed59d9aff58e705790f9bda7e1ef80b069d4e
Author: Christian Grothoff <christian@grothoff.org>
AuthorDate: Mon Jul 11 12:45:16 2022 +0200

    -add product validation logic
---
 .../taler-merchant-httpd_private-post-orders.c     | 64 ++++++++++++++++++++--
 1 file 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,

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

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