Line data Source code
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 "bank_api_common.h"
23 :
24 :
25 : enum GNUNET_GenericReturnValue
26 309 : TALER_BANK_setup_auth_ (CURL *easy,
27 : const struct TALER_BANK_AuthenticationData *auth)
28 : {
29 : enum GNUNET_GenericReturnValue ret;
30 :
31 309 : ret = GNUNET_OK;
32 309 : switch (auth->method)
33 : {
34 43 : case TALER_BANK_AUTH_NONE:
35 43 : return GNUNET_OK;
36 266 : case TALER_BANK_AUTH_BASIC:
37 : {
38 : char *up;
39 :
40 266 : GNUNET_asprintf (&up,
41 : "%s:%s",
42 266 : auth->details.basic.username,
43 266 : auth->details.basic.password);
44 266 : if ( (CURLE_OK !=
45 266 : curl_easy_setopt (easy,
46 : CURLOPT_HTTPAUTH,
47 266 : CURLAUTH_BASIC)) ||
48 : (CURLE_OK !=
49 266 : curl_easy_setopt (easy,
50 : CURLOPT_USERPWD,
51 : up)) )
52 0 : ret = GNUNET_SYSERR;
53 266 : GNUNET_free (up);
54 266 : break;
55 : }
56 0 : case TALER_BANK_AUTH_BEARER:
57 : {
58 0 : if ( (CURLE_OK !=
59 0 : curl_easy_setopt (easy,
60 : CURLOPT_HTTPAUTH,
61 0 : CURLAUTH_BEARER)) ||
62 : (CURLE_OK !=
63 0 : curl_easy_setopt (easy,
64 : CURLOPT_XOAUTH2_BEARER,
65 : auth->details.bearer.token)) )
66 0 : ret = GNUNET_SYSERR;
67 0 : break;
68 : }
69 : }
70 266 : return ret;
71 : }
72 :
73 :
74 : /* end of bank_api_common.c */
|