sync

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

sync-httpd2_get-backups-KEY-objects-UID.c (3776B)


      1 /*
      2   This file is part of TALER
      3   Copyright (C) 2025 Taler Systems SA
      4 
      5   TALER is free software; you can redistribute it and/or modify it under the
      6   terms of the GNU Affero 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 Affero General Public License for more details.
     12 
     13   You should have received a copy of the GNU Affero General Public License along with
     14   TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
     15 */
     16 /**
     17  * @file sync-httpd2_get-backups-KEY-objects-UID.c
     18  * @brief Handle GET /backups/$KEY/objects/$UID requests
     19  * @author Iván Ávalos
     20  */
     21 #include "platform.h"
     22 #include "sync-httpd2.h"
     23 #include <gnunet/gnunet_util_lib.h>
     24 #include <gnunet/gnunet_json_lib.h>
     25 #include <taler/taler_json_lib.h>
     26 #include <taler/taler_mhd2_lib.h>
     27 #include "sync-httpd2_get-backups-KEY-objects-UID.h"
     28 #include <sync/sync_util.h>
     29 
     30 
     31 const struct MHD_Action *
     32 SH_backup_object_get (struct MHD_Request *request,
     33                       const struct SYNC_AccountPublicKeyP *account_pub,
     34                       const char *const args[],
     35                       uint_fast64_t upload_size,
     36                       bool is_update)
     37 {
     38   struct SYNC_ObjectUID uid;
     39   struct GNUNET_HashCode object_hash;
     40   int64_t refcount;
     41   size_t data_size;
     42   void *data = NULL;
     43   enum SYNC_DB_QueryStatus qs;
     44 
     45   (void) upload_size;
     46   (void) is_update;
     47 
     48   /* Parse UID from URL */
     49   if (GNUNET_OK !=
     50       GNUNET_STRINGS_string_to_data (args[0],
     51                                      strlen (args[0]),
     52                                      &uid,
     53                                      sizeof (uid)))
     54   {
     55     return TALER_MHD2_reply_with_error (
     56       request,
     57       MHD_HTTP_STATUS_BAD_REQUEST,
     58       TALER_EC_GENERIC_PARAMETER_MALFORMED,
     59       "uid");
     60   }
     61 
     62   /* Look up object by UID */
     63   qs = SYNCDB_lookup_object_uid (account_pub,
     64                                  &uid,
     65                                  &object_hash,
     66                                  &refcount,
     67                                  &data_size,
     68                                  &data);
     69   switch (qs)
     70   {
     71   case SYNC_DB_ONE_RESULT:
     72     {
     73       json_t *resp_json;
     74 
     75       resp_json = SYNC_object_entry_serialize (&uid,
     76                                                data_size,
     77                                                data);
     78       GNUNET_free (data);
     79       return TALER_MHD2_reply_json_steal (request,
     80                                           resp_json,
     81                                           MHD_HTTP_STATUS_OK);
     82     }
     83   case SYNC_DB_NO_RESULTS:
     84     return TALER_MHD2_reply_with_error (
     85       request,
     86       MHD_HTTP_STATUS_NOT_FOUND,
     87       TALER_EC_SYNC_PREVIOUS_BACKUP_UNKNOWN,
     88       "object not found");
     89   case SYNC_DB_PAYMENT_REQUIRED:
     90     return TALER_MHD2_reply_with_error (
     91       request,
     92       MHD_HTTP_STATUS_PAYMENT_REQUIRED,
     93       TALER_EC_SYNC_ACCOUNT_UNKNOWN,
     94       NULL);
     95   case SYNC_DB_HARD_ERROR:
     96     GNUNET_break (0);
     97     return TALER_MHD2_reply_with_error (
     98       request,
     99       MHD_HTTP_STATUS_INTERNAL_SERVER_ERROR,
    100       TALER_EC_GENERIC_DB_COMMIT_FAILED,
    101       NULL);
    102   case SYNC_DB_SOFT_ERROR:
    103     GNUNET_break (0);
    104     return TALER_MHD2_reply_with_error (
    105       request,
    106       MHD_HTTP_STATUS_INTERNAL_SERVER_ERROR,
    107       TALER_EC_GENERIC_DB_SOFT_FAILURE,
    108       NULL);
    109   default:
    110     GNUNET_break (0);
    111     return TALER_MHD2_reply_with_error (
    112       request,
    113       MHD_HTTP_STATUS_INTERNAL_SERVER_ERROR,
    114       TALER_EC_GENERIC_INTERNAL_INVARIANT_FAILURE,
    115       NULL);
    116   }
    117 }
    118 
    119 
    120 /* end of sync-httpd2_get-backups-KEY-objects-UID.c */