gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] [taler-merchant] branch master updated (144e55a -> 4d6a591)


From: gnunet
Subject: [GNUnet-SVN] [taler-merchant] branch master updated (144e55a -> 4d6a591)
Date: Wed, 17 Jan 2018 23:07:46 +0100

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

dold pushed a change to branch master
in repository merchant.

    from 144e55a  typo in header
     new 09de8f4  parse locations from config
     new 7215dea  remove unused exported variable
     new 4d6a591  include locations and proper labels in proposal

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 src/backend/taler-merchant-httpd.c          | 76 +++++++++++++++++++++++++++++
 src/backend/taler-merchant-httpd.h          |  5 +-
 src/backend/taler-merchant-httpd_proposal.c | 39 ++++++++++++++-
 3 files changed, 116 insertions(+), 4 deletions(-)

diff --git a/src/backend/taler-merchant-httpd.c 
b/src/backend/taler-merchant-httpd.c
index 0ae5d39..ea3b7b4 100644
--- a/src/backend/taler-merchant-httpd.c
+++ b/src/backend/taler-merchant-httpd.c
@@ -79,6 +79,12 @@ static long long unsigned port;
 struct GNUNET_TIME_Relative wire_transfer_delay;
 
 /**
+ * Locations from the configuration.  Mapping from
+ * label to location data.
+ */
+json_t *default_locations;
+
+/**
  * If the frontend does NOT specify a payment deadline, how long should
  * offers we make be valid by default?
  */
@@ -507,6 +513,57 @@ prepare_daemon ()
 
 
 /**
+ * Callback that looks for 'merchant-location-*' sections,
+ * and populates @a default_locations.
+ *
+ * @param cls closure
+ * @section section name this callback gets
+ */
+static void
+locations_iterator_cb (void *cls,
+                       const char *section)
+{
+  struct GNUNET_CONFIGURATION_Handle *cfg = cls;
+  const char *prefix = "merchant-location-";
+  const char *substr = strstr (section, prefix);
+  const char *locname;
+  json_t *loc;
+
+  if ( (NULL == substr) || (substr != section) )
+    return;
+
+  locname = section + strlen (prefix);
+  if (0 == strlen (locname))
+    return;
+
+  GNUNET_assert (json_is_object (default_locations));
+
+  loc = json_object ();
+  json_object_set_new (default_locations, locname, loc);
+
+  char *keys[] = {
+    "country", "city", "state", "region", "province",
+    "zip_code", "street", "street_number",
+    NULL,
+  };
+
+  for (unsigned int pos = 0; NULL != keys[pos]; pos++)
+  {
+    char *val;
+    (void) GNUNET_CONFIGURATION_get_value_string (cfg,
+                                                  section,
+                                                  keys[pos],
+                                                  &val);
+    if (NULL != val)
+    {
+      json_object_set_new (loc, keys[pos], json_string (val));
+      GNUNET_free (val);
+    }
+  }
+}
+
+
+/**
  * Callback that looks for 'merchant-instance-*' sections,
  * and populates accordingly each instance's data
  *
@@ -775,6 +832,23 @@ TMH_lookup_instance_json (struct json_t *json)
 
 
 /**
+ * Iterate over locations in config in order to populate
+ * the location data.
+ *
+ * @param config configuration handle
+ * @return #GNUNET_OK if successful, #GNUNET_SYSERR upon errors
+ */
+static void
+iterate_locations (const struct GNUNET_CONFIGURATION_Handle *config)
+{
+  GNUNET_assert (NULL == default_locations);
+  default_locations = json_object ();
+  GNUNET_CONFIGURATION_iterate_sections (config,
+                                         &locations_iterator_cb,
+                                         (void *) config);
+}
+
+/**
  * Iterate over each merchant instance, in order to populate
  * each instance's own data
  *
@@ -986,6 +1060,8 @@ run (void *cls,
   }
   GNUNET_free (wireformat);
 
+  iterate_locations (config);
+
   if (NULL ==
       (db = TALER_MERCHANTDB_plugin_load (config)))
   {
diff --git a/src/backend/taler-merchant-httpd.h 
b/src/backend/taler-merchant-httpd.h
index a1b0f84..e86d387 100644
--- a/src/backend/taler-merchant-httpd.h
+++ b/src/backend/taler-merchant-httpd.h
@@ -236,9 +236,10 @@ struct TM_HandlerContext
 
 
 /**
- * Our wire format details in JSON format (with salt).
+ * Locations from the configuration.  Mapping from
+ * label to location data.
  */
-extern json_t *j_wire;
+extern json_t *default_locations;
 
 /**
  * Default maximum wire fee to assume, unless stated differently in the 
proposal
diff --git a/src/backend/taler-merchant-httpd_proposal.c 
b/src/backend/taler-merchant-httpd_proposal.c
index 61da3b3..f7be8b0 100644
--- a/src/backend/taler-merchant-httpd_proposal.c
+++ b/src/backend/taler-merchant-httpd_proposal.c
@@ -311,6 +311,9 @@ proposal_put (struct MHD_Connection *connection,
     // the backend the "instance" name and lets it fill out.
     struct MerchantInstance *mi = TMH_lookup_instance (instance);
     json_t *merchant;
+    json_t *locations;
+    json_t *loc;
+    char *label;
 
     if (NULL == mi)
     {
@@ -329,15 +332,47 @@ proposal_put (struct MHD_Connection *connection,
                          json_string (mi->name));
     json_object_set_new (merchant,
                          "jurisdiction",
-                         json_string ("none"));
+                         json_string ("_mj"));
     json_object_set_new (merchant,
                          "address",
-                         json_string ("none"));
+                         json_string ("_ma"));
     json_object_set_new (order,
                          "merchant",
                          merchant);
     json_object_del (order,
                      "instance");
+
+    locations = json_object_get (order,
+                                 "locations");
+    if (NULL == locations)
+    {
+      locations = json_object ();
+      json_object_set_new (order,
+                           "locations",
+                           locations);
+    }
+
+    GNUNET_assert (0 < GNUNET_asprintf (&label,
+                                        "merchant-location-%s-address",
+                                        mi->id));
+    loc = json_object_get (default_locations, label);
+    if (NULL == loc)
+      loc = json_object ();
+    else
+      loc = json_deep_copy (loc);
+    json_object_set_new (locations, "_ma", loc);
+    GNUNET_free (label);
+
+    GNUNET_assert (0 < GNUNET_asprintf (&label,
+                                        "merchant-location-%s-jurisdiction",
+                                        mi->id));
+    loc = json_object_get (default_locations, label);
+    if (NULL == loc)
+      loc = json_object ();
+    else
+      loc = json_deep_copy (loc);
+    json_object_set_new (locations, "_mj", loc);
+    GNUNET_free (label);
   }
 
   /* extract fields we need to sign separately */

-- 
To stop receiving notification emails like this one, please contact
address@hidden



reply via email to

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