Line data Source code
1 : /*
2 : This file is part of Challenger
3 : Copyright (C) 2023 Taler Systems SA
4 :
5 : Challenger is free software; you can redistribute it and/or modify it under the
6 : terms of the GNU General Public License as published by the Free Software
7 : Foundation; either version 3, or (at your option) any later version.
8 :
9 : Challenger is distributed in the hope that it will be useful, but WITHOUT ANY
10 : WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 : A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12 :
13 : You should have received a copy of the GNU General Public License along with
14 : Challenger; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
15 : */
16 : /**
17 : * @file src/challengerdb/info_get_token.c
18 : * @brief Implementation of the info_get_token function for Postgres
19 : * @author Christian Grothoff
20 : */
21 : #include "platform.h"
22 : #include <taler/taler_error_codes.h>
23 : #include <taler/taler_dbevents.h>
24 : #include <taler/taler_pq_lib.h>
25 : #include "info_get_token.h"
26 : #include "pg_helper.h"
27 :
28 :
29 : enum GNUNET_DB_QueryStatus
30 2 : CHALLENGERDB_info_get_token (struct CHALLENGERDB_PostgresContext *ctx,
31 : const struct CHALLENGER_AccessTokenP *token,
32 : uint64_t *rowid,
33 : json_t **address,
34 : struct GNUNET_TIME_Timestamp *address_expiration)
35 : {
36 : struct GNUNET_TIME_Absolute now
37 2 : = GNUNET_TIME_absolute_get ();
38 2 : struct GNUNET_PQ_QueryParam params[] = {
39 2 : GNUNET_PQ_query_param_auto_from_type (token),
40 2 : GNUNET_PQ_query_param_absolute_time (&now),
41 : GNUNET_PQ_query_param_end
42 : };
43 : struct GNUNET_TIME_Absolute at;
44 2 : struct GNUNET_PQ_ResultSpec rs[] = {
45 2 : GNUNET_PQ_result_spec_uint64 ("rowid",
46 : rowid),
47 2 : TALER_PQ_result_spec_json ("address",
48 : address),
49 2 : GNUNET_PQ_result_spec_absolute_time ("address_expiration_time",
50 : &at),
51 : GNUNET_PQ_result_spec_end
52 : };
53 : enum GNUNET_DB_QueryStatus qs;
54 :
55 2 : PREPARE (ctx,
56 : "info_get_token",
57 : "SELECT "
58 : " grant_serial_id AS rowid"
59 : " ,address"
60 : " ,address_expiration_time"
61 : " FROM tokens"
62 : " WHERE access_token=$1"
63 : " AND token_expiration_time > $2");
64 2 : qs = GNUNET_PQ_eval_prepared_singleton_select (ctx->conn,
65 : "info_get_token",
66 : params,
67 : rs);
68 2 : if (qs > 0)
69 2 : *address_expiration = GNUNET_TIME_absolute_to_timestamp (at);
70 2 : return qs;
71 : }
|