annotate libpurple/protocols/qq/qq_network.c @ 27243:7054f810b0f9

Check in code that connects to oscar using clientLogin. This is the authentication scheme they've publically documented. We still use the old MD5-style login as the default, but you can optionally try this out by checking a check box on the advanced tab of your oscar account. Functionally everything is supposed to be the same. However, for some reason users with Mobile IM forwarding turned on don't show up online and can't be messaged. Not sure why. Using clientLogin DOES make it easier for AOL to track us. And yes, it probably makes it easier for AOL to block us, too. But I don't believe they want to do that. I believe they're trying to keep their network open, and I think we should appreciate that and try to work with them. We're not just some small open source project that slips under the radar unnoticed anymore. It's good to have options, right? None of this code was taken from anywhere (outside of libpurple). I wrote it all from scratch (and took a few bits from other places in libpurple). I did use the documentation on http://dev.aol.com/aim , but I don't believe that affects us from a licensing standpoint in any way. If you disagree we should talk about it on the devel mailing list.
author Mark Doliner <mark@kingant.net>
date Tue, 23 Jun 2009 18:20:12 +0000
parents 7da3cf2530b7
children f541583e31bd
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
23052
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"
23683
1c50f12b1c52 2008.08.02 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23606
diff changeset
30 #include "group_info.h"
24088
1ee91ff0d5fe 2008.10.09 - ccpaging <ccpaging(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24085
diff changeset
31 #include "group_internal.h"
23753
5f454b975a99 2008.08.10 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23683
diff changeset
32 #include "qq_crypt.h"
24065
bdfcfd71449c patch 20080922 from ccpaging <ccpaging(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24048
diff changeset
33 #include "qq_define.h"
23683
1c50f12b1c52 2008.08.02 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23606
diff changeset
34 #include "qq_base.h"
1c50f12b1c52 2008.08.02 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23606
diff changeset
35 #include "buddy_list.h"
23052
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"
23053
55f986ccbb6a patch-05-reconnect-and-code-cleanup
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23052
diff changeset
38 #include "qq_trans.h"
23052
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
39 #include "utils.h"
23683
1c50f12b1c52 2008.08.02 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23606
diff changeset
40 #include "qq_process.h"
23052
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
41
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
42 #define QQ_DEFAULT_PORT 8000
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
43
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
44 /* set QQ_CONNECT_MAX to 1, when test reconnecting */
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
45 #define QQ_CONNECT_MAX 3
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
46 #define QQ_CONNECT_INTERVAL 2
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
47 #define QQ_CONNECT_CHECK 5
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
48 #define QQ_KEEP_ALIVE_INTERVAL 60
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
49 #define QQ_TRANS_INTERVAL 10
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
50
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
51 gboolean connect_to_server(PurpleConnection *gc, gchar *server, gint port);
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
52
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
53 static qq_connection *connection_find(qq_data *qd, int fd) {
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
54 qq_connection *ret = NULL;
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
55 GSList *entry = qd->openconns;
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
56 while(entry) {
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
57 ret = entry->data;
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
58 if(ret->fd == fd) return ret;
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
59 entry = entry->next;
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
60 }
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
61 return NULL;
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
62 }
23053
55f986ccbb6a patch-05-reconnect-and-code-cleanup
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23052
diff changeset
63
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
64 static qq_connection *connection_create(qq_data *qd, int fd) {
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
65 qq_connection *ret = g_new0(qq_connection, 1);
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
66 ret->fd = fd;
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
67 qd->openconns = g_slist_append(qd->openconns, ret);
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
68 return ret;
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
69 }
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
70
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
71 static void connection_remove(qq_data *qd, int fd) {
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
72 qq_connection *conn = connection_find(qd, fd);
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
73 qd->openconns = g_slist_remove(qd->openconns, conn);
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
74
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
75 g_return_if_fail( conn != NULL );
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
76
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
77 purple_debug_info("QQ", "Close socket %d\n", conn->fd);
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
78 if(conn->input_handler > 0) purple_input_remove(conn->input_handler);
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
79 if(conn->can_write_handler > 0) purple_input_remove(conn->can_write_handler);
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
80
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
81 if (conn->fd >= 0) close(conn->fd);
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
82 if(conn->tcp_txbuf != NULL) purple_circ_buffer_destroy(conn->tcp_txbuf);
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
83 if (conn->tcp_rxqueue != NULL) g_free(conn->tcp_rxqueue);
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
84
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
85 g_free(conn);
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
86 }
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
87
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
88 static void connection_free_all(qq_data *qd) {
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
89 qq_connection *ret = NULL;
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
90 GSList *entry = qd->openconns;
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
91 while(entry) {
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
92 ret = entry->data;
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
93 connection_remove(qd, ret->fd);
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
94 entry = qd->openconns;
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
95 }
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
96 }
23053
55f986ccbb6a patch-05-reconnect-and-code-cleanup
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23052
diff changeset
97 static gboolean set_new_server(qq_data *qd)
55f986ccbb6a patch-05-reconnect-and-code-cleanup
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23052
diff changeset
98 {
55f986ccbb6a patch-05-reconnect-and-code-cleanup
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23052
diff changeset
99 gint count;
55f986ccbb6a patch-05-reconnect-and-code-cleanup
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23052
diff changeset
100 gint index;
55f986ccbb6a patch-05-reconnect-and-code-cleanup
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23052
diff changeset
101 GList *it = NULL;
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
102
23053
55f986ccbb6a patch-05-reconnect-and-code-cleanup
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23052
diff changeset
103 g_return_val_if_fail(qd != NULL, FALSE);
55f986ccbb6a patch-05-reconnect-and-code-cleanup
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23052
diff changeset
104
55f986ccbb6a patch-05-reconnect-and-code-cleanup
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23052
diff changeset
105 if (qd->servers == NULL) {
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
106 purple_debug_info("QQ", "Server list is NULL\n");
23053
55f986ccbb6a patch-05-reconnect-and-code-cleanup
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23052
diff changeset
107 return FALSE;
55f986ccbb6a patch-05-reconnect-and-code-cleanup
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23052
diff changeset
108 }
55f986ccbb6a patch-05-reconnect-and-code-cleanup
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23052
diff changeset
109
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
110 /* remove server used before */
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
111 if (qd->curr_server != NULL) {
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
112 purple_debug_info("QQ",
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
113 "Remove current [%s] from server list\n", qd->curr_server);
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
114 qd->servers = g_list_remove(qd->servers, qd->curr_server);
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
115 qd->curr_server = NULL;
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
116 }
24026
25f62d21b3f8 disapproval of revision '8cebefbc6cd5d84acb69c74e69e8821f11dd225d'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24019
diff changeset
117
23053
55f986ccbb6a patch-05-reconnect-and-code-cleanup
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23052
diff changeset
118 count = g_list_length(qd->servers);
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
119 purple_debug_info("QQ", "Server list has %d\n", count);
23053
55f986ccbb6a patch-05-reconnect-and-code-cleanup
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23052
diff changeset
120 if (count <= 0) {
55f986ccbb6a patch-05-reconnect-and-code-cleanup
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23052
diff changeset
121 /* no server left, disconnect when result is false */
55f986ccbb6a patch-05-reconnect-and-code-cleanup
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23052
diff changeset
122 qd->servers = NULL;
55f986ccbb6a patch-05-reconnect-and-code-cleanup
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23052
diff changeset
123 return FALSE;
55f986ccbb6a patch-05-reconnect-and-code-cleanup
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23052
diff changeset
124 }
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
125
23053
55f986ccbb6a patch-05-reconnect-and-code-cleanup
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23052
diff changeset
126 /* get new server */
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
127 index = rand() % count;
23053
55f986ccbb6a patch-05-reconnect-and-code-cleanup
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23052
diff changeset
128 it = g_list_nth(qd->servers, index);
24496
cd70713a996d Whitespace fix
Richard Laager <rlaager@wiktel.com>
parents: 24374
diff changeset
129 qd->curr_server = it->data; /* do not free server_name */
cd70713a996d Whitespace fix
Richard Laager <rlaager@wiktel.com>
parents: 24374
diff changeset
130 if (qd->curr_server == NULL || strlen(qd->curr_server) <= 0 ) {
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
131 purple_debug_info("QQ", "Server name at %d is empty\n", index);
23053
55f986ccbb6a patch-05-reconnect-and-code-cleanup
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23052
diff changeset
132 return FALSE;
55f986ccbb6a patch-05-reconnect-and-code-cleanup
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23052
diff changeset
133 }
55f986ccbb6a patch-05-reconnect-and-code-cleanup
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23052
diff changeset
134
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
135 purple_debug_info("QQ", "set new server to %s\n", qd->curr_server);
23053
55f986ccbb6a patch-05-reconnect-and-code-cleanup
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23052
diff changeset
136 return TRUE;
55f986ccbb6a patch-05-reconnect-and-code-cleanup
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23052
diff changeset
137 }
23052
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
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
150 static gboolean connect_check(gpointer data)
23053
55f986ccbb6a patch-05-reconnect-and-code-cleanup
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23052
diff changeset
151 {
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
152 PurpleConnection *gc = (PurpleConnection *) data;
23053
55f986ccbb6a patch-05-reconnect-and-code-cleanup
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23052
diff changeset
153 qq_data *qd;
55f986ccbb6a patch-05-reconnect-and-code-cleanup
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23052
diff changeset
154
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
155 g_return_val_if_fail(gc != NULL && gc->proto_data != NULL, FALSE);
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
156 qd = (qq_data *) gc->proto_data;
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
157
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
158 if (qd->connect_watcher > 0) {
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
159 purple_timeout_remove(qd->connect_watcher);
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
160 qd->connect_watcher = 0;
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
161 }
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
162
24065
bdfcfd71449c patch 20080922 from ccpaging <ccpaging(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24048
diff changeset
163 if (qd->fd >= 0 && qd->ld.token != NULL && qd->ld.token_len > 0) {
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
164 purple_debug_info("QQ", "Connect ok\n");
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
165 return FALSE;
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
166 }
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
167
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
168 qd->connect_watcher = purple_timeout_add_seconds(0, qq_connect_later, gc);
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
169 return FALSE;
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
170 }
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
171
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
172 /* Warning: qq_connect_later destory all connection
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
173 * Any function should be care of use qq_data after call this function
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
174 * Please conside tcp_pending and udp_pending */
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
175 gboolean qq_connect_later(gpointer data)
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
176 {
24873
115a2e9ea8b3 2008.12.28 - flos <lonicerae(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24839
diff changeset
177 PurpleConnection *gc;
115a2e9ea8b3 2008.12.28 - flos <lonicerae(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24839
diff changeset
178 char *tmp_server;
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
179 int port;
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
180 gchar **segments;
24873
115a2e9ea8b3 2008.12.28 - flos <lonicerae(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24839
diff changeset
181 qq_data *qd;
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
182
24873
115a2e9ea8b3 2008.12.28 - flos <lonicerae(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24839
diff changeset
183 gc = (PurpleConnection *) data;
23053
55f986ccbb6a patch-05-reconnect-and-code-cleanup
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23052
diff changeset
184 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: 23052
diff changeset
185 qd = (qq_data *) gc->proto_data;
24873
115a2e9ea8b3 2008.12.28 - flos <lonicerae(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24839
diff changeset
186 tmp_server = NULL;
23053
55f986ccbb6a patch-05-reconnect-and-code-cleanup
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23052
diff changeset
187
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
188 if (qd->check_watcher > 0) {
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
189 purple_timeout_remove(qd->check_watcher);
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
190 qd->check_watcher = 0;
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
191 }
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
192 qq_disconnect(gc);
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
193
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
194 if (qd->redirect_ip.s_addr != 0) {
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
195 /* redirect to new server */
24873
115a2e9ea8b3 2008.12.28 - flos <lonicerae(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24839
diff changeset
196 tmp_server = g_strdup_printf("%s:%d", inet_ntoa(qd->redirect_ip), qd->redirect_port);
115a2e9ea8b3 2008.12.28 - flos <lonicerae(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24839
diff changeset
197 qd->servers = g_list_append(qd->servers, tmp_server);
115a2e9ea8b3 2008.12.28 - flos <lonicerae(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24839
diff changeset
198
115a2e9ea8b3 2008.12.28 - flos <lonicerae(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24839
diff changeset
199 qd->curr_server = tmp_server;
115a2e9ea8b3 2008.12.28 - flos <lonicerae(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24839
diff changeset
200 tmp_server = NULL;
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
201
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
202 qd->redirect_ip.s_addr = 0;
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
203 qd->redirect_port = 0;
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
204 qd->connect_retry = QQ_CONNECT_MAX;
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
205 }
23053
55f986ccbb6a patch-05-reconnect-and-code-cleanup
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23052
diff changeset
206
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
207 if (qd->curr_server == NULL || strlen (qd->curr_server) == 0 || qd->connect_retry <= 0) {
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
208 if ( set_new_server(qd) != TRUE) {
24066
dbc7a9742f8d 2008.09.26 - ccpaging <ccpaging(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24065
diff changeset
209 purple_connection_error_reason(gc,
dbc7a9742f8d 2008.09.26 - ccpaging <ccpaging(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24065
diff changeset
210 PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
24374
75545fdf8944 String changes. I'm kind of blindly making changes to the qq strings
Mark Doliner <mark@kingant.net>
parents: 24359
diff changeset
211 _("Unable to connect."));
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
212 return FALSE;
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
213 }
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
214 qd->connect_retry = QQ_CONNECT_MAX;
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
215 }
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
216
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
217 segments = g_strsplit_set(qd->curr_server, ":", 0);
24873
115a2e9ea8b3 2008.12.28 - flos <lonicerae(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24839
diff changeset
218 tmp_server = g_strdup(segments[0]);
115a2e9ea8b3 2008.12.28 - flos <lonicerae(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24839
diff changeset
219 if (NULL != segments[1]) {
115a2e9ea8b3 2008.12.28 - flos <lonicerae(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24839
diff changeset
220 port = atoi(segments[1]);
115a2e9ea8b3 2008.12.28 - flos <lonicerae(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24839
diff changeset
221 if (port <= 0) {
115a2e9ea8b3 2008.12.28 - flos <lonicerae(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24839
diff changeset
222 purple_debug_info("QQ", "Port not define in %s, use default.\n", qd->curr_server);
115a2e9ea8b3 2008.12.28 - flos <lonicerae(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24839
diff changeset
223 port = QQ_DEFAULT_PORT;
115a2e9ea8b3 2008.12.28 - flos <lonicerae(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24839
diff changeset
224 }
115a2e9ea8b3 2008.12.28 - flos <lonicerae(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24839
diff changeset
225 } else {
115a2e9ea8b3 2008.12.28 - flos <lonicerae(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24839
diff changeset
226 purple_debug_info("QQ", "Error splitting server string: %s, setting port to default.\n", qd->curr_server);
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
227 port = QQ_DEFAULT_PORT;
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
228 }
24873
115a2e9ea8b3 2008.12.28 - flos <lonicerae(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24839
diff changeset
229
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
230 g_strfreev(segments);
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
231
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
232 qd->connect_retry--;
24873
115a2e9ea8b3 2008.12.28 - flos <lonicerae(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24839
diff changeset
233 if ( !connect_to_server(gc, tmp_server, port) ) {
24066
dbc7a9742f8d 2008.09.26 - ccpaging <ccpaging(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24065
diff changeset
234 purple_connection_error_reason(gc,
dbc7a9742f8d 2008.09.26 - ccpaging <ccpaging(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24065
diff changeset
235 PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
236 _("Unable to connect."));
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
237 }
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
238
24873
115a2e9ea8b3 2008.12.28 - flos <lonicerae(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24839
diff changeset
239 g_free(tmp_server);
115a2e9ea8b3 2008.12.28 - flos <lonicerae(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24839
diff changeset
240 tmp_server = NULL;
115a2e9ea8b3 2008.12.28 - flos <lonicerae(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24839
diff changeset
241
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
242 qd->check_watcher = purple_timeout_add_seconds(QQ_CONNECT_CHECK, connect_check, gc);
23053
55f986ccbb6a patch-05-reconnect-and-code-cleanup
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23052
diff changeset
243 return FALSE; /* timeout callback stops */
55f986ccbb6a patch-05-reconnect-and-code-cleanup
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23052
diff changeset
244 }
55f986ccbb6a patch-05-reconnect-and-code-cleanup
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23052
diff changeset
245
24065
bdfcfd71449c patch 20080922 from ccpaging <ccpaging(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24048
diff changeset
246 static void redirect_server(PurpleConnection *gc)
bdfcfd71449c patch 20080922 from ccpaging <ccpaging(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24048
diff changeset
247 {
bdfcfd71449c patch 20080922 from ccpaging <ccpaging(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24048
diff changeset
248 qq_data *qd;
bdfcfd71449c patch 20080922 from ccpaging <ccpaging(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24048
diff changeset
249 qd = (qq_data *) gc->proto_data;
bdfcfd71449c patch 20080922 from ccpaging <ccpaging(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24048
diff changeset
250
bdfcfd71449c patch 20080922 from ccpaging <ccpaging(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24048
diff changeset
251 if (qd->check_watcher > 0) {
bdfcfd71449c patch 20080922 from ccpaging <ccpaging(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24048
diff changeset
252 purple_timeout_remove(qd->check_watcher);
bdfcfd71449c patch 20080922 from ccpaging <ccpaging(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24048
diff changeset
253 qd->check_watcher = 0;
bdfcfd71449c patch 20080922 from ccpaging <ccpaging(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24048
diff changeset
254 }
bdfcfd71449c patch 20080922 from ccpaging <ccpaging(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24048
diff changeset
255 if (qd->connect_watcher > 0) purple_timeout_remove(qd->connect_watcher);
bdfcfd71449c patch 20080922 from ccpaging <ccpaging(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24048
diff changeset
256 qd->connect_watcher = purple_timeout_add_seconds(QQ_CONNECT_INTERVAL, qq_connect_later, gc);
bdfcfd71449c patch 20080922 from ccpaging <ccpaging(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24048
diff changeset
257 }
bdfcfd71449c patch 20080922 from ccpaging <ccpaging(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24048
diff changeset
258
23052
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
259 /* process the incoming packet from qq_pending */
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
260 static gboolean packet_process(PurpleConnection *gc, guint8 *buf, gint buf_len)
23052
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
261 {
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
262 qq_data *qd;
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
263 gint bytes, bytes_not_read;
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
264
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
265 guint8 header_tag;
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
266 guint16 source_tag;
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
267 guint16 cmd;
23053
55f986ccbb6a patch-05-reconnect-and-code-cleanup
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23052
diff changeset
268 guint16 seq; /* May be ack_seq or send_seq, depends on cmd */
23753
5f454b975a99 2008.08.10 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23683
diff changeset
269 guint8 room_cmd;
5f454b975a99 2008.08.10 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23683
diff changeset
270 guint32 room_id;
25149
7da3cf2530b7 2009.02.21 - flos <lonicerae(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 25070
diff changeset
271 guint32 update_class;
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
272 guint32 ship32;
24065
bdfcfd71449c patch 20080922 from ccpaging <ccpaging(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24048
diff changeset
273 int ret;
23053
55f986ccbb6a patch-05-reconnect-and-code-cleanup
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23052
diff changeset
274
23683
1c50f12b1c52 2008.08.02 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23606
diff changeset
275 qq_transaction *trans;
23052
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
276
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
277 g_return_val_if_fail(buf != NULL && buf_len > 0, TRUE);
23052
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
278
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
279 qd = (qq_data *) gc->proto_data;
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
280
23757
69c218fd5d54 applied changes from 5688199e261449d33b5803dafff50d860896ebcb
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23756
diff changeset
281 qd->net_stat.rcved++;
69c218fd5d54 applied changes from 5688199e261449d33b5803dafff50d860896ebcb
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23756
diff changeset
282 if (qd->net_stat.rcved <= 0) memset(&(qd->net_stat), 0, sizeof(qd->net_stat));
24026
25f62d21b3f8 disapproval of revision '8cebefbc6cd5d84acb69c74e69e8821f11dd225d'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24019
diff changeset
283
23053
55f986ccbb6a patch-05-reconnect-and-code-cleanup
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23052
diff changeset
284 /* Len, header and tail tag have been checked before */
23052
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
285 bytes = 0;
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
286 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
287
23753
5f454b975a99 2008.08.10 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23683
diff changeset
288 #if 1
23755
23cec4360d4a applied changes from 8cebefbc6cd5d84acb69c74e69e8821f11dd225d
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23754
diff changeset
289 purple_debug_info("QQ", "==> [%05d] %s 0x%04X, source tag 0x%04X len %d\n",
23cec4360d4a applied changes from 8cebefbc6cd5d84acb69c74e69e8821f11dd225d
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23754
diff changeset
290 seq, qq_get_cmd_desc(cmd), cmd, source_tag, buf_len);
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
291 #endif
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
292 /* this is the length of all the encrypted data (also remove tail tag) */
23052
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
293 bytes_not_read = buf_len - bytes - 1;
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
294
23053
55f986ccbb6a patch-05-reconnect-and-code-cleanup
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23052
diff changeset
295 /* ack packet, we need to update send tranactions */
55f986ccbb6a patch-05-reconnect-and-code-cleanup
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23052
diff changeset
296 /* we do not check duplication for server ack */
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
297 trans = qq_trans_find_rcved(gc, cmd, seq);
23683
1c50f12b1c52 2008.08.02 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23606
diff changeset
298 if (trans == NULL) {
1c50f12b1c52 2008.08.02 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23606
diff changeset
299 /* new server command */
23755
23cec4360d4a applied changes from 8cebefbc6cd5d84acb69c74e69e8821f11dd225d
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23754
diff changeset
300 if ( !qd->is_login ) {
23cec4360d4a applied changes from 8cebefbc6cd5d84acb69c74e69e8821f11dd225d
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23754
diff changeset
301 qq_trans_add_remain(gc, cmd, seq, buf + bytes, bytes_not_read);
23cec4360d4a applied changes from 8cebefbc6cd5d84acb69c74e69e8821f11dd225d
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23754
diff changeset
302 } else {
23cec4360d4a applied changes from 8cebefbc6cd5d84acb69c74e69e8821f11dd225d
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23754
diff changeset
303 qq_trans_add_server_cmd(gc, cmd, seq, buf + bytes, bytes_not_read);
23cec4360d4a applied changes from 8cebefbc6cd5d84acb69c74e69e8821f11dd225d
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23754
diff changeset
304 qq_proc_server_cmd(gc, cmd, seq, buf + bytes, bytes_not_read);
23053
55f986ccbb6a patch-05-reconnect-and-code-cleanup
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23052
diff changeset
305 }
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
306 return TRUE;
23683
1c50f12b1c52 2008.08.02 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23606
diff changeset
307 }
1c50f12b1c52 2008.08.02 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23606
diff changeset
308
1c50f12b1c52 2008.08.02 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23606
diff changeset
309 if (qq_trans_is_dup(trans)) {
23757
69c218fd5d54 applied changes from 5688199e261449d33b5803dafff50d860896ebcb
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23756
diff changeset
310 qd->net_stat.rcved_dup++;
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
311 purple_debug_info("QQ", "dup [%05d] %s, discard...\n", seq, qq_get_cmd_desc(cmd));
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
312 return TRUE;
24021
6408be948d56 disapproval of revision '92d52eef2994d2697999177804e3665989cfa352'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24020
diff changeset
313 }
6408be948d56 disapproval of revision '92d52eef2994d2697999177804e3665989cfa352'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24020
diff changeset
314
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
315 update_class = qq_trans_get_class(trans);
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
316 ship32 = qq_trans_get_ship(trans);
24048
d57928c9dd8f 2008.09.19 - ccpaging <ccpaging(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24046
diff changeset
317 if (update_class != 0 || ship32 != 0) {
24586
c69c337269e1 Clean debug info
Hu Yong <ccpaging@gmail.com>
parents: 24571
diff changeset
318 purple_debug_info("QQ", "Update class %d, ship32 %d\n", update_class, ship32);
24048
d57928c9dd8f 2008.09.19 - ccpaging <ccpaging(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24046
diff changeset
319 }
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
320
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
321 switch (cmd) {
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
322 case QQ_CMD_TOKEN:
24065
bdfcfd71449c patch 20080922 from ccpaging <ccpaging(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24048
diff changeset
323 case QQ_CMD_GET_SERVER:
24069
dc112387190f 2008.09.29 - ccpaging <ccpaging(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24068
diff changeset
324 case QQ_CMD_TOKEN_EX:
dc112387190f 2008.09.29 - ccpaging <ccpaging(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24068
diff changeset
325 case QQ_CMD_CHECK_PWD:
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
326 case QQ_CMD_LOGIN:
24065
bdfcfd71449c patch 20080922 from ccpaging <ccpaging(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24048
diff changeset
327 ret = qq_proc_login_cmds(gc, cmd, seq, buf + bytes, bytes_not_read, update_class, ship32);
bdfcfd71449c patch 20080922 from ccpaging <ccpaging(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24048
diff changeset
328 if (ret != QQ_LOGIN_REPLY_OK) {
bdfcfd71449c patch 20080922 from ccpaging <ccpaging(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24048
diff changeset
329 if (ret == QQ_LOGIN_REPLY_REDIRECT) {
bdfcfd71449c patch 20080922 from ccpaging <ccpaging(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24048
diff changeset
330 redirect_server(gc);
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
331 }
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
332 return FALSE; /* do nothing after this function and return now */
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
333 }
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
334 break;
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
335 case QQ_CMD_ROOM:
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
336 room_cmd = qq_trans_get_room_cmd(trans);
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
337 room_id = qq_trans_get_room_id(trans);
24065
bdfcfd71449c patch 20080922 from ccpaging <ccpaging(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24048
diff changeset
338 qq_proc_room_cmds(gc, seq, room_cmd, room_id, buf + bytes, bytes_not_read, update_class, ship32);
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
339 break;
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
340 default:
24065
bdfcfd71449c patch 20080922 from ccpaging <ccpaging(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24048
diff changeset
341 qq_proc_client_cmds(gc, cmd, seq, buf + bytes, bytes_not_read, update_class, ship32);
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
342 break;
23052
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
343 }
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
344
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
345 return TRUE;
23052
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
346 }
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
347
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
348 static void tcp_pending(gpointer data, gint source, PurpleInputCondition cond)
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
349 {
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
350 PurpleConnection *gc = (PurpleConnection *) data;
23052
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
351 qq_data *qd;
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
352 qq_connection *conn;
23053
55f986ccbb6a patch-05-reconnect-and-code-cleanup
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23052
diff changeset
353 guint8 buf[1024]; /* set to 16 when test tcp_rxqueue */
23052
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
354 gint buf_len;
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
355 gint bytes;
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
356
23052
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
357 guint8 *pkt;
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
358 guint16 pkt_len;
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
359
23052
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
360 gchar *error_msg;
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
361 guint8 *jump;
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
362 gint jump_len;
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
363
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
364 g_return_if_fail(gc != NULL && gc->proto_data != NULL);
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
365 qd = (qq_data *) gc->proto_data;
23052
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
366
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
367 if(cond != PURPLE_INPUT_READ) {
24066
dbc7a9742f8d 2008.09.26 - ccpaging <ccpaging(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24065
diff changeset
368 purple_connection_error_reason(gc,
dbc7a9742f8d 2008.09.26 - ccpaging <ccpaging(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24065
diff changeset
369 PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
23052
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
370 _("Socket error"));
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
371 return;
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
372 }
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
373
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
374 conn = connection_find(qd, source);
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
375 g_return_if_fail(conn != NULL);
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
376
23052
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
377 /* test code, not using tcp_rxqueue
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
378 memset(pkt,0, sizeof(pkt));
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
379 buf_len = read(qd->fd, pkt, sizeof(pkt));
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
380 if (buf_len > 2) {
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
381 packet_process(gc, pkt + 2, buf_len - 2);
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
382 }
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
383 return;
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
384 */
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
385
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
386 buf_len = read(source, buf, sizeof(buf));
23052
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
387 if (buf_len < 0) {
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
388 if (errno == EAGAIN)
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
389 /* No worries */
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
390 return;
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
391
24630
8f757b2139d2 String changes (a few of which I had already made, grumble grumble).
Mark Doliner <mark@kingant.net>
parents: 24627
diff changeset
392 error_msg = g_strdup_printf(_("Lost connection with server:\n%s"), g_strerror(errno));
24066
dbc7a9742f8d 2008.09.26 - ccpaging <ccpaging(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24065
diff changeset
393 purple_connection_error_reason(gc,
dbc7a9742f8d 2008.09.26 - ccpaging <ccpaging(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24065
diff changeset
394 PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
dbc7a9742f8d 2008.09.26 - ccpaging <ccpaging(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24065
diff changeset
395 error_msg);
23052
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
396 g_free(error_msg);
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
397 return;
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
398 } else if (buf_len == 0) {
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
399 purple_connection_error_reason(gc, PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
400 _("Server closed the connection."));
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
401 return;
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
402 }
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
403
23606
bdb38a8bf721 20080717-05-1-fix-keep-alive ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23054
diff changeset
404 /* 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: 23054
diff changeset
405 * 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: 23054
diff changeset
406 gc->last_received = time(NULL);
bdb38a8bf721 20080717-05-1-fix-keep-alive ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23054
diff changeset
407 */
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
408 /* purple_debug_info("TCP_PENDING", "Read %d bytes, rxlen is %d\n", buf_len, conn->tcp_rxlen); */
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
409 conn->tcp_rxqueue = g_realloc(conn->tcp_rxqueue, buf_len + conn->tcp_rxlen);
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
410 memcpy(conn->tcp_rxqueue + conn->tcp_rxlen, buf, buf_len);
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
411 conn->tcp_rxlen += buf_len;
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
412
23052
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
413 pkt = g_newa(guint8, MAX_PACKET_SIZE);
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
414 while (PURPLE_CONNECTION_IS_VALID(gc)) {
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
415 if (qd->openconns == NULL) {
23052
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
416 break;
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
417 }
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
418 if (conn->tcp_rxqueue == NULL) {
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
419 conn->tcp_rxlen = 0;
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
420 break;
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
421 }
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
422 if (conn->tcp_rxlen < QQ_TCP_HEADER_LENGTH) {
23052
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
423 break;
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
424 }
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
425
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
426 bytes = 0;
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
427 bytes += qq_get16(&pkt_len, conn->tcp_rxqueue + bytes);
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
428 if (conn->tcp_rxlen < pkt_len) {
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
429 break;
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
430 }
24026
25f62d21b3f8 disapproval of revision '8cebefbc6cd5d84acb69c74e69e8821f11dd225d'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24019
diff changeset
431
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
432 /* purple_debug_info("TCP_PENDING", "Packet len=%d, rxlen=%d\n", pkt_len, conn->tcp_rxlen); */
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
433 if ( pkt_len < QQ_TCP_HEADER_LENGTH
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
434 || *(conn->tcp_rxqueue + bytes) != QQ_PACKET_TAG
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
435 || *(conn->tcp_rxqueue + pkt_len - 1) != QQ_PACKET_TAIL) {
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
436 /* HEY! This isn't even a QQ. What are you trying to pull? */
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
437 purple_debug_warning("TCP_PENDING", "Packet error, no header or tail tag\n");
23052
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
438
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
439 jump = memchr(conn->tcp_rxqueue + 1, QQ_PACKET_TAIL, conn->tcp_rxlen - 1);
23052
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
440 if ( !jump ) {
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
441 purple_debug_warning("TCP_PENDING", "Failed to find next tail, clear receive buffer\n");
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
442 g_free(conn->tcp_rxqueue);
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
443 conn->tcp_rxqueue = NULL;
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
444 conn->tcp_rxlen = 0;
23052
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
445 return;
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
446 }
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
447
23053
55f986ccbb6a patch-05-reconnect-and-code-cleanup
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23052
diff changeset
448 /* jump and over QQ_PACKET_TAIL */
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
449 jump_len = (jump - conn->tcp_rxqueue) + 1;
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
450 purple_debug_warning("TCP_PENDING", "Find next tail at %d, jump %d\n", jump_len, jump_len + 1);
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
451 g_memmove(conn->tcp_rxqueue, jump, conn->tcp_rxlen - jump_len);
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
452 conn->tcp_rxlen -= jump_len;
23052
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
453 continue;
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
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
456 memset(pkt, 0, MAX_PACKET_SIZE);
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
457 g_memmove(pkt, conn->tcp_rxqueue + bytes, pkt_len - bytes);
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
458
23053
55f986ccbb6a patch-05-reconnect-and-code-cleanup
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23052
diff changeset
459 /* jump to next packet */
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
460 conn->tcp_rxlen -= pkt_len;
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
461 if (conn->tcp_rxlen) {
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
462 /* purple_debug_info("TCP_PENDING", "shrink tcp_rxqueue to %d\n", conn->tcp_rxlen); */
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
463 jump = g_memdup(conn->tcp_rxqueue + pkt_len, conn->tcp_rxlen);
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
464 g_free(conn->tcp_rxqueue);
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
465 conn->tcp_rxqueue = jump;
23052
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
466 } else {
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
467 /* purple_debug_info("TCP_PENDING", "free tcp_rxqueue\n"); */
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
468 g_free(conn->tcp_rxqueue);
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
469 conn->tcp_rxqueue = NULL;
23052
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
470 }
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
471
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
472 /* packet_process may call disconnect and destory data like conn
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
473 * do not call packet_process before jump,
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
474 * break if packet_process return FALSE */
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
475 if (packet_process(gc, pkt, pkt_len - bytes) == FALSE) {
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
476 purple_debug_info("TCP_PENDING", "Connection has been destory\n");
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
477 break;
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
478 }
23052
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
479 }
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
480 }
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
481
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
482 static void udp_pending(gpointer data, gint source, PurpleInputCondition cond)
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
483 {
24839
b74fa0d31c74 2008.12.25 - flos <lonicerae(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24630
diff changeset
484 PurpleConnection *gc = NULL;
23052
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
485 qq_data *qd;
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
486 guint8 *buf;
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
487 gint buf_len;
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
488
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
489 gc = (PurpleConnection *) data;
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
490 g_return_if_fail(gc != NULL && gc->proto_data != NULL);
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
491 qd = (qq_data *) gc->proto_data;
23052
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
492
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
493 if(cond != PURPLE_INPUT_READ) {
24066
dbc7a9742f8d 2008.09.26 - ccpaging <ccpaging(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24065
diff changeset
494 purple_connection_error_reason(gc,
dbc7a9742f8d 2008.09.26 - ccpaging <ccpaging(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24065
diff changeset
495 PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
23052
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
496 _("Socket error"));
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
497 return;
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
498 }
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 buf = g_newa(guint8, MAX_PACKET_SIZE);
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
501
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
502 /* here we have UDP proxy suppport */
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
503 buf_len = read(source, buf, MAX_PACKET_SIZE);
23052
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
504 if (buf_len <= 0) {
24066
dbc7a9742f8d 2008.09.26 - ccpaging <ccpaging(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24065
diff changeset
505 purple_connection_error_reason(gc,
dbc7a9742f8d 2008.09.26 - ccpaging <ccpaging(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24065
diff changeset
506 PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
23052
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
507 _("Unable to read from socket"));
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
508 return;
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
509 }
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
510
23606
bdb38a8bf721 20080717-05-1-fix-keep-alive ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23054
diff changeset
511 /* 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: 23054
diff changeset
512 * 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: 23054
diff changeset
513 gc->last_received = time(NULL);
bdb38a8bf721 20080717-05-1-fix-keep-alive ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23054
diff changeset
514 */
23052
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
515
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
516 if (buf_len < QQ_UDP_HEADER_LENGTH) {
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
517 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
518 qq_hex_dump(PURPLE_DEBUG_ERROR, "UDP_PENDING",
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
519 buf, buf_len,
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
520 "Received packet is too short, or no header and tail tag");
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
521 return;
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
522 }
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
523 }
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
524
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
525 /* packet_process may call disconnect and destory data like conn
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
526 * do not call packet_process before jump,
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
527 * break if packet_process return FALSE */
23052
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
528 packet_process(gc, buf, buf_len);
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
529 }
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
530
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
531 static gint udp_send_out(PurpleConnection *gc, guint8 *data, gint data_len)
23052
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
532 {
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
533 qq_data *qd;
23052
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
534 gint ret;
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
535
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
536 g_return_val_if_fail(data != NULL && data_len > 0, -1);
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
537
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
538 g_return_val_if_fail(gc != NULL && gc->proto_data != NULL, -1);
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
539 qd = (qq_data *) gc->proto_data;
23052
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
540
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
541 #if 0
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
542 purple_debug_info("UDP_SEND_OUT", "Send %d bytes to socket %d\n", data_len, qd->fd);
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
543 #endif
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
544
23052
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
545 errno = 0;
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
546 ret = send(qd->fd, data, data_len, 0);
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
547 if (ret < 0 && errno == EAGAIN) {
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
548 return ret;
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
549 }
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
550
23052
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
551 if (ret < 0) {
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
552 /* TODO: what to do here - do we really have to disconnect? */
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
553 purple_debug_error("UDP_SEND_OUT", "Send failed: %d, %s\n", errno, g_strerror(errno));
24066
dbc7a9742f8d 2008.09.26 - ccpaging <ccpaging(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24065
diff changeset
554 purple_connection_error_reason(gc,
dbc7a9742f8d 2008.09.26 - ccpaging <ccpaging(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24065
diff changeset
555 PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
dbc7a9742f8d 2008.09.26 - ccpaging <ccpaging(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24065
diff changeset
556 g_strerror(errno));
23052
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
557 }
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
558 return ret;
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
559 }
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
560
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
561 static void tcp_can_write(gpointer data, gint source, PurpleInputCondition cond)
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
562 {
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
563 PurpleConnection *gc = (PurpleConnection *) data;
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
564 qq_data *qd;
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
565 qq_connection *conn;
23052
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
566 int ret, writelen;
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
567
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
568 g_return_if_fail(gc != NULL && gc->proto_data != NULL);
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
569 qd = (qq_data *) gc->proto_data;
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
570
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
571 conn = connection_find(qd, source);
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
572 g_return_if_fail(conn != NULL);
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
573
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
574 writelen = purple_circ_buffer_get_max_read(conn->tcp_txbuf);
23052
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
575 if (writelen == 0) {
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
576 purple_input_remove(conn->can_write_handler);
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
577 conn->can_write_handler = 0;
23052
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
578 return;
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
579 }
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
580
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
581 ret = write(source, conn->tcp_txbuf->outptr, writelen);
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
582 purple_debug_info("TCP_CAN_WRITE", "total %d bytes is sent %d\n", writelen, ret);
23052
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
583
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
584 if (ret < 0 && errno == EAGAIN)
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
585 return;
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
586 else if (ret < 0) {
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
587 /* TODO: what to do here - do we really have to disconnect? */
24066
dbc7a9742f8d 2008.09.26 - ccpaging <ccpaging(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24065
diff changeset
588 purple_connection_error_reason(gc,
dbc7a9742f8d 2008.09.26 - ccpaging <ccpaging(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24065
diff changeset
589 PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
dbc7a9742f8d 2008.09.26 - ccpaging <ccpaging(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24065
diff changeset
590 _("Write Error"));
23052
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
591 return;
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
592 }
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
593
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
594 purple_circ_buffer_mark_read(conn->tcp_txbuf, ret);
23052
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
595 }
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
596
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
597 static gint tcp_send_out(PurpleConnection *gc, guint8 *data, gint data_len)
23052
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
598 {
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
599 qq_data *qd;
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
600 qq_connection *conn;
23052
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
601 gint ret;
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
602
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
603 g_return_val_if_fail(data != NULL && data_len > 0, -1);
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
604
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
605 g_return_val_if_fail(gc != NULL && gc->proto_data != NULL, -1);
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
606 qd = (qq_data *) gc->proto_data;
23052
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
607
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
608 conn = connection_find(qd, qd->fd);
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
609 g_return_val_if_fail(conn, -1);
23052
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
610
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
611 #if 0
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
612 purple_debug_info("TCP_SEND_OUT", "Send %d bytes to socket %d\n", data_len, qd->fd);
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
613 #endif
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
614
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
615 if (conn->can_write_handler == 0) {
23052
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
616 ret = write(qd->fd, data, data_len);
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
617 } else {
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
618 ret = -1;
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
619 errno = EAGAIN;
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
620 }
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
621
23683
1c50f12b1c52 2008.08.02 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23606
diff changeset
622 /*
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
623 purple_debug_info("TCP_SEND_OUT",
23052
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
624 "Socket %d, total %d bytes is sent %d\n", qd->fd, data_len, ret);
23683
1c50f12b1c52 2008.08.02 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23606
diff changeset
625 */
23052
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
626 if (ret < 0 && errno == EAGAIN) {
23053
55f986ccbb6a patch-05-reconnect-and-code-cleanup
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23052
diff changeset
627 /* socket is busy, send later */
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
628 purple_debug_info("TCP_SEND_OUT", "Socket is busy and send later\n");
23052
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
629 ret = 0;
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
630 } else if (ret <= 0) {
23053
55f986ccbb6a patch-05-reconnect-and-code-cleanup
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23052
diff changeset
631 /* TODO: what to do here - do we really have to disconnect? */
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
632 purple_debug_error("TCP_SEND_OUT",
23052
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
633 "Send to socket %d failed: %d, %s\n", qd->fd, errno, g_strerror(errno));
24066
dbc7a9742f8d 2008.09.26 - ccpaging <ccpaging(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24065
diff changeset
634 purple_connection_error_reason(gc,
dbc7a9742f8d 2008.09.26 - ccpaging <ccpaging(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24065
diff changeset
635 PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
dbc7a9742f8d 2008.09.26 - ccpaging <ccpaging(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24065
diff changeset
636 g_strerror(errno));
23052
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
637 return ret;
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
638 }
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
639
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
640 if (ret < data_len) {
24586
c69c337269e1 Clean debug info
Hu Yong <ccpaging@gmail.com>
parents: 24571
diff changeset
641 purple_debug_info("TCP_SEND_OUT", "Add %d bytes to buffer\n", data_len - ret);
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
642 if (conn->can_write_handler == 0) {
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
643 conn->can_write_handler = purple_input_add(qd->fd, PURPLE_INPUT_WRITE, tcp_can_write, gc);
23052
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
644 }
24571
c52fe0a3b11d Fixed: purple_circ_buffer not created before append
Hu Yong <ccpaging@gmail.com>
parents: 24088
diff changeset
645 if (conn->tcp_txbuf == NULL) {
c52fe0a3b11d Fixed: purple_circ_buffer not created before append
Hu Yong <ccpaging@gmail.com>
parents: 24088
diff changeset
646 conn->tcp_txbuf = purple_circ_buffer_new(4096);
c52fe0a3b11d Fixed: purple_circ_buffer not created before append
Hu Yong <ccpaging@gmail.com>
parents: 24088
diff changeset
647 }
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
648 purple_circ_buffer_append(conn->tcp_txbuf, data + ret, data_len - ret);
23052
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
649 }
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
650 return ret;
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
651 }
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
652
23683
1c50f12b1c52 2008.08.02 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23606
diff changeset
653 static gboolean network_timeout(gpointer data)
23052
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
654 {
23683
1c50f12b1c52 2008.08.02 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23606
diff changeset
655 PurpleConnection *gc = (PurpleConnection *) data;
23052
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
656 qq_data *qd;
23683
1c50f12b1c52 2008.08.02 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23606
diff changeset
657 gboolean is_lost_conn;
1c50f12b1c52 2008.08.02 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23606
diff changeset
658
23052
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
659 g_return_val_if_fail(gc != NULL && gc->proto_data != NULL, TRUE);
23683
1c50f12b1c52 2008.08.02 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23606
diff changeset
660 qd = (qq_data *) gc->proto_data;
23052
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
661
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
662 is_lost_conn = qq_trans_scan(gc);
23683
1c50f12b1c52 2008.08.02 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23606
diff changeset
663 if (is_lost_conn) {
1c50f12b1c52 2008.08.02 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23606
diff changeset
664 purple_connection_error_reason(gc,
24066
dbc7a9742f8d 2008.09.26 - ccpaging <ccpaging(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24065
diff changeset
665 PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
dbc7a9742f8d 2008.09.26 - ccpaging <ccpaging(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24065
diff changeset
666 _("Connection lost"));
23683
1c50f12b1c52 2008.08.02 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23606
diff changeset
667 return TRUE;
1c50f12b1c52 2008.08.02 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23606
diff changeset
668 }
23052
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
669
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
670 if ( !qd->is_login ) {
23683
1c50f12b1c52 2008.08.02 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23606
diff changeset
671 return TRUE;
1c50f12b1c52 2008.08.02 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23606
diff changeset
672 }
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
673
23683
1c50f12b1c52 2008.08.02 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23606
diff changeset
674 qd->itv_count.keep_alive--;
1c50f12b1c52 2008.08.02 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23606
diff changeset
675 if (qd->itv_count.keep_alive <= 0) {
1c50f12b1c52 2008.08.02 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23606
diff changeset
676 qd->itv_count.keep_alive = qd->itv_config.keep_alive;
24071
619ac2303c46 2009.10.02 - ccpaging <ccpaging(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24069
diff changeset
677 if (qd->client_version >= 2008) {
619ac2303c46 2009.10.02 - ccpaging <ccpaging(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24069
diff changeset
678 qq_request_keep_alive_2008(gc);
619ac2303c46 2009.10.02 - ccpaging <ccpaging(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24069
diff changeset
679 } else if (qd->client_version >= 2007) {
619ac2303c46 2009.10.02 - ccpaging <ccpaging(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24069
diff changeset
680 qq_request_keep_alive_2007(gc);
619ac2303c46 2009.10.02 - ccpaging <ccpaging(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24069
diff changeset
681 } else {
619ac2303c46 2009.10.02 - ccpaging <ccpaging(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24069
diff changeset
682 qq_request_keep_alive(gc);
619ac2303c46 2009.10.02 - ccpaging <ccpaging(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24069
diff changeset
683 }
23683
1c50f12b1c52 2008.08.02 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23606
diff changeset
684 return TRUE;
1c50f12b1c52 2008.08.02 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23606
diff changeset
685 }
23052
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
686
23683
1c50f12b1c52 2008.08.02 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23606
diff changeset
687 if (qd->itv_config.update <= 0) {
1c50f12b1c52 2008.08.02 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23606
diff changeset
688 return TRUE;
1c50f12b1c52 2008.08.02 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23606
diff changeset
689 }
1c50f12b1c52 2008.08.02 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23606
diff changeset
690
1c50f12b1c52 2008.08.02 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23606
diff changeset
691 qd->itv_count.update--;
1c50f12b1c52 2008.08.02 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23606
diff changeset
692 if (qd->itv_count.update <= 0) {
1c50f12b1c52 2008.08.02 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23606
diff changeset
693 qd->itv_count.update = qd->itv_config.update;
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
694 qq_update_online(gc, 0);
23683
1c50f12b1c52 2008.08.02 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23606
diff changeset
695 return TRUE;
23052
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
696 }
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
697
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
698 return TRUE; /* if return FALSE, timeout callback stops */
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
699 }
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
700
24065
bdfcfd71449c patch 20080922 from ccpaging <ccpaging(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24048
diff changeset
701 static void set_all_keys(PurpleConnection *gc)
23052
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 qq_data *qd;
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
704 const gchar *passwd;
24066
dbc7a9742f8d 2008.09.26 - ccpaging <ccpaging(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24065
diff changeset
705 guint8 *dest;
dbc7a9742f8d 2008.09.26 - ccpaging <ccpaging(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24065
diff changeset
706 int dest_len = QQ_KEY_LENGTH;
24071
619ac2303c46 2009.10.02 - ccpaging <ccpaging(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24069
diff changeset
707 #ifndef DEBUG
619ac2303c46 2009.10.02 - ccpaging <ccpaging(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24069
diff changeset
708 int bytes;
619ac2303c46 2009.10.02 - ccpaging <ccpaging(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24069
diff changeset
709 #endif
23053
55f986ccbb6a patch-05-reconnect-and-code-cleanup
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23052
diff changeset
710 /* _qq_show_socket("Got login socket", source); */
23052
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
711
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
712 g_return_if_fail(gc != NULL && gc->proto_data != NULL);
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
713 qd = (qq_data *) gc->proto_data;
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
714
23052
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
715 /* QQ use random seq, to minimize duplicated packets */
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
716 srand(time(NULL));
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
717 qd->send_seq = rand() & 0xffff;
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
718
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
719 qd->is_login = FALSE;
24571
c52fe0a3b11d Fixed: purple_circ_buffer not created before append
Hu Yong <ccpaging@gmail.com>
parents: 24088
diff changeset
720 qd->uid = strtoul(purple_account_get_username(purple_connection_get_account(gc)), NULL, 10);
23052
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
721
24065
bdfcfd71449c patch 20080922 from ccpaging <ccpaging(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24048
diff changeset
722 #ifdef DEBUG
24066
dbc7a9742f8d 2008.09.26 - ccpaging <ccpaging(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24065
diff changeset
723 memset(qd->ld.random_key, 0x01, sizeof(qd->ld.random_key));
24065
bdfcfd71449c patch 20080922 from ccpaging <ccpaging(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24048
diff changeset
724 #else
24066
dbc7a9742f8d 2008.09.26 - ccpaging <ccpaging(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24065
diff changeset
725 for (bytes = 0; bytes < sizeof(qd->ld.random_key); bytes++) {
dbc7a9742f8d 2008.09.26 - ccpaging <ccpaging(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24065
diff changeset
726 qd->ld.random_key[bytes] = (guint8) (rand() & 0xff);
24065
bdfcfd71449c patch 20080922 from ccpaging <ccpaging(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24048
diff changeset
727 }
bdfcfd71449c patch 20080922 from ccpaging <ccpaging(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24048
diff changeset
728 #endif
bdfcfd71449c patch 20080922 from ccpaging <ccpaging(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24048
diff changeset
729
23052
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
730 /* now generate md5 processed passwd */
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
731 passwd = purple_account_get_password(purple_connection_get_account(gc));
23683
1c50f12b1c52 2008.08.02 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23606
diff changeset
732
1c50f12b1c52 2008.08.02 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23606
diff changeset
733 /* use twice-md5 of user password as session key since QQ 2003iii */
24069
dc112387190f 2008.09.29 - ccpaging <ccpaging(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24068
diff changeset
734 dest = qd->ld.pwd_md5;
24066
dbc7a9742f8d 2008.09.26 - ccpaging <ccpaging(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24065
diff changeset
735 qq_get_md5(dest, dest_len, (guint8 *)passwd, strlen(passwd));
23683
1c50f12b1c52 2008.08.02 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23606
diff changeset
736
24069
dc112387190f 2008.09.29 - ccpaging <ccpaging(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24068
diff changeset
737 dest = qd->ld.pwd_twice_md5;
dc112387190f 2008.09.29 - ccpaging <ccpaging(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24068
diff changeset
738 qq_get_md5(dest, dest_len, qd->ld.pwd_md5, dest_len);
23052
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
739 }
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
740
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
741 /* the callback function after socket is built
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
742 * we setup the qq protocol related configuration here */
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
743 static void connect_cb(gpointer data, gint source, const gchar *error_message)
23052
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
744 {
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
745 PurpleConnection *gc;
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
746 qq_data *qd;
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
747 PurpleAccount *account ;
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
748 qq_connection *conn;
23052
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
749
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
750 gc = (PurpleConnection *) data;
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
751 g_return_if_fail(gc != NULL && gc->proto_data != NULL);
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
752
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
753 qd = (qq_data *) gc->proto_data;
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
754 account = purple_connection_get_account(gc);
23052
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
755
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
756 /* conn_data will be destoryed */
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
757 qd->conn_data = NULL;
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
758
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
759 if (!PURPLE_CONNECTION_IS_VALID(gc)) {
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
760 purple_debug_info("QQ_CONN", "Invalid connection\n");
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
761 close(source);
23052
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
762 return;
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
763 }
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
764
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
765 if (source < 0) { /* socket returns -1 */
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
766 purple_debug_info("QQ_CONN",
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
767 "Could not establish a connection with the server:\n%s\n",
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
768 error_message);
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
769 if (qd->connect_watcher > 0) purple_timeout_remove(qd->connect_watcher);
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
770 qd->connect_watcher = purple_timeout_add_seconds(QQ_CONNECT_INTERVAL, qq_connect_later, gc);
23052
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
771 return;
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
772 }
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
773
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
774 /* _qq_show_socket("Got login socket", source); */
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
775 qd->fd = source;
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
776 conn = connection_create(qd, source);
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
777 if (qd->use_tcp) {
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
778 conn->input_handler = purple_input_add(source, PURPLE_INPUT_READ, tcp_pending, gc);
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
779 } else {
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
780 conn->input_handler = purple_input_add(source, PURPLE_INPUT_READ, udp_pending, gc);
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
781 }
23052
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
782
24065
bdfcfd71449c patch 20080922 from ccpaging <ccpaging(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24048
diff changeset
783 g_return_if_fail(qd->network_watcher == 0);
bdfcfd71449c patch 20080922 from ccpaging <ccpaging(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24048
diff changeset
784 qd->network_watcher = purple_timeout_add_seconds(qd->itv_config.resend, network_timeout, gc);
bdfcfd71449c patch 20080922 from ccpaging <ccpaging(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24048
diff changeset
785
bdfcfd71449c patch 20080922 from ccpaging <ccpaging(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24048
diff changeset
786 set_all_keys( gc );
bdfcfd71449c patch 20080922 from ccpaging <ccpaging(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24048
diff changeset
787
24071
619ac2303c46 2009.10.02 - ccpaging <ccpaging(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24069
diff changeset
788 if (qd->client_version >= 2007) {
24630
8f757b2139d2 String changes (a few of which I had already made, grumble grumble).
Mark Doliner <mark@kingant.net>
parents: 24627
diff changeset
789 purple_connection_update_progress(gc, _("Getting server"), 2, QQ_CONNECT_STEPS);
24065
bdfcfd71449c patch 20080922 from ccpaging <ccpaging(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24048
diff changeset
790 qq_request_get_server(gc);
bdfcfd71449c patch 20080922 from ccpaging <ccpaging(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24048
diff changeset
791 return;
bdfcfd71449c patch 20080922 from ccpaging <ccpaging(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24048
diff changeset
792 }
bdfcfd71449c patch 20080922 from ccpaging <ccpaging(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24048
diff changeset
793
24630
8f757b2139d2 String changes (a few of which I had already made, grumble grumble).
Mark Doliner <mark@kingant.net>
parents: 24627
diff changeset
794 purple_connection_update_progress(gc, _("Requesting token"), 2, QQ_CONNECT_STEPS);
24065
bdfcfd71449c patch 20080922 from ccpaging <ccpaging(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24048
diff changeset
795 qq_request_token(gc);
23052
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
796 }
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
797
23755
23cec4360d4a applied changes from 8cebefbc6cd5d84acb69c74e69e8821f11dd225d
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23754
diff changeset
798 #ifndef purple_proxy_connect_udp
24026
25f62d21b3f8 disapproval of revision '8cebefbc6cd5d84acb69c74e69e8821f11dd225d'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24019
diff changeset
799 static void udp_can_write(gpointer data, gint source, PurpleInputCondition cond)
23052
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
800 {
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
801 PurpleConnection *gc;
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
802 qq_data *qd;
24026
25f62d21b3f8 disapproval of revision '8cebefbc6cd5d84acb69c74e69e8821f11dd225d'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24019
diff changeset
803 socklen_t len;
25f62d21b3f8 disapproval of revision '8cebefbc6cd5d84acb69c74e69e8821f11dd225d'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24019
diff changeset
804 int error=0, ret;
25f62d21b3f8 disapproval of revision '8cebefbc6cd5d84acb69c74e69e8821f11dd225d'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24019
diff changeset
805
25f62d21b3f8 disapproval of revision '8cebefbc6cd5d84acb69c74e69e8821f11dd225d'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24019
diff changeset
806 gc = (PurpleConnection *) data;
25f62d21b3f8 disapproval of revision '8cebefbc6cd5d84acb69c74e69e8821f11dd225d'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24019
diff changeset
807 g_return_if_fail(gc != NULL && gc->proto_data != NULL);
25f62d21b3f8 disapproval of revision '8cebefbc6cd5d84acb69c74e69e8821f11dd225d'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24019
diff changeset
808
25f62d21b3f8 disapproval of revision '8cebefbc6cd5d84acb69c74e69e8821f11dd225d'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24019
diff changeset
809 qd = (qq_data *) gc->proto_data;
25f62d21b3f8 disapproval of revision '8cebefbc6cd5d84acb69c74e69e8821f11dd225d'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24019
diff changeset
810
25f62d21b3f8 disapproval of revision '8cebefbc6cd5d84acb69c74e69e8821f11dd225d'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24019
diff changeset
811
25f62d21b3f8 disapproval of revision '8cebefbc6cd5d84acb69c74e69e8821f11dd225d'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24019
diff changeset
812 purple_debug_info("proxy", "Connected.\n");
25f62d21b3f8 disapproval of revision '8cebefbc6cd5d84acb69c74e69e8821f11dd225d'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24019
diff changeset
813
25f62d21b3f8 disapproval of revision '8cebefbc6cd5d84acb69c74e69e8821f11dd225d'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24019
diff changeset
814 /*
25f62d21b3f8 disapproval of revision '8cebefbc6cd5d84acb69c74e69e8821f11dd225d'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24019
diff changeset
815 * getsockopt after a non-blocking connect returns -1 if something is
25f62d21b3f8 disapproval of revision '8cebefbc6cd5d84acb69c74e69e8821f11dd225d'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24019
diff changeset
816 * really messed up (bad descriptor, usually). Otherwise, it returns 0 and
25f62d21b3f8 disapproval of revision '8cebefbc6cd5d84acb69c74e69e8821f11dd225d'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24019
diff changeset
817 * error holds what connect would have returned if it blocked until now.
25f62d21b3f8 disapproval of revision '8cebefbc6cd5d84acb69c74e69e8821f11dd225d'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24019
diff changeset
818 * Thus, error == 0 is success, error == EINPROGRESS means "try again",
25f62d21b3f8 disapproval of revision '8cebefbc6cd5d84acb69c74e69e8821f11dd225d'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24019
diff changeset
819 * and anything else is a real error.
25f62d21b3f8 disapproval of revision '8cebefbc6cd5d84acb69c74e69e8821f11dd225d'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24019
diff changeset
820 *
25f62d21b3f8 disapproval of revision '8cebefbc6cd5d84acb69c74e69e8821f11dd225d'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24019
diff changeset
821 * (error == EINPROGRESS can happen after a select because the kernel can
25f62d21b3f8 disapproval of revision '8cebefbc6cd5d84acb69c74e69e8821f11dd225d'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24019
diff changeset
822 * be overly optimistic sometimes. select is just a hint that you might be
25f62d21b3f8 disapproval of revision '8cebefbc6cd5d84acb69c74e69e8821f11dd225d'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24019
diff changeset
823 * able to do something.)
25f62d21b3f8 disapproval of revision '8cebefbc6cd5d84acb69c74e69e8821f11dd225d'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24019
diff changeset
824 */
25f62d21b3f8 disapproval of revision '8cebefbc6cd5d84acb69c74e69e8821f11dd225d'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24019
diff changeset
825 len = sizeof(error);
25f62d21b3f8 disapproval of revision '8cebefbc6cd5d84acb69c74e69e8821f11dd225d'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24019
diff changeset
826 ret = getsockopt(source, SOL_SOCKET, SO_ERROR, &error, &len);
25f62d21b3f8 disapproval of revision '8cebefbc6cd5d84acb69c74e69e8821f11dd225d'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24019
diff changeset
827 if (ret == 0 && error == EINPROGRESS)
25f62d21b3f8 disapproval of revision '8cebefbc6cd5d84acb69c74e69e8821f11dd225d'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24019
diff changeset
828 return; /* we'll be called again later */
23755
23cec4360d4a applied changes from 8cebefbc6cd5d84acb69c74e69e8821f11dd225d
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23754
diff changeset
829
23cec4360d4a applied changes from 8cebefbc6cd5d84acb69c74e69e8821f11dd225d
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23754
diff changeset
830 purple_input_remove(qd->udp_can_write_handler);
23cec4360d4a applied changes from 8cebefbc6cd5d84acb69c74e69e8821f11dd225d
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23754
diff changeset
831 qd->udp_can_write_handler = 0;
24026
25f62d21b3f8 disapproval of revision '8cebefbc6cd5d84acb69c74e69e8821f11dd225d'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24019
diff changeset
832 if (ret < 0 || error != 0) {
23755
23cec4360d4a applied changes from 8cebefbc6cd5d84acb69c74e69e8821f11dd225d
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23754
diff changeset
833 if(ret != 0)
24026
25f62d21b3f8 disapproval of revision '8cebefbc6cd5d84acb69c74e69e8821f11dd225d'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24019
diff changeset
834 error = errno;
25f62d21b3f8 disapproval of revision '8cebefbc6cd5d84acb69c74e69e8821f11dd225d'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24019
diff changeset
835
25f62d21b3f8 disapproval of revision '8cebefbc6cd5d84acb69c74e69e8821f11dd225d'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24019
diff changeset
836 close(source);
25f62d21b3f8 disapproval of revision '8cebefbc6cd5d84acb69c74e69e8821f11dd225d'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24019
diff changeset
837
25f62d21b3f8 disapproval of revision '8cebefbc6cd5d84acb69c74e69e8821f11dd225d'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24019
diff changeset
838 purple_debug_error("proxy", "getsockopt SO_ERROR check: %s\n", g_strerror(error));
25f62d21b3f8 disapproval of revision '8cebefbc6cd5d84acb69c74e69e8821f11dd225d'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24019
diff changeset
839
23755
23cec4360d4a applied changes from 8cebefbc6cd5d84acb69c74e69e8821f11dd225d
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23754
diff changeset
840 connect_cb(gc, -1, _("Unable to connect"));
24026
25f62d21b3f8 disapproval of revision '8cebefbc6cd5d84acb69c74e69e8821f11dd225d'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24019
diff changeset
841 return;
25f62d21b3f8 disapproval of revision '8cebefbc6cd5d84acb69c74e69e8821f11dd225d'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24019
diff changeset
842 }
25f62d21b3f8 disapproval of revision '8cebefbc6cd5d84acb69c74e69e8821f11dd225d'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24019
diff changeset
843
23755
23cec4360d4a applied changes from 8cebefbc6cd5d84acb69c74e69e8821f11dd225d
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23754
diff changeset
844 connect_cb(gc, source, NULL);
24026
25f62d21b3f8 disapproval of revision '8cebefbc6cd5d84acb69c74e69e8821f11dd225d'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24019
diff changeset
845 }
25f62d21b3f8 disapproval of revision '8cebefbc6cd5d84acb69c74e69e8821f11dd225d'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24019
diff changeset
846
25f62d21b3f8 disapproval of revision '8cebefbc6cd5d84acb69c74e69e8821f11dd225d'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24019
diff changeset
847 static void udp_host_resolved(GSList *hosts, gpointer data, const char *error_message) {
25f62d21b3f8 disapproval of revision '8cebefbc6cd5d84acb69c74e69e8821f11dd225d'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24019
diff changeset
848 PurpleConnection *gc;
25f62d21b3f8 disapproval of revision '8cebefbc6cd5d84acb69c74e69e8821f11dd225d'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24019
diff changeset
849 qq_data *qd;
25f62d21b3f8 disapproval of revision '8cebefbc6cd5d84acb69c74e69e8821f11dd225d'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24019
diff changeset
850 struct sockaddr server_addr;
25f62d21b3f8 disapproval of revision '8cebefbc6cd5d84acb69c74e69e8821f11dd225d'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24019
diff changeset
851 int addr_size;
25f62d21b3f8 disapproval of revision '8cebefbc6cd5d84acb69c74e69e8821f11dd225d'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24019
diff changeset
852 gint fd = -1;
25f62d21b3f8 disapproval of revision '8cebefbc6cd5d84acb69c74e69e8821f11dd225d'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24019
diff changeset
853 int flags;
23052
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
854
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
855 gc = (PurpleConnection *) data;
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
856 g_return_if_fail(gc != NULL && gc->proto_data != NULL);
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
857
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
858 qd = (qq_data *) gc->proto_data;
24026
25f62d21b3f8 disapproval of revision '8cebefbc6cd5d84acb69c74e69e8821f11dd225d'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24019
diff changeset
859
25f62d21b3f8 disapproval of revision '8cebefbc6cd5d84acb69c74e69e8821f11dd225d'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24019
diff changeset
860 /* udp_query_data must be set as NULL.
25f62d21b3f8 disapproval of revision '8cebefbc6cd5d84acb69c74e69e8821f11dd225d'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24019
diff changeset
861 * Otherwise purple_dnsquery_destroy in qq_disconnect cause glib double free error */
25f62d21b3f8 disapproval of revision '8cebefbc6cd5d84acb69c74e69e8821f11dd225d'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24019
diff changeset
862 qd->udp_query_data = NULL;
23052
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
863
24026
25f62d21b3f8 disapproval of revision '8cebefbc6cd5d84acb69c74e69e8821f11dd225d'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24019
diff changeset
864 if (!hosts || !hosts->data) {
25f62d21b3f8 disapproval of revision '8cebefbc6cd5d84acb69c74e69e8821f11dd225d'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24019
diff changeset
865 purple_connection_error_reason(gc,
24066
dbc7a9742f8d 2008.09.26 - ccpaging <ccpaging(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24065
diff changeset
866 PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
dbc7a9742f8d 2008.09.26 - ccpaging <ccpaging(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24065
diff changeset
867 _("Couldn't resolve host"));
23052
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
868 return;
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
24026
25f62d21b3f8 disapproval of revision '8cebefbc6cd5d84acb69c74e69e8821f11dd225d'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24019
diff changeset
871 addr_size = GPOINTER_TO_INT(hosts->data);
25f62d21b3f8 disapproval of revision '8cebefbc6cd5d84acb69c74e69e8821f11dd225d'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24019
diff changeset
872 hosts = g_slist_remove(hosts, hosts->data);
25f62d21b3f8 disapproval of revision '8cebefbc6cd5d84acb69c74e69e8821f11dd225d'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24019
diff changeset
873 memcpy(&server_addr, hosts->data, addr_size);
25f62d21b3f8 disapproval of revision '8cebefbc6cd5d84acb69c74e69e8821f11dd225d'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24019
diff changeset
874 g_free(hosts->data);
23755
23cec4360d4a applied changes from 8cebefbc6cd5d84acb69c74e69e8821f11dd225d
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23754
diff changeset
875
24026
25f62d21b3f8 disapproval of revision '8cebefbc6cd5d84acb69c74e69e8821f11dd225d'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24019
diff changeset
876 hosts = g_slist_remove(hosts, hosts->data);
25f62d21b3f8 disapproval of revision '8cebefbc6cd5d84acb69c74e69e8821f11dd225d'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24019
diff changeset
877 while(hosts) {
25f62d21b3f8 disapproval of revision '8cebefbc6cd5d84acb69c74e69e8821f11dd225d'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24019
diff changeset
878 hosts = g_slist_remove(hosts, hosts->data);
25f62d21b3f8 disapproval of revision '8cebefbc6cd5d84acb69c74e69e8821f11dd225d'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24019
diff changeset
879 g_free(hosts->data);
25f62d21b3f8 disapproval of revision '8cebefbc6cd5d84acb69c74e69e8821f11dd225d'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24019
diff changeset
880 hosts = g_slist_remove(hosts, hosts->data);
25f62d21b3f8 disapproval of revision '8cebefbc6cd5d84acb69c74e69e8821f11dd225d'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24019
diff changeset
881 }
25f62d21b3f8 disapproval of revision '8cebefbc6cd5d84acb69c74e69e8821f11dd225d'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24019
diff changeset
882
25f62d21b3f8 disapproval of revision '8cebefbc6cd5d84acb69c74e69e8821f11dd225d'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24019
diff changeset
883 fd = socket(PF_INET, SOCK_DGRAM, 0);
25f62d21b3f8 disapproval of revision '8cebefbc6cd5d84acb69c74e69e8821f11dd225d'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24019
diff changeset
884 if (fd < 0) {
23755
23cec4360d4a applied changes from 8cebefbc6cd5d84acb69c74e69e8821f11dd225d
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23754
diff changeset
885 purple_debug_error("QQ",
24026
25f62d21b3f8 disapproval of revision '8cebefbc6cd5d84acb69c74e69e8821f11dd225d'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24019
diff changeset
886 "Unable to create socket: %s\n", g_strerror(errno));
23052
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
887 return;
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
888 }
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
889
24026
25f62d21b3f8 disapproval of revision '8cebefbc6cd5d84acb69c74e69e8821f11dd225d'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24019
diff changeset
890 /* we use non-blocking mode to speed up connection */
25f62d21b3f8 disapproval of revision '8cebefbc6cd5d84acb69c74e69e8821f11dd225d'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24019
diff changeset
891 flags = fcntl(fd, F_GETFL);
25f62d21b3f8 disapproval of revision '8cebefbc6cd5d84acb69c74e69e8821f11dd225d'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24019
diff changeset
892 fcntl(fd, F_SETFL, flags | O_NONBLOCK);
25f62d21b3f8 disapproval of revision '8cebefbc6cd5d84acb69c74e69e8821f11dd225d'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24019
diff changeset
893 #ifndef _WIN32
25f62d21b3f8 disapproval of revision '8cebefbc6cd5d84acb69c74e69e8821f11dd225d'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24019
diff changeset
894 fcntl(fd, F_SETFD, FD_CLOEXEC);
25f62d21b3f8 disapproval of revision '8cebefbc6cd5d84acb69c74e69e8821f11dd225d'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24019
diff changeset
895 #endif
25f62d21b3f8 disapproval of revision '8cebefbc6cd5d84acb69c74e69e8821f11dd225d'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24019
diff changeset
896
25f62d21b3f8 disapproval of revision '8cebefbc6cd5d84acb69c74e69e8821f11dd225d'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24019
diff changeset
897 /* From Unix-socket-FAQ: http://www.faqs.org/faqs/unix-faq/socket/
25f62d21b3f8 disapproval of revision '8cebefbc6cd5d84acb69c74e69e8821f11dd225d'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24019
diff changeset
898 *
25f62d21b3f8 disapproval of revision '8cebefbc6cd5d84acb69c74e69e8821f11dd225d'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24019
diff changeset
899 * If a UDP socket is unconnected, which is the normal state after a
25f62d21b3f8 disapproval of revision '8cebefbc6cd5d84acb69c74e69e8821f11dd225d'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24019
diff changeset
900 * bind() call, then send() or write() are not allowed, since no
25f62d21b3f8 disapproval of revision '8cebefbc6cd5d84acb69c74e69e8821f11dd225d'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24019
diff changeset
901 * destination is available; only sendto() can be used to send data.
23755
23cec4360d4a applied changes from 8cebefbc6cd5d84acb69c74e69e8821f11dd225d
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23754
diff changeset
902 *
24026
25f62d21b3f8 disapproval of revision '8cebefbc6cd5d84acb69c74e69e8821f11dd225d'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24019
diff changeset
903 * Calling connect() on the socket simply records the specified address
25f62d21b3f8 disapproval of revision '8cebefbc6cd5d84acb69c74e69e8821f11dd225d'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24019
diff changeset
904 * and port number as being the desired communications partner. That
25f62d21b3f8 disapproval of revision '8cebefbc6cd5d84acb69c74e69e8821f11dd225d'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24019
diff changeset
905 * means that send() or write() are now allowed; they use the destination
25f62d21b3f8 disapproval of revision '8cebefbc6cd5d84acb69c74e69e8821f11dd225d'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24019
diff changeset
906 * address and port given on the connect call as the destination of packets.
25f62d21b3f8 disapproval of revision '8cebefbc6cd5d84acb69c74e69e8821f11dd225d'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24019
diff changeset
907 */
25f62d21b3f8 disapproval of revision '8cebefbc6cd5d84acb69c74e69e8821f11dd225d'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24019
diff changeset
908 if (connect(fd, &server_addr, addr_size) >= 0) {
23755
23cec4360d4a applied changes from 8cebefbc6cd5d84acb69c74e69e8821f11dd225d
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23754
diff changeset
909 purple_debug_info("QQ", "Connected.\n");
24026
25f62d21b3f8 disapproval of revision '8cebefbc6cd5d84acb69c74e69e8821f11dd225d'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24019
diff changeset
910 flags = fcntl(fd, F_GETFL);
25f62d21b3f8 disapproval of revision '8cebefbc6cd5d84acb69c74e69e8821f11dd225d'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24019
diff changeset
911 fcntl(fd, F_SETFL, flags & ~O_NONBLOCK);
23755
23cec4360d4a applied changes from 8cebefbc6cd5d84acb69c74e69e8821f11dd225d
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23754
diff changeset
912 connect_cb(gc, fd, NULL);
24026
25f62d21b3f8 disapproval of revision '8cebefbc6cd5d84acb69c74e69e8821f11dd225d'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24019
diff changeset
913 return;
24019
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23774
diff changeset
914 }
23755
23cec4360d4a applied changes from 8cebefbc6cd5d84acb69c74e69e8821f11dd225d
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23754
diff changeset
915
24026
25f62d21b3f8 disapproval of revision '8cebefbc6cd5d84acb69c74e69e8821f11dd225d'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24019
diff changeset
916 /* [EINPROGRESS]
23755
23cec4360d4a applied changes from 8cebefbc6cd5d84acb69c74e69e8821f11dd225d
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23754
diff changeset
917 * The socket is marked as non-blocking and the connection cannot be
23cec4360d4a applied changes from 8cebefbc6cd5d84acb69c74e69e8821f11dd225d
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23754
diff changeset
918 * completed immediately. It is possible to select for completion by
24026
25f62d21b3f8 disapproval of revision '8cebefbc6cd5d84acb69c74e69e8821f11dd225d'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24019
diff changeset
919 * selecting the socket for writing.
25f62d21b3f8 disapproval of revision '8cebefbc6cd5d84acb69c74e69e8821f11dd225d'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24019
diff changeset
920 * [EINTR]
23755
23cec4360d4a applied changes from 8cebefbc6cd5d84acb69c74e69e8821f11dd225d
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23754
diff changeset
921 * A signal interrupted the call.
24026
25f62d21b3f8 disapproval of revision '8cebefbc6cd5d84acb69c74e69e8821f11dd225d'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24019
diff changeset
922 * The connection is established asynchronously.
25f62d21b3f8 disapproval of revision '8cebefbc6cd5d84acb69c74e69e8821f11dd225d'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24019
diff changeset
923 */
25f62d21b3f8 disapproval of revision '8cebefbc6cd5d84acb69c74e69e8821f11dd225d'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24019
diff changeset
924 if ((errno == EINPROGRESS) || (errno == EINTR)) {
23755
23cec4360d4a applied changes from 8cebefbc6cd5d84acb69c74e69e8821f11dd225d
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23754
diff changeset
925 purple_debug_warning( "QQ", "Connect in asynchronous mode.\n");
23cec4360d4a applied changes from 8cebefbc6cd5d84acb69c74e69e8821f11dd225d
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23754
diff changeset
926 qd->udp_can_write_handler = purple_input_add(fd, PURPLE_INPUT_WRITE, udp_can_write, gc);
24026
25f62d21b3f8 disapproval of revision '8cebefbc6cd5d84acb69c74e69e8821f11dd225d'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24019
diff changeset
927 return;
25f62d21b3f8 disapproval of revision '8cebefbc6cd5d84acb69c74e69e8821f11dd225d'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24019
diff changeset
928 }
23052
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
929
23755
23cec4360d4a applied changes from 8cebefbc6cd5d84acb69c74e69e8821f11dd225d
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23754
diff changeset
930 purple_debug_error("QQ", "Connection failed: %s\n", g_strerror(errno));
24026
25f62d21b3f8 disapproval of revision '8cebefbc6cd5d84acb69c74e69e8821f11dd225d'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24019
diff changeset
931 close(fd);
23052
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
932 }
23755
23cec4360d4a applied changes from 8cebefbc6cd5d84acb69c74e69e8821f11dd225d
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23754
diff changeset
933 #endif
23052
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
934
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
935 gboolean connect_to_server(PurpleConnection *gc, gchar *server, gint port)
23052
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
936 {
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
937 PurpleAccount *account ;
23052
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
938 qq_data *qd;
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
939
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
940 g_return_val_if_fail(gc != NULL && gc->proto_data != NULL, FALSE);
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
941 account = purple_connection_get_account(gc);
23052
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
942 qd = (qq_data *) gc->proto_data;
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
943
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
944 if (server == NULL || strlen(server) == 0 || port == 0) {
24066
dbc7a9742f8d 2008.09.26 - ccpaging <ccpaging(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24065
diff changeset
945 purple_connection_error_reason(gc,
dbc7a9742f8d 2008.09.26 - ccpaging <ccpaging(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24065
diff changeset
946 PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
947 _("Invalid server or port"));
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
948 return FALSE;
23053
55f986ccbb6a patch-05-reconnect-and-code-cleanup
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23052
diff changeset
949 }
55f986ccbb6a patch-05-reconnect-and-code-cleanup
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23052
diff changeset
950
24630
8f757b2139d2 String changes (a few of which I had already made, grumble grumble).
Mark Doliner <mark@kingant.net>
parents: 24627
diff changeset
951 purple_connection_update_progress(gc, _("Connecting to server"), 1, QQ_CONNECT_STEPS);
23053
55f986ccbb6a patch-05-reconnect-and-code-cleanup
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23052
diff changeset
952
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
953 purple_debug_info("QQ", "Connect to %s:%d\n", server, port);
23052
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
954
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
955 if (qd->conn_data != NULL) {
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
956 purple_proxy_connect_cancel(qd->conn_data);
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
957 qd->conn_data = NULL;
23052
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
958 }
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
959
23755
23cec4360d4a applied changes from 8cebefbc6cd5d84acb69c74e69e8821f11dd225d
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23754
diff changeset
960 #ifdef purple_proxy_connect_udp
23cec4360d4a applied changes from 8cebefbc6cd5d84acb69c74e69e8821f11dd225d
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23754
diff changeset
961 if (qd->use_tcp) {
23cec4360d4a applied changes from 8cebefbc6cd5d84acb69c74e69e8821f11dd225d
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23754
diff changeset
962 qd->conn_data = purple_proxy_connect(gc, account, server, port, connect_cb, gc);
23cec4360d4a applied changes from 8cebefbc6cd5d84acb69c74e69e8821f11dd225d
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23754
diff changeset
963 } else {
23cec4360d4a applied changes from 8cebefbc6cd5d84acb69c74e69e8821f11dd225d
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23754
diff changeset
964 qd->conn_data = purple_proxy_connect_udp(gc, account, server, port, connect_cb, gc);
23cec4360d4a applied changes from 8cebefbc6cd5d84acb69c74e69e8821f11dd225d
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23754
diff changeset
965 }
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
966 if ( qd->conn_data == NULL ) {
24627
55b7371eadf4 Fix some English in the QQ plugin. And remove some translated phrases that are
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 24601
diff changeset
967 purple_debug_error("QQ", "Couldn't create socket");
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
968 return FALSE;
23052
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
969 }
23755
23cec4360d4a applied changes from 8cebefbc6cd5d84acb69c74e69e8821f11dd225d
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23754
diff changeset
970 #else
23cec4360d4a applied changes from 8cebefbc6cd5d84acb69c74e69e8821f11dd225d
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23754
diff changeset
971 /* QQ connection via UDP/TCP.
24026
25f62d21b3f8 disapproval of revision '8cebefbc6cd5d84acb69c74e69e8821f11dd225d'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24019
diff changeset
972 * Now use Purple proxy function to provide TCP proxy support,
25f62d21b3f8 disapproval of revision '8cebefbc6cd5d84acb69c74e69e8821f11dd225d'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24019
diff changeset
973 * and qq_udp_proxy.c to add UDP proxy support (thanks henry) */
25f62d21b3f8 disapproval of revision '8cebefbc6cd5d84acb69c74e69e8821f11dd225d'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24019
diff changeset
974 if(qd->use_tcp) {
23755
23cec4360d4a applied changes from 8cebefbc6cd5d84acb69c74e69e8821f11dd225d
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23754
diff changeset
975 qd->conn_data = purple_proxy_connect(gc, account, server, port, connect_cb, gc);
23cec4360d4a applied changes from 8cebefbc6cd5d84acb69c74e69e8821f11dd225d
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23754
diff changeset
976 if ( qd->conn_data == NULL ) {
23cec4360d4a applied changes from 8cebefbc6cd5d84acb69c74e69e8821f11dd225d
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23754
diff changeset
977 purple_debug_error("QQ", "Unable to connect.");
23cec4360d4a applied changes from 8cebefbc6cd5d84acb69c74e69e8821f11dd225d
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23754
diff changeset
978 return FALSE;
24026
25f62d21b3f8 disapproval of revision '8cebefbc6cd5d84acb69c74e69e8821f11dd225d'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24019
diff changeset
979 }
23755
23cec4360d4a applied changes from 8cebefbc6cd5d84acb69c74e69e8821f11dd225d
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23754
diff changeset
980 return TRUE;
23052
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
981 }
24026
25f62d21b3f8 disapproval of revision '8cebefbc6cd5d84acb69c74e69e8821f11dd225d'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24019
diff changeset
982
23755
23cec4360d4a applied changes from 8cebefbc6cd5d84acb69c74e69e8821f11dd225d
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23754
diff changeset
983 purple_debug_info("QQ", "UDP Connect to %s:%d\n", server, port);
23cec4360d4a applied changes from 8cebefbc6cd5d84acb69c74e69e8821f11dd225d
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23754
diff changeset
984 qd->udp_query_data = purple_dnsquery_a(server, port, udp_host_resolved, gc);
23cec4360d4a applied changes from 8cebefbc6cd5d84acb69c74e69e8821f11dd225d
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23754
diff changeset
985 if ( qd->udp_query_data == NULL ) {
23cec4360d4a applied changes from 8cebefbc6cd5d84acb69c74e69e8821f11dd225d
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23754
diff changeset
986 purple_debug_error("QQ", "Could not resolve hostname");
23cec4360d4a applied changes from 8cebefbc6cd5d84acb69c74e69e8821f11dd225d
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23754
diff changeset
987 return FALSE;
23052
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
988 }
23755
23cec4360d4a applied changes from 8cebefbc6cd5d84acb69c74e69e8821f11dd225d
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23754
diff changeset
989 #endif
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
990 return TRUE;
23052
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
991 }
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
992
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
993 /* clean up qq_data structure and all its components
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
994 * always used before a redirectly connection */
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
995 void qq_disconnect(PurpleConnection *gc)
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
996 {
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
997 qq_data *qd;
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
998
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
999 g_return_if_fail(gc != NULL && gc->proto_data != NULL);
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
1000 qd = (qq_data *) gc->proto_data;
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
1001
24630
8f757b2139d2 String changes (a few of which I had already made, grumble grumble).
Mark Doliner <mark@kingant.net>
parents: 24627
diff changeset
1002 purple_debug_info("QQ", "Disconnecting...\n");
23683
1c50f12b1c52 2008.08.02 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23606
diff changeset
1003
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
1004 if (qd->network_watcher > 0) {
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
1005 purple_debug_info("QQ", "Remove network watcher\n");
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
1006 purple_timeout_remove(qd->network_watcher);
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
1007 qd->network_watcher = 0;
23683
1c50f12b1c52 2008.08.02 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23606
diff changeset
1008 }
1c50f12b1c52 2008.08.02 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23606
diff changeset
1009
23052
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
1010 /* finish all I/O */
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
1011 if (qd->fd >= 0 && qd->is_login) {
24065
bdfcfd71449c patch 20080922 from ccpaging <ccpaging(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24048
diff changeset
1012 qq_request_logout(gc);
23052
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
1013 }
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
1014
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
1015 /* not connected */
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
1016 if (qd->conn_data != NULL) {
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
1017 purple_debug_info("QQ", "Connect cancel\n");
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
1018 purple_proxy_connect_cancel(qd->conn_data);
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
1019 qd->conn_data = NULL;
23052
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
1020 }
23755
23cec4360d4a applied changes from 8cebefbc6cd5d84acb69c74e69e8821f11dd225d
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23754
diff changeset
1021 #ifndef purple_proxy_connect_udp
23cec4360d4a applied changes from 8cebefbc6cd5d84acb69c74e69e8821f11dd225d
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23754
diff changeset
1022 if (qd->udp_can_write_handler) {
23cec4360d4a applied changes from 8cebefbc6cd5d84acb69c74e69e8821f11dd225d
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23754
diff changeset
1023 purple_input_remove(qd->udp_can_write_handler);
23cec4360d4a applied changes from 8cebefbc6cd5d84acb69c74e69e8821f11dd225d
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23754
diff changeset
1024 qd->udp_can_write_handler = 0;
24026
25f62d21b3f8 disapproval of revision '8cebefbc6cd5d84acb69c74e69e8821f11dd225d'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24019
diff changeset
1025 }
25f62d21b3f8 disapproval of revision '8cebefbc6cd5d84acb69c74e69e8821f11dd225d'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24019
diff changeset
1026 if (qd->udp_query_data != NULL) {
23755
23cec4360d4a applied changes from 8cebefbc6cd5d84acb69c74e69e8821f11dd225d
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23754
diff changeset
1027 purple_debug_info("QQ", "destroy udp_query_data\n");
24026
25f62d21b3f8 disapproval of revision '8cebefbc6cd5d84acb69c74e69e8821f11dd225d'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24019
diff changeset
1028 purple_dnsquery_destroy(qd->udp_query_data);
25f62d21b3f8 disapproval of revision '8cebefbc6cd5d84acb69c74e69e8821f11dd225d'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24019
diff changeset
1029 qd->udp_query_data = NULL;
25f62d21b3f8 disapproval of revision '8cebefbc6cd5d84acb69c74e69e8821f11dd225d'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24019
diff changeset
1030 }
23755
23cec4360d4a applied changes from 8cebefbc6cd5d84acb69c74e69e8821f11dd225d
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23754
diff changeset
1031 #endif
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
1032 connection_free_all(qd);
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
1033 qd->fd = -1;
23052
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
1034
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
1035 qq_trans_remove_all(gc);
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
1036
24066
dbc7a9742f8d 2008.09.26 - ccpaging <ccpaging(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24065
diff changeset
1037 memset(qd->ld.random_key, 0, sizeof(qd->ld.random_key));
24069
dc112387190f 2008.09.29 - ccpaging <ccpaging(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24068
diff changeset
1038 memset(qd->ld.pwd_md5, 0, sizeof(qd->ld.pwd_md5));
dc112387190f 2008.09.29 - ccpaging <ccpaging(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24068
diff changeset
1039 memset(qd->ld.pwd_twice_md5, 0, sizeof(qd->ld.pwd_twice_md5));
24066
dbc7a9742f8d 2008.09.26 - ccpaging <ccpaging(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24065
diff changeset
1040 memset(qd->ld.login_key, 0, sizeof(qd->ld.login_key));
23683
1c50f12b1c52 2008.08.02 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23606
diff changeset
1041 memset(qd->session_key, 0, sizeof(qd->session_key));
1c50f12b1c52 2008.08.02 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23606
diff changeset
1042 memset(qd->session_md5, 0, sizeof(qd->session_md5));
1c50f12b1c52 2008.08.02 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23606
diff changeset
1043
24068
87e61a85f5dd 2008.09.28 - ccpaging <ccpaging(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24066
diff changeset
1044 qd->my_local_ip.s_addr = 0;
87e61a85f5dd 2008.09.28 - ccpaging <ccpaging(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24066
diff changeset
1045 qd->my_local_port = 0;
23683
1c50f12b1c52 2008.08.02 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23606
diff changeset
1046 qd->my_ip.s_addr = 0;
24068
87e61a85f5dd 2008.09.28 - ccpaging <ccpaging(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24066
diff changeset
1047 qd->my_port = 0;
23052
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
1048
24088
1ee91ff0d5fe 2008.10.09 - ccpaging <ccpaging(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24085
diff changeset
1049 qq_room_data_free_all(gc);
24079
1bdf7b602684 2008.10.07 - ccpaging <ccpaging(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24071
diff changeset
1050 qq_buddy_data_free_all(gc);
23052
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
1051 }
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
1052
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
1053 static gint packet_encap(qq_data *qd, guint8 *buf, gint maxlen, guint16 cmd, guint16 seq,
23052
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
1054 guint8 *data, gint data_len)
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
1055 {
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
1056 gint bytes = 0;
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
1057 g_return_val_if_fail(qd != NULL && buf != NULL && maxlen > 0, -1);
23753
5f454b975a99 2008.08.10 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23683
diff changeset
1058 g_return_val_if_fail(data != NULL && data_len > 0, -1);
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
1059
23052
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
1060 /* 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
1061 * so leave room here to store packet size */
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
1062 if (qd->use_tcp) {
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
1063 bytes += qq_put16(buf + bytes, 0x0000);
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
1064 }
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
1065 /* now comes the normal QQ packet as UDP */
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
1066 bytes += qq_put8(buf + bytes, QQ_PACKET_TAG);
24066
dbc7a9742f8d 2008.09.26 - ccpaging <ccpaging(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24065
diff changeset
1067 bytes += qq_put16(buf + bytes, qd->client_tag);
23052
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
1068 bytes += qq_put16(buf + bytes, cmd);
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
1069
23052
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
1070 bytes += qq_put16(buf + bytes, seq);
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
1071
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
1072 bytes += qq_put32(buf + bytes, qd->uid);
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
1073 bytes += qq_putdata(buf + bytes, data, data_len);
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
1074 bytes += qq_put8(buf + bytes, QQ_PACKET_TAIL);
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
1075
23053
55f986ccbb6a patch-05-reconnect-and-code-cleanup
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23052
diff changeset
1076 /* set TCP packet length at begin of the packet */
23052
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
1077 if (qd->use_tcp) {
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
1078 qq_put16(buf, bytes);
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
1079 }
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
1080
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
1081 return bytes;
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
1082 }
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
1083
23683
1c50f12b1c52 2008.08.02 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23606
diff changeset
1084 /* data has been encrypted before */
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
1085 static gint packet_send_out(PurpleConnection *gc, guint16 cmd, guint16 seq, guint8 *data, gint data_len)
23052
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
1086 {
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
1087 qq_data *qd;
23052
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
1088 guint8 *buf;
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
1089 gint buf_len;
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
1090 gint bytes_sent;
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
1091
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
1092 g_return_val_if_fail(gc != NULL && gc->proto_data != NULL, -1);
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
1093 qd = (qq_data *)gc->proto_data;
23053
55f986ccbb6a patch-05-reconnect-and-code-cleanup
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23052
diff changeset
1094 g_return_val_if_fail(data != NULL && data_len > 0, -1);
55f986ccbb6a patch-05-reconnect-and-code-cleanup
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23052
diff changeset
1095
23052
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
1096 buf = g_newa(guint8, MAX_PACKET_SIZE);
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
1097 memset(buf, 0, MAX_PACKET_SIZE);
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
1098 buf_len = packet_encap(qd, buf, MAX_PACKET_SIZE, cmd, seq, data, data_len);
23052
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
1099 if (buf_len <= 0) {
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
1100 return -1;
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
1101 }
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
1102
23757
69c218fd5d54 applied changes from 5688199e261449d33b5803dafff50d860896ebcb
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23756
diff changeset
1103 qd->net_stat.sent++;
23052
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
1104 if (qd->use_tcp) {
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
1105 bytes_sent = tcp_send_out(gc, buf, buf_len);
23052
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
1106 } else {
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
1107 bytes_sent = udp_send_out(gc, buf, buf_len);
23052
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
1108 }
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
1109
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
1110 return bytes_sent;
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
1111 }
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
1112
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
1113 gint qq_send_cmd_encrypted(PurpleConnection *gc, guint16 cmd, guint16 seq,
24066
dbc7a9742f8d 2008.09.26 - ccpaging <ccpaging(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24065
diff changeset
1114 guint8 *encrypted, gint encrypted_len, gboolean is_save2trans)
23052
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
1115 {
23756
1a0caf9983fa applied changes from 92d52eef2994d2697999177804e3665989cfa352
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23755
diff changeset
1116 gint sent_len;
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
1117
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
1118 #if 1
23756
1a0caf9983fa applied changes from 92d52eef2994d2697999177804e3665989cfa352
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23755
diff changeset
1119 /* qq_show_packet("qq_send_cmd_encrypted", data, data_len); */
24586
c69c337269e1 Clean debug info
Hu Yong <ccpaging@gmail.com>
parents: 24571
diff changeset
1120 purple_debug_info("QQ", "<== [%05d] %s(0x%04X), datalen %d\n",
23756
1a0caf9983fa applied changes from 92d52eef2994d2697999177804e3665989cfa352
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23755
diff changeset
1121 seq, qq_get_cmd_desc(cmd), cmd, encrypted_len);
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
1122 #endif
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
1123
24066
dbc7a9742f8d 2008.09.26 - ccpaging <ccpaging(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24065
diff changeset
1124 sent_len = packet_send_out(gc, cmd, seq, encrypted, encrypted_len);
23756
1a0caf9983fa applied changes from 92d52eef2994d2697999177804e3665989cfa352
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23755
diff changeset
1125 if (is_save2trans) {
24066
dbc7a9742f8d 2008.09.26 - ccpaging <ccpaging(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24065
diff changeset
1126 qq_trans_add_client_cmd(gc, cmd, seq, encrypted, encrypted_len, 0, 0);
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
1127 }
23756
1a0caf9983fa applied changes from 92d52eef2994d2697999177804e3665989cfa352
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23755
diff changeset
1128 return sent_len;
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
1129 }
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
1130
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
1131 /* Encrypt data with session_key, and send packet out */
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
1132 static gint send_cmd_detail(PurpleConnection *gc, guint16 cmd, guint16 seq,
25149
7da3cf2530b7 2009.02.21 - flos <lonicerae(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 25070
diff changeset
1133 guint8 *data, gint data_len, gboolean is_save2trans,
7da3cf2530b7 2009.02.21 - flos <lonicerae(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 25070
diff changeset
1134 guint32 update_class, guint32 ship32)
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
1135 {
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
1136 qq_data *qd;
24066
dbc7a9742f8d 2008.09.26 - ccpaging <ccpaging(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24065
diff changeset
1137 guint8 *encrypted;
23052
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
1138 gint encrypted_len;
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
1139 gint bytes_sent;
23052
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
1140
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
1141 g_return_val_if_fail(gc != NULL && gc->proto_data != NULL, -1);
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
1142 qd = (qq_data *)gc->proto_data;
23053
55f986ccbb6a patch-05-reconnect-and-code-cleanup
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23052
diff changeset
1143 g_return_val_if_fail(data != NULL && data_len > 0, -1);
23052
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
1144
23753
5f454b975a99 2008.08.10 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23683
diff changeset
1145 /* at most 16 bytes more */
24066
dbc7a9742f8d 2008.09.26 - ccpaging <ccpaging(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24065
diff changeset
1146 encrypted = g_newa(guint8, data_len + 16);
dbc7a9742f8d 2008.09.26 - ccpaging <ccpaging(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24065
diff changeset
1147 encrypted_len = qq_encrypt(encrypted, data, data_len, qd->session_key);
23753
5f454b975a99 2008.08.10 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23683
diff changeset
1148 if (encrypted_len < 16) {
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
1149 purple_debug_error("QQ_ENCRYPT", "Error len %d: [%05d] 0x%04X %s\n",
23753
5f454b975a99 2008.08.10 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23683
diff changeset
1150 encrypted_len, seq, cmd, qq_get_cmd_desc(cmd));
5f454b975a99 2008.08.10 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23683
diff changeset
1151 return -1;
5f454b975a99 2008.08.10 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23683
diff changeset
1152 }
23052
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
1153
24066
dbc7a9742f8d 2008.09.26 - ccpaging <ccpaging(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24065
diff changeset
1154 bytes_sent = packet_send_out(gc, cmd, seq, encrypted, encrypted_len);
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
1155
23756
1a0caf9983fa applied changes from 92d52eef2994d2697999177804e3665989cfa352
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23755
diff changeset
1156 if (is_save2trans) {
24066
dbc7a9742f8d 2008.09.26 - ccpaging <ccpaging(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24065
diff changeset
1157 qq_trans_add_client_cmd(gc, cmd, seq, encrypted, encrypted_len,
23756
1a0caf9983fa applied changes from 92d52eef2994d2697999177804e3665989cfa352
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23755
diff changeset
1158 update_class, ship32);
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
1159 }
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
1160 return bytes_sent;
23052
51dbe83ebbd3 patch-04-tcp-pending
SHiNE CsyFeK <csyfek@gmail.com>
parents:
diff changeset
1161 }
23053
55f986ccbb6a patch-05-reconnect-and-code-cleanup
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23052
diff changeset
1162
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
1163 gint qq_send_cmd_mess(PurpleConnection *gc, guint16 cmd, guint8 *data, gint data_len,
25149
7da3cf2530b7 2009.02.21 - flos <lonicerae(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 25070
diff changeset
1164 guint32 update_class, guint32 ship32)
23053
55f986ccbb6a patch-05-reconnect-and-code-cleanup
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23052
diff changeset
1165 {
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
1166 qq_data *qd;
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
1167 guint16 seq;
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
1168
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
1169 g_return_val_if_fail(gc != NULL && gc->proto_data != NULL, -1);
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
1170 qd = (qq_data *) gc->proto_data;
23053
55f986ccbb6a patch-05-reconnect-and-code-cleanup
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23052
diff changeset
1171 g_return_val_if_fail(data != NULL && data_len > 0, -1);
55f986ccbb6a patch-05-reconnect-and-code-cleanup
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23052
diff changeset
1172
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
1173 seq = ++qd->send_seq;
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
1174 #if 1
24586
c69c337269e1 Clean debug info
Hu Yong <ccpaging@gmail.com>
parents: 24571
diff changeset
1175 purple_debug_info("QQ", "<== [%05d] %s(0x%04X), datalen %d\n",
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
1176 seq, qq_get_cmd_desc(cmd), cmd, data_len);
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
1177 #endif
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
1178 return send_cmd_detail(gc, cmd, seq, data, data_len, TRUE, update_class, ship32);
23053
55f986ccbb6a patch-05-reconnect-and-code-cleanup
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23052
diff changeset
1179 }
23753
5f454b975a99 2008.08.10 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23683
diff changeset
1180
23756
1a0caf9983fa applied changes from 92d52eef2994d2697999177804e3665989cfa352
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23755
diff changeset
1181 /* set seq and is_save2trans, then call send_cmd_detail */
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
1182 gint qq_send_cmd(PurpleConnection *gc, guint16 cmd, guint8 *data, gint data_len)
24026
25f62d21b3f8 disapproval of revision '8cebefbc6cd5d84acb69c74e69e8821f11dd225d'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24019
diff changeset
1183 {
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
1184 qq_data *qd;
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
1185 guint16 seq;
23756
1a0caf9983fa applied changes from 92d52eef2994d2697999177804e3665989cfa352
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23755
diff changeset
1186 gboolean is_save2trans;
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
1187
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
1188 g_return_val_if_fail(gc != NULL && gc->proto_data != NULL, -1);
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
1189 qd = (qq_data *) gc->proto_data;
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
1190 g_return_val_if_fail(data != NULL && data_len > 0, -1);
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
1191
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
1192 if (cmd != QQ_CMD_LOGOUT) {
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
1193 seq = ++qd->send_seq;
23756
1a0caf9983fa applied changes from 92d52eef2994d2697999177804e3665989cfa352
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23755
diff changeset
1194 is_save2trans = TRUE;
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
1195 } else {
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
1196 seq = 0xFFFF;
23756
1a0caf9983fa applied changes from 92d52eef2994d2697999177804e3665989cfa352
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23755
diff changeset
1197 is_save2trans = FALSE;
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
1198 }
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
1199 #if 1
24586
c69c337269e1 Clean debug info
Hu Yong <ccpaging@gmail.com>
parents: 24571
diff changeset
1200 purple_debug_info("QQ", "<== [%05d] %s(0x%04X), datalen %d\n",
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
1201 seq, qq_get_cmd_desc(cmd), cmd, data_len);
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
1202 #endif
23756
1a0caf9983fa applied changes from 92d52eef2994d2697999177804e3665989cfa352
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23755
diff changeset
1203 return send_cmd_detail(gc, cmd, seq, data, data_len, is_save2trans, 0, 0);
24026
25f62d21b3f8 disapproval of revision '8cebefbc6cd5d84acb69c74e69e8821f11dd225d'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24019
diff changeset
1204 }
25f62d21b3f8 disapproval of revision '8cebefbc6cd5d84acb69c74e69e8821f11dd225d'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24019
diff changeset
1205
23756
1a0caf9983fa applied changes from 92d52eef2994d2697999177804e3665989cfa352
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23755
diff changeset
1206 /* set seq and is_save2trans, then call send_cmd_detail */
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
1207 gint qq_send_server_reply(PurpleConnection *gc, guint16 cmd, guint16 seq, guint8 *data, gint data_len)
24026
25f62d21b3f8 disapproval of revision '8cebefbc6cd5d84acb69c74e69e8821f11dd225d'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24019
diff changeset
1208 {
23756
1a0caf9983fa applied changes from 92d52eef2994d2697999177804e3665989cfa352
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23755
diff changeset
1209 qq_data *qd;
24066
dbc7a9742f8d 2008.09.26 - ccpaging <ccpaging(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24065
diff changeset
1210 guint8 *encrypted;
23756
1a0caf9983fa applied changes from 92d52eef2994d2697999177804e3665989cfa352
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23755
diff changeset
1211 gint encrypted_len;
1a0caf9983fa applied changes from 92d52eef2994d2697999177804e3665989cfa352
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23755
diff changeset
1212 gint bytes_sent;
1a0caf9983fa applied changes from 92d52eef2994d2697999177804e3665989cfa352
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23755
diff changeset
1213
1a0caf9983fa applied changes from 92d52eef2994d2697999177804e3665989cfa352
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23755
diff changeset
1214 g_return_val_if_fail(gc != NULL && gc->proto_data != NULL, -1);
1a0caf9983fa applied changes from 92d52eef2994d2697999177804e3665989cfa352
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23755
diff changeset
1215 qd = (qq_data *)gc->proto_data;
1a0caf9983fa applied changes from 92d52eef2994d2697999177804e3665989cfa352
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23755
diff changeset
1216 g_return_val_if_fail(data != NULL && data_len > 0, -1);
1a0caf9983fa applied changes from 92d52eef2994d2697999177804e3665989cfa352
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23755
diff changeset
1217
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
1218 #if 1
24586
c69c337269e1 Clean debug info
Hu Yong <ccpaging@gmail.com>
parents: 24571
diff changeset
1219 purple_debug_info("QQ", "<== [SRV-%05d] %s(0x%04X), datalen %d\n",
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
1220 seq, qq_get_cmd_desc(cmd), cmd, data_len);
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
1221 #endif
23756
1a0caf9983fa applied changes from 92d52eef2994d2697999177804e3665989cfa352
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23755
diff changeset
1222 /* at most 16 bytes more */
24066
dbc7a9742f8d 2008.09.26 - ccpaging <ccpaging(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24065
diff changeset
1223 encrypted = g_newa(guint8, data_len + 16);
dbc7a9742f8d 2008.09.26 - ccpaging <ccpaging(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24065
diff changeset
1224 encrypted_len = qq_encrypt(encrypted, data, data_len, qd->session_key);
23756
1a0caf9983fa applied changes from 92d52eef2994d2697999177804e3665989cfa352
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23755
diff changeset
1225 if (encrypted_len < 16) {
1a0caf9983fa applied changes from 92d52eef2994d2697999177804e3665989cfa352
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23755
diff changeset
1226 purple_debug_error("QQ_ENCRYPT", "Error len %d: [%05d] 0x%04X %s\n",
1a0caf9983fa applied changes from 92d52eef2994d2697999177804e3665989cfa352
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23755
diff changeset
1227 encrypted_len, seq, cmd, qq_get_cmd_desc(cmd));
1a0caf9983fa applied changes from 92d52eef2994d2697999177804e3665989cfa352
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23755
diff changeset
1228 return -1;
1a0caf9983fa applied changes from 92d52eef2994d2697999177804e3665989cfa352
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23755
diff changeset
1229 }
1a0caf9983fa applied changes from 92d52eef2994d2697999177804e3665989cfa352
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23755
diff changeset
1230
24066
dbc7a9742f8d 2008.09.26 - ccpaging <ccpaging(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24065
diff changeset
1231 bytes_sent = packet_send_out(gc, cmd, seq, encrypted, encrypted_len);
dbc7a9742f8d 2008.09.26 - ccpaging <ccpaging(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24065
diff changeset
1232 qq_trans_add_server_reply(gc, cmd, seq, encrypted, encrypted_len);
23756
1a0caf9983fa applied changes from 92d52eef2994d2697999177804e3665989cfa352
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23755
diff changeset
1233
1a0caf9983fa applied changes from 92d52eef2994d2697999177804e3665989cfa352
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23755
diff changeset
1234 return bytes_sent;
24026
25f62d21b3f8 disapproval of revision '8cebefbc6cd5d84acb69c74e69e8821f11dd225d'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24019
diff changeset
1235 }
25f62d21b3f8 disapproval of revision '8cebefbc6cd5d84acb69c74e69e8821f11dd225d'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24019
diff changeset
1236
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
1237 static gint send_room_cmd(PurpleConnection *gc, guint8 room_cmd, guint32 room_id,
25149
7da3cf2530b7 2009.02.21 - flos <lonicerae(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 25070
diff changeset
1238 guint8 *data, gint data_len, guint32 update_class, guint32 ship32)
23753
5f454b975a99 2008.08.10 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23683
diff changeset
1239 {
24019
147ada94a1d8 2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23774
diff changeset
1240 qq_data *qd;
23753
5f454b975a99 2008.08.10 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23683
diff changeset
1241 guint8 *buf;
5f454b975a99 2008.08.10 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23683
diff changeset
1242 gint buf_len;
24066
dbc7a9742f8d 2008.09.26 - ccpaging <ccpaging(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24065
diff changeset
1243 guint8 *encrypted;
23753
5f454b975a99 2008.08.10 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23683
diff changeset
1244 gint encrypted_len;
5f454b975a99 2008.08.10 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23683
diff changeset
1245 gint bytes_sent;
5f454b975a99 2008.08.10 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23683
diff changeset
1246 guint16 seq;
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
1247
23753
5f454b975a99 2008.08.10 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23683
diff changeset
1248 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: 23683
diff changeset
1249 qd = (qq_data *) gc->proto_data;
5f454b975a99 2008.08.10 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23683
diff changeset
1250
5f454b975a99 2008.08.10 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23683
diff changeset
1251 buf = g_newa(guint8, MAX_PACKET_SIZE);
5f454b975a99 2008.08.10 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23683
diff changeset
1252 memset(buf, 0, MAX_PACKET_SIZE);
5f454b975a99 2008.08.10 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23683
diff changeset
1253
5f454b975a99 2008.08.10 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23683
diff changeset
1254 /* encap room_cmd and room id to buf*/
5f454b975a99 2008.08.10 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23683
diff changeset
1255 buf_len = 0;
5f454b975a99 2008.08.10 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23683
diff changeset
1256 buf_len += qq_put8(buf + buf_len, room_cmd);
5f454b975a99 2008.08.10 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23683
diff changeset
1257 if (room_id != 0) {
24595
6591f7056b3a Code clean
Hu Yong <ccpaging@gmail.com>
parents: 24586
diff changeset
1258 /* id 0 is for QQ Demo Group, now they are closed*/
23753
5f454b975a99 2008.08.10 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23683
diff changeset
1259 buf_len += qq_put32(buf + buf_len, room_id);
5f454b975a99 2008.08.10 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23683
diff changeset
1260 }
5f454b975a99 2008.08.10 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23683
diff changeset
1261 if (data != NULL && data_len > 0) {
5f454b975a99 2008.08.10 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23683
diff changeset
1262 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: 23683
diff changeset
1263 }
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
1264
23753
5f454b975a99 2008.08.10 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23683
diff changeset
1265 qd->send_seq++;
5f454b975a99 2008.08.10 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23683
diff changeset
1266 seq = qd->send_seq;
5f454b975a99 2008.08.10 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23683
diff changeset
1267
24066
dbc7a9742f8d 2008.09.26 - ccpaging <ccpaging(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24065
diff changeset
1268 /* Encrypt to encrypted with session_key */
23753
5f454b975a99 2008.08.10 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23683
diff changeset
1269 /* at most 16 bytes more */
24066
dbc7a9742f8d 2008.09.26 - ccpaging <ccpaging(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24065
diff changeset
1270 encrypted = g_newa(guint8, buf_len + 16);
dbc7a9742f8d 2008.09.26 - ccpaging <ccpaging(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24065
diff changeset
1271 encrypted_len = qq_encrypt(encrypted, buf, buf_len, qd->session_key);
23753
5f454b975a99 2008.08.10 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23683
diff changeset
1272 if (encrypted_len < 16) {
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
1273 purple_debug_error("QQ_ENCRYPT", "Error len %d: [%05d] %s (0x%02X)\n",
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
1274 encrypted_len, seq, qq_get_room_cmd_desc(room_cmd), room_cmd);
23753
5f454b975a99 2008.08.10 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23683
diff changeset
1275 return -1;
5f454b975a99 2008.08.10 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23683
diff changeset
1276 }
5f454b975a99 2008.08.10 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23683
diff changeset
1277
24066
dbc7a9742f8d 2008.09.26 - ccpaging <ccpaging(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24065
diff changeset
1278 bytes_sent = packet_send_out(gc, QQ_CMD_ROOM, seq, encrypted, encrypted_len);
23753
5f454b975a99 2008.08.10 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23683
diff changeset
1279 #if 1
23756
1a0caf9983fa applied changes from 92d52eef2994d2697999177804e3665989cfa352
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23755
diff changeset
1280 /* qq_show_packet("send_room_cmd", buf, buf_len); */
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
1281 purple_debug_info("QQ",
24586
c69c337269e1 Clean debug info
Hu Yong <ccpaging@gmail.com>
parents: 24571
diff changeset
1282 "<== [%05d] %s (0x%02X) to room %d, datalen %d\n",
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
1283 seq, qq_get_room_cmd_desc(room_cmd), room_cmd, room_id, buf_len);
23753
5f454b975a99 2008.08.10 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23683
diff changeset
1284 #endif
24026
25f62d21b3f8 disapproval of revision '8cebefbc6cd5d84acb69c74e69e8821f11dd225d'
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24019
diff changeset
1285
24066
dbc7a9742f8d 2008.09.26 - ccpaging <ccpaging(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24065
diff changeset
1286 qq_trans_add_room_cmd(gc, seq, room_cmd, room_id, encrypted, encrypted_len,
23756
1a0caf9983fa applied changes from 92d52eef2994d2697999177804e3665989cfa352
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23755
diff changeset
1287 update_class, ship32);
23753
5f454b975a99 2008.08.10 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23683
diff changeset
1288 return bytes_sent;
5f454b975a99 2008.08.10 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23683
diff changeset
1289 }
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
1290
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
1291 gint qq_send_room_cmd_mess(PurpleConnection *gc, guint8 room_cmd, guint32 room_id,
25149
7da3cf2530b7 2009.02.21 - flos <lonicerae(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 25070
diff changeset
1292 guint8 *data, gint data_len, guint32 update_class, guint32 ship32)
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
1293 {
24085
237e5a94e11c 2008.10.08 - ccpaging <ccpaging(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24079
diff changeset
1294 g_return_val_if_fail(room_cmd > 0, -1);
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
1295 return send_room_cmd(gc, room_cmd, room_id, data, data_len, update_class, ship32);
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
1296 }
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
1297
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
1298 gint qq_send_room_cmd(PurpleConnection *gc, guint8 room_cmd, guint32 room_id,
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
1299 guint8 *data, gint data_len)
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
1300 {
24085
237e5a94e11c 2008.10.08 - ccpaging <ccpaging(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24079
diff changeset
1301 g_return_val_if_fail(room_cmd > 0 && room_id > 0, -1);
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
1302 return send_room_cmd(gc, room_cmd, room_id, data, data_len, 0, 0);
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
1303 }
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
1304
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
1305 gint qq_send_room_cmd_noid(PurpleConnection *gc, guint8 room_cmd,
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
1306 guint8 *data, gint data_len)
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
1307 {
24085
237e5a94e11c 2008.10.08 - ccpaging <ccpaging(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents: 24079
diff changeset
1308 g_return_val_if_fail(room_cmd > 0, -1);
23754
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
1309 return send_room_cmd(gc, room_cmd, 0, data, data_len, 0, 0);
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
1310 }
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
1311
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
1312 gint qq_send_room_cmd_only(PurpleConnection *gc, guint8 room_cmd, guint32 room_id)
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
1313 {
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
1314 g_return_val_if_fail(room_cmd > 0 && room_id > 0, -1);
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
1315 return send_room_cmd(gc, room_cmd, room_id, NULL, 0, 0, 0);
967344bc404d applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents: 23753
diff changeset
1316 }