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