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
This commit is contained in:
Kai Huuhko 2014-05-19 15:48:41 +09:00 committed by Carsten Haitzler (Rasterman)
parent f691b71284
commit 78c9a82a14
2 changed files with 33 additions and 24 deletions

View File

@ -624,14 +624,7 @@ efreet_desktop_command_file_process(Efreet_Desktop_Command *command, const char
f->command = command; f->command = command;
/* handle uris */ /* handle uris */
if ((!strncmp(file, "http", 4) && (!strncmp(file + 4, "://", 3) || !strncmp(file + 4, "s://", 4))) || !strncmp(file, "ftp://", 6)) if (!strncmp(file, "file:", 5))
{
uri = file;
base = ecore_file_file_get(file);
nonlocal = 1;
}
else if (!strncmp(file, "file:", 5))
{ {
file = efreet_desktop_command_file_uri_process(file); file = efreet_desktop_command_file_uri_process(file);
if (!file) if (!file)
@ -640,6 +633,13 @@ efreet_desktop_command_file_process(Efreet_Desktop_Command *command, const char
return NULL; return NULL;
} }
} }
else if (strstr(file, ":"))
{
uri = file;
base = ecore_file_file_get(file);
nonlocal = 1;
}
if (nonlocal) if (nonlocal)
{ {

View File

@ -18,40 +18,49 @@
#include "Efreet.h" #include "Efreet.h"
#include "efreet_private.h" #include "efreet_private.h"
/* The URI standard is at http://tools.ietf.org/html/std66 */
EAPI Efreet_Uri * EAPI Efreet_Uri *
efreet_uri_decode(const char *full_uri) efreet_uri_decode(const char *full_uri)
{ {
Efreet_Uri *uri; Efreet_Uri *uri;
const char *p; const char *p;
char protocol[64], hostname[_POSIX_HOST_NAME_MAX], path[PATH_MAX]; char scheme[64], authority[_POSIX_HOST_NAME_MAX], path[PATH_MAX];
int i = 0; int i = 0;
EINA_SAFETY_ON_NULL_RETURN_VAL(full_uri, NULL); EINA_SAFETY_ON_NULL_RETURN_VAL(full_uri, NULL);
/* An uri should be in the form <protocol>://<hostname>/<path> */ /* An uri should be in the form <scheme>:[<authority>][<path>][<query>][<fragment>] */
if (!strstr(full_uri, "://")) return NULL; if (!strstr(full_uri, ":")) return NULL;
memset(protocol, 0, 64);
memset(hostname, 0, _POSIX_HOST_NAME_MAX); memset(scheme, 0, 64);
memset(authority, 0, _POSIX_HOST_NAME_MAX);
memset(path, 0, PATH_MAX); memset(path, 0, PATH_MAX);
/* parse protocol */ /* parse scheme */
p = full_uri; p = full_uri;
for (i = 0; *p != ':' && *p != '\0' && i < (64 - 1); p++, i++) for (i = 0; *p != ':' && *p != '\0' && i < (64 - 1); p++, i++)
protocol[i] = *p; scheme[i] = *p;
protocol[i] = '\0'; if (i == 0) return NULL; /* scheme is required */
scheme[i] = '\0';
/* parse hostname */ /* parse authority */
p += 3; p++;
if (*p != '/') if (*p != '/')
{ {
for (i = 0; *p != '/' && *p != '\0' && i < (_POSIX_HOST_NAME_MAX - 1); p++, i++) p++;
hostname[i] = *p; if (*p != '/')
hostname[i] = '\0'; {
for (i = 0; *p != '/' && *p != '?' && *p != '#' && *p != '\0' && i < (_POSIX_HOST_NAME_MAX - 1); p++, i++)
authority[i] = *p;
authority[i] = '\0';
}
else /* It's a path, let path parser handle the leading slash */
p--;
} }
else else
hostname[0] = '\0'; authority[0] = '\0';
/* parse path */ /* parse path */
/* See http://www.faqs.org/rfcs/rfc1738.html for the escaped chars */ /* See http://www.faqs.org/rfcs/rfc1738.html for the escaped chars */
@ -71,8 +80,8 @@ efreet_uri_decode(const char *full_uri)
uri = NEW(Efreet_Uri, 1); uri = NEW(Efreet_Uri, 1);
if (!uri) return NULL; if (!uri) return NULL;
uri->protocol = eina_stringshare_add(protocol); uri->protocol = eina_stringshare_add(scheme);
uri->hostname = eina_stringshare_add(hostname); uri->hostname = eina_stringshare_add(authority);
uri->path = eina_stringshare_add(path); uri->path = eina_stringshare_add(path);
return uri; return uri;