aboutsummaryrefslogtreecommitdiff
path: root/src/include/taler_extensions.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/include/taler_extensions.h')
-rw-r--r--src/include/taler_extensions.h159
1 files changed, 56 insertions, 103 deletions
diff --git a/src/include/taler_extensions.h b/src/include/taler_extensions.h
index 8e1823cc..40b14402 100644
--- a/src/include/taler_extensions.h
+++ b/src/include/taler_extensions.h
@@ -24,6 +24,7 @@
#include <gnunet/gnunet_util_lib.h>
#include "taler_crypto_lib.h"
#include "taler_json_lib.h"
+#include "taler_mhd_lib.h"
#define TALER_EXTENSION_SECTION_PREFIX "exchange-extension-"
@@ -34,6 +35,17 @@ enum TALER_Extension_Type
TALER_Extension_MaxPredefined = 1 // Must be last of the predefined
};
+
+/*
+ * @brief simply linked list of extensions
+ */
+
+struct TALER_Extensions
+{
+ struct TALER_Extensions *next;
+ const struct TALER_Extension *extension;
+};
+
/*
* @brief Represents the implementation of an extension.
*
@@ -41,14 +53,12 @@ enum TALER_Extension_Type
*/
struct TALER_Extension
{
- /* simple linked list */
- struct TALER_Extension *next;
-
enum TALER_Extension_Type type;
char *name;
bool critical;
char *version;
void *config;
+ bool enabled;
json_t *config_json;
void (*disable)(struct TALER_Extension *ext);
@@ -63,9 +73,11 @@ struct TALER_Extension
json_t *(*config_to_json)(
const struct TALER_Extension *ext);
- enum GNUNET_GenericReturnValue (*load_taler_config)(
- struct TALER_Extension *ext,
- const struct GNUNET_CONFIGURATION_Handle *cfg);
+ MHD_RESULT (*http_post_handler)(
+ struct MHD_Connection *connection,
+ const json_t *root,
+ const char *const args[]);
+
};
/**
@@ -73,15 +85,15 @@ struct TALER_Extension
*/
/*
- * @brief Sets the configuration of the extensions from the given TALER
- * configuration.
+ * @brief Loads the extensions as shared libraries, as specified in the given
+ * TALER configuration.
*
* @param cfg Handle to the TALER configuration
* @return GNUNET_OK on success, GNUNET_SYSERR if unknown extensions were found
* or any particular configuration couldn't be parsed.
*/
enum GNUNET_GenericReturnValue
-TALER_extensions_load_taler_config (
+TALER_extensions_load (
const struct GNUNET_CONFIGURATION_Handle *cfg);
/*
@@ -118,25 +130,13 @@ TALER_extensions_load_json_config (
/*
* @brief Returns the head of the linked list of extensions.
*/
-const struct TALER_Extension *
+const struct TALER_Extensions *
TALER_extensions_get_head ();
-/*
- * @brief Adds an extension to the linked list of extensions.
- *
- * @param new_extension the new extension to be added
- * @return GNUNET_OK on success, GNUNET_SYSERR if the extension is invalid
- * (missing fields), GNUNET_NO if there is already an extension with that name
- * or type.
- */
-enum GNUNET_GenericReturnValue
-TALER_extensions_add (
- struct TALER_Extension *new_extension);
-
/**
* @brief Finds and returns a supported extension by a given type.
*
- * @param type type of the extension to lookup
+ * @param type of the extension to lookup
* @return extension found, or NULL (should not happen!)
*/
const struct TALER_Extension *
@@ -154,8 +154,6 @@ const struct TALER_Extension *
TALER_extensions_get_by_name (
const char *name);
-#define TALER_extensions_is_enabled(ext) (NULL != (ext)->config)
-
/**
* @brief Check if a given type of an extension is enabled
*
@@ -166,6 +164,15 @@ bool
TALER_extensions_is_enabled_type (
enum TALER_Extension_Type type);
+/**
+ * @brief Check if an extension is enabled
+ *
+ * @param extension The extension handler.
+ * @return true enabled, false if not enabled, will assert if type is not found.
+ */
+bool
+TALER_extensions_is_enabled (
+ const struct TALER_Extension *extension);
/*
* Verify the signature of a given JSON object for extensions with the master
@@ -189,6 +196,9 @@ TALER_extensions_verify_json_config_signature (
/*
* TALER Age Restriction Extension
+ *
+ * This extension is special insofar as it directly interacts with coins and
+ * denominations.
*/
#define TALER_EXTENSION_SECTION_AGE_RESTRICTION (TALER_EXTENSION_SECTION_PREFIX \
@@ -204,98 +214,41 @@ TALER_extensions_verify_json_config_signature (
| 1 << 21)
#define TALER_EXTENSION_AGE_RESTRICTION_DEFAULT_AGE_GROUPS "8:10:12:14:16:18:21"
-/**
- * @brief Registers the extension for age restriction to the list extensions
- */
-enum GNUNET_GenericReturnValue
-TALER_extension_age_restriction_register ();
-/**
- * @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"
- *
- * represents the following list of eight age groups:
- *
- * | Group | Ages |
- * | -----:|:------------- |
- * | 0 | 0, 1, ..., 7 |
- * | 1 | 8, 9 |
- * | 2 | 10, 11 |
- * | 3 | 12, 13 |
- * | 4 | 14, 15 |
- * | 5 | 16, 17 |
- * | 6 | 18, 19, 20 |
- * | 7 | 21, ... |
- *
- * which is then encoded as a 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.
+/*
+ * @brief Configuration for Age Restriction
*/
-enum GNUNET_GenericReturnValue
-TALER_parse_age_group_string (
- const char *groups,
- struct TALER_AgeMask *mask);
+struct TALER_AgeRestrictionConfig
+{
+ bool enabled;
+ struct TALER_AgeMask mask;
+ uint8_t num_groups;
+};
-/**
- * @brief 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 Returns true when age restriction is configured and enabled.
+ * @brief Retrieve the age restriction configuration
+ *
+ * @return age restriction configuration if present, otherwise NULL.
*/
-bool
-TALER_extensions_age_restriction_is_enabled ();
+const struct TALER_AgeRestrictionConfig *
+TALER_extensions_get_age_restriction_config ();
/**
- * @brief Returns true when age restriction is configured (might not be
- * _enabled_, though).
+ * @brief Check if age restriction is enabled
+ *
+ * @return true, if age restriction is loaded, configured and enabled; otherwise false.
*/
bool
-TALER_extensions_age_restriction_is_configured ();
+TALER_extensions_is_age_restriction_enabled ();
/**
- * @brief Returns the currently set age mask. Note that even if age
- * restriction is not enabled, the age mask might be have a non-zero value.
- */
-struct TALER_AgeMask
-TALER_extensions_age_restriction_ageMask ();
-
-
-/**
- * @brief Returns the amount of age groups defined. 0 means no age restriction
- * enabled.
- */
-size_t
-TALER_extensions_age_restriction_num_groups ();
-
-/**
- * @brief Parses a JSON object { "age_groups": "a:b:...y:z" }.
+ * @brief Return the age mask for age restriction
*
- * @param root is the json object
- * @param[out] mask on success, will contain the age mask
- * @return #GNUNET_OK on success and #GNUNET_SYSERR on failure.
+ * @return configured age mask, if age restriction is loaded, configured and enabled; otherwise zero mask.
*/
-enum GNUNET_GenericReturnValue
-TALER_JSON_parse_age_groups (const json_t *root,
- struct TALER_AgeMask *mask);
+struct TALER_AgeMask
+TALER_extensions_get_age_restriction_mask ();
/*