Mercurial > pidgin
annotate src/proxy.c @ 14103:eec0c7fd8529
[gaim-migrate @ 16734]
gaim_proxy_connect()ion attemps can now be canceled. So there
is no longer a need to do that GAIM_CONNECTION_IS_VALID()
crap at the top of gaim_proxy_connect() callback functions.
All of the callers of gaim_proxy_connect() still need to be
updated, though.
committer: Tailor Script <tailor@pidgin.im>
| author | Mark Doliner <mark@kingant.net> |
|---|---|
| date | Sun, 13 Aug 2006 08:38:02 +0000 |
| parents | 7b030f6ed1c3 |
| children | 7a205b430d19 |
| rev | line source |
|---|---|
|
5681
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
1 /** |
|
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
2 * @file proxy.c Proxy API |
|
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
3 * @ingroup core |
|
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
4 * |
| 1 | 5 * gaim |
| 6 * | |
| 8046 | 7 * Gaim is the legal property of its developers, whose names are too numerous |
| 8 * to list here. Please refer to the COPYRIGHT file distributed with this | |
| 9 * source distribution. | |
| 1 | 10 * |
| 11 * This program is free software; you can redistribute it and/or modify | |
| 12 * it under the terms of the GNU General Public License as published by | |
| 13 * the Free Software Foundation; either version 2 of the License, or | |
| 14 * (at your option) any later version. | |
| 15 * | |
| 16 * This program is distributed in the hope that it will be useful, | |
| 17 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 19 * GNU General Public License for more details. | |
| 20 * | |
| 21 * You should have received a copy of the GNU General Public License | |
| 22 * along with this program; if not, write to the Free Software | |
| 23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 24 * | |
| 25 */ | |
| 26 | |
| 27 /* this is a little piece of code to handle proxy connection */ | |
| 28 /* it is intended to : 1st handle http proxy, using the CONNECT command | |
| 6856 | 29 , 2nd provide an easy way to add socks support |
| 30 , 3rd draw women to it like flies to honey */ | |
| 1 | 31 |
|
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5681
diff
changeset
|
32 #include "internal.h" |
|
10684
72a5babfa8b4
[gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
10626
diff
changeset
|
33 #include "cipher.h" |
|
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5681
diff
changeset
|
34 #include "debug.h" |
| 6621 | 35 #include "notify.h" |
| 12391 | 36 #include "ntlm.h" |
|
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5681
diff
changeset
|
37 #include "prefs.h" |
| 1 | 38 #include "proxy.h" |
|
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5681
diff
changeset
|
39 #include "util.h" |
| 3630 | 40 |
| 14090 | 41 struct _GaimProxyConnectInfo { |
| 14089 | 42 GaimProxyConnectFunction connect_cb; |
| 43 GaimProxyErrorFunction error_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; |
| 14097 | 50 |
| 51 /** | |
| 52 * This contains alternating length/char* values. The char* | |
| 53 * values need to be freed when removed from the linked list. | |
| 54 */ | |
| 9129 | 55 GSList *hosts; |
| 14097 | 56 |
| 14103 | 57 /* |
| 58 * All of the following variables are used when establishing a | |
| 59 * connection through a proxy. | |
| 60 */ | |
|
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
61 guchar *write_buffer; |
|
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
62 gsize write_buf_len; |
|
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
63 gsize written_len; |
|
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
64 GaimInputFunction read_cb; |
|
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
65 guchar *read_buffer; |
|
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
66 gsize read_buf_len; |
|
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
67 gsize read_len; |
|
1840
00aef397a1fe
[gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1705
diff
changeset
|
68 }; |
|
00aef397a1fe
[gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1705
diff
changeset
|
69 |
| 12246 | 70 static const char *socks5errors[] = { |
| 7982 | 71 "succeeded\n", |
| 72 "general SOCKS server failure\n", | |
| 73 "connection not allowed by ruleset\n", | |
| 74 "Network unreachable\n", | |
| 75 "Host unreachable\n", | |
| 76 "Connection refused\n", | |
| 77 "TTL expired\n", | |
| 78 "Command not supported\n", | |
| 79 "Address type not supported\n" | |
| 80 }; | |
| 81 | |
| 14089 | 82 static GaimProxyInfo *global_proxy_info = NULL; |
| 14103 | 83 |
| 84 /* | |
| 85 * TODO: Once all callers of gaim_proxy_connect() are keeping track | |
| 86 * of the return value from that function this linked list | |
| 87 * will no longer be needed. | |
| 88 */ | |
| 14096 | 89 static GSList *connect_infos = NULL; |
| 14089 | 90 |
| 14103 | 91 static void try_connect(GaimProxyConnectInfo *connect_info); |
| 14089 | 92 |
|
5681
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
93 /************************************************************************** |
|
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
94 * Proxy structure API |
|
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
95 **************************************************************************/ |
|
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
96 GaimProxyInfo * |
|
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
97 gaim_proxy_info_new(void) |
|
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
98 { |
|
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
99 return g_new0(GaimProxyInfo, 1); |
|
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
100 } |
|
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 void |
|
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
103 gaim_proxy_info_destroy(GaimProxyInfo *info) |
|
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
104 { |
|
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
105 g_return_if_fail(info != NULL); |
|
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
106 |
| 13968 | 107 g_free(info->host); |
| 108 g_free(info->username); | |
| 109 g_free(info->password); | |
|
5681
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
110 |
|
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
111 g_free(info); |
|
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
112 } |
|
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 void |
|
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
115 gaim_proxy_info_set_type(GaimProxyInfo *info, GaimProxyType type) |
|
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
116 { |
|
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
117 g_return_if_fail(info != NULL); |
|
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
118 |
|
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
119 info->type = type; |
|
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
120 } |
|
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 void |
|
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
123 gaim_proxy_info_set_host(GaimProxyInfo *info, const char *host) |
|
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
124 { |
|
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
125 g_return_if_fail(info != NULL); |
|
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
126 |
| 13968 | 127 g_free(info->host); |
| 14035 | 128 info->host = g_strdup(host); |
|
5681
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
129 } |
|
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 void |
|
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
132 gaim_proxy_info_set_port(GaimProxyInfo *info, int port) |
|
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
133 { |
|
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
134 g_return_if_fail(info != NULL); |
|
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
135 |
|
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
136 info->port = port; |
|
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
137 } |
|
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 void |
|
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
140 gaim_proxy_info_set_username(GaimProxyInfo *info, const char *username) |
|
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
141 { |
|
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
142 g_return_if_fail(info != NULL); |
|
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
143 |
| 13968 | 144 g_free(info->username); |
| 14035 | 145 info->username = g_strdup(username); |
|
5681
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
146 } |
|
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 void |
|
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
149 gaim_proxy_info_set_password(GaimProxyInfo *info, const char *password) |
|
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
150 { |
|
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
151 g_return_if_fail(info != NULL); |
|
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
152 |
| 13968 | 153 g_free(info->password); |
| 14035 | 154 info->password = g_strdup(password); |
|
5681
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
155 } |
|
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 GaimProxyType |
|
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
158 gaim_proxy_info_get_type(const GaimProxyInfo *info) |
|
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
159 { |
|
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
160 g_return_val_if_fail(info != NULL, GAIM_PROXY_NONE); |
|
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
161 |
|
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
162 return info->type; |
|
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
163 } |
|
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 const char * |
|
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
166 gaim_proxy_info_get_host(const GaimProxyInfo *info) |
|
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
167 { |
|
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
168 g_return_val_if_fail(info != NULL, NULL); |
|
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
169 |
|
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
170 return info->host; |
|
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
171 } |
|
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 int |
|
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
174 gaim_proxy_info_get_port(const GaimProxyInfo *info) |
|
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
175 { |
|
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
176 g_return_val_if_fail(info != NULL, 0); |
|
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
177 |
|
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
178 return info->port; |
|
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
179 } |
|
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 const char * |
|
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
182 gaim_proxy_info_get_username(const GaimProxyInfo *info) |
|
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
183 { |
|
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
184 g_return_val_if_fail(info != NULL, NULL); |
|
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
185 |
|
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
186 return info->username; |
|
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
187 } |
|
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 const char * |
|
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
190 gaim_proxy_info_get_password(const GaimProxyInfo *info) |
|
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
191 { |
|
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
192 g_return_val_if_fail(info != NULL, NULL); |
|
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
193 |
|
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
194 return info->password; |
|
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
195 } |
|
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 * Global Proxy API |
|
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
199 **************************************************************************/ |
|
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
200 GaimProxyInfo * |
|
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
201 gaim_global_proxy_get_info(void) |
|
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
202 { |
|
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
203 return global_proxy_info; |
|
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
204 } |
|
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
205 |
|
12412
a88ca6da0b38
[gaim-migrate @ 14719]
Richard Laager <rlaager@wiktel.com>
parents:
12391
diff
changeset
|
206 static GaimProxyInfo * |
| 11878 | 207 gaim_gnome_proxy_get_info(void) |
| 208 { | |
| 209 static GaimProxyInfo info = {0, NULL, 0, NULL, NULL}; | |
| 210 gchar *path; | |
| 211 if ((path = g_find_program_in_path("gconftool-2"))) { | |
| 212 gchar *tmp; | |
| 12156 | 213 |
| 214 g_free(path); | |
| 215 | |
| 11878 | 216 /* See whether to use a proxy. */ |
| 217 if (!g_spawn_command_line_sync("gconftool-2 -g /system/http_proxy/use_http_proxy", &tmp, | |
| 218 NULL, NULL, NULL)) | |
| 219 return gaim_global_proxy_get_info(); | |
|
12811
ac41924f8bb0
[gaim-migrate @ 15159]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12765
diff
changeset
|
220 if (!strcmp(tmp, "false\n")) { |
| 11878 | 221 info.type = GAIM_PROXY_NONE; |
| 222 g_free(tmp); | |
|
12811
ac41924f8bb0
[gaim-migrate @ 15159]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12765
diff
changeset
|
223 return &info; |
|
ac41924f8bb0
[gaim-migrate @ 15159]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12765
diff
changeset
|
224 } else if (strcmp(tmp, "true\n")) { |
|
ac41924f8bb0
[gaim-migrate @ 15159]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12765
diff
changeset
|
225 g_free(tmp); |
| 11878 | 226 return gaim_global_proxy_get_info(); |
| 227 } | |
| 12156 | 228 |
| 11878 | 229 g_free(tmp); |
| 230 info.type = GAIM_PROXY_HTTP; | |
| 12156 | 231 |
| 11878 | 232 /* Free the old fields */ |
| 233 if (info.host) { | |
| 234 g_free(info.host); | |
| 235 info.host = NULL; | |
| 236 } | |
| 237 if (info.username) { | |
| 238 g_free(info.username); | |
| 239 info.username = NULL; | |
| 240 } | |
| 241 if (info.password) { | |
| 242 g_free(info.password); | |
| 243 info.password = NULL; | |
| 244 } | |
| 12156 | 245 |
| 11878 | 246 /* Get the new ones */ |
| 247 if (!g_spawn_command_line_sync("gconftool-2 -g /system/http_proxy/host", &info.host, | |
| 248 NULL, NULL, NULL)) | |
| 249 return gaim_global_proxy_get_info(); | |
| 250 g_strchomp(info.host); | |
| 12156 | 251 |
| 11878 | 252 if (!g_spawn_command_line_sync("gconftool-2 -g /system/http_proxy/authentication_user", &info.username, |
| 253 NULL, NULL, NULL)) | |
| 254 return gaim_global_proxy_get_info(); | |
| 255 g_strchomp(info.username); | |
| 256 | |
| 257 if (!g_spawn_command_line_sync("gconftool-2 -g /system/http_proxy/authentication_password", &info.password, | |
| 258 NULL, NULL, NULL)) | |
| 259 return gaim_global_proxy_get_info(); | |
| 260 g_strchomp(info.password); | |
| 261 | |
| 262 if (!g_spawn_command_line_sync("gconftool-2 -g /system/http_proxy/port", &tmp, | |
| 263 NULL, NULL, NULL)) | |
| 264 return gaim_global_proxy_get_info(); | |
| 265 info.port = atoi(tmp); | |
| 12156 | 266 g_free(tmp); |
| 11878 | 267 |
| 268 return &info; | |
| 269 } | |
| 270 return gaim_global_proxy_get_info(); | |
| 271 } | |
|
5681
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
272 /************************************************************************** |
|
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
273 * Proxy API |
|
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
274 **************************************************************************/ |
| 4366 | 275 |
| 14103 | 276 /* |
| 277 * This is used when the connection attempt to one particular IP | |
| 278 * address fails. We close the socket, remove the watcher and get | |
| 279 * rid of input and output buffers. Normally try_connect() will | |
| 280 * be called immediately after this. | |
| 281 */ | |
| 282 static void | |
| 283 gaim_proxy_connect_info_disconnect(GaimProxyConnectInfo *connect_info) | |
| 284 { | |
| 285 if (connect_info->inpa > 0) | |
| 286 { | |
| 287 gaim_input_remove(connect_info->inpa); | |
| 288 connect_info->inpa = 0; | |
| 289 } | |
| 290 | |
| 291 if (connect_info->fd >= 0) | |
| 292 { | |
| 293 close(connect_info->fd); | |
| 294 connect_info->fd = -1; | |
| 295 } | |
| 296 | |
| 297 g_free(connect_info->write_buffer); | |
| 298 connect_info->write_buffer = NULL; | |
| 299 | |
| 300 g_free(connect_info->read_buffer); | |
| 301 connect_info->read_buffer = NULL; | |
| 302 } | |
| 303 | |
| 14089 | 304 static void |
| 14097 | 305 gaim_proxy_connect_info_destroy(GaimProxyConnectInfo *connect_info) |
| 14089 | 306 { |
| 14103 | 307 gaim_proxy_connect_info_disconnect(connect_info); |
| 14089 | 308 |
| 14103 | 309 connect_infos = g_slist_remove(connect_infos, connect_info); |
| 14089 | 310 |
| 14096 | 311 while (connect_info->hosts != NULL) |
| 14089 | 312 { |
| 313 /* Discard the length... */ | |
| 14096 | 314 connect_info->hosts = g_slist_remove(connect_info->hosts, connect_info->hosts->data); |
| 14089 | 315 /* Free the address... */ |
| 14096 | 316 g_free(connect_info->hosts->data); |
| 317 connect_info->hosts = g_slist_remove(connect_info->hosts, connect_info->hosts->data); | |
| 14089 | 318 } |
| 319 | |
| 14096 | 320 g_free(connect_info->host); |
| 321 g_free(connect_info); | |
| 14089 | 322 } |
| 323 | |
| 324 static void | |
| 14103 | 325 gaim_proxy_connect_info_connected(GaimProxyConnectInfo *connect_info) |
| 14089 | 326 { |
| 14103 | 327 connect_info->connect_cb(connect_info->data, connect_info->fd); |
| 328 | |
| 329 /* | |
| 330 * We've passed the file descriptor to the protocol, so it's no longer | |
| 331 * our responsibility, and we should be careful not to free it when | |
| 332 * we destroy the connect_info. | |
| 333 */ | |
| 334 connect_info->fd = -1; | |
| 335 | |
| 14096 | 336 gaim_proxy_connect_info_destroy(connect_info); |
| 14089 | 337 } |
| 338 | |
| 339 /** | |
| 340 * @param error An error message explaining why the connection | |
| 341 * failed. This will be passed to the callback function | |
| 342 * specified in the call to gaim_proxy_connect(). | |
| 343 */ | |
| 14099 | 344 /* |
| 345 * TODO: Make sure all callers of this function pass a really really | |
| 346 * good error_message. | |
| 347 */ | |
| 14089 | 348 static void |
| 14097 | 349 gaim_proxy_connect_info_error(GaimProxyConnectInfo *connect_info, const gchar *error_message) |
| 14089 | 350 { |
| 14096 | 351 if (connect_info->error_cb == NULL) |
| 14089 | 352 { |
| 353 /* | |
| 354 * TODO | |
| 355 * While we're transitioning to the new gaim_proxy_connect() | |
| 356 * code, not all callers supply an error_cb. If this is the | |
| 357 * case then they're expecting connect_cb to be called with | |
| 358 * an fd of -1 in the case of an error. Once all callers have | |
| 359 * been changed this whole if statement should be removed. | |
| 360 */ | |
| 14096 | 361 connect_info->connect_cb(connect_info->data, -1); |
| 362 gaim_proxy_connect_info_destroy(connect_info); | |
| 14089 | 363 return; |
| 364 } | |
| 365 | |
| 14096 | 366 connect_info->error_cb(connect_info->data, error_message); |
| 367 gaim_proxy_connect_info_destroy(connect_info); | |
| 14089 | 368 } |
| 369 | |
|
13648
3eba1e7458c7
[gaim-migrate @ 16049]
Evan Schoenberg <evan.s@dreskin.net>
parents:
13530
diff
changeset
|
370 #if defined(__unix__) || defined(__APPLE__) |
| 4366 | 371 |
| 10711 | 372 /* |
| 373 * This structure represents both a pending DNS request and | |
| 374 * a free child process. | |
| 4366 | 375 */ |
| 376 typedef struct { | |
| 377 char *host; | |
| 378 int port; | |
| 14089 | 379 GaimProxyDnsConnectFunction callback; |
| 4366 | 380 gpointer data; |
| 14089 | 381 guint inpa; |
| 4366 | 382 int fd_in, fd_out; |
| 383 pid_t dns_pid; | |
| 384 } pending_dns_request_t; | |
| 385 | |
| 386 static GSList *free_dns_children = NULL; | |
| 387 static GQueue *queued_requests = NULL; | |
| 388 | |
| 389 static int number_of_dns_children = 0; | |
| 390 | |
| 12246 | 391 static const int MAX_DNS_CHILDREN = 2; |
| 4366 | 392 |
| 393 typedef struct { | |
| 394 char hostname[512]; | |
| 395 int port; | |
| 396 } dns_params_t; | |
| 397 | |
| 398 typedef struct { | |
| 399 dns_params_t params; | |
| 14089 | 400 GaimProxyDnsConnectFunction callback; |
| 4366 | 401 gpointer data; |
| 402 } queued_dns_request_t; | |
| 403 | |
| 10711 | 404 /* |
| 405 * Begin the DNS resolver child process functions. | |
| 406 */ | |
| 407 #ifdef HAVE_SIGNAL_H | |
| 408 static void | |
| 409 trap_gdb_bug() | |
| 410 { | |
| 411 const char *message = | |
| 13968 | 412 "Gaim's DNS child got a SIGTRAP signal.\n" |
| 10711 | 413 "This can be caused by trying to run gaim inside gdb.\n" |
| 414 "There is a known gdb bug which prevents this. Supposedly gaim\n" | |
| 415 "should have detected you were using gdb and used an ugly hack,\n" | |
| 416 "check cope_with_gdb_brokenness() in proxy.c.\n\n" | |
| 417 "For more info about this bug, see http://sources.redhat.com/ml/gdb/2001-07/msg00349.html\n"; | |
| 418 fputs("\n* * *\n",stderr); | |
| 419 fputs(message,stderr); | |
| 420 fputs("* * *\n\n",stderr); | |
| 421 execlp("xmessage","xmessage","-center", message, NULL); | |
| 422 _exit(1); | |
| 423 } | |
| 424 #endif | |
| 425 | |
| 426 static void | |
| 427 cope_with_gdb_brokenness() | |
| 428 { | |
| 429 #ifdef __linux__ | |
| 430 static gboolean already_done = FALSE; | |
| 431 char s[256], e[512]; | |
| 432 int n; | |
| 433 pid_t ppid; | |
| 434 | |
| 435 if(already_done) | |
| 436 return; | |
| 437 already_done = TRUE; | |
| 438 ppid = getppid(); | |
| 439 snprintf(s, sizeof(s), "/proc/%d/exe", ppid); | |
| 440 n = readlink(s, e, sizeof(e)); | |
| 441 if(n < 0) | |
| 442 return; | |
| 443 | |
| 444 e[MIN(n,sizeof(e)-1)] = '\0'; | |
| 445 | |
| 446 if(strstr(e,"gdb")) { | |
| 447 gaim_debug_info("dns", | |
| 448 "Debugger detected, performing useless query...\n"); | |
| 449 gethostbyname("x.x.x.x.x"); | |
| 450 } | |
| 451 #endif | |
| 452 } | |
| 453 | |
| 454 static void | |
| 455 gaim_dns_resolverthread(int child_out, int child_in, gboolean show_debug) | |
| 456 { | |
| 457 dns_params_t dns_params; | |
| 458 const size_t zero = 0; | |
| 459 int rc; | |
|
13425
95cc25e78ef6
[gaim-migrate @ 15800]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13404
diff
changeset
|
460 #ifdef HAVE_GETADDRINFO |
| 10711 | 461 struct addrinfo hints, *res, *tmp; |
| 462 char servname[20]; | |
| 463 #else | |
| 464 struct sockaddr_in sin; | |
| 465 const size_t addrlen = sizeof(sin); | |
| 466 #endif | |
| 467 | |
| 468 #ifdef HAVE_SIGNAL_H | |
| 469 signal(SIGHUP, SIG_DFL); | |
| 470 signal(SIGINT, SIG_DFL); | |
| 471 signal(SIGQUIT, SIG_DFL); | |
| 472 signal(SIGCHLD, SIG_DFL); | |
| 473 signal(SIGTERM, SIG_DFL); | |
| 474 signal(SIGTRAP, trap_gdb_bug); | |
| 475 #endif | |
| 476 | |
| 477 /* | |
| 478 * We resolve 1 host name for each iteration of this | |
| 479 * while loop. | |
| 480 * | |
| 481 * The top half of this reads in the hostname and port | |
| 482 * number from the socket with our parent. The bottom | |
| 483 * half of this resolves the IP (blocking) and sends | |
| 484 * the result back to our parent, when finished. | |
| 485 */ | |
| 486 while (1) { | |
| 487 const char ch = 'Y'; | |
| 488 fd_set fds; | |
| 489 struct timeval tv = { .tv_sec = 40 , .tv_usec = 0 }; | |
| 490 FD_ZERO(&fds); | |
| 491 FD_SET(child_in, &fds); | |
| 492 rc = select(child_in + 1, &fds, NULL, NULL, &tv); | |
| 493 if (!rc) { | |
| 494 if (show_debug) | |
|
13798
24b768639db5
[gaim-migrate @ 16210]
Richard Laager <rlaager@wiktel.com>
parents:
13786
diff
changeset
|
495 printf("dns[%d]: nobody needs me... =(\n", getpid()); |
| 10711 | 496 break; |
| 497 } | |
| 498 rc = read(child_in, &dns_params, sizeof(dns_params_t)); | |
| 499 if (rc < 0) { | |
| 500 perror("read()"); | |
| 501 break; | |
| 502 } | |
| 503 if (rc == 0) { | |
| 504 if (show_debug) | |
|
13798
24b768639db5
[gaim-migrate @ 16210]
Richard Laager <rlaager@wiktel.com>
parents:
13786
diff
changeset
|
505 printf("dns[%d]: Oops, father has gone, wait for me, wait...!\n", getpid()); |
| 10711 | 506 _exit(0); |
| 507 } | |
| 508 if (dns_params.hostname[0] == '\0') { | |
|
13798
24b768639db5
[gaim-migrate @ 16210]
Richard Laager <rlaager@wiktel.com>
parents:
13786
diff
changeset
|
509 printf("dns[%d]: hostname = \"\" (port = %d)!!!\n", getpid(), dns_params.port); |
| 10711 | 510 _exit(1); |
| 511 } | |
| 512 /* Tell our parent that we read the data successfully */ | |
| 513 write(child_out, &ch, sizeof(ch)); | |
| 514 | |
| 515 /* We have the hostname and port, now resolve the IP */ | |
| 516 | |
|
13425
95cc25e78ef6
[gaim-migrate @ 15800]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13404
diff
changeset
|
517 #ifdef HAVE_GETADDRINFO |
| 10711 | 518 g_snprintf(servname, sizeof(servname), "%d", dns_params.port); |
| 519 memset(&hints, 0, sizeof(hints)); | |
| 520 | |
| 521 /* This is only used to convert a service | |
| 522 * name to a port number. As we know we are | |
| 523 * passing a number already, we know this | |
| 524 * value will not be really used by the C | |
| 525 * library. | |
| 526 */ | |
| 527 hints.ai_socktype = SOCK_STREAM; | |
| 528 rc = getaddrinfo(dns_params.hostname, servname, &hints, &res); | |
| 529 write(child_out, &rc, sizeof(rc)); | |
| 530 if (rc != 0) { | |
| 531 close(child_out); | |
| 532 if (show_debug) | |
|
13798
24b768639db5
[gaim-migrate @ 16210]
Richard Laager <rlaager@wiktel.com>
parents:
13786
diff
changeset
|
533 printf("dns[%d] Error: getaddrinfo returned %d\n", |
| 10711 | 534 getpid(), rc); |
| 535 dns_params.hostname[0] = '\0'; | |
| 536 continue; | |
| 537 } | |
| 538 tmp = res; | |
| 539 while (res) { | |
| 540 size_t ai_addrlen = res->ai_addrlen; | |
| 541 write(child_out, &ai_addrlen, sizeof(ai_addrlen)); | |
| 542 write(child_out, res->ai_addr, res->ai_addrlen); | |
| 543 res = res->ai_next; | |
| 544 } | |
| 545 freeaddrinfo(tmp); | |
| 546 write(child_out, &zero, sizeof(zero)); | |
| 547 #else | |
| 548 if (!inet_aton(dns_params.hostname, &sin.sin_addr)) { | |
| 549 struct hostent *hp; | |
| 550 if (!(hp = gethostbyname(dns_params.hostname))) { | |
| 551 write(child_out, &h_errno, sizeof(int)); | |
| 552 close(child_out); | |
| 553 if (show_debug) | |
|
13798
24b768639db5
[gaim-migrate @ 16210]
Richard Laager <rlaager@wiktel.com>
parents:
13786
diff
changeset
|
554 printf("DNS Error: %d\n", h_errno); |
| 10711 | 555 _exit(0); |
| 556 } | |
| 557 memset(&sin, 0, sizeof(struct sockaddr_in)); | |
| 558 memcpy(&sin.sin_addr.s_addr, hp->h_addr, hp->h_length); | |
| 559 sin.sin_family = hp->h_addrtype; | |
| 560 } else | |
| 561 sin.sin_family = AF_INET; | |
| 562 | |
| 563 sin.sin_port = htons(dns_params.port); | |
| 564 write(child_out, &addrlen, sizeof(addrlen)); | |
| 565 write(child_out, &sin, addrlen); | |
| 566 write(child_out, &zero, sizeof(zero)); | |
| 567 #endif | |
| 568 dns_params.hostname[0] = '\0'; | |
| 569 } | |
| 570 | |
| 571 close(child_out); | |
| 572 close(child_in); | |
| 573 | |
| 574 _exit(0); | |
| 575 } | |
| 576 | |
| 577 static pending_dns_request_t * | |
| 578 gaim_dns_new_resolverthread(gboolean show_debug) | |
| 579 { | |
| 580 pending_dns_request_t *req; | |
| 581 int child_out[2], child_in[2]; | |
| 582 | |
| 583 /* Create pipes for communicating with the child process */ | |
| 584 if (pipe(child_out) || pipe(child_in)) { | |
| 585 gaim_debug_error("dns", | |
| 586 "Could not create pipes: %s\n", strerror(errno)); | |
| 587 return NULL; | |
| 588 } | |
| 589 | |
| 590 req = g_new(pending_dns_request_t, 1); | |
| 591 | |
| 592 cope_with_gdb_brokenness(); | |
| 593 | |
| 594 /* Fork! */ | |
| 595 req->dns_pid = fork(); | |
| 596 | |
| 597 /* If we are the child process... */ | |
| 598 if (req->dns_pid == 0) { | |
| 599 /* We should not access the parent's side of the pipes, so close them */ | |
| 600 close(child_out[0]); | |
| 601 close(child_in[1]); | |
| 602 | |
| 603 gaim_dns_resolverthread(child_out[1], child_in[0], show_debug); | |
| 604 /* The thread calls _exit() rather than returning, so we never get here */ | |
| 605 } | |
| 606 | |
| 607 /* We should not access the child's side of the pipes, so close them */ | |
| 608 close(child_out[1]); | |
| 609 close(child_in[0]); | |
| 610 if (req->dns_pid == -1) { | |
| 611 gaim_debug_error("dns", | |
| 612 "Could not create child process for DNS: %s\n", | |
| 613 strerror(errno)); | |
| 614 g_free(req); | |
| 615 return NULL; | |
| 616 } | |
| 617 | |
| 618 req->fd_out = child_out[0]; | |
| 619 req->fd_in = child_in[1]; | |
| 620 number_of_dns_children++; | |
| 621 gaim_debug_info("dns", | |
| 622 "Created new DNS child %d, there are now %d children.\n", | |
| 623 req->dns_pid, number_of_dns_children); | |
| 624 | |
| 625 return req; | |
| 626 } | |
| 627 /* | |
| 628 * End the DNS resolver child process functions. | |
| 629 */ | |
| 630 | |
| 631 /* | |
| 632 * Begin the functions for dealing with the DNS child processes. | |
| 633 */ | |
| 634 static void | |
| 635 req_free(pending_dns_request_t *req) | |
| 4434 | 636 { |
| 637 g_return_if_fail(req != NULL); | |
| 10707 | 638 |
| 4434 | 639 close(req->fd_in); |
| 640 close(req->fd_out); | |
| 10707 | 641 |
| 642 g_free(req->host); | |
| 4434 | 643 g_free(req); |
| 10707 | 644 |
| 4434 | 645 number_of_dns_children--; |
| 646 } | |
| 647 | |
| 10711 | 648 static int |
| 649 send_dns_request_to_child(pending_dns_request_t *req, dns_params_t *dns_params) | |
| 4366 | 650 { |
| 651 char ch; | |
| 652 int rc; | |
| 13530 | 653 pid_t pid; |
| 4366 | 654 |
| 13530 | 655 /* This waitpid might return the child's PID if it has recently |
| 656 * exited, or it might return an error if it exited "long | |
| 657 * enough" ago that it has already been reaped; in either | |
| 658 * instance, we can't use it. */ | |
| 659 if ((pid = waitpid (req->dns_pid, NULL, WNOHANG)) > 0) { | |
| 10309 | 660 gaim_debug_warning("dns", |
|
5218
4ee151ad8233
[gaim-migrate @ 5588]
Christian Hammond <chipx86@chipx86.com>
parents:
5211
diff
changeset
|
661 "DNS child %d no longer exists\n", req->dns_pid); |
| 4366 | 662 return -1; |
| 13530 | 663 } else if (pid < 0) { |
| 664 gaim_debug_warning("dns", | |
| 665 "Wait for DNS child %d failed: %s\n", | |
| 666 req->dns_pid, strerror(errno)); | |
| 667 return -1; | |
| 4366 | 668 } |
| 9129 | 669 |
| 4366 | 670 /* Let's contact this lost child! */ |
| 671 rc = write(req->fd_in, dns_params, sizeof(*dns_params)); | |
| 10707 | 672 if (rc < 0) { |
| 10309 | 673 gaim_debug_error("dns", |
|
5211
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
4993
diff
changeset
|
674 "Unable to write to DNS child %d: %d\n", |
|
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
4993
diff
changeset
|
675 req->dns_pid, strerror(errno)); |
| 4434 | 676 close(req->fd_in); |
| 4366 | 677 return -1; |
| 678 } | |
| 9129 | 679 |
| 4366 | 680 g_return_val_if_fail(rc == sizeof(*dns_params), -1); |
| 9129 | 681 |
| 4366 | 682 /* Did you hear me? (This avoids some race conditions) */ |
| 10707 | 683 rc = read(req->fd_out, &ch, sizeof(ch)); |
| 684 if (rc != 1 || ch != 'Y') | |
| 685 { | |
| 10309 | 686 gaim_debug_warning("dns", |
|
5211
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
4993
diff
changeset
|
687 "DNS child %d not responding. Killing it!\n", |
|
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
4993
diff
changeset
|
688 req->dns_pid); |
| 4366 | 689 kill(req->dns_pid, SIGKILL); |
| 690 return -1; | |
| 691 } | |
| 9655 | 692 |
| 10309 | 693 gaim_debug_info("dns", |
|
5211
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
4993
diff
changeset
|
694 "Successfully sent DNS request to child %d\n", req->dns_pid); |
| 10707 | 695 |
| 4366 | 696 return 0; |
| 697 } | |
| 698 | |
| 10711 | 699 static void |
| 700 host_resolved(gpointer data, gint source, GaimInputCondition cond); | |
| 4366 | 701 |
| 10711 | 702 static void |
| 703 release_dns_child(pending_dns_request_t *req) | |
|
2911
4790fb1272a1
[gaim-migrate @ 2924]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2907
diff
changeset
|
704 { |
| 4366 | 705 g_free(req->host); |
| 10707 | 706 req->host = NULL; |
| 4366 | 707 |
| 10707 | 708 if (queued_requests && !g_queue_is_empty(queued_requests)) { |
| 4366 | 709 queued_dns_request_t *r = g_queue_pop_head(queued_requests); |
| 710 req->host = g_strdup(r->params.hostname); | |
| 711 req->port = r->params.port; | |
| 712 req->callback = r->callback; | |
| 713 req->data = r->data; | |
| 714 | |
| 10309 | 715 gaim_debug_info("dns", |
|
5211
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
4993
diff
changeset
|
716 "Processing queued DNS query for '%s' with child %d\n", |
|
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
4993
diff
changeset
|
717 req->host, req->dns_pid); |
| 4366 | 718 |
| 10707 | 719 if (send_dns_request_to_child(req, &(r->params)) != 0) { |
| 4434 | 720 req_free(req); |
| 4366 | 721 req = NULL; |
|
5211
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
4993
diff
changeset
|
722 |
| 10309 | 723 gaim_debug_warning("dns", |
|
5211
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
4993
diff
changeset
|
724 "Intent of process queued query of '%s' failed, " |
|
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
4993
diff
changeset
|
725 "requeueing...\n", r->params.hostname); |
| 4366 | 726 g_queue_push_head(queued_requests, r); |
| 727 } else { | |
| 728 req->inpa = gaim_input_add(req->fd_out, GAIM_INPUT_READ, host_resolved, req); | |
| 729 g_free(r); | |
| 730 } | |
| 9655 | 731 |
| 4366 | 732 } else { |
| 733 req->host = NULL; | |
| 734 req->callback = NULL; | |
| 735 req->data = NULL; | |
| 736 free_dns_children = g_slist_append(free_dns_children, req); | |
| 737 } | |
| 738 } | |
| 739 | |
| 10711 | 740 static void |
| 741 host_resolved(gpointer data, gint source, GaimInputCondition cond) | |
| 4366 | 742 { |
| 743 pending_dns_request_t *req = (pending_dns_request_t*)data; | |
| 744 int rc, err; | |
| 4678 | 745 GSList *hosts = NULL; |
| 4366 | 746 struct sockaddr *addr = NULL; |
| 8436 | 747 size_t addrlen; |
| 4366 | 748 |
| 13023 | 749 gaim_debug_info("dns", "Got response for '%s'\n", req->host); |
| 4366 | 750 gaim_input_remove(req->inpa); |
| 751 | |
| 10707 | 752 rc = read(req->fd_out, &err, sizeof(err)); |
| 753 if ((rc == 4) && (err != 0)) | |
| 754 { | |
| 4366 | 755 char message[1024]; |
|
13425
95cc25e78ef6
[gaim-migrate @ 15800]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13404
diff
changeset
|
756 #ifdef HAVE_GETADDRINFO |
| 4366 | 757 g_snprintf(message, sizeof(message), "DNS error: %s (pid=%d)", |
| 8977 | 758 gai_strerror(err), req->dns_pid); |
| 4366 | 759 #else |
| 8977 | 760 g_snprintf(message, sizeof(message), "DNS error: %d (pid=%d)", |
| 761 err, req->dns_pid); | |
| 4366 | 762 #endif |
| 10309 | 763 gaim_debug_error("dns", "%s\n", message); |
| 4678 | 764 req->callback(NULL, req->data, message); |
| 765 release_dns_child(req); | |
| 4366 | 766 return; |
| 767 } | |
| 10707 | 768 if (rc > 0) |
| 769 { | |
| 770 while (rc > 0) { | |
| 771 rc = read(req->fd_out, &addrlen, sizeof(addrlen)); | |
| 772 if (rc > 0 && addrlen > 0) { | |
| 773 addr = g_malloc(addrlen); | |
| 774 rc = read(req->fd_out, addr, addrlen); | |
| 4678 | 775 hosts = g_slist_append(hosts, GINT_TO_POINTER(addrlen)); |
| 776 hosts = g_slist_append(hosts, addr); | |
| 777 } else { | |
| 778 break; | |
| 779 } | |
| 4366 | 780 } |
| 10707 | 781 } else if (rc == -1) { |
| 4366 | 782 char message[1024]; |
| 783 g_snprintf(message, sizeof(message), "Error reading from DNS child: %s",strerror(errno)); | |
| 10309 | 784 gaim_debug_error("dns", "%s\n", message); |
| 4678 | 785 req->callback(NULL, req->data, message); |
| 4434 | 786 req_free(req); |
| 4366 | 787 return; |
| 10707 | 788 } else if (rc == 0) { |
| 4366 | 789 char message[1024]; |
| 790 g_snprintf(message, sizeof(message), "EOF reading from DNS child"); | |
| 791 close(req->fd_out); | |
| 10309 | 792 gaim_debug_error("dns", "%s\n", message); |
| 4678 | 793 req->callback(NULL, req->data, message); |
| 4434 | 794 req_free(req); |
| 4366 | 795 return; |
| 796 } | |
| 797 | |
| 798 /* wait4(req->dns_pid, NULL, WNOHANG, NULL); */ | |
| 799 | |
| 4678 | 800 req->callback(hosts, req->data, NULL); |
| 4366 | 801 |
| 4678 | 802 release_dns_child(req); |
| 4366 | 803 } |
| 10711 | 804 /* |
| 805 * End the functions for dealing with the DNS child processes. | |
| 806 */ | |
| 9657 | 807 |
| 10711 | 808 int |
| 14089 | 809 gaim_gethostbyname_async(const char *hostname, int port, GaimProxyDnsConnectFunction callback, gpointer data) |
| 4366 | 810 { |
| 811 pending_dns_request_t *req = NULL; | |
| 812 dns_params_t dns_params; | |
| 9656 | 813 gchar *host_temp; |
| 10307 | 814 gboolean show_debug; |
| 815 | |
| 816 show_debug = gaim_debug_is_enabled(); | |
| 9655 | 817 |
| 9656 | 818 host_temp = g_strstrip(g_strdup(hostname)); |
| 819 strncpy(dns_params.hostname, host_temp, sizeof(dns_params.hostname) - 1); | |
| 9655 | 820 g_free(host_temp); |
| 9656 | 821 dns_params.hostname[sizeof(dns_params.hostname) - 1] = '\0'; |
| 4366 | 822 dns_params.port = port; |
| 9129 | 823 |
| 9656 | 824 /* |
| 825 * If we have any children, attempt to have them perform the DNS | |
| 826 * query. If we're able to send the query to a child, then req | |
| 827 * will be set to the pending_dns_request_t. Otherwise, req will | |
| 828 * be NULL and we'll need to create a new DNS request child. | |
| 829 */ | |
| 830 while (free_dns_children != NULL) { | |
| 831 req = free_dns_children->data; | |
| 832 free_dns_children = g_slist_remove(free_dns_children, req); | |
| 9129 | 833 |
| 9656 | 834 if (send_dns_request_to_child(req, &dns_params) == 0) |
| 835 /* We found an acceptable child, yay */ | |
| 836 break; | |
| 9129 | 837 |
| 9656 | 838 req_free(req); |
| 9657 | 839 req = NULL; |
| 4366 | 840 } |
| 841 | |
| 9657 | 842 /* We need to create a new DNS request child */ |
| 9656 | 843 if (req == NULL) { |
| 844 if (number_of_dns_children >= MAX_DNS_CHILDREN) { | |
| 4366 | 845 queued_dns_request_t *r = g_new(queued_dns_request_t, 1); |
| 846 memcpy(&(r->params), &dns_params, sizeof(dns_params)); | |
| 847 r->callback = callback; | |
| 848 r->data = data; | |
| 9656 | 849 if (!queued_requests) |
| 4366 | 850 queued_requests = g_queue_new(); |
| 851 g_queue_push_tail(queued_requests, r); | |
|
5211
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
4993
diff
changeset
|
852 |
| 10309 | 853 gaim_debug_info("dns", |
| 9656 | 854 "DNS query for '%s' queued\n", dns_params.hostname); |
|
5211
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
4993
diff
changeset
|
855 |
| 4366 | 856 return 0; |
| 857 } | |
| 858 | |
| 10711 | 859 req = gaim_dns_new_resolverthread(show_debug); |
| 12977 | 860 if (req == NULL) |
| 861 { | |
| 862 gaim_debug_error("proxy", "oh dear, this is going to explode, I give up\n"); | |
| 863 return -1; | |
| 864 } | |
| 10711 | 865 send_dns_request_to_child(req, &dns_params); |
| 4366 | 866 } |
| 9656 | 867 |
| 9657 | 868 req->host = g_strdup(hostname); |
| 9656 | 869 req->port = port; |
| 870 req->callback = callback; | |
| 871 req->data = data; | |
| 4366 | 872 req->inpa = gaim_input_add(req->fd_out, GAIM_INPUT_READ, host_resolved, req); |
| 9656 | 873 |
| 4366 | 874 return 0; |
| 875 } | |
|
10237
2f6dcbaaabe0
[gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
10172
diff
changeset
|
876 |
|
13648
3eba1e7458c7
[gaim-migrate @ 16049]
Evan Schoenberg <evan.s@dreskin.net>
parents:
13530
diff
changeset
|
877 #elif defined _WIN32 /* end __unix__ || __APPLE__ */ |
|
10237
2f6dcbaaabe0
[gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
10172
diff
changeset
|
878 |
|
2f6dcbaaabe0
[gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
10172
diff
changeset
|
879 typedef struct _dns_tdata { |
|
2f6dcbaaabe0
[gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
10172
diff
changeset
|
880 char *hostname; |
|
2f6dcbaaabe0
[gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
10172
diff
changeset
|
881 int port; |
| 14089 | 882 GaimProxyDnsConnectFunction callback; |
|
10237
2f6dcbaaabe0
[gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
10172
diff
changeset
|
883 gpointer data; |
|
2f6dcbaaabe0
[gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
10172
diff
changeset
|
884 GSList *hosts; |
|
2f6dcbaaabe0
[gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
10172
diff
changeset
|
885 char *errmsg; |
|
2f6dcbaaabe0
[gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
10172
diff
changeset
|
886 } dns_tdata; |
|
2f6dcbaaabe0
[gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
10172
diff
changeset
|
887 |
|
2f6dcbaaabe0
[gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
10172
diff
changeset
|
888 static gboolean dns_main_thread_cb(gpointer data) { |
|
2f6dcbaaabe0
[gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
10172
diff
changeset
|
889 dns_tdata *td = (dns_tdata*)data; |
|
10562
e06da39b467c
[gaim-migrate @ 11942]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10561
diff
changeset
|
890 if (td->errmsg != NULL) { |
|
e06da39b467c
[gaim-migrate @ 11942]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10561
diff
changeset
|
891 gaim_debug_info("dns", "%s\n", td->errmsg); |
|
e06da39b467c
[gaim-migrate @ 11942]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10561
diff
changeset
|
892 } |
|
10237
2f6dcbaaabe0
[gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
10172
diff
changeset
|
893 td->callback(td->hosts, td->data, td->errmsg); |
|
2f6dcbaaabe0
[gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
10172
diff
changeset
|
894 g_free(td->hostname); |
|
10562
e06da39b467c
[gaim-migrate @ 11942]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10561
diff
changeset
|
895 g_free(td->errmsg); |
|
10237
2f6dcbaaabe0
[gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
10172
diff
changeset
|
896 g_free(td); |
|
2f6dcbaaabe0
[gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
10172
diff
changeset
|
897 return FALSE; |
|
2f6dcbaaabe0
[gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
10172
diff
changeset
|
898 } |
|
2f6dcbaaabe0
[gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
10172
diff
changeset
|
899 |
|
2f6dcbaaabe0
[gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
10172
diff
changeset
|
900 static gpointer dns_thread(gpointer data) { |
|
10619
4ab7dec04c38
[gaim-migrate @ 12086]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10613
diff
changeset
|
901 |
|
13425
95cc25e78ef6
[gaim-migrate @ 15800]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13404
diff
changeset
|
902 #ifdef HAVE_GETADDRINFO |
|
10619
4ab7dec04c38
[gaim-migrate @ 12086]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10613
diff
changeset
|
903 int rc; |
|
4ab7dec04c38
[gaim-migrate @ 12086]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10613
diff
changeset
|
904 struct addrinfo hints, *res, *tmp; |
|
4ab7dec04c38
[gaim-migrate @ 12086]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10613
diff
changeset
|
905 char servname[20]; |
|
4ab7dec04c38
[gaim-migrate @ 12086]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10613
diff
changeset
|
906 #else |
|
10237
2f6dcbaaabe0
[gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
10172
diff
changeset
|
907 struct sockaddr_in sin; |
|
10619
4ab7dec04c38
[gaim-migrate @ 12086]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10613
diff
changeset
|
908 struct hostent *hp; |
|
4ab7dec04c38
[gaim-migrate @ 12086]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10613
diff
changeset
|
909 #endif |
|
10237
2f6dcbaaabe0
[gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
10172
diff
changeset
|
910 dns_tdata *td = (dns_tdata*)data; |
|
10619
4ab7dec04c38
[gaim-migrate @ 12086]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10613
diff
changeset
|
911 |
|
13425
95cc25e78ef6
[gaim-migrate @ 15800]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13404
diff
changeset
|
912 #ifdef HAVE_GETADDRINFO |
|
10619
4ab7dec04c38
[gaim-migrate @ 12086]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10613
diff
changeset
|
913 g_snprintf(servname, sizeof(servname), "%d", td->port); |
|
4ab7dec04c38
[gaim-migrate @ 12086]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10613
diff
changeset
|
914 memset(&hints,0,sizeof(hints)); |
|
10237
2f6dcbaaabe0
[gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
10172
diff
changeset
|
915 |
|
10619
4ab7dec04c38
[gaim-migrate @ 12086]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10613
diff
changeset
|
916 /* This is only used to convert a service |
|
4ab7dec04c38
[gaim-migrate @ 12086]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10613
diff
changeset
|
917 * name to a port number. As we know we are |
|
4ab7dec04c38
[gaim-migrate @ 12086]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10613
diff
changeset
|
918 * passing a number already, we know this |
|
4ab7dec04c38
[gaim-migrate @ 12086]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10613
diff
changeset
|
919 * value will not be really used by the C |
|
4ab7dec04c38
[gaim-migrate @ 12086]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10613
diff
changeset
|
920 * library. |
|
4ab7dec04c38
[gaim-migrate @ 12086]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10613
diff
changeset
|
921 */ |
|
4ab7dec04c38
[gaim-migrate @ 12086]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10613
diff
changeset
|
922 hints.ai_socktype = SOCK_STREAM; |
|
4ab7dec04c38
[gaim-migrate @ 12086]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10613
diff
changeset
|
923 if ((rc = getaddrinfo(td->hostname, servname, &hints, &res)) == 0) { |
|
4ab7dec04c38
[gaim-migrate @ 12086]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10613
diff
changeset
|
924 tmp = res; |
|
4ab7dec04c38
[gaim-migrate @ 12086]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10613
diff
changeset
|
925 while(res) { |
|
4ab7dec04c38
[gaim-migrate @ 12086]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10613
diff
changeset
|
926 td->hosts = g_slist_append(td->hosts, |
|
4ab7dec04c38
[gaim-migrate @ 12086]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10613
diff
changeset
|
927 GSIZE_TO_POINTER(res->ai_addrlen)); |
|
4ab7dec04c38
[gaim-migrate @ 12086]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10613
diff
changeset
|
928 td->hosts = g_slist_append(td->hosts, |
|
4ab7dec04c38
[gaim-migrate @ 12086]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10613
diff
changeset
|
929 g_memdup(res->ai_addr, res->ai_addrlen)); |
|
4ab7dec04c38
[gaim-migrate @ 12086]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10613
diff
changeset
|
930 res = res->ai_next; |
|
4ab7dec04c38
[gaim-migrate @ 12086]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10613
diff
changeset
|
931 } |
|
4ab7dec04c38
[gaim-migrate @ 12086]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10613
diff
changeset
|
932 freeaddrinfo(tmp); |
|
4ab7dec04c38
[gaim-migrate @ 12086]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10613
diff
changeset
|
933 } else { |
|
4ab7dec04c38
[gaim-migrate @ 12086]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10613
diff
changeset
|
934 td->errmsg = g_strdup_printf("DNS getaddrinfo(\"%s\", \"%s\") error: %d", td->hostname, servname, rc); |
|
4ab7dec04c38
[gaim-migrate @ 12086]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10613
diff
changeset
|
935 } |
|
4ab7dec04c38
[gaim-migrate @ 12086]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10613
diff
changeset
|
936 #else |
|
10562
e06da39b467c
[gaim-migrate @ 11942]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10561
diff
changeset
|
937 if ((hp = gethostbyname(td->hostname))) { |
|
e06da39b467c
[gaim-migrate @ 11942]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10561
diff
changeset
|
938 memset(&sin, 0, sizeof(struct sockaddr_in)); |
|
e06da39b467c
[gaim-migrate @ 11942]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10561
diff
changeset
|
939 memcpy(&sin.sin_addr.s_addr, hp->h_addr, hp->h_length); |
|
e06da39b467c
[gaim-migrate @ 11942]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10561
diff
changeset
|
940 sin.sin_family = hp->h_addrtype; |
|
e06da39b467c
[gaim-migrate @ 11942]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10561
diff
changeset
|
941 sin.sin_port = htons(td->port); |
| 10305 | 942 |
|
10562
e06da39b467c
[gaim-migrate @ 11942]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10561
diff
changeset
|
943 td->hosts = g_slist_append(td->hosts, |
|
10619
4ab7dec04c38
[gaim-migrate @ 12086]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10613
diff
changeset
|
944 GSIZE_TO_POINTER(sizeof(sin))); |
|
10562
e06da39b467c
[gaim-migrate @ 11942]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10561
diff
changeset
|
945 td->hosts = g_slist_append(td->hosts, |
|
e06da39b467c
[gaim-migrate @ 11942]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10561
diff
changeset
|
946 g_memdup(&sin, sizeof(sin))); |
|
e06da39b467c
[gaim-migrate @ 11942]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10561
diff
changeset
|
947 } else { |
|
10619
4ab7dec04c38
[gaim-migrate @ 12086]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10613
diff
changeset
|
948 td->errmsg = g_strdup_printf("DNS gethostbyname(\"%s\") error: %d", td->hostname, h_errno); |
|
10562
e06da39b467c
[gaim-migrate @ 11942]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10561
diff
changeset
|
949 } |
|
10619
4ab7dec04c38
[gaim-migrate @ 12086]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10613
diff
changeset
|
950 #endif |
|
10237
2f6dcbaaabe0
[gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
10172
diff
changeset
|
951 /* back to main thread */ |
|
2f6dcbaaabe0
[gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
10172
diff
changeset
|
952 g_idle_add(dns_main_thread_cb, td); |
|
2f6dcbaaabe0
[gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
10172
diff
changeset
|
953 return 0; |
| 10305 | 954 } |
|
10237
2f6dcbaaabe0
[gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
10172
diff
changeset
|
955 |
| 10711 | 956 int |
| 957 gaim_gethostbyname_async(const char *hostname, int port, | |
| 14089 | 958 GaimProxyDnsConnectFunction callback, gpointer data) |
| 10711 | 959 { |
|
10237
2f6dcbaaabe0
[gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
10172
diff
changeset
|
960 dns_tdata *td; |
|
2f6dcbaaabe0
[gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
10172
diff
changeset
|
961 struct sockaddr_in sin; |
|
2f6dcbaaabe0
[gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
10172
diff
changeset
|
962 GError* err = NULL; |
|
2f6dcbaaabe0
[gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
10172
diff
changeset
|
963 |
|
2f6dcbaaabe0
[gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
10172
diff
changeset
|
964 if(inet_aton(hostname, &sin.sin_addr)) { |
|
2f6dcbaaabe0
[gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
10172
diff
changeset
|
965 GSList *hosts = NULL; |
|
2f6dcbaaabe0
[gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
10172
diff
changeset
|
966 sin.sin_family = AF_INET; |
|
2f6dcbaaabe0
[gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
10172
diff
changeset
|
967 sin.sin_port = htons(port); |
|
2f6dcbaaabe0
[gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
10172
diff
changeset
|
968 hosts = g_slist_append(hosts, GINT_TO_POINTER(sizeof(sin))); |
|
2f6dcbaaabe0
[gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
10172
diff
changeset
|
969 hosts = g_slist_append(hosts, g_memdup(&sin, sizeof(sin))); |
|
2f6dcbaaabe0
[gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
10172
diff
changeset
|
970 callback(hosts, data, NULL); |
|
2f6dcbaaabe0
[gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
10172
diff
changeset
|
971 return 0; |
|
2f6dcbaaabe0
[gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
10172
diff
changeset
|
972 } |
|
2f6dcbaaabe0
[gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
10172
diff
changeset
|
973 |
|
2f6dcbaaabe0
[gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
10172
diff
changeset
|
974 gaim_debug_info("dns", "DNS Lookup for: %s\n", hostname); |
|
2f6dcbaaabe0
[gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
10172
diff
changeset
|
975 td = g_new0(dns_tdata, 1); |
|
2f6dcbaaabe0
[gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
10172
diff
changeset
|
976 td->hostname = g_strdup(hostname); |
|
2f6dcbaaabe0
[gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
10172
diff
changeset
|
977 td->port = port; |
|
2f6dcbaaabe0
[gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
10172
diff
changeset
|
978 td->callback = callback; |
|
2f6dcbaaabe0
[gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
10172
diff
changeset
|
979 td->data = data; |
|
2f6dcbaaabe0
[gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
10172
diff
changeset
|
980 |
|
2f6dcbaaabe0
[gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
10172
diff
changeset
|
981 if(!g_thread_create(dns_thread, td, FALSE, &err)) { |
|
2f6dcbaaabe0
[gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
10172
diff
changeset
|
982 gaim_debug_error("dns", "DNS thread create failure: %s\n", err?err->message:""); |
|
2f6dcbaaabe0
[gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
10172
diff
changeset
|
983 g_error_free(err); |
|
2f6dcbaaabe0
[gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
10172
diff
changeset
|
984 g_free(td->hostname); |
|
2f6dcbaaabe0
[gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
10172
diff
changeset
|
985 g_free(td); |
|
2f6dcbaaabe0
[gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
10172
diff
changeset
|
986 return -1; |
|
2f6dcbaaabe0
[gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
10172
diff
changeset
|
987 } |
|
2f6dcbaaabe0
[gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
10172
diff
changeset
|
988 return 0; |
|
2f6dcbaaabe0
[gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
10172
diff
changeset
|
989 } |
|
2f6dcbaaabe0
[gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
10172
diff
changeset
|
990 |
|
13648
3eba1e7458c7
[gaim-migrate @ 16049]
Evan Schoenberg <evan.s@dreskin.net>
parents:
13530
diff
changeset
|
991 #else /* not __unix__ or __APPLE__ or _WIN32 */ |
| 4366 | 992 |
| 993 typedef struct { | |
| 994 gpointer data; | |
| 995 size_t addrlen; | |
| 996 struct sockaddr *addr; | |
| 14089 | 997 GaimProxyDnsConnectFunction callback; |
| 4366 | 998 } pending_dns_request_t; |
| 999 | |
| 1000 static gboolean host_resolved(gpointer data) | |
| 1001 { | |
| 1002 pending_dns_request_t *req = (pending_dns_request_t*)data; | |
| 4678 | 1003 GSList *hosts = NULL; |
| 1004 hosts = g_slist_append(hosts, GINT_TO_POINTER(req->addrlen)); | |
| 1005 hosts = g_slist_append(hosts, req->addr); | |
| 1006 req->callback(hosts, req->data, NULL); | |
| 4366 | 1007 g_free(req); |
| 1008 return FALSE; | |
| 1009 } | |
| 1010 | |
|
5681
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
1011 int |
|
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
1012 gaim_gethostbyname_async(const char *hostname, int port, |
| 14089 | 1013 GaimProxyDnsConnectFunction callback, gpointer data) |
| 4366 | 1014 { |
| 1015 struct sockaddr_in sin; | |
| 1016 pending_dns_request_t *req; | |
| 1017 | |
| 1018 if (!inet_aton(hostname, &sin.sin_addr)) { | |
|
2911
4790fb1272a1
[gaim-migrate @ 2924]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2907
diff
changeset
|
1019 struct hostent *hp; |
| 4366 | 1020 if(!(hp = gethostbyname(hostname))) { |
| 10309 | 1021 gaim_debug_error("dns", |
| 8977 | 1022 "gaim_gethostbyname(\"%s\", %d) failed: %d\n", |
| 1023 hostname, port, h_errno); | |
| 4366 | 1024 return -1; |
|
2911
4790fb1272a1
[gaim-migrate @ 2924]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2907
diff
changeset
|
1025 } |
|
4790fb1272a1
[gaim-migrate @ 2924]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2907
diff
changeset
|
1026 memset(&sin, 0, sizeof(struct sockaddr_in)); |
|
4790fb1272a1
[gaim-migrate @ 2924]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2907
diff
changeset
|
1027 memcpy(&sin.sin_addr.s_addr, hp->h_addr, hp->h_length); |
|
4790fb1272a1
[gaim-migrate @ 2924]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2907
diff
changeset
|
1028 sin.sin_family = hp->h_addrtype; |
|
4790fb1272a1
[gaim-migrate @ 2924]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2907
diff
changeset
|
1029 } else |
|
4790fb1272a1
[gaim-migrate @ 2924]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2907
diff
changeset
|
1030 sin.sin_family = AF_INET; |
|
4790fb1272a1
[gaim-migrate @ 2924]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2907
diff
changeset
|
1031 sin.sin_port = htons(port); |
|
4790fb1272a1
[gaim-migrate @ 2924]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2907
diff
changeset
|
1032 |
| 4366 | 1033 req = g_new(pending_dns_request_t, 1); |
| 1034 req->addr = (struct sockaddr*) g_memdup(&sin, sizeof(sin)); | |
| 1035 req->addrlen = sizeof(sin); | |
| 1036 req->data = data; | |
| 1037 req->callback = callback; | |
|
8273
f24172f53650
[gaim-migrate @ 8997]
Christian Hammond <chipx86@chipx86.com>
parents:
8269
diff
changeset
|
1038 gaim_timeout_add(10, host_resolved, req); |
| 4366 | 1039 return 0; |
|
2911
4790fb1272a1
[gaim-migrate @ 2924]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2907
diff
changeset
|
1040 } |
|
4790fb1272a1
[gaim-migrate @ 2924]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2907
diff
changeset
|
1041 |
|
13648
3eba1e7458c7
[gaim-migrate @ 16049]
Evan Schoenberg <evan.s@dreskin.net>
parents:
13530
diff
changeset
|
1042 #endif /* not __unix__ or __APPLE__ or _WIN32 */ |
| 4366 | 1043 |
|
5681
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
1044 static void |
|
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
1045 no_one_calls(gpointer data, gint source, GaimInputCondition cond) |
|
1840
00aef397a1fe
[gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1705
diff
changeset
|
1046 { |
| 14097 | 1047 GaimProxyConnectInfo *connect_info = data; |
|
12991
c1b2ba353e85
[gaim-migrate @ 15344]
Richard Laager <rlaager@wiktel.com>
parents:
12977
diff
changeset
|
1048 socklen_t len; |
|
8273
f24172f53650
[gaim-migrate @ 8997]
Christian Hammond <chipx86@chipx86.com>
parents:
8269
diff
changeset
|
1049 int error=0, ret; |
|
3717
988485669631
[gaim-migrate @ 3850]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3630
diff
changeset
|
1050 |
| 10309 | 1051 gaim_debug_info("proxy", "Connected.\n"); |
|
3717
988485669631
[gaim-migrate @ 3850]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3630
diff
changeset
|
1052 |
|
1840
00aef397a1fe
[gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1705
diff
changeset
|
1053 len = sizeof(error); |
|
4648
4bb99cdfd837
[gaim-migrate @ 4959]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
4634
diff
changeset
|
1054 |
|
8273
f24172f53650
[gaim-migrate @ 8997]
Christian Hammond <chipx86@chipx86.com>
parents:
8269
diff
changeset
|
1055 /* |
|
f24172f53650
[gaim-migrate @ 8997]
Christian Hammond <chipx86@chipx86.com>
parents:
8269
diff
changeset
|
1056 * getsockopt after a non-blocking connect returns -1 if something is |
|
f24172f53650
[gaim-migrate @ 8997]
Christian Hammond <chipx86@chipx86.com>
parents:
8269
diff
changeset
|
1057 * really messed up (bad descriptor, usually). Otherwise, it returns 0 and |
|
f24172f53650
[gaim-migrate @ 8997]
Christian Hammond <chipx86@chipx86.com>
parents:
8269
diff
changeset
|
1058 * 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
|
1059 * Thus, error == 0 is success, error == EINPROGRESS means "try again", |
|
f24172f53650
[gaim-migrate @ 8997]
Christian Hammond <chipx86@chipx86.com>
parents:
8269
diff
changeset
|
1060 * and anything else is a real error. |
|
f24172f53650
[gaim-migrate @ 8997]
Christian Hammond <chipx86@chipx86.com>
parents:
8269
diff
changeset
|
1061 * |
|
f24172f53650
[gaim-migrate @ 8997]
Christian Hammond <chipx86@chipx86.com>
parents:
8269
diff
changeset
|
1062 * (error == EINPROGRESS can happen after a select because the kernel can |
|
f24172f53650
[gaim-migrate @ 8997]
Christian Hammond <chipx86@chipx86.com>
parents:
8269
diff
changeset
|
1063 * 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
|
1064 * able to do something.) |
|
f24172f53650
[gaim-migrate @ 8997]
Christian Hammond <chipx86@chipx86.com>
parents:
8269
diff
changeset
|
1065 */ |
| 14103 | 1066 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
|
1067 if (ret == 0 && error == EINPROGRESS) |
| 9863 | 1068 return; /* we'll be called again later */ |
|
8273
f24172f53650
[gaim-migrate @ 8997]
Christian Hammond <chipx86@chipx86.com>
parents:
8269
diff
changeset
|
1069 if (ret < 0 || error != 0) { |
| 14089 | 1070 if (ret!=0) |
| 1071 error = errno; | |
|
5681
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
1072 |
| 10309 | 1073 gaim_debug_error("proxy", |
| 9100 | 1074 "getsockopt SO_ERROR check: %s\n", strerror(error)); |
| 9129 | 1075 |
| 14103 | 1076 gaim_proxy_connect_info_disconnect(connect_info); |
| 14096 | 1077 try_connect(connect_info); |
|
1840
00aef397a1fe
[gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1705
diff
changeset
|
1078 return; |
|
00aef397a1fe
[gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1705
diff
changeset
|
1079 } |
|
5681
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
1080 |
| 14096 | 1081 gaim_input_remove(connect_info->inpa); |
| 1082 connect_info->inpa = 0; | |
|
5681
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
1083 |
| 14103 | 1084 gaim_proxy_connect_info_connected(connect_info); |
|
1840
00aef397a1fe
[gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1705
diff
changeset
|
1085 } |
|
00aef397a1fe
[gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1705
diff
changeset
|
1086 |
| 14103 | 1087 static gboolean |
| 1088 clean_connect(gpointer data) | |
|
1868
a49ed23b3c02
[gaim-migrate @ 1878]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1844
diff
changeset
|
1089 { |
| 14103 | 1090 GaimProxyConnectInfo *connect_info; |
|
1868
a49ed23b3c02
[gaim-migrate @ 1878]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1844
diff
changeset
|
1091 |
| 14103 | 1092 connect_info = data; |
| 1093 gaim_proxy_connect_info_connected(connect_info); | |
|
1868
a49ed23b3c02
[gaim-migrate @ 1878]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1844
diff
changeset
|
1094 |
|
a49ed23b3c02
[gaim-migrate @ 1878]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1844
diff
changeset
|
1095 return FALSE; |
|
a49ed23b3c02
[gaim-migrate @ 1878]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1844
diff
changeset
|
1096 } |
|
a49ed23b3c02
[gaim-migrate @ 1878]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1844
diff
changeset
|
1097 |
|
5681
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
1098 static int |
| 14097 | 1099 proxy_connect_none(GaimProxyConnectInfo *connect_info, struct sockaddr *addr, socklen_t addrlen) |
| 1 | 1100 { |
| 14103 | 1101 gaim_debug_info("proxy", "Connecting to %s:%d with no proxy\n", |
| 1102 connect_info->host, connect_info->port); | |
|
3717
988485669631
[gaim-migrate @ 3850]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3630
diff
changeset
|
1103 |
| 14103 | 1104 connect_info->fd = socket(addr->sa_family, SOCK_STREAM, 0); |
| 1105 if (connect_info->fd < 0) | |
| 1106 { | |
| 10309 | 1107 gaim_debug_error("proxy", |
|
5211
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
4993
diff
changeset
|
1108 "Unable to create socket: %s\n", strerror(errno)); |
|
1087
56c7ceb986a8
[gaim-migrate @ 1097]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1057
diff
changeset
|
1109 return -1; |
|
1840
00aef397a1fe
[gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1705
diff
changeset
|
1110 } |
| 14103 | 1111 fcntl(connect_info->fd, F_SETFL, O_NONBLOCK); |
| 10172 | 1112 #ifndef _WIN32 |
| 14103 | 1113 fcntl(connect_info->fd, F_SETFD, FD_CLOEXEC); |
| 10172 | 1114 #endif |
|
3717
988485669631
[gaim-migrate @ 3850]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3630
diff
changeset
|
1115 |
| 14103 | 1116 if (connect(connect_info->fd, (struct sockaddr *)addr, addrlen) != 0) |
| 14099 | 1117 { |
|
1840
00aef397a1fe
[gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1705
diff
changeset
|
1118 if ((errno == EINPROGRESS) || (errno == EINTR)) { |
| 14103 | 1119 gaim_debug_info("proxy", "Connection in progress\n"); |
| 1120 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
|
1121 } |
|
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
1122 else { |
| 10309 | 1123 gaim_debug_error("proxy", |
| 9100 | 1124 "Connect failed: %s\n", strerror(errno)); |
| 14103 | 1125 close(connect_info->fd); |
| 1126 connect_info->fd = -1; | |
|
1840
00aef397a1fe
[gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1705
diff
changeset
|
1127 return -1; |
|
00aef397a1fe
[gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1705
diff
changeset
|
1128 } |
|
5681
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
1129 } |
| 14103 | 1130 else |
| 1131 { | |
| 1132 /* | |
| 1133 * The connection happened IMMEDIATELY... strange, but whatever. | |
| 1134 */ | |
|
12991
c1b2ba353e85
[gaim-migrate @ 15344]
Richard Laager <rlaager@wiktel.com>
parents:
12977
diff
changeset
|
1135 socklen_t len; |
|
2048
3366311426df
[gaim-migrate @ 2058]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1881
diff
changeset
|
1136 int error = ETIMEDOUT; |
| 14103 | 1137 gaim_debug_info("proxy", "Connected immediately.\n"); |
|
1840
00aef397a1fe
[gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1705
diff
changeset
|
1138 len = sizeof(error); |
| 14103 | 1139 if (getsockopt(connect_info->fd, SOL_SOCKET, SO_ERROR, &error, &len) != 0) |
| 14099 | 1140 { |
| 10309 | 1141 gaim_debug_error("proxy", "getsockopt failed.\n"); |
| 14103 | 1142 close(connect_info->fd); |
| 1143 connect_info->fd = -1; | |
|
1840
00aef397a1fe
[gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1705
diff
changeset
|
1144 return -1; |
|
00aef397a1fe
[gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1705
diff
changeset
|
1145 } |
| 14103 | 1146 |
| 1147 /* | |
| 1148 * We want to call the "connected" callback eventually, but we | |
| 1149 * don't want to call it before we return, just in case. | |
| 1150 */ | |
| 1151 gaim_timeout_add(10, clean_connect, connect_info); | |
|
1087
56c7ceb986a8
[gaim-migrate @ 1097]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1057
diff
changeset
|
1152 } |
|
56c7ceb986a8
[gaim-migrate @ 1097]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1057
diff
changeset
|
1153 |
| 14103 | 1154 return connect_info->fd; |
|
1087
56c7ceb986a8
[gaim-migrate @ 1097]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1057
diff
changeset
|
1155 } |
|
56c7ceb986a8
[gaim-migrate @ 1097]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1057
diff
changeset
|
1156 |
|
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1157 static void |
|
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1158 proxy_do_write(gpointer data, gint source, GaimInputCondition cond) |
|
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1159 { |
| 14097 | 1160 GaimProxyConnectInfo *connect_info = data; |
| 14096 | 1161 const guchar *request = connect_info->write_buffer + connect_info->written_len; |
| 1162 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
|
1163 |
| 14103 | 1164 int ret = write(connect_info->fd, request, request_len); |
|
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1165 |
|
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1166 if(ret < 0 && errno == EAGAIN) |
|
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1167 return; |
|
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1168 else if(ret < 0) { |
| 14103 | 1169 gaim_proxy_connect_info_disconnect(connect_info); |
| 14096 | 1170 try_connect(connect_info); |
|
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1171 return; |
|
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1172 } else if (ret < request_len) { |
| 14096 | 1173 connect_info->written_len += ret; |
|
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1174 return; |
|
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1175 } |
|
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1176 |
| 14096 | 1177 gaim_input_remove(connect_info->inpa); |
| 1178 g_free(connect_info->write_buffer); | |
| 1179 connect_info->write_buffer = NULL; | |
|
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1180 |
|
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1181 /* register the response handler for the response */ |
| 14103 | 1182 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
|
1183 } |
|
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1184 |
| 3376 | 1185 #define HTTP_GOODSTRING "HTTP/1.0 200" |
| 1186 #define HTTP_GOODSTRING2 "HTTP/1.1 200" | |
|
1087
56c7ceb986a8
[gaim-migrate @ 1097]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1057
diff
changeset
|
1187 |
|
7834
99ffabc6ce73
[gaim-migrate @ 8487]
Christian Hammond <chipx86@chipx86.com>
parents:
7652
diff
changeset
|
1188 /* 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
|
1189 static void |
|
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
1190 http_canread(gpointer data, gint source, GaimInputCondition cond) |
|
1840
00aef397a1fe
[gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1705
diff
changeset
|
1191 { |
|
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1192 int len, headers_len, status = 0; |
|
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1193 gboolean error; |
| 14097 | 1194 GaimProxyConnectInfo *connect_info = data; |
|
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1195 guchar *p; |
|
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1196 gsize max_read; |
| 14089 | 1197 gchar *msg; |
|
1840
00aef397a1fe
[gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1705
diff
changeset
|
1198 |
| 14096 | 1199 if(connect_info->read_buffer == NULL) { |
| 1200 connect_info->read_buf_len = 8192; | |
| 1201 connect_info->read_buffer = g_malloc(connect_info->read_buf_len); | |
| 1202 connect_info->read_len = 0; | |
|
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1203 } |
|
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1204 |
| 14096 | 1205 p = connect_info->read_buffer + connect_info->read_len; |
| 1206 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
|
1207 |
| 14103 | 1208 len = read(connect_info->fd, p, max_read); |
|
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1209 if(len < 0 && errno == EAGAIN) |
|
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1210 return; |
|
13786
5ddde4ad1ca2
[gaim-migrate @ 16198]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13752
diff
changeset
|
1211 else if(len <= 0) { |
| 14096 | 1212 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
|
1213 return; |
|
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1214 } else { |
| 14096 | 1215 connect_info->read_len += len; |
|
1840
00aef397a1fe
[gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1705
diff
changeset
|
1216 } |
|
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1217 p[len] = '\0'; |
|
5681
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
1218 |
| 14096 | 1219 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
|
1220 *p = '\0'; |
| 14096 | 1221 headers_len = (p - connect_info->read_buffer) + 4; |
|
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1222 } else if(len == max_read) |
|
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1223 headers_len = len; |
|
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1224 else |
|
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1225 return; |
|
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1226 |
| 14096 | 1227 error = strncmp((const char *)connect_info->read_buffer, "HTTP/", 5) != 0; |
| 14089 | 1228 if (!error) |
| 1229 { | |
|
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1230 int major; |
| 14096 | 1231 p = connect_info->read_buffer + 5; |
| 13386 | 1232 major = strtol((const char *)p, (char **)&p, 10); |
|
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1233 error = (major == 0) || (*p != '.'); |
| 4366 | 1234 if(!error) { |
|
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1235 int minor; |
| 4366 | 1236 p++; |
| 13386 | 1237 minor = strtol((const char *)p, (char **)&p, 10); |
|
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1238 error = (*p != ' '); |
| 4366 | 1239 if(!error) { |
| 1240 p++; | |
| 13386 | 1241 status = strtol((const char *)p, (char **)&p, 10); |
|
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1242 error = (*p != ' '); |
| 4366 | 1243 } |
| 1244 } | |
| 1245 } | |
| 9129 | 1246 |
| 12391 | 1247 /* Read the contents */ |
| 14096 | 1248 p = (guchar *)g_strrstr((const gchar *)connect_info->read_buffer, "Content-Length: "); |
| 14089 | 1249 if (p != NULL) |
| 1250 { | |
| 12391 | 1251 gchar *tmp; |
| 1252 int len = 0; | |
| 1253 char tmpc; | |
| 1254 p += strlen("Content-Length: "); | |
| 13386 | 1255 tmp = strchr((const char *)p, '\r'); |
| 13404 | 1256 if(tmp) |
| 1257 *tmp = '\0'; | |
| 13386 | 1258 len = atoi((const char *)p); |
| 13404 | 1259 if(tmp) |
| 1260 *tmp = '\r'; | |
|
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1261 |
|
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1262 /* Compensate for what has already been read */ |
| 14096 | 1263 len -= connect_info->read_len - headers_len; |
|
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1264 /* 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
|
1265 complaining / breaking since we don't read the whole page */ |
|
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1266 while(len--) { |
|
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1267 /* TODO: deal with EAGAIN (and other errors) better */ |
| 14103 | 1268 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
|
1269 break; |
|
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1270 } |
| 12391 | 1271 } |
|
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1272 |
| 14089 | 1273 if (error) |
| 1274 { | |
| 1275 msg = g_strdup_printf("Unable to parse response from HTTP proxy: %s\n", | |
| 14096 | 1276 connect_info->read_buffer); |
| 1277 gaim_proxy_connect_info_error(connect_info, msg); | |
| 14089 | 1278 g_free(msg); |
|
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1279 return; |
| 14089 | 1280 } |
| 1281 else if (status != 200) | |
| 1282 { | |
| 10309 | 1283 gaim_debug_error("proxy", |
|
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1284 "Proxy server replied with:\n%s\n", |
| 14096 | 1285 connect_info->read_buffer); |
|
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1286 |
| 9129 | 1287 |
|
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1288 if(status == 407 /* Proxy Auth */) { |
| 12391 | 1289 gchar *ntlm; |
| 14096 | 1290 if((ntlm = g_strrstr((const gchar *)connect_info->read_buffer, "Proxy-Authenticate: NTLM "))) { /* Check for Type-2 */ |
| 13698 | 1291 gchar *tmp = ntlm; |
| 1292 guint8 *nonce; | |
| 14096 | 1293 gchar *domain = (gchar*)gaim_proxy_info_get_username(connect_info->gpi); |
| 12391 | 1294 gchar *username; |
| 1295 gchar *request; | |
| 1296 gchar *response; | |
| 14089 | 1297 username = strchr(domain, '\\'); |
| 1298 if (username == NULL) | |
| 1299 { | |
| 1300 msg = g_strdup_printf(_("HTTP proxy connection error %d"), status); | |
| 14096 | 1301 gaim_proxy_connect_info_error(connect_info, msg); |
| 12391 | 1302 g_free(msg); |
| 1303 return; | |
| 1304 } | |
|
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1305 *username = '\0'; |
|
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1306 username++; |
| 12391 | 1307 ntlm += strlen("Proxy-Authenticate: NTLM "); |
| 13698 | 1308 while(*tmp != '\r' && *tmp != '\0') tmp++; |
| 1309 *tmp = '\0'; | |
| 13084 | 1310 nonce = gaim_ntlm_parse_type2(ntlm, NULL); |
|
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1311 response = gaim_ntlm_gen_type3(username, |
| 14096 | 1312 (gchar*) gaim_proxy_info_get_password(connect_info->gpi), |
| 1313 (gchar*) gaim_proxy_info_get_host(connect_info->gpi), | |
|
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1314 domain, nonce, NULL); |
| 12391 | 1315 username--; |
| 1316 *username = '\\'; | |
|
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1317 request = g_strdup_printf( |
|
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1318 "CONNECT %s:%d HTTP/1.1\r\n" |
|
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1319 "Host: %s:%d\r\n" |
|
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1320 "Proxy-Authorization: NTLM %s\r\n" |
|
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1321 "Proxy-Connection: Keep-Alive\r\n\r\n", |
| 14096 | 1322 connect_info->host, connect_info->port, connect_info->host, |
| 1323 connect_info->port, response); | |
| 12391 | 1324 g_free(response); |
|
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1325 |
| 14096 | 1326 gaim_input_remove(connect_info->inpa); |
| 1327 g_free(connect_info->read_buffer); | |
| 1328 connect_info->read_buffer = NULL; | |
|
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1329 |
| 14096 | 1330 connect_info->write_buffer = (guchar *)request; |
| 1331 connect_info->write_buf_len = strlen(request); | |
| 1332 connect_info->written_len = 0; | |
|
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1333 |
| 14096 | 1334 connect_info->read_cb = http_canread; |
|
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1335 |
| 14103 | 1336 connect_info->inpa = gaim_input_add(connect_info->fd, |
| 14096 | 1337 GAIM_INPUT_WRITE, proxy_do_write, connect_info); |
|
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1338 |
| 14103 | 1339 proxy_do_write(connect_info, connect_info->fd, cond); |
| 12391 | 1340 return; |
| 14096 | 1341 } else if((ntlm = g_strrstr((const char *)connect_info->read_buffer, "Proxy-Authenticate: NTLM"))) { /* Empty message */ |
| 12391 | 1342 gchar request[2048]; |
| 14096 | 1343 gchar *domain = (gchar*) gaim_proxy_info_get_username(connect_info->gpi); |
| 12391 | 1344 gchar *username; |
| 1345 int request_len; | |
| 14089 | 1346 username = strchr(domain, '\\'); |
| 1347 if (username == NULL) | |
| 1348 { | |
| 1349 msg = g_strdup_printf(_("HTTP proxy connection error %d"), status); | |
| 14096 | 1350 gaim_proxy_connect_info_error(connect_info, msg); |
| 12391 | 1351 g_free(msg); |
| 1352 return; | |
| 1353 } | |
|
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1354 *username = '\0'; |
| 12391 | 1355 |
| 1356 request_len = g_snprintf(request, sizeof(request), | |
|
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1357 "CONNECT %s:%d HTTP/1.1\r\n" |
|
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1358 "Host: %s:%d\r\n", |
| 14096 | 1359 connect_info->host, connect_info->port, |
| 1360 connect_info->host, connect_info->port); | |
| 12391 | 1361 |
| 1362 g_return_if_fail(request_len < sizeof(request)); | |
| 1363 request_len += g_snprintf(request + request_len, | |
|
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1364 sizeof(request) - request_len, |
|
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1365 "Proxy-Authorization: NTLM %s\r\n" |
|
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1366 "Proxy-Connection: Keep-Alive\r\n\r\n", |
|
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1367 gaim_ntlm_gen_type1( |
| 14096 | 1368 (gchar*) gaim_proxy_info_get_host(connect_info->gpi), |
|
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1369 domain)); |
| 12391 | 1370 *username = '\\'; |
|
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1371 |
| 14096 | 1372 gaim_input_remove(connect_info->inpa); |
| 1373 g_free(connect_info->read_buffer); | |
| 1374 connect_info->read_buffer = NULL; | |
|
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1375 |
| 14096 | 1376 connect_info->write_buffer = g_memdup(request, request_len); |
| 1377 connect_info->write_buf_len = request_len; | |
| 1378 connect_info->written_len = 0; | |
|
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1379 |
| 14096 | 1380 connect_info->read_cb = http_canread; |
|
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1381 |
| 14103 | 1382 connect_info->inpa = gaim_input_add(connect_info->fd, |
| 14096 | 1383 GAIM_INPUT_WRITE, proxy_do_write, connect_info); |
|
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1384 |
| 14103 | 1385 proxy_do_write(connect_info, connect_info->fd, cond); |
| 12391 | 1386 return; |
| 1387 } else { | |
| 14089 | 1388 msg = g_strdup_printf(_("HTTP proxy connection error %d"), status); |
| 14096 | 1389 gaim_proxy_connect_info_error(connect_info, msg); |
| 12391 | 1390 g_free(msg); |
|
13208
de4f1fb08088
[gaim-migrate @ 15572]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13200
diff
changeset
|
1391 return; |
| 12391 | 1392 } |
| 1393 } | |
|
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1394 if(status == 403 /* Forbidden */ ) { |
| 14096 | 1395 msg = g_strdup_printf(_("Access denied: HTTP proxy server forbids port %d tunnelling."), connect_info->port); |
| 1396 gaim_proxy_connect_info_error(connect_info, msg); | |
| 8917 | 1397 g_free(msg); |
| 1398 } else { | |
| 14089 | 1399 msg = g_strdup_printf(_("HTTP proxy connection error %d"), status); |
| 14096 | 1400 gaim_proxy_connect_info_error(connect_info, msg); |
|
7834
99ffabc6ce73
[gaim-migrate @ 8487]
Christian Hammond <chipx86@chipx86.com>
parents:
7652
diff
changeset
|
1401 g_free(msg); |
|
99ffabc6ce73
[gaim-migrate @ 8487]
Christian Hammond <chipx86@chipx86.com>
parents:
7652
diff
changeset
|
1402 } |
|
99ffabc6ce73
[gaim-migrate @ 8487]
Christian Hammond <chipx86@chipx86.com>
parents:
7652
diff
changeset
|
1403 } else { |
| 14096 | 1404 gaim_input_remove(connect_info->inpa); |
| 1405 connect_info->inpa = 0; | |
| 1406 g_free(connect_info->read_buffer); | |
| 1407 connect_info->read_buffer = NULL; | |
| 14089 | 1408 gaim_debug_info("proxy", "HTTP proxy connection established\n"); |
| 14103 | 1409 gaim_proxy_connect_info_connected(connect_info); |
|
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1410 return; |
|
1840
00aef397a1fe
[gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1705
diff
changeset
|
1411 } |
|
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1412 } |
| 9129 | 1413 |
|
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1414 |
|
1840
00aef397a1fe
[gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1705
diff
changeset
|
1415 |
|
5681
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
1416 static void |
|
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
1417 http_canwrite(gpointer data, gint source, GaimInputCondition cond) |
|
1840
00aef397a1fe
[gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1705
diff
changeset
|
1418 { |
| 4366 | 1419 char request[8192]; |
| 1420 int request_len = 0; | |
| 14097 | 1421 GaimProxyConnectInfo *connect_info = data; |
|
12991
c1b2ba353e85
[gaim-migrate @ 15344]
Richard Laager <rlaager@wiktel.com>
parents:
12977
diff
changeset
|
1422 socklen_t len; |
|
2048
3366311426df
[gaim-migrate @ 2058]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1881
diff
changeset
|
1423 int error = ETIMEDOUT; |
|
3717
988485669631
[gaim-migrate @ 3850]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3630
diff
changeset
|
1424 |
| 10309 | 1425 gaim_debug_info("http proxy", "Connected.\n"); |
|
5211
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
4993
diff
changeset
|
1426 |
| 14096 | 1427 if (connect_info->inpa > 0) |
| 14089 | 1428 { |
| 14096 | 1429 gaim_input_remove(connect_info->inpa); |
| 1430 connect_info->inpa = 0; | |
| 14089 | 1431 } |
|
5681
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
1432 |
|
1840
00aef397a1fe
[gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1705
diff
changeset
|
1433 len = sizeof(error); |
|
5681
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
1434 |
| 14103 | 1435 if (getsockopt(connect_info->fd, SOL_SOCKET, SO_ERROR, &error, &len) < 0) { |
| 1436 gaim_proxy_connect_info_disconnect(connect_info); | |
| 14096 | 1437 try_connect(connect_info); |
|
1840
00aef397a1fe
[gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1705
diff
changeset
|
1438 return; |
|
00aef397a1fe
[gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1705
diff
changeset
|
1439 } |
|
7834
99ffabc6ce73
[gaim-migrate @ 8487]
Christian Hammond <chipx86@chipx86.com>
parents:
7652
diff
changeset
|
1440 |
|
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1441 gaim_debug_info("proxy", "using CONNECT tunnelling for %s:%d\n", |
| 14096 | 1442 connect_info->host, connect_info->port); |
|
5681
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
1443 request_len = g_snprintf(request, sizeof(request), |
|
7834
99ffabc6ce73
[gaim-migrate @ 8487]
Christian Hammond <chipx86@chipx86.com>
parents:
7652
diff
changeset
|
1444 "CONNECT %s:%d HTTP/1.1\r\nHost: %s:%d\r\n", |
| 14096 | 1445 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
|
1446 |
| 14096 | 1447 if (gaim_proxy_info_get_username(connect_info->gpi) != NULL) { |
|
1843
4dbd8533d209
[gaim-migrate @ 1853]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1840
diff
changeset
|
1448 char *t1, *t2; |
|
5681
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
1449 t1 = g_strdup_printf("%s:%s", |
| 14096 | 1450 gaim_proxy_info_get_username(connect_info->gpi), |
| 1451 gaim_proxy_info_get_password(connect_info->gpi) ? | |
| 1452 gaim_proxy_info_get_password(connect_info->gpi) : ""); | |
| 11143 | 1453 t2 = gaim_base64_encode((const guchar *)t1, strlen(t1)); |
|
1843
4dbd8533d209
[gaim-migrate @ 1853]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1840
diff
changeset
|
1454 g_free(t1); |
| 4366 | 1455 g_return_if_fail(request_len < sizeof(request)); |
| 13386 | 1456 |
|
5681
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
1457 request_len += g_snprintf(request + request_len, |
|
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1458 sizeof(request) - request_len, |
|
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1459 "Proxy-Authorization: Basic %s\r\n" |
|
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1460 "Proxy-Authorization: NTLM %s\r\n" |
|
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1461 "Proxy-Connection: Keep-Alive\r\n", t2, |
|
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1462 gaim_ntlm_gen_type1( |
| 14096 | 1463 (gchar*)gaim_proxy_info_get_host(connect_info->gpi),"")); |
|
1843
4dbd8533d209
[gaim-migrate @ 1853]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1840
diff
changeset
|
1464 g_free(t2); |
|
4dbd8533d209
[gaim-migrate @ 1853]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1840
diff
changeset
|
1465 } |
|
4dbd8533d209
[gaim-migrate @ 1853]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1840
diff
changeset
|
1466 |
| 4366 | 1467 g_return_if_fail(request_len < sizeof(request)); |
| 1468 strcpy(request + request_len, "\r\n"); | |
| 1469 request_len += 2; | |
| 14096 | 1470 connect_info->write_buffer = g_memdup(request, request_len); |
| 1471 connect_info->write_buf_len = request_len; | |
| 1472 connect_info->written_len = 0; | |
|
5681
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
1473 |
| 14096 | 1474 connect_info->read_cb = http_canread; |
|
1840
00aef397a1fe
[gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1705
diff
changeset
|
1475 |
| 14103 | 1476 connect_info->inpa = gaim_input_add(connect_info->fd, GAIM_INPUT_WRITE, proxy_do_write, |
| 14096 | 1477 connect_info); |
|
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1478 |
| 14103 | 1479 proxy_do_write(connect_info, connect_info->fd, cond); |
|
1840
00aef397a1fe
[gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1705
diff
changeset
|
1480 } |
|
00aef397a1fe
[gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1705
diff
changeset
|
1481 |
|
5681
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
1482 static int |
| 14097 | 1483 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
|
1484 { |
| 10309 | 1485 gaim_debug_info("http proxy", |
|
5211
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
4993
diff
changeset
|
1486 "Connecting to %s:%d via %s:%d using HTTP\n", |
| 14096 | 1487 (connect_info->host ? connect_info->host : "(null)"), connect_info->port, |
| 1488 (gaim_proxy_info_get_host(connect_info->gpi) ? gaim_proxy_info_get_host(connect_info->gpi) : "(null)"), | |
| 1489 gaim_proxy_info_get_port(connect_info->gpi)); | |
|
1087
56c7ceb986a8
[gaim-migrate @ 1097]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1057
diff
changeset
|
1490 |
| 14103 | 1491 connect_info->fd = socket(addr->sa_family, SOCK_STREAM, 0); |
| 1492 if (connect_info->fd < 0) | |
|
1087
56c7ceb986a8
[gaim-migrate @ 1097]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1057
diff
changeset
|
1493 return -1; |
|
56c7ceb986a8
[gaim-migrate @ 1097]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1057
diff
changeset
|
1494 |
| 14103 | 1495 fcntl(connect_info->fd, F_SETFL, O_NONBLOCK); |
| 10172 | 1496 #ifndef _WIN32 |
| 14103 | 1497 fcntl(connect_info->fd, F_SETFD, FD_CLOEXEC); |
| 10172 | 1498 #endif |
|
3717
988485669631
[gaim-migrate @ 3850]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3630
diff
changeset
|
1499 |
| 14103 | 1500 if (connect(connect_info->fd, addr, addrlen) != 0) |
| 14099 | 1501 { |
|
1840
00aef397a1fe
[gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1705
diff
changeset
|
1502 if ((errno == EINPROGRESS) || (errno == EINTR)) { |
| 14103 | 1503 gaim_debug_info("http proxy", "Connection in progress\n"); |
| 9655 | 1504 |
| 14096 | 1505 if (connect_info->port != 80) { |
|
7834
99ffabc6ce73
[gaim-migrate @ 8487]
Christian Hammond <chipx86@chipx86.com>
parents:
7652
diff
changeset
|
1506 /* we need to do CONNECT first */ |
| 14103 | 1507 connect_info->inpa = gaim_input_add(connect_info->fd, GAIM_INPUT_WRITE, |
| 14096 | 1508 http_canwrite, connect_info); |
|
7834
99ffabc6ce73
[gaim-migrate @ 8487]
Christian Hammond <chipx86@chipx86.com>
parents:
7652
diff
changeset
|
1509 } else { |
| 14089 | 1510 gaim_debug_info("proxy", "HTTP proxy connection established\n"); |
| 14103 | 1511 gaim_proxy_connect_info_connected(connect_info); |
|
7834
99ffabc6ce73
[gaim-migrate @ 8487]
Christian Hammond <chipx86@chipx86.com>
parents:
7652
diff
changeset
|
1512 } |
|
1840
00aef397a1fe
[gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1705
diff
changeset
|
1513 } else { |
| 14103 | 1514 close(connect_info->fd); |
| 1515 connect_info->fd = -1; | |
|
1840
00aef397a1fe
[gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1705
diff
changeset
|
1516 return -1; |
|
00aef397a1fe
[gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1705
diff
changeset
|
1517 } |
|
5681
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
1518 } |
|
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
1519 else { |
|
12991
c1b2ba353e85
[gaim-migrate @ 15344]
Richard Laager <rlaager@wiktel.com>
parents:
12977
diff
changeset
|
1520 socklen_t len; |
|
2048
3366311426df
[gaim-migrate @ 2058]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1881
diff
changeset
|
1521 int error = ETIMEDOUT; |
|
3717
988485669631
[gaim-migrate @ 3850]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3630
diff
changeset
|
1522 |
| 14103 | 1523 gaim_debug_info("http proxy", "Connected immediately.\n"); |
|
5211
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
4993
diff
changeset
|
1524 |
|
1840
00aef397a1fe
[gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1705
diff
changeset
|
1525 len = sizeof(error); |
| 14103 | 1526 if (getsockopt(connect_info->fd, SOL_SOCKET, SO_ERROR, &error, &len) != 0) |
| 14099 | 1527 { |
| 14103 | 1528 close(connect_info->fd); |
| 1529 connect_info->fd = -1; | |
|
1840
00aef397a1fe
[gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1705
diff
changeset
|
1530 return -1; |
|
00aef397a1fe
[gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1705
diff
changeset
|
1531 } |
| 14103 | 1532 http_canwrite(connect_info, connect_info->fd, GAIM_INPUT_WRITE); |
|
1695
c0ab844d4790
[gaim-migrate @ 1705]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1451
diff
changeset
|
1533 } |
|
1840
00aef397a1fe
[gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1705
diff
changeset
|
1534 |
| 14103 | 1535 return connect_info->fd; |
|
1840
00aef397a1fe
[gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1705
diff
changeset
|
1536 } |
|
00aef397a1fe
[gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1705
diff
changeset
|
1537 |
|
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1538 |
|
5681
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
1539 static void |
|
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
1540 s4_canread(gpointer data, gint source, GaimInputCondition cond) |
|
1840
00aef397a1fe
[gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1705
diff
changeset
|
1541 { |
| 14097 | 1542 GaimProxyConnectInfo *connect_info = data; |
| 13386 | 1543 guchar *buf; |
|
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1544 int len, max_read; |
|
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1545 |
|
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1546 /* 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
|
1547 * be correct, we deal with the unlikely scenario */ |
|
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1548 |
| 14096 | 1549 if (connect_info->read_buffer == NULL) { |
| 1550 connect_info->read_buf_len = 12; | |
| 1551 connect_info->read_buffer = g_malloc(connect_info->read_buf_len); | |
| 1552 connect_info->read_len = 0; | |
|
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1553 } |
|
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1554 |
| 14096 | 1555 buf = connect_info->read_buffer + connect_info->read_len; |
| 1556 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
|
1557 |
| 14103 | 1558 len = read(connect_info->fd, buf, max_read); |
|
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1559 |
| 14096 | 1560 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
|
1561 return; |
| 14096 | 1562 else if (len + connect_info->read_len >= 4) { |
| 1563 if (connect_info->read_buffer[1] == 90) { | |
| 14103 | 1564 gaim_proxy_connect_info_connected(connect_info); |
|
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1565 return; |
|
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1566 } |
|
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1567 } |
|
1840
00aef397a1fe
[gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1705
diff
changeset
|
1568 |
| 14103 | 1569 gaim_proxy_connect_info_disconnect(connect_info); |
| 14096 | 1570 try_connect(connect_info); |
|
1840
00aef397a1fe
[gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1705
diff
changeset
|
1571 } |
|
1705
b4d454e5ee31
[gaim-migrate @ 1715]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1695
diff
changeset
|
1572 |
|
5681
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
1573 static void |
|
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
1574 s4_canwrite(gpointer data, gint source, GaimInputCondition cond) |
|
1840
00aef397a1fe
[gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1705
diff
changeset
|
1575 { |
|
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1576 unsigned char packet[9]; |
|
1840
00aef397a1fe
[gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1705
diff
changeset
|
1577 struct hostent *hp; |
| 14097 | 1578 GaimProxyConnectInfo *connect_info = data; |
|
12991
c1b2ba353e85
[gaim-migrate @ 15344]
Richard Laager <rlaager@wiktel.com>
parents:
12977
diff
changeset
|
1579 socklen_t len; |
|
2048
3366311426df
[gaim-migrate @ 2058]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1881
diff
changeset
|
1580 int error = ETIMEDOUT; |
|
3717
988485669631
[gaim-migrate @ 3850]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3630
diff
changeset
|
1581 |
|
11033
50224ac8184d
[gaim-migrate @ 12919]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10917
diff
changeset
|
1582 gaim_debug_info("socks4 proxy", "Connected.\n"); |
|
5211
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
4993
diff
changeset
|
1583 |
| 14096 | 1584 if (connect_info->inpa > 0) |
| 14089 | 1585 { |
| 14096 | 1586 gaim_input_remove(connect_info->inpa); |
| 1587 connect_info->inpa = 0; | |
| 14089 | 1588 } |
|
5681
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
1589 |
|
1840
00aef397a1fe
[gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1705
diff
changeset
|
1590 len = sizeof(error); |
|
5681
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
1591 |
| 14103 | 1592 if (getsockopt(connect_info->fd, SOL_SOCKET, SO_ERROR, &error, &len) < 0) { |
| 1593 gaim_proxy_connect_info_disconnect(connect_info); | |
| 14096 | 1594 try_connect(connect_info); |
|
1840
00aef397a1fe
[gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1705
diff
changeset
|
1595 return; |
|
00aef397a1fe
[gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1705
diff
changeset
|
1596 } |
|
3717
988485669631
[gaim-migrate @ 3850]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3630
diff
changeset
|
1597 |
| 10561 | 1598 /* |
| 1599 * The socks4 spec doesn't include support for doing host name | |
| 1600 * lookups by the proxy. Some socks4 servers do this via | |
| 1601 * extensions to the protocol. Since we don't know if a | |
| 1602 * server supports this, it would need to be implemented | |
| 1603 * with an option, or some detection mechanism - in the | |
| 1604 * meantime, stick with plain old SOCKS4. | |
| 1605 */ | |
| 14103 | 1606 /* TODO: This needs to be non-blocking! */ |
| 1607 hp = gethostbyname(connect_info->host); | |
| 1608 if (hp == NULL) { | |
| 1609 gaim_proxy_connect_info_disconnect(connect_info); | |
| 14096 | 1610 try_connect(connect_info); |
|
1840
00aef397a1fe
[gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1705
diff
changeset
|
1611 return; |
|
1087
56c7ceb986a8
[gaim-migrate @ 1097]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1057
diff
changeset
|
1612 } |
|
56c7ceb986a8
[gaim-migrate @ 1097]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1057
diff
changeset
|
1613 |
|
1840
00aef397a1fe
[gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1705
diff
changeset
|
1614 packet[0] = 4; |
|
00aef397a1fe
[gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1705
diff
changeset
|
1615 packet[1] = 1; |
| 14096 | 1616 packet[2] = connect_info->port >> 8; |
| 1617 packet[3] = connect_info->port & 0xff; | |
|
1840
00aef397a1fe
[gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1705
diff
changeset
|
1618 packet[4] = (unsigned char)(hp->h_addr_list[0])[0]; |
|
00aef397a1fe
[gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1705
diff
changeset
|
1619 packet[5] = (unsigned char)(hp->h_addr_list[0])[1]; |
|
00aef397a1fe
[gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1705
diff
changeset
|
1620 packet[6] = (unsigned char)(hp->h_addr_list[0])[2]; |
|
00aef397a1fe
[gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1705
diff
changeset
|
1621 packet[7] = (unsigned char)(hp->h_addr_list[0])[3]; |
|
00aef397a1fe
[gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1705
diff
changeset
|
1622 packet[8] = 0; |
|
3717
988485669631
[gaim-migrate @ 3850]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3630
diff
changeset
|
1623 |
| 14096 | 1624 connect_info->write_buffer = g_memdup(packet, sizeof(packet)); |
| 1625 connect_info->write_buf_len = sizeof(packet); | |
| 1626 connect_info->written_len = 0; | |
| 1627 connect_info->read_cb = s4_canread; | |
|
5681
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
1628 |
| 14103 | 1629 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
|
1630 |
| 14103 | 1631 proxy_do_write(connect_info, connect_info->fd, cond); |
| 1 | 1632 } |
| 1633 | |
|
5681
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
1634 static int |
| 14097 | 1635 proxy_connect_socks4(GaimProxyConnectInfo *connect_info, struct sockaddr *addr, socklen_t addrlen) |
| 1 | 1636 { |
| 10309 | 1637 gaim_debug_info("socks4 proxy", |
|
5211
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
4993
diff
changeset
|
1638 "Connecting to %s:%d via %s:%d using SOCKS4\n", |
| 14096 | 1639 connect_info->host, connect_info->port, |
| 1640 gaim_proxy_info_get_host(connect_info->gpi), | |
| 1641 gaim_proxy_info_get_port(connect_info->gpi)); | |
| 1 | 1642 |
| 14103 | 1643 connect_info->fd = socket(addr->sa_family, SOCK_STREAM, 0); |
| 1644 if (connect_info->fd < 0) | |
|
1087
56c7ceb986a8
[gaim-migrate @ 1097]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1057
diff
changeset
|
1645 return -1; |
| 1 | 1646 |
| 14103 | 1647 fcntl(connect_info->fd, F_SETFL, O_NONBLOCK); |
| 10172 | 1648 #ifndef _WIN32 |
| 14103 | 1649 fcntl(connect_info->fd, F_SETFD, FD_CLOEXEC); |
| 10172 | 1650 #endif |
|
5681
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
1651 |
| 14103 | 1652 if (connect(connect_info->fd, addr, addrlen) != 0) |
| 14099 | 1653 { |
|
1840
00aef397a1fe
[gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1705
diff
changeset
|
1654 if ((errno == EINPROGRESS) || (errno == EINTR)) { |
| 14103 | 1655 gaim_debug_info("socks4 proxy", "Connection in progress.\n"); |
| 1656 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
|
1657 } |
|
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
1658 else { |
| 14103 | 1659 close(connect_info->fd); |
| 1660 connect_info->fd = -1; | |
|
1840
00aef397a1fe
[gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1705
diff
changeset
|
1661 return -1; |
|
00aef397a1fe
[gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1705
diff
changeset
|
1662 } |
|
00aef397a1fe
[gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1705
diff
changeset
|
1663 } else { |
|
12991
c1b2ba353e85
[gaim-migrate @ 15344]
Richard Laager <rlaager@wiktel.com>
parents:
12977
diff
changeset
|
1664 socklen_t len; |
|
2048
3366311426df
[gaim-migrate @ 2058]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1881
diff
changeset
|
1665 int error = ETIMEDOUT; |
|
3717
988485669631
[gaim-migrate @ 3850]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3630
diff
changeset
|
1666 |
| 14103 | 1667 gaim_debug_info("socks4 proxy", "Connected immediately.\n"); |
|
5211
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
4993
diff
changeset
|
1668 |
|
1840
00aef397a1fe
[gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1705
diff
changeset
|
1669 len = sizeof(error); |
|
5681
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
1670 |
| 14103 | 1671 if (getsockopt(connect_info->fd, SOL_SOCKET, SO_ERROR, &error, &len) != 0) |
| 14099 | 1672 { |
| 14103 | 1673 close(connect_info->fd); |
| 1674 connect_info->fd = -1; | |
|
1840
00aef397a1fe
[gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1705
diff
changeset
|
1675 return -1; |
|
00aef397a1fe
[gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1705
diff
changeset
|
1676 } |
|
5681
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
1677 |
| 14103 | 1678 s4_canwrite(connect_info, connect_info->fd, GAIM_INPUT_WRITE); |
|
1840
00aef397a1fe
[gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1705
diff
changeset
|
1679 } |
|
670
9e51c1a4abba
[gaim-migrate @ 680]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
664
diff
changeset
|
1680 |
| 14103 | 1681 return connect_info->fd; |
|
1840
00aef397a1fe
[gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1705
diff
changeset
|
1682 } |
|
00aef397a1fe
[gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1705
diff
changeset
|
1683 |
|
5681
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
1684 static void |
|
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
1685 s5_canread_again(gpointer data, gint source, GaimInputCondition cond) |
|
1840
00aef397a1fe
[gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1705
diff
changeset
|
1686 { |
|
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1687 guchar *dest, *buf; |
| 14097 | 1688 GaimProxyConnectInfo *connect_info = data; |
|
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1689 int len; |
|
1840
00aef397a1fe
[gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1705
diff
changeset
|
1690 |
| 14096 | 1691 if (connect_info->read_buffer == NULL) { |
| 1692 connect_info->read_buf_len = 512; | |
| 1693 connect_info->read_buffer = g_malloc(connect_info->read_buf_len); | |
| 1694 connect_info->read_len = 0; | |
|
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1695 } |
|
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1696 |
| 14096 | 1697 dest = connect_info->read_buffer + connect_info->read_len; |
| 1698 buf = connect_info->read_buffer; | |
|
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1699 |
| 10309 | 1700 gaim_debug_info("socks5 proxy", "Able to read again.\n"); |
|
1840
00aef397a1fe
[gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1705
diff
changeset
|
1701 |
| 14103 | 1702 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
|
1703 if(len < 0 && errno == EAGAIN) |
|
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1704 return; |
|
13786
5ddde4ad1ca2
[gaim-migrate @ 16198]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13752
diff
changeset
|
1705 else if(len <= 0) { |
| 10309 | 1706 gaim_debug_warning("socks5 proxy", "or not...\n"); |
| 14103 | 1707 gaim_proxy_connect_info_disconnect(connect_info); |
| 14096 | 1708 try_connect(connect_info); |
|
1840
00aef397a1fe
[gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1705
diff
changeset
|
1709 return; |
|
1087
56c7ceb986a8
[gaim-migrate @ 1097]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1057
diff
changeset
|
1710 } |
| 14096 | 1711 connect_info->read_len += len; |
|
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1712 |
| 14096 | 1713 if(connect_info->read_len < 4) |
|
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1714 return; |
|
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1715 |
|
1840
00aef397a1fe
[gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1705
diff
changeset
|
1716 if ((buf[0] != 0x05) || (buf[1] != 0x00)) { |
| 7982 | 1717 if ((buf[0] == 0x05) && (buf[1] < 0x09)) |
| 10309 | 1718 gaim_debug_error("socks5 proxy", socks5errors[buf[1]]); |
| 7982 | 1719 else |
| 10309 | 1720 gaim_debug_error("socks5 proxy", "Bad data.\n"); |
| 14103 | 1721 gaim_proxy_connect_info_disconnect(connect_info); |
| 14096 | 1722 try_connect(connect_info); |
|
1840
00aef397a1fe
[gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1705
diff
changeset
|
1723 return; |
|
00aef397a1fe
[gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1705
diff
changeset
|
1724 } |
|
670
9e51c1a4abba
[gaim-migrate @ 680]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
664
diff
changeset
|
1725 |
| 8262 | 1726 /* Skip past BND.ADDR */ |
| 1727 switch(buf[3]) { | |
| 1728 case 0x01: /* the address is a version-4 IP address, with a length of 4 octets */ | |
| 14096 | 1729 if(connect_info->read_len < 4 + 4) |
|
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1730 return; |
|
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1731 buf += 4 + 4; |
| 8262 | 1732 break; |
| 1733 case 0x03: /* the address field contains a fully-qualified domain name. The first | |
| 1734 octet of the address field contains the number of octets of name that | |
| 1735 follow, there is no terminating NUL octet. */ | |
| 14096 | 1736 if(connect_info->read_len < 4 + 1) |
|
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1737 return; |
|
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1738 buf += 4 + 1; |
| 14096 | 1739 if(connect_info->read_len < 4 + 1 + buf[0]) |
|
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1740 return; |
|
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1741 buf += buf[0]; |
| 8262 | 1742 break; |
| 1743 case 0x04: /* the address is a version-6 IP address, with a length of 16 octets */ | |
| 14096 | 1744 if(connect_info->read_len < 4 + 16) |
|
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1745 return; |
|
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1746 buf += 4 + 16; |
| 8262 | 1747 break; |
| 1748 } | |
| 1749 | |
| 14096 | 1750 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
|
1751 return; |
|
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1752 |
| 8262 | 1753 /* Skip past BND.PORT */ |
|
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1754 buf += 2; |
| 8262 | 1755 |
| 14103 | 1756 gaim_proxy_connect_info_connected(connect_info); |
| 1 | 1757 } |
| 1758 | |
|
5681
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
1759 static void |
| 14089 | 1760 s5_sendconnect(gpointer data, int source) |
|
1087
56c7ceb986a8
[gaim-migrate @ 1097]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1057
diff
changeset
|
1761 { |
| 14097 | 1762 GaimProxyConnectInfo *connect_info = data; |
| 14096 | 1763 int hlen = strlen(connect_info->host); |
| 1764 connect_info->write_buf_len = 5 + hlen + 2; | |
| 1765 connect_info->write_buffer = g_malloc(connect_info->write_buf_len); | |
| 1766 connect_info->written_len = 0; | |
|
1840
00aef397a1fe
[gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1705
diff
changeset
|
1767 |
| 14096 | 1768 connect_info->write_buffer[0] = 0x05; |
| 1769 connect_info->write_buffer[1] = 0x01; /* CONNECT */ | |
| 1770 connect_info->write_buffer[2] = 0x00; /* reserved */ | |
| 1771 connect_info->write_buffer[3] = 0x03; /* address type -- host name */ | |
| 1772 connect_info->write_buffer[4] = hlen; | |
| 1773 memcpy(connect_info->write_buffer + 5, connect_info->host, hlen); | |
| 1774 connect_info->write_buffer[5 + hlen] = connect_info->port >> 8; | |
| 1775 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
|
1776 |
| 14096 | 1777 connect_info->read_cb = s5_canread_again; |
|
5681
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
1778 |
| 14103 | 1779 connect_info->inpa = gaim_input_add(connect_info->fd, GAIM_INPUT_WRITE, proxy_do_write, connect_info); |
| 1780 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
|
1781 } |
|
1087
56c7ceb986a8
[gaim-migrate @ 1097]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1057
diff
changeset
|
1782 |
|
5681
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
1783 static void |
|
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
1784 s5_readauth(gpointer data, gint source, GaimInputCondition cond) |
|
1844
9845deede1e9
[gaim-migrate @ 1854]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1843
diff
changeset
|
1785 { |
| 14097 | 1786 GaimProxyConnectInfo *connect_info = data; |
|
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1787 int len; |
|
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1788 |
| 14096 | 1789 if (connect_info->read_buffer == NULL) { |
| 1790 connect_info->read_buf_len = 2; | |
| 1791 connect_info->read_buffer = g_malloc(connect_info->read_buf_len); | |
| 1792 connect_info->read_len = 0; | |
|
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1793 } |
|
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1794 |
|
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1795 gaim_debug_info("socks5 proxy", "Got auth response.\n"); |
|
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1796 |
| 14103 | 1797 len = read(connect_info->fd, connect_info->read_buffer + connect_info->read_len, |
| 14096 | 1798 connect_info->read_buf_len - connect_info->read_len); |
|
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1799 if(len < 0 && errno == EAGAIN) |
|
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1800 return; |
|
13786
5ddde4ad1ca2
[gaim-migrate @ 16198]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13752
diff
changeset
|
1801 else if(len <= 0) { |
| 14103 | 1802 gaim_proxy_connect_info_disconnect(connect_info); |
| 14096 | 1803 try_connect(connect_info); |
|
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1804 return; |
|
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1805 } |
| 14096 | 1806 connect_info->read_len += len; |
|
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1807 |
| 14096 | 1808 if (connect_info->read_len < 2) |
|
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1809 return; |
|
1844
9845deede1e9
[gaim-migrate @ 1854]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1843
diff
changeset
|
1810 |
| 14096 | 1811 gaim_input_remove(connect_info->inpa); |
| 1812 connect_info->inpa = 0; | |
|
1844
9845deede1e9
[gaim-migrate @ 1854]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1843
diff
changeset
|
1813 |
| 14096 | 1814 if ((connect_info->read_buffer[0] != 0x01) || (connect_info->read_buffer[1] != 0x00)) { |
| 14103 | 1815 gaim_proxy_connect_info_disconnect(connect_info); |
| 14096 | 1816 try_connect(connect_info); |
|
1844
9845deede1e9
[gaim-migrate @ 1854]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1843
diff
changeset
|
1817 return; |
|
9845deede1e9
[gaim-migrate @ 1854]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1843
diff
changeset
|
1818 } |
|
9845deede1e9
[gaim-migrate @ 1854]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1843
diff
changeset
|
1819 |
| 14096 | 1820 g_free(connect_info->read_buffer); |
| 1821 connect_info->read_buffer = NULL; | |
|
1844
9845deede1e9
[gaim-migrate @ 1854]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1843
diff
changeset
|
1822 |
| 14103 | 1823 s5_sendconnect(connect_info, connect_info->fd); |
|
1844
9845deede1e9
[gaim-migrate @ 1854]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1843
diff
changeset
|
1824 } |
|
9845deede1e9
[gaim-migrate @ 1854]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1843
diff
changeset
|
1825 |
| 14097 | 1826 static void |
| 1827 hmacmd5_chap(const unsigned char * challenge, int challen, const char * passwd, unsigned char * response) | |
| 10561 | 1828 { |
|
10684
72a5babfa8b4
[gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
10626
diff
changeset
|
1829 GaimCipher *cipher; |
|
72a5babfa8b4
[gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
10626
diff
changeset
|
1830 GaimCipherContext *ctx; |
| 10561 | 1831 int i; |
| 1832 unsigned char Kxoripad[65]; | |
| 1833 unsigned char Kxoropad[65]; | |
| 1834 int pwlen; | |
| 1835 | |
|
10684
72a5babfa8b4
[gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
10626
diff
changeset
|
1836 cipher = gaim_ciphers_find_cipher("md5"); |
|
72a5babfa8b4
[gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
10626
diff
changeset
|
1837 ctx = gaim_cipher_context_new(cipher, NULL); |
|
72a5babfa8b4
[gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
10626
diff
changeset
|
1838 |
| 12765 | 1839 memset(Kxoripad,0,sizeof(Kxoripad)); |
| 1840 memset(Kxoropad,0,sizeof(Kxoropad)); | |
| 1841 | |
| 10561 | 1842 pwlen=strlen(passwd); |
| 1843 if (pwlen>64) { | |
| 11183 | 1844 gaim_cipher_context_append(ctx, (const guchar *)passwd, strlen(passwd)); |
| 12765 | 1845 gaim_cipher_context_digest(ctx, sizeof(Kxoripad), Kxoripad, NULL); |
| 10561 | 1846 pwlen=16; |
| 12765 | 1847 } else { |
| 1848 memcpy(Kxoripad, passwd, pwlen); | |
| 10561 | 1849 } |
| 12765 | 1850 memcpy(Kxoropad,Kxoripad,pwlen); |
| 10561 | 1851 |
| 1852 for (i=0;i<64;i++) { | |
| 1853 Kxoripad[i]^=0x36; | |
| 1854 Kxoropad[i]^=0x5c; | |
| 1855 } | |
|
10684
72a5babfa8b4
[gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
10626
diff
changeset
|
1856 |
|
72a5babfa8b4
[gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
10626
diff
changeset
|
1857 gaim_cipher_context_reset(ctx, NULL); |
|
72a5babfa8b4
[gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
10626
diff
changeset
|
1858 gaim_cipher_context_append(ctx, Kxoripad, 64); |
|
72a5babfa8b4
[gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
10626
diff
changeset
|
1859 gaim_cipher_context_append(ctx, challenge, challen); |
|
10687
b256ce6b85b8
[gaim-migrate @ 12235]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10684
diff
changeset
|
1860 gaim_cipher_context_digest(ctx, sizeof(Kxoripad), Kxoripad, NULL); |
| 10561 | 1861 |
|
10684
72a5babfa8b4
[gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
10626
diff
changeset
|
1862 gaim_cipher_context_reset(ctx, NULL); |
|
72a5babfa8b4
[gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
10626
diff
changeset
|
1863 gaim_cipher_context_append(ctx, Kxoropad, 64); |
|
72a5babfa8b4
[gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
10626
diff
changeset
|
1864 gaim_cipher_context_append(ctx, Kxoripad, 16); |
| 12765 | 1865 gaim_cipher_context_digest(ctx, 16, response, NULL); |
|
10684
72a5babfa8b4
[gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
10626
diff
changeset
|
1866 |
|
72a5babfa8b4
[gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
10626
diff
changeset
|
1867 gaim_cipher_context_destroy(ctx); |
| 10561 | 1868 } |
| 1869 | |
| 1870 static void | |
| 1871 s5_readchap(gpointer data, gint source, GaimInputCondition cond) | |
| 1872 { | |
|
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1873 guchar *cmdbuf, *buf; |
| 14097 | 1874 GaimProxyConnectInfo *connect_info = data; |
|
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1875 int len, navas, currentav; |
| 10561 | 1876 |
| 1877 gaim_debug(GAIM_DEBUG_INFO, "socks5 proxy", "Got CHAP response.\n"); | |
| 1878 | |
| 14096 | 1879 if (connect_info->read_buffer == NULL) { |
| 1880 connect_info->read_buf_len = 20; | |
| 1881 connect_info->read_buffer = g_malloc(connect_info->read_buf_len); | |
| 1882 connect_info->read_len = 0; | |
|
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1883 } |
|
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1884 |
| 14103 | 1885 len = read(connect_info->fd, connect_info->read_buffer + connect_info->read_len, |
| 14096 | 1886 connect_info->read_buf_len - connect_info->read_len); |
|
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1887 |
|
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1888 if(len < 0 && errno == EAGAIN) |
|
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1889 return; |
|
13786
5ddde4ad1ca2
[gaim-migrate @ 16198]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13752
diff
changeset
|
1890 else if(len <= 0) { |
| 14103 | 1891 gaim_proxy_connect_info_disconnect(connect_info); |
| 14096 | 1892 try_connect(connect_info); |
| 10561 | 1893 return; |
| 1894 } | |
| 14096 | 1895 connect_info->read_len += len; |
| 10561 | 1896 |
| 14096 | 1897 if (connect_info->read_len < 2) |
|
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1898 return; |
|
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1899 |
| 14096 | 1900 cmdbuf = connect_info->read_buffer; |
|
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1901 |
|
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1902 if (*cmdbuf != 0x01) { |
| 14103 | 1903 gaim_proxy_connect_info_disconnect(connect_info); |
| 14096 | 1904 try_connect(connect_info); |
| 10561 | 1905 return; |
| 1906 } | |
|
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1907 cmdbuf++; |
| 10561 | 1908 |
|
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1909 navas = *cmdbuf; |
|
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1910 cmdbuf++; |
| 10561 | 1911 |
| 1912 for (currentav = 0; currentav < navas; currentav++) { | |
| 14096 | 1913 if (connect_info->read_len - (cmdbuf - connect_info->read_buffer) < 2) |
| 10561 | 1914 return; |
| 14096 | 1915 if (connect_info->read_len - (cmdbuf - connect_info->read_buffer) < cmdbuf[1]) |
| 10561 | 1916 return; |
|
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1917 buf = cmdbuf + 2; |
| 10561 | 1918 switch (cmdbuf[0]) { |
| 1919 case 0x00: | |
| 1920 /* Did auth work? */ | |
| 1921 if (buf[0] == 0x00) { | |
| 14096 | 1922 gaim_input_remove(connect_info->inpa); |
| 1923 connect_info->inpa = 0; | |
| 1924 g_free(connect_info->read_buffer); | |
| 1925 connect_info->read_buffer = NULL; | |
| 10561 | 1926 /* Success */ |
| 14103 | 1927 s5_sendconnect(connect_info, connect_info->fd); |
| 10613 | 1928 return; |
| 10561 | 1929 } else { |
| 1930 /* Failure */ | |
|
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1931 gaim_debug_warning("proxy", |
|
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1932 "socks5 CHAP authentication " |
|
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1933 "failed. Disconnecting..."); |
| 14103 | 1934 gaim_proxy_connect_info_disconnect(connect_info); |
| 14096 | 1935 try_connect(connect_info); |
| 10561 | 1936 return; |
| 1937 } | |
| 1938 break; | |
| 1939 case 0x03: | |
| 1940 /* Server wants our credentials */ | |
|
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1941 |
| 14096 | 1942 connect_info->write_buf_len = 16 + 4; |
| 1943 connect_info->write_buffer = g_malloc(connect_info->write_buf_len); | |
| 1944 connect_info->written_len = 0; | |
|
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1945 |
| 10561 | 1946 hmacmd5_chap(buf, cmdbuf[1], |
| 14096 | 1947 gaim_proxy_info_get_password(connect_info->gpi), |
| 1948 connect_info->write_buffer + 4); | |
| 1949 connect_info->write_buffer[0] = 0x01; | |
| 1950 connect_info->write_buffer[1] = 0x01; | |
| 1951 connect_info->write_buffer[2] = 0x04; | |
| 1952 connect_info->write_buffer[3] = 0x10; | |
| 10561 | 1953 |
| 14096 | 1954 gaim_input_remove(connect_info->inpa); |
| 1955 g_free(connect_info->read_buffer); | |
| 1956 connect_info->read_buffer = NULL; | |
|
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1957 |
| 14096 | 1958 connect_info->read_cb = s5_readchap; |
|
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1959 |
| 14103 | 1960 connect_info->inpa = gaim_input_add(connect_info->fd, |
| 14096 | 1961 GAIM_INPUT_WRITE, proxy_do_write, connect_info); |
|
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1962 |
| 14103 | 1963 proxy_do_write(connect_info, connect_info->fd, GAIM_INPUT_WRITE); |
| 10561 | 1964 break; |
| 1965 case 0x11: | |
| 1966 /* Server wants to select an algorithm */ | |
| 1967 if (buf[0] != 0x85) { | |
| 1968 /* Only currently support HMAC-MD5 */ | |
|
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1969 gaim_debug_warning("proxy", |
|
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1970 "Server tried to select an " |
|
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1971 "algorithm that we did not advertise " |
|
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1972 "as supporting. This is a violation " |
|
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1973 "of the socks5 CHAP specification. " |
|
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1974 "Disconnecting..."); |
| 14103 | 1975 gaim_proxy_connect_info_disconnect(connect_info); |
| 14096 | 1976 try_connect(connect_info); |
| 10561 | 1977 return; |
| 1978 } | |
| 1979 break; | |
| 1980 } | |
|
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1981 cmdbuf = buf + cmdbuf[1]; |
| 10561 | 1982 } |
| 1983 /* Fell through. We ran out of CHAP events to process, but haven't | |
| 1984 * succeeded or failed authentication - there may be more to come. | |
| 1985 * If this is the case, come straight back here. */ | |
| 1986 } | |
| 1987 | |
|
5681
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
1988 static void |
|
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
1989 s5_canread(gpointer data, gint source, GaimInputCondition cond) |
|
1844
9845deede1e9
[gaim-migrate @ 1854]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1843
diff
changeset
|
1990 { |
| 14097 | 1991 GaimProxyConnectInfo *connect_info = data; |
|
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1992 int len; |
|
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1993 |
| 14096 | 1994 if (connect_info->read_buffer == NULL) { |
| 1995 connect_info->read_buf_len = 2; | |
| 1996 connect_info->read_buffer = g_malloc(connect_info->read_buf_len); | |
| 1997 connect_info->read_len = 0; | |
|
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1998 } |
|
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
1999 |
|
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
2000 gaim_debug_info("socks5 proxy", "Able to read.\n"); |
|
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
2001 |
| 14103 | 2002 len = read(connect_info->fd, connect_info->read_buffer + connect_info->read_len, |
| 14096 | 2003 connect_info->read_buf_len - connect_info->read_len); |
|
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
2004 if(len < 0 && errno == EAGAIN) |
|
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
2005 return; |
|
13786
5ddde4ad1ca2
[gaim-migrate @ 16198]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13752
diff
changeset
|
2006 else if(len <= 0) { |
| 14103 | 2007 gaim_proxy_connect_info_disconnect(connect_info); |
| 14096 | 2008 try_connect(connect_info); |
|
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
2009 return; |
|
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
2010 } |
| 14096 | 2011 connect_info->read_len += len; |
|
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
2012 |
| 14096 | 2013 if (connect_info->read_len < 2) |
|
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
2014 return; |
|
1844
9845deede1e9
[gaim-migrate @ 1854]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1843
diff
changeset
|
2015 |
| 14096 | 2016 gaim_input_remove(connect_info->inpa); |
| 2017 connect_info->inpa = 0; | |
|
1844
9845deede1e9
[gaim-migrate @ 1854]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1843
diff
changeset
|
2018 |
| 14096 | 2019 if ((connect_info->read_buffer[0] != 0x05) || (connect_info->read_buffer[1] == 0xff)) { |
| 14103 | 2020 gaim_proxy_connect_info_disconnect(connect_info); |
| 14096 | 2021 try_connect(connect_info); |
|
1844
9845deede1e9
[gaim-migrate @ 1854]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1843
diff
changeset
|
2022 return; |
|
9845deede1e9
[gaim-migrate @ 1854]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1843
diff
changeset
|
2023 } |
|
9845deede1e9
[gaim-migrate @ 1854]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1843
diff
changeset
|
2024 |
| 14096 | 2025 if (connect_info->read_buffer[1] == 0x02) { |
|
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
2026 gsize i, j; |
| 10912 | 2027 const char *u, *p; |
| 9129 | 2028 |
| 14096 | 2029 u = gaim_proxy_info_get_username(connect_info->gpi); |
| 2030 p = gaim_proxy_info_get_password(connect_info->gpi); | |
| 10912 | 2031 |
| 2032 i = (u == NULL) ? 0 : strlen(u); | |
| 2033 j = (p == NULL) ? 0 : strlen(p); | |
|
5681
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
2034 |
| 14096 | 2035 connect_info->write_buf_len = 1 + 1 + i + 1 + j; |
| 2036 connect_info->write_buffer = g_malloc(connect_info->write_buf_len); | |
| 2037 connect_info->written_len = 0; | |
|
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
2038 |
| 14096 | 2039 connect_info->write_buffer[0] = 0x01; /* version 1 */ |
| 2040 connect_info->write_buffer[1] = i; | |
| 10917 | 2041 if (u != NULL) |
| 14096 | 2042 memcpy(connect_info->write_buffer + 2, u, i); |
| 2043 connect_info->write_buffer[2 + i] = j; | |
| 10917 | 2044 if (p != NULL) |
| 14096 | 2045 memcpy(connect_info->write_buffer + 2 + i + 1, p, j); |
|
3717
988485669631
[gaim-migrate @ 3850]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3630
diff
changeset
|
2046 |
| 14096 | 2047 g_free(connect_info->read_buffer); |
| 2048 connect_info->read_buffer = NULL; | |
|
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
2049 |
| 14096 | 2050 connect_info->read_cb = s5_readauth; |
|
5681
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
2051 |
| 14103 | 2052 connect_info->inpa = gaim_input_add(connect_info->fd, GAIM_INPUT_WRITE, |
| 14096 | 2053 proxy_do_write, connect_info); |
|
1844
9845deede1e9
[gaim-migrate @ 1854]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1843
diff
changeset
|
2054 |
| 14103 | 2055 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
|
2056 |
|
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
2057 return; |
| 14096 | 2058 } else if (connect_info->read_buffer[1] == 0x03) { |
|
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
2059 gsize userlen; |
| 14096 | 2060 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
|
2061 |
| 14096 | 2062 connect_info->write_buf_len = 7 + userlen; |
| 2063 connect_info->write_buffer = g_malloc(connect_info->write_buf_len); | |
| 2064 connect_info->written_len = 0; | |
|
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
2065 |
| 14096 | 2066 connect_info->write_buffer[0] = 0x01; |
| 2067 connect_info->write_buffer[1] = 0x02; | |
| 2068 connect_info->write_buffer[2] = 0x11; | |
| 2069 connect_info->write_buffer[3] = 0x01; | |
| 2070 connect_info->write_buffer[4] = 0x85; | |
| 2071 connect_info->write_buffer[5] = 0x02; | |
| 2072 connect_info->write_buffer[6] = userlen; | |
| 2073 memcpy(connect_info->write_buffer + 7, | |
| 2074 gaim_proxy_info_get_username(connect_info->gpi), userlen); | |
| 10561 | 2075 |
| 14096 | 2076 g_free(connect_info->read_buffer); |
| 2077 connect_info->read_buffer = NULL; | |
|
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
2078 |
| 14096 | 2079 connect_info->read_cb = s5_readchap; |
|
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
2080 |
| 14103 | 2081 connect_info->inpa = gaim_input_add(connect_info->fd, GAIM_INPUT_WRITE, |
| 14096 | 2082 proxy_do_write, connect_info); |
| 10561 | 2083 |
| 14103 | 2084 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
|
2085 |
|
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
2086 return; |
|
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
2087 } else { |
| 14096 | 2088 g_free(connect_info->read_buffer); |
| 2089 connect_info->read_buffer = NULL; | |
|
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
2090 |
| 14103 | 2091 s5_sendconnect(connect_info, connect_info->fd); |
|
1844
9845deede1e9
[gaim-migrate @ 1854]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1843
diff
changeset
|
2092 } |
|
9845deede1e9
[gaim-migrate @ 1854]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1843
diff
changeset
|
2093 } |
|
9845deede1e9
[gaim-migrate @ 1854]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1843
diff
changeset
|
2094 |
|
5681
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
2095 static void |
|
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
2096 s5_canwrite(gpointer data, gint source, GaimInputCondition cond) |
|
1840
00aef397a1fe
[gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1705
diff
changeset
|
2097 { |
|
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
2098 unsigned char buf[5]; |
|
1840
00aef397a1fe
[gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1705
diff
changeset
|
2099 int i; |
| 14097 | 2100 GaimProxyConnectInfo *connect_info = data; |
|
12991
c1b2ba353e85
[gaim-migrate @ 15344]
Richard Laager <rlaager@wiktel.com>
parents:
12977
diff
changeset
|
2101 socklen_t len; |
|
2048
3366311426df
[gaim-migrate @ 2058]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1881
diff
changeset
|
2102 int error = ETIMEDOUT; |
|
3717
988485669631
[gaim-migrate @ 3850]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3630
diff
changeset
|
2103 |
| 10309 | 2104 gaim_debug_info("socks5 proxy", "Connected.\n"); |
|
5211
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
4993
diff
changeset
|
2105 |
| 14096 | 2106 if (connect_info->inpa > 0) |
| 14089 | 2107 { |
| 14096 | 2108 gaim_input_remove(connect_info->inpa); |
| 2109 connect_info->inpa = 0; | |
| 14089 | 2110 } |
|
5681
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
2111 |
|
1840
00aef397a1fe
[gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1705
diff
changeset
|
2112 len = sizeof(error); |
| 14103 | 2113 if (getsockopt(connect_info->fd, SOL_SOCKET, SO_ERROR, &error, &len) < 0) { |
| 2114 gaim_proxy_connect_info_disconnect(connect_info); | |
| 14096 | 2115 try_connect(connect_info); |
|
1840
00aef397a1fe
[gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1705
diff
changeset
|
2116 return; |
|
1087
56c7ceb986a8
[gaim-migrate @ 1097]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1057
diff
changeset
|
2117 } |
|
56c7ceb986a8
[gaim-migrate @ 1097]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1057
diff
changeset
|
2118 |
|
56c7ceb986a8
[gaim-migrate @ 1097]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1057
diff
changeset
|
2119 i = 0; |
|
1252
46c09828e929
[gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1087
diff
changeset
|
2120 buf[0] = 0x05; /* SOCKS version 5 */ |
|
5681
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
2121 |
| 14096 | 2122 if (gaim_proxy_info_get_username(connect_info->gpi) != NULL) { |
| 10561 | 2123 buf[1] = 0x03; /* three methods */ |
|
1844
9845deede1e9
[gaim-migrate @ 1854]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1843
diff
changeset
|
2124 buf[2] = 0x00; /* no authentication */ |
| 10561 | 2125 buf[3] = 0x03; /* CHAP authentication */ |
| 2126 buf[4] = 0x02; /* username/password authentication */ | |
| 2127 i = 5; | |
|
5681
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
2128 } |
|
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
2129 else { |
|
1844
9845deede1e9
[gaim-migrate @ 1854]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1843
diff
changeset
|
2130 buf[1] = 0x01; |
|
9845deede1e9
[gaim-migrate @ 1854]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1843
diff
changeset
|
2131 buf[2] = 0x00; |
|
9845deede1e9
[gaim-migrate @ 1854]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1843
diff
changeset
|
2132 i = 3; |
|
9845deede1e9
[gaim-migrate @ 1854]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1843
diff
changeset
|
2133 } |
|
3717
988485669631
[gaim-migrate @ 3850]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3630
diff
changeset
|
2134 |
| 14096 | 2135 connect_info->write_buf_len = i; |
| 2136 connect_info->write_buffer = g_malloc(connect_info->write_buf_len); | |
| 2137 memcpy(connect_info->write_buffer, buf, i); | |
|
5681
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
2138 |
| 14096 | 2139 connect_info->read_cb = s5_canread; |
|
1087
56c7ceb986a8
[gaim-migrate @ 1097]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1057
diff
changeset
|
2140 |
| 14103 | 2141 connect_info->inpa = gaim_input_add(connect_info->fd, GAIM_INPUT_WRITE, proxy_do_write, connect_info); |
| 2142 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
|
2143 } |
|
1087
56c7ceb986a8
[gaim-migrate @ 1097]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1057
diff
changeset
|
2144 |
|
5681
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
2145 static int |
| 14097 | 2146 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
|
2147 { |
| 10309 | 2148 gaim_debug_info("socks5 proxy", |
|
5211
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
4993
diff
changeset
|
2149 "Connecting to %s:%d via %s:%d using SOCKS5\n", |
| 14096 | 2150 connect_info->host, connect_info->port, |
| 2151 gaim_proxy_info_get_host(connect_info->gpi), | |
| 2152 gaim_proxy_info_get_port(connect_info->gpi)); | |
|
1840
00aef397a1fe
[gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1705
diff
changeset
|
2153 |
| 14103 | 2154 connect_info->fd = socket(addr->sa_family, SOCK_STREAM, 0); |
| 2155 if (connect_info->fd < 0) | |
|
1087
56c7ceb986a8
[gaim-migrate @ 1097]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1057
diff
changeset
|
2156 return -1; |
|
56c7ceb986a8
[gaim-migrate @ 1097]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1057
diff
changeset
|
2157 |
| 14103 | 2158 fcntl(connect_info->fd, F_SETFL, O_NONBLOCK); |
| 10172 | 2159 #ifndef _WIN32 |
| 14103 | 2160 fcntl(connect_info->fd, F_SETFD, FD_CLOEXEC); |
| 10172 | 2161 #endif |
|
5681
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
2162 |
| 14103 | 2163 if (connect(connect_info->fd, addr, addrlen) != 0) |
| 14099 | 2164 { |
|
1840
00aef397a1fe
[gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1705
diff
changeset
|
2165 if ((errno == EINPROGRESS) || (errno == EINTR)) { |
| 14103 | 2166 gaim_debug_info("socks5 proxy", "Connection in progress\n"); |
| 2167 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
|
2168 } |
|
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
2169 else { |
| 14103 | 2170 close(connect_info->fd); |
| 2171 connect_info->fd = -1; | |
|
1840
00aef397a1fe
[gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1705
diff
changeset
|
2172 return -1; |
|
00aef397a1fe
[gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1705
diff
changeset
|
2173 } |
|
5681
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
2174 } |
|
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
2175 else { |
|
12991
c1b2ba353e85
[gaim-migrate @ 15344]
Richard Laager <rlaager@wiktel.com>
parents:
12977
diff
changeset
|
2176 socklen_t len; |
|
2048
3366311426df
[gaim-migrate @ 2058]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1881
diff
changeset
|
2177 int error = ETIMEDOUT; |
|
3717
988485669631
[gaim-migrate @ 3850]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3630
diff
changeset
|
2178 |
| 14103 | 2179 gaim_debug_info("socks5 proxy", "Connected immediately.\n"); |
|
5681
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
2180 |
|
1840
00aef397a1fe
[gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1705
diff
changeset
|
2181 len = sizeof(error); |
|
5681
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
2182 |
| 14103 | 2183 if (getsockopt(connect_info->fd, SOL_SOCKET, SO_ERROR, &error, &len) != 0) |
| 14099 | 2184 { |
| 14103 | 2185 close(connect_info->fd); |
| 2186 connect_info->fd = -1; | |
|
1840
00aef397a1fe
[gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1705
diff
changeset
|
2187 return -1; |
|
00aef397a1fe
[gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1705
diff
changeset
|
2188 } |
|
5681
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
2189 |
| 14103 | 2190 s5_canwrite(connect_info, connect_info->fd, GAIM_INPUT_WRITE); |
|
1087
56c7ceb986a8
[gaim-migrate @ 1097]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1057
diff
changeset
|
2191 } |
|
56c7ceb986a8
[gaim-migrate @ 1097]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1057
diff
changeset
|
2192 |
| 14103 | 2193 return connect_info->fd; |
|
1087
56c7ceb986a8
[gaim-migrate @ 1097]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1057
diff
changeset
|
2194 } |
|
56c7ceb986a8
[gaim-migrate @ 1097]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1057
diff
changeset
|
2195 |
| 14103 | 2196 /** |
| 2197 * This function iterates through a list of IP addresses and attempts | |
| 2198 * to connect to each one. This is called after the hostname is | |
| 2199 * resolved, and if a connection attempt fails. | |
| 2200 */ | |
| 14097 | 2201 static void try_connect(GaimProxyConnectInfo *connect_info) |
| 4366 | 2202 { |
| 4678 | 2203 size_t addrlen; |
| 2204 struct sockaddr *addr; | |
| 2205 int ret = -1; | |
| 4634 | 2206 |
| 14099 | 2207 if (connect_info->hosts == NULL) |
| 2208 { | |
| 2209 gaim_proxy_connect_info_error(connect_info, _("Could not resolve host name")); | |
| 2210 return; | |
| 2211 } | |
| 2212 | |
| 2213 while (connect_info->hosts) | |
| 2214 { | |
| 14096 | 2215 addrlen = GPOINTER_TO_INT(connect_info->hosts->data); |
| 2216 connect_info->hosts = g_slist_remove(connect_info->hosts, connect_info->hosts->data); | |
| 2217 addr = connect_info->hosts->data; | |
| 2218 connect_info->hosts = g_slist_remove(connect_info->hosts, connect_info->hosts->data); | |
| 4366 | 2219 |
| 14096 | 2220 switch (gaim_proxy_info_get_type(connect_info->gpi)) { |
|
5681
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
2221 case GAIM_PROXY_NONE: |
| 14096 | 2222 ret = proxy_connect_none(connect_info, addr, addrlen); |
| 4678 | 2223 break; |
|
5681
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
2224 |
|
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
2225 case GAIM_PROXY_HTTP: |
| 14096 | 2226 ret = proxy_connect_http(connect_info, addr, addrlen); |
| 4678 | 2227 break; |
|
5681
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
2228 |
|
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
2229 case GAIM_PROXY_SOCKS4: |
| 14096 | 2230 ret = proxy_connect_socks4(connect_info, addr, addrlen); |
| 4678 | 2231 break; |
|
5681
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
2232 |
|
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
2233 case GAIM_PROXY_SOCKS5: |
| 14096 | 2234 ret = proxy_connect_socks5(connect_info, addr, addrlen); |
| 4678 | 2235 break; |
|
5681
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
2236 |
| 6621 | 2237 case GAIM_PROXY_USE_ENVVAR: |
| 14096 | 2238 ret = proxy_connect_http(connect_info, addr, addrlen); |
| 6621 | 2239 break; |
| 2240 | |
|
5681
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
2241 default: |
|
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
2242 break; |
| 4678 | 2243 } |
|
5681
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
2244 |
| 9129 | 2245 g_free(addr); |
| 2246 | |
| 14099 | 2247 if (ret >= 0) |
| 4366 | 2248 break; |
| 4678 | 2249 } |
|
5681
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
2250 |
|
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
2251 if (ret < 0) { |
| 14099 | 2252 gaim_proxy_connect_info_error(connect_info, _("Unable to establish a connection")); |
| 4366 | 2253 } |
| 2254 } | |
| 2255 | |
| 9129 | 2256 static void |
| 2257 connection_host_resolved(GSList *hosts, gpointer data, | |
| 2258 const char *error_message) | |
| 2259 { | |
| 14097 | 2260 GaimProxyConnectInfo *connect_info; |
| 9129 | 2261 |
| 14099 | 2262 if (error_message != NULL) |
| 2263 { | |
| 2264 gaim_debug_info("proxy", "Error while resolving hostname: %s\n", error_message); | |
| 2265 /* TODO: Destroy connect_info and return? */ | |
| 2266 } | |
| 2267 | |
| 14097 | 2268 connect_info = data; |
| 14096 | 2269 connect_info->hosts = hosts; |
| 9129 | 2270 |
| 14096 | 2271 try_connect(connect_info); |
| 9129 | 2272 } |
| 2273 | |
| 13514 | 2274 GaimProxyInfo * |
| 2275 gaim_proxy_get_setup(GaimAccount *account) | |
|
1087
56c7ceb986a8
[gaim-migrate @ 1097]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1057
diff
changeset
|
2276 { |
| 13514 | 2277 GaimProxyInfo *gpi; |
| 6621 | 2278 const gchar *tmp; |
|
5681
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
2279 |
| 11878 | 2280 if (account && gaim_account_get_proxy_info(account) != NULL) |
| 13514 | 2281 gpi = gaim_account_get_proxy_info(account); |
| 11878 | 2282 else if (gaim_running_gnome()) |
| 13514 | 2283 gpi = gaim_gnome_proxy_get_info(); |
| 11878 | 2284 else |
| 13514 | 2285 gpi = gaim_global_proxy_get_info(); |
|
5681
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
2286 |
| 13514 | 2287 if (gaim_proxy_info_get_type(gpi) == GAIM_PROXY_USE_ENVVAR) { |
| 6621 | 2288 if ((tmp = g_getenv("HTTP_PROXY")) != NULL || |
| 2289 (tmp = g_getenv("http_proxy")) != NULL || | |
| 10534 | 2290 (tmp = g_getenv("HTTPPROXY")) != NULL) { |
|
9227
9171e528d7e5
[gaim-migrate @ 10023]
Christian Hammond <chipx86@chipx86.com>
parents:
9148
diff
changeset
|
2291 char *proxyhost,*proxypath,*proxyuser,*proxypasswd; |
| 7652 | 2292 int proxyport; |
| 6621 | 2293 |
| 9129 | 2294 /* http_proxy-format: |
|
9227
9171e528d7e5
[gaim-migrate @ 10023]
Christian Hammond <chipx86@chipx86.com>
parents:
9148
diff
changeset
|
2295 * export http_proxy="http://user:passwd@your.proxy.server:port/" |
| 7652 | 2296 */ |
|
9227
9171e528d7e5
[gaim-migrate @ 10023]
Christian Hammond <chipx86@chipx86.com>
parents:
9148
diff
changeset
|
2297 if(gaim_url_parse(tmp, &proxyhost, &proxyport, &proxypath, &proxyuser, &proxypasswd)) { |
| 13514 | 2298 gaim_proxy_info_set_host(gpi, proxyhost); |
| 7652 | 2299 g_free(proxyhost); |
| 2300 g_free(proxypath); | |
|
9227
9171e528d7e5
[gaim-migrate @ 10023]
Christian Hammond <chipx86@chipx86.com>
parents:
9148
diff
changeset
|
2301 if (proxyuser != NULL) { |
| 13514 | 2302 gaim_proxy_info_set_username(gpi, proxyuser); |
|
9227
9171e528d7e5
[gaim-migrate @ 10023]
Christian Hammond <chipx86@chipx86.com>
parents:
9148
diff
changeset
|
2303 g_free(proxyuser); |
|
9171e528d7e5
[gaim-migrate @ 10023]
Christian Hammond <chipx86@chipx86.com>
parents:
9148
diff
changeset
|
2304 } |
|
9171e528d7e5
[gaim-migrate @ 10023]
Christian Hammond <chipx86@chipx86.com>
parents:
9148
diff
changeset
|
2305 if (proxypasswd != NULL) { |
| 13514 | 2306 gaim_proxy_info_set_password(gpi, proxypasswd); |
|
9227
9171e528d7e5
[gaim-migrate @ 10023]
Christian Hammond <chipx86@chipx86.com>
parents:
9148
diff
changeset
|
2307 g_free(proxypasswd); |
|
9171e528d7e5
[gaim-migrate @ 10023]
Christian Hammond <chipx86@chipx86.com>
parents:
9148
diff
changeset
|
2308 } |
| 7652 | 2309 |
| 2310 /* only for backward compatibility */ | |
| 9129 | 2311 if (proxyport == 80 && |
| 7652 | 2312 ((tmp = g_getenv("HTTP_PROXY_PORT")) != NULL || |
| 2313 (tmp = g_getenv("http_proxy_port")) != NULL || | |
| 2314 (tmp = g_getenv("HTTPPROXYPORT")) != NULL)) | |
| 2315 proxyport = atoi(tmp); | |
| 9129 | 2316 |
| 13514 | 2317 gaim_proxy_info_set_port(gpi, proxyport); |
| 7652 | 2318 } |
| 10534 | 2319 } else { |
| 2320 /* no proxy environment variable found, don't use a proxy */ | |
| 2321 gaim_debug_info("proxy", "No environment settings found, not using a proxy\n"); | |
| 13514 | 2322 gaim_proxy_info_set_type(gpi, GAIM_PROXY_NONE); |
| 6621 | 2323 } |
| 2324 | |
|
9227
9171e528d7e5
[gaim-migrate @ 10023]
Christian Hammond <chipx86@chipx86.com>
parents:
9148
diff
changeset
|
2325 /* XXX: Do we want to skip this step if user/password were part of url? */ |
| 6621 | 2326 if ((tmp = g_getenv("HTTP_PROXY_USER")) != NULL || |
| 2327 (tmp = g_getenv("http_proxy_user")) != NULL || | |
| 2328 (tmp = g_getenv("HTTPPROXYUSER")) != NULL) | |
| 13514 | 2329 gaim_proxy_info_set_username(gpi, tmp); |
| 6621 | 2330 |
| 2331 if ((tmp = g_getenv("HTTP_PROXY_PASS")) != NULL || | |
| 2332 (tmp = g_getenv("http_proxy_pass")) != NULL || | |
| 2333 (tmp = g_getenv("HTTPPROXYPASS")) != NULL) | |
| 13514 | 2334 gaim_proxy_info_set_password(gpi, tmp); |
| 6621 | 2335 } |
| 2336 | |
| 13514 | 2337 return gpi; |
| 2338 } | |
| 2339 | |
| 14089 | 2340 GaimProxyConnectInfo * |
| 13514 | 2341 gaim_proxy_connect(GaimAccount *account, const char *host, int port, |
| 14089 | 2342 GaimProxyConnectFunction connect_cb, |
| 2343 GaimProxyErrorFunction error_cb, gpointer data) | |
| 13514 | 2344 { |
| 2345 const char *connecthost = host; | |
| 2346 int connectport = port; | |
| 14097 | 2347 GaimProxyConnectInfo *connect_info; |
| 13514 | 2348 |
| 14089 | 2349 g_return_val_if_fail(host != NULL, NULL); |
| 2350 g_return_val_if_fail(port > 0, NULL); | |
| 2351 g_return_val_if_fail(connect_cb != NULL, NULL); | |
| 2352 /* g_return_val_if_fail(error_cb != NULL, NULL); *//* TODO: Soon! */ | |
| 13514 | 2353 |
| 14097 | 2354 connect_info = g_new0(GaimProxyConnectInfo, 1); |
| 14103 | 2355 connect_info->fd = -1; |
| 14096 | 2356 connect_info->connect_cb = connect_cb; |
| 2357 connect_info->error_cb = error_cb; | |
| 2358 connect_info->data = data; | |
| 2359 connect_info->host = g_strdup(host); | |
| 2360 connect_info->port = port; | |
| 2361 connect_info->gpi = gaim_proxy_get_setup(account); | |
| 13514 | 2362 |
| 14096 | 2363 if ((gaim_proxy_info_get_type(connect_info->gpi) != GAIM_PROXY_NONE) && |
| 2364 (gaim_proxy_info_get_host(connect_info->gpi) == NULL || | |
| 2365 gaim_proxy_info_get_port(connect_info->gpi) <= 0)) { | |
|
5681
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
2366 |
| 6621 | 2367 gaim_notify_error(NULL, NULL, _("Invalid proxy settings"), _("Either the host name or port number specified for your given proxy type is invalid.")); |
| 14096 | 2368 gaim_proxy_connect_info_destroy(connect_info); |
| 14089 | 2369 return NULL; |
|
1840
00aef397a1fe
[gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1705
diff
changeset
|
2370 } |
| 4366 | 2371 |
| 14096 | 2372 switch (gaim_proxy_info_get_type(connect_info->gpi)) |
| 4366 | 2373 { |
|
5681
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
2374 case GAIM_PROXY_NONE: |
| 4366 | 2375 break; |
|
5681
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
2376 |
|
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
2377 case GAIM_PROXY_HTTP: |
|
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
2378 case GAIM_PROXY_SOCKS4: |
|
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
2379 case GAIM_PROXY_SOCKS5: |
| 6621 | 2380 case GAIM_PROXY_USE_ENVVAR: |
| 14096 | 2381 connecthost = gaim_proxy_info_get_host(connect_info->gpi); |
| 2382 connectport = gaim_proxy_info_get_port(connect_info->gpi); | |
| 4366 | 2383 break; |
|
5681
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
2384 |
| 4366 | 2385 default: |
| 14096 | 2386 gaim_proxy_connect_info_destroy(connect_info); |
| 14089 | 2387 return NULL; |
| 2388 } | |
| 2389 | |
| 2390 if (gaim_gethostbyname_async(connecthost, | |
| 14096 | 2391 connectport, connection_host_resolved, connect_info) != 0) |
| 14089 | 2392 { |
| 14096 | 2393 gaim_proxy_connect_info_destroy(connect_info); |
| 14089 | 2394 return NULL; |
| 4366 | 2395 } |
|
5681
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
2396 |
| 14096 | 2397 connect_infos = g_slist_prepend(connect_infos, connect_info); |
| 14089 | 2398 |
| 14096 | 2399 return connect_info; |
|
5681
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
2400 } |
|
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
2401 |
| 14089 | 2402 /* |
| 2403 * Combine some of this code with gaim_proxy_connect() | |
| 2404 */ | |
| 2405 GaimProxyConnectInfo * | |
| 8262 | 2406 gaim_proxy_connect_socks5(GaimProxyInfo *gpi, const char *host, int port, |
| 14089 | 2407 GaimProxyConnectFunction connect_cb, |
| 2408 GaimProxyErrorFunction error_cb, gpointer data) | |
| 8262 | 2409 { |
| 14097 | 2410 GaimProxyConnectInfo *connect_info; |
| 8262 | 2411 |
| 14089 | 2412 g_return_val_if_fail(host != NULL, NULL); |
| 2413 g_return_val_if_fail(port > 0, NULL); | |
| 2414 g_return_val_if_fail(connect_cb != NULL, NULL); | |
| 2415 /* g_return_val_if_fail(error_cb != NULL, NULL); *//* TODO: Soon! */ | |
| 2416 | |
| 14097 | 2417 connect_info = g_new0(GaimProxyConnectInfo, 1); |
| 14103 | 2418 connect_info->fd = -1; |
| 14096 | 2419 connect_info->connect_cb = connect_cb; |
| 2420 connect_info->error_cb = error_cb; | |
| 2421 connect_info->data = data; | |
| 2422 connect_info->host = g_strdup(host); | |
| 2423 connect_info->port = port; | |
| 2424 connect_info->gpi = gpi; | |
| 8262 | 2425 |
| 14089 | 2426 if (gaim_gethostbyname_async(gaim_proxy_info_get_host(gpi), |
| 14096 | 2427 gaim_proxy_info_get_port(gpi), connection_host_resolved, connect_info) != 0) |
| 14089 | 2428 { |
| 14096 | 2429 gaim_proxy_connect_info_destroy(connect_info); |
| 14089 | 2430 return NULL; |
| 2431 } | |
| 2432 | |
| 14096 | 2433 connect_infos = g_slist_prepend(connect_infos, connect_info); |
| 14089 | 2434 |
| 14096 | 2435 return connect_info; |
| 8262 | 2436 } |
| 2437 | |
| 14103 | 2438 void |
| 2439 gaim_proxy_connect_cancel(GaimProxyConnectInfo *connect_info) | |
| 2440 { | |
| 2441 gaim_proxy_connect_info_destroy(connect_info); | |
| 2442 } | |
| 8262 | 2443 |
|
5681
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
2444 static void |
| 12816 | 2445 proxy_pref_cb(const char *name, GaimPrefType type, |
| 2446 gconstpointer value, gpointer data) | |
|
5681
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
2447 { |
|
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
2448 GaimProxyInfo *info = gaim_global_proxy_get_info(); |
|
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
2449 |
| 6001 | 2450 if (!strcmp(name, "/core/proxy/type")) { |
| 2451 int proxytype; | |
| 12816 | 2452 const char *type = value; |
| 6001 | 2453 |
| 2454 if (!strcmp(type, "none")) | |
| 2455 proxytype = GAIM_PROXY_NONE; | |
| 2456 else if (!strcmp(type, "http")) | |
| 2457 proxytype = GAIM_PROXY_HTTP; | |
| 2458 else if (!strcmp(type, "socks4")) | |
| 2459 proxytype = GAIM_PROXY_SOCKS4; | |
| 2460 else if (!strcmp(type, "socks5")) | |
| 2461 proxytype = GAIM_PROXY_SOCKS5; | |
| 6621 | 2462 else if (!strcmp(type, "envvar")) |
| 2463 proxytype = GAIM_PROXY_USE_ENVVAR; | |
| 6001 | 2464 else |
| 2465 proxytype = -1; | |
| 2466 | |
| 2467 gaim_proxy_info_set_type(info, proxytype); | |
| 2468 } else if (!strcmp(name, "/core/proxy/host")) | |
|
5681
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
2469 gaim_proxy_info_set_host(info, value); |
|
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
2470 else if (!strcmp(name, "/core/proxy/port")) |
|
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
2471 gaim_proxy_info_set_port(info, GPOINTER_TO_INT(value)); |
|
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
2472 else if (!strcmp(name, "/core/proxy/username")) |
|
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
2473 gaim_proxy_info_set_username(info, value); |
|
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
2474 else if (!strcmp(name, "/core/proxy/password")) |
|
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
2475 gaim_proxy_info_set_password(info, value); |
|
1087
56c7ceb986a8
[gaim-migrate @ 1097]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1057
diff
changeset
|
2476 } |
|
5681
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
2477 |
| 14089 | 2478 void * |
| 2479 gaim_proxy_get_handle() | |
| 2480 { | |
| 2481 static int handle; | |
| 2482 | |
| 2483 return &handle; | |
| 2484 } | |
| 2485 | |
|
5681
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
2486 void |
|
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
2487 gaim_proxy_init(void) |
|
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
2488 { |
| 10087 | 2489 void *handle; |
| 2490 | |
|
5681
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
2491 /* Initialize a default proxy info struct. */ |
|
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
2492 global_proxy_info = gaim_proxy_info_new(); |
|
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
2493 |
|
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
2494 /* Proxy */ |
|
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
2495 gaim_prefs_add_none("/core/proxy"); |
|
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
2496 gaim_prefs_add_string("/core/proxy/type", "none"); |
|
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
2497 gaim_prefs_add_string("/core/proxy/host", ""); |
|
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
2498 gaim_prefs_add_int("/core/proxy/port", 0); |
|
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
2499 gaim_prefs_add_string("/core/proxy/username", ""); |
|
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
2500 gaim_prefs_add_string("/core/proxy/password", ""); |
|
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
2501 |
|
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
2502 /* Setup callbacks for the preferences. */ |
| 10087 | 2503 handle = gaim_proxy_get_handle(); |
|
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
2504 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
|
2505 NULL); |
|
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
2506 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
|
2507 NULL); |
|
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
2508 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
|
2509 NULL); |
| 10087 | 2510 gaim_prefs_connect_callback(handle, "/core/proxy/username", |
|
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
2511 proxy_pref_cb, NULL); |
| 10087 | 2512 gaim_prefs_connect_callback(handle, "/core/proxy/password", |
|
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13084
diff
changeset
|
2513 proxy_pref_cb, NULL); |
|
10626
06f5cc17cddc
[gaim-migrate @ 12101]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10619
diff
changeset
|
2514 #ifdef _WIN32 |
|
10237
2f6dcbaaabe0
[gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
10172
diff
changeset
|
2515 if(!g_thread_supported()) |
|
2f6dcbaaabe0
[gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
10172
diff
changeset
|
2516 g_thread_init(NULL); |
|
10626
06f5cc17cddc
[gaim-migrate @ 12101]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10619
diff
changeset
|
2517 #endif |
|
5681
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
2518 } |
| 10087 | 2519 |
| 14089 | 2520 void |
| 2521 gaim_proxy_uninit(void) | |
| 10087 | 2522 { |
| 14096 | 2523 while (connect_infos != NULL) |
| 2524 gaim_proxy_connect_info_destroy(connect_infos->data); | |
| 10087 | 2525 } |
