7 #ifndef _POSIX_HOST_NAME_MAX
8 #define _POSIX_HOST_NAME_MAX 255
15 /* define macros and variable for using the eina logging system */
16 #define EFREET_MODULE_LOG_DOM /* no logging in this file */
19 #include "efreet_private.h"
23 efreet_uri_decode(const char *full_uri)
27 char protocol[64], hostname[_POSIX_HOST_NAME_MAX], path[PATH_MAX];
30 EINA_SAFETY_ON_NULL_RETURN_VAL(full_uri, NULL);
32 /* An uri should be in the form <protocol>://<hostname>/<path> */
33 if (!strstr(full_uri, "://")) return NULL;
35 memset(protocol, 0, 64);
36 memset(hostname, 0, _POSIX_HOST_NAME_MAX);
37 memset(path, 0, PATH_MAX);
41 for (i = 0; *p != ':' && *p != '\0' && i < 64; p++, i++)
49 for (i = 0; *p != '/' && *p != '\0' && i < _POSIX_HOST_NAME_MAX; p++, i++)
57 /* See http://www.faqs.org/rfcs/rfc1738.html for the escaped chars */
58 for (i = 0; *p != '\0' && i < PATH_MAX; i++, p++)
64 path[i] = (char)strtol(&(path[i]), NULL, 16);
71 uri = NEW(Efreet_Uri, 1);
72 if (!uri) return NULL;
74 uri->protocol = eina_stringshare_add(protocol);
75 uri->hostname = eina_stringshare_add(hostname);
76 uri->path = eina_stringshare_add(path);
82 efreet_uri_encode(Efreet_Uri *uri)
84 char dest[PATH_MAX * 3 + 4];
88 EINA_SAFETY_ON_NULL_RETURN_VAL(uri, NULL);
89 EINA_SAFETY_ON_NULL_RETURN_VAL(uri->path, NULL);
90 EINA_SAFETY_ON_NULL_RETURN_VAL(uri->protocol, NULL);
92 memset(dest, 0, PATH_MAX * 3 + 4);
93 snprintf(dest, strlen(uri->protocol) + 4, "%s://", uri->protocol);
95 /* Most app doesn't handle the hostname in the uri so it's put to NULL */
96 for (i = strlen(uri->protocol) + 3, p = uri->path; *p != '\0'; p++, i++)
98 if (isalnum(*p) || strchr("/$-_.+!*'()", *p))
102 snprintf(&(dest[i]), 4, "%%%02X", (unsigned char) *p);
107 return eina_stringshare_add(dest);
111 efreet_uri_free(Efreet_Uri *uri)
115 IF_RELEASE(uri->protocol);
116 IF_RELEASE(uri->path);
117 IF_RELEASE(uri->hostname);