annotate libpurple/proxy.c @ 25901:4670851af098

Patch from fqueze to add API for setting the global proxy settings. Fixes #7610.
author Daniel Atallah <daniel.atallah@gmail.com>
date Tue, 06 Jan 2009 03:46:52 +0000
parents 95ef7beb926b
children be3ba7e07de5
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1 /**
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2 * @file proxy.c Proxy API
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3 * @ingroup core
20074
6bf32c9e15a7 remove gpl boilerplate from doxygen docs
Sean Egan <seanegan@gmail.com>
parents: 20040
diff changeset
4 */
6bf32c9e15a7 remove gpl boilerplate from doxygen docs
Sean Egan <seanegan@gmail.com>
parents: 20040
diff changeset
5
6bf32c9e15a7 remove gpl boilerplate from doxygen docs
Sean Egan <seanegan@gmail.com>
parents: 20040
diff changeset
6 /* purple
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
7 *
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
8 * Purple is the legal property of its developers, whose names are too numerous
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
9 * to list here. Please refer to the COPYRIGHT file distributed with this
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
10 * source distribution.
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
11 *
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
12 * This program is free software; you can redistribute it and/or modify
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
13 * it under the terms of the GNU General Public License as published by
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
14 * the Free Software Foundation; either version 2 of the License, or
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
15 * (at your option) any later version.
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
16 *
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
17 * This program is distributed in the hope that it will be useful,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
20 * GNU General Public License for more details.
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
21 *
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
22 * You should have received a copy of the GNU General Public License
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
23 * along with this program; if not, write to the Free Software
19681
44b4e8bd759b The FSF changed its address a while ago; our files were out of date.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 19662
diff changeset
24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
25 *
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
26 */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
27
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
28 /* this is a little piece of code to handle proxy connection */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
29 /* it is intended to : 1st handle http proxy, using the CONNECT command
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
30 , 2nd provide an easy way to add socks support
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
31 , 3rd draw women to it like flies to honey */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
32
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
33 #include "internal.h"
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
34 #include "cipher.h"
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
35 #include "debug.h"
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
36 #include "dnsquery.h"
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
37 #include "notify.h"
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
38 #include "ntlm.h"
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
39 #include "prefs.h"
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
40 #include "proxy.h"
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
41 #include "util.h"
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
42
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
43 struct _PurpleProxyConnectData {
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
44 void *handle;
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
45 PurpleProxyConnectFunction connect_cb;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
46 gpointer data;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
47 gchar *host;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
48 int port;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
49 int fd;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
50 guint inpa;
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
51 PurpleProxyInfo *gpi;
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
52 PurpleDnsQueryData *query_data;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
53
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
54 /**
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
55 * This contains alternating length/char* values. The char*
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
56 * values need to be freed when removed from the linked list.
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
57 */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
58 GSList *hosts;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
59
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
60 /*
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
61 * All of the following variables are used when establishing a
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
62 * connection through a proxy.
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
63 */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
64 guchar *write_buffer;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
65 gsize write_buf_len;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
66 gsize written_len;
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
67 PurpleInputFunction read_cb;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
68 guchar *read_buffer;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
69 gsize read_buf_len;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
70 gsize read_len;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
71 };
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
72
21015
787b3897ba9f Patch from Andrew Gaul to constify a bunch of static variables to reduce
Ka-Hing Cheung <khc@hxbc.us>
parents: 20359
diff changeset
73 static const char * const socks5errors[] = {
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
74 "succeeded\n",
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
75 "general SOCKS server failure\n",
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
76 "connection not allowed by ruleset\n",
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
77 "Network unreachable\n",
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
78 "Host unreachable\n",
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
79 "Connection refused\n",
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
80 "TTL expired\n",
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
81 "Command not supported\n",
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
82 "Address type not supported\n"
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
83 };
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
84
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
85 static PurpleProxyInfo *global_proxy_info = NULL;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
86
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
87 static GSList *handles = NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
88
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
89 static void try_connect(PurpleProxyConnectData *connect_data);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
90
15976
a6a79b8616bf I commonly see a crash in which socket_ready_cb(), shortly after a laptop wakes from sleep, is passed invalid (previously freed) connect_data. It looks like this:
Evan Schoenberg <evan.s@dreskin.net>
parents: 15822
diff changeset
91 /*
a6a79b8616bf I commonly see a crash in which socket_ready_cb(), shortly after a laptop wakes from sleep, is passed invalid (previously freed) connect_data. It looks like this:
Evan Schoenberg <evan.s@dreskin.net>
parents: 15822
diff changeset
92 * TODO: Eventually (GObjectification) this bad boy will be removed, because it is
a6a79b8616bf I commonly see a crash in which socket_ready_cb(), shortly after a laptop wakes from sleep, is passed invalid (previously freed) connect_data. It looks like this:
Evan Schoenberg <evan.s@dreskin.net>
parents: 15822
diff changeset
93 * a gross fix for a crashy problem.
a6a79b8616bf I commonly see a crash in which socket_ready_cb(), shortly after a laptop wakes from sleep, is passed invalid (previously freed) connect_data. It looks like this:
Evan Schoenberg <evan.s@dreskin.net>
parents: 15822
diff changeset
94 */
a6a79b8616bf I commonly see a crash in which socket_ready_cb(), shortly after a laptop wakes from sleep, is passed invalid (previously freed) connect_data. It looks like this:
Evan Schoenberg <evan.s@dreskin.net>
parents: 15822
diff changeset
95 #define PURPLE_PROXY_CONNECT_DATA_IS_VALID(connect_data) g_slist_find(handles, connect_data)
a6a79b8616bf I commonly see a crash in which socket_ready_cb(), shortly after a laptop wakes from sleep, is passed invalid (previously freed) connect_data. It looks like this:
Evan Schoenberg <evan.s@dreskin.net>
parents: 15822
diff changeset
96
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
97 /**************************************************************************
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
98 * Proxy structure API
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
99 **************************************************************************/
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
100 PurpleProxyInfo *
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
101 purple_proxy_info_new(void)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
102 {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
103 return g_new0(PurpleProxyInfo, 1);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
104 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
105
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
106 void
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
107 purple_proxy_info_destroy(PurpleProxyInfo *info)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
108 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
109 g_return_if_fail(info != NULL);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
110
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
111 g_free(info->host);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
112 g_free(info->username);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
113 g_free(info->password);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
114
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
115 g_free(info);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
116 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
117
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
118 void
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
119 purple_proxy_info_set_type(PurpleProxyInfo *info, PurpleProxyType type)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
120 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
121 g_return_if_fail(info != NULL);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
122
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
123 info->type = type;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
124 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
125
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
126 void
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
127 purple_proxy_info_set_host(PurpleProxyInfo *info, const char *host)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
128 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
129 g_return_if_fail(info != NULL);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
130
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
131 g_free(info->host);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
132 info->host = g_strdup(host);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
133 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
134
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
135 void
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
136 purple_proxy_info_set_port(PurpleProxyInfo *info, int port)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
137 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
138 g_return_if_fail(info != NULL);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
139
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
140 info->port = port;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
141 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
142
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
143 void
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
144 purple_proxy_info_set_username(PurpleProxyInfo *info, const char *username)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
145 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
146 g_return_if_fail(info != NULL);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
147
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
148 g_free(info->username);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
149 info->username = g_strdup(username);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
150 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
151
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
152 void
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
153 purple_proxy_info_set_password(PurpleProxyInfo *info, const char *password)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
154 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
155 g_return_if_fail(info != NULL);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
156
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
157 g_free(info->password);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
158 info->password = g_strdup(password);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
159 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
160
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
161 PurpleProxyType
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
162 purple_proxy_info_get_type(const PurpleProxyInfo *info)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
163 {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
164 g_return_val_if_fail(info != NULL, PURPLE_PROXY_NONE);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
165
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
166 return info->type;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
167 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
168
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
169 const char *
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
170 purple_proxy_info_get_host(const PurpleProxyInfo *info)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
171 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
172 g_return_val_if_fail(info != NULL, NULL);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
173
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
174 return info->host;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
175 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
176
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
177 int
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
178 purple_proxy_info_get_port(const PurpleProxyInfo *info)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
179 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
180 g_return_val_if_fail(info != NULL, 0);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
181
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
182 return info->port;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
183 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
184
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
185 const char *
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
186 purple_proxy_info_get_username(const PurpleProxyInfo *info)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
187 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
188 g_return_val_if_fail(info != NULL, NULL);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
189
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
190 return info->username;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
191 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
192
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
193 const char *
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
194 purple_proxy_info_get_password(const PurpleProxyInfo *info)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
195 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
196 g_return_val_if_fail(info != NULL, NULL);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
197
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
198 return info->password;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
199 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
200
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
201 /**************************************************************************
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
202 * Global Proxy API
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
203 **************************************************************************/
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
204 PurpleProxyInfo *
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
205 purple_global_proxy_get_info(void)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
206 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
207 return global_proxy_info;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
208 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
209
25901
4670851af098 Patch from fqueze to add API for setting the global proxy settings. Fixes #7610.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24750
diff changeset
210 void
4670851af098 Patch from fqueze to add API for setting the global proxy settings. Fixes #7610.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24750
diff changeset
211 purple_global_proxy_set_info(PurpleProxyInfo *info)
4670851af098 Patch from fqueze to add API for setting the global proxy settings. Fixes #7610.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24750
diff changeset
212 {
4670851af098 Patch from fqueze to add API for setting the global proxy settings. Fixes #7610.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24750
diff changeset
213 g_return_if_fail(info != NULL);
4670851af098 Patch from fqueze to add API for setting the global proxy settings. Fixes #7610.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24750
diff changeset
214
4670851af098 Patch from fqueze to add API for setting the global proxy settings. Fixes #7610.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24750
diff changeset
215 purple_proxy_info_destroy(global_proxy_info);
4670851af098 Patch from fqueze to add API for setting the global proxy settings. Fixes #7610.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24750
diff changeset
216
4670851af098 Patch from fqueze to add API for setting the global proxy settings. Fixes #7610.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24750
diff changeset
217 global_proxy_info = info;
4670851af098 Patch from fqueze to add API for setting the global proxy settings. Fixes #7610.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24750
diff changeset
218 }
4670851af098 Patch from fqueze to add API for setting the global proxy settings. Fixes #7610.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24750
diff changeset
219
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
220 static PurpleProxyInfo *
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
221 purple_gnome_proxy_get_info(void)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
222 {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
223 static PurpleProxyInfo info = {0, NULL, 0, NULL, NULL};
23960
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23389
diff changeset
224 gboolean use_same_proxy = FALSE;
24119
d4239c588fcf Some minor cleanup; removal of unnecessary frees and setting stuff to NULL
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24118
diff changeset
225 gchar *tmp, *err = NULL;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
226
22419
31fb78b1184c Short circuit and return out of the function early if gconftool-2
Mark Doliner <mark@kingant.net>
parents: 22417
diff changeset
227 tmp = g_find_program_in_path("gconftool-2");
31fb78b1184c Short circuit and return out of the function early if gconftool-2
Mark Doliner <mark@kingant.net>
parents: 22417
diff changeset
228 if (tmp == NULL)
31fb78b1184c Short circuit and return out of the function early if gconftool-2
Mark Doliner <mark@kingant.net>
parents: 22417
diff changeset
229 return purple_global_proxy_get_info();
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
230
22419
31fb78b1184c Short circuit and return out of the function early if gconftool-2
Mark Doliner <mark@kingant.net>
parents: 22417
diff changeset
231 g_free(tmp);
24119
d4239c588fcf Some minor cleanup; removal of unnecessary frees and setting stuff to NULL
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24118
diff changeset
232 tmp = NULL;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
233
22420
316c8565f562 Improve our error handling of Gnome proxy settings.
Mark Doliner <mark@kingant.net>
parents: 22419
diff changeset
234 /* Check whether to use a proxy. */
316c8565f562 Improve our error handling of Gnome proxy settings.
Mark Doliner <mark@kingant.net>
parents: 22419
diff changeset
235 if (!g_spawn_command_line_sync("gconftool-2 -g /system/proxy/mode",
23960
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23389
diff changeset
236 &tmp, &err, NULL, NULL))
22419
31fb78b1184c Short circuit and return out of the function early if gconftool-2
Mark Doliner <mark@kingant.net>
parents: 22417
diff changeset
237 return purple_global_proxy_get_info();
23960
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23389
diff changeset
238 g_free(err);
24119
d4239c588fcf Some minor cleanup; removal of unnecessary frees and setting stuff to NULL
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24118
diff changeset
239 err = NULL;
22418
6eb0749ad46c disapproval of revision 'd5ef30aafa0c0ecff773017ab7ac542f9ba7b4b4'
Mark Doliner <mark@kingant.net>
parents: 22417
diff changeset
240
22419
31fb78b1184c Short circuit and return out of the function early if gconftool-2
Mark Doliner <mark@kingant.net>
parents: 22417
diff changeset
241 if (!strcmp(tmp, "none\n")) {
31fb78b1184c Short circuit and return out of the function early if gconftool-2
Mark Doliner <mark@kingant.net>
parents: 22417
diff changeset
242 info.type = PURPLE_PROXY_NONE;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
243 g_free(tmp);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
244 return &info;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
245 }
22420
316c8565f562 Improve our error handling of Gnome proxy settings.
Mark Doliner <mark@kingant.net>
parents: 22419
diff changeset
246
316c8565f562 Improve our error handling of Gnome proxy settings.
Mark Doliner <mark@kingant.net>
parents: 22419
diff changeset
247 if (strcmp(tmp, "manual\n")) {
316c8565f562 Improve our error handling of Gnome proxy settings.
Mark Doliner <mark@kingant.net>
parents: 22419
diff changeset
248 /* Unknown setting. Fallback to using our global proxy settings. */
22419
31fb78b1184c Short circuit and return out of the function early if gconftool-2
Mark Doliner <mark@kingant.net>
parents: 22417
diff changeset
249 g_free(tmp);
31fb78b1184c Short circuit and return out of the function early if gconftool-2
Mark Doliner <mark@kingant.net>
parents: 22417
diff changeset
250 return purple_global_proxy_get_info();
31fb78b1184c Short circuit and return out of the function early if gconftool-2
Mark Doliner <mark@kingant.net>
parents: 22417
diff changeset
251 }
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
252
22419
31fb78b1184c Short circuit and return out of the function early if gconftool-2
Mark Doliner <mark@kingant.net>
parents: 22417
diff changeset
253 g_free(tmp);
24119
d4239c588fcf Some minor cleanup; removal of unnecessary frees and setting stuff to NULL
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24118
diff changeset
254 tmp = NULL;
22420
316c8565f562 Improve our error handling of Gnome proxy settings.
Mark Doliner <mark@kingant.net>
parents: 22419
diff changeset
255
22422
04b807c8b98d Bring back the lines that free info.whatever on subsequent calls to
Mark Doliner <mark@kingant.net>
parents: 22421
diff changeset
256 /* Free the old fields */
04b807c8b98d Bring back the lines that free info.whatever on subsequent calls to
Mark Doliner <mark@kingant.net>
parents: 22421
diff changeset
257 if (info.host) {
04b807c8b98d Bring back the lines that free info.whatever on subsequent calls to
Mark Doliner <mark@kingant.net>
parents: 22421
diff changeset
258 g_free(info.host);
04b807c8b98d Bring back the lines that free info.whatever on subsequent calls to
Mark Doliner <mark@kingant.net>
parents: 22421
diff changeset
259 info.host = NULL;
04b807c8b98d Bring back the lines that free info.whatever on subsequent calls to
Mark Doliner <mark@kingant.net>
parents: 22421
diff changeset
260 }
04b807c8b98d Bring back the lines that free info.whatever on subsequent calls to
Mark Doliner <mark@kingant.net>
parents: 22421
diff changeset
261 if (info.username) {
04b807c8b98d Bring back the lines that free info.whatever on subsequent calls to
Mark Doliner <mark@kingant.net>
parents: 22421
diff changeset
262 g_free(info.username);
04b807c8b98d Bring back the lines that free info.whatever on subsequent calls to
Mark Doliner <mark@kingant.net>
parents: 22421
diff changeset
263 info.username = NULL;
04b807c8b98d Bring back the lines that free info.whatever on subsequent calls to
Mark Doliner <mark@kingant.net>
parents: 22421
diff changeset
264 }
04b807c8b98d Bring back the lines that free info.whatever on subsequent calls to
Mark Doliner <mark@kingant.net>
parents: 22421
diff changeset
265 if (info.password) {
04b807c8b98d Bring back the lines that free info.whatever on subsequent calls to
Mark Doliner <mark@kingant.net>
parents: 22421
diff changeset
266 g_free(info.password);
04b807c8b98d Bring back the lines that free info.whatever on subsequent calls to
Mark Doliner <mark@kingant.net>
parents: 22421
diff changeset
267 info.password = NULL;
04b807c8b98d Bring back the lines that free info.whatever on subsequent calls to
Mark Doliner <mark@kingant.net>
parents: 22421
diff changeset
268 }
04b807c8b98d Bring back the lines that free info.whatever on subsequent calls to
Mark Doliner <mark@kingant.net>
parents: 22421
diff changeset
269
23960
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23389
diff changeset
270 if (!g_spawn_command_line_sync("gconftool-2 -g /system/http_proxy/use_same_proxy",
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23389
diff changeset
271 &tmp, &err, NULL, NULL))
22419
31fb78b1184c Short circuit and return out of the function early if gconftool-2
Mark Doliner <mark@kingant.net>
parents: 22417
diff changeset
272 return purple_global_proxy_get_info();
23960
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23389
diff changeset
273 g_free(err);
24119
d4239c588fcf Some minor cleanup; removal of unnecessary frees and setting stuff to NULL
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24118
diff changeset
274 err = NULL;
23960
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23389
diff changeset
275
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23389
diff changeset
276 if (!strcmp(tmp, "true\n"))
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23389
diff changeset
277 use_same_proxy = TRUE;
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23389
diff changeset
278 g_free(tmp);
24119
d4239c588fcf Some minor cleanup; removal of unnecessary frees and setting stuff to NULL
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24118
diff changeset
279 tmp = NULL;
23960
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23389
diff changeset
280
24118
0bd896cd1b90 Fix a double free. Fixes #7047
Stu Tomlinson <stu@nosnilmot.com>
parents: 24107
diff changeset
281 if (!use_same_proxy) {
0bd896cd1b90 Fix a double free. Fixes #7047
Stu Tomlinson <stu@nosnilmot.com>
parents: 24107
diff changeset
282 if (!g_spawn_command_line_sync("gconftool-2 -g /system/proxy/socks_host",
23960
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23389
diff changeset
283 &info.host, &err, NULL, NULL))
24118
0bd896cd1b90 Fix a double free. Fixes #7047
Stu Tomlinson <stu@nosnilmot.com>
parents: 24107
diff changeset
284 return purple_global_proxy_get_info();
0bd896cd1b90 Fix a double free. Fixes #7047
Stu Tomlinson <stu@nosnilmot.com>
parents: 24107
diff changeset
285 g_free(err);
24119
d4239c588fcf Some minor cleanup; removal of unnecessary frees and setting stuff to NULL
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24118
diff changeset
286 err = NULL;
24118
0bd896cd1b90 Fix a double free. Fixes #7047
Stu Tomlinson <stu@nosnilmot.com>
parents: 24107
diff changeset
287 }
23960
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23389
diff changeset
288
24118
0bd896cd1b90 Fix a double free. Fixes #7047
Stu Tomlinson <stu@nosnilmot.com>
parents: 24107
diff changeset
289 if(info.host != NULL)
0bd896cd1b90 Fix a double free. Fixes #7047
Stu Tomlinson <stu@nosnilmot.com>
parents: 24107
diff changeset
290 g_strchomp(info.host);
0bd896cd1b90 Fix a double free. Fixes #7047
Stu Tomlinson <stu@nosnilmot.com>
parents: 24107
diff changeset
291
0bd896cd1b90 Fix a double free. Fixes #7047
Stu Tomlinson <stu@nosnilmot.com>
parents: 24107
diff changeset
292 if (!use_same_proxy && (info.host != NULL) && (*info.host != '\0')) {
23960
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23389
diff changeset
293 info.type = PURPLE_PROXY_SOCKS5;
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23389
diff changeset
294 if (!g_spawn_command_line_sync("gconftool-2 -g /system/proxy/socks_port",
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23389
diff changeset
295 &tmp, &err, NULL, NULL))
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23389
diff changeset
296 {
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23389
diff changeset
297 g_free(info.host);
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23389
diff changeset
298 info.host = NULL;
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23389
diff changeset
299 return purple_global_proxy_get_info();
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23389
diff changeset
300 }
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23389
diff changeset
301 g_free(err);
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23389
diff changeset
302 info.port = atoi(tmp);
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23389
diff changeset
303 g_free(tmp);
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23389
diff changeset
304 } else {
22420
316c8565f562 Improve our error handling of Gnome proxy settings.
Mark Doliner <mark@kingant.net>
parents: 22419
diff changeset
305 g_free(info.host);
23960
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23389
diff changeset
306 if (!g_spawn_command_line_sync("gconftool-2 -g /system/http_proxy/host",
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23389
diff changeset
307 &info.host, &err, NULL, NULL))
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23389
diff changeset
308 return purple_global_proxy_get_info();
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23389
diff changeset
309 g_free(err);
24119
d4239c588fcf Some minor cleanup; removal of unnecessary frees and setting stuff to NULL
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24118
diff changeset
310 err = NULL;
d4239c588fcf Some minor cleanup; removal of unnecessary frees and setting stuff to NULL
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24118
diff changeset
311
23960
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23389
diff changeset
312 /* If we get this far then we know we're using an HTTP proxy */
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23389
diff changeset
313 info.type = PURPLE_PROXY_HTTP;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
314
23960
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23389
diff changeset
315 g_strchomp(info.host);
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23389
diff changeset
316 if (*info.host == '\0')
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23389
diff changeset
317 {
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23389
diff changeset
318 purple_debug_info("proxy", "Gnome proxy settings are set to "
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23389
diff changeset
319 "'manual' but no suitable proxy server is specified. Using "
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23389
diff changeset
320 "Pidgin's proxy settings instead.\n");
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23389
diff changeset
321 g_free(info.host);
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23389
diff changeset
322 info.host = NULL;
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23389
diff changeset
323 return purple_global_proxy_get_info();
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23389
diff changeset
324 }
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23389
diff changeset
325
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23389
diff changeset
326 if (!g_spawn_command_line_sync("gconftool-2 -g /system/http_proxy/authentication_user",
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23389
diff changeset
327 &info.username, &err, NULL, NULL))
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23389
diff changeset
328 {
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23389
diff changeset
329 g_free(info.host);
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23389
diff changeset
330 info.host = NULL;
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23389
diff changeset
331 return purple_global_proxy_get_info();
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23389
diff changeset
332 }
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23389
diff changeset
333 g_free(err);
24119
d4239c588fcf Some minor cleanup; removal of unnecessary frees and setting stuff to NULL
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24118
diff changeset
334 err = NULL;
23960
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23389
diff changeset
335 g_strchomp(info.username);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
336
23960
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23389
diff changeset
337 if (!g_spawn_command_line_sync("gconftool-2 -g /system/http_proxy/authentication_password",
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23389
diff changeset
338 &info.password, &err, NULL, NULL))
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23389
diff changeset
339 {
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23389
diff changeset
340 g_free(info.host);
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23389
diff changeset
341 info.host = NULL;
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23389
diff changeset
342 g_free(info.username);
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23389
diff changeset
343 info.username = NULL;
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23389
diff changeset
344 return purple_global_proxy_get_info();
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23389
diff changeset
345 }
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23389
diff changeset
346 g_free(err);
24119
d4239c588fcf Some minor cleanup; removal of unnecessary frees and setting stuff to NULL
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24118
diff changeset
347 err = NULL;
23960
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23389
diff changeset
348 g_strchomp(info.password);
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23389
diff changeset
349
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23389
diff changeset
350 if (!g_spawn_command_line_sync("gconftool-2 -g /system/http_proxy/port",
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23389
diff changeset
351 &tmp, &err, NULL, NULL))
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23389
diff changeset
352 {
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23389
diff changeset
353 g_free(info.host);
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23389
diff changeset
354 info.host = NULL;
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23389
diff changeset
355 g_free(info.username);
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23389
diff changeset
356 info.username = NULL;
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23389
diff changeset
357 g_free(info.password);
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23389
diff changeset
358 info.password = NULL;
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23389
diff changeset
359 return purple_global_proxy_get_info();
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23389
diff changeset
360 }
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23389
diff changeset
361 g_free(err);
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23389
diff changeset
362 info.port = atoi(tmp);
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23389
diff changeset
363 g_free(tmp);
22420
316c8565f562 Improve our error handling of Gnome proxy settings.
Mark Doliner <mark@kingant.net>
parents: 22419
diff changeset
364 }
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
365
22419
31fb78b1184c Short circuit and return out of the function early if gconftool-2
Mark Doliner <mark@kingant.net>
parents: 22417
diff changeset
366 return &info;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
367 }
23970
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
368
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
369 #ifdef _WIN32
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
370
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
371 typedef BOOL (CALLBACK* LPFNWINHTTPGETIEPROXYCONFIG)(/*IN OUT*/ WINHTTP_CURRENT_USER_IE_PROXY_CONFIG* pProxyConfig);
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
372
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
373 /* This modifies "host" in-place evilly */
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
374 static void
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
375 _proxy_fill_hostinfo(PurpleProxyInfo *info, char *host, int default_port)
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
376 {
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
377 int port = default_port;
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
378 char *d;
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
379
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
380 d = g_strrstr(host, ":");
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
381 if (d)
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
382 *d = '\0';
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
383 d++;
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
384 if (*d)
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
385 sscanf(d, "%d", &port);
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
386
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
387 purple_proxy_info_set_host(info, host);
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
388 purple_proxy_info_set_port(info, port);
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
389 }
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
390
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
391 static PurpleProxyInfo *
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
392 purple_win32_proxy_get_info(void)
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
393 {
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
394 static LPFNWINHTTPGETIEPROXYCONFIG MyWinHttpGetIEProxyConfig = NULL;
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
395 static gboolean loaded = FALSE;
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
396 static PurpleProxyInfo info = {0, NULL, 0, NULL, NULL};
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
397
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
398 WINHTTP_CURRENT_USER_IE_PROXY_CONFIG ie_proxy_config;
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
399
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
400 if (!loaded) {
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
401 loaded = TRUE;
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
402 MyWinHttpGetIEProxyConfig = (LPFNWINHTTPGETIEPROXYCONFIG)
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
403 wpurple_find_and_loadproc("winhttp.dll", "WinHttpGetIEProxyConfigForCurrentUser");
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
404 if (!MyWinHttpGetIEProxyConfig)
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
405 purple_debug_info("proxy", "Unable to read Windows Proxy Settings.\n");
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
406 }
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
407
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
408 if (!MyWinHttpGetIEProxyConfig)
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
409 return NULL;
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
410
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
411 ZeroMemory(&ie_proxy_config, sizeof(ie_proxy_config));
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
412 if (!MyWinHttpGetIEProxyConfig(&ie_proxy_config)) {
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
413 purple_debug_error("proxy", "Error reading Windows Proxy Settings(%lu).\n", GetLastError());
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
414 return NULL;
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
415 }
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
416
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
417 /* We can't do much if it is autodetect*/
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
418 if (ie_proxy_config.fAutoDetect) {
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
419 purple_debug_error("proxy", "Windows Proxy Settings set to autodetect (not supported).\n");
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
420
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
421 /* TODO: For 3.0.0 we'll revisit this (maybe)*/
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
422
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
423 return NULL;
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
424
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
425 } else if (ie_proxy_config.lpszProxy) {
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
426 gchar *proxy_list = g_utf16_to_utf8(ie_proxy_config.lpszProxy, -1,
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
427 NULL, NULL, NULL);
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
428
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
429 /* We can't do anything about the bypass list, as we don't have the url */
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
430 /* TODO: For 3.0.0 we'll revisit this*/
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
431
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
432 /* There are proxy settings for several protocols */
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
433 if (proxy_list && *proxy_list) {
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
434 char *specific = NULL, *tmp;
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
435
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
436 /* If there is only a global proxy, which means "HTTP" */
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
437 if (!strchr(proxy_list, ';') || (specific = g_strstr_len(proxy_list, -1, "http=")) != NULL) {
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
438
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
439 if (specific) {
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
440 specific += strlen("http=");
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
441 tmp = strchr(specific, ';');
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
442 if (tmp)
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
443 *tmp = '\0';
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
444 /* specific now points the proxy server (and port) */
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
445 } else
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
446 specific = proxy_list;
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
447
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
448 purple_proxy_info_set_type(&info, PURPLE_PROXY_HTTP);
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
449 _proxy_fill_hostinfo(&info, specific, 80);
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
450 /* TODO: is there a way to set the username/password? */
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
451 purple_proxy_info_set_username(&info, NULL);
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
452 purple_proxy_info_set_password(&info, NULL);
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
453
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
454 purple_debug_info("proxy", "Windows Proxy Settings: HTTP proxy: '%s:%d'.\n",
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
455 purple_proxy_info_get_host(&info),
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
456 purple_proxy_info_get_port(&info));
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
457
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
458 } else if ((specific = g_strstr_len(proxy_list, -1, "socks=")) != NULL) {
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
459
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
460 specific += strlen("socks=");
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
461 tmp = strchr(specific, ';');
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
462 if (tmp)
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
463 *tmp = '\0';
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
464 /* specific now points the proxy server (and port) */
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
465
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
466 purple_proxy_info_set_type(&info, PURPLE_PROXY_SOCKS5);
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
467 _proxy_fill_hostinfo(&info, specific, 1080);
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
468 /* TODO: is there a way to set the username/password? */
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
469 purple_proxy_info_set_username(&info, NULL);
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
470 purple_proxy_info_set_password(&info, NULL);
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
471
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
472 purple_debug_info("proxy", "Windows Proxy Settings: SOCKS5 proxy: '%s:%d'.\n",
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
473 purple_proxy_info_get_host(&info),
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
474 purple_proxy_info_get_port(&info));
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
475
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
476 } else {
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
477
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
478 purple_debug_info("proxy", "Windows Proxy Settings: No supported proxy specified.\n");
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
479
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
480 purple_proxy_info_set_type(&info, PURPLE_PROXY_NONE);
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
481
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
482 }
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
483 }
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
484
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
485 /* TODO: Fix API to be able look at proxy bypass settings */
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
486
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
487 g_free(proxy_list);
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
488 } else {
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
489 purple_debug_info("proxy", "No Windows proxy set.\n");
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
490 purple_proxy_info_set_type(&info, PURPLE_PROXY_NONE);
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
491 }
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
492
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
493 if (ie_proxy_config.lpszAutoConfigUrl)
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
494 GlobalFree(ie_proxy_config.lpszAutoConfigUrl);
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
495 if (ie_proxy_config.lpszProxy)
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
496 GlobalFree(ie_proxy_config.lpszProxy);
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
497 if (ie_proxy_config.lpszProxyBypass)
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
498 GlobalFree(ie_proxy_config.lpszProxyBypass);
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
499
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
500 return &info;
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
501 }
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
502 #endif
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
503
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
504
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
505 /**************************************************************************
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
506 * Proxy API
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
507 **************************************************************************/
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
508
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
509 /**
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
510 * Whoever calls this needs to have called
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
511 * purple_proxy_connect_data_disconnect() beforehand.
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
512 */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
513 static void
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
514 purple_proxy_connect_data_destroy(PurpleProxyConnectData *connect_data)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
515 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
516 handles = g_slist_remove(handles, connect_data);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
517
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
518 if (connect_data->query_data != NULL)
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
519 purple_dnsquery_destroy(connect_data->query_data);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
520
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
521 while (connect_data->hosts != NULL)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
522 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
523 /* Discard the length... */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
524 connect_data->hosts = g_slist_remove(connect_data->hosts, connect_data->hosts->data);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
525 /* Free the address... */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
526 g_free(connect_data->hosts->data);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
527 connect_data->hosts = g_slist_remove(connect_data->hosts, connect_data->hosts->data);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
528 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
529
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
530 g_free(connect_data->host);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
531 g_free(connect_data);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
532 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
533
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
534 /**
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
535 * Free all information dealing with a connection attempt and
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
536 * reset the connect_data to prepare for it to try to connect
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
537 * to another IP address.
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
538 *
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
539 * If an error message is passed in, then we know the connection
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
540 * attempt failed. If the connection attempt failed and
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
541 * connect_data->hosts is not empty then we try the next IP address.
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
542 * If the connection attempt failed and we have no more hosts
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
543 * try try then we call the callback with the given error message,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
544 * then destroy the connect_data.
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
545 *
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
546 * @param error_message An error message explaining why the connection
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
547 * failed. This will be passed to the callback function
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
548 * specified in the call to purple_proxy_connect(). If the
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
549 * connection was successful then pass in null.
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
550 */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
551 static void
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
552 purple_proxy_connect_data_disconnect(PurpleProxyConnectData *connect_data, const gchar *error_message)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
553 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
554 if (connect_data->inpa > 0)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
555 {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
556 purple_input_remove(connect_data->inpa);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
557 connect_data->inpa = 0;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
558 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
559
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
560 if (connect_data->fd >= 0)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
561 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
562 close(connect_data->fd);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
563 connect_data->fd = -1;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
564 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
565
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
566 g_free(connect_data->write_buffer);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
567 connect_data->write_buffer = NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
568
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
569 g_free(connect_data->read_buffer);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
570 connect_data->read_buffer = NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
571
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
572 if (error_message != NULL)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
573 {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
574 purple_debug_info("proxy", "Connection attempt failed: %s\n",
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
575 error_message);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
576 if (connect_data->hosts != NULL)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
577 try_connect(connect_data);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
578 else
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
579 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
580 /* Everything failed! Tell the originator of the request. */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
581 connect_data->connect_cb(connect_data->data, -1, error_message);
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
582 purple_proxy_connect_data_destroy(connect_data);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
583 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
584 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
585 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
586
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
587 /**
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
588 * This calls purple_proxy_connect_data_disconnect(), but it lets you
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
589 * specify the error_message using a printf()-like syntax.
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
590 */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
591 static void
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
592 purple_proxy_connect_data_disconnect_formatted(PurpleProxyConnectData *connect_data, const char *format, ...)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
593 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
594 va_list args;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
595 gchar *tmp;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
596
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
597 va_start(args, format);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
598 tmp = g_strdup_vprintf(format, args);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
599 va_end(args);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
600
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
601 purple_proxy_connect_data_disconnect(connect_data, tmp);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
602 g_free(tmp);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
603 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
604
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
605 static void
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
606 purple_proxy_connect_data_connected(PurpleProxyConnectData *connect_data)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
607 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
608 connect_data->connect_cb(connect_data->data, connect_data->fd, NULL);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
609
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
610 /*
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
611 * We've passed the file descriptor to the protocol, so it's no longer
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
612 * our responsibility, and we should be careful not to free it when
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
613 * we destroy the connect_data.
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
614 */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
615 connect_data->fd = -1;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
616
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
617 purple_proxy_connect_data_disconnect(connect_data, NULL);
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
618 purple_proxy_connect_data_destroy(connect_data);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
619 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
620
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
621 static void
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
622 socket_ready_cb(gpointer data, gint source, PurpleInputCondition cond)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
623 {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
624 PurpleProxyConnectData *connect_data = data;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
625 int error = 0;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
626 int ret;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
627
15976
a6a79b8616bf I commonly see a crash in which socket_ready_cb(), shortly after a laptop wakes from sleep, is passed invalid (previously freed) connect_data. It looks like this:
Evan Schoenberg <evan.s@dreskin.net>
parents: 15822
diff changeset
628 /* If the socket-connected message had already been triggered when connect_data
a6a79b8616bf I commonly see a crash in which socket_ready_cb(), shortly after a laptop wakes from sleep, is passed invalid (previously freed) connect_data. It looks like this:
Evan Schoenberg <evan.s@dreskin.net>
parents: 15822
diff changeset
629 * was destroyed via purple_proxy_connect_cancel(), we may get here with a freed connect_data.
a6a79b8616bf I commonly see a crash in which socket_ready_cb(), shortly after a laptop wakes from sleep, is passed invalid (previously freed) connect_data. It looks like this:
Evan Schoenberg <evan.s@dreskin.net>
parents: 15822
diff changeset
630 */
a6a79b8616bf I commonly see a crash in which socket_ready_cb(), shortly after a laptop wakes from sleep, is passed invalid (previously freed) connect_data. It looks like this:
Evan Schoenberg <evan.s@dreskin.net>
parents: 15822
diff changeset
631 if (!PURPLE_PROXY_CONNECT_DATA_IS_VALID(connect_data))
a6a79b8616bf I commonly see a crash in which socket_ready_cb(), shortly after a laptop wakes from sleep, is passed invalid (previously freed) connect_data. It looks like this:
Evan Schoenberg <evan.s@dreskin.net>
parents: 15822
diff changeset
632 return;
20039
1846fd2da2b4 Fix proxy settings to be loaded correctly when libpurple is initialized. This was broken because it relied on the prefs being loaded after proxy initialization so that the pref callbacks would be triggered and I changed the prefs loading to happen right at the beginning to fix other issues. Fixes #3092.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 19781
diff changeset
633
24749
333f03472486 This string appears before the connection attempt, so it shouldn't be
Kevin Stange <kevin@simguy.net>
parents: 24119
diff changeset
634 purple_debug_info("proxy", "Connecting to %s:%d.\n",
15681
14d85ee22d78 Added a new GaimEventLoopUiOps item, input_get_error(). This function allows the UI to return the current error status on a socket/input. If the UI does not implement it (as Pidgin and gntgaim do not, since glib's handling of sockets is sane), it is just a wrapper around getsockopt(). Implemented or not, its return values should match those of getsockopt() with a level of SOL_SOCKET and an option of SO_ERROR. For curious souls, Adium will be using this to provide a working version of getsockopt(); the CoreFoundation CFSocket class which is used for socket read/write calls getsockopt() with SO_ERROR itself, thereby clearing the error flag [as documented in getsockopt()'s behavior], so depending upon it for determining if an error occurred leads to significant misbehavior.
Evan Schoenberg <evan.s@dreskin.net>
parents: 15497
diff changeset
635 connect_data->host, connect_data->port);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
636
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
637 /*
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
638 * purple_input_get_error after a non-blocking connect returns -1 if something is
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
639 * really messed up (bad descriptor, usually). Otherwise, it returns 0 and
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
640 * error holds what connect would have returned if it blocked until now.
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
641 * Thus, error == 0 is success, error == EINPROGRESS means "try again",
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
642 * and anything else is a real error.
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
643 *
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
644 * (error == EINPROGRESS can happen after a select because the kernel can
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
645 * be overly optimistic sometimes. select is just a hint that you might be
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
646 * able to do something.)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
647 */
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
648 ret = purple_input_get_error(connect_data->fd, &error);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
649
15681
14d85ee22d78 Added a new GaimEventLoopUiOps item, input_get_error(). This function allows the UI to return the current error status on a socket/input. If the UI does not implement it (as Pidgin and gntgaim do not, since glib's handling of sockets is sane), it is just a wrapper around getsockopt(). Implemented or not, its return values should match those of getsockopt() with a level of SOL_SOCKET and an option of SO_ERROR. For curious souls, Adium will be using this to provide a working version of getsockopt(); the CoreFoundation CFSocket class which is used for socket read/write calls getsockopt() with SO_ERROR itself, thereby clearing the error flag [as documented in getsockopt()'s behavior], so depending upon it for determining if an error occurred leads to significant misbehavior.
Evan Schoenberg <evan.s@dreskin.net>
parents: 15497
diff changeset
650 if (ret == 0 && error == EINPROGRESS) {
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
651 /* No worries - we'll be called again later */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
652 /* TODO: Does this ever happen? */
19654
941965d6fd88 Patch from QuLogic. Fixes #2903 ('Missing newlines in debug messages.')
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 17431
diff changeset
653 purple_debug_info("proxy", "(ret == 0 && error == EINPROGRESS)\n");
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
654 return;
15681
14d85ee22d78 Added a new GaimEventLoopUiOps item, input_get_error(). This function allows the UI to return the current error status on a socket/input. If the UI does not implement it (as Pidgin and gntgaim do not, since glib's handling of sockets is sane), it is just a wrapper around getsockopt(). Implemented or not, its return values should match those of getsockopt() with a level of SOL_SOCKET and an option of SO_ERROR. For curious souls, Adium will be using this to provide a working version of getsockopt(); the CoreFoundation CFSocket class which is used for socket read/write calls getsockopt() with SO_ERROR itself, thereby clearing the error flag [as documented in getsockopt()'s behavior], so depending upon it for determining if an error occurred leads to significant misbehavior.
Evan Schoenberg <evan.s@dreskin.net>
parents: 15497
diff changeset
655 }
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
656
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
657 if (ret != 0 || error != 0) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
658 if (ret != 0)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
659 error = errno;
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
660 purple_debug_info("proxy", "Error connecting to %s:%d (%s).\n",
21121
35b4f1dc4c8d replace most calls to strerror with calls to g_strerror. strerror will return
Nathan Walp <nwalp@pidgin.im>
parents: 21015
diff changeset
661 connect_data->host, connect_data->port, g_strerror(error));
15681
14d85ee22d78 Added a new GaimEventLoopUiOps item, input_get_error(). This function allows the UI to return the current error status on a socket/input. If the UI does not implement it (as Pidgin and gntgaim do not, since glib's handling of sockets is sane), it is just a wrapper around getsockopt(). Implemented or not, its return values should match those of getsockopt() with a level of SOL_SOCKET and an option of SO_ERROR. For curious souls, Adium will be using this to provide a working version of getsockopt(); the CoreFoundation CFSocket class which is used for socket read/write calls getsockopt() with SO_ERROR itself, thereby clearing the error flag [as documented in getsockopt()'s behavior], so depending upon it for determining if an error occurred leads to significant misbehavior.
Evan Schoenberg <evan.s@dreskin.net>
parents: 15497
diff changeset
662
21121
35b4f1dc4c8d replace most calls to strerror with calls to g_strerror. strerror will return
Nathan Walp <nwalp@pidgin.im>
parents: 21015
diff changeset
663 purple_proxy_connect_data_disconnect(connect_data, g_strerror(error));
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
664 return;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
665 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
666
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
667 purple_proxy_connect_data_connected(connect_data);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
668 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
669
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
670 static gboolean
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
671 clean_connect(gpointer data)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
672 {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
673 purple_proxy_connect_data_connected(data);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
674
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
675 return FALSE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
676 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
677
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
678 static void
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
679 proxy_connect_none(PurpleProxyConnectData *connect_data, struct sockaddr *addr, socklen_t addrlen)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
680 {
20347
04fe5601fedb applied changes from 2762c6075c0dc52a96098c5478c5bf68cfd890a3
Luke Schierer <lschiere@pidgin.im>
parents: 20074
diff changeset
681 int flags;
04fe5601fedb applied changes from 2762c6075c0dc52a96098c5478c5bf68cfd890a3
Luke Schierer <lschiere@pidgin.im>
parents: 20074
diff changeset
682
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
683 purple_debug_info("proxy", "Connecting to %s:%d with no proxy\n",
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
684 connect_data->host, connect_data->port);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
685
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
686 connect_data->fd = socket(addr->sa_family, SOCK_STREAM, 0);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
687 if (connect_data->fd < 0)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
688 {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
689 purple_proxy_connect_data_disconnect_formatted(connect_data,
21121
35b4f1dc4c8d replace most calls to strerror with calls to g_strerror. strerror will return
Nathan Walp <nwalp@pidgin.im>
parents: 21015
diff changeset
690 _("Unable to create socket:\n%s"), g_strerror(errno));
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
691 return;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
692 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
693
20347
04fe5601fedb applied changes from 2762c6075c0dc52a96098c5478c5bf68cfd890a3
Luke Schierer <lschiere@pidgin.im>
parents: 20074
diff changeset
694 flags = fcntl(connect_data->fd, F_GETFL);
04fe5601fedb applied changes from 2762c6075c0dc52a96098c5478c5bf68cfd890a3
Luke Schierer <lschiere@pidgin.im>
parents: 20074
diff changeset
695 fcntl(connect_data->fd, F_SETFL, flags | O_NONBLOCK);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
696 #ifndef _WIN32
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
697 fcntl(connect_data->fd, F_SETFD, FD_CLOEXEC);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
698 #endif
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
699
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
700 if (connect(connect_data->fd, addr, addrlen) != 0)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
701 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
702 if ((errno == EINPROGRESS) || (errno == EINTR))
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
703 {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
704 purple_debug_info("proxy", "Connection in progress\n");
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
705 connect_data->inpa = purple_input_add(connect_data->fd,
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
706 PURPLE_INPUT_WRITE, socket_ready_cb, connect_data);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
707 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
708 else
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
709 {
21121
35b4f1dc4c8d replace most calls to strerror with calls to g_strerror. strerror will return
Nathan Walp <nwalp@pidgin.im>
parents: 21015
diff changeset
710 purple_proxy_connect_data_disconnect(connect_data, g_strerror(errno));
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
711 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
712 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
713 else
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
714 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
715 /*
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
716 * The connection happened IMMEDIATELY... strange, but whatever.
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
717 */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
718 int error = ETIMEDOUT;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
719 int ret;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
720
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
721 purple_debug_info("proxy", "Connected immediately.\n");
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
722
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
723 ret = purple_input_get_error(connect_data->fd, &error);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
724 if ((ret != 0) || (error != 0))
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
725 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
726 if (ret != 0)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
727 error = errno;
21121
35b4f1dc4c8d replace most calls to strerror with calls to g_strerror. strerror will return
Nathan Walp <nwalp@pidgin.im>
parents: 21015
diff changeset
728 purple_proxy_connect_data_disconnect(connect_data, g_strerror(error));
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
729 return;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
730 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
731
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
732 /*
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
733 * We want to call the "connected" callback eventually, but we
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
734 * don't want to call it before we return, just in case.
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
735 */
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
736 purple_timeout_add(10, clean_connect, connect_data);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
737 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
738 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
739
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
740 /**
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
741 * This is a utility function used by the HTTP, SOCKS4 and SOCKS5
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
742 * connect functions. It writes data from a buffer to a socket.
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
743 * When all the data is written it sets up a watcher to read a
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
744 * response and call a specified function.
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
745 */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
746 static void
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
747 proxy_do_write(gpointer data, gint source, PurpleInputCondition cond)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
748 {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
749 PurpleProxyConnectData *connect_data;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
750 const guchar *request;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
751 gsize request_len;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
752 int ret;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
753
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
754 connect_data = data;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
755 request = connect_data->write_buffer + connect_data->written_len;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
756 request_len = connect_data->write_buf_len - connect_data->written_len;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
757
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
758 ret = write(connect_data->fd, request, request_len);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
759 if (ret <= 0)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
760 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
761 if (errno == EAGAIN)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
762 /* No worries */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
763 return;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
764
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
765 /* Error! */
21121
35b4f1dc4c8d replace most calls to strerror with calls to g_strerror. strerror will return
Nathan Walp <nwalp@pidgin.im>
parents: 21015
diff changeset
766 purple_proxy_connect_data_disconnect(connect_data, g_strerror(errno));
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
767 return;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
768 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
769 if (ret < request_len) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
770 connect_data->written_len += ret;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
771 return;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
772 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
773
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
774 /* We're done writing data! Wait for a response. */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
775 g_free(connect_data->write_buffer);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
776 connect_data->write_buffer = NULL;
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
777 purple_input_remove(connect_data->inpa);
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
778 connect_data->inpa = purple_input_add(connect_data->fd,
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
779 PURPLE_INPUT_READ, connect_data->read_cb, connect_data);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
780 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
781
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
782 #define HTTP_GOODSTRING "HTTP/1.0 200"
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
783 #define HTTP_GOODSTRING2 "HTTP/1.1 200"
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
784
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
785 /**
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
786 * We're using an HTTP proxy for a non-port 80 tunnel. Read the
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
787 * response to the CONNECT request.
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
788 */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
789 static void
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
790 http_canread(gpointer data, gint source, PurpleInputCondition cond)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
791 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
792 int len, headers_len, status = 0;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
793 gboolean error;
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
794 PurpleProxyConnectData *connect_data = data;
17431
79ecaab86f91 Eliminate some type punning warnings in proxy.c. This was inspired by a
Richard Laager <rlaager@wiktel.com>
parents: 17372
diff changeset
795 char *p;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
796 gsize max_read;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
797
23992
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23970
diff changeset
798 if (connect_data->read_buffer == NULL) {
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
799 connect_data->read_buf_len = 8192;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
800 connect_data->read_buffer = g_malloc(connect_data->read_buf_len);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
801 connect_data->read_len = 0;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
802 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
803
17431
79ecaab86f91 Eliminate some type punning warnings in proxy.c. This was inspired by a
Richard Laager <rlaager@wiktel.com>
parents: 17372
diff changeset
804 p = (char *)connect_data->read_buffer + connect_data->read_len;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
805 max_read = connect_data->read_buf_len - connect_data->read_len - 1;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
806
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
807 len = read(connect_data->fd, p, max_read);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
808
23992
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23970
diff changeset
809 if (len == 0) {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
810 purple_proxy_connect_data_disconnect(connect_data,
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
811 _("Server closed the connection."));
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
812 return;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
813 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
814
23992
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23970
diff changeset
815 if (len < 0) {
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
816 if (errno == EAGAIN)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
817 /* No worries */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
818 return;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
819
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
820 /* Error! */
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
821 purple_proxy_connect_data_disconnect_formatted(connect_data,
21121
35b4f1dc4c8d replace most calls to strerror with calls to g_strerror. strerror will return
Nathan Walp <nwalp@pidgin.im>
parents: 21015
diff changeset
822 _("Lost connection with server:\n%s"), g_strerror(errno));
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
823 return;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
824 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
825
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
826 connect_data->read_len += len;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
827 p[len] = '\0';
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
828
17431
79ecaab86f91 Eliminate some type punning warnings in proxy.c. This was inspired by a
Richard Laager <rlaager@wiktel.com>
parents: 17372
diff changeset
829 p = g_strstr_len((const gchar *)connect_data->read_buffer,
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
830 connect_data->read_len, "\r\n\r\n");
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
831 if (p != NULL) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
832 *p = '\0';
17431
79ecaab86f91 Eliminate some type punning warnings in proxy.c. This was inspired by a
Richard Laager <rlaager@wiktel.com>
parents: 17372
diff changeset
833 headers_len = (p - (char *)connect_data->read_buffer) + 4;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
834 } else if(len == max_read)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
835 headers_len = len;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
836 else
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
837 return;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
838
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
839 error = strncmp((const char *)connect_data->read_buffer, "HTTP/", 5) != 0;
23992
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23970
diff changeset
840 if (!error) {
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
841 int major;
17431
79ecaab86f91 Eliminate some type punning warnings in proxy.c. This was inspired by a
Richard Laager <rlaager@wiktel.com>
parents: 17372
diff changeset
842 p = (char *)connect_data->read_buffer + 5;
79ecaab86f91 Eliminate some type punning warnings in proxy.c. This was inspired by a
Richard Laager <rlaager@wiktel.com>
parents: 17372
diff changeset
843 major = strtol(p, &p, 10);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
844 error = (major == 0) || (*p != '.');
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
845 if(!error) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
846 int minor;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
847 p++;
17431
79ecaab86f91 Eliminate some type punning warnings in proxy.c. This was inspired by a
Richard Laager <rlaager@wiktel.com>
parents: 17372
diff changeset
848 minor = strtol(p, &p, 10);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
849 error = (*p != ' ');
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
850 if(!error) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
851 p++;
17431
79ecaab86f91 Eliminate some type punning warnings in proxy.c. This was inspired by a
Richard Laager <rlaager@wiktel.com>
parents: 17372
diff changeset
852 status = strtol(p, &p, 10);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
853 error = (*p != ' ');
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
854 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
855 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
856 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
857
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
858 /* Read the contents */
17431
79ecaab86f91 Eliminate some type punning warnings in proxy.c. This was inspired by a
Richard Laager <rlaager@wiktel.com>
parents: 17372
diff changeset
859 p = g_strrstr((const gchar *)connect_data->read_buffer, "Content-Length: ");
23992
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23970
diff changeset
860 if (p != NULL) {
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
861 gchar *tmp;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
862 int len = 0;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
863 char tmpc;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
864 p += strlen("Content-Length: ");
17431
79ecaab86f91 Eliminate some type punning warnings in proxy.c. This was inspired by a
Richard Laager <rlaager@wiktel.com>
parents: 17372
diff changeset
865 tmp = strchr(p, '\r');
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
866 if(tmp)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
867 *tmp = '\0';
17431
79ecaab86f91 Eliminate some type punning warnings in proxy.c. This was inspired by a
Richard Laager <rlaager@wiktel.com>
parents: 17372
diff changeset
868 len = atoi(p);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
869 if(tmp)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
870 *tmp = '\r';
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
871
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
872 /* Compensate for what has already been read */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
873 len -= connect_data->read_len - headers_len;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
874 /* I'm assuming that we're doing this to prevent the server from
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
875 complaining / breaking since we don't read the whole page */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
876 while (len--) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
877 /* TODO: deal with EAGAIN (and other errors) better */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
878 if (read(connect_data->fd, &tmpc, 1) < 0 && errno != EAGAIN)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
879 break;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
880 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
881 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
882
23992
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23970
diff changeset
883 if (error) {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
884 purple_proxy_connect_data_disconnect_formatted(connect_data,
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
885 _("Unable to parse response from HTTP proxy: %s\n"),
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
886 connect_data->read_buffer);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
887 return;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
888 }
23992
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23970
diff changeset
889 else if (status != 200) {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
890 purple_debug_error("proxy",
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
891 "Proxy server replied with:\n%s\n",
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
892 connect_data->read_buffer);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
893
23992
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23970
diff changeset
894 if (status == 407 /* Proxy Auth */) {
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23970
diff changeset
895 const char *header;
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23970
diff changeset
896 gchar *request;
19781
6dcab2412c22 This is parts 1 and 2 of patch #2910 from Vladimir (thecrux) to improve NTLM proxy handling. Specifically, it specifies that we're using Unicode strings and uses the hostname of the local machine instead of incorrectly using the proxy server's hostname for authentication. References #2910.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 19681
diff changeset
897
23992
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23970
diff changeset
898 header = g_strrstr((const gchar *)connect_data->read_buffer,
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23970
diff changeset
899 "Proxy-Authenticate: NTLM");
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23970
diff changeset
900 if (header != NULL) {
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23970
diff changeset
901 const char *header_end = header + strlen("Proxy-Authenticate: NTLM");
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23970
diff changeset
902 const char *domain = purple_proxy_info_get_username(connect_data->gpi);
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23970
diff changeset
903 char *username = NULL, hostname[256];
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23970
diff changeset
904 gchar *response;
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23970
diff changeset
905 int ret;
19781
6dcab2412c22 This is parts 1 and 2 of patch #2910 from Vladimir (thecrux) to improve NTLM proxy handling. Specifically, it specifies that we're using Unicode strings and uses the hostname of the local machine instead of incorrectly using the proxy server's hostname for authentication. References #2910.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 19681
diff changeset
906
23992
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23970
diff changeset
907 ret = gethostname(hostname, sizeof(hostname));
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23970
diff changeset
908 hostname[sizeof(hostname) - 1] = '\0';
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23970
diff changeset
909 if (ret < 0 || hostname[0] == '\0') {
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23970
diff changeset
910 purple_debug_warning("proxy", "gethostname() failed -- is your hostname set?");
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23970
diff changeset
911 strcpy(hostname, "localhost");
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23970
diff changeset
912 }
19781
6dcab2412c22 This is parts 1 and 2 of patch #2910 from Vladimir (thecrux) to improve NTLM proxy handling. Specifically, it specifies that we're using Unicode strings and uses the hostname of the local machine instead of incorrectly using the proxy server's hostname for authentication. References #2910.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 19681
diff changeset
913
20359
36da9249f3a9 applied changes from e33c17e58da161b8cffaf13e9d79e9bb4b9ce4ce
Luke Schierer <lschiere@pidgin.im>
parents: 20347
diff changeset
914 if (domain != NULL)
23992
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23970
diff changeset
915 username = (char*) strchr(domain, '\\');
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23970
diff changeset
916 if (username == NULL) {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
917 purple_proxy_connect_data_disconnect_formatted(connect_data,
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
918 _("HTTP proxy connection error %d"), status);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
919 return;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
920 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
921 *username = '\0';
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
922
23992
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23970
diff changeset
923 /* Is there a message? */
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23970
diff changeset
924 if (*header_end == ' ') {
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23970
diff changeset
925 /* Check for Type-2 */
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23970
diff changeset
926 char *tmp = (char*) header;
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23970
diff changeset
927 guint8 *nonce;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
928
23992
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23970
diff changeset
929 header_end++;
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23970
diff changeset
930 username++;
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23970
diff changeset
931 while(*tmp != '\r' && *tmp != '\0') tmp++;
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23970
diff changeset
932 *tmp = '\0';
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23970
diff changeset
933 nonce = purple_ntlm_parse_type2(header_end, NULL);
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23970
diff changeset
934 response = purple_ntlm_gen_type3(username,
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23970
diff changeset
935 (gchar*) purple_proxy_info_get_password(connect_data->gpi),
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23970
diff changeset
936 hostname,
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23970
diff changeset
937 domain, nonce, NULL);
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23970
diff changeset
938 username--;
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23970
diff changeset
939 } else /* Empty message */
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23970
diff changeset
940 response = purple_ntlm_gen_type1(hostname, domain);
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23970
diff changeset
941
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
942 *username = '\\';
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
943
23992
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23970
diff changeset
944 request = g_strdup_printf(
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23970
diff changeset
945 "CONNECT %s:%d HTTP/1.1\r\n"
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23970
diff changeset
946 "Host: %s:%d\r\n"
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23970
diff changeset
947 "Proxy-Authorization: NTLM %s\r\n"
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23970
diff changeset
948 "Proxy-Connection: Keep-Alive\r\n\r\n",
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23970
diff changeset
949 connect_data->host, connect_data->port,
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23970
diff changeset
950 connect_data->host, connect_data->port,
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23970
diff changeset
951 response);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
952
23992
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23970
diff changeset
953 g_free(response);
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23970
diff changeset
954
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23970
diff changeset
955 } else if((header = g_strrstr((const char *)connect_data->read_buffer, "Proxy-Authenticate: Basic"))) {
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23970
diff changeset
956 gchar *t1, *t2;
24526
f3103f786c86 Prevent a NULL printf crash.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24453
diff changeset
957 const char *username, *password;
f3103f786c86 Prevent a NULL printf crash.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24453
diff changeset
958
f3103f786c86 Prevent a NULL printf crash.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24453
diff changeset
959 username = purple_proxy_info_get_username(connect_data->gpi);
f3103f786c86 Prevent a NULL printf crash.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24453
diff changeset
960 password = purple_proxy_info_get_password(connect_data->gpi);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
961
23992
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23970
diff changeset
962 t1 = g_strdup_printf("%s:%s",
24526
f3103f786c86 Prevent a NULL printf crash.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24453
diff changeset
963 username ? username : "",
f3103f786c86 Prevent a NULL printf crash.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24453
diff changeset
964 password ? password : "");
f3103f786c86 Prevent a NULL printf crash.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24453
diff changeset
965 t2 = purple_base64_encode((guchar *)t1, strlen(t1));
23992
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23970
diff changeset
966 g_free(t1);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
967
23992
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23970
diff changeset
968 request = g_strdup_printf(
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23970
diff changeset
969 "CONNECT %s:%d HTTP/1.1\r\n"
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23970
diff changeset
970 "Host: %s:%d\r\n"
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23970
diff changeset
971 "Proxy-Authorization: Basic %s\r\n",
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23970
diff changeset
972 connect_data->host, connect_data->port,
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23970
diff changeset
973 connect_data->host, connect_data->port,
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23970
diff changeset
974 t2);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
975
23992
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23970
diff changeset
976 g_free(t2);
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23970
diff changeset
977
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
978 } else {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
979 purple_proxy_connect_data_disconnect_formatted(connect_data,
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
980 _("HTTP proxy connection error %d"), status);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
981 return;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
982 }
23992
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23970
diff changeset
983
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23970
diff changeset
984 purple_input_remove(connect_data->inpa);
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23970
diff changeset
985 g_free(connect_data->read_buffer);
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23970
diff changeset
986 connect_data->read_buffer = NULL;
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23970
diff changeset
987
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23970
diff changeset
988 connect_data->write_buffer = (guchar *)request;
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23970
diff changeset
989 connect_data->write_buf_len = strlen(request);
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23970
diff changeset
990 connect_data->written_len = 0;
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23970
diff changeset
991
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23970
diff changeset
992 connect_data->read_cb = http_canread;
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23970
diff changeset
993
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23970
diff changeset
994 connect_data->inpa = purple_input_add(connect_data->fd,
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23970
diff changeset
995 PURPLE_INPUT_WRITE, proxy_do_write, connect_data);
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23970
diff changeset
996
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23970
diff changeset
997 proxy_do_write(connect_data, connect_data->fd, cond);
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23970
diff changeset
998
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23970
diff changeset
999 return;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1000 }
23992
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23970
diff changeset
1001
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23970
diff changeset
1002 if (status == 403) {
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1003 /* Forbidden */
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
1004 purple_proxy_connect_data_disconnect_formatted(connect_data,
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1005 _("Access denied: HTTP proxy server forbids port %d tunneling."),
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1006 connect_data->port);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1007 } else {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
1008 purple_proxy_connect_data_disconnect_formatted(connect_data,
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1009 _("HTTP proxy connection error %d"), status);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1010 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1011 } else {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
1012 purple_input_remove(connect_data->inpa);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1013 connect_data->inpa = 0;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1014 g_free(connect_data->read_buffer);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1015 connect_data->read_buffer = NULL;
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
1016 purple_debug_info("proxy", "HTTP proxy connection established\n");
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
1017 purple_proxy_connect_data_connected(connect_data);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1018 return;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1019 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1020 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1021
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1022 static void
23010
2b91ea8c94d5 Rearrange some of the HTTP proxy handling to make sure that we're actually
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23008
diff changeset
1023 http_start_connect_tunneling(PurpleProxyConnectData *connect_data) {
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1024 GString *request;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1025 int ret;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1026
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
1027 purple_debug_info("proxy", "Using CONNECT tunneling for %s:%d\n",
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1028 connect_data->host, connect_data->port);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1029
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1030 request = g_string_sized_new(4096);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1031 g_string_append_printf(request,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1032 "CONNECT %s:%d HTTP/1.1\r\nHost: %s:%d\r\n",
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1033 connect_data->host, connect_data->port,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1034 connect_data->host, connect_data->port);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1035
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
1036 if (purple_proxy_info_get_username(connect_data->gpi) != NULL)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1037 {
22322
01e814b7556b Patch from eperez to plug a leak in the ntlm proxy authentication. Fixes #4702
Daniel Atallah <daniel.atallah@gmail.com>
parents: 21121
diff changeset
1038 char *t1, *t2, *ntlm_type1;
19781
6dcab2412c22 This is parts 1 and 2 of patch #2910 from Vladimir (thecrux) to improve NTLM proxy handling. Specifically, it specifies that we're using Unicode strings and uses the hostname of the local machine instead of incorrectly using the proxy server's hostname for authentication. References #2910.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 19681
diff changeset
1039 char hostname[256];
6dcab2412c22 This is parts 1 and 2 of patch #2910 from Vladimir (thecrux) to improve NTLM proxy handling. Specifically, it specifies that we're using Unicode strings and uses the hostname of the local machine instead of incorrectly using the proxy server's hostname for authentication. References #2910.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 19681
diff changeset
1040
6dcab2412c22 This is parts 1 and 2 of patch #2910 from Vladimir (thecrux) to improve NTLM proxy handling. Specifically, it specifies that we're using Unicode strings and uses the hostname of the local machine instead of incorrectly using the proxy server's hostname for authentication. References #2910.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 19681
diff changeset
1041 ret = gethostname(hostname, sizeof(hostname));
6dcab2412c22 This is parts 1 and 2 of patch #2910 from Vladimir (thecrux) to improve NTLM proxy handling. Specifically, it specifies that we're using Unicode strings and uses the hostname of the local machine instead of incorrectly using the proxy server's hostname for authentication. References #2910.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 19681
diff changeset
1042 hostname[sizeof(hostname) - 1] = '\0';
6dcab2412c22 This is parts 1 and 2 of patch #2910 from Vladimir (thecrux) to improve NTLM proxy handling. Specifically, it specifies that we're using Unicode strings and uses the hostname of the local machine instead of incorrectly using the proxy server's hostname for authentication. References #2910.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 19681
diff changeset
1043 if (ret < 0 || hostname[0] == '\0') {
6dcab2412c22 This is parts 1 and 2 of patch #2910 from Vladimir (thecrux) to improve NTLM proxy handling. Specifically, it specifies that we're using Unicode strings and uses the hostname of the local machine instead of incorrectly using the proxy server's hostname for authentication. References #2910.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 19681
diff changeset
1044 purple_debug_warning("proxy", "gethostname() failed -- is your hostname set?");
6dcab2412c22 This is parts 1 and 2 of patch #2910 from Vladimir (thecrux) to improve NTLM proxy handling. Specifically, it specifies that we're using Unicode strings and uses the hostname of the local machine instead of incorrectly using the proxy server's hostname for authentication. References #2910.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 19681
diff changeset
1045 strcpy(hostname, "localhost");
6dcab2412c22 This is parts 1 and 2 of patch #2910 from Vladimir (thecrux) to improve NTLM proxy handling. Specifically, it specifies that we're using Unicode strings and uses the hostname of the local machine instead of incorrectly using the proxy server's hostname for authentication. References #2910.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 19681
diff changeset
1046 }
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1047
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1048 t1 = g_strdup_printf("%s:%s",
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
1049 purple_proxy_info_get_username(connect_data->gpi),
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
1050 purple_proxy_info_get_password(connect_data->gpi) ?
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
1051 purple_proxy_info_get_password(connect_data->gpi) : "");
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
1052 t2 = purple_base64_encode((const guchar *)t1, strlen(t1));
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1053 g_free(t1);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1054
22322
01e814b7556b Patch from eperez to plug a leak in the ntlm proxy authentication. Fixes #4702
Daniel Atallah <daniel.atallah@gmail.com>
parents: 21121
diff changeset
1055 ntlm_type1 = purple_ntlm_gen_type1(hostname, "");
01e814b7556b Patch from eperez to plug a leak in the ntlm proxy authentication. Fixes #4702
Daniel Atallah <daniel.atallah@gmail.com>
parents: 21121
diff changeset
1056
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1057 g_string_append_printf(request,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1058 "Proxy-Authorization: Basic %s\r\n"
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1059 "Proxy-Authorization: NTLM %s\r\n"
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1060 "Proxy-Connection: Keep-Alive\r\n",
22322
01e814b7556b Patch from eperez to plug a leak in the ntlm proxy authentication. Fixes #4702
Daniel Atallah <daniel.atallah@gmail.com>
parents: 21121
diff changeset
1061 t2, ntlm_type1);
01e814b7556b Patch from eperez to plug a leak in the ntlm proxy authentication. Fixes #4702
Daniel Atallah <daniel.atallah@gmail.com>
parents: 21121
diff changeset
1062 g_free(ntlm_type1);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1063 g_free(t2);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1064 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1065
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1066 g_string_append(request, "\r\n");
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1067
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1068 connect_data->write_buf_len = request->len;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1069 connect_data->write_buffer = (guchar *)g_string_free(request, FALSE);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1070 connect_data->written_len = 0;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1071 connect_data->read_cb = http_canread;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1072
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
1073 connect_data->inpa = purple_input_add(connect_data->fd,
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
1074 PURPLE_INPUT_WRITE, proxy_do_write, connect_data);
23010
2b91ea8c94d5 Rearrange some of the HTTP proxy handling to make sure that we're actually
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23008
diff changeset
1075 proxy_do_write(connect_data, connect_data->fd, PURPLE_INPUT_WRITE);
2b91ea8c94d5 Rearrange some of the HTTP proxy handling to make sure that we're actually
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23008
diff changeset
1076 }
2b91ea8c94d5 Rearrange some of the HTTP proxy handling to make sure that we're actually
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23008
diff changeset
1077
2b91ea8c94d5 Rearrange some of the HTTP proxy handling to make sure that we're actually
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23008
diff changeset
1078 static void
2b91ea8c94d5 Rearrange some of the HTTP proxy handling to make sure that we're actually
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23008
diff changeset
1079 http_canwrite(gpointer data, gint source, PurpleInputCondition cond) {
2b91ea8c94d5 Rearrange some of the HTTP proxy handling to make sure that we're actually
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23008
diff changeset
1080 PurpleProxyConnectData *connect_data = data;
2b91ea8c94d5 Rearrange some of the HTTP proxy handling to make sure that we're actually
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23008
diff changeset
1081 int ret, error = ETIMEDOUT;
2b91ea8c94d5 Rearrange some of the HTTP proxy handling to make sure that we're actually
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23008
diff changeset
1082
2b91ea8c94d5 Rearrange some of the HTTP proxy handling to make sure that we're actually
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23008
diff changeset
1083 purple_debug_info("proxy", "Connected to %s:%d.\n",
2b91ea8c94d5 Rearrange some of the HTTP proxy handling to make sure that we're actually
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23008
diff changeset
1084 connect_data->host, connect_data->port);
2b91ea8c94d5 Rearrange some of the HTTP proxy handling to make sure that we're actually
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23008
diff changeset
1085
2b91ea8c94d5 Rearrange some of the HTTP proxy handling to make sure that we're actually
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23008
diff changeset
1086 if (connect_data->inpa > 0) {
2b91ea8c94d5 Rearrange some of the HTTP proxy handling to make sure that we're actually
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23008
diff changeset
1087 purple_input_remove(connect_data->inpa);
2b91ea8c94d5 Rearrange some of the HTTP proxy handling to make sure that we're actually
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23008
diff changeset
1088 connect_data->inpa = 0;
2b91ea8c94d5 Rearrange some of the HTTP proxy handling to make sure that we're actually
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23008
diff changeset
1089 }
2b91ea8c94d5 Rearrange some of the HTTP proxy handling to make sure that we're actually
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23008
diff changeset
1090
2b91ea8c94d5 Rearrange some of the HTTP proxy handling to make sure that we're actually
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23008
diff changeset
1091 ret = purple_input_get_error(connect_data->fd, &error);
2b91ea8c94d5 Rearrange some of the HTTP proxy handling to make sure that we're actually
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23008
diff changeset
1092 if (ret != 0 || error != 0) {
2b91ea8c94d5 Rearrange some of the HTTP proxy handling to make sure that we're actually
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23008
diff changeset
1093 if (ret != 0)
2b91ea8c94d5 Rearrange some of the HTTP proxy handling to make sure that we're actually
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23008
diff changeset
1094 error = errno;
2b91ea8c94d5 Rearrange some of the HTTP proxy handling to make sure that we're actually
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23008
diff changeset
1095 purple_proxy_connect_data_disconnect(connect_data, g_strerror(error));
2b91ea8c94d5 Rearrange some of the HTTP proxy handling to make sure that we're actually
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23008
diff changeset
1096 return;
2b91ea8c94d5 Rearrange some of the HTTP proxy handling to make sure that we're actually
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23008
diff changeset
1097 }
2b91ea8c94d5 Rearrange some of the HTTP proxy handling to make sure that we're actually
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23008
diff changeset
1098
2b91ea8c94d5 Rearrange some of the HTTP proxy handling to make sure that we're actually
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23008
diff changeset
1099 if (connect_data->port == 80) {
2b91ea8c94d5 Rearrange some of the HTTP proxy handling to make sure that we're actually
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23008
diff changeset
1100 /*
2b91ea8c94d5 Rearrange some of the HTTP proxy handling to make sure that we're actually
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23008
diff changeset
1101 * If we're trying to connect to something running on
2b91ea8c94d5 Rearrange some of the HTTP proxy handling to make sure that we're actually
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23008
diff changeset
1102 * port 80 then we assume the traffic using this
2b91ea8c94d5 Rearrange some of the HTTP proxy handling to make sure that we're actually
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23008
diff changeset
1103 * connection is going to be HTTP traffic. If it's
2b91ea8c94d5 Rearrange some of the HTTP proxy handling to make sure that we're actually
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23008
diff changeset
1104 * not then this will fail (uglily). But it's good
2b91ea8c94d5 Rearrange some of the HTTP proxy handling to make sure that we're actually
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23008
diff changeset
1105 * to avoid using the CONNECT method because it's
2b91ea8c94d5 Rearrange some of the HTTP proxy handling to make sure that we're actually
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23008
diff changeset
1106 * not always allowed.
2b91ea8c94d5 Rearrange some of the HTTP proxy handling to make sure that we're actually
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23008
diff changeset
1107 */
2b91ea8c94d5 Rearrange some of the HTTP proxy handling to make sure that we're actually
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23008
diff changeset
1108 purple_debug_info("proxy", "HTTP proxy connection established\n");
2b91ea8c94d5 Rearrange some of the HTTP proxy handling to make sure that we're actually
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23008
diff changeset
1109 purple_proxy_connect_data_connected(connect_data);
2b91ea8c94d5 Rearrange some of the HTTP proxy handling to make sure that we're actually
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23008
diff changeset
1110 } else {
2b91ea8c94d5 Rearrange some of the HTTP proxy handling to make sure that we're actually
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23008
diff changeset
1111 http_start_connect_tunneling(connect_data);
2b91ea8c94d5 Rearrange some of the HTTP proxy handling to make sure that we're actually
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23008
diff changeset
1112 }
2b91ea8c94d5 Rearrange some of the HTTP proxy handling to make sure that we're actually
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23008
diff changeset
1113
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1114 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1115
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1116 static void
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
1117 proxy_connect_http(PurpleProxyConnectData *connect_data, struct sockaddr *addr, socklen_t addrlen)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1118 {
20347
04fe5601fedb applied changes from 2762c6075c0dc52a96098c5478c5bf68cfd890a3
Luke Schierer <lschiere@pidgin.im>
parents: 20074
diff changeset
1119 int flags;
04fe5601fedb applied changes from 2762c6075c0dc52a96098c5478c5bf68cfd890a3
Luke Schierer <lschiere@pidgin.im>
parents: 20074
diff changeset
1120
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
1121 purple_debug_info("proxy",
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1122 "Connecting to %s:%d via %s:%d using HTTP\n",
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1123 connect_data->host, connect_data->port,
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
1124 (purple_proxy_info_get_host(connect_data->gpi) ? purple_proxy_info_get_host(connect_data->gpi) : "(null)"),
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
1125 purple_proxy_info_get_port(connect_data->gpi));
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1126
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1127 connect_data->fd = socket(addr->sa_family, SOCK_STREAM, 0);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1128 if (connect_data->fd < 0)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1129 {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
1130 purple_proxy_connect_data_disconnect_formatted(connect_data,
21121
35b4f1dc4c8d replace most calls to strerror with calls to g_strerror. strerror will return
Nathan Walp <nwalp@pidgin.im>
parents: 21015
diff changeset
1131 _("Unable to create socket:\n%s"), g_strerror(errno));
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1132 return;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1133 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1134
20347
04fe5601fedb applied changes from 2762c6075c0dc52a96098c5478c5bf68cfd890a3
Luke Schierer <lschiere@pidgin.im>
parents: 20074
diff changeset
1135 flags = fcntl(connect_data->fd, F_GETFL);
04fe5601fedb applied changes from 2762c6075c0dc52a96098c5478c5bf68cfd890a3
Luke Schierer <lschiere@pidgin.im>
parents: 20074
diff changeset
1136 fcntl(connect_data->fd, F_SETFL, flags | O_NONBLOCK);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1137 #ifndef _WIN32
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1138 fcntl(connect_data->fd, F_SETFD, FD_CLOEXEC);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1139 #endif
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1140
23010
2b91ea8c94d5 Rearrange some of the HTTP proxy handling to make sure that we're actually
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23008
diff changeset
1141 if (connect(connect_data->fd, addr, addrlen) != 0) {
2b91ea8c94d5 Rearrange some of the HTTP proxy handling to make sure that we're actually
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23008
diff changeset
1142 if (errno == EINPROGRESS || errno == EINTR) {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
1143 purple_debug_info("proxy", "Connection in progress\n");
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1144
23010
2b91ea8c94d5 Rearrange some of the HTTP proxy handling to make sure that we're actually
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23008
diff changeset
1145 connect_data->inpa = purple_input_add(connect_data->fd,
2b91ea8c94d5 Rearrange some of the HTTP proxy handling to make sure that we're actually
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23008
diff changeset
1146 PURPLE_INPUT_WRITE, http_canwrite, connect_data);
2b91ea8c94d5 Rearrange some of the HTTP proxy handling to make sure that we're actually
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23008
diff changeset
1147 } else
21121
35b4f1dc4c8d replace most calls to strerror with calls to g_strerror. strerror will return
Nathan Walp <nwalp@pidgin.im>
parents: 21015
diff changeset
1148 purple_proxy_connect_data_disconnect(connect_data, g_strerror(errno));
23010
2b91ea8c94d5 Rearrange some of the HTTP proxy handling to make sure that we're actually
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23008
diff changeset
1149 } else {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
1150 purple_debug_info("proxy", "Connected immediately.\n");
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1151
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
1152 http_canwrite(connect_data, connect_data->fd, PURPLE_INPUT_WRITE);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1153 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1154 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1155
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1156 static void
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
1157 s4_canread(gpointer data, gint source, PurpleInputCondition cond)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1158 {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
1159 PurpleProxyConnectData *connect_data = data;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1160 guchar *buf;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1161 int len, max_read;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1162
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1163 /* This is really not going to block under normal circumstances, but to
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1164 * be correct, we deal with the unlikely scenario */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1165
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1166 if (connect_data->read_buffer == NULL) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1167 connect_data->read_buf_len = 12;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1168 connect_data->read_buffer = g_malloc(connect_data->read_buf_len);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1169 connect_data->read_len = 0;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1170 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1171
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1172 buf = connect_data->read_buffer + connect_data->read_len;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1173 max_read = connect_data->read_buf_len - connect_data->read_len;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1174
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1175 len = read(connect_data->fd, buf, max_read);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1176
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1177 if ((len < 0 && errno == EAGAIN) || (len > 0 && len + connect_data->read_len < 4))
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1178 return;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1179 else if (len + connect_data->read_len >= 4) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1180 if (connect_data->read_buffer[1] == 90) {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
1181 purple_proxy_connect_data_connected(connect_data);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1182 return;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1183 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1184 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1185
21121
35b4f1dc4c8d replace most calls to strerror with calls to g_strerror. strerror will return
Nathan Walp <nwalp@pidgin.im>
parents: 21015
diff changeset
1186 purple_proxy_connect_data_disconnect(connect_data, g_strerror(errno));
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1187 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1188
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1189 static void
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
1190 s4_canwrite(gpointer data, gint source, PurpleInputCondition cond)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1191 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1192 unsigned char packet[9];
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1193 struct hostent *hp;
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
1194 PurpleProxyConnectData *connect_data = data;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1195 int error = ETIMEDOUT;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1196 int ret;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1197
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
1198 purple_debug_info("socks4 proxy", "Connected.\n");
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1199
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1200 if (connect_data->inpa > 0)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1201 {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
1202 purple_input_remove(connect_data->inpa);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1203 connect_data->inpa = 0;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1204 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1205
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
1206 ret = purple_input_get_error(connect_data->fd, &error);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1207 if ((ret != 0) || (error != 0))
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1208 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1209 if (ret != 0)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1210 error = errno;
21121
35b4f1dc4c8d replace most calls to strerror with calls to g_strerror. strerror will return
Nathan Walp <nwalp@pidgin.im>
parents: 21015
diff changeset
1211 purple_proxy_connect_data_disconnect(connect_data, g_strerror(error));
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1212 return;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1213 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1214
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1215 /*
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1216 * The socks4 spec doesn't include support for doing host name
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1217 * lookups by the proxy. Some socks4 servers do this via
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1218 * extensions to the protocol. Since we don't know if a
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1219 * server supports this, it would need to be implemented
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1220 * with an option, or some detection mechanism - in the
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1221 * meantime, stick with plain old SOCKS4.
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1222 */
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
1223 /* TODO: Use purple_dnsquery_a() */
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1224 hp = gethostbyname(connect_data->host);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1225 if (hp == NULL) {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
1226 purple_proxy_connect_data_disconnect_formatted(connect_data,
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1227 _("Error resolving %s"), connect_data->host);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1228 return;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1229 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1230
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1231 packet[0] = 4;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1232 packet[1] = 1;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1233 packet[2] = connect_data->port >> 8;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1234 packet[3] = connect_data->port & 0xff;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1235 packet[4] = (unsigned char)(hp->h_addr_list[0])[0];
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1236 packet[5] = (unsigned char)(hp->h_addr_list[0])[1];
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1237 packet[6] = (unsigned char)(hp->h_addr_list[0])[2];
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1238 packet[7] = (unsigned char)(hp->h_addr_list[0])[3];
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1239 packet[8] = 0;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1240
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1241 connect_data->write_buffer = g_memdup(packet, sizeof(packet));
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1242 connect_data->write_buf_len = sizeof(packet);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1243 connect_data->written_len = 0;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1244 connect_data->read_cb = s4_canread;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1245
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
1246 connect_data->inpa = purple_input_add(connect_data->fd, PURPLE_INPUT_WRITE, proxy_do_write, connect_data);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1247
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1248 proxy_do_write(connect_data, connect_data->fd, cond);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1249 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1250
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1251 static void
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
1252 proxy_connect_socks4(PurpleProxyConnectData *connect_data, struct sockaddr *addr, socklen_t addrlen)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1253 {
20347
04fe5601fedb applied changes from 2762c6075c0dc52a96098c5478c5bf68cfd890a3
Luke Schierer <lschiere@pidgin.im>
parents: 20074
diff changeset
1254 int flags;
04fe5601fedb applied changes from 2762c6075c0dc52a96098c5478c5bf68cfd890a3
Luke Schierer <lschiere@pidgin.im>
parents: 20074
diff changeset
1255
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
1256 purple_debug_info("proxy",
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1257 "Connecting to %s:%d via %s:%d using SOCKS4\n",
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1258 connect_data->host, connect_data->port,
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
1259 purple_proxy_info_get_host(connect_data->gpi),
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
1260 purple_proxy_info_get_port(connect_data->gpi));
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1261
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1262 connect_data->fd = socket(addr->sa_family, SOCK_STREAM, 0);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1263 if (connect_data->fd < 0)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1264 {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
1265 purple_proxy_connect_data_disconnect_formatted(connect_data,
21121
35b4f1dc4c8d replace most calls to strerror with calls to g_strerror. strerror will return
Nathan Walp <nwalp@pidgin.im>
parents: 21015
diff changeset
1266 _("Unable to create socket:\n%s"), g_strerror(errno));
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1267 return;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1268 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1269
20347
04fe5601fedb applied changes from 2762c6075c0dc52a96098c5478c5bf68cfd890a3
Luke Schierer <lschiere@pidgin.im>
parents: 20074
diff changeset
1270 flags = fcntl(connect_data->fd, F_GETFL);
04fe5601fedb applied changes from 2762c6075c0dc52a96098c5478c5bf68cfd890a3
Luke Schierer <lschiere@pidgin.im>
parents: 20074
diff changeset
1271 fcntl(connect_data->fd, F_SETFL, flags | O_NONBLOCK);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1272 #ifndef _WIN32
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1273 fcntl(connect_data->fd, F_SETFD, FD_CLOEXEC);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1274 #endif
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1275
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1276 if (connect(connect_data->fd, addr, addrlen) != 0)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1277 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1278 if ((errno == EINPROGRESS) || (errno == EINTR))
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1279 {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
1280 purple_debug_info("proxy", "Connection in progress.\n");
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
1281 connect_data->inpa = purple_input_add(connect_data->fd,
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
1282 PURPLE_INPUT_WRITE, s4_canwrite, connect_data);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1283 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1284 else
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1285 {
21121
35b4f1dc4c8d replace most calls to strerror with calls to g_strerror. strerror will return
Nathan Walp <nwalp@pidgin.im>
parents: 21015
diff changeset
1286 purple_proxy_connect_data_disconnect(connect_data, g_strerror(errno));
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1287 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1288 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1289 else
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1290 {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
1291 purple_debug_info("proxy", "Connected immediately.\n");
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1292
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
1293 s4_canwrite(connect_data, connect_data->fd, PURPLE_INPUT_WRITE);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1294 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1295 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1296
17372
5a51af9a61a7 fix socks5 from over-reading the headers, and throwing away data (fixes jabber file receiving)
Nathan Walp <nwalp@pidgin.im>
parents: 17058
diff changeset
1297 static gboolean
5a51af9a61a7 fix socks5 from over-reading the headers, and throwing away data (fixes jabber file receiving)
Nathan Walp <nwalp@pidgin.im>
parents: 17058
diff changeset
1298 s5_ensure_buffer_length(PurpleProxyConnectData *connect_data, int len)
5a51af9a61a7 fix socks5 from over-reading the headers, and throwing away data (fixes jabber file receiving)
Nathan Walp <nwalp@pidgin.im>
parents: 17058
diff changeset
1299 {
5a51af9a61a7 fix socks5 from over-reading the headers, and throwing away data (fixes jabber file receiving)
Nathan Walp <nwalp@pidgin.im>
parents: 17058
diff changeset
1300 if(connect_data->read_len < len) {
5a51af9a61a7 fix socks5 from over-reading the headers, and throwing away data (fixes jabber file receiving)
Nathan Walp <nwalp@pidgin.im>
parents: 17058
diff changeset
1301 if(connect_data->read_buf_len < len) {
5a51af9a61a7 fix socks5 from over-reading the headers, and throwing away data (fixes jabber file receiving)
Nathan Walp <nwalp@pidgin.im>
parents: 17058
diff changeset
1302 /* it's not just that we haven't read enough, it's that we haven't tried to read enough yet */
22486
3225c99785b8 Fix a bunch of compiler warnings caused by my addition of G_GNUC_PRINTF()
Mark Doliner <mark@kingant.net>
parents: 22422
diff changeset
1303 purple_debug_info("s5", "reallocing from %" G_GSIZE_FORMAT
3225c99785b8 Fix a bunch of compiler warnings caused by my addition of G_GNUC_PRINTF()
Mark Doliner <mark@kingant.net>
parents: 22422
diff changeset
1304 " to %d\n", connect_data->read_buf_len, len);
17372
5a51af9a61a7 fix socks5 from over-reading the headers, and throwing away data (fixes jabber file receiving)
Nathan Walp <nwalp@pidgin.im>
parents: 17058
diff changeset
1305 connect_data->read_buf_len = len;
5a51af9a61a7 fix socks5 from over-reading the headers, and throwing away data (fixes jabber file receiving)
Nathan Walp <nwalp@pidgin.im>
parents: 17058
diff changeset
1306 connect_data->read_buffer = g_realloc(connect_data->read_buffer, connect_data->read_buf_len);
5a51af9a61a7 fix socks5 from over-reading the headers, and throwing away data (fixes jabber file receiving)
Nathan Walp <nwalp@pidgin.im>
parents: 17058
diff changeset
1307 }
5a51af9a61a7 fix socks5 from over-reading the headers, and throwing away data (fixes jabber file receiving)
Nathan Walp <nwalp@pidgin.im>
parents: 17058
diff changeset
1308 return FALSE;
5a51af9a61a7 fix socks5 from over-reading the headers, and throwing away data (fixes jabber file receiving)
Nathan Walp <nwalp@pidgin.im>
parents: 17058
diff changeset
1309 }
5a51af9a61a7 fix socks5 from over-reading the headers, and throwing away data (fixes jabber file receiving)
Nathan Walp <nwalp@pidgin.im>
parents: 17058
diff changeset
1310
5a51af9a61a7 fix socks5 from over-reading the headers, and throwing away data (fixes jabber file receiving)
Nathan Walp <nwalp@pidgin.im>
parents: 17058
diff changeset
1311 return TRUE;
5a51af9a61a7 fix socks5 from over-reading the headers, and throwing away data (fixes jabber file receiving)
Nathan Walp <nwalp@pidgin.im>
parents: 17058
diff changeset
1312 }
5a51af9a61a7 fix socks5 from over-reading the headers, and throwing away data (fixes jabber file receiving)
Nathan Walp <nwalp@pidgin.im>
parents: 17058
diff changeset
1313
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1314 static void
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
1315 s5_canread_again(gpointer data, gint source, PurpleInputCondition cond)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1316 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1317 guchar *dest, *buf;
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
1318 PurpleProxyConnectData *connect_data = data;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1319 int len;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1320
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1321 if (connect_data->read_buffer == NULL) {
23008
d0f933c88fc6 Fix SOCK5 error handling to abort when we get a bogus ATYP response. Make the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 22539
diff changeset
1322 connect_data->read_buf_len = 5;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1323 connect_data->read_buffer = g_malloc(connect_data->read_buf_len);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1324 connect_data->read_len = 0;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1325 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1326
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1327 dest = connect_data->read_buffer + connect_data->read_len;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1328 buf = connect_data->read_buffer;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1329
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1330 len = read(connect_data->fd, dest, (connect_data->read_buf_len - connect_data->read_len));
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1331
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1332 if (len == 0)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1333 {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
1334 purple_proxy_connect_data_disconnect(connect_data,
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1335 _("Server closed the connection."));
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1336 return;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1337 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1338
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1339 if (len < 0)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1340 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1341 if (errno == EAGAIN)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1342 /* No worries */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1343 return;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1344
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1345 /* Error! */
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
1346 purple_proxy_connect_data_disconnect_formatted(connect_data,
21121
35b4f1dc4c8d replace most calls to strerror with calls to g_strerror. strerror will return
Nathan Walp <nwalp@pidgin.im>
parents: 21015
diff changeset
1347 _("Lost connection with server:\n%s"), g_strerror(errno));
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1348 return;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1349 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1350
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1351 connect_data->read_len += len;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1352
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1353 if(connect_data->read_len < 4)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1354 return;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1355
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1356 if ((buf[0] != 0x05) || (buf[1] != 0x00)) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1357 if ((buf[0] == 0x05) && (buf[1] < 0x09)) {
24453
0320b4a33432 Backport the 'purple_debug_*(msg)' -> 'purple_debug_*("%s", msg);' fixes.
Richard Laager <rlaager@wiktel.com>
parents: 24273
diff changeset
1358 purple_debug_error("socks5 proxy", "%s", socks5errors[buf[1]]);
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
1359 purple_proxy_connect_data_disconnect(connect_data,
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1360 socks5errors[buf[1]]);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1361 } else {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
1362 purple_debug_error("socks5 proxy", "Bad data.\n");
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
1363 purple_proxy_connect_data_disconnect(connect_data,
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1364 _("Received invalid data on connection with server."));
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1365 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1366 return;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1367 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1368
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1369 /* Skip past BND.ADDR */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1370 switch(buf[3]) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1371 case 0x01: /* the address is a version-4 IP address, with a length of 4 octets */
17372
5a51af9a61a7 fix socks5 from over-reading the headers, and throwing away data (fixes jabber file receiving)
Nathan Walp <nwalp@pidgin.im>
parents: 17058
diff changeset
1372 if(!s5_ensure_buffer_length(connect_data, 4 + 4))
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1373 return;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1374 buf += 4 + 4;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1375 break;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1376 case 0x03: /* the address field contains a fully-qualified domain name. The first
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1377 octet of the address field contains the number of octets of name that
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1378 follow, there is no terminating NUL octet. */
17372
5a51af9a61a7 fix socks5 from over-reading the headers, and throwing away data (fixes jabber file receiving)
Nathan Walp <nwalp@pidgin.im>
parents: 17058
diff changeset
1379 if(!s5_ensure_buffer_length(connect_data, 4 + 1))
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1380 return;
17372
5a51af9a61a7 fix socks5 from over-reading the headers, and throwing away data (fixes jabber file receiving)
Nathan Walp <nwalp@pidgin.im>
parents: 17058
diff changeset
1381 buf += 4;
5a51af9a61a7 fix socks5 from over-reading the headers, and throwing away data (fixes jabber file receiving)
Nathan Walp <nwalp@pidgin.im>
parents: 17058
diff changeset
1382 if(!s5_ensure_buffer_length(connect_data, 4 + 1 + buf[0]))
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1383 return;
17372
5a51af9a61a7 fix socks5 from over-reading the headers, and throwing away data (fixes jabber file receiving)
Nathan Walp <nwalp@pidgin.im>
parents: 17058
diff changeset
1384 buf += buf[0] + 1;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1385 break;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1386 case 0x04: /* the address is a version-6 IP address, with a length of 16 octets */
17372
5a51af9a61a7 fix socks5 from over-reading the headers, and throwing away data (fixes jabber file receiving)
Nathan Walp <nwalp@pidgin.im>
parents: 17058
diff changeset
1387 if(!s5_ensure_buffer_length(connect_data, 4 + 16))
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1388 return;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1389 buf += 4 + 16;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1390 break;
23008
d0f933c88fc6 Fix SOCK5 error handling to abort when we get a bogus ATYP response. Make the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 22539
diff changeset
1391 default:
d0f933c88fc6 Fix SOCK5 error handling to abort when we get a bogus ATYP response. Make the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 22539
diff changeset
1392 purple_debug_error("socks5 proxy", "Invalid ATYP received (0x%X)\n", buf[3]);
d0f933c88fc6 Fix SOCK5 error handling to abort when we get a bogus ATYP response. Make the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 22539
diff changeset
1393 purple_proxy_connect_data_disconnect(connect_data,
d0f933c88fc6 Fix SOCK5 error handling to abort when we get a bogus ATYP response. Make the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 22539
diff changeset
1394 _("Received invalid data on connection with server."));
d0f933c88fc6 Fix SOCK5 error handling to abort when we get a bogus ATYP response. Make the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 22539
diff changeset
1395 return;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1396 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1397
17372
5a51af9a61a7 fix socks5 from over-reading the headers, and throwing away data (fixes jabber file receiving)
Nathan Walp <nwalp@pidgin.im>
parents: 17058
diff changeset
1398 /* Skip past BND.PORT */
5a51af9a61a7 fix socks5 from over-reading the headers, and throwing away data (fixes jabber file receiving)
Nathan Walp <nwalp@pidgin.im>
parents: 17058
diff changeset
1399 if(!s5_ensure_buffer_length(connect_data, (buf - connect_data->read_buffer) + 2))
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1400 return;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1401
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
1402 purple_proxy_connect_data_connected(connect_data);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1403 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1404
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1405 static void
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1406 s5_sendconnect(gpointer data, int source)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1407 {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
1408 PurpleProxyConnectData *connect_data = data;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1409 int hlen = strlen(connect_data->host);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1410 connect_data->write_buf_len = 5 + hlen + 2;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1411 connect_data->write_buffer = g_malloc(connect_data->write_buf_len);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1412 connect_data->written_len = 0;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1413
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1414 connect_data->write_buffer[0] = 0x05;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1415 connect_data->write_buffer[1] = 0x01; /* CONNECT */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1416 connect_data->write_buffer[2] = 0x00; /* reserved */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1417 connect_data->write_buffer[3] = 0x03; /* address type -- host name */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1418 connect_data->write_buffer[4] = hlen;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1419 memcpy(connect_data->write_buffer + 5, connect_data->host, hlen);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1420 connect_data->write_buffer[5 + hlen] = connect_data->port >> 8;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1421 connect_data->write_buffer[5 + hlen + 1] = connect_data->port & 0xff;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1422
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1423 connect_data->read_cb = s5_canread_again;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1424
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
1425 connect_data->inpa = purple_input_add(connect_data->fd, PURPLE_INPUT_WRITE, proxy_do_write, connect_data);
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
1426 proxy_do_write(connect_data, connect_data->fd, PURPLE_INPUT_WRITE);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1427 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1428
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1429 static void
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
1430 s5_readauth(gpointer data, gint source, PurpleInputCondition cond)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1431 {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
1432 PurpleProxyConnectData *connect_data = data;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1433 int len;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1434
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1435 if (connect_data->read_buffer == NULL) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1436 connect_data->read_buf_len = 2;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1437 connect_data->read_buffer = g_malloc(connect_data->read_buf_len);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1438 connect_data->read_len = 0;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1439 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1440
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
1441 purple_debug_info("socks5 proxy", "Got auth response.\n");
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1442
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1443 len = read(connect_data->fd, connect_data->read_buffer + connect_data->read_len,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1444 connect_data->read_buf_len - connect_data->read_len);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1445
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1446 if (len == 0)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1447 {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
1448 purple_proxy_connect_data_disconnect(connect_data,
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1449 _("Server closed the connection."));
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1450 return;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1451 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1452
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1453 if (len < 0)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1454 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1455 if (errno == EAGAIN)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1456 /* No worries */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1457 return;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1458
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1459 /* Error! */
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
1460 purple_proxy_connect_data_disconnect_formatted(connect_data,
21121
35b4f1dc4c8d replace most calls to strerror with calls to g_strerror. strerror will return
Nathan Walp <nwalp@pidgin.im>
parents: 21015
diff changeset
1461 _("Lost connection with server:\n%s"), g_strerror(errno));
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1462 return;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1463 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1464
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1465 connect_data->read_len += len;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1466 if (connect_data->read_len < 2)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1467 return;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1468
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
1469 purple_input_remove(connect_data->inpa);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1470 connect_data->inpa = 0;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1471
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1472 if ((connect_data->read_buffer[0] != 0x01) || (connect_data->read_buffer[1] != 0x00)) {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
1473 purple_proxy_connect_data_disconnect(connect_data,
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1474 _("Received invalid data on connection with server."));
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1475 return;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1476 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1477
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1478 g_free(connect_data->read_buffer);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1479 connect_data->read_buffer = NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1480
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1481 s5_sendconnect(connect_data, connect_data->fd);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1482 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1483
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1484 static void
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1485 hmacmd5_chap(const unsigned char * challenge, int challen, const char * passwd, unsigned char * response)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1486 {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
1487 PurpleCipher *cipher;
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
1488 PurpleCipherContext *ctx;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1489 int i;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1490 unsigned char Kxoripad[65];
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1491 unsigned char Kxoropad[65];
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1492 int pwlen;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1493
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
1494 cipher = purple_ciphers_find_cipher("md5");
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
1495 ctx = purple_cipher_context_new(cipher, NULL);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1496
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1497 memset(Kxoripad,0,sizeof(Kxoripad));
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1498 memset(Kxoropad,0,sizeof(Kxoropad));
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1499
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1500 pwlen=strlen(passwd);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1501 if (pwlen>64) {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
1502 purple_cipher_context_append(ctx, (const guchar *)passwd, strlen(passwd));
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
1503 purple_cipher_context_digest(ctx, sizeof(Kxoripad), Kxoripad, NULL);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1504 pwlen=16;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1505 } else {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1506 memcpy(Kxoripad, passwd, pwlen);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1507 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1508 memcpy(Kxoropad,Kxoripad,pwlen);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1509
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1510 for (i=0;i<64;i++) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1511 Kxoripad[i]^=0x36;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1512 Kxoropad[i]^=0x5c;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1513 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1514
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
1515 purple_cipher_context_reset(ctx, NULL);
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
1516 purple_cipher_context_append(ctx, Kxoripad, 64);
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
1517 purple_cipher_context_append(ctx, challenge, challen);
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
1518 purple_cipher_context_digest(ctx, sizeof(Kxoripad), Kxoripad, NULL);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1519
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
1520 purple_cipher_context_reset(ctx, NULL);
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
1521 purple_cipher_context_append(ctx, Kxoropad, 64);
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
1522 purple_cipher_context_append(ctx, Kxoripad, 16);
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
1523 purple_cipher_context_digest(ctx, 16, response, NULL);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1524
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
1525 purple_cipher_context_destroy(ctx);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1526 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1527
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1528 static void
24106
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23992
diff changeset
1529 s5_readchap(gpointer data, gint source, PurpleInputCondition cond);
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23992
diff changeset
1530
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23992
diff changeset
1531 /*
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23992
diff changeset
1532 * Return how many bytes we processed
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23992
diff changeset
1533 * -1 means we've shouldn't keep reading from the buffer
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23992
diff changeset
1534 */
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23992
diff changeset
1535 static gssize
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23992
diff changeset
1536 s5_parse_chap_msg(PurpleProxyConnectData *connect_data)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1537 {
24106
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23992
diff changeset
1538 guchar *buf, *cmdbuf = connect_data->read_buffer;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1539 int len, navas, currentav;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1540
24106
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23992
diff changeset
1541 purple_debug_misc("socks5 proxy", "Reading CHAP message: %x\n", *cmdbuf);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1542
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1543 if (*cmdbuf != 0x01) {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
1544 purple_proxy_connect_data_disconnect(connect_data,
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1545 _("Received invalid data on connection with server."));
24106
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23992
diff changeset
1546 return -1;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1547 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1548 cmdbuf++;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1549
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1550 navas = *cmdbuf;
24106
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23992
diff changeset
1551
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23992
diff changeset
1552 purple_debug_misc("socks5 proxy", "Expecting %d attribute(s).\n", navas);
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23992
diff changeset
1553
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1554 cmdbuf++;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1555
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1556 for (currentav = 0; currentav < navas; currentav++) {
22539
5a0186edda97 Fix SOCKS5 CHAP authentication to be more robust; the current stuff depends on the attributes coming in in a specific order and the whole authentication having a maximum length of 20 bytes. Big thanks to Jonathan Rudolph ("simple" on IRC) for helping figure out what was wrong.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 22486
diff changeset
1557
5a0186edda97 Fix SOCKS5 CHAP authentication to be more robust; the current stuff depends on the attributes coming in in a specific order and the whole authentication having a maximum length of 20 bytes. Big thanks to Jonathan Rudolph ("simple" on IRC) for helping figure out what was wrong.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 22486
diff changeset
1558 len = connect_data->read_len - (cmdbuf - connect_data->read_buffer);
5a0186edda97 Fix SOCKS5 CHAP authentication to be more robust; the current stuff depends on the attributes coming in in a specific order and the whole authentication having a maximum length of 20 bytes. Big thanks to Jonathan Rudolph ("simple" on IRC) for helping figure out what was wrong.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 22486
diff changeset
1559 /* We don't have enough data to even know how long the next attribute is,
5a0186edda97 Fix SOCKS5 CHAP authentication to be more robust; the current stuff depends on the attributes coming in in a specific order and the whole authentication having a maximum length of 20 bytes. Big thanks to Jonathan Rudolph ("simple" on IRC) for helping figure out what was wrong.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 22486
diff changeset
1560 * or we don't have the full length of the next attribute. */
5a0186edda97 Fix SOCKS5 CHAP authentication to be more robust; the current stuff depends on the attributes coming in in a specific order and the whole authentication having a maximum length of 20 bytes. Big thanks to Jonathan Rudolph ("simple" on IRC) for helping figure out what was wrong.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 22486
diff changeset
1561 if (len < 2 || len < (cmdbuf[1] + 2)) {
5a0186edda97 Fix SOCKS5 CHAP authentication to be more robust; the current stuff depends on the attributes coming in in a specific order and the whole authentication having a maximum length of 20 bytes. Big thanks to Jonathan Rudolph ("simple" on IRC) for helping figure out what was wrong.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 22486
diff changeset
1562 /* Clear out the attributes that have been read - decrease the attribute count */
5a0186edda97 Fix SOCKS5 CHAP authentication to be more robust; the current stuff depends on the attributes coming in in a specific order and the whole authentication having a maximum length of 20 bytes. Big thanks to Jonathan Rudolph ("simple" on IRC) for helping figure out what was wrong.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 22486
diff changeset
1563 connect_data->read_buffer[1] = navas - currentav;
5a0186edda97 Fix SOCKS5 CHAP authentication to be more robust; the current stuff depends on the attributes coming in in a specific order and the whole authentication having a maximum length of 20 bytes. Big thanks to Jonathan Rudolph ("simple" on IRC) for helping figure out what was wrong.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 22486
diff changeset
1564 /* Move the unprocessed data into the first attribute position */
5a0186edda97 Fix SOCKS5 CHAP authentication to be more robust; the current stuff depends on the attributes coming in in a specific order and the whole authentication having a maximum length of 20 bytes. Big thanks to Jonathan Rudolph ("simple" on IRC) for helping figure out what was wrong.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 22486
diff changeset
1565 memmove((connect_data->read_buffer + 2), cmdbuf, len);
5a0186edda97 Fix SOCKS5 CHAP authentication to be more robust; the current stuff depends on the attributes coming in in a specific order and the whole authentication having a maximum length of 20 bytes. Big thanks to Jonathan Rudolph ("simple" on IRC) for helping figure out what was wrong.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 22486
diff changeset
1566 /* Decrease the read count accordingly */
5a0186edda97 Fix SOCKS5 CHAP authentication to be more robust; the current stuff depends on the attributes coming in in a specific order and the whole authentication having a maximum length of 20 bytes. Big thanks to Jonathan Rudolph ("simple" on IRC) for helping figure out what was wrong.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 22486
diff changeset
1567 connect_data->read_len = len + 2;
24106
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23992
diff changeset
1568
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23992
diff changeset
1569 purple_debug_info("socks5 proxy", "Need more data to retrieve attribute %d.\n", currentav);
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23992
diff changeset
1570
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23992
diff changeset
1571 return -1;
22539
5a0186edda97 Fix SOCKS5 CHAP authentication to be more robust; the current stuff depends on the attributes coming in in a specific order and the whole authentication having a maximum length of 20 bytes. Big thanks to Jonathan Rudolph ("simple" on IRC) for helping figure out what was wrong.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 22486
diff changeset
1572 }
5a0186edda97 Fix SOCKS5 CHAP authentication to be more robust; the current stuff depends on the attributes coming in in a specific order and the whole authentication having a maximum length of 20 bytes. Big thanks to Jonathan Rudolph ("simple" on IRC) for helping figure out what was wrong.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 22486
diff changeset
1573
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1574 buf = cmdbuf + 2;
22539
5a0186edda97 Fix SOCKS5 CHAP authentication to be more robust; the current stuff depends on the attributes coming in in a specific order and the whole authentication having a maximum length of 20 bytes. Big thanks to Jonathan Rudolph ("simple" on IRC) for helping figure out what was wrong.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 22486
diff changeset
1575
5a0186edda97 Fix SOCKS5 CHAP authentication to be more robust; the current stuff depends on the attributes coming in in a specific order and the whole authentication having a maximum length of 20 bytes. Big thanks to Jonathan Rudolph ("simple" on IRC) for helping figure out what was wrong.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 22486
diff changeset
1576 if (cmdbuf[1] == 0) {
5a0186edda97 Fix SOCKS5 CHAP authentication to be more robust; the current stuff depends on the attributes coming in in a specific order and the whole authentication having a maximum length of 20 bytes. Big thanks to Jonathan Rudolph ("simple" on IRC) for helping figure out what was wrong.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 22486
diff changeset
1577 purple_debug_error("socks5 proxy", "Attribute %x Value length of 0; ignoring.\n", cmdbuf[0]);
5a0186edda97 Fix SOCKS5 CHAP authentication to be more robust; the current stuff depends on the attributes coming in in a specific order and the whole authentication having a maximum length of 20 bytes. Big thanks to Jonathan Rudolph ("simple" on IRC) for helping figure out what was wrong.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 22486
diff changeset
1578 cmdbuf = buf;
5a0186edda97 Fix SOCKS5 CHAP authentication to be more robust; the current stuff depends on the attributes coming in in a specific order and the whole authentication having a maximum length of 20 bytes. Big thanks to Jonathan Rudolph ("simple" on IRC) for helping figure out what was wrong.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 22486
diff changeset
1579 continue;
5a0186edda97 Fix SOCKS5 CHAP authentication to be more robust; the current stuff depends on the attributes coming in in a specific order and the whole authentication having a maximum length of 20 bytes. Big thanks to Jonathan Rudolph ("simple" on IRC) for helping figure out what was wrong.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 22486
diff changeset
1580 }
5a0186edda97 Fix SOCKS5 CHAP authentication to be more robust; the current stuff depends on the attributes coming in in a specific order and the whole authentication having a maximum length of 20 bytes. Big thanks to Jonathan Rudolph ("simple" on IRC) for helping figure out what was wrong.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 22486
diff changeset
1581
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1582 switch (cmdbuf[0]) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1583 case 0x00:
22539
5a0186edda97 Fix SOCKS5 CHAP authentication to be more robust; the current stuff depends on the attributes coming in in a specific order and the whole authentication having a maximum length of 20 bytes. Big thanks to Jonathan Rudolph ("simple" on IRC) for helping figure out what was wrong.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 22486
diff changeset
1584 purple_debug_info("socks5 proxy", "Received STATUS of %x\n", buf[0]);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1585 /* Did auth work? */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1586 if (buf[0] == 0x00) {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
1587 purple_input_remove(connect_data->inpa);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1588 connect_data->inpa = 0;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1589 g_free(connect_data->read_buffer);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1590 connect_data->read_buffer = NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1591 /* Success */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1592 s5_sendconnect(connect_data, connect_data->fd);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1593 } else {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1594 /* Failure */
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
1595 purple_debug_warning("proxy",
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1596 "socks5 CHAP authentication "
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1597 "failed. Disconnecting...");
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
1598 purple_proxy_connect_data_disconnect(connect_data,
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1599 _("Authentication failed"));
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1600 }
24106
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23992
diff changeset
1601 return -1;
24107
71fecd0f4ce6 Add support for printing out the TEXT-MESSAGE in SOCKS5 CHAP auth.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24106
diff changeset
1602 case 0x01:
71fecd0f4ce6 Add support for printing out the TEXT-MESSAGE in SOCKS5 CHAP auth.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24106
diff changeset
1603 /* We've already validated that cmdbuf[1] is sane. */
71fecd0f4ce6 Add support for printing out the TEXT-MESSAGE in SOCKS5 CHAP auth.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24106
diff changeset
1604 purple_debug_info("socks5 proxy", "Received TEXT-MESSAGE of '%.*s'\n", (int) cmdbuf[1], buf);
71fecd0f4ce6 Add support for printing out the TEXT-MESSAGE in SOCKS5 CHAP auth.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24106
diff changeset
1605 break;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1606 case 0x03:
22539
5a0186edda97 Fix SOCKS5 CHAP authentication to be more robust; the current stuff depends on the attributes coming in in a specific order and the whole authentication having a maximum length of 20 bytes. Big thanks to Jonathan Rudolph ("simple" on IRC) for helping figure out what was wrong.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 22486
diff changeset
1607 purple_debug_info("socks5 proxy", "Received CHALLENGE\n");
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1608 /* Server wants our credentials */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1609
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1610 connect_data->write_buf_len = 16 + 4;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1611 connect_data->write_buffer = g_malloc(connect_data->write_buf_len);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1612 connect_data->written_len = 0;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1613
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1614 hmacmd5_chap(buf, cmdbuf[1],
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
1615 purple_proxy_info_get_password(connect_data->gpi),
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1616 connect_data->write_buffer + 4);
24107
71fecd0f4ce6 Add support for printing out the TEXT-MESSAGE in SOCKS5 CHAP auth.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24106
diff changeset
1617 /* TODO: What about USER-IDENTITY? */
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1618 connect_data->write_buffer[0] = 0x01;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1619 connect_data->write_buffer[1] = 0x01;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1620 connect_data->write_buffer[2] = 0x04;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1621 connect_data->write_buffer[3] = 0x10;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1622
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
1623 purple_input_remove(connect_data->inpa);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1624 g_free(connect_data->read_buffer);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1625 connect_data->read_buffer = NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1626
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1627 connect_data->read_cb = s5_readchap;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1628
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
1629 connect_data->inpa = purple_input_add(connect_data->fd,
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
1630 PURPLE_INPUT_WRITE, proxy_do_write, connect_data);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1631
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
1632 proxy_do_write(connect_data, connect_data->fd, PURPLE_INPUT_WRITE);
24106
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23992
diff changeset
1633 return -1;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1634 case 0x11:
22539
5a0186edda97 Fix SOCKS5 CHAP authentication to be more robust; the current stuff depends on the attributes coming in in a specific order and the whole authentication having a maximum length of 20 bytes. Big thanks to Jonathan Rudolph ("simple" on IRC) for helping figure out what was wrong.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 22486
diff changeset
1635 purple_debug_info("socks5 proxy", "Received ALGORIGTHMS of %x\n", buf[0]);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1636 /* Server wants to select an algorithm */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1637 if (buf[0] != 0x85) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1638 /* Only currently support HMAC-MD5 */
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
1639 purple_debug_warning("proxy",
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1640 "Server tried to select an "
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1641 "algorithm that we did not advertise "
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1642 "as supporting. This is a violation "
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1643 "of the socks5 CHAP specification. "
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1644 "Disconnecting...");
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
1645 purple_proxy_connect_data_disconnect(connect_data,
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1646 _("Received invalid data on connection with server."));
24106
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23992
diff changeset
1647 return -1;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1648 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1649 break;
22539
5a0186edda97 Fix SOCKS5 CHAP authentication to be more robust; the current stuff depends on the attributes coming in in a specific order and the whole authentication having a maximum length of 20 bytes. Big thanks to Jonathan Rudolph ("simple" on IRC) for helping figure out what was wrong.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 22486
diff changeset
1650 default:
5a0186edda97 Fix SOCKS5 CHAP authentication to be more robust; the current stuff depends on the attributes coming in in a specific order and the whole authentication having a maximum length of 20 bytes. Big thanks to Jonathan Rudolph ("simple" on IRC) for helping figure out what was wrong.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 22486
diff changeset
1651 purple_debug_info("socks5 proxy", "Received unused command %x, length=%d\n", cmdbuf[0], cmdbuf[1]);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1652 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1653 cmdbuf = buf + cmdbuf[1];
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1654 }
22539
5a0186edda97 Fix SOCKS5 CHAP authentication to be more robust; the current stuff depends on the attributes coming in in a specific order and the whole authentication having a maximum length of 20 bytes. Big thanks to Jonathan Rudolph ("simple" on IRC) for helping figure out what was wrong.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 22486
diff changeset
1655
24106
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23992
diff changeset
1656 return (cmdbuf - connect_data->read_buffer);
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23992
diff changeset
1657 }
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23992
diff changeset
1658
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23992
diff changeset
1659 static void
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23992
diff changeset
1660 s5_readchap(gpointer data, gint source, PurpleInputCondition cond)
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23992
diff changeset
1661 {
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23992
diff changeset
1662 gssize msg_ret;
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23992
diff changeset
1663 PurpleProxyConnectData *connect_data = data;
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23992
diff changeset
1664 int len;
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23992
diff changeset
1665
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23992
diff changeset
1666 purple_debug(PURPLE_DEBUG_INFO, "socks5 proxy", "Got CHAP response.\n");
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23992
diff changeset
1667
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23992
diff changeset
1668 if (connect_data->read_buffer == NULL) {
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23992
diff changeset
1669 /* A big enough butfer to read the message header (2 bytes) and at least one complete attribute and value (1 + 1 + 255). */
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23992
diff changeset
1670 connect_data->read_buf_len = 259;
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23992
diff changeset
1671 connect_data->read_buffer = g_malloc(connect_data->read_buf_len);
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23992
diff changeset
1672 connect_data->read_len = 0;
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23992
diff changeset
1673 }
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23992
diff changeset
1674
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23992
diff changeset
1675 if (connect_data->read_buf_len - connect_data->read_len == 0) {
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23992
diff changeset
1676 /*If the stuff below is right, this shouldn't be possible. */
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23992
diff changeset
1677 purple_debug_error("socks5 proxy", "This is about to suck because the read buffer is full (shouldn't happen).\n");
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23992
diff changeset
1678 }
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23992
diff changeset
1679
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23992
diff changeset
1680 len = read(connect_data->fd, connect_data->read_buffer + connect_data->read_len,
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23992
diff changeset
1681 connect_data->read_buf_len - connect_data->read_len);
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23992
diff changeset
1682
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23992
diff changeset
1683 if (len == 0) {
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23992
diff changeset
1684 purple_proxy_connect_data_disconnect(connect_data,
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23992
diff changeset
1685 _("Server closed the connection."));
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23992
diff changeset
1686 return;
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23992
diff changeset
1687 }
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23992
diff changeset
1688
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23992
diff changeset
1689 if (len < 0) {
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23992
diff changeset
1690 if (errno == EAGAIN)
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23992
diff changeset
1691 /* No worries */
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23992
diff changeset
1692 return;
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23992
diff changeset
1693
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23992
diff changeset
1694 /* Error! */
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23992
diff changeset
1695 purple_proxy_connect_data_disconnect_formatted(connect_data,
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23992
diff changeset
1696 _("Lost connection with server:\n%s"), g_strerror(errno));
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23992
diff changeset
1697 return;
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23992
diff changeset
1698 }
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23992
diff changeset
1699
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23992
diff changeset
1700 connect_data->read_len += len;
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23992
diff changeset
1701
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23992
diff changeset
1702 /* We may have read more than one message into the buffer, we need to make sure to process them all */
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23992
diff changeset
1703 while (1) {
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23992
diff changeset
1704
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23992
diff changeset
1705 /* We need more to be able to read this message */
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23992
diff changeset
1706 if (connect_data->read_len < 2)
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23992
diff changeset
1707 return;
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23992
diff changeset
1708
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23992
diff changeset
1709 msg_ret = s5_parse_chap_msg(connect_data);
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23992
diff changeset
1710
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23992
diff changeset
1711 if (msg_ret < 0)
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23992
diff changeset
1712 return;
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23992
diff changeset
1713
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23992
diff changeset
1714 /* See if we have another message already in the buffer */
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23992
diff changeset
1715 if ((len = connect_data->read_len - msg_ret) > 0) {
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23992
diff changeset
1716
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23992
diff changeset
1717 /* Move on to the next message */
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23992
diff changeset
1718 memmove(connect_data->read_buffer, connect_data->read_buffer + msg_ret, len);
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23992
diff changeset
1719 /* Decrease the read count accordingly */
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23992
diff changeset
1720 connect_data->read_len = len;
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23992
diff changeset
1721
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23992
diff changeset
1722 /* Try to read the message that connect_data->read_buffer now points to */
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23992
diff changeset
1723 continue;
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23992
diff changeset
1724 }
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23992
diff changeset
1725
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23992
diff changeset
1726 break;
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23992
diff changeset
1727 }
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23992
diff changeset
1728
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1729 /* Fell through. We ran out of CHAP events to process, but haven't
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1730 * succeeded or failed authentication - there may be more to come.
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1731 * If this is the case, come straight back here. */
22539
5a0186edda97 Fix SOCKS5 CHAP authentication to be more robust; the current stuff depends on the attributes coming in in a specific order and the whole authentication having a maximum length of 20 bytes. Big thanks to Jonathan Rudolph ("simple" on IRC) for helping figure out what was wrong.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 22486
diff changeset
1732
24106
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23992
diff changeset
1733 purple_debug_info("socks5 proxy", "Waiting for another message from which to read CHAP info.\n");
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23992
diff changeset
1734
22539
5a0186edda97 Fix SOCKS5 CHAP authentication to be more robust; the current stuff depends on the attributes coming in in a specific order and the whole authentication having a maximum length of 20 bytes. Big thanks to Jonathan Rudolph ("simple" on IRC) for helping figure out what was wrong.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 22486
diff changeset
1735 /* We've processed all the available attributes, so get ready for a whole new message */
5a0186edda97 Fix SOCKS5 CHAP authentication to be more robust; the current stuff depends on the attributes coming in in a specific order and the whole authentication having a maximum length of 20 bytes. Big thanks to Jonathan Rudolph ("simple" on IRC) for helping figure out what was wrong.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 22486
diff changeset
1736 g_free(connect_data->read_buffer);
5a0186edda97 Fix SOCKS5 CHAP authentication to be more robust; the current stuff depends on the attributes coming in in a specific order and the whole authentication having a maximum length of 20 bytes. Big thanks to Jonathan Rudolph ("simple" on IRC) for helping figure out what was wrong.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 22486
diff changeset
1737 connect_data->read_buffer = NULL;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1738 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1739
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1740 static void
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
1741 s5_canread(gpointer data, gint source, PurpleInputCondition cond)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1742 {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
1743 PurpleProxyConnectData *connect_data = data;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1744 int len;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1745
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1746 if (connect_data->read_buffer == NULL) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1747 connect_data->read_buf_len = 2;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1748 connect_data->read_buffer = g_malloc(connect_data->read_buf_len);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1749 connect_data->read_len = 0;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1750 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1751
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
1752 purple_debug_info("socks5 proxy", "Able to read.\n");
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1753
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1754 len = read(connect_data->fd, connect_data->read_buffer + connect_data->read_len,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1755 connect_data->read_buf_len - connect_data->read_len);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1756
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1757 if (len == 0)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1758 {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
1759 purple_proxy_connect_data_disconnect(connect_data,
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1760 _("Server closed the connection."));
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1761 return;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1762 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1763
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1764 if (len < 0)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1765 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1766 if (errno == EAGAIN)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1767 /* No worries */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1768 return;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1769
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1770 /* Error! */
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
1771 purple_proxy_connect_data_disconnect_formatted(connect_data,
21121
35b4f1dc4c8d replace most calls to strerror with calls to g_strerror. strerror will return
Nathan Walp <nwalp@pidgin.im>
parents: 21015
diff changeset
1772 _("Lost connection with server:\n%s"), g_strerror(errno));
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1773 return;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1774 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1775
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1776 connect_data->read_len += len;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1777 if (connect_data->read_len < 2)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1778 return;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1779
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
1780 purple_input_remove(connect_data->inpa);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1781 connect_data->inpa = 0;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1782
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1783 if ((connect_data->read_buffer[0] != 0x05) || (connect_data->read_buffer[1] == 0xff)) {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
1784 purple_proxy_connect_data_disconnect(connect_data,
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1785 _("Received invalid data on connection with server."));
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1786 return;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1787 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1788
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1789 if (connect_data->read_buffer[1] == 0x02) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1790 gsize i, j;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1791 const char *u, *p;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1792
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
1793 u = purple_proxy_info_get_username(connect_data->gpi);
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
1794 p = purple_proxy_info_get_password(connect_data->gpi);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1795
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1796 i = (u == NULL) ? 0 : strlen(u);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1797 j = (p == NULL) ? 0 : strlen(p);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1798
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1799 connect_data->write_buf_len = 1 + 1 + i + 1 + j;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1800 connect_data->write_buffer = g_malloc(connect_data->write_buf_len);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1801 connect_data->written_len = 0;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1802
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1803 connect_data->write_buffer[0] = 0x01; /* version 1 */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1804 connect_data->write_buffer[1] = i;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1805 if (u != NULL)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1806 memcpy(connect_data->write_buffer + 2, u, i);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1807 connect_data->write_buffer[2 + i] = j;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1808 if (p != NULL)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1809 memcpy(connect_data->write_buffer + 2 + i + 1, p, j);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1810
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1811 g_free(connect_data->read_buffer);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1812 connect_data->read_buffer = NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1813
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1814 connect_data->read_cb = s5_readauth;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1815
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
1816 connect_data->inpa = purple_input_add(connect_data->fd, PURPLE_INPUT_WRITE,
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1817 proxy_do_write, connect_data);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1818
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
1819 proxy_do_write(connect_data, connect_data->fd, PURPLE_INPUT_WRITE);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1820
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1821 return;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1822 } else if (connect_data->read_buffer[1] == 0x03) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1823 gsize userlen;
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
1824 userlen = strlen(purple_proxy_info_get_username(connect_data->gpi));
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1825
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1826 connect_data->write_buf_len = 7 + userlen;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1827 connect_data->write_buffer = g_malloc(connect_data->write_buf_len);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1828 connect_data->written_len = 0;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1829
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1830 connect_data->write_buffer[0] = 0x01;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1831 connect_data->write_buffer[1] = 0x02;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1832 connect_data->write_buffer[2] = 0x11;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1833 connect_data->write_buffer[3] = 0x01;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1834 connect_data->write_buffer[4] = 0x85;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1835 connect_data->write_buffer[5] = 0x02;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1836 connect_data->write_buffer[6] = userlen;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1837 memcpy(connect_data->write_buffer + 7,
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
1838 purple_proxy_info_get_username(connect_data->gpi), userlen);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1839
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1840 g_free(connect_data->read_buffer);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1841 connect_data->read_buffer = NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1842
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1843 connect_data->read_cb = s5_readchap;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1844
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
1845 connect_data->inpa = purple_input_add(connect_data->fd, PURPLE_INPUT_WRITE,
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1846 proxy_do_write, connect_data);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1847
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
1848 proxy_do_write(connect_data, connect_data->fd, PURPLE_INPUT_WRITE);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1849
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1850 return;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1851 } else {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1852 g_free(connect_data->read_buffer);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1853 connect_data->read_buffer = NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1854
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1855 s5_sendconnect(connect_data, connect_data->fd);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1856 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1857 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1858
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1859 static void
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
1860 s5_canwrite(gpointer data, gint source, PurpleInputCondition cond)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1861 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1862 unsigned char buf[5];
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1863 int i;
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
1864 PurpleProxyConnectData *connect_data = data;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1865 int error = ETIMEDOUT;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1866 int ret;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1867
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
1868 purple_debug_info("socks5 proxy", "Connected.\n");
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1869
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1870 if (connect_data->inpa > 0)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1871 {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
1872 purple_input_remove(connect_data->inpa);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1873 connect_data->inpa = 0;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1874 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1875
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
1876 ret = purple_input_get_error(connect_data->fd, &error);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1877 if ((ret != 0) || (error != 0))
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1878 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1879 if (ret != 0)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1880 error = errno;
21121
35b4f1dc4c8d replace most calls to strerror with calls to g_strerror. strerror will return
Nathan Walp <nwalp@pidgin.im>
parents: 21015
diff changeset
1881 purple_proxy_connect_data_disconnect(connect_data, g_strerror(error));
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1882 return;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1883 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1884
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1885 i = 0;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1886 buf[0] = 0x05; /* SOCKS version 5 */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1887
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
1888 if (purple_proxy_info_get_username(connect_data->gpi) != NULL) {
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1889 buf[1] = 0x03; /* three methods */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1890 buf[2] = 0x00; /* no authentication */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1891 buf[3] = 0x03; /* CHAP authentication */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1892 buf[4] = 0x02; /* username/password authentication */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1893 i = 5;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1894 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1895 else {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1896 buf[1] = 0x01;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1897 buf[2] = 0x00;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1898 i = 3;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1899 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1900
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1901 connect_data->write_buf_len = i;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1902 connect_data->write_buffer = g_malloc(connect_data->write_buf_len);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1903 memcpy(connect_data->write_buffer, buf, i);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1904
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1905 connect_data->read_cb = s5_canread;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1906
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
1907 connect_data->inpa = purple_input_add(connect_data->fd, PURPLE_INPUT_WRITE, proxy_do_write, connect_data);
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
1908 proxy_do_write(connect_data, connect_data->fd, PURPLE_INPUT_WRITE);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1909 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1910
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1911 static void
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
1912 proxy_connect_socks5(PurpleProxyConnectData *connect_data, struct sockaddr *addr, socklen_t addrlen)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1913 {
20347
04fe5601fedb applied changes from 2762c6075c0dc52a96098c5478c5bf68cfd890a3
Luke Schierer <lschiere@pidgin.im>
parents: 20074
diff changeset
1914 int flags;
04fe5601fedb applied changes from 2762c6075c0dc52a96098c5478c5bf68cfd890a3
Luke Schierer <lschiere@pidgin.im>
parents: 20074
diff changeset
1915
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
1916 purple_debug_info("proxy",
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1917 "Connecting to %s:%d via %s:%d using SOCKS5\n",
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1918 connect_data->host, connect_data->port,
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
1919 purple_proxy_info_get_host(connect_data->gpi),
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
1920 purple_proxy_info_get_port(connect_data->gpi));
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1921
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1922 connect_data->fd = socket(addr->sa_family, SOCK_STREAM, 0);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1923 if (connect_data->fd < 0)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1924 {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
1925 purple_proxy_connect_data_disconnect_formatted(connect_data,
21121
35b4f1dc4c8d replace most calls to strerror with calls to g_strerror. strerror will return
Nathan Walp <nwalp@pidgin.im>
parents: 21015
diff changeset
1926 _("Unable to create socket:\n%s"), g_strerror(errno));
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1927 return;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1928 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1929
20347
04fe5601fedb applied changes from 2762c6075c0dc52a96098c5478c5bf68cfd890a3
Luke Schierer <lschiere@pidgin.im>
parents: 20074
diff changeset
1930 flags = fcntl(connect_data->fd, F_GETFL);
04fe5601fedb applied changes from 2762c6075c0dc52a96098c5478c5bf68cfd890a3
Luke Schierer <lschiere@pidgin.im>
parents: 20074
diff changeset
1931 fcntl(connect_data->fd, F_SETFL, flags | O_NONBLOCK);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1932 #ifndef _WIN32
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1933 fcntl(connect_data->fd, F_SETFD, FD_CLOEXEC);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1934 #endif
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1935
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1936 if (connect(connect_data->fd, addr, addrlen) != 0)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1937 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1938 if ((errno == EINPROGRESS) || (errno == EINTR))
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1939 {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
1940 purple_debug_info("socks5 proxy", "Connection in progress\n");
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
1941 connect_data->inpa = purple_input_add(connect_data->fd,
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
1942 PURPLE_INPUT_WRITE, s5_canwrite, connect_data);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1943 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1944 else
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1945 {
21121
35b4f1dc4c8d replace most calls to strerror with calls to g_strerror. strerror will return
Nathan Walp <nwalp@pidgin.im>
parents: 21015
diff changeset
1946 purple_proxy_connect_data_disconnect(connect_data, g_strerror(errno));
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1947 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1948 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1949 else
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1950 {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
1951 purple_debug_info("proxy", "Connected immediately.\n");
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1952
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
1953 s5_canwrite(connect_data, connect_data->fd, PURPLE_INPUT_WRITE);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1954 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1955 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1956
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1957 /**
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1958 * This function attempts to connect to the next IP address in the list
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
1959 * of IP addresses returned to us by purple_dnsquery_a() and attemps
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1960 * to connect to each one. This is called after the hostname is
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1961 * resolved, and each time a connection attempt fails (assuming there
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1962 * is another IP address to try).
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1963 */
23201
313b87adb730 A patch from Peter O'Gorman at The Written Word, Inc. to fix various
Peter O'Gorman <pogma@thewrittenword.com>
parents: 23010
diff changeset
1964 #ifndef INET6_ADDRSTRLEN
313b87adb730 A patch from Peter O'Gorman at The Written Word, Inc. to fix various
Peter O'Gorman <pogma@thewrittenword.com>
parents: 23010
diff changeset
1965 #define INET6_ADDRSTRLEN 46
313b87adb730 A patch from Peter O'Gorman at The Written Word, Inc. to fix various
Peter O'Gorman <pogma@thewrittenword.com>
parents: 23010
diff changeset
1966 #endif
313b87adb730 A patch from Peter O'Gorman at The Written Word, Inc. to fix various
Peter O'Gorman <pogma@thewrittenword.com>
parents: 23010
diff changeset
1967
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
1968 static void try_connect(PurpleProxyConnectData *connect_data)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1969 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1970 size_t addrlen;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1971 struct sockaddr *addr;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1972 char ipaddr[INET6_ADDRSTRLEN];
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1973
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1974 addrlen = GPOINTER_TO_INT(connect_data->hosts->data);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1975 connect_data->hosts = g_slist_remove(connect_data->hosts, connect_data->hosts->data);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1976 addr = connect_data->hosts->data;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1977 connect_data->hosts = g_slist_remove(connect_data->hosts, connect_data->hosts->data);
23201
313b87adb730 A patch from Peter O'Gorman at The Written Word, Inc. to fix various
Peter O'Gorman <pogma@thewrittenword.com>
parents: 23010
diff changeset
1978 #ifdef HAVE_INET_NTOP
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1979 inet_ntop(addr->sa_family, &((struct sockaddr_in *)addr)->sin_addr,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1980 ipaddr, sizeof(ipaddr));
23201
313b87adb730 A patch from Peter O'Gorman at The Written Word, Inc. to fix various
Peter O'Gorman <pogma@thewrittenword.com>
parents: 23010
diff changeset
1981 #else
313b87adb730 A patch from Peter O'Gorman at The Written Word, Inc. to fix various
Peter O'Gorman <pogma@thewrittenword.com>
parents: 23010
diff changeset
1982 memcpy(ipaddr,inet_ntoa(((struct sockaddr_in *)addr)->sin_addr),
313b87adb730 A patch from Peter O'Gorman at The Written Word, Inc. to fix various
Peter O'Gorman <pogma@thewrittenword.com>
parents: 23010
diff changeset
1983 sizeof(ipaddr));
313b87adb730 A patch from Peter O'Gorman at The Written Word, Inc. to fix various
Peter O'Gorman <pogma@thewrittenword.com>
parents: 23010
diff changeset
1984 #endif
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
1985 purple_debug_info("proxy", "Attempting connection to %s\n", ipaddr);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1986
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
1987 switch (purple_proxy_info_get_type(connect_data->gpi)) {
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
1988 case PURPLE_PROXY_NONE:
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1989 proxy_connect_none(connect_data, addr, addrlen);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1990 break;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1991
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
1992 case PURPLE_PROXY_HTTP:
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1993 proxy_connect_http(connect_data, addr, addrlen);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1994 break;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1995
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
1996 case PURPLE_PROXY_SOCKS4:
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1997 proxy_connect_socks4(connect_data, addr, addrlen);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1998 break;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1999
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
2000 case PURPLE_PROXY_SOCKS5:
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2001 proxy_connect_socks5(connect_data, addr, addrlen);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2002 break;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2003
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
2004 case PURPLE_PROXY_USE_ENVVAR:
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2005 proxy_connect_http(connect_data, addr, addrlen);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2006 break;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2007
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2008 default:
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2009 break;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2010 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2011
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2012 g_free(addr);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2013 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2014
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2015 static void
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2016 connection_host_resolved(GSList *hosts, gpointer data,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2017 const char *error_message)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2018 {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
2019 PurpleProxyConnectData *connect_data;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2020
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2021 connect_data = data;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2022 connect_data->query_data = NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2023
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2024 if (error_message != NULL)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2025 {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
2026 purple_proxy_connect_data_disconnect(connect_data, error_message);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2027 return;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2028 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2029
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2030 if (hosts == NULL)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2031 {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
2032 purple_proxy_connect_data_disconnect(connect_data, _("Could not resolve host name"));
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2033 return;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2034 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2035
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2036 connect_data->hosts = hosts;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2037
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2038 try_connect(connect_data);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2039 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2040
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
2041 PurpleProxyInfo *
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
2042 purple_proxy_get_setup(PurpleAccount *account)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2043 {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
2044 PurpleProxyInfo *gpi = NULL;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2045 const gchar *tmp;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2046
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2047 /* This is used as a fallback so we don't overwrite the selected proxy type */
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
2048 static PurpleProxyInfo *tmp_none_proxy_info = NULL;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2049 if (!tmp_none_proxy_info) {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
2050 tmp_none_proxy_info = purple_proxy_info_new();
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
2051 purple_proxy_info_set_type(tmp_none_proxy_info, PURPLE_PROXY_NONE);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2052 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2053
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
2054 if (account && purple_account_get_proxy_info(account) != NULL) {
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
2055 gpi = purple_account_get_proxy_info(account);
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
2056 if (purple_proxy_info_get_type(gpi) == PURPLE_PROXY_USE_GLOBAL)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2057 gpi = NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2058 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2059 if (gpi == NULL) {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
2060 if (purple_running_gnome())
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
2061 gpi = purple_gnome_proxy_get_info();
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2062 else
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
2063 gpi = purple_global_proxy_get_info();
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2064 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2065
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
2066 if (purple_proxy_info_get_type(gpi) == PURPLE_PROXY_USE_ENVVAR) {
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2067 if ((tmp = g_getenv("HTTP_PROXY")) != NULL ||
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2068 (tmp = g_getenv("http_proxy")) != NULL ||
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2069 (tmp = g_getenv("HTTPPROXY")) != NULL) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2070 char *proxyhost, *proxyuser, *proxypasswd;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2071 int proxyport;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2072
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2073 /* http_proxy-format:
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2074 * export http_proxy="http://user:passwd@your.proxy.server:port/"
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2075 */
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
2076 if(purple_url_parse(tmp, &proxyhost, &proxyport, NULL, &proxyuser, &proxypasswd)) {
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
2077 purple_proxy_info_set_host(gpi, proxyhost);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2078 g_free(proxyhost);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2079
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
2080 purple_proxy_info_set_username(gpi, proxyuser);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2081 g_free(proxyuser);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2082
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
2083 purple_proxy_info_set_password(gpi, proxypasswd);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2084 g_free(proxypasswd);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2085
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2086 /* only for backward compatibility */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2087 if (proxyport == 80 &&
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2088 ((tmp = g_getenv("HTTP_PROXY_PORT")) != NULL ||
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2089 (tmp = g_getenv("http_proxy_port")) != NULL ||
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2090 (tmp = g_getenv("HTTPPROXYPORT")) != NULL))
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2091 proxyport = atoi(tmp);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2092
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
2093 purple_proxy_info_set_port(gpi, proxyport);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2094
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2095 /* XXX: Do we want to skip this step if user/password were part of url? */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2096 if ((tmp = g_getenv("HTTP_PROXY_USER")) != NULL ||
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2097 (tmp = g_getenv("http_proxy_user")) != NULL ||
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2098 (tmp = g_getenv("HTTPPROXYUSER")) != NULL)
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
2099 purple_proxy_info_set_username(gpi, tmp);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2100
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2101 if ((tmp = g_getenv("HTTP_PROXY_PASS")) != NULL ||
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2102 (tmp = g_getenv("http_proxy_pass")) != NULL ||
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2103 (tmp = g_getenv("HTTPPROXYPASS")) != NULL)
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
2104 purple_proxy_info_set_password(gpi, tmp);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2105
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2106 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2107 } else {
23970
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
2108 #ifdef _WIN32
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
2109 PurpleProxyInfo *wgpi;
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
2110 if ((wgpi = purple_win32_proxy_get_info()) != NULL)
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
2111 return wgpi;
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23960
diff changeset
2112 #endif
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2113 /* no proxy environment variable found, don't use a proxy */
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
2114 purple_debug_info("proxy", "No environment settings found, not using a proxy\n");
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2115 gpi = tmp_none_proxy_info;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2116 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2117
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2118 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2119
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2120 return gpi;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2121 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2122
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
2123 PurpleProxyConnectData *
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
2124 purple_proxy_connect(void *handle, PurpleAccount *account,
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2125 const char *host, int port,
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
2126 PurpleProxyConnectFunction connect_cb, gpointer data)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2127 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2128 const char *connecthost = host;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2129 int connectport = port;
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
2130 PurpleProxyConnectData *connect_data;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2131
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2132 g_return_val_if_fail(host != NULL, NULL);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2133 g_return_val_if_fail(port > 0, NULL);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2134 g_return_val_if_fail(connect_cb != NULL, NULL);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2135
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
2136 connect_data = g_new0(PurpleProxyConnectData, 1);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2137 connect_data->fd = -1;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2138 connect_data->handle = handle;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2139 connect_data->connect_cb = connect_cb;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2140 connect_data->data = data;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2141 connect_data->host = g_strdup(host);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2142 connect_data->port = port;
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
2143 connect_data->gpi = purple_proxy_get_setup(account);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2144
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
2145 if ((purple_proxy_info_get_type(connect_data->gpi) != PURPLE_PROXY_NONE) &&
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
2146 (purple_proxy_info_get_host(connect_data->gpi) == NULL ||
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
2147 purple_proxy_info_get_port(connect_data->gpi) <= 0)) {
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2148
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
2149 purple_notify_error(NULL, NULL, _("Invalid proxy settings"), _("Either the host name or port number specified for your given proxy type is invalid."));
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
2150 purple_proxy_connect_data_destroy(connect_data);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2151 return NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2152 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2153
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
2154 switch (purple_proxy_info_get_type(connect_data->gpi))
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2155 {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
2156 case PURPLE_PROXY_NONE:
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2157 break;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2158
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
2159 case PURPLE_PROXY_HTTP:
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
2160 case PURPLE_PROXY_SOCKS4:
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
2161 case PURPLE_PROXY_SOCKS5:
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
2162 case PURPLE_PROXY_USE_ENVVAR:
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
2163 connecthost = purple_proxy_info_get_host(connect_data->gpi);
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
2164 connectport = purple_proxy_info_get_port(connect_data->gpi);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2165 break;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2166
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2167 default:
24273
1263f302d05e Add debug output when proxy configuration issues are seen. This will help to
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24119
diff changeset
2168 purple_debug_error("proxy", "Invalid Proxy type (%d) specified.\n",
1263f302d05e Add debug output when proxy configuration issues are seen. This will help to
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24119
diff changeset
2169 purple_proxy_info_get_type(connect_data->gpi));
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
2170 purple_proxy_connect_data_destroy(connect_data);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2171 return NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2172 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2173
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
2174 connect_data->query_data = purple_dnsquery_a(connecthost,
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2175 connectport, connection_host_resolved, connect_data);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2176 if (connect_data->query_data == NULL)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2177 {
24273
1263f302d05e Add debug output when proxy configuration issues are seen. This will help to
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24119
diff changeset
2178 purple_debug_error("proxy", "dns query failed unexpectedly.\n");
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
2179 purple_proxy_connect_data_destroy(connect_data);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2180 return NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2181 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2182
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2183 handles = g_slist_prepend(handles, connect_data);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2184
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2185 return connect_data;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2186 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2187
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2188 /*
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
2189 * Combine some of this code with purple_proxy_connect()
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2190 */
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
2191 PurpleProxyConnectData *
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
2192 purple_proxy_connect_socks5(void *handle, PurpleProxyInfo *gpi,
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2193 const char *host, int port,
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
2194 PurpleProxyConnectFunction connect_cb,
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2195 gpointer data)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2196 {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
2197 PurpleProxyConnectData *connect_data;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2198
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2199 g_return_val_if_fail(host != NULL, NULL);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2200 g_return_val_if_fail(port >= 0, NULL);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2201 g_return_val_if_fail(connect_cb != NULL, NULL);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2202
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
2203 connect_data = g_new0(PurpleProxyConnectData, 1);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2204 connect_data->fd = -1;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2205 connect_data->handle = handle;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2206 connect_data->connect_cb = connect_cb;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2207 connect_data->data = data;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2208 connect_data->host = g_strdup(host);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2209 connect_data->port = port;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2210 connect_data->gpi = gpi;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2211
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2212 connect_data->query_data =
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
2213 purple_dnsquery_a(purple_proxy_info_get_host(gpi),
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
2214 purple_proxy_info_get_port(gpi),
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2215 connection_host_resolved, connect_data);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2216 if (connect_data->query_data == NULL)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2217 {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
2218 purple_proxy_connect_data_destroy(connect_data);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2219 return NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2220 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2221
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2222 handles = g_slist_prepend(handles, connect_data);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2223
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2224 return connect_data;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2225 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2226
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2227 void
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
2228 purple_proxy_connect_cancel(PurpleProxyConnectData *connect_data)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2229 {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
2230 purple_proxy_connect_data_disconnect(connect_data, NULL);
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
2231 purple_proxy_connect_data_destroy(connect_data);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2232 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2233
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2234 void
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
2235 purple_proxy_connect_cancel_with_handle(void *handle)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2236 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2237 GSList *l, *l_next;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2238
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2239 for (l = handles; l != NULL; l = l_next) {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
2240 PurpleProxyConnectData *connect_data = l->data;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2241
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2242 l_next = l->next;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2243
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2244 if (connect_data->handle == handle)
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
2245 purple_proxy_connect_cancel(connect_data);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2246 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2247 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2248
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2249 static void
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
2250 proxy_pref_cb(const char *name, PurplePrefType type,
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2251 gconstpointer value, gpointer data)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2252 {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
2253 PurpleProxyInfo *info = purple_global_proxy_get_info();
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2254
16424
4999bbc52881 Works for me! Renames prefs: /core to /purple, /gaim/gtk to /pidgin, /gaim/gnt to /finch
Sean Egan <seanegan@gmail.com>
parents: 15976
diff changeset
2255 if (!strcmp(name, "/purple/proxy/type")) {
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2256 int proxytype;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2257 const char *type = value;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2258
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2259 if (!strcmp(type, "none"))
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
2260 proxytype = PURPLE_PROXY_NONE;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2261 else if (!strcmp(type, "http"))
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
2262 proxytype = PURPLE_PROXY_HTTP;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2263 else if (!strcmp(type, "socks4"))
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
2264 proxytype = PURPLE_PROXY_SOCKS4;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2265 else if (!strcmp(type, "socks5"))
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
2266 proxytype = PURPLE_PROXY_SOCKS5;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2267 else if (!strcmp(type, "envvar"))
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
2268 proxytype = PURPLE_PROXY_USE_ENVVAR;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2269 else
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2270 proxytype = -1;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2271
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
2272 purple_proxy_info_set_type(info, proxytype);
16424
4999bbc52881 Works for me! Renames prefs: /core to /purple, /gaim/gtk to /pidgin, /gaim/gnt to /finch
Sean Egan <seanegan@gmail.com>
parents: 15976
diff changeset
2273 } else if (!strcmp(name, "/purple/proxy/host"))
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
2274 purple_proxy_info_set_host(info, value);
16424
4999bbc52881 Works for me! Renames prefs: /core to /purple, /gaim/gtk to /pidgin, /gaim/gnt to /finch
Sean Egan <seanegan@gmail.com>
parents: 15976
diff changeset
2275 else if (!strcmp(name, "/purple/proxy/port"))
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
2276 purple_proxy_info_set_port(info, GPOINTER_TO_INT(value));
16424
4999bbc52881 Works for me! Renames prefs: /core to /purple, /gaim/gtk to /pidgin, /gaim/gnt to /finch
Sean Egan <seanegan@gmail.com>
parents: 15976
diff changeset
2277 else if (!strcmp(name, "/purple/proxy/username"))
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
2278 purple_proxy_info_set_username(info, value);
16424
4999bbc52881 Works for me! Renames prefs: /core to /purple, /gaim/gtk to /pidgin, /gaim/gnt to /finch
Sean Egan <seanegan@gmail.com>
parents: 15976
diff changeset
2279 else if (!strcmp(name, "/purple/proxy/password"))
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
2280 purple_proxy_info_set_password(info, value);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2281 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2282
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2283 void *
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
2284 purple_proxy_get_handle()
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2285 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2286 static int handle;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2287
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2288 return &handle;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2289 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2290
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2291 void
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
2292 purple_proxy_init(void)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2293 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2294 void *handle;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2295
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2296 /* Initialize a default proxy info struct. */
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
2297 global_proxy_info = purple_proxy_info_new();
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2298
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2299 /* Proxy */
16424
4999bbc52881 Works for me! Renames prefs: /core to /purple, /gaim/gtk to /pidgin, /gaim/gnt to /finch
Sean Egan <seanegan@gmail.com>
parents: 15976
diff changeset
2300 purple_prefs_add_none("/purple/proxy");
4999bbc52881 Works for me! Renames prefs: /core to /purple, /gaim/gtk to /pidgin, /gaim/gnt to /finch
Sean Egan <seanegan@gmail.com>
parents: 15976
diff changeset
2301 purple_prefs_add_string("/purple/proxy/type", "none");
4999bbc52881 Works for me! Renames prefs: /core to /purple, /gaim/gtk to /pidgin, /gaim/gnt to /finch
Sean Egan <seanegan@gmail.com>
parents: 15976
diff changeset
2302 purple_prefs_add_string("/purple/proxy/host", "");
4999bbc52881 Works for me! Renames prefs: /core to /purple, /gaim/gtk to /pidgin, /gaim/gnt to /finch
Sean Egan <seanegan@gmail.com>
parents: 15976
diff changeset
2303 purple_prefs_add_int("/purple/proxy/port", 0);
4999bbc52881 Works for me! Renames prefs: /core to /purple, /gaim/gtk to /pidgin, /gaim/gnt to /finch
Sean Egan <seanegan@gmail.com>
parents: 15976
diff changeset
2304 purple_prefs_add_string("/purple/proxy/username", "");
4999bbc52881 Works for me! Renames prefs: /core to /purple, /gaim/gtk to /pidgin, /gaim/gnt to /finch
Sean Egan <seanegan@gmail.com>
parents: 15976
diff changeset
2305 purple_prefs_add_string("/purple/proxy/password", "");
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2306
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2307 /* Setup callbacks for the preferences. */
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
2308 handle = purple_proxy_get_handle();
16424
4999bbc52881 Works for me! Renames prefs: /core to /purple, /gaim/gtk to /pidgin, /gaim/gnt to /finch
Sean Egan <seanegan@gmail.com>
parents: 15976
diff changeset
2309 purple_prefs_connect_callback(handle, "/purple/proxy/type", proxy_pref_cb,
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2310 NULL);
16424
4999bbc52881 Works for me! Renames prefs: /core to /purple, /gaim/gtk to /pidgin, /gaim/gnt to /finch
Sean Egan <seanegan@gmail.com>
parents: 15976
diff changeset
2311 purple_prefs_connect_callback(handle, "/purple/proxy/host", proxy_pref_cb,
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2312 NULL);
16424
4999bbc52881 Works for me! Renames prefs: /core to /purple, /gaim/gtk to /pidgin, /gaim/gnt to /finch
Sean Egan <seanegan@gmail.com>
parents: 15976
diff changeset
2313 purple_prefs_connect_callback(handle, "/purple/proxy/port", proxy_pref_cb,
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2314 NULL);
16424
4999bbc52881 Works for me! Renames prefs: /core to /purple, /gaim/gtk to /pidgin, /gaim/gnt to /finch
Sean Egan <seanegan@gmail.com>
parents: 15976
diff changeset
2315 purple_prefs_connect_callback(handle, "/purple/proxy/username",
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2316 proxy_pref_cb, NULL);
16424
4999bbc52881 Works for me! Renames prefs: /core to /purple, /gaim/gtk to /pidgin, /gaim/gnt to /finch
Sean Egan <seanegan@gmail.com>
parents: 15976
diff changeset
2317 purple_prefs_connect_callback(handle, "/purple/proxy/password",
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2318 proxy_pref_cb, NULL);
20039
1846fd2da2b4 Fix proxy settings to be loaded correctly when libpurple is initialized. This was broken because it relied on the prefs being loaded after proxy initialization so that the pref callbacks would be triggered and I changed the prefs loading to happen right at the beginning to fix other issues. Fixes #3092.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 19781
diff changeset
2319
1846fd2da2b4 Fix proxy settings to be loaded correctly when libpurple is initialized. This was broken because it relied on the prefs being loaded after proxy initialization so that the pref callbacks would be triggered and I changed the prefs loading to happen right at the beginning to fix other issues. Fixes #3092.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 19781
diff changeset
2320 /* Load the initial proxy settings */
20040
b34d0ba5e225 Apply a similar fix to the proxy prefs loading fix to the status scores.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 20039
diff changeset
2321 purple_prefs_trigger_callback("/purple/proxy/type");
b34d0ba5e225 Apply a similar fix to the proxy prefs loading fix to the status scores.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 20039
diff changeset
2322 purple_prefs_trigger_callback("/purple/proxy/host");
b34d0ba5e225 Apply a similar fix to the proxy prefs loading fix to the status scores.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 20039
diff changeset
2323 purple_prefs_trigger_callback("/purple/proxy/port");
b34d0ba5e225 Apply a similar fix to the proxy prefs loading fix to the status scores.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 20039
diff changeset
2324 purple_prefs_trigger_callback("/purple/proxy/username");
b34d0ba5e225 Apply a similar fix to the proxy prefs loading fix to the status scores.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 20039
diff changeset
2325 purple_prefs_trigger_callback("/purple/proxy/password");
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2326 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2327
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2328 void
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
2329 purple_proxy_uninit(void)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2330 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2331 while (handles != NULL)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2332 {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
2333 purple_proxy_connect_data_disconnect(handles->data, NULL);
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15681
diff changeset
2334 purple_proxy_connect_data_destroy(handles->data);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2335 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2336 }