]> git.sesse.net Git - vlc/commitdiff
make_URI: handle Windows UNC paths
authorRémi Denis-Courmont <remi@remlab.net>
Sun, 12 Jul 2009 17:04:06 +0000 (20:04 +0300)
committerRémi Denis-Courmont <remi@remlab.net>
Sun, 12 Jul 2009 17:10:20 +0000 (20:10 +0300)
src/test/url.c
src/text/strings.c

index 875c9a5f7b37a588f8fbba482e712428abe679b7..64060b5c2eb6b80fe2e4958f9806588918fb39c7 100644 (file)
@@ -117,7 +117,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);*/
index 1b42933d43c5f5dfa41f6ce3541c307645696473..c2ab87bddaee9b94a5e7d43db244093e7daeb7ba 100644 (file)
@@ -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];