[vlc-devel] commit: make_URI: handle Windows UNC paths ( Rémi Denis-Courmont )

git version control git at videolan.org
Sun Jul 12 19:11:05 CEST 2009


vlc | branch: 1.0-bugfix | Rémi Denis-Courmont <remi at remlab.net> | Sun Jul 12 20:04:06 2009 +0300| [3bb3090a0c8e704d1bfa58d0bbd2dd81d6e0cb6b] | committer: Rémi Denis-Courmont 

make_URI: handle Windows UNC paths
(cherry picked from commit 644185a5fe78fff280bbb35deb2f4e4ab51ad143)

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=3bb3090a0c8e704d1bfa58d0bbd2dd81d6e0cb6b
---

 src/test/url.c     |    3 ++-
 src/text/strings.c |   34 ++++++++++++++++++++++++++++------
 2 files changed, 30 insertions(+), 7 deletions(-)

diff --git a/src/test/url.c b/src/test/url.c
index d03e48c..f68a001 100644
--- a/src/test/url.c
+++ b/src/test/url.c
@@ -108,7 +108,8 @@ int main (void)
     test_path ("/", "file:///");
     test_path ("/home/john/", "file:///home/john/");
     test_path ("/home/john/music.ogg", "file:///home/john/music.ogg");
-    //test_path ("\\\\server/pub/music.ogg", "file://server/pub/music.ogg");
+    test_path ("\\\\server/pub/music.ogg", "smb://server/pub/music.ogg");
+    test_path ("\\\\server\\pub\\music.ogg", "smb://server/pub/music.ogg");
 
     /*int fd = open (".", O_RDONLY);
     assert (fd != -1);*/
diff --git a/src/text/strings.c b/src/text/strings.c
index e61d699..283b9b6 100644
--- a/src/text/strings.c
+++ b/src/text/strings.c
@@ -1079,15 +1079,37 @@ char *make_URI (const char *path)
     }
     else
 #endif
-#if 0
-    /* Windows UNC paths (file://host/share/path instead of file:///path) */
     if (!strncmp (path, "\\\\", 2))
-    {
-        path += 2;
-        buf = strdup ("file://");
+    {   /* Windows UNC paths */
+#ifndef WIN32
+        /* \\host\share\path -> smb://host/share/path */
+        if (strchr (path + 2, '\\') != NULL)
+        {   /* Convert antislashes to slashes */
+            char *dup = strdup (path);
+            if (dup == NULL)
+                return NULL;
+            for (size_t i = 2; dup[i]; i++)
+                if (dup[i] == '\\')
+                    dup[i] = DIR_SEP_CHAR;
+
+            char *ret = make_URI (dup);
+            free (dup);
+            return ret;
+        }
+# define SMB_SCHEME "smb"
+#else
+        /* \\host\share\path -> file://host/share/path */
+# define SMB_SCHEME "file"
+#endif
+        size_t hostlen = strcspn (path + 2, DIR_SEP);
+
+        buf = malloc (sizeof (SMB_SCHEME) + 3 + hostlen);
+        if (buf != NULL)
+            snprintf (buf, sizeof (SMB_SCHEME) + 3 + hostlen,
+                      SMB_SCHEME"://%s", path + 2);
+        path += 2 + hostlen;
     }
     else
-#endif
     if (path[0] != DIR_SEP_CHAR)
     {   /* Relative path: prepend the current working directory */
         char cwd[PATH_MAX];




More information about the vlc-devel mailing list