diff options
author | Tatsuya Kinoshita <tats@debian.org> | 2013-04-08 12:56:59 +0000 |
---|---|---|
committer | Tatsuya Kinoshita <tats@debian.org> | 2013-04-08 12:56:59 +0000 |
commit | fa5bc4b95d1ea172e465ee4186724130cbe16414 (patch) | |
tree | 65d67bec6c1b212301c4745e4c99e18bd1109931 /url.c | |
parent | Merge branch 'feature/sgrmouse' (diff) | |
parent | One more patch for siteconf from [w3m-dev 04464] (diff) | |
download | w3m-fa5bc4b95d1ea172e465ee4186724130cbe16414.tar.gz w3m-fa5bc4b95d1ea172e465ee4186724130cbe16414.zip |
Merge branch 'feature/siteconf'
Diffstat (limited to 'url.c')
-rw-r--r-- | url.c | 122 |
1 files changed, 99 insertions, 23 deletions
@@ -444,6 +444,8 @@ baseURL(Buffer *buf) /* <BASE> tag is defined in the document */ return buf->baseURL; } + else if (IS_EMPTY_PARSED_URL(&buf->currentURL)) + return NULL; else return &buf->currentURL; } @@ -638,16 +640,21 @@ openSocket(char *const hostname, #define COPYPATH_SPC_ALLOW 0 #define COPYPATH_SPC_IGNORE 1 #define COPYPATH_SPC_REPLACE 2 +#define COPYPATH_SPC_MASK 3 +#define COPYPATH_LOWERCASE 4 static char * copyPath(char *orgpath, int length, int option) { Str tmp = Strnew(); - while (*orgpath && length != 0) { - if (IS_SPACE(*orgpath)) { - switch (option) { + char ch; + while ((ch = *orgpath) != 0 && length != 0) { + if (option & COPYPATH_LOWERCASE) + ch = TOLOWER(ch); + if (IS_SPACE(ch)) { + switch (option & COPYPATH_SPC_MASK) { case COPYPATH_SPC_ALLOW: - Strcat_char(tmp, *orgpath); + Strcat_char(tmp, ch); break; case COPYPATH_SPC_IGNORE: /* do nothing */ @@ -658,7 +665,7 @@ copyPath(char *orgpath, int length, int option) } } else - Strcat_char(tmp, *orgpath); + Strcat_char(tmp, ch); orgpath++; length--; } @@ -668,22 +675,14 @@ copyPath(char *orgpath, int length, int option) void parseURL(char *url, ParsedURL *p_url, ParsedURL *current) { - char *p, *q; + char *p, *q, *qq; Str tmp; url = url_quote(url); /* quote 0x01-0x20, 0x7F-0xFF */ p = url; + copyParsedURL(p_url, NULL); p_url->scheme = SCM_MISSING; - p_url->port = 0; - p_url->user = NULL; - p_url->pass = NULL; - p_url->host = NULL; - p_url->is_nocache = 0; - p_url->file = NULL; - p_url->real_file = NULL; - p_url->query = NULL; - p_url->label = NULL; /* RFC1808: Relative Uniform Resource Locators * 4. Resolving Relative URLs @@ -694,7 +693,7 @@ parseURL(char *url, ParsedURL *p_url, ParsedURL *current) goto do_label; } #if defined( __EMX__ ) || defined( __CYGWIN__ ) - if (!strncmp(url, "file://localhost/", 17)) { + if (!strncasecmp(url, "file://localhost/", 17)) { p_url->scheme = SCM_LOCAL; p += 17 - 1; url += 17 - 1; @@ -802,19 +801,20 @@ parseURL(char *url, ParsedURL *p_url, ParsedURL *current) /* scheme://user:pass@host or * scheme://host:port */ - p_url->host = copyPath(q, p - q, COPYPATH_SPC_IGNORE); + qq = q; q = ++p; while (*p && strchr("@/?#", *p) == NULL) p++; if (*p == '@') { /* scheme://user:pass@... */ + p_url->user = copyPath(qq, q - 1 - qq, COPYPATH_SPC_IGNORE); p_url->pass = copyPath(q, p - q, COPYPATH_SPC_ALLOW); q = ++p; - p_url->user = p_url->host; - p_url->host = NULL; goto analyze_url; } /* scheme://host:port/ */ + p_url->host = copyPath(qq, q - 1 - qq, + COPYPATH_SPC_IGNORE | COPYPATH_LOWERCASE); tmp = Strnew_charp_n(q, p - q); p_url->port = atoi(tmp->ptr); /* *p is one of ['\0', '/', '?', '#'] */ @@ -829,7 +829,8 @@ parseURL(char *url, ParsedURL *p_url, ParsedURL *current) case '/': case '?': case '#': - p_url->host = copyPath(q, p - q, COPYPATH_SPC_IGNORE); + p_url->host = copyPath(q, p - q, + COPYPATH_SPC_IGNORE | COPYPATH_LOWERCASE); p_url->port = DefaultPort[p_url->scheme]; break; } @@ -956,12 +957,16 @@ parseURL(char *url, ParsedURL *p_url, ParsedURL *current) p_url->label = NULL; } -#define initParsedURL(p) bzero(p,sizeof(ParsedURL)) #define ALLOC_STR(s) ((s)==NULL?NULL:allocStr(s,-1)) void -copyParsedURL(ParsedURL *p, ParsedURL *q) +copyParsedURL(ParsedURL *p, const ParsedURL *q) { + if (q == NULL) { + memset(p, 0, sizeof(ParsedURL)); + p->scheme = SCM_UNKNOWN; + return; + } p->scheme = q->scheme; p->port = q->port; p->is_nocache = q->is_nocache; @@ -1283,6 +1288,8 @@ static char * otherinfo(ParsedURL *target, ParsedURL *current, char *referer) { Str s = Strnew(); + const int *no_referer_ptr; + int no_referer; Strcat_charp(s, "User-Agent: "); if (UserAgent == NULL || *UserAgent == '\0') @@ -1306,7 +1313,12 @@ otherinfo(ParsedURL *target, ParsedURL *current, char *referer) Strcat_charp(s, "Pragma: no-cache\r\n"); Strcat_charp(s, "Cache-control: no-cache\r\n"); } - if (!NoSendReferer) { + no_referer = NoSendReferer; + no_referer_ptr = query_SCONF_NO_REFERER_FROM(current); + no_referer = NoSendReferer || (no_referer_ptr && *no_referer_ptr); + no_referer_ptr = query_SCONF_NO_REFERER_TO(target); + no_referer = no_referer || (no_referer_ptr && *no_referer_ptr); + if (!no_referer) { #ifdef USE_SSL if (current && current->scheme == SCM_HTTPS && target->scheme != SCM_HTTPS) { /* Don't send Referer: if https:// -> http:// */ @@ -1314,6 +1326,7 @@ otherinfo(ParsedURL *target, ParsedURL *current, char *referer) else #endif if (referer == NULL && current && current->scheme != SCM_LOCAL && + current->scheme != SCM_LOCAL_CGI && (current->scheme != SCM_FTP || (current->user == NULL && current->pass == NULL))) { char *p = current->label; @@ -2234,3 +2247,66 @@ schemeToProxy(int scheme) } return pu; } + +#ifdef USE_M17N +wc_ces +url_to_charset(const char *url, const ParsedURL *base, wc_ces doc_charset) +{ + const ParsedURL *pu; + ParsedURL pu_buf; + const wc_ces *csptr; + + if (url && *url && *url != '#') { + parseURL2((char *)url, &pu_buf, (ParsedURL *)base); + pu = &pu_buf; + } else { + pu = base; + } + if (pu && (pu->scheme == SCM_LOCAL || pu->scheme == SCM_LOCAL_CGI)) + return SystemCharset; + csptr = query_SCONF_URL_CHARSET(pu); + return (csptr && *csptr) ? *csptr : + doc_charset ? doc_charset : DocumentCharset; +} + +char * +url_encode(const char *url, const ParsedURL *base, wc_ces doc_charset) +{ + return url_quote_conv((char *)url, + url_to_charset(url, base, doc_charset)); +} + +#if 0 /* unused */ +char * +url_decode(const char *url, const ParsedURL *base, wc_ces doc_charset) +{ + if (!DecodeURL) + return (char *)url; + return url_unquote_conv((char *)url, + url_to_charset(url, base, doc_charset)); +} +#endif + +char * +url_decode2(const char *url, const Buffer *buf) +{ + wc_ces url_charset; + + if (!DecodeURL) + return (char *)url; + url_charset = buf ? + url_to_charset(url, baseURL((Buffer *)buf), buf->document_charset) : + url_to_charset(url, NULL, 0); + return url_unquote_conv((char *)url, url_charset); +} + +#else /* !defined(USE_M17N) */ + +char * +url_decode0(const char *url) +{ + if (!DecodeURL) + return (char *)url; + return url_unquote_conv((char *)url, 0); +} +#endif /* !defined(USE_M17N) */ |