From 9443c10d7feb0d91323869dd08ec61ca781564f4 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sat, 11 Jan 2020 15:19:56 +0100 Subject: major refactoring, eliminating wire-plugins and moving towards new bank API. main code compiles, testcases known to fail, code sure not to fully work yet --- src/bank-lib/bank_api_common.c | 86 ++++++++++++++++-------------------------- 1 file changed, 33 insertions(+), 53 deletions(-) (limited to 'src/bank-lib/bank_api_common.c') diff --git a/src/bank-lib/bank_api_common.c b/src/bank-lib/bank_api_common.c index 50769dae2..8a8f4289f 100644 --- a/src/bank-lib/bank_api_common.c +++ b/src/bank-lib/bank_api_common.c @@ -1,6 +1,6 @@ /* This file is part of TALER - Copyright (C) 2015, 2016, 2017 GNUnet e.V. + Copyright (C) 2015-2020 Taler Systems SA TALER is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -24,67 +24,47 @@ /** - * Append HTTP key-value pair to curl header list. + * Set authentication data in @a easy from @a auth. + * The API currently specifies the use of HTTP basic + * authentication. * - * @param hdr list to append to, can be NULL - * @param key key to append - * @param value value to append - * @return new list, NULL on error + * @param easy curl handle to setup for authentication + * @param auth authentication data to use + * @return #GNUNET_OK in success */ -static struct curl_slist * -append (struct curl_slist *hdr, - const char *key, - const char *value) +int +TALER_BANK_setup_auth_ (CURL *easy, + const struct TALER_BANK_AuthenticationData *auth) { - char *str; - struct curl_slist *ret; - - GNUNET_asprintf (&str, - "%s: %s", - key, - value); - ret = curl_slist_append (hdr, - str); - GNUNET_free (str); - if (NULL == ret) - { - GNUNET_break (0); - curl_slist_free_all (hdr); - return NULL; - } - return ret; -} - - -/** - * Build authentication header from @a auth. - * - * @param auth authentication data to use. - * - * @return NULL on error, otherwise curl headers to use. - */ -struct curl_slist * -TALER_BANK_make_auth_header_ - (const struct TALER_BANK_AuthenticationData *auth) -{ - struct curl_slist *authh; + int ret; + ret = GNUNET_OK; switch (auth->method) { case TALER_BANK_AUTH_NONE: - return NULL; + return GNUNET_OK; case TALER_BANK_AUTH_BASIC: - authh = append (NULL, - "X-Taler-Bank-Username", - auth->details.basic.username); - if (NULL == authh) - return NULL; - authh = append (authh, - "X-Taler-Bank-Password", - auth->details.basic.password); - return authh; + { + char *up; + + GNUNET_asprintf (&up, + "%s:%s", + auth->details.basic.username, + auth->details.basic.password); + if ( (CURLE_OK != + curl_easy_setopt (easy, + CURLOPT_HTTPAUTH, + CURLAUTH_BASIC)) || + (CURLE_OK != + curl_easy_setopt (easy, + CURLOPT_USERPWD, + up)) ) + ret = GNUNET_SYSERR; + GNUNET_free (up); + break; + } } - return NULL; + return ret; } -- cgit v1.2.3