exchange

Base system with REST service to issue digital coins, run by the payment service provider
Log | Files | Refs | Submodules | README | LICENSE

commit 285ba92711f4998966b7be3615823c50a6ebcdd1
parent 5566b11d10e057c90e33870db395b583b2709364
Author: Christian Grothoff <christian@grothoff.org>
Date:   Sat, 20 Jul 2024 16:33:31 +0200

add logic to parse new_check field

Diffstat:
Msrc/include/taler_kyclogic_lib.h | 10+++++++---
Msrc/kyclogic/kyclogic_api.c | 44++++++++++++++++++++++++++++++++++++++++++++
Msrc/kyclogic/taler-exchange-kyc-tester.c | 56+++++++++++++++++++++++++++++++++++++-------------------
3 files changed, 88 insertions(+), 22 deletions(-)

diff --git a/src/include/taler_kyclogic_lib.h b/src/include/taler_kyclogic_lib.h @@ -514,12 +514,16 @@ struct TALER_KYCLOGIC_KycCheckContext * Obtain the provider logic for a given set of @a lrs * and a specific @a kyc_rule from @a lrs that was * triggered and the choosen @a measure_name from the - * list of measures of that @a kyc_rule. + * list of measures of that @a kyc_rule. Can also be + * used to obtain the "current" check of a @a lrs if + * no trigger has been hit. * * @param lrs rule set * @param kyc_rule rule that was triggered - * @param measure_name selected measure - * @param[out] kcc set to check to run + * @param measure_name selected measure, + * NULL to return the "new_check" set by the @a lrs + * @param[out] kcc set to check to run; + * kcc->check will be NULL if the "skip" check is used * @return #GNUNET_OK on success, #GNUNET_SYSERR on error */ enum GNUNET_GenericReturnValue diff --git a/src/kyclogic/kyclogic_api.c b/src/kyclogic/kyclogic_api.c @@ -176,6 +176,13 @@ struct TALER_KYCLOGIC_LegitimizationRuleSet char *successor_measure; /** + * Name of the check that becomes active when this + * measure is triggered. + * NULL for no check (allowed, but should be rare). + */ + char *new_check; + + /** * Array of the rules. */ struct TALER_KYCLOGIC_KycRule *kyc_rules; @@ -385,6 +392,7 @@ TALER_KYCLOGIC_rules_parse (const json_t *jlrs) struct GNUNET_TIME_Timestamp expiration_time; const char *successor_measure = NULL; const json_t *jrules; + const char *new_check = NULL; const json_t *jcustom_measures = NULL; struct GNUNET_JSON_Specification spec[] = { GNUNET_JSON_spec_timestamp ( @@ -395,6 +403,11 @@ TALER_KYCLOGIC_rules_parse (const json_t *jlrs) "successor_measure", &successor_measure), NULL), + GNUNET_JSON_spec_mark_optional ( + GNUNET_JSON_spec_string ( + "new_check", + &new_check), + NULL), GNUNET_JSON_spec_array_const ("rules", &jrules), GNUNET_JSON_spec_mark_optional ( @@ -419,6 +432,10 @@ TALER_KYCLOGIC_rules_parse (const json_t *jlrs) = (NULL == successor_measure) ? NULL : GNUNET_strdup (successor_measure); + lrs->new_check + = (NULL == new_check) + ? NULL + : GNUNET_strdup (new_check); lrs->num_kyc_rules = (unsigned int) json_array_size (jrules); if (((size_t) lrs->num_kyc_rules) != @@ -605,6 +622,7 @@ TALER_KYCLOGIC_rules_free (struct TALER_KYCLOGIC_LegitimizationRuleSet *lrs) GNUNET_free (lrs->kyc_rules); GNUNET_free (lrs->custom_measures); GNUNET_free (lrs->successor_measure); + GNUNET_free (lrs->new_check); GNUNET_free (lrs); } @@ -2230,6 +2248,23 @@ TALER_KYCLOGIC_requirements_to_check ( bool found = false; const struct TALER_KYCLOGIC_Measure *measure = NULL; + if (NULL == measure_name) + { + /* No measure selected, return the "new_check" */ + if (0 != strcasecmp (lrs->new_check, + "SKIP")) + { + kcc->check = find_check (lrs->new_check); + GNUNET_break (NULL != kcc->check); + } + else + { + kcc->check =NULL; + } + kcc->prog_name = measure->prog_name; + kcc->context = measure->context; + return GNUNET_OK; + } for (unsigned int i = 0; i<kyc_rule->num_measures; i++) { if (0 != strcmp (measure_name, @@ -2263,6 +2298,15 @@ TALER_KYCLOGIC_requirements_to_check ( return GNUNET_SYSERR; } + if (0 == strcasecmp (measure->check_name, + "SKIP")) + { + kcc->check = NULL; + kcc->prog_name = measure->prog_name; + kcc->context = measure->context; + return GNUNET_OK; + } + for (unsigned int i = 0; i<num_kyc_checks; i++) if (0 == strcmp (measure->check_name, kyc_checks[i]->check_name)) diff --git a/src/kyclogic/taler-exchange-kyc-tester.c b/src/kyclogic/taler-exchange-kyc-tester.c @@ -283,6 +283,11 @@ static int print_h_payto; static int run_webservice; /** + * -M command-line option. + */ +static int list_measures; + +/** * Value to return from main() */ static int global_ret; @@ -1614,10 +1619,10 @@ run (void *cls, { struct TALER_KYCLOGIC_KycCheckContext kcc; - if (NULL == measure) + if (0 != list_measures) { // FIXME: print rule with possible measures! - + GNUNET_break (0); global_ret = EXIT_SUCCESS; GNUNET_SCHEDULER_shutdown (); return; @@ -1636,6 +1641,14 @@ run (void *cls, GNUNET_SCHEDULER_shutdown (); return; } + if (NULL == kcc.check) + { + GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, + "SKIP check selected, nothing to do here\n"); + global_ret = EXIT_SUCCESS; + GNUNET_SCHEDULER_shutdown (); + return; + } switch (kcc.check->type) { case TALER_KYCLOGIC_CT_INFO: @@ -1742,6 +1755,11 @@ main (int argc, const struct GNUNET_GETOPT_CommandLineOption options[] = { GNUNET_GETOPT_option_help ( "tool to test KYC provider integrations"), + GNUNET_GETOPT_option_flag ( + 'M', + "list-measures", + "list available measures", + &list_measures), GNUNET_GETOPT_option_string ( 'm', "measure", @@ -1754,6 +1772,11 @@ main (int argc, "OPERATION_TYPE", "name of the operation that triggers legitimization (WITHDRAW, DEPOSIT, etc.)", &operation_s), + GNUNET_GETOPT_option_flag ( + 'P', + "print-payto-hash", + "output the hash of the payto://-URI", + &print_h_payto), GNUNET_GETOPT_option_base32_fixed_size ( 'p', "payto-hash", @@ -1761,23 +1784,18 @@ main (int argc, "base32 encoding of the hash of a payto://-URI to use for the account (otherwise a random value will be used)", &cmd_line_h_payto, sizeof (cmd_line_h_payto)), - GNUNET_GETOPT_option_flag ( - 'P', - "print-payto-hash", - "output the hash of the payto://-URI", - &print_h_payto), - GNUNET_GETOPT_option_uint ( - 'r', - "rowid", - "NUMBER", - "override row ID to use in simulation (default: 42)", - &kyc_row_id), GNUNET_GETOPT_option_string ( 'R', "ruleset", "JSON", "use the given legitimization rule set (otherwise defaults from configuration are used)", &lrs_s), + GNUNET_GETOPT_option_uint ( + 'r', + "rowid", + "NUMBER", + "override row ID to use in simulation (default: 42)", + &kyc_row_id), TALER_getopt_get_amount ( 't', "trigger", @@ -1785,17 +1803,17 @@ main (int argc, "threshold crossed that would trigger some legitimization rule", &trigger_amount), GNUNET_GETOPT_option_string ( - 'u', - "user", - "ID", - "use the given provider user ID (overridden if -i is also used)", - &cmd_provider_user_id), - GNUNET_GETOPT_option_string ( 'U', "legitimization", "ID", "use the given provider legitimization ID (overridden if -i is also used)", &cmd_provider_legitimization_id), + GNUNET_GETOPT_option_string ( + 'u', + "user", + "ID", + "use the given provider user ID (overridden if -i is also used)", + &cmd_provider_user_id), GNUNET_GETOPT_option_flag ( 'w', "run-webservice",