gnunet-svn
[Top][All Lists]
Advanced

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

[taler-merchant] 01/02: implement protocol spec v15


From: gnunet
Subject: [taler-merchant] 01/02: implement protocol spec v15
Date: Mon, 13 May 2024 13:50:51 +0200

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

grothoff pushed a commit to branch master
in repository merchant.

commit 0e0751a19096f2ab08e519c9d8735f14c658bbfb
Author: Christian Grothoff <christian@grothoff.org>
AuthorDate: Mon May 13 13:27:40 2024 +0200

    implement protocol spec v15
---
 contrib/wallet-core                                |   2 +-
 src/backend/Makefile.am                            |   2 +
 src/backend/taler-merchant-httpd.c                 |   7 +
 src/backend/taler-merchant-httpd_config.c          |   2 +-
 src/backend/taler-merchant-httpd_private-get-pos.c | 145 +++++++++++++++++
 src/backend/taler-merchant-httpd_private-get-pos.h |  41 +++++
 .../taler-merchant-httpd_private-get-products-ID.c |  22 +--
 src/backenddb/Makefile.am                          |   1 +
 src/backenddb/pg_lookup_all_products.c             | 171 +++++++++++++++++++++
 src/backenddb/pg_lookup_all_products.h             |  46 ++++++
 src/backenddb/pg_lookup_product.c                  |   2 +-
 src/backenddb/plugin_merchantdb_postgres.c         |   3 +
 src/include/taler_merchant_service.h               |   6 +-
 src/include/taler_merchantdb_plugin.h              |  32 ++++
 src/lib/merchant_api_get_config.c                  |   4 +-
 src/lib/merchant_api_get_product.c                 |  31 ++--
 16 files changed, 488 insertions(+), 29 deletions(-)

diff --git a/contrib/wallet-core b/contrib/wallet-core
index 68b2ef73..240d647d 160000
--- a/contrib/wallet-core
+++ b/contrib/wallet-core
@@ -1 +1 @@
-Subproject commit 68b2ef735377373da29fd20aeb9facaf91c03832
+Subproject commit 240d647da85de6b575d15c37efec04757541e3dc
diff --git a/src/backend/Makefile.am b/src/backend/Makefile.am
index dbc7cde8..65ffa514 100644
--- a/src/backend/Makefile.am
+++ b/src/backend/Makefile.am
@@ -65,6 +65,8 @@ taler_merchant_httpd_SOURCES = \
     taler-merchant-httpd_private-get-instances-ID.h \
   taler-merchant-httpd_private-get-instances-ID-kyc.c \
     taler-merchant-httpd_private-get-instances-ID-kyc.h \
+  taler-merchant-httpd_private-get-pos.c \
+    taler-merchant-httpd_private-get-pos.h \
   taler-merchant-httpd_private-get-products.c \
     taler-merchant-httpd_private-get-products.h \
   taler-merchant-httpd_private-get-products-ID.c \
diff --git a/src/backend/taler-merchant-httpd.c 
b/src/backend/taler-merchant-httpd.c
index 7384bfc9..0fa83d81 100644
--- a/src/backend/taler-merchant-httpd.c
+++ b/src/backend/taler-merchant-httpd.c
@@ -48,6 +48,7 @@
 #include "taler-merchant-httpd_private-get-instances.h"
 #include "taler-merchant-httpd_private-get-instances-ID.h"
 #include "taler-merchant-httpd_private-get-instances-ID-kyc.h"
+#include "taler-merchant-httpd_private-get-pos.h"
 #include "taler-merchant-httpd_private-get-products.h"
 #include "taler-merchant-httpd_private-get-products-ID.h"
 #include "taler-merchant-httpd_private-get-orders.h"
@@ -932,6 +933,12 @@ url_handler (void *cls,
       .method = MHD_HTTP_METHOD_GET,
       .handler = &TMH_private_get_instances_ID_kyc,
     },
+    /* GET /pos: */
+    {
+      .url_prefix = "/pos",
+      .method = MHD_HTTP_METHOD_GET,
+      .handler = &TMH_private_get_pos
+    },
     /* GET /products: */
     {
       .url_prefix = "/products",
diff --git a/src/backend/taler-merchant-httpd_config.c 
b/src/backend/taler-merchant-httpd_config.c
index d1340249..97dd1714 100644
--- a/src/backend/taler-merchant-httpd_config.c
+++ b/src/backend/taler-merchant-httpd_config.c
@@ -42,7 +42,7 @@
  * #MERCHANT_PROTOCOL_CURRENT and #MERCHANT_PROTOCOL_AGE in
  * merchant_api_config.c!
  */
-#define MERCHANT_PROTOCOL_VERSION "14:1:10"
+#define MERCHANT_PROTOCOL_VERSION "15:0:11"
 
 
 /**
diff --git a/src/backend/taler-merchant-httpd_private-get-pos.c 
b/src/backend/taler-merchant-httpd_private-get-pos.c
new file mode 100644
index 00000000..1f6f1262
--- /dev/null
+++ b/src/backend/taler-merchant-httpd_private-get-pos.c
@@ -0,0 +1,145 @@
+/*
+  This file is part of TALER
+  (C) 2019, 2020, 2021, 2024 Taler Systems SA
+
+  TALER is free software; you can redistribute it and/or modify it under the
+  terms of the GNU Affero General Public License as published by the Free 
Software
+  Foundation; either version 3, or (at your option) any later version.
+
+  TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+  WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+  A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
+
+  You should have received a copy of the GNU General Public License along with
+  TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file taler-merchant-httpd_private-get-pos.c
+ * @brief implement GET /private/pos
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler-merchant-httpd_private-get-pos.h"
+
+
+/**
+ * Closure for add_product().
+ */
+struct Context
+{
+  /**
+   * JSON array of products we are building.
+   */
+  json_t *pa;
+
+  /**
+   * JSON array of categories we are building.
+   */
+  json_t *ca;
+
+};
+
+
+/**
+ * Add product details to our JSON array.
+ *
+ * @param ctx a `struct Context` with JSON arrays to build
+ * @param product_id ID of the product
+ */
+static void
+add_product (void *cls,
+             uint64_t product_serial,
+             const char *product_id,
+             const struct TALER_MERCHANTDB_ProductDetails *pd)
+{
+  struct Context *ctx = cls;
+  json_t *pa = ctx->pa;
+  json_t *cata;
+
+  /* FIXME: add proper category support! */
+  cata = json_array ();
+  GNUNET_assert (
+    0 == json_array_append_new (
+      cata,
+      json_integer (0)));
+  GNUNET_assert (
+    0 ==
+    json_array_append_new (
+      pa,
+      GNUNET_JSON_PACK (
+        GNUNET_JSON_pack_string ("description",
+                                 pd->description),
+        GNUNET_JSON_pack_object_incref ("description_i18n",
+                                        (json_t *) pd->description_i18n),
+        GNUNET_JSON_pack_string ("unit",
+                                 pd->unit),
+        TALER_JSON_pack_amount ("price",
+                                &pd->price),
+        GNUNET_JSON_pack_allow_null (
+          GNUNET_JSON_pack_string ("image",
+                                   pd->image)),
+        GNUNET_JSON_pack_array_steal ("categories",
+                                      cata),
+        GNUNET_JSON_pack_allow_null (
+          GNUNET_JSON_pack_array_incref ("taxes",
+                                         (json_t *) pd->taxes)),
+        (INT64_MAX == pd->total_stock)
+        ? GNUNET_JSON_pack_int64 ("total_stock",
+                                  pd->total_stock)
+        : GNUNET_JSON_pack_allow_null (
+          GNUNET_JSON_pack_string ("total_stock",
+                                   NULL)),
+        GNUNET_JSON_pack_uint64 ("minimum_age",
+                                 pd->minimum_age),
+        GNUNET_JSON_pack_uint64 ("product_serial",
+                                 product_serial),
+        GNUNET_JSON_pack_string ("product_id",
+                                 product_id))));
+}
+
+
+MHD_RESULT
+TMH_private_get_pos (const struct TMH_RequestHandler *rh,
+                     struct MHD_Connection *connection,
+                     struct TMH_HandlerContext *hc)
+{
+  struct Context ctx;
+  enum GNUNET_DB_QueryStatus qs;
+
+  ctx.pa = json_array ();
+  GNUNET_assert (NULL != ctx.pa);
+  ctx.ca = json_array ();
+  GNUNET_assert (NULL != ctx.ca);
+  GNUNET_assert (
+    0 == json_array_append_new (
+      ctx.ca,
+      GNUNET_JSON_PACK (
+        GNUNET_JSON_pack_uint64 ("id",
+                                 0),
+        GNUNET_JSON_pack_string ("name",
+                                 "default"))));
+  qs = TMH_db->lookup_all_products (TMH_db->cls,
+                                    hc->instance->settings.id,
+                                    &add_product,
+                                    &ctx);
+  if (0 > qs)
+  {
+    GNUNET_break (0);
+    json_decref (ctx.pa);
+    json_decref (ctx.ca);
+    return TALER_MHD_reply_with_error (connection,
+                                       MHD_HTTP_INTERNAL_SERVER_ERROR,
+                                       TALER_EC_GENERIC_DB_FETCH_FAILED,
+                                       NULL);
+  }
+  return TALER_MHD_REPLY_JSON_PACK (
+    connection,
+    MHD_HTTP_OK,
+    GNUNET_JSON_pack_array_steal ("categories",
+                                  ctx.ca),
+    GNUNET_JSON_pack_array_steal ("products",
+                                  ctx.pa));
+}
+
+
+/* end of taler-merchant-httpd_private-get-pos.c */
diff --git a/src/backend/taler-merchant-httpd_private-get-pos.h 
b/src/backend/taler-merchant-httpd_private-get-pos.h
new file mode 100644
index 00000000..ce266823
--- /dev/null
+++ b/src/backend/taler-merchant-httpd_private-get-pos.h
@@ -0,0 +1,41 @@
+/*
+  This file is part of TALER
+  (C) 2024 Taler Systems SA
+
+  TALER is free software; you can redistribute it and/or modify it under the
+  terms of the GNU Affero General Public License as published by the Free 
Software
+  Foundation; either version 3, or (at your option) any later version.
+
+  TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+  WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+  A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
+
+  You should have received a copy of the GNU General Public License along with
+  TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file taler-merchant-httpd_private-get-pos.h
+ * @brief implement GET /pos
+ * @author Christian Grothoff
+ */
+#ifndef TALER_MERCHANT_HTTPD_PRIVATE_GET_POS_H
+#define TALER_MERCHANT_HTTPD_PRIVATE_GET_POS_H
+
+#include "taler-merchant-httpd.h"
+
+
+/**
+ * Handle a GET "/pos" request.
+ *
+ * @param rh context of the handler
+ * @param connection the MHD connection to handle
+ * @param[in,out] hc context with further information about the request
+ * @return MHD result code
+ */
+MHD_RESULT
+TMH_private_get_pos (const struct TMH_RequestHandler *rh,
+                     struct MHD_Connection *connection,
+                     struct TMH_HandlerContext *hc);
+
+/* end of taler-merchant-httpd_private-get-pos.h */
+#endif
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 1406349f..107081f7 100644
--- a/src/backend/taler-merchant-httpd_private-get-products-ID.c
+++ b/src/backend/taler-merchant-httpd_private-get-products-ID.c
@@ -32,9 +32,10 @@
  * @return MHD result code
  */
 MHD_RESULT
-TMH_private_get_products_ID (const struct TMH_RequestHandler *rh,
-                             struct MHD_Connection *connection,
-                             struct TMH_HandlerContext *hc)
+TMH_private_get_products_ID (
+  const struct TMH_RequestHandler *rh,
+  struct MHD_Connection *connection,
+  struct TMH_HandlerContext *hc)
 {
   struct TMH_MerchantInstance *mi = hc->instance;
   struct TALER_MERCHANTDB_ProductDetails pd = { 0 };
@@ -74,10 +75,12 @@ TMH_private_get_products_ID (const struct 
TMH_RequestHandler *rh,
                                pd.unit),
       TALER_JSON_pack_amount ("price",
                               &pd.price),
-      GNUNET_JSON_pack_string ("image",
-                               pd.image),
-      GNUNET_JSON_pack_array_steal ("taxes",
-                                    pd.taxes),
+      GNUNET_JSON_pack_allow_null (
+        GNUNET_JSON_pack_string ("image",
+                                 pd.image)),
+      GNUNET_JSON_pack_allow_null (
+        GNUNET_JSON_pack_array_steal ("taxes",
+                                      pd.taxes)),
       GNUNET_JSON_pack_int64 ("total_stock",
                               (INT64_MAX == pd.total_stock)
                               ? -1LL
@@ -86,8 +89,9 @@ TMH_private_get_products_ID (const struct TMH_RequestHandler 
*rh,
                                pd.total_sold),
       GNUNET_JSON_pack_uint64 ("total_lost",
                                pd.total_lost),
-      GNUNET_JSON_pack_object_steal ("address",
-                                     pd.address),
+      GNUNET_JSON_pack_allow_null (
+        GNUNET_JSON_pack_object_steal ("address",
+                                       pd.address)),
       GNUNET_JSON_pack_allow_null (
         GNUNET_JSON_pack_timestamp ("next_restock",
                                     (pd.next_restock))),
diff --git a/src/backenddb/Makefile.am b/src/backenddb/Makefile.am
index defc3cf9..89be9a4f 100644
--- a/src/backenddb/Makefile.am
+++ b/src/backenddb/Makefile.am
@@ -112,6 +112,7 @@ libtaler_plugin_merchantdb_postgres_la_SOURCES = \
   pg_update_template.h pg_update_template.c \
   pg_lookup_templates.h pg_lookup_templates.c \
   pg_lookup_template.h pg_lookup_template.c \
+  pg_lookup_all_products.h pg_lookup_all_products.c \
   pg_lookup_products.h pg_lookup_products.c \
   pg_lookup_product.h pg_lookup_product.c \
   pg_delete_product.h pg_delete_product.c \
diff --git a/src/backenddb/pg_lookup_all_products.c 
b/src/backenddb/pg_lookup_all_products.c
new file mode 100644
index 00000000..29751a45
--- /dev/null
+++ b/src/backenddb/pg_lookup_all_products.c
@@ -0,0 +1,171 @@
+/*
+   This file is part of TALER
+   Copyright (C) 2024 Taler Systems SA
+
+   TALER is free software; you can redistribute it and/or modify it under the
+   terms of the GNU General Public License as published by the Free Software
+   Foundation; either version 3, or (at your option) any later version.
+
+   TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+   WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 
FOR
+   A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License along with
+   TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file backenddb/pg_lookup_all_products.c
+ * @brief Implementation of the lookup_all_products function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include <taler/taler_error_codes.h>
+#include <taler/taler_dbevents.h>
+#include <taler/taler_pq_lib.h>
+#include "pg_lookup_products.h"
+#include "pg_helper.h"
+
+/**
+ * Context used for TMH_PG_lookup_all_products().
+ */
+struct LookupProductsContext
+{
+  /**
+   * Function to call with the results.
+   */
+  TALER_MERCHANTDB_ProductCallback cb;
+
+  /**
+   * Closure for @a cb.
+   */
+  void *cb_cls;
+
+  /**
+   * Did database result extraction fail?
+   */
+  bool extract_failed;
+};
+
+
+/**
+ * Function to be called with the results of a SELECT statement
+ * that has returned @a num_results results about products.
+ *
+ * @param[in,out] cls of type `struct LookupProductsContext *`
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+lookup_products_cb (void *cls,
+                    PGresult *result,
+                    unsigned int num_results)
+{
+  struct LookupProductsContext *plc = cls;
+
+  for (unsigned int i = 0; i < num_results; i++)
+  {
+    char *product_id;
+    uint64_t product_serial;
+    struct TALER_MERCHANTDB_ProductDetails pd;
+    struct GNUNET_PQ_ResultSpec rs[] = {
+      GNUNET_PQ_result_spec_string ("product_id",
+                                    &product_id),
+      GNUNET_PQ_result_spec_uint64 ("product_serial",
+                                    &product_serial),
+      GNUNET_PQ_result_spec_string ("description",
+                                    &pd.description),
+      TALER_PQ_result_spec_json ("description_i18n",
+                                 &pd.description_i18n),
+      GNUNET_PQ_result_spec_string ("unit",
+                                    &pd.unit),
+      TALER_PQ_result_spec_amount_with_currency ("price",
+                                   &pd.price),
+      TALER_PQ_result_spec_json ("taxes",
+                                 &pd.taxes),
+      GNUNET_PQ_result_spec_uint64 ("total_stock",
+                                    &pd.total_stock),
+      GNUNET_PQ_result_spec_uint64 ("total_sold",
+                                    &pd.total_sold),
+      GNUNET_PQ_result_spec_uint64 ("total_lost",
+                                    &pd.total_lost),
+      GNUNET_PQ_result_spec_string ("image",
+                                    &pd.image),
+      TALER_PQ_result_spec_json ("address",
+                                 &pd.address),
+      GNUNET_PQ_result_spec_timestamp ("next_restock",
+                                       &pd.next_restock),
+      GNUNET_PQ_result_spec_uint32 ("minimum_age",
+                                    &pd.minimum_age),
+      GNUNET_PQ_result_spec_end
+    };
+
+    if (GNUNET_OK !=
+        GNUNET_PQ_extract_result (result,
+                                  rs,
+                                  i))
+    {
+      GNUNET_break (0);
+      plc->extract_failed = true;
+      return;
+    }
+    plc->cb (plc->cb_cls,
+             product_serial,
+             product_id,
+             &pd);
+    GNUNET_PQ_cleanup_result (rs);
+  }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TMH_PG_lookup_all_products (void *cls,
+                        const char *instance_id,
+                        TALER_MERCHANTDB_ProductCallback cb,
+                        void *cb_cls)
+{
+  struct PostgresClosure *pg = cls;
+  struct LookupProductsContext plc = {
+    .cb = cb,
+    .cb_cls = cb_cls,
+    /* Can be overwritten by the lookup_products_cb */
+    .extract_failed = false,
+  };
+  struct GNUNET_PQ_QueryParam params[] = {
+    GNUNET_PQ_query_param_string (instance_id),
+    GNUNET_PQ_query_param_end
+  };
+  enum GNUNET_DB_QueryStatus qs;
+
+  check_connection (pg);
+  PREPARE (pg,
+           "lookup_all_products",
+           "SELECT"
+           " description"
+           ",description_i18n"
+           ",unit"
+           ",price"
+           ",taxes"
+           ",total_stock"
+           ",total_sold"
+           ",total_lost"
+           ",image"
+           ",merchant_inventory.address"
+           ",next_restock"
+           ",minimum_age"
+           ",product_id"
+           ",product_serial"
+           " FROM merchant_inventory"
+           " JOIN merchant_instances"
+           "   USING (merchant_serial)"
+           " WHERE merchant_instances.merchant_id=$1");
+  qs = GNUNET_PQ_eval_prepared_multi_select (
+    pg->conn,
+    "lookup_all_products",
+    params,
+    &lookup_products_cb,
+    &plc);
+  /* If there was an error inside lookup_products_cb, return a hard error. */
+  if (plc.extract_failed)
+    return GNUNET_DB_STATUS_HARD_ERROR;
+  return qs;
+}
diff --git a/src/backenddb/pg_lookup_all_products.h 
b/src/backenddb/pg_lookup_all_products.h
new file mode 100644
index 00000000..390fa60d
--- /dev/null
+++ b/src/backenddb/pg_lookup_all_products.h
@@ -0,0 +1,46 @@
+/*
+   This file is part of TALER
+   Copyright (C) 2024 Taler Systems SA
+
+   TALER is free software; you can redistribute it and/or modify it under the
+   terms of the GNU General Public License as published by the Free Software
+   Foundation; either version 3, or (at your option) any later version.
+
+   TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+   WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 
FOR
+   A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License along with
+   TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file backenddb/pg_lookup_all_products.h
+ * @brief implementation of the lookup_all_products function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_LOOKUP_ALL_PRODUCTS_H
+#define PG_LOOKUP_ALL_PRODUCTS_H
+
+#include <taler/taler_util.h>
+#include <taler/taler_json_lib.h>
+#include "taler_merchantdb_plugin.h"
+
+/**
+ * Lookup all of the products the given instance has configured.
+ *
+ * @param cls closure
+ * @param instance_id instance to lookup products for
+ * @param offset transfer_serial number of the transfer we want to offset from
+ * @param limit number of entries to return, negative for descending,
+ *                positive for ascending
+ * @param cb function to call on all products found
+ * @param cb_cls closure for @a cb
+ * @return database result code
+ */
+enum GNUNET_DB_QueryStatus
+TMH_PG_lookup_all_products (void *cls,
+                            const char *instance_id,
+                            TALER_MERCHANTDB_ProductCallback cb,
+                            void *cb_cls);
+
+#endif
diff --git a/src/backenddb/pg_lookup_product.c 
b/src/backenddb/pg_lookup_product.c
index 65a3c0e5..a078cf8e 100644
--- a/src/backenddb/pg_lookup_product.c
+++ b/src/backenddb/pg_lookup_product.c
@@ -60,7 +60,7 @@ TMH_PG_lookup_product (void *cls,
       GNUNET_PQ_result_spec_string ("unit",
                                     &pd->unit),
       TALER_PQ_result_spec_amount_with_currency ("price",
-                                   &pd->price),
+                                                 &pd->price),
       TALER_PQ_result_spec_json ("taxes",
                                  &pd->taxes),
       GNUNET_PQ_result_spec_uint64 ("total_stock",
diff --git a/src/backenddb/plugin_merchantdb_postgres.c 
b/src/backenddb/plugin_merchantdb_postgres.c
index e5f3f2a1..4a03dbfe 100644
--- a/src/backenddb/plugin_merchantdb_postgres.c
+++ b/src/backenddb/plugin_merchantdb_postgres.c
@@ -63,6 +63,7 @@
 #include "pg_inactivate_account.h"
 #include "pg_activate_account.h"
 #include "pg_lookup_products.h"
+#include "pg_lookup_all_products.h"
 #include "pg_lookup_product.h"
 #include "pg_delete_product.h"
 #include "pg_insert_product.h"
@@ -407,6 +408,8 @@ libtaler_plugin_merchantdb_postgres_init (void *cls)
     = &TMH_PG_update_transfer_status;
   plugin->lookup_products
     = &TMH_PG_lookup_products;
+  plugin->lookup_all_products
+    = &TMH_PG_lookup_all_products;
   plugin->lookup_product
     = &TMH_PG_lookup_product;
   plugin->delete_product
diff --git a/src/include/taler_merchant_service.h 
b/src/include/taler_merchant_service.h
index 057c9eff..537a2485 100644
--- a/src/include/taler_merchant_service.h
+++ b/src/include/taler_merchant_service.h
@@ -1516,12 +1516,12 @@ struct TALER_MERCHANT_ProductGetResponse
       struct TALER_Amount price;
 
       /**
-       * base64-encoded product image
+       * base64-encoded product image, can be NULL if none is set.
        */
       const char *image;
 
       /**
-       * list of taxes paid by the merchant
+       * list of taxes paid by the merchant, can be NULL if no taxes were 
specified.
        */
       const json_t *taxes;
 
@@ -1544,7 +1544,7 @@ struct TALER_MERCHANT_ProductGetResponse
       uint64_t total_lost;
 
       /**
-       * where the product is in stock
+       * where the product is in stock, can be NULL if no location was given.
        */
       const json_t *location;
 
diff --git a/src/include/taler_merchantdb_plugin.h 
b/src/include/taler_merchantdb_plugin.h
index 44fdc0ab..12b13e33 100644
--- a/src/include/taler_merchantdb_plugin.h
+++ b/src/include/taler_merchantdb_plugin.h
@@ -334,6 +334,22 @@ struct TALER_MERCHANTDB_ProductDetails
 };
 
 
+/**
+ * Typically called by `lookup_all_products`.
+ *
+ * @param cls a `json_t *` JSON array to build
+ * @param product_serial row ID of the product
+ * @param product_id ID of the product
+ * @param pd full product details
+ */
+typedef void
+(*TALER_MERCHANTDB_ProductCallback)(
+  void *cls,
+  uint64_t product_serial,
+  const char *product_id,
+  const struct TALER_MERCHANTDB_ProductDetails *pd);
+
+
 /**
  * Typically called by `lookup_templates`.
  *
@@ -1619,6 +1635,22 @@ struct TALER_MERCHANTDB_Plugin
                      TALER_MERCHANTDB_ProductsCallback cb,
                      void *cb_cls);
 
+
+  /**
+   * Lookup full details of all of the products the given instance has 
configured (expensive).
+   *
+   * @param cls closure
+   * @param instance_id instance to lookup products for
+   * @param cb function to call on all products found
+   * @param cb_cls closure for @a cb
+   * @return database result code
+   */
+  enum GNUNET_DB_QueryStatus
+  (*lookup_all_products)(void *cls,
+                         const char *instance_id,
+                         TALER_MERCHANTDB_ProductCallback cb,
+                         void *cb_cls);
+
   /**
    * Lookup details about a particular product.
    *
diff --git a/src/lib/merchant_api_get_config.c 
b/src/lib/merchant_api_get_config.c
index b4b700bd..cf5147fe 100644
--- a/src/lib/merchant_api_get_config.c
+++ b/src/lib/merchant_api_get_config.c
@@ -34,12 +34,12 @@
  * Which version of the Taler protocol is implemented
  * by this library?  Used to determine compatibility.
  */
-#define MERCHANT_PROTOCOL_CURRENT 14
+#define MERCHANT_PROTOCOL_CURRENT 15
 
 /**
  * How many configs are we backwards-compatible with?
  */
-#define MERCHANT_PROTOCOL_AGE 2
+#define MERCHANT_PROTOCOL_AGE 3
 
 /**
  * How many exchanges do we allow at most per merchant?
diff --git a/src/lib/merchant_api_get_product.c 
b/src/lib/merchant_api_get_product.c
index 3f026bf3..bb10a438 100644
--- a/src/lib/merchant_api_get_product.c
+++ b/src/lib/merchant_api_get_product.c
@@ -1,6 +1,6 @@
 /*
   This file is part of TALER
-  Copyright (C) 2014-2023 Taler Systems SA
+  Copyright (C) 2014-2024 Taler Systems SA
 
   TALER is free software; you can redistribute it and/or modify it under the
   terms of the GNU Lesser General Public License as published by the Free 
Software
@@ -105,12 +105,16 @@ handle_get_product_finished (void *cls,
         TALER_JSON_spec_amount_any (
           "price",
           &pgr.details.ok.price),
-        GNUNET_JSON_spec_string (
-          "image",
-          &pgr.details.ok.image),
-        GNUNET_JSON_spec_array_const (
-          "taxes",
-          &pgr.details.ok.taxes),
+        GNUNET_JSON_spec_mark_optional (
+          GNUNET_JSON_spec_string (
+            "image",
+            &pgr.details.ok.image),
+          NULL),
+        GNUNET_JSON_spec_mark_optional (
+          GNUNET_JSON_spec_array_const (
+            "taxes",
+            &pgr.details.ok.taxes),
+          NULL),
         GNUNET_JSON_spec_int64 (
           "total_stock",
           &pgr.details.ok.total_stock),
@@ -120,12 +124,15 @@ handle_get_product_finished (void *cls,
         GNUNET_JSON_spec_uint64 (
           "total_lost",
           &pgr.details.ok.total_lost),
-        GNUNET_JSON_spec_object_const (
-          "address",
-          &pgr.details.ok.location),
         GNUNET_JSON_spec_mark_optional (
-          GNUNET_JSON_spec_timestamp ("next_restock",
-                                      &pgr.details.ok.next_restock),
+          GNUNET_JSON_spec_object_const (
+            "address",
+            &pgr.details.ok.location),
+          NULL),
+        GNUNET_JSON_spec_mark_optional (
+          GNUNET_JSON_spec_timestamp (
+            "next_restock",
+            &pgr.details.ok.next_restock),
           NULL),
         GNUNET_JSON_spec_end ()
       };

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