syncdb_store_backup_TR.c (3326B)
1 /* 2 This file is part of TALER 3 (C) 2014--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 Lesser 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 syncdb/syncdb_store_backup_TR.c 18 * @brief store first backup 19 * @author Christian Grothoff 20 */ 21 #include "syncdb_pg.h" 22 23 24 enum SYNC_DB_QueryStatus 25 SYNCDB_store_backup_TR ( 26 const struct SYNC_AccountPublicKeyP *account_pub, 27 const struct SYNC_AccountSignatureP *account_sig, 28 const struct GNUNET_HashCode *backup_hash, 29 size_t backup_size, 30 const void *backup) 31 { 32 uint32_t bs = (uint32_t) backup_size; 33 bool payment_required; 34 bool old_backup_mismatch; 35 bool no_change; 36 bool inserted; 37 struct GNUNET_PQ_QueryParam params[] = { 38 GNUNET_PQ_query_param_auto_from_type (account_pub), 39 GNUNET_PQ_query_param_auto_from_type (account_sig), 40 GNUNET_PQ_query_param_auto_from_type (backup_hash), 41 GNUNET_PQ_query_param_uint32 (&bs), 42 GNUNET_PQ_query_param_fixed_size (backup, 43 backup_size), 44 GNUNET_PQ_query_param_end 45 }; 46 struct GNUNET_PQ_ResultSpec rs[] = { 47 GNUNET_PQ_result_spec_bool ("out_payment_required", 48 &payment_required), 49 GNUNET_PQ_result_spec_bool ("out_old_backup_mismatch", 50 &old_backup_mismatch), 51 GNUNET_PQ_result_spec_bool ("out_no_change", 52 &no_change), 53 GNUNET_PQ_result_spec_bool ("out_inserted", 54 &inserted), 55 GNUNET_PQ_result_spec_end 56 }; 57 enum GNUNET_DB_QueryStatus qs; 58 59 SYNCDB_preflight (); 60 PREPARE ("do_store_backup", 61 "SELECT" 62 " out_payment_required" 63 ",out_old_backup_mismatch" 64 ",out_no_change" 65 ",out_inserted" 66 " FROM sync_do_store_backup" 67 " ($1,$2,$3,$4,$5);"); 68 qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn, 69 "do_store_backup", 70 params, 71 rs); 72 switch (qs) 73 { 74 case GNUNET_DB_STATUS_HARD_ERROR: 75 return SYNC_DB_HARD_ERROR; 76 case GNUNET_DB_STATUS_SOFT_ERROR: 77 GNUNET_break (0); 78 return SYNC_DB_SOFT_ERROR; 79 case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS: 80 GNUNET_break (0); 81 return SYNC_DB_HARD_ERROR; 82 case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT: 83 if (inserted) 84 return SYNC_DB_ONE_RESULT; 85 if (payment_required) 86 return SYNC_DB_PAYMENT_REQUIRED; 87 if (old_backup_mismatch) 88 return SYNC_DB_OLD_BACKUP_MISMATCH; 89 if (no_change) 90 return SYNC_DB_NO_RESULTS; 91 GNUNET_break (0); 92 return SYNC_DB_HARD_ERROR; 93 default: 94 GNUNET_break (0); 95 return SYNC_DB_HARD_ERROR; 96 } 97 } 98 99 100 /* end of syncdb_store_backup_TR.c */