X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=ucw%2Furl.c;h=39e52946e2bd086cd3cbdaefa4985fe217b56fde;hb=342e0c3edeacf4eecd03da36c879ca817c64a0f3;hp=8f5073a99721aadef2b1b29526940ee5d58bc8db;hpb=689b60e4c61d300b576fdb7007de51189d2f0f7e;p=libucw.git diff --git a/ucw/url.c b/ucw/url.c index 8f5073a9..39e52946 100644 --- a/ucw/url.c +++ b/ucw/url.c @@ -7,11 +7,6 @@ * This software may be freely distributed and used according to the terms * of the GNU Lesser General Public License. * - * The URL syntax corresponds to RFC 2396 with several exceptions: - * - * o Escaping of special characters still follows RFC 1738. - * o Interpretation of path parameters follows RFC 1808. - * * XXX: The buffer handling in this module is really horrible, but it works. */ @@ -35,6 +30,7 @@ static uns url_min_repeat_count = 0x7fffffff; static uns url_max_repeat_length = 0; static uns url_max_occurences = ~0U; +#ifndef TEST static struct cf_section url_config = { CF_ITEMS { CF_UNS("IgnoreSpaces", &url_ignore_spaces), @@ -51,6 +47,7 @@ static void CONSTRUCTOR url_init_config(void) { cf_declare_section("URL", &url_config, 0); } +#endif /* Escaping and de-escaping */ @@ -95,6 +92,14 @@ url_deescape(const char *s, char *d) val = NCC_AND; break; case '#': val = NCC_HASH; break; +#ifndef CONFIG_URL_ESCAPE_COMPAT + case '$': + val = NCC_DOLLAR; break; + case '+': + val = NCC_PLUS; break; + case ',': + val = NCC_COMMA; break; +#endif } *d++ = val; s += 3; @@ -133,16 +138,19 @@ url_enescape(const char *s, char *d) { if (d >= end) return URL_ERR_TOO_LONG; - if (Calnum(c) || /* RFC 1738(2.2): Only alphanumerics ... */ - c == '$' || c == '-' || c == '_' || c == '.' || c == '+' || /* ... and several other exceptions ... */ - c == '!' || c == '*' || c == '\'' || c == '(' || c == ')' || - c == ',' || - c == '/' || c == '?' || c == ':' || c == '@' || /* ... and reserved chars used for reserved purpose */ - c == '=' || c == '&' || c == '#' || c == ';') + if (Calnum(c) || /* RFC 2396 (2.1-2.3): Only alphanumerics ... */ + c == '!' || c == '*' || c == '\'' || c == '(' || c == ')' || /* ... and some exceptions and reserved chars */ + c == '$' || c == '-' || c == '_' || c == '.' || c == '+' || + c == ',' || c == '=' || c == '&' || c == '#' || c == ';' || + c == '/' || c == '?' || c == ':' || c == '@' +#ifndef CONFIG_URL_ESCAPE_COMPAT + || c == '~' +#endif + ) *d++ = *s++; else { - uns val = ((byte)*s < NCC_MAX) ? NCC_CHARS[(byte)*s] : *s; + uns val = (byte)(((byte)*s < NCC_MAX) ? NCC_CHARS[(byte)*s] : *s); *d++ = '%'; *d++ = enhex(val >> 4); *d++ = enhex(val & 0x0f); @@ -162,14 +170,14 @@ url_enescape_friendly(const char *src, char *dest) { if (dest >= end) return URL_ERR_TOO_LONG; - if (*srcb < NCC_MAX) + if ((byte)*srcb < NCC_MAX) *dest++ = NCC_CHARS[*srcb++]; else if (*srcb >= 0x20 && *srcb < 0x7f) *dest++ = *srcb++; else { *dest++ = '%'; - *dest++ = enhex(*srcb >> 4); + *dest++ = enhex((byte)*srcb >> 4); *dest++ = enhex(*srcb++ & 0x0f); } } @@ -183,7 +191,7 @@ char *url_proto_names[URL_PROTO_MAX] = URL_PNAMES; static int url_proto_path_flags[URL_PROTO_MAX] = URL_PATH_FLAGS; uns -identify_protocol(const char *p) +url_identify_protocol(const char *p) { uns i; @@ -211,7 +219,7 @@ url_split(char *s, struct url *u, char *d) while (s < p) *d++ = *s++; *d++ = 0; - u->protoid = identify_protocol(u->protocol); + u->protoid = url_identify_protocol(u->protocol); s++; if (url_proto_path_flags[u->protoid] && (s[0] != '/' || s[1] != '/')) { @@ -318,15 +326,9 @@ relpath_merge(struct url *u, struct url *b) ; goto copy; } - if (a[0] == ';') /* Change parameters */ - { - for(p=o; *p && *p != ';' && *p != '?' && *p != '#'; p++) - ; - goto copy; - } p = NULL; /* Copy original path and find the last slash */ - while (*o && *o != ';' && *o != '?' && *o != '#') + while (*o && *o != '?' && *o != '#') { if (d >= e) return URL_ERR_TOO_LONG; @@ -517,7 +519,7 @@ url_pack(struct url *u, char *d) { d = append(d, u->protocol, e); d = append(d, ":", e); - u->protoid = identify_protocol(u->protocol); + u->protoid = url_identify_protocol(u->protocol); } if (u->host) { @@ -610,7 +612,7 @@ int main(int argc, char **argv) char buf1[MAX_URL_SIZE], buf2[MAX_URL_SIZE], buf3[MAX_URL_SIZE], buf4[MAX_URL_SIZE]; int err; struct url url, url0; - char *base = "http://mj@www.hell.org/123/sub_dir/index.html;param?query&zzz/subquery#fragment"; + char *base = "http://mj@www.hell.org/123/sub_dir;param/index.html;param?query&zzz/sub;query+#fragment?"; if (argc != 2 && argc != 3) return 1;