aboutsummaryrefslogtreecommitdiff
path: root/src/exchange-tools/taler-exchange-offline.c
diff options
context:
space:
mode:
authorÖzgür Kesim <oec-taler@kesim.org>2022-10-02 18:05:58 +0200
committerÖzgür Kesim <oec-taler@kesim.org>2022-10-02 18:05:58 +0200
commit04c7e0bb337dd88dde60293d94d2e192a8fc2ff5 (patch)
treebff69b52b8d07be2442dde6ca86a3df2776b2e67 /src/exchange-tools/taler-exchange-offline.c
parent165b85ddd59ce4af9b3f28409b6210d8f688f17d (diff)
Refactor extensions
- Extensions are now compiled as shared libraries and loaded at runtime according to the TALER configuration. - So far, only age restriction is loaded as extension. - Groundwork for extension auction_brandt started.
Diffstat (limited to 'src/exchange-tools/taler-exchange-offline.c')
-rw-r--r--src/exchange-tools/taler-exchange-offline.c89
1 files changed, 51 insertions, 38 deletions
diff --git a/src/exchange-tools/taler-exchange-offline.c b/src/exchange-tools/taler-exchange-offline.c
index 60a39df9..e7cb94b5 100644
--- a/src/exchange-tools/taler-exchange-offline.c
+++ b/src/exchange-tools/taler-exchange-offline.c
@@ -138,6 +138,11 @@ static struct GNUNET_CURL_RescheduleContext *rc;
static const struct GNUNET_CONFIGURATION_Handle *kcfg;
/**
+ * Age restriction configuration
+ */
+static struct TALER_AgeRestrictionConfig ar_config = {0};
+
+/**
* Return value from main().
*/
static int global_ret;
@@ -164,11 +169,6 @@ static char *currency;
static char *CFG_exchange_url;
/**
- * If age restriction is enabled, the age mask to be used
- */
-static struct TALER_AgeMask age_mask = {0};
-
-/**
* A subcommand supported by this program.
*/
struct SubCommand
@@ -2386,6 +2386,7 @@ do_upload (char *const *args)
return;
}
trigger_upload (CFG_exchange_url);
+
json_decref (out);
out = NULL;
}
@@ -3888,7 +3889,7 @@ load_age_mask (const char*section_name)
static const struct TALER_AgeMask null_mask = {0};
enum GNUNET_GenericReturnValue ret;
- if (age_mask.bits == 0)
+ if (! ar_config.enabled)
return null_mask;
if (GNUNET_OK != (GNUNET_CONFIGURATION_have_value (
@@ -3900,14 +3901,14 @@ load_age_mask (const char*section_name)
ret = GNUNET_CONFIGURATION_get_value_yesno (kcfg,
section_name,
"AGE_RESTRICTED");
- if (GNUNET_YES == ret)
- return age_mask;
-
if (GNUNET_SYSERR == ret)
GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR,
section_name,
"AGE_RESTRICTED",
"Value must be YES or NO\n");
+ if (GNUNET_YES == ret)
+ return ar_config.mask;
+
return null_mask;
}
@@ -4248,7 +4249,7 @@ do_setup (char *const *args)
static void
do_extensions_show (char *const *args)
{
- const struct TALER_Extension *it;
+ const struct TALER_Extensions *it;
json_t *exts = json_object ();
json_t *obj;
@@ -4258,8 +4259,9 @@ do_extensions_show (char *const *args)
it = it->next)
GNUNET_assert (0 ==
json_object_set_new (exts,
- it->name,
- it->config_to_json (it)));
+ it->extension->name,
+ it->extension->config_to_json (
+ it->extension)));
obj = GNUNET_JSON_PACK (
GNUNET_JSON_pack_object_steal ("extensions",
exts));
@@ -4268,7 +4270,7 @@ do_extensions_show (char *const *args)
json_dumps (obj,
JSON_INDENT (2)));
json_decref (obj);
- next (args + 1);
+ next (args);
}
@@ -4281,25 +4283,29 @@ do_extensions_sign (char *const *args)
json_t *extensions = json_object ();
struct TALER_ExtensionConfigHashP h_config;
struct TALER_MasterSignatureP sig;
- const struct TALER_Extension *it;
+ const struct TALER_Extensions *it;
+ bool found = false;
json_t *obj;
GNUNET_assert (NULL != extensions);
- if (GNUNET_OK !=
- TALER_extensions_load_taler_config (kcfg))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "error while loading taler config for extensions\n");
- json_decref (extensions);
- return;
- }
for (it = TALER_extensions_get_head ();
NULL != it;
it = it->next)
+ {
+ const struct TALER_Extension *ext = it->extension;
+ GNUNET_assert (ext);
+
+ found = true;
+
GNUNET_assert (0 ==
json_object_set_new (extensions,
- it->name,
- it->config_to_json (it)));
+ ext->name,
+ ext->config_to_json (
+ ext)));
+ }
+
+ if (! found)
+ return;
if (GNUNET_OK !=
TALER_JSON_extensions_config_hash (extensions,
@@ -4327,9 +4333,10 @@ do_extensions_sign (char *const *args)
GNUNET_JSON_pack_data_auto (
"extensions_sig",
&sig));
+
output_operation (OP_EXTENSIONS,
obj);
- next (args + 1);
+ next (args);
}
@@ -4396,6 +4403,7 @@ do_work_extensions (char *const *args)
}
};
+
if (NULL == args[0])
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -4530,6 +4538,24 @@ run (void *cls,
(void) cls;
(void) cfgfile;
kcfg = cfg;
+
+
+ /* load extensions */
+ GNUNET_assert (GNUNET_OK ==
+ TALER_extensions_load (kcfg));
+
+ /* setup age restriction, if applicable */
+ {
+ const struct TALER_AgeRestrictionConfig *arc;
+
+ if (NULL !=
+ (arc = TALER_extensions_get_age_restriction_config ()))
+ {
+ ar_config = *arc;
+ ar_config.enabled = true;
+ }
+ }
+
if (GNUNET_OK !=
TALER_config_get_currency (kcfg,
&currency))
@@ -4538,18 +4564,6 @@ run (void *cls,
return;
}
- /* load age mask, if age restriction is enabled */
- GNUNET_assert (GNUNET_OK ==
- TALER_extension_age_restriction_register ());
-
- if (GNUNET_OK != TALER_extensions_load_taler_config (kcfg))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "error while loading taler config for extensions\n");
- return;
- }
- age_mask = TALER_extensions_age_restriction_ageMask ();
-
ctx = GNUNET_CURL_init (&GNUNET_CURL_gnunet_scheduler_reschedule,
&rc);
rc = GNUNET_CURL_gnunet_rc_create (ctx);
@@ -4579,7 +4593,6 @@ main (int argc,
GNUNET_GETOPT_OPTION_END
};
enum GNUNET_GenericReturnValue ret;
-
/* force linker to link against libtalerutil; if we do
not do this, the linker may "optimize" libtalerutil
away and skip #TALER_OS_init(), which we do need */