pg_authorize_start.c (4269B)
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 challengerdb/pg_authorize_start.c 18 * @brief Implementation of the authorize_start function for Postgres 19 * @author Christian Grothoff 20 * @author Bohdan Potuzhnyi 21 * @author Vlada Svirsh 22 */ 23 #include "platform.h" 24 #include <taler/taler_error_codes.h> 25 #include <taler/taler_dbevents.h> 26 #include <taler/taler_pq_lib.h> 27 #include "pg_authorize_start.h" 28 #include "pg_helper.h" 29 30 31 enum GNUNET_DB_QueryStatus 32 CH_PG_authorize_start (void *cls, 33 const struct CHALLENGER_ValidationNonceP *nonce, 34 uint64_t client_id, 35 const char *client_scope, 36 const char *client_state, 37 const char *client_redirect_uri, 38 const char *code_challenge, 39 uint32_t code_challenge_method, 40 json_t **last_address, 41 uint32_t *address_attempts_left, 42 uint32_t *pin_transmissions_left, 43 uint32_t *auth_attempts_left, 44 bool *solved, 45 struct GNUNET_TIME_Absolute *last_tx_time) 46 { 47 struct PostgresClosure *pg = cls; 48 struct GNUNET_PQ_QueryParam params[] = { 49 GNUNET_PQ_query_param_auto_from_type (nonce), 50 GNUNET_PQ_query_param_uint64 (&client_id), 51 NULL != client_scope 52 ? GNUNET_PQ_query_param_string (client_scope) 53 : GNUNET_PQ_query_param_null (), 54 GNUNET_PQ_query_param_string (client_state), 55 NULL != client_redirect_uri 56 ? GNUNET_PQ_query_param_string (client_redirect_uri) 57 : GNUNET_PQ_query_param_null (), 58 NULL != code_challenge 59 ? GNUNET_PQ_query_param_string (code_challenge) 60 : GNUNET_PQ_query_param_null (), 61 GNUNET_PQ_query_param_uint32 (&code_challenge_method), 62 GNUNET_PQ_query_param_end 63 }; 64 struct GNUNET_PQ_ResultSpec rs[] = { 65 GNUNET_PQ_result_spec_allow_null ( 66 TALER_PQ_result_spec_json ("address", 67 last_address), 68 NULL), 69 GNUNET_PQ_result_spec_uint32 ("address_attempts_left", 70 address_attempts_left), 71 GNUNET_PQ_result_spec_uint32 ("pin_transmissions_left", 72 pin_transmissions_left), 73 GNUNET_PQ_result_spec_uint32 ("auth_attempts_left", 74 auth_attempts_left), 75 GNUNET_PQ_result_spec_bool ("solved", 76 solved), 77 GNUNET_PQ_result_spec_absolute_time ("last_tx_time", 78 last_tx_time), 79 GNUNET_PQ_result_spec_end 80 }; 81 82 *last_address = NULL; 83 PREPARE (pg, 84 "authorize_start_validation", 85 "UPDATE validations SET" 86 " client_scope=$3" 87 " ,client_state=$4" 88 " ,client_redirect_uri=$5::VARCHAR" 89 " ,code_challenge=$6" 90 " ,code_challenge_method=$7" 91 " WHERE nonce=$1" 92 " AND client_serial_id=$2" 93 " AND ($5::VARCHAR=COALESCE(client_redirect_uri,$5::VARCHAR))" 94 " RETURNING" 95 " address" 96 " ,address_attempts_left" 97 " ,pin_transmissions_left" 98 " ,GREATEST(0, auth_attempts_left) AS auth_attempts_left" 99 " ,auth_attempts_left = -1 AS solved" 100 " ,last_tx_time;"); 101 return GNUNET_PQ_eval_prepared_singleton_select (pg->conn, 102 "authorize_start_validation", 103 params, 104 rs); 105 }