ref: fb52dfe4197457eb5eb4134dece22ad42752f31e
parent: 1e9ebfb3aec50a18bfaec8da2a96b9604e40ca18
author: Julien Blanchard <julien@typed-hole.org>
date: Tue Dec 22 06:51:02 EST 2020
Add some comments before refact
--- a/castor.c
+++ b/castor.c
@@ -602,19 +602,24 @@
if(link==nil)
return;
- if(strbeg(link, "gemini://") == 0){
+ if(strbeg(link, "gemini://") == 0){ /* gemini absolute */
next_url = urlparse(nil, link);
- }else if(strbeg(link, "//") == 0){
+ }else if(strstr(link, "://") != 0){ /* other protocol absolute */
+ next_url = urlparse(nil, link);
+ }else if(strbeg(link, "//") == 0){ /* schemeless so gemini */
next_url = urlparse(nil, smprint("gemini:%s", link));
- }else if(strbeg(link, "mailto:") == 0){
+ }else if(strbeg(link, "mailto:") == 0){ /* mailto: */
next_url = urlparse(nil, link);
}else{
/* assuming relative URL */
if(strcmp(link, "/") == 0){
+ /* no slash, must be a hostname */
n = smprint("gemini://%s", current_base_url->host);
}else if(*link == '/'){
+ /* start with a slash so skip it (+1) */
n = smprint("%s%s", urlparse(current_base_url, link)->raw, estrdup(link)+1);
}else{
+ /* make an absolute URL of the link */
n = smprint("%s%s", urlparse(current_base_url, link)->raw, estrdup(link));
}
next_url = urlparse(nil, n);