Sun, 16 Mar 2008 20:36:52 +0000
Fix a bunch of compiler warnings caused by my addition of G_GNUC_PRINTF()
to our debug functions (I really thought we had added that in a while ago?)
I didn't fix all of them... just most of them.
Oh, see these pages for a little info:
http://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html
http://library.gnome.org/devel/glib/unstable/glib-Miscellaneous-Macros.html#G-GNUC-PRINTF:CAPS
| 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 | ||
|
22259
bc9fcfd10196
disapproval of revision 'db9b3bc9d4427a6a03d1c25aac5215bf0f8e05ec'
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
22248
diff
changeset
|
167 | char *yahoo_convert_to_numeric(const char *str) |
|
bc9fcfd10196
disapproval of revision 'db9b3bc9d4427a6a03d1c25aac5215bf0f8e05ec'
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
22248
diff
changeset
|
168 | { |
|
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
|
169 | 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
|
170 | char *retstr; |
|
22289
a1f40ee48fa8
Fix (hopefully) the last problem in this function. Refs #3295.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
22261
diff
changeset
|
171 | const unsigned char *p; |
|
22259
bc9fcfd10196
disapproval of revision 'db9b3bc9d4427a6a03d1c25aac5215bf0f8e05ec'
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
22248
diff
changeset
|
172 | |
|
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
|
173 | 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
|
174 | |
|
22289
a1f40ee48fa8
Fix (hopefully) the last problem in this function. Refs #3295.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
22261
diff
changeset
|
175 | 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
|
176 | g_string_append_printf(gstr, "&#%u;", *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 | |
|
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 | 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
|
180 | |
|
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_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
|
182 | |
|
22259
bc9fcfd10196
disapproval of revision 'db9b3bc9d4427a6a03d1c25aac5215bf0f8e05ec'
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
22248
diff
changeset
|
183 | return retstr; |
|
bc9fcfd10196
disapproval of revision 'db9b3bc9d4427a6a03d1c25aac5215bf0f8e05ec'
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
22248
diff
changeset
|
184 | } |
|
bc9fcfd10196
disapproval of revision 'db9b3bc9d4427a6a03d1c25aac5215bf0f8e05ec'
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
22248
diff
changeset
|
185 | |
| 6513 | 186 | /* |
| 187 | * 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
|
188 | * work (or are supposed to work). I didn't implement them yet. |
| 6513 | 189 | * |
| 190 | * [0;30m ---black | |
| 191 | * [1;37m ---white | |
| 192 | * [0;37m ---tan | |
| 193 | * [0;38m ---light black | |
| 194 | * [1;39m ---dark blue | |
| 195 | * [0;32m ---green | |
| 196 | * [0;33m ---yellow | |
| 197 | * [0;35m ---pink | |
| 198 | * [1;35m ---purple | |
| 199 | * [1;30m ---light blue | |
| 200 | * [0;31m ---red | |
| 201 | * [0;34m ---blue | |
| 202 | * [0;36m ---aqua | |
| 203 | * (shift+comma)lyellow(shift+period) ---light yellow | |
| 204 | * (shift+comma)lgreen(shift+period) ---light green | |
| 205 | [2;30m <--white out | |
| 206 | */ | |
| 207 | ||
| 208 | static GHashTable *ht = NULL; | |
| 209 | ||
| 210 | void yahoo_init_colorht() | |
| 211 | { | |
| 212 | ht = g_hash_table_new(g_str_hash, g_str_equal); | |
| 6629 | 213 | /* the numbers in comments are what gyach uses, but i think they're incorrect */ |
| 6513 | 214 | g_hash_table_insert(ht, "30", "<FONT COLOR=\"#000000\">"); /* black */ |
| 215 | g_hash_table_insert(ht, "31", "<FONT COLOR=\"#0000FF\">"); /* blue */ | |
| 216 | g_hash_table_insert(ht, "32", "<FONT COLOR=\"#008080\">"); /* cyan */ /* 00b2b2 */ | |
| 217 | g_hash_table_insert(ht, "33", "<FONT COLOR=\"#808080\">"); /* gray */ /* 808080 */ | |
| 218 | g_hash_table_insert(ht, "34", "<FONT COLOR=\"#008000\">"); /* green */ /* 00c200 */ | |
| 219 | g_hash_table_insert(ht, "35", "<FONT COLOR=\"#FF0080\">"); /* pink */ /* ffafaf */ | |
| 220 | g_hash_table_insert(ht, "36", "<FONT COLOR=\"#800080\">"); /* purple */ /* b200b2 */ | |
| 221 | g_hash_table_insert(ht, "37", "<FONT COLOR=\"#FF8000\">"); /* orange */ /* ffff00 */ | |
| 222 | g_hash_table_insert(ht, "38", "<FONT COLOR=\"#FF0000\">"); /* red */ | |
| 223 | g_hash_table_insert(ht, "39", "<FONT COLOR=\"#808000\">"); /* olive */ /* 546b50 */ | |
| 224 | ||
| 225 | g_hash_table_insert(ht, "1", "<B>"); | |
| 226 | g_hash_table_insert(ht, "x1", "</B>"); | |
| 227 | g_hash_table_insert(ht, "2", "<I>"); | |
| 228 | g_hash_table_insert(ht, "x2", "</I>"); | |
| 229 | g_hash_table_insert(ht, "4", "<U>"); | |
| 230 | g_hash_table_insert(ht, "x4", "</U>"); | |
| 231 | ||
| 6629 | 232 | /* these just tell us the text they surround is supposed |
| 15884 | 233 | * to be a link. purple figures that out on its own so we |
| 6629 | 234 | * just ignore it. |
| 235 | */ | |
| 236 | g_hash_table_insert(ht, "l", ""); /* link start */ | |
| 237 | g_hash_table_insert(ht, "xl", ""); /* link end */ | |
| 238 | ||
| 6513 | 239 | g_hash_table_insert(ht, "<black>", "<FONT COLOR=\"#000000\">"); |
| 240 | g_hash_table_insert(ht, "<blue>", "<FONT COLOR=\"#0000FF\">"); | |
| 241 | g_hash_table_insert(ht, "<cyan>", "<FONT COLOR=\"#008284\">"); | |
| 242 | g_hash_table_insert(ht, "<gray>", "<FONT COLOR=\"#848284\">"); | |
| 243 | g_hash_table_insert(ht, "<green>", "<FONT COLOR=\"#008200\">"); | |
| 244 | g_hash_table_insert(ht, "<pink>", "<FONT COLOR=\"#FF0084\">"); | |
| 245 | g_hash_table_insert(ht, "<purple>", "<FONT COLOR=\"#840084\">"); | |
| 246 | g_hash_table_insert(ht, "<orange>", "<FONT COLOR=\"#FF8000\">"); | |
| 247 | g_hash_table_insert(ht, "<red>", "<FONT COLOR=\"#FF0000\">"); | |
| 248 | g_hash_table_insert(ht, "<yellow>", "<FONT COLOR=\"#848200\">"); | |
| 249 | ||
| 250 | g_hash_table_insert(ht, "</black>", "</FONT>"); | |
| 251 | g_hash_table_insert(ht, "</blue>", "</FONT>"); | |
| 252 | g_hash_table_insert(ht, "</cyan>", "</FONT>"); | |
| 253 | g_hash_table_insert(ht, "</gray>", "</FONT>"); | |
| 254 | g_hash_table_insert(ht, "</green>", "</FONT>"); | |
| 255 | g_hash_table_insert(ht, "</pink>", "</FONT>"); | |
| 256 | g_hash_table_insert(ht, "</purple>", "</FONT>"); | |
| 257 | g_hash_table_insert(ht, "</orange>", "</FONT>"); | |
| 258 | g_hash_table_insert(ht, "</red>", "</FONT>"); | |
| 259 | g_hash_table_insert(ht, "</yellow>", "</FONT>"); | |
| 260 | ||
| 261 | /* remove these once we have proper support for <FADE> and <ALT> */ | |
| 262 | g_hash_table_insert(ht, "</fade>", ""); | |
| 263 | g_hash_table_insert(ht, "</alt>", ""); | |
| 8375 | 264 | |
| 265 | /* these are the normal html yahoo sends (besides <font>). | |
| 266 | * anything else will get turned into <tag>, so if I forgot | |
| 267 | * about something, please add it. Why Yahoo! has to send unescaped | |
| 268 | * <'s and >'s that aren't supposed to be html is beyond me. | |
| 269 | */ | |
| 270 | g_hash_table_insert(ht, "<b>", "<b>"); | |
| 271 | g_hash_table_insert(ht, "<i>", "<i>"); | |
| 272 | g_hash_table_insert(ht, "<u>", "<u>"); | |
| 273 | ||
| 274 | g_hash_table_insert(ht, "</b>", "</b>"); | |
| 275 | g_hash_table_insert(ht, "</i>", "</i>"); | |
| 276 | g_hash_table_insert(ht, "</u>", "</u>"); | |
| 8440 | 277 | g_hash_table_insert(ht, "</font>", "</font>"); |
| 6513 | 278 | } |
| 279 | ||
| 280 | void yahoo_dest_colorht() | |
| 281 | { | |
| 282 | g_hash_table_destroy(ht); | |
| 283 | } | |
| 284 | ||
| 6629 | 285 | static int point_to_html(int x) |
| 286 | { | |
| 287 | if (x < 9) | |
| 288 | return 1; | |
| 289 | if (x < 11) | |
| 290 | return 2; | |
| 291 | if (x < 13) | |
| 292 | return 3; | |
| 293 | if (x < 17) | |
| 294 | return 4; | |
| 295 | if (x < 25) | |
| 296 | return 5; | |
| 297 | if (x < 35) | |
| 298 | return 6; | |
| 299 | return 7; | |
| 300 | } | |
|
10380
8608e553808f
[gaim-migrate @ 11605]
Evan Schoenberg <evands@pidgin.im>
parents:
10023
diff
changeset
|
301 | |
|
8608e553808f
[gaim-migrate @ 11605]
Evan Schoenberg <evands@pidgin.im>
parents:
10023
diff
changeset
|
302 | /* The Yahoo size tag is actually an absz tag; convert it to an HTML size, and include both tags */ |
| 6629 | 303 | static void _font_tags_fix_size(GString *tag, GString *dest) |
| 304 | { | |
| 305 | char *x, *end; | |
| 306 | int size; | |
| 307 | ||
|
13710
c8376b63ca31
[gaim-migrate @ 16112]
Richard Laager <rlaager@pidgin.im>
parents:
11644
diff
changeset
|
308 | if (((x = strstr(tag->str, "size"))) && ((x = strchr(x, '=')))) { |
| 6629 | 309 | while (*x && !g_ascii_isdigit(*x)) |
| 310 | x++; | |
| 311 | if (*x) { | |
|
10380
8608e553808f
[gaim-migrate @ 11605]
Evan Schoenberg <evands@pidgin.im>
parents:
10023
diff
changeset
|
312 | int htmlsize; |
|
8608e553808f
[gaim-migrate @ 11605]
Evan Schoenberg <evands@pidgin.im>
parents:
10023
diff
changeset
|
313 | |
| 6629 | 314 | size = strtol(x, &end, 10); |
|
10380
8608e553808f
[gaim-migrate @ 11605]
Evan Schoenberg <evands@pidgin.im>
parents:
10023
diff
changeset
|
315 | htmlsize = point_to_html(size); |
| 6629 | 316 | g_string_append_len(dest, tag->str, x - tag->str); |
|
10380
8608e553808f
[gaim-migrate @ 11605]
Evan Schoenberg <evands@pidgin.im>
parents:
10023
diff
changeset
|
317 | g_string_append_printf(dest, "%d", htmlsize); |
|
8608e553808f
[gaim-migrate @ 11605]
Evan Schoenberg <evands@pidgin.im>
parents:
10023
diff
changeset
|
318 | g_string_append_printf(dest, "\" absz=\"%d", size); |
| 6629 | 319 | g_string_append(dest, end); |
| 320 | } else { | |
| 321 | g_string_append(dest, tag->str); | |
| 322 | return; | |
| 323 | } | |
| 324 | } else { | |
| 325 | g_string_append(dest, tag->str); | |
| 326 | return; | |
| 327 | } | |
| 328 | } | |
| 329 | ||
| 330 | char *yahoo_codes_to_html(const char *x) | |
| 6513 | 331 | { |
| 332 | GString *s, *tmp; | |
| 6629 | 333 | int i, j, xs, nomoreendtags = 0; /* s/endtags/closinganglebrackets */ |
| 6513 | 334 | char *match, *ret; |
| 335 | ||
| 336 | s = g_string_sized_new(strlen(x)); | |
| 337 | ||
| 338 | for (i = 0, xs = strlen(x); i < xs; i++) { | |
| 339 | if ((x[i] == 0x1b) && (x[i+1] == '[')) { | |
| 340 | j = i + 1; | |
| 341 | ||
| 342 | while (j++ < xs) { | |
| 343 | if (x[j] != 'm') | |
| 344 | continue; | |
| 345 | else { | |
| 346 | 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
|
347 | if (tmp->str[0] == '#') |
| 6513 | 348 | g_string_append_printf(s, "<FONT COLOR=\"%s\">", tmp->str); |
|
6546
6a14dfe43d5c
[gaim-migrate @ 7068]
Mark Doliner <markdoliner@pidgin.im>
parents:
6513
diff
changeset
|
349 | else if ((match = (char *) g_hash_table_lookup(ht, tmp->str))) |
| 6513 | 350 | g_string_append(s, match); |
| 351 | else { | |
| 15884 | 352 | purple_debug(PURPLE_DEBUG_ERROR, "yahoo", |
| 6513 | 353 | "Unknown ansi code 'ESC[%sm'.\n", tmp->str); |
| 354 | g_string_free(tmp, TRUE); | |
| 355 | break; | |
| 356 | } | |
| 357 | ||
| 358 | i = j; | |
| 359 | g_string_free(tmp, TRUE); | |
| 360 | break; | |
| 361 | } | |
| 362 | } | |
| 363 | ||
| 364 | } else if (!nomoreendtags && (x[i] == '<')) { | |
| 6629 | 365 | j = i; |
| 6513 | 366 | |
| 367 | while (j++ < xs) { | |
| 368 | if (x[j] != '>') | |
| 369 | if (j == xs) { | |
| 8375 | 370 | g_string_append(s, "<"); |
| 6513 | 371 | nomoreendtags = 1; |
| 372 | } | |
| 373 | else | |
| 374 | continue; | |
| 375 | else { | |
| 376 | tmp = g_string_new_len(x + i, j - i + 1); | |
| 377 | g_string_ascii_down(tmp); | |
| 378 | ||
|
6546
6a14dfe43d5c
[gaim-migrate @ 7068]
Mark Doliner <markdoliner@pidgin.im>
parents:
6513
diff
changeset
|
379 | if ((match = (char *) g_hash_table_lookup(ht, tmp->str))) |
| 6513 | 380 | g_string_append(s, match); |
| 6629 | 381 | else if (!strncmp(tmp->str, "<fade ", 6) || |
| 382 | !strncmp(tmp->str, "<alt ", 5) || | |
| 383 | !strncmp(tmp->str, "<snd ", 5)) { | |
| 6513 | 384 | |
| 6629 | 385 | /* remove this if gtkimhtml ever supports any of these */ |
| 6513 | 386 | i = j; |
| 387 | g_string_free(tmp, TRUE); | |
| 388 | break; | |
| 389 | ||
| 6629 | 390 | } else if (!strncmp(tmp->str, "<font ", 6)) { |
| 391 | _font_tags_fix_size(tmp, s); | |
| 6513 | 392 | } else { |
| 8375 | 393 | g_string_append(s, "<"); |
| 6513 | 394 | g_string_free(tmp, TRUE); |
| 395 | break; | |
| 396 | } | |
| 397 | ||
| 398 | i = j; | |
| 399 | g_string_free(tmp, TRUE); | |
| 400 | break; | |
| 401 | } | |
| 402 | ||
| 403 | } | |
| 404 | ||
| 405 | } else { | |
| 8375 | 406 | if (x[i] == '<') |
| 407 | g_string_append(s, "<"); | |
| 408 | else if (x[i] == '>') | |
| 409 | g_string_append(s, ">"); | |
| 8440 | 410 | else if (x[i] == '&') |
| 411 | g_string_append(s, "&"); | |
| 412 | else if (x[i] == '"') | |
| 413 | g_string_append(s, """); | |
| 8375 | 414 | else |
| 415 | g_string_append_c(s, x[i]); | |
| 6513 | 416 | } |
| 417 | } | |
| 418 | ||
| 419 | ret = s->str; | |
| 420 | g_string_free(s, FALSE); | |
| 15884 | 421 | purple_debug(PURPLE_DEBUG_MISC, "yahoo", "yahoo_codes_to_html: Returning string: '%s'.\n", ret); |
| 6513 | 422 | return ret; |
| 423 | } | |
| 6629 | 424 | |
| 425 | /* borrowed from gtkimhtml */ | |
| 426 | #define MAX_FONT_SIZE 7 | |
|
10899
87d9aec5b72d
[gaim-migrate @ 12619]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10504
diff
changeset
|
427 | #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
|
428 | static const gint _point_sizes [] = { 8, 10, 12, 14, 20, 30, 40 }; |
| 6629 | 429 | |
| 430 | enum fatype { size, color, face, junk }; | |
| 431 | typedef struct { | |
| 432 | enum fatype type; | |
| 433 | union { | |
| 434 | int size; | |
| 435 | char *color; | |
| 436 | char *face; | |
| 437 | char *junk; | |
| 438 | } u; | |
| 439 | } fontattr; | |
| 440 | ||
| 441 | static void fontattr_free(fontattr *f) | |
| 442 | { | |
| 443 | if (f->type == color) | |
| 444 | g_free(f->u.color); | |
| 445 | else if (f->type == face) | |
| 446 | g_free(f->u.face); | |
| 447 | g_free(f); | |
| 448 | } | |
| 449 | ||
| 450 | static void yahoo_htc_queue_cleanup(GQueue *q) | |
| 451 | { | |
| 452 | char *tmp; | |
| 453 | ||
| 454 | while ((tmp = g_queue_pop_tail(q))) | |
| 455 | g_free(tmp); | |
| 456 | g_queue_free(q); | |
| 457 | } | |
| 458 | ||
| 459 | static void _parse_font_tag(const char *src, GString *dest, int *i, int *j, | |
| 460 | int len, GQueue *colors, GQueue *tags, GQueue *ftattr) | |
| 461 | { | |
| 462 | ||
| 463 | int m, n, vstart; | |
| 464 | gboolean quote = 0, done = 0; | |
| 465 | ||
| 466 | m = *j; | |
| 467 | ||
| 468 | while (1) { | |
| 469 | m++; | |
| 470 | ||
| 471 | if (m >= len) { | |
| 472 | g_string_append(dest, &src[*i]); | |
| 473 | *i = len; | |
| 474 | break; | |
| 475 | } | |
| 476 | ||
| 477 | if (src[m] == '=') { | |
| 478 | n = vstart = m; | |
| 479 | while (1) { | |
| 480 | n++; | |
| 481 | ||
| 482 | if (n >= len) { | |
| 483 | m = n; | |
| 484 | break; | |
| 485 | } | |
| 486 | ||
|
6631
a2608d595a32
[gaim-migrate @ 7155]
Björn Voigt <bjoern@cs.tu-berlin.de>
parents:
6629
diff
changeset
|
487 | if (src[n] == '"') { |
| 6629 | 488 | if (!quote) { |
| 489 | quote = 1; | |
| 490 | vstart = n; | |
| 491 | continue; | |
| 492 | } else { | |
| 493 | done = 1; | |
| 494 | } | |
|
6631
a2608d595a32
[gaim-migrate @ 7155]
Björn Voigt <bjoern@cs.tu-berlin.de>
parents:
6629
diff
changeset
|
495 | } |
| 6629 | 496 | |
| 497 | if (!quote && ((src[n] == ' ') || (src[n] == '>'))) | |
| 498 | done = 1; | |
| 499 | ||
| 500 | if (done) { | |
| 501 | if (!g_ascii_strncasecmp(&src[*j+1], "FACE", m - *j - 1)) { | |
| 502 | fontattr *f; | |
| 503 | ||
| 504 | f = g_new(fontattr, 1); | |
| 505 | f->type = face; | |
| 506 | f->u.face = g_strndup(&src[vstart+1], n-vstart-1); | |
| 507 | if (!ftattr) | |
| 508 | ftattr = g_queue_new(); | |
| 509 | g_queue_push_tail(ftattr, f); | |
| 510 | m = n; | |
| 511 | break; | |
| 512 | } else if (!g_ascii_strncasecmp(&src[*j+1], "SIZE", m - *j - 1)) { | |
| 513 | fontattr *f; | |
| 514 | ||
| 515 | f = g_new(fontattr, 1); | |
| 516 | f->type = size; | |
| 517 | f->u.size = POINT_SIZE(strtol(&src[vstart+1], NULL, 10)); | |
| 518 | if (!ftattr) | |
| 519 | ftattr = g_queue_new(); | |
| 520 | g_queue_push_tail(ftattr, f); | |
| 521 | m = n; | |
| 522 | break; | |
| 523 | } else if (!g_ascii_strncasecmp(&src[*j+1], "COLOR", m - *j - 1)) { | |
| 524 | fontattr *f; | |
| 525 | ||
| 526 | f = g_new(fontattr, 1); | |
| 527 | f->type = color; | |
| 528 | f->u.color = g_strndup(&src[vstart+1], n-vstart-1); | |
| 529 | if (!ftattr) | |
| 530 | ftattr = g_queue_new(); | |
| 531 | g_queue_push_head(ftattr, f); | |
| 532 | m = n; | |
| 533 | break; | |
| 534 | } else { | |
| 535 | fontattr *f; | |
| 536 | ||
| 537 | f = g_new(fontattr, 1); | |
| 538 | f->type = junk; | |
| 539 | f->u.junk = g_strndup(&src[*j+1], n-*j); | |
| 540 | if (!ftattr) | |
| 541 | ftattr = g_queue_new(); | |
| 542 | g_queue_push_tail(ftattr, f); | |
| 543 | m = n; | |
| 544 | break; | |
| 545 | } | |
| 546 | ||
| 547 | } | |
| 548 | } | |
| 549 | } | |
| 550 | ||
| 551 | if (src[m] == ' ') | |
| 552 | *j = m; | |
| 553 | ||
| 554 | if (src[m] == '>') { | |
| 555 | gboolean needendtag = 0; | |
| 556 | fontattr *f; | |
| 557 | GString *tmp = g_string_new(NULL); | |
| 558 | char *colorstr; | |
| 559 | ||
| 560 | if (!g_queue_is_empty(ftattr)) { | |
| 561 | while ((f = g_queue_pop_tail(ftattr))) { | |
| 562 | switch (f->type) { | |
| 563 | case size: | |
| 564 | if (!needendtag) { | |
| 565 | needendtag = 1; | |
| 566 | g_string_append(dest, "<font "); | |
| 567 | } | |
| 568 | ||
| 569 | g_string_append_printf(dest, "size=\"%d\" ", f->u.size); | |
| 570 | fontattr_free(f); | |
| 571 | break; | |
| 572 | case face: | |
| 573 | if (!needendtag) { | |
| 574 | needendtag = 1; | |
| 575 | g_string_append(dest, "<font "); | |
| 576 | } | |
| 577 | ||
| 578 | g_string_append_printf(dest, "face=\"%s\" ", f->u.face); | |
| 579 | fontattr_free(f); | |
| 580 | break; | |
| 581 | case junk: | |
| 582 | if (!needendtag) { | |
| 583 | needendtag = 1; | |
| 584 | g_string_append(dest, "<font "); | |
| 585 | } | |
| 586 | ||
| 587 | g_string_append(dest, f->u.junk); | |
| 588 | fontattr_free(f); | |
| 589 | break; | |
| 590 | ||
| 591 | case color: | |
| 592 | if (needendtag) { | |
| 593 | g_string_append(tmp, "</font>"); | |
| 594 | dest->str[dest->len-1] = '>'; | |
| 595 | needendtag = 0; | |
| 596 | } | |
| 597 | ||
| 598 | colorstr = g_queue_peek_tail(colors); | |
| 599 | g_string_append(tmp, colorstr ? colorstr : "\033[#000000m"); | |
| 600 | g_string_append_printf(dest, "\033[%sm", f->u.color); | |
| 601 | g_queue_push_tail(colors, g_strdup_printf("\033[%sm", f->u.color)); | |
| 602 | fontattr_free(f); | |
| 603 | break; | |
| 604 | } | |
| 605 | } | |
| 606 | ||
| 607 | g_queue_free(ftattr); | |
| 608 | ftattr = NULL; | |
| 609 | ||
| 610 | if (needendtag) { | |
| 611 | dest->str[dest->len-1] = '>'; | |
| 612 | g_queue_push_tail(tags, g_strdup("</font>")); | |
| 613 | g_string_free(tmp, TRUE); | |
| 614 | } else { | |
| 615 | g_queue_push_tail(tags, tmp->str); | |
| 616 | g_string_free(tmp, FALSE); | |
| 617 | } | |
| 618 | } | |
| 619 | ||
| 620 | *i = *j = m; | |
| 621 | break; | |
| 622 | } | |
| 623 | } | |
| 624 | ||
| 625 | } | |
| 626 | ||
| 627 | char *yahoo_html_to_codes(const char *src) | |
| 628 | { | |
|
6631
a2608d595a32
[gaim-migrate @ 7155]
Björn Voigt <bjoern@cs.tu-berlin.de>
parents:
6629
diff
changeset
|
629 | int i, j, len; |
| 6629 | 630 | GString *dest; |
| 631 | char *ret, *esc; | |
| 632 | GQueue *colors, *tags; | |
| 633 | GQueue *ftattr = NULL; | |
| 8440 | 634 | gboolean no_more_specials = FALSE; |
| 6629 | 635 | |
| 636 | colors = g_queue_new(); | |
| 637 | tags = g_queue_new(); | |
| 638 | dest = g_string_sized_new(strlen(src)); | |
| 639 | ||
| 640 | for (i = 0, len = strlen(src); i < len; i++) { | |
| 641 | ||
| 8440 | 642 | if (!no_more_specials && src[i] == '<') { |
| 6629 | 643 | j = i; |
| 644 | ||
| 645 | while (1) { | |
| 646 | j++; | |
| 647 | ||
| 648 | if (j >= len) { /* no '>' */ | |
| 8440 | 649 | g_string_append_c(dest, src[i]); |
| 650 | no_more_specials = TRUE; | |
| 6629 | 651 | break; |
| 652 | } | |
| 653 | ||
| 654 | if (src[j] == '<') { | |
| 8440 | 655 | /* FIXME: This doesn't convert outgoing entities. |
| 656 | * However, I suspect this case may never | |
| 657 | * happen anymore because of the entities. | |
| 658 | */ | |
| 6629 | 659 | g_string_append_len(dest, &src[i], j - i); |
| 660 | i = j - 1; | |
| 661 | if (ftattr) { | |
| 662 | fontattr *f; | |
| 663 | ||
| 664 | while ((f = g_queue_pop_head(ftattr))) | |
| 665 | fontattr_free(f); | |
| 666 | g_queue_free(ftattr); | |
| 667 | ftattr = NULL; | |
| 668 | } | |
| 669 | break; | |
| 670 | } | |
| 671 | ||
| 672 | if (src[j] == ' ') { | |
| 673 | if (!g_ascii_strncasecmp(&src[i+1], "BODY", j - i - 1)) { | |
| 674 | char *t = strchr(&src[j], '>'); | |
| 675 | if (!t) { | |
| 676 | g_string_append(dest, &src[i]); | |
| 677 | i = len; | |
| 678 | break; | |
| 679 | } else { | |
| 680 | i = t - src; | |
| 681 | break; | |
| 682 | } | |
| 8533 | 683 | } else if (!g_ascii_strncasecmp(&src[i+1], "A HREF=\"", j - i - 1)) { |
| 684 | j += 7; | |
| 685 | g_string_append(dest, "\033[lm"); | |
| 686 | while (1) { | |
| 687 | g_string_append_c(dest, src[j]); | |
| 688 | if (++j >= len) { | |
| 8480 | 689 | i = len; |
| 690 | break; | |
| 691 | } | |
| 8533 | 692 | if (src[j] == '"') { |
| 693 | g_string_append(dest, "\033[xlm"); | |
| 694 | while (1) { | |
| 695 | if (++j >= len) { | |
| 696 | i = len; | |
| 697 | break; | |
| 698 | } | |
| 699 | if (!g_ascii_strncasecmp(&src[j], "</A>", 4)) { | |
| 700 | j += 3; | |
| 701 | break; | |
| 702 | } | |
| 703 | } | |
| 704 | i = j; | |
| 8480 | 705 | break; |
| 706 | } | |
| 707 | } | |
|
16169
4aa4ec9afa9c
Stop Yahoo sending SPAN tags, fixes Yahoo part of ticket 78
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
708 | } 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
|
709 | while (1) { |
|
4aa4ec9afa9c
Stop Yahoo sending SPAN tags, fixes Yahoo part of ticket 78
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
710 | if (++j >= len) { |
|
4aa4ec9afa9c
Stop Yahoo sending SPAN tags, fixes Yahoo part of ticket 78
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
711 | 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
|
712 | i = len; |
|
4aa4ec9afa9c
Stop Yahoo sending SPAN tags, fixes Yahoo part of ticket 78
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
713 | break; |
|
4aa4ec9afa9c
Stop Yahoo sending SPAN tags, fixes Yahoo part of ticket 78
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
714 | } |
|
4aa4ec9afa9c
Stop Yahoo sending SPAN tags, fixes Yahoo part of ticket 78
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
715 | if (src[j] == '>') { |
|
4aa4ec9afa9c
Stop Yahoo sending SPAN tags, fixes Yahoo part of ticket 78
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
716 | i = j; |
|
4aa4ec9afa9c
Stop Yahoo sending SPAN tags, fixes Yahoo part of ticket 78
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
717 | break; |
|
4aa4ec9afa9c
Stop Yahoo sending SPAN tags, fixes Yahoo part of ticket 78
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
718 | } |
|
4aa4ec9afa9c
Stop Yahoo sending SPAN tags, fixes Yahoo part of ticket 78
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
719 | } |
| 6629 | 720 | } else if (g_ascii_strncasecmp(&src[i+1], "FONT", j - i - 1)) { /* not interested! */ |
| 721 | while (1) { | |
| 722 | if (++j >= len) { | |
| 723 | g_string_append(dest, &src[i]); | |
| 724 | i = len; | |
| 725 | break; | |
| 726 | } | |
| 727 | if (src[j] == '>') { | |
| 728 | g_string_append_len(dest, &src[i], j - i + 1); | |
| 729 | i = j; | |
| 730 | break; | |
| 731 | } | |
| 732 | } | |
| 733 | } else { /* yay we have a font tag */ | |
| 734 | _parse_font_tag(src, dest, &i, &j, len, colors, tags, ftattr); | |
| 735 | } | |
| 736 | ||
| 737 | break; | |
| 738 | } | |
| 739 | ||
| 740 | if (src[j] == '>') { | |
| 8440 | 741 | /* This has some problems like the FIXME for the |
| 742 | * '<' case. and like that case, I suspect the case | |
| 743 | * that this has problems is won't happen anymore anyway. | |
| 744 | */ | |
| 6629 | 745 | int sublen = j - i - 1; |
| 746 | ||
| 747 | if (sublen) { | |
| 748 | if (!g_ascii_strncasecmp(&src[i+1], "B", sublen)) { | |
| 749 | g_string_append(dest, "\033[1m"); | |
| 750 | } else if (!g_ascii_strncasecmp(&src[i+1], "/B", sublen)) { | |
| 751 | g_string_append(dest, "\033[x1m"); | |
| 752 | } else if (!g_ascii_strncasecmp(&src[i+1], "I", sublen)) { | |
| 753 | g_string_append(dest, "\033[2m"); | |
| 754 | } else if (!g_ascii_strncasecmp(&src[i+1], "/I", sublen)) { | |
| 755 | g_string_append(dest, "\033[x2m"); | |
| 756 | } else if (!g_ascii_strncasecmp(&src[i+1], "U", sublen)) { | |
| 757 | g_string_append(dest, "\033[4m"); | |
| 758 | } else if (!g_ascii_strncasecmp(&src[i+1], "/U", sublen)) { | |
| 759 | g_string_append(dest, "\033[x4m"); | |
| 8480 | 760 | } else if (!g_ascii_strncasecmp(&src[i+1], "/A", sublen)) { |
| 761 | g_string_append(dest, "\033[xlm"); | |
| 8455 | 762 | } else if (!g_ascii_strncasecmp(&src[i+1], "BR", sublen)) { |
| 763 | g_string_append_c(dest, '\n'); | |
| 6629 | 764 | } else if (!g_ascii_strncasecmp(&src[i+1], "/BODY", sublen)) { |
| 765 | /* 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
|
766 | } 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
|
767 | /* </span> tags. dangerously close to </spam> */ |
| 6629 | 768 | } else if (!g_ascii_strncasecmp(&src[i+1], "/FONT", sublen) && g_queue_peek_tail(tags)) { |
| 769 | char *etag, *cl; | |
| 770 | ||
| 771 | etag = g_queue_pop_tail(tags); | |
| 772 | if (etag) { | |
| 773 | g_string_append(dest, etag); | |
| 774 | if (!strcmp(etag, "</font>")) { | |
| 775 | cl = g_queue_pop_tail(colors); | |
| 776 | if (cl) | |
| 777 | g_free(cl); | |
| 778 | } | |
| 779 | g_free(etag); | |
| 780 | } | |
| 781 | } else { | |
| 782 | g_string_append_len(dest, &src[i], j - i + 1); | |
| 783 | } | |
| 784 | } else { | |
| 785 | g_string_append_len(dest, &src[i], j - i + 1); | |
| 786 | } | |
| 787 | ||
| 788 | i = j; | |
| 789 | break; | |
| 790 | } | |
| 791 | ||
| 792 | } | |
| 793 | ||
| 794 | } else { | |
| 8440 | 795 | if (((len - i) >= 4) && !strncmp(&src[i], "<", 4)) { |
| 796 | g_string_append_c(dest, '<'); | |
| 797 | i += 3; | |
| 798 | } else if (((len - i) >= 4) && !strncmp(&src[i], ">", 4)) { | |
| 799 | g_string_append_c(dest, '>'); | |
| 800 | 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
|
801 | } else if (((len - i) >= 5) && !strncmp(&src[i], "&", 5)) { |
| 8440 | 802 | g_string_append_c(dest, '&'); |
| 803 | 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
|
804 | } else if (((len - i) >= 6) && !strncmp(&src[i], """, 6)) { |
| 8440 | 805 | g_string_append_c(dest, '"'); |
| 806 | 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
|
807 | } 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
|
808 | 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
|
809 | i += 5; |
| 8440 | 810 | } else { |
| 811 | g_string_append_c(dest, src[i]); | |
| 812 | } | |
| 6629 | 813 | } |
| 814 | } | |
| 815 | ||
| 816 | ret = dest->str; | |
| 817 | g_string_free(dest, FALSE); | |
| 818 | ||
| 819 | esc = g_strescape(ret, NULL); | |
| 15884 | 820 | purple_debug(PURPLE_DEBUG_MISC, "yahoo", "yahoo_html_to_codes: Returning string: '%s'.\n", esc); |
| 6629 | 821 | g_free(esc); |
| 822 | ||
| 823 | yahoo_htc_queue_cleanup(colors); | |
| 824 | yahoo_htc_queue_cleanup(tags); | |
| 825 | ||
| 826 | return ret; | |
| 827 | } |