14192
|
1 /**
|
15026
|
2 * @file group_im.c
|
14192
|
3 *
|
15026
|
4 * gaim
|
14192
|
5 *
|
15026
|
6 * Gaim is the legal property of its developers, whose names are too numerous
|
|
7 * to list here. Please refer to the COPYRIGHT file distributed with this
|
|
8 * source distribution.
|
14192
|
9 *
|
|
10 * This program is free software; you can redistribute it and/or modify
|
|
11 * it under the terms of the GNU General Public License as published by
|
|
12 * the Free Software Foundation; either version 2 of the License, or
|
|
13 * (at your option) any later version.
|
|
14 *
|
|
15 * This program is distributed in the hope that it will be useful,
|
|
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
18 * GNU General Public License for more details.
|
|
19 *
|
|
20 * You should have received a copy of the GNU General Public License
|
|
21 * along with this program; if not, write to the Free Software
|
|
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
23 */
|
|
24
|
|
25 #include "conversation.h"
|
|
26 #include "debug.h"
|
|
27 #include "notify.h"
|
|
28 #include "prefs.h"
|
|
29 #include "request.h"
|
|
30 #include "util.h"
|
|
31
|
|
32 #include "char_conv.h"
|
|
33 #include "group_find.h"
|
14404
|
34 #include "group_internal.h"
|
14192
|
35 #include "group_info.h"
|
|
36 #include "group_im.h"
|
|
37 #include "group_network.h"
|
|
38 #include "group_opt.h"
|
|
39 #include "im.h"
|
|
40 #include "packet_parse.h"
|
|
41 #include "utils.h"
|
|
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 gchar *msg;
|
|
51 guint8 *font_attr;
|
|
52 gint font_attr_len;
|
|
53 } qq_recv_group_im;
|
|
54
|
|
55 /* send IM to a group */
|
|
56 void qq_send_packet_group_im(GaimConnection *gc, qq_group *group, const gchar *msg)
|
|
57 {
|
|
58 gint data_len, bytes;
|
|
59 guint8 *raw_data, *cursor, *send_im_tail;
|
|
60 guint16 msg_len;
|
|
61 gchar *msg_filtered;
|
|
62
|
14629
|
63 g_return_if_fail(group != NULL && msg != NULL);
|
14192
|
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, (guint8 *) msg_filtered, msg_len);
|
|
76 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, 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
|
|
90 /* this is the ACK */
|
|
91 void qq_process_group_cmd_im(guint8 *data, guint8 **cursor, gint len, GaimConnection *gc)
|
|
92 {
|
|
93 /* return should be the internal group id
|
|
94 * but we have nothing to do with it */
|
|
95 return;
|
|
96 }
|
|
97
|
|
98 /* receive an application to join the group */
|
|
99 void qq_process_recv_group_im_apply_join
|
|
100 (guint8 *data, guint8 **cursor, gint len, guint32 internal_group_id, GaimConnection *gc)
|
|
101 {
|
|
102 guint32 external_group_id, user_uid;
|
|
103 guint8 group_type;
|
|
104 gchar *reason_utf8, *msg, *reason;
|
|
105 group_member_opt *g;
|
|
106
|
14629
|
107 g_return_if_fail(internal_group_id > 0 && data != NULL && len > 0);
|
14192
|
108
|
|
109 if (*cursor >= (data + len - 1)) {
|
|
110 gaim_debug(GAIM_DEBUG_WARNING, "QQ", "Received group msg apply_join is empty\n");
|
|
111 return;
|
|
112 }
|
|
113
|
|
114 read_packet_dw(data, cursor, len, &external_group_id);
|
|
115 read_packet_b(data, cursor, len, &group_type);
|
|
116 read_packet_dw(data, cursor, len, &user_uid);
|
|
117
|
|
118 g_return_if_fail(external_group_id > 0 && user_uid > 0);
|
|
119
|
|
120 convert_as_pascal_string(*cursor, &reason_utf8, QQ_CHARSET_DEFAULT);
|
|
121
|
|
122 msg = g_strdup_printf(_("User %d applied to join group %d"), user_uid, external_group_id);
|
|
123 reason = g_strdup_printf(_("Reason: %s"), reason_utf8);
|
|
124
|
|
125 g = g_new0(group_member_opt, 1);
|
|
126 g->gc = gc;
|
|
127 g->internal_group_id = internal_group_id;
|
|
128 g->member = user_uid;
|
|
129
|
|
130 gaim_request_action(gc, _("QQ Qun Operation"),
|
|
131 msg, reason,
|
|
132 2, g, 3,
|
|
133 _("Approve"),
|
|
134 G_CALLBACK
|
|
135 (qq_group_approve_application_with_struct),
|
|
136 _("Reject"),
|
|
137 G_CALLBACK
|
|
138 (qq_group_reject_application_with_struct),
|
|
139 _("Search"), G_CALLBACK(qq_group_search_application_with_struct));
|
|
140
|
|
141 g_free(reason);
|
|
142 g_free(msg);
|
|
143 g_free(reason_utf8);
|
|
144 }
|
|
145
|
|
146 /* the request to join a group is rejected */
|
|
147 void qq_process_recv_group_im_been_rejected
|
|
148 (guint8 *data, guint8 **cursor, gint len, guint32 internal_group_id, GaimConnection *gc)
|
|
149 {
|
|
150 guint32 external_group_id, admin_uid;
|
|
151 guint8 group_type;
|
|
152 gchar *reason_utf8, *msg, *reason;
|
|
153 qq_group *group;
|
|
154
|
14629
|
155 g_return_if_fail(data != NULL && len > 0);
|
14192
|
156
|
|
157 if (*cursor >= (data + len - 1)) {
|
|
158 gaim_debug(GAIM_DEBUG_WARNING, "QQ", "Received group msg been_rejected is empty\n");
|
|
159 return;
|
|
160 }
|
|
161
|
|
162 read_packet_dw(data, cursor, len, &external_group_id);
|
|
163 read_packet_b(data, cursor, len, &group_type);
|
|
164 read_packet_dw(data, cursor, len, &admin_uid);
|
|
165
|
|
166 g_return_if_fail(external_group_id > 0 && admin_uid > 0);
|
|
167
|
|
168 convert_as_pascal_string(*cursor, &reason_utf8, QQ_CHARSET_DEFAULT);
|
|
169
|
|
170 msg = g_strdup_printf
|
|
171 (_("You request to join group %d has been rejected by admin %d"), external_group_id, admin_uid);
|
|
172 reason = g_strdup_printf(_("Reason: %s"), reason_utf8);
|
|
173
|
|
174 gaim_notify_warning(gc, _("QQ Qun Operation"), msg, reason);
|
|
175
|
14404
|
176 group = qq_group_find_by_id(gc, internal_group_id, QQ_INTERNAL_ID);
|
14192
|
177 if (group != NULL) {
|
|
178 group->my_status = QQ_GROUP_MEMBER_STATUS_NOT_MEMBER;
|
|
179 qq_group_refresh(gc, group);
|
|
180 }
|
|
181
|
|
182 g_free(reason);
|
|
183 g_free(msg);
|
|
184 g_free(reason_utf8);
|
|
185 }
|
|
186
|
|
187 /* the request to join a group is approved */
|
|
188 void qq_process_recv_group_im_been_approved
|
|
189 (guint8 *data, guint8 **cursor, gint len, guint32 internal_group_id, GaimConnection *gc)
|
|
190 {
|
|
191 guint32 external_group_id, admin_uid;
|
|
192 guint8 group_type;
|
|
193 gchar *reason_utf8, *msg;
|
|
194 qq_group *group;
|
|
195
|
14629
|
196 g_return_if_fail(data != NULL && len > 0);
|
14192
|
197
|
|
198 if (*cursor >= (data + len - 1)) {
|
|
199 gaim_debug(GAIM_DEBUG_WARNING, "QQ", "Received group msg been_approved is empty\n");
|
|
200 return;
|
|
201 }
|
|
202
|
|
203 read_packet_dw(data, cursor, len, &external_group_id);
|
|
204 read_packet_b(data, cursor, len, &group_type);
|
|
205 read_packet_dw(data, cursor, len, &admin_uid);
|
|
206
|
|
207 g_return_if_fail(external_group_id > 0 && admin_uid > 0);
|
|
208 /* it is also a "æ— " here, so do not display */
|
|
209 convert_as_pascal_string(*cursor, &reason_utf8, QQ_CHARSET_DEFAULT);
|
|
210
|
|
211 msg = g_strdup_printf
|
|
212 (_("You request to join group %d has been approved by admin %d"), external_group_id, admin_uid);
|
|
213
|
|
214 gaim_notify_warning(gc, _("QQ Qun Operation"), msg, NULL);
|
|
215
|
14404
|
216 group = qq_group_find_by_id(gc, internal_group_id, QQ_INTERNAL_ID);
|
14192
|
217 if (group != NULL) {
|
|
218 group->my_status = QQ_GROUP_MEMBER_STATUS_IS_MEMBER;
|
|
219 qq_group_refresh(gc, group);
|
|
220 }
|
|
221
|
|
222 g_free(msg);
|
|
223 g_free(reason_utf8);
|
|
224 }
|
|
225
|
|
226 /* process the packet when removed from a group */
|
|
227 void qq_process_recv_group_im_been_removed
|
|
228 (guint8 *data, guint8 **cursor, gint len, guint32 internal_group_id, GaimConnection *gc)
|
|
229 {
|
|
230 guint32 external_group_id, uid;
|
|
231 guint8 group_type;
|
|
232 gchar *msg;
|
|
233 qq_group *group;
|
|
234
|
14629
|
235 g_return_if_fail(data != NULL && len > 0);
|
14192
|
236
|
|
237 if (*cursor >= (data + len - 1)) {
|
|
238 gaim_debug(GAIM_DEBUG_WARNING, "QQ", "Received group msg been_removed is empty\n");
|
|
239 return;
|
|
240 }
|
|
241
|
|
242 read_packet_dw(data, cursor, len, &external_group_id);
|
|
243 read_packet_b(data, cursor, len, &group_type);
|
|
244 read_packet_dw(data, cursor, len, &uid);
|
|
245
|
|
246 g_return_if_fail(external_group_id > 0 && uid > 0);
|
|
247
|
|
248 msg = g_strdup_printf(_("You [%d] has exit group \"%d\""), uid, external_group_id);
|
|
249 gaim_notify_info(gc, _("QQ Qun Operation"), msg, NULL);
|
|
250
|
14404
|
251 group = qq_group_find_by_id(gc, internal_group_id, QQ_INTERNAL_ID);
|
14192
|
252 if (group != NULL) {
|
|
253 group->my_status = QQ_GROUP_MEMBER_STATUS_NOT_MEMBER;
|
|
254 qq_group_refresh(gc, group);
|
|
255 }
|
|
256
|
|
257 g_free(msg);
|
|
258 }
|
|
259
|
|
260 /* process the packet when added to a group */
|
|
261 void qq_process_recv_group_im_been_added
|
|
262 (guint8 *data, guint8 **cursor, gint len, guint32 internal_group_id, GaimConnection *gc)
|
|
263 {
|
|
264 guint32 external_group_id, uid;
|
|
265 guint8 group_type;
|
|
266 qq_group *group;
|
|
267 gchar *msg;
|
|
268
|
14629
|
269 g_return_if_fail(data != NULL && len > 0);
|
14192
|
270
|
|
271 if (*cursor >= (data + len - 1)) {
|
|
272 gaim_debug(GAIM_DEBUG_WARNING, "QQ", "Received group msg been_added is empty\n");
|
|
273 return;
|
|
274 }
|
|
275
|
|
276 read_packet_dw(data, cursor, len, &external_group_id);
|
|
277 read_packet_b(data, cursor, len, &group_type);
|
|
278 read_packet_dw(data, cursor, len, &uid);
|
|
279
|
|
280 g_return_if_fail(external_group_id > 0 && uid > 0);
|
|
281
|
|
282 msg = g_strdup_printf(_("You [%d] has been added by group \"%d\""), uid, external_group_id);
|
14404
|
283 gaim_notify_info(gc, _("QQ Qun Operation"), msg, _("This group has been added to your buddy list"));
|
14192
|
284
|
14404
|
285 group = qq_group_find_by_id(gc, internal_group_id, QQ_INTERNAL_ID);
|
14192
|
286 if (group != NULL) {
|
|
287 group->my_status = QQ_GROUP_MEMBER_STATUS_IS_MEMBER;
|
|
288 qq_group_refresh(gc, group);
|
|
289 } else { /* no such group, try to create a dummy first, and then update */
|
14404
|
290 group = qq_group_create_internal_record(gc, internal_group_id, external_group_id, NULL);
|
14192
|
291 group->my_status = QQ_GROUP_MEMBER_STATUS_IS_MEMBER;
|
|
292 qq_group_refresh(gc, group);
|
|
293 qq_send_cmd_group_get_group_info(gc, group);
|
|
294 /* the return of this cmd will automatically update the group in blist */
|
|
295 }
|
|
296
|
|
297 g_free(msg);
|
|
298 }
|
|
299
|
|
300 /* recv an IM from a group chat */
|
|
301 void qq_process_recv_group_im(guint8 *data, guint8 **cursor, gint data_len,
|
|
302 guint32 internal_group_id, GaimConnection *gc, guint16 im_type)
|
|
303 {
|
14656
|
304 gchar *msg_with_gaim_smiley, *msg_utf8_encoded, *im_src_name, *hex_dump;
|
14192
|
305 guint16 unknown;
|
|
306 guint32 unknown4;
|
|
307 GaimConversation *conv;
|
|
308 qq_data *qd;
|
|
309 qq_buddy *member;
|
|
310 qq_group *group;
|
|
311 qq_recv_group_im *im_group;
|
|
312 gint skip_len;
|
|
313
|
14629
|
314 g_return_if_fail(data != NULL && data_len > 0);
|
14192
|
315 qd = (qq_data *) gc->proto_data;
|
|
316
|
14656
|
317 hex_dump = hex_dump_to_str(*cursor, data_len - (*cursor - data));
|
|
318 gaim_debug(GAIM_DEBUG_INFO, "QQ", "group im hex dump\n%s\n", hex_dump);
|
14192
|
319
|
|
320 if (*cursor >= (data + data_len - 1)) {
|
|
321 gaim_debug(GAIM_DEBUG_WARNING, "QQ", "Received group im_group is empty\n");
|
|
322 return;
|
|
323 }
|
|
324
|
|
325 im_group = g_newa(qq_recv_group_im, 1);
|
|
326
|
|
327 read_packet_dw(data, cursor, data_len, &(im_group->external_group_id));
|
|
328 read_packet_b(data, cursor, data_len, &(im_group->group_type));
|
|
329
|
|
330 if(QQ_RECV_IM_TEMP_QUN_IM == im_type) {
|
|
331 read_packet_dw(data, cursor, data_len, &(internal_group_id));
|
|
332 }
|
|
333
|
|
334 read_packet_dw(data, cursor, data_len, &(im_group->member_uid));
|
|
335 read_packet_w(data, cursor, data_len, &unknown); /* 0x0001? */
|
|
336 read_packet_w(data, cursor, data_len, &(im_group->msg_seq));
|
|
337 read_packet_dw(data, cursor, data_len, (guint32 *) & (im_group->send_time));
|
|
338 read_packet_dw(data, cursor, data_len, &unknown4); /* versionID */
|
|
339 /*
|
|
340 * length includes font_attr
|
|
341 * this msg_len includes msg and font_attr
|
|
342 **** the format is ****
|
|
343 * length of all
|
|
344 * 1. unknown 10 bytes
|
|
345 * 2. 0-ended string
|
|
346 * 3. font_attr
|
|
347 */
|
|
348
|
|
349 read_packet_w(data, cursor, data_len, &(im_group->msg_len));
|
|
350 g_return_if_fail(im_group->msg_len > 0);
|
|
351
|
|
352 /*
|
|
353 * 10 bytes from lumaqq
|
|
354 * contentType = buf.getChar();
|
|
355 * totalFragments = buf.get() & 255;
|
|
356 * fragmentSequence = buf.get() & 255;
|
|
357 * messageId = buf.getChar();
|
|
358 * buf.getInt();
|
|
359 */
|
|
360
|
|
361 if(im_type != QQ_RECV_IM_UNKNOWN_QUN_IM)
|
|
362 skip_len = 10;
|
|
363 else
|
|
364 skip_len = 0;
|
|
365 *cursor += skip_len;
|
|
366
|
|
367 im_group->msg = g_strdup((gchar *) *cursor);
|
|
368 *cursor += strlen(im_group->msg) + 1;
|
|
369 /* there might not be any font_attr, check it */
|
|
370 im_group->font_attr_len = im_group->msg_len - strlen(im_group->msg) - 1 - skip_len;
|
|
371 if (im_group->font_attr_len > 0)
|
|
372 im_group->font_attr = g_memdup(*cursor, im_group->font_attr_len);
|
|
373 else
|
|
374 im_group->font_attr = NULL;
|
|
375
|
|
376 /* group im_group has no flag to indicate whether it has font_attr or not */
|
|
377 msg_with_gaim_smiley = qq_smiley_to_gaim(im_group->msg);
|
|
378 if (im_group->font_attr_len > 0)
|
|
379 msg_utf8_encoded = qq_encode_to_gaim(im_group->font_attr,
|
|
380 im_group->font_attr_len, msg_with_gaim_smiley);
|
|
381 else
|
|
382 msg_utf8_encoded = qq_to_utf8(msg_with_gaim_smiley, QQ_CHARSET_DEFAULT);
|
|
383
|
14404
|
384 group = qq_group_find_by_id(gc, internal_group_id, QQ_INTERNAL_ID);
|
14192
|
385 g_return_if_fail(group != NULL);
|
|
386
|
|
387 conv = gaim_find_conversation_with_account(GAIM_CONV_TYPE_CHAT, group->group_name_utf8, gaim_connection_get_account(gc));
|
|
388 if (conv == NULL && gaim_prefs_get_bool("/plugins/prpl/qq/prompt_group_msg_on_recv")) {
|
|
389 serv_got_joined_chat(gc, qd->channel++, group->group_name_utf8);
|
|
390 conv = gaim_find_conversation_with_account(GAIM_CONV_TYPE_CHAT, group->group_name_utf8, gaim_connection_get_account(gc));
|
|
391 }
|
|
392
|
|
393 if (conv != NULL) {
|
|
394 member = qq_group_find_member_by_uid(group, im_group->member_uid);
|
|
395 if (member == NULL || member->nickname == NULL)
|
|
396 im_src_name = uid_to_gaim_name(im_group->member_uid);
|
|
397 else
|
|
398 im_src_name = g_strdup(member->nickname);
|
|
399 serv_got_chat_in(gc,
|
|
400 gaim_conv_chat_get_id(GAIM_CONV_CHAT
|
|
401 (conv)), im_src_name, 0, msg_utf8_encoded, im_group->send_time);
|
|
402 g_free(im_src_name);
|
|
403 }
|
14656
|
404 g_free(hex_dump);
|
14192
|
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 }
|