aboutsummaryrefslogtreecommitdiff
path: root/src/include/taler_util.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/include/taler_util.h')
-rw-r--r--src/include/taler_util.h60
1 files changed, 60 insertions, 0 deletions
diff --git a/src/include/taler_util.h b/src/include/taler_util.h
index 1de264c1..e0473bff 100644
--- a/src/include/taler_util.h
+++ b/src/include/taler_util.h
@@ -21,6 +21,7 @@
#ifndef TALER_UTIL_H
#define TALER_UTIL_H
+#include <gnunet/gnunet_common.h>
#define __TALER_UTIL_LIB_H_INSIDE__
#include <gnunet/gnunet_util_lib.h>
@@ -511,6 +512,33 @@ char *strchrnul (const char *s, int c);
#endif
/**
+ * @brief Parses a date information into days after 1970-01-01 (or 0)
+ *
+ * The input MUST be of the form
+ *
+ * 1) YYYY-MM-DD, representing a valid date
+ * 2) YYYY-MM-00, representing a valid month in a particular year
+ * 3) YYYY-00-00, representing a valid year.
+ *
+ * In the cases 2) and 3) the out parameter is set to the beginning of the
+ * time, f.e. 1950-00-00 == 1950-01-01 and 1888-03-00 == 1888-03-01
+ *
+ * The output will set to the number of days after 1970-01-01 or 0, if the input
+ * represents a date belonging to the largest allowed age group.
+ *
+ * @param in Input string representation of the date
+ * @param mask Age mask
+ * @param[out] out Where to write the result
+ * @return GNUNET_OK on success, GNUNET_SYSERR otherwise
+ */
+enum GNUNET_GenericReturnValue
+TALER_parse_coarse_date (
+ const char *in,
+ const struct TALER_AgeMask *mask,
+ uint32_t *out);
+
+
+/**
* @brief Parses a string as a list of age groups.
*
* The string must consist of a colon-separated list of increasing integers
@@ -558,6 +586,18 @@ char *
TALER_age_mask_to_string (
const struct TALER_AgeMask *mask);
+/*
+ * @brief returns the age group of a given age for a given age mask
+ *
+ * @param mask Age mask
+ * @param age The given age
+ * @return age group
+ */
+uint8_t
+TALER_get_age_group (
+ const struct TALER_AgeMask *mask,
+ uint8_t age);
+
/**
* @brief Parses a JSON object { "age_groups": "a:b:...y:z" }.
*
@@ -570,6 +610,26 @@ TALER_JSON_parse_age_groups (const json_t *root,
struct TALER_AgeMask *mask);
+/* @brief Return the lowest age in the corresponding group for a given age
+ * according the given age mask.
+ *
+ * @param[IN] mask age mask
+ * @param[IN] age age to check
+ * @return lowest age in corresponding age group
+ */
+uint8_t
+TALER_get_lowest_age (
+ const struct TALER_AgeMask *mask,
+ uint8_t age);
+
+/* @brief Get the lowest age for the largest age group
+ *
+ * @param mask the age mask
+ * @return lowest age for the largest age group
+ */
+#define TALER_adult_age(mask) \
+ sizeof((mask)->bits) * 8 - __builtin_clz ((mask)->bits) - 1
+
/**
* Handle to an external process that will assist
* with some JSON-to-JSON conversion.