summaryrefslogtreecommitdiff
path: root/sfeed_gopher.c
diff options
context:
space:
mode:
authorHiltjo Posthuma <hiltjo@codemadness.org>2020-05-13 18:01:03 +0200
committerHiltjo Posthuma <hiltjo@codemadness.org>2020-05-13 19:06:41 +0200
commitf1e17c612e33790a390c1ee1329c8433017d0c44 (patch)
treeeb21d55235957f4ad23eff6217e31a93df5783c1 /sfeed_gopher.c
parent510947149b81b5b715bb6cffd142fa4ffb0b0f24 (diff)
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 (limited to 'sfeed_gopher.c')
-rw-r--r--sfeed_gopher.c55
1 files changed, 37 insertions, 18 deletions
diff --git a/sfeed_gopher.c b/sfeed_gopher.c
index 7362716..93e2e61 100644
--- 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);
}