Sat, 25 Jul 2009 20:46:43 +0000
propagate from branch 'im.pidgin.pidgin' (head 212f39e443597406af0718671dfa7109d107f89b)
to branch 'im.pidgin.cpw.qulogic.gtk3' (head 482df00eccd3706575f8852f61d528020b045db0)
| 6513 | 1 | /* |
| 15884 | 2 | * purple |
| 6513 | 3 | * |
| 4 | * Some code copyright 2003 Tim Ringenbach <omarvo@hotmail.com> | |
| 5 | * (marv on irc.freenode.net) | |
| 6 | * | |
| 7 | * This program is free software; you can redistribute it and/or modify | |
| 8 | * it under the terms of the GNU General Public License as published by | |
| 9 | * the Free Software Foundation; either version 2 of the License, or | |
| 10 | * (at your option) any later version. | |
| 11 | * | |
| 12 | * This program is distributed in the hope that it will be useful, | |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 15 | * GNU General Public License for more details. | |
| 16 | * | |
| 17 | * You should have received a copy of the GNU General Public License | |
| 18 | * along with this program; if not, write to the Free Software | |
|
19859
71d37b57eff2
The FSF changed its address a while ago; our files were out of date.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
19337
diff
changeset
|
19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
| 6513 | 20 | * |
| 21 | */ | |
| 22 | ||
| 23 | #ifdef HAVE_CONFIG_H | |
| 24 | #include "config.h" | |
|
27335
06a805d4e690
Strip trailing whitespace and comment #endif marcos that close #ifdef macros
Mark Doliner <markdoliner@pidgin.im>
parents:
24181
diff
changeset
|
25 | #endif /* HAVE_CONFIG_H */ |
| 6513 | 26 | |
|
10023
6b0014040323
[gaim-migrate @ 10955]
Mark Doliner <markdoliner@pidgin.im>
parents:
9164
diff
changeset
|
27 | #include "debug.h" |
|
6b0014040323
[gaim-migrate @ 10955]
Mark Doliner <markdoliner@pidgin.im>
parents:
9164
diff
changeset
|
28 | #include "internal.h" |
| 6513 | 29 | #include "prpl.h" |
|
10023
6b0014040323
[gaim-migrate @ 10955]
Mark Doliner <markdoliner@pidgin.im>
parents:
9164
diff
changeset
|
30 | |
|
27555
afb7cb5c350c
Update for file renames.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
27547
diff
changeset
|
31 | #include "libymsg.h" |
| 6513 | 32 | |
|
6546
6a14dfe43d5c
[gaim-migrate @ 7068]
Mark Doliner <markdoliner@pidgin.im>
parents:
6513
diff
changeset
|
33 | #include <string.h> |
|
24181
e028e31dcc67
Do a better job of detecting if the yahoo account is connecting through a HTTP
Daniel Atallah <datallah@pidgin.im>
parents:
23173
diff
changeset
|
34 | |
|
e028e31dcc67
Do a better job of detecting if the yahoo account is connecting through a HTTP
Daniel Atallah <datallah@pidgin.im>
parents:
23173
diff
changeset
|
35 | gboolean |
|
e028e31dcc67
Do a better job of detecting if the yahoo account is connecting through a HTTP
Daniel Atallah <datallah@pidgin.im>
parents:
23173
diff
changeset
|
36 | yahoo_account_use_http_proxy(PurpleConnection *conn) |
|
e028e31dcc67
Do a better job of detecting if the yahoo account is connecting through a HTTP
Daniel Atallah <datallah@pidgin.im>
parents:
23173
diff
changeset
|
37 | { |
|
e028e31dcc67
Do a better job of detecting if the yahoo account is connecting through a HTTP
Daniel Atallah <datallah@pidgin.im>
parents:
23173
diff
changeset
|
38 | PurpleProxyInfo *ppi = purple_proxy_get_setup(conn->account); |
|
e028e31dcc67
Do a better job of detecting if the yahoo account is connecting through a HTTP
Daniel Atallah <datallah@pidgin.im>
parents:
23173
diff
changeset
|
39 | return (ppi->type == PURPLE_PROXY_HTTP || ppi->type == PURPLE_PROXY_USE_ENVVAR); |
|
e028e31dcc67
Do a better job of detecting if the yahoo account is connecting through a HTTP
Daniel Atallah <datallah@pidgin.im>
parents:
23173
diff
changeset
|
40 | } |
|
e028e31dcc67
Do a better job of detecting if the yahoo account is connecting through a HTTP
Daniel Atallah <datallah@pidgin.im>
parents:
23173
diff
changeset
|
41 | |
|
22202
e42ab2e3eba1
This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan Sankaranarayanan <madthanu@gmail.com>
parents:
21946
diff
changeset
|
42 | /* |
|
e42ab2e3eba1
This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan Sankaranarayanan <madthanu@gmail.com>
parents:
21946
diff
changeset
|
43 | * Returns cookies formatted as a null terminated string for the given connection. |
|
e42ab2e3eba1
This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan Sankaranarayanan <madthanu@gmail.com>
parents:
21946
diff
changeset
|
44 | * Must g_free return value. |
|
27335
06a805d4e690
Strip trailing whitespace and comment #endif marcos that close #ifdef macros
Mark Doliner <markdoliner@pidgin.im>
parents:
24181
diff
changeset
|
45 | * |
|
22202
e42ab2e3eba1
This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan Sankaranarayanan <madthanu@gmail.com>
parents:
21946
diff
changeset
|
46 | * TODO:will work, but must test for strict correctness |
|
e42ab2e3eba1
This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan Sankaranarayanan <madthanu@gmail.com>
parents:
21946
diff
changeset
|
47 | */ |
|
e42ab2e3eba1
This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan Sankaranarayanan <madthanu@gmail.com>
parents:
21946
diff
changeset
|
48 | gchar* yahoo_get_cookies(PurpleConnection *gc) |
|
e42ab2e3eba1
This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan Sankaranarayanan <madthanu@gmail.com>
parents:
21946
diff
changeset
|
49 | { |
|
e42ab2e3eba1
This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan Sankaranarayanan <madthanu@gmail.com>
parents:
21946
diff
changeset
|
50 | gchar *ans = NULL; |
|
e42ab2e3eba1
This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan Sankaranarayanan <madthanu@gmail.com>
parents:
21946
diff
changeset
|
51 | gchar *cur; |
|
e42ab2e3eba1
This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan Sankaranarayanan <madthanu@gmail.com>
parents:
21946
diff
changeset
|
52 | char firstflag = 1; |
|
e42ab2e3eba1
This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan Sankaranarayanan <madthanu@gmail.com>
parents:
21946
diff
changeset
|
53 | gchar *t1,*t2,*t3; |
|
e42ab2e3eba1
This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan Sankaranarayanan <madthanu@gmail.com>
parents:
21946
diff
changeset
|
54 | GSList *tmp; |
|
e42ab2e3eba1
This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan Sankaranarayanan <madthanu@gmail.com>
parents:
21946
diff
changeset
|
55 | GSList *cookies; |
|
e42ab2e3eba1
This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan Sankaranarayanan <madthanu@gmail.com>
parents:
21946
diff
changeset
|
56 | cookies = ((struct yahoo_data*)(gc->proto_data))->cookies; |
|
e42ab2e3eba1
This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan Sankaranarayanan <madthanu@gmail.com>
parents:
21946
diff
changeset
|
57 | tmp = cookies; |
|
e42ab2e3eba1
This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan Sankaranarayanan <madthanu@gmail.com>
parents:
21946
diff
changeset
|
58 | while(tmp) |
|
e42ab2e3eba1
This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan Sankaranarayanan <madthanu@gmail.com>
parents:
21946
diff
changeset
|
59 | { |
|
e42ab2e3eba1
This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan Sankaranarayanan <madthanu@gmail.com>
parents:
21946
diff
changeset
|
60 | cur = tmp->data; |
|
e42ab2e3eba1
This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan Sankaranarayanan <madthanu@gmail.com>
parents:
21946
diff
changeset
|
61 | t1 = ans; |
|
e42ab2e3eba1
This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan Sankaranarayanan <madthanu@gmail.com>
parents:
21946
diff
changeset
|
62 | t2 = g_strrstr(cur, ";expires="); |
|
e42ab2e3eba1
This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan Sankaranarayanan <madthanu@gmail.com>
parents:
21946
diff
changeset
|
63 | if(t2 == NULL) |
|
e42ab2e3eba1
This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan Sankaranarayanan <madthanu@gmail.com>
parents:
21946
diff
changeset
|
64 | t2 = g_strrstr(cur, "; expires="); |
|
e42ab2e3eba1
This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan Sankaranarayanan <madthanu@gmail.com>
parents:
21946
diff
changeset
|
65 | if(t2 == NULL) |
|
e42ab2e3eba1
This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan Sankaranarayanan <madthanu@gmail.com>
parents:
21946
diff
changeset
|
66 | { |
|
e42ab2e3eba1
This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan Sankaranarayanan <madthanu@gmail.com>
parents:
21946
diff
changeset
|
67 | if(firstflag) |
|
e42ab2e3eba1
This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan Sankaranarayanan <madthanu@gmail.com>
parents:
21946
diff
changeset
|
68 | ans = g_strdup_printf("%c=%s", cur[0], cur+2); |
|
e42ab2e3eba1
This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan Sankaranarayanan <madthanu@gmail.com>
parents:
21946
diff
changeset
|
69 | else |
|
e42ab2e3eba1
This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan Sankaranarayanan <madthanu@gmail.com>
parents:
21946
diff
changeset
|
70 | ans = g_strdup_printf("%s; %c=%s", t1, cur[0], cur+2); |
|
e42ab2e3eba1
This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan Sankaranarayanan <madthanu@gmail.com>
parents:
21946
diff
changeset
|
71 | } |
|
e42ab2e3eba1
This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan Sankaranarayanan <madthanu@gmail.com>
parents:
21946
diff
changeset
|
72 | else |
|
e42ab2e3eba1
This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan Sankaranarayanan <madthanu@gmail.com>
parents:
21946
diff
changeset
|
73 | { |
|
e42ab2e3eba1
This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan Sankaranarayanan <madthanu@gmail.com>
parents:
21946
diff
changeset
|
74 | t3 = strstr(t2+1, ";"); |
|
e42ab2e3eba1
This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan Sankaranarayanan <madthanu@gmail.com>
parents:
21946
diff
changeset
|
75 | if(t3 != NULL) |
|
e42ab2e3eba1
This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan Sankaranarayanan <madthanu@gmail.com>
parents:
21946
diff
changeset
|
76 | { |
|
e42ab2e3eba1
This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan Sankaranarayanan <madthanu@gmail.com>
parents:
21946
diff
changeset
|
77 | t2[0] = '\0'; |
|
e42ab2e3eba1
This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan Sankaranarayanan <madthanu@gmail.com>
parents:
21946
diff
changeset
|
78 | |
|
e42ab2e3eba1
This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan Sankaranarayanan <madthanu@gmail.com>
parents:
21946
diff
changeset
|
79 | if(firstflag) |
|
e42ab2e3eba1
This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan Sankaranarayanan <madthanu@gmail.com>
parents:
21946
diff
changeset
|
80 | ans = g_strdup_printf("%c=%s%s", cur[0], cur+2, t3); |
|
e42ab2e3eba1
This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan Sankaranarayanan <madthanu@gmail.com>
parents:
21946
diff
changeset
|
81 | else |
|
e42ab2e3eba1
This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan Sankaranarayanan <madthanu@gmail.com>
parents:
21946
diff
changeset
|
82 | ans = g_strdup_printf("%s; %c=%s%s", t1, cur[0], cur+2, t3); |
|
e42ab2e3eba1
This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan Sankaranarayanan <madthanu@gmail.com>
parents:
21946
diff
changeset
|
83 | |
|
e42ab2e3eba1
This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan Sankaranarayanan <madthanu@gmail.com>
parents:
21946
diff
changeset
|
84 | t2[0] = ';'; |
|
e42ab2e3eba1
This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan Sankaranarayanan <madthanu@gmail.com>
parents:
21946
diff
changeset
|
85 | } |
|
e42ab2e3eba1
This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan Sankaranarayanan <madthanu@gmail.com>
parents:
21946
diff
changeset
|
86 | else |
|
e42ab2e3eba1
This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan Sankaranarayanan <madthanu@gmail.com>
parents:
21946
diff
changeset
|
87 | { |
|
e42ab2e3eba1
This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan Sankaranarayanan <madthanu@gmail.com>
parents:
21946
diff
changeset
|
88 | t2[0] = '\0'; |
|
e42ab2e3eba1
This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan Sankaranarayanan <madthanu@gmail.com>
parents:
21946
diff
changeset
|
89 | |
|
e42ab2e3eba1
This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan Sankaranarayanan <madthanu@gmail.com>
parents:
21946
diff
changeset
|
90 | if(firstflag) |
|
e42ab2e3eba1
This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan Sankaranarayanan <madthanu@gmail.com>
parents:
21946
diff
changeset
|
91 | ans = g_strdup_printf("%c=%s", cur[0], cur+2); |
|
e42ab2e3eba1
This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan Sankaranarayanan <madthanu@gmail.com>
parents:
21946
diff
changeset
|
92 | else |
|
e42ab2e3eba1
This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan Sankaranarayanan <madthanu@gmail.com>
parents:
21946
diff
changeset
|
93 | ans = g_strdup_printf("%s; %c=%s", t1, cur[0], cur+2); |
|
e42ab2e3eba1
This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan Sankaranarayanan <madthanu@gmail.com>
parents:
21946
diff
changeset
|
94 | |
|
e42ab2e3eba1
This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan Sankaranarayanan <madthanu@gmail.com>
parents:
21946
diff
changeset
|
95 | t2[0] = ';'; |
|
e42ab2e3eba1
This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan Sankaranarayanan <madthanu@gmail.com>
parents:
21946
diff
changeset
|
96 | } |
|
e42ab2e3eba1
This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan Sankaranarayanan <madthanu@gmail.com>
parents:
21946
diff
changeset
|
97 | } |
|
e42ab2e3eba1
This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan Sankaranarayanan <madthanu@gmail.com>
parents:
21946
diff
changeset
|
98 | if(firstflag) |
|
e42ab2e3eba1
This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan Sankaranarayanan <madthanu@gmail.com>
parents:
21946
diff
changeset
|
99 | firstflag = 0; |
|
e42ab2e3eba1
This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan Sankaranarayanan <madthanu@gmail.com>
parents:
21946
diff
changeset
|
100 | else |
|
e42ab2e3eba1
This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan Sankaranarayanan <madthanu@gmail.com>
parents:
21946
diff
changeset
|
101 | g_free(t1); |
|
e42ab2e3eba1
This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan Sankaranarayanan <madthanu@gmail.com>
parents:
21946
diff
changeset
|
102 | tmp = g_slist_next(tmp); |
|
e42ab2e3eba1
This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan Sankaranarayanan <madthanu@gmail.com>
parents:
21946
diff
changeset
|
103 | } |
|
e42ab2e3eba1
This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan Sankaranarayanan <madthanu@gmail.com>
parents:
21946
diff
changeset
|
104 | return ans; |
|
e42ab2e3eba1
This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan Sankaranarayanan <madthanu@gmail.com>
parents:
21946
diff
changeset
|
105 | } |
|
6546
6a14dfe43d5c
[gaim-migrate @ 7068]
Mark Doliner <markdoliner@pidgin.im>
parents:
6513
diff
changeset
|
106 | |
| 7827 | 107 | /** |
| 108 | * Encode some text to send to the yahoo server. | |
| 109 | * | |
| 110 | * @param gc The connection handle. | |
| 111 | * @param str The null terminated utf8 string to encode. | |
| 112 | * @param utf8 If not @c NULL, whether utf8 is okay or not. | |
| 113 | * Even if it is okay, we may not use it. If we | |
| 114 | * used it, we set this to @c TRUE, else to | |
| 115 | * @c FALSE. If @c NULL, false is assumed, and | |
| 116 | * it is not dereferenced. | |
| 117 | * @return The g_malloced string in the appropriate encoding. | |
| 118 | */ | |
| 15884 | 119 | char *yahoo_string_encode(PurpleConnection *gc, const char *str, gboolean *utf8) |
| 7827 | 120 | { |
| 9164 | 121 | struct yahoo_data *yd = gc->proto_data; |
| 7827 | 122 | char *ret; |
|
10504
eae130eefbfe
[gaim-migrate @ 11796]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10380
diff
changeset
|
123 | const char *to_codeset; |
| 7827 | 124 | |
|
23173
c6dde2d2e30e
applied changes from a5e7a62db1d43009f4ff463b7fe67ff3a7275a78
Daniel Atallah <datallah@pidgin.im>
parents:
22289
diff
changeset
|
125 | if (yd->jp) |
|
c6dde2d2e30e
applied changes from a5e7a62db1d43009f4ff463b7fe67ff3a7275a78
Daniel Atallah <datallah@pidgin.im>
parents:
22289
diff
changeset
|
126 | return g_strdup(str); |
| 9164 | 127 | |
| 7827 | 128 | if (utf8 && *utf8) /* FIXME: maybe don't use utf8 if it'll fit in latin1 */ |
| 129 | return g_strdup(str); | |
| 130 | ||
|
23173
c6dde2d2e30e
applied changes from a5e7a62db1d43009f4ff463b7fe67ff3a7275a78
Daniel Atallah <datallah@pidgin.im>
parents:
22289
diff
changeset
|
131 | to_codeset = purple_account_get_string(purple_connection_get_account(gc), "local_charset", "ISO-8859-1"); |
|
c6dde2d2e30e
applied changes from a5e7a62db1d43009f4ff463b7fe67ff3a7275a78
Daniel Atallah <datallah@pidgin.im>
parents:
22289
diff
changeset
|
132 | ret = g_convert_with_fallback(str, -1, to_codeset, "UTF-8", "?", NULL, NULL, NULL); |
| 7827 | 133 | |
| 134 | if (ret) | |
| 135 | return ret; | |
| 136 | else | |
| 137 | return g_strdup(""); | |
| 138 | } | |
| 139 | ||
| 140 | /** | |
| 141 | * Decode some text received from the server. | |
| 142 | * | |
| 143 | * @param gc The gc handle. | |
| 144 | * @param str The null terminated string to decode. | |
| 145 | * @param utf8 Did the server tell us it was supposed to be utf8? | |
| 146 | * @return The decoded, utf-8 string, which must be g_free()'d. | |
| 147 | */ | |
| 15884 | 148 | char *yahoo_string_decode(PurpleConnection *gc, const char *str, gboolean utf8) |
| 7827 | 149 | { |
| 9164 | 150 | struct yahoo_data *yd = gc->proto_data; |
| 7827 | 151 | char *ret; |
| 14347 | 152 | const char *from_codeset; |
| 7827 | 153 | |
| 154 | if (utf8) { | |
| 155 | if (g_utf8_validate(str, -1, NULL)) | |
| 156 | return g_strdup(str); | |
| 157 | } | |
| 158 | ||
| 9164 | 159 | if (yd->jp) |
| 160 | from_codeset = "SHIFT_JIS"; | |
| 161 | else | |
| 15884 | 162 | from_codeset = purple_account_get_string(purple_connection_get_account(gc), "local_charset", "ISO-8859-1"); |
| 7827 | 163 | |
|
19337
68471e68386a
Use -1 as length with g_convert() functions instead of strlen()
Daniel Atallah <datallah@pidgin.im>
parents:
16169
diff
changeset
|
164 | ret = g_convert_with_fallback(str, -1, "UTF-8", from_codeset, NULL, NULL, NULL, NULL); |
| 7827 | 165 | |
| 166 | if (ret) | |
| 167 | return ret; | |
| 168 | else | |
| 169 | return g_strdup(""); | |
| 170 | } | |
| 171 | ||
|
22259
bc9fcfd10196
disapproval of revision 'db9b3bc9d4427a6a03d1c25aac5215bf0f8e05ec'
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
22248
diff
changeset
|
172 | char *yahoo_convert_to_numeric(const char *str) |
|
bc9fcfd10196
disapproval of revision 'db9b3bc9d4427a6a03d1c25aac5215bf0f8e05ec'
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
22248
diff
changeset
|
173 | { |
|
22261
e80d3a79f3b8
Since I needed to bring back yahoo_convert_to_numeric, I figured I could at
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
22259
diff
changeset
|
174 | GString *gstr = NULL; |
|
e80d3a79f3b8
Since I needed to bring back yahoo_convert_to_numeric, I figured I could at
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
22259
diff
changeset
|
175 | char *retstr; |
|
22289
a1f40ee48fa8
Fix (hopefully) the last problem in this function. Refs #3295.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
22261
diff
changeset
|
176 | const unsigned char *p; |
|
22259
bc9fcfd10196
disapproval of revision 'db9b3bc9d4427a6a03d1c25aac5215bf0f8e05ec'
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
22248
diff
changeset
|
177 | |
|
22261
e80d3a79f3b8
Since I needed to bring back yahoo_convert_to_numeric, I figured I could at
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
22259
diff
changeset
|
178 | gstr = g_string_sized_new(strlen(str) * 6 + 1); |
|
e80d3a79f3b8
Since I needed to bring back yahoo_convert_to_numeric, I figured I could at
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
22259
diff
changeset
|
179 | |
|
22289
a1f40ee48fa8
Fix (hopefully) the last problem in this function. Refs #3295.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
22261
diff
changeset
|
180 | for (p = (unsigned char *)str; *p; p++) { |
|
22261
e80d3a79f3b8
Since I needed to bring back yahoo_convert_to_numeric, I figured I could at
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
22259
diff
changeset
|
181 | g_string_append_printf(gstr, "&#%u;", *p); |
|
22259
bc9fcfd10196
disapproval of revision 'db9b3bc9d4427a6a03d1c25aac5215bf0f8e05ec'
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
22248
diff
changeset
|
182 | } |
|
22261
e80d3a79f3b8
Since I needed to bring back yahoo_convert_to_numeric, I figured I could at
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
22259
diff
changeset
|
183 | |
|
e80d3a79f3b8
Since I needed to bring back yahoo_convert_to_numeric, I figured I could at
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
22259
diff
changeset
|
184 | retstr = gstr->str; |
|
e80d3a79f3b8
Since I needed to bring back yahoo_convert_to_numeric, I figured I could at
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
22259
diff
changeset
|
185 | |
|
e80d3a79f3b8
Since I needed to bring back yahoo_convert_to_numeric, I figured I could at
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
22259
diff
changeset
|
186 | g_string_free(gstr, FALSE); |
|
e80d3a79f3b8
Since I needed to bring back yahoo_convert_to_numeric, I figured I could at
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
22259
diff
changeset
|
187 | |
|
22259
bc9fcfd10196
disapproval of revision 'db9b3bc9d4427a6a03d1c25aac5215bf0f8e05ec'
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
22248
diff
changeset
|
188 | return retstr; |
|
bc9fcfd10196
disapproval of revision 'db9b3bc9d4427a6a03d1c25aac5215bf0f8e05ec'
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
22248
diff
changeset
|
189 | } |
|
bc9fcfd10196
disapproval of revision 'db9b3bc9d4427a6a03d1c25aac5215bf0f8e05ec'
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
22248
diff
changeset
|
190 | |
| 6513 | 191 | /* |
| 192 | * I found these on some website but i don't know that they actually | |
|
8735
01248ea222d3
[gaim-migrate @ 9490]
Jonathan Champ <royanee@users.sourceforge.net>
parents:
8533
diff
changeset
|
193 | * work (or are supposed to work). I didn't implement them yet. |
|
27335
06a805d4e690
Strip trailing whitespace and comment #endif marcos that close #ifdef macros
Mark Doliner <markdoliner@pidgin.im>
parents:
24181
diff
changeset
|
194 | * |
| 6513 | 195 | * [0;30m ---black |
| 196 | * [1;37m ---white | |
| 197 | * [0;37m ---tan | |
| 198 | * [0;38m ---light black | |
| 199 | * [1;39m ---dark blue | |
| 200 | * [0;32m ---green | |
| 201 | * [0;33m ---yellow | |
| 202 | * [0;35m ---pink | |
| 203 | * [1;35m ---purple | |
| 204 | * [1;30m ---light blue | |
| 205 | * [0;31m ---red | |
| 206 | * [0;34m ---blue | |
| 207 | * [0;36m ---aqua | |
| 208 | * (shift+comma)lyellow(shift+period) ---light yellow | |
| 209 | * (shift+comma)lgreen(shift+period) ---light green | |
| 210 | [2;30m <--white out | |
| 211 | */ | |
| 212 | ||
| 213 | static GHashTable *ht = NULL; | |
| 214 | ||
| 215 | void yahoo_init_colorht() | |
| 216 | { | |
|
27683
9ee099fab4ee
Don't double-free the color hash table when deinitializing both prpl-yahoo
Mark Doliner <markdoliner@pidgin.im>
parents:
27555
diff
changeset
|
217 | if (ht != NULL) |
|
9ee099fab4ee
Don't double-free the color hash table when deinitializing both prpl-yahoo
Mark Doliner <markdoliner@pidgin.im>
parents:
27555
diff
changeset
|
218 | /* Hash table has already been initialized */ |
|
9ee099fab4ee
Don't double-free the color hash table when deinitializing both prpl-yahoo
Mark Doliner <markdoliner@pidgin.im>
parents:
27555
diff
changeset
|
219 | return; |
|
9ee099fab4ee
Don't double-free the color hash table when deinitializing both prpl-yahoo
Mark Doliner <markdoliner@pidgin.im>
parents:
27555
diff
changeset
|
220 | |
| 6513 | 221 | ht = g_hash_table_new(g_str_hash, g_str_equal); |
|
27683
9ee099fab4ee
Don't double-free the color hash table when deinitializing both prpl-yahoo
Mark Doliner <markdoliner@pidgin.im>
parents:
27555
diff
changeset
|
222 | /* the numbers in comments are what gyach uses, but i think they're incorrect */ |
| 6513 | 223 | g_hash_table_insert(ht, "30", "<FONT COLOR=\"#000000\">"); /* black */ |
| 224 | g_hash_table_insert(ht, "31", "<FONT COLOR=\"#0000FF\">"); /* blue */ | |
| 225 | g_hash_table_insert(ht, "32", "<FONT COLOR=\"#008080\">"); /* cyan */ /* 00b2b2 */ | |
| 226 | g_hash_table_insert(ht, "33", "<FONT COLOR=\"#808080\">"); /* gray */ /* 808080 */ | |
| 227 | g_hash_table_insert(ht, "34", "<FONT COLOR=\"#008000\">"); /* green */ /* 00c200 */ | |
| 228 | g_hash_table_insert(ht, "35", "<FONT COLOR=\"#FF0080\">"); /* pink */ /* ffafaf */ | |
| 229 | g_hash_table_insert(ht, "36", "<FONT COLOR=\"#800080\">"); /* purple */ /* b200b2 */ | |
| 230 | g_hash_table_insert(ht, "37", "<FONT COLOR=\"#FF8000\">"); /* orange */ /* ffff00 */ | |
| 231 | g_hash_table_insert(ht, "38", "<FONT COLOR=\"#FF0000\">"); /* red */ | |
| 232 | g_hash_table_insert(ht, "39", "<FONT COLOR=\"#808000\">"); /* olive */ /* 546b50 */ | |
| 233 | ||
| 234 | g_hash_table_insert(ht, "1", "<B>"); | |
| 235 | g_hash_table_insert(ht, "x1", "</B>"); | |
| 236 | g_hash_table_insert(ht, "2", "<I>"); | |
| 237 | g_hash_table_insert(ht, "x2", "</I>"); | |
| 238 | g_hash_table_insert(ht, "4", "<U>"); | |
| 239 | g_hash_table_insert(ht, "x4", "</U>"); | |
| 240 | ||
| 6629 | 241 | /* these just tell us the text they surround is supposed |
| 15884 | 242 | * to be a link. purple figures that out on its own so we |
| 6629 | 243 | * just ignore it. |
| 244 | */ | |
| 245 | g_hash_table_insert(ht, "l", ""); /* link start */ | |
| 246 | g_hash_table_insert(ht, "xl", ""); /* link end */ | |
| 247 | ||
| 6513 | 248 | g_hash_table_insert(ht, "<black>", "<FONT COLOR=\"#000000\">"); |
| 249 | g_hash_table_insert(ht, "<blue>", "<FONT COLOR=\"#0000FF\">"); | |
| 250 | g_hash_table_insert(ht, "<cyan>", "<FONT COLOR=\"#008284\">"); | |
| 251 | g_hash_table_insert(ht, "<gray>", "<FONT COLOR=\"#848284\">"); | |
| 252 | g_hash_table_insert(ht, "<green>", "<FONT COLOR=\"#008200\">"); | |
| 253 | g_hash_table_insert(ht, "<pink>", "<FONT COLOR=\"#FF0084\">"); | |
| 254 | g_hash_table_insert(ht, "<purple>", "<FONT COLOR=\"#840084\">"); | |
| 255 | g_hash_table_insert(ht, "<orange>", "<FONT COLOR=\"#FF8000\">"); | |
| 256 | g_hash_table_insert(ht, "<red>", "<FONT COLOR=\"#FF0000\">"); | |
| 257 | g_hash_table_insert(ht, "<yellow>", "<FONT COLOR=\"#848200\">"); | |
| 258 | ||
| 259 | g_hash_table_insert(ht, "</black>", "</FONT>"); | |
| 260 | g_hash_table_insert(ht, "</blue>", "</FONT>"); | |
| 261 | g_hash_table_insert(ht, "</cyan>", "</FONT>"); | |
| 262 | g_hash_table_insert(ht, "</gray>", "</FONT>"); | |
| 263 | g_hash_table_insert(ht, "</green>", "</FONT>"); | |
| 264 | g_hash_table_insert(ht, "</pink>", "</FONT>"); | |
| 265 | g_hash_table_insert(ht, "</purple>", "</FONT>"); | |
| 266 | g_hash_table_insert(ht, "</orange>", "</FONT>"); | |
| 267 | g_hash_table_insert(ht, "</red>", "</FONT>"); | |
| 268 | g_hash_table_insert(ht, "</yellow>", "</FONT>"); | |
| 269 | ||
| 270 | /* remove these once we have proper support for <FADE> and <ALT> */ | |
| 271 | g_hash_table_insert(ht, "</fade>", ""); | |
| 272 | g_hash_table_insert(ht, "</alt>", ""); | |
| 8375 | 273 | |
| 274 | /* these are the normal html yahoo sends (besides <font>). | |
| 275 | * anything else will get turned into <tag>, so if I forgot | |
| 276 | * about something, please add it. Why Yahoo! has to send unescaped | |
| 277 | * <'s and >'s that aren't supposed to be html is beyond me. | |
| 278 | */ | |
| 279 | g_hash_table_insert(ht, "<b>", "<b>"); | |
| 280 | g_hash_table_insert(ht, "<i>", "<i>"); | |
| 281 | g_hash_table_insert(ht, "<u>", "<u>"); | |
| 282 | ||
| 283 | g_hash_table_insert(ht, "</b>", "</b>"); | |
| 284 | g_hash_table_insert(ht, "</i>", "</i>"); | |
| 285 | g_hash_table_insert(ht, "</u>", "</u>"); | |
| 8440 | 286 | g_hash_table_insert(ht, "</font>", "</font>"); |
| 6513 | 287 | } |
| 288 | ||
| 289 | void yahoo_dest_colorht() | |
| 290 | { | |
|
27683
9ee099fab4ee
Don't double-free the color hash table when deinitializing both prpl-yahoo
Mark Doliner <markdoliner@pidgin.im>
parents:
27555
diff
changeset
|
291 | if (ht == NULL) |
|
9ee099fab4ee
Don't double-free the color hash table when deinitializing both prpl-yahoo
Mark Doliner <markdoliner@pidgin.im>
parents:
27555
diff
changeset
|
292 | /* Hash table has already been destroyed */ |
|
9ee099fab4ee
Don't double-free the color hash table when deinitializing both prpl-yahoo
Mark Doliner <markdoliner@pidgin.im>
parents:
27555
diff
changeset
|
293 | return; |
|
9ee099fab4ee
Don't double-free the color hash table when deinitializing both prpl-yahoo
Mark Doliner <markdoliner@pidgin.im>
parents:
27555
diff
changeset
|
294 | |
| 6513 | 295 | g_hash_table_destroy(ht); |
|
27683
9ee099fab4ee
Don't double-free the color hash table when deinitializing both prpl-yahoo
Mark Doliner <markdoliner@pidgin.im>
parents:
27555
diff
changeset
|
296 | ht = NULL; |
| 6513 | 297 | } |
| 298 | ||
| 6629 | 299 | static int point_to_html(int x) |
| 300 | { | |
| 301 | if (x < 9) | |
| 302 | return 1; | |
| 303 | if (x < 11) | |
| 304 | return 2; | |
| 305 | if (x < 13) | |
| 306 | return 3; | |
| 307 | if (x < 17) | |
| 308 | return 4; | |
| 309 | if (x < 25) | |
| 310 | return 5; | |
| 311 | if (x < 35) | |
| 312 | return 6; | |
| 313 | return 7; | |
| 314 | } | |
|
10380
8608e553808f
[gaim-migrate @ 11605]
Evan Schoenberg <evands@pidgin.im>
parents:
10023
diff
changeset
|
315 | |
|
8608e553808f
[gaim-migrate @ 11605]
Evan Schoenberg <evands@pidgin.im>
parents:
10023
diff
changeset
|
316 | /* The Yahoo size tag is actually an absz tag; convert it to an HTML size, and include both tags */ |
| 6629 | 317 | static void _font_tags_fix_size(GString *tag, GString *dest) |
| 318 | { | |
| 319 | char *x, *end; | |
| 320 | int size; | |
| 321 | ||
|
13710
c8376b63ca31
[gaim-migrate @ 16112]
Richard Laager <rlaager@pidgin.im>
parents:
11644
diff
changeset
|
322 | if (((x = strstr(tag->str, "size"))) && ((x = strchr(x, '=')))) { |
| 6629 | 323 | while (*x && !g_ascii_isdigit(*x)) |
| 324 | x++; | |
| 325 | if (*x) { | |
|
10380
8608e553808f
[gaim-migrate @ 11605]
Evan Schoenberg <evands@pidgin.im>
parents:
10023
diff
changeset
|
326 | int htmlsize; |
|
8608e553808f
[gaim-migrate @ 11605]
Evan Schoenberg <evands@pidgin.im>
parents:
10023
diff
changeset
|
327 | |
| 6629 | 328 | size = strtol(x, &end, 10); |
|
10380
8608e553808f
[gaim-migrate @ 11605]
Evan Schoenberg <evands@pidgin.im>
parents:
10023
diff
changeset
|
329 | htmlsize = point_to_html(size); |
| 6629 | 330 | g_string_append_len(dest, tag->str, x - tag->str); |
|
10380
8608e553808f
[gaim-migrate @ 11605]
Evan Schoenberg <evands@pidgin.im>
parents:
10023
diff
changeset
|
331 | g_string_append_printf(dest, "%d", htmlsize); |
|
8608e553808f
[gaim-migrate @ 11605]
Evan Schoenberg <evands@pidgin.im>
parents:
10023
diff
changeset
|
332 | g_string_append_printf(dest, "\" absz=\"%d", size); |
| 6629 | 333 | g_string_append(dest, end); |
| 334 | } else { | |
| 335 | g_string_append(dest, tag->str); | |
| 336 | return; | |
| 337 | } | |
| 338 | } else { | |
| 339 | g_string_append(dest, tag->str); | |
| 340 | return; | |
| 341 | } | |
| 342 | } | |
| 343 | ||
| 344 | char *yahoo_codes_to_html(const char *x) | |
| 6513 | 345 | { |
| 346 | GString *s, *tmp; | |
| 6629 | 347 | int i, j, xs, nomoreendtags = 0; /* s/endtags/closinganglebrackets */ |
| 6513 | 348 | char *match, *ret; |
| 349 | ||
| 350 | s = g_string_sized_new(strlen(x)); | |
| 351 | ||
| 352 | for (i = 0, xs = strlen(x); i < xs; i++) { | |
| 353 | if ((x[i] == 0x1b) && (x[i+1] == '[')) { | |
| 354 | j = i + 1; | |
| 355 | ||
| 356 | while (j++ < xs) { | |
| 357 | if (x[j] != 'm') | |
| 358 | continue; | |
| 359 | else { | |
| 360 | tmp = g_string_new_len(x + i + 2, j - i - 2); | |
|
6621
2a18ef3e5224
[gaim-migrate @ 7145]
Robert McQueen <robot101@debian.org>
parents:
6546
diff
changeset
|
361 | if (tmp->str[0] == '#') |
| 6513 | 362 | g_string_append_printf(s, "<FONT COLOR=\"%s\">", tmp->str); |
|
6546
6a14dfe43d5c
[gaim-migrate @ 7068]
Mark Doliner <markdoliner@pidgin.im>
parents:
6513
diff
changeset
|
363 | else if ((match = (char *) g_hash_table_lookup(ht, tmp->str))) |
| 6513 | 364 | g_string_append(s, match); |
| 365 | else { | |
|
27547
c136491361eb
Convert the yahoo prpl to using the debug convenience functions instead of
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
27361
diff
changeset
|
366 | purple_debug_error("yahoo", |
| 6513 | 367 | "Unknown ansi code 'ESC[%sm'.\n", tmp->str); |
| 368 | g_string_free(tmp, TRUE); | |
| 369 | break; | |
| 370 | } | |
| 371 | ||
| 372 | i = j; | |
| 373 | g_string_free(tmp, TRUE); | |
| 374 | break; | |
| 375 | } | |
| 376 | } | |
| 377 | ||
| 378 | } else if (!nomoreendtags && (x[i] == '<')) { | |
| 6629 | 379 | j = i; |
| 6513 | 380 | |
| 381 | while (j++ < xs) { | |
| 382 | if (x[j] != '>') | |
| 383 | if (j == xs) { | |
| 8375 | 384 | g_string_append(s, "<"); |
| 6513 | 385 | nomoreendtags = 1; |
| 386 | } | |
| 387 | else | |
| 388 | continue; | |
| 389 | else { | |
| 390 | tmp = g_string_new_len(x + i, j - i + 1); | |
| 391 | g_string_ascii_down(tmp); | |
| 392 | ||
|
6546
6a14dfe43d5c
[gaim-migrate @ 7068]
Mark Doliner <markdoliner@pidgin.im>
parents:
6513
diff
changeset
|
393 | if ((match = (char *) g_hash_table_lookup(ht, tmp->str))) |
| 6513 | 394 | g_string_append(s, match); |
| 6629 | 395 | else if (!strncmp(tmp->str, "<fade ", 6) || |
| 396 | !strncmp(tmp->str, "<alt ", 5) || | |
| 397 | !strncmp(tmp->str, "<snd ", 5)) { | |
| 6513 | 398 | |
| 6629 | 399 | /* remove this if gtkimhtml ever supports any of these */ |
| 6513 | 400 | i = j; |
| 401 | g_string_free(tmp, TRUE); | |
| 402 | break; | |
| 403 | ||
| 6629 | 404 | } else if (!strncmp(tmp->str, "<font ", 6)) { |
| 405 | _font_tags_fix_size(tmp, s); | |
| 6513 | 406 | } else { |
| 8375 | 407 | g_string_append(s, "<"); |
| 6513 | 408 | g_string_free(tmp, TRUE); |
| 409 | break; | |
| 410 | } | |
| 411 | ||
| 412 | i = j; | |
| 413 | g_string_free(tmp, TRUE); | |
| 414 | break; | |
| 415 | } | |
| 416 | ||
| 417 | } | |
| 418 | ||
| 419 | } else { | |
| 8375 | 420 | if (x[i] == '<') |
| 421 | g_string_append(s, "<"); | |
| 422 | else if (x[i] == '>') | |
| 423 | g_string_append(s, ">"); | |
| 8440 | 424 | else if (x[i] == '&') |
| 425 | g_string_append(s, "&"); | |
| 426 | else if (x[i] == '"') | |
| 427 | g_string_append(s, """); | |
| 8375 | 428 | else |
| 429 | g_string_append_c(s, x[i]); | |
| 6513 | 430 | } |
| 431 | } | |
| 432 | ||
| 433 | ret = s->str; | |
| 434 | g_string_free(s, FALSE); | |
|
27547
c136491361eb
Convert the yahoo prpl to using the debug convenience functions instead of
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
27361
diff
changeset
|
435 | purple_debug_misc("yahoo", "yahoo_codes_to_html: Returning string: '%s'.\n", ret); |
| 6513 | 436 | return ret; |
| 437 | } | |
| 6629 | 438 | |
| 439 | /* borrowed from gtkimhtml */ | |
| 440 | #define MAX_FONT_SIZE 7 | |
|
10899
87d9aec5b72d
[gaim-migrate @ 12619]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10504
diff
changeset
|
441 | #define POINT_SIZE(x) (_point_sizes [MIN ((x > 0 ? x : 1), MAX_FONT_SIZE) - 1]) |
|
14904
cab89db4854c
[gaim-migrate @ 17611]
Henning Norén <henning.noren@gmail.com>
parents:
14347
diff
changeset
|
442 | static const gint _point_sizes [] = { 8, 10, 12, 14, 20, 30, 40 }; |
| 6629 | 443 | |
| 444 | enum fatype { size, color, face, junk }; | |
| 445 | typedef struct { | |
| 446 | enum fatype type; | |
| 447 | union { | |
| 448 | int size; | |
| 449 | char *color; | |
| 450 | char *face; | |
| 451 | char *junk; | |
| 452 | } u; | |
| 453 | } fontattr; | |
| 454 | ||
| 455 | static void fontattr_free(fontattr *f) | |
| 456 | { | |
| 457 | if (f->type == color) | |
| 458 | g_free(f->u.color); | |
| 459 | else if (f->type == face) | |
| 460 | g_free(f->u.face); | |
| 461 | g_free(f); | |
| 462 | } | |
| 463 | ||
| 464 | static void yahoo_htc_queue_cleanup(GQueue *q) | |
| 465 | { | |
| 466 | char *tmp; | |
| 467 | ||
| 468 | while ((tmp = g_queue_pop_tail(q))) | |
| 469 | g_free(tmp); | |
| 470 | g_queue_free(q); | |
| 471 | } | |
| 472 | ||
| 473 | static void _parse_font_tag(const char *src, GString *dest, int *i, int *j, | |
| 474 | int len, GQueue *colors, GQueue *tags, GQueue *ftattr) | |
| 475 | { | |
| 476 | ||
| 477 | int m, n, vstart; | |
| 478 | gboolean quote = 0, done = 0; | |
| 479 | ||
| 480 | m = *j; | |
| 481 | ||
| 482 | while (1) { | |
| 483 | m++; | |
| 484 | ||
| 485 | if (m >= len) { | |
| 486 | g_string_append(dest, &src[*i]); | |
| 487 | *i = len; | |
| 488 | break; | |
| 489 | } | |
| 490 | ||
| 491 | if (src[m] == '=') { | |
| 492 | n = vstart = m; | |
| 493 | while (1) { | |
| 494 | n++; | |
| 495 | ||
| 496 | if (n >= len) { | |
| 497 | m = n; | |
| 498 | break; | |
| 499 | } | |
| 500 | ||
|
6631
a2608d595a32
[gaim-migrate @ 7155]
Björn Voigt <bjoern@cs.tu-berlin.de>
parents:
6629
diff
changeset
|
501 | if (src[n] == '"') { |
| 6629 | 502 | if (!quote) { |
| 503 | quote = 1; | |
| 504 | vstart = n; | |
| 505 | continue; | |
| 506 | } else { | |
| 507 | done = 1; | |
| 508 | } | |
|
6631
a2608d595a32
[gaim-migrate @ 7155]
Björn Voigt <bjoern@cs.tu-berlin.de>
parents:
6629
diff
changeset
|
509 | } |
| 6629 | 510 | |
| 511 | if (!quote && ((src[n] == ' ') || (src[n] == '>'))) | |
| 512 | done = 1; | |
| 513 | ||
| 514 | if (done) { | |
| 515 | if (!g_ascii_strncasecmp(&src[*j+1], "FACE", m - *j - 1)) { | |
| 516 | fontattr *f; | |
| 517 | ||
| 518 | f = g_new(fontattr, 1); | |
| 519 | f->type = face; | |
| 520 | f->u.face = g_strndup(&src[vstart+1], n-vstart-1); | |
| 521 | if (!ftattr) | |
| 522 | ftattr = g_queue_new(); | |
| 523 | g_queue_push_tail(ftattr, f); | |
| 524 | m = n; | |
| 525 | break; | |
| 526 | } else if (!g_ascii_strncasecmp(&src[*j+1], "SIZE", m - *j - 1)) { | |
| 527 | fontattr *f; | |
| 528 | ||
| 529 | f = g_new(fontattr, 1); | |
| 530 | f->type = size; | |
| 531 | f->u.size = POINT_SIZE(strtol(&src[vstart+1], NULL, 10)); | |
| 532 | if (!ftattr) | |
| 533 | ftattr = g_queue_new(); | |
| 534 | g_queue_push_tail(ftattr, f); | |
| 535 | m = n; | |
| 536 | break; | |
| 537 | } else if (!g_ascii_strncasecmp(&src[*j+1], "COLOR", m - *j - 1)) { | |
| 538 | fontattr *f; | |
| 539 | ||
| 540 | f = g_new(fontattr, 1); | |
| 541 | f->type = color; | |
| 542 | f->u.color = g_strndup(&src[vstart+1], n-vstart-1); | |
| 543 | if (!ftattr) | |
| 544 | ftattr = g_queue_new(); | |
| 545 | g_queue_push_head(ftattr, f); | |
| 546 | m = n; | |
| 547 | break; | |
| 548 | } else { | |
| 549 | fontattr *f; | |
| 550 | ||
| 551 | f = g_new(fontattr, 1); | |
| 552 | f->type = junk; | |
| 553 | f->u.junk = g_strndup(&src[*j+1], n-*j); | |
| 554 | if (!ftattr) | |
| 555 | ftattr = g_queue_new(); | |
| 556 | g_queue_push_tail(ftattr, f); | |
| 557 | m = n; | |
| 558 | break; | |
| 559 | } | |
| 560 | ||
| 561 | } | |
| 562 | } | |
| 563 | } | |
| 564 | ||
| 565 | if (src[m] == ' ') | |
| 566 | *j = m; | |
| 567 | ||
| 568 | if (src[m] == '>') { | |
| 569 | gboolean needendtag = 0; | |
| 570 | fontattr *f; | |
| 571 | GString *tmp = g_string_new(NULL); | |
| 572 | char *colorstr; | |
| 573 | ||
| 574 | if (!g_queue_is_empty(ftattr)) { | |
| 575 | while ((f = g_queue_pop_tail(ftattr))) { | |
| 576 | switch (f->type) { | |
| 577 | case size: | |
| 578 | if (!needendtag) { | |
| 579 | needendtag = 1; | |
| 580 | g_string_append(dest, "<font "); | |
| 581 | } | |
| 582 | ||
| 583 | g_string_append_printf(dest, "size=\"%d\" ", f->u.size); | |
| 584 | fontattr_free(f); | |
| 585 | break; | |
| 586 | case face: | |
| 587 | if (!needendtag) { | |
| 588 | needendtag = 1; | |
| 589 | g_string_append(dest, "<font "); | |
| 590 | } | |
| 591 | ||
| 592 | g_string_append_printf(dest, "face=\"%s\" ", f->u.face); | |
| 593 | fontattr_free(f); | |
| 594 | break; | |
| 595 | case junk: | |
| 596 | if (!needendtag) { | |
| 597 | needendtag = 1; | |
| 598 | g_string_append(dest, "<font "); | |
| 599 | } | |
| 600 | ||
| 601 | g_string_append(dest, f->u.junk); | |
| 602 | fontattr_free(f); | |
| 603 | break; | |
| 604 | ||
| 605 | case color: | |
| 606 | if (needendtag) { | |
| 607 | g_string_append(tmp, "</font>"); | |
| 608 | dest->str[dest->len-1] = '>'; | |
| 609 | needendtag = 0; | |
| 610 | } | |
| 611 | ||
| 612 | colorstr = g_queue_peek_tail(colors); | |
| 613 | g_string_append(tmp, colorstr ? colorstr : "\033[#000000m"); | |
| 614 | g_string_append_printf(dest, "\033[%sm", f->u.color); | |
| 615 | g_queue_push_tail(colors, g_strdup_printf("\033[%sm", f->u.color)); | |
| 616 | fontattr_free(f); | |
| 617 | break; | |
| 618 | } | |
| 619 | } | |
| 620 | ||
| 621 | g_queue_free(ftattr); | |
| 622 | ftattr = NULL; | |
| 623 | ||
| 624 | if (needendtag) { | |
| 625 | dest->str[dest->len-1] = '>'; | |
| 626 | g_queue_push_tail(tags, g_strdup("</font>")); | |
| 627 | g_string_free(tmp, TRUE); | |
| 628 | } else { | |
| 629 | g_queue_push_tail(tags, tmp->str); | |
| 630 | g_string_free(tmp, FALSE); | |
| 631 | } | |
| 632 | } | |
| 633 | ||
| 634 | *i = *j = m; | |
| 635 | break; | |
| 636 | } | |
| 637 | } | |
| 638 | ||
| 639 | } | |
| 640 | ||
| 641 | char *yahoo_html_to_codes(const char *src) | |
| 642 | { | |
|
6631
a2608d595a32
[gaim-migrate @ 7155]
Björn Voigt <bjoern@cs.tu-berlin.de>
parents:
6629
diff
changeset
|
643 | int i, j, len; |
| 6629 | 644 | GString *dest; |
| 645 | char *ret, *esc; | |
| 646 | GQueue *colors, *tags; | |
| 647 | GQueue *ftattr = NULL; | |
| 8440 | 648 | gboolean no_more_specials = FALSE; |
| 6629 | 649 | |
| 650 | colors = g_queue_new(); | |
| 651 | tags = g_queue_new(); | |
| 652 | dest = g_string_sized_new(strlen(src)); | |
| 653 | ||
| 654 | for (i = 0, len = strlen(src); i < len; i++) { | |
| 655 | ||
| 8440 | 656 | if (!no_more_specials && src[i] == '<') { |
| 6629 | 657 | j = i; |
| 658 | ||
| 659 | while (1) { | |
| 660 | j++; | |
| 661 | ||
| 662 | if (j >= len) { /* no '>' */ | |
| 8440 | 663 | g_string_append_c(dest, src[i]); |
| 664 | no_more_specials = TRUE; | |
| 6629 | 665 | break; |
| 666 | } | |
| 667 | ||
| 668 | if (src[j] == '<') { | |
| 8440 | 669 | /* FIXME: This doesn't convert outgoing entities. |
| 670 | * However, I suspect this case may never | |
| 671 | * happen anymore because of the entities. | |
| 672 | */ | |
| 6629 | 673 | g_string_append_len(dest, &src[i], j - i); |
| 674 | i = j - 1; | |
| 675 | if (ftattr) { | |
| 676 | fontattr *f; | |
| 677 | ||
| 678 | while ((f = g_queue_pop_head(ftattr))) | |
| 679 | fontattr_free(f); | |
| 680 | g_queue_free(ftattr); | |
| 681 | ftattr = NULL; | |
| 682 | } | |
| 683 | break; | |
| 684 | } | |
| 685 | ||
| 686 | if (src[j] == ' ') { | |
| 687 | if (!g_ascii_strncasecmp(&src[i+1], "BODY", j - i - 1)) { | |
| 688 | char *t = strchr(&src[j], '>'); | |
| 689 | if (!t) { | |
| 690 | g_string_append(dest, &src[i]); | |
| 691 | i = len; | |
| 692 | break; | |
| 693 | } else { | |
| 694 | i = t - src; | |
| 695 | break; | |
| 696 | } | |
| 8533 | 697 | } else if (!g_ascii_strncasecmp(&src[i+1], "A HREF=\"", j - i - 1)) { |
| 698 | j += 7; | |
| 699 | g_string_append(dest, "\033[lm"); | |
| 700 | while (1) { | |
| 701 | g_string_append_c(dest, src[j]); | |
| 702 | if (++j >= len) { | |
| 8480 | 703 | i = len; |
| 704 | break; | |
| 705 | } | |
| 8533 | 706 | if (src[j] == '"') { |
| 707 | g_string_append(dest, "\033[xlm"); | |
| 708 | while (1) { | |
| 709 | if (++j >= len) { | |
| 710 | i = len; | |
| 711 | break; | |
| 712 | } | |
| 713 | if (!g_ascii_strncasecmp(&src[j], "</A>", 4)) { | |
| 714 | j += 3; | |
| 715 | break; | |
| 716 | } | |
| 717 | } | |
| 718 | i = j; | |
| 8480 | 719 | break; |
| 720 | } | |
| 721 | } | |
|
16169
4aa4ec9afa9c
Stop Yahoo sending SPAN tags, fixes Yahoo part of ticket 78
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
722 | } else if (!g_ascii_strncasecmp(&src[i+1], "SPAN", j - i - 1)) { /* drop span tags */ |
|
4aa4ec9afa9c
Stop Yahoo sending SPAN tags, fixes Yahoo part of ticket 78
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
723 | while (1) { |
|
4aa4ec9afa9c
Stop Yahoo sending SPAN tags, fixes Yahoo part of ticket 78
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
724 | if (++j >= len) { |
|
4aa4ec9afa9c
Stop Yahoo sending SPAN tags, fixes Yahoo part of ticket 78
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
725 | g_string_append(dest, &src[i]); |
|
4aa4ec9afa9c
Stop Yahoo sending SPAN tags, fixes Yahoo part of ticket 78
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
726 | i = len; |
|
4aa4ec9afa9c
Stop Yahoo sending SPAN tags, fixes Yahoo part of ticket 78
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
727 | break; |
|
4aa4ec9afa9c
Stop Yahoo sending SPAN tags, fixes Yahoo part of ticket 78
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
728 | } |
|
4aa4ec9afa9c
Stop Yahoo sending SPAN tags, fixes Yahoo part of ticket 78
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
729 | if (src[j] == '>') { |
|
4aa4ec9afa9c
Stop Yahoo sending SPAN tags, fixes Yahoo part of ticket 78
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
730 | i = j; |
|
4aa4ec9afa9c
Stop Yahoo sending SPAN tags, fixes Yahoo part of ticket 78
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
731 | break; |
|
4aa4ec9afa9c
Stop Yahoo sending SPAN tags, fixes Yahoo part of ticket 78
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
732 | } |
|
4aa4ec9afa9c
Stop Yahoo sending SPAN tags, fixes Yahoo part of ticket 78
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
733 | } |
| 6629 | 734 | } else if (g_ascii_strncasecmp(&src[i+1], "FONT", j - i - 1)) { /* not interested! */ |
| 735 | while (1) { | |
| 736 | if (++j >= len) { | |
| 737 | g_string_append(dest, &src[i]); | |
| 738 | i = len; | |
| 739 | break; | |
| 740 | } | |
| 741 | if (src[j] == '>') { | |
| 742 | g_string_append_len(dest, &src[i], j - i + 1); | |
| 743 | i = j; | |
| 744 | break; | |
| 745 | } | |
| 746 | } | |
| 747 | } else { /* yay we have a font tag */ | |
| 748 | _parse_font_tag(src, dest, &i, &j, len, colors, tags, ftattr); | |
| 749 | } | |
| 750 | ||
| 751 | break; | |
| 752 | } | |
| 753 | ||
| 754 | if (src[j] == '>') { | |
| 8440 | 755 | /* This has some problems like the FIXME for the |
| 756 | * '<' case. and like that case, I suspect the case | |
| 757 | * that this has problems is won't happen anymore anyway. | |
| 758 | */ | |
| 6629 | 759 | int sublen = j - i - 1; |
| 760 | ||
| 761 | if (sublen) { | |
| 762 | if (!g_ascii_strncasecmp(&src[i+1], "B", sublen)) { | |
| 763 | g_string_append(dest, "\033[1m"); | |
| 764 | } else if (!g_ascii_strncasecmp(&src[i+1], "/B", sublen)) { | |
| 765 | g_string_append(dest, "\033[x1m"); | |
| 766 | } else if (!g_ascii_strncasecmp(&src[i+1], "I", sublen)) { | |
| 767 | g_string_append(dest, "\033[2m"); | |
| 768 | } else if (!g_ascii_strncasecmp(&src[i+1], "/I", sublen)) { | |
| 769 | g_string_append(dest, "\033[x2m"); | |
| 770 | } else if (!g_ascii_strncasecmp(&src[i+1], "U", sublen)) { | |
| 771 | g_string_append(dest, "\033[4m"); | |
| 772 | } else if (!g_ascii_strncasecmp(&src[i+1], "/U", sublen)) { | |
| 773 | g_string_append(dest, "\033[x4m"); | |
| 8480 | 774 | } else if (!g_ascii_strncasecmp(&src[i+1], "/A", sublen)) { |
| 775 | g_string_append(dest, "\033[xlm"); | |
| 8455 | 776 | } else if (!g_ascii_strncasecmp(&src[i+1], "BR", sublen)) { |
| 777 | g_string_append_c(dest, '\n'); | |
| 6629 | 778 | } else if (!g_ascii_strncasecmp(&src[i+1], "/BODY", sublen)) { |
| 779 | /* mmm, </body> tags. *BURP* */ | |
|
16169
4aa4ec9afa9c
Stop Yahoo sending SPAN tags, fixes Yahoo part of ticket 78
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
780 | } else if (!g_ascii_strncasecmp(&src[i+1], "/SPAN", sublen)) { |
|
4aa4ec9afa9c
Stop Yahoo sending SPAN tags, fixes Yahoo part of ticket 78
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
781 | /* </span> tags. dangerously close to </spam> */ |
| 6629 | 782 | } else if (!g_ascii_strncasecmp(&src[i+1], "/FONT", sublen) && g_queue_peek_tail(tags)) { |
| 783 | char *etag, *cl; | |
| 784 | ||
| 785 | etag = g_queue_pop_tail(tags); | |
| 786 | if (etag) { | |
| 787 | g_string_append(dest, etag); | |
| 788 | if (!strcmp(etag, "</font>")) { | |
| 789 | cl = g_queue_pop_tail(colors); | |
| 790 | if (cl) | |
| 791 | g_free(cl); | |
| 792 | } | |
| 793 | g_free(etag); | |
| 794 | } | |
| 795 | } else { | |
| 796 | g_string_append_len(dest, &src[i], j - i + 1); | |
| 797 | } | |
| 798 | } else { | |
| 799 | g_string_append_len(dest, &src[i], j - i + 1); | |
| 800 | } | |
| 801 | ||
| 802 | i = j; | |
| 803 | break; | |
| 804 | } | |
| 805 | ||
| 806 | } | |
| 807 | ||
| 808 | } else { | |
| 8440 | 809 | if (((len - i) >= 4) && !strncmp(&src[i], "<", 4)) { |
| 810 | g_string_append_c(dest, '<'); | |
| 811 | i += 3; | |
| 812 | } else if (((len - i) >= 4) && !strncmp(&src[i], ">", 4)) { | |
| 813 | g_string_append_c(dest, '>'); | |
| 814 | i += 3; | |
|
21946
f444fc9e2d18
Make yahoo_html_to_codes deal with ' in messages being sent. Also correct
Will Thompson <resiak@pidgin.im>
parents:
19859
diff
changeset
|
815 | } else if (((len - i) >= 5) && !strncmp(&src[i], "&", 5)) { |
| 8440 | 816 | g_string_append_c(dest, '&'); |
| 817 | i += 4; | |
|
21946
f444fc9e2d18
Make yahoo_html_to_codes deal with ' in messages being sent. Also correct
Will Thompson <resiak@pidgin.im>
parents:
19859
diff
changeset
|
818 | } else if (((len - i) >= 6) && !strncmp(&src[i], """, 6)) { |
| 8440 | 819 | g_string_append_c(dest, '"'); |
| 820 | i += 5; | |
|
21946
f444fc9e2d18
Make yahoo_html_to_codes deal with ' in messages being sent. Also correct
Will Thompson <resiak@pidgin.im>
parents:
19859
diff
changeset
|
821 | } else if (((len - i) >= 6) && !strncmp(&src[i], "'", 6)) { |
|
f444fc9e2d18
Make yahoo_html_to_codes deal with ' in messages being sent. Also correct
Will Thompson <resiak@pidgin.im>
parents:
19859
diff
changeset
|
822 | g_string_append_c(dest, '\''); |
|
f444fc9e2d18
Make yahoo_html_to_codes deal with ' in messages being sent. Also correct
Will Thompson <resiak@pidgin.im>
parents:
19859
diff
changeset
|
823 | i += 5; |
| 8440 | 824 | } else { |
| 825 | g_string_append_c(dest, src[i]); | |
| 826 | } | |
| 6629 | 827 | } |
| 828 | } | |
| 829 | ||
| 830 | ret = dest->str; | |
| 831 | g_string_free(dest, FALSE); | |
| 832 | ||
| 833 | esc = g_strescape(ret, NULL); | |
|
27547
c136491361eb
Convert the yahoo prpl to using the debug convenience functions instead of
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
27361
diff
changeset
|
834 | purple_debug_misc("yahoo", "yahoo_html_to_codes: Returning string: '%s'.\n", esc); |
| 6629 | 835 | g_free(esc); |
| 836 | ||
| 837 | yahoo_htc_queue_cleanup(colors); | |
| 838 | yahoo_htc_queue_cleanup(tags); | |
| 839 | ||
| 840 | return ret; | |
| 841 | } |