mirror of
git://git.code.sf.net/p/dhcpd-pools/code
synced 2025-12-17 16:26:59 +00:00
output: add must_put_err() utility function
This function deals situation when mustach put happens before enter, that is
a sign of an invalid input template. Good side of adding this function is
that dhcpd-pools does not need to modify code provided by Jose.
Reference: 66183bc7c7
Proposed-by: José Bollo <jobol@nonadev.net>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
This commit is contained in:
parent
4fc4bcd083
commit
e4baff79bd
2 changed files with 11 additions and 4 deletions
|
|
@ -61,11 +61,20 @@ struct expl {
|
||||||
static int must_enter(void *closure, const char *name);
|
static int must_enter(void *closure, const char *name);
|
||||||
static int must_leave(void *closure);
|
static int must_leave(void *closure);
|
||||||
|
|
||||||
|
/* This can be called when template is invalid end put happens before enter. */
|
||||||
|
int must_put_err(void *closure __attribute__ ((unused)),
|
||||||
|
const char *name __attribute__ ((unused)),
|
||||||
|
int escape __attribute__ ((unused)),
|
||||||
|
FILE *file __attribute__ ((unused)))
|
||||||
|
{
|
||||||
|
return MUSTACH_ERROR_SYSTEM;
|
||||||
|
}
|
||||||
|
|
||||||
/* Set mustach function pointers. */
|
/* Set mustach function pointers. */
|
||||||
static struct mustach_itf itf = {
|
static struct mustach_itf itf = {
|
||||||
.start = NULL,
|
.start = NULL,
|
||||||
.enter = must_enter,
|
.enter = must_enter,
|
||||||
.put = NULL,
|
.put = must_put_err,
|
||||||
.next = NULL,
|
.next = NULL,
|
||||||
.leave = must_leave
|
.leave = must_leave
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,7 @@ static int getpartial(struct mustach_itf *itf, void *closure, const char *name,
|
||||||
|
|
||||||
*result = NULL;
|
*result = NULL;
|
||||||
file = open_memstream(result, &size);
|
file = open_memstream(result, &size);
|
||||||
if (itf->put == NULL || file == NULL)
|
if (file == NULL)
|
||||||
rc = MUSTACH_ERROR_SYSTEM;
|
rc = MUSTACH_ERROR_SYSTEM;
|
||||||
else {
|
else {
|
||||||
rc = itf->put(closure, name, 0, file);
|
rc = itf->put(closure, name, 0, file);
|
||||||
|
|
@ -192,8 +192,6 @@ static int process(const char *template, struct mustach_itf *itf, void *closure,
|
||||||
default:
|
default:
|
||||||
/* replacement */
|
/* replacement */
|
||||||
if (emit) {
|
if (emit) {
|
||||||
if (itf->put == NULL)
|
|
||||||
return MUSTACH_ERROR_SYSTEM;
|
|
||||||
rc = itf->put(closure, name, c != '&', file);
|
rc = itf->put(closure, name, c != '&', file);
|
||||||
if (rc < 0)
|
if (rc < 0)
|
||||||
return rc;
|
return rc;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue