annotate src/proxy.c @ 8410:3c07b7d0084c

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