]> sjero.net Git - wget/commitdiff
[svn] Use new function to test filename for common html suffixes.
authorabbotti <devnull@localhost>
Fri, 12 Apr 2002 18:53:39 +0000 (11:53 -0700)
committerabbotti <devnull@localhost>
Fri, 12 Apr 2002 18:53:39 +0000 (11:53 -0700)
Submitted by Ian Abbott in <3CB72D29.4898.1F34872@localhost> with minor
changes to formatting and comments.

src/ChangeLog
src/http.c
src/recur.c
src/retr.c
src/utils.c
src/utils.h

index 00a440b1e346ef41032dd7888c2ad5a49f90c4f8..5fa69110f7c72cb4f4b9601e2ca341e86f66038a 100644 (file)
@@ -1,3 +1,16 @@
+2002-04-12  Ian Abbott  <abbotti@mev.co.uk>
+
+       * utils.c (has_html_suffix_p): New function to test filename for
+       common html extensions.
+
+       * utils.h: Declare it.
+
+       * http.c (http_loop): Use it instead of previous test.
+
+       * retr.c (retrieve_url): Ditto.
+
+       * recur.c (download_child_p): Ditto.
+
 2002-04-12  Hrvoje Niksic  <hniksic@arsdigita.com>
 
        * config.h.in: Define _VA_LIST on Solaris to prevent stdio.h from
index 6dacacab060c68d1b03101e4e5c3dae5bd6a0e6b..3e62856d86540e3d99e04dfeba6def956e77f4d3 100644 (file)
@@ -1405,7 +1405,7 @@ http_loop (struct url *u, char **newloc, char **local_file, const char *referer,
   int use_ts, got_head = 0;    /* time-stamping info */
   char *filename_plus_orig_suffix;
   char *local_filename = NULL;
-  char *tms, *suf, *locf, *tmrate;
+  char *tms, *locf, *tmrate;
   uerr_t err;
   time_t tml = -1, tmr = -1;   /* local and remote time-stamps */
   long local_size = 0;         /* the size of the local file */
@@ -1465,9 +1465,8 @@ File `%s' already there, will not retrieve.\n"), *hstat.local_file);
       *dt |= RETROKF;
 
       /* #### Bogusness alert.  */
-      /* If its suffix is "html" or "htm", assume text/html.  */
-      if (((suf = suffix (*hstat.local_file)) != NULL)
-         && (!strcmp (suf, "html") || !strcmp (suf, "htm")))
+      /* If its suffix is "html" or "htm" or similar, assume text/html.  */
+      if (has_html_suffix_p (*hstat.local_file))
        *dt |= TEXTHTML;
 
       FREE_MAYBE (dummy);
index a1fe72ae9bcfb568e737a1af0573afca3678604b..1d6a6988934886f4753c46e2bdc1f9f5cfe1a5b9 100644 (file)
@@ -510,7 +510,6 @@ download_child_p (const struct urlpos *upos, struct url *parent, int depth,
 
   /* 6. */
   {
-    char *suf;
     /* Check for acceptance/rejection rules.  We ignore these rules
        for HTML documents because they might lead to other files which
        need to be downloaded.  Of course, we don't know which
@@ -521,14 +520,13 @@ download_child_p (const struct urlpos *upos, struct url *parent, int depth,
        * u->file is not "" (i.e. it is not a directory)
        and either:
          + there is no file suffix,
-        + or there is a suffix, but is not "html" or "htm",
+        + or there is a suffix, but is not "html" or "htm" or similar,
         + both:
           - recursion is not infinite,
           - and we are at its very end. */
 
     if (u->file[0] != '\0'
-       && ((suf = suffix (url)) == NULL
-           || (0 != strcmp (suf, "html") && 0 != strcmp (suf, "htm"))
+       && (!has_html_suffix_p (url)
            || (opt.reclevel != INFINITE_RECURSION && depth >= opt.reclevel)))
       {
        if (!acceptable (u->file))
index 36eb3481885c14addd46d2a08bd9f8e33d3f3209..c35dde110483a482fae8bf8b673d3e2ab725cb66 100644 (file)
@@ -384,12 +384,11 @@ retrieve_url (const char *origurl, char **file, char **newloc,
 
       /* There is a possibility of having HTTP being redirected to
         FTP.  In these cases we must decide whether the text is HTML
-        according to the suffix.  The HTML suffixes are `.html' and
-        `.htm', case-insensitive.  */
+        according to the suffix.  The HTML suffixes are `.html',
+        `.htm' and a few others, case-insensitive.  */
       if (redirection_count && local_file && u->scheme == SCHEME_FTP)
        {
-         char *suf = suffix (local_file);
-         if (suf && (!strcasecmp (suf, "html") || !strcasecmp (suf, "htm")))
+         if (has_html_suffix_p (local_file))
            *dt |= TEXTHTML;
        }
     }
index 3f04edafbb8f70b153a6486518c56d0d66d3a586..ca8505acf0c7d9846dd8ae0e83618fc7db0b7a5e 100644 (file)
@@ -792,6 +792,31 @@ suffix (const char *str)
     return NULL;
 }
 
+/* Return non-zero if FNAME ends with a typical HTML suffix.  The
+   following (case-insensitive) suffixes are presumed to be HTML files:
+   
+     html
+     htm
+     ?html (`?' matches one character)
+
+   #### CAVEAT.  This is not necessarily a good indication that FNAME
+   refers to a file that contains HTML!  */
+int
+has_html_suffix_p (const char *fname)
+{
+  char *suf;
+
+  if ((suf = suffix (fname)) == NULL)
+    return 0;
+  if (!strcasecmp (suf, "html"))
+    return 1;
+  if (!strcasecmp (suf, "htm"))
+    return 1;
+  if (suf[0] && !strcasecmp (suf + 1, "html"))
+    return 1;
+  return 0;
+}
+
 /* Read a line from FP and return the pointer to freshly allocated
    storage.  The stoarage space is obtained through malloc() and
    should be freed with free() when it is no longer needed.
index 0cba30187311fc2b1659750700c84f12e15f5662..162ddd7042bc6b4eda97e8d13be0118d162f721b 100644 (file)
@@ -70,6 +70,8 @@ int accdir PARAMS ((const char *s, enum accd));
 char *suffix PARAMS ((const char *s));
 int match_tail PARAMS ((const char *, const char *));
 
+int has_html_suffix_p PARAMS ((const char *));
+
 char *read_whole_line PARAMS ((FILE *));
 struct file_memory *read_file PARAMS ((const char *));
 void read_file_free PARAMS ((struct file_memory *));