annotate src/proxy.c @ 14142:89d043d547cc

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