annotate libpurple/protocols/qq/qq_network.c @ 24113:5c030dc88356

merge of '035bfdb2d9357e8feaf49c1fea3daa75cd90d74d' and 'e0d4adfcd908978bcad627bd8212730ce8775292'
author Daniel Atallah <daniel.atallah@gmail.com>
date Mon, 15 Sep 2008 03:05:34 +0000
parents fb8204e956a1 6408be948d56
children 225e0e9e1055
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
23050
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
1 /**
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
2 * @file qq_network.c
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
3 *
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
4 * purple
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
5 *
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
6 * Purple is the legal property of its developers, whose names are too numerous
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
7 * to list here. Please refer to the COPYRIGHT file distributed with this
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
8 * source distribution.
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
9 *
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
10 * This program is free software; you can redistribute it and/or modify
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
11 * it under the terms of the GNU General Public License as published by
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
12 * the Free Software Foundation; either version 2 of the License, or
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
13 * (at your option) any later version.
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
14 *
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
15 * This program is distributed in the hope that it will be useful,
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
18 * GNU General Public License for more details.
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
19 *
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
20 * You should have received a copy of the GNU General Public License
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
21 * along with this program; if not, write to the Free Software
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
23 */
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
24
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
25 #include "cipher.h"
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
26 #include "debug.h"
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
27 #include "internal.h"
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
28
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
29 #include "buddy_info.h"
23638
1c50f12b1c52 2008.08.02 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23561
diff changeset
30 #include "group_info.h"
23050
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
31 #include "group_free.h"
23695
5f454b975a99 2008.08.10 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23638
diff changeset
32 #include "qq_crypt.h"
23050
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
33 #include "header_info.h"
23638
1c50f12b1c52 2008.08.02 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23561
diff changeset
34 #include "qq_base.h"
1c50f12b1c52 2008.08.02 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23561
diff changeset
35 #include "buddy_list.h"
23050
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
36 #include "packet_parse.h"
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
37 #include "qq_network.h"
23051
55f986ccbb6a patch-05-reconnect-and-code-cleanup
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23050
diff changeset
38 #include "qq_trans.h"
23050
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
39 #include "utils.h"
23638
1c50f12b1c52 2008.08.02 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23561
diff changeset
40 #include "qq_process.h"
23050
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
41
24088
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
42 #define QQ_DEFAULT_PORT 8000
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
43
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
44 /* set QQ_CONNECT_MAX to 1, when test reconnecting */
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
45 #define QQ_CONNECT_MAX 3
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
46 #define QQ_CONNECT_INTERVAL 2
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
47 #define QQ_CONNECT_CHECK 5
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
48 #define QQ_KEEP_ALIVE_INTERVAL 60
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
49 #define QQ_TRANS_INTERVAL 10
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
50
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
51 gboolean connect_to_server(PurpleConnection *gc, gchar *server, gint port);
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
52
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
53 static qq_connection *connection_find(qq_data *qd, int fd) {
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
54 qq_connection *ret = NULL;
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
55 GSList *entry = qd->openconns;
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
56 while(entry) {
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
57 ret = entry->data;
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
58 if(ret->fd == fd) return ret;
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
59 entry = entry->next;
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
60 }
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
61 return NULL;
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
62 }
23051
55f986ccbb6a patch-05-reconnect-and-code-cleanup
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23050
diff changeset
63
24088
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
64 static qq_connection *connection_create(qq_data *qd, int fd) {
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
65 qq_connection *ret = g_new0(qq_connection, 1);
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
66 ret->fd = fd;
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
67 qd->openconns = g_slist_append(qd->openconns, ret);
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
68 return ret;
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
69 }
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
70
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
71 static void connection_remove(qq_data *qd, int fd) {
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
72 qq_connection *conn = connection_find(qd, fd);
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
73 qd->openconns = g_slist_remove(qd->openconns, conn);
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
74
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
75 g_return_if_fail( conn != NULL );
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
76
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
77 purple_debug_info("QQ", "Close socket %d\n", conn->fd);
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
78 if(conn->input_handler > 0) purple_input_remove(conn->input_handler);
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
79 if(conn->can_write_handler > 0) purple_input_remove(conn->can_write_handler);
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
80
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
81 if (conn->fd >= 0) close(conn->fd);
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
82 if(conn->tcp_txbuf != NULL) purple_circ_buffer_destroy(conn->tcp_txbuf);
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
83 if (conn->tcp_rxqueue != NULL) g_free(conn->tcp_rxqueue);
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
84
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
85 g_free(conn);
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
86 }
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
87
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
88 static void connection_free_all(qq_data *qd) {
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
89 qq_connection *ret = NULL;
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
90 GSList *entry = qd->openconns;
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
91 while(entry) {
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
92 ret = entry->data;
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
93 connection_remove(qd, ret->fd);
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
94 entry = qd->openconns;
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
95 }
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
96 }
23051
55f986ccbb6a patch-05-reconnect-and-code-cleanup
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23050
diff changeset
97 static gboolean set_new_server(qq_data *qd)
55f986ccbb6a patch-05-reconnect-and-code-cleanup
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23050
diff changeset
98 {
55f986ccbb6a patch-05-reconnect-and-code-cleanup
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23050
diff changeset
99 gint count;
55f986ccbb6a patch-05-reconnect-and-code-cleanup
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23050
diff changeset
100 gint index;
55f986ccbb6a patch-05-reconnect-and-code-cleanup
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23050
diff changeset
101 GList *it = NULL;
24088
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
102
23051
55f986ccbb6a patch-05-reconnect-and-code-cleanup
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23050
diff changeset
103 g_return_val_if_fail(qd != NULL, FALSE);
55f986ccbb6a patch-05-reconnect-and-code-cleanup
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23050
diff changeset
104
55f986ccbb6a patch-05-reconnect-and-code-cleanup
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23050
diff changeset
105 if (qd->servers == NULL) {
24088
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
106 purple_debug_info("QQ", "Server list is NULL\n");
23051
55f986ccbb6a patch-05-reconnect-and-code-cleanup
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23050
diff changeset
107 return FALSE;
55f986ccbb6a patch-05-reconnect-and-code-cleanup
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23050
diff changeset
108 }
55f986ccbb6a patch-05-reconnect-and-code-cleanup
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23050
diff changeset
109
24088
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
110 /* remove server used before */
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
111 if (qd->curr_server != NULL) {
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
112 purple_debug_info("QQ",
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
113 "Remove current [%s] from server list\n", qd->curr_server);
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
114 qd->servers = g_list_remove(qd->servers, qd->curr_server);
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
115 qd->curr_server = NULL;
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
116 }
23051
55f986ccbb6a patch-05-reconnect-and-code-cleanup
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23050
diff changeset
117
55f986ccbb6a patch-05-reconnect-and-code-cleanup
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23050
diff changeset
118 count = g_list_length(qd->servers);
24088
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
119 purple_debug_info("QQ", "Server list has %d\n", count);
23051
55f986ccbb6a patch-05-reconnect-and-code-cleanup
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23050
diff changeset
120 if (count <= 0) {
55f986ccbb6a patch-05-reconnect-and-code-cleanup
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23050
diff changeset
121 /* no server left, disconnect when result is false */
55f986ccbb6a patch-05-reconnect-and-code-cleanup
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23050
diff changeset
122 qd->servers = NULL;
55f986ccbb6a patch-05-reconnect-and-code-cleanup
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23050
diff changeset
123 return FALSE;
55f986ccbb6a patch-05-reconnect-and-code-cleanup
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23050
diff changeset
124 }
24088
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
125
23051
55f986ccbb6a patch-05-reconnect-and-code-cleanup
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23050
diff changeset
126 /* get new server */
24088
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
127 index = rand() % count;
23051
55f986ccbb6a patch-05-reconnect-and-code-cleanup
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23050
diff changeset
128 it = g_list_nth(qd->servers, index);
24088
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
129 qd->curr_server = it->data; /* do not free server_name */
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
130 if (qd->curr_server == NULL || strlen(qd->curr_server) <= 0 ) {
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
131 purple_debug_info("QQ", "Server name at %d is empty\n", index);
23051
55f986ccbb6a patch-05-reconnect-and-code-cleanup
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23050
diff changeset
132 return FALSE;
55f986ccbb6a patch-05-reconnect-and-code-cleanup
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23050
diff changeset
133 }
55f986ccbb6a patch-05-reconnect-and-code-cleanup
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23050
diff changeset
134
24088
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
135 purple_debug_info("QQ", "set new server to %s\n", qd->curr_server);
23051
55f986ccbb6a patch-05-reconnect-and-code-cleanup
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23050
diff changeset
136 return TRUE;
55f986ccbb6a patch-05-reconnect-and-code-cleanup
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23050
diff changeset
137 }
23050
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
138
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
139 static gint packet_get_header(guint8 *header_tag, guint16 *source_tag,
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
140 guint16 *cmd, guint16 *seq, guint8 *buf)
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
141 {
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
142 gint bytes = 0;
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
143 bytes += qq_get8(header_tag, buf + bytes);
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
144 bytes += qq_get16(source_tag, buf + bytes);
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
145 bytes += qq_get16(cmd, buf + bytes);
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
146 bytes += qq_get16(seq, buf + bytes);
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
147 return bytes;
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
148 }
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
149
24088
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
150 static gboolean connect_check(gpointer data)
23051
55f986ccbb6a patch-05-reconnect-and-code-cleanup
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23050
diff changeset
151 {
24088
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
152 PurpleConnection *gc = (PurpleConnection *) data;
23051
55f986ccbb6a patch-05-reconnect-and-code-cleanup
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23050
diff changeset
153 qq_data *qd;
55f986ccbb6a patch-05-reconnect-and-code-cleanup
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23050
diff changeset
154
24088
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
155 g_return_val_if_fail(gc != NULL && gc->proto_data != NULL, FALSE);
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
156 qd = (qq_data *) gc->proto_data;
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
157
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
158 if (qd->connect_watcher > 0) {
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
159 purple_timeout_remove(qd->connect_watcher);
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
160 qd->connect_watcher = 0;
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
161 }
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
162
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
163 if (qd->fd >= 0 && qd->token != NULL && qd->token_len >= 0) {
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
164 purple_debug_info("QQ", "Connect ok\n");
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
165 return FALSE;
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
166 }
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
167
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
168 qd->connect_watcher = purple_timeout_add_seconds(0, qq_connect_later, gc);
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
169 return FALSE;
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
170 }
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
171
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
172 /* Warning: qq_connect_later destory all connection
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
173 * Any function should be care of use qq_data after call this function
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
174 * Please conside tcp_pending and udp_pending */
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
175 gboolean qq_connect_later(gpointer data)
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
176 {
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
177 PurpleConnection *gc = (PurpleConnection *) data;
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
178 qq_data *qd;
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
179 char *server;
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
180 int port;
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
181 gchar **segments;
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
182
23051
55f986ccbb6a patch-05-reconnect-and-code-cleanup
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23050
diff changeset
183 g_return_val_if_fail(gc != NULL && gc->proto_data != NULL, FALSE);
55f986ccbb6a patch-05-reconnect-and-code-cleanup
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23050
diff changeset
184 qd = (qq_data *) gc->proto_data;
55f986ccbb6a patch-05-reconnect-and-code-cleanup
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23050
diff changeset
185
24088
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
186 if (qd->check_watcher > 0) {
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
187 purple_timeout_remove(qd->check_watcher);
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
188 qd->check_watcher = 0;
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
189 }
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
190 qq_disconnect(gc);
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
191
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
192 if (qd->redirect_ip.s_addr != 0) {
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
193 /* redirect to new server */
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
194 server = g_strdup_printf("%s:%d", inet_ntoa(qd->redirect_ip), qd->redirect_port);
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
195 qd->servers = g_list_append(qd->servers, server);
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
196 qd->curr_server = server;
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
197
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
198 qd->redirect_ip.s_addr = 0;
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
199 qd->redirect_port = 0;
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
200 qd->connect_retry = QQ_CONNECT_MAX;
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
201 }
23051
55f986ccbb6a patch-05-reconnect-and-code-cleanup
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23050
diff changeset
202
24088
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
203 if (qd->curr_server == NULL || strlen (qd->curr_server) == 0 || qd->connect_retry <= 0) {
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
204 if ( set_new_server(qd) != TRUE) {
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
205 purple_connection_error_reason(gc, PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
206 _("Failed to connect all servers"));
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
207 return FALSE;
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
208 }
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
209 qd->connect_retry = QQ_CONNECT_MAX;
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
210 }
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
211
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
212 segments = g_strsplit_set(qd->curr_server, ":", 0);
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
213 server = g_strdup(segments[0]);
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
214 port = atoi(segments[1]);
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
215 if (port <= 0) {
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
216 purple_debug_info("QQ", "Port not define in %s\n", qd->curr_server);
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
217 port = QQ_DEFAULT_PORT;
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
218 }
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
219 g_strfreev(segments);
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
220
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
221 qd->connect_retry--;
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
222 if ( !connect_to_server(gc, server, port) ) {
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
223 purple_connection_error_reason(gc, PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
224 _("Unable to connect."));
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
225 }
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
226
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
227 qd->check_watcher = purple_timeout_add_seconds(QQ_CONNECT_CHECK, connect_check, gc);
23051
55f986ccbb6a patch-05-reconnect-and-code-cleanup
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23050
diff changeset
228 return FALSE; /* timeout callback stops */
55f986ccbb6a patch-05-reconnect-and-code-cleanup
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23050
diff changeset
229 }
55f986ccbb6a patch-05-reconnect-and-code-cleanup
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23050
diff changeset
230
23050
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
231 /* process the incoming packet from qq_pending */
24088
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
232 static gboolean packet_process(PurpleConnection *gc, guint8 *buf, gint buf_len)
23050
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
233 {
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
234 qq_data *qd;
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
235 gint bytes, bytes_not_read;
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
236
24090
6408be948d56 disapproval of revision '92d52eef2994d2697999177804e3665989cfa352'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24089
diff changeset
237 gboolean prev_update_status;
6408be948d56 disapproval of revision '92d52eef2994d2697999177804e3665989cfa352'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24089
diff changeset
238
23050
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
239 guint8 header_tag;
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
240 guint16 source_tag;
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
241 guint16 cmd;
23051
55f986ccbb6a patch-05-reconnect-and-code-cleanup
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23050
diff changeset
242 guint16 seq; /* May be ack_seq or send_seq, depends on cmd */
23695
5f454b975a99 2008.08.10 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23638
diff changeset
243 guint8 room_cmd;
5f454b975a99 2008.08.10 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23638
diff changeset
244 guint32 room_id;
24088
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
245 gint update_class;
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
246 guint32 ship32;
23051
55f986ccbb6a patch-05-reconnect-and-code-cleanup
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23050
diff changeset
247
23638
1c50f12b1c52 2008.08.02 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23561
diff changeset
248 qq_transaction *trans;
23050
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
249
24088
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
250 g_return_val_if_fail(buf != NULL && buf_len > 0, TRUE);
23050
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
251
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
252 qd = (qq_data *) gc->proto_data;
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
253
23051
55f986ccbb6a patch-05-reconnect-and-code-cleanup
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23050
diff changeset
254 /* Len, header and tail tag have been checked before */
23050
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
255 bytes = 0;
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
256 bytes += packet_get_header(&header_tag, &source_tag, &cmd, &seq, buf + bytes);
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
257
23695
5f454b975a99 2008.08.10 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23638
diff changeset
258 #if 1
24090
6408be948d56 disapproval of revision '92d52eef2994d2697999177804e3665989cfa352'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24089
diff changeset
259 purple_debug_info("QQ", "==> [%05d] 0x%04X %s, source tag 0x%04X len %d\n",
6408be948d56 disapproval of revision '92d52eef2994d2697999177804e3665989cfa352'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24089
diff changeset
260 seq, cmd, qq_get_cmd_desc(cmd), source_tag, buf_len);
24088
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
261 #endif
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
262 /* this is the length of all the encrypted data (also remove tail tag) */
23050
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
263 bytes_not_read = buf_len - bytes - 1;
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
264
23051
55f986ccbb6a patch-05-reconnect-and-code-cleanup
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23050
diff changeset
265 /* ack packet, we need to update send tranactions */
55f986ccbb6a patch-05-reconnect-and-code-cleanup
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23050
diff changeset
266 /* we do not check duplication for server ack */
24088
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
267 trans = qq_trans_find_rcved(gc, cmd, seq);
23638
1c50f12b1c52 2008.08.02 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23561
diff changeset
268 if (trans == NULL) {
1c50f12b1c52 2008.08.02 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23561
diff changeset
269 /* new server command */
24090
6408be948d56 disapproval of revision '92d52eef2994d2697999177804e3665989cfa352'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24089
diff changeset
270 qq_trans_add_server_cmd(gc, cmd, seq, buf + bytes, bytes_not_read);
6408be948d56 disapproval of revision '92d52eef2994d2697999177804e3665989cfa352'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24089
diff changeset
271 if ( qd->is_finish_update ) {
6408be948d56 disapproval of revision '92d52eef2994d2697999177804e3665989cfa352'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24089
diff changeset
272 qq_proc_cmd_server(gc, cmd, seq, buf + bytes, bytes_not_read);
23051
55f986ccbb6a patch-05-reconnect-and-code-cleanup
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23050
diff changeset
273 }
24088
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
274 return TRUE;
23638
1c50f12b1c52 2008.08.02 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23561
diff changeset
275 }
1c50f12b1c52 2008.08.02 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23561
diff changeset
276
1c50f12b1c52 2008.08.02 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23561
diff changeset
277 if (qq_trans_is_dup(trans)) {
24088
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
278 purple_debug_info("QQ", "dup [%05d] %s, discard...\n", seq, qq_get_cmd_desc(cmd));
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
279 return TRUE;
23638
1c50f12b1c52 2008.08.02 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23561
diff changeset
280 }
1c50f12b1c52 2008.08.02 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23561
diff changeset
281
24090
6408be948d56 disapproval of revision '92d52eef2994d2697999177804e3665989cfa352'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24089
diff changeset
282 if (qq_trans_is_server(trans)) {
6408be948d56 disapproval of revision '92d52eef2994d2697999177804e3665989cfa352'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24089
diff changeset
283 if ( qd->is_finish_update ) {
6408be948d56 disapproval of revision '92d52eef2994d2697999177804e3665989cfa352'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24089
diff changeset
284 qq_proc_cmd_server(gc, cmd, seq, buf + bytes, bytes_not_read);
6408be948d56 disapproval of revision '92d52eef2994d2697999177804e3665989cfa352'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24089
diff changeset
285 }
6408be948d56 disapproval of revision '92d52eef2994d2697999177804e3665989cfa352'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24089
diff changeset
286 return TRUE;
6408be948d56 disapproval of revision '92d52eef2994d2697999177804e3665989cfa352'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24089
diff changeset
287 }
6408be948d56 disapproval of revision '92d52eef2994d2697999177804e3665989cfa352'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24089
diff changeset
288
24088
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
289 update_class = qq_trans_get_class(trans);
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
290 ship32 = qq_trans_get_ship(trans);
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
291
24090
6408be948d56 disapproval of revision '92d52eef2994d2697999177804e3665989cfa352'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24089
diff changeset
292 prev_update_status = qd->is_finish_update;
24088
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
293 switch (cmd) {
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
294 case QQ_CMD_TOKEN:
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
295 if (qq_process_token_reply(gc, buf + bytes, bytes_not_read) == QQ_TOKEN_REPLY_OK) {
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
296 qq_send_packet_login(gc);
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
297 }
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
298 break;
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
299 case QQ_CMD_LOGIN:
24090
6408be948d56 disapproval of revision '92d52eef2994d2697999177804e3665989cfa352'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24089
diff changeset
300 qq_proc_cmd_login(gc, buf + bytes, bytes_not_read);
24088
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
301 /* check is redirect or not, and do it now */
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
302 if (qd->redirect_ip.s_addr != 0) {
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
303 if (qd->check_watcher > 0) {
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
304 purple_timeout_remove(qd->check_watcher);
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
305 qd->check_watcher = 0;
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
306 }
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
307 if (qd->connect_watcher > 0) purple_timeout_remove(qd->connect_watcher);
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
308 qd->connect_watcher = purple_timeout_add_seconds(QQ_CONNECT_INTERVAL, qq_connect_later, gc);
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
309 return FALSE; /* do nothing after this function and return now */
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
310 }
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
311 break;
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
312 case QQ_CMD_ROOM:
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
313 room_cmd = qq_trans_get_room_cmd(trans);
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
314 room_id = qq_trans_get_room_id(trans);
23695
5f454b975a99 2008.08.10 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23638
diff changeset
315 #if 1
24088
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
316 purple_debug_info("QQ", "%s (0x%02X) for room %d, len %d\n",
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
317 qq_get_room_cmd_desc(room_cmd), room_cmd, room_id, buf_len);
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
318 #endif
24090
6408be948d56 disapproval of revision '92d52eef2994d2697999177804e3665989cfa352'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24089
diff changeset
319 qq_proc_room_cmd_reply(gc, seq, room_cmd, room_id, buf + bytes, bytes_not_read, update_class, ship32);
24088
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
320 break;
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
321 default:
24090
6408be948d56 disapproval of revision '92d52eef2994d2697999177804e3665989cfa352'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24089
diff changeset
322 qq_proc_cmd_reply(gc, cmd, seq, buf + bytes, bytes_not_read, update_class, ship32);
24088
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
323 break;
23050
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
324 }
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
325
24090
6408be948d56 disapproval of revision '92d52eef2994d2697999177804e3665989cfa352'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24089
diff changeset
326 if (prev_update_status != qd->is_finish_update && qd->is_finish_update == TRUE) {
6408be948d56 disapproval of revision '92d52eef2994d2697999177804e3665989cfa352'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24089
diff changeset
327 /* is_login, but we have packets before login */
6408be948d56 disapproval of revision '92d52eef2994d2697999177804e3665989cfa352'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24089
diff changeset
328 qq_trans_process_before_login(gc);
6408be948d56 disapproval of revision '92d52eef2994d2697999177804e3665989cfa352'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24089
diff changeset
329 return TRUE;
6408be948d56 disapproval of revision '92d52eef2994d2697999177804e3665989cfa352'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24089
diff changeset
330 }
24088
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
331 return TRUE;
23050
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
332 }
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
333
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
334 static void tcp_pending(gpointer data, gint source, PurpleInputCondition cond)
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
335 {
24088
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
336 PurpleConnection *gc = (PurpleConnection *) data;
23050
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
337 qq_data *qd;
24088
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
338 qq_connection *conn;
23051
55f986ccbb6a patch-05-reconnect-and-code-cleanup
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23050
diff changeset
339 guint8 buf[1024]; /* set to 16 when test tcp_rxqueue */
23050
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
340 gint buf_len;
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
341 gint bytes;
24088
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
342
23050
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
343 guint8 *pkt;
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
344 guint16 pkt_len;
24088
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
345
23050
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
346 gchar *error_msg;
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
347 guint8 *jump;
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
348 gint jump_len;
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
349
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
350 g_return_if_fail(gc != NULL && gc->proto_data != NULL);
24088
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
351 qd = (qq_data *) gc->proto_data;
23050
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
352
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
353 if(cond != PURPLE_INPUT_READ) {
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
354 purple_connection_error_reason(gc, PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
355 _("Socket error"));
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
356 return;
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
357 }
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
358
24088
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
359 conn = connection_find(qd, source);
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
360 g_return_if_fail(conn != NULL);
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
361
23050
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
362 /* test code, not using tcp_rxqueue
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
363 memset(pkt,0, sizeof(pkt));
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
364 buf_len = read(qd->fd, pkt, sizeof(pkt));
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
365 if (buf_len > 2) {
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
366 packet_process(gc, pkt + 2, buf_len - 2);
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
367 }
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
368 return;
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
369 */
24088
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
370
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
371 buf_len = read(source, buf, sizeof(buf));
23050
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
372 if (buf_len < 0) {
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
373 if (errno == EAGAIN)
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
374 /* No worries */
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
375 return;
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
376
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
377 error_msg = g_strdup_printf(_("Lost connection with server:\n%d, %s"), errno, g_strerror(errno));
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
378 purple_connection_error_reason(gc, PURPLE_CONNECTION_ERROR_NETWORK_ERROR, error_msg);
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
379 g_free(error_msg);
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
380 return;
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
381 } else if (buf_len == 0) {
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
382 purple_connection_error_reason(gc, PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
383 _("Server closed the connection."));
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
384 return;
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
385 }
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
386
23561
bdb38a8bf721 20080717-05-1-fix-keep-alive ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23052
diff changeset
387 /* keep alive will be sent in 30 seconds since last_receive
bdb38a8bf721 20080717-05-1-fix-keep-alive ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23052
diff changeset
388 * QQ need a keep alive packet in every 60 seconds
bdb38a8bf721 20080717-05-1-fix-keep-alive ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23052
diff changeset
389 gc->last_received = time(NULL);
bdb38a8bf721 20080717-05-1-fix-keep-alive ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23052
diff changeset
390 */
24088
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
391 /* purple_debug_info("TCP_PENDING", "Read %d bytes, rxlen is %d\n", buf_len, conn->tcp_rxlen); */
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
392 conn->tcp_rxqueue = g_realloc(conn->tcp_rxqueue, buf_len + conn->tcp_rxlen);
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
393 memcpy(conn->tcp_rxqueue + conn->tcp_rxlen, buf, buf_len);
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
394 conn->tcp_rxlen += buf_len;
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
395
23050
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
396 pkt = g_newa(guint8, MAX_PACKET_SIZE);
24088
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
397 while (PURPLE_CONNECTION_IS_VALID(gc)) {
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
398 if (qd->openconns == NULL) {
23050
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
399 break;
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
400 }
24088
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
401 if (conn->tcp_rxqueue == NULL) {
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
402 conn->tcp_rxlen = 0;
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
403 break;
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
404 }
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
405 if (conn->tcp_rxlen < QQ_TCP_HEADER_LENGTH) {
23050
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
406 break;
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
407 }
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
408
24088
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
409 bytes = 0;
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
410 bytes += qq_get16(&pkt_len, conn->tcp_rxqueue + bytes);
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
411 if (conn->tcp_rxlen < pkt_len) {
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
412 break;
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
413 }
23050
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
414
24088
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
415 /* purple_debug_info("TCP_PENDING", "Packet len=%d, rxlen=%d\n", pkt_len, conn->tcp_rxlen); */
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
416 if ( pkt_len < QQ_TCP_HEADER_LENGTH
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
417 || *(conn->tcp_rxqueue + bytes) != QQ_PACKET_TAG
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
418 || *(conn->tcp_rxqueue + pkt_len - 1) != QQ_PACKET_TAIL) {
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
419 /* HEY! This isn't even a QQ. What are you trying to pull? */
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
420 purple_debug_warning("TCP_PENDING", "Packet error, no header or tail tag\n");
23050
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
421
24088
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
422 jump = memchr(conn->tcp_rxqueue + 1, QQ_PACKET_TAIL, conn->tcp_rxlen - 1);
23050
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
423 if ( !jump ) {
24088
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
424 purple_debug_warning("TCP_PENDING", "Failed to find next tail, clear receive buffer\n");
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
425 g_free(conn->tcp_rxqueue);
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
426 conn->tcp_rxqueue = NULL;
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
427 conn->tcp_rxlen = 0;
23050
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
428 return;
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
429 }
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
430
23051
55f986ccbb6a patch-05-reconnect-and-code-cleanup
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23050
diff changeset
431 /* jump and over QQ_PACKET_TAIL */
24088
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
432 jump_len = (jump - conn->tcp_rxqueue) + 1;
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
433 purple_debug_warning("TCP_PENDING", "Find next tail at %d, jump %d\n", jump_len, jump_len + 1);
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
434 g_memmove(conn->tcp_rxqueue, jump, conn->tcp_rxlen - jump_len);
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
435 conn->tcp_rxlen -= jump_len;
23050
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
436 continue;
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
437 }
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
438
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
439 memset(pkt, 0, MAX_PACKET_SIZE);
24088
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
440 g_memmove(pkt, conn->tcp_rxqueue + bytes, pkt_len - bytes);
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
441
23051
55f986ccbb6a patch-05-reconnect-and-code-cleanup
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23050
diff changeset
442 /* jump to next packet */
24088
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
443 conn->tcp_rxlen -= pkt_len;
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
444 if (conn->tcp_rxlen) {
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
445 /* purple_debug_info("TCP_PENDING", "shrink tcp_rxqueue to %d\n", conn->tcp_rxlen); */
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
446 jump = g_memdup(conn->tcp_rxqueue + pkt_len, conn->tcp_rxlen);
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
447 g_free(conn->tcp_rxqueue);
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
448 conn->tcp_rxqueue = jump;
23050
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
449 } else {
24088
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
450 /* purple_debug_info("TCP_PENDING", "free tcp_rxqueue\n"); */
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
451 g_free(conn->tcp_rxqueue);
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
452 conn->tcp_rxqueue = NULL;
23050
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
453 }
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
454
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
455 if (pkt == NULL) {
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
456 continue;
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
457 }
24088
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
458 /* packet_process may call disconnect and destory data like conn
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
459 * do not call packet_process before jump,
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
460 * break if packet_process return FALSE */
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
461 if (packet_process(gc, pkt, pkt_len - bytes) == FALSE) {
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
462 purple_debug_info("TCP_PENDING", "Connection has been destory\n");
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
463 break;
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
464 }
23050
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
465 }
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
466 }
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
467
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
468 static void udp_pending(gpointer data, gint source, PurpleInputCondition cond)
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
469 {
24088
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
470 PurpleConnection *gc = (PurpleConnection *) data;
23050
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
471 qq_data *qd;
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
472 guint8 *buf;
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
473 gint buf_len;
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
474
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
475 gc = (PurpleConnection *) data;
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
476 g_return_if_fail(gc != NULL && gc->proto_data != NULL);
24088
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
477 qd = (qq_data *) gc->proto_data;
23050
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
478
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
479 if(cond != PURPLE_INPUT_READ) {
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
480 purple_connection_error_reason(gc, PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
481 _("Socket error"));
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
482 return;
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
483 }
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
484
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
485 buf = g_newa(guint8, MAX_PACKET_SIZE);
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
486
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
487 /* here we have UDP proxy suppport */
24088
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
488 buf_len = read(source, buf, MAX_PACKET_SIZE);
23050
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
489 if (buf_len <= 0) {
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
490 purple_connection_error_reason(gc, PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
491 _("Unable to read from socket"));
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
492 return;
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
493 }
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
494
23561
bdb38a8bf721 20080717-05-1-fix-keep-alive ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23052
diff changeset
495 /* keep alive will be sent in 30 seconds since last_receive
bdb38a8bf721 20080717-05-1-fix-keep-alive ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23052
diff changeset
496 * QQ need a keep alive packet in every 60 seconds
bdb38a8bf721 20080717-05-1-fix-keep-alive ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23052
diff changeset
497 gc->last_received = time(NULL);
bdb38a8bf721 20080717-05-1-fix-keep-alive ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23052
diff changeset
498 */
23050
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
499
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
500 if (buf_len < QQ_UDP_HEADER_LENGTH) {
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
501 if (buf[0] != QQ_PACKET_TAG || buf[buf_len - 1] != QQ_PACKET_TAIL) {
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
502 qq_hex_dump(PURPLE_DEBUG_ERROR, "UDP_PENDING",
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
503 buf, buf_len,
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
504 "Received packet is too short, or no header and tail tag");
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
505 return;
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
506 }
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
507 }
24088
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
508
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
509 /* packet_process may call disconnect and destory data like conn
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
510 * do not call packet_process before jump,
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
511 * break if packet_process return FALSE */
23050
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
512 packet_process(gc, buf, buf_len);
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
513 }
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
514
24088
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
515 static gint udp_send_out(PurpleConnection *gc, guint8 *data, gint data_len)
23050
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
516 {
24088
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
517 qq_data *qd;
23050
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
518 gint ret;
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
519
24088
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
520 g_return_val_if_fail(data != NULL && data_len > 0, -1);
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
521
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
522 g_return_val_if_fail(gc != NULL && gc->proto_data != NULL, -1);
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
523 qd = (qq_data *) gc->proto_data;
23050
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
524
24088
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
525 #if 0
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
526 purple_debug_info("UDP_SEND_OUT", "Send %d bytes to socket %d\n", data_len, qd->fd);
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
527 #endif
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
528
23050
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
529 errno = 0;
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
530 ret = send(qd->fd, data, data_len, 0);
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
531 if (ret < 0 && errno == EAGAIN) {
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
532 return ret;
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
533 }
24088
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
534
23050
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
535 if (ret < 0) {
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
536 /* TODO: what to do here - do we really have to disconnect? */
24088
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
537 purple_debug_error("UDP_SEND_OUT", "Send failed: %d, %s\n", errno, g_strerror(errno));
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
538 purple_connection_error_reason(gc, PURPLE_CONNECTION_ERROR_NETWORK_ERROR, g_strerror(errno));
23050
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
539 }
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
540 return ret;
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
541 }
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
542
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
543 static void tcp_can_write(gpointer data, gint source, PurpleInputCondition cond)
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
544 {
24088
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
545 PurpleConnection *gc = (PurpleConnection *) data;
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
546 qq_data *qd;
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
547 qq_connection *conn;
23050
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
548 int ret, writelen;
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
549
24088
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
550 g_return_if_fail(gc != NULL && gc->proto_data != NULL);
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
551 qd = (qq_data *) gc->proto_data;
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
552
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
553 conn = connection_find(qd, source);
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
554 g_return_if_fail(conn != NULL);
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
555
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
556 writelen = purple_circ_buffer_get_max_read(conn->tcp_txbuf);
23050
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
557 if (writelen == 0) {
24088
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
558 purple_input_remove(conn->can_write_handler);
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
559 conn->can_write_handler = 0;
23050
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
560 return;
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
561 }
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
562
24088
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
563 ret = write(source, conn->tcp_txbuf->outptr, writelen);
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
564 purple_debug_info("TCP_CAN_WRITE", "total %d bytes is sent %d\n", writelen, ret);
23050
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
565
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
566 if (ret < 0 && errno == EAGAIN)
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
567 return;
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
568 else if (ret < 0) {
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
569 /* TODO: what to do here - do we really have to disconnect? */
24088
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
570 purple_connection_error_reason(gc, PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
23050
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
571 _("Write Error"));
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
572 return;
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
573 }
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
574
24088
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
575 purple_circ_buffer_mark_read(conn->tcp_txbuf, ret);
23050
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
576 }
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
577
24088
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
578 static gint tcp_send_out(PurpleConnection *gc, guint8 *data, gint data_len)
23050
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
579 {
24088
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
580 qq_data *qd;
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
581 qq_connection *conn;
23050
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
582 gint ret;
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
583
24088
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
584 g_return_val_if_fail(data != NULL && data_len > 0, -1);
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
585
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
586 g_return_val_if_fail(gc != NULL && gc->proto_data != NULL, -1);
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
587 qd = (qq_data *) gc->proto_data;
23050
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
588
24088
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
589 conn = connection_find(qd, qd->fd);
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
590 g_return_val_if_fail(conn, -1);
23050
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
591
24088
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
592 #if 0
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
593 purple_debug_info("TCP_SEND_OUT", "Send %d bytes to socket %d\n", data_len, qd->fd);
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
594 #endif
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
595
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
596 if (conn->can_write_handler == 0) {
23050
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
597 ret = write(qd->fd, data, data_len);
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
598 } else {
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
599 ret = -1;
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
600 errno = EAGAIN;
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
601 }
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
602
23638
1c50f12b1c52 2008.08.02 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23561
diff changeset
603 /*
24088
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
604 purple_debug_info("TCP_SEND_OUT",
23050
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
605 "Socket %d, total %d bytes is sent %d\n", qd->fd, data_len, ret);
23638
1c50f12b1c52 2008.08.02 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23561
diff changeset
606 */
23050
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
607 if (ret < 0 && errno == EAGAIN) {
23051
55f986ccbb6a patch-05-reconnect-and-code-cleanup
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23050
diff changeset
608 /* socket is busy, send later */
24088
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
609 purple_debug_info("TCP_SEND_OUT", "Socket is busy and send later\n");
23050
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
610 ret = 0;
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
611 } else if (ret <= 0) {
23051
55f986ccbb6a patch-05-reconnect-and-code-cleanup
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23050
diff changeset
612 /* TODO: what to do here - do we really have to disconnect? */
24088
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
613 purple_debug_error("TCP_SEND_OUT",
23050
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
614 "Send to socket %d failed: %d, %s\n", qd->fd, errno, g_strerror(errno));
24088
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
615 purple_connection_error_reason(gc, PURPLE_CONNECTION_ERROR_NETWORK_ERROR, g_strerror(errno));
23050
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
616 return ret;
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
617 }
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
618
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
619 if (ret < data_len) {
24088
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
620 purple_debug_info("TCP_SEND_OUT",
23050
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
621 "Add %d bytes to buffer\n", data_len - ret);
24088
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
622 if (conn->can_write_handler == 0) {
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
623 conn->can_write_handler = purple_input_add(qd->fd, PURPLE_INPUT_WRITE, tcp_can_write, gc);
23050
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
624 }
24088
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
625 purple_circ_buffer_append(conn->tcp_txbuf, data + ret, data_len - ret);
23050
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
626 }
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
627 return ret;
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
628 }
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
629
23638
1c50f12b1c52 2008.08.02 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23561
diff changeset
630 static gboolean network_timeout(gpointer data)
23050
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
631 {
23638
1c50f12b1c52 2008.08.02 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23561
diff changeset
632 PurpleConnection *gc = (PurpleConnection *) data;
23050
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
633 qq_data *qd;
23638
1c50f12b1c52 2008.08.02 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23561
diff changeset
634 gboolean is_lost_conn;
1c50f12b1c52 2008.08.02 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23561
diff changeset
635
23050
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
636 g_return_val_if_fail(gc != NULL && gc->proto_data != NULL, TRUE);
23638
1c50f12b1c52 2008.08.02 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23561
diff changeset
637 qd = (qq_data *) gc->proto_data;
23050
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
638
24088
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
639 is_lost_conn = qq_trans_scan(gc);
23638
1c50f12b1c52 2008.08.02 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23561
diff changeset
640 if (is_lost_conn) {
1c50f12b1c52 2008.08.02 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23561
diff changeset
641 purple_connection_error_reason(gc,
1c50f12b1c52 2008.08.02 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23561
diff changeset
642 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, _("Connection lost"));
1c50f12b1c52 2008.08.02 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23561
diff changeset
643 return TRUE;
1c50f12b1c52 2008.08.02 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23561
diff changeset
644 }
23050
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
645
24088
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
646 if ( !qd->is_login ) {
23638
1c50f12b1c52 2008.08.02 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23561
diff changeset
647 return TRUE;
1c50f12b1c52 2008.08.02 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23561
diff changeset
648 }
24088
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
649
23638
1c50f12b1c52 2008.08.02 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23561
diff changeset
650 qd->itv_count.keep_alive--;
1c50f12b1c52 2008.08.02 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23561
diff changeset
651 if (qd->itv_count.keep_alive <= 0) {
1c50f12b1c52 2008.08.02 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23561
diff changeset
652 qd->itv_count.keep_alive = qd->itv_config.keep_alive;
1c50f12b1c52 2008.08.02 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23561
diff changeset
653 qq_send_packet_keep_alive(gc);
1c50f12b1c52 2008.08.02 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23561
diff changeset
654 return TRUE;
1c50f12b1c52 2008.08.02 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23561
diff changeset
655 }
23050
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
656
23638
1c50f12b1c52 2008.08.02 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23561
diff changeset
657 if (qd->itv_config.update <= 0) {
1c50f12b1c52 2008.08.02 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23561
diff changeset
658 return TRUE;
1c50f12b1c52 2008.08.02 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23561
diff changeset
659 }
1c50f12b1c52 2008.08.02 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23561
diff changeset
660
1c50f12b1c52 2008.08.02 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23561
diff changeset
661 qd->itv_count.update--;
1c50f12b1c52 2008.08.02 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23561
diff changeset
662 if (qd->itv_count.update <= 0) {
1c50f12b1c52 2008.08.02 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23561
diff changeset
663 qd->itv_count.update = qd->itv_config.update;
24088
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
664 qq_update_online(gc, 0);
23638
1c50f12b1c52 2008.08.02 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23561
diff changeset
665 return TRUE;
23050
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
666 }
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
667
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
668 return TRUE; /* if return FALSE, timeout callback stops */
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
669 }
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
670
24088
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
671 static void do_request_token(PurpleConnection *gc)
23050
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
672 {
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
673 qq_data *qd;
23051
55f986ccbb6a patch-05-reconnect-and-code-cleanup
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23050
diff changeset
674 gchar *conn_msg;
23050
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
675 const gchar *passwd;
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
676
23051
55f986ccbb6a patch-05-reconnect-and-code-cleanup
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23050
diff changeset
677 /* _qq_show_socket("Got login socket", source); */
23050
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
678
24088
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
679 g_return_if_fail(gc != NULL && gc->proto_data != NULL);
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
680 qd = (qq_data *) gc->proto_data;
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
681
23050
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
682 /* QQ use random seq, to minimize duplicated packets */
24088
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
683 srand(time(NULL));
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
684 qd->send_seq = rand() & 0xffff;
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
685
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
686 qd->is_login = FALSE;
24090
6408be948d56 disapproval of revision '92d52eef2994d2697999177804e3665989cfa352'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24089
diff changeset
687 qd->is_finish_update = FALSE;
23050
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
688 qd->channel = 1;
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
689 qd->uid = strtol(purple_account_get_username(purple_connection_get_account(gc)), NULL, 10);
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
690
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
691 /* now generate md5 processed passwd */
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
692 passwd = purple_account_get_password(purple_connection_get_account(gc));
23638
1c50f12b1c52 2008.08.02 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23561
diff changeset
693
1c50f12b1c52 2008.08.02 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23561
diff changeset
694 /* use twice-md5 of user password as session key since QQ 2003iii */
1c50f12b1c52 2008.08.02 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23561
diff changeset
695 qq_get_md5(qd->password_twice_md5, sizeof(qd->password_twice_md5),
1c50f12b1c52 2008.08.02 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23561
diff changeset
696 (guint8 *)passwd, strlen(passwd));
1c50f12b1c52 2008.08.02 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23561
diff changeset
697 qq_get_md5(qd->password_twice_md5, sizeof(qd->password_twice_md5),
1c50f12b1c52 2008.08.02 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23561
diff changeset
698 qd->password_twice_md5, sizeof(qd->password_twice_md5));
1c50f12b1c52 2008.08.02 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23561
diff changeset
699
24088
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
700 g_return_if_fail(qd->network_watcher == 0);
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
701 qd->network_watcher = purple_timeout_add_seconds(qd->itv_config.resend, network_timeout, gc);
23050
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
702
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
703 /* Update the login progress status display */
24088
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
704 conn_msg = g_strdup_printf(_("Request token"));
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
705 purple_connection_update_progress(gc, conn_msg, 2, QQ_CONNECT_STEPS);
23051
55f986ccbb6a patch-05-reconnect-and-code-cleanup
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23050
diff changeset
706 g_free(conn_msg);
23050
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
707
23638
1c50f12b1c52 2008.08.02 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23561
diff changeset
708 qq_send_packet_token(gc);
23050
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
709 }
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
710
24088
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
711 /* the callback function after socket is built
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
712 * we setup the qq protocol related configuration here */
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
713 static void connect_cb(gpointer data, gint source, const gchar *error_message)
23050
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
714 {
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
715 PurpleConnection *gc;
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
716 qq_data *qd;
24088
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
717 PurpleAccount *account ;
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
718 qq_connection *conn;
23050
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
719
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
720 gc = (PurpleConnection *) data;
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
721 g_return_if_fail(gc != NULL && gc->proto_data != NULL);
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
722
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
723 qd = (qq_data *) gc->proto_data;
24088
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
724 account = purple_connection_get_account(gc);
23050
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
725
24088
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
726 /* conn_data will be destoryed */
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
727 qd->conn_data = NULL;
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
728
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
729 if (!PURPLE_CONNECTION_IS_VALID(gc)) {
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
730 purple_debug_info("QQ_CONN", "Invalid connection\n");
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
731 close(source);
23050
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
732 return;
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
733 }
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
734
24088
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
735 if (source < 0) { /* socket returns -1 */
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
736 purple_debug_info("QQ_CONN",
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
737 "Could not establish a connection with the server:\n%s\n",
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
738 error_message);
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
739 if (qd->connect_watcher > 0) purple_timeout_remove(qd->connect_watcher);
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
740 qd->connect_watcher = purple_timeout_add_seconds(QQ_CONNECT_INTERVAL, qq_connect_later, gc);
23050
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
741 return;
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
742 }
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
743
24088
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
744 /* _qq_show_socket("Got login socket", source); */
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
745 qd->fd = source;
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
746 conn = connection_create(qd, source);
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
747 if (qd->use_tcp) {
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
748 conn->input_handler = purple_input_add(source, PURPLE_INPUT_READ, tcp_pending, gc);
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
749 } else {
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
750 conn->input_handler = purple_input_add(source, PURPLE_INPUT_READ, udp_pending, gc);
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
751 }
23050
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
752
24088
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
753 do_request_token( gc );
23050
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
754 }
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
755
24088
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
756 gboolean connect_to_server(PurpleConnection *gc, gchar *server, gint port)
23050
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
757 {
24088
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
758 PurpleAccount *account ;
23050
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
759 qq_data *qd;
23051
55f986ccbb6a patch-05-reconnect-and-code-cleanup
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23050
diff changeset
760 gchar *conn_msg;
23050
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
761
24088
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
762 g_return_val_if_fail(gc != NULL && gc->proto_data != NULL, FALSE);
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
763 account = purple_connection_get_account(gc);
23050
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
764 qd = (qq_data *) gc->proto_data;
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
765
24088
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
766 if (server == NULL || strlen(server) == 0 || port == 0) {
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
767 purple_connection_error_reason(gc, PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
768 _("Invalid server or port"));
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
769 return FALSE;
23051
55f986ccbb6a patch-05-reconnect-and-code-cleanup
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23050
diff changeset
770 }
55f986ccbb6a patch-05-reconnect-and-code-cleanup
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23050
diff changeset
771
24088
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
772 conn_msg = g_strdup_printf( _("Connecting server %s, retries %d"), server, port);
23051
55f986ccbb6a patch-05-reconnect-and-code-cleanup
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23050
diff changeset
773 purple_connection_update_progress(gc, conn_msg, 1, QQ_CONNECT_STEPS);
55f986ccbb6a patch-05-reconnect-and-code-cleanup
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23050
diff changeset
774 g_free(conn_msg);
55f986ccbb6a patch-05-reconnect-and-code-cleanup
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23050
diff changeset
775
24088
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
776 purple_debug_info("QQ", "Connect to %s:%d\n", server, port);
23050
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
777
24088
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
778 if (qd->conn_data != NULL) {
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
779 purple_proxy_connect_cancel(qd->conn_data);
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
780 qd->conn_data = NULL;
23050
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
781 }
24090
6408be948d56 disapproval of revision '92d52eef2994d2697999177804e3665989cfa352'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24089
diff changeset
782 qd->conn_data = purple_proxy_connect(gc, account, server, port, connect_cb, gc);
24088
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
783 if ( qd->conn_data == NULL ) {
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
784 purple_debug_error("QQ", _("Couldn't create socket"));
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
785 return FALSE;
23050
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
786 }
24088
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
787 return TRUE;
23050
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
788 }
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
789
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
790 /* clean up qq_data structure and all its components
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
791 * always used before a redirectly connection */
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
792 void qq_disconnect(PurpleConnection *gc)
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
793 {
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
794 qq_data *qd;
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
795
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
796 g_return_if_fail(gc != NULL && gc->proto_data != NULL);
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
797 qd = (qq_data *) gc->proto_data;
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
798
24088
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
799 purple_debug_info("QQ", "Disconnecting ...\n");
23638
1c50f12b1c52 2008.08.02 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23561
diff changeset
800
24088
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
801 if (qd->network_watcher > 0) {
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
802 purple_debug_info("QQ", "Remove network watcher\n");
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
803 purple_timeout_remove(qd->network_watcher);
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
804 qd->network_watcher = 0;
23638
1c50f12b1c52 2008.08.02 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23561
diff changeset
805 }
1c50f12b1c52 2008.08.02 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23561
diff changeset
806
23050
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
807 /* finish all I/O */
24088
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
808 if (qd->fd >= 0 && qd->is_login) {
23050
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
809 qq_send_packet_logout(gc);
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
810 }
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
811
24088
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
812 /* not connected */
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
813 if (qd->conn_data != NULL) {
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
814 purple_debug_info("QQ", "Connect cancel\n");
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
815 purple_proxy_connect_cancel(qd->conn_data);
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
816 qd->conn_data = NULL;
23050
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
817 }
24088
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
818 connection_free_all(qd);
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
819 qd->fd = -1;
23050
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
820
24088
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
821 qq_trans_remove_all(gc);
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
822
23638
1c50f12b1c52 2008.08.02 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23561
diff changeset
823 if (qd->token) {
24088
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
824 purple_debug_info("QQ", "free token\n");
23638
1c50f12b1c52 2008.08.02 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23561
diff changeset
825 g_free(qd->token);
1c50f12b1c52 2008.08.02 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23561
diff changeset
826 qd->token = NULL;
1c50f12b1c52 2008.08.02 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23561
diff changeset
827 qd->token_len = 0;
23050
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
828 }
23638
1c50f12b1c52 2008.08.02 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23561
diff changeset
829 memset(qd->inikey, 0, sizeof(qd->inikey));
1c50f12b1c52 2008.08.02 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23561
diff changeset
830 memset(qd->password_twice_md5, 0, sizeof(qd->password_twice_md5));
1c50f12b1c52 2008.08.02 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23561
diff changeset
831 memset(qd->session_key, 0, sizeof(qd->session_key));
1c50f12b1c52 2008.08.02 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23561
diff changeset
832 memset(qd->session_md5, 0, sizeof(qd->session_md5));
1c50f12b1c52 2008.08.02 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23561
diff changeset
833
1c50f12b1c52 2008.08.02 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23561
diff changeset
834 qd->my_ip.s_addr = 0;
23050
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
835
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
836 qq_group_free_all(qd);
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
837 qq_add_buddy_request_free(qd);
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
838 qq_info_query_free(qd);
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
839 qq_buddies_list_free(gc->account, qd);
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
840 }
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
841
24088
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
842 static gint packet_encap(qq_data *qd, guint8 *buf, gint maxlen, guint16 cmd, guint16 seq,
23050
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
843 guint8 *data, gint data_len)
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
844 {
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
845 gint bytes = 0;
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
846 g_return_val_if_fail(qd != NULL && buf != NULL && maxlen > 0, -1);
23695
5f454b975a99 2008.08.10 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23638
diff changeset
847 g_return_val_if_fail(data != NULL && data_len > 0, -1);
24088
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
848
23050
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
849 /* QQ TCP packet has two bytes in the begining defines packet length
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
850 * so leave room here to store packet size */
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
851 if (qd->use_tcp) {
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
852 bytes += qq_put16(buf + bytes, 0x0000);
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
853 }
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
854 /* now comes the normal QQ packet as UDP */
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
855 bytes += qq_put8(buf + bytes, QQ_PACKET_TAG);
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
856 bytes += qq_put16(buf + bytes, QQ_CLIENT);
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
857 bytes += qq_put16(buf + bytes, cmd);
24088
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
858
23050
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
859 bytes += qq_put16(buf + bytes, seq);
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
860
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
861 bytes += qq_put32(buf + bytes, qd->uid);
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
862 bytes += qq_putdata(buf + bytes, data, data_len);
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
863 bytes += qq_put8(buf + bytes, QQ_PACKET_TAIL);
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
864
23051
55f986ccbb6a patch-05-reconnect-and-code-cleanup
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23050
diff changeset
865 /* set TCP packet length at begin of the packet */
23050
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
866 if (qd->use_tcp) {
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
867 qq_put16(buf, bytes);
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
868 }
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
869
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
870 return bytes;
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
871 }
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
872
23638
1c50f12b1c52 2008.08.02 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23561
diff changeset
873 /* data has been encrypted before */
24088
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
874 static gint packet_send_out(PurpleConnection *gc, guint16 cmd, guint16 seq, guint8 *data, gint data_len)
23050
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
875 {
24088
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
876 qq_data *qd;
23050
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
877 guint8 *buf;
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
878 gint buf_len;
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
879 gint bytes_sent;
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
880
24088
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
881 g_return_val_if_fail(gc != NULL && gc->proto_data != NULL, -1);
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
882 qd = (qq_data *)gc->proto_data;
23051
55f986ccbb6a patch-05-reconnect-and-code-cleanup
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23050
diff changeset
883 g_return_val_if_fail(data != NULL && data_len > 0, -1);
55f986ccbb6a patch-05-reconnect-and-code-cleanup
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23050
diff changeset
884
23050
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
885 buf = g_newa(guint8, MAX_PACKET_SIZE);
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
886 memset(buf, 0, MAX_PACKET_SIZE);
24088
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
887 buf_len = packet_encap(qd, buf, MAX_PACKET_SIZE, cmd, seq, data, data_len);
23050
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
888 if (buf_len <= 0) {
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
889 return -1;
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
890 }
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
891
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
892 if (qd->use_tcp) {
24088
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
893 bytes_sent = tcp_send_out(gc, buf, buf_len);
23050
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
894 } else {
24088
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
895 bytes_sent = udp_send_out(gc, buf, buf_len);
23050
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
896 }
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
897
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
898 return bytes_sent;
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
899 }
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
900
24088
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
901 gint qq_send_cmd_encrypted(PurpleConnection *gc, guint16 cmd, guint16 seq,
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
902 guint8 *data, gint data_len, gboolean need_ack)
23050
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
903 {
24088
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
904 gint send_len;
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
905
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
906 #if 1
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
907 purple_debug_info("QQ", "<== [%05d], %s(0x%04X), datalen %d\n",
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
908 seq, qq_get_cmd_desc(cmd), cmd, data_len);
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
909 #endif
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
910
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
911 send_len = packet_send_out(gc, cmd, seq, data, data_len);
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
912 if (need_ack) {
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
913 qq_trans_add_client_cmd(gc, cmd, seq, data, data_len, 0, 0);
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
914 }
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
915 return send_len;
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
916 }
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
917
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
918 /* Encrypt data with session_key, and send packet out */
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
919 static gint send_cmd_detail(PurpleConnection *gc, guint16 cmd, guint16 seq,
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
920 guint8 *data, gint data_len, gboolean need_ack, gint update_class, guint32 ship32)
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
921 {
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
922 qq_data *qd;
23050
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
923 guint8 *encrypted_data;
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
924 gint encrypted_len;
24088
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
925 gint bytes_sent;
23050
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
926
24088
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
927 g_return_val_if_fail(gc != NULL && gc->proto_data != NULL, -1);
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
928 qd = (qq_data *)gc->proto_data;
23051
55f986ccbb6a patch-05-reconnect-and-code-cleanup
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23050
diff changeset
929 g_return_val_if_fail(data != NULL && data_len > 0, -1);
23050
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
930
23695
5f454b975a99 2008.08.10 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23638
diff changeset
931 /* at most 16 bytes more */
5f454b975a99 2008.08.10 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23638
diff changeset
932 encrypted_data = g_newa(guint8, data_len + 16);
5f454b975a99 2008.08.10 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23638
diff changeset
933 encrypted_len = qq_encrypt(encrypted_data, data, data_len, qd->session_key);
5f454b975a99 2008.08.10 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23638
diff changeset
934 if (encrypted_len < 16) {
24088
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
935 purple_debug_error("QQ_ENCRYPT", "Error len %d: [%05d] 0x%04X %s\n",
23695
5f454b975a99 2008.08.10 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23638
diff changeset
936 encrypted_len, seq, cmd, qq_get_cmd_desc(cmd));
5f454b975a99 2008.08.10 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23638
diff changeset
937 return -1;
5f454b975a99 2008.08.10 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23638
diff changeset
938 }
23050
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
939
24088
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
940 bytes_sent = packet_send_out(gc, cmd, seq, encrypted_data, encrypted_len);
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
941
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
942 if (need_ack) {
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
943 qq_trans_add_client_cmd(gc, cmd, seq, encrypted_data, encrypted_len, update_class, ship32);
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
944 }
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
945 return bytes_sent;
23050
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
946 }
23051
55f986ccbb6a patch-05-reconnect-and-code-cleanup
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23050
diff changeset
947
24088
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
948 gint qq_send_cmd_mess(PurpleConnection *gc, guint16 cmd, guint8 *data, gint data_len,
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
949 gint update_class, guint32 ship32)
23051
55f986ccbb6a patch-05-reconnect-and-code-cleanup
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23050
diff changeset
950 {
24088
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
951 qq_data *qd;
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
952 guint16 seq;
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
953
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
954 g_return_val_if_fail(gc != NULL && gc->proto_data != NULL, -1);
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
955 qd = (qq_data *) gc->proto_data;
23051
55f986ccbb6a patch-05-reconnect-and-code-cleanup
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23050
diff changeset
956 g_return_val_if_fail(data != NULL && data_len > 0, -1);
55f986ccbb6a patch-05-reconnect-and-code-cleanup
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23050
diff changeset
957
24088
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
958 seq = ++qd->send_seq;
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
959 #if 1
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
960 purple_debug_info("QQ", "<== [%05d], %s(0x%04X), datalen %d\n",
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
961 seq, qq_get_cmd_desc(cmd), cmd, data_len);
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
962 #endif
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
963 return send_cmd_detail(gc, cmd, seq, data, data_len, TRUE, update_class, ship32);
23051
55f986ccbb6a patch-05-reconnect-and-code-cleanup
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23050
diff changeset
964 }
23695
5f454b975a99 2008.08.10 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23638
diff changeset
965
24088
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
966 /* set seq and need_ack, then call send_cmd_detail */
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
967 gint qq_send_cmd(PurpleConnection *gc, guint16 cmd, guint8 *data, gint data_len)
23695
5f454b975a99 2008.08.10 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23638
diff changeset
968 {
24088
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
969 qq_data *qd;
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
970 guint16 seq;
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
971 gboolean need_ack;
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
972
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
973 g_return_val_if_fail(gc != NULL && gc->proto_data != NULL, -1);
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
974 qd = (qq_data *) gc->proto_data;
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
975 g_return_val_if_fail(data != NULL && data_len > 0, -1);
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
976
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
977 if (cmd != QQ_CMD_LOGOUT) {
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
978 seq = ++qd->send_seq;
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
979 need_ack = TRUE;
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
980 } else {
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
981 seq = 0xFFFF;
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
982 need_ack = FALSE;
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
983 }
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
984 #if 1
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
985 purple_debug_info("QQ", "<== [%05d], %s(0x%04X), datalen %d\n",
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
986 seq, qq_get_cmd_desc(cmd), cmd, data_len);
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
987 #endif
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
988 return send_cmd_detail(gc, cmd, seq, data, data_len, need_ack, 0, 0);
23695
5f454b975a99 2008.08.10 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23638
diff changeset
989 }
5f454b975a99 2008.08.10 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23638
diff changeset
990
24088
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
991 /* set seq and need_ack, then call send_cmd_detail */
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
992 gint qq_send_server_reply(PurpleConnection *gc, guint16 cmd, guint16 seq, guint8 *data, gint data_len)
23695
5f454b975a99 2008.08.10 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23638
diff changeset
993 {
24088
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
994 #if 1
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
995 purple_debug_info("QQ", "<== [SRV-%05d], %s(0x%04X), datalen %d\n",
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
996 seq, qq_get_cmd_desc(cmd), cmd, data_len);
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
997 #endif
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
998 return send_cmd_detail(gc, cmd, seq, data, data_len, FALSE, 0, 0);
23695
5f454b975a99 2008.08.10 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23638
diff changeset
999 }
5f454b975a99 2008.08.10 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23638
diff changeset
1000
24088
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
1001 static gint send_room_cmd(PurpleConnection *gc, guint8 room_cmd, guint32 room_id,
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
1002 guint8 *data, gint data_len, gint update_class, guint32 ship32)
23695
5f454b975a99 2008.08.10 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23638
diff changeset
1003 {
5f454b975a99 2008.08.10 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23638
diff changeset
1004 qq_data *qd;
5f454b975a99 2008.08.10 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23638
diff changeset
1005 guint8 *buf;
5f454b975a99 2008.08.10 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23638
diff changeset
1006 gint buf_len;
5f454b975a99 2008.08.10 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23638
diff changeset
1007 guint8 *encrypted_data;
5f454b975a99 2008.08.10 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23638
diff changeset
1008 gint encrypted_len;
5f454b975a99 2008.08.10 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23638
diff changeset
1009 gint bytes_sent;
5f454b975a99 2008.08.10 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23638
diff changeset
1010 guint16 seq;
24088
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
1011
23695
5f454b975a99 2008.08.10 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23638
diff changeset
1012 g_return_val_if_fail(gc != NULL && gc->proto_data != NULL, -1);
5f454b975a99 2008.08.10 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23638
diff changeset
1013 qd = (qq_data *) gc->proto_data;
5f454b975a99 2008.08.10 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23638
diff changeset
1014
5f454b975a99 2008.08.10 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23638
diff changeset
1015 buf = g_newa(guint8, MAX_PACKET_SIZE);
5f454b975a99 2008.08.10 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23638
diff changeset
1016 memset(buf, 0, MAX_PACKET_SIZE);
5f454b975a99 2008.08.10 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23638
diff changeset
1017
5f454b975a99 2008.08.10 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23638
diff changeset
1018 /* encap room_cmd and room id to buf*/
5f454b975a99 2008.08.10 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23638
diff changeset
1019 buf_len = 0;
5f454b975a99 2008.08.10 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23638
diff changeset
1020 buf_len += qq_put8(buf + buf_len, room_cmd);
5f454b975a99 2008.08.10 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23638
diff changeset
1021 if (room_id != 0) {
5f454b975a99 2008.08.10 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23638
diff changeset
1022 /* id 0 is for QQ Demo Group, now there are not existed*/
5f454b975a99 2008.08.10 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23638
diff changeset
1023 buf_len += qq_put32(buf + buf_len, room_id);
5f454b975a99 2008.08.10 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23638
diff changeset
1024 }
5f454b975a99 2008.08.10 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23638
diff changeset
1025 if (data != NULL && data_len > 0) {
5f454b975a99 2008.08.10 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23638
diff changeset
1026 buf_len += qq_putdata(buf + buf_len, data, data_len);
5f454b975a99 2008.08.10 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23638
diff changeset
1027 }
24088
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
1028
23695
5f454b975a99 2008.08.10 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23638
diff changeset
1029 qd->send_seq++;
5f454b975a99 2008.08.10 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23638
diff changeset
1030 seq = qd->send_seq;
5f454b975a99 2008.08.10 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23638
diff changeset
1031
5f454b975a99 2008.08.10 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23638
diff changeset
1032 /* Encrypt to encrypted_data with session_key */
5f454b975a99 2008.08.10 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23638
diff changeset
1033 /* at most 16 bytes more */
5f454b975a99 2008.08.10 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23638
diff changeset
1034 encrypted_data = g_newa(guint8, buf_len + 16);
5f454b975a99 2008.08.10 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23638
diff changeset
1035 encrypted_len = qq_encrypt(encrypted_data, buf, buf_len, qd->session_key);
5f454b975a99 2008.08.10 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23638
diff changeset
1036 if (encrypted_len < 16) {
24088
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
1037 purple_debug_error("QQ_ENCRYPT", "Error len %d: [%05d] %s (0x%02X)\n",
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
1038 encrypted_len, seq, qq_get_room_cmd_desc(room_cmd), room_cmd);
23695
5f454b975a99 2008.08.10 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23638
diff changeset
1039 return -1;
5f454b975a99 2008.08.10 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23638
diff changeset
1040 }
5f454b975a99 2008.08.10 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23638
diff changeset
1041
24088
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
1042 bytes_sent = packet_send_out(gc, QQ_CMD_ROOM, seq, encrypted_data, encrypted_len);
23695
5f454b975a99 2008.08.10 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23638
diff changeset
1043 #if 1
5f454b975a99 2008.08.10 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23638
diff changeset
1044 /* qq_show_packet("QQ_SEND_DATA", buf, buf_len); */
24088
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
1045 purple_debug_info("QQ",
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
1046 "<== [%05d], %s (0x%02X) to room %d, datalen %d\n",
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
1047 seq, qq_get_room_cmd_desc(room_cmd), room_cmd, room_id, buf_len);
23695
5f454b975a99 2008.08.10 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23638
diff changeset
1048 #endif
24088
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
1049
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
1050 qq_trans_add_room_cmd(gc, seq, room_cmd, room_id, buf, buf_len, update_class, ship32);
23695
5f454b975a99 2008.08.10 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23638
diff changeset
1051 return bytes_sent;
5f454b975a99 2008.08.10 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23638
diff changeset
1052 }
24088
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
1053
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
1054 gint qq_send_room_cmd_mess(PurpleConnection *gc, guint8 room_cmd, guint32 room_id,
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
1055 guint8 *data, gint data_len, gint update_class, guint32 ship32)
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
1056 {
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
1057 return send_room_cmd(gc, room_cmd, room_id, data, data_len, update_class, ship32);
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
1058 }
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
1059
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
1060 gint qq_send_room_cmd(PurpleConnection *gc, guint8 room_cmd, guint32 room_id,
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
1061 guint8 *data, gint data_len)
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
1062 {
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
1063 return send_room_cmd(gc, room_cmd, room_id, data, data_len, 0, 0);
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
1064 }
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
1065
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
1066 gint qq_send_room_cmd_noid(PurpleConnection *gc, guint8 room_cmd,
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
1067 guint8 *data, gint data_len)
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
1068 {
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
1069 return send_room_cmd(gc, room_cmd, 0, data, data_len, 0, 0);
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
1070 }
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
1071
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
1072 gint qq_send_room_cmd_only(PurpleConnection *gc, guint8 room_cmd, guint32 room_id)
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
1073 {
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
1074 g_return_val_if_fail(room_cmd > 0 && room_id > 0, -1);
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
1075 return send_room_cmd(gc, room_cmd, room_id, NULL, 0, 0, 0);
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23712
diff changeset
1076 }