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
|
|
23 // START OF FILE
|
|
24 /*****************************************************************************/
|
|
25 #include "debug.h"
|
|
26 #include "conversation.h" // GaimConversation
|
|
27 #include "notify.h" // gaim_notify_warning
|
|
28 #include "prefs.h" // gaim_prefs_get_bool
|
|
29 #include "request.h" // gaim_request_action
|
|
30 #include "util.h"
|
|
31
|
|
32 #include "utils.h" // uid_to_gaim_name
|
|
33 #include "packet_parse.h" // create_packet_xx
|
|
34 #include "char_conv.h" // qq_smiley_to_gaim
|
|
35 #include "group_find.h" // qq_group_find_by_external_group_id
|
|
36 #include "group_hash.h" // qq_group_refresh
|
|
37 #include "group_info.h" // qq_send_cmd_group_get_group_info
|
|
38 #include "group_im.h"
|
|
39 #include "group_network.h" // qq_send_group_cmd
|
|
40 #include "group_opt.h" // add_group_member
|
|
41 #include "im.h" // QQ_SEND_IM_AFTER_MSG_LEN
|
|
42
|
|
43 typedef struct _qq_recv_group_im {
|
|
44 guint32 external_group_id;
|
|
45 guint8 group_type;
|
|
46 guint32 member_uid;
|
|
47 guint16 msg_seq;
|
|
48 time_t send_time;
|
|
49 guint16 msg_len;
|
|
50 guint8 *msg;
|
|
51 guint8 *font_attr;
|
|
52 gint font_attr_len;
|
|
53 } qq_recv_group_im;
|
|
54
|
|
55 /*****************************************************************************/
|
|
56 // send IM to a group
|
|
57 void qq_send_packet_group_im(GaimConnection * gc, qq_group * group, const gchar * msg) {
|
|
58 gint data_len, bytes;
|
|
59 guint8 *raw_data, *cursor;
|
|
60 guint16 msg_len;
|
|
61 gchar *msg_filtered;
|
|
62
|
|
63 g_return_if_fail(gc != NULL && group != NULL && msg != NULL);
|
|
64
|
|
65 msg_filtered = gaim_markup_strip_html(msg);
|
|
66 msg_len = strlen(msg_filtered);
|
|
67 data_len = 7 + msg_len + QQ_SEND_IM_AFTER_MSG_LEN;
|
|
68 raw_data = g_newa(guint8, data_len);
|
|
69 cursor = raw_data;
|
|
70
|
|
71 bytes = 0;
|
|
72 bytes += create_packet_b(raw_data, &cursor, QQ_GROUP_CMD_SEND_MSG);
|
|
73 bytes += create_packet_dw(raw_data, &cursor, group->internal_group_id);
|
|
74 bytes += create_packet_w(raw_data, &cursor, msg_len + QQ_SEND_IM_AFTER_MSG_LEN);
|
|
75 bytes += create_packet_data(raw_data, &cursor, (gchar *) msg_filtered, msg_len);
|
|
76 guint8 *send_im_tail = qq_get_send_im_tail(NULL, NULL, NULL,
|
|
77 FALSE, FALSE, FALSE,
|
|
78 QQ_SEND_IM_AFTER_MSG_LEN);
|
|
79 bytes += create_packet_data(raw_data, &cursor, (gchar *) send_im_tail, QQ_SEND_IM_AFTER_MSG_LEN);
|
|
80 g_free(send_im_tail);
|
|
81 g_free(msg_filtered);
|
|
82
|
|
83 if (bytes == data_len) // create OK
|
|
84 qq_send_group_cmd(gc, group, raw_data, data_len);
|
|
85 else
|
|
86 gaim_debug(GAIM_DEBUG_ERROR, "QQ",
|
|
87 "Fail creating group_im packet, expect %d bytes, build %d bytes\n", data_len, bytes);
|
|
88
|
|
89 } // qq_send_packet_group_im
|
|
90
|
|
91 /*****************************************************************************/
|
|
92 // this is the ACK
|
|
93 void qq_process_group_cmd_im(guint8 * data, guint8 ** cursor, gint len, GaimConnection * gc) {
|
|
94 // return should be the internal group id
|
|
95 // but we have nothing to do with it
|
|
96 return;
|
|
97 } // qq_process_group_cmd_im
|
|
98
|
|
99 /*****************************************************************************/
|
|
100 // receive an application to join the group
|
|
101 void qq_process_recv_group_im_apply_join
|
|
102 (guint8 * data, guint8 ** cursor, gint len, guint32 internal_group_id, GaimConnection * gc) {
|
|
103 guint32 external_group_id, user_uid;
|
|
104 guint8 group_type;
|
|
105 gchar *reason_utf8, *msg, *reason;
|
|
106 group_member_opt *g;
|
|
107
|
|
108 g_return_if_fail(gc != NULL && internal_group_id > 0 && data != NULL && len > 0);
|
|
109
|
|
110 if (*cursor >= (data + len - 1)) {
|
|
111 gaim_debug(GAIM_DEBUG_WARNING, "QQ", "Received group msg apply_join is empty\n");
|
|
112 return;
|
|
113 } // if
|
|
114
|
|
115 read_packet_dw(data, cursor, len, &external_group_id);
|
|
116 read_packet_b(data, cursor, len, &group_type);
|
|
117 read_packet_dw(data, cursor, len, &user_uid);
|
|
118
|
|
119 g_return_if_fail(external_group_id > 0 && user_uid > 0);
|
|
120
|
|
121 convert_as_pascal_string(*cursor, &reason_utf8, QQ_CHARSET_DEFAULT);
|
|
122
|
|
123 msg = g_strdup_printf(_("User %d applied to join group %d"), user_uid, external_group_id);
|
|
124 reason = g_strdup_printf(_("Reason: %s"), reason_utf8);
|
|
125
|
|
126 g = g_new0(group_member_opt, 1);
|
|
127 g->gc = gc;
|
|
128 g->internal_group_id = internal_group_id;
|
|
129 g->member = user_uid;
|
|
130
|
|
131 gaim_request_action(gc, _("QQ Qun Operation"),
|
|
132 msg, reason,
|
|
133 2, g, 3,
|
|
134 _("Approve"),
|
|
135 G_CALLBACK
|
|
136 (qq_group_approve_application_with_struct),
|
|
137 _("Reject"),
|
|
138 G_CALLBACK
|
|
139 (qq_group_reject_application_with_struct),
|
|
140 _("Search"), G_CALLBACK(qq_group_search_application_with_struct));
|
|
141
|
|
142 g_free(reason);
|
|
143 g_free(msg);
|
|
144 g_free(reason_utf8);
|
|
145
|
|
146 } // qq_process_recv_group_im_apply_join
|
|
147
|
|
148 /*****************************************************************************/
|
|
149 // the request to join a group is rejected
|
|
150 void qq_process_recv_group_im_been_rejected
|
|
151 (guint8 * data, guint8 ** cursor, gint len, guint32 internal_group_id, GaimConnection * gc) {
|
|
152 guint32 external_group_id, admin_uid;
|
|
153 guint8 group_type;
|
|
154 gchar *reason_utf8, *msg, *reason;
|
|
155 qq_group *group;
|
|
156
|
|
157 g_return_if_fail(gc != NULL && data != NULL && len > 0);
|
|
158
|
|
159 if (*cursor >= (data + len - 1)) {
|
|
160 gaim_debug(GAIM_DEBUG_WARNING, "QQ", "Received group msg been_rejected is empty\n");
|
|
161 return;
|
|
162 } // if
|
|
163
|
|
164 read_packet_dw(data, cursor, len, &external_group_id);
|
|
165 read_packet_b(data, cursor, len, &group_type);
|
|
166 read_packet_dw(data, cursor, len, &admin_uid);
|
|
167
|
|
168 g_return_if_fail(external_group_id > 0 && admin_uid > 0);
|
|
169
|
|
170 convert_as_pascal_string(*cursor, &reason_utf8, QQ_CHARSET_DEFAULT);
|
|
171
|
|
172 msg = g_strdup_printf
|
|
173 (_("You request to join group %d has been rejected by admin %d"), external_group_id, admin_uid);
|
|
174 reason = g_strdup_printf(_("Reason: %s"), reason_utf8);
|
|
175
|
|
176 gaim_notify_warning(gc, _("QQ Qun Operation"), msg, reason);
|
|
177
|
|
178 group = qq_group_find_by_internal_group_id(gc, internal_group_id);
|
|
179 if (group != NULL) {
|
|
180 group->my_status = QQ_GROUP_MEMBER_STATUS_NOT_MEMBER;
|
|
181 qq_group_refresh(gc, group);
|
|
182 } // if group
|
|
183
|
|
184 g_free(reason);
|
|
185 g_free(msg);
|
|
186 g_free(reason_utf8);
|
|
187
|
|
188 } // qq_process_group_im_being_rejected
|
|
189
|
|
190 /*****************************************************************************/
|
|
191 // the request to join a group is approved
|
|
192 void qq_process_recv_group_im_been_approved
|
|
193 (guint8 * data, guint8 ** cursor, gint len, guint32 internal_group_id, GaimConnection * gc) {
|
|
194 guint32 external_group_id, admin_uid;
|
|
195 guint8 group_type;
|
|
196 gchar *reason_utf8, *msg;
|
|
197 qq_group *group;
|
|
198
|
|
199 g_return_if_fail(gc != NULL && data != NULL && len > 0);
|
|
200
|
|
201 if (*cursor >= (data + len - 1)) {
|
|
202 gaim_debug(GAIM_DEBUG_WARNING, "QQ", "Received group msg been_approved is empty\n");
|
|
203 return;
|
|
204 } // if
|
|
205
|
|
206 read_packet_dw(data, cursor, len, &external_group_id);
|
|
207 read_packet_b(data, cursor, len, &group_type);
|
|
208 read_packet_dw(data, cursor, len, &admin_uid);
|
|
209
|
|
210 g_return_if_fail(external_group_id > 0 && admin_uid > 0);
|
|
211 // it is also a "æ— " here, so do not display
|
|
212 convert_as_pascal_string(*cursor, &reason_utf8, QQ_CHARSET_DEFAULT);
|
|
213
|
|
214 msg = g_strdup_printf
|
|
215 (_("You request to join group %d has been approved by admin %d"), external_group_id, admin_uid);
|
|
216
|
|
217 gaim_notify_warning(gc, _("QQ Qun Operation"), msg, NULL);
|
|
218
|
|
219 group = qq_group_find_by_internal_group_id(gc, internal_group_id);
|
|
220 if (group != NULL) {
|
|
221 group->my_status = QQ_GROUP_MEMBER_STATUS_IS_MEMBER;
|
|
222 qq_group_refresh(gc, group);
|
|
223 } // if group
|
|
224
|
|
225 g_free(msg);
|
|
226 g_free(reason_utf8);
|
|
227 } // qq_process_group_im_being_approved
|
|
228
|
|
229 /*****************************************************************************/
|
|
230 // process the packet when reomved from a group
|
|
231 void qq_process_recv_group_im_been_removed
|
|
232 (guint8 * data, guint8 ** cursor, gint len, guint32 internal_group_id, GaimConnection * gc) {
|
|
233 guint32 external_group_id, uid;
|
|
234 guint8 group_type;
|
|
235 gchar *msg;
|
|
236 qq_group *group;
|
|
237
|
|
238 g_return_if_fail(gc != NULL && data != NULL && len > 0);
|
|
239
|
|
240 if (*cursor >= (data + len - 1)) {
|
|
241 gaim_debug(GAIM_DEBUG_WARNING, "QQ", "Received group msg been_removed is empty\n");
|
|
242 return;
|
|
243 } // if
|
|
244
|
|
245 read_packet_dw(data, cursor, len, &external_group_id);
|
|
246 read_packet_b(data, cursor, len, &group_type);
|
|
247 read_packet_dw(data, cursor, len, &uid);
|
|
248
|
|
249 g_return_if_fail(external_group_id > 0 && uid > 0);
|
|
250
|
|
251 msg = g_strdup_printf(_("You [%d] has exit group \"%d\""), uid, external_group_id);
|
|
252 gaim_notify_info(gc, _("QQ Qun Operation"), msg, NULL);
|
|
253
|
|
254 group = qq_group_find_by_internal_group_id(gc, internal_group_id);
|
|
255 if (group != NULL) {
|
|
256 group->my_status = QQ_GROUP_MEMBER_STATUS_NOT_MEMBER;
|
|
257 qq_group_refresh(gc, group);
|
|
258 } // if group
|
|
259
|
|
260 g_free(msg);
|
|
261 } // qq_process_recv_group_im_been_removed
|
|
262
|
|
263 /*****************************************************************************/
|
|
264 // process the packet when added to a group
|
|
265 void qq_process_recv_group_im_been_added
|
|
266 (guint8 * data, guint8 ** cursor, gint len, guint32 internal_group_id, GaimConnection * gc) {
|
|
267 guint32 external_group_id, uid;
|
|
268 guint8 group_type;
|
|
269 qq_group *group;
|
|
270 gchar *msg;
|
|
271
|
|
272 g_return_if_fail(gc != NULL && data != NULL && len > 0);
|
|
273
|
|
274 if (*cursor >= (data + len - 1)) {
|
|
275 gaim_debug(GAIM_DEBUG_WARNING, "QQ", "Received group msg been_added is empty\n");
|
|
276 return;
|
|
277 } // if
|
|
278
|
|
279 read_packet_dw(data, cursor, len, &external_group_id);
|
|
280 read_packet_b(data, cursor, len, &group_type);
|
|
281 read_packet_dw(data, cursor, len, &uid);
|
|
282
|
|
283 g_return_if_fail(external_group_id > 0 && uid > 0);
|
|
284
|
|
285 msg = g_strdup_printf(_("You [%d] has been added by group \"%d\""), uid, external_group_id);
|
|
286 gaim_notify_info(gc, _("QQ Qun Operation"), msg, _("OpenQ has added this group to your buddy list"));
|
|
287
|
|
288 group = qq_group_find_by_internal_group_id(gc, internal_group_id);
|
|
289 if (group != NULL) {
|
|
290 group->my_status = QQ_GROUP_MEMBER_STATUS_IS_MEMBER;
|
|
291 qq_group_refresh(gc, group);
|
|
292 } else { // no such group, try to create a dummy first, and then update
|
|
293 group = qq_group_create_by_id(gc, internal_group_id, external_group_id);
|
|
294 group->my_status = QQ_GROUP_MEMBER_STATUS_IS_MEMBER;
|
|
295 qq_group_refresh(gc, group);
|
|
296 qq_send_cmd_group_get_group_info(gc, group);
|
|
297 // the return of this cmd will automatically update the group in blist
|
|
298 } // if group;
|
|
299
|
|
300 g_free(msg);
|
|
301
|
|
302 } // qq_process_recv_group_im_been_added
|
|
303
|
|
304 /*****************************************************************************/
|
|
305 // recv an IM from a group chat
|
|
306 void qq_process_recv_group_im
|
|
307 (guint8 * data, guint8 ** cursor, gint data_len, guint32 internal_group_id, GaimConnection * gc, guint16 im_type /* gfhuang */)
|
|
308 {
|
|
309 gchar *msg_with_gaim_smiley, *msg_utf8_encoded, *im_src_name;
|
|
310 guint16 unknown;
|
|
311 guint32 unknown4;
|
|
312 GaimConversation *conv;
|
|
313 qq_data *qd;
|
|
314 qq_buddy *member;
|
|
315 qq_group *group;
|
|
316 qq_recv_group_im *im_group;
|
|
317 gint skip_len;
|
|
318
|
|
319 g_return_if_fail(gc != NULL && gc->proto_data != NULL && data != NULL && data_len > 0);
|
|
320 qd = (qq_data *) gc->proto_data;
|
|
321
|
|
322 gaim_debug(GAIM_DEBUG_INFO, "QQ", //by gfhuang
|
|
323 "group im hex dump\n%s\n", hex_dump_to_str(*cursor, data_len - (*cursor - data)));
|
|
324
|
|
325 if (*cursor >= (data + data_len - 1)) {
|
|
326 gaim_debug(GAIM_DEBUG_WARNING, "QQ", "Received group im_group is empty\n");
|
|
327 return;
|
|
328 }
|
|
329
|
|
330 im_group = g_newa(qq_recv_group_im, 1);
|
|
331
|
|
332 read_packet_dw(data, cursor, data_len, &(im_group->external_group_id));
|
|
333 read_packet_b(data, cursor, data_len, &(im_group->group_type));
|
|
334
|
|
335 if(QQ_RECV_IM_TEMP_QUN_IM == im_type) { //by gfhuang, protocal changed
|
|
336 read_packet_dw(data, cursor, data_len, &(internal_group_id));
|
|
337 }
|
|
338
|
|
339 read_packet_dw(data, cursor, data_len, &(im_group->member_uid));
|
|
340 read_packet_w(data, cursor, data_len, &unknown); // 0x0001?
|
|
341 read_packet_w(data, cursor, data_len, &(im_group->msg_seq));
|
|
342 read_packet_dw(data, cursor, data_len, (guint32 *) & (im_group->send_time));
|
|
343 read_packet_dw(data, cursor, data_len, &unknown4); // versionID, gfhuang
|
|
344 // length includes font_attr
|
|
345 // this msg_len includes msg and font_attr
|
|
346 ////////////////// the format is
|
|
347 // length of all
|
|
348 // 1. unknown 10 bytes
|
|
349 // 2. 0-ended string
|
|
350 // 3. font_attr
|
|
351
|
|
352 read_packet_w(data, cursor, data_len, &(im_group->msg_len));
|
|
353 g_return_if_fail(im_group->msg_len > 0);
|
|
354
|
|
355 // 10 bytes from lumaqq
|
|
356 // contentType = buf.getChar();
|
|
357 // totalFragments = buf.get() & 255;
|
|
358 // fragmentSequence = buf.get() & 255;
|
|
359 // messageId = buf.getChar();
|
|
360 // buf.getInt();
|
|
361
|
|
362 if(im_type != QQ_RECV_IM_UNKNOWN_QUN_IM) // gfhuang, protocal changed
|
|
363 skip_len = 10;
|
|
364 else
|
|
365 skip_len = 0;
|
|
366 *cursor += skip_len;
|
|
367
|
|
368 im_group->msg = g_strdup(*cursor);
|
|
369 *cursor += strlen(im_group->msg) + 1;
|
|
370 // there might not be any font_attr, check it
|
|
371 im_group->font_attr_len = im_group->msg_len - strlen(im_group->msg) - 1 - skip_len /* gfhuang */;
|
|
372 if (im_group->font_attr_len > 0)
|
|
373 im_group->font_attr = g_memdup(*cursor, im_group->font_attr_len);
|
|
374 else
|
|
375 im_group->font_attr = NULL;
|
|
376
|
|
377 // group im_group has no flag to indicate whether it has font_attr or not
|
|
378 msg_with_gaim_smiley = qq_smiley_to_gaim(im_group->msg);
|
|
379 if (im_group->font_attr_len > 0)
|
|
380 msg_utf8_encoded = qq_encode_to_gaim(im_group->font_attr,
|
|
381 im_group->font_attr_len, msg_with_gaim_smiley);
|
|
382 else
|
|
383 msg_utf8_encoded = qq_to_utf8(msg_with_gaim_smiley, QQ_CHARSET_DEFAULT);
|
|
384
|
|
385 group = qq_group_find_by_internal_group_id(gc, internal_group_id);
|
|
386 g_return_if_fail(group != NULL);
|
|
387
|
|
388 conv = gaim_find_conversation_with_account(GAIM_CONV_TYPE_CHAT, /*gfhuang*/group->group_name_utf8, gaim_connection_get_account(gc));
|
|
389 if (conv == NULL && gaim_prefs_get_bool("/plugins/prpl/qq/prompt_group_msg_on_recv")) {
|
|
390 serv_got_joined_chat(gc, qd->channel++, group->group_name_utf8);
|
|
391 conv = gaim_find_conversation_with_account(GAIM_CONV_TYPE_CHAT, /*gfhuang*/group->group_name_utf8, gaim_connection_get_account(gc));
|
|
392 } // if conv
|
|
393
|
|
394 if (conv != NULL) {
|
|
395 member = qq_group_find_member_by_uid(group, im_group->member_uid);
|
|
396 if (member == NULL || member->nickname == NULL)
|
|
397 im_src_name = uid_to_gaim_name(im_group->member_uid);
|
|
398 else
|
|
399 im_src_name = g_strdup(member->nickname);
|
|
400 serv_got_chat_in(gc,
|
|
401 gaim_conv_chat_get_id(GAIM_CONV_CHAT
|
|
402 (conv)), im_src_name, 0, msg_utf8_encoded, im_group->send_time);
|
|
403 g_free(im_src_name);
|
|
404 } // if conv
|
|
405 g_free(msg_with_gaim_smiley);
|
|
406 g_free(msg_utf8_encoded);
|
|
407 g_free(im_group->msg);
|
|
408 g_free(im_group->font_attr);
|
|
409 } // _qq_process_recv_group_im
|
|
410
|
|
411
|
|
412 /*****************************************************************************/
|
|
413 // END OF FILE
|