]> sjero.net Git - wget/blobdiff - src/url.c
[svn] Fix retrieval of directories when initial CWD is not `/'.
[wget] / src / url.c
index 20130e3099362df999724db9470dd39d2bc31768..cca3ac96568a1d919a58aaafdd73a898f8179412 100644 (file)
--- a/src/url.c
+++ b/src/url.c
@@ -26,7 +26,6 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
 #else
 # include <strings.h>
 #endif
-#include <ctype.h>
 #include <sys/types.h>
 #ifdef HAVE_UNISTD_H
 # include <unistd.h>
@@ -43,11 +42,6 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
 extern int errno;
 #endif
 
-/* Default port definitions */
-#define DEFAULT_HTTP_PORT 80
-#define DEFAULT_FTP_PORT 21
-#define DEFAULT_HTTPS_PORT 443
-
 /* Table of Unsafe chars.  This is intialized in
    init_unsafe_char_table.  */
 
@@ -339,13 +333,13 @@ int
 skip_uname (const char *url)
 {
   const char *p;
-  for (p = url; *p && *p != '/'; p++)
-    if (*p == '@')
-      break;
+  const char *q = NULL;
+  for (p = url ; *p && *p != '/'; p++)
+    if (*p == '@') q = p;
   /* If a `@' was found before the first occurrence of `/', skip
      it.  */
-  if (*p == '@')
-    return p - url + 1;
+  if (q != NULL)
+    return q - url + 1;
   else
     return 0;
 }
@@ -497,6 +491,7 @@ parseurl (const char *url, struct urlinfo *u, int strict)
       /* #### We don't handle type `d' correctly yet.  */
       if (!u->ftp_type || TOUPPER (u->ftp_type) == 'D')
        u->ftp_type = 'I';
+      DEBUGP (("ftp_type %c -> ", u->ftp_type));
     }
   DEBUGP (("opath %s -> ", u->path));
   /* Parse the username and password (if existing).  */
@@ -519,7 +514,7 @@ parseurl (const char *url, struct urlinfo *u, int strict)
   DEBUGP (("ndir %s\n", u->dir));
   /* Strip trailing `/'.  */
   l = strlen (u->dir);
-  if (l && u->dir[l - 1] == '/')
+  if (l > 1 && u->dir[l - 1] == '/')
     u->dir[l - 1] = '\0';
   /* Re-create the path: */
   abs_ftp = (u->proto == URLFTP && *u->dir == '/');
@@ -607,7 +602,7 @@ static uerr_t
 parse_uname (const char *url, char **user, char **passwd)
 {
   int l;
-  const char *p, *col;
+  const char *p, *q, *col;
   char **where;
 
   *user = NULL;
@@ -627,7 +622,7 @@ parse_uname (const char *url, char **user, char **passwd)
   if (*p != '@')
     return URLOK;
   /* Else find the username and password.  */
-  for (p = col = url; *p != '@'; p++)
+  for (p = q = col = url; *p && *p != '/'; p++)
     {
       if (*p == ':' && !*user)
        {
@@ -636,12 +631,13 @@ parse_uname (const char *url, char **user, char **passwd)
          (*user)[p - url] = '\0';
          col = p + 1;
        }
+      if (*p == '@') q = p;
     }
   /* Decide whether you have only the username or both.  */
   where = *user ? passwd : user;
-  *where = (char *)xmalloc (p - col + 1);
-  memcpy (*where, col, p - col);
-  (*where)[p - col] = '\0';
+  *where = (char *)xmalloc (q - col + 1);
+  memcpy (*where, col, q - col);
+  (*where)[q - col] = '\0';
   return URLOK;
 }
 
@@ -661,10 +657,11 @@ process_ftp_type (char *path)
     return '\0';
 }
 \f
-/* Return the URL as fine-formed string, with a proper protocol,
-   optional port number, directory and optional user/password.  If
-   HIDE is non-zero, password will be hidden.  The forbidden
-   characters in the URL will be cleansed.  */
+/* Return the URL as fine-formed string, with a proper protocol, optional port
+   number, directory and optional user/password.  If `hide' is non-zero (as it
+   is when we're calling this on a URL we plan to print, but not when calling it
+   to canonicalize a URL for use within the program), password will be hidden.
+   The forbidden characters in the URL will be cleansed.  */
 char *
 str_url (const struct urlinfo *u, int hide)
 {
@@ -688,11 +685,14 @@ str_url (const struct urlinfo *u, int hide)
     user = CLEANDUP (u->user);
   if (u->passwd)
     {
-      int j;
-      passwd = CLEANDUP (u->passwd);
       if (hide)
-       for (j = 0; passwd[j]; j++)
-         passwd[j] = 'x';
+       /* Don't output the password, or someone might see it over the user's
+          shoulder (or in saved wget output).  Don't give away the number of
+          characters in the password, either, as we did in past versions of
+          this code, when we replaced the password characters with 'x's. */
+       passwd = xstrdup("<password>");
+      else
+       passwd = CLEANDUP (u->passwd);
     }
   if (u->proto == URLFTP && *dir == '/')
     {
@@ -1561,6 +1561,7 @@ write_backup_file (const char *file, downloaded_file_t downloaded_file_return)
         thought I could just add a field to the urlpos structure saying
         that we'd written a .orig file for this URL, but that didn't work,
         so I had to make this separate list.
+        -- Dan Harkless <wget@harkless.org>
 
          This [adding a field to the urlpos structure] didn't work
          because convert_file() is called twice: once after all its
@@ -1569,10 +1570,11 @@ write_backup_file (const char *file, downloaded_file_t downloaded_file_return)
          original linked list collected in recursive_retrieve() is
          lost after the first invocation of convert_links(), and
          convert_all_links() makes a new one (it calls get_urls_html()
-         for each file it covers.)  That's why your approach didn't
+         for each file it covers.)  That's why your first approach didn't
          work.  The way to make it work is perhaps to make this flag a
-         field in the `urls_html' list.  */
-
+         field in the `urls_html' list.
+        -- Hrvoje Niksic <hniksic@arsdigita.com>
+      */
       converted_file_ptr = xmalloc(sizeof(*converted_file_ptr));
       converted_file_ptr->string = xstrdup(file);  /* die on out-of-mem. */
       converted_file_ptr->next = converted_files;