]> sjero.net Git - wget/blobdiff - src/ftp-ls.c
[svn] Correct the conversion of month entries for NT and VMS.
[wget] / src / ftp-ls.c
index d40261e8fe7a54ffbf2966af350bab7e89693898..28fcf9c2913e197bb0f3c90dd3d9b2965b4040d4 100644 (file)
@@ -31,7 +31,6 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
 # include <unistd.h>
 #endif
 #include <sys/types.h>
-#include <ctype.h>
 #include <errno.h>
 
 #include "wget.h"
@@ -147,7 +146,7 @@ ftp_parse_unix_ls (const char *file, int ignore_perms)
          break;
        default:
          cur.type = FT_UNKNOWN;
-         DEBUGP (("UNKOWN; "));
+         DEBUGP (("UNKNOWN; "));
          break;
        }
 
@@ -156,15 +155,16 @@ ftp_parse_unix_ls (const char *file, int ignore_perms)
          switch (cur.type)
            {
            case FT_PLAINFILE:
-             cur.perms = 420;
+             cur.perms = 0644;
              break;
            case FT_DIRECTORY:
-             cur.perms = 493;
+             cur.perms = 0755;
              break;
            default:
-             cur.perms = 1023;
+             /*cur.perms = 1023;*/     /* #### What is this?  --hniksic */
+             cur.perms = 0644;
            }
-         DEBUGP (("implicite perms %0o; ", cur.perms));
+         DEBUGP (("implicit perms %0o; ", cur.perms));
        }
        else
          {
@@ -411,7 +411,7 @@ ftp_parse_winnt_ls (const char *file)
   FILE *fp;
   int len;
   int year, month, day;         /* for time analysis */
-  int hour, min, sec;
+  int hour, min;
   struct tm timestruct;
 
   char *line, *tok;             /* tokenizer */
@@ -441,9 +441,11 @@ ftp_parse_winnt_ls (const char *file)
       cur.name = xstrdup(tok);
       DEBUGP(("Name: '%s'\n", cur.name));
 
-      /* First column: mm-dd-yy */
+      /* First column: mm-dd-yy. Should atoi() on the month fail, january
+        will be assumed.  */
       tok = strtok(line, "-");
-      month = atoi(tok);
+      month = atoi(tok) - 1;
+      if (month < 0) month = 0;
       tok = strtok(NULL, "-");
       day = atoi(tok);
       tok = strtok(NULL, " ");
@@ -451,22 +453,23 @@ ftp_parse_winnt_ls (const char *file)
       /* Assuming the epoch starting at 1.1.1970 */
       if (year <= 70) year += 100;
 
-      /* Second column: hh:mm[AP]M */
+      /* Second column: hh:mm[AP]M, listing does not contain value for
+         seconds */
       tok = strtok(NULL,  ":");
       hour = atoi(tok);
       tok = strtok(NULL,  "M");
       min = atoi(tok);
-      /* Adjust hour from AM/PM */
+      /* Adjust hour from AM/PM. Just for the record, the sequence goes
+         11:00AM, 12:00PM, 01:00PM ... 11:00PM, 12:00AM, 01:00AM . */
       tok+=2;
+      if (hour == 12)  hour  = 0;
       if (*tok == 'P') hour += 12;
-      /* Listing does not contain value for seconds */
-      sec = 0;
 
       DEBUGP(("YYYY/MM/DD HH:MM - %d/%02d/%02d %02d:%02d\n", 
               year+1900, month, day, hour, min));
       
       /* Build the time-stamp (copy & paste from above) */
-      timestruct.tm_sec   = sec;
+      timestruct.tm_sec   = 0;
       timestruct.tm_min   = min;
       timestruct.tm_hour  = hour;
       timestruct.tm_mday  = day;
@@ -489,14 +492,14 @@ ftp_parse_winnt_ls (const char *file)
        {
          cur.type  = FT_DIRECTORY;
          cur.size  = 0;
-         cur.perms = 493; /* my gcc does not like 0755 ?? */
+         cur.perms = 0755;
          DEBUGP(("Directory\n"));
        }
       else
        {
          cur.type  = FT_PLAINFILE;
          cur.size  = atoi(tok);
-         cur.perms = 420; /* 0664 octal */
+         cur.perms = 0644;
          DEBUGP(("File, size %ld bytes\n", cur.size));
        }
 
@@ -563,7 +566,7 @@ ftp_parse_vms_ls (const char *file)
   int hour, min, sec;
   struct tm timestruct;
 
-  char *line, *tok, *p;          /* tokenizer */
+  char *line, *tok;             /* tokenizer */
   struct fileinfo *dir, *l, cur; /* list creation */
 
   fp = fopen (file, "rb");
@@ -584,6 +587,7 @@ ftp_parse_vms_ls (const char *file)
   /* Line loop to end of file: */
   while ((line = read_whole_line (fp)))
     {
+      char *p;
       i = clean_line (line);
       if (!i) break;
 
@@ -665,18 +669,22 @@ ftp_parse_vms_ls (const char *file)
       }
       for (i=0; i<12; i++) if (!strcmp(tok,months[i])) break;
       /* Uknown months are mapped to January */
-      month = (i%12)+1
-      tok = strtok(NULL, " ");
-      year = atoi(tok)-1900;
+      month = i % 12 
+      tok = strtok (NULL, " ");
+      year = atoi (tok) - 1900;
       DEBUGP(("date parsed\n"));
 
-      /* Fourth/Third column: Time hh:mm:ss */
-      tok = strtok(NULL,  ":");
-      hour = atoi(tok);
-      tok = strtok(NULL,  ":");
-      min = atoi(tok);
-      tok = strtok(NULL,  " ");
-      sec = atoi(tok);
+      /* Fourth/Third column: Time hh:mm[:ss] */
+      tok = strtok (NULL, " ");
+      hour = min = sec = 0;
+      p = tok;
+      hour = atoi (p);
+      for (; *p && *p != ':'; ++p);
+      if (*p)
+       min = atoi (++p);
+      for (; *p && *p != ':'; ++p);
+      if (*p)
+       sec = atoi (++p);
 
       DEBUGP(("YYYY/MM/DD HH:MM:SS - %d/%02d/%02d %02d:%02d:%02d\n", 
               year+1900, month, day, hour, min, sec));
@@ -809,8 +817,8 @@ ftp_index (const char *file, struct urlinfo *u, struct fileinfo *f)
     {
       char *tmpu, *tmpp;        /* temporary, clean user and passwd */
 
-      tmpu = CLEANDUP (u->user);
-      tmpp = u->passwd ? CLEANDUP (u->passwd) : NULL;
+      tmpu = encode_string (u->user);
+      tmpp = u->passwd ? encode_string (u->passwd) : NULL;
       upwd = (char *)xmalloc (strlen (tmpu)
                             + (tmpp ? (1 + strlen (tmpp)) : 0) + 2);
       sprintf (upwd, "%s%s%s@", tmpu, tmpp ? ":" : "", tmpp ? tmpp : "");