]> sjero.net Git - wget/commitdiff
[svn] Allow match_tail to be case insensitive.
authorhniksic <devnull@localhost>
Wed, 8 May 2002 18:24:40 +0000 (11:24 -0700)
committerhniksic <devnull@localhost>
Wed, 8 May 2002 18:24:40 +0000 (11:24 -0700)
Published in <sxsznzabirr.fsf@florida.munich.redhat.com>.

src/ChangeLog
src/cookies.c
src/ftp.c
src/utils.c
src/utils.h

index addafe0c4545cbaa18e46c58f1f50590eeff547a..14a0e99e16caa2fe2a97290c43ce4a16c4360add 100644 (file)
@@ -1,3 +1,14 @@
+2002-05-08  Hrvoje Niksic  <hniksic@arsdigita.com>
+
+       * 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  <abbotti@mev.co.uk>
 
        * cookies.c (cookie_jar_process_set_cookie): Do not store
index 7df96f7c9cde86d1f441313b170c519bfa538cd2..3de9c32327e11ee30497c9b8dcab5d7fa80133bd 100644 (file)
@@ -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)) : "<indefinitely>",
+          ? asctime (localtime (&cookie->expiry_time)) : "<undefined>",
           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;
index 45685329586a13d7e78c3d27547db9a9ca61db5b..ebddf3a06fbfaaf9d8890fbd459452b2ea209bcc 100644 (file)
--- 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)
index 0756fde98bc18b5501d0a0fee63566ce166e65cd..46f4d2593e01d10553570762cd0f5e7ebd950331 100644 (file)
@@ -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
index ff139f7328cfdd8e4355815a54de4ea4bdd36c3e..7a8e223dc5ee1d8438a147512cb3d96de938498f 100644 (file)
@@ -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 *));