Commit Diff


commit - 179f0f58fdda609680cbe2e35261920767de44fa
commit + c07ac9967137c45b2019bf763346346539b48d98
blob - 6e3769e169fea75e2a69270b4b9f71b675f7d9cf
blob + 9c00ac612156466396e3a82792fa4aef4b163197
--- Makefile.am
+++ Makefile.am
@@ -4,6 +4,7 @@ telescope_SOURCES =	compat.h	\
 			compat/*.[ch]	\
 			gemini.c	\
 			gemtext.c	\
+			mime.c		\
 			pages.c		\
 			telescope.c	\
 			telescope.h	\
blob - 6b945d131b5f4e03e7a4028d7233d758c3a40b4b
blob + 2a42f3a27834e8580525bf17f689297acd2c18de
--- pages.c
+++ pages.c
@@ -50,6 +50,7 @@ const char *err_pages[70] = {
 	[CANNOT_FETCH]		= "# Couldn't load the page\n",
 	[TOO_MUCH_REDIRECTS]	= "# Too much redirects\n",
 	[MALFORMED_RESPONSE]	= "# Got a malformed response\n",
+	[UNKNOWN_TYPE_OR_CSET]	= "# Unsupported type or charset\n",
 
 	[10] = "# Input required\n",
 	[11] = "# Input required\n",
blob - 6df001b5456b94ad62d8d599ff1b3ecc122f242d
blob + b392356c4cd1a33bd39de6f051850671e5f64254
--- telescope.c
+++ telescope.c
@@ -14,7 +14,8 @@
 struct event		 imsgev;
 struct tabshead		 tabshead;
 
-struct proto protos[] = {
+/* the first is also the fallback one */
+static struct proto protos[] = {
 	{ "gemini:",	load_gemini_url },
 	{ "about:",	load_about_url },
 	{ NULL, NULL },
@@ -149,10 +150,12 @@ handle_imsg_got_meta(struct imsg *imsg, size_t datalen
 		load_page_from_str(tab, err_pages[tab->code]);
 		ui_require_input(tab, tab->code == 11);
 	} else if (tab->code == 20) {
-		/* TODO: parse mime type */
-		gemtext_initparser(&tab->page);
-		imsg_compose(ibuf, IMSG_PROCEED, tab->id, 0, -1, NULL, 0);
-		imsg_flush(ibuf);
+		if (setup_parser_for(tab)) {
+			imsg_compose(ibuf, IMSG_PROCEED, tab->id, 0, -1, NULL, 0);
+			imsg_flush(ibuf);
+		} else {
+			load_page_from_str(tab, err_pages[UNKNOWN_TYPE_OR_CSET]);
+		}
 	} else if (tab->code < 40) { /* 3x */
 		tab->redirect_count++;
 
blob - 9c5befa4fe3de4b7ab1ceb6ccf2bd8b5970d02e8
blob + bf54aa6c97b1ba2ff689a44462e7a2ed28fe7f7d
--- telescope.h
+++ telescope.h
@@ -108,9 +108,6 @@ struct proto {
 	void		 (*loadfn)(struct tab*, const char*);
 };
 
-/* the first is also the fallback one */
-extern struct proto protos[];
-
 extern struct event		 imsgev;
 
 /* gemini.c */
@@ -119,12 +116,16 @@ int		 client_main(struct imsgbuf *b);
 /* gemtext.c */
 void		 gemtext_initparser(struct parser*);
 
+/* mime.c */
+int		 setup_parser_for(struct tab*);
+
 /* pages.c */
 extern const char	*about_new;
 
 #define CANNOT_FETCH		0
 #define TOO_MUCH_REDIRECTS	1
 #define MALFORMED_RESPONSE	2
+#define UNKNOWN_TYPE_OR_CSET	3
 extern const char	*err_pages[70];
 
 /* telescope.c */