LCOV - code coverage report
Current view: top level - lib - exchange_api_restrictions.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 0.0 % 62 0
Test Date: 2026-09-09 15:11:34 Functions: 0.0 % 3 0

            Line data    Source code
       1              : /*
       2              :   This file is part of TALER
       3              :   Copyright (C) 2024 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 lib/exchange_api_restrictions.c
      19              :  * @brief convenience functions related to account restrictions
      20              :  * @author Christian Grothoff
      21              :  */
      22              : #include "taler/taler_exchange_service.h"
      23              : #include <regex.h>
      24              : 
      25              : 
      26              : enum GNUNET_GenericReturnValue
      27            0 : TALER_EXCHANGE_test_account_allowed (
      28              :   const struct TALER_EXCHANGE_WireAccount *account,
      29              :   bool check_credit,
      30              :   const struct TALER_NormalizedPayto payto_uri)
      31              : {
      32            0 :   unsigned int limit
      33              :     = check_credit
      34              :     ? account->credit_restrictions_length
      35            0 :     : account->debit_restrictions_length;
      36              : 
      37              :   /* check wire method matches */
      38              :   {
      39              :     char *wm1;
      40              :     char *wm2;
      41              :     bool ok;
      42              : 
      43            0 :     wm1 = TALER_payto_get_method (payto_uri.normalized_payto);
      44            0 :     if (NULL == wm1)
      45              :     {
      46            0 :       GNUNET_break (0);
      47            0 :       GNUNET_free (wm1);
      48            0 :       return GNUNET_SYSERR;
      49              :     }
      50            0 :     wm2 = TALER_payto_get_method (account->fpayto_uri.full_payto);
      51            0 :     if (NULL == wm2)
      52              :     {
      53            0 :       GNUNET_break (0);
      54            0 :       return GNUNET_SYSERR;
      55              :     }
      56            0 :     ok = (0 == strcmp (wm1,
      57              :                        wm2));
      58            0 :     GNUNET_free (wm1);
      59            0 :     GNUNET_free (wm2);
      60            0 :     if (! ok)
      61            0 :       return GNUNET_NO;
      62              :   }
      63              : 
      64            0 :   for (unsigned int i = 0; i<limit; i++)
      65              :   {
      66            0 :     const struct TALER_EXCHANGE_AccountRestriction *ar
      67              :       = check_credit
      68            0 :       ? &account->credit_restrictions[i]
      69            0 :       : &account->debit_restrictions[i];
      70              : 
      71            0 :     switch (ar->type)
      72              :     {
      73            0 :     case TALER_EXCHANGE_AR_INVALID:
      74            0 :       GNUNET_break (0);
      75            0 :       return GNUNET_SYSERR;
      76            0 :     case TALER_EXCHANGE_AR_DENY:
      77            0 :       return GNUNET_NO;
      78            0 :     case TALER_EXCHANGE_AR_REGEX:
      79              :       {
      80              :         regex_t ex;
      81            0 :         bool allowed = false;
      82              : 
      83            0 :         if (0 != regcomp (&ex,
      84            0 :                           ar->details.regex.posix_egrep,
      85              :                           REG_NOSUB | REG_EXTENDED))
      86              :         {
      87            0 :           GNUNET_break_op (0);
      88            0 :           return GNUNET_SYSERR;
      89              :         }
      90            0 :         if (0 ==
      91            0 :             regexec (&ex,
      92            0 :                      payto_uri.normalized_payto,
      93              :                      0, NULL,
      94              :                      0))
      95              :         {
      96            0 :           GNUNET_log (GNUNET_ERROR_TYPE_INFO,
      97              :                       "Account `%s' allowed by regex\n",
      98              :                       payto_uri.normalized_payto);
      99            0 :           allowed = true;
     100              :         }
     101            0 :         regfree (&ex);
     102            0 :         if (! allowed)
     103            0 :           return GNUNET_NO;
     104            0 :         break;
     105              :       }
     106              :     }     /* end switch */
     107              :   }     /* end loop over restrictions */
     108            0 :   return GNUNET_YES;
     109              : }
     110              : 
     111              : 
     112              : void
     113            0 : TALER_EXCHANGE_keys_evaluate_hard_limits (
     114              :   const struct TALER_EXCHANGE_Keys *keys,
     115              :   enum TALER_KYCLOGIC_KycTriggerEvent event,
     116              :   struct TALER_Amount *limit)
     117              : {
     118            0 :   for (unsigned int i = 0; i<keys->hard_limits_length; i++)
     119              :   {
     120            0 :     const struct TALER_EXCHANGE_AccountLimit *al
     121            0 :       = &keys->hard_limits[i];
     122              : 
     123            0 :     if (event != al->operation_type)
     124            0 :       continue;
     125            0 :     if (al->soft_limit)
     126            0 :       continue;
     127            0 :     if (! TALER_amount_cmp_currency (limit,
     128              :                                      &al->threshold))
     129            0 :       continue;
     130            0 :     GNUNET_break (GNUNET_OK ==
     131              :                   TALER_amount_min (limit,
     132              :                                     limit,
     133              :                                     &al->threshold));
     134              :   }
     135            0 : }
     136              : 
     137              : 
     138              : bool
     139            0 : TALER_EXCHANGE_keys_evaluate_zero_limits (
     140              :   const struct TALER_EXCHANGE_Keys *keys,
     141              :   enum TALER_KYCLOGIC_KycTriggerEvent event)
     142              : {
     143            0 :   for (unsigned int i = 0; i<keys->zero_limits_length; i++)
     144              :   {
     145            0 :     const struct TALER_EXCHANGE_ZeroLimitedOperation *zlo
     146            0 :       = &keys->zero_limits[i];
     147              : 
     148            0 :     if (event == zlo->operation_type)
     149            0 :       return true;
     150              :   }
     151            0 :   return false;
     152              : }
        

Generated by: LCOV version 2.0-1