summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSree Harsha Totakura <sreeharsha@totakura.in>2015-03-26 18:06:37 +0100
committerSree Harsha Totakura <sreeharsha@totakura.in>2015-03-26 18:06:37 +0100
commitf94bb0a3a076caab71597b32963fd2815b8446f9 (patch)
treec9a08e071a446f6a4b8b10149f9cbaef567d69cc
parenta3ac2587cfee3c8b6e058d4086eea8f5f297e5af (diff)
downloadexchange-f94bb0a3a076caab71597b32963fd2815b8446f9.tar.gz
exchange-f94bb0a3a076caab71597b32963fd2815b8446f9.tar.bz2
exchange-f94bb0a3a076caab71597b32963fd2815b8446f9.zip
db: Implement plugin loading and unloading
-rw-r--r--src/mint/plugin.c31
-rw-r--r--src/mint/plugin_mintdb_postgres.c5
-rw-r--r--src/mint/taler_mintdb_plugin.h5
-rw-r--r--src/mint/test_mint_db.c1
4 files changed, 39 insertions, 3 deletions
diff --git a/src/mint/plugin.c b/src/mint/plugin.c
index 4fb75f87..455c7e8f 100644
--- a/src/mint/plugin.c
+++ b/src/mint/plugin.c
@@ -43,7 +43,34 @@ static char *old_dlsearchpath;
int
TALER_MINT_plugin_load (const struct GNUNET_CONFIGURATION_Handle *cfg)
{
- return GNUNET_SYSERR;
+ char *plugin_name;
+ char *lib_name;
+ struct GNUNET_CONFIGURATION_Handle *cfg_dup;
+
+ if (NULL != plugin)
+ return GNUNET_OK;
+ if (GNUNET_SYSERR ==
+ GNUNET_CONFIGURATION_get_value_string (cfg,
+ "mint",
+ "db",
+ &plugin_name))
+ {
+ GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
+ "mint",
+ "db");
+ return GNUNET_SYSERR;
+ }
+ (void) GNUNET_asprintf (&lib_name,
+ "libtaler_plugin_mintdb_%s",
+ plugin_name);
+ GNUNET_free (plugin_name);
+ cfg_dup = GNUNET_CONFIGURATION_dup (cfg);
+ plugin = GNUNET_PLUGIN_load (lib_name, cfg_dup);
+ GNUNET_CONFIGURATION_destroy (cfg_dup);
+ GNUNET_free (lib_name);
+ if (NULL == plugin)
+ return GNUNET_SYSERR;
+ return GNUNET_OK;
}
@@ -55,6 +82,8 @@ TALER_MINT_plugin_unload ()
{
if (NULL == plugin)
return;
+ GNUNET_assert (NULL == GNUNET_PLUGIN_unload (plugin->library_name,
+ plugin));
}
diff --git a/src/mint/plugin_mintdb_postgres.c b/src/mint/plugin_mintdb_postgres.c
index 5a1ff8c0..8edee59a 100644
--- a/src/mint/plugin_mintdb_postgres.c
+++ b/src/mint/plugin_mintdb_postgres.c
@@ -2289,16 +2289,17 @@ libtaler_plugin_mintdb_postgres_init (void *cls)
/* FIXME: use configuration section with "postgres" in its name... */
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_string (cfg,
- "mint", "db",
+ "mint", "db_conn_str",
&pg->TALER_MINT_db_connection_cfg_str))
{
GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
"mint",
- "db");
+ "db_conn_str");
return NULL;
}
plugin = GNUNET_new (struct TALER_MINTDB_Plugin);
plugin->cls = pg;
+ plugin->library_name = "libtaler_plugin_mintdb_postgres";
plugin->get_session = &postgres_get_session;
plugin->drop_temporary = &postgres_drop_temporary;
plugin->create_tables = &postgres_create_tables;
diff --git a/src/mint/taler_mintdb_plugin.h b/src/mint/taler_mintdb_plugin.h
index 08a73479..4d74b88d 100644
--- a/src/mint/taler_mintdb_plugin.h
+++ b/src/mint/taler_mintdb_plugin.h
@@ -479,6 +479,11 @@ struct TALER_MINTDB_Plugin
void *cls;
/**
+ * Name of the library which generated this plugin
+ */
+ const char *library_name;
+
+ /**
* Get the thread-local database-handle.
* Connect to the db if the connection does not exist yet.
*
diff --git a/src/mint/test_mint_db.c b/src/mint/test_mint_db.c
index 0b61818f..ef882b90 100644
--- a/src/mint/test_mint_db.c
+++ b/src/mint/test_mint_db.c
@@ -343,6 +343,7 @@ run (void *cls,
if (NULL != cbc2.sig.rsa_signature)
GNUNET_CRYPTO_rsa_signature_free (cbc2.sig.rsa_signature);
dkp = NULL;
+ TALER_MINT_plugin_unload ();
}