diff options
Diffstat (limited to 'WWW/Library/Implementation/HTParse.c')
-rw-r--r-- | WWW/Library/Implementation/HTParse.c | 68 |
1 files changed, 47 insertions, 21 deletions
diff --git a/WWW/Library/Implementation/HTParse.c b/WWW/Library/Implementation/HTParse.c index 34703652..4b09e64a 100644 --- a/WWW/Library/Implementation/HTParse.c +++ b/WWW/Library/Implementation/HTParse.c @@ -5,6 +5,7 @@ #include <HTUtils.h> #include <HTParse.h> +#include <LYUtils.h> #include <LYLeaks.h> #define HEX_ESCAPE '%' @@ -150,19 +151,6 @@ PRIVATE void scan ARGS2( } } } - -#ifdef NOT_DEFINED /* search is just treated as part of path */ - { - char *p = (relative ? relative : absolute); - if (p != NULL) { - char *q = strchr(p, '?'); /* Any search string? */ - if (q != NULL) { - *q = '\0'; /* If so, chop that off. */ - parts->search = (q + 1); - } - } - } -#endif /* NOT_DEFINED */ } /*scan */ @@ -420,9 +408,9 @@ PUBLIC char * HTParse ARGS3( strcat(result, related.relative); CTRACE((tfp, "HTParse: (Related-REL)\n")); } else { /* No inheritance */ - if (strncasecomp(aName, "lynxcgi:", 8) && - strncasecomp(aName, "lynxexec:", 9) && - strncasecomp(aName, "lynxprog:", 9)) { + if (!isLYNXCGI(aName) && + !isLYNXEXEC(aName) && + !isLYNXPROG(aName)) { strcat(result, "/"); } if (!strcmp(result, "news:/")) @@ -697,8 +685,8 @@ PUBLIC char * HTRelative ARGS2( return result; } -/* Escape undesirable characters using % HTEscape() -** ------------------------------------- +/* Escape undesirable characters using % HTEscape() +** ------------------------------------- ** ** This function takes a pointer to a string in which ** some characters may be unacceptable unescaped. @@ -711,7 +699,7 @@ PRIVATE CONST unsigned char isAcceptable[96] = /* Bit 0 xalpha -- see HTFile.h ** Bit 1 xpalpha -- as xalpha but with plus. -** Bit 3 ... path -- as xpalphas but with / +** Bit 2 ... path -- as xpalphas but with / */ /* 0 1 2 3 4 5 6 7 8 9 A B C D E F */ { 0,0,0,0,0,0,0,0,0,0,7,6,0,7,7,4, /* 2x !"#$%&'()*+,-./ */ @@ -741,13 +729,51 @@ PUBLIC char * HTEscape ARGS2( for (q = result, p = str; *p; p++) { unsigned char a = TOASCII(*p); if (!ACCEPTABLE(a)) { - *q++ = HEX_ESCAPE; /* Means hex commming */ + *q++ = HEX_ESCAPE; /* Means hex coming */ *q++ = hex[a >> 4]; *q++ = hex[a & 15]; } else *q++ = *p; } - *q++ = '\0'; /* Terminate */ + *q++ = '\0'; /* Terminate */ + return result; +} + +/* Escape unsafe characters using % HTEscapeUnsafe() +** -------------------------------- +** +** This function takes a pointer to a string in which +** some characters may be that may be unsafe are unescaped. +** It returns a string which has these characters +** represented by a '%' character followed by two hex digits. +** +** Unlike HTUnEscape(), this routine returns a malloc'd string. +*/ +#define UNSAFE(ch) (((ch) <= 32) || ((ch) >= 127)) + +PUBLIC char *HTEscapeUnsafe ARGS1( + CONST char *, str) +{ + CONST char * p; + char * q; + char * result; + int unacceptable = 0; + for (p = str; *p; p++) + if (UNSAFE(UCH(TOASCII(*p)))) + unacceptable++; + result = typecallocn(char, p-str + unacceptable + unacceptable + 1); + if (result == NULL) + outofmem(__FILE__, "HTEscapeUnsafe"); + for (q = result, p = str; *p; p++) { + unsigned char a = TOASCII(*p); + if (UNSAFE(a)) { + *q++ = HEX_ESCAPE; /* Means hex coming */ + *q++ = hex[a >> 4]; + *q++ = hex[a & 15]; + } + else *q++ = *p; + } + *q++ = '\0'; /* Terminate */ return result; } |