sync

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

syncdb_append_block_TR.c (4937B)


      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_append_block_TR.c
     18  * @brief append block at the end of DLL
     19  * @author Iván Ávalos
     20  */
     21 #include "syncdb_pg.h"
     22 
     23 enum SYNC_DB_QueryStatus
     24 SYNCDB_append_block_TR (
     25   const struct SYNC_AccountPublicKeyP *account_pub,
     26   const struct SYNC_BlockNonce *block_nonce,
     27   const struct SYNC_BlockNonce *prev_nonce,
     28   const struct GNUNET_HashCode *data_hash,
     29   size_t data_size,
     30   const void *data,
     31   unsigned int refs_length,
     32   const struct SYNC_ObjectUID *object_uids,
     33   const int16_t *object_incs,
     34   const struct SYNC_AccountSignatureP *upload_sig,
     35   const struct GNUNET_HashCode *refs_hash,
     36   const struct SYNC_AccountSignatureP *prev_upload_sig,
     37   const struct GNUNET_HashCode *prev_hash,
     38   const struct SYNC_BlockNonce *prev_prev_nonce)
     39 {
     40   bool account_missing;
     41   bool outdated_append;
     42   bool negative_refcount;
     43   bool refs_missing;
     44   bool inserted;
     45   bool refs_updated;
     46   struct GNUNET_PQ_QueryParam params[] = {
     47     GNUNET_PQ_query_param_auto_from_type (account_pub),
     48     GNUNET_PQ_query_param_auto_from_type (block_nonce),
     49     (NULL != prev_nonce)
     50     ? GNUNET_PQ_query_param_auto_from_type (prev_nonce)
     51     : GNUNET_PQ_query_param_null (),
     52     GNUNET_PQ_query_param_auto_from_type (data_hash),
     53     GNUNET_PQ_query_param_fixed_size (data,
     54                                       data_size),
     55     GNUNET_PQ_query_param_array_auto_from_type (refs_length,
     56                                                 object_uids,
     57                                                 pg->conn),
     58     GNUNET_PQ_query_param_array_int16 (refs_length,
     59                                        object_incs,
     60                                        pg->conn),
     61     GNUNET_PQ_query_param_auto_from_type (upload_sig),
     62     GNUNET_PQ_query_param_auto_from_type (refs_hash),
     63     (NULL != prev_upload_sig)
     64     ? GNUNET_PQ_query_param_auto_from_type (prev_upload_sig)
     65     : GNUNET_PQ_query_param_null (),
     66     (NULL != prev_hash)
     67     ? GNUNET_PQ_query_param_auto_from_type (prev_hash)
     68     : GNUNET_PQ_query_param_null (),
     69     (NULL != prev_prev_nonce)
     70     ? GNUNET_PQ_query_param_auto_from_type (prev_prev_nonce)
     71     : GNUNET_PQ_query_param_null (),
     72     GNUNET_PQ_query_param_end,
     73   };
     74   struct GNUNET_PQ_ResultSpec rs[] = {
     75     GNUNET_PQ_result_spec_bool ("out_account_missing",
     76                                 &account_missing),
     77     GNUNET_PQ_result_spec_bool ("out_outdated_append",
     78                                 &outdated_append),
     79     GNUNET_PQ_result_spec_bool ("out_negative_refcount",
     80                                 &negative_refcount),
     81     GNUNET_PQ_result_spec_bool ("out_refs_missing",
     82                                 &refs_missing),
     83     GNUNET_PQ_result_spec_bool ("out_inserted",
     84                                 &inserted),
     85     GNUNET_PQ_result_spec_bool ("out_refs_updated",
     86                                 &refs_updated),
     87     GNUNET_PQ_result_spec_end,
     88   };
     89   enum GNUNET_DB_QueryStatus qs;
     90 
     91   SYNCDB_preflight ();
     92   PREPARE ("do_append_block",
     93            "SELECT"
     94            " out_account_missing"
     95            ",out_outdated_append"
     96            ",out_negative_refcount"
     97            ",out_refs_missing"
     98            ",out_inserted"
     99            ",out_refs_updated"
    100            " FROM sync_do_append_block"
    101            " ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12)");
    102   qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
    103                                                  "do_append_block",
    104                                                  params,
    105                                                  rs);
    106 
    107   switch (qs)
    108   {
    109   case GNUNET_DB_STATUS_HARD_ERROR:
    110     return SYNC_DB_HARD_ERROR;
    111   case GNUNET_DB_STATUS_SOFT_ERROR:
    112     GNUNET_break (0);
    113     return SYNC_DB_SOFT_ERROR;
    114   case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
    115     GNUNET_break (0);
    116     return SYNC_DB_HARD_ERROR;
    117   case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
    118     if (inserted && refs_updated)
    119       return SYNC_DB_ONE_RESULT;
    120     if (account_missing)
    121       return SYNC_DB_PAYMENT_REQUIRED;
    122     if (outdated_append)
    123       return SYNC_DB_OUTDATED_WRITE;
    124     if (negative_refcount || refs_missing)
    125       return SYNC_DB_INCONSISTENT_BACKUP;
    126     /* Nothing else failed, so the INSERT hit the primary key */
    127     return SYNC_DB_OUTDATED_WRITE;
    128   default:
    129     GNUNET_break (0);
    130     return SYNC_DB_HARD_ERROR;
    131   }
    132 }