annotate src/proxy.c @ 12348:4f7797a3024b

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