From 9a3e3e396442918099d44f0bcc9184007ecbef35 Mon Sep 17 00:00:00 2001 From: "C. McEnroe" Date: Mon, 13 Apr 2020 13:56:59 -0400 Subject: Allow NULL vars and escape to templateRender --- template.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/template.c b/template.c index 750f339..fed3202 100644 --- a/template.c +++ b/template.c @@ -24,6 +24,11 @@ #include "archive.h" +static int escapeNull(FILE *file, const char *str) { + size_t n = fwrite(str, strlen(str), 1, file); + return (n ? 0 : -1); +} + int escapeURL(FILE *file, const char *str) { static const char *Safe = { "$-_.+!*'()," @@ -70,11 +75,12 @@ int templateRender( FILE *file, const char *template, const struct Variable vars[], EscapeFn *escape ) { + if (!escape) escape = escapeNull; for (bool subst = false; *template; subst ^= true) { size_t len = strcspn(template, "[]"); if (subst) { const char *value = NULL; - for (const struct Variable *var = vars; var->name; ++var) { + for (const struct Variable *var = vars; var && var->name; ++var) { if (strlen(var->name) != len) continue; if (strncmp(var->name, template, len)) continue; value = var->value; @@ -103,15 +109,14 @@ char *templateURL(const char *template, const struct Variable vars[]) { for (const struct Variable *var = vars; var->name; ++var) { cap += 3 * strlen(var->value); } - char *buf = malloc(cap); if (!buf) err(EX_OSERR, "malloc"); FILE *file = fmemopen(buf, cap, "w"); if (!file) err(EX_OSERR, "fmemopen"); - int error = templateRender(file, template, vars, escapeURL) || fclose(file); + int error = templateRender(file, template, vars, escapeURL) + || fclose(file); assert(!error); - return buf; } -- cgit 1.4.1 9a4c70b9e14904'/>
path: root/Linux.mk (unfollow)
Commit message (Collapse)Author
2020-01-20Use Xr for first "litterbox" in README 1.0June McEnroe
2020-01-20Introduce pounce link in READMEJune McEnroe
2020-01-18Use < for beforeJune McEnroe
2020-01-18Rearrange code in scoopJune McEnroe
2020-01-16Add scoop flag for local timeJune McEnroe
2020-01-14Remove note about usernames for pounceJune McEnroe
This is done automatically with the causal.agency/passive capability now.
2020-01-14Reference IRCv3.1 SASL specJune McEnroe
2020-01-14Ensure ansi resets formatting and null-terminatesJune McEnroe
fmemopen in text-mode only ensures the buffer is null-terminated if the last write does not fill the buffer.
2020-01-14Implement IRC formatting to ANSI translationJune McEnroe
2020-01-14Add -b flag for live backupJune McEnroe
2020-01-14Add columnsize = 0 option to FTS indexJune McEnroe
Since we don't use ranking functions and I don't see them being useful, there is no point in having columnsize, which just takes extra space in the database. In my database of approximately 3.5 million events, disabling columnsize saves about 62 MB. The migration unfortunately has to rebuild the entire index to disable it.
2020-01-12Add option for client cert and SASL EXTERNALJune McEnroe
2020-01-12Add Linux.mkJune McEnroe
2020-01-11Fix unscoop dedup window syntaxJune McEnroe
2020-01-11Bump busy timeout to 10sJune McEnroe