LCOV - code coverage report
Current view: top level - util - config.c (source / functions) Hit Total Coverage
Test: GNU Taler exchange coverage report Lines: 8 52 15.4 %
Date: 2022-08-25 06:15:09 Functions: 1 3 33.3 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :   This file is part of TALER
       3             :   Copyright (C) 2014-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 <http://www.gnu.org/licenses/>
      15             : */
      16             : /**
      17             :  * @file config.c
      18             :  * @brief configuration parsing functions for Taler-specific data types
      19             :  * @author Florian Dold
      20             :  * @author Benedikt Mueller
      21             :  */
      22             : #include "platform.h"
      23             : #include "taler_util.h"
      24             : 
      25             : 
      26             : enum GNUNET_GenericReturnValue
      27           0 : TALER_config_get_amount (const struct GNUNET_CONFIGURATION_Handle *cfg,
      28             :                          const char *section,
      29             :                          const char *option,
      30             :                          struct TALER_Amount *denom)
      31             : {
      32             :   char *str;
      33             : 
      34           0 :   if (GNUNET_OK !=
      35           0 :       GNUNET_CONFIGURATION_get_value_string (cfg,
      36             :                                              section,
      37             :                                              option,
      38             :                                              &str))
      39             :   {
      40           0 :     GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
      41             :                                section,
      42             :                                option);
      43           0 :     return GNUNET_NO;
      44             :   }
      45           0 :   if (GNUNET_OK !=
      46           0 :       TALER_string_to_amount (str,
      47             :                               denom))
      48             :   {
      49           0 :     GNUNET_free (str);
      50           0 :     GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR,
      51             :                                section,
      52             :                                option,
      53             :                                "invalid amount");
      54           0 :     return GNUNET_SYSERR;
      55             :   }
      56           0 :   GNUNET_free (str);
      57           0 :   return GNUNET_OK;
      58             : }
      59             : 
      60             : 
      61             : enum GNUNET_GenericReturnValue
      62           0 : TALER_config_get_denom_fees (const struct GNUNET_CONFIGURATION_Handle *cfg,
      63             :                              const char *currency,
      64             :                              const char *section,
      65             :                              struct TALER_DenomFeeSet *fees)
      66             : {
      67           0 :   if (GNUNET_OK !=
      68           0 :       TALER_config_get_amount (cfg,
      69             :                                section,
      70             :                                "FEE_WITHDRAW",
      71             :                                &fees->withdraw))
      72             :   {
      73           0 :     GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR,
      74             :                                "Need amount for option `%s' in section `%s'\n",
      75             :                                "FEE_WITHDRAW",
      76             :                                section);
      77           0 :     return GNUNET_SYSERR;
      78             :   }
      79           0 :   if (GNUNET_OK !=
      80           0 :       TALER_config_get_amount (cfg,
      81             :                                section,
      82             :                                "FEE_DEPOSIT",
      83             :                                &fees->deposit))
      84             :   {
      85           0 :     GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR,
      86             :                                "Need amount for option `%s' in section `%s'\n",
      87             :                                "FEE_DEPOSIT",
      88             :                                section);
      89           0 :     return GNUNET_SYSERR;
      90             :   }
      91           0 :   if (GNUNET_OK !=
      92           0 :       TALER_config_get_amount (cfg,
      93             :                                section,
      94             :                                "FEE_REFRESH",
      95             :                                &fees->refresh))
      96             :   {
      97           0 :     GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR,
      98             :                                "Need amount for option `%s' in section `%s'\n",
      99             :                                "FEE_REFRESH",
     100             :                                section);
     101           0 :     return GNUNET_SYSERR;
     102             :   }
     103           0 :   if (GNUNET_OK !=
     104           0 :       TALER_config_get_amount (cfg,
     105             :                                section,
     106             :                                "FEE_REFUND",
     107             :                                &fees->refund))
     108             :   {
     109           0 :     GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR,
     110             :                                "Need amount for option `%s' in section `%s'\n",
     111             :                                "FEE_REFUND",
     112             :                                section);
     113           0 :     return GNUNET_SYSERR;
     114             :   }
     115           0 :   if (GNUNET_OK !=
     116           0 :       TALER_denom_fee_check_currency (currency,
     117             :                                       fees))
     118             :   {
     119           0 :     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
     120             :                 "Need fee amounts in section `%s' to use currency `%s'\n",
     121             :                 section,
     122             :                 currency);
     123           0 :     return GNUNET_SYSERR;
     124             :   }
     125           0 :   return GNUNET_OK;
     126             : }
     127             : 
     128             : 
     129             : enum GNUNET_GenericReturnValue
     130          26 : TALER_config_get_currency (const struct GNUNET_CONFIGURATION_Handle *cfg,
     131             :                            char **currency)
     132             : {
     133             :   size_t slen;
     134             : 
     135          26 :   if (GNUNET_OK !=
     136          26 :       GNUNET_CONFIGURATION_get_value_string (cfg,
     137             :                                              "taler",
     138             :                                              "CURRENCY",
     139             :                                              currency))
     140             :   {
     141           0 :     GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
     142             :                                "taler",
     143             :                                "CURRENCY");
     144           0 :     return GNUNET_SYSERR;
     145             :   }
     146          26 :   slen = strlen (*currency);
     147          26 :   if (slen >= TALER_CURRENCY_LEN)
     148             :   {
     149           0 :     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
     150             :                 "Currency `%s' longer than the allowed limit of %u characters.",
     151             :                 *currency,
     152             :                 (unsigned int) TALER_CURRENCY_LEN);
     153           0 :     GNUNET_free (*currency);
     154           0 :     *currency = NULL;
     155           0 :     return GNUNET_SYSERR;
     156             :   }
     157         114 :   for (size_t i = 0; i<slen; i++)
     158          88 :     if (! isalpha ((unsigned char) (*currency)[i]))
     159             :     {
     160           0 :       GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
     161             :                   "Currency `%s' must only use characters from the A-Z range.",
     162             :                   *currency);
     163           0 :       GNUNET_free (*currency);
     164           0 :       *currency = NULL;
     165           0 :       return GNUNET_SYSERR;
     166             :     }
     167          26 :   return GNUNET_OK;
     168             : }

Generated by: LCOV version 1.14