From 0e2a09e0f33fc9c5fd780e90bcf0b98395f94c2a Mon Sep 17 00:00:00 2001 From: "C. McEnroe" Date: Sun, 26 Apr 2020 21:48:54 -0400 Subject: Clean up atom.c and fix base URLs Base URL should not be URL escaped! --- atom.c | 38 ++++++++++++++++++-------------------- 1 file 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] [title] [updated] - + ); 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] [title] [updated] - - - + + + ); 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) { ); - 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); -- cgit 1.4.1