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