summaryrefslogtreecommitdiff
path: root/src/extensions/extensions.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/extensions/extensions.c')
-rw-r--r--src/extensions/extensions.c68
1 files changed, 42 insertions, 26 deletions
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;