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