summaryrefslogtreecommitdiff
path: root/legacy/efreet
diff options
context:
space:
mode:
authorDavide Andreoli <dave@gurumeditation.it>2008-08-03 00:07:17 +0000
committerDavide Andreoli <dave@gurumeditation.it>2008-08-03 00:07:17 +0000
commit71e9fe89e9918117d10d318d894394c8bf2aab31 (patch)
treecc16f51464a09bf2141b3df7d560adf0d6139735 /legacy/efreet
parent1379c749b0e44d389b055e8dea502af279280d13 (diff)
Move Efreet_Uri stuff on the proper file. We can now use this in e instead of the internal one.
SVN revision: 35312
Diffstat (limited to 'legacy/efreet')
-rw-r--r--legacy/efreet/src/lib/Efreet.h2
-rw-r--r--legacy/efreet/src/lib/Efreet_Trash.h39
-rw-r--r--legacy/efreet/src/lib/Makefile.am4
-rw-r--r--legacy/efreet/src/lib/efreet_trash.c117
-rw-r--r--legacy/efreet/src/lib/efreet_uri.c117
-rw-r--r--legacy/efreet/src/lib/efreet_uri.h43
6 files changed, 174 insertions, 148 deletions
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 @@
22 * @li Icon Theme Specification 22 * @li Icon Theme Specification
23 * @li Desktop Entry Specification 23 * @li Desktop Entry Specification
24 * @li Desktop Menu Specification 24 * @li Desktop Menu Specification
25 * @li FDO URI Specification
25 * @li Shared Mime Info Specification 26 * @li Shared Mime Info Specification
26 * @li Trash Specification 27 * @li Trash Specification
27 */ 28 */
@@ -57,6 +58,7 @@ extern "C" {
57#include "efreet_desktop.h" 58#include "efreet_desktop.h"
58#include "efreet_menu.h" 59#include "efreet_menu.h"
59#include "efreet_utils.h" 60#include "efreet_utils.h"
61#include "efreet_uri.h"
60 62
61EAPI int efreet_init(void); 63EAPI int efreet_init(void);
62EAPI int efreet_shutdown(void); 64EAPI 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 @@
2#ifndef EFREET_TRASH_H 2#ifndef EFREET_TRASH_H
3#define EFREET_TRASH_H 3#define EFREET_TRASH_H
4 4
5/**
6 * @file Efreet_Trash.h
7 * @brief Contains the methods used to support the FDO trash specification.
8 * @addtogroup Efreet_Trash Efreet_Trash: The XDG Trash Specification
9 * Efreet_Trash.h provides all of the necessary headers and includes to
10 * work with Efreet_Trash.
11 * @{
12 */
13
14#ifdef EAPI 5#ifdef EAPI
15#undef EAPI 6#undef EAPI
16#endif 7#endif
@@ -36,29 +27,14 @@
36extern "C" { 27extern "C" {
37#endif 28#endif
38 29
39
40
41/** 30/**
42 * Efreet_Uri 31 * @file Efreet_Trash.h
43 */ 32 * @brief Contains the methods used to support the FDO trash specification.
44typedef struct Efreet_Uri Efreet_Uri; 33 * @addtogroup Efreet_Trash Efreet_Trash: The XDG Trash Specification
45 34 * Efreet_Trash.h provides all of the necessary headers and includes to
46/** 35 * work with Efreet_Trash.
47 * Efreet_Uri 36 * @{
48 * @brief Contains a simple rappresentation of an uri. The string don't have
49 * special chars escaped.
50 */ 37 */
51struct Efreet_Uri
52{
53 const char *protocol; /**< The name of the host if any, or NULL */
54 const char *hostname; /**< The name of the host if any, or NULL */
55 const char *path; /**< The full file path whitout protocol nor host*/
56};
57
58
59EAPI const char *efreet_uri_escape(Efreet_Uri *uri);
60EAPI Efreet_Uri *efreet_uri_parse(const char *val);
61EAPI void efreet_uri_free(Efreet_Uri *uri);
62 38
63EAPI int efreet_trash_init(void); 39EAPI int efreet_trash_init(void);
64EAPI void efreet_trash_shutdown(void); 40EAPI void efreet_trash_shutdown(void);
@@ -68,8 +44,7 @@ EAPI int efreet_trash_delete_uri(Efreet_Uri *uri, int force_delete);
68EAPI Ecore_List *efreet_trash_ls(void); 44EAPI Ecore_List *efreet_trash_ls(void);
69EAPI int efreet_trash_is_empty(void); 45EAPI int efreet_trash_is_empty(void);
70EAPI int efreet_trash_empty_trash(void); 46EAPI int efreet_trash_empty_trash(void);
71 47
72
73/** 48/**
74 * @} 49 * @}
75 */ 50 */
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 \
15efreet_icon.h \ 15efreet_icon.h \
16efreet_ini.h \ 16efreet_ini.h \
17efreet_menu.h \ 17efreet_menu.h \
18efreet_utils.h 18efreet_utils.h \
19efreet_uri.h
19 20
20EFREETSOURCES = \ 21EFREETSOURCES = \
21efreet.c \ 22efreet.c \
@@ -26,6 +27,7 @@ efreet_ini.c \
26efreet_desktop.c \ 27efreet_desktop.c \
27efreet_menu.c \ 28efreet_menu.c \
28efreet_utils.c \ 29efreet_utils.c \
30efreet_uri.c \
29efreet_private.h \ 31efreet_private.h \
30efreet_xml.h \ 32efreet_xml.h \
31$(EFREETHEADERS) 33$(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)
108 return 0; 108 return 0;
109 } 109 }
110 } 110 }
111 111
112
113 /* create info file */ 112 /* create info file */
114 snprintf(dest, PATH_MAX, "%s/info/%s.trashinfo", 113 snprintf(dest, PATH_MAX, "%s/info/%s.trashinfo",
115 efreet_trash_dir_get(), fname); 114 efreet_trash_dir_get(), fname);
@@ -119,7 +118,7 @@ efreet_trash_delete_uri(Efreet_Uri *uri, int force_delete)
119 fputs("[Trash Info]\n", f); //TODO is '\n' right?? (or \r\c??) 118 fputs("[Trash Info]\n", f); //TODO is '\n' right?? (or \r\c??)
120 119
121 fputs("Path=", f); 120 fputs("Path=", f);
122 escaped = efreet_uri_escape(uri); 121 escaped = efreet_uri_encode(uri);
123 fputs(escaped + 7, f); // +7 == don't write 'file://' 122 fputs(escaped + 7, f); // +7 == don't write 'file://'
124 IF_RELEASE(escaped); 123 IF_RELEASE(escaped);
125 124
@@ -198,115 +197,3 @@ efreet_trash_ls(void)
198 return files; 197 return files;
199} 198}
200 199
201
202/**
203 * @param val: a valid uri string to parse
204 * @return Return The corresponding Efreet_Uri structure. Or NULL on errors.
205 * @brief Parse a single uri and return an Efreet_Uri struct. If there's no
206 * hostname in the uri then the hostname parameter is NULL. All the uri escaped
207 * chars will be converted back.
208 */
209EAPI Efreet_Uri *
210efreet_uri_parse(const char *val)
211{
212 Efreet_Uri *uri;
213 const char *p;
214 char protocol[64], hostname[_POSIX_HOST_NAME_MAX], path[PATH_MAX];
215 int i = 0;
216
217 /* An uri should be in the form <protocol>://<hostname>/<path> */
218 p = strstr(val, "://");
219 if (!p) return NULL;
220
221 memset(protocol, 0, 64);
222 memset(hostname, 0, _POSIX_HOST_NAME_MAX);
223 memset(path, 0, PATH_MAX);
224
225 /* parse protocol */
226 p = val;
227 for (i = 0; *p != ':' && *p != '\0' && i < 64; p++, i++)
228 protocol[i] = *p;
229 protocol[i] = '\0';
230
231 /* parse hostname */
232 p += 3;
233 if (*p != '/')
234 {
235 for (i = 0; *p != '/' && *p != '\0' && i < _POSIX_HOST_NAME_MAX; p++, i++)
236 hostname[i] = *p;
237 hostname[i] = '\0';
238 }
239 else
240 hostname[0] = '\0';
241
242 /* parse path */
243 /* See http://www.faqs.org/rfcs/rfc1738.html for the escaped chars */
244 for (i = 0; *p != '\0' && i < PATH_MAX; i++, p++)
245 {
246 if (*p == '%')
247 {
248 path[i] = *(++p);
249 path[i + 1] = *(++p);
250 path[i] = (char)strtol(&(path[i]), NULL, 16);
251 path[i + 1] = '\0';
252 }
253 else
254 path[i] = *p;
255 }
256
257 uri = NEW(Efreet_Uri, 1);
258 if (!uri) return NULL;
259
260 uri->protocol = ecore_string_instance(protocol);
261 uri->hostname = ecore_string_instance(hostname);
262 uri->path = ecore_string_instance(path);
263
264 return uri;
265}
266
267/**
268 * @param uri: The uri structure to escape
269 * @return The string rapresentation of an uri (ex: 'file:///home/my%20name')
270 * @brief Get the string rapresentation of the given uri struct escaping
271 * illegal caracters. The resulting string will contain the protocol but not the
272 * hostname, as many apps doesn't handle it.
273 */
274EAPI const char *
275efreet_uri_escape(Efreet_Uri *uri)
276{
277 char dest[PATH_MAX * 3 + 4];
278 const char *p;
279 int i;
280
281 if (!uri || !uri->path || !uri->protocol) return NULL;
282 memset(dest, 0, PATH_MAX * 3 + 4);
283 snprintf(dest, strlen(uri->protocol) + 4, "%s://", uri->protocol);
284
285 /* Most app doesn't handle the hostname in the uri so it's put to NULL */
286 for (i = strlen(uri->protocol) + 3, p = uri->path; *p != '\0'; p++, i++)
287 {
288 if (isalnum(*p) || strchr("/$-_.+!*'()", *p))
289 dest[i] = *p;
290 else
291 {
292 snprintf(&(dest[i]), 4, "%%%02X", *p);
293 i += 2;
294 }
295 }
296
297 return ecore_string_instance(dest);
298}
299
300/**
301 * @param uri: The uri to free
302 * @brief Free the given uri structure.
303 */
304EAPI void
305efreet_uri_free(Efreet_Uri *uri)
306{
307 if (!uri) return;
308 IF_RELEASE(uri->protocol);
309 IF_RELEASE(uri->path);
310 IF_RELEASE(uri->hostname);
311 FREE(uri);
312}
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 @@
1/* vim: set sw=4 ts=4 sts=4 et: */
2#include "Efreet.h"
3#include "efreet_private.h"
4
5
6/**
7 * @param full_uri: a valid uri string to parse
8 * @return Return The corresponding Efreet_Uri structure. Or NULL on errors.
9 * @brief Read a single uri and return an Efreet_Uri struct. If there's no
10 * hostname in the uri then the hostname parameter will be NULL. All the uri
11 * escaped chars will be converted to normal.
12 */
13EAPI Efreet_Uri *
14efreet_uri_decode(const char *full_uri)
15{
16 Efreet_Uri *uri;
17 const char *p;
18 char protocol[64], hostname[_POSIX_HOST_NAME_MAX], path[PATH_MAX];
19 int i = 0;
20
21 /* An uri should be in the form <protocol>://<hostname>/<path> */
22 if (!strstr(full_uri, "://")) return NULL;
23
24 memset(protocol, 0, 64);
25 memset(hostname, 0, _POSIX_HOST_NAME_MAX);
26 memset(path, 0, PATH_MAX);
27
28 /* parse protocol */
29 p = full_uri;
30 for (i = 0; *p != ':' && *p != '\0' && i < 64; p++, i++)
31 protocol[i] = *p;
32 protocol[i] = '\0';
33
34 /* parse hostname */
35 p += 3;
36 if (*p != '/')
37 {
38 for (i = 0; *p != '/' && *p != '\0' && i < _POSIX_HOST_NAME_MAX; p++, i++)
39 hostname[i] = *p;
40 hostname[i] = '\0';
41 }
42 else
43 hostname[0] = '\0';
44
45 /* parse path */
46 /* See http://www.faqs.org/rfcs/rfc1738.html for the escaped chars */
47 for (i = 0; *p != '\0' && i < PATH_MAX; i++, p++)
48 {
49 if (*p == '%')
50 {
51 path[i] = *(++p);
52 path[i + 1] = *(++p);
53 path[i] = (char)strtol(&(path[i]), NULL, 16);
54 path[i + 1] = '\0';
55 }
56 else
57 path[i] = *p;
58 }
59
60 uri = NEW(Efreet_Uri, 1);
61 if (!uri) return NULL;
62
63 uri->protocol = ecore_string_instance(protocol);
64 uri->hostname = ecore_string_instance(hostname);
65 uri->path = ecore_string_instance(path);
66
67 return uri;
68}
69
70/**
71 * @param uri: Create an URI string from an Efreet_Uri struct
72 * @return The string rapresentation of uri (ex: 'file:///home/my%20name')
73 * @brief Get the string rapresentation of the given uri struct escaping
74 * illegal caracters. Remember to free the string with ecore_string_release()
75 * when you don't need it anymore.
76 * @note The resulting string will contain the protocol and the path but not
77 * the hostname, as many apps doesn't handle it.
78 */
79EAPI const char *
80efreet_uri_encode(Efreet_Uri *uri)
81{
82 char dest[PATH_MAX * 3 + 4];
83 const char *p;
84 int i;
85
86 if (!uri || !uri->path || !uri->protocol) return NULL;
87 memset(dest, 0, PATH_MAX * 3 + 4);
88 snprintf(dest, strlen(uri->protocol) + 4, "%s://", uri->protocol);
89
90 /* Most app doesn't handle the hostname in the uri so it's put to NULL */
91 for (i = strlen(uri->protocol) + 3, p = uri->path; *p != '\0'; p++, i++)
92 {
93 if (isalnum(*p) || strchr("/$-_.+!*'()", *p))
94 dest[i] = *p;
95 else
96 {
97 snprintf(&(dest[i]), 4, "%%%02X", *p);
98 i += 2;
99 }
100 }
101
102 return ecore_string_instance(dest);
103}
104
105/**
106 * @param uri: The uri to free
107 * @brief Free the given uri structure.
108 */
109EAPI void
110efreet_uri_free(Efreet_Uri *uri)
111{
112 if (!uri) return;
113 IF_RELEASE(uri->protocol);
114 IF_RELEASE(uri->path);
115 IF_RELEASE(uri->hostname);
116 FREE(uri);
117}
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 @@
1/* vim: set sw=4 ts=4 sts=4 et: */
2#ifndef EFREET_URI_H
3#define EFREET_URI_H
4
5/**
6 * @file efreet_uri.h
7 * @brief Contains the methods used to support the FDO URI specification.
8 * @addtogroup Efreet_Uri Efreet_Uri: The FDO URI Specification functions
9 * @{
10 */
11
12#include <Ecore.h>
13#include <Ecore_Data.h>
14
15
16/**
17 * Efreet_Uri
18 */
19typedef struct Efreet_Uri Efreet_Uri;
20
21/**
22 * Efreet_Uri
23 * @brief Contains a simple rappresentation of an uri. The string don't have
24 * special chars escaped.
25 */
26struct Efreet_Uri
27{
28 const char *protocol; /**< The protocol used (usually 'file')*/
29 const char *hostname; /**< The name of the host if any, or NULL */
30 const char *path; /**< The full file path whitout protocol nor host*/
31};
32
33
34EAPI const char *efreet_uri_encode(Efreet_Uri *uri);
35EAPI Efreet_Uri *efreet_uri_decode(const char *val);
36EAPI void efreet_uri_free(Efreet_Uri *uri);
37
38
39/**
40 * @}
41 */
42
43#endif