annotate src/protocols/qq/login_logout.c @ 14142:89d043d547cc

[gaim-migrate @ 16784] Never allow Yahoo! to insert a NULL value into the outgoing packet hash. This fixes some random crashes when the packet gets sent, and yahoo_packet_length() is called, which eventually calls strlen(NULL), which crashes committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Wed, 16 Aug 2006 06:58:59 +0000
parents ef8490f9e823
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
13870
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
1 /**
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
2 * The QQ2003C protocol plugin
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
3 *
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
4 * for gaim
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
5 *
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
6 * Copyright (C) 2004 Puzzlebird
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
7 *
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
8 * This program is free software; you can redistribute it and/or modify
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
9 * it under the terms of the GNU General Public License as published by
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
10 * the Free Software Foundation; either version 2 of the License, or
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
11 * (at your option) any later version.
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
12 *
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
13 * This program is distributed in the hope that it will be useful,
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
16 * GNU General Public License for more details.
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
17 *
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
18 * You should have received a copy of the GNU General Public License
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
19 * along with this program; if not, write to the Free Software
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
21 */
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
22
14021
ef8490f9e823 [gaim-migrate @ 16618]
Mark Huetsch <markhuetsch>
parents: 14013
diff changeset
23 #include "debug.h"
ef8490f9e823 [gaim-migrate @ 16618]
Mark Huetsch <markhuetsch>
parents: 14013
diff changeset
24 #include "internal.h"
ef8490f9e823 [gaim-migrate @ 16618]
Mark Huetsch <markhuetsch>
parents: 14013
diff changeset
25 #include "server.h"
13870
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
26
14021
ef8490f9e823 [gaim-migrate @ 16618]
Mark Huetsch <markhuetsch>
parents: 14013
diff changeset
27 #include "buddy_info.h"
ef8490f9e823 [gaim-migrate @ 16618]
Mark Huetsch <markhuetsch>
parents: 14013
diff changeset
28 #include "buddy_list.h"
ef8490f9e823 [gaim-migrate @ 16618]
Mark Huetsch <markhuetsch>
parents: 14013
diff changeset
29 #include "buddy_status.h"
ef8490f9e823 [gaim-migrate @ 16618]
Mark Huetsch <markhuetsch>
parents: 14013
diff changeset
30 #include "char_conv.h"
ef8490f9e823 [gaim-migrate @ 16618]
Mark Huetsch <markhuetsch>
parents: 14013
diff changeset
31 #include "crypt.h"
ef8490f9e823 [gaim-migrate @ 16618]
Mark Huetsch <markhuetsch>
parents: 14013
diff changeset
32 #include "group.h"
ef8490f9e823 [gaim-migrate @ 16618]
Mark Huetsch <markhuetsch>
parents: 14013
diff changeset
33 #include "header_info.h"
13870
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
34 #include "login_logout.h"
14021
ef8490f9e823 [gaim-migrate @ 16618]
Mark Huetsch <markhuetsch>
parents: 14013
diff changeset
35 #include "packet_parse.h"
ef8490f9e823 [gaim-migrate @ 16618]
Mark Huetsch <markhuetsch>
parents: 14013
diff changeset
36 #include "qq.h"
ef8490f9e823 [gaim-migrate @ 16618]
Mark Huetsch <markhuetsch>
parents: 14013
diff changeset
37 #include "qq_proxy.h"
ef8490f9e823 [gaim-migrate @ 16618]
Mark Huetsch <markhuetsch>
parents: 14013
diff changeset
38 #include "send_core.h"
ef8490f9e823 [gaim-migrate @ 16618]
Mark Huetsch <markhuetsch>
parents: 14013
diff changeset
39 #include "utils.h"
13870
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
40
14013
e9fe337fa9aa [gaim-migrate @ 16605]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
41 #define QQ_LOGIN_DATA_LENGTH 416
13870
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
42 #define QQ_LOGIN_REPLY_OK_PACKET_LEN 139
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
43 #define QQ_LOGIN_REPLY_REDIRECT_PACKET_LEN 11
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
44
14013
e9fe337fa9aa [gaim-migrate @ 16605]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
45 #define QQ_REQUEST_LOGIN_TOKEN_REPLY_OK 0x00
13870
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
46
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
47 #define QQ_LOGIN_REPLY_OK 0x00
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
48 #define QQ_LOGIN_REPLY_REDIRECT 0x01
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
49 #define QQ_LOGIN_REPLY_PWD_ERROR 0x05
14021
ef8490f9e823 [gaim-migrate @ 16618]
Mark Huetsch <markhuetsch>
parents: 14013
diff changeset
50 #define QQ_LOGIN_REPLY_MISC_ERROR 0xff /* defined by myself */
13870
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
51
14021
ef8490f9e823 [gaim-migrate @ 16618]
Mark Huetsch <markhuetsch>
parents: 14013
diff changeset
52 /* for QQ 2003iii 0117, fixed value */
13870
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
53 /* static const guint8 login_23_51[29] = {
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
54 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
55 0x00, 0x00, 0x00, 0x00, 0xbf, 0x14, 0x11, 0x20,
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
56 0x03, 0x9d, 0xb2, 0xe6, 0xb3, 0x11, 0xb7, 0x13,
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
57 0x95, 0x67, 0xda, 0x2c, 0x01
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
58 }; */
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
59
14021
ef8490f9e823 [gaim-migrate @ 16618]
Mark Huetsch <markhuetsch>
parents: 14013
diff changeset
60 /* for QQ 2003iii 0304, fixed value */
13870
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
61 /*
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
62 static const guint8 login_23_51[29] = {
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
63 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
64 0x00, 0x00, 0x00, 0x00, 0x9a, 0x93, 0xfe, 0x85,
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
65 0xd3, 0xd9, 0x2a, 0x41, 0xc8, 0x0d, 0xff, 0xb6,
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
66 0x40, 0xb8, 0xac, 0x32, 0x01
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
67 };
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
68 */
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
69
14021
ef8490f9e823 [gaim-migrate @ 16618]
Mark Huetsch <markhuetsch>
parents: 14013
diff changeset
70 /* for QQ 2005? copy from lumaqq */
13870
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
71 static const gint8 login_23_51[29] = {
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
72 0, 0, 0,
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
73 0, 0, 0, 0, 0, 0, 0, 0, 0, -122,
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
74 -52, 76, 53, 44, -45, 115, 108, 20, -10, -10,
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
75 -81, -61, -6, 51, -92, 1
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
76 };
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
77
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
78 static const gint8 login_53_68[16] = {
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
79 -115, -117, -6, -20, -43, 82, 23, 74, -122, -7,
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
80 -89, 117, -26, 50, -47, 109
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
81 };
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
82
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
83 static const gint8 login_100_bytes[100] = {
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
84 64,
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
85 11, 4, 2, 0, 1, 0, 0, 0, 0, 0,
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
86 3, 9, 0, 0, 0, 0, 0, 0, 0, 1,
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
87 -23, 3, 1, 0, 0, 0, 0, 0, 1, -13,
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
88 3, 0, 0, 0, 0, 0, 0, 1, -19, 3,
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
89 0, 0, 0, 0, 0, 0, 1, -20, 3, 0,
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
90 0, 0, 0, 0, 0, 3, 5, 0, 0, 0,
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
91 0, 0, 0, 0, 3, 7, 0, 0, 0, 0,
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
92 0, 0, 0, 1, -18, 3, 0, 0, 0, 0,
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
93 0, 0, 1, -17, 3, 0, 0, 0, 0, 0,
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
94 0, 1, -21, 3, 0, 0, 0, 0, 0
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
95 };
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
96
14021
ef8490f9e823 [gaim-migrate @ 16618]
Mark Huetsch <markhuetsch>
parents: 14013
diff changeset
97 /* fixed value, not affected by version, or mac address */
13870
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
98 /*
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
99 static const guint8 login_53_68[16] = {
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
100 0x82, 0x2a, 0x91, 0xfd, 0xa5, 0xca, 0x67, 0x4c,
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
101 0xac, 0x81, 0x1f, 0x6f, 0x52, 0x05, 0xa7, 0xbf
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
102 };
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
103 */
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
104
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
105
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
106 typedef struct _qq_login_reply_ok qq_login_reply_ok_packet;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
107 typedef struct _qq_login_reply_redirect qq_login_reply_redirect_packet;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
108
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
109 struct _qq_login_reply_ok {
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
110 guint8 result;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
111 guint8 *session_key;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
112 guint32 uid;
14021
ef8490f9e823 [gaim-migrate @ 16618]
Mark Huetsch <markhuetsch>
parents: 14013
diff changeset
113 guint8 client_ip[4]; /* those detected by server */
13870
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
114 guint16 client_port;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
115 guint8 server_ip[4];
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
116 guint16 server_port;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
117 time_t login_time;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
118 guint8 unknown1[26];
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
119 guint8 unknown_server1_ip[4];
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
120 guint16 unknown_server1_port;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
121 guint8 unknown_server2_ip[4];
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
122 guint16 unknown_server2_port;
14021
ef8490f9e823 [gaim-migrate @ 16618]
Mark Huetsch <markhuetsch>
parents: 14013
diff changeset
123 guint16 unknown2; /* 0x0001 */
ef8490f9e823 [gaim-migrate @ 16618]
Mark Huetsch <markhuetsch>
parents: 14013
diff changeset
124 guint16 unknown3; /* 0x0000 */
13870
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
125 guint8 unknown4[32];
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
126 guint8 unknown5[12];
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
127 guint8 last_client_ip[4];
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
128 time_t last_login_time;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
129 guint8 unknown6[8];
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
130 };
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
131
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
132 struct _qq_login_reply_redirect {
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
133 guint8 result;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
134 guint32 uid;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
135 guint8 new_server_ip[4];
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
136 guint16 new_server_port;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
137 };
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
138
14021
ef8490f9e823 [gaim-migrate @ 16618]
Mark Huetsch <markhuetsch>
parents: 14013
diff changeset
139 extern gint /* defined in send_core.c */
ef8490f9e823 [gaim-migrate @ 16618]
Mark Huetsch <markhuetsch>
parents: 14013
diff changeset
140 _create_packet_head_seq(guint8 *buf,
ef8490f9e823 [gaim-migrate @ 16618]
Mark Huetsch <markhuetsch>
parents: 14013
diff changeset
141 guint8 **cursor, GaimConnection *gc, guint16 cmd, gboolean is_auto_seq, guint16 *seq);
ef8490f9e823 [gaim-migrate @ 16618]
Mark Huetsch <markhuetsch>
parents: 14013
diff changeset
142 extern gint /* defined in send_core.c */
ef8490f9e823 [gaim-migrate @ 16618]
Mark Huetsch <markhuetsch>
parents: 14013
diff changeset
143 _qq_send_packet(GaimConnection *gc, guint8 *buf, gint len, guint16 cmd);
13870
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
144
14021
ef8490f9e823 [gaim-migrate @ 16618]
Mark Huetsch <markhuetsch>
parents: 14013
diff changeset
145 /* It is fixed to 16 bytes 0x01 for QQ2003,
ef8490f9e823 [gaim-migrate @ 16618]
Mark Huetsch <markhuetsch>
parents: 14013
diff changeset
146 * Any value works (or a random 16 bytes string) */
14013
e9fe337fa9aa [gaim-migrate @ 16605]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
147 static guint8 *_gen_login_key(void)
13870
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
148 {
14013
e9fe337fa9aa [gaim-migrate @ 16605]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
149 return (guint8 *) g_strnfill(QQ_KEY_LENGTH, 0x01);
e9fe337fa9aa [gaim-migrate @ 16605]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
150 }
13870
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
151
14021
ef8490f9e823 [gaim-migrate @ 16618]
Mark Huetsch <markhuetsch>
parents: 14013
diff changeset
152 /* process login reply which says OK */
ef8490f9e823 [gaim-migrate @ 16618]
Mark Huetsch <markhuetsch>
parents: 14013
diff changeset
153 static gint _qq_process_login_ok(GaimConnection *gc, guint8 *data, gint len)
13870
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
154 {
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
155 gint bytes;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
156 guint8 *cursor;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
157 qq_data *qd;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
158 qq_login_reply_ok_packet lrop;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
159
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
160 g_return_val_if_fail(gc != NULL && gc->proto_data != NULL, QQ_LOGIN_REPLY_MISC_ERROR);
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
161
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
162 qd = (qq_data *) gc->proto_data;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
163 cursor = data;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
164 bytes = 0;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
165
14021
ef8490f9e823 [gaim-migrate @ 16618]
Mark Huetsch <markhuetsch>
parents: 14013
diff changeset
166 /* 000-000: reply code */
13870
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
167 bytes += read_packet_b(data, &cursor, len, &lrop.result);
14021
ef8490f9e823 [gaim-migrate @ 16618]
Mark Huetsch <markhuetsch>
parents: 14013
diff changeset
168 /* 001-016: session key */
13870
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
169 lrop.session_key = g_memdup(cursor, QQ_KEY_LENGTH);
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
170 cursor += QQ_KEY_LENGTH;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
171 bytes += QQ_KEY_LENGTH;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
172 gaim_debug(GAIM_DEBUG_INFO, "QQ", "Get session_key done\n");
14021
ef8490f9e823 [gaim-migrate @ 16618]
Mark Huetsch <markhuetsch>
parents: 14013
diff changeset
173 /* 017-020: login uid */
13870
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
174 bytes += read_packet_dw(data, &cursor, len, &lrop.uid);
14021
ef8490f9e823 [gaim-migrate @ 16618]
Mark Huetsch <markhuetsch>
parents: 14013
diff changeset
175 /* 021-024: server detected user public IP */
13870
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
176 bytes += read_packet_data(data, &cursor, len, (guint8 *) & lrop.client_ip, 4);
14021
ef8490f9e823 [gaim-migrate @ 16618]
Mark Huetsch <markhuetsch>
parents: 14013
diff changeset
177 /* 025-026: server detected user port */
13870
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
178 bytes += read_packet_w(data, &cursor, len, &lrop.client_port);
14021
ef8490f9e823 [gaim-migrate @ 16618]
Mark Huetsch <markhuetsch>
parents: 14013
diff changeset
179 /* 027-030: server detected itself ip 127.0.0.1 ? */
13870
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
180 bytes += read_packet_data(data, &cursor, len, (guint8 *) & lrop.server_ip, 4);
14021
ef8490f9e823 [gaim-migrate @ 16618]
Mark Huetsch <markhuetsch>
parents: 14013
diff changeset
181 /* 031-032: server listening port */
13870
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
182 bytes += read_packet_w(data, &cursor, len, &lrop.server_port);
14021
ef8490f9e823 [gaim-migrate @ 16618]
Mark Huetsch <markhuetsch>
parents: 14013
diff changeset
183 /* 033-036: login time for current session */
13870
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
184 bytes += read_packet_dw(data, &cursor, len, (guint32 *) & lrop.login_time);
14021
ef8490f9e823 [gaim-migrate @ 16618]
Mark Huetsch <markhuetsch>
parents: 14013
diff changeset
185 /* 037-062: 26 bytes, unknown */
13870
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
186 bytes += read_packet_data(data, &cursor, len, (guint8 *) & lrop.unknown1, 26);
14021
ef8490f9e823 [gaim-migrate @ 16618]
Mark Huetsch <markhuetsch>
parents: 14013
diff changeset
187 /* 063-066: unknown server1 ip address */
13870
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
188 bytes += read_packet_data(data, &cursor, len, (guint8 *) & lrop.unknown_server1_ip, 4);
14021
ef8490f9e823 [gaim-migrate @ 16618]
Mark Huetsch <markhuetsch>
parents: 14013
diff changeset
189 /* 067-068: unknown server1 port */
13870
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
190 bytes += read_packet_w(data, &cursor, len, &lrop.unknown_server1_port);
14021
ef8490f9e823 [gaim-migrate @ 16618]
Mark Huetsch <markhuetsch>
parents: 14013
diff changeset
191 /* 069-072: unknown server2 ip address */
13870
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
192 bytes += read_packet_data(data, &cursor, len, (guint8 *) & lrop.unknown_server2_ip, 4);
14021
ef8490f9e823 [gaim-migrate @ 16618]
Mark Huetsch <markhuetsch>
parents: 14013
diff changeset
193 /* 073-074: unknown server2 port */
13870
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
194 bytes += read_packet_w(data, &cursor, len, &lrop.unknown_server2_port);
14021
ef8490f9e823 [gaim-migrate @ 16618]
Mark Huetsch <markhuetsch>
parents: 14013
diff changeset
195 /* 075-076: 2 bytes unknown */
13870
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
196 bytes += read_packet_w(data, &cursor, len, &lrop.unknown2);
14021
ef8490f9e823 [gaim-migrate @ 16618]
Mark Huetsch <markhuetsch>
parents: 14013
diff changeset
197 /* 077-078: 2 bytes unknown */
13870
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
198 bytes += read_packet_w(data, &cursor, len, &lrop.unknown3);
14021
ef8490f9e823 [gaim-migrate @ 16618]
Mark Huetsch <markhuetsch>
parents: 14013
diff changeset
199 /* 079-110: 32 bytes unknown */
13870
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
200 bytes += read_packet_data(data, &cursor, len, (guint8 *) & lrop.unknown4, 32);
14021
ef8490f9e823 [gaim-migrate @ 16618]
Mark Huetsch <markhuetsch>
parents: 14013
diff changeset
201 /* 111-122: 12 bytes unknown */
13870
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
202 bytes += read_packet_data(data, &cursor, len, (guint8 *) & lrop.unknown5, 12);
14021
ef8490f9e823 [gaim-migrate @ 16618]
Mark Huetsch <markhuetsch>
parents: 14013
diff changeset
203 /* 123-126: login IP of last session */
13870
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
204 bytes += read_packet_data(data, &cursor, len, (guint8 *) & lrop.last_client_ip, 4);
14021
ef8490f9e823 [gaim-migrate @ 16618]
Mark Huetsch <markhuetsch>
parents: 14013
diff changeset
205 /* 127-130: login time of last session */
13870
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
206 bytes += read_packet_dw(data, &cursor, len, (guint32 *) & lrop.last_login_time);
14021
ef8490f9e823 [gaim-migrate @ 16618]
Mark Huetsch <markhuetsch>
parents: 14013
diff changeset
207 /* 131-138: 8 bytes unknown */
13870
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
208 bytes += read_packet_data(data, &cursor, len, (guint8 *) & lrop.unknown6, 8);
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
209
14021
ef8490f9e823 [gaim-migrate @ 16618]
Mark Huetsch <markhuetsch>
parents: 14013
diff changeset
210 if (bytes != QQ_LOGIN_REPLY_OK_PACKET_LEN) { /* fail parsing login info */
13870
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
211 gaim_debug(GAIM_DEBUG_WARNING, "QQ",
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
212 "Fail parsing login info, expect %d bytes, read %d bytes\n",
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
213 QQ_LOGIN_REPLY_OK_PACKET_LEN, bytes);
14021
ef8490f9e823 [gaim-migrate @ 16618]
Mark Huetsch <markhuetsch>
parents: 14013
diff changeset
214 } /* but we still go on as login OK */
13870
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
215
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
216 qd->session_key = g_memdup(lrop.session_key, QQ_KEY_LENGTH);
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
217 qd->my_ip = gen_ip_str(lrop.client_ip);
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
218 qd->my_port = lrop.client_port;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
219 qd->login_time = lrop.login_time;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
220 qd->last_login_time = lrop.last_login_time;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
221 qd->last_login_ip = gen_ip_str(lrop.last_client_ip);
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
222
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
223 g_free(lrop.session_key);
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
224
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
225 gaim_connection_set_state(gc, GAIM_CONNECTED);
14021
ef8490f9e823 [gaim-migrate @ 16618]
Mark Huetsch <markhuetsch>
parents: 14013
diff changeset
226 qd->logged_in = TRUE; /* must be defined after sev_finish_login */
13870
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
227
14021
ef8490f9e823 [gaim-migrate @ 16618]
Mark Huetsch <markhuetsch>
parents: 14013
diff changeset
228 /* now initiate QQ Qun, do it first as it may take longer to finish */
13870
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
229 qq_group_init(gc);
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
230
14021
ef8490f9e823 [gaim-migrate @ 16618]
Mark Huetsch <markhuetsch>
parents: 14013
diff changeset
231 /* Now goes on updating my icon/nickname, not showing info_window */
13870
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
232 qq_send_packet_get_info(gc, qd->uid, FALSE);
14021
ef8490f9e823 [gaim-migrate @ 16618]
Mark Huetsch <markhuetsch>
parents: 14013
diff changeset
233 /* change my status manually, even server may broadcast my online */
13870
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
234 qd->status = (qd->login_mode == QQ_LOGIN_MODE_HIDDEN) ? QQ_SELF_STATUS_INVISIBLE : QQ_SELF_STATUS_AVAILABLE;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
235 qq_send_packet_change_status(gc);
14021
ef8490f9e823 [gaim-migrate @ 16618]
Mark Huetsch <markhuetsch>
parents: 14013
diff changeset
236 /* now refresh buddy list */
13870
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
237
14021
ef8490f9e823 [gaim-migrate @ 16618]
Mark Huetsch <markhuetsch>
parents: 14013
diff changeset
238 /* changed by gfhuang, using With Qun version, error, not working still */
13870
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
239 qq_send_packet_get_buddies_list(gc, QQ_FRIENDS_LIST_POSITION_START);
14021
ef8490f9e823 [gaim-migrate @ 16618]
Mark Huetsch <markhuetsch>
parents: 14013
diff changeset
240 /* qq_send_packet_get_all_list_with_group(gc, QQ_FRIENDS_LIST_POSITION_START); */
13870
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
241
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
242 return QQ_LOGIN_REPLY_OK;
14013
e9fe337fa9aa [gaim-migrate @ 16605]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
243 }
13870
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
244
14021
ef8490f9e823 [gaim-migrate @ 16618]
Mark Huetsch <markhuetsch>
parents: 14013
diff changeset
245 /* process login reply packet which includes redirected new server address */
ef8490f9e823 [gaim-migrate @ 16618]
Mark Huetsch <markhuetsch>
parents: 14013
diff changeset
246 static gint _qq_process_login_redirect(GaimConnection *gc, guint8 *data, gint len)
13870
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
247 {
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
248 gint bytes, ret;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
249 guint8 *cursor;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
250 gchar *new_server_str;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
251 qq_data *qd;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
252 qq_login_reply_redirect_packet lrrp;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
253
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
254 g_return_val_if_fail(gc != NULL && gc->proto_data != NULL, QQ_LOGIN_REPLY_MISC_ERROR);
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
255
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
256 qd = (qq_data *) gc->proto_data;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
257 cursor = data;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
258 bytes = 0;
14021
ef8490f9e823 [gaim-migrate @ 16618]
Mark Huetsch <markhuetsch>
parents: 14013
diff changeset
259 /* 000-000: reply code */
13870
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
260 bytes += read_packet_b(data, &cursor, len, &lrrp.result);
14021
ef8490f9e823 [gaim-migrate @ 16618]
Mark Huetsch <markhuetsch>
parents: 14013
diff changeset
261 /* 001-004: login uid */
13870
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
262 bytes += read_packet_dw(data, &cursor, len, &lrrp.uid);
14021
ef8490f9e823 [gaim-migrate @ 16618]
Mark Huetsch <markhuetsch>
parents: 14013
diff changeset
263 /* 005-008: redirected new server IP */
13870
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
264 bytes += read_packet_data(data, &cursor, len, lrrp.new_server_ip, 4);
14021
ef8490f9e823 [gaim-migrate @ 16618]
Mark Huetsch <markhuetsch>
parents: 14013
diff changeset
265 /* 009-010: redirected new server port */
13870
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
266 bytes += read_packet_w(data, &cursor, len, &lrrp.new_server_port);
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
267
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
268 if (bytes != QQ_LOGIN_REPLY_REDIRECT_PACKET_LEN) {
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
269 gaim_debug(GAIM_DEBUG_ERROR, "QQ",
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
270 "Fail parsing login redirect packet, expect %d bytes, read %d bytes\n",
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
271 QQ_LOGIN_REPLY_REDIRECT_PACKET_LEN, bytes);
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
272 ret = QQ_LOGIN_REPLY_MISC_ERROR;
14021
ef8490f9e823 [gaim-migrate @ 16618]
Mark Huetsch <markhuetsch>
parents: 14013
diff changeset
273 } else { /* start new connection */
13870
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
274 new_server_str = gen_ip_str(lrrp.new_server_ip);
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
275 gaim_debug(GAIM_DEBUG_WARNING, "QQ",
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
276 "Redirected to new server: %s:%d\n", new_server_str, lrrp.new_server_port);
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
277 qq_connect(gc->account, new_server_str, lrrp.new_server_port, qd->use_tcp, TRUE);
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
278 g_free(new_server_str);
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
279 ret = QQ_LOGIN_REPLY_REDIRECT;
14013
e9fe337fa9aa [gaim-migrate @ 16605]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
280 }
13870
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
281
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
282 return ret;
14013
e9fe337fa9aa [gaim-migrate @ 16605]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
283 }
13870
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
284
14021
ef8490f9e823 [gaim-migrate @ 16618]
Mark Huetsch <markhuetsch>
parents: 14013
diff changeset
285 /* process login reply which says wrong password */
13870
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
286 static gint _qq_process_login_wrong_pwd(GaimConnection * gc, guint8 * data, gint len)
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
287 {
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
288 gchar *server_reply, *server_reply_utf8;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
289 server_reply = g_new0(gchar, len);
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
290 g_memmove(server_reply, data + 1, len - 1);
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
291 server_reply_utf8 = qq_to_utf8(server_reply, QQ_CHARSET_DEFAULT);
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
292 gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Wrong password, server msg in UTF8: %s\n", server_reply_utf8);
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
293 g_free(server_reply);
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
294 g_free(server_reply_utf8);
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
295
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
296 return QQ_LOGIN_REPLY_PWD_ERROR;
14013
e9fe337fa9aa [gaim-migrate @ 16605]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
297 }
13870
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
298
14021
ef8490f9e823 [gaim-migrate @ 16618]
Mark Huetsch <markhuetsch>
parents: 14013
diff changeset
299 /* request before login */
13870
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
300 void qq_send_packet_request_login_token(GaimConnection *gc)
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
301 {
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
302 qq_data *qd;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
303 guint8 *buf, *cursor;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
304 guint16 seq_ret;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
305 gint bytes;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
306
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
307 g_return_if_fail(gc != NULL && gc->proto_data != NULL);
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
308
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
309 qd = (qq_data *) gc->proto_data;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
310 buf = g_newa(guint8, MAX_PACKET_SIZE);
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
311
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
312 cursor = buf;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
313 bytes = 0;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
314 bytes += _create_packet_head_seq(buf, &cursor, gc, QQ_CMD_REQUEST_LOGIN_TOKEN, TRUE, &seq_ret);
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
315 bytes += create_packet_dw(buf, &cursor, qd->uid);
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
316 bytes += create_packet_b(buf, &cursor, 0);
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
317 bytes += create_packet_b(buf, &cursor, QQ_PACKET_TAIL);
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
318
14021
ef8490f9e823 [gaim-migrate @ 16618]
Mark Huetsch <markhuetsch>
parents: 14013
diff changeset
319 if (bytes == (cursor - buf)) /* packet creation OK */
13870
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
320 _qq_send_packet(gc, buf, bytes, QQ_CMD_REQUEST_LOGIN_TOKEN);
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
321 else
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
322 gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Fail create request login token packet\n");
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
323 }
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
324
14021
ef8490f9e823 [gaim-migrate @ 16618]
Mark Huetsch <markhuetsch>
parents: 14013
diff changeset
325 /* TODO: The login packet and its response have changed by QQ2006 Beta2. In that version,
ef8490f9e823 [gaim-migrate @ 16618]
Mark Huetsch <markhuetsch>
parents: 14013
diff changeset
326 * the login OK response packet does not appear to be decryptable with qd->pwkey or qd->inikey.
ef8490f9e823 [gaim-migrate @ 16618]
Mark Huetsch <markhuetsch>
parents: 14013
diff changeset
327 * Fortunately, this older system still works. */
14013
e9fe337fa9aa [gaim-migrate @ 16605]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
328
14021
ef8490f9e823 [gaim-migrate @ 16618]
Mark Huetsch <markhuetsch>
parents: 14013
diff changeset
329 /* send login packet to QQ server */
ef8490f9e823 [gaim-migrate @ 16618]
Mark Huetsch <markhuetsch>
parents: 14013
diff changeset
330 static void qq_send_packet_login(GaimConnection *gc, guint8 token_length, guint8 *token)
13870
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
331 {
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
332 qq_data *qd;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
333 guint8 *buf, *cursor, *raw_data, *encrypted_data;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
334 guint16 seq_ret;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
335 gint encrypted_len, bytes;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
336 gint pos;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
337
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
338 g_return_if_fail(gc != NULL && gc->proto_data != NULL);
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
339
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
340 qd = (qq_data *) gc->proto_data;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
341 buf = g_newa(guint8, MAX_PACKET_SIZE);
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
342 raw_data = g_newa(guint8, QQ_LOGIN_DATA_LENGTH);
14021
ef8490f9e823 [gaim-migrate @ 16618]
Mark Huetsch <markhuetsch>
parents: 14013
diff changeset
343 encrypted_data = g_newa(guint8, QQ_LOGIN_DATA_LENGTH + 16); /* 16 bytes more */
13870
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
344 qd->inikey = _gen_login_key();
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
345
14021
ef8490f9e823 [gaim-migrate @ 16618]
Mark Huetsch <markhuetsch>
parents: 14013
diff changeset
346 /* now generate the encrypted data
ef8490f9e823 [gaim-migrate @ 16618]
Mark Huetsch <markhuetsch>
parents: 14013
diff changeset
347 * 000-015 use pwkey as key to encrypt empty string */
14013
e9fe337fa9aa [gaim-migrate @ 16605]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
348 qq_crypt(ENCRYPT, (guint8 *) "", 0, qd->pwkey, raw_data, &encrypted_len);
14021
ef8490f9e823 [gaim-migrate @ 16618]
Mark Huetsch <markhuetsch>
parents: 14013
diff changeset
349 /* 016-016 */
13870
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
350 raw_data[16] = 0x00;
14021
ef8490f9e823 [gaim-migrate @ 16618]
Mark Huetsch <markhuetsch>
parents: 14013
diff changeset
351 /* 017-020, used to be IP, now zero */
13870
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
352 *((guint32 *) (raw_data + 17)) = 0x00000000;
14021
ef8490f9e823 [gaim-migrate @ 16618]
Mark Huetsch <markhuetsch>
parents: 14013
diff changeset
353 /* 021-022, used to be port, now zero */
13870
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
354 *((guint16 *) (raw_data + 21)) = 0x0000;
14021
ef8490f9e823 [gaim-migrate @ 16618]
Mark Huetsch <markhuetsch>
parents: 14013
diff changeset
355 /* 023-051, fixed value, unknown */
13870
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
356 g_memmove(raw_data + 23, login_23_51, 29);
14021
ef8490f9e823 [gaim-migrate @ 16618]
Mark Huetsch <markhuetsch>
parents: 14013
diff changeset
357 /* 052-052, login mode */
13870
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
358 raw_data[52] = qd->login_mode;
14021
ef8490f9e823 [gaim-migrate @ 16618]
Mark Huetsch <markhuetsch>
parents: 14013
diff changeset
359 /* 053-068, fixed value, maybe related to per machine */
13870
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
360 g_memmove(raw_data + 53, login_53_68, 16);
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
361
14021
ef8490f9e823 [gaim-migrate @ 16618]
Mark Huetsch <markhuetsch>
parents: 14013
diff changeset
362 /* 069, login token length */
13870
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
363 raw_data[69] = token_length;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
364 pos = 70;
14021
ef8490f9e823 [gaim-migrate @ 16618]
Mark Huetsch <markhuetsch>
parents: 14013
diff changeset
365 /* 070-093, login token, normally 24 bytes */
13870
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
366 g_memmove(raw_data + pos, token, token_length);
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
367 pos += token_length;
14021
ef8490f9e823 [gaim-migrate @ 16618]
Mark Huetsch <markhuetsch>
parents: 14013
diff changeset
368 /* 100 bytes unknown */
13870
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
369 g_memmove(raw_data + pos, login_100_bytes, 100);
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
370 pos += 100;
14021
ef8490f9e823 [gaim-migrate @ 16618]
Mark Huetsch <markhuetsch>
parents: 14013
diff changeset
371 /* all zero left */
13870
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
372 memset(raw_data+pos, 0, QQ_LOGIN_DATA_LENGTH - pos);
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
373
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
374 qq_crypt(ENCRYPT, raw_data, QQ_LOGIN_DATA_LENGTH, qd->inikey, encrypted_data, &encrypted_len);
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
375
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
376 cursor = buf;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
377 bytes = 0;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
378 bytes += _create_packet_head_seq(buf, &cursor, gc, QQ_CMD_LOGIN, TRUE, &seq_ret);
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
379 bytes += create_packet_dw(buf, &cursor, qd->uid);
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
380 bytes += create_packet_data(buf, &cursor, qd->inikey, QQ_KEY_LENGTH);
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
381 bytes += create_packet_data(buf, &cursor, encrypted_data, encrypted_len);
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
382 bytes += create_packet_b(buf, &cursor, QQ_PACKET_TAIL);
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
383
14021
ef8490f9e823 [gaim-migrate @ 16618]
Mark Huetsch <markhuetsch>
parents: 14013
diff changeset
384 if (bytes == (cursor - buf)) /* packet creation OK */
13870
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
385 _qq_send_packet(gc, buf, bytes, QQ_CMD_LOGIN);
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
386 else
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
387 gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Fail create login packet\n");
14013
e9fe337fa9aa [gaim-migrate @ 16605]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
388 }
13870
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
389
14021
ef8490f9e823 [gaim-migrate @ 16618]
Mark Huetsch <markhuetsch>
parents: 14013
diff changeset
390 void qq_process_request_login_token_reply(guint8 *buf, gint buf_len, GaimConnection *gc)
13870
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
391 {
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
392 qq_data *qd;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
393
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
394 g_return_if_fail(gc != NULL && gc->proto_data != NULL);
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
395 g_return_if_fail(buf != NULL && buf_len != 0);
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
396
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
397 qd = (qq_data *) gc->proto_data;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
398
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
399 if (buf[0] == QQ_REQUEST_LOGIN_TOKEN_REPLY_OK) {
14013
e9fe337fa9aa [gaim-migrate @ 16605]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
400 if (buf[1] != buf_len-2) {
e9fe337fa9aa [gaim-migrate @ 16605]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
401 gaim_debug(GAIM_DEBUG_INFO, "QQ",
e9fe337fa9aa [gaim-migrate @ 16605]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
402 "Malformed login token reply packet. Packet specifies length of %d, actual length is %d\n", buf[1], buf_len-2);
e9fe337fa9aa [gaim-migrate @ 16605]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
403 gaim_debug(GAIM_DEBUG_INFO, "QQ",
e9fe337fa9aa [gaim-migrate @ 16605]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
404 "Attempting to proceed with the actual packet length.\n");
e9fe337fa9aa [gaim-migrate @ 16605]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
405 }
13870
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
406 gaim_debug(GAIM_DEBUG_INFO, "QQ",
14013
e9fe337fa9aa [gaim-migrate @ 16605]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
407 "<<< got a token with %d bytes -> [default] decrypt and dump\n%s",buf_len-2, hex_dump_to_str(buf+2, buf_len-2));
e9fe337fa9aa [gaim-migrate @ 16605]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
408 qq_send_packet_login(gc, buf_len-2, buf+2);
13870
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
409 } else {
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
410 gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Unknown request login token reply code : %d\n", buf[0]);
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
411 gaim_debug(GAIM_DEBUG_WARNING, "QQ",
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
412 ">>> %d bytes -> [default] decrypt and dump\n%s",
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
413 buf_len, hex_dump_to_str(buf, buf_len));
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
414 try_dump_as_gbk(buf, buf_len);
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
415 gaim_connection_error(gc, _("Request login token error!"));
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
416 }
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
417 }
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
418
14021
ef8490f9e823 [gaim-migrate @ 16618]
Mark Huetsch <markhuetsch>
parents: 14013
diff changeset
419 /* send logout packets to QQ server */
ef8490f9e823 [gaim-migrate @ 16618]
Mark Huetsch <markhuetsch>
parents: 14013
diff changeset
420 void qq_send_packet_logout(GaimConnection *gc)
13870
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
421 {
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
422 gint i;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
423 qq_data *qd;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
424
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
425 g_return_if_fail(gc != NULL && gc->proto_data != NULL);
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
426
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
427 qd = (qq_data *) gc->proto_data;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
428 for (i = 0; i < 4; i++)
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
429 qq_send_cmd(gc, QQ_CMD_LOGOUT, FALSE, 0xffff, FALSE, qd->pwkey, QQ_KEY_LENGTH);
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
430
14021
ef8490f9e823 [gaim-migrate @ 16618]
Mark Huetsch <markhuetsch>
parents: 14013
diff changeset
431 qd->logged_in = FALSE; /* update login status AFTER sending logout packets */
ef8490f9e823 [gaim-migrate @ 16618]
Mark Huetsch <markhuetsch>
parents: 14013
diff changeset
432 }
13870
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
433
14021
ef8490f9e823 [gaim-migrate @ 16618]
Mark Huetsch <markhuetsch>
parents: 14013
diff changeset
434 /* process the login reply packet */
ef8490f9e823 [gaim-migrate @ 16618]
Mark Huetsch <markhuetsch>
parents: 14013
diff changeset
435 void qq_process_login_reply(guint8 *buf, gint buf_len, GaimConnection *gc)
13870
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
436 {
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
437 gint len, ret, bytes;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
438 guint8 *data;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
439 qq_data *qd;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
440
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
441 g_return_if_fail(gc != NULL && gc->proto_data != NULL);
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
442 g_return_if_fail(buf != NULL && buf_len != 0);
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
443
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
444 qd = (qq_data *) gc->proto_data;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
445 len = buf_len;
14021
ef8490f9e823 [gaim-migrate @ 16618]
Mark Huetsch <markhuetsch>
parents: 14013
diff changeset
446 data = g_newa(guint8, len);
13870
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
447
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
448 if (qq_crypt(DECRYPT, buf, buf_len, qd->pwkey, data, &len)) {
14021
ef8490f9e823 [gaim-migrate @ 16618]
Mark Huetsch <markhuetsch>
parents: 14013
diff changeset
449 /* should be able to decrypt with pwkey */
13870
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
450 gaim_debug(GAIM_DEBUG_INFO, "QQ", "Decrypt login reply packet with pwkey, %d bytes\n", len);
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
451 if (data[0] == QQ_LOGIN_REPLY_OK) {
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
452 ret = _qq_process_login_ok(gc, data, len);
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
453 } else {
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
454 gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Unknown login reply code : %d\n", data[0]);
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
455 ret = QQ_LOGIN_REPLY_MISC_ERROR;
14021
ef8490f9e823 [gaim-migrate @ 16618]
Mark Huetsch <markhuetsch>
parents: 14013
diff changeset
456 }
ef8490f9e823 [gaim-migrate @ 16618]
Mark Huetsch <markhuetsch>
parents: 14013
diff changeset
457 } else { /* decrypt with pwkey error */
ef8490f9e823 [gaim-migrate @ 16618]
Mark Huetsch <markhuetsch>
parents: 14013
diff changeset
458 len = buf_len; /* reset len, decrypt will fail if len is too short */
13870
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
459 if (qq_crypt(DECRYPT, buf, buf_len, qd->inikey, data, &len)) {
14021
ef8490f9e823 [gaim-migrate @ 16618]
Mark Huetsch <markhuetsch>
parents: 14013
diff changeset
460 /* decrypt ok with inipwd, it might be password error */
ef8490f9e823 [gaim-migrate @ 16618]
Mark Huetsch <markhuetsch>
parents: 14013
diff changeset
461 gaim_debug(GAIM_DEBUG_WARNING, "QQ",
ef8490f9e823 [gaim-migrate @ 16618]
Mark Huetsch <markhuetsch>
parents: 14013
diff changeset
462 "Decrypt login reply packet with inikey, %d bytes\n", len);
13870
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
463 bytes = 0;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
464 switch (data[0]) {
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
465 case QQ_LOGIN_REPLY_REDIRECT:
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
466 ret = _qq_process_login_redirect(gc, data, len);
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
467 break;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
468 case QQ_LOGIN_REPLY_PWD_ERROR:
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
469 ret = _qq_process_login_wrong_pwd(gc, data, len);
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
470 break;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
471 default:
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
472 gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Unknown reply code: %d\n", data[0]);
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
473 gaim_debug(GAIM_DEBUG_WARNING, "QQ",
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
474 ">>> %d bytes -> [default] decrypt and dump\n%s",
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
475 buf_len, hex_dump_to_str(data, len));
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
476 try_dump_as_gbk(data, len);
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
477
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
478 ret = QQ_LOGIN_REPLY_MISC_ERROR;
14021
ef8490f9e823 [gaim-migrate @ 16618]
Mark Huetsch <markhuetsch>
parents: 14013
diff changeset
479 }
ef8490f9e823 [gaim-migrate @ 16618]
Mark Huetsch <markhuetsch>
parents: 14013
diff changeset
480 } else { /* no idea how to decrypt */
13870
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
481 gaim_debug(GAIM_DEBUG_ERROR, "QQ", "No idea how to decrypt login reply\n");
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
482 ret = QQ_LOGIN_REPLY_MISC_ERROR;
14021
ef8490f9e823 [gaim-migrate @ 16618]
Mark Huetsch <markhuetsch>
parents: 14013
diff changeset
483 }
ef8490f9e823 [gaim-migrate @ 16618]
Mark Huetsch <markhuetsch>
parents: 14013
diff changeset
484 }
13870
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
485
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
486 switch (ret) {
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
487 case QQ_LOGIN_REPLY_PWD_ERROR:
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
488 gc->wants_to_die = TRUE;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
489 gaim_connection_error(gc, _("Wrong password!"));
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
490 break;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
491 case QQ_LOGIN_REPLY_MISC_ERROR:
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
492 gaim_connection_error(gc, _("Unable to login, check debug log"));
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
493 break;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
494 case QQ_LOGIN_REPLY_OK:
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
495 gaim_debug(GAIM_DEBUG_INFO, "QQ", "Login replys OK, everything is fine\n");
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
496 break;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
497 case QQ_LOGIN_REPLY_REDIRECT:
14021
ef8490f9e823 [gaim-migrate @ 16618]
Mark Huetsch <markhuetsch>
parents: 14013
diff changeset
498 /* the redirect has been done in _qq_process_login_reply */
13870
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
499 break;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
500 default:{;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
501 }
14013
e9fe337fa9aa [gaim-migrate @ 16605]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
502 }
e9fe337fa9aa [gaim-migrate @ 16605]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
503 }