Fri, 19 Jun 2009 20:34:02 +0000
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 | 1 | /* |
| 15884 | 2 | * purple |
| 6513 | 3 | * |
| 4 | * Some code copyright 2003 Tim Ringenbach <omarvo@hotmail.com> | |
| 5 | * (marv on irc.freenode.net) | |
| 6 | * | |
| 7 | * This program is free software; you can redistribute it and/or modify | |
| 8 | * it under the terms of the GNU General Public License as published by | |
| 9 | * the Free Software Foundation; either version 2 of the License, or | |
| 10 | * (at your option) any later version. | |
| 11 | * | |
| 12 | * This program is distributed in the hope that it will be useful, | |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 15 | * GNU General Public License for more details. | |
| 16 | * | |
| 17 | * You should have received a copy of the GNU General Public License | |
| 18 | * along with this program; if not, write to the Free Software | |
|
19859
71d37b57eff2
The FSF changed its address a while ago; our files were out of date.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
19337
diff
changeset
|
19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
| 6513 | 20 | * |
| 21 | */ | |
| 22 | ||
| 23 | #ifdef HAVE_CONFIG_H | |
| 24 | #include "config.h" | |
| 25 | #endif | |
| 26 | ||
|
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 | 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 | 33 | #include "yahoo.h" |
| 6513 | 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 | 653 | /** |
| 654 | * Encode some text to send to the yahoo server. | |
| 655 | * | |
| 656 | * @param gc The connection handle. | |
| 657 | * @param str The null terminated utf8 string to encode. | |
| 658 | * @param utf8 If not @c NULL, whether utf8 is okay or not. | |
| 659 | * Even if it is okay, we may not use it. If we | |
| 660 | * used it, we set this to @c TRUE, else to | |
| 661 | * @c FALSE. If @c NULL, false is assumed, and | |
| 662 | * it is not dereferenced. | |
| 663 | * @return The g_malloced string in the appropriate encoding. | |
| 664 | */ | |
| 15884 | 665 | char *yahoo_string_encode(PurpleConnection *gc, const char *str, gboolean *utf8) |
| 7827 | 666 | { |
| 9164 | 667 | struct yahoo_data *yd = gc->proto_data; |
| 7827 | 668 | char *ret; |
|
10504
eae130eefbfe
[gaim-migrate @ 11796]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10380
diff
changeset
|
669 | const char *to_codeset; |
| 7827 | 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 | 673 | |
| 7827 | 674 | if (utf8 && *utf8) /* FIXME: maybe don't use utf8 if it'll fit in latin1 */ |
| 675 | return g_strdup(str); | |
| 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 | 679 | |
| 680 | if (ret) | |
| 681 | return ret; | |
| 682 | else | |
| 683 | return g_strdup(""); | |
| 684 | } | |
| 685 | ||
| 686 | /** | |
| 687 | * Decode some text received from the server. | |
| 688 | * | |
| 689 | * @param gc The gc handle. | |
| 690 | * @param str The null terminated string to decode. | |
| 691 | * @param utf8 Did the server tell us it was supposed to be utf8? | |
| 692 | * @return The decoded, utf-8 string, which must be g_free()'d. | |
| 693 | */ | |
| 15884 | 694 | char *yahoo_string_decode(PurpleConnection *gc, const char *str, gboolean utf8) |
| 7827 | 695 | { |
| 9164 | 696 | struct yahoo_data *yd = gc->proto_data; |
| 7827 | 697 | char *ret; |
| 14347 | 698 | const char *from_codeset; |
| 7827 | 699 | |
| 700 | if (utf8) { | |
| 701 | if (g_utf8_validate(str, -1, NULL)) | |
| 702 | return g_strdup(str); | |
| 703 | } | |
| 704 | ||
| 9164 | 705 | if (yd->jp) |
| 706 | from_codeset = "SHIFT_JIS"; | |
| 707 | else | |
| 15884 | 708 | from_codeset = purple_account_get_string(purple_connection_get_account(gc), "local_charset", "ISO-8859-1"); |
| 7827 | 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 | 711 | |
| 712 | if (ret) | |
| 713 | return ret; | |
| 714 | else | |
| 715 | return g_strdup(""); | |
| 716 | } | |
| 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 | 737 | /* |
| 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 | 740 | * |
| 741 | * [0;30m ---black | |
| 742 | * [1;37m ---white | |
| 743 | * [0;37m ---tan | |
| 744 | * [0;38m ---light black | |
| 745 | * [1;39m ---dark blue | |
| 746 | * [0;32m ---green | |
| 747 | * [0;33m ---yellow | |
| 748 | * [0;35m ---pink | |
| 749 | * [1;35m ---purple | |
| 750 | * [1;30m ---light blue | |
| 751 | * [0;31m ---red | |
| 752 | * [0;34m ---blue | |
| 753 | * [0;36m ---aqua | |
| 754 | * (shift+comma)lyellow(shift+period) ---light yellow | |
| 755 | * (shift+comma)lgreen(shift+period) ---light green | |
| 756 | [2;30m <--white out | |
| 757 | */ | |
| 758 | ||
| 759 | static GHashTable *ht = NULL; | |
| 760 | ||
| 761 | void yahoo_init_colorht() | |
| 762 | { | |
| 763 | ht = g_hash_table_new(g_str_hash, g_str_equal); | |
| 6629 | 764 | /* the numbers in comments are what gyach uses, but i think they're incorrect */ |
| 6513 | 765 | g_hash_table_insert(ht, "30", "<FONT COLOR=\"#000000\">"); /* black */ |
| 766 | g_hash_table_insert(ht, "31", "<FONT COLOR=\"#0000FF\">"); /* blue */ | |
| 767 | g_hash_table_insert(ht, "32", "<FONT COLOR=\"#008080\">"); /* cyan */ /* 00b2b2 */ | |
| 768 | g_hash_table_insert(ht, "33", "<FONT COLOR=\"#808080\">"); /* gray */ /* 808080 */ | |
| 769 | g_hash_table_insert(ht, "34", "<FONT COLOR=\"#008000\">"); /* green */ /* 00c200 */ | |
| 770 | g_hash_table_insert(ht, "35", "<FONT COLOR=\"#FF0080\">"); /* pink */ /* ffafaf */ | |
| 771 | g_hash_table_insert(ht, "36", "<FONT COLOR=\"#800080\">"); /* purple */ /* b200b2 */ | |
| 772 | g_hash_table_insert(ht, "37", "<FONT COLOR=\"#FF8000\">"); /* orange */ /* ffff00 */ | |
| 773 | g_hash_table_insert(ht, "38", "<FONT COLOR=\"#FF0000\">"); /* red */ | |
| 774 | g_hash_table_insert(ht, "39", "<FONT COLOR=\"#808000\">"); /* olive */ /* 546b50 */ | |
| 775 | ||
| 776 | g_hash_table_insert(ht, "1", "<B>"); | |
| 777 | g_hash_table_insert(ht, "x1", "</B>"); | |
| 778 | g_hash_table_insert(ht, "2", "<I>"); | |
| 779 | g_hash_table_insert(ht, "x2", "</I>"); | |
| 780 | g_hash_table_insert(ht, "4", "<U>"); | |
| 781 | g_hash_table_insert(ht, "x4", "</U>"); | |
| 782 | ||
| 6629 | 783 | /* these just tell us the text they surround is supposed |
| 15884 | 784 | * to be a link. purple figures that out on its own so we |
| 6629 | 785 | * just ignore it. |
| 786 | */ | |
| 787 | g_hash_table_insert(ht, "l", ""); /* link start */ | |
| 788 | g_hash_table_insert(ht, "xl", ""); /* link end */ | |
| 789 | ||
| 6513 | 790 | g_hash_table_insert(ht, "<black>", "<FONT COLOR=\"#000000\">"); |
| 791 | g_hash_table_insert(ht, "<blue>", "<FONT COLOR=\"#0000FF\">"); | |
| 792 | g_hash_table_insert(ht, "<cyan>", "<FONT COLOR=\"#008284\">"); | |
| 793 | g_hash_table_insert(ht, "<gray>", "<FONT COLOR=\"#848284\">"); | |
| 794 | g_hash_table_insert(ht, "<green>", "<FONT COLOR=\"#008200\">"); | |
| 795 | g_hash_table_insert(ht, "<pink>", "<FONT COLOR=\"#FF0084\">"); | |
| 796 | g_hash_table_insert(ht, "<purple>", "<FONT COLOR=\"#840084\">"); | |
| 797 | g_hash_table_insert(ht, "<orange>", "<FONT COLOR=\"#FF8000\">"); | |
| 798 | g_hash_table_insert(ht, "<red>", "<FONT COLOR=\"#FF0000\">"); | |
| 799 | g_hash_table_insert(ht, "<yellow>", "<FONT COLOR=\"#848200\">"); | |
| 800 | ||
| 801 | g_hash_table_insert(ht, "</black>", "</FONT>"); | |
| 802 | g_hash_table_insert(ht, "</blue>", "</FONT>"); | |
| 803 | g_hash_table_insert(ht, "</cyan>", "</FONT>"); | |
| 804 | g_hash_table_insert(ht, "</gray>", "</FONT>"); | |
| 805 | g_hash_table_insert(ht, "</green>", "</FONT>"); | |
| 806 | g_hash_table_insert(ht, "</pink>", "</FONT>"); | |
| 807 | g_hash_table_insert(ht, "</purple>", "</FONT>"); | |
| 808 | g_hash_table_insert(ht, "</orange>", "</FONT>"); | |
| 809 | g_hash_table_insert(ht, "</red>", "</FONT>"); | |
| 810 | g_hash_table_insert(ht, "</yellow>", "</FONT>"); | |
| 811 | ||
| 812 | /* remove these once we have proper support for <FADE> and <ALT> */ | |
| 813 | g_hash_table_insert(ht, "</fade>", ""); | |
| 814 | g_hash_table_insert(ht, "</alt>", ""); | |
| 8375 | 815 | |
| 816 | /* these are the normal html yahoo sends (besides <font>). | |
| 817 | * anything else will get turned into <tag>, so if I forgot | |
| 818 | * about something, please add it. Why Yahoo! has to send unescaped | |
| 819 | * <'s and >'s that aren't supposed to be html is beyond me. | |
| 820 | */ | |
| 821 | g_hash_table_insert(ht, "<b>", "<b>"); | |
| 822 | g_hash_table_insert(ht, "<i>", "<i>"); | |
| 823 | g_hash_table_insert(ht, "<u>", "<u>"); | |
| 824 | ||
| 825 | g_hash_table_insert(ht, "</b>", "</b>"); | |
| 826 | g_hash_table_insert(ht, "</i>", "</i>"); | |
| 827 | g_hash_table_insert(ht, "</u>", "</u>"); | |
| 8440 | 828 | g_hash_table_insert(ht, "</font>", "</font>"); |
| 6513 | 829 | } |
| 830 | ||
| 831 | void yahoo_dest_colorht() | |
| 832 | { | |
| 833 | g_hash_table_destroy(ht); | |
| 834 | } | |
| 835 | ||
| 6629 | 836 | static int point_to_html(int x) |
| 837 | { | |
| 838 | if (x < 9) | |
| 839 | return 1; | |
| 840 | if (x < 11) | |
| 841 | return 2; | |
| 842 | if (x < 13) | |
| 843 | return 3; | |
| 844 | if (x < 17) | |
| 845 | return 4; | |
| 846 | if (x < 25) | |
| 847 | return 5; | |
| 848 | if (x < 35) | |
| 849 | return 6; | |
| 850 | return 7; | |
| 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 | 854 | static void _font_tags_fix_size(GString *tag, GString *dest) |
| 855 | { | |
| 856 | char *x, *end; | |
| 857 | int size; | |
| 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 | 860 | while (*x && !g_ascii_isdigit(*x)) |
| 861 | x++; | |
| 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 | 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 | 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 | 870 | g_string_append(dest, end); |
| 871 | } else { | |
| 872 | g_string_append(dest, tag->str); | |
| 873 | return; | |
| 874 | } | |
| 875 | } else { | |
| 876 | g_string_append(dest, tag->str); | |
| 877 | return; | |
| 878 | } | |
| 879 | } | |
| 880 | ||
| 881 | char *yahoo_codes_to_html(const char *x) | |
| 6513 | 882 | { |
| 883 | GString *s, *tmp; | |
| 6629 | 884 | int i, j, xs, nomoreendtags = 0; /* s/endtags/closinganglebrackets */ |
| 6513 | 885 | char *match, *ret; |
| 886 | ||
| 887 | s = g_string_sized_new(strlen(x)); | |
| 888 | ||
| 889 | for (i = 0, xs = strlen(x); i < xs; i++) { | |
| 890 | if ((x[i] == 0x1b) && (x[i+1] == '[')) { | |
| 891 | j = i + 1; | |
| 892 | ||
| 893 | while (j++ < xs) { | |
| 894 | if (x[j] != 'm') | |
| 895 | continue; | |
| 896 | else { | |
| 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 | 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 | 901 | g_string_append(s, match); |
| 902 | else { | |
| 15884 | 903 | purple_debug(PURPLE_DEBUG_ERROR, "yahoo", |
| 6513 | 904 | "Unknown ansi code 'ESC[%sm'.\n", tmp->str); |
| 905 | g_string_free(tmp, TRUE); | |
| 906 | break; | |
| 907 | } | |
| 908 | ||
| 909 | i = j; | |
| 910 | g_string_free(tmp, TRUE); | |
| 911 | break; | |
| 912 | } | |
| 913 | } | |
| 914 | ||
| 915 | } else if (!nomoreendtags && (x[i] == '<')) { | |
| 6629 | 916 | j = i; |
| 6513 | 917 | |
| 918 | while (j++ < xs) { | |
| 919 | if (x[j] != '>') | |
| 920 | if (j == xs) { | |
| 8375 | 921 | g_string_append(s, "<"); |
| 6513 | 922 | nomoreendtags = 1; |
| 923 | } | |
| 924 | else | |
| 925 | continue; | |
| 926 | else { | |
| 927 | tmp = g_string_new_len(x + i, j - i + 1); | |
| 928 | g_string_ascii_down(tmp); | |
| 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 | 931 | g_string_append(s, match); |
| 6629 | 932 | else if (!strncmp(tmp->str, "<fade ", 6) || |
| 933 | !strncmp(tmp->str, "<alt ", 5) || | |
| 934 | !strncmp(tmp->str, "<snd ", 5)) { | |
| 6513 | 935 | |
| 6629 | 936 | /* remove this if gtkimhtml ever supports any of these */ |
| 6513 | 937 | i = j; |
| 938 | g_string_free(tmp, TRUE); | |
| 939 | break; | |
| 940 | ||
| 6629 | 941 | } else if (!strncmp(tmp->str, "<font ", 6)) { |
| 942 | _font_tags_fix_size(tmp, s); | |
| 6513 | 943 | } else { |
| 8375 | 944 | g_string_append(s, "<"); |
| 6513 | 945 | g_string_free(tmp, TRUE); |
| 946 | break; | |
| 947 | } | |
| 948 | ||
| 949 | i = j; | |
| 950 | g_string_free(tmp, TRUE); | |
| 951 | break; | |
| 952 | } | |
| 953 | ||
| 954 | } | |
| 955 | ||
| 956 | } else { | |
| 8375 | 957 | if (x[i] == '<') |
| 958 | g_string_append(s, "<"); | |
| 959 | else if (x[i] == '>') | |
| 960 | g_string_append(s, ">"); | |
| 8440 | 961 | else if (x[i] == '&') |
| 962 | g_string_append(s, "&"); | |
| 963 | else if (x[i] == '"') | |
| 964 | g_string_append(s, """); | |
| 8375 | 965 | else |
| 966 | g_string_append_c(s, x[i]); | |
| 6513 | 967 | } |
| 968 | } | |
| 969 | ||
| 970 | ret = s->str; | |
| 971 | g_string_free(s, FALSE); | |
| 15884 | 972 | purple_debug(PURPLE_DEBUG_MISC, "yahoo", "yahoo_codes_to_html: Returning string: '%s'.\n", ret); |
| 6513 | 973 | return ret; |
| 974 | } | |
| 6629 | 975 | |
| 976 | /* borrowed from gtkimhtml */ | |
| 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 | 980 | |
| 981 | enum fatype { size, color, face, junk }; | |
| 982 | typedef struct { | |
| 983 | enum fatype type; | |
| 984 | union { | |
| 985 | int size; | |
| 986 | char *color; | |
| 987 | char *face; | |
| 988 | char *junk; | |
| 989 | } u; | |
| 990 | } fontattr; | |
| 991 | ||
| 992 | static void fontattr_free(fontattr *f) | |
| 993 | { | |
| 994 | if (f->type == color) | |
| 995 | g_free(f->u.color); | |
| 996 | else if (f->type == face) | |
| 997 | g_free(f->u.face); | |
| 998 | g_free(f); | |
| 999 | } | |
| 1000 | ||
| 1001 | static void yahoo_htc_queue_cleanup(GQueue *q) | |
| 1002 | { | |
| 1003 | char *tmp; | |
| 1004 | ||
| 1005 | while ((tmp = g_queue_pop_tail(q))) | |
| 1006 | g_free(tmp); | |
| 1007 | g_queue_free(q); | |
| 1008 | } | |
| 1009 | ||
| 1010 | static void _parse_font_tag(const char *src, GString *dest, int *i, int *j, | |
| 1011 | int len, GQueue *colors, GQueue *tags, GQueue *ftattr) | |
| 1012 | { | |
| 1013 | ||
| 1014 | int m, n, vstart; | |
| 1015 | gboolean quote = 0, done = 0; | |
| 1016 | ||
| 1017 | m = *j; | |
| 1018 | ||
| 1019 | while (1) { | |
| 1020 | m++; | |
| 1021 | ||
| 1022 | if (m >= len) { | |
| 1023 | g_string_append(dest, &src[*i]); | |
| 1024 | *i = len; | |
| 1025 | break; | |
| 1026 | } | |
| 1027 | ||
| 1028 | if (src[m] == '=') { | |
| 1029 | n = vstart = m; | |
| 1030 | while (1) { | |
| 1031 | n++; | |
| 1032 | ||
| 1033 | if (n >= len) { | |
| 1034 | m = n; | |
| 1035 | break; | |
| 1036 | } | |
| 1037 | ||
|
6631
a2608d595a32
[gaim-migrate @ 7155]
Björn Voigt <bjoern@cs.tu-berlin.de>
parents:
6629
diff
changeset
|
1038 | if (src[n] == '"') { |
| 6629 | 1039 | if (!quote) { |
| 1040 | quote = 1; | |
| 1041 | vstart = n; | |
| 1042 | continue; | |
| 1043 | } else { | |
| 1044 | done = 1; | |
| 1045 | } | |
|
6631
a2608d595a32
[gaim-migrate @ 7155]
Björn Voigt <bjoern@cs.tu-berlin.de>
parents:
6629
diff
changeset
|
1046 | } |
| 6629 | 1047 | |
| 1048 | if (!quote && ((src[n] == ' ') || (src[n] == '>'))) | |
| 1049 | done = 1; | |
| 1050 | ||
| 1051 | if (done) { | |
| 1052 | if (!g_ascii_strncasecmp(&src[*j+1], "FACE", m - *j - 1)) { | |
| 1053 | fontattr *f; | |
| 1054 | ||
| 1055 | f = g_new(fontattr, 1); | |
| 1056 | f->type = face; | |
| 1057 | f->u.face = g_strndup(&src[vstart+1], n-vstart-1); | |
| 1058 | if (!ftattr) | |
| 1059 | ftattr = g_queue_new(); | |
| 1060 | g_queue_push_tail(ftattr, f); | |
| 1061 | m = n; | |
| 1062 | break; | |
| 1063 | } else if (!g_ascii_strncasecmp(&src[*j+1], "SIZE", m - *j - 1)) { | |
| 1064 | fontattr *f; | |
| 1065 | ||
| 1066 | f = g_new(fontattr, 1); | |
| 1067 | f->type = size; | |
| 1068 | f->u.size = POINT_SIZE(strtol(&src[vstart+1], NULL, 10)); | |
| 1069 | if (!ftattr) | |
| 1070 | ftattr = g_queue_new(); | |
| 1071 | g_queue_push_tail(ftattr, f); | |
| 1072 | m = n; | |
| 1073 | break; | |
| 1074 | } else if (!g_ascii_strncasecmp(&src[*j+1], "COLOR", m - *j - 1)) { | |
| 1075 | fontattr *f; | |
| 1076 | ||
| 1077 | f = g_new(fontattr, 1); | |
| 1078 | f->type = color; | |
| 1079 | f->u.color = g_strndup(&src[vstart+1], n-vstart-1); | |
| 1080 | if (!ftattr) | |
| 1081 | ftattr = g_queue_new(); | |
| 1082 | g_queue_push_head(ftattr, f); | |
| 1083 | m = n; | |
| 1084 | break; | |
| 1085 | } else { | |
| 1086 | fontattr *f; | |
| 1087 | ||
| 1088 | f = g_new(fontattr, 1); | |
| 1089 | f->type = junk; | |
| 1090 | f->u.junk = g_strndup(&src[*j+1], n-*j); | |
| 1091 | if (!ftattr) | |
| 1092 | ftattr = g_queue_new(); | |
| 1093 | g_queue_push_tail(ftattr, f); | |
| 1094 | m = n; | |
| 1095 | break; | |
| 1096 | } | |
| 1097 | ||
| 1098 | } | |
| 1099 | } | |
| 1100 | } | |
| 1101 | ||
| 1102 | if (src[m] == ' ') | |
| 1103 | *j = m; | |
| 1104 | ||
| 1105 | if (src[m] == '>') { | |
| 1106 | gboolean needendtag = 0; | |
| 1107 | fontattr *f; | |
| 1108 | GString *tmp = g_string_new(NULL); | |
| 1109 | char *colorstr; | |
| 1110 | ||
| 1111 | if (!g_queue_is_empty(ftattr)) { | |
| 1112 | while ((f = g_queue_pop_tail(ftattr))) { | |
| 1113 | switch (f->type) { | |
| 1114 | case size: | |
| 1115 | if (!needendtag) { | |
| 1116 | needendtag = 1; | |
| 1117 | g_string_append(dest, "<font "); | |
| 1118 | } | |
| 1119 | ||
| 1120 | g_string_append_printf(dest, "size=\"%d\" ", f->u.size); | |
| 1121 | fontattr_free(f); | |
| 1122 | break; | |
| 1123 | case face: | |
| 1124 | if (!needendtag) { | |
| 1125 | needendtag = 1; | |
| 1126 | g_string_append(dest, "<font "); | |
| 1127 | } | |
| 1128 | ||
| 1129 | g_string_append_printf(dest, "face=\"%s\" ", f->u.face); | |
| 1130 | fontattr_free(f); | |
| 1131 | break; | |
| 1132 | case junk: | |
| 1133 | if (!needendtag) { | |
| 1134 | needendtag = 1; | |
| 1135 | g_string_append(dest, "<font "); | |
| 1136 | } | |
| 1137 | ||
| 1138 | g_string_append(dest, f->u.junk); | |
| 1139 | fontattr_free(f); | |
| 1140 | break; | |
| 1141 | ||
| 1142 | case color: | |
| 1143 | if (needendtag) { | |
| 1144 | g_string_append(tmp, "</font>"); | |
| 1145 | dest->str[dest->len-1] = '>'; | |
| 1146 | needendtag = 0; | |
| 1147 | } | |
| 1148 | ||
| 1149 | colorstr = g_queue_peek_tail(colors); | |
| 1150 | g_string_append(tmp, colorstr ? colorstr : "\033[#000000m"); | |
| 1151 | g_string_append_printf(dest, "\033[%sm", f->u.color); | |
| 1152 | g_queue_push_tail(colors, g_strdup_printf("\033[%sm", f->u.color)); | |
| 1153 | fontattr_free(f); | |
| 1154 | break; | |
| 1155 | } | |
| 1156 | } | |
| 1157 | ||
| 1158 | g_queue_free(ftattr); | |
| 1159 | ftattr = NULL; | |
| 1160 | ||
| 1161 | if (needendtag) { | |
| 1162 | dest->str[dest->len-1] = '>'; | |
| 1163 | g_queue_push_tail(tags, g_strdup("</font>")); | |
| 1164 | g_string_free(tmp, TRUE); | |
| 1165 | } else { | |
| 1166 | g_queue_push_tail(tags, tmp->str); | |
| 1167 | g_string_free(tmp, FALSE); | |
| 1168 | } | |
| 1169 | } | |
| 1170 | ||
| 1171 | *i = *j = m; | |
| 1172 | break; | |
| 1173 | } | |
| 1174 | } | |
| 1175 | ||
| 1176 | } | |
| 1177 | ||
| 1178 | char *yahoo_html_to_codes(const char *src) | |
| 1179 | { | |
|
6631
a2608d595a32
[gaim-migrate @ 7155]
Björn Voigt <bjoern@cs.tu-berlin.de>
parents:
6629
diff
changeset
|
1180 | int i, j, len; |
| 6629 | 1181 | GString *dest; |
| 1182 | char *ret, *esc; | |
| 1183 | GQueue *colors, *tags; | |
| 1184 | GQueue *ftattr = NULL; | |
| 8440 | 1185 | gboolean no_more_specials = FALSE; |
| 6629 | 1186 | |
| 1187 | colors = g_queue_new(); | |
| 1188 | tags = g_queue_new(); | |
| 1189 | dest = g_string_sized_new(strlen(src)); | |
| 1190 | ||
| 1191 | for (i = 0, len = strlen(src); i < len; i++) { | |
| 1192 | ||
| 8440 | 1193 | if (!no_more_specials && src[i] == '<') { |
| 6629 | 1194 | j = i; |
| 1195 | ||
| 1196 | while (1) { | |
| 1197 | j++; | |
| 1198 | ||
| 1199 | if (j >= len) { /* no '>' */ | |
| 8440 | 1200 | g_string_append_c(dest, src[i]); |
| 1201 | no_more_specials = TRUE; | |
| 6629 | 1202 | break; |
| 1203 | } | |
| 1204 | ||
| 1205 | if (src[j] == '<') { | |
| 8440 | 1206 | /* FIXME: This doesn't convert outgoing entities. |
| 1207 | * However, I suspect this case may never | |
| 1208 | * happen anymore because of the entities. | |
| 1209 | */ | |
| 6629 | 1210 | g_string_append_len(dest, &src[i], j - i); |
| 1211 | i = j - 1; | |
| 1212 | if (ftattr) { | |
| 1213 | fontattr *f; | |
| 1214 | ||
| 1215 | while ((f = g_queue_pop_head(ftattr))) | |
| 1216 | fontattr_free(f); | |
| 1217 | g_queue_free(ftattr); | |
| 1218 | ftattr = NULL; | |
| 1219 | } | |
| 1220 | break; | |
| 1221 | } | |
| 1222 | ||
| 1223 | if (src[j] == ' ') { | |
| 1224 | if (!g_ascii_strncasecmp(&src[i+1], "BODY", j - i - 1)) { | |
| 1225 | char *t = strchr(&src[j], '>'); | |
| 1226 | if (!t) { | |
| 1227 | g_string_append(dest, &src[i]); | |
| 1228 | i = len; | |
| 1229 | break; | |
| 1230 | } else { | |
| 1231 | i = t - src; | |
| 1232 | break; | |
| 1233 | } | |
| 8533 | 1234 | } else if (!g_ascii_strncasecmp(&src[i+1], "A HREF=\"", j - i - 1)) { |
| 1235 | j += 7; | |
| 1236 | g_string_append(dest, "\033[lm"); | |
| 1237 | while (1) { | |
| 1238 | g_string_append_c(dest, src[j]); | |
| 1239 | if (++j >= len) { | |
| 8480 | 1240 | i = len; |
| 1241 | break; | |
| 1242 | } | |
| 8533 | 1243 | if (src[j] == '"') { |
| 1244 | g_string_append(dest, "\033[xlm"); | |
| 1245 | while (1) { | |
| 1246 | if (++j >= len) { | |
| 1247 | i = len; | |
| 1248 | break; | |
| 1249 | } | |
| 1250 | if (!g_ascii_strncasecmp(&src[j], "</A>", 4)) { | |
| 1251 | j += 3; | |
| 1252 | break; | |
| 1253 | } | |
| 1254 | } | |
| 1255 | i = j; | |
| 8480 | 1256 | break; |
| 1257 | } | |
| 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 | 1271 | } else if (g_ascii_strncasecmp(&src[i+1], "FONT", j - i - 1)) { /* not interested! */ |
| 1272 | while (1) { | |
| 1273 | if (++j >= len) { | |
| 1274 | g_string_append(dest, &src[i]); | |
| 1275 | i = len; | |
| 1276 | break; | |
| 1277 | } | |
| 1278 | if (src[j] == '>') { | |
| 1279 | g_string_append_len(dest, &src[i], j - i + 1); | |
| 1280 | i = j; | |
| 1281 | break; | |
| 1282 | } | |
| 1283 | } | |
| 1284 | } else { /* yay we have a font tag */ | |
| 1285 | _parse_font_tag(src, dest, &i, &j, len, colors, tags, ftattr); | |
| 1286 | } | |
| 1287 | ||
| 1288 | break; | |
| 1289 | } | |
| 1290 | ||
| 1291 | if (src[j] == '>') { | |
| 8440 | 1292 | /* This has some problems like the FIXME for the |
| 1293 | * '<' case. and like that case, I suspect the case | |
| 1294 | * that this has problems is won't happen anymore anyway. | |
| 1295 | */ | |
| 6629 | 1296 | int sublen = j - i - 1; |
| 1297 | ||
| 1298 | if (sublen) { | |
| 1299 | if (!g_ascii_strncasecmp(&src[i+1], "B", sublen)) { | |
| 1300 | g_string_append(dest, "\033[1m"); | |
| 1301 | } else if (!g_ascii_strncasecmp(&src[i+1], "/B", sublen)) { | |
| 1302 | g_string_append(dest, "\033[x1m"); | |
| 1303 | } else if (!g_ascii_strncasecmp(&src[i+1], "I", sublen)) { | |
| 1304 | g_string_append(dest, "\033[2m"); | |
| 1305 | } else if (!g_ascii_strncasecmp(&src[i+1], "/I", sublen)) { | |
| 1306 | g_string_append(dest, "\033[x2m"); | |
| 1307 | } else if (!g_ascii_strncasecmp(&src[i+1], "U", sublen)) { | |
| 1308 | g_string_append(dest, "\033[4m"); | |
| 1309 | } else if (!g_ascii_strncasecmp(&src[i+1], "/U", sublen)) { | |
| 1310 | g_string_append(dest, "\033[x4m"); | |
| 8480 | 1311 | } else if (!g_ascii_strncasecmp(&src[i+1], "/A", sublen)) { |
| 1312 | g_string_append(dest, "\033[xlm"); | |
| 8455 | 1313 | } else if (!g_ascii_strncasecmp(&src[i+1], "BR", sublen)) { |
| 1314 | g_string_append_c(dest, '\n'); | |
| 6629 | 1315 | } else if (!g_ascii_strncasecmp(&src[i+1], "/BODY", sublen)) { |
| 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 | 1319 | } else if (!g_ascii_strncasecmp(&src[i+1], "/FONT", sublen) && g_queue_peek_tail(tags)) { |
| 1320 | char *etag, *cl; | |
| 1321 | ||
| 1322 | etag = g_queue_pop_tail(tags); | |
| 1323 | if (etag) { | |
| 1324 | g_string_append(dest, etag); | |
| 1325 | if (!strcmp(etag, "</font>")) { | |
| 1326 | cl = g_queue_pop_tail(colors); | |
| 1327 | if (cl) | |
| 1328 | g_free(cl); | |
| 1329 | } | |
| 1330 | g_free(etag); | |
| 1331 | } | |
| 1332 | } else { | |
| 1333 | g_string_append_len(dest, &src[i], j - i + 1); | |
| 1334 | } | |
| 1335 | } else { | |
| 1336 | g_string_append_len(dest, &src[i], j - i + 1); | |
| 1337 | } | |
| 1338 | ||
| 1339 | i = j; | |
| 1340 | break; | |
| 1341 | } | |
| 1342 | ||
| 1343 | } | |
| 1344 | ||
| 1345 | } else { | |
| 8440 | 1346 | if (((len - i) >= 4) && !strncmp(&src[i], "<", 4)) { |
| 1347 | g_string_append_c(dest, '<'); | |
| 1348 | i += 3; | |
| 1349 | } else if (((len - i) >= 4) && !strncmp(&src[i], ">", 4)) { | |
| 1350 | g_string_append_c(dest, '>'); | |
| 1351 | i += 3; | |
|
21946
f444fc9e2d18
Make yahoo_html_to_codes deal with ' in messages being sent. Also correct
Will Thompson <resiak@pidgin.im>
parents:
19859
diff
changeset
|
1352 | } else if (((len - i) >= 5) && !strncmp(&src[i], "&", 5)) { |
| 8440 | 1353 | g_string_append_c(dest, '&'); |
| 1354 | i += 4; | |
|
21946
f444fc9e2d18
Make yahoo_html_to_codes deal with ' in messages being sent. Also correct
Will Thompson <resiak@pidgin.im>
parents:
19859
diff
changeset
|
1355 | } else if (((len - i) >= 6) && !strncmp(&src[i], """, 6)) { |
| 8440 | 1356 | g_string_append_c(dest, '"'); |
| 1357 | i += 5; | |
|
21946
f444fc9e2d18
Make yahoo_html_to_codes deal with ' in messages being sent. Also correct
Will Thompson <resiak@pidgin.im>
parents:
19859
diff
changeset
|
1358 | } else if (((len - i) >= 6) && !strncmp(&src[i], "'", 6)) { |
|
f444fc9e2d18
Make yahoo_html_to_codes deal with ' in messages being sent. Also correct
Will Thompson <resiak@pidgin.im>
parents:
19859
diff
changeset
|
1359 | g_string_append_c(dest, '\''); |
|
f444fc9e2d18
Make yahoo_html_to_codes deal with ' in messages being sent. Also correct
Will Thompson <resiak@pidgin.im>
parents:
19859
diff
changeset
|
1360 | i += 5; |
| 8440 | 1361 | } else { |
| 1362 | g_string_append_c(dest, src[i]); | |
| 1363 | } | |
| 6629 | 1364 | } |
| 1365 | } | |
| 1366 | ||
| 1367 | ret = dest->str; | |
| 1368 | g_string_free(dest, FALSE); | |
| 1369 | ||
| 1370 | esc = g_strescape(ret, NULL); | |
| 15884 | 1371 | purple_debug(PURPLE_DEBUG_MISC, "yahoo", "yahoo_html_to_codes: Returning string: '%s'.\n", esc); |
| 6629 | 1372 | g_free(esc); |
| 1373 | ||
| 1374 | yahoo_htc_queue_cleanup(colors); | |
| 1375 | yahoo_htc_queue_cleanup(tags); | |
| 1376 | ||
| 1377 | return ret; | |
| 1378 | } |