Mercurial > pidgin.yaz
annotate src/util.c @ 13853:bbf0470cb348
[gaim-migrate @ 16312]
Improvement/fixing of GntTree. Do the scrolling and stuff without 'reliably'.
committer: Tailor Script <tailor@pidgin.im>
author | Sadrul Habib Chowdhury <imadil@gmail.com> |
---|---|
date | Fri, 23 Jun 2006 00:45:45 +0000 |
parents | 378bba5011e7 |
children | 7d513e44201b |
rev | line source |
---|---|
1 | 1 /* |
7094
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
2 * @file util.h Utility Functions |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3 * @ingroup core |
1 | 4 * |
8046 | 5 * Gaim is the legal property of its developers, whose names are too numerous |
6 * to list here. Please refer to the COPYRIGHT file distributed with this | |
7 * source distribution. | |
1 | 8 * |
9 * This program is free software; you can redistribute it and/or modify | |
10 * it under the terms of the GNU General Public License as published by | |
11 * the Free Software Foundation; either version 2 of the License, or | |
12 * (at your option) any later version. | |
13 * | |
14 * This program is distributed in the hope that it will be useful, | |
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 * GNU General Public License for more details. | |
18 * | |
19 * You should have received a copy of the GNU General Public License | |
20 * along with this program; if not, write to the Free Software | |
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
22 */ | |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5826
diff
changeset
|
23 #include "internal.h" |
3630 | 24 |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5826
diff
changeset
|
25 #include "conversation.h" |
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5826
diff
changeset
|
26 #include "debug.h" |
10425 | 27 #include "notify.h" |
1575
427e1409917c
[gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1560
diff
changeset
|
28 #include "prpl.h" |
5545
7a64114641c3
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5532
diff
changeset
|
29 #include "prefs.h" |
7094
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
30 #include "util.h" |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
31 |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
32 typedef struct |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
33 { |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
34 void (*callback)(void *, const char *, size_t); |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
35 void *user_data; |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
36 |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
37 struct |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
38 { |
9227
9171e528d7e5
[gaim-migrate @ 10023]
Christian Hammond <chipx86@chipx86.com>
parents:
9222
diff
changeset
|
39 char *user; |
9171e528d7e5
[gaim-migrate @ 10023]
Christian Hammond <chipx86@chipx86.com>
parents:
9222
diff
changeset
|
40 char *passwd; |
7094
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
41 char *address; |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
42 int port; |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
43 char *page; |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
44 |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
45 } website; |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
46 |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
47 char *url; |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
48 gboolean full; |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
49 char *user_agent; |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
50 gboolean http11; |
12887
4229503f1cd9
[gaim-migrate @ 15240]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12880
diff
changeset
|
51 char *request; |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13163
diff
changeset
|
52 gsize request_written; |
12887
4229503f1cd9
[gaim-migrate @ 15240]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12880
diff
changeset
|
53 gboolean include_headers; |
7094
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
54 |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
55 int inpa; |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
56 |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13163
diff
changeset
|
57 gboolean got_headers; |
9240 | 58 gboolean has_explicit_data_len; |
7094
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
59 char *webdata; |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
60 unsigned long len; |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
61 unsigned long data_len; |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
62 |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
63 } GaimFetchUrlData; |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
64 |
8596 | 65 static char custom_home_dir[MAXPATHLEN]; |
3630 | 66 static char home_dir[MAXPATHLEN]; |
67 | |
12919
248b8b39c671
[gaim-migrate @ 15272]
Etan Reisner <pidgin@unreliablesource.net>
parents:
12907
diff
changeset
|
68 GaimMenuAction * |
13102
5828d42e8684
[gaim-migrate @ 15464]
Richard Laager <rlaager@wiktel.com>
parents:
13097
diff
changeset
|
69 gaim_menu_action_new(const char *label, GaimCallback callback, gpointer data, |
12919
248b8b39c671
[gaim-migrate @ 15272]
Etan Reisner <pidgin@unreliablesource.net>
parents:
12907
diff
changeset
|
70 GList *children) |
248b8b39c671
[gaim-migrate @ 15272]
Etan Reisner <pidgin@unreliablesource.net>
parents:
12907
diff
changeset
|
71 { |
248b8b39c671
[gaim-migrate @ 15272]
Etan Reisner <pidgin@unreliablesource.net>
parents:
12907
diff
changeset
|
72 GaimMenuAction *act = g_new0(GaimMenuAction, 1); |
13102
5828d42e8684
[gaim-migrate @ 15464]
Richard Laager <rlaager@wiktel.com>
parents:
13097
diff
changeset
|
73 act->label = g_strdup(label); |
12919
248b8b39c671
[gaim-migrate @ 15272]
Etan Reisner <pidgin@unreliablesource.net>
parents:
12907
diff
changeset
|
74 act->callback = callback; |
248b8b39c671
[gaim-migrate @ 15272]
Etan Reisner <pidgin@unreliablesource.net>
parents:
12907
diff
changeset
|
75 act->data = data; |
248b8b39c671
[gaim-migrate @ 15272]
Etan Reisner <pidgin@unreliablesource.net>
parents:
12907
diff
changeset
|
76 act->children = children; |
248b8b39c671
[gaim-migrate @ 15272]
Etan Reisner <pidgin@unreliablesource.net>
parents:
12907
diff
changeset
|
77 return act; |
248b8b39c671
[gaim-migrate @ 15272]
Etan Reisner <pidgin@unreliablesource.net>
parents:
12907
diff
changeset
|
78 } |
248b8b39c671
[gaim-migrate @ 15272]
Etan Reisner <pidgin@unreliablesource.net>
parents:
12907
diff
changeset
|
79 |
13102
5828d42e8684
[gaim-migrate @ 15464]
Richard Laager <rlaager@wiktel.com>
parents:
13097
diff
changeset
|
80 void |
5828d42e8684
[gaim-migrate @ 15464]
Richard Laager <rlaager@wiktel.com>
parents:
13097
diff
changeset
|
81 gaim_menu_action_free(GaimMenuAction *act) |
5828d42e8684
[gaim-migrate @ 15464]
Richard Laager <rlaager@wiktel.com>
parents:
13097
diff
changeset
|
82 { |
5828d42e8684
[gaim-migrate @ 15464]
Richard Laager <rlaager@wiktel.com>
parents:
13097
diff
changeset
|
83 g_return_if_fail(act != NULL); |
5828d42e8684
[gaim-migrate @ 15464]
Richard Laager <rlaager@wiktel.com>
parents:
13097
diff
changeset
|
84 |
5828d42e8684
[gaim-migrate @ 15464]
Richard Laager <rlaager@wiktel.com>
parents:
13097
diff
changeset
|
85 g_free(act->label); |
5828d42e8684
[gaim-migrate @ 15464]
Richard Laager <rlaager@wiktel.com>
parents:
13097
diff
changeset
|
86 g_free(act); |
5828d42e8684
[gaim-migrate @ 15464]
Richard Laager <rlaager@wiktel.com>
parents:
13097
diff
changeset
|
87 } |
5828d42e8684
[gaim-migrate @ 15464]
Richard Laager <rlaager@wiktel.com>
parents:
13097
diff
changeset
|
88 |
7108
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
89 /************************************************************************** |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
90 * Base16 Functions |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
91 **************************************************************************/ |
11127 | 92 gchar * |
11137 | 93 gaim_base16_encode(const guchar *data, gsize len) |
1 | 94 { |
7108
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
95 int i; |
11127 | 96 gchar *ascii = NULL; |
7108
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
97 |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
98 g_return_val_if_fail(data != NULL, NULL); |
11127 | 99 g_return_val_if_fail(len > 0, NULL); |
100 | |
101 ascii = g_malloc(len * 2 + 1); | |
102 | |
103 for (i = 0; i < len; i++) | |
7108
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
104 snprintf(&ascii[i * 2], 3, "%02hhx", data[i]); |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
105 |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
106 return ascii; |
1 | 107 } |
108 | |
11137 | 109 guchar * |
11127 | 110 gaim_base16_decode(const char *str, gsize *ret_len) |
1 | 111 { |
7108
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
112 int len, i, accumulator = 0; |
11137 | 113 guchar *data; |
11127 | 114 |
115 g_return_val_if_fail(str != NULL, NULL); | |
116 | |
117 len = strlen(str); | |
118 | |
119 g_return_val_if_fail(strlen(str) > 0, 0); | |
7108
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
120 g_return_val_if_fail(len % 2 > 0, 0); |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
121 |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
122 data = g_malloc(len / 2); |
1 | 123 |
7108
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
124 for (i = 0; i < len; i++) |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
125 { |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
126 if ((i % 2) == 0) |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
127 accumulator = 0; |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
128 else |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
129 accumulator <<= 4; |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
130 |
11127 | 131 if (isdigit(str[i])) |
132 accumulator |= str[i] - 48; | |
7108
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
133 else |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
134 { |
11127 | 135 switch(str[i]) |
7108
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
136 { |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
137 case 'a': case 'A': accumulator |= 10; break; |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
138 case 'b': case 'B': accumulator |= 11; break; |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
139 case 'c': case 'C': accumulator |= 12; break; |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
140 case 'd': case 'D': accumulator |= 13; break; |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
141 case 'e': case 'E': accumulator |= 14; break; |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
142 case 'f': case 'F': accumulator |= 15; break; |
1826
7f889cdfa03e
[gaim-migrate @ 1836]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
143 } |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
144 } |
7108
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
145 |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
146 if (i % 2) |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
147 data[(i - 1) / 2] = accumulator; |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
148 } |
1 | 149 |
11127 | 150 if (ret_len != NULL) |
151 *ret_len = len / 2; | |
152 | |
153 return data; | |
1 | 154 } |
155 | |
7108
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
156 /************************************************************************** |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
157 * Base64 Functions |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
158 **************************************************************************/ |
4888
912294585edf
[gaim-migrate @ 5218]
Christian Hammond <chipx86@chipx86.com>
parents:
4853
diff
changeset
|
159 static const char alphabet[] = |
912294585edf
[gaim-migrate @ 5218]
Christian Hammond <chipx86@chipx86.com>
parents:
4853
diff
changeset
|
160 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" |
912294585edf
[gaim-migrate @ 5218]
Christian Hammond <chipx86@chipx86.com>
parents:
4853
diff
changeset
|
161 "0123456789+/"; |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
162 |
8929 | 163 static const char xdigits[] = |
164 "0123456789abcdef"; | |
165 | |
11127 | 166 gchar * |
11137 | 167 gaim_base64_encode(const guchar *data, gsize len) |
1 | 168 { |
6872 | 169 char *out, *rv; |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
170 |
11127 | 171 g_return_val_if_fail(data != NULL, NULL); |
172 g_return_val_if_fail(len > 0, NULL); | |
173 | |
174 rv = out = g_malloc(((len/3)+1)*4 + 1); | |
175 | |
176 for (; len >= 3; len -= 3) | |
7108
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
177 { |
11127 | 178 *out++ = alphabet[data[0] >> 2]; |
179 *out++ = alphabet[((data[0] << 4) & 0x30) | (data[1] >> 4)]; | |
180 *out++ = alphabet[((data[1] << 2) & 0x3c) | (data[2] >> 6)]; | |
181 *out++ = alphabet[data[2] & 0x3f]; | |
182 data += 3; | |
7108
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
183 } |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
184 |
11127 | 185 if (len > 0) |
7108
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
186 { |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
187 unsigned char fragment; |
6872 | 188 |
11127 | 189 *out++ = alphabet[data[0] >> 2]; |
190 fragment = (data[0] << 4) & 0x30; | |
191 | |
192 if (len > 1) | |
193 fragment |= data[1] >> 4; | |
7108
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
194 |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
195 *out++ = alphabet[fragment]; |
11127 | 196 *out++ = (len < 2) ? '=' : alphabet[(data[1] << 2) & 0x3c]; |
7108
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
197 *out++ = '='; |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
198 } |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
199 |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
200 *out = '\0'; |
5426 | 201 |
202 return rv; | |
1 | 203 } |
204 | |
11137 | 205 guchar * |
11127 | 206 gaim_base64_decode(const char *str, gsize *ret_len) |
1 | 207 { |
11137 | 208 guchar *out = NULL; |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
209 char tmp = 0; |
1920
5bed3bc833b5
[gaim-migrate @ 1930]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1878
diff
changeset
|
210 const char *c; |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
211 gint32 tmp2 = 0; |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
212 int len = 0, n = 0; |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
213 |
11127 | 214 g_return_val_if_fail(str != NULL, NULL); |
215 | |
216 c = str; | |
1 | 217 |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
218 while (*c) { |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
219 if (*c >= 'A' && *c <= 'Z') { |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
220 tmp = *c - 'A'; |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
221 } else if (*c >= 'a' && *c <= 'z') { |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
222 tmp = 26 + (*c - 'a'); |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
223 } else if (*c >= '0' && *c <= 57) { |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
224 tmp = 52 + (*c - '0'); |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
225 } else if (*c == '+') { |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
226 tmp = 62; |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
227 } else if (*c == '/') { |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
228 tmp = 63; |
5289 | 229 } else if (*c == '\r' || *c == '\n') { |
230 c++; | |
231 continue; | |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
232 } else if (*c == '=') { |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
233 if (n == 3) { |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
234 out = g_realloc(out, len + 2); |
11137 | 235 out[len] = (guchar)(tmp2 >> 10) & 0xff; |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
236 len++; |
11137 | 237 out[len] = (guchar)(tmp2 >> 2) & 0xff; |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
238 len++; |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
239 } else if (n == 2) { |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
240 out = g_realloc(out, len + 1); |
11137 | 241 out[len] = (guchar)(tmp2 >> 4) & 0xff; |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
242 len++; |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
243 } |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
244 break; |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
245 } |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
246 tmp2 = ((tmp2 << 6) | (tmp & 0xff)); |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
247 n++; |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
248 if (n == 4) { |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
249 out = g_realloc(out, len + 3); |
11137 | 250 out[len] = (guchar)((tmp2 >> 16) & 0xff); |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
251 len++; |
11137 | 252 out[len] = (guchar)((tmp2 >> 8) & 0xff); |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
253 len++; |
11137 | 254 out[len] = (guchar)(tmp2 & 0xff); |
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
255 len++; |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
256 tmp2 = 0; |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
257 n = 0; |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
258 } |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
259 c++; |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
260 } |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
261 |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
262 out = g_realloc(out, len + 1); |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
263 out[len] = 0; |
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1250
diff
changeset
|
264 |
11127 | 265 if (ret_len != NULL) |
266 *ret_len = len; | |
267 | |
268 return out; | |
1 | 269 } |
270 | |
7679 | 271 /************************************************************************** |
11132 | 272 * Quoted Printable Functions (see RFC 2045). |
7679 | 273 **************************************************************************/ |
11137 | 274 guchar * |
11132 | 275 gaim_quotedp_decode(const char *str, gsize *ret_len) |
7679 | 276 { |
8125 | 277 char *n, *new; |
278 const char *end, *p; | |
7722 | 279 |
8005
3bdfb4308d10
[gaim-migrate @ 8682]
Christian Hammond <chipx86@chipx86.com>
parents:
7956
diff
changeset
|
280 n = new = g_malloc(strlen (str) + 1); |
8125 | 281 end = str + strlen(str); |
7679 | 282 |
8125 | 283 for (p = str; p < end; p++, n++) { |
7679 | 284 if (*p == '=') { |
8929 | 285 if (p[1] == '\r' && p[2] == '\n') { /* 5.1 #5 */ |
286 n -= 1; | |
287 p += 2; | |
288 } else if (p[1] == '\n') { /* fuzzy case for 5.1 #5 */ | |
289 n -= 1; | |
290 p += 1; | |
291 } else if (p[1] && p[2]) { | |
292 char *nibble1 = strchr(xdigits, tolower(p[1])); | |
293 char *nibble2 = strchr(xdigits, tolower(p[2])); | |
294 if (nibble1 && nibble2) { /* 5.1 #1 */ | |
295 *n = ((nibble1 - xdigits) << 4) | (nibble2 - xdigits); | |
296 p += 2; | |
297 } else { /* This should never happen */ | |
298 *n = *p; | |
299 } | |
300 } else { /* This should never happen */ | |
301 *n = *p; | |
302 } | |
7679 | 303 } |
304 else if (*p == '_') | |
305 *n = ' '; | |
306 else | |
307 *n = *p; | |
308 } | |
309 | |
310 *n = '\0'; | |
311 | |
11132 | 312 if (ret_len != NULL) |
7679 | 313 *ret_len = n - new; |
7722 | 314 |
7679 | 315 /* Resize to take less space */ |
316 /* new = realloc(new, n - new); */ | |
317 | |
11137 | 318 return (guchar *)new; |
7679 | 319 } |
320 | |
321 /************************************************************************** | |
322 * MIME Functions | |
323 **************************************************************************/ | |
324 char * | |
325 gaim_mime_decode_field(const char *str) | |
326 { | |
7858 | 327 /* |
8958 | 328 * This is wing's version, partially based on revo/shx's version |
329 * See RFC2047 [which apparently obsoletes RFC1342] | |
7858 | 330 */ |
8958 | 331 typedef enum { |
332 state_start, state_equal1, state_question1, | |
333 state_charset, state_question2, | |
334 state_encoding, state_question3, | |
335 state_encoded_text, state_question4, state_equal2 = state_start | |
336 } encoded_word_state_t; | |
337 encoded_word_state_t state = state_start; | |
7858 | 338 const char *cur, *mark; |
8958 | 339 const char *charset0 = NULL, *encoding0 = NULL, *encoded_text0 = NULL; |
7858 | 340 char *n, *new; |
341 | |
8976 | 342 /* token can be any CHAR (supposedly ISO8859-1/ISO2022), not just ASCII */ |
8958 | 343 #define token_char_p(c) \ |
344 (c != ' ' && !iscntrl(c) && !strchr("()<>@,;:\"/[]?.=", c)) | |
345 | |
346 /* But encoded-text must be ASCII; alas, isascii() may not exist */ | |
347 #define encoded_text_char_p(c) \ | |
348 ((c & 0x80) == 0 && c != '?' && c != ' ' && isgraph(c)) | |
349 | |
350 #define RECOVER_MARKED_TEXT strncpy(n, mark, cur - mark + 1); \ | |
351 n += cur - mark + 1 | |
352 | |
8976 | 353 g_return_val_if_fail(str != NULL, NULL); |
354 | |
355 /* NOTE: Assuming that we need just strlen(str)+1 *may* be wrong. | |
356 * It would be wrong if one byte (in some unknown encoding) could | |
357 * expand to >=4 bytes of UTF-8; I don't know if there are such things. | |
358 */ | |
7858 | 359 n = new = g_malloc(strlen(str) + 1); |
360 | |
361 /* Here we will be looking for encoded words and if they seem to be | |
362 * valid then decode them. | |
363 * They are of this form: =?charset?encoding?text?= | |
364 */ | |
365 | |
8958 | 366 for (cur = str, mark = NULL; *cur; cur += 1) { |
367 switch (state) { | |
368 case state_equal1: | |
369 if (*cur == '?') { | |
370 state = state_question1; | |
371 } else { | |
372 RECOVER_MARKED_TEXT; | |
373 state = state_start; | |
374 } | |
375 break; | |
376 case state_question1: | |
377 if (token_char_p(*cur)) { | |
378 charset0 = cur; | |
379 state = state_charset; | |
380 } else { /* This should never happen */ | |
381 RECOVER_MARKED_TEXT; | |
382 state = state_start; | |
383 } | |
384 break; | |
385 case state_charset: | |
7858 | 386 if (*cur == '?') { |
8958 | 387 state = state_question2; |
8976 | 388 } else if (!token_char_p(*cur)) { /* This should never happen */ |
8958 | 389 RECOVER_MARKED_TEXT; |
390 state = state_start; | |
391 } | |
392 break; | |
393 case state_question2: | |
394 if (token_char_p(*cur)) { | |
395 encoding0 = cur; | |
396 state = state_encoding; | |
397 } else { /* This should never happen */ | |
398 RECOVER_MARKED_TEXT; | |
399 state = state_start; | |
400 } | |
401 break; | |
402 case state_encoding: | |
403 if (*cur == '?') { | |
404 state = state_question3; | |
8976 | 405 } else if (!token_char_p(*cur)) { /* This should never happen */ |
8958 | 406 RECOVER_MARKED_TEXT; |
407 state = state_start; | |
408 } | |
409 break; | |
410 case state_question3: | |
411 if (encoded_text_char_p(*cur)) { | |
412 encoded_text0 = cur; | |
413 state = state_encoded_text; | |
8976 | 414 } else if (*cur == '?') { /* empty string */ |
415 encoded_text0 = cur; | |
416 state = state_question4; | |
8958 | 417 } else { /* This should never happen */ |
418 RECOVER_MARKED_TEXT; | |
419 state = state_start; | |
7858 | 420 } |
8958 | 421 break; |
422 case state_encoded_text: | |
423 if (*cur == '?') { | |
424 state = state_question4; | |
425 } else if (!encoded_text_char_p(*cur)) { | |
426 RECOVER_MARKED_TEXT; | |
427 state = state_start; | |
428 } | |
429 break; | |
430 case state_question4: | |
431 if (*cur == '=') { /* Got the whole encoded-word */ | |
432 char *charset = g_strndup(charset0, encoding0 - charset0 - 1); | |
433 char *encoding = g_strndup(encoding0, encoded_text0 - encoding0 - 1); | |
434 char *encoded_text = g_strndup(encoded_text0, cur - encoded_text0 - 1); | |
11137 | 435 guchar *decoded = NULL; |
11127 | 436 gsize dec_len; |
8958 | 437 if (g_ascii_strcasecmp(encoding, "Q") == 0) |
11132 | 438 decoded = gaim_quotedp_decode(encoded_text, &dec_len); |
8958 | 439 else if (g_ascii_strcasecmp(encoding, "B") == 0) |
11127 | 440 decoded = gaim_base64_decode(encoded_text, &dec_len); |
8958 | 441 else |
442 decoded = NULL; | |
443 if (decoded) { | |
444 gsize len; | |
11132 | 445 char *converted = g_convert((const gchar *)decoded, dec_len, "utf-8", charset, NULL, &len, NULL); |
8958 | 446 |
447 if (converted) { | |
448 n = strncpy(n, converted, len) + len; | |
449 g_free(converted); | |
450 } | |
451 g_free(decoded); | |
7858 | 452 } |
8958 | 453 g_free(charset); |
454 g_free(encoding); | |
455 g_free(encoded_text); | |
456 state = state_equal2; /* Restart the FSM */ | |
457 } else { /* This should never happen */ | |
458 RECOVER_MARKED_TEXT; | |
459 state = state_start; | |
7858 | 460 } |
8958 | 461 break; |
462 default: | |
463 if (*cur == '=') { | |
464 mark = cur; | |
465 state = state_equal1; | |
466 } else { | |
467 /* Some unencoded text. */ | |
468 *n = *cur; | |
469 n += 1; | |
470 } | |
471 break; | |
472 } /* switch */ | |
473 } /* for */ | |
474 | |
475 if (state != state_start) { | |
476 RECOVER_MARKED_TEXT; | |
7858 | 477 } |
478 *n = '\0'; | |
479 | |
480 return new; | |
7840 | 481 } |
7824 | 482 |
7679 | 483 |
7108
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
484 /************************************************************************** |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
485 * Date/Time Functions |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
486 **************************************************************************/ |
13152
4bb701a8736f
[gaim-migrate @ 15515]
Richard Laager <rlaager@wiktel.com>
parents:
13120
diff
changeset
|
487 |
13426
47e51939c923
[gaim-migrate @ 15801]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13399
diff
changeset
|
488 #ifdef _WIN32 |
47e51939c923
[gaim-migrate @ 15801]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13399
diff
changeset
|
489 static long win32_get_tz_offset() { |
47e51939c923
[gaim-migrate @ 15801]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13399
diff
changeset
|
490 TIME_ZONE_INFORMATION tzi; |
47e51939c923
[gaim-migrate @ 15801]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13399
diff
changeset
|
491 DWORD ret; |
47e51939c923
[gaim-migrate @ 15801]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13399
diff
changeset
|
492 long off = -1; |
47e51939c923
[gaim-migrate @ 15801]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13399
diff
changeset
|
493 |
47e51939c923
[gaim-migrate @ 15801]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13399
diff
changeset
|
494 if ((ret = GetTimeZoneInformation(&tzi)) != TIME_ZONE_ID_INVALID) |
47e51939c923
[gaim-migrate @ 15801]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13399
diff
changeset
|
495 { |
47e51939c923
[gaim-migrate @ 15801]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13399
diff
changeset
|
496 off = -(tzi.Bias * 60); |
47e51939c923
[gaim-migrate @ 15801]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13399
diff
changeset
|
497 if (ret == TIME_ZONE_ID_DAYLIGHT) |
47e51939c923
[gaim-migrate @ 15801]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13399
diff
changeset
|
498 off -= tzi.DaylightBias * 60; |
47e51939c923
[gaim-migrate @ 15801]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13399
diff
changeset
|
499 } |
47e51939c923
[gaim-migrate @ 15801]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13399
diff
changeset
|
500 |
47e51939c923
[gaim-migrate @ 15801]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13399
diff
changeset
|
501 return off; |
47e51939c923
[gaim-migrate @ 15801]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13399
diff
changeset
|
502 } |
47e51939c923
[gaim-migrate @ 15801]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13399
diff
changeset
|
503 #endif |
47e51939c923
[gaim-migrate @ 15801]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13399
diff
changeset
|
504 |
13152
4bb701a8736f
[gaim-migrate @ 15515]
Richard Laager <rlaager@wiktel.com>
parents:
13120
diff
changeset
|
505 #ifndef HAVE_STRFTIME_Z_FORMAT |
4bb701a8736f
[gaim-migrate @ 15515]
Richard Laager <rlaager@wiktel.com>
parents:
13120
diff
changeset
|
506 static const char *get_tmoff(const struct tm *tm) |
4bb701a8736f
[gaim-migrate @ 15515]
Richard Laager <rlaager@wiktel.com>
parents:
13120
diff
changeset
|
507 { |
4bb701a8736f
[gaim-migrate @ 15515]
Richard Laager <rlaager@wiktel.com>
parents:
13120
diff
changeset
|
508 static char buf[6]; |
4bb701a8736f
[gaim-migrate @ 15515]
Richard Laager <rlaager@wiktel.com>
parents:
13120
diff
changeset
|
509 long off; |
4bb701a8736f
[gaim-migrate @ 15515]
Richard Laager <rlaager@wiktel.com>
parents:
13120
diff
changeset
|
510 gint8 min; |
4bb701a8736f
[gaim-migrate @ 15515]
Richard Laager <rlaager@wiktel.com>
parents:
13120
diff
changeset
|
511 gint8 hrs; |
4bb701a8736f
[gaim-migrate @ 15515]
Richard Laager <rlaager@wiktel.com>
parents:
13120
diff
changeset
|
512 struct tm new_tm = *tm; |
4bb701a8736f
[gaim-migrate @ 15515]
Richard Laager <rlaager@wiktel.com>
parents:
13120
diff
changeset
|
513 |
4bb701a8736f
[gaim-migrate @ 15515]
Richard Laager <rlaager@wiktel.com>
parents:
13120
diff
changeset
|
514 mktime(&new_tm); |
4bb701a8736f
[gaim-migrate @ 15515]
Richard Laager <rlaager@wiktel.com>
parents:
13120
diff
changeset
|
515 |
4bb701a8736f
[gaim-migrate @ 15515]
Richard Laager <rlaager@wiktel.com>
parents:
13120
diff
changeset
|
516 if (new_tm.tm_isdst < 0) |
4bb701a8736f
[gaim-migrate @ 15515]
Richard Laager <rlaager@wiktel.com>
parents:
13120
diff
changeset
|
517 g_return_val_if_reached(""); |
4bb701a8736f
[gaim-migrate @ 15515]
Richard Laager <rlaager@wiktel.com>
parents:
13120
diff
changeset
|
518 |
4bb701a8736f
[gaim-migrate @ 15515]
Richard Laager <rlaager@wiktel.com>
parents:
13120
diff
changeset
|
519 #ifdef _WIN32 |
13426
47e51939c923
[gaim-migrate @ 15801]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13399
diff
changeset
|
520 if ((off = win32_get_tz_offset()) == -1) |
47e51939c923
[gaim-migrate @ 15801]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13399
diff
changeset
|
521 return ""; |
13152
4bb701a8736f
[gaim-migrate @ 15515]
Richard Laager <rlaager@wiktel.com>
parents:
13120
diff
changeset
|
522 #else |
4bb701a8736f
[gaim-migrate @ 15515]
Richard Laager <rlaager@wiktel.com>
parents:
13120
diff
changeset
|
523 # ifdef HAVE_TM_GMTOFF |
4bb701a8736f
[gaim-migrate @ 15515]
Richard Laager <rlaager@wiktel.com>
parents:
13120
diff
changeset
|
524 off = new_tm.tm_gmtoff; |
4bb701a8736f
[gaim-migrate @ 15515]
Richard Laager <rlaager@wiktel.com>
parents:
13120
diff
changeset
|
525 # else |
4bb701a8736f
[gaim-migrate @ 15515]
Richard Laager <rlaager@wiktel.com>
parents:
13120
diff
changeset
|
526 # ifdef HAVE_TIMEZONE |
4bb701a8736f
[gaim-migrate @ 15515]
Richard Laager <rlaager@wiktel.com>
parents:
13120
diff
changeset
|
527 tzset(); |
4bb701a8736f
[gaim-migrate @ 15515]
Richard Laager <rlaager@wiktel.com>
parents:
13120
diff
changeset
|
528 off = -timezone; |
4bb701a8736f
[gaim-migrate @ 15515]
Richard Laager <rlaager@wiktel.com>
parents:
13120
diff
changeset
|
529 # endif /* HAVE_TIMEZONE */ |
4bb701a8736f
[gaim-migrate @ 15515]
Richard Laager <rlaager@wiktel.com>
parents:
13120
diff
changeset
|
530 # endif /* !HAVE_TM_GMTOFF */ |
4bb701a8736f
[gaim-migrate @ 15515]
Richard Laager <rlaager@wiktel.com>
parents:
13120
diff
changeset
|
531 #endif /* _WIN32 */ |
4bb701a8736f
[gaim-migrate @ 15515]
Richard Laager <rlaager@wiktel.com>
parents:
13120
diff
changeset
|
532 |
4bb701a8736f
[gaim-migrate @ 15515]
Richard Laager <rlaager@wiktel.com>
parents:
13120
diff
changeset
|
533 min = (off / 60) % 60; |
4bb701a8736f
[gaim-migrate @ 15515]
Richard Laager <rlaager@wiktel.com>
parents:
13120
diff
changeset
|
534 hrs = ((off / 60) - min) / 60; |
4bb701a8736f
[gaim-migrate @ 15515]
Richard Laager <rlaager@wiktel.com>
parents:
13120
diff
changeset
|
535 |
4bb701a8736f
[gaim-migrate @ 15515]
Richard Laager <rlaager@wiktel.com>
parents:
13120
diff
changeset
|
536 if (g_snprintf(buf, sizeof(buf), "%+03d%02d", hrs, ABS(min)) > 5) |
4bb701a8736f
[gaim-migrate @ 15515]
Richard Laager <rlaager@wiktel.com>
parents:
13120
diff
changeset
|
537 g_return_val_if_reached(""); |
4bb701a8736f
[gaim-migrate @ 15515]
Richard Laager <rlaager@wiktel.com>
parents:
13120
diff
changeset
|
538 |
4bb701a8736f
[gaim-migrate @ 15515]
Richard Laager <rlaager@wiktel.com>
parents:
13120
diff
changeset
|
539 return buf; |
4bb701a8736f
[gaim-migrate @ 15515]
Richard Laager <rlaager@wiktel.com>
parents:
13120
diff
changeset
|
540 } |
13333
b04212d6b115
[gaim-migrate @ 15703]
Richard Laager <rlaager@wiktel.com>
parents:
13307
diff
changeset
|
541 #endif |
b04212d6b115
[gaim-migrate @ 15703]
Richard Laager <rlaager@wiktel.com>
parents:
13307
diff
changeset
|
542 |
b04212d6b115
[gaim-migrate @ 15703]
Richard Laager <rlaager@wiktel.com>
parents:
13307
diff
changeset
|
543 /* Windows doesn't HAVE_STRFTIME_Z_FORMAT, but this seems clearer. -- rlaager */ |
b04212d6b115
[gaim-migrate @ 15703]
Richard Laager <rlaager@wiktel.com>
parents:
13307
diff
changeset
|
544 #if !defined(HAVE_STRFTIME_Z_FORMAT) || defined(_WIN32) |
13152
4bb701a8736f
[gaim-migrate @ 15515]
Richard Laager <rlaager@wiktel.com>
parents:
13120
diff
changeset
|
545 static size_t gaim_internal_strftime(char *s, size_t max, const char *format, const struct tm *tm) |
4bb701a8736f
[gaim-migrate @ 15515]
Richard Laager <rlaager@wiktel.com>
parents:
13120
diff
changeset
|
546 { |
4bb701a8736f
[gaim-migrate @ 15515]
Richard Laager <rlaager@wiktel.com>
parents:
13120
diff
changeset
|
547 const char *start; |
4bb701a8736f
[gaim-migrate @ 15515]
Richard Laager <rlaager@wiktel.com>
parents:
13120
diff
changeset
|
548 const char *c; |
4bb701a8736f
[gaim-migrate @ 15515]
Richard Laager <rlaager@wiktel.com>
parents:
13120
diff
changeset
|
549 char *fmt = NULL; |
4bb701a8736f
[gaim-migrate @ 15515]
Richard Laager <rlaager@wiktel.com>
parents:
13120
diff
changeset
|
550 |
4bb701a8736f
[gaim-migrate @ 15515]
Richard Laager <rlaager@wiktel.com>
parents:
13120
diff
changeset
|
551 /* Yes, this is checked in gaim_utf8_strftime(), |
4bb701a8736f
[gaim-migrate @ 15515]
Richard Laager <rlaager@wiktel.com>
parents:
13120
diff
changeset
|
552 * but better safe than sorry. -- rlaager */ |
4bb701a8736f
[gaim-migrate @ 15515]
Richard Laager <rlaager@wiktel.com>
parents:
13120
diff
changeset
|
553 g_return_val_if_fail(format != NULL, 0); |
4bb701a8736f
[gaim-migrate @ 15515]
Richard Laager <rlaager@wiktel.com>
parents:
13120
diff
changeset
|
554 |
4bb701a8736f
[gaim-migrate @ 15515]
Richard Laager <rlaager@wiktel.com>
parents:
13120
diff
changeset
|
555 /* This is fairly efficient, and it only gets |
13333
b04212d6b115
[gaim-migrate @ 15703]
Richard Laager <rlaager@wiktel.com>
parents:
13307
diff
changeset
|
556 * executed on Windows or if the underlying |
b04212d6b115
[gaim-migrate @ 15703]
Richard Laager <rlaager@wiktel.com>
parents:
13307
diff
changeset
|
557 * system doesn't support the %z format string, |
b04212d6b115
[gaim-migrate @ 15703]
Richard Laager <rlaager@wiktel.com>
parents:
13307
diff
changeset
|
558 * for strftime() so I think it's good enough. |
b04212d6b115
[gaim-migrate @ 15703]
Richard Laager <rlaager@wiktel.com>
parents:
13307
diff
changeset
|
559 * -- rlaager */ |
13152
4bb701a8736f
[gaim-migrate @ 15515]
Richard Laager <rlaager@wiktel.com>
parents:
13120
diff
changeset
|
560 for (c = start = format; *c ; c++) |
4bb701a8736f
[gaim-migrate @ 15515]
Richard Laager <rlaager@wiktel.com>
parents:
13120
diff
changeset
|
561 { |
4bb701a8736f
[gaim-migrate @ 15515]
Richard Laager <rlaager@wiktel.com>
parents:
13120
diff
changeset
|
562 if (*c != '%') |
4bb701a8736f
[gaim-migrate @ 15515]
Richard Laager <rlaager@wiktel.com>
parents:
13120
diff
changeset
|
563 continue; |
4bb701a8736f
[gaim-migrate @ 15515]
Richard Laager <rlaager@wiktel.com>
parents:
13120
diff
changeset
|
564 |
4bb701a8736f
[gaim-migrate @ 15515]
Richard Laager <rlaager@wiktel.com>
parents:
13120
diff
changeset
|
565 c++; |
4bb701a8736f
[gaim-migrate @ 15515]
Richard Laager <rlaager@wiktel.com>
parents:
13120
diff
changeset
|
566 |
13333
b04212d6b115
[gaim-migrate @ 15703]
Richard Laager <rlaager@wiktel.com>
parents:
13307
diff
changeset
|
567 #ifndef HAVE_STRFTIME_Z_FORMAT |
13152
4bb701a8736f
[gaim-migrate @ 15515]
Richard Laager <rlaager@wiktel.com>
parents:
13120
diff
changeset
|
568 if (*c == 'z') |
4bb701a8736f
[gaim-migrate @ 15515]
Richard Laager <rlaager@wiktel.com>
parents:
13120
diff
changeset
|
569 { |
4bb701a8736f
[gaim-migrate @ 15515]
Richard Laager <rlaager@wiktel.com>
parents:
13120
diff
changeset
|
570 char *tmp = g_strdup_printf("%s%.*s%s", |
4bb701a8736f
[gaim-migrate @ 15515]
Richard Laager <rlaager@wiktel.com>
parents:
13120
diff
changeset
|
571 fmt ? fmt : "", |
4bb701a8736f
[gaim-migrate @ 15515]
Richard Laager <rlaager@wiktel.com>
parents:
13120
diff
changeset
|
572 c - start - 1, |
4bb701a8736f
[gaim-migrate @ 15515]
Richard Laager <rlaager@wiktel.com>
parents:
13120
diff
changeset
|
573 start, |
4bb701a8736f
[gaim-migrate @ 15515]
Richard Laager <rlaager@wiktel.com>
parents:
13120
diff
changeset
|
574 get_tmoff(tm)); |
4bb701a8736f
[gaim-migrate @ 15515]
Richard Laager <rlaager@wiktel.com>
parents:
13120
diff
changeset
|
575 g_free(fmt); |
4bb701a8736f
[gaim-migrate @ 15515]
Richard Laager <rlaager@wiktel.com>
parents:
13120
diff
changeset
|
576 fmt = tmp; |
4bb701a8736f
[gaim-migrate @ 15515]
Richard Laager <rlaager@wiktel.com>
parents:
13120
diff
changeset
|
577 start = c + 1; |
4bb701a8736f
[gaim-migrate @ 15515]
Richard Laager <rlaager@wiktel.com>
parents:
13120
diff
changeset
|
578 } |
13333
b04212d6b115
[gaim-migrate @ 15703]
Richard Laager <rlaager@wiktel.com>
parents:
13307
diff
changeset
|
579 #endif |
b04212d6b115
[gaim-migrate @ 15703]
Richard Laager <rlaager@wiktel.com>
parents:
13307
diff
changeset
|
580 #ifdef _WIN32 |
b04212d6b115
[gaim-migrate @ 15703]
Richard Laager <rlaager@wiktel.com>
parents:
13307
diff
changeset
|
581 if (*c == 'Z') |
b04212d6b115
[gaim-migrate @ 15703]
Richard Laager <rlaager@wiktel.com>
parents:
13307
diff
changeset
|
582 { |
b04212d6b115
[gaim-migrate @ 15703]
Richard Laager <rlaager@wiktel.com>
parents:
13307
diff
changeset
|
583 char *tmp = g_strdup_printf("%s%.*s%s", |
b04212d6b115
[gaim-migrate @ 15703]
Richard Laager <rlaager@wiktel.com>
parents:
13307
diff
changeset
|
584 fmt ? fmt : "", |
b04212d6b115
[gaim-migrate @ 15703]
Richard Laager <rlaager@wiktel.com>
parents:
13307
diff
changeset
|
585 c - start - 1, |
b04212d6b115
[gaim-migrate @ 15703]
Richard Laager <rlaager@wiktel.com>
parents:
13307
diff
changeset
|
586 start, |
b04212d6b115
[gaim-migrate @ 15703]
Richard Laager <rlaager@wiktel.com>
parents:
13307
diff
changeset
|
587 wgaim_get_timezone_abbreviation(tm)); |
b04212d6b115
[gaim-migrate @ 15703]
Richard Laager <rlaager@wiktel.com>
parents:
13307
diff
changeset
|
588 g_free(fmt); |
b04212d6b115
[gaim-migrate @ 15703]
Richard Laager <rlaager@wiktel.com>
parents:
13307
diff
changeset
|
589 fmt = tmp; |
b04212d6b115
[gaim-migrate @ 15703]
Richard Laager <rlaager@wiktel.com>
parents:
13307
diff
changeset
|
590 start = c + 1; |
b04212d6b115
[gaim-migrate @ 15703]
Richard Laager <rlaager@wiktel.com>
parents:
13307
diff
changeset
|
591 } |
b04212d6b115
[gaim-migrate @ 15703]
Richard Laager <rlaager@wiktel.com>
parents:
13307
diff
changeset
|
592 #endif |
13152
4bb701a8736f
[gaim-migrate @ 15515]
Richard Laager <rlaager@wiktel.com>
parents:
13120
diff
changeset
|
593 } |
4bb701a8736f
[gaim-migrate @ 15515]
Richard Laager <rlaager@wiktel.com>
parents:
13120
diff
changeset
|
594 |
4bb701a8736f
[gaim-migrate @ 15515]
Richard Laager <rlaager@wiktel.com>
parents:
13120
diff
changeset
|
595 if (fmt != NULL) |
4bb701a8736f
[gaim-migrate @ 15515]
Richard Laager <rlaager@wiktel.com>
parents:
13120
diff
changeset
|
596 { |
4bb701a8736f
[gaim-migrate @ 15515]
Richard Laager <rlaager@wiktel.com>
parents:
13120
diff
changeset
|
597 size_t ret; |
4bb701a8736f
[gaim-migrate @ 15515]
Richard Laager <rlaager@wiktel.com>
parents:
13120
diff
changeset
|
598 |
4bb701a8736f
[gaim-migrate @ 15515]
Richard Laager <rlaager@wiktel.com>
parents:
13120
diff
changeset
|
599 if (*start) |
4bb701a8736f
[gaim-migrate @ 15515]
Richard Laager <rlaager@wiktel.com>
parents:
13120
diff
changeset
|
600 { |
4bb701a8736f
[gaim-migrate @ 15515]
Richard Laager <rlaager@wiktel.com>
parents:
13120
diff
changeset
|
601 char *tmp = g_strconcat(fmt, start, NULL); |
4bb701a8736f
[gaim-migrate @ 15515]
Richard Laager <rlaager@wiktel.com>
parents:
13120
diff
changeset
|
602 g_free(fmt); |
4bb701a8736f
[gaim-migrate @ 15515]
Richard Laager <rlaager@wiktel.com>
parents:
13120
diff
changeset
|
603 fmt = tmp; |
4bb701a8736f
[gaim-migrate @ 15515]
Richard Laager <rlaager@wiktel.com>
parents:
13120
diff
changeset
|
604 } |
4bb701a8736f
[gaim-migrate @ 15515]
Richard Laager <rlaager@wiktel.com>
parents:
13120
diff
changeset
|
605 |
4bb701a8736f
[gaim-migrate @ 15515]
Richard Laager <rlaager@wiktel.com>
parents:
13120
diff
changeset
|
606 ret = strftime(s, max, fmt, tm); |
4bb701a8736f
[gaim-migrate @ 15515]
Richard Laager <rlaager@wiktel.com>
parents:
13120
diff
changeset
|
607 g_free(fmt); |
4bb701a8736f
[gaim-migrate @ 15515]
Richard Laager <rlaager@wiktel.com>
parents:
13120
diff
changeset
|
608 |
4bb701a8736f
[gaim-migrate @ 15515]
Richard Laager <rlaager@wiktel.com>
parents:
13120
diff
changeset
|
609 return ret; |
4bb701a8736f
[gaim-migrate @ 15515]
Richard Laager <rlaager@wiktel.com>
parents:
13120
diff
changeset
|
610 } |
4bb701a8736f
[gaim-migrate @ 15515]
Richard Laager <rlaager@wiktel.com>
parents:
13120
diff
changeset
|
611 |
4bb701a8736f
[gaim-migrate @ 15515]
Richard Laager <rlaager@wiktel.com>
parents:
13120
diff
changeset
|
612 return strftime(s, max, format, tm); |
4bb701a8736f
[gaim-migrate @ 15515]
Richard Laager <rlaager@wiktel.com>
parents:
13120
diff
changeset
|
613 } |
13333
b04212d6b115
[gaim-migrate @ 15703]
Richard Laager <rlaager@wiktel.com>
parents:
13307
diff
changeset
|
614 #else /* HAVE_STRFTIME_Z_FORMAT && !_WIN32 */ |
13152
4bb701a8736f
[gaim-migrate @ 15515]
Richard Laager <rlaager@wiktel.com>
parents:
13120
diff
changeset
|
615 #define gaim_internal_strftime strftime |
4bb701a8736f
[gaim-migrate @ 15515]
Richard Laager <rlaager@wiktel.com>
parents:
13120
diff
changeset
|
616 #endif |
4bb701a8736f
[gaim-migrate @ 15515]
Richard Laager <rlaager@wiktel.com>
parents:
13120
diff
changeset
|
617 |
13104
e1e5462b7d81
[gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents:
13102
diff
changeset
|
618 const char * |
e1e5462b7d81
[gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents:
13102
diff
changeset
|
619 gaim_utf8_strftime(const char *format, const struct tm *tm) |
e1e5462b7d81
[gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents:
13102
diff
changeset
|
620 { |
e1e5462b7d81
[gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents:
13102
diff
changeset
|
621 static char buf[128]; |
13215
15b3926e2147
[gaim-migrate @ 15579]
Richard Laager <rlaager@wiktel.com>
parents:
13200
diff
changeset
|
622 char *locale; |
15b3926e2147
[gaim-migrate @ 15579]
Richard Laager <rlaager@wiktel.com>
parents:
13200
diff
changeset
|
623 GError *err = NULL; |
15b3926e2147
[gaim-migrate @ 15579]
Richard Laager <rlaager@wiktel.com>
parents:
13200
diff
changeset
|
624 int len; |
13104
e1e5462b7d81
[gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents:
13102
diff
changeset
|
625 char *utf8; |
e1e5462b7d81
[gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents:
13102
diff
changeset
|
626 |
13119
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13117
diff
changeset
|
627 g_return_val_if_fail(format != NULL, NULL); |
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13117
diff
changeset
|
628 |
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13117
diff
changeset
|
629 if (tm == NULL) |
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13117
diff
changeset
|
630 { |
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13117
diff
changeset
|
631 time_t now = time(NULL); |
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13117
diff
changeset
|
632 tm = localtime(&now); |
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13117
diff
changeset
|
633 } |
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13117
diff
changeset
|
634 |
13215
15b3926e2147
[gaim-migrate @ 15579]
Richard Laager <rlaager@wiktel.com>
parents:
13200
diff
changeset
|
635 locale = g_locale_from_utf8(format, -1, NULL, NULL, &err); |
15b3926e2147
[gaim-migrate @ 15579]
Richard Laager <rlaager@wiktel.com>
parents:
13200
diff
changeset
|
636 if (err != NULL) |
15b3926e2147
[gaim-migrate @ 15579]
Richard Laager <rlaager@wiktel.com>
parents:
13200
diff
changeset
|
637 { |
15b3926e2147
[gaim-migrate @ 15579]
Richard Laager <rlaager@wiktel.com>
parents:
13200
diff
changeset
|
638 gaim_debug_error("util", "Format conversion failed in gaim_utf8_strftime(): %s", err->message); |
15b3926e2147
[gaim-migrate @ 15579]
Richard Laager <rlaager@wiktel.com>
parents:
13200
diff
changeset
|
639 g_error_free(err); |
15b3926e2147
[gaim-migrate @ 15579]
Richard Laager <rlaager@wiktel.com>
parents:
13200
diff
changeset
|
640 locale = g_strdup(format); |
15b3926e2147
[gaim-migrate @ 15579]
Richard Laager <rlaager@wiktel.com>
parents:
13200
diff
changeset
|
641 } |
15b3926e2147
[gaim-migrate @ 15579]
Richard Laager <rlaager@wiktel.com>
parents:
13200
diff
changeset
|
642 |
13115
e42983a1038c
[gaim-migrate @ 15477]
Richard Laager <rlaager@wiktel.com>
parents:
13104
diff
changeset
|
643 /* A return value of 0 is either an error (in |
e42983a1038c
[gaim-migrate @ 15477]
Richard Laager <rlaager@wiktel.com>
parents:
13104
diff
changeset
|
644 * which case, the contents of the buffer are |
e42983a1038c
[gaim-migrate @ 15477]
Richard Laager <rlaager@wiktel.com>
parents:
13104
diff
changeset
|
645 * undefined) or the empty string (in which |
e42983a1038c
[gaim-migrate @ 15477]
Richard Laager <rlaager@wiktel.com>
parents:
13104
diff
changeset
|
646 * case, no harm is done here). */ |
13215
15b3926e2147
[gaim-migrate @ 15579]
Richard Laager <rlaager@wiktel.com>
parents:
13200
diff
changeset
|
647 if ((len = gaim_internal_strftime(buf, sizeof(buf), locale, tm)) == 0) |
13115
e42983a1038c
[gaim-migrate @ 15477]
Richard Laager <rlaager@wiktel.com>
parents:
13104
diff
changeset
|
648 { |
13215
15b3926e2147
[gaim-migrate @ 15579]
Richard Laager <rlaager@wiktel.com>
parents:
13200
diff
changeset
|
649 g_free(locale); |
15b3926e2147
[gaim-migrate @ 15579]
Richard Laager <rlaager@wiktel.com>
parents:
13200
diff
changeset
|
650 return ""; |
13115
e42983a1038c
[gaim-migrate @ 15477]
Richard Laager <rlaager@wiktel.com>
parents:
13104
diff
changeset
|
651 } |
13104
e1e5462b7d81
[gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents:
13102
diff
changeset
|
652 |
13307 | 653 g_free(locale); |
654 | |
13215
15b3926e2147
[gaim-migrate @ 15579]
Richard Laager <rlaager@wiktel.com>
parents:
13200
diff
changeset
|
655 utf8 = g_locale_to_utf8(buf, len, NULL, NULL, &err); |
15b3926e2147
[gaim-migrate @ 15579]
Richard Laager <rlaager@wiktel.com>
parents:
13200
diff
changeset
|
656 if (err != NULL) |
15b3926e2147
[gaim-migrate @ 15579]
Richard Laager <rlaager@wiktel.com>
parents:
13200
diff
changeset
|
657 { |
15b3926e2147
[gaim-migrate @ 15579]
Richard Laager <rlaager@wiktel.com>
parents:
13200
diff
changeset
|
658 gaim_debug_error("util", "Result conversion failed in gaim_utf8_strftime(): %s", err->message); |
15b3926e2147
[gaim-migrate @ 15579]
Richard Laager <rlaager@wiktel.com>
parents:
13200
diff
changeset
|
659 g_error_free(err); |
15b3926e2147
[gaim-migrate @ 15579]
Richard Laager <rlaager@wiktel.com>
parents:
13200
diff
changeset
|
660 } |
15b3926e2147
[gaim-migrate @ 15579]
Richard Laager <rlaager@wiktel.com>
parents:
13200
diff
changeset
|
661 else |
13104
e1e5462b7d81
[gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents:
13102
diff
changeset
|
662 { |
e1e5462b7d81
[gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents:
13102
diff
changeset
|
663 gaim_strlcpy(buf, utf8); |
e1e5462b7d81
[gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents:
13102
diff
changeset
|
664 g_free(utf8); |
e1e5462b7d81
[gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents:
13102
diff
changeset
|
665 } |
e1e5462b7d81
[gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents:
13102
diff
changeset
|
666 |
e1e5462b7d81
[gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents:
13102
diff
changeset
|
667 return buf; |
e1e5462b7d81
[gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents:
13102
diff
changeset
|
668 } |
e1e5462b7d81
[gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents:
13102
diff
changeset
|
669 |
e1e5462b7d81
[gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents:
13102
diff
changeset
|
670 const char * |
e1e5462b7d81
[gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents:
13102
diff
changeset
|
671 gaim_date_format_short(const struct tm *tm) |
e1e5462b7d81
[gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents:
13102
diff
changeset
|
672 { |
e1e5462b7d81
[gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents:
13102
diff
changeset
|
673 return gaim_utf8_strftime("%x", tm); |
e1e5462b7d81
[gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents:
13102
diff
changeset
|
674 } |
e1e5462b7d81
[gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents:
13102
diff
changeset
|
675 |
e1e5462b7d81
[gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents:
13102
diff
changeset
|
676 const char * |
e1e5462b7d81
[gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents:
13102
diff
changeset
|
677 gaim_date_format_long(const struct tm *tm) |
e1e5462b7d81
[gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents:
13102
diff
changeset
|
678 { |
e1e5462b7d81
[gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents:
13102
diff
changeset
|
679 return gaim_utf8_strftime(_("%x %X"), tm); |
e1e5462b7d81
[gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents:
13102
diff
changeset
|
680 } |
e1e5462b7d81
[gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents:
13102
diff
changeset
|
681 |
e1e5462b7d81
[gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents:
13102
diff
changeset
|
682 const char * |
13119
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13117
diff
changeset
|
683 gaim_date_format_full(const struct tm *tm) |
13104
e1e5462b7d81
[gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents:
13102
diff
changeset
|
684 { |
13119
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13117
diff
changeset
|
685 return gaim_utf8_strftime("%c", tm); |
13104
e1e5462b7d81
[gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents:
13102
diff
changeset
|
686 } |
e1e5462b7d81
[gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents:
13102
diff
changeset
|
687 |
e1e5462b7d81
[gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents:
13102
diff
changeset
|
688 const char * |
e1e5462b7d81
[gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents:
13102
diff
changeset
|
689 gaim_time_format(const struct tm *tm) |
e1e5462b7d81
[gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents:
13102
diff
changeset
|
690 { |
e1e5462b7d81
[gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents:
13102
diff
changeset
|
691 return gaim_utf8_strftime("%X", tm); |
e1e5462b7d81
[gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents:
13102
diff
changeset
|
692 } |
3630 | 693 |
7108
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
694 time_t |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
695 gaim_time_build(int year, int month, int day, int hour, int min, int sec) |
1805
caa605e70917
[gaim-migrate @ 1815]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1753
diff
changeset
|
696 { |
caa605e70917
[gaim-migrate @ 1815]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1753
diff
changeset
|
697 struct tm tm; |
caa605e70917
[gaim-migrate @ 1815]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1753
diff
changeset
|
698 |
caa605e70917
[gaim-migrate @ 1815]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1753
diff
changeset
|
699 tm.tm_year = year - 1900; |
caa605e70917
[gaim-migrate @ 1815]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1753
diff
changeset
|
700 tm.tm_mon = month - 1; |
caa605e70917
[gaim-migrate @ 1815]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1753
diff
changeset
|
701 tm.tm_mday = day; |
caa605e70917
[gaim-migrate @ 1815]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1753
diff
changeset
|
702 tm.tm_hour = hour; |
caa605e70917
[gaim-migrate @ 1815]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1753
diff
changeset
|
703 tm.tm_min = min; |
caa605e70917
[gaim-migrate @ 1815]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1753
diff
changeset
|
704 tm.tm_sec = sec >= 0 ? sec : time(NULL) % 60; |
7108
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
705 |
1805
caa605e70917
[gaim-migrate @ 1815]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1753
diff
changeset
|
706 return mktime(&tm); |
caa605e70917
[gaim-migrate @ 1815]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1753
diff
changeset
|
707 } |
3230 | 708 |
8577 | 709 time_t |
13119
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13117
diff
changeset
|
710 gaim_str_to_time(const char *timestamp, gboolean utc, |
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13117
diff
changeset
|
711 struct tm *tm, long *tz_off, const char **rest) |
8577 | 712 { |
9722 | 713 time_t retval = 0; |
9716 | 714 struct tm *t; |
13119
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13117
diff
changeset
|
715 const char *c = timestamp; |
13104
e1e5462b7d81
[gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents:
13102
diff
changeset
|
716 int year = 0; |
13119
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13117
diff
changeset
|
717 long tzoff = GAIM_NO_TZ_OFF; |
9716 | 718 |
719 time(&retval); | |
720 t = localtime(&retval); | |
721 | |
722 /* 4 digit year */ | |
13104
e1e5462b7d81
[gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents:
13102
diff
changeset
|
723 if (sscanf(c, "%04d", &year) && year > 1900) |
e1e5462b7d81
[gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents:
13102
diff
changeset
|
724 { |
e1e5462b7d81
[gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents:
13102
diff
changeset
|
725 c += 4; |
e1e5462b7d81
[gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents:
13102
diff
changeset
|
726 if (*c == '-') |
e1e5462b7d81
[gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents:
13102
diff
changeset
|
727 c++; |
13117
d9d15ec284ca
[gaim-migrate @ 15479]
Richard Laager <rlaager@wiktel.com>
parents:
13116
diff
changeset
|
728 t->tm_year = year - 1900; |
13104
e1e5462b7d81
[gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents:
13102
diff
changeset
|
729 } |
8577 | 730 |
731 /* 2 digit month */ | |
13104
e1e5462b7d81
[gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents:
13102
diff
changeset
|
732 if (!sscanf(c, "%02d", &t->tm_mon)) |
13119
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13117
diff
changeset
|
733 { |
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13117
diff
changeset
|
734 if (rest != NULL && *c != '\0') |
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13117
diff
changeset
|
735 *rest = c; |
13104
e1e5462b7d81
[gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents:
13102
diff
changeset
|
736 return 0; |
13119
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13117
diff
changeset
|
737 } |
9716 | 738 c += 2; |
13104
e1e5462b7d81
[gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents:
13102
diff
changeset
|
739 if (*c == '-' || *c == '/') |
8577 | 740 c++; |
9716 | 741 t->tm_mon -= 1; |
742 | |
743 /* 2 digit day */ | |
13104
e1e5462b7d81
[gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents:
13102
diff
changeset
|
744 if (!sscanf(c, "%02d", &t->tm_mday)) |
13119
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13117
diff
changeset
|
745 { |
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13117
diff
changeset
|
746 if (rest != NULL && *c != '\0') |
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13117
diff
changeset
|
747 *rest = c; |
13104
e1e5462b7d81
[gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents:
13102
diff
changeset
|
748 return 0; |
13119
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13117
diff
changeset
|
749 } |
9716 | 750 c += 2; |
13104
e1e5462b7d81
[gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents:
13102
diff
changeset
|
751 if (*c == '/') |
e1e5462b7d81
[gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents:
13102
diff
changeset
|
752 { |
e1e5462b7d81
[gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents:
13102
diff
changeset
|
753 c++; |
e1e5462b7d81
[gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents:
13102
diff
changeset
|
754 |
e1e5462b7d81
[gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents:
13102
diff
changeset
|
755 if (!sscanf(c, "%04d", &t->tm_year)) |
13119
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13117
diff
changeset
|
756 { |
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13117
diff
changeset
|
757 if (rest != NULL && *c != '\0') |
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13117
diff
changeset
|
758 *rest = c; |
13464
974fffde9f60
[gaim-migrate @ 15839]
Richard Laager <rlaager@wiktel.com>
parents:
13443
diff
changeset
|
759 return 0; |
13119
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13117
diff
changeset
|
760 } |
13104
e1e5462b7d81
[gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents:
13102
diff
changeset
|
761 t->tm_year -= 1900; |
e1e5462b7d81
[gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents:
13102
diff
changeset
|
762 } |
13119
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13117
diff
changeset
|
763 else if (*c == 'T' || *c == '.') |
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13117
diff
changeset
|
764 { |
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13117
diff
changeset
|
765 c++; |
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13117
diff
changeset
|
766 /* we have more than a date, keep going */ |
9725 | 767 |
768 /* 2 digit hour */ | |
13119
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13117
diff
changeset
|
769 if ((sscanf(c, "%02d:%02d:%02d", &t->tm_hour, &t->tm_min, &t->tm_sec) == 3 && (c = c + 8)) || |
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13117
diff
changeset
|
770 (sscanf(c, "%02d%02d%02d", &t->tm_hour, &t->tm_min, &t->tm_sec) == 3 && (c = c + 6))) |
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13117
diff
changeset
|
771 { |
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13117
diff
changeset
|
772 gboolean offset_positive = FALSE; |
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13117
diff
changeset
|
773 int tzhrs; |
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13117
diff
changeset
|
774 int tzmins; |
9716 | 775 |
10876 | 776 t->tm_isdst = -1; |
777 | |
13119
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13117
diff
changeset
|
778 if (*c == '.' && *(c+1) >= '0' && *(c+1) <= '9') /* dealing with precision we don't care about */ |
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13117
diff
changeset
|
779 c += 4; |
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13117
diff
changeset
|
780 if (*c == '+') |
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13117
diff
changeset
|
781 offset_positive = TRUE; |
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13117
diff
changeset
|
782 if (((*c == '+' || *c == '-') && (c = c + 1)) && |
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13117
diff
changeset
|
783 ((sscanf(c, "%02d:%02d", &tzhrs, &tzmins) == 2 && (c = c + 5)) || |
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13117
diff
changeset
|
784 (sscanf(c, "%02d%02d", &tzhrs, &tzmins) == 2 && (c = c + 4)))) |
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13117
diff
changeset
|
785 { |
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13117
diff
changeset
|
786 tzoff = tzhrs*60*60 + tzmins*60; |
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13117
diff
changeset
|
787 if (offset_positive) |
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13117
diff
changeset
|
788 tzoff *= -1; |
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13117
diff
changeset
|
789 /* We don't want the C library doing DST calculations |
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13117
diff
changeset
|
790 * if we know the UTC offset already. */ |
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13117
diff
changeset
|
791 t->tm_isdst = 0; |
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13117
diff
changeset
|
792 } |
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13117
diff
changeset
|
793 |
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13117
diff
changeset
|
794 if (rest != NULL && *c != '\0') |
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13117
diff
changeset
|
795 { |
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13117
diff
changeset
|
796 if (*c == ' ') |
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13117
diff
changeset
|
797 c++; |
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13117
diff
changeset
|
798 if (*c != '\0') |
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13117
diff
changeset
|
799 *rest = c; |
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13117
diff
changeset
|
800 } |
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13117
diff
changeset
|
801 |
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13117
diff
changeset
|
802 if (tzoff != GAIM_NO_TZ_OFF || utc) |
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13117
diff
changeset
|
803 { |
13584
097ae11c67e0
[gaim-migrate @ 15966]
Richard Laager <rlaager@wiktel.com>
parents:
13520
diff
changeset
|
804 #if defined(_WIN32) |
097ae11c67e0
[gaim-migrate @ 15966]
Richard Laager <rlaager@wiktel.com>
parents:
13520
diff
changeset
|
805 long sys_tzoff; |
097ae11c67e0
[gaim-migrate @ 15966]
Richard Laager <rlaager@wiktel.com>
parents:
13520
diff
changeset
|
806 #endif |
097ae11c67e0
[gaim-migrate @ 15966]
Richard Laager <rlaager@wiktel.com>
parents:
13520
diff
changeset
|
807 |
13119
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13117
diff
changeset
|
808 #if defined(_WIN32) || defined(HAVE_TM_GMTOFF) || defined (HAVE_TIMEZONE) |
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13117
diff
changeset
|
809 if (tzoff == GAIM_NO_TZ_OFF) |
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13117
diff
changeset
|
810 tzoff = 0; |
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13117
diff
changeset
|
811 #endif |
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13117
diff
changeset
|
812 |
10987
a8a7730db73c
[gaim-migrate @ 12824]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10948
diff
changeset
|
813 #ifdef _WIN32 |
13584
097ae11c67e0
[gaim-migrate @ 15966]
Richard Laager <rlaager@wiktel.com>
parents:
13520
diff
changeset
|
814 if ((sys_tzoff = win32_get_tz_offset()) == -1) |
13119
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13117
diff
changeset
|
815 tzoff = GAIM_NO_TZ_OFF; |
13584
097ae11c67e0
[gaim-migrate @ 15966]
Richard Laager <rlaager@wiktel.com>
parents:
13520
diff
changeset
|
816 else |
097ae11c67e0
[gaim-migrate @ 15966]
Richard Laager <rlaager@wiktel.com>
parents:
13520
diff
changeset
|
817 tzoff += sys_tzoff; |
10987
a8a7730db73c
[gaim-migrate @ 12824]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10948
diff
changeset
|
818 #else |
8577 | 819 #ifdef HAVE_TM_GMTOFF |
9716 | 820 tzoff += t->tm_gmtoff; |
8577 | 821 #else |
9716 | 822 # ifdef HAVE_TIMEZONE |
823 tzset(); /* making sure */ | |
824 tzoff -= timezone; | |
825 # endif | |
8577 | 826 #endif |
10987
a8a7730db73c
[gaim-migrate @ 12824]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10948
diff
changeset
|
827 #endif /* _WIN32 */ |
8577 | 828 } |
9716 | 829 } |
13119
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13117
diff
changeset
|
830 else |
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13117
diff
changeset
|
831 { |
13399
18d5d4018604
[gaim-migrate @ 15773]
Richard Laager <rlaager@wiktel.com>
parents:
13367
diff
changeset
|
832 if (rest != NULL && *c != '\0') |
13119
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13117
diff
changeset
|
833 *rest = c; |
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13117
diff
changeset
|
834 } |
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13117
diff
changeset
|
835 } |
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13117
diff
changeset
|
836 |
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13117
diff
changeset
|
837 if (tm != NULL) |
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13117
diff
changeset
|
838 { |
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13117
diff
changeset
|
839 *tm = *t; |
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13117
diff
changeset
|
840 tm->tm_isdst = -1; |
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13117
diff
changeset
|
841 mktime(tm); |
9716 | 842 } |
843 | |
844 retval = mktime(t); | |
13119
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13117
diff
changeset
|
845 if (tzoff != GAIM_NO_TZ_OFF) |
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13117
diff
changeset
|
846 retval += tzoff; |
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13117
diff
changeset
|
847 |
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13117
diff
changeset
|
848 if (tz_off != NULL) |
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13117
diff
changeset
|
849 *tz_off = tzoff; |
9716 | 850 |
851 return retval; | |
8577 | 852 } |
853 | |
7108
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
854 /************************************************************************** |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
855 * Markup Functions |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
856 **************************************************************************/ |
7094
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
857 gboolean |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
858 gaim_markup_find_tag(const char *needle, const char *haystack, |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
859 const char **start, const char **end, GData **attributes) |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
860 { |
6982 | 861 GData *attribs; |
862 const char *cur = haystack; | |
863 char *name = NULL; | |
864 gboolean found = FALSE; | |
865 gboolean in_tag = FALSE; | |
866 gboolean in_attr = FALSE; | |
7094
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
867 const char *in_quotes = NULL; |
7804 | 868 size_t needlelen; |
6982 | 869 |
7804 | 870 g_return_val_if_fail( needle != NULL, FALSE); |
871 g_return_val_if_fail( *needle != '\0', FALSE); | |
872 g_return_val_if_fail( haystack != NULL, FALSE); | |
873 g_return_val_if_fail( *haystack != '\0', FALSE); | |
874 g_return_val_if_fail( start != NULL, FALSE); | |
875 g_return_val_if_fail( end != NULL, FALSE); | |
876 g_return_val_if_fail(attributes != NULL, FALSE); | |
877 | |
878 needlelen = strlen(needle); | |
6982 | 879 g_datalist_init(&attribs); |
880 | |
881 while (*cur && !found) { | |
882 if (in_tag) { | |
883 if (in_quotes) { | |
884 const char *close = cur; | |
885 | |
7078 | 886 while (*close && *close != *in_quotes) |
6982 | 887 close++; |
888 | |
889 /* if we got the close quote, store the value and carry on from * | |
890 * after it. if we ran to the end of the string, point to the NULL * | |
891 * and we're outta here */ | |
892 if (*close) { | |
893 /* only store a value if we have an attribute name */ | |
894 if (name) { | |
895 size_t len = close - cur; | |
896 char *val = g_strndup(cur, len); | |
897 | |
898 g_datalist_set_data_full(&attribs, name, val, g_free); | |
899 g_free(name); | |
900 name = NULL; | |
901 } | |
902 | |
7078 | 903 in_quotes = NULL; |
6982 | 904 cur = close + 1; |
905 } else { | |
906 cur = close; | |
907 } | |
908 } else if (in_attr) { | |
909 const char *close = cur; | |
910 | |
7078 | 911 while (*close && *close != '>' && *close != '"' && |
912 *close != '\'' && *close != ' ' && *close != '=') | |
6982 | 913 close++; |
914 | |
915 /* if we got the equals, store the name of the attribute. if we got | |
916 * the quote, save the attribute and go straight to quote mode. | |
917 * otherwise the tag closed or we reached the end of the string, | |
918 * so we can get outta here */ | |
919 switch (*close) { | |
920 case '"': | |
7078 | 921 case '\'': |
922 in_quotes = close; | |
6982 | 923 case '=': |
924 { | |
925 size_t len = close - cur; | |
926 | |
927 /* don't store a blank attribute name */ | |
928 if (len) { | |
929 if (name) | |
930 g_free(name); | |
931 name = g_ascii_strdown(cur, len); | |
932 } | |
933 | |
934 in_attr = FALSE; | |
935 cur = close + 1; | |
936 break; | |
937 } | |
938 case ' ': | |
939 case '>': | |
940 in_attr = FALSE; | |
941 default: | |
942 cur = close; | |
943 break; | |
944 } | |
945 } else { | |
946 switch (*cur) { | |
947 case ' ': | |
948 /* swallow extra spaces inside tag */ | |
949 while (*cur && *cur == ' ') cur++; | |
950 in_attr = TRUE; | |
951 break; | |
952 case '>': | |
953 found = TRUE; | |
954 *end = cur; | |
955 break; | |
956 case '"': | |
7078 | 957 case '\'': |
958 in_quotes = cur; | |
6982 | 959 default: |
960 cur++; | |
961 break; | |
962 } | |
963 } | |
964 } else { | |
965 /* if we hit a < followed by the name of our tag... */ | |
966 if (*cur == '<' && !g_ascii_strncasecmp(cur + 1, needle, needlelen)) { | |
967 *start = cur; | |
968 cur = cur + needlelen + 1; | |
969 | |
970 /* if we're pointing at a space or a >, we found the right tag. if * | |
971 * we're not, we've found a longer tag, so we need to skip to the * | |
972 * >, but not being distracted by >s inside quotes. */ | |
973 if (*cur == ' ' || *cur == '>') { | |
974 in_tag = TRUE; | |
975 } else { | |
7804 | 976 while (*cur && *cur != '"' && *cur != '\'' && *cur != '>') { |
6982 | 977 if (*cur == '"') { |
978 cur++; | |
979 while (*cur && *cur != '"') | |
980 cur++; | |
7804 | 981 } else if (*cur == '\'') { |
982 cur++; | |
983 while (*cur && *cur != '\'') | |
984 cur++; | |
6982 | 985 } else { |
986 cur++; | |
987 } | |
988 } | |
989 } | |
990 } else { | |
991 cur++; | |
992 } | |
993 } | |
994 } | |
995 | |
996 /* clean up any attribute name from a premature termination */ | |
997 if (name) | |
998 g_free(name); | |
999 | |
1000 if (found) { | |
1001 *attributes = attribs; | |
1002 } else { | |
1003 *start = NULL; | |
1004 *end = NULL; | |
1005 *attributes = NULL; | |
1006 } | |
1007 | |
1008 return found; | |
1009 } | |
7094
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
1010 |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
1011 gboolean |
7675 | 1012 gaim_markup_extract_info_field(const char *str, int len, GString *dest, |
7095
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1013 const char *start_token, int skip, |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1014 const char *end_token, char check_value, |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1015 const char *no_value_token, |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1016 const char *display_name, gboolean is_link, |
13104
e1e5462b7d81
[gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents:
13102
diff
changeset
|
1017 const char *link_prefix, |
e1e5462b7d81
[gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents:
13102
diff
changeset
|
1018 GaimInfoFieldFormatCallback format_cb) |
7095
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1019 { |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1020 const char *p, *q; |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1021 |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1022 g_return_val_if_fail(str != NULL, FALSE); |
7675 | 1023 g_return_val_if_fail(dest != NULL, FALSE); |
7095
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1024 g_return_val_if_fail(start_token != NULL, FALSE); |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1025 g_return_val_if_fail(end_token != NULL, FALSE); |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1026 g_return_val_if_fail(display_name != NULL, FALSE); |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1027 |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1028 p = strstr(str, start_token); |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1029 |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1030 if (p == NULL) |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1031 return FALSE; |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1032 |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1033 p += strlen(start_token) + skip; |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1034 |
7675 | 1035 if (p >= str + len) |
1036 return FALSE; | |
1037 | |
7095
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1038 if (check_value != '\0' && *p == check_value) |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1039 return FALSE; |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1040 |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1041 q = strstr(p, end_token); |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1042 |
9161 | 1043 /* Trim leading blanks */ |
1044 while (*p != '\n' && g_ascii_isspace(*p)) { | |
1045 p += 1; | |
1046 } | |
1047 | |
1048 /* Trim trailing blanks */ | |
1049 while (q > p && g_ascii_isspace(*(q - 1))) { | |
1050 q -= 1; | |
1051 } | |
1052 | |
1053 /* Don't bother with null strings */ | |
1054 if (p == q) | |
1055 return FALSE; | |
1056 | |
7095
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1057 if (q != NULL && (!no_value_token || |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1058 (no_value_token && strncmp(p, no_value_token, |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1059 strlen(no_value_token))))) |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1060 { |
9220 | 1061 g_string_append_printf(dest, _("<b>%s:</b> "), display_name); |
7095
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1062 |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1063 if (is_link) |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1064 { |
7675 | 1065 g_string_append(dest, "<br><a href=\""); |
7095
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1066 |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1067 if (link_prefix) |
7675 | 1068 g_string_append(dest, link_prefix); |
7095
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1069 |
13104
e1e5462b7d81
[gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents:
13102
diff
changeset
|
1070 if (format_cb != NULL) |
e1e5462b7d81
[gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents:
13102
diff
changeset
|
1071 { |
e1e5462b7d81
[gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents:
13102
diff
changeset
|
1072 char *reformatted = format_cb(p, q - p); |
e1e5462b7d81
[gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents:
13102
diff
changeset
|
1073 g_string_append(dest, reformatted); |
e1e5462b7d81
[gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents:
13102
diff
changeset
|
1074 g_free(reformatted); |
e1e5462b7d81
[gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents:
13102
diff
changeset
|
1075 } |
e1e5462b7d81
[gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents:
13102
diff
changeset
|
1076 else |
e1e5462b7d81
[gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents:
13102
diff
changeset
|
1077 g_string_append_len(dest, p, q - p); |
7675 | 1078 g_string_append(dest, "\">"); |
7095
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1079 |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1080 if (link_prefix) |
7675 | 1081 g_string_append(dest, link_prefix); |
7095
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1082 |
7675 | 1083 g_string_append_len(dest, p, q - p); |
1084 g_string_append(dest, "</a>"); | |
7095
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1085 } |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1086 else |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1087 { |
13104
e1e5462b7d81
[gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents:
13102
diff
changeset
|
1088 if (format_cb != NULL) |
e1e5462b7d81
[gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents:
13102
diff
changeset
|
1089 { |
e1e5462b7d81
[gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents:
13102
diff
changeset
|
1090 char *reformatted = format_cb(p, q - p); |
e1e5462b7d81
[gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents:
13102
diff
changeset
|
1091 g_string_append(dest, reformatted); |
e1e5462b7d81
[gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents:
13102
diff
changeset
|
1092 g_free(reformatted); |
e1e5462b7d81
[gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents:
13102
diff
changeset
|
1093 } |
e1e5462b7d81
[gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents:
13102
diff
changeset
|
1094 else |
e1e5462b7d81
[gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents:
13102
diff
changeset
|
1095 g_string_append_len(dest, p, q - p); |
7095
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1096 } |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1097 |
7675 | 1098 g_string_append(dest, "<br>\n"); |
7095
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1099 |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1100 return TRUE; |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1101 } |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1102 |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1103 return FALSE; |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1104 } |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1105 |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1106 struct gaim_parse_tag { |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1107 char *src_tag; |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1108 char *dest_tag; |
8064 | 1109 gboolean ignore; |
7095
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1110 }; |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1111 |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1112 #define ALLOW_TAG_ALT(x, y) if(!g_ascii_strncasecmp(c, "<" x " ", strlen("<" x " "))) { \ |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1113 const char *o = c + strlen("<" x); \ |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1114 const char *p = NULL, *q = NULL, *r = NULL; \ |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1115 GString *innards = g_string_new(""); \ |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1116 while(o && *o) { \ |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1117 if(!q && (*o == '\"' || *o == '\'') ) { \ |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1118 q = o; \ |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1119 } else if(q) { \ |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1120 if(*o == *q) { \ |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1121 char *unescaped = g_strndup(q+1, o-q-1); \ |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1122 char *escaped = g_markup_escape_text(unescaped, -1); \ |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1123 g_string_append_printf(innards, "%c%s%c", *q, escaped, *q); \ |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1124 g_free(unescaped); \ |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1125 g_free(escaped); \ |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1126 q = NULL; \ |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1127 } else if(*c == '\\') { \ |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1128 o++; \ |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1129 } \ |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1130 } else if(*o == '<') { \ |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1131 r = o; \ |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1132 } else if(*o == '>') { \ |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1133 p = o; \ |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1134 break; \ |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1135 } else { \ |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1136 innards = g_string_append_c(innards, *o); \ |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1137 } \ |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1138 o++; \ |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1139 } \ |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1140 if(p && !r) { \ |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1141 if(*(p-1) != '/') { \ |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1142 struct gaim_parse_tag *pt = g_new0(struct gaim_parse_tag, 1); \ |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1143 pt->src_tag = x; \ |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1144 pt->dest_tag = y; \ |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1145 tags = g_list_prepend(tags, pt); \ |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1146 } \ |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1147 xhtml = g_string_append(xhtml, "<" y); \ |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1148 c += strlen("<" x ); \ |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1149 xhtml = g_string_append(xhtml, innards->str); \ |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1150 xhtml = g_string_append_c(xhtml, '>'); \ |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1151 c = p + 1; \ |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1152 } else { \ |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1153 xhtml = g_string_append(xhtml, "<"); \ |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1154 plain = g_string_append_c(plain, '<'); \ |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1155 c++; \ |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1156 } \ |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1157 g_string_free(innards, TRUE); \ |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1158 continue; \ |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1159 } \ |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1160 if(!g_ascii_strncasecmp(c, "<" x, strlen("<" x)) && \ |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1161 (*(c+strlen("<" x)) == '>' || \ |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1162 !g_ascii_strncasecmp(c+strlen("<" x), "/>", 2))) { \ |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1163 xhtml = g_string_append(xhtml, "<" y); \ |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1164 c += strlen("<" x); \ |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1165 if(*c != '/') { \ |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1166 struct gaim_parse_tag *pt = g_new0(struct gaim_parse_tag, 1); \ |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1167 pt->src_tag = x; \ |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1168 pt->dest_tag = y; \ |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1169 tags = g_list_prepend(tags, pt); \ |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1170 xhtml = g_string_append_c(xhtml, '>'); \ |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1171 } else { \ |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1172 xhtml = g_string_append(xhtml, "/>");\ |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1173 } \ |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1174 c = strchr(c, '>') + 1; \ |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1175 continue; \ |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1176 } |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1177 #define ALLOW_TAG(x) ALLOW_TAG_ALT(x, x) |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1178 void |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1179 gaim_markup_html_to_xhtml(const char *html, char **xhtml_out, |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1180 char **plain_out) |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1181 { |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1182 GString *xhtml = g_string_new(""); |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1183 GString *plain = g_string_new(""); |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1184 GList *tags = NULL, *tag; |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1185 const char *c = html; |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1186 |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1187 while(c && *c) { |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1188 if(*c == '<') { |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1189 if(*(c+1) == '/') { /* closing tag */ |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1190 tag = tags; |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1191 while(tag) { |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1192 struct gaim_parse_tag *pt = tag->data; |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1193 if(!g_ascii_strncasecmp((c+2), pt->src_tag, strlen(pt->src_tag)) && *(c+strlen(pt->src_tag)+2) == '>') { |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1194 c += strlen(pt->src_tag) + 3; |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1195 break; |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1196 } |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1197 tag = tag->next; |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1198 } |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1199 if(tag) { |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1200 while(tags) { |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1201 struct gaim_parse_tag *pt = tags->data; |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1202 g_string_append_printf(xhtml, "</%s>", pt->dest_tag); |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1203 if(tags == tag) |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1204 break; |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1205 tags = g_list_remove(tags, pt); |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1206 g_free(pt); |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1207 } |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1208 g_free(tag->data); |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1209 tags = g_list_remove(tags, tag->data); |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1210 } else { |
8534 | 1211 /* a closing tag we weren't expecting... |
1212 * we'll let it slide, if it's really a tag...if it's | |
1213 * just a </ we'll escape it properly */ | |
1214 const char *end = c+2; | |
1215 while(*end && g_ascii_isalpha(*end)) | |
1216 end++; | |
1217 if(*end == '>') { | |
1218 c = end+1; | |
1219 } else { | |
1220 xhtml = g_string_append(xhtml, "<"); | |
1221 plain = g_string_append_c(plain, '<'); | |
1222 c++; | |
1223 } | |
7095
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1224 } |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1225 } else { /* opening tag */ |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1226 ALLOW_TAG("a"); |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1227 ALLOW_TAG_ALT("b", "strong"); |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1228 ALLOW_TAG("blockquote"); |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1229 ALLOW_TAG_ALT("bold", "strong"); |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1230 ALLOW_TAG("cite"); |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1231 ALLOW_TAG("div"); |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1232 ALLOW_TAG("em"); |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1233 ALLOW_TAG("h1"); |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1234 ALLOW_TAG("h2"); |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1235 ALLOW_TAG("h3"); |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1236 ALLOW_TAG("h4"); |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1237 ALLOW_TAG("h5"); |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1238 ALLOW_TAG("h6"); |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1239 /* we only allow html to start the message */ |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1240 if(c == html) |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1241 ALLOW_TAG("html"); |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1242 ALLOW_TAG_ALT("i", "em"); |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1243 ALLOW_TAG_ALT("italic", "em"); |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1244 ALLOW_TAG("li"); |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1245 ALLOW_TAG("ol"); |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1246 ALLOW_TAG("p"); |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1247 ALLOW_TAG("pre"); |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1248 ALLOW_TAG("q"); |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1249 ALLOW_TAG("span"); |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1250 ALLOW_TAG("strong"); |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1251 ALLOW_TAG("ul"); |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1252 |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1253 /* we skip <HR> because it's not legal in XHTML-IM. However, |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1254 * we still want to send something sensible, so we put a |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1255 * linebreak in its place. <BR> also needs special handling |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1256 * because putting a </BR> to close it would just be dumb. */ |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1257 if((!g_ascii_strncasecmp(c, "<br", 3) |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1258 || !g_ascii_strncasecmp(c, "<hr", 3)) |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1259 && (*(c+3) == '>' || |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1260 !g_ascii_strncasecmp(c+3, "/>", 2) || |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1261 !g_ascii_strncasecmp(c+3, " />", 3))) { |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1262 c = strchr(c, '>') + 1; |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1263 xhtml = g_string_append(xhtml, "<br/>"); |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1264 if(*c != '\n') |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1265 plain = g_string_append_c(plain, '\n'); |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1266 continue; |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1267 } |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1268 if(!g_ascii_strncasecmp(c, "<u>", 3) || !g_ascii_strncasecmp(c, "<underline>", strlen("<underline>"))) { |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1269 struct gaim_parse_tag *pt = g_new0(struct gaim_parse_tag, 1); |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1270 pt->src_tag = *(c+2) == '>' ? "u" : "underline"; |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1271 pt->dest_tag = "span"; |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1272 tags = g_list_prepend(tags, pt); |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1273 c = strchr(c, '>') + 1; |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1274 xhtml = g_string_append(xhtml, "<span style='text-decoration: underline;'>"); |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1275 continue; |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1276 } |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1277 if(!g_ascii_strncasecmp(c, "<s>", 3) || !g_ascii_strncasecmp(c, "<strike>", strlen("<strike>"))) { |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1278 struct gaim_parse_tag *pt = g_new0(struct gaim_parse_tag, 1); |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1279 pt->src_tag = *(c+2) == '>' ? "s" : "strike"; |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1280 pt->dest_tag = "span"; |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1281 tags = g_list_prepend(tags, pt); |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1282 c = strchr(c, '>') + 1; |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1283 xhtml = g_string_append(xhtml, "<span style='text-decoration: line-through;'>"); |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1284 continue; |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1285 } |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1286 if(!g_ascii_strncasecmp(c, "<sub>", 5)) { |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1287 struct gaim_parse_tag *pt = g_new0(struct gaim_parse_tag, 1); |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1288 pt->src_tag = "sub"; |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1289 pt->dest_tag = "span"; |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1290 tags = g_list_prepend(tags, pt); |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1291 c = strchr(c, '>') + 1; |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1292 xhtml = g_string_append(xhtml, "<span style='vertical-align:sub;'>"); |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1293 continue; |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1294 } |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1295 if(!g_ascii_strncasecmp(c, "<sup>", 5)) { |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1296 struct gaim_parse_tag *pt = g_new0(struct gaim_parse_tag, 1); |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1297 pt->src_tag = "sup"; |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1298 pt->dest_tag = "span"; |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1299 tags = g_list_prepend(tags, pt); |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1300 c = strchr(c, '>') + 1; |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1301 xhtml = g_string_append(xhtml, "<span style='vertical-align:super;'>"); |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1302 continue; |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1303 } |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1304 if(!g_ascii_strncasecmp(c, "<font", 5) && (*(c+5) == '>' || *(c+5) == ' ')) { |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1305 const char *p = c; |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1306 GString *style = g_string_new(""); |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1307 struct gaim_parse_tag *pt; |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1308 while(*p && *p != '>') { |
8064 | 1309 if(!g_ascii_strncasecmp(p, "back=", strlen("back="))) { |
1310 const char *q = p + strlen("back="); | |
1311 GString *color = g_string_new(""); | |
1312 if(*q == '\'' || *q == '\"') | |
1313 q++; | |
1314 while(*q && *q != '\"' && *q != '\'' && *q != ' ') { | |
1315 color = g_string_append_c(color, *q); | |
1316 q++; | |
1317 } | |
1318 g_string_append_printf(style, "background: %s; ", color->str); | |
1319 g_string_free(color, TRUE); | |
1320 p = q; | |
1321 } else if(!g_ascii_strncasecmp(p, "color=", strlen("color="))) { | |
7095
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1322 const char *q = p + strlen("color="); |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1323 GString *color = g_string_new(""); |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1324 if(*q == '\'' || *q == '\"') |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1325 q++; |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1326 while(*q && *q != '\"' && *q != '\'' && *q != ' ') { |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1327 color = g_string_append_c(color, *q); |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1328 q++; |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1329 } |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1330 g_string_append_printf(style, "color: %s; ", color->str); |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1331 g_string_free(color, TRUE); |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1332 p = q; |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1333 } else if(!g_ascii_strncasecmp(p, "face=", strlen("face="))) { |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1334 const char *q = p + strlen("face="); |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1335 gboolean space_allowed = FALSE; |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1336 GString *face = g_string_new(""); |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1337 if(*q == '\'' || *q == '\"') { |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1338 space_allowed = TRUE; |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1339 q++; |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1340 } |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1341 while(*q && *q != '\"' && *q != '\'' && (space_allowed || *q != ' ')) { |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1342 face = g_string_append_c(face, *q); |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1343 q++; |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1344 } |
13834
378bba5011e7
[gaim-migrate @ 16283]
Richard Laager <rlaager@wiktel.com>
parents:
13829
diff
changeset
|
1345 g_string_append_printf(style, "font-family: %s; ", g_strstrip(face->str)); |
7095
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1346 g_string_free(face, TRUE); |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1347 p = q; |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1348 } else if(!g_ascii_strncasecmp(p, "size=", strlen("size="))) { |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1349 const char *q = p + strlen("size="); |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1350 int sz; |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1351 const char *size = "medium"; |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1352 if(*q == '\'' || *q == '\"') |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1353 q++; |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1354 sz = atoi(q); |
8686 | 1355 switch (sz) |
1356 { | |
1357 case 1: | |
1358 size = "xx-small"; | |
1359 break; | |
1360 case 2: | |
1361 size = "x-small"; | |
1362 break; | |
1363 case 3: | |
1364 size = "small"; | |
1365 break; | |
1366 case 4: | |
1367 size = "medium"; | |
1368 break; | |
1369 case 5: | |
1370 size = "large"; | |
1371 break; | |
1372 case 6: | |
1373 size = "x-large"; | |
1374 break; | |
1375 case 7: | |
1376 size = "xx-large"; | |
1377 break; | |
1378 default: | |
1379 break; | |
1380 } | |
7095
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1381 g_string_append_printf(style, "font-size: %s; ", size); |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1382 p = q; |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1383 } |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1384 p++; |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1385 } |
10593 | 1386 if ((c = strchr(c, '>')) != NULL) |
1387 c++; | |
1388 else | |
1389 c = p; | |
8064 | 1390 pt = g_new0(struct gaim_parse_tag, 1); |
1391 pt->src_tag = "font"; | |
1392 pt->dest_tag = "span"; | |
1393 tags = g_list_prepend(tags, pt); | |
1394 if(style->len) | |
13834
378bba5011e7
[gaim-migrate @ 16283]
Richard Laager <rlaager@wiktel.com>
parents:
13829
diff
changeset
|
1395 g_string_append_printf(xhtml, "<span style='%s'>", g_strstrip(style->str)); |
8064 | 1396 else |
1397 pt->ignore = TRUE; | |
7095
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1398 g_string_free(style, TRUE); |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1399 continue; |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1400 } |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1401 if(!g_ascii_strncasecmp(c, "<body ", 6)) { |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1402 const char *p = c; |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1403 gboolean did_something = FALSE; |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1404 while(*p && *p != '>') { |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1405 if(!g_ascii_strncasecmp(p, "bgcolor=", strlen("bgcolor="))) { |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1406 const char *q = p + strlen("bgcolor="); |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1407 struct gaim_parse_tag *pt = g_new0(struct gaim_parse_tag, 1); |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1408 GString *color = g_string_new(""); |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1409 if(*q == '\'' || *q == '\"') |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1410 q++; |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1411 while(*q && *q != '\"' && *q != '\'' && *q != ' ') { |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1412 color = g_string_append_c(color, *q); |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1413 q++; |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1414 } |
13834
378bba5011e7
[gaim-migrate @ 16283]
Richard Laager <rlaager@wiktel.com>
parents:
13829
diff
changeset
|
1415 g_string_append_printf(xhtml, "<span style='background: %s;'>", g_strstrip(color->str)); |
7095
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1416 g_string_free(color, TRUE); |
10623 | 1417 if ((c = strchr(c, '>')) != NULL) |
1418 c++; | |
1419 else | |
1420 c = p; | |
7095
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1421 pt->src_tag = "body"; |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1422 pt->dest_tag = "span"; |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1423 tags = g_list_prepend(tags, pt); |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1424 did_something = TRUE; |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1425 break; |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1426 } |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1427 p++; |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1428 } |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1429 if(did_something) continue; |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1430 } |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1431 /* this has to come after the special case for bgcolor */ |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1432 ALLOW_TAG("body"); |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1433 if(!g_ascii_strncasecmp(c, "<!--", strlen("<!--"))) { |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1434 char *p = strstr(c + strlen("<!--"), "-->"); |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1435 if(p) { |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1436 xhtml = g_string_append(xhtml, "<!--"); |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1437 c += strlen("<!--"); |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1438 continue; |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1439 } |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1440 } |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1441 |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1442 xhtml = g_string_append(xhtml, "<"); |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1443 plain = g_string_append_c(plain, '<'); |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1444 c++; |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1445 } |
7287 | 1446 } else if(*c == '&') { |
1447 char buf[7]; | |
1448 char *pln; | |
1449 int len = 1; | |
1450 guint pound; | |
1451 if(!g_ascii_strncasecmp(c, "&", 5)) { | |
1452 pln = "&"; | |
1453 len = 5; | |
1454 } else if(!g_ascii_strncasecmp(c, "<", 4)) { | |
1455 pln = "<"; | |
1456 len = 4; | |
1457 } else if(!g_ascii_strncasecmp(c, ">", 4)) { | |
1458 pln = ">"; | |
1459 len = 4; | |
1460 } else if(!g_ascii_strncasecmp(c, " ", 6)) { | |
1461 pln = " "; | |
1462 len = 6; | |
1463 } else if(!g_ascii_strncasecmp(c, "©", 6)) { | |
1464 pln = "©"; | |
1465 len = 6; | |
1466 } else if(!g_ascii_strncasecmp(c, """, 6)) { | |
1467 pln = "\""; | |
1468 len = 6; | |
1469 } else if(!g_ascii_strncasecmp(c, "®", 5)) { | |
1470 pln = "®"; | |
1471 len = 5; | |
1472 } else if(!g_ascii_strncasecmp(c, "'", 6)) { | |
1473 pln = "\'"; | |
1474 len = 6; | |
1475 } else if(*(c+1) == '#' && (sscanf(c, "&#%u;", £) == 1) && | |
1476 pound != 0 && *(c+3+(gint)log10(pound)) == ';') { | |
1477 int buflen = g_unichar_to_utf8((gunichar)pound, buf); | |
1478 buf[buflen] = '\0'; | |
1479 pln = buf; | |
1480 | |
1481 | |
1482 len = 2; | |
1483 while(isdigit((gint) c [len])) len++; | |
1484 if(c [len] == ';') len++; | |
1485 } else { | |
1486 len = 1; | |
1487 g_snprintf(buf, sizeof(buf), "%c", *c); | |
1488 pln = buf; | |
1489 } | |
1490 xhtml = g_string_append_len(xhtml, c, len); | |
1491 plain = g_string_append(plain, pln); | |
1492 c += len; | |
7095
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1493 } else { |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1494 xhtml = g_string_append_c(xhtml, *c); |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1495 plain = g_string_append_c(plain, *c); |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1496 c++; |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1497 } |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1498 } |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1499 tag = tags; |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1500 while(tag) { |
8064 | 1501 struct gaim_parse_tag *pt = tag->data; |
1502 if(!pt->ignore) | |
1503 g_string_append_printf(xhtml, "</%s>", pt->dest_tag); | |
7095
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1504 tag = tag->next; |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1505 } |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1506 g_list_free(tags); |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1507 if(xhtml_out) |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1508 *xhtml_out = g_strdup(xhtml->str); |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1509 if(plain_out) |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1510 *plain_out = g_strdup(plain->str); |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1511 g_string_free(xhtml, TRUE); |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1512 g_string_free(plain, TRUE); |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1513 } |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1514 |
9161 | 1515 /* The following are probably reasonable changes: |
1516 * - \n should be converted to a normal space | |
1517 * - in addition to <br>, <p> and <div> etc. should also be converted into \n | |
9241 | 1518 * - We want to turn </td>#whitespace<td> sequences into a single tab |
1519 * - We want to turn <td> into a single tab (for msn profile "parsing") | |
9161 | 1520 * - We want to turn </tr>#whitespace<tr> sequences into a single \n |
9241 | 1521 * - <script>...</script> and <style>...</style> should be completely removed |
9161 | 1522 */ |
1523 | |
7095
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1524 char * |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1525 gaim_markup_strip_html(const char *str) |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1526 { |
7103 | 1527 int i, j, k; |
1528 gboolean visible = TRUE; | |
9161 | 1529 gboolean closing_td_p = FALSE; |
7103 | 1530 gchar *str2; |
9241 | 1531 const gchar *cdata_close_tag = NULL; |
12620
13599d978a31
[gaim-migrate @ 14956]
Richard Laager <rlaager@wiktel.com>
parents:
12483
diff
changeset
|
1532 gchar *href = NULL; |
13599d978a31
[gaim-migrate @ 14956]
Richard Laager <rlaager@wiktel.com>
parents:
12483
diff
changeset
|
1533 int href_st = 0; |
7103 | 1534 |
7110 | 1535 if(!str) |
1536 return NULL; | |
7103 | 1537 |
1538 str2 = g_strdup(str); | |
1539 | |
1540 for (i = 0, j = 0; str2[i]; i++) | |
1541 { | |
1542 if (str2[i] == '<') | |
1543 { | |
9241 | 1544 if (cdata_close_tag) |
9161 | 1545 { |
9241 | 1546 /* Note: Don't even assume any other tag is a tag in CDATA */ |
1547 if (strncasecmp(str2 + i, cdata_close_tag, | |
1548 strlen(cdata_close_tag)) == 0) | |
1549 { | |
1550 i += strlen(cdata_close_tag) - 1; | |
1551 cdata_close_tag = NULL; | |
1552 } | |
1553 continue; | |
1554 } | |
1555 else if (strncasecmp(str2 + i, "<td", 3) == 0 && closing_td_p) | |
1556 { | |
1557 str2[j++] = '\t'; | |
9161 | 1558 visible = TRUE; |
1559 } | |
1560 else if (strncasecmp(str2 + i, "</td>", 5) == 0) | |
8517 | 1561 { |
9161 | 1562 closing_td_p = TRUE; |
1563 visible = FALSE; | |
1564 } | |
1565 else | |
1566 { | |
1567 closing_td_p = FALSE; | |
1568 visible = TRUE; | |
8517 | 1569 } |
1570 | |
7103 | 1571 k = i + 1; |
1572 | |
1573 if(g_ascii_isspace(str2[k])) | |
1574 visible = TRUE; | |
9170 | 1575 else if (str2[k]) |
7103 | 1576 { |
9161 | 1577 /* Scan until we end the tag either implicitly (closed start |
1578 * tag) or explicitly, using a sloppy method (i.e., < or > | |
1579 * inside quoted attributes will screw us up) | |
1580 */ | |
1581 while (str2[k] && str2[k] != '<' && str2[k] != '>') | |
7103 | 1582 { |
1583 k++; | |
1584 } | |
9241 | 1585 |
12620
13599d978a31
[gaim-migrate @ 14956]
Richard Laager <rlaager@wiktel.com>
parents:
12483
diff
changeset
|
1586 /* If we've got an <a> tag with an href, save the address |
13599d978a31
[gaim-migrate @ 14956]
Richard Laager <rlaager@wiktel.com>
parents:
12483
diff
changeset
|
1587 * to print later. */ |
13599d978a31
[gaim-migrate @ 14956]
Richard Laager <rlaager@wiktel.com>
parents:
12483
diff
changeset
|
1588 if (strncasecmp(str2 + i, "<a", 2) == 0 && |
13599d978a31
[gaim-migrate @ 14956]
Richard Laager <rlaager@wiktel.com>
parents:
12483
diff
changeset
|
1589 g_ascii_isspace(str2[i+2])) |
13599d978a31
[gaim-migrate @ 14956]
Richard Laager <rlaager@wiktel.com>
parents:
12483
diff
changeset
|
1590 { |
13599d978a31
[gaim-migrate @ 14956]
Richard Laager <rlaager@wiktel.com>
parents:
12483
diff
changeset
|
1591 int st; /* start of href, inclusive [ */ |
13599d978a31
[gaim-migrate @ 14956]
Richard Laager <rlaager@wiktel.com>
parents:
12483
diff
changeset
|
1592 int end; /* end of href, exclusive ) */ |
13599d978a31
[gaim-migrate @ 14956]
Richard Laager <rlaager@wiktel.com>
parents:
12483
diff
changeset
|
1593 char delim = ' '; |
13599d978a31
[gaim-migrate @ 14956]
Richard Laager <rlaager@wiktel.com>
parents:
12483
diff
changeset
|
1594 /* Find start of href */ |
13599d978a31
[gaim-migrate @ 14956]
Richard Laager <rlaager@wiktel.com>
parents:
12483
diff
changeset
|
1595 for (st = i + 3; st < k; st++) |
13599d978a31
[gaim-migrate @ 14956]
Richard Laager <rlaager@wiktel.com>
parents:
12483
diff
changeset
|
1596 { |
13599d978a31
[gaim-migrate @ 14956]
Richard Laager <rlaager@wiktel.com>
parents:
12483
diff
changeset
|
1597 if (strncasecmp(str2+st, "href=", 5) == 0) |
13599d978a31
[gaim-migrate @ 14956]
Richard Laager <rlaager@wiktel.com>
parents:
12483
diff
changeset
|
1598 { |
13599d978a31
[gaim-migrate @ 14956]
Richard Laager <rlaager@wiktel.com>
parents:
12483
diff
changeset
|
1599 st += 5; |
13599d978a31
[gaim-migrate @ 14956]
Richard Laager <rlaager@wiktel.com>
parents:
12483
diff
changeset
|
1600 if (str2[st] == '"') |
13599d978a31
[gaim-migrate @ 14956]
Richard Laager <rlaager@wiktel.com>
parents:
12483
diff
changeset
|
1601 { |
13599d978a31
[gaim-migrate @ 14956]
Richard Laager <rlaager@wiktel.com>
parents:
12483
diff
changeset
|
1602 delim = '"'; |
13599d978a31
[gaim-migrate @ 14956]
Richard Laager <rlaager@wiktel.com>
parents:
12483
diff
changeset
|
1603 st++; |
13599d978a31
[gaim-migrate @ 14956]
Richard Laager <rlaager@wiktel.com>
parents:
12483
diff
changeset
|
1604 } |
13599d978a31
[gaim-migrate @ 14956]
Richard Laager <rlaager@wiktel.com>
parents:
12483
diff
changeset
|
1605 break; |
13599d978a31
[gaim-migrate @ 14956]
Richard Laager <rlaager@wiktel.com>
parents:
12483
diff
changeset
|
1606 } |
13599d978a31
[gaim-migrate @ 14956]
Richard Laager <rlaager@wiktel.com>
parents:
12483
diff
changeset
|
1607 } |
13599d978a31
[gaim-migrate @ 14956]
Richard Laager <rlaager@wiktel.com>
parents:
12483
diff
changeset
|
1608 /* find end of address */ |
13599d978a31
[gaim-migrate @ 14956]
Richard Laager <rlaager@wiktel.com>
parents:
12483
diff
changeset
|
1609 for (end = st; end < k && str2[end] != delim; end++) |
13599d978a31
[gaim-migrate @ 14956]
Richard Laager <rlaager@wiktel.com>
parents:
12483
diff
changeset
|
1610 { |
13599d978a31
[gaim-migrate @ 14956]
Richard Laager <rlaager@wiktel.com>
parents:
12483
diff
changeset
|
1611 /* All the work is done in the loop construct above. */ |
13599d978a31
[gaim-migrate @ 14956]
Richard Laager <rlaager@wiktel.com>
parents:
12483
diff
changeset
|
1612 } |
13599d978a31
[gaim-migrate @ 14956]
Richard Laager <rlaager@wiktel.com>
parents:
12483
diff
changeset
|
1613 |
13599d978a31
[gaim-migrate @ 14956]
Richard Laager <rlaager@wiktel.com>
parents:
12483
diff
changeset
|
1614 /* If there's an address, save it. If there was |
13599d978a31
[gaim-migrate @ 14956]
Richard Laager <rlaager@wiktel.com>
parents:
12483
diff
changeset
|
1615 * already one saved, kill it. */ |
13599d978a31
[gaim-migrate @ 14956]
Richard Laager <rlaager@wiktel.com>
parents:
12483
diff
changeset
|
1616 if (st < k) |
13599d978a31
[gaim-migrate @ 14956]
Richard Laager <rlaager@wiktel.com>
parents:
12483
diff
changeset
|
1617 { |
13599d978a31
[gaim-migrate @ 14956]
Richard Laager <rlaager@wiktel.com>
parents:
12483
diff
changeset
|
1618 char *tmp; |
13599d978a31
[gaim-migrate @ 14956]
Richard Laager <rlaager@wiktel.com>
parents:
12483
diff
changeset
|
1619 g_free(href); |
13599d978a31
[gaim-migrate @ 14956]
Richard Laager <rlaager@wiktel.com>
parents:
12483
diff
changeset
|
1620 tmp = g_strndup(str2 + st, end - st); |
13599d978a31
[gaim-migrate @ 14956]
Richard Laager <rlaager@wiktel.com>
parents:
12483
diff
changeset
|
1621 href = gaim_unescape_html(tmp); |
13599d978a31
[gaim-migrate @ 14956]
Richard Laager <rlaager@wiktel.com>
parents:
12483
diff
changeset
|
1622 g_free(tmp); |
13599d978a31
[gaim-migrate @ 14956]
Richard Laager <rlaager@wiktel.com>
parents:
12483
diff
changeset
|
1623 href_st = j; |
13599d978a31
[gaim-migrate @ 14956]
Richard Laager <rlaager@wiktel.com>
parents:
12483
diff
changeset
|
1624 } |
13599d978a31
[gaim-migrate @ 14956]
Richard Laager <rlaager@wiktel.com>
parents:
12483
diff
changeset
|
1625 } |
13599d978a31
[gaim-migrate @ 14956]
Richard Laager <rlaager@wiktel.com>
parents:
12483
diff
changeset
|
1626 |
13599d978a31
[gaim-migrate @ 14956]
Richard Laager <rlaager@wiktel.com>
parents:
12483
diff
changeset
|
1627 /* Replace </a> with an ascii representation of the |
13599d978a31
[gaim-migrate @ 14956]
Richard Laager <rlaager@wiktel.com>
parents:
12483
diff
changeset
|
1628 * address the link was pointing to. */ |
13599d978a31
[gaim-migrate @ 14956]
Richard Laager <rlaager@wiktel.com>
parents:
12483
diff
changeset
|
1629 else if (href != NULL && strncasecmp(str2 + i, "</a>", 4) == 0) |
13599d978a31
[gaim-migrate @ 14956]
Richard Laager <rlaager@wiktel.com>
parents:
12483
diff
changeset
|
1630 { |
13599d978a31
[gaim-migrate @ 14956]
Richard Laager <rlaager@wiktel.com>
parents:
12483
diff
changeset
|
1631 |
13599d978a31
[gaim-migrate @ 14956]
Richard Laager <rlaager@wiktel.com>
parents:
12483
diff
changeset
|
1632 size_t hrlen = strlen(href); |
13599d978a31
[gaim-migrate @ 14956]
Richard Laager <rlaager@wiktel.com>
parents:
12483
diff
changeset
|
1633 |
13599d978a31
[gaim-migrate @ 14956]
Richard Laager <rlaager@wiktel.com>
parents:
12483
diff
changeset
|
1634 /* Only insert the href if it's different from the CDATA. */ |
12640
de306144dc8a
[gaim-migrate @ 14976]
Richard Laager <rlaager@wiktel.com>
parents:
12628
diff
changeset
|
1635 if ((hrlen != j - href_st || |
de306144dc8a
[gaim-migrate @ 14976]
Richard Laager <rlaager@wiktel.com>
parents:
12628
diff
changeset
|
1636 strncmp(str2 + href_st, href, hrlen)) && |
de306144dc8a
[gaim-migrate @ 14976]
Richard Laager <rlaager@wiktel.com>
parents:
12628
diff
changeset
|
1637 (hrlen != j - href_st + 7 || /* 7 == strlen("http://") */ |
de306144dc8a
[gaim-migrate @ 14976]
Richard Laager <rlaager@wiktel.com>
parents:
12628
diff
changeset
|
1638 strncmp(str2 + href_st, href + 7, hrlen - 7))) |
12620
13599d978a31
[gaim-migrate @ 14956]
Richard Laager <rlaager@wiktel.com>
parents:
12483
diff
changeset
|
1639 { |
13599d978a31
[gaim-migrate @ 14956]
Richard Laager <rlaager@wiktel.com>
parents:
12483
diff
changeset
|
1640 str2[j++] = ' '; |
12628
26647ddcc9c5
[gaim-migrate @ 14964]
Richard Laager <rlaager@wiktel.com>
parents:
12622
diff
changeset
|
1641 str2[j++] = '('; |
12620
13599d978a31
[gaim-migrate @ 14956]
Richard Laager <rlaager@wiktel.com>
parents:
12483
diff
changeset
|
1642 g_memmove(str2 + j, href, hrlen); |
13599d978a31
[gaim-migrate @ 14956]
Richard Laager <rlaager@wiktel.com>
parents:
12483
diff
changeset
|
1643 j += hrlen; |
12628
26647ddcc9c5
[gaim-migrate @ 14964]
Richard Laager <rlaager@wiktel.com>
parents:
12622
diff
changeset
|
1644 str2[j++] = ')'; |
12620
13599d978a31
[gaim-migrate @ 14956]
Richard Laager <rlaager@wiktel.com>
parents:
12483
diff
changeset
|
1645 g_free(href); |
13599d978a31
[gaim-migrate @ 14956]
Richard Laager <rlaager@wiktel.com>
parents:
12483
diff
changeset
|
1646 href = NULL; |
13599d978a31
[gaim-migrate @ 14956]
Richard Laager <rlaager@wiktel.com>
parents:
12483
diff
changeset
|
1647 } |
13599d978a31
[gaim-migrate @ 14956]
Richard Laager <rlaager@wiktel.com>
parents:
12483
diff
changeset
|
1648 } |
13599d978a31
[gaim-migrate @ 14956]
Richard Laager <rlaager@wiktel.com>
parents:
12483
diff
changeset
|
1649 |
9161 | 1650 /* Check for tags which should be mapped to newline */ |
12620
13599d978a31
[gaim-migrate @ 14956]
Richard Laager <rlaager@wiktel.com>
parents:
12483
diff
changeset
|
1651 else if (strncasecmp(str2 + i, "<p>", 3) == 0 |
9161 | 1652 || strncasecmp(str2 + i, "<tr", 3) == 0 |
1653 || strncasecmp(str2 + i, "<br", 3) == 0 | |
1654 || strncasecmp(str2 + i, "<li", 3) == 0 | |
1655 || strncasecmp(str2 + i, "<div", 4) == 0 | |
1656 || strncasecmp(str2 + i, "</table>", 8) == 0) | |
1657 { | |
1658 str2[j++] = '\n'; | |
1659 } | |
9241 | 1660 /* Check for tags which begin CDATA and need to be closed */ |
1661 #if 0 /* FIXME.. option is end tag optional, we can't handle this right now */ | |
1662 else if (strncasecmp(str2 + i, "<option", 7) == 0) | |
1663 { | |
1664 /* FIXME: We should not do this if the OPTION is SELECT'd */ | |
1665 cdata_close_tag = "</option>"; | |
1666 } | |
1667 #endif | |
1668 else if (strncasecmp(str2 + i, "<script", 7) == 0) | |
1669 { | |
1670 cdata_close_tag = "</script>"; | |
1671 } | |
1672 else if (strncasecmp(str2 + i, "<style", 6) == 0) | |
1673 { | |
1674 cdata_close_tag = "</style>"; | |
1675 } | |
9161 | 1676 /* Update the index and continue checking after the tag */ |
10731 | 1677 i = (str2[k] == '<' || str2[k] == '\0')? k - 1: k; |
9161 | 1678 continue; |
7103 | 1679 } |
1680 } | |
9241 | 1681 else if (cdata_close_tag) |
1682 { | |
1683 continue; | |
1684 } | |
9161 | 1685 else if (!g_ascii_isspace(str2[i])) |
7103 | 1686 { |
1687 visible = TRUE; | |
1688 } | |
1689 | |
9273 | 1690 /* XXX: This sucks. We need to be un-escaping all entities, which |
1691 * includes these, as well as the &#num; ones */ | |
1692 | |
7103 | 1693 if (str2[i] == '&' && strncasecmp(str2 + i, """, 6) == 0) |
1694 { | |
1695 str2[j++] = '\"'; | |
1696 i = i + 5; | |
1697 continue; | |
1698 } | |
1699 | |
8517 | 1700 if (str2[i] == '&' && strncasecmp(str2 + i, "&", 5) == 0) |
1701 { | |
1702 str2[j++] = '&'; | |
1703 i = i + 4; | |
1704 continue; | |
1705 } | |
1706 | |
1707 if (str2[i] == '&' && strncasecmp(str2 + i, "<", 4) == 0) | |
1708 { | |
1709 str2[j++] = '<'; | |
1710 i = i + 3; | |
1711 continue; | |
1712 } | |
1713 | |
1714 if (str2[i] == '&' && strncasecmp(str2 + i, ">", 4) == 0) | |
1715 { | |
1716 str2[j++] = '>'; | |
1717 i = i + 3; | |
1718 continue; | |
1719 } | |
1720 | |
9273 | 1721 if (str2[i] == '&' && strncasecmp(str2 + i, "'", 6) == 0) |
1722 { | |
1723 str2[j++] = '\''; | |
1724 i = i + 5; | |
1725 continue; | |
1726 } | |
1727 | |
7103 | 1728 if (visible) |
9161 | 1729 str2[j++] = g_ascii_isspace(str2[i])? ' ': str2[i]; |
7103 | 1730 } |
1731 | |
12620
13599d978a31
[gaim-migrate @ 14956]
Richard Laager <rlaager@wiktel.com>
parents:
12483
diff
changeset
|
1732 g_free(href); |
13599d978a31
[gaim-migrate @ 14956]
Richard Laager <rlaager@wiktel.com>
parents:
12483
diff
changeset
|
1733 |
7103 | 1734 str2[j] = '\0'; |
1735 | |
1736 return str2; | |
7095
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1737 } |
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
1738 |
10461 | 1739 static gboolean |
7108
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
1740 badchar(char c) |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
1741 { |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
1742 switch (c) { |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
1743 case ' ': |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
1744 case ',': |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
1745 case '\0': |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
1746 case '\n': |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
1747 case '<': |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
1748 case '>': |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
1749 case '"': |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
1750 case '\'': |
10461 | 1751 return TRUE; |
7108
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
1752 default: |
10461 | 1753 return FALSE; |
7108
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
1754 } |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
1755 } |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
1756 |
10461 | 1757 static gboolean |
1758 badentity(const char *c) | |
1759 { | |
1760 if (!g_ascii_strncasecmp(c, "<", 4) || | |
1761 !g_ascii_strncasecmp(c, ">", 4) || | |
1762 !g_ascii_strncasecmp(c, """, 6)) { | |
1763 return TRUE; | |
1764 } | |
1765 return FALSE; | |
1766 } | |
1767 | |
7107
9220c7490cd1
[gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents:
7106
diff
changeset
|
1768 char * |
9220c7490cd1
[gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents:
7106
diff
changeset
|
1769 gaim_markup_linkify(const char *text) |
9220c7490cd1
[gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents:
7106
diff
changeset
|
1770 { |
9220c7490cd1
[gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents:
7106
diff
changeset
|
1771 const char *c, *t, *q = NULL; |
10902 | 1772 char *tmp, *tmpurlbuf, *url_buf; |
9222 | 1773 gunichar g; |
8538 | 1774 gboolean inside_html = FALSE; |
9222 | 1775 int inside_paren = 0; |
7107
9220c7490cd1
[gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents:
7106
diff
changeset
|
1776 GString *ret = g_string_new(""); |
10372
618a330c0260
[gaim-migrate @ 11595]
Luke Schierer <lschiere@pidgin.im>
parents:
10332
diff
changeset
|
1777 /* Assumes you have a buffer able to carry at least BUF_LEN * 2 bytes */ |
7107
9220c7490cd1
[gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents:
7106
diff
changeset
|
1778 |
9220c7490cd1
[gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents:
7106
diff
changeset
|
1779 c = text; |
9220c7490cd1
[gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents:
7106
diff
changeset
|
1780 while (*c) { |
9222 | 1781 |
1782 if(*c == '(' && !inside_html) { | |
1783 inside_paren++; | |
1784 ret = g_string_append_c(ret, *c); | |
1785 c++; | |
1786 } | |
1787 | |
8538 | 1788 if(inside_html) { |
1789 if(*c == '>') { | |
1790 inside_html = FALSE; | |
1791 } else if(!q && (*c == '\"' || *c == '\'')) { | |
1792 q = c; | |
1793 } else if(q) { | |
1794 if(*c == *q) | |
1795 q = NULL; | |
1796 } | |
1797 } else if(*c == '<') { | |
1798 inside_html = TRUE; | |
9077 | 1799 if (!g_ascii_strncasecmp(c, "<A", 2)) { |
1800 while (1) { | |
1801 if (!g_ascii_strncasecmp(c, "/A>", 3)) { | |
1802 inside_html = FALSE; | |
1803 break; | |
1804 } | |
1805 ret = g_string_append_c(ret, *c); | |
1806 c++; | |
1807 if (!(*c)) | |
1808 break; | |
7107
9220c7490cd1
[gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents:
7106
diff
changeset
|
1809 } |
9220c7490cd1
[gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents:
7106
diff
changeset
|
1810 } |
9220c7490cd1
[gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents:
7106
diff
changeset
|
1811 } else if ((*c=='h') && (!g_ascii_strncasecmp(c, "http://", 7) || |
9220c7490cd1
[gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents:
7106
diff
changeset
|
1812 (!g_ascii_strncasecmp(c, "https://", 8)))) { |
9220c7490cd1
[gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents:
7106
diff
changeset
|
1813 t = c; |
9220c7490cd1
[gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents:
7106
diff
changeset
|
1814 while (1) { |
10461 | 1815 if (badchar(*t) || badentity(t)) { |
7107
9220c7490cd1
[gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents:
7106
diff
changeset
|
1816 |
9220c7490cd1
[gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents:
7106
diff
changeset
|
1817 if (*(t) == ',' && (*(t + 1) != ' ')) { |
9220c7490cd1
[gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents:
7106
diff
changeset
|
1818 t++; |
9220c7490cd1
[gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents:
7106
diff
changeset
|
1819 continue; |
9220c7490cd1
[gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents:
7106
diff
changeset
|
1820 } |
9220c7490cd1
[gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents:
7106
diff
changeset
|
1821 |
9220c7490cd1
[gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents:
7106
diff
changeset
|
1822 if (*(t - 1) == '.') |
9220c7490cd1
[gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents:
7106
diff
changeset
|
1823 t--; |
9222 | 1824 if ((*(t - 1) == ')' && (inside_paren > 0))) { |
1825 t--; | |
1826 } | |
10461 | 1827 |
10902 | 1828 url_buf = g_strndup(c, t - c); |
8918 | 1829 tmpurlbuf = gaim_unescape_html(url_buf); |
7107
9220c7490cd1
[gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents:
7106
diff
changeset
|
1830 g_string_append_printf(ret, "<A HREF=\"%s\">%s</A>", |
8918 | 1831 tmpurlbuf, url_buf); |
10902 | 1832 g_free(url_buf); |
8918 | 1833 g_free(tmpurlbuf); |
7107
9220c7490cd1
[gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents:
7106
diff
changeset
|
1834 c = t; |
9220c7490cd1
[gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents:
7106
diff
changeset
|
1835 break; |
9220c7490cd1
[gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents:
7106
diff
changeset
|
1836 } |
9220c7490cd1
[gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents:
7106
diff
changeset
|
1837 t++; |
9220c7490cd1
[gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents:
7106
diff
changeset
|
1838 |
9220c7490cd1
[gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents:
7106
diff
changeset
|
1839 } |
13770
9df4a46b0bb3
[gaim-migrate @ 16182]
Richard Laager <rlaager@wiktel.com>
parents:
13645
diff
changeset
|
1840 } else if (!g_ascii_strncasecmp(c, "www.", 4) && (c == text || badchar(c[-1]) || badentity(c-1))) { |
7107
9220c7490cd1
[gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents:
7106
diff
changeset
|
1841 if (c[4] != '.') { |
9220c7490cd1
[gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents:
7106
diff
changeset
|
1842 t = c; |
9220c7490cd1
[gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents:
7106
diff
changeset
|
1843 while (1) { |
10461 | 1844 if (badchar(*t) || badentity(t)) { |
7107
9220c7490cd1
[gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents:
7106
diff
changeset
|
1845 if (t - c == 4) { |
9220c7490cd1
[gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents:
7106
diff
changeset
|
1846 break; |
9220c7490cd1
[gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents:
7106
diff
changeset
|
1847 } |
9220c7490cd1
[gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents:
7106
diff
changeset
|
1848 |
9220c7490cd1
[gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents:
7106
diff
changeset
|
1849 if (*(t) == ',' && (*(t + 1) != ' ')) { |
9220c7490cd1
[gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents:
7106
diff
changeset
|
1850 t++; |
9220c7490cd1
[gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents:
7106
diff
changeset
|
1851 continue; |
9220c7490cd1
[gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents:
7106
diff
changeset
|
1852 } |
9220c7490cd1
[gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents:
7106
diff
changeset
|
1853 |
9220c7490cd1
[gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents:
7106
diff
changeset
|
1854 if (*(t - 1) == '.') |
9220c7490cd1
[gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents:
7106
diff
changeset
|
1855 t--; |
9222 | 1856 if ((*(t - 1) == ')' && (inside_paren > 0))) { |
1857 t--; | |
1858 } | |
10902 | 1859 url_buf = g_strndup(c, t - c); |
8918 | 1860 tmpurlbuf = gaim_unescape_html(url_buf); |
7107
9220c7490cd1
[gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents:
7106
diff
changeset
|
1861 g_string_append_printf(ret, |
8918 | 1862 "<A HREF=\"http://%s\">%s</A>", tmpurlbuf, |
7107
9220c7490cd1
[gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents:
7106
diff
changeset
|
1863 url_buf); |
10902 | 1864 g_free(url_buf); |
8918 | 1865 g_free(tmpurlbuf); |
7107
9220c7490cd1
[gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents:
7106
diff
changeset
|
1866 c = t; |
9220c7490cd1
[gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents:
7106
diff
changeset
|
1867 break; |
9220c7490cd1
[gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents:
7106
diff
changeset
|
1868 } |
9220c7490cd1
[gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents:
7106
diff
changeset
|
1869 t++; |
9220c7490cd1
[gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents:
7106
diff
changeset
|
1870 } |
9220c7490cd1
[gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents:
7106
diff
changeset
|
1871 } |
9220c7490cd1
[gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents:
7106
diff
changeset
|
1872 } else if (!g_ascii_strncasecmp(c, "ftp://", 6)) { |
9220c7490cd1
[gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents:
7106
diff
changeset
|
1873 t = c; |
9220c7490cd1
[gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents:
7106
diff
changeset
|
1874 while (1) { |
10461 | 1875 if (badchar(*t) || badentity(t)) { |
7107
9220c7490cd1
[gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents:
7106
diff
changeset
|
1876 if (*(t - 1) == '.') |
9220c7490cd1
[gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents:
7106
diff
changeset
|
1877 t--; |
9222 | 1878 if ((*(t - 1) == ')' && (inside_paren > 0))) { |
1879 t--; | |
1880 } | |
10905 | 1881 url_buf = g_strndup(c, t - c); |
8918 | 1882 tmpurlbuf = gaim_unescape_html(url_buf); |
7107
9220c7490cd1
[gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents:
7106
diff
changeset
|
1883 g_string_append_printf(ret, "<A HREF=\"%s\">%s</A>", |
8918 | 1884 tmpurlbuf, url_buf); |
10902 | 1885 g_free(url_buf); |
8918 | 1886 g_free(tmpurlbuf); |
7107
9220c7490cd1
[gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents:
7106
diff
changeset
|
1887 c = t; |
9220c7490cd1
[gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents:
7106
diff
changeset
|
1888 break; |
9220c7490cd1
[gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents:
7106
diff
changeset
|
1889 } |
9220c7490cd1
[gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents:
7106
diff
changeset
|
1890 if (!t) |
9220c7490cd1
[gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents:
7106
diff
changeset
|
1891 break; |
9220c7490cd1
[gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents:
7106
diff
changeset
|
1892 t++; |
9220c7490cd1
[gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents:
7106
diff
changeset
|
1893 |
9220c7490cd1
[gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents:
7106
diff
changeset
|
1894 } |
13770
9df4a46b0bb3
[gaim-migrate @ 16182]
Richard Laager <rlaager@wiktel.com>
parents:
13645
diff
changeset
|
1895 } else if (!g_ascii_strncasecmp(c, "ftp.", 4) && (c == text || badchar(c[-1]) || badentity(c-1))) { |
7107
9220c7490cd1
[gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents:
7106
diff
changeset
|
1896 if (c[4] != '.') { |
9220c7490cd1
[gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents:
7106
diff
changeset
|
1897 t = c; |
9220c7490cd1
[gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents:
7106
diff
changeset
|
1898 while (1) { |
10461 | 1899 if (badchar(*t) || badentity(t)) { |
7107
9220c7490cd1
[gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents:
7106
diff
changeset
|
1900 if (t - c == 4) { |
9220c7490cd1
[gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents:
7106
diff
changeset
|
1901 break; |
9220c7490cd1
[gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents:
7106
diff
changeset
|
1902 } |
9220c7490cd1
[gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents:
7106
diff
changeset
|
1903 if (*(t - 1) == '.') |
9220c7490cd1
[gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents:
7106
diff
changeset
|
1904 t--; |
9222 | 1905 if ((*(t - 1) == ')' && (inside_paren > 0))) { |
1906 t--; | |
1907 } | |
10902 | 1908 url_buf = g_strndup(c, t - c); |
8918 | 1909 tmpurlbuf = gaim_unescape_html(url_buf); |
7107
9220c7490cd1
[gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents:
7106
diff
changeset
|
1910 g_string_append_printf(ret, |
8918 | 1911 "<A HREF=\"ftp://%s\">%s</A>", tmpurlbuf, |
7107
9220c7490cd1
[gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents:
7106
diff
changeset
|
1912 url_buf); |
10902 | 1913 g_free(url_buf); |
8918 | 1914 g_free(tmpurlbuf); |
7107
9220c7490cd1
[gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents:
7106
diff
changeset
|
1915 c = t; |
9220c7490cd1
[gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents:
7106
diff
changeset
|
1916 break; |
9220c7490cd1
[gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents:
7106
diff
changeset
|
1917 } |
9220c7490cd1
[gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents:
7106
diff
changeset
|
1918 if (!t) |
9220c7490cd1
[gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents:
7106
diff
changeset
|
1919 break; |
9220c7490cd1
[gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents:
7106
diff
changeset
|
1920 t++; |
9220c7490cd1
[gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents:
7106
diff
changeset
|
1921 } |
9220c7490cd1
[gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents:
7106
diff
changeset
|
1922 } |
9220c7490cd1
[gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents:
7106
diff
changeset
|
1923 } else if (!g_ascii_strncasecmp(c, "mailto:", 7)) { |
9220c7490cd1
[gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents:
7106
diff
changeset
|
1924 t = c; |
9220c7490cd1
[gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents:
7106
diff
changeset
|
1925 while (1) { |
10461 | 1926 if (badchar(*t) || badentity(t)) { |
7107
9220c7490cd1
[gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents:
7106
diff
changeset
|
1927 if (*(t - 1) == '.') |
9220c7490cd1
[gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents:
7106
diff
changeset
|
1928 t--; |
10902 | 1929 url_buf = g_strndup(c, t - c); |
8918 | 1930 tmpurlbuf = gaim_unescape_html(url_buf); |
7107
9220c7490cd1
[gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents:
7106
diff
changeset
|
1931 g_string_append_printf(ret, "<A HREF=\"%s\">%s</A>", |
8918 | 1932 tmpurlbuf, url_buf); |
10902 | 1933 g_free(url_buf); |
8918 | 1934 g_free(tmpurlbuf); |
7107
9220c7490cd1
[gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents:
7106
diff
changeset
|
1935 c = t; |
9220c7490cd1
[gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents:
7106
diff
changeset
|
1936 break; |
9220c7490cd1
[gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents:
7106
diff
changeset
|
1937 } |
9220c7490cd1
[gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents:
7106
diff
changeset
|
1938 if (!t) |
9220c7490cd1
[gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents:
7106
diff
changeset
|
1939 break; |
9220c7490cd1
[gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents:
7106
diff
changeset
|
1940 t++; |
9220c7490cd1
[gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents:
7106
diff
changeset
|
1941 |
9220c7490cd1
[gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents:
7106
diff
changeset
|
1942 } |
9220c7490cd1
[gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents:
7106
diff
changeset
|
1943 } else if (c != text && (*c == '@')) { |
9220c7490cd1
[gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents:
7106
diff
changeset
|
1944 int flag; |
10905 | 1945 GString *gurl_buf = NULL; |
7107
9220c7490cd1
[gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents:
7106
diff
changeset
|
1946 const char illegal_chars[] = "!@#$%^&*()[]{}/|\\<>\":;\r\n \0"; |
9220c7490cd1
[gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents:
7106
diff
changeset
|
1947 |
9220c7490cd1
[gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents:
7106
diff
changeset
|
1948 if (strchr(illegal_chars,*(c - 1)) || strchr(illegal_chars, *(c + 1))) |
9220c7490cd1
[gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents:
7106
diff
changeset
|
1949 flag = 0; |
10902 | 1950 else { |
7107
9220c7490cd1
[gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents:
7106
diff
changeset
|
1951 flag = 1; |
10902 | 1952 gurl_buf = g_string_new(""); |
1953 } | |
7107
9220c7490cd1
[gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents:
7106
diff
changeset
|
1954 |
9220c7490cd1
[gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents:
7106
diff
changeset
|
1955 t = c; |
9220c7490cd1
[gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents:
7106
diff
changeset
|
1956 while (flag) { |
9222 | 1957 /* iterate backwards grabbing the local part of an email address */ |
1958 g = g_utf8_get_char(t); | |
1959 if (badchar(*t) || (g >= 127) || (*t == '(') || | |
11176 | 1960 ((*t == ';') && ((t > (text+2) && (!g_ascii_strncasecmp(t - 3, "<", 4) || |
1961 !g_ascii_strncasecmp(t - 3, ">", 4))) || | |
1962 (t > (text+4) && (!g_ascii_strncasecmp(t - 5, """, 6)))))) { | |
9222 | 1963 /* local part will already be part of ret, strip it out */ |
1964 ret = g_string_truncate(ret, ret->len - (c - t)); | |
1965 ret = g_string_append_unichar(ret, g); | |
7107
9220c7490cd1
[gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents:
7106
diff
changeset
|
1966 break; |
9220c7490cd1
[gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents:
7106
diff
changeset
|
1967 } else { |
9222 | 1968 g_string_prepend_unichar(gurl_buf, g); |
1969 t = g_utf8_find_prev_char(text, t); | |
7107
9220c7490cd1
[gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents:
7106
diff
changeset
|
1970 if (t < text) { |
9220c7490cd1
[gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents:
7106
diff
changeset
|
1971 ret = g_string_assign(ret, ""); |
9220c7490cd1
[gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents:
7106
diff
changeset
|
1972 break; |
9220c7490cd1
[gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents:
7106
diff
changeset
|
1973 } |
9220c7490cd1
[gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents:
7106
diff
changeset
|
1974 } |
9220c7490cd1
[gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents:
7106
diff
changeset
|
1975 } |
9220c7490cd1
[gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents:
7106
diff
changeset
|
1976 |
9222 | 1977 t = g_utf8_find_next_char(c, NULL); |
7107
9220c7490cd1
[gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents:
7106
diff
changeset
|
1978 |
9220c7490cd1
[gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents:
7106
diff
changeset
|
1979 while (flag) { |
9222 | 1980 /* iterate forwards grabbing the domain part of an email address */ |
1981 g = g_utf8_get_char(t); | |
10461 | 1982 if (badchar(*t) || (g >= 127) || (*t == ')') || badentity(t)) { |
7107
9220c7490cd1
[gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents:
7106
diff
changeset
|
1983 char *d; |
9220c7490cd1
[gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents:
7106
diff
changeset
|
1984 |
10902 | 1985 url_buf = g_string_free(gurl_buf, FALSE); |
9222 | 1986 |
1987 /* strip off trailing periods */ | |
10902 | 1988 if (strlen(url_buf) > 0) { |
1989 for (d = url_buf + strlen(url_buf) - 1; *d == '.'; d--, t--) | |
1990 *d = '\0'; | |
1991 } | |
7107
9220c7490cd1
[gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents:
7106
diff
changeset
|
1992 |
8918 | 1993 tmpurlbuf = gaim_unescape_html(url_buf); |
9045 | 1994 if (gaim_email_is_valid(tmpurlbuf)) { |
1995 g_string_append_printf(ret, "<A HREF=\"mailto:%s\">%s</A>", | |
1996 tmpurlbuf, url_buf); | |
1997 } else { | |
1998 g_string_append(ret, url_buf); | |
1999 } | |
10902 | 2000 g_free(url_buf); |
8918 | 2001 g_free(tmpurlbuf); |
7107
9220c7490cd1
[gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents:
7106
diff
changeset
|
2002 c = t; |
9220c7490cd1
[gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents:
7106
diff
changeset
|
2003 |
9220c7490cd1
[gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents:
7106
diff
changeset
|
2004 break; |
9220c7490cd1
[gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents:
7106
diff
changeset
|
2005 } else { |
9222 | 2006 g_string_append_unichar(gurl_buf, g); |
2007 t = g_utf8_find_next_char(t, NULL); | |
7107
9220c7490cd1
[gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents:
7106
diff
changeset
|
2008 } |
9220c7490cd1
[gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents:
7106
diff
changeset
|
2009 } |
9222 | 2010 } |
2011 | |
2012 if(*c == ')' && !inside_html) { | |
2013 inside_paren--; | |
2014 ret = g_string_append_c(ret, *c); | |
2015 c++; | |
7107
9220c7490cd1
[gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents:
7106
diff
changeset
|
2016 } |
9220c7490cd1
[gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents:
7106
diff
changeset
|
2017 |
9220c7490cd1
[gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents:
7106
diff
changeset
|
2018 if (*c == 0) |
9220c7490cd1
[gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents:
7106
diff
changeset
|
2019 break; |
9220c7490cd1
[gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents:
7106
diff
changeset
|
2020 |
9220c7490cd1
[gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents:
7106
diff
changeset
|
2021 ret = g_string_append_c(ret, *c); |
9220c7490cd1
[gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents:
7106
diff
changeset
|
2022 c++; |
9220c7490cd1
[gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents:
7106
diff
changeset
|
2023 |
9220c7490cd1
[gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents:
7106
diff
changeset
|
2024 } |
9220c7490cd1
[gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents:
7106
diff
changeset
|
2025 tmp = ret->str; |
9220c7490cd1
[gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents:
7106
diff
changeset
|
2026 g_string_free(ret, FALSE); |
9220c7490cd1
[gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents:
7106
diff
changeset
|
2027 return tmp; |
9220c7490cd1
[gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents:
7106
diff
changeset
|
2028 } |
9220c7490cd1
[gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents:
7106
diff
changeset
|
2029 |
8163 | 2030 char * |
8442 | 2031 gaim_unescape_html(const char *html) { |
2032 char *unescaped = NULL; | |
2033 | |
2034 if (html != NULL) { | |
2035 const char *c = html; | |
2036 GString *ret = g_string_new(""); | |
2037 while (*c) { | |
2038 if (!strncmp(c, "&", 5)) { | |
2039 ret = g_string_append_c(ret, '&'); | |
2040 c += 5; | |
2041 } else if (!strncmp(c, "<", 4)) { | |
2042 ret = g_string_append_c(ret, '<'); | |
2043 c += 4; | |
2044 } else if (!strncmp(c, ">", 4)) { | |
2045 ret = g_string_append_c(ret, '>'); | |
2046 c += 4; | |
2047 } else if (!strncmp(c, """, 6)) { | |
2048 ret = g_string_append_c(ret, '"'); | |
2049 c += 6; | |
8625 | 2050 } else if (!strncmp(c, "'", 6)) { |
2051 ret = g_string_append_c(ret, '\''); | |
2052 c += 6; | |
8500 | 2053 } else if (!strncmp(c, "<br>", 4)) { |
2054 ret = g_string_append_c(ret, '\n'); | |
2055 c += 4; | |
8442 | 2056 } else { |
2057 ret = g_string_append_c(ret, *c); | |
2058 c++; | |
2059 } | |
2060 } | |
2061 | |
2062 unescaped = ret->str; | |
2063 g_string_free(ret, FALSE); | |
2064 } | |
2065 return unescaped; | |
2066 | |
2067 } | |
2068 | |
9175 | 2069 char * |
2070 gaim_markup_slice(const char *str, guint x, guint y) | |
2071 { | |
2072 GString *ret; | |
2073 GQueue *q; | |
2074 guint z = 0; | |
2075 gboolean appended = FALSE; | |
2076 gunichar c; | |
2077 char *tag; | |
2078 | |
2079 g_return_val_if_fail(x <= y, NULL); | |
2080 | |
2081 if (x == y) | |
2082 return g_strdup(""); | |
2083 | |
2084 ret = g_string_new(""); | |
2085 q = g_queue_new(); | |
2086 | |
2087 while (*str && (z < y)) { | |
2088 c = g_utf8_get_char(str); | |
2089 | |
2090 if (c == '<') { | |
2091 char *end = strchr(str, '>'); | |
2092 | |
2093 if (!end) { | |
2094 g_string_free(ret, TRUE); | |
2095 while ((tag = g_queue_pop_head(q))) | |
2096 g_free(tag); | |
2097 g_queue_free(q); | |
2098 return NULL; | |
2099 } | |
2100 | |
2101 if (!g_ascii_strncasecmp(str, "<img ", 5)) { | |
2102 z += strlen("[Image]"); | |
2103 } else if (!g_ascii_strncasecmp(str, "<br", 3)) { | |
2104 z += 1; | |
2105 } else if (!g_ascii_strncasecmp(str, "<hr>", 4)) { | |
2106 z += strlen("\n---\n"); | |
2107 } else if (!g_ascii_strncasecmp(str, "</", 2)) { | |
2108 /* pop stack */ | |
2109 char *tmp; | |
2110 | |
2111 tmp = g_queue_pop_head(q); | |
2112 if (tmp) | |
2113 g_free(tmp); | |
2114 /* z += 0; */ | |
2115 } else { | |
2116 /* push it unto the stack */ | |
2117 char *tmp; | |
2118 | |
2119 tmp = g_strndup(str, end - str + 1); | |
2120 g_queue_push_head(q, tmp); | |
2121 /* z += 0; */ | |
2122 } | |
2123 | |
13643 | 2124 if (z >= x) { |
9175 | 2125 g_string_append_len(ret, str, end - str + 1); |
2126 } | |
2127 | |
2128 str = end; | |
2129 } else if (c == '&') { | |
2130 char *end = strchr(str, ';'); | |
2131 if (!end) { | |
2132 g_string_free(ret, TRUE); | |
2133 while ((tag = g_queue_pop_head(q))) | |
2134 g_free(tag); | |
2135 g_queue_free(q); | |
2136 | |
2137 return NULL; | |
2138 } | |
2139 | |
2140 if (z >= x) | |
2141 g_string_append_len(ret, str, end - str + 1); | |
2142 | |
2143 z++; | |
2144 str = end; | |
2145 } else { | |
13643 | 2146 if (z == x && z > 0 && !appended) { |
2147 GList *l = q->tail; | |
2148 | |
2149 while (l) { | |
2150 tag = l->data; | |
2151 g_string_append(ret, tag); | |
2152 l = l->prev; | |
2153 } | |
2154 appended = TRUE; | |
2155 } | |
2156 | |
9175 | 2157 if (z >= x) |
2158 g_string_append_unichar(ret, c); | |
2159 z++; | |
2160 } | |
2161 | |
2162 str = g_utf8_next_char(str); | |
2163 } | |
2164 | |
2165 while ((tag = g_queue_pop_head(q))) { | |
2166 char *name; | |
2167 | |
2168 name = gaim_markup_get_tag_name(tag); | |
2169 g_string_append_printf(ret, "</%s>", name); | |
2170 g_free(name); | |
2171 g_free(tag); | |
2172 } | |
2173 | |
2174 g_queue_free(q); | |
2175 return g_string_free(ret, FALSE); | |
2176 } | |
2177 | |
2178 char * | |
2179 gaim_markup_get_tag_name(const char *tag) | |
2180 { | |
2181 int i; | |
2182 g_return_val_if_fail(tag != NULL, NULL); | |
2183 g_return_val_if_fail(*tag == '<', NULL); | |
2184 | |
2185 for (i = 1; tag[i]; i++) | |
2186 if (tag[i] == '>' || tag[i] == ' ' || tag[i] == '/') | |
2187 break; | |
2188 | |
13643 | 2189 return g_strndup(tag+1, i-1); |
9175 | 2190 } |
2191 | |
7108
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2192 /************************************************************************** |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2193 * Path/Filename Functions |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2194 **************************************************************************/ |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2195 const char * |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2196 gaim_home_dir(void) |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2197 { |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2198 #ifndef _WIN32 |
11665 | 2199 return g_get_home_dir(); |
7108
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2200 #else |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2201 return wgaim_data_dir(); |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2202 #endif |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2203 } |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2204 |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2205 /* returns a string of the form ~/.gaim, where ~ is replaced by the user's home |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2206 * dir. Note that there is no trailing slash after .gaim. */ |
10332 | 2207 const char * |
7108
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2208 gaim_user_dir(void) |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2209 { |
8596 | 2210 if (custom_home_dir != NULL && strlen(custom_home_dir) > 0) { |
2211 strcpy ((char*) &home_dir, (char*) &custom_home_dir); | |
2212 } else { | |
2213 const gchar *hd = gaim_home_dir(); | |
7108
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2214 |
8596 | 2215 if (hd) { |
9916 | 2216 g_strlcpy((char*) &home_dir, hd, sizeof(home_dir)); |
2217 g_strlcat((char*) &home_dir, G_DIR_SEPARATOR_S ".gaim", | |
2218 sizeof(home_dir)); | |
8596 | 2219 } |
7108
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2220 } |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2221 |
8596 | 2222 return home_dir; |
2223 } | |
2224 | |
10871 | 2225 void gaim_util_set_user_dir(const char *dir) |
8596 | 2226 { |
2227 if (dir != NULL && strlen(dir) > 0) { | |
9916 | 2228 g_strlcpy((char*) &custom_home_dir, dir, |
2229 sizeof(custom_home_dir)); | |
8596 | 2230 } |
7108
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2231 } |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2232 |
7622 | 2233 int gaim_build_dir (const char *path, int mode) |
7612 | 2234 { |
11361 | 2235 #if GLIB_CHECK_VERSION(2,8,0) |
2236 return g_mkdir_with_parents(path, mode); | |
2237 #else | |
7612 | 2238 char *dir, **components, delim[] = { G_DIR_SEPARATOR, '\0' }; |
2239 int cur, len; | |
2240 | |
7632 | 2241 g_return_val_if_fail(path != NULL, -1); |
7612 | 2242 |
2243 dir = g_new0(char, strlen(path) + 1); | |
7622 | 2244 components = g_strsplit(path, delim, -1); |
7612 | 2245 len = 0; |
2246 for (cur = 0; components[cur] != NULL; cur++) { | |
7633 | 2247 /* If you don't know what you're doing on both |
2248 * win32 and *NIX, stay the hell away from this code */ | |
2249 if(cur > 1) | |
2250 dir[len++] = G_DIR_SEPARATOR; | |
7612 | 2251 strcpy(dir + len, components[cur]); |
2252 len += strlen(components[cur]); | |
7633 | 2253 if(cur == 0) |
2254 dir[len++] = G_DIR_SEPARATOR; | |
7632 | 2255 |
2256 if(g_file_test(dir, G_FILE_TEST_IS_DIR)) { | |
2257 continue; | |
10948
747ef488c600
[gaim-migrate @ 12747]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10905
diff
changeset
|
2258 #ifdef _WIN32 |
747ef488c600
[gaim-migrate @ 12747]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10905
diff
changeset
|
2259 /* allow us to create subdirs on UNC paths |
747ef488c600
[gaim-migrate @ 12747]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10905
diff
changeset
|
2260 * (\\machinename\path\to\blah) |
747ef488c600
[gaim-migrate @ 12747]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10905
diff
changeset
|
2261 * g_file_test() doesn't work on "\\machinename" */ |
747ef488c600
[gaim-migrate @ 12747]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10905
diff
changeset
|
2262 } else if (cur == 2 && dir[0] == '\\' && dir[1] == '\\' |
747ef488c600
[gaim-migrate @ 12747]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10905
diff
changeset
|
2263 && components[cur + 1] != NULL) { |
747ef488c600
[gaim-migrate @ 12747]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10905
diff
changeset
|
2264 continue; |
747ef488c600
[gaim-migrate @ 12747]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10905
diff
changeset
|
2265 #endif |
7632 | 2266 } else if(g_file_test(dir, G_FILE_TEST_EXISTS)) { |
9716 | 2267 gaim_debug_warning("build_dir", "bad path: %s\n", path); |
7612 | 2268 g_strfreev(components); |
2269 g_free(dir); | |
2270 return -1; | |
2271 } | |
2272 | |
10589
0f7452b1f777
[gaim-migrate @ 11994]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10569
diff
changeset
|
2273 if (g_mkdir(dir, mode) < 0) { |
9716 | 2274 gaim_debug_warning("build_dir", "mkdir: %s\n", strerror(errno)); |
7612 | 2275 g_strfreev(components); |
2276 g_free(dir); | |
2277 return -1; | |
2278 } | |
2279 } | |
2280 | |
2281 g_strfreev(components); | |
2282 g_free(dir); | |
2283 return 0; | |
11361 | 2284 #endif |
7612 | 2285 } |
2286 | |
7108
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2287 /* |
10414 | 2288 * This function is long and beautiful, like my--um, yeah. Anyway, |
2289 * it includes lots of error checking so as we don't overwrite | |
2290 * people's settings if there is a problem writing the new values. | |
2291 */ | |
2292 gboolean | |
10415 | 2293 gaim_util_write_data_to_file(const char *filename, const char *data, size_t size) |
10414 | 2294 { |
2295 const char *user_dir = gaim_user_dir(); | |
2296 gchar *filename_temp, *filename_full; | |
2297 FILE *file; | |
10415 | 2298 size_t real_size, byteswritten; |
10414 | 2299 struct stat st; |
2300 | |
2301 g_return_val_if_fail(user_dir != NULL, FALSE); | |
2302 | |
2303 gaim_debug_info("util", "Writing file %s to directory %s\n", | |
2304 filename, user_dir); | |
2305 | |
2306 /* Ensure the user directory exists */ | |
2307 if (!g_file_test(user_dir, G_FILE_TEST_IS_DIR)) | |
2308 { | |
10589
0f7452b1f777
[gaim-migrate @ 11994]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10569
diff
changeset
|
2309 if (g_mkdir(user_dir, S_IRUSR | S_IWUSR | S_IXUSR) == -1) |
10414 | 2310 { |
2311 gaim_debug_error("util", "Error creating directory %s: %s\n", | |
2312 user_dir, strerror(errno)); | |
2313 return FALSE; | |
2314 } | |
2315 } | |
2316 | |
10415 | 2317 filename_full = g_strdup_printf("%s" G_DIR_SEPARATOR_S "%s", user_dir, filename); |
10414 | 2318 filename_temp = g_strdup_printf("%s.save", filename_full); |
2319 | |
2320 /* Remove an old temporary file, if one exists */ | |
2321 if (g_file_test(filename_temp, G_FILE_TEST_EXISTS)) | |
2322 { | |
10589
0f7452b1f777
[gaim-migrate @ 11994]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10569
diff
changeset
|
2323 if (g_unlink(filename_temp) == -1) |
10414 | 2324 { |
2325 gaim_debug_error("util", "Error removing old file %s: %s\n", | |
2326 filename_temp, strerror(errno)); | |
2327 } | |
2328 } | |
2329 | |
2330 /* Open file */ | |
10589
0f7452b1f777
[gaim-migrate @ 11994]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10569
diff
changeset
|
2331 file = g_fopen(filename_temp, "wb"); |
10414 | 2332 if (file == NULL) |
2333 { | |
2334 gaim_debug_error("util", "Error opening file %s for writing: %s\n", | |
2335 filename_temp, strerror(errno)); | |
2336 g_free(filename_full); | |
2337 g_free(filename_temp); | |
2338 return FALSE; | |
2339 } | |
2340 | |
2341 /* Write to file */ | |
10415 | 2342 real_size = (size == -1) ? strlen(data) : size; |
2343 byteswritten = fwrite(data, 1, real_size, file); | |
10414 | 2344 |
2345 /* Close file */ | |
2346 if (fclose(file) != 0) | |
2347 { | |
2348 gaim_debug_error("util", "Error closing file %s: %s\n", | |
2349 filename_temp, strerror(errno)); | |
2350 g_free(filename_full); | |
2351 g_free(filename_temp); | |
2352 return FALSE; | |
2353 } | |
2354 | |
2355 /* Ensure the file is the correct size */ | |
10415 | 2356 if (byteswritten != real_size) |
10414 | 2357 { |
11656
f9c5480ad0ce
[gaim-migrate @ 13940]
Richard Laager <rlaager@wiktel.com>
parents:
11552
diff
changeset
|
2358 gaim_debug_error("util", "Error writing to file %s: Wrote %" G_GSIZE_FORMAT " bytes " |
f9c5480ad0ce
[gaim-migrate @ 13940]
Richard Laager <rlaager@wiktel.com>
parents:
11552
diff
changeset
|
2359 "but should have written %" G_GSIZE_FORMAT "; is your disk full?\n", |
10415 | 2360 filename_temp, byteswritten, real_size); |
10414 | 2361 g_free(filename_full); |
2362 g_free(filename_temp); | |
2363 return FALSE; | |
2364 } | |
2365 /* Use stat to be absolutely sure. */ | |
10589
0f7452b1f777
[gaim-migrate @ 11994]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10569
diff
changeset
|
2366 if ((g_stat(filename_temp, &st) == -1) || (st.st_size != real_size)) |
10414 | 2367 { |
2368 gaim_debug_error("util", "Error writing data to file %s: " | |
2369 "Incomplete file written; is your disk full?\n", | |
2370 filename_temp); | |
2371 g_free(filename_full); | |
2372 g_free(filename_temp); | |
2373 return FALSE; | |
2374 } | |
2375 | |
12622
b7860c9902f2
[gaim-migrate @ 14958]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12620
diff
changeset
|
2376 #ifndef _WIN32 |
10414 | 2377 /* Set file permissions */ |
2378 if (chmod(filename_temp, S_IRUSR | S_IWUSR) == -1) | |
2379 { | |
2380 gaim_debug_error("util", "Error setting permissions of file %s: %s\n", | |
2381 filename_temp, strerror(errno)); | |
2382 } | |
12622
b7860c9902f2
[gaim-migrate @ 14958]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12620
diff
changeset
|
2383 #endif |
10414 | 2384 |
2385 /* Rename to the REAL name */ | |
10589
0f7452b1f777
[gaim-migrate @ 11994]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10569
diff
changeset
|
2386 if (g_rename(filename_temp, filename_full) == -1) |
10414 | 2387 { |
2388 gaim_debug_error("util", "Error renaming %s to %s: %s\n", | |
2389 filename_temp, filename_full, strerror(errno)); | |
2390 } | |
2391 | |
2392 g_free(filename_full); | |
2393 g_free(filename_temp); | |
2394 | |
2395 return TRUE; | |
2396 } | |
2397 | |
10425 | 2398 xmlnode * |
2399 gaim_util_read_xml_from_file(const char *filename, const char *description) | |
2400 { | |
2401 const char *user_dir = gaim_user_dir(); | |
2402 gchar *filename_full; | |
2403 GError *error; | |
2404 gchar *contents = NULL; | |
2405 gsize length; | |
2406 xmlnode *node = NULL; | |
2407 | |
2408 g_return_val_if_fail(user_dir != NULL, NULL); | |
2409 | |
2410 gaim_debug_info("util", "Reading file %s from directory %s\n", | |
2411 filename, user_dir); | |
2412 | |
2413 filename_full = g_build_filename(user_dir, filename, NULL); | |
2414 | |
2415 if (!g_file_test(filename_full, G_FILE_TEST_EXISTS)) | |
2416 { | |
2417 gaim_debug_info("util", "File %s does not exist (this is not " | |
2418 "necessarily an error)\n", filename_full); | |
2419 g_free(filename_full); | |
2420 return NULL; | |
2421 } | |
2422 | |
2423 if (!g_file_get_contents(filename_full, &contents, &length, &error)) | |
2424 { | |
2425 gaim_debug_error("util", "Error reading file %s: %s\n", | |
2426 filename_full, error->message); | |
2427 g_error_free(error); | |
2428 } | |
2429 | |
2430 if ((contents != NULL) && (length > 0)) | |
2431 { | |
2432 node = xmlnode_from_str(contents, length); | |
2433 | |
2434 /* If we were unable to parse the file then save its contents to a backup file */ | |
2435 if (node == NULL) | |
2436 { | |
2437 gchar *filename_temp; | |
2438 | |
2439 filename_temp = g_strdup_printf("%s~", filename); | |
2440 gaim_debug_error("util", "Error parsing file %s. Rrenaming old " | |
2441 "file to %s\n", filename_full, filename_temp); | |
2442 gaim_util_write_data_to_file(filename_temp, contents, length); | |
2443 g_free(filename_temp); | |
2444 } | |
2445 | |
2446 g_free(contents); | |
2447 } | |
2448 | |
2449 /* If we could not parse the file then show the user an error message */ | |
2450 if (node == NULL) | |
2451 { | |
2452 gchar *title, *msg; | |
2453 title = g_strdup_printf(_("Error Reading %s"), filename); | |
2454 msg = g_strdup_printf(_("An error was encountered reading your " | |
2455 "%s. They have not been loaded, and the old file " | |
11493 | 2456 "has been renamed to %s~."), description, filename_full); |
10425 | 2457 gaim_notify_error(NULL, NULL, title, msg); |
2458 g_free(title); | |
2459 g_free(msg); | |
2460 } | |
2461 | |
2462 g_free(filename_full); | |
2463 | |
2464 return node; | |
2465 } | |
2466 | |
10414 | 2467 /* |
7108
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2468 * Like mkstemp() but returns a file pointer, uses a pre-set template, |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2469 * uses the semantics of tempnam() for the directory to use and allocates |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2470 * the space for the filepath. |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2471 * |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2472 * Caller is responsible for closing the file and removing it when done, |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2473 * as well as freeing the space pointed-to by "path" with g_free(). |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2474 * |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2475 * Returns NULL on failure and cleans up after itself if so. |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2476 */ |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2477 static const char *gaim_mkstemp_templ = {"gaimXXXXXX"}; |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2478 |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2479 FILE * |
10203
7ff9b8b22e7d
[gaim-migrate @ 11324]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
10112
diff
changeset
|
2480 gaim_mkstemp(char **fpath, gboolean binary) |
7108
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2481 { |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2482 const gchar *tmpdir; |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2483 #ifndef _WIN32 |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2484 int fd; |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2485 #endif |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2486 FILE *fp = NULL; |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2487 |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2488 g_return_val_if_fail(fpath != NULL, NULL); |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2489 |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2490 if((tmpdir = (gchar*)g_get_tmp_dir()) != NULL) { |
9427 | 2491 if((*fpath = g_strdup_printf("%s" G_DIR_SEPARATOR_S "%s", tmpdir, gaim_mkstemp_templ)) != NULL) { |
7108
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2492 #ifdef _WIN32 |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2493 char* result = _mktemp( *fpath ); |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2494 if( result == NULL ) |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2495 gaim_debug(GAIM_DEBUG_ERROR, "gaim_mkstemp", |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2496 "Problem creating the template\n"); |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2497 else |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2498 { |
10589
0f7452b1f777
[gaim-migrate @ 11994]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10569
diff
changeset
|
2499 if( (fp = g_fopen( result, binary?"wb+":"w+")) == NULL ) { |
7108
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2500 gaim_debug(GAIM_DEBUG_ERROR, "gaim_mkstemp", |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2501 "Couldn't fopen() %s\n", result); |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2502 } |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2503 } |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2504 #else |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2505 if((fd = mkstemp(*fpath)) == -1) { |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2506 gaim_debug(GAIM_DEBUG_ERROR, "gaim_mkstemp", |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2507 "Couldn't make \"%s\", error: %d\n", |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2508 *fpath, errno); |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2509 } else { |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2510 if((fp = fdopen(fd, "r+")) == NULL) { |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2511 close(fd); |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2512 gaim_debug(GAIM_DEBUG_ERROR, "gaim_mkstemp", |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2513 "Couldn't fdopen(), error: %d\n", errno); |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2514 } |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2515 } |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2516 #endif |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2517 if(!fp) { |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2518 g_free(*fpath); |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2519 *fpath = NULL; |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2520 } |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2521 } |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2522 } else { |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2523 gaim_debug(GAIM_DEBUG_ERROR, "gaim_mkstemp", |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2524 "g_get_tmp_dir() failed!"); |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2525 } |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2526 |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2527 return fp; |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2528 } |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2529 |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2530 gboolean |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2531 gaim_program_is_valid(const char *program) |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2532 { |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2533 GError *error = NULL; |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2534 char **argv; |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2535 gchar *progname; |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2536 gboolean is_valid = FALSE; |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2537 |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2538 g_return_val_if_fail(program != NULL, FALSE); |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2539 g_return_val_if_fail(*program != '\0', FALSE); |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2540 |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2541 if (!g_shell_parse_argv(program, NULL, &argv, &error)) { |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2542 gaim_debug(GAIM_DEBUG_ERROR, "program_is_valid", |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2543 "Could not parse program '%s': %s\n", |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2544 program, error->message); |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2545 g_error_free(error); |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2546 return FALSE; |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2547 } |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2548 |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2549 if (argv == NULL) { |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2550 return FALSE; |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2551 } |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2552 |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2553 progname = g_find_program_in_path(argv[0]); |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2554 is_valid = (progname != NULL); |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2555 |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2556 g_strfreev(argv); |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2557 g_free(progname); |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2558 |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2559 return is_valid; |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2560 } |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2561 |
11878 | 2562 |
2563 gboolean | |
2564 gaim_running_gnome(void) | |
2565 { | |
13615
6bf81c38b458
[gaim-migrate @ 16001]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13613
diff
changeset
|
2566 #ifndef _WIN32 |
11878 | 2567 gchar *tmp = g_find_program_in_path("gnome-open"); |
12483
54448bd2ccc7
[gaim-migrate @ 14795]
Richard Laager <rlaager@wiktel.com>
parents:
12110
diff
changeset
|
2568 |
54448bd2ccc7
[gaim-migrate @ 14795]
Richard Laager <rlaager@wiktel.com>
parents:
12110
diff
changeset
|
2569 if (tmp == NULL) |
54448bd2ccc7
[gaim-migrate @ 14795]
Richard Laager <rlaager@wiktel.com>
parents:
12110
diff
changeset
|
2570 return FALSE; |
54448bd2ccc7
[gaim-migrate @ 14795]
Richard Laager <rlaager@wiktel.com>
parents:
12110
diff
changeset
|
2571 g_free(tmp); |
54448bd2ccc7
[gaim-migrate @ 14795]
Richard Laager <rlaager@wiktel.com>
parents:
12110
diff
changeset
|
2572 |
54448bd2ccc7
[gaim-migrate @ 14795]
Richard Laager <rlaager@wiktel.com>
parents:
12110
diff
changeset
|
2573 return (g_getenv("GNOME_DESKTOP_SESSION_ID") != NULL); |
13615
6bf81c38b458
[gaim-migrate @ 16001]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13613
diff
changeset
|
2574 #else |
6bf81c38b458
[gaim-migrate @ 16001]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13613
diff
changeset
|
2575 return FALSE; |
6bf81c38b458
[gaim-migrate @ 16001]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13613
diff
changeset
|
2576 #endif |
12483
54448bd2ccc7
[gaim-migrate @ 14795]
Richard Laager <rlaager@wiktel.com>
parents:
12110
diff
changeset
|
2577 } |
54448bd2ccc7
[gaim-migrate @ 14795]
Richard Laager <rlaager@wiktel.com>
parents:
12110
diff
changeset
|
2578 |
54448bd2ccc7
[gaim-migrate @ 14795]
Richard Laager <rlaager@wiktel.com>
parents:
12110
diff
changeset
|
2579 gboolean |
54448bd2ccc7
[gaim-migrate @ 14795]
Richard Laager <rlaager@wiktel.com>
parents:
12110
diff
changeset
|
2580 gaim_running_kde(void) |
54448bd2ccc7
[gaim-migrate @ 14795]
Richard Laager <rlaager@wiktel.com>
parents:
12110
diff
changeset
|
2581 { |
13615
6bf81c38b458
[gaim-migrate @ 16001]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13613
diff
changeset
|
2582 #ifndef _WIN32 |
12483
54448bd2ccc7
[gaim-migrate @ 14795]
Richard Laager <rlaager@wiktel.com>
parents:
12110
diff
changeset
|
2583 gchar *tmp = g_find_program_in_path("kfmclient"); |
54448bd2ccc7
[gaim-migrate @ 14795]
Richard Laager <rlaager@wiktel.com>
parents:
12110
diff
changeset
|
2584 const char *session; |
54448bd2ccc7
[gaim-migrate @ 14795]
Richard Laager <rlaager@wiktel.com>
parents:
12110
diff
changeset
|
2585 |
54448bd2ccc7
[gaim-migrate @ 14795]
Richard Laager <rlaager@wiktel.com>
parents:
12110
diff
changeset
|
2586 if (tmp == NULL) |
54448bd2ccc7
[gaim-migrate @ 14795]
Richard Laager <rlaager@wiktel.com>
parents:
12110
diff
changeset
|
2587 return FALSE; |
54448bd2ccc7
[gaim-migrate @ 14795]
Richard Laager <rlaager@wiktel.com>
parents:
12110
diff
changeset
|
2588 g_free(tmp); |
54448bd2ccc7
[gaim-migrate @ 14795]
Richard Laager <rlaager@wiktel.com>
parents:
12110
diff
changeset
|
2589 |
54448bd2ccc7
[gaim-migrate @ 14795]
Richard Laager <rlaager@wiktel.com>
parents:
12110
diff
changeset
|
2590 session = g_getenv("KDE_FULL_SESSION"); |
54448bd2ccc7
[gaim-migrate @ 14795]
Richard Laager <rlaager@wiktel.com>
parents:
12110
diff
changeset
|
2591 if (session != NULL && !strcmp(session, "true")) |
11878 | 2592 return TRUE; |
12483
54448bd2ccc7
[gaim-migrate @ 14795]
Richard Laager <rlaager@wiktel.com>
parents:
12110
diff
changeset
|
2593 |
54448bd2ccc7
[gaim-migrate @ 14795]
Richard Laager <rlaager@wiktel.com>
parents:
12110
diff
changeset
|
2594 /* If you run Gaim from Konsole under !KDE, this will provide a |
54448bd2ccc7
[gaim-migrate @ 14795]
Richard Laager <rlaager@wiktel.com>
parents:
12110
diff
changeset
|
2595 * a false positive. Since we do the GNOME checks first, this is |
54448bd2ccc7
[gaim-migrate @ 14795]
Richard Laager <rlaager@wiktel.com>
parents:
12110
diff
changeset
|
2596 * only a problem if you're running something !(KDE || GNOME) and |
54448bd2ccc7
[gaim-migrate @ 14795]
Richard Laager <rlaager@wiktel.com>
parents:
12110
diff
changeset
|
2597 * you run Gaim from Konsole. This really shouldn't be a problem. */ |
54448bd2ccc7
[gaim-migrate @ 14795]
Richard Laager <rlaager@wiktel.com>
parents:
12110
diff
changeset
|
2598 return ((g_getenv("KDEDIR") != NULL) || g_getenv("KDEDIRS") != NULL); |
13615
6bf81c38b458
[gaim-migrate @ 16001]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13613
diff
changeset
|
2599 #else |
6bf81c38b458
[gaim-migrate @ 16001]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13613
diff
changeset
|
2600 return FALSE; |
6bf81c38b458
[gaim-migrate @ 16001]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13613
diff
changeset
|
2601 #endif |
11878 | 2602 } |
2603 | |
7108
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2604 char * |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2605 gaim_fd_get_ip(int fd) |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2606 { |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2607 struct sockaddr addr; |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2608 socklen_t namelen = sizeof(addr); |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2609 |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2610 g_return_val_if_fail(fd != 0, NULL); |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2611 |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2612 if (getsockname(fd, &addr, &namelen)) |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2613 return NULL; |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2614 |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2615 return g_strdup(inet_ntoa(((struct sockaddr_in *)&addr)->sin_addr)); |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2616 } |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2617 |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2618 |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2619 /************************************************************************** |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2620 * String Functions |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2621 **************************************************************************/ |
7162 | 2622 const char * |
11153 | 2623 gaim_normalize(const GaimAccount *account, const char *str) |
7108
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2624 { |
7430 | 2625 const char *ret = NULL; |
7261 | 2626 |
13619
667af11a6411
[gaim-migrate @ 16005]
Richard Laager <rlaager@wiktel.com>
parents:
13615
diff
changeset
|
2627 if (account != NULL) |
13613
723fd573111c
[gaim-migrate @ 15999]
Richard Laager <rlaager@wiktel.com>
parents:
13585
diff
changeset
|
2628 { |
723fd573111c
[gaim-migrate @ 15999]
Richard Laager <rlaager@wiktel.com>
parents:
13585
diff
changeset
|
2629 GaimPlugin *prpl = gaim_find_prpl(gaim_account_get_protocol_id(account)); |
723fd573111c
[gaim-migrate @ 15999]
Richard Laager <rlaager@wiktel.com>
parents:
13585
diff
changeset
|
2630 |
723fd573111c
[gaim-migrate @ 15999]
Richard Laager <rlaager@wiktel.com>
parents:
13585
diff
changeset
|
2631 if (prpl != NULL) |
723fd573111c
[gaim-migrate @ 15999]
Richard Laager <rlaager@wiktel.com>
parents:
13585
diff
changeset
|
2632 { |
723fd573111c
[gaim-migrate @ 15999]
Richard Laager <rlaager@wiktel.com>
parents:
13585
diff
changeset
|
2633 GaimPluginProtocolInfo *prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(prpl); |
723fd573111c
[gaim-migrate @ 15999]
Richard Laager <rlaager@wiktel.com>
parents:
13585
diff
changeset
|
2634 |
723fd573111c
[gaim-migrate @ 15999]
Richard Laager <rlaager@wiktel.com>
parents:
13585
diff
changeset
|
2635 if(prpl_info && prpl_info->normalize) |
723fd573111c
[gaim-migrate @ 15999]
Richard Laager <rlaager@wiktel.com>
parents:
13585
diff
changeset
|
2636 ret = prpl_info->normalize(account, str); |
723fd573111c
[gaim-migrate @ 15999]
Richard Laager <rlaager@wiktel.com>
parents:
13585
diff
changeset
|
2637 } |
723fd573111c
[gaim-migrate @ 15999]
Richard Laager <rlaager@wiktel.com>
parents:
13585
diff
changeset
|
2638 } |
723fd573111c
[gaim-migrate @ 15999]
Richard Laager <rlaager@wiktel.com>
parents:
13585
diff
changeset
|
2639 |
13620
78c2c6a462d7
[gaim-migrate @ 16006]
Richard Laager <rlaager@wiktel.com>
parents:
13619
diff
changeset
|
2640 if (ret == NULL) |
11153 | 2641 { |
7261 | 2642 static char buf[BUF_LEN]; |
2643 char *tmp; | |
11153 | 2644 |
2645 tmp = g_utf8_normalize(str, -1, G_NORMALIZE_DEFAULT); | |
7261 | 2646 g_snprintf(buf, sizeof(buf), "%s", tmp); |
2647 g_free(tmp); | |
7108
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2648 |
7430 | 2649 ret = buf; |
7261 | 2650 } |
11153 | 2651 |
7430 | 2652 return ret; |
7108
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2653 } |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2654 |
11153 | 2655 /* |
2656 * You probably don't want to call this directly, it is | |
2657 * mainly for use as a PRPL callback function. See the | |
2658 * comments in util.h. | |
2659 */ | |
2660 const char * | |
2661 gaim_normalize_nocase(const GaimAccount *account, const char *str) | |
2662 { | |
2663 static char buf[BUF_LEN]; | |
2664 char *tmp1, *tmp2; | |
2665 | |
2666 g_return_val_if_fail(str != NULL, NULL); | |
2667 | |
2668 tmp1 = g_utf8_strdown(str, -1); | |
2669 tmp2 = g_utf8_normalize(tmp1, -1, G_NORMALIZE_DEFAULT); | |
13645
073bc6da6403
[gaim-migrate @ 16043]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13643
diff
changeset
|
2670 g_snprintf(buf, sizeof(buf), "%s", tmp2 ? tmp2 : ""); |
11153 | 2671 g_free(tmp2); |
2672 g_free(tmp1); | |
2673 | |
2674 return buf; | |
2675 } | |
2676 | |
8700 | 2677 gchar * |
8341 | 2678 gaim_strdup_withhtml(const gchar *src) |
7108
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2679 { |
8341 | 2680 gulong destsize, i, j; |
2681 gchar *dest; | |
7108
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2682 |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2683 g_return_val_if_fail(src != NULL, NULL); |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2684 |
8341 | 2685 /* New length is (length of src) + (number of \n's * 3) + 1 */ |
2686 for (i = 0, j = 0; src[i] != '\0'; i++) | |
2687 if (src[i] == '\n') | |
2688 j++; | |
2689 | |
2690 destsize = i + (j * 3) + 1; | |
2691 dest = g_malloc(destsize); | |
7108
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2692 |
8341 | 2693 /* Copy stuff, ignoring \r's, because they are dumb */ |
2694 for (i = 0, j = 0; src[i] != '\0'; i++) { | |
2695 if (src[i] == '\n') { | |
2696 strcpy(&dest[j], "<BR>"); | |
2697 j += 4; | |
2698 } else if (src[i] != '\r') | |
2699 dest[j++] = src[i]; | |
2700 } | |
2701 | |
2702 dest[destsize-1] = '\0'; | |
7108
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2703 |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2704 return dest; |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2705 } |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2706 |
7628 | 2707 gboolean |
2708 gaim_str_has_prefix(const char *s, const char *p) | |
2709 { | |
11780 | 2710 #if GLIB_CHECK_VERSION(2,2,0) |
2711 return g_str_has_prefix(s, p); | |
2712 #else | |
13095
5a7c4570d768
[gaim-migrate @ 15457]
Richard Laager <rlaager@wiktel.com>
parents:
13089
diff
changeset
|
2713 g_return_val_if_fail(s != NULL, FALSE); |
5a7c4570d768
[gaim-migrate @ 15457]
Richard Laager <rlaager@wiktel.com>
parents:
13089
diff
changeset
|
2714 g_return_val_if_fail(p != NULL, FALSE); |
5a7c4570d768
[gaim-migrate @ 15457]
Richard Laager <rlaager@wiktel.com>
parents:
13089
diff
changeset
|
2715 |
5a7c4570d768
[gaim-migrate @ 15457]
Richard Laager <rlaager@wiktel.com>
parents:
13089
diff
changeset
|
2716 return (!strncmp(s, p, strlen(p))); |
11780 | 2717 #endif |
7628 | 2718 } |
2719 | |
2720 gboolean | |
2721 gaim_str_has_suffix(const char *s, const char *x) | |
2722 { | |
11780 | 2723 #if GLIB_CHECK_VERSION(2,2,0) |
2724 return g_str_has_suffix(s, x); | |
2725 #else | |
13095
5a7c4570d768
[gaim-migrate @ 15457]
Richard Laager <rlaager@wiktel.com>
parents:
13089
diff
changeset
|
2726 int off; |
5a7c4570d768
[gaim-migrate @ 15457]
Richard Laager <rlaager@wiktel.com>
parents:
13089
diff
changeset
|
2727 |
5a7c4570d768
[gaim-migrate @ 15457]
Richard Laager <rlaager@wiktel.com>
parents:
13089
diff
changeset
|
2728 g_return_val_if_fail(s != NULL, FALSE); |
5a7c4570d768
[gaim-migrate @ 15457]
Richard Laager <rlaager@wiktel.com>
parents:
13089
diff
changeset
|
2729 g_return_val_if_fail(x != NULL, FALSE); |
5a7c4570d768
[gaim-migrate @ 15457]
Richard Laager <rlaager@wiktel.com>
parents:
13089
diff
changeset
|
2730 |
5a7c4570d768
[gaim-migrate @ 15457]
Richard Laager <rlaager@wiktel.com>
parents:
13089
diff
changeset
|
2731 off = strlen(s) - strlen(x); |
5a7c4570d768
[gaim-migrate @ 15457]
Richard Laager <rlaager@wiktel.com>
parents:
13089
diff
changeset
|
2732 return (off >= 0 && !strcmp(s + off, x)); |
11780 | 2733 #endif |
7628 | 2734 } |
2735 | |
7108
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2736 char * |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2737 gaim_str_add_cr(const char *text) |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2738 { |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2739 char *ret = NULL; |
7631 | 2740 int count = 0, j; |
2741 guint i; | |
7108
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2742 |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2743 g_return_val_if_fail(text != NULL, NULL); |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2744 |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2745 if (text[0] == '\n') |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2746 count++; |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2747 for (i = 1; i < strlen(text); i++) |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2748 if (text[i] == '\n' && text[i - 1] != '\r') |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2749 count++; |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2750 |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2751 if (count == 0) |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2752 return g_strdup(text); |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2753 |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2754 ret = g_malloc0(strlen(text) + count + 1); |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2755 |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2756 i = 0; j = 0; |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2757 if (text[i] == '\n') |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2758 ret[j++] = '\r'; |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2759 ret[j++] = text[i++]; |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2760 for (; i < strlen(text); i++) { |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2761 if (text[i] == '\n' && text[i - 1] != '\r') |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2762 ret[j++] = '\r'; |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2763 ret[j++] = text[i]; |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2764 } |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2765 |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2766 gaim_debug_misc("gaim_str_add_cr", "got: %s, leaving with %s\n", |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2767 text, ret); |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2768 |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2769 return ret; |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2770 } |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2771 |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2772 void |
11920 | 2773 gaim_str_strip_char(char *text, char thechar) |
7108
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2774 { |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2775 int i, j; |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2776 |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2777 g_return_if_fail(text != NULL); |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2778 |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2779 for (i = 0, j = 0; text[i]; i++) |
11920 | 2780 if (text[i] != thechar) |
11142 | 2781 text[j++] = text[i]; |
2782 | |
2783 text[j++] = '\0'; | |
7108
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2784 } |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2785 |
11920 | 2786 void |
2787 gaim_util_chrreplace(char *string, char delimiter, | |
2788 char replacement) | |
2789 { | |
2790 int i = 0; | |
2791 | |
2792 g_return_if_fail(string != NULL); | |
2793 | |
2794 while (string[i] != '\0') | |
2795 { | |
2796 if (string[i] == delimiter) | |
2797 string[i] = replacement; | |
2798 i++; | |
2799 } | |
2800 } | |
2801 | |
8341 | 2802 gchar * |
7108
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2803 gaim_strreplace(const char *string, const char *delimiter, |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2804 const char *replacement) |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2805 { |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2806 gchar **split; |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2807 gchar *ret; |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2808 |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2809 g_return_val_if_fail(string != NULL, NULL); |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2810 g_return_val_if_fail(delimiter != NULL, NULL); |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2811 g_return_val_if_fail(replacement != NULL, NULL); |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2812 |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2813 split = g_strsplit(string, delimiter, 0); |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2814 ret = g_strjoinv(replacement, split); |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2815 g_strfreev(split); |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2816 |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2817 return ret; |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2818 } |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2819 |
8341 | 2820 gchar * |
2821 gaim_strcasereplace(const char *string, const char *delimiter, | |
2822 const char *replacement) | |
2823 { | |
2824 gchar *ret; | |
2825 int length_del, length_rep, i, j; | |
2826 | |
2827 g_return_val_if_fail(string != NULL, NULL); | |
2828 g_return_val_if_fail(delimiter != NULL, NULL); | |
2829 g_return_val_if_fail(replacement != NULL, NULL); | |
2830 | |
2831 length_del = strlen(delimiter); | |
2832 length_rep = strlen(replacement); | |
2833 | |
2834 /* Count how many times the delimiter appears */ | |
2835 i = 0; /* position in the source string */ | |
8735
92cbf9713795
[gaim-migrate @ 9490]
Christian Hammond <chipx86@chipx86.com>
parents:
8700
diff
changeset
|
2836 j = 0; /* number of occurrences of "delimiter" */ |
8341 | 2837 while (string[i] != '\0') { |
2838 if (!strncasecmp(&string[i], delimiter, length_del)) { | |
2839 i += length_del; | |
2840 j += length_rep; | |
2841 } else { | |
2842 i++; | |
2843 j++; | |
2844 } | |
2845 } | |
2846 | |
2847 ret = g_malloc(j+1); | |
2848 | |
2849 i = 0; /* position in the source string */ | |
2850 j = 0; /* position in the destination string */ | |
2851 while (string[i] != '\0') { | |
2852 if (!strncasecmp(&string[i], delimiter, length_del)) { | |
2853 strncpy(&ret[j], replacement, length_rep); | |
2854 i += length_del; | |
2855 j += length_rep; | |
2856 } else { | |
2857 ret[j] = string[i]; | |
2858 i++; | |
2859 j++; | |
2860 } | |
2861 } | |
2862 | |
2863 ret[j] = '\0'; | |
2864 | |
2865 return ret; | |
2866 } | |
2867 | |
7108
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2868 const char * |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2869 gaim_strcasestr(const char *haystack, const char *needle) |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2870 { |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2871 size_t hlen, nlen; |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2872 const char *tmp, *ret; |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2873 |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2874 g_return_val_if_fail(haystack != NULL, NULL); |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2875 g_return_val_if_fail(needle != NULL, NULL); |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2876 |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2877 hlen = strlen(haystack); |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2878 nlen = strlen(needle); |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2879 tmp = haystack, |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2880 ret = NULL; |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2881 |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2882 g_return_val_if_fail(hlen > 0, NULL); |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2883 g_return_val_if_fail(nlen > 0, NULL); |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2884 |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2885 while (*tmp && !ret) { |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2886 if (!g_ascii_strncasecmp(needle, tmp, nlen)) |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2887 ret = tmp; |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2888 else |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2889 tmp++; |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2890 } |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2891 |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2892 return ret; |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2893 } |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2894 |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2895 char * |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2896 gaim_str_size_to_units(size_t size) |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2897 { |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2898 static const char *size_str[4] = { "bytes", "KB", "MB", "GB" }; |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2899 float size_mag; |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2900 int size_index = 0; |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2901 |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2902 if (size == -1) { |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2903 return g_strdup(_("Calculating...")); |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2904 } |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2905 else if (size == 0) { |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2906 return g_strdup(_("Unknown.")); |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2907 } |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2908 else { |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2909 size_mag = (float)size; |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2910 |
10569
12349012610b
[gaim-migrate @ 11957]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10506
diff
changeset
|
2911 while ((size_index < 3) && (size_mag > 1024)) { |
7108
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2912 size_mag /= 1024; |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2913 size_index++; |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2914 } |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2915 |
10103 | 2916 if (size_index == 0) { |
11656
f9c5480ad0ce
[gaim-migrate @ 13940]
Richard Laager <rlaager@wiktel.com>
parents:
11552
diff
changeset
|
2917 return g_strdup_printf("%" G_GSIZE_FORMAT " %s", size, size_str[size_index]); |
10103 | 2918 } else { |
2919 return g_strdup_printf("%.2f %s", size_mag, size_str[size_index]); | |
2920 } | |
7108
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2921 } |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2922 } |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2923 |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2924 char * |
9233
0c352d0e4ddc
[gaim-migrate @ 10029]
Christian Hammond <chipx86@chipx86.com>
parents:
9230
diff
changeset
|
2925 gaim_str_seconds_to_string(guint secs) |
7108
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2926 { |
13097
f1bf8989bbf2
[gaim-migrate @ 15459]
Richard Laager <rlaager@wiktel.com>
parents:
13095
diff
changeset
|
2927 char *ret = NULL; |
9233
0c352d0e4ddc
[gaim-migrate @ 10029]
Christian Hammond <chipx86@chipx86.com>
parents:
9230
diff
changeset
|
2928 guint days, hrs, mins; |
0c352d0e4ddc
[gaim-migrate @ 10029]
Christian Hammond <chipx86@chipx86.com>
parents:
9230
diff
changeset
|
2929 |
9424 | 2930 if (secs < 60) |
2931 { | |
13097
f1bf8989bbf2
[gaim-migrate @ 15459]
Richard Laager <rlaager@wiktel.com>
parents:
13095
diff
changeset
|
2932 return g_strdup_printf(ngettext("%d second", "%d seconds", secs), secs); |
9424 | 2933 } |
2934 | |
9233
0c352d0e4ddc
[gaim-migrate @ 10029]
Christian Hammond <chipx86@chipx86.com>
parents:
9230
diff
changeset
|
2935 days = secs / (60 * 60 * 24); |
0c352d0e4ddc
[gaim-migrate @ 10029]
Christian Hammond <chipx86@chipx86.com>
parents:
9230
diff
changeset
|
2936 secs = secs % (60 * 60 * 24); |
0c352d0e4ddc
[gaim-migrate @ 10029]
Christian Hammond <chipx86@chipx86.com>
parents:
9230
diff
changeset
|
2937 hrs = secs / (60 * 60); |
0c352d0e4ddc
[gaim-migrate @ 10029]
Christian Hammond <chipx86@chipx86.com>
parents:
9230
diff
changeset
|
2938 secs = secs % (60 * 60); |
0c352d0e4ddc
[gaim-migrate @ 10029]
Christian Hammond <chipx86@chipx86.com>
parents:
9230
diff
changeset
|
2939 mins = secs / 60; |
0c352d0e4ddc
[gaim-migrate @ 10029]
Christian Hammond <chipx86@chipx86.com>
parents:
9230
diff
changeset
|
2940 secs = secs % 60; |
0c352d0e4ddc
[gaim-migrate @ 10029]
Christian Hammond <chipx86@chipx86.com>
parents:
9230
diff
changeset
|
2941 |
0c352d0e4ddc
[gaim-migrate @ 10029]
Christian Hammond <chipx86@chipx86.com>
parents:
9230
diff
changeset
|
2942 if (days > 0) |
0c352d0e4ddc
[gaim-migrate @ 10029]
Christian Hammond <chipx86@chipx86.com>
parents:
9230
diff
changeset
|
2943 { |
13097
f1bf8989bbf2
[gaim-migrate @ 15459]
Richard Laager <rlaager@wiktel.com>
parents:
13095
diff
changeset
|
2944 ret = g_strdup_printf(ngettext("%d day", "%d days", days), days); |
7108
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2945 } |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2946 |
9233
0c352d0e4ddc
[gaim-migrate @ 10029]
Christian Hammond <chipx86@chipx86.com>
parents:
9230
diff
changeset
|
2947 if (hrs > 0) |
0c352d0e4ddc
[gaim-migrate @ 10029]
Christian Hammond <chipx86@chipx86.com>
parents:
9230
diff
changeset
|
2948 { |
13097
f1bf8989bbf2
[gaim-migrate @ 15459]
Richard Laager <rlaager@wiktel.com>
parents:
13095
diff
changeset
|
2949 if (ret != NULL) |
f1bf8989bbf2
[gaim-migrate @ 15459]
Richard Laager <rlaager@wiktel.com>
parents:
13095
diff
changeset
|
2950 { |
f1bf8989bbf2
[gaim-migrate @ 15459]
Richard Laager <rlaager@wiktel.com>
parents:
13095
diff
changeset
|
2951 char *tmp = g_strdup_printf( |
f1bf8989bbf2
[gaim-migrate @ 15459]
Richard Laager <rlaager@wiktel.com>
parents:
13095
diff
changeset
|
2952 ngettext("%s, %d hour", "%s, %d hours", hrs), |
f1bf8989bbf2
[gaim-migrate @ 15459]
Richard Laager <rlaager@wiktel.com>
parents:
13095
diff
changeset
|
2953 ret, hrs); |
f1bf8989bbf2
[gaim-migrate @ 15459]
Richard Laager <rlaager@wiktel.com>
parents:
13095
diff
changeset
|
2954 g_free(ret); |
f1bf8989bbf2
[gaim-migrate @ 15459]
Richard Laager <rlaager@wiktel.com>
parents:
13095
diff
changeset
|
2955 ret = tmp; |
f1bf8989bbf2
[gaim-migrate @ 15459]
Richard Laager <rlaager@wiktel.com>
parents:
13095
diff
changeset
|
2956 } |
f1bf8989bbf2
[gaim-migrate @ 15459]
Richard Laager <rlaager@wiktel.com>
parents:
13095
diff
changeset
|
2957 else |
f1bf8989bbf2
[gaim-migrate @ 15459]
Richard Laager <rlaager@wiktel.com>
parents:
13095
diff
changeset
|
2958 ret = g_strdup_printf(ngettext("%d hour", "%d hours", hrs), hrs); |
9233
0c352d0e4ddc
[gaim-migrate @ 10029]
Christian Hammond <chipx86@chipx86.com>
parents:
9230
diff
changeset
|
2959 } |
0c352d0e4ddc
[gaim-migrate @ 10029]
Christian Hammond <chipx86@chipx86.com>
parents:
9230
diff
changeset
|
2960 |
0c352d0e4ddc
[gaim-migrate @ 10029]
Christian Hammond <chipx86@chipx86.com>
parents:
9230
diff
changeset
|
2961 if (mins > 0) |
0c352d0e4ddc
[gaim-migrate @ 10029]
Christian Hammond <chipx86@chipx86.com>
parents:
9230
diff
changeset
|
2962 { |
13097
f1bf8989bbf2
[gaim-migrate @ 15459]
Richard Laager <rlaager@wiktel.com>
parents:
13095
diff
changeset
|
2963 if (ret != NULL) |
f1bf8989bbf2
[gaim-migrate @ 15459]
Richard Laager <rlaager@wiktel.com>
parents:
13095
diff
changeset
|
2964 { |
f1bf8989bbf2
[gaim-migrate @ 15459]
Richard Laager <rlaager@wiktel.com>
parents:
13095
diff
changeset
|
2965 char *tmp = g_strdup_printf( |
f1bf8989bbf2
[gaim-migrate @ 15459]
Richard Laager <rlaager@wiktel.com>
parents:
13095
diff
changeset
|
2966 ngettext("%s, %d minute", "%s, %d minutes", mins), |
f1bf8989bbf2
[gaim-migrate @ 15459]
Richard Laager <rlaager@wiktel.com>
parents:
13095
diff
changeset
|
2967 ret, mins); |
f1bf8989bbf2
[gaim-migrate @ 15459]
Richard Laager <rlaager@wiktel.com>
parents:
13095
diff
changeset
|
2968 g_free(ret); |
f1bf8989bbf2
[gaim-migrate @ 15459]
Richard Laager <rlaager@wiktel.com>
parents:
13095
diff
changeset
|
2969 ret = tmp; |
f1bf8989bbf2
[gaim-migrate @ 15459]
Richard Laager <rlaager@wiktel.com>
parents:
13095
diff
changeset
|
2970 } |
f1bf8989bbf2
[gaim-migrate @ 15459]
Richard Laager <rlaager@wiktel.com>
parents:
13095
diff
changeset
|
2971 else |
f1bf8989bbf2
[gaim-migrate @ 15459]
Richard Laager <rlaager@wiktel.com>
parents:
13095
diff
changeset
|
2972 ret = g_strdup_printf(ngettext("%d minute", "%d minutes", mins), mins); |
9233
0c352d0e4ddc
[gaim-migrate @ 10029]
Christian Hammond <chipx86@chipx86.com>
parents:
9230
diff
changeset
|
2973 } |
0c352d0e4ddc
[gaim-migrate @ 10029]
Christian Hammond <chipx86@chipx86.com>
parents:
9230
diff
changeset
|
2974 |
13097
f1bf8989bbf2
[gaim-migrate @ 15459]
Richard Laager <rlaager@wiktel.com>
parents:
13095
diff
changeset
|
2975 return ret; |
7108
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2976 } |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
2977 |
9277 | 2978 |
2979 char * | |
2980 gaim_str_binary_to_ascii(const unsigned char *binary, guint len) | |
2981 { | |
2982 GString *ret; | |
2983 guint i; | |
2984 | |
2985 g_return_val_if_fail(len > 0, NULL); | |
2986 | |
2987 ret = g_string_sized_new(len); | |
2988 | |
2989 for (i = 0; i < len; i++) | |
2990 if (binary[i] < 32 || binary[i] > 126) | |
2991 g_string_append_printf(ret, "\\x%02hhx", binary[i]); | |
2992 else if (binary[i] == '\\') | |
2993 g_string_append(ret, "\\\\"); | |
2994 else | |
2995 g_string_append_c(ret, binary[i]); | |
2996 | |
2997 return g_string_free(ret, FALSE); | |
2998 } | |
2999 | |
7108
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
3000 /************************************************************************** |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
3001 * URI/URL Functions |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
3002 **************************************************************************/ |
7095
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7094
diff
changeset
|
3003 gboolean |
7094
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3004 gaim_url_parse(const char *url, char **ret_host, int *ret_port, |
9227
9171e528d7e5
[gaim-migrate @ 10023]
Christian Hammond <chipx86@chipx86.com>
parents:
9222
diff
changeset
|
3005 char **ret_path, char **ret_user, char **ret_passwd) |
7094
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3006 { |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3007 char scan_info[255]; |
8118 | 3008 char port_str[6]; |
7094
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3009 int f; |
9341 | 3010 const char *at, *slash; |
7094
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3011 const char *turl; |
9227
9171e528d7e5
[gaim-migrate @ 10023]
Christian Hammond <chipx86@chipx86.com>
parents:
9222
diff
changeset
|
3012 char host[256], path[256], user[256], passwd[256]; |
7094
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3013 int port = 0; |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3014 /* hyphen at end includes it in control set */ |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3015 static char addr_ctrl[] = "A-Za-z0-9.-"; |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3016 static char port_ctrl[] = "0-9"; |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3017 static char page_ctrl[] = "A-Za-z0-9.~_/:*!@&%%?=+^-"; |
9227
9171e528d7e5
[gaim-migrate @ 10023]
Christian Hammond <chipx86@chipx86.com>
parents:
9222
diff
changeset
|
3018 static char user_ctrl[] = "A-Za-z0-9.~_/*!&%%?=+^-"; |
9171e528d7e5
[gaim-migrate @ 10023]
Christian Hammond <chipx86@chipx86.com>
parents:
9222
diff
changeset
|
3019 static char passwd_ctrl[] = "A-Za-z0-9.~_/*!&%%?=+^-"; |
7094
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3020 |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3021 g_return_val_if_fail(url != NULL, FALSE); |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3022 |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3023 if ((turl = strstr(url, "http://")) != NULL || |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3024 (turl = strstr(url, "HTTP://")) != NULL) |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3025 { |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3026 turl += 7; |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3027 url = turl; |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3028 } |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3029 |
9227
9171e528d7e5
[gaim-migrate @ 10023]
Christian Hammond <chipx86@chipx86.com>
parents:
9222
diff
changeset
|
3030 /* parse out authentication information if supplied */ |
9341 | 3031 /* Only care about @ char BEFORE the first / */ |
3032 at = strchr(url, '@'); | |
3033 slash = strchr(url, '/'); | |
3034 if ((at != NULL) && | |
3035 (((slash != NULL) && (strlen(at) > strlen(slash))) || | |
3036 (slash == NULL))) { | |
9227
9171e528d7e5
[gaim-migrate @ 10023]
Christian Hammond <chipx86@chipx86.com>
parents:
9222
diff
changeset
|
3037 g_snprintf(scan_info, sizeof(scan_info), |
9171e528d7e5
[gaim-migrate @ 10023]
Christian Hammond <chipx86@chipx86.com>
parents:
9222
diff
changeset
|
3038 "%%255[%s]:%%255[%s]^@", user_ctrl, passwd_ctrl); |
9171e528d7e5
[gaim-migrate @ 10023]
Christian Hammond <chipx86@chipx86.com>
parents:
9222
diff
changeset
|
3039 f = sscanf(url, scan_info, user, passwd); |
9171e528d7e5
[gaim-migrate @ 10023]
Christian Hammond <chipx86@chipx86.com>
parents:
9222
diff
changeset
|
3040 |
9171e528d7e5
[gaim-migrate @ 10023]
Christian Hammond <chipx86@chipx86.com>
parents:
9222
diff
changeset
|
3041 if (f ==1 ) { |
9171e528d7e5
[gaim-migrate @ 10023]
Christian Hammond <chipx86@chipx86.com>
parents:
9222
diff
changeset
|
3042 /* No passwd, possibly just username supplied */ |
9171e528d7e5
[gaim-migrate @ 10023]
Christian Hammond <chipx86@chipx86.com>
parents:
9222
diff
changeset
|
3043 g_snprintf(scan_info, sizeof(scan_info), |
9171e528d7e5
[gaim-migrate @ 10023]
Christian Hammond <chipx86@chipx86.com>
parents:
9222
diff
changeset
|
3044 "%%255[%s]^@", user_ctrl); |
9171e528d7e5
[gaim-migrate @ 10023]
Christian Hammond <chipx86@chipx86.com>
parents:
9222
diff
changeset
|
3045 f = sscanf(url, scan_info, user); |
9171e528d7e5
[gaim-migrate @ 10023]
Christian Hammond <chipx86@chipx86.com>
parents:
9222
diff
changeset
|
3046 *passwd = '\0'; |
9171e528d7e5
[gaim-migrate @ 10023]
Christian Hammond <chipx86@chipx86.com>
parents:
9222
diff
changeset
|
3047 } |
9171e528d7e5
[gaim-migrate @ 10023]
Christian Hammond <chipx86@chipx86.com>
parents:
9222
diff
changeset
|
3048 |
9230 | 3049 url = at+1; /* move pointer after the @ char */ |
9227
9171e528d7e5
[gaim-migrate @ 10023]
Christian Hammond <chipx86@chipx86.com>
parents:
9222
diff
changeset
|
3050 } else { |
9171e528d7e5
[gaim-migrate @ 10023]
Christian Hammond <chipx86@chipx86.com>
parents:
9222
diff
changeset
|
3051 *user = '\0'; |
9171e528d7e5
[gaim-migrate @ 10023]
Christian Hammond <chipx86@chipx86.com>
parents:
9222
diff
changeset
|
3052 *passwd = '\0'; |
9171e528d7e5
[gaim-migrate @ 10023]
Christian Hammond <chipx86@chipx86.com>
parents:
9222
diff
changeset
|
3053 } |
9171e528d7e5
[gaim-migrate @ 10023]
Christian Hammond <chipx86@chipx86.com>
parents:
9222
diff
changeset
|
3054 |
7094
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3055 g_snprintf(scan_info, sizeof(scan_info), |
8118 | 3056 "%%255[%s]:%%5[%s]/%%255[%s]", addr_ctrl, port_ctrl, page_ctrl); |
7094
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3057 |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3058 f = sscanf(url, scan_info, host, port_str, path); |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3059 |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3060 if (f == 1) |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3061 { |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3062 g_snprintf(scan_info, sizeof(scan_info), |
8118 | 3063 "%%255[%s]/%%255[%s]", |
7094
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3064 addr_ctrl, page_ctrl); |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3065 f = sscanf(url, scan_info, host, path); |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3066 g_snprintf(port_str, sizeof(port_str), "80"); |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3067 } |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3068 |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3069 if (f == 1) |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3070 *path = '\0'; |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3071 |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3072 sscanf(port_str, "%d", &port); |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3073 |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3074 if (ret_host != NULL) *ret_host = g_strdup(host); |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3075 if (ret_port != NULL) *ret_port = port; |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3076 if (ret_path != NULL) *ret_path = g_strdup(path); |
9227
9171e528d7e5
[gaim-migrate @ 10023]
Christian Hammond <chipx86@chipx86.com>
parents:
9222
diff
changeset
|
3077 if (ret_user != NULL) *ret_user = g_strdup(user); |
9171e528d7e5
[gaim-migrate @ 10023]
Christian Hammond <chipx86@chipx86.com>
parents:
9222
diff
changeset
|
3078 if (ret_passwd != NULL) *ret_passwd = g_strdup(passwd); |
7094
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3079 |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3080 return TRUE; |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3081 } |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3082 |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3083 static void |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3084 destroy_fetch_url_data(GaimFetchUrlData *gfud) |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3085 { |
12887
4229503f1cd9
[gaim-migrate @ 15240]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12880
diff
changeset
|
3086 g_free(gfud->webdata); |
4229503f1cd9
[gaim-migrate @ 15240]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12880
diff
changeset
|
3087 g_free(gfud->url); |
4229503f1cd9
[gaim-migrate @ 15240]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12880
diff
changeset
|
3088 g_free(gfud->user_agent); |
4229503f1cd9
[gaim-migrate @ 15240]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12880
diff
changeset
|
3089 g_free(gfud->website.address); |
4229503f1cd9
[gaim-migrate @ 15240]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12880
diff
changeset
|
3090 g_free(gfud->website.page); |
4229503f1cd9
[gaim-migrate @ 15240]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12880
diff
changeset
|
3091 g_free(gfud->website.user); |
4229503f1cd9
[gaim-migrate @ 15240]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12880
diff
changeset
|
3092 g_free(gfud->website.passwd); |
4229503f1cd9
[gaim-migrate @ 15240]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12880
diff
changeset
|
3093 g_free(gfud->request); |
7094
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3094 |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3095 g_free(gfud); |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3096 } |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3097 |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3098 static gboolean |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3099 parse_redirect(const char *data, size_t data_len, gint sock, |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3100 GaimFetchUrlData *gfud) |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3101 { |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3102 gchar *s; |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3103 |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3104 if ((s = g_strstr_len(data, data_len, "Location: ")) != NULL) |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3105 { |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3106 gchar *new_url, *temp_url, *end; |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3107 gboolean full; |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3108 int len; |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3109 |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3110 s += strlen("Location: "); |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3111 end = strchr(s, '\r'); |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3112 |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3113 /* Just in case :) */ |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3114 if (end == NULL) |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3115 end = strchr(s, '\n'); |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3116 |
10623 | 3117 if (end == NULL) |
3118 return FALSE; | |
3119 | |
7094
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3120 len = end - s; |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3121 |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3122 new_url = g_malloc(len + 1); |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3123 strncpy(new_url, s, len); |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3124 new_url[len] = '\0'; |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3125 |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3126 full = gfud->full; |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3127 |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3128 if (*new_url == '/' || g_strstr_len(new_url, len, "://") == NULL) |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3129 { |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3130 temp_url = new_url; |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3131 |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3132 new_url = g_strdup_printf("%s:%d%s", gfud->website.address, |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3133 gfud->website.port, temp_url); |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3134 |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3135 g_free(temp_url); |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3136 |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3137 full = FALSE; |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3138 } |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3139 |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3140 /* Close the existing stuff. */ |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3141 gaim_input_remove(gfud->inpa); |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3142 close(sock); |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3143 |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3144 gaim_debug_info("gaim_url_fetch", "Redirecting to %s\n", new_url); |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3145 |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3146 /* Try again, with this new location. */ |
12887
4229503f1cd9
[gaim-migrate @ 15240]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12880
diff
changeset
|
3147 gaim_url_fetch_request(new_url, full, gfud->user_agent, |
13367
85b2ba4aa606
[gaim-migrate @ 15740]
Richard Laager <rlaager@wiktel.com>
parents:
13356
diff
changeset
|
3148 gfud->http11, NULL, gfud->include_headers, |
12887
4229503f1cd9
[gaim-migrate @ 15240]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12880
diff
changeset
|
3149 gfud->callback, gfud->user_data); |
7094
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3150 |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3151 /* Free up. */ |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3152 g_free(new_url); |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3153 destroy_fetch_url_data(gfud); |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3154 |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3155 return TRUE; |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3156 } |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3157 |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3158 return FALSE; |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3159 } |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3160 |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3161 static size_t |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3162 parse_content_len(const char *data, size_t data_len) |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3163 { |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3164 size_t content_len = 0; |
9240 | 3165 const char *p = NULL; |
3166 | |
3167 /* This is still technically wrong, since headers are case-insensitive | |
3168 * [RFC 2616, section 4.2], though this ought to catch the normal case. | |
3169 * Note: data is _not_ nul-terminated. | |
3170 */ | |
13520
c836ba676c7c
[gaim-migrate @ 15896]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13499
diff
changeset
|
3171 if(data_len > 16) { |
c836ba676c7c
[gaim-migrate @ 15896]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13499
diff
changeset
|
3172 p = (strncmp(data, "Content-Length: ", 16) == 0) ? data : NULL; |
c836ba676c7c
[gaim-migrate @ 15896]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13499
diff
changeset
|
3173 if(!p) |
12887
4229503f1cd9
[gaim-migrate @ 15240]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12880
diff
changeset
|
3174 p = (strncmp(data, "CONTENT-LENGTH: ", 16) == 0) |
4229503f1cd9
[gaim-migrate @ 15240]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12880
diff
changeset
|
3175 ? data : NULL; |
13520
c836ba676c7c
[gaim-migrate @ 15896]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13499
diff
changeset
|
3176 if(!p) { |
12887
4229503f1cd9
[gaim-migrate @ 15240]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12880
diff
changeset
|
3177 p = g_strstr_len(data, data_len, "\nContent-Length: "); |
4229503f1cd9
[gaim-migrate @ 15240]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12880
diff
changeset
|
3178 if (p) |
4229503f1cd9
[gaim-migrate @ 15240]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12880
diff
changeset
|
3179 p++; |
4229503f1cd9
[gaim-migrate @ 15240]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12880
diff
changeset
|
3180 } |
13520
c836ba676c7c
[gaim-migrate @ 15896]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13499
diff
changeset
|
3181 if(!p) { |
12887
4229503f1cd9
[gaim-migrate @ 15240]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12880
diff
changeset
|
3182 p = g_strstr_len(data, data_len, "\nCONTENT-LENGTH: "); |
4229503f1cd9
[gaim-migrate @ 15240]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12880
diff
changeset
|
3183 if (p) |
4229503f1cd9
[gaim-migrate @ 15240]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12880
diff
changeset
|
3184 p++; |
4229503f1cd9
[gaim-migrate @ 15240]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12880
diff
changeset
|
3185 } |
4229503f1cd9
[gaim-migrate @ 15240]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12880
diff
changeset
|
3186 |
13520
c836ba676c7c
[gaim-migrate @ 15896]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13499
diff
changeset
|
3187 if(p) |
12887
4229503f1cd9
[gaim-migrate @ 15240]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12880
diff
changeset
|
3188 p += 16; |
9240 | 3189 } |
3190 | |
3191 /* If we can find a Content-Length header at all, try to sscanf it. | |
3192 * Response headers should end with at least \r\n, so sscanf is safe, | |
3193 * if we make sure that there is indeed a \n in our header. | |
3194 */ | |
3195 if (p && g_strstr_len(p, data_len - (p - data), "\n")) { | |
12887
4229503f1cd9
[gaim-migrate @ 15240]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12880
diff
changeset
|
3196 sscanf(p, "%" G_GSIZE_FORMAT, &content_len); |
9818 | 3197 gaim_debug_misc("parse_content_len", "parsed %u\n", content_len); |
9240 | 3198 } |
7094
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3199 |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3200 return content_len; |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3201 } |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3202 |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13163
diff
changeset
|
3203 |
7094
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3204 static void |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3205 url_fetched_cb(gpointer url_data, gint sock, GaimInputCondition cond) |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3206 { |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3207 GaimFetchUrlData *gfud = url_data; |
12109
936e3b7cd864
[gaim-migrate @ 14409]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11920
diff
changeset
|
3208 int len; |
936e3b7cd864
[gaim-migrate @ 14409]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11920
diff
changeset
|
3209 char buf[4096]; |
936e3b7cd864
[gaim-migrate @ 14409]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11920
diff
changeset
|
3210 char *data_cursor; |
9240 | 3211 gboolean got_eof = FALSE; |
7094
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3212 |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13163
diff
changeset
|
3213 while((len = read(sock, buf, sizeof(buf))) > 0) { |
12109
936e3b7cd864
[gaim-migrate @ 14409]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11920
diff
changeset
|
3214 /* If we've filled up our butfer, make it bigger */ |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13163
diff
changeset
|
3215 if((gfud->len + len) >= gfud->data_len) { |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13163
diff
changeset
|
3216 while((gfud->len + len) >= gfud->data_len) |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13163
diff
changeset
|
3217 gfud->data_len += sizeof(buf); |
7094
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3218 |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3219 gfud->webdata = g_realloc(gfud->webdata, gfud->data_len); |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3220 } |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3221 |
12109
936e3b7cd864
[gaim-migrate @ 14409]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11920
diff
changeset
|
3222 data_cursor = gfud->webdata + gfud->len; |
936e3b7cd864
[gaim-migrate @ 14409]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11920
diff
changeset
|
3223 |
936e3b7cd864
[gaim-migrate @ 14409]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11920
diff
changeset
|
3224 gfud->len += len; |
936e3b7cd864
[gaim-migrate @ 14409]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11920
diff
changeset
|
3225 |
936e3b7cd864
[gaim-migrate @ 14409]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11920
diff
changeset
|
3226 memcpy(data_cursor, buf, len); |
936e3b7cd864
[gaim-migrate @ 14409]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11920
diff
changeset
|
3227 |
11407 | 3228 gfud->webdata[gfud->len] = '\0'; |
7094
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3229 |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13163
diff
changeset
|
3230 if(!gfud->got_headers) { |
12109
936e3b7cd864
[gaim-migrate @ 14409]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11920
diff
changeset
|
3231 char *tmp; |
936e3b7cd864
[gaim-migrate @ 14409]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11920
diff
changeset
|
3232 |
936e3b7cd864
[gaim-migrate @ 14409]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11920
diff
changeset
|
3233 /** See if we've reached the end of the headers yet */ |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13163
diff
changeset
|
3234 if((tmp = strstr(gfud->webdata, "\r\n\r\n"))) { |
12109
936e3b7cd864
[gaim-migrate @ 14409]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11920
diff
changeset
|
3235 char * new_data; |
936e3b7cd864
[gaim-migrate @ 14409]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11920
diff
changeset
|
3236 guint header_len = (tmp + 4 - gfud->webdata); |
13520
c836ba676c7c
[gaim-migrate @ 15896]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13499
diff
changeset
|
3237 size_t content_len; |
12109
936e3b7cd864
[gaim-migrate @ 14409]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11920
diff
changeset
|
3238 |
936e3b7cd864
[gaim-migrate @ 14409]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11920
diff
changeset
|
3239 gaim_debug_misc("gaim_url_fetch", "Response headers: '%.*s'\n", |
936e3b7cd864
[gaim-migrate @ 14409]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11920
diff
changeset
|
3240 header_len, gfud->webdata); |
936e3b7cd864
[gaim-migrate @ 14409]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11920
diff
changeset
|
3241 |
936e3b7cd864
[gaim-migrate @ 14409]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11920
diff
changeset
|
3242 /* See if we can find a redirect. */ |
13520
c836ba676c7c
[gaim-migrate @ 15896]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13499
diff
changeset
|
3243 if(parse_redirect(gfud->webdata, header_len, sock, gfud)) |
12109
936e3b7cd864
[gaim-migrate @ 14409]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11920
diff
changeset
|
3244 return; |
936e3b7cd864
[gaim-migrate @ 14409]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11920
diff
changeset
|
3245 |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13163
diff
changeset
|
3246 gfud->got_headers = TRUE; |
12109
936e3b7cd864
[gaim-migrate @ 14409]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11920
diff
changeset
|
3247 |
936e3b7cd864
[gaim-migrate @ 14409]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11920
diff
changeset
|
3248 /* No redirect. See if we can find a content length. */ |
936e3b7cd864
[gaim-migrate @ 14409]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11920
diff
changeset
|
3249 content_len = parse_content_len(gfud->webdata, header_len); |
936e3b7cd864
[gaim-migrate @ 14409]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11920
diff
changeset
|
3250 |
13520
c836ba676c7c
[gaim-migrate @ 15896]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13499
diff
changeset
|
3251 if(content_len == 0) { |
12109
936e3b7cd864
[gaim-migrate @ 14409]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11920
diff
changeset
|
3252 /* We'll stick with an initial 8192 */ |
936e3b7cd864
[gaim-migrate @ 14409]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11920
diff
changeset
|
3253 content_len = 8192; |
13520
c836ba676c7c
[gaim-migrate @ 15896]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13499
diff
changeset
|
3254 } else { |
12109
936e3b7cd864
[gaim-migrate @ 14409]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11920
diff
changeset
|
3255 gfud->has_explicit_data_len = TRUE; |
936e3b7cd864
[gaim-migrate @ 14409]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11920
diff
changeset
|
3256 } |
936e3b7cd864
[gaim-migrate @ 14409]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11920
diff
changeset
|
3257 |
12887
4229503f1cd9
[gaim-migrate @ 15240]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12880
diff
changeset
|
3258 |
4229503f1cd9
[gaim-migrate @ 15240]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12880
diff
changeset
|
3259 /* If we're returning the headers too, we don't need to clean them out */ |
13520
c836ba676c7c
[gaim-migrate @ 15896]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13499
diff
changeset
|
3260 if(gfud->include_headers) { |
12887
4229503f1cd9
[gaim-migrate @ 15240]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12880
diff
changeset
|
3261 gfud->data_len = content_len + header_len; |
13520
c836ba676c7c
[gaim-migrate @ 15896]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13499
diff
changeset
|
3262 gfud->webdata = g_realloc(gfud->webdata, gfud->data_len); |
12907
5e338dda872f
[gaim-migrate @ 15260]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12887
diff
changeset
|
3263 } else { |
13520
c836ba676c7c
[gaim-migrate @ 15896]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13499
diff
changeset
|
3264 size_t body_len = 0; |
c836ba676c7c
[gaim-migrate @ 15896]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13499
diff
changeset
|
3265 |
c836ba676c7c
[gaim-migrate @ 15896]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13499
diff
changeset
|
3266 if(gfud->len > (header_len + 1)) |
12907
5e338dda872f
[gaim-migrate @ 15260]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12887
diff
changeset
|
3267 body_len = (gfud->len - header_len); |
5e338dda872f
[gaim-migrate @ 15260]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12887
diff
changeset
|
3268 |
13520
c836ba676c7c
[gaim-migrate @ 15896]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13499
diff
changeset
|
3269 content_len = MAX(content_len, body_len); |
12907
5e338dda872f
[gaim-migrate @ 15260]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12887
diff
changeset
|
3270 |
5e338dda872f
[gaim-migrate @ 15260]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12887
diff
changeset
|
3271 new_data = g_try_malloc(content_len); |
13520
c836ba676c7c
[gaim-migrate @ 15896]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13499
diff
changeset
|
3272 if(new_data == NULL) { |
12907
5e338dda872f
[gaim-migrate @ 15260]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12887
diff
changeset
|
3273 gaim_debug_error("gaim_url_fetch", "Failed to allocate %u bytes: %s\n", |
5e338dda872f
[gaim-migrate @ 15260]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12887
diff
changeset
|
3274 content_len, strerror(errno)); |
5e338dda872f
[gaim-migrate @ 15260]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12887
diff
changeset
|
3275 gaim_input_remove(gfud->inpa); |
5e338dda872f
[gaim-migrate @ 15260]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12887
diff
changeset
|
3276 close(sock); |
5e338dda872f
[gaim-migrate @ 15260]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12887
diff
changeset
|
3277 gfud->callback(gfud->user_data, NULL, 0); |
5e338dda872f
[gaim-migrate @ 15260]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12887
diff
changeset
|
3278 destroy_fetch_url_data(gfud); |
5e338dda872f
[gaim-migrate @ 15260]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12887
diff
changeset
|
3279 |
5e338dda872f
[gaim-migrate @ 15260]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12887
diff
changeset
|
3280 return; |
5e338dda872f
[gaim-migrate @ 15260]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12887
diff
changeset
|
3281 } |
5e338dda872f
[gaim-migrate @ 15260]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12887
diff
changeset
|
3282 |
5e338dda872f
[gaim-migrate @ 15260]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12887
diff
changeset
|
3283 /* We may have read part of the body when reading the headers, don't lose it */ |
13520
c836ba676c7c
[gaim-migrate @ 15896]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13499
diff
changeset
|
3284 if(body_len > 0) { |
12907
5e338dda872f
[gaim-migrate @ 15260]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12887
diff
changeset
|
3285 tmp += 4; |
5e338dda872f
[gaim-migrate @ 15260]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12887
diff
changeset
|
3286 memcpy(new_data, tmp, body_len); |
5e338dda872f
[gaim-migrate @ 15260]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12887
diff
changeset
|
3287 } |
5e338dda872f
[gaim-migrate @ 15260]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12887
diff
changeset
|
3288 |
5e338dda872f
[gaim-migrate @ 15260]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12887
diff
changeset
|
3289 /* Out with the old... */ |
5e338dda872f
[gaim-migrate @ 15260]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12887
diff
changeset
|
3290 g_free(gfud->webdata); |
5e338dda872f
[gaim-migrate @ 15260]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12887
diff
changeset
|
3291 |
5e338dda872f
[gaim-migrate @ 15260]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12887
diff
changeset
|
3292 /* In with the new. */ |
5e338dda872f
[gaim-migrate @ 15260]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12887
diff
changeset
|
3293 gfud->len = body_len; |
5e338dda872f
[gaim-migrate @ 15260]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12887
diff
changeset
|
3294 gfud->data_len = content_len; |
5e338dda872f
[gaim-migrate @ 15260]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12887
diff
changeset
|
3295 gfud->webdata = new_data; |
12887
4229503f1cd9
[gaim-migrate @ 15240]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12880
diff
changeset
|
3296 } |
7094
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3297 } |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3298 } |
12109
936e3b7cd864
[gaim-migrate @ 14409]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11920
diff
changeset
|
3299 |
13520
c836ba676c7c
[gaim-migrate @ 15896]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13499
diff
changeset
|
3300 if(gfud->has_explicit_data_len && gfud->len >= gfud->data_len) { |
9240 | 3301 got_eof = TRUE; |
12109
936e3b7cd864
[gaim-migrate @ 14409]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11920
diff
changeset
|
3302 break; |
9240 | 3303 } |
7094
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3304 } |
12109
936e3b7cd864
[gaim-migrate @ 14409]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11920
diff
changeset
|
3305 |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13163
diff
changeset
|
3306 if(len <= 0) { |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13163
diff
changeset
|
3307 if(errno == EAGAIN) { |
12109
936e3b7cd864
[gaim-migrate @ 14409]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11920
diff
changeset
|
3308 return; |
13520
c836ba676c7c
[gaim-migrate @ 15896]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13499
diff
changeset
|
3309 } else if(errno != ETIMEDOUT) { |
12109
936e3b7cd864
[gaim-migrate @ 14409]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11920
diff
changeset
|
3310 got_eof = TRUE; |
936e3b7cd864
[gaim-migrate @ 14409]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11920
diff
changeset
|
3311 } else { |
936e3b7cd864
[gaim-migrate @ 14409]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11920
diff
changeset
|
3312 gaim_input_remove(gfud->inpa); |
936e3b7cd864
[gaim-migrate @ 14409]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11920
diff
changeset
|
3313 close(sock); |
936e3b7cd864
[gaim-migrate @ 14409]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11920
diff
changeset
|
3314 |
936e3b7cd864
[gaim-migrate @ 14409]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11920
diff
changeset
|
3315 gfud->callback(gfud->user_data, NULL, 0); |
936e3b7cd864
[gaim-migrate @ 14409]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11920
diff
changeset
|
3316 |
936e3b7cd864
[gaim-migrate @ 14409]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11920
diff
changeset
|
3317 destroy_fetch_url_data(gfud); |
936e3b7cd864
[gaim-migrate @ 14409]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11920
diff
changeset
|
3318 return; |
936e3b7cd864
[gaim-migrate @ 14409]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11920
diff
changeset
|
3319 } |
9240 | 3320 } |
3321 | |
13520
c836ba676c7c
[gaim-migrate @ 15896]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13499
diff
changeset
|
3322 if(got_eof) { |
7094
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3323 gfud->webdata = g_realloc(gfud->webdata, gfud->len + 1); |
12109
936e3b7cd864
[gaim-migrate @ 14409]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11920
diff
changeset
|
3324 gfud->webdata[gfud->len] = '\0'; |
7094
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3325 |
9311 | 3326 /* gaim_debug_misc("gaim_url_fetch", "Received: '%s'\n", gfud->webdata); */ |
7094
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3327 |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3328 gaim_input_remove(gfud->inpa); |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3329 close(sock); |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3330 gfud->callback(gfud->user_data, gfud->webdata, gfud->len); |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3331 |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3332 destroy_fetch_url_data(gfud); |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3333 } |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3334 } |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3335 |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13163
diff
changeset
|
3336 static void |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13163
diff
changeset
|
3337 url_fetch_connect_cb(gpointer url_data, gint sock, GaimInputCondition cond) { |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13163
diff
changeset
|
3338 GaimFetchUrlData *gfud = url_data; |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13163
diff
changeset
|
3339 int len, total_len; |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13163
diff
changeset
|
3340 |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13163
diff
changeset
|
3341 if(sock == -1) { |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13163
diff
changeset
|
3342 gfud->callback(gfud->user_data, NULL, 0); |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13163
diff
changeset
|
3343 destroy_fetch_url_data(gfud); |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13163
diff
changeset
|
3344 return; |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13163
diff
changeset
|
3345 } |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13163
diff
changeset
|
3346 |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13163
diff
changeset
|
3347 if (!gfud->request) { |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13163
diff
changeset
|
3348 if (gfud->user_agent) { |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13163
diff
changeset
|
3349 /* Host header is not forbidden in HTTP/1.0 requests, and HTTP/1.1 |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13163
diff
changeset
|
3350 * clients must know how to handle the "chunked" transfer encoding. |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13163
diff
changeset
|
3351 * Gaim doesn't know how to handle "chunked", so should always send |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13163
diff
changeset
|
3352 * the Host header regardless, to get around some observed problems |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13163
diff
changeset
|
3353 */ |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13163
diff
changeset
|
3354 gfud->request = g_strdup_printf( |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13163
diff
changeset
|
3355 "GET %s%s HTTP/%s\r\n" |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13163
diff
changeset
|
3356 "Connection: close\r\n" |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13163
diff
changeset
|
3357 "User-Agent: %s\r\n" |
13829
b6967e51f6c4
[gaim-migrate @ 16274]
Christopher O'Brien <siege@pidgin.im>
parents:
13770
diff
changeset
|
3358 "Accept: */*\r\n" |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13163
diff
changeset
|
3359 "Host: %s\r\n\r\n", |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13163
diff
changeset
|
3360 (gfud->full ? "" : "/"), |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13163
diff
changeset
|
3361 (gfud->full ? gfud->url : gfud->website.page), |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13163
diff
changeset
|
3362 (gfud->http11 ? "1.1" : "1.0"), |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13163
diff
changeset
|
3363 gfud->user_agent, gfud->website.address); |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13163
diff
changeset
|
3364 } else { |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13163
diff
changeset
|
3365 gfud->request = g_strdup_printf( |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13163
diff
changeset
|
3366 "GET %s%s HTTP/%s\r\n" |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13163
diff
changeset
|
3367 "Connection: close\r\n" |
13829
b6967e51f6c4
[gaim-migrate @ 16274]
Christopher O'Brien <siege@pidgin.im>
parents:
13770
diff
changeset
|
3368 "Accept: */*\r\n" |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13163
diff
changeset
|
3369 "Host: %s\r\n\r\n", |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13163
diff
changeset
|
3370 (gfud->full ? "" : "/"), |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13163
diff
changeset
|
3371 (gfud->full ? gfud->url : gfud->website.page), |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13163
diff
changeset
|
3372 (gfud->http11 ? "1.1" : "1.0"), |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13163
diff
changeset
|
3373 gfud->website.address); |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13163
diff
changeset
|
3374 } |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13163
diff
changeset
|
3375 } |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13163
diff
changeset
|
3376 |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13163
diff
changeset
|
3377 gaim_debug_misc("gaim_url_fetch", "Request: '%s'\n", gfud->request); |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13163
diff
changeset
|
3378 |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13163
diff
changeset
|
3379 if(!gfud->inpa) |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13163
diff
changeset
|
3380 gfud->inpa = gaim_input_add(sock, GAIM_INPUT_WRITE, |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13163
diff
changeset
|
3381 url_fetch_connect_cb, gfud); |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13163
diff
changeset
|
3382 |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13163
diff
changeset
|
3383 total_len = strlen(gfud->request); |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13163
diff
changeset
|
3384 |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13163
diff
changeset
|
3385 len = write(sock, gfud->request + gfud->request_written, |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13163
diff
changeset
|
3386 total_len - gfud->request_written); |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13163
diff
changeset
|
3387 |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13163
diff
changeset
|
3388 if(len < 0 && errno == EAGAIN) |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13163
diff
changeset
|
3389 return; |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13163
diff
changeset
|
3390 else if(len < 0) { |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13163
diff
changeset
|
3391 gaim_input_remove(gfud->inpa); |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13163
diff
changeset
|
3392 close(sock); |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13163
diff
changeset
|
3393 gfud->callback(gfud->user_data, NULL, 0); |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13163
diff
changeset
|
3394 destroy_fetch_url_data(gfud); |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13163
diff
changeset
|
3395 return; |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13163
diff
changeset
|
3396 } |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13163
diff
changeset
|
3397 gfud->request_written += len; |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13163
diff
changeset
|
3398 |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13163
diff
changeset
|
3399 if(gfud->request_written != total_len) |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13163
diff
changeset
|
3400 return; |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13163
diff
changeset
|
3401 |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13163
diff
changeset
|
3402 gaim_input_remove(gfud->inpa); |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13163
diff
changeset
|
3403 |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13163
diff
changeset
|
3404 gfud->inpa = gaim_input_add(sock, GAIM_INPUT_READ, url_fetched_cb, |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13163
diff
changeset
|
3405 gfud); |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13163
diff
changeset
|
3406 } |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13163
diff
changeset
|
3407 |
7094
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3408 void |
12887
4229503f1cd9
[gaim-migrate @ 15240]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12880
diff
changeset
|
3409 gaim_url_fetch_request(const char *url, gboolean full, |
4229503f1cd9
[gaim-migrate @ 15240]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12880
diff
changeset
|
3410 const char *user_agent, gboolean http11, |
4229503f1cd9
[gaim-migrate @ 15240]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12880
diff
changeset
|
3411 const char *request, gboolean include_headers, |
4229503f1cd9
[gaim-migrate @ 15240]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12880
diff
changeset
|
3412 GaimURLFetchCallback cb, void *user_data) |
7094
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3413 { |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3414 GaimFetchUrlData *gfud; |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3415 |
9257 | 3416 g_return_if_fail(url != NULL); |
3417 g_return_if_fail(cb != NULL); | |
9311 | 3418 |
9240 | 3419 gaim_debug_info("gaim_url_fetch", |
3420 "requested to fetch (%s), full=%d, user_agent=(%s), http11=%d\n", | |
9257 | 3421 url, full, user_agent?user_agent:"(null)", http11); |
7094
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3422 |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3423 gfud = g_new0(GaimFetchUrlData, 1); |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3424 |
12887
4229503f1cd9
[gaim-migrate @ 15240]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12880
diff
changeset
|
3425 gfud->callback = cb; |
7094
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3426 gfud->user_data = user_data; |
12887
4229503f1cd9
[gaim-migrate @ 15240]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12880
diff
changeset
|
3427 gfud->url = g_strdup(url); |
4229503f1cd9
[gaim-migrate @ 15240]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12880
diff
changeset
|
3428 gfud->user_agent = user_agent ? g_strdup(user_agent) : NULL; |
4229503f1cd9
[gaim-migrate @ 15240]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12880
diff
changeset
|
3429 gfud->http11 = http11; |
4229503f1cd9
[gaim-migrate @ 15240]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12880
diff
changeset
|
3430 gfud->full = full; |
4229503f1cd9
[gaim-migrate @ 15240]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12880
diff
changeset
|
3431 gfud->request = request ? g_strdup(request) : NULL; |
4229503f1cd9
[gaim-migrate @ 15240]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12880
diff
changeset
|
3432 gfud->include_headers = include_headers; |
7094
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3433 |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3434 gaim_url_parse(url, &gfud->website.address, &gfud->website.port, |
9227
9171e528d7e5
[gaim-migrate @ 10023]
Christian Hammond <chipx86@chipx86.com>
parents:
9222
diff
changeset
|
3435 &gfud->website.page, &gfud->website.user, &gfud->website.passwd); |
7094
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3436 |
12802
26b31b4c43a2
[gaim-migrate @ 15149]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12640
diff
changeset
|
3437 if (gaim_proxy_connect(NULL, gfud->website.address, |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13163
diff
changeset
|
3438 gfud->website.port, url_fetch_connect_cb, gfud) != 0) { |
7094
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3439 destroy_fetch_url_data(gfud); |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3440 |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3441 cb(user_data, g_strdup(_("g003: Error opening connection.\n")), 0); |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3442 } |
2343c3aa1dec
[gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents:
7078
diff
changeset
|
3443 } |
7108
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
3444 |
7162 | 3445 const char * |
7134 | 3446 gaim_url_decode(const char *str) |
3447 { | |
3448 static char buf[BUF_LEN]; | |
7631 | 3449 guint i, j = 0; |
7134 | 3450 char *bum; |
9804 | 3451 char hex[3]; |
7134 | 3452 |
3453 g_return_val_if_fail(str != NULL, NULL); | |
3454 | |
9804 | 3455 /* |
3456 * XXX - This check could be removed and buf could be made | |
3457 * dynamically allocated, but this is easier. | |
3458 */ | |
3459 if (strlen(str) >= BUF_LEN) | |
3460 return NULL; | |
3461 | |
7134 | 3462 for (i = 0; i < strlen(str); i++) { |
3463 | |
3464 if (str[i] != '%') | |
3465 buf[j++] = str[i]; | |
3466 else { | |
3467 strncpy(hex, str + ++i, 2); | |
3468 hex[2] = '\0'; | |
3469 | |
3470 /* i is pointing to the start of the number */ | |
3471 i++; | |
3472 | |
3473 /* | |
3474 * Now it's at the end and at the start of the for loop | |
3475 * will be at the next character. | |
3476 */ | |
3477 buf[j++] = strtol(hex, NULL, 16); | |
3478 } | |
3479 } | |
3480 | |
3481 buf[j] = '\0'; | |
3482 | |
3483 if (!g_utf8_validate(buf, -1, (const char **)&bum)) | |
3484 *bum = '\0'; | |
3485 | |
3486 return buf; | |
3487 } | |
3488 | |
7162 | 3489 const char * |
7134 | 3490 gaim_url_encode(const char *str) |
3491 { | |
10700
9505695acff8
[gaim-migrate @ 12273]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10636
diff
changeset
|
3492 const char *iter; |
7134 | 3493 static char buf[BUF_LEN]; |
10700
9505695acff8
[gaim-migrate @ 12273]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10636
diff
changeset
|
3494 char utf_char[6]; |
7631 | 3495 guint i, j = 0; |
7134 | 3496 |
3497 g_return_val_if_fail(str != NULL, NULL); | |
10700
9505695acff8
[gaim-migrate @ 12273]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10636
diff
changeset
|
3498 g_return_val_if_fail(g_utf8_validate(str, -1, NULL), NULL); |
9505695acff8
[gaim-migrate @ 12273]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10636
diff
changeset
|
3499 |
9505695acff8
[gaim-migrate @ 12273]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10636
diff
changeset
|
3500 iter = str; |
9505695acff8
[gaim-migrate @ 12273]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10636
diff
changeset
|
3501 for (; *iter && j < (BUF_LEN - 1) ; iter = g_utf8_next_char(iter)) { |
9505695acff8
[gaim-migrate @ 12273]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10636
diff
changeset
|
3502 gunichar c = g_utf8_get_char(iter); |
10800 | 3503 /* If the character is an ASCII character and is alphanumeric |
3504 * no need to escape */ | |
3505 if (c < 128 && isalnum(c)) { | |
10700
9505695acff8
[gaim-migrate @ 12273]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10636
diff
changeset
|
3506 buf[j++] = c; |
9505695acff8
[gaim-migrate @ 12273]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10636
diff
changeset
|
3507 } else { |
9505695acff8
[gaim-migrate @ 12273]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10636
diff
changeset
|
3508 int bytes = g_unichar_to_utf8(c, utf_char); |
9505695acff8
[gaim-migrate @ 12273]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10636
diff
changeset
|
3509 for (i = 0; i < bytes; i++) { |
9505695acff8
[gaim-migrate @ 12273]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10636
diff
changeset
|
3510 if (j > (BUF_LEN - 4)) |
9505695acff8
[gaim-migrate @ 12273]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10636
diff
changeset
|
3511 break; |
9505695acff8
[gaim-migrate @ 12273]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10636
diff
changeset
|
3512 sprintf(buf + j, "%%%02x", utf_char[i] & 0xff); |
9505695acff8
[gaim-migrate @ 12273]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10636
diff
changeset
|
3513 j += 3; |
9505695acff8
[gaim-migrate @ 12273]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10636
diff
changeset
|
3514 } |
7134 | 3515 } |
3516 } | |
3517 | |
3518 buf[j] = '\0'; | |
3519 | |
3520 return buf; | |
3521 } | |
7108
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
3522 |
9054 | 3523 /* Originally lifted from |
3524 * http://www.oreillynet.com/pub/a/network/excerpt/spcookbook_chap03/index3.html | |
3525 * ... and slightly modified to be a bit more rfc822 compliant | |
3526 * ... and modified a bit more to make domain checking rfc1035 compliant | |
3527 * with the exception permitted in rfc1101 for domains to start with digit | |
3528 * but not completely checking to avoid conflicts with IP addresses | |
3529 */ | |
9045 | 3530 gboolean |
3531 gaim_email_is_valid(const char *address) | |
3532 { | |
3533 const char *c, *domain; | |
3534 static char *rfc822_specials = "()<>@,;:\\\"[]"; | |
3535 | |
9054 | 3536 /* first we validate the name portion (name@domain) (rfc822)*/ |
9045 | 3537 for (c = address; *c; c++) { |
3538 if (*c == '\"' && (c == address || *(c - 1) == '.' || *(c - 1) == '\"')) { | |
3539 while (*++c) { | |
9054 | 3540 if (*c == '\\') { |
3541 if (*c++ && *c < 127 && *c != '\n' && *c != '\r') continue; | |
3542 else return FALSE; | |
3543 } | |
9045 | 3544 if (*c == '\"') break; |
9054 | 3545 if (*c < ' ' || *c >= 127) return FALSE; |
9045 | 3546 } |
3547 if (!*c++) return FALSE; | |
3548 if (*c == '@') break; | |
3549 if (*c != '.') return FALSE; | |
3550 continue; | |
3551 } | |
3552 if (*c == '@') break; | |
3553 if (*c <= ' ' || *c >= 127) return FALSE; | |
3554 if (strchr(rfc822_specials, *c)) return FALSE; | |
3555 } | |
9054 | 3556 /* strictly we should return false if (*(c - 1) == '.') too, but I think |
3557 * we should permit user.@domain type addresses - they do work :) */ | |
3558 if (c == address) return FALSE; | |
3559 | |
3560 /* next we validate the domain portion (name@domain) (rfc1035 & rfc1011) */ | |
9045 | 3561 if (!*(domain = ++c)) return FALSE; |
3562 do { | |
9054 | 3563 if (*c == '.' && (c == domain || *(c - 1) == '.' || *(c - 1) == '-')) |
3564 return FALSE; | |
3565 if (*c == '-' && *(c - 1) == '.') return FALSE; | |
3566 if ((*c < '0' && *c != '-' && *c != '.') || (*c > '9' && *c < 'A') || | |
3567 (*c > 'Z' && *c < 'a') || (*c > 'z')) return FALSE; | |
9045 | 3568 } while (*++c); |
3569 | |
9054 | 3570 if (*(c - 1) == '-') return FALSE; |
3571 | |
3572 return ((c - domain) > 3 ? TRUE : FALSE); | |
9045 | 3573 } |
3574 | |
11135 | 3575 /* Stolen from gnome_uri_list_extract_uris */ |
3576 GList * | |
3577 gaim_uri_list_extract_uris(const gchar *uri_list) | |
3578 { | |
9670 | 3579 const gchar *p, *q; |
3580 gchar *retval; | |
3581 GList *result = NULL; | |
3582 | |
3583 g_return_val_if_fail (uri_list != NULL, NULL); | |
3584 | |
3585 p = uri_list; | |
3586 | |
3587 /* We don't actually try to validate the URI according to RFC | |
3588 * 2396, or even check for allowed characters - we just ignore | |
3589 * comments and trim whitespace off the ends. We also | |
3590 * allow LF delimination as well as the specified CRLF. | |
3591 */ | |
3592 while (p) { | |
3593 if (*p != '#') { | |
3594 while (isspace(*p)) | |
3595 p++; | |
3596 | |
3597 q = p; | |
3598 while (*q && (*q != '\n') && (*q != '\r')) | |
3599 q++; | |
3600 | |
3601 if (q > p) { | |
3602 q--; | |
3603 while (q > p && isspace(*q)) | |
3604 q--; | |
3605 | |
3606 retval = (gchar*)g_malloc (q - p + 2); | |
3607 strncpy (retval, p, q - p + 1); | |
3608 retval[q - p + 1] = '\0'; | |
3609 | |
3610 result = g_list_prepend (result, retval); | |
3611 } | |
3612 } | |
3613 p = strchr (p, '\n'); | |
3614 if (p) | |
3615 p++; | |
3616 } | |
3617 | |
3618 return g_list_reverse (result); | |
3619 } | |
3620 | |
3621 | |
11135 | 3622 /* Stolen from gnome_uri_list_extract_filenames */ |
3623 GList * | |
3624 gaim_uri_list_extract_filenames(const gchar *uri_list) | |
3625 { | |
9670 | 3626 GList *tmp_list, *node, *result; |
3627 | |
3628 g_return_val_if_fail (uri_list != NULL, NULL); | |
3629 | |
11135 | 3630 result = gaim_uri_list_extract_uris(uri_list); |
9670 | 3631 |
3632 tmp_list = result; | |
3633 while (tmp_list) { | |
3634 gchar *s = (gchar*)tmp_list->data; | |
3635 | |
3636 node = tmp_list; | |
3637 tmp_list = tmp_list->next; | |
3638 | |
3639 if (!strncmp (s, "file:", 5)) { | |
3640 node->data = g_filename_from_uri (s, NULL, NULL); | |
3641 /* not sure if this fallback is useful at all */ | |
3642 if (!node->data) node->data = g_strdup (s+5); | |
3643 } else { | |
3644 result = g_list_remove_link(result, node); | |
3645 g_list_free_1 (node); | |
3646 } | |
3647 g_free (s); | |
3648 } | |
3649 return result; | |
3650 } | |
9054 | 3651 |
7108
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
3652 /************************************************************************** |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
3653 * UTF8 String Functions |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
3654 **************************************************************************/ |
9642 | 3655 gchar * |
7108
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
3656 gaim_utf8_try_convert(const char *str) |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
3657 { |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
3658 gsize converted; |
9642 | 3659 gchar *utf8; |
7108
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
3660 |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
3661 g_return_val_if_fail(str != NULL, NULL); |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
3662 |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
3663 if (g_utf8_validate(str, -1, NULL)) { |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
3664 return g_strdup(str); |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
3665 } |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
3666 |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
3667 utf8 = g_locale_to_utf8(str, -1, &converted, NULL, NULL); |
9642 | 3668 if (utf8 != NULL) |
3669 return utf8; | |
7108
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
3670 |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
3671 utf8 = g_convert(str, -1, "UTF-8", "ISO-8859-15", &converted, NULL, NULL); |
9642 | 3672 if ((utf8 != NULL) && (converted == strlen(str))) |
3673 return utf8; | |
3674 | |
3675 if (utf8 != NULL) | |
7108
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
3676 g_free(utf8); |
9642 | 3677 |
3678 return NULL; | |
7108
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
3679 } |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
3680 |
10258 | 3681 #define utf8_first(x) ((x & 0x80) == 0 || (x & 0xe0) == 0xc0 \ |
3682 || (x & 0xf0) == 0xe0 || (x & 0xf8) == 0xf) | |
3683 gchar * | |
3684 gaim_utf8_salvage(const char *str) | |
3685 { | |
3686 GString *workstr; | |
3687 const char *end; | |
3688 | |
3689 g_return_val_if_fail(str != NULL, NULL); | |
3690 | |
3691 workstr = g_string_sized_new(strlen(str)); | |
3692 | |
3693 do { | |
3694 g_utf8_validate(str, -1, &end); | |
3695 workstr = g_string_append_len(workstr, str, end - str); | |
3696 str = end; | |
3697 if (*str == '\0') | |
3698 break; | |
3699 do { | |
3700 workstr = g_string_append_c(workstr, '?'); | |
3701 str++; | |
3702 } while (!utf8_first(*str)); | |
3703 } while (*str != '\0'); | |
3704 | |
3705 return g_string_free(workstr, FALSE); | |
3706 } | |
3707 | |
12813
547c199072c8
[gaim-migrate @ 15161]
Christopher O'Brien <siege@pidgin.im>
parents:
12802
diff
changeset
|
3708 |
547c199072c8
[gaim-migrate @ 15161]
Christopher O'Brien <siege@pidgin.im>
parents:
12802
diff
changeset
|
3709 char * |
12880
bad785371fa5
[gaim-migrate @ 15232]
Christopher O'Brien <siege@pidgin.im>
parents:
12813
diff
changeset
|
3710 gaim_utf8_ncr_encode(const char *str) |
12813
547c199072c8
[gaim-migrate @ 15161]
Christopher O'Brien <siege@pidgin.im>
parents:
12802
diff
changeset
|
3711 { |
547c199072c8
[gaim-migrate @ 15161]
Christopher O'Brien <siege@pidgin.im>
parents:
12802
diff
changeset
|
3712 GString *out; |
547c199072c8
[gaim-migrate @ 15161]
Christopher O'Brien <siege@pidgin.im>
parents:
12802
diff
changeset
|
3713 |
12880
bad785371fa5
[gaim-migrate @ 15232]
Christopher O'Brien <siege@pidgin.im>
parents:
12813
diff
changeset
|
3714 g_return_val_if_fail(str != NULL, NULL); |
bad785371fa5
[gaim-migrate @ 15232]
Christopher O'Brien <siege@pidgin.im>
parents:
12813
diff
changeset
|
3715 g_return_val_if_fail(g_utf8_validate(str, -1, NULL), NULL); |
12813
547c199072c8
[gaim-migrate @ 15161]
Christopher O'Brien <siege@pidgin.im>
parents:
12802
diff
changeset
|
3716 |
547c199072c8
[gaim-migrate @ 15161]
Christopher O'Brien <siege@pidgin.im>
parents:
12802
diff
changeset
|
3717 out = g_string_new(""); |
547c199072c8
[gaim-migrate @ 15161]
Christopher O'Brien <siege@pidgin.im>
parents:
12802
diff
changeset
|
3718 |
12880
bad785371fa5
[gaim-migrate @ 15232]
Christopher O'Brien <siege@pidgin.im>
parents:
12813
diff
changeset
|
3719 for(; *str; str = g_utf8_next_char(str)) { |
bad785371fa5
[gaim-migrate @ 15232]
Christopher O'Brien <siege@pidgin.im>
parents:
12813
diff
changeset
|
3720 gunichar wc = g_utf8_get_char(str); |
bad785371fa5
[gaim-migrate @ 15232]
Christopher O'Brien <siege@pidgin.im>
parents:
12813
diff
changeset
|
3721 |
bad785371fa5
[gaim-migrate @ 15232]
Christopher O'Brien <siege@pidgin.im>
parents:
12813
diff
changeset
|
3722 /* super simple check. hopefully not too wrong. */ |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13163
diff
changeset
|
3723 if(wc >= 0x80) { |
12813
547c199072c8
[gaim-migrate @ 15161]
Christopher O'Brien <siege@pidgin.im>
parents:
12802
diff
changeset
|
3724 g_string_append_printf(out, "&#%u;", (guint32) wc); |
547c199072c8
[gaim-migrate @ 15161]
Christopher O'Brien <siege@pidgin.im>
parents:
12802
diff
changeset
|
3725 } else { |
547c199072c8
[gaim-migrate @ 15161]
Christopher O'Brien <siege@pidgin.im>
parents:
12802
diff
changeset
|
3726 g_string_append_unichar(out, wc); |
547c199072c8
[gaim-migrate @ 15161]
Christopher O'Brien <siege@pidgin.im>
parents:
12802
diff
changeset
|
3727 } |
547c199072c8
[gaim-migrate @ 15161]
Christopher O'Brien <siege@pidgin.im>
parents:
12802
diff
changeset
|
3728 } |
547c199072c8
[gaim-migrate @ 15161]
Christopher O'Brien <siege@pidgin.im>
parents:
12802
diff
changeset
|
3729 |
547c199072c8
[gaim-migrate @ 15161]
Christopher O'Brien <siege@pidgin.im>
parents:
12802
diff
changeset
|
3730 return g_string_free(out, FALSE); |
547c199072c8
[gaim-migrate @ 15161]
Christopher O'Brien <siege@pidgin.im>
parents:
12802
diff
changeset
|
3731 } |
547c199072c8
[gaim-migrate @ 15161]
Christopher O'Brien <siege@pidgin.im>
parents:
12802
diff
changeset
|
3732 |
547c199072c8
[gaim-migrate @ 15161]
Christopher O'Brien <siege@pidgin.im>
parents:
12802
diff
changeset
|
3733 |
9161 | 3734 char * |
12880
bad785371fa5
[gaim-migrate @ 15232]
Christopher O'Brien <siege@pidgin.im>
parents:
12813
diff
changeset
|
3735 gaim_utf8_ncr_decode(const char *str) |
9161 | 3736 { |
12813
547c199072c8
[gaim-migrate @ 15161]
Christopher O'Brien <siege@pidgin.im>
parents:
12802
diff
changeset
|
3737 GString *out; |
12880
bad785371fa5
[gaim-migrate @ 15232]
Christopher O'Brien <siege@pidgin.im>
parents:
12813
diff
changeset
|
3738 char *buf, *b; |
bad785371fa5
[gaim-migrate @ 15232]
Christopher O'Brien <siege@pidgin.im>
parents:
12813
diff
changeset
|
3739 |
bad785371fa5
[gaim-migrate @ 15232]
Christopher O'Brien <siege@pidgin.im>
parents:
12813
diff
changeset
|
3740 g_return_val_if_fail(str != NULL, NULL); |
bad785371fa5
[gaim-migrate @ 15232]
Christopher O'Brien <siege@pidgin.im>
parents:
12813
diff
changeset
|
3741 g_return_val_if_fail(g_utf8_validate(str, -1, NULL), NULL); |
bad785371fa5
[gaim-migrate @ 15232]
Christopher O'Brien <siege@pidgin.im>
parents:
12813
diff
changeset
|
3742 |
bad785371fa5
[gaim-migrate @ 15232]
Christopher O'Brien <siege@pidgin.im>
parents:
12813
diff
changeset
|
3743 buf = (char *) str; |
12813
547c199072c8
[gaim-migrate @ 15161]
Christopher O'Brien <siege@pidgin.im>
parents:
12802
diff
changeset
|
3744 out = g_string_new(""); |
547c199072c8
[gaim-migrate @ 15161]
Christopher O'Brien <siege@pidgin.im>
parents:
12802
diff
changeset
|
3745 |
12880
bad785371fa5
[gaim-migrate @ 15232]
Christopher O'Brien <siege@pidgin.im>
parents:
12813
diff
changeset
|
3746 while( (b = strstr(buf, "&#")) ) { |
bad785371fa5
[gaim-migrate @ 15232]
Christopher O'Brien <siege@pidgin.im>
parents:
12813
diff
changeset
|
3747 gunichar wc; |
bad785371fa5
[gaim-migrate @ 15232]
Christopher O'Brien <siege@pidgin.im>
parents:
12813
diff
changeset
|
3748 int base = 0; |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13163
diff
changeset
|
3749 |
12880
bad785371fa5
[gaim-migrate @ 15232]
Christopher O'Brien <siege@pidgin.im>
parents:
12813
diff
changeset
|
3750 /* append everything leading up to the &# */ |
bad785371fa5
[gaim-migrate @ 15232]
Christopher O'Brien <siege@pidgin.im>
parents:
12813
diff
changeset
|
3751 g_string_append_len(out, buf, b-buf); |
bad785371fa5
[gaim-migrate @ 15232]
Christopher O'Brien <siege@pidgin.im>
parents:
12813
diff
changeset
|
3752 |
bad785371fa5
[gaim-migrate @ 15232]
Christopher O'Brien <siege@pidgin.im>
parents:
12813
diff
changeset
|
3753 b += 2; /* skip past the &# */ |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13163
diff
changeset
|
3754 |
13488
14fa5c324573
[gaim-migrate @ 15864]
Christopher O'Brien <siege@pidgin.im>
parents:
13464
diff
changeset
|
3755 /* strtoul will treat 0x prefix as hex, but not just x */ |
14fa5c324573
[gaim-migrate @ 15864]
Christopher O'Brien <siege@pidgin.im>
parents:
13464
diff
changeset
|
3756 if(*b == 'x' || *b == 'X') { |
12880
bad785371fa5
[gaim-migrate @ 15232]
Christopher O'Brien <siege@pidgin.im>
parents:
12813
diff
changeset
|
3757 base = 16; |
13488
14fa5c324573
[gaim-migrate @ 15864]
Christopher O'Brien <siege@pidgin.im>
parents:
13464
diff
changeset
|
3758 b++; |
14fa5c324573
[gaim-migrate @ 15864]
Christopher O'Brien <siege@pidgin.im>
parents:
13464
diff
changeset
|
3759 } |
12880
bad785371fa5
[gaim-migrate @ 15232]
Christopher O'Brien <siege@pidgin.im>
parents:
12813
diff
changeset
|
3760 |
bad785371fa5
[gaim-migrate @ 15232]
Christopher O'Brien <siege@pidgin.im>
parents:
12813
diff
changeset
|
3761 /* advances buf to the end of the ncr segment */ |
bad785371fa5
[gaim-migrate @ 15232]
Christopher O'Brien <siege@pidgin.im>
parents:
12813
diff
changeset
|
3762 wc = (gunichar) strtoul(b, &buf, base); |
bad785371fa5
[gaim-migrate @ 15232]
Christopher O'Brien <siege@pidgin.im>
parents:
12813
diff
changeset
|
3763 |
bad785371fa5
[gaim-migrate @ 15232]
Christopher O'Brien <siege@pidgin.im>
parents:
12813
diff
changeset
|
3764 /* this mimics the previous impl of ncr_decode */ |
bad785371fa5
[gaim-migrate @ 15232]
Christopher O'Brien <siege@pidgin.im>
parents:
12813
diff
changeset
|
3765 if(*buf == ';') { |
bad785371fa5
[gaim-migrate @ 15232]
Christopher O'Brien <siege@pidgin.im>
parents:
12813
diff
changeset
|
3766 g_string_append_unichar(out, wc); |
bad785371fa5
[gaim-migrate @ 15232]
Christopher O'Brien <siege@pidgin.im>
parents:
12813
diff
changeset
|
3767 buf++; |
9161 | 3768 } |
3769 } | |
12880
bad785371fa5
[gaim-migrate @ 15232]
Christopher O'Brien <siege@pidgin.im>
parents:
12813
diff
changeset
|
3770 |
bad785371fa5
[gaim-migrate @ 15232]
Christopher O'Brien <siege@pidgin.im>
parents:
12813
diff
changeset
|
3771 /* append whatever's left */ |
bad785371fa5
[gaim-migrate @ 15232]
Christopher O'Brien <siege@pidgin.im>
parents:
12813
diff
changeset
|
3772 g_string_append(out, buf); |
bad785371fa5
[gaim-migrate @ 15232]
Christopher O'Brien <siege@pidgin.im>
parents:
12813
diff
changeset
|
3773 |
9161 | 3774 return g_string_free(out, FALSE); |
3775 } | |
3776 | |
12880
bad785371fa5
[gaim-migrate @ 15232]
Christopher O'Brien <siege@pidgin.im>
parents:
12813
diff
changeset
|
3777 |
7108
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
3778 int |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
3779 gaim_utf8_strcasecmp(const char *a, const char *b) |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
3780 { |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
3781 char *a_norm = NULL; |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
3782 char *b_norm = NULL; |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
3783 int ret = -1; |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
3784 |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
3785 if(!a && b) |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
3786 return -1; |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
3787 else if(!b && a) |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
3788 return 1; |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
3789 else if(!a && !b) |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
3790 return 0; |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
3791 |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
3792 if(!g_utf8_validate(a, -1, NULL) || !g_utf8_validate(b, -1, NULL)) |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
3793 { |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
3794 gaim_debug_error("gaim_utf8_strcasecmp", |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
3795 "One or both parameters are invalid UTF8\n"); |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
3796 return ret; |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
3797 } |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
3798 |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
3799 a_norm = g_utf8_casefold(a, -1); |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
3800 b_norm = g_utf8_casefold(b, -1); |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
3801 ret = g_utf8_collate(a_norm, b_norm); |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
3802 g_free(a_norm); |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
3803 g_free(b_norm); |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
3804 |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
3805 return ret; |
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
3806 } |
7162 | 3807 |
11552
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11493
diff
changeset
|
3808 /* previously conversation::find_nick() */ |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13163
diff
changeset
|
3809 gboolean |
11552
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11493
diff
changeset
|
3810 gaim_utf8_has_word(const char *haystack, const char *needle) |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11493
diff
changeset
|
3811 { |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11493
diff
changeset
|
3812 char *hay, *pin, *p; |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11493
diff
changeset
|
3813 int n; |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11493
diff
changeset
|
3814 gboolean ret = FALSE; |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11493
diff
changeset
|
3815 |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11493
diff
changeset
|
3816 hay = g_utf8_strdown(haystack, -1); |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11493
diff
changeset
|
3817 |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11493
diff
changeset
|
3818 pin = g_utf8_strdown(needle, -1); |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11493
diff
changeset
|
3819 n = strlen(pin); |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11493
diff
changeset
|
3820 |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11493
diff
changeset
|
3821 if ((p = strstr(hay, pin)) != NULL) { |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11493
diff
changeset
|
3822 if ((p == hay || !isalnum(*(p - 1))) && !isalnum(*(p + n))) { |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11493
diff
changeset
|
3823 ret = TRUE; |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11493
diff
changeset
|
3824 } |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11493
diff
changeset
|
3825 } |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11493
diff
changeset
|
3826 |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11493
diff
changeset
|
3827 g_free(pin); |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11493
diff
changeset
|
3828 g_free(hay); |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11493
diff
changeset
|
3829 |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11493
diff
changeset
|
3830 return ret; |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11493
diff
changeset
|
3831 } |
11d30825c1bb
[gaim-migrate @ 13812]
Gary Kramlich <grim@reaperworld.com>
parents:
11493
diff
changeset
|
3832 |
13089 | 3833 void |
3834 gaim_print_utf8_to_console(FILE *filestream, char *message) | |
3835 { | |
3836 gchar *message_conv; | |
3837 GError *error = NULL; | |
3838 | |
3839 /* Try to convert 'message' to user's locale */ | |
3840 message_conv = g_locale_from_utf8(message, -1, NULL, NULL, &error); | |
3841 if (message_conv != NULL) { | |
3842 fputs(message_conv, filestream); | |
3843 g_free(message_conv); | |
3844 } | |
3845 else | |
3846 { | |
3847 /* use 'message' as a fallback */ | |
3848 g_warning("%s\n", error->message); | |
3849 g_error_free(error); | |
3850 fputs(message, filestream); | |
3851 } | |
3852 } | |
3853 | |
7564 | 3854 gboolean gaim_message_meify(char *message, size_t len) |
3855 { | |
3856 char *c; | |
3857 gboolean inside_html = FALSE; | |
3858 | |
3859 g_return_val_if_fail(message != NULL, FALSE); | |
3860 | |
3861 if(len == -1) | |
3862 len = strlen(message); | |
3863 | |
3864 for (c = message; *c; c++, len--) { | |
3865 if(inside_html) { | |
3866 if(*c == '>') | |
3867 inside_html = FALSE; | |
3868 } else { | |
3869 if(*c == '<') | |
3870 inside_html = TRUE; | |
3871 else | |
3872 break; | |
3873 } | |
3874 } | |
3875 | |
3876 if(*c && !g_ascii_strncasecmp(c, "/me ", 4)) { | |
3877 memmove(c, c+4, len-3); | |
3878 return TRUE; | |
3879 } | |
3880 | |
3881 return FALSE; | |
3882 } | |
3883 | |
7889 | 3884 char *gaim_text_strip_mnemonic(const char *in) |
3885 { | |
3886 char *out; | |
3887 char *a; | |
8561 | 3888 char *a0; |
7889 | 3889 const char *b; |
3890 | |
3891 g_return_val_if_fail(in != NULL, NULL); | |
3892 | |
3893 out = g_malloc(strlen(in)+1); | |
3894 a = out; | |
3895 b = in; | |
3896 | |
8561 | 3897 a0 = a; /* The last non-space char seen so far, or the first char */ |
3898 | |
7889 | 3899 while(*b) { |
3900 if(*b == '_') { | |
8561 | 3901 if(a > out && b > in && *(b-1) == '(' && *(b+1) && !(*(b+1) & 0x80) && *(b+2) == ')') { |
3902 /* Detected CJK style shortcut (Bug 875311) */ | |
3903 a = a0; /* undo the left parenthesis */ | |
3904 b += 3; /* and skip the whole mess */ | |
3905 } else if(*(b+1) == '_') { | |
7889 | 3906 *(a++) = '_'; |
3907 b += 2; | |
8561 | 3908 a0 = a; |
7889 | 3909 } else { |
3910 b++; | |
3911 } | |
8561 | 3912 /* We don't want to corrupt the middle of UTF-8 characters */ |
3913 } else if (!(*b & 0x80)) { /* other 1-byte char */ | |
3914 if (*b != ' ') | |
3915 a0 = a; | |
3916 *(a++) = *(b++); | |
7889 | 3917 } else { |
8561 | 3918 /* Multibyte utf8 char, don't look for _ inside these */ |
3919 int n = 0; | |
3920 int i; | |
3921 if ((*b & 0xe0) == 0xc0) { | |
3922 n = 2; | |
3923 } else if ((*b & 0xf0) == 0xe0) { | |
3924 n = 3; | |
3925 } else if ((*b & 0xf8) == 0xf0) { | |
3926 n = 4; | |
3927 } else if ((*b & 0xfc) == 0xf8) { | |
3928 n = 5; | |
3929 } else if ((*b & 0xfe) == 0xfc) { | |
3930 n = 6; | |
3931 } else { /* Illegal utf8 */ | |
3932 n = 1; | |
3933 } | |
3934 a0 = a; /* unless we want to delete CJK spaces too */ | |
3935 for (i = 0; i < n && *b; i += 1) { | |
3936 *(a++) = *(b++); | |
3937 } | |
7889 | 3938 } |
3939 } | |
3940 *a = '\0'; | |
3941 | |
3942 return out; | |
3943 } | |
3944 | |
9926 | 3945 const char* gaim_unescape_filename(const char *escaped) { |
3946 return gaim_url_decode(escaped); | |
3947 } | |
3948 | |
3949 | |
3950 /* this is almost identical to gaim_url_encode (hence gaim_url_decode | |
3951 * being used above), but we want to keep certain characters unescaped | |
3952 * for compat reasons */ | |
3953 const char * | |
3954 gaim_escape_filename(const char *str) | |
3955 { | |
10700
9505695acff8
[gaim-migrate @ 12273]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10636
diff
changeset
|
3956 const char *iter; |
9926 | 3957 static char buf[BUF_LEN]; |
10700
9505695acff8
[gaim-migrate @ 12273]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10636
diff
changeset
|
3958 char utf_char[6]; |
9926 | 3959 guint i, j = 0; |
3960 | |
3961 g_return_val_if_fail(str != NULL, NULL); | |
10700
9505695acff8
[gaim-migrate @ 12273]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10636
diff
changeset
|
3962 g_return_val_if_fail(g_utf8_validate(str, -1, NULL), NULL); |
9505695acff8
[gaim-migrate @ 12273]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10636
diff
changeset
|
3963 |
9505695acff8
[gaim-migrate @ 12273]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10636
diff
changeset
|
3964 iter = str; |
9505695acff8
[gaim-migrate @ 12273]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10636
diff
changeset
|
3965 for (; *iter && j < (BUF_LEN - 1) ; iter = g_utf8_next_char(iter)) { |
9505695acff8
[gaim-migrate @ 12273]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10636
diff
changeset
|
3966 gunichar c = g_utf8_get_char(iter); |
9505695acff8
[gaim-migrate @ 12273]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10636
diff
changeset
|
3967 /* If the character is an ASCII character and is alphanumeric, |
9505695acff8
[gaim-migrate @ 12273]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10636
diff
changeset
|
3968 * or one of the specified values, no need to escape */ |
10800 | 3969 if (c < 128 && (isalnum(c) || c == '@' || c == '-' || |
10700
9505695acff8
[gaim-migrate @ 12273]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10636
diff
changeset
|
3970 c == '_' || c == '.' || c == '#')) { |
9505695acff8
[gaim-migrate @ 12273]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10636
diff
changeset
|
3971 buf[j++] = c; |
9505695acff8
[gaim-migrate @ 12273]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10636
diff
changeset
|
3972 } else { |
9505695acff8
[gaim-migrate @ 12273]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10636
diff
changeset
|
3973 int bytes = g_unichar_to_utf8(c, utf_char); |
9505695acff8
[gaim-migrate @ 12273]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10636
diff
changeset
|
3974 for (i = 0; i < bytes; i++) { |
9505695acff8
[gaim-migrate @ 12273]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10636
diff
changeset
|
3975 if (j > (BUF_LEN - 4)) |
9505695acff8
[gaim-migrate @ 12273]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10636
diff
changeset
|
3976 break; |
9505695acff8
[gaim-migrate @ 12273]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10636
diff
changeset
|
3977 sprintf(buf + j, "%%%02x", utf_char[i] & 0xff); |
9505695acff8
[gaim-migrate @ 12273]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10636
diff
changeset
|
3978 j += 3; |
9505695acff8
[gaim-migrate @ 12273]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10636
diff
changeset
|
3979 } |
9926 | 3980 } |
3981 } | |
3982 | |
3983 buf[j] = '\0'; | |
3984 | |
3985 return buf; | |
3986 } | |
3987 | |
3988 |