Commit Diff


commit - 69f631d93578026c42de78c0165983c036f7b135
commit + 5fb52fc04465f7828ef88810d153e77c705efa57
blob - a582bd02daa7e1a5aa21245bc19c8af9cfda83ba
blob + 7e10f942f0ebab3178319faa22f2c46d7de1c00a
--- ChangeLog
+++ ChangeLog
@@ -1,3 +1,7 @@
+2021-07-25  Omar Polo  <op@omarpolo.com>
+
+	* telescope.c (load_finger_url): add support for the finger protocol
+
 2021-07-24  Omar Polo  <op@omarpolo.com>
 
 	* cmd.c (cmd_scroll_line_up): don't crash on empty pages
blob - 99a98e62e7983cd13bbf1baba51ab642d96b05d0
blob + 4edb5d1130f5538684e87b5915300e201bf99d64
--- net.c
+++ net.c
@@ -45,6 +45,7 @@ static struct tls_config	*tlsconf;
 struct req {
 	struct phos_uri		 url;
 	uint32_t		 id;
+	int			 proto;
 	int			 fd;
 	struct tls		*ctx;
 	char			 req[1024];
@@ -188,21 +189,37 @@ err:
 done:
 	freeaddrinfo(req->servinfo);
 
-	/* prepare tls */
-        if ((req->ctx = tls_client()) == NULL) {
-		close_with_errf(req, "tls_client: %s", strerror(errno));
-		return;
-	}
-	if (tls_configure(req->ctx, tlsconf) == -1) {
-		close_with_errf(req, "tls_configure: %s", tls_error(req->ctx));
-		return;
-	}
-	if (tls_connect_socket(req->ctx, req->fd, req->url.host) == -1) {
-		close_with_errf(req, "tls_connect_socket: %s",
-		    tls_error(req->ctx));
-		return;
+	switch (req->proto) {
+	case PROTO_FINGER:
+		/* finger doesn't have a header */
+		req->done_header = 1;
+		net_ready(req);
+		break;
+
+	case PROTO_GEMINI:
+		/* prepare tls */
+		if ((req->ctx = tls_client()) == NULL) {
+			close_with_errf(req, "tls_client: %s",
+			    strerror(errno));
+			return;
+		}
+		if (tls_configure(req->ctx, tlsconf) == -1) {
+			close_with_errf(req, "tls_configure: %s",
+			    tls_error(req->ctx));
+			return;
+		}
+		if (tls_connect_socket(req->ctx, req->fd, req->url.host)
+		    == -1) {
+			close_with_errf(req, "tls_connect_socket: %s",
+			    tls_error(req->ctx));
+			return;
+		}
+		yield_w(req, net_tls_handshake, &timeout_for_handshake);
+		break;
+
+	default:
+		die();
 	}
-	yield_w(req, net_tls_handshake, &timeout_for_handshake);
 }
 
 #if HAVE_ASR_RUN
@@ -612,6 +629,8 @@ handle_get_raw(struct imsg *imsg, size_t datalen)
 	strlcpy(req->req, r->req, sizeof(req->req));
 	req->len = strlen(r->req);
 
+	req->proto = r->proto;
+
 #if HAVE_ASR_RUN
         async_conn_towards(req);
 #else
blob - 19f976b29b29ab144cf23d93b1cdc6fa745b208b
blob + 4ff81ed2913c91b22e0e086708c6ab8f99d60237
--- telescope.c
+++ telescope.c
@@ -55,6 +55,7 @@ enum telescope_process {
 
 static struct proto protos[] = {
 	{ "about",	load_about_url },
+	{ "finger",	load_finger_url },
 	{ "gemini",	load_gemini_url },
 	{ NULL, NULL },
 };
@@ -573,6 +574,52 @@ load_about_url(struct tab *tab, const char *url)
 }
 
 void
+load_finger_url(struct tab *tab, const char *url)
+{
+	struct get_req	 req;
+	size_t		 len;
+	char		*at;
+
+	stop_tab(tab);
+	tab->id = tab_new_id();
+
+	memset(&req, 0, sizeof(req));
+	if (*tab->uri.port != '\0')
+		strlcpy(req.port, tab->uri.port, sizeof(req.port));
+	else
+		strlcpy(req.port, "79", sizeof(req.port));
+
+	/*
+	 * Sometimes the finger url have the user as path component
+	 * (e.g. finger://thelambdalab.xyz/plugd), sometimes as
+	 * userinfo (e.g. finger://cobradile@finger.farm).
+	 */
+	if ((at = strchr(tab->uri.host, '@')) != NULL) {
+		len = at - tab->uri.host;
+		memcpy(req.req, tab->uri.host, len);
+
+		if (len >= sizeof(req.req))
+			die();
+		req.req[len] = '\0';
+
+		strlcpy(req.host, at+1, sizeof(req.host));
+	} else {
+		strlcpy(req.host, tab->uri.host, sizeof(req.host));
+
+		/* +1 to skip the initial `/' */
+		strlcpy(req.req, tab->uri.path+1, sizeof(req.req));
+	}
+
+	strlcat(req.req, "\r\n", sizeof(req.req));
+
+	req.proto = PROTO_FINGER;
+
+	ui_send_net(IMSG_GET_RAW, tab->id, &req, sizeof(req));
+
+	textplain_initparser(&tab->buffer.page);
+}
+
+void
 load_gemini_url(struct tab *tab, const char *url)
 {
 	struct get_req	 req;
blob - 6ad095d0a22a799530bde00a85ffe30938eed66e
blob + 263bcb83c28c1289b993ac7ea39632c0d313937f
--- telescope.h
+++ telescope.h
@@ -243,6 +243,7 @@ struct proxy {
 
 enum {
 	PROTO_GEMINI,
+	PROTO_FINGER,
 	/* ... */
 };
 
@@ -323,6 +324,7 @@ void		 sandbox_fs_process(void);
 
 /* telescope.c */
 void		 load_about_url(struct tab*, const char*);
+void		 load_finger_url(struct tab *, const char *);
 void		 load_gemini_url(struct tab*, const char*);
 void		 load_via_proxy(struct tab *, const char *, struct proxy *);
 void		 load_url(struct tab *, const char *, const char *);