libpurple/protocols/yahoo/util.c

Fri, 19 Jun 2009 20:34:02 +0000

author
John Bailey <rekkanoryo@rekkanoryo.org>
date
Fri, 19 Jun 2009 20:34:02 +0000
branch
release-2.5.7
changeset 25765
b2e8fd04620e
parent 24181
e028e31dcc67
child 27361
62f1aa8045bb
permissions
-rw-r--r--

Ugly hack to get around needing a minor bump to make this authentication code
work with some proxies. I yanked the relevant code from 2.6.0devel's
libpurple/util.c and made it local to the yahoo prpl.

6513
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
1 /*
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
2 * purple
6513
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
3 *
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
4 * Some code copyright 2003 Tim Ringenbach <omarvo@hotmail.com>
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
5 * (marv on irc.freenode.net)
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
6 *
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
7 * This program is free software; you can redistribute it and/or modify
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
8 * it under the terms of the GNU General Public License as published by
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
9 * the Free Software Foundation; either version 2 of the License, or
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
10 * (at your option) any later version.
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
11 *
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful,
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
15 * GNU General Public License for more details.
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
16 *
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
17 * You should have received a copy of the GNU General Public License
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
18 * along with this program; if not, write to the Free Software
19859
71d37b57eff2 The FSF changed its address a while ago; our files were out of date.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 19337
diff changeset
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
6513
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
20 *
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
21 */
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
22
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
23 #ifdef HAVE_CONFIG_H
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
24 #include "config.h"
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
25 #endif
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
26
25765
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
27 #include "cipher.h"
10023
6b0014040323 [gaim-migrate @ 10955]
Mark Doliner <markdoliner@pidgin.im>
parents: 9164
diff changeset
28 #include "debug.h"
6b0014040323 [gaim-migrate @ 10955]
Mark Doliner <markdoliner@pidgin.im>
parents: 9164
diff changeset
29 #include "internal.h"
6513
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
30 #include "prpl.h"
25765
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
31 #include "util.h"
10023
6b0014040323 [gaim-migrate @ 10955]
Mark Doliner <markdoliner@pidgin.im>
parents: 9164
diff changeset
32
7827
080c98045e12 [gaim-migrate @ 8479]
Ethan Blanton <elb@pidgin.im>
parents: 6631
diff changeset
33 #include "yahoo.h"
6513
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
34
6546
6a14dfe43d5c [gaim-migrate @ 7068]
Mark Doliner <markdoliner@pidgin.im>
parents: 6513
diff changeset
35 #include <string.h>
24181
e028e31dcc67 Do a better job of detecting if the yahoo account is connecting through a HTTP
Daniel Atallah <datallah@pidgin.im>
parents: 23173
diff changeset
36
25765
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
37 struct _PurpleUtilFetchUrlData
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
38 {
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
39 PurpleUtilFetchUrlCallback callback;
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
40 void *user_data;
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
41
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
42 struct
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
43 {
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
44 char *user;
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
45 char *passwd;
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
46 char *address;
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
47 int port;
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
48 char *page;
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
49
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
50 } website;
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
51
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
52 char *url;
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
53 int num_times_redirected;
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
54 gboolean full;
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
55 char *user_agent;
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
56 gboolean http11;
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
57 char *request;
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
58 gsize request_written;
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
59 gboolean include_headers;
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
60
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
61 gboolean is_ssl;
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
62 PurpleSslConnection *ssl_connection;
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
63 PurpleProxyConnectData *connect_data;
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
64 int fd;
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
65 guint inpa;
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
66
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
67 gboolean got_headers;
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
68 gboolean has_explicit_data_len;
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
69 char *webdata;
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
70 unsigned long len;
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
71 unsigned long data_len;
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
72 gssize max_len;
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
73 };
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
74
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
75 /**
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
76 * The arguments to this function are similar to printf.
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
77 */
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
78 static void
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
79 purple_util_fetch_url_error(PurpleUtilFetchUrlData *gfud, const char *format, ...)
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
80 {
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
81 gchar *error_message;
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
82 va_list args;
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
83
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
84 va_start(args, format);
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
85 error_message = g_strdup_vprintf(format, args);
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
86 va_end(args);
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
87
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
88 gfud->callback(gfud, gfud->user_data, NULL, 0, error_message);
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
89 g_free(error_message);
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
90 purple_util_fetch_url_cancel(gfud);
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
91 }
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
92 static void url_fetch_connect_cb(gpointer url_data, gint source, const gchar *error_message);
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
93 static void ssl_url_fetch_connect_cb(gpointer data, PurpleSslConnection *ssl_connection, PurpleInputCondition cond);
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
94 static void ssl_url_fetch_error_cb(PurpleSslConnection *ssl_connection, PurpleSslErrorType error, gpointer data);
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
95
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
96 static gboolean
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
97 parse_redirect(const char *data, size_t data_len,
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
98 PurpleUtilFetchUrlData *gfud)
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
99 {
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
100 gchar *s;
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
101 gchar *new_url, *temp_url, *end;
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
102 gboolean full;
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
103 int len;
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
104
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
105 if ((s = g_strstr_len(data, data_len, "\nLocation: ")) == NULL)
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
106 /* We're not being redirected */
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
107 return FALSE;
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
108
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
109 s += strlen("Location: ");
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
110 end = strchr(s, '\r');
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
111
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
112 /* Just in case :) */
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
113 if (end == NULL)
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
114 end = strchr(s, '\n');
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
115
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
116 if (end == NULL)
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
117 return FALSE;
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
118
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
119 len = end - s;
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
120
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
121 new_url = g_malloc(len + 1);
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
122 strncpy(new_url, s, len);
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
123 new_url[len] = '\0';
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
124
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
125 full = gfud->full;
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
126
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
127 if (*new_url == '/' || g_strstr_len(new_url, len, "://") == NULL)
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
128 {
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
129 temp_url = new_url;
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
130
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
131 new_url = g_strdup_printf("%s:%d%s", gfud->website.address,
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
132 gfud->website.port, temp_url);
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
133
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
134 g_free(temp_url);
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
135
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
136 full = FALSE;
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
137 }
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
138
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
139 purple_debug_info("util", "Redirecting to %s\n", new_url);
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
140
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
141 gfud->num_times_redirected++;
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
142 if (gfud->num_times_redirected >= 5)
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
143 {
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
144 purple_util_fetch_url_error(gfud,
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
145 _("Could not open %s: Redirected too many times"),
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
146 gfud->url);
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
147 return TRUE;
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
148 }
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
149
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
150 /*
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
151 * Try again, with this new location. This code is somewhat
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
152 * ugly, but we need to reuse the gfud because whoever called
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
153 * us is holding a reference to it.
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
154 */
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
155 g_free(gfud->url);
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
156 gfud->url = new_url;
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
157 gfud->full = full;
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
158 g_free(gfud->request);
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
159 gfud->request = NULL;
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
160
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
161 if (gfud->is_ssl) {
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
162 gfud->is_ssl = FALSE;
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
163 purple_ssl_close(gfud->ssl_connection);
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
164 gfud->ssl_connection = NULL;
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
165 } else {
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
166 purple_input_remove(gfud->inpa);
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
167 gfud->inpa = 0;
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
168 close(gfud->fd);
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
169 gfud->fd = -1;
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
170 }
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
171 gfud->request_written = 0;
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
172 gfud->len = 0;
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
173 gfud->data_len = 0;
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
174
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
175 g_free(gfud->website.user);
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
176 g_free(gfud->website.passwd);
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
177 g_free(gfud->website.address);
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
178 g_free(gfud->website.page);
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
179 purple_url_parse(new_url, &gfud->website.address, &gfud->website.port,
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
180 &gfud->website.page, &gfud->website.user, &gfud->website.passwd);
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
181
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
182 if (purple_strcasestr(new_url, "https://") != NULL) {
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
183 gfud->is_ssl = TRUE;
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
184 gfud->ssl_connection = purple_ssl_connect(NULL,
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
185 gfud->website.address, gfud->website.port,
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
186 ssl_url_fetch_connect_cb, ssl_url_fetch_error_cb, gfud);
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
187 } else {
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
188 gfud->connect_data = purple_proxy_connect(NULL, NULL,
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
189 gfud->website.address, gfud->website.port,
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
190 url_fetch_connect_cb, gfud);
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
191 }
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
192
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
193 if (gfud->ssl_connection == NULL && gfud->connect_data == NULL)
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
194 {
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
195 purple_util_fetch_url_error(gfud, _("Unable to connect to %s"),
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
196 gfud->website.address);
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
197 }
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
198
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
199 return TRUE;
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
200 }
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
201
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
202 static size_t
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
203 parse_content_len(const char *data, size_t data_len)
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
204 {
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
205 size_t content_len = 0;
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
206 const char *p = NULL;
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
207
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
208 /* This is still technically wrong, since headers are case-insensitive
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
209 * [RFC 2616, section 4.2], though this ought to catch the normal case.
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
210 * Note: data is _not_ nul-terminated.
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
211 */
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
212 if(data_len > 16) {
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
213 p = (strncmp(data, "Content-Length: ", 16) == 0) ? data : NULL;
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
214 if(!p)
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
215 p = (strncmp(data, "CONTENT-LENGTH: ", 16) == 0)
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
216 ? data : NULL;
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
217 if(!p) {
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
218 p = g_strstr_len(data, data_len, "\nContent-Length: ");
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
219 if (p)
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
220 p++;
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
221 }
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
222 if(!p) {
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
223 p = g_strstr_len(data, data_len, "\nCONTENT-LENGTH: ");
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
224 if (p)
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
225 p++;
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
226 }
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
227
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
228 if(p)
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
229 p += 16;
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
230 }
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
231
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
232 /* If we can find a Content-Length header at all, try to sscanf it.
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
233 * Response headers should end with at least \r\n, so sscanf is safe,
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
234 * if we make sure that there is indeed a \n in our header.
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
235 */
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
236 if (p && g_strstr_len(p, data_len - (p - data), "\n")) {
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
237 sscanf(p, "%" G_GSIZE_FORMAT, &content_len);
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
238 purple_debug_misc("util", "parsed %" G_GSIZE_FORMAT "\n", content_len);
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
239 }
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
240
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
241 return content_len;
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
242 }
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
243
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
244
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
245 static void
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
246 url_fetch_recv_cb(gpointer url_data, gint source, PurpleInputCondition cond)
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
247 {
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
248 PurpleUtilFetchUrlData *gfud = url_data;
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
249 int len;
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
250 char buf[4096];
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
251 char *data_cursor;
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
252 gboolean got_eof = FALSE;
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
253
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
254 /*
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
255 * Read data in a loop until we can't read any more! This is a
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
256 * little confusing because we read using a different function
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
257 * depending on whether the socket is ssl or cleartext.
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
258 */
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
259 while ((gfud->is_ssl && ((len = purple_ssl_read(gfud->ssl_connection, buf, sizeof(buf))) > 0)) ||
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
260 (!gfud->is_ssl && (len = read(source, buf, sizeof(buf))) > 0))
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
261 {
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
262 if(gfud->max_len != -1 && (gfud->len + len) > gfud->max_len) {
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
263 purple_util_fetch_url_error(gfud, _("Error reading from %s: response too long (%d bytes limit)"),
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
264 gfud->website.address, gfud->max_len);
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
265 return;
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
266 }
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
267
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
268 /* If we've filled up our buffer, make it bigger */
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
269 if((gfud->len + len) >= gfud->data_len) {
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
270 while((gfud->len + len) >= gfud->data_len)
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
271 gfud->data_len += sizeof(buf);
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
272
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
273 gfud->webdata = g_realloc(gfud->webdata, gfud->data_len);
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
274 }
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
275
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
276 data_cursor = gfud->webdata + gfud->len;
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
277
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
278 gfud->len += len;
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
279
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
280 memcpy(data_cursor, buf, len);
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
281
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
282 gfud->webdata[gfud->len] = '\0';
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
283
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
284 if(!gfud->got_headers) {
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
285 char *tmp;
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
286
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
287 /* See if we've reached the end of the headers yet */
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
288 if((tmp = strstr(gfud->webdata, "\r\n\r\n"))) {
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
289 char * new_data;
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
290 guint header_len = (tmp + 4 - gfud->webdata);
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
291 size_t content_len;
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
292
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
293 purple_debug_misc("util", "Response headers: '%.*s'\n",
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
294 header_len, gfud->webdata);
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
295
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
296 /* See if we can find a redirect. */
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
297 if(parse_redirect(gfud->webdata, header_len, gfud))
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
298 return;
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
299
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
300 gfud->got_headers = TRUE;
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
301
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
302 /* No redirect. See if we can find a content length. */
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
303 content_len = parse_content_len(gfud->webdata, header_len);
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
304
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
305 if(content_len == 0) {
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
306 /* We'll stick with an initial 8192 */
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
307 content_len = 8192;
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
308 } else {
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
309 gfud->has_explicit_data_len = TRUE;
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
310 }
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
311
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
312
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
313 /* If we're returning the headers too, we don't need to clean them out */
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
314 if(gfud->include_headers) {
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
315 gfud->data_len = content_len + header_len;
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
316 gfud->webdata = g_realloc(gfud->webdata, gfud->data_len);
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
317 } else {
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
318 size_t body_len = 0;
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
319
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
320 if(gfud->len > (header_len + 1))
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
321 body_len = (gfud->len - header_len);
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
322
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
323 content_len = MAX(content_len, body_len);
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
324
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
325 new_data = g_try_malloc(content_len);
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
326 if(new_data == NULL) {
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
327 purple_debug_error("util",
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
328 "Failed to allocate %" G_GSIZE_FORMAT " bytes: %s\n",
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
329 content_len, g_strerror(errno));
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
330 purple_util_fetch_url_error(gfud,
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
331 _("Unable to allocate enough memory to hold "
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
332 "the contents from %s. The web server may "
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
333 "be trying something malicious."),
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
334 gfud->website.address);
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
335
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
336 return;
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
337 }
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
338
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
339 /* We may have read part of the body when reading the headers, don't lose it */
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
340 if(body_len > 0) {
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
341 tmp += 4;
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
342 memcpy(new_data, tmp, body_len);
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
343 }
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
344
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
345 /* Out with the old... */
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
346 g_free(gfud->webdata);
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
347
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
348 /* In with the new. */
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
349 gfud->len = body_len;
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
350 gfud->data_len = content_len;
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
351 gfud->webdata = new_data;
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
352 }
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
353 }
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
354 }
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
355
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
356 if(gfud->has_explicit_data_len && gfud->len >= gfud->data_len) {
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
357 got_eof = TRUE;
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
358 break;
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
359 }
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
360 }
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
361
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
362 if(len < 0) {
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
363 if(errno == EAGAIN) {
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
364 return;
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
365 } else {
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
366 purple_util_fetch_url_error(gfud, _("Error reading from %s: %s"),
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
367 gfud->website.address, g_strerror(errno));
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
368 return;
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
369 }
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
370 }
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
371
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
372 if((len == 0) || got_eof) {
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
373 gfud->webdata = g_realloc(gfud->webdata, gfud->len + 1);
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
374 gfud->webdata[gfud->len] = '\0';
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
375
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
376 gfud->callback(gfud, gfud->user_data, gfud->webdata, gfud->len, NULL);
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
377 purple_util_fetch_url_cancel(gfud);
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
378 }
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
379 }
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
380
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
381 static void ssl_url_fetch_recv_cb(gpointer data, PurpleSslConnection *ssl_connection, PurpleInputCondition cond)
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
382 {
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
383 url_fetch_recv_cb(data, -1, cond);
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
384 }
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
385
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
386 /*
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
387 * This function is called when the socket is available to be written
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
388 * to.
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
389 *
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
390 * @param source The file descriptor that can be written to. This can
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
391 * be an http connection or it can be the SSL connection of an
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
392 * https request. So be careful what you use it for! If it's
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
393 * an https request then use purple_ssl_write() instead of
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
394 * writing to it directly.
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
395 */
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
396 static void
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
397 url_fetch_send_cb(gpointer data, gint source, PurpleInputCondition cond)
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
398 {
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
399 PurpleUtilFetchUrlData *gfud;
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
400 int len, total_len;
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
401
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
402 gfud = data;
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
403
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
404 if (gfud->request == NULL)
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
405 {
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
406 /* Host header is not forbidden in HTTP/1.0 requests, and HTTP/1.1
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
407 * clients must know how to handle the "chunked" transfer encoding.
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
408 * Purple doesn't know how to handle "chunked", so should always send
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
409 * the Host header regardless, to get around some observed problems
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
410 */
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
411 if (gfud->user_agent) {
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
412 gfud->request = g_strdup_printf(
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
413 "GET %s%s HTTP/%s\r\n"
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
414 "Connection: close\r\n"
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
415 "User-Agent: %s\r\n"
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
416 "Accept: */*\r\n"
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
417 "Host: %s\r\n\r\n",
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
418 (gfud->full ? "" : "/"),
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
419 (gfud->full ? (gfud->url ? gfud->url : "") : (gfud->website.page ? gfud->website.page : "")),
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
420 (gfud->http11 ? "1.1" : "1.0"),
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
421 (gfud->user_agent ? gfud->user_agent : ""),
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
422 (gfud->website.address ? gfud->website.address : ""));
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
423 } else {
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
424 gfud->request = g_strdup_printf(
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
425 "GET %s%s HTTP/%s\r\n"
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
426 "Connection: close\r\n"
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
427 "Accept: */*\r\n"
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
428 "Host: %s\r\n\r\n",
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
429 (gfud->full ? "" : "/"),
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
430 (gfud->full ? (gfud->url ? gfud->url : "") : (gfud->website.page ? gfud->website.page : "")),
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
431 (gfud->http11 ? "1.1" : "1.0"),
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
432 (gfud->website.address ? gfud->website.address : ""));
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
433 }
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
434 }
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
435
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
436 if(g_getenv("PURPLE_UNSAFE_DEBUG"))
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
437 purple_debug_misc("util", "Request: '%s'\n", gfud->request);
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
438 else
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
439 purple_debug_misc("util", "request constructed\n");
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
440
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
441 total_len = strlen(gfud->request);
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
442
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
443 if (gfud->is_ssl)
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
444 len = purple_ssl_write(gfud->ssl_connection, gfud->request + gfud->request_written,
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
445 total_len - gfud->request_written);
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
446 else
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
447 len = write(gfud->fd, gfud->request + gfud->request_written,
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
448 total_len - gfud->request_written);
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
449
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
450 if (len < 0 && errno == EAGAIN)
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
451 return;
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
452 else if (len < 0) {
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
453 purple_util_fetch_url_error(gfud, _("Error writing to %s: %s"),
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
454 gfud->website.address, g_strerror(errno));
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
455 return;
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
456 }
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
457 gfud->request_written += len;
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
458
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
459 if (gfud->request_written < total_len)
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
460 return;
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
461
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
462 /* We're done writing our request, now start reading the response */
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
463 if (gfud->is_ssl) {
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
464 purple_input_remove(gfud->inpa);
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
465 gfud->inpa = 0;
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
466 purple_ssl_input_add(gfud->ssl_connection, ssl_url_fetch_recv_cb, gfud);
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
467 } else {
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
468 purple_input_remove(gfud->inpa);
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
469 gfud->inpa = purple_input_add(gfud->fd, PURPLE_INPUT_READ, url_fetch_recv_cb,
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
470 gfud);
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
471 }
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
472 }
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
473
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
474 static void
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
475 url_fetch_connect_cb(gpointer url_data, gint source, const gchar *error_message)
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
476 {
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
477 PurpleUtilFetchUrlData *gfud;
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
478
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
479 gfud = url_data;
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
480 gfud->connect_data = NULL;
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
481
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
482 if (source == -1)
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
483 {
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
484 purple_util_fetch_url_error(gfud, _("Unable to connect to %s: %s"),
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
485 (gfud->website.address ? gfud->website.address : ""), error_message);
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
486 return;
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
487 }
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
488
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
489 gfud->fd = source;
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
490
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
491 gfud->inpa = purple_input_add(source, PURPLE_INPUT_WRITE,
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
492 url_fetch_send_cb, gfud);
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
493 url_fetch_send_cb(gfud, source, PURPLE_INPUT_WRITE);
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
494 }
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
495
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
496 static void ssl_url_fetch_connect_cb(gpointer data, PurpleSslConnection *ssl_connection, PurpleInputCondition cond)
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
497 {
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
498 PurpleUtilFetchUrlData *gfud;
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
499
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
500 gfud = data;
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
501
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
502 gfud->inpa = purple_input_add(ssl_connection->fd, PURPLE_INPUT_WRITE,
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
503 url_fetch_send_cb, gfud);
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
504 url_fetch_send_cb(gfud, ssl_connection->fd, PURPLE_INPUT_WRITE);
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
505 }
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
506
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
507 static void ssl_url_fetch_error_cb(PurpleSslConnection *ssl_connection, PurpleSslErrorType error, gpointer data)
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
508 {
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
509 PurpleUtilFetchUrlData *gfud;
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
510
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
511 gfud = data;
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
512 gfud->ssl_connection = NULL;
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
513
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
514 purple_util_fetch_url_error(gfud, _("Unable to connect to %s: %s"),
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
515 (gfud->website.address ? gfud->website.address : ""),
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
516 purple_ssl_strerror(error));
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
517 }
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
518
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
519 PurpleUtilFetchUrlData *
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
520 purple_util_fetch_url_request_len_with_account(PurpleAccount *account,
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
521 const char *url, gboolean full, const char *user_agent, gboolean http11,
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
522 const char *request, gboolean include_headers, gssize max_len,
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
523 PurpleUtilFetchUrlCallback callback, void *user_data)
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
524 {
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
525 PurpleUtilFetchUrlData *gfud;
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
526
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
527 g_return_val_if_fail(url != NULL, NULL);
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
528 g_return_val_if_fail(callback != NULL, NULL);
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
529
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
530 if(g_getenv("PURPLE_UNSAFE_DEBUG"))
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
531 purple_debug_info("util",
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
532 "requested to fetch (%s), full=%d, user_agent=(%s), http11=%d\n",
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
533 url, full, user_agent?user_agent:"(null)", http11);
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
534 else
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
535 purple_debug_info("util", "requesting to fetch a URL\n");
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
536
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
537 gfud = g_new0(PurpleUtilFetchUrlData, 1);
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
538
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
539 gfud->callback = callback;
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
540 gfud->user_data = user_data;
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
541 gfud->url = g_strdup(url);
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
542 gfud->user_agent = g_strdup(user_agent);
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
543 gfud->http11 = http11;
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
544 gfud->full = full;
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
545 gfud->request = g_strdup(request);
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
546 gfud->include_headers = include_headers;
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
547 gfud->fd = -1;
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
548 gfud->max_len = max_len;
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
549
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
550 purple_url_parse(url, &gfud->website.address, &gfud->website.port,
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
551 &gfud->website.page, &gfud->website.user, &gfud->website.passwd);
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
552
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
553 if (purple_strcasestr(url, "https://") != NULL) {
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
554 if (!purple_ssl_is_supported()) {
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
555 purple_util_fetch_url_error(gfud,
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
556 _("Unable to connect to %s: Server requires TLS/SSL, but no TLS/SSL support was found."),
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
557 gfud->website.address);
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
558 return NULL;
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
559 }
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
560
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
561 gfud->is_ssl = TRUE;
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
562 gfud->ssl_connection = purple_ssl_connect(account,
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
563 gfud->website.address, gfud->website.port,
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
564 ssl_url_fetch_connect_cb, ssl_url_fetch_error_cb, gfud);
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
565 } else {
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
566 gfud->connect_data = purple_proxy_connect(NULL, account,
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
567 gfud->website.address, gfud->website.port,
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
568 url_fetch_connect_cb, gfud);
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
569 }
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
570
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
571 if (gfud->ssl_connection == NULL && gfud->connect_data == NULL)
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
572 {
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
573 purple_util_fetch_url_error(gfud, _("Unable to connect to %s"),
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
574 gfud->website.address);
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
575 return NULL;
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
576 }
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
577
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
578 return gfud;
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
579 }
b2e8fd04620e Ugly hack to get around needing a minor bump to make this authentication code
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24181
diff changeset
580
24181
e028e31dcc67 Do a better job of detecting if the yahoo account is connecting through a HTTP
Daniel Atallah <datallah@pidgin.im>
parents: 23173
diff changeset
581 gboolean
e028e31dcc67 Do a better job of detecting if the yahoo account is connecting through a HTTP
Daniel Atallah <datallah@pidgin.im>
parents: 23173
diff changeset
582 yahoo_account_use_http_proxy(PurpleConnection *conn)
e028e31dcc67 Do a better job of detecting if the yahoo account is connecting through a HTTP
Daniel Atallah <datallah@pidgin.im>
parents: 23173
diff changeset
583 {
e028e31dcc67 Do a better job of detecting if the yahoo account is connecting through a HTTP
Daniel Atallah <datallah@pidgin.im>
parents: 23173
diff changeset
584 PurpleProxyInfo *ppi = purple_proxy_get_setup(conn->account);
e028e31dcc67 Do a better job of detecting if the yahoo account is connecting through a HTTP
Daniel Atallah <datallah@pidgin.im>
parents: 23173
diff changeset
585 return (ppi->type == PURPLE_PROXY_HTTP || ppi->type == PURPLE_PROXY_USE_ENVVAR);
e028e31dcc67 Do a better job of detecting if the yahoo account is connecting through a HTTP
Daniel Atallah <datallah@pidgin.im>
parents: 23173
diff changeset
586 }
e028e31dcc67 Do a better job of detecting if the yahoo account is connecting through a HTTP
Daniel Atallah <datallah@pidgin.im>
parents: 23173
diff changeset
587
22202
e42ab2e3eba1 This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan Sankaranarayanan <madthanu@gmail.com>
parents: 21946
diff changeset
588 /*
e42ab2e3eba1 This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan Sankaranarayanan <madthanu@gmail.com>
parents: 21946
diff changeset
589 * Returns cookies formatted as a null terminated string for the given connection.
e42ab2e3eba1 This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan Sankaranarayanan <madthanu@gmail.com>
parents: 21946
diff changeset
590 * Must g_free return value.
e42ab2e3eba1 This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan Sankaranarayanan <madthanu@gmail.com>
parents: 21946
diff changeset
591 *
e42ab2e3eba1 This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan Sankaranarayanan <madthanu@gmail.com>
parents: 21946
diff changeset
592 * TODO:will work, but must test for strict correctness
e42ab2e3eba1 This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan Sankaranarayanan <madthanu@gmail.com>
parents: 21946
diff changeset
593 */
e42ab2e3eba1 This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan Sankaranarayanan <madthanu@gmail.com>
parents: 21946
diff changeset
594 gchar* yahoo_get_cookies(PurpleConnection *gc)
e42ab2e3eba1 This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan Sankaranarayanan <madthanu@gmail.com>
parents: 21946
diff changeset
595 {
e42ab2e3eba1 This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan Sankaranarayanan <madthanu@gmail.com>
parents: 21946
diff changeset
596 gchar *ans = NULL;
e42ab2e3eba1 This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan Sankaranarayanan <madthanu@gmail.com>
parents: 21946
diff changeset
597 gchar *cur;
e42ab2e3eba1 This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan Sankaranarayanan <madthanu@gmail.com>
parents: 21946
diff changeset
598 char firstflag = 1;
e42ab2e3eba1 This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan Sankaranarayanan <madthanu@gmail.com>
parents: 21946
diff changeset
599 gchar *t1,*t2,*t3;
e42ab2e3eba1 This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan Sankaranarayanan <madthanu@gmail.com>
parents: 21946
diff changeset
600 GSList *tmp;
e42ab2e3eba1 This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan Sankaranarayanan <madthanu@gmail.com>
parents: 21946
diff changeset
601 GSList *cookies;
e42ab2e3eba1 This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan Sankaranarayanan <madthanu@gmail.com>
parents: 21946
diff changeset
602 cookies = ((struct yahoo_data*)(gc->proto_data))->cookies;
e42ab2e3eba1 This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan Sankaranarayanan <madthanu@gmail.com>
parents: 21946
diff changeset
603 tmp = cookies;
e42ab2e3eba1 This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan Sankaranarayanan <madthanu@gmail.com>
parents: 21946
diff changeset
604 while(tmp)
e42ab2e3eba1 This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan Sankaranarayanan <madthanu@gmail.com>
parents: 21946
diff changeset
605 {
e42ab2e3eba1 This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan Sankaranarayanan <madthanu@gmail.com>
parents: 21946
diff changeset
606 cur = tmp->data;
e42ab2e3eba1 This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan Sankaranarayanan <madthanu@gmail.com>
parents: 21946
diff changeset
607 t1 = ans;
e42ab2e3eba1 This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan Sankaranarayanan <madthanu@gmail.com>
parents: 21946
diff changeset
608 t2 = g_strrstr(cur, ";expires=");
e42ab2e3eba1 This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan Sankaranarayanan <madthanu@gmail.com>
parents: 21946
diff changeset
609 if(t2 == NULL)
e42ab2e3eba1 This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan Sankaranarayanan <madthanu@gmail.com>
parents: 21946
diff changeset
610 t2 = g_strrstr(cur, "; expires=");
e42ab2e3eba1 This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan Sankaranarayanan <madthanu@gmail.com>
parents: 21946
diff changeset
611 if(t2 == NULL)
e42ab2e3eba1 This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan Sankaranarayanan <madthanu@gmail.com>
parents: 21946
diff changeset
612 {
e42ab2e3eba1 This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan Sankaranarayanan <madthanu@gmail.com>
parents: 21946
diff changeset
613 if(firstflag)
e42ab2e3eba1 This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan Sankaranarayanan <madthanu@gmail.com>
parents: 21946
diff changeset
614 ans = g_strdup_printf("%c=%s", cur[0], cur+2);
e42ab2e3eba1 This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan Sankaranarayanan <madthanu@gmail.com>
parents: 21946
diff changeset
615 else
e42ab2e3eba1 This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan Sankaranarayanan <madthanu@gmail.com>
parents: 21946
diff changeset
616 ans = g_strdup_printf("%s; %c=%s", t1, cur[0], cur+2);
e42ab2e3eba1 This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan Sankaranarayanan <madthanu@gmail.com>
parents: 21946
diff changeset
617 }
e42ab2e3eba1 This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan Sankaranarayanan <madthanu@gmail.com>
parents: 21946
diff changeset
618 else
e42ab2e3eba1 This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan Sankaranarayanan <madthanu@gmail.com>
parents: 21946
diff changeset
619 {
e42ab2e3eba1 This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan Sankaranarayanan <madthanu@gmail.com>
parents: 21946
diff changeset
620 t3 = strstr(t2+1, ";");
e42ab2e3eba1 This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan Sankaranarayanan <madthanu@gmail.com>
parents: 21946
diff changeset
621 if(t3 != NULL)
e42ab2e3eba1 This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan Sankaranarayanan <madthanu@gmail.com>
parents: 21946
diff changeset
622 {
e42ab2e3eba1 This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan Sankaranarayanan <madthanu@gmail.com>
parents: 21946
diff changeset
623 t2[0] = '\0';
e42ab2e3eba1 This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan Sankaranarayanan <madthanu@gmail.com>
parents: 21946
diff changeset
624
e42ab2e3eba1 This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan Sankaranarayanan <madthanu@gmail.com>
parents: 21946
diff changeset
625 if(firstflag)
e42ab2e3eba1 This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan Sankaranarayanan <madthanu@gmail.com>
parents: 21946
diff changeset
626 ans = g_strdup_printf("%c=%s%s", cur[0], cur+2, t3);
e42ab2e3eba1 This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan Sankaranarayanan <madthanu@gmail.com>
parents: 21946
diff changeset
627 else
e42ab2e3eba1 This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan Sankaranarayanan <madthanu@gmail.com>
parents: 21946
diff changeset
628 ans = g_strdup_printf("%s; %c=%s%s", t1, cur[0], cur+2, t3);
e42ab2e3eba1 This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan Sankaranarayanan <madthanu@gmail.com>
parents: 21946
diff changeset
629
e42ab2e3eba1 This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan Sankaranarayanan <madthanu@gmail.com>
parents: 21946
diff changeset
630 t2[0] = ';';
e42ab2e3eba1 This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan Sankaranarayanan <madthanu@gmail.com>
parents: 21946
diff changeset
631 }
e42ab2e3eba1 This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan Sankaranarayanan <madthanu@gmail.com>
parents: 21946
diff changeset
632 else
e42ab2e3eba1 This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan Sankaranarayanan <madthanu@gmail.com>
parents: 21946
diff changeset
633 {
e42ab2e3eba1 This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan Sankaranarayanan <madthanu@gmail.com>
parents: 21946
diff changeset
634 t2[0] = '\0';
e42ab2e3eba1 This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan Sankaranarayanan <madthanu@gmail.com>
parents: 21946
diff changeset
635
e42ab2e3eba1 This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan Sankaranarayanan <madthanu@gmail.com>
parents: 21946
diff changeset
636 if(firstflag)
e42ab2e3eba1 This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan Sankaranarayanan <madthanu@gmail.com>
parents: 21946
diff changeset
637 ans = g_strdup_printf("%c=%s", cur[0], cur+2);
e42ab2e3eba1 This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan Sankaranarayanan <madthanu@gmail.com>
parents: 21946
diff changeset
638 else
e42ab2e3eba1 This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan Sankaranarayanan <madthanu@gmail.com>
parents: 21946
diff changeset
639 ans = g_strdup_printf("%s; %c=%s", t1, cur[0], cur+2);
e42ab2e3eba1 This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan Sankaranarayanan <madthanu@gmail.com>
parents: 21946
diff changeset
640
e42ab2e3eba1 This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan Sankaranarayanan <madthanu@gmail.com>
parents: 21946
diff changeset
641 t2[0] = ';';
e42ab2e3eba1 This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan Sankaranarayanan <madthanu@gmail.com>
parents: 21946
diff changeset
642 }
e42ab2e3eba1 This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan Sankaranarayanan <madthanu@gmail.com>
parents: 21946
diff changeset
643 }
e42ab2e3eba1 This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan Sankaranarayanan <madthanu@gmail.com>
parents: 21946
diff changeset
644 if(firstflag)
e42ab2e3eba1 This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan Sankaranarayanan <madthanu@gmail.com>
parents: 21946
diff changeset
645 firstflag = 0;
e42ab2e3eba1 This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan Sankaranarayanan <madthanu@gmail.com>
parents: 21946
diff changeset
646 else
e42ab2e3eba1 This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan Sankaranarayanan <madthanu@gmail.com>
parents: 21946
diff changeset
647 g_free(t1);
e42ab2e3eba1 This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan Sankaranarayanan <madthanu@gmail.com>
parents: 21946
diff changeset
648 tmp = g_slist_next(tmp);
e42ab2e3eba1 This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan Sankaranarayanan <madthanu@gmail.com>
parents: 21946
diff changeset
649 }
e42ab2e3eba1 This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan Sankaranarayanan <madthanu@gmail.com>
parents: 21946
diff changeset
650 return ans;
e42ab2e3eba1 This patch from Thanumalayan S. implements Yahoo protocol version 15 file
Thanumalayan Sankaranarayanan <madthanu@gmail.com>
parents: 21946
diff changeset
651 }
6546
6a14dfe43d5c [gaim-migrate @ 7068]
Mark Doliner <markdoliner@pidgin.im>
parents: 6513
diff changeset
652
7827
080c98045e12 [gaim-migrate @ 8479]
Ethan Blanton <elb@pidgin.im>
parents: 6631
diff changeset
653 /**
080c98045e12 [gaim-migrate @ 8479]
Ethan Blanton <elb@pidgin.im>
parents: 6631
diff changeset
654 * Encode some text to send to the yahoo server.
080c98045e12 [gaim-migrate @ 8479]
Ethan Blanton <elb@pidgin.im>
parents: 6631
diff changeset
655 *
080c98045e12 [gaim-migrate @ 8479]
Ethan Blanton <elb@pidgin.im>
parents: 6631
diff changeset
656 * @param gc The connection handle.
080c98045e12 [gaim-migrate @ 8479]
Ethan Blanton <elb@pidgin.im>
parents: 6631
diff changeset
657 * @param str The null terminated utf8 string to encode.
080c98045e12 [gaim-migrate @ 8479]
Ethan Blanton <elb@pidgin.im>
parents: 6631
diff changeset
658 * @param utf8 If not @c NULL, whether utf8 is okay or not.
080c98045e12 [gaim-migrate @ 8479]
Ethan Blanton <elb@pidgin.im>
parents: 6631
diff changeset
659 * Even if it is okay, we may not use it. If we
080c98045e12 [gaim-migrate @ 8479]
Ethan Blanton <elb@pidgin.im>
parents: 6631
diff changeset
660 * used it, we set this to @c TRUE, else to
080c98045e12 [gaim-migrate @ 8479]
Ethan Blanton <elb@pidgin.im>
parents: 6631
diff changeset
661 * @c FALSE. If @c NULL, false is assumed, and
080c98045e12 [gaim-migrate @ 8479]
Ethan Blanton <elb@pidgin.im>
parents: 6631
diff changeset
662 * it is not dereferenced.
080c98045e12 [gaim-migrate @ 8479]
Ethan Blanton <elb@pidgin.im>
parents: 6631
diff changeset
663 * @return The g_malloced string in the appropriate encoding.
080c98045e12 [gaim-migrate @ 8479]
Ethan Blanton <elb@pidgin.im>
parents: 6631
diff changeset
664 */
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
665 char *yahoo_string_encode(PurpleConnection *gc, const char *str, gboolean *utf8)
7827
080c98045e12 [gaim-migrate @ 8479]
Ethan Blanton <elb@pidgin.im>
parents: 6631
diff changeset
666 {
9164
46904c930b6e [gaim-migrate @ 9949]
Tim Ringenbach <marv@pidgin.im>
parents: 8955
diff changeset
667 struct yahoo_data *yd = gc->proto_data;
7827
080c98045e12 [gaim-migrate @ 8479]
Ethan Blanton <elb@pidgin.im>
parents: 6631
diff changeset
668 char *ret;
10504
eae130eefbfe [gaim-migrate @ 11796]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 10380
diff changeset
669 const char *to_codeset;
7827
080c98045e12 [gaim-migrate @ 8479]
Ethan Blanton <elb@pidgin.im>
parents: 6631
diff changeset
670
23173
c6dde2d2e30e applied changes from a5e7a62db1d43009f4ff463b7fe67ff3a7275a78
Daniel Atallah <datallah@pidgin.im>
parents: 22289
diff changeset
671 if (yd->jp)
c6dde2d2e30e applied changes from a5e7a62db1d43009f4ff463b7fe67ff3a7275a78
Daniel Atallah <datallah@pidgin.im>
parents: 22289
diff changeset
672 return g_strdup(str);
9164
46904c930b6e [gaim-migrate @ 9949]
Tim Ringenbach <marv@pidgin.im>
parents: 8955
diff changeset
673
7827
080c98045e12 [gaim-migrate @ 8479]
Ethan Blanton <elb@pidgin.im>
parents: 6631
diff changeset
674 if (utf8 && *utf8) /* FIXME: maybe don't use utf8 if it'll fit in latin1 */
080c98045e12 [gaim-migrate @ 8479]
Ethan Blanton <elb@pidgin.im>
parents: 6631
diff changeset
675 return g_strdup(str);
080c98045e12 [gaim-migrate @ 8479]
Ethan Blanton <elb@pidgin.im>
parents: 6631
diff changeset
676
23173
c6dde2d2e30e applied changes from a5e7a62db1d43009f4ff463b7fe67ff3a7275a78
Daniel Atallah <datallah@pidgin.im>
parents: 22289
diff changeset
677 to_codeset = purple_account_get_string(purple_connection_get_account(gc), "local_charset", "ISO-8859-1");
c6dde2d2e30e applied changes from a5e7a62db1d43009f4ff463b7fe67ff3a7275a78
Daniel Atallah <datallah@pidgin.im>
parents: 22289
diff changeset
678 ret = g_convert_with_fallback(str, -1, to_codeset, "UTF-8", "?", NULL, NULL, NULL);
7827
080c98045e12 [gaim-migrate @ 8479]
Ethan Blanton <elb@pidgin.im>
parents: 6631
diff changeset
679
080c98045e12 [gaim-migrate @ 8479]
Ethan Blanton <elb@pidgin.im>
parents: 6631
diff changeset
680 if (ret)
080c98045e12 [gaim-migrate @ 8479]
Ethan Blanton <elb@pidgin.im>
parents: 6631
diff changeset
681 return ret;
080c98045e12 [gaim-migrate @ 8479]
Ethan Blanton <elb@pidgin.im>
parents: 6631
diff changeset
682 else
080c98045e12 [gaim-migrate @ 8479]
Ethan Blanton <elb@pidgin.im>
parents: 6631
diff changeset
683 return g_strdup("");
080c98045e12 [gaim-migrate @ 8479]
Ethan Blanton <elb@pidgin.im>
parents: 6631
diff changeset
684 }
080c98045e12 [gaim-migrate @ 8479]
Ethan Blanton <elb@pidgin.im>
parents: 6631
diff changeset
685
080c98045e12 [gaim-migrate @ 8479]
Ethan Blanton <elb@pidgin.im>
parents: 6631
diff changeset
686 /**
080c98045e12 [gaim-migrate @ 8479]
Ethan Blanton <elb@pidgin.im>
parents: 6631
diff changeset
687 * Decode some text received from the server.
080c98045e12 [gaim-migrate @ 8479]
Ethan Blanton <elb@pidgin.im>
parents: 6631
diff changeset
688 *
080c98045e12 [gaim-migrate @ 8479]
Ethan Blanton <elb@pidgin.im>
parents: 6631
diff changeset
689 * @param gc The gc handle.
080c98045e12 [gaim-migrate @ 8479]
Ethan Blanton <elb@pidgin.im>
parents: 6631
diff changeset
690 * @param str The null terminated string to decode.
080c98045e12 [gaim-migrate @ 8479]
Ethan Blanton <elb@pidgin.im>
parents: 6631
diff changeset
691 * @param utf8 Did the server tell us it was supposed to be utf8?
080c98045e12 [gaim-migrate @ 8479]
Ethan Blanton <elb@pidgin.im>
parents: 6631
diff changeset
692 * @return The decoded, utf-8 string, which must be g_free()'d.
080c98045e12 [gaim-migrate @ 8479]
Ethan Blanton <elb@pidgin.im>
parents: 6631
diff changeset
693 */
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
694 char *yahoo_string_decode(PurpleConnection *gc, const char *str, gboolean utf8)
7827
080c98045e12 [gaim-migrate @ 8479]
Ethan Blanton <elb@pidgin.im>
parents: 6631
diff changeset
695 {
9164
46904c930b6e [gaim-migrate @ 9949]
Tim Ringenbach <marv@pidgin.im>
parents: 8955
diff changeset
696 struct yahoo_data *yd = gc->proto_data;
7827
080c98045e12 [gaim-migrate @ 8479]
Ethan Blanton <elb@pidgin.im>
parents: 6631
diff changeset
697 char *ret;
14347
4c0fe0512e73 [gaim-migrate @ 16971]
Tim Ringenbach <marv@pidgin.im>
parents: 14254
diff changeset
698 const char *from_codeset;
7827
080c98045e12 [gaim-migrate @ 8479]
Ethan Blanton <elb@pidgin.im>
parents: 6631
diff changeset
699
080c98045e12 [gaim-migrate @ 8479]
Ethan Blanton <elb@pidgin.im>
parents: 6631
diff changeset
700 if (utf8) {
080c98045e12 [gaim-migrate @ 8479]
Ethan Blanton <elb@pidgin.im>
parents: 6631
diff changeset
701 if (g_utf8_validate(str, -1, NULL))
080c98045e12 [gaim-migrate @ 8479]
Ethan Blanton <elb@pidgin.im>
parents: 6631
diff changeset
702 return g_strdup(str);
080c98045e12 [gaim-migrate @ 8479]
Ethan Blanton <elb@pidgin.im>
parents: 6631
diff changeset
703 }
080c98045e12 [gaim-migrate @ 8479]
Ethan Blanton <elb@pidgin.im>
parents: 6631
diff changeset
704
9164
46904c930b6e [gaim-migrate @ 9949]
Tim Ringenbach <marv@pidgin.im>
parents: 8955
diff changeset
705 if (yd->jp)
46904c930b6e [gaim-migrate @ 9949]
Tim Ringenbach <marv@pidgin.im>
parents: 8955
diff changeset
706 from_codeset = "SHIFT_JIS";
46904c930b6e [gaim-migrate @ 9949]
Tim Ringenbach <marv@pidgin.im>
parents: 8955
diff changeset
707 else
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
708 from_codeset = purple_account_get_string(purple_connection_get_account(gc), "local_charset", "ISO-8859-1");
7827
080c98045e12 [gaim-migrate @ 8479]
Ethan Blanton <elb@pidgin.im>
parents: 6631
diff changeset
709
19337
68471e68386a Use -1 as length with g_convert() functions instead of strlen()
Daniel Atallah <datallah@pidgin.im>
parents: 16169
diff changeset
710 ret = g_convert_with_fallback(str, -1, "UTF-8", from_codeset, NULL, NULL, NULL, NULL);
7827
080c98045e12 [gaim-migrate @ 8479]
Ethan Blanton <elb@pidgin.im>
parents: 6631
diff changeset
711
080c98045e12 [gaim-migrate @ 8479]
Ethan Blanton <elb@pidgin.im>
parents: 6631
diff changeset
712 if (ret)
080c98045e12 [gaim-migrate @ 8479]
Ethan Blanton <elb@pidgin.im>
parents: 6631
diff changeset
713 return ret;
080c98045e12 [gaim-migrate @ 8479]
Ethan Blanton <elb@pidgin.im>
parents: 6631
diff changeset
714 else
080c98045e12 [gaim-migrate @ 8479]
Ethan Blanton <elb@pidgin.im>
parents: 6631
diff changeset
715 return g_strdup("");
080c98045e12 [gaim-migrate @ 8479]
Ethan Blanton <elb@pidgin.im>
parents: 6631
diff changeset
716 }
080c98045e12 [gaim-migrate @ 8479]
Ethan Blanton <elb@pidgin.im>
parents: 6631
diff changeset
717
22259
bc9fcfd10196 disapproval of revision 'db9b3bc9d4427a6a03d1c25aac5215bf0f8e05ec'
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 22248
diff changeset
718 char *yahoo_convert_to_numeric(const char *str)
bc9fcfd10196 disapproval of revision 'db9b3bc9d4427a6a03d1c25aac5215bf0f8e05ec'
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 22248
diff changeset
719 {
22261
e80d3a79f3b8 Since I needed to bring back yahoo_convert_to_numeric, I figured I could at
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 22259
diff changeset
720 GString *gstr = NULL;
e80d3a79f3b8 Since I needed to bring back yahoo_convert_to_numeric, I figured I could at
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 22259
diff changeset
721 char *retstr;
22289
a1f40ee48fa8 Fix (hopefully) the last problem in this function. Refs #3295.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 22261
diff changeset
722 const unsigned char *p;
22259
bc9fcfd10196 disapproval of revision 'db9b3bc9d4427a6a03d1c25aac5215bf0f8e05ec'
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 22248
diff changeset
723
22261
e80d3a79f3b8 Since I needed to bring back yahoo_convert_to_numeric, I figured I could at
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 22259
diff changeset
724 gstr = g_string_sized_new(strlen(str) * 6 + 1);
e80d3a79f3b8 Since I needed to bring back yahoo_convert_to_numeric, I figured I could at
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 22259
diff changeset
725
22289
a1f40ee48fa8 Fix (hopefully) the last problem in this function. Refs #3295.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 22261
diff changeset
726 for (p = (unsigned char *)str; *p; p++) {
22261
e80d3a79f3b8 Since I needed to bring back yahoo_convert_to_numeric, I figured I could at
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 22259
diff changeset
727 g_string_append_printf(gstr, "&#%u;", *p);
22259
bc9fcfd10196 disapproval of revision 'db9b3bc9d4427a6a03d1c25aac5215bf0f8e05ec'
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 22248
diff changeset
728 }
22261
e80d3a79f3b8 Since I needed to bring back yahoo_convert_to_numeric, I figured I could at
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 22259
diff changeset
729
e80d3a79f3b8 Since I needed to bring back yahoo_convert_to_numeric, I figured I could at
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 22259
diff changeset
730 retstr = gstr->str;
e80d3a79f3b8 Since I needed to bring back yahoo_convert_to_numeric, I figured I could at
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 22259
diff changeset
731
e80d3a79f3b8 Since I needed to bring back yahoo_convert_to_numeric, I figured I could at
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 22259
diff changeset
732 g_string_free(gstr, FALSE);
e80d3a79f3b8 Since I needed to bring back yahoo_convert_to_numeric, I figured I could at
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 22259
diff changeset
733
22259
bc9fcfd10196 disapproval of revision 'db9b3bc9d4427a6a03d1c25aac5215bf0f8e05ec'
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 22248
diff changeset
734 return retstr;
bc9fcfd10196 disapproval of revision 'db9b3bc9d4427a6a03d1c25aac5215bf0f8e05ec'
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 22248
diff changeset
735 }
bc9fcfd10196 disapproval of revision 'db9b3bc9d4427a6a03d1c25aac5215bf0f8e05ec'
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 22248
diff changeset
736
6513
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
737 /*
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
738 * I found these on some website but i don't know that they actually
8735
01248ea222d3 [gaim-migrate @ 9490]
Jonathan Champ <royanee@users.sourceforge.net>
parents: 8533
diff changeset
739 * work (or are supposed to work). I didn't implement them yet.
6513
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
740 *
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
741 * [0;30m ---black
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
742 * [1;37m ---white
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
743 * [0;37m ---tan
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
744 * [0;38m ---light black
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
745 * [1;39m ---dark blue
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
746 * [0;32m ---green
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
747 * [0;33m ---yellow
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
748 * [0;35m ---pink
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
749 * [1;35m ---purple
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
750 * [1;30m ---light blue
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
751 * [0;31m ---red
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
752 * [0;34m ---blue
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
753 * [0;36m ---aqua
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
754 * (shift+comma)lyellow(shift+period) ---light yellow
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
755 * (shift+comma)lgreen(shift+period) ---light green
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
756 [2;30m <--white out
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
757 */
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
758
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
759 static GHashTable *ht = NULL;
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
760
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
761 void yahoo_init_colorht()
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
762 {
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
763 ht = g_hash_table_new(g_str_hash, g_str_equal);
6629
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
764 /* the numbers in comments are what gyach uses, but i think they're incorrect */
6513
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
765 g_hash_table_insert(ht, "30", "<FONT COLOR=\"#000000\">"); /* black */
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
766 g_hash_table_insert(ht, "31", "<FONT COLOR=\"#0000FF\">"); /* blue */
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
767 g_hash_table_insert(ht, "32", "<FONT COLOR=\"#008080\">"); /* cyan */ /* 00b2b2 */
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
768 g_hash_table_insert(ht, "33", "<FONT COLOR=\"#808080\">"); /* gray */ /* 808080 */
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
769 g_hash_table_insert(ht, "34", "<FONT COLOR=\"#008000\">"); /* green */ /* 00c200 */
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
770 g_hash_table_insert(ht, "35", "<FONT COLOR=\"#FF0080\">"); /* pink */ /* ffafaf */
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
771 g_hash_table_insert(ht, "36", "<FONT COLOR=\"#800080\">"); /* purple */ /* b200b2 */
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
772 g_hash_table_insert(ht, "37", "<FONT COLOR=\"#FF8000\">"); /* orange */ /* ffff00 */
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
773 g_hash_table_insert(ht, "38", "<FONT COLOR=\"#FF0000\">"); /* red */
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
774 g_hash_table_insert(ht, "39", "<FONT COLOR=\"#808000\">"); /* olive */ /* 546b50 */
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
775
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
776 g_hash_table_insert(ht, "1", "<B>");
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
777 g_hash_table_insert(ht, "x1", "</B>");
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
778 g_hash_table_insert(ht, "2", "<I>");
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
779 g_hash_table_insert(ht, "x2", "</I>");
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
780 g_hash_table_insert(ht, "4", "<U>");
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
781 g_hash_table_insert(ht, "x4", "</U>");
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
782
6629
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
783 /* these just tell us the text they surround is supposed
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
784 * to be a link. purple figures that out on its own so we
6629
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
785 * just ignore it.
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
786 */
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
787 g_hash_table_insert(ht, "l", ""); /* link start */
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
788 g_hash_table_insert(ht, "xl", ""); /* link end */
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
789
6513
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
790 g_hash_table_insert(ht, "<black>", "<FONT COLOR=\"#000000\">");
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
791 g_hash_table_insert(ht, "<blue>", "<FONT COLOR=\"#0000FF\">");
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
792 g_hash_table_insert(ht, "<cyan>", "<FONT COLOR=\"#008284\">");
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
793 g_hash_table_insert(ht, "<gray>", "<FONT COLOR=\"#848284\">");
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
794 g_hash_table_insert(ht, "<green>", "<FONT COLOR=\"#008200\">");
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
795 g_hash_table_insert(ht, "<pink>", "<FONT COLOR=\"#FF0084\">");
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
796 g_hash_table_insert(ht, "<purple>", "<FONT COLOR=\"#840084\">");
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
797 g_hash_table_insert(ht, "<orange>", "<FONT COLOR=\"#FF8000\">");
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
798 g_hash_table_insert(ht, "<red>", "<FONT COLOR=\"#FF0000\">");
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
799 g_hash_table_insert(ht, "<yellow>", "<FONT COLOR=\"#848200\">");
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
800
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
801 g_hash_table_insert(ht, "</black>", "</FONT>");
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
802 g_hash_table_insert(ht, "</blue>", "</FONT>");
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
803 g_hash_table_insert(ht, "</cyan>", "</FONT>");
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
804 g_hash_table_insert(ht, "</gray>", "</FONT>");
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
805 g_hash_table_insert(ht, "</green>", "</FONT>");
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
806 g_hash_table_insert(ht, "</pink>", "</FONT>");
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
807 g_hash_table_insert(ht, "</purple>", "</FONT>");
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
808 g_hash_table_insert(ht, "</orange>", "</FONT>");
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
809 g_hash_table_insert(ht, "</red>", "</FONT>");
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
810 g_hash_table_insert(ht, "</yellow>", "</FONT>");
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
811
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
812 /* remove these once we have proper support for <FADE> and <ALT> */
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
813 g_hash_table_insert(ht, "</fade>", "");
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
814 g_hash_table_insert(ht, "</alt>", "");
8375
13448d864067 [gaim-migrate @ 9102]
Tim Ringenbach <marv@pidgin.im>
parents: 7827
diff changeset
815
13448d864067 [gaim-migrate @ 9102]
Tim Ringenbach <marv@pidgin.im>
parents: 7827
diff changeset
816 /* these are the normal html yahoo sends (besides <font>).
13448d864067 [gaim-migrate @ 9102]
Tim Ringenbach <marv@pidgin.im>
parents: 7827
diff changeset
817 * anything else will get turned into &lt;tag&gt;, so if I forgot
13448d864067 [gaim-migrate @ 9102]
Tim Ringenbach <marv@pidgin.im>
parents: 7827
diff changeset
818 * about something, please add it. Why Yahoo! has to send unescaped
13448d864067 [gaim-migrate @ 9102]
Tim Ringenbach <marv@pidgin.im>
parents: 7827
diff changeset
819 * <'s and >'s that aren't supposed to be html is beyond me.
13448d864067 [gaim-migrate @ 9102]
Tim Ringenbach <marv@pidgin.im>
parents: 7827
diff changeset
820 */
13448d864067 [gaim-migrate @ 9102]
Tim Ringenbach <marv@pidgin.im>
parents: 7827
diff changeset
821 g_hash_table_insert(ht, "<b>", "<b>");
13448d864067 [gaim-migrate @ 9102]
Tim Ringenbach <marv@pidgin.im>
parents: 7827
diff changeset
822 g_hash_table_insert(ht, "<i>", "<i>");
13448d864067 [gaim-migrate @ 9102]
Tim Ringenbach <marv@pidgin.im>
parents: 7827
diff changeset
823 g_hash_table_insert(ht, "<u>", "<u>");
13448d864067 [gaim-migrate @ 9102]
Tim Ringenbach <marv@pidgin.im>
parents: 7827
diff changeset
824
13448d864067 [gaim-migrate @ 9102]
Tim Ringenbach <marv@pidgin.im>
parents: 7827
diff changeset
825 g_hash_table_insert(ht, "</b>", "</b>");
13448d864067 [gaim-migrate @ 9102]
Tim Ringenbach <marv@pidgin.im>
parents: 7827
diff changeset
826 g_hash_table_insert(ht, "</i>", "</i>");
13448d864067 [gaim-migrate @ 9102]
Tim Ringenbach <marv@pidgin.im>
parents: 7827
diff changeset
827 g_hash_table_insert(ht, "</u>", "</u>");
8440
b3cc68914150 [gaim-migrate @ 9170]
Tim Ringenbach <marv@pidgin.im>
parents: 8376
diff changeset
828 g_hash_table_insert(ht, "</font>", "</font>");
6513
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
829 }
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
830
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
831 void yahoo_dest_colorht()
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
832 {
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
833 g_hash_table_destroy(ht);
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
834 }
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
835
6629
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
836 static int point_to_html(int x)
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
837 {
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
838 if (x < 9)
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
839 return 1;
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
840 if (x < 11)
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
841 return 2;
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
842 if (x < 13)
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
843 return 3;
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
844 if (x < 17)
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
845 return 4;
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
846 if (x < 25)
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
847 return 5;
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
848 if (x < 35)
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
849 return 6;
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
850 return 7;
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
851 }
10380
8608e553808f [gaim-migrate @ 11605]
Evan Schoenberg <evands@pidgin.im>
parents: 10023
diff changeset
852
8608e553808f [gaim-migrate @ 11605]
Evan Schoenberg <evands@pidgin.im>
parents: 10023
diff changeset
853 /* The Yahoo size tag is actually an absz tag; convert it to an HTML size, and include both tags */
6629
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
854 static void _font_tags_fix_size(GString *tag, GString *dest)
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
855 {
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
856 char *x, *end;
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
857 int size;
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
858
13710
c8376b63ca31 [gaim-migrate @ 16112]
Richard Laager <rlaager@pidgin.im>
parents: 11644
diff changeset
859 if (((x = strstr(tag->str, "size"))) && ((x = strchr(x, '=')))) {
6629
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
860 while (*x && !g_ascii_isdigit(*x))
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
861 x++;
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
862 if (*x) {
10380
8608e553808f [gaim-migrate @ 11605]
Evan Schoenberg <evands@pidgin.im>
parents: 10023
diff changeset
863 int htmlsize;
8608e553808f [gaim-migrate @ 11605]
Evan Schoenberg <evands@pidgin.im>
parents: 10023
diff changeset
864
6629
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
865 size = strtol(x, &end, 10);
10380
8608e553808f [gaim-migrate @ 11605]
Evan Schoenberg <evands@pidgin.im>
parents: 10023
diff changeset
866 htmlsize = point_to_html(size);
6629
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
867 g_string_append_len(dest, tag->str, x - tag->str);
10380
8608e553808f [gaim-migrate @ 11605]
Evan Schoenberg <evands@pidgin.im>
parents: 10023
diff changeset
868 g_string_append_printf(dest, "%d", htmlsize);
8608e553808f [gaim-migrate @ 11605]
Evan Schoenberg <evands@pidgin.im>
parents: 10023
diff changeset
869 g_string_append_printf(dest, "\" absz=\"%d", size);
6629
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
870 g_string_append(dest, end);
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
871 } else {
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
872 g_string_append(dest, tag->str);
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
873 return;
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
874 }
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
875 } else {
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
876 g_string_append(dest, tag->str);
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
877 return;
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
878 }
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
879 }
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
880
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
881 char *yahoo_codes_to_html(const char *x)
6513
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
882 {
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
883 GString *s, *tmp;
6629
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
884 int i, j, xs, nomoreendtags = 0; /* s/endtags/closinganglebrackets */
6513
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
885 char *match, *ret;
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
886
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
887 s = g_string_sized_new(strlen(x));
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
888
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
889 for (i = 0, xs = strlen(x); i < xs; i++) {
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
890 if ((x[i] == 0x1b) && (x[i+1] == '[')) {
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
891 j = i + 1;
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
892
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
893 while (j++ < xs) {
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
894 if (x[j] != 'm')
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
895 continue;
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
896 else {
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
897 tmp = g_string_new_len(x + i + 2, j - i - 2);
6621
2a18ef3e5224 [gaim-migrate @ 7145]
Robert McQueen <robot101@debian.org>
parents: 6546
diff changeset
898 if (tmp->str[0] == '#')
6513
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
899 g_string_append_printf(s, "<FONT COLOR=\"%s\">", tmp->str);
6546
6a14dfe43d5c [gaim-migrate @ 7068]
Mark Doliner <markdoliner@pidgin.im>
parents: 6513
diff changeset
900 else if ((match = (char *) g_hash_table_lookup(ht, tmp->str)))
6513
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
901 g_string_append(s, match);
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
902 else {
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
903 purple_debug(PURPLE_DEBUG_ERROR, "yahoo",
6513
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
904 "Unknown ansi code 'ESC[%sm'.\n", tmp->str);
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
905 g_string_free(tmp, TRUE);
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
906 break;
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
907 }
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
908
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
909 i = j;
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
910 g_string_free(tmp, TRUE);
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
911 break;
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
912 }
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
913 }
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
914
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
915 } else if (!nomoreendtags && (x[i] == '<')) {
6629
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
916 j = i;
6513
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
917
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
918 while (j++ < xs) {
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
919 if (x[j] != '>')
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
920 if (j == xs) {
8375
13448d864067 [gaim-migrate @ 9102]
Tim Ringenbach <marv@pidgin.im>
parents: 7827
diff changeset
921 g_string_append(s, "&lt;");
6513
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
922 nomoreendtags = 1;
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
923 }
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
924 else
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
925 continue;
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
926 else {
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
927 tmp = g_string_new_len(x + i, j - i + 1);
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
928 g_string_ascii_down(tmp);
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
929
6546
6a14dfe43d5c [gaim-migrate @ 7068]
Mark Doliner <markdoliner@pidgin.im>
parents: 6513
diff changeset
930 if ((match = (char *) g_hash_table_lookup(ht, tmp->str)))
6513
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
931 g_string_append(s, match);
6629
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
932 else if (!strncmp(tmp->str, "<fade ", 6) ||
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
933 !strncmp(tmp->str, "<alt ", 5) ||
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
934 !strncmp(tmp->str, "<snd ", 5)) {
6513
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
935
6629
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
936 /* remove this if gtkimhtml ever supports any of these */
6513
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
937 i = j;
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
938 g_string_free(tmp, TRUE);
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
939 break;
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
940
6629
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
941 } else if (!strncmp(tmp->str, "<font ", 6)) {
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
942 _font_tags_fix_size(tmp, s);
6513
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
943 } else {
8375
13448d864067 [gaim-migrate @ 9102]
Tim Ringenbach <marv@pidgin.im>
parents: 7827
diff changeset
944 g_string_append(s, "&lt;");
6513
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
945 g_string_free(tmp, TRUE);
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
946 break;
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
947 }
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
948
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
949 i = j;
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
950 g_string_free(tmp, TRUE);
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
951 break;
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
952 }
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
953
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
954 }
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
955
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
956 } else {
8375
13448d864067 [gaim-migrate @ 9102]
Tim Ringenbach <marv@pidgin.im>
parents: 7827
diff changeset
957 if (x[i] == '<')
13448d864067 [gaim-migrate @ 9102]
Tim Ringenbach <marv@pidgin.im>
parents: 7827
diff changeset
958 g_string_append(s, "&lt;");
13448d864067 [gaim-migrate @ 9102]
Tim Ringenbach <marv@pidgin.im>
parents: 7827
diff changeset
959 else if (x[i] == '>')
13448d864067 [gaim-migrate @ 9102]
Tim Ringenbach <marv@pidgin.im>
parents: 7827
diff changeset
960 g_string_append(s, "&gt;");
8440
b3cc68914150 [gaim-migrate @ 9170]
Tim Ringenbach <marv@pidgin.im>
parents: 8376
diff changeset
961 else if (x[i] == '&')
b3cc68914150 [gaim-migrate @ 9170]
Tim Ringenbach <marv@pidgin.im>
parents: 8376
diff changeset
962 g_string_append(s, "&amp;");
b3cc68914150 [gaim-migrate @ 9170]
Tim Ringenbach <marv@pidgin.im>
parents: 8376
diff changeset
963 else if (x[i] == '"')
b3cc68914150 [gaim-migrate @ 9170]
Tim Ringenbach <marv@pidgin.im>
parents: 8376
diff changeset
964 g_string_append(s, "&quot;");
8375
13448d864067 [gaim-migrate @ 9102]
Tim Ringenbach <marv@pidgin.im>
parents: 7827
diff changeset
965 else
13448d864067 [gaim-migrate @ 9102]
Tim Ringenbach <marv@pidgin.im>
parents: 7827
diff changeset
966 g_string_append_c(s, x[i]);
6513
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
967 }
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
968 }
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
969
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
970 ret = s->str;
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
971 g_string_free(s, FALSE);
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
972 purple_debug(PURPLE_DEBUG_MISC, "yahoo", "yahoo_codes_to_html: Returning string: '%s'.\n", ret);
6513
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
973 return ret;
191231aceb3f [gaim-migrate @ 7030]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
974 }
6629
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
975
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
976 /* borrowed from gtkimhtml */
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
977 #define MAX_FONT_SIZE 7
10899
87d9aec5b72d [gaim-migrate @ 12619]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 10504
diff changeset
978 #define POINT_SIZE(x) (_point_sizes [MIN ((x > 0 ? x : 1), MAX_FONT_SIZE) - 1])
14904
cab89db4854c [gaim-migrate @ 17611]
Henning Norén <henning.noren@gmail.com>
parents: 14347
diff changeset
979 static const gint _point_sizes [] = { 8, 10, 12, 14, 20, 30, 40 };
6629
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
980
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
981 enum fatype { size, color, face, junk };
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
982 typedef struct {
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
983 enum fatype type;
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
984 union {
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
985 int size;
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
986 char *color;
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
987 char *face;
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
988 char *junk;
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
989 } u;
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
990 } fontattr;
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
991
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
992 static void fontattr_free(fontattr *f)
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
993 {
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
994 if (f->type == color)
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
995 g_free(f->u.color);
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
996 else if (f->type == face)
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
997 g_free(f->u.face);
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
998 g_free(f);
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
999 }
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1000
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1001 static void yahoo_htc_queue_cleanup(GQueue *q)
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1002 {
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1003 char *tmp;
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1004
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1005 while ((tmp = g_queue_pop_tail(q)))
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1006 g_free(tmp);
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1007 g_queue_free(q);
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1008 }
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1009
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1010 static void _parse_font_tag(const char *src, GString *dest, int *i, int *j,
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1011 int len, GQueue *colors, GQueue *tags, GQueue *ftattr)
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1012 {
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1013
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1014 int m, n, vstart;
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1015 gboolean quote = 0, done = 0;
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1016
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1017 m = *j;
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1018
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1019 while (1) {
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1020 m++;
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1021
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1022 if (m >= len) {
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1023 g_string_append(dest, &src[*i]);
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1024 *i = len;
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1025 break;
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1026 }
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1027
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1028 if (src[m] == '=') {
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1029 n = vstart = m;
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1030 while (1) {
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1031 n++;
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1032
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1033 if (n >= len) {
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1034 m = n;
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1035 break;
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1036 }
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1037
6631
a2608d595a32 [gaim-migrate @ 7155]
Björn Voigt <bjoern@cs.tu-berlin.de>
parents: 6629
diff changeset
1038 if (src[n] == '"') {
6629
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1039 if (!quote) {
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1040 quote = 1;
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1041 vstart = n;
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1042 continue;
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1043 } else {
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1044 done = 1;
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1045 }
6631
a2608d595a32 [gaim-migrate @ 7155]
Björn Voigt <bjoern@cs.tu-berlin.de>
parents: 6629
diff changeset
1046 }
6629
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1047
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1048 if (!quote && ((src[n] == ' ') || (src[n] == '>')))
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1049 done = 1;
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1050
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1051 if (done) {
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1052 if (!g_ascii_strncasecmp(&src[*j+1], "FACE", m - *j - 1)) {
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1053 fontattr *f;
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1054
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1055 f = g_new(fontattr, 1);
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1056 f->type = face;
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1057 f->u.face = g_strndup(&src[vstart+1], n-vstart-1);
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1058 if (!ftattr)
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1059 ftattr = g_queue_new();
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1060 g_queue_push_tail(ftattr, f);
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1061 m = n;
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1062 break;
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1063 } else if (!g_ascii_strncasecmp(&src[*j+1], "SIZE", m - *j - 1)) {
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1064 fontattr *f;
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1065
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1066 f = g_new(fontattr, 1);
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1067 f->type = size;
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1068 f->u.size = POINT_SIZE(strtol(&src[vstart+1], NULL, 10));
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1069 if (!ftattr)
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1070 ftattr = g_queue_new();
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1071 g_queue_push_tail(ftattr, f);
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1072 m = n;
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1073 break;
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1074 } else if (!g_ascii_strncasecmp(&src[*j+1], "COLOR", m - *j - 1)) {
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1075 fontattr *f;
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1076
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1077 f = g_new(fontattr, 1);
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1078 f->type = color;
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1079 f->u.color = g_strndup(&src[vstart+1], n-vstart-1);
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1080 if (!ftattr)
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1081 ftattr = g_queue_new();
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1082 g_queue_push_head(ftattr, f);
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1083 m = n;
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1084 break;
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1085 } else {
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1086 fontattr *f;
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1087
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1088 f = g_new(fontattr, 1);
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1089 f->type = junk;
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1090 f->u.junk = g_strndup(&src[*j+1], n-*j);
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1091 if (!ftattr)
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1092 ftattr = g_queue_new();
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1093 g_queue_push_tail(ftattr, f);
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1094 m = n;
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1095 break;
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1096 }
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1097
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1098 }
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1099 }
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1100 }
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1101
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1102 if (src[m] == ' ')
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1103 *j = m;
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1104
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1105 if (src[m] == '>') {
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1106 gboolean needendtag = 0;
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1107 fontattr *f;
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1108 GString *tmp = g_string_new(NULL);
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1109 char *colorstr;
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1110
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1111 if (!g_queue_is_empty(ftattr)) {
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1112 while ((f = g_queue_pop_tail(ftattr))) {
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1113 switch (f->type) {
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1114 case size:
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1115 if (!needendtag) {
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1116 needendtag = 1;
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1117 g_string_append(dest, "<font ");
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1118 }
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1119
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1120 g_string_append_printf(dest, "size=\"%d\" ", f->u.size);
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1121 fontattr_free(f);
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1122 break;
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1123 case face:
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1124 if (!needendtag) {
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1125 needendtag = 1;
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1126 g_string_append(dest, "<font ");
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1127 }
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1128
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1129 g_string_append_printf(dest, "face=\"%s\" ", f->u.face);
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1130 fontattr_free(f);
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1131 break;
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1132 case junk:
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1133 if (!needendtag) {
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1134 needendtag = 1;
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1135 g_string_append(dest, "<font ");
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1136 }
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1137
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1138 g_string_append(dest, f->u.junk);
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1139 fontattr_free(f);
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1140 break;
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1141
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1142 case color:
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1143 if (needendtag) {
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1144 g_string_append(tmp, "</font>");
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1145 dest->str[dest->len-1] = '>';
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1146 needendtag = 0;
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1147 }
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1148
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1149 colorstr = g_queue_peek_tail(colors);
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1150 g_string_append(tmp, colorstr ? colorstr : "\033[#000000m");
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1151 g_string_append_printf(dest, "\033[%sm", f->u.color);
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1152 g_queue_push_tail(colors, g_strdup_printf("\033[%sm", f->u.color));
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1153 fontattr_free(f);
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1154 break;
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1155 }
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1156 }
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1157
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1158 g_queue_free(ftattr);
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1159 ftattr = NULL;
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1160
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1161 if (needendtag) {
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1162 dest->str[dest->len-1] = '>';
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1163 g_queue_push_tail(tags, g_strdup("</font>"));
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1164 g_string_free(tmp, TRUE);
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1165 } else {
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1166 g_queue_push_tail(tags, tmp->str);
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1167 g_string_free(tmp, FALSE);
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1168 }
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1169 }
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1170
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1171 *i = *j = m;
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1172 break;
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1173 }
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1174 }
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1175
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1176 }
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1177
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1178 char *yahoo_html_to_codes(const char *src)
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1179 {
6631
a2608d595a32 [gaim-migrate @ 7155]
Björn Voigt <bjoern@cs.tu-berlin.de>
parents: 6629
diff changeset
1180 int i, j, len;
6629
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1181 GString *dest;
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1182 char *ret, *esc;
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1183 GQueue *colors, *tags;
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1184 GQueue *ftattr = NULL;
8440
b3cc68914150 [gaim-migrate @ 9170]
Tim Ringenbach <marv@pidgin.im>
parents: 8376
diff changeset
1185 gboolean no_more_specials = FALSE;
6629
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1186
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1187 colors = g_queue_new();
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1188 tags = g_queue_new();
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1189 dest = g_string_sized_new(strlen(src));
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1190
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1191 for (i = 0, len = strlen(src); i < len; i++) {
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1192
8440
b3cc68914150 [gaim-migrate @ 9170]
Tim Ringenbach <marv@pidgin.im>
parents: 8376
diff changeset
1193 if (!no_more_specials && src[i] == '<') {
6629
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1194 j = i;
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1195
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1196 while (1) {
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1197 j++;
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1198
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1199 if (j >= len) { /* no '>' */
8440
b3cc68914150 [gaim-migrate @ 9170]
Tim Ringenbach <marv@pidgin.im>
parents: 8376
diff changeset
1200 g_string_append_c(dest, src[i]);
b3cc68914150 [gaim-migrate @ 9170]
Tim Ringenbach <marv@pidgin.im>
parents: 8376
diff changeset
1201 no_more_specials = TRUE;
6629
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1202 break;
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1203 }
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1204
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1205 if (src[j] == '<') {
8440
b3cc68914150 [gaim-migrate @ 9170]
Tim Ringenbach <marv@pidgin.im>
parents: 8376
diff changeset
1206 /* FIXME: This doesn't convert outgoing entities.
b3cc68914150 [gaim-migrate @ 9170]
Tim Ringenbach <marv@pidgin.im>
parents: 8376
diff changeset
1207 * However, I suspect this case may never
b3cc68914150 [gaim-migrate @ 9170]
Tim Ringenbach <marv@pidgin.im>
parents: 8376
diff changeset
1208 * happen anymore because of the entities.
b3cc68914150 [gaim-migrate @ 9170]
Tim Ringenbach <marv@pidgin.im>
parents: 8376
diff changeset
1209 */
6629
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1210 g_string_append_len(dest, &src[i], j - i);
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1211 i = j - 1;
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1212 if (ftattr) {
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1213 fontattr *f;
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1214
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1215 while ((f = g_queue_pop_head(ftattr)))
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1216 fontattr_free(f);
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1217 g_queue_free(ftattr);
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1218 ftattr = NULL;
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1219 }
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1220 break;
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1221 }
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1222
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1223 if (src[j] == ' ') {
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1224 if (!g_ascii_strncasecmp(&src[i+1], "BODY", j - i - 1)) {
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1225 char *t = strchr(&src[j], '>');
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1226 if (!t) {
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1227 g_string_append(dest, &src[i]);
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1228 i = len;
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1229 break;
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1230 } else {
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1231 i = t - src;
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1232 break;
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1233 }
8533
a5016f9d104a [gaim-migrate @ 9272]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 8480
diff changeset
1234 } else if (!g_ascii_strncasecmp(&src[i+1], "A HREF=\"", j - i - 1)) {
a5016f9d104a [gaim-migrate @ 9272]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 8480
diff changeset
1235 j += 7;
a5016f9d104a [gaim-migrate @ 9272]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 8480
diff changeset
1236 g_string_append(dest, "\033[lm");
a5016f9d104a [gaim-migrate @ 9272]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 8480
diff changeset
1237 while (1) {
a5016f9d104a [gaim-migrate @ 9272]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 8480
diff changeset
1238 g_string_append_c(dest, src[j]);
a5016f9d104a [gaim-migrate @ 9272]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 8480
diff changeset
1239 if (++j >= len) {
8480
e1c32e741f2d [gaim-migrate @ 9213]
Kevin Stange <kstange@pidgin.im>
parents: 8455
diff changeset
1240 i = len;
e1c32e741f2d [gaim-migrate @ 9213]
Kevin Stange <kstange@pidgin.im>
parents: 8455
diff changeset
1241 break;
e1c32e741f2d [gaim-migrate @ 9213]
Kevin Stange <kstange@pidgin.im>
parents: 8455
diff changeset
1242 }
8533
a5016f9d104a [gaim-migrate @ 9272]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 8480
diff changeset
1243 if (src[j] == '"') {
a5016f9d104a [gaim-migrate @ 9272]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 8480
diff changeset
1244 g_string_append(dest, "\033[xlm");
a5016f9d104a [gaim-migrate @ 9272]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 8480
diff changeset
1245 while (1) {
a5016f9d104a [gaim-migrate @ 9272]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 8480
diff changeset
1246 if (++j >= len) {
a5016f9d104a [gaim-migrate @ 9272]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 8480
diff changeset
1247 i = len;
a5016f9d104a [gaim-migrate @ 9272]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 8480
diff changeset
1248 break;
a5016f9d104a [gaim-migrate @ 9272]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 8480
diff changeset
1249 }
a5016f9d104a [gaim-migrate @ 9272]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 8480
diff changeset
1250 if (!g_ascii_strncasecmp(&src[j], "</A>", 4)) {
a5016f9d104a [gaim-migrate @ 9272]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 8480
diff changeset
1251 j += 3;
a5016f9d104a [gaim-migrate @ 9272]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 8480
diff changeset
1252 break;
a5016f9d104a [gaim-migrate @ 9272]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 8480
diff changeset
1253 }
a5016f9d104a [gaim-migrate @ 9272]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 8480
diff changeset
1254 }
a5016f9d104a [gaim-migrate @ 9272]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 8480
diff changeset
1255 i = j;
8480
e1c32e741f2d [gaim-migrate @ 9213]
Kevin Stange <kstange@pidgin.im>
parents: 8455
diff changeset
1256 break;
e1c32e741f2d [gaim-migrate @ 9213]
Kevin Stange <kstange@pidgin.im>
parents: 8455
diff changeset
1257 }
e1c32e741f2d [gaim-migrate @ 9213]
Kevin Stange <kstange@pidgin.im>
parents: 8455
diff changeset
1258 }
16169
4aa4ec9afa9c Stop Yahoo sending SPAN tags, fixes Yahoo part of ticket 78
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 15884
diff changeset
1259 } else if (!g_ascii_strncasecmp(&src[i+1], "SPAN", j - i - 1)) { /* drop span tags */
4aa4ec9afa9c Stop Yahoo sending SPAN tags, fixes Yahoo part of ticket 78
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 15884
diff changeset
1260 while (1) {
4aa4ec9afa9c Stop Yahoo sending SPAN tags, fixes Yahoo part of ticket 78
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 15884
diff changeset
1261 if (++j >= len) {
4aa4ec9afa9c Stop Yahoo sending SPAN tags, fixes Yahoo part of ticket 78
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 15884
diff changeset
1262 g_string_append(dest, &src[i]);
4aa4ec9afa9c Stop Yahoo sending SPAN tags, fixes Yahoo part of ticket 78
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 15884
diff changeset
1263 i = len;
4aa4ec9afa9c Stop Yahoo sending SPAN tags, fixes Yahoo part of ticket 78
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 15884
diff changeset
1264 break;
4aa4ec9afa9c Stop Yahoo sending SPAN tags, fixes Yahoo part of ticket 78
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 15884
diff changeset
1265 }
4aa4ec9afa9c Stop Yahoo sending SPAN tags, fixes Yahoo part of ticket 78
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 15884
diff changeset
1266 if (src[j] == '>') {
4aa4ec9afa9c Stop Yahoo sending SPAN tags, fixes Yahoo part of ticket 78
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 15884
diff changeset
1267 i = j;
4aa4ec9afa9c Stop Yahoo sending SPAN tags, fixes Yahoo part of ticket 78
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 15884
diff changeset
1268 break;
4aa4ec9afa9c Stop Yahoo sending SPAN tags, fixes Yahoo part of ticket 78
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 15884
diff changeset
1269 }
4aa4ec9afa9c Stop Yahoo sending SPAN tags, fixes Yahoo part of ticket 78
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 15884
diff changeset
1270 }
6629
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1271 } else if (g_ascii_strncasecmp(&src[i+1], "FONT", j - i - 1)) { /* not interested! */
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1272 while (1) {
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1273 if (++j >= len) {
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1274 g_string_append(dest, &src[i]);
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1275 i = len;
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1276 break;
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1277 }
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1278 if (src[j] == '>') {
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1279 g_string_append_len(dest, &src[i], j - i + 1);
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1280 i = j;
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1281 break;
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1282 }
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1283 }
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1284 } else { /* yay we have a font tag */
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1285 _parse_font_tag(src, dest, &i, &j, len, colors, tags, ftattr);
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1286 }
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1287
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1288 break;
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1289 }
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1290
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1291 if (src[j] == '>') {
8440
b3cc68914150 [gaim-migrate @ 9170]
Tim Ringenbach <marv@pidgin.im>
parents: 8376
diff changeset
1292 /* This has some problems like the FIXME for the
b3cc68914150 [gaim-migrate @ 9170]
Tim Ringenbach <marv@pidgin.im>
parents: 8376
diff changeset
1293 * '<' case. and like that case, I suspect the case
b3cc68914150 [gaim-migrate @ 9170]
Tim Ringenbach <marv@pidgin.im>
parents: 8376
diff changeset
1294 * that this has problems is won't happen anymore anyway.
b3cc68914150 [gaim-migrate @ 9170]
Tim Ringenbach <marv@pidgin.im>
parents: 8376
diff changeset
1295 */
6629
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1296 int sublen = j - i - 1;
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1297
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1298 if (sublen) {
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1299 if (!g_ascii_strncasecmp(&src[i+1], "B", sublen)) {
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1300 g_string_append(dest, "\033[1m");
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1301 } else if (!g_ascii_strncasecmp(&src[i+1], "/B", sublen)) {
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1302 g_string_append(dest, "\033[x1m");
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1303 } else if (!g_ascii_strncasecmp(&src[i+1], "I", sublen)) {
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1304 g_string_append(dest, "\033[2m");
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1305 } else if (!g_ascii_strncasecmp(&src[i+1], "/I", sublen)) {
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1306 g_string_append(dest, "\033[x2m");
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1307 } else if (!g_ascii_strncasecmp(&src[i+1], "U", sublen)) {
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1308 g_string_append(dest, "\033[4m");
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1309 } else if (!g_ascii_strncasecmp(&src[i+1], "/U", sublen)) {
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1310 g_string_append(dest, "\033[x4m");
8480
e1c32e741f2d [gaim-migrate @ 9213]
Kevin Stange <kstange@pidgin.im>
parents: 8455
diff changeset
1311 } else if (!g_ascii_strncasecmp(&src[i+1], "/A", sublen)) {
e1c32e741f2d [gaim-migrate @ 9213]
Kevin Stange <kstange@pidgin.im>
parents: 8455
diff changeset
1312 g_string_append(dest, "\033[xlm");
8455
dd43a455556c [gaim-migrate @ 9185]
Tim Ringenbach <marv@pidgin.im>
parents: 8440
diff changeset
1313 } else if (!g_ascii_strncasecmp(&src[i+1], "BR", sublen)) {
dd43a455556c [gaim-migrate @ 9185]
Tim Ringenbach <marv@pidgin.im>
parents: 8440
diff changeset
1314 g_string_append_c(dest, '\n');
6629
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1315 } else if (!g_ascii_strncasecmp(&src[i+1], "/BODY", sublen)) {
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1316 /* mmm, </body> tags. *BURP* */
16169
4aa4ec9afa9c Stop Yahoo sending SPAN tags, fixes Yahoo part of ticket 78
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 15884
diff changeset
1317 } else if (!g_ascii_strncasecmp(&src[i+1], "/SPAN", sublen)) {
4aa4ec9afa9c Stop Yahoo sending SPAN tags, fixes Yahoo part of ticket 78
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 15884
diff changeset
1318 /* </span> tags. dangerously close to </spam> */
6629
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1319 } else if (!g_ascii_strncasecmp(&src[i+1], "/FONT", sublen) && g_queue_peek_tail(tags)) {
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1320 char *etag, *cl;
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1321
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1322 etag = g_queue_pop_tail(tags);
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1323 if (etag) {
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1324 g_string_append(dest, etag);
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1325 if (!strcmp(etag, "</font>")) {
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1326 cl = g_queue_pop_tail(colors);
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1327 if (cl)
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1328 g_free(cl);
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1329 }
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1330 g_free(etag);
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1331 }
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1332 } else {
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1333 g_string_append_len(dest, &src[i], j - i + 1);
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1334 }
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1335 } else {
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1336 g_string_append_len(dest, &src[i], j - i + 1);
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1337 }
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1338
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1339 i = j;
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1340 break;
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1341 }
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1342
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1343 }
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1344
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1345 } else {
8440
b3cc68914150 [gaim-migrate @ 9170]
Tim Ringenbach <marv@pidgin.im>
parents: 8376
diff changeset
1346 if (((len - i) >= 4) && !strncmp(&src[i], "&lt;", 4)) {
b3cc68914150 [gaim-migrate @ 9170]
Tim Ringenbach <marv@pidgin.im>
parents: 8376
diff changeset
1347 g_string_append_c(dest, '<');
b3cc68914150 [gaim-migrate @ 9170]
Tim Ringenbach <marv@pidgin.im>
parents: 8376
diff changeset
1348 i += 3;
b3cc68914150 [gaim-migrate @ 9170]
Tim Ringenbach <marv@pidgin.im>
parents: 8376
diff changeset
1349 } else if (((len - i) >= 4) && !strncmp(&src[i], "&gt;", 4)) {
b3cc68914150 [gaim-migrate @ 9170]
Tim Ringenbach <marv@pidgin.im>
parents: 8376
diff changeset
1350 g_string_append_c(dest, '>');
b3cc68914150 [gaim-migrate @ 9170]
Tim Ringenbach <marv@pidgin.im>
parents: 8376
diff changeset
1351 i += 3;
21946
f444fc9e2d18 Make yahoo_html_to_codes deal with &apos; in messages being sent. Also correct
Will Thompson <resiak@pidgin.im>
parents: 19859
diff changeset
1352 } else if (((len - i) >= 5) && !strncmp(&src[i], "&amp;", 5)) {
8440
b3cc68914150 [gaim-migrate @ 9170]
Tim Ringenbach <marv@pidgin.im>
parents: 8376
diff changeset
1353 g_string_append_c(dest, '&');
b3cc68914150 [gaim-migrate @ 9170]
Tim Ringenbach <marv@pidgin.im>
parents: 8376
diff changeset
1354 i += 4;
21946
f444fc9e2d18 Make yahoo_html_to_codes deal with &apos; in messages being sent. Also correct
Will Thompson <resiak@pidgin.im>
parents: 19859
diff changeset
1355 } else if (((len - i) >= 6) && !strncmp(&src[i], "&quot;", 6)) {
8440
b3cc68914150 [gaim-migrate @ 9170]
Tim Ringenbach <marv@pidgin.im>
parents: 8376
diff changeset
1356 g_string_append_c(dest, '"');
b3cc68914150 [gaim-migrate @ 9170]
Tim Ringenbach <marv@pidgin.im>
parents: 8376
diff changeset
1357 i += 5;
21946
f444fc9e2d18 Make yahoo_html_to_codes deal with &apos; in messages being sent. Also correct
Will Thompson <resiak@pidgin.im>
parents: 19859
diff changeset
1358 } else if (((len - i) >= 6) && !strncmp(&src[i], "&apos;", 6)) {
f444fc9e2d18 Make yahoo_html_to_codes deal with &apos; in messages being sent. Also correct
Will Thompson <resiak@pidgin.im>
parents: 19859
diff changeset
1359 g_string_append_c(dest, '\'');
f444fc9e2d18 Make yahoo_html_to_codes deal with &apos; in messages being sent. Also correct
Will Thompson <resiak@pidgin.im>
parents: 19859
diff changeset
1360 i += 5;
8440
b3cc68914150 [gaim-migrate @ 9170]
Tim Ringenbach <marv@pidgin.im>
parents: 8376
diff changeset
1361 } else {
b3cc68914150 [gaim-migrate @ 9170]
Tim Ringenbach <marv@pidgin.im>
parents: 8376
diff changeset
1362 g_string_append_c(dest, src[i]);
b3cc68914150 [gaim-migrate @ 9170]
Tim Ringenbach <marv@pidgin.im>
parents: 8376
diff changeset
1363 }
6629
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1364 }
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1365 }
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1366
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1367 ret = dest->str;
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1368 g_string_free(dest, FALSE);
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1369
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1370 esc = g_strescape(ret, NULL);
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
1371 purple_debug(PURPLE_DEBUG_MISC, "yahoo", "yahoo_html_to_codes: Returning string: '%s'.\n", esc);
6629
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1372 g_free(esc);
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1373
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1374 yahoo_htc_queue_cleanup(colors);
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1375 yahoo_htc_queue_cleanup(tags);
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1376
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1377 return ret;
9d6bbc91ba24 [gaim-migrate @ 7153]
Tim Ringenbach <marv@pidgin.im>
parents: 6621
diff changeset
1378 }

mercurial