diff options
Diffstat (limited to 'WWW')
-rw-r--r-- | WWW/Library/Implementation/HTParse.c | 12 | ||||
-rw-r--r-- | WWW/Library/Implementation/HTParse.h | 7 | ||||
-rw-r--r-- | WWW/Library/Implementation/HTTP.c | 38 | ||||
-rw-r--r-- | WWW/Library/Implementation/HTUtils.h | 3 |
4 files changed, 34 insertions, 26 deletions
diff --git a/WWW/Library/Implementation/HTParse.c b/WWW/Library/Implementation/HTParse.c index 34833801..c76fcfbc 100644 --- a/WWW/Library/Implementation/HTParse.c +++ b/WWW/Library/Implementation/HTParse.c @@ -1,5 +1,5 @@ /* - * $LynxId: HTParse.c,v 1.75 2014/02/12 23:15:42 tom Exp $ + * $LynxId: HTParse.c,v 1.76 2016/11/24 12:25:45 tom Exp $ * * Parse HyperText Document Address HTParse.c * ================================ @@ -302,7 +302,7 @@ static void convert_to_idna(char *host) idna_strerror((Idna_rc) code))); } if (output) - idn_free (output); + idn_free(output); } free(buffer); } @@ -473,8 +473,6 @@ char *HTParse(const char *aName, *tail++ = '/'; } strcpy(tail, given.host ? given.host : related.host); -#define CLEAN_URLS -#ifdef CLEAN_URLS /* * Ignore default port numbers, and trailing dots on FQDNs, which * will only cause identical addresses to look different. (related @@ -483,9 +481,12 @@ char *HTParse(const char *aName, { char *p2, *h; int portnumber; + int gen_delims = 0; - if ((p2 = StrChr(result, '@')) != NULL) + if ((p2 = HTSkipToAt(result, &gen_delims)) != NULL + && gen_delims == 0) { tail = (p2 + 1); + } p2 = HTParsePort(result, &portnumber); if (p2 != NULL && acc_method != NULL) { /* @@ -539,7 +540,6 @@ char *HTParse(const char *aName, */ convert_to_idna(tail); #endif -#endif /* CLEAN_URLS */ } } diff --git a/WWW/Library/Implementation/HTParse.h b/WWW/Library/Implementation/HTParse.h index 3f427c41..ce1bff61 100644 --- a/WWW/Library/Implementation/HTParse.h +++ b/WWW/Library/Implementation/HTParse.h @@ -1,5 +1,5 @@ /* - * $LynxId: HTParse.h,v 1.21 2010/09/24 22:45:23 tom Exp $ + * $LynxId: HTParse.h,v 1.22 2016/11/23 21:06:50 tom Exp $ * HTParse: URL parsing in the WWW Library * HTPARSE * @@ -17,6 +17,11 @@ #ifdef __cplusplus extern "C" { #endif + +#define RFC_3986_UNRESERVED(c) (isalnum(UCH(c)) || strchr("-._~", UCH(c)) != 0) +#define RFC_3986_GEN_DELIMS(c) ((c) != 0 && strchr(":/?#[]@", UCH(c)) != 0) +#define RFC_3986_SUB_DELIMS(c) ((c) != 0 && strchr("!$&'()*+,;=", UCH(c)) != 0) + /* * The following are flag bits which may be ORed together to form * a number to give the 'wanted' argument to HTParse. diff --git a/WWW/Library/Implementation/HTTP.c b/WWW/Library/Implementation/HTTP.c index 08ed0c08..9a5bc2b8 100644 --- a/WWW/Library/Implementation/HTTP.c +++ b/WWW/Library/Implementation/HTTP.c @@ -1,5 +1,5 @@ /* - * $LynxId: HTTP.c,v 1.160 2016/11/15 09:31:41 tom Exp $ + * $LynxId: HTTP.c,v 1.161 2016/11/24 12:20:07 tom Exp $ * * HyperText Tranfer Protocol - Client implementation HTTP.c * ========================== @@ -528,11 +528,7 @@ int ws_netread(int fd, char *buf, int len) * host = IP-literal / IPv4address / reg-name * reg-name = *( unreserved / pct-encoded / sub-delims ) */ -#define RFC_3986_UNRESERVED(c) (isalnum(UCH(c)) || strchr("-._~", UCH(c)) != 0) -#define RFC_3986_GEN_DELIMS(c) ((c) != 0 && strchr(":/?#[]@", UCH(c)) != 0) -#define RFC_3986_SUB_DELIMS(c) ((c) != 0 && strchr("!$&'()*+,;=", UCH(c)) != 0) - -static char *skip_user_passwd(char *host) +char *HTSkipToAt(char *host, int *gen_delims) { char *result = 0; char *s = host; @@ -540,6 +536,7 @@ static char *skip_user_passwd(char *host) int ch; int last = -1; + *gen_delims = 0; while ((ch = UCH(*s)) != '\0') { if (ch == '\0') { break; @@ -551,6 +548,7 @@ static char *skip_user_passwd(char *host) result = s; break; } else if (RFC_3986_GEN_DELIMS(ch)) { + *gen_delims += 1; if (!RFC_3986_GEN_DELIMS(s[1])) break; } else if (ch == '%') { @@ -584,16 +582,15 @@ static char *fake_hostname(char *auth) */ void strip_userid(char *host, int parse_only) { + int gen_delims = 0; char *p1 = host; - char *p2 = skip_user_passwd(host); + char *p2 = HTSkipToAt(host, &gen_delims); if (p2 != 0) { char *msg = NULL; char *auth = NULL; - char *save = NULL; char *fake = NULL; char *p3 = p2; - int gen_delims = 0; int sub_delims = 0; int my_delimit = UCH(*p2); int do_trimming = (my_delimit == '@'); @@ -606,7 +603,6 @@ void strip_userid(char *host, int parse_only) * Trailing "gen-delims" demonstrates that there is no user/password. */ while ((p3 != host) && RFC_3986_GEN_DELIMS(p3[-1])) { - ++gen_delims; *(--p3) = '\0'; } /* @@ -616,15 +612,21 @@ void strip_userid(char *host, int parse_only) ++sub_delims; *(--p3) = '\0'; } - CTRACE((tfp, "trimmed:%s\n", host)); - StrAllocCopy(save, host); + /* + * Trim trailing "gen-delims" from the real hostname. + */ + for (p3 = p2; *p3 != '\0'; ++p3) { + if (RFC_3986_GEN_DELIMS(*p3)) { + *p3 = '\0'; + break; + } + } + CTRACE((tfp, "trim auth: result:`%s'\n", host)); - if (gen_delims || strcmp(save, auth)) { - HTSprintf0(&msg, - gettext("User/password may appear to be a hostname: '%s' (e.g, '%s')"), - auth, save); + if (gen_delims || strcmp(host, auth)) { do_trimming = !gen_delims; - } else if (*host == '\0' && sub_delims) { + } + if (*host == '\0' && sub_delims) { HTSprintf0(&msg, gettext("User/password contains only punctuation: %s"), auth); @@ -639,9 +641,9 @@ void strip_userid(char *host, int parse_only) while ((*p1++ = *p2++) != '\0') { ; } + CTRACE((tfp, "trim host: result:`%s'\n", host)); } FREE(fake); - FREE(save); FREE(auth); FREE(msg); } diff --git a/WWW/Library/Implementation/HTUtils.h b/WWW/Library/Implementation/HTUtils.h index 5c221ccb..744557ab 100644 --- a/WWW/Library/Implementation/HTUtils.h +++ b/WWW/Library/Implementation/HTUtils.h @@ -1,5 +1,5 @@ /* - * $LynxId: HTUtils.h,v 1.121 2016/11/15 09:26:37 tom Exp $ + * $LynxId: HTUtils.h,v 1.122 2016/11/23 22:16:51 tom Exp $ * * Utility macros for the W3 code library * MACROS FOR GENERAL USE @@ -801,6 +801,7 @@ extern "C" { extern FILE *TraceFP(void); + extern char *HTSkipToAt(char *host, int *gen_delims); extern void strip_userid(char *host, int warn); #ifdef USE_SSL |