annotate src/util.c @ 8863:75849c0650e5

[gaim-migrate @ 9631] paco-paco distracted me and i got confused where i was at. i actually just committed the code for this, now the rest committer: Tailor Script <tailor@pidgin.im>
author Luke Schierer <lschiere@pidgin.im>
date Mon, 03 May 2004 17:55:46 +0000
parents 92cbf9713795
children ae3f33870550
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
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
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
4 *
8046
fa6395637e2c [gaim-migrate @ 8730]
Sean Egan <seanegan@gmail.com>
parents: 8026
diff changeset
5 * Gaim is the legal property of its developers, whose names are too numerous
fa6395637e2c [gaim-migrate @ 8730]
Sean Egan <seanegan@gmail.com>
parents: 8026
diff changeset
6 * to list here. Please refer to the COPYRIGHT file distributed with this
fa6395637e2c [gaim-migrate @ 8730]
Sean Egan <seanegan@gmail.com>
parents: 8026
diff changeset
7 * source distribution.
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
8 *
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
9 * This program is free software; you can redistribute it and/or modify
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
10 * it under the terms of the GNU General Public License as published by
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
11 * the Free Software Foundation; either version 2 of the License, or
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
12 * (at your option) any later version.
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
13 *
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
14 * This program is distributed in the hope that it will be useful,
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
17 * GNU General Public License for more details.
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
18 *
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
19 * You should have received a copy of the GNU General Public License
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
20 * along with this program; if not, write to the Free Software
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
22 */
5872
059d95c67cda [gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents: 5826
diff changeset
23 #include "internal.h"
3630
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3572
diff changeset
24
7612
3ae88e96dde2 [gaim-migrate @ 8236]
Ethan Blanton <elb@pidgin.im>
parents: 7564
diff changeset
25 #include <errno.h>
3ae88e96dde2 [gaim-migrate @ 8236]
Ethan Blanton <elb@pidgin.im>
parents: 7564
diff changeset
26 #include <sys/types.h>
3ae88e96dde2 [gaim-migrate @ 8236]
Ethan Blanton <elb@pidgin.im>
parents: 7564
diff changeset
27 #include <sys/stat.h>
3ae88e96dde2 [gaim-migrate @ 8236]
Ethan Blanton <elb@pidgin.im>
parents: 7564
diff changeset
28
5872
059d95c67cda [gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents: 5826
diff changeset
29 #include "conversation.h"
059d95c67cda [gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents: 5826
diff changeset
30 #include "debug.h"
1575
427e1409917c [gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1560
diff changeset
31 #include "prpl.h"
5545
7a64114641c3 [gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents: 5532
diff changeset
32 #include "prefs.h"
7094
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
33 #include "util.h"
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
34
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
35 typedef struct
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 void (*callback)(void *, const char *, size_t);
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
38 void *user_data;
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
39
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
40 struct
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
41 {
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
42 char *address;
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
43 int port;
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
44 char *page;
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
45
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
46 } website;
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
47
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
48 char *url;
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
49 gboolean full;
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
50 char *user_agent;
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
51 gboolean http11;
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
52
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
53 int inpa;
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 gboolean sentreq;
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
56 gboolean newline;
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
57 gboolean startsaving;
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
58 char *webdata;
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
59 unsigned long len;
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
60 unsigned long data_len;
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
61
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
62 } GaimFetchUrlData;
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
63
8596
56360561af5e [gaim-migrate @ 9347]
Luke Schierer <lschiere@pidgin.im>
parents: 8577
diff changeset
64 static char custom_home_dir[MAXPATHLEN];
3630
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3572
diff changeset
65 static char home_dir[MAXPATHLEN];
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3572
diff changeset
66
7108
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
67 /**************************************************************************
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
68 * Base16 Functions
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
69 **************************************************************************/
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
70 unsigned char *
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
71 gaim_base16_encode(const unsigned char *data, int length)
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
72 {
7108
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
73 int i;
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
74 unsigned char *ascii = NULL;
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
75
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
76 g_return_val_if_fail(data != NULL, NULL);
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
77 g_return_val_if_fail(length > 0, NULL);
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
78
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
79 ascii = g_malloc(length * 2 + 1);
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
80
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
81 for (i = 0; i < length; i++)
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
82 snprintf(&ascii[i * 2], 3, "%02hhx", data[i]);
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
83
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
84 return ascii;
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
85 }
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
86
7108
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
87 int
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
88 gaim_base16_decode(const char *ascii, unsigned char **raw)
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
89 {
7108
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
90 int len, i, accumulator = 0;
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
91 unsigned char *data;
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
92
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
93 g_return_val_if_fail(ascii != NULL, 0);
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
94
7108
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
95 len = strlen(ascii);
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
96
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
97 g_return_val_if_fail(strlen(ascii) > 0, 0);
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
98 g_return_val_if_fail(len % 2 > 0, 0);
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
99
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
100 data = g_malloc(len / 2);
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
101
7108
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
102 for (i = 0; i < len; i++)
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
103 {
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
104 if ((i % 2) == 0)
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
105 accumulator = 0;
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
106 else
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
107 accumulator <<= 4;
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
108
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
109 if (isdigit(ascii[i]))
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
110 accumulator |= ascii[i] - 48;
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
111 else
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
112 {
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
113 switch(ascii[i])
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
114 {
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
115 case 'a': case 'A': accumulator |= 10; break;
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
116 case 'b': case 'B': accumulator |= 11; break;
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
117 case 'c': case 'C': accumulator |= 12; break;
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
118 case 'd': case 'D': accumulator |= 13; break;
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
119 case 'e': case 'E': accumulator |= 14; break;
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
120 case 'f': case 'F': accumulator |= 15; break;
1826
7f889cdfa03e [gaim-migrate @ 1836]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1815
diff changeset
121 }
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
122 }
7108
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
123
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
124 if (i % 2)
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
125 data[(i - 1) / 2] = accumulator;
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
126 }
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
127
7108
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
128 *raw = data;
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
129
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
130 return (len / 2);
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
131 }
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
132
7108
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
133 /**************************************************************************
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
134 * Base64 Functions
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
135 **************************************************************************/
4888
912294585edf [gaim-migrate @ 5218]
Christian Hammond <chipx86@chipx86.com>
parents: 4853
diff changeset
136 static const char alphabet[] =
912294585edf [gaim-migrate @ 5218]
Christian Hammond <chipx86@chipx86.com>
parents: 4853
diff changeset
137 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
912294585edf [gaim-migrate @ 5218]
Christian Hammond <chipx86@chipx86.com>
parents: 4853
diff changeset
138 "0123456789+/";
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
139
7108
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
140 unsigned char *
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
141 gaim_base64_encode(const unsigned char *in, size_t inlen)
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
142 {
6872
dd0eecfbe413 [gaim-migrate @ 7418]
Nathan Walp <nwalp@pidgin.im>
parents: 6861
diff changeset
143 char *out, *rv;
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 g_return_val_if_fail(in != NULL, NULL);
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
146 g_return_val_if_fail(inlen > 0, NULL);
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
147
7265
d565594c1bae [gaim-migrate @ 7842]
Nathan Walp <nwalp@pidgin.im>
parents: 7262
diff changeset
148 rv = out = g_malloc(((inlen/3)+1)*4 + 1);
1238
78c4f497db2b [gaim-migrate @ 1248]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1202
diff changeset
149
7108
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
150 for (; inlen >= 3; inlen -= 3)
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
151 {
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
152 *out++ = alphabet[in[0] >> 2];
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
153 *out++ = alphabet[((in[0] << 4) & 0x30) | (in[1] >> 4)];
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
154 *out++ = alphabet[((in[1] << 2) & 0x3c) | (in[2] >> 6)];
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
155 *out++ = alphabet[in[2] & 0x3f];
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
156 in += 3;
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
157 }
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
158
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
159 if (inlen > 0)
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
160 {
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
161 unsigned char fragment;
6872
dd0eecfbe413 [gaim-migrate @ 7418]
Nathan Walp <nwalp@pidgin.im>
parents: 6861
diff changeset
162
7108
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
163 *out++ = alphabet[in[0] >> 2];
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
164 fragment = (in[0] << 4) & 0x30;
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
165
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
166 if (inlen > 1)
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
167 fragment |= in[1] >> 4;
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
168
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
169 *out++ = alphabet[fragment];
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
170 *out++ = (inlen < 2) ? '=' : alphabet[(in[1] << 2) & 0x3c];
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
171 *out++ = '=';
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
172 }
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
173
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
174 *out = '\0';
5426
8d8bf0d31a23 [gaim-migrate @ 5805]
Nathan Walp <nwalp@pidgin.im>
parents: 5341
diff changeset
175
8d8bf0d31a23 [gaim-migrate @ 5805]
Nathan Walp <nwalp@pidgin.im>
parents: 5341
diff changeset
176 return rv;
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
177 }
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
178
7108
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
179 void
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
180 gaim_base64_decode(const char *text, char **data, int *size)
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
181 {
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
182 char *out = NULL;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
183 char tmp = 0;
1920
5bed3bc833b5 [gaim-migrate @ 1930]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1878
diff changeset
184 const char *c;
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
185 gint32 tmp2 = 0;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
186 int len = 0, n = 0;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
187
7108
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
188 g_return_if_fail(text != NULL);
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
189 g_return_if_fail(data != NULL);
1920
5bed3bc833b5 [gaim-migrate @ 1930]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1878
diff changeset
190
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
191 c = text;
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
192
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
193 while (*c) {
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
194 if (*c >= 'A' && *c <= 'Z') {
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
195 tmp = *c - 'A';
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
196 } else if (*c >= 'a' && *c <= 'z') {
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
197 tmp = 26 + (*c - 'a');
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
198 } else if (*c >= '0' && *c <= 57) {
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
199 tmp = 52 + (*c - '0');
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
200 } else if (*c == '+') {
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
201 tmp = 62;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
202 } else if (*c == '/') {
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
203 tmp = 63;
5289
cfbd0cb3f18b [gaim-migrate @ 5661]
Nathan Walp <nwalp@pidgin.im>
parents: 5247
diff changeset
204 } else if (*c == '\r' || *c == '\n') {
cfbd0cb3f18b [gaim-migrate @ 5661]
Nathan Walp <nwalp@pidgin.im>
parents: 5247
diff changeset
205 c++;
cfbd0cb3f18b [gaim-migrate @ 5661]
Nathan Walp <nwalp@pidgin.im>
parents: 5247
diff changeset
206 continue;
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
207 } else if (*c == '=') {
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
208 if (n == 3) {
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
209 out = g_realloc(out, len + 2);
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
210 out[len] = (char)(tmp2 >> 10) & 0xff;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
211 len++;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
212 out[len] = (char)(tmp2 >> 2) & 0xff;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
213 len++;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
214 } else if (n == 2) {
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
215 out = g_realloc(out, len + 1);
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
216 out[len] = (char)(tmp2 >> 4) & 0xff;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
217 len++;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
218 }
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
219 break;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
220 }
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
221 tmp2 = ((tmp2 << 6) | (tmp & 0xff));
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
222 n++;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
223 if (n == 4) {
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
224 out = g_realloc(out, len + 3);
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
225 out[len] = (char)((tmp2 >> 16) & 0xff);
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
226 len++;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
227 out[len] = (char)((tmp2 >> 8) & 0xff);
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
228 len++;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
229 out[len] = (char)(tmp2 & 0xff);
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
230 len++;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
231 tmp2 = 0;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
232 n = 0;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
233 }
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
234 c++;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
235 }
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
236
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
237 out = g_realloc(out, len + 1);
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
238 out[len] = 0;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
239
1920
5bed3bc833b5 [gaim-migrate @ 1930]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1878
diff changeset
240 *data = out;
7108
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
241
1920
5bed3bc833b5 [gaim-migrate @ 1930]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1878
diff changeset
242 if (size)
5bed3bc833b5 [gaim-migrate @ 1930]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1878
diff changeset
243 *size = len;
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
244 }
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
245
7679
1363f91da9cc [gaim-migrate @ 8323]
Mark Doliner <mark@kingant.net>
parents: 7675
diff changeset
246 /**************************************************************************
1363f91da9cc [gaim-migrate @ 8323]
Mark Doliner <mark@kingant.net>
parents: 7675
diff changeset
247 * Quoted Printable Functions
1363f91da9cc [gaim-migrate @ 8323]
Mark Doliner <mark@kingant.net>
parents: 7675
diff changeset
248 **************************************************************************/
1363f91da9cc [gaim-migrate @ 8323]
Mark Doliner <mark@kingant.net>
parents: 7675
diff changeset
249 void
1363f91da9cc [gaim-migrate @ 8323]
Mark Doliner <mark@kingant.net>
parents: 7675
diff changeset
250 gaim_quotedp_decode(const char *str, char **ret_str, int *ret_len)
1363f91da9cc [gaim-migrate @ 8323]
Mark Doliner <mark@kingant.net>
parents: 7675
diff changeset
251 {
8125
abbfed0b0050 [gaim-migrate @ 8829]
Nathan Walp <nwalp@pidgin.im>
parents: 8123
diff changeset
252 char *n, *new;
abbfed0b0050 [gaim-migrate @ 8829]
Nathan Walp <nwalp@pidgin.im>
parents: 8123
diff changeset
253 const char *end, *p;
8088
a86784e3b98c [gaim-migrate @ 8787]
Ethan Blanton <elb@pidgin.im>
parents: 8064
diff changeset
254 int i;
7722
db1542e84ee6 [gaim-migrate @ 8367]
Nathan Walp <nwalp@pidgin.im>
parents: 7679
diff changeset
255
8005
3bdfb4308d10 [gaim-migrate @ 8682]
Christian Hammond <chipx86@chipx86.com>
parents: 7956
diff changeset
256 n = new = g_malloc(strlen (str) + 1);
8125
abbfed0b0050 [gaim-migrate @ 8829]
Nathan Walp <nwalp@pidgin.im>
parents: 8123
diff changeset
257 end = str + strlen(str);
7679
1363f91da9cc [gaim-migrate @ 8323]
Mark Doliner <mark@kingant.net>
parents: 7675
diff changeset
258
8125
abbfed0b0050 [gaim-migrate @ 8829]
Nathan Walp <nwalp@pidgin.im>
parents: 8123
diff changeset
259 for (p = str; p < end; p++, n++) {
7679
1363f91da9cc [gaim-migrate @ 8323]
Mark Doliner <mark@kingant.net>
parents: 7675
diff changeset
260 if (*p == '=') {
8088
a86784e3b98c [gaim-migrate @ 8787]
Ethan Blanton <elb@pidgin.im>
parents: 8064
diff changeset
261 sscanf(p + 1, "%2x\n", &i);
8125
abbfed0b0050 [gaim-migrate @ 8829]
Nathan Walp <nwalp@pidgin.im>
parents: 8123
diff changeset
262 *n = i;
7679
1363f91da9cc [gaim-migrate @ 8323]
Mark Doliner <mark@kingant.net>
parents: 7675
diff changeset
263 p += 2;
1363f91da9cc [gaim-migrate @ 8323]
Mark Doliner <mark@kingant.net>
parents: 7675
diff changeset
264 }
1363f91da9cc [gaim-migrate @ 8323]
Mark Doliner <mark@kingant.net>
parents: 7675
diff changeset
265 else if (*p == '_')
1363f91da9cc [gaim-migrate @ 8323]
Mark Doliner <mark@kingant.net>
parents: 7675
diff changeset
266 *n = ' ';
1363f91da9cc [gaim-migrate @ 8323]
Mark Doliner <mark@kingant.net>
parents: 7675
diff changeset
267 else
1363f91da9cc [gaim-migrate @ 8323]
Mark Doliner <mark@kingant.net>
parents: 7675
diff changeset
268 *n = *p;
1363f91da9cc [gaim-migrate @ 8323]
Mark Doliner <mark@kingant.net>
parents: 7675
diff changeset
269 }
1363f91da9cc [gaim-migrate @ 8323]
Mark Doliner <mark@kingant.net>
parents: 7675
diff changeset
270
1363f91da9cc [gaim-migrate @ 8323]
Mark Doliner <mark@kingant.net>
parents: 7675
diff changeset
271 *n = '\0';
1363f91da9cc [gaim-migrate @ 8323]
Mark Doliner <mark@kingant.net>
parents: 7675
diff changeset
272
1363f91da9cc [gaim-migrate @ 8323]
Mark Doliner <mark@kingant.net>
parents: 7675
diff changeset
273 if (ret_len)
1363f91da9cc [gaim-migrate @ 8323]
Mark Doliner <mark@kingant.net>
parents: 7675
diff changeset
274 *ret_len = n - new;
7722
db1542e84ee6 [gaim-migrate @ 8367]
Nathan Walp <nwalp@pidgin.im>
parents: 7679
diff changeset
275
7679
1363f91da9cc [gaim-migrate @ 8323]
Mark Doliner <mark@kingant.net>
parents: 7675
diff changeset
276 /* Resize to take less space */
1363f91da9cc [gaim-migrate @ 8323]
Mark Doliner <mark@kingant.net>
parents: 7675
diff changeset
277 /* new = realloc(new, n - new); */
1363f91da9cc [gaim-migrate @ 8323]
Mark Doliner <mark@kingant.net>
parents: 7675
diff changeset
278
1363f91da9cc [gaim-migrate @ 8323]
Mark Doliner <mark@kingant.net>
parents: 7675
diff changeset
279 *ret_str = new;
1363f91da9cc [gaim-migrate @ 8323]
Mark Doliner <mark@kingant.net>
parents: 7675
diff changeset
280 }
1363f91da9cc [gaim-migrate @ 8323]
Mark Doliner <mark@kingant.net>
parents: 7675
diff changeset
281
1363f91da9cc [gaim-migrate @ 8323]
Mark Doliner <mark@kingant.net>
parents: 7675
diff changeset
282 /**************************************************************************
1363f91da9cc [gaim-migrate @ 8323]
Mark Doliner <mark@kingant.net>
parents: 7675
diff changeset
283 * MIME Functions
1363f91da9cc [gaim-migrate @ 8323]
Mark Doliner <mark@kingant.net>
parents: 7675
diff changeset
284 **************************************************************************/
1363f91da9cc [gaim-migrate @ 8323]
Mark Doliner <mark@kingant.net>
parents: 7675
diff changeset
285 char *
1363f91da9cc [gaim-migrate @ 8323]
Mark Doliner <mark@kingant.net>
parents: 7675
diff changeset
286 gaim_mime_decode_field(const char *str)
1363f91da9cc [gaim-migrate @ 8323]
Mark Doliner <mark@kingant.net>
parents: 7675
diff changeset
287 {
7858
1ce040412bd5 [gaim-migrate @ 8512]
Mark Doliner <mark@kingant.net>
parents: 7840
diff changeset
288 /*
1ce040412bd5 [gaim-migrate @ 8512]
Mark Doliner <mark@kingant.net>
parents: 7840
diff changeset
289 * This is revo/shx's version. It has had some problems with
1ce040412bd5 [gaim-migrate @ 8512]
Mark Doliner <mark@kingant.net>
parents: 7840
diff changeset
290 * crashing, but it's probably a better implementation.
1ce040412bd5 [gaim-migrate @ 8512]
Mark Doliner <mark@kingant.net>
parents: 7840
diff changeset
291 */
1ce040412bd5 [gaim-migrate @ 8512]
Mark Doliner <mark@kingant.net>
parents: 7840
diff changeset
292 const char *cur, *mark;
1ce040412bd5 [gaim-migrate @ 8512]
Mark Doliner <mark@kingant.net>
parents: 7840
diff changeset
293 const char *unencoded, *encoded;
1ce040412bd5 [gaim-migrate @ 8512]
Mark Doliner <mark@kingant.net>
parents: 7840
diff changeset
294 char *n, *new;
1ce040412bd5 [gaim-migrate @ 8512]
Mark Doliner <mark@kingant.net>
parents: 7840
diff changeset
295
1ce040412bd5 [gaim-migrate @ 8512]
Mark Doliner <mark@kingant.net>
parents: 7840
diff changeset
296 n = new = g_malloc(strlen(str) + 1);
1ce040412bd5 [gaim-migrate @ 8512]
Mark Doliner <mark@kingant.net>
parents: 7840
diff changeset
297
1ce040412bd5 [gaim-migrate @ 8512]
Mark Doliner <mark@kingant.net>
parents: 7840
diff changeset
298 /* Here we will be looking for encoded words and if they seem to be
1ce040412bd5 [gaim-migrate @ 8512]
Mark Doliner <mark@kingant.net>
parents: 7840
diff changeset
299 * valid then decode them.
1ce040412bd5 [gaim-migrate @ 8512]
Mark Doliner <mark@kingant.net>
parents: 7840
diff changeset
300 * They are of this form: =?charset?encoding?text?=
1ce040412bd5 [gaim-migrate @ 8512]
Mark Doliner <mark@kingant.net>
parents: 7840
diff changeset
301 */
1ce040412bd5 [gaim-migrate @ 8512]
Mark Doliner <mark@kingant.net>
parents: 7840
diff changeset
302
1ce040412bd5 [gaim-migrate @ 8512]
Mark Doliner <mark@kingant.net>
parents: 7840
diff changeset
303 for (unencoded = cur = str; (encoded = cur = strstr(cur, "=?")); unencoded = cur) {
1ce040412bd5 [gaim-migrate @ 8512]
Mark Doliner <mark@kingant.net>
parents: 7840
diff changeset
304 gboolean found_word = FALSE;
1ce040412bd5 [gaim-migrate @ 8512]
Mark Doliner <mark@kingant.net>
parents: 7840
diff changeset
305 int i, num, len, dec_len;
1ce040412bd5 [gaim-migrate @ 8512]
Mark Doliner <mark@kingant.net>
parents: 7840
diff changeset
306 char *decoded, *converted;
1ce040412bd5 [gaim-migrate @ 8512]
Mark Doliner <mark@kingant.net>
parents: 7840
diff changeset
307 char *tokens[3];
1ce040412bd5 [gaim-migrate @ 8512]
Mark Doliner <mark@kingant.net>
parents: 7840
diff changeset
308
1ce040412bd5 [gaim-migrate @ 8512]
Mark Doliner <mark@kingant.net>
parents: 7840
diff changeset
309 /* Let's look for tokens, they are between ?'s */
1ce040412bd5 [gaim-migrate @ 8512]
Mark Doliner <mark@kingant.net>
parents: 7840
diff changeset
310 for (cur += 2, mark = cur, num = 0; *cur; cur++) {
1ce040412bd5 [gaim-migrate @ 8512]
Mark Doliner <mark@kingant.net>
parents: 7840
diff changeset
311 if (*cur == '?') {
1ce040412bd5 [gaim-migrate @ 8512]
Mark Doliner <mark@kingant.net>
parents: 7840
diff changeset
312 if (num > 2)
1ce040412bd5 [gaim-migrate @ 8512]
Mark Doliner <mark@kingant.net>
parents: 7840
diff changeset
313 /* No more than 3 tokens. */
1ce040412bd5 [gaim-migrate @ 8512]
Mark Doliner <mark@kingant.net>
parents: 7840
diff changeset
314 break;
1ce040412bd5 [gaim-migrate @ 8512]
Mark Doliner <mark@kingant.net>
parents: 7840
diff changeset
315
1ce040412bd5 [gaim-migrate @ 8512]
Mark Doliner <mark@kingant.net>
parents: 7840
diff changeset
316 tokens[num++] = g_strndup(mark, cur - mark);
1ce040412bd5 [gaim-migrate @ 8512]
Mark Doliner <mark@kingant.net>
parents: 7840
diff changeset
317
1ce040412bd5 [gaim-migrate @ 8512]
Mark Doliner <mark@kingant.net>
parents: 7840
diff changeset
318 mark = (cur + 1);
1ce040412bd5 [gaim-migrate @ 8512]
Mark Doliner <mark@kingant.net>
parents: 7840
diff changeset
319
1ce040412bd5 [gaim-migrate @ 8512]
Mark Doliner <mark@kingant.net>
parents: 7840
diff changeset
320 if (*mark == '=') {
1ce040412bd5 [gaim-migrate @ 8512]
Mark Doliner <mark@kingant.net>
parents: 7840
diff changeset
321 found_word = TRUE;
1ce040412bd5 [gaim-migrate @ 8512]
Mark Doliner <mark@kingant.net>
parents: 7840
diff changeset
322 break;
1ce040412bd5 [gaim-migrate @ 8512]
Mark Doliner <mark@kingant.net>
parents: 7840
diff changeset
323 }
1ce040412bd5 [gaim-migrate @ 8512]
Mark Doliner <mark@kingant.net>
parents: 7840
diff changeset
324 }
1ce040412bd5 [gaim-migrate @ 8512]
Mark Doliner <mark@kingant.net>
parents: 7840
diff changeset
325 #if 0
8735
92cbf9713795 [gaim-migrate @ 9490]
Christian Hammond <chipx86@chipx86.com>
parents: 8700
diff changeset
326 /* I think this is rarely going to happen, if at all */
7858
1ce040412bd5 [gaim-migrate @ 8512]
Mark Doliner <mark@kingant.net>
parents: 7840
diff changeset
327 else if ((num < 2) && (strchr("()<>@,;:/[]", *cur)))
1ce040412bd5 [gaim-migrate @ 8512]
Mark Doliner <mark@kingant.net>
parents: 7840
diff changeset
328 /* There can't be these characters in the first two tokens. */
1ce040412bd5 [gaim-migrate @ 8512]
Mark Doliner <mark@kingant.net>
parents: 7840
diff changeset
329 break;
1ce040412bd5 [gaim-migrate @ 8512]
Mark Doliner <mark@kingant.net>
parents: 7840
diff changeset
330 else if ((num == 2) && (*cur == ' '))
1ce040412bd5 [gaim-migrate @ 8512]
Mark Doliner <mark@kingant.net>
parents: 7840
diff changeset
331 /* There can't be spaces in the third token. */
1ce040412bd5 [gaim-migrate @ 8512]
Mark Doliner <mark@kingant.net>
parents: 7840
diff changeset
332 break;
1ce040412bd5 [gaim-migrate @ 8512]
Mark Doliner <mark@kingant.net>
parents: 7840
diff changeset
333 #endif
1ce040412bd5 [gaim-migrate @ 8512]
Mark Doliner <mark@kingant.net>
parents: 7840
diff changeset
334 }
1ce040412bd5 [gaim-migrate @ 8512]
Mark Doliner <mark@kingant.net>
parents: 7840
diff changeset
335
1ce040412bd5 [gaim-migrate @ 8512]
Mark Doliner <mark@kingant.net>
parents: 7840
diff changeset
336 cur += 2;
1ce040412bd5 [gaim-migrate @ 8512]
Mark Doliner <mark@kingant.net>
parents: 7840
diff changeset
337
1ce040412bd5 [gaim-migrate @ 8512]
Mark Doliner <mark@kingant.net>
parents: 7840
diff changeset
338 if (found_word) {
1ce040412bd5 [gaim-migrate @ 8512]
Mark Doliner <mark@kingant.net>
parents: 7840
diff changeset
339 /* We found an encoded word. */
1ce040412bd5 [gaim-migrate @ 8512]
Mark Doliner <mark@kingant.net>
parents: 7840
diff changeset
340 /* =?charset?encoding?text?= */
1ce040412bd5 [gaim-migrate @ 8512]
Mark Doliner <mark@kingant.net>
parents: 7840
diff changeset
341
1ce040412bd5 [gaim-migrate @ 8512]
Mark Doliner <mark@kingant.net>
parents: 7840
diff changeset
342 /* Some unencoded text. */
1ce040412bd5 [gaim-migrate @ 8512]
Mark Doliner <mark@kingant.net>
parents: 7840
diff changeset
343 len = encoded - unencoded;
1ce040412bd5 [gaim-migrate @ 8512]
Mark Doliner <mark@kingant.net>
parents: 7840
diff changeset
344 n = strncpy(n, unencoded, len) + len;
1ce040412bd5 [gaim-migrate @ 8512]
Mark Doliner <mark@kingant.net>
parents: 7840
diff changeset
345
1ce040412bd5 [gaim-migrate @ 8512]
Mark Doliner <mark@kingant.net>
parents: 7840
diff changeset
346 if (g_ascii_strcasecmp(tokens[1], "Q") == 0)
1ce040412bd5 [gaim-migrate @ 8512]
Mark Doliner <mark@kingant.net>
parents: 7840
diff changeset
347 gaim_quotedp_decode(tokens[2], &decoded, &dec_len);
1ce040412bd5 [gaim-migrate @ 8512]
Mark Doliner <mark@kingant.net>
parents: 7840
diff changeset
348 else if (g_ascii_strcasecmp(tokens[1], "B") == 0)
1ce040412bd5 [gaim-migrate @ 8512]
Mark Doliner <mark@kingant.net>
parents: 7840
diff changeset
349 gaim_base64_decode(tokens[2], &decoded, &dec_len);
1ce040412bd5 [gaim-migrate @ 8512]
Mark Doliner <mark@kingant.net>
parents: 7840
diff changeset
350 else
1ce040412bd5 [gaim-migrate @ 8512]
Mark Doliner <mark@kingant.net>
parents: 7840
diff changeset
351 decoded = NULL;
1ce040412bd5 [gaim-migrate @ 8512]
Mark Doliner <mark@kingant.net>
parents: 7840
diff changeset
352
1ce040412bd5 [gaim-migrate @ 8512]
Mark Doliner <mark@kingant.net>
parents: 7840
diff changeset
353 if (decoded) {
1ce040412bd5 [gaim-migrate @ 8512]
Mark Doliner <mark@kingant.net>
parents: 7840
diff changeset
354 converted = g_convert(decoded, dec_len, "utf-8", tokens[0], NULL, &len, NULL);
1ce040412bd5 [gaim-migrate @ 8512]
Mark Doliner <mark@kingant.net>
parents: 7840
diff changeset
355
1ce040412bd5 [gaim-migrate @ 8512]
Mark Doliner <mark@kingant.net>
parents: 7840
diff changeset
356 if (converted) {
1ce040412bd5 [gaim-migrate @ 8512]
Mark Doliner <mark@kingant.net>
parents: 7840
diff changeset
357 n = strncpy(n, converted, len) + len;
1ce040412bd5 [gaim-migrate @ 8512]
Mark Doliner <mark@kingant.net>
parents: 7840
diff changeset
358 g_free(converted);
1ce040412bd5 [gaim-migrate @ 8512]
Mark Doliner <mark@kingant.net>
parents: 7840
diff changeset
359 } else if (len) {
1ce040412bd5 [gaim-migrate @ 8512]
Mark Doliner <mark@kingant.net>
parents: 7840
diff changeset
360 converted = g_convert(decoded, len, "utf-8", tokens[0], NULL, &len, NULL);
1ce040412bd5 [gaim-migrate @ 8512]
Mark Doliner <mark@kingant.net>
parents: 7840
diff changeset
361 n = strncpy(n, converted, len) + len;
1ce040412bd5 [gaim-migrate @ 8512]
Mark Doliner <mark@kingant.net>
parents: 7840
diff changeset
362 g_free(converted);
1ce040412bd5 [gaim-migrate @ 8512]
Mark Doliner <mark@kingant.net>
parents: 7840
diff changeset
363 }
1ce040412bd5 [gaim-migrate @ 8512]
Mark Doliner <mark@kingant.net>
parents: 7840
diff changeset
364 g_free(decoded);
1ce040412bd5 [gaim-migrate @ 8512]
Mark Doliner <mark@kingant.net>
parents: 7840
diff changeset
365 }
1ce040412bd5 [gaim-migrate @ 8512]
Mark Doliner <mark@kingant.net>
parents: 7840
diff changeset
366 } else {
1ce040412bd5 [gaim-migrate @ 8512]
Mark Doliner <mark@kingant.net>
parents: 7840
diff changeset
367 /* Some unencoded text. */
1ce040412bd5 [gaim-migrate @ 8512]
Mark Doliner <mark@kingant.net>
parents: 7840
diff changeset
368 len = cur - unencoded;
1ce040412bd5 [gaim-migrate @ 8512]
Mark Doliner <mark@kingant.net>
parents: 7840
diff changeset
369 n = strncpy(n, unencoded, len) + len;
1ce040412bd5 [gaim-migrate @ 8512]
Mark Doliner <mark@kingant.net>
parents: 7840
diff changeset
370 }
1ce040412bd5 [gaim-migrate @ 8512]
Mark Doliner <mark@kingant.net>
parents: 7840
diff changeset
371
1ce040412bd5 [gaim-migrate @ 8512]
Mark Doliner <mark@kingant.net>
parents: 7840
diff changeset
372 for (i = 0; i < num; i++)
1ce040412bd5 [gaim-migrate @ 8512]
Mark Doliner <mark@kingant.net>
parents: 7840
diff changeset
373 g_free(tokens[i]);
1ce040412bd5 [gaim-migrate @ 8512]
Mark Doliner <mark@kingant.net>
parents: 7840
diff changeset
374 }
1ce040412bd5 [gaim-migrate @ 8512]
Mark Doliner <mark@kingant.net>
parents: 7840
diff changeset
375
1ce040412bd5 [gaim-migrate @ 8512]
Mark Doliner <mark@kingant.net>
parents: 7840
diff changeset
376 *n = '\0';
1ce040412bd5 [gaim-migrate @ 8512]
Mark Doliner <mark@kingant.net>
parents: 7840
diff changeset
377
1ce040412bd5 [gaim-migrate @ 8512]
Mark Doliner <mark@kingant.net>
parents: 7840
diff changeset
378 /* There is unencoded text at the end. */
1ce040412bd5 [gaim-migrate @ 8512]
Mark Doliner <mark@kingant.net>
parents: 7840
diff changeset
379 if (*unencoded)
1ce040412bd5 [gaim-migrate @ 8512]
Mark Doliner <mark@kingant.net>
parents: 7840
diff changeset
380 n = strcpy(n, unencoded);
1ce040412bd5 [gaim-migrate @ 8512]
Mark Doliner <mark@kingant.net>
parents: 7840
diff changeset
381
1ce040412bd5 [gaim-migrate @ 8512]
Mark Doliner <mark@kingant.net>
parents: 7840
diff changeset
382 return new;
7840
13334c29799b [gaim-migrate @ 8493]
Mark Doliner <mark@kingant.net>
parents: 7824
diff changeset
383 }
7824
1663c076a744 [gaim-migrate @ 8476]
Mark Doliner <mark@kingant.net>
parents: 7820
diff changeset
384
7679
1363f91da9cc [gaim-migrate @ 8323]
Mark Doliner <mark@kingant.net>
parents: 7675
diff changeset
385
7108
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
386 /**************************************************************************
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
387 * Date/Time Functions
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
388 **************************************************************************/
7162
d14e026611c0 [gaim-migrate @ 7729]
Nathan Walp <nwalp@pidgin.im>
parents: 7134
diff changeset
389 const char *
7108
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
390 gaim_date(void)
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
391 {
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
392 static char date[80];
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
393 time_t tme;
7108
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
394
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
395 time(&tme);
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
396 strftime(date, sizeof(date), "%H:%M:%S", localtime(&tme));
7108
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
397
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
398 return date;
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
399 }
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
400
7162
d14e026611c0 [gaim-migrate @ 7729]
Nathan Walp <nwalp@pidgin.im>
parents: 7134
diff changeset
401 const char *
7108
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
402 gaim_date_full(void)
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
403 {
7108
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
404 char *date;
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
405 time_t tme;
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
406
7108
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
407 time(&tme);
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
408 date = ctime(&tme);
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
409 date[strlen(date) - 1] = '\0';
1100
f168625b63fe [gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1087
diff changeset
410
7108
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
411 return date;
3630
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3572
diff changeset
412 }
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3572
diff changeset
413
7108
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
414 time_t
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
415 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
416 {
caa605e70917 [gaim-migrate @ 1815]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1753
diff changeset
417 struct tm tm;
caa605e70917 [gaim-migrate @ 1815]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1753
diff changeset
418
caa605e70917 [gaim-migrate @ 1815]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1753
diff changeset
419 tm.tm_year = year - 1900;
caa605e70917 [gaim-migrate @ 1815]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1753
diff changeset
420 tm.tm_mon = month - 1;
caa605e70917 [gaim-migrate @ 1815]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1753
diff changeset
421 tm.tm_mday = day;
caa605e70917 [gaim-migrate @ 1815]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1753
diff changeset
422 tm.tm_hour = hour;
caa605e70917 [gaim-migrate @ 1815]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1753
diff changeset
423 tm.tm_min = min;
caa605e70917 [gaim-migrate @ 1815]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1753
diff changeset
424 tm.tm_sec = sec >= 0 ? sec : time(NULL) % 60;
7108
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
425
1805
caa605e70917 [gaim-migrate @ 1815]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1753
diff changeset
426 return mktime(&tm);
caa605e70917 [gaim-migrate @ 1815]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1753
diff changeset
427 }
3230
d05dc05bde8a [gaim-migrate @ 3247]
Jim Seymour <jseymour>
parents: 3153
diff changeset
428
8577
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8561
diff changeset
429 time_t
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8561
diff changeset
430 gaim_str_to_time(const char *timestamp, gboolean utc)
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8561
diff changeset
431 {
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8561
diff changeset
432 struct tm t;
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8561
diff changeset
433 time_t retval = 0;
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8561
diff changeset
434 char buf[32];
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8561
diff changeset
435 char *c;
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8561
diff changeset
436 int tzoff = 0;
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8561
diff changeset
437
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8561
diff changeset
438 time(&retval);
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8561
diff changeset
439 localtime_r(&retval, &t);
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8561
diff changeset
440
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8561
diff changeset
441 snprintf(buf, sizeof(buf), "%s", timestamp);
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8561
diff changeset
442 c = buf;
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8561
diff changeset
443
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8561
diff changeset
444 /* 4 digit year */
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8561
diff changeset
445 if(!sscanf(c, "%04d", &t.tm_year)) return 0;
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8561
diff changeset
446 c+=4;
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8561
diff changeset
447 if(*c == '-')
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8561
diff changeset
448 c++;
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8561
diff changeset
449
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8561
diff changeset
450 t.tm_year -= 1900;
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8561
diff changeset
451
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8561
diff changeset
452 /* 2 digit month */
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8561
diff changeset
453 if(!sscanf(c, "%02d", &t.tm_mon)) return 0;
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8561
diff changeset
454 c+=2;
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8561
diff changeset
455 if(*c == '-')
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8561
diff changeset
456 c++;
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8561
diff changeset
457
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8561
diff changeset
458 t.tm_mon -= 1;
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8561
diff changeset
459
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8561
diff changeset
460
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8561
diff changeset
461 /* 2 digit day */
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8561
diff changeset
462 if(!sscanf(c, "%02d", &t.tm_mday)) return 0;
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8561
diff changeset
463 c+=2;
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8561
diff changeset
464 if(*c == 'T' || *c == '.') { /* we have more than a date, keep going */
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8561
diff changeset
465 c++; /* skip the "T" */
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8561
diff changeset
466
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8561
diff changeset
467 /* 2 digit hour */
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8561
diff changeset
468 if(sscanf(c, "%02d:%02d:%02d", &t.tm_hour, &t.tm_min, &t.tm_sec) == 3 ||
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8561
diff changeset
469 sscanf(c, "%02d%02d%02d", &t.tm_hour, &t.tm_min, &t.tm_sec) == 3) {
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8561
diff changeset
470 int tzhrs, tzmins;
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8561
diff changeset
471 c+=8;
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8561
diff changeset
472 if(*c == '.') /* dealing with precision we don't care about */
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8561
diff changeset
473 c += 4;
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8561
diff changeset
474
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8561
diff changeset
475 if((*c == '+' || *c == '-') &&
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8561
diff changeset
476 sscanf(c+1, "%02d:%02d", &tzhrs, &tzmins)) {
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8561
diff changeset
477 tzoff = tzhrs*60*60 + tzmins*60;
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8561
diff changeset
478 if(*c == '+')
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8561
diff changeset
479 tzoff *= -1;
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8561
diff changeset
480 }
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8561
diff changeset
481
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8561
diff changeset
482 if(tzoff || utc) {
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8561
diff changeset
483
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8561
diff changeset
484 #ifdef HAVE_TM_GMTOFF
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8561
diff changeset
485 tzoff += t.tm_gmtoff;
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8561
diff changeset
486 #else
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8561
diff changeset
487 # ifdef HAVE_TIMEZONE
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8561
diff changeset
488 tzset(); /* making sure */
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8561
diff changeset
489 tzoff -= timezone;
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8561
diff changeset
490 # endif
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8561
diff changeset
491 #endif
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8561
diff changeset
492 }
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8561
diff changeset
493 }
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8561
diff changeset
494 }
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8561
diff changeset
495
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8561
diff changeset
496 t.tm_isdst = -1;
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8561
diff changeset
497
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8561
diff changeset
498 retval = mktime(&t);
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8561
diff changeset
499
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8561
diff changeset
500 retval += tzoff;
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8561
diff changeset
501
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8561
diff changeset
502 return retval;
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8561
diff changeset
503 }
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8561
diff changeset
504
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8561
diff changeset
505
3230
d05dc05bde8a [gaim-migrate @ 3247]
Jim Seymour <jseymour>
parents: 3153
diff changeset
506
7108
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
507 /**************************************************************************
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
508 * Markup Functions
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
509 **************************************************************************/
7094
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
510 gboolean
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
511 gaim_markup_find_tag(const char *needle, const char *haystack,
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
512 const char **start, const char **end, GData **attributes)
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
513 {
6982
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6872
diff changeset
514 GData *attribs;
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6872
diff changeset
515 const char *cur = haystack;
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6872
diff changeset
516 char *name = NULL;
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6872
diff changeset
517 gboolean found = FALSE;
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6872
diff changeset
518 gboolean in_tag = FALSE;
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6872
diff changeset
519 gboolean in_attr = FALSE;
7094
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
520 const char *in_quotes = NULL;
7804
622c9149609c [gaim-migrate @ 8451]
Nathan Walp <nwalp@pidgin.im>
parents: 7722
diff changeset
521 size_t needlelen;
6982
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6872
diff changeset
522
7804
622c9149609c [gaim-migrate @ 8451]
Nathan Walp <nwalp@pidgin.im>
parents: 7722
diff changeset
523 g_return_val_if_fail( needle != NULL, FALSE);
622c9149609c [gaim-migrate @ 8451]
Nathan Walp <nwalp@pidgin.im>
parents: 7722
diff changeset
524 g_return_val_if_fail( *needle != '\0', FALSE);
622c9149609c [gaim-migrate @ 8451]
Nathan Walp <nwalp@pidgin.im>
parents: 7722
diff changeset
525 g_return_val_if_fail( haystack != NULL, FALSE);
622c9149609c [gaim-migrate @ 8451]
Nathan Walp <nwalp@pidgin.im>
parents: 7722
diff changeset
526 g_return_val_if_fail( *haystack != '\0', FALSE);
622c9149609c [gaim-migrate @ 8451]
Nathan Walp <nwalp@pidgin.im>
parents: 7722
diff changeset
527 g_return_val_if_fail( start != NULL, FALSE);
622c9149609c [gaim-migrate @ 8451]
Nathan Walp <nwalp@pidgin.im>
parents: 7722
diff changeset
528 g_return_val_if_fail( end != NULL, FALSE);
622c9149609c [gaim-migrate @ 8451]
Nathan Walp <nwalp@pidgin.im>
parents: 7722
diff changeset
529 g_return_val_if_fail(attributes != NULL, FALSE);
622c9149609c [gaim-migrate @ 8451]
Nathan Walp <nwalp@pidgin.im>
parents: 7722
diff changeset
530
622c9149609c [gaim-migrate @ 8451]
Nathan Walp <nwalp@pidgin.im>
parents: 7722
diff changeset
531 needlelen = strlen(needle);
6982
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6872
diff changeset
532 g_datalist_init(&attribs);
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6872
diff changeset
533
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6872
diff changeset
534 while (*cur && !found) {
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6872
diff changeset
535 if (in_tag) {
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6872
diff changeset
536 if (in_quotes) {
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6872
diff changeset
537 const char *close = cur;
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6872
diff changeset
538
7078
acd2a66e59ed [gaim-migrate @ 7643]
Nathan Walp <nwalp@pidgin.im>
parents: 7000
diff changeset
539 while (*close && *close != *in_quotes)
6982
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6872
diff changeset
540 close++;
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6872
diff changeset
541
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6872
diff changeset
542 /* if we got the close quote, store the value and carry on from *
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6872
diff changeset
543 * after it. if we ran to the end of the string, point to the NULL *
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6872
diff changeset
544 * and we're outta here */
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6872
diff changeset
545 if (*close) {
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6872
diff changeset
546 /* only store a value if we have an attribute name */
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6872
diff changeset
547 if (name) {
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6872
diff changeset
548 size_t len = close - cur;
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6872
diff changeset
549 char *val = g_strndup(cur, len);
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6872
diff changeset
550
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6872
diff changeset
551 g_datalist_set_data_full(&attribs, name, val, g_free);
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6872
diff changeset
552 g_free(name);
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6872
diff changeset
553 name = NULL;
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6872
diff changeset
554 }
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6872
diff changeset
555
7078
acd2a66e59ed [gaim-migrate @ 7643]
Nathan Walp <nwalp@pidgin.im>
parents: 7000
diff changeset
556 in_quotes = NULL;
6982
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6872
diff changeset
557 cur = close + 1;
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6872
diff changeset
558 } else {
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6872
diff changeset
559 cur = close;
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6872
diff changeset
560 }
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6872
diff changeset
561 } else if (in_attr) {
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6872
diff changeset
562 const char *close = cur;
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6872
diff changeset
563
7078
acd2a66e59ed [gaim-migrate @ 7643]
Nathan Walp <nwalp@pidgin.im>
parents: 7000
diff changeset
564 while (*close && *close != '>' && *close != '"' &&
acd2a66e59ed [gaim-migrate @ 7643]
Nathan Walp <nwalp@pidgin.im>
parents: 7000
diff changeset
565 *close != '\'' && *close != ' ' && *close != '=')
6982
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6872
diff changeset
566 close++;
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6872
diff changeset
567
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6872
diff changeset
568 /* if we got the equals, store the name of the attribute. if we got
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6872
diff changeset
569 * the quote, save the attribute and go straight to quote mode.
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6872
diff changeset
570 * otherwise the tag closed or we reached the end of the string,
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6872
diff changeset
571 * so we can get outta here */
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6872
diff changeset
572 switch (*close) {
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6872
diff changeset
573 case '"':
7078
acd2a66e59ed [gaim-migrate @ 7643]
Nathan Walp <nwalp@pidgin.im>
parents: 7000
diff changeset
574 case '\'':
acd2a66e59ed [gaim-migrate @ 7643]
Nathan Walp <nwalp@pidgin.im>
parents: 7000
diff changeset
575 in_quotes = close;
6982
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6872
diff changeset
576 case '=':
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6872
diff changeset
577 {
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6872
diff changeset
578 size_t len = close - cur;
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6872
diff changeset
579
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6872
diff changeset
580 /* don't store a blank attribute name */
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6872
diff changeset
581 if (len) {
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6872
diff changeset
582 if (name)
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6872
diff changeset
583 g_free(name);
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6872
diff changeset
584 name = g_ascii_strdown(cur, len);
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6872
diff changeset
585 }
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6872
diff changeset
586
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6872
diff changeset
587 in_attr = FALSE;
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6872
diff changeset
588 cur = close + 1;
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6872
diff changeset
589 break;
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6872
diff changeset
590 }
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6872
diff changeset
591 case ' ':
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6872
diff changeset
592 case '>':
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6872
diff changeset
593 in_attr = FALSE;
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6872
diff changeset
594 default:
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6872
diff changeset
595 cur = close;
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6872
diff changeset
596 break;
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6872
diff changeset
597 }
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6872
diff changeset
598 } else {
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6872
diff changeset
599 switch (*cur) {
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6872
diff changeset
600 case ' ':
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6872
diff changeset
601 /* swallow extra spaces inside tag */
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6872
diff changeset
602 while (*cur && *cur == ' ') cur++;
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6872
diff changeset
603 in_attr = TRUE;
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6872
diff changeset
604 break;
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6872
diff changeset
605 case '>':
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6872
diff changeset
606 found = TRUE;
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6872
diff changeset
607 *end = cur;
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6872
diff changeset
608 break;
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6872
diff changeset
609 case '"':
7078
acd2a66e59ed [gaim-migrate @ 7643]
Nathan Walp <nwalp@pidgin.im>
parents: 7000
diff changeset
610 case '\'':
acd2a66e59ed [gaim-migrate @ 7643]
Nathan Walp <nwalp@pidgin.im>
parents: 7000
diff changeset
611 in_quotes = cur;
6982
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6872
diff changeset
612 default:
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6872
diff changeset
613 cur++;
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6872
diff changeset
614 break;
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6872
diff changeset
615 }
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6872
diff changeset
616 }
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6872
diff changeset
617 } else {
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6872
diff changeset
618 /* if we hit a < followed by the name of our tag... */
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6872
diff changeset
619 if (*cur == '<' && !g_ascii_strncasecmp(cur + 1, needle, needlelen)) {
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6872
diff changeset
620 *start = cur;
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6872
diff changeset
621 cur = cur + needlelen + 1;
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6872
diff changeset
622
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6872
diff changeset
623 /* if we're pointing at a space or a >, we found the right tag. if *
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6872
diff changeset
624 * we're not, we've found a longer tag, so we need to skip to the *
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6872
diff changeset
625 * >, but not being distracted by >s inside quotes. */
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6872
diff changeset
626 if (*cur == ' ' || *cur == '>') {
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6872
diff changeset
627 in_tag = TRUE;
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6872
diff changeset
628 } else {
7804
622c9149609c [gaim-migrate @ 8451]
Nathan Walp <nwalp@pidgin.im>
parents: 7722
diff changeset
629 while (*cur && *cur != '"' && *cur != '\'' && *cur != '>') {
6982
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6872
diff changeset
630 if (*cur == '"') {
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6872
diff changeset
631 cur++;
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6872
diff changeset
632 while (*cur && *cur != '"')
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6872
diff changeset
633 cur++;
7804
622c9149609c [gaim-migrate @ 8451]
Nathan Walp <nwalp@pidgin.im>
parents: 7722
diff changeset
634 } else if (*cur == '\'') {
622c9149609c [gaim-migrate @ 8451]
Nathan Walp <nwalp@pidgin.im>
parents: 7722
diff changeset
635 cur++;
622c9149609c [gaim-migrate @ 8451]
Nathan Walp <nwalp@pidgin.im>
parents: 7722
diff changeset
636 while (*cur && *cur != '\'')
622c9149609c [gaim-migrate @ 8451]
Nathan Walp <nwalp@pidgin.im>
parents: 7722
diff changeset
637 cur++;
6982
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6872
diff changeset
638 } else {
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6872
diff changeset
639 cur++;
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6872
diff changeset
640 }
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6872
diff changeset
641 }
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6872
diff changeset
642 }
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6872
diff changeset
643 } else {
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6872
diff changeset
644 cur++;
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6872
diff changeset
645 }
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6872
diff changeset
646 }
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6872
diff changeset
647 }
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6872
diff changeset
648
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6872
diff changeset
649 /* clean up any attribute name from a premature termination */
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6872
diff changeset
650 if (name)
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6872
diff changeset
651 g_free(name);
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6872
diff changeset
652
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6872
diff changeset
653 if (found) {
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6872
diff changeset
654 *attributes = attribs;
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6872
diff changeset
655 } else {
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6872
diff changeset
656 *start = NULL;
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6872
diff changeset
657 *end = NULL;
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6872
diff changeset
658 *attributes = NULL;
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6872
diff changeset
659 }
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6872
diff changeset
660
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6872
diff changeset
661 return found;
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6872
diff changeset
662 }
7094
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
663
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
664 gboolean
7675
66d9440db6ec [gaim-migrate @ 8319]
Luke Schierer <lschiere@pidgin.im>
parents: 7673
diff changeset
665 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
666 const char *start_token, int skip,
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
667 const char *end_token, char check_value,
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
668 const char *no_value_token,
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
669 const char *display_name, gboolean is_link,
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
670 const char *link_prefix)
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
671 {
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
672 const char *p, *q;
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
673
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
674 g_return_val_if_fail(str != NULL, FALSE);
7675
66d9440db6ec [gaim-migrate @ 8319]
Luke Schierer <lschiere@pidgin.im>
parents: 7673
diff changeset
675 g_return_val_if_fail(dest != NULL, FALSE);
7095
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
676 g_return_val_if_fail(start_token != NULL, FALSE);
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
677 g_return_val_if_fail(end_token != NULL, FALSE);
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
678 g_return_val_if_fail(display_name != NULL, FALSE);
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
679
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
680 p = strstr(str, start_token);
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
681
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
682 if (p == NULL)
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
683 return FALSE;
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
684
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
685 p += strlen(start_token) + skip;
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
686
7675
66d9440db6ec [gaim-migrate @ 8319]
Luke Schierer <lschiere@pidgin.im>
parents: 7673
diff changeset
687 if (p >= str + len)
66d9440db6ec [gaim-migrate @ 8319]
Luke Schierer <lschiere@pidgin.im>
parents: 7673
diff changeset
688 return FALSE;
66d9440db6ec [gaim-migrate @ 8319]
Luke Schierer <lschiere@pidgin.im>
parents: 7673
diff changeset
689
7095
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
690 if (check_value != '\0' && *p == check_value)
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
691 return FALSE;
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
692
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
693 q = strstr(p, end_token);
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
694
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
695 if (q != NULL && (!no_value_token ||
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
696 (no_value_token && strncmp(p, no_value_token,
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
697 strlen(no_value_token)))))
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
698 {
7675
66d9440db6ec [gaim-migrate @ 8319]
Luke Schierer <lschiere@pidgin.im>
parents: 7673
diff changeset
699 g_string_append(dest, "<b>");
66d9440db6ec [gaim-migrate @ 8319]
Luke Schierer <lschiere@pidgin.im>
parents: 7673
diff changeset
700 g_string_append(dest, display_name);
66d9440db6ec [gaim-migrate @ 8319]
Luke Schierer <lschiere@pidgin.im>
parents: 7673
diff changeset
701 g_string_append(dest, ":</b> ");
7095
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
702
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
703 if (is_link)
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
704 {
7675
66d9440db6ec [gaim-migrate @ 8319]
Luke Schierer <lschiere@pidgin.im>
parents: 7673
diff changeset
705 g_string_append(dest, "<br><a href=\"");
7095
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
706
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
707 if (link_prefix)
7675
66d9440db6ec [gaim-migrate @ 8319]
Luke Schierer <lschiere@pidgin.im>
parents: 7673
diff changeset
708 g_string_append(dest, link_prefix);
7095
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
709
7675
66d9440db6ec [gaim-migrate @ 8319]
Luke Schierer <lschiere@pidgin.im>
parents: 7673
diff changeset
710 g_string_append_len(dest, p, q - p);
66d9440db6ec [gaim-migrate @ 8319]
Luke Schierer <lschiere@pidgin.im>
parents: 7673
diff changeset
711 g_string_append(dest, "\">");
7095
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
712
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
713 if (link_prefix)
7675
66d9440db6ec [gaim-migrate @ 8319]
Luke Schierer <lschiere@pidgin.im>
parents: 7673
diff changeset
714 g_string_append(dest, link_prefix);
7095
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
715
7675
66d9440db6ec [gaim-migrate @ 8319]
Luke Schierer <lschiere@pidgin.im>
parents: 7673
diff changeset
716 g_string_append_len(dest, p, q - p);
66d9440db6ec [gaim-migrate @ 8319]
Luke Schierer <lschiere@pidgin.im>
parents: 7673
diff changeset
717 g_string_append(dest, "</a>");
7095
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
718 }
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
719 else
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
720 {
7675
66d9440db6ec [gaim-migrate @ 8319]
Luke Schierer <lschiere@pidgin.im>
parents: 7673
diff changeset
721 g_string_append_len(dest, p, q - p);
7095
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
722 }
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
723
7675
66d9440db6ec [gaim-migrate @ 8319]
Luke Schierer <lschiere@pidgin.im>
parents: 7673
diff changeset
724 g_string_append(dest, "<br>\n");
7095
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
725
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
726 return TRUE;
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
727 }
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
728
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
729 return FALSE;
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
730 }
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
731
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
732 struct gaim_parse_tag {
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
733 char *src_tag;
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
734 char *dest_tag;
8064
9b6bc1010054 [gaim-migrate @ 8757]
Nathan Walp <nwalp@pidgin.im>
parents: 8063
diff changeset
735 gboolean ignore;
7095
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
736 };
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
737
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
738 #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
739 const char *o = c + strlen("<" x); \
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
740 const char *p = NULL, *q = NULL, *r = NULL; \
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
741 GString *innards = g_string_new(""); \
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
742 while(o && *o) { \
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
743 if(!q && (*o == '\"' || *o == '\'') ) { \
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
744 q = o; \
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
745 } else if(q) { \
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
746 if(*o == *q) { \
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
747 char *unescaped = g_strndup(q+1, o-q-1); \
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
748 char *escaped = g_markup_escape_text(unescaped, -1); \
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
749 g_string_append_printf(innards, "%c%s%c", *q, escaped, *q); \
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
750 g_free(unescaped); \
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
751 g_free(escaped); \
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
752 q = NULL; \
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
753 } else if(*c == '\\') { \
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
754 o++; \
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
755 } \
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
756 } else if(*o == '<') { \
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
757 r = o; \
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
758 } else if(*o == '>') { \
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
759 p = o; \
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
760 break; \
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
761 } else { \
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
762 innards = g_string_append_c(innards, *o); \
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
763 } \
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
764 o++; \
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
765 } \
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
766 if(p && !r) { \
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
767 if(*(p-1) != '/') { \
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
768 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
769 pt->src_tag = x; \
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
770 pt->dest_tag = y; \
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
771 tags = g_list_prepend(tags, pt); \
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
772 } \
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
773 xhtml = g_string_append(xhtml, "<" y); \
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
774 c += strlen("<" x ); \
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
775 xhtml = g_string_append(xhtml, innards->str); \
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
776 xhtml = g_string_append_c(xhtml, '>'); \
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
777 c = p + 1; \
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
778 } else { \
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
779 xhtml = g_string_append(xhtml, "&lt;"); \
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
780 plain = g_string_append_c(plain, '<'); \
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
781 c++; \
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
782 } \
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
783 g_string_free(innards, TRUE); \
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
784 continue; \
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
785 } \
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
786 if(!g_ascii_strncasecmp(c, "<" x, strlen("<" x)) && \
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
787 (*(c+strlen("<" x)) == '>' || \
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
788 !g_ascii_strncasecmp(c+strlen("<" x), "/>", 2))) { \
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
789 xhtml = g_string_append(xhtml, "<" y); \
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
790 c += strlen("<" x); \
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
791 if(*c != '/') { \
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
792 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
793 pt->src_tag = x; \
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
794 pt->dest_tag = y; \
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
795 tags = g_list_prepend(tags, pt); \
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
796 xhtml = g_string_append_c(xhtml, '>'); \
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
797 } else { \
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
798 xhtml = g_string_append(xhtml, "/>");\
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
799 } \
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
800 c = strchr(c, '>') + 1; \
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
801 continue; \
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
802 }
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
803 #define ALLOW_TAG(x) ALLOW_TAG_ALT(x, x)
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
804 void
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
805 gaim_markup_html_to_xhtml(const char *html, char **xhtml_out,
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
806 char **plain_out)
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
807 {
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
808 GString *xhtml = g_string_new("");
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
809 GString *plain = g_string_new("");
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
810 GList *tags = NULL, *tag;
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
811 const char *c = html;
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
812
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
813 while(c && *c) {
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
814 if(*c == '<') {
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
815 if(*(c+1) == '/') { /* closing tag */
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
816 tag = tags;
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
817 while(tag) {
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
818 struct gaim_parse_tag *pt = tag->data;
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
819 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
820 c += strlen(pt->src_tag) + 3;
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
821 break;
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
822 }
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
823 tag = tag->next;
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
824 }
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
825 if(tag) {
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
826 while(tags) {
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
827 struct gaim_parse_tag *pt = tags->data;
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
828 g_string_append_printf(xhtml, "</%s>", pt->dest_tag);
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
829 if(tags == tag)
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
830 break;
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
831 tags = g_list_remove(tags, pt);
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
832 g_free(pt);
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
833 }
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
834 g_free(tag->data);
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
835 tags = g_list_remove(tags, tag->data);
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
836 } else {
8534
389e2b9dae6a [gaim-migrate @ 9273]
Nathan Walp <nwalp@pidgin.im>
parents: 8517
diff changeset
837 /* a closing tag we weren't expecting...
389e2b9dae6a [gaim-migrate @ 9273]
Nathan Walp <nwalp@pidgin.im>
parents: 8517
diff changeset
838 * we'll let it slide, if it's really a tag...if it's
389e2b9dae6a [gaim-migrate @ 9273]
Nathan Walp <nwalp@pidgin.im>
parents: 8517
diff changeset
839 * just a </ we'll escape it properly */
389e2b9dae6a [gaim-migrate @ 9273]
Nathan Walp <nwalp@pidgin.im>
parents: 8517
diff changeset
840 const char *end = c+2;
389e2b9dae6a [gaim-migrate @ 9273]
Nathan Walp <nwalp@pidgin.im>
parents: 8517
diff changeset
841 while(*end && g_ascii_isalpha(*end))
389e2b9dae6a [gaim-migrate @ 9273]
Nathan Walp <nwalp@pidgin.im>
parents: 8517
diff changeset
842 end++;
389e2b9dae6a [gaim-migrate @ 9273]
Nathan Walp <nwalp@pidgin.im>
parents: 8517
diff changeset
843 if(*end == '>') {
389e2b9dae6a [gaim-migrate @ 9273]
Nathan Walp <nwalp@pidgin.im>
parents: 8517
diff changeset
844 c = end+1;
389e2b9dae6a [gaim-migrate @ 9273]
Nathan Walp <nwalp@pidgin.im>
parents: 8517
diff changeset
845 } else {
389e2b9dae6a [gaim-migrate @ 9273]
Nathan Walp <nwalp@pidgin.im>
parents: 8517
diff changeset
846 xhtml = g_string_append(xhtml, "&lt;");
389e2b9dae6a [gaim-migrate @ 9273]
Nathan Walp <nwalp@pidgin.im>
parents: 8517
diff changeset
847 plain = g_string_append_c(plain, '<');
389e2b9dae6a [gaim-migrate @ 9273]
Nathan Walp <nwalp@pidgin.im>
parents: 8517
diff changeset
848 c++;
389e2b9dae6a [gaim-migrate @ 9273]
Nathan Walp <nwalp@pidgin.im>
parents: 8517
diff changeset
849 }
7095
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
850 }
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
851 } else { /* opening tag */
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
852 ALLOW_TAG("a");
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
853 ALLOW_TAG_ALT("b", "strong");
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
854 ALLOW_TAG("blockquote");
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
855 ALLOW_TAG_ALT("bold", "strong");
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
856 ALLOW_TAG("cite");
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
857 ALLOW_TAG("div");
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
858 ALLOW_TAG("em");
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
859 ALLOW_TAG("h1");
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
860 ALLOW_TAG("h2");
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
861 ALLOW_TAG("h3");
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
862 ALLOW_TAG("h4");
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
863 ALLOW_TAG("h5");
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
864 ALLOW_TAG("h6");
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
865 /* we only allow html to start the message */
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
866 if(c == html)
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
867 ALLOW_TAG("html");
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
868 ALLOW_TAG_ALT("i", "em");
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
869 ALLOW_TAG_ALT("italic", "em");
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
870 ALLOW_TAG("li");
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
871 ALLOW_TAG("ol");
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
872 ALLOW_TAG("p");
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
873 ALLOW_TAG("pre");
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
874 ALLOW_TAG("q");
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
875 ALLOW_TAG("span");
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
876 ALLOW_TAG("strong");
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
877 ALLOW_TAG("ul");
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
878
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
879 /* 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
880 * we still want to send something sensible, so we put a
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
881 * linebreak in its place. <BR> also needs special handling
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
882 * because putting a </BR> to close it would just be dumb. */
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
883 if((!g_ascii_strncasecmp(c, "<br", 3)
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
884 || !g_ascii_strncasecmp(c, "<hr", 3))
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
885 && (*(c+3) == '>' ||
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
886 !g_ascii_strncasecmp(c+3, "/>", 2) ||
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
887 !g_ascii_strncasecmp(c+3, " />", 3))) {
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
888 c = strchr(c, '>') + 1;
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
889 xhtml = g_string_append(xhtml, "<br/>");
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
890 if(*c != '\n')
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
891 plain = g_string_append_c(plain, '\n');
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
892 continue;
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
893 }
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
894 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
895 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
896 pt->src_tag = *(c+2) == '>' ? "u" : "underline";
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
897 pt->dest_tag = "span";
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
898 tags = g_list_prepend(tags, pt);
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
899 c = strchr(c, '>') + 1;
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
900 xhtml = g_string_append(xhtml, "<span style='text-decoration: underline;'>");
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
901 continue;
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
902 }
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
903 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
904 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
905 pt->src_tag = *(c+2) == '>' ? "s" : "strike";
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
906 pt->dest_tag = "span";
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
907 tags = g_list_prepend(tags, pt);
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
908 c = strchr(c, '>') + 1;
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
909 xhtml = g_string_append(xhtml, "<span style='text-decoration: line-through;'>");
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
910 continue;
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
911 }
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
912 if(!g_ascii_strncasecmp(c, "<sub>", 5)) {
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
913 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
914 pt->src_tag = "sub";
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
915 pt->dest_tag = "span";
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
916 tags = g_list_prepend(tags, pt);
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
917 c = strchr(c, '>') + 1;
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
918 xhtml = g_string_append(xhtml, "<span style='vertical-align:sub;'>");
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
919 continue;
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
920 }
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
921 if(!g_ascii_strncasecmp(c, "<sup>", 5)) {
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
922 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
923 pt->src_tag = "sup";
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
924 pt->dest_tag = "span";
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
925 tags = g_list_prepend(tags, pt);
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
926 c = strchr(c, '>') + 1;
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
927 xhtml = g_string_append(xhtml, "<span style='vertical-align:super;'>");
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
928 continue;
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
929 }
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
930 if(!g_ascii_strncasecmp(c, "<font", 5) && (*(c+5) == '>' || *(c+5) == ' ')) {
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
931 const char *p = c;
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
932 GString *style = g_string_new("");
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
933 struct gaim_parse_tag *pt;
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
934 while(*p && *p != '>') {
8064
9b6bc1010054 [gaim-migrate @ 8757]
Nathan Walp <nwalp@pidgin.im>
parents: 8063
diff changeset
935 if(!g_ascii_strncasecmp(p, "back=", strlen("back="))) {
9b6bc1010054 [gaim-migrate @ 8757]
Nathan Walp <nwalp@pidgin.im>
parents: 8063
diff changeset
936 const char *q = p + strlen("back=");
9b6bc1010054 [gaim-migrate @ 8757]
Nathan Walp <nwalp@pidgin.im>
parents: 8063
diff changeset
937 GString *color = g_string_new("");
9b6bc1010054 [gaim-migrate @ 8757]
Nathan Walp <nwalp@pidgin.im>
parents: 8063
diff changeset
938 if(*q == '\'' || *q == '\"')
9b6bc1010054 [gaim-migrate @ 8757]
Nathan Walp <nwalp@pidgin.im>
parents: 8063
diff changeset
939 q++;
9b6bc1010054 [gaim-migrate @ 8757]
Nathan Walp <nwalp@pidgin.im>
parents: 8063
diff changeset
940 while(*q && *q != '\"' && *q != '\'' && *q != ' ') {
9b6bc1010054 [gaim-migrate @ 8757]
Nathan Walp <nwalp@pidgin.im>
parents: 8063
diff changeset
941 color = g_string_append_c(color, *q);
9b6bc1010054 [gaim-migrate @ 8757]
Nathan Walp <nwalp@pidgin.im>
parents: 8063
diff changeset
942 q++;
9b6bc1010054 [gaim-migrate @ 8757]
Nathan Walp <nwalp@pidgin.im>
parents: 8063
diff changeset
943 }
9b6bc1010054 [gaim-migrate @ 8757]
Nathan Walp <nwalp@pidgin.im>
parents: 8063
diff changeset
944 g_string_append_printf(style, "background: %s; ", color->str);
9b6bc1010054 [gaim-migrate @ 8757]
Nathan Walp <nwalp@pidgin.im>
parents: 8063
diff changeset
945 g_string_free(color, TRUE);
9b6bc1010054 [gaim-migrate @ 8757]
Nathan Walp <nwalp@pidgin.im>
parents: 8063
diff changeset
946 p = q;
9b6bc1010054 [gaim-migrate @ 8757]
Nathan Walp <nwalp@pidgin.im>
parents: 8063
diff changeset
947 } else if(!g_ascii_strncasecmp(p, "color=", strlen("color="))) {
7095
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
948 const char *q = p + strlen("color=");
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
949 GString *color = g_string_new("");
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
950 if(*q == '\'' || *q == '\"')
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
951 q++;
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
952 while(*q && *q != '\"' && *q != '\'' && *q != ' ') {
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
953 color = g_string_append_c(color, *q);
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
954 q++;
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
955 }
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
956 g_string_append_printf(style, "color: %s; ", color->str);
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
957 g_string_free(color, TRUE);
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
958 p = q;
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
959 } else if(!g_ascii_strncasecmp(p, "face=", strlen("face="))) {
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
960 const char *q = p + strlen("face=");
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
961 gboolean space_allowed = FALSE;
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
962 GString *face = g_string_new("");
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
963 if(*q == '\'' || *q == '\"') {
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
964 space_allowed = TRUE;
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
965 q++;
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
966 }
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
967 while(*q && *q != '\"' && *q != '\'' && (space_allowed || *q != ' ')) {
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
968 face = g_string_append_c(face, *q);
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
969 q++;
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
970 }
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
971 g_string_append_printf(style, "font-family: %s; ", face->str);
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
972 g_string_free(face, TRUE);
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
973 p = q;
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
974 } else if(!g_ascii_strncasecmp(p, "size=", strlen("size="))) {
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
975 const char *q = p + strlen("size=");
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
976 int sz;
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
977 const char *size = "medium";
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
978 if(*q == '\'' || *q == '\"')
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
979 q++;
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
980 sz = atoi(q);
8686
140b0d020c43 [gaim-migrate @ 9439]
Luke Schierer <lschiere@pidgin.im>
parents: 8625
diff changeset
981 switch (sz)
140b0d020c43 [gaim-migrate @ 9439]
Luke Schierer <lschiere@pidgin.im>
parents: 8625
diff changeset
982 {
140b0d020c43 [gaim-migrate @ 9439]
Luke Schierer <lschiere@pidgin.im>
parents: 8625
diff changeset
983 case 1:
140b0d020c43 [gaim-migrate @ 9439]
Luke Schierer <lschiere@pidgin.im>
parents: 8625
diff changeset
984 size = "xx-small";
140b0d020c43 [gaim-migrate @ 9439]
Luke Schierer <lschiere@pidgin.im>
parents: 8625
diff changeset
985 break;
140b0d020c43 [gaim-migrate @ 9439]
Luke Schierer <lschiere@pidgin.im>
parents: 8625
diff changeset
986 case 2:
140b0d020c43 [gaim-migrate @ 9439]
Luke Schierer <lschiere@pidgin.im>
parents: 8625
diff changeset
987 size = "x-small";
140b0d020c43 [gaim-migrate @ 9439]
Luke Schierer <lschiere@pidgin.im>
parents: 8625
diff changeset
988 break;
140b0d020c43 [gaim-migrate @ 9439]
Luke Schierer <lschiere@pidgin.im>
parents: 8625
diff changeset
989 case 3:
140b0d020c43 [gaim-migrate @ 9439]
Luke Schierer <lschiere@pidgin.im>
parents: 8625
diff changeset
990 size = "small";
140b0d020c43 [gaim-migrate @ 9439]
Luke Schierer <lschiere@pidgin.im>
parents: 8625
diff changeset
991 break;
140b0d020c43 [gaim-migrate @ 9439]
Luke Schierer <lschiere@pidgin.im>
parents: 8625
diff changeset
992 case 4:
140b0d020c43 [gaim-migrate @ 9439]
Luke Schierer <lschiere@pidgin.im>
parents: 8625
diff changeset
993 size = "medium";
140b0d020c43 [gaim-migrate @ 9439]
Luke Schierer <lschiere@pidgin.im>
parents: 8625
diff changeset
994 break;
140b0d020c43 [gaim-migrate @ 9439]
Luke Schierer <lschiere@pidgin.im>
parents: 8625
diff changeset
995 case 5:
140b0d020c43 [gaim-migrate @ 9439]
Luke Schierer <lschiere@pidgin.im>
parents: 8625
diff changeset
996 size = "large";
140b0d020c43 [gaim-migrate @ 9439]
Luke Schierer <lschiere@pidgin.im>
parents: 8625
diff changeset
997 break;
140b0d020c43 [gaim-migrate @ 9439]
Luke Schierer <lschiere@pidgin.im>
parents: 8625
diff changeset
998 case 6:
140b0d020c43 [gaim-migrate @ 9439]
Luke Schierer <lschiere@pidgin.im>
parents: 8625
diff changeset
999 size = "x-large";
140b0d020c43 [gaim-migrate @ 9439]
Luke Schierer <lschiere@pidgin.im>
parents: 8625
diff changeset
1000 break;
140b0d020c43 [gaim-migrate @ 9439]
Luke Schierer <lschiere@pidgin.im>
parents: 8625
diff changeset
1001 case 7:
140b0d020c43 [gaim-migrate @ 9439]
Luke Schierer <lschiere@pidgin.im>
parents: 8625
diff changeset
1002 size = "xx-large";
140b0d020c43 [gaim-migrate @ 9439]
Luke Schierer <lschiere@pidgin.im>
parents: 8625
diff changeset
1003 break;
140b0d020c43 [gaim-migrate @ 9439]
Luke Schierer <lschiere@pidgin.im>
parents: 8625
diff changeset
1004 default:
140b0d020c43 [gaim-migrate @ 9439]
Luke Schierer <lschiere@pidgin.im>
parents: 8625
diff changeset
1005 break;
140b0d020c43 [gaim-migrate @ 9439]
Luke Schierer <lschiere@pidgin.im>
parents: 8625
diff changeset
1006 }
7095
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
1007 g_string_append_printf(style, "font-size: %s; ", size);
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
1008 p = q;
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
1009 }
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
1010 p++;
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
1011 }
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
1012 c = strchr(c, '>') + 1;
8064
9b6bc1010054 [gaim-migrate @ 8757]
Nathan Walp <nwalp@pidgin.im>
parents: 8063
diff changeset
1013 pt = g_new0(struct gaim_parse_tag, 1);
9b6bc1010054 [gaim-migrate @ 8757]
Nathan Walp <nwalp@pidgin.im>
parents: 8063
diff changeset
1014 pt->src_tag = "font";
9b6bc1010054 [gaim-migrate @ 8757]
Nathan Walp <nwalp@pidgin.im>
parents: 8063
diff changeset
1015 pt->dest_tag = "span";
9b6bc1010054 [gaim-migrate @ 8757]
Nathan Walp <nwalp@pidgin.im>
parents: 8063
diff changeset
1016 tags = g_list_prepend(tags, pt);
9b6bc1010054 [gaim-migrate @ 8757]
Nathan Walp <nwalp@pidgin.im>
parents: 8063
diff changeset
1017 if(style->len)
8026
17b90334f3cc [gaim-migrate @ 8706]
Nathan Walp <nwalp@pidgin.im>
parents: 8005
diff changeset
1018 g_string_append_printf(xhtml, "<span style='%s'>", style->str);
8064
9b6bc1010054 [gaim-migrate @ 8757]
Nathan Walp <nwalp@pidgin.im>
parents: 8063
diff changeset
1019 else
9b6bc1010054 [gaim-migrate @ 8757]
Nathan Walp <nwalp@pidgin.im>
parents: 8063
diff changeset
1020 pt->ignore = TRUE;
7095
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
1021 g_string_free(style, TRUE);
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
1022 continue;
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
1023 }
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
1024 if(!g_ascii_strncasecmp(c, "<body ", 6)) {
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
1025 const char *p = c;
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
1026 gboolean did_something = FALSE;
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
1027 while(*p && *p != '>') {
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
1028 if(!g_ascii_strncasecmp(p, "bgcolor=", strlen("bgcolor="))) {
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
1029 const char *q = p + strlen("bgcolor=");
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
1030 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
1031 GString *color = g_string_new("");
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
1032 if(*q == '\'' || *q == '\"')
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
1033 q++;
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
1034 while(*q && *q != '\"' && *q != '\'' && *q != ' ') {
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
1035 color = g_string_append_c(color, *q);
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
1036 q++;
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
1037 }
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
1038 g_string_append_printf(xhtml, "<span style='background: %s;'>", color->str);
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
1039 g_string_free(color, TRUE);
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
1040 c = strchr(c, '>') + 1;
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
1041 pt->src_tag = "body";
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
1042 pt->dest_tag = "span";
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
1043 tags = g_list_prepend(tags, pt);
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
1044 did_something = TRUE;
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
1045 break;
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
1046 }
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
1047 p++;
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
1048 }
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
1049 if(did_something) continue;
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
1050 }
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
1051 /* this has to come after the special case for bgcolor */
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
1052 ALLOW_TAG("body");
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
1053 if(!g_ascii_strncasecmp(c, "<!--", strlen("<!--"))) {
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
1054 char *p = strstr(c + strlen("<!--"), "-->");
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
1055 if(p) {
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
1056 xhtml = g_string_append(xhtml, "<!--");
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
1057 c += strlen("<!--");
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
1058 continue;
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
1059 }
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
1060 }
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
1061
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
1062 xhtml = g_string_append(xhtml, "&lt;");
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
1063 plain = g_string_append_c(plain, '<');
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
1064 c++;
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
1065 }
7287
3a41c3f80228 [gaim-migrate @ 7868]
Nathan Walp <nwalp@pidgin.im>
parents: 7265
diff changeset
1066 } else if(*c == '&') {
3a41c3f80228 [gaim-migrate @ 7868]
Nathan Walp <nwalp@pidgin.im>
parents: 7265
diff changeset
1067 char buf[7];
3a41c3f80228 [gaim-migrate @ 7868]
Nathan Walp <nwalp@pidgin.im>
parents: 7265
diff changeset
1068 char *pln;
3a41c3f80228 [gaim-migrate @ 7868]
Nathan Walp <nwalp@pidgin.im>
parents: 7265
diff changeset
1069 int len = 1;
3a41c3f80228 [gaim-migrate @ 7868]
Nathan Walp <nwalp@pidgin.im>
parents: 7265
diff changeset
1070 guint pound;
3a41c3f80228 [gaim-migrate @ 7868]
Nathan Walp <nwalp@pidgin.im>
parents: 7265
diff changeset
1071 if(!g_ascii_strncasecmp(c, "&amp;", 5)) {
3a41c3f80228 [gaim-migrate @ 7868]
Nathan Walp <nwalp@pidgin.im>
parents: 7265
diff changeset
1072 pln = "&";
3a41c3f80228 [gaim-migrate @ 7868]
Nathan Walp <nwalp@pidgin.im>
parents: 7265
diff changeset
1073 len = 5;
3a41c3f80228 [gaim-migrate @ 7868]
Nathan Walp <nwalp@pidgin.im>
parents: 7265
diff changeset
1074 } else if(!g_ascii_strncasecmp(c, "&lt;", 4)) {
3a41c3f80228 [gaim-migrate @ 7868]
Nathan Walp <nwalp@pidgin.im>
parents: 7265
diff changeset
1075 pln = "<";
3a41c3f80228 [gaim-migrate @ 7868]
Nathan Walp <nwalp@pidgin.im>
parents: 7265
diff changeset
1076 len = 4;
3a41c3f80228 [gaim-migrate @ 7868]
Nathan Walp <nwalp@pidgin.im>
parents: 7265
diff changeset
1077 } else if(!g_ascii_strncasecmp(c, "&gt;", 4)) {
3a41c3f80228 [gaim-migrate @ 7868]
Nathan Walp <nwalp@pidgin.im>
parents: 7265
diff changeset
1078 pln = ">";
3a41c3f80228 [gaim-migrate @ 7868]
Nathan Walp <nwalp@pidgin.im>
parents: 7265
diff changeset
1079 len = 4;
3a41c3f80228 [gaim-migrate @ 7868]
Nathan Walp <nwalp@pidgin.im>
parents: 7265
diff changeset
1080 } else if(!g_ascii_strncasecmp(c, "&nbsp;", 6)) {
3a41c3f80228 [gaim-migrate @ 7868]
Nathan Walp <nwalp@pidgin.im>
parents: 7265
diff changeset
1081 pln = " ";
3a41c3f80228 [gaim-migrate @ 7868]
Nathan Walp <nwalp@pidgin.im>
parents: 7265
diff changeset
1082 len = 6;
3a41c3f80228 [gaim-migrate @ 7868]
Nathan Walp <nwalp@pidgin.im>
parents: 7265
diff changeset
1083 } else if(!g_ascii_strncasecmp(c, "&copy;", 6)) {
3a41c3f80228 [gaim-migrate @ 7868]
Nathan Walp <nwalp@pidgin.im>
parents: 7265
diff changeset
1084 pln = "©";
3a41c3f80228 [gaim-migrate @ 7868]
Nathan Walp <nwalp@pidgin.im>
parents: 7265
diff changeset
1085 len = 6;
3a41c3f80228 [gaim-migrate @ 7868]
Nathan Walp <nwalp@pidgin.im>
parents: 7265
diff changeset
1086 } else if(!g_ascii_strncasecmp(c, "&quot;", 6)) {
3a41c3f80228 [gaim-migrate @ 7868]
Nathan Walp <nwalp@pidgin.im>
parents: 7265
diff changeset
1087 pln = "\"";
3a41c3f80228 [gaim-migrate @ 7868]
Nathan Walp <nwalp@pidgin.im>
parents: 7265
diff changeset
1088 len = 6;
3a41c3f80228 [gaim-migrate @ 7868]
Nathan Walp <nwalp@pidgin.im>
parents: 7265
diff changeset
1089 } else if(!g_ascii_strncasecmp(c, "&reg;", 5)) {
3a41c3f80228 [gaim-migrate @ 7868]
Nathan Walp <nwalp@pidgin.im>
parents: 7265
diff changeset
1090 pln = "®";
3a41c3f80228 [gaim-migrate @ 7868]
Nathan Walp <nwalp@pidgin.im>
parents: 7265
diff changeset
1091 len = 5;
3a41c3f80228 [gaim-migrate @ 7868]
Nathan Walp <nwalp@pidgin.im>
parents: 7265
diff changeset
1092 } else if(!g_ascii_strncasecmp(c, "&apos;", 6)) {
3a41c3f80228 [gaim-migrate @ 7868]
Nathan Walp <nwalp@pidgin.im>
parents: 7265
diff changeset
1093 pln = "\'";
3a41c3f80228 [gaim-migrate @ 7868]
Nathan Walp <nwalp@pidgin.im>
parents: 7265
diff changeset
1094 len = 6;
3a41c3f80228 [gaim-migrate @ 7868]
Nathan Walp <nwalp@pidgin.im>
parents: 7265
diff changeset
1095 } else if(*(c+1) == '#' && (sscanf(c, "&#%u;", &pound) == 1) &&
3a41c3f80228 [gaim-migrate @ 7868]
Nathan Walp <nwalp@pidgin.im>
parents: 7265
diff changeset
1096 pound != 0 && *(c+3+(gint)log10(pound)) == ';') {
3a41c3f80228 [gaim-migrate @ 7868]
Nathan Walp <nwalp@pidgin.im>
parents: 7265
diff changeset
1097 int buflen = g_unichar_to_utf8((gunichar)pound, buf);
3a41c3f80228 [gaim-migrate @ 7868]
Nathan Walp <nwalp@pidgin.im>
parents: 7265
diff changeset
1098 buf[buflen] = '\0';
3a41c3f80228 [gaim-migrate @ 7868]
Nathan Walp <nwalp@pidgin.im>
parents: 7265
diff changeset
1099 pln = buf;
3a41c3f80228 [gaim-migrate @ 7868]
Nathan Walp <nwalp@pidgin.im>
parents: 7265
diff changeset
1100
3a41c3f80228 [gaim-migrate @ 7868]
Nathan Walp <nwalp@pidgin.im>
parents: 7265
diff changeset
1101
3a41c3f80228 [gaim-migrate @ 7868]
Nathan Walp <nwalp@pidgin.im>
parents: 7265
diff changeset
1102 len = 2;
3a41c3f80228 [gaim-migrate @ 7868]
Nathan Walp <nwalp@pidgin.im>
parents: 7265
diff changeset
1103 while(isdigit((gint) c [len])) len++;
3a41c3f80228 [gaim-migrate @ 7868]
Nathan Walp <nwalp@pidgin.im>
parents: 7265
diff changeset
1104 if(c [len] == ';') len++;
3a41c3f80228 [gaim-migrate @ 7868]
Nathan Walp <nwalp@pidgin.im>
parents: 7265
diff changeset
1105 } else {
3a41c3f80228 [gaim-migrate @ 7868]
Nathan Walp <nwalp@pidgin.im>
parents: 7265
diff changeset
1106 len = 1;
3a41c3f80228 [gaim-migrate @ 7868]
Nathan Walp <nwalp@pidgin.im>
parents: 7265
diff changeset
1107 g_snprintf(buf, sizeof(buf), "%c", *c);
3a41c3f80228 [gaim-migrate @ 7868]
Nathan Walp <nwalp@pidgin.im>
parents: 7265
diff changeset
1108 pln = buf;
3a41c3f80228 [gaim-migrate @ 7868]
Nathan Walp <nwalp@pidgin.im>
parents: 7265
diff changeset
1109 }
3a41c3f80228 [gaim-migrate @ 7868]
Nathan Walp <nwalp@pidgin.im>
parents: 7265
diff changeset
1110 xhtml = g_string_append_len(xhtml, c, len);
3a41c3f80228 [gaim-migrate @ 7868]
Nathan Walp <nwalp@pidgin.im>
parents: 7265
diff changeset
1111 plain = g_string_append(plain, pln);
3a41c3f80228 [gaim-migrate @ 7868]
Nathan Walp <nwalp@pidgin.im>
parents: 7265
diff changeset
1112 c += len;
7095
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
1113 } else {
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
1114 xhtml = g_string_append_c(xhtml, *c);
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
1115 plain = g_string_append_c(plain, *c);
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
1116 c++;
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
1117 }
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
1118 }
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
1119 tag = tags;
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
1120 while(tag) {
8064
9b6bc1010054 [gaim-migrate @ 8757]
Nathan Walp <nwalp@pidgin.im>
parents: 8063
diff changeset
1121 struct gaim_parse_tag *pt = tag->data;
9b6bc1010054 [gaim-migrate @ 8757]
Nathan Walp <nwalp@pidgin.im>
parents: 8063
diff changeset
1122 if(!pt->ignore)
9b6bc1010054 [gaim-migrate @ 8757]
Nathan Walp <nwalp@pidgin.im>
parents: 8063
diff changeset
1123 g_string_append_printf(xhtml, "</%s>", pt->dest_tag);
7095
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
1124 tag = tag->next;
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
1125 }
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
1126 g_list_free(tags);
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
1127 if(xhtml_out)
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
1128 *xhtml_out = g_strdup(xhtml->str);
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
1129 if(plain_out)
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
1130 *plain_out = g_strdup(plain->str);
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
1131 g_string_free(xhtml, TRUE);
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
1132 g_string_free(plain, TRUE);
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
1133 }
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
1134
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
1135 char *
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
1136 gaim_markup_strip_html(const char *str)
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
1137 {
7103
5dc4ed905a1a [gaim-migrate @ 7668]
Nathan Walp <nwalp@pidgin.im>
parents: 7099
diff changeset
1138 int i, j, k;
5dc4ed905a1a [gaim-migrate @ 7668]
Nathan Walp <nwalp@pidgin.im>
parents: 7099
diff changeset
1139 gboolean visible = TRUE;
5dc4ed905a1a [gaim-migrate @ 7668]
Nathan Walp <nwalp@pidgin.im>
parents: 7099
diff changeset
1140 gchar *str2;
5dc4ed905a1a [gaim-migrate @ 7668]
Nathan Walp <nwalp@pidgin.im>
parents: 7099
diff changeset
1141
7110
b003397b16fe [gaim-migrate @ 7676]
Nathan Walp <nwalp@pidgin.im>
parents: 7108
diff changeset
1142 if(!str)
b003397b16fe [gaim-migrate @ 7676]
Nathan Walp <nwalp@pidgin.im>
parents: 7108
diff changeset
1143 return NULL;
7103
5dc4ed905a1a [gaim-migrate @ 7668]
Nathan Walp <nwalp@pidgin.im>
parents: 7099
diff changeset
1144
5dc4ed905a1a [gaim-migrate @ 7668]
Nathan Walp <nwalp@pidgin.im>
parents: 7099
diff changeset
1145 str2 = g_strdup(str);
5dc4ed905a1a [gaim-migrate @ 7668]
Nathan Walp <nwalp@pidgin.im>
parents: 7099
diff changeset
1146
5dc4ed905a1a [gaim-migrate @ 7668]
Nathan Walp <nwalp@pidgin.im>
parents: 7099
diff changeset
1147 for (i = 0, j = 0; str2[i]; i++)
5dc4ed905a1a [gaim-migrate @ 7668]
Nathan Walp <nwalp@pidgin.im>
parents: 7099
diff changeset
1148 {
5dc4ed905a1a [gaim-migrate @ 7668]
Nathan Walp <nwalp@pidgin.im>
parents: 7099
diff changeset
1149 if (str2[i] == '<')
5dc4ed905a1a [gaim-migrate @ 7668]
Nathan Walp <nwalp@pidgin.im>
parents: 7099
diff changeset
1150 {
8517
5cb93726e4d5 [gaim-migrate @ 9256]
Luke Schierer <lschiere@pidgin.im>
parents: 8511
diff changeset
1151 if (strncasecmp(str2 + i, "<br>", 4) == 0)
5cb93726e4d5 [gaim-migrate @ 9256]
Luke Schierer <lschiere@pidgin.im>
parents: 8511
diff changeset
1152 {
5cb93726e4d5 [gaim-migrate @ 9256]
Luke Schierer <lschiere@pidgin.im>
parents: 8511
diff changeset
1153 str2[j++] = '\n';
5cb93726e4d5 [gaim-migrate @ 9256]
Luke Schierer <lschiere@pidgin.im>
parents: 8511
diff changeset
1154 i = i + 3;
5cb93726e4d5 [gaim-migrate @ 9256]
Luke Schierer <lschiere@pidgin.im>
parents: 8511
diff changeset
1155 continue;
5cb93726e4d5 [gaim-migrate @ 9256]
Luke Schierer <lschiere@pidgin.im>
parents: 8511
diff changeset
1156 }
5cb93726e4d5 [gaim-migrate @ 9256]
Luke Schierer <lschiere@pidgin.im>
parents: 8511
diff changeset
1157
7103
5dc4ed905a1a [gaim-migrate @ 7668]
Nathan Walp <nwalp@pidgin.im>
parents: 7099
diff changeset
1158 k = i + 1;
5dc4ed905a1a [gaim-migrate @ 7668]
Nathan Walp <nwalp@pidgin.im>
parents: 7099
diff changeset
1159
5dc4ed905a1a [gaim-migrate @ 7668]
Nathan Walp <nwalp@pidgin.im>
parents: 7099
diff changeset
1160 if(g_ascii_isspace(str2[k]))
5dc4ed905a1a [gaim-migrate @ 7668]
Nathan Walp <nwalp@pidgin.im>
parents: 7099
diff changeset
1161 visible = TRUE;
5dc4ed905a1a [gaim-migrate @ 7668]
Nathan Walp <nwalp@pidgin.im>
parents: 7099
diff changeset
1162 else
5dc4ed905a1a [gaim-migrate @ 7668]
Nathan Walp <nwalp@pidgin.im>
parents: 7099
diff changeset
1163 {
5dc4ed905a1a [gaim-migrate @ 7668]
Nathan Walp <nwalp@pidgin.im>
parents: 7099
diff changeset
1164 while (str2[k])
5dc4ed905a1a [gaim-migrate @ 7668]
Nathan Walp <nwalp@pidgin.im>
parents: 7099
diff changeset
1165 {
5dc4ed905a1a [gaim-migrate @ 7668]
Nathan Walp <nwalp@pidgin.im>
parents: 7099
diff changeset
1166 if (str2[k] == '<')
5dc4ed905a1a [gaim-migrate @ 7668]
Nathan Walp <nwalp@pidgin.im>
parents: 7099
diff changeset
1167 {
5dc4ed905a1a [gaim-migrate @ 7668]
Nathan Walp <nwalp@pidgin.im>
parents: 7099
diff changeset
1168 visible = TRUE;
5dc4ed905a1a [gaim-migrate @ 7668]
Nathan Walp <nwalp@pidgin.im>
parents: 7099
diff changeset
1169 break;
5dc4ed905a1a [gaim-migrate @ 7668]
Nathan Walp <nwalp@pidgin.im>
parents: 7099
diff changeset
1170 }
7095
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
1171
7103
5dc4ed905a1a [gaim-migrate @ 7668]
Nathan Walp <nwalp@pidgin.im>
parents: 7099
diff changeset
1172 if (str2[k] == '>')
5dc4ed905a1a [gaim-migrate @ 7668]
Nathan Walp <nwalp@pidgin.im>
parents: 7099
diff changeset
1173 {
5dc4ed905a1a [gaim-migrate @ 7668]
Nathan Walp <nwalp@pidgin.im>
parents: 7099
diff changeset
1174 visible = FALSE;
5dc4ed905a1a [gaim-migrate @ 7668]
Nathan Walp <nwalp@pidgin.im>
parents: 7099
diff changeset
1175 break;
5dc4ed905a1a [gaim-migrate @ 7668]
Nathan Walp <nwalp@pidgin.im>
parents: 7099
diff changeset
1176 }
7095
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
1177
7103
5dc4ed905a1a [gaim-migrate @ 7668]
Nathan Walp <nwalp@pidgin.im>
parents: 7099
diff changeset
1178 k++;
5dc4ed905a1a [gaim-migrate @ 7668]
Nathan Walp <nwalp@pidgin.im>
parents: 7099
diff changeset
1179 }
5dc4ed905a1a [gaim-migrate @ 7668]
Nathan Walp <nwalp@pidgin.im>
parents: 7099
diff changeset
1180 }
5dc4ed905a1a [gaim-migrate @ 7668]
Nathan Walp <nwalp@pidgin.im>
parents: 7099
diff changeset
1181 }
5dc4ed905a1a [gaim-migrate @ 7668]
Nathan Walp <nwalp@pidgin.im>
parents: 7099
diff changeset
1182 else if (str2[i] == '>' && !visible)
5dc4ed905a1a [gaim-migrate @ 7668]
Nathan Walp <nwalp@pidgin.im>
parents: 7099
diff changeset
1183 {
5dc4ed905a1a [gaim-migrate @ 7668]
Nathan Walp <nwalp@pidgin.im>
parents: 7099
diff changeset
1184 visible = TRUE;
5dc4ed905a1a [gaim-migrate @ 7668]
Nathan Walp <nwalp@pidgin.im>
parents: 7099
diff changeset
1185 continue;
5dc4ed905a1a [gaim-migrate @ 7668]
Nathan Walp <nwalp@pidgin.im>
parents: 7099
diff changeset
1186 }
5dc4ed905a1a [gaim-migrate @ 7668]
Nathan Walp <nwalp@pidgin.im>
parents: 7099
diff changeset
1187
5dc4ed905a1a [gaim-migrate @ 7668]
Nathan Walp <nwalp@pidgin.im>
parents: 7099
diff changeset
1188 if (str2[i] == '&' && strncasecmp(str2 + i, "&quot;", 6) == 0)
5dc4ed905a1a [gaim-migrate @ 7668]
Nathan Walp <nwalp@pidgin.im>
parents: 7099
diff changeset
1189 {
5dc4ed905a1a [gaim-migrate @ 7668]
Nathan Walp <nwalp@pidgin.im>
parents: 7099
diff changeset
1190 str2[j++] = '\"';
5dc4ed905a1a [gaim-migrate @ 7668]
Nathan Walp <nwalp@pidgin.im>
parents: 7099
diff changeset
1191 i = i + 5;
5dc4ed905a1a [gaim-migrate @ 7668]
Nathan Walp <nwalp@pidgin.im>
parents: 7099
diff changeset
1192 continue;
5dc4ed905a1a [gaim-migrate @ 7668]
Nathan Walp <nwalp@pidgin.im>
parents: 7099
diff changeset
1193 }
5dc4ed905a1a [gaim-migrate @ 7668]
Nathan Walp <nwalp@pidgin.im>
parents: 7099
diff changeset
1194
8517
5cb93726e4d5 [gaim-migrate @ 9256]
Luke Schierer <lschiere@pidgin.im>
parents: 8511
diff changeset
1195 if (str2[i] == '&' && strncasecmp(str2 + i, "&amp;", 5) == 0)
5cb93726e4d5 [gaim-migrate @ 9256]
Luke Schierer <lschiere@pidgin.im>
parents: 8511
diff changeset
1196 {
5cb93726e4d5 [gaim-migrate @ 9256]
Luke Schierer <lschiere@pidgin.im>
parents: 8511
diff changeset
1197 str2[j++] = '&';
5cb93726e4d5 [gaim-migrate @ 9256]
Luke Schierer <lschiere@pidgin.im>
parents: 8511
diff changeset
1198 i = i + 4;
5cb93726e4d5 [gaim-migrate @ 9256]
Luke Schierer <lschiere@pidgin.im>
parents: 8511
diff changeset
1199 continue;
5cb93726e4d5 [gaim-migrate @ 9256]
Luke Schierer <lschiere@pidgin.im>
parents: 8511
diff changeset
1200 }
5cb93726e4d5 [gaim-migrate @ 9256]
Luke Schierer <lschiere@pidgin.im>
parents: 8511
diff changeset
1201
5cb93726e4d5 [gaim-migrate @ 9256]
Luke Schierer <lschiere@pidgin.im>
parents: 8511
diff changeset
1202 if (str2[i] == '&' && strncasecmp(str2 + i, "&lt;", 4) == 0)
5cb93726e4d5 [gaim-migrate @ 9256]
Luke Schierer <lschiere@pidgin.im>
parents: 8511
diff changeset
1203 {
5cb93726e4d5 [gaim-migrate @ 9256]
Luke Schierer <lschiere@pidgin.im>
parents: 8511
diff changeset
1204 str2[j++] = '<';
5cb93726e4d5 [gaim-migrate @ 9256]
Luke Schierer <lschiere@pidgin.im>
parents: 8511
diff changeset
1205 i = i + 3;
5cb93726e4d5 [gaim-migrate @ 9256]
Luke Schierer <lschiere@pidgin.im>
parents: 8511
diff changeset
1206 continue;
5cb93726e4d5 [gaim-migrate @ 9256]
Luke Schierer <lschiere@pidgin.im>
parents: 8511
diff changeset
1207 }
5cb93726e4d5 [gaim-migrate @ 9256]
Luke Schierer <lschiere@pidgin.im>
parents: 8511
diff changeset
1208
5cb93726e4d5 [gaim-migrate @ 9256]
Luke Schierer <lschiere@pidgin.im>
parents: 8511
diff changeset
1209 if (str2[i] == '&' && strncasecmp(str2 + i, "&gt;", 4) == 0)
5cb93726e4d5 [gaim-migrate @ 9256]
Luke Schierer <lschiere@pidgin.im>
parents: 8511
diff changeset
1210 {
5cb93726e4d5 [gaim-migrate @ 9256]
Luke Schierer <lschiere@pidgin.im>
parents: 8511
diff changeset
1211 str2[j++] = '>';
5cb93726e4d5 [gaim-migrate @ 9256]
Luke Schierer <lschiere@pidgin.im>
parents: 8511
diff changeset
1212 i = i + 3;
5cb93726e4d5 [gaim-migrate @ 9256]
Luke Schierer <lschiere@pidgin.im>
parents: 8511
diff changeset
1213 continue;
5cb93726e4d5 [gaim-migrate @ 9256]
Luke Schierer <lschiere@pidgin.im>
parents: 8511
diff changeset
1214 }
5cb93726e4d5 [gaim-migrate @ 9256]
Luke Schierer <lschiere@pidgin.im>
parents: 8511
diff changeset
1215
7103
5dc4ed905a1a [gaim-migrate @ 7668]
Nathan Walp <nwalp@pidgin.im>
parents: 7099
diff changeset
1216 if (visible)
5dc4ed905a1a [gaim-migrate @ 7668]
Nathan Walp <nwalp@pidgin.im>
parents: 7099
diff changeset
1217 str2[j++] = str2[i];
5dc4ed905a1a [gaim-migrate @ 7668]
Nathan Walp <nwalp@pidgin.im>
parents: 7099
diff changeset
1218 }
5dc4ed905a1a [gaim-migrate @ 7668]
Nathan Walp <nwalp@pidgin.im>
parents: 7099
diff changeset
1219
5dc4ed905a1a [gaim-migrate @ 7668]
Nathan Walp <nwalp@pidgin.im>
parents: 7099
diff changeset
1220 str2[j] = '\0';
5dc4ed905a1a [gaim-migrate @ 7668]
Nathan Walp <nwalp@pidgin.im>
parents: 7099
diff changeset
1221
5dc4ed905a1a [gaim-migrate @ 7668]
Nathan Walp <nwalp@pidgin.im>
parents: 7099
diff changeset
1222 return str2;
7095
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
1223 }
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
1224
7108
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1225 static gint
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1226 badchar(char c)
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1227 {
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1228 switch (c) {
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1229 case ' ':
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1230 case ',':
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1231 case '(':
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1232 case ')':
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1233 case '\0':
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1234 case '\n':
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1235 case '<':
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1236 case '>':
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1237 case '"':
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1238 case '\'':
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1239 return 1;
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1240 default:
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1241 return 0;
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1242 }
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1243 }
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1244
7107
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1245 char *
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1246 gaim_markup_linkify(const char *text)
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1247 {
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1248 const char *c, *t, *q = NULL;
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1249 char *tmp;
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1250 char url_buf[BUF_LEN * 4];
8538
848dfa9fe9d4 [gaim-migrate @ 9279]
Nathan Walp <nwalp@pidgin.im>
parents: 8534
diff changeset
1251 gboolean inside_html = FALSE;
7107
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1252 GString *ret = g_string_new("");
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1253 /* Assumes you have a buffer able to cary at least BUF_LEN * 2 bytes */
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1254
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1255 c = text;
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1256 while (*c) {
8538
848dfa9fe9d4 [gaim-migrate @ 9279]
Nathan Walp <nwalp@pidgin.im>
parents: 8534
diff changeset
1257 if(inside_html) {
848dfa9fe9d4 [gaim-migrate @ 9279]
Nathan Walp <nwalp@pidgin.im>
parents: 8534
diff changeset
1258 if(*c == '>') {
848dfa9fe9d4 [gaim-migrate @ 9279]
Nathan Walp <nwalp@pidgin.im>
parents: 8534
diff changeset
1259 inside_html = FALSE;
848dfa9fe9d4 [gaim-migrate @ 9279]
Nathan Walp <nwalp@pidgin.im>
parents: 8534
diff changeset
1260 } else if(!q && (*c == '\"' || *c == '\'')) {
848dfa9fe9d4 [gaim-migrate @ 9279]
Nathan Walp <nwalp@pidgin.im>
parents: 8534
diff changeset
1261 q = c;
848dfa9fe9d4 [gaim-migrate @ 9279]
Nathan Walp <nwalp@pidgin.im>
parents: 8534
diff changeset
1262 } else if(q) {
848dfa9fe9d4 [gaim-migrate @ 9279]
Nathan Walp <nwalp@pidgin.im>
parents: 8534
diff changeset
1263 if(*c == *q)
848dfa9fe9d4 [gaim-migrate @ 9279]
Nathan Walp <nwalp@pidgin.im>
parents: 8534
diff changeset
1264 q = NULL;
848dfa9fe9d4 [gaim-migrate @ 9279]
Nathan Walp <nwalp@pidgin.im>
parents: 8534
diff changeset
1265 }
848dfa9fe9d4 [gaim-migrate @ 9279]
Nathan Walp <nwalp@pidgin.im>
parents: 8534
diff changeset
1266 } else if(*c == '<') {
848dfa9fe9d4 [gaim-migrate @ 9279]
Nathan Walp <nwalp@pidgin.im>
parents: 8534
diff changeset
1267 inside_html = TRUE;
7107
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1268 } else if (!g_ascii_strncasecmp(c, "<A", 2)) {
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1269 while (1) {
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1270 if (!g_ascii_strncasecmp(c, "/A>", 3)) {
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1271 break;
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1272 }
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1273 ret = g_string_append_c(ret, *c);
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1274 c++;
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1275 if (!(*c))
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1276 break;
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1277 }
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1278 } else if ((*c=='h') && (!g_ascii_strncasecmp(c, "http://", 7) ||
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1279 (!g_ascii_strncasecmp(c, "https://", 8)))) {
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1280 t = c;
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1281 while (1) {
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1282 if (badchar(*t)) {
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1283
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1284 if (*(t) == ',' && (*(t + 1) != ' ')) {
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1285 t++;
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1286 continue;
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1287 }
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1288
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1289 if (*(t - 1) == '.')
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1290 t--;
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1291 strncpy(url_buf, c, t - c);
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1292 url_buf[t - c] = 0;
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1293 g_string_append_printf(ret, "<A HREF=\"%s\">%s</A>",
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1294 url_buf, url_buf);
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1295 c = t;
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1296 break;
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1297 }
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1298 if (!t)
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1299 break;
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1300 t++;
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1301
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1302 }
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1303 } else if (!g_ascii_strncasecmp(c, "www.", 4)) {
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1304 if (c[4] != '.') {
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1305 t = c;
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1306 while (1) {
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1307 if (badchar(*t)) {
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1308 if (t - c == 4) {
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1309 break;
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1310 }
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1311
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1312 if (*(t) == ',' && (*(t + 1) != ' ')) {
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1313 t++;
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1314 continue;
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1315 }
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1316
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1317 if (*(t - 1) == '.')
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1318 t--;
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1319 strncpy(url_buf, c, t - c);
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1320 url_buf[t - c] = 0;
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1321 g_string_append_printf(ret,
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1322 "<A HREF=\"http://%s\">%s</A>", url_buf,
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1323 url_buf);
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1324 c = t;
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1325 break;
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1326 }
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1327 if (!t)
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1328 break;
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1329 t++;
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1330 }
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1331 }
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1332 } else if (!g_ascii_strncasecmp(c, "ftp://", 6)) {
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1333 t = c;
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1334 while (1) {
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1335 if (badchar(*t)) {
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1336 if (*(t - 1) == '.')
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1337 t--;
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1338 strncpy(url_buf, c, t - c);
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1339 url_buf[t - c] = 0;
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1340 g_string_append_printf(ret, "<A HREF=\"%s\">%s</A>",
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1341 url_buf, url_buf);
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1342 c = t;
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1343 break;
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1344 }
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1345 if (!t)
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1346 break;
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1347 t++;
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1348
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1349 }
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1350 } else if (!g_ascii_strncasecmp(c, "ftp.", 4)) {
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1351 if (c[4] != '.') {
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1352 t = c;
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1353 while (1) {
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1354 if (badchar(*t)) {
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1355 if (t - c == 4) {
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1356 break;
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1357 }
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1358 if (*(t - 1) == '.')
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1359 t--;
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1360 strncpy(url_buf, c, t - c);
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1361 url_buf[t - c] = 0;
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1362 g_string_append_printf(ret,
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1363 "<A HREF=\"ftp://%s\">%s</A>", url_buf,
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1364 url_buf);
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1365 c = t;
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1366 break;
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1367 }
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1368 if (!t)
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1369 break;
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1370 t++;
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1371 }
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1372 }
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1373 } else if (!g_ascii_strncasecmp(c, "mailto:", 7)) {
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1374 t = c;
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1375 while (1) {
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1376 if (badchar(*t)) {
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1377 if (*(t - 1) == '.')
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1378 t--;
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1379 strncpy(url_buf, c, t - c);
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1380 url_buf[t - c] = 0;
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1381 g_string_append_printf(ret, "<A HREF=\"%s\">%s</A>",
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1382 url_buf, url_buf);
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1383 c = t;
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1384 break;
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1385 }
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1386 if (!t)
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1387 break;
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1388 t++;
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1389
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1390 }
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1391 } else if (c != text && (*c == '@')) {
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1392 char *tmp;
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1393 int flag;
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1394 int len = 0;
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1395 const char illegal_chars[] = "!@#$%^&*()[]{}/|\\<>\":;\r\n \0";
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1396 url_buf[0] = 0;
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1397
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1398 if (strchr(illegal_chars,*(c - 1)) || strchr(illegal_chars, *(c + 1)))
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1399 flag = 0;
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1400 else
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1401 flag = 1;
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1402
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1403 t = c;
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1404 while (flag) {
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1405 if (badchar(*t)) {
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1406 ret = g_string_truncate(ret, ret->len - (len - 1));
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1407 break;
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1408 } else {
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1409 len++;
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1410 tmp = g_malloc(len + 1);
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1411 tmp[len] = 0;
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1412 tmp[0] = *t;
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1413 strncpy(tmp + 1, url_buf, len - 1);
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1414 strcpy(url_buf, tmp);
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1415 url_buf[len] = 0;
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1416 g_free(tmp);
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1417 t--;
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1418 if (t < text) {
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1419 ret = g_string_assign(ret, "");
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1420 break;
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1421 }
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1422 }
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1423 }
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1424
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1425 t = c + 1;
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1426
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1427 while (flag) {
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1428 if (badchar(*t)) {
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1429 char *d;
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1430
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1431 for (d = url_buf + strlen(url_buf) - 1; *d == '.'; d--, t--)
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1432 *d = '\0';
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1433
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1434 g_string_append_printf(ret, "<A HREF=\"mailto:%s\">%s</A>",
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1435 url_buf, url_buf);
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1436 c = t;
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1437
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1438 break;
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1439 } else {
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1440 strncat(url_buf, t, 1);
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1441 len++;
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1442 url_buf[len] = 0;
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1443 }
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1444
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1445 t++;
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1446 }
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1447 }
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1448
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1449 if (*c == 0)
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1450 break;
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1451
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1452 ret = g_string_append_c(ret, *c);
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1453 c++;
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1454
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1455 }
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1456 tmp = ret->str;
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1457 g_string_free(ret, FALSE);
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1458 return tmp;
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1459 }
9220c7490cd1 [gaim-migrate @ 7672]
Christian Hammond <chipx86@chipx86.com>
parents: 7106
diff changeset
1460
8163
da57fb60680a [gaim-migrate @ 8875]
Ethan Blanton <elb@pidgin.im>
parents: 8125
diff changeset
1461 char *
da57fb60680a [gaim-migrate @ 8875]
Ethan Blanton <elb@pidgin.im>
parents: 8125
diff changeset
1462 gaim_escape_html(const char *html) {
da57fb60680a [gaim-migrate @ 8875]
Ethan Blanton <elb@pidgin.im>
parents: 8125
diff changeset
1463 char *escaped = NULL;
da57fb60680a [gaim-migrate @ 8875]
Ethan Blanton <elb@pidgin.im>
parents: 8125
diff changeset
1464
da57fb60680a [gaim-migrate @ 8875]
Ethan Blanton <elb@pidgin.im>
parents: 8125
diff changeset
1465 if (html != NULL) {
da57fb60680a [gaim-migrate @ 8875]
Ethan Blanton <elb@pidgin.im>
parents: 8125
diff changeset
1466 const char *c = html;
da57fb60680a [gaim-migrate @ 8875]
Ethan Blanton <elb@pidgin.im>
parents: 8125
diff changeset
1467 GString *ret = g_string_new("");
da57fb60680a [gaim-migrate @ 8875]
Ethan Blanton <elb@pidgin.im>
parents: 8125
diff changeset
1468 while (*c) {
da57fb60680a [gaim-migrate @ 8875]
Ethan Blanton <elb@pidgin.im>
parents: 8125
diff changeset
1469 switch(*c) {
da57fb60680a [gaim-migrate @ 8875]
Ethan Blanton <elb@pidgin.im>
parents: 8125
diff changeset
1470 case '&':
da57fb60680a [gaim-migrate @ 8875]
Ethan Blanton <elb@pidgin.im>
parents: 8125
diff changeset
1471 ret = g_string_append(ret, "&amp;");
da57fb60680a [gaim-migrate @ 8875]
Ethan Blanton <elb@pidgin.im>
parents: 8125
diff changeset
1472 break;
da57fb60680a [gaim-migrate @ 8875]
Ethan Blanton <elb@pidgin.im>
parents: 8125
diff changeset
1473 case '<':
da57fb60680a [gaim-migrate @ 8875]
Ethan Blanton <elb@pidgin.im>
parents: 8125
diff changeset
1474 ret = g_string_append(ret, "&lt;");
da57fb60680a [gaim-migrate @ 8875]
Ethan Blanton <elb@pidgin.im>
parents: 8125
diff changeset
1475 break;
da57fb60680a [gaim-migrate @ 8875]
Ethan Blanton <elb@pidgin.im>
parents: 8125
diff changeset
1476 case '>':
da57fb60680a [gaim-migrate @ 8875]
Ethan Blanton <elb@pidgin.im>
parents: 8125
diff changeset
1477 ret = g_string_append(ret, "&gt;");
da57fb60680a [gaim-migrate @ 8875]
Ethan Blanton <elb@pidgin.im>
parents: 8125
diff changeset
1478 break;
da57fb60680a [gaim-migrate @ 8875]
Ethan Blanton <elb@pidgin.im>
parents: 8125
diff changeset
1479 case '"':
da57fb60680a [gaim-migrate @ 8875]
Ethan Blanton <elb@pidgin.im>
parents: 8125
diff changeset
1480 ret = g_string_append(ret, "&quot;");
da57fb60680a [gaim-migrate @ 8875]
Ethan Blanton <elb@pidgin.im>
parents: 8125
diff changeset
1481 break;
da57fb60680a [gaim-migrate @ 8875]
Ethan Blanton <elb@pidgin.im>
parents: 8125
diff changeset
1482 default:
da57fb60680a [gaim-migrate @ 8875]
Ethan Blanton <elb@pidgin.im>
parents: 8125
diff changeset
1483 ret = g_string_append_c(ret, *c);
da57fb60680a [gaim-migrate @ 8875]
Ethan Blanton <elb@pidgin.im>
parents: 8125
diff changeset
1484 }
da57fb60680a [gaim-migrate @ 8875]
Ethan Blanton <elb@pidgin.im>
parents: 8125
diff changeset
1485 c++;
da57fb60680a [gaim-migrate @ 8875]
Ethan Blanton <elb@pidgin.im>
parents: 8125
diff changeset
1486 }
da57fb60680a [gaim-migrate @ 8875]
Ethan Blanton <elb@pidgin.im>
parents: 8125
diff changeset
1487
da57fb60680a [gaim-migrate @ 8875]
Ethan Blanton <elb@pidgin.im>
parents: 8125
diff changeset
1488 escaped = ret->str;
da57fb60680a [gaim-migrate @ 8875]
Ethan Blanton <elb@pidgin.im>
parents: 8125
diff changeset
1489 g_string_free(ret, FALSE);
da57fb60680a [gaim-migrate @ 8875]
Ethan Blanton <elb@pidgin.im>
parents: 8125
diff changeset
1490 }
da57fb60680a [gaim-migrate @ 8875]
Ethan Blanton <elb@pidgin.im>
parents: 8125
diff changeset
1491 return escaped;
da57fb60680a [gaim-migrate @ 8875]
Ethan Blanton <elb@pidgin.im>
parents: 8125
diff changeset
1492
da57fb60680a [gaim-migrate @ 8875]
Ethan Blanton <elb@pidgin.im>
parents: 8125
diff changeset
1493 }
7108
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1494
8442
3d0178c4f390 [gaim-migrate @ 9172]
Luke Schierer <lschiere@pidgin.im>
parents: 8433
diff changeset
1495 char *
3d0178c4f390 [gaim-migrate @ 9172]
Luke Schierer <lschiere@pidgin.im>
parents: 8433
diff changeset
1496 gaim_unescape_html(const char *html) {
3d0178c4f390 [gaim-migrate @ 9172]
Luke Schierer <lschiere@pidgin.im>
parents: 8433
diff changeset
1497 char *unescaped = NULL;
3d0178c4f390 [gaim-migrate @ 9172]
Luke Schierer <lschiere@pidgin.im>
parents: 8433
diff changeset
1498
3d0178c4f390 [gaim-migrate @ 9172]
Luke Schierer <lschiere@pidgin.im>
parents: 8433
diff changeset
1499 if (html != NULL) {
3d0178c4f390 [gaim-migrate @ 9172]
Luke Schierer <lschiere@pidgin.im>
parents: 8433
diff changeset
1500 const char *c = html;
3d0178c4f390 [gaim-migrate @ 9172]
Luke Schierer <lschiere@pidgin.im>
parents: 8433
diff changeset
1501 GString *ret = g_string_new("");
3d0178c4f390 [gaim-migrate @ 9172]
Luke Schierer <lschiere@pidgin.im>
parents: 8433
diff changeset
1502 while (*c) {
3d0178c4f390 [gaim-migrate @ 9172]
Luke Schierer <lschiere@pidgin.im>
parents: 8433
diff changeset
1503 if (!strncmp(c, "&amp;", 5)) {
3d0178c4f390 [gaim-migrate @ 9172]
Luke Schierer <lschiere@pidgin.im>
parents: 8433
diff changeset
1504 ret = g_string_append_c(ret, '&');
3d0178c4f390 [gaim-migrate @ 9172]
Luke Schierer <lschiere@pidgin.im>
parents: 8433
diff changeset
1505 c += 5;
3d0178c4f390 [gaim-migrate @ 9172]
Luke Schierer <lschiere@pidgin.im>
parents: 8433
diff changeset
1506 } else if (!strncmp(c, "&lt;", 4)) {
3d0178c4f390 [gaim-migrate @ 9172]
Luke Schierer <lschiere@pidgin.im>
parents: 8433
diff changeset
1507 ret = g_string_append_c(ret, '<');
3d0178c4f390 [gaim-migrate @ 9172]
Luke Schierer <lschiere@pidgin.im>
parents: 8433
diff changeset
1508 c += 4;
3d0178c4f390 [gaim-migrate @ 9172]
Luke Schierer <lschiere@pidgin.im>
parents: 8433
diff changeset
1509 } else if (!strncmp(c, "&gt;", 4)) {
3d0178c4f390 [gaim-migrate @ 9172]
Luke Schierer <lschiere@pidgin.im>
parents: 8433
diff changeset
1510 ret = g_string_append_c(ret, '>');
3d0178c4f390 [gaim-migrate @ 9172]
Luke Schierer <lschiere@pidgin.im>
parents: 8433
diff changeset
1511 c += 4;
3d0178c4f390 [gaim-migrate @ 9172]
Luke Schierer <lschiere@pidgin.im>
parents: 8433
diff changeset
1512 } else if (!strncmp(c, "&quot;", 6)) {
3d0178c4f390 [gaim-migrate @ 9172]
Luke Schierer <lschiere@pidgin.im>
parents: 8433
diff changeset
1513 ret = g_string_append_c(ret, '"');
3d0178c4f390 [gaim-migrate @ 9172]
Luke Schierer <lschiere@pidgin.im>
parents: 8433
diff changeset
1514 c += 6;
8625
afff7b6ae29f [gaim-migrate @ 9376]
Nathan Walp <nwalp@pidgin.im>
parents: 8596
diff changeset
1515 } else if (!strncmp(c, "&apos;", 6)) {
afff7b6ae29f [gaim-migrate @ 9376]
Nathan Walp <nwalp@pidgin.im>
parents: 8596
diff changeset
1516 ret = g_string_append_c(ret, '\'');
afff7b6ae29f [gaim-migrate @ 9376]
Nathan Walp <nwalp@pidgin.im>
parents: 8596
diff changeset
1517 c += 6;
8500
a6748565835a [gaim-migrate @ 9236]
Mark Doliner <mark@kingant.net>
parents: 8442
diff changeset
1518 } else if (!strncmp(c, "<br>", 4)) {
a6748565835a [gaim-migrate @ 9236]
Mark Doliner <mark@kingant.net>
parents: 8442
diff changeset
1519 ret = g_string_append_c(ret, '\n');
a6748565835a [gaim-migrate @ 9236]
Mark Doliner <mark@kingant.net>
parents: 8442
diff changeset
1520 c += 4;
8442
3d0178c4f390 [gaim-migrate @ 9172]
Luke Schierer <lschiere@pidgin.im>
parents: 8433
diff changeset
1521 } else {
3d0178c4f390 [gaim-migrate @ 9172]
Luke Schierer <lschiere@pidgin.im>
parents: 8433
diff changeset
1522 ret = g_string_append_c(ret, *c);
3d0178c4f390 [gaim-migrate @ 9172]
Luke Schierer <lschiere@pidgin.im>
parents: 8433
diff changeset
1523 c++;
3d0178c4f390 [gaim-migrate @ 9172]
Luke Schierer <lschiere@pidgin.im>
parents: 8433
diff changeset
1524 }
3d0178c4f390 [gaim-migrate @ 9172]
Luke Schierer <lschiere@pidgin.im>
parents: 8433
diff changeset
1525 }
3d0178c4f390 [gaim-migrate @ 9172]
Luke Schierer <lschiere@pidgin.im>
parents: 8433
diff changeset
1526
3d0178c4f390 [gaim-migrate @ 9172]
Luke Schierer <lschiere@pidgin.im>
parents: 8433
diff changeset
1527 unescaped = ret->str;
3d0178c4f390 [gaim-migrate @ 9172]
Luke Schierer <lschiere@pidgin.im>
parents: 8433
diff changeset
1528 g_string_free(ret, FALSE);
3d0178c4f390 [gaim-migrate @ 9172]
Luke Schierer <lschiere@pidgin.im>
parents: 8433
diff changeset
1529 }
3d0178c4f390 [gaim-migrate @ 9172]
Luke Schierer <lschiere@pidgin.im>
parents: 8433
diff changeset
1530 return unescaped;
3d0178c4f390 [gaim-migrate @ 9172]
Luke Schierer <lschiere@pidgin.im>
parents: 8433
diff changeset
1531
3d0178c4f390 [gaim-migrate @ 9172]
Luke Schierer <lschiere@pidgin.im>
parents: 8433
diff changeset
1532 }
3d0178c4f390 [gaim-migrate @ 9172]
Luke Schierer <lschiere@pidgin.im>
parents: 8433
diff changeset
1533
7108
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1534 /**************************************************************************
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1535 * Path/Filename Functions
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1536 **************************************************************************/
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1537 const char *
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1538 gaim_home_dir(void)
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1539 {
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1540 #ifndef _WIN32
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1541 if(g_get_home_dir())
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1542 return g_get_home_dir();
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1543 else
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1544 return NULL;
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1545 #else
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1546 return wgaim_data_dir();
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1547 #endif
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1548 }
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1549
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1550 /* 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
1551 * dir. Note that there is no trailing slash after .gaim. */
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1552 char *
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1553 gaim_user_dir(void)
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1554 {
8596
56360561af5e [gaim-migrate @ 9347]
Luke Schierer <lschiere@pidgin.im>
parents: 8577
diff changeset
1555 if (custom_home_dir != NULL && strlen(custom_home_dir) > 0) {
56360561af5e [gaim-migrate @ 9347]
Luke Schierer <lschiere@pidgin.im>
parents: 8577
diff changeset
1556 strcpy ((char*) &home_dir, (char*) &custom_home_dir);
56360561af5e [gaim-migrate @ 9347]
Luke Schierer <lschiere@pidgin.im>
parents: 8577
diff changeset
1557 } else {
56360561af5e [gaim-migrate @ 9347]
Luke Schierer <lschiere@pidgin.im>
parents: 8577
diff changeset
1558 const gchar *hd = gaim_home_dir();
7108
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1559
8596
56360561af5e [gaim-migrate @ 9347]
Luke Schierer <lschiere@pidgin.im>
parents: 8577
diff changeset
1560 if (hd) {
56360561af5e [gaim-migrate @ 9347]
Luke Schierer <lschiere@pidgin.im>
parents: 8577
diff changeset
1561 strcpy((char*) &home_dir, hd);
56360561af5e [gaim-migrate @ 9347]
Luke Schierer <lschiere@pidgin.im>
parents: 8577
diff changeset
1562 strcat((char*) &home_dir, G_DIR_SEPARATOR_S ".gaim");
56360561af5e [gaim-migrate @ 9347]
Luke Schierer <lschiere@pidgin.im>
parents: 8577
diff changeset
1563 }
7108
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1564 }
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1565
8596
56360561af5e [gaim-migrate @ 9347]
Luke Schierer <lschiere@pidgin.im>
parents: 8577
diff changeset
1566 return home_dir;
56360561af5e [gaim-migrate @ 9347]
Luke Schierer <lschiere@pidgin.im>
parents: 8577
diff changeset
1567 }
56360561af5e [gaim-migrate @ 9347]
Luke Schierer <lschiere@pidgin.im>
parents: 8577
diff changeset
1568
56360561af5e [gaim-migrate @ 9347]
Luke Schierer <lschiere@pidgin.im>
parents: 8577
diff changeset
1569 void set_gaim_user_dir(const char *dir)
56360561af5e [gaim-migrate @ 9347]
Luke Schierer <lschiere@pidgin.im>
parents: 8577
diff changeset
1570 {
56360561af5e [gaim-migrate @ 9347]
Luke Schierer <lschiere@pidgin.im>
parents: 8577
diff changeset
1571 if (dir != NULL && strlen(dir) > 0) {
56360561af5e [gaim-migrate @ 9347]
Luke Schierer <lschiere@pidgin.im>
parents: 8577
diff changeset
1572 strcpy((char*) &custom_home_dir, dir);
56360561af5e [gaim-migrate @ 9347]
Luke Schierer <lschiere@pidgin.im>
parents: 8577
diff changeset
1573 }
7108
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1574 }
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1575
7622
072feee65244 [gaim-migrate @ 8246]
Nathan Walp <nwalp@pidgin.im>
parents: 7617
diff changeset
1576 int gaim_build_dir (const char *path, int mode)
7612
3ae88e96dde2 [gaim-migrate @ 8236]
Ethan Blanton <elb@pidgin.im>
parents: 7564
diff changeset
1577 {
3ae88e96dde2 [gaim-migrate @ 8236]
Ethan Blanton <elb@pidgin.im>
parents: 7564
diff changeset
1578 char *dir, **components, delim[] = { G_DIR_SEPARATOR, '\0' };
3ae88e96dde2 [gaim-migrate @ 8236]
Ethan Blanton <elb@pidgin.im>
parents: 7564
diff changeset
1579 int cur, len;
3ae88e96dde2 [gaim-migrate @ 8236]
Ethan Blanton <elb@pidgin.im>
parents: 7564
diff changeset
1580
7632
925c3ad6531b [gaim-migrate @ 8257]
Nathan Walp <nwalp@pidgin.im>
parents: 7631
diff changeset
1581 g_return_val_if_fail(path != NULL, -1);
7612
3ae88e96dde2 [gaim-migrate @ 8236]
Ethan Blanton <elb@pidgin.im>
parents: 7564
diff changeset
1582
3ae88e96dde2 [gaim-migrate @ 8236]
Ethan Blanton <elb@pidgin.im>
parents: 7564
diff changeset
1583 dir = g_new0(char, strlen(path) + 1);
7622
072feee65244 [gaim-migrate @ 8246]
Nathan Walp <nwalp@pidgin.im>
parents: 7617
diff changeset
1584 components = g_strsplit(path, delim, -1);
7612
3ae88e96dde2 [gaim-migrate @ 8236]
Ethan Blanton <elb@pidgin.im>
parents: 7564
diff changeset
1585 len = 0;
3ae88e96dde2 [gaim-migrate @ 8236]
Ethan Blanton <elb@pidgin.im>
parents: 7564
diff changeset
1586 for (cur = 0; components[cur] != NULL; cur++) {
7633
ee6c31982350 [gaim-migrate @ 8258]
Nathan Walp <nwalp@pidgin.im>
parents: 7632
diff changeset
1587 /* If you don't know what you're doing on both
ee6c31982350 [gaim-migrate @ 8258]
Nathan Walp <nwalp@pidgin.im>
parents: 7632
diff changeset
1588 * win32 and *NIX, stay the hell away from this code */
ee6c31982350 [gaim-migrate @ 8258]
Nathan Walp <nwalp@pidgin.im>
parents: 7632
diff changeset
1589 if(cur > 1)
ee6c31982350 [gaim-migrate @ 8258]
Nathan Walp <nwalp@pidgin.im>
parents: 7632
diff changeset
1590 dir[len++] = G_DIR_SEPARATOR;
7612
3ae88e96dde2 [gaim-migrate @ 8236]
Ethan Blanton <elb@pidgin.im>
parents: 7564
diff changeset
1591 strcpy(dir + len, components[cur]);
3ae88e96dde2 [gaim-migrate @ 8236]
Ethan Blanton <elb@pidgin.im>
parents: 7564
diff changeset
1592 len += strlen(components[cur]);
7633
ee6c31982350 [gaim-migrate @ 8258]
Nathan Walp <nwalp@pidgin.im>
parents: 7632
diff changeset
1593 if(cur == 0)
ee6c31982350 [gaim-migrate @ 8258]
Nathan Walp <nwalp@pidgin.im>
parents: 7632
diff changeset
1594 dir[len++] = G_DIR_SEPARATOR;
7632
925c3ad6531b [gaim-migrate @ 8257]
Nathan Walp <nwalp@pidgin.im>
parents: 7631
diff changeset
1595
925c3ad6531b [gaim-migrate @ 8257]
Nathan Walp <nwalp@pidgin.im>
parents: 7631
diff changeset
1596 if(g_file_test(dir, G_FILE_TEST_IS_DIR)) {
925c3ad6531b [gaim-migrate @ 8257]
Nathan Walp <nwalp@pidgin.im>
parents: 7631
diff changeset
1597 continue;
925c3ad6531b [gaim-migrate @ 8257]
Nathan Walp <nwalp@pidgin.im>
parents: 7631
diff changeset
1598 } else if(g_file_test(dir, G_FILE_TEST_EXISTS)) {
925c3ad6531b [gaim-migrate @ 8257]
Nathan Walp <nwalp@pidgin.im>
parents: 7631
diff changeset
1599 gaim_debug(GAIM_DEBUG_WARNING, "build_dir", "bad path: %s\n", path);
7612
3ae88e96dde2 [gaim-migrate @ 8236]
Ethan Blanton <elb@pidgin.im>
parents: 7564
diff changeset
1600 g_strfreev(components);
3ae88e96dde2 [gaim-migrate @ 8236]
Ethan Blanton <elb@pidgin.im>
parents: 7564
diff changeset
1601 g_free(dir);
3ae88e96dde2 [gaim-migrate @ 8236]
Ethan Blanton <elb@pidgin.im>
parents: 7564
diff changeset
1602 return -1;
3ae88e96dde2 [gaim-migrate @ 8236]
Ethan Blanton <elb@pidgin.im>
parents: 7564
diff changeset
1603 }
3ae88e96dde2 [gaim-migrate @ 8236]
Ethan Blanton <elb@pidgin.im>
parents: 7564
diff changeset
1604
3ae88e96dde2 [gaim-migrate @ 8236]
Ethan Blanton <elb@pidgin.im>
parents: 7564
diff changeset
1605 if (mkdir(dir, mode) < 0) {
3ae88e96dde2 [gaim-migrate @ 8236]
Ethan Blanton <elb@pidgin.im>
parents: 7564
diff changeset
1606 gaim_debug(GAIM_DEBUG_WARNING, "build_dir", "mkdir: %s\n", strerror(errno));
3ae88e96dde2 [gaim-migrate @ 8236]
Ethan Blanton <elb@pidgin.im>
parents: 7564
diff changeset
1607 g_strfreev(components);
3ae88e96dde2 [gaim-migrate @ 8236]
Ethan Blanton <elb@pidgin.im>
parents: 7564
diff changeset
1608 g_free(dir);
3ae88e96dde2 [gaim-migrate @ 8236]
Ethan Blanton <elb@pidgin.im>
parents: 7564
diff changeset
1609 return -1;
3ae88e96dde2 [gaim-migrate @ 8236]
Ethan Blanton <elb@pidgin.im>
parents: 7564
diff changeset
1610 }
3ae88e96dde2 [gaim-migrate @ 8236]
Ethan Blanton <elb@pidgin.im>
parents: 7564
diff changeset
1611 }
3ae88e96dde2 [gaim-migrate @ 8236]
Ethan Blanton <elb@pidgin.im>
parents: 7564
diff changeset
1612
3ae88e96dde2 [gaim-migrate @ 8236]
Ethan Blanton <elb@pidgin.im>
parents: 7564
diff changeset
1613 g_strfreev(components);
3ae88e96dde2 [gaim-migrate @ 8236]
Ethan Blanton <elb@pidgin.im>
parents: 7564
diff changeset
1614 g_free(dir);
3ae88e96dde2 [gaim-migrate @ 8236]
Ethan Blanton <elb@pidgin.im>
parents: 7564
diff changeset
1615 return 0;
3ae88e96dde2 [gaim-migrate @ 8236]
Ethan Blanton <elb@pidgin.im>
parents: 7564
diff changeset
1616 }
3ae88e96dde2 [gaim-migrate @ 8236]
Ethan Blanton <elb@pidgin.im>
parents: 7564
diff changeset
1617
7108
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1618 /*
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1619 * 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
1620 * 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
1621 * the space for the filepath.
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1622 *
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1623 * 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
1624 * 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
1625 *
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1626 * Returns NULL on failure and cleans up after itself if so.
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1627 */
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1628 static const char *gaim_mkstemp_templ = {"gaimXXXXXX"};
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1629
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1630 FILE *
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1631 gaim_mkstemp(char **fpath)
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1632 {
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1633 const gchar *tmpdir;
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1634 #ifndef _WIN32
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1635 int fd;
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1636 #endif
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1637 FILE *fp = NULL;
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1638
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1639 g_return_val_if_fail(fpath != NULL, NULL);
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1640
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1641 if((tmpdir = (gchar*)g_get_tmp_dir()) != NULL) {
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1642 if((*fpath = g_strdup_printf("%s" G_DIR_SEPARATOR_S "%s", tmpdir, gaim_mkstemp_templ)) != NULL) {
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1643 #ifdef _WIN32
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1644 char* result = _mktemp( *fpath );
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1645 if( result == NULL )
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1646 gaim_debug(GAIM_DEBUG_ERROR, "gaim_mkstemp",
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1647 "Problem creating the template\n");
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1648 else
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1649 {
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1650 if( (fp = fopen( result, "w+" )) == NULL ) {
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1651 gaim_debug(GAIM_DEBUG_ERROR, "gaim_mkstemp",
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1652 "Couldn't fopen() %s\n", result);
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1653 }
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1654 }
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1655 #else
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1656 if((fd = mkstemp(*fpath)) == -1) {
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1657 gaim_debug(GAIM_DEBUG_ERROR, "gaim_mkstemp",
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1658 "Couldn't make \"%s\", error: %d\n",
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1659 *fpath, errno);
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1660 } else {
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1661 if((fp = fdopen(fd, "r+")) == NULL) {
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1662 close(fd);
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1663 gaim_debug(GAIM_DEBUG_ERROR, "gaim_mkstemp",
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1664 "Couldn't fdopen(), error: %d\n", errno);
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1665 }
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1666 }
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1667 #endif
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1668 if(!fp) {
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1669 g_free(*fpath);
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1670 *fpath = NULL;
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1671 }
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1672 }
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1673 } else {
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1674 gaim_debug(GAIM_DEBUG_ERROR, "gaim_mkstemp",
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1675 "g_get_tmp_dir() failed!");
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1676 }
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1677
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1678 return fp;
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1679 }
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1680
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1681 gboolean
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1682 gaim_program_is_valid(const char *program)
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1683 {
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1684 GError *error = NULL;
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1685 char **argv;
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1686 gchar *progname;
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1687 gboolean is_valid = FALSE;
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1688
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1689 g_return_val_if_fail(program != NULL, FALSE);
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1690 g_return_val_if_fail(*program != '\0', FALSE);
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1691
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1692 if (!g_shell_parse_argv(program, NULL, &argv, &error)) {
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1693 gaim_debug(GAIM_DEBUG_ERROR, "program_is_valid",
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1694 "Could not parse program '%s': %s\n",
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1695 program, error->message);
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1696 g_error_free(error);
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1697 return FALSE;
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1698 }
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1699
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1700 if (argv == NULL) {
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1701 return FALSE;
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1702 }
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1703
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1704 progname = g_find_program_in_path(argv[0]);
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1705 is_valid = (progname != NULL);
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1706
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1707 g_strfreev(argv);
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1708 g_free(progname);
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1709
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1710 return is_valid;
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1711 }
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1712
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1713 char *
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1714 gaim_fd_get_ip(int fd)
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1715 {
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1716 struct sockaddr addr;
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1717 socklen_t namelen = sizeof(addr);
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1718
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1719 g_return_val_if_fail(fd != 0, NULL);
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1720
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1721 if (getsockname(fd, &addr, &namelen))
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1722 return NULL;
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1723
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1724 return g_strdup(inet_ntoa(((struct sockaddr_in *)&addr)->sin_addr));
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1725 }
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1726
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1727
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1728 /**************************************************************************
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1729 * String Functions
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1730 **************************************************************************/
7162
d14e026611c0 [gaim-migrate @ 7729]
Nathan Walp <nwalp@pidgin.im>
parents: 7134
diff changeset
1731 const char *
7261
1930e3d00ecd [gaim-migrate @ 7838]
Nathan Walp <nwalp@pidgin.im>
parents: 7162
diff changeset
1732 gaim_normalize(const GaimAccount *account, const char *s)
7108
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1733 {
7261
1930e3d00ecd [gaim-migrate @ 7838]
Nathan Walp <nwalp@pidgin.im>
parents: 7162
diff changeset
1734 GaimPlugin *prpl = NULL;
1930e3d00ecd [gaim-migrate @ 7838]
Nathan Walp <nwalp@pidgin.im>
parents: 7162
diff changeset
1735 GaimPluginProtocolInfo *prpl_info = NULL;
7430
783eea64614c [gaim-migrate @ 8034]
Nathan Walp <nwalp@pidgin.im>
parents: 7386
diff changeset
1736 const char *ret = NULL;
7261
1930e3d00ecd [gaim-migrate @ 7838]
Nathan Walp <nwalp@pidgin.im>
parents: 7162
diff changeset
1737
1930e3d00ecd [gaim-migrate @ 7838]
Nathan Walp <nwalp@pidgin.im>
parents: 7162
diff changeset
1738 if(account)
7956
1b8261f374ea [gaim-migrate @ 8631]
Nathan Walp <nwalp@pidgin.im>
parents: 7889
diff changeset
1739 prpl = gaim_find_prpl(gaim_account_get_protocol_id(account));
7108
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1740
7261
1930e3d00ecd [gaim-migrate @ 7838]
Nathan Walp <nwalp@pidgin.im>
parents: 7162
diff changeset
1741 if(prpl)
1930e3d00ecd [gaim-migrate @ 7838]
Nathan Walp <nwalp@pidgin.im>
parents: 7162
diff changeset
1742 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(prpl);
1930e3d00ecd [gaim-migrate @ 7838]
Nathan Walp <nwalp@pidgin.im>
parents: 7162
diff changeset
1743
7430
783eea64614c [gaim-migrate @ 8034]
Nathan Walp <nwalp@pidgin.im>
parents: 7386
diff changeset
1744 if(prpl_info && prpl_info->normalize)
783eea64614c [gaim-migrate @ 8034]
Nathan Walp <nwalp@pidgin.im>
parents: 7386
diff changeset
1745 ret = prpl_info->normalize(account, s);
783eea64614c [gaim-migrate @ 8034]
Nathan Walp <nwalp@pidgin.im>
parents: 7386
diff changeset
1746
783eea64614c [gaim-migrate @ 8034]
Nathan Walp <nwalp@pidgin.im>
parents: 7386
diff changeset
1747 if(!ret) {
7261
1930e3d00ecd [gaim-migrate @ 7838]
Nathan Walp <nwalp@pidgin.im>
parents: 7162
diff changeset
1748 static char buf[BUF_LEN];
1930e3d00ecd [gaim-migrate @ 7838]
Nathan Walp <nwalp@pidgin.im>
parents: 7162
diff changeset
1749 char *tmp;
1930e3d00ecd [gaim-migrate @ 7838]
Nathan Walp <nwalp@pidgin.im>
parents: 7162
diff changeset
1750 int i, j;
7108
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1751
7261
1930e3d00ecd [gaim-migrate @ 7838]
Nathan Walp <nwalp@pidgin.im>
parents: 7162
diff changeset
1752 g_return_val_if_fail(s != NULL, NULL);
1930e3d00ecd [gaim-migrate @ 7838]
Nathan Walp <nwalp@pidgin.im>
parents: 7162
diff changeset
1753
1930e3d00ecd [gaim-migrate @ 7838]
Nathan Walp <nwalp@pidgin.im>
parents: 7162
diff changeset
1754 strncpy(buf, s, BUF_LEN);
1930e3d00ecd [gaim-migrate @ 7838]
Nathan Walp <nwalp@pidgin.im>
parents: 7162
diff changeset
1755 for (i=0, j=0; buf[j]; i++, j++) {
1930e3d00ecd [gaim-migrate @ 7838]
Nathan Walp <nwalp@pidgin.im>
parents: 7162
diff changeset
1756 while (buf[j] == ' ')
1930e3d00ecd [gaim-migrate @ 7838]
Nathan Walp <nwalp@pidgin.im>
parents: 7162
diff changeset
1757 j++;
1930e3d00ecd [gaim-migrate @ 7838]
Nathan Walp <nwalp@pidgin.im>
parents: 7162
diff changeset
1758 buf[i] = buf[j];
1930e3d00ecd [gaim-migrate @ 7838]
Nathan Walp <nwalp@pidgin.im>
parents: 7162
diff changeset
1759 }
1930e3d00ecd [gaim-migrate @ 7838]
Nathan Walp <nwalp@pidgin.im>
parents: 7162
diff changeset
1760 buf[i] = '\0';
7108
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1761
7261
1930e3d00ecd [gaim-migrate @ 7838]
Nathan Walp <nwalp@pidgin.im>
parents: 7162
diff changeset
1762 tmp = g_utf8_strdown(buf, -1);
1930e3d00ecd [gaim-migrate @ 7838]
Nathan Walp <nwalp@pidgin.im>
parents: 7162
diff changeset
1763 g_snprintf(buf, sizeof(buf), "%s", tmp);
1930e3d00ecd [gaim-migrate @ 7838]
Nathan Walp <nwalp@pidgin.im>
parents: 7162
diff changeset
1764 g_free(tmp);
1930e3d00ecd [gaim-migrate @ 7838]
Nathan Walp <nwalp@pidgin.im>
parents: 7162
diff changeset
1765 tmp = g_utf8_normalize(buf, -1, G_NORMALIZE_DEFAULT);
1930e3d00ecd [gaim-migrate @ 7838]
Nathan Walp <nwalp@pidgin.im>
parents: 7162
diff changeset
1766 g_snprintf(buf, sizeof(buf), "%s", tmp);
1930e3d00ecd [gaim-migrate @ 7838]
Nathan Walp <nwalp@pidgin.im>
parents: 7162
diff changeset
1767 g_free(tmp);
7108
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1768
7430
783eea64614c [gaim-migrate @ 8034]
Nathan Walp <nwalp@pidgin.im>
parents: 7386
diff changeset
1769 ret = buf;
7261
1930e3d00ecd [gaim-migrate @ 7838]
Nathan Walp <nwalp@pidgin.im>
parents: 7162
diff changeset
1770 }
7430
783eea64614c [gaim-migrate @ 8034]
Nathan Walp <nwalp@pidgin.im>
parents: 7386
diff changeset
1771 return ret;
7108
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1772 }
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1773
8700
ddd2bf87fe8d [gaim-migrate @ 9453]
Mark Doliner <mark@kingant.net>
parents: 8686
diff changeset
1774 gchar *
ddd2bf87fe8d [gaim-migrate @ 9453]
Mark Doliner <mark@kingant.net>
parents: 8686
diff changeset
1775 gaim_str_sub_away_formatters(const char *str, const char *name)
7108
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1776 {
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1777 char *c;
8700
ddd2bf87fe8d [gaim-migrate @ 9453]
Mark Doliner <mark@kingant.net>
parents: 8686
diff changeset
1778 gchar *cpy;
7108
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1779 int cnt = 0;
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1780 time_t t;
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1781 struct tm *tme;
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1782 char tmp[20];
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1783
8700
ddd2bf87fe8d [gaim-migrate @ 9453]
Mark Doliner <mark@kingant.net>
parents: 8686
diff changeset
1784 g_return_val_if_fail(str != NULL, NULL);
7108
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1785 g_return_val_if_fail(name != NULL, NULL);
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1786
8700
ddd2bf87fe8d [gaim-migrate @ 9453]
Mark Doliner <mark@kingant.net>
parents: 8686
diff changeset
1787 cpy = g_malloc(BUF_LONG);
ddd2bf87fe8d [gaim-migrate @ 9453]
Mark Doliner <mark@kingant.net>
parents: 8686
diff changeset
1788
7108
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1789 t = time(NULL);
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1790 tme = localtime(&t);
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1791
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1792 cpy[0] = '\0';
8700
ddd2bf87fe8d [gaim-migrate @ 9453]
Mark Doliner <mark@kingant.net>
parents: 8686
diff changeset
1793 c = (char *)str;
7108
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1794 while (*c) {
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1795 switch (*c) {
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1796 case '%':
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1797 if (*(c + 1)) {
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1798 switch (*(c + 1)) {
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1799 case 'n':
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1800 /* append name */
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1801 strcpy(cpy + cnt, name);
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1802 cnt += strlen(name);
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1803 c++;
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1804 break;
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1805 case 'd':
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1806 /* append date */
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1807 strftime(tmp, 20, "%m/%d/%Y", tme);
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1808 strcpy(cpy + cnt, tmp);
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1809 cnt += strlen(tmp);
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1810 c++;
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1811 break;
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1812 case 't':
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1813 /* append time */
7459
825351e3b01b [gaim-migrate @ 8072]
Christian Hammond <chipx86@chipx86.com>
parents: 7430
diff changeset
1814 strftime(tmp, 20, "%I:%M:%S %p", tme);
7108
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1815 strcpy(cpy + cnt, tmp);
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1816 cnt += strlen(tmp);
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1817 c++;
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1818 break;
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1819 default:
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1820 cpy[cnt++] = *c;
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1821 }
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1822 }
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1823 break;
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1824 default:
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1825 cpy[cnt++] = *c;
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1826 }
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1827 c++;
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1828 }
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1829 cpy[cnt] = '\0';
8700
ddd2bf87fe8d [gaim-migrate @ 9453]
Mark Doliner <mark@kingant.net>
parents: 8686
diff changeset
1830
ddd2bf87fe8d [gaim-migrate @ 9453]
Mark Doliner <mark@kingant.net>
parents: 8686
diff changeset
1831 return cpy;
7108
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1832 }
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1833
8341
fec4c1fb2ac8 [gaim-migrate @ 9065]
Mark Doliner <mark@kingant.net>
parents: 8163
diff changeset
1834 gchar *
fec4c1fb2ac8 [gaim-migrate @ 9065]
Mark Doliner <mark@kingant.net>
parents: 8163
diff changeset
1835 gaim_strdup_withhtml(const gchar *src)
7108
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1836 {
8341
fec4c1fb2ac8 [gaim-migrate @ 9065]
Mark Doliner <mark@kingant.net>
parents: 8163
diff changeset
1837 gulong destsize, i, j;
fec4c1fb2ac8 [gaim-migrate @ 9065]
Mark Doliner <mark@kingant.net>
parents: 8163
diff changeset
1838 gchar *dest;
7108
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1839
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1840 g_return_val_if_fail(src != NULL, NULL);
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1841
8341
fec4c1fb2ac8 [gaim-migrate @ 9065]
Mark Doliner <mark@kingant.net>
parents: 8163
diff changeset
1842 /* New length is (length of src) + (number of \n's * 3) + 1 */
fec4c1fb2ac8 [gaim-migrate @ 9065]
Mark Doliner <mark@kingant.net>
parents: 8163
diff changeset
1843 for (i = 0, j = 0; src[i] != '\0'; i++)
fec4c1fb2ac8 [gaim-migrate @ 9065]
Mark Doliner <mark@kingant.net>
parents: 8163
diff changeset
1844 if (src[i] == '\n')
fec4c1fb2ac8 [gaim-migrate @ 9065]
Mark Doliner <mark@kingant.net>
parents: 8163
diff changeset
1845 j++;
fec4c1fb2ac8 [gaim-migrate @ 9065]
Mark Doliner <mark@kingant.net>
parents: 8163
diff changeset
1846
fec4c1fb2ac8 [gaim-migrate @ 9065]
Mark Doliner <mark@kingant.net>
parents: 8163
diff changeset
1847 destsize = i + (j * 3) + 1;
fec4c1fb2ac8 [gaim-migrate @ 9065]
Mark Doliner <mark@kingant.net>
parents: 8163
diff changeset
1848 dest = g_malloc(destsize);
7108
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1849
8341
fec4c1fb2ac8 [gaim-migrate @ 9065]
Mark Doliner <mark@kingant.net>
parents: 8163
diff changeset
1850 /* Copy stuff, ignoring \r's, because they are dumb */
fec4c1fb2ac8 [gaim-migrate @ 9065]
Mark Doliner <mark@kingant.net>
parents: 8163
diff changeset
1851 for (i = 0, j = 0; src[i] != '\0'; i++) {
fec4c1fb2ac8 [gaim-migrate @ 9065]
Mark Doliner <mark@kingant.net>
parents: 8163
diff changeset
1852 if (src[i] == '\n') {
fec4c1fb2ac8 [gaim-migrate @ 9065]
Mark Doliner <mark@kingant.net>
parents: 8163
diff changeset
1853 strcpy(&dest[j], "<BR>");
fec4c1fb2ac8 [gaim-migrate @ 9065]
Mark Doliner <mark@kingant.net>
parents: 8163
diff changeset
1854 j += 4;
fec4c1fb2ac8 [gaim-migrate @ 9065]
Mark Doliner <mark@kingant.net>
parents: 8163
diff changeset
1855 } else if (src[i] != '\r')
fec4c1fb2ac8 [gaim-migrate @ 9065]
Mark Doliner <mark@kingant.net>
parents: 8163
diff changeset
1856 dest[j++] = src[i];
fec4c1fb2ac8 [gaim-migrate @ 9065]
Mark Doliner <mark@kingant.net>
parents: 8163
diff changeset
1857 }
fec4c1fb2ac8 [gaim-migrate @ 9065]
Mark Doliner <mark@kingant.net>
parents: 8163
diff changeset
1858
fec4c1fb2ac8 [gaim-migrate @ 9065]
Mark Doliner <mark@kingant.net>
parents: 8163
diff changeset
1859 dest[destsize-1] = '\0';
7108
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1860
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1861 return dest;
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1862 }
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1863
7628
e293d0c42ccb [gaim-migrate @ 8252]
Ethan Blanton <elb@pidgin.im>
parents: 7622
diff changeset
1864 gboolean
e293d0c42ccb [gaim-migrate @ 8252]
Ethan Blanton <elb@pidgin.im>
parents: 7622
diff changeset
1865 gaim_str_has_prefix(const char *s, const char *p)
e293d0c42ccb [gaim-migrate @ 8252]
Ethan Blanton <elb@pidgin.im>
parents: 7622
diff changeset
1866 {
e293d0c42ccb [gaim-migrate @ 8252]
Ethan Blanton <elb@pidgin.im>
parents: 7622
diff changeset
1867 if (!strncmp(s, p, strlen(p)))
e293d0c42ccb [gaim-migrate @ 8252]
Ethan Blanton <elb@pidgin.im>
parents: 7622
diff changeset
1868 return TRUE;
e293d0c42ccb [gaim-migrate @ 8252]
Ethan Blanton <elb@pidgin.im>
parents: 7622
diff changeset
1869
e293d0c42ccb [gaim-migrate @ 8252]
Ethan Blanton <elb@pidgin.im>
parents: 7622
diff changeset
1870 return FALSE;
e293d0c42ccb [gaim-migrate @ 8252]
Ethan Blanton <elb@pidgin.im>
parents: 7622
diff changeset
1871 }
e293d0c42ccb [gaim-migrate @ 8252]
Ethan Blanton <elb@pidgin.im>
parents: 7622
diff changeset
1872
e293d0c42ccb [gaim-migrate @ 8252]
Ethan Blanton <elb@pidgin.im>
parents: 7622
diff changeset
1873 gboolean
e293d0c42ccb [gaim-migrate @ 8252]
Ethan Blanton <elb@pidgin.im>
parents: 7622
diff changeset
1874 gaim_str_has_suffix(const char *s, const char *x)
e293d0c42ccb [gaim-migrate @ 8252]
Ethan Blanton <elb@pidgin.im>
parents: 7622
diff changeset
1875 {
e293d0c42ccb [gaim-migrate @ 8252]
Ethan Blanton <elb@pidgin.im>
parents: 7622
diff changeset
1876 int off = strlen(s) - strlen(x);
e293d0c42ccb [gaim-migrate @ 8252]
Ethan Blanton <elb@pidgin.im>
parents: 7622
diff changeset
1877
e293d0c42ccb [gaim-migrate @ 8252]
Ethan Blanton <elb@pidgin.im>
parents: 7622
diff changeset
1878 if (off >= 0 && !strcmp(s + off, x))
e293d0c42ccb [gaim-migrate @ 8252]
Ethan Blanton <elb@pidgin.im>
parents: 7622
diff changeset
1879 return TRUE;
e293d0c42ccb [gaim-migrate @ 8252]
Ethan Blanton <elb@pidgin.im>
parents: 7622
diff changeset
1880
e293d0c42ccb [gaim-migrate @ 8252]
Ethan Blanton <elb@pidgin.im>
parents: 7622
diff changeset
1881 return FALSE;
e293d0c42ccb [gaim-migrate @ 8252]
Ethan Blanton <elb@pidgin.im>
parents: 7622
diff changeset
1882 }
e293d0c42ccb [gaim-migrate @ 8252]
Ethan Blanton <elb@pidgin.im>
parents: 7622
diff changeset
1883
7108
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1884 char *
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1885 gaim_str_add_cr(const char *text)
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1886 {
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1887 char *ret = NULL;
7631
ea2d07ad05a9 [gaim-migrate @ 8255]
Nathan Walp <nwalp@pidgin.im>
parents: 7628
diff changeset
1888 int count = 0, j;
ea2d07ad05a9 [gaim-migrate @ 8255]
Nathan Walp <nwalp@pidgin.im>
parents: 7628
diff changeset
1889 guint i;
7108
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1890
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1891 g_return_val_if_fail(text != NULL, NULL);
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1892
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1893 if (text[0] == '\n')
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1894 count++;
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1895 for (i = 1; i < strlen(text); i++)
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1896 if (text[i] == '\n' && text[i - 1] != '\r')
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1897 count++;
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1898
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1899 if (count == 0)
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1900 return g_strdup(text);
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1901
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1902 ret = g_malloc0(strlen(text) + count + 1);
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1903
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1904 i = 0; j = 0;
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1905 if (text[i] == '\n')
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1906 ret[j++] = '\r';
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1907 ret[j++] = text[i++];
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1908 for (; i < strlen(text); i++) {
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1909 if (text[i] == '\n' && text[i - 1] != '\r')
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1910 ret[j++] = '\r';
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1911 ret[j++] = text[i];
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1912 }
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1913
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1914 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
1915 text, ret);
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1916
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1917 return ret;
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1918 }
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1919
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1920 void
7478
3c21f3084ff0 [gaim-migrate @ 8091]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 7459
diff changeset
1921 gaim_str_strip_cr(char *text)
7108
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1922 {
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1923 int i, j;
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1924 char *text2;
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1925
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1926 g_return_if_fail(text != NULL);
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1927
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1928 text2 = g_malloc(strlen(text) + 1);
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1929
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1930 for (i = 0, j = 0; text[i]; i++)
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1931 if (text[i] != '\r')
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1932 text2[j++] = text[i];
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1933 text2[j] = '\0';
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1934
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1935 strcpy(text, text2);
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1936 g_free(text2);
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1937 }
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1938
8341
fec4c1fb2ac8 [gaim-migrate @ 9065]
Mark Doliner <mark@kingant.net>
parents: 8163
diff changeset
1939 gchar *
7108
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1940 gaim_strreplace(const char *string, const char *delimiter,
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1941 const char *replacement)
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1942 {
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1943 gchar **split;
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1944 gchar *ret;
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1945
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1946 g_return_val_if_fail(string != NULL, NULL);
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1947 g_return_val_if_fail(delimiter != NULL, NULL);
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1948 g_return_val_if_fail(replacement != NULL, NULL);
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1949
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1950 split = g_strsplit(string, delimiter, 0);
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1951 ret = g_strjoinv(replacement, split);
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1952 g_strfreev(split);
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1953
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1954 return ret;
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1955 }
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
1956
8341
fec4c1fb2ac8 [gaim-migrate @ 9065]
Mark Doliner <mark@kingant.net>
parents: 8163
diff changeset
1957 gchar *
fec4c1fb2ac8 [gaim-migrate @ 9065]
Mark Doliner <mark@kingant.net>
parents: 8163
diff changeset
1958 gaim_strcasereplace(const char *string, const char *delimiter,
fec4c1fb2ac8 [gaim-migrate @ 9065]
Mark Doliner <mark@kingant.net>
parents: 8163
diff changeset
1959 const char *replacement)
fec4c1fb2ac8 [gaim-migrate @ 9065]
Mark Doliner <mark@kingant.net>
parents: 8163
diff changeset
1960 {
fec4c1fb2ac8 [gaim-migrate @ 9065]
Mark Doliner <mark@kingant.net>
parents: 8163
diff changeset
1961 gchar *ret;
fec4c1fb2ac8 [gaim-migrate @ 9065]
Mark Doliner <mark@kingant.net>
parents: 8163
diff changeset
1962 int length_del, length_rep, i, j;
fec4c1fb2ac8 [gaim-migrate @ 9065]
Mark Doliner <mark@kingant.net>
parents: 8163
diff changeset
1963
fec4c1fb2ac8 [gaim-migrate @ 9065]
Mark Doliner <mark@kingant.net>
parents: 8163
diff changeset
1964 g_return_val_if_fail(string != NULL, NULL);
fec4c1fb2ac8 [gaim-migrate @ 9065]
Mark Doliner <mark@kingant.net>
parents: 8163
diff changeset
1965 g_return_val_if_fail(delimiter != NULL, NULL);
fec4c1fb2ac8 [gaim-migrate @ 9065]
Mark Doliner <mark@kingant.net>
parents: 8163
diff changeset
1966 g_return_val_if_fail(replacement != NULL, NULL);
fec4c1fb2ac8 [gaim-migrate @ 9065]
Mark Doliner <mark@kingant.net>
parents: 8163
diff changeset
1967
fec4c1fb2ac8 [gaim-migrate @ 9065]
Mark Doliner <mark@kingant.net>
parents: 8163
diff changeset
1968 length_del = strlen(delimiter);
fec4c1fb2ac8 [gaim-migrate @ 9065]
Mark Doliner <mark@kingant.net>
parents: 8163
diff changeset
1969 length_rep = strlen(replacement);
fec4c1fb2ac8 [gaim-migrate @ 9065]
Mark Doliner <mark@kingant.net>
parents: 8163
diff changeset
1970
fec4c1fb2ac8 [gaim-migrate @ 9065]
Mark Doliner <mark@kingant.net>
parents: 8163
diff changeset
1971 /* Count how many times the delimiter appears */
fec4c1fb2ac8 [gaim-migrate @ 9065]
Mark Doliner <mark@kingant.net>
parents: 8163
diff changeset
1972 i = 0; /* position in the source string */
8735
92cbf9713795 [gaim-migrate @ 9490]
Christian Hammond <chipx86@chipx86.com>
parents: 8700
diff changeset
1973 j = 0; /* number of occurrences of "delimiter" */
8341
fec4c1fb2ac8 [gaim-migrate @ 9065]
Mark Doliner <mark@kingant.net>
parents: 8163
diff changeset
1974 while (string[i] != '\0') {
fec4c1fb2ac8 [gaim-migrate @ 9065]
Mark Doliner <mark@kingant.net>
parents: 8163
diff changeset
1975 if (!strncasecmp(&string[i], delimiter, length_del)) {
fec4c1fb2ac8 [gaim-migrate @ 9065]
Mark Doliner <mark@kingant.net>
parents: 8163
diff changeset
1976 i += length_del;
fec4c1fb2ac8 [gaim-migrate @ 9065]
Mark Doliner <mark@kingant.net>
parents: 8163
diff changeset
1977 j += length_rep;
fec4c1fb2ac8 [gaim-migrate @ 9065]
Mark Doliner <mark@kingant.net>
parents: 8163
diff changeset
1978 } else {
fec4c1fb2ac8 [gaim-migrate @ 9065]
Mark Doliner <mark@kingant.net>
parents: 8163
diff changeset
1979 i++;
fec4c1fb2ac8 [gaim-migrate @ 9065]
Mark Doliner <mark@kingant.net>
parents: 8163
diff changeset
1980 j++;
fec4c1fb2ac8 [gaim-migrate @ 9065]
Mark Doliner <mark@kingant.net>
parents: 8163
diff changeset
1981 }
fec4c1fb2ac8 [gaim-migrate @ 9065]
Mark Doliner <mark@kingant.net>
parents: 8163
diff changeset
1982 }
fec4c1fb2ac8 [gaim-migrate @ 9065]
Mark Doliner <mark@kingant.net>
parents: 8163
diff changeset
1983
fec4c1fb2ac8 [gaim-migrate @ 9065]
Mark Doliner <mark@kingant.net>
parents: 8163
diff changeset
1984 ret = g_malloc(j+1);
fec4c1fb2ac8 [gaim-migrate @ 9065]
Mark Doliner <mark@kingant.net>
parents: 8163
diff changeset
1985
fec4c1fb2ac8 [gaim-migrate @ 9065]
Mark Doliner <mark@kingant.net>
parents: 8163
diff changeset
1986 i = 0; /* position in the source string */
fec4c1fb2ac8 [gaim-migrate @ 9065]
Mark Doliner <mark@kingant.net>
parents: 8163
diff changeset
1987 j = 0; /* position in the destination string */
fec4c1fb2ac8 [gaim-migrate @ 9065]
Mark Doliner <mark@kingant.net>
parents: 8163
diff changeset
1988 while (string[i] != '\0') {
fec4c1fb2ac8 [gaim-migrate @ 9065]
Mark Doliner <mark@kingant.net>
parents: 8163
diff changeset
1989 if (!strncasecmp(&string[i], delimiter, length_del)) {
fec4c1fb2ac8 [gaim-migrate @ 9065]
Mark Doliner <mark@kingant.net>
parents: 8163
diff changeset
1990 strncpy(&ret[j], replacement, length_rep);
fec4c1fb2ac8 [gaim-migrate @ 9065]
Mark Doliner <mark@kingant.net>
parents: 8163
diff changeset
1991 i += length_del;
fec4c1fb2ac8 [gaim-migrate @ 9065]
Mark Doliner <mark@kingant.net>
parents: 8163
diff changeset
1992 j += length_rep;
fec4c1fb2ac8 [gaim-migrate @ 9065]
Mark Doliner <mark@kingant.net>
parents: 8163
diff changeset
1993 } else {
fec4c1fb2ac8 [gaim-migrate @ 9065]
Mark Doliner <mark@kingant.net>
parents: 8163
diff changeset
1994 ret[j] = string[i];
fec4c1fb2ac8 [gaim-migrate @ 9065]
Mark Doliner <mark@kingant.net>
parents: 8163
diff changeset
1995 i++;
fec4c1fb2ac8 [gaim-migrate @ 9065]
Mark Doliner <mark@kingant.net>
parents: 8163
diff changeset
1996 j++;
fec4c1fb2ac8 [gaim-migrate @ 9065]
Mark Doliner <mark@kingant.net>
parents: 8163
diff changeset
1997 }
fec4c1fb2ac8 [gaim-migrate @ 9065]
Mark Doliner <mark@kingant.net>
parents: 8163
diff changeset
1998 }
fec4c1fb2ac8 [gaim-migrate @ 9065]
Mark Doliner <mark@kingant.net>
parents: 8163
diff changeset
1999
fec4c1fb2ac8 [gaim-migrate @ 9065]
Mark Doliner <mark@kingant.net>
parents: 8163
diff changeset
2000 ret[j] = '\0';
fec4c1fb2ac8 [gaim-migrate @ 9065]
Mark Doliner <mark@kingant.net>
parents: 8163
diff changeset
2001
fec4c1fb2ac8 [gaim-migrate @ 9065]
Mark Doliner <mark@kingant.net>
parents: 8163
diff changeset
2002 return ret;
fec4c1fb2ac8 [gaim-migrate @ 9065]
Mark Doliner <mark@kingant.net>
parents: 8163
diff changeset
2003 }
fec4c1fb2ac8 [gaim-migrate @ 9065]
Mark Doliner <mark@kingant.net>
parents: 8163
diff changeset
2004
7108
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2005 const char *
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2006 gaim_strcasestr(const char *haystack, const char *needle)
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2007 {
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2008 size_t hlen, nlen;
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2009 const char *tmp, *ret;
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2010
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2011 g_return_val_if_fail(haystack != NULL, NULL);
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2012 g_return_val_if_fail(needle != NULL, NULL);
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2013
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2014 hlen = strlen(haystack);
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2015 nlen = strlen(needle);
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2016 tmp = haystack,
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2017 ret = NULL;
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2018
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2019 g_return_val_if_fail(hlen > 0, NULL);
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2020 g_return_val_if_fail(nlen > 0, NULL);
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2021
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2022 while (*tmp && !ret) {
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2023 if (!g_ascii_strncasecmp(needle, tmp, nlen))
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2024 ret = tmp;
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2025 else
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2026 tmp++;
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2027 }
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2028
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2029 return ret;
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2030 }
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2031
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2032 char *
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2033 gaim_str_size_to_units(size_t size)
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2034 {
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2035 static const char *size_str[4] = { "bytes", "KB", "MB", "GB" };
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2036 float size_mag;
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2037 int size_index = 0;
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2038
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2039 if (size == -1) {
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2040 return g_strdup(_("Calculating..."));
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2041 }
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2042 else if (size == 0) {
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2043 return g_strdup(_("Unknown."));
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2044 }
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2045 else {
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2046 size_mag = (float)size;
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2047
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2048 while ((size_index < 4) && (size_mag > 1024)) {
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2049 size_mag /= 1024;
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2050 size_index++;
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2051 }
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2052
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2053 return g_strdup_printf("%.2f %s", size_mag, size_str[size_index]);
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2054 }
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2055 }
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2056
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2057 char *
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2058 gaim_str_seconds_to_string(guint sec)
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2059 {
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2060 guint daze, hrs, min;
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2061 char *ret = NULL;
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2062
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2063 daze = sec / (60 * 60 * 24);
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2064 hrs = (sec % (60 * 60 * 24)) / (60 * 60);
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2065 min = (sec % (60 * 60)) / 60;
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2066 sec = min % 60;
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2067
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2068 if (daze) {
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2069 if (hrs || min) {
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2070 if (hrs) {
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2071 if (min) {
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2072 ret = g_strdup_printf(
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2073 "%d %s, %d %s, %d %s.",
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2074 daze, ngettext("day","days",daze),
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2075 hrs, ngettext("hour","hours",hrs), min, ngettext("minute","minutes",min));
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2076 } else {
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2077 ret = g_strdup_printf(
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2078 "%d %s, %d %s.",
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2079 daze, ngettext("day","days",daze), hrs, ngettext("hour","hours",hrs));
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2080 }
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2081 } else {
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2082 ret = g_strdup_printf(
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2083 "%d %s, %d %s.",
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2084 daze, ngettext("day","days",daze), min, ngettext("minute","minutes",min));
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2085 }
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2086 } else
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2087 ret = g_strdup_printf("%d %s.", daze, ngettext("day","days",daze));
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2088 } else {
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2089 if (hrs) {
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2090 if (min) {
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2091 ret = g_strdup_printf(
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2092 "%d %s, %d %s.",
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2093 hrs, ngettext("hour","hours",hrs), min, ngettext("minute","minutes",min));
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2094 } else {
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2095 ret = g_strdup_printf("%d %s.", hrs, ngettext("hour","hours",hrs));
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2096 }
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2097 } else {
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2098 ret = g_strdup_printf("%d %s.", min, ngettext("minute","minutes",min));
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2099 }
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2100 }
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2101
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2102 return ret;
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2103 }
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2104
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2105 /**************************************************************************
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2106 * URI/URL Functions
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2107 **************************************************************************/
7095
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7094
diff changeset
2108 gboolean
7094
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2109 gaim_url_parse(const char *url, char **ret_host, int *ret_port,
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2110 char **ret_path)
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2111 {
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2112 char scan_info[255];
8118
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8088
diff changeset
2113 char port_str[6];
7094
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2114 int f;
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2115 const char *turl;
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2116 char host[256], path[256];
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2117 int port = 0;
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2118 /* hyphen at end includes it in control set */
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2119 static char addr_ctrl[] = "A-Za-z0-9.-";
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2120 static char port_ctrl[] = "0-9";
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2121 static char page_ctrl[] = "A-Za-z0-9.~_/:*!@&%%?=+^-";
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2122
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2123 g_return_val_if_fail(url != NULL, FALSE);
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2124
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2125 if ((turl = strstr(url, "http://")) != NULL ||
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2126 (turl = strstr(url, "HTTP://")) != NULL)
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2127 {
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2128 turl += 7;
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2129 url = turl;
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2130 }
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2131
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2132 g_snprintf(scan_info, sizeof(scan_info),
8118
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8088
diff changeset
2133 "%%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
2134
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2135 f = sscanf(url, scan_info, host, port_str, path);
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2136
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2137 if (f == 1)
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2138 {
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2139 g_snprintf(scan_info, sizeof(scan_info),
8118
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8088
diff changeset
2140 "%%255[%s]/%%255[%s]",
7094
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2141 addr_ctrl, page_ctrl);
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2142 f = sscanf(url, scan_info, host, path);
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2143 g_snprintf(port_str, sizeof(port_str), "80");
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2144 }
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2145
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2146 if (f == 1)
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2147 *path = '\0';
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2148
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2149 sscanf(port_str, "%d", &port);
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2150
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2151 if (ret_host != NULL) *ret_host = g_strdup(host);
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2152 if (ret_port != NULL) *ret_port = port;
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2153 if (ret_path != NULL) *ret_path = g_strdup(path);
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2154
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2155 return TRUE;
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2156 }
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2157
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2158 static void
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2159 destroy_fetch_url_data(GaimFetchUrlData *gfud)
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2160 {
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2161 if (gfud->webdata != NULL) g_free(gfud->webdata);
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2162 if (gfud->url != NULL) g_free(gfud->url);
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2163 if (gfud->user_agent != NULL) g_free(gfud->user_agent);
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2164 if (gfud->website.address != NULL) g_free(gfud->website.address);
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2165 if (gfud->website.page != NULL) g_free(gfud->website.page);
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2166
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2167 g_free(gfud);
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2168 }
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2169
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2170 static gboolean
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2171 parse_redirect(const char *data, size_t data_len, gint sock,
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2172 GaimFetchUrlData *gfud)
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2173 {
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2174 gchar *s;
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2175
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2176 if ((s = g_strstr_len(data, data_len, "Location: ")) != NULL)
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2177 {
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2178 gchar *new_url, *temp_url, *end;
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2179 gboolean full;
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2180 int len;
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2181
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2182 s += strlen("Location: ");
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2183 end = strchr(s, '\r');
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2184
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2185 /* Just in case :) */
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2186 if (end == NULL)
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2187 end = strchr(s, '\n');
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2188
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2189 len = end - s;
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2190
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2191 new_url = g_malloc(len + 1);
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2192 strncpy(new_url, s, len);
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2193 new_url[len] = '\0';
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2194
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2195 full = gfud->full;
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2196
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2197 if (*new_url == '/' || g_strstr_len(new_url, len, "://") == NULL)
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2198 {
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2199 temp_url = new_url;
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2200
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2201 new_url = g_strdup_printf("%s:%d%s", gfud->website.address,
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2202 gfud->website.port, temp_url);
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2203
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2204 g_free(temp_url);
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2205
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2206 full = FALSE;
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2207 }
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2208
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2209 /* Close the existing stuff. */
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2210 gaim_input_remove(gfud->inpa);
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2211 close(sock);
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2212
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2213 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
2214
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2215 /* Try again, with this new location. */
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2216 gaim_url_fetch(new_url, full, gfud->user_agent, gfud->http11,
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2217 gfud->callback, gfud->user_data);
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2218
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2219 /* Free up. */
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2220 g_free(new_url);
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2221 destroy_fetch_url_data(gfud);
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2222
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2223 return TRUE;
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2224 }
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2225
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2226 return FALSE;
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2227 }
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2228
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2229 static size_t
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2230 parse_content_len(const char *data, size_t data_len)
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2231 {
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2232 size_t content_len = 0;
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2233
7386
414c701ef1ff [gaim-migrate @ 7981]
Luke Schierer <lschiere@pidgin.im>
parents: 7322
diff changeset
2234 sscanf(data, "Content-Length: %d", (int *)&content_len);
7094
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2235
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2236 return content_len;
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2237 }
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2238
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2239 static void
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2240 url_fetched_cb(gpointer url_data, gint sock, GaimInputCondition cond)
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2241 {
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2242 GaimFetchUrlData *gfud = url_data;
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2243 char data;
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2244
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2245 if (sock == -1)
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2246 {
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2247 gfud->callback(gfud->user_data, NULL, 0);
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2248
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2249 destroy_fetch_url_data(gfud);
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2250
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2251 return;
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2252 }
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2253
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2254 if (!gfud->sentreq)
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2255 {
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2256 char buf[1024];
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2257
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2258 if (gfud->user_agent)
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2259 {
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2260 if (gfud->http11)
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2261 {
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2262 g_snprintf(buf, sizeof(buf),
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2263 "GET %s%s HTTP/1.1\r\n"
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2264 "User-Agent: \"%s\"\r\n"
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2265 "Host: %s\r\n\r\n",
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2266 (gfud->full ? "" : "/"),
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2267 (gfud->full ? gfud->url : gfud->website.page),
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2268 gfud->user_agent, gfud->website.address);
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2269 }
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2270 else
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2271 {
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2272 g_snprintf(buf, sizeof(buf),
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2273 "GET %s%s HTTP/1.0\r\n"
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2274 "User-Agent: \"%s\"\r\n\r\n",
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2275 (gfud->full ? "" : "/"),
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2276 (gfud->full ? gfud->url : gfud->website.page),
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2277 gfud->user_agent);
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2278 }
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2279 }
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2280 else
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2281 {
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2282 if (gfud->http11)
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2283 {
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2284 g_snprintf(buf, sizeof(buf),
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2285 "GET %s%s HTTP/1.1\r\n"
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2286 "Host: %s\r\n\r\n",
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2287 (gfud->full ? "" : "/"),
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2288 (gfud->full ? gfud->url : gfud->website.page),
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2289 gfud->website.address);
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2290 }
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2291 else
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2292 {
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2293 g_snprintf(buf, sizeof(buf),
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2294 "GET %s%s HTTP/1.0\r\n\r\n",
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2295 (gfud->full ? "" : "/"),
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2296 (gfud->full ? gfud->url : gfud->website.page));
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2297 }
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2298 }
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2299
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2300 gaim_debug_misc("gaim_url_fetch", "Request: %s\n", buf);
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2301
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2302 write(sock, buf, strlen(buf));
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2303 fcntl(sock, F_SETFL, O_NONBLOCK);
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2304 gfud->sentreq = TRUE;
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2305 gfud->inpa = gaim_input_add(sock, GAIM_INPUT_READ,
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2306 url_fetched_cb, url_data);
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2307 gfud->data_len = 4096;
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2308 gfud->webdata = g_malloc(gfud->data_len);
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2309
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2310 return;
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2311 }
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2312
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2313 if (read(sock, &data, 1) > 0 || errno == EWOULDBLOCK)
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2314 {
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2315 if (errno == EWOULDBLOCK)
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2316 {
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2317 errno = 0;
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2318
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2319 return;
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2320 }
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2321
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2322 gfud->len++;
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2323
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2324 if (gfud->len == gfud->data_len + 1)
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2325 {
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2326 gfud->data_len += (gfud->data_len) / 2;
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2327
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2328 gfud->webdata = g_realloc(gfud->webdata, gfud->data_len);
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2329 }
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2330
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2331 gfud->webdata[gfud->len - 1] = data;
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2332
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2333 if (!gfud->startsaving)
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2334 {
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2335 if (data == '\r')
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2336 return;
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2337
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2338 if (data == '\n')
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2339 {
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2340 if (gfud->newline)
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2341 {
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2342 size_t content_len;
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2343 gfud->startsaving = TRUE;
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2344
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2345 /* See if we can find a redirect. */
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2346 if (parse_redirect(gfud->webdata, gfud->len, sock, gfud))
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2347 return;
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2348
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2349 /* No redirect. See if we can find a content length. */
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2350 content_len = parse_content_len(gfud->webdata, gfud->len);
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2351
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2352 if (content_len == 0)
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2353 {
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2354 /* We'll stick with an initial 8192 */
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2355 content_len = 8192;
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2356 }
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2357
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2358 /* Out with the old... */
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2359 gfud->len = 0;
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2360 g_free(gfud->webdata);
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2361 gfud->webdata = NULL;
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2362
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2363 /* In with the new. */
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2364 gfud->data_len = content_len;
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2365 gfud->webdata = g_malloc(gfud->data_len);
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2366 }
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2367 else
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2368 gfud->newline = TRUE;
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2369
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2370 return;
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2371 }
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2372
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2373 gfud->newline = FALSE;
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2374 }
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2375 }
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2376 else if (errno != ETIMEDOUT)
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2377 {
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2378 gfud->webdata = g_realloc(gfud->webdata, gfud->len + 1);
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2379 gfud->webdata[gfud->len] = 0;
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2380
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2381 gaim_debug_misc("gaim_url_fetch", "Received: '%s'\n", gfud->webdata);
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2382
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2383 gaim_input_remove(gfud->inpa);
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2384 close(sock);
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2385 gfud->callback(gfud->user_data, gfud->webdata, gfud->len);
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2386
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2387 destroy_fetch_url_data(gfud);
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2388 }
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2389 else
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2390 {
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2391 gaim_input_remove(gfud->inpa);
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2392 close(sock);
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2393
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2394 gfud->callback(gfud->user_data, NULL, 0);
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2395
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2396 destroy_fetch_url_data(gfud);
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2397 }
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2398 }
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2399
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2400 void
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2401 gaim_url_fetch(const char *url, gboolean full,
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2402 const char *user_agent, gboolean http11,
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2403 void (*cb)(gpointer, const char *, size_t),
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2404 void *user_data)
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2405 {
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2406 int sock;
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2407 GaimFetchUrlData *gfud;
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2408
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2409 g_return_if_fail(url != NULL);
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2410 g_return_if_fail(cb != NULL);
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2411
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2412 gfud = g_new0(GaimFetchUrlData, 1);
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2413
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2414 gfud->callback = cb;
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2415 gfud->user_data = user_data;
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2416 gfud->url = g_strdup(url);
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2417 gfud->user_agent = (user_agent != NULL ? g_strdup(user_agent) : NULL);
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2418 gfud->http11 = http11;
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2419 gfud->full = full;
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2420
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2421 gaim_url_parse(url, &gfud->website.address, &gfud->website.port,
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2422 &gfud->website.page);
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2423
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2424 if ((sock = gaim_proxy_connect(NULL, gfud->website.address,
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2425 gfud->website.port, url_fetched_cb,
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2426 gfud)) < 0)
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2427 {
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2428 destroy_fetch_url_data(gfud);
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2429
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2430 cb(user_data, g_strdup(_("g003: Error opening connection.\n")), 0);
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2431 }
2343c3aa1dec [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
2432 }
7108
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2433
7162
d14e026611c0 [gaim-migrate @ 7729]
Nathan Walp <nwalp@pidgin.im>
parents: 7134
diff changeset
2434 const char *
7134
67f9b43c402a [gaim-migrate @ 7701]
Sean Egan <seanegan@gmail.com>
parents: 7110
diff changeset
2435 gaim_url_decode(const char *str)
67f9b43c402a [gaim-migrate @ 7701]
Sean Egan <seanegan@gmail.com>
parents: 7110
diff changeset
2436 {
67f9b43c402a [gaim-migrate @ 7701]
Sean Egan <seanegan@gmail.com>
parents: 7110
diff changeset
2437 static char buf[BUF_LEN];
7631
ea2d07ad05a9 [gaim-migrate @ 8255]
Nathan Walp <nwalp@pidgin.im>
parents: 7628
diff changeset
2438 guint i, j = 0;
7134
67f9b43c402a [gaim-migrate @ 7701]
Sean Egan <seanegan@gmail.com>
parents: 7110
diff changeset
2439 char *bum;
67f9b43c402a [gaim-migrate @ 7701]
Sean Egan <seanegan@gmail.com>
parents: 7110
diff changeset
2440
67f9b43c402a [gaim-migrate @ 7701]
Sean Egan <seanegan@gmail.com>
parents: 7110
diff changeset
2441 g_return_val_if_fail(str != NULL, NULL);
67f9b43c402a [gaim-migrate @ 7701]
Sean Egan <seanegan@gmail.com>
parents: 7110
diff changeset
2442
67f9b43c402a [gaim-migrate @ 7701]
Sean Egan <seanegan@gmail.com>
parents: 7110
diff changeset
2443 for (i = 0; i < strlen(str); i++) {
67f9b43c402a [gaim-migrate @ 7701]
Sean Egan <seanegan@gmail.com>
parents: 7110
diff changeset
2444 char hex[3];
67f9b43c402a [gaim-migrate @ 7701]
Sean Egan <seanegan@gmail.com>
parents: 7110
diff changeset
2445
67f9b43c402a [gaim-migrate @ 7701]
Sean Egan <seanegan@gmail.com>
parents: 7110
diff changeset
2446 if (str[i] != '%')
67f9b43c402a [gaim-migrate @ 7701]
Sean Egan <seanegan@gmail.com>
parents: 7110
diff changeset
2447 buf[j++] = str[i];
67f9b43c402a [gaim-migrate @ 7701]
Sean Egan <seanegan@gmail.com>
parents: 7110
diff changeset
2448 else {
67f9b43c402a [gaim-migrate @ 7701]
Sean Egan <seanegan@gmail.com>
parents: 7110
diff changeset
2449 strncpy(hex, str + ++i, 2);
67f9b43c402a [gaim-migrate @ 7701]
Sean Egan <seanegan@gmail.com>
parents: 7110
diff changeset
2450 hex[2] = '\0';
67f9b43c402a [gaim-migrate @ 7701]
Sean Egan <seanegan@gmail.com>
parents: 7110
diff changeset
2451
67f9b43c402a [gaim-migrate @ 7701]
Sean Egan <seanegan@gmail.com>
parents: 7110
diff changeset
2452 /* i is pointing to the start of the number */
67f9b43c402a [gaim-migrate @ 7701]
Sean Egan <seanegan@gmail.com>
parents: 7110
diff changeset
2453 i++;
67f9b43c402a [gaim-migrate @ 7701]
Sean Egan <seanegan@gmail.com>
parents: 7110
diff changeset
2454
67f9b43c402a [gaim-migrate @ 7701]
Sean Egan <seanegan@gmail.com>
parents: 7110
diff changeset
2455 /*
67f9b43c402a [gaim-migrate @ 7701]
Sean Egan <seanegan@gmail.com>
parents: 7110
diff changeset
2456 * Now it's at the end and at the start of the for loop
67f9b43c402a [gaim-migrate @ 7701]
Sean Egan <seanegan@gmail.com>
parents: 7110
diff changeset
2457 * will be at the next character.
67f9b43c402a [gaim-migrate @ 7701]
Sean Egan <seanegan@gmail.com>
parents: 7110
diff changeset
2458 */
67f9b43c402a [gaim-migrate @ 7701]
Sean Egan <seanegan@gmail.com>
parents: 7110
diff changeset
2459 buf[j++] = strtol(hex, NULL, 16);
67f9b43c402a [gaim-migrate @ 7701]
Sean Egan <seanegan@gmail.com>
parents: 7110
diff changeset
2460 }
67f9b43c402a [gaim-migrate @ 7701]
Sean Egan <seanegan@gmail.com>
parents: 7110
diff changeset
2461 }
67f9b43c402a [gaim-migrate @ 7701]
Sean Egan <seanegan@gmail.com>
parents: 7110
diff changeset
2462
67f9b43c402a [gaim-migrate @ 7701]
Sean Egan <seanegan@gmail.com>
parents: 7110
diff changeset
2463 buf[j] = '\0';
67f9b43c402a [gaim-migrate @ 7701]
Sean Egan <seanegan@gmail.com>
parents: 7110
diff changeset
2464
67f9b43c402a [gaim-migrate @ 7701]
Sean Egan <seanegan@gmail.com>
parents: 7110
diff changeset
2465 if (!g_utf8_validate(buf, -1, (const char **)&bum))
67f9b43c402a [gaim-migrate @ 7701]
Sean Egan <seanegan@gmail.com>
parents: 7110
diff changeset
2466 *bum = '\0';
67f9b43c402a [gaim-migrate @ 7701]
Sean Egan <seanegan@gmail.com>
parents: 7110
diff changeset
2467
67f9b43c402a [gaim-migrate @ 7701]
Sean Egan <seanegan@gmail.com>
parents: 7110
diff changeset
2468 return buf;
67f9b43c402a [gaim-migrate @ 7701]
Sean Egan <seanegan@gmail.com>
parents: 7110
diff changeset
2469 }
67f9b43c402a [gaim-migrate @ 7701]
Sean Egan <seanegan@gmail.com>
parents: 7110
diff changeset
2470
7162
d14e026611c0 [gaim-migrate @ 7729]
Nathan Walp <nwalp@pidgin.im>
parents: 7134
diff changeset
2471 const char *
7134
67f9b43c402a [gaim-migrate @ 7701]
Sean Egan <seanegan@gmail.com>
parents: 7110
diff changeset
2472 gaim_url_encode(const char *str)
67f9b43c402a [gaim-migrate @ 7701]
Sean Egan <seanegan@gmail.com>
parents: 7110
diff changeset
2473 {
67f9b43c402a [gaim-migrate @ 7701]
Sean Egan <seanegan@gmail.com>
parents: 7110
diff changeset
2474 static char buf[BUF_LEN];
7631
ea2d07ad05a9 [gaim-migrate @ 8255]
Nathan Walp <nwalp@pidgin.im>
parents: 7628
diff changeset
2475 guint i, j = 0;
7134
67f9b43c402a [gaim-migrate @ 7701]
Sean Egan <seanegan@gmail.com>
parents: 7110
diff changeset
2476
67f9b43c402a [gaim-migrate @ 7701]
Sean Egan <seanegan@gmail.com>
parents: 7110
diff changeset
2477 g_return_val_if_fail(str != NULL, NULL);
67f9b43c402a [gaim-migrate @ 7701]
Sean Egan <seanegan@gmail.com>
parents: 7110
diff changeset
2478
67f9b43c402a [gaim-migrate @ 7701]
Sean Egan <seanegan@gmail.com>
parents: 7110
diff changeset
2479 for (i = 0; i < strlen(str); i++) {
67f9b43c402a [gaim-migrate @ 7701]
Sean Egan <seanegan@gmail.com>
parents: 7110
diff changeset
2480 if (isalnum(str[i]))
67f9b43c402a [gaim-migrate @ 7701]
Sean Egan <seanegan@gmail.com>
parents: 7110
diff changeset
2481 buf[j++] = str[i];
67f9b43c402a [gaim-migrate @ 7701]
Sean Egan <seanegan@gmail.com>
parents: 7110
diff changeset
2482 else {
67f9b43c402a [gaim-migrate @ 7701]
Sean Egan <seanegan@gmail.com>
parents: 7110
diff changeset
2483 sprintf(buf + j, "%%%02x", (unsigned char)str[i]);
67f9b43c402a [gaim-migrate @ 7701]
Sean Egan <seanegan@gmail.com>
parents: 7110
diff changeset
2484 j += 3;
67f9b43c402a [gaim-migrate @ 7701]
Sean Egan <seanegan@gmail.com>
parents: 7110
diff changeset
2485 }
67f9b43c402a [gaim-migrate @ 7701]
Sean Egan <seanegan@gmail.com>
parents: 7110
diff changeset
2486 }
67f9b43c402a [gaim-migrate @ 7701]
Sean Egan <seanegan@gmail.com>
parents: 7110
diff changeset
2487
67f9b43c402a [gaim-migrate @ 7701]
Sean Egan <seanegan@gmail.com>
parents: 7110
diff changeset
2488 buf[j] = '\0';
67f9b43c402a [gaim-migrate @ 7701]
Sean Egan <seanegan@gmail.com>
parents: 7110
diff changeset
2489
67f9b43c402a [gaim-migrate @ 7701]
Sean Egan <seanegan@gmail.com>
parents: 7110
diff changeset
2490 return buf;
67f9b43c402a [gaim-migrate @ 7701]
Sean Egan <seanegan@gmail.com>
parents: 7110
diff changeset
2491 }
7108
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2492
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2493 /**************************************************************************
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2494 * UTF8 String Functions
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2495 **************************************************************************/
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2496 char *
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2497 gaim_utf8_try_convert(const char *str)
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2498 {
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2499 gsize converted;
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2500 char *utf8;
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2501
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2502 g_return_val_if_fail(str != NULL, NULL);
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 if (g_utf8_validate(str, -1, NULL)) {
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2505 return g_strdup(str);
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2506 }
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2507
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2508 utf8 = g_locale_to_utf8(str, -1, &converted, NULL, NULL);
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2509 if (utf8)
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2510 return(utf8);
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2511
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2512 g_free(utf8);
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2513
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2514 utf8 = g_convert(str, -1, "UTF-8", "ISO-8859-15", &converted, NULL, NULL);
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2515 if (utf8 && converted == strlen (str)) {
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2516 return(utf8);
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2517 } else if (utf8) {
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2518 g_free(utf8);
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2519 }
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 return(NULL);
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2522 }
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2523
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2524 int
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2525 gaim_utf8_strcasecmp(const char *a, const char *b)
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 char *a_norm = NULL;
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2528 char *b_norm = NULL;
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2529 int ret = -1;
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2530
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2531 if(!a && b)
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2532 return -1;
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2533 else if(!b && a)
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2534 return 1;
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2535 else if(!a && !b)
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2536 return 0;
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 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
2539 {
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2540 gaim_debug_error("gaim_utf8_strcasecmp",
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2541 "One or both parameters are invalid UTF8\n");
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2542 return ret;
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2543 }
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2544
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2545 a_norm = g_utf8_casefold(a, -1);
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2546 b_norm = g_utf8_casefold(b, -1);
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2547 ret = g_utf8_collate(a_norm, b_norm);
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2548 g_free(a_norm);
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2549 g_free(b_norm);
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2550
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2551 return ret;
6faeeecab0dc [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
2552 }
7162
d14e026611c0 [gaim-migrate @ 7729]
Nathan Walp <nwalp@pidgin.im>
parents: 7134
diff changeset
2553
7564
54b370f7d9bf [gaim-migrate @ 8180]
Nathan Walp <nwalp@pidgin.im>
parents: 7478
diff changeset
2554 gboolean gaim_message_meify(char *message, size_t len)
54b370f7d9bf [gaim-migrate @ 8180]
Nathan Walp <nwalp@pidgin.im>
parents: 7478
diff changeset
2555 {
54b370f7d9bf [gaim-migrate @ 8180]
Nathan Walp <nwalp@pidgin.im>
parents: 7478
diff changeset
2556 char *c;
54b370f7d9bf [gaim-migrate @ 8180]
Nathan Walp <nwalp@pidgin.im>
parents: 7478
diff changeset
2557 gboolean inside_html = FALSE;
54b370f7d9bf [gaim-migrate @ 8180]
Nathan Walp <nwalp@pidgin.im>
parents: 7478
diff changeset
2558
54b370f7d9bf [gaim-migrate @ 8180]
Nathan Walp <nwalp@pidgin.im>
parents: 7478
diff changeset
2559 g_return_val_if_fail(message != NULL, FALSE);
54b370f7d9bf [gaim-migrate @ 8180]
Nathan Walp <nwalp@pidgin.im>
parents: 7478
diff changeset
2560
54b370f7d9bf [gaim-migrate @ 8180]
Nathan Walp <nwalp@pidgin.im>
parents: 7478
diff changeset
2561 if(len == -1)
54b370f7d9bf [gaim-migrate @ 8180]
Nathan Walp <nwalp@pidgin.im>
parents: 7478
diff changeset
2562 len = strlen(message);
54b370f7d9bf [gaim-migrate @ 8180]
Nathan Walp <nwalp@pidgin.im>
parents: 7478
diff changeset
2563
54b370f7d9bf [gaim-migrate @ 8180]
Nathan Walp <nwalp@pidgin.im>
parents: 7478
diff changeset
2564 for (c = message; *c; c++, len--) {
54b370f7d9bf [gaim-migrate @ 8180]
Nathan Walp <nwalp@pidgin.im>
parents: 7478
diff changeset
2565 if(inside_html) {
54b370f7d9bf [gaim-migrate @ 8180]
Nathan Walp <nwalp@pidgin.im>
parents: 7478
diff changeset
2566 if(*c == '>')
54b370f7d9bf [gaim-migrate @ 8180]
Nathan Walp <nwalp@pidgin.im>
parents: 7478
diff changeset
2567 inside_html = FALSE;
54b370f7d9bf [gaim-migrate @ 8180]
Nathan Walp <nwalp@pidgin.im>
parents: 7478
diff changeset
2568 } else {
54b370f7d9bf [gaim-migrate @ 8180]
Nathan Walp <nwalp@pidgin.im>
parents: 7478
diff changeset
2569 if(*c == '<')
54b370f7d9bf [gaim-migrate @ 8180]
Nathan Walp <nwalp@pidgin.im>
parents: 7478
diff changeset
2570 inside_html = TRUE;
54b370f7d9bf [gaim-migrate @ 8180]
Nathan Walp <nwalp@pidgin.im>
parents: 7478
diff changeset
2571 else
54b370f7d9bf [gaim-migrate @ 8180]
Nathan Walp <nwalp@pidgin.im>
parents: 7478
diff changeset
2572 break;
54b370f7d9bf [gaim-migrate @ 8180]
Nathan Walp <nwalp@pidgin.im>
parents: 7478
diff changeset
2573 }
54b370f7d9bf [gaim-migrate @ 8180]
Nathan Walp <nwalp@pidgin.im>
parents: 7478
diff changeset
2574 }
54b370f7d9bf [gaim-migrate @ 8180]
Nathan Walp <nwalp@pidgin.im>
parents: 7478
diff changeset
2575
54b370f7d9bf [gaim-migrate @ 8180]
Nathan Walp <nwalp@pidgin.im>
parents: 7478
diff changeset
2576 if(*c && !g_ascii_strncasecmp(c, "/me ", 4)) {
54b370f7d9bf [gaim-migrate @ 8180]
Nathan Walp <nwalp@pidgin.im>
parents: 7478
diff changeset
2577 memmove(c, c+4, len-3);
54b370f7d9bf [gaim-migrate @ 8180]
Nathan Walp <nwalp@pidgin.im>
parents: 7478
diff changeset
2578 return TRUE;
54b370f7d9bf [gaim-migrate @ 8180]
Nathan Walp <nwalp@pidgin.im>
parents: 7478
diff changeset
2579 }
54b370f7d9bf [gaim-migrate @ 8180]
Nathan Walp <nwalp@pidgin.im>
parents: 7478
diff changeset
2580
54b370f7d9bf [gaim-migrate @ 8180]
Nathan Walp <nwalp@pidgin.im>
parents: 7478
diff changeset
2581 return FALSE;
54b370f7d9bf [gaim-migrate @ 8180]
Nathan Walp <nwalp@pidgin.im>
parents: 7478
diff changeset
2582 }
54b370f7d9bf [gaim-migrate @ 8180]
Nathan Walp <nwalp@pidgin.im>
parents: 7478
diff changeset
2583
7889
7e1bb4deca24 [gaim-migrate @ 8547]
Nathan Walp <nwalp@pidgin.im>
parents: 7858
diff changeset
2584 char *gaim_text_strip_mnemonic(const char *in)
7e1bb4deca24 [gaim-migrate @ 8547]
Nathan Walp <nwalp@pidgin.im>
parents: 7858
diff changeset
2585 {
7e1bb4deca24 [gaim-migrate @ 8547]
Nathan Walp <nwalp@pidgin.im>
parents: 7858
diff changeset
2586 char *out;
7e1bb4deca24 [gaim-migrate @ 8547]
Nathan Walp <nwalp@pidgin.im>
parents: 7858
diff changeset
2587 char *a;
8561
2d4ccd94e298 [gaim-migrate @ 9305]
Luke Schierer <lschiere@pidgin.im>
parents: 8538
diff changeset
2588 char *a0;
7889
7e1bb4deca24 [gaim-migrate @ 8547]
Nathan Walp <nwalp@pidgin.im>
parents: 7858
diff changeset
2589 const char *b;
7e1bb4deca24 [gaim-migrate @ 8547]
Nathan Walp <nwalp@pidgin.im>
parents: 7858
diff changeset
2590
7e1bb4deca24 [gaim-migrate @ 8547]
Nathan Walp <nwalp@pidgin.im>
parents: 7858
diff changeset
2591 g_return_val_if_fail(in != NULL, NULL);
7e1bb4deca24 [gaim-migrate @ 8547]
Nathan Walp <nwalp@pidgin.im>
parents: 7858
diff changeset
2592
7e1bb4deca24 [gaim-migrate @ 8547]
Nathan Walp <nwalp@pidgin.im>
parents: 7858
diff changeset
2593 out = g_malloc(strlen(in)+1);
7e1bb4deca24 [gaim-migrate @ 8547]
Nathan Walp <nwalp@pidgin.im>
parents: 7858
diff changeset
2594 a = out;
7e1bb4deca24 [gaim-migrate @ 8547]
Nathan Walp <nwalp@pidgin.im>
parents: 7858
diff changeset
2595 b = in;
7e1bb4deca24 [gaim-migrate @ 8547]
Nathan Walp <nwalp@pidgin.im>
parents: 7858
diff changeset
2596
8561
2d4ccd94e298 [gaim-migrate @ 9305]
Luke Schierer <lschiere@pidgin.im>
parents: 8538
diff changeset
2597 a0 = a; /* The last non-space char seen so far, or the first char */
2d4ccd94e298 [gaim-migrate @ 9305]
Luke Schierer <lschiere@pidgin.im>
parents: 8538
diff changeset
2598
7889
7e1bb4deca24 [gaim-migrate @ 8547]
Nathan Walp <nwalp@pidgin.im>
parents: 7858
diff changeset
2599 while(*b) {
7e1bb4deca24 [gaim-migrate @ 8547]
Nathan Walp <nwalp@pidgin.im>
parents: 7858
diff changeset
2600 if(*b == '_') {
8561
2d4ccd94e298 [gaim-migrate @ 9305]
Luke Schierer <lschiere@pidgin.im>
parents: 8538
diff changeset
2601 if(a > out && b > in && *(b-1) == '(' && *(b+1) && !(*(b+1) & 0x80) && *(b+2) == ')') {
2d4ccd94e298 [gaim-migrate @ 9305]
Luke Schierer <lschiere@pidgin.im>
parents: 8538
diff changeset
2602 /* Detected CJK style shortcut (Bug 875311) */
2d4ccd94e298 [gaim-migrate @ 9305]
Luke Schierer <lschiere@pidgin.im>
parents: 8538
diff changeset
2603 a = a0; /* undo the left parenthesis */
2d4ccd94e298 [gaim-migrate @ 9305]
Luke Schierer <lschiere@pidgin.im>
parents: 8538
diff changeset
2604 b += 3; /* and skip the whole mess */
2d4ccd94e298 [gaim-migrate @ 9305]
Luke Schierer <lschiere@pidgin.im>
parents: 8538
diff changeset
2605 } else if(*(b+1) == '_') {
7889
7e1bb4deca24 [gaim-migrate @ 8547]
Nathan Walp <nwalp@pidgin.im>
parents: 7858
diff changeset
2606 *(a++) = '_';
7e1bb4deca24 [gaim-migrate @ 8547]
Nathan Walp <nwalp@pidgin.im>
parents: 7858
diff changeset
2607 b += 2;
8561
2d4ccd94e298 [gaim-migrate @ 9305]
Luke Schierer <lschiere@pidgin.im>
parents: 8538
diff changeset
2608 a0 = a;
7889
7e1bb4deca24 [gaim-migrate @ 8547]
Nathan Walp <nwalp@pidgin.im>
parents: 7858
diff changeset
2609 } else {
7e1bb4deca24 [gaim-migrate @ 8547]
Nathan Walp <nwalp@pidgin.im>
parents: 7858
diff changeset
2610 b++;
7e1bb4deca24 [gaim-migrate @ 8547]
Nathan Walp <nwalp@pidgin.im>
parents: 7858
diff changeset
2611 }
8561
2d4ccd94e298 [gaim-migrate @ 9305]
Luke Schierer <lschiere@pidgin.im>
parents: 8538
diff changeset
2612 /* We don't want to corrupt the middle of UTF-8 characters */
2d4ccd94e298 [gaim-migrate @ 9305]
Luke Schierer <lschiere@pidgin.im>
parents: 8538
diff changeset
2613 } else if (!(*b & 0x80)) { /* other 1-byte char */
2d4ccd94e298 [gaim-migrate @ 9305]
Luke Schierer <lschiere@pidgin.im>
parents: 8538
diff changeset
2614 if (*b != ' ')
2d4ccd94e298 [gaim-migrate @ 9305]
Luke Schierer <lschiere@pidgin.im>
parents: 8538
diff changeset
2615 a0 = a;
2d4ccd94e298 [gaim-migrate @ 9305]
Luke Schierer <lschiere@pidgin.im>
parents: 8538
diff changeset
2616 *(a++) = *(b++);
7889
7e1bb4deca24 [gaim-migrate @ 8547]
Nathan Walp <nwalp@pidgin.im>
parents: 7858
diff changeset
2617 } else {
8561
2d4ccd94e298 [gaim-migrate @ 9305]
Luke Schierer <lschiere@pidgin.im>
parents: 8538
diff changeset
2618 /* Multibyte utf8 char, don't look for _ inside these */
2d4ccd94e298 [gaim-migrate @ 9305]
Luke Schierer <lschiere@pidgin.im>
parents: 8538
diff changeset
2619 int n = 0;
2d4ccd94e298 [gaim-migrate @ 9305]
Luke Schierer <lschiere@pidgin.im>
parents: 8538
diff changeset
2620 int i;
2d4ccd94e298 [gaim-migrate @ 9305]
Luke Schierer <lschiere@pidgin.im>
parents: 8538
diff changeset
2621 if ((*b & 0xe0) == 0xc0) {
2d4ccd94e298 [gaim-migrate @ 9305]
Luke Schierer <lschiere@pidgin.im>
parents: 8538
diff changeset
2622 n = 2;
2d4ccd94e298 [gaim-migrate @ 9305]
Luke Schierer <lschiere@pidgin.im>
parents: 8538
diff changeset
2623 } else if ((*b & 0xf0) == 0xe0) {
2d4ccd94e298 [gaim-migrate @ 9305]
Luke Schierer <lschiere@pidgin.im>
parents: 8538
diff changeset
2624 n = 3;
2d4ccd94e298 [gaim-migrate @ 9305]
Luke Schierer <lschiere@pidgin.im>
parents: 8538
diff changeset
2625 } else if ((*b & 0xf8) == 0xf0) {
2d4ccd94e298 [gaim-migrate @ 9305]
Luke Schierer <lschiere@pidgin.im>
parents: 8538
diff changeset
2626 n = 4;
2d4ccd94e298 [gaim-migrate @ 9305]
Luke Schierer <lschiere@pidgin.im>
parents: 8538
diff changeset
2627 } else if ((*b & 0xfc) == 0xf8) {
2d4ccd94e298 [gaim-migrate @ 9305]
Luke Schierer <lschiere@pidgin.im>
parents: 8538
diff changeset
2628 n = 5;
2d4ccd94e298 [gaim-migrate @ 9305]
Luke Schierer <lschiere@pidgin.im>
parents: 8538
diff changeset
2629 } else if ((*b & 0xfe) == 0xfc) {
2d4ccd94e298 [gaim-migrate @ 9305]
Luke Schierer <lschiere@pidgin.im>
parents: 8538
diff changeset
2630 n = 6;
2d4ccd94e298 [gaim-migrate @ 9305]
Luke Schierer <lschiere@pidgin.im>
parents: 8538
diff changeset
2631 } else { /* Illegal utf8 */
2d4ccd94e298 [gaim-migrate @ 9305]
Luke Schierer <lschiere@pidgin.im>
parents: 8538
diff changeset
2632 n = 1;
2d4ccd94e298 [gaim-migrate @ 9305]
Luke Schierer <lschiere@pidgin.im>
parents: 8538
diff changeset
2633 }
2d4ccd94e298 [gaim-migrate @ 9305]
Luke Schierer <lschiere@pidgin.im>
parents: 8538
diff changeset
2634 a0 = a; /* unless we want to delete CJK spaces too */
2d4ccd94e298 [gaim-migrate @ 9305]
Luke Schierer <lschiere@pidgin.im>
parents: 8538
diff changeset
2635 for (i = 0; i < n && *b; i += 1) {
2d4ccd94e298 [gaim-migrate @ 9305]
Luke Schierer <lschiere@pidgin.im>
parents: 8538
diff changeset
2636 *(a++) = *(b++);
2d4ccd94e298 [gaim-migrate @ 9305]
Luke Schierer <lschiere@pidgin.im>
parents: 8538
diff changeset
2637 }
7889
7e1bb4deca24 [gaim-migrate @ 8547]
Nathan Walp <nwalp@pidgin.im>
parents: 7858
diff changeset
2638 }
7e1bb4deca24 [gaim-migrate @ 8547]
Nathan Walp <nwalp@pidgin.im>
parents: 7858
diff changeset
2639 }
7e1bb4deca24 [gaim-migrate @ 8547]
Nathan Walp <nwalp@pidgin.im>
parents: 7858
diff changeset
2640 *a = '\0';
7e1bb4deca24 [gaim-migrate @ 8547]
Nathan Walp <nwalp@pidgin.im>
parents: 7858
diff changeset
2641
7e1bb4deca24 [gaim-migrate @ 8547]
Nathan Walp <nwalp@pidgin.im>
parents: 7858
diff changeset
2642 return out;
7e1bb4deca24 [gaim-migrate @ 8547]
Nathan Walp <nwalp@pidgin.im>
parents: 7858
diff changeset
2643 }
7e1bb4deca24 [gaim-migrate @ 8547]
Nathan Walp <nwalp@pidgin.im>
parents: 7858
diff changeset
2644