LCOV - code coverage report
Current view: top level - bank-lib - bank_api_parse.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 53.9 % 76 41
Test Date: 2026-02-16 10:50:18 Functions: 100.0 % 2 2

            Line data    Source code
       1              : /*
       2              :   This file is part of TALER
       3              :   Copyright (C) 2018-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_parse.c
      19              :  * @brief Convenience function to parse authentication configuration
      20              :  * @author Christian Grothoff
      21              :  */
      22              : #include "taler/platform.h"
      23              : #include "taler/taler_bank_service.h"
      24              : 
      25              : 
      26              : enum GNUNET_GenericReturnValue
      27          301 : TALER_BANK_auth_parse_cfg (const struct GNUNET_CONFIGURATION_Handle *cfg,
      28              :                            const char *section,
      29              :                            struct TALER_BANK_AuthenticationData *auth)
      30              : {
      31              :   const struct
      32              :   {
      33              :     const char *m;
      34              :     enum TALER_BANK_AuthenticationMethod e;
      35          301 :   } methods[] = {
      36              :     { "NONE",  TALER_BANK_AUTH_NONE    },
      37              :     { "BASIC", TALER_BANK_AUTH_BASIC   },
      38              :     { "BEARER", TALER_BANK_AUTH_BEARER },
      39              :     { NULL, TALER_BANK_AUTH_NONE       }
      40              :   };
      41              :   char *method;
      42              : 
      43          301 :   auth->core_bank_url = NULL;
      44          301 :   if (GNUNET_OK ==
      45          301 :       GNUNET_CONFIGURATION_get_value_string (cfg,
      46              :                                              section,
      47              :                                              "CORE_BANK_URL",
      48              :                                              &auth->core_bank_url))
      49              :   {
      50          153 :     if (! TALER_is_web_url (auth->core_bank_url))
      51              :     {
      52            0 :       GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR,
      53              :                                  section,
      54              :                                  "CORE_BANK_URL",
      55              :                                  "Not a valid URL");
      56            0 :       return GNUNET_SYSERR;
      57              :     }
      58              :   }
      59          301 :   if (GNUNET_OK !=
      60          301 :       GNUNET_CONFIGURATION_get_value_string (cfg,
      61              :                                              section,
      62              :                                              "WIRE_GATEWAY_URL",
      63              :                                              &auth->wire_gateway_url))
      64              :   {
      65            0 :     GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
      66              :                                section,
      67              :                                "WIRE_GATEWAY_URL");
      68            0 :     return GNUNET_SYSERR;
      69              :   }
      70          301 :   if (GNUNET_OK !=
      71          301 :       GNUNET_CONFIGURATION_get_value_string (cfg,
      72              :                                              section,
      73              :                                              "WIRE_GATEWAY_AUTH_METHOD",
      74              :                                              &method))
      75              :   {
      76            0 :     GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
      77              :                                section,
      78              :                                "WIRE_GATEWAY_AUTH_METHOD");
      79            0 :     GNUNET_free (auth->wire_gateway_url);
      80            0 :     return GNUNET_SYSERR;
      81              :   }
      82          520 :   for (unsigned int i = 0; NULL != methods[i].m; i++)
      83              :   {
      84          520 :     if (0 == strcasecmp (method,
      85          520 :                          methods[i].m))
      86              :     {
      87          301 :       switch (methods[i].e)
      88              :       {
      89           82 :       case TALER_BANK_AUTH_NONE:
      90           82 :         auth->method = TALER_BANK_AUTH_NONE;
      91           82 :         GNUNET_free (method);
      92           82 :         return GNUNET_OK;
      93          219 :       case TALER_BANK_AUTH_BASIC:
      94          219 :         if (GNUNET_OK !=
      95          219 :             GNUNET_CONFIGURATION_get_value_string (
      96              :               cfg,
      97              :               section,
      98              :               "USERNAME",
      99              :               &auth->details.basic.username))
     100              :         {
     101            0 :           GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
     102              :                                      section,
     103              :                                      "USERNAME");
     104            0 :           GNUNET_free (method);
     105            0 :           GNUNET_free (auth->wire_gateway_url);
     106            0 :           return GNUNET_SYSERR;
     107              :         }
     108          219 :         if (GNUNET_OK !=
     109          219 :             GNUNET_CONFIGURATION_get_value_string (
     110              :               cfg,
     111              :               section,
     112              :               "PASSWORD",
     113              :               &auth->details.basic.password))
     114              :         {
     115            0 :           GNUNET_free (auth->details.basic.username);
     116            0 :           auth->details.basic.username = NULL;
     117            0 :           GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
     118              :                                      section,
     119              :                                      "PASSWORD");
     120            0 :           GNUNET_free (method);
     121            0 :           GNUNET_free (auth->wire_gateway_url);
     122            0 :           return GNUNET_SYSERR;
     123              :         }
     124          219 :         auth->method = TALER_BANK_AUTH_BASIC;
     125          219 :         GNUNET_free (method);
     126          219 :         return GNUNET_OK;
     127            0 :       case TALER_BANK_AUTH_BEARER:
     128            0 :         if (GNUNET_OK !=
     129            0 :             GNUNET_CONFIGURATION_get_value_string (
     130              :               cfg,
     131              :               section,
     132              :               "TOKEN",
     133              :               &auth->details.bearer.token))
     134              :         {
     135            0 :           GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
     136              :                                      section,
     137              :                                      "TOKEN");
     138            0 :           GNUNET_free (method);
     139            0 :           GNUNET_free (auth->wire_gateway_url);
     140            0 :           return GNUNET_SYSERR;
     141              :         }
     142            0 :         auth->method = TALER_BANK_AUTH_BEARER;
     143            0 :         GNUNET_free (method);
     144            0 :         return GNUNET_OK;
     145              :       }
     146              :     }
     147              :   }
     148            0 :   GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
     149              :               "Unknown authentication method `%s'\n",
     150              :               method);
     151            0 :   GNUNET_free (method);
     152            0 :   return GNUNET_SYSERR;
     153              : }
     154              : 
     155              : 
     156              : void
     157          267 : TALER_BANK_auth_free (struct TALER_BANK_AuthenticationData *auth)
     158              : {
     159          267 :   switch (auth->method)
     160              :   {
     161           86 :   case TALER_BANK_AUTH_NONE:
     162           86 :     break;
     163          181 :   case TALER_BANK_AUTH_BASIC:
     164          181 :     if (NULL != auth->details.basic.username)
     165              :     {
     166          181 :       GNUNET_free (auth->details.basic.username);
     167          181 :       auth->details.basic.username = NULL;
     168              :     }
     169          181 :     if (NULL != auth->details.basic.password)
     170              :     {
     171          181 :       GNUNET_free (auth->details.basic.password);
     172          181 :       auth->details.basic.password = NULL;
     173              :     }
     174          181 :     break;
     175            0 :   case TALER_BANK_AUTH_BEARER:
     176            0 :     if (NULL != auth->details.bearer.token)
     177              :     {
     178            0 :       GNUNET_free (auth->details.bearer.token);
     179            0 :       auth->details.bearer.token = NULL;
     180              :     }
     181            0 :     break;
     182              :   }
     183              : 
     184          267 :   GNUNET_free (auth->wire_gateway_url);
     185          267 :   auth->wire_gateway_url = NULL;
     186          267 : }
     187              : 
     188              : 
     189              : /* end of bank_api_parse.c */
        

Generated by: LCOV version 2.0-1