diff options
author | June McEnroe <june@causal.agency> | 2020-04-26 21:48:54 -0400 |
---|---|---|
committer | June McEnroe <june@causal.agency> | 2020-04-26 21:48:54 -0400 |
commit | 0e2a09e0f33fc9c5fd780e90bcf0b98395f94c2a (patch) | |
tree | 49e15d1925599fc551820f3e59d8ad5b2e226b2f | |
parent | Clean up archive.c (diff) | |
download | bubger-0e2a09e0f33fc9c5fd780e90bcf0b98395f94c2a.tar.gz bubger-0e2a09e0f33fc9c5fd780e90bcf0b98395f94c2a.zip |
Clean up atom.c and fix base URLs
Base URL should not be URL escaped!
Diffstat (limited to '')
-rw-r--r-- | atom.c | 38 |
1 files changed, 18 insertions, 20 deletions
diff --git a/atom.c b/atom.c index ea58c49..7c0dc5e 100644 --- a/atom.c +++ b/atom.c @@ -48,12 +48,17 @@ static int atomAuthor(FILE *file, struct Address addr) { static char *atomEntryURL(const struct Envelope *envelope) { struct Variable vars[] = { - { "base", baseURL }, { "messageID", envelope->messageID }, { "type", "mbox" }, {0}, }; - return templateURL("[base]/" PATH_MESSAGE, vars); + return templateURL("/" PATH_MESSAGE, vars); +} + +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; } int atomEntryOpen(FILE *file, const struct Envelope *envelope) { @@ -62,16 +67,15 @@ int atomEntryOpen(FILE *file, const struct Envelope *envelope) { <id>[id]</id> <title>[title]</title> <updated>[updated]</updated> - <link rel="alternate" type="application/mbox" href="[url]"/> + <link rel="alternate" type="application/mbox" href="[base][url]"/> ); char *id = atomID(envelope); - char updated[sizeof("0000-00-00T00:00:00Z")]; - strftime(updated, sizeof(updated), "%FT%TZ", gmtime(&envelope->time)); char *url = atomEntryURL(envelope); struct Variable vars[] = { { "id", id }, { "title", envelope->subject }, - { "updated", updated }, + { "updated", atomUpdated(envelope->time) }, + { "base", baseURL }, { "url", url }, {0}, }; @@ -104,12 +108,11 @@ int atomEntryClose(FILE *file) { static char *atomThreadURL(const struct Envelope *envelope, const char *type) { struct Variable vars[] = { - { "base", baseURL }, { "messageID", envelope->messageID }, { "type", type }, {0}, }; - return templateURL("[base]/" PATH_THREAD, vars); + return templateURL("/" PATH_THREAD, vars); } int atomThreadOpen(FILE *file, const struct Envelope *envelope) { @@ -119,14 +122,11 @@ int atomThreadOpen(FILE *file, const struct Envelope *envelope) { <id>[id]</id> <title>[title]</title> <updated>[updated]</updated> - <link rel="self" href="[atom]"/> - <link rel="alternate" type="text/html" href="[html]"/> - <link rel="alternate" type="application/mbox" href="[mbox]"/> + <link rel="self" href="[base][atom]"/> + <link rel="alternate" type="text/html" href="[base][html]"/> + <link rel="alternate" type="application/mbox" href="[base][mbox]"/> ); char *id = atomID(envelope); - time_t now = time(NULL); - char updated[sizeof("0000-00-00T00:00:00Z")]; - strftime(updated, sizeof(updated), "%FT%TZ", gmtime(&now)); char *atom = atomThreadURL(envelope, "atom"); char *html = atomThreadURL(envelope, "html"); char *mbox = atomThreadURL(envelope, "mbox"); @@ -134,7 +134,8 @@ int atomThreadOpen(FILE *file, const struct Envelope *envelope) { { "q", "?" }, { "id", id }, { "title", envelope->subject }, - { "updated", updated }, + { "updated", atomUpdated(time(NULL)) }, + { "base", baseURL }, { "atom", atom }, { "html", html }, { "mbox", mbox }, @@ -164,15 +165,12 @@ int atomIndexOpen(FILE *file) { <link rel="self" href="[base]/index.atom"/> <link rel="alternate" type="text/html" href="[base]/index.html"/> ); - time_t now = time(NULL); - char updated[sizeof("0000-00-00T00:00:00Z")]; - strftime(updated, sizeof(updated), "%FT%TZ", gmtime(&now)); struct Variable vars[] = { { "q", "?" }, { "addr", baseAddress }, - { "base", (baseURL ? baseURL : "") }, { "title", baseTitle }, - { "updated", updated }, + { "updated", atomUpdated(time(NULL)) }, + { "base", baseURL }, {0}, }; return templateRender(file, template, vars, escapeXML); |