api_common.c (2341B)
1 /* 2 This file is part of TALER 3 Copyright (C) 2015-2020 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 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 lib/api_common.c 19 * @brief Common functions for API implementations in the taler digitizer. 20 * since types are used which are not in the current bank/exchange lib the the file suffix is not set 21 * @author Christian Grothoff 22 * @author Reto Tellenbach 23 */ 24 #include "api_common.h" 25 26 27 enum GNUNET_GenericReturnValue 28 DIGITIZER_setup_auth_ (CURL *easy, 29 const struct DIGITIZER_BankAuthenticationData *auth) 30 { 31 enum GNUNET_GenericReturnValue ret; 32 33 ret = GNUNET_OK; 34 switch (auth->method) 35 { 36 case TALER_BANK_AUTH_NONE: 37 return GNUNET_OK; 38 case TALER_BANK_AUTH_BASIC: 39 { 40 char *up; 41 42 GNUNET_asprintf (&up, 43 "%s:%s", 44 auth->details.basic.username, 45 auth->details.basic.password); 46 if ( (CURLE_OK != 47 curl_easy_setopt (easy, 48 CURLOPT_HTTPAUTH, 49 CURLAUTH_BASIC)) || 50 (CURLE_OK != 51 curl_easy_setopt (easy, 52 CURLOPT_USERPWD, 53 up)) ) 54 ret = GNUNET_SYSERR; 55 GNUNET_free (up); 56 break; 57 } 58 case TALER_BANK_AUTH_BEARER: 59 { 60 if ( (CURLE_OK != 61 curl_easy_setopt (easy, 62 CURLOPT_HTTPAUTH, 63 CURLAUTH_BEARER)) || 64 (CURLE_OK != 65 curl_easy_setopt (easy, 66 CURLOPT_XOAUTH2_BEARER, 67 auth->details.bearer.token)) ) 68 ret = GNUNET_SYSERR; 69 break; 70 } 71 } 72 return ret; 73 } 74 75 76 /* end of bank_api_common.c */