annotate src/uri_utils.c @ 904:1698baa37871

Move uri_*() functions to separate files: uri_utils.[ch]
author zas_
date Sun, 20 Jul 2008 15:16:05 +0000
parents
children 1646720364cf
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
904
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
1 /*
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
2 * Geeqie
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
3 * Copyright (C) 2008 The Geeqie Team
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
4 *
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
5 * Authors: John Ellis, Vladimir Nadvornik, Laurent Monin
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
6 *
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
7 *
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
8 * This software is released under the GNU General Public License (GNU GPL).
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
9 * Please read the included file COPYING for more information.
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
10 * This software comes with no warranty of any kind, use at your own risk!
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
11 */
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
12
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
13 #include "main.h"
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
14 #include "uri_utils.h"
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
15
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
16 #include "filedata.h"
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
17 #include "ui_fileops.h"
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
18
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
19 /*
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
20 *-----------------------------------------------------------------------------
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
21 * drag and drop uri utils
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
22 *-----------------------------------------------------------------------------
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
23 */
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
24
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
25 /* the following characters are allowed to be unencoded for pathnames:
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
26 * $ & + , / : = @
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
27 */
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
28 static gint escape_char_list[] = {
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
29 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 0 */
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
30 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 10 */
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
31 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 20 */
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
32 /* spc ! " # $ % & ' */
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
33 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, /* 30 */
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
34 /* ( ) * + , - . / 0 1 */
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
35 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 40 */
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
36 /* 2 3 4 5 6 7 8 9 : ; */
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
37 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, /* 50 */
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
38 /* < = > ? @ A B C D E */
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
39 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, /* 60 */
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
40 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 70 */
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
41 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 80 */
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
42 /* Z [ \ ] ^ _ ` a b c */
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
43 0, 1, 1, 1, 1, 0, 1, 0, 0, 0, /* 90 */
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
44 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 100 */
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
45 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 110 */
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
46 /* x y z { | } ~ del */
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
47 0, 0, 0, 1, 1, 1, 0, 0 /* 120, 127 is end */
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
48 };
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
49
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
50 static gchar *hex_char = "0123456789ABCDEF";
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
51
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
52 static gint escape_test(guchar c)
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
53 {
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
54 if (c < 32 || c > 127) return TRUE;
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
55 return (escape_char_list[c] != 0);
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
56 }
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
57
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
58 static const gchar *escape_code(guchar c)
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
59 {
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
60 static gchar text[4];
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
61
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
62 text[0] = '%';
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
63 text[1] = hex_char[c>>4];
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
64 text[2] = hex_char[c%16];
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
65 text[3] = '\0';
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
66
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
67 return text;
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
68 }
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
69
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
70 gchar *uri_text_escape(const gchar *text)
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
71 {
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
72 GString *string;
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
73 gchar *result;
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
74 const gchar *p;
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
75
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
76 if (!text) return NULL;
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
77
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
78 string = g_string_new("");
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
79
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
80 p = text;
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
81 while (*p != '\0')
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
82 {
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
83 if (escape_test(*p))
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
84 {
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
85 g_string_append(string, escape_code(*p));
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
86 }
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
87 else
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
88 {
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
89 g_string_append_c(string, *p);
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
90 }
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
91 p++;
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
92 }
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
93
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
94 result = string->str;
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
95 g_string_free(string, FALSE);
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
96
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
97 /* dropped filenames are expected to be utf-8 compatible */
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
98 if (!g_utf8_validate(result, -1, NULL))
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
99 {
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
100 gchar *tmp;
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
101
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
102 tmp = g_locale_to_utf8(result, -1, NULL, NULL, NULL);
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
103 if (tmp)
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
104 {
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
105 g_free(result);
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
106 result = tmp;
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
107 }
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
108 }
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
109
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
110 return result;
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
111 }
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
112
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
113 /* this operates on the passed string, decoding escaped characters */
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
114 void uri_text_decode(gchar *text)
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
115 {
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
116 if (strchr(text, '%'))
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
117 {
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
118 gchar *w;
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
119 gchar *r;
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
120
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
121 w = r = text;
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
122
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
123 while (*r != '\0')
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
124 {
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
125 if (*r == '%' && *(r + 1) != '\0' && *(r + 2) != '\0')
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
126 {
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
127 gchar t[3];
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
128 gint n;
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
129
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
130 r++;
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
131 t[0] = *r;
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
132 r++;
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
133 t[1] = *r;
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
134 t[2] = '\0';
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
135 n = (gint)strtol(t, NULL, 16);
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
136 if (n > 0 && n < 256)
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
137 {
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
138 *w = (gchar)n;
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
139 }
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
140 else
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
141 {
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
142 /* invalid number, rewind and ignore this escape */
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
143 r -= 2;
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
144 *w = *r;
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
145 }
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
146 }
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
147 else if (w != r)
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
148 {
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
149 *w = *r;
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
150 }
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
151 r++;
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
152 w++;
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
153 }
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
154 if (*w != '\0') *w = '\0';
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
155 }
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
156 }
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
157
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
158 static void uri_list_parse_encoded_chars(GList *list)
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
159 {
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
160 GList *work = list;
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
161
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
162 while (work)
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
163 {
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
164 gchar *text = work->data;
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
165
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
166 uri_text_decode(text);
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
167
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
168 work = work->next;
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
169 }
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
170 }
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
171
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
172 GList *uri_list_from_text(gchar *data, gint files_only)
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
173 {
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
174 GList *list = NULL;
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
175 gint b, e;
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
176
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
177 b = e = 0;
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
178
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
179 while (data[b] != '\0')
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
180 {
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
181 while (data[e] != '\r' && data[e] != '\n' && data[e] != '\0') e++;
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
182 if (strncmp(data + b, "file:", 5) == 0)
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
183 {
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
184 gchar *path;
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
185 b += 5;
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
186 while (data[b] == '/' && data[b+1] == '/') b++;
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
187 path = g_strndup(data + b, e - b);
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
188 list = g_list_append(list, path_to_utf8(path));
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
189 g_free(path);
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
190 }
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
191 else if (!files_only && strncmp(data + b, "http:", 5) == 0)
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
192 {
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
193 list = g_list_append(list, g_strndup(data + b, e - b));
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
194 }
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
195 else if (!files_only && strncmp(data + b, "ftp:", 3) == 0)
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
196 {
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
197 list = g_list_append(list, g_strndup(data + b, e - b));
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
198 }
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
199 while (data[e] == '\r' || data[e] == '\n') e++;
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
200 b = e;
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
201 }
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
202
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
203 uri_list_parse_encoded_chars(list);
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
204
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
205 return list;
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
206 }
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
207
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
208 GList *uri_filelist_from_text(gchar *data, gint files_only)
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
209 {
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
210 GList *path_list = uri_list_from_text(data, files_only);
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
211 GList *filelist = filelist_from_path_list(path_list);
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
212 string_list_free(path_list);
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
213 return filelist;
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
214 }
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
215
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
216 gchar *uri_text_from_list(GList *list, gint *len, gint plain_text)
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
217 {
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
218 gchar *uri_text = NULL;
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
219 GString *string;
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
220 GList *work;
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
221
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
222 if (!list)
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
223 {
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
224 if (len) *len = 0;
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
225 return NULL;
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
226 }
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
227
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
228 string = g_string_new("");
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
229
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
230 work = list;
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
231 while (work)
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
232 {
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
233 const gchar *name8; /* dnd filenames are in utf-8 */
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
234
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
235 name8 = work->data;
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
236
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
237 if (!plain_text)
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
238 {
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
239 gchar *escaped;
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
240
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
241 escaped = uri_text_escape(name8);
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
242 g_string_append(string, "file:");
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
243 g_string_append(string, escaped);
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
244 g_free(escaped);
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
245
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
246 g_string_append(string, "\r\n");
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
247 }
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
248 else
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
249 {
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
250 g_string_append(string, name8);
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
251 if (work->next) g_string_append(string, "\n");
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
252 }
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
253
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
254 work = work->next;
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
255 }
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
256
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
257 uri_text = string->str;
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
258 if (len) *len = string->len;
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
259 g_string_free(string, FALSE);
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
260
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
261 return uri_text;
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
262 }
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
263
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
264 gchar *uri_text_from_filelist(GList *list, gint *len, gint plain_text)
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
265 {
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
266 GList *path_list = filelist_to_path_list(list);
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
267 gchar *ret = uri_text_from_list(path_list, len, plain_text);
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
268 string_list_free(path_list);
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
269 return ret;
1698baa37871 Move uri_*() functions to separate files: uri_utils.[ch]
zas_
parents:
diff changeset
270 }