Commit Diff


commit - 8da4eaff2d5d150f7491c80bf3f1e26d184706d5
commit + 1663bf1e97e8a9f54bb78bfe8853f81c8e99e6db
blob - 7e10f942f0ebab3178319faa22f2c46d7de1c00a
blob + ef85be551b45a8600235822def0b7ac7836e6dc7
--- ChangeLog
+++ ChangeLog
@@ -1,6 +1,7 @@
 2021-07-25  Omar Polo  <op@omarpolo.com>
 
 	* telescope.c (load_finger_url): add support for the finger protocol
+	(load_gopher_url): initial gopher support
 
 2021-07-24  Omar Polo  <op@omarpolo.com>
 
blob - 4edb5d1130f5538684e87b5915300e201bf99d64
blob + e02fda2b3f326511315d01ed4b2b9575847861ec
--- net.c
+++ net.c
@@ -191,7 +191,8 @@ done:
 
 	switch (req->proto) {
 	case PROTO_FINGER:
-		/* finger doesn't have a header */
+	case PROTO_GOPHER:
+		/* finger and gopher don't have a header nor TLS */
 		req->done_header = 1;
 		net_ready(req);
 		break;
blob - 48bd46bc60b57d4abae1ca979f81109ca4ef0bdc
blob + 7c61398338fc18e8e7c29d0793db9d97a11daa74
--- telescope.c
+++ telescope.c
@@ -105,6 +105,7 @@ static void		 load_page_from_str(struct tab*, const ch
 static void		 load_about_url(struct tab*, const char*);
 static void		 load_finger_url(struct tab *, const char *);
 static void		 load_gemini_url(struct tab*, const char*);
+static void		 load_gopher_url(struct tab *, const char *);
 static void		 load_via_proxy(struct tab *, const char *,
 			     struct proxy *);
 static void		 make_request(struct tab *, struct get_req *, int,
@@ -124,6 +125,7 @@ static struct proto {
 	{"about",	NULL,	load_about_url},
 	{"finger",	"79",	load_finger_url},
 	{"gemini",	"1965",	load_gemini_url},
+	{"gopher",	"70",	load_gopher_url},
 	{NULL, NULL, NULL},
 };
 
@@ -629,6 +631,20 @@ load_gemini_url(struct tab *tab, const char *url)
 	strlcpy(req.port, tab->uri.port, sizeof(req.host));
 
 	make_request(tab, &req, PROTO_GEMINI, tab->hist_cur->h);
+}
+
+static void
+load_gopher_url(struct tab *tab, const char *url)
+{
+	struct get_req	req;
+
+	memset(&req, 0, sizeof(req));
+	strlcpy(req.host, tab->uri.host, sizeof(req.host));
+	strlcpy(req.port, tab->uri.port, sizeof(req.host));
+
+	/* cheat a bit by considering gophermaps text */
+	textplain_initparser(&tab->buffer.page);
+	make_request(tab, &req, PROTO_GOPHER, tab->uri.path);
 }
 
 static void
blob - 68c3d3838b7da43273f6bd78d1f64f0505dcebdb
blob + b557a96f53d24ed8af96b580b6cd797fea965893
--- telescope.h
+++ telescope.h
@@ -232,6 +232,7 @@ struct proxy {
 enum {
 	PROTO_FINGER,
 	PROTO_GEMINI,
+	PROTO_GOPHER,
 	/* ... */
 };