From: hniksic Date: Wed, 8 May 2002 18:24:40 +0000 (-0700) Subject: [svn] Allow match_tail to be case insensitive. X-Git-Tag: v1.13~1763 X-Git-Url: http://sjero.net/git/?p=wget;a=commitdiff_plain;h=fd42ae13117c207c91558c2f466ffdbf6bb55039 [svn] Allow match_tail to be case insensitive. Published in . --- diff --git a/src/ChangeLog b/src/ChangeLog index addafe0c..14a0e99e 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,14 @@ +2002-05-08 Hrvoje Niksic + + * cookies.c (check_domain_match): Use match_tail in case + insensitive mode. + + * utils.c (match_tail): Allow the caller to specify case + insensitive mode. + + * cookies.c (store_cookie): When expiry_time is 0, print it as + undefined, not indefinite. + 2002-05-07 Ian Abbott * cookies.c (cookie_jar_process_set_cookie): Do not store diff --git a/src/cookies.c b/src/cookies.c index 7df96f7c..3de9c323 100644 --- a/src/cookies.c +++ b/src/cookies.c @@ -230,7 +230,7 @@ store_cookie (struct cookie_jar *jar, struct cookie *cookie) cookie->permanent ? "permanent" : "nonpermanent", cookie->secure, cookie->expiry_time - ? asctime (localtime (&cookie->expiry_time)) : "", + ? asctime (localtime (&cookie->expiry_time)) : "", cookie->attr, cookie->value)); } @@ -676,7 +676,7 @@ check_domain_match (const char *cookie_domain, const char *host) DEBUGP ((" 3")); /* HOST must match the tail of cookie_domain. */ - if (!match_tail (host, cookie_domain)) + if (!match_tail (host, cookie_domain, 1)) return 0; /* We know that COOKIE_DOMAIN is a subset of HOST; however, we must @@ -754,7 +754,7 @@ check_domain_match (const char *cookie_domain, const char *host) ".com", ".edu", ".net", ".org", ".gov", ".mil", ".int" }; for (i = 0; i < ARRAY_SIZE (known_toplevel_domains); i++) - if (match_tail (cookie_domain, known_toplevel_domains[i])) + if (match_tail (cookie_domain, known_toplevel_domains[i], 1)) { known_toplevel = 1; break; diff --git a/src/ftp.c b/src/ftp.c index 45685329..ebddf3a0 100644 --- a/src/ftp.c +++ b/src/ftp.c @@ -698,6 +698,18 @@ Error in server response, closing control connection.\n")); if (cmd & DO_RETR) { + /* If we're in spider mode, don't really retrieve anything. The + fact that we got to this point should be proof enough that + the file exists, vaguely akin to HTTP's concept of a "HEAD" + request. */ + if (opt.spider) + { + CLOSE (csock); + closeport (dtsock); + rbuf_uninitialize (&con->rbuf); + return RETRFINISHED; + } + if (opt.verbose) { if (!opt.server_response) diff --git a/src/utils.c b/src/utils.c index 0756fde9..46f4d259 100644 --- a/src/utils.c +++ b/src/utils.c @@ -755,20 +755,37 @@ accdir (const char *directory, enum accd flags) return 1; } -/* Match the end of STRING against PATTERN. For instance: +/* Return non-zero if STRING ends with TAIL. For instance: + + match_tail ("abc", "bc", 0) -> 1 + match_tail ("abc", "ab", 0) -> 0 + match_tail ("abc", "abc", 0) -> 1 + + If FOLD_CASE_P is non-zero, the comparison will be + case-insensitive. */ - match_backwards ("abc", "bc") -> 1 - match_backwards ("abc", "ab") -> 0 - match_backwards ("abc", "abc") -> 1 */ int -match_tail (const char *string, const char *pattern) +match_tail (const char *string, const char *tail, int fold_case_p) { int i, j; - for (i = strlen (string), j = strlen (pattern); i >= 0 && j >= 0; i--, j--) - if (string[i] != pattern[j]) - break; - /* If the pattern was exhausted, the match was succesful. */ + /* We want this to be fast, so we code two loops, one with + case-folding, one without. */ + + if (!fold_case_p) + { + for (i = strlen (string), j = strlen (tail); i >= 0 && j >= 0; i--, j--) + if (string[i] != tail[j]) + break; + } + else + { + for (i = strlen (string), j = strlen (tail); i >= 0 && j >= 0; i--, j--) + if (TOLOWER (string[i]) != TOLOWER (tail[j])) + break; + } + + /* If the tail was exhausted, the match was succesful. */ if (j == -1) return 1; else @@ -797,7 +814,7 @@ in_acclist (const char *const *accepts, const char *s, int backward) { if (backward) { - if (match_tail (s, *accepts)) + if (match_tail (s, *accepts, 0)) return 1; } else diff --git a/src/utils.h b/src/utils.h index ff139f73..7a8e223d 100644 --- a/src/utils.h +++ b/src/utils.h @@ -69,7 +69,7 @@ char *file_merge PARAMS ((const char *, const char *)); int acceptable PARAMS ((const char *)); int accdir PARAMS ((const char *s, enum accd)); char *suffix PARAMS ((const char *s)); -int match_tail PARAMS ((const char *, const char *)); +int match_tail PARAMS ((const char *, const char *, int)); int has_html_suffix_p PARAMS ((const char *));