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