summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2021-09-01 00:59:34 +0200
committerChristian Grothoff <christian@grothoff.org>2021-09-01 00:59:34 +0200
commitc3a1a4ecbea0c8df729b7a29da5d31c1f9dab9c9 (patch)
tree9fee7ded48451ba9e25b06b355c76078e291cef5
parent79de1f2faddd1032fa0f915365be6d85ea333fb3 (diff)
downloadanastasis-c3a1a4ecbea0c8df729b7a29da5d31c1f9dab9c9.tar.gz
anastasis-c3a1a4ecbea0c8df729b7a29da5d31c1f9dab9c9.tar.bz2
anastasis-c3a1a4ecbea0c8df729b7a29da5d31c1f9dab9c9.zip
separate DB creation from plugin loading; fix misc. Debian package issues
-rw-r--r--debian/anastasis-httpd.postinst6
-rwxr-xr-xdebian/db/install/pgsql2
-rw-r--r--debian/etc/anastasis/anastasis.conf21
-rwxr-xr-xdebian/rules2
-rw-r--r--doc/sphinx/manpages/anastasis.conf.5.rst3
-rw-r--r--src/authorization/anastasis-helper-authorization-iban.c10
-rw-r--r--src/backend/anastasis-httpd.c8
-rw-r--r--src/include/anastasis_database_plugin.h22
-rw-r--r--src/stasis/anastasis-dbinit.c8
-rw-r--r--src/stasis/plugin_anastasis_postgres.c788
-rw-r--r--src/stasis/test_anastasis_db.c10
11 files changed, 495 insertions, 385 deletions
diff --git a/debian/anastasis-httpd.postinst b/debian/anastasis-httpd.postinst
index fe89acb..994b06b 100644
--- a/debian/anastasis-httpd.postinst
+++ b/debian/anastasis-httpd.postinst
@@ -20,6 +20,12 @@ configure)
adduser --quiet --system --ingroup ${_GROUPNAME} --no-create-home --home ${TALER_HOME} ${_USERNAME}
fi
+ if ! dpkg-statoverride --list /etc/anastasis/secrets/anastasis-db.secret.conf >/dev/null 2>&1; then
+ dpkg-statoverride --add --update \
+ anastasis-httpd root 460 \
+ /etc/anastasis/secrets/anastasis-db.secret.conf
+ fi
+
# Setup postgres database (needs dbconfig-pgsql package)
if [ -f /usr/share/dbconfig-common/dpkg/postinst.pgsql ]; then
. /usr/share/dbconfig-common/dpkg/postinst.pgsql
diff --git a/debian/db/install/pgsql b/debian/db/install/pgsql
index dab5d1e..f695fed 100755
--- a/debian/db/install/pgsql
+++ b/debian/db/install/pgsql
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!/bin/bash
set -eu
diff --git a/debian/etc/anastasis/anastasis.conf b/debian/etc/anastasis/anastasis.conf
index e662a43..4d0deda 100644
--- a/debian/etc/anastasis/anastasis.conf
+++ b/debian/etc/anastasis/anastasis.conf
@@ -1,5 +1,26 @@
[anastasis]
DATABASE = postgres
+SERVE = unix
+
+# You must set each of the following options
+# before starting anastasis-httpd!
+#
+# Storage fee for policies (per year)
+#ANNUAL_FEE = KUDOS:0
+#
+# Storage fee for truth
+#TRUTH_UPLOAD_FEE = KUDOS:0
+
+# Name of your business
+#BUSINESS_NAME = ""
+
+# Random server salt. Use output of 'uuidgen'
+#SERVER_SALT = ""
+
+# How high is the per key share insurance offered
+# by your business?
+#INSURANCE = KUDOS:0
+
[taler]
# Currency accepted by anastasis via GNU Taler payments.
diff --git a/debian/rules b/debian/rules
index e3c7db5..cfd43c7 100755
--- a/debian/rules
+++ b/debian/rules
@@ -34,7 +34,7 @@ override_dh_install:
dh_install
# Done manually for debhelper-compat<13
dh_installtmpfiles
-# Remove files already present in libtalerexchange from main taler-exchange package
+# Remove files already present in libanastasis-dev/cli from anastasis-httpd/libanastasis packages
cd debian/libanastasis-dev; find . -type f,l -exec rm -f ../anastasis-httpd/{} \;
cd debian/anastasis-cli; find . -type f -exec rm -f ../anastasis-httpd/{} \;
cd debian/libanastasis-dev; find . -type f,l -exec rm -f ../libanastasis/{} \;
diff --git a/doc/sphinx/manpages/anastasis.conf.5.rst b/doc/sphinx/manpages/anastasis.conf.5.rst
index 1f6b49e..000d8f0 100644
--- a/doc/sphinx/manpages/anastasis.conf.5.rst
+++ b/doc/sphinx/manpages/anastasis.conf.5.rst
@@ -67,6 +67,9 @@ ANNUAL_FEE
TRUTH_UPLOAD_FEE
Annual fee to be paid for truth uploads, i.e. "EUR:1.5".
+INSURANCE
+ Amount up to which key shares are warranted, i.e. "EUR:1000000".
+
DB
Database backend to use, only ``postgres`` is supported right now.
diff --git a/src/authorization/anastasis-helper-authorization-iban.c b/src/authorization/anastasis-helper-authorization-iban.c
index 04dfa03..c6e5335 100644
--- a/src/authorization/anastasis-helper-authorization-iban.c
+++ b/src/authorization/anastasis-helper-authorization-iban.c
@@ -390,6 +390,16 @@ run (void *cls,
return;
}
if (GNUNET_OK !=
+ db_plugin->connect (db_plugin->cls))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Database not set up. Did you run anastasis-dbinit?\n");
+ global_ret = EXIT_NOTCONFIGURED;
+ ANASTASIS_DB_plugin_unload (db_plugin);
+ db_plugin = NULL;
+ return;
+ }
+ if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_string (cfg,
"authorization-iban",
"CREDIT_IBAN",
diff --git a/src/backend/anastasis-httpd.c b/src/backend/anastasis-httpd.c
index fdf17ff..9f5c87b 100644
--- a/src/backend/anastasis-httpd.c
+++ b/src/backend/anastasis-httpd.c
@@ -888,6 +888,14 @@ run (void *cls,
GNUNET_SCHEDULER_shutdown ();
return;
}
+ if (GNUNET_OK !=
+ db->connect (db->cls))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Database not setup. Did you run anastasis-dbinit?\n");
+ GNUNET_SCHEDULER_shutdown ();
+ return;
+ }
fh = TALER_MHD_bind (config,
"anastasis",
diff --git a/src/include/anastasis_database_plugin.h b/src/include/anastasis_database_plugin.h
index 565ad69..bc4b0e6 100644
--- a/src/include/anastasis_database_plugin.h
+++ b/src/include/anastasis_database_plugin.h
@@ -187,8 +187,26 @@ struct ANASTASIS_DatabasePlugin
* @param cls closure
* @return #GNUNET_OK upon success; #GNUNET_SYSERR upon failure
*/
- int
- (*drop_tables) (void *cls);
+ enum GNUNET_GenericReturnValue
+ (*drop_tables)(void *cls);
+
+ /**
+ * Connect to the database.
+ *
+ * @param cls closure
+ * @return #GNUNET_OK upon success; #GNUNET_SYSERR upon failure
+ */
+ enum GNUNET_GenericReturnValue
+ (*connect)(void *cls);
+
+ /**
+ * Initialize merchant tables
+ *
+ * @param cls closure
+ * @return #GNUNET_OK upon success; #GNUNET_SYSERR upon failure
+ */
+ enum GNUNET_GenericReturnValue
+ (*create_tables)(void *cls);
/**
* Function called to perform "garbage collection" on the
diff --git a/src/stasis/anastasis-dbinit.c b/src/stasis/anastasis-dbinit.c
index 038fb7c..17b3c56 100644
--- a/src/stasis/anastasis-dbinit.c
+++ b/src/stasis/anastasis-dbinit.c
@@ -54,7 +54,7 @@ run (void *cls,
{
fprintf (stderr,
"Failed to initialize database plugin.\n");
- global_ret = 1;
+ global_ret = EXIT_FAILURE;
return;
}
if (reset_db)
@@ -63,6 +63,12 @@ run (void *cls,
ANASTASIS_DB_plugin_unload (plugin);
plugin = ANASTASIS_DB_plugin_load (cfg);
}
+ if (GNUNET_OK !=
+ plugin->create_tables (plugin->cls))
+ {
+ global_ret = EXIT_FAILURE;
+ return;
+ }
ANASTASIS_DB_plugin_unload (plugin);
}
diff --git a/src/stasis/plugin_anastasis_postgres.c b/src/stasis/plugin_anastasis_postgres.c
index 8ee16ad..b78dbdb 100644
--- a/src/stasis/plugin_anastasis_postgres.c
+++ b/src/stasis/plugin_anastasis_postgres.c
@@ -81,7 +81,7 @@ struct PostgresClosure
* @param cls closure our `struct Plugin`
* @return #GNUNET_OK upon success; #GNUNET_SYSERR upon failure
*/
-static int
+static enum GNUNET_GenericReturnValue
postgres_drop_tables (void *cls)
{
struct PostgresClosure *pg = cls;
@@ -100,6 +100,416 @@ postgres_drop_tables (void *cls)
/**
+ * Initialize tables.
+ *
+ * @param cls the `struct PostgresClosure` with the plugin-specific state
+ * @return #GNUNET_OK upon success; #GNUNET_SYSERR upon failure
+ */
+static enum GNUNET_GenericReturnValue
+postgres_create_tables (void *cls)
+{
+ struct PostgresClosure *pc = cls;
+ struct GNUNET_PQ_Context *conn;
+
+ conn = GNUNET_PQ_connect_with_cfg (pc->cfg,
+ "stasis-postgres",
+ "stasis-",
+ NULL,
+ NULL);
+ if (NULL == conn)
+ return GNUNET_SYSERR;
+ GNUNET_PQ_disconnect (conn);
+ return GNUNET_OK;
+}
+
+
+/**
+ * Establish connection to the database.
+ *
+ * @param cls plugin context
+ * @return #GNUNET_OK upon success; #GNUNET_SYSERR upon failure
+ */
+static enum GNUNET_GenericReturnValue
+postgres_connect (void *cls)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_PreparedStatement ps[] = {
+ GNUNET_PQ_make_prepare ("user_insert",
+ "INSERT INTO anastasis_user "
+ "(user_id"
+ ",expiration_date"
+ ") VALUES "
+ "($1, $2);",
+ 2),
+ GNUNET_PQ_make_prepare ("do_commit",
+ "COMMIT",
+ 0),
+ GNUNET_PQ_make_prepare ("user_select",
+ "SELECT"
+ " expiration_date "
+ "FROM anastasis_user"
+ " WHERE user_id=$1"
+ " FOR UPDATE;",
+ 1),
+ GNUNET_PQ_make_prepare ("user_update",
+ "UPDATE anastasis_user"
+ " SET "
+ " expiration_date=$1"
+ " WHERE user_id=$2;",
+ 2),
+ GNUNET_PQ_make_prepare ("recdoc_payment_insert",
+ "INSERT INTO anastasis_recdoc_payment "
+ "(user_id"
+ ",post_counter"
+ ",amount_val"
+ ",amount_frac"
+ ",payment_identifier"
+ ",creation_date"
+ ") VALUES "
+ "($1, $2, $3, $4, $5, $6);",
+ 6),
+ GNUNET_PQ_make_prepare ("challenge_payment_insert",
+ "INSERT INTO anastasis_challenge_payment "
+ "(truth_uuid"
+ ",amount_val"
+ ",amount_frac"
+ ",payment_identifier"
+ ",creation_date"
+ ") VALUES "
+ "($1, $2, $3, $4, $5);",
+ 5),
+ GNUNET_PQ_make_prepare ("truth_payment_insert",
+ "INSERT INTO anastasis_truth_payment "
+ "(truth_uuid"
+ ",amount_val"
+ ",amount_frac"
+ ",expiration"
+ ") VALUES "
+ "($1, $2, $3, $4);",
+ 4),
+ GNUNET_PQ_make_prepare ("recdoc_payment_done",
+ "UPDATE anastasis_recdoc_payment "
+ "SET"
+ " paid=TRUE "
+ "WHERE"
+ " payment_identifier=$1"
+ " AND"
+ " user_id=$2"
+ " AND"
+ " paid=FALSE;",
+ 2),
+ GNUNET_PQ_make_prepare ("challenge_refund_update",
+ "UPDATE anastasis_challenge_payment "
+ "SET"
+ " refunded=TRUE "
+ "WHERE"
+ " payment_identifier=$1"
+ " AND"
+ " paid=TRUE"
+ " AND"
+ " truth_uuid=$2;",
+ 2),
+ GNUNET_PQ_make_prepare ("challenge_payment_done",
+ "UPDATE anastasis_challenge_payment "
+ "SET"
+ " paid=TRUE "
+ "WHERE"
+ " payment_identifier=$1"
+ " AND"
+ " refunded=FALSE"
+ " AND"
+ " truth_uuid=$2"
+ " AND"
+ " paid=FALSE;",
+ 2),
+ GNUNET_PQ_make_prepare ("recdoc_payment_select",
+ "SELECT"
+ " creation_date"
+ ",post_counter"
+ ",amount_val"
+ ",amount_frac"
+ ",paid"
+ " FROM anastasis_recdoc_payment"
+ " WHERE payment_identifier=$1;",
+ 1),
+ GNUNET_PQ_make_prepare ("truth_payment_select",
+ "SELECT"
+ " expiration"
+ " FROM anastasis_truth_payment"
+ " WHERE truth_uuid=$1"
+ " AND expiration>$2;",
+ 2),
+ GNUNET_PQ_make_prepare ("challenge_payment_select",
+ "SELECT"
+ " creation_date"
+ ",amount_val"
+ ",amount_frac"
+ ",paid"
+ " FROM anastasis_challenge_payment"
+ " WHERE payment_identifier=$1"
+ " AND truth_uuid=$2"
+ " AND refunded=FALSE"
+ " AND counter>0;",
+ 1),
+ GNUNET_PQ_make_prepare ("challenge_pending_payment_select",
+ "SELECT"
+ " creation_date"
+ ",payment_identifier"
+ ",amount_val"
+ ",amount_frac"
+ " FROM anastasis_challenge_payment"
+ " WHERE"
+ " paid=FALSE"
+ " AND"
+ " refunded=FALSE"
+ " AND"
+ " truth_uuid=$1"
+ " AND"
+ " creation_date > $2;",
+ 1),
+ GNUNET_PQ_make_prepare ("recdoc_payments_select",
+ "SELECT"
+ " user_id"
+ ",payment_identifier"
+ ",amount_val"
+ ",amount_frac"
+ " FROM anastasis_recdoc_payment"
+ " WHERE paid=FALSE;",
+ 0),
+ GNUNET_PQ_make_prepare ("gc_accounts",
+ "DELETE FROM anastasis_user "
+ "WHERE"
+ " expiration_date < $1;",
+ 1),
+ GNUNET_PQ_make_prepare ("gc_recdoc_pending_payments",
+ "DELETE FROM anastasis_recdoc_payment "
+ "WHERE"
+ " paid=FALSE"
+ " AND"
+ " creation_date < $1;",
+ 1),
+ GNUNET_PQ_make_prepare ("gc_challenge_pending_payments",
+ "DELETE FROM anastasis_challenge_payment "
+ "WHERE"
+ " (paid=FALSE"
+ " OR"
+ " refunded=TRUE)"
+ " AND"
+ " creation_date < $1;",
+ 1),
+ GNUNET_PQ_make_prepare ("truth_insert",
+ "INSERT INTO anastasis_truth "
+ "(truth_uuid"
+ ",key_share_data"
+ ",method_name"
+ ",encrypted_truth"
+ ",truth_mime"
+ ",expiration"
+ ") VALUES "
+ "($1, $2, $3, $4, $5, $6);",
+ 6),
+
+ GNUNET_PQ_make_prepare ("test_auth_iban_payment",
+ "SELECT"
+ " credit_val"
+ ",credit_frac"
+ ",wire_subject"
+ " FROM anastasis_auth_iban_in"
+ " WHERE debit_account_details=$1"
+ " AND execution_date>=$2;",
+ 2),
+ GNUNET_PQ_make_prepare ("store_auth_iban_payment_details",
+ "INSERT INTO anastasis_auth_iban_in "
+ "(wire_reference"
+ ",wire_subject"
+ ",credit_val"
+ ",credit_frac"
+ ",debit_account_details"
+ ",credit_account_details"
+ ",execution_date"
+ ") VALUES "
+ "($1, $2, $3, $4, $5, $6, $7);",
+ 7),
+
+
+ GNUNET_PQ_make_prepare ("recovery_document_insert",
+ "INSERT INTO anastasis_recoverydocument "
+ "(user_id"
+ ",version"
+ ",account_sig"
+ ",recovery_data_hash"
+ ",recovery_data"
+ ") VALUES "
+ "($1, $2, $3, $4, $5);",
+ 5),
+ GNUNET_PQ_make_prepare ("truth_select",
+ "SELECT "
+ " method_name"
+ ",encrypted_truth"
+ ",truth_mime"
+ " FROM anastasis_truth"
+ " WHERE truth_uuid =$1;",
+ 1),
+ GNUNET_PQ_make_prepare ("latest_recoverydocument_select",
+ "SELECT "
+ " version"
+ ",account_sig"
+ ",recovery_data_hash"
+ ",recovery_data"
+ " FROM anastasis_recoverydocument"
+ " WHERE user_id =$1 "
+ " ORDER BY version DESC"
+ " LIMIT 1;",
+ 1),
+ GNUNET_PQ_make_prepare ("latest_recovery_version_select",
+ "SELECT"
+ " version"
+ ",recovery_data_hash"
+ ",expiration_date"
+ " FROM anastasis_recoverydocument"
+ " JOIN anastasis_user USING (user_id)"
+ " WHERE user_id=$1"
+ " ORDER BY version DESC"
+ " LIMIT 1;",
+ 1),
+ GNUNET_PQ_make_prepare ("recoverydocument_select",
+ "SELECT "
+ " account_sig"
+ ",recovery_data_hash"
+ ",recovery_data"
+ " FROM anastasis_recoverydocument"
+ " WHERE user_id=$1"
+ " AND version=$2;",
+ 2),
+ GNUNET_PQ_make_prepare ("postcounter_select",
+ "SELECT"
+ " post_counter"
+ " FROM anastasis_recdoc_payment"
+ " WHERE user_id=$1"
+ " AND payment_identifier=$2;",
+ 2),
+ GNUNET_PQ_make_prepare ("postcounter_update",
+ "UPDATE "
+ "anastasis_recdoc_payment "
+ "SET "
+ "post_counter=$1 "
+ "WHERE user_id =$2 "
+ "AND payment_identifier=$3;",
+ 3),
+ GNUNET_PQ_make_prepare ("key_share_select",
+ "SELECT "
+ "key_share_data "
+ "FROM "
+ "anastasis_truth "
+ "WHERE truth_uuid =$1;",
+ 1),
+ GNUNET_PQ_make_prepare ("challengecode_insert",
+ "INSERT INTO anastasis_challengecode "
+ "(truth_uuid"
+ ",code"
+ ",creation_date"
+ ",expiration_date"
+ ",retry_counter"
+ ") VALUES "
+ "($1, $2, $3, $4, $5);",
+ 5),
+ GNUNET_PQ_make_prepare ("challengecode_select",
+ "SELECT "
+ " code"
+ ",satisfied"
+ " FROM anastasis_challengecode"
+ " WHERE truth_uuid=$1"
+ " AND expiration_date > $2"
+ " AND retry_counter != 0;",
+ 2),
+ GNUNET_PQ_make_prepare ("challengecode_set_satisfied",
+ "UPDATE anastasis_challengecode"
+ " SET satisfied=TRUE"
+ " WHERE truth_uuid=$1"
+ " AND code=$2"
+ " AND creation_date IN"
+ " (SELECT creation_date"
+ " FROM anastasis_challengecode"
+ " WHERE truth_uuid=$1"
+ " AND code=$2"
+ " ORDER BY creation_date DESC"
+ " LIMIT 1);",
+ 2),
+ GNUNET_PQ_make_prepare ("challengecode_test_satisfied",
+ "SELECT 1 FROM anastasis_challengecode"
+ " WHERE truth_uuid=$1"
+ " AND satisfied=TRUE"
+ " AND code=$2"
+ " AND creation_date >= $3"
+ " LIMIT 1;",
+ 3),
+ GNUNET_PQ_make_prepare ("challengecode_select_meta",
+ "SELECT "
+ " code"
+ ",retry_counter"
+ ",retransmission_date"
+ " FROM anastasis_challengecode"
+ " WHERE truth_uuid=$1"
+ " AND expiration_date > $2"
+ " AND creation_date > $3"
+ " ORDER BY creation_date DESC"
+ " LIMIT 1;",
+ 2),
+ GNUNET_PQ_make_prepare ("challengecode_update_retry",
+ "UPDATE anastasis_challengecode"
+ " SET retry_counter=retry_counter - 1"
+ " WHERE truth_uuid=$1"
+ " AND code=$2"
+ " AND retry_counter != 0;",
+ 1),
+ GNUNET_PQ_make_prepare ("challengepayment_dec_counter",
+ "UPDATE anastasis_challenge_payment"
+ " SET counter=counter - 1"
+ " WHERE truth_uuid=$1"
+ " AND payment_identifier=$2"
+ " AND counter > 0;",
+ 2),
+ GNUNET_PQ_make_prepare ("challengecode_mark_sent",
+ "UPDATE anastasis_challengecode"
+ " SET retransmission_date=$3"
+ " WHERE truth_uuid=$1"
+ " AND code=$2"
+ " AND creation_date IN"
+ " (SELECT creation_date"
+ " FROM anastasis_challengecode"
+ " WHERE truth_uuid=$1"
+ " AND code=$2"
+ " ORDER BY creation_date DESC"
+ " LIMIT 1);",
+ 3),
+ GNUNET_PQ_make_prepare ("get_last_auth_iban_payment",
+ "SELECT "
+ " wire_reference"
+ " FROM anastasis_auth_iban_in"
+ " WHERE credit_account_details=$1"
+ " ORDER BY wire_reference DESC"
+ " LIMIT 1;",
+ 1),
+ GNUNET_PQ_make_prepare ("gc_challengecodes",
+ "DELETE FROM anastasis_challengecode "
+ "WHERE "
+ "expiration_date < $1;",
+ 1),
+ GNUNET_PQ_PREPARED_STATEMENT_END
+ };
+
+ pg->conn = GNUNET_PQ_connect_with_cfg (pg->cfg,
+ "stasis-postgres",
+ NULL,
+ NULL,
+ ps);
+ if (NULL == pg->conn)
+ return GNUNET_SYSERR;
+ return GNUNET_OK;
+}
+
+
+/**
* Check that the database connection is still up.
*
* @param cls a `struct PostgresClosure` with connection to check
@@ -2281,383 +2691,9 @@ libanastasis_plugin_db_postgres_init (void *cls)
struct GNUNET_CONFIGURATION_Handle *cfg = cls;
struct PostgresClosure *pg;
struct ANASTASIS_DatabasePlugin *plugin;
- struct GNUNET_PQ_PreparedStatement ps[] = {
- GNUNET_PQ_make_prepare ("user_insert",
- "INSERT INTO anastasis_user "
- "(user_id"
- ",expiration_date"
- ") VALUES "
- "($1, $2);",
- 2),
- GNUNET_PQ_make_prepare ("do_commit",
- "COMMIT",
- 0),
- GNUNET_PQ_make_prepare ("user_select",
- "SELECT"
- " expiration_date "
- "FROM anastasis_user"
- " WHERE user_id=$1"
- " FOR UPDATE;",
- 1),
- GNUNET_PQ_make_prepare ("user_update",
- "UPDATE anastasis_user"
- " SET "
- " expiration_date=$1"
- " WHERE user_id=$2;",
- 2),
- GNUNET_PQ_make_prepare ("recdoc_payment_insert",
- "INSERT INTO anastasis_recdoc_payment "
- "(user_id"
- ",post_counter"
- ",amount_val"
- ",amount_frac"
- ",payment_identifier"
- ",creation_date"
- ") VALUES "
- "($1, $2, $3, $4, $5, $6);",
- 6),
- GNUNET_PQ_make_prepare ("challenge_payment_insert",
- "INSERT INTO anastasis_challenge_payment "
- "(truth_uuid"
- ",amount_val"
- ",amount_frac"
- ",payment_identifier"
- ",creation_date"
- ") VALUES "
- "($1, $2, $3, $4, $5);",
- 5),
- GNUNET_PQ_make_prepare ("truth_payment_insert",
- "INSERT INTO anastasis_truth_payment "
- "(truth_uuid"
- ",amount_val"
- ",amount_frac"
- ",expiration"
- ") VALUES "
- "($1, $2, $3, $4);",
- 4),
- GNUNET_PQ_make_prepare ("recdoc_payment_done",
- "UPDATE anastasis_recdoc_payment "
- "SET"
- " paid=TRUE "
- "WHERE"
- " payment_identifier=$1"
- " AND"
- " user_id=$2"
- " AND"
- " paid=FALSE;",
- 2),
- GNUNET_PQ_make_prepare ("challenge_refund_update",
- "UPDATE anastasis_challenge_payment "
- "SET"
- " refunded=TRUE "
- "WHERE"
- " payment_identifier=$1"
- " AND"
- " paid=TRUE"
- " AND"
- " truth_uuid=$2;",
- 2),
- GNUNET_PQ_make_prepare ("challenge_payment_done",
- "UPDATE anastasis_challenge_payment "
- "SET"
- " paid=TRUE "
- "WHERE"
- " payment_identifier=$1"
- " AND"
- " refunded=FALSE"
- " AND"
- " truth_uuid=$2"
- " AND"
- " paid=FALSE;",
- 2),
- GNUNET_PQ_make_prepare ("recdoc_payment_select",
- "SELECT"
- " creation_date"
- ",post_counter"
- ",amount_val"
- ",amount_frac"
- ",paid"
- " FROM anastasis_recdoc_payment"
- " WHERE payment_identifier=$1;",
- 1),
- GNUNET_PQ_make_prepare ("truth_payment_select",
- "SELECT"
- " expiration"
- " FROM anastasis_truth_payment"
- " WHERE truth_uuid=$1"
- " AND expiration>$2;",
- 2),
- GNUNET_PQ_make_prepare ("challenge_payment_select",
- "SELECT"
- " creation_date"
- ",amount_val"
- ",amount_frac"
- ",paid"
- " FROM anastasis_challenge_payment"
- " WHERE payment_identifier=$1"
- " AND truth_uuid=$2"
- " AND refunded=FALSE"
- " AND counter>0;",
- 1),
- GNUNET_PQ_make_prepare ("challenge_pending_payment_select",
- "SELECT"
- " creation_date"
- ",payment_identifier"
- ",amount_val"
- ",amount_frac"
- " FROM anastasis_challenge_payment"
- " WHERE"
- " paid=FALSE"
- " AND"
- " refunded=FALSE"
- " AND"
- " truth_uuid=$1"
- " AND"
- " creation_date > $2;",
- 1),
- GNUNET_PQ_make_prepare ("recdoc_payments_select",
- "SELECT"
- " user_id"
- ",payment_identifier"
- ",amount_val"
- ",amount_frac"
- " FROM anastasis_recdoc_payment"
- " WHERE paid=FALSE;",
- 0),
- GNUNET_PQ_make_prepare ("gc_accounts",
- "DELETE FROM anastasis_user "
- "WHERE"
- " expiration_date < $1;",
- 1),
- GNUNET_PQ_make_prepare ("gc_recdoc_pending_payments",
- "DELETE FROM anastasis_recdoc_payment "
- "WHERE"
- " paid=FALSE"
- " AND"
- " creation_date < $1;",
- 1),
- GNUNET_PQ_make_prepare ("gc_challenge_pending_payments",
- "DELETE FROM anastasis_challenge_payment "
- "WHERE"
- " (paid=FALSE"
- " OR"
- " refunded=TRUE)"
- " AND"
- " creation_date < $1;",
- 1),
- GNUNET_PQ_make_prepare ("truth_insert",
- "INSERT INTO anastasis_truth "
- "(truth_uuid"
- ",key_share_data"
- ",method_name"
- ",encrypted_truth"
- ",truth_mime"
- ",expiration"
- ") VALUES "
- "($1, $2, $3, $4, $5, $6);",
- 6),
-
- GNUNET_PQ_make_prepare ("test_auth_iban_payment",
- "SELECT"
- " credit_val"
- ",credit_frac"
- ",wire_subject"
- " FROM anastasis_auth_iban_in"
- " WHERE debit_account_details=$1"
- " AND execution_date>=$2;",
- 2),
- GNUNET_PQ_make_prepare ("store_auth_iban_payment_details",
- "INSERT INTO anastasis_auth_iban_in "
- "(wire_reference"
- ",wire_subject"
- ",credit_val"
- ",credit_frac"
- ",debit_account_details"
- ",credit_account_details"
- ",execution_date"
- ") VALUES "
- "($1, $2, $3, $4, $5, $6, $7);",
- 7),
-
-
- GNUNET_PQ_make_prepare ("recovery_document_insert",
- "INSERT INTO anastasis_recoverydocument "
- "(user_id"
- ",version"
- ",account_sig"
- ",recovery_data_hash"
- ",recovery_data"
- ") VALUES "
- "($1, $2, $3, $4, $5);",
- 5),
- GNUNET_PQ_make_prepare ("truth_select",
- "SELECT "
- " method_name"
- ",encrypted_truth"
- ",truth_mime"
- " FROM anastasis_truth"
- " WHERE truth_uuid =$1;",
- 1),
- GNUNET_PQ_make_prepare ("latest_recoverydocument_select",
- "SELECT "
- " version"
- ",account_sig"
- ",recovery_data_hash"
- ",recovery_data"
- " FROM anastasis_recoverydocument"
- " WHERE user_id =$1 "
- " ORDER BY version DESC"
- " LIMIT 1;",
- 1),
- GNUNET_PQ_make_prepare ("latest_recovery_version_select",
- "SELECT"
- " version"
- ",recovery_data_hash"
- ",expiration_date"
- " FROM anastasis_recoverydocument"
- " JOIN anastasis_user USING (user_id)"
- " WHERE user_id=$1"
- " ORDER BY version DESC"
- " LIMIT 1;",
- 1),
- GNUNET_PQ_make_prepare ("recoverydocument_select",
- "SELECT "
- " account_sig"
- ",recovery_data_hash"
- ",recovery_data"
- " FROM anastasis_recoverydocument"
- " WHERE user_id=$1"
- " AND version=$2;",
- 2),
- GNUNET_PQ_make_prepare ("postcounter_select",
- "SELECT"
- " post_counter"
- " FROM anastasis_recdoc_payment"
- " WHERE user_id=$1"
- " AND payment_identifier=$2;",
- 2),
- GNUNET_PQ_make_prepare ("postcounter_update",
- "UPDATE "
- "anastasis_recdoc_payment "
- "SET "
- "post_counter=$1 "
- "WHERE user_id =$2 "
- "AND payment_identifier=$3;",
- 3),
- GNUNET_PQ_make_prepare ("key_share_select",
- "SELECT "
- "key_share_data "
- "FROM "
- "anastasis_truth "
- "WHERE truth_uuid =$1;",
- 1),
- GNUNET_PQ_make_prepare ("challengecode_insert",
- "INSERT INTO anastasis_challengecode "
- "(truth_uuid"
- ",code"
- ",creation_date"
- ",expiration_date"
- ",retry_counter"
- ") VALUES "
- "($1, $2, $3, $4, $5);",
- 5),
- GNUNET_PQ_make_prepare ("challengecode_select",
- "SELECT "
- " code"
- ",satisfied"
- " FROM anastasis_challengecode"
- " WHERE truth_uuid=$1"
- " AND expiration_date > $2"
- " AND retry_counter != 0;",
- 2),
- GNUNET_PQ_make_prepare ("challengecode_set_satisfied",
- "UPDATE anastasis_challengecode"
- " SET satisfied=TRUE"
- " WHERE truth_uuid=$1"
- " AND code=$2"
- " AND creation_date IN"
- " (SELECT creation_date"
- " FROM anastasis_challengecode"
- " WHERE truth_uuid=$1"
- " AND code=$2"
- " ORDER BY creation_date DESC"
- " LIMIT 1);",
- 2),
- GNUNET_PQ_make_prepare ("challengecode_test_satisfied",
- "SELECT 1 FROM anastasis_challengecode"
- " WHERE truth_uuid=$1"
- " AND satisfied=TRUE"
- " AND code=$2"
- " AND creation_date >= $3"
- " LIMIT 1;",
- 3),
- GNUNET_PQ_make_prepare ("challengecode_select_meta",
- "SELECT "
- " code"
- ",retry_counter"
- ",retransmission_date"
- " FROM anastasis_challengecode"
- " WHERE truth_uuid=$1"
- " AND expiration_date > $2"
- " AND creation_date > $3"
- " ORDER BY creation_date DESC"
- " LIMIT 1;",
- 2),
- GNUNET_PQ_make_prepare ("challengecode_update_retry",
- "UPDATE anastasis_challengecode"
- " SET retry_counter=retry_counter - 1"
- " WHERE truth_uuid=$1"
- " AND code=$2"
- " AND retry_counter != 0;",
- 1),
- GNUNET_PQ_make_prepare ("challengepayment_dec_counter",
- "UPDATE anastasis_challenge_payment"
- " SET counter=counter - 1"
- " WHERE truth_uuid=$1"
- " AND payment_identifier=$2"
- " AND counter > 0;",
- 2),
- GNUNET_PQ_make_prepare ("challengecode_mark_sent",
- "UPDATE anastasis_challengecode"
- " SET retransmission_date=$3"
- " WHERE truth_uuid=$1"
- " AND code=$2"
- " AND creation_date IN"
- " (SELECT creation_date"
- " FROM anastasis_challengecode"
- " WHERE truth_uuid=$1"
- " AND code=$2"
- " ORDER BY creation_date DESC"
- " LIMIT 1);",
- 3),
- GNUNET_PQ_make_prepare ("get_last_auth_iban_payment",
- "SELECT "
- " wire_reference"
- " FROM anastasis_auth_iban_in"
- " WHERE credit_account_details=$1"
- " ORDER BY wire_reference DESC"
- " LIMIT 1;",
- 1),
- GNUNET_PQ_make_prepare ("gc_challengecodes",
- "DELETE FROM anastasis_challengecode "
- "WHERE "
- "expiration_date < $1;",
- 1),
- GNUNET_PQ_PREPARED_STATEMENT_END
- };
pg = GNUNET_new (struct PostgresClosure);
pg->cfg = cfg;
- pg->conn = GNUNET_PQ_connect_with_cfg (cfg,
- "stasis-postgres",
- "stasis-",
- NULL,
- ps);
- if (NULL == pg->conn)
- {
- GNUNET_free (pg);
- return NULL;
- }
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_string (cfg,
"taler",
@@ -2673,6 +2709,8 @@ libanastasis_plugin_db_postgres_init (void *cls)
}
plugin = GNUNET_new (struct ANASTASIS_DatabasePlugin);
plugin->cls = pg;
+ plugin->connect = &postgres_connect;
+ plugin->create_tables = &postgres_create_tables;
plugin->drop_tables = &postgres_drop_tables;
plugin->gc = &postgres_gc;
plugin->preflight = &postgres_preflight;
diff --git a/src/stasis/test_anastasis_db.c b/src/stasis/test_anastasis_db.c
index 204307a..1ec9770 100644
--- a/src/stasis/test_anastasis_db.c
+++ b/src/stasis/test_anastasis_db.c
@@ -92,15 +92,15 @@ run (void *cls)
result = 77;
return;
}
- if (GNUNET_OK != plugin->drop_tables (plugin->cls))
+ (void) plugin->drop_tables (plugin->cls);
+ if (GNUNET_OK !=
+ plugin->create_tables (plugin->cls))
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Dropping tables failed\n");
result = 77;
return;
}
- ANASTASIS_DB_plugin_unload (plugin);
- if (NULL == (plugin = ANASTASIS_DB_plugin_load (cfg)))
+ if (GNUNET_OK !=
+ plugin->connect (plugin->cls))
{
result = 77;
return;