w3m

Unnamed repository; edit this file to name it for gitweb.
git clone https://logand.com/git/w3m.git/
Log | Files | Refs | README

commit 86d2ecf70c5cb78ee4775cdc3e1855e8a6b5fd83
parent 220e2f83772a735bfa552f8e8b39e6393ccde677
Author: ukai <ukai>
Date:   Wed,  8 Jan 2003 17:24:11 +0000

[w3m-dev 03616] Re: data: URL scheme
* file.c (loadGeneralFile): check SCM_DATA
	(loadImageBuffer): newBuffer()
* html.h (SCM_DATA): added
* indep.c (url_unquote): deleted
	(Str_url_unquote): renamed from Str_form_unquote
			+ is decoded is_form only
* indep.h (url_unquote): deleted
	(Str_url_unquote): added
	(Str_form_unquote): define by Str_url_unquote
* main.c (followA): file_unquote
	(cmd_loadURL): file_unquote
* url.c (DefaultPort): add for data:
	(schemetable): add "data"
	(DefaultFile): SCM_FTPDIR
	(parseURL): scheme copied from current
	(parseURL2): SCM_DATA
		check SCM_FTP, SCM_FTPDIR
	(_parsedURL2Str): add data in scheme_str
		handle SCM_DATA
		SCM_FTPDIR
	(openURL): file_unquote
		handle SCM_DATA
From: Hironori SAKAMOTO <hsaka@mth.biglobe.ne.jp>

Diffstat:
MChangeLog | 26++++++++++++++++++++++++++
Mfile.c | 7+++++--
Mhtml.h | 5+++--
Mindep.c | 33+++------------------------------
Mindep.h | 4++--
Mmain.c | 4++--
Murl.c | 64++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------
7 files changed, 99 insertions(+), 44 deletions(-)

diff --git a/ChangeLog b/ChangeLog @@ -1,3 +1,29 @@ +2003-01-09 Hironori SAKAMOTO <hsaka@mth.biglobe.ne.jp> + + * [w3m-dev 03616] Re: data: URL scheme + * file.c (loadGeneralFile): check SCM_DATA + (loadImageBuffer): newBuffer() + * html.h (SCM_DATA): added + * indep.c (url_unquote): deleted + (Str_url_unquote): renamed from Str_form_unquote + + is decoded is_form only + * indep.h (url_unquote): deleted + (Str_url_unquote): added + (Str_form_unquote): define by Str_url_unquote + * main.c (followA): file_unquote + (cmd_loadURL): file_unquote + * url.c (DefaultPort): add for data: + (schemetable): add "data" + (DefaultFile): SCM_FTPDIR + (parseURL): scheme copied from current + (parseURL2): SCM_DATA + check SCM_FTP, SCM_FTPDIR + (_parsedURL2Str): add data in scheme_str + handle SCM_DATA + SCM_FTPDIR + (openURL): file_unquote + handle SCM_DATA + 2003-01-08 Hironori SAKAMOTO <hsaka@mth.biglobe.ne.jp> * [w3m-dev 03611] relative URL diff --git a/file.c b/file.c @@ -1870,6 +1870,9 @@ loadGeneralFile(char *path, ParsedURL *volatile current, char *referer, } #endif } + else if (pu.scheme == SCM_DATA) { + t = f.guess_type; + } else if (searchHeader) { t_buf = newBuffer(INIT_BUFFER_WIDTH); readHeader(&f, t_buf, searchHeader_through, &pu); @@ -6867,13 +6870,13 @@ loadImageBuffer(URLFile *uf, Buffer *newBuf) cache->index = 0; image_buffer: + if (newBuf == NULL) + newBuf = newBuffer(INIT_BUFFER_WIDTH); cache->loaded |= IMG_FLAG_DONT_REMOVE; if (uf->scheme != SCM_LOCAL) newBuf->sourcefile = cache->file; tmp = Sprintf("<img src=\"%s\"><br><br>", html_quote(image->url)); - if (newBuf == NULL) - newBuf = newBuffer(INIT_BUFFER_WIDTH); tmpf = tmpfname(TMPF_SRC, ".html"); src = fopen(tmpf->ptr, "w"); newBuf->mailcap_source = tmpf->ptr; diff --git a/html.h b/html.h @@ -364,9 +364,10 @@ struct environment { #define SCM_NNTP_GROUP 8 #define SCM_NEWS 9 #define SCM_NEWS_GROUP 10 -#define SCM_MAILTO 11 +#define SCM_DATA 11 +#define SCM_MAILTO 12 #ifdef USE_SSL -#define SCM_HTTPS 12 +#define SCM_HTTPS 13 #endif /* USE_SSL */ #endif /* _HTML_H */ diff --git a/indep.c b/indep.c @@ -535,34 +535,6 @@ url_quote(char *str) } char * -url_unquote(char *str) -{ - Str tmp = NULL; - char *p, *q; - int c; - - for (p = str; *p;) { - if (*p == '%') { - q = p; - c = url_unquote_char(&q); - if (c >= 0 && c != '\0' && c != '\n' && c != '\r') { - if (tmp == NULL) - tmp = Strnew_charp_n(str, (int)(p - str)); - Strcat_char(tmp, (char)c); - p = q; - continue; - } - } - if (tmp) - Strcat_char(tmp, *p); - p++; - } - if (tmp) - return tmp->ptr; - return str; -} - -char * file_quote(char *str) { Str tmp = NULL; @@ -661,15 +633,16 @@ Str_form_quote(Str x) return x; } + Str -Str_form_unquote(Str x) +Str_url_unquote(Str x, int is_form) { Str tmp = NULL; char *p = x->ptr, *ep = x->ptr + x->length, *q; int c; for (; p < ep;) { - if (*p == '+') { + if (is_form && *p == '+') { if (tmp == NULL) tmp = Strnew_charp_n(x->ptr, (int)(p - x->ptr)); Strcat_char(tmp, ' '); diff --git a/indep.h b/indep.h @@ -45,9 +45,9 @@ extern char *html_unquote(char *str); extern char *file_quote(char *str); extern char *file_unquote(char *str); extern char *url_quote(char *str); -extern char *url_unquote(char *str); +extern Str Str_url_unquote(Str x, int is_form); extern Str Str_form_quote(Str x); -extern Str Str_form_unquote(Str x); +#define Str_form_unquote(x) Str_url_unquote((x), TRUE) extern char *shell_quote(char *str); extern char *w3m_auxbin_dir(); diff --git a/main.c b/main.c @@ -2864,7 +2864,7 @@ followA(void) Strtruncate(to, pos - to->ptr); #endif fmTerm(); - system(myExtCommand(Mailer, shell_quote(url_unquote(to->ptr)), + system(myExtCommand(Mailer, shell_quote(file_unquote(to->ptr)), FALSE)->ptr); fmInit(); displayBuffer(Currentbuf, B_FORCE_REDRAW); @@ -3819,7 +3819,7 @@ cmd_loadURL(char *url, ParsedURL *current, char *referer) Strtruncate(to, pos - to->ptr); #endif fmTerm(); - system(myExtCommand(Mailer, shell_quote(url_unquote(to->ptr)), + system(myExtCommand(Mailer, shell_quote(file_unquote(to->ptr)), FALSE)->ptr); fmInit(); displayBuffer(Currentbuf, B_FORCE_REDRAW); diff --git a/url.c b/url.c @@ -56,6 +56,7 @@ static int 119, /* nntp group */ 119, /* news */ 119, /* news group */ + 0, /* data - not defined */ 0, /* mailto - not defined */ #ifdef USE_SSL 443, /* https */ @@ -73,6 +74,7 @@ struct cmdtable schemetable[] = { /* {"nntp", SCM_NNTP_GROUP}, */ {"news", SCM_NEWS}, /* {"news", SCM_NEWS_GROUP}, */ + {"data", SCM_DATA}, #ifndef USE_W3MMAILER {"mailto", SCM_MAILTO}, #endif @@ -226,6 +228,7 @@ DefaultFile(int scheme) case SCM_LOCAL: case SCM_LOCAL_CGI: case SCM_FTP: + case SCM_FTPDIR: return allocStr("/", -1); } return NULL; @@ -708,9 +711,29 @@ parseURL(char *url, ParsedURL *p_url, ParsedURL *current) * denotes a filename (therefore the scheme is SCM_LOCAL). */ if (current) { - p_url->scheme = current->scheme; - if (p_url->scheme == SCM_LOCAL_CGI) - p_url->scheme = SCM_LOCAL; + switch (current->scheme) { + case SCM_LOCAL: + case SCM_LOCAL_CGI: + p_url->scheme = SCM_LOCAL; + break; + case SCM_FTP: + case SCM_FTPDIR: + p_url->scheme = SCM_FTP; + break; +#ifdef USE_NNTP + case SCM_NNTP: + case SCM_NNTP_GROUP: + p_url->scheme = SCM_NNTP; + break; + case SCM_NEWS: + case SCM_NEWS_GROUP: + p_url->scheme = SCM_NEWS; + break; +#endif + default: + p_url->scheme = current->scheme; + break; + } } else p_url->scheme = SCM_LOCAL; @@ -970,6 +993,8 @@ parseURL2(char *url, ParsedURL *pu, ParsedURL *current) if (pu->scheme == SCM_MAILTO) return; #endif + if (pu->scheme == SCM_DATA) + return; if (pu->scheme == SCM_NEWS || pu->scheme == SCM_NEWS_GROUP) { if (pu->file && !strchr(pu->file, '@') && (!(p = strchr(pu->file, '/')) || strchr(p + 1, '-') || @@ -1000,7 +1025,9 @@ parseURL2(char *url, ParsedURL *pu, ParsedURL *current) if (pu->scheme == SCM_LOCAL) pu->file = expandName(pu->file); - if (current && pu->scheme == current->scheme && pu->host == NULL) { + if (current && (pu->scheme == current->scheme || + (pu->scheme == SCM_FTP && current->scheme == SCM_FTPDIR)) + && pu->host == NULL) { /* Copy omitted element from the current URL */ pu->user = current->user; pu->pass = current->pass; @@ -1120,7 +1147,7 @@ _parsedURL2Str(ParsedURL *pu, int pass) Str tmp; static char *scheme_str[] = { "http", "gopher", "ftp", "ftp", "file", "file", "exec", "nntp", "nntp", - "news", "news", "mailto", + "news", "news", "data", "mailto", #ifdef USE_SSL "https", #endif /* USE_SSL */ @@ -1156,6 +1183,10 @@ _parsedURL2Str(ParsedURL *pu, int pass) return tmp; } #endif + if (pu->scheme == SCM_DATA) { + Strcat_charp(tmp, pu->file); + return tmp; + } #ifdef USE_NNTP if (pu->scheme != SCM_NEWS && pu->scheme != SCM_NEWS_GROUP) #endif /* USE_NNTP */ @@ -1593,6 +1624,7 @@ openURL(char *url, ParsedURL *pu, ParsedURL *current, } return uf; case SCM_FTP: + case SCM_FTPDIR: if (pu->file == NULL) pu->file = allocStr("/", -1); if (non_null(FTP_proxy) && @@ -1769,7 +1801,7 @@ openURL(char *url, ParsedURL *pu, ParsedURL *current, return uf; if (pu->file == NULL) pu->file = "1"; - tmp = Strnew_charp(url_unquote(pu->file)); + tmp = Strnew_charp(file_unquote(pu->file)); Strcat_char(tmp, '\n'); } write(sock, tmp->ptr, tmp->length); @@ -1787,6 +1819,26 @@ openURL(char *url, ParsedURL *pu, ParsedURL *current, uf.stream = openNewsStream(pu); return uf; #endif /* USE_NNTP */ + case SCM_DATA: + if (pu->file == NULL) + return uf; + p = Strnew_charp(pu->file)->ptr; + q = strchr(p, ','); + if (q == NULL) + return uf; + *q++ = '\0'; + tmp = Strnew_charp(q); + q = strrchr(p, ';'); + if (q != NULL && !strcmp(q, ";base64")) + { + *q = '\0'; + uf.encoding = ENC_BASE64; + } + else + tmp = Str_url_unquote(tmp, FALSE); + uf.stream = newStrStream(tmp); + uf.guess_type = (*p != '\0') ? p : "text/plain"; + return uf; case SCM_UNKNOWN: default: return uf;