diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/include/taler_templating_lib.h | 17 | ||||
-rw-r--r-- | src/templating/templating_api.c | 25 |
2 files changed, 42 insertions, 0 deletions
diff --git a/src/include/taler_templating_lib.h b/src/include/taler_templating_lib.h index e4f3f1f1c..53946b9c0 100644 --- a/src/include/taler_templating_lib.h +++ b/src/include/taler_templating_lib.h @@ -25,6 +25,23 @@ /** + * Fill in Mustach template @a tmpl using the data from @a root + * and return the result in @a result. + * + * @param tmpl 0-terminated string with Mustach template + * @param root JSON data to fill into the template + * @param[out] result where to write the result + * @param[out] result_size where to write the length of the result + * @return 0 on success, otherwise Mustach-specific error code + */ +int +TALER_TEMPLATING_fill (const char *tmpl, + const json_t *root, + void **result, + size_t *result_size); + + +/** * Load a @a template and substitute using @a root, returning the result in a * @a reply encoded suitable for the @a connection with the given @a * http_status code. On errors, the @a http_status code diff --git a/src/templating/templating_api.c b/src/templating/templating_api.c index 47ada208e..324e199eb 100644 --- a/src/templating/templating_api.c +++ b/src/templating/templating_api.c @@ -171,6 +171,31 @@ make_static_url (struct MHD_Connection *con, } +int +TALER_TEMPLATING_fill (const char *tmpl, + const json_t *root, + void **result, + size_t *result_size) +{ + int eno; + + if (0 != + (eno = mustach_jansson (tmpl, + (json_t *) root, + (char **) result, + result_size))) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "mustach failed on template with error %d\n", + eno); + *result = NULL; + *result_size = 0; + return eno; + } + return eno; +} + + enum GNUNET_GenericReturnValue TALER_TEMPLATING_build (struct MHD_Connection *connection, unsigned int *http_status, |