iterate_kyc_reference.c (3497B)
1 /* 2 This file is part of TALER 3 Copyright (C) 2022 Taler Systems SA 4 5 TALER 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 TALER 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 TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> 15 */ 16 /** 17 * @file iterate_kyc_reference.c 18 * @brief Low-level (statement-level) Postgres database access for the exchange 19 * @author Christian Grothoff 20 */ 21 #include "taler/taler_pq_lib.h" 22 #include "exchange-database/iterate_kyc_reference.h" 23 #include "helper.h" 24 25 26 /** 27 * Closure for #iterate_kyc_reference_cb() 28 */ 29 struct IteratorContext 30 { 31 /** 32 * Function to call with the results. 33 */ 34 TALER_EXCHANGEDB_LegitimizationProcessCallback cb; 35 36 /** 37 * Closure to pass to @e cb 38 */ 39 void *cb_cls; 40 41 /** 42 * Plugin context. 43 */ 44 struct TALER_EXCHANGEDB_PostgresContext *pg; 45 }; 46 47 48 /** 49 * Helper function for #TALER_EXCHANGEDB_iterate_kyc_reference(). 50 * Calls the callback with each denomination key. 51 * 52 * @param cls a `struct IteratorContext` 53 * @param result db results 54 * @param num_results number of results in @a result 55 */ 56 static void 57 iterate_kyc_reference_cb (void *cls, 58 PGresult *result, 59 unsigned int num_results) 60 { 61 struct IteratorContext *ic = cls; 62 63 for (unsigned int i = 0; i<num_results; i++) 64 { 65 char *kyc_provider_name_name; 66 char *provider_user_id; 67 char *legitimization_id; 68 struct GNUNET_PQ_ResultSpec rs[] = { 69 GNUNET_PQ_result_spec_string ("provider_name", 70 &kyc_provider_name_name), 71 GNUNET_PQ_result_spec_string ("provider_user_id", 72 &provider_user_id), 73 GNUNET_PQ_result_spec_string ("provider_legitimization_id", 74 &legitimization_id), 75 GNUNET_PQ_result_spec_end 76 }; 77 78 if (GNUNET_OK != 79 GNUNET_PQ_extract_result (result, 80 rs, 81 i)) 82 { 83 GNUNET_break (0); 84 return; 85 } 86 ic->cb (ic->cb_cls, 87 kyc_provider_name_name, 88 provider_user_id, 89 legitimization_id); 90 GNUNET_PQ_cleanup_result (rs); 91 } 92 } 93 94 95 enum GNUNET_DB_QueryStatus 96 TALER_EXCHANGEDB_iterate_kyc_reference ( 97 struct TALER_EXCHANGEDB_PostgresContext *pg, 98 const struct TALER_NormalizedPaytoHashP *h_payto, 99 TALER_EXCHANGEDB_LegitimizationProcessCallback lpc, 100 void *lpc_cls) 101 { 102 struct GNUNET_PQ_QueryParam params[] = { 103 GNUNET_PQ_query_param_auto_from_type (h_payto), 104 GNUNET_PQ_query_param_end 105 }; 106 struct IteratorContext ic = { 107 .cb = lpc, 108 .cb_cls = lpc_cls, 109 .pg = pg 110 }; 111 112 PREPARE (pg, 113 "iterate_kyc_reference", 114 "SELECT " 115 " provider_name" 116 ",provider_user_id" 117 ",provider_legitimization_id" 118 " FROM legitimization_processes" 119 " WHERE h_payto=$1;"); 120 return GNUNET_PQ_eval_prepared_multi_select ( 121 pg->conn, 122 "iterate_kyc_reference", 123 params, 124 &iterate_kyc_reference_cb, 125 &ic); 126 }