syncdb_store_object_TR.c (3028B)
1 /* 2 This file is part of TALER 3 (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 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_object_TR.c 18 * @brief store object into sync database 19 * @author Iván Ávalos 20 */ 21 #include "syncdb_pg.h" 22 23 24 enum SYNC_DB_QueryStatus 25 SYNCDB_store_object_TR ( 26 const struct SYNC_ObjectUID *uid, 27 const struct SYNC_AccountPublicKeyP *account_pub, 28 const struct GNUNET_HashCode *object_hash, 29 struct GNUNET_TIME_Relative lifetime, 30 size_t data_size, 31 const void *data) 32 { 33 enum GNUNET_DB_QueryStatus qs; 34 bool out_account_missing; 35 bool out_inserted; 36 struct GNUNET_TIME_Timestamp expiration 37 = GNUNET_TIME_relative_to_timestamp (lifetime); 38 struct GNUNET_PQ_QueryParam params[] = { 39 GNUNET_PQ_query_param_auto_from_type (account_pub), 40 GNUNET_PQ_query_param_auto_from_type (uid), 41 GNUNET_PQ_query_param_auto_from_type (object_hash), 42 GNUNET_PQ_query_param_timestamp (&expiration), 43 GNUNET_PQ_query_param_fixed_size (data, 44 data_size), 45 GNUNET_PQ_query_param_end, 46 }; 47 struct GNUNET_PQ_ResultSpec rs[] = { 48 GNUNET_PQ_result_spec_bool ("out_account_missing", 49 &out_account_missing), 50 GNUNET_PQ_result_spec_bool ("out_inserted", 51 &out_inserted), 52 GNUNET_PQ_result_spec_end, 53 }; 54 SYNCDB_preflight (); 55 PREPARE ("do_store_object", 56 "SELECT" 57 " out_account_missing" 58 ",out_inserted" 59 " FROM sync_do_store_object" 60 " ($1,$2,$3,$4,$5)"); 61 qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn, 62 "do_store_object", 63 params, 64 rs); 65 switch (qs) 66 { 67 case GNUNET_DB_STATUS_HARD_ERROR: 68 return SYNC_DB_HARD_ERROR; 69 case GNUNET_DB_STATUS_SOFT_ERROR: 70 GNUNET_break (0); 71 return SYNC_DB_SOFT_ERROR; 72 case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS: 73 GNUNET_break (0); 74 return SYNC_DB_HARD_ERROR; 75 case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT: 76 if (out_account_missing) 77 return SYNC_DB_PAYMENT_REQUIRED; 78 if (! out_inserted) 79 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 80 "Object with given UID already exists\n"); 81 return SYNC_DB_ONE_RESULT; 82 default: 83 GNUNET_break (0); 84 return SYNC_DB_HARD_ERROR; 85 } 86 } 87 88 89 /* end of syncdb_store_object_TR.c */