9front - general discussion about 9front
 help / color / mirror / Atom feed
From: james palmer <james@biobuf.link>
To: 9front@9front.org
Subject: [9front] [PATCH] mothra: read the content-type header instead of using file(1) to determine type
Date: Mon, 07 Jun 2021 09:13:51 +0000	[thread overview]
Message-ID: <07270CC0D7E95F9E37CE20FABE03BD7C@biobuf.link> (raw)


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));

                 reply	other threads:[~2021-06-08 10:37 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=07270CC0D7E95F9E37CE20FABE03BD7C@biobuf.link \
    --to=james@biobuf.link \
    --cc=9front@9front.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).