sync-httpd2_config.c (3865B)
1 /* 2 This file is part of Sync 3 Copyright (C) 2020--2025 Taler Systems SA 4 5 Sync 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 Sync 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 Sync; see the file COPYING.GPL. If not, see <http://www.gnu.org/licenses/> 15 */ 16 /** 17 * @file sync/sync-httpd2_config.c 18 * @brief headers for /config handler 19 * @author Christian Grothoff 20 */ 21 #include "platform.h" 22 #include "sync-httpd2_config.h" 23 #include <taler/taler_json_lib.h> 24 #include <taler/taler_mhd2_lib.h> 25 26 27 /* 28 * Protocol version history: 29 * 30 * 0: original design 31 * 1: adds ?fresh=y to POST backup operation to force fresh contract 32 * to be created 33 * 2: block upload signatures are stored server-side and returned with 34 * the block list, so wallets can verify the backup before applying 35 * 3: adds GET /backups/$ACCOUNT_KEY, reporting when the account expires 36 * and how much of the storage allowance it uses 37 */ 38 39 const struct MHD_Action * 40 SH_handler_config (struct MHD_Request *request, 41 uint_fast64_t upload_size) 42 { 43 static struct MHD_Response *response; 44 static struct GNUNET_TIME_Absolute a; 45 46 GNUNET_break_op (0 == upload_size); 47 if ( (GNUNET_TIME_absolute_is_past (a)) && 48 (NULL != response) ) 49 { 50 MHD_response_destroy (response); 51 response = NULL; 52 } 53 if (NULL == response) 54 { 55 struct GNUNET_TIME_Timestamp km; 56 char dat[128]; 57 58 a = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_DAYS); 59 /* Round up to next full day to ensure the expiration 60 time does not become a fingerprint! */ 61 a = GNUNET_TIME_absolute_round_down (a, 62 GNUNET_TIME_UNIT_DAYS); 63 a = GNUNET_TIME_absolute_add (a, 64 GNUNET_TIME_UNIT_DAYS); 65 /* => /config response stays at most 48h in caches! */ 66 km = GNUNET_TIME_absolute_to_timestamp (a); 67 TALER_MHD2_get_date_string (km.abs_time, 68 dat); 69 response = TALER_MHD2_MAKE_JSON_PACK ( 70 MHD_HTTP_STATUS_OK, 71 GNUNET_JSON_pack_string ("name", 72 "sync"), 73 GNUNET_JSON_pack_string ("build_version", 74 PACKAGE_VERSION), 75 GNUNET_JSON_pack_string ("implementation", 76 "urn:net:taler:specs:sync:c-reference"), 77 GNUNET_JSON_pack_uint64 ("storage_limit_in_megabytes", 78 SH_upload_limit_mb), 79 TALER_JSON_pack_amount ("liability_limit", 80 &SH_insurance), 81 TALER_JSON_pack_amount ("annual_fee", 82 &SH_annual_fee), 83 GNUNET_JSON_pack_string ("version", 84 "4:0:1")); 85 GNUNET_break (MHD_SC_OK == 86 MHD_response_add_header (response, 87 MHD_HTTP_HEADER_EXPIRES, 88 dat)); 89 GNUNET_break (MHD_SC_OK == 90 MHD_response_add_header (response, 91 MHD_HTTP_HEADER_CACHE_CONTROL, 92 "public,max-age=21600")); /* 6h */ 93 GNUNET_assert (MHD_SC_OK == 94 MHD_RESPONSE_SET_OPTIONS (response, 95 MHD_R_OPTION_REUSABLE (true))); 96 } 97 return MHD_action_from_response (request, 98 response); 99 } 100 101 102 /* end of sync-httpd2_config.c */