From aacf368c6d4ec9adb9fae28d3ca07d074fd459f5 Mon Sep 17 00:00:00 2001 From: Ori Bernstein Date: Sat, 12 Jun 2021 14:32:16 +0000 Subject: [PATCH] mothra: read the content-type header over file(1) to determine type (thanks james palmer) this fixes some pages being classified as xml by file(1), meaning they would be rendered as plain text rather than as html. --- sys/src/cmd/mothra/mothra.c | 3 ++- sys/src/cmd/mothra/mothra.h | 2 ++ sys/src/cmd/mothra/snoop.c | 25 ++++++++++++++++++------- sys/src/cmd/mothra/url.c | 3 +++ 4 files changed, 25 insertions(+), 8 deletions(-) diff --git a/sys/src/cmd/mothra/mothra.c b/sys/src/cmd/mothra/mothra.c index 291272c4c..bc8cb9261 100644 --- a/sys/src/cmd/mothra/mothra.c +++ b/sys/src/cmd/mothra/mothra.c @@ -1017,8 +1017,9 @@ void geturl(char *urlname, int post, int plumb, int map){ message("getting %s", selection->fullname); if(mothmode && !plumb) typ = -1; - else + else if((typ = mimetotype(selection->contenttype)) < 0) typ = snooptype(fd); + switch(typ){ default: if(plumb){ diff --git a/sys/src/cmd/mothra/mothra.h b/sys/src/cmd/mothra/mothra.h index 806ab614b..200650ab7 100644 --- a/sys/src/cmd/mothra/mothra.h +++ b/sys/src/cmd/mothra/mothra.h @@ -28,6 +28,7 @@ struct Url{ char *reltext; char fullname[NNAME]; char tag[NNAME]; + char contenttype[NNAME]; int map; /* is this an image map? */ }; struct Www{ @@ -97,6 +98,7 @@ int Ufmt(Fmt *f); #pragma varargck type "U" char* void message(char *, ...); int filetype(int, char *, int); +int mimetotype(char *); int snooptype(int); void mkfieldpanel(Rtext *); void geturl(char *, int, int, int); diff --git a/sys/src/cmd/mothra/snoop.c b/sys/src/cmd/mothra/snoop.c index 7df01acb6..833141544 100644 --- a/sys/src/cmd/mothra/snoop.c +++ b/sys/src/cmd/mothra/snoop.c @@ -87,8 +87,9 @@ Err1: } int -snooptype(int fd) +mimetotype(char *mime) { + int i; static struct { char *typ; int val; @@ -110,13 +111,23 @@ snooptype(int fd) "image/", PAGE, "text/", PLAIN, "message/rfc822", PLAIN, - }; - char buf[128]; - int i; - if(filetype(fd, buf, sizeof(buf)) < 0) - return -1; + }; + for(i=0; itag, sizeof(url->tag)); + + snprint(buf+n, sizeof(buf)-n, "/contenttype"); + readstr(buf, url->contenttype, sizeof(url->contenttype)); snprint(buf+n, sizeof(buf)-n, "/contentencoding"); readstr(buf, buf, sizeof(buf));