sync

Backup service to store encrypted wallet databases (experimental)
Log | Files | Refs | Submodules | README | LICENSE

syncdb_lookup_object_uid.c (2785B)


      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_uid.c
     18  * @brief lookup object on sync account by UID
     19  * @author Iván Ávalos
     20  */
     21 #include "syncdb_pg.h"
     22 
     23 
     24 enum SYNC_DB_QueryStatus
     25 SYNCDB_lookup_object_uid (
     26   const struct SYNC_AccountPublicKeyP *account_pub,
     27   const struct SYNC_ObjectUID *uid,
     28   struct GNUNET_HashCode *object_hash,
     29   int64_t *refcount,
     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 (uid),
     37     GNUNET_PQ_query_param_end,
     38   };
     39   struct GNUNET_PQ_ResultSpec rs[] = {
     40     GNUNET_PQ_result_spec_auto_from_type ("object_hash",
     41                                           object_hash),
     42     GNUNET_PQ_result_spec_int64 ("refcount",
     43                                  refcount),
     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_uid",
     53            "SELECT"
     54            " object_hash"
     55            ",refcount"
     56            ",data_blob"
     57            " FROM objects"
     58            " WHERE"
     59            "  account_pub=$1"
     60            " AND"
     61            "  uid=$2");
     62   qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
     63                                                  "do_lookup_object_uid",
     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     return SYNC_DB_NO_RESULTS;
     76   case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
     77     if (NULL != data)
     78       *(void **) data = tmp_data;
     79     else
     80       GNUNET_free (tmp_data);
     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_lookup_object_uid.c */