|
13870
|
1 /**
|
|
|
2 * The QQ2003C protocol plugin
|
|
|
3 *
|
|
|
4 * for gaim
|
|
|
5 *
|
|
|
6 * Copyright (C) 2004 Puzzlebird
|
|
|
7 *
|
|
|
8 * This program is free software; you can redistribute it and/or modify
|
|
|
9 * it under the terms of the GNU General Public License as published by
|
|
|
10 * the Free Software Foundation; either version 2 of the License, or
|
|
|
11 * (at your option) any later version.
|
|
|
12 *
|
|
|
13 * This program is distributed in the hope that it will be useful,
|
|
|
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
16 * GNU General Public License for more details.
|
|
|
17 *
|
|
|
18 * You should have received a copy of the GNU General Public License
|
|
|
19 * along with this program; if not, write to the Free Software
|
|
|
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
21 */
|
|
|
22
|
|
14021
|
23 #include "conversation.h"
|
|
|
24 #include "debug.h"
|
|
|
25 #include "internal.h"
|
|
|
26 #include "cipher.h"
|
|
|
27 #include "notify.h"
|
|
|
28 #include "server.h"
|
|
|
29 #include "util.h"
|
|
13870
|
30
|
|
14021
|
31 #include "buddy_info.h"
|
|
|
32 #include "buddy_list.h"
|
|
|
33 #include "buddy_opt.h"
|
|
|
34 #include "char_conv.h"
|
|
|
35 #include "crypt.h"
|
|
|
36 #include "group_im.h"
|
|
|
37 #include "header_info.h"
|
|
13870
|
38 #include "im.h"
|
|
14021
|
39 #include "packet_parse.h"
|
|
|
40 #include "send_core.h"
|
|
13870
|
41 #include "send_file.h"
|
|
14021
|
42 #include "utils.h"
|
|
13870
|
43
|
|
|
44 #define QQ_SEND_IM_REPLY_OK 0x00
|
|
|
45 #define DEFAULT_FONT_NAME_LEN 4
|
|
|
46
|
|
14021
|
47 /* a debug function */
|
|
|
48 void _qq_show_packet(gchar *desc, gchar *buf, gint len);
|
|
13870
|
49
|
|
|
50 enum
|
|
|
51 {
|
|
|
52 QQ_NORMAL_IM_TEXT = 0x000b,
|
|
14021
|
53 QQ_NORMAL_IM_FILE_REQUEST_TCP = 0x0001,
|
|
13870
|
54 QQ_NORMAL_IM_FILE_APPROVE_TCP = 0x0003,
|
|
|
55 QQ_NORMAL_IM_FILE_REJECT_TCP = 0x0005,
|
|
|
56 QQ_NORMAL_IM_FILE_REQUEST_UDP = 0x0035,
|
|
|
57 QQ_NORMAL_IM_FILE_APPROVE_UDP = 0x0037,
|
|
|
58 QQ_NORMAL_IM_FILE_REJECT_UDP = 0x0039,
|
|
|
59 QQ_NORMAL_IM_FILE_NOTIFY = 0x003b,
|
|
14021
|
60 QQ_NORMAL_IM_FILE_PASV = 0x003f, /* are you behind a firewall? */
|
|
13870
|
61 QQ_NORMAL_IM_FILE_CANCEL = 0x0049,
|
|
14021
|
62 QQ_NORMAL_IM_FILE_EX_REQUEST_UDP = 0x81,
|
|
|
63 QQ_NORMAL_IM_FILE_EX_REQUEST_ACCEPT = 0x83,
|
|
|
64 QQ_NORMAL_IM_FILE_EX_REQUEST_CANCEL = 0x85,
|
|
|
65 QQ_NORMAL_IM_FILE_EX_NOTIFY_IP = 0x87
|
|
13870
|
66 };
|
|
|
67
|
|
14021
|
68 enum {
|
|
|
69 QQ_RECV_SYS_IM_KICK_OUT = 0x01
|
|
13870
|
70 };
|
|
|
71
|
|
|
72 typedef struct _qq_recv_im_header qq_recv_im_header;
|
|
|
73 typedef struct _qq_recv_normal_im_text qq_recv_normal_im_text;
|
|
|
74 typedef struct _qq_recv_normal_im_common qq_recv_normal_im_common;
|
|
|
75 typedef struct _qq_recv_normal_im_unprocessed qq_recv_normal_im_unprocessed;
|
|
|
76
|
|
|
77 struct _qq_recv_normal_im_common {
|
|
14021
|
78 /* this is the common part of normal_text */
|
|
13870
|
79 guint16 sender_ver;
|
|
|
80 guint32 sender_uid;
|
|
|
81 guint32 receiver_uid;
|
|
|
82 guint8 *session_md5;
|
|
|
83 guint16 normal_im_type;
|
|
|
84 };
|
|
|
85
|
|
|
86 struct _qq_recv_normal_im_text {
|
|
|
87 qq_recv_normal_im_common *common;
|
|
14021
|
88 /* now comes the part for text only */
|
|
13870
|
89 guint16 msg_seq;
|
|
|
90 guint32 send_time;
|
|
|
91 guint8 unknown1;
|
|
|
92 guint8 sender_icon;
|
|
|
93 guint8 unknown2[3];
|
|
|
94 guint8 is_there_font_attr;
|
|
|
95 guint8 unknown3[4];
|
|
|
96 guint8 msg_type;
|
|
14021
|
97 guint8 *msg; /* no fixed length, ends with 0x00 */
|
|
13870
|
98 guint8 *font_attr;
|
|
|
99 gint font_attr_len;
|
|
|
100 };
|
|
|
101
|
|
|
102 struct _qq_recv_normal_im_unprocessed {
|
|
|
103 qq_recv_normal_im_common *common;
|
|
14021
|
104 /* now comes the part of unprocessed */
|
|
|
105 guint8 *unknown; /* no fixed length */
|
|
13870
|
106 gint length;
|
|
|
107 };
|
|
|
108
|
|
|
109 struct _qq_recv_im_header {
|
|
|
110 guint32 sender_uid;
|
|
|
111 guint32 receiver_uid;
|
|
|
112 guint32 server_im_seq;
|
|
|
113 guint8 sender_ip[4];
|
|
|
114 guint16 sender_port;
|
|
|
115 guint16 im_type;
|
|
|
116 };
|
|
|
117
|
|
|
118 #define QQ_SEND_IM_AFTER_MSG_HEADER_LEN 8
|
|
|
119 #define DEFAULT_FONT_NAME "\0xcb\0xce\0xcc\0xe5"
|
|
|
120
|
|
14021
|
121 guint8 *qq_get_send_im_tail(const gchar *font_color,
|
|
|
122 const gchar *font_size,
|
|
|
123 const gchar *font_name,
|
|
13870
|
124 gboolean is_bold, gboolean is_italic, gboolean is_underline, guint tail_len)
|
|
|
125 {
|
|
|
126 gchar *s1, *s2;
|
|
|
127 unsigned char *rgb;
|
|
|
128 guint font_name_len;
|
|
|
129 guint8 *send_im_tail;
|
|
|
130 const guint8 simsun[] = { 0xcb, 0xce, 0xcc, 0xe5 };
|
|
|
131
|
|
|
132 if (font_name) {
|
|
|
133 font_name_len = strlen(font_name);
|
|
|
134 } else {
|
|
|
135 font_name_len = DEFAULT_FONT_NAME_LEN;
|
|
|
136 font_name = simsun;
|
|
|
137 }
|
|
|
138
|
|
|
139 send_im_tail = g_new0(guint8, tail_len);
|
|
|
140
|
|
|
141 g_strlcpy(send_im_tail + QQ_SEND_IM_AFTER_MSG_HEADER_LEN,
|
|
|
142 font_name, tail_len - QQ_SEND_IM_AFTER_MSG_HEADER_LEN);
|
|
|
143 send_im_tail[tail_len - 1] = tail_len;
|
|
|
144
|
|
|
145 send_im_tail[0] = 0x00;
|
|
|
146 if (font_size) {
|
|
|
147 send_im_tail[1] = (guint8) (atoi(font_size) * 3 + 1);
|
|
|
148 } else {
|
|
|
149 send_im_tail[1] = 10;
|
|
|
150 }
|
|
|
151 if (is_bold)
|
|
|
152 send_im_tail[1] |= 0x20;
|
|
|
153 if (is_italic)
|
|
|
154 send_im_tail[1] |= 0x40;
|
|
|
155 if (is_underline)
|
|
|
156 send_im_tail[1] |= 0x80;
|
|
|
157
|
|
|
158 if (font_color) {
|
|
|
159 s1 = g_strndup(font_color + 1, 6);
|
|
|
160 /* Henry: maybe this is a bug of gaim, the string should have
|
|
|
161 * the length of odd number @_@
|
|
|
162 */
|
|
|
163 s2 = g_strdup_printf("%sH", s1);
|
|
|
164 rgb = gaim_base16_decode(s2, NULL);
|
|
|
165 g_free(s1);
|
|
|
166 g_free(s2);
|
|
|
167 memcpy(send_im_tail + 2, rgb, 3);
|
|
|
168 g_free(rgb);
|
|
|
169 } else {
|
|
|
170 send_im_tail[2] = send_im_tail[3] = send_im_tail[4] = 0;
|
|
|
171 }
|
|
|
172
|
|
|
173 send_im_tail[5] = 0x00;
|
|
|
174 send_im_tail[6] = 0x86;
|
|
14021
|
175 send_im_tail[7] = 0x22; /* encoding, 0x8622=GB, 0x0000=EN, define BIG5 support here */
|
|
13870
|
176 _qq_show_packet("QQ_MESG", send_im_tail, tail_len);
|
|
|
177 return (guint8 *) send_im_tail;
|
|
14021
|
178 }
|
|
13870
|
179
|
|
|
180 static const gchar *qq_get_recv_im_type_str(gint type)
|
|
|
181 {
|
|
|
182 switch (type) {
|
|
|
183 case QQ_RECV_IM_TO_BUDDY:
|
|
|
184 return "QQ_RECV_IM_TO_BUDDY";
|
|
|
185 case QQ_RECV_IM_TO_UNKNOWN:
|
|
|
186 return "QQ_RECV_IM_TO_UNKNOWN";
|
|
|
187 case QQ_RECV_IM_UNKNOWN_QUN_IM:
|
|
|
188 return "QQ_RECV_IM_UNKNOWN_QUN_IM";
|
|
|
189 case QQ_RECV_IM_ADD_TO_QUN:
|
|
|
190 return "QQ_RECV_IM_ADD_TO_QUN";
|
|
|
191 case QQ_RECV_IM_DEL_FROM_QUN:
|
|
|
192 return "QQ_RECV_IM_DEL_FROM_QUN";
|
|
|
193 case QQ_RECV_IM_APPLY_ADD_TO_QUN:
|
|
|
194 return "QQ_RECV_IM_APPLY_ADD_TO_QUN";
|
|
|
195 case QQ_RECV_IM_CREATE_QUN:
|
|
|
196 return "QQ_RECV_IM_CREATE_QUN";
|
|
|
197 case QQ_RECV_IM_SYS_NOTIFICATION:
|
|
|
198 return "QQ_RECV_IM_SYS_NOTIFICATION";
|
|
|
199 case QQ_RECV_IM_APPROVE_APPLY_ADD_TO_QUN:
|
|
|
200 return "QQ_RECV_IM_APPROVE_APPLY_ADD_TO_QUN";
|
|
|
201 case QQ_RECV_IM_REJCT_APPLY_ADD_TO_QUN:
|
|
|
202 return "QQ_RECV_IM_REJCT_APPLY_ADD_TO_QUN";
|
|
|
203 case QQ_RECV_IM_TEMP_QUN_IM:
|
|
14021
|
204 return "QQ_RECV_IM_TEMP_QUN_IM";
|
|
13870
|
205 case QQ_RECV_IM_QUN_IM:
|
|
14021
|
206 return "QQ_RECV_IM_QUN_IM";
|
|
13870
|
207 default:
|
|
|
208 return "QQ_RECV_IM_UNKNOWN";
|
|
14021
|
209 }
|
|
|
210 }
|
|
13870
|
211
|
|
14021
|
212 /* generate a md5 key using uid and session_key */
|
|
|
213 gchar *_gen_session_md5(gint uid, gchar *session_key)
|
|
13870
|
214 {
|
|
|
215 gchar *src, md5_str[QQ_KEY_LENGTH];
|
|
|
216 guint8 *cursor;
|
|
|
217 GaimCipher *cipher;
|
|
|
218 GaimCipherContext *context;
|
|
|
219
|
|
|
220 src = g_newa(gchar, 20);
|
|
|
221 cursor = src;
|
|
|
222 create_packet_dw(src, &cursor, uid);
|
|
|
223 create_packet_data(src, &cursor, session_key, QQ_KEY_LENGTH);
|
|
|
224
|
|
|
225 cipher = gaim_ciphers_find_cipher("md5");
|
|
|
226 context = gaim_cipher_context_new(cipher, NULL);
|
|
|
227 gaim_cipher_context_append(context, src, 20);
|
|
|
228 gaim_cipher_context_digest(context, sizeof(md5_str), md5_str, NULL);
|
|
|
229 gaim_cipher_context_destroy(context);
|
|
|
230
|
|
|
231 return g_memdup(md5_str, QQ_KEY_LENGTH);
|
|
14021
|
232 }
|
|
13870
|
233
|
|
14021
|
234 /* when we receive a message,
|
|
|
235 * we send an ACK which is the first 16 bytes of incoming packet */
|
|
|
236 static void _qq_send_packet_recv_im_ack(GaimConnection *gc, guint16 seq, guint8 *data)
|
|
|
237 {
|
|
13870
|
238 qq_send_cmd(gc, QQ_CMD_RECV_IM, FALSE, seq, FALSE, data, 16);
|
|
14021
|
239 }
|
|
13870
|
240
|
|
14021
|
241 /* read the common parts of the normal_im,
|
|
|
242 * returns the bytes read if succeed, or -1 if there is any error */
|
|
|
243 static gint _qq_normal_im_common_read(guint8 *data, guint8 **cursor, gint len, qq_recv_normal_im_common *common)
|
|
|
244 {
|
|
13870
|
245 gint bytes;
|
|
|
246 g_return_val_if_fail(data != NULL && len != 0 && common != NULL, -1);
|
|
|
247
|
|
|
248 bytes = 0;
|
|
14021
|
249 /* now push data into common header */
|
|
13870
|
250 bytes += read_packet_w(data, cursor, len, &(common->sender_ver));
|
|
|
251 bytes += read_packet_dw(data, cursor, len, &(common->sender_uid));
|
|
|
252 bytes += read_packet_dw(data, cursor, len, &(common->receiver_uid));
|
|
|
253
|
|
|
254 common->session_md5 = g_memdup(*cursor, QQ_KEY_LENGTH);
|
|
|
255 bytes += QQ_KEY_LENGTH;
|
|
|
256 *cursor += QQ_KEY_LENGTH;
|
|
|
257
|
|
|
258 bytes += read_packet_w(data, cursor, len, &(common->normal_im_type));
|
|
|
259
|
|
14021
|
260 if (bytes != 28) { /* read common place fail */
|
|
13870
|
261 gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Expect 28 bytes, read %d bytes\n", bytes);
|
|
|
262 return -1;
|
|
14021
|
263 }
|
|
13870
|
264
|
|
|
265 return bytes;
|
|
14021
|
266 }
|
|
13870
|
267
|
|
14021
|
268 /* process received normal text IM */
|
|
13870
|
269 static void _qq_process_recv_normal_im_text
|
|
14021
|
270 (guint8 *data, guint8 **cursor, gint len, qq_recv_normal_im_common *common, GaimConnection *gc)
|
|
|
271 {
|
|
13870
|
272 guint16 gaim_msg_type;
|
|
|
273 gchar *name;
|
|
|
274 gchar *msg_with_gaim_smiley;
|
|
|
275 gchar *msg_utf8_encoded;
|
|
|
276 qq_data *qd;
|
|
|
277 qq_recv_normal_im_text *im_text;
|
|
|
278
|
|
|
279 g_return_if_fail(gc != NULL && gc->proto_data != NULL && common != NULL);
|
|
|
280 qd = (qq_data *) gc->proto_data;
|
|
|
281
|
|
14021
|
282 /* now it is QQ_NORMAL_IM_TEXT */
|
|
13870
|
283 if (*cursor >= (data + len - 1)) {
|
|
|
284 gaim_debug(GAIM_DEBUG_WARNING, "QQ", "Received normal IM text is empty\n");
|
|
|
285 return;
|
|
|
286 } else
|
|
|
287 im_text = g_newa(qq_recv_normal_im_text, 1);
|
|
|
288
|
|
|
289 im_text->common = common;
|
|
|
290
|
|
14021
|
291 /* push data into im_text */
|
|
13870
|
292 read_packet_w(data, cursor, len, &(im_text->msg_seq));
|
|
|
293 read_packet_dw(data, cursor, len, &(im_text->send_time));
|
|
|
294 read_packet_b(data, cursor, len, &(im_text->unknown1));
|
|
|
295 read_packet_b(data, cursor, len, &(im_text->sender_icon));
|
|
|
296 read_packet_data(data, cursor, len, (guint8 *) & (im_text->unknown2), 3);
|
|
|
297 read_packet_b(data, cursor, len, &(im_text->is_there_font_attr));
|
|
14021
|
298 /**
|
|
|
299 * from lumaqq for unknown3
|
|
|
300 * totalFragments = buf.get() & 255;
|
|
|
301 * fragmentSequence = buf.get() & 255;
|
|
|
302 * messageId = buf.getChar();
|
|
|
303 */
|
|
13870
|
304 read_packet_data(data, cursor, len, (guint8 *) & (im_text->unknown3), 4);
|
|
|
305 read_packet_b(data, cursor, len, &(im_text->msg_type));
|
|
|
306
|
|
14021
|
307 /* we need to check if this is auto-reply
|
|
|
308 * QQ2003iii build 0304, returns the msg without font_attr
|
|
|
309 * even the is_there_font_attr shows 0x01, and msg does not ends with 0x00 */
|
|
13870
|
310 if (im_text->msg_type == QQ_IM_AUTO_REPLY) {
|
|
14021
|
311 im_text->is_there_font_attr = 0x00; /* indeed there is no this flag */
|
|
13870
|
312 im_text->msg = g_strndup(*cursor, data + len - *cursor);
|
|
14021
|
313 } else { /* it is normal mesasge */
|
|
13870
|
314 if (im_text->is_there_font_attr) {
|
|
|
315 im_text->msg = g_strdup(*cursor);
|
|
|
316 *cursor += strlen(im_text->msg) + 1;
|
|
|
317 im_text->font_attr_len = data + len - *cursor;
|
|
|
318 im_text->font_attr = g_memdup(*cursor, im_text->font_attr_len);
|
|
14021
|
319 } else /* not im_text->is_there_font_attr */
|
|
13870
|
320 im_text->msg = g_strndup(*cursor, data + len - *cursor);
|
|
14021
|
321 } /* if im_text->msg_type */
|
|
13870
|
322 _qq_show_packet("QQ_MESG recv", data, *cursor - data);
|
|
|
323
|
|
|
324 name = uid_to_gaim_name(common->sender_uid);
|
|
|
325 if (gaim_find_buddy(gc->account, name) == NULL)
|
|
|
326 qq_add_buddy_by_recv_packet(gc, common->sender_uid, FALSE, TRUE);
|
|
|
327
|
|
|
328 gaim_msg_type = (im_text->msg_type == QQ_IM_AUTO_REPLY) ? GAIM_MESSAGE_AUTO_RESP : 0;
|
|
|
329
|
|
|
330 msg_with_gaim_smiley = qq_smiley_to_gaim(im_text->msg);
|
|
|
331 msg_utf8_encoded = im_text->is_there_font_attr ?
|
|
|
332 qq_encode_to_gaim(im_text->font_attr,
|
|
|
333 im_text->font_attr_len,
|
|
|
334 msg_with_gaim_smiley) : qq_to_utf8(msg_with_gaim_smiley, QQ_CHARSET_DEFAULT);
|
|
|
335
|
|
14021
|
336 /* send encoded to gaim, note that we use im_text->send_time,
|
|
|
337 * not the time we receive the message
|
|
|
338 * as it may have been dealyed when I am not online. */
|
|
13870
|
339 serv_got_im(gc, name, msg_utf8_encoded, gaim_msg_type, (time_t) im_text->send_time);
|
|
|
340
|
|
|
341 g_free(msg_utf8_encoded);
|
|
|
342 g_free(msg_with_gaim_smiley);
|
|
|
343 g_free(name);
|
|
|
344 g_free(im_text->msg);
|
|
|
345 if (im_text->is_there_font_attr)
|
|
|
346 g_free(im_text->font_attr);
|
|
14021
|
347 }
|
|
13870
|
348
|
|
14021
|
349 /* it is a normal IM, maybe text or video request */
|
|
|
350 static void _qq_process_recv_normal_im(guint8 *data, guint8 **cursor, gint len, GaimConnection *gc)
|
|
13870
|
351 {
|
|
|
352 gint bytes;
|
|
|
353 qq_recv_normal_im_common *common;
|
|
|
354 qq_recv_normal_im_unprocessed *im_unprocessed;
|
|
|
355
|
|
|
356 g_return_if_fail (data != NULL && len != 0);
|
|
|
357
|
|
|
358 if (*cursor >= (data + len - 1)) {
|
|
|
359 gaim_debug (GAIM_DEBUG_WARNING, "QQ",
|
|
|
360 "Received normal IM is empty\n");
|
|
|
361 return;
|
|
|
362 }
|
|
|
363 else
|
|
|
364 common = g_newa (qq_recv_normal_im_common, 1);
|
|
|
365
|
|
|
366 bytes = _qq_normal_im_common_read (data, cursor, len, common);
|
|
|
367 if (bytes < 0) {
|
|
|
368 gaim_debug (GAIM_DEBUG_ERROR, "QQ",
|
|
|
369 "Fail read the common part of normal IM\n");
|
|
|
370 return;
|
|
14021
|
371 }
|
|
13870
|
372
|
|
|
373 switch (common->normal_im_type) {
|
|
|
374 case QQ_NORMAL_IM_TEXT:
|
|
|
375 gaim_debug (GAIM_DEBUG_INFO,
|
|
|
376 "QQ",
|
|
|
377 "Normal IM, text type:\n [%d] => [%d], src: %s\n",
|
|
|
378 common->sender_uid, common->receiver_uid,
|
|
|
379 qq_get_source_str (common->sender_ver));
|
|
|
380 _qq_process_recv_normal_im_text (data, cursor, len, common,
|
|
|
381 gc);
|
|
|
382 break;
|
|
|
383 case QQ_NORMAL_IM_FILE_REJECT_UDP:
|
|
|
384 qq_process_recv_file_reject (data, cursor, len,
|
|
|
385 common->sender_uid, gc);
|
|
|
386 break;
|
|
|
387 case QQ_NORMAL_IM_FILE_APPROVE_UDP:
|
|
|
388 qq_process_recv_file_accept (data, cursor, len,
|
|
|
389 common->sender_uid, gc);
|
|
|
390 break;
|
|
|
391 case QQ_NORMAL_IM_FILE_REQUEST_UDP:
|
|
|
392 qq_process_recv_file_request (data, cursor, len,
|
|
|
393 common->sender_uid, gc);
|
|
|
394 break;
|
|
|
395 case QQ_NORMAL_IM_FILE_CANCEL:
|
|
|
396 qq_process_recv_file_cancel (data, cursor, len,
|
|
|
397 common->sender_uid, gc);
|
|
|
398 break;
|
|
|
399 case QQ_NORMAL_IM_FILE_NOTIFY:
|
|
|
400 qq_process_recv_file_notify (data, cursor, len,
|
|
|
401 common->sender_uid, gc);
|
|
|
402 break;
|
|
|
403 default:
|
|
|
404 im_unprocessed = g_newa (qq_recv_normal_im_unprocessed, 1);
|
|
|
405 im_unprocessed->common = common;
|
|
|
406 im_unprocessed->unknown = *cursor;
|
|
|
407 im_unprocessed->length = data + len - *cursor;
|
|
14021
|
408 /* a simple process here, maybe more later */
|
|
13870
|
409 gaim_debug (GAIM_DEBUG_WARNING, "QQ",
|
|
|
410 "Normal IM, unprocessed type [0x%04x]\n",
|
|
|
411 common->normal_im_type);
|
|
|
412 gaim_debug (GAIM_DEBUG_WARNING, "QQ",
|
|
|
413 "Dump unknown part.\n%s",
|
|
|
414 hex_dump_to_str (im_unprocessed->unknown,
|
|
|
415 im_unprocessed->length));
|
|
|
416 g_free (common->session_md5);
|
|
|
417 return;
|
|
14021
|
418 }
|
|
13870
|
419
|
|
|
420 g_free (common->session_md5);
|
|
14021
|
421 }
|
|
13870
|
422
|
|
14021
|
423 /* process im from system administrator */
|
|
|
424 static void _qq_process_recv_sys_im(guint8 *data, guint8 **cursor, gint data_len, GaimConnection *gc)
|
|
|
425 {
|
|
13870
|
426 gint len;
|
|
|
427 guint8 reply;
|
|
|
428 gchar **segments, *msg_utf8;
|
|
|
429
|
|
|
430 g_return_if_fail(gc != NULL && data != NULL && data_len != 0);
|
|
|
431
|
|
|
432 if (*cursor >= (data + data_len - 1)) {
|
|
|
433 gaim_debug(GAIM_DEBUG_WARNING, "QQ", "Received sys IM is empty\n");
|
|
|
434 return;
|
|
|
435 }
|
|
|
436
|
|
|
437 len = data + data_len - *cursor;
|
|
|
438
|
|
|
439 if (NULL == (segments = split_data(*cursor, len, "\x2f", 2)))
|
|
|
440 return;
|
|
|
441
|
|
|
442 reply = strtol(segments[0], NULL, 10);
|
|
|
443 if (reply == QQ_RECV_SYS_IM_KICK_OUT)
|
|
|
444 gaim_debug(GAIM_DEBUG_WARNING, "QQ", "We are kicked out by QQ server\n");
|
|
|
445 msg_utf8 = qq_to_utf8(segments[1], QQ_CHARSET_DEFAULT);
|
|
|
446 gaim_notify_warning(gc, NULL, _("System Message"), msg_utf8);
|
|
14021
|
447 }
|
|
13870
|
448
|
|
14021
|
449 /* send an IM to to_uid */
|
|
|
450 void qq_send_packet_im(GaimConnection *gc, guint32 to_uid, gchar *msg, gint type)
|
|
|
451 {
|
|
13870
|
452 qq_data *qd;
|
|
|
453 guint8 *cursor, *raw_data;
|
|
|
454 guint16 client_tag, normal_im_type;
|
|
|
455 gint msg_len, raw_len, bytes;
|
|
|
456 time_t now;
|
|
|
457 gchar *md5, *msg_filtered;
|
|
|
458 GData *attribs;
|
|
|
459 gchar *font_size = NULL, *font_color = NULL, *font_name = NULL, *tmp;
|
|
|
460 gboolean is_bold = FALSE, is_italic = FALSE, is_underline = FALSE;
|
|
|
461 const gchar *start, *end, *last;
|
|
|
462
|
|
|
463 g_return_if_fail(gc != NULL && gc->proto_data != NULL);
|
|
|
464
|
|
|
465 qd = (qq_data *) gc->proto_data;
|
|
|
466 client_tag = QQ_CLIENT;
|
|
|
467 normal_im_type = QQ_NORMAL_IM_TEXT;
|
|
|
468
|
|
|
469 last = msg;
|
|
|
470 while (gaim_markup_find_tag("font", last, &start, &end, &attribs)) {
|
|
|
471 tmp = g_datalist_get_data(&attribs, "size");
|
|
|
472 if (tmp) {
|
|
|
473 if (font_size)
|
|
|
474 g_free(font_size);
|
|
|
475 font_size = g_strdup(tmp);
|
|
|
476 }
|
|
|
477 tmp = g_datalist_get_data(&attribs, "color");
|
|
|
478 if (tmp) {
|
|
|
479 if (font_color)
|
|
|
480 g_free(font_color);
|
|
|
481 font_color = g_strdup(tmp);
|
|
|
482 }
|
|
|
483 tmp = g_datalist_get_data(&attribs, "face");
|
|
|
484 if (tmp) {
|
|
|
485 if (font_name)
|
|
|
486 g_free(font_name);
|
|
|
487 font_name = g_strdup(tmp);
|
|
|
488 }
|
|
|
489
|
|
|
490 g_datalist_clear(&attribs);
|
|
|
491 last = end + 1;
|
|
|
492 }
|
|
|
493
|
|
|
494 if (gaim_markup_find_tag("b", msg, &start, &end, &attribs)) {
|
|
|
495 is_bold = TRUE;
|
|
|
496 g_datalist_clear(&attribs);
|
|
|
497 }
|
|
|
498
|
|
|
499 if (gaim_markup_find_tag("i", msg, &start, &end, &attribs)) {
|
|
|
500 is_italic = TRUE;
|
|
|
501 g_datalist_clear(&attribs);
|
|
|
502 }
|
|
|
503
|
|
|
504 if (gaim_markup_find_tag("u", msg, &start, &end, &attribs)) {
|
|
|
505 is_underline = TRUE;
|
|
|
506 g_datalist_clear(&attribs);
|
|
|
507 }
|
|
|
508
|
|
|
509 gaim_debug(GAIM_DEBUG_INFO, "QQ_MESG", "send mesg: %s\n", msg);
|
|
|
510 msg_filtered = gaim_markup_strip_html(msg);
|
|
|
511 msg_len = strlen(msg_filtered);
|
|
|
512 now = time(NULL);
|
|
|
513 md5 = _gen_session_md5(qd->uid, qd->session_key);
|
|
|
514
|
|
|
515 guint font_name_len, tail_len;
|
|
|
516 font_name_len = (font_name) ? strlen(font_name) : DEFAULT_FONT_NAME_LEN;
|
|
|
517 tail_len = font_name_len + QQ_SEND_IM_AFTER_MSG_HEADER_LEN + 1;
|
|
|
518
|
|
|
519 raw_len = QQ_SEND_IM_BEFORE_MSG_LEN + msg_len + tail_len;
|
|
|
520 raw_data = g_newa(guint8, raw_len);
|
|
|
521 cursor = raw_data;
|
|
|
522 bytes = 0;
|
|
|
523
|
|
14021
|
524 /* 000-003: receiver uid */
|
|
13870
|
525 bytes += create_packet_dw(raw_data, &cursor, qd->uid);
|
|
14021
|
526 /* 004-007: sender uid */
|
|
13870
|
527 bytes += create_packet_dw(raw_data, &cursor, to_uid);
|
|
14021
|
528 /* 008-009: sender client version */
|
|
13870
|
529 bytes += create_packet_w(raw_data, &cursor, client_tag);
|
|
14021
|
530 /* 010-013: receiver uid */
|
|
13870
|
531 bytes += create_packet_dw(raw_data, &cursor, qd->uid);
|
|
14021
|
532 /* 014-017: sender uid */
|
|
13870
|
533 bytes += create_packet_dw(raw_data, &cursor, to_uid);
|
|
14021
|
534 /* 018-033: md5 of (uid+session_key) */
|
|
13870
|
535 bytes += create_packet_data(raw_data, &cursor, md5, 16);
|
|
14021
|
536 /* 034-035: message type */
|
|
13870
|
537 bytes += create_packet_w(raw_data, &cursor, normal_im_type);
|
|
14021
|
538 /* 036-037: sequence number */
|
|
13870
|
539 bytes += create_packet_w(raw_data, &cursor, qd->send_seq);
|
|
14021
|
540 /* 038-041: send time */
|
|
13870
|
541 bytes += create_packet_dw(raw_data, &cursor, (guint32) now);
|
|
14021
|
542 /* 042-042: always 0x00 */
|
|
13870
|
543 bytes += create_packet_b(raw_data, &cursor, 0x00);
|
|
14021
|
544 /* 043-043: sender icon */
|
|
13870
|
545 bytes += create_packet_b(raw_data, &cursor, qd->my_icon);
|
|
14021
|
546 /* 044-046: always 0x00 */
|
|
13870
|
547 bytes += create_packet_w(raw_data, &cursor, 0x0000);
|
|
|
548 bytes += create_packet_b(raw_data, &cursor, 0x00);
|
|
14021
|
549 /* 047-047: we use font attr */
|
|
13870
|
550 bytes += create_packet_b(raw_data, &cursor, 0x01);
|
|
14021
|
551 /* 048-051: always 0x00 */
|
|
13870
|
552 bytes += create_packet_dw(raw_data, &cursor, 0x00000000);
|
|
14021
|
553 /* 052-052: text message type (normal/auto-reply) */
|
|
13870
|
554 bytes += create_packet_b(raw_data, &cursor, type);
|
|
14021
|
555 /* 053- : msg ends with 0x00 */
|
|
13870
|
556 bytes += create_packet_data(raw_data, &cursor, msg_filtered, msg_len);
|
|
|
557 guint8 *send_im_tail = qq_get_send_im_tail(font_color, font_size, font_name, is_bold,
|
|
|
558 is_italic, is_underline, tail_len);
|
|
|
559 _qq_show_packet("QQ_MESG debug", send_im_tail, tail_len);
|
|
|
560 bytes += create_packet_data(raw_data, &cursor, (gchar *) send_im_tail, tail_len);
|
|
|
561
|
|
|
562 _qq_show_packet("QQ_MESG raw", raw_data, cursor - raw_data);
|
|
|
563
|
|
14021
|
564 if (bytes == raw_len) /* create packet OK */
|
|
13870
|
565 qq_send_cmd(gc, QQ_CMD_SEND_IM, TRUE, 0, TRUE, raw_data, cursor - raw_data);
|
|
|
566 else
|
|
|
567 gaim_debug(GAIM_DEBUG_ERROR, "QQ",
|
|
|
568 "Fail creating send_im packet, expect %d bytes, build %d bytes\n", raw_len, bytes);
|
|
|
569
|
|
|
570 if (font_color)
|
|
|
571 g_free(font_color);
|
|
|
572 if (font_size)
|
|
|
573 g_free(font_size);
|
|
|
574 g_free(send_im_tail);
|
|
|
575 g_free(msg_filtered);
|
|
14021
|
576 }
|
|
13870
|
577
|
|
14021
|
578 /* parse the reply to send_im */
|
|
|
579 void qq_process_send_im_reply(guint8 *buf, gint buf_len, GaimConnection *gc)
|
|
13870
|
580 {
|
|
|
581 qq_data *qd;
|
|
|
582 gint len;
|
|
|
583 guint8 *data, *cursor, reply;
|
|
|
584
|
|
|
585 g_return_if_fail(gc != NULL && gc->proto_data != NULL);
|
|
|
586 g_return_if_fail(buf != NULL && buf_len != 0);
|
|
|
587
|
|
|
588 qd = gc->proto_data;
|
|
|
589 len = buf_len;
|
|
|
590 data = g_newa(guint8, len);
|
|
|
591
|
|
|
592 if (qq_crypt(DECRYPT, buf, buf_len, qd->session_key, data, &len)) {
|
|
|
593 cursor = data;
|
|
|
594 read_packet_b(data, &cursor, len, &reply);
|
|
|
595 if (reply != QQ_SEND_IM_REPLY_OK) {
|
|
|
596 gaim_debug(GAIM_DEBUG_WARNING, "QQ", "Send IM fail\n");
|
|
|
597 gaim_notify_error(gc, _("Server ACK"), _("Send IM fail\n"), NULL);
|
|
|
598 }
|
|
|
599 else
|
|
|
600 gaim_debug(GAIM_DEBUG_INFO, "QQ", "IM ACK OK\n");
|
|
|
601 } else {
|
|
|
602 gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Error decrypt send im reply\n");
|
|
|
603 }
|
|
14021
|
604 }
|
|
13870
|
605
|
|
14021
|
606 /* I receive a message, mainly it is text msg,
|
|
|
607 * but we need to proess other types (group etc) */
|
|
|
608 void qq_process_recv_im(guint8 *buf, gint buf_len, guint16 seq, GaimConnection *gc)
|
|
|
609 {
|
|
13870
|
610 qq_data *qd;
|
|
|
611 gint len, bytes;
|
|
|
612 guint8 *data, *cursor;
|
|
|
613 qq_recv_im_header *im_header;
|
|
|
614
|
|
|
615 g_return_if_fail(gc != NULL && gc->proto_data != NULL);
|
|
|
616 g_return_if_fail(buf != NULL && buf_len != 0);
|
|
|
617
|
|
|
618 qd = (qq_data *) gc->proto_data;
|
|
|
619 len = buf_len;
|
|
|
620 data = g_newa(guint8, len);
|
|
|
621
|
|
|
622 if (qq_crypt(DECRYPT, buf, buf_len, qd->session_key, data, &len)) {
|
|
14021
|
623 if (len < 16) { /* we need to ack with the first 16 bytes */
|
|
13870
|
624 gaim_debug(GAIM_DEBUG_ERROR, "QQ", "IM is too short\n");
|
|
|
625 return;
|
|
|
626 } else
|
|
|
627 _qq_send_packet_recv_im_ack(gc, seq, data);
|
|
|
628
|
|
|
629 cursor = data;
|
|
|
630 bytes = 0;
|
|
|
631 im_header = g_newa(qq_recv_im_header, 1);
|
|
|
632 bytes += read_packet_dw(data, &cursor, len, &(im_header->sender_uid));
|
|
|
633 bytes += read_packet_dw(data, &cursor, len, &(im_header->receiver_uid));
|
|
|
634 bytes += read_packet_dw(data, &cursor, len, &(im_header->server_im_seq));
|
|
14021
|
635 /* if the message is delivered via server, it is server IP/port */
|
|
13870
|
636 bytes += read_packet_data(data, &cursor, len, (guint8 *) & (im_header->sender_ip), 4);
|
|
|
637 bytes += read_packet_w(data, &cursor, len, &(im_header->sender_port));
|
|
|
638 bytes += read_packet_w(data, &cursor, len, &(im_header->im_type));
|
|
|
639
|
|
14021
|
640 if (bytes != 20) { /* length of im_header */
|
|
13870
|
641 gaim_debug(GAIM_DEBUG_ERROR, "QQ",
|
|
|
642 "Fail read recv IM header, expect 20 bytes, read %d bytes\n", bytes);
|
|
|
643 return;
|
|
14021
|
644 }
|
|
13870
|
645
|
|
14021
|
646 if (im_header->receiver_uid != qd->uid) { /* should not happen */
|
|
13870
|
647 gaim_debug(GAIM_DEBUG_ERROR, "QQ", "IM to [%d], NOT me\n", im_header->receiver_uid);
|
|
|
648 return;
|
|
14021
|
649 }
|
|
13870
|
650
|
|
|
651 switch (im_header->im_type) {
|
|
|
652 case QQ_RECV_IM_TO_BUDDY:
|
|
|
653 gaim_debug(GAIM_DEBUG_INFO, "QQ",
|
|
|
654 "IM from buddy [%d], I am in his/her buddy list\n", im_header->sender_uid);
|
|
|
655 _qq_process_recv_normal_im(data, &cursor, len, gc);
|
|
|
656 break;
|
|
|
657 case QQ_RECV_IM_TO_UNKNOWN:
|
|
|
658 gaim_debug(GAIM_DEBUG_INFO, "QQ",
|
|
|
659 "IM from buddy [%d], I am a stranger to him/her\n", im_header->sender_uid);
|
|
|
660 _qq_process_recv_normal_im(data, &cursor, len, gc);
|
|
|
661 break;
|
|
|
662 case QQ_RECV_IM_UNKNOWN_QUN_IM:
|
|
|
663 case QQ_RECV_IM_TEMP_QUN_IM:
|
|
|
664 case QQ_RECV_IM_QUN_IM:
|
|
|
665 gaim_debug(GAIM_DEBUG_INFO, "QQ", "IM from group, internal_id [%d]\n", im_header->sender_uid);
|
|
14021
|
666 /* sender_uid is in fact internal_group_id */
|
|
13870
|
667 qq_process_recv_group_im(data, &cursor, len, im_header->sender_uid, gc, im_header->im_type);
|
|
|
668 break;
|
|
|
669 case QQ_RECV_IM_ADD_TO_QUN:
|
|
|
670 gaim_debug(GAIM_DEBUG_INFO, "QQ",
|
|
|
671 "IM from group, added by group internal_id [%d]\n", im_header->sender_uid);
|
|
14021
|
672 /* sender_uid is in fact internal_group_id
|
|
|
673 * we need this to create a dummy group and add to blist */
|
|
13870
|
674 qq_process_recv_group_im_been_added(data, &cursor, len, im_header->sender_uid, gc);
|
|
|
675 break;
|
|
|
676 case QQ_RECV_IM_DEL_FROM_QUN:
|
|
|
677 gaim_debug(GAIM_DEBUG_INFO, "QQ",
|
|
|
678 "IM from group, removed by group internal_ID [%d]\n", im_header->sender_uid);
|
|
14021
|
679 /* sender_uid is in fact internal_group_id */
|
|
13870
|
680 qq_process_recv_group_im_been_removed(data, &cursor, len, im_header->sender_uid, gc);
|
|
|
681 break;
|
|
|
682 case QQ_RECV_IM_APPLY_ADD_TO_QUN:
|
|
|
683 gaim_debug(GAIM_DEBUG_INFO, "QQ",
|
|
|
684 "IM from group, apply to join group internal_ID [%d]\n", im_header->sender_uid);
|
|
14021
|
685 /* sender_uid is in fact internal_group_id */
|
|
13870
|
686 qq_process_recv_group_im_apply_join(data, &cursor, len, im_header->sender_uid, gc);
|
|
|
687 break;
|
|
|
688 case QQ_RECV_IM_APPROVE_APPLY_ADD_TO_QUN:
|
|
|
689 gaim_debug(GAIM_DEBUG_INFO, "QQ",
|
|
|
690 "IM for group system info, approved by group internal_id [%d]\n",
|
|
|
691 im_header->sender_uid);
|
|
14021
|
692 /* sender_uid is in fact internal_group_id */
|
|
13870
|
693 qq_process_recv_group_im_been_approved(data, &cursor, len, im_header->sender_uid, gc);
|
|
|
694 break;
|
|
|
695 case QQ_RECV_IM_REJCT_APPLY_ADD_TO_QUN:
|
|
|
696 gaim_debug(GAIM_DEBUG_INFO, "QQ",
|
|
|
697 "IM for group system info, rejected by group internal_id [%d]\n",
|
|
|
698 im_header->sender_uid);
|
|
14021
|
699 /* sender_uid is in fact internal_group_id */
|
|
13870
|
700 qq_process_recv_group_im_been_rejected(data, &cursor, len, im_header->sender_uid, gc);
|
|
|
701 break;
|
|
|
702 case QQ_RECV_IM_SYS_NOTIFICATION:
|
|
|
703 gaim_debug(GAIM_DEBUG_INFO, "QQ",
|
|
|
704 "IM from [%d], should be a system administrator\n", im_header->sender_uid);
|
|
|
705 _qq_process_recv_sys_im(data, &cursor, len, gc);
|
|
|
706 break;
|
|
|
707 default:
|
|
|
708 gaim_debug(GAIM_DEBUG_WARNING, "QQ",
|
|
|
709 "IM from [%d], [0x%02x] %s is not processed\n",
|
|
|
710 im_header->sender_uid,
|
|
|
711 im_header->im_type, qq_get_recv_im_type_str(im_header->im_type));
|
|
14021
|
712 }
|
|
|
713 } else {
|
|
13870
|
714 gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Error decrypt rev im\n");
|
|
14021
|
715 }
|
|
|
716 }
|