annotate libpurple/proxy.c @ 32272:9b2f7847c133

Commit updated versions of our translations after running po/stats.pl
author Mark Doliner <mark@kingant.net>
date Thu, 18 Aug 2011 07:09:21 +0000
parents 5498ee1aa30b
children f22bc8b5b9dc
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
15374
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
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
7 *
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
8 * Purple is the legal property of its developers, whose names are too numerous
15374
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
19680
44b4e8bd759b The FSF changed its address a while ago; our files were out of date.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 19661
diff changeset
24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
15374
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 */
31980
92f3d821653f purple: Fix some compiler warnings related to new API and missing prototypes.
Paul Aurich <paul@darkrain42.org>
parents: 31930
diff changeset
32 #define _PURPLE_PROXY_C_
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
33
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
34 #include "internal.h"
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
35 #include "cipher.h"
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
36 #include "debug.h"
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
37 #include "dnsquery.h"
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
38 #include "notify.h"
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
39 #include "ntlm.h"
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
40 #include "prefs.h"
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
41 #include "proxy.h"
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
42 #include "util.h"
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
43
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
44 struct _PurpleProxyConnectData {
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
45 void *handle;
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
46 PurpleProxyConnectFunction connect_cb;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
47 gpointer data;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
48 gchar *host;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
49 int port;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
50 int fd;
27114
4c3b1bb3ba91 Add purple_proxy_connect_udp. Closes #6589.
Hu Yong <ccpaging@gmail.com>
parents: 25438
diff changeset
51 int socket_type;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
52 guint inpa;
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
53 PurpleProxyInfo *gpi;
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
54 PurpleDnsQueryData *query_data;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
55
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
56 /**
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
57 * 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
58 * 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
59 */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
60 GSList *hosts;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
61
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
62 /*
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
63 * 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
64 * connection through a proxy.
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
65 */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
66 guchar *write_buffer;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
67 gsize write_buf_len;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
68 gsize written_len;
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
69 PurpleInputFunction read_cb;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
70 guchar *read_buffer;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
71 gsize read_buf_len;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
72 gsize read_len;
31930
0eceb1304f53 Add new DNS-related API to perform lookups in the context of an account.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31929
diff changeset
73 PurpleAccount *account;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
74 };
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
75
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
76 static const char * const socks5errors[] = {
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
77 "succeeded\n",
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
78 "general SOCKS server failure\n",
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
79 "connection not allowed by ruleset\n",
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
80 "Network unreachable\n",
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
81 "Host unreachable\n",
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
82 "Connection refused\n",
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
83 "TTL expired\n",
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
84 "Command not supported\n",
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
85 "Address type not supported\n"
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
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
88 static PurpleProxyInfo *global_proxy_info = NULL;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
89
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
90 static GSList *handles = NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
91
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
92 static void try_connect(PurpleProxyConnectData *connect_data);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
93
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: 15823
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: 15823
diff changeset
95 * 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: 15823
diff changeset
96 * 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: 15823
diff changeset
97 */
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: 15823
diff changeset
98 #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: 15823
diff changeset
99
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
100 /**************************************************************************
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
101 * Proxy structure API
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
102 **************************************************************************/
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
103 PurpleProxyInfo *
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
104 purple_proxy_info_new(void)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
105 {
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
106 return g_new0(PurpleProxyInfo, 1);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
107 }
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 void
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
110 purple_proxy_info_destroy(PurpleProxyInfo *info)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
111 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
112 g_return_if_fail(info != NULL);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
113
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
114 g_free(info->host);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
115 g_free(info->username);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
116 g_free(info->password);
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 g_free(info);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
119 }
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 void
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
122 purple_proxy_info_set_type(PurpleProxyInfo *info, PurpleProxyType type)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
123 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
124 g_return_if_fail(info != NULL);
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 info->type = type;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
127 }
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 void
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
130 purple_proxy_info_set_host(PurpleProxyInfo *info, const char *host)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
131 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
132 g_return_if_fail(info != NULL);
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 g_free(info->host);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
135 info->host = g_strdup(host);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
136 }
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 void
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
139 purple_proxy_info_set_port(PurpleProxyInfo *info, int port)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
140 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
141 g_return_if_fail(info != NULL);
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 info->port = port;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
144 }
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 void
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
147 purple_proxy_info_set_username(PurpleProxyInfo *info, const char *username)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
148 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
149 g_return_if_fail(info != NULL);
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 g_free(info->username);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
152 info->username = g_strdup(username);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
153 }
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 void
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
156 purple_proxy_info_set_password(PurpleProxyInfo *info, const char *password)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
157 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
158 g_return_if_fail(info != NULL);
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 g_free(info->password);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
161 info->password = g_strdup(password);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
162 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
163
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
164 PurpleProxyType
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
165 purple_proxy_info_get_type(const PurpleProxyInfo *info)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
166 {
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
167 g_return_val_if_fail(info != NULL, PURPLE_PROXY_NONE);
15374
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 return info->type;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
170 }
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 const char *
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
173 purple_proxy_info_get_host(const PurpleProxyInfo *info)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
174 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
175 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
176
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
177 return info->host;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
178 }
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 int
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
181 purple_proxy_info_get_port(const PurpleProxyInfo *info)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
182 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
183 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
184
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
185 return info->port;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
186 }
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 const char *
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
189 purple_proxy_info_get_username(const PurpleProxyInfo *info)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
190 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
191 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
192
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
193 return info->username;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
194 }
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 const char *
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
197 purple_proxy_info_get_password(const PurpleProxyInfo *info)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
198 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
199 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
200
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
201 return info->password;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
202 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
203
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
204 /**************************************************************************
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
205 * Global Proxy API
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
206 **************************************************************************/
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
207 PurpleProxyInfo *
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
208 purple_global_proxy_get_info(void)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
209 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
210 return global_proxy_info;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
211 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
212
25392
4670851af098 Patch from fqueze to add API for setting the global proxy settings. Fixes #7610.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24714
diff changeset
213 void
4670851af098 Patch from fqueze to add API for setting the global proxy settings. Fixes #7610.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24714
diff changeset
214 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: 24714
diff changeset
215 {
4670851af098 Patch from fqueze to add API for setting the global proxy settings. Fixes #7610.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24714
diff changeset
216 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: 24714
diff changeset
217
4670851af098 Patch from fqueze to add API for setting the global proxy settings. Fixes #7610.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24714
diff changeset
218 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: 24714
diff changeset
219
4670851af098 Patch from fqueze to add API for setting the global proxy settings. Fixes #7610.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24714
diff changeset
220 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: 24714
diff changeset
221 }
4670851af098 Patch from fqueze to add API for setting the global proxy settings. Fixes #7610.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24714
diff changeset
222
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
223 static PurpleProxyInfo *
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
224 purple_gnome_proxy_get_info(void)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
225 {
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
226 static PurpleProxyInfo info = {0, NULL, 0, NULL, NULL};
23890
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23391
diff changeset
227 gboolean use_same_proxy = FALSE;
24050
d4239c588fcf Some minor cleanup; removal of unnecessary frees and setting stuff to NULL
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24049
diff changeset
228 gchar *tmp, *err = NULL;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
229
22409
31fb78b1184c Short circuit and return out of the function early if gconftool-2
Mark Doliner <mark@kingant.net>
parents: 22407
diff changeset
230 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: 22407
diff changeset
231 if (tmp == NULL)
31fb78b1184c Short circuit and return out of the function early if gconftool-2
Mark Doliner <mark@kingant.net>
parents: 22407
diff changeset
232 return purple_global_proxy_get_info();
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
233
22409
31fb78b1184c Short circuit and return out of the function early if gconftool-2
Mark Doliner <mark@kingant.net>
parents: 22407
diff changeset
234 g_free(tmp);
24050
d4239c588fcf Some minor cleanup; removal of unnecessary frees and setting stuff to NULL
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24049
diff changeset
235 tmp = NULL;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
236
22410
316c8565f562 Improve our error handling of Gnome proxy settings.
Mark Doliner <mark@kingant.net>
parents: 22409
diff changeset
237 /* Check whether to use a proxy. */
316c8565f562 Improve our error handling of Gnome proxy settings.
Mark Doliner <mark@kingant.net>
parents: 22409
diff changeset
238 if (!g_spawn_command_line_sync("gconftool-2 -g /system/proxy/mode",
23890
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23391
diff changeset
239 &tmp, &err, NULL, NULL))
22409
31fb78b1184c Short circuit and return out of the function early if gconftool-2
Mark Doliner <mark@kingant.net>
parents: 22407
diff changeset
240 return purple_global_proxy_get_info();
23890
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23391
diff changeset
241 g_free(err);
24050
d4239c588fcf Some minor cleanup; removal of unnecessary frees and setting stuff to NULL
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24049
diff changeset
242 err = NULL;
22408
6eb0749ad46c disapproval of revision 'd5ef30aafa0c0ecff773017ab7ac542f9ba7b4b4'
Mark Doliner <mark@kingant.net>
parents: 22407
diff changeset
243
25385
a6e3cb32cdd2 Patch from Paul Aurich to add purple_strequal to help readability and simplicity of code. Ie, don't need to negate the value of strcmp, since this does a strcmp and does the negation for us
Paul Aurich <paul@darkrain42.org>
parents: 24714
diff changeset
244 if (purple_strequal(tmp, "none\n")) {
22409
31fb78b1184c Short circuit and return out of the function early if gconftool-2
Mark Doliner <mark@kingant.net>
parents: 22407
diff changeset
245 info.type = PURPLE_PROXY_NONE;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
246 g_free(tmp);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
247 return &info;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
248 }
22410
316c8565f562 Improve our error handling of Gnome proxy settings.
Mark Doliner <mark@kingant.net>
parents: 22409
diff changeset
249
28437
30497d814cb9 Fix GNOME proxy settings. Fixes #10051.
Paul Aurich <paul@darkrain42.org>
parents: 28245
diff changeset
250 if (!purple_strequal(tmp, "manual\n")) {
22410
316c8565f562 Improve our error handling of Gnome proxy settings.
Mark Doliner <mark@kingant.net>
parents: 22409
diff changeset
251 /* Unknown setting. Fallback to using our global proxy settings. */
22409
31fb78b1184c Short circuit and return out of the function early if gconftool-2
Mark Doliner <mark@kingant.net>
parents: 22407
diff changeset
252 g_free(tmp);
31fb78b1184c Short circuit and return out of the function early if gconftool-2
Mark Doliner <mark@kingant.net>
parents: 22407
diff changeset
253 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: 22407
diff changeset
254 }
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
255
22409
31fb78b1184c Short circuit and return out of the function early if gconftool-2
Mark Doliner <mark@kingant.net>
parents: 22407
diff changeset
256 g_free(tmp);
24050
d4239c588fcf Some minor cleanup; removal of unnecessary frees and setting stuff to NULL
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24049
diff changeset
257 tmp = NULL;
22410
316c8565f562 Improve our error handling of Gnome proxy settings.
Mark Doliner <mark@kingant.net>
parents: 22409
diff changeset
258
22412
04b807c8b98d Bring back the lines that free info.whatever on subsequent calls to
Mark Doliner <mark@kingant.net>
parents: 22411
diff changeset
259 /* Free the old fields */
04b807c8b98d Bring back the lines that free info.whatever on subsequent calls to
Mark Doliner <mark@kingant.net>
parents: 22411
diff changeset
260 if (info.host) {
04b807c8b98d Bring back the lines that free info.whatever on subsequent calls to
Mark Doliner <mark@kingant.net>
parents: 22411
diff changeset
261 g_free(info.host);
04b807c8b98d Bring back the lines that free info.whatever on subsequent calls to
Mark Doliner <mark@kingant.net>
parents: 22411
diff changeset
262 info.host = NULL;
04b807c8b98d Bring back the lines that free info.whatever on subsequent calls to
Mark Doliner <mark@kingant.net>
parents: 22411
diff changeset
263 }
04b807c8b98d Bring back the lines that free info.whatever on subsequent calls to
Mark Doliner <mark@kingant.net>
parents: 22411
diff changeset
264 if (info.username) {
04b807c8b98d Bring back the lines that free info.whatever on subsequent calls to
Mark Doliner <mark@kingant.net>
parents: 22411
diff changeset
265 g_free(info.username);
04b807c8b98d Bring back the lines that free info.whatever on subsequent calls to
Mark Doliner <mark@kingant.net>
parents: 22411
diff changeset
266 info.username = NULL;
04b807c8b98d Bring back the lines that free info.whatever on subsequent calls to
Mark Doliner <mark@kingant.net>
parents: 22411
diff changeset
267 }
04b807c8b98d Bring back the lines that free info.whatever on subsequent calls to
Mark Doliner <mark@kingant.net>
parents: 22411
diff changeset
268 if (info.password) {
04b807c8b98d Bring back the lines that free info.whatever on subsequent calls to
Mark Doliner <mark@kingant.net>
parents: 22411
diff changeset
269 g_free(info.password);
04b807c8b98d Bring back the lines that free info.whatever on subsequent calls to
Mark Doliner <mark@kingant.net>
parents: 22411
diff changeset
270 info.password = NULL;
04b807c8b98d Bring back the lines that free info.whatever on subsequent calls to
Mark Doliner <mark@kingant.net>
parents: 22411
diff changeset
271 }
04b807c8b98d Bring back the lines that free info.whatever on subsequent calls to
Mark Doliner <mark@kingant.net>
parents: 22411
diff changeset
272
23890
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23391
diff changeset
273 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: 23391
diff changeset
274 &tmp, &err, NULL, NULL))
22409
31fb78b1184c Short circuit and return out of the function early if gconftool-2
Mark Doliner <mark@kingant.net>
parents: 22407
diff changeset
275 return purple_global_proxy_get_info();
23890
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23391
diff changeset
276 g_free(err);
24050
d4239c588fcf Some minor cleanup; removal of unnecessary frees and setting stuff to NULL
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24049
diff changeset
277 err = NULL;
23890
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23391
diff changeset
278
25385
a6e3cb32cdd2 Patch from Paul Aurich to add purple_strequal to help readability and simplicity of code. Ie, don't need to negate the value of strcmp, since this does a strcmp and does the negation for us
Paul Aurich <paul@darkrain42.org>
parents: 24714
diff changeset
279 if (purple_strequal(tmp, "true\n"))
23890
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23391
diff changeset
280 use_same_proxy = TRUE;
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23391
diff changeset
281 g_free(tmp);
24050
d4239c588fcf Some minor cleanup; removal of unnecessary frees and setting stuff to NULL
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24049
diff changeset
282 tmp = NULL;
23890
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23391
diff changeset
283
24049
0bd896cd1b90 Fix a double free. Fixes #7047
Stu Tomlinson <stu@nosnilmot.com>
parents: 24038
diff changeset
284 if (!use_same_proxy) {
0bd896cd1b90 Fix a double free. Fixes #7047
Stu Tomlinson <stu@nosnilmot.com>
parents: 24038
diff changeset
285 if (!g_spawn_command_line_sync("gconftool-2 -g /system/proxy/socks_host",
23890
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23391
diff changeset
286 &info.host, &err, NULL, NULL))
24049
0bd896cd1b90 Fix a double free. Fixes #7047
Stu Tomlinson <stu@nosnilmot.com>
parents: 24038
diff changeset
287 return purple_global_proxy_get_info();
0bd896cd1b90 Fix a double free. Fixes #7047
Stu Tomlinson <stu@nosnilmot.com>
parents: 24038
diff changeset
288 g_free(err);
24050
d4239c588fcf Some minor cleanup; removal of unnecessary frees and setting stuff to NULL
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24049
diff changeset
289 err = NULL;
24049
0bd896cd1b90 Fix a double free. Fixes #7047
Stu Tomlinson <stu@nosnilmot.com>
parents: 24038
diff changeset
290 }
23890
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23391
diff changeset
291
24049
0bd896cd1b90 Fix a double free. Fixes #7047
Stu Tomlinson <stu@nosnilmot.com>
parents: 24038
diff changeset
292 if(info.host != NULL)
0bd896cd1b90 Fix a double free. Fixes #7047
Stu Tomlinson <stu@nosnilmot.com>
parents: 24038
diff changeset
293 g_strchomp(info.host);
0bd896cd1b90 Fix a double free. Fixes #7047
Stu Tomlinson <stu@nosnilmot.com>
parents: 24038
diff changeset
294
0bd896cd1b90 Fix a double free. Fixes #7047
Stu Tomlinson <stu@nosnilmot.com>
parents: 24038
diff changeset
295 if (!use_same_proxy && (info.host != NULL) && (*info.host != '\0')) {
23890
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23391
diff changeset
296 info.type = PURPLE_PROXY_SOCKS5;
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23391
diff changeset
297 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: 23391
diff changeset
298 &tmp, &err, NULL, NULL))
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23391
diff changeset
299 {
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23391
diff changeset
300 g_free(info.host);
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23391
diff changeset
301 info.host = NULL;
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23391
diff changeset
302 return purple_global_proxy_get_info();
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23391
diff changeset
303 }
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23391
diff changeset
304 g_free(err);
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23391
diff changeset
305 info.port = atoi(tmp);
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23391
diff changeset
306 g_free(tmp);
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23391
diff changeset
307 } else {
22410
316c8565f562 Improve our error handling of Gnome proxy settings.
Mark Doliner <mark@kingant.net>
parents: 22409
diff changeset
308 g_free(info.host);
23890
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23391
diff changeset
309 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: 23391
diff changeset
310 &info.host, &err, NULL, NULL))
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23391
diff changeset
311 return purple_global_proxy_get_info();
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23391
diff changeset
312 g_free(err);
24050
d4239c588fcf Some minor cleanup; removal of unnecessary frees and setting stuff to NULL
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24049
diff changeset
313 err = NULL;
d4239c588fcf Some minor cleanup; removal of unnecessary frees and setting stuff to NULL
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24049
diff changeset
314
23890
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23391
diff changeset
315 /* 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: 23391
diff changeset
316 info.type = PURPLE_PROXY_HTTP;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
317
23890
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23391
diff changeset
318 g_strchomp(info.host);
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23391
diff changeset
319 if (*info.host == '\0')
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23391
diff changeset
320 {
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23391
diff changeset
321 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: 23391
diff changeset
322 "'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: 23391
diff changeset
323 "Pidgin's proxy settings instead.\n");
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23391
diff changeset
324 g_free(info.host);
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23391
diff changeset
325 info.host = NULL;
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23391
diff changeset
326 return purple_global_proxy_get_info();
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23391
diff changeset
327 }
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23391
diff changeset
328
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23391
diff changeset
329 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: 23391
diff changeset
330 &info.username, &err, NULL, NULL))
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23391
diff changeset
331 {
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23391
diff changeset
332 g_free(info.host);
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23391
diff changeset
333 info.host = NULL;
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23391
diff changeset
334 return purple_global_proxy_get_info();
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23391
diff changeset
335 }
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23391
diff changeset
336 g_free(err);
24050
d4239c588fcf Some minor cleanup; removal of unnecessary frees and setting stuff to NULL
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24049
diff changeset
337 err = NULL;
23890
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23391
diff changeset
338 g_strchomp(info.username);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
339
23890
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23391
diff changeset
340 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: 23391
diff changeset
341 &info.password, &err, NULL, NULL))
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23391
diff changeset
342 {
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23391
diff changeset
343 g_free(info.host);
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23391
diff changeset
344 info.host = NULL;
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23391
diff changeset
345 g_free(info.username);
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23391
diff changeset
346 info.username = NULL;
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23391
diff changeset
347 return purple_global_proxy_get_info();
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23391
diff changeset
348 }
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23391
diff changeset
349 g_free(err);
24050
d4239c588fcf Some minor cleanup; removal of unnecessary frees and setting stuff to NULL
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24049
diff changeset
350 err = NULL;
23890
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23391
diff changeset
351 g_strchomp(info.password);
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23391
diff changeset
352
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23391
diff changeset
353 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: 23391
diff changeset
354 &tmp, &err, NULL, NULL))
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23391
diff changeset
355 {
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23391
diff changeset
356 g_free(info.host);
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23391
diff changeset
357 info.host = NULL;
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23391
diff changeset
358 g_free(info.username);
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23391
diff changeset
359 info.username = NULL;
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23391
diff changeset
360 g_free(info.password);
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23391
diff changeset
361 info.password = NULL;
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23391
diff changeset
362 return purple_global_proxy_get_info();
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23391
diff changeset
363 }
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23391
diff changeset
364 g_free(err);
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23391
diff changeset
365 info.port = atoi(tmp);
64585aab233a Use SOCKS proxy if specified when running in GNOME
Stu Tomlinson <stu@nosnilmot.com>
parents: 23391
diff changeset
366 g_free(tmp);
22410
316c8565f562 Improve our error handling of Gnome proxy settings.
Mark Doliner <mark@kingant.net>
parents: 22409
diff changeset
367 }
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
368
22409
31fb78b1184c Short circuit and return out of the function early if gconftool-2
Mark Doliner <mark@kingant.net>
parents: 22407
diff changeset
369 return &info;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
370 }
23900
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23890
diff changeset
371
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23890
diff changeset
372 #ifdef _WIN32
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23890
diff changeset
373
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23890
diff changeset
374 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: 23890
diff changeset
375
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23890
diff changeset
376 /* 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: 23890
diff changeset
377 static void
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23890
diff changeset
378 _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: 23890
diff changeset
379 {
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23890
diff changeset
380 int port = default_port;
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23890
diff changeset
381 char *d;
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23890
diff changeset
382
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23890
diff changeset
383 d = g_strrstr(host, ":");
30185
9e60e300541a Fix an invalid memory deref with Windows proxy settings when there's no ":port"
mklencke@gmx.net
parents: 29434
diff changeset
384 if (d) {
23900
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23890
diff changeset
385 *d = '\0';
30185
9e60e300541a Fix an invalid memory deref with Windows proxy settings when there's no ":port"
mklencke@gmx.net
parents: 29434
diff changeset
386
9e60e300541a Fix an invalid memory deref with Windows proxy settings when there's no ":port"
mklencke@gmx.net
parents: 29434
diff changeset
387 d++;
9e60e300541a Fix an invalid memory deref with Windows proxy settings when there's no ":port"
mklencke@gmx.net
parents: 29434
diff changeset
388 if (*d)
9e60e300541a Fix an invalid memory deref with Windows proxy settings when there's no ":port"
mklencke@gmx.net
parents: 29434
diff changeset
389 sscanf(d, "%d", &port);
9e60e300541a Fix an invalid memory deref with Windows proxy settings when there's no ":port"
mklencke@gmx.net
parents: 29434
diff changeset
390
9e60e300541a Fix an invalid memory deref with Windows proxy settings when there's no ":port"
mklencke@gmx.net
parents: 29434
diff changeset
391 if (port == 0)
9e60e300541a Fix an invalid memory deref with Windows proxy settings when there's no ":port"
mklencke@gmx.net
parents: 29434
diff changeset
392 port = default_port;
9e60e300541a Fix an invalid memory deref with Windows proxy settings when there's no ":port"
mklencke@gmx.net
parents: 29434
diff changeset
393 }
23900
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23890
diff changeset
394
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23890
diff changeset
395 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: 23890
diff changeset
396 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: 23890
diff changeset
397 }
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23890
diff changeset
398
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23890
diff changeset
399 static PurpleProxyInfo *
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23890
diff changeset
400 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: 23890
diff changeset
401 {
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23890
diff changeset
402 static LPFNWINHTTPGETIEPROXYCONFIG MyWinHttpGetIEProxyConfig = NULL;
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23890
diff changeset
403 static gboolean loaded = FALSE;
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23890
diff changeset
404 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: 23890
diff changeset
405
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23890
diff changeset
406 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: 23890
diff changeset
407
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23890
diff changeset
408 if (!loaded) {
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23890
diff changeset
409 loaded = TRUE;
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23890
diff changeset
410 MyWinHttpGetIEProxyConfig = (LPFNWINHTTPGETIEPROXYCONFIG)
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23890
diff changeset
411 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: 23890
diff changeset
412 if (!MyWinHttpGetIEProxyConfig)
27313
627d23bfdb05 Increase the logging level of some debugging messages that seemed to be a
mauro.brasil@tqi.com.br
parents: 27114
diff changeset
413 purple_debug_warning("proxy", "Unable to read Windows Proxy Settings.\n");
23900
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23890
diff changeset
414 }
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23890
diff changeset
415
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23890
diff changeset
416 if (!MyWinHttpGetIEProxyConfig)
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23890
diff changeset
417 return NULL;
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23890
diff changeset
418
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23890
diff changeset
419 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: 23890
diff changeset
420 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: 23890
diff changeset
421 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: 23890
diff changeset
422 return NULL;
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23890
diff changeset
423 }
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23890
diff changeset
424
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23890
diff changeset
425 /* 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: 23890
diff changeset
426 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: 23890
diff changeset
427 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: 23890
diff changeset
428
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23890
diff changeset
429 /* 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: 23890
diff changeset
430
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23890
diff changeset
431 return NULL;
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23890
diff changeset
432
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23890
diff changeset
433 } 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: 23890
diff changeset
434 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: 23890
diff changeset
435 NULL, NULL, NULL);
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23890
diff changeset
436
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23890
diff changeset
437 /* 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: 23890
diff changeset
438 /* 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: 23890
diff changeset
439
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23890
diff changeset
440 /* 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: 23890
diff changeset
441 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: 23890
diff changeset
442 char *specific = NULL, *tmp;
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23890
diff changeset
443
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23890
diff changeset
444 /* 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: 23890
diff changeset
445 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: 23890
diff changeset
446
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23890
diff changeset
447 if (specific) {
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23890
diff changeset
448 specific += strlen("http=");
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23890
diff changeset
449 tmp = strchr(specific, ';');
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23890
diff changeset
450 if (tmp)
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23890
diff changeset
451 *tmp = '\0';
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23890
diff changeset
452 /* 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: 23890
diff changeset
453 } else
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23890
diff changeset
454 specific = proxy_list;
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23890
diff changeset
455
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23890
diff changeset
456 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: 23890
diff changeset
457 _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: 23890
diff changeset
458 /* 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: 23890
diff changeset
459 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: 23890
diff changeset
460 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: 23890
diff changeset
461
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23890
diff changeset
462 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: 23890
diff changeset
463 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: 23890
diff changeset
464 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: 23890
diff changeset
465
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23890
diff changeset
466 } 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: 23890
diff changeset
467
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23890
diff changeset
468 specific += strlen("socks=");
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23890
diff changeset
469 tmp = strchr(specific, ';');
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23890
diff changeset
470 if (tmp)
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23890
diff changeset
471 *tmp = '\0';
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23890
diff changeset
472 /* 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: 23890
diff changeset
473
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23890
diff changeset
474 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: 23890
diff changeset
475 _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: 23890
diff changeset
476 /* 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: 23890
diff changeset
477 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: 23890
diff changeset
478 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: 23890
diff changeset
479
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23890
diff changeset
480 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: 23890
diff changeset
481 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: 23890
diff changeset
482 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: 23890
diff changeset
483
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23890
diff changeset
484 } else {
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23890
diff changeset
485
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23890
diff changeset
486 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: 23890
diff changeset
487
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23890
diff changeset
488 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: 23890
diff changeset
489
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23890
diff changeset
490 }
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23890
diff changeset
491 }
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23890
diff changeset
492
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23890
diff changeset
493 /* 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: 23890
diff changeset
494
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23890
diff changeset
495 g_free(proxy_list);
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23890
diff changeset
496 } else {
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23890
diff changeset
497 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: 23890
diff changeset
498 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: 23890
diff changeset
499 }
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23890
diff changeset
500
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23890
diff changeset
501 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: 23890
diff changeset
502 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: 23890
diff changeset
503 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: 23890
diff changeset
504 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: 23890
diff changeset
505 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: 23890
diff changeset
506 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: 23890
diff changeset
507
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23890
diff changeset
508 return &info;
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23890
diff changeset
509 }
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23890
diff changeset
510 #endif
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23890
diff changeset
511
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23890
diff changeset
512
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
513 /**************************************************************************
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
514 * Proxy API
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
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 * Whoever calls this needs to have called
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
519 * purple_proxy_connect_data_disconnect() beforehand.
15374
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 static void
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
522 purple_proxy_connect_data_destroy(PurpleProxyConnectData *connect_data)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
523 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
524 handles = g_slist_remove(handles, connect_data);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
525
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
526 if (connect_data->query_data != NULL)
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
527 purple_dnsquery_destroy(connect_data->query_data);
15374
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 while (connect_data->hosts != NULL)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
530 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
531 /* Discard the length... */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
532 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
533 /* Free the address... */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
534 g_free(connect_data->hosts->data);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
535 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
536 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
537
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
538 g_free(connect_data->host);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
539 g_free(connect_data);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
540 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
541
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
542 /**
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
543 * 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
544 * 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
545 * to another IP address.
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
546 *
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
547 * 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
548 * 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
549 * 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
550 * 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
551 * 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
552 * then destroy the connect_data.
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 * @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
555 * failed. This will be passed to the callback function
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
556 * specified in the call to purple_proxy_connect(). If the
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
557 * connection was successful then pass in null.
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 static void
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
560 purple_proxy_connect_data_disconnect(PurpleProxyConnectData *connect_data, const gchar *error_message)
15374
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 if (connect_data->inpa > 0)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
563 {
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
564 purple_input_remove(connect_data->inpa);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
565 connect_data->inpa = 0;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
566 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
567
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
568 if (connect_data->fd >= 0)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
569 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
570 close(connect_data->fd);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
571 connect_data->fd = -1;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
572 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
573
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
574 g_free(connect_data->write_buffer);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
575 connect_data->write_buffer = NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
576
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
577 g_free(connect_data->read_buffer);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
578 connect_data->read_buffer = NULL;
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 if (error_message != NULL)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
581 {
27313
627d23bfdb05 Increase the logging level of some debugging messages that seemed to be a
mauro.brasil@tqi.com.br
parents: 27114
diff changeset
582 purple_debug_error("proxy", "Connection attempt failed: %s\n",
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
583 error_message);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
584 if (connect_data->hosts != NULL)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
585 try_connect(connect_data);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
586 else
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
587 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
588 /* 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
589 connect_data->connect_cb(connect_data->data, -1, error_message);
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
590 purple_proxy_connect_data_destroy(connect_data);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
591 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
592 }
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
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
595 /**
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
596 * This calls purple_proxy_connect_data_disconnect(), but it lets you
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
597 * 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
598 */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
599 static void
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
600 purple_proxy_connect_data_disconnect_formatted(PurpleProxyConnectData *connect_data, const char *format, ...)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
601 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
602 va_list args;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
603 gchar *tmp;
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 va_start(args, format);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
606 tmp = g_strdup_vprintf(format, args);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
607 va_end(args);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
608
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
609 purple_proxy_connect_data_disconnect(connect_data, tmp);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
610 g_free(tmp);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
611 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
612
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
613 static void
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
614 purple_proxy_connect_data_connected(PurpleProxyConnectData *connect_data)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
615 {
28006
3712ef8bf231 Add an explicit "Connected" message right before passing control from proxy subsystem to whomever called purple_proxy_connect.
Paul Aurich <paul@darkrain42.org>
parents: 27463
diff changeset
616 purple_debug_info("proxy", "Connected to %s:%d.\n",
3712ef8bf231 Add an explicit "Connected" message right before passing control from proxy subsystem to whomever called purple_proxy_connect.
Paul Aurich <paul@darkrain42.org>
parents: 27463
diff changeset
617 connect_data->host, connect_data->port);
3712ef8bf231 Add an explicit "Connected" message right before passing control from proxy subsystem to whomever called purple_proxy_connect.
Paul Aurich <paul@darkrain42.org>
parents: 27463
diff changeset
618
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
619 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
620
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
621 /*
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
622 * 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
623 * 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
624 * we destroy the connect_data.
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
625 */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
626 connect_data->fd = -1;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
627
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
628 purple_proxy_connect_data_disconnect(connect_data, NULL);
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
629 purple_proxy_connect_data_destroy(connect_data);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
630 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
631
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
632 static void
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
633 socket_ready_cb(gpointer data, gint source, PurpleInputCondition cond)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
634 {
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
635 PurpleProxyConnectData *connect_data = data;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
636 int error = 0;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
637 int ret;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
638
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: 15823
diff changeset
639 /* 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: 15823
diff changeset
640 * 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: 15823
diff changeset
641 */
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: 15823
diff changeset
642 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: 15823
diff changeset
643 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: 19990
diff changeset
644
24713
333f03472486 This string appears before the connection attempt, so it shouldn't be
Kevin Stange <kevin@simguy.net>
parents: 24050
diff changeset
645 purple_debug_info("proxy", "Connecting to %s:%d.\n",
15682
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: 15498
diff changeset
646 connect_data->host, connect_data->port);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
647
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
648 /*
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
649 * purple_input_get_error after a non-blocking connect returns -1 if something is
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
650 * 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
651 * 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
652 * 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
653 * and anything else is a real error.
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
654 *
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
655 * (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
656 * 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
657 * able to do something.)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
658 */
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
659 ret = purple_input_get_error(connect_data->fd, &error);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
660
15682
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: 15498
diff changeset
661 if (ret == 0 && error == EINPROGRESS) {
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
662 /* 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
663 /* TODO: Does this ever happen? */
19653
941965d6fd88 Patch from QuLogic. Fixes #2903 ('Missing newlines in debug messages.')
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 17651
diff changeset
664 purple_debug_info("proxy", "(ret == 0 && error == EINPROGRESS)\n");
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
665 return;
15682
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: 15498
diff changeset
666 }
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
667
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
668 if (ret != 0 || error != 0) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
669 if (ret != 0)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
670 error = errno;
27313
627d23bfdb05 Increase the logging level of some debugging messages that seemed to be a
mauro.brasil@tqi.com.br
parents: 27114
diff changeset
671 purple_debug_error("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
672 connect_data->host, connect_data->port, g_strerror(error));
15682
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: 15498
diff changeset
673
21121
35b4f1dc4c8d replace most calls to strerror with calls to g_strerror. strerror will return
Nathan Walp <nwalp@pidgin.im>
parents: 21015
diff changeset
674 purple_proxy_connect_data_disconnect(connect_data, g_strerror(error));
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
675 return;
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
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
678 purple_proxy_connect_data_connected(connect_data);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
679 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
680
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
681 static gboolean
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
682 clean_connect(gpointer data)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
683 {
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
684 purple_proxy_connect_data_connected(data);
15374
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 return FALSE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
687 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
688
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
689 static void
27114
4c3b1bb3ba91 Add purple_proxy_connect_udp. Closes #6589.
Hu Yong <ccpaging@gmail.com>
parents: 25438
diff changeset
690 proxy_connect_udp_none(PurpleProxyConnectData *connect_data, struct sockaddr *addr, socklen_t addrlen)
4c3b1bb3ba91 Add purple_proxy_connect_udp. Closes #6589.
Hu Yong <ccpaging@gmail.com>
parents: 25438
diff changeset
691 {
4c3b1bb3ba91 Add purple_proxy_connect_udp. Closes #6589.
Hu Yong <ccpaging@gmail.com>
parents: 25438
diff changeset
692 int flags;
4c3b1bb3ba91 Add purple_proxy_connect_udp. Closes #6589.
Hu Yong <ccpaging@gmail.com>
parents: 25438
diff changeset
693
4c3b1bb3ba91 Add purple_proxy_connect_udp. Closes #6589.
Hu Yong <ccpaging@gmail.com>
parents: 25438
diff changeset
694 purple_debug_info("proxy", "UDP Connecting to %s:%d with no proxy\n",
4c3b1bb3ba91 Add purple_proxy_connect_udp. Closes #6589.
Hu Yong <ccpaging@gmail.com>
parents: 25438
diff changeset
695 connect_data->host, connect_data->port);
4c3b1bb3ba91 Add purple_proxy_connect_udp. Closes #6589.
Hu Yong <ccpaging@gmail.com>
parents: 25438
diff changeset
696
4c3b1bb3ba91 Add purple_proxy_connect_udp. Closes #6589.
Hu Yong <ccpaging@gmail.com>
parents: 25438
diff changeset
697 connect_data->fd = socket(addr->sa_family, SOCK_DGRAM, 0);
4c3b1bb3ba91 Add purple_proxy_connect_udp. Closes #6589.
Hu Yong <ccpaging@gmail.com>
parents: 25438
diff changeset
698 if (connect_data->fd < 0)
4c3b1bb3ba91 Add purple_proxy_connect_udp. Closes #6589.
Hu Yong <ccpaging@gmail.com>
parents: 25438
diff changeset
699 {
4c3b1bb3ba91 Add purple_proxy_connect_udp. Closes #6589.
Hu Yong <ccpaging@gmail.com>
parents: 25438
diff changeset
700 purple_proxy_connect_data_disconnect_formatted(connect_data,
27457
70629a4a89ec Remove periods and newlines from many error messages that end up being used
Mark Doliner <mark@kingant.net>
parents: 27313
diff changeset
701 _("Unable to create socket: %s"), g_strerror(errno));
27114
4c3b1bb3ba91 Add purple_proxy_connect_udp. Closes #6589.
Hu Yong <ccpaging@gmail.com>
parents: 25438
diff changeset
702 return;
4c3b1bb3ba91 Add purple_proxy_connect_udp. Closes #6589.
Hu Yong <ccpaging@gmail.com>
parents: 25438
diff changeset
703 }
4c3b1bb3ba91 Add purple_proxy_connect_udp. Closes #6589.
Hu Yong <ccpaging@gmail.com>
parents: 25438
diff changeset
704
4c3b1bb3ba91 Add purple_proxy_connect_udp. Closes #6589.
Hu Yong <ccpaging@gmail.com>
parents: 25438
diff changeset
705 flags = fcntl(connect_data->fd, F_GETFL);
4c3b1bb3ba91 Add purple_proxy_connect_udp. Closes #6589.
Hu Yong <ccpaging@gmail.com>
parents: 25438
diff changeset
706 fcntl(connect_data->fd, F_SETFL, flags | O_NONBLOCK);
4c3b1bb3ba91 Add purple_proxy_connect_udp. Closes #6589.
Hu Yong <ccpaging@gmail.com>
parents: 25438
diff changeset
707 #ifndef _WIN32
4c3b1bb3ba91 Add purple_proxy_connect_udp. Closes #6589.
Hu Yong <ccpaging@gmail.com>
parents: 25438
diff changeset
708 fcntl(connect_data->fd, F_SETFD, FD_CLOEXEC);
4c3b1bb3ba91 Add purple_proxy_connect_udp. Closes #6589.
Hu Yong <ccpaging@gmail.com>
parents: 25438
diff changeset
709 #endif
4c3b1bb3ba91 Add purple_proxy_connect_udp. Closes #6589.
Hu Yong <ccpaging@gmail.com>
parents: 25438
diff changeset
710
4c3b1bb3ba91 Add purple_proxy_connect_udp. Closes #6589.
Hu Yong <ccpaging@gmail.com>
parents: 25438
diff changeset
711 if (connect(connect_data->fd, addr, addrlen) != 0)
4c3b1bb3ba91 Add purple_proxy_connect_udp. Closes #6589.
Hu Yong <ccpaging@gmail.com>
parents: 25438
diff changeset
712 {
4c3b1bb3ba91 Add purple_proxy_connect_udp. Closes #6589.
Hu Yong <ccpaging@gmail.com>
parents: 25438
diff changeset
713 if ((errno == EINPROGRESS) || (errno == EINTR))
4c3b1bb3ba91 Add purple_proxy_connect_udp. Closes #6589.
Hu Yong <ccpaging@gmail.com>
parents: 25438
diff changeset
714 {
4c3b1bb3ba91 Add purple_proxy_connect_udp. Closes #6589.
Hu Yong <ccpaging@gmail.com>
parents: 25438
diff changeset
715 purple_debug_info("proxy", "UDP Connection in progress\n");
4c3b1bb3ba91 Add purple_proxy_connect_udp. Closes #6589.
Hu Yong <ccpaging@gmail.com>
parents: 25438
diff changeset
716 connect_data->inpa = purple_input_add(connect_data->fd,
4c3b1bb3ba91 Add purple_proxy_connect_udp. Closes #6589.
Hu Yong <ccpaging@gmail.com>
parents: 25438
diff changeset
717 PURPLE_INPUT_WRITE, socket_ready_cb, connect_data);
4c3b1bb3ba91 Add purple_proxy_connect_udp. Closes #6589.
Hu Yong <ccpaging@gmail.com>
parents: 25438
diff changeset
718 }
4c3b1bb3ba91 Add purple_proxy_connect_udp. Closes #6589.
Hu Yong <ccpaging@gmail.com>
parents: 25438
diff changeset
719 else
4c3b1bb3ba91 Add purple_proxy_connect_udp. Closes #6589.
Hu Yong <ccpaging@gmail.com>
parents: 25438
diff changeset
720 {
4c3b1bb3ba91 Add purple_proxy_connect_udp. Closes #6589.
Hu Yong <ccpaging@gmail.com>
parents: 25438
diff changeset
721 purple_proxy_connect_data_disconnect(connect_data, g_strerror(errno));
4c3b1bb3ba91 Add purple_proxy_connect_udp. Closes #6589.
Hu Yong <ccpaging@gmail.com>
parents: 25438
diff changeset
722 }
4c3b1bb3ba91 Add purple_proxy_connect_udp. Closes #6589.
Hu Yong <ccpaging@gmail.com>
parents: 25438
diff changeset
723 }
4c3b1bb3ba91 Add purple_proxy_connect_udp. Closes #6589.
Hu Yong <ccpaging@gmail.com>
parents: 25438
diff changeset
724 else
4c3b1bb3ba91 Add purple_proxy_connect_udp. Closes #6589.
Hu Yong <ccpaging@gmail.com>
parents: 25438
diff changeset
725 {
4c3b1bb3ba91 Add purple_proxy_connect_udp. Closes #6589.
Hu Yong <ccpaging@gmail.com>
parents: 25438
diff changeset
726 /*
4c3b1bb3ba91 Add purple_proxy_connect_udp. Closes #6589.
Hu Yong <ccpaging@gmail.com>
parents: 25438
diff changeset
727 * The connection happened IMMEDIATELY... strange, but whatever.
4c3b1bb3ba91 Add purple_proxy_connect_udp. Closes #6589.
Hu Yong <ccpaging@gmail.com>
parents: 25438
diff changeset
728 */
4c3b1bb3ba91 Add purple_proxy_connect_udp. Closes #6589.
Hu Yong <ccpaging@gmail.com>
parents: 25438
diff changeset
729 int error = ETIMEDOUT;
4c3b1bb3ba91 Add purple_proxy_connect_udp. Closes #6589.
Hu Yong <ccpaging@gmail.com>
parents: 25438
diff changeset
730 int ret;
4c3b1bb3ba91 Add purple_proxy_connect_udp. Closes #6589.
Hu Yong <ccpaging@gmail.com>
parents: 25438
diff changeset
731
4c3b1bb3ba91 Add purple_proxy_connect_udp. Closes #6589.
Hu Yong <ccpaging@gmail.com>
parents: 25438
diff changeset
732 purple_debug_info("proxy", "UDP Connected immediately.\n");
4c3b1bb3ba91 Add purple_proxy_connect_udp. Closes #6589.
Hu Yong <ccpaging@gmail.com>
parents: 25438
diff changeset
733
4c3b1bb3ba91 Add purple_proxy_connect_udp. Closes #6589.
Hu Yong <ccpaging@gmail.com>
parents: 25438
diff changeset
734 ret = purple_input_get_error(connect_data->fd, &error);
4c3b1bb3ba91 Add purple_proxy_connect_udp. Closes #6589.
Hu Yong <ccpaging@gmail.com>
parents: 25438
diff changeset
735 if ((ret != 0) || (error != 0))
4c3b1bb3ba91 Add purple_proxy_connect_udp. Closes #6589.
Hu Yong <ccpaging@gmail.com>
parents: 25438
diff changeset
736 {
4c3b1bb3ba91 Add purple_proxy_connect_udp. Closes #6589.
Hu Yong <ccpaging@gmail.com>
parents: 25438
diff changeset
737 if (ret != 0)
4c3b1bb3ba91 Add purple_proxy_connect_udp. Closes #6589.
Hu Yong <ccpaging@gmail.com>
parents: 25438
diff changeset
738 error = errno;
4c3b1bb3ba91 Add purple_proxy_connect_udp. Closes #6589.
Hu Yong <ccpaging@gmail.com>
parents: 25438
diff changeset
739 purple_proxy_connect_data_disconnect(connect_data, g_strerror(error));
4c3b1bb3ba91 Add purple_proxy_connect_udp. Closes #6589.
Hu Yong <ccpaging@gmail.com>
parents: 25438
diff changeset
740 return;
4c3b1bb3ba91 Add purple_proxy_connect_udp. Closes #6589.
Hu Yong <ccpaging@gmail.com>
parents: 25438
diff changeset
741 }
4c3b1bb3ba91 Add purple_proxy_connect_udp. Closes #6589.
Hu Yong <ccpaging@gmail.com>
parents: 25438
diff changeset
742
4c3b1bb3ba91 Add purple_proxy_connect_udp. Closes #6589.
Hu Yong <ccpaging@gmail.com>
parents: 25438
diff changeset
743 /*
4c3b1bb3ba91 Add purple_proxy_connect_udp. Closes #6589.
Hu Yong <ccpaging@gmail.com>
parents: 25438
diff changeset
744 * We want to call the "connected" callback eventually, but we
4c3b1bb3ba91 Add purple_proxy_connect_udp. Closes #6589.
Hu Yong <ccpaging@gmail.com>
parents: 25438
diff changeset
745 * don't want to call it before we return, just in case.
4c3b1bb3ba91 Add purple_proxy_connect_udp. Closes #6589.
Hu Yong <ccpaging@gmail.com>
parents: 25438
diff changeset
746 */
4c3b1bb3ba91 Add purple_proxy_connect_udp. Closes #6589.
Hu Yong <ccpaging@gmail.com>
parents: 25438
diff changeset
747 purple_timeout_add(10, clean_connect, connect_data);
4c3b1bb3ba91 Add purple_proxy_connect_udp. Closes #6589.
Hu Yong <ccpaging@gmail.com>
parents: 25438
diff changeset
748 }
4c3b1bb3ba91 Add purple_proxy_connect_udp. Closes #6589.
Hu Yong <ccpaging@gmail.com>
parents: 25438
diff changeset
749 }
4c3b1bb3ba91 Add purple_proxy_connect_udp. Closes #6589.
Hu Yong <ccpaging@gmail.com>
parents: 25438
diff changeset
750
4c3b1bb3ba91 Add purple_proxy_connect_udp. Closes #6589.
Hu Yong <ccpaging@gmail.com>
parents: 25438
diff changeset
751 static void
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
752 proxy_connect_none(PurpleProxyConnectData *connect_data, struct sockaddr *addr, socklen_t addrlen)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
753 {
20347
04fe5601fedb applied changes from 2762c6075c0dc52a96098c5478c5bf68cfd890a3
Luke Schierer <lschiere@pidgin.im>
parents: 20074
diff changeset
754 int flags;
04fe5601fedb applied changes from 2762c6075c0dc52a96098c5478c5bf68cfd890a3
Luke Schierer <lschiere@pidgin.im>
parents: 20074
diff changeset
755
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
756 purple_debug_info("proxy", "Connecting to %s:%d with no proxy\n",
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
757 connect_data->host, connect_data->port);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
758
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
759 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
760 if (connect_data->fd < 0)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
761 {
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
762 purple_proxy_connect_data_disconnect_formatted(connect_data,
27457
70629a4a89ec Remove periods and newlines from many error messages that end up being used
Mark Doliner <mark@kingant.net>
parents: 27313
diff changeset
763 _("Unable to create socket: %s"), g_strerror(errno));
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
764 return;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
765 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
766
20347
04fe5601fedb applied changes from 2762c6075c0dc52a96098c5478c5bf68cfd890a3
Luke Schierer <lschiere@pidgin.im>
parents: 20074
diff changeset
767 flags = fcntl(connect_data->fd, F_GETFL);
04fe5601fedb applied changes from 2762c6075c0dc52a96098c5478c5bf68cfd890a3
Luke Schierer <lschiere@pidgin.im>
parents: 20074
diff changeset
768 fcntl(connect_data->fd, F_SETFL, flags | O_NONBLOCK);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
769 #ifndef _WIN32
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
770 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
771 #endif
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 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
774 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
775 if ((errno == EINPROGRESS) || (errno == EINTR))
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
776 {
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
777 purple_debug_info("proxy", "Connection in progress\n");
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
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: 15682
diff changeset
779 PURPLE_INPUT_WRITE, socket_ready_cb, connect_data);
15374
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 else
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
782 {
21121
35b4f1dc4c8d replace most calls to strerror with calls to g_strerror. strerror will return
Nathan Walp <nwalp@pidgin.im>
parents: 21015
diff changeset
783 purple_proxy_connect_data_disconnect(connect_data, g_strerror(errno));
15374
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 else
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
787 {
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 * The connection happened IMMEDIATELY... strange, but whatever.
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
790 */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
791 int error = ETIMEDOUT;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
792 int ret;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
793
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
794 purple_debug_info("proxy", "Connected immediately.\n");
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
795
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
796 ret = purple_input_get_error(connect_data->fd, &error);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
797 if ((ret != 0) || (error != 0))
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
798 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
799 if (ret != 0)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
800 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
801 purple_proxy_connect_data_disconnect(connect_data, g_strerror(error));
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
802 return;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
803 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
804
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
805 /*
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
806 * 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
807 * 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
808 */
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
809 purple_timeout_add(10, clean_connect, connect_data);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
810 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
811 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
812
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 * 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
815 * 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
816 * 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
817 * response and call a specified function.
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
818 */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
819 static void
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
820 proxy_do_write(gpointer data, gint source, PurpleInputCondition cond)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
821 {
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
822 PurpleProxyConnectData *connect_data;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
823 const guchar *request;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
824 gsize request_len;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
825 int ret;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
826
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
827 connect_data = data;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
828 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
829 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
830
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
831 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
832 if (ret <= 0)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
833 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
834 if (errno == EAGAIN)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
835 /* No worries */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
836 return;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
837
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
838 /* 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
839 purple_proxy_connect_data_disconnect(connect_data, g_strerror(errno));
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
840 return;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
841 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
842 if (ret < request_len) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
843 connect_data->written_len += ret;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
844 return;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
845 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
846
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
847 /* 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
848 g_free(connect_data->write_buffer);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
849 connect_data->write_buffer = NULL;
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
850 purple_input_remove(connect_data->inpa);
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
851 connect_data->inpa = purple_input_add(connect_data->fd,
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
852 PURPLE_INPUT_READ, connect_data->read_cb, connect_data);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
853 }
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 #define HTTP_GOODSTRING "HTTP/1.0 200"
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
856 #define HTTP_GOODSTRING2 "HTTP/1.1 200"
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 /**
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
859 * 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
860 * response to the CONNECT request.
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
861 */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
862 static void
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
863 http_canread(gpointer data, gint source, PurpleInputCondition cond)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
864 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
865 int len, headers_len, status = 0;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
866 gboolean error;
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
867 PurpleProxyConnectData *connect_data = data;
17651
79ecaab86f91 Eliminate some type punning warnings in proxy.c. This was inspired by a
Richard Laager <rlaager@wiktel.com>
parents: 17452
diff changeset
868 char *p;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
869 gsize max_read;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
870
23922
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23900
diff changeset
871 if (connect_data->read_buffer == NULL) {
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
872 connect_data->read_buf_len = 8192;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
873 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
874 connect_data->read_len = 0;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
875 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
876
17651
79ecaab86f91 Eliminate some type punning warnings in proxy.c. This was inspired by a
Richard Laager <rlaager@wiktel.com>
parents: 17452
diff changeset
877 p = (char *)connect_data->read_buffer + connect_data->read_len;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
878 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
879
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
880 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
881
23922
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23900
diff changeset
882 if (len == 0) {
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
883 purple_proxy_connect_data_disconnect(connect_data,
27457
70629a4a89ec Remove periods and newlines from many error messages that end up being used
Mark Doliner <mark@kingant.net>
parents: 27313
diff changeset
884 _("Server closed the connection"));
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
885 return;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
886 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
887
23922
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23900
diff changeset
888 if (len < 0) {
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
889 if (errno == EAGAIN)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
890 /* No worries */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
891 return;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
892
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
893 /* Error! */
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
894 purple_proxy_connect_data_disconnect_formatted(connect_data,
27457
70629a4a89ec Remove periods and newlines from many error messages that end up being used
Mark Doliner <mark@kingant.net>
parents: 27313
diff changeset
895 _("Lost connection with server: %s"), g_strerror(errno));
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
896 return;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
897 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
898
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
899 connect_data->read_len += len;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
900 p[len] = '\0';
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
901
17651
79ecaab86f91 Eliminate some type punning warnings in proxy.c. This was inspired by a
Richard Laager <rlaager@wiktel.com>
parents: 17452
diff changeset
902 p = g_strstr_len((const gchar *)connect_data->read_buffer,
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
903 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
904 if (p != NULL) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
905 *p = '\0';
17651
79ecaab86f91 Eliminate some type punning warnings in proxy.c. This was inspired by a
Richard Laager <rlaager@wiktel.com>
parents: 17452
diff changeset
906 headers_len = (p - (char *)connect_data->read_buffer) + 4;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
907 } else if(len == max_read)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
908 headers_len = len;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
909 else
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
910 return;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
911
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
912 error = strncmp((const char *)connect_data->read_buffer, "HTTP/", 5) != 0;
23922
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23900
diff changeset
913 if (!error) {
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
914 int major;
17651
79ecaab86f91 Eliminate some type punning warnings in proxy.c. This was inspired by a
Richard Laager <rlaager@wiktel.com>
parents: 17452
diff changeset
915 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: 17452
diff changeset
916 major = strtol(p, &p, 10);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
917 error = (major == 0) || (*p != '.');
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
918 if(!error) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
919 int minor;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
920 p++;
17651
79ecaab86f91 Eliminate some type punning warnings in proxy.c. This was inspired by a
Richard Laager <rlaager@wiktel.com>
parents: 17452
diff changeset
921 minor = strtol(p, &p, 10);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
922 error = (*p != ' ');
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
923 if(!error) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
924 p++;
17651
79ecaab86f91 Eliminate some type punning warnings in proxy.c. This was inspired by a
Richard Laager <rlaager@wiktel.com>
parents: 17452
diff changeset
925 status = strtol(p, &p, 10);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
926 error = (*p != ' ');
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
927 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
928 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
929 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
930
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
931 /* Read the contents */
17651
79ecaab86f91 Eliminate some type punning warnings in proxy.c. This was inspired by a
Richard Laager <rlaager@wiktel.com>
parents: 17452
diff changeset
932 p = g_strrstr((const gchar *)connect_data->read_buffer, "Content-Length: ");
23922
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23900
diff changeset
933 if (p != NULL) {
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
934 gchar *tmp;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
935 int len = 0;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
936 char tmpc;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
937 p += strlen("Content-Length: ");
17651
79ecaab86f91 Eliminate some type punning warnings in proxy.c. This was inspired by a
Richard Laager <rlaager@wiktel.com>
parents: 17452
diff changeset
938 tmp = strchr(p, '\r');
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
939 if(tmp)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
940 *tmp = '\0';
17651
79ecaab86f91 Eliminate some type punning warnings in proxy.c. This was inspired by a
Richard Laager <rlaager@wiktel.com>
parents: 17452
diff changeset
941 len = atoi(p);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
942 if(tmp)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
943 *tmp = '\r';
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
944
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
945 /* Compensate for what has already been read */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
946 len -= connect_data->read_len - headers_len;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
947 /* 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
948 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
949 while (len--) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
950 /* 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
951 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
952 break;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
953 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
954 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
955
23922
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23900
diff changeset
956 if (error) {
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
957 purple_proxy_connect_data_disconnect_formatted(connect_data,
27457
70629a4a89ec Remove periods and newlines from many error messages that end up being used
Mark Doliner <mark@kingant.net>
parents: 27313
diff changeset
958 _("Unable to parse response from HTTP proxy: %s"),
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
959 connect_data->read_buffer);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
960 return;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
961 }
23922
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23900
diff changeset
962 else if (status != 200) {
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
963 purple_debug_error("proxy",
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
964 "Proxy server replied with:\n%s\n",
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
965 connect_data->read_buffer);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
966
23922
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23900
diff changeset
967 if (status == 407 /* Proxy Auth */) {
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23900
diff changeset
968 const char *header;
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23900
diff changeset
969 gchar *request;
19990
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: 19680
diff changeset
970
23922
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23900
diff changeset
971 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: 23900
diff changeset
972 "Proxy-Authenticate: NTLM");
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23900
diff changeset
973 if (header != NULL) {
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23900
diff changeset
974 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: 23900
diff changeset
975 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: 23900
diff changeset
976 char *username = NULL, hostname[256];
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23900
diff changeset
977 gchar *response;
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23900
diff changeset
978 int ret;
19990
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: 19680
diff changeset
979
23922
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23900
diff changeset
980 ret = gethostname(hostname, sizeof(hostname));
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23900
diff changeset
981 hostname[sizeof(hostname) - 1] = '\0';
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23900
diff changeset
982 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: 23900
diff changeset
983 purple_debug_warning("proxy", "gethostname() failed -- is your hostname set?");
32235
5498ee1aa30b Copy hostname fallbacks using g_strlcpy instead of strcpy.
Ethan Blanton <elb@pidgin.im>
parents: 31986
diff changeset
984 g_strlcpy(hostname, "localhost", sizeof(hostname));
23922
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23900
diff changeset
985 }
19990
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: 19680
diff changeset
986
20359
36da9249f3a9 applied changes from e33c17e58da161b8cffaf13e9d79e9bb4b9ce4ce
Luke Schierer <lschiere@pidgin.im>
parents: 20347
diff changeset
987 if (domain != NULL)
23922
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23900
diff changeset
988 username = (char*) strchr(domain, '\\');
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23900
diff changeset
989 if (username == NULL) {
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
990 purple_proxy_connect_data_disconnect_formatted(connect_data,
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
991 _("HTTP proxy connection error %d"), status);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
992 return;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
993 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
994 *username = '\0';
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
995
23922
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23900
diff changeset
996 /* Is there a message? */
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23900
diff changeset
997 if (*header_end == ' ') {
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23900
diff changeset
998 /* Check for Type-2 */
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23900
diff changeset
999 char *tmp = (char*) header;
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23900
diff changeset
1000 guint8 *nonce;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1001
23922
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23900
diff changeset
1002 header_end++;
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23900
diff changeset
1003 username++;
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23900
diff changeset
1004 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: 23900
diff changeset
1005 *tmp = '\0';
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23900
diff changeset
1006 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: 23900
diff changeset
1007 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: 23900
diff changeset
1008 (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: 23900
diff changeset
1009 hostname,
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23900
diff changeset
1010 domain, nonce, NULL);
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23900
diff changeset
1011 username--;
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23900
diff changeset
1012 } else /* Empty message */
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23900
diff changeset
1013 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: 23900
diff changeset
1014
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1015 *username = '\\';
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1016
23922
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23900
diff changeset
1017 request = g_strdup_printf(
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23900
diff changeset
1018 "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: 23900
diff changeset
1019 "Host: %s:%d\r\n"
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23900
diff changeset
1020 "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: 23900
diff changeset
1021 "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: 23900
diff changeset
1022 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: 23900
diff changeset
1023 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: 23900
diff changeset
1024 response);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1025
23922
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23900
diff changeset
1026 g_free(response);
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23900
diff changeset
1027
30846
7c871249318b Fix some "Dead nested assignment"s and then kill off some useless
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30185
diff changeset
1028 } else if (g_strrstr((const char *)connect_data->read_buffer, "Proxy-Authenticate: Basic") != NULL) {
23922
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23900
diff changeset
1029 gchar *t1, *t2;
24471
f3103f786c86 Prevent a NULL printf crash.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24398
diff changeset
1030 const char *username, *password;
f3103f786c86 Prevent a NULL printf crash.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24398
diff changeset
1031
f3103f786c86 Prevent a NULL printf crash.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24398
diff changeset
1032 username = purple_proxy_info_get_username(connect_data->gpi);
f3103f786c86 Prevent a NULL printf crash.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24398
diff changeset
1033 password = purple_proxy_info_get_password(connect_data->gpi);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1034
23922
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23900
diff changeset
1035 t1 = g_strdup_printf("%s:%s",
24471
f3103f786c86 Prevent a NULL printf crash.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24398
diff changeset
1036 username ? username : "",
f3103f786c86 Prevent a NULL printf crash.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24398
diff changeset
1037 password ? password : "");
f3103f786c86 Prevent a NULL printf crash.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24398
diff changeset
1038 t2 = purple_base64_encode((guchar *)t1, strlen(t1));
23922
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23900
diff changeset
1039 g_free(t1);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1040
23922
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23900
diff changeset
1041 request = g_strdup_printf(
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23900
diff changeset
1042 "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: 23900
diff changeset
1043 "Host: %s:%d\r\n"
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23900
diff changeset
1044 "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: 23900
diff changeset
1045 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: 23900
diff changeset
1046 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: 23900
diff changeset
1047 t2);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1048
23922
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23900
diff changeset
1049 g_free(t2);
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23900
diff changeset
1050
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1051 } else {
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
1052 purple_proxy_connect_data_disconnect_formatted(connect_data,
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1053 _("HTTP proxy connection error %d"), status);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1054 return;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1055 }
23922
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23900
diff changeset
1056
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23900
diff changeset
1057 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: 23900
diff changeset
1058 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: 23900
diff changeset
1059 connect_data->read_buffer = NULL;
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23900
diff changeset
1060
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23900
diff changeset
1061 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: 23900
diff changeset
1062 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: 23900
diff changeset
1063 connect_data->written_len = 0;
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23900
diff changeset
1064
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23900
diff changeset
1065 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: 23900
diff changeset
1066
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23900
diff changeset
1067 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: 23900
diff changeset
1068 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: 23900
diff changeset
1069
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23900
diff changeset
1070 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: 23900
diff changeset
1071
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23900
diff changeset
1072 return;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1073 }
23922
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23900
diff changeset
1074
4a1bbe955690 Add support for sending authorization for Basic proxy authentication when the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23900
diff changeset
1075 if (status == 403) {
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1076 /* Forbidden */
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
1077 purple_proxy_connect_data_disconnect_formatted(connect_data,
27457
70629a4a89ec Remove periods and newlines from many error messages that end up being used
Mark Doliner <mark@kingant.net>
parents: 27313
diff changeset
1078 _("Access denied: HTTP proxy server forbids port %d tunneling"),
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1079 connect_data->port);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1080 } else {
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
1081 purple_proxy_connect_data_disconnect_formatted(connect_data,
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1082 _("HTTP proxy connection error %d"), status);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1083 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1084 } else {
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
1085 purple_input_remove(connect_data->inpa);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1086 connect_data->inpa = 0;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1087 g_free(connect_data->read_buffer);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1088 connect_data->read_buffer = NULL;
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
1089 purple_debug_info("proxy", "HTTP proxy connection established\n");
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
1090 purple_proxy_connect_data_connected(connect_data);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1091 return;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1092 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1093 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1094
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1095 static void
23012
2b91ea8c94d5 Rearrange some of the HTTP proxy handling to make sure that we're actually
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23010
diff changeset
1096 http_start_connect_tunneling(PurpleProxyConnectData *connect_data) {
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1097 GString *request;
29120
9750ec16f325 disapproval of revision '04b807937c8e058bcddca1fe81be8cf681345ae8'
Mark Doliner <mark@kingant.net>
parents: 29119
diff changeset
1098 int ret;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1099
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
1100 purple_debug_info("proxy", "Using CONNECT tunneling for %s:%d\n",
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1101 connect_data->host, connect_data->port);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1102
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1103 request = g_string_sized_new(4096);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1104 g_string_append_printf(request,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1105 "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
1106 connect_data->host, connect_data->port,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1107 connect_data->host, connect_data->port);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1108
29127
c01d4a1c7ee5 disapproval of revision '32e63a51dbb65b8b63d134bde098d40167574148'
Paul Aurich <paul@darkrain42.org>
parents: 29052
diff changeset
1109 if (purple_proxy_info_get_username(connect_data->gpi) != NULL)
c01d4a1c7ee5 disapproval of revision '32e63a51dbb65b8b63d134bde098d40167574148'
Paul Aurich <paul@darkrain42.org>
parents: 29052
diff changeset
1110 {
c01d4a1c7ee5 disapproval of revision '32e63a51dbb65b8b63d134bde098d40167574148'
Paul Aurich <paul@darkrain42.org>
parents: 29052
diff changeset
1111 char *t1, *t2, *ntlm_type1;
c01d4a1c7ee5 disapproval of revision '32e63a51dbb65b8b63d134bde098d40167574148'
Paul Aurich <paul@darkrain42.org>
parents: 29052
diff changeset
1112 char hostname[256];
c01d4a1c7ee5 disapproval of revision '32e63a51dbb65b8b63d134bde098d40167574148'
Paul Aurich <paul@darkrain42.org>
parents: 29052
diff changeset
1113
c01d4a1c7ee5 disapproval of revision '32e63a51dbb65b8b63d134bde098d40167574148'
Paul Aurich <paul@darkrain42.org>
parents: 29052
diff changeset
1114 ret = gethostname(hostname, sizeof(hostname));
c01d4a1c7ee5 disapproval of revision '32e63a51dbb65b8b63d134bde098d40167574148'
Paul Aurich <paul@darkrain42.org>
parents: 29052
diff changeset
1115 hostname[sizeof(hostname) - 1] = '\0';
c01d4a1c7ee5 disapproval of revision '32e63a51dbb65b8b63d134bde098d40167574148'
Paul Aurich <paul@darkrain42.org>
parents: 29052
diff changeset
1116 if (ret < 0 || hostname[0] == '\0') {
c01d4a1c7ee5 disapproval of revision '32e63a51dbb65b8b63d134bde098d40167574148'
Paul Aurich <paul@darkrain42.org>
parents: 29052
diff changeset
1117 purple_debug_warning("proxy", "gethostname() failed -- is your hostname set?");
32235
5498ee1aa30b Copy hostname fallbacks using g_strlcpy instead of strcpy.
Ethan Blanton <elb@pidgin.im>
parents: 31986
diff changeset
1118 g_strlcpy(hostname, "localhost", sizeof(hostname));
29127
c01d4a1c7ee5 disapproval of revision '32e63a51dbb65b8b63d134bde098d40167574148'
Paul Aurich <paul@darkrain42.org>
parents: 29052
diff changeset
1119 }
c01d4a1c7ee5 disapproval of revision '32e63a51dbb65b8b63d134bde098d40167574148'
Paul Aurich <paul@darkrain42.org>
parents: 29052
diff changeset
1120
c01d4a1c7ee5 disapproval of revision '32e63a51dbb65b8b63d134bde098d40167574148'
Paul Aurich <paul@darkrain42.org>
parents: 29052
diff changeset
1121 t1 = g_strdup_printf("%s:%s",
c01d4a1c7ee5 disapproval of revision '32e63a51dbb65b8b63d134bde098d40167574148'
Paul Aurich <paul@darkrain42.org>
parents: 29052
diff changeset
1122 purple_proxy_info_get_username(connect_data->gpi),
c01d4a1c7ee5 disapproval of revision '32e63a51dbb65b8b63d134bde098d40167574148'
Paul Aurich <paul@darkrain42.org>
parents: 29052
diff changeset
1123 purple_proxy_info_get_password(connect_data->gpi) ?
c01d4a1c7ee5 disapproval of revision '32e63a51dbb65b8b63d134bde098d40167574148'
Paul Aurich <paul@darkrain42.org>
parents: 29052
diff changeset
1124 purple_proxy_info_get_password(connect_data->gpi) : "");
c01d4a1c7ee5 disapproval of revision '32e63a51dbb65b8b63d134bde098d40167574148'
Paul Aurich <paul@darkrain42.org>
parents: 29052
diff changeset
1125 t2 = purple_base64_encode((const guchar *)t1, strlen(t1));
c01d4a1c7ee5 disapproval of revision '32e63a51dbb65b8b63d134bde098d40167574148'
Paul Aurich <paul@darkrain42.org>
parents: 29052
diff changeset
1126 g_free(t1);
c01d4a1c7ee5 disapproval of revision '32e63a51dbb65b8b63d134bde098d40167574148'
Paul Aurich <paul@darkrain42.org>
parents: 29052
diff changeset
1127
c01d4a1c7ee5 disapproval of revision '32e63a51dbb65b8b63d134bde098d40167574148'
Paul Aurich <paul@darkrain42.org>
parents: 29052
diff changeset
1128 ntlm_type1 = purple_ntlm_gen_type1(hostname, "");
c01d4a1c7ee5 disapproval of revision '32e63a51dbb65b8b63d134bde098d40167574148'
Paul Aurich <paul@darkrain42.org>
parents: 29052
diff changeset
1129
c01d4a1c7ee5 disapproval of revision '32e63a51dbb65b8b63d134bde098d40167574148'
Paul Aurich <paul@darkrain42.org>
parents: 29052
diff changeset
1130 g_string_append_printf(request,
c01d4a1c7ee5 disapproval of revision '32e63a51dbb65b8b63d134bde098d40167574148'
Paul Aurich <paul@darkrain42.org>
parents: 29052
diff changeset
1131 "Proxy-Authorization: Basic %s\r\n"
c01d4a1c7ee5 disapproval of revision '32e63a51dbb65b8b63d134bde098d40167574148'
Paul Aurich <paul@darkrain42.org>
parents: 29052
diff changeset
1132 "Proxy-Authorization: NTLM %s\r\n"
c01d4a1c7ee5 disapproval of revision '32e63a51dbb65b8b63d134bde098d40167574148'
Paul Aurich <paul@darkrain42.org>
parents: 29052
diff changeset
1133 "Proxy-Connection: Keep-Alive\r\n",
c01d4a1c7ee5 disapproval of revision '32e63a51dbb65b8b63d134bde098d40167574148'
Paul Aurich <paul@darkrain42.org>
parents: 29052
diff changeset
1134 t2, ntlm_type1);
c01d4a1c7ee5 disapproval of revision '32e63a51dbb65b8b63d134bde098d40167574148'
Paul Aurich <paul@darkrain42.org>
parents: 29052
diff changeset
1135 g_free(ntlm_type1);
c01d4a1c7ee5 disapproval of revision '32e63a51dbb65b8b63d134bde098d40167574148'
Paul Aurich <paul@darkrain42.org>
parents: 29052
diff changeset
1136 g_free(t2);
c01d4a1c7ee5 disapproval of revision '32e63a51dbb65b8b63d134bde098d40167574148'
Paul Aurich <paul@darkrain42.org>
parents: 29052
diff changeset
1137 }
c01d4a1c7ee5 disapproval of revision '32e63a51dbb65b8b63d134bde098d40167574148'
Paul Aurich <paul@darkrain42.org>
parents: 29052
diff changeset
1138
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1139 g_string_append(request, "\r\n");
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1140
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1141 connect_data->write_buf_len = request->len;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1142 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
1143 connect_data->written_len = 0;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1144 connect_data->read_cb = http_canread;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1145
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
1146 connect_data->inpa = purple_input_add(connect_data->fd,
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
1147 PURPLE_INPUT_WRITE, proxy_do_write, connect_data);
23012
2b91ea8c94d5 Rearrange some of the HTTP proxy handling to make sure that we're actually
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23010
diff changeset
1148 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: 23010
diff changeset
1149 }
2b91ea8c94d5 Rearrange some of the HTTP proxy handling to make sure that we're actually
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23010
diff changeset
1150
2b91ea8c94d5 Rearrange some of the HTTP proxy handling to make sure that we're actually
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23010
diff changeset
1151 static void
2b91ea8c94d5 Rearrange some of the HTTP proxy handling to make sure that we're actually
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23010
diff changeset
1152 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: 23010
diff changeset
1153 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: 23010
diff changeset
1154 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: 23010
diff changeset
1155
2b91ea8c94d5 Rearrange some of the HTTP proxy handling to make sure that we're actually
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23010
diff changeset
1156 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: 23010
diff changeset
1157 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: 23010
diff changeset
1158
2b91ea8c94d5 Rearrange some of the HTTP proxy handling to make sure that we're actually
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23010
diff changeset
1159 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: 23010
diff changeset
1160 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: 23010
diff changeset
1161 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: 23010
diff changeset
1162 }
2b91ea8c94d5 Rearrange some of the HTTP proxy handling to make sure that we're actually
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23010
diff changeset
1163
2b91ea8c94d5 Rearrange some of the HTTP proxy handling to make sure that we're actually
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23010
diff changeset
1164 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: 23010
diff changeset
1165 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: 23010
diff changeset
1166 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: 23010
diff changeset
1167 error = errno;
2b91ea8c94d5 Rearrange some of the HTTP proxy handling to make sure that we're actually
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23010
diff changeset
1168 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: 23010
diff changeset
1169 return;
2b91ea8c94d5 Rearrange some of the HTTP proxy handling to make sure that we're actually
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23010
diff changeset
1170 }
2b91ea8c94d5 Rearrange some of the HTTP proxy handling to make sure that we're actually
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23010
diff changeset
1171
2b91ea8c94d5 Rearrange some of the HTTP proxy handling to make sure that we're actually
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23010
diff changeset
1172 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: 23010
diff changeset
1173 /*
2b91ea8c94d5 Rearrange some of the HTTP proxy handling to make sure that we're actually
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23010
diff changeset
1174 * 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: 23010
diff changeset
1175 * 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: 23010
diff changeset
1176 * 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: 23010
diff changeset
1177 * 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: 23010
diff changeset
1178 * 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: 23010
diff changeset
1179 * 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: 23010
diff changeset
1180 */
2b91ea8c94d5 Rearrange some of the HTTP proxy handling to make sure that we're actually
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23010
diff changeset
1181 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: 23010
diff changeset
1182 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: 23010
diff changeset
1183 } else {
2b91ea8c94d5 Rearrange some of the HTTP proxy handling to make sure that we're actually
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23010
diff changeset
1184 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: 23010
diff changeset
1185 }
2b91ea8c94d5 Rearrange some of the HTTP proxy handling to make sure that we're actually
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23010
diff changeset
1186
15374
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
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
1190 proxy_connect_http(PurpleProxyConnectData *connect_data, struct sockaddr *addr, socklen_t addrlen)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1191 {
20347
04fe5601fedb applied changes from 2762c6075c0dc52a96098c5478c5bf68cfd890a3
Luke Schierer <lschiere@pidgin.im>
parents: 20074
diff changeset
1192 int flags;
04fe5601fedb applied changes from 2762c6075c0dc52a96098c5478c5bf68cfd890a3
Luke Schierer <lschiere@pidgin.im>
parents: 20074
diff changeset
1193
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
1194 purple_debug_info("proxy",
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1195 "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
1196 connect_data->host, connect_data->port,
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
1197 (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: 15682
diff changeset
1198 purple_proxy_info_get_port(connect_data->gpi));
15374
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 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
1201 if (connect_data->fd < 0)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1202 {
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
1203 purple_proxy_connect_data_disconnect_formatted(connect_data,
27457
70629a4a89ec Remove periods and newlines from many error messages that end up being used
Mark Doliner <mark@kingant.net>
parents: 27313
diff changeset
1204 _("Unable to create socket: %s"), g_strerror(errno));
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1205 return;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1206 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1207
20347
04fe5601fedb applied changes from 2762c6075c0dc52a96098c5478c5bf68cfd890a3
Luke Schierer <lschiere@pidgin.im>
parents: 20074
diff changeset
1208 flags = fcntl(connect_data->fd, F_GETFL);
04fe5601fedb applied changes from 2762c6075c0dc52a96098c5478c5bf68cfd890a3
Luke Schierer <lschiere@pidgin.im>
parents: 20074
diff changeset
1209 fcntl(connect_data->fd, F_SETFL, flags | O_NONBLOCK);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1210 #ifndef _WIN32
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1211 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
1212 #endif
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1213
23012
2b91ea8c94d5 Rearrange some of the HTTP proxy handling to make sure that we're actually
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23010
diff changeset
1214 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: 23010
diff changeset
1215 if (errno == EINPROGRESS || errno == EINTR) {
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
1216 purple_debug_info("proxy", "Connection in progress\n");
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1217
23012
2b91ea8c94d5 Rearrange some of the HTTP proxy handling to make sure that we're actually
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23010
diff changeset
1218 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: 23010
diff changeset
1219 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: 23010
diff changeset
1220 } 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
1221 purple_proxy_connect_data_disconnect(connect_data, g_strerror(errno));
23012
2b91ea8c94d5 Rearrange some of the HTTP proxy handling to make sure that we're actually
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23010
diff changeset
1222 } else {
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
1223 purple_debug_info("proxy", "Connected immediately.\n");
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1224
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
1225 http_canwrite(connect_data, connect_data->fd, PURPLE_INPUT_WRITE);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1226 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1227 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1228
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1229 static void
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
1230 s4_canread(gpointer data, gint source, PurpleInputCondition cond)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1231 {
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
1232 PurpleProxyConnectData *connect_data = data;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1233 guchar *buf;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1234 int len, max_read;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1235
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1236 /* 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
1237 * 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
1238
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1239 if (connect_data->read_buffer == NULL) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1240 connect_data->read_buf_len = 12;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1241 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
1242 connect_data->read_len = 0;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1243 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1244
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1245 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
1246 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
1247
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1248 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
1249
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1250 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
1251 return;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1252 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
1253 if (connect_data->read_buffer[1] == 90) {
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
1254 purple_proxy_connect_data_connected(connect_data);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1255 return;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1256 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1257 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1258
21121
35b4f1dc4c8d replace most calls to strerror with calls to g_strerror. strerror will return
Nathan Walp <nwalp@pidgin.im>
parents: 21015
diff changeset
1259 purple_proxy_connect_data_disconnect(connect_data, g_strerror(errno));
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1260 }
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 static void
25112
de01d4aa4571 Use asynchronous DNS lookups for SOCKS4.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24714
diff changeset
1263 s4_host_resolved(GSList *hosts, gpointer data, const char *error_message)
de01d4aa4571 Use asynchronous DNS lookups for SOCKS4.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24714
diff changeset
1264 {
de01d4aa4571 Use asynchronous DNS lookups for SOCKS4.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24714
diff changeset
1265 PurpleProxyConnectData *connect_data = data;
de01d4aa4571 Use asynchronous DNS lookups for SOCKS4.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24714
diff changeset
1266 unsigned char packet[9];
de01d4aa4571 Use asynchronous DNS lookups for SOCKS4.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24714
diff changeset
1267 struct sockaddr *addr;
de01d4aa4571 Use asynchronous DNS lookups for SOCKS4.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24714
diff changeset
1268
de01d4aa4571 Use asynchronous DNS lookups for SOCKS4.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24714
diff changeset
1269 connect_data->query_data = NULL;
de01d4aa4571 Use asynchronous DNS lookups for SOCKS4.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24714
diff changeset
1270
de01d4aa4571 Use asynchronous DNS lookups for SOCKS4.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24714
diff changeset
1271 if (error_message != NULL) {
de01d4aa4571 Use asynchronous DNS lookups for SOCKS4.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24714
diff changeset
1272 purple_proxy_connect_data_disconnect(connect_data, error_message);
de01d4aa4571 Use asynchronous DNS lookups for SOCKS4.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24714
diff changeset
1273 return;
de01d4aa4571 Use asynchronous DNS lookups for SOCKS4.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24714
diff changeset
1274 }
de01d4aa4571 Use asynchronous DNS lookups for SOCKS4.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24714
diff changeset
1275
de01d4aa4571 Use asynchronous DNS lookups for SOCKS4.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24714
diff changeset
1276 if (hosts == NULL) {
de01d4aa4571 Use asynchronous DNS lookups for SOCKS4.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24714
diff changeset
1277 purple_proxy_connect_data_disconnect_formatted(connect_data,
de01d4aa4571 Use asynchronous DNS lookups for SOCKS4.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24714
diff changeset
1278 _("Error resolving %s"), connect_data->host);
de01d4aa4571 Use asynchronous DNS lookups for SOCKS4.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24714
diff changeset
1279 return;
de01d4aa4571 Use asynchronous DNS lookups for SOCKS4.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24714
diff changeset
1280 }
de01d4aa4571 Use asynchronous DNS lookups for SOCKS4.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24714
diff changeset
1281
de01d4aa4571 Use asynchronous DNS lookups for SOCKS4.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24714
diff changeset
1282 /* Discard the length... */
de01d4aa4571 Use asynchronous DNS lookups for SOCKS4.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24714
diff changeset
1283 hosts = g_slist_delete_link(hosts, hosts);
de01d4aa4571 Use asynchronous DNS lookups for SOCKS4.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24714
diff changeset
1284 addr = hosts->data;
de01d4aa4571 Use asynchronous DNS lookups for SOCKS4.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24714
diff changeset
1285 hosts = g_slist_delete_link(hosts, hosts);
de01d4aa4571 Use asynchronous DNS lookups for SOCKS4.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24714
diff changeset
1286
25114
e859785b49d8 Implement support for resolving DNS via the SOCKS4 proxy in use.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 25113
diff changeset
1287 packet[0] = 0x04;
e859785b49d8 Implement support for resolving DNS via the SOCKS4 proxy in use.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 25113
diff changeset
1288 packet[1] = 0x01;
25112
de01d4aa4571 Use asynchronous DNS lookups for SOCKS4.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24714
diff changeset
1289 packet[2] = connect_data->port >> 8;
de01d4aa4571 Use asynchronous DNS lookups for SOCKS4.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24714
diff changeset
1290 packet[3] = connect_data->port & 0xff;
de01d4aa4571 Use asynchronous DNS lookups for SOCKS4.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24714
diff changeset
1291 memcpy(packet + 4, &((struct sockaddr_in *)addr)->sin_addr.s_addr, 4);
25114
e859785b49d8 Implement support for resolving DNS via the SOCKS4 proxy in use.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 25113
diff changeset
1292 packet[8] = 0x00;
25112
de01d4aa4571 Use asynchronous DNS lookups for SOCKS4.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24714
diff changeset
1293
de01d4aa4571 Use asynchronous DNS lookups for SOCKS4.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24714
diff changeset
1294 g_free(addr);
de01d4aa4571 Use asynchronous DNS lookups for SOCKS4.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24714
diff changeset
1295
de01d4aa4571 Use asynchronous DNS lookups for SOCKS4.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24714
diff changeset
1296 /* We could try the other hosts, but hopefully that shouldn't be necessary */
de01d4aa4571 Use asynchronous DNS lookups for SOCKS4.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24714
diff changeset
1297 while (hosts != NULL) {
de01d4aa4571 Use asynchronous DNS lookups for SOCKS4.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24714
diff changeset
1298 /* Discard the length... */
de01d4aa4571 Use asynchronous DNS lookups for SOCKS4.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24714
diff changeset
1299 hosts = g_slist_delete_link(hosts, hosts);
de01d4aa4571 Use asynchronous DNS lookups for SOCKS4.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24714
diff changeset
1300 /* Free the address... */
de01d4aa4571 Use asynchronous DNS lookups for SOCKS4.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24714
diff changeset
1301 g_free(hosts->data);
de01d4aa4571 Use asynchronous DNS lookups for SOCKS4.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24714
diff changeset
1302 hosts = g_slist_delete_link(hosts, hosts);
de01d4aa4571 Use asynchronous DNS lookups for SOCKS4.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24714
diff changeset
1303 }
de01d4aa4571 Use asynchronous DNS lookups for SOCKS4.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24714
diff changeset
1304
de01d4aa4571 Use asynchronous DNS lookups for SOCKS4.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24714
diff changeset
1305 connect_data->write_buffer = g_memdup(packet, sizeof(packet));
de01d4aa4571 Use asynchronous DNS lookups for SOCKS4.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24714
diff changeset
1306 connect_data->write_buf_len = sizeof(packet);
de01d4aa4571 Use asynchronous DNS lookups for SOCKS4.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24714
diff changeset
1307 connect_data->written_len = 0;
de01d4aa4571 Use asynchronous DNS lookups for SOCKS4.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24714
diff changeset
1308 connect_data->read_cb = s4_canread;
de01d4aa4571 Use asynchronous DNS lookups for SOCKS4.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24714
diff changeset
1309
de01d4aa4571 Use asynchronous DNS lookups for SOCKS4.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24714
diff changeset
1310 connect_data->inpa = purple_input_add(connect_data->fd, PURPLE_INPUT_WRITE, proxy_do_write, connect_data);
de01d4aa4571 Use asynchronous DNS lookups for SOCKS4.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24714
diff changeset
1311
de01d4aa4571 Use asynchronous DNS lookups for SOCKS4.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24714
diff changeset
1312 proxy_do_write(connect_data, connect_data->fd, PURPLE_INPUT_WRITE);
de01d4aa4571 Use asynchronous DNS lookups for SOCKS4.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24714
diff changeset
1313 }
de01d4aa4571 Use asynchronous DNS lookups for SOCKS4.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24714
diff changeset
1314
de01d4aa4571 Use asynchronous DNS lookups for SOCKS4.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24714
diff changeset
1315 static void
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
1316 s4_canwrite(gpointer data, gint source, PurpleInputCondition cond)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1317 {
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
1318 PurpleProxyConnectData *connect_data = data;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1319 int error = ETIMEDOUT;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1320 int ret;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1321
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
1322 purple_debug_info("socks4 proxy", "Connected.\n");
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1323
25112
de01d4aa4571 Use asynchronous DNS lookups for SOCKS4.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24714
diff changeset
1324 if (connect_data->inpa > 0) {
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
1325 purple_input_remove(connect_data->inpa);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1326 connect_data->inpa = 0;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1327 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1328
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
1329 ret = purple_input_get_error(connect_data->fd, &error);
25112
de01d4aa4571 Use asynchronous DNS lookups for SOCKS4.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24714
diff changeset
1330 if ((ret != 0) || (error != 0)) {
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1331 if (ret != 0)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1332 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
1333 purple_proxy_connect_data_disconnect(connect_data, g_strerror(error));
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1334 return;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1335 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1336
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1337 /*
25114
e859785b49d8 Implement support for resolving DNS via the SOCKS4 proxy in use.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 25113
diff changeset
1338 * The socks4 spec doesn't include support for doing host name lookups by
e859785b49d8 Implement support for resolving DNS via the SOCKS4 proxy in use.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 25113
diff changeset
1339 * the proxy. Many socks4 servers do this via the "socks4a" extension to
e859785b49d8 Implement support for resolving DNS via the SOCKS4 proxy in use.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 25113
diff changeset
1340 * the protocol. There doesn't appear to be a way to detect if a server
e859785b49d8 Implement support for resolving DNS via the SOCKS4 proxy in use.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 25113
diff changeset
1341 * supports this, so we require that the user set a global option.
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1342 */
25114
e859785b49d8 Implement support for resolving DNS via the SOCKS4 proxy in use.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 25113
diff changeset
1343 if (purple_prefs_get_bool("/purple/proxy/socks4_remotedns")) {
e859785b49d8 Implement support for resolving DNS via the SOCKS4 proxy in use.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 25113
diff changeset
1344 unsigned char packet[9];
e859785b49d8 Implement support for resolving DNS via the SOCKS4 proxy in use.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 25113
diff changeset
1345 int len;
e859785b49d8 Implement support for resolving DNS via the SOCKS4 proxy in use.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 25113
diff changeset
1346
e859785b49d8 Implement support for resolving DNS via the SOCKS4 proxy in use.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 25113
diff changeset
1347 purple_debug_info("socks4 proxy", "Attempting to use remote DNS.\n");
e859785b49d8 Implement support for resolving DNS via the SOCKS4 proxy in use.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 25113
diff changeset
1348
e859785b49d8 Implement support for resolving DNS via the SOCKS4 proxy in use.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 25113
diff changeset
1349 packet[0] = 0x04;
e859785b49d8 Implement support for resolving DNS via the SOCKS4 proxy in use.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 25113
diff changeset
1350 packet[1] = 0x01;
e859785b49d8 Implement support for resolving DNS via the SOCKS4 proxy in use.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 25113
diff changeset
1351 packet[2] = connect_data->port >> 8;
e859785b49d8 Implement support for resolving DNS via the SOCKS4 proxy in use.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 25113
diff changeset
1352 packet[3] = connect_data->port & 0xff;
e859785b49d8 Implement support for resolving DNS via the SOCKS4 proxy in use.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 25113
diff changeset
1353 packet[4] = 0x00;
e859785b49d8 Implement support for resolving DNS via the SOCKS4 proxy in use.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 25113
diff changeset
1354 packet[5] = 0x00;
e859785b49d8 Implement support for resolving DNS via the SOCKS4 proxy in use.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 25113
diff changeset
1355 packet[6] = 0x00;
e859785b49d8 Implement support for resolving DNS via the SOCKS4 proxy in use.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 25113
diff changeset
1356 packet[7] = 0x01;
e859785b49d8 Implement support for resolving DNS via the SOCKS4 proxy in use.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 25113
diff changeset
1357 packet[8] = 0x00;
e859785b49d8 Implement support for resolving DNS via the SOCKS4 proxy in use.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 25113
diff changeset
1358
e859785b49d8 Implement support for resolving DNS via the SOCKS4 proxy in use.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 25113
diff changeset
1359 len = sizeof(packet) + strlen(connect_data->host) + 1;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1360
25114
e859785b49d8 Implement support for resolving DNS via the SOCKS4 proxy in use.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 25113
diff changeset
1361 connect_data->write_buffer = g_malloc0(len);
e859785b49d8 Implement support for resolving DNS via the SOCKS4 proxy in use.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 25113
diff changeset
1362 memcpy(connect_data->write_buffer, packet, sizeof(packet));
e859785b49d8 Implement support for resolving DNS via the SOCKS4 proxy in use.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 25113
diff changeset
1363 memcpy(connect_data->write_buffer + sizeof(packet), connect_data->host, strlen(connect_data->host));
e859785b49d8 Implement support for resolving DNS via the SOCKS4 proxy in use.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 25113
diff changeset
1364 connect_data->write_buf_len = len;
e859785b49d8 Implement support for resolving DNS via the SOCKS4 proxy in use.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 25113
diff changeset
1365 connect_data->written_len = 0;
e859785b49d8 Implement support for resolving DNS via the SOCKS4 proxy in use.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 25113
diff changeset
1366 connect_data->read_cb = s4_canread;
e859785b49d8 Implement support for resolving DNS via the SOCKS4 proxy in use.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 25113
diff changeset
1367
e859785b49d8 Implement support for resolving DNS via the SOCKS4 proxy in use.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 25113
diff changeset
1368 connect_data->inpa = purple_input_add(connect_data->fd, PURPLE_INPUT_WRITE, proxy_do_write, connect_data);
e859785b49d8 Implement support for resolving DNS via the SOCKS4 proxy in use.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 25113
diff changeset
1369
e859785b49d8 Implement support for resolving DNS via the SOCKS4 proxy in use.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 25113
diff changeset
1370 proxy_do_write(connect_data, connect_data->fd, PURPLE_INPUT_WRITE);
e859785b49d8 Implement support for resolving DNS via the SOCKS4 proxy in use.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 25113
diff changeset
1371 } else {
31930
0eceb1304f53 Add new DNS-related API to perform lookups in the context of an account.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31929
diff changeset
1372 connect_data->query_data = purple_dnsquery_a_account(
0eceb1304f53 Add new DNS-related API to perform lookups in the context of an account.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31929
diff changeset
1373 connect_data->account, connect_data->host,
25114
e859785b49d8 Implement support for resolving DNS via the SOCKS4 proxy in use.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 25113
diff changeset
1374 connect_data->port, s4_host_resolved, connect_data);
e859785b49d8 Implement support for resolving DNS via the SOCKS4 proxy in use.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 25113
diff changeset
1375
e859785b49d8 Implement support for resolving DNS via the SOCKS4 proxy in use.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 25113
diff changeset
1376 if (connect_data->query_data == NULL) {
e859785b49d8 Implement support for resolving DNS via the SOCKS4 proxy in use.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 25113
diff changeset
1377 purple_debug_error("proxy", "dns query failed unexpectedly.\n");
e859785b49d8 Implement support for resolving DNS via the SOCKS4 proxy in use.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 25113
diff changeset
1378 purple_proxy_connect_data_destroy(connect_data);
e859785b49d8 Implement support for resolving DNS via the SOCKS4 proxy in use.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 25113
diff changeset
1379 }
25112
de01d4aa4571 Use asynchronous DNS lookups for SOCKS4.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24714
diff changeset
1380 }
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1381 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1382
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1383 static void
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
1384 proxy_connect_socks4(PurpleProxyConnectData *connect_data, struct sockaddr *addr, socklen_t addrlen)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1385 {
20347
04fe5601fedb applied changes from 2762c6075c0dc52a96098c5478c5bf68cfd890a3
Luke Schierer <lschiere@pidgin.im>
parents: 20074
diff changeset
1386 int flags;
04fe5601fedb applied changes from 2762c6075c0dc52a96098c5478c5bf68cfd890a3
Luke Schierer <lschiere@pidgin.im>
parents: 20074
diff changeset
1387
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
1388 purple_debug_info("proxy",
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1389 "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
1390 connect_data->host, connect_data->port,
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
1391 purple_proxy_info_get_host(connect_data->gpi),
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
1392 purple_proxy_info_get_port(connect_data->gpi));
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1393
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1394 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
1395 if (connect_data->fd < 0)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1396 {
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
1397 purple_proxy_connect_data_disconnect_formatted(connect_data,
27457
70629a4a89ec Remove periods and newlines from many error messages that end up being used
Mark Doliner <mark@kingant.net>
parents: 27313
diff changeset
1398 _("Unable to create socket: %s"), g_strerror(errno));
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1399 return;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1400 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1401
20347
04fe5601fedb applied changes from 2762c6075c0dc52a96098c5478c5bf68cfd890a3
Luke Schierer <lschiere@pidgin.im>
parents: 20074
diff changeset
1402 flags = fcntl(connect_data->fd, F_GETFL);
04fe5601fedb applied changes from 2762c6075c0dc52a96098c5478c5bf68cfd890a3
Luke Schierer <lschiere@pidgin.im>
parents: 20074
diff changeset
1403 fcntl(connect_data->fd, F_SETFL, flags | O_NONBLOCK);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1404 #ifndef _WIN32
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1405 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
1406 #endif
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1407
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1408 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
1409 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1410 if ((errno == EINPROGRESS) || (errno == EINTR))
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1411 {
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
1412 purple_debug_info("proxy", "Connection in progress.\n");
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
1413 connect_data->inpa = purple_input_add(connect_data->fd,
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
1414 PURPLE_INPUT_WRITE, s4_canwrite, connect_data);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1415 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1416 else
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1417 {
21121
35b4f1dc4c8d replace most calls to strerror with calls to g_strerror. strerror will return
Nathan Walp <nwalp@pidgin.im>
parents: 21015
diff changeset
1418 purple_proxy_connect_data_disconnect(connect_data, g_strerror(errno));
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1419 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1420 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1421 else
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1422 {
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
1423 purple_debug_info("proxy", "Connected immediately.\n");
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1424
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
1425 s4_canwrite(connect_data, connect_data->fd, PURPLE_INPUT_WRITE);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1426 }
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
17452
5a51af9a61a7 fix socks5 from over-reading the headers, and throwing away data (fixes jabber file receiving)
Nathan Walp <nwalp@pidgin.im>
parents: 17069
diff changeset
1429 static gboolean
5a51af9a61a7 fix socks5 from over-reading the headers, and throwing away data (fixes jabber file receiving)
Nathan Walp <nwalp@pidgin.im>
parents: 17069
diff changeset
1430 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: 17069
diff changeset
1431 {
5a51af9a61a7 fix socks5 from over-reading the headers, and throwing away data (fixes jabber file receiving)
Nathan Walp <nwalp@pidgin.im>
parents: 17069
diff changeset
1432 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: 17069
diff changeset
1433 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: 17069
diff changeset
1434 /* it's not just that we haven't read enough, it's that we haven't tried to read enough yet */
22475
3225c99785b8 Fix a bunch of compiler warnings caused by my addition of G_GNUC_PRINTF()
Mark Doliner <mark@kingant.net>
parents: 22412
diff changeset
1435 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: 22412
diff changeset
1436 " to %d\n", connect_data->read_buf_len, len);
17452
5a51af9a61a7 fix socks5 from over-reading the headers, and throwing away data (fixes jabber file receiving)
Nathan Walp <nwalp@pidgin.im>
parents: 17069
diff changeset
1437 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: 17069
diff changeset
1438 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: 17069
diff changeset
1439 }
5a51af9a61a7 fix socks5 from over-reading the headers, and throwing away data (fixes jabber file receiving)
Nathan Walp <nwalp@pidgin.im>
parents: 17069
diff changeset
1440 return FALSE;
5a51af9a61a7 fix socks5 from over-reading the headers, and throwing away data (fixes jabber file receiving)
Nathan Walp <nwalp@pidgin.im>
parents: 17069
diff changeset
1441 }
5a51af9a61a7 fix socks5 from over-reading the headers, and throwing away data (fixes jabber file receiving)
Nathan Walp <nwalp@pidgin.im>
parents: 17069
diff changeset
1442
5a51af9a61a7 fix socks5 from over-reading the headers, and throwing away data (fixes jabber file receiving)
Nathan Walp <nwalp@pidgin.im>
parents: 17069
diff changeset
1443 return TRUE;
5a51af9a61a7 fix socks5 from over-reading the headers, and throwing away data (fixes jabber file receiving)
Nathan Walp <nwalp@pidgin.im>
parents: 17069
diff changeset
1444 }
5a51af9a61a7 fix socks5 from over-reading the headers, and throwing away data (fixes jabber file receiving)
Nathan Walp <nwalp@pidgin.im>
parents: 17069
diff changeset
1445
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1446 static void
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
1447 s5_canread_again(gpointer data, gint source, PurpleInputCondition cond)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1448 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1449 guchar *dest, *buf;
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
1450 PurpleProxyConnectData *connect_data = data;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1451 int len;
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 (connect_data->read_buffer == NULL) {
23010
d0f933c88fc6 Fix SOCK5 error handling to abort when we get a bogus ATYP response. Make the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 22522
diff changeset
1454 connect_data->read_buf_len = 5;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1455 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
1456 connect_data->read_len = 0;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1457 }
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 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
1460 buf = connect_data->read_buffer;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1461
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1462 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
1463
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1464 if (len == 0)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1465 {
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
1466 purple_proxy_connect_data_disconnect(connect_data,
27457
70629a4a89ec Remove periods and newlines from many error messages that end up being used
Mark Doliner <mark@kingant.net>
parents: 27313
diff changeset
1467 _("Server closed the connection"));
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1468 return;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1469 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1470
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1471 if (len < 0)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1472 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1473 if (errno == EAGAIN)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1474 /* No worries */
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 /* Error! */
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
1478 purple_proxy_connect_data_disconnect_formatted(connect_data,
27457
70629a4a89ec Remove periods and newlines from many error messages that end up being used
Mark Doliner <mark@kingant.net>
parents: 27313
diff changeset
1479 _("Lost connection with server: %s"), g_strerror(errno));
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1480 return;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1481 }
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 connect_data->read_len += len;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1484
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1485 if(connect_data->read_len < 4)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1486 return;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1487
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1488 if ((buf[0] != 0x05) || (buf[1] != 0x00)) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1489 if ((buf[0] == 0x05) && (buf[1] < 0x09)) {
24398
0320b4a33432 Backport the 'purple_debug_*(msg)' -> 'purple_debug_*("%s", msg);' fixes.
Richard Laager <rlaager@wiktel.com>
parents: 24215
diff changeset
1490 purple_debug_error("socks5 proxy", "%s", socks5errors[buf[1]]);
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
1491 purple_proxy_connect_data_disconnect(connect_data,
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1492 socks5errors[buf[1]]);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1493 } else {
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
1494 purple_debug_error("socks5 proxy", "Bad data.\n");
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
1495 purple_proxy_connect_data_disconnect(connect_data,
27457
70629a4a89ec Remove periods and newlines from many error messages that end up being used
Mark Doliner <mark@kingant.net>
parents: 27313
diff changeset
1496 _("Received invalid data on connection with server"));
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1497 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1498 return;
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
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1501 /* Skip past BND.ADDR */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1502 switch(buf[3]) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1503 case 0x01: /* the address is a version-4 IP address, with a length of 4 octets */
17452
5a51af9a61a7 fix socks5 from over-reading the headers, and throwing away data (fixes jabber file receiving)
Nathan Walp <nwalp@pidgin.im>
parents: 17069
diff changeset
1504 if(!s5_ensure_buffer_length(connect_data, 4 + 4))
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1505 return;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1506 buf += 4 + 4;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1507 break;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1508 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
1509 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
1510 follow, there is no terminating NUL octet. */
17452
5a51af9a61a7 fix socks5 from over-reading the headers, and throwing away data (fixes jabber file receiving)
Nathan Walp <nwalp@pidgin.im>
parents: 17069
diff changeset
1511 if(!s5_ensure_buffer_length(connect_data, 4 + 1))
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1512 return;
17452
5a51af9a61a7 fix socks5 from over-reading the headers, and throwing away data (fixes jabber file receiving)
Nathan Walp <nwalp@pidgin.im>
parents: 17069
diff changeset
1513 buf += 4;
5a51af9a61a7 fix socks5 from over-reading the headers, and throwing away data (fixes jabber file receiving)
Nathan Walp <nwalp@pidgin.im>
parents: 17069
diff changeset
1514 if(!s5_ensure_buffer_length(connect_data, 4 + 1 + buf[0]))
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1515 return;
17452
5a51af9a61a7 fix socks5 from over-reading the headers, and throwing away data (fixes jabber file receiving)
Nathan Walp <nwalp@pidgin.im>
parents: 17069
diff changeset
1516 buf += buf[0] + 1;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1517 break;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1518 case 0x04: /* the address is a version-6 IP address, with a length of 16 octets */
17452
5a51af9a61a7 fix socks5 from over-reading the headers, and throwing away data (fixes jabber file receiving)
Nathan Walp <nwalp@pidgin.im>
parents: 17069
diff changeset
1519 if(!s5_ensure_buffer_length(connect_data, 4 + 16))
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1520 return;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1521 buf += 4 + 16;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1522 break;
23010
d0f933c88fc6 Fix SOCK5 error handling to abort when we get a bogus ATYP response. Make the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 22522
diff changeset
1523 default:
d0f933c88fc6 Fix SOCK5 error handling to abort when we get a bogus ATYP response. Make the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 22522
diff changeset
1524 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: 22522
diff changeset
1525 purple_proxy_connect_data_disconnect(connect_data,
27457
70629a4a89ec Remove periods and newlines from many error messages that end up being used
Mark Doliner <mark@kingant.net>
parents: 27313
diff changeset
1526 _("Received invalid data on connection with server"));
23010
d0f933c88fc6 Fix SOCK5 error handling to abort when we get a bogus ATYP response. Make the
Daniel Atallah <daniel.atallah@gmail.com>
parents: 22522
diff changeset
1527 return;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1528 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1529
17452
5a51af9a61a7 fix socks5 from over-reading the headers, and throwing away data (fixes jabber file receiving)
Nathan Walp <nwalp@pidgin.im>
parents: 17069
diff changeset
1530 /* 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: 17069
diff changeset
1531 if(!s5_ensure_buffer_length(connect_data, (buf - connect_data->read_buffer) + 2))
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1532 return;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1533
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
1534 purple_proxy_connect_data_connected(connect_data);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1535 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1536
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1537 static void
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1538 s5_sendconnect(gpointer data, int source)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1539 {
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
1540 PurpleProxyConnectData *connect_data = data;
25113
8fa011906ac3 A few type fixes.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 25112
diff changeset
1541 size_t hlen = strlen(connect_data->host);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1542 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
1543 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
1544 connect_data->written_len = 0;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1545
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1546 connect_data->write_buffer[0] = 0x05;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1547 connect_data->write_buffer[1] = 0x01; /* CONNECT */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1548 connect_data->write_buffer[2] = 0x00; /* reserved */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1549 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
1550 connect_data->write_buffer[4] = hlen;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1551 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
1552 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
1553 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
1554
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1555 connect_data->read_cb = s5_canread_again;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1556
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
1557 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: 15682
diff changeset
1558 proxy_do_write(connect_data, connect_data->fd, PURPLE_INPUT_WRITE);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1559 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1560
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1561 static void
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
1562 s5_readauth(gpointer data, gint source, PurpleInputCondition cond)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1563 {
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
1564 PurpleProxyConnectData *connect_data = data;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1565 int len;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1566
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1567 if (connect_data->read_buffer == NULL) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1568 connect_data->read_buf_len = 2;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1569 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
1570 connect_data->read_len = 0;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1571 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1572
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
1573 purple_debug_info("socks5 proxy", "Got auth response.\n");
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1574
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1575 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
1576 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
1577
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1578 if (len == 0)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1579 {
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
1580 purple_proxy_connect_data_disconnect(connect_data,
27457
70629a4a89ec Remove periods and newlines from many error messages that end up being used
Mark Doliner <mark@kingant.net>
parents: 27313
diff changeset
1581 _("Server closed the connection"));
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1582 return;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1583 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1584
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1585 if (len < 0)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1586 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1587 if (errno == EAGAIN)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1588 /* No worries */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1589 return;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1590
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1591 /* Error! */
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
1592 purple_proxy_connect_data_disconnect_formatted(connect_data,
27457
70629a4a89ec Remove periods and newlines from many error messages that end up being used
Mark Doliner <mark@kingant.net>
parents: 27313
diff changeset
1593 _("Lost connection with server: %s"), g_strerror(errno));
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1594 return;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1595 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1596
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1597 connect_data->read_len += len;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1598 if (connect_data->read_len < 2)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1599 return;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1600
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
1601 purple_input_remove(connect_data->inpa);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1602 connect_data->inpa = 0;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1603
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1604 if ((connect_data->read_buffer[0] != 0x01) || (connect_data->read_buffer[1] != 0x00)) {
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
1605 purple_proxy_connect_data_disconnect(connect_data,
27457
70629a4a89ec Remove periods and newlines from many error messages that end up being used
Mark Doliner <mark@kingant.net>
parents: 27313
diff changeset
1606 _("Received invalid data on connection with server"));
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1607 return;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1608 }
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 g_free(connect_data->read_buffer);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1611 connect_data->read_buffer = NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1612
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1613 s5_sendconnect(connect_data, connect_data->fd);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1614 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1615
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1616 static void
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1617 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
1618 {
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
1619 PurpleCipher *cipher;
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
1620 PurpleCipherContext *ctx;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1621 int i;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1622 unsigned char Kxoripad[65];
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1623 unsigned char Kxoropad[65];
25113
8fa011906ac3 A few type fixes.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 25112
diff changeset
1624 size_t pwlen;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1625
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
1626 cipher = purple_ciphers_find_cipher("md5");
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
1627 ctx = purple_cipher_context_new(cipher, NULL);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1628
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1629 memset(Kxoripad,0,sizeof(Kxoripad));
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1630 memset(Kxoropad,0,sizeof(Kxoropad));
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1631
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1632 pwlen=strlen(passwd);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1633 if (pwlen>64) {
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
1634 purple_cipher_context_append(ctx, (const guchar *)passwd, strlen(passwd));
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
1635 purple_cipher_context_digest(ctx, sizeof(Kxoripad), Kxoripad, NULL);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1636 pwlen=16;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1637 } else {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1638 memcpy(Kxoripad, passwd, pwlen);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1639 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1640 memcpy(Kxoropad,Kxoripad,pwlen);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1641
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1642 for (i=0;i<64;i++) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1643 Kxoripad[i]^=0x36;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1644 Kxoropad[i]^=0x5c;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1645 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1646
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
1647 purple_cipher_context_reset(ctx, NULL);
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
1648 purple_cipher_context_append(ctx, Kxoripad, 64);
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
1649 purple_cipher_context_append(ctx, challenge, challen);
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
1650 purple_cipher_context_digest(ctx, sizeof(Kxoripad), Kxoripad, NULL);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1651
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
1652 purple_cipher_context_reset(ctx, NULL);
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
1653 purple_cipher_context_append(ctx, Kxoropad, 64);
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
1654 purple_cipher_context_append(ctx, Kxoripad, 16);
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
1655 purple_cipher_context_digest(ctx, 16, response, NULL);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1656
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
1657 purple_cipher_context_destroy(ctx);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1658 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1659
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1660 static void
24037
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23922
diff changeset
1661 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: 23922
diff changeset
1662
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23922
diff changeset
1663 /*
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23922
diff changeset
1664 * 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: 23922
diff changeset
1665 * -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: 23922
diff changeset
1666 */
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23922
diff changeset
1667 static gssize
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23922
diff changeset
1668 s5_parse_chap_msg(PurpleProxyConnectData *connect_data)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1669 {
24037
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23922
diff changeset
1670 guchar *buf, *cmdbuf = connect_data->read_buffer;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1671 int len, navas, currentav;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1672
24037
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23922
diff changeset
1673 purple_debug_misc("socks5 proxy", "Reading CHAP message: %x\n", *cmdbuf);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1674
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1675 if (*cmdbuf != 0x01) {
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
1676 purple_proxy_connect_data_disconnect(connect_data,
27457
70629a4a89ec Remove periods and newlines from many error messages that end up being used
Mark Doliner <mark@kingant.net>
parents: 27313
diff changeset
1677 _("Received invalid data on connection with server"));
24037
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23922
diff changeset
1678 return -1;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1679 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1680 cmdbuf++;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1681
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1682 navas = *cmdbuf;
24037
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23922
diff changeset
1683
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23922
diff changeset
1684 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: 23922
diff changeset
1685
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1686 cmdbuf++;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1687
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1688 for (currentav = 0; currentav < navas; currentav++) {
22522
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: 22475
diff changeset
1689
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: 22475
diff changeset
1690 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: 22475
diff changeset
1691 /* 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: 22475
diff changeset
1692 * 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: 22475
diff changeset
1693 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: 22475
diff changeset
1694 /* 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: 22475
diff changeset
1695 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: 22475
diff changeset
1696 /* 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: 22475
diff changeset
1697 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: 22475
diff changeset
1698 /* 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: 22475
diff changeset
1699 connect_data->read_len = len + 2;
24037
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23922
diff changeset
1700
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23922
diff changeset
1701 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: 23922
diff changeset
1702
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23922
diff changeset
1703 return -1;
22522
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: 22475
diff changeset
1704 }
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: 22475
diff changeset
1705
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1706 buf = cmdbuf + 2;
22522
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: 22475
diff changeset
1707
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: 22475
diff changeset
1708 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: 22475
diff changeset
1709 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: 22475
diff changeset
1710 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: 22475
diff changeset
1711 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: 22475
diff changeset
1712 }
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: 22475
diff changeset
1713
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1714 switch (cmdbuf[0]) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1715 case 0x00:
22522
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: 22475
diff changeset
1716 purple_debug_info("socks5 proxy", "Received STATUS of %x\n", buf[0]);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1717 /* Did auth work? */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1718 if (buf[0] == 0x00) {
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
1719 purple_input_remove(connect_data->inpa);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1720 connect_data->inpa = 0;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1721 g_free(connect_data->read_buffer);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1722 connect_data->read_buffer = NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1723 /* Success */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1724 s5_sendconnect(connect_data, connect_data->fd);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1725 } else {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1726 /* Failure */
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
1727 purple_debug_warning("proxy",
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1728 "socks5 CHAP authentication "
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1729 "failed. Disconnecting...");
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
1730 purple_proxy_connect_data_disconnect(connect_data,
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1731 _("Authentication failed"));
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1732 }
24037
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23922
diff changeset
1733 return -1;
24038
71fecd0f4ce6 Add support for printing out the TEXT-MESSAGE in SOCKS5 CHAP auth.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24037
diff changeset
1734 case 0x01:
71fecd0f4ce6 Add support for printing out the TEXT-MESSAGE in SOCKS5 CHAP auth.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24037
diff changeset
1735 /* 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: 24037
diff changeset
1736 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: 24037
diff changeset
1737 break;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1738 case 0x03:
22522
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: 22475
diff changeset
1739 purple_debug_info("socks5 proxy", "Received CHALLENGE\n");
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1740 /* Server wants our credentials */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1741
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1742 connect_data->write_buf_len = 16 + 4;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1743 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
1744 connect_data->written_len = 0;
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 hmacmd5_chap(buf, cmdbuf[1],
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
1747 purple_proxy_info_get_password(connect_data->gpi),
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1748 connect_data->write_buffer + 4);
24038
71fecd0f4ce6 Add support for printing out the TEXT-MESSAGE in SOCKS5 CHAP auth.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24037
diff changeset
1749 /* TODO: What about USER-IDENTITY? */
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1750 connect_data->write_buffer[0] = 0x01;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1751 connect_data->write_buffer[1] = 0x01;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1752 connect_data->write_buffer[2] = 0x04;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1753 connect_data->write_buffer[3] = 0x10;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1754
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
1755 purple_input_remove(connect_data->inpa);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1756 g_free(connect_data->read_buffer);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1757 connect_data->read_buffer = NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1758
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1759 connect_data->read_cb = s5_readchap;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1760
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
1761 connect_data->inpa = purple_input_add(connect_data->fd,
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
1762 PURPLE_INPUT_WRITE, proxy_do_write, connect_data);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1763
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
1764 proxy_do_write(connect_data, connect_data->fd, PURPLE_INPUT_WRITE);
24037
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23922
diff changeset
1765 return -1;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1766 case 0x11:
22522
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: 22475
diff changeset
1767 purple_debug_info("socks5 proxy", "Received ALGORIGTHMS of %x\n", buf[0]);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1768 /* Server wants to select an algorithm */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1769 if (buf[0] != 0x85) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1770 /* Only currently support HMAC-MD5 */
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
1771 purple_debug_warning("proxy",
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1772 "Server tried to select an "
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1773 "algorithm that we did not advertise "
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1774 "as supporting. This is a violation "
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1775 "of the socks5 CHAP specification. "
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1776 "Disconnecting...");
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
1777 purple_proxy_connect_data_disconnect(connect_data,
27457
70629a4a89ec Remove periods and newlines from many error messages that end up being used
Mark Doliner <mark@kingant.net>
parents: 27313
diff changeset
1778 _("Received invalid data on connection with server"));
24037
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23922
diff changeset
1779 return -1;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1780 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1781 break;
22522
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: 22475
diff changeset
1782 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: 22475
diff changeset
1783 purple_debug_info("socks5 proxy", "Received unused command %x, length=%d\n", cmdbuf[0], cmdbuf[1]);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1784 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1785 cmdbuf = buf + cmdbuf[1];
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1786 }
22522
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: 22475
diff changeset
1787
24037
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23922
diff changeset
1788 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: 23922
diff changeset
1789 }
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23922
diff changeset
1790
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23922
diff changeset
1791 static void
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23922
diff changeset
1792 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: 23922
diff changeset
1793 {
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23922
diff changeset
1794 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: 23922
diff changeset
1795 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: 23922
diff changeset
1796 int len;
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23922
diff changeset
1797
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23922
diff changeset
1798 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: 23922
diff changeset
1799
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23922
diff changeset
1800 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: 23922
diff changeset
1801 /* 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: 23922
diff changeset
1802 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: 23922
diff changeset
1803 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: 23922
diff changeset
1804 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: 23922
diff changeset
1805 }
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23922
diff changeset
1806
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23922
diff changeset
1807 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: 23922
diff changeset
1808 /*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: 23922
diff changeset
1809 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: 23922
diff changeset
1810 }
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23922
diff changeset
1811
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23922
diff changeset
1812 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: 23922
diff changeset
1813 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: 23922
diff changeset
1814
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23922
diff changeset
1815 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: 23922
diff changeset
1816 purple_proxy_connect_data_disconnect(connect_data,
27457
70629a4a89ec Remove periods and newlines from many error messages that end up being used
Mark Doliner <mark@kingant.net>
parents: 27313
diff changeset
1817 _("Server closed the connection"));
24037
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23922
diff changeset
1818 return;
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23922
diff changeset
1819 }
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23922
diff changeset
1820
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23922
diff changeset
1821 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: 23922
diff changeset
1822 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: 23922
diff changeset
1823 /* No worries */
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23922
diff changeset
1824 return;
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23922
diff changeset
1825
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23922
diff changeset
1826 /* Error! */
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23922
diff changeset
1827 purple_proxy_connect_data_disconnect_formatted(connect_data,
27457
70629a4a89ec Remove periods and newlines from many error messages that end up being used
Mark Doliner <mark@kingant.net>
parents: 27313
diff changeset
1828 _("Lost connection with server: %s"), g_strerror(errno));
24037
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23922
diff changeset
1829 return;
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23922
diff changeset
1830 }
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23922
diff changeset
1831
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23922
diff changeset
1832 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: 23922
diff changeset
1833
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23922
diff changeset
1834 /* 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: 23922
diff changeset
1835 while (1) {
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23922
diff changeset
1836
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23922
diff changeset
1837 /* 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: 23922
diff changeset
1838 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: 23922
diff changeset
1839 return;
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23922
diff changeset
1840
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23922
diff changeset
1841 msg_ret = s5_parse_chap_msg(connect_data);
25113
8fa011906ac3 A few type fixes.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 25112
diff changeset
1842
24037
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23922
diff changeset
1843 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: 23922
diff changeset
1844 return;
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23922
diff changeset
1845
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23922
diff changeset
1846 /* 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: 23922
diff changeset
1847 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: 23922
diff changeset
1848
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23922
diff changeset
1849 /* 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: 23922
diff changeset
1850 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: 23922
diff changeset
1851 /* 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: 23922
diff changeset
1852 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: 23922
diff changeset
1853
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23922
diff changeset
1854 /* 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: 23922
diff changeset
1855 continue;
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23922
diff changeset
1856 }
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23922
diff changeset
1857
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23922
diff changeset
1858 break;
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23922
diff changeset
1859 }
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23922
diff changeset
1860
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1861 /* 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
1862 * 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
1863 * If this is the case, come straight back here. */
22522
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: 22475
diff changeset
1864
24037
1fb2e7951f9b Fix the SOCKS5 CHAP authentication to parse several messages if they are read at
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23922
diff changeset
1865 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: 23922
diff changeset
1866
22522
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: 22475
diff changeset
1867 /* 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: 22475
diff changeset
1868 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: 22475
diff changeset
1869 connect_data->read_buffer = NULL;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1870 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1871
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1872 static void
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
1873 s5_canread(gpointer data, gint source, PurpleInputCondition cond)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1874 {
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
1875 PurpleProxyConnectData *connect_data = data;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1876 int len;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1877
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1878 if (connect_data->read_buffer == NULL) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1879 connect_data->read_buf_len = 2;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1880 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
1881 connect_data->read_len = 0;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1882 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1883
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
1884 purple_debug_info("socks5 proxy", "Able to read.\n");
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1885
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1886 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
1887 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
1888
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1889 if (len == 0)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1890 {
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
1891 purple_proxy_connect_data_disconnect(connect_data,
27457
70629a4a89ec Remove periods and newlines from many error messages that end up being used
Mark Doliner <mark@kingant.net>
parents: 27313
diff changeset
1892 _("Server closed the connection"));
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1893 return;
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
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1896 if (len < 0)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1897 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1898 if (errno == EAGAIN)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1899 /* No worries */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1900 return;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1901
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1902 /* Error! */
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
1903 purple_proxy_connect_data_disconnect_formatted(connect_data,
27457
70629a4a89ec Remove periods and newlines from many error messages that end up being used
Mark Doliner <mark@kingant.net>
parents: 27313
diff changeset
1904 _("Lost connection with server: %s"), g_strerror(errno));
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1905 return;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1906 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1907
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1908 connect_data->read_len += len;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1909 if (connect_data->read_len < 2)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1910 return;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1911
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
1912 purple_input_remove(connect_data->inpa);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1913 connect_data->inpa = 0;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1914
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1915 if ((connect_data->read_buffer[0] != 0x05) || (connect_data->read_buffer[1] == 0xff)) {
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
1916 purple_proxy_connect_data_disconnect(connect_data,
27457
70629a4a89ec Remove periods and newlines from many error messages that end up being used
Mark Doliner <mark@kingant.net>
parents: 27313
diff changeset
1917 _("Received invalid data on connection with server"));
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1918 return;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1919 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1920
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1921 if (connect_data->read_buffer[1] == 0x02) {
25113
8fa011906ac3 A few type fixes.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 25112
diff changeset
1922 size_t i, j;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1923 const char *u, *p;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1924
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
1925 u = purple_proxy_info_get_username(connect_data->gpi);
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
1926 p = purple_proxy_info_get_password(connect_data->gpi);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1927
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1928 i = (u == NULL) ? 0 : strlen(u);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1929 j = (p == NULL) ? 0 : strlen(p);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1930
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1931 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
1932 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
1933 connect_data->written_len = 0;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1934
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1935 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
1936 connect_data->write_buffer[1] = i;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1937 if (u != NULL)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1938 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
1939 connect_data->write_buffer[2 + i] = j;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1940 if (p != NULL)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1941 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
1942
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1943 g_free(connect_data->read_buffer);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1944 connect_data->read_buffer = NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1945
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1946 connect_data->read_cb = s5_readauth;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1947
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
1948 connect_data->inpa = purple_input_add(connect_data->fd, PURPLE_INPUT_WRITE,
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1949 proxy_do_write, connect_data);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1950
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
1951 proxy_do_write(connect_data, connect_data->fd, PURPLE_INPUT_WRITE);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1952
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1953 return;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1954 } else if (connect_data->read_buffer[1] == 0x03) {
25113
8fa011906ac3 A few type fixes.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 25112
diff changeset
1955 size_t userlen;
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
1956 userlen = strlen(purple_proxy_info_get_username(connect_data->gpi));
15374
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 connect_data->write_buf_len = 7 + userlen;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1959 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
1960 connect_data->written_len = 0;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1961
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1962 connect_data->write_buffer[0] = 0x01;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1963 connect_data->write_buffer[1] = 0x02;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1964 connect_data->write_buffer[2] = 0x11;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1965 connect_data->write_buffer[3] = 0x01;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1966 connect_data->write_buffer[4] = 0x85;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1967 connect_data->write_buffer[5] = 0x02;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1968 connect_data->write_buffer[6] = userlen;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1969 memcpy(connect_data->write_buffer + 7,
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
1970 purple_proxy_info_get_username(connect_data->gpi), userlen);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1971
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1972 g_free(connect_data->read_buffer);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1973 connect_data->read_buffer = NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1974
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1975 connect_data->read_cb = s5_readchap;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1976
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
1977 connect_data->inpa = purple_input_add(connect_data->fd, PURPLE_INPUT_WRITE,
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1978 proxy_do_write, connect_data);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1979
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
1980 proxy_do_write(connect_data, connect_data->fd, PURPLE_INPUT_WRITE);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1981
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1982 return;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1983 } else {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1984 g_free(connect_data->read_buffer);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1985 connect_data->read_buffer = NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1986
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1987 s5_sendconnect(connect_data, connect_data->fd);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1988 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1989 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1990
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1991 static void
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
1992 s5_canwrite(gpointer data, gint source, PurpleInputCondition cond)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1993 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1994 unsigned char buf[5];
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1995 int i;
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
1996 PurpleProxyConnectData *connect_data = data;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1997 int error = ETIMEDOUT;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1998 int ret;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1999
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
2000 purple_debug_info("socks5 proxy", "Connected.\n");
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2001
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2002 if (connect_data->inpa > 0)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2003 {
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
2004 purple_input_remove(connect_data->inpa);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2005 connect_data->inpa = 0;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2006 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2007
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
2008 ret = purple_input_get_error(connect_data->fd, &error);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2009 if ((ret != 0) || (error != 0))
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 if (ret != 0)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2012 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
2013 purple_proxy_connect_data_disconnect(connect_data, g_strerror(error));
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2014 return;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2015 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2016
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2017 i = 0;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2018 buf[0] = 0x05; /* SOCKS version 5 */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2019
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
2020 if (purple_proxy_info_get_username(connect_data->gpi) != NULL) {
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2021 buf[1] = 0x03; /* three methods */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2022 buf[2] = 0x00; /* no authentication */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2023 buf[3] = 0x03; /* CHAP authentication */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2024 buf[4] = 0x02; /* username/password authentication */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2025 i = 5;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2026 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2027 else {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2028 buf[1] = 0x01;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2029 buf[2] = 0x00;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2030 i = 3;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2031 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2032
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2033 connect_data->write_buf_len = i;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2034 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
2035 memcpy(connect_data->write_buffer, buf, i);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2036
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2037 connect_data->read_cb = s5_canread;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2038
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
2039 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: 15682
diff changeset
2040 proxy_do_write(connect_data, connect_data->fd, PURPLE_INPUT_WRITE);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2041 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2042
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2043 static void
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
2044 proxy_connect_socks5(PurpleProxyConnectData *connect_data, struct sockaddr *addr, socklen_t addrlen)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2045 {
20347
04fe5601fedb applied changes from 2762c6075c0dc52a96098c5478c5bf68cfd890a3
Luke Schierer <lschiere@pidgin.im>
parents: 20074
diff changeset
2046 int flags;
04fe5601fedb applied changes from 2762c6075c0dc52a96098c5478c5bf68cfd890a3
Luke Schierer <lschiere@pidgin.im>
parents: 20074
diff changeset
2047
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
2048 purple_debug_info("proxy",
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2049 "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
2050 connect_data->host, connect_data->port,
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
2051 purple_proxy_info_get_host(connect_data->gpi),
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
2052 purple_proxy_info_get_port(connect_data->gpi));
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2053
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2054 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
2055 if (connect_data->fd < 0)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2056 {
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
2057 purple_proxy_connect_data_disconnect_formatted(connect_data,
27457
70629a4a89ec Remove periods and newlines from many error messages that end up being used
Mark Doliner <mark@kingant.net>
parents: 27313
diff changeset
2058 _("Unable to create socket: %s"), g_strerror(errno));
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2059 return;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2060 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2061
20347
04fe5601fedb applied changes from 2762c6075c0dc52a96098c5478c5bf68cfd890a3
Luke Schierer <lschiere@pidgin.im>
parents: 20074
diff changeset
2062 flags = fcntl(connect_data->fd, F_GETFL);
04fe5601fedb applied changes from 2762c6075c0dc52a96098c5478c5bf68cfd890a3
Luke Schierer <lschiere@pidgin.im>
parents: 20074
diff changeset
2063 fcntl(connect_data->fd, F_SETFL, flags | O_NONBLOCK);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2064 #ifndef _WIN32
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2065 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
2066 #endif
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2067
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2068 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
2069 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2070 if ((errno == EINPROGRESS) || (errno == EINTR))
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2071 {
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
2072 purple_debug_info("socks5 proxy", "Connection in progress\n");
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
2073 connect_data->inpa = purple_input_add(connect_data->fd,
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
2074 PURPLE_INPUT_WRITE, s5_canwrite, connect_data);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2075 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2076 else
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2077 {
21121
35b4f1dc4c8d replace most calls to strerror with calls to g_strerror. strerror will return
Nathan Walp <nwalp@pidgin.im>
parents: 21015
diff changeset
2078 purple_proxy_connect_data_disconnect(connect_data, g_strerror(errno));
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2079 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2080 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2081 else
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2082 {
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
2083 purple_debug_info("proxy", "Connected immediately.\n");
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2084
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
2085 s5_canwrite(connect_data, connect_data->fd, PURPLE_INPUT_WRITE);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2086 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2087 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2088
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2089 /**
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2090 * This function attempts to connect to the next IP address in the list
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
2091 * of IP addresses returned to us by purple_dnsquery_a() and attemps
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2092 * 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
2093 * 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
2094 * is another IP address to try).
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2095 */
23203
313b87adb730 A patch from Peter O'Gorman at The Written Word, Inc. to fix various
Peter O'Gorman <pogma@thewrittenword.com>
parents: 23012
diff changeset
2096 #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: 23012
diff changeset
2097 #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: 23012
diff changeset
2098 #endif
313b87adb730 A patch from Peter O'Gorman at The Written Word, Inc. to fix various
Peter O'Gorman <pogma@thewrittenword.com>
parents: 23012
diff changeset
2099
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
2100 static void try_connect(PurpleProxyConnectData *connect_data)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2101 {
25113
8fa011906ac3 A few type fixes.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 25112
diff changeset
2102 socklen_t addrlen;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2103 struct sockaddr *addr;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2104 char ipaddr[INET6_ADDRSTRLEN];
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 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
2107 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
2108 addr = connect_data->hosts->data;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2109 connect_data->hosts = g_slist_remove(connect_data->hosts, connect_data->hosts->data);
23203
313b87adb730 A patch from Peter O'Gorman at The Written Word, Inc. to fix various
Peter O'Gorman <pogma@thewrittenword.com>
parents: 23012
diff changeset
2110 #ifdef HAVE_INET_NTOP
29434
0257b8fe21d6 proxy: Fix printing IPv6 addresses
Paul Aurich <paul@darkrain42.org>
parents: 29129
diff changeset
2111 if (addr->sa_family == AF_INET)
0257b8fe21d6 proxy: Fix printing IPv6 addresses
Paul Aurich <paul@darkrain42.org>
parents: 29129
diff changeset
2112 inet_ntop(addr->sa_family, &((struct sockaddr_in *)addr)->sin_addr,
0257b8fe21d6 proxy: Fix printing IPv6 addresses
Paul Aurich <paul@darkrain42.org>
parents: 29129
diff changeset
2113 ipaddr, sizeof(ipaddr));
0257b8fe21d6 proxy: Fix printing IPv6 addresses
Paul Aurich <paul@darkrain42.org>
parents: 29129
diff changeset
2114 else if (addr->sa_family == AF_INET6)
0257b8fe21d6 proxy: Fix printing IPv6 addresses
Paul Aurich <paul@darkrain42.org>
parents: 29129
diff changeset
2115 inet_ntop(addr->sa_family, &((struct sockaddr_in6 *)addr)->sin6_addr,
0257b8fe21d6 proxy: Fix printing IPv6 addresses
Paul Aurich <paul@darkrain42.org>
parents: 29129
diff changeset
2116 ipaddr, sizeof(ipaddr));
23203
313b87adb730 A patch from Peter O'Gorman at The Written Word, Inc. to fix various
Peter O'Gorman <pogma@thewrittenword.com>
parents: 23012
diff changeset
2117 #else
25113
8fa011906ac3 A few type fixes.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 25112
diff changeset
2118 memcpy(ipaddr, inet_ntoa(((struct sockaddr_in *)addr)->sin_addr),
23203
313b87adb730 A patch from Peter O'Gorman at The Written Word, Inc. to fix various
Peter O'Gorman <pogma@thewrittenword.com>
parents: 23012
diff changeset
2119 sizeof(ipaddr));
313b87adb730 A patch from Peter O'Gorman at The Written Word, Inc. to fix various
Peter O'Gorman <pogma@thewrittenword.com>
parents: 23012
diff changeset
2120 #endif
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
2121 purple_debug_info("proxy", "Attempting connection to %s\n", ipaddr);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2122
27114
4c3b1bb3ba91 Add purple_proxy_connect_udp. Closes #6589.
Hu Yong <ccpaging@gmail.com>
parents: 25438
diff changeset
2123 if (connect_data->socket_type == SOCK_DGRAM) {
4c3b1bb3ba91 Add purple_proxy_connect_udp. Closes #6589.
Hu Yong <ccpaging@gmail.com>
parents: 25438
diff changeset
2124 proxy_connect_udp_none(connect_data, addr, addrlen);
4c3b1bb3ba91 Add purple_proxy_connect_udp. Closes #6589.
Hu Yong <ccpaging@gmail.com>
parents: 25438
diff changeset
2125 g_free(addr);
4c3b1bb3ba91 Add purple_proxy_connect_udp. Closes #6589.
Hu Yong <ccpaging@gmail.com>
parents: 25438
diff changeset
2126 return;
4c3b1bb3ba91 Add purple_proxy_connect_udp. Closes #6589.
Hu Yong <ccpaging@gmail.com>
parents: 25438
diff changeset
2127 }
4c3b1bb3ba91 Add purple_proxy_connect_udp. Closes #6589.
Hu Yong <ccpaging@gmail.com>
parents: 25438
diff changeset
2128
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
2129 switch (purple_proxy_info_get_type(connect_data->gpi)) {
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
2130 case PURPLE_PROXY_NONE:
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2131 proxy_connect_none(connect_data, addr, addrlen);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2132 break;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2133
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
2134 case PURPLE_PROXY_HTTP:
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2135 proxy_connect_http(connect_data, addr, addrlen);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2136 break;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2137
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
2138 case PURPLE_PROXY_SOCKS4:
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2139 proxy_connect_socks4(connect_data, addr, addrlen);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2140 break;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2141
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
2142 case PURPLE_PROXY_SOCKS5:
31929
9a7c5d242521 Add a new proxy type of "Tor". This is really just a SOCKS5 proxy, but can be
Daniel Atallah <daniel.atallah@gmail.com>
parents: 30846
diff changeset
2143 case PURPLE_PROXY_TOR:
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2144 proxy_connect_socks5(connect_data, addr, addrlen);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2145 break;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2146
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
2147 case PURPLE_PROXY_USE_ENVVAR:
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2148 proxy_connect_http(connect_data, addr, addrlen);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2149 break;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2150
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2151 default:
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2152 break;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2153 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2154
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2155 g_free(addr);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2156 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2157
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2158 static void
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2159 connection_host_resolved(GSList *hosts, gpointer data,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2160 const char *error_message)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2161 {
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
2162 PurpleProxyConnectData *connect_data;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2163
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2164 connect_data = data;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2165 connect_data->query_data = NULL;
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 if (error_message != NULL)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2168 {
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
2169 purple_proxy_connect_data_disconnect(connect_data, error_message);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2170 return;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2171 }
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 if (hosts == NULL)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2174 {
27463
f541583e31bd More uniformity among disconnect error messages
Mark Doliner <mark@kingant.net>
parents: 27457
diff changeset
2175 purple_proxy_connect_data_disconnect(connect_data, _("Unable to resolve hostname"));
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2176 return;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2177 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2178
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2179 connect_data->hosts = hosts;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2180
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2181 try_connect(connect_data);
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
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
2184 PurpleProxyInfo *
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
2185 purple_proxy_get_setup(PurpleAccount *account)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2186 {
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
2187 PurpleProxyInfo *gpi = NULL;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2188 const gchar *tmp;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2189
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2190 /* This is used as a fallback so we don't overwrite the selected proxy type */
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
2191 static PurpleProxyInfo *tmp_none_proxy_info = NULL;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2192 if (!tmp_none_proxy_info) {
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
2193 tmp_none_proxy_info = purple_proxy_info_new();
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
2194 purple_proxy_info_set_type(tmp_none_proxy_info, PURPLE_PROXY_NONE);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2195 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2196
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
2197 if (account && purple_account_get_proxy_info(account) != NULL) {
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
2198 gpi = purple_account_get_proxy_info(account);
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
2199 if (purple_proxy_info_get_type(gpi) == PURPLE_PROXY_USE_GLOBAL)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2200 gpi = NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2201 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2202 if (gpi == NULL) {
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
2203 if (purple_running_gnome())
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
2204 gpi = purple_gnome_proxy_get_info();
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2205 else
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
2206 gpi = purple_global_proxy_get_info();
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2207 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2208
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
2209 if (purple_proxy_info_get_type(gpi) == PURPLE_PROXY_USE_ENVVAR) {
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2210 if ((tmp = g_getenv("HTTP_PROXY")) != NULL ||
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2211 (tmp = g_getenv("http_proxy")) != NULL ||
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2212 (tmp = g_getenv("HTTPPROXY")) != NULL) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2213 char *proxyhost, *proxyuser, *proxypasswd;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2214 int proxyport;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2215
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2216 /* http_proxy-format:
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2217 * 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
2218 */
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
2219 if(purple_url_parse(tmp, &proxyhost, &proxyport, NULL, &proxyuser, &proxypasswd)) {
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
2220 purple_proxy_info_set_host(gpi, proxyhost);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2221 g_free(proxyhost);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2222
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
2223 purple_proxy_info_set_username(gpi, proxyuser);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2224 g_free(proxyuser);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2225
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
2226 purple_proxy_info_set_password(gpi, proxypasswd);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2227 g_free(proxypasswd);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2228
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2229 /* only for backward compatibility */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2230 if (proxyport == 80 &&
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2231 ((tmp = g_getenv("HTTP_PROXY_PORT")) != NULL ||
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2232 (tmp = g_getenv("http_proxy_port")) != NULL ||
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2233 (tmp = g_getenv("HTTPPROXYPORT")) != NULL))
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2234 proxyport = atoi(tmp);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2235
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
2236 purple_proxy_info_set_port(gpi, proxyport);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2237
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2238 /* 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
2239 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
2240 (tmp = g_getenv("http_proxy_user")) != NULL ||
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2241 (tmp = g_getenv("HTTPPROXYUSER")) != NULL)
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
2242 purple_proxy_info_set_username(gpi, tmp);
15374
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 ((tmp = g_getenv("HTTP_PROXY_PASS")) != NULL ||
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2245 (tmp = g_getenv("http_proxy_pass")) != NULL ||
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2246 (tmp = g_getenv("HTTPPROXYPASS")) != NULL)
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
2247 purple_proxy_info_set_password(gpi, tmp);
15374
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 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2250 } else {
23900
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23890
diff changeset
2251 #ifdef _WIN32
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23890
diff changeset
2252 PurpleProxyInfo *wgpi;
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23890
diff changeset
2253 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: 23890
diff changeset
2254 return wgpi;
54eb782d4721 Add support for reading SOCKS proxy information from the Windows proxy settings.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23890
diff changeset
2255 #endif
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2256 /* no proxy environment variable found, don't use a proxy */
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
2257 purple_debug_info("proxy", "No environment settings found, not using a proxy\n");
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2258 gpi = tmp_none_proxy_info;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2259 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2260
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2261 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2262
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2263 return gpi;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2264 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2265
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
2266 PurpleProxyConnectData *
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
2267 purple_proxy_connect(void *handle, PurpleAccount *account,
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2268 const char *host, int port,
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
2269 PurpleProxyConnectFunction connect_cb, gpointer data)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2270 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2271 const char *connecthost = host;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2272 int connectport = port;
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
2273 PurpleProxyConnectData *connect_data;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2274
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2275 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
2276 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
2277 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
2278
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
2279 connect_data = g_new0(PurpleProxyConnectData, 1);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2280 connect_data->fd = -1;
27114
4c3b1bb3ba91 Add purple_proxy_connect_udp. Closes #6589.
Hu Yong <ccpaging@gmail.com>
parents: 25438
diff changeset
2281 connect_data->socket_type = SOCK_STREAM;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2282 connect_data->handle = handle;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2283 connect_data->connect_cb = connect_cb;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2284 connect_data->data = data;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2285 connect_data->host = g_strdup(host);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2286 connect_data->port = port;
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
2287 connect_data->gpi = purple_proxy_get_setup(account);
31930
0eceb1304f53 Add new DNS-related API to perform lookups in the context of an account.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31929
diff changeset
2288 connect_data->account = account;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2289
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
2290 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: 15682
diff changeset
2291 (purple_proxy_info_get_host(connect_data->gpi) == NULL ||
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
2292 purple_proxy_info_get_port(connect_data->gpi) <= 0)) {
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2293
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
2294 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: 15682
diff changeset
2295 purple_proxy_connect_data_destroy(connect_data);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2296 return NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2297 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2298
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
2299 switch (purple_proxy_info_get_type(connect_data->gpi))
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2300 {
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
2301 case PURPLE_PROXY_NONE:
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2302 break;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2303
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
2304 case PURPLE_PROXY_HTTP:
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
2305 case PURPLE_PROXY_SOCKS4:
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
2306 case PURPLE_PROXY_SOCKS5:
31929
9a7c5d242521 Add a new proxy type of "Tor". This is really just a SOCKS5 proxy, but can be
Daniel Atallah <daniel.atallah@gmail.com>
parents: 30846
diff changeset
2307 case PURPLE_PROXY_TOR:
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
2308 case PURPLE_PROXY_USE_ENVVAR:
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
2309 connecthost = purple_proxy_info_get_host(connect_data->gpi);
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
2310 connectport = purple_proxy_info_get_port(connect_data->gpi);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2311 break;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2312
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2313 default:
24215
1263f302d05e Add debug output when proxy configuration issues are seen. This will help to
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24050
diff changeset
2314 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: 24050
diff changeset
2315 purple_proxy_info_get_type(connect_data->gpi));
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
2316 purple_proxy_connect_data_destroy(connect_data);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2317 return NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2318 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2319
31930
0eceb1304f53 Add new DNS-related API to perform lookups in the context of an account.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31929
diff changeset
2320 connect_data->query_data = purple_dnsquery_a_account(account, connecthost,
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2321 connectport, connection_host_resolved, connect_data);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2322 if (connect_data->query_data == NULL)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2323 {
24215
1263f302d05e Add debug output when proxy configuration issues are seen. This will help to
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24050
diff changeset
2324 purple_debug_error("proxy", "dns query failed unexpectedly.\n");
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
2325 purple_proxy_connect_data_destroy(connect_data);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2326 return NULL;
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
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2329 handles = g_slist_prepend(handles, connect_data);
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 return connect_data;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2332 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2333
27114
4c3b1bb3ba91 Add purple_proxy_connect_udp. Closes #6589.
Hu Yong <ccpaging@gmail.com>
parents: 25438
diff changeset
2334 PurpleProxyConnectData *
4c3b1bb3ba91 Add purple_proxy_connect_udp. Closes #6589.
Hu Yong <ccpaging@gmail.com>
parents: 25438
diff changeset
2335 purple_proxy_connect_udp(void *handle, PurpleAccount *account,
4c3b1bb3ba91 Add purple_proxy_connect_udp. Closes #6589.
Hu Yong <ccpaging@gmail.com>
parents: 25438
diff changeset
2336 const char *host, int port,
4c3b1bb3ba91 Add purple_proxy_connect_udp. Closes #6589.
Hu Yong <ccpaging@gmail.com>
parents: 25438
diff changeset
2337 PurpleProxyConnectFunction connect_cb, gpointer data)
4c3b1bb3ba91 Add purple_proxy_connect_udp. Closes #6589.
Hu Yong <ccpaging@gmail.com>
parents: 25438
diff changeset
2338 {
4c3b1bb3ba91 Add purple_proxy_connect_udp. Closes #6589.
Hu Yong <ccpaging@gmail.com>
parents: 25438
diff changeset
2339 const char *connecthost = host;
4c3b1bb3ba91 Add purple_proxy_connect_udp. Closes #6589.
Hu Yong <ccpaging@gmail.com>
parents: 25438
diff changeset
2340 int connectport = port;
4c3b1bb3ba91 Add purple_proxy_connect_udp. Closes #6589.
Hu Yong <ccpaging@gmail.com>
parents: 25438
diff changeset
2341 PurpleProxyConnectData *connect_data;
4c3b1bb3ba91 Add purple_proxy_connect_udp. Closes #6589.
Hu Yong <ccpaging@gmail.com>
parents: 25438
diff changeset
2342
4c3b1bb3ba91 Add purple_proxy_connect_udp. Closes #6589.
Hu Yong <ccpaging@gmail.com>
parents: 25438
diff changeset
2343 g_return_val_if_fail(host != NULL, NULL);
4c3b1bb3ba91 Add purple_proxy_connect_udp. Closes #6589.
Hu Yong <ccpaging@gmail.com>
parents: 25438
diff changeset
2344 g_return_val_if_fail(port > 0, NULL);
4c3b1bb3ba91 Add purple_proxy_connect_udp. Closes #6589.
Hu Yong <ccpaging@gmail.com>
parents: 25438
diff changeset
2345 g_return_val_if_fail(connect_cb != NULL, NULL);
4c3b1bb3ba91 Add purple_proxy_connect_udp. Closes #6589.
Hu Yong <ccpaging@gmail.com>
parents: 25438
diff changeset
2346
4c3b1bb3ba91 Add purple_proxy_connect_udp. Closes #6589.
Hu Yong <ccpaging@gmail.com>
parents: 25438
diff changeset
2347 connect_data = g_new0(PurpleProxyConnectData, 1);
4c3b1bb3ba91 Add purple_proxy_connect_udp. Closes #6589.
Hu Yong <ccpaging@gmail.com>
parents: 25438
diff changeset
2348 connect_data->fd = -1;
4c3b1bb3ba91 Add purple_proxy_connect_udp. Closes #6589.
Hu Yong <ccpaging@gmail.com>
parents: 25438
diff changeset
2349 connect_data->socket_type = SOCK_DGRAM;
4c3b1bb3ba91 Add purple_proxy_connect_udp. Closes #6589.
Hu Yong <ccpaging@gmail.com>
parents: 25438
diff changeset
2350 connect_data->handle = handle;
4c3b1bb3ba91 Add purple_proxy_connect_udp. Closes #6589.
Hu Yong <ccpaging@gmail.com>
parents: 25438
diff changeset
2351 connect_data->connect_cb = connect_cb;
4c3b1bb3ba91 Add purple_proxy_connect_udp. Closes #6589.
Hu Yong <ccpaging@gmail.com>
parents: 25438
diff changeset
2352 connect_data->data = data;
4c3b1bb3ba91 Add purple_proxy_connect_udp. Closes #6589.
Hu Yong <ccpaging@gmail.com>
parents: 25438
diff changeset
2353 connect_data->host = g_strdup(host);
4c3b1bb3ba91 Add purple_proxy_connect_udp. Closes #6589.
Hu Yong <ccpaging@gmail.com>
parents: 25438
diff changeset
2354 connect_data->port = port;
4c3b1bb3ba91 Add purple_proxy_connect_udp. Closes #6589.
Hu Yong <ccpaging@gmail.com>
parents: 25438
diff changeset
2355 connect_data->gpi = purple_proxy_get_setup(account);
31930
0eceb1304f53 Add new DNS-related API to perform lookups in the context of an account.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31929
diff changeset
2356 connect_data->account = account;
27114
4c3b1bb3ba91 Add purple_proxy_connect_udp. Closes #6589.
Hu Yong <ccpaging@gmail.com>
parents: 25438
diff changeset
2357
4c3b1bb3ba91 Add purple_proxy_connect_udp. Closes #6589.
Hu Yong <ccpaging@gmail.com>
parents: 25438
diff changeset
2358 if ((purple_proxy_info_get_type(connect_data->gpi) != PURPLE_PROXY_NONE) &&
4c3b1bb3ba91 Add purple_proxy_connect_udp. Closes #6589.
Hu Yong <ccpaging@gmail.com>
parents: 25438
diff changeset
2359 (purple_proxy_info_get_host(connect_data->gpi) == NULL ||
4c3b1bb3ba91 Add purple_proxy_connect_udp. Closes #6589.
Hu Yong <ccpaging@gmail.com>
parents: 25438
diff changeset
2360 purple_proxy_info_get_port(connect_data->gpi) <= 0)) {
4c3b1bb3ba91 Add purple_proxy_connect_udp. Closes #6589.
Hu Yong <ccpaging@gmail.com>
parents: 25438
diff changeset
2361
4c3b1bb3ba91 Add purple_proxy_connect_udp. Closes #6589.
Hu Yong <ccpaging@gmail.com>
parents: 25438
diff changeset
2362 purple_notify_error(NULL, NULL, _("Invalid proxy settings"), _("Either the host name or port number specified for your given proxy type is invalid."));
4c3b1bb3ba91 Add purple_proxy_connect_udp. Closes #6589.
Hu Yong <ccpaging@gmail.com>
parents: 25438
diff changeset
2363 purple_proxy_connect_data_destroy(connect_data);
4c3b1bb3ba91 Add purple_proxy_connect_udp. Closes #6589.
Hu Yong <ccpaging@gmail.com>
parents: 25438
diff changeset
2364 return NULL;
4c3b1bb3ba91 Add purple_proxy_connect_udp. Closes #6589.
Hu Yong <ccpaging@gmail.com>
parents: 25438
diff changeset
2365 }
4c3b1bb3ba91 Add purple_proxy_connect_udp. Closes #6589.
Hu Yong <ccpaging@gmail.com>
parents: 25438
diff changeset
2366
4c3b1bb3ba91 Add purple_proxy_connect_udp. Closes #6589.
Hu Yong <ccpaging@gmail.com>
parents: 25438
diff changeset
2367 switch (purple_proxy_info_get_type(connect_data->gpi))
4c3b1bb3ba91 Add purple_proxy_connect_udp. Closes #6589.
Hu Yong <ccpaging@gmail.com>
parents: 25438
diff changeset
2368 {
4c3b1bb3ba91 Add purple_proxy_connect_udp. Closes #6589.
Hu Yong <ccpaging@gmail.com>
parents: 25438
diff changeset
2369 case PURPLE_PROXY_NONE:
4c3b1bb3ba91 Add purple_proxy_connect_udp. Closes #6589.
Hu Yong <ccpaging@gmail.com>
parents: 25438
diff changeset
2370 break;
4c3b1bb3ba91 Add purple_proxy_connect_udp. Closes #6589.
Hu Yong <ccpaging@gmail.com>
parents: 25438
diff changeset
2371
4c3b1bb3ba91 Add purple_proxy_connect_udp. Closes #6589.
Hu Yong <ccpaging@gmail.com>
parents: 25438
diff changeset
2372 case PURPLE_PROXY_HTTP:
4c3b1bb3ba91 Add purple_proxy_connect_udp. Closes #6589.
Hu Yong <ccpaging@gmail.com>
parents: 25438
diff changeset
2373 case PURPLE_PROXY_SOCKS4:
4c3b1bb3ba91 Add purple_proxy_connect_udp. Closes #6589.
Hu Yong <ccpaging@gmail.com>
parents: 25438
diff changeset
2374 case PURPLE_PROXY_SOCKS5:
31929
9a7c5d242521 Add a new proxy type of "Tor". This is really just a SOCKS5 proxy, but can be
Daniel Atallah <daniel.atallah@gmail.com>
parents: 30846
diff changeset
2375 case PURPLE_PROXY_TOR:
27114
4c3b1bb3ba91 Add purple_proxy_connect_udp. Closes #6589.
Hu Yong <ccpaging@gmail.com>
parents: 25438
diff changeset
2376 case PURPLE_PROXY_USE_ENVVAR:
4c3b1bb3ba91 Add purple_proxy_connect_udp. Closes #6589.
Hu Yong <ccpaging@gmail.com>
parents: 25438
diff changeset
2377 purple_debug_info("proxy", "Ignoring Proxy type (%d) for UDP.\n",
4c3b1bb3ba91 Add purple_proxy_connect_udp. Closes #6589.
Hu Yong <ccpaging@gmail.com>
parents: 25438
diff changeset
2378 purple_proxy_info_get_type(connect_data->gpi));
4c3b1bb3ba91 Add purple_proxy_connect_udp. Closes #6589.
Hu Yong <ccpaging@gmail.com>
parents: 25438
diff changeset
2379 break;
4c3b1bb3ba91 Add purple_proxy_connect_udp. Closes #6589.
Hu Yong <ccpaging@gmail.com>
parents: 25438
diff changeset
2380
4c3b1bb3ba91 Add purple_proxy_connect_udp. Closes #6589.
Hu Yong <ccpaging@gmail.com>
parents: 25438
diff changeset
2381 default:
4c3b1bb3ba91 Add purple_proxy_connect_udp. Closes #6589.
Hu Yong <ccpaging@gmail.com>
parents: 25438
diff changeset
2382 purple_debug_error("proxy", "Invalid Proxy type (%d) specified.\n",
4c3b1bb3ba91 Add purple_proxy_connect_udp. Closes #6589.
Hu Yong <ccpaging@gmail.com>
parents: 25438
diff changeset
2383 purple_proxy_info_get_type(connect_data->gpi));
4c3b1bb3ba91 Add purple_proxy_connect_udp. Closes #6589.
Hu Yong <ccpaging@gmail.com>
parents: 25438
diff changeset
2384 purple_proxy_connect_data_destroy(connect_data);
4c3b1bb3ba91 Add purple_proxy_connect_udp. Closes #6589.
Hu Yong <ccpaging@gmail.com>
parents: 25438
diff changeset
2385 return NULL;
4c3b1bb3ba91 Add purple_proxy_connect_udp. Closes #6589.
Hu Yong <ccpaging@gmail.com>
parents: 25438
diff changeset
2386 }
4c3b1bb3ba91 Add purple_proxy_connect_udp. Closes #6589.
Hu Yong <ccpaging@gmail.com>
parents: 25438
diff changeset
2387
31930
0eceb1304f53 Add new DNS-related API to perform lookups in the context of an account.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31929
diff changeset
2388 connect_data->query_data = purple_dnsquery_a_account(account, connecthost,
27114
4c3b1bb3ba91 Add purple_proxy_connect_udp. Closes #6589.
Hu Yong <ccpaging@gmail.com>
parents: 25438
diff changeset
2389 connectport, connection_host_resolved, connect_data);
4c3b1bb3ba91 Add purple_proxy_connect_udp. Closes #6589.
Hu Yong <ccpaging@gmail.com>
parents: 25438
diff changeset
2390 if (connect_data->query_data == NULL)
4c3b1bb3ba91 Add purple_proxy_connect_udp. Closes #6589.
Hu Yong <ccpaging@gmail.com>
parents: 25438
diff changeset
2391 {
4c3b1bb3ba91 Add purple_proxy_connect_udp. Closes #6589.
Hu Yong <ccpaging@gmail.com>
parents: 25438
diff changeset
2392 purple_proxy_connect_data_destroy(connect_data);
4c3b1bb3ba91 Add purple_proxy_connect_udp. Closes #6589.
Hu Yong <ccpaging@gmail.com>
parents: 25438
diff changeset
2393 return NULL;
4c3b1bb3ba91 Add purple_proxy_connect_udp. Closes #6589.
Hu Yong <ccpaging@gmail.com>
parents: 25438
diff changeset
2394 }
4c3b1bb3ba91 Add purple_proxy_connect_udp. Closes #6589.
Hu Yong <ccpaging@gmail.com>
parents: 25438
diff changeset
2395
4c3b1bb3ba91 Add purple_proxy_connect_udp. Closes #6589.
Hu Yong <ccpaging@gmail.com>
parents: 25438
diff changeset
2396 handles = g_slist_prepend(handles, connect_data);
4c3b1bb3ba91 Add purple_proxy_connect_udp. Closes #6589.
Hu Yong <ccpaging@gmail.com>
parents: 25438
diff changeset
2397
4c3b1bb3ba91 Add purple_proxy_connect_udp. Closes #6589.
Hu Yong <ccpaging@gmail.com>
parents: 25438
diff changeset
2398 return connect_data;
4c3b1bb3ba91 Add purple_proxy_connect_udp. Closes #6589.
Hu Yong <ccpaging@gmail.com>
parents: 25438
diff changeset
2399 }
4c3b1bb3ba91 Add purple_proxy_connect_udp. Closes #6589.
Hu Yong <ccpaging@gmail.com>
parents: 25438
diff changeset
2400
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
2401 PurpleProxyConnectData *
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
2402 purple_proxy_connect_socks5(void *handle, PurpleProxyInfo *gpi,
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2403 const char *host, int port,
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
2404 PurpleProxyConnectFunction connect_cb,
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2405 gpointer data)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2406 {
31930
0eceb1304f53 Add new DNS-related API to perform lookups in the context of an account.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31929
diff changeset
2407 return purple_proxy_connect_socks5_account(NULL, handle, gpi,
0eceb1304f53 Add new DNS-related API to perform lookups in the context of an account.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31929
diff changeset
2408 host, port, connect_cb, data);
0eceb1304f53 Add new DNS-related API to perform lookups in the context of an account.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31929
diff changeset
2409 }
31984
b9f58c31afc7 proxy: Use account proxy when making standalone SOCKS5 connections.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31930
diff changeset
2410
b9f58c31afc7 proxy: Use account proxy when making standalone SOCKS5 connections.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31930
diff changeset
2411
b9f58c31afc7 proxy: Use account proxy when making standalone SOCKS5 connections.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31930
diff changeset
2412 /* This is called when we connect to the SOCKS5 proxy server (through any
b9f58c31afc7 proxy: Use account proxy when making standalone SOCKS5 connections.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31930
diff changeset
2413 * relevant account proxy)
b9f58c31afc7 proxy: Use account proxy when making standalone SOCKS5 connections.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31930
diff changeset
2414 */
b9f58c31afc7 proxy: Use account proxy when making standalone SOCKS5 connections.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31930
diff changeset
2415 static void socks5_connected_to_proxy(gpointer data, gint source,
b9f58c31afc7 proxy: Use account proxy when making standalone SOCKS5 connections.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31930
diff changeset
2416 const gchar *error_message) {
b9f58c31afc7 proxy: Use account proxy when making standalone SOCKS5 connections.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31930
diff changeset
2417 /* This is the PurpleProxyConnectData for the overall SOCKS5 connection */
b9f58c31afc7 proxy: Use account proxy when making standalone SOCKS5 connections.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31930
diff changeset
2418 PurpleProxyConnectData *connect_data = data;
b9f58c31afc7 proxy: Use account proxy when making standalone SOCKS5 connections.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31930
diff changeset
2419
b9f58c31afc7 proxy: Use account proxy when making standalone SOCKS5 connections.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31930
diff changeset
2420 /* Check that the overall SOCKS5 connection wasn't cancelled while we were
b9f58c31afc7 proxy: Use account proxy when making standalone SOCKS5 connections.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31930
diff changeset
2421 * connecting to it (we don't have a way of associating the process of
b9f58c31afc7 proxy: Use account proxy when making standalone SOCKS5 connections.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31930
diff changeset
2422 * connecting to the SOCKS5 server to the overall PurpleProxyConnectData)
b9f58c31afc7 proxy: Use account proxy when making standalone SOCKS5 connections.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31930
diff changeset
2423 */
b9f58c31afc7 proxy: Use account proxy when making standalone SOCKS5 connections.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31930
diff changeset
2424 if (!PURPLE_PROXY_CONNECT_DATA_IS_VALID(connect_data))
b9f58c31afc7 proxy: Use account proxy when making standalone SOCKS5 connections.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31930
diff changeset
2425 return;
b9f58c31afc7 proxy: Use account proxy when making standalone SOCKS5 connections.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31930
diff changeset
2426
b9f58c31afc7 proxy: Use account proxy when making standalone SOCKS5 connections.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31930
diff changeset
2427 if (error_message != NULL) {
b9f58c31afc7 proxy: Use account proxy when making standalone SOCKS5 connections.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31930
diff changeset
2428 purple_debug_error("proxy", "Unable to connect to SOCKS5 host.\n");
b9f58c31afc7 proxy: Use account proxy when making standalone SOCKS5 connections.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31930
diff changeset
2429 connect_data->connect_cb(connect_data->data, source, error_message);
b9f58c31afc7 proxy: Use account proxy when making standalone SOCKS5 connections.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31930
diff changeset
2430 return;
b9f58c31afc7 proxy: Use account proxy when making standalone SOCKS5 connections.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31930
diff changeset
2431 }
b9f58c31afc7 proxy: Use account proxy when making standalone SOCKS5 connections.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31930
diff changeset
2432
b9f58c31afc7 proxy: Use account proxy when making standalone SOCKS5 connections.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31930
diff changeset
2433 purple_debug_info("proxy", "Initiating SOCKS5 negotiation.\n");
b9f58c31afc7 proxy: Use account proxy when making standalone SOCKS5 connections.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31930
diff changeset
2434
b9f58c31afc7 proxy: Use account proxy when making standalone SOCKS5 connections.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31930
diff changeset
2435 purple_debug_info("proxy",
b9f58c31afc7 proxy: Use account proxy when making standalone SOCKS5 connections.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31930
diff changeset
2436 "Connecting to %s:%d via %s:%d using SOCKS5\n",
b9f58c31afc7 proxy: Use account proxy when making standalone SOCKS5 connections.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31930
diff changeset
2437 connect_data->host, connect_data->port,
b9f58c31afc7 proxy: Use account proxy when making standalone SOCKS5 connections.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31930
diff changeset
2438 purple_proxy_info_get_host(connect_data->gpi),
b9f58c31afc7 proxy: Use account proxy when making standalone SOCKS5 connections.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31930
diff changeset
2439 purple_proxy_info_get_port(connect_data->gpi));
b9f58c31afc7 proxy: Use account proxy when making standalone SOCKS5 connections.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31930
diff changeset
2440
b9f58c31afc7 proxy: Use account proxy when making standalone SOCKS5 connections.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31930
diff changeset
2441 connect_data->fd = source;
b9f58c31afc7 proxy: Use account proxy when making standalone SOCKS5 connections.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31930
diff changeset
2442
b9f58c31afc7 proxy: Use account proxy when making standalone SOCKS5 connections.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31930
diff changeset
2443 s5_canwrite(connect_data, connect_data->fd, PURPLE_INPUT_WRITE);
b9f58c31afc7 proxy: Use account proxy when making standalone SOCKS5 connections.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31930
diff changeset
2444 }
b9f58c31afc7 proxy: Use account proxy when making standalone SOCKS5 connections.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31930
diff changeset
2445
31930
0eceb1304f53 Add new DNS-related API to perform lookups in the context of an account.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31929
diff changeset
2446 /*
0eceb1304f53 Add new DNS-related API to perform lookups in the context of an account.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31929
diff changeset
2447 * Combine some of this code with purple_proxy_connect()
0eceb1304f53 Add new DNS-related API to perform lookups in the context of an account.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31929
diff changeset
2448 */
0eceb1304f53 Add new DNS-related API to perform lookups in the context of an account.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31929
diff changeset
2449 PurpleProxyConnectData *
0eceb1304f53 Add new DNS-related API to perform lookups in the context of an account.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31929
diff changeset
2450 purple_proxy_connect_socks5_account(void *handle, PurpleAccount *account,
0eceb1304f53 Add new DNS-related API to perform lookups in the context of an account.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31929
diff changeset
2451 PurpleProxyInfo *gpi,
0eceb1304f53 Add new DNS-related API to perform lookups in the context of an account.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31929
diff changeset
2452 const char *host, int port,
0eceb1304f53 Add new DNS-related API to perform lookups in the context of an account.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31929
diff changeset
2453 PurpleProxyConnectFunction connect_cb,
0eceb1304f53 Add new DNS-related API to perform lookups in the context of an account.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31929
diff changeset
2454 gpointer data)
0eceb1304f53 Add new DNS-related API to perform lookups in the context of an account.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31929
diff changeset
2455 {
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
2456 PurpleProxyConnectData *connect_data;
31984
b9f58c31afc7 proxy: Use account proxy when making standalone SOCKS5 connections.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31930
diff changeset
2457 PurpleProxyConnectData *account_proxy_conn_data;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2458
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2459 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
2460 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
2461 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
2462
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
2463 connect_data = g_new0(PurpleProxyConnectData, 1);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2464 connect_data->fd = -1;
27114
4c3b1bb3ba91 Add purple_proxy_connect_udp. Closes #6589.
Hu Yong <ccpaging@gmail.com>
parents: 25438
diff changeset
2465 connect_data->socket_type = SOCK_STREAM;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2466 connect_data->handle = handle;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2467 connect_data->connect_cb = connect_cb;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2468 connect_data->data = data;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2469 connect_data->host = g_strdup(host);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2470 connect_data->port = port;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2471 connect_data->gpi = gpi;
31930
0eceb1304f53 Add new DNS-related API to perform lookups in the context of an account.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31929
diff changeset
2472 connect_data->account = account;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2473
31984
b9f58c31afc7 proxy: Use account proxy when making standalone SOCKS5 connections.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31930
diff changeset
2474 /* If there is an account proxy, use it to connect to the desired SOCKS5
b9f58c31afc7 proxy: Use account proxy when making standalone SOCKS5 connections.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31930
diff changeset
2475 * proxy.
b9f58c31afc7 proxy: Use account proxy when making standalone SOCKS5 connections.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31930
diff changeset
2476 */
b9f58c31afc7 proxy: Use account proxy when making standalone SOCKS5 connections.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31930
diff changeset
2477 account_proxy_conn_data = purple_proxy_connect(connect_data->handle,
b9f58c31afc7 proxy: Use account proxy when making standalone SOCKS5 connections.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31930
diff changeset
2478 connect_data->account,
b9f58c31afc7 proxy: Use account proxy when making standalone SOCKS5 connections.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31930
diff changeset
2479 purple_proxy_info_get_host(connect_data->gpi),
b9f58c31afc7 proxy: Use account proxy when making standalone SOCKS5 connections.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31930
diff changeset
2480 purple_proxy_info_get_port(connect_data->gpi),
b9f58c31afc7 proxy: Use account proxy when making standalone SOCKS5 connections.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31930
diff changeset
2481 socks5_connected_to_proxy, connect_data);
b9f58c31afc7 proxy: Use account proxy when making standalone SOCKS5 connections.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31930
diff changeset
2482
b9f58c31afc7 proxy: Use account proxy when making standalone SOCKS5 connections.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31930
diff changeset
2483 if (account_proxy_conn_data == NULL) {
b9f58c31afc7 proxy: Use account proxy when making standalone SOCKS5 connections.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31930
diff changeset
2484 purple_debug_error("proxy", "Unable to initiate connection to account proxy.\n");
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
2485 purple_proxy_connect_data_destroy(connect_data);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2486 return NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2487 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2488
31984
b9f58c31afc7 proxy: Use account proxy when making standalone SOCKS5 connections.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31930
diff changeset
2489 /* The API doesn't really provide us with a way to cancel the specific
b9f58c31afc7 proxy: Use account proxy when making standalone SOCKS5 connections.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31930
diff changeset
2490 * proxy connection attempt (account_proxy_conn_data) when the overall
b9f58c31afc7 proxy: Use account proxy when making standalone SOCKS5 connections.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31930
diff changeset
2491 * SOCKS5 connection (connect_data) attempt is cancelled :(
b9f58c31afc7 proxy: Use account proxy when making standalone SOCKS5 connections.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31930
diff changeset
2492 */
b9f58c31afc7 proxy: Use account proxy when making standalone SOCKS5 connections.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 31930
diff changeset
2493
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2494 handles = g_slist_prepend(handles, connect_data);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2495
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2496 return connect_data;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2497 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2498
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2499 void
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
2500 purple_proxy_connect_cancel(PurpleProxyConnectData *connect_data)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2501 {
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
2502 purple_proxy_connect_data_disconnect(connect_data, NULL);
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
2503 purple_proxy_connect_data_destroy(connect_data);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2504 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2505
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2506 void
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
2507 purple_proxy_connect_cancel_with_handle(void *handle)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2508 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2509 GSList *l, *l_next;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2510
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2511 for (l = handles; l != NULL; l = l_next) {
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
2512 PurpleProxyConnectData *connect_data = l->data;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2513
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2514 l_next = l->next;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2515
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2516 if (connect_data->handle == handle)
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
2517 purple_proxy_connect_cancel(connect_data);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2518 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2519 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2520
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2521 static void
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
2522 proxy_pref_cb(const char *name, PurplePrefType type,
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2523 gconstpointer value, gpointer data)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2524 {
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
2525 PurpleProxyInfo *info = purple_global_proxy_get_info();
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2526
25385
a6e3cb32cdd2 Patch from Paul Aurich to add purple_strequal to help readability and simplicity of code. Ie, don't need to negate the value of strcmp, since this does a strcmp and does the negation for us
Paul Aurich <paul@darkrain42.org>
parents: 24714
diff changeset
2527 if (purple_strequal(name, "/purple/proxy/type")) {
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2528 int proxytype;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2529 const char *type = value;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2530
25385
a6e3cb32cdd2 Patch from Paul Aurich to add purple_strequal to help readability and simplicity of code. Ie, don't need to negate the value of strcmp, since this does a strcmp and does the negation for us
Paul Aurich <paul@darkrain42.org>
parents: 24714
diff changeset
2531 if (purple_strequal(type, "none"))
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
2532 proxytype = PURPLE_PROXY_NONE;
25385
a6e3cb32cdd2 Patch from Paul Aurich to add purple_strequal to help readability and simplicity of code. Ie, don't need to negate the value of strcmp, since this does a strcmp and does the negation for us
Paul Aurich <paul@darkrain42.org>
parents: 24714
diff changeset
2533 else if (purple_strequal(type, "http"))
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
2534 proxytype = PURPLE_PROXY_HTTP;
25385
a6e3cb32cdd2 Patch from Paul Aurich to add purple_strequal to help readability and simplicity of code. Ie, don't need to negate the value of strcmp, since this does a strcmp and does the negation for us
Paul Aurich <paul@darkrain42.org>
parents: 24714
diff changeset
2535 else if (purple_strequal(type, "socks4"))
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
2536 proxytype = PURPLE_PROXY_SOCKS4;
25385
a6e3cb32cdd2 Patch from Paul Aurich to add purple_strequal to help readability and simplicity of code. Ie, don't need to negate the value of strcmp, since this does a strcmp and does the negation for us
Paul Aurich <paul@darkrain42.org>
parents: 24714
diff changeset
2537 else if (purple_strequal(type, "socks5"))
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
2538 proxytype = PURPLE_PROXY_SOCKS5;
31929
9a7c5d242521 Add a new proxy type of "Tor". This is really just a SOCKS5 proxy, but can be
Daniel Atallah <daniel.atallah@gmail.com>
parents: 30846
diff changeset
2539 else if (purple_strequal(type, "tor"))
9a7c5d242521 Add a new proxy type of "Tor". This is really just a SOCKS5 proxy, but can be
Daniel Atallah <daniel.atallah@gmail.com>
parents: 30846
diff changeset
2540 proxytype = PURPLE_PROXY_TOR;
25385
a6e3cb32cdd2 Patch from Paul Aurich to add purple_strequal to help readability and simplicity of code. Ie, don't need to negate the value of strcmp, since this does a strcmp and does the negation for us
Paul Aurich <paul@darkrain42.org>
parents: 24714
diff changeset
2541 else if (purple_strequal(type, "envvar"))
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
2542 proxytype = PURPLE_PROXY_USE_ENVVAR;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2543 else
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2544 proxytype = -1;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2545
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
2546 purple_proxy_info_set_type(info, proxytype);
25385
a6e3cb32cdd2 Patch from Paul Aurich to add purple_strequal to help readability and simplicity of code. Ie, don't need to negate the value of strcmp, since this does a strcmp and does the negation for us
Paul Aurich <paul@darkrain42.org>
parents: 24714
diff changeset
2547 } else if (purple_strequal(name, "/purple/proxy/host"))
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
2548 purple_proxy_info_set_host(info, value);
25385
a6e3cb32cdd2 Patch from Paul Aurich to add purple_strequal to help readability and simplicity of code. Ie, don't need to negate the value of strcmp, since this does a strcmp and does the negation for us
Paul Aurich <paul@darkrain42.org>
parents: 24714
diff changeset
2549 else if (purple_strequal(name, "/purple/proxy/port"))
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
2550 purple_proxy_info_set_port(info, GPOINTER_TO_INT(value));
25385
a6e3cb32cdd2 Patch from Paul Aurich to add purple_strequal to help readability and simplicity of code. Ie, don't need to negate the value of strcmp, since this does a strcmp and does the negation for us
Paul Aurich <paul@darkrain42.org>
parents: 24714
diff changeset
2551 else if (purple_strequal(name, "/purple/proxy/username"))
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
2552 purple_proxy_info_set_username(info, value);
25385
a6e3cb32cdd2 Patch from Paul Aurich to add purple_strequal to help readability and simplicity of code. Ie, don't need to negate the value of strcmp, since this does a strcmp and does the negation for us
Paul Aurich <paul@darkrain42.org>
parents: 24714
diff changeset
2553 else if (purple_strequal(name, "/purple/proxy/password"))
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
2554 purple_proxy_info_set_password(info, value);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2555 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2556
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2557 void *
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
2558 purple_proxy_get_handle()
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2559 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2560 static int handle;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2561
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2562 return &handle;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2563 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2564
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2565 void
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
2566 purple_proxy_init(void)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2567 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2568 void *handle;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2569
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2570 /* Initialize a default proxy info struct. */
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
2571 global_proxy_info = purple_proxy_info_new();
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2572
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2573 /* Proxy */
16427
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
2574 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
2575 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
2576 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
2577 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
2578 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
2579 purple_prefs_add_string("/purple/proxy/password", "");
25114
e859785b49d8 Implement support for resolving DNS via the SOCKS4 proxy in use.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 25113
diff changeset
2580 purple_prefs_add_bool("/purple/proxy/socks4_remotedns", FALSE);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2581
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2582 /* Setup callbacks for the preferences. */
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
2583 handle = purple_proxy_get_handle();
16427
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
2584 purple_prefs_connect_callback(handle, "/purple/proxy/type", proxy_pref_cb,
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2585 NULL);
16427
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
2586 purple_prefs_connect_callback(handle, "/purple/proxy/host", proxy_pref_cb,
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2587 NULL);
16427
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
2588 purple_prefs_connect_callback(handle, "/purple/proxy/port", proxy_pref_cb,
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2589 NULL);
16427
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
2590 purple_prefs_connect_callback(handle, "/purple/proxy/username",
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2591 proxy_pref_cb, NULL);
16427
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
2592 purple_prefs_connect_callback(handle, "/purple/proxy/password",
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2593 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: 19990
diff changeset
2594
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: 19990
diff changeset
2595 /* 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
2596 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
2597 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
2598 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
2599 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
2600 purple_prefs_trigger_callback("/purple/proxy/password");
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2601 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2602
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2603 void
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
2604 purple_proxy_uninit(void)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2605 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2606 while (handles != NULL)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2607 {
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
2608 purple_proxy_connect_data_disconnect(handles->data, NULL);
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15682
diff changeset
2609 purple_proxy_connect_data_destroy(handles->data);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2610 }
28245
32a707746454 Clean up various file-scoped globals at uninit.
Paul Aurich <paul@darkrain42.org>
parents: 28006
diff changeset
2611
32a707746454 Clean up various file-scoped globals at uninit.
Paul Aurich <paul@darkrain42.org>
parents: 28006
diff changeset
2612 purple_prefs_disconnect_by_handle(purple_proxy_get_handle());
32a707746454 Clean up various file-scoped globals at uninit.
Paul Aurich <paul@darkrain42.org>
parents: 28006
diff changeset
2613
32a707746454 Clean up various file-scoped globals at uninit.
Paul Aurich <paul@darkrain42.org>
parents: 28006
diff changeset
2614 purple_proxy_info_destroy(global_proxy_info);
32a707746454 Clean up various file-scoped globals at uninit.
Paul Aurich <paul@darkrain42.org>
parents: 28006
diff changeset
2615 global_proxy_info = NULL;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2616 }