annotate libpurple/protocols/yahoo/util.c @ 28435:4a2adf413aaa

merged with im.pidgin.pidgin
author Yoshiki Yazawa <yaz@honeyplanet.jp>
date Mon, 24 Aug 2009 17:20:46 +0900
parents 94abbb806273 1d2425f2e4ff
children 7c33fccedea8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1 /*
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
2 * purple
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3 *
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4 * Some code copyright 2003 Tim Ringenbach <omarvo@hotmail.com>
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
5 * (marv on irc.freenode.net)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
6 *
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
7 * This program is free software; you can redistribute it and/or modify
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
8 * it under the terms of the GNU General Public License as published by
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
9 * the Free Software Foundation; either version 2 of the License, or
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
10 * (at your option) any later version.
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
11 *
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
15 * GNU General Public License for more details.
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
16 *
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
17 * You should have received a copy of the GNU General Public License
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
18 * along with this program; if not, write to the Free Software
19680
44b4e8bd759b The FSF changed its address a while ago; our files were out of date.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 19197
diff changeset
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
20 *
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
21 */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
22
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
23 #ifdef HAVE_CONFIG_H
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
24 #include "config.h"
27193
510f07e1f5c1 Strip trailing whitespace and comment #endif marcos that close #ifdef macros
Mark Doliner <mark@kingant.net>
parents: 23916
diff changeset
25 #endif /* HAVE_CONFIG_H */
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
26
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
27 #include "debug.h"
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
28 #include "internal.h"
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
29 #include "prpl.h"
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
30
27395
ef5f0cde8d74 Update for file renames.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 27384
diff changeset
31 #include "libymsg.h"
25467
be098f796b32 yaz patch has been applied.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 16109
diff changeset
32 #include "util.h"
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
33
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
34 #include <string.h>
23916
18a1f0fe5f40 Do a better job of detecting if the yahoo account is connecting through a HTTP
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23033
diff changeset
35
18a1f0fe5f40 Do a better job of detecting if the yahoo account is connecting through a HTTP
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23033
diff changeset
36 gboolean
18a1f0fe5f40 Do a better job of detecting if the yahoo account is connecting through a HTTP
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23033
diff changeset
37 yahoo_account_use_http_proxy(PurpleConnection *conn)
18a1f0fe5f40 Do a better job of detecting if the yahoo account is connecting through a HTTP
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23033
diff changeset
38 {
18a1f0fe5f40 Do a better job of detecting if the yahoo account is connecting through a HTTP
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23033
diff changeset
39 PurpleProxyInfo *ppi = purple_proxy_get_setup(conn->account);
18a1f0fe5f40 Do a better job of detecting if the yahoo account is connecting through a HTTP
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23033
diff changeset
40 return (ppi->type == PURPLE_PROXY_HTTP || ppi->type == PURPLE_PROXY_USE_ENVVAR);
18a1f0fe5f40 Do a better job of detecting if the yahoo account is connecting through a HTTP
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23033
diff changeset
41 }
18a1f0fe5f40 Do a better job of detecting if the yahoo account is connecting through a HTTP
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23033
diff changeset
42
22018
118046227581 This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan <madthanu@gmail.com>
parents: 21831
diff changeset
43 /*
118046227581 This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan <madthanu@gmail.com>
parents: 21831
diff changeset
44 * Returns cookies formatted as a null terminated string for the given connection.
118046227581 This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan <madthanu@gmail.com>
parents: 21831
diff changeset
45 * Must g_free return value.
27193
510f07e1f5c1 Strip trailing whitespace and comment #endif marcos that close #ifdef macros
Mark Doliner <mark@kingant.net>
parents: 23916
diff changeset
46 *
22018
118046227581 This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan <madthanu@gmail.com>
parents: 21831
diff changeset
47 * TODO:will work, but must test for strict correctness
118046227581 This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan <madthanu@gmail.com>
parents: 21831
diff changeset
48 */
118046227581 This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan <madthanu@gmail.com>
parents: 21831
diff changeset
49 gchar* yahoo_get_cookies(PurpleConnection *gc)
118046227581 This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan <madthanu@gmail.com>
parents: 21831
diff changeset
50 {
118046227581 This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan <madthanu@gmail.com>
parents: 21831
diff changeset
51 gchar *ans = NULL;
118046227581 This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan <madthanu@gmail.com>
parents: 21831
diff changeset
52 gchar *cur;
118046227581 This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan <madthanu@gmail.com>
parents: 21831
diff changeset
53 char firstflag = 1;
118046227581 This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan <madthanu@gmail.com>
parents: 21831
diff changeset
54 gchar *t1,*t2,*t3;
118046227581 This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan <madthanu@gmail.com>
parents: 21831
diff changeset
55 GSList *tmp;
118046227581 This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan <madthanu@gmail.com>
parents: 21831
diff changeset
56 GSList *cookies;
28025
908be3822215 Move from "struct yahoo_data" to "YahooData" to be consistent with other structs
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 27501
diff changeset
57 cookies = ((YahooData*)(gc->proto_data))->cookies;
22018
118046227581 This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan <madthanu@gmail.com>
parents: 21831
diff changeset
58 tmp = cookies;
118046227581 This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan <madthanu@gmail.com>
parents: 21831
diff changeset
59 while(tmp)
118046227581 This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan <madthanu@gmail.com>
parents: 21831
diff changeset
60 {
118046227581 This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan <madthanu@gmail.com>
parents: 21831
diff changeset
61 cur = tmp->data;
118046227581 This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan <madthanu@gmail.com>
parents: 21831
diff changeset
62 t1 = ans;
118046227581 This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan <madthanu@gmail.com>
parents: 21831
diff changeset
63 t2 = g_strrstr(cur, ";expires=");
118046227581 This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan <madthanu@gmail.com>
parents: 21831
diff changeset
64 if(t2 == NULL)
118046227581 This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan <madthanu@gmail.com>
parents: 21831
diff changeset
65 t2 = g_strrstr(cur, "; expires=");
118046227581 This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan <madthanu@gmail.com>
parents: 21831
diff changeset
66 if(t2 == NULL)
118046227581 This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan <madthanu@gmail.com>
parents: 21831
diff changeset
67 {
118046227581 This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan <madthanu@gmail.com>
parents: 21831
diff changeset
68 if(firstflag)
118046227581 This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan <madthanu@gmail.com>
parents: 21831
diff changeset
69 ans = g_strdup_printf("%c=%s", cur[0], cur+2);
118046227581 This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan <madthanu@gmail.com>
parents: 21831
diff changeset
70 else
118046227581 This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan <madthanu@gmail.com>
parents: 21831
diff changeset
71 ans = g_strdup_printf("%s; %c=%s", t1, cur[0], cur+2);
118046227581 This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan <madthanu@gmail.com>
parents: 21831
diff changeset
72 }
118046227581 This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan <madthanu@gmail.com>
parents: 21831
diff changeset
73 else
118046227581 This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan <madthanu@gmail.com>
parents: 21831
diff changeset
74 {
118046227581 This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan <madthanu@gmail.com>
parents: 21831
diff changeset
75 t3 = strstr(t2+1, ";");
118046227581 This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan <madthanu@gmail.com>
parents: 21831
diff changeset
76 if(t3 != NULL)
118046227581 This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan <madthanu@gmail.com>
parents: 21831
diff changeset
77 {
118046227581 This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan <madthanu@gmail.com>
parents: 21831
diff changeset
78 t2[0] = '\0';
118046227581 This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan <madthanu@gmail.com>
parents: 21831
diff changeset
79
118046227581 This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan <madthanu@gmail.com>
parents: 21831
diff changeset
80 if(firstflag)
118046227581 This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan <madthanu@gmail.com>
parents: 21831
diff changeset
81 ans = g_strdup_printf("%c=%s%s", cur[0], cur+2, t3);
118046227581 This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan <madthanu@gmail.com>
parents: 21831
diff changeset
82 else
118046227581 This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan <madthanu@gmail.com>
parents: 21831
diff changeset
83 ans = g_strdup_printf("%s; %c=%s%s", t1, cur[0], cur+2, t3);
118046227581 This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan <madthanu@gmail.com>
parents: 21831
diff changeset
84
118046227581 This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan <madthanu@gmail.com>
parents: 21831
diff changeset
85 t2[0] = ';';
118046227581 This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan <madthanu@gmail.com>
parents: 21831
diff changeset
86 }
118046227581 This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan <madthanu@gmail.com>
parents: 21831
diff changeset
87 else
118046227581 This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan <madthanu@gmail.com>
parents: 21831
diff changeset
88 {
118046227581 This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan <madthanu@gmail.com>
parents: 21831
diff changeset
89 t2[0] = '\0';
118046227581 This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan <madthanu@gmail.com>
parents: 21831
diff changeset
90
118046227581 This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan <madthanu@gmail.com>
parents: 21831
diff changeset
91 if(firstflag)
118046227581 This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan <madthanu@gmail.com>
parents: 21831
diff changeset
92 ans = g_strdup_printf("%c=%s", cur[0], cur+2);
118046227581 This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan <madthanu@gmail.com>
parents: 21831
diff changeset
93 else
118046227581 This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan <madthanu@gmail.com>
parents: 21831
diff changeset
94 ans = g_strdup_printf("%s; %c=%s", t1, cur[0], cur+2);
118046227581 This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan <madthanu@gmail.com>
parents: 21831
diff changeset
95
118046227581 This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan <madthanu@gmail.com>
parents: 21831
diff changeset
96 t2[0] = ';';
118046227581 This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan <madthanu@gmail.com>
parents: 21831
diff changeset
97 }
118046227581 This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan <madthanu@gmail.com>
parents: 21831
diff changeset
98 }
118046227581 This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan <madthanu@gmail.com>
parents: 21831
diff changeset
99 if(firstflag)
118046227581 This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan <madthanu@gmail.com>
parents: 21831
diff changeset
100 firstflag = 0;
118046227581 This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan <madthanu@gmail.com>
parents: 21831
diff changeset
101 else
118046227581 This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan <madthanu@gmail.com>
parents: 21831
diff changeset
102 g_free(t1);
118046227581 This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan <madthanu@gmail.com>
parents: 21831
diff changeset
103 tmp = g_slist_next(tmp);
118046227581 This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan <madthanu@gmail.com>
parents: 21831
diff changeset
104 }
118046227581 This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan <madthanu@gmail.com>
parents: 21831
diff changeset
105 return ans;
118046227581 This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan <madthanu@gmail.com>
parents: 21831
diff changeset
106 }
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
107
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
108 /**
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
109 * Encode some text to send to the yahoo server.
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
110 *
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
111 * @param gc The connection handle.
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
112 * @param str The null terminated utf8 string to encode.
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
113 * @param utf8 If not @c NULL, whether utf8 is okay or not.
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
114 * Even if it is okay, we may not use it. If we
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
115 * used it, we set this to @c TRUE, else to
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
116 * @c FALSE. If @c NULL, false is assumed, and
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
117 * it is not dereferenced.
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
118 * @return The g_malloced string in the appropriate encoding.
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
119 */
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
120 char *yahoo_string_encode(PurpleConnection *gc, const char *str, gboolean *utf8)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
121 {
28025
908be3822215 Move from "struct yahoo_data" to "YahooData" to be consistent with other structs
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 27501
diff changeset
122 YahooData *yd = gc->proto_data;
27769
c9b4fdb3fdb1 adapted to the transition to utf-8 of yahoo-jp.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 27760
diff changeset
123 char *ret = NULL;
27773
0f3a131d23da - import nosuke's hash 244 patch and others to yahoo plugin
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 27772
diff changeset
124 gsize newlen;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
125 const char *to_codeset;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
126
27854
fcd28c88459b revert one thing
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 27853
diff changeset
127 if (utf8 && *utf8) {
27769
c9b4fdb3fdb1 adapted to the transition to utf-8 of yahoo-jp.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 27760
diff changeset
128 return botch_utf((gchar *)str, strlen((gchar *)str), &newlen);
c9b4fdb3fdb1 adapted to the transition to utf-8 of yahoo-jp.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 27760
diff changeset
129 }
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
130
23033
bf7ce9629402 applied changes from a5e7a62db1d43009f4ff463b7fe67ff3a7275a78
Daniel Atallah <daniel.atallah@gmail.com>
parents: 22155
diff changeset
131 to_codeset = purple_account_get_string(purple_connection_get_account(gc), "local_charset", "ISO-8859-1");
bf7ce9629402 applied changes from a5e7a62db1d43009f4ff463b7fe67ff3a7275a78
Daniel Atallah <daniel.atallah@gmail.com>
parents: 22155
diff changeset
132 ret = g_convert_with_fallback(str, -1, to_codeset, "UTF-8", "?", NULL, NULL, NULL);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
133
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
134 if (ret)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
135 return ret;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
136 else
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
137 return g_strdup("");
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
138 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
139
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
140 /**
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
141 * Decode some text received from the server.
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
142 *
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
143 * @param gc The gc handle.
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
144 * @param str The null terminated string to decode.
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
145 * @param utf8 Did the server tell us it was supposed to be utf8?
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
146 * @return The decoded, utf-8 string, which must be g_free()'d.
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
147 */
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
148 char *yahoo_string_decode(PurpleConnection *gc, const char *str, gboolean utf8)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
149 {
28025
908be3822215 Move from "struct yahoo_data" to "YahooData" to be consistent with other structs
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 27501
diff changeset
150 YahooData *yd = gc->proto_data;
25467
be098f796b32 yaz patch has been applied.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 16109
diff changeset
151 char *ret, *tmp;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
152 const char *from_codeset;
27773
0f3a131d23da - import nosuke's hash 244 patch and others to yahoo plugin
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 27772
diff changeset
153 gsize newlen;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
154
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
155 if (utf8) {
27769
c9b4fdb3fdb1 adapted to the transition to utf-8 of yahoo-jp.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 27760
diff changeset
156 ret = sanitize_utf((gchar *)str, strlen((gchar *)str), &newlen);
c9b4fdb3fdb1 adapted to the transition to utf-8 of yahoo-jp.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 27760
diff changeset
157 if (g_utf8_validate(ret, -1, NULL))
c9b4fdb3fdb1 adapted to the transition to utf-8 of yahoo-jp.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 27760
diff changeset
158 return ret;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
159 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
160
27852
f473058e3839 yahoo status fix second try.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 27851
diff changeset
161 if (yd->jp && !utf8)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
162 from_codeset = "SHIFT_JIS";
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
163 else
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
164 from_codeset = purple_account_get_string(purple_connection_get_account(gc), "local_charset", "ISO-8859-1");
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
165
19197
47942d19f301 Use -1 as length with g_convert() functions instead of strlen()
Daniel Atallah <daniel.atallah@gmail.com>
parents: 16109
diff changeset
166 ret = g_convert_with_fallback(str, -1, "UTF-8", from_codeset, NULL, NULL, NULL, NULL);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
167
27853
ae2cc2905136 clean yahoo/util.c up.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 27852
diff changeset
168 if (ret) {
25467
be098f796b32 yaz patch has been applied.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 16109
diff changeset
169 tmp = ret;
27769
c9b4fdb3fdb1 adapted to the transition to utf-8 of yahoo-jp.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 27760
diff changeset
170 ret = sanitize_utf((gchar *)tmp, strlen((gchar *)tmp), &newlen);
25467
be098f796b32 yaz patch has been applied.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 16109
diff changeset
171 g_free(tmp);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
172 return ret;
25467
be098f796b32 yaz patch has been applied.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 16109
diff changeset
173 }
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
174 else
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
175 return g_strdup("");
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
176 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
177
22123
840e7e1b6dac disapproval of revision '947ccb889812585e6d53eac13fc12734d8481e33'
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 22121
diff changeset
178 char *yahoo_convert_to_numeric(const char *str)
840e7e1b6dac disapproval of revision '947ccb889812585e6d53eac13fc12734d8481e33'
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 22121
diff changeset
179 {
22134
33abfb98a460 Since I needed to bring back yahoo_convert_to_numeric, I figured I could at
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 22123
diff changeset
180 GString *gstr = NULL;
22155
a886e43210b1 Fix (hopefully) the last problem in this function. Refs #3295.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 22134
diff changeset
181 const unsigned char *p;
22123
840e7e1b6dac disapproval of revision '947ccb889812585e6d53eac13fc12734d8481e33'
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 22121
diff changeset
182
22134
33abfb98a460 Since I needed to bring back yahoo_convert_to_numeric, I figured I could at
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 22123
diff changeset
183 gstr = g_string_sized_new(strlen(str) * 6 + 1);
33abfb98a460 Since I needed to bring back yahoo_convert_to_numeric, I figured I could at
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 22123
diff changeset
184
22155
a886e43210b1 Fix (hopefully) the last problem in this function. Refs #3295.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 22134
diff changeset
185 for (p = (unsigned char *)str; *p; p++) {
22134
33abfb98a460 Since I needed to bring back yahoo_convert_to_numeric, I figured I could at
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 22123
diff changeset
186 g_string_append_printf(gstr, "&#%u;", *p);
22123
840e7e1b6dac disapproval of revision '947ccb889812585e6d53eac13fc12734d8481e33'
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 22121
diff changeset
187 }
22134
33abfb98a460 Since I needed to bring back yahoo_convert_to_numeric, I figured I could at
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 22123
diff changeset
188
28080
a0a8b61301c8 Simplify a wee bit
Mark Doliner <mark@kingant.net>
parents: 28025
diff changeset
189 return g_string_free(gstr, FALSE);
22123
840e7e1b6dac disapproval of revision '947ccb889812585e6d53eac13fc12734d8481e33'
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 22121
diff changeset
190 }
840e7e1b6dac disapproval of revision '947ccb889812585e6d53eac13fc12734d8481e33'
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 22121
diff changeset
191
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
192 /*
28155
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
193 * The values in this hash table should probably be lowercase, since that's
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
194 * what xhtml expects. Also because yahoo_codes_to_html() does
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
195 * case-sensitive comparisons.
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
196 *
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
197 * I found these on some website but i don't know that they actually
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
198 * work (or are supposed to work). I didn't implement them yet.
27193
510f07e1f5c1 Strip trailing whitespace and comment #endif marcos that close #ifdef macros
Mark Doliner <mark@kingant.net>
parents: 23916
diff changeset
199 *
28155
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
200 * [0;30m ---black
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
201 * [1;37m ---white
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
202 * [0;37m ---tan
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
203 * [0;38m ---light black
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
204 * [1;39m ---dark blue
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
205 * [0;32m ---green
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
206 * [0;33m ---yellow
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
207 * [0;35m ---pink
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
208 * [1;35m ---purple
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
209 * [1;30m ---light blue
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
210 * [0;31m ---red
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
211 * [0;34m ---blue
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
212 * [0;36m ---aqua
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
213 * (shift+comma)lyellow(shift+period) ---light yellow
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
214 * (shift+comma)lgreen(shift+period) ---light green
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
215 * [2;30m <--white out
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
216 */
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
217
28155
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
218 static GHashTable *esc_codes_ht = NULL;
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
219 static GHashTable *tags_ht = NULL;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
220
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
221 void yahoo_init_colorht()
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
222 {
28155
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
223 if (esc_codes_ht != NULL)
27501
8368e4fb7d3a Don't double-free the color hash table when deinitializing both prpl-yahoo
Mark Doliner <mark@kingant.net>
parents: 27395
diff changeset
224 /* Hash table has already been initialized */
8368e4fb7d3a Don't double-free the color hash table when deinitializing both prpl-yahoo
Mark Doliner <mark@kingant.net>
parents: 27395
diff changeset
225 return;
8368e4fb7d3a Don't double-free the color hash table when deinitializing both prpl-yahoo
Mark Doliner <mark@kingant.net>
parents: 27395
diff changeset
226
28155
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
227 /* Key is the escape code string. Value is the HTML that should be
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
228 * inserted in place of the escape code. */
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
229 esc_codes_ht = g_hash_table_new(g_str_hash, g_str_equal);
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
230
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
231 /* Key is the name of the HTML tag, for example "font" or "/font"
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
232 * value is the HTML that should be inserted in place of the old tag */
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
233 tags_ht = g_hash_table_new(g_str_hash, g_str_equal);
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
234
27501
8368e4fb7d3a Don't double-free the color hash table when deinitializing both prpl-yahoo
Mark Doliner <mark@kingant.net>
parents: 27395
diff changeset
235 /* the numbers in comments are what gyach uses, but i think they're incorrect */
28116
07de864fc024 Change yahoo_codes_to_html() to use the same USE_CSS_FORMATTING #define
Mark Doliner <mark@kingant.net>
parents: 28108
diff changeset
236 #ifdef USE_CSS_FORMATTING
28155
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
237 g_hash_table_insert(esc_codes_ht, "30", "<span style=\"color: #000000\">"); /* black */
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
238 g_hash_table_insert(esc_codes_ht, "31", "<span style=\"color: #0000FF\">"); /* blue */
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
239 g_hash_table_insert(esc_codes_ht, "32", "<span style=\"color: #008080\">"); /* cyan */ /* 00b2b2 */
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
240 g_hash_table_insert(esc_codes_ht, "33", "<span style=\"color: #808080\">"); /* gray */ /* 808080 */
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
241 g_hash_table_insert(esc_codes_ht, "34", "<span style=\"color: #008000\">"); /* green */ /* 00c200 */
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
242 g_hash_table_insert(esc_codes_ht, "35", "<span style=\"color: #FF0080\">"); /* pink */ /* ffafaf */
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
243 g_hash_table_insert(esc_codes_ht, "36", "<span style=\"color: #800080\">"); /* purple */ /* b200b2 */
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
244 g_hash_table_insert(esc_codes_ht, "37", "<span style=\"color: #FF8000\">"); /* orange */ /* ffff00 */
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
245 g_hash_table_insert(esc_codes_ht, "38", "<span style=\"color: #FF0000\">"); /* red */
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
246 g_hash_table_insert(esc_codes_ht, "39", "<span style=\"color: #808000\">"); /* olive */ /* 546b50 */
28116
07de864fc024 Change yahoo_codes_to_html() to use the same USE_CSS_FORMATTING #define
Mark Doliner <mark@kingant.net>
parents: 28108
diff changeset
247 #else
28155
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
248 g_hash_table_insert(esc_codes_ht, "30", "<font color=\"#000000\">"); /* black */
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
249 g_hash_table_insert(esc_codes_ht, "31", "<font color=\"#0000FF\">"); /* blue */
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
250 g_hash_table_insert(esc_codes_ht, "32", "<font color=\"#008080\">"); /* cyan */ /* 00b2b2 */
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
251 g_hash_table_insert(esc_codes_ht, "33", "<font color=\"#808080\">"); /* gray */ /* 808080 */
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
252 g_hash_table_insert(esc_codes_ht, "34", "<font color=\"#008000\">"); /* green */ /* 00c200 */
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
253 g_hash_table_insert(esc_codes_ht, "35", "<font color=\"#FF0080\">"); /* pink */ /* ffafaf */
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
254 g_hash_table_insert(esc_codes_ht, "36", "<font color=\"#800080\">"); /* purple */ /* b200b2 */
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
255 g_hash_table_insert(esc_codes_ht, "37", "<font color=\"#FF8000\">"); /* orange */ /* ffff00 */
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
256 g_hash_table_insert(esc_codes_ht, "38", "<font color=\"#FF0000\">"); /* red */
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
257 g_hash_table_insert(esc_codes_ht, "39", "<font color=\"#808000\">"); /* olive */ /* 546b50 */
28116
07de864fc024 Change yahoo_codes_to_html() to use the same USE_CSS_FORMATTING #define
Mark Doliner <mark@kingant.net>
parents: 28108
diff changeset
258 #endif /* !USE_CSS_FORMATTING */
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
259
28155
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
260 g_hash_table_insert(esc_codes_ht, "1", "<b>");
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
261 g_hash_table_insert(esc_codes_ht, "x1", "</b>");
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
262 g_hash_table_insert(esc_codes_ht, "2", "<i>");
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
263 g_hash_table_insert(esc_codes_ht, "x2", "</i>");
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
264 g_hash_table_insert(esc_codes_ht, "4", "<u>");
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
265 g_hash_table_insert(esc_codes_ht, "x4", "</u>");
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
266
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
267 /* these just tell us the text they surround is supposed
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
268 * to be a link. purple figures that out on its own so we
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
269 * just ignore it.
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
270 */
28155
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
271 g_hash_table_insert(esc_codes_ht, "l", ""); /* link start */
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
272 g_hash_table_insert(esc_codes_ht, "xl", ""); /* link end */
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
273
28116
07de864fc024 Change yahoo_codes_to_html() to use the same USE_CSS_FORMATTING #define
Mark Doliner <mark@kingant.net>
parents: 28108
diff changeset
274 #ifdef USE_CSS_FORMATTING
28155
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
275 g_hash_table_insert(tags_ht, "black", "<span style=\"color: #000000\">");
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
276 g_hash_table_insert(tags_ht, "blue", "<span style=\"color: #0000FF\">");
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
277 g_hash_table_insert(tags_ht, "cyan", "<span style=\"color: #008284\">");
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
278 g_hash_table_insert(tags_ht, "gray", "<span style=\"color: #848284\">");
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
279 g_hash_table_insert(tags_ht, "green", "<span style=\"color: #008200\">");
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
280 g_hash_table_insert(tags_ht, "pink", "<span style=\"color: #FF0084\">");
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
281 g_hash_table_insert(tags_ht, "purple", "<span style=\"color: #840084\">");
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
282 g_hash_table_insert(tags_ht, "orange", "<span style=\"color: #FF8000\">");
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
283 g_hash_table_insert(tags_ht, "red", "<span style=\"color: #FF0000\">");
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
284 g_hash_table_insert(tags_ht, "yellow", "<span style=\"color: #848200\">");
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
285
28155
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
286 g_hash_table_insert(tags_ht, "/black", "</span>");
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
287 g_hash_table_insert(tags_ht, "/blue", "</span>");
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
288 g_hash_table_insert(tags_ht, "/cyan", "</span>");
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
289 g_hash_table_insert(tags_ht, "/gray", "</span>");
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
290 g_hash_table_insert(tags_ht, "/green", "</span>");
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
291 g_hash_table_insert(tags_ht, "/pink", "</span>");
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
292 g_hash_table_insert(tags_ht, "/purple", "</span>");
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
293 g_hash_table_insert(tags_ht, "/orange", "</span>");
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
294 g_hash_table_insert(tags_ht, "/red", "</span>");
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
295 g_hash_table_insert(tags_ht, "/yellow", "</span>");
28116
07de864fc024 Change yahoo_codes_to_html() to use the same USE_CSS_FORMATTING #define
Mark Doliner <mark@kingant.net>
parents: 28108
diff changeset
296 #else
28155
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
297 g_hash_table_insert(tags_ht, "black", "<font color=\"#000000\">");
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
298 g_hash_table_insert(tags_ht, "blue", "<font color=\"#0000FF\">");
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
299 g_hash_table_insert(tags_ht, "cyan", "<font color=\"#008284\">");
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
300 g_hash_table_insert(tags_ht, "gray", "<font color=\"#848284\">");
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
301 g_hash_table_insert(tags_ht, "green", "<font color=\"#008200\">");
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
302 g_hash_table_insert(tags_ht, "pink", "<font color=\"#FF0084\">");
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
303 g_hash_table_insert(tags_ht, "purple", "<font color=\"#840084\">");
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
304 g_hash_table_insert(tags_ht, "orange", "<font color=\"#FF8000\">");
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
305 g_hash_table_insert(tags_ht, "red", "<font color=\"#FF0000\">");
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
306 g_hash_table_insert(tags_ht, "yellow", "<font color=\"#848200\">");
28116
07de864fc024 Change yahoo_codes_to_html() to use the same USE_CSS_FORMATTING #define
Mark Doliner <mark@kingant.net>
parents: 28108
diff changeset
307
28155
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
308 g_hash_table_insert(tags_ht, "/black", "</font>");
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
309 g_hash_table_insert(tags_ht, "/blue", "</font>");
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
310 g_hash_table_insert(tags_ht, "/cyan", "</font>");
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
311 g_hash_table_insert(tags_ht, "/gray", "</font>");
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
312 g_hash_table_insert(tags_ht, "/green", "</font>");
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
313 g_hash_table_insert(tags_ht, "/pink", "</font>");
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
314 g_hash_table_insert(tags_ht, "/purple", "</font>");
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
315 g_hash_table_insert(tags_ht, "/orange", "</font>");
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
316 g_hash_table_insert(tags_ht, "/red", "</font>");
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
317 g_hash_table_insert(tags_ht, "/yellow", "</font>");
28116
07de864fc024 Change yahoo_codes_to_html() to use the same USE_CSS_FORMATTING #define
Mark Doliner <mark@kingant.net>
parents: 28108
diff changeset
318 #endif /* !USE_CSS_FORMATTING */
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
319
28155
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
320 /* We don't support these tags, so discard them */
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
321 g_hash_table_insert(tags_ht, "alt", "");
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
322 g_hash_table_insert(tags_ht, "fade", "");
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
323 g_hash_table_insert(tags_ht, "snd", "");
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
324 g_hash_table_insert(tags_ht, "/alt", "");
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
325 g_hash_table_insert(tags_ht, "/fade", "");
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
326
28155
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
327 /* Official clients don't seem to send b, i or u tags. They use
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
328 * the escape codes listed above. Official clients definitely send
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
329 * font tags, though. I wonder if we can remove the opening and
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
330 * closing b, i and u tags from here? */
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
331 g_hash_table_insert(tags_ht, "b", "<b>");
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
332 g_hash_table_insert(tags_ht, "i", "<i>");
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
333 g_hash_table_insert(tags_ht, "u", "<u>");
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
334 g_hash_table_insert(tags_ht, "font", "<font>");
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
335
28155
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
336 g_hash_table_insert(tags_ht, "/b", "</b>");
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
337 g_hash_table_insert(tags_ht, "/i", "</i>");
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
338 g_hash_table_insert(tags_ht, "/u", "</u>");
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
339 g_hash_table_insert(tags_ht, "/font", "</font>");
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
340 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
341
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
342 void yahoo_dest_colorht()
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
343 {
28155
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
344 if (esc_codes_ht == NULL)
27501
8368e4fb7d3a Don't double-free the color hash table when deinitializing both prpl-yahoo
Mark Doliner <mark@kingant.net>
parents: 27395
diff changeset
345 /* Hash table has already been destroyed */
8368e4fb7d3a Don't double-free the color hash table when deinitializing both prpl-yahoo
Mark Doliner <mark@kingant.net>
parents: 27395
diff changeset
346 return;
8368e4fb7d3a Don't double-free the color hash table when deinitializing both prpl-yahoo
Mark Doliner <mark@kingant.net>
parents: 27395
diff changeset
347
28155
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
348 g_hash_table_destroy(esc_codes_ht);
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
349 esc_codes_ht = NULL;
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
350 g_hash_table_destroy(tags_ht);
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
351 tags_ht = NULL;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
352 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
353
28116
07de864fc024 Change yahoo_codes_to_html() to use the same USE_CSS_FORMATTING #define
Mark Doliner <mark@kingant.net>
parents: 28108
diff changeset
354 #ifndef USE_CSS_FORMATTING
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
355 static int point_to_html(int x)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
356 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
357 if (x < 9)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
358 return 1;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
359 if (x < 11)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
360 return 2;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
361 if (x < 13)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
362 return 3;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
363 if (x < 17)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
364 return 4;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
365 if (x < 25)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
366 return 5;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
367 if (x < 35)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
368 return 6;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
369 return 7;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
370 }
28116
07de864fc024 Change yahoo_codes_to_html() to use the same USE_CSS_FORMATTING #define
Mark Doliner <mark@kingant.net>
parents: 28108
diff changeset
371 #endif /* !USE_CSS_FORMATTING */
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
372
28155
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
373 static void append_attrs_datalist_foreach_cb(GQuark key_id, gpointer data, gpointer user_data)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
374 {
28155
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
375 const char *key;
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
376 const char *value;
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
377 xmlnode *cur;
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
378
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
379 key = g_quark_to_string(key_id);
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
380 value = data;
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
381 cur = user_data;
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
382
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
383 xmlnode_set_attrib(cur, key, value);
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
384 }
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
385
28155
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
386 /**
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
387 * @param cur A pointer to the position in the XML tree that we're
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
388 * currently building. This will be modified when opening a tag
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
389 * or closing an existing tag.
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
390 */
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
391 static void yahoo_codes_to_html_add_tag(xmlnode **cur, const char *tag, gboolean is_closing_tag, const gchar *tag_name, gboolean is_font_tag)
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
392 {
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
393 if (is_closing_tag) {
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
394 xmlnode *tmp;
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
395 GSList *dangling_tags = NULL;
28116
07de864fc024 Change yahoo_codes_to_html() to use the same USE_CSS_FORMATTING #define
Mark Doliner <mark@kingant.net>
parents: 28108
diff changeset
396
28155
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
397 /* Move up the DOM until we find the opening tag */
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
398 for (tmp = *cur; tmp != NULL; tmp = xmlnode_get_parent(tmp)) {
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
399 /* Add one to tag_name when doing this comparison because it starts with a / */
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
400 if (g_str_equal(tmp->name, tag_name + 1))
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
401 /* Found */
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
402 break;
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
403 dangling_tags = g_slist_prepend(dangling_tags, tmp);
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
404 }
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
405 if (tmp == NULL) {
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
406 /* This is a closing tag with no opening tag. Useless. */
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
407 purple_debug_error("yahoo", "Ignoring unmatched tag %s", tag);
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
408 g_slist_free(dangling_tags);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
409 return;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
410 }
28155
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
411
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
412 /* Move our current position up, now that we've closed a tag */
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
413 *cur = xmlnode_get_parent(tmp);
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
414
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
415 /* Re-open any tags that were nested below the tag we just closed */
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
416 while (dangling_tags != NULL) {
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
417 tmp = dangling_tags->data;
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
418 dangling_tags = g_slist_delete_link(dangling_tags, dangling_tags);
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
419
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
420 /* Create a copy of this tag+attributes (but not child tags or
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
421 * data) at our new location */
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
422 *cur = xmlnode_new_child(*cur, tmp->name);
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
423 for (tmp = tmp->child; tmp != NULL; tmp = tmp->next)
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
424 if (tmp->type == XMLNODE_TYPE_ATTRIB)
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
425 xmlnode_set_attrib_full(*cur, tmp->name,
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
426 tmp->xmlns, tmp->prefix, tmp->data);
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
427 }
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
428 } else {
28155
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
429 const char *start;
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
430 const char *end;
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
431 GData *attributes;
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
432 char *fontsize = NULL;
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
433
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
434 purple_markup_find_tag(tag_name, tag, &start, &end, &attributes);
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
435 *cur = xmlnode_new_child(*cur, tag_name);
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
436
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
437 if (is_font_tag) {
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
438 /* Special case for the font size attribute */
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
439 fontsize = g_strdup(g_datalist_get_data(&attributes, "size"));
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
440 if (fontsize != NULL)
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
441 g_datalist_remove_data(&attributes, "size");
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
442 }
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
443
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
444 /* Add all font tag attributes */
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
445 g_datalist_foreach(&attributes, append_attrs_datalist_foreach_cb, *cur);
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
446 g_datalist_clear(&attributes);
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
447
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
448 if (fontsize != NULL) {
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
449 #ifdef USE_CSS_FORMATTING
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
450 /*
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
451 * The Yahoo font size value is given in pt, even though the HTML
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
452 * standard for <font size="x"> treats the size as a number on a
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
453 * scale between 1 and 7. So we insert the font size as a CSS
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
454 * style on a span tag.
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
455 */
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
456 gchar *tmp = g_strdup_printf("font-size: %spt", fontsize);
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
457 *cur = xmlnode_new_child(*cur, "span");
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
458 xmlnode_set_attrib(*cur, "style", tmp);
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
459 g_free(tmp);
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
460 #else
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
461 /*
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
462 * The Yahoo font size value is given in pt, even though the HTML
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
463 * standard for <font size="x"> treats the size as a number on a
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
464 * scale between 1 and 7. So we convert it to an appropriate
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
465 * value. This loses precision, which is why CSS formatting is
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
466 * preferred. The "absz" attribute remains here for backward
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
467 * compatibility with UIs that might use it, but it is totally
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
468 * not standard at all.
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
469 */
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
470 int size, htmlsize;
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
471 gchar tmp[11];
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
472 size = strtol(fontsize, NULL, 10);
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
473 htmlsize = point_to_html(size);
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
474 sprintf(tmp, "%u", htmlsize);
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
475 xmlnode_set_attrib(*cur, "size", tmp);
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
476 xmlnode_set_attrib(*cur, "absz", fontsize);
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
477 #endif /* !USE_CSS_FORMATTING */
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
478 g_free(fontsize);
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
479 }
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
480 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
481 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
482
28155
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
483 /**
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
484 * Similar to purple_markup_get_tag_name(), but works with closing tags.
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
485 *
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
486 * @return The lowercase name of the tag. If this is a closing tag then
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
487 * this value starts with a forward slash. The caller must free
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
488 * this string with g_free.
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
489 */
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
490 static gchar *yahoo_markup_get_tag_name(const char *tag, gboolean *is_closing_tag)
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
491 {
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
492 size_t len;
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
493
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
494 *is_closing_tag = (tag[1] == '/');
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
495 if (*is_closing_tag)
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
496 len = strcspn(tag + 1, "> ");
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
497 else
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
498 len = strcspn(tag + 1, "> /");
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
499
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
500 return g_utf8_strdown(tag + 1, len);
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
501 }
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
502
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
503 /*
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
504 * Yahoo! messages generally aren't well-formed. Their markup is
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
505 * more of a flow from start to finish rather than a hierarchy from
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
506 * outer to inner. They tend to open tags and close them only when
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
507 * necessary.
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
508 *
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
509 * Example: <font size="8">size 8 <font size="16">size 16 <font size="8">size 8 again
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
510 *
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
511 * But we want to send well-formed HTML to the core, so we step through
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
512 * the input string and build an xmlnode tree containing sanitized HTML.
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
513 */
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
514 char *yahoo_codes_to_html(const char *x)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
515 {
28103
8660d8bc467c Minor optimization when sending and receiving messages on Yahoo: only
Mark Doliner <mark@kingant.net>
parents: 28102
diff changeset
516 size_t x_len;
28155
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
517 xmlnode *html, *cur;
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
518 GString *cdata = g_string_new(NULL);
28103
8660d8bc467c Minor optimization when sending and receiving messages on Yahoo: only
Mark Doliner <mark@kingant.net>
parents: 28102
diff changeset
519 int i, j;
28108
2b3a9a68e0bc Of course I got it backwards
Mark Doliner <mark@kingant.net>
parents: 28107
diff changeset
520 gboolean no_more_gt_brackets = FALSE;
28104
70219821df98 Make match a const char *, and remove two unnecessary casts
Mark Doliner <mark@kingant.net>
parents: 28103
diff changeset
521 const char *match;
28376
83a3b3b5976a Oh, I guess we should escape this when printing to the debug window.
Mark Doliner <mark@kingant.net>
parents: 28369
diff changeset
522 gchar *xmlstr1, *xmlstr2, *esc;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
523
28103
8660d8bc467c Minor optimization when sending and receiving messages on Yahoo: only
Mark Doliner <mark@kingant.net>
parents: 28102
diff changeset
524 x_len = strlen(x);
28155
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
525 html = xmlnode_new("html");
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
526
28155
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
527 cur = html;
28103
8660d8bc467c Minor optimization when sending and receiving messages on Yahoo: only
Mark Doliner <mark@kingant.net>
parents: 28102
diff changeset
528 for (i = 0; i < x_len; i++) {
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
529 if ((x[i] == 0x1b) && (x[i+1] == '[')) {
28107
1c9d3038a0d3 Better variable name?
Mark Doliner <mark@kingant.net>
parents: 28105
diff changeset
530 /* This escape sequence signifies the beginning of some
1c9d3038a0d3 Better variable name?
Mark Doliner <mark@kingant.net>
parents: 28105
diff changeset
531 * text formatting code */
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
532 j = i + 1;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
533
28103
8660d8bc467c Minor optimization when sending and receiving messages on Yahoo: only
Mark Doliner <mark@kingant.net>
parents: 28102
diff changeset
534 while (j++ < x_len) {
28155
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
535 gchar *code;
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
536
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
537 if (x[j] != 'm')
28155
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
538 /* Keep looking for the end of this sequence */
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
539 continue;
28155
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
540
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
541 /* We've reached the end of the formatting sequence, yay */
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
542
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
543 /* Append any character data that belongs in the current node */
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
544 if (cdata->len > 0) {
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
545 xmlnode_insert_data(cur, cdata->str, cdata->len);
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
546 g_string_truncate(cdata, 0);
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
547 }
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
548
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
549 code = g_strndup(x + i + 2, j - i - 2);
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
550 if (code[0] == '#') {
28116
07de864fc024 Change yahoo_codes_to_html() to use the same USE_CSS_FORMATTING #define
Mark Doliner <mark@kingant.net>
parents: 28108
diff changeset
551 #ifdef USE_CSS_FORMATTING
28155
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
552 gchar *tmp = g_strdup_printf("color: %s", code);
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
553 cur = xmlnode_new_child(cur, "span");
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
554 xmlnode_set_attrib(cur, "style", tmp);
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
555 g_free(tmp);
28116
07de864fc024 Change yahoo_codes_to_html() to use the same USE_CSS_FORMATTING #define
Mark Doliner <mark@kingant.net>
parents: 28108
diff changeset
556 #else
28155
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
557 cur = xmlnode_new_child(cur, "font");
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
558 xmlnode_set_attrib(cur, "color", code);
28116
07de864fc024 Change yahoo_codes_to_html() to use the same USE_CSS_FORMATTING #define
Mark Doliner <mark@kingant.net>
parents: 28108
diff changeset
559 #endif /* !USE_CSS_FORMATTING */
28155
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
560
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
561 } else if ((match = g_hash_table_lookup(esc_codes_ht, code))) {
28348
617e7a90b69c Fix a possible crash when receiving URLs in yahoo. It doesn't crash for me
Mark Doliner <mark@kingant.net>
parents: 28172
diff changeset
562 /* Some tags are in the hash table only because we
617e7a90b69c Fix a possible crash when receiving URLs in yahoo. It doesn't crash for me
Mark Doliner <mark@kingant.net>
parents: 28172
diff changeset
563 * want to ignore them */
617e7a90b69c Fix a possible crash when receiving URLs in yahoo. It doesn't crash for me
Mark Doliner <mark@kingant.net>
parents: 28172
diff changeset
564 if (match[0] != '\0') {
617e7a90b69c Fix a possible crash when receiving URLs in yahoo. It doesn't crash for me
Mark Doliner <mark@kingant.net>
parents: 28172
diff changeset
565 gboolean is_closing_tag;
617e7a90b69c Fix a possible crash when receiving URLs in yahoo. It doesn't crash for me
Mark Doliner <mark@kingant.net>
parents: 28172
diff changeset
566 gchar *tag_name;
617e7a90b69c Fix a possible crash when receiving URLs in yahoo. It doesn't crash for me
Mark Doliner <mark@kingant.net>
parents: 28172
diff changeset
567 tag_name = yahoo_markup_get_tag_name(match, &is_closing_tag);
617e7a90b69c Fix a possible crash when receiving URLs in yahoo. It doesn't crash for me
Mark Doliner <mark@kingant.net>
parents: 28172
diff changeset
568 yahoo_codes_to_html_add_tag(&cur, match, is_closing_tag, tag_name, FALSE);
617e7a90b69c Fix a possible crash when receiving URLs in yahoo. It doesn't crash for me
Mark Doliner <mark@kingant.net>
parents: 28172
diff changeset
569 g_free(tag_name);
617e7a90b69c Fix a possible crash when receiving URLs in yahoo. It doesn't crash for me
Mark Doliner <mark@kingant.net>
parents: 28172
diff changeset
570 }
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
571
28155
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
572 } else {
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
573 purple_debug_error("yahoo",
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
574 "Ignoring unknown ansi code 'ESC[%sm'.\n", code);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
575 }
28155
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
576
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
577 g_free(code);
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
578 i = j;
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
579 break;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
580 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
581
28155
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
582 } else if (x[i] == '<' && !no_more_gt_brackets) {
28107
1c9d3038a0d3 Better variable name?
Mark Doliner <mark@kingant.net>
parents: 28105
diff changeset
583 /* The start of an HTML tag */
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
584 j = i;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
585
28103
8660d8bc467c Minor optimization when sending and receiving messages on Yahoo: only
Mark Doliner <mark@kingant.net>
parents: 28102
diff changeset
586 while (j++ < x_len) {
28155
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
587 gchar *tag;
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
588 gboolean is_closing_tag;
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
589 gchar *tag_name;
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
590
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
591 if (x[j] != '>') {
28171
f6dab0e7a817 Take care of a special case where we would incorrectly parse incoming IMs
Mark Doliner <mark@kingant.net>
parents: 28168
diff changeset
592 if (x[j] == '"') {
f6dab0e7a817 Take care of a special case where we would incorrectly parse incoming IMs
Mark Doliner <mark@kingant.net>
parents: 28168
diff changeset
593 /* We're inside a quoted attribute value. Skip to the end */
f6dab0e7a817 Take care of a special case where we would incorrectly parse incoming IMs
Mark Doliner <mark@kingant.net>
parents: 28168
diff changeset
594 j++;
f6dab0e7a817 Take care of a special case where we would incorrectly parse incoming IMs
Mark Doliner <mark@kingant.net>
parents: 28168
diff changeset
595 while (j != x_len && x[j] != '"')
f6dab0e7a817 Take care of a special case where we would incorrectly parse incoming IMs
Mark Doliner <mark@kingant.net>
parents: 28168
diff changeset
596 j++;
f6dab0e7a817 Take care of a special case where we would incorrectly parse incoming IMs
Mark Doliner <mark@kingant.net>
parents: 28168
diff changeset
597 } else if (x[j] == '\'') {
f6dab0e7a817 Take care of a special case where we would incorrectly parse incoming IMs
Mark Doliner <mark@kingant.net>
parents: 28168
diff changeset
598 /* We're inside a quoted attribute value. Skip to the end */
f6dab0e7a817 Take care of a special case where we would incorrectly parse incoming IMs
Mark Doliner <mark@kingant.net>
parents: 28168
diff changeset
599 j++;
f6dab0e7a817 Take care of a special case where we would incorrectly parse incoming IMs
Mark Doliner <mark@kingant.net>
parents: 28168
diff changeset
600 while (j != x_len && x[j] != '\'')
f6dab0e7a817 Take care of a special case where we would incorrectly parse incoming IMs
Mark Doliner <mark@kingant.net>
parents: 28168
diff changeset
601 j++;
f6dab0e7a817 Take care of a special case where we would incorrectly parse incoming IMs
Mark Doliner <mark@kingant.net>
parents: 28168
diff changeset
602 }
28155
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
603 if (j != x_len)
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
604 /* Keep looking for the end of this tag */
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
605 continue;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
606
28155
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
607 /* This < has no corresponding > */
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
608 g_string_append_c(cdata, x[i]);
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
609 no_more_gt_brackets = TRUE;
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
610 break;
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
611 }
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
612
28155
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
613 tag = g_strndup(x + i, j - i + 1);
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
614 tag_name = yahoo_markup_get_tag_name(tag, &is_closing_tag);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
615
28155
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
616 match = g_hash_table_lookup(tags_ht, tag_name);
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
617 if (match == NULL) {
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
618 /* Unknown tag. The user probably typed a less-than sign */
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
619 g_string_append_c(cdata, x[i]);
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
620 g_free(tag);
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
621 g_free(tag_name);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
622 break;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
623 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
624
28155
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
625 /* Some tags are in the hash table only because we
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
626 * want to ignore them */
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
627 if (match[0] != '\0') {
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
628 /* Append any character data that belongs in the current node */
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
629 if (cdata->len > 0) {
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
630 xmlnode_insert_data(cur, cdata->str, cdata->len);
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
631 g_string_truncate(cdata, 0);
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
632 }
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
633 if (g_str_equal(tag_name, "font"))
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
634 /* Font tags are a special case. We don't
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
635 * necessarily want to replace the whole thing--
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
636 * we just want to fix the size attribute. */
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
637 yahoo_codes_to_html_add_tag(&cur, tag, is_closing_tag, tag_name, TRUE);
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
638 else
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
639 yahoo_codes_to_html_add_tag(&cur, match, is_closing_tag, tag_name, FALSE);
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
640 }
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
641
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
642 i = j;
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
643 g_free(tag);
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
644 g_free(tag_name);
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
645 break;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
646 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
647
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
648 } else {
28155
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
649 g_string_append_c(cdata, x[i]);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
650 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
651 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
652
28155
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
653 /* Append any remaining character data */
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
654 if (cdata->len > 0)
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
655 xmlnode_insert_data(cur, cdata->str, cdata->len);
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
656 g_string_free(cdata, TRUE);
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
657
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
658 /* Serialize our HTML */
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
659 xmlstr1 = xmlnode_to_str(html, NULL);
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
660 xmlnode_free(html);
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
661
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
662 /* Strip off the outter HTML node */
28165
5eca0f387c13 Make this enum follow our naming conventions a little better
Mark Doliner <mark@kingant.net>
parents: 28155
diff changeset
663 /* This probably isn't necessary, especially if we made the outter HTML
5eca0f387c13 Make this enum follow our naming conventions a little better
Mark Doliner <mark@kingant.net>
parents: 28155
diff changeset
664 * node an empty span. But the HTML is simpler this way. */
28155
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
665 xmlstr2 = g_strndup(xmlstr1 + 6, strlen(xmlstr1) - 13);
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
666 g_free(xmlstr1);
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
667
28376
83a3b3b5976a Oh, I guess we should escape this when printing to the debug window.
Mark Doliner <mark@kingant.net>
parents: 28369
diff changeset
668 esc = g_strescape(x, NULL);
83a3b3b5976a Oh, I guess we should escape this when printing to the debug window.
Mark Doliner <mark@kingant.net>
parents: 28369
diff changeset
669 purple_debug_misc("yahoo", "yahoo_codes_to_html(%s)=%s\n", esc, xmlstr2);
83a3b3b5976a Oh, I guess we should escape this when printing to the debug window.
Mark Doliner <mark@kingant.net>
parents: 28369
diff changeset
670 g_free(esc);
83a3b3b5976a Oh, I guess we should escape this when printing to the debug window.
Mark Doliner <mark@kingant.net>
parents: 28369
diff changeset
671
28155
1e02e65ce301 Changes to the way we translate raw yahoo messages to HTML. The HTML
Mark Doliner <mark@kingant.net>
parents: 28119
diff changeset
672 return xmlstr2;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
673 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
674
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
675 /* borrowed from gtkimhtml */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
676 #define MAX_FONT_SIZE 7
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
677 #define POINT_SIZE(x) (_point_sizes [MIN ((x > 0 ? x : 1), MAX_FONT_SIZE) - 1])
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
678 static const gint _point_sizes [] = { 8, 10, 12, 14, 20, 30, 40 };
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
679
28362
c06114f3d58d * Change yahoo_html_to_codes() a little to hopefully be more straight forward
Mark Doliner <mark@kingant.net>
parents: 28348
diff changeset
680 typedef struct
c06114f3d58d * Change yahoo_html_to_codes() a little to hopefully be more straight forward
Mark Doliner <mark@kingant.net>
parents: 28348
diff changeset
681 {
c06114f3d58d * Change yahoo_html_to_codes() a little to hopefully be more straight forward
Mark Doliner <mark@kingant.net>
parents: 28348
diff changeset
682 gboolean bold;
c06114f3d58d * Change yahoo_html_to_codes() a little to hopefully be more straight forward
Mark Doliner <mark@kingant.net>
parents: 28348
diff changeset
683 gboolean italic;
c06114f3d58d * Change yahoo_html_to_codes() a little to hopefully be more straight forward
Mark Doliner <mark@kingant.net>
parents: 28348
diff changeset
684 gboolean underline;
c06114f3d58d * Change yahoo_html_to_codes() a little to hopefully be more straight forward
Mark Doliner <mark@kingant.net>
parents: 28348
diff changeset
685 gboolean in_link;
c06114f3d58d * Change yahoo_html_to_codes() a little to hopefully be more straight forward
Mark Doliner <mark@kingant.net>
parents: 28348
diff changeset
686 int font_size;
c06114f3d58d * Change yahoo_html_to_codes() a little to hopefully be more straight forward
Mark Doliner <mark@kingant.net>
parents: 28348
diff changeset
687 char *font_face;
c06114f3d58d * Change yahoo_html_to_codes() a little to hopefully be more straight forward
Mark Doliner <mark@kingant.net>
parents: 28348
diff changeset
688 char *font_color;
c06114f3d58d * Change yahoo_html_to_codes() a little to hopefully be more straight forward
Mark Doliner <mark@kingant.net>
parents: 28348
diff changeset
689 } CurrentMsgState;
c06114f3d58d * Change yahoo_html_to_codes() a little to hopefully be more straight forward
Mark Doliner <mark@kingant.net>
parents: 28348
diff changeset
690
28166
bc9da266d25d This is actually a stack, not a queue, so we can use a simpler data
Mark Doliner <mark@kingant.net>
parents: 28165
diff changeset
691 static void yahoo_htc_list_cleanup(GSList *l)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
692 {
28166
bc9da266d25d This is actually a stack, not a queue, so we can use a simpler data
Mark Doliner <mark@kingant.net>
parents: 28165
diff changeset
693 while (l != NULL) {
bc9da266d25d This is actually a stack, not a queue, so we can use a simpler data
Mark Doliner <mark@kingant.net>
parents: 28165
diff changeset
694 g_free(l->data);
bc9da266d25d This is actually a stack, not a queue, so we can use a simpler data
Mark Doliner <mark@kingant.net>
parents: 28165
diff changeset
695 l = g_slist_delete_link(l, l);
bc9da266d25d This is actually a stack, not a queue, so we can use a simpler data
Mark Doliner <mark@kingant.net>
parents: 28165
diff changeset
696 }
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
697 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
698
28378
6b446431b2b0 This function no longer needs these two parameters
Mark Doliner <mark@kingant.net>
parents: 28377
diff changeset
699 static void parse_font_tag(GString *dest, const char *tag_name, const char *tag,
6b446431b2b0 This function no longer needs these two parameters
Mark Doliner <mark@kingant.net>
parents: 28377
diff changeset
700 GSList **colors, GSList **tags)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
701 {
28363
b289449f3e9f Make outgoing yahoo messages with links, font color, font face or font size
Mark Doliner <mark@kingant.net>
parents: 28362
diff changeset
702 const char *start;
b289449f3e9f Make outgoing yahoo messages with links, font color, font face or font size
Mark Doliner <mark@kingant.net>
parents: 28362
diff changeset
703 const char *end;
b289449f3e9f Make outgoing yahoo messages with links, font color, font face or font size
Mark Doliner <mark@kingant.net>
parents: 28362
diff changeset
704 GData *attributes;
b289449f3e9f Make outgoing yahoo messages with links, font color, font face or font size
Mark Doliner <mark@kingant.net>
parents: 28362
diff changeset
705 const char *attribute;
b289449f3e9f Make outgoing yahoo messages with links, font color, font face or font size
Mark Doliner <mark@kingant.net>
parents: 28362
diff changeset
706 gboolean needendtag;
b289449f3e9f Make outgoing yahoo messages with links, font color, font face or font size
Mark Doliner <mark@kingant.net>
parents: 28362
diff changeset
707 GString *tmp;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
708
28363
b289449f3e9f Make outgoing yahoo messages with links, font color, font face or font size
Mark Doliner <mark@kingant.net>
parents: 28362
diff changeset
709 purple_markup_find_tag(tag_name, tag, &start, &end, &attributes);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
710
28369
5ff49aa05439 Don't put stuff into a linked list only to iterate through the linked list
Mark Doliner <mark@kingant.net>
parents: 28368
diff changeset
711 needendtag = FALSE;
5ff49aa05439 Don't put stuff into a linked list only to iterate through the linked list
Mark Doliner <mark@kingant.net>
parents: 28368
diff changeset
712 tmp = g_string_new(NULL);
5ff49aa05439 Don't put stuff into a linked list only to iterate through the linked list
Mark Doliner <mark@kingant.net>
parents: 28368
diff changeset
713
5ff49aa05439 Don't put stuff into a linked list only to iterate through the linked list
Mark Doliner <mark@kingant.net>
parents: 28368
diff changeset
714 attribute = g_datalist_get_data(&attributes, "color");
5ff49aa05439 Don't put stuff into a linked list only to iterate through the linked list
Mark Doliner <mark@kingant.net>
parents: 28368
diff changeset
715 if (attribute != NULL) {
5ff49aa05439 Don't put stuff into a linked list only to iterate through the linked list
Mark Doliner <mark@kingant.net>
parents: 28368
diff changeset
716 g_string_append(tmp, *colors ? (*colors)->data : "\033[#000000m");
5ff49aa05439 Don't put stuff into a linked list only to iterate through the linked list
Mark Doliner <mark@kingant.net>
parents: 28368
diff changeset
717 g_string_append_printf(dest, "\033[%sm", attribute);
5ff49aa05439 Don't put stuff into a linked list only to iterate through the linked list
Mark Doliner <mark@kingant.net>
parents: 28368
diff changeset
718 *colors = g_slist_prepend(*colors,
5ff49aa05439 Don't put stuff into a linked list only to iterate through the linked list
Mark Doliner <mark@kingant.net>
parents: 28368
diff changeset
719 g_strdup_printf("\033[%sm", attribute));
28383
2a6f0c2460ae Fix a bug in our outgoing yahoo message formatting where messages
Mark Doliner <mark@kingant.net>
parents: 28378
diff changeset
720 } else {
2a6f0c2460ae Fix a bug in our outgoing yahoo message formatting where messages
Mark Doliner <mark@kingant.net>
parents: 28378
diff changeset
721 /* We need to add a value to the colors stack even if we're not
2a6f0c2460ae Fix a bug in our outgoing yahoo message formatting where messages
Mark Doliner <mark@kingant.net>
parents: 28378
diff changeset
722 * setting a color because we ALWAYS pop exactly 1 element from
2a6f0c2460ae Fix a bug in our outgoing yahoo message formatting where messages
Mark Doliner <mark@kingant.net>
parents: 28378
diff changeset
723 * this stack for every </font> tag. If we don't add anything
2a6f0c2460ae Fix a bug in our outgoing yahoo message formatting where messages
Mark Doliner <mark@kingant.net>
parents: 28378
diff changeset
724 * then we'll pop something that we shouldn't when we hit this
2a6f0c2460ae Fix a bug in our outgoing yahoo message formatting where messages
Mark Doliner <mark@kingant.net>
parents: 28378
diff changeset
725 * corresponding </font>. */
2a6f0c2460ae Fix a bug in our outgoing yahoo message formatting where messages
Mark Doliner <mark@kingant.net>
parents: 28378
diff changeset
726 *colors = g_slist_prepend(*colors,
2a6f0c2460ae Fix a bug in our outgoing yahoo message formatting where messages
Mark Doliner <mark@kingant.net>
parents: 28378
diff changeset
727 *colors ? g_strdup((*colors)->data) : g_strdup("\033[#000000m"));
28369
5ff49aa05439 Don't put stuff into a linked list only to iterate through the linked list
Mark Doliner <mark@kingant.net>
parents: 28368
diff changeset
728 }
5ff49aa05439 Don't put stuff into a linked list only to iterate through the linked list
Mark Doliner <mark@kingant.net>
parents: 28368
diff changeset
729
28363
b289449f3e9f Make outgoing yahoo messages with links, font color, font face or font size
Mark Doliner <mark@kingant.net>
parents: 28362
diff changeset
730 attribute = g_datalist_get_data(&attributes, "face");
b289449f3e9f Make outgoing yahoo messages with links, font color, font face or font size
Mark Doliner <mark@kingant.net>
parents: 28362
diff changeset
731 if (attribute != NULL) {
28369
5ff49aa05439 Don't put stuff into a linked list only to iterate through the linked list
Mark Doliner <mark@kingant.net>
parents: 28368
diff changeset
732 needendtag = TRUE;
5ff49aa05439 Don't put stuff into a linked list only to iterate through the linked list
Mark Doliner <mark@kingant.net>
parents: 28368
diff changeset
733 g_string_append(dest, "<font ");
5ff49aa05439 Don't put stuff into a linked list only to iterate through the linked list
Mark Doliner <mark@kingant.net>
parents: 28368
diff changeset
734 g_string_append_printf(dest, "face=\"%s\" ", attribute);
28363
b289449f3e9f Make outgoing yahoo messages with links, font color, font face or font size
Mark Doliner <mark@kingant.net>
parents: 28362
diff changeset
735 }
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
736
28363
b289449f3e9f Make outgoing yahoo messages with links, font color, font face or font size
Mark Doliner <mark@kingant.net>
parents: 28362
diff changeset
737 attribute = g_datalist_get_data(&attributes, "size");
b289449f3e9f Make outgoing yahoo messages with links, font color, font face or font size
Mark Doliner <mark@kingant.net>
parents: 28362
diff changeset
738 if (attribute != NULL) {
28369
5ff49aa05439 Don't put stuff into a linked list only to iterate through the linked list
Mark Doliner <mark@kingant.net>
parents: 28368
diff changeset
739 if (!needendtag) {
5ff49aa05439 Don't put stuff into a linked list only to iterate through the linked list
Mark Doliner <mark@kingant.net>
parents: 28368
diff changeset
740 needendtag = TRUE;
5ff49aa05439 Don't put stuff into a linked list only to iterate through the linked list
Mark Doliner <mark@kingant.net>
parents: 28368
diff changeset
741 g_string_append(dest, "<font ");
5ff49aa05439 Don't put stuff into a linked list only to iterate through the linked list
Mark Doliner <mark@kingant.net>
parents: 28368
diff changeset
742 }
28368
8b68373bf393 Use a GSList here instead of a GQueue. Yay for simplification.
Mark Doliner <mark@kingant.net>
parents: 28367
diff changeset
743
28369
5ff49aa05439 Don't put stuff into a linked list only to iterate through the linked list
Mark Doliner <mark@kingant.net>
parents: 28368
diff changeset
744 g_string_append_printf(dest, "size=\"%d\" ",
5ff49aa05439 Don't put stuff into a linked list only to iterate through the linked list
Mark Doliner <mark@kingant.net>
parents: 28368
diff changeset
745 POINT_SIZE(strtol(attribute, NULL, 10)));
28368
8b68373bf393 Use a GSList here instead of a GQueue. Yay for simplification.
Mark Doliner <mark@kingant.net>
parents: 28367
diff changeset
746 }
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
747
28368
8b68373bf393 Use a GSList here instead of a GQueue. Yay for simplification.
Mark Doliner <mark@kingant.net>
parents: 28367
diff changeset
748 if (needendtag) {
8b68373bf393 Use a GSList here instead of a GQueue. Yay for simplification.
Mark Doliner <mark@kingant.net>
parents: 28367
diff changeset
749 dest->str[dest->len-1] = '>';
8b68373bf393 Use a GSList here instead of a GQueue. Yay for simplification.
Mark Doliner <mark@kingant.net>
parents: 28367
diff changeset
750 *tags = g_slist_prepend(*tags, g_strdup("</font>"));
8b68373bf393 Use a GSList here instead of a GQueue. Yay for simplification.
Mark Doliner <mark@kingant.net>
parents: 28367
diff changeset
751 g_string_free(tmp, TRUE);
8b68373bf393 Use a GSList here instead of a GQueue. Yay for simplification.
Mark Doliner <mark@kingant.net>
parents: 28367
diff changeset
752 } else {
8b68373bf393 Use a GSList here instead of a GQueue. Yay for simplification.
Mark Doliner <mark@kingant.net>
parents: 28367
diff changeset
753 *tags = g_slist_prepend(*tags, tmp->str);
8b68373bf393 Use a GSList here instead of a GQueue. Yay for simplification.
Mark Doliner <mark@kingant.net>
parents: 28367
diff changeset
754 g_string_free(tmp, FALSE);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
755 }
28369
5ff49aa05439 Don't put stuff into a linked list only to iterate through the linked list
Mark Doliner <mark@kingant.net>
parents: 28368
diff changeset
756
5ff49aa05439 Don't put stuff into a linked list only to iterate through the linked list
Mark Doliner <mark@kingant.net>
parents: 28368
diff changeset
757 g_datalist_clear(&attributes);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
758 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
759
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
760 char *yahoo_html_to_codes(const char *src)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
761 {
28166
bc9da266d25d This is actually a stack, not a queue, so we can use a simpler data
Mark Doliner <mark@kingant.net>
parents: 28165
diff changeset
762 GSList *colors = NULL;
28369
5ff49aa05439 Don't put stuff into a linked list only to iterate through the linked list
Mark Doliner <mark@kingant.net>
parents: 28368
diff changeset
763
5ff49aa05439 Don't put stuff into a linked list only to iterate through the linked list
Mark Doliner <mark@kingant.net>
parents: 28368
diff changeset
764 /**
5ff49aa05439 Don't put stuff into a linked list only to iterate through the linked list
Mark Doliner <mark@kingant.net>
parents: 28368
diff changeset
765 * A stack of char*s where each char* is the string that should be
5ff49aa05439 Don't put stuff into a linked list only to iterate through the linked list
Mark Doliner <mark@kingant.net>
parents: 28368
diff changeset
766 * appended to dest in order to close all the tags that were opened
5ff49aa05439 Don't put stuff into a linked list only to iterate through the linked list
Mark Doliner <mark@kingant.net>
parents: 28368
diff changeset
767 * by a <font> tag.
5ff49aa05439 Don't put stuff into a linked list only to iterate through the linked list
Mark Doliner <mark@kingant.net>
parents: 28368
diff changeset
768 */
28166
bc9da266d25d This is actually a stack, not a queue, so we can use a simpler data
Mark Doliner <mark@kingant.net>
parents: 28165
diff changeset
769 GSList *tags = NULL;
28369
5ff49aa05439 Don't put stuff into a linked list only to iterate through the linked list
Mark Doliner <mark@kingant.net>
parents: 28368
diff changeset
770
28103
8660d8bc467c Minor optimization when sending and receiving messages on Yahoo: only
Mark Doliner <mark@kingant.net>
parents: 28102
diff changeset
771 size_t src_len;
8660d8bc467c Minor optimization when sending and receiving messages on Yahoo: only
Mark Doliner <mark@kingant.net>
parents: 28102
diff changeset
772 int i, j;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
773 GString *dest;
28080
a0a8b61301c8 Simplify a wee bit
Mark Doliner <mark@kingant.net>
parents: 28025
diff changeset
774 char *esc;
28362
c06114f3d58d * Change yahoo_html_to_codes() a little to hopefully be more straight forward
Mark Doliner <mark@kingant.net>
parents: 28348
diff changeset
775 gboolean no_more_gt_brackets = FALSE;
c06114f3d58d * Change yahoo_html_to_codes() a little to hopefully be more straight forward
Mark Doliner <mark@kingant.net>
parents: 28348
diff changeset
776 gchar *tag, *tag_name;
c06114f3d58d * Change yahoo_html_to_codes() a little to hopefully be more straight forward
Mark Doliner <mark@kingant.net>
parents: 28348
diff changeset
777 gboolean is_closing_tag;
c06114f3d58d * Change yahoo_html_to_codes() a little to hopefully be more straight forward
Mark Doliner <mark@kingant.net>
parents: 28348
diff changeset
778 CurrentMsgState current_state;
c06114f3d58d * Change yahoo_html_to_codes() a little to hopefully be more straight forward
Mark Doliner <mark@kingant.net>
parents: 28348
diff changeset
779
28377
69793158765c use memset instead of bzero for better portability and profit
Daniel Atallah <daniel.atallah@gmail.com>
parents: 28376
diff changeset
780 memset(&current_state, 0, sizeof(current_state));
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
781
28103
8660d8bc467c Minor optimization when sending and receiving messages on Yahoo: only
Mark Doliner <mark@kingant.net>
parents: 28102
diff changeset
782 src_len = strlen(src);
8660d8bc467c Minor optimization when sending and receiving messages on Yahoo: only
Mark Doliner <mark@kingant.net>
parents: 28102
diff changeset
783 dest = g_string_sized_new(src_len);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
784
28103
8660d8bc467c Minor optimization when sending and receiving messages on Yahoo: only
Mark Doliner <mark@kingant.net>
parents: 28102
diff changeset
785 for (i = 0; i < src_len; i++) {
28362
c06114f3d58d * Change yahoo_html_to_codes() a little to hopefully be more straight forward
Mark Doliner <mark@kingant.net>
parents: 28348
diff changeset
786 if (src[i] == '<' && !no_more_gt_brackets) {
c06114f3d58d * Change yahoo_html_to_codes() a little to hopefully be more straight forward
Mark Doliner <mark@kingant.net>
parents: 28348
diff changeset
787 /* The start of an HTML tag */
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
788 j = i;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
789
28362
c06114f3d58d * Change yahoo_html_to_codes() a little to hopefully be more straight forward
Mark Doliner <mark@kingant.net>
parents: 28348
diff changeset
790 while (j++ < src_len) {
c06114f3d58d * Change yahoo_html_to_codes() a little to hopefully be more straight forward
Mark Doliner <mark@kingant.net>
parents: 28348
diff changeset
791 if (src[j] != '>') {
c06114f3d58d * Change yahoo_html_to_codes() a little to hopefully be more straight forward
Mark Doliner <mark@kingant.net>
parents: 28348
diff changeset
792 if (src[j] == '"') {
c06114f3d58d * Change yahoo_html_to_codes() a little to hopefully be more straight forward
Mark Doliner <mark@kingant.net>
parents: 28348
diff changeset
793 /* We're inside a quoted attribute value. Skip to the end */
c06114f3d58d * Change yahoo_html_to_codes() a little to hopefully be more straight forward
Mark Doliner <mark@kingant.net>
parents: 28348
diff changeset
794 j++;
c06114f3d58d * Change yahoo_html_to_codes() a little to hopefully be more straight forward
Mark Doliner <mark@kingant.net>
parents: 28348
diff changeset
795 while (j != src_len && src[j] != '"')
c06114f3d58d * Change yahoo_html_to_codes() a little to hopefully be more straight forward
Mark Doliner <mark@kingant.net>
parents: 28348
diff changeset
796 j++;
c06114f3d58d * Change yahoo_html_to_codes() a little to hopefully be more straight forward
Mark Doliner <mark@kingant.net>
parents: 28348
diff changeset
797 } else if (src[j] == '\'') {
c06114f3d58d * Change yahoo_html_to_codes() a little to hopefully be more straight forward
Mark Doliner <mark@kingant.net>
parents: 28348
diff changeset
798 /* We're inside a quoted attribute value. Skip to the end */
c06114f3d58d * Change yahoo_html_to_codes() a little to hopefully be more straight forward
Mark Doliner <mark@kingant.net>
parents: 28348
diff changeset
799 j++;
c06114f3d58d * Change yahoo_html_to_codes() a little to hopefully be more straight forward
Mark Doliner <mark@kingant.net>
parents: 28348
diff changeset
800 while (j != src_len && src[j] != '\'')
c06114f3d58d * Change yahoo_html_to_codes() a little to hopefully be more straight forward
Mark Doliner <mark@kingant.net>
parents: 28348
diff changeset
801 j++;
c06114f3d58d * Change yahoo_html_to_codes() a little to hopefully be more straight forward
Mark Doliner <mark@kingant.net>
parents: 28348
diff changeset
802 }
c06114f3d58d * Change yahoo_html_to_codes() a little to hopefully be more straight forward
Mark Doliner <mark@kingant.net>
parents: 28348
diff changeset
803 if (j != src_len)
c06114f3d58d * Change yahoo_html_to_codes() a little to hopefully be more straight forward
Mark Doliner <mark@kingant.net>
parents: 28348
diff changeset
804 /* Keep looking for the end of this tag */
c06114f3d58d * Change yahoo_html_to_codes() a little to hopefully be more straight forward
Mark Doliner <mark@kingant.net>
parents: 28348
diff changeset
805 continue;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
806
28362
c06114f3d58d * Change yahoo_html_to_codes() a little to hopefully be more straight forward
Mark Doliner <mark@kingant.net>
parents: 28348
diff changeset
807 /* This < has no corresponding > */
c06114f3d58d * Change yahoo_html_to_codes() a little to hopefully be more straight forward
Mark Doliner <mark@kingant.net>
parents: 28348
diff changeset
808 g_string_append_c(dest, src[i]);
c06114f3d58d * Change yahoo_html_to_codes() a little to hopefully be more straight forward
Mark Doliner <mark@kingant.net>
parents: 28348
diff changeset
809 no_more_gt_brackets = TRUE;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
810 break;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
811 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
812
28362
c06114f3d58d * Change yahoo_html_to_codes() a little to hopefully be more straight forward
Mark Doliner <mark@kingant.net>
parents: 28348
diff changeset
813 tag = g_strndup(src + i, j - i + 1);
c06114f3d58d * Change yahoo_html_to_codes() a little to hopefully be more straight forward
Mark Doliner <mark@kingant.net>
parents: 28348
diff changeset
814 tag_name = yahoo_markup_get_tag_name(tag, &is_closing_tag);
c06114f3d58d * Change yahoo_html_to_codes() a little to hopefully be more straight forward
Mark Doliner <mark@kingant.net>
parents: 28348
diff changeset
815
c06114f3d58d * Change yahoo_html_to_codes() a little to hopefully be more straight forward
Mark Doliner <mark@kingant.net>
parents: 28348
diff changeset
816 if (g_str_equal(tag_name, "a")) {
28363
b289449f3e9f Make outgoing yahoo messages with links, font color, font face or font size
Mark Doliner <mark@kingant.net>
parents: 28362
diff changeset
817 const char *start;
b289449f3e9f Make outgoing yahoo messages with links, font color, font face or font size
Mark Doliner <mark@kingant.net>
parents: 28362
diff changeset
818 const char *end;
b289449f3e9f Make outgoing yahoo messages with links, font color, font face or font size
Mark Doliner <mark@kingant.net>
parents: 28362
diff changeset
819 GData *attributes;
b289449f3e9f Make outgoing yahoo messages with links, font color, font face or font size
Mark Doliner <mark@kingant.net>
parents: 28362
diff changeset
820 const char *attribute;
b289449f3e9f Make outgoing yahoo messages with links, font color, font face or font size
Mark Doliner <mark@kingant.net>
parents: 28362
diff changeset
821
b289449f3e9f Make outgoing yahoo messages with links, font color, font face or font size
Mark Doliner <mark@kingant.net>
parents: 28362
diff changeset
822 /*
b289449f3e9f Make outgoing yahoo messages with links, font color, font face or font size
Mark Doliner <mark@kingant.net>
parents: 28362
diff changeset
823 * TODO: Ideally we would replace this:
b289449f3e9f Make outgoing yahoo messages with links, font color, font face or font size
Mark Doliner <mark@kingant.net>
parents: 28362
diff changeset
824 * <a href="http://pidgin.im/">Pidgin</a>
b289449f3e9f Make outgoing yahoo messages with links, font color, font face or font size
Mark Doliner <mark@kingant.net>
parents: 28362
diff changeset
825 * with this:
b289449f3e9f Make outgoing yahoo messages with links, font color, font face or font size
Mark Doliner <mark@kingant.net>
parents: 28362
diff changeset
826 * Pidgin (http://pidgin.im/)
b289449f3e9f Make outgoing yahoo messages with links, font color, font face or font size
Mark Doliner <mark@kingant.net>
parents: 28362
diff changeset
827 *
b289449f3e9f Make outgoing yahoo messages with links, font color, font face or font size
Mark Doliner <mark@kingant.net>
parents: 28362
diff changeset
828 * Currently we drop the text within the <a> tag and
b289449f3e9f Make outgoing yahoo messages with links, font color, font face or font size
Mark Doliner <mark@kingant.net>
parents: 28362
diff changeset
829 * just show the URL. Doing it the fancy way is
b289449f3e9f Make outgoing yahoo messages with links, font color, font face or font size
Mark Doliner <mark@kingant.net>
parents: 28362
diff changeset
830 * complicated when dealing with HTML tags within the
b289449f3e9f Make outgoing yahoo messages with links, font color, font face or font size
Mark Doliner <mark@kingant.net>
parents: 28362
diff changeset
831 * <a> tag.
b289449f3e9f Make outgoing yahoo messages with links, font color, font face or font size
Mark Doliner <mark@kingant.net>
parents: 28362
diff changeset
832 */
b289449f3e9f Make outgoing yahoo messages with links, font color, font face or font size
Mark Doliner <mark@kingant.net>
parents: 28362
diff changeset
833
b289449f3e9f Make outgoing yahoo messages with links, font color, font face or font size
Mark Doliner <mark@kingant.net>
parents: 28362
diff changeset
834 /* Append the URL */
b289449f3e9f Make outgoing yahoo messages with links, font color, font face or font size
Mark Doliner <mark@kingant.net>
parents: 28362
diff changeset
835 purple_markup_find_tag(tag_name, tag, &start, &end, &attributes);
b289449f3e9f Make outgoing yahoo messages with links, font color, font face or font size
Mark Doliner <mark@kingant.net>
parents: 28362
diff changeset
836 attribute = g_datalist_get_data(&attributes, "href");
b289449f3e9f Make outgoing yahoo messages with links, font color, font face or font size
Mark Doliner <mark@kingant.net>
parents: 28362
diff changeset
837 if (attribute != NULL) {
b289449f3e9f Make outgoing yahoo messages with links, font color, font face or font size
Mark Doliner <mark@kingant.net>
parents: 28362
diff changeset
838 if (purple_str_has_prefix(attribute, "mailto:"))
b289449f3e9f Make outgoing yahoo messages with links, font color, font face or font size
Mark Doliner <mark@kingant.net>
parents: 28362
diff changeset
839 attribute += 7;
b289449f3e9f Make outgoing yahoo messages with links, font color, font face or font size
Mark Doliner <mark@kingant.net>
parents: 28362
diff changeset
840 g_string_append(dest, attribute);
28362
c06114f3d58d * Change yahoo_html_to_codes() a little to hopefully be more straight forward
Mark Doliner <mark@kingant.net>
parents: 28348
diff changeset
841 }
28363
b289449f3e9f Make outgoing yahoo messages with links, font color, font face or font size
Mark Doliner <mark@kingant.net>
parents: 28362
diff changeset
842 g_datalist_clear(&attributes);
b289449f3e9f Make outgoing yahoo messages with links, font color, font face or font size
Mark Doliner <mark@kingant.net>
parents: 28362
diff changeset
843
b289449f3e9f Make outgoing yahoo messages with links, font color, font face or font size
Mark Doliner <mark@kingant.net>
parents: 28362
diff changeset
844 /* Skip past the closing </a> tag */
b289449f3e9f Make outgoing yahoo messages with links, font color, font face or font size
Mark Doliner <mark@kingant.net>
parents: 28362
diff changeset
845 end = purple_strcasestr(src + j, "</a>");
b289449f3e9f Make outgoing yahoo messages with links, font color, font face or font size
Mark Doliner <mark@kingant.net>
parents: 28362
diff changeset
846 if (end != NULL)
b289449f3e9f Make outgoing yahoo messages with links, font color, font face or font size
Mark Doliner <mark@kingant.net>
parents: 28362
diff changeset
847 j = end - src + 3;
28362
c06114f3d58d * Change yahoo_html_to_codes() a little to hopefully be more straight forward
Mark Doliner <mark@kingant.net>
parents: 28348
diff changeset
848
c06114f3d58d * Change yahoo_html_to_codes() a little to hopefully be more straight forward
Mark Doliner <mark@kingant.net>
parents: 28348
diff changeset
849 } else if (g_str_equal(tag_name, "font")) {
28378
6b446431b2b0 This function no longer needs these two parameters
Mark Doliner <mark@kingant.net>
parents: 28377
diff changeset
850 parse_font_tag(dest, tag_name, tag, &colors, &tags);
28362
c06114f3d58d * Change yahoo_html_to_codes() a little to hopefully be more straight forward
Mark Doliner <mark@kingant.net>
parents: 28348
diff changeset
851 } else if (g_str_equal(tag_name, "b")) {
c06114f3d58d * Change yahoo_html_to_codes() a little to hopefully be more straight forward
Mark Doliner <mark@kingant.net>
parents: 28348
diff changeset
852 g_string_append(dest, "\033[1m");
c06114f3d58d * Change yahoo_html_to_codes() a little to hopefully be more straight forward
Mark Doliner <mark@kingant.net>
parents: 28348
diff changeset
853 current_state.bold = TRUE;
c06114f3d58d * Change yahoo_html_to_codes() a little to hopefully be more straight forward
Mark Doliner <mark@kingant.net>
parents: 28348
diff changeset
854 } else if (g_str_equal(tag_name, "/b")) {
c06114f3d58d * Change yahoo_html_to_codes() a little to hopefully be more straight forward
Mark Doliner <mark@kingant.net>
parents: 28348
diff changeset
855 if (current_state.bold) {
c06114f3d58d * Change yahoo_html_to_codes() a little to hopefully be more straight forward
Mark Doliner <mark@kingant.net>
parents: 28348
diff changeset
856 g_string_append(dest, "\033[x1m");
c06114f3d58d * Change yahoo_html_to_codes() a little to hopefully be more straight forward
Mark Doliner <mark@kingant.net>
parents: 28348
diff changeset
857 current_state.bold = FALSE;
c06114f3d58d * Change yahoo_html_to_codes() a little to hopefully be more straight forward
Mark Doliner <mark@kingant.net>
parents: 28348
diff changeset
858 }
c06114f3d58d * Change yahoo_html_to_codes() a little to hopefully be more straight forward
Mark Doliner <mark@kingant.net>
parents: 28348
diff changeset
859 } else if (g_str_equal(tag_name, "i")) {
c06114f3d58d * Change yahoo_html_to_codes() a little to hopefully be more straight forward
Mark Doliner <mark@kingant.net>
parents: 28348
diff changeset
860 current_state.italic = TRUE;
c06114f3d58d * Change yahoo_html_to_codes() a little to hopefully be more straight forward
Mark Doliner <mark@kingant.net>
parents: 28348
diff changeset
861 g_string_append(dest, "\033[2m");
c06114f3d58d * Change yahoo_html_to_codes() a little to hopefully be more straight forward
Mark Doliner <mark@kingant.net>
parents: 28348
diff changeset
862 } else if (g_str_equal(tag_name, "/i")) {
c06114f3d58d * Change yahoo_html_to_codes() a little to hopefully be more straight forward
Mark Doliner <mark@kingant.net>
parents: 28348
diff changeset
863 if (current_state.italic) {
c06114f3d58d * Change yahoo_html_to_codes() a little to hopefully be more straight forward
Mark Doliner <mark@kingant.net>
parents: 28348
diff changeset
864 g_string_append(dest, "\033[x2m");
c06114f3d58d * Change yahoo_html_to_codes() a little to hopefully be more straight forward
Mark Doliner <mark@kingant.net>
parents: 28348
diff changeset
865 current_state.italic = FALSE;
c06114f3d58d * Change yahoo_html_to_codes() a little to hopefully be more straight forward
Mark Doliner <mark@kingant.net>
parents: 28348
diff changeset
866 }
c06114f3d58d * Change yahoo_html_to_codes() a little to hopefully be more straight forward
Mark Doliner <mark@kingant.net>
parents: 28348
diff changeset
867 } else if (g_str_equal(tag_name, "u")) {
c06114f3d58d * Change yahoo_html_to_codes() a little to hopefully be more straight forward
Mark Doliner <mark@kingant.net>
parents: 28348
diff changeset
868 current_state.underline = TRUE;
c06114f3d58d * Change yahoo_html_to_codes() a little to hopefully be more straight forward
Mark Doliner <mark@kingant.net>
parents: 28348
diff changeset
869 g_string_append(dest, "\033[4m");
c06114f3d58d * Change yahoo_html_to_codes() a little to hopefully be more straight forward
Mark Doliner <mark@kingant.net>
parents: 28348
diff changeset
870 } else if (g_str_equal(tag_name, "/u")) {
c06114f3d58d * Change yahoo_html_to_codes() a little to hopefully be more straight forward
Mark Doliner <mark@kingant.net>
parents: 28348
diff changeset
871 if (current_state.underline) {
c06114f3d58d * Change yahoo_html_to_codes() a little to hopefully be more straight forward
Mark Doliner <mark@kingant.net>
parents: 28348
diff changeset
872 g_string_append(dest, "\033[x4m");
c06114f3d58d * Change yahoo_html_to_codes() a little to hopefully be more straight forward
Mark Doliner <mark@kingant.net>
parents: 28348
diff changeset
873 current_state.underline = FALSE;
c06114f3d58d * Change yahoo_html_to_codes() a little to hopefully be more straight forward
Mark Doliner <mark@kingant.net>
parents: 28348
diff changeset
874 }
c06114f3d58d * Change yahoo_html_to_codes() a little to hopefully be more straight forward
Mark Doliner <mark@kingant.net>
parents: 28348
diff changeset
875 } else if (g_str_equal(tag_name, "/a")) {
28363
b289449f3e9f Make outgoing yahoo messages with links, font color, font face or font size
Mark Doliner <mark@kingant.net>
parents: 28362
diff changeset
876 /* Do nothing */
28362
c06114f3d58d * Change yahoo_html_to_codes() a little to hopefully be more straight forward
Mark Doliner <mark@kingant.net>
parents: 28348
diff changeset
877 } else if (g_str_equal(tag_name, "br")) {
c06114f3d58d * Change yahoo_html_to_codes() a little to hopefully be more straight forward
Mark Doliner <mark@kingant.net>
parents: 28348
diff changeset
878 g_string_append_c(dest, '\n');
c06114f3d58d * Change yahoo_html_to_codes() a little to hopefully be more straight forward
Mark Doliner <mark@kingant.net>
parents: 28348
diff changeset
879 } else if (g_str_equal(tag_name, "/font")) {
c06114f3d58d * Change yahoo_html_to_codes() a little to hopefully be more straight forward
Mark Doliner <mark@kingant.net>
parents: 28348
diff changeset
880 if (tags != NULL) {
c06114f3d58d * Change yahoo_html_to_codes() a little to hopefully be more straight forward
Mark Doliner <mark@kingant.net>
parents: 28348
diff changeset
881 char *etag = tags->data;
c06114f3d58d * Change yahoo_html_to_codes() a little to hopefully be more straight forward
Mark Doliner <mark@kingant.net>
parents: 28348
diff changeset
882 tags = g_slist_delete_link(tags, tags);
c06114f3d58d * Change yahoo_html_to_codes() a little to hopefully be more straight forward
Mark Doliner <mark@kingant.net>
parents: 28348
diff changeset
883 g_string_append(dest, etag);
28383
2a6f0c2460ae Fix a bug in our outgoing yahoo message formatting where messages
Mark Doliner <mark@kingant.net>
parents: 28378
diff changeset
884 if (colors != NULL) {
2a6f0c2460ae Fix a bug in our outgoing yahoo message formatting where messages
Mark Doliner <mark@kingant.net>
parents: 28378
diff changeset
885 g_free(colors->data);
2a6f0c2460ae Fix a bug in our outgoing yahoo message formatting where messages
Mark Doliner <mark@kingant.net>
parents: 28378
diff changeset
886 colors = g_slist_delete_link(colors, colors);
16109
8e61e7be988b Stop Yahoo sending SPAN tags, fixes Yahoo part of ticket 78
Stu Tomlinson <stu@nosnilmot.com>
parents: 15823
diff changeset
887 }
28362
c06114f3d58d * Change yahoo_html_to_codes() a little to hopefully be more straight forward
Mark Doliner <mark@kingant.net>
parents: 28348
diff changeset
888 g_free(etag);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
889 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
890 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
891
28362
c06114f3d58d * Change yahoo_html_to_codes() a little to hopefully be more straight forward
Mark Doliner <mark@kingant.net>
parents: 28348
diff changeset
892 i = j;
c06114f3d58d * Change yahoo_html_to_codes() a little to hopefully be more straight forward
Mark Doliner <mark@kingant.net>
parents: 28348
diff changeset
893 g_free(tag);
c06114f3d58d * Change yahoo_html_to_codes() a little to hopefully be more straight forward
Mark Doliner <mark@kingant.net>
parents: 28348
diff changeset
894 g_free(tag_name);
c06114f3d58d * Change yahoo_html_to_codes() a little to hopefully be more straight forward
Mark Doliner <mark@kingant.net>
parents: 28348
diff changeset
895 break;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
896 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
897
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
898 } else {
28168
64fd19956153 Reuse our purple_markup_unescape_entity() function instead of
Mark Doliner <mark@kingant.net>
parents: 28167
diff changeset
899 const char *entity;
64fd19956153 Reuse our purple_markup_unescape_entity() function instead of
Mark Doliner <mark@kingant.net>
parents: 28167
diff changeset
900 int length;
64fd19956153 Reuse our purple_markup_unescape_entity() function instead of
Mark Doliner <mark@kingant.net>
parents: 28167
diff changeset
901
64fd19956153 Reuse our purple_markup_unescape_entity() function instead of
Mark Doliner <mark@kingant.net>
parents: 28167
diff changeset
902 entity = purple_markup_unescape_entity(src + i, &length);
64fd19956153 Reuse our purple_markup_unescape_entity() function instead of
Mark Doliner <mark@kingant.net>
parents: 28167
diff changeset
903 if (entity != NULL) {
64fd19956153 Reuse our purple_markup_unescape_entity() function instead of
Mark Doliner <mark@kingant.net>
parents: 28167
diff changeset
904 /* src[i] is the start of an HTML entity */
64fd19956153 Reuse our purple_markup_unescape_entity() function instead of
Mark Doliner <mark@kingant.net>
parents: 28167
diff changeset
905 g_string_append(dest, entity);
64fd19956153 Reuse our purple_markup_unescape_entity() function instead of
Mark Doliner <mark@kingant.net>
parents: 28167
diff changeset
906 i += length - 1;
64fd19956153 Reuse our purple_markup_unescape_entity() function instead of
Mark Doliner <mark@kingant.net>
parents: 28167
diff changeset
907 } else
64fd19956153 Reuse our purple_markup_unescape_entity() function instead of
Mark Doliner <mark@kingant.net>
parents: 28167
diff changeset
908 /* src[i] is a normal character */
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
909 g_string_append_c(dest, src[i]);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
910 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
911 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
912
28080
a0a8b61301c8 Simplify a wee bit
Mark Doliner <mark@kingant.net>
parents: 28025
diff changeset
913 esc = g_strescape(dest->str, NULL);
28363
b289449f3e9f Make outgoing yahoo messages with links, font color, font face or font size
Mark Doliner <mark@kingant.net>
parents: 28362
diff changeset
914 purple_debug_misc("yahoo", "yahoo_html_to_codes(%s)=%s\n", src, esc);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
915 g_free(esc);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
916
28166
bc9da266d25d This is actually a stack, not a queue, so we can use a simpler data
Mark Doliner <mark@kingant.net>
parents: 28165
diff changeset
917 yahoo_htc_list_cleanup(colors);
bc9da266d25d This is actually a stack, not a queue, so we can use a simpler data
Mark Doliner <mark@kingant.net>
parents: 28165
diff changeset
918 yahoo_htc_list_cleanup(tags);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
919
28080
a0a8b61301c8 Simplify a wee bit
Mark Doliner <mark@kingant.net>
parents: 28025
diff changeset
920 return g_string_free(dest, FALSE);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
921 }