changeset 60:8a9324fb63a4

2002-11-21 Brian Masney <masneyb@gftp.org> * lib/protocols.c (gftp_get_next_line) - fixed several bugs * lib/cache.c - Don't do a cache lookup in gftp_new_cache_entry(). In gftp_find_cache_entry(), don't log an error to the user if we can't open up the cache file * lib/rfc959.c lib/rfc2068.c lib/protocols.c - small cache fixes * lib/cache.c lib/rfc2068.c lib/rfc959.c - pass full buffer size instead of buffer size - 1 to gftp_get_line
author masneyb
date Fri, 22 Nov 2002 00:54:38 +0000
parents 618423504fe0
children 42df9e4be8e0
files ChangeLog lib/cache.c lib/protocols.c lib/rfc2068.c lib/rfc959.c
diffstat 5 files changed, 36 insertions(+), 51 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Thu Nov 21 02:49:06 2002 +0000
+++ b/ChangeLog	Fri Nov 22 00:54:38 2002 +0000
@@ -1,3 +1,15 @@
+2002-11-21 Brian Masney <masneyb@gftp.org>
+	* lib/protocols.c (gftp_get_next_line) - fixed several bugs 
+
+	* lib/cache.c - Don't do a cache lookup in gftp_new_cache_entry(). In 
+	gftp_find_cache_entry(), don't log an error to the user if we can't
+	open up the cache file
+
+	* lib/rfc959.c lib/rfc2068.c lib/protocols.c - small cache fixes
+
+	* lib/cache.c lib/rfc2068.c lib/rfc959.c - pass full buffer size 
+	instead of buffer size - 1 to gftp_get_line
+
 2002-11-20 Brian Masney <masneyb@gftp.org>
 	* lib/config_file.c - don't check buf[-1] for blank newlines in 
 	gftp_read_config_file() and gftp_read_bookmarks_file() 
@@ -252,7 +264,7 @@
 
 	* cvsclean - added this script
 
-	* *.[ch] - added $Id: ChangeLog,v 1.34 2002/11/21 02:49:05 masneyb Exp $ tags
+	* *.[ch] - added $Id: ChangeLog,v 1.35 2002/11/22 00:54:37 masneyb Exp $ tags
 
 	* debian/* - updated files from Debian maintainer
 
--- a/lib/cache.c	Thu Nov 21 02:49:06 2002 +0000
+++ b/lib/cache.c	Fri Nov 22 00:54:38 2002 +0000
@@ -38,9 +38,6 @@
   int cache_fd, fd;
   ssize_t ret;
 
-  if ((fd = gftp_find_cache_entry (request)) > 0)
-    return (fd);
-
   cachedir = expand_path (BASE_CONF_DIR "/cache");
   if (access (cachedir, F_OK) == -1)
     {
@@ -127,24 +124,15 @@
   indexfile = expand_path (BASE_CONF_DIR "/cache/index.db");
   if ((indexfd = open (indexfile, O_RDONLY)) == -1)
     {
-      if (request != NULL)
-        request->logging_function (gftp_logging_error, request->user_data,
-                                   _("Error: Cannot open local file %s: %s\n"),
-                                   indexfile, g_strerror (errno));
-
       g_free (indexfile);
       return (-1);
     }
   g_free (indexfile);
 
   rbuf = NULL;
-  while (gftp_get_line (NULL, &rbuf, buf, sizeof (buf) - 1, indexfd) > 0)
+  while (gftp_get_line (NULL, &rbuf, buf, sizeof (buf), indexfd) > 0)
     {
       len = strlen (buf);
-      if (buf[len - 1] == '\n')
-        buf[--len] = '\0';
-      if (buf[len - 1] == '\r')
-        buf[--len] = '\0';
 
       if (!((pos = strrchr (buf, '\t')) != NULL && *(pos + 1) != '\0'))
 	continue;
@@ -216,13 +204,9 @@
     }
 
   rbuf = NULL;
-  while (gftp_get_line (NULL, &rbuf, buf, sizeof (buf) - 1, indexfd) > 0)
+  while (gftp_get_line (NULL, &rbuf, buf, sizeof (buf), indexfd) > 0)
     {
       len = strlen (buf);
-      if (buf[len - 1] == '\n')
-        buf[--len] = '\0';
-      if (buf[len - 1] == '\r')
-        buf[--len] = '\0';
 
       if (!((pos = strrchr (buf, '\t')) != NULL && *(pos + 1) != '\0'))
 	continue;
@@ -279,13 +263,9 @@
 
   rbuf = NULL;
   buflen = strlen (description);
-  while (gftp_get_line (NULL, &rbuf, buf, sizeof (buf) - 1, indexfd) > 0)
+  while (gftp_get_line (NULL, &rbuf, buf, sizeof (buf), indexfd) > 0)
     {
       len = strlen (buf);
-      if (buf[len - 1] == '\n')
-        buf[--len] = '\0';
-      if (buf[len - 1] == '\r')
-        buf[--len] = '\0';
 
       if (!((pos = strrchr (buf, '\t')) != NULL && *(pos + 1) != '\0'))
         {
--- a/lib/protocols.c	Thu Nov 21 02:49:06 2002 +0000
+++ b/lib/protocols.c	Fri Nov 22 00:54:38 2002 +0000
@@ -343,15 +343,17 @@
         }
 #endif
 
-      if (ret >= 0 && !request->cached && request->cachefd > 0&& 
+      if (ret >= 0 && !request->cached && request->cachefd > 0 && 
           request->last_dir_entry != NULL)
         {
-          if (gftp_writefmt (request, request->cachefd, "%s\n",
-                             request->last_dir_entry) < 0)
+          if (gftp_write (request, request->last_dir_entry,
+                          request->last_dir_entry_len, request->cachefd) < 0)
             {
               request->logging_function (gftp_logging_error, request->user_data,
                                         _("Error: Cannot write to cache: %s\n"),
                                         g_strerror (errno));
+              close (request->cachefd);
+              request->cachefd = -1;
             }
         }
     } while (ret > 0 && !gftp_match_filespec (fle->file, filespec));
@@ -1883,13 +1885,14 @@
     {
       *rbuf = g_malloc0 (sizeof (**rbuf));
       (*rbuf)->max_bufsize = len;
-      (*rbuf)->buffer = g_malloc ((*rbuf)->max_bufsize);
+      (*rbuf)->buffer = g_malloc ((*rbuf)->max_bufsize + 1);
       if ((ret = gftp_read (request, (*rbuf)->buffer, (*rbuf)->max_bufsize, 
                             fd)) <= 0)
         {
           gftp_free_getline_buffer (rbuf);
           return (ret);
         }
+      (*rbuf)->buffer[ret] = '\0';
       (*rbuf)->cur_bufsize = ret;
       (*rbuf)->curpos = (*rbuf)->buffer;
     }
@@ -1909,20 +1912,12 @@
               if (pos > (*rbuf)->curpos && *(pos - 1) == '\r')
                 pos--;
               *pos = '\0';
-
-              if (len > pos - (*rbuf)->curpos + 1)
-                len = pos - (*rbuf)->curpos + 1;
             }
           else
-            {
-              nextpos = NULL;
-              if (len > (*rbuf)->cur_bufsize)
-                len = (*rbuf)->cur_bufsize;
-            }
+            nextpos = NULL;
 
           strncpy (str, (*rbuf)->curpos, len);
-          str[len] = '\0';
-          retval = len;
+          retval = pos - (*rbuf)->curpos > len ? len : pos - (*rbuf)->curpos;
 
           if (pos != NULL)
             {
@@ -1956,6 +1951,7 @@
               gftp_free_getline_buffer (rbuf);
               return (ret);
             }
+          (*rbuf)->buffer[ret + copysize] = '\0';
           (*rbuf)->cur_bufsize = ret + copysize;
         }
     }
--- a/lib/rfc2068.c	Thu Nov 21 02:49:06 2002 +0000
+++ b/lib/rfc2068.c	Fri Nov 22 00:54:38 2002 +0000
@@ -87,7 +87,7 @@
   params->max_bytes = 0;
 
   rbuf = NULL;
-  if (gftp_get_line (request, &rbuf, tempstr, sizeof (tempstr) - 1, 
+  if (gftp_get_line (request, &rbuf, tempstr, sizeof (tempstr), 
                      request->sockfd) < 0)
     return (-1);
 
@@ -103,7 +103,7 @@
   while (1) 
     {
       /* Read rest of proxy header */
-      if (gftp_get_line (request, &rbuf, tempstr, sizeof (tempstr) - 1, 
+      if (gftp_get_line (request, &rbuf, tempstr, sizeof (tempstr), 
                          request->sockfd) < 0)
 	return (-1);
 
@@ -669,7 +669,7 @@
   rbuf = NULL;
   while (1)
     {
-      if (gftp_get_line (request, &rbuf, tempstr, sizeof (tempstr) - 1, fd) < 0)
+      if (gftp_get_line (request, &rbuf, tempstr, sizeof (tempstr), fd) < 0)
         return (-2);
 
       tempstr[sizeof (tempstr) - 1] = '\0';
@@ -678,7 +678,7 @@
       if (params->chunked_transfer && strcmp (tempstr, "0\r\n") == 0)
         {
           while ((len = gftp_get_line (request, &rbuf, tempstr, 
-                                       sizeof (tempstr) - 1, fd)) > 0)
+                                       sizeof (tempstr), fd)) > 0)
             {
               if (strcmp (tempstr, "\r\n") == 0)
                 break;
@@ -709,9 +709,8 @@
   len = strlen (tempstr);
   if (!request->cached)
     {
-      request->last_dir_entry = g_malloc (len + 1);
-      strcpy (request->last_dir_entry, tempstr);
-      request->last_dir_entry_len = len;
+      request->last_dir_entry = g_strdup_printf ("%s\n", tempstr);
+      request->last_dir_entry_len = len + 1;
     }
   return (len);
 }
--- a/lib/rfc959.c	Thu Nov 21 02:49:06 2002 +0000
+++ b/lib/rfc959.c	Fri Nov 22 00:54:38 2002 +0000
@@ -50,8 +50,7 @@
   do
     {
       if ((num_read = gftp_get_line (request, &parms->sockfd_rbuf, tempstr, 
-                                     sizeof (tempstr) - 1, 
-                                     request->sockfd)) <= 0)
+                                     sizeof (tempstr), request->sockfd)) <= 0)
 	break;
 
       if (isdigit ((int) *tempstr) && isdigit ((int) *(tempstr + 1))
@@ -895,7 +894,7 @@
   do
     {
       if ((len = gftp_get_line (request, &parms->datafd_rbuf,
-                                tempstr, sizeof (tempstr) - 1, fd)) <= 0)
+                                tempstr, sizeof (tempstr), fd)) <= 0)
 	{
           gftp_file_destroy (fle);
 	  return ((int) len);
@@ -919,9 +918,8 @@
   len = strlen (tempstr);
   if (!request->cached)
     {
-      request->last_dir_entry = g_malloc (len + 1);
-      strcpy (request->last_dir_entry, tempstr);
-      request->last_dir_entry_len = len;
+      request->last_dir_entry = g_strdup_printf ("%s\n", tempstr);
+      request->last_dir_entry_len = len + 1;
     }
   return (len);
 }