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