about summary refs log tree commit diff
path: root/atom.c
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2020-11-29 00:50:33 -0500
committerJune McEnroe <june@causal.agency>2020-11-29 00:50:33 -0500
commita4d4e766e38c7c8aa0c842e6de84b912c9fcaed7 (patch)
tree3166fb318dffa213548eb6c1bf6783e7988296d1 /atom.c
parentReplace templateBuffer with templateString (diff)
downloadbubger-a4d4e766e38c7c8aa0c842e6de84b912c9fcaed7.tar.gz
bubger-a4d4e766e38c7c8aa0c842e6de84b912c9fcaed7.zip
Revert to old quoting style in atom
Diffstat (limited to 'atom.c')
-rw-r--r--atom.c110
1 files changed, 52 insertions, 58 deletions
diff --git a/atom.c b/atom.c
index ddfb3f6..16215df 100644
--- a/atom.c
+++ b/atom.c
@@ -41,22 +41,6 @@ static char *atomID(const struct Envelope *envelope) {
 	return templateString("mid:[messageID]", vars, escapeURL);
 }
 
-static int atomAuthor(FILE *file, struct Address addr) {
-	const char *template = {
-		Q(<author>)
-			Q(<name>[name]</name>)
-			Q(<email>[mailbox]@[host]</email>)
-		Q(</author>)
-	};
-	struct Variable vars[] = {
-		{ "name", addressName(addr) },
-		{ "mailbox", addr.mailbox },
-		{ "host", addr.host },
-		{0},
-	};
-	return templateRender(file, template, vars, escapeXML);
-}
-
 static char *atomEntryURL(const struct Envelope *envelope) {
 	struct Variable vars[] = {
 		{ "messageID", envelope->messageID },
@@ -66,26 +50,36 @@ static char *atomEntryURL(const struct Envelope *envelope) {
 	return templateString("/" PATH_MESSAGE, vars, escapeURL);
 }
 
-static const char *atomUpdated(time_t time) {
-	static char buf[sizeof("0000-00-00T00:00:00Z")];
-	strftime(buf, sizeof(buf), "%FT%TZ", gmtime(&time));
-	return buf;
+static int atomAuthor(FILE *file, struct Address addr) {
+	const char *template = Q(
+		<author>
+			<name>[name]</name>
+			<email>[mailbox]@[host]</email>
+		</author>
+	);
+	struct Variable vars[] = {
+		{ "name", addressName(addr) },
+		{ "mailbox", addr.mailbox },
+		{ "host", addr.host },
+		{0},
+	};
+	return templateRender(file, template, vars, escapeXML);
 }
 
 int atomEntryOpen(FILE *file, const struct Envelope *envelope) {
-	const char *template = {
-		Q(<entry>)
-		Q(<id>[id]</id>)
-		Q(<title>[title]</title>)
-		Q(<updated>[updated]</updated>)
-		Q(<link rel="alternate" type="application/mbox" href="[base][url]"/>)
-	};
 	char *id = atomID(envelope);
 	char *url = atomEntryURL(envelope);
+	const char *template = Q(
+		<entry>
+		<id>[id]</id>
+		<title>[title]</title>
+		<updated>[updated]</updated>
+		<link rel="alternate" type="application/mbox" href="[base][url]"/>
+	);
 	struct Variable vars[] = {
 		{ "id", id },
 		{ "title", envelope->subject },
-		{ "updated", atomUpdated(envelope->time) },
+		{ "updated", iso8601(envelope->time).s },
 		{ "base", baseURL },
 		{ "url", url },
 		{0},
@@ -99,13 +93,13 @@ int atomEntryOpen(FILE *file, const struct Envelope *envelope) {
 }
 
 int atomContent(FILE *file, const char *content) {
-	const char *template = {
-		Q(<content type="xhtml">)
-			Q(<div xmlns="http://www.w3.org/1999/xhtml">)
-				Q(<pre>[content]</pre>)
-			Q(</div>)
-		Q(</content>)
-	};
+	const char *template = Q(
+		<content type="xhtml">
+			<div xmlns="http://www.w3.org/1999/xhtml">
+				<pre>[content]</pre>
+			</div>
+		</content>
+	);
 	struct Variable vars[] = {
 		{ "content", content },
 		{0},
@@ -126,27 +120,28 @@ static char *atomThreadURL(const struct Envelope *envelope, const char *type) {
 	return templateString("/" PATH_THREAD, vars, escapeURL);
 }
 
+#define XML_DECL "<?" Q(xml version="1.0" encoding="utf-8") "?>"
+
 int atomThreadOpen(FILE *file, const struct Envelope *envelope) {
-	const char *template = {
-		"<?" Q(xml version="1.0" encoding="utf-8") "?>"
-		Q(<feed xmlns="http://www.w3.org/2005/Atom">)
-		Q(<generator uri="[generator]">bubger</generator>)
-		Q(<id>[id]</id>)
-		Q(<title>[title]</title>)
-		Q(<updated>[updated]</updated>)
-		Q(<link rel="self" href="[base][atom]"/>)
-		Q(<link rel="alternate" type="text/html" href="[base][html]"/>)
-		Q(<link rel="alternate" type="application/mbox" href="[base][mbox]"/>)
-	};
 	char *id = atomID(envelope);
 	char *atom = atomThreadURL(envelope, "atom");
 	char *html = atomThreadURL(envelope, "html");
 	char *mbox = atomThreadURL(envelope, "mbox");
+	const char *template = XML_DECL Q(
+		<feed xmlns="http://www.w3.org/2005/Atom">
+		<generator uri="[generator]">bubger</generator>
+		<id>[id]</id>
+		<title>[title]</title>
+		<updated>[updated]</updated>
+		<link rel="self" href="[base][atom]"/>
+		<link rel="alternate" type="text/html" href="[base][html]"/>
+		<link rel="alternate" type="application/mbox" href="[base][mbox]"/>
+	);
 	struct Variable vars[] = {
 		{ "generator", GENERATOR_URL },
 		{ "id", id },
 		{ "title", envelope->subject },
-		{ "updated", atomUpdated(time(NULL)) },
+		{ "updated", iso8601(time(NULL)).s },
 		{ "base", baseURL },
 		{ "atom", atom },
 		{ "html", html },
@@ -168,21 +163,20 @@ int atomThreadClose(FILE *file) {
 }
 
 int atomIndexOpen(FILE *file) {
-	const char *template = {
-		"<?" Q(xml version="1.0" encoding="utf-8") "?>"
-		Q(<feed xmlns="http://www.w3.org/2005/Atom">)
-		Q(<generator uri="[generator]">bubger</generator>)
-		Q(<id>mailto:[mailto]</id>)
-		Q(<title>[title]</title>)
-		Q(<updated>[updated]</updated>)
-		Q(<link rel="self" href="[base]/index.atom"/>)
-		Q(<link rel="alternate" type="text/html" href="[base]/index.html"/>)
-	};
+	const char *template = XML_DECL Q(
+		<feed xmlns="http://www.w3.org/2005/Atom">
+		<generator uri="[generator]">bubger</generator>
+		<id>mailto:[mailto]</id>
+		<title>[title]</title>
+		<updated>[updated]</updated>
+		<link rel="self" href="[base]/index.atom"/>
+		<link rel="alternate" type="text/html" href="[base]/index.html"/>
+	);
 	struct Variable vars[] = {
 		{ "generator", GENERATOR_URL },
 		{ "mailto", baseMailto },
 		{ "title", baseTitle },
-		{ "updated", atomUpdated(time(NULL)) },
+		{ "updated", iso8601(time(NULL)).s },
 		{ "base", baseURL },
 		{0},
 	};