insert_tos_accepted_early.c (2989B)
1 /* 2 This file is part of TALER 3 Copyright (C) 2026 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 src/backenddb/insert_tos_accepted_early.c 18 * @brief Implementation of the insert_tos_accepted_early function for Postgres 19 * @author Christian Grothoff 20 */ 21 #include "platform.h" 22 #include <taler/taler_pq_lib.h> 23 #include <taler/taler_dbevents.h> 24 #include "merchant-database/insert_tos_accepted_early.h" 25 #include "helper.h" 26 27 28 enum GNUNET_DB_QueryStatus 29 TALER_MERCHANTDB_insert_tos_accepted_early ( 30 struct TALER_MERCHANTDB_PostgresContext *pg, 31 const char *merchant_id, 32 const char *exchange_url, 33 const char *tos_version) 34 { 35 struct TALER_MERCHANTDB_MerchantKycStatusChangeEventP ev = { 36 .header.size = htons (sizeof (ev)), 37 .header.type = htons (TALER_DBEVENT_MERCHANT_EXCHANGE_KYC_STATUS_CHANGED), 38 .merchant_pub = pg->current_merchant_pub 39 }; 40 struct TALER_MERCHANTDB_InstanceKycStatusChangeEventP hdr = { 41 .header.size = htons (sizeof (hdr)), 42 .header.type = htons (TALER_DBEVENT_MERCHANT_KYC_STATUS_CHANGED), 43 .merchant_pub = pg->current_merchant_pub 44 }; 45 char *notify_s = GNUNET_PQ_get_event_notify_channel (&hdr.header); 46 struct GNUNET_PQ_QueryParam params[] = { 47 GNUNET_PQ_query_param_string (exchange_url), 48 GNUNET_PQ_query_param_string (tos_version), 49 GNUNET_PQ_query_param_fixed_size ( 50 &ev, 51 offsetof (struct TALER_MERCHANTDB_MerchantKycStatusChangeEventP, h_wire)), 52 GNUNET_PQ_query_param_string (notify_s), 53 GNUNET_PQ_query_param_end 54 }; 55 bool changed; 56 struct GNUNET_PQ_ResultSpec rs[] = { 57 GNUNET_PQ_result_spec_bool ("changed", &changed), 58 GNUNET_PQ_result_spec_end 59 }; 60 enum GNUNET_DB_QueryStatus qs; 61 62 GNUNET_assert (NULL != pg->current_merchant_id); 63 GNUNET_assert (0 == strcmp (merchant_id, 64 pg->current_merchant_id)); 65 TMH_PQ_prepare_anon (pg, 66 "SELECT merchant_do_set_tos_accepted_early" 67 " ($1, $2, $3, $4) AS changed"); 68 qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn, 69 "", 70 params, 71 rs); 72 GNUNET_free (notify_s); 73 if (qs <= 0) 74 return qs; 75 return changed 76 ? GNUNET_DB_STATUS_SUCCESS_ONE_RESULT 77 : GNUNET_DB_STATUS_SUCCESS_NO_RESULTS; 78 }