From cdaf1ce69b5fb56f09bbdc00942b03f039710614 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sun, 9 Feb 2020 16:34:40 +0100 Subject: [PATCH] rename SQL files to make filenames consistent with versioning name --- src/auditordb/Makefile.am | 4 +- src/auditordb/{0000.sql => auditor-0000.sql} | 0 src/auditordb/{0001.sql => auditor-0001.sql} | 0 src/auditordb/plugin_auditordb_postgres.c | 91 +++++-------------- src/exchangedb/Makefile.am | 4 +- .../{0000.sql => exchange-0000.sql} | 0 .../{0001.sql => exchange-0001.sql} | 0 src/exchangedb/plugin_exchangedb_postgres.c | 66 ++++---------- 8 files changed, 43 insertions(+), 122 deletions(-) rename src/auditordb/{0000.sql => auditor-0000.sql} (100%) rename src/auditordb/{0001.sql => auditor-0001.sql} (100%) rename src/exchangedb/{0000.sql => exchange-0000.sql} (100%) rename src/exchangedb/{0001.sql => exchange-0001.sql} (100%) diff --git a/src/auditordb/Makefile.am b/src/auditordb/Makefile.am index 1378c5496..3efdc200e 100644 --- a/src/auditordb/Makefile.am +++ b/src/auditordb/Makefile.am @@ -14,8 +14,8 @@ pkgcfg_DATA = \ sqldir = $(prefix)/share/taler/sql/auditor/ sql_DATA = \ - 0000.sql \ - 0001.sql \ + auditor-0000.sql \ + auditor-0001.sql \ drop0000.sql \ restart0000.sql diff --git a/src/auditordb/0000.sql b/src/auditordb/auditor-0000.sql similarity index 100% rename from src/auditordb/0000.sql rename to src/auditordb/auditor-0000.sql diff --git a/src/auditordb/0001.sql b/src/auditordb/auditor-0001.sql similarity index 100% rename from src/auditordb/0001.sql rename to src/auditordb/auditor-0001.sql diff --git a/src/auditordb/plugin_auditordb_postgres.c b/src/auditordb/plugin_auditordb_postgres.c index 08d24fd7f..ca07d406b 100644 --- a/src/auditordb/plugin_auditordb_postgres.c +++ b/src/auditordb/plugin_auditordb_postgres.c @@ -80,15 +80,9 @@ struct PostgresClosure pthread_key_t db_conn_threadlocal; /** - * Directory with SQL statements to run to create tables. + * Our configuration. */ - char *sql_dir; - - /** - * Database connection string, as read from - * the configuration. - */ - char *connection_cfg_str; + const struct GNUNET_CONFIGURATION_Handle *cfg; /** * Which currency should we assume all amounts to be in? @@ -114,16 +108,12 @@ postgres_drop_tables (void *cls, { struct PostgresClosure *pc = cls; struct GNUNET_PQ_Context *conn; - char *exec_dir; - GNUNET_asprintf (&exec_dir, - (drop_exchangelist) ? "%sdrop" : "%srestart", - pc->sql_dir); - conn = GNUNET_PQ_connect (pc->connection_cfg_str, - exec_dir, - NULL, - NULL); - GNUNET_free (exec_dir); + conn = GNUNET_PQ_connect_with_cfg (pc->cfg, + "auditordb-postgres", + (drop_exchangelist) ? "drop" : "restart", + NULL, + NULL); if (NULL == conn) return GNUNET_SYSERR; GNUNET_PQ_disconnect (conn); @@ -143,10 +133,11 @@ postgres_create_tables (void *cls) struct PostgresClosure *pc = cls; struct GNUNET_PQ_Context *conn; - conn = GNUNET_PQ_connect (pc->connection_cfg_str, - pc->sql_dir, - NULL, - NULL); + conn = GNUNET_PQ_connect_with_cfg (pc->cfg, + "auditordb-postgres", + "auditor-", + NULL, + NULL); if (NULL == conn) return GNUNET_SYSERR; GNUNET_PQ_disconnect (conn); @@ -734,10 +725,11 @@ postgres_get_session (void *cls) GNUNET_PQ_reconnect_if_down (session->conn); return session; } - db_conn = GNUNET_PQ_connect (pc->connection_cfg_str, - NULL, - NULL, - ps); + db_conn = GNUNET_PQ_connect_with_cfg (pc->cfg, + "auditordb-postgres", + NULL, + NULL, + ps); if (NULL == db_conn) return NULL; session = GNUNET_new (struct TALER_AUDITORDB_Session); @@ -897,10 +889,11 @@ postgres_gc (void *cls) }; now = GNUNET_TIME_absolute_get (); - conn = GNUNET_PQ_connect (pc->connection_cfg_str, - NULL, - NULL, - ps); + conn = GNUNET_PQ_connect_with_cfg (pc->cfg, + "auditordb-postgres", + NULL, + NULL, + ps); if (NULL == conn) return GNUNET_SYSERR; GNUNET_log (GNUNET_ERROR_TYPE_ERROR, @@ -3247,50 +3240,16 @@ libtaler_plugin_auditordb_postgres_init (void *cls) const struct GNUNET_CONFIGURATION_Handle *cfg = cls; struct PostgresClosure *pg; struct TALER_AUDITORDB_Plugin *plugin; - const char *ec; pg = GNUNET_new (struct PostgresClosure); - if (GNUNET_OK != - GNUNET_CONFIGURATION_get_value_filename (cfg, - "auditordb-postgres", - "SQL_DIR", - &pg->sql_dir)) - { - GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, - "auditordb-postgres", - "SQL_DIR"); - GNUNET_free (pg); - return NULL; - } + pg->cfg = cfg; if (0 != pthread_key_create (&pg->db_conn_threadlocal, &db_conn_destroy)) { TALER_LOG_ERROR ("Cannnot create pthread key.\n"); - GNUNET_free (pg->sql_dir); GNUNET_free (pg); return NULL; } - ec = getenv ("TALER_AUDITORDB_POSTGRES_CONFIG"); - if (NULL != ec) - { - pg->connection_cfg_str = GNUNET_strdup (ec); - } - else - { - if (GNUNET_OK != - GNUNET_CONFIGURATION_get_value_string (cfg, - "auditordb-postgres", - "CONFIG", - &pg->connection_cfg_str)) - { - GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, - "auditordb-postgres", - "CONFIG"); - GNUNET_free (pg->sql_dir); - GNUNET_free (pg); - return NULL; - } - } if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg, "taler", @@ -3300,8 +3259,6 @@ libtaler_plugin_auditordb_postgres_init (void *cls) GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, "taler", "CURRENCY"); - GNUNET_free (pg->connection_cfg_str); - GNUNET_free (pg->sql_dir); GNUNET_free (pg); return NULL; } @@ -3407,8 +3364,6 @@ libtaler_plugin_auditordb_postgres_done (void *cls) struct TALER_AUDITORDB_Plugin *plugin = cls; struct PostgresClosure *pg = plugin->cls; - GNUNET_free (pg->connection_cfg_str); - GNUNET_free (pg->sql_dir); GNUNET_free (pg->currency); GNUNET_free (pg); GNUNET_free (plugin); diff --git a/src/exchangedb/Makefile.am b/src/exchangedb/Makefile.am index e7ac4d719..37809f6b4 100644 --- a/src/exchangedb/Makefile.am +++ b/src/exchangedb/Makefile.am @@ -15,8 +15,8 @@ pkgcfg_DATA = \ sqldir = $(prefix)/share/taler/sql/exchange/ sql_DATA = \ - 0000.sql \ - 0001.sql \ + exchange-0000.sql \ + exchange-0001.sql \ drop0000.sql EXTRA_DIST = \ diff --git a/src/exchangedb/0000.sql b/src/exchangedb/exchange-0000.sql similarity index 100% rename from src/exchangedb/0000.sql rename to src/exchangedb/exchange-0000.sql diff --git a/src/exchangedb/0001.sql b/src/exchangedb/exchange-0001.sql similarity index 100% rename from src/exchangedb/0001.sql rename to src/exchangedb/exchange-0001.sql diff --git a/src/exchangedb/plugin_exchangedb_postgres.c b/src/exchangedb/plugin_exchangedb_postgres.c index fe0021fa6..9df2fe770 100644 --- a/src/exchangedb/plugin_exchangedb_postgres.c +++ b/src/exchangedb/plugin_exchangedb_postgres.c @@ -113,12 +113,6 @@ struct PostgresClosure */ const struct GNUNET_CONFIGURATION_Handle *cfg; - /** - * Database connection string, as read from - * the configuration. - */ - char *connection_cfg_str; - /** * Directory with SQL statements to run to create tables. */ @@ -163,16 +157,12 @@ postgres_drop_tables (void *cls) { struct PostgresClosure *pc = cls; struct GNUNET_PQ_Context *conn; - char *drop_dir; - GNUNET_asprintf (&drop_dir, - "%sdrop", - pc->sql_dir); - conn = GNUNET_PQ_connect (pc->connection_cfg_str, - drop_dir, - NULL, - NULL); - GNUNET_free (drop_dir); + conn = GNUNET_PQ_connect_with_cfg (pc->cfg, + "exchangedb-postgres", + "drop", + NULL, + NULL); if (NULL == conn) return GNUNET_SYSERR; GNUNET_PQ_disconnect (conn); @@ -194,7 +184,7 @@ postgres_create_tables (void *cls) conn = GNUNET_PQ_connect_with_cfg (pc->cfg, "exchangedb-postgres", - "", + "exchange-", NULL, NULL); if (NULL == conn) @@ -1393,10 +1383,11 @@ postgres_get_session (void *cls) GNUNET_PQ_PREPARED_STATEMENT_END }; - db_conn = GNUNET_PQ_connect (pc->connection_cfg_str, - NULL, - es, - ps); + db_conn = GNUNET_PQ_connect_with_cfg (pc->cfg, + "exchangedb-postgres", + NULL, + es, + ps); } if (NULL == db_conn) return NULL; @@ -5377,10 +5368,11 @@ postgres_gc (void *cls) GNUNET_PQ_PREPARED_STATEMENT_END }; - conn = GNUNET_PQ_connect (pg->connection_cfg_str, - NULL, - NULL, - ps); + conn = GNUNET_PQ_connect_with_cfg (pg->cfg, + "exchangedb-postgres", + NULL, + NULL, + ps); } if (NULL == conn) return GNUNET_SYSERR; @@ -7221,7 +7213,6 @@ libtaler_plugin_exchangedb_postgres_init (void *cls) const struct GNUNET_CONFIGURATION_Handle *cfg = cls; struct PostgresClosure *pg; struct TALER_EXCHANGEDB_Plugin *plugin; - const char *ec; pg = GNUNET_new (struct PostgresClosure); pg->cfg = cfg; @@ -7246,28 +7237,6 @@ libtaler_plugin_exchangedb_postgres_init (void *cls) GNUNET_free (pg); return NULL; } - ec = getenv ("TALER_EXCHANGEDB_POSTGRES_CONFIG"); - if (NULL != ec) - { - pg->connection_cfg_str = GNUNET_strdup (ec); - } - else - { - if (GNUNET_OK != - GNUNET_CONFIGURATION_get_value_string (cfg, - "exchangedb-postgres", - "CONFIG", - &pg->connection_cfg_str)) - { - GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, - "exchangedb-postgres", - "CONFIG"); - GNUNET_free (pg->sql_dir); - GNUNET_free (pg); - return NULL; - } - } - if ( (GNUNET_OK != GNUNET_CONFIGURATION_get_value_time (cfg, "exchangedb", @@ -7283,7 +7252,6 @@ libtaler_plugin_exchangedb_postgres_init (void *cls) GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, "exchangedb", "LEGAL/IDLE_RESERVE_EXPIRATION_TIME"); - GNUNET_free (pg->connection_cfg_str); GNUNET_free (pg->sql_dir); GNUNET_free (pg); return NULL; @@ -7297,7 +7265,6 @@ libtaler_plugin_exchangedb_postgres_init (void *cls) GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, "taler", "CURRENCY"); - GNUNET_free (pg->connection_cfg_str); GNUNET_free (pg->sql_dir); GNUNET_free (pg); return NULL; @@ -7413,7 +7380,6 @@ libtaler_plugin_exchangedb_postgres_done (void *cls) /* If we launched a session for the main thread, kill it here before we unload */ db_conn_destroy (pg->main_session); - GNUNET_free (pg->connection_cfg_str); GNUNET_free (pg->sql_dir); GNUNET_free (pg->currency); GNUNET_free (pg);