changeset 105:ae13b18c9336

2003-2-9 Brian Masney <masneyb@gftp.org> * lib/protocols.c (parse_time) - parse more time formats. Better error checking. If there was an error parsing this time, skip ahead to the next token * lib/rfc2068.c - this was completely broken. This was broken whenever I did the conversion over to use the gftp_get_line() function. * lib/rfc959.c - use g_strdup instead of g_malloc/strcpy
author masneyb
date Sun, 09 Feb 2003 20:05:35 +0000
parents 31a004f868f7
children d70ba687cb8e
files ChangeLog lib/protocols.c lib/rfc2068.c lib/rfc959.c
diffstat 4 files changed, 81 insertions(+), 62 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Fri Feb 07 22:02:51 2003 +0000
+++ b/ChangeLog	Sun Feb 09 20:05:35 2003 +0000
@@ -1,3 +1,13 @@
+2003-2-9 Brian Masney <masneyb@gftp.org>
+	* lib/protocols.c (parse_time) - parse more time formats. Better
+	error checking. If there was an error parsing this time,
+	skip ahead to the next token
+
+	* lib/rfc2068.c - this was completely broken. This was broken whenever
+	I did the conversion over to use the gftp_get_line() function. 
+
+	* lib/rfc959.c - use g_strdup instead of g_malloc/strcpy
+
 2003-2-6 Brian Masney <masneyb@gftp.org>
 	* lib/gftp.h lib/protocols.c lib/rfc2068.c - put in new 
 	parse_time() function that should work across all locales.
@@ -480,7 +490,7 @@
 
 	* cvsclean - added this script
 
-	* *.[ch] - added $Id: ChangeLog,v 1.57 2003/02/07 01:24:12 masneyb Exp $ tags
+	* *.[ch] - added $Id: ChangeLog,v 1.58 2003/02/09 20:05:35 masneyb Exp $ tags
 
 	* debian/* - updated files from Debian maintainer
 
--- a/lib/protocols.c	Fri Feb 07 22:02:51 2003 +0000
+++ b/lib/protocols.c	Sun Feb 09 20:05:35 2003 +0000
@@ -1028,18 +1028,23 @@
 parse_time (char *str, char **endpos)
 {
   struct tm curtime, *loctime;
+  time_t t, ret;
   char *tmppos;
-  time_t t;
 
   memset (&curtime, 0, sizeof (curtime));
   curtime.tm_isdst = -1;
-  if (isdigit ((int) str[0]) && str[2] == '-')
+  if (strlen (str) > 4 && isdigit ((int) str[0]) && str[2] == '-' && isdigit ((int) str[3]))
     {
       /* This is how DOS will return the date/time */
       /* 07-06-99  12:57PM */
 
       tmppos = strptime (str, "%m-%d-%y %I:%M%p", &curtime);
     }
+  else if (strlen (str) > 4 && isdigit ((int) str[0]) && str[2] == '-' && isalpha (str[3]))
+    {
+      /* 10-Jan-2003 09:14 */
+      tmppos = strptime (str, "%d-%h-%Y %H:%M", &curtime);
+    }
   else
     {
       /* This is how most UNIX, Novell, and MacOS ftp servers send their time */
@@ -1056,8 +1061,23 @@
         tmppos = strptime (str, "%h %d %Y", &curtime);
     }
 
+  if (tmppos != NULL)
+    ret = mktime (&curtime);
+  else
+    ret = 0;
+
   if (endpos != NULL)
-    *endpos = tmppos;
+    {
+      if (tmppos == NULL)
+        {
+          /* We cannot parse this date format. So, just skip this date field and continue to the next
+             token. This is mainly for the HTTP support */
+
+          for (*endpos = str; **endpos != ' ' && **endpos != '\t' && **endpos != '\0'; *endpos++);
+        }
+      else
+        *endpos = tmppos;
+    }
 
   return (mktime (&curtime));
 }
--- a/lib/rfc2068.c	Fri Feb 07 22:02:51 2003 +0000
+++ b/lib/rfc2068.c	Sun Feb 09 20:05:35 2003 +0000
@@ -22,6 +22,7 @@
 
 typedef struct rfc2068_params_tag
 {
+  gftp_getline_buffer * rbuf;
   unsigned long read_bytes,
                 max_bytes;
   int chunked_transfer : 1;
@@ -79,46 +80,42 @@
 static off_t 
 rfc2068_read_response (gftp_request * request)
 {
-  gftp_getline_buffer * rbuf;
   rfc2068_params * params;
   char tempstr[255];
   int ret;
 
   params = request->protocol_data;
+  params->chunked_transfer = 0;
+  params->rbuf = NULL;
+  *tempstr = '\0';
   params->max_bytes = 0;
-
-  rbuf = NULL;
-  if ((ret = gftp_get_line (request, &rbuf, tempstr, sizeof (tempstr), 
-                            request->sockfd)) < 0)
-    return (ret);
+  if (request->last_ftp_response)
+    {
+      g_free (request->last_ftp_response); 
+      request->last_ftp_response = NULL;
+    }
 
-  if (request->last_ftp_response)
-    g_free (request->last_ftp_response);
-  request->last_ftp_response = g_malloc (strlen (tempstr) + 1);
-  strcpy (request->last_ftp_response, tempstr);
-
-  request->logging_function (gftp_logging_recv, request->user_data, "%s",
-                             tempstr);
+  do
+    {
+      if ((ret = gftp_get_line (request, &params->rbuf, tempstr, sizeof (tempstr), 
+                                request->sockfd)) < 0)
+        return (ret);
 
-  params->chunked_transfer = 0;
-  while (1) 
-    {
-      /* Read rest of proxy header */
-      if ((ret = gftp_get_line (request, &rbuf, tempstr, sizeof (tempstr), 
-                                request->sockfd)) < 0)
-	return (ret);
+      if (request->last_ftp_response == NULL)
+        request->last_ftp_response = g_strdup (tempstr);
+
+      if (*tempstr != '\0')
+        {
+          request->logging_function (gftp_logging_recv, request->user_data, "%s\n",
+                                     tempstr);
 
-      if (*tempstr == '\r' || *tempstr == '\n')
-        break;
-
-      request->logging_function (gftp_logging_recv, request->user_data, "%s",
-                                 tempstr);
-
-      if (strncmp (tempstr, "Content-Length:", 15) == 0)
-	params->max_bytes = strtol (tempstr + 16, NULL, 10);
-      if (strncmp (tempstr, "Transfer-Encoding: chunked", 26) == 0)
-        params->chunked_transfer = 1;
+          if (strncmp (tempstr, "Content-Length:", 15) == 0)
+            params->max_bytes = strtol (tempstr + 16, NULL, 10);
+          if (strcmp (tempstr, "Transfer-Encoding: chunked") == 0)
+            params->chunked_transfer = 1;
+        }
     }
+  while (*tempstr != '\0');
 
   return (params->max_bytes);
 }
@@ -224,10 +221,7 @@
     }
 
   if (!request->directory)
-    {
-      request->directory = g_malloc (2);
-      strcpy (request->directory, "/");
-    }
+    request->directory = g_strdup ("/");
 
   return (0);
 }
@@ -498,8 +492,7 @@
 
   /* Copy file attributes. Just about the only thing we can get is whether it
      is a directory or not */
-  fle->attribs = g_malloc (11);
-  strcpy (fle->attribs, "----------");
+  fle->attribs = g_strdup ("----------");
   if (*(pos - 1) == '/')
     {
       *(pos - 1) = '\0';
@@ -512,8 +505,7 @@
       *stpos == '\0' || *stpos == '?')
     return (0);
 
-  fle->file = g_malloc (strlen (stpos) + 1);
-  strcpy (fle->file, stpos);
+  fle->file = g_strdup (stpos);
 
   if (*(pos - 1) == '\0')
     *(pos - 1) = '/';
@@ -528,7 +520,7 @@
 
   pos += 4;
 
-  while (*pos == ' ' || *pos == '.' || *pos == '<')
+  while (*pos == ' ' || *pos == '\t' || *pos == '.' || *pos == '<')
     {
       if (*pos == '<')
 	{
@@ -556,6 +548,9 @@
 
   fle->datetime = parse_time (pos, &pos);
 
+  if (pos == NULL)
+    return (1);
+
   while (*pos == ' ' || *pos == ']')
     pos++;
 
@@ -594,7 +589,6 @@
 static int
 rfc2068_get_next_file (gftp_request * request, gftp_file * fle, int fd)
 {
-  gftp_getline_buffer * rbuf;
   rfc2068_params * params;
   char tempstr[255];
   size_t len;
@@ -611,22 +605,23 @@
       request->last_dir_entry = NULL;
     }
 
-  rbuf = NULL;
+  if (fd < 0)
+    fd = request->sockfd;
+
   while (1)
     {
-      if ((ret = gftp_get_line (request, &rbuf, tempstr, sizeof (tempstr), 
+      if ((ret = gftp_get_line (request, &params->rbuf, tempstr, sizeof (tempstr), 
                                 fd)) < 0)
         return (ret);
 
-      tempstr[sizeof (tempstr) - 1] = '\0';
       params->read_bytes += strlen (tempstr);
 
-      if (params->chunked_transfer && strcmp (tempstr, "0\r\n") == 0)
+      if (params->chunked_transfer && strcmp (tempstr, "0") == 0)
         {
-          while ((len = gftp_get_line (request, &rbuf, tempstr, 
+          while ((len = gftp_get_line (request, &params->rbuf, tempstr, 
                                        sizeof (tempstr), fd)) > 0)
             {
-              if (strcmp (tempstr, "\r\n") == 0)
+              if (*tempstr == '\0')
                 break;
             }
 	  gftp_file_destroy (fle);
@@ -649,7 +644,7 @@
   if (fle->file == NULL)
     {
       gftp_file_destroy (fle);
-      return (GFTP_ERETRYABLE); /* FIXME is this correct? */
+      return (0);
     }
 
   len = strlen (tempstr);
@@ -673,8 +668,7 @@
     {
       if (request->directory)
         g_free (request->directory);
-      request->directory = g_malloc (strlen (directory) + 1);
-      strcpy (request->directory, directory);
+      request->directory = g_strdup (directory);
     }
   return (0);
 }
@@ -690,10 +684,7 @@
 
 
   if (request->proxy_config == NULL)
-    {
-      request->proxy_config = g_malloc (5);
-      strcpy (request->proxy_config, "http");
-    }
+    request->proxy_config = g_strdup ("http");
 }
 
 
@@ -745,7 +736,7 @@
   request->need_userpass = 0;
   request->use_cache = 1;
   request->use_threads = 1;
-  request->always_connected = 0;
+  request->always_connected = 1;
   request->protocol_data = g_malloc0 (sizeof (rfc2068_params));
   gftp_set_config_options (request);
 }
--- a/lib/rfc959.c	Fri Feb 07 22:02:51 2003 +0000
+++ b/lib/rfc959.c	Sun Feb 09 20:05:35 2003 +0000
@@ -67,8 +67,7 @@
   if (num_read < 0)
     return ((int) num_read);
 
-  request->last_ftp_response = g_malloc (strlen (tempstr) + 1);
-  strcpy (request->last_ftp_response, tempstr);
+  request->last_ftp_response = g_strdup (tempstr);
 
   if (request->last_ftp_response[0] == '4' &&
       request->last_ftp_response[1] == '2')
@@ -254,8 +253,7 @@
   if (request->directory)
     g_free (request->directory);
 
-  request->directory = g_malloc (strlen (dir) + 1);
-  strcpy (request->directory, dir);
+  request->directory = g_strdup (dir);
   return (0);
 }