aboutsummaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
authorÖzgür Kesim <oec-taler@kesim.org>2022-01-23 01:31:02 +0100
committerÖzgür Kesim <oec-taler@kesim.org>2022-01-23 01:36:21 +0100
commit8684a9bfea9223808e33edca9f91b8bd76379fd0 (patch)
tree2354ad02b8ea515fe2de64cb8a42ca078f9f8b64 /src/util
parent1962ed6b0b44c6c7d3503b3340da1be147e25f87 (diff)
[age_restriction] progress 13/n
- major refactoring of extensions - extensions live now in a separate library, libtalerextensions - refactored all components using age_restriction accordingly - plumbing for plugin support for extensions roughly layed down
Diffstat (limited to 'src/util')
-rw-r--r--src/util/Makefile.am2
-rw-r--r--src/util/extension_age_restriction.c169
-rw-r--r--src/util/extensions.c49
3 files changed, 0 insertions, 220 deletions
diff --git a/src/util/Makefile.am b/src/util/Makefile.am
index 55ebb4dff..35e580347 100644
--- a/src/util/Makefile.am
+++ b/src/util/Makefile.am
@@ -72,8 +72,6 @@ libtalerutil_la_SOURCES = \
crypto_wire.c \
denom.c \
exchange_signatures.c \
- extensions.c \
- extension_age_restriction.c \
getopt.c \
lang.c \
iban.c \
diff --git a/src/util/extension_age_restriction.c b/src/util/extension_age_restriction.c
deleted file mode 100644
index 0b04c7d7b..000000000
--- a/src/util/extension_age_restriction.c
+++ /dev/null
@@ -1,169 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2014-2020 Taler Systems SA
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU 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 General Public License for more details.
-
- You should have received a copy of the GNU General Public License along with
- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
- */
-/**
- * @file extension_age_restriction.c
- * @brief Utility functions regarding age restriction
- * @author Özgür Kesim
- */
-#include "platform.h"
-#include "taler_util.h"
-#include "taler_extensions.h"
-#include "stdint.h"
-
-/**
- *
- * @param cfg Handle to the GNUNET configuration
- * @param[out] Mask for age restriction. Will be 0 if age restriction was not enabled in the config.
- * @return Error if extension for age restriction was set, but age groups were
- * invalid, OK otherwise.
- */
-enum GNUNET_GenericReturnValue
-TALER_get_age_mask (const struct GNUNET_CONFIGURATION_Handle *cfg,
- struct TALER_AgeMask *mask)
-{
- char *groups;
- enum GNUNET_GenericReturnValue ret = GNUNET_SYSERR;
-
- if ((GNUNET_YES != GNUNET_CONFIGURATION_have_value (cfg,
- TALER_EXTENSION_SECTION_AGE_RESTRICTION,
- "ENABLED")) ||
- (GNUNET_YES != GNUNET_CONFIGURATION_get_value_yesno (cfg,
- TALER_EXTENSION_SECTION_AGE_RESTRICTION,
- "ENABLED")))
- {
- /* Age restriction is not enabled */
- mask->mask = 0;
- return GNUNET_OK;
- }
-
- /* Age restriction is enabled, extract age groups */
- if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg,
- TALER_EXTENSION_SECTION_AGE_RESTRICTION,
- "AGE_GROUPS",
- &groups))
- {
- /* FIXME: log error? */
- return GNUNET_SYSERR;
- }
- if (groups == NULL)
- {
- /* No groups defined in config, return default_age_mask */
- mask->mask = TALER_EXTENSION_DEFAULT_AGE_MASK;
- return GNUNET_OK;
- }
-
- ret = TALER_parse_age_group_string (groups, mask);
- GNUNET_free (groups);
- return ret;
-}
-
-
-/**
- * @param groups String representation of the age groups. Must be of the form
- * a:b:...:n:m
- * with
- * 0 < a < b <...< n < m < 32
- * @param[out] mask Bit representation of the age groups.
- * @return Error if string was invalid, OK otherwise.
- */
-enum GNUNET_GenericReturnValue
-TALER_parse_age_group_string (const char *groups,
- struct TALER_AgeMask *mask)
-{
-
- const char *pos = groups;
- unsigned int prev = 0;
- unsigned int val = 0;
- char c;
-
- while (*pos)
- {
- c = *pos++;
- if (':' == c)
- {
- if (prev >= val)
- return GNUNET_SYSERR;
-
- mask->mask |= 1 << val;
- prev = val;
- val = 0;
- continue;
- }
-
- if ('0'>c || '9'<c)
- return GNUNET_SYSERR;
-
- val = 10 * val + c - '0';
-
- if (0>=val || 32<=val)
- return GNUNET_SYSERR;
- }
-
- if (0>val || 32<=val || prev>=val)
- return GNUNET_SYSERR;
-
- mask->mask |= (1 << val);
- mask->mask |= 1; // mark zeroth group, too
-
- return GNUNET_OK;
-}
-
-
-/**
- * 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 *m)
-{
- uint32_t mask = m->mask;
- unsigned int n = 0;
- char *buf = GNUNET_malloc (32 * 3); // max characters possible
- char *pos = buf;
-
- if (NULL == buf)
- {
- return buf;
- }
-
- while (mask != 0)
- {
- mask >>= 1;
- n++;
- if (0 == (mask & 1))
- {
- continue;
- }
-
- if (n > 9)
- {
- *(pos++) = '0' + n / 10;
- }
- *(pos++) = '0' + n % 10;
-
- if (0 != (mask >> 1))
- {
- *(pos++) = ':';
- }
- }
- return buf;
-}
-
-
-/* end of extension_age_restriction.c */
diff --git a/src/util/extensions.c b/src/util/extensions.c
deleted file mode 100644
index 87dd16b4d..000000000
--- a/src/util/extensions.c
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- 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 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 General Public License for more details.
-
- You should have received a copy of the GNU General Public License along with
- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
- */
-/**
- * @file extensions.c
- * @brief Utility functions for extensions
- * @author Özgür Kesim
- */
-#include "platform.h"
-#include "taler_util.h"
-#include "taler_extensions.h"
-#include "stdint.h"
-
-enum GNUNET_GenericReturnValue
-TALER_extension_get_by_name (const char *name,
- const struct TALER_Extension **extensions,
- const struct TALER_Extension **ext)
-{
-
- const struct TALER_Extension *it = *extensions;
-
- for (; NULL != it; it++)
- {
- if (0 == strncmp (name,
- it->name,
- strlen (it->name)))
- {
- *ext = it;
- return GNUNET_OK;
- }
- }
-
- return GNUNET_NO;
-}
-
-
-/* end of extensions.c */