[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[gftp] Re: Changing Novell servers with CWD //server



Here is a patch for expand_path() to lib/misc.c so that it won't strip off
the double slashes. Please let me know if it fixes your problem.

Brian



On Sun, Nov 02, 2003 at 10:15:18PM +0100, Michal Schmidt wrote:
> Brian Masney wrote:
> > Hi,
> >    The version of gftp at http://www.gftp.org/gftp-test.tar.bz2 should fix
> > this problem for you. I have removed all of the code that strips out the
> > double slashes.
> > 
> > Brian
> 
> Hi,
>    Thank you for trying to resolve this problem. Unfortunately it still
> doesn't work. When I type "//dzin" into the chdir combobox, gFTP sends
> "CWD /dzin".
>    Now I've added several printf()s into the source to find out, where
> the double slashes get removed. I've found this:
> In ./src/gtk/menu-items.c:chdir_edit: edttxt=//dzin
> In ./lib/misc.c:expand_path: src=//dzin
> In ./lib/misc.c:expand_path: newstr=/dzin
> In ./src/gtk/menu-items.c:chdir_edit: tempstr=/dzin
> 
> So the function expand_path removes the slash. I am now trying to
> understand, what exactly this function is supposed to do. I may then be
> able to fix it myself.
> 
> Michal Schmidt
Index: misc.c
===================================================================
RCS file: /cvs/gnome/gftp/lib/misc.c,v
retrieving revision 1.50
diff -u -r1.50 misc.c
--- misc.c	3 Nov 2003 02:11:17 -0000	1.50
+++ misc.c	4 Nov 2003 19:21:12 -0000
@@ -151,7 +151,8 @@
 char *
 expand_path (const char *src)
 {
-  char *str, *pos, *endpos, *prevpos, *newstr, *tempstr, tempchar;
+  char *str, *pos, *endpos, *prevpos, *newstr, *tempstr, *ntoken,
+       tempchar;
   struct passwd *pw;
 
   pw = NULL;
@@ -178,22 +179,28 @@
   while ((pos = strchr (endpos, '/')) != NULL)
     {
       pos++;
-      while (*pos == '/')
-        pos++;
 
-      if ((endpos = strchr (pos, '/')) == NULL)
+      for (ntoken = pos; *ntoken == '/'; ntoken++);
+
+      if ((endpos = strchr (ntoken, '/')) == NULL)
 	endpos = pos + strlen (pos);
 
       tempchar = *endpos;
       *endpos = '\0';
 
-      if (strcmp (pos, "..") == 0)
+      if (strcmp (ntoken, "..") == 0)
 	{
-	  *(pos - 1) = '\0';
 	  if (newstr != NULL && (prevpos = strrchr (newstr, '/')) != NULL)
-	    *prevpos = '\0';
+            {
+	      *prevpos = '\0';
+              if (*newstr == '\0')
+                {
+                  g_free (newstr);
+                  newstr = NULL;
+                }
+            }
 	}
-      else if (strcmp (pos, ".") != 0)
+      else if (strcmp (ntoken, ".") != 0)
 	{
 	  if (newstr == NULL)
 	    newstr = g_strdup (pos - 1);
@@ -215,7 +222,7 @@
   if (endpos != NULL && *endpos != '\0' && newstr == NULL)
     {
       if (strcmp (endpos, "..") == 0)
-        newstr = g_malloc0 (1);
+        newstr = g_strdup ("/");
       else
         newstr = g_strdup (endpos);
     }
@@ -359,6 +366,10 @@
   int i;
 
   printf ("%s\n", gftp_version);
+
+#ifdef _REENTRANT
+  printf ("#define _REENTRANT\n");
+#endif
 
 #ifdef _GNU_SOURCE
   printf ("#define _GNU_SOURCE\n");