From cc7d7707ab2bd43bc9e95c0eeec9ce95cdc0c523 Mon Sep 17 00:00:00 2001 From: Özgür Kesim Date: Sat, 8 Jan 2022 14:40:20 +0100 Subject: [age restriction] progress 10/n More work towards support for extensions: - Prepared statements and DB-plugin-functions for setting and retrieving configurations from the database added. - primitive "registry" of extensions for age restrictions and peer2peer (stub) - TALER_Extensions now with FP for parsing, setting and converting a configuration. - /management/extensions handler now verifies signature of the (opaque) json object for all extensions. - /management/extensions handler calls the FP in the corrensponding TALER_Extension for parsing and setting the configuration of a particular extension More work towards age restriction: - TALER_Extensions interfaces for config-parser, -setter and converter implemented for age restriction - DB event handler now retrieves config from database, parses it and sets it (the age mask) in the global extension. - load_age_mask now loads age mask from the global extension (and not from the config file) - add age_restricted_denoms to /keys response --- src/include/taler_extensions.h | 63 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 58 insertions(+), 5 deletions(-) (limited to 'src/include/taler_extensions.h') diff --git a/src/include/taler_extensions.h b/src/include/taler_extensions.h index b6d5c826c..199776eb7 100644 --- a/src/include/taler_extensions.h +++ b/src/include/taler_extensions.h @@ -23,6 +23,7 @@ #include #include "taler_crypto_lib.h" +#include "taler_json_lib.h" #define TALER_EXTENSION_SECTION_PREFIX "exchange-extension-" @@ -39,22 +40,42 @@ enum TALER_Extension_Type { TALER_Extension_AgeRestriction = 0, TALER_Extension_Peer2Peer = 1, - TALER_Extension_Max = 2 + TALER_Extension_Max = 2 // Must be last }; +/* + * TODO oec: documentation + */ struct TALER_Extension { enum TALER_Extension_Type type; char *name; bool critical; void *config; + + enum GNUNET_GenericReturnValue (*test_config)(const json_t *config); + enum GNUNET_GenericReturnValue (*parse_and_set_config)(struct + TALER_Extension *this, + const json_t *config); + json_t *(*config_to_json)(const struct TALER_Extension *this); }; -/* - * TALER Peer2Peer Extension - * FIXME oec +/** + * Generic functions for extensions */ +/** + * Finds and returns a supported extension by a given name. + * + * @param name name of the extension to lookup + * @param extensions list of TALER_Extensions as haystack, terminated by an entry of type TALER_Extension_Max + * @param[out] ext set to the extension, if found, NULL otherwise + * @return GNUNET_OK if extension was found, GNUNET_NO otherwise + */ +enum GNUNET_GenericReturnValue +TALER_extension_get_by_name (const char *name, + const struct TALER_Extension **extensions, + const struct TALER_Extension **ext); /* * TALER Age Restriction Extension @@ -72,7 +93,19 @@ struct TALER_Extension << 21) /** - * @param groups String representation of age groups, like: "8:10:12:14:16:18:21" + * @brief Parses a string as a list of age groups. + * + * The string must consist of a colon-separated list of increasing integers + * between 0 and 31. Each entry represents the beginning of a new age group. + * F.e. the string "8:10:12:14:16:18:21" parses into the following list of age + * groups + * 0-7, 8-9, 10-11, 12-13, 14-15, 16-17, 18-20, 21-... + * which then is represented as bit mask with the corresponding bits set: + * 31 24 16 8 0 + * | | | | | + * oooooooo oo1oo1o1 o1o1o1o1 ooooooo1 + * + * @param groups String representation of age groups * @param[out] mask Mask representation for age restriction. * @return Error, if age groups were invalid, OK otherwise. */ @@ -81,6 +114,19 @@ TALER_parse_age_group_string (char *groups, struct TALER_AgeMask *mask); /** + * Encodes the age mask into a string, like "8:10:12:14:16:18:21" + * + * @param mask Age mask + * @return String representation of the age mask, allocated by GNUNET_malloc. + * Can be used as value in the TALER config. + */ +char * +TALER_age_mask_to_string (const struct TALER_AgeMask *mask); + + +/** + * @brief Reads the age groups from the configuration and sets the + * corresponding age mask. * * @param cfg * @param[out] mask for age restriction, will be set to 0 if age restriction is disabled. @@ -90,4 +136,11 @@ TALER_parse_age_group_string (char *groups, enum TALER_Extension_ReturnValue TALER_get_age_mask (const struct GNUNET_CONFIGURATION_Handle *cfg, struct TALER_AgeMask *mask); + + +/* + * TALER Peer2Peer Extension + * TODO oec + */ + #endif -- cgit v1.2.3