exchange

Base system with REST service to issue digital coins, run by the payment service provider
Log | Files | Refs | Submodules | README | LICENSE

commit a2438f668d4e7a2968a083da52f1b593bc892f0d
parent 7706f7e2fe24198606c77a8c199ef7e7019c9f5c
Author: Christian Grothoff <christian@grothoff.org>
Date:   Tue,  4 Aug 2026 13:48:57 +0200

libtalerjson: introduce TALER_JSON_spec_slug_copy()

Diffstat:
Mmeson.build | 2+-
Msrc/include/taler/taler_json_lib.h | 13+++++++++++++
Msrc/json/json_helper.c | 47+++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 61 insertions(+), 1 deletion(-)

diff --git a/meson.build b/meson.build @@ -282,7 +282,7 @@ if not get_option('only-doc') libltversions = [ ['libtalerutil', '16:0:2'], - ['libtalerjson', '7:0:3'], + ['libtalerjson', '8:0:4'], ['libtalercurl', '0:1:0'], ['libtalerpq', '1:0:0'], ['libtalersq', '0:0:0'], diff --git a/src/include/taler/taler_json_lib.h b/src/include/taler/taler_json_lib.h @@ -613,6 +613,19 @@ TALER_JSON_spec_slug (const char *field, /** + * Generate line in parser specification for slugs (URL-safe identifiers). + * Creates a copy of the original string. + * + * @param field name of the field + * @param[out] slug string to initialize + * @return corresponding field spec + */ +struct GNUNET_JSON_Specification +TALER_JSON_spec_slug_copy (const char *field, + char **slug); + + +/** * Generate line in parser specification for full * "payto://" URIs. * diff --git a/src/json/json_helper.c b/src/json/json_helper.c @@ -1524,6 +1524,53 @@ TALER_JSON_spec_slug (const char *field, /** + * Parse given JSON object to slug. + * + * @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_slug_copy (void *cls, + json_t *root, + struct GNUNET_JSON_Specification *spec) +{ + const char *str; + + (void) cls; + str = json_string_value (root); + if (NULL == str) + { + GNUNET_break_op (0); + return GNUNET_SYSERR; + } + if (! TALER_is_slug (str)) + { + GNUNET_break_op (0); + return GNUNET_SYSERR; + } + *(char **) spec->ptr = GNUNET_strdup (str); + return GNUNET_OK; +} + + +struct GNUNET_JSON_Specification +TALER_JSON_spec_slug_copy (const char *field, + char **slug) +{ + struct GNUNET_JSON_Specification ret = { + .parser = &parse_slug_copy, + .field = field, + .ptr = slug + }; + + *slug = NULL; + return ret; +} + + +/** * Parse given JSON object to payto:// URI. * * @param cls closure, NULL