changeset 204:9b2de8d3fafe

2003-6-25 Brian Masney <masneyb@gftp.org> * lib/misc.c (expand_path) - small improvements * lib/rfc2068.c src/text/gftp-gtk.c - fixes for path handling, namely when changing directories to the parent (..)
author masneyb
date Thu, 26 Jun 2003 02:14:24 +0000
parents 95e669973a84
children feac1903a018
files ChangeLog TODO lib/misc.c lib/rfc2068.c src/text/gftp-text.c
diffstat 5 files changed, 56 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Thu Jun 26 01:40:24 2003 +0000
+++ b/ChangeLog	Thu Jun 26 02:14:24 2003 +0000
@@ -1,3 +1,9 @@
+2003-6-25 Brian Masney <masneyb@gftp.org>
+	* lib/misc.c (expand_path) - small improvements
+
+	* lib/rfc2068.c src/text/gftp-gtk.c - fixes for path handling, namely
+	when changing directories to the parent (..)
+
 2003-6-25 Brian Masney <masneyb@gftp.org>
 	* lib/misc.c - fix warning if DMALLOC is disabled
 
@@ -1128,7 +1134,7 @@
 
 	* cvsclean - added this script
 
-	* *.[ch] - added $Id: ChangeLog,v 1.102 2003/06/26 01:40:23 masneyb Exp $ tags
+	* *.[ch] - added $Id: ChangeLog,v 1.103 2003/06/26 02:14:22 masneyb Exp $ tags
 
 	* debian/* - updated files from Debian maintainer
 
--- a/TODO	Thu Jun 26 01:40:24 2003 +0000
+++ b/TODO	Thu Jun 26 02:14:24 2003 +0000
@@ -6,7 +6,6 @@
 * Check for memory leaks with dmalloc
 * DND - be able to resume transfers
 * HTTP - keepalive
-* HTTP - chdir .. is busted
 * HTTP - I am getting complaints about HTTP proxy support is busted
 * Profile SSHV2 transfers, they seem really slow to me
 * Override options on a per site basis (backend is done, I just have to make
--- a/lib/misc.c	Thu Jun 26 01:40:24 2003 +0000
+++ b/lib/misc.c	Thu Jun 26 02:14:24 2003 +0000
@@ -149,10 +149,13 @@
       pos++;
       while (*pos == '/')
         pos++;
+
       if ((endpos = strchr (pos, '/')) == NULL)
 	endpos = pos + strlen (pos);
+
       tempchar = *endpos;
       *endpos = '\0';
+
       if (strcmp (pos, "..") == 0)
 	{
 	  *(pos - 1) = '\0';
@@ -170,18 +173,28 @@
 	      newstr = tempstr;
 	    }
 	}
+
       *endpos = tempchar;
       if (*endpos == '\0')
 	break;
+
       endpos = pos + 1;
     }
 
+  if (endpos != NULL && *endpos != '\0' && newstr == NULL)
+    {
+      if (strcmp (endpos, "..") == 0)
+        newstr = g_malloc0 (1);
+      else
+        newstr = g_strdup (endpos);
+    }
+
   if (newstr == NULL || *newstr == '\0')
     {
       if (newstr != NULL)
 	g_free (newstr);
-      newstr = g_malloc0 (2);
-      *newstr = '/';
+
+      newstr = g_malloc0 (1);
     }
 
   g_free (str);
--- a/lib/rfc2068.c	Thu Jun 26 01:40:24 2003 +0000
+++ b/lib/rfc2068.c	Thu Jun 26 02:14:24 2003 +0000
@@ -643,15 +643,27 @@
 static int
 rfc2068_chdir (gftp_request * request, const char *directory)
 {
+  char *tempstr, *olddir;
+
   g_return_val_if_fail (request != NULL, GFTP_EFATAL);
   g_return_val_if_fail (request->protonum == GFTP_HTTP_NUM, GFTP_EFATAL);
   g_return_val_if_fail (directory != NULL, GFTP_EFATAL);
 
   if (request->directory != directory)
     {
-      if (request->directory)
-        g_free (request->directory);
-      request->directory = g_strdup (directory);
+      olddir = request->directory;
+
+      if (*directory != '/')
+        {
+          tempstr = g_strconcat (request->directory, "/", directory, NULL);
+          request->directory = expand_path (tempstr);
+          g_free (tempstr);
+        }
+      else
+        request->directory = expand_path (directory);
+
+      if (olddir != NULL)
+        g_free (olddir);
     }
   return (0);
 }
--- a/src/text/gftp-text.c	Thu Jun 26 01:40:24 2003 +0000
+++ b/src/text/gftp-text.c	Thu Jun 26 02:14:24 2003 +0000
@@ -422,7 +422,7 @@
 int
 gftp_text_cd (gftp_request * request, char *command, gpointer *data)
 {
-  char *newdir = NULL;
+  char *tempstr, *newdir = NULL;
 
   if (!GFTP_IS_CONNECTED (request))
     {
@@ -436,6 +436,24 @@
                      _("usage: chdir <directory>\n"));
       return (1);
     }
+  else if (request->protonum == GFTP_LOCAL_NUM)
+    {
+      if (*command != '/')
+        {
+          tempstr = g_strconcat (request->directory, "/", command, NULL);
+          newdir = expand_path (tempstr);
+          g_free (tempstr);
+        }
+      else
+        newdir = expand_path (command);
+
+      if (newdir == NULL)
+        {
+          gftp_text_log (gftp_logging_error, request, 
+                         _("usage: chdir <directory>\n"));
+          return (1);
+        }
+    }
 
   gftp_set_directory (request, newdir != NULL ? newdir : command);