client_check.c (3917B)
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/client_check.c 18 * @brief Implementation of the client_check 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 "client_check.h" 26 #include "pg_helper.h" 27 28 29 enum GNUNET_DB_QueryStatus 30 CHALLENGERDB_client_check ( 31 struct CHALLENGERDB_PostgresContext *ctx, 32 uint64_t client_id, 33 const char *client_secret, 34 uint32_t counter_increment, 35 char **client_redirect_uri) 36 { 37 struct GNUNET_PQ_ResultSpec rs[] = { 38 GNUNET_PQ_result_spec_allow_null ( 39 GNUNET_PQ_result_spec_string ("uri", 40 client_redirect_uri), 41 NULL), 42 GNUNET_PQ_result_spec_end 43 }; 44 45 *client_redirect_uri = NULL; 46 if (0 == counter_increment) 47 { 48 struct GNUNET_PQ_QueryParam params[] = { 49 GNUNET_PQ_query_param_uint64 (&client_id), 50 GNUNET_PQ_query_param_string (client_secret), 51 GNUNET_PQ_query_param_end 52 }; 53 54 PREPARE (ctx, 55 "client_check_ro", 56 "SELECT uri" 57 " FROM clients" 58 " WHERE client_serial_id=$1" 59 " AND client_secret=$2;"); 60 return GNUNET_PQ_eval_prepared_singleton_select (ctx->conn, 61 "client_check_ro", 62 params, 63 rs); 64 } 65 else 66 { 67 struct GNUNET_PQ_QueryParam params[] = { 68 GNUNET_PQ_query_param_uint64 (&client_id), 69 GNUNET_PQ_query_param_string (client_secret), 70 GNUNET_PQ_query_param_uint32 (&counter_increment), 71 GNUNET_PQ_query_param_end 72 }; 73 74 PREPARE (ctx, 75 "client_check", 76 "UPDATE clients SET" 77 " validation_counter=validation_counter+CAST($3::INT4 AS INT8)" 78 " WHERE client_serial_id=$1" 79 " AND client_secret=$2" 80 " RETURNING uri;"); 81 return GNUNET_PQ_eval_prepared_singleton_select (ctx->conn, 82 "client_check", 83 params, 84 rs); 85 } 86 } 87 88 89 enum GNUNET_DB_QueryStatus 90 CHALLENGERDB_client_check2 ( 91 struct CHALLENGERDB_PostgresContext *ctx, 92 const char *client_uri, 93 const char *client_secret, 94 uint64_t *client_id) 95 { 96 struct GNUNET_PQ_QueryParam params[] = { 97 GNUNET_PQ_query_param_string (client_uri), 98 GNUNET_PQ_query_param_string (client_secret), 99 GNUNET_PQ_query_param_end 100 }; 101 struct GNUNET_PQ_ResultSpec rs[] = { 102 GNUNET_PQ_result_spec_uint64 ("client_serial_id", 103 client_id), 104 GNUNET_PQ_result_spec_end 105 }; 106 107 PREPARE (ctx, 108 "client_check2", 109 "SELECT client_serial_id" 110 " FROM clients" 111 " WHERE uri=$1" 112 " AND client_secret=$2;"); 113 return GNUNET_PQ_eval_prepared_singleton_select (ctx->conn, 114 "client_check2", 115 params, 116 rs); 117 }