annotate src/proxy.c @ 10300:cfd119bd3caf

[gaim-migrate @ 11484] Um, remove a parameter that wasn't used. This should close Red Hat bug 141588 committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Thu, 02 Dec 2004 23:01:05 +0000
parents 36b7335d3452
children 9bfcb5eb12bd
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"
059d95c67cda [gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents: 5681
diff changeset
33 #include "debug.h"
6621
42fdf16f1dad [gaim-migrate @ 7145]
Mark Doliner <mark@kingant.net>
parents: 6320
diff changeset
34 #include "notify.h"
5872
059d95c67cda [gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents: 5681
diff changeset
35 #include "prefs.h"
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
36 #include "proxy.h"
5872
059d95c67cda [gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents: 5681
diff changeset
37 #include "util.h"
3630
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3376
diff changeset
38
9729
f44ae9331afc [gaim-migrate @ 10590]
Mark Doliner <mark@kingant.net>
parents: 9657
diff changeset
39 #include "gaim.h"
1881
a02584b98823 [gaim-migrate @ 1891]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1868
diff changeset
40
9729
f44ae9331afc [gaim-migrate @ 10590]
Mark Doliner <mark@kingant.net>
parents: 9657
diff changeset
41 static GaimProxyInfo *global_proxy_info = NULL;
5872
059d95c67cda [gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents: 5681
diff changeset
42
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
43 struct PHB {
2090
b66aca8e8dce [gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2048
diff changeset
44 GaimInputFunction func;
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
45 gpointer data;
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
46 char *host;
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
47 int port;
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
48 gint inpa;
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
49 GaimProxyInfo *gpi;
5563
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents: 5532
diff changeset
50 GaimAccount *account;
9129
3e94a77ee0c7 [gaim-migrate @ 9907]
Nathan Walp <nwalp@pidgin.im>
parents: 9100
diff changeset
51 GSList *hosts;
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
52 };
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
53
9129
3e94a77ee0c7 [gaim-migrate @ 9907]
Nathan Walp <nwalp@pidgin.im>
parents: 9100
diff changeset
54 static void try_connect(struct PHB *);
3e94a77ee0c7 [gaim-migrate @ 9907]
Nathan Walp <nwalp@pidgin.im>
parents: 9100
diff changeset
55
7982
58af482c89f7 [gaim-migrate @ 8659]
Luke Schierer <lschiere@pidgin.im>
parents: 7834
diff changeset
56 const char* socks5errors[] = {
58af482c89f7 [gaim-migrate @ 8659]
Luke Schierer <lschiere@pidgin.im>
parents: 7834
diff changeset
57 "succeeded\n",
58af482c89f7 [gaim-migrate @ 8659]
Luke Schierer <lschiere@pidgin.im>
parents: 7834
diff changeset
58 "general SOCKS server failure\n",
58af482c89f7 [gaim-migrate @ 8659]
Luke Schierer <lschiere@pidgin.im>
parents: 7834
diff changeset
59 "connection not allowed by ruleset\n",
58af482c89f7 [gaim-migrate @ 8659]
Luke Schierer <lschiere@pidgin.im>
parents: 7834
diff changeset
60 "Network unreachable\n",
58af482c89f7 [gaim-migrate @ 8659]
Luke Schierer <lschiere@pidgin.im>
parents: 7834
diff changeset
61 "Host unreachable\n",
58af482c89f7 [gaim-migrate @ 8659]
Luke Schierer <lschiere@pidgin.im>
parents: 7834
diff changeset
62 "Connection refused\n",
58af482c89f7 [gaim-migrate @ 8659]
Luke Schierer <lschiere@pidgin.im>
parents: 7834
diff changeset
63 "TTL expired\n",
58af482c89f7 [gaim-migrate @ 8659]
Luke Schierer <lschiere@pidgin.im>
parents: 7834
diff changeset
64 "Command not supported\n",
58af482c89f7 [gaim-migrate @ 8659]
Luke Schierer <lschiere@pidgin.im>
parents: 7834
diff changeset
65 "Address type not supported\n"
58af482c89f7 [gaim-migrate @ 8659]
Luke Schierer <lschiere@pidgin.im>
parents: 7834
diff changeset
66 };
58af482c89f7 [gaim-migrate @ 8659]
Luke Schierer <lschiere@pidgin.im>
parents: 7834
diff changeset
67
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
68 /**************************************************************************
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
69 * Proxy structure API
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
70 **************************************************************************/
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
71 GaimProxyInfo *
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
72 gaim_proxy_info_new(void)
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
73 {
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
74 return g_new0(GaimProxyInfo, 1);
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
75 }
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
76
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
77 void
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
78 gaim_proxy_info_destroy(GaimProxyInfo *info)
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
79 {
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
80 g_return_if_fail(info != NULL);
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
81
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
82 if (info->host != NULL) g_free(info->host);
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
83 if (info->username != NULL) g_free(info->username);
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
84 if (info->password != NULL) g_free(info->password);
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
85
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
86 g_free(info);
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
87 }
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
88
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
89 void
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
90 gaim_proxy_info_set_type(GaimProxyInfo *info, GaimProxyType type)
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
91 {
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
92 g_return_if_fail(info != NULL);
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
93
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
94 info->type = type;
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
95 }
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
96
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
97 void
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
98 gaim_proxy_info_set_host(GaimProxyInfo *info, const char *host)
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
99 {
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
100 g_return_if_fail(info != NULL);
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
101
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
102 if (info->host != NULL)
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
103 g_free(info->host);
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
104
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
105 info->host = (host == NULL ? NULL : g_strdup(host));
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
106 }
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
107
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
108 void
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
109 gaim_proxy_info_set_port(GaimProxyInfo *info, int port)
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
110 {
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
111 g_return_if_fail(info != NULL);
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
112
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
113 info->port = port;
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
114 }
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
115
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
116 void
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
117 gaim_proxy_info_set_username(GaimProxyInfo *info, const char *username)
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
118 {
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
119 g_return_if_fail(info != NULL);
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
120
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
121 if (info->username != NULL)
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
122 g_free(info->username);
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
123
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
124 info->username = (username == NULL ? NULL : g_strdup(username));
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
125 }
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
126
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
127 void
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
128 gaim_proxy_info_set_password(GaimProxyInfo *info, const char *password)
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
129 {
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
130 g_return_if_fail(info != NULL);
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
131
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
132 if (info->password != NULL)
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
133 g_free(info->password);
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
134
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
135 info->password = (password == NULL ? NULL : g_strdup(password));
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
136 }
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
137
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
138 GaimProxyType
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
139 gaim_proxy_info_get_type(const GaimProxyInfo *info)
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
140 {
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
141 g_return_val_if_fail(info != NULL, GAIM_PROXY_NONE);
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
142
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
143 return info->type;
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
144 }
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
145
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
146 const char *
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
147 gaim_proxy_info_get_host(const GaimProxyInfo *info)
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
148 {
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
149 g_return_val_if_fail(info != NULL, NULL);
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
150
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
151 return info->host;
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
152 }
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
153
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
154 int
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
155 gaim_proxy_info_get_port(const GaimProxyInfo *info)
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
156 {
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
157 g_return_val_if_fail(info != NULL, 0);
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
158
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
159 return info->port;
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
160 }
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
161
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
162 const char *
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
163 gaim_proxy_info_get_username(const GaimProxyInfo *info)
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
164 {
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
165 g_return_val_if_fail(info != NULL, NULL);
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
166
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
167 return info->username;
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
168 }
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
169
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
170 const char *
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
171 gaim_proxy_info_get_password(const GaimProxyInfo *info)
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
172 {
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
173 g_return_val_if_fail(info != NULL, NULL);
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
174
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
175 return info->password;
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
176 }
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
177
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
178 /**************************************************************************
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
179 * Global Proxy API
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
180 **************************************************************************/
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
181 GaimProxyInfo *
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
182 gaim_global_proxy_get_info(void)
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
183 {
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
184 return global_proxy_info;
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
185 }
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
186
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
187 /**************************************************************************
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
188 * Proxy API
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
189 **************************************************************************/
4678
9ce3c698ff5e [gaim-migrate @ 4989]
Nathan Walp <nwalp@pidgin.im>
parents: 4648
diff changeset
190 typedef void (*dns_callback_t)(GSList *hosts, gpointer data,
9ce3c698ff5e [gaim-migrate @ 4989]
Nathan Walp <nwalp@pidgin.im>
parents: 4648
diff changeset
191 const char *error_message);
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
192
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
193 #ifdef __unix__
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
194
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
195 /* This structure represents both a pending DNS request and
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
196 * a free child process.
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
197 */
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
198 typedef struct {
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
199 char *host;
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
200 int port;
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
201 dns_callback_t callback;
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
202 gpointer data;
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
203 gint inpa;
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
204 int fd_in, fd_out;
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
205 pid_t dns_pid;
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
206 } pending_dns_request_t;
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
207
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
208 static GSList *free_dns_children = NULL;
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
209 static GQueue *queued_requests = NULL;
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
210
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
211 static int number_of_dns_children = 0;
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
212
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
213 const int MAX_DNS_CHILDREN = 2;
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
214
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
215 typedef struct {
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
216 char hostname[512];
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
217 int port;
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
218 } dns_params_t;
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
219
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
220 typedef struct {
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
221 dns_params_t params;
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
222 dns_callback_t callback;
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
223 gpointer data;
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
224 } queued_dns_request_t;
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
225
4434
6b83a532eeb2 [gaim-migrate @ 4709]
Nathan Walp <nwalp@pidgin.im>
parents: 4394
diff changeset
226 static void req_free(pending_dns_request_t *req)
6b83a532eeb2 [gaim-migrate @ 4709]
Nathan Walp <nwalp@pidgin.im>
parents: 4394
diff changeset
227 {
6b83a532eeb2 [gaim-migrate @ 4709]
Nathan Walp <nwalp@pidgin.im>
parents: 4394
diff changeset
228 g_return_if_fail(req != NULL);
6b83a532eeb2 [gaim-migrate @ 4709]
Nathan Walp <nwalp@pidgin.im>
parents: 4394
diff changeset
229 if(req->host)
6b83a532eeb2 [gaim-migrate @ 4709]
Nathan Walp <nwalp@pidgin.im>
parents: 4394
diff changeset
230 g_free(req->host);
6b83a532eeb2 [gaim-migrate @ 4709]
Nathan Walp <nwalp@pidgin.im>
parents: 4394
diff changeset
231 close(req->fd_in);
6b83a532eeb2 [gaim-migrate @ 4709]
Nathan Walp <nwalp@pidgin.im>
parents: 4394
diff changeset
232 close(req->fd_out);
6b83a532eeb2 [gaim-migrate @ 4709]
Nathan Walp <nwalp@pidgin.im>
parents: 4394
diff changeset
233 g_free(req);
6b83a532eeb2 [gaim-migrate @ 4709]
Nathan Walp <nwalp@pidgin.im>
parents: 4394
diff changeset
234 number_of_dns_children--;
6b83a532eeb2 [gaim-migrate @ 4709]
Nathan Walp <nwalp@pidgin.im>
parents: 4394
diff changeset
235 }
6b83a532eeb2 [gaim-migrate @ 4709]
Nathan Walp <nwalp@pidgin.im>
parents: 4394
diff changeset
236
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
237 static int send_dns_request_to_child(pending_dns_request_t *req, dns_params_t *dns_params)
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
238 {
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
239 char ch;
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
240 int rc;
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
241
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
242 /* Are you alive? */
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
243 if(kill(req->dns_pid, 0) != 0) {
5211
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
244 gaim_debug(GAIM_DEBUG_WARNING, "dns",
5218
4ee151ad8233 [gaim-migrate @ 5588]
Christian Hammond <chipx86@chipx86.com>
parents: 5211
diff changeset
245 "DNS child %d no longer exists\n", req->dns_pid);
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
246 return -1;
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
247 }
9129
3e94a77ee0c7 [gaim-migrate @ 9907]
Nathan Walp <nwalp@pidgin.im>
parents: 9100
diff changeset
248
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
249 /* Let's contact this lost child! */
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
250 rc = write(req->fd_in, dns_params, sizeof(*dns_params));
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
251 if(rc<0) {
5211
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
252 gaim_debug(GAIM_DEBUG_ERROR, "dns",
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
253 "Unable to write to DNS child %d: %d\n",
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
254 req->dns_pid, strerror(errno));
4434
6b83a532eeb2 [gaim-migrate @ 4709]
Nathan Walp <nwalp@pidgin.im>
parents: 4394
diff changeset
255 close(req->fd_in);
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
256 return -1;
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
257 }
9129
3e94a77ee0c7 [gaim-migrate @ 9907]
Nathan Walp <nwalp@pidgin.im>
parents: 9100
diff changeset
258
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
259 g_return_val_if_fail(rc == sizeof(*dns_params), -1);
9129
3e94a77ee0c7 [gaim-migrate @ 9907]
Nathan Walp <nwalp@pidgin.im>
parents: 9100
diff changeset
260
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
261 /* Did you hear me? (This avoids some race conditions) */
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
262 rc = read(req->fd_out, &ch, 1);
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
263 if(rc != 1 || ch!='Y') {
5211
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
264 gaim_debug(GAIM_DEBUG_WARNING, "dns",
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
265 "DNS child %d not responding. Killing it!\n",
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
266 req->dns_pid);
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
267 kill(req->dns_pid, SIGKILL);
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
268 return -1;
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
269 }
9655
00f96f4cc775 [gaim-migrate @ 10503]
Luke Schierer <lschiere@pidgin.im>
parents: 9653
diff changeset
270
5211
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
271 gaim_debug(GAIM_DEBUG_INFO, "dns",
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
272 "Successfully sent DNS request to child %d\n", req->dns_pid);
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
273 return 0;
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
274 }
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 static void host_resolved(gpointer data, gint source, GaimInputCondition cond);
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
277
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
278 static void release_dns_child(pending_dns_request_t *req)
2911
4790fb1272a1 [gaim-migrate @ 2924]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2907
diff changeset
279 {
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
280 g_free(req->host);
4434
6b83a532eeb2 [gaim-migrate @ 4709]
Nathan Walp <nwalp@pidgin.im>
parents: 4394
diff changeset
281 req->host=NULL;
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
282
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
283 if(queued_requests && !g_queue_is_empty(queued_requests)) {
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
284 queued_dns_request_t *r = g_queue_pop_head(queued_requests);
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
285 req->host = g_strdup(r->params.hostname);
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
286 req->port = r->params.port;
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
287 req->callback = r->callback;
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
288 req->data = r->data;
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
289
5211
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
290 gaim_debug(GAIM_DEBUG_INFO, "dns",
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
291 "Processing queued DNS query for '%s' with child %d\n",
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
292 req->host, req->dns_pid);
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
293
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
294 if(send_dns_request_to_child(req, &(r->params)) != 0) {
4434
6b83a532eeb2 [gaim-migrate @ 4709]
Nathan Walp <nwalp@pidgin.im>
parents: 4394
diff changeset
295 req_free(req);
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
296 req = NULL;
5211
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
297
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
298 gaim_debug(GAIM_DEBUG_WARNING, "dns",
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
299 "Intent of process queued query of '%s' failed, "
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
300 "requeueing...\n", r->params.hostname);
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
301 g_queue_push_head(queued_requests, r);
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
302 } else {
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
303 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
304 g_free(r);
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
305 }
9655
00f96f4cc775 [gaim-migrate @ 10503]
Luke Schierer <lschiere@pidgin.im>
parents: 9653
diff changeset
306
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
307 } else {
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
308 req->host = NULL;
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
309 req->callback = NULL;
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
310 req->data = NULL;
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
311 free_dns_children = g_slist_append(free_dns_children, req);
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
312 }
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
313 }
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
314
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
315 static void host_resolved(gpointer data, gint source, GaimInputCondition cond)
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
316 {
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
317 pending_dns_request_t *req = (pending_dns_request_t*)data;
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
318 int rc, err;
4678
9ce3c698ff5e [gaim-migrate @ 4989]
Nathan Walp <nwalp@pidgin.im>
parents: 4648
diff changeset
319 GSList *hosts = NULL;
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
320 struct sockaddr *addr = NULL;
8436
4bb3d8dc717e [gaim-migrate @ 9166]
Luke Schierer <lschiere@pidgin.im>
parents: 8273
diff changeset
321 size_t addrlen;
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
322
5211
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
323 gaim_debug(GAIM_DEBUG_INFO, "dns", "Host '%s' resolved\n", req->host);
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
324 gaim_input_remove(req->inpa);
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
325
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
326 rc=read(req->fd_out, &err, sizeof(err));
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
327 if((rc==4) && (err!=0)) {
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
328 char message[1024];
8977
52fba1dafe0e [gaim-migrate @ 9751]
Mark Doliner <mark@kingant.net>
parents: 8917
diff changeset
329 #if HAVE_GETADDRINFO
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
330 g_snprintf(message, sizeof(message), "DNS error: %s (pid=%d)",
8977
52fba1dafe0e [gaim-migrate @ 9751]
Mark Doliner <mark@kingant.net>
parents: 8917
diff changeset
331 gai_strerror(err), req->dns_pid);
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
332 #else
8977
52fba1dafe0e [gaim-migrate @ 9751]
Mark Doliner <mark@kingant.net>
parents: 8917
diff changeset
333 g_snprintf(message, sizeof(message), "DNS error: %d (pid=%d)",
52fba1dafe0e [gaim-migrate @ 9751]
Mark Doliner <mark@kingant.net>
parents: 8917
diff changeset
334 err, req->dns_pid);
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
335 #endif
5211
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
336 gaim_debug(GAIM_DEBUG_ERROR, "dns", "%s\n", message);
4678
9ce3c698ff5e [gaim-migrate @ 4989]
Nathan Walp <nwalp@pidgin.im>
parents: 4648
diff changeset
337 req->callback(NULL, req->data, message);
9ce3c698ff5e [gaim-migrate @ 4989]
Nathan Walp <nwalp@pidgin.im>
parents: 4648
diff changeset
338 release_dns_child(req);
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
339 return;
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
340 }
4367
101fa831f52f [gaim-migrate @ 4633]
Mark Doliner <mark@kingant.net>
parents: 4366
diff changeset
341 if(rc>0) {
4678
9ce3c698ff5e [gaim-migrate @ 4989]
Nathan Walp <nwalp@pidgin.im>
parents: 4648
diff changeset
342 while(rc > 0) {
9ce3c698ff5e [gaim-migrate @ 4989]
Nathan Walp <nwalp@pidgin.im>
parents: 4648
diff changeset
343 rc=read(req->fd_out, &addrlen, sizeof(addrlen));
9ce3c698ff5e [gaim-migrate @ 4989]
Nathan Walp <nwalp@pidgin.im>
parents: 4648
diff changeset
344 if(rc>0 && addrlen > 0) {
9ce3c698ff5e [gaim-migrate @ 4989]
Nathan Walp <nwalp@pidgin.im>
parents: 4648
diff changeset
345 addr=g_malloc(addrlen);
9ce3c698ff5e [gaim-migrate @ 4989]
Nathan Walp <nwalp@pidgin.im>
parents: 4648
diff changeset
346 rc=read(req->fd_out, addr, addrlen);
9ce3c698ff5e [gaim-migrate @ 4989]
Nathan Walp <nwalp@pidgin.im>
parents: 4648
diff changeset
347 hosts = g_slist_append(hosts, GINT_TO_POINTER(addrlen));
9ce3c698ff5e [gaim-migrate @ 4989]
Nathan Walp <nwalp@pidgin.im>
parents: 4648
diff changeset
348 hosts = g_slist_append(hosts, addr);
9ce3c698ff5e [gaim-migrate @ 4989]
Nathan Walp <nwalp@pidgin.im>
parents: 4648
diff changeset
349 } else {
9ce3c698ff5e [gaim-migrate @ 4989]
Nathan Walp <nwalp@pidgin.im>
parents: 4648
diff changeset
350 break;
9ce3c698ff5e [gaim-migrate @ 4989]
Nathan Walp <nwalp@pidgin.im>
parents: 4648
diff changeset
351 }
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
352 }
4678
9ce3c698ff5e [gaim-migrate @ 4989]
Nathan Walp <nwalp@pidgin.im>
parents: 4648
diff changeset
353 } else if(rc==-1) {
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
354 char message[1024];
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
355 g_snprintf(message, sizeof(message), "Error reading from DNS child: %s",strerror(errno));
5211
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
356 gaim_debug(GAIM_DEBUG_ERROR, "dns", "%s\n", message);
4678
9ce3c698ff5e [gaim-migrate @ 4989]
Nathan Walp <nwalp@pidgin.im>
parents: 4648
diff changeset
357 req->callback(NULL, req->data, message);
4434
6b83a532eeb2 [gaim-migrate @ 4709]
Nathan Walp <nwalp@pidgin.im>
parents: 4394
diff changeset
358 req_free(req);
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
359 return;
4678
9ce3c698ff5e [gaim-migrate @ 4989]
Nathan Walp <nwalp@pidgin.im>
parents: 4648
diff changeset
360 } else if(rc==0) {
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
361 char message[1024];
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
362 g_snprintf(message, sizeof(message), "EOF reading from DNS child");
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
363 close(req->fd_out);
5211
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
364 gaim_debug(GAIM_DEBUG_ERROR, "dns", "%s\n", message);
4678
9ce3c698ff5e [gaim-migrate @ 4989]
Nathan Walp <nwalp@pidgin.im>
parents: 4648
diff changeset
365 req->callback(NULL, req->data, message);
4434
6b83a532eeb2 [gaim-migrate @ 4709]
Nathan Walp <nwalp@pidgin.im>
parents: 4394
diff changeset
366 req_free(req);
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
367 return;
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
368 }
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
369
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
370 /* wait4(req->dns_pid, NULL, WNOHANG, NULL); */
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
371
4678
9ce3c698ff5e [gaim-migrate @ 4989]
Nathan Walp <nwalp@pidgin.im>
parents: 4648
diff changeset
372 req->callback(hosts, req->data, NULL);
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
373
4678
9ce3c698ff5e [gaim-migrate @ 4989]
Nathan Walp <nwalp@pidgin.im>
parents: 4648
diff changeset
374 release_dns_child(req);
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
375 }
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
376
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
377 static void trap_gdb_bug()
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
378 {
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
379 const char *message =
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
380 "Gaim's DNS child got a SIGTRAP signal. \n"
5435
a2f26666de42 [gaim-migrate @ 5817]
Mark Doliner <mark@kingant.net>
parents: 5426
diff changeset
381 "This can be caused by trying to run gaim inside gdb.\n"
a2f26666de42 [gaim-migrate @ 5817]
Mark Doliner <mark@kingant.net>
parents: 5426
diff changeset
382 "There is a known gdb bug which prevents this. Supposedly gaim\n"
a2f26666de42 [gaim-migrate @ 5817]
Mark Doliner <mark@kingant.net>
parents: 5426
diff changeset
383 "should have detected you were using gdb and used an ugly hack,\n"
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
384 "check cope_with_gdb_brokenness() in proxy.c.\n\n"
5435
a2f26666de42 [gaim-migrate @ 5817]
Mark Doliner <mark@kingant.net>
parents: 5426
diff changeset
385 "For more info about this bug, see http://sources.redhat.com/ml/gdb/2001-07/msg00349.html\n";
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
386 fputs("\n* * *\n",stderr);
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
387 fputs(message,stderr);
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
388 fputs("* * *\n\n",stderr);
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
389 execlp("xmessage","xmessage","-center", message, NULL);
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
390 _exit(1);
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
391 }
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
392
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
393 static void cope_with_gdb_brokenness()
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
394 {
9738
d9e8d420e9fe [gaim-migrate @ 10600]
Christian Hammond <chipx86@chipx86.com>
parents: 9729
diff changeset
395 #ifdef __linux__
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
396 static gboolean already_done = FALSE;
8798
28c0ebfd7a53 [gaim-migrate @ 9560]
Nathan Walp <nwalp@pidgin.im>
parents: 8789
diff changeset
397 char s[256], e[512];
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
398 int n;
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
399 pid_t ppid;
2911
4790fb1272a1 [gaim-migrate @ 2924]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2907
diff changeset
400
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
401 if(already_done)
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
402 return;
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
403 already_done = TRUE;
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
404 ppid = getppid();
8798
28c0ebfd7a53 [gaim-migrate @ 9560]
Nathan Walp <nwalp@pidgin.im>
parents: 8789
diff changeset
405 snprintf(s, sizeof(s), "/proc/%d/exe", ppid);
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
406 n = readlink(s, e, sizeof(e));
8798
28c0ebfd7a53 [gaim-migrate @ 9560]
Nathan Walp <nwalp@pidgin.im>
parents: 8789
diff changeset
407 if(n < 0)
28c0ebfd7a53 [gaim-migrate @ 9560]
Nathan Walp <nwalp@pidgin.im>
parents: 8789
diff changeset
408 return;
28c0ebfd7a53 [gaim-migrate @ 9560]
Nathan Walp <nwalp@pidgin.im>
parents: 8789
diff changeset
409
8789
58787b676854 [gaim-migrate @ 9551]
Luke Schierer <lschiere@pidgin.im>
parents: 8735
diff changeset
410 e[MIN(n,sizeof(e)-1)] = '\0';
8798
28c0ebfd7a53 [gaim-migrate @ 9560]
Nathan Walp <nwalp@pidgin.im>
parents: 8789
diff changeset
411
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
412 if(strstr(e,"gdb")) {
5211
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
413 gaim_debug(GAIM_DEBUG_INFO, "dns",
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
414 "Debugger detected, performing useless query...\n");
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
415 gethostbyname("x.x.x.x.x");
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
416 }
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
417 #endif
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
418 }
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
419
9657
51464cbbdc1a [gaim-migrate @ 10505]
Mark Doliner <mark@kingant.net>
parents: 9656
diff changeset
420 static void
9729
f44ae9331afc [gaim-migrate @ 10590]
Mark Doliner <mark@kingant.net>
parents: 9657
diff changeset
421 gaim_dns_childthread(int child_out, int child_in, dns_params_t *dns_params, gboolean show_debug)
9657
51464cbbdc1a [gaim-migrate @ 10505]
Mark Doliner <mark@kingant.net>
parents: 9656
diff changeset
422 {
51464cbbdc1a [gaim-migrate @ 10505]
Mark Doliner <mark@kingant.net>
parents: 9656
diff changeset
423 const int zero = 0;
51464cbbdc1a [gaim-migrate @ 10505]
Mark Doliner <mark@kingant.net>
parents: 9656
diff changeset
424 int rc;
51464cbbdc1a [gaim-migrate @ 10505]
Mark Doliner <mark@kingant.net>
parents: 9656
diff changeset
425 #if HAVE_GETADDRINFO
51464cbbdc1a [gaim-migrate @ 10505]
Mark Doliner <mark@kingant.net>
parents: 9656
diff changeset
426 struct addrinfo hints, *res, *tmp;
51464cbbdc1a [gaim-migrate @ 10505]
Mark Doliner <mark@kingant.net>
parents: 9656
diff changeset
427 char servname[20];
51464cbbdc1a [gaim-migrate @ 10505]
Mark Doliner <mark@kingant.net>
parents: 9656
diff changeset
428 #else
51464cbbdc1a [gaim-migrate @ 10505]
Mark Doliner <mark@kingant.net>
parents: 9656
diff changeset
429 struct sockaddr_in sin;
51464cbbdc1a [gaim-migrate @ 10505]
Mark Doliner <mark@kingant.net>
parents: 9656
diff changeset
430 const size_t addrlen = sizeof(sin);
51464cbbdc1a [gaim-migrate @ 10505]
Mark Doliner <mark@kingant.net>
parents: 9656
diff changeset
431 #endif
51464cbbdc1a [gaim-migrate @ 10505]
Mark Doliner <mark@kingant.net>
parents: 9656
diff changeset
432
51464cbbdc1a [gaim-migrate @ 10505]
Mark Doliner <mark@kingant.net>
parents: 9656
diff changeset
433 #ifdef HAVE_SIGNAL_H
51464cbbdc1a [gaim-migrate @ 10505]
Mark Doliner <mark@kingant.net>
parents: 9656
diff changeset
434 signal(SIGHUP, SIG_DFL);
51464cbbdc1a [gaim-migrate @ 10505]
Mark Doliner <mark@kingant.net>
parents: 9656
diff changeset
435 signal(SIGINT, SIG_DFL);
51464cbbdc1a [gaim-migrate @ 10505]
Mark Doliner <mark@kingant.net>
parents: 9656
diff changeset
436 signal(SIGQUIT, SIG_DFL);
51464cbbdc1a [gaim-migrate @ 10505]
Mark Doliner <mark@kingant.net>
parents: 9656
diff changeset
437 signal(SIGCHLD, SIG_DFL);
51464cbbdc1a [gaim-migrate @ 10505]
Mark Doliner <mark@kingant.net>
parents: 9656
diff changeset
438 signal(SIGTERM, SIG_DFL);
51464cbbdc1a [gaim-migrate @ 10505]
Mark Doliner <mark@kingant.net>
parents: 9656
diff changeset
439 signal(SIGTRAP, trap_gdb_bug);
51464cbbdc1a [gaim-migrate @ 10505]
Mark Doliner <mark@kingant.net>
parents: 9656
diff changeset
440 #endif
51464cbbdc1a [gaim-migrate @ 10505]
Mark Doliner <mark@kingant.net>
parents: 9656
diff changeset
441
51464cbbdc1a [gaim-migrate @ 10505]
Mark Doliner <mark@kingant.net>
parents: 9656
diff changeset
442 while (1) {
51464cbbdc1a [gaim-migrate @ 10505]
Mark Doliner <mark@kingant.net>
parents: 9656
diff changeset
443 if (dns_params->hostname[0] == '\0') {
51464cbbdc1a [gaim-migrate @ 10505]
Mark Doliner <mark@kingant.net>
parents: 9656
diff changeset
444 const char Y = 'Y';
51464cbbdc1a [gaim-migrate @ 10505]
Mark Doliner <mark@kingant.net>
parents: 9656
diff changeset
445 fd_set fds;
51464cbbdc1a [gaim-migrate @ 10505]
Mark Doliner <mark@kingant.net>
parents: 9656
diff changeset
446 struct timeval tv = { .tv_sec = 40 , .tv_usec = 0 };
51464cbbdc1a [gaim-migrate @ 10505]
Mark Doliner <mark@kingant.net>
parents: 9656
diff changeset
447 FD_ZERO(&fds);
51464cbbdc1a [gaim-migrate @ 10505]
Mark Doliner <mark@kingant.net>
parents: 9656
diff changeset
448 FD_SET(child_in, &fds);
51464cbbdc1a [gaim-migrate @ 10505]
Mark Doliner <mark@kingant.net>
parents: 9656
diff changeset
449 rc = select(child_in + 1, &fds, NULL, NULL, &tv);
51464cbbdc1a [gaim-migrate @ 10505]
Mark Doliner <mark@kingant.net>
parents: 9656
diff changeset
450 if (!rc) {
9729
f44ae9331afc [gaim-migrate @ 10590]
Mark Doliner <mark@kingant.net>
parents: 9657
diff changeset
451 if (show_debug)
9657
51464cbbdc1a [gaim-migrate @ 10505]
Mark Doliner <mark@kingant.net>
parents: 9656
diff changeset
452 fprintf(stderr,"dns[%d]: nobody needs me... =(\n", getpid());
51464cbbdc1a [gaim-migrate @ 10505]
Mark Doliner <mark@kingant.net>
parents: 9656
diff changeset
453 break;
51464cbbdc1a [gaim-migrate @ 10505]
Mark Doliner <mark@kingant.net>
parents: 9656
diff changeset
454 }
51464cbbdc1a [gaim-migrate @ 10505]
Mark Doliner <mark@kingant.net>
parents: 9656
diff changeset
455 rc = read(child_in, dns_params, sizeof(dns_params_t));
51464cbbdc1a [gaim-migrate @ 10505]
Mark Doliner <mark@kingant.net>
parents: 9656
diff changeset
456 if (rc < 0) {
51464cbbdc1a [gaim-migrate @ 10505]
Mark Doliner <mark@kingant.net>
parents: 9656
diff changeset
457 perror("read()");
51464cbbdc1a [gaim-migrate @ 10505]
Mark Doliner <mark@kingant.net>
parents: 9656
diff changeset
458 break;
51464cbbdc1a [gaim-migrate @ 10505]
Mark Doliner <mark@kingant.net>
parents: 9656
diff changeset
459 }
51464cbbdc1a [gaim-migrate @ 10505]
Mark Doliner <mark@kingant.net>
parents: 9656
diff changeset
460 if (rc==0) {
9729
f44ae9331afc [gaim-migrate @ 10590]
Mark Doliner <mark@kingant.net>
parents: 9657
diff changeset
461 if (show_debug)
9792
465d19aad04b [gaim-migrate @ 10660]
Nathan Walp <nwalp@pidgin.im>
parents: 9738
diff changeset
462 fprintf(stderr,"dns[%d]: Oops, father has gone, wait for me, wait...!\n", getpid());
9657
51464cbbdc1a [gaim-migrate @ 10505]
Mark Doliner <mark@kingant.net>
parents: 9656
diff changeset
463 _exit(0);
51464cbbdc1a [gaim-migrate @ 10505]
Mark Doliner <mark@kingant.net>
parents: 9656
diff changeset
464 }
51464cbbdc1a [gaim-migrate @ 10505]
Mark Doliner <mark@kingant.net>
parents: 9656
diff changeset
465 if (dns_params->hostname[0] == '\0') {
51464cbbdc1a [gaim-migrate @ 10505]
Mark Doliner <mark@kingant.net>
parents: 9656
diff changeset
466 fprintf(stderr, "dns[%d]: hostname = \"\" (port = %d)!!!\n", getpid(), dns_params->port);
51464cbbdc1a [gaim-migrate @ 10505]
Mark Doliner <mark@kingant.net>
parents: 9656
diff changeset
467 _exit(1);
51464cbbdc1a [gaim-migrate @ 10505]
Mark Doliner <mark@kingant.net>
parents: 9656
diff changeset
468 }
51464cbbdc1a [gaim-migrate @ 10505]
Mark Doliner <mark@kingant.net>
parents: 9656
diff changeset
469 write(child_out, &Y, 1);
51464cbbdc1a [gaim-migrate @ 10505]
Mark Doliner <mark@kingant.net>
parents: 9656
diff changeset
470 }
51464cbbdc1a [gaim-migrate @ 10505]
Mark Doliner <mark@kingant.net>
parents: 9656
diff changeset
471
51464cbbdc1a [gaim-migrate @ 10505]
Mark Doliner <mark@kingant.net>
parents: 9656
diff changeset
472 #if HAVE_GETADDRINFO
51464cbbdc1a [gaim-migrate @ 10505]
Mark Doliner <mark@kingant.net>
parents: 9656
diff changeset
473 g_snprintf(servname, sizeof(servname), "%d", dns_params->port);
51464cbbdc1a [gaim-migrate @ 10505]
Mark Doliner <mark@kingant.net>
parents: 9656
diff changeset
474 memset(&hints,0,sizeof(hints));
51464cbbdc1a [gaim-migrate @ 10505]
Mark Doliner <mark@kingant.net>
parents: 9656
diff changeset
475
51464cbbdc1a [gaim-migrate @ 10505]
Mark Doliner <mark@kingant.net>
parents: 9656
diff changeset
476 /* This is only used to convert a service
51464cbbdc1a [gaim-migrate @ 10505]
Mark Doliner <mark@kingant.net>
parents: 9656
diff changeset
477 * name to a port number. As we know we are
51464cbbdc1a [gaim-migrate @ 10505]
Mark Doliner <mark@kingant.net>
parents: 9656
diff changeset
478 * passing a number already, we know this
51464cbbdc1a [gaim-migrate @ 10505]
Mark Doliner <mark@kingant.net>
parents: 9656
diff changeset
479 * value will not be really used by the C
51464cbbdc1a [gaim-migrate @ 10505]
Mark Doliner <mark@kingant.net>
parents: 9656
diff changeset
480 * library.
51464cbbdc1a [gaim-migrate @ 10505]
Mark Doliner <mark@kingant.net>
parents: 9656
diff changeset
481 */
51464cbbdc1a [gaim-migrate @ 10505]
Mark Doliner <mark@kingant.net>
parents: 9656
diff changeset
482 hints.ai_socktype = SOCK_STREAM;
51464cbbdc1a [gaim-migrate @ 10505]
Mark Doliner <mark@kingant.net>
parents: 9656
diff changeset
483 rc = getaddrinfo(dns_params->hostname, servname, &hints, &res);
9729
f44ae9331afc [gaim-migrate @ 10590]
Mark Doliner <mark@kingant.net>
parents: 9657
diff changeset
484 if (rc) {
9657
51464cbbdc1a [gaim-migrate @ 10505]
Mark Doliner <mark@kingant.net>
parents: 9656
diff changeset
485 write(child_out, &rc, sizeof(int));
51464cbbdc1a [gaim-migrate @ 10505]
Mark Doliner <mark@kingant.net>
parents: 9656
diff changeset
486 close(child_out);
9729
f44ae9331afc [gaim-migrate @ 10590]
Mark Doliner <mark@kingant.net>
parents: 9657
diff changeset
487 if (show_debug)
9657
51464cbbdc1a [gaim-migrate @ 10505]
Mark Doliner <mark@kingant.net>
parents: 9656
diff changeset
488 fprintf(stderr,"dns[%d] Error: getaddrinfo returned %d\n",
51464cbbdc1a [gaim-migrate @ 10505]
Mark Doliner <mark@kingant.net>
parents: 9656
diff changeset
489 getpid(), rc);
51464cbbdc1a [gaim-migrate @ 10505]
Mark Doliner <mark@kingant.net>
parents: 9656
diff changeset
490 dns_params->hostname[0] = '\0';
51464cbbdc1a [gaim-migrate @ 10505]
Mark Doliner <mark@kingant.net>
parents: 9656
diff changeset
491 continue;
51464cbbdc1a [gaim-migrate @ 10505]
Mark Doliner <mark@kingant.net>
parents: 9656
diff changeset
492 }
51464cbbdc1a [gaim-migrate @ 10505]
Mark Doliner <mark@kingant.net>
parents: 9656
diff changeset
493 write(child_out, &zero, sizeof(zero));
51464cbbdc1a [gaim-migrate @ 10505]
Mark Doliner <mark@kingant.net>
parents: 9656
diff changeset
494 tmp = res;
51464cbbdc1a [gaim-migrate @ 10505]
Mark Doliner <mark@kingant.net>
parents: 9656
diff changeset
495 while(res) {
51464cbbdc1a [gaim-migrate @ 10505]
Mark Doliner <mark@kingant.net>
parents: 9656
diff changeset
496 size_t ai_addrlen = res->ai_addrlen;
51464cbbdc1a [gaim-migrate @ 10505]
Mark Doliner <mark@kingant.net>
parents: 9656
diff changeset
497 write(child_out, &ai_addrlen, sizeof(ai_addrlen));
51464cbbdc1a [gaim-migrate @ 10505]
Mark Doliner <mark@kingant.net>
parents: 9656
diff changeset
498 write(child_out, res->ai_addr, res->ai_addrlen);
51464cbbdc1a [gaim-migrate @ 10505]
Mark Doliner <mark@kingant.net>
parents: 9656
diff changeset
499 res = res->ai_next;
51464cbbdc1a [gaim-migrate @ 10505]
Mark Doliner <mark@kingant.net>
parents: 9656
diff changeset
500 }
51464cbbdc1a [gaim-migrate @ 10505]
Mark Doliner <mark@kingant.net>
parents: 9656
diff changeset
501 freeaddrinfo(tmp);
51464cbbdc1a [gaim-migrate @ 10505]
Mark Doliner <mark@kingant.net>
parents: 9656
diff changeset
502 write(child_out, &zero, sizeof(zero));
51464cbbdc1a [gaim-migrate @ 10505]
Mark Doliner <mark@kingant.net>
parents: 9656
diff changeset
503 #else
10264
36b7335d3452 [gaim-migrate @ 11410]
Mark Doliner <mark@kingant.net>
parents: 10239
diff changeset
504 if (!inet_aton(dns_params->hostname, &sin.sin_addr)) {
9657
51464cbbdc1a [gaim-migrate @ 10505]
Mark Doliner <mark@kingant.net>
parents: 9656
diff changeset
505 struct hostent *hp;
9729
f44ae9331afc [gaim-migrate @ 10590]
Mark Doliner <mark@kingant.net>
parents: 9657
diff changeset
506 if (!(hp = gethostbyname(dns_params->hostname))) {
9657
51464cbbdc1a [gaim-migrate @ 10505]
Mark Doliner <mark@kingant.net>
parents: 9656
diff changeset
507 write(child_out, &h_errno, sizeof(int));
51464cbbdc1a [gaim-migrate @ 10505]
Mark Doliner <mark@kingant.net>
parents: 9656
diff changeset
508 close(child_out);
9729
f44ae9331afc [gaim-migrate @ 10590]
Mark Doliner <mark@kingant.net>
parents: 9657
diff changeset
509 if (show_debug)
9657
51464cbbdc1a [gaim-migrate @ 10505]
Mark Doliner <mark@kingant.net>
parents: 9656
diff changeset
510 fprintf(stderr,"DNS Error: %d\n", h_errno);
51464cbbdc1a [gaim-migrate @ 10505]
Mark Doliner <mark@kingant.net>
parents: 9656
diff changeset
511 _exit(0);
51464cbbdc1a [gaim-migrate @ 10505]
Mark Doliner <mark@kingant.net>
parents: 9656
diff changeset
512 }
51464cbbdc1a [gaim-migrate @ 10505]
Mark Doliner <mark@kingant.net>
parents: 9656
diff changeset
513 memset(&sin, 0, sizeof(struct sockaddr_in));
51464cbbdc1a [gaim-migrate @ 10505]
Mark Doliner <mark@kingant.net>
parents: 9656
diff changeset
514 memcpy(&sin.sin_addr.s_addr, hp->h_addr, hp->h_length);
51464cbbdc1a [gaim-migrate @ 10505]
Mark Doliner <mark@kingant.net>
parents: 9656
diff changeset
515 sin.sin_family = hp->h_addrtype;
51464cbbdc1a [gaim-migrate @ 10505]
Mark Doliner <mark@kingant.net>
parents: 9656
diff changeset
516 } else
51464cbbdc1a [gaim-migrate @ 10505]
Mark Doliner <mark@kingant.net>
parents: 9656
diff changeset
517 sin.sin_family = AF_INET;
51464cbbdc1a [gaim-migrate @ 10505]
Mark Doliner <mark@kingant.net>
parents: 9656
diff changeset
518
51464cbbdc1a [gaim-migrate @ 10505]
Mark Doliner <mark@kingant.net>
parents: 9656
diff changeset
519 sin.sin_port = htons(dns_params->port);
51464cbbdc1a [gaim-migrate @ 10505]
Mark Doliner <mark@kingant.net>
parents: 9656
diff changeset
520 write(child_out, &zero, sizeof(zero));
51464cbbdc1a [gaim-migrate @ 10505]
Mark Doliner <mark@kingant.net>
parents: 9656
diff changeset
521 write(child_out, &addrlen, sizeof(addrlen));
51464cbbdc1a [gaim-migrate @ 10505]
Mark Doliner <mark@kingant.net>
parents: 9656
diff changeset
522 write(child_out, &sin, addrlen);
51464cbbdc1a [gaim-migrate @ 10505]
Mark Doliner <mark@kingant.net>
parents: 9656
diff changeset
523 write(child_out, &zero, sizeof(zero));
51464cbbdc1a [gaim-migrate @ 10505]
Mark Doliner <mark@kingant.net>
parents: 9656
diff changeset
524 #endif
51464cbbdc1a [gaim-migrate @ 10505]
Mark Doliner <mark@kingant.net>
parents: 9656
diff changeset
525 dns_params->hostname[0] = '\0';
51464cbbdc1a [gaim-migrate @ 10505]
Mark Doliner <mark@kingant.net>
parents: 9656
diff changeset
526 }
51464cbbdc1a [gaim-migrate @ 10505]
Mark Doliner <mark@kingant.net>
parents: 9656
diff changeset
527
51464cbbdc1a [gaim-migrate @ 10505]
Mark Doliner <mark@kingant.net>
parents: 9656
diff changeset
528 close(child_out);
51464cbbdc1a [gaim-migrate @ 10505]
Mark Doliner <mark@kingant.net>
parents: 9656
diff changeset
529 close(child_in);
51464cbbdc1a [gaim-migrate @ 10505]
Mark Doliner <mark@kingant.net>
parents: 9656
diff changeset
530
51464cbbdc1a [gaim-migrate @ 10505]
Mark Doliner <mark@kingant.net>
parents: 9656
diff changeset
531 _exit(0);
51464cbbdc1a [gaim-migrate @ 10505]
Mark Doliner <mark@kingant.net>
parents: 9656
diff changeset
532 }
51464cbbdc1a [gaim-migrate @ 10505]
Mark Doliner <mark@kingant.net>
parents: 9656
diff changeset
533
4434
6b83a532eeb2 [gaim-migrate @ 4709]
Nathan Walp <nwalp@pidgin.im>
parents: 4394
diff changeset
534 int 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
535 {
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
536 pending_dns_request_t *req = NULL;
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
537 dns_params_t dns_params;
9656
2ea77e275b85 [gaim-migrate @ 10504]
Mark Doliner <mark@kingant.net>
parents: 9655
diff changeset
538 gchar *host_temp;
9655
00f96f4cc775 [gaim-migrate @ 10503]
Luke Schierer <lschiere@pidgin.im>
parents: 9653
diff changeset
539
9656
2ea77e275b85 [gaim-migrate @ 10504]
Mark Doliner <mark@kingant.net>
parents: 9655
diff changeset
540 host_temp = g_strstrip(g_strdup(hostname));
2ea77e275b85 [gaim-migrate @ 10504]
Mark Doliner <mark@kingant.net>
parents: 9655
diff changeset
541 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
542 g_free(host_temp);
9656
2ea77e275b85 [gaim-migrate @ 10504]
Mark Doliner <mark@kingant.net>
parents: 9655
diff changeset
543 dns_params.hostname[sizeof(dns_params.hostname) - 1] = '\0';
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
544 dns_params.port = port;
9129
3e94a77ee0c7 [gaim-migrate @ 9907]
Nathan Walp <nwalp@pidgin.im>
parents: 9100
diff changeset
545
9656
2ea77e275b85 [gaim-migrate @ 10504]
Mark Doliner <mark@kingant.net>
parents: 9655
diff changeset
546 /*
2ea77e275b85 [gaim-migrate @ 10504]
Mark Doliner <mark@kingant.net>
parents: 9655
diff changeset
547 * 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
548 * 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
549 * 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
550 * 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
551 */
2ea77e275b85 [gaim-migrate @ 10504]
Mark Doliner <mark@kingant.net>
parents: 9655
diff changeset
552 while (free_dns_children != NULL) {
2ea77e275b85 [gaim-migrate @ 10504]
Mark Doliner <mark@kingant.net>
parents: 9655
diff changeset
553 req = free_dns_children->data;
2ea77e275b85 [gaim-migrate @ 10504]
Mark Doliner <mark@kingant.net>
parents: 9655
diff changeset
554 free_dns_children = g_slist_remove(free_dns_children, req);
9129
3e94a77ee0c7 [gaim-migrate @ 9907]
Nathan Walp <nwalp@pidgin.im>
parents: 9100
diff changeset
555
9656
2ea77e275b85 [gaim-migrate @ 10504]
Mark Doliner <mark@kingant.net>
parents: 9655
diff changeset
556 if (send_dns_request_to_child(req, &dns_params) == 0)
2ea77e275b85 [gaim-migrate @ 10504]
Mark Doliner <mark@kingant.net>
parents: 9655
diff changeset
557 /* We found an acceptable child, yay */
2ea77e275b85 [gaim-migrate @ 10504]
Mark Doliner <mark@kingant.net>
parents: 9655
diff changeset
558 break;
9129
3e94a77ee0c7 [gaim-migrate @ 9907]
Nathan Walp <nwalp@pidgin.im>
parents: 9100
diff changeset
559
9656
2ea77e275b85 [gaim-migrate @ 10504]
Mark Doliner <mark@kingant.net>
parents: 9655
diff changeset
560 req_free(req);
9657
51464cbbdc1a [gaim-migrate @ 10505]
Mark Doliner <mark@kingant.net>
parents: 9656
diff changeset
561 req = NULL;
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
562 }
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
563
9657
51464cbbdc1a [gaim-migrate @ 10505]
Mark Doliner <mark@kingant.net>
parents: 9656
diff changeset
564 /* We need to create a new DNS request child */
9656
2ea77e275b85 [gaim-migrate @ 10504]
Mark Doliner <mark@kingant.net>
parents: 9655
diff changeset
565 if (req == NULL) {
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
566 int child_out[2], child_in[2];
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
567
9656
2ea77e275b85 [gaim-migrate @ 10504]
Mark Doliner <mark@kingant.net>
parents: 9655
diff changeset
568 if (number_of_dns_children >= MAX_DNS_CHILDREN) {
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
569 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
570 memcpy(&(r->params), &dns_params, sizeof(dns_params));
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
571 r->callback = callback;
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
572 r->data = data;
9656
2ea77e275b85 [gaim-migrate @ 10504]
Mark Doliner <mark@kingant.net>
parents: 9655
diff changeset
573 if (!queued_requests)
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
574 queued_requests = g_queue_new();
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
575 g_queue_push_tail(queued_requests, r);
5211
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
576
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
577 gaim_debug(GAIM_DEBUG_INFO, "dns",
9656
2ea77e275b85 [gaim-migrate @ 10504]
Mark Doliner <mark@kingant.net>
parents: 9655
diff changeset
578 "DNS query for '%s' queued\n", dns_params.hostname);
5211
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
579
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
580 return 0;
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
581 }
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
582
9657
51464cbbdc1a [gaim-migrate @ 10505]
Mark Doliner <mark@kingant.net>
parents: 9656
diff changeset
583 /* Create pipes for communicating with the child process */
9656
2ea77e275b85 [gaim-migrate @ 10504]
Mark Doliner <mark@kingant.net>
parents: 9655
diff changeset
584 if (pipe(child_out) || pipe(child_in)) {
5211
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
585 gaim_debug(GAIM_DEBUG_ERROR, "dns",
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
586 "Could not create pipes: %s\n", strerror(errno));
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
587 return -1;
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
588 }
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
589
9657
51464cbbdc1a [gaim-migrate @ 10505]
Mark Doliner <mark@kingant.net>
parents: 9656
diff changeset
590 req = g_new(pending_dns_request_t, 1);
9655
00f96f4cc775 [gaim-migrate @ 10503]
Luke Schierer <lschiere@pidgin.im>
parents: 9653
diff changeset
591
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
592 cope_with_gdb_brokenness();
9655
00f96f4cc775 [gaim-migrate @ 10503]
Luke Schierer <lschiere@pidgin.im>
parents: 9653
diff changeset
593
9657
51464cbbdc1a [gaim-migrate @ 10505]
Mark Doliner <mark@kingant.net>
parents: 9656
diff changeset
594 /* Fork! */
9656
2ea77e275b85 [gaim-migrate @ 10504]
Mark Doliner <mark@kingant.net>
parents: 9655
diff changeset
595 req->dns_pid = fork();
2ea77e275b85 [gaim-migrate @ 10504]
Mark Doliner <mark@kingant.net>
parents: 9655
diff changeset
596
9657
51464cbbdc1a [gaim-migrate @ 10505]
Mark Doliner <mark@kingant.net>
parents: 9656
diff changeset
597 /* If we are the child process... */
9729
f44ae9331afc [gaim-migrate @ 10590]
Mark Doliner <mark@kingant.net>
parents: 9657
diff changeset
598 if (req->dns_pid == 0) {
9656
2ea77e275b85 [gaim-migrate @ 10504]
Mark Doliner <mark@kingant.net>
parents: 9655
diff changeset
599 /* We should not access the parent's side of the pipe, so close them... */
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
600 close(child_out[0]);
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
601 close(child_in[1]);
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
602
9729
f44ae9331afc [gaim-migrate @ 10590]
Mark Doliner <mark@kingant.net>
parents: 9657
diff changeset
603 gaim_dns_childthread(child_out[1], child_in[0], &dns_params, opt_debug);
9657
51464cbbdc1a [gaim-migrate @ 10505]
Mark Doliner <mark@kingant.net>
parents: 9656
diff changeset
604 /* The thread calls _exit() rather than returning, so we never get here */
51464cbbdc1a [gaim-migrate @ 10505]
Mark Doliner <mark@kingant.net>
parents: 9656
diff changeset
605 }
9656
2ea77e275b85 [gaim-migrate @ 10504]
Mark Doliner <mark@kingant.net>
parents: 9655
diff changeset
606
2ea77e275b85 [gaim-migrate @ 10504]
Mark Doliner <mark@kingant.net>
parents: 9655
diff changeset
607 /* We should not access the child's side of the pipe, so close them... */
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
608 close(child_out[1]);
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
609 close(child_in[0]);
9657
51464cbbdc1a [gaim-migrate @ 10505]
Mark Doliner <mark@kingant.net>
parents: 9656
diff changeset
610 if (req->dns_pid == -1) {
5211
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
611 gaim_debug(GAIM_DEBUG_ERROR, "dns",
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
612 "Could not create child process for DNS: %s\n",
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
613 strerror(errno));
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
614 g_free(req);
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
615 return -1;
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
616 }
9657
51464cbbdc1a [gaim-migrate @ 10505]
Mark Doliner <mark@kingant.net>
parents: 9656
diff changeset
617
9656
2ea77e275b85 [gaim-migrate @ 10504]
Mark Doliner <mark@kingant.net>
parents: 9655
diff changeset
618 req->fd_out = child_out[0];
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
619 req->fd_in = child_in[1];
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
620 number_of_dns_children++;
5211
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
621 gaim_debug(GAIM_DEBUG_INFO, "dns",
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
622 "Created new DNS child %d, there are now %d children.\n",
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
623 req->dns_pid, number_of_dns_children);
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
624 }
9656
2ea77e275b85 [gaim-migrate @ 10504]
Mark Doliner <mark@kingant.net>
parents: 9655
diff changeset
625
9657
51464cbbdc1a [gaim-migrate @ 10505]
Mark Doliner <mark@kingant.net>
parents: 9656
diff changeset
626 req->host = g_strdup(hostname);
9656
2ea77e275b85 [gaim-migrate @ 10504]
Mark Doliner <mark@kingant.net>
parents: 9655
diff changeset
627 req->port = port;
2ea77e275b85 [gaim-migrate @ 10504]
Mark Doliner <mark@kingant.net>
parents: 9655
diff changeset
628 req->callback = callback;
2ea77e275b85 [gaim-migrate @ 10504]
Mark Doliner <mark@kingant.net>
parents: 9655
diff changeset
629 req->data = data;
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
630 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
631
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
632 return 0;
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
633 }
10237
2f6dcbaaabe0 [gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 10172
diff changeset
634
10239
d0558652e0c4 [gaim-migrate @ 11376]
Sean Egan <seanegan@gmail.com>
parents: 10237
diff changeset
635 #elif defined _WIN32 /* end __unix__ */
10237
2f6dcbaaabe0 [gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 10172
diff changeset
636
2f6dcbaaabe0 [gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 10172
diff changeset
637 /* Note: The below win32 implementation is actually platform independent.
2f6dcbaaabe0 [gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 10172
diff changeset
638 Perhaps this can be used in place of the above platform dependent code.
2f6dcbaaabe0 [gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 10172
diff changeset
639 */
2f6dcbaaabe0 [gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 10172
diff changeset
640
2f6dcbaaabe0 [gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 10172
diff changeset
641 typedef struct _dns_tdata {
2f6dcbaaabe0 [gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 10172
diff changeset
642 char *hostname;
2f6dcbaaabe0 [gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 10172
diff changeset
643 int port;
2f6dcbaaabe0 [gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 10172
diff changeset
644 dns_callback_t callback;
2f6dcbaaabe0 [gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 10172
diff changeset
645 gpointer data;
2f6dcbaaabe0 [gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 10172
diff changeset
646 GSList *hosts;
2f6dcbaaabe0 [gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 10172
diff changeset
647 char *errmsg;
2f6dcbaaabe0 [gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 10172
diff changeset
648 } dns_tdata;
2f6dcbaaabe0 [gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 10172
diff changeset
649
2f6dcbaaabe0 [gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 10172
diff changeset
650 static gboolean dns_main_thread_cb(gpointer data) {
2f6dcbaaabe0 [gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 10172
diff changeset
651 dns_tdata *td = (dns_tdata*)data;
2f6dcbaaabe0 [gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 10172
diff changeset
652 td->callback(td->hosts, td->data, td->errmsg);
2f6dcbaaabe0 [gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 10172
diff changeset
653 g_free(td->hostname);
2f6dcbaaabe0 [gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 10172
diff changeset
654 g_free(td);
2f6dcbaaabe0 [gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 10172
diff changeset
655 return FALSE;
2f6dcbaaabe0 [gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 10172
diff changeset
656 }
2f6dcbaaabe0 [gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 10172
diff changeset
657
2f6dcbaaabe0 [gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 10172
diff changeset
658 static gpointer dns_thread(gpointer data) {
2f6dcbaaabe0 [gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 10172
diff changeset
659 struct sockaddr_in sin;
2f6dcbaaabe0 [gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 10172
diff changeset
660 dns_tdata *td = (dns_tdata*)data;
2f6dcbaaabe0 [gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 10172
diff changeset
661 struct hostent *hp;
2f6dcbaaabe0 [gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 10172
diff changeset
662
2f6dcbaaabe0 [gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 10172
diff changeset
663 if(!(hp = gethostbyname(td->hostname)))
2f6dcbaaabe0 [gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 10172
diff changeset
664 goto failure;
2f6dcbaaabe0 [gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 10172
diff changeset
665 memset(&sin, 0, sizeof(struct sockaddr_in));
2f6dcbaaabe0 [gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 10172
diff changeset
666 memcpy(&sin.sin_addr.s_addr, hp->h_addr, hp->h_length);
2f6dcbaaabe0 [gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 10172
diff changeset
667 sin.sin_family = hp->h_addrtype;
2f6dcbaaabe0 [gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 10172
diff changeset
668 sin.sin_port = htons(td->port);
2f6dcbaaabe0 [gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 10172
diff changeset
669
2f6dcbaaabe0 [gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 10172
diff changeset
670 td->hosts = g_slist_append(td->hosts, GINT_TO_POINTER(sizeof(sin)));
2f6dcbaaabe0 [gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 10172
diff changeset
671 td->hosts = g_slist_append(td->hosts, g_memdup(&sin, sizeof(sin)));
2f6dcbaaabe0 [gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 10172
diff changeset
672 /* back to main thread */
2f6dcbaaabe0 [gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 10172
diff changeset
673 g_idle_add(dns_main_thread_cb, td);
2f6dcbaaabe0 [gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 10172
diff changeset
674 return 0;
2f6dcbaaabe0 [gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 10172
diff changeset
675 failure:
2f6dcbaaabe0 [gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 10172
diff changeset
676 g_free(td->hostname);
2f6dcbaaabe0 [gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 10172
diff changeset
677 g_free(td);
2f6dcbaaabe0 [gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 10172
diff changeset
678 return 0;
2f6dcbaaabe0 [gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 10172
diff changeset
679 }
2f6dcbaaabe0 [gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 10172
diff changeset
680
2f6dcbaaabe0 [gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 10172
diff changeset
681 int gaim_gethostbyname_async(const char *hostname, int port,
2f6dcbaaabe0 [gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 10172
diff changeset
682 dns_callback_t callback, gpointer data) {
2f6dcbaaabe0 [gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 10172
diff changeset
683 dns_tdata *td;
2f6dcbaaabe0 [gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 10172
diff changeset
684 struct sockaddr_in sin;
2f6dcbaaabe0 [gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 10172
diff changeset
685 GError* err = NULL;
2f6dcbaaabe0 [gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 10172
diff changeset
686
2f6dcbaaabe0 [gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 10172
diff changeset
687 if(inet_aton(hostname, &sin.sin_addr)) {
2f6dcbaaabe0 [gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 10172
diff changeset
688 GSList *hosts = NULL;
2f6dcbaaabe0 [gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 10172
diff changeset
689 sin.sin_family = AF_INET;
2f6dcbaaabe0 [gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 10172
diff changeset
690 sin.sin_port = htons(port);
2f6dcbaaabe0 [gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 10172
diff changeset
691 hosts = g_slist_append(hosts, GINT_TO_POINTER(sizeof(sin)));
2f6dcbaaabe0 [gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 10172
diff changeset
692 hosts = g_slist_append(hosts, g_memdup(&sin, sizeof(sin)));
2f6dcbaaabe0 [gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 10172
diff changeset
693 callback(hosts, data, NULL);
2f6dcbaaabe0 [gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 10172
diff changeset
694 return 0;
2f6dcbaaabe0 [gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 10172
diff changeset
695 }
2f6dcbaaabe0 [gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 10172
diff changeset
696
2f6dcbaaabe0 [gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 10172
diff changeset
697 gaim_debug_info("dns", "DNS Lookup for: %s\n", hostname);
2f6dcbaaabe0 [gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 10172
diff changeset
698 td = g_new0(dns_tdata, 1);
2f6dcbaaabe0 [gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 10172
diff changeset
699 td->hostname = g_strdup(hostname);
2f6dcbaaabe0 [gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 10172
diff changeset
700 td->port = port;
2f6dcbaaabe0 [gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 10172
diff changeset
701 td->callback = callback;
2f6dcbaaabe0 [gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 10172
diff changeset
702 td->data = data;
2f6dcbaaabe0 [gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 10172
diff changeset
703
2f6dcbaaabe0 [gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 10172
diff changeset
704 if(!g_thread_create(dns_thread, td, FALSE, &err)) {
2f6dcbaaabe0 [gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 10172
diff changeset
705 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
706 g_error_free(err);
2f6dcbaaabe0 [gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 10172
diff changeset
707 g_free(td->hostname);
2f6dcbaaabe0 [gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 10172
diff changeset
708 g_free(td);
2f6dcbaaabe0 [gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 10172
diff changeset
709 return -1;
2f6dcbaaabe0 [gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 10172
diff changeset
710 }
2f6dcbaaabe0 [gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 10172
diff changeset
711 return 0;
2f6dcbaaabe0 [gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 10172
diff changeset
712 }
2f6dcbaaabe0 [gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 10172
diff changeset
713
2f6dcbaaabe0 [gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 10172
diff changeset
714 #else /* not __unix__ or _WIN32 */
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
715
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
716 typedef struct {
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
717 gpointer data;
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
718 size_t addrlen;
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
719 struct sockaddr *addr;
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
720 dns_callback_t callback;
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
721 } pending_dns_request_t;
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
722
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
723 static gboolean host_resolved(gpointer data)
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
724 {
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
725 pending_dns_request_t *req = (pending_dns_request_t*)data;
4678
9ce3c698ff5e [gaim-migrate @ 4989]
Nathan Walp <nwalp@pidgin.im>
parents: 4648
diff changeset
726 GSList *hosts = NULL;
9ce3c698ff5e [gaim-migrate @ 4989]
Nathan Walp <nwalp@pidgin.im>
parents: 4648
diff changeset
727 hosts = g_slist_append(hosts, GINT_TO_POINTER(req->addrlen));
9ce3c698ff5e [gaim-migrate @ 4989]
Nathan Walp <nwalp@pidgin.im>
parents: 4648
diff changeset
728 hosts = g_slist_append(hosts, req->addr);
9ce3c698ff5e [gaim-migrate @ 4989]
Nathan Walp <nwalp@pidgin.im>
parents: 4648
diff changeset
729 req->callback(hosts, req->data, NULL);
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
730 g_free(req);
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
731 return FALSE;
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
732 }
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
733
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
734 int
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
735 gaim_gethostbyname_async(const char *hostname, int port,
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
736 dns_callback_t callback, gpointer data)
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
737 {
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
738 struct sockaddr_in sin;
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
739 pending_dns_request_t *req;
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
740
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
741 if (!inet_aton(hostname, &sin.sin_addr)) {
2911
4790fb1272a1 [gaim-migrate @ 2924]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2907
diff changeset
742 struct hostent *hp;
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
743 if(!(hp = gethostbyname(hostname))) {
5211
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
744 gaim_debug(GAIM_DEBUG_ERROR, "dns",
8977
52fba1dafe0e [gaim-migrate @ 9751]
Mark Doliner <mark@kingant.net>
parents: 8917
diff changeset
745 "gaim_gethostbyname(\"%s\", %d) failed: %d\n",
52fba1dafe0e [gaim-migrate @ 9751]
Mark Doliner <mark@kingant.net>
parents: 8917
diff changeset
746 hostname, port, h_errno);
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
747 return -1;
2911
4790fb1272a1 [gaim-migrate @ 2924]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2907
diff changeset
748 }
4790fb1272a1 [gaim-migrate @ 2924]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2907
diff changeset
749 memset(&sin, 0, sizeof(struct sockaddr_in));
4790fb1272a1 [gaim-migrate @ 2924]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2907
diff changeset
750 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
751 sin.sin_family = hp->h_addrtype;
4790fb1272a1 [gaim-migrate @ 2924]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2907
diff changeset
752 } else
4790fb1272a1 [gaim-migrate @ 2924]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2907
diff changeset
753 sin.sin_family = AF_INET;
4790fb1272a1 [gaim-migrate @ 2924]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2907
diff changeset
754 sin.sin_port = htons(port);
4790fb1272a1 [gaim-migrate @ 2924]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2907
diff changeset
755
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
756 req = g_new(pending_dns_request_t, 1);
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
757 req->addr = (struct sockaddr*) g_memdup(&sin, sizeof(sin));
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
758 req->addrlen = sizeof(sin);
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
759 req->data = data;
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
760 req->callback = callback;
8273
f24172f53650 [gaim-migrate @ 8997]
Christian Hammond <chipx86@chipx86.com>
parents: 8269
diff changeset
761 gaim_timeout_add(10, host_resolved, req);
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
762 return 0;
2911
4790fb1272a1 [gaim-migrate @ 2924]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2907
diff changeset
763 }
4790fb1272a1 [gaim-migrate @ 2924]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2907
diff changeset
764
10237
2f6dcbaaabe0 [gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 10172
diff changeset
765 #endif /* not __unix__ or _WIN32 */
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
766
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
767 static void
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
768 no_one_calls(gpointer data, gint source, GaimInputCondition cond)
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
769 {
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
770 struct PHB *phb = data;
2048
3366311426df [gaim-migrate @ 2058]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1881
diff changeset
771 unsigned int len;
8273
f24172f53650 [gaim-migrate @ 8997]
Christian Hammond <chipx86@chipx86.com>
parents: 8269
diff changeset
772 int error=0, ret;
3717
988485669631 [gaim-migrate @ 3850]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 3630
diff changeset
773
5211
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
774 gaim_debug(GAIM_DEBUG_INFO, "proxy", "Connected.\n");
3717
988485669631 [gaim-migrate @ 3850]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 3630
diff changeset
775
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
776 len = sizeof(error);
4648
4bb99cdfd837 [gaim-migrate @ 4959]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 4634
diff changeset
777
8273
f24172f53650 [gaim-migrate @ 8997]
Christian Hammond <chipx86@chipx86.com>
parents: 8269
diff changeset
778 /*
f24172f53650 [gaim-migrate @ 8997]
Christian Hammond <chipx86@chipx86.com>
parents: 8269
diff changeset
779 * getsockopt after a non-blocking connect returns -1 if something is
f24172f53650 [gaim-migrate @ 8997]
Christian Hammond <chipx86@chipx86.com>
parents: 8269
diff changeset
780 * really messed up (bad descriptor, usually). Otherwise, it returns 0 and
f24172f53650 [gaim-migrate @ 8997]
Christian Hammond <chipx86@chipx86.com>
parents: 8269
diff changeset
781 * 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
782 * Thus, error == 0 is success, error == EINPROGRESS means "try again",
f24172f53650 [gaim-migrate @ 8997]
Christian Hammond <chipx86@chipx86.com>
parents: 8269
diff changeset
783 * and anything else is a real error.
f24172f53650 [gaim-migrate @ 8997]
Christian Hammond <chipx86@chipx86.com>
parents: 8269
diff changeset
784 *
f24172f53650 [gaim-migrate @ 8997]
Christian Hammond <chipx86@chipx86.com>
parents: 8269
diff changeset
785 * (error == EINPROGRESS can happen after a select because the kernel can
f24172f53650 [gaim-migrate @ 8997]
Christian Hammond <chipx86@chipx86.com>
parents: 8269
diff changeset
786 * 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
787 * able to do something.)
f24172f53650 [gaim-migrate @ 8997]
Christian Hammond <chipx86@chipx86.com>
parents: 8269
diff changeset
788 */
f24172f53650 [gaim-migrate @ 8997]
Christian Hammond <chipx86@chipx86.com>
parents: 8269
diff changeset
789 ret = getsockopt(source, SOL_SOCKET, SO_ERROR, &error, &len);
f24172f53650 [gaim-migrate @ 8997]
Christian Hammond <chipx86@chipx86.com>
parents: 8269
diff changeset
790 if (ret == 0 && error == EINPROGRESS)
9863
0e3a84f18467 [gaim-migrate @ 10742]
Mark Doliner <mark@kingant.net>
parents: 9792
diff changeset
791 return; /* we'll be called again later */
8273
f24172f53650 [gaim-migrate @ 8997]
Christian Hammond <chipx86@chipx86.com>
parents: 8269
diff changeset
792 if (ret < 0 || error != 0) {
9100
4b3e5a5063f9 [gaim-migrate @ 9877]
Ethan Blanton <elb@pidgin.im>
parents: 8977
diff changeset
793 if(ret!=0) error = errno;
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
794 close(source);
2090
b66aca8e8dce [gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2048
diff changeset
795 gaim_input_remove(phb->inpa);
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
796
5211
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
797 gaim_debug(GAIM_DEBUG_ERROR, "proxy",
9100
4b3e5a5063f9 [gaim-migrate @ 9877]
Ethan Blanton <elb@pidgin.im>
parents: 8977
diff changeset
798 "getsockopt SO_ERROR check: %s\n", strerror(error));
9129
3e94a77ee0c7 [gaim-migrate @ 9907]
Nathan Walp <nwalp@pidgin.im>
parents: 9100
diff changeset
799
3e94a77ee0c7 [gaim-migrate @ 9907]
Nathan Walp <nwalp@pidgin.im>
parents: 9100
diff changeset
800 try_connect(phb);
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
801 return;
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
802 }
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
803
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
804 fcntl(source, F_SETFL, 0);
2090
b66aca8e8dce [gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2048
diff changeset
805 gaim_input_remove(phb->inpa);
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
806
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
807 if (phb->account == NULL ||
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
808 gaim_account_get_connection(phb->account) != NULL) {
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
809
4993
de84c1de2f66 [gaim-migrate @ 5328]
Nathan Walp <nwalp@pidgin.im>
parents: 4679
diff changeset
810 phb->func(phb->data, source, GAIM_INPUT_READ);
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
811 }
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
812
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
813 g_free(phb->host);
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
814 g_free(phb);
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
815 }
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
816
1868
a49ed23b3c02 [gaim-migrate @ 1878]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1844
diff changeset
817 static gboolean clean_connect(gpointer data)
a49ed23b3c02 [gaim-migrate @ 1878]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1844
diff changeset
818 {
a49ed23b3c02 [gaim-migrate @ 1878]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1844
diff changeset
819 struct PHB *phb = data;
a49ed23b3c02 [gaim-migrate @ 1878]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1844
diff changeset
820
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
821 if (phb->account == NULL ||
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
822 gaim_account_get_connection(phb->account) != NULL) {
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
823
4993
de84c1de2f66 [gaim-migrate @ 5328]
Nathan Walp <nwalp@pidgin.im>
parents: 4679
diff changeset
824 phb->func(phb->data, phb->port, GAIM_INPUT_READ);
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
825 }
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
826
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
827 g_free(phb->host);
1868
a49ed23b3c02 [gaim-migrate @ 1878]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1844
diff changeset
828 g_free(phb);
a49ed23b3c02 [gaim-migrate @ 1878]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1844
diff changeset
829
a49ed23b3c02 [gaim-migrate @ 1878]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1844
diff changeset
830 return FALSE;
a49ed23b3c02 [gaim-migrate @ 1878]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1844
diff changeset
831 }
a49ed23b3c02 [gaim-migrate @ 1878]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1844
diff changeset
832
a49ed23b3c02 [gaim-migrate @ 1878]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1844
diff changeset
833
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
834 static int
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
835 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
836 {
1087
56c7ceb986a8 [gaim-migrate @ 1097]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1057
diff changeset
837 int fd = -1;
3717
988485669631 [gaim-migrate @ 3850]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 3630
diff changeset
838
5211
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
839 gaim_debug(GAIM_DEBUG_INFO, "proxy",
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
840 "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
841
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
842 if ((fd = socket(addr->sa_family, SOCK_STREAM, 0)) < 0) {
5211
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
843 gaim_debug(GAIM_DEBUG_ERROR, "proxy",
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
844 "Unable to create socket: %s\n", strerror(errno));
1087
56c7ceb986a8 [gaim-migrate @ 1097]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1057
diff changeset
845 return -1;
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
846 }
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
847 fcntl(fd, F_SETFL, O_NONBLOCK);
10172
374d63326461 [gaim-migrate @ 11275]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10170
diff changeset
848 #ifndef _WIN32
10170
3c88c2f1b732 [gaim-migrate @ 11262]
Ethan Blanton <elb@pidgin.im>
parents: 10087
diff changeset
849 fcntl(fd, F_SETFD, FD_CLOEXEC);
10172
374d63326461 [gaim-migrate @ 11275]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10170
diff changeset
850 #endif
3717
988485669631 [gaim-migrate @ 3850]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 3630
diff changeset
851
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
852 if (connect(fd, (struct sockaddr *)addr, addrlen) < 0) {
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
853 if ((errno == EINPROGRESS) || (errno == EINTR)) {
5211
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
854 gaim_debug(GAIM_DEBUG_WARNING, "proxy",
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
855 "Connect would have blocked.\n");
2090
b66aca8e8dce [gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2048
diff changeset
856 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
857 }
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
858 else {
5211
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
859 gaim_debug(GAIM_DEBUG_ERROR, "proxy",
9100
4b3e5a5063f9 [gaim-migrate @ 9877]
Ethan Blanton <elb@pidgin.im>
parents: 8977
diff changeset
860 "Connect failed: %s\n", strerror(errno));
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
861 close(fd);
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
862 return -1;
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
863 }
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
864 }
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
865 else {
2048
3366311426df [gaim-migrate @ 2058]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1881
diff changeset
866 unsigned int len;
3366311426df [gaim-migrate @ 2058]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1881
diff changeset
867 int error = ETIMEDOUT;
5211
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
868 gaim_debug(GAIM_DEBUG_MISC, "proxy", "Connect didn't block.\n");
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
869 len = sizeof(error);
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
870 if (getsockopt(fd, SOL_SOCKET, SO_ERROR, &error, &len) < 0) {
5211
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
871 gaim_debug(GAIM_DEBUG_ERROR, "proxy", "getsockopt failed.\n");
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
872 close(fd);
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
873 return -1;
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
874 }
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
875 fcntl(fd, F_SETFL, 0);
2372
2927c2c26fe6 [gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2306
diff changeset
876 phb->port = fd; /* bleh */
8273
f24172f53650 [gaim-migrate @ 8997]
Christian Hammond <chipx86@chipx86.com>
parents: 8269
diff changeset
877 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
878 want to call our callback
2927c2c26fe6 [gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2306
diff changeset
879 before we return. */
1087
56c7ceb986a8 [gaim-migrate @ 1097]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1057
diff changeset
880 }
56c7ceb986a8 [gaim-migrate @ 1097]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1057
diff changeset
881
56c7ceb986a8 [gaim-migrate @ 1097]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1057
diff changeset
882 return fd;
56c7ceb986a8 [gaim-migrate @ 1097]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1057
diff changeset
883 }
56c7ceb986a8 [gaim-migrate @ 1097]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1057
diff changeset
884
3376
8d0fa912ecaf [gaim-migrate @ 3395]
Sean Egan <seanegan@gmail.com>
parents: 3283
diff changeset
885 #define HTTP_GOODSTRING "HTTP/1.0 200"
8d0fa912ecaf [gaim-migrate @ 3395]
Sean Egan <seanegan@gmail.com>
parents: 3283
diff changeset
886 #define HTTP_GOODSTRING2 "HTTP/1.1 200"
1087
56c7ceb986a8 [gaim-migrate @ 1097]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1057
diff changeset
887
7834
99ffabc6ce73 [gaim-migrate @ 8487]
Christian Hammond <chipx86@chipx86.com>
parents: 7652
diff changeset
888 static void
99ffabc6ce73 [gaim-migrate @ 8487]
Christian Hammond <chipx86@chipx86.com>
parents: 7652
diff changeset
889 http_complete(struct PHB *phb, gint source)
99ffabc6ce73 [gaim-migrate @ 8487]
Christian Hammond <chipx86@chipx86.com>
parents: 7652
diff changeset
890 {
99ffabc6ce73 [gaim-migrate @ 8487]
Christian Hammond <chipx86@chipx86.com>
parents: 7652
diff changeset
891 gaim_debug(GAIM_DEBUG_INFO, "http proxy", "proxy connection established\n");
9129
3e94a77ee0c7 [gaim-migrate @ 9907]
Nathan Walp <nwalp@pidgin.im>
parents: 9100
diff changeset
892 if(source < 0) {
3e94a77ee0c7 [gaim-migrate @ 9907]
Nathan Walp <nwalp@pidgin.im>
parents: 9100
diff changeset
893 try_connect(phb);
3e94a77ee0c7 [gaim-migrate @ 9907]
Nathan Walp <nwalp@pidgin.im>
parents: 9100
diff changeset
894 } else if(!phb->account || phb->account->gc) {
7834
99ffabc6ce73 [gaim-migrate @ 8487]
Christian Hammond <chipx86@chipx86.com>
parents: 7652
diff changeset
895 phb->func(phb->data, source, GAIM_INPUT_READ);
9129
3e94a77ee0c7 [gaim-migrate @ 9907]
Nathan Walp <nwalp@pidgin.im>
parents: 9100
diff changeset
896 g_free(phb->host);
3e94a77ee0c7 [gaim-migrate @ 9907]
Nathan Walp <nwalp@pidgin.im>
parents: 9100
diff changeset
897 g_free(phb);
3e94a77ee0c7 [gaim-migrate @ 9907]
Nathan Walp <nwalp@pidgin.im>
parents: 9100
diff changeset
898 }
7834
99ffabc6ce73 [gaim-migrate @ 8487]
Christian Hammond <chipx86@chipx86.com>
parents: 7652
diff changeset
899 }
99ffabc6ce73 [gaim-migrate @ 8487]
Christian Hammond <chipx86@chipx86.com>
parents: 7652
diff changeset
900
99ffabc6ce73 [gaim-migrate @ 8487]
Christian Hammond <chipx86@chipx86.com>
parents: 7652
diff changeset
901
99ffabc6ce73 [gaim-migrate @ 8487]
Christian Hammond <chipx86@chipx86.com>
parents: 7652
diff changeset
902 /* 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
903 static void
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
904 http_canread(gpointer data, gint source, GaimInputCondition cond)
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
905 {
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
906 int nlc = 0;
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
907 int pos = 0;
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
908 int minor, major, status, error=0;
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
909 struct PHB *phb = data;
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
910 char inputline[8192], *p;
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
911
2090
b66aca8e8dce [gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2048
diff changeset
912 gaim_input_remove(phb->inpa);
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
913
8118
52089b055c12 [gaim-migrate @ 8822]
Luke Schierer <lschiere@pidgin.im>
parents: 8046
diff changeset
914 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
915 if (inputline[pos - 1] == '\n')
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
916 nlc++;
2372
2927c2c26fe6 [gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2306
diff changeset
917 else if (inputline[pos - 1] != '\r')
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
918 nlc = 0;
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
919 }
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
920 inputline[pos] = '\0';
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
921
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
922 error = strncmp(inputline, "HTTP/", 5) != 0;
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
923 if(!error) {
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
924 p = inputline + 5;
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
925 major = strtol(p, &p, 10);
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
926 error = (major==0) || (*p != '.');
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
927 if(!error) {
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
928 p++;
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
929 minor = strtol(p, &p, 10);
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
930 error = (*p!=' ');
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
931 if(!error) {
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
932 p++;
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
933 status = strtol(p, &p, 10);
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
934 error = (*p!=' ');
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
935 }
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
936 }
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
937 }
9129
3e94a77ee0c7 [gaim-migrate @ 9907]
Nathan Walp <nwalp@pidgin.im>
parents: 9100
diff changeset
938
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
939 if(error) {
5211
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
940 gaim_debug(GAIM_DEBUG_ERROR, "proxy",
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
941 "Unable to parse proxy's response: %s\n", inputline);
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
942 close(source);
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
943 source=-1;
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
944 }
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
945 else if(status!=200) {
5211
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
946 gaim_debug(GAIM_DEBUG_ERROR, "proxy",
7834
99ffabc6ce73 [gaim-migrate @ 8487]
Christian Hammond <chipx86@chipx86.com>
parents: 7652
diff changeset
947 "Proxy server replied with:\n%s\n", p);
9129
3e94a77ee0c7 [gaim-migrate @ 9907]
Nathan Walp <nwalp@pidgin.im>
parents: 9100
diff changeset
948 close(source);
7834
99ffabc6ce73 [gaim-migrate @ 8487]
Christian Hammond <chipx86@chipx86.com>
parents: 7652
diff changeset
949 source = -1;
9129
3e94a77ee0c7 [gaim-migrate @ 9907]
Nathan Walp <nwalp@pidgin.im>
parents: 9100
diff changeset
950
3e94a77ee0c7 [gaim-migrate @ 9907]
Nathan Walp <nwalp@pidgin.im>
parents: 9100
diff changeset
951 /* 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
952 if ( status == 403 /* Forbidden */ ) {
189ee7356c59 [gaim-migrate @ 9687]
Mark Doliner <mark@kingant.net>
parents: 8889
diff changeset
953 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
954 gaim_connection_error(phb->account->gc, msg);
189ee7356c59 [gaim-migrate @ 9687]
Mark Doliner <mark@kingant.net>
parents: 8889
diff changeset
955 g_free(msg);
189ee7356c59 [gaim-migrate @ 9687]
Mark Doliner <mark@kingant.net>
parents: 8889
diff changeset
956 } else {
7834
99ffabc6ce73 [gaim-migrate @ 8487]
Christian Hammond <chipx86@chipx86.com>
parents: 7652
diff changeset
957 char *msg = g_strdup_printf(_("Proxy connection error %d"), status);
99ffabc6ce73 [gaim-migrate @ 8487]
Christian Hammond <chipx86@chipx86.com>
parents: 7652
diff changeset
958 gaim_connection_error(phb->account->gc, msg);
99ffabc6ce73 [gaim-migrate @ 8487]
Christian Hammond <chipx86@chipx86.com>
parents: 7652
diff changeset
959 g_free(msg);
99ffabc6ce73 [gaim-migrate @ 8487]
Christian Hammond <chipx86@chipx86.com>
parents: 7652
diff changeset
960 }
9129
3e94a77ee0c7 [gaim-migrate @ 9907]
Nathan Walp <nwalp@pidgin.im>
parents: 9100
diff changeset
961
7834
99ffabc6ce73 [gaim-migrate @ 8487]
Christian Hammond <chipx86@chipx86.com>
parents: 7652
diff changeset
962 } else {
99ffabc6ce73 [gaim-migrate @ 8487]
Christian Hammond <chipx86@chipx86.com>
parents: 7652
diff changeset
963 http_complete(phb, source);
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
964 }
9129
3e94a77ee0c7 [gaim-migrate @ 9907]
Nathan Walp <nwalp@pidgin.im>
parents: 9100
diff changeset
965
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
966 return;
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
967 }
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
968
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
969 static void
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
970 http_canwrite(gpointer data, gint source, GaimInputCondition cond)
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
971 {
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
972 char request[8192];
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
973 int request_len = 0;
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
974 struct PHB *phb = data;
2048
3366311426df [gaim-migrate @ 2058]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1881
diff changeset
975 unsigned int len;
3366311426df [gaim-migrate @ 2058]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1881
diff changeset
976 int error = ETIMEDOUT;
3717
988485669631 [gaim-migrate @ 3850]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 3630
diff changeset
977
5211
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
978 gaim_debug(GAIM_DEBUG_INFO, "http proxy", "Connected.\n");
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
979
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
980 if (phb->inpa > 0)
2090
b66aca8e8dce [gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2048
diff changeset
981 gaim_input_remove(phb->inpa);
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
982
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
983 len = sizeof(error);
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
984
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
985 if (getsockopt(source, SOL_SOCKET, SO_ERROR, &error, &len) < 0) {
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
986 close(source);
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
987
9129
3e94a77ee0c7 [gaim-migrate @ 9907]
Nathan Walp <nwalp@pidgin.im>
parents: 9100
diff changeset
988 try_connect(phb);
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
989 return;
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
990 }
7834
99ffabc6ce73 [gaim-migrate @ 8487]
Christian Hammond <chipx86@chipx86.com>
parents: 7652
diff changeset
991
99ffabc6ce73 [gaim-migrate @ 8487]
Christian Hammond <chipx86@chipx86.com>
parents: 7652
diff changeset
992 gaim_debug(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
993 request_len = g_snprintf(request, sizeof(request),
7834
99ffabc6ce73 [gaim-migrate @ 8487]
Christian Hammond <chipx86@chipx86.com>
parents: 7652
diff changeset
994 "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
995 phb->host, phb->port, phb->host, phb->port);
1843
4dbd8533d209 [gaim-migrate @ 1853]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1840
diff changeset
996
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
997 if (gaim_proxy_info_get_username(phb->gpi) != NULL) {
1843
4dbd8533d209 [gaim-migrate @ 1853]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1840
diff changeset
998 char *t1, *t2;
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
999 t1 = g_strdup_printf("%s:%s",
7834
99ffabc6ce73 [gaim-migrate @ 8487]
Christian Hammond <chipx86@chipx86.com>
parents: 7652
diff changeset
1000 gaim_proxy_info_get_username(phb->gpi),
99ffabc6ce73 [gaim-migrate @ 8487]
Christian Hammond <chipx86@chipx86.com>
parents: 7652
diff changeset
1001 gaim_proxy_info_get_password(phb->gpi) ?
99ffabc6ce73 [gaim-migrate @ 8487]
Christian Hammond <chipx86@chipx86.com>
parents: 7652
diff changeset
1002 gaim_proxy_info_get_password(phb->gpi) : "");
7106
db6bd3e794d8 [gaim-migrate @ 7671]
Christian Hammond <chipx86@chipx86.com>
parents: 6856
diff changeset
1003 t2 = gaim_base64_encode(t1, strlen(t1));
1843
4dbd8533d209 [gaim-migrate @ 1853]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1840
diff changeset
1004 g_free(t1);
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
1005 g_return_if_fail(request_len < sizeof(request));
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1006 request_len += g_snprintf(request + request_len,
7834
99ffabc6ce73 [gaim-migrate @ 8487]
Christian Hammond <chipx86@chipx86.com>
parents: 7652
diff changeset
1007 sizeof(request) - request_len,
99ffabc6ce73 [gaim-migrate @ 8487]
Christian Hammond <chipx86@chipx86.com>
parents: 7652
diff changeset
1008 "Proxy-Authorization: Basic %s\r\n", t2);
1843
4dbd8533d209 [gaim-migrate @ 1853]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1840
diff changeset
1009 g_free(t2);
4dbd8533d209 [gaim-migrate @ 1853]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1840
diff changeset
1010 }
4dbd8533d209 [gaim-migrate @ 1853]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1840
diff changeset
1011
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
1012 g_return_if_fail(request_len < sizeof(request));
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
1013 strcpy(request + request_len, "\r\n");
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
1014 request_len += 2;
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
1015
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
1016 if (write(source, request, request_len) < 0) {
1843
4dbd8533d209 [gaim-migrate @ 1853]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1840
diff changeset
1017 close(source);
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1018
9129
3e94a77ee0c7 [gaim-migrate @ 9907]
Nathan Walp <nwalp@pidgin.im>
parents: 9100
diff changeset
1019 try_connect(phb);
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1020 return;
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1021 }
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1022
7834
99ffabc6ce73 [gaim-migrate @ 8487]
Christian Hammond <chipx86@chipx86.com>
parents: 7652
diff changeset
1023 /* register the response handler for the CONNECT request */
2090
b66aca8e8dce [gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2048
diff changeset
1024 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
1025 }
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1026
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1027 static int
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1028 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
1029 {
56c7ceb986a8 [gaim-migrate @ 1097]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1057
diff changeset
1030 int fd = -1;
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
1031
5211
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
1032 gaim_debug(GAIM_DEBUG_INFO, "http proxy",
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
1033 "Connecting to %s:%d via %s:%d using HTTP\n",
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1034 phb->host, phb->port,
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1035 gaim_proxy_info_get_host(phb->gpi),
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1036 gaim_proxy_info_get_port(phb->gpi));
1087
56c7ceb986a8 [gaim-migrate @ 1097]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1057
diff changeset
1037
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
1038 if ((fd = socket(addr->sa_family, SOCK_STREAM, 0)) < 0) {
1087
56c7ceb986a8 [gaim-migrate @ 1097]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1057
diff changeset
1039 return -1;
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1040 }
1087
56c7ceb986a8 [gaim-migrate @ 1097]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1057
diff changeset
1041
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1042 fcntl(fd, F_SETFL, O_NONBLOCK);
10172
374d63326461 [gaim-migrate @ 11275]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10170
diff changeset
1043 #ifndef _WIN32
10170
3c88c2f1b732 [gaim-migrate @ 11262]
Ethan Blanton <elb@pidgin.im>
parents: 10087
diff changeset
1044 fcntl(fd, F_SETFD, FD_CLOEXEC);
10172
374d63326461 [gaim-migrate @ 11275]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10170
diff changeset
1045 #endif
3717
988485669631 [gaim-migrate @ 3850]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 3630
diff changeset
1046
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
1047 if (connect(fd, addr, addrlen) < 0) {
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1048 if ((errno == EINPROGRESS) || (errno == EINTR)) {
5211
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
1049 gaim_debug(GAIM_DEBUG_WARNING, "http proxy",
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
1050 "Connect would have blocked.\n");
9655
00f96f4cc775 [gaim-migrate @ 10503]
Luke Schierer <lschiere@pidgin.im>
parents: 9653
diff changeset
1051
7834
99ffabc6ce73 [gaim-migrate @ 8487]
Christian Hammond <chipx86@chipx86.com>
parents: 7652
diff changeset
1052 if (phb->port != 80) {
99ffabc6ce73 [gaim-migrate @ 8487]
Christian Hammond <chipx86@chipx86.com>
parents: 7652
diff changeset
1053 /* we need to do CONNECT first */
99ffabc6ce73 [gaim-migrate @ 8487]
Christian Hammond <chipx86@chipx86.com>
parents: 7652
diff changeset
1054 phb->inpa = gaim_input_add(fd, GAIM_INPUT_WRITE,
99ffabc6ce73 [gaim-migrate @ 8487]
Christian Hammond <chipx86@chipx86.com>
parents: 7652
diff changeset
1055 http_canwrite, phb);
99ffabc6ce73 [gaim-migrate @ 8487]
Christian Hammond <chipx86@chipx86.com>
parents: 7652
diff changeset
1056 } else {
99ffabc6ce73 [gaim-migrate @ 8487]
Christian Hammond <chipx86@chipx86.com>
parents: 7652
diff changeset
1057 http_complete(phb, fd);
99ffabc6ce73 [gaim-migrate @ 8487]
Christian Hammond <chipx86@chipx86.com>
parents: 7652
diff changeset
1058 }
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1059 } else {
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1060 close(fd);
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1061 return -1;
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1062 }
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1063 }
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1064 else {
2048
3366311426df [gaim-migrate @ 2058]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1881
diff changeset
1065 unsigned int len;
3366311426df [gaim-migrate @ 2058]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1881
diff changeset
1066 int error = ETIMEDOUT;
3717
988485669631 [gaim-migrate @ 3850]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 3630
diff changeset
1067
5211
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
1068 gaim_debug(GAIM_DEBUG_MISC, "http proxy",
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
1069 "Connect didn't block.\n");
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
1070
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1071 len = sizeof(error);
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1072 if (getsockopt(fd, SOL_SOCKET, SO_ERROR, &error, &len) < 0) {
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1073 close(fd);
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1074 return -1;
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1075 }
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1076 fcntl(fd, F_SETFL, 0);
2090
b66aca8e8dce [gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2048
diff changeset
1077 http_canwrite(phb, fd, GAIM_INPUT_WRITE);
1695
c0ab844d4790 [gaim-migrate @ 1705]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1451
diff changeset
1078 }
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1079
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1080 return fd;
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1081 }
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1082
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1083 static void
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1084 s4_canread(gpointer data, gint source, GaimInputCondition cond)
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1085 {
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1086 unsigned char packet[12];
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1087 struct PHB *phb = data;
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1088
2090
b66aca8e8dce [gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2048
diff changeset
1089 gaim_input_remove(phb->inpa);
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1090
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1091 memset(packet, 0, sizeof(packet));
3717
988485669631 [gaim-migrate @ 3850]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 3630
diff changeset
1092
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1093 if (read(source, packet, 9) >= 4 && packet[1] == 90) {
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1094 if (phb->account == NULL ||
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1095 gaim_account_get_connection(phb->account) != NULL) {
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1096
6017
968a00c9f230 [gaim-migrate @ 6467]
Mark Doliner <mark@kingant.net>
parents: 6001
diff changeset
1097 phb->func(phb->data, source, GAIM_INPUT_READ);
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1098 }
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1099
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1100 g_free(phb->host);
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1101 g_free(phb);
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1102 return;
1695
c0ab844d4790 [gaim-migrate @ 1705]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1451
diff changeset
1103 }
1087
56c7ceb986a8 [gaim-migrate @ 1097]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1057
diff changeset
1104
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1105 close(source);
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1106
9129
3e94a77ee0c7 [gaim-migrate @ 9907]
Nathan Walp <nwalp@pidgin.im>
parents: 9100
diff changeset
1107 try_connect(phb);
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1108 }
1705
b4d454e5ee31 [gaim-migrate @ 1715]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1695
diff changeset
1109
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1110 static void
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1111 s4_canwrite(gpointer data, gint source, GaimInputCondition cond)
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1112 {
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1113 unsigned char packet[12];
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1114 struct hostent *hp;
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1115 struct PHB *phb = data;
2048
3366311426df [gaim-migrate @ 2058]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1881
diff changeset
1116 unsigned int len;
3366311426df [gaim-migrate @ 2058]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1881
diff changeset
1117 int error = ETIMEDOUT;
3717
988485669631 [gaim-migrate @ 3850]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 3630
diff changeset
1118
5211
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
1119 gaim_debug(GAIM_DEBUG_INFO, "s4 proxy", "Connected.\n");
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
1120
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1121 if (phb->inpa > 0)
2090
b66aca8e8dce [gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2048
diff changeset
1122 gaim_input_remove(phb->inpa);
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1123
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1124 len = sizeof(error);
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1125
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1126 if (getsockopt(source, SOL_SOCKET, SO_ERROR, &error, &len) < 0) {
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1127 close(source);
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1128
9129
3e94a77ee0c7 [gaim-migrate @ 9907]
Nathan Walp <nwalp@pidgin.im>
parents: 9100
diff changeset
1129 try_connect(phb);
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1130 return;
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1131 }
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1132 fcntl(source, F_SETFL, 0);
3717
988485669631 [gaim-migrate @ 3850]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 3630
diff changeset
1133
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1134 /* XXX does socks4 not support host name lookups by the proxy? */
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1135 if (!(hp = gethostbyname(phb->host))) {
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1136 close(source);
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1137
9129
3e94a77ee0c7 [gaim-migrate @ 9907]
Nathan Walp <nwalp@pidgin.im>
parents: 9100
diff changeset
1138 try_connect(phb);
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1139 return;
1087
56c7ceb986a8 [gaim-migrate @ 1097]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1057
diff changeset
1140 }
56c7ceb986a8 [gaim-migrate @ 1097]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1057
diff changeset
1141
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1142 packet[0] = 4;
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1143 packet[1] = 1;
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1144 packet[2] = phb->port >> 8;
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1145 packet[3] = phb->port & 0xff;
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1146 packet[4] = (unsigned char)(hp->h_addr_list[0])[0];
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1147 packet[5] = (unsigned char)(hp->h_addr_list[0])[1];
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1148 packet[6] = (unsigned char)(hp->h_addr_list[0])[2];
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1149 packet[7] = (unsigned char)(hp->h_addr_list[0])[3];
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1150 packet[8] = 0;
3717
988485669631 [gaim-migrate @ 3850]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 3630
diff changeset
1151
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1152 if (write(source, packet, 9) != 9) {
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1153 close(source);
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1154
9129
3e94a77ee0c7 [gaim-migrate @ 9907]
Nathan Walp <nwalp@pidgin.im>
parents: 9100
diff changeset
1155 try_connect(phb);
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1156 return;
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1157 }
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1158
2090
b66aca8e8dce [gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2048
diff changeset
1159 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
1160 }
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
1161
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1162 static int
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1163 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
1164 {
1087
56c7ceb986a8 [gaim-migrate @ 1097]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1057
diff changeset
1165 int fd = -1;
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
1166
5211
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
1167 gaim_debug(GAIM_DEBUG_INFO, "socks4 proxy",
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
1168 "Connecting to %s:%d via %s:%d using SOCKS4\n",
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1169 phb->host, phb->port,
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1170 gaim_proxy_info_get_host(phb->gpi),
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1171 gaim_proxy_info_get_port(phb->gpi));
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
1172
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1173 if ((fd = socket(addr->sa_family, SOCK_STREAM, 0)) < 0)
1087
56c7ceb986a8 [gaim-migrate @ 1097]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1057
diff changeset
1174 return -1;
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
1175
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1176 fcntl(fd, F_SETFL, O_NONBLOCK);
10172
374d63326461 [gaim-migrate @ 11275]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10170
diff changeset
1177 #ifndef _WIN32
10170
3c88c2f1b732 [gaim-migrate @ 11262]
Ethan Blanton <elb@pidgin.im>
parents: 10087
diff changeset
1178 fcntl(fd, F_SETFD, FD_CLOEXEC);
10172
374d63326461 [gaim-migrate @ 11275]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10170
diff changeset
1179 #endif
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1180
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
1181 if (connect(fd, addr, addrlen) < 0) {
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1182 if ((errno == EINPROGRESS) || (errno == EINTR)) {
5211
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
1183 gaim_debug(GAIM_DEBUG_WARNING, "socks4 proxy",
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
1184 "Connect would have blocked.\n");
2090
b66aca8e8dce [gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2048
diff changeset
1185 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
1186 }
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1187 else {
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1188 close(fd);
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1189 return -1;
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1190 }
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1191 } else {
2048
3366311426df [gaim-migrate @ 2058]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1881
diff changeset
1192 unsigned int len;
3366311426df [gaim-migrate @ 2058]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1881
diff changeset
1193 int error = ETIMEDOUT;
3717
988485669631 [gaim-migrate @ 3850]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 3630
diff changeset
1194
5211
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
1195 gaim_debug(GAIM_DEBUG_MISC, "socks4 proxy",
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
1196 "Connect didn't block.\n");
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
1197
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1198 len = sizeof(error);
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1199
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1200 if (getsockopt(fd, SOL_SOCKET, SO_ERROR, &error, &len) < 0) {
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1201 close(fd);
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1202 return -1;
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1203 }
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1204
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1205 fcntl(fd, F_SETFL, 0);
2090
b66aca8e8dce [gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2048
diff changeset
1206 s4_canwrite(phb, fd, GAIM_INPUT_WRITE);
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1207 }
670
9e51c1a4abba [gaim-migrate @ 680]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 664
diff changeset
1208
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1209 return fd;
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1210 }
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1211
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1212 static void
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1213 s5_canread_again(gpointer data, gint source, GaimInputCondition cond)
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1214 {
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1215 unsigned char buf[512];
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1216 struct PHB *phb = data;
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1217
2090
b66aca8e8dce [gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2048
diff changeset
1218 gaim_input_remove(phb->inpa);
5211
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
1219 gaim_debug(GAIM_DEBUG_INFO, "socks5 proxy", "Able to read again.\n");
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1220
8262
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
1221 if (read(source, buf, 4) < 4) {
5211
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
1222 gaim_debug(GAIM_DEBUG_WARNING, "socks5 proxy", "or not...\n");
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1223 close(source);
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1224
9129
3e94a77ee0c7 [gaim-migrate @ 9907]
Nathan Walp <nwalp@pidgin.im>
parents: 9100
diff changeset
1225 try_connect(phb);
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1226 return;
1087
56c7ceb986a8 [gaim-migrate @ 1097]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1057
diff changeset
1227 }
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1228 if ((buf[0] != 0x05) || (buf[1] != 0x00)) {
7982
58af482c89f7 [gaim-migrate @ 8659]
Luke Schierer <lschiere@pidgin.im>
parents: 7834
diff changeset
1229 if ((buf[0] == 0x05) && (buf[1] < 0x09))
58af482c89f7 [gaim-migrate @ 8659]
Luke Schierer <lschiere@pidgin.im>
parents: 7834
diff changeset
1230 gaim_debug(GAIM_DEBUG_ERROR, "socks5 proxy", socks5errors[buf[1]]);
58af482c89f7 [gaim-migrate @ 8659]
Luke Schierer <lschiere@pidgin.im>
parents: 7834
diff changeset
1231 else
58af482c89f7 [gaim-migrate @ 8659]
Luke Schierer <lschiere@pidgin.im>
parents: 7834
diff changeset
1232 gaim_debug(GAIM_DEBUG_ERROR, "socks5 proxy", "Bad data.\n");
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1233 close(source);
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1234
9129
3e94a77ee0c7 [gaim-migrate @ 9907]
Nathan Walp <nwalp@pidgin.im>
parents: 9100
diff changeset
1235 try_connect(phb);
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1236 return;
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1237 }
670
9e51c1a4abba [gaim-migrate @ 680]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 664
diff changeset
1238
8262
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
1239 /* Skip past BND.ADDR */
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
1240 switch(buf[3]) {
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
1241 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
1242 read(source, buf, 4);
8262
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
1243 break;
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
1244 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
1245 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
1246 follow, there is no terminating NUL octet. */
8269
79b834d7c2a2 [gaim-migrate @ 8992]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
1247 read(source, buf, 1);
79b834d7c2a2 [gaim-migrate @ 8992]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
1248 read(source, buf, buf[0]);
8262
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
1249 break;
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
1250 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
1251 read(source, buf, 16);
8262
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
1252 break;
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
1253 }
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
1254
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
1255 /* Skip past BND.PORT */
8269
79b834d7c2a2 [gaim-migrate @ 8992]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
1256 read(source, buf, 2);
8262
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
1257
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1258 if (phb->account == NULL ||
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1259 gaim_account_get_connection(phb->account) != NULL) {
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1260
4993
de84c1de2f66 [gaim-migrate @ 5328]
Nathan Walp <nwalp@pidgin.im>
parents: 4679
diff changeset
1261 phb->func(phb->data, source, GAIM_INPUT_READ);
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1262 }
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1263
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1264 g_free(phb->host);
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1265 g_free(phb);
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
1266 }
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
1267
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1268 static void
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1269 s5_sendconnect(gpointer data, gint source)
1087
56c7ceb986a8 [gaim-migrate @ 1097]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1057
diff changeset
1270 {
56c7ceb986a8 [gaim-migrate @ 1097]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1057
diff changeset
1271 unsigned char buf[512];
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1272 struct PHB *phb = data;
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1273 int hlen = strlen(phb->host);
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1274
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1275 buf[0] = 0x05;
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1276 buf[1] = 0x01; /* CONNECT */
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1277 buf[2] = 0x00; /* reserved */
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1278 buf[3] = 0x03; /* address type -- host name */
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1279 buf[4] = hlen;
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1280 memcpy(buf + 5, phb->host, hlen);
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1281 buf[5 + strlen(phb->host)] = phb->port >> 8;
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1282 buf[5 + strlen(phb->host) + 1] = phb->port & 0xff;
1087
56c7ceb986a8 [gaim-migrate @ 1097]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1057
diff changeset
1283
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1284 if (write(source, buf, (5 + strlen(phb->host) + 2)) < (5 + strlen(phb->host) + 2)) {
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1285 close(source);
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1286
9129
3e94a77ee0c7 [gaim-migrate @ 9907]
Nathan Walp <nwalp@pidgin.im>
parents: 9100
diff changeset
1287 try_connect(phb);
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1288 return;
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1289 }
1087
56c7ceb986a8 [gaim-migrate @ 1097]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1057
diff changeset
1290
2090
b66aca8e8dce [gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2048
diff changeset
1291 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
1292 }
1087
56c7ceb986a8 [gaim-migrate @ 1097]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1057
diff changeset
1293
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1294 static void
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1295 s5_readauth(gpointer data, gint source, GaimInputCondition cond)
1844
9845deede1e9 [gaim-migrate @ 1854]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1843
diff changeset
1296 {
9845deede1e9 [gaim-migrate @ 1854]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1843
diff changeset
1297 unsigned char buf[512];
9845deede1e9 [gaim-migrate @ 1854]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1843
diff changeset
1298 struct PHB *phb = data;
9845deede1e9 [gaim-migrate @ 1854]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1843
diff changeset
1299
2090
b66aca8e8dce [gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2048
diff changeset
1300 gaim_input_remove(phb->inpa);
5211
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
1301 gaim_debug(GAIM_DEBUG_INFO, "socks5 proxy", "Got auth response.\n");
1844
9845deede1e9 [gaim-migrate @ 1854]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1843
diff changeset
1302
9845deede1e9 [gaim-migrate @ 1854]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1843
diff changeset
1303 if (read(source, buf, 2) < 2) {
9845deede1e9 [gaim-migrate @ 1854]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1843
diff changeset
1304 close(source);
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1305
9129
3e94a77ee0c7 [gaim-migrate @ 9907]
Nathan Walp <nwalp@pidgin.im>
parents: 9100
diff changeset
1306 try_connect(phb);
1844
9845deede1e9 [gaim-migrate @ 1854]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1843
diff changeset
1307 return;
9845deede1e9 [gaim-migrate @ 1854]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1843
diff changeset
1308 }
9845deede1e9 [gaim-migrate @ 1854]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1843
diff changeset
1309
2790
0148422dff4d [gaim-migrate @ 2803]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2754
diff changeset
1310 if ((buf[0] != 0x01) || (buf[1] != 0x00)) {
1844
9845deede1e9 [gaim-migrate @ 1854]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1843
diff changeset
1311 close(source);
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1312
9129
3e94a77ee0c7 [gaim-migrate @ 9907]
Nathan Walp <nwalp@pidgin.im>
parents: 9100
diff changeset
1313 try_connect(phb);
1844
9845deede1e9 [gaim-migrate @ 1854]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1843
diff changeset
1314 return;
9845deede1e9 [gaim-migrate @ 1854]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1843
diff changeset
1315 }
9845deede1e9 [gaim-migrate @ 1854]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1843
diff changeset
1316
9845deede1e9 [gaim-migrate @ 1854]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1843
diff changeset
1317 s5_sendconnect(phb, source);
9845deede1e9 [gaim-migrate @ 1854]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1843
diff changeset
1318 }
9845deede1e9 [gaim-migrate @ 1854]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1843
diff changeset
1319
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1320 static void
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1321 s5_canread(gpointer data, gint source, GaimInputCondition cond)
1844
9845deede1e9 [gaim-migrate @ 1854]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1843
diff changeset
1322 {
9845deede1e9 [gaim-migrate @ 1854]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1843
diff changeset
1323 unsigned char buf[512];
9845deede1e9 [gaim-migrate @ 1854]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1843
diff changeset
1324 struct PHB *phb = data;
9845deede1e9 [gaim-migrate @ 1854]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1843
diff changeset
1325
2090
b66aca8e8dce [gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2048
diff changeset
1326 gaim_input_remove(phb->inpa);
5211
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
1327 gaim_debug(GAIM_DEBUG_INFO, "socks5 proxy", "Able to read.\n");
1844
9845deede1e9 [gaim-migrate @ 1854]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1843
diff changeset
1328
9845deede1e9 [gaim-migrate @ 1854]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1843
diff changeset
1329 if (read(source, buf, 2) < 2) {
9845deede1e9 [gaim-migrate @ 1854]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1843
diff changeset
1330 close(source);
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1331
9129
3e94a77ee0c7 [gaim-migrate @ 9907]
Nathan Walp <nwalp@pidgin.im>
parents: 9100
diff changeset
1332 try_connect(phb);
1844
9845deede1e9 [gaim-migrate @ 1854]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1843
diff changeset
1333 return;
9845deede1e9 [gaim-migrate @ 1854]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1843
diff changeset
1334 }
9845deede1e9 [gaim-migrate @ 1854]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1843
diff changeset
1335
9845deede1e9 [gaim-migrate @ 1854]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1843
diff changeset
1336 if ((buf[0] != 0x05) || (buf[1] == 0xff)) {
9845deede1e9 [gaim-migrate @ 1854]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1843
diff changeset
1337 close(source);
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1338
9129
3e94a77ee0c7 [gaim-migrate @ 9907]
Nathan Walp <nwalp@pidgin.im>
parents: 9100
diff changeset
1339 try_connect(phb);
1844
9845deede1e9 [gaim-migrate @ 1854]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1843
diff changeset
1340 return;
9845deede1e9 [gaim-migrate @ 1854]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1843
diff changeset
1341 }
9845deede1e9 [gaim-migrate @ 1854]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1843
diff changeset
1342
9845deede1e9 [gaim-migrate @ 1854]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1843
diff changeset
1343 if (buf[1] == 0x02) {
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1344 unsigned int i, j;
9129
3e94a77ee0c7 [gaim-migrate @ 9907]
Nathan Walp <nwalp@pidgin.im>
parents: 9100
diff changeset
1345
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1346 i = strlen(gaim_proxy_info_get_username(phb->gpi));
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1347 j = strlen(gaim_proxy_info_get_password(phb->gpi));
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1348
2372
2927c2c26fe6 [gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2306
diff changeset
1349 buf[0] = 0x01; /* version 1 */
1844
9845deede1e9 [gaim-migrate @ 1854]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1843
diff changeset
1350 buf[1] = i;
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1351 memcpy(buf + 2, gaim_proxy_info_get_username(phb->gpi), i);
2372
2927c2c26fe6 [gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2306
diff changeset
1352 buf[2 + i] = j;
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1353 memcpy(buf + 2 + i + 1, gaim_proxy_info_get_password(phb->gpi), j);
3717
988485669631 [gaim-migrate @ 3850]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 3630
diff changeset
1354
2372
2927c2c26fe6 [gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2306
diff changeset
1355 if (write(source, buf, 3 + i + j) < 3 + i + j) {
1844
9845deede1e9 [gaim-migrate @ 1854]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1843
diff changeset
1356 close(source);
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1357
9129
3e94a77ee0c7 [gaim-migrate @ 9907]
Nathan Walp <nwalp@pidgin.im>
parents: 9100
diff changeset
1358 try_connect(phb);
1844
9845deede1e9 [gaim-migrate @ 1854]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1843
diff changeset
1359 return;
9845deede1e9 [gaim-migrate @ 1854]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1843
diff changeset
1360 }
9845deede1e9 [gaim-migrate @ 1854]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1843
diff changeset
1361
2090
b66aca8e8dce [gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2048
diff changeset
1362 phb->inpa = gaim_input_add(source, GAIM_INPUT_READ, s5_readauth, phb);
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1363 }
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1364 else {
1844
9845deede1e9 [gaim-migrate @ 1854]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1843
diff changeset
1365 s5_sendconnect(phb, source);
9845deede1e9 [gaim-migrate @ 1854]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1843
diff changeset
1366 }
9845deede1e9 [gaim-migrate @ 1854]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1843
diff changeset
1367 }
9845deede1e9 [gaim-migrate @ 1854]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1843
diff changeset
1368
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1369 static void
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1370 s5_canwrite(gpointer data, gint source, GaimInputCondition cond)
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1371 {
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1372 unsigned char buf[512];
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1373 int i;
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1374 struct PHB *phb = data;
2048
3366311426df [gaim-migrate @ 2058]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1881
diff changeset
1375 unsigned int len;
3366311426df [gaim-migrate @ 2058]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1881
diff changeset
1376 int error = ETIMEDOUT;
3717
988485669631 [gaim-migrate @ 3850]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 3630
diff changeset
1377
5872
059d95c67cda [gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents: 5681
diff changeset
1378 gaim_debug(GAIM_DEBUG_INFO, "socks5 proxy", "Connected.\n");
5211
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
1379
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1380 if (phb->inpa > 0)
2090
b66aca8e8dce [gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2048
diff changeset
1381 gaim_input_remove(phb->inpa);
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1382
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1383 len = sizeof(error);
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1384 if (getsockopt(source, SOL_SOCKET, SO_ERROR, &error, &len) < 0) {
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1385 close(source);
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1386
9129
3e94a77ee0c7 [gaim-migrate @ 9907]
Nathan Walp <nwalp@pidgin.im>
parents: 9100
diff changeset
1387 try_connect(phb);
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1388 return;
1087
56c7ceb986a8 [gaim-migrate @ 1097]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1057
diff changeset
1389 }
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1390 fcntl(source, F_SETFL, 0);
1087
56c7ceb986a8 [gaim-migrate @ 1097]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1057
diff changeset
1391
56c7ceb986a8 [gaim-migrate @ 1097]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1057
diff changeset
1392 i = 0;
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1087
diff changeset
1393 buf[0] = 0x05; /* SOCKS version 5 */
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1394
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1395 if (gaim_proxy_info_get_username(phb->gpi) != NULL) {
1844
9845deede1e9 [gaim-migrate @ 1854]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1843
diff changeset
1396 buf[1] = 0x02; /* two methods */
9845deede1e9 [gaim-migrate @ 1854]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1843
diff changeset
1397 buf[2] = 0x00; /* no authentication */
9845deede1e9 [gaim-migrate @ 1854]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1843
diff changeset
1398 buf[3] = 0x02; /* username/password authentication */
9845deede1e9 [gaim-migrate @ 1854]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1843
diff changeset
1399 i = 4;
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1400 }
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1401 else {
1844
9845deede1e9 [gaim-migrate @ 1854]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1843
diff changeset
1402 buf[1] = 0x01;
9845deede1e9 [gaim-migrate @ 1854]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1843
diff changeset
1403 buf[2] = 0x00;
9845deede1e9 [gaim-migrate @ 1854]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1843
diff changeset
1404 i = 3;
9845deede1e9 [gaim-migrate @ 1854]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1843
diff changeset
1405 }
3717
988485669631 [gaim-migrate @ 3850]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 3630
diff changeset
1406
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1407 if (write(source, buf, i) < i) {
5211
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
1408 gaim_debug(GAIM_DEBUG_ERROR, "socks5 proxy", "Unable to write\n");
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1409 close(source);
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1410
9129
3e94a77ee0c7 [gaim-migrate @ 9907]
Nathan Walp <nwalp@pidgin.im>
parents: 9100
diff changeset
1411 try_connect(phb);
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1412 return;
1087
56c7ceb986a8 [gaim-migrate @ 1097]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1057
diff changeset
1413 }
56c7ceb986a8 [gaim-migrate @ 1097]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1057
diff changeset
1414
2090
b66aca8e8dce [gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2048
diff changeset
1415 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
1416 }
1087
56c7ceb986a8 [gaim-migrate @ 1097]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1057
diff changeset
1417
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1418 static int
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1419 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
1420 {
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1421 int fd = -1;
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1422
5211
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
1423 gaim_debug(GAIM_DEBUG_INFO, "socks5 proxy",
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
1424 "Connecting to %s:%d via %s:%d using SOCKS5\n",
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1425 phb->host, phb->port,
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1426 gaim_proxy_info_get_host(phb->gpi),
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1427 gaim_proxy_info_get_port(phb->gpi));
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1428
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1429 if ((fd = socket(addr->sa_family, SOCK_STREAM, 0)) < 0)
1087
56c7ceb986a8 [gaim-migrate @ 1097]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1057
diff changeset
1430 return -1;
56c7ceb986a8 [gaim-migrate @ 1097]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1057
diff changeset
1431
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1432 fcntl(fd, F_SETFL, O_NONBLOCK);
10172
374d63326461 [gaim-migrate @ 11275]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10170
diff changeset
1433 #ifndef _WIN32
10170
3c88c2f1b732 [gaim-migrate @ 11262]
Ethan Blanton <elb@pidgin.im>
parents: 10087
diff changeset
1434 fcntl(fd, F_SETFD, FD_CLOEXEC);
10172
374d63326461 [gaim-migrate @ 11275]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10170
diff changeset
1435 #endif
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1436
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
1437 if (connect(fd, addr, addrlen) < 0) {
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1438 if ((errno == EINPROGRESS) || (errno == EINTR)) {
5211
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
1439 gaim_debug(GAIM_DEBUG_WARNING, "socks5 proxy",
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
1440 "Connect would have blocked.\n");
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1441
2090
b66aca8e8dce [gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2048
diff changeset
1442 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
1443 }
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1444 else {
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1445 close(fd);
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1446 return -1;
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1447 }
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1448 }
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1449 else {
2048
3366311426df [gaim-migrate @ 2058]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1881
diff changeset
1450 unsigned int len;
3366311426df [gaim-migrate @ 2058]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1881
diff changeset
1451 int error = ETIMEDOUT;
3717
988485669631 [gaim-migrate @ 3850]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 3630
diff changeset
1452
5211
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
1453 gaim_debug(GAIM_DEBUG_MISC, "socks5 proxy",
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
1454 "Connect didn't block.\n");
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1455
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1456 len = sizeof(error);
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1457
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1458 if (getsockopt(fd, SOL_SOCKET, SO_ERROR, &error, &len) < 0) {
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1459 close(fd);
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1460 return -1;
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1461 }
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1462
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1463 fcntl(fd, F_SETFL, 0);
2090
b66aca8e8dce [gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2048
diff changeset
1464 s5_canwrite(phb, fd, GAIM_INPUT_WRITE);
1087
56c7ceb986a8 [gaim-migrate @ 1097]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1057
diff changeset
1465 }
56c7ceb986a8 [gaim-migrate @ 1097]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1057
diff changeset
1466
56c7ceb986a8 [gaim-migrate @ 1097]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1057
diff changeset
1467 return fd;
56c7ceb986a8 [gaim-migrate @ 1097]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1057
diff changeset
1468 }
56c7ceb986a8 [gaim-migrate @ 1097]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1057
diff changeset
1469
9129
3e94a77ee0c7 [gaim-migrate @ 9907]
Nathan Walp <nwalp@pidgin.im>
parents: 9100
diff changeset
1470 static void try_connect(struct PHB *phb)
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
1471 {
4678
9ce3c698ff5e [gaim-migrate @ 4989]
Nathan Walp <nwalp@pidgin.im>
parents: 4648
diff changeset
1472 size_t addrlen;
9ce3c698ff5e [gaim-migrate @ 4989]
Nathan Walp <nwalp@pidgin.im>
parents: 4648
diff changeset
1473 struct sockaddr *addr;
9ce3c698ff5e [gaim-migrate @ 4989]
Nathan Walp <nwalp@pidgin.im>
parents: 4648
diff changeset
1474 int ret = -1;
4634
d19872836812 [gaim-migrate @ 4941]
Nathan Walp <nwalp@pidgin.im>
parents: 4499
diff changeset
1475
9129
3e94a77ee0c7 [gaim-migrate @ 9907]
Nathan Walp <nwalp@pidgin.im>
parents: 9100
diff changeset
1476 while (phb->hosts) {
3e94a77ee0c7 [gaim-migrate @ 9907]
Nathan Walp <nwalp@pidgin.im>
parents: 9100
diff changeset
1477 addrlen = GPOINTER_TO_INT(phb->hosts->data);
3e94a77ee0c7 [gaim-migrate @ 9907]
Nathan Walp <nwalp@pidgin.im>
parents: 9100
diff changeset
1478 phb->hosts = g_slist_remove(phb->hosts, phb->hosts->data);
3e94a77ee0c7 [gaim-migrate @ 9907]
Nathan Walp <nwalp@pidgin.im>
parents: 9100
diff changeset
1479 addr = phb->hosts->data;
3e94a77ee0c7 [gaim-migrate @ 9907]
Nathan Walp <nwalp@pidgin.im>
parents: 9100
diff changeset
1480 phb->hosts = g_slist_remove(phb->hosts, phb->hosts->data);
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
1481
9129
3e94a77ee0c7 [gaim-migrate @ 9907]
Nathan Walp <nwalp@pidgin.im>
parents: 9100
diff changeset
1482 switch (gaim_proxy_info_get_type(phb->gpi)) {
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1483 case GAIM_PROXY_NONE:
4678
9ce3c698ff5e [gaim-migrate @ 4989]
Nathan Walp <nwalp@pidgin.im>
parents: 4648
diff changeset
1484 ret = proxy_connect_none(phb, addr, addrlen);
9ce3c698ff5e [gaim-migrate @ 4989]
Nathan Walp <nwalp@pidgin.im>
parents: 4648
diff changeset
1485 break;
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1486
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1487 case GAIM_PROXY_HTTP:
4678
9ce3c698ff5e [gaim-migrate @ 4989]
Nathan Walp <nwalp@pidgin.im>
parents: 4648
diff changeset
1488 ret = proxy_connect_http(phb, addr, addrlen);
9ce3c698ff5e [gaim-migrate @ 4989]
Nathan Walp <nwalp@pidgin.im>
parents: 4648
diff changeset
1489 break;
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1490
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1491 case GAIM_PROXY_SOCKS4:
4678
9ce3c698ff5e [gaim-migrate @ 4989]
Nathan Walp <nwalp@pidgin.im>
parents: 4648
diff changeset
1492 ret = proxy_connect_socks4(phb, addr, addrlen);
9ce3c698ff5e [gaim-migrate @ 4989]
Nathan Walp <nwalp@pidgin.im>
parents: 4648
diff changeset
1493 break;
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1494
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1495 case GAIM_PROXY_SOCKS5:
4678
9ce3c698ff5e [gaim-migrate @ 4989]
Nathan Walp <nwalp@pidgin.im>
parents: 4648
diff changeset
1496 ret = proxy_connect_socks5(phb, addr, addrlen);
9ce3c698ff5e [gaim-migrate @ 4989]
Nathan Walp <nwalp@pidgin.im>
parents: 4648
diff changeset
1497 break;
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1498
6621
42fdf16f1dad [gaim-migrate @ 7145]
Mark Doliner <mark@kingant.net>
parents: 6320
diff changeset
1499 case GAIM_PROXY_USE_ENVVAR:
42fdf16f1dad [gaim-migrate @ 7145]
Mark Doliner <mark@kingant.net>
parents: 6320
diff changeset
1500 ret = proxy_connect_http(phb, addr, addrlen);
42fdf16f1dad [gaim-migrate @ 7145]
Mark Doliner <mark@kingant.net>
parents: 6320
diff changeset
1501 break;
42fdf16f1dad [gaim-migrate @ 7145]
Mark Doliner <mark@kingant.net>
parents: 6320
diff changeset
1502
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1503 default:
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1504 break;
4678
9ce3c698ff5e [gaim-migrate @ 4989]
Nathan Walp <nwalp@pidgin.im>
parents: 4648
diff changeset
1505 }
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1506
9129
3e94a77ee0c7 [gaim-migrate @ 9907]
Nathan Walp <nwalp@pidgin.im>
parents: 9100
diff changeset
1507 g_free(addr);
3e94a77ee0c7 [gaim-migrate @ 9907]
Nathan Walp <nwalp@pidgin.im>
parents: 9100
diff changeset
1508
4678
9ce3c698ff5e [gaim-migrate @ 4989]
Nathan Walp <nwalp@pidgin.im>
parents: 4648
diff changeset
1509 if (ret > 0)
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
1510 break;
4678
9ce3c698ff5e [gaim-migrate @ 4989]
Nathan Walp <nwalp@pidgin.im>
parents: 4648
diff changeset
1511 }
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1512
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1513 if (ret < 0) {
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1514 if (phb->account == NULL ||
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1515 gaim_account_get_connection(phb->account) != NULL) {
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1516
4993
de84c1de2f66 [gaim-migrate @ 5328]
Nathan Walp <nwalp@pidgin.im>
parents: 4679
diff changeset
1517 phb->func(phb->data, -1, GAIM_INPUT_READ);
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1518 }
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1519
4678
9ce3c698ff5e [gaim-migrate @ 4989]
Nathan Walp <nwalp@pidgin.im>
parents: 4648
diff changeset
1520 g_free(phb->host);
9ce3c698ff5e [gaim-migrate @ 4989]
Nathan Walp <nwalp@pidgin.im>
parents: 4648
diff changeset
1521 g_free(phb);
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
1522 }
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
1523 }
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
1524
9129
3e94a77ee0c7 [gaim-migrate @ 9907]
Nathan Walp <nwalp@pidgin.im>
parents: 9100
diff changeset
1525 static void
3e94a77ee0c7 [gaim-migrate @ 9907]
Nathan Walp <nwalp@pidgin.im>
parents: 9100
diff changeset
1526 connection_host_resolved(GSList *hosts, gpointer data,
3e94a77ee0c7 [gaim-migrate @ 9907]
Nathan Walp <nwalp@pidgin.im>
parents: 9100
diff changeset
1527 const char *error_message)
3e94a77ee0c7 [gaim-migrate @ 9907]
Nathan Walp <nwalp@pidgin.im>
parents: 9100
diff changeset
1528 {
3e94a77ee0c7 [gaim-migrate @ 9907]
Nathan Walp <nwalp@pidgin.im>
parents: 9100
diff changeset
1529 struct PHB *phb = (struct PHB*)data;
3e94a77ee0c7 [gaim-migrate @ 9907]
Nathan Walp <nwalp@pidgin.im>
parents: 9100
diff changeset
1530
3e94a77ee0c7 [gaim-migrate @ 9907]
Nathan Walp <nwalp@pidgin.im>
parents: 9100
diff changeset
1531 phb->hosts = hosts;
3e94a77ee0c7 [gaim-migrate @ 9907]
Nathan Walp <nwalp@pidgin.im>
parents: 9100
diff changeset
1532
3e94a77ee0c7 [gaim-migrate @ 9907]
Nathan Walp <nwalp@pidgin.im>
parents: 9100
diff changeset
1533 try_connect(phb);
3e94a77ee0c7 [gaim-migrate @ 9907]
Nathan Walp <nwalp@pidgin.im>
parents: 9100
diff changeset
1534 }
3e94a77ee0c7 [gaim-migrate @ 9907]
Nathan Walp <nwalp@pidgin.im>
parents: 9100
diff changeset
1535
4452
2afc0f845e74 [gaim-migrate @ 4727]
Sean Egan <seanegan@gmail.com>
parents: 4447
diff changeset
1536 int
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1537 gaim_proxy_connect(GaimAccount *account, const char *host, int port,
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1538 GaimInputFunction func, gpointer data)
1087
56c7ceb986a8 [gaim-migrate @ 1097]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1057
diff changeset
1539 {
5580
86456ec3ca25 [gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents: 5572
diff changeset
1540 const char *connecthost = host;
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
1541 int connectport = port;
6040
80e3641ee9eb [gaim-migrate @ 6490]
Mark Doliner <mark@kingant.net>
parents: 6017
diff changeset
1542 struct PHB *phb;
6621
42fdf16f1dad [gaim-migrate @ 7145]
Mark Doliner <mark@kingant.net>
parents: 6320
diff changeset
1543 const gchar *tmp;
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1544
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1545 g_return_val_if_fail(host != NULL, -1);
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1546 g_return_val_if_fail(port != 0 && port != -1, -1);
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1547 g_return_val_if_fail(func != NULL, -1);
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1548
6040
80e3641ee9eb [gaim-migrate @ 6490]
Mark Doliner <mark@kingant.net>
parents: 6017
diff changeset
1549 phb = g_new0(struct PHB, 1);
80e3641ee9eb [gaim-migrate @ 6490]
Mark Doliner <mark@kingant.net>
parents: 6017
diff changeset
1550
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1551 if (account == NULL || gaim_account_get_proxy_info(account) == NULL)
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1552 phb->gpi = gaim_global_proxy_get_info();
4634
d19872836812 [gaim-migrate @ 4941]
Nathan Walp <nwalp@pidgin.im>
parents: 4499
diff changeset
1553 else
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1554 phb->gpi = gaim_account_get_proxy_info(account);
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1555
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1556 phb->func = func;
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1557 phb->data = data;
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
1558 phb->host = g_strdup(host);
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
1559 phb->port = port;
4993
de84c1de2f66 [gaim-migrate @ 5328]
Nathan Walp <nwalp@pidgin.im>
parents: 4679
diff changeset
1560 phb->account = account;
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1561
6621
42fdf16f1dad [gaim-migrate @ 7145]
Mark Doliner <mark@kingant.net>
parents: 6320
diff changeset
1562 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
1563 if ((tmp = g_getenv("HTTP_PROXY")) != NULL ||
42fdf16f1dad [gaim-migrate @ 7145]
Mark Doliner <mark@kingant.net>
parents: 6320
diff changeset
1564 (tmp = g_getenv("http_proxy")) != NULL ||
42fdf16f1dad [gaim-migrate @ 7145]
Mark Doliner <mark@kingant.net>
parents: 6320
diff changeset
1565 (tmp= g_getenv("HTTPPROXY")) != NULL) {
9227
9171e528d7e5 [gaim-migrate @ 10023]
Christian Hammond <chipx86@chipx86.com>
parents: 9148
diff changeset
1566 char *proxyhost,*proxypath,*proxyuser,*proxypasswd;
7652
ac6b2b3a9a1f [gaim-migrate @ 8296]
Luke Schierer <lschiere@pidgin.im>
parents: 7475
diff changeset
1567 int proxyport;
6621
42fdf16f1dad [gaim-migrate @ 7145]
Mark Doliner <mark@kingant.net>
parents: 6320
diff changeset
1568
9129
3e94a77ee0c7 [gaim-migrate @ 9907]
Nathan Walp <nwalp@pidgin.im>
parents: 9100
diff changeset
1569 /* http_proxy-format:
9227
9171e528d7e5 [gaim-migrate @ 10023]
Christian Hammond <chipx86@chipx86.com>
parents: 9148
diff changeset
1570 * export http_proxy="http://user:passwd@your.proxy.server:port/"
7652
ac6b2b3a9a1f [gaim-migrate @ 8296]
Luke Schierer <lschiere@pidgin.im>
parents: 7475
diff changeset
1571 */
9227
9171e528d7e5 [gaim-migrate @ 10023]
Christian Hammond <chipx86@chipx86.com>
parents: 9148
diff changeset
1572 if(gaim_url_parse(tmp, &proxyhost, &proxyport, &proxypath, &proxyuser, &proxypasswd)) {
7652
ac6b2b3a9a1f [gaim-migrate @ 8296]
Luke Schierer <lschiere@pidgin.im>
parents: 7475
diff changeset
1573 gaim_proxy_info_set_host(phb->gpi, proxyhost);
ac6b2b3a9a1f [gaim-migrate @ 8296]
Luke Schierer <lschiere@pidgin.im>
parents: 7475
diff changeset
1574 g_free(proxyhost);
ac6b2b3a9a1f [gaim-migrate @ 8296]
Luke Schierer <lschiere@pidgin.im>
parents: 7475
diff changeset
1575 g_free(proxypath);
9227
9171e528d7e5 [gaim-migrate @ 10023]
Christian Hammond <chipx86@chipx86.com>
parents: 9148
diff changeset
1576 if (proxyuser != NULL) {
9171e528d7e5 [gaim-migrate @ 10023]
Christian Hammond <chipx86@chipx86.com>
parents: 9148
diff changeset
1577 gaim_proxy_info_set_username(phb->gpi, proxyuser);
9171e528d7e5 [gaim-migrate @ 10023]
Christian Hammond <chipx86@chipx86.com>
parents: 9148
diff changeset
1578 g_free(proxyuser);
9171e528d7e5 [gaim-migrate @ 10023]
Christian Hammond <chipx86@chipx86.com>
parents: 9148
diff changeset
1579 }
9171e528d7e5 [gaim-migrate @ 10023]
Christian Hammond <chipx86@chipx86.com>
parents: 9148
diff changeset
1580 if (proxypasswd != NULL) {
9171e528d7e5 [gaim-migrate @ 10023]
Christian Hammond <chipx86@chipx86.com>
parents: 9148
diff changeset
1581 gaim_proxy_info_set_password(phb->gpi, proxypasswd);
9171e528d7e5 [gaim-migrate @ 10023]
Christian Hammond <chipx86@chipx86.com>
parents: 9148
diff changeset
1582 g_free(proxypasswd);
9171e528d7e5 [gaim-migrate @ 10023]
Christian Hammond <chipx86@chipx86.com>
parents: 9148
diff changeset
1583 }
7652
ac6b2b3a9a1f [gaim-migrate @ 8296]
Luke Schierer <lschiere@pidgin.im>
parents: 7475
diff changeset
1584
ac6b2b3a9a1f [gaim-migrate @ 8296]
Luke Schierer <lschiere@pidgin.im>
parents: 7475
diff changeset
1585 /* only for backward compatibility */
9129
3e94a77ee0c7 [gaim-migrate @ 9907]
Nathan Walp <nwalp@pidgin.im>
parents: 9100
diff changeset
1586 if (proxyport == 80 &&
7652
ac6b2b3a9a1f [gaim-migrate @ 8296]
Luke Schierer <lschiere@pidgin.im>
parents: 7475
diff changeset
1587 ((tmp = g_getenv("HTTP_PROXY_PORT")) != NULL ||
ac6b2b3a9a1f [gaim-migrate @ 8296]
Luke Schierer <lschiere@pidgin.im>
parents: 7475
diff changeset
1588 (tmp = g_getenv("http_proxy_port")) != NULL ||
ac6b2b3a9a1f [gaim-migrate @ 8296]
Luke Schierer <lschiere@pidgin.im>
parents: 7475
diff changeset
1589 (tmp = g_getenv("HTTPPROXYPORT")) != NULL))
ac6b2b3a9a1f [gaim-migrate @ 8296]
Luke Schierer <lschiere@pidgin.im>
parents: 7475
diff changeset
1590 proxyport = atoi(tmp);
9129
3e94a77ee0c7 [gaim-migrate @ 9907]
Nathan Walp <nwalp@pidgin.im>
parents: 9100
diff changeset
1591
7652
ac6b2b3a9a1f [gaim-migrate @ 8296]
Luke Schierer <lschiere@pidgin.im>
parents: 7475
diff changeset
1592 gaim_proxy_info_set_port(phb->gpi, proxyport);
ac6b2b3a9a1f [gaim-migrate @ 8296]
Luke Schierer <lschiere@pidgin.im>
parents: 7475
diff changeset
1593 }
6621
42fdf16f1dad [gaim-migrate @ 7145]
Mark Doliner <mark@kingant.net>
parents: 6320
diff changeset
1594 }
42fdf16f1dad [gaim-migrate @ 7145]
Mark Doliner <mark@kingant.net>
parents: 6320
diff changeset
1595
9227
9171e528d7e5 [gaim-migrate @ 10023]
Christian Hammond <chipx86@chipx86.com>
parents: 9148
diff changeset
1596 /* 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
1597 if ((tmp = g_getenv("HTTP_PROXY_USER")) != NULL ||
42fdf16f1dad [gaim-migrate @ 7145]
Mark Doliner <mark@kingant.net>
parents: 6320
diff changeset
1598 (tmp = g_getenv("http_proxy_user")) != NULL ||
42fdf16f1dad [gaim-migrate @ 7145]
Mark Doliner <mark@kingant.net>
parents: 6320
diff changeset
1599 (tmp = g_getenv("HTTPPROXYUSER")) != NULL)
42fdf16f1dad [gaim-migrate @ 7145]
Mark Doliner <mark@kingant.net>
parents: 6320
diff changeset
1600 gaim_proxy_info_set_username(phb->gpi, tmp);
42fdf16f1dad [gaim-migrate @ 7145]
Mark Doliner <mark@kingant.net>
parents: 6320
diff changeset
1601
42fdf16f1dad [gaim-migrate @ 7145]
Mark Doliner <mark@kingant.net>
parents: 6320
diff changeset
1602 if ((tmp = g_getenv("HTTP_PROXY_PASS")) != NULL ||
42fdf16f1dad [gaim-migrate @ 7145]
Mark Doliner <mark@kingant.net>
parents: 6320
diff changeset
1603 (tmp = g_getenv("http_proxy_pass")) != NULL ||
42fdf16f1dad [gaim-migrate @ 7145]
Mark Doliner <mark@kingant.net>
parents: 6320
diff changeset
1604 (tmp = g_getenv("HTTPPROXYPASS")) != NULL)
42fdf16f1dad [gaim-migrate @ 7145]
Mark Doliner <mark@kingant.net>
parents: 6320
diff changeset
1605 gaim_proxy_info_set_password(phb->gpi, tmp);
42fdf16f1dad [gaim-migrate @ 7145]
Mark Doliner <mark@kingant.net>
parents: 6320
diff changeset
1606 }
42fdf16f1dad [gaim-migrate @ 7145]
Mark Doliner <mark@kingant.net>
parents: 6320
diff changeset
1607
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1608 if ((gaim_proxy_info_get_type(phb->gpi) != GAIM_PROXY_NONE) &&
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1609 (gaim_proxy_info_get_host(phb->gpi) == NULL ||
6621
42fdf16f1dad [gaim-migrate @ 7145]
Mark Doliner <mark@kingant.net>
parents: 6320
diff changeset
1610 gaim_proxy_info_get_port(phb->gpi) <= 0)) {
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1611
6621
42fdf16f1dad [gaim-migrate @ 7145]
Mark Doliner <mark@kingant.net>
parents: 6320
diff changeset
1612 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
1613 g_free(phb->host);
42fdf16f1dad [gaim-migrate @ 7145]
Mark Doliner <mark@kingant.net>
parents: 6320
diff changeset
1614 g_free(phb);
42fdf16f1dad [gaim-migrate @ 7145]
Mark Doliner <mark@kingant.net>
parents: 6320
diff changeset
1615 return -1;
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1616 }
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
1617
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1618 switch (gaim_proxy_info_get_type(phb->gpi))
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
1619 {
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1620 case GAIM_PROXY_NONE:
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
1621 break;
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1622
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1623 case GAIM_PROXY_HTTP:
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1624 case GAIM_PROXY_SOCKS4:
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1625 case GAIM_PROXY_SOCKS5:
6621
42fdf16f1dad [gaim-migrate @ 7145]
Mark Doliner <mark@kingant.net>
parents: 6320
diff changeset
1626 case GAIM_PROXY_USE_ENVVAR:
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1627 connecthost = gaim_proxy_info_get_host(phb->gpi);
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1628 connectport = gaim_proxy_info_get_port(phb->gpi);
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
1629 break;
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1630
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
1631 default:
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
1632 g_free(phb->host);
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
1633 g_free(phb);
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
1634 return -1;
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
1635 }
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1636
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1637 return gaim_gethostbyname_async(connecthost, connectport,
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1638 connection_host_resolved, phb);
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1639 }
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1640
8262
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
1641 int
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
1642 gaim_proxy_connect_socks5(GaimProxyInfo *gpi, const char *host, int port,
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
1643 GaimInputFunction func, gpointer data)
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
1644 {
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
1645 struct PHB *phb;
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
1646
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
1647 phb = g_new0(struct PHB, 1);
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
1648 phb->gpi = gpi;
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
1649 phb->func = func;
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
1650 phb->data = data;
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
1651 phb->host = g_strdup(host);
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
1652 phb->port = port;
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
1653
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
1654 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
1655 connection_host_resolved, phb);
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
1656 }
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
1657
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
1658
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1659 static void
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1660 proxy_pref_cb(const char *name, GaimPrefType type, gpointer value,
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1661 gpointer data)
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1662 {
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1663 GaimProxyInfo *info = gaim_global_proxy_get_info();
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1664
6001
5e9364e9b29e [gaim-migrate @ 6449]
Mark Doliner <mark@kingant.net>
parents: 5970
diff changeset
1665 if (!strcmp(name, "/core/proxy/type")) {
5e9364e9b29e [gaim-migrate @ 6449]
Mark Doliner <mark@kingant.net>
parents: 5970
diff changeset
1666 int proxytype;
5e9364e9b29e [gaim-migrate @ 6449]
Mark Doliner <mark@kingant.net>
parents: 5970
diff changeset
1667 char *type = value;
5e9364e9b29e [gaim-migrate @ 6449]
Mark Doliner <mark@kingant.net>
parents: 5970
diff changeset
1668
5e9364e9b29e [gaim-migrate @ 6449]
Mark Doliner <mark@kingant.net>
parents: 5970
diff changeset
1669 if (!strcmp(type, "none"))
5e9364e9b29e [gaim-migrate @ 6449]
Mark Doliner <mark@kingant.net>
parents: 5970
diff changeset
1670 proxytype = GAIM_PROXY_NONE;
5e9364e9b29e [gaim-migrate @ 6449]
Mark Doliner <mark@kingant.net>
parents: 5970
diff changeset
1671 else if (!strcmp(type, "http"))
5e9364e9b29e [gaim-migrate @ 6449]
Mark Doliner <mark@kingant.net>
parents: 5970
diff changeset
1672 proxytype = GAIM_PROXY_HTTP;
5e9364e9b29e [gaim-migrate @ 6449]
Mark Doliner <mark@kingant.net>
parents: 5970
diff changeset
1673 else if (!strcmp(type, "socks4"))
5e9364e9b29e [gaim-migrate @ 6449]
Mark Doliner <mark@kingant.net>
parents: 5970
diff changeset
1674 proxytype = GAIM_PROXY_SOCKS4;
5e9364e9b29e [gaim-migrate @ 6449]
Mark Doliner <mark@kingant.net>
parents: 5970
diff changeset
1675 else if (!strcmp(type, "socks5"))
5e9364e9b29e [gaim-migrate @ 6449]
Mark Doliner <mark@kingant.net>
parents: 5970
diff changeset
1676 proxytype = GAIM_PROXY_SOCKS5;
6621
42fdf16f1dad [gaim-migrate @ 7145]
Mark Doliner <mark@kingant.net>
parents: 6320
diff changeset
1677 else if (!strcmp(type, "envvar"))
42fdf16f1dad [gaim-migrate @ 7145]
Mark Doliner <mark@kingant.net>
parents: 6320
diff changeset
1678 proxytype = GAIM_PROXY_USE_ENVVAR;
6001
5e9364e9b29e [gaim-migrate @ 6449]
Mark Doliner <mark@kingant.net>
parents: 5970
diff changeset
1679 else
5e9364e9b29e [gaim-migrate @ 6449]
Mark Doliner <mark@kingant.net>
parents: 5970
diff changeset
1680 proxytype = -1;
5e9364e9b29e [gaim-migrate @ 6449]
Mark Doliner <mark@kingant.net>
parents: 5970
diff changeset
1681
5e9364e9b29e [gaim-migrate @ 6449]
Mark Doliner <mark@kingant.net>
parents: 5970
diff changeset
1682 gaim_proxy_info_set_type(info, proxytype);
5e9364e9b29e [gaim-migrate @ 6449]
Mark Doliner <mark@kingant.net>
parents: 5970
diff changeset
1683 } else if (!strcmp(name, "/core/proxy/host"))
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1684 gaim_proxy_info_set_host(info, value);
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1685 else if (!strcmp(name, "/core/proxy/port"))
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1686 gaim_proxy_info_set_port(info, GPOINTER_TO_INT(value));
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1687 else if (!strcmp(name, "/core/proxy/username"))
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1688 gaim_proxy_info_set_username(info, value);
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1689 else if (!strcmp(name, "/core/proxy/password"))
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1690 gaim_proxy_info_set_password(info, value);
1087
56c7ceb986a8 [gaim-migrate @ 1097]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1057
diff changeset
1691 }
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1692
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1693 void
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1694 gaim_proxy_init(void)
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1695 {
10087
9fdbfe832fac [gaim-migrate @ 11098]
Stu Tomlinson <stu@nosnilmot.com>
parents: 9863
diff changeset
1696 void *handle;
9fdbfe832fac [gaim-migrate @ 11098]
Stu Tomlinson <stu@nosnilmot.com>
parents: 9863
diff changeset
1697
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1698 /* Initialize a default proxy info struct. */
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1699 global_proxy_info = gaim_proxy_info_new();
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1700
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1701 /* Proxy */
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1702 gaim_prefs_add_none("/core/proxy");
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1703 gaim_prefs_add_string("/core/proxy/type", "none");
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1704 gaim_prefs_add_string("/core/proxy/host", "");
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1705 gaim_prefs_add_int("/core/proxy/port", 0);
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1706 gaim_prefs_add_string("/core/proxy/username", "");
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1707 gaim_prefs_add_string("/core/proxy/password", "");
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1708
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1709 /* Setup callbacks for the preferences. */
10087
9fdbfe832fac [gaim-migrate @ 11098]
Stu Tomlinson <stu@nosnilmot.com>
parents: 9863
diff changeset
1710 handle = gaim_proxy_get_handle();
9fdbfe832fac [gaim-migrate @ 11098]
Stu Tomlinson <stu@nosnilmot.com>
parents: 9863
diff changeset
1711 gaim_prefs_connect_callback(handle, "/core/proxy/type",
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1712 proxy_pref_cb, NULL);
10087
9fdbfe832fac [gaim-migrate @ 11098]
Stu Tomlinson <stu@nosnilmot.com>
parents: 9863
diff changeset
1713 gaim_prefs_connect_callback(handle, "/core/proxy/host",
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1714 proxy_pref_cb, NULL);
10087
9fdbfe832fac [gaim-migrate @ 11098]
Stu Tomlinson <stu@nosnilmot.com>
parents: 9863
diff changeset
1715 gaim_prefs_connect_callback(handle, "/core/proxy/port",
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1716 proxy_pref_cb, NULL);
10087
9fdbfe832fac [gaim-migrate @ 11098]
Stu Tomlinson <stu@nosnilmot.com>
parents: 9863
diff changeset
1717 gaim_prefs_connect_callback(handle, "/core/proxy/username",
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1718 proxy_pref_cb, NULL);
10087
9fdbfe832fac [gaim-migrate @ 11098]
Stu Tomlinson <stu@nosnilmot.com>
parents: 9863
diff changeset
1719 gaim_prefs_connect_callback(handle, "/core/proxy/password",
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1720 proxy_pref_cb, NULL);
10237
2f6dcbaaabe0 [gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 10172
diff changeset
1721 #ifdef _WIN32
2f6dcbaaabe0 [gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 10172
diff changeset
1722 if(!g_thread_supported())
2f6dcbaaabe0 [gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 10172
diff changeset
1723 g_thread_init(NULL);
2f6dcbaaabe0 [gaim-migrate @ 11373]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 10172
diff changeset
1724 #endif
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1725 }
10087
9fdbfe832fac [gaim-migrate @ 11098]
Stu Tomlinson <stu@nosnilmot.com>
parents: 9863
diff changeset
1726
9fdbfe832fac [gaim-migrate @ 11098]
Stu Tomlinson <stu@nosnilmot.com>
parents: 9863
diff changeset
1727 void *
9fdbfe832fac [gaim-migrate @ 11098]
Stu Tomlinson <stu@nosnilmot.com>
parents: 9863
diff changeset
1728 gaim_proxy_get_handle()
9fdbfe832fac [gaim-migrate @ 11098]
Stu Tomlinson <stu@nosnilmot.com>
parents: 9863
diff changeset
1729 {
9fdbfe832fac [gaim-migrate @ 11098]
Stu Tomlinson <stu@nosnilmot.com>
parents: 9863
diff changeset
1730 static int handle;
9fdbfe832fac [gaim-migrate @ 11098]
Stu Tomlinson <stu@nosnilmot.com>
parents: 9863
diff changeset
1731
9fdbfe832fac [gaim-migrate @ 11098]
Stu Tomlinson <stu@nosnilmot.com>
parents: 9863
diff changeset
1732 return &handle;
9fdbfe832fac [gaim-migrate @ 11098]
Stu Tomlinson <stu@nosnilmot.com>
parents: 9863
diff changeset
1733 }