diff options
Diffstat (limited to 'src/extensions')
-rw-r--r-- | src/extensions/age_restriction/Makefile.am | 3 | ||||
-rw-r--r-- | src/extensions/age_restriction/age_restriction.c | 25 | ||||
-rw-r--r-- | src/extensions/extensions.c | 68 |
3 files changed, 55 insertions, 41 deletions
diff --git a/src/extensions/age_restriction/Makefile.am b/src/extensions/age_restriction/Makefile.am index 85d676538..bf5b2f5f5 100644 --- a/src/extensions/age_restriction/Makefile.am +++ b/src/extensions/age_restriction/Makefile.am @@ -18,12 +18,11 @@ plugin_LTLIBRARIES = \ libtaler_extension_age_restriction.la libtaler_extension_age_restriction_la_LDFLAGS = \ - -version-info 0:0:0 \ + $(TALER_PLUGIN_LDFLAGS) \ -no-undefined libtaler_extension_age_restriction_la_SOURCES = \ age_restriction.c - libtaler_extension_age_restriction_la_LIBADD = \ $(top_builddir)/src/json/libtalerjson.la \ $(top_builddir)/src/util/libtalerutil.la \ diff --git a/src/extensions/age_restriction/age_restriction.c b/src/extensions/age_restriction/age_restriction.c index 2d6d0cbd7..08b598d50 100644 --- a/src/extensions/age_restriction/age_restriction.c +++ b/src/extensions/age_restriction/age_restriction.c @@ -94,7 +94,7 @@ age_restriction_load_config ( ext->config = &AR_config; ext->enabled = true; - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + GNUNET_log (GNUNET_ERROR_TYPE_INFO, "loaded new age restriction config with age groups: %s\n", TALER_age_mask_to_string (&mask)); @@ -112,7 +112,6 @@ static json_t * age_restriction_manifest ( const struct TALER_Extension *ext) { - char *mask_str; json_t *conf; GNUNET_assert (NULL != ext); @@ -124,17 +123,17 @@ age_restriction_manifest ( return json_null (); } - mask_str = TALER_age_mask_to_string (&AR_config.mask); conf = GNUNET_JSON_PACK ( - GNUNET_JSON_pack_string ("age_groups", mask_str) + GNUNET_JSON_pack_string ("age_groups", + TALER_age_mask_to_string (&AR_config.mask)) ); - - free (mask_str); - return GNUNET_JSON_PACK ( - GNUNET_JSON_pack_bool ("critical", ext->critical), - GNUNET_JSON_pack_string ("version", ext->version), - GNUNET_JSON_pack_object_steal ("config", conf) + GNUNET_JSON_pack_bool ("critical", + ext->critical), + GNUNET_JSON_pack_string ("version", + ext->version), + GNUNET_JSON_pack_object_steal ("config", + conf) ); } @@ -207,10 +206,10 @@ libtaler_extension_age_restriction_init (void *arg) return NULL; } - mask.bits = TALER_EXTENSION_AGE_RESTRICTION_DEFAULT_AGE_MASK; + if (NULL == groups) + groups = GNUNET_strdup (TALER_EXTENSION_AGE_RESTRICTION_DEFAULT_AGE_GROUPS); - if ((groups != NULL) && - (GNUNET_OK != TALER_parse_age_group_string (groups, &mask))) + if (GNUNET_OK != TALER_parse_age_group_string (groups, &mask)) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[age restriction] couldn't parse age groups: '%s'\n", diff --git a/src/extensions/extensions.c b/src/extensions/extensions.c index fc361e08c..999e9317a 100644 --- a/src/extensions/extensions.c +++ b/src/extensions/extensions.c @@ -19,6 +19,7 @@ * @author Özgür Kesim */ #include "platform.h" +#include "taler_extensions_policy.h" #include "taler_util.h" #include "taler_signatures.h" #include "taler_extensions.h" @@ -138,7 +139,7 @@ TALER_extensions_get_by_name ( enum GNUNET_GenericReturnValue TALER_extensions_verify_manifests_signature ( - json_t *manifests, + const json_t *manifests, struct TALER_MasterSignatureP *extensions_sig, struct TALER_MasterPublicKeyP *master_pub) { @@ -184,7 +185,7 @@ configure_extension ( { struct LoadConfClosure *col = cls; const char *name; - char *lib_name; + char lib_name[1024] = {0}; struct TALER_Extension *extension; if (GNUNET_OK != col->error) @@ -199,17 +200,16 @@ configure_extension ( /* Load the extension library */ - GNUNET_asprintf (&lib_name, + GNUNET_snprintf (lib_name, + sizeof(lib_name), "libtaler_extension_%s", name); /* Lower-case extension name, config is case-insensitive */ for (unsigned int i = 0; i < strlen (lib_name); i++) - { lib_name[i] = tolower (lib_name[i]); - } - extension = GNUNET_PLUGIN_load ( - lib_name, - (void *) col->cfg); + + extension = GNUNET_PLUGIN_load (lib_name, + (void *) col->cfg); if (NULL == extension) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, @@ -274,72 +274,76 @@ TALER_extensions_parse_manifest ( json_t **config) { enum GNUNET_GenericReturnValue ret; - json_t *cfg; struct GNUNET_JSON_Specification spec[] = { GNUNET_JSON_spec_boolean ("critical", critical), GNUNET_JSON_spec_string ("version", version), GNUNET_JSON_spec_json ("config", - &cfg), + config), GNUNET_JSON_spec_end () }; + *config = NULL; if (GNUNET_OK != (ret = GNUNET_JSON_parse (obj, spec, NULL, NULL))) return ret; - - *config = json_copy (cfg); - GNUNET_JSON_parse_free (spec); - return GNUNET_OK; } enum GNUNET_GenericReturnValue TALER_extensions_load_manifests ( - json_t *extensions) + const json_t *extensions) { - const char*name; + const char *name; json_t *manifest; GNUNET_assert (NULL != extensions); GNUNET_assert (json_is_object (extensions)); - json_object_foreach (extensions, name, manifest) + json_object_foreach ((json_t *) extensions, name, manifest) { int critical; const char *version; json_t *config; - struct TALER_Extension *extension = (struct - TALER_Extension *) - TALER_extensions_get_by_name (name); + struct TALER_Extension *extension + = (struct TALER_Extension *) + TALER_extensions_get_by_name (name); if (NULL == extension) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "no such extension: %s\n", name); + "no such extension: %s\n", + name); return GNUNET_SYSERR; } /* load and verify criticality, version, etc. */ if (GNUNET_OK != TALER_extensions_parse_manifest ( - manifest, &critical, &version, &config)) + manifest, + &critical, + &version, + &config)) return GNUNET_SYSERR; if (critical != extension->critical - || 0 != strcmp (version, extension->version) // TODO: libtool compare? + || 0 != strcmp (version, + extension->version) // TODO: libtool compare? || NULL == config - || GNUNET_OK != extension->load_config (config, NULL)) + || (GNUNET_OK != + extension->load_config (config, + NULL)) ) return GNUNET_SYSERR; /* This _should_ work now */ if (GNUNET_OK != - extension->load_config (config, extension)) + extension->load_config (config, + extension)) return GNUNET_SYSERR; extension->enabled = true; @@ -363,6 +367,7 @@ TALER_extensions_load_manifests ( */ static char *fulfillment2str[] = { + [TALER_PolicyFulfillmentInitial] = "<init>", [TALER_PolicyFulfillmentReady] = "Ready", [TALER_PolicyFulfillmentSuccess] = "Success", [TALER_PolicyFulfillmentFailure] = "Failure", @@ -381,6 +386,7 @@ TALER_policy_fulfillment_state_str ( enum GNUNET_GenericReturnValue TALER_extensions_create_policy_details ( + const char *currency, const json_t *policy_options, struct TALER_PolicyDetails *details, const char **error_hint) @@ -424,8 +430,18 @@ TALER_extensions_create_policy_details ( return GNUNET_NO; } + /* Set state fields in the policy details to initial values. */ + GNUNET_assert (GNUNET_OK == + TALER_amount_set_zero (currency, + &details->accumulated_total)); + GNUNET_assert (GNUNET_OK == + TALER_amount_set_zero (currency, + &details->policy_fee)); details->deadline = GNUNET_TIME_UNIT_FOREVER_TS; - ret = extension->create_policy_details (policy_options, + details->fulfillment_state = TALER_PolicyFulfillmentInitial; + details->no_policy_fulfillment_id = true; + ret = extension->create_policy_details (currency, + policy_options, details, error_hint); return ret; |