gnunet-svn
[Top][All Lists]
Advanced

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

[taler-merchant] branch master updated: correct (product) image to be a


From: gnunet
Subject: [taler-merchant] branch master updated: correct (product) image to be a string (as specified) instead of a JSON object
Date: Fri, 16 Apr 2021 23:33:15 +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 843f0040 correct (product) image to be a string (as specified) instead 
of a JSON object
843f0040 is described below

commit 843f00401878a2db69cea3d3a5f72f27bd763070
Author: Christian Grothoff <christian@grothoff.org>
AuthorDate: Fri Apr 16 23:32:58 2021 +0200

    correct (product) image to be a string (as specified) instead of a JSON 
object
---
 .../taler-merchant-httpd_private-get-products-ID.c        |  2 +-
 .../taler-merchant-httpd_private-patch-products-ID.c      | 11 +++--------
 src/backend/taler-merchant-httpd_private-post-orders.c    |  2 +-
 src/backend/taler-merchant-httpd_private-post-products.c  | 14 ++++++++++----
 src/backenddb/merchantdb_helper.c                         |  5 +++--
 src/backenddb/plugin_merchantdb_postgres.c                |  8 ++++----
 src/include/taler_merchant_service.h                      |  6 +++---
 src/include/taler_merchant_testing_lib.h                  |  4 ++--
 src/include/taler_merchantdb_plugin.h                     |  5 +++--
 src/lib/merchant_api_get_product.c                        |  6 +++---
 src/lib/merchant_api_patch_product.c                      |  4 ++--
 src/lib/merchant_api_post_products.c                      |  4 ++--
 src/testing/test_merchant_api.c                           |  6 +++---
 src/testing/testing_api_cmd_get_product.c                 | 15 ++++++++-------
 src/testing/testing_api_cmd_patch_product.c               | 10 +++++-----
 src/testing/testing_api_cmd_post_products.c               | 12 ++++++------
 16 files changed, 59 insertions(+), 55 deletions(-)

diff --git a/src/backend/taler-merchant-httpd_private-get-products-ID.c 
b/src/backend/taler-merchant-httpd_private-get-products-ID.c
index 0fc666eb..d98b4801 100644
--- a/src/backend/taler-merchant-httpd_private-get-products-ID.c
+++ b/src/backend/taler-merchant-httpd_private-get-products-ID.c
@@ -66,7 +66,7 @@ TMH_private_get_products_ID (const struct TMH_RequestHandler 
*rh,
 
     reply = json_pack (
       "{s:s, s:s, s:o, s:o, s:I,"
-      " s:I, s:I, s:o, s:o, s:o}",
+      " s:I, s:I, s:o, s:o, s:s}",
       "description",
       pd.description,
       "unit",
diff --git a/src/backend/taler-merchant-httpd_private-patch-products-ID.c 
b/src/backend/taler-merchant-httpd_private-patch-products-ID.c
index dd989866..d1ae5c7d 100644
--- a/src/backend/taler-merchant-httpd_private-patch-products-ID.c
+++ b/src/backend/taler-merchant-httpd_private-patch-products-ID.c
@@ -86,12 +86,7 @@ determine_cause (struct MHD_Connection *connection,
       ec = TALER_EC_MERCHANT_PRIVATE_PATCH_PRODUCTS_TOTAL_STOCKED_REDUCED;
     if (pd->total_stock - pdx.total_sold > pd->total_lost)
       ec = TALER_EC_MERCHANT_PRIVATE_PATCH_PRODUCTS_TOTAL_LOST_EXCEEDS_STOCKS;
-    GNUNET_free (pdx.description);
-    json_decref (pdx.description_i18n);
-    GNUNET_free (pdx.unit);
-    json_decref (pdx.taxes);
-    json_decref (pdx.image);
-    json_decref (pdx.address);
+    TALER_MERCHANTDB_product_details_free (&pdx);
     return TALER_MHD_reply_with_error (connection,
                                        MHD_HTTP_CONFLICT,
                                        ec,
@@ -127,8 +122,8 @@ TMH_private_patch_products_ID (const struct 
TMH_RequestHandler *rh,
                              (const char **) &pd.unit),
     TALER_JSON_spec_amount ("price",
                             &pd.price),
-    GNUNET_JSON_spec_json ("image",
-                           &pd.image),
+    GNUNET_JSON_spec_string ("image",
+                             (const char **) &pd.image),
     GNUNET_JSON_spec_json ("taxes",
                            &pd.taxes),
     GNUNET_JSON_spec_json ("address",
diff --git a/src/backend/taler-merchant-httpd_private-post-orders.c 
b/src/backend/taler-merchant-httpd_private-post-orders.c
index 9ae9a1bd..2d1441a6 100644
--- a/src/backend/taler-merchant-httpd_private-post-orders.c
+++ b/src/backend/taler-merchant-httpd_private-post-orders.c
@@ -1153,7 +1153,7 @@ merge_inventory (struct MHD_Connection *connection,
       {
         json_t *p;
 
-        p = json_pack ("{s:s, s:o, s:s, s:o, s:o, s:o, s:I}",
+        p = json_pack ("{s:s, s:o, s:s, s:o, s:o, s:s, s:I}",
                        "description",
                        pd.description,
                        "description_i18n",
diff --git a/src/backend/taler-merchant-httpd_private-post-products.c 
b/src/backend/taler-merchant-httpd_private-post-products.c
index 987857b4..9387a657 100644
--- a/src/backend/taler-merchant-httpd_private-post-products.c
+++ b/src/backend/taler-merchant-httpd_private-post-products.c
@@ -59,8 +59,8 @@ products_equal (const struct TALER_MERCHANTDB_ProductDetails 
*p1,
            (p1->total_stock == p2->total_stock) &&
            (p1->total_sold == p2->total_sold) &&
            (p1->total_lost == p2->total_lost) &&
-           (1 == json_equal (p1->image,
-                             p2->image)) &&
+           (0 == strcmp (p1->image,
+                         p2->image)) &&
            (1 == json_equal (p1->address,
                              p2->address)) &&
            (p1->next_restock.abs_value_us ==
@@ -92,8 +92,8 @@ TMH_private_post_products (const struct TMH_RequestHandler 
*rh,
                              (const char **) &pd.unit),
     TALER_JSON_spec_amount ("price",
                             &pd.price),
-    GNUNET_JSON_spec_json ("image",
-                           &pd.image),
+    GNUNET_JSON_spec_string ("image",
+                             (const char **) &pd.image),
     GNUNET_JSON_spec_json ("taxes",
                            &pd.taxes),
     GNUNET_JSON_spec_json ("address",
@@ -113,9 +113,12 @@ TMH_private_post_products (const struct TMH_RequestHandler 
*rh,
                                      hc->request_body,
                                      spec);
     if (GNUNET_OK != res)
+    {
+      GNUNET_break_op (0);
       return (GNUNET_NO == res)
              ? MHD_YES
              : MHD_NO;
+    }
   }
   if (0 !=
       strcasecmp (pd.price.currency,
@@ -210,6 +213,8 @@ retry:
   }
   GNUNET_JSON_parse_free (spec);
   if (qs < 0)
+  {
+    GNUNET_break_op (0);
     return TALER_MHD_reply_with_error (
       connection,
       MHD_HTTP_INTERNAL_SERVER_ERROR,
@@ -217,6 +222,7 @@ retry:
       ? TALER_EC_GENERIC_DB_SOFT_FAILURE
       : TALER_EC_GENERIC_DB_COMMIT_FAILED,
       NULL);
+  }
   return TALER_MHD_reply_static (connection,
                                  MHD_HTTP_NO_CONTENT,
                                  NULL,
diff --git a/src/backenddb/merchantdb_helper.c 
b/src/backenddb/merchantdb_helper.c
index 516a5788..5a121287 100644
--- a/src/backenddb/merchantdb_helper.c
+++ b/src/backenddb/merchantdb_helper.c
@@ -24,13 +24,14 @@
 
 
 void
-TALER_MERCHANTDB_product_details_free (struct TALER_MERCHANTDB_ProductDetails 
*pd)
+TALER_MERCHANTDB_product_details_free (
+  struct TALER_MERCHANTDB_ProductDetails *pd)
 {
   GNUNET_free (pd->description);
   json_decref (pd->description_i18n);
   GNUNET_free (pd->unit);
   json_decref (pd->taxes);
-  json_decref (pd->image);
+  GNUNET_free (pd->image);
   json_decref (pd->address);
 }
 
diff --git a/src/backenddb/plugin_merchantdb_postgres.c 
b/src/backenddb/plugin_merchantdb_postgres.c
index e39d8498..0170767d 100644
--- a/src/backenddb/plugin_merchantdb_postgres.c
+++ b/src/backenddb/plugin_merchantdb_postgres.c
@@ -986,8 +986,8 @@ postgres_lookup_product (void *cls,
                                   &pd->total_sold),
     GNUNET_PQ_result_spec_uint64 ("total_lost",
                                   &pd->total_lost),
-    TALER_PQ_result_spec_json ("image",
-                               &pd->image),
+    GNUNET_PQ_result_spec_string ("image",
+                                  &pd->image),
     TALER_PQ_result_spec_json ("address",
                                &pd->address),
     GNUNET_PQ_result_spec_absolute_time ("next_restock",
@@ -1059,7 +1059,7 @@ postgres_insert_product (void *cls,
     GNUNET_PQ_query_param_string (pd->description),
     TALER_PQ_query_param_json (pd->description_i18n),
     GNUNET_PQ_query_param_string (pd->unit),
-    TALER_PQ_query_param_json (pd->image),
+    GNUNET_PQ_query_param_string (pd->image),
     TALER_PQ_query_param_json (pd->taxes),
     TALER_PQ_query_param_amount (&pd->price),
     GNUNET_PQ_query_param_uint64 (&pd->total_stock),
@@ -1107,7 +1107,7 @@ postgres_update_product (void *cls,
     GNUNET_PQ_query_param_string (pd->description),
     TALER_PQ_query_param_json (pd->description_i18n),
     GNUNET_PQ_query_param_string (pd->unit),
-    TALER_PQ_query_param_json (pd->image), /* $6 */
+    GNUNET_PQ_query_param_string (pd->image), /* $6 */
     TALER_PQ_query_param_json (pd->taxes),
     TALER_PQ_query_param_amount (&pd->price),
     GNUNET_PQ_query_param_uint64 (&pd->total_stock),
diff --git a/src/include/taler_merchant_service.h 
b/src/include/taler_merchant_service.h
index b897bd2c..e45aded7 100644
--- a/src/include/taler_merchant_service.h
+++ b/src/include/taler_merchant_service.h
@@ -978,7 +978,7 @@ typedef void
   const json_t *description_i18n,
   const char *unit,
   const struct TALER_Amount *price,
-  const json_t *image,
+  const char *image,
   const json_t *taxes,
   int64_t total_stock,
   uint64_t total_sold,
@@ -1068,7 +1068,7 @@ TALER_MERCHANT_products_post (
   const json_t *description_i18n,
   const char *unit,
   const struct TALER_Amount *price,
-  const json_t *image,
+  const char *image,
   const json_t *taxes,
   int64_t total_stock,
   const json_t *address,
@@ -1143,7 +1143,7 @@ TALER_MERCHANT_product_patch (
   const json_t *description_i18n,
   const char *unit,
   const struct TALER_Amount *price,
-  const json_t *image,
+  const char *image,
   const json_t *taxes,
   int64_t total_stock,
   uint64_t total_lost,
diff --git a/src/include/taler_merchant_testing_lib.h 
b/src/include/taler_merchant_testing_lib.h
index 2e872406..9bd7396b 100644
--- a/src/include/taler_merchant_testing_lib.h
+++ b/src/include/taler_merchant_testing_lib.h
@@ -316,7 +316,7 @@ TALER_TESTING_cmd_merchant_post_products2 (
   json_t *description_i18n,
   const char *unit,
   const char *price,
-  json_t *image,
+  const char *image,
   json_t *taxes,
   int64_t total_stock,
   json_t *address,
@@ -380,7 +380,7 @@ TALER_TESTING_cmd_merchant_patch_product (
   json_t *description_i18n,
   const char *unit,
   const char *price,
-  json_t *image,
+  const char *image,
   json_t *taxes,
   int64_t total_stock,
   uint64_t total_lost,
diff --git a/src/include/taler_merchantdb_plugin.h 
b/src/include/taler_merchantdb_plugin.h
index 6f94e514..8a6d18e6 100644
--- a/src/include/taler_merchantdb_plugin.h
+++ b/src/include/taler_merchantdb_plugin.h
@@ -221,7 +221,7 @@ struct TALER_MERCHANTDB_ProductDetails
   /**
    * Base64-encoded product image, or an empty string.
    */
-  json_t *image;
+  char *image;
 
   /**
    * Identifies where the product is in stock, possibly an empty map.
@@ -854,7 +854,8 @@ struct TALER_MERCHANTDB_Plugin
   enum GNUNET_DB_QueryStatus
   (*update_instance_auth)(void *cls,
                           const char *merchant_id,
-                          const struct TALER_MERCHANTDB_InstanceAuthSettings 
*ias);
+                          const struct
+                          TALER_MERCHANTDB_InstanceAuthSettings *ias);
 
   /**
    * Set an instance's account in our database to "inactive".
diff --git a/src/lib/merchant_api_get_product.c 
b/src/lib/merchant_api_get_product.c
index 32e06123..9e0f9114 100644
--- a/src/lib/merchant_api_get_product.c
+++ b/src/lib/merchant_api_get_product.c
@@ -95,7 +95,7 @@ handle_get_product_finished (void *cls,
       json_t *description_i18n;
       const char *unit;
       struct TALER_Amount price;
-      json_t *image;
+      const char *image;
       json_t *taxes;
       int64_t total_stock;
       uint64_t total_sold;
@@ -112,8 +112,8 @@ handle_get_product_finished (void *cls,
                                  &unit),
         TALER_JSON_spec_amount ("price",
                                 &price),
-        GNUNET_JSON_spec_json ("image",
-                               &image),
+        GNUNET_JSON_spec_string ("image",
+                                 &image),
         GNUNET_JSON_spec_json ("taxes",
                                &taxes),
         GNUNET_JSON_spec_int64 ("total_stock",
diff --git a/src/lib/merchant_api_patch_product.c 
b/src/lib/merchant_api_patch_product.c
index f5630fc3..5cd1747e 100644
--- a/src/lib/merchant_api_patch_product.c
+++ b/src/lib/merchant_api_patch_product.c
@@ -163,7 +163,7 @@ TALER_MERCHANT_product_patch (
   const json_t *description_i18n,
   const char *unit,
   const struct TALER_Amount *price,
-  const json_t *image,
+  const char *image,
   const json_t *taxes,
   int64_t total_stock,
   uint64_t total_lost,
@@ -176,7 +176,7 @@ TALER_MERCHANT_product_patch (
   json_t *req_obj;
 
   (void) GNUNET_TIME_round_abs (&next_restock);
-  req_obj = json_pack ("{s:s, s:O, s:s, s:o, s:O,"
+  req_obj = json_pack ("{s:s, s:O, s:s, s:o, s:s,"
                        " s:O, s:I: s:I, s:O, s:o}",
                        "description",
                        description,
diff --git a/src/lib/merchant_api_post_products.c 
b/src/lib/merchant_api_post_products.c
index 7ed9755c..5ef8b90e 100644
--- a/src/lib/merchant_api_post_products.c
+++ b/src/lib/merchant_api_post_products.c
@@ -165,7 +165,7 @@ TALER_MERCHANT_products_post (
   const json_t *description_i18n,
   const char *unit,
   const struct TALER_Amount *price,
-  const json_t *image,
+  const char *image,
   const json_t *taxes,
   int64_t total_stock,
   const json_t *address,
@@ -178,7 +178,7 @@ TALER_MERCHANT_products_post (
 
   (void) GNUNET_TIME_round_abs (&next_restock);
   req_obj = json_pack ("{s:s, s:s, s:O, s:s, s:o,"
-                       " s:O, s:O, s:I, s:O, s:o}",
+                       " s:s, s:O, s:I, s:O, s:o}",
                        "product_id",
                        product_id,
                        "description",
diff --git a/src/testing/test_merchant_api.c b/src/testing/test_merchant_api.c
index 401cfd0a..6d9314b6 100644
--- a/src/testing/test_merchant_api.c
+++ b/src/testing/test_merchant_api.c
@@ -536,7 +536,7 @@ run (void *cls,
                                               json_object (),
                                               "can",
                                               "EUR:1",
-                                              json_object (),
+                                              "IMAGE-DATA",
                                               json_object (),
                                               5,
                                               0,
@@ -1367,7 +1367,7 @@ run (void *cls,
                                               json_pack ("{s:s}", "en", 
"text"),
                                               "kg",
                                               "EUR:1",
-                                              json_object (),
+                                              "IMAGE",
                                               json_object (),
                                               40,
                                               0,
@@ -1394,7 +1394,7 @@ run (void *cls,
                                               json_pack ("{s:s}", "en", 
"text"),
                                               "kg",
                                               "EUR:1",
-                                              json_object (),
+                                              "IMAGE",
                                               json_object (),
                                               40,
                                               0,
diff --git a/src/testing/testing_api_cmd_get_product.c 
b/src/testing/testing_api_cmd_get_product.c
index e65a3793..88050a42 100644
--- a/src/testing/testing_api_cmd_get_product.c
+++ b/src/testing/testing_api_cmd_get_product.c
@@ -98,7 +98,7 @@ get_product_cb (void *cls,
                 const json_t *description_i18n,
                 const char *unit,
                 const struct TALER_Amount *price,
-                const json_t *image,
+                const char *image,
                 const json_t *taxes,
                 int64_t total_stock,
                 uint64_t total_sold,
@@ -178,14 +178,15 @@ get_product_cb (void *cls,
       }
     }
     {
-      const json_t *expected_image;
+      const char *expected_image;
+
       if (GNUNET_OK !=
-          TALER_TESTING_get_trait_json (product_cmd,
-                                        1,
-                                        &expected_image))
+          TALER_TESTING_get_trait_string (product_cmd,
+                                          3,
+                                          &expected_image))
         TALER_TESTING_interpreter_fail (gis->is);
-      if (1 != json_equal (image,
-                           expected_image))
+      if (0 != strcmp (image,
+                       expected_image))
       {
         GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                     "Product image does not match\n");
diff --git a/src/testing/testing_api_cmd_patch_product.c 
b/src/testing/testing_api_cmd_patch_product.c
index 7e4476d8..6e4613df 100644
--- a/src/testing/testing_api_cmd_patch_product.c
+++ b/src/testing/testing_api_cmd_patch_product.c
@@ -77,7 +77,7 @@ struct PatchProductState
   /**
    * base64-encoded product image
    */
-  json_t *image;
+  char *image;
 
   /**
    * list of taxes paid by the merchant
@@ -205,7 +205,7 @@ patch_product_traits (void *cls,
     TALER_TESTING_make_trait_json (0, pps->description_i18n),
     TALER_TESTING_make_trait_string (1, pps->unit),
     TALER_TESTING_make_trait_amount_obj (0, &pps->price),
-    TALER_TESTING_make_trait_json (1, pps->image),
+    TALER_TESTING_make_trait_string (3, pps->image),
     TALER_TESTING_make_trait_json (2, pps->taxes),
     TALER_TESTING_make_trait_int64 (0, &pps->total_stock),
     TALER_TESTING_make_trait_json (3, pps->address),
@@ -241,7 +241,7 @@ patch_product_cleanup (void *cls,
     TALER_MERCHANT_product_patch_cancel (pis->iph);
   }
   json_decref (pis->description_i18n);
-  json_decref (pis->image);
+  GNUNET_free (pis->image);
   json_decref (pis->taxes);
   json_decref (pis->address);
   GNUNET_free (pis);
@@ -257,7 +257,7 @@ TALER_TESTING_cmd_merchant_patch_product (
   json_t *description_i18n,
   const char *unit,
   const char *price,
-  json_t *image,
+  const char *image,
   json_t *taxes,
   int64_t total_stock,
   uint64_t total_lost,
@@ -277,7 +277,7 @@ TALER_TESTING_cmd_merchant_patch_product (
   GNUNET_assert (GNUNET_OK ==
                  TALER_string_to_amount (price,
                                          &pis->price));
-  pis->image = image; /* ownership taken */
+  pis->image = GNUNET_strdup (image);
   pis->taxes = taxes; /* ownership taken */
   pis->total_stock = total_stock;
   pis->total_lost = total_lost;
diff --git a/src/testing/testing_api_cmd_post_products.c 
b/src/testing/testing_api_cmd_post_products.c
index b1f497db..1a358a7e 100644
--- a/src/testing/testing_api_cmd_post_products.c
+++ b/src/testing/testing_api_cmd_post_products.c
@@ -77,7 +77,7 @@ struct PostProductsState
   /**
    * base64-encoded product image
    */
-  json_t *image;
+  char *image;
 
   /**
    * list of taxes paid by the merchant
@@ -202,7 +202,7 @@ post_products_traits (void *cls,
     TALER_TESTING_make_trait_json (0, pps->description_i18n),
     TALER_TESTING_make_trait_string (1, pps->unit),
     TALER_TESTING_make_trait_amount_obj (0, &pps->price),
-    TALER_TESTING_make_trait_json (1, pps->image),
+    TALER_TESTING_make_trait_string (3, pps->image),
     TALER_TESTING_make_trait_json (2, pps->taxes),
     TALER_TESTING_make_trait_int64 (0, &pps->total_stock),
     TALER_TESTING_make_trait_json (3, pps->address),
@@ -238,7 +238,7 @@ post_products_cleanup (void *cls,
     TALER_MERCHANT_products_post_cancel (pis->iph);
   }
   json_decref (pis->description_i18n);
-  json_decref (pis->image);
+  GNUNET_free (pis->image);
   json_decref (pis->taxes);
   json_decref (pis->address);
   GNUNET_free (pis);
@@ -254,7 +254,7 @@ TALER_TESTING_cmd_merchant_post_products2 (
   json_t *description_i18n,
   const char *unit,
   const char *price,
-  json_t *image,
+  const char *image,
   json_t *taxes,
   int64_t total_stock,
   json_t *address,
@@ -273,7 +273,7 @@ TALER_TESTING_cmd_merchant_post_products2 (
   GNUNET_assert (GNUNET_OK ==
                  TALER_string_to_amount (price,
                                          &pis->price));
-  pis->image = image; /* ownership taken */
+  pis->image = GNUNET_strdup (image);
   pis->taxes = taxes; /* ownership taken */
   pis->total_stock = total_stock;
   pis->address = address; /* ownership taken */
@@ -308,7 +308,7 @@ TALER_TESTING_cmd_merchant_post_products (const char *label,
     json_pack ("{s:s}", "en", description),
     "test-unit",
     price,
-    json_object (),
+    "",
     json_object (),
     4,
     json_pack ("{s:s}", "street", "my street"),

-- 
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]