about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--template.c13
1 files 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;
 }
020-04-26 19:01:02 -0400'>2020-04-26Include Cc address in reply mailtosJune McEnroe 2020-04-26Use %R for RFC numbers in STANDARDS sectionJune McEnroe 2020-04-26Add mailto spec to STANDARDSJune McEnroe 2020-04-26Increase space between nav itemsJune McEnroe 2020-04-26Add mailto address for the archiveJune McEnroe 2020-04-26Put dates on new lines in indexJune McEnroe 2020-04-26Include <> around Message-Id in mailto: URLsJune McEnroe 2020-04-26Add link to index on thread pagesJune McEnroe 2020-04-26Fall back to Content-Type name parameter for attachmentsJune McEnroe 2020-04-26Remove margins in article.message headerJune McEnroe 2020-04-26Generate index.atomJune McEnroe 2020-04-26Generate XHTML content in Atom entriesJune McEnroe 2020-04-25Style index pageJune McEnroe 2020-04-25Render index.htmlJune McEnroe 2020-04-25Wrap <summary> replies count in <data>June McEnroe 2020-04-25Accumulate thread envelopes before concatenationJune McEnroe 2020-04-24Free envelope in concatDataJune McEnroe 2020-04-24Use replyTo address in mailto:June McEnroe 2020-04-23Wrap quoted lines in <q>June McEnroe>June McEnroe 2020-09-10Update catgirl to 1.2June McEnroe 2020-09-09Add pounce-palaver portJune McEnroe 2020-09-09Update pounce to 2.0June McEnroe 2020-09-09Update litterbox to 1.6June McEnroe 2020-08-23Add scooper portJune McEnroe 2020-08-23Add catsit portJune McEnroe 2020-08-13Update pounce to 1.4p2June McEnroe 2020-08-11Update pounce to 1.4p1June McEnroe 2020-08-10Add litterbox portJune McEnroe 2020-08-10Add missing USES=pkgconfig to pounceJune McEnroe