[RFE][PATCH] Allow cd smb://, cd sh://, cd mc:// vfs requests



Hi,

since we can access ftp filesystems either like cd /#ftp: or more
intuitively like cd ftp:// it's not a bad idea IMNSHO to add such
extensions also for other filesystems. The attached patch implements
such an extension and it makes vfs_translate_url() more comprehensive in
the way that the aliases are kept in a separate table. strip_password()
is modified to take the change in account.

Cheers,
Jindrich

-- 
Jindrich Novy <jnovy redhat com>, http://people.redhat.com/jnovy/
ChangeLog:

	* vfs.c (vfs_translate_url): Add support for smb://, sh:// and mc://
	filesystem requests. Introduced separate table for vfs aliases.
	* util.c (strip_password): Modifications to take the aliases into
	account while eliminating passwords.

--- mc-4.6.1a-20050202/vfs/vfs.c.vfs-url	2004-11-16 17:16:08.000000000 +0100
+++ mc-4.6.1a-20050202/vfs/vfs.c	2005-02-07 13:03:06.660269240 +0100
@@ -981,15 +981,28 @@ vfs_fill_names (fill_names_f func)
  * Returns vfs path corresponding to given url. If passed string is
  * not recognized as url, g_strdup(url) is returned.
  */
+
+static const struct {
+    const char *name;
+    size_t name_len;
+    const char *substitute;
+} url_table[] = { {"ftp://";, 6, "/#ftp:"},
+                  {"mc://", 5, "/#mc:"},
+                  {"smb://", 6, "/#smb:"},
+                  {"sh://", 5, "/#sh:"},
+                  {"a:", 2, "/#a"}
+};
+
 char *
 vfs_translate_url (const char *url)
 {
-    if (strncmp (url, "ftp://";, 6) == 0)
-	return g_strconcat ("/#ftp:", url + 6, (char *) NULL);
-    else if (strncmp (url, "a:", 2) == 0)
-	return g_strdup ("/#a");
-    else
-	return g_strdup (url);
+    int i;
+
+    for (i = 0; i < sizeof (url_table)/sizeof (url_table[0]); i++)
+       if (!strncmp (url, url_table[i].name, url_table[i].name_len))
+           return g_strconcat (url_table[i].substitute, url + url_table[i].name_len, (char*)NULL);
+
+    return g_strdup (url);
 }
 
 int vfs_file_is_local (const char *filename)
--- mc-4.6.1a-20050202/src/util.c.vfs-url	2004-12-02 21:08:06.000000000 +0100
+++ mc-4.6.1a-20050202/src/util.c	2005-02-07 13:19:53.830156144 +0100
@@ -432,10 +432,13 @@ strip_password (char *p, int has_prefix)
 	const char *name;
         size_t len;
     } prefixes[] = { {"/#ftp:", 6},
-		     {"/#mc:", 5},
 		     {"ftp://";, 6},
+		     {"/#mc:", 5},
+		     {"mc://", 5},
 		     {"/#smb:", 6},
-		     {"/#sh:", 5}
+		     {"smb://", 6},
+		     {"/#sh:", 5},
+		     {"sh://", 5}
     };
     char *at, *inner_colon, *dir;
     size_t i;


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