sync

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

syncdb_lookup_account_TR.c (2637B)


      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_lookup_account_TR.c
     18  * @brief lookup account and backup metadata
     19  * @author Christian Grothoff
     20  */
     21 #include "syncdb_pg.h"
     22 
     23 
     24 enum SYNC_DB_QueryStatus
     25 SYNCDB_lookup_account_TR (
     26   const struct SYNC_AccountPublicKeyP *account_pub,
     27   struct GNUNET_HashCode *backup_hash)
     28 {
     29   bool payment_required;
     30   bool no_backup;
     31   struct GNUNET_PQ_QueryParam params[] = {
     32     GNUNET_PQ_query_param_auto_from_type (account_pub),
     33     GNUNET_PQ_query_param_end
     34   };
     35   struct GNUNET_PQ_ResultSpec rs[] = {
     36     GNUNET_PQ_result_spec_auto_from_type ("out_backup_hash",
     37                                           backup_hash),
     38     GNUNET_PQ_result_spec_bool ("out_payment_required",
     39                                 &payment_required),
     40     GNUNET_PQ_result_spec_bool ("out_no_backup",
     41                                 &no_backup),
     42     GNUNET_PQ_result_spec_end
     43   };
     44   enum GNUNET_DB_QueryStatus qs;
     45 
     46   SYNCDB_preflight ();
     47   PREPARE ("do_lookup_account",
     48            "SELECT"
     49            " out_backup_hash"
     50            ",out_payment_required"
     51            ",out_no_backup"
     52            " FROM sync_do_lookup_account"
     53            " ($1);");
     54   qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
     55                                                  "do_lookup_account",
     56                                                  params,
     57                                                  rs);
     58   switch (qs)
     59   {
     60   case GNUNET_DB_STATUS_HARD_ERROR:
     61     return SYNC_DB_HARD_ERROR;
     62   case GNUNET_DB_STATUS_SOFT_ERROR:
     63     GNUNET_break (0);
     64     return SYNC_DB_SOFT_ERROR;
     65   case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
     66     GNUNET_break (0);
     67     return SYNC_DB_HARD_ERROR;
     68   case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
     69     if (payment_required)
     70       return SYNC_DB_PAYMENT_REQUIRED;
     71     if (no_backup)
     72       return SYNC_DB_NO_RESULTS;
     73     return SYNC_DB_ONE_RESULT;
     74   default:
     75     GNUNET_break (0);
     76     return SYNC_DB_HARD_ERROR;
     77   }
     78 }
     79 
     80 
     81 /* end of syncdb_lookup_account_TR.c */