syncdb_lookup_object.c (2820B)
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_lookup_object.c 18 * @brief lookup object on sync account 19 * @author Iván Ávalos 20 */ 21 #include "syncdb_pg.h" 22 23 24 enum SYNC_DB_QueryStatus 25 SYNCDB_lookup_object ( 26 const struct SYNC_AccountPublicKeyP *account_pub, 27 const struct GNUNET_HashCode *object_hash, 28 int64_t *refcount, 29 struct GNUNET_TIME_Timestamp *expiration_date, 30 size_t *data_size, 31 void *data) 32 { 33 void *tmp_data; 34 struct GNUNET_PQ_QueryParam params[] = { 35 GNUNET_PQ_query_param_auto_from_type (account_pub), 36 GNUNET_PQ_query_param_auto_from_type (object_hash), 37 GNUNET_PQ_query_param_end, 38 }; 39 struct GNUNET_PQ_ResultSpec rs[] = { 40 GNUNET_PQ_result_spec_int64 ("refcount", 41 refcount), 42 GNUNET_PQ_result_spec_auto_from_type ("expiration_date", 43 expiration_date), 44 GNUNET_PQ_result_spec_variable_size ("data_blob", 45 &tmp_data, 46 data_size), 47 GNUNET_PQ_result_spec_end, 48 }; 49 enum GNUNET_DB_QueryStatus qs; 50 51 SYNCDB_preflight (); 52 PREPARE ("do_lookup_object", 53 "SELECT" 54 " refcount" 55 ",expiration_date" 56 ",data_blob" 57 " FROM objects" 58 " WHERE" 59 " account_pub=$1" 60 " AND" 61 " object_hash=$2"); 62 qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn, 63 "do_lookup_object", 64 params, 65 rs); 66 67 switch (qs) 68 { 69 case GNUNET_DB_STATUS_HARD_ERROR: 70 return SYNC_DB_HARD_ERROR; 71 case GNUNET_DB_STATUS_SOFT_ERROR: 72 GNUNET_break (0); 73 return SYNC_DB_SOFT_ERROR; 74 case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS: 75 /* no such object; a perfectly normal outcome */ 76 return SYNC_DB_NO_RESULTS; 77 case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT: 78 if (NULL != data) 79 *(void **) data = tmp_data; 80 else 81 GNUNET_free (tmp_data); 82 return SYNC_DB_ONE_RESULT; 83 default: 84 GNUNET_break (0); 85 return SYNC_DB_HARD_ERROR; 86 } 87 }