From 78c9a82a142f619ccd0957957351fe0e573de76c Mon Sep 17 00:00:00 2001 From: Kai Huuhko Date: Mon, 19 May 2014 15:48:41 +0900 Subject: [PATCH] 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 --- src/lib/efreet/efreet_desktop_command.c | 16 +++++----- src/lib/efreet/efreet_uri.c | 41 +++++++++++++++---------- 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 f->command = command; /* handle uris */ - if ((!strncmp(file, "http", 4) && (!strncmp(file + 4, "://", 3) || !strncmp(file + 4, "s://", 4))) || !strncmp(file, "ftp://", 6)) - { - uri = file; - base = ecore_file_file_get(file); - - nonlocal = 1; - } - else if (!strncmp(file, "file:", 5)) + if (!strncmp(file, "file:", 5)) { file = efreet_desktop_command_file_uri_process(file); if (!file) @@ -640,6 +633,13 @@ efreet_desktop_command_file_process(Efreet_Desktop_Command *command, const char return NULL; } } + else if (strstr(file, ":")) + { + uri = file; + base = ecore_file_file_get(file); + + nonlocal = 1; + } if (nonlocal) { 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 @@ #include "Efreet.h" #include "efreet_private.h" +/* The URI standard is at http://tools.ietf.org/html/std66 */ EAPI Efreet_Uri * efreet_uri_decode(const char *full_uri) { Efreet_Uri *uri; 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; EINA_SAFETY_ON_NULL_RETURN_VAL(full_uri, NULL); - /* An uri should be in the form :/// */ - if (!strstr(full_uri, "://")) return NULL; + /* An uri should be in the form :[][][][] */ + 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); - /* parse protocol */ + /* parse scheme */ p = full_uri; for (i = 0; *p != ':' && *p != '\0' && i < (64 - 1); p++, i++) - protocol[i] = *p; - protocol[i] = '\0'; + scheme[i] = *p; + if (i == 0) return NULL; /* scheme is required */ + scheme[i] = '\0'; - /* parse hostname */ - p += 3; + /* parse authority */ + p++; if (*p != '/') { - for (i = 0; *p != '/' && *p != '\0' && i < (_POSIX_HOST_NAME_MAX - 1); p++, i++) - hostname[i] = *p; - hostname[i] = '\0'; + p++; + if (*p != '/') + { + 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 - hostname[0] = '\0'; + authority[0] = '\0'; /* parse path */ /* 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); if (!uri) return NULL; - uri->protocol = eina_stringshare_add(protocol); - uri->hostname = eina_stringshare_add(hostname); + uri->protocol = eina_stringshare_add(scheme); + uri->hostname = eina_stringshare_add(authority); uri->path = eina_stringshare_add(path); return uri;