sfeed

simple feed reader - forked from git.codemadness.org/sfeed
git clone git://src.gearsix.net/sfeed
Log | Files | Refs | Atom | README | LICENSE

commit f1e17c612e33790a390c1ee1329c8433017d0c44
parent 510947149b81b5b715bb6cffd142fa4ffb0b0f24
Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date:   Wed, 13 May 2020 18:01:03 +0200

sfeed_gopher: do not use URL: prefix for gopher:// urls.

Support the Gopher protocol directly and use the specified Gopher type.

Idea by adc, thanks!

Diffstat:
Msfeed_gopher.c | 55+++++++++++++++++++++++++++++++++++++------------------
1 file changed, 37 insertions(+), 18 deletions(-)

diff --git a/sfeed_gopher.c b/sfeed_gopher.c @@ -37,11 +37,13 @@ gophertext(FILE *fp, const char *s) static void printfeed(FILE *fpitems, FILE *fpin, struct feed *f) { - char *fields[FieldLast]; + struct uri u; + char *fields[FieldLast], *itemhost, *itemport, *itempath; ssize_t linelen; unsigned int isnew; struct tm *tm; time_t parsedtime; + int itemtype; if (f->name[0]) { fprintf(fpitems, "i%s\t\t%s\t%s\r\n", f->name, host, port); @@ -63,25 +65,42 @@ printfeed(FILE *fpitems, FILE *fpin, struct feed *f) f->totalnew += isnew; f->total++; + itemhost = host; + itemport = port; + itemtype = 'i'; + itempath = fields[FieldLink]; + if (fields[FieldLink][0]) { - fputs("h", fpitems); - fprintf(fpitems, "%c %04d-%02d-%02d %02d:%02d ", - isnew ? 'N' : ' ', - tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, - tm->tm_hour, tm->tm_min); - gophertext(fpitems, fields[FieldTitle]); - fputs("\tURL:", fpitems); - gophertext(fpitems, fields[FieldLink]); - - } else { - fprintf(fpitems, "i%c %04d-%02d-%02d %02d:%02d ", - isnew ? 'N' : ' ', - tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, - tm->tm_hour, tm->tm_min); - gophertext(fpitems, fields[FieldTitle]); - fputs("\t", fpitems); + itemtype = 'h'; + if (!strncmp(fields[FieldLink], "gopher://", 9)) { + if (parseuri(fields[FieldLink], &u, 0) == -1) + continue; + itemhost = u.host; + itemport = u.port[0] ? u.port : "70"; + itemtype = '1'; + itempath = u.path; + + if (itempath[0] == '/') { + itempath++; + if (*itempath) { + itemtype = *itempath; + itempath++; + } + } + } } - fprintf(fpitems, "\t%s\t%s\r\n", host, port); + + fprintf(fpitems, "%c%c %04d-%02d-%02d %02d:%02d ", + itemtype, + isnew ? 'N' : ' ', + tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, + tm->tm_hour, tm->tm_min); + gophertext(fpitems, fields[FieldTitle]); + fputs("\t", fpitems); + if (itemtype == 'h' && fields[FieldLink] == itempath) + fputs("URL:", fpitems); + gophertext(fpitems, itempath); + fprintf(fpitems, "\t%s\t%s\r\n", itemhost, itemport); } fputs(".\r\n", fpitems); }