summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorVincent Torri <vincent.torri@gmail.com>2021-02-06 14:49:54 +0000
committerCarsten Haitzler (Rasterman) <raster@rasterman.com>2021-02-06 14:49:54 +0000
commitec4ef6911591b0ce47616438dfd34626d9302537 (patch)
treebed0d387b7a2346040cc0b3d73acf64c0f758839 /src/lib
parentd8d52861a619e7a6e1e7244ffb70a9a8b4819c07 (diff)
Efreet: fix file:// scheme on Windows
Summary: On Windows, file:///c:/path/to/file is correct and not managed. Use a Win API for manage it correctly Test Plan: test case Reviewers: raster, cedric Reviewed By: raster Subscribers: #reviewers, #committers Tags: #efl Differential Revision: https://phab.enlightenment.org/D12244
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/efreet/efreet_uri.c70
-rw-r--r--src/lib/efreet/meson.build5
2 files changed, 75 insertions, 0 deletions
diff --git a/src/lib/efreet/efreet_uri.c b/src/lib/efreet/efreet_uri.c
index 44fe54a35f..2b64556159 100644
--- a/src/lib/efreet/efreet_uri.c
+++ b/src/lib/efreet/efreet_uri.c
@@ -2,8 +2,15 @@
2# include <config.h> 2# include <config.h>
3#endif 3#endif
4 4
5#include <stdlib.h>
6#include <string.h>
5#include <ctype.h> 7#include <ctype.h>
6 8
9#ifdef _WIN32
10# include <windows.h>
11# include <shlwapi.h>
12#endif
13
7#ifndef _POSIX_HOST_NAME_MAX 14#ifndef _POSIX_HOST_NAME_MAX
8#define _POSIX_HOST_NAME_MAX 255 15#define _POSIX_HOST_NAME_MAX 255
9#endif 16#endif
@@ -28,6 +35,64 @@ efreet_uri_decode(const char *full_uri)
28 EINA_SAFETY_ON_NULL_RETURN_VAL(full_uri, NULL); 35 EINA_SAFETY_ON_NULL_RETURN_VAL(full_uri, NULL);
29 36
30 /* An uri should be in the form <scheme>:[<authority>][<path>][<query>][<fragment>] */ 37 /* An uri should be in the form <scheme>:[<authority>][<path>][<query>][<fragment>] */
38
39 /*
40 * Specific code for Windows when the scheme part of full_uri is 'file',
41 * for local Windows file path.
42 * see https://docs.microsoft.com/en-us/archive/blogs/ie/file-uris-in-windows
43 *
44 * Correct syntax :
45 * file:///c:/path/to/file
46 *
47 * The returned path must be c:\path\to\file
48 */
49#ifdef _WIN32
50
51 *scheme = 0;
52 *authority = 0;
53 *path = 0;
54
55 if (strncasecmp(full_uri, "file://", strlen("file://")) == 0)
56 {
57 HRESULT res;
58 DWORD len;
59# ifdef UNICODE
60 wchar_t buf[MAX_PATH];
61 wchar_t *w_full_uri;
62 char *uri;
63
64 w_full_uri = evil_utf8_to_utf16(full_uri);
65 if (!w_full_uri)
66 return NULL;
67
68 if (wcslen(w_full_uri) > 2048)
69 {
70 free(w_full_uri);
71 return NULL;
72 }
73
74 len = sizeof(buf);
75 res = PathCreateFromUrl(w_full_uri, buf, &len, 0UL);
76 free(w_full_uri);
77 if (res != S_OK)
78 return NULL;
79 uri = evil_utf16_to_utf8(buf);
80 if (uri)
81 {
82 strncpy(path, uri, sizeof(path));
83 path[sizeof(path)-1] = 0;
84 goto win32_file_scheme;
85 }
86#else
87 len = sizeof(path);
88 res = PathCreateFromUrl(full_uri, path, &len, 0UL);
89 if (res == S_OK)
90 goto win32_file_scheme;
91#endif
92 return NULL;
93 }
94#endif
95
31 sep = strchr(full_uri, ':'); 96 sep = strchr(full_uri, ':');
32 if (!sep) return NULL; 97 if (!sep) return NULL;
33 /* check if we have a Windows PATH, that is a letter follow by a colon */ 98 /* check if we have a Windows PATH, that is a letter follow by a colon */
@@ -77,6 +142,11 @@ efreet_uri_decode(const char *full_uri)
77 path[i] = *p; 142 path[i] = *p;
78 } 143 }
79 144
145#ifdef _WIN32
146 win32_file_scheme:
147 strcpy(scheme, "file");
148#endif
149
80 uri = NEW(Efreet_Uri, 1); 150 uri = NEW(Efreet_Uri, 1);
81 if (!uri) return NULL; 151 if (!uri) return NULL;
82 152
diff --git a/src/lib/efreet/meson.build b/src/lib/efreet/meson.build
index 41d3113566..1d02f3db1f 100644
--- a/src/lib/efreet/meson.build
+++ b/src/lib/efreet/meson.build
@@ -36,6 +36,11 @@ efreet_ext_deps = [buildsystem_simple, intl, m]
36 36
37package_c_args += ['-DDATA_DIR="'+dir_data+'"'] 37package_c_args += ['-DDATA_DIR="'+dir_data+'"']
38 38
39if sys_windows
40 shlwapi = cc.find_library('shlwapi')
41 efreet_ext_deps += [shlwapi]
42endif
43
39efreet_lib = library('efreet', 44efreet_lib = library('efreet',
40 efreet_src, 45 efreet_src,
41 dependencies: efreet_pub_deps + efreet_ext_deps + efreet_deps, 46 dependencies: efreet_pub_deps + efreet_ext_deps + efreet_deps,