Towards a dynamic plugin solution of extensions
- implemented TALER_Extensions.parse_config for age restriction - implemented TALER_Extensions.config_to_json for age restriction - TEH_extensions_init now initializes the global TEH_extensions ** list
This commit is contained in:
parent
c9ab318abc
commit
9978b25912
@ -150,7 +150,7 @@ bool TEH_suicide;
|
||||
/**
|
||||
* Global register of extensions
|
||||
*/
|
||||
struct TALER_Extension *TEH_extensions;
|
||||
struct TALER_Extension **TEH_extensions;
|
||||
|
||||
/**
|
||||
* Value to return from main()
|
||||
|
@ -204,7 +204,7 @@ extern struct GNUNET_CURL_Context *TEH_curl_ctx;
|
||||
/**
|
||||
* The manifest of the available extensions, NULL terminated
|
||||
*/
|
||||
extern struct TALER_Extension *TEH_extensions;
|
||||
extern struct TALER_Extension **TEH_extensions;
|
||||
|
||||
/**
|
||||
* @brief Struct describing an URL and the handler for it.
|
||||
|
@ -24,47 +24,94 @@
|
||||
#include "taler-exchange-httpd_extensions.h"
|
||||
#include "taler_json_lib.h"
|
||||
#include "taler_mhd_lib.h"
|
||||
#include "taler_extensions.h"
|
||||
#include <jansson.h>
|
||||
|
||||
/**
|
||||
* Create a list with the extensions for Age Restriction and Peer2Peer
|
||||
*
|
||||
* TODO oec
|
||||
* @brief implements the TALER_Extension.parse_config interface.
|
||||
*/
|
||||
static struct TALER_Extension *
|
||||
register_known_extensions ()
|
||||
enum GNUNET_GenericReturnValue
|
||||
TALER_Extension_AgeRestriction_parse_config (struct TALER_Extension *this, const
|
||||
json_t *config)
|
||||
{
|
||||
/* TODO oec
|
||||
* - create list of correct size, or linked list?
|
||||
* - fill data for age restriction and peer2peer
|
||||
* - set function pointers for parser and json-converter
|
||||
* - set function pointers for notimplemented?
|
||||
*/
|
||||
/**
|
||||
* The global manifest with the list supported extensions, sorted by
|
||||
* TALER_Extension_Type.
|
||||
*
|
||||
* TODO: This needs to become a dynamic list, once we have a model for
|
||||
* extensions as plugins.
|
||||
struct TALER_Extension *TEH_extensions[] = {
|
||||
[TALER_Extension_AgeRestriction] = {
|
||||
.type = TALER_Extension_AgeRestriction,
|
||||
.name = "age_restriction",
|
||||
.critical = false,
|
||||
.config = NULL, // disabled per default
|
||||
// .parse_config = &TALER_Extension_AgeRestriction_parse_config,
|
||||
// .config_to_json = &TALER_Extension_AgeRestriction_config_to_json,
|
||||
},
|
||||
[TALER_Extension_Peer2Peer] = {
|
||||
.type = TALER_Extension_Peer2Peer,
|
||||
.name = "peer2peer",
|
||||
.critical = false,
|
||||
.config = NULL, // disabled per default
|
||||
},
|
||||
};
|
||||
**/
|
||||
enum GNUNET_GenericReturnValue ret;
|
||||
struct TALER_AgeMask mask = {0};
|
||||
|
||||
return NULL;
|
||||
ret = TALER_agemask_parse_json (config, &mask);
|
||||
if (GNUNET_OK != ret)
|
||||
return ret;
|
||||
|
||||
if (this != NULL && TALER_Extension_AgeRestriction == this->type)
|
||||
{
|
||||
if (NULL != this->config)
|
||||
{
|
||||
GNUNET_free (this->config);
|
||||
}
|
||||
this->config = GNUNET_malloc (sizeof(struct TALER_AgeMask));
|
||||
GNUNET_memcpy (this->config, &mask, sizeof(struct TALER_AgeMask));
|
||||
}
|
||||
|
||||
return GNUNET_OK;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief implements the TALER_Extension.config_to_json interface.
|
||||
*/
|
||||
json_t *
|
||||
TALER_Extension_AgeRestriction_config_to_json (const struct
|
||||
TALER_Extension *this)
|
||||
{
|
||||
const struct TALER_AgeMask *mask;
|
||||
if (NULL == this || TALER_Extension_AgeRestriction != this->type)
|
||||
return NULL;
|
||||
|
||||
mask = (struct TALER_AgeMask *) this->config;
|
||||
json_t *config = GNUNET_JSON_PACK (
|
||||
GNUNET_JSON_pack_string ("extension", this->name),
|
||||
GNUNET_JSON_pack_string ("mask",
|
||||
TALER_age_mask_to_string (mask))
|
||||
);
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
|
||||
/* The extension for age restriction */
|
||||
static struct TALER_Extension extension_ageRestriction = {
|
||||
.type = TALER_Extension_AgeRestriction,
|
||||
.name = "age_restriction",
|
||||
.critical = false,
|
||||
.config = NULL, // disabled per default
|
||||
.parse_config = &TALER_Extension_AgeRestriction_parse_config,
|
||||
.config_to_json = &TALER_Extension_AgeRestriction_config_to_json,
|
||||
};
|
||||
|
||||
/* TODO: The extension for peer2peer */
|
||||
static struct TALER_Extension extension_peer2peer = {
|
||||
.type = TALER_Extension_Peer2Peer,
|
||||
.name = "peer2peer",
|
||||
.critical = false,
|
||||
.config = NULL, // disabled per default
|
||||
.parse_config = NULL, // TODO oec
|
||||
.config_to_json = NULL, // TODO oec
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Create a list with the extensions for Age Restriction and Peer2Peer
|
||||
*/
|
||||
static struct TALER_Extension **
|
||||
get_known_extensions ()
|
||||
{
|
||||
|
||||
struct TALER_Extension **list = GNUNET_new_array (TALER_Extension_Max + 1,
|
||||
struct TALER_Extension *);
|
||||
list[TALER_Extension_AgeRestriction] = &extension_ageRestriction;
|
||||
list[TALER_Extension_Peer2Peer] = &extension_peer2peer;
|
||||
list[TALER_Extension_Max] = NULL;
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
@ -115,7 +162,7 @@ extension_update_event_cb (void *cls,
|
||||
enum GNUNET_DB_QueryStatus qs;
|
||||
|
||||
qs = TEH_plugin->get_extension_config (TEH_plugin->cls,
|
||||
TEH_extensions[type].name,
|
||||
TEH_extensions[type]->name, // FIXME oec
|
||||
&config);
|
||||
|
||||
if (qs < 0)
|
||||
@ -139,22 +186,24 @@ extension_update_event_cb (void *cls,
|
||||
enum GNUNET_GenericReturnValue
|
||||
TEH_extensions_init ()
|
||||
{
|
||||
// TEH_extensions = register_known_extensions();
|
||||
TEH_extensions = get_known_extensions ();
|
||||
|
||||
struct GNUNET_DB_EventHeaderP ev = {
|
||||
.size = htons (sizeof (ev)),
|
||||
.type = htons (TALER_DBEVENT_EXCHANGE_EXTENSIONS_UPDATED),
|
||||
};
|
||||
|
||||
extensions_eh = TEH_plugin->event_listen (TEH_plugin->cls,
|
||||
GNUNET_TIME_UNIT_FOREVER_REL,
|
||||
&ev,
|
||||
&extension_update_event_cb,
|
||||
NULL);
|
||||
if (NULL == extensions_eh)
|
||||
{
|
||||
GNUNET_break (0);
|
||||
return GNUNET_SYSERR;
|
||||
struct GNUNET_DB_EventHeaderP ev = {
|
||||
.size = htons (sizeof (ev)),
|
||||
.type = htons (TALER_DBEVENT_EXCHANGE_EXTENSIONS_UPDATED),
|
||||
};
|
||||
|
||||
extensions_eh = TEH_plugin->event_listen (TEH_plugin->cls,
|
||||
GNUNET_TIME_UNIT_FOREVER_REL,
|
||||
&ev,
|
||||
&extension_update_event_cb,
|
||||
NULL);
|
||||
if (NULL == extensions_eh)
|
||||
{
|
||||
GNUNET_break (0);
|
||||
return GNUNET_SYSERR;
|
||||
}
|
||||
}
|
||||
return GNUNET_OK;
|
||||
}
|
||||
|
@ -128,7 +128,7 @@ set_extensions (void *cls,
|
||||
|
||||
qs = TEH_plugin->set_extension_config (
|
||||
TEH_plugin->cls,
|
||||
TEH_extensions[ext->type].name,
|
||||
TEH_extensions[ext->type]->name, // FIXME oec
|
||||
config,
|
||||
sig);
|
||||
|
||||
@ -258,6 +258,8 @@ TEH_handler_management_post_extensions (
|
||||
|
||||
/* 2. Make sure name refers to a supported extension */
|
||||
if (GNUNET_OK != TALER_get_extension_by_name (name,
|
||||
(const struct
|
||||
TALER_Extension **)
|
||||
TEH_extensions,
|
||||
&extension))
|
||||
{
|
||||
|
@ -72,7 +72,7 @@ struct TALER_Extension
|
||||
*/
|
||||
enum GNUNET_GenericReturnValue
|
||||
TALER_get_extension_by_name (const char *name,
|
||||
const struct TALER_Extension *extensions,
|
||||
const struct TALER_Extension **extensions,
|
||||
const struct TALER_Extension **ext);
|
||||
|
||||
/*
|
||||
@ -112,6 +112,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.
|
||||
|
@ -23,7 +23,6 @@
|
||||
#include "taler_extensions.h"
|
||||
#include "stdint.h"
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param cfg Handle to the GNUNET configuration
|
||||
@ -137,12 +136,14 @@ TALER_parse_age_group_string (char *groups,
|
||||
|
||||
|
||||
/**
|
||||
* 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 (struct TALER_AgeMask *m)
|
||||
TALER_age_mask_to_string (const struct TALER_AgeMask *m)
|
||||
{
|
||||
uint32_t mask = m->mask;
|
||||
unsigned int n = 0;
|
||||
|
@ -25,13 +25,13 @@
|
||||
|
||||
enum GNUNET_GenericReturnValue
|
||||
TALER_get_extension_by_name (const char *name,
|
||||
const struct TALER_Extension *extensions,
|
||||
const struct TALER_Extension **extensions,
|
||||
const struct TALER_Extension **ext)
|
||||
{
|
||||
|
||||
const struct TALER_Extension *it = extensions;
|
||||
const struct TALER_Extension *it = *extensions;
|
||||
|
||||
for (; it->type != TALER_Extension_Max; it++)
|
||||
for (; NULL != it; it++)
|
||||
{
|
||||
if (0 == strncmp (name,
|
||||
it->name,
|
||||
|
Loading…
Reference in New Issue
Block a user