]> sjero.net Git - wget/blobdiff - src/retr.c
[svn] Include <netdb.h> where h_errno is used. Likewise for <errno.h> and errno.
[wget] / src / retr.c
index 30f4556f9ea1add5e78bffcb38a5334eccbe29e8..3334ced804e4b0a030d861c856ec821abacc6c7b 100644 (file)
@@ -44,6 +44,10 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
 #include "connect.h"
 #include "hash.h"
 
+#ifndef errno
+extern int errno;
+#endif
+
 #ifdef WINDOWS
 LARGE_INTEGER internal_time;
 #else
@@ -118,7 +122,15 @@ get_contents (int fd, FILE *fp, long *len, long restval, long expected,
       int amount_to_read = (use_expected
                            ? MIN (expected - *len, sizeof (c))
                            : sizeof (c));
-      res = iread (fd, c, amount_to_read);
+#ifdef HAVE_SSL
+               if (rbuf->ssl!=NULL) {
+                 res = ssl_iread (rbuf->ssl, c, amount_to_read);
+               } else {
+#endif /* HAVE_SSL */
+                 res = iread (fd, c, amount_to_read);
+#ifdef HAVE_SSL
+               }
+#endif /* HAVE_SSL */
       if (res > 0)
        {
          if (fwrite (c, sizeof (char), res, fp) < res)
@@ -322,7 +334,7 @@ rate (long bytes, long msecs)
                        && no_proxy_match((u)->host,                    \
                                          (const char **)opt.no_proxy))
 
-/* Retrieve the given URL.  Decides which loop to call -- HTTP, FTP,
+/* Retrieve the given URL.  Decides which loop to call -- HTTP(S), FTP,
    or simply copy it with file:// (#### the latter not yet
    implemented!).  */
 uerr_t
@@ -355,7 +367,7 @@ retrieve_url (const char *origurl, char **file, char **newloc,
       freeurl (u, 1);
       if (redirections)
        string_set_free (redirections);
-      free (url);
+      xfree (url);
       return result;
     }
 
@@ -392,7 +404,7 @@ retrieve_url (const char *origurl, char **file, char **newloc,
          freeurl (u, 1);
          if (redirections)
            string_set_free (redirections);
-         free (url);
+         xfree (url);
          return PROXERR;
        }
       /* Parse the proxy URL.  */
@@ -406,7 +418,7 @@ retrieve_url (const char *origurl, char **file, char **newloc,
          freeurl (u, 1);
          if (redirections)
            string_set_free (redirections);
-         free (url);
+         xfree (url);
          return PROXERR;
        }
       u->proto = URLHTTP;
@@ -415,7 +427,11 @@ retrieve_url (const char *origurl, char **file, char **newloc,
   assert (u->proto != URLFILE);        /* #### Implement me!  */
   mynewloc = NULL;
 
+#ifdef HAVE_SSL
+  if (u->proto == URLHTTP || u->proto == URLHTTPS )
+#else
   if (u->proto == URLHTTP)
+#endif /* HAVE_SSL */
     result = http_loop (u, &mynewloc, dt);
   else if (u->proto == URLFTP)
     {
@@ -456,7 +472,7 @@ retrieve_url (const char *origurl, char **file, char **newloc,
         there break the rules and use relative URLs, and popular
         browsers are lenient about this, so wget should be too. */
       construced_newloc = url_concat (url, mynewloc);
-      free (mynewloc);
+      xfree (mynewloc);
       mynewloc = construced_newloc;
 
       /* Now, see if this new location makes sense. */
@@ -469,15 +485,15 @@ retrieve_url (const char *origurl, char **file, char **newloc,
          freeurl (u, 1);
          if (redirections)
            string_set_free (redirections);
-         free (url);
-         free (mynewloc);
+         xfree (url);
+         xfree (mynewloc);
          return result;
        }
 
       /* Now mynewloc will become newloc_struct->url, because if the
          Location contained relative paths like .././something, we
          don't want that propagating as url.  */
-      free (mynewloc);
+      xfree (mynewloc);
       mynewloc = xstrdup (newloc_struct->url);
 
       if (!redirections)
@@ -498,13 +514,13 @@ retrieve_url (const char *origurl, char **file, char **newloc,
          freeurl (u, 1);
          if (redirections)
            string_set_free (redirections);
-         free (url);
-         free (mynewloc);
+         xfree (url);
+         xfree (mynewloc);
          return WRONGCODE;
        }
       string_set_add (redirections, newloc_struct->url);
 
-      free (url);
+      xfree (url);
       url = mynewloc;
       freeurl (u, 1);
       u = newloc_struct;
@@ -525,7 +541,7 @@ retrieve_url (const char *origurl, char **file, char **newloc,
   if (newloc)
     *newloc = url;
   else
-    free (url);
+    xfree (url);
 
   return result;
 }
@@ -622,3 +638,34 @@ downloaded_exceeds_quota (void)
 
   return opt.downloaded > opt.quota;
 }
+
+/* If opt.wait or opt.waitretry are specified, and if certain
+   conditions are met, sleep the appropriate number of seconds.  See
+   the documentation of --wait and --waitretry for more information.
+
+   COUNT is the count of current retrieval, beginning with 1. */
+
+void
+sleep_between_retrievals (int count)
+{
+  static int first_retrieval = 1;
+
+  if (!first_retrieval && (opt.wait || opt.waitretry))
+    {
+      if (opt.waitretry && count > 1)
+       {
+         /* If opt.waitretry is specified and this is a retry, wait
+            for COUNT-1 number of seconds, or for opt.waitretry
+            seconds.  */
+         if (count <= opt.waitretry)
+           sleep (count - 1);
+         else
+           sleep (opt.waitretry);
+       }
+      else if (opt.wait)
+       /* Otherwise, check if opt.wait is specified.  If so, sleep.  */
+       sleep (opt.wait);
+    }
+  if (first_retrieval)
+    first_retrieval = 0;
+}