~julienxx/castor9

48a172147b7b55108dc0f40995ef5000a52d50a5 — Julien Blanchard 3 years ago 27cba01
Make TLS ans parsing more robust
1 files changed, 15 insertions(+), 6 deletions(-)

M castor.c
M castor.c => castor.c +15 -6
@@ 325,10 325,15 @@ request(Url *url)
		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,19 595,23 @@ texthit(Panel *p, int b, Rtext *rt)
	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));
		}
		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 @@ main(int argc, char *argv[])
	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]);