sync

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

syncdb_update_backup_TR.c (3688B)


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