annotate src/proxy.c @ 5893:718c1e8d5728

[gaim-migrate @ 6325] Dear Mark, Chips and dip night was lots of fun! Thanks for the idea! I told you that the 0x81 thing wasn't the problem. The server sends that when it already has the icon with the given md5sum cached. The client then resends the SSI modify packet to get the server to actually use that icon. This is not what is causing the loop; the loop happened before I added that code, and happens when that code doesn't get called. Love, Sean. committer: Tailor Script <tailor@pidgin.im>
author Sean Egan <seanegan@gmail.com>
date Sun, 15 Jun 2003 15:09:01 +0000
parents 059d95c67cda
children 730015652f4d
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 *
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
7 * Copyright (C) 1998-1999, Mark Spencer <markster@marko.net>
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
8 * Copyright (C) 2003 Christian Hammond <chipx86@gnupdate.org>
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
9 *
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
10 * This program is free software; you can redistribute it and/or modify
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
11 * 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
12 * the Free Software Foundation; either version 2 of the License, or
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
13 * (at your option) any later version.
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
14 *
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
15 * This program is distributed in the hope that it will be useful,
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
18 * GNU General Public License for more details.
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
19 *
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
20 * You should have received a copy of the GNU General Public License
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
21 * along with this program; if not, write to the Free Software
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
23 *
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 /* this is a little piece of code to handle proxy connection */
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
27 /* it is intended to : 1st handle http proxy, using the CONNECT command
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
28 , 2nd provide an easy way to add socks support */
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
29
5872
059d95c67cda [gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents: 5681
diff changeset
30 #include "internal.h"
059d95c67cda [gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents: 5681
diff changeset
31 #include "debug.h"
059d95c67cda [gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents: 5681
diff changeset
32 #include "prefs.h"
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
33 #include "proxy.h"
5872
059d95c67cda [gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents: 5681
diff changeset
34 #include "util.h"
3630
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3376
diff changeset
35
2090
b66aca8e8dce [gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2048
diff changeset
36 #define GAIM_READ_COND (G_IO_IN | G_IO_HUP | G_IO_ERR)
2229
b5ad79ad917b [gaim-migrate @ 2239]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2096
diff changeset
37 #define GAIM_WRITE_COND (G_IO_OUT | G_IO_HUP | G_IO_ERR | G_IO_NVAL)
2090
b66aca8e8dce [gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2048
diff changeset
38
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
39 static GaimProxyInfo *global_proxy_info = NULL;
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
40 static gboolean global_proxy_info_from_prefs = FALSE;
1881
a02584b98823 [gaim-migrate @ 1891]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1868
diff changeset
41
5872
059d95c67cda [gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents: 5681
diff changeset
42 static int opt_debug = 0;
059d95c67cda [gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents: 5681
diff changeset
43
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
44 struct PHB {
2090
b66aca8e8dce [gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2048
diff changeset
45 GaimInputFunction func;
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
46 gpointer data;
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
47 char *host;
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
48 int port;
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
49 gint inpa;
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
50 GaimProxyInfo *gpi;
5563
9eb5b13fd412 [gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents: 5532
diff changeset
51 GaimAccount *account;
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
52 };
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
53
2090
b66aca8e8dce [gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2048
diff changeset
54 typedef struct _GaimIOClosure {
b66aca8e8dce [gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2048
diff changeset
55 GaimInputFunction function;
2300
d2686f757d6e [gaim-migrate @ 2310]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2266
diff changeset
56 guint result;
2090
b66aca8e8dce [gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2048
diff changeset
57 gpointer data;
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
58
2090
b66aca8e8dce [gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2048
diff changeset
59 } GaimIOClosure;
b66aca8e8dce [gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2048
diff changeset
60
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
61 /**************************************************************************
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
62 * Proxy structure API
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
63 **************************************************************************/
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
64 GaimProxyInfo *
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
65 gaim_proxy_info_new(void)
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
66 {
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
67 return g_new0(GaimProxyInfo, 1);
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
68 }
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
69
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
70 void
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
71 gaim_proxy_info_destroy(GaimProxyInfo *info)
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 g_return_if_fail(info != NULL);
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
74
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
75 if (info->host != NULL) g_free(info->host);
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
76 if (info->username != NULL) g_free(info->username);
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
77 if (info->password != NULL) g_free(info->password);
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
78
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
79 g_free(info);
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
80 }
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
81
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
82 void
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
83 gaim_proxy_info_set_type(GaimProxyInfo *info, GaimProxyType type)
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
84 {
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
85 g_return_if_fail(info != NULL);
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
86
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
87 info->type = 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
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
90 void
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
91 gaim_proxy_info_set_host(GaimProxyInfo *info, const char *host)
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
92 {
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
93 g_return_if_fail(info != NULL);
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
94
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
95 if (info->host != NULL)
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
96 g_free(info->host);
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
97
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
98 info->host = (host == NULL ? NULL : g_strdup(host));
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
99 }
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
100
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
101 void
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
102 gaim_proxy_info_set_port(GaimProxyInfo *info, int port)
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
103 {
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
104 g_return_if_fail(info != NULL);
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
105
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
106 info->port = 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
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
109 void
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
110 gaim_proxy_info_set_username(GaimProxyInfo *info, const char *username)
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 g_return_if_fail(info != NULL);
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
113
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
114 if (info->username != NULL)
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
115 g_free(info->username);
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
116
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
117 info->username = (username == NULL ? NULL : g_strdup(username));
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
118 }
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
119
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
120 void
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
121 gaim_proxy_info_set_password(GaimProxyInfo *info, const char *password)
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 g_return_if_fail(info != NULL);
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
124
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
125 if (info->password != NULL)
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
126 g_free(info->password);
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
127
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
128 info->password = (password == NULL ? NULL : g_strdup(password));
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
129 }
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
130
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
131 GaimProxyType
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
132 gaim_proxy_info_get_type(const GaimProxyInfo *info)
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 g_return_val_if_fail(info != NULL, GAIM_PROXY_NONE);
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
135
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
136 return info->type;
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
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
139 const char *
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
140 gaim_proxy_info_get_host(const GaimProxyInfo *info)
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 g_return_val_if_fail(info != NULL, NULL);
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
143
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
144 return info->host;
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
145 }
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
146
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
147 int
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
148 gaim_proxy_info_get_port(const GaimProxyInfo *info)
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
149 {
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
150 g_return_val_if_fail(info != NULL, 0);
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
151
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
152 return info->port;
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
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
155 const char *
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
156 gaim_proxy_info_get_username(const GaimProxyInfo *info)
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 g_return_val_if_fail(info != NULL, NULL);
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
159
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
160 return info->username;
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
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
163 const char *
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
164 gaim_proxy_info_get_password(const GaimProxyInfo *info)
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 g_return_val_if_fail(info != NULL, NULL);
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
167
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
168 return info->password;
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
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 * Global Proxy API
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 void
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
175 gaim_global_proxy_set_from_prefs(gboolean from_prefs)
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
176 {
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
177 global_proxy_info_from_prefs = from_prefs;
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
178 }
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
179
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
180 GaimProxyInfo *
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
181 gaim_global_proxy_get_info(void)
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
182 {
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
183 return global_proxy_info;
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
184 }
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
185
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
186 gboolean
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
187 gaim_global_proxy_is_from_prefs(void)
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
188 {
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
189 return global_proxy_info_from_prefs;
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
190 }
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
191
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
192 /**************************************************************************
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
193 * Proxy API
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
194 **************************************************************************/
2096
39b4413ce4b3 [gaim-migrate @ 2106]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2090
diff changeset
195 static void gaim_io_destroy(gpointer data)
39b4413ce4b3 [gaim-migrate @ 2106]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2090
diff changeset
196 {
39b4413ce4b3 [gaim-migrate @ 2106]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2090
diff changeset
197 g_free(data);
39b4413ce4b3 [gaim-migrate @ 2106]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2090
diff changeset
198 }
39b4413ce4b3 [gaim-migrate @ 2106]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2090
diff changeset
199
2090
b66aca8e8dce [gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2048
diff changeset
200 static gboolean gaim_io_invoke(GIOChannel *source, GIOCondition condition, gpointer data)
b66aca8e8dce [gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2048
diff changeset
201 {
b66aca8e8dce [gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2048
diff changeset
202 GaimIOClosure *closure = data;
b66aca8e8dce [gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2048
diff changeset
203 GaimInputCondition gaim_cond = 0;
b66aca8e8dce [gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2048
diff changeset
204
b66aca8e8dce [gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2048
diff changeset
205 if (condition & GAIM_READ_COND)
b66aca8e8dce [gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2048
diff changeset
206 gaim_cond |= GAIM_INPUT_READ;
2754
642413968b03 [gaim-migrate @ 2767]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2477
diff changeset
207 if (condition & GAIM_WRITE_COND)
2090
b66aca8e8dce [gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2048
diff changeset
208 gaim_cond |= GAIM_INPUT_WRITE;
b66aca8e8dce [gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2048
diff changeset
209
2840
babeeac8cf9e [gaim-migrate @ 2853]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2790
diff changeset
210 /*
5211
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
211 gaim_debug(GAIM_DEBUG_MISC, "proxy",
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
212 "CLOSURE: callback for %d, fd is %d\n",
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
213 closure->result, g_io_channel_unix_get_fd(source));
2840
babeeac8cf9e [gaim-migrate @ 2853]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2790
diff changeset
214 */
2300
d2686f757d6e [gaim-migrate @ 2310]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2266
diff changeset
215
2090
b66aca8e8dce [gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2048
diff changeset
216 closure->function(closure->data, g_io_channel_unix_get_fd(source), gaim_cond);
b66aca8e8dce [gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2048
diff changeset
217
b66aca8e8dce [gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2048
diff changeset
218 return TRUE;
b66aca8e8dce [gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2048
diff changeset
219 }
b66aca8e8dce [gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2048
diff changeset
220
2372
2927c2c26fe6 [gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2306
diff changeset
221 gint gaim_input_add(gint source, GaimInputCondition condition, GaimInputFunction function, gpointer data)
2090
b66aca8e8dce [gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2048
diff changeset
222 {
b66aca8e8dce [gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2048
diff changeset
223 GaimIOClosure *closure = g_new0(GaimIOClosure, 1);
b66aca8e8dce [gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2048
diff changeset
224 GIOChannel *channel;
b66aca8e8dce [gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2048
diff changeset
225 GIOCondition cond = 0;
b66aca8e8dce [gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2048
diff changeset
226
b66aca8e8dce [gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2048
diff changeset
227 closure->function = function;
b66aca8e8dce [gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2048
diff changeset
228 closure->data = data;
b66aca8e8dce [gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2048
diff changeset
229
b66aca8e8dce [gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2048
diff changeset
230 if (condition & GAIM_INPUT_READ)
b66aca8e8dce [gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2048
diff changeset
231 cond |= GAIM_READ_COND;
b66aca8e8dce [gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2048
diff changeset
232 if (condition & GAIM_INPUT_WRITE)
b66aca8e8dce [gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2048
diff changeset
233 cond |= GAIM_WRITE_COND;
b66aca8e8dce [gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2048
diff changeset
234
b66aca8e8dce [gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2048
diff changeset
235 channel = g_io_channel_unix_new(source);
2300
d2686f757d6e [gaim-migrate @ 2310]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2266
diff changeset
236 closure->result = g_io_add_watch_full(channel, G_PRIORITY_DEFAULT, cond,
2372
2927c2c26fe6 [gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2306
diff changeset
237 gaim_io_invoke, closure, gaim_io_destroy);
5211
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
238
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
239 /*
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
240 gaim_debug(GAIM_DEBUG_MISC, "proxy",
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
241 "CLOSURE: adding input watcher %d for fd %d\n",
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
242 closure->result, source);
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
243 */
2300
d2686f757d6e [gaim-migrate @ 2310]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2266
diff changeset
244
2090
b66aca8e8dce [gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2048
diff changeset
245 g_io_channel_unref(channel);
2300
d2686f757d6e [gaim-migrate @ 2310]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2266
diff changeset
246 return closure->result;
2090
b66aca8e8dce [gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2048
diff changeset
247 }
b66aca8e8dce [gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2048
diff changeset
248
b66aca8e8dce [gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2048
diff changeset
249 void gaim_input_remove(gint tag)
b66aca8e8dce [gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2048
diff changeset
250 {
5211
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
251 /* gaim_debug(GAIM_DEBUG_MISC, "proxy",
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
252 "CLOSURE: removing input watcher %d\n", tag); */
2477
8530d4d72fab [gaim-migrate @ 2490]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2372
diff changeset
253 if (tag > 0)
8530d4d72fab [gaim-migrate @ 2490]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2372
diff changeset
254 g_source_remove(tag);
2090
b66aca8e8dce [gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2048
diff changeset
255 }
b66aca8e8dce [gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2048
diff changeset
256
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
257
4678
9ce3c698ff5e [gaim-migrate @ 4989]
Nathan Walp <nwalp@pidgin.im>
parents: 4648
diff changeset
258 typedef void (*dns_callback_t)(GSList *hosts, gpointer data,
9ce3c698ff5e [gaim-migrate @ 4989]
Nathan Walp <nwalp@pidgin.im>
parents: 4648
diff changeset
259 const char *error_message);
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
260
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
261 #ifdef __unix__
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
262
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
263 /* This structure represents both a pending DNS request and
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
264 * a free child process.
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
265 */
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
266 typedef struct {
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
267 char *host;
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
268 int port;
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
269 dns_callback_t callback;
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
270 gpointer data;
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
271 gint inpa;
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
272 int fd_in, fd_out;
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
273 pid_t dns_pid;
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
274 } pending_dns_request_t;
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
275
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
276 static GSList *free_dns_children = NULL;
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
277 static GQueue *queued_requests = NULL;
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
278
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
279 static int number_of_dns_children = 0;
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
280
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
281 const int MAX_DNS_CHILDREN = 2;
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
282
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
283 typedef struct {
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
284 char hostname[512];
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
285 int port;
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
286 } dns_params_t;
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
287
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
288 typedef struct {
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
289 dns_params_t params;
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
290 dns_callback_t callback;
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
291 gpointer data;
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
292 } queued_dns_request_t;
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
293
4434
6b83a532eeb2 [gaim-migrate @ 4709]
Nathan Walp <nwalp@pidgin.im>
parents: 4394
diff changeset
294 static void req_free(pending_dns_request_t *req)
6b83a532eeb2 [gaim-migrate @ 4709]
Nathan Walp <nwalp@pidgin.im>
parents: 4394
diff changeset
295 {
6b83a532eeb2 [gaim-migrate @ 4709]
Nathan Walp <nwalp@pidgin.im>
parents: 4394
diff changeset
296 g_return_if_fail(req != NULL);
6b83a532eeb2 [gaim-migrate @ 4709]
Nathan Walp <nwalp@pidgin.im>
parents: 4394
diff changeset
297 if(req->host)
6b83a532eeb2 [gaim-migrate @ 4709]
Nathan Walp <nwalp@pidgin.im>
parents: 4394
diff changeset
298 g_free(req->host);
6b83a532eeb2 [gaim-migrate @ 4709]
Nathan Walp <nwalp@pidgin.im>
parents: 4394
diff changeset
299 close(req->fd_in);
6b83a532eeb2 [gaim-migrate @ 4709]
Nathan Walp <nwalp@pidgin.im>
parents: 4394
diff changeset
300 close(req->fd_out);
6b83a532eeb2 [gaim-migrate @ 4709]
Nathan Walp <nwalp@pidgin.im>
parents: 4394
diff changeset
301 g_free(req);
6b83a532eeb2 [gaim-migrate @ 4709]
Nathan Walp <nwalp@pidgin.im>
parents: 4394
diff changeset
302 number_of_dns_children--;
6b83a532eeb2 [gaim-migrate @ 4709]
Nathan Walp <nwalp@pidgin.im>
parents: 4394
diff changeset
303 }
6b83a532eeb2 [gaim-migrate @ 4709]
Nathan Walp <nwalp@pidgin.im>
parents: 4394
diff changeset
304
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
305 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
306 {
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
307 char ch;
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
308 int rc;
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 /* Are you alive? */
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
311 if(kill(req->dns_pid, 0) != 0) {
5211
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
312 gaim_debug(GAIM_DEBUG_WARNING, "dns",
5218
4ee151ad8233 [gaim-migrate @ 5588]
Christian Hammond <chipx86@chipx86.com>
parents: 5211
diff changeset
313 "DNS child %d no longer exists\n", req->dns_pid);
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
314 return -1;
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
315 }
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
316
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
317 /* Let's contact this lost child! */
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
318 rc = write(req->fd_in, dns_params, sizeof(*dns_params));
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
319 if(rc<0) {
5211
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
320 gaim_debug(GAIM_DEBUG_ERROR, "dns",
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
321 "Unable to write to DNS child %d: %d\n",
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
322 req->dns_pid, strerror(errno));
4434
6b83a532eeb2 [gaim-migrate @ 4709]
Nathan Walp <nwalp@pidgin.im>
parents: 4394
diff changeset
323 close(req->fd_in);
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
324 return -1;
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
325 }
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
326
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
327 g_return_val_if_fail(rc == sizeof(*dns_params), -1);
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
328
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
329 /* Did you hear me? (This avoids some race conditions) */
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
330 rc = read(req->fd_out, &ch, 1);
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
331 if(rc != 1 || ch!='Y') {
5211
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
332 gaim_debug(GAIM_DEBUG_WARNING, "dns",
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
333 "DNS child %d not responding. Killing it!\n",
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
334 req->dns_pid);
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
335 kill(req->dns_pid, SIGKILL);
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
336 return -1;
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
337 }
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
338
5211
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
339 gaim_debug(GAIM_DEBUG_INFO, "dns",
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
340 "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
341 return 0;
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
342 }
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
343
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
344 static void host_resolved(gpointer data, gint source, GaimInputCondition cond);
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
345
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
346 static void release_dns_child(pending_dns_request_t *req)
2911
4790fb1272a1 [gaim-migrate @ 2924]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2907
diff changeset
347 {
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
348 g_free(req->host);
4434
6b83a532eeb2 [gaim-migrate @ 4709]
Nathan Walp <nwalp@pidgin.im>
parents: 4394
diff changeset
349 req->host=NULL;
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
350
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
351 if(queued_requests && !g_queue_is_empty(queued_requests)) {
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
352 queued_dns_request_t *r = g_queue_pop_head(queued_requests);
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
353 req->host = g_strdup(r->params.hostname);
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
354 req->port = r->params.port;
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
355 req->callback = r->callback;
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
356 req->data = r->data;
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
357
5211
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
358 gaim_debug(GAIM_DEBUG_INFO, "dns",
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
359 "Processing queued DNS query for '%s' with child %d\n",
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
360 req->host, req->dns_pid);
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
361
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
362 if(send_dns_request_to_child(req, &(r->params)) != 0) {
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 req = NULL;
5211
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
365
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
366 gaim_debug(GAIM_DEBUG_WARNING, "dns",
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
367 "Intent of process queued query of '%s' failed, "
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
368 "requeueing...\n", r->params.hostname);
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
369 g_queue_push_head(queued_requests, r);
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
370 } else {
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
371 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
372 g_free(r);
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
373 }
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
374
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
375 } else {
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
376 req->host = NULL;
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
377 req->callback = NULL;
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
378 req->data = NULL;
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
379 free_dns_children = g_slist_append(free_dns_children, req);
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
380 }
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
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
383 static void host_resolved(gpointer data, gint source, GaimInputCondition cond)
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
384 {
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
385 pending_dns_request_t *req = (pending_dns_request_t*)data;
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
386 int rc, err;
4678
9ce3c698ff5e [gaim-migrate @ 4989]
Nathan Walp <nwalp@pidgin.im>
parents: 4648
diff changeset
387 GSList *hosts = NULL;
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
388 struct sockaddr *addr = NULL;
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
389 socklen_t addrlen;
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
390
5211
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
391 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
392 gaim_input_remove(req->inpa);
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
393
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
394 rc=read(req->fd_out, &err, sizeof(err));
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
395 if((rc==4) && (err!=0)) {
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
396 char message[1024];
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
397 g_snprintf(message, sizeof(message), "DNS error: %s (pid=%d)",
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
398 #ifdef HAVE_GETADDRINFO
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
399 gai_strerror(err),
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
400 #else
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
401 hstrerror(err),
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
402 #endif
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
403 req->dns_pid);
5211
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
404 gaim_debug(GAIM_DEBUG_ERROR, "dns", "%s\n", message);
4678
9ce3c698ff5e [gaim-migrate @ 4989]
Nathan Walp <nwalp@pidgin.im>
parents: 4648
diff changeset
405 req->callback(NULL, req->data, message);
9ce3c698ff5e [gaim-migrate @ 4989]
Nathan Walp <nwalp@pidgin.im>
parents: 4648
diff changeset
406 release_dns_child(req);
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
407 return;
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
408 }
4367
101fa831f52f [gaim-migrate @ 4633]
Mark Doliner <mark@kingant.net>
parents: 4366
diff changeset
409 if(rc>0) {
4678
9ce3c698ff5e [gaim-migrate @ 4989]
Nathan Walp <nwalp@pidgin.im>
parents: 4648
diff changeset
410 while(rc > 0) {
9ce3c698ff5e [gaim-migrate @ 4989]
Nathan Walp <nwalp@pidgin.im>
parents: 4648
diff changeset
411 rc=read(req->fd_out, &addrlen, sizeof(addrlen));
9ce3c698ff5e [gaim-migrate @ 4989]
Nathan Walp <nwalp@pidgin.im>
parents: 4648
diff changeset
412 if(rc>0 && addrlen > 0) {
9ce3c698ff5e [gaim-migrate @ 4989]
Nathan Walp <nwalp@pidgin.im>
parents: 4648
diff changeset
413 addr=g_malloc(addrlen);
9ce3c698ff5e [gaim-migrate @ 4989]
Nathan Walp <nwalp@pidgin.im>
parents: 4648
diff changeset
414 rc=read(req->fd_out, addr, addrlen);
9ce3c698ff5e [gaim-migrate @ 4989]
Nathan Walp <nwalp@pidgin.im>
parents: 4648
diff changeset
415 hosts = g_slist_append(hosts, GINT_TO_POINTER(addrlen));
9ce3c698ff5e [gaim-migrate @ 4989]
Nathan Walp <nwalp@pidgin.im>
parents: 4648
diff changeset
416 hosts = g_slist_append(hosts, addr);
9ce3c698ff5e [gaim-migrate @ 4989]
Nathan Walp <nwalp@pidgin.im>
parents: 4648
diff changeset
417 } else {
9ce3c698ff5e [gaim-migrate @ 4989]
Nathan Walp <nwalp@pidgin.im>
parents: 4648
diff changeset
418 break;
9ce3c698ff5e [gaim-migrate @ 4989]
Nathan Walp <nwalp@pidgin.im>
parents: 4648
diff changeset
419 }
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
420 }
4678
9ce3c698ff5e [gaim-migrate @ 4989]
Nathan Walp <nwalp@pidgin.im>
parents: 4648
diff changeset
421 } else if(rc==-1) {
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
422 char message[1024];
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
423 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
424 gaim_debug(GAIM_DEBUG_ERROR, "dns", "%s\n", message);
4678
9ce3c698ff5e [gaim-migrate @ 4989]
Nathan Walp <nwalp@pidgin.im>
parents: 4648
diff changeset
425 req->callback(NULL, req->data, message);
4434
6b83a532eeb2 [gaim-migrate @ 4709]
Nathan Walp <nwalp@pidgin.im>
parents: 4394
diff changeset
426 req_free(req);
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
427 return;
4678
9ce3c698ff5e [gaim-migrate @ 4989]
Nathan Walp <nwalp@pidgin.im>
parents: 4648
diff changeset
428 } else if(rc==0) {
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
429 char message[1024];
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
430 g_snprintf(message, sizeof(message), "EOF reading from DNS child");
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
431 close(req->fd_out);
5211
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
432 gaim_debug(GAIM_DEBUG_ERROR, "dns", "%s\n", message);
4678
9ce3c698ff5e [gaim-migrate @ 4989]
Nathan Walp <nwalp@pidgin.im>
parents: 4648
diff changeset
433 req->callback(NULL, req->data, message);
4434
6b83a532eeb2 [gaim-migrate @ 4709]
Nathan Walp <nwalp@pidgin.im>
parents: 4394
diff changeset
434 req_free(req);
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
435 return;
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
436 }
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
437
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
438 /* wait4(req->dns_pid, NULL, WNOHANG, NULL); */
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
439
4678
9ce3c698ff5e [gaim-migrate @ 4989]
Nathan Walp <nwalp@pidgin.im>
parents: 4648
diff changeset
440 req->callback(hosts, req->data, NULL);
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
441
4678
9ce3c698ff5e [gaim-migrate @ 4989]
Nathan Walp <nwalp@pidgin.im>
parents: 4648
diff changeset
442 while(hosts) {
9ce3c698ff5e [gaim-migrate @ 4989]
Nathan Walp <nwalp@pidgin.im>
parents: 4648
diff changeset
443 hosts = g_slist_remove(hosts, hosts->data);
9ce3c698ff5e [gaim-migrate @ 4989]
Nathan Walp <nwalp@pidgin.im>
parents: 4648
diff changeset
444 g_free(hosts->data);
9ce3c698ff5e [gaim-migrate @ 4989]
Nathan Walp <nwalp@pidgin.im>
parents: 4648
diff changeset
445 hosts = g_slist_remove(hosts, hosts->data);
9ce3c698ff5e [gaim-migrate @ 4989]
Nathan Walp <nwalp@pidgin.im>
parents: 4648
diff changeset
446 }
9ce3c698ff5e [gaim-migrate @ 4989]
Nathan Walp <nwalp@pidgin.im>
parents: 4648
diff changeset
447
9ce3c698ff5e [gaim-migrate @ 4989]
Nathan Walp <nwalp@pidgin.im>
parents: 4648
diff changeset
448 release_dns_child(req);
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
449 }
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
450
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
451 static void trap_gdb_bug()
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
452 {
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
453 const char *message =
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
454 "Gaim's DNS child got a SIGTRAP signal. \n"
5435
a2f26666de42 [gaim-migrate @ 5817]
Mark Doliner <mark@kingant.net>
parents: 5426
diff changeset
455 "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
456 "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
457 "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
458 "check cope_with_gdb_brokenness() in proxy.c.\n\n"
5435
a2f26666de42 [gaim-migrate @ 5817]
Mark Doliner <mark@kingant.net>
parents: 5426
diff changeset
459 "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
460 fputs("\n* * *\n",stderr);
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
461 fputs(message,stderr);
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
462 fputs("* * *\n\n",stderr);
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
463 execlp("xmessage","xmessage","-center", message, NULL);
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
464 _exit(1);
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
465 }
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 static void cope_with_gdb_brokenness()
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
468 {
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
469 static gboolean already_done = FALSE;
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
470 char s[300], e[300];
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
471 int n;
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
472 pid_t ppid;
2911
4790fb1272a1 [gaim-migrate @ 2924]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2907
diff changeset
473
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
474 #ifdef __linux__
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
475 if(already_done)
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
476 return;
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
477 already_done = TRUE;
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
478 ppid = getppid();
5435
a2f26666de42 [gaim-migrate @ 5817]
Mark Doliner <mark@kingant.net>
parents: 5426
diff changeset
479 snprintf(s, 300, "/proc/%d/exe", ppid);
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
480 n = readlink(s, e, sizeof(e));
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
481 e[MAX(n,sizeof(e)-1)] = '\0';
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
482
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
483 if(strstr(e,"gdb")) {
5211
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
484 gaim_debug(GAIM_DEBUG_INFO, "dns",
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
485 "Debugger detected, performing useless query...\n");
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
486 gethostbyname("x.x.x.x.x");
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
487 }
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
488 #endif
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
489 }
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
490
4434
6b83a532eeb2 [gaim-migrate @ 4709]
Nathan Walp <nwalp@pidgin.im>
parents: 4394
diff changeset
491 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
492 {
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
493 pending_dns_request_t *req = NULL;
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
494 dns_params_t dns_params;
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
495
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
496 strncpy(dns_params.hostname, hostname, sizeof(dns_params.hostname)-1);
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
497 dns_params.hostname[sizeof(dns_params.hostname)-1] = '\0';
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
498 dns_params.port = port;
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
499
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
500 /* Is there a free available child? */
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
501 while(free_dns_children && !req) {
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
502 GSList *l = free_dns_children;
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
503 free_dns_children = g_slist_remove_link(free_dns_children, l);
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
504 req = l->data;
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
505 g_slist_free(l);
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
506
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
507 if(send_dns_request_to_child(req, &dns_params) != 0) {
4434
6b83a532eeb2 [gaim-migrate @ 4709]
Nathan Walp <nwalp@pidgin.im>
parents: 4394
diff changeset
508 req_free(req);
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
509 req = NULL;
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
510 continue;
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
511 }
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
512
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
513 }
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
514
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
515 if(!req) {
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
516 int child_out[2], child_in[2];
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
517
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
518 if(number_of_dns_children >= MAX_DNS_CHILDREN) {
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
519 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
520 memcpy(&(r->params), &dns_params, sizeof(dns_params));
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
521 r->callback = callback;
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
522 r->data = data;
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
523 if(!queued_requests)
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
524 queued_requests = g_queue_new();
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
525 g_queue_push_tail(queued_requests, r);
5211
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
526
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
527 gaim_debug(GAIM_DEBUG_INFO, "dns",
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
528 "DNS query for '%s' queued\n", hostname);
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
529
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
530 return 0;
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
531 }
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
532
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
533 if(pipe(child_out) || pipe(child_in)) {
5211
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
534 gaim_debug(GAIM_DEBUG_ERROR, "dns",
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
535 "Could not create pipes: %s\n", strerror(errno));
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
536 return -1;
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
537 }
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
538
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
539 /* We need to create a new child. */
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
540 req = g_new(pending_dns_request_t,1);
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
541
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
542 cope_with_gdb_brokenness();
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
543
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
544 req->dns_pid=fork();
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
545 if(req->dns_pid==0) {
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
546 const int zero = 0;
4394
3fa2941a5323 [gaim-migrate @ 4660]
Luke Schierer <lschiere@pidgin.im>
parents: 4367
diff changeset
547 int rc;
3fa2941a5323 [gaim-migrate @ 4660]
Luke Schierer <lschiere@pidgin.im>
parents: 4367
diff changeset
548
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
549 #ifdef HAVE_GETADDRINFO
4678
9ce3c698ff5e [gaim-migrate @ 4989]
Nathan Walp <nwalp@pidgin.im>
parents: 4648
diff changeset
550 struct addrinfo hints, *res, *tmp;
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
551 char servname[20];
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
552 #else
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
553 struct sockaddr_in sin;
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
554 const socklen_t addrlen = sizeof(sin);
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
555 #endif
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
556 #ifdef HAVE_SIGNAL_H
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
557 signal(SIGHUP, SIG_DFL);
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
558 signal(SIGINT, SIG_DFL);
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
559 signal(SIGQUIT, SIG_DFL);
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
560 signal(SIGCHLD, SIG_DFL);
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
561 signal(SIGTERM, SIG_DFL);
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
562 signal(SIGTRAP, trap_gdb_bug);
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
563 #endif
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
564
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
565
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
566 close(child_out[0]);
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
567 close(child_in[1]);
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
568
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
569 while(1) {
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
570 if(dns_params.hostname[0] == '\0') {
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
571 const char Y = 'Y';
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
572 fd_set fds;
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
573 struct timeval tv = { .tv_sec = 40 , .tv_usec = 0 };
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
574 FD_ZERO(&fds);
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
575 FD_SET(child_in[0], &fds);
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
576 rc = select(child_in[0]+1, &fds, NULL, NULL, &tv);
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
577 if(!rc) {
5872
059d95c67cda [gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents: 5681
diff changeset
578 if (opt_debug)
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
579 fprintf(stderr,"dns[%d]: nobody needs me... =(\n", getpid());
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
580 break;
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
581 }
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
582 rc = read(child_in[0], &dns_params, sizeof(dns_params));
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
583 if(rc < 0) {
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
584 perror("read()");
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
585 break;
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
586 }
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
587 if(rc==0) {
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
588 if(opt_debug)
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
589 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
590 _exit(0);
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
591 }
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
592 if(dns_params.hostname[0] == '\0') {
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
593 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
594 _exit(1);
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
595 }
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
596 write(child_out[1], &Y, 1);
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
597 }
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
598
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
599 #ifdef HAVE_GETADDRINFO
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
600 g_snprintf(servname, sizeof(servname), "%d", dns_params.port);
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
601 memset(&hints,0,sizeof(hints));
4434
6b83a532eeb2 [gaim-migrate @ 4709]
Nathan Walp <nwalp@pidgin.im>
parents: 4394
diff changeset
602
6b83a532eeb2 [gaim-migrate @ 4709]
Nathan Walp <nwalp@pidgin.im>
parents: 4394
diff changeset
603 /* This is only used to convert a service
6b83a532eeb2 [gaim-migrate @ 4709]
Nathan Walp <nwalp@pidgin.im>
parents: 4394
diff changeset
604 * name to a port number. As we know we are
6b83a532eeb2 [gaim-migrate @ 4709]
Nathan Walp <nwalp@pidgin.im>
parents: 4394
diff changeset
605 * passing a number already, we know this
6b83a532eeb2 [gaim-migrate @ 4709]
Nathan Walp <nwalp@pidgin.im>
parents: 4394
diff changeset
606 * value will not be really used by the C
6b83a532eeb2 [gaim-migrate @ 4709]
Nathan Walp <nwalp@pidgin.im>
parents: 4394
diff changeset
607 * library.
6b83a532eeb2 [gaim-migrate @ 4709]
Nathan Walp <nwalp@pidgin.im>
parents: 4394
diff changeset
608 */
6b83a532eeb2 [gaim-migrate @ 4709]
Nathan Walp <nwalp@pidgin.im>
parents: 4394
diff changeset
609 hints.ai_socktype = SOCK_STREAM;
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
610 rc = getaddrinfo(dns_params.hostname, servname, &hints, &res);
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
611 if(rc) {
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
612 write(child_out[1], &rc, sizeof(int));
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
613 close(child_out[1]);
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
614 if(opt_debug)
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
615 fprintf(stderr,"dns[%d] Error: getaddrinfo returned %d\n",
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
616 getpid(), rc);
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
617 dns_params.hostname[0] = '\0';
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
618 continue;
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
619 }
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
620 write(child_out[1], &zero, sizeof(zero));
4679
5b372a95b9a8 [gaim-migrate @ 4990]
Nathan Walp <nwalp@pidgin.im>
parents: 4678
diff changeset
621 tmp = res;
4678
9ce3c698ff5e [gaim-migrate @ 4989]
Nathan Walp <nwalp@pidgin.im>
parents: 4648
diff changeset
622 while(res) {
9ce3c698ff5e [gaim-migrate @ 4989]
Nathan Walp <nwalp@pidgin.im>
parents: 4648
diff changeset
623 write(child_out[1], &(res->ai_addrlen), sizeof(res->ai_addrlen));
9ce3c698ff5e [gaim-migrate @ 4989]
Nathan Walp <nwalp@pidgin.im>
parents: 4648
diff changeset
624 write(child_out[1], res->ai_addr, res->ai_addrlen);
9ce3c698ff5e [gaim-migrate @ 4989]
Nathan Walp <nwalp@pidgin.im>
parents: 4648
diff changeset
625 res = res->ai_next;
9ce3c698ff5e [gaim-migrate @ 4989]
Nathan Walp <nwalp@pidgin.im>
parents: 4648
diff changeset
626 }
4679
5b372a95b9a8 [gaim-migrate @ 4990]
Nathan Walp <nwalp@pidgin.im>
parents: 4678
diff changeset
627 freeaddrinfo(tmp);
4678
9ce3c698ff5e [gaim-migrate @ 4989]
Nathan Walp <nwalp@pidgin.im>
parents: 4648
diff changeset
628 write(child_out[1], &zero, sizeof(zero));
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
629 #else
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
630 if (!inet_aton(hostname, &sin.sin_addr)) {
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
631 struct hostent *hp;
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
632 if(!(hp = gethostbyname(dns_params.hostname))) {
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
633 write(child_out[1], &h_errno, sizeof(int));
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
634 close(child_out[1]);
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
635 if(opt_debug)
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
636 fprintf(stderr,"DNS Error: %s\n",hstrerror(h_errno));
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
637 _exit(0);
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
638 }
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
639 memset(&sin, 0, sizeof(struct sockaddr_in));
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
640 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
641 sin.sin_family = hp->h_addrtype;
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
642 } else
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
643 sin.sin_family = AF_INET;
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
644 sin.sin_port = htons(dns_params.port);
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
645 write(child_out[1], &zero, sizeof(zero));
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
646 write(child_out[1], &addrlen, sizeof(addrlen));
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
647 write(child_out[1], &sin, addrlen);
4678
9ce3c698ff5e [gaim-migrate @ 4989]
Nathan Walp <nwalp@pidgin.im>
parents: 4648
diff changeset
648 write(child_out[1], &zero, sizeof(zero));
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
649 #endif
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
650 dns_params.hostname[0] = '\0';
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
651 }
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
652 close(child_out[1]);
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
653 close(child_in[0]);
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
654 _exit(0);
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
655 }
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
656 close(child_out[1]);
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
657 close(child_in[0]);
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
658 if(req->dns_pid==-1) {
5211
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
659 gaim_debug(GAIM_DEBUG_ERROR, "dns",
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
660 "Could not create child process for DNS: %s\n",
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
661 strerror(errno));
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
662 g_free(req);
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
663 return -1;
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
664 }
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
665 req->fd_in = child_in[1];
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
666 req->fd_out = child_out[0];
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
667 number_of_dns_children++;
5211
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
668 gaim_debug(GAIM_DEBUG_INFO, "dns",
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
669 "Created new DNS child %d, there are now %d children.\n",
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
670 req->dns_pid, number_of_dns_children);
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
671 }
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
672 req->host=g_strdup(hostname);
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
673 req->port=port;
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
674 req->callback=callback;
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
675 req->data=data;
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
676 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
677 return 0;
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
678 }
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
679 #else
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
680
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
681 typedef struct {
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
682 gpointer data;
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
683 size_t addrlen;
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
684 struct sockaddr *addr;
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
685 dns_callback_t callback;
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
686 } pending_dns_request_t;
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
687
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
688 static gboolean host_resolved(gpointer data)
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
689 {
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
690 pending_dns_request_t *req = (pending_dns_request_t*)data;
4678
9ce3c698ff5e [gaim-migrate @ 4989]
Nathan Walp <nwalp@pidgin.im>
parents: 4648
diff changeset
691 GSList *hosts = NULL;
9ce3c698ff5e [gaim-migrate @ 4989]
Nathan Walp <nwalp@pidgin.im>
parents: 4648
diff changeset
692 hosts = g_slist_append(hosts, GINT_TO_POINTER(req->addrlen));
9ce3c698ff5e [gaim-migrate @ 4989]
Nathan Walp <nwalp@pidgin.im>
parents: 4648
diff changeset
693 hosts = g_slist_append(hosts, req->addr);
9ce3c698ff5e [gaim-migrate @ 4989]
Nathan Walp <nwalp@pidgin.im>
parents: 4648
diff changeset
694 req->callback(hosts, req->data, NULL);
9ce3c698ff5e [gaim-migrate @ 4989]
Nathan Walp <nwalp@pidgin.im>
parents: 4648
diff changeset
695 g_slist_free(hosts);
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
696 g_free(req->addr);
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
697 g_free(req);
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
698 return FALSE;
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
699 }
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
700
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
701 int
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
702 gaim_gethostbyname_async(const char *hostname, int port,
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
703 dns_callback_t callback, gpointer data)
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
704 {
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
705 struct sockaddr_in sin;
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
706 pending_dns_request_t *req;
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
707
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
708 if (!inet_aton(hostname, &sin.sin_addr)) {
2911
4790fb1272a1 [gaim-migrate @ 2924]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2907
diff changeset
709 struct hostent *hp;
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
710 if(!(hp = gethostbyname(hostname))) {
5211
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
711 gaim_debug(GAIM_DEBUG_ERROR, "dns",
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
712 "gaim_gethostbyname(\"%s\", %d) failed: %s\n",
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
713 hostname, port, hstrerror(h_errno));
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
714 return -1;
2911
4790fb1272a1 [gaim-migrate @ 2924]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2907
diff changeset
715 }
4790fb1272a1 [gaim-migrate @ 2924]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2907
diff changeset
716 memset(&sin, 0, sizeof(struct sockaddr_in));
4790fb1272a1 [gaim-migrate @ 2924]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2907
diff changeset
717 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
718 sin.sin_family = hp->h_addrtype;
4790fb1272a1 [gaim-migrate @ 2924]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2907
diff changeset
719 } else
4790fb1272a1 [gaim-migrate @ 2924]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2907
diff changeset
720 sin.sin_family = AF_INET;
4790fb1272a1 [gaim-migrate @ 2924]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2907
diff changeset
721 sin.sin_port = htons(port);
4790fb1272a1 [gaim-migrate @ 2924]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2907
diff changeset
722
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
723 req = g_new(pending_dns_request_t, 1);
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
724 req->addr = (struct sockaddr*) g_memdup(&sin, sizeof(sin));
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
725 req->addrlen = sizeof(sin);
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
726 req->data = data;
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
727 req->callback = callback;
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
728 g_timeout_add(10, host_resolved, req);
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
729 return 0;
2911
4790fb1272a1 [gaim-migrate @ 2924]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2907
diff changeset
730 }
4790fb1272a1 [gaim-migrate @ 2924]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2907
diff changeset
731
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
732 #endif
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
733
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
734 static void
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
735 no_one_calls(gpointer data, gint source, GaimInputCondition cond)
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
736 {
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
737 struct PHB *phb = data;
2048
3366311426df [gaim-migrate @ 2058]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1881
diff changeset
738 unsigned int len;
4648
4bb99cdfd837 [gaim-migrate @ 4959]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 4634
diff changeset
739 int error=0;
4bb99cdfd837 [gaim-migrate @ 4959]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 4634
diff changeset
740 int ret=0;
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", "Connected.\n");
3717
988485669631 [gaim-migrate @ 3850]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 3630
diff changeset
743
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
744 len = sizeof(error);
4648
4bb99cdfd837 [gaim-migrate @ 4959]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 4634
diff changeset
745
4bb99cdfd837 [gaim-migrate @ 4959]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 4634
diff changeset
746 ret = getsockopt(source, SOL_SOCKET, SO_ERROR, &error, &len);
4bb99cdfd837 [gaim-migrate @ 4959]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 4634
diff changeset
747 if (ret < 0 || error != 0) {
5225
0bf1ced10b2b [gaim-migrate @ 5595]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 5218
diff changeset
748 if(ret==0) errno = error;
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
749 close(source);
2090
b66aca8e8dce [gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2048
diff changeset
750 gaim_input_remove(phb->inpa);
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
751
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
752 if (phb->account == NULL ||
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
753 gaim_account_get_connection(phb->account) != NULL) {
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
754
4993
de84c1de2f66 [gaim-migrate @ 5328]
Nathan Walp <nwalp@pidgin.im>
parents: 4679
diff changeset
755 phb->func(phb->data, -1, GAIM_INPUT_READ);
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
756 }
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
757
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
758 g_free(phb->host);
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
759 g_free(phb);
5211
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
760
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
761 gaim_debug(GAIM_DEBUG_ERROR, "proxy",
5225
0bf1ced10b2b [gaim-migrate @ 5595]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 5218
diff changeset
762 "getsockopt SO_ERROR check: %s\n", strerror(errno));
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
763 return;
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
764 }
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
765
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
766 fcntl(source, F_SETFL, 0);
2090
b66aca8e8dce [gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2048
diff changeset
767 gaim_input_remove(phb->inpa);
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
768
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
769 if (phb->account == NULL ||
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
770 gaim_account_get_connection(phb->account) != NULL) {
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
771
4993
de84c1de2f66 [gaim-migrate @ 5328]
Nathan Walp <nwalp@pidgin.im>
parents: 4679
diff changeset
772 phb->func(phb->data, source, GAIM_INPUT_READ);
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
773 }
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
774
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
775 g_free(phb->host);
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
776 g_free(phb);
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
777 }
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
778
1868
a49ed23b3c02 [gaim-migrate @ 1878]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1844
diff changeset
779 static gboolean clean_connect(gpointer data)
a49ed23b3c02 [gaim-migrate @ 1878]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1844
diff changeset
780 {
a49ed23b3c02 [gaim-migrate @ 1878]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1844
diff changeset
781 struct PHB *phb = data;
a49ed23b3c02 [gaim-migrate @ 1878]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1844
diff changeset
782
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
783 if (phb->account == NULL ||
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
784 gaim_account_get_connection(phb->account) != NULL) {
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
785
4993
de84c1de2f66 [gaim-migrate @ 5328]
Nathan Walp <nwalp@pidgin.im>
parents: 4679
diff changeset
786 phb->func(phb->data, phb->port, GAIM_INPUT_READ);
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
787 }
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
788
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
789 g_free(phb->host);
1868
a49ed23b3c02 [gaim-migrate @ 1878]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1844
diff changeset
790 g_free(phb);
a49ed23b3c02 [gaim-migrate @ 1878]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1844
diff changeset
791
a49ed23b3c02 [gaim-migrate @ 1878]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1844
diff changeset
792 return FALSE;
a49ed23b3c02 [gaim-migrate @ 1878]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1844
diff changeset
793 }
a49ed23b3c02 [gaim-migrate @ 1878]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1844
diff changeset
794
a49ed23b3c02 [gaim-migrate @ 1878]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1844
diff changeset
795
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
796 static int
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
797 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
798 {
1087
56c7ceb986a8 [gaim-migrate @ 1097]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1057
diff changeset
799 int fd = -1;
3717
988485669631 [gaim-migrate @ 3850]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 3630
diff changeset
800
5211
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
801 gaim_debug(GAIM_DEBUG_INFO, "proxy",
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
802 "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
803
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
804 if ((fd = socket(addr->sa_family, SOCK_STREAM, 0)) < 0) {
5211
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
805 gaim_debug(GAIM_DEBUG_ERROR, "proxy",
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
806 "Unable to create socket: %s\n", strerror(errno));
1087
56c7ceb986a8 [gaim-migrate @ 1097]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1057
diff changeset
807 return -1;
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
808 }
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
809 fcntl(fd, F_SETFL, O_NONBLOCK);
3717
988485669631 [gaim-migrate @ 3850]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 3630
diff changeset
810
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
811 if (connect(fd, (struct sockaddr *)addr, addrlen) < 0) {
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
812 if ((errno == EINPROGRESS) || (errno == EINTR)) {
5211
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
813 gaim_debug(GAIM_DEBUG_WARNING, "proxy",
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
814 "Connect would have blocked.\n");
2090
b66aca8e8dce [gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2048
diff changeset
815 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
816 }
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
817 else {
5211
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
818 gaim_debug(GAIM_DEBUG_ERROR, "proxy",
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
819 "Connect failed (errno %d)\n", errno);
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
820 close(fd);
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
821 return -1;
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
822 }
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
823 }
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
824 else {
2048
3366311426df [gaim-migrate @ 2058]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1881
diff changeset
825 unsigned int len;
3366311426df [gaim-migrate @ 2058]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1881
diff changeset
826 int error = ETIMEDOUT;
5211
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
827 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
828 len = sizeof(error);
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
829 if (getsockopt(fd, SOL_SOCKET, SO_ERROR, &error, &len) < 0) {
5211
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
830 gaim_debug(GAIM_DEBUG_ERROR, "proxy", "getsockopt failed.\n");
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
831 close(fd);
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
832 return -1;
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
833 }
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
834 fcntl(fd, F_SETFL, 0);
2372
2927c2c26fe6 [gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2306
diff changeset
835 phb->port = fd; /* bleh */
2927c2c26fe6 [gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2306
diff changeset
836 g_timeout_add(50, clean_connect, phb); /* we do this because we never
2927c2c26fe6 [gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2306
diff changeset
837 want to call our callback
2927c2c26fe6 [gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2306
diff changeset
838 before we return. */
1087
56c7ceb986a8 [gaim-migrate @ 1097]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1057
diff changeset
839 }
56c7ceb986a8 [gaim-migrate @ 1097]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1057
diff changeset
840
56c7ceb986a8 [gaim-migrate @ 1097]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1057
diff changeset
841 return fd;
56c7ceb986a8 [gaim-migrate @ 1097]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1057
diff changeset
842 }
56c7ceb986a8 [gaim-migrate @ 1097]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1057
diff changeset
843
3376
8d0fa912ecaf [gaim-migrate @ 3395]
Sean Egan <seanegan@gmail.com>
parents: 3283
diff changeset
844 #define HTTP_GOODSTRING "HTTP/1.0 200"
8d0fa912ecaf [gaim-migrate @ 3395]
Sean Egan <seanegan@gmail.com>
parents: 3283
diff changeset
845 #define HTTP_GOODSTRING2 "HTTP/1.1 200"
1087
56c7ceb986a8 [gaim-migrate @ 1097]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1057
diff changeset
846
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
847 static void
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
848 http_canread(gpointer data, gint source, GaimInputCondition cond)
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
849 {
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
850 int nlc = 0;
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
851 int pos = 0;
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
852 int minor, major, status, error=0;
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
853 struct PHB *phb = data;
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
854 char inputline[8192], *p;
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
855
2090
b66aca8e8dce [gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2048
diff changeset
856 gaim_input_remove(phb->inpa);
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
857
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
858 while ((nlc != 2) && (read(source, &inputline[pos++], 1) == 1)) {
2372
2927c2c26fe6 [gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2306
diff changeset
859 if (inputline[pos - 1] == '\n')
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
860 nlc++;
2372
2927c2c26fe6 [gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2306
diff changeset
861 else if (inputline[pos - 1] != '\r')
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
862 nlc = 0;
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
863 }
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
864 inputline[pos] = '\0';
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
865
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
866 error = strncmp(inputline, "HTTP/", 5) != 0;
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
867 if(!error) {
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
868 p = inputline + 5;
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
869 major = strtol(p, &p, 10);
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
870 error = (major==0) || (*p != '.');
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
871 if(!error) {
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
872 p++;
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
873 minor = strtol(p, &p, 10);
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
874 error = (*p!=' ');
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
875 if(!error) {
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
876 p++;
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
877 status = strtol(p, &p, 10);
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
878 error = (*p!=' ');
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
879 }
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
880 }
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
881 }
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
882
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
883 if(error) {
5211
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
884 gaim_debug(GAIM_DEBUG_ERROR, "proxy",
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
885 "Unable to parse proxy's response: %s\n", inputline);
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
886 close(source);
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
887 source=-1;
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
888 }
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
889 else if(status!=200) {
5211
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
890 gaim_debug(GAIM_DEBUG_ERROR, "proxy",
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
891 "Proxy server replied: (%s)\n", p);
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
892 close(source);
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
893 source=-1;
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
894 }
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
895
4993
de84c1de2f66 [gaim-migrate @ 5328]
Nathan Walp <nwalp@pidgin.im>
parents: 4679
diff changeset
896 if(!phb->account || phb->account->gc)
de84c1de2f66 [gaim-migrate @ 5328]
Nathan Walp <nwalp@pidgin.im>
parents: 4679
diff changeset
897 phb->func(phb->data, source, GAIM_INPUT_READ);
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
898 g_free(phb->host);
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
899 g_free(phb);
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
900 return;
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
901 }
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
902
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
903 static void
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
904 http_canwrite(gpointer data, gint source, GaimInputCondition cond)
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
905 {
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
906 char request[8192];
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
907 int request_len = 0;
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
908 struct PHB *phb = data;
2048
3366311426df [gaim-migrate @ 2058]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1881
diff changeset
909 unsigned int len;
3366311426df [gaim-migrate @ 2058]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1881
diff changeset
910 int error = ETIMEDOUT;
3717
988485669631 [gaim-migrate @ 3850]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 3630
diff changeset
911
5211
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
912 gaim_debug(GAIM_DEBUG_INFO, "http proxy", "Connected.\n");
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
913
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
914 if (phb->inpa > 0)
2090
b66aca8e8dce [gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2048
diff changeset
915 gaim_input_remove(phb->inpa);
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
916
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
917 len = sizeof(error);
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
918
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
919 if (getsockopt(source, SOL_SOCKET, SO_ERROR, &error, &len) < 0) {
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
920 close(source);
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
921
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
922 if (phb->account == NULL ||
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
923 gaim_account_get_connection(phb->account) != NULL) {
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
924
4993
de84c1de2f66 [gaim-migrate @ 5328]
Nathan Walp <nwalp@pidgin.im>
parents: 4679
diff changeset
925 phb->func(phb->data, -1, GAIM_INPUT_READ);
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
926 }
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
927
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
928 g_free(phb->host);
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
929 g_free(phb);
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
930 return;
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
931 }
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
932 request_len = g_snprintf(request, sizeof(request),
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
933 "CONNECT %s:%d HTTP/1.1\r\nHost: %s:%d\r\n",
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
934 phb->host, phb->port, phb->host, phb->port);
1843
4dbd8533d209 [gaim-migrate @ 1853]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1840
diff changeset
935
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
936 if (gaim_proxy_info_get_username(phb->gpi) != NULL) {
1843
4dbd8533d209 [gaim-migrate @ 1853]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1840
diff changeset
937 char *t1, *t2;
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
938 t1 = g_strdup_printf("%s:%s",
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
939 gaim_proxy_info_get_username(phb->gpi),
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
940 gaim_proxy_info_get_password(phb->gpi));
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
941
5532
6f35b80c5ffa [gaim-migrate @ 5932]
Luke Schierer <lschiere@pidgin.im>
parents: 5435
diff changeset
942 t2 = tobase64(t1, strlen(t1));
1843
4dbd8533d209 [gaim-migrate @ 1853]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1840
diff changeset
943 g_free(t1);
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
944 g_return_if_fail(request_len < sizeof(request));
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
945 request_len += g_snprintf(request + request_len,
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
946 sizeof(request) - request_len,
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
947 "Proxy-Authorization: Basic %s\r\n", t2);
1843
4dbd8533d209 [gaim-migrate @ 1853]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1840
diff changeset
948 g_free(t2);
4dbd8533d209 [gaim-migrate @ 1853]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1840
diff changeset
949 }
4dbd8533d209 [gaim-migrate @ 1853]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1840
diff changeset
950
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
951 g_return_if_fail(request_len < sizeof(request));
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
952 strcpy(request + request_len, "\r\n");
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
953 request_len += 2;
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
954
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
955 if (write(source, request, request_len) < 0) {
1843
4dbd8533d209 [gaim-migrate @ 1853]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1840
diff changeset
956 close(source);
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
957
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
958 if (phb->account == NULL ||
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
959 gaim_account_get_connection(phb->account) != NULL) {
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
960
4993
de84c1de2f66 [gaim-migrate @ 5328]
Nathan Walp <nwalp@pidgin.im>
parents: 4679
diff changeset
961 phb->func(phb->data, -1, GAIM_INPUT_READ);
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
962 }
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
963
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
964 g_free(phb->host);
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
965 g_free(phb);
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
966 return;
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
967 }
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
968
2090
b66aca8e8dce [gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2048
diff changeset
969 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
970 }
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
971
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
972 static int
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
973 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
974 {
56c7ceb986a8 [gaim-migrate @ 1097]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1057
diff changeset
975 int fd = -1;
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
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",
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
978 "Connecting to %s:%d via %s:%d using HTTP\n",
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
979 phb->host, phb->port,
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
980 gaim_proxy_info_get_host(phb->gpi),
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
981 gaim_proxy_info_get_port(phb->gpi));
1087
56c7ceb986a8 [gaim-migrate @ 1097]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1057
diff changeset
982
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
983 if ((fd = socket(addr->sa_family, SOCK_STREAM, 0)) < 0) {
1087
56c7ceb986a8 [gaim-migrate @ 1097]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1057
diff changeset
984 return -1;
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
985 }
1087
56c7ceb986a8 [gaim-migrate @ 1097]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1057
diff changeset
986
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
987 fcntl(fd, F_SETFL, O_NONBLOCK);
3717
988485669631 [gaim-migrate @ 3850]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 3630
diff changeset
988
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
989 if (connect(fd, addr, addrlen) < 0) {
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
990 if ((errno == EINPROGRESS) || (errno == EINTR)) {
5211
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
991 gaim_debug(GAIM_DEBUG_WARNING, "http proxy",
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
992 "Connect would have blocked.\n");
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
993 phb->inpa = gaim_input_add(fd, GAIM_INPUT_WRITE,
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
994 http_canwrite, phb);
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
995 } else {
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
996 close(fd);
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
997 return -1;
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
998 }
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
999 }
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1000 else {
2048
3366311426df [gaim-migrate @ 2058]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1881
diff changeset
1001 unsigned int len;
3366311426df [gaim-migrate @ 2058]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1881
diff changeset
1002 int error = ETIMEDOUT;
3717
988485669631 [gaim-migrate @ 3850]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 3630
diff changeset
1003
5211
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
1004 gaim_debug(GAIM_DEBUG_MISC, "http proxy",
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
1005 "Connect didn't block.\n");
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
1006
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1007 len = sizeof(error);
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1008 if (getsockopt(fd, SOL_SOCKET, SO_ERROR, &error, &len) < 0) {
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1009 close(fd);
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1010 return -1;
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1011 }
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1012 fcntl(fd, F_SETFL, 0);
2090
b66aca8e8dce [gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2048
diff changeset
1013 http_canwrite(phb, fd, GAIM_INPUT_WRITE);
1695
c0ab844d4790 [gaim-migrate @ 1705]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1451
diff changeset
1014 }
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1015
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1016 return fd;
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1017 }
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1018
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1019 static void
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1020 s4_canread(gpointer data, gint source, GaimInputCondition cond)
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1021 {
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1022 unsigned char packet[12];
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1023 struct PHB *phb = data;
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1024
2090
b66aca8e8dce [gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2048
diff changeset
1025 gaim_input_remove(phb->inpa);
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1026
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1027 memset(packet, 0, sizeof(packet));
3717
988485669631 [gaim-migrate @ 3850]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 3630
diff changeset
1028
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1029 if (read(source, packet, 9) >= 4 && packet[1] == 90) {
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1030 if (phb->account == NULL ||
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1031 gaim_account_get_connection(phb->account) != NULL) {
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1032
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1033 phb->func(phb->data, -1, GAIM_INPUT_READ);
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1034 }
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1035
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1036 g_free(phb->host);
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1037 g_free(phb);
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1038 return;
1695
c0ab844d4790 [gaim-migrate @ 1705]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1451
diff changeset
1039 }
1087
56c7ceb986a8 [gaim-migrate @ 1097]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1057
diff changeset
1040
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1041 close(source);
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1042
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1043 if (phb->account == NULL ||
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1044 gaim_account_get_connection(phb->account) != NULL) {
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1045
4993
de84c1de2f66 [gaim-migrate @ 5328]
Nathan Walp <nwalp@pidgin.im>
parents: 4679
diff changeset
1046 phb->func(phb->data, -1, GAIM_INPUT_READ);
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1047 }
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1048
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1049 g_free(phb->host);
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1050 g_free(phb);
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1051 }
1705
b4d454e5ee31 [gaim-migrate @ 1715]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1695
diff changeset
1052
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1053 static void
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1054 s4_canwrite(gpointer data, gint source, GaimInputCondition cond)
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1055 {
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1056 unsigned char packet[12];
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1057 struct hostent *hp;
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1058 struct PHB *phb = data;
2048
3366311426df [gaim-migrate @ 2058]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1881
diff changeset
1059 unsigned int len;
3366311426df [gaim-migrate @ 2058]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1881
diff changeset
1060 int error = ETIMEDOUT;
3717
988485669631 [gaim-migrate @ 3850]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 3630
diff changeset
1061
5211
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
1062 gaim_debug(GAIM_DEBUG_INFO, "s4 proxy", "Connected.\n");
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
1063
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1064 if (phb->inpa > 0)
2090
b66aca8e8dce [gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2048
diff changeset
1065 gaim_input_remove(phb->inpa);
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1066
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1067 len = sizeof(error);
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1068
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1069 if (getsockopt(source, SOL_SOCKET, SO_ERROR, &error, &len) < 0) {
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1070 close(source);
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1071
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1072 if (phb->account == NULL ||
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1073 gaim_account_get_connection(phb->account) != NULL) {
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1074
4993
de84c1de2f66 [gaim-migrate @ 5328]
Nathan Walp <nwalp@pidgin.im>
parents: 4679
diff changeset
1075 phb->func(phb->data, -1, GAIM_INPUT_READ);
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1076 }
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1077
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1078 g_free(phb->host);
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1079 g_free(phb);
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1080 return;
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1081 }
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1082 fcntl(source, F_SETFL, 0);
3717
988485669631 [gaim-migrate @ 3850]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 3630
diff changeset
1083
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1084 /* XXX does socks4 not support host name lookups by the proxy? */
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1085 if (!(hp = gethostbyname(phb->host))) {
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1086 close(source);
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1087
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1088 if (phb->account == NULL ||
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1089 gaim_account_get_connection(phb->account) != NULL) {
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1090
4993
de84c1de2f66 [gaim-migrate @ 5328]
Nathan Walp <nwalp@pidgin.im>
parents: 4679
diff changeset
1091 phb->func(phb->data, -1, GAIM_INPUT_READ);
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1092 }
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1093
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1094 g_free(phb->host);
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1095 g_free(phb);
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1096 return;
1087
56c7ceb986a8 [gaim-migrate @ 1097]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1057
diff changeset
1097 }
56c7ceb986a8 [gaim-migrate @ 1097]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1057
diff changeset
1098
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1099 packet[0] = 4;
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1100 packet[1] = 1;
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1101 packet[2] = phb->port >> 8;
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1102 packet[3] = phb->port & 0xff;
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1103 packet[4] = (unsigned char)(hp->h_addr_list[0])[0];
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1104 packet[5] = (unsigned char)(hp->h_addr_list[0])[1];
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1105 packet[6] = (unsigned char)(hp->h_addr_list[0])[2];
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1106 packet[7] = (unsigned char)(hp->h_addr_list[0])[3];
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1107 packet[8] = 0;
3717
988485669631 [gaim-migrate @ 3850]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 3630
diff changeset
1108
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1109 if (write(source, packet, 9) != 9) {
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1110 close(source);
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1111
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1112 if (phb->account == NULL ||
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1113 gaim_account_get_connection(phb->account) != NULL) {
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1114
4993
de84c1de2f66 [gaim-migrate @ 5328]
Nathan Walp <nwalp@pidgin.im>
parents: 4679
diff changeset
1115 phb->func(phb->data, -1, GAIM_INPUT_READ);
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
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1118 g_free(phb->host);
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1119 g_free(phb);
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1120 return;
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1121 }
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1122
2090
b66aca8e8dce [gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2048
diff changeset
1123 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
1124 }
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
1125
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1126 static int
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1127 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
1128 {
1087
56c7ceb986a8 [gaim-migrate @ 1097]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1057
diff changeset
1129 int fd = -1;
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
1130
5211
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
1131 gaim_debug(GAIM_DEBUG_INFO, "socks4 proxy",
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
1132 "Connecting to %s:%d via %s:%d using SOCKS4\n",
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1133 phb->host, phb->port,
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1134 gaim_proxy_info_get_host(phb->gpi),
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1135 gaim_proxy_info_get_port(phb->gpi));
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
1136
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1137 if ((fd = socket(addr->sa_family, SOCK_STREAM, 0)) < 0)
1087
56c7ceb986a8 [gaim-migrate @ 1097]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1057
diff changeset
1138 return -1;
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
1139
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1140 fcntl(fd, F_SETFL, O_NONBLOCK);
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1141
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
1142 if (connect(fd, addr, addrlen) < 0) {
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1143 if ((errno == EINPROGRESS) || (errno == EINTR)) {
5211
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
1144 gaim_debug(GAIM_DEBUG_WARNING, "socks4 proxy",
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
1145 "Connect would have blocked.\n");
2090
b66aca8e8dce [gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2048
diff changeset
1146 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
1147 }
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1148 else {
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1149 close(fd);
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1150 return -1;
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1151 }
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1152 } else {
2048
3366311426df [gaim-migrate @ 2058]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1881
diff changeset
1153 unsigned int len;
3366311426df [gaim-migrate @ 2058]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1881
diff changeset
1154 int error = ETIMEDOUT;
3717
988485669631 [gaim-migrate @ 3850]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 3630
diff changeset
1155
5211
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
1156 gaim_debug(GAIM_DEBUG_MISC, "socks4 proxy",
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
1157 "Connect didn't block.\n");
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
1158
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1159 len = sizeof(error);
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1160
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1161 if (getsockopt(fd, SOL_SOCKET, SO_ERROR, &error, &len) < 0) {
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1162 close(fd);
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1163 return -1;
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1164 }
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1165
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1166 fcntl(fd, F_SETFL, 0);
2090
b66aca8e8dce [gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2048
diff changeset
1167 s4_canwrite(phb, fd, GAIM_INPUT_WRITE);
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1168 }
670
9e51c1a4abba [gaim-migrate @ 680]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 664
diff changeset
1169
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1170 return fd;
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1171 }
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1172
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1173 static void
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1174 s5_canread_again(gpointer data, gint source, GaimInputCondition cond)
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1175 {
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1176 unsigned char buf[512];
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1177 struct PHB *phb = data;
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1178
2090
b66aca8e8dce [gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2048
diff changeset
1179 gaim_input_remove(phb->inpa);
5211
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
1180 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
1181
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1182 if (read(source, buf, 10) < 10) {
5211
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
1183 gaim_debug(GAIM_DEBUG_WARNING, "socks5 proxy", "or not...\n");
1840
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;
1087
56c7ceb986a8 [gaim-migrate @ 1097]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1057
diff changeset
1195 }
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1196 if ((buf[0] != 0x05) || (buf[1] != 0x00)) {
5211
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
1197 gaim_debug(GAIM_DEBUG_ERROR, "socks5 proxy", "Bad data.\n");
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1198 close(source);
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1199
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1200 if (phb->account == NULL ||
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1201 gaim_account_get_connection(phb->account) != NULL) {
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1202
4993
de84c1de2f66 [gaim-migrate @ 5328]
Nathan Walp <nwalp@pidgin.im>
parents: 4679
diff changeset
1203 phb->func(phb->data, -1, GAIM_INPUT_READ);
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1204 }
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1205
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1206 g_free(phb->host);
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1207 g_free(phb);
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1208 return;
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1209 }
670
9e51c1a4abba [gaim-migrate @ 680]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 664
diff changeset
1210
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1211 if (phb->account == NULL ||
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1212 gaim_account_get_connection(phb->account) != NULL) {
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1213
4993
de84c1de2f66 [gaim-migrate @ 5328]
Nathan Walp <nwalp@pidgin.im>
parents: 4679
diff changeset
1214 phb->func(phb->data, source, GAIM_INPUT_READ);
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1215 }
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1216
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1217 g_free(phb->host);
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1218 g_free(phb);
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
1219 }
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
1220
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1221 static void
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1222 s5_sendconnect(gpointer data, gint source)
1087
56c7ceb986a8 [gaim-migrate @ 1097]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1057
diff changeset
1223 {
56c7ceb986a8 [gaim-migrate @ 1097]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1057
diff changeset
1224 unsigned char buf[512];
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1225 struct PHB *phb = data;
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1226 int hlen = strlen(phb->host);
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1227
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1228 buf[0] = 0x05;
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1229 buf[1] = 0x01; /* CONNECT */
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1230 buf[2] = 0x00; /* reserved */
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1231 buf[3] = 0x03; /* address type -- host name */
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1232 buf[4] = hlen;
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1233 memcpy(buf + 5, phb->host, hlen);
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1234 buf[5 + strlen(phb->host)] = phb->port >> 8;
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1235 buf[5 + strlen(phb->host) + 1] = phb->port & 0xff;
1087
56c7ceb986a8 [gaim-migrate @ 1097]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1057
diff changeset
1236
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1237 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
1238 close(source);
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1239
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1240 if (phb->account == NULL ||
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1241 gaim_account_get_connection(phb->account) != NULL) {
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1242
4993
de84c1de2f66 [gaim-migrate @ 5328]
Nathan Walp <nwalp@pidgin.im>
parents: 4679
diff changeset
1243 phb->func(phb->data, -1, GAIM_INPUT_READ);
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1244 }
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1245
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1246 g_free(phb->host);
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1247 g_free(phb);
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1248 return;
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1249 }
1087
56c7ceb986a8 [gaim-migrate @ 1097]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1057
diff changeset
1250
2090
b66aca8e8dce [gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2048
diff changeset
1251 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
1252 }
1087
56c7ceb986a8 [gaim-migrate @ 1097]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1057
diff changeset
1253
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1254 static void
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1255 s5_readauth(gpointer data, gint source, GaimInputCondition cond)
1844
9845deede1e9 [gaim-migrate @ 1854]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1843
diff changeset
1256 {
9845deede1e9 [gaim-migrate @ 1854]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1843
diff changeset
1257 unsigned char buf[512];
9845deede1e9 [gaim-migrate @ 1854]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1843
diff changeset
1258 struct PHB *phb = data;
9845deede1e9 [gaim-migrate @ 1854]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1843
diff changeset
1259
2090
b66aca8e8dce [gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2048
diff changeset
1260 gaim_input_remove(phb->inpa);
5211
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
1261 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
1262
9845deede1e9 [gaim-migrate @ 1854]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1843
diff changeset
1263 if (read(source, buf, 2) < 2) {
9845deede1e9 [gaim-migrate @ 1854]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1843
diff changeset
1264 close(source);
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1265
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1266 if (phb->account == NULL ||
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1267 gaim_account_get_connection(phb->account) != NULL) {
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1268
4993
de84c1de2f66 [gaim-migrate @ 5328]
Nathan Walp <nwalp@pidgin.im>
parents: 4679
diff changeset
1269 phb->func(phb->data, -1, GAIM_INPUT_READ);
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1270 }
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1271
1844
9845deede1e9 [gaim-migrate @ 1854]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1843
diff changeset
1272 g_free(phb->host);
9845deede1e9 [gaim-migrate @ 1854]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1843
diff changeset
1273 g_free(phb);
9845deede1e9 [gaim-migrate @ 1854]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1843
diff changeset
1274 return;
9845deede1e9 [gaim-migrate @ 1854]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1843
diff changeset
1275 }
9845deede1e9 [gaim-migrate @ 1854]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1843
diff changeset
1276
2790
0148422dff4d [gaim-migrate @ 2803]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2754
diff changeset
1277 if ((buf[0] != 0x01) || (buf[1] != 0x00)) {
1844
9845deede1e9 [gaim-migrate @ 1854]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1843
diff changeset
1278 close(source);
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1279
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1280 if (phb->account == NULL ||
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1281 gaim_account_get_connection(phb->account) != NULL) {
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1282
4993
de84c1de2f66 [gaim-migrate @ 5328]
Nathan Walp <nwalp@pidgin.im>
parents: 4679
diff changeset
1283 phb->func(phb->data, -1, GAIM_INPUT_READ);
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1284 }
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1285
1844
9845deede1e9 [gaim-migrate @ 1854]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1843
diff changeset
1286 g_free(phb->host);
9845deede1e9 [gaim-migrate @ 1854]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1843
diff changeset
1287 g_free(phb);
9845deede1e9 [gaim-migrate @ 1854]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1843
diff changeset
1288 return;
9845deede1e9 [gaim-migrate @ 1854]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1843
diff changeset
1289 }
9845deede1e9 [gaim-migrate @ 1854]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1843
diff changeset
1290
9845deede1e9 [gaim-migrate @ 1854]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1843
diff changeset
1291 s5_sendconnect(phb, source);
9845deede1e9 [gaim-migrate @ 1854]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1843
diff changeset
1292 }
9845deede1e9 [gaim-migrate @ 1854]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1843
diff changeset
1293
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1294 static void
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1295 s5_canread(gpointer data, gint source, GaimInputCondition cond)
1844
9845deede1e9 [gaim-migrate @ 1854]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1843
diff changeset
1296 {
9845deede1e9 [gaim-migrate @ 1854]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1843
diff changeset
1297 unsigned char buf[512];
9845deede1e9 [gaim-migrate @ 1854]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1843
diff changeset
1298 struct PHB *phb = data;
9845deede1e9 [gaim-migrate @ 1854]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1843
diff changeset
1299
2090
b66aca8e8dce [gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2048
diff changeset
1300 gaim_input_remove(phb->inpa);
5211
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
1301 gaim_debug(GAIM_DEBUG_INFO, "socks5 proxy", "Able to read.\n");
1844
9845deede1e9 [gaim-migrate @ 1854]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1843
diff changeset
1302
9845deede1e9 [gaim-migrate @ 1854]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1843
diff changeset
1303 if (read(source, buf, 2) < 2) {
9845deede1e9 [gaim-migrate @ 1854]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1843
diff changeset
1304 close(source);
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1305
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1306 if (phb->account == NULL ||
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1307 gaim_account_get_connection(phb->account) != NULL) {
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1308
4993
de84c1de2f66 [gaim-migrate @ 5328]
Nathan Walp <nwalp@pidgin.im>
parents: 4679
diff changeset
1309 phb->func(phb->data, -1, GAIM_INPUT_READ);
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1310 }
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1311
1844
9845deede1e9 [gaim-migrate @ 1854]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1843
diff changeset
1312 g_free(phb->host);
9845deede1e9 [gaim-migrate @ 1854]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1843
diff changeset
1313 g_free(phb);
9845deede1e9 [gaim-migrate @ 1854]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1843
diff changeset
1314 return;
9845deede1e9 [gaim-migrate @ 1854]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1843
diff changeset
1315 }
9845deede1e9 [gaim-migrate @ 1854]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1843
diff changeset
1316
9845deede1e9 [gaim-migrate @ 1854]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1843
diff changeset
1317 if ((buf[0] != 0x05) || (buf[1] == 0xff)) {
9845deede1e9 [gaim-migrate @ 1854]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1843
diff changeset
1318 close(source);
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1319
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1320 if (phb->account == NULL ||
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1321 gaim_account_get_connection(phb->account) != NULL) {
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1322
4993
de84c1de2f66 [gaim-migrate @ 5328]
Nathan Walp <nwalp@pidgin.im>
parents: 4679
diff changeset
1323 phb->func(phb->data, -1, GAIM_INPUT_READ);
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1324 }
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1325
1844
9845deede1e9 [gaim-migrate @ 1854]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1843
diff changeset
1326 g_free(phb->host);
9845deede1e9 [gaim-migrate @ 1854]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1843
diff changeset
1327 g_free(phb);
9845deede1e9 [gaim-migrate @ 1854]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1843
diff changeset
1328 return;
9845deede1e9 [gaim-migrate @ 1854]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1843
diff changeset
1329 }
9845deede1e9 [gaim-migrate @ 1854]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1843
diff changeset
1330
9845deede1e9 [gaim-migrate @ 1854]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1843
diff changeset
1331 if (buf[1] == 0x02) {
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1332 unsigned int i, j;
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1333
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1334 i = strlen(gaim_proxy_info_get_username(phb->gpi));
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1335 j = strlen(gaim_proxy_info_get_password(phb->gpi));
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1336
2372
2927c2c26fe6 [gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2306
diff changeset
1337 buf[0] = 0x01; /* version 1 */
1844
9845deede1e9 [gaim-migrate @ 1854]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1843
diff changeset
1338 buf[1] = i;
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1339 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
1340 buf[2 + i] = j;
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1341 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
1342
2372
2927c2c26fe6 [gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2306
diff changeset
1343 if (write(source, buf, 3 + i + j) < 3 + i + j) {
1844
9845deede1e9 [gaim-migrate @ 1854]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1843
diff changeset
1344 close(source);
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1345
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1346 if (phb->account == NULL ||
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1347 gaim_account_get_connection(phb->account) != NULL) {
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1348
4993
de84c1de2f66 [gaim-migrate @ 5328]
Nathan Walp <nwalp@pidgin.im>
parents: 4679
diff changeset
1349 phb->func(phb->data, -1, GAIM_INPUT_READ);
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1350 }
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1351
1844
9845deede1e9 [gaim-migrate @ 1854]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1843
diff changeset
1352 g_free(phb->host);
9845deede1e9 [gaim-migrate @ 1854]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1843
diff changeset
1353 g_free(phb);
9845deede1e9 [gaim-migrate @ 1854]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1843
diff changeset
1354 return;
9845deede1e9 [gaim-migrate @ 1854]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1843
diff changeset
1355 }
9845deede1e9 [gaim-migrate @ 1854]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1843
diff changeset
1356
2090
b66aca8e8dce [gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2048
diff changeset
1357 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
1358 }
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1359 else {
1844
9845deede1e9 [gaim-migrate @ 1854]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1843
diff changeset
1360 s5_sendconnect(phb, source);
9845deede1e9 [gaim-migrate @ 1854]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1843
diff changeset
1361 }
9845deede1e9 [gaim-migrate @ 1854]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1843
diff changeset
1362 }
9845deede1e9 [gaim-migrate @ 1854]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1843
diff changeset
1363
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1364 static void
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1365 s5_canwrite(gpointer data, gint source, GaimInputCondition cond)
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1366 {
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1367 unsigned char buf[512];
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1368 int i;
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1369 struct PHB *phb = data;
2048
3366311426df [gaim-migrate @ 2058]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1881
diff changeset
1370 unsigned int len;
3366311426df [gaim-migrate @ 2058]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1881
diff changeset
1371 int error = ETIMEDOUT;
3717
988485669631 [gaim-migrate @ 3850]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 3630
diff changeset
1372
5872
059d95c67cda [gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents: 5681
diff changeset
1373 gaim_debug(GAIM_DEBUG_INFO, "socks5 proxy", "Connected.\n");
5211
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
1374
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1375 if (phb->inpa > 0)
2090
b66aca8e8dce [gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2048
diff changeset
1376 gaim_input_remove(phb->inpa);
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1377
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1378 len = sizeof(error);
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1379 if (getsockopt(source, SOL_SOCKET, SO_ERROR, &error, &len) < 0) {
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1380 close(source);
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1381 if (phb->account == NULL ||
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1382 gaim_account_get_connection(phb->account) != NULL) {
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1383
4993
de84c1de2f66 [gaim-migrate @ 5328]
Nathan Walp <nwalp@pidgin.im>
parents: 4679
diff changeset
1384 phb->func(phb->data, -1, GAIM_INPUT_READ);
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1385 }
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1386
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1387 g_free(phb->host);
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1388 g_free(phb);
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1389 return;
1087
56c7ceb986a8 [gaim-migrate @ 1097]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1057
diff changeset
1390 }
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1391 fcntl(source, F_SETFL, 0);
1087
56c7ceb986a8 [gaim-migrate @ 1097]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1057
diff changeset
1392
56c7ceb986a8 [gaim-migrate @ 1097]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1057
diff changeset
1393 i = 0;
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1087
diff changeset
1394 buf[0] = 0x05; /* SOCKS version 5 */
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1395
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1396 if (gaim_proxy_info_get_username(phb->gpi) != NULL) {
1844
9845deede1e9 [gaim-migrate @ 1854]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1843
diff changeset
1397 buf[1] = 0x02; /* two methods */
9845deede1e9 [gaim-migrate @ 1854]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1843
diff changeset
1398 buf[2] = 0x00; /* no authentication */
9845deede1e9 [gaim-migrate @ 1854]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1843
diff changeset
1399 buf[3] = 0x02; /* username/password authentication */
9845deede1e9 [gaim-migrate @ 1854]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1843
diff changeset
1400 i = 4;
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 else {
1844
9845deede1e9 [gaim-migrate @ 1854]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1843
diff changeset
1403 buf[1] = 0x01;
9845deede1e9 [gaim-migrate @ 1854]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1843
diff changeset
1404 buf[2] = 0x00;
9845deede1e9 [gaim-migrate @ 1854]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1843
diff changeset
1405 i = 3;
9845deede1e9 [gaim-migrate @ 1854]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1843
diff changeset
1406 }
3717
988485669631 [gaim-migrate @ 3850]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 3630
diff changeset
1407
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1408 if (write(source, buf, i) < i) {
5211
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
1409 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
1410 close(source);
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1411
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1412 if (phb->account == NULL ||
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1413 gaim_account_get_connection(phb->account) != NULL) {
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1414
4993
de84c1de2f66 [gaim-migrate @ 5328]
Nathan Walp <nwalp@pidgin.im>
parents: 4679
diff changeset
1415 phb->func(phb->data, -1, GAIM_INPUT_READ);
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1416 }
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1417
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1418 g_free(phb->host);
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1419 g_free(phb);
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1420 return;
1087
56c7ceb986a8 [gaim-migrate @ 1097]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1057
diff changeset
1421 }
56c7ceb986a8 [gaim-migrate @ 1097]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1057
diff changeset
1422
2090
b66aca8e8dce [gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2048
diff changeset
1423 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
1424 }
1087
56c7ceb986a8 [gaim-migrate @ 1097]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1057
diff changeset
1425
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1426 static int
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1427 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
1428 {
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1429 int fd = -1;
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1430
5211
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
1431 gaim_debug(GAIM_DEBUG_INFO, "socks5 proxy",
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
1432 "Connecting to %s:%d via %s:%d using SOCKS5\n",
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1433 phb->host, phb->port,
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1434 gaim_proxy_info_get_host(phb->gpi),
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1435 gaim_proxy_info_get_port(phb->gpi));
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1436
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1437 if ((fd = socket(addr->sa_family, SOCK_STREAM, 0)) < 0)
1087
56c7ceb986a8 [gaim-migrate @ 1097]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1057
diff changeset
1438 return -1;
56c7ceb986a8 [gaim-migrate @ 1097]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1057
diff changeset
1439
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1440 fcntl(fd, F_SETFL, O_NONBLOCK);
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1441
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
1442 if (connect(fd, addr, addrlen) < 0) {
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1443 if ((errno == EINPROGRESS) || (errno == EINTR)) {
5211
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
1444 gaim_debug(GAIM_DEBUG_WARNING, "socks5 proxy",
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
1445 "Connect would have blocked.\n");
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1446
2090
b66aca8e8dce [gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2048
diff changeset
1447 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
1448 }
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1449 else {
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1450 close(fd);
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1451 return -1;
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1452 }
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1453 }
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1454 else {
2048
3366311426df [gaim-migrate @ 2058]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1881
diff changeset
1455 unsigned int len;
3366311426df [gaim-migrate @ 2058]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1881
diff changeset
1456 int error = ETIMEDOUT;
3717
988485669631 [gaim-migrate @ 3850]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 3630
diff changeset
1457
5211
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
1458 gaim_debug(GAIM_DEBUG_MISC, "socks5 proxy",
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4993
diff changeset
1459 "Connect didn't block.\n");
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1460
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1461 len = sizeof(error);
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1462
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1463 if (getsockopt(fd, SOL_SOCKET, SO_ERROR, &error, &len) < 0) {
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1464 close(fd);
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1465 return -1;
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1466 }
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1467
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1468 fcntl(fd, F_SETFL, 0);
2090
b66aca8e8dce [gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2048
diff changeset
1469 s5_canwrite(phb, fd, GAIM_INPUT_WRITE);
1087
56c7ceb986a8 [gaim-migrate @ 1097]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1057
diff changeset
1470 }
56c7ceb986a8 [gaim-migrate @ 1097]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1057
diff changeset
1471
56c7ceb986a8 [gaim-migrate @ 1097]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1057
diff changeset
1472 return fd;
56c7ceb986a8 [gaim-migrate @ 1097]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1057
diff changeset
1473 }
56c7ceb986a8 [gaim-migrate @ 1097]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1057
diff changeset
1474
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1475 static void
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1476 connection_host_resolved(GSList *hosts, gpointer data,
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1477 const char *error_message)
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
1478 {
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
1479 struct PHB *phb = (struct PHB*)data;
4678
9ce3c698ff5e [gaim-migrate @ 4989]
Nathan Walp <nwalp@pidgin.im>
parents: 4648
diff changeset
1480 size_t addrlen;
9ce3c698ff5e [gaim-migrate @ 4989]
Nathan Walp <nwalp@pidgin.im>
parents: 4648
diff changeset
1481 struct sockaddr *addr;
9ce3c698ff5e [gaim-migrate @ 4989]
Nathan Walp <nwalp@pidgin.im>
parents: 4648
diff changeset
1482 int ret = -1;
4634
d19872836812 [gaim-migrate @ 4941]
Nathan Walp <nwalp@pidgin.im>
parents: 4499
diff changeset
1483
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1484 while (hosts) {
4678
9ce3c698ff5e [gaim-migrate @ 4989]
Nathan Walp <nwalp@pidgin.im>
parents: 4648
diff changeset
1485 addrlen = GPOINTER_TO_INT(hosts->data);
9ce3c698ff5e [gaim-migrate @ 4989]
Nathan Walp <nwalp@pidgin.im>
parents: 4648
diff changeset
1486 hosts = hosts->next;
9ce3c698ff5e [gaim-migrate @ 4989]
Nathan Walp <nwalp@pidgin.im>
parents: 4648
diff changeset
1487 addr = hosts->data;
9ce3c698ff5e [gaim-migrate @ 4989]
Nathan Walp <nwalp@pidgin.im>
parents: 4648
diff changeset
1488 hosts = hosts->next;
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
1489
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1490 switch (gaim_proxy_info_get_type(phb->gpi))
4678
9ce3c698ff5e [gaim-migrate @ 4989]
Nathan Walp <nwalp@pidgin.im>
parents: 4648
diff changeset
1491 {
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1492 case GAIM_PROXY_NONE:
4678
9ce3c698ff5e [gaim-migrate @ 4989]
Nathan Walp <nwalp@pidgin.im>
parents: 4648
diff changeset
1493 ret = proxy_connect_none(phb, addr, addrlen);
9ce3c698ff5e [gaim-migrate @ 4989]
Nathan Walp <nwalp@pidgin.im>
parents: 4648
diff changeset
1494 break;
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1495
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1496 case GAIM_PROXY_HTTP:
4678
9ce3c698ff5e [gaim-migrate @ 4989]
Nathan Walp <nwalp@pidgin.im>
parents: 4648
diff changeset
1497 ret = proxy_connect_http(phb, addr, addrlen);
9ce3c698ff5e [gaim-migrate @ 4989]
Nathan Walp <nwalp@pidgin.im>
parents: 4648
diff changeset
1498 break;
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1499
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1500 case GAIM_PROXY_SOCKS4:
4678
9ce3c698ff5e [gaim-migrate @ 4989]
Nathan Walp <nwalp@pidgin.im>
parents: 4648
diff changeset
1501 ret = proxy_connect_socks4(phb, addr, addrlen);
9ce3c698ff5e [gaim-migrate @ 4989]
Nathan Walp <nwalp@pidgin.im>
parents: 4648
diff changeset
1502 break;
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1503
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1504 case GAIM_PROXY_SOCKS5:
4678
9ce3c698ff5e [gaim-migrate @ 4989]
Nathan Walp <nwalp@pidgin.im>
parents: 4648
diff changeset
1505 ret = proxy_connect_socks5(phb, addr, addrlen);
9ce3c698ff5e [gaim-migrate @ 4989]
Nathan Walp <nwalp@pidgin.im>
parents: 4648
diff changeset
1506 break;
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 default:
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1509 break;
4678
9ce3c698ff5e [gaim-migrate @ 4989]
Nathan Walp <nwalp@pidgin.im>
parents: 4648
diff changeset
1510 }
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1511
4678
9ce3c698ff5e [gaim-migrate @ 4989]
Nathan Walp <nwalp@pidgin.im>
parents: 4648
diff changeset
1512 if (ret > 0)
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
1513 break;
4678
9ce3c698ff5e [gaim-migrate @ 4989]
Nathan Walp <nwalp@pidgin.im>
parents: 4648
diff changeset
1514 }
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1515
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1516 if (ret < 0) {
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1517 if (phb->account == NULL ||
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1518 gaim_account_get_connection(phb->account) != NULL) {
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1519
4993
de84c1de2f66 [gaim-migrate @ 5328]
Nathan Walp <nwalp@pidgin.im>
parents: 4679
diff changeset
1520 phb->func(phb->data, -1, GAIM_INPUT_READ);
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1521 }
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1522
4678
9ce3c698ff5e [gaim-migrate @ 4989]
Nathan Walp <nwalp@pidgin.im>
parents: 4648
diff changeset
1523 g_free(phb->host);
9ce3c698ff5e [gaim-migrate @ 4989]
Nathan Walp <nwalp@pidgin.im>
parents: 4648
diff changeset
1524 g_free(phb);
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
1525 }
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
1526 }
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
1527
4452
2afc0f845e74 [gaim-migrate @ 4727]
Sean Egan <seanegan@gmail.com>
parents: 4447
diff changeset
1528 int
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1529 gaim_proxy_connect(GaimAccount *account, const char *host, int port,
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1530 GaimInputFunction func, gpointer data)
1087
56c7ceb986a8 [gaim-migrate @ 1097]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1057
diff changeset
1531 {
5580
86456ec3ca25 [gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents: 5572
diff changeset
1532 const char *connecthost = host;
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
1533 int connectport = port;
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1534 struct PHB *phb = g_new0(struct PHB, 1);
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1535
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1536 g_return_val_if_fail(host != NULL, -1);
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1537 g_return_val_if_fail(port != 0 && port != -1, -1);
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1538 g_return_val_if_fail(func != NULL, -1);
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1539
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1540 if (account == NULL || gaim_account_get_proxy_info(account) == NULL)
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1541 phb->gpi = gaim_global_proxy_get_info();
4634
d19872836812 [gaim-migrate @ 4941]
Nathan Walp <nwalp@pidgin.im>
parents: 4499
diff changeset
1542 else
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1543 phb->gpi = gaim_account_get_proxy_info(account);
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1544
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1545 phb->func = func;
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1546 phb->data = data;
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
1547 phb->host = g_strdup(host);
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
1548 phb->port = port;
4993
de84c1de2f66 [gaim-migrate @ 5328]
Nathan Walp <nwalp@pidgin.im>
parents: 4679
diff changeset
1549 phb->account = account;
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1550
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1551 if ((gaim_proxy_info_get_type(phb->gpi) != GAIM_PROXY_NONE) &&
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1552 (gaim_proxy_info_get_host(phb->gpi) == NULL ||
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1553 gaim_proxy_info_get_port(phb->gpi) == 0 ||
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1554 gaim_proxy_info_get_port(phb->gpi) == -1)) {
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1555
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1556 gaim_proxy_info_set_type(phb->gpi, GAIM_PROXY_NONE);
1840
00aef397a1fe [gaim-migrate @ 1850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1705
diff changeset
1557 }
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
1558
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1559 switch (gaim_proxy_info_get_type(phb->gpi))
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
1560 {
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1561 case GAIM_PROXY_NONE:
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
1562 break;
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1563
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1564 case GAIM_PROXY_HTTP:
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1565 case GAIM_PROXY_SOCKS4:
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1566 case GAIM_PROXY_SOCKS5:
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1567 connecthost = gaim_proxy_info_get_host(phb->gpi);
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1568 connectport = gaim_proxy_info_get_port(phb->gpi);
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
1569 break;
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1570
4366
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
1571 default:
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
1572 g_free(phb->host);
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
1573 g_free(phb);
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
1574 return -1;
7ba9b56a8796 [gaim-migrate @ 4632]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
1575 }
5681
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1576
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1577 return gaim_gethostbyname_async(connecthost, connectport,
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1578 connection_host_resolved, phb);
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1579 }
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1580
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1581
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1582 static void
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1583 proxy_pref_cb(const char *name, GaimPrefType type, gpointer value,
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1584 gpointer data)
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1585 {
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1586 GaimProxyInfo *info = gaim_global_proxy_get_info();
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1587
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1588 if (!strcmp(name, "/core/proxy/type"))
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1589 gaim_proxy_info_set_type(info, GPOINTER_TO_INT(value));
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1590 else if (!strcmp(name, "/core/proxy/host"))
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1591 gaim_proxy_info_set_host(info, value);
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1592 else if (!strcmp(name, "/core/proxy/port"))
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1593 gaim_proxy_info_set_port(info, GPOINTER_TO_INT(value));
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1594 else if (!strcmp(name, "/core/proxy/username"))
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1595 gaim_proxy_info_set_username(info, value);
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1596 else if (!strcmp(name, "/core/proxy/password"))
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1597 gaim_proxy_info_set_password(info, value);
1087
56c7ceb986a8 [gaim-migrate @ 1097]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1057
diff changeset
1598 }
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 void
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1601 gaim_proxy_init(void)
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1602 {
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1603 /* Initialize a default proxy info struct. */
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1604 global_proxy_info = gaim_proxy_info_new();
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1605
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1606 /* Proxy */
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1607 gaim_prefs_add_none("/core/proxy");
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1608 gaim_prefs_add_string("/core/proxy/type", "none");
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1609 gaim_prefs_add_string("/core/proxy/host", "");
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1610 gaim_prefs_add_int("/core/proxy/port", 0);
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1611 gaim_prefs_add_string("/core/proxy/username", "");
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1612 gaim_prefs_add_string("/core/proxy/password", "");
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1613
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1614 /* Setup callbacks for the preferences. */
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1615 gaim_prefs_connect_callback("/core/proxy/type",
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1616 proxy_pref_cb, NULL);
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1617 gaim_prefs_connect_callback("/core/proxy/host",
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1618 proxy_pref_cb, NULL);
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1619 gaim_prefs_connect_callback("/core/proxy/port",
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1620 proxy_pref_cb, NULL);
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1621 gaim_prefs_connect_callback("/core/proxy/username",
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1622 proxy_pref_cb, NULL);
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1623 gaim_prefs_connect_callback("/core/proxy/password",
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1624 proxy_pref_cb, NULL);
46d7ad0dfa26 [gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents: 5580
diff changeset
1625 }