annotate libgaim/protocols/qq/qq_proxy.c @ 14312:ef05f400817f

[gaim-migrate @ 17002] Fix the win32 method. I also changed the callback to be triggered asynchronously in the error case and had to add some supporting stuff. committer: Tailor Script <tailor@pidgin.im>
author Daniel Atallah <daniel.atallah@gmail.com>
date Wed, 23 Aug 2006 14:49:40 +0000
parents 902c3aa4950a
children 473b225e7352
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1 /**
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
2 * The QQ2003C protocol plugin
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
3 *
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
4 * for gaim
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
5 *
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
6 * Copyright (C) 2004 Puzzlebird
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
7 * Henry Ou <henry@linux.net>
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
8 *
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
9 * This program is free software; you can redistribute it and/or modify
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
10 * it under the terms of the GNU General Public License as published by
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
11 * the Free Software Foundation; either version 2 of the License, or
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
12 * (at your option) any later version.
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
13 *
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
14 * This program is distributed in the hope that it will be useful,
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
17 * GNU General Public License for more details.
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
18 *
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
19 * You should have received a copy of the GNU General Public License
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
20 * along with this program; if not, write to the Free Software
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
22 */
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
23
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
24 #include "cipher.h"
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
25 #include "debug.h"
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
26 #include "internal.h"
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
27
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
28 #ifdef _WIN32
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
29 #define random rand
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
30 #define srandom srand
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
31 #endif
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
32
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
33 #include "packet_parse.h"
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
34 #include "buddy_info.h"
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
35 #include "buddy_opt.h"
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
36 #include "char_conv.h"
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
37 #include "group_free.h"
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
38 #include "login_logout.h"
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
39 #include "qq_proxy.h"
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
40 #include "recv_core.h"
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
41 #include "send_core.h"
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
42 #include "sendqueue.h"
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
43 #include "udp_proxy_s5.h"
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
44 #include "utils.h"
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
45
14195
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
46 /* These functions are used only in development phase */
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
47 /*
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
48 static void _qq_show_socket(gchar *desc, gint fd) {
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
49 struct sockaddr_in sin;
14195
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
50 socklen_t len = sizeof(sin);
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
51 getsockname(fd, (struct sockaddr *)&sin, &len);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
52 gaim_debug(GAIM_DEBUG_INFO, desc, "%s:%d\n",
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
53 inet_ntoa(sin.sin_addr), ntohs(sin.sin_port));
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
54 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
55 */
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
56
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
57 void _qq_show_packet(const gchar *desc, const guint8 *buf, gint len)
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
58 {
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
59 char buf1[8*len+2], buf2[10];
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
60 int i;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
61 buf1[0] = 0;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
62 for (i = 0; i < len; i++) {
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
63 sprintf(buf2, " %02x(%d)", buf[i] & 0xff, buf[i] & 0xff);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
64 strcat(buf1, buf2);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
65 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
66 strcat(buf1, "\n");
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
67 gaim_debug(GAIM_DEBUG_INFO, desc, buf1);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
68 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
69
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
70 /* QQ 2003iii uses double MD5 for the pwkey to get the session key */
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
71 static guint8 *_gen_pwkey(const gchar *pwd)
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
72 {
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
73 GaimCipher *cipher;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
74 GaimCipherContext *context;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
75
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
76 guchar pwkey_tmp[QQ_KEY_LENGTH];
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
77
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
78 cipher = gaim_ciphers_find_cipher("md5");
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
79 context = gaim_cipher_context_new(cipher, NULL);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
80 gaim_cipher_context_append(context, (guchar *) pwd, strlen(pwd));
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
81 gaim_cipher_context_digest(context, sizeof(pwkey_tmp), pwkey_tmp, NULL);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
82 gaim_cipher_context_destroy(context);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
83 context = gaim_cipher_context_new(cipher, NULL);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
84 gaim_cipher_context_append(context, pwkey_tmp, QQ_KEY_LENGTH);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
85 gaim_cipher_context_digest(context, sizeof(pwkey_tmp), pwkey_tmp, NULL);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
86 gaim_cipher_context_destroy(context);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
87
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
88 return g_memdup(pwkey_tmp, QQ_KEY_LENGTH);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
89 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
90
14195
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
91 static gboolean _qq_fill_host(GSList *hosts, struct sockaddr_in *addr, gint *addr_size)
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
92 {
14195
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
93 if (!hosts || !hosts->data)
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
94 return FALSE;
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
95
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
96 *addr_size = GPOINTER_TO_INT(hosts->data);
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
97
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
98 hosts = g_slist_remove(hosts, hosts->data);
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
99 memcpy(addr, hosts->data, *addr_size);
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
100 g_free(hosts->data);
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
101 hosts = g_slist_remove(hosts, hosts->data);
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
102 while(hosts) {
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
103 hosts = g_slist_remove(hosts, hosts->data);
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
104 g_free(hosts->data);
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
105 hosts = g_slist_remove(hosts, hosts->data);
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
106 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
107
14195
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
108 return TRUE;
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
109 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
110
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
111 /* set up any finalizing start-up stuff */
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
112 static void _qq_start_services(GaimConnection *gc)
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
113 {
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
114 /* start watching for IMs about to be sent */
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
115 /*
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
116 gaim_signal_connect(gaim_conversations_get_handle(),
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
117 "sending-im-msg", gc,
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
118 GAIM_CALLBACK(qq_sending_im_msg_cb), NULL);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
119 */
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
120 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
121
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
122 /* the callback function after socket is built
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
123 * we setup the qq protocol related configuration here */
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
124 static void _qq_got_login(gpointer data, gint source, const gchar *error_message)
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
125 {
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
126 qq_data *qd;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
127 GaimConnection *gc;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
128 gchar *buf;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
129 const gchar *passwd;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
130
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
131 gc = (GaimConnection *) data;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
132
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
133 if (!GAIM_CONNECTION_IS_VALID(gc)) {
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
134 close(source);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
135 return;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
136 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
137
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
138 g_return_if_fail(gc != NULL && gc->proto_data != NULL);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
139
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
140 if (source < 0) { /* socket returns -1 */
14195
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
141 gaim_connection_error(gc, error_message);
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
142 return;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
143 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
144
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
145 qd = (qq_data *) gc->proto_data;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
146
14195
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
147 /*
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
148 _qq_show_socket("Got login socket", source);
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
149 */
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
150
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
151 /* QQ use random seq, to minimize duplicated packets */
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
152 srandom(time(NULL));
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
153 qd->send_seq = random() & 0x0000ffff;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
154 qd->fd = source;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
155 qd->logged_in = FALSE;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
156 qd->channel = 1;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
157 qd->uid = strtol(gaim_account_get_username(gaim_connection_get_account(gc)), NULL, 10);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
158 qd->before_login_packets = g_queue_new();
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
159
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
160 /* now generate md5 processed passwd */
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
161 passwd = gaim_account_get_password(gaim_connection_get_account(gc));
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
162 qd->pwkey = _gen_pwkey(passwd);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
163
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
164 qd->sendqueue_timeout = gaim_timeout_add(QQ_SENDQUEUE_TIMEOUT, qq_sendqueue_timeout_callback, gc);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
165 gc->inpa = gaim_input_add(qd->fd, GAIM_INPUT_READ, qq_input_pending, gc);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
166
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
167 /* Update the login progress status display */
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
168 buf = g_strdup_printf("Login as %d", qd->uid);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
169 gaim_connection_update_progress(gc, buf, 1, QQ_CONNECT_STEPS);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
170 g_free(buf);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
171
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
172 _qq_start_services(gc);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
173
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
174 qq_send_packet_request_login_token(gc);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
175 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
176
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
177 /* clean up qq_data structure and all its components
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
178 * always used before a redirectly connection */
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
179 static void _qq_common_clean(GaimConnection *gc)
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
180 {
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
181 qq_data *qd;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
182
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
183 g_return_if_fail(gc != NULL && gc->proto_data != NULL);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
184 qd = (qq_data *) gc->proto_data;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
185
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
186 /* finish all I/O */
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
187 if (qd->fd >= 0 && qd->logged_in)
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
188 qq_send_packet_logout(gc);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
189 close(qd->fd);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
190
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
191 if (qd->sendqueue_timeout > 0) {
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
192 gaim_timeout_remove(qd->sendqueue_timeout);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
193 qd->sendqueue_timeout = 0;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
194 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
195
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
196 if (gc->inpa > 0) {
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
197 gaim_input_remove(gc->inpa);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
198 gc->inpa = 0;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
199 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
200
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
201 qq_b4_packets_free(qd);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
202 qq_sendqueue_free(qd);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
203 qq_group_packets_free(qd);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
204 qq_group_free_all(qd);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
205 qq_add_buddy_request_free(qd);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
206 qq_info_query_free(qd);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
207 qq_buddies_list_free(gc->account, qd);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
208 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
209
14195
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
210 static void no_one_calls(gpointer data, gint source, GaimInputCondition cond)
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
211 {
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
212 struct PHB *phb = data;
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
213 socklen_t len;
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
214 int error=0, ret;
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
215
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
216 gaim_debug_info("proxy", "Connected.\n");
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
217
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
218 len = sizeof(error);
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
219
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
220 /*
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
221 * getsockopt after a non-blocking connect returns -1 if something is
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
222 * really messed up (bad descriptor, usually). Otherwise, it returns 0 and
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
223 * error holds what connect would have returned if it blocked until now.
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
224 * Thus, error == 0 is success, error == EINPROGRESS means "try again",
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
225 * and anything else is a real error.
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
226 *
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
227 * (error == EINPROGRESS can happen after a select because the kernel can
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
228 * be overly optimistic sometimes. select is just a hint that you might be
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
229 * able to do something.)
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
230 */
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
231 ret = getsockopt(source, SOL_SOCKET, SO_ERROR, &error, &len);
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
232 if (ret == 0 && error == EINPROGRESS)
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
233 return; /* we'll be called again later */
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
234 if (ret < 0 || error != 0) {
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
235 if(ret!=0)
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
236 error = errno;
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
237 close(source);
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
238 gaim_input_remove(phb->inpa);
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
239
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
240 gaim_debug_error("proxy", "getsockopt SO_ERROR check: %s\n", strerror(error));
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
241
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
242 phb->func(phb->data, -1, _("Unable to connect"));
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
243 return;
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
244 }
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
245
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
246 gaim_input_remove(phb->inpa);
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
247
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
248 if (phb->account == NULL || gaim_account_get_connection(phb->account) != NULL) {
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
249
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
250 phb->func(phb->data, source, NULL);
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
251 }
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
252
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
253 g_free(phb->host);
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
254 g_free(phb);
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
255 }
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
256
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
257 /* returns -1 if fails, otherwise returns the file handle */
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
258 static gint _qq_proxy_none(struct PHB *phb, struct sockaddr *addr, socklen_t addrlen)
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
259 {
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
260 gint fd = -1;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
261
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
262 gaim_debug(GAIM_DEBUG_INFO, "QQ", "Using UDP without proxy\n");
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
263 fd = socket(PF_INET, SOCK_DGRAM, 0);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
264
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
265 if (fd < 0) {
14195
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
266 gaim_debug(GAIM_DEBUG_ERROR, "QQ Redirect",
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
267 "Unable to create socket: %s\n", strerror(errno));
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
268 return -1;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
269 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
270
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
271 /* we use non-blocking mode to speed up connection */
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
272 fcntl(fd, F_SETFL, O_NONBLOCK);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
273
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
274 /* From Unix-socket-FAQ: http://www.faqs.org/faqs/unix-faq/socket/
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
275 *
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
276 * If a UDP socket is unconnected, which is the normal state after a
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
277 * bind() call, then send() or write() are not allowed, since no
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
278 * destination is available; only sendto() can be used to send data.
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
279 *
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
280 * Calling connect() on the socket simply records the specified address
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
281 * and port number as being the desired communications partner. That
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
282 * means that send() or write() are now allowed; they use the destination
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
283 * address and port given on the connect call as the destination of packets.
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
284 */
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
285 if (connect(fd, addr, addrlen) < 0) {
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
286 /* [EINPROGRESS]
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
287 * The socket is marked as non-blocking and the connection cannot be
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
288 * completed immediately. It is possible to select for completion by
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
289 * selecting the socket for writing.
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
290 * [EINTR]
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
291 * A signal interrupted the call.
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
292 * The connection is established asynchronously.
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
293 */
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
294 if ((errno == EINPROGRESS) || (errno == EINTR)) {
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
295 gaim_debug(GAIM_DEBUG_WARNING, "QQ", "Connect in asynchronous mode.\n");
14195
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
296 phb->inpa = gaim_input_add(fd, GAIM_INPUT_WRITE, no_one_calls, phb);
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
297 } else {
14195
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
298 gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Connection failed: %d\n", strerror(errno));
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
299 close(fd);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
300 return -1;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
301 } /* if errno */
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
302 } else { /* connect returns 0 */
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
303 gaim_debug(GAIM_DEBUG_INFO, "QQ", "Connected.\n");
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
304 fcntl(fd, F_SETFL, 0);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
305 phb->func(phb->data, fd, NULL);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
306 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
307
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
308 return fd;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
309 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
310
14195
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
311 static void _qq_proxy_resolved(GSList *hosts, gpointer data, const char *error_message)
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
312 {
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
313 struct PHB *phb = (struct PHB *) data;
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
314 struct sockaddr_in addr;
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
315 gint addr_size, ret = -1;
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
316
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
317 if(_qq_fill_host(hosts, &addr, &addr_size))
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
318 ret = qq_proxy_socks5(phb, (struct sockaddr *) &addr, addr_size);
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
319
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
320 if (ret < 0) {
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
321 phb->func(phb->data, -1, _("Unable to connect"));
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
322 g_free(phb->host);
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
323 g_free(phb);
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
324 }
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
325 }
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
326
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
327 static void _qq_server_resolved(GSList *hosts, gpointer data, const char *error_message)
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
328 {
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
329 struct PHB *phb = (struct PHB *) data;
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
330 GaimConnection *gc = (GaimConnection *) phb->data;
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
331 qq_data *qd = (qq_data *) gc->proto_data;
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
332 struct sockaddr_in addr;
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
333 gint addr_size, ret = -1;
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
334
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
335 if(_qq_fill_host(hosts, &addr, &addr_size)) {
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
336 switch (gaim_proxy_info_get_type(phb->gpi)) {
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
337 case GAIM_PROXY_NONE:
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
338 ret = _qq_proxy_none(phb, (struct sockaddr *) &addr, addr_size);
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
339 break;
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
340 case GAIM_PROXY_SOCKS5:
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
341 ret = 0;
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
342 if (gaim_proxy_info_get_host(phb->gpi) == NULL ||
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
343 gaim_proxy_info_get_port(phb->gpi) == 0) {
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
344 gaim_debug(GAIM_DEBUG_ERROR, "QQ",
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
345 "Use of socks5 proxy selected but host or port info doesn't exist.\n");
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
346 ret = -1;
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
347 } else {
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
348 /* as the destination is always QQ server during the session,
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
349 * we can set dest_sin here, instead of _qq_s5_canread_again */
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
350 memcpy(&qd->dest_sin, &addr, addr_size);
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
351 if (gaim_dnsquery_a(gaim_proxy_info_get_host(phb->gpi),
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
352 gaim_proxy_info_get_port(phb->gpi),
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
353 _qq_proxy_resolved, phb) == NULL)
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
354 ret = -1;
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
355 }
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
356 break;
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
357 default:
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
358 gaim_debug(GAIM_DEBUG_WARNING, "QQ",
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
359 "Proxy type %i is unsupported, not using a proxy.\n",
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
360 gaim_proxy_info_get_type(phb->gpi));
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
361 ret = _qq_proxy_none(phb, (struct sockaddr *) &addr, addr_size);
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
362 }
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
363 }
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
364
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
365 if (ret < 0) {
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
366 phb->func(gc, -1, _("Unable to connect"));
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
367 g_free(phb->host);
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
368 g_free(phb);
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
369 }
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
370 }
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
371
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
372 /* returns -1 if dns lookup fails, otherwise returns 0 */
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
373 static gint _qq_udp_proxy_connect(GaimAccount *account,
14195
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
374 const gchar *server, guint16 port,
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
375 void callback(gpointer, gint, const gchar *error_message),
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
376 GaimConnection *gc)
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
377 {
14195
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
378 GaimProxyInfo *info;
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
379 struct PHB *phb;
14195
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
380 qq_data *qd = (qq_data *) gc->proto_data;
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
381
14195
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
382 g_return_val_if_fail(gc != NULL && qd != NULL, -1);
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
383
14195
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
384 info = gaim_proxy_get_setup(account);
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
385
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
386 phb = g_new0(struct PHB, 1);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
387 phb->host = g_strdup(server);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
388 phb->port = port;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
389 phb->account = account;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
390 phb->gpi = info;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
391 phb->func = callback;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
392 phb->data = gc;
14195
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
393 qd->proxy_type = gaim_proxy_info_get_type(phb->gpi);
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
394
14195
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
395 gaim_debug(GAIM_DEBUG_INFO, "QQ", "Choosing proxy type %d\n",
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
396 gaim_proxy_info_get_type(phb->gpi));
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
397
14195
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
398 if (gaim_dnsquery_a(server, port, _qq_server_resolved, phb) == NULL) {
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
399 phb->func(gc, -1, _("Unable to connect"));
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
400 g_free(phb->host);
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
401 g_free(phb);
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
402 return -1;
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
403 } else {
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
404 return 0;
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
405 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
406 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
407
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
408 /* QQ connection via UDP/TCP.
14195
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
409 * I use Gaim proxy function to provide TCP proxy support,
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
410 * and qq_udp_proxy.c to add UDP proxy support (thanks henry) */
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
411 static gint _proxy_connect_full (GaimAccount *account, const gchar *host, guint16 port,
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
412 GaimProxyConnectFunction func, gpointer data, gboolean use_tcp)
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
413 {
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
414 GaimConnection *gc;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
415 qq_data *qd;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
416
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
417 gc = gaim_account_get_connection(account);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
418 qd = (qq_data *) gc->proto_data;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
419 qd->server_ip = g_strdup(host);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
420 qd->server_port = port;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
421
14195
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
422 if(use_tcp)
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
423 return (gaim_proxy_connect(account, host, port, func, data) == NULL);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
424 else
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
425 return _qq_udp_proxy_connect(account, host, port, func, data);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
426 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
427
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
428 /* establish a generic QQ connection
14195
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
429 * TCP/UDP, and direct/redirected */
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
430 gint qq_connect(GaimAccount *account, const gchar *host, guint16 port,
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
431 gboolean use_tcp, gboolean is_redirect)
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
432 {
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
433 GaimConnection *gc;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
434
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
435 g_return_val_if_fail(host != NULL, -1);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
436 g_return_val_if_fail(port > 0, -1);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
437
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
438 gc = gaim_account_get_connection(account);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
439 g_return_val_if_fail(gc != NULL && gc->proto_data != NULL, -1);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
440
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
441 if (is_redirect)
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
442 _qq_common_clean(gc);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
443
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
444 return _proxy_connect_full(account, host, port, _qq_got_login, gc, use_tcp);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
445 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
446
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
447 /* clean up the given QQ connection and free all resources */
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
448 void qq_disconnect(GaimConnection *gc)
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
449 {
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
450 qq_data *qd;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
451
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
452 g_return_if_fail(gc != NULL);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
453
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
454 _qq_common_clean(gc);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
455
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
456 qd = gc->proto_data;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
457 g_free(qd->inikey);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
458 g_free(qd->pwkey);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
459 g_free(qd->session_key);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
460 g_free(qd->my_ip);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
461 g_free(qd);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
462
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
463 gc->proto_data = NULL;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
464 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
465
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
466 /* send packet with proxy support */
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
467 gint qq_proxy_write(qq_data *qd, guint8 *data, gint len)
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
468 {
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
469 guint8 *buf;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
470 gint ret;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
471
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
472 g_return_val_if_fail(qd != NULL && qd->fd >= 0 && data != NULL && len > 0, -1);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
473
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
474 /* TCP sock5 may be processed twice
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
475 * so we need to check qd->use_tcp as well */
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
476 if ((!qd->use_tcp) && qd->proxy_type == GAIM_PROXY_SOCKS5) { /* UDP sock5 */
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
477 buf = g_newa(guint8, len + 10);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
478 buf[0] = 0x00;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
479 buf[1] = 0x00; /* reserved */
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
480 buf[2] = 0x00; /* frag */
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
481 buf[3] = 0x01; /* type */
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
482 g_memmove(buf + 4, &(qd->dest_sin.sin_addr.s_addr), 4);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
483 g_memmove(buf + 8, &(qd->dest_sin.sin_port), 2);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
484 g_memmove(buf + 10, data, len);
14195
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
485 errno = 0;
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
486 ret = send(qd->fd, buf, len + 10, 0);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
487 } else {
14195
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
488 errno = 0;
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
489 ret = send(qd->fd, data, len, 0);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
490 }
14195
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
491 if (ret == -1) {
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
492 gaim_connection_error(qd->gc, _("Socket send error"));
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
493 return ret;
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
494 } else if (errno == ECONNREFUSED) {
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
495 gaim_connection_error(qd->gc, _("Connection refused"));
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
496 return ret;
902c3aa4950a [gaim-migrate @ 16867]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
497 }
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
498
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
499 return ret;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
500 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
501
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
502 /* read packet input with proxy support */
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
503 gint qq_proxy_read(qq_data *qd, guint8 *data, gint len)
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
504 {
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
505 guint8 *buf;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
506 gint bytes;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
507 buf = g_newa(guint8, MAX_PACKET_SIZE + 10);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
508
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
509 g_return_val_if_fail(qd != NULL && data != NULL && len > 0, -1);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
510 g_return_val_if_fail(qd->fd > 0, -1);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
511
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
512 bytes = read(qd->fd, buf, len + 10);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
513 if (bytes < 0)
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
514 return -1;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
515
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
516 if ((!qd->use_tcp) && qd->proxy_type == GAIM_PROXY_SOCKS5) { /* UDP sock5 */
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
517 if (bytes < 10)
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
518 return -1;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
519 bytes -= 10;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
520 g_memmove(data, buf + 10, bytes); /* cut off the header */
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
521 } else {
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
522 g_memmove(data, buf, bytes);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
523 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
524
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
525 return bytes;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
526 }