summaryrefslogtreecommitdiff
path: root/src/lib/efreet
diff options
context:
space:
mode:
authorKai Huuhko <kai.huuhko@gmail.com>2014-05-19 15:48:41 +0900
committerCarsten Haitzler (Rasterman) <raster@rasterman.com>2014-05-19 15:48:41 +0900
commit78c9a82a142f619ccd0957957351fe0e573de76c (patch)
tree3eeb6a01f46cb0ecc08e01e225dfcbe02384be74 /src/lib/efreet
parentf691b712841bc64e6267cd70cf28782c743bb916 (diff)
efreet: Handle URIs in a more generic way
Summary: Fixes T1219 Reviewers: englebass CC: cedric Maniphest Tasks: T1219 Differential Revision: https://phab.enlightenment.org/D865
Diffstat (limited to 'src/lib/efreet')
-rw-r--r--src/lib/efreet/efreet_desktop_command.c16
-rw-r--r--src/lib/efreet/efreet_uri.c41
2 files changed, 33 insertions, 24 deletions
diff --git a/src/lib/efreet/efreet_desktop_command.c b/src/lib/efreet/efreet_desktop_command.c
index df313a81d7..1e4c51d740 100644
--- a/src/lib/efreet/efreet_desktop_command.c
+++ b/src/lib/efreet/efreet_desktop_command.c
@@ -624,14 +624,7 @@ efreet_desktop_command_file_process(Efreet_Desktop_Command *command, const char
624 f->command = command; 624 f->command = command;
625 625
626 /* handle uris */ 626 /* handle uris */
627 if ((!strncmp(file, "http", 4) && (!strncmp(file + 4, "://", 3) || !strncmp(file + 4, "s://", 4))) || !strncmp(file, "ftp://", 6)) 627 if (!strncmp(file, "file:", 5))
628 {
629 uri = file;
630 base = ecore_file_file_get(file);
631
632 nonlocal = 1;
633 }
634 else if (!strncmp(file, "file:", 5))
635 { 628 {
636 file = efreet_desktop_command_file_uri_process(file); 629 file = efreet_desktop_command_file_uri_process(file);
637 if (!file) 630 if (!file)
@@ -640,6 +633,13 @@ efreet_desktop_command_file_process(Efreet_Desktop_Command *command, const char
640 return NULL; 633 return NULL;
641 } 634 }
642 } 635 }
636 else if (strstr(file, ":"))
637 {
638 uri = file;
639 base = ecore_file_file_get(file);
640
641 nonlocal = 1;
642 }
643 643
644 if (nonlocal) 644 if (nonlocal)
645 { 645 {
diff --git a/src/lib/efreet/efreet_uri.c b/src/lib/efreet/efreet_uri.c
index 236f7e519c..54e1d6fad0 100644
--- a/src/lib/efreet/efreet_uri.c
+++ b/src/lib/efreet/efreet_uri.c
@@ -18,40 +18,49 @@
18#include "Efreet.h" 18#include "Efreet.h"
19#include "efreet_private.h" 19#include "efreet_private.h"
20 20
21/* The URI standard is at http://tools.ietf.org/html/std66 */
21 22
22EAPI Efreet_Uri * 23EAPI Efreet_Uri *
23efreet_uri_decode(const char *full_uri) 24efreet_uri_decode(const char *full_uri)
24{ 25{
25 Efreet_Uri *uri; 26 Efreet_Uri *uri;
26 const char *p; 27 const char *p;
27 char protocol[64], hostname[_POSIX_HOST_NAME_MAX], path[PATH_MAX]; 28 char scheme[64], authority[_POSIX_HOST_NAME_MAX], path[PATH_MAX];
28 int i = 0; 29 int i = 0;
29 30
30 EINA_SAFETY_ON_NULL_RETURN_VAL(full_uri, NULL); 31 EINA_SAFETY_ON_NULL_RETURN_VAL(full_uri, NULL);
31 32
32 /* An uri should be in the form <protocol>://<hostname>/<path> */ 33 /* An uri should be in the form <scheme>:[<authority>][<path>][<query>][<fragment>] */
33 if (!strstr(full_uri, "://")) return NULL; 34 if (!strstr(full_uri, ":")) return NULL;
34 35
35 memset(protocol, 0, 64); 36
36 memset(hostname, 0, _POSIX_HOST_NAME_MAX); 37 memset(scheme, 0, 64);
38 memset(authority, 0, _POSIX_HOST_NAME_MAX);
37 memset(path, 0, PATH_MAX); 39 memset(path, 0, PATH_MAX);
38 40
39 /* parse protocol */ 41 /* parse scheme */
40 p = full_uri; 42 p = full_uri;
41 for (i = 0; *p != ':' && *p != '\0' && i < (64 - 1); p++, i++) 43 for (i = 0; *p != ':' && *p != '\0' && i < (64 - 1); p++, i++)
42 protocol[i] = *p; 44 scheme[i] = *p;
43 protocol[i] = '\0'; 45 if (i == 0) return NULL; /* scheme is required */
46 scheme[i] = '\0';
44 47
45 /* parse hostname */ 48 /* parse authority */
46 p += 3; 49 p++;
47 if (*p != '/') 50 if (*p != '/')
48 { 51 {
49 for (i = 0; *p != '/' && *p != '\0' && i < (_POSIX_HOST_NAME_MAX - 1); p++, i++) 52 p++;
50 hostname[i] = *p; 53 if (*p != '/')
51 hostname[i] = '\0'; 54 {
55 for (i = 0; *p != '/' && *p != '?' && *p != '#' && *p != '\0' && i < (_POSIX_HOST_NAME_MAX - 1); p++, i++)
56 authority[i] = *p;
57 authority[i] = '\0';
58 }
59 else /* It's a path, let path parser handle the leading slash */
60 p--;
52 } 61 }
53 else 62 else
54 hostname[0] = '\0'; 63 authority[0] = '\0';
55 64
56 /* parse path */ 65 /* parse path */
57 /* See http://www.faqs.org/rfcs/rfc1738.html for the escaped chars */ 66 /* See http://www.faqs.org/rfcs/rfc1738.html for the escaped chars */
@@ -71,8 +80,8 @@ efreet_uri_decode(const char *full_uri)
71 uri = NEW(Efreet_Uri, 1); 80 uri = NEW(Efreet_Uri, 1);
72 if (!uri) return NULL; 81 if (!uri) return NULL;
73 82
74 uri->protocol = eina_stringshare_add(protocol); 83 uri->protocol = eina_stringshare_add(scheme);
75 uri->hostname = eina_stringshare_add(hostname); 84 uri->hostname = eina_stringshare_add(authority);
76 uri->path = eina_stringshare_add(path); 85 uri->path = eina_stringshare_add(path);
77 86
78 return uri; 87 return uri;