LCOV - code coverage report
Current view: top level - util - config.c (source / functions) Hit Total Coverage
Test: GNU Taler exchange coverage report Lines: 12 23 52.2 %
Date: 2021-08-30 06:43:37 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) 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             : /**
      27             :  * Obtain denomination amount from configuration file.
      28             :  *
      29             :  * @param cfg configuration to use
      30             :  * @param section section of the configuration to access
      31             :  * @param option option of the configuration to access
      32             :  * @param[out] denom set to the amount found in configuration
      33             :  * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
      34             :  */
      35             : int
      36        1725 : TALER_config_get_amount (const struct GNUNET_CONFIGURATION_Handle *cfg,
      37             :                          const char *section,
      38             :                          const char *option,
      39             :                          struct TALER_Amount *denom)
      40             : {
      41             :   char *str;
      42             : 
      43        1725 :   if (GNUNET_OK !=
      44        1725 :       GNUNET_CONFIGURATION_get_value_string (cfg,
      45             :                                              section,
      46             :                                              option,
      47             :                                              &str))
      48             :   {
      49           0 :     GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
      50             :                                section,
      51             :                                option);
      52           0 :     return GNUNET_NO;
      53             :   }
      54        1725 :   if (GNUNET_OK !=
      55        1725 :       TALER_string_to_amount (str,
      56             :                               denom))
      57             :   {
      58           0 :     GNUNET_free (str);
      59           0 :     GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR,
      60             :                                section,
      61             :                                option,
      62             :                                "valid amount");
      63           0 :     return GNUNET_SYSERR;
      64             :   }
      65        1725 :   GNUNET_free (str);
      66        1725 :   return GNUNET_OK;
      67             : }
      68             : 
      69             : 
      70             : /**
      71             :  * Load our currency from the @a cfg (in section [taler]
      72             :  * the option "CURRENCY").
      73             :  *
      74             :  * @param cfg configuration to use
      75             :  * @param[out] currency where to write the result
      76             :  * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
      77             :  */
      78             : int
      79        1579 : TALER_config_get_currency (const struct GNUNET_CONFIGURATION_Handle *cfg,
      80             :                            char **currency)
      81             : {
      82        1579 :   if (GNUNET_OK !=
      83        1579 :       GNUNET_CONFIGURATION_get_value_string (cfg,
      84             :                                              "taler",
      85             :                                              "CURRENCY",
      86             :                                              currency))
      87             :   {
      88           0 :     GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
      89             :                                "taler",
      90             :                                "CURRENCY");
      91           0 :     return GNUNET_SYSERR;
      92             :   }
      93        1579 :   if (strlen (*currency) >= TALER_CURRENCY_LEN)
      94             :   {
      95           0 :     fprintf (stderr,
      96             :              "Currency `%s' longer than the allowed limit of %u characters.",
      97             :              *currency,
      98             :              (unsigned int) TALER_CURRENCY_LEN);
      99           0 :     GNUNET_free (*currency);
     100           0 :     *currency = NULL;
     101           0 :     return GNUNET_SYSERR;
     102             :   }
     103        1579 :   return GNUNET_OK;
     104             : }

Generated by: LCOV version 1.14