diff options
Diffstat (limited to 'src/restclient/anastasis_api_policy_store.c')
-rw-r--r-- | src/restclient/anastasis_api_policy_store.c | 53 |
1 files changed, 46 insertions, 7 deletions
diff --git a/src/restclient/anastasis_api_policy_store.c b/src/restclient/anastasis_api_policy_store.c index 5d44094..3afee7d 100644 --- a/src/restclient/anastasis_api_policy_store.c +++ b/src/restclient/anastasis_api_policy_store.c @@ -1,18 +1,18 @@ /* This file is part of ANASTASIS - Copyright (C) 2014-2021 Anastasis SARL + Copyright (C) 2014-2022 Anastasis SARL ANASTASIS is free software; you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as + it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2.1, or (at your option) any later version. ANASTASIS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. + GNU General Public License for more details. - You should have received a copy of the GNU Lesser General Public + You should have received a copy of the GNU General Public License along with ANASTASIS; see the file COPYING.LGPL. If not, see <http://www.gnu.org/licenses/> */ @@ -165,8 +165,7 @@ handle_policy_store_finished (void *cls, ud.us = ANASTASIS_US_SUCCESS; ud.details.success.curr_backup_hash = &pso->new_upload_hash; ud.details.success.policy_expiration - = GNUNET_TIME_absolute_add ( - GNUNET_TIME_UNIT_ZERO_ABS, + = GNUNET_TIME_relative_to_timestamp ( GNUNET_TIME_relative_multiply ( GNUNET_TIME_UNIT_SECONDS, expiration)); @@ -212,6 +211,10 @@ handle_policy_store_finished (void *cls, ud.us = ANASTASIS_US_PAYMENT_REQUIRED; ud.details.payment.payment_request = pso->pay_uri; break; + case MHD_HTTP_REQUEST_TIMEOUT: + ud.us = ANASTASIS_US_CLIENT_ERROR; + ud.ec = TALER_EC_ANASTASIS_PAYMENT_GENERIC_TIMEOUT; + break; case MHD_HTTP_PAYLOAD_TOO_LARGE: ud.us = ANASTASIS_US_CLIENT_ERROR; ud.ec = TALER_EC_GENERIC_UPLOAD_EXCEEDS_LIMIT; @@ -227,6 +230,11 @@ handle_policy_store_finished (void *cls, data_size); ud.us = ANASTASIS_US_SERVER_ERROR; break; + case MHD_HTTP_BAD_GATEWAY: + ud.ec = TALER_JSON_get_error_code2 (data, + data_size); + ud.us = ANASTASIS_US_SERVER_ERROR; + break; default: ud.ec = TALER_JSON_get_error_code2 (data, data_size); @@ -348,6 +356,8 @@ ANASTASIS_policy_store ( const struct ANASTASIS_CRYPTO_AccountPrivateKeyP *anastasis_priv, const void *recovery_data, size_t recovery_data_size, + const void *recovery_meta_data, + size_t recovery_meta_data_size, uint32_t payment_years_requested, const struct ANASTASIS_PaymentSecretP *payment_secret, struct GNUNET_TIME_Relative payment_timeout, @@ -364,6 +374,11 @@ ANASTASIS_policy_store ( .purpose.size = htonl (sizeof (usp)) }; + if (NULL == recovery_meta_data) + { + GNUNET_break (0); + return NULL; + } tms = (unsigned long long) (payment_timeout.rel_value_us / GNUNET_TIME_UNIT_MILLISECONDS.rel_value_us); GNUNET_CRYPTO_hash (recovery_data, @@ -402,7 +417,7 @@ ANASTASIS_policy_store ( val = GNUNET_STRINGS_data_to_string_alloc (&usp.new_recovery_data_hash, sizeof (struct GNUNET_HashCode)); GNUNET_asprintf (&hdr, - "%s: %s", + "%s: \"%s\"", MHD_HTTP_HEADER_IF_NONE_MATCH, val); GNUNET_free (val); @@ -417,6 +432,30 @@ ANASTASIS_policy_store ( } job_headers = ext; + /* Setup meta-data header */ + { + char *meta_val; + + meta_val = GNUNET_STRINGS_data_to_string_alloc ( + recovery_meta_data, + recovery_meta_data_size); + GNUNET_asprintf (&hdr, + "%s: %s", + ANASTASIS_HTTP_HEADER_POLICY_META_DATA, + meta_val); + GNUNET_free (meta_val); + ext = curl_slist_append (job_headers, + hdr); + GNUNET_free (hdr); + if (NULL == ext) + { + GNUNET_break (0); + curl_slist_free_all (job_headers); + return NULL; + } + job_headers = ext; + } + /* Setup Payment-Identifier header */ if (NULL != payment_secret) { |