comparison libpurple/protocols/qq/qq_proxy.c @ 15822:32c366eeeb99

sed -ie 's/gaim/purple/g'
author Sean Egan <seanegan@gmail.com>
date Mon, 19 Mar 2007 07:01:17 +0000
parents 5fe8042783c1
children b9a0b1bd321b
comparison
equal deleted inserted replaced
15821:84b0f9b23ede 15822:32c366eeeb99
1 /** 1 /**
2 * @file qq_proxy.c 2 * @file qq_proxy.c
3 * 3 *
4 * gaim 4 * purple
5 * 5 *
6 * Gaim is the legal property of its developers, whose names are too numerous 6 * Purple is the legal property of its developers, whose names are too numerous
7 * to list here. Please refer to the COPYRIGHT file distributed with this 7 * to list here. Please refer to the COPYRIGHT file distributed with this
8 * source distribution. 8 * source distribution.
9 * 9 *
10 * This program is free software; you can redistribute it and/or modify 10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by 11 * it under the terms of the GNU General Public License as published by
48 /* 48 /*
49 static void _qq_show_socket(gchar *desc, gint fd) { 49 static void _qq_show_socket(gchar *desc, gint fd) {
50 struct sockaddr_in sin; 50 struct sockaddr_in sin;
51 socklen_t len = sizeof(sin); 51 socklen_t len = sizeof(sin);
52 getsockname(fd, (struct sockaddr *)&sin, &len); 52 getsockname(fd, (struct sockaddr *)&sin, &len);
53 gaim_debug(GAIM_DEBUG_INFO, desc, "%s:%d\n", 53 purple_debug(PURPLE_DEBUG_INFO, desc, "%s:%d\n",
54 inet_ntoa(sin.sin_addr), g_ntohs(sin.sin_port)); 54 inet_ntoa(sin.sin_addr), g_ntohs(sin.sin_port));
55 } 55 }
56 */ 56 */
57 57
58 void _qq_show_packet(const gchar *desc, const guint8 *buf, gint len) 58 void _qq_show_packet(const gchar *desc, const guint8 *buf, gint len)
63 for (i = 0; i < len; i++) { 63 for (i = 0; i < len; i++) {
64 sprintf(buf2, " %02x(%d)", buf[i] & 0xff, buf[i] & 0xff); 64 sprintf(buf2, " %02x(%d)", buf[i] & 0xff, buf[i] & 0xff);
65 strcat(buf1, buf2); 65 strcat(buf1, buf2);
66 } 66 }
67 strcat(buf1, "\n"); 67 strcat(buf1, "\n");
68 gaim_debug(GAIM_DEBUG_INFO, desc, "%s", buf1); 68 purple_debug(PURPLE_DEBUG_INFO, desc, "%s", buf1);
69 } 69 }
70 70
71 /* QQ 2003iii uses double MD5 for the pwkey to get the session key */ 71 /* QQ 2003iii uses double MD5 for the pwkey to get the session key */
72 static guint8 *_gen_pwkey(const gchar *pwd) 72 static guint8 *_gen_pwkey(const gchar *pwd)
73 { 73 {
74 GaimCipher *cipher; 74 PurpleCipher *cipher;
75 GaimCipherContext *context; 75 PurpleCipherContext *context;
76 76
77 guchar pwkey_tmp[QQ_KEY_LENGTH]; 77 guchar pwkey_tmp[QQ_KEY_LENGTH];
78 78
79 cipher = gaim_ciphers_find_cipher("md5"); 79 cipher = purple_ciphers_find_cipher("md5");
80 context = gaim_cipher_context_new(cipher, NULL); 80 context = purple_cipher_context_new(cipher, NULL);
81 gaim_cipher_context_append(context, (guchar *) pwd, strlen(pwd)); 81 purple_cipher_context_append(context, (guchar *) pwd, strlen(pwd));
82 gaim_cipher_context_digest(context, sizeof(pwkey_tmp), pwkey_tmp, NULL); 82 purple_cipher_context_digest(context, sizeof(pwkey_tmp), pwkey_tmp, NULL);
83 gaim_cipher_context_destroy(context); 83 purple_cipher_context_destroy(context);
84 context = gaim_cipher_context_new(cipher, NULL); 84 context = purple_cipher_context_new(cipher, NULL);
85 gaim_cipher_context_append(context, pwkey_tmp, QQ_KEY_LENGTH); 85 purple_cipher_context_append(context, pwkey_tmp, QQ_KEY_LENGTH);
86 gaim_cipher_context_digest(context, sizeof(pwkey_tmp), pwkey_tmp, NULL); 86 purple_cipher_context_digest(context, sizeof(pwkey_tmp), pwkey_tmp, NULL);
87 gaim_cipher_context_destroy(context); 87 purple_cipher_context_destroy(context);
88 88
89 return g_memdup(pwkey_tmp, QQ_KEY_LENGTH); 89 return g_memdup(pwkey_tmp, QQ_KEY_LENGTH);
90 } 90 }
91 91
92 static gboolean _qq_fill_host(GSList *hosts, struct sockaddr_in *addr, gint *addr_size) 92 static gboolean _qq_fill_host(GSList *hosts, struct sockaddr_in *addr, gint *addr_size)
108 108
109 return TRUE; 109 return TRUE;
110 } 110 }
111 111
112 /* set up any finalizing start-up stuff */ 112 /* set up any finalizing start-up stuff */
113 static void _qq_start_services(GaimConnection *gc) 113 static void _qq_start_services(PurpleConnection *gc)
114 { 114 {
115 /* start watching for IMs about to be sent */ 115 /* start watching for IMs about to be sent */
116 /* 116 /*
117 gaim_signal_connect(gaim_conversations_get_handle(), 117 purple_signal_connect(purple_conversations_get_handle(),
118 "sending-im-msg", gc, 118 "sending-im-msg", gc,
119 GAIM_CALLBACK(qq_sending_im_msg_cb), NULL); 119 PURPLE_CALLBACK(qq_sending_im_msg_cb), NULL);
120 */ 120 */
121 } 121 }
122 122
123 /* the callback function after socket is built 123 /* the callback function after socket is built
124 * we setup the qq protocol related configuration here */ 124 * we setup the qq protocol related configuration here */
125 static void _qq_got_login(gpointer data, gint source, const gchar *error_message) 125 static void _qq_got_login(gpointer data, gint source, const gchar *error_message)
126 { 126 {
127 qq_data *qd; 127 qq_data *qd;
128 GaimConnection *gc; 128 PurpleConnection *gc;
129 gchar *buf; 129 gchar *buf;
130 const gchar *passwd; 130 const gchar *passwd;
131 131
132 gc = (GaimConnection *) data; 132 gc = (PurpleConnection *) data;
133 133
134 if (!GAIM_CONNECTION_IS_VALID(gc)) { 134 if (!PURPLE_CONNECTION_IS_VALID(gc)) {
135 close(source); 135 close(source);
136 return; 136 return;
137 } 137 }
138 138
139 g_return_if_fail(gc != NULL && gc->proto_data != NULL); 139 g_return_if_fail(gc != NULL && gc->proto_data != NULL);
140 140
141 if (source < 0) { /* socket returns -1 */ 141 if (source < 0) { /* socket returns -1 */
142 gaim_connection_error(gc, error_message); 142 purple_connection_error(gc, error_message);
143 return; 143 return;
144 } 144 }
145 145
146 qd = (qq_data *) gc->proto_data; 146 qd = (qq_data *) gc->proto_data;
147 147
153 srandom(time(NULL)); 153 srandom(time(NULL));
154 qd->send_seq = random() & 0x0000ffff; 154 qd->send_seq = random() & 0x0000ffff;
155 qd->fd = source; 155 qd->fd = source;
156 qd->logged_in = FALSE; 156 qd->logged_in = FALSE;
157 qd->channel = 1; 157 qd->channel = 1;
158 qd->uid = strtol(gaim_account_get_username(gaim_connection_get_account(gc)), NULL, 10); 158 qd->uid = strtol(purple_account_get_username(purple_connection_get_account(gc)), NULL, 10);
159 159
160 /* now generate md5 processed passwd */ 160 /* now generate md5 processed passwd */
161 passwd = gaim_account_get_password(gaim_connection_get_account(gc)); 161 passwd = purple_account_get_password(purple_connection_get_account(gc));
162 qd->pwkey = _gen_pwkey(passwd); 162 qd->pwkey = _gen_pwkey(passwd);
163 163
164 qd->sendqueue_timeout = gaim_timeout_add(QQ_SENDQUEUE_TIMEOUT, qq_sendqueue_timeout_callback, gc); 164 qd->sendqueue_timeout = purple_timeout_add(QQ_SENDQUEUE_TIMEOUT, qq_sendqueue_timeout_callback, gc);
165 gc->inpa = gaim_input_add(qd->fd, GAIM_INPUT_READ, qq_input_pending, gc); 165 gc->inpa = purple_input_add(qd->fd, PURPLE_INPUT_READ, qq_input_pending, gc);
166 166
167 /* Update the login progress status display */ 167 /* Update the login progress status display */
168 buf = g_strdup_printf("Login as %d", qd->uid); 168 buf = g_strdup_printf("Login as %d", qd->uid);
169 gaim_connection_update_progress(gc, buf, 1, QQ_CONNECT_STEPS); 169 purple_connection_update_progress(gc, buf, 1, QQ_CONNECT_STEPS);
170 g_free(buf); 170 g_free(buf);
171 171
172 _qq_start_services(gc); 172 _qq_start_services(gc);
173 173
174 qq_send_packet_request_login_token(gc); 174 qq_send_packet_request_login_token(gc);
175 } 175 }
176 176
177 /* clean up qq_data structure and all its components 177 /* clean up qq_data structure and all its components
178 * always used before a redirectly connection */ 178 * always used before a redirectly connection */
179 static void _qq_common_clean(GaimConnection *gc) 179 static void _qq_common_clean(PurpleConnection *gc)
180 { 180 {
181 qq_data *qd; 181 qq_data *qd;
182 182
183 g_return_if_fail(gc != NULL && gc->proto_data != NULL); 183 g_return_if_fail(gc != NULL && gc->proto_data != NULL);
184 qd = (qq_data *) gc->proto_data; 184 qd = (qq_data *) gc->proto_data;
187 if (qd->fd >= 0 && qd->logged_in) 187 if (qd->fd >= 0 && qd->logged_in)
188 qq_send_packet_logout(gc); 188 qq_send_packet_logout(gc);
189 close(qd->fd); 189 close(qd->fd);
190 190
191 if (qd->sendqueue_timeout > 0) { 191 if (qd->sendqueue_timeout > 0) {
192 gaim_timeout_remove(qd->sendqueue_timeout); 192 purple_timeout_remove(qd->sendqueue_timeout);
193 qd->sendqueue_timeout = 0; 193 qd->sendqueue_timeout = 0;
194 } 194 }
195 195
196 if (gc->inpa > 0) { 196 if (gc->inpa > 0) {
197 gaim_input_remove(gc->inpa); 197 purple_input_remove(gc->inpa);
198 gc->inpa = 0; 198 gc->inpa = 0;
199 } 199 }
200 200
201 qq_b4_packets_free(qd); 201 qq_b4_packets_free(qd);
202 qq_sendqueue_free(qd); 202 qq_sendqueue_free(qd);
205 qq_add_buddy_request_free(qd); 205 qq_add_buddy_request_free(qd);
206 qq_info_query_free(qd); 206 qq_info_query_free(qd);
207 qq_buddies_list_free(gc->account, qd); 207 qq_buddies_list_free(gc->account, qd);
208 } 208 }
209 209
210 static void no_one_calls(gpointer data, gint source, GaimInputCondition cond) 210 static void no_one_calls(gpointer data, gint source, PurpleInputCondition cond)
211 { 211 {
212 struct PHB *phb = data; 212 struct PHB *phb = data;
213 socklen_t len; 213 socklen_t len;
214 int error=0, ret; 214 int error=0, ret;
215 215
216 gaim_debug_info("proxy", "Connected.\n"); 216 purple_debug_info("proxy", "Connected.\n");
217 217
218 len = sizeof(error); 218 len = sizeof(error);
219 219
220 /* 220 /*
221 * getsockopt after a non-blocking connect returns -1 if something is 221 * getsockopt after a non-blocking connect returns -1 if something is
233 return; /* we'll be called again later */ 233 return; /* we'll be called again later */
234 if (ret < 0 || error != 0) { 234 if (ret < 0 || error != 0) {
235 if(ret!=0) 235 if(ret!=0)
236 error = errno; 236 error = errno;
237 close(source); 237 close(source);
238 gaim_input_remove(phb->inpa); 238 purple_input_remove(phb->inpa);
239 239
240 gaim_debug_error("proxy", "getsockopt SO_ERROR check: %s\n", strerror(error)); 240 purple_debug_error("proxy", "getsockopt SO_ERROR check: %s\n", strerror(error));
241 241
242 phb->func(phb->data, -1, _("Unable to connect")); 242 phb->func(phb->data, -1, _("Unable to connect"));
243 return; 243 return;
244 } 244 }
245 245
246 gaim_input_remove(phb->inpa); 246 purple_input_remove(phb->inpa);
247 247
248 if (phb->account == NULL || gaim_account_get_connection(phb->account) != NULL) { 248 if (phb->account == NULL || purple_account_get_connection(phb->account) != NULL) {
249 249
250 phb->func(phb->data, source, NULL); 250 phb->func(phb->data, source, NULL);
251 } 251 }
252 252
253 g_free(phb->host); 253 g_free(phb->host);
257 /* returns -1 if fails, otherwise returns the file handle */ 257 /* returns -1 if fails, otherwise returns the file handle */
258 static gint _qq_proxy_none(struct PHB *phb, struct sockaddr *addr, socklen_t addrlen) 258 static gint _qq_proxy_none(struct PHB *phb, struct sockaddr *addr, socklen_t addrlen)
259 { 259 {
260 gint fd = -1; 260 gint fd = -1;
261 261
262 gaim_debug(GAIM_DEBUG_INFO, "QQ", "Using UDP without proxy\n"); 262 purple_debug(PURPLE_DEBUG_INFO, "QQ", "Using UDP without proxy\n");
263 fd = socket(PF_INET, SOCK_DGRAM, 0); 263 fd = socket(PF_INET, SOCK_DGRAM, 0);
264 264
265 if (fd < 0) { 265 if (fd < 0) {
266 gaim_debug(GAIM_DEBUG_ERROR, "QQ Redirect", 266 purple_debug(PURPLE_DEBUG_ERROR, "QQ Redirect",
267 "Unable to create socket: %s\n", strerror(errno)); 267 "Unable to create socket: %s\n", strerror(errno));
268 return -1; 268 return -1;
269 } 269 }
270 270
271 /* we use non-blocking mode to speed up connection */ 271 /* we use non-blocking mode to speed up connection */
290 * [EINTR] 290 * [EINTR]
291 * A signal interrupted the call. 291 * A signal interrupted the call.
292 * The connection is established asynchronously. 292 * The connection is established asynchronously.
293 */ 293 */
294 if ((errno == EINPROGRESS) || (errno == EINTR)) { 294 if ((errno == EINPROGRESS) || (errno == EINTR)) {
295 gaim_debug(GAIM_DEBUG_WARNING, "QQ", "Connect in asynchronous mode.\n"); 295 purple_debug(PURPLE_DEBUG_WARNING, "QQ", "Connect in asynchronous mode.\n");
296 phb->inpa = gaim_input_add(fd, GAIM_INPUT_WRITE, no_one_calls, phb); 296 phb->inpa = purple_input_add(fd, PURPLE_INPUT_WRITE, no_one_calls, phb);
297 } else { 297 } else {
298 gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Connection failed: %d\n", strerror(errno)); 298 purple_debug(PURPLE_DEBUG_ERROR, "QQ", "Connection failed: %d\n", strerror(errno));
299 close(fd); 299 close(fd);
300 return -1; 300 return -1;
301 } /* if errno */ 301 } /* if errno */
302 } else { /* connect returns 0 */ 302 } else { /* connect returns 0 */
303 gaim_debug(GAIM_DEBUG_INFO, "QQ", "Connected.\n"); 303 purple_debug(PURPLE_DEBUG_INFO, "QQ", "Connected.\n");
304 fcntl(fd, F_SETFL, 0); 304 fcntl(fd, F_SETFL, 0);
305 phb->func(phb->data, fd, NULL); 305 phb->func(phb->data, fd, NULL);
306 } 306 }
307 307
308 return fd; 308 return fd;
325 } 325 }
326 326
327 static void _qq_server_resolved(GSList *hosts, gpointer data, const char *error_message) 327 static void _qq_server_resolved(GSList *hosts, gpointer data, const char *error_message)
328 { 328 {
329 struct PHB *phb = (struct PHB *) data; 329 struct PHB *phb = (struct PHB *) data;
330 GaimConnection *gc = (GaimConnection *) phb->data; 330 PurpleConnection *gc = (PurpleConnection *) phb->data;
331 qq_data *qd = (qq_data *) gc->proto_data; 331 qq_data *qd = (qq_data *) gc->proto_data;
332 struct sockaddr_in addr; 332 struct sockaddr_in addr;
333 gint addr_size, ret = -1; 333 gint addr_size, ret = -1;
334 334
335 if(_qq_fill_host(hosts, &addr, &addr_size)) { 335 if(_qq_fill_host(hosts, &addr, &addr_size)) {
336 switch (gaim_proxy_info_get_type(phb->gpi)) { 336 switch (purple_proxy_info_get_type(phb->gpi)) {
337 case GAIM_PROXY_NONE: 337 case PURPLE_PROXY_NONE:
338 ret = _qq_proxy_none(phb, (struct sockaddr *) &addr, addr_size); 338 ret = _qq_proxy_none(phb, (struct sockaddr *) &addr, addr_size);
339 break; 339 break;
340 case GAIM_PROXY_SOCKS5: 340 case PURPLE_PROXY_SOCKS5:
341 ret = 0; 341 ret = 0;
342 if (gaim_proxy_info_get_host(phb->gpi) == NULL || 342 if (purple_proxy_info_get_host(phb->gpi) == NULL ||
343 gaim_proxy_info_get_port(phb->gpi) == 0) { 343 purple_proxy_info_get_port(phb->gpi) == 0) {
344 gaim_debug(GAIM_DEBUG_ERROR, "QQ", 344 purple_debug(PURPLE_DEBUG_ERROR, "QQ",
345 "Use of socks5 proxy selected but host or port info doesn't exist.\n"); 345 "Use of socks5 proxy selected but host or port info doesn't exist.\n");
346 ret = -1; 346 ret = -1;
347 } else { 347 } else {
348 /* as the destination is always QQ server during the session, 348 /* as the destination is always QQ server during the session,
349 * we can set dest_sin here, instead of _qq_s5_canread_again */ 349 * we can set dest_sin here, instead of _qq_s5_canread_again */
350 memcpy(&qd->dest_sin, &addr, addr_size); 350 memcpy(&qd->dest_sin, &addr, addr_size);
351 if (gaim_dnsquery_a(gaim_proxy_info_get_host(phb->gpi), 351 if (purple_dnsquery_a(purple_proxy_info_get_host(phb->gpi),
352 gaim_proxy_info_get_port(phb->gpi), 352 purple_proxy_info_get_port(phb->gpi),
353 _qq_proxy_resolved, phb) == NULL) 353 _qq_proxy_resolved, phb) == NULL)
354 ret = -1; 354 ret = -1;
355 } 355 }
356 break; 356 break;
357 default: 357 default:
358 gaim_debug(GAIM_DEBUG_WARNING, "QQ", 358 purple_debug(PURPLE_DEBUG_WARNING, "QQ",
359 "Proxy type %i is unsupported, not using a proxy.\n", 359 "Proxy type %i is unsupported, not using a proxy.\n",
360 gaim_proxy_info_get_type(phb->gpi)); 360 purple_proxy_info_get_type(phb->gpi));
361 ret = _qq_proxy_none(phb, (struct sockaddr *) &addr, addr_size); 361 ret = _qq_proxy_none(phb, (struct sockaddr *) &addr, addr_size);
362 } 362 }
363 } 363 }
364 364
365 if (ret < 0) { 365 if (ret < 0) {
368 g_free(phb); 368 g_free(phb);
369 } 369 }
370 } 370 }
371 371
372 /* returns -1 if dns lookup fails, otherwise returns 0 */ 372 /* returns -1 if dns lookup fails, otherwise returns 0 */
373 static gint _qq_udp_proxy_connect(GaimAccount *account, 373 static gint _qq_udp_proxy_connect(PurpleAccount *account,
374 const gchar *server, guint16 port, 374 const gchar *server, guint16 port,
375 void callback(gpointer, gint, const gchar *error_message), 375 void callback(gpointer, gint, const gchar *error_message),
376 GaimConnection *gc) 376 PurpleConnection *gc)
377 { 377 {
378 GaimProxyInfo *info; 378 PurpleProxyInfo *info;
379 struct PHB *phb; 379 struct PHB *phb;
380 qq_data *qd = (qq_data *) gc->proto_data; 380 qq_data *qd = (qq_data *) gc->proto_data;
381 381
382 g_return_val_if_fail(gc != NULL && qd != NULL, -1); 382 g_return_val_if_fail(gc != NULL && qd != NULL, -1);
383 383
384 info = gaim_proxy_get_setup(account); 384 info = purple_proxy_get_setup(account);
385 385
386 phb = g_new0(struct PHB, 1); 386 phb = g_new0(struct PHB, 1);
387 phb->host = g_strdup(server); 387 phb->host = g_strdup(server);
388 phb->port = port; 388 phb->port = port;
389 phb->account = account; 389 phb->account = account;
390 phb->gpi = info; 390 phb->gpi = info;
391 phb->func = callback; 391 phb->func = callback;
392 phb->data = gc; 392 phb->data = gc;
393 qd->proxy_type = gaim_proxy_info_get_type(phb->gpi); 393 qd->proxy_type = purple_proxy_info_get_type(phb->gpi);
394 394
395 gaim_debug(GAIM_DEBUG_INFO, "QQ", "Choosing proxy type %d\n", 395 purple_debug(PURPLE_DEBUG_INFO, "QQ", "Choosing proxy type %d\n",
396 gaim_proxy_info_get_type(phb->gpi)); 396 purple_proxy_info_get_type(phb->gpi));
397 397
398 if (gaim_dnsquery_a(server, port, _qq_server_resolved, phb) == NULL) { 398 if (purple_dnsquery_a(server, port, _qq_server_resolved, phb) == NULL) {
399 phb->func(gc, -1, _("Unable to connect")); 399 phb->func(gc, -1, _("Unable to connect"));
400 g_free(phb->host); 400 g_free(phb->host);
401 g_free(phb); 401 g_free(phb);
402 return -1; 402 return -1;
403 } else { 403 } else {
404 return 0; 404 return 0;
405 } 405 }
406 } 406 }
407 407
408 /* QQ connection via UDP/TCP. 408 /* QQ connection via UDP/TCP.
409 * I use Gaim proxy function to provide TCP proxy support, 409 * I use Purple proxy function to provide TCP proxy support,
410 * and qq_udp_proxy.c to add UDP proxy support (thanks henry) */ 410 * and qq_udp_proxy.c to add UDP proxy support (thanks henry) */
411 static gint _proxy_connect_full (GaimAccount *account, const gchar *host, guint16 port, 411 static gint _proxy_connect_full (PurpleAccount *account, const gchar *host, guint16 port,
412 GaimProxyConnectFunction func, gpointer data, gboolean use_tcp) 412 PurpleProxyConnectFunction func, gpointer data, gboolean use_tcp)
413 { 413 {
414 GaimConnection *gc; 414 PurpleConnection *gc;
415 qq_data *qd; 415 qq_data *qd;
416 416
417 gc = gaim_account_get_connection(account); 417 gc = purple_account_get_connection(account);
418 qd = (qq_data *) gc->proto_data; 418 qd = (qq_data *) gc->proto_data;
419 qd->server_ip = g_strdup(host); 419 qd->server_ip = g_strdup(host);
420 qd->server_port = port; 420 qd->server_port = port;
421 421
422 if(use_tcp) 422 if(use_tcp)
423 return (gaim_proxy_connect(NULL, account, host, port, func, data) == NULL); 423 return (purple_proxy_connect(NULL, account, host, port, func, data) == NULL);
424 else 424 else
425 return _qq_udp_proxy_connect(account, host, port, func, data); 425 return _qq_udp_proxy_connect(account, host, port, func, data);
426 } 426 }
427 427
428 /* establish a generic QQ connection 428 /* establish a generic QQ connection
429 * TCP/UDP, and direct/redirected */ 429 * TCP/UDP, and direct/redirected */
430 gint qq_connect(GaimAccount *account, const gchar *host, guint16 port, 430 gint qq_connect(PurpleAccount *account, const gchar *host, guint16 port,
431 gboolean use_tcp, gboolean is_redirect) 431 gboolean use_tcp, gboolean is_redirect)
432 { 432 {
433 GaimConnection *gc; 433 PurpleConnection *gc;
434 qq_data *qd; 434 qq_data *qd;
435 435
436 g_return_val_if_fail(host != NULL, -1); 436 g_return_val_if_fail(host != NULL, -1);
437 g_return_val_if_fail(port > 0, -1); 437 g_return_val_if_fail(port > 0, -1);
438 438
439 gc = gaim_account_get_connection(account); 439 gc = purple_account_get_connection(account);
440 g_return_val_if_fail(gc != NULL && gc->proto_data != NULL, -1); 440 g_return_val_if_fail(gc != NULL && gc->proto_data != NULL, -1);
441 441
442 if (is_redirect) 442 if (is_redirect)
443 _qq_common_clean(gc); 443 _qq_common_clean(gc);
444 444
447 447
448 return _proxy_connect_full(account, host, port, _qq_got_login, gc, use_tcp); 448 return _proxy_connect_full(account, host, port, _qq_got_login, gc, use_tcp);
449 } 449 }
450 450
451 /* clean up the given QQ connection and free all resources */ 451 /* clean up the given QQ connection and free all resources */
452 void qq_disconnect(GaimConnection *gc) 452 void qq_disconnect(PurpleConnection *gc)
453 { 453 {
454 qq_data *qd; 454 qq_data *qd;
455 455
456 g_return_if_fail(gc != NULL); 456 g_return_if_fail(gc != NULL);
457 457
476 476
477 g_return_val_if_fail(qd != NULL && qd->fd >= 0 && data != NULL && len > 0, -1); 477 g_return_val_if_fail(qd != NULL && qd->fd >= 0 && data != NULL && len > 0, -1);
478 478
479 /* TCP sock5 may be processed twice 479 /* TCP sock5 may be processed twice
480 * so we need to check qd->use_tcp as well */ 480 * so we need to check qd->use_tcp as well */
481 if ((!qd->use_tcp) && qd->proxy_type == GAIM_PROXY_SOCKS5) { /* UDP sock5 */ 481 if ((!qd->use_tcp) && qd->proxy_type == PURPLE_PROXY_SOCKS5) { /* UDP sock5 */
482 buf = g_newa(guint8, len + 10); 482 buf = g_newa(guint8, len + 10);
483 buf[0] = 0x00; 483 buf[0] = 0x00;
484 buf[1] = 0x00; /* reserved */ 484 buf[1] = 0x00; /* reserved */
485 buf[2] = 0x00; /* frag */ 485 buf[2] = 0x00; /* frag */
486 buf[3] = 0x01; /* type */ 486 buf[3] = 0x01; /* type */
492 } else { 492 } else {
493 errno = 0; 493 errno = 0;
494 ret = send(qd->fd, data, len, 0); 494 ret = send(qd->fd, data, len, 0);
495 } 495 }
496 if (ret == -1) { 496 if (ret == -1) {
497 gaim_connection_error(qd->gc, _("Socket send error")); 497 purple_connection_error(qd->gc, _("Socket send error"));
498 return ret; 498 return ret;
499 } else if (errno == ECONNREFUSED) { 499 } else if (errno == ECONNREFUSED) {
500 gaim_connection_error(qd->gc, _("Connection refused")); 500 purple_connection_error(qd->gc, _("Connection refused"));
501 return ret; 501 return ret;
502 } 502 }
503 503
504 return ret; 504 return ret;
505 } 505 }
516 516
517 bytes = read(qd->fd, buf, len + 10); 517 bytes = read(qd->fd, buf, len + 10);
518 if (bytes < 0) 518 if (bytes < 0)
519 return -1; 519 return -1;
520 520
521 if ((!qd->use_tcp) && qd->proxy_type == GAIM_PROXY_SOCKS5) { /* UDP sock5 */ 521 if ((!qd->use_tcp) && qd->proxy_type == PURPLE_PROXY_SOCKS5) { /* UDP sock5 */
522 if (bytes < 10) 522 if (bytes < 10)
523 return -1; 523 return -1;
524 bytes -= 10; 524 bytes -= 10;
525 g_memmove(data, buf + 10, bytes); /* cut off the header */ 525 g_memmove(data, buf + 10, bytes); /* cut off the header */
526 } else { 526 } else {