annotate libgaim/proxy.c @ 14545:0a7ce7c8faa8

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