LCOV - code coverage report
Current view: top level - util - util.c (source / functions) Hit Total Coverage
Test: GNU Taler exchange coverage report Lines: 7 84 8.3 %
Date: 2022-08-25 06:15:09 Functions: 1 10 10.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 util.c
      18             :  * @brief Common utility functions
      19             :  * @author Sree Harsha Totakura <sreeharsha@totakura.in>
      20             :  * @author Florian Dold
      21             :  * @author Benedikt Mueller
      22             :  */
      23             : #include "platform.h"
      24             : #include "taler_util.h"
      25             : 
      26             : 
      27             : const char *
      28         134 : TALER_b2s (const void *buf,
      29             :            size_t buf_size)
      30             : {
      31             :   static GNUNET_THREAD_LOCAL char ret[9];
      32             :   struct GNUNET_HashCode hc;
      33             :   char *tmp;
      34             : 
      35         134 :   GNUNET_CRYPTO_hash (buf,
      36             :                       buf_size,
      37             :                       &hc);
      38         134 :   tmp = GNUNET_STRINGS_data_to_string_alloc (&hc,
      39             :                                              sizeof (hc));
      40         134 :   memcpy (ret,
      41             :           tmp,
      42             :           8);
      43         134 :   GNUNET_free (tmp);
      44         134 :   ret[8] = '\0';
      45         134 :   return ret;
      46             : }
      47             : 
      48             : 
      49             : void
      50           0 : TALER_denom_fee_set_hton (struct TALER_DenomFeeSetNBOP *nbo,
      51             :                           const struct TALER_DenomFeeSet *fees)
      52             : {
      53           0 :   TALER_amount_hton (&nbo->withdraw,
      54             :                      &fees->withdraw);
      55           0 :   TALER_amount_hton (&nbo->deposit,
      56             :                      &fees->deposit);
      57           0 :   TALER_amount_hton (&nbo->refresh,
      58             :                      &fees->refresh);
      59           0 :   TALER_amount_hton (&nbo->refund,
      60             :                      &fees->refund);
      61           0 : }
      62             : 
      63             : 
      64             : void
      65           0 : TALER_denom_fee_set_ntoh (struct TALER_DenomFeeSet *fees,
      66             :                           const struct TALER_DenomFeeSetNBOP *nbo)
      67             : {
      68           0 :   TALER_amount_ntoh (&fees->withdraw,
      69             :                      &nbo->withdraw);
      70           0 :   TALER_amount_ntoh (&fees->deposit,
      71             :                      &nbo->deposit);
      72           0 :   TALER_amount_ntoh (&fees->refresh,
      73             :                      &nbo->refresh);
      74           0 :   TALER_amount_ntoh (&fees->refund,
      75             :                      &nbo->refund);
      76           0 : }
      77             : 
      78             : 
      79             : void
      80           0 : TALER_global_fee_set_hton (struct TALER_GlobalFeeSetNBOP *nbo,
      81             :                            const struct TALER_GlobalFeeSet *fees)
      82             : {
      83           0 :   TALER_amount_hton (&nbo->history,
      84             :                      &fees->history);
      85           0 :   TALER_amount_hton (&nbo->kyc,
      86             :                      &fees->kyc);
      87           0 :   TALER_amount_hton (&nbo->account,
      88             :                      &fees->account);
      89           0 :   TALER_amount_hton (&nbo->purse,
      90             :                      &fees->purse);
      91           0 : }
      92             : 
      93             : 
      94             : void
      95           0 : TALER_global_fee_set_ntoh (struct TALER_GlobalFeeSet *fees,
      96             :                            const struct TALER_GlobalFeeSetNBOP *nbo)
      97             : {
      98           0 :   TALER_amount_ntoh (&fees->history,
      99             :                      &nbo->history);
     100           0 :   TALER_amount_ntoh (&fees->kyc,
     101             :                      &nbo->kyc);
     102           0 :   TALER_amount_ntoh (&fees->account,
     103             :                      &nbo->account);
     104           0 :   TALER_amount_ntoh (&fees->purse,
     105             :                      &nbo->purse);
     106           0 : }
     107             : 
     108             : 
     109             : void
     110           0 : TALER_wire_fee_set_hton (struct TALER_WireFeeSetNBOP *nbo,
     111             :                          const struct TALER_WireFeeSet *fees)
     112             : {
     113           0 :   TALER_amount_hton (&nbo->wire,
     114             :                      &fees->wire);
     115           0 :   TALER_amount_hton (&nbo->closing,
     116             :                      &fees->closing);
     117           0 :   TALER_amount_hton (&nbo->wad,
     118             :                      &fees->wad);
     119           0 : }
     120             : 
     121             : 
     122             : void
     123           0 : TALER_wire_fee_set_ntoh (struct TALER_WireFeeSet *fees,
     124             :                          const struct TALER_WireFeeSetNBOP *nbo)
     125             : {
     126           0 :   TALER_amount_ntoh (&fees->wire,
     127             :                      &nbo->wire);
     128           0 :   TALER_amount_ntoh (&fees->closing,
     129             :                      &nbo->closing);
     130           0 :   TALER_amount_ntoh (&fees->wad,
     131             :                      &nbo->wad);
     132           0 : }
     133             : 
     134             : 
     135             : int
     136           0 : TALER_global_fee_set_cmp (const struct TALER_GlobalFeeSet *f1,
     137             :                           const struct TALER_GlobalFeeSet *f2)
     138             : {
     139             :   int ret;
     140             : 
     141           0 :   ret = TALER_amount_cmp (&f1->history,
     142             :                           &f2->history);
     143           0 :   if (0 != ret)
     144           0 :     return ret;
     145           0 :   ret = TALER_amount_cmp (&f1->kyc,
     146             :                           &f2->kyc);
     147           0 :   if (0 != ret)
     148           0 :     return ret;
     149           0 :   ret = TALER_amount_cmp (&f1->account,
     150             :                           &f2->account);
     151           0 :   if (0 != ret)
     152           0 :     return ret;
     153           0 :   ret = TALER_amount_cmp (&f1->purse,
     154             :                           &f2->purse);
     155           0 :   if (0 != ret)
     156           0 :     return ret;
     157           0 :   return 0;
     158             : }
     159             : 
     160             : 
     161             : int
     162           0 : TALER_wire_fee_set_cmp (const struct TALER_WireFeeSet *f1,
     163             :                         const struct TALER_WireFeeSet *f2)
     164             : {
     165             :   int ret;
     166             : 
     167           0 :   ret = TALER_amount_cmp (&f1->wire,
     168             :                           &f2->wire);
     169           0 :   if (0 != ret)
     170           0 :     return ret;
     171           0 :   ret = TALER_amount_cmp (&f1->closing,
     172             :                           &f2->closing);
     173           0 :   if (0 != ret)
     174           0 :     return ret;
     175           0 :   ret = TALER_amount_cmp (&f1->wad,
     176             :                           &f2->wad);
     177           0 :   if (0 != ret)
     178           0 :     return ret;
     179           0 :   return 0;
     180             : }
     181             : 
     182             : 
     183             : enum GNUNET_GenericReturnValue
     184           0 : TALER_denom_fee_check_currency (
     185             :   const char *currency,
     186             :   const struct TALER_DenomFeeSet *fees)
     187             : {
     188           0 :   if (GNUNET_YES !=
     189           0 :       TALER_amount_is_currency (&fees->withdraw,
     190             :                                 currency))
     191             :   {
     192           0 :     GNUNET_break (0);
     193           0 :     return GNUNET_NO;
     194             :   }
     195           0 :   if (GNUNET_YES !=
     196           0 :       TALER_amount_is_currency (&fees->deposit,
     197             :                                 currency))
     198             :   {
     199           0 :     GNUNET_break (0);
     200           0 :     return GNUNET_NO;
     201             :   }
     202           0 :   if (GNUNET_YES !=
     203           0 :       TALER_amount_is_currency (&fees->refresh,
     204             :                                 currency))
     205             :   {
     206           0 :     GNUNET_break (0);
     207           0 :     return GNUNET_NO;
     208             :   }
     209           0 :   if (GNUNET_YES !=
     210           0 :       TALER_amount_is_currency (&fees->refund,
     211             :                                 currency))
     212             :   {
     213           0 :     GNUNET_break (0);
     214           0 :     return GNUNET_NO;
     215             :   }
     216           0 :   return GNUNET_OK;
     217             : }
     218             : 
     219             : 
     220             : #ifdef __APPLE__
     221             : char *
     222             : strchrnul (const char *s,
     223             :            int c)
     224             : {
     225             :   char *value;
     226             :   value = strchr (s,
     227             :                   c);
     228             :   if (NULL == value)
     229             :     value = &s[strlen (s)];
     230             :   return value;
     231             : }
     232             : 
     233             : 
     234             : #endif
     235             : 
     236             : 
     237             : /* end of util.c */

Generated by: LCOV version 1.14