exchange

Base system with REST service to issue digital coins, run by the payment service provider
Log | Files | Refs | Submodules | README | LICENSE

bank_api_common.c (2189B)


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