diff options
Diffstat (limited to 'src/extensions')
-rw-r--r-- | src/extensions/age_restriction/Makefile.am | 2 | ||||
-rw-r--r-- | src/extensions/age_restriction/age_restriction.c (renamed from src/extensions/age_restriction/extension_age_restriction.c) | 78 | ||||
-rw-r--r-- | src/extensions/age_restriction_helper.c | 3 | ||||
-rw-r--r-- | src/extensions/extensions.c | 43 | ||||
-rw-r--r-- | src/extensions/policy_brandt_vickrey_auction/Makefile.am (renamed from src/extensions/policy_auction/Makefile.am) | 10 | ||||
-rw-r--r-- | src/extensions/policy_brandt_vickrey_auction/policy_brandt_vickrey_auction.c (renamed from src/extensions/policy_auction/policy_auction.c) | 135 | ||||
-rw-r--r-- | src/extensions/policy_escrow/TODO.md | 15 |
7 files changed, 118 insertions, 168 deletions
diff --git a/src/extensions/age_restriction/Makefile.am b/src/extensions/age_restriction/Makefile.am index e90c1962..85d67653 100644 --- a/src/extensions/age_restriction/Makefile.am +++ b/src/extensions/age_restriction/Makefile.am @@ -22,7 +22,7 @@ libtaler_extension_age_restriction_la_LDFLAGS = \ -no-undefined libtaler_extension_age_restriction_la_SOURCES = \ - extension_age_restriction.c + age_restriction.c libtaler_extension_age_restriction_la_LIBADD = \ $(top_builddir)/src/json/libtalerjson.la \ diff --git a/src/extensions/age_restriction/extension_age_restriction.c b/src/extensions/age_restriction/age_restriction.c index 697d066f..a1a11e4f 100644 --- a/src/extensions/age_restriction/extension_age_restriction.c +++ b/src/extensions/age_restriction/age_restriction.c @@ -14,7 +14,7 @@ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> */ /** - * @file extension_age_restriction.c + * @file age_restriction.c * @brief Utility functions regarding age restriction * @author Özgür Kesim */ @@ -51,26 +51,19 @@ age_restriction_disable ( ext->enabled = false; ext->config = NULL; - if (NULL != ext->config_json) - { - json_decref (ext->config_json); - ext->config_json = NULL; - } - - AR_config.enabled = false; AR_config.mask.bits = 0; AR_config.num_groups = 0; } /** - * @brief implements the TALER_Extension.load_json_config interface. + * @brief implements the TALER_Extension.load_config interface. * * @param ext if NULL, only tests the configuration * @param jconfig the configuration as json */ static enum GNUNET_GenericReturnValue -age_restriction_load_json_config ( +age_restriction_load_config ( struct TALER_Extension *ext, json_t *jconfig) { @@ -98,14 +91,8 @@ age_restriction_load_json_config ( AR_config.num_groups = __builtin_popcount (mask.bits) - 1; } - AR_config.enabled = true; ext->config = &AR_config; - - if (NULL != ext->config_json) - json_decref (ext->config_json); - ext->enabled = true; - ext->config_json = json_copy (jconfig); json_decref (jconfig); GNUNET_log (GNUNET_ERROR_TYPE_WARNING, @@ -117,13 +104,13 @@ age_restriction_load_json_config ( /** - * @brief implements the TALER_Extension.config_to_json interface. + * @brief implements the TALER_Extension.manifest interface. * * @param ext if NULL, only tests the configuration * @return configuration as json_t* object, maybe NULL */ static json_t * -age_restriction_config_to_json ( +age_restriction_manifest ( const struct TALER_Extension *ext) { char *mask_str; @@ -131,13 +118,6 @@ age_restriction_config_to_json ( GNUNET_assert (NULL != ext); - if (! ext->enabled) - { - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - "age restriction not enabled"); - return json_null (); - } - if (NULL == ext->config) { GNUNET_log (GNUNET_ERROR_TYPE_WARNING, @@ -145,11 +125,6 @@ age_restriction_config_to_json ( return json_null (); } - if (NULL != ext->config_json) - { - return json_copy (ext->config_json); - } - mask_str = TALER_age_mask_to_string (&AR_config.mask); conf = GNUNET_JSON_PACK ( GNUNET_JSON_pack_string ("age_groups", mask_str) @@ -165,36 +140,19 @@ age_restriction_config_to_json ( } -/** - * @brief implements the TALER_Extension.test_json_config interface. - * - * @param config configuration as json_t* to test - * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise. - */ -static enum GNUNET_GenericReturnValue -age_restriction_test_json_config ( - const json_t *config) -{ - struct TALER_AgeMask mask = {0}; - - return TALER_JSON_parse_age_groups (config, &mask); -} - - /* The extension for age restriction */ -struct TALER_Extension TE_extension_age_restriction = { +struct TALER_Extension TE_age_restriction = { .type = TALER_Extension_AgeRestriction, .name = "age_restriction", .critical = false, .version = "1", .enabled = false, /* disabled per default */ - .has_config = true, /* we need to store configuration */ .config = NULL, - .config_json = NULL, .disable = &age_restriction_disable, - .test_json_config = &age_restriction_test_json_config, - .load_json_config = &age_restriction_load_json_config, - .config_to_json = &age_restriction_config_to_json, + .load_config = &age_restriction_load_config, + .manifest = &age_restriction_manifest, + .deposit_handler = NULL, + .http_get_handler = NULL, .http_post_handler = NULL, }; @@ -261,23 +219,20 @@ libtaler_extension_age_restriction_init (void *arg) AR_config.mask = mask; AR_config.num_groups = __builtin_popcount (mask.bits) - 1; /* no underflow, first bit always set */ - AR_config.enabled = true; GNUNET_log (GNUNET_ERROR_TYPE_INFO, "[age restriction] setting age mask to %s with #groups: %d\n", TALER_age_mask_to_string (&AR_config.mask), __builtin_popcount (AR_config.mask.bits) - 1); - TE_extension_age_restriction.config = &AR_config; - TE_extension_age_restriction.enabled = true; + TE_age_restriction.config = &AR_config; - /* Note: we do now have TE_age_restriction_config set, however - * ext->config_json is NOT set, i.e. the extension is not yet active! For - * age restriction to become active, load_json_config must have been - * called. */ + /* Note: we do now have TE_age_restriction_config set, however the extension + * is not yet enabled! For age restriction to become active, load_config must + * have been called. */ GNUNET_free (groups); - return &TE_extension_age_restriction; + return &TE_age_restriction; } @@ -292,11 +247,10 @@ libtaler_extension_age_restriction_done (void *arg) { GNUNET_log (GNUNET_ERROR_TYPE_INFO, "[age restriction] disabling and unloading"); - AR_config.enabled = 0; AR_config.mask.bits = 0; AR_config.num_groups = 0; return NULL; } -/* end of extension_age_restriction.c */ +/* end of age_restriction.c */ diff --git a/src/extensions/age_restriction_helper.c b/src/extensions/age_restriction_helper.c index 2cd77515..8ba83511 100644 --- a/src/extensions/age_restriction_helper.c +++ b/src/extensions/age_restriction_helper.c @@ -61,8 +61,7 @@ TALER_extensions_get_age_restriction_mask () ext = TALER_extensions_get_by_type (TALER_Extension_AgeRestriction); if ((NULL == ext) || - (NULL == ext->config) || - (! ext->enabled)) + (NULL == ext->config)) return (struct TALER_AgeMask) {0} ; diff --git a/src/extensions/extensions.c b/src/extensions/extensions.c index 95fb8cf0..33e03613 100644 --- a/src/extensions/extensions.c +++ b/src/extensions/extensions.c @@ -46,9 +46,8 @@ add_extension ( (NULL == extension->name) || (NULL == extension->version) || (NULL == extension->disable) || - (NULL == extension->test_json_config) || - (NULL == extension->load_json_config) || - (NULL == extension->config_to_json)) + (NULL == extension->load_config) || + (NULL == extension->manifest)) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "invalid extension\n"); @@ -138,20 +137,20 @@ TALER_extensions_get_by_name ( enum GNUNET_GenericReturnValue -TALER_extensions_verify_json_config_signature ( - json_t *extensions, +TALER_extensions_verify_manifests_signature ( + json_t *manifests, struct TALER_MasterSignatureP *extensions_sig, struct TALER_MasterPublicKeyP *master_pub) { - struct TALER_ExtensionConfigHashP h_config; + struct TALER_ExtensionManifestsHashP h_manifests; if (GNUNET_OK != - TALER_JSON_extensions_config_hash (extensions, - &h_config)) + TALER_JSON_extensions_manifests_hash (manifests, + &h_manifests)) return GNUNET_SYSERR; if (GNUNET_OK != - TALER_exchange_offline_extension_config_hash_verify ( - &h_config, + TALER_exchange_offline_extension_manifests_hash_verify ( + &h_manifests, master_pub, extensions_sig)) return GNUNET_NO; @@ -240,7 +239,7 @@ configure_extension ( static bool extensions_loaded = false; enum GNUNET_GenericReturnValue -TALER_extensions_load ( +TALER_extensions_init ( const struct GNUNET_CONFIGURATION_Handle *cfg) { struct LoadConfClosure col = { @@ -263,7 +262,7 @@ TALER_extensions_load ( enum GNUNET_GenericReturnValue -TALER_extensions_is_json_config ( +TALER_extensions_parse_manifest ( json_t *obj, int *critical, const char **version, @@ -296,22 +295,21 @@ TALER_extensions_is_json_config ( enum GNUNET_GenericReturnValue -TALER_extensions_load_json_config ( +TALER_extensions_load_manifests ( json_t *extensions) { const char*name; - json_t *blob; + json_t *manifest; GNUNET_assert (NULL != extensions); GNUNET_assert (json_is_object (extensions)); - json_object_foreach (extensions, name, blob) + json_object_foreach (extensions, name, manifest) { int critical; const char *version; json_t *config; - const struct TALER_Extension *extension = - TALER_extensions_get_by_name (name); + struct TALER_Extension *extension = (struct TALER_Extension *)TALER_extensions_get_by_name (name); if (NULL == extension) { @@ -322,21 +320,22 @@ TALER_extensions_load_json_config ( /* load and verify criticality, version, etc. */ if (GNUNET_OK != - TALER_extensions_is_json_config ( - blob, &critical, &version, &config)) + TALER_extensions_parse_manifest ( + manifest, &critical, &version, &config)) return GNUNET_SYSERR; if (critical != extension->critical || 0 != strcmp (version, extension->version) // TODO: libtool compare? || NULL == config - || GNUNET_OK != extension->test_json_config (config)) + || GNUNET_OK != extension->load_config (NULL, config)) return GNUNET_SYSERR; /* This _should_ work now */ if (GNUNET_OK != - extension->load_json_config ((struct TALER_Extension *) extension, - config)) + extension->load_config ( extension, config)) return GNUNET_SYSERR; + + extension->enabled = true; } /* make sure to disable all extensions that weren't mentioned in the json */ diff --git a/src/extensions/policy_auction/Makefile.am b/src/extensions/policy_brandt_vickrey_auction/Makefile.am index cf44b95e..63fa6ce6 100644 --- a/src/extensions/policy_auction/Makefile.am +++ b/src/extensions/policy_brandt_vickrey_auction/Makefile.am @@ -16,16 +16,16 @@ endif plugindir = $(libdir)/taler plugin_LTLIBRARIES = \ - libtaler_extension_policy_auction.la + libtaler_extension_policy_brandt_vickrey_auction.la -libtaler_extension_policy_auction_la_LDFLAGS = \ +libtaler_extension_policy_brandt_vickrey_auction_la_LDFLAGS = \ -version-info 0:0:0 \ -no-undefined -libtaler_extension_policy_auction_la_SOURCES = \ - policy_auction.c +libtaler_extension_policy_brandt_vickrey_auction_la_SOURCES = \ + policy_brandt_vickrey_auction.c -libtaler_extension_policy_auction_la_LIBADD = \ +libtaler_extension_policy_brandt_vickrey_auction_la_LIBADD = \ $(top_builddir)/src/json/libtalerjson.la \ $(top_builddir)/src/util/libtalerutil.la \ -lgnunetjson \ diff --git a/src/extensions/policy_auction/policy_auction.c b/src/extensions/policy_brandt_vickrey_auction/policy_brandt_vickrey_auction.c index d1c3237c..daf91ccb 100644 --- a/src/extensions/policy_auction/policy_auction.c +++ b/src/extensions/policy_brandt_vickrey_auction/policy_brandt_vickrey_auction.c @@ -14,7 +14,7 @@ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> */ /** - * @file policy_auction.c + * @file policy_brandt_vickery_auction.c * @brief Extension for replay of auctions of type Brandt * @author Özgür Kesim */ @@ -26,13 +26,26 @@ #include "stdint.h" #include <microhttpd.h> -#define POLICY_AUCTION "policy_auction" -#define LOG_PREFIX "[policy_auction] " +#define POLICY_AUCTION "policy_brandt_vickery_auction" +#define LOG_PREFIX "[policy_brandt_vickery_auction] " #define MAX_RESULT_SIZE 10 * 1024 +/* (public) configuration of this extension */ +/* TODO: these fields need to be set in the init handler */ +static struct TALER_BrandtVickreyAuction BV_config = { + .max_bidders = 10, + .max_prices = 10, + .auction_fee = { + .value = 0, + .fraction = 0, + .currency = {'E', 'U', 'R', 0, 0, 0, 0, 0, 0, 0, 0, 0}, + }, +}; + /* Path to the replay program. */ static char *replay_program; + /* supported currency */ static char *currency; @@ -123,45 +136,6 @@ json_error (json_t **output, return GNUNET_SYSERR; }; -/** - * @brief returns an JSON with the result - */ -#if 0 -static enum GNUNET_GenericReturnValue -json_result (json_t **output, - const struct transcript *tr) -{ - json_t *results; - - GNUNET_assert (NULL != tr); - - *output = json_object (); - results = json_array (); - GNUNET_assert (*output); - GNUNET_assert (results); - - for (size_t i = 0; i < tr->results_len; i++) - { - json_t *result = json_pack ("{s:i, s:s}", - "bidder", tr->results[i].bidder, - "price", tr->results[i].price); - GNUNET_assert (result); - - GNUNET_assert (-1 != - json_array_append_new (results, result)); - } - - GNUNET_assert (-1 != - json_object_set_new (*output, - "winners", - results)); - - return GNUNET_OK; -} - - -#endif - /* * @brief Parses a given json as transcript. @@ -508,55 +482,49 @@ static void auction_disable ( struct TALER_Extension *ext) { - /* TODO: cleanup configuration */ + ext->config = NULL; ext->enabled = false; } /** - * @brief implements the TALER_Extension.test_json_config interface. - * - * @param config configuration as json_t* to test - * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise. - */ -static enum GNUNET_GenericReturnValue -auction_test_json_config ( - const json_t *config) -{ - /* This extension has no configuration */ - return GNUNET_OK; -} - - -/** - * @brief implements the TALER_Extension.config_to_json interface. + * @brief implements the TALER_Extension.manifest interface. * * @param ext if NULL, only tests the configuration * @return configuration as json_t* object, maybe NULL */ static json_t * -auction_config_to_json ( +auction_manifest ( const struct TALER_Extension *ext) { - /* TODO: add configuration */ + struct TALER_BrandtVickreyAuction *conf = ext->config; + GNUNET_assert (conf); + + json_t *config = GNUNET_JSON_PACK ( + GNUNET_JSON_pack_int64 ("max_bidders", conf->max_bidders), + GNUNET_JSON_pack_int64 ("max_prices", conf->max_prices), + TALER_JSON_pack_amount ("auction_fee", &conf->auction_fee)); + GNUNET_assert (config); + return GNUNET_JSON_PACK ( GNUNET_JSON_pack_bool ("critical", ext->critical), - GNUNET_JSON_pack_string ("version", ext->version)); + GNUNET_JSON_pack_string ("version", ext->version), + GNUNET_JSON_pack_object_steal ("config", config)); } /** - * @brief implements the TALER_Extension.load_json_config interface. + * @brief implements the TALER_Extension.load_config interface. * * @param ext if NULL, only tests the configuration * @param jconfig the configuration as json */ static enum GNUNET_GenericReturnValue -auction_load_json_config ( +auction_load_config ( struct TALER_Extension *ext, json_t *jconfig) { - /* TODO: add configuration */ + /* TODO: parse configuration */ ext->enabled = true; return GNUNET_OK; } @@ -620,20 +588,36 @@ auction_http_post_handler ( } +/** + * @brief implements the TALER_Extensions.deposit_handler interface. + * + * @param[in] input JSON input from the client during a deposit request + * @param[out] output by this extension + * @return GNUNET_OK if the request was OK + */ +enum GNUNET_GenericReturnValue +auction_deposit_handler ( + json_t *input, + json_t **output) +{ + /* TODO */ + *output = NULL; + return GNUNET_OK; +} + + /* The extension struct for auctions of brandt-style */ struct TALER_Extension TE_auction_brandt = { - .type = TALER_Extension_PolicyAuction, + .type = TALER_Extension_PolicyBrandtVickeryAuction, .name = POLICY_AUCTION, .critical = false, .version = "0", .enabled = false, /* disabled per default */ - .has_config = true, - .config = NULL, - .config_json = NULL, + .config = &BV_config, .disable = &auction_disable, - .test_json_config = &auction_test_json_config, - .load_json_config = &auction_load_json_config, - .config_to_json = &auction_config_to_json, + .load_config = &auction_load_config, + .manifest = &auction_manifest, + .deposit_handler = &auction_deposit_handler, .http_get_handler = &auction_http_get_handler, .http_post_handler = &auction_http_post_handler, }; @@ -653,7 +637,7 @@ struct TALER_Extension TE_auction_brandt = { * @return Pointer to TE_auction_brandt */ struct TALER_Extension * -libtaler_extension_policy_auction_init (void *arg) +libtaler_extension_policy_brandt_vickery_auction_init (void *arg) { const struct GNUNET_CONFIGURATION_Handle *cfg = arg; @@ -705,7 +689,6 @@ libtaler_extension_policy_auction_init (void *arg) /* TODO: read other config parameters and generate configuration */ - return &TE_auction_brandt; } @@ -718,7 +701,7 @@ libtaler_extension_policy_auction_init (void *arg) * @return null */ void * -libtaler_extension_policy_auction_done (void *arg) +libtaler_extension_policy_brandt_vickery_auction_done (void *arg) { auction_disable (&TE_auction_brandt); GNUNET_free (replay_program); @@ -728,4 +711,4 @@ libtaler_extension_policy_auction_done (void *arg) } -/* end of policy_auction.c */ +/* end of policy_brandt_vickery_auction.c */ diff --git a/src/extensions/policy_escrow/TODO.md b/src/extensions/policy_escrow/TODO.md new file mode 100644 index 00000000..52d2c1ab --- /dev/null +++ b/src/extensions/policy_escrow/TODO.md @@ -0,0 +1,15 @@ +# Basic escrow extension + +- on deposit, coins can be put into escrow + - timeout will be specified + - target payto-URL + - public key for release + - returns escrow ID == hash of the coins. + +- /extension/escrow endpoint + - post request requires of escrow ID + - signature of the release-key and all coins nedded + - transfere to target-payto-URL. + +- on timeout: + - coins are unblocked |