LCOV - code coverage report
Current view: top level - bank-lib - bank_api_parse.c (source / functions) Hit Total Coverage
Test: GNU Taler exchange coverage report Lines: 24 53 45.3 %
Date: 2022-08-25 06:15:09 Functions: 2 2 100.0 %
Legend: Lines: hit not hit

          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 "platform.h"
      23             : #include "taler_bank_service.h"
      24             : 
      25             : 
      26             : enum GNUNET_GenericReturnValue
      27           1 : 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           1 :   } methods[] = {
      36             :     { "NONE",  TALER_BANK_AUTH_NONE  },
      37             :     { "BASIC", TALER_BANK_AUTH_BASIC },
      38             :     { NULL, TALER_BANK_AUTH_NONE     }
      39             :   };
      40             :   char *method;
      41             : 
      42           1 :   if (GNUNET_OK !=
      43           1 :       GNUNET_CONFIGURATION_get_value_string (cfg,
      44             :                                              section,
      45             :                                              "WIRE_GATEWAY_URL",
      46             :                                              &auth->wire_gateway_url))
      47             :   {
      48           0 :     GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
      49             :                                section,
      50             :                                "WIRE_GATEWAY_URL");
      51           0 :     return GNUNET_SYSERR;
      52             :   }
      53             : 
      54           1 :   if (GNUNET_OK !=
      55           1 :       GNUNET_CONFIGURATION_get_value_string (cfg,
      56             :                                              section,
      57             :                                              "WIRE_GATEWAY_AUTH_METHOD",
      58             :                                              &method))
      59             :   {
      60           0 :     GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
      61             :                                section,
      62             :                                "WIRE_GATEWAY_AUTH_METHOD");
      63           0 :     GNUNET_free (auth->wire_gateway_url);
      64           0 :     return GNUNET_SYSERR;
      65             :   }
      66           2 :   for (unsigned int i = 0; NULL != methods[i].m; i++)
      67             :   {
      68           2 :     if (0 == strcasecmp (method,
      69             :                          methods[i].m))
      70             :     {
      71           1 :       switch (methods[i].e)
      72             :       {
      73           0 :       case TALER_BANK_AUTH_NONE:
      74           0 :         auth->method = TALER_BANK_AUTH_NONE;
      75           0 :         GNUNET_free (method);
      76           0 :         return GNUNET_OK;
      77           1 :       case TALER_BANK_AUTH_BASIC:
      78           1 :         if (GNUNET_OK !=
      79           1 :             GNUNET_CONFIGURATION_get_value_string (cfg,
      80             :                                                    section,
      81             :                                                    "USERNAME",
      82             :                                                    &auth->details.basic.username))
      83             :         {
      84           0 :           GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
      85             :                                      section,
      86             :                                      "USERNAME");
      87           0 :           GNUNET_free (method);
      88           0 :           GNUNET_free (auth->wire_gateway_url);
      89           0 :           return GNUNET_SYSERR;
      90             :         }
      91           1 :         if (GNUNET_OK !=
      92           1 :             GNUNET_CONFIGURATION_get_value_string (cfg,
      93             :                                                    section,
      94             :                                                    "PASSWORD",
      95             :                                                    &auth->details.basic.password))
      96             :         {
      97           0 :           GNUNET_free (auth->details.basic.username);
      98           0 :           auth->details.basic.username = NULL;
      99           0 :           GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
     100             :                                      section,
     101             :                                      "PASSWORD");
     102           0 :           GNUNET_free (method);
     103           0 :           GNUNET_free (auth->wire_gateway_url);
     104           0 :           return GNUNET_SYSERR;
     105             :         }
     106           1 :         auth->method = TALER_BANK_AUTH_BASIC;
     107           1 :         GNUNET_free (method);
     108           1 :         return GNUNET_OK;
     109             :       }
     110             :     }
     111             :   }
     112           0 :   GNUNET_free (method);
     113           0 :   return GNUNET_SYSERR;
     114             : }
     115             : 
     116             : 
     117             : void
     118           4 : TALER_BANK_auth_free (struct TALER_BANK_AuthenticationData *auth)
     119             : {
     120           4 :   switch (auth->method)
     121             :   {
     122           4 :   case TALER_BANK_AUTH_NONE:
     123           4 :     break;
     124           0 :   case TALER_BANK_AUTH_BASIC:
     125           0 :     if (NULL != auth->details.basic.username)
     126             :     {
     127           0 :       GNUNET_free (auth->details.basic.username);
     128           0 :       auth->details.basic.username = NULL;
     129             :     }
     130           0 :     if (NULL != auth->details.basic.password)
     131             :     {
     132           0 :       GNUNET_free (auth->details.basic.password);
     133           0 :       auth->details.basic.password = NULL;
     134             :     }
     135           0 :     break;
     136             :   }
     137           4 :   GNUNET_free (auth->wire_gateway_url);
     138           4 :   auth->wire_gateway_url = NULL;
     139           4 : }
     140             : 
     141             : 
     142             : /* end of bank_api_parse.c */

Generated by: LCOV version 1.14