bank_api_common.c (2217B)
1 /* 2 This file is part of TALER 3 Copyright (C) 2015-2020 Taler Systems SA 4 5 TALER is free software; you can redistribute it and/or modify it under the 6 terms of the GNU 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 General Public License for more details. 12 13 You should have received a copy of the GNU General Public License along with 14 TALER; see the file COPYING. If not, see 15 <http://www.gnu.org/licenses/> 16 */ 17 /** 18 * @file bank-lib/bank_api_common.c 19 * @brief Common functions for the bank API 20 * @author Christian Grothoff 21 */ 22 #include "taler/platform.h" 23 #include "bank_api_common.h" 24 25 26 enum GNUNET_GenericReturnValue 27 TALER_BANK_setup_auth_ (CURL *easy, 28 const struct TALER_BANK_AuthenticationData *auth) 29 { 30 enum GNUNET_GenericReturnValue ret; 31 32 ret = GNUNET_OK; 33 switch (auth->method) 34 { 35 case TALER_BANK_AUTH_NONE: 36 return GNUNET_OK; 37 case TALER_BANK_AUTH_BASIC: 38 { 39 char *up; 40 41 GNUNET_asprintf (&up, 42 "%s:%s", 43 auth->details.basic.username, 44 auth->details.basic.password); 45 if ( (CURLE_OK != 46 curl_easy_setopt (easy, 47 CURLOPT_HTTPAUTH, 48 CURLAUTH_BASIC)) || 49 (CURLE_OK != 50 curl_easy_setopt (easy, 51 CURLOPT_USERPWD, 52 up)) ) 53 ret = GNUNET_SYSERR; 54 GNUNET_free (up); 55 break; 56 } 57 case TALER_BANK_AUTH_BEARER: 58 { 59 if ( (CURLE_OK != 60 curl_easy_setopt (easy, 61 CURLOPT_HTTPAUTH, 62 CURLAUTH_BEARER)) || 63 (CURLE_OK != 64 curl_easy_setopt (easy, 65 CURLOPT_XOAUTH2_BEARER, 66 auth->details.bearer.token)) ) 67 ret = GNUNET_SYSERR; 68 break; 69 } 70 } 71 return ret; 72 } 73 74 75 /* end of bank_api_common.c */