9front - general discussion about 9front
 help / color / mirror / Atom feed
* [9front] [PATCH] mothra: read the content-type header instead of using file(1) to determine type
@ 2021-06-07  9:13 james palmer
  0 siblings, 0 replies; only message in thread
From: james palmer @ 2021-06-07  9:13 UTC (permalink / raw)
  To: 9front


this fixes some pages being classified as xml by file(1),
meaning they would be rendered as plain text rather than as html.

if the header is not present mothra will fall back to using file(1).
---
diff 56656a7ac6aac082b65d77cf0a0e4bc492ddcd2c 3ec67240f59d1e68b8d7fcb30fa17fe87f317bff
--- a/sys/src/cmd/mothra/mothra.c	Mon Jun  7 10:01:32 2021
+++ b/sys/src/cmd/mothra/mothra.c	Mon Jun  7 10:13:51 2021
@@ -1017,8 +1017,9 @@
 		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){
--- a/sys/src/cmd/mothra/mothra.h	Mon Jun  7 10:01:32 2021
+++ b/sys/src/cmd/mothra/mothra.h	Mon Jun  7 10:13:51 2021
@@ -28,6 +28,7 @@
 	char *reltext;
 	char fullname[NNAME];
 	char tag[NNAME];
+	char contenttype[NNAME];
 	int map;		/* is this an image map? */
 };
 struct Www{
@@ -97,6 +98,7 @@
 #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);
--- a/sys/src/cmd/mothra/snoop.c	Mon Jun  7 10:01:32 2021
+++ b/sys/src/cmd/mothra/snoop.c	Mon Jun  7 10:13:51 2021
@@ -87,8 +87,9 @@
 }
 
 int
-snooptype(int fd)
+mimetotype(char *mime)
 {
+	int i;
 	static struct {
 		char	*typ;
 		int	val;
@@ -110,13 +111,23 @@
 	"image/",			PAGE,
 	"text/",			PLAIN,
 	"message/rfc822",		PLAIN,
-	};
+	};	
+
+	for(i=0; i<nelem(tab); i++)
+		if(strncmp(mime, tab[i].typ, strlen(tab[i].typ)) == 0)
+			return tab[i].val;
+			
+	return -1;
+}
+
+int
+snooptype(int fd)
+{
 	char buf[128];
 	int i;
+	
 	if(filetype(fd, buf, sizeof(buf)) < 0)
 		return -1;
-	for(i=0; i<nelem(tab); i++)
-		if(strncmp(buf, tab[i].typ, strlen(tab[i].typ)) == 0)
-			return tab[i].val;
-	return -1;
+		
+	return mimetotype(buf);
 }
--- a/sys/src/cmd/mothra/url.c	Mon Jun  7 10:01:32 2021
+++ b/sys/src/cmd/mothra/url.c	Mon Jun  7 10:13:51 2021
@@ -215,6 +215,9 @@
 
 	snprint(buf+n, sizeof(buf)-n, "/parsed/fragment");
 	readstr(buf, url->tag, 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));

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-06-08 10:37 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-07  9:13 [9front] [PATCH] mothra: read the content-type header instead of using file(1) to determine type james palmer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).