first steps adding extension data structures
This commit is contained in:
parent
96304043fb
commit
fe18b02ab6
@ -750,7 +750,7 @@ load_age_mask (const char*section_name)
|
||||
struct TALER_AgeMask age_mask = {0};
|
||||
|
||||
/* FIXME-oec: get age_mask from database, not from config */
|
||||
if (TALER_EXTENSION_OK != TALER_get_age_mask (TEH_cfg, &age_mask))
|
||||
if (TALER_Extension_OK != TALER_get_age_mask (TEH_cfg, &age_mask))
|
||||
{
|
||||
GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR,
|
||||
TALER_EXTENSION_SECTION_AGE_RESTRICTION,
|
||||
@ -761,6 +761,9 @@ load_age_mask (const char*section_name)
|
||||
|
||||
if (age_mask.mask == 0)
|
||||
{
|
||||
/* Age restriction support is not enabled. Ignore the AGE_RESTRICTED field
|
||||
* for the particular denomination and simply return the null_mask
|
||||
*/
|
||||
return null_mask;
|
||||
}
|
||||
|
||||
|
@ -1,18 +1,18 @@
|
||||
/*
|
||||
This file is part of TALER
|
||||
Copyright (C) 2014-2021 Taler Systems SA
|
||||
This file is part of TALER
|
||||
Copyright (C) 2014-2021 Taler Systems SA
|
||||
|
||||
TALER is free software; you can redistribute it and/or modify it under the
|
||||
terms of the GNU Affero General Public License as published by the Free Software
|
||||
Foundation; either version 3, or (at your option) any later version.
|
||||
TALER is free software; you can redistribute it and/or modify it under the
|
||||
terms of the GNU Affero General Public License as published by the Free Software
|
||||
Foundation; either version 3, or (at your option) any later version.
|
||||
|
||||
TALER is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
||||
A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
|
||||
TALER is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
||||
A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License along with
|
||||
TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
You should have received a copy of the GNU Affero General Public License along with
|
||||
TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
/**
|
||||
* @file include/taler_exchange_service.h
|
||||
* @brief C interface of libtalerexchange, a C library to use exchange's HTTP API
|
||||
@ -1527,7 +1527,7 @@ typedef void
|
||||
*
|
||||
* @param exchange the exchange handle; the exchange must be ready to operate
|
||||
* @param refresh_data the refresh data as returned from
|
||||
#TALER_EXCHANGE_refresh_prepare())
|
||||
#TALER_EXCHANGE_refresh_prepare())
|
||||
* @param melt_cb the callback to call with the result
|
||||
* @param melt_cb_cls closure for @a melt_cb
|
||||
* @return a handle for this request; NULL if the argument was invalid.
|
||||
@ -1593,7 +1593,7 @@ struct TALER_EXCHANGE_RefreshesRevealHandle;
|
||||
*
|
||||
* @param exchange the exchange handle; the exchange must be ready to operate
|
||||
* @param refresh_data the refresh data as returned from
|
||||
#TALER_EXCHANGE_refresh_prepare())
|
||||
#TALER_EXCHANGE_refresh_prepare())
|
||||
* @param noreveal_index response from the exchange to the
|
||||
* #TALER_EXCHANGE_melt() invocation
|
||||
* @param reveal_cb the callback to call with the final result of the
|
||||
@ -2619,8 +2619,9 @@ TALER_EXCHANGE_post_management_keys_cancel (
|
||||
*/
|
||||
struct TALER_EXCHANGE_ManagementPostExtensionsData
|
||||
{
|
||||
|
||||
/* FIXME-oec: define data structure */
|
||||
struct TALER_Extension *extensions;
|
||||
struct TALER_MasterSignatureP *extension_sigs;
|
||||
uint32_t num_extensions;
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -26,17 +26,63 @@
|
||||
|
||||
#define TALER_EXTENSION_SECTION_PREFIX "exchange-extension-"
|
||||
|
||||
enum TALER_EXTENSION_ReturnValue
|
||||
enum TALER_Extension_ReturnValue
|
||||
{
|
||||
TALER_EXTENSION_OK = 0,
|
||||
TALER_EXTENSION_ERROR_PARSING = 1,
|
||||
TALER_EXTENSION_ERROR_INVALID = 2,
|
||||
TALER_EXTENSION_ERROR_SYS = 3
|
||||
TALER_Extension_OK = 0,
|
||||
TALER_Extension_ERROR_PARSING = 1,
|
||||
TALER_Extension_ERROR_INVALID = 2,
|
||||
TALER_Extension_ERROR_SYS = 3
|
||||
};
|
||||
|
||||
enum TALER_Extension_Type
|
||||
{
|
||||
TALER_Extension_Peer2Peer = 0,
|
||||
TALER_Extension_AgeRestriction = 1
|
||||
};
|
||||
|
||||
struct TALER_Extension
|
||||
{
|
||||
enum TALER_Extension_Type type;
|
||||
char *name;
|
||||
bool critical;
|
||||
void *config;
|
||||
size_t config_size;
|
||||
};
|
||||
|
||||
struct TALER_Peer2Peer_Config
|
||||
{
|
||||
// FIXME
|
||||
};
|
||||
|
||||
/**
|
||||
* g_TALER_Extensions_by_Type is the global manifest with the list supported
|
||||
* extensions, sorted by TALER_Extension_Type.
|
||||
*
|
||||
* TODO: Mutex?
|
||||
*
|
||||
**/
|
||||
struct TALER_Extension g_TALER_Extensions_by_Type[] = {
|
||||
[TALER_Extension_Peer2Peer] = {
|
||||
.type = TALER_Extension_Peer2Peer,
|
||||
.name = "peer2peer",
|
||||
.critical = false,
|
||||
.config_size = sizeof(struct TALER_Peer2Peer_Config),
|
||||
},
|
||||
[TALER_Extension_AgeRestriction] = {
|
||||
.type = TALER_Extension_AgeRestriction,
|
||||
.name = "age_restriction",
|
||||
.critical = false,
|
||||
.config_size = sizeof(struct TALER_AgeMask),
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* TALER Age Restriction Extensions
|
||||
* TALER Peer2Peer Extension
|
||||
*/
|
||||
|
||||
/*
|
||||
* TALER Age Restriction Extension
|
||||
*/
|
||||
|
||||
#define TALER_EXTENSION_SECTION_AGE_RESTRICTION (TALER_EXTENSION_SECTION_PREFIX \
|
||||
@ -55,7 +101,7 @@ enum TALER_EXTENSION_ReturnValue
|
||||
* @param[out] mask Mask representation for age restriction.
|
||||
* @return Error, if age groups were invalid, OK otherwise.
|
||||
*/
|
||||
enum TALER_EXTENSION_ReturnValue
|
||||
enum TALER_Extension_ReturnValue
|
||||
TALER_parse_age_group_string (char *groups,
|
||||
struct TALER_AgeMask *mask);
|
||||
|
||||
@ -66,8 +112,7 @@ TALER_parse_age_group_string (char *groups,
|
||||
* @return Error if extension for age restriction was set but age groups were
|
||||
* invalid, OK otherwise.
|
||||
*/
|
||||
enum TALER_EXTENSION_ReturnValue
|
||||
enum TALER_Extension_ReturnValue
|
||||
TALER_get_age_mask (const struct GNUNET_CONFIGURATION_Handle *cfg,
|
||||
struct TALER_AgeMask *mask);
|
||||
|
||||
#endif
|
||||
|
@ -22,6 +22,7 @@
|
||||
#include "platform.h"
|
||||
#include "taler_json_lib.h"
|
||||
#include <gnunet/gnunet_curl_lib.h>
|
||||
#include "taler_extensions.h"
|
||||
#include "taler_exchange_service.h"
|
||||
#include "taler_signatures.h"
|
||||
#include "taler_curl_lib.h"
|
||||
@ -131,11 +132,9 @@ TALER_EXCHANGE_management_post_extensions (
|
||||
struct TALER_EXCHANGE_ManagementPostExtensionsHandle *ph;
|
||||
// FIXME-oec: TODO!
|
||||
CURL *eh = NULL;
|
||||
/*
|
||||
json_t *body;
|
||||
json_t *denom_sigs;
|
||||
json_t *signkey_sigs;
|
||||
*/
|
||||
json_t *extensions = NULL;
|
||||
json_t *extension_sigs = NULL;
|
||||
|
||||
ph = GNUNET_new (struct TALER_EXCHANGE_ManagementPostExtensionsHandle);
|
||||
ph->cb = cb;
|
||||
@ -151,44 +150,57 @@ TALER_EXCHANGE_management_post_extensions (
|
||||
GNUNET_free (ph);
|
||||
return NULL;
|
||||
}
|
||||
/*
|
||||
denom_sigs = json_array ();
|
||||
GNUNET_assert (NULL != denom_sigs);
|
||||
for (unsigned int i = 0; i<pkd->num_denom_sigs; i++)
|
||||
extensions = json_array ();
|
||||
GNUNET_assert (NULL != extensions);
|
||||
for (unsigned int i = 0; i<pkd->num_extensions; i++)
|
||||
{
|
||||
const struct TALER_EXCHANGE_DenominationKeySignature *dks
|
||||
= &pkd->denom_sigs[i];
|
||||
json_t *config;
|
||||
const struct TALER_Extension *ext
|
||||
= &pkd->extensions[i];
|
||||
|
||||
switch (ext->type)
|
||||
{
|
||||
// TODO: case TALER_Extension_Peer2Peer
|
||||
case TALER_Extension_AgeRestriction:
|
||||
struct TALER_AgeMask *mask = (struct TALER_AgeMask *) (&ext->config);
|
||||
config = GNUNET_JSON_PACK (GNUNET_JSON_pack_data_auto ("mask",
|
||||
&mask->mask));
|
||||
GNUNET_assert (NULL != config);
|
||||
break;
|
||||
default:
|
||||
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
|
||||
"Extension not supported.\n");
|
||||
}
|
||||
|
||||
GNUNET_assert (0 ==
|
||||
json_array_append_new (
|
||||
denom_sigs,
|
||||
extensions,
|
||||
GNUNET_JSON_PACK (
|
||||
GNUNET_JSON_pack_data_auto ("h_denom_pub",
|
||||
&dks->h_denom_pub),
|
||||
GNUNET_JSON_pack_data_auto ("master_sig",
|
||||
&dks->master_sig))));
|
||||
GNUNET_JSON_pack_data_auto ("extension",
|
||||
&ext->name),
|
||||
GNUNET_JSON_pack_data_auto ("config",
|
||||
config)
|
||||
)));
|
||||
}
|
||||
signkey_sigs = json_array ();
|
||||
GNUNET_assert (NULL != signkey_sigs);
|
||||
for (unsigned int i = 0; i<pkd->num_sign_sigs; i++)
|
||||
extension_sigs = json_array ();
|
||||
GNUNET_assert (NULL != extension_sigs);
|
||||
for (unsigned int i = 0; i<pkd->num_extensions; i++)
|
||||
{
|
||||
const struct TALER_EXCHANGE_SigningKeySignature *sks
|
||||
= &pkd->sign_sigs[i];
|
||||
const struct TALER_MasterSignatureP *sks
|
||||
= &pkd->extension_sigs[i];
|
||||
|
||||
GNUNET_assert (0 ==
|
||||
json_array_append_new (
|
||||
signkey_sigs,
|
||||
extension_sigs,
|
||||
GNUNET_JSON_PACK (
|
||||
GNUNET_JSON_pack_data_auto ("exchange_pub",
|
||||
&sks->exchange_pub),
|
||||
GNUNET_JSON_pack_data_auto ("master_sig",
|
||||
&sks->master_sig))));
|
||||
GNUNET_JSON_pack_data_auto ("extension_sig",
|
||||
&sks->eddsa_signature))));
|
||||
}
|
||||
body = GNUNET_JSON_PACK (
|
||||
GNUNET_JSON_pack_array_steal ("denom_sigs",
|
||||
denom_sigs),
|
||||
GNUNET_JSON_pack_array_steal ("signkey_sigs",
|
||||
signkey_sigs));
|
||||
GNUNET_JSON_pack_array_steal ("extensions",
|
||||
extensions),
|
||||
GNUNET_JSON_pack_array_steal ("extension_sigs",
|
||||
extension_sigs));
|
||||
eh = curl_easy_init ();
|
||||
GNUNET_assert (NULL != eh);
|
||||
if (GNUNET_OK !=
|
||||
@ -209,7 +221,6 @@ TALER_EXCHANGE_management_post_extensions (
|
||||
GNUNET_assert (CURLE_OK == curl_easy_setopt (eh,
|
||||
CURLOPT_URL,
|
||||
ph->url));
|
||||
*/
|
||||
ph->job = GNUNET_CURL_job_add2 (ctx,
|
||||
eh,
|
||||
ph->post_ctx.headers,
|
||||
@ -228,7 +239,6 @@ void
|
||||
TALER_EXCHANGE_post_management_extensions_cancel (
|
||||
struct TALER_EXCHANGE_ManagementPostExtensionsHandle *ph)
|
||||
{
|
||||
/* FIXME-oec: TODO
|
||||
if (NULL != ph->job)
|
||||
{
|
||||
GNUNET_CURL_job_cancel (ph->job);
|
||||
@ -237,5 +247,4 @@ TALER_EXCHANGE_post_management_extensions_cancel (
|
||||
TALER_curl_easy_post_finished (&ph->post_ctx);
|
||||
GNUNET_free (ph->url);
|
||||
GNUNET_free (ph);
|
||||
*/
|
||||
}
|
||||
|
@ -31,12 +31,12 @@
|
||||
* @return Error if extension for age restriction was set, but age groups were
|
||||
* invalid, OK otherwise.
|
||||
*/
|
||||
enum TALER_EXTENSION_ReturnValue
|
||||
enum TALER_Extension_ReturnValue
|
||||
TALER_get_age_mask (const struct GNUNET_CONFIGURATION_Handle *cfg,
|
||||
struct TALER_AgeMask *mask)
|
||||
{
|
||||
char *groups;
|
||||
enum TALER_EXTENSION_ReturnValue ret = TALER_EXTENSION_ERROR_SYS;
|
||||
enum TALER_Extension_ReturnValue ret = TALER_Extension_ERROR_SYS;
|
||||
|
||||
if ((GNUNET_NO == GNUNET_CONFIGURATION_have_value (cfg,
|
||||
TALER_EXTENSION_SECTION_AGE_RESTRICTION,
|
||||
@ -47,7 +47,7 @@ TALER_get_age_mask (const struct GNUNET_CONFIGURATION_Handle *cfg,
|
||||
{
|
||||
/* Age restriction is not enabled */
|
||||
mask->mask = 0;
|
||||
return TALER_EXTENSION_OK;
|
||||
return TALER_Extension_OK;
|
||||
}
|
||||
|
||||
/* Age restriction is enabled, extract age groups */
|
||||
@ -57,13 +57,13 @@ TALER_get_age_mask (const struct GNUNET_CONFIGURATION_Handle *cfg,
|
||||
&groups))
|
||||
{
|
||||
/* FIXME: log error? */
|
||||
return TALER_EXTENSION_ERROR_SYS;
|
||||
return TALER_Extension_ERROR_SYS;
|
||||
}
|
||||
if (groups == NULL)
|
||||
{
|
||||
/* No groups defined in config, return default_age_mask */
|
||||
mask->mask = TALER_EXTENSION_DEFAULT_AGE_MASK;
|
||||
return TALER_EXTENSION_OK;
|
||||
return TALER_Extension_OK;
|
||||
}
|
||||
|
||||
ret = TALER_parse_age_group_string (groups, mask);
|
||||
@ -80,11 +80,11 @@ TALER_get_age_mask (const struct GNUNET_CONFIGURATION_Handle *cfg,
|
||||
* @param[out] mask Bit representation of the age groups.
|
||||
* @return Error if string was invalid, OK otherwise.
|
||||
*/
|
||||
enum TALER_EXTENSION_ReturnValue
|
||||
enum TALER_Extension_ReturnValue
|
||||
TALER_parse_age_group_string (char *groups,
|
||||
struct TALER_AgeMask *mask)
|
||||
{
|
||||
enum TALER_EXTENSION_ReturnValue ret = TALER_EXTENSION_ERROR_SYS;
|
||||
enum TALER_Extension_ReturnValue ret = TALER_Extension_ERROR_SYS;
|
||||
char *pos;
|
||||
unsigned int prev = 0;
|
||||
unsigned int val;
|
||||
@ -105,14 +105,14 @@ TALER_parse_age_group_string (char *groups,
|
||||
{
|
||||
/* Invalid input */
|
||||
mask->mask = 0;
|
||||
ret = TALER_EXTENSION_ERROR_PARSING;
|
||||
ret = TALER_Extension_ERROR_PARSING;
|
||||
break;
|
||||
}
|
||||
else if ((0 >= val) || (32 <= val) || (prev >= val))
|
||||
{
|
||||
/* Invalid value */
|
||||
mask->mask = 0;
|
||||
ret = TALER_EXTENSION_ERROR_INVALID;
|
||||
ret = TALER_Extension_ERROR_INVALID;
|
||||
break;
|
||||
}
|
||||
|
||||
@ -123,7 +123,7 @@ TALER_parse_age_group_string (char *groups,
|
||||
{
|
||||
/* We reached the end. Mark zeroth age-group and exit. */
|
||||
mask->mask |= 1;
|
||||
ret = TALER_EXTENSION_OK;
|
||||
ret = TALER_Extension_OK;
|
||||
break;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user