summaryrefslogtreecommitdiff
path: root/sfeed_atom.c
diff options
context:
space:
mode:
authorHiltjo Posthuma <hiltjo@codemadness.org>2020-06-04 18:01:15 +0200
committerHiltjo Posthuma <hiltjo@codemadness.org>2020-06-04 18:01:15 +0200
commitcadd8ae8e6c1e5673258df9541042c74e705e518 (patch)
treecbc4c67fd987850f09eca1afd84a81457db32c93 /sfeed_atom.c
parent3329788501ffa0acedefdf97a1173e66d76de033 (diff)
sfeed_atom: make the output more conform
- Set mandatory entry tags: id, updated. - Change entry published (optional tag) to updated (mandatory). - Add <feed> tags: author name, id, updated, title. Thanks lich for the feedback and testing.
Diffstat (limited to 'sfeed_atom.c')
-rw-r--r--sfeed_atom.c26
1 files changed, 23 insertions, 3 deletions
diff --git a/sfeed_atom.c b/sfeed_atom.c
index 33bd9a7..722a400 100644
--- a/sfeed_atom.c
+++ b/sfeed_atom.c
@@ -7,6 +7,7 @@
#include "util.h"
+static time_t now;
static char *line;
static size_t linesize;
@@ -65,12 +66,19 @@ printfeed(FILE *fp, const char *feedname)
xmlencode(fields[FieldLink], stdout);
fputs("\" />\n", stdout);
}
+ /* prefer link over id for Atom <id>. */
+ fputs("\t<id>", stdout);
+ if (fields[FieldLink][0])
+ xmlencode(fields[FieldLink], stdout);
+ else if (fields[FieldId][0])
+ xmlencode(fields[FieldId], stdout);
+ fputs("</id>\n", stdout);
if (fields[FieldEnclosure][0]) {
fputs("\t<link rel=\"enclosure\" href=\"", stdout);
xmlencode(fields[FieldEnclosure], stdout);
fputs("\" />\n", stdout);
}
- fprintf(stdout, "\t<published>%04d-%02d-%02dT%02d:%02d:%02dZ</published>\n",
+ fprintf(stdout, "\t<updated>%04d-%02d-%02dT%02d:%02d:%02dZ</updated>\n",
tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
tm->tm_hour, tm->tm_min, tm->tm_sec);
if (fields[FieldAuthor][0]) {
@@ -97,6 +105,7 @@ printfeed(FILE *fp, const char *feedname)
int
main(int argc, char *argv[])
{
+ struct tm *tm;
FILE *fp;
char *name;
int i;
@@ -109,9 +118,20 @@ main(int argc, char *argv[])
err(1, "pledge");
}
+ if ((now = time(NULL)) == -1)
+ err(1, "time");
+ if (!(tm = gmtime(&now)))
+ err(1, "gmtime");
+
fputs("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
- "<feed xmlns=\"http://www.w3.org/2005/Atom\" xml:lang=\"en\">\n",
- stdout);
+ "<feed xmlns=\"http://www.w3.org/2005/Atom\">\n"
+ "\t<title type=\"text\">Newsfeed</title>\n"
+ "\t<author><name>sfeed</name></author>\n", stdout);
+ printf("\t<id>urn:newsfeed:%lld</id>\n"
+ "\t<updated>%04d-%02d-%02dT%02d:%02d:%02dZ</updated>\n",
+ (long long)now,
+ tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
+ tm->tm_hour, tm->tm_min, tm->tm_sec);
if (argc == 1) {
printfeed(stdin, "");