diff --git a/legacy/efreet/src/lib/Efreet.h b/legacy/efreet/src/lib/Efreet.h index 88d74384b3..db13044565 100644 --- a/legacy/efreet/src/lib/Efreet.h +++ b/legacy/efreet/src/lib/Efreet.h @@ -22,6 +22,7 @@ * @li Icon Theme Specification * @li Desktop Entry Specification * @li Desktop Menu Specification + * @li FDO URI Specification * @li Shared Mime Info Specification * @li Trash Specification */ @@ -57,6 +58,7 @@ extern "C" { #include "efreet_desktop.h" #include "efreet_menu.h" #include "efreet_utils.h" +#include "efreet_uri.h" EAPI int efreet_init(void); EAPI int efreet_shutdown(void); diff --git a/legacy/efreet/src/lib/Efreet_Trash.h b/legacy/efreet/src/lib/Efreet_Trash.h index 585144e1f5..febf70d6eb 100644 --- a/legacy/efreet/src/lib/Efreet_Trash.h +++ b/legacy/efreet/src/lib/Efreet_Trash.h @@ -2,15 +2,6 @@ #ifndef EFREET_TRASH_H #define EFREET_TRASH_H -/** - * @file Efreet_Trash.h - * @brief Contains the methods used to support the FDO trash specification. - * @addtogroup Efreet_Trash Efreet_Trash: The XDG Trash Specification - * Efreet_Trash.h provides all of the necessary headers and includes to - * work with Efreet_Trash. - * @{ - */ - #ifdef EAPI #undef EAPI #endif @@ -36,29 +27,14 @@ extern "C" { #endif - - /** - * Efreet_Uri + * @file Efreet_Trash.h + * @brief Contains the methods used to support the FDO trash specification. + * @addtogroup Efreet_Trash Efreet_Trash: The XDG Trash Specification + * Efreet_Trash.h provides all of the necessary headers and includes to + * work with Efreet_Trash. + * @{ */ -typedef struct Efreet_Uri Efreet_Uri; - -/** - * Efreet_Uri - * @brief Contains a simple rappresentation of an uri. The string don't have - * special chars escaped. - */ -struct Efreet_Uri -{ - const char *protocol; /**< The name of the host if any, or NULL */ - const char *hostname; /**< The name of the host if any, or NULL */ - const char *path; /**< The full file path whitout protocol nor host*/ -}; - - -EAPI const char *efreet_uri_escape(Efreet_Uri *uri); -EAPI Efreet_Uri *efreet_uri_parse(const char *val); -EAPI void efreet_uri_free(Efreet_Uri *uri); EAPI int efreet_trash_init(void); EAPI void efreet_trash_shutdown(void); @@ -68,8 +44,7 @@ EAPI int efreet_trash_delete_uri(Efreet_Uri *uri, int force_delete); EAPI Ecore_List *efreet_trash_ls(void); EAPI int efreet_trash_is_empty(void); EAPI int efreet_trash_empty_trash(void); - - + /** * @} */ diff --git a/legacy/efreet/src/lib/Makefile.am b/legacy/efreet/src/lib/Makefile.am index 1812e48823..c304b48865 100644 --- a/legacy/efreet/src/lib/Makefile.am +++ b/legacy/efreet/src/lib/Makefile.am @@ -15,7 +15,8 @@ efreet_desktop.h \ efreet_icon.h \ efreet_ini.h \ efreet_menu.h \ -efreet_utils.h +efreet_utils.h \ +efreet_uri.h EFREETSOURCES = \ efreet.c \ @@ -26,6 +27,7 @@ efreet_ini.c \ efreet_desktop.c \ efreet_menu.c \ efreet_utils.c \ +efreet_uri.c \ efreet_private.h \ efreet_xml.h \ $(EFREETHEADERS) diff --git a/legacy/efreet/src/lib/efreet_trash.c b/legacy/efreet/src/lib/efreet_trash.c index 305fffc127..c43cb0203a 100644 --- a/legacy/efreet/src/lib/efreet_trash.c +++ b/legacy/efreet/src/lib/efreet_trash.c @@ -108,8 +108,7 @@ efreet_trash_delete_uri(Efreet_Uri *uri, int force_delete) return 0; } } - - + /* create info file */ snprintf(dest, PATH_MAX, "%s/info/%s.trashinfo", efreet_trash_dir_get(), fname); @@ -119,7 +118,7 @@ efreet_trash_delete_uri(Efreet_Uri *uri, int force_delete) fputs("[Trash Info]\n", f); //TODO is '\n' right?? (or \r\c??) fputs("Path=", f); - escaped = efreet_uri_escape(uri); + escaped = efreet_uri_encode(uri); fputs(escaped + 7, f); // +7 == don't write 'file://' IF_RELEASE(escaped); @@ -198,115 +197,3 @@ efreet_trash_ls(void) return files; } - -/** - * @param val: a valid uri string to parse - * @return Return The corresponding Efreet_Uri structure. Or NULL on errors. - * @brief Parse a single uri and return an Efreet_Uri struct. If there's no - * hostname in the uri then the hostname parameter is NULL. All the uri escaped - * chars will be converted back. - */ -EAPI Efreet_Uri * -efreet_uri_parse(const char *val) -{ - Efreet_Uri *uri; - const char *p; - char protocol[64], hostname[_POSIX_HOST_NAME_MAX], path[PATH_MAX]; - int i = 0; - - /* An uri should be in the form :/// */ - p = strstr(val, "://"); - if (!p) return NULL; - - memset(protocol, 0, 64); - memset(hostname, 0, _POSIX_HOST_NAME_MAX); - memset(path, 0, PATH_MAX); - - /* parse protocol */ - p = val; - for (i = 0; *p != ':' && *p != '\0' && i < 64; p++, i++) - protocol[i] = *p; - protocol[i] = '\0'; - - /* parse hostname */ - p += 3; - if (*p != '/') - { - for (i = 0; *p != '/' && *p != '\0' && i < _POSIX_HOST_NAME_MAX; p++, i++) - hostname[i] = *p; - hostname[i] = '\0'; - } - else - hostname[0] = '\0'; - - /* parse path */ - /* See http://www.faqs.org/rfcs/rfc1738.html for the escaped chars */ - for (i = 0; *p != '\0' && i < PATH_MAX; i++, p++) - { - if (*p == '%') - { - path[i] = *(++p); - path[i + 1] = *(++p); - path[i] = (char)strtol(&(path[i]), NULL, 16); - path[i + 1] = '\0'; - } - else - path[i] = *p; - } - - uri = NEW(Efreet_Uri, 1); - if (!uri) return NULL; - - uri->protocol = ecore_string_instance(protocol); - uri->hostname = ecore_string_instance(hostname); - uri->path = ecore_string_instance(path); - - return uri; -} - -/** - * @param uri: The uri structure to escape - * @return The string rapresentation of an uri (ex: 'file:///home/my%20name') - * @brief Get the string rapresentation of the given uri struct escaping - * illegal caracters. The resulting string will contain the protocol but not the - * hostname, as many apps doesn't handle it. - */ -EAPI const char * -efreet_uri_escape(Efreet_Uri *uri) -{ - char dest[PATH_MAX * 3 + 4]; - const char *p; - int i; - - if (!uri || !uri->path || !uri->protocol) return NULL; - memset(dest, 0, PATH_MAX * 3 + 4); - snprintf(dest, strlen(uri->protocol) + 4, "%s://", uri->protocol); - - /* Most app doesn't handle the hostname in the uri so it's put to NULL */ - for (i = strlen(uri->protocol) + 3, p = uri->path; *p != '\0'; p++, i++) - { - if (isalnum(*p) || strchr("/$-_.+!*'()", *p)) - dest[i] = *p; - else - { - snprintf(&(dest[i]), 4, "%%%02X", *p); - i += 2; - } - } - - return ecore_string_instance(dest); -} - -/** - * @param uri: The uri to free - * @brief Free the given uri structure. - */ -EAPI void -efreet_uri_free(Efreet_Uri *uri) -{ - if (!uri) return; - IF_RELEASE(uri->protocol); - IF_RELEASE(uri->path); - IF_RELEASE(uri->hostname); - FREE(uri); -} diff --git a/legacy/efreet/src/lib/efreet_uri.c b/legacy/efreet/src/lib/efreet_uri.c new file mode 100644 index 0000000000..e50d7ce87d --- /dev/null +++ b/legacy/efreet/src/lib/efreet_uri.c @@ -0,0 +1,117 @@ +/* vim: set sw=4 ts=4 sts=4 et: */ +#include "Efreet.h" +#include "efreet_private.h" + + +/** + * @param full_uri: a valid uri string to parse + * @return Return The corresponding Efreet_Uri structure. Or NULL on errors. + * @brief Read a single uri and return an Efreet_Uri struct. If there's no + * hostname in the uri then the hostname parameter will be NULL. All the uri + * escaped chars will be converted to normal. + */ +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]; + int i = 0; + + /* 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(path, 0, PATH_MAX); + + /* parse protocol */ + p = full_uri; + for (i = 0; *p != ':' && *p != '\0' && i < 64; p++, i++) + protocol[i] = *p; + protocol[i] = '\0'; + + /* parse hostname */ + p += 3; + if (*p != '/') + { + for (i = 0; *p != '/' && *p != '\0' && i < _POSIX_HOST_NAME_MAX; p++, i++) + hostname[i] = *p; + hostname[i] = '\0'; + } + else + hostname[0] = '\0'; + + /* parse path */ + /* See http://www.faqs.org/rfcs/rfc1738.html for the escaped chars */ + for (i = 0; *p != '\0' && i < PATH_MAX; i++, p++) + { + if (*p == '%') + { + path[i] = *(++p); + path[i + 1] = *(++p); + path[i] = (char)strtol(&(path[i]), NULL, 16); + path[i + 1] = '\0'; + } + else + path[i] = *p; + } + + uri = NEW(Efreet_Uri, 1); + if (!uri) return NULL; + + uri->protocol = ecore_string_instance(protocol); + uri->hostname = ecore_string_instance(hostname); + uri->path = ecore_string_instance(path); + + return uri; +} + +/** + * @param uri: Create an URI string from an Efreet_Uri struct + * @return The string rapresentation of uri (ex: 'file:///home/my%20name') + * @brief Get the string rapresentation of the given uri struct escaping + * illegal caracters. Remember to free the string with ecore_string_release() + * when you don't need it anymore. + * @note The resulting string will contain the protocol and the path but not + * the hostname, as many apps doesn't handle it. + */ +EAPI const char * +efreet_uri_encode(Efreet_Uri *uri) +{ + char dest[PATH_MAX * 3 + 4]; + const char *p; + int i; + + if (!uri || !uri->path || !uri->protocol) return NULL; + memset(dest, 0, PATH_MAX * 3 + 4); + snprintf(dest, strlen(uri->protocol) + 4, "%s://", uri->protocol); + + /* Most app doesn't handle the hostname in the uri so it's put to NULL */ + for (i = strlen(uri->protocol) + 3, p = uri->path; *p != '\0'; p++, i++) + { + if (isalnum(*p) || strchr("/$-_.+!*'()", *p)) + dest[i] = *p; + else + { + snprintf(&(dest[i]), 4, "%%%02X", *p); + i += 2; + } + } + + return ecore_string_instance(dest); +} + +/** + * @param uri: The uri to free + * @brief Free the given uri structure. + */ +EAPI void +efreet_uri_free(Efreet_Uri *uri) +{ + if (!uri) return; + IF_RELEASE(uri->protocol); + IF_RELEASE(uri->path); + IF_RELEASE(uri->hostname); + FREE(uri); +} diff --git a/legacy/efreet/src/lib/efreet_uri.h b/legacy/efreet/src/lib/efreet_uri.h new file mode 100644 index 0000000000..6b8548b8ff --- /dev/null +++ b/legacy/efreet/src/lib/efreet_uri.h @@ -0,0 +1,43 @@ +/* vim: set sw=4 ts=4 sts=4 et: */ +#ifndef EFREET_URI_H +#define EFREET_URI_H + +/** + * @file efreet_uri.h + * @brief Contains the methods used to support the FDO URI specification. + * @addtogroup Efreet_Uri Efreet_Uri: The FDO URI Specification functions + * @{ + */ + +#include +#include + + +/** + * Efreet_Uri + */ +typedef struct Efreet_Uri Efreet_Uri; + +/** + * Efreet_Uri + * @brief Contains a simple rappresentation of an uri. The string don't have + * special chars escaped. + */ +struct Efreet_Uri +{ + const char *protocol; /**< The protocol used (usually 'file')*/ + const char *hostname; /**< The name of the host if any, or NULL */ + const char *path; /**< The full file path whitout protocol nor host*/ +}; + + +EAPI const char *efreet_uri_encode(Efreet_Uri *uri); +EAPI Efreet_Uri *efreet_uri_decode(const char *val); +EAPI void efreet_uri_free(Efreet_Uri *uri); + + +/** + * @} + */ + +#endif