shithub: castor9

Download patch

ref: 48a172147b7b55108dc0f40995ef5000a52d50a5
parent: 27cba0188575b3663d7e4873c99adfa489213d5a
author: Julien Blanchard <[email protected]>
date: Thu Dec 10 12:45:06 EST 2020

Make TLS ans parsing more robust

--- a/castor.c
+++ b/castor.c
@@ -325,10 +325,15 @@
 		return -1;
 	}
 
-	conn.serverName = url->host;
 	memset(&conn, 0, sizeof(conn));
+	conn.serverName = url->host;
 
 	fd = tlsClient(fd, &conn);
+	if(fd < 0){
+		message("tls: %r");
+		return -1;
+	}
+
 	th = initThumbprints("/sys/lib/ssl/gemini", nil, "x509");
 
 	if(th != nil){
@@ -590,11 +595,15 @@
 	if(link==nil)
 		return;
 
-	if(strbeg(link, "gemini://") == 0 || strstr(link, "://") != nil){
+	if(strbeg(link, "gemini://") == 0){
 		next_url = urlparse(nil, link);
+	}else if(strbeg(link, "//") == 0){
+		next_url = urlparse(nil, smprint("gemini:%s", link));
 	}else{
 		/* assuming relative URL */
-		if(*link == '/'){
+		if(strcmp(link, "/") == 0){
+			n = smprint("gemini://%s", current_base_url->host);
+		}else if(*link == '/'){
 			n = smprint("%s%s", urlparse(current_base_url, link)->raw, estrdup(link)+1);
 		}else{
 			n = smprint("%s%s", urlparse(current_base_url, link)->raw, estrdup(link));
@@ -601,8 +610,8 @@
 		}
 		next_url = urlparse(nil, n);
 	}
-	
-	if(strcmp(next_url->scheme, "gemini") == 0){
+
+	if(strbeg(next_url->raw, "gemini://") == 0){
 		gemini_get(next_url);
 	}else{
 		plumburl(next_url);
@@ -690,7 +699,7 @@
 	Url *url;
 	
 	if(argc == 2)
-		if(strcmp(argv[1], "gemini://") != 0){
+		if(strbeg(argv[1], "gemini://") != 0){
 			url = urlparse(nil, smprint("gemini://%s", argv[1]));
 		}else{
 			url = urlparse(nil, argv[1]);