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