LCOV - code coverage report
Current view: top level - bank-lib - bank_api_common.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 16 24 66.7 %
Date: 2025-06-22 12:09:43 Functions: 1 1 100.0 %

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

Generated by: LCOV version 1.16