commit 7989e0ec611393f2491049de17a0e18f40a6023a
parent b180a54821572de577aa9cbbbb846b2cc3d2fdac
Author: Christian Grothoff <christian@grothoff.org>
Date: Sat, 6 May 2023 19:18:59 +0200
-add missing files
Diffstat:
4 files changed, 223 insertions(+), 0 deletions(-)
diff --git a/src/challengerdb/pg_auth_add_grant.c b/src/challengerdb/pg_auth_add_grant.c
@@ -0,0 +1,60 @@
+/*
+ This file is part of Challenger
+ Copyright (C) 2023 Taler Systems SA
+
+ Challenger is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ Challenger is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ Challenger; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file challengerdb/pg_auth_add_grant.c
+ * @brief Implementation of the auth_add_grant function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include <taler/taler_error_codes.h>
+#include <taler/taler_dbevents.h>
+#include <taler/taler_pq_lib.h>
+#include "pg_auth_add_grant.h"
+#include "pg_helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+CH_PG_auth_add_grant (
+ void *cls,
+ const struct CHALLENGER_ValidationNonceP *nonce,
+ const struct CHALLENGER_AccessTokenP *grant,
+ struct GNUNET_TIME_Relative grant_expiration,
+ struct GNUNET_TIME_Relative address_expiration)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (nonce),
+ GNUNET_PQ_query_param_auto_from_type (grant),
+ GNUNET_PQ_query_param_relative_time (&grant_expiration),
+ GNUNET_PQ_query_param_relative_time (&address_expiration),
+ GNUNET_PQ_query_param_end
+ };
+
+ PREPARE (pg,
+ "auth_add_grant",
+ "INSERT INTO grants"
+ " (access_token"
+ " ,address"
+ " ,grant_expiration_time"
+ " ,address_expiration_time"
+ ") SELECT"
+ " $2, address, $3, $4 + last_tx_time"
+ " FROM validations"
+ " WHERE nonce=$1;");
+ return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "auth_add_grant",
+ params);
+}
diff --git a/src/challengerdb/pg_auth_add_grant.h b/src/challengerdb/pg_auth_add_grant.h
@@ -0,0 +1,48 @@
+/*
+ This file is part of Challenger
+ Copyright (C) 2023 Taler Systems SA
+
+ Challenger is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ Challenger is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ Challenger; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file backenddb/pg_auth_add_grant.h
+ * @brief implementation of the auth_add_grant function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_AUTH_ADD_GRANT_H
+#define PG_AUTH_ADD_GRANT_H
+
+#include <taler/taler_util.h>
+#include <taler/taler_json_lib.h>
+#include "challenger_database_plugin.h"
+
+
+/**
+ * Add access @a grant to address under @a nonce.
+ *
+ * @param cls closure
+ * @param nonce validation process to grant access to
+ * @param grant grant token that grants access
+ * @param grant_expiration for how long should the grant be valid
+ * @param address_expiration for how long after validation do we consider addresses to be valid
+ * @return transaction status
+ */
+enum GNUNET_DB_QueryStatus
+CH_PG_auth_add_grant (
+ void *cls,
+ const struct CHALLENGER_ValidationNonceP *nonce,
+ const struct CHALLENGER_AccessTokenP *grant,
+ struct GNUNET_TIME_Relative grant_expiration,
+ struct GNUNET_TIME_Relative address_expiration);
+
+
+#endif
diff --git a/src/challengerdb/pg_info_get_grant.c b/src/challengerdb/pg_info_get_grant.c
@@ -0,0 +1,69 @@
+/*
+ This file is part of Challenger
+ Copyright (C) 2023 Taler Systems SA
+
+ Challenger is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ Challenger is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ Challenger; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file challengerdb/pg_info_get_grant.c
+ * @brief Implementation of the info_get_grant function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include <taler/taler_error_codes.h>
+#include <taler/taler_dbevents.h>
+#include <taler/taler_pq_lib.h>
+#include "pg_info_get_grant.h"
+#include "pg_helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+CH_PG_info_get_grant (
+ void *cls,
+ const struct CHALLENGER_AccessTokenP *grant,
+ char **address,
+ struct GNUNET_TIME_Timestamp *address_expiration)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_TIME_Absolute now
+ = GNUNET_TIME_absolute_get ();
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (grant),
+ GNUNET_PQ_query_param_absolute_time (&now),
+ GNUNET_PQ_query_param_end
+ };
+ struct GNUNET_TIME_Absolute at;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_string ("address",
+ address),
+ GNUNET_PQ_result_spec_absolute_time ("address_expiration_timestamp",
+ &at),
+ GNUNET_PQ_result_spec_end
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ PREPARE (pg,
+ "info_get_grant",
+ "SELECT "
+ " address"
+ " ,address_expiration_timestamp"
+ " FROM grants"
+ " WHERE access_token=$1"
+ " AND grant_expiration_time>=$2");
+ qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+ "validation_get",
+ params,
+ rs);
+ if (qs > 0)
+ *address_expiration = GNUNET_TIME_absolute_to_timestamp (at);
+ return qs;
+}
diff --git a/src/challengerdb/pg_info_get_grant.h b/src/challengerdb/pg_info_get_grant.h
@@ -0,0 +1,46 @@
+/*
+ This file is part of Challenger
+ Copyright (C) 2023 Taler Systems SA
+
+ Challenger is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ Challenger is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ Challenger; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file backenddb/pg_info_get_grant.h
+ * @brief implementation of the info_get_grant function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_INFO_GET_GRANT_H
+#define PG_INFO_GET_GRANT_H
+
+#include <taler/taler_util.h>
+#include <taler/taler_json_lib.h>
+#include "challenger_database_plugin.h"
+
+
+/**
+ * Return @a address which @a grant gives access to.
+ *
+ * @param cls closure
+ * @param grant grant token that grants access
+ * @param[out] address set to the address under @a grant
+ * @param[out] address_expiration set to how long we consider @a address to be valid
+ * @return transaction status
+ */
+enum GNUNET_DB_QueryStatus
+CH_PG_info_get_grant (
+ void *cls,
+ const struct CHALLENGER_AccessTokenP *grant,
+ char **address,
+ struct GNUNET_TIME_Timestamp *address_expiration);
+
+
+#endif