commit a3daea66496095ad184a19a534d9f659858691ad
parent 705e4f219889ca4f8a9562034d8c69d53f63ada1
Author: Marcello Stanisci <marcello.stanisci@inria.fr>
Date: Wed, 22 Jun 2016 19:58:30 +0200
proper closure for instances iterator
Diffstat:
2 files changed, 62 insertions(+), 6 deletions(-)
diff --git a/src/backend/taler-merchant-httpd.c b/src/backend/taler-merchant-httpd.c
@@ -524,9 +524,13 @@ instances_iterator_cb (void *cls,
&mi->pubkey.eddsa_pub);
GNUNET_free (pk);
+ /** To free or not to free **/
+ mi->id = token + 1;
+
/**
* Fill 'id'
* Fill wirething
+ * Check if 'default' given
*/
}
@@ -536,16 +540,41 @@ instances_iterator_cb (void *cls,
* each instance's own data
*
* @param config configuration handle
+ * @param allowed which wire format is allowed/expected?
* @return GNUNET_OK if successful, GNUNET_SYSERR upon errors
* (for example, if no "defaul" instance is defined)
*/
-static void
-iterate_instances (const struct GNUNET_CONFIGURATION_Handle *config)
+static unsigned int
+iterate_instances (const struct GNUNET_CONFIGURATION_Handle *config,
+ const char *allowed)
{
+ struct IterateInstancesCls *iic;
+ char *lib_name;
+
+ (void) GNUNET_asprintf (&lib_name,
+ "libtaler_plugin_wire_%s",
+ allowed);
+ iic = GNUNET_new (struct IterateInstancesCls);
+ iic->config = config;
+ iic->default_instance = GNUNET_NO;
+ iic->plugin = GNUNET_PLUGIN_load (lib_name,
+ NULL);
+ iic->plugin->library_name = lib_name;
+ if (NULL == iic->plugin)
+ {
+ GNUNET_free (lib_name);
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Wire transfer method `%s' not supported\n",
+ allowed);
+ return GNUNET_SYSERR;
+ }
GNUNET_CONFIGURATION_iterate_sections (config,
&instances_iterator_cb,
- (void *) config);
+ (void *) iic);
+ GNUNET_free (lib_name);
+ GNUNET_free (iic);
+ return GNUNET_OK;
}
@@ -622,7 +651,6 @@ run (void *cls,
GNUNET_SCHEDULER_shutdown ();
return;
}
- GNUNET_free (wireformat);
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_filename (config,
@@ -655,11 +683,11 @@ run (void *cls,
/** per instance end **/
/** debug per instance iterator start **/
- iterate_instances (config);
+ iterate_instances (config, wireformat);
GNUNET_SCHEDULER_shutdown ();
return;
/** debug per instance iterator end **/
-
+ GNUNET_free (wireformat);
if (NULL ==
(db = TALER_MERCHANTDB_plugin_load (config)))
{
diff --git a/src/backend/taler-merchant-httpd.h b/src/backend/taler-merchant-httpd.h
@@ -34,6 +34,29 @@
} while (0)
/**
+ * Used by the iterator of the various merchant's instances given
+ * in configuration
+ */
+struct IterateInstancesCls {
+
+ /**
+ * Handle for the configuration beig parsed
+ */
+ const struct GNUNET_CONFIGURATION_Handle *config;
+
+ /**
+ * Flag indicating whether config contains a default instance
+ */
+ unsigned int default_instance;
+
+ /**
+ * Wire plugin
+ */
+ struct TALER_WIRE_Plugin *plugin;
+};
+
+
+/**
* Information that defines a merchant "instance". That way, a single
* backend can account for several merchants, as used to do in donation
* shops
@@ -41,6 +64,11 @@
struct MerchantInstance {
/**
+ * Instance's mnemonic identifier
+ */
+ char *id;
+
+ /**
* File holding the merchant's private key
*/
char *keyfile;