aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTatsuya Kinoshita <tats@debian.org>2020-10-24 06:16:10 +0000
committerGitHub <noreply@github.com>2020-10-24 06:16:10 +0000
commit35bc5aa8439829c44861a5c9b248572f5d5cac0b (patch)
tree540c98c6fabd9d92781fce7941fbe19173ca31ea
parentUpdate ChangeLog (diff)
parentMoved back filetype indicator to the beginning of file names (diff)
downloadw3m-35bc5aa8439829c44861a5c9b248572f5d5cac0b.tar.gz
w3m-35bc5aa8439829c44861a5c9b248572f5d5cac0b.zip
Merge pull request #152 from bptato/master
Fix gopher support
Diffstat (limited to '')
-rw-r--r--file.c40
-rw-r--r--url.c35
2 files changed, 68 insertions, 7 deletions
diff --git a/file.c b/file.c
index 52ace23..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) {
+ p = pu.file;
+ while(*p == '/')
+ ++p;
+ switch (*p) {
case '0':
t = "text/plain";
break;
@@ -7393,8 +7398,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, pre;
MySignalHandler(*volatile prevtrap) (SIGNAL_ARG) = NULL;
#ifdef USE_M17N
wc_ces doc_charset = DocumentCharset;
@@ -7414,6 +7420,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;
@@ -7440,6 +7447,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,20 +7467,38 @@ 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, "<a href=\"",
- html_quote(url_encode(q, NULL, *charset)),
- "\">", p, html_quote(name->ptr + 1), "</a>\n", NULL);
+ type = Strsubstr(name, 0, 1);
+ q = Strnew_m_charp("gopher://", host->ptr, ":", port->ptr, "/", type->ptr, file->ptr, NULL)->ptr;
+ if(link) {
+ if(pre) {
+ Strcat_charp(tmp, "</pre>");
+ pre = 0;
+ }
+ Strcat_m_charp(tmp, "<a href=\"",
+ html_quote(url_encode(q, NULL, *charset)),
+ "\">", p, " ", html_quote(name->ptr + 1), "</a><br>\n", NULL);
+ } else {
+ if(!pre) {
+ Strcat_charp(tmp, "<pre>");
+ pre = 1;
+ }
+
+ Strcat_m_charp(tmp, html_quote(name->ptr + 1), "\n", NULL);
+ }
}
gopher_end:
TRAP_OFF;
+ if(pre)
+ Strcat_charp(tmp, "</pre>");
Strcat_charp(tmp, "</table>\n</body>\n</html>\n");
return tmp;
}
diff --git a/url.c b/url.c
index 972f14b..ce0a53c 100644
--- a/url.c
+++ b/url.c
@@ -1570,6 +1570,11 @@ openURL(char *url, ParsedURL *pu, ParsedURL *current,
Str tmp;
int sock, scheme;
char *p, *q, *u;
+#ifdef USE_GOPHER
+ Str gophertmp;
+ char type;
+ int n;
+#endif
URLFile uf;
HRequest hr0;
#ifdef USE_SSL
@@ -1833,6 +1838,33 @@ openURL(char *url, ParsedURL *pu, ParsedURL *current,
break;
#ifdef USE_GOPHER
case SCM_GOPHER:
+ 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':
+ tmp = Strnew_charp(pu->file);
+ gophertmp = Strdup(tmp);
+ Strdelete(tmp, n, 1);
+ pu->file = tmp->ptr;
+ break;
+ default:
+ type = '\0';
+ break;
+ }
+ } else {
+ type = '\0';
+ }
if (non_null(GOPHER_proxy) &&
!Do_not_use_proxy &&
pu->host != NULL && !check_no_proxy(pu->host)) {
@@ -1855,6 +1887,9 @@ openURL(char *url, ParsedURL *pu, ParsedURL *current,
Strcat_char(tmp, '\n');
}
write(sock, tmp->ptr, tmp->length);
+ if(type != '\0') {
+ pu->file = gophertmp->ptr;
+ }
break;
#endif /* USE_GOPHER */
#ifdef USE_NNTP