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