LCOV - code coverage report
Current view: top level - bank - mb_common.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 14 24 58.3 %
Date: 2025-06-23 16:22:09 Functions: 1 1 100.0 %

          Line data    Source code
       1             : /*
       2             :   This file is part of Taler
       3             :   Copyright (C) 2015-2023 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/mb_common.c
      19             :  * @brief Common functions for the bank API
      20             :  * @author Christian Grothoff
      21             :  */
      22             : #include "platform.h"
      23             : #include "mb_common.h"
      24             : 
      25             : 
      26             : enum GNUNET_GenericReturnValue
      27           4 : TALER_MERCHANT_BANK_setup_auth_ (
      28             :   CURL *easy,
      29             :   const struct TALER_MERCHANT_BANK_AuthenticationData *auth)
      30             : {
      31             :   enum GNUNET_GenericReturnValue ret;
      32             : 
      33           4 :   ret = GNUNET_OK;
      34           4 :   switch (auth->method)
      35             :   {
      36           0 :   case TALER_MERCHANT_BANK_AUTH_NONE:
      37           0 :     return GNUNET_OK;
      38           4 :   case TALER_MERCHANT_BANK_AUTH_BASIC:
      39             :     {
      40             :       char *up;
      41             : 
      42           4 :       GNUNET_asprintf (&up,
      43             :                        "%s:%s",
      44           4 :                        auth->details.basic.username,
      45           4 :                        auth->details.basic.password);
      46           4 :       if ( (CURLE_OK !=
      47           4 :             curl_easy_setopt (easy,
      48             :                               CURLOPT_HTTPAUTH,
      49           4 :                               CURLAUTH_BASIC)) ||
      50             :            (CURLE_OK !=
      51           4 :             curl_easy_setopt (easy,
      52             :                               CURLOPT_USERPWD,
      53             :                               up)) )
      54           0 :         ret = GNUNET_SYSERR;
      55           4 :       GNUNET_free (up);
      56           4 :       break;
      57             :     }
      58           0 :   case TALER_MERCHANT_BANK_AUTH_BEARER:
      59             :     {
      60           0 :       if ( (CURLE_OK !=
      61           0 :             curl_easy_setopt (easy,
      62             :                               CURLOPT_HTTPAUTH,
      63           0 :                               CURLAUTH_BEARER)) ||
      64             :            (CURLE_OK !=
      65           0 :             curl_easy_setopt (easy,
      66             :                               CURLOPT_XOAUTH2_BEARER,
      67             :                               auth->details.bearer.token)) )
      68           0 :         ret = GNUNET_SYSERR;
      69           0 :       break;
      70             :     }
      71             :   }
      72           4 :   return ret;
      73             : }
      74             : 
      75             : 
      76             : /* end of mb_common.c */

Generated by: LCOV version 1.16