pg_lookup_contract_terms3.c (3858B)
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 backenddb/pg_lookup_contract_terms3.c 18 * @brief Implementation of the lookup_contract_terms3 function for Postgres 19 * @author Iván Ávalos 20 * @author Christian Grothoff 21 */ 22 #include "platform.h" 23 #include <sys/types.h> 24 #include <taler/taler_error_codes.h> 25 #include <taler/taler_dbevents.h> 26 #include <taler/taler_pq_lib.h> 27 #include "pg_lookup_contract_terms3.h" 28 #include "pg_helper.h" 29 30 31 enum GNUNET_DB_QueryStatus 32 TMH_PG_lookup_contract_terms3 ( 33 void *cls, 34 const char *instance_id, 35 const char *order_id, 36 const char *session_id, 37 json_t **contract_terms, 38 uint64_t *order_serial, 39 bool *paid, 40 bool *wired, 41 bool *session_matches, 42 struct TALER_ClaimTokenP *claim_token, 43 int16_t *choice_index) 44 { 45 struct PostgresClosure *pg = cls; 46 enum GNUNET_DB_QueryStatus qs; 47 struct TALER_ClaimTokenP ct; 48 uint16_t ci = 0; 49 bool choice_index_null = false; 50 struct GNUNET_PQ_QueryParam params[] = { 51 GNUNET_PQ_query_param_string (instance_id), 52 GNUNET_PQ_query_param_string (order_id), 53 NULL == session_id 54 ? GNUNET_PQ_query_param_null () 55 : GNUNET_PQ_query_param_string (session_id), 56 GNUNET_PQ_query_param_end 57 }; 58 struct GNUNET_PQ_ResultSpec rs[] = { 59 /* contract_terms must be first! */ 60 TALER_PQ_result_spec_json ("contract_terms", 61 contract_terms), 62 GNUNET_PQ_result_spec_uint64 ("order_serial", 63 order_serial), 64 GNUNET_PQ_result_spec_bool ("paid", 65 paid), 66 GNUNET_PQ_result_spec_bool ("wired", 67 wired), 68 GNUNET_PQ_result_spec_allow_null ( 69 GNUNET_PQ_result_spec_bool ("session_matches", 70 session_matches), 71 NULL), 72 GNUNET_PQ_result_spec_auto_from_type ("claim_token", 73 &ct), 74 GNUNET_PQ_result_spec_allow_null ( 75 GNUNET_PQ_result_spec_uint16 ("choice_index", 76 &ci), 77 &choice_index_null), 78 GNUNET_PQ_result_spec_end 79 }; 80 81 *session_matches = false; 82 check_connection (pg); 83 PREPARE (pg, 84 "lookup_contract_terms3", 85 "SELECT" 86 " contract_terms::TEXT" 87 ",order_serial" 88 ",claim_token" 89 ",paid" 90 ",wired" 91 ",(session_id=$3) AS session_matches" 92 ",choice_index" 93 " FROM merchant_contract_terms" 94 " WHERE order_id=$2" 95 " AND merchant_serial=" 96 " (SELECT merchant_serial" 97 " FROM merchant_instances" 98 " WHERE merchant_id=$1)"); 99 qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn, 100 "lookup_contract_terms3", 101 params, 102 (NULL != contract_terms) 103 ? rs 104 : &rs[1]); 105 if (NULL != claim_token) 106 *claim_token = ct; 107 if (! choice_index_null) 108 *choice_index = (int16_t) ci; 109 else 110 *choice_index = -1; 111 return qs; 112 }