summaryrefslogtreecommitdiff
path: root/src/json/json_helper.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2021-12-14 16:04:32 +0100
committerChristian Grothoff <christian@grothoff.org>2021-12-14 16:04:40 +0100
commit1a1fafbd438f3f21a15c990d904e192b045d2391 (patch)
treecdd32023fd1d7c530caeae0487528d7eaac2aa29 /src/json/json_helper.c
parentbf54ee30d4727217264f470321cc2f91facf63cc (diff)
downloadexchange-1a1fafbd438f3f21a15c990d904e192b045d2391.tar.gz
exchange-1a1fafbd438f3f21a15c990d904e192b045d2391.tar.bz2
exchange-1a1fafbd438f3f21a15c990d904e192b045d2391.zip
introducing GNUNET_TIME_Timestamp, recoup now with amounts
Diffstat (limited to 'src/json/json_helper.c')
-rw-r--r--src/json/json_helper.c213
1 files changed, 0 insertions, 213 deletions
diff --git a/src/json/json_helper.c b/src/json/json_helper.c
index 7c01cde0c..949354e24 100644
--- a/src/json/json_helper.c
+++ b/src/json/json_helper.c
@@ -216,219 +216,6 @@ TALER_JSON_spec_amount_any_nbo (const char *name,
/**
- * Parse given JSON object to *rounded* absolute time.
- *
- * @param cls closure, NULL
- * @param root the json object representing data
- * @param[out] spec where to write the data
- * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error
- */
-static enum GNUNET_GenericReturnValue
-parse_abs_time (void *cls,
- json_t *root,
- struct GNUNET_JSON_Specification *spec)
-{
- struct GNUNET_TIME_Absolute *abs = spec->ptr;
- json_t *json_t_ms;
- unsigned long long int tval;
-
- (void) cls;
- if (! json_is_object (root))
- {
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
- json_t_ms = json_object_get (root,
- "t_ms");
- if (json_is_integer (json_t_ms))
- {
- tval = json_integer_value (json_t_ms);
- /* Time is in milliseconds in JSON, but in microseconds in GNUNET_TIME_Absolute */
- abs->abs_value_us = tval * 1000LL;
- if ((abs->abs_value_us) / 1000LL != tval)
- {
- /* Integer overflow */
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
- if (GNUNET_OK !=
- GNUNET_TIME_round_abs (abs))
- {
- /* time not rounded */
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
- return GNUNET_OK;
- }
- if (json_is_string (json_t_ms))
- {
- const char *val;
-
- val = json_string_value (json_t_ms);
- if ((0 == strcasecmp (val, "never")))
- {
- *abs = GNUNET_TIME_UNIT_FOREVER_ABS;
- return GNUNET_OK;
- }
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "`%s' is not a valid absolute time\n",
- json_string_value (json_t_ms));
- return GNUNET_SYSERR;
- }
- return GNUNET_SYSERR;
-}
-
-
-struct GNUNET_JSON_Specification
-TALER_JSON_spec_absolute_time (const char *name,
- struct GNUNET_TIME_Absolute *r_time)
-{
- struct GNUNET_JSON_Specification ret = {
- .parser = &parse_abs_time,
- .cleaner = NULL,
- .cls = NULL,
- .field = name,
- .ptr = r_time,
- .ptr_size = sizeof(struct GNUNET_TIME_Absolute),
- .size_ptr = NULL
- };
-
- return ret;
-}
-
-
-/**
- * Parse given JSON object to absolute time.
- *
- * @param cls closure, NULL
- * @param root the json object representing data
- * @param[out] spec where to write the data
- * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error
- */
-static enum GNUNET_GenericReturnValue
-parse_abs_time_nbo (void *cls,
- json_t *root,
- struct GNUNET_JSON_Specification *spec)
-{
- struct GNUNET_TIME_AbsoluteNBO *abs = spec->ptr;
- struct GNUNET_TIME_Absolute a;
- struct GNUNET_JSON_Specification ispec;
-
- (void) cls;
- ispec = *spec;
- ispec.parser = &parse_abs_time;
- ispec.ptr = &a;
- if (GNUNET_OK !=
- parse_abs_time (NULL,
- root,
- &ispec))
- {
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
- *abs = GNUNET_TIME_absolute_hton (a);
- return GNUNET_OK;
-}
-
-
-struct GNUNET_JSON_Specification
-TALER_JSON_spec_absolute_time_nbo (const char *name,
- struct GNUNET_TIME_AbsoluteNBO *r_time)
-{
- struct GNUNET_JSON_Specification ret = {
- .parser = &parse_abs_time_nbo,
- .cleaner = NULL,
- .cls = NULL,
- .field = name,
- .ptr = r_time,
- .ptr_size = sizeof(struct GNUNET_TIME_AbsoluteNBO),
- .size_ptr = NULL
- };
-
- return ret;
-}
-
-
-/**
- * Parse given JSON object to relative time.
- *
- * @param cls closure, NULL
- * @param root the json object representing data
- * @param[out] spec where to write the data
- * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error
- */
-static enum GNUNET_GenericReturnValue
-parse_rel_time (void *cls,
- json_t *root,
- struct GNUNET_JSON_Specification *spec)
-{
- struct GNUNET_TIME_Relative *rel = spec->ptr;
- json_t *json_d_ms;
- unsigned long long int tval;
-
- (void) cls;
- if (! json_is_object (root))
- {
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
- json_d_ms = json_object_get (root, "d_ms");
- if (json_is_integer (json_d_ms))
- {
- tval = json_integer_value (json_d_ms);
- /* Time is in milliseconds in JSON, but in microseconds in GNUNET_TIME_Absolute */
- rel->rel_value_us = tval * 1000LL;
- if ((rel->rel_value_us) / 1000LL != tval)
- {
- /* Integer overflow */
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
- if (GNUNET_OK !=
- GNUNET_TIME_round_rel (rel))
- {
- /* time not rounded */
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
- return GNUNET_OK;
- }
- if (json_is_string (json_d_ms))
- {
- const char *val;
- val = json_string_value (json_d_ms);
- if ((0 == strcasecmp (val, "forever")))
- {
- *rel = GNUNET_TIME_UNIT_FOREVER_REL;
- return GNUNET_OK;
- }
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
-}
-
-
-struct GNUNET_JSON_Specification
-TALER_JSON_spec_relative_time (const char *name,
- struct GNUNET_TIME_Relative *r_time)
-{
- struct GNUNET_JSON_Specification ret = {
- .parser = &parse_rel_time,
- .cleaner = NULL,
- .cls = NULL,
- .field = name,
- .ptr = r_time,
- .ptr_size = sizeof(struct GNUNET_TIME_Relative),
- .size_ptr = NULL
- };
-
- return ret;
-}
-
-
-/**
* Parse given JSON object to denomination public key.
*
* @param cls closure, NULL