modify GNUNET_PQ_connect_with_cfg to enable flexible loading of .sql files
authorChristian Grothoff <christian@grothoff.org>
Fri, 24 Jan 2020 15:30:45 +0000 (16:30 +0100)
committerChristian Grothoff <christian@grothoff.org>
Fri, 24 Jan 2020 15:30:45 +0000 (16:30 +0100)
contrib/build-common
src/datacache/plugin_datacache_postgres.c
src/datastore/plugin_datastore_postgres.c
src/include/gnunet_pq_lib.h
src/namecache/plugin_namecache_postgres.c
src/namestore/plugin_namestore_postgres.c
src/pq/pq_connect.c

index 1915a74bbb4cd2ae9bc541a382dfebc37064a2fd..d81bbfabc2538932f631d3946bd6a9b95182b4f2 160000 (submodule)
@@ -1 +1 @@
-Subproject commit 1915a74bbb4cd2ae9bc541a382dfebc37064a2fd
+Subproject commit d81bbfabc2538932f631d3946bd6a9b95182b4f2
index 09049fde21f2722004a09d5a1517aab6f0c9a743..c21be92194487fd74b7c4d884a217cb7f355b88f 100644 (file)
@@ -123,6 +123,7 @@ init_connection (struct Plugin *plugin)
 
   plugin->dbh = GNUNET_PQ_connect_with_cfg (plugin->env->cfg,
                                             "datacache-postgres",
+                                            NULL,
                                             es,
                                             ps);
   if (NULL == plugin->dbh)
index eba71722689209b02e008ad30d986f7ff0555d60..88ceb1b0aca8c54cbbc068bbf3e94a85e28b793c 100644 (file)
@@ -172,6 +172,7 @@ init_connection (struct Plugin *plugin)
 
   plugin->dbh = GNUNET_PQ_connect_with_cfg (plugin->env->cfg,
                                             "datastore-postgres",
+                                            NULL,
                                             es,
                                             ps);
   if (NULL == plugin->dbh)
index 8b32a9265490b604f9ae6b5736a2b51c1efb9ef1..53d2549c2978040e4299e29bc83df0a190edccf1 100644 (file)
@@ -742,8 +742,12 @@ GNUNET_PQ_connect (const char *config_str,
  * statements in @a es are executed whenever we (re)connect to the
  * database, and that the prepared statements in @a ps are "ready".
  *
+ * The caller does not have to ensure that @a es and @a ps remain allocated
+ * and initialized in memory until #GNUNET_PQ_disconnect() is called, as a copy will be made.
+ *
  * @param cfg configuration
  * @param section configuration section to use to get Postgres configuration options
+ * @param load_path_suffix suffix to append to the SQL_DIR in the configuration
  * @param es #GNUNET_PQ_PREPARED_STATEMENT_END-terminated
  *            array of statements to execute upon EACH connection, can be NULL
  * @param ps array of prepared statements to prepare, can be NULL
@@ -752,6 +756,7 @@ GNUNET_PQ_connect (const char *config_str,
 struct GNUNET_PQ_Context *
 GNUNET_PQ_connect_with_cfg (const struct GNUNET_CONFIGURATION_Handle *cfg,
                             const char *section,
+                            const char *load_path,
                             const struct GNUNET_PQ_ExecuteStatement *es,
                             const struct GNUNET_PQ_PreparedStatement *ps);
 
index f4a114e226c40ab2f7c4358595b43f07a7bcd73d..0e947e9c577557d6b27c0e4b5784aad50f4d8e69 100644 (file)
@@ -113,6 +113,7 @@ database_setup (struct Plugin *plugin)
 
     plugin->dbh = GNUNET_PQ_connect_with_cfg (plugin->cfg,
                                               "namecache-postgres",
+                                              NULL,
                                               es,
                                               ps);
   }
index d0fc33fe91d3742413b2112ae7d6f6b2bcdb6b5b..01dddde9e05d9aa1e6f538f9934cf96cefc67b59 100644 (file)
@@ -158,6 +158,7 @@ database_setup (struct Plugin *plugin)
 
     plugin->dbh = GNUNET_PQ_connect_with_cfg (plugin->cfg,
                                               "namestore-postgres",
+                                              NULL,
                                               es,
                                               ps);
   }
index 1ef2da7625a94848420be63050dbfce49cd03c44..7cd7d8787b5120deb3a47fb0c1beb46d87cd82d9 100644 (file)
@@ -267,12 +267,12 @@ GNUNET_PQ_reconnect (struct GNUNET_PQ_Context *db)
  * statements in @a es are executed whenever we (re)connect to the
  * database, and that the prepared statements in @a ps are "ready".
  *
- * The caller MUST ensure that @a es and @a ps remain allocated and
- * initialized in memory until #GNUNET_PQ_disconnect() is called,
- * as they may be needed repeatedly and no copy will be made.
+ * The caller does not have to ensure that @a es and @a ps remain allocated
+ * and initialized in memory until #GNUNET_PQ_disconnect() is called, as a copy will be made.
  *
  * @param cfg configuration
  * @param section configuration section to use to get Postgres configuration options
+ * @param load_path_suffix suffix to append to the SQL_DIR in the configuration
  * @param es #GNUNET_PQ_PREPARED_STATEMENT_END-terminated
  *            array of statements to execute upon EACH connection, can be NULL
  * @param ps array of prepared statements to prepare, can be NULL
@@ -281,12 +281,14 @@ GNUNET_PQ_reconnect (struct GNUNET_PQ_Context *db)
 struct GNUNET_PQ_Context *
 GNUNET_PQ_connect_with_cfg (const struct GNUNET_CONFIGURATION_Handle *cfg,
                             const char *section,
+                            const char *load_path_suffix,
                             const struct GNUNET_PQ_ExecuteStatement *es,
                             const struct GNUNET_PQ_PreparedStatement *ps)
 {
   struct GNUNET_PQ_Context *db;
   char *conninfo;
   char *load_path;
+  char *sp;
 
   if (GNUNET_OK !=
       GNUNET_CONFIGURATION_get_value_string (cfg,
@@ -294,17 +296,23 @@ GNUNET_PQ_connect_with_cfg (const struct GNUNET_CONFIGURATION_Handle *cfg,
                                              "CONFIG",
                                              &conninfo))
     conninfo = NULL;
-  if (GNUNET_OK !=
-      GNUNET_CONFIGURATION_get_value_string (cfg,
-                                             section,
-                                             "SQL_PATH",
-                                             &load_path))
-    load_path = NULL;
+  load_path = NULL;
+  sp = NULL;
+  if (GNUNET_OK ==
+      GNUNET_CONFIGURATION_get_value_filename (cfg,
+                                               section,
+                                               "SQL_DIR",
+                                               &sp))
+    GNUNET_asprintf (&load_path,
+                     "%s%s",
+                     sp,
+                     load_path_suffix);
   db = GNUNET_PQ_connect (conninfo == NULL ? "" : conninfo,
                           load_path,
                           es,
                           ps);
   GNUNET_free_non_null (load_path);
+  GNUNET_free_non_null (sp);
   GNUNET_free_non_null (conninfo);
   return db;
 }