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