sync-httpd2_get-backups-KEY.c (2973B)
1 /* 2 This file is part of TALER 3 Copyright (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 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.c 18 * @brief GET /backups/$KEY — account status 19 * @author Christian Grothoff 20 */ 21 #include "sync-httpd2.h" 22 #include "sync-httpd2_get-backups-KEY.h" 23 #include <gnunet/gnunet_json_lib.h> 24 #include <taler/taler_json_lib.h> 25 #include <sync/sync_util.h> 26 27 28 const struct MHD_Action * 29 SH_backup_account_get (struct MHD_Request *request, 30 const struct SYNC_AccountPublicKeyP *account_pub) 31 { 32 struct GNUNET_TIME_Timestamp expiration_date; 33 uint64_t storage_used_bytes; 34 uint64_t block_count; 35 enum SYNC_DB_QueryStatus qs; 36 37 qs = SYNCDB_lookup_account_TR (account_pub, 38 &expiration_date, 39 &storage_used_bytes, 40 &block_count); 41 switch (qs) 42 { 43 case SYNC_DB_ONE_RESULT: 44 break; 45 case SYNC_DB_TARGET_MISSING: 46 /* Deliberately not 402: the client is asking *whether* it has to 47 pay, so an unknown account is simply not found. */ 48 return TALER_MHD2_reply_with_error ( 49 request, 50 MHD_HTTP_STATUS_NOT_FOUND, 51 TALER_EC_SYNC_ACCOUNT_UNKNOWN, 52 NULL); 53 case SYNC_DB_HARD_ERROR: 54 GNUNET_break (0); 55 return TALER_MHD2_reply_with_error ( 56 request, 57 MHD_HTTP_STATUS_INTERNAL_SERVER_ERROR, 58 TALER_EC_GENERIC_DB_FETCH_FAILED, 59 NULL); 60 case SYNC_DB_SOFT_ERROR: 61 GNUNET_break (0); 62 return TALER_MHD2_reply_with_error ( 63 request, 64 MHD_HTTP_STATUS_INTERNAL_SERVER_ERROR, 65 TALER_EC_GENERIC_DB_SOFT_FAILURE, 66 NULL); 67 default: 68 GNUNET_break (0); 69 return TALER_MHD2_reply_with_error ( 70 request, 71 MHD_HTTP_STATUS_INTERNAL_SERVER_ERROR, 72 TALER_EC_SYNC_GENERIC_BACKEND_ERROR, 73 NULL); 74 } 75 76 /* An account past its expiration is reported as it stands, not 77 refused: the date is exactly what the client came for. */ 78 return TALER_MHD2_reply_json_steal ( 79 request, 80 GNUNET_JSON_PACK ( 81 GNUNET_JSON_pack_timestamp ("expiration_date", 82 expiration_date), 83 GNUNET_JSON_pack_uint64 ("storage_used_bytes", 84 storage_used_bytes), 85 GNUNET_JSON_pack_uint64 ("block_count", 86 block_count)), 87 MHD_HTTP_STATUS_OK); 88 }