From 171db89cc2a82bad906704debb0db8a9058c3e35 Mon Sep 17 00:00:00 2001 From: bptato Date: Sat, 7 Nov 2020 23:12:35 +0100 Subject: Support Gopher items search (7) and binary file (9) --- file.c | 46 +++++++++++++++++++++++++++++++++++++++++++++- proto.h | 1 + url.c | 14 ++++++++++++++ 3 files changed, 60 insertions(+), 1 deletion(-) diff --git a/file.c b/file.c index 358f20a..f5aaa5b 100644 --- a/file.c +++ b/file.c @@ -1961,7 +1961,7 @@ loadGeneralFile(char *path, ParsedURL *volatile current, char *referer, #endif /* USE_NNTP */ #ifdef USE_GOPHER else if (pu.scheme == SCM_GOPHER) { - p = pu.file; + p = file_unquote(pu.file); while(*p == '/') ++p; switch (*p) { @@ -1974,6 +1974,16 @@ loadGeneralFile(char *path, ParsedURL *volatile current, char *referer, t = "gopher:directory"; TRAP_OFF; goto page_loaded; + case '7': + if(pu.query != NULL) { + page = loadGopherDir(&f, &pu, &charset); + t = "gopher:directory"; + } else { + page = loadGopherSearch(&f, &pu, &charset); + t = "gopher:search"; + } + TRAP_OFF; + goto page_loaded; case 's': t = "audio/basic"; break; @@ -1983,6 +1993,9 @@ loadGeneralFile(char *path, ParsedURL *volatile current, char *referer, case 'h': t = "text/html"; break; + case '9': + do_download = 1; + break; } } #endif /* USE_GOPHER */ @@ -7455,6 +7468,9 @@ loadGopherDir(URLFile *uf, ParsedURL *pu, wc_ces * charset) case '1': p = "[directory]"; break; + case '7': + p = "[search]"; + break; case 'm': p = "[message]"; break; @@ -7470,6 +7486,9 @@ loadGopherDir(URLFile *uf, ParsedURL *pu, wc_ces * charset) case 'i': link = 0; break; + case '9': + p = "[binary]"; + break; default: p = "[unsupported]"; break; @@ -7502,6 +7521,31 @@ loadGopherDir(URLFile *uf, ParsedURL *pu, wc_ces * charset) Strcat_charp(tmp, "\n\n\n"); return tmp; } + +Str +loadGopherSearch(URLFile *uf, ParsedURL *pu, wc_ces * charset) +{ + Str tmp; + char *volatile p, *volatile q; + MySignalHandler(*volatile prevtrap) (SIGNAL_ARG) = NULL; + tmp = parsedURL2Str(pu); + p = html_quote(tmp->ptr); +#ifdef USE_M17N + wc_ces doc_charset = DocumentCharset; + tmp = + convertLine(NULL, Strnew_charp(file_unquote(tmp->ptr)), RAW_MODE, + charset, doc_charset); +#endif + q = html_quote(tmp->ptr); + + tmp = Strnew_m_charp("\n\n\n", q, + "\n\n\n

Search ", q, + "

\n
\n
\n" + "" + "
\n
\n", NULL); + + return tmp; +} #endif /* USE_GOPHER */ /* diff --git a/proto.h b/proto.h index b20538e..749a3c0 100644 --- a/proto.h +++ b/proto.h @@ -262,6 +262,7 @@ extern void loadHTMLstream(URLFile *f, Buffer *newBuf, FILE * src, extern Buffer *loadHTMLString(Str page); #ifdef USE_GOPHER extern Str loadGopherDir(URLFile *uf, ParsedURL *pu, wc_ces * charset); +extern Str loadGopherSearch(URLFile *uf, ParsedURL *pu, wc_ces * charset); #endif /* USE_GOPHER */ extern Buffer *loadBuffer(URLFile *uf, Buffer *newBuf); #ifdef USE_IMAGE diff --git a/url.c b/url.c index ce0a53c..7368e94 100644 --- a/url.c +++ b/url.c @@ -1839,6 +1839,7 @@ openURL(char *url, ParsedURL *pu, ParsedURL *current, #ifdef USE_GOPHER case SCM_GOPHER: p = pu->file; + q = p; n = 0; while(*p == '/') { ++p; @@ -1853,6 +1854,8 @@ openURL(char *url, ParsedURL *pu, ParsedURL *current, case 's': case 'g': case 'h': + case '7': + case '9': tmp = Strnew_charp(pu->file); gophertmp = Strdup(tmp); Strdelete(tmp, n, 1); @@ -1865,6 +1868,17 @@ openURL(char *url, ParsedURL *pu, ParsedURL *current, } else { type = '\0'; } + while(*p != '\0') { + if(*p == '?') + *p = '\t'; + ++p; + } + if(pu->query != NULL) { + tmp = Strnew_charp(pu->file); + Strcat_char(tmp, '\t'); + Strcat_charp(tmp, pu->query); + pu->file = tmp->ptr; + } if (non_null(GOPHER_proxy) && !Do_not_use_proxy && pu->host != NULL && !check_no_proxy(pu->host)) { -- cgit v1.2.3 From 30f873ddb1a77aa5c508e3fe863b08cc94257ed7 Mon Sep 17 00:00:00 2001 From: bptato Date: Sat, 7 Nov 2020 23:16:41 +0100 Subject: Remove unnecessary variable assignment --- url.c | 1 - 1 file changed, 1 deletion(-) diff --git a/url.c b/url.c index 7368e94..1a16c30 100644 --- a/url.c +++ b/url.c @@ -1839,7 +1839,6 @@ openURL(char *url, ParsedURL *pu, ParsedURL *current, #ifdef USE_GOPHER case SCM_GOPHER: p = pu->file; - q = p; n = 0; while(*p == '/') { ++p; -- cgit v1.2.3 From 469c4084aa85a6ded18b259703509a79480bd8c0 Mon Sep 17 00:00:00 2001 From: bptato Date: Sat, 7 Nov 2020 23:23:33 +0100 Subject: Remove unnecessary file_unquote call --- file.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/file.c b/file.c index f5aaa5b..268e3f8 100644 --- a/file.c +++ b/file.c @@ -1961,7 +1961,7 @@ loadGeneralFile(char *path, ParsedURL *volatile current, char *referer, #endif /* USE_NNTP */ #ifdef USE_GOPHER else if (pu.scheme == SCM_GOPHER) { - p = file_unquote(pu.file); + p = pu.file; while(*p == '/') ++p; switch (*p) { -- cgit v1.2.3 From ba6bed3cb1dcdef2fed0e32d686ee340c2c56077 Mon Sep 17 00:00:00 2001 From: bptato Date: Sat, 7 Nov 2020 23:30:53 +0100 Subject: Remove useless loop --- url.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/url.c b/url.c index 1a16c30..aef66ad 100644 --- a/url.c +++ b/url.c @@ -1867,11 +1867,6 @@ openURL(char *url, ParsedURL *pu, ParsedURL *current, } else { type = '\0'; } - while(*p != '\0') { - if(*p == '?') - *p = '\t'; - ++p; - } if(pu->query != NULL) { tmp = Strnew_charp(pu->file); Strcat_char(tmp, '\t'); -- cgit v1.2.3