sync

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

syncdb_delete_block_TR.c (5513B)


      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_delete_block_TR.c
     18  * @brief delete a block in the DLL
     19  * @author Iván Ávalos
     20  */
     21 #include "syncdb_pg.h"
     22 
     23 
     24 enum SYNC_DB_QueryStatus
     25 SYNCDB_delete_block_TR (
     26   const struct SYNC_AccountPublicKeyP *account_pub,
     27   const struct SYNC_BlockNonce *block_nonce,
     28   const struct SYNC_BlockNonce *prev_nonce,
     29   const struct SYNC_BlockNonce *next_nonce,
     30   const struct GNUNET_HashCode *block_hash,
     31   unsigned int refs_length,
     32   const struct SYNC_ObjectUID *object_uids,
     33   const int16_t *object_incs,
     34   const struct SYNC_AccountSignatureP *prev_upload_sig,
     35   const struct GNUNET_HashCode *prev_hash,
     36   const struct SYNC_BlockNonce *prev_prev_nonce,
     37   const struct SYNC_AccountSignatureP *next_upload_sig,
     38   const struct GNUNET_HashCode *next_hash,
     39   const struct SYNC_BlockNonce *next_next_nonce)
     40 {
     41   bool account_missing;
     42   bool block_missing;
     43   bool outdated_write;
     44   bool refs_missing;
     45   bool negative_refcount;
     46   bool deleted;
     47   bool refs_updated;
     48   struct GNUNET_PQ_QueryParam params[] = {
     49     GNUNET_PQ_query_param_auto_from_type (account_pub),
     50     GNUNET_PQ_query_param_auto_from_type (block_nonce),
     51     (NULL != prev_nonce)
     52     ? GNUNET_PQ_query_param_auto_from_type (prev_nonce)
     53     : GNUNET_PQ_query_param_null (),
     54     (NULL != next_nonce)
     55     ? GNUNET_PQ_query_param_auto_from_type (next_nonce)
     56     : GNUNET_PQ_query_param_null (),
     57     (NULL != block_hash)
     58     ? GNUNET_PQ_query_param_auto_from_type (block_hash)
     59     : GNUNET_PQ_query_param_null (),
     60     GNUNET_PQ_query_param_array_auto_from_type (refs_length,
     61                                                 object_uids,
     62                                                 pg->conn),
     63     GNUNET_PQ_query_param_array_uint16 (refs_length,
     64                                         (const uint16_t *) object_incs,
     65                                         pg->conn),
     66     (NULL != prev_upload_sig)
     67     ? GNUNET_PQ_query_param_auto_from_type (prev_upload_sig)
     68     : GNUNET_PQ_query_param_null (),
     69     (NULL != prev_hash)
     70     ? GNUNET_PQ_query_param_auto_from_type (prev_hash)
     71     : GNUNET_PQ_query_param_null (),
     72     (NULL != prev_prev_nonce)
     73     ? GNUNET_PQ_query_param_auto_from_type (prev_prev_nonce)
     74     : GNUNET_PQ_query_param_null (),
     75     (NULL != next_upload_sig)
     76     ? GNUNET_PQ_query_param_auto_from_type (next_upload_sig)
     77     : GNUNET_PQ_query_param_null (),
     78     (NULL != next_hash)
     79     ? GNUNET_PQ_query_param_auto_from_type (next_hash)
     80     : GNUNET_PQ_query_param_null (),
     81     (NULL != next_next_nonce)
     82     ? GNUNET_PQ_query_param_auto_from_type (next_next_nonce)
     83     : GNUNET_PQ_query_param_null (),
     84     GNUNET_PQ_query_param_end,
     85   };
     86   struct GNUNET_PQ_ResultSpec rs[] = {
     87     GNUNET_PQ_result_spec_bool ("out_account_missing",
     88                                 &account_missing),
     89     GNUNET_PQ_result_spec_bool ("out_block_missing",
     90                                 &block_missing),
     91     GNUNET_PQ_result_spec_bool ("out_outdated_write",
     92                                 &outdated_write),
     93     GNUNET_PQ_result_spec_bool ("out_refs_missing",
     94                                 &refs_missing),
     95     GNUNET_PQ_result_spec_bool ("out_negative_refcount",
     96                                 &negative_refcount),
     97     GNUNET_PQ_result_spec_bool ("out_deleted",
     98                                 &deleted),
     99     GNUNET_PQ_result_spec_bool ("out_refs_updated",
    100                                 &refs_updated),
    101     GNUNET_PQ_result_spec_end,
    102   };
    103 
    104   enum GNUNET_DB_QueryStatus qs;
    105 
    106   SYNCDB_preflight ();
    107   PREPARE ("do_delete_block",
    108            "SELECT"
    109            " out_account_missing"
    110            ",out_block_missing"
    111            ",out_outdated_write"
    112            ",out_refs_missing"
    113            ",out_negative_refcount"
    114            ",out_deleted"
    115            ",out_refs_updated"
    116            " FROM sync_do_delete_block"
    117            " ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13)");
    118   qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
    119                                                  "do_delete_block",
    120                                                  params,
    121                                                  rs);
    122 
    123   switch (qs)
    124   {
    125   case GNUNET_DB_STATUS_HARD_ERROR:
    126     return SYNC_DB_HARD_ERROR;
    127   case GNUNET_DB_STATUS_SOFT_ERROR:
    128     GNUNET_break (0);
    129     return SYNC_DB_SOFT_ERROR;
    130   case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
    131     GNUNET_break (0);
    132     return SYNC_DB_HARD_ERROR;
    133   case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
    134     if (deleted)
    135       return SYNC_DB_ONE_RESULT;
    136     if (account_missing)
    137       return SYNC_DB_PAYMENT_REQUIRED;
    138     if (block_missing)
    139       return SYNC_DB_TARGET_MISSING;
    140     if (outdated_write)
    141       return SYNC_DB_OUTDATED_WRITE;
    142     if (refs_missing || negative_refcount)
    143       return SYNC_DB_INCONSISTENT_BACKUP;
    144     GNUNET_break (0);
    145     return SYNC_DB_HARD_ERROR;
    146   default:
    147     GNUNET_break (0);
    148     return SYNC_DB_HARD_ERROR;
    149   }
    150 }