annotate libgaim/proxy.c @ 14913:a03e74b9b257

[gaim-migrate @ 17685] fixing bugs 1570090, 1426401, applying patch 1526274. Starting to add support for ways to get around version-blocked sametime servers. Added fix to prevent login redirects from entering an eternal loop. Removing an unnecessary (and problematic) LDFLAG. I've been really slack for a while, so this is me getting caught up. committer: Tailor Script <tailor@pidgin.im>
author Christopher O'Brien <siege@pidgin.im>
date Mon, 06 Nov 2006 22:22:52 +0000
parents 6334d1b51252
children 3e8ae7a4fa0e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1 /**
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
2 * @file proxy.c Proxy API
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
3 * @ingroup core
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
4 *
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
5 * gaim
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
6 *
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
7 * Gaim is the legal property of its developers, whose names are too numerous
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
8 * to list here. Please refer to the COPYRIGHT file distributed with this
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
9 * source distribution.
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
10 *
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
11 * This program is free software; you can redistribute it and/or modify
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
12 * it under the terms of the GNU General Public License as published by
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
13 * the Free Software Foundation; either version 2 of the License, or
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
14 * (at your option) any later version.
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
15 *
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
16 * This program is distributed in the hope that it will be useful,
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
19 * GNU General Public License for more details.
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
20 *
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
21 * You should have received a copy of the GNU General Public License
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
22 * along with this program; if not, write to the Free Software
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
24 *
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
25 */
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
26
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
27 /* this is a little piece of code to handle proxy connection */
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
28 /* it is intended to : 1st handle http proxy, using the CONNECT command
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
29 , 2nd provide an easy way to add socks support
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
30 , 3rd draw women to it like flies to honey */
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
31
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
32 #include "internal.h"
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
33 #include "cipher.h"
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
34 #include "debug.h"
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
35 #include "dnsquery.h"
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
36 #include "notify.h"
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
37 #include "ntlm.h"
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
38 #include "prefs.h"
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
39 #include "proxy.h"
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
40 #include "util.h"
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
41
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
42 struct _GaimProxyConnectData {
14837
118fd0dc5b6e [gaim-migrate @ 17606]
Mark Doliner <mark@kingant.net>
parents: 14474
diff changeset
43 void *handle;
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
44 GaimProxyConnectFunction connect_cb;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
45 gpointer data;
14451
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
46 gchar *host;
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
47 int port;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
48 int fd;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
49 guint inpa;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
50 GaimProxyInfo *gpi;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
51 GaimDnsQueryData *query_data;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
52
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
53 /**
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
54 * This contains alternating length/char* values. The char*
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
55 * values need to be freed when removed from the linked list.
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
56 */
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
57 GSList *hosts;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
58
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
59 /*
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
60 * All of the following variables are used when establishing a
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
61 * connection through a proxy.
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
62 */
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
63 guchar *write_buffer;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
64 gsize write_buf_len;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
65 gsize written_len;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
66 GaimInputFunction read_cb;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
67 guchar *read_buffer;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
68 gsize read_buf_len;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
69 gsize read_len;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
70 };
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
71
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
72 static const char *socks5errors[] = {
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
73 "succeeded\n",
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
74 "general SOCKS server failure\n",
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
75 "connection not allowed by ruleset\n",
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
76 "Network unreachable\n",
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
77 "Host unreachable\n",
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
78 "Connection refused\n",
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
79 "TTL expired\n",
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
80 "Command not supported\n",
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
81 "Address type not supported\n"
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
82 };
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
83
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
84 static GaimProxyInfo *global_proxy_info = NULL;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
85
14837
118fd0dc5b6e [gaim-migrate @ 17606]
Mark Doliner <mark@kingant.net>
parents: 14474
diff changeset
86 static GSList *handles = NULL;
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
87
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
88 static void try_connect(GaimProxyConnectData *connect_data);
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
89
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
90 /**************************************************************************
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
91 * Proxy structure API
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
92 **************************************************************************/
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
93 GaimProxyInfo *
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
94 gaim_proxy_info_new(void)
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
95 {
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
96 return g_new0(GaimProxyInfo, 1);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
97 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
98
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
99 void
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
100 gaim_proxy_info_destroy(GaimProxyInfo *info)
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
101 {
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
102 g_return_if_fail(info != NULL);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
103
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
104 g_free(info->host);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
105 g_free(info->username);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
106 g_free(info->password);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
107
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
108 g_free(info);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
109 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
110
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
111 void
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
112 gaim_proxy_info_set_type(GaimProxyInfo *info, GaimProxyType type)
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
113 {
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
114 g_return_if_fail(info != NULL);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
115
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
116 info->type = type;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
117 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
118
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
119 void
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
120 gaim_proxy_info_set_host(GaimProxyInfo *info, const char *host)
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
121 {
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
122 g_return_if_fail(info != NULL);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
123
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
124 g_free(info->host);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
125 info->host = g_strdup(host);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
126 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
127
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
128 void
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
129 gaim_proxy_info_set_port(GaimProxyInfo *info, int port)
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
130 {
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
131 g_return_if_fail(info != NULL);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
132
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
133 info->port = port;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
134 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
135
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
136 void
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
137 gaim_proxy_info_set_username(GaimProxyInfo *info, const char *username)
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
138 {
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
139 g_return_if_fail(info != NULL);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
140
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
141 g_free(info->username);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
142 info->username = g_strdup(username);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
143 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
144
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
145 void
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
146 gaim_proxy_info_set_password(GaimProxyInfo *info, const char *password)
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
147 {
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
148 g_return_if_fail(info != NULL);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
149
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
150 g_free(info->password);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
151 info->password = g_strdup(password);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
152 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
153
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
154 GaimProxyType
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
155 gaim_proxy_info_get_type(const GaimProxyInfo *info)
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
156 {
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
157 g_return_val_if_fail(info != NULL, GAIM_PROXY_NONE);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
158
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
159 return info->type;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
160 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
161
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
162 const char *
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
163 gaim_proxy_info_get_host(const GaimProxyInfo *info)
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
164 {
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
165 g_return_val_if_fail(info != NULL, NULL);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
166
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
167 return info->host;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
168 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
169
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
170 int
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
171 gaim_proxy_info_get_port(const GaimProxyInfo *info)
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
172 {
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
173 g_return_val_if_fail(info != NULL, 0);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
174
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
175 return info->port;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
176 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
177
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
178 const char *
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
179 gaim_proxy_info_get_username(const GaimProxyInfo *info)
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
180 {
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
181 g_return_val_if_fail(info != NULL, NULL);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
182
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
183 return info->username;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
184 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
185
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
186 const char *
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
187 gaim_proxy_info_get_password(const GaimProxyInfo *info)
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
188 {
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
189 g_return_val_if_fail(info != NULL, NULL);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
190
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
191 return info->password;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
192 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
193
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
194 /**************************************************************************
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
195 * Global Proxy API
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
196 **************************************************************************/
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
197 GaimProxyInfo *
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
198 gaim_global_proxy_get_info(void)
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
199 {
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
200 return global_proxy_info;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
201 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
202
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
203 static GaimProxyInfo *
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
204 gaim_gnome_proxy_get_info(void)
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
205 {
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
206 static GaimProxyInfo info = {0, NULL, 0, NULL, NULL};
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
207 gchar *path;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
208 if ((path = g_find_program_in_path("gconftool-2"))) {
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
209 gchar *tmp;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
210
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
211 g_free(path);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
212
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
213 /* See whether to use a proxy. */
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
214 if (!g_spawn_command_line_sync("gconftool-2 -g /system/http_proxy/use_http_proxy", &tmp,
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
215 NULL, NULL, NULL))
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
216 return gaim_global_proxy_get_info();
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
217 if (!strcmp(tmp, "false\n")) {
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
218 info.type = GAIM_PROXY_NONE;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
219 g_free(tmp);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
220 return &info;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
221 } else if (strcmp(tmp, "true\n")) {
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
222 g_free(tmp);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
223 return gaim_global_proxy_get_info();
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
224 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
225
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
226 g_free(tmp);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
227 info.type = GAIM_PROXY_HTTP;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
228
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
229 /* Free the old fields */
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
230 if (info.host) {
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
231 g_free(info.host);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
232 info.host = NULL;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
233 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
234 if (info.username) {
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
235 g_free(info.username);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
236 info.username = NULL;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
237 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
238 if (info.password) {
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
239 g_free(info.password);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
240 info.password = NULL;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
241 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
242
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
243 /* Get the new ones */
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
244 if (!g_spawn_command_line_sync("gconftool-2 -g /system/http_proxy/host", &info.host,
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
245 NULL, NULL, NULL))
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
246 return gaim_global_proxy_get_info();
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
247 g_strchomp(info.host);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
248
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
249 if (!g_spawn_command_line_sync("gconftool-2 -g /system/http_proxy/authentication_user", &info.username,
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
250 NULL, NULL, NULL))
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
251 return gaim_global_proxy_get_info();
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
252 g_strchomp(info.username);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
253
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
254 if (!g_spawn_command_line_sync("gconftool-2 -g /system/http_proxy/authentication_password", &info.password,
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
255 NULL, NULL, NULL))
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
256 return gaim_global_proxy_get_info();
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
257 g_strchomp(info.password);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
258
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
259 if (!g_spawn_command_line_sync("gconftool-2 -g /system/http_proxy/port", &tmp,
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
260 NULL, NULL, NULL))
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
261 return gaim_global_proxy_get_info();
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
262 info.port = atoi(tmp);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
263 g_free(tmp);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
264
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
265 return &info;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
266 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
267 return gaim_global_proxy_get_info();
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
268 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
269 /**************************************************************************
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
270 * Proxy API
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
271 **************************************************************************/
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
272
14451
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
273 /**
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
274 * Whoever calls this needs to have called
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
275 * gaim_proxy_connect_data_disconnect() beforehand.
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
276 */
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
277 static void
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
278 gaim_proxy_connect_data_destroy(GaimProxyConnectData *connect_data)
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
279 {
14837
118fd0dc5b6e [gaim-migrate @ 17606]
Mark Doliner <mark@kingant.net>
parents: 14474
diff changeset
280 handles = g_slist_remove(handles, connect_data);
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
281
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
282 if (connect_data->query_data != NULL)
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
283 gaim_dnsquery_destroy(connect_data->query_data);
14238
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
284
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
285 while (connect_data->hosts != NULL)
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
286 {
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
287 /* Discard the length... */
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
288 connect_data->hosts = g_slist_remove(connect_data->hosts, connect_data->hosts->data);
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
289 /* Free the address... */
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
290 g_free(connect_data->hosts->data);
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
291 connect_data->hosts = g_slist_remove(connect_data->hosts, connect_data->hosts->data);
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
292 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
293
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
294 g_free(connect_data->host);
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
295 g_free(connect_data);
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
296 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
297
14451
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
298 /**
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
299 * Free all information dealing with a connection attempt and
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
300 * reset the connect_data to prepare for it to try to connect
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
301 * to another IP address.
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
302 *
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
303 * If an error message is passed in, then we know the connection
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
304 * attempt failed. If the connection attempt failed and
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
305 * connect_data->hosts is not empty then we try the next IP address.
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
306 * If the connection attempt failed and we have no more hosts
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
307 * try try then we call the callback with the given error message,
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
308 * then destroy the connect_data.
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
309 *
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
310 * @param error_message An error message explaining why the connection
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
311 * failed. This will be passed to the callback function
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
312 * specified in the call to gaim_proxy_connect(). If the
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
313 * connection was successful then pass in null.
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
314 */
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
315 static void
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
316 gaim_proxy_connect_data_disconnect(GaimProxyConnectData *connect_data, const gchar *error_message)
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
317 {
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
318 if (connect_data->inpa > 0)
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
319 {
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
320 gaim_input_remove(connect_data->inpa);
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
321 connect_data->inpa = 0;
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
322 }
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
323
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
324 if (connect_data->fd >= 0)
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
325 {
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
326 close(connect_data->fd);
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
327 connect_data->fd = -1;
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
328 }
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
329
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
330 g_free(connect_data->write_buffer);
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
331 connect_data->write_buffer = NULL;
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
332
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
333 g_free(connect_data->read_buffer);
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
334 connect_data->read_buffer = NULL;
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
335
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
336 if (error_message != NULL)
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
337 {
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
338 gaim_debug_info("proxy", "Connection attempt failed: %s\n",
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
339 error_message);
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
340 if (connect_data->hosts != NULL)
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
341 try_connect(connect_data);
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
342 else
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
343 {
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
344 /* Everything failed! Tell the originator of the request. */
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
345 connect_data->connect_cb(connect_data->data, -1, error_message);
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
346 gaim_proxy_connect_data_destroy(connect_data);
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
347 }
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
348 }
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
349 }
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
350
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
351 /**
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
352 * This calls gaim_proxy_connect_data_disconnect(), but it lets you
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
353 * specify the error_message using a printf()-like syntax.
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
354 */
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
355 static void
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
356 gaim_proxy_connect_data_disconnect_formatted(GaimProxyConnectData *connect_data, const char *format, ...)
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
357 {
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
358 va_list args;
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
359 gchar *tmp;
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
360
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
361 va_start(args, format);
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
362 tmp = g_strdup_vprintf(format, args);
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
363 va_end(args);
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
364
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
365 gaim_proxy_connect_data_disconnect(connect_data, tmp);
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
366 g_free(tmp);
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
367 }
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
368
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
369 static void
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
370 gaim_proxy_connect_data_connected(GaimProxyConnectData *connect_data)
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
371 {
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
372 connect_data->connect_cb(connect_data->data, connect_data->fd, NULL);
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
373
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
374 /*
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
375 * We've passed the file descriptor to the protocol, so it's no longer
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
376 * our responsibility, and we should be careful not to free it when
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
377 * we destroy the connect_data.
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
378 */
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
379 connect_data->fd = -1;
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
380
14451
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
381 gaim_proxy_connect_data_disconnect(connect_data, NULL);
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
382 gaim_proxy_connect_data_destroy(connect_data);
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
383 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
384
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
385 static void
14451
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
386 socket_ready_cb(gpointer data, gint source, GaimInputCondition cond)
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
387 {
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
388 GaimProxyConnectData *connect_data = data;
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
389 socklen_t len;
14451
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
390 int error = 0;
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
391 int ret;
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
392
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
393 gaim_debug_info("proxy", "Connected.\n");
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
394
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
395 /*
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
396 * getsockopt after a non-blocking connect returns -1 if something is
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
397 * really messed up (bad descriptor, usually). Otherwise, it returns 0 and
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
398 * error holds what connect would have returned if it blocked until now.
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
399 * Thus, error == 0 is success, error == EINPROGRESS means "try again",
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
400 * and anything else is a real error.
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
401 *
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
402 * (error == EINPROGRESS can happen after a select because the kernel can
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
403 * be overly optimistic sometimes. select is just a hint that you might be
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
404 * able to do something.)
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
405 */
14451
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
406 len = sizeof(error);
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
407 ret = getsockopt(connect_data->fd, SOL_SOCKET, SO_ERROR, &error, &len);
14451
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
408
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
409 if (ret == 0 && error == EINPROGRESS)
14451
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
410 /* No worries - we'll be called again later */
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
411 /* TODO: Does this ever happen? */
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
412 return;
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
413
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
414 if (ret != 0 || error != 0) {
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
415 if (ret != 0)
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
416 error = errno;
14451
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
417 gaim_proxy_connect_data_disconnect(connect_data, strerror(error));
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
418 return;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
419 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
420
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
421 gaim_proxy_connect_data_connected(connect_data);
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
422 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
423
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
424 static gboolean
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
425 clean_connect(gpointer data)
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
426 {
14451
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
427 gaim_proxy_connect_data_connected(data);
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
428
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
429 return FALSE;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
430 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
431
14451
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
432 static void
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
433 proxy_connect_none(GaimProxyConnectData *connect_data, struct sockaddr *addr, socklen_t addrlen)
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
434 {
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
435 gaim_debug_info("proxy", "Connecting to %s:%d with no proxy\n",
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
436 connect_data->host, connect_data->port);
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
437
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
438 connect_data->fd = socket(addr->sa_family, SOCK_STREAM, 0);
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
439 if (connect_data->fd < 0)
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
440 {
14451
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
441 gaim_proxy_connect_data_disconnect_formatted(connect_data,
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
442 _("Unable to create socket:\n%s"), strerror(errno));
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
443 return;
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
444 }
14451
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
445
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
446 fcntl(connect_data->fd, F_SETFL, O_NONBLOCK);
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
447 #ifndef _WIN32
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
448 fcntl(connect_data->fd, F_SETFD, FD_CLOEXEC);
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
449 #endif
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
450
14451
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
451 if (connect(connect_data->fd, addr, addrlen) != 0)
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
452 {
14451
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
453 if ((errno == EINPROGRESS) || (errno == EINTR))
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
454 {
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
455 gaim_debug_info("proxy", "Connection in progress\n");
14451
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
456 connect_data->inpa = gaim_input_add(connect_data->fd,
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
457 GAIM_INPUT_WRITE, socket_ready_cb, connect_data);
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
458 }
14451
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
459 else
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
460 {
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
461 gaim_proxy_connect_data_disconnect(connect_data, strerror(errno));
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
462 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
463 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
464 else
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
465 {
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
466 /*
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
467 * The connection happened IMMEDIATELY... strange, but whatever.
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
468 */
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
469 socklen_t len;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
470 int error = ETIMEDOUT;
14451
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
471 int ret;
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
472
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
473 gaim_debug_info("proxy", "Connected immediately.\n");
14451
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
474
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
475 len = sizeof(error);
14451
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
476 ret = getsockopt(connect_data->fd, SOL_SOCKET, SO_ERROR, &error, &len);
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
477 if ((ret != 0) || (error != 0))
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
478 {
14451
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
479 if (ret != 0)
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
480 error = errno;
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
481 gaim_proxy_connect_data_disconnect(connect_data, strerror(error));
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
482 return;
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
483 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
484
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
485 /*
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
486 * We want to call the "connected" callback eventually, but we
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
487 * don't want to call it before we return, just in case.
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
488 */
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
489 gaim_timeout_add(10, clean_connect, connect_data);
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
490 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
491 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
492
14451
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
493 /**
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
494 * This is a utility function used by the HTTP, SOCKS4 and SOCKS5
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
495 * connect functions. It writes data from a buffer to a socket.
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
496 * When all the data is written it sets up a watcher to read a
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
497 * response and call a specified function.
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
498 */
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
499 static void
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
500 proxy_do_write(gpointer data, gint source, GaimInputCondition cond)
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
501 {
14451
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
502 GaimProxyConnectData *connect_data;
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
503 const guchar *request;
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
504 gsize request_len;
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
505 int ret;
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
506
14451
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
507 connect_data = data;
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
508 request = connect_data->write_buffer + connect_data->written_len;
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
509 request_len = connect_data->write_buf_len - connect_data->written_len;
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
510
14451
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
511 ret = write(connect_data->fd, request, request_len);
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
512 if (ret <= 0)
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
513 {
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
514 if (errno == EAGAIN)
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
515 /* No worries */
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
516 return;
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
517
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
518 /* Error! */
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
519 gaim_proxy_connect_data_disconnect(connect_data, strerror(errno));
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
520 return;
14451
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
521 }
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
522 if (ret < request_len) {
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
523 connect_data->written_len += ret;
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
524 return;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
525 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
526
14451
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
527 /* We're done writing data! Wait for a response. */
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
528 g_free(connect_data->write_buffer);
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
529 connect_data->write_buffer = NULL;
14451
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
530 gaim_input_remove(connect_data->inpa);
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
531 connect_data->inpa = gaim_input_add(connect_data->fd,
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
532 GAIM_INPUT_READ, connect_data->read_cb, connect_data);
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
533 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
534
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
535 #define HTTP_GOODSTRING "HTTP/1.0 200"
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
536 #define HTTP_GOODSTRING2 "HTTP/1.1 200"
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
537
14451
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
538 /**
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
539 * We're using an HTTP proxy for a non-port 80 tunnel. Read the
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
540 * response to the CONNECT request.
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
541 */
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
542 static void
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
543 http_canread(gpointer data, gint source, GaimInputCondition cond)
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
544 {
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
545 int len, headers_len, status = 0;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
546 gboolean error;
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
547 GaimProxyConnectData *connect_data = data;
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
548 guchar *p;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
549 gsize max_read;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
550
14451
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
551 if (connect_data->read_buffer == NULL)
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
552 {
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
553 connect_data->read_buf_len = 8192;
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
554 connect_data->read_buffer = g_malloc(connect_data->read_buf_len);
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
555 connect_data->read_len = 0;
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
556 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
557
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
558 p = connect_data->read_buffer + connect_data->read_len;
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
559 max_read = connect_data->read_buf_len - connect_data->read_len - 1;
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
560
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
561 len = read(connect_data->fd, p, max_read);
14451
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
562
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
563 if (len == 0)
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
564 {
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
565 gaim_proxy_connect_data_disconnect(connect_data,
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
566 _("Server closed the connection."));
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
567 return;
14451
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
568 }
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
569
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
570 if (len < 0)
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
571 {
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
572 if (errno == EAGAIN)
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
573 /* No worries */
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
574 return;
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
575
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
576 /* Error! */
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
577 gaim_proxy_connect_data_disconnect_formatted(connect_data,
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
578 _("Lost connection with server:\n%s"), strerror(errno));
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
579 return;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
580 }
14451
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
581
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
582 connect_data->read_len += len;
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
583 p[len] = '\0';
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
584
14451
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
585 p = (guchar *)g_strstr_len((const gchar *)connect_data->read_buffer,
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
586 connect_data->read_len, "\r\n\r\n");
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
587 if (p != NULL) {
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
588 *p = '\0';
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
589 headers_len = (p - connect_data->read_buffer) + 4;
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
590 } else if(len == max_read)
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
591 headers_len = len;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
592 else
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
593 return;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
594
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
595 error = strncmp((const char *)connect_data->read_buffer, "HTTP/", 5) != 0;
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
596 if (!error)
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
597 {
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
598 int major;
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
599 p = connect_data->read_buffer + 5;
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
600 major = strtol((const char *)p, (char **)&p, 10);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
601 error = (major == 0) || (*p != '.');
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
602 if(!error) {
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
603 int minor;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
604 p++;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
605 minor = strtol((const char *)p, (char **)&p, 10);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
606 error = (*p != ' ');
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
607 if(!error) {
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
608 p++;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
609 status = strtol((const char *)p, (char **)&p, 10);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
610 error = (*p != ' ');
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
611 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
612 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
613 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
614
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
615 /* Read the contents */
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
616 p = (guchar *)g_strrstr((const gchar *)connect_data->read_buffer, "Content-Length: ");
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
617 if (p != NULL)
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
618 {
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
619 gchar *tmp;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
620 int len = 0;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
621 char tmpc;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
622 p += strlen("Content-Length: ");
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
623 tmp = strchr((const char *)p, '\r');
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
624 if(tmp)
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
625 *tmp = '\0';
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
626 len = atoi((const char *)p);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
627 if(tmp)
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
628 *tmp = '\r';
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
629
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
630 /* Compensate for what has already been read */
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
631 len -= connect_data->read_len - headers_len;
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
632 /* I'm assuming that we're doing this to prevent the server from
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
633 complaining / breaking since we don't read the whole page */
14451
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
634 while (len--) {
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
635 /* TODO: deal with EAGAIN (and other errors) better */
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
636 if (read(connect_data->fd, &tmpc, 1) < 0 && errno != EAGAIN)
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
637 break;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
638 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
639 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
640
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
641 if (error)
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
642 {
14451
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
643 gaim_proxy_connect_data_disconnect_formatted(connect_data,
14356
4ae3c2913c3e [gaim-migrate @ 17062]
Mark Doliner <mark@kingant.net>
parents: 14262
diff changeset
644 _("Unable to parse response from HTTP proxy: %s\n"),
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
645 connect_data->read_buffer);
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
646 return;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
647 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
648 else if (status != 200)
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
649 {
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
650 gaim_debug_error("proxy",
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
651 "Proxy server replied with:\n%s\n",
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
652 connect_data->read_buffer);
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
653
14451
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
654 if (status == 407 /* Proxy Auth */)
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
655 {
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
656 gchar *ntlm;
14451
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
657 ntlm = g_strrstr((const gchar *)connect_data->read_buffer,
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
658 "Proxy-Authenticate: NTLM ");
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
659 if (ntlm != NULL)
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
660 {
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
661 /* Check for Type-2 */
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
662 gchar *tmp = ntlm;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
663 guint8 *nonce;
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
664 gchar *domain = (gchar*)gaim_proxy_info_get_username(connect_data->gpi);
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
665 gchar *username;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
666 gchar *request;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
667 gchar *response;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
668 username = strchr(domain, '\\');
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
669 if (username == NULL)
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
670 {
14451
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
671 gaim_proxy_connect_data_disconnect_formatted(connect_data,
14356
4ae3c2913c3e [gaim-migrate @ 17062]
Mark Doliner <mark@kingant.net>
parents: 14262
diff changeset
672 _("HTTP proxy connection error %d"), status);
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
673 return;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
674 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
675 *username = '\0';
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
676 username++;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
677 ntlm += strlen("Proxy-Authenticate: NTLM ");
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
678 while(*tmp != '\r' && *tmp != '\0') tmp++;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
679 *tmp = '\0';
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
680 nonce = gaim_ntlm_parse_type2(ntlm, NULL);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
681 response = gaim_ntlm_gen_type3(username,
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
682 (gchar*) gaim_proxy_info_get_password(connect_data->gpi),
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
683 (gchar*) gaim_proxy_info_get_host(connect_data->gpi),
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
684 domain, nonce, NULL);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
685 username--;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
686 *username = '\\';
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
687 request = g_strdup_printf(
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
688 "CONNECT %s:%d HTTP/1.1\r\n"
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
689 "Host: %s:%d\r\n"
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
690 "Proxy-Authorization: NTLM %s\r\n"
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
691 "Proxy-Connection: Keep-Alive\r\n\r\n",
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
692 connect_data->host, connect_data->port, connect_data->host,
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
693 connect_data->port, response);
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
694 g_free(response);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
695
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
696 g_free(connect_data->read_buffer);
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
697 connect_data->read_buffer = NULL;
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
698
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
699 connect_data->write_buffer = (guchar *)request;
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
700 connect_data->write_buf_len = strlen(request);
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
701 connect_data->written_len = 0;
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
702 connect_data->read_cb = http_canread;
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
703
14451
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
704 gaim_input_remove(connect_data->inpa);
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
705 connect_data->inpa = gaim_input_add(connect_data->fd,
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
706 GAIM_INPUT_WRITE, proxy_do_write, connect_data);
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
707 proxy_do_write(connect_data, connect_data->fd, cond);
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
708 return;
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
709 } else if((ntlm = g_strrstr((const char *)connect_data->read_buffer, "Proxy-Authenticate: NTLM"))) { /* Empty message */
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
710 gchar request[2048];
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
711 gchar *domain = (gchar*) gaim_proxy_info_get_username(connect_data->gpi);
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
712 gchar *username;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
713 int request_len;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
714 username = strchr(domain, '\\');
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
715 if (username == NULL)
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
716 {
14451
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
717 gaim_proxy_connect_data_disconnect_formatted(connect_data,
14356
4ae3c2913c3e [gaim-migrate @ 17062]
Mark Doliner <mark@kingant.net>
parents: 14262
diff changeset
718 _("HTTP proxy connection error %d"), status);
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
719 return;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
720 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
721 *username = '\0';
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
722
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
723 request_len = g_snprintf(request, sizeof(request),
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
724 "CONNECT %s:%d HTTP/1.1\r\n"
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
725 "Host: %s:%d\r\n",
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
726 connect_data->host, connect_data->port,
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
727 connect_data->host, connect_data->port);
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
728
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
729 g_return_if_fail(request_len < sizeof(request));
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
730 request_len += g_snprintf(request + request_len,
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
731 sizeof(request) - request_len,
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
732 "Proxy-Authorization: NTLM %s\r\n"
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
733 "Proxy-Connection: Keep-Alive\r\n\r\n",
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
734 gaim_ntlm_gen_type1(
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
735 (gchar*) gaim_proxy_info_get_host(connect_data->gpi),
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
736 domain));
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
737 *username = '\\';
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
738
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
739 gaim_input_remove(connect_data->inpa);
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
740 g_free(connect_data->read_buffer);
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
741 connect_data->read_buffer = NULL;
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
742
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
743 connect_data->write_buffer = g_memdup(request, request_len);
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
744 connect_data->write_buf_len = request_len;
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
745 connect_data->written_len = 0;
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
746
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
747 connect_data->read_cb = http_canread;
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
748
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
749 connect_data->inpa = gaim_input_add(connect_data->fd,
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
750 GAIM_INPUT_WRITE, proxy_do_write, connect_data);
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
751
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
752 proxy_do_write(connect_data, connect_data->fd, cond);
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
753 return;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
754 } else {
14451
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
755 gaim_proxy_connect_data_disconnect_formatted(connect_data,
14356
4ae3c2913c3e [gaim-migrate @ 17062]
Mark Doliner <mark@kingant.net>
parents: 14262
diff changeset
756 _("HTTP proxy connection error %d"), status);
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
757 return;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
758 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
759 }
14451
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
760 if (status == 403)
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
761 {
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
762 /* Forbidden */
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
763 gaim_proxy_connect_data_disconnect_formatted(connect_data,
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
764 _("Access denied: HTTP proxy server forbids port %d tunneling."),
14356
4ae3c2913c3e [gaim-migrate @ 17062]
Mark Doliner <mark@kingant.net>
parents: 14262
diff changeset
765 connect_data->port);
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
766 } else {
14451
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
767 gaim_proxy_connect_data_disconnect_formatted(connect_data,
14356
4ae3c2913c3e [gaim-migrate @ 17062]
Mark Doliner <mark@kingant.net>
parents: 14262
diff changeset
768 _("HTTP proxy connection error %d"), status);
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
769 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
770 } else {
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
771 gaim_input_remove(connect_data->inpa);
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
772 connect_data->inpa = 0;
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
773 g_free(connect_data->read_buffer);
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
774 connect_data->read_buffer = NULL;
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
775 gaim_debug_info("proxy", "HTTP proxy connection established\n");
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
776 gaim_proxy_connect_data_connected(connect_data);
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
777 return;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
778 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
779 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
780
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
781 static void
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
782 http_canwrite(gpointer data, gint source, GaimInputCondition cond)
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
783 {
14451
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
784 GString *request;
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
785 GaimProxyConnectData *connect_data;
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
786 socklen_t len;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
787 int error = ETIMEDOUT;
14451
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
788 int ret;
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
789
14451
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
790 gaim_debug_info("proxy", "Connected.\n");
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
791
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
792 connect_data = data;
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
793
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
794 if (connect_data->inpa > 0)
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
795 {
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
796 gaim_input_remove(connect_data->inpa);
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
797 connect_data->inpa = 0;
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
798 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
799
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
800 len = sizeof(error);
14451
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
801 ret = getsockopt(connect_data->fd, SOL_SOCKET, SO_ERROR, &error, &len);
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
802 if ((ret != 0) || (error != 0))
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
803 {
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
804 if (ret != 0)
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
805 error = errno;
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
806 gaim_proxy_connect_data_disconnect(connect_data, strerror(error));
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
807 return;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
808 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
809
14451
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
810 gaim_debug_info("proxy", "Using CONNECT tunneling for %s:%d\n",
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
811 connect_data->host, connect_data->port);
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
812
14451
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
813 request = g_string_sized_new(4096);
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
814 g_string_append_printf(request,
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
815 "CONNECT %s:%d HTTP/1.1\r\nHost: %s:%d\r\n",
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
816 connect_data->host, connect_data->port,
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
817 connect_data->host, connect_data->port);
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
818
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
819 if (gaim_proxy_info_get_username(connect_data->gpi) != NULL)
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
820 {
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
821 char *t1, *t2;
14451
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
822
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
823 t1 = g_strdup_printf("%s:%s",
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
824 gaim_proxy_info_get_username(connect_data->gpi),
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
825 gaim_proxy_info_get_password(connect_data->gpi) ?
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
826 gaim_proxy_info_get_password(connect_data->gpi) : "");
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
827 t2 = gaim_base64_encode((const guchar *)t1, strlen(t1));
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
828 g_free(t1);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
829
14451
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
830 g_string_append_printf(request,
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
831 "Proxy-Authorization: Basic %s\r\n"
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
832 "Proxy-Authorization: NTLM %s\r\n"
14451
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
833 "Proxy-Connection: Keep-Alive\r\n",
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
834 t2, gaim_ntlm_gen_type1(
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
835 gaim_proxy_info_get_host(connect_data->gpi), ""));
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
836 g_free(t2);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
837 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
838
14451
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
839 g_string_append(request, "\r\n");
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
840
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
841 connect_data->write_buf_len = request->len;
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
842 connect_data->write_buffer = (guchar *)g_string_free(request, FALSE);
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
843 connect_data->written_len = 0;
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
844 connect_data->read_cb = http_canread;
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
845
14451
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
846 connect_data->inpa = gaim_input_add(connect_data->fd,
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
847 GAIM_INPUT_WRITE, proxy_do_write, connect_data);
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
848 proxy_do_write(connect_data, connect_data->fd, cond);
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
849 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
850
14451
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
851 static void
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
852 proxy_connect_http(GaimProxyConnectData *connect_data, struct sockaddr *addr, socklen_t addrlen)
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
853 {
14451
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
854 gaim_debug_info("proxy",
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
855 "Connecting to %s:%d via %s:%d using HTTP\n",
14451
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
856 connect_data->host, connect_data->port,
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
857 (gaim_proxy_info_get_host(connect_data->gpi) ? gaim_proxy_info_get_host(connect_data->gpi) : "(null)"),
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
858 gaim_proxy_info_get_port(connect_data->gpi));
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
859
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
860 connect_data->fd = socket(addr->sa_family, SOCK_STREAM, 0);
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
861 if (connect_data->fd < 0)
14451
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
862 {
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
863 gaim_proxy_connect_data_disconnect_formatted(connect_data,
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
864 _("Unable to create socket:\n%s"), strerror(errno));
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
865 return;
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
866 }
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
867
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
868 fcntl(connect_data->fd, F_SETFL, O_NONBLOCK);
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
869 #ifndef _WIN32
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
870 fcntl(connect_data->fd, F_SETFD, FD_CLOEXEC);
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
871 #endif
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
872
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
873 if (connect(connect_data->fd, addr, addrlen) != 0)
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
874 {
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
875 if ((errno == EINPROGRESS) || (errno == EINTR)) {
14451
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
876 gaim_debug_info("proxy", "Connection in progress\n");
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
877
14451
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
878 if (connect_data->port != 80)
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
879 {
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
880 /* we need to do CONNECT first */
14451
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
881 connect_data->inpa = gaim_input_add(connect_data->fd,
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
882 GAIM_INPUT_WRITE, http_canwrite, connect_data);
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
883 }
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
884 else
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
885 {
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
886 /*
14474
adcdf5e04128 [gaim-migrate @ 17190]
Mark Doliner <mark@kingant.net>
parents: 14451
diff changeset
887 * If we're trying to connect to something running on
adcdf5e04128 [gaim-migrate @ 17190]
Mark Doliner <mark@kingant.net>
parents: 14451
diff changeset
888 * port 80 then we assume the traffic using this
adcdf5e04128 [gaim-migrate @ 17190]
Mark Doliner <mark@kingant.net>
parents: 14451
diff changeset
889 * connection is going to be HTTP traffic. If it's
adcdf5e04128 [gaim-migrate @ 17190]
Mark Doliner <mark@kingant.net>
parents: 14451
diff changeset
890 * not then this will fail (uglily). But it's good
adcdf5e04128 [gaim-migrate @ 17190]
Mark Doliner <mark@kingant.net>
parents: 14451
diff changeset
891 * to avoid using the CONNECT method because it's
adcdf5e04128 [gaim-migrate @ 17190]
Mark Doliner <mark@kingant.net>
parents: 14451
diff changeset
892 * not always allowed.
14451
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
893 */
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
894 gaim_debug_info("proxy", "HTTP proxy connection established\n");
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
895 gaim_proxy_connect_data_connected(connect_data);
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
896 }
14451
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
897 }
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
898 else
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
899 {
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
900 gaim_proxy_connect_data_disconnect(connect_data, strerror(errno));
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
901 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
902 }
14451
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
903 else
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
904 {
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
905 gaim_debug_info("proxy", "Connected immediately.\n");
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
906
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
907 http_canwrite(connect_data, connect_data->fd, GAIM_INPUT_WRITE);
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
908 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
909 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
910
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
911 static void
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
912 s4_canread(gpointer data, gint source, GaimInputCondition cond)
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
913 {
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
914 GaimProxyConnectData *connect_data = data;
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
915 guchar *buf;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
916 int len, max_read;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
917
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
918 /* This is really not going to block under normal circumstances, but to
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
919 * be correct, we deal with the unlikely scenario */
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
920
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
921 if (connect_data->read_buffer == NULL) {
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
922 connect_data->read_buf_len = 12;
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
923 connect_data->read_buffer = g_malloc(connect_data->read_buf_len);
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
924 connect_data->read_len = 0;
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
925 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
926
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
927 buf = connect_data->read_buffer + connect_data->read_len;
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
928 max_read = connect_data->read_buf_len - connect_data->read_len;
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
929
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
930 len = read(connect_data->fd, buf, max_read);
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
931
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
932 if ((len < 0 && errno == EAGAIN) || (len > 0 && len + connect_data->read_len < 4))
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
933 return;
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
934 else if (len + connect_data->read_len >= 4) {
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
935 if (connect_data->read_buffer[1] == 90) {
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
936 gaim_proxy_connect_data_connected(connect_data);
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
937 return;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
938 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
939 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
940
14451
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
941 gaim_proxy_connect_data_disconnect(connect_data, strerror(errno));
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
942 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
943
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
944 static void
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
945 s4_canwrite(gpointer data, gint source, GaimInputCondition cond)
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
946 {
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
947 unsigned char packet[9];
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
948 struct hostent *hp;
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
949 GaimProxyConnectData *connect_data = data;
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
950 socklen_t len;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
951 int error = ETIMEDOUT;
14451
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
952 int ret;
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
953
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
954 gaim_debug_info("socks4 proxy", "Connected.\n");
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
955
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
956 if (connect_data->inpa > 0)
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
957 {
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
958 gaim_input_remove(connect_data->inpa);
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
959 connect_data->inpa = 0;
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
960 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
961
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
962 len = sizeof(error);
14451
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
963 ret = getsockopt(connect_data->fd, SOL_SOCKET, SO_ERROR, &error, &len);
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
964 if ((ret != 0) || (error != 0))
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
965 {
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
966 if (ret != 0)
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
967 error = errno;
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
968 gaim_proxy_connect_data_disconnect(connect_data, strerror(error));
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
969 return;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
970 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
971
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
972 /*
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
973 * The socks4 spec doesn't include support for doing host name
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
974 * lookups by the proxy. Some socks4 servers do this via
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
975 * extensions to the protocol. Since we don't know if a
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
976 * server supports this, it would need to be implemented
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
977 * with an option, or some detection mechanism - in the
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
978 * meantime, stick with plain old SOCKS4.
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
979 */
14451
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
980 /* TODO: Use gaim_dnsquery_a() */
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
981 hp = gethostbyname(connect_data->host);
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
982 if (hp == NULL) {
14451
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
983 gaim_proxy_connect_data_disconnect_formatted(connect_data,
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
984 _("Error resolving %s"), connect_data->host);
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
985 return;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
986 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
987
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
988 packet[0] = 4;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
989 packet[1] = 1;
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
990 packet[2] = connect_data->port >> 8;
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
991 packet[3] = connect_data->port & 0xff;
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
992 packet[4] = (unsigned char)(hp->h_addr_list[0])[0];
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
993 packet[5] = (unsigned char)(hp->h_addr_list[0])[1];
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
994 packet[6] = (unsigned char)(hp->h_addr_list[0])[2];
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
995 packet[7] = (unsigned char)(hp->h_addr_list[0])[3];
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
996 packet[8] = 0;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
997
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
998 connect_data->write_buffer = g_memdup(packet, sizeof(packet));
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
999 connect_data->write_buf_len = sizeof(packet);
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1000 connect_data->written_len = 0;
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1001 connect_data->read_cb = s4_canread;
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1002
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1003 connect_data->inpa = gaim_input_add(connect_data->fd, GAIM_INPUT_WRITE, proxy_do_write, connect_data);
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1004
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1005 proxy_do_write(connect_data, connect_data->fd, cond);
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1006 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1007
14451
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1008 static void
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1009 proxy_connect_socks4(GaimProxyConnectData *connect_data, struct sockaddr *addr, socklen_t addrlen)
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1010 {
14451
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1011 gaim_debug_info("proxy",
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1012 "Connecting to %s:%d via %s:%d using SOCKS4\n",
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1013 connect_data->host, connect_data->port,
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1014 gaim_proxy_info_get_host(connect_data->gpi),
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1015 gaim_proxy_info_get_port(connect_data->gpi));
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1016
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1017 connect_data->fd = socket(addr->sa_family, SOCK_STREAM, 0);
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1018 if (connect_data->fd < 0)
14451
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1019 {
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1020 gaim_proxy_connect_data_disconnect_formatted(connect_data,
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1021 _("Unable to create socket:\n%s"), strerror(errno));
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1022 return;
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1023 }
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1024
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1025 fcntl(connect_data->fd, F_SETFL, O_NONBLOCK);
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1026 #ifndef _WIN32
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1027 fcntl(connect_data->fd, F_SETFD, FD_CLOEXEC);
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1028 #endif
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1029
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1030 if (connect(connect_data->fd, addr, addrlen) != 0)
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1031 {
14451
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1032 if ((errno == EINPROGRESS) || (errno == EINTR))
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1033 {
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1034 gaim_debug_info("proxy", "Connection in progress.\n");
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1035 connect_data->inpa = gaim_input_add(connect_data->fd,
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1036 GAIM_INPUT_WRITE, s4_canwrite, connect_data);
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1037 }
14451
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1038 else
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1039 {
14451
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1040 gaim_proxy_connect_data_disconnect(connect_data, strerror(errno));
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1041 }
14451
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1042 }
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1043 else
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1044 {
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1045 gaim_debug_info("proxy", "Connected immediately.\n");
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1046
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1047 s4_canwrite(connect_data, connect_data->fd, GAIM_INPUT_WRITE);
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1048 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1049 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1050
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1051 static void
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1052 s5_canread_again(gpointer data, gint source, GaimInputCondition cond)
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1053 {
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1054 guchar *dest, *buf;
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1055 GaimProxyConnectData *connect_data = data;
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1056 int len;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1057
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1058 if (connect_data->read_buffer == NULL) {
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1059 connect_data->read_buf_len = 512;
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1060 connect_data->read_buffer = g_malloc(connect_data->read_buf_len);
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1061 connect_data->read_len = 0;
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1062 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1063
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1064 dest = connect_data->read_buffer + connect_data->read_len;
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1065 buf = connect_data->read_buffer;
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1066
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1067 gaim_debug_info("socks5 proxy", "Able to read again.\n");
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1068
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1069 len = read(connect_data->fd, dest, (connect_data->read_buf_len - connect_data->read_len));
14451
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1070
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1071 if (len == 0)
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1072 {
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1073 gaim_proxy_connect_data_disconnect(connect_data,
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1074 _("Server closed the connection."));
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1075 return;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1076 }
14451
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1077
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1078 if (len < 0)
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1079 {
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1080 if (errno == EAGAIN)
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1081 /* No worries */
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1082 return;
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1083
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1084 /* Error! */
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1085 gaim_proxy_connect_data_disconnect_formatted(connect_data,
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1086 _("Lost connection with server:\n%s"), strerror(errno));
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1087 return;
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1088 }
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1089
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1090 connect_data->read_len += len;
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1091
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1092 if(connect_data->read_len < 4)
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1093 return;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1094
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1095 if ((buf[0] != 0x05) || (buf[1] != 0x00)) {
14451
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1096 if ((buf[0] == 0x05) && (buf[1] < 0x09)) {
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1097 gaim_debug_error("socks5 proxy", socks5errors[buf[1]]);
14451
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1098 gaim_proxy_connect_data_disconnect(connect_data,
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1099 socks5errors[buf[1]]);
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1100 } else {
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1101 gaim_debug_error("socks5 proxy", "Bad data.\n");
14451
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1102 gaim_proxy_connect_data_disconnect(connect_data,
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1103 _("Received invalid data on connection with server."));
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1104 }
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1105 return;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1106 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1107
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1108 /* Skip past BND.ADDR */
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1109 switch(buf[3]) {
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1110 case 0x01: /* the address is a version-4 IP address, with a length of 4 octets */
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1111 if(connect_data->read_len < 4 + 4)
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1112 return;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1113 buf += 4 + 4;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1114 break;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1115 case 0x03: /* the address field contains a fully-qualified domain name. The first
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1116 octet of the address field contains the number of octets of name that
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1117 follow, there is no terminating NUL octet. */
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1118 if(connect_data->read_len < 4 + 1)
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1119 return;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1120 buf += 4 + 1;
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1121 if(connect_data->read_len < 4 + 1 + buf[0])
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1122 return;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1123 buf += buf[0];
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1124 break;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1125 case 0x04: /* the address is a version-6 IP address, with a length of 16 octets */
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1126 if(connect_data->read_len < 4 + 16)
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1127 return;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1128 buf += 4 + 16;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1129 break;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1130 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1131
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1132 if(connect_data->read_len < (buf - connect_data->read_buffer) + 2)
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1133 return;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1134
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1135 /* Skip past BND.PORT */
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1136 buf += 2;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1137
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1138 gaim_proxy_connect_data_connected(connect_data);
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1139 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1140
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1141 static void
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1142 s5_sendconnect(gpointer data, int source)
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1143 {
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1144 GaimProxyConnectData *connect_data = data;
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1145 int hlen = strlen(connect_data->host);
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1146 connect_data->write_buf_len = 5 + hlen + 2;
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1147 connect_data->write_buffer = g_malloc(connect_data->write_buf_len);
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1148 connect_data->written_len = 0;
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1149
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1150 connect_data->write_buffer[0] = 0x05;
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1151 connect_data->write_buffer[1] = 0x01; /* CONNECT */
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1152 connect_data->write_buffer[2] = 0x00; /* reserved */
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1153 connect_data->write_buffer[3] = 0x03; /* address type -- host name */
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1154 connect_data->write_buffer[4] = hlen;
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1155 memcpy(connect_data->write_buffer + 5, connect_data->host, hlen);
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1156 connect_data->write_buffer[5 + hlen] = connect_data->port >> 8;
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1157 connect_data->write_buffer[5 + hlen + 1] = connect_data->port & 0xff;
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1158
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1159 connect_data->read_cb = s5_canread_again;
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1160
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1161 connect_data->inpa = gaim_input_add(connect_data->fd, GAIM_INPUT_WRITE, proxy_do_write, connect_data);
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1162 proxy_do_write(connect_data, connect_data->fd, GAIM_INPUT_WRITE);
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1163 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1164
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1165 static void
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1166 s5_readauth(gpointer data, gint source, GaimInputCondition cond)
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1167 {
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1168 GaimProxyConnectData *connect_data = data;
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1169 int len;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1170
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1171 if (connect_data->read_buffer == NULL) {
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1172 connect_data->read_buf_len = 2;
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1173 connect_data->read_buffer = g_malloc(connect_data->read_buf_len);
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1174 connect_data->read_len = 0;
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1175 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1176
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1177 gaim_debug_info("socks5 proxy", "Got auth response.\n");
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1178
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1179 len = read(connect_data->fd, connect_data->read_buffer + connect_data->read_len,
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1180 connect_data->read_buf_len - connect_data->read_len);
14451
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1181
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1182 if (len == 0)
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1183 {
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1184 gaim_proxy_connect_data_disconnect(connect_data,
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1185 _("Server closed the connection."));
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1186 return;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1187 }
14451
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1188
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1189 if (len < 0)
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1190 {
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1191 if (errno == EAGAIN)
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1192 /* No worries */
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1193 return;
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1194
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1195 /* Error! */
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1196 gaim_proxy_connect_data_disconnect_formatted(connect_data,
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1197 _("Lost connection with server:\n%s"), strerror(errno));
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1198 return;
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1199 }
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1200
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1201 connect_data->read_len += len;
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1202 if (connect_data->read_len < 2)
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1203 return;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1204
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1205 gaim_input_remove(connect_data->inpa);
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1206 connect_data->inpa = 0;
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1207
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1208 if ((connect_data->read_buffer[0] != 0x01) || (connect_data->read_buffer[1] != 0x00)) {
14451
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1209 gaim_proxy_connect_data_disconnect(connect_data,
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1210 _("Received invalid data on connection with server."));
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1211 return;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1212 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1213
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1214 g_free(connect_data->read_buffer);
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1215 connect_data->read_buffer = NULL;
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1216
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1217 s5_sendconnect(connect_data, connect_data->fd);
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1218 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1219
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1220 static void
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1221 hmacmd5_chap(const unsigned char * challenge, int challen, const char * passwd, unsigned char * response)
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1222 {
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1223 GaimCipher *cipher;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1224 GaimCipherContext *ctx;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1225 int i;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1226 unsigned char Kxoripad[65];
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1227 unsigned char Kxoropad[65];
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1228 int pwlen;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1229
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1230 cipher = gaim_ciphers_find_cipher("md5");
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1231 ctx = gaim_cipher_context_new(cipher, NULL);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1232
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1233 memset(Kxoripad,0,sizeof(Kxoripad));
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1234 memset(Kxoropad,0,sizeof(Kxoropad));
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1235
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1236 pwlen=strlen(passwd);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1237 if (pwlen>64) {
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1238 gaim_cipher_context_append(ctx, (const guchar *)passwd, strlen(passwd));
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1239 gaim_cipher_context_digest(ctx, sizeof(Kxoripad), Kxoripad, NULL);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1240 pwlen=16;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1241 } else {
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1242 memcpy(Kxoripad, passwd, pwlen);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1243 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1244 memcpy(Kxoropad,Kxoripad,pwlen);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1245
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1246 for (i=0;i<64;i++) {
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1247 Kxoripad[i]^=0x36;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1248 Kxoropad[i]^=0x5c;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1249 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1250
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1251 gaim_cipher_context_reset(ctx, NULL);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1252 gaim_cipher_context_append(ctx, Kxoripad, 64);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1253 gaim_cipher_context_append(ctx, challenge, challen);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1254 gaim_cipher_context_digest(ctx, sizeof(Kxoripad), Kxoripad, NULL);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1255
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1256 gaim_cipher_context_reset(ctx, NULL);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1257 gaim_cipher_context_append(ctx, Kxoropad, 64);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1258 gaim_cipher_context_append(ctx, Kxoripad, 16);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1259 gaim_cipher_context_digest(ctx, 16, response, NULL);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1260
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1261 gaim_cipher_context_destroy(ctx);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1262 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1263
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1264 static void
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1265 s5_readchap(gpointer data, gint source, GaimInputCondition cond)
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1266 {
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1267 guchar *cmdbuf, *buf;
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1268 GaimProxyConnectData *connect_data = data;
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1269 int len, navas, currentav;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1270
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1271 gaim_debug(GAIM_DEBUG_INFO, "socks5 proxy", "Got CHAP response.\n");
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1272
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1273 if (connect_data->read_buffer == NULL) {
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1274 connect_data->read_buf_len = 20;
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1275 connect_data->read_buffer = g_malloc(connect_data->read_buf_len);
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1276 connect_data->read_len = 0;
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1277 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1278
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1279 len = read(connect_data->fd, connect_data->read_buffer + connect_data->read_len,
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1280 connect_data->read_buf_len - connect_data->read_len);
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1281
14451
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1282 if (len == 0)
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1283 {
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1284 gaim_proxy_connect_data_disconnect(connect_data,
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1285 _("Server closed the connection."));
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1286 return;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1287 }
14451
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1288
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1289 if (len < 0)
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1290 {
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1291 if (errno == EAGAIN)
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1292 /* No worries */
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1293 return;
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1294
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1295 /* Error! */
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1296 gaim_proxy_connect_data_disconnect_formatted(connect_data,
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1297 _("Lost connection with server:\n%s"), strerror(errno));
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1298 return;
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1299 }
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1300
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1301 connect_data->read_len += len;
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1302 if (connect_data->read_len < 2)
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1303 return;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1304
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1305 cmdbuf = connect_data->read_buffer;
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1306
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1307 if (*cmdbuf != 0x01) {
14451
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1308 gaim_proxy_connect_data_disconnect(connect_data,
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1309 _("Received invalid data on connection with server."));
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1310 return;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1311 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1312 cmdbuf++;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1313
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1314 navas = *cmdbuf;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1315 cmdbuf++;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1316
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1317 for (currentav = 0; currentav < navas; currentav++) {
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1318 if (connect_data->read_len - (cmdbuf - connect_data->read_buffer) < 2)
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1319 return;
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1320 if (connect_data->read_len - (cmdbuf - connect_data->read_buffer) < cmdbuf[1])
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1321 return;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1322 buf = cmdbuf + 2;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1323 switch (cmdbuf[0]) {
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1324 case 0x00:
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1325 /* Did auth work? */
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1326 if (buf[0] == 0x00) {
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1327 gaim_input_remove(connect_data->inpa);
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1328 connect_data->inpa = 0;
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1329 g_free(connect_data->read_buffer);
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1330 connect_data->read_buffer = NULL;
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1331 /* Success */
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1332 s5_sendconnect(connect_data, connect_data->fd);
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1333 return;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1334 } else {
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1335 /* Failure */
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1336 gaim_debug_warning("proxy",
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1337 "socks5 CHAP authentication "
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1338 "failed. Disconnecting...");
14451
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1339 gaim_proxy_connect_data_disconnect(connect_data,
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1340 _("Authentication failed"));
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1341 return;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1342 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1343 break;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1344 case 0x03:
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1345 /* Server wants our credentials */
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1346
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1347 connect_data->write_buf_len = 16 + 4;
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1348 connect_data->write_buffer = g_malloc(connect_data->write_buf_len);
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1349 connect_data->written_len = 0;
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1350
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1351 hmacmd5_chap(buf, cmdbuf[1],
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1352 gaim_proxy_info_get_password(connect_data->gpi),
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1353 connect_data->write_buffer + 4);
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1354 connect_data->write_buffer[0] = 0x01;
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1355 connect_data->write_buffer[1] = 0x01;
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1356 connect_data->write_buffer[2] = 0x04;
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1357 connect_data->write_buffer[3] = 0x10;
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1358
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1359 gaim_input_remove(connect_data->inpa);
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1360 g_free(connect_data->read_buffer);
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1361 connect_data->read_buffer = NULL;
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1362
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1363 connect_data->read_cb = s5_readchap;
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1364
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1365 connect_data->inpa = gaim_input_add(connect_data->fd,
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1366 GAIM_INPUT_WRITE, proxy_do_write, connect_data);
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1367
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1368 proxy_do_write(connect_data, connect_data->fd, GAIM_INPUT_WRITE);
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1369 break;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1370 case 0x11:
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1371 /* Server wants to select an algorithm */
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1372 if (buf[0] != 0x85) {
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1373 /* Only currently support HMAC-MD5 */
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1374 gaim_debug_warning("proxy",
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1375 "Server tried to select an "
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1376 "algorithm that we did not advertise "
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1377 "as supporting. This is a violation "
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1378 "of the socks5 CHAP specification. "
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1379 "Disconnecting...");
14451
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1380 gaim_proxy_connect_data_disconnect(connect_data,
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1381 _("Received invalid data on connection with server."));
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1382 return;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1383 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1384 break;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1385 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1386 cmdbuf = buf + cmdbuf[1];
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1387 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1388 /* Fell through. We ran out of CHAP events to process, but haven't
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1389 * succeeded or failed authentication - there may be more to come.
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1390 * If this is the case, come straight back here. */
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1391 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1392
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1393 static void
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1394 s5_canread(gpointer data, gint source, GaimInputCondition cond)
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1395 {
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1396 GaimProxyConnectData *connect_data = data;
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1397 int len;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1398
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1399 if (connect_data->read_buffer == NULL) {
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1400 connect_data->read_buf_len = 2;
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1401 connect_data->read_buffer = g_malloc(connect_data->read_buf_len);
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1402 connect_data->read_len = 0;
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1403 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1404
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1405 gaim_debug_info("socks5 proxy", "Able to read.\n");
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1406
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1407 len = read(connect_data->fd, connect_data->read_buffer + connect_data->read_len,
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1408 connect_data->read_buf_len - connect_data->read_len);
14451
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1409
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1410 if (len == 0)
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1411 {
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1412 gaim_proxy_connect_data_disconnect(connect_data,
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1413 _("Server closed the connection."));
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1414 return;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1415 }
14451
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1416
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1417 if (len < 0)
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1418 {
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1419 if (errno == EAGAIN)
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1420 /* No worries */
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1421 return;
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1422
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1423 /* Error! */
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1424 gaim_proxy_connect_data_disconnect_formatted(connect_data,
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1425 _("Lost connection with server:\n%s"), strerror(errno));
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1426 return;
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1427 }
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1428
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1429 connect_data->read_len += len;
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1430 if (connect_data->read_len < 2)
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1431 return;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1432
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1433 gaim_input_remove(connect_data->inpa);
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1434 connect_data->inpa = 0;
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1435
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1436 if ((connect_data->read_buffer[0] != 0x05) || (connect_data->read_buffer[1] == 0xff)) {
14451
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1437 gaim_proxy_connect_data_disconnect(connect_data,
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1438 _("Received invalid data on connection with server."));
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1439 return;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1440 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1441
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1442 if (connect_data->read_buffer[1] == 0x02) {
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1443 gsize i, j;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1444 const char *u, *p;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1445
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1446 u = gaim_proxy_info_get_username(connect_data->gpi);
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1447 p = gaim_proxy_info_get_password(connect_data->gpi);
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1448
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1449 i = (u == NULL) ? 0 : strlen(u);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1450 j = (p == NULL) ? 0 : strlen(p);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1451
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1452 connect_data->write_buf_len = 1 + 1 + i + 1 + j;
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1453 connect_data->write_buffer = g_malloc(connect_data->write_buf_len);
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1454 connect_data->written_len = 0;
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1455
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1456 connect_data->write_buffer[0] = 0x01; /* version 1 */
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1457 connect_data->write_buffer[1] = i;
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1458 if (u != NULL)
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1459 memcpy(connect_data->write_buffer + 2, u, i);
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1460 connect_data->write_buffer[2 + i] = j;
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1461 if (p != NULL)
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1462 memcpy(connect_data->write_buffer + 2 + i + 1, p, j);
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1463
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1464 g_free(connect_data->read_buffer);
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1465 connect_data->read_buffer = NULL;
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1466
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1467 connect_data->read_cb = s5_readauth;
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1468
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1469 connect_data->inpa = gaim_input_add(connect_data->fd, GAIM_INPUT_WRITE,
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1470 proxy_do_write, connect_data);
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1471
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1472 proxy_do_write(connect_data, connect_data->fd, GAIM_INPUT_WRITE);
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1473
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1474 return;
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1475 } else if (connect_data->read_buffer[1] == 0x03) {
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1476 gsize userlen;
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1477 userlen = strlen(gaim_proxy_info_get_username(connect_data->gpi));
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1478
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1479 connect_data->write_buf_len = 7 + userlen;
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1480 connect_data->write_buffer = g_malloc(connect_data->write_buf_len);
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1481 connect_data->written_len = 0;
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1482
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1483 connect_data->write_buffer[0] = 0x01;
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1484 connect_data->write_buffer[1] = 0x02;
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1485 connect_data->write_buffer[2] = 0x11;
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1486 connect_data->write_buffer[3] = 0x01;
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1487 connect_data->write_buffer[4] = 0x85;
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1488 connect_data->write_buffer[5] = 0x02;
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1489 connect_data->write_buffer[6] = userlen;
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1490 memcpy(connect_data->write_buffer + 7,
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1491 gaim_proxy_info_get_username(connect_data->gpi), userlen);
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1492
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1493 g_free(connect_data->read_buffer);
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1494 connect_data->read_buffer = NULL;
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1495
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1496 connect_data->read_cb = s5_readchap;
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1497
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1498 connect_data->inpa = gaim_input_add(connect_data->fd, GAIM_INPUT_WRITE,
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1499 proxy_do_write, connect_data);
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1500
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1501 proxy_do_write(connect_data, connect_data->fd, GAIM_INPUT_WRITE);
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1502
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1503 return;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1504 } else {
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1505 g_free(connect_data->read_buffer);
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1506 connect_data->read_buffer = NULL;
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1507
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1508 s5_sendconnect(connect_data, connect_data->fd);
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1509 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1510 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1511
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1512 static void
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1513 s5_canwrite(gpointer data, gint source, GaimInputCondition cond)
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1514 {
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1515 unsigned char buf[5];
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1516 int i;
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1517 GaimProxyConnectData *connect_data = data;
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1518 socklen_t len;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1519 int error = ETIMEDOUT;
14451
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1520 int ret;
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1521
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1522 gaim_debug_info("socks5 proxy", "Connected.\n");
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1523
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1524 if (connect_data->inpa > 0)
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1525 {
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1526 gaim_input_remove(connect_data->inpa);
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1527 connect_data->inpa = 0;
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1528 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1529
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1530 len = sizeof(error);
14451
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1531 ret = getsockopt(connect_data->fd, SOL_SOCKET, SO_ERROR, &error, &len);
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1532 if ((ret != 0) || (error != 0))
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1533 {
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1534 if (ret != 0)
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1535 error = errno;
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1536 gaim_proxy_connect_data_disconnect(connect_data, strerror(error));
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1537 return;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1538 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1539
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1540 i = 0;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1541 buf[0] = 0x05; /* SOCKS version 5 */
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1542
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1543 if (gaim_proxy_info_get_username(connect_data->gpi) != NULL) {
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1544 buf[1] = 0x03; /* three methods */
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1545 buf[2] = 0x00; /* no authentication */
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1546 buf[3] = 0x03; /* CHAP authentication */
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1547 buf[4] = 0x02; /* username/password authentication */
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1548 i = 5;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1549 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1550 else {
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1551 buf[1] = 0x01;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1552 buf[2] = 0x00;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1553 i = 3;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1554 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1555
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1556 connect_data->write_buf_len = i;
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1557 connect_data->write_buffer = g_malloc(connect_data->write_buf_len);
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1558 memcpy(connect_data->write_buffer, buf, i);
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1559
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1560 connect_data->read_cb = s5_canread;
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1561
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1562 connect_data->inpa = gaim_input_add(connect_data->fd, GAIM_INPUT_WRITE, proxy_do_write, connect_data);
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1563 proxy_do_write(connect_data, connect_data->fd, GAIM_INPUT_WRITE);
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1564 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1565
14451
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1566 static void
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1567 proxy_connect_socks5(GaimProxyConnectData *connect_data, struct sockaddr *addr, socklen_t addrlen)
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1568 {
14451
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1569 gaim_debug_info("proxy",
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1570 "Connecting to %s:%d via %s:%d using SOCKS5\n",
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1571 connect_data->host, connect_data->port,
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1572 gaim_proxy_info_get_host(connect_data->gpi),
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1573 gaim_proxy_info_get_port(connect_data->gpi));
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1574
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1575 connect_data->fd = socket(addr->sa_family, SOCK_STREAM, 0);
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1576 if (connect_data->fd < 0)
14451
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1577 {
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1578 gaim_proxy_connect_data_disconnect_formatted(connect_data,
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1579 _("Unable to create socket:\n%s"), strerror(errno));
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1580 return;
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1581 }
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1582
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1583 fcntl(connect_data->fd, F_SETFL, O_NONBLOCK);
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1584 #ifndef _WIN32
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1585 fcntl(connect_data->fd, F_SETFD, FD_CLOEXEC);
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1586 #endif
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1587
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1588 if (connect(connect_data->fd, addr, addrlen) != 0)
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1589 {
14451
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1590 if ((errno == EINPROGRESS) || (errno == EINTR))
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1591 {
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1592 gaim_debug_info("socks5 proxy", "Connection in progress\n");
14451
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1593 connect_data->inpa = gaim_input_add(connect_data->fd,
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1594 GAIM_INPUT_WRITE, s5_canwrite, connect_data);
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1595 }
14451
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1596 else
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1597 {
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1598 gaim_proxy_connect_data_disconnect(connect_data, strerror(errno));
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1599 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1600 }
14451
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1601 else
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1602 {
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1603 gaim_debug_info("proxy", "Connected immediately.\n");
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1604
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1605 s5_canwrite(connect_data, connect_data->fd, GAIM_INPUT_WRITE);
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1606 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1607 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1608
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1609 /**
14451
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1610 * This function attempts to connect to the next IP address in the list
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1611 * of IP addresses returned to us by gaim_dnsquery_a() and attemps
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1612 * to connect to each one. This is called after the hostname is
14451
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1613 * resolved, and each time a connection attempt fails (assuming there
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1614 * is another IP address to try).
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1615 */
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1616 static void try_connect(GaimProxyConnectData *connect_data)
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1617 {
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1618 size_t addrlen;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1619 struct sockaddr *addr;
14903
6334d1b51252 [gaim-migrate @ 17675]
Mark Doliner <mark@kingant.net>
parents: 14837
diff changeset
1620 char ipaddr[INET6_ADDRSTRLEN];
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1621
14451
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1622 addrlen = GPOINTER_TO_INT(connect_data->hosts->data);
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1623 connect_data->hosts = g_slist_remove(connect_data->hosts, connect_data->hosts->data);
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1624 addr = connect_data->hosts->data;
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1625 connect_data->hosts = g_slist_remove(connect_data->hosts, connect_data->hosts->data);
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1626
14903
6334d1b51252 [gaim-migrate @ 17675]
Mark Doliner <mark@kingant.net>
parents: 14837
diff changeset
1627 inet_ntop(addr->sa_family, &((struct sockaddr_in *)addr)->sin_addr,
6334d1b51252 [gaim-migrate @ 17675]
Mark Doliner <mark@kingant.net>
parents: 14837
diff changeset
1628 ipaddr, sizeof(ipaddr));
6334d1b51252 [gaim-migrate @ 17675]
Mark Doliner <mark@kingant.net>
parents: 14837
diff changeset
1629 gaim_debug_info("proxy", "Attempting connection to %s\n", ipaddr);
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1630
14451
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1631 switch (gaim_proxy_info_get_type(connect_data->gpi)) {
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1632 case GAIM_PROXY_NONE:
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1633 proxy_connect_none(connect_data, addr, addrlen);
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1634 break;
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1635
14451
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1636 case GAIM_PROXY_HTTP:
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1637 proxy_connect_http(connect_data, addr, addrlen);
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1638 break;
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1639
14451
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1640 case GAIM_PROXY_SOCKS4:
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1641 proxy_connect_socks4(connect_data, addr, addrlen);
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1642 break;
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1643
14451
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1644 case GAIM_PROXY_SOCKS5:
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1645 proxy_connect_socks5(connect_data, addr, addrlen);
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1646 break;
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1647
14451
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1648 case GAIM_PROXY_USE_ENVVAR:
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1649 proxy_connect_http(connect_data, addr, addrlen);
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1650 break;
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1651
14451
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1652 default:
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1653 break;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1654 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1655
14451
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1656 g_free(addr);
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1657 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1658
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1659 static void
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1660 connection_host_resolved(GSList *hosts, gpointer data,
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1661 const char *error_message)
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1662 {
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1663 GaimProxyConnectData *connect_data;
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1664
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1665 connect_data = data;
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1666 connect_data->query_data = NULL;
14238
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
1667
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1668 if (error_message != NULL)
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1669 {
14451
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1670 gaim_proxy_connect_data_disconnect(connect_data, error_message);
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1671 return;
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1672 }
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1673
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1674 if (hosts == NULL)
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1675 {
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1676 gaim_proxy_connect_data_disconnect(connect_data, _("Could not resolve host name"));
14238
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
1677 return;
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1678 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1679
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1680 connect_data->hosts = hosts;
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1681
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1682 try_connect(connect_data);
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1683 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1684
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1685 GaimProxyInfo *
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1686 gaim_proxy_get_setup(GaimAccount *account)
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1687 {
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1688 GaimProxyInfo *gpi;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1689 const gchar *tmp;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1690
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1691 if (account && gaim_account_get_proxy_info(account) != NULL)
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1692 gpi = gaim_account_get_proxy_info(account);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1693 else if (gaim_running_gnome())
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1694 gpi = gaim_gnome_proxy_get_info();
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1695 else
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1696 gpi = gaim_global_proxy_get_info();
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1697
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1698 if (gaim_proxy_info_get_type(gpi) == GAIM_PROXY_USE_ENVVAR) {
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1699 if ((tmp = g_getenv("HTTP_PROXY")) != NULL ||
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1700 (tmp = g_getenv("http_proxy")) != NULL ||
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1701 (tmp = g_getenv("HTTPPROXY")) != NULL) {
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1702 char *proxyhost,*proxypath,*proxyuser,*proxypasswd;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1703 int proxyport;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1704
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1705 /* http_proxy-format:
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1706 * export http_proxy="http://user:passwd@your.proxy.server:port/"
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1707 */
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1708 if(gaim_url_parse(tmp, &proxyhost, &proxyport, &proxypath, &proxyuser, &proxypasswd)) {
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1709 gaim_proxy_info_set_host(gpi, proxyhost);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1710 g_free(proxyhost);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1711 g_free(proxypath);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1712 if (proxyuser != NULL) {
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1713 gaim_proxy_info_set_username(gpi, proxyuser);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1714 g_free(proxyuser);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1715 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1716 if (proxypasswd != NULL) {
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1717 gaim_proxy_info_set_password(gpi, proxypasswd);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1718 g_free(proxypasswd);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1719 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1720
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1721 /* only for backward compatibility */
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1722 if (proxyport == 80 &&
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1723 ((tmp = g_getenv("HTTP_PROXY_PORT")) != NULL ||
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1724 (tmp = g_getenv("http_proxy_port")) != NULL ||
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1725 (tmp = g_getenv("HTTPPROXYPORT")) != NULL))
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1726 proxyport = atoi(tmp);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1727
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1728 gaim_proxy_info_set_port(gpi, proxyport);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1729 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1730 } else {
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1731 /* no proxy environment variable found, don't use a proxy */
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1732 gaim_debug_info("proxy", "No environment settings found, not using a proxy\n");
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1733 gaim_proxy_info_set_type(gpi, GAIM_PROXY_NONE);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1734 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1735
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1736 /* XXX: Do we want to skip this step if user/password were part of url? */
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1737 if ((tmp = g_getenv("HTTP_PROXY_USER")) != NULL ||
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1738 (tmp = g_getenv("http_proxy_user")) != NULL ||
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1739 (tmp = g_getenv("HTTPPROXYUSER")) != NULL)
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1740 gaim_proxy_info_set_username(gpi, tmp);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1741
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1742 if ((tmp = g_getenv("HTTP_PROXY_PASS")) != NULL ||
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1743 (tmp = g_getenv("http_proxy_pass")) != NULL ||
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1744 (tmp = g_getenv("HTTPPROXYPASS")) != NULL)
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1745 gaim_proxy_info_set_password(gpi, tmp);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1746 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1747
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1748 return gpi;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1749 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1750
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1751 GaimProxyConnectData *
14837
118fd0dc5b6e [gaim-migrate @ 17606]
Mark Doliner <mark@kingant.net>
parents: 14474
diff changeset
1752 gaim_proxy_connect(void *handle, GaimAccount *account,
118fd0dc5b6e [gaim-migrate @ 17606]
Mark Doliner <mark@kingant.net>
parents: 14474
diff changeset
1753 const char *host, int port,
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1754 GaimProxyConnectFunction connect_cb, gpointer data)
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1755 {
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1756 const char *connecthost = host;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1757 int connectport = port;
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1758 GaimProxyConnectData *connect_data;
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1759
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1760 g_return_val_if_fail(host != NULL, NULL);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1761 g_return_val_if_fail(port > 0, NULL);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1762 g_return_val_if_fail(connect_cb != NULL, NULL);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1763
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1764 connect_data = g_new0(GaimProxyConnectData, 1);
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1765 connect_data->fd = -1;
14837
118fd0dc5b6e [gaim-migrate @ 17606]
Mark Doliner <mark@kingant.net>
parents: 14474
diff changeset
1766 connect_data->handle = handle;
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1767 connect_data->connect_cb = connect_cb;
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1768 connect_data->data = data;
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1769 connect_data->host = g_strdup(host);
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1770 connect_data->port = port;
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1771 connect_data->gpi = gaim_proxy_get_setup(account);
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1772
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1773 if ((gaim_proxy_info_get_type(connect_data->gpi) != GAIM_PROXY_NONE) &&
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1774 (gaim_proxy_info_get_host(connect_data->gpi) == NULL ||
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1775 gaim_proxy_info_get_port(connect_data->gpi) <= 0)) {
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1776
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1777 gaim_notify_error(NULL, NULL, _("Invalid proxy settings"), _("Either the host name or port number specified for your given proxy type is invalid."));
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1778 gaim_proxy_connect_data_destroy(connect_data);
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1779 return NULL;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1780 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1781
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1782 switch (gaim_proxy_info_get_type(connect_data->gpi))
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1783 {
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1784 case GAIM_PROXY_NONE:
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1785 break;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1786
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1787 case GAIM_PROXY_HTTP:
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1788 case GAIM_PROXY_SOCKS4:
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1789 case GAIM_PROXY_SOCKS5:
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1790 case GAIM_PROXY_USE_ENVVAR:
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1791 connecthost = gaim_proxy_info_get_host(connect_data->gpi);
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1792 connectport = gaim_proxy_info_get_port(connect_data->gpi);
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1793 break;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1794
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1795 default:
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1796 gaim_proxy_connect_data_destroy(connect_data);
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1797 return NULL;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1798 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1799
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1800 connect_data->query_data = gaim_dnsquery_a(connecthost,
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1801 connectport, connection_host_resolved, connect_data);
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1802 if (connect_data->query_data == NULL)
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1803 {
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1804 gaim_proxy_connect_data_destroy(connect_data);
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1805 return NULL;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1806 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1807
14837
118fd0dc5b6e [gaim-migrate @ 17606]
Mark Doliner <mark@kingant.net>
parents: 14474
diff changeset
1808 handles = g_slist_prepend(handles, connect_data);
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1809
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1810 return connect_data;
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1811 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1812
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1813 /*
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1814 * Combine some of this code with gaim_proxy_connect()
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1815 */
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1816 GaimProxyConnectData *
14837
118fd0dc5b6e [gaim-migrate @ 17606]
Mark Doliner <mark@kingant.net>
parents: 14474
diff changeset
1817 gaim_proxy_connect_socks5(void *handle, GaimProxyInfo *gpi,
118fd0dc5b6e [gaim-migrate @ 17606]
Mark Doliner <mark@kingant.net>
parents: 14474
diff changeset
1818 const char *host, int port,
118fd0dc5b6e [gaim-migrate @ 17606]
Mark Doliner <mark@kingant.net>
parents: 14474
diff changeset
1819 GaimProxyConnectFunction connect_cb,
118fd0dc5b6e [gaim-migrate @ 17606]
Mark Doliner <mark@kingant.net>
parents: 14474
diff changeset
1820 gpointer data)
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1821 {
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1822 GaimProxyConnectData *connect_data;
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1823
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1824 g_return_val_if_fail(host != NULL, NULL);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1825 g_return_val_if_fail(port > 0, NULL);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1826 g_return_val_if_fail(connect_cb != NULL, NULL);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1827
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1828 connect_data = g_new0(GaimProxyConnectData, 1);
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1829 connect_data->fd = -1;
14837
118fd0dc5b6e [gaim-migrate @ 17606]
Mark Doliner <mark@kingant.net>
parents: 14474
diff changeset
1830 connect_data->handle = handle;
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1831 connect_data->connect_cb = connect_cb;
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1832 connect_data->data = data;
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1833 connect_data->host = g_strdup(host);
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1834 connect_data->port = port;
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1835 connect_data->gpi = gpi;
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1836
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1837 connect_data->query_data =
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1838 gaim_dnsquery_a(gaim_proxy_info_get_host(gpi),
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1839 gaim_proxy_info_get_port(gpi),
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1840 connection_host_resolved, connect_data);
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1841 if (connect_data->query_data == NULL)
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1842 {
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1843 gaim_proxy_connect_data_destroy(connect_data);
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1844 return NULL;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1845 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1846
14837
118fd0dc5b6e [gaim-migrate @ 17606]
Mark Doliner <mark@kingant.net>
parents: 14474
diff changeset
1847 handles = g_slist_prepend(handles, connect_data);
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1848
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1849 return connect_data;
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1850 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1851
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1852 void
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1853 gaim_proxy_connect_cancel(GaimProxyConnectData *connect_data)
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1854 {
14451
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1855 gaim_proxy_connect_data_disconnect(connect_data, NULL);
14262
baff095b146c [gaim-migrate @ 16944]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
1856 gaim_proxy_connect_data_destroy(connect_data);
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1857 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1858
14837
118fd0dc5b6e [gaim-migrate @ 17606]
Mark Doliner <mark@kingant.net>
parents: 14474
diff changeset
1859 void
118fd0dc5b6e [gaim-migrate @ 17606]
Mark Doliner <mark@kingant.net>
parents: 14474
diff changeset
1860 gaim_proxy_connect_cancel_with_handle(void *handle)
118fd0dc5b6e [gaim-migrate @ 17606]
Mark Doliner <mark@kingant.net>
parents: 14474
diff changeset
1861 {
118fd0dc5b6e [gaim-migrate @ 17606]
Mark Doliner <mark@kingant.net>
parents: 14474
diff changeset
1862 GSList *l, *l_next;
118fd0dc5b6e [gaim-migrate @ 17606]
Mark Doliner <mark@kingant.net>
parents: 14474
diff changeset
1863
118fd0dc5b6e [gaim-migrate @ 17606]
Mark Doliner <mark@kingant.net>
parents: 14474
diff changeset
1864 for (l = handles; l != NULL; l = l_next) {
118fd0dc5b6e [gaim-migrate @ 17606]
Mark Doliner <mark@kingant.net>
parents: 14474
diff changeset
1865 GaimProxyConnectData *connect_data = l->data;
118fd0dc5b6e [gaim-migrate @ 17606]
Mark Doliner <mark@kingant.net>
parents: 14474
diff changeset
1866
118fd0dc5b6e [gaim-migrate @ 17606]
Mark Doliner <mark@kingant.net>
parents: 14474
diff changeset
1867 l_next = l->next;
118fd0dc5b6e [gaim-migrate @ 17606]
Mark Doliner <mark@kingant.net>
parents: 14474
diff changeset
1868
118fd0dc5b6e [gaim-migrate @ 17606]
Mark Doliner <mark@kingant.net>
parents: 14474
diff changeset
1869 if (connect_data->handle == handle)
118fd0dc5b6e [gaim-migrate @ 17606]
Mark Doliner <mark@kingant.net>
parents: 14474
diff changeset
1870 gaim_proxy_connect_cancel(connect_data);
118fd0dc5b6e [gaim-migrate @ 17606]
Mark Doliner <mark@kingant.net>
parents: 14474
diff changeset
1871 }
118fd0dc5b6e [gaim-migrate @ 17606]
Mark Doliner <mark@kingant.net>
parents: 14474
diff changeset
1872 }
118fd0dc5b6e [gaim-migrate @ 17606]
Mark Doliner <mark@kingant.net>
parents: 14474
diff changeset
1873
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1874 static void
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1875 proxy_pref_cb(const char *name, GaimPrefType type,
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1876 gconstpointer value, gpointer data)
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1877 {
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1878 GaimProxyInfo *info = gaim_global_proxy_get_info();
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1879
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1880 if (!strcmp(name, "/core/proxy/type")) {
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1881 int proxytype;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1882 const char *type = value;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1883
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1884 if (!strcmp(type, "none"))
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1885 proxytype = GAIM_PROXY_NONE;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1886 else if (!strcmp(type, "http"))
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1887 proxytype = GAIM_PROXY_HTTP;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1888 else if (!strcmp(type, "socks4"))
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1889 proxytype = GAIM_PROXY_SOCKS4;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1890 else if (!strcmp(type, "socks5"))
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1891 proxytype = GAIM_PROXY_SOCKS5;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1892 else if (!strcmp(type, "envvar"))
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1893 proxytype = GAIM_PROXY_USE_ENVVAR;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1894 else
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1895 proxytype = -1;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1896
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1897 gaim_proxy_info_set_type(info, proxytype);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1898 } else if (!strcmp(name, "/core/proxy/host"))
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1899 gaim_proxy_info_set_host(info, value);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1900 else if (!strcmp(name, "/core/proxy/port"))
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1901 gaim_proxy_info_set_port(info, GPOINTER_TO_INT(value));
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1902 else if (!strcmp(name, "/core/proxy/username"))
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1903 gaim_proxy_info_set_username(info, value);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1904 else if (!strcmp(name, "/core/proxy/password"))
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1905 gaim_proxy_info_set_password(info, value);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1906 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1907
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1908 void *
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1909 gaim_proxy_get_handle()
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1910 {
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1911 static int handle;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1912
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1913 return &handle;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1914 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1915
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1916 void
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1917 gaim_proxy_init(void)
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1918 {
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1919 void *handle;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1920
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1921 /* Initialize a default proxy info struct. */
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1922 global_proxy_info = gaim_proxy_info_new();
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1923
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1924 /* Proxy */
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1925 gaim_prefs_add_none("/core/proxy");
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1926 gaim_prefs_add_string("/core/proxy/type", "none");
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1927 gaim_prefs_add_string("/core/proxy/host", "");
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1928 gaim_prefs_add_int("/core/proxy/port", 0);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1929 gaim_prefs_add_string("/core/proxy/username", "");
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1930 gaim_prefs_add_string("/core/proxy/password", "");
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1931
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1932 /* Setup callbacks for the preferences. */
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1933 handle = gaim_proxy_get_handle();
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1934 gaim_prefs_connect_callback(handle, "/core/proxy/type", proxy_pref_cb,
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1935 NULL);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1936 gaim_prefs_connect_callback(handle, "/core/proxy/host", proxy_pref_cb,
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1937 NULL);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1938 gaim_prefs_connect_callback(handle, "/core/proxy/port", proxy_pref_cb,
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1939 NULL);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1940 gaim_prefs_connect_callback(handle, "/core/proxy/username",
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1941 proxy_pref_cb, NULL);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1942 gaim_prefs_connect_callback(handle, "/core/proxy/password",
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1943 proxy_pref_cb, NULL);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1944 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1945
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1946 void
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1947 gaim_proxy_uninit(void)
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1948 {
14837
118fd0dc5b6e [gaim-migrate @ 17606]
Mark Doliner <mark@kingant.net>
parents: 14474
diff changeset
1949 while (handles != NULL)
14451
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1950 {
14837
118fd0dc5b6e [gaim-migrate @ 17606]
Mark Doliner <mark@kingant.net>
parents: 14474
diff changeset
1951 gaim_proxy_connect_data_disconnect(handles->data, NULL);
118fd0dc5b6e [gaim-migrate @ 17606]
Mark Doliner <mark@kingant.net>
parents: 14474
diff changeset
1952 gaim_proxy_connect_data_destroy(handles->data);
14451
8bc97389bdb2 [gaim-migrate @ 17165]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
1953 }
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1954 }