From 4bc97ce307f717166909f303d766d495fb477e6a Mon Sep 17 00:00:00 2001 From: bptato Date: Wed, 21 Oct 2020 12:56:36 +0200 Subject: Improved gopher support --- file.c | 23 ++++++++++++++++------- url.c | 33 +++++++++++++++++++++++++-------- 2 files changed, 41 insertions(+), 15 deletions(-) diff --git a/file.c b/file.c index 52ace23..41e8f58 100644 --- a/file.c +++ b/file.c @@ -1959,7 +1959,7 @@ loadGeneralFile(char *path, ParsedURL *volatile current, char *referer, #endif /* USE_NNTP */ #ifdef USE_GOPHER else if (pu.scheme == SCM_GOPHER) { - switch (*pu.file) { + switch (pu.file[strlen(pu.file)-1]) { case '0': t = "text/plain"; break; @@ -7393,8 +7393,9 @@ Str loadGopherDir(URLFile *uf, ParsedURL *pu, wc_ces * charset) { Str volatile tmp; - Str lbuf, name, file, host, port; + Str lbuf, name, file, host, port, type; char *volatile p, *volatile q; + int link; MySignalHandler(*volatile prevtrap) (SIGNAL_ARG) = NULL; #ifdef USE_M17N wc_ces doc_charset = DocumentCharset; @@ -7440,6 +7441,7 @@ loadGopherDir(URLFile *uf, ParsedURL *pu, wc_ces * charset) for (q = p; *q && *q != '\t' && *q != '\r' && *q != '\n'; q++) ; port = Strnew_charp_n(p, q - p); + link = 1; switch (name->ptr[0]) { case '0': p = "[text file]"; @@ -7459,15 +7461,22 @@ loadGopherDir(URLFile *uf, ParsedURL *pu, wc_ces * charset) case 'h': p = "[HTML]"; break; + case 'i': + link = 0; + break; default: p = "[unsupported]"; break; } - q = Strnew_m_charp("gopher://", host->ptr, ":", port->ptr, - "/", file->ptr, NULL)->ptr; - Strcat_m_charp(tmp, "", p, html_quote(name->ptr + 1), "\n", NULL); + type = Strsubstr(name, 0, 1); + q = Strnew_m_charp("gopher://", host->ptr, ":", port->ptr, file->ptr, type->ptr, NULL)->ptr; + if(link) { + Strcat_m_charp(tmp, "", p, " ", html_quote(name->ptr + 1), "
\n", NULL); + } else { + Strcat_m_charp(tmp, "

", html_quote(name->ptr + 1), "

\n", NULL); + } } gopher_end: diff --git a/url.c b/url.c index 972f14b..d5d2760 100644 --- a/url.c +++ b/url.c @@ -931,14 +931,6 @@ parseURL(char *url, ParsedURL *p_url, ParsedURL *current) #endif q = p; -#ifdef USE_GOPHER - if (p_url->scheme == SCM_GOPHER) { - if (*q == '/') - q++; - if (*q && q[0] != '/' && q[1] != '/' && q[2] == '/') - q++; - } -#endif /* USE_GOPHER */ if (*p == '/') p++; if (*p == '\0' || *p == '#' || *p == '?') { /* scheme://host[:port]/ */ @@ -1570,6 +1562,7 @@ openURL(char *url, ParsedURL *pu, ParsedURL *current, Str tmp; int sock, scheme; char *p, *q, *u; + char end; URLFile uf; HRequest hr0; #ifdef USE_SSL @@ -1833,6 +1826,27 @@ openURL(char *url, ParsedURL *pu, ParsedURL *current, break; #ifdef USE_GOPHER case SCM_GOPHER: + if(pu->file) { + end = pu->file[strlen(pu->file)-1]; + switch(end) { + case '0': + case '1': + case 'm': + case 's': + case 'g': + case 'h': + pu->file[strlen(pu->file)-1] = '\0'; + break; + default: + if('0' <= end && end <= '9') + pu->file[strlen(pu->file)-1] = '\0'; + else + end = '\0'; + break; + } + } else { + end = '\0'; + } if (non_null(GOPHER_proxy) && !Do_not_use_proxy && pu->host != NULL && !check_no_proxy(pu->host)) { @@ -1855,6 +1869,9 @@ openURL(char *url, ParsedURL *pu, ParsedURL *current, Strcat_char(tmp, '\n'); } write(sock, tmp->ptr, tmp->length); + if(end != '\0') { + pu->file[strlen(pu->file)] = end; + } break; #endif /* USE_GOPHER */ #ifdef USE_NNTP -- cgit v1.2.3 From 16e0b6aa63541c83726ade3df6f8c23f9c15c1ff Mon Sep 17 00:00:00 2001 From: bptato Date: Wed, 21 Oct 2020 13:30:01 +0200 Subject: Improved gopher directory display --- file.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/file.c b/file.c index 41e8f58..12f439a 100644 --- a/file.c +++ b/file.c @@ -7395,7 +7395,7 @@ loadGopherDir(URLFile *uf, ParsedURL *pu, wc_ces * charset) Str volatile tmp; Str lbuf, name, file, host, port, type; char *volatile p, *volatile q; - int link; + int link, pre; MySignalHandler(*volatile prevtrap) (SIGNAL_ARG) = NULL; #ifdef USE_M17N wc_ces doc_charset = DocumentCharset; @@ -7415,6 +7415,7 @@ loadGopherDir(URLFile *uf, ParsedURL *pu, wc_ces * charset) goto gopher_end; TRAP_ON; + pre = 0; while (1) { if (lbuf = StrUFgets(uf), lbuf->length == 0) break; @@ -7469,19 +7470,33 @@ loadGopherDir(URLFile *uf, ParsedURL *pu, wc_ces * charset) break; } type = Strsubstr(name, 0, 1); - q = Strnew_m_charp("gopher://", host->ptr, ":", port->ptr, file->ptr, type->ptr, NULL)->ptr; + if(file->ptr[0] == '/') + q = Strnew_m_charp("gopher://", host->ptr, ":", port->ptr, file->ptr, type->ptr, NULL)->ptr; + else + q = Strnew_m_charp("gopher://", host->ptr, ":", port->ptr, "/", file->ptr, type->ptr, NULL)->ptr; if(link) { + if(pre) { + Strcat_charp(tmp, ""); + pre = 0; + } Strcat_m_charp(tmp, "", p, " ", html_quote(name->ptr + 1), "
\n", NULL); } else { - Strcat_m_charp(tmp, "

", html_quote(name->ptr + 1), "

\n", NULL); + if(!pre) { + Strcat_charp(tmp, "
");
+		pre = 1;
+	    }
+
+	    Strcat_m_charp(tmp, html_quote(name->ptr + 1), "\n", NULL);
 	}
     }
 
   gopher_end:
     TRAP_OFF;
 
+    if(pre)
+	Strcat_charp(tmp, "
"); Strcat_charp(tmp, "\n\n\n"); return tmp; } -- cgit v1.2.3 From 26876fc89b09cf34e88130c2d976fa220bf52dd6 Mon Sep 17 00:00:00 2001 From: bptato Date: Wed, 21 Oct 2020 16:31:05 +0200 Subject: Moved back filetype indicator to the beginning of file names --- file.c | 12 +++++++----- url.c | 42 ++++++++++++++++++++++++++++++------------ 2 files changed, 37 insertions(+), 17 deletions(-) diff --git a/file.c b/file.c index 12f439a..358f20a 100644 --- a/file.c +++ b/file.c @@ -1712,6 +1712,8 @@ loadGeneralFile(char *path, ParsedURL *volatile current, char *referer, URLOption url_option; Str tmp; Str volatile page = NULL; +#ifdef USE_GOPHER +#endif #ifdef USE_M17N wc_ces charset = WC_CES_US_ASCII; #endif @@ -1959,7 +1961,10 @@ loadGeneralFile(char *path, ParsedURL *volatile current, char *referer, #endif /* USE_NNTP */ #ifdef USE_GOPHER else if (pu.scheme == SCM_GOPHER) { - switch (pu.file[strlen(pu.file)-1]) { + p = pu.file; + while(*p == '/') + ++p; + switch (*p) { case '0': t = "text/plain"; break; @@ -7470,10 +7475,7 @@ loadGopherDir(URLFile *uf, ParsedURL *pu, wc_ces * charset) break; } type = Strsubstr(name, 0, 1); - if(file->ptr[0] == '/') - q = Strnew_m_charp("gopher://", host->ptr, ":", port->ptr, file->ptr, type->ptr, NULL)->ptr; - else - q = Strnew_m_charp("gopher://", host->ptr, ":", port->ptr, "/", file->ptr, type->ptr, NULL)->ptr; + q = Strnew_m_charp("gopher://", host->ptr, ":", port->ptr, "/", type->ptr, file->ptr, NULL)->ptr; if(link) { if(pre) { Strcat_charp(tmp, ""); diff --git a/url.c b/url.c index d5d2760..ce0a53c 100644 --- a/url.c +++ b/url.c @@ -931,6 +931,14 @@ parseURL(char *url, ParsedURL *p_url, ParsedURL *current) #endif q = p; +#ifdef USE_GOPHER + if (p_url->scheme == SCM_GOPHER) { + if (*q == '/') + q++; + if (*q && q[0] != '/' && q[1] != '/' && q[2] == '/') + q++; + } +#endif /* USE_GOPHER */ if (*p == '/') p++; if (*p == '\0' || *p == '#' || *p == '?') { /* scheme://host[:port]/ */ @@ -1562,7 +1570,11 @@ openURL(char *url, ParsedURL *pu, ParsedURL *current, Str tmp; int sock, scheme; char *p, *q, *u; - char end; +#ifdef USE_GOPHER + Str gophertmp; + char type; + int n; +#endif URLFile uf; HRequest hr0; #ifdef USE_SSL @@ -1826,26 +1838,32 @@ openURL(char *url, ParsedURL *pu, ParsedURL *current, break; #ifdef USE_GOPHER case SCM_GOPHER: - if(pu->file) { - end = pu->file[strlen(pu->file)-1]; - switch(end) { + p = pu->file; + n = 0; + while(*p == '/') { + ++p; + ++n; + } + if(*p != '\0') { + type = pu->file[n]; + switch(type) { case '0': case '1': case 'm': case 's': case 'g': case 'h': - pu->file[strlen(pu->file)-1] = '\0'; + tmp = Strnew_charp(pu->file); + gophertmp = Strdup(tmp); + Strdelete(tmp, n, 1); + pu->file = tmp->ptr; break; default: - if('0' <= end && end <= '9') - pu->file[strlen(pu->file)-1] = '\0'; - else - end = '\0'; + type = '\0'; break; } } else { - end = '\0'; + type = '\0'; } if (non_null(GOPHER_proxy) && !Do_not_use_proxy && @@ -1869,8 +1887,8 @@ openURL(char *url, ParsedURL *pu, ParsedURL *current, Strcat_char(tmp, '\n'); } write(sock, tmp->ptr, tmp->length); - if(end != '\0') { - pu->file[strlen(pu->file)] = end; + if(type != '\0') { + pu->file = gophertmp->ptr; } break; #endif /* USE_GOPHER */ -- cgit v1.2.3