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 "debug.h"
|
|
24 #include "internal.h"
|
|
25 #include "notify.h"
|
|
26 #include "request.h"
|
|
27
|
|
28 #include "buddy_info.h"
|
|
29 #include "buddy_list.h"
|
|
30 #include "buddy_opt.h"
|
|
31 #include "char_conv.h"
|
|
32 #include "crypt.h"
|
|
33 #include "header_info.h"
|
|
34 #include "im.h"
|
|
35 #include "keep_alive.h"
|
|
36 #include "packet_parse.h"
|
|
37 #include "send_core.h"
|
|
38 #include "utils.h"
|
|
39
|
|
40 #define GAIM_GROUP_QQ_FORMAT "QQ (%s)"
|
|
41 #define GAIM_GROUP_QQ_UNKNOWN "QQ Unknown"
|
|
42 #define GAIM_GROUP_QQ_BLOCKED "QQ Blocked"
|
|
43
|
|
44 #define QQ_REMOVE_BUDDY_REPLY_OK 0x00
|
|
45 #define QQ_REMOVE_SELF_REPLY_OK 0x00
|
|
46 #define QQ_ADD_BUDDY_AUTH_REPLY_OK 0x30 /* ASCII value of "0" */
|
|
47
|
|
48 enum {
|
|
49 QQ_MY_AUTH_APPROVE = 0x30, /* ASCII value of "0" */
|
|
50 QQ_MY_AUTH_REJECT = 0x31, /* ASCII value of "1" */
|
|
51 QQ_MY_AUTH_REQUEST = 0x32, /* ASCII value of "2" */
|
|
52 };
|
|
53
|
|
54 typedef struct _qq_add_buddy_request {
|
|
55 guint32 uid;
|
|
56 guint16 seq;
|
|
57 } qq_add_buddy_request;
|
|
58
|
|
59 /* send packet to remove a buddy from my buddy list */
|
|
60 static void _qq_send_packet_remove_buddy(GaimConnection *gc, guint32 uid)
|
|
61 {
|
14519
|
62 gchar uid_str[11];
|
14192
|
63
|
|
64 g_return_if_fail(gc != NULL && uid > 0);
|
|
65
|
14519
|
66 g_snprintf(uid_str, sizeof(uid_str), "%d", uid);
|
14192
|
67 qq_send_cmd(gc, QQ_CMD_DEL_FRIEND, TRUE, 0,
|
|
68 TRUE, (guint8 *) uid_str, strlen(uid_str));
|
|
69 }
|
|
70
|
|
71 /* try to remove myself from someone's buddy list */
|
|
72 static void _qq_send_packet_remove_self_from(GaimConnection *gc, guint32 uid)
|
|
73 {
|
|
74 guint8 *raw_data, *cursor;
|
|
75
|
|
76 g_return_if_fail(gc != NULL && gc->proto_data != NULL && uid > 0);
|
|
77
|
|
78 raw_data = g_newa(guint8, 4);
|
|
79 cursor = raw_data;
|
|
80 create_packet_dw(raw_data, &cursor, uid);
|
|
81
|
|
82 qq_send_cmd(gc, QQ_CMD_REMOVE_SELF, TRUE, 0, TRUE, raw_data, 4);
|
|
83 }
|
|
84
|
|
85 /* try to add a buddy without authentication */
|
|
86 static void _qq_send_packet_add_buddy(GaimConnection *gc, guint32 uid)
|
|
87 {
|
|
88 qq_data *qd;
|
|
89 qq_add_buddy_request *req;
|
14519
|
90 gchar uid_str[11];
|
14192
|
91
|
|
92 g_return_if_fail(gc != NULL && gc->proto_data != NULL && uid > 0);
|
|
93
|
|
94 /* we need to send the ascii code of this uid to qq server */
|
14519
|
95 g_snprintf(uid_str, sizeof(uid_str), "%d", uid);
|
14192
|
96 qq_send_cmd(gc, QQ_CMD_ADD_FRIEND_WO_AUTH, TRUE, 0,
|
|
97 TRUE, (guint8 *) uid_str, strlen(uid_str));
|
|
98
|
|
99 /* must be set after sending packet to get the correct send_seq */
|
|
100 qd = (qq_data *) gc->proto_data;
|
|
101 req = g_new0(qq_add_buddy_request, 1);
|
|
102 req->seq = qd->send_seq;
|
|
103 req->uid = uid;
|
|
104 qd->add_buddy_request = g_list_append(qd->add_buddy_request, req);
|
|
105 }
|
|
106
|
|
107 /* this buddy needs authentication, text conversion is done at lowest level */
|
|
108 static void _qq_send_packet_buddy_auth(GaimConnection *gc, guint32 uid, const gchar response, const gchar *text)
|
|
109 {
|
14519
|
110 gchar *text_qq, uid_str[11];
|
14192
|
111 guint8 bar, *cursor, *raw_data;
|
|
112
|
|
113 g_return_if_fail(gc != NULL && uid != 0);
|
|
114
|
14519
|
115 g_snprintf(uid_str, sizeof(uid_str), "%d", uid);
|
14192
|
116 bar = 0x1f;
|
|
117 raw_data = g_newa(guint8, QQ_MSG_IM_MAX);
|
|
118 cursor = raw_data;
|
|
119
|
|
120 create_packet_data(raw_data, &cursor, (guint8 *) uid_str, strlen(uid_str));
|
|
121 create_packet_b(raw_data, &cursor, bar);
|
|
122 create_packet_b(raw_data, &cursor, response);
|
|
123
|
|
124 if (text != NULL) {
|
|
125 text_qq = utf8_to_qq(text, QQ_CHARSET_DEFAULT);
|
|
126 create_packet_b(raw_data, &cursor, bar);
|
|
127 create_packet_data(raw_data, &cursor, (guint8 *) text_qq, strlen(text_qq));
|
|
128 g_free(text_qq);
|
|
129 }
|
|
130
|
|
131 qq_send_cmd(gc, QQ_CMD_BUDDY_AUTH, TRUE, 0, TRUE, raw_data, cursor - raw_data);
|
|
132 }
|
|
133
|
|
134 static void _qq_send_packet_add_buddy_auth_with_gc_and_uid(gc_and_uid *g, const gchar *text)
|
|
135 {
|
|
136 GaimConnection *gc;
|
|
137 guint32 uid;
|
|
138 g_return_if_fail(g != NULL);
|
|
139
|
|
140 gc = g->gc;
|
|
141 uid = g->uid;
|
|
142 g_return_if_fail(gc != NULL && uid != 0);
|
|
143
|
|
144 _qq_send_packet_buddy_auth(gc, uid, QQ_MY_AUTH_REQUEST, text);
|
|
145 g_free(g);
|
|
146 }
|
|
147
|
|
148 /* the real packet to reject and request is sent from here */
|
|
149 static void _qq_reject_add_request_real(gc_and_uid *g, const gchar *reason)
|
|
150 {
|
|
151 gint uid;
|
|
152 GaimConnection *gc;
|
|
153
|
|
154 g_return_if_fail(g != NULL);
|
|
155
|
|
156 gc = g->gc;
|
|
157 uid = g->uid;
|
|
158 g_return_if_fail(gc != NULL && uid != 0);
|
|
159
|
|
160 _qq_send_packet_buddy_auth(gc, uid, QQ_MY_AUTH_REJECT, reason);
|
|
161 g_free(g);
|
|
162 }
|
|
163
|
|
164 /* we approve other's request of adding me as friend */
|
|
165 void qq_approve_add_request_with_gc_and_uid(gc_and_uid *g)
|
|
166 {
|
|
167 gint uid;
|
|
168 GaimConnection *gc;
|
|
169
|
|
170 g_return_if_fail(g != NULL);
|
|
171
|
|
172 gc = g->gc;
|
|
173 uid = g->uid;
|
|
174 g_return_if_fail(gc != NULL && uid != 0);
|
|
175
|
|
176 _qq_send_packet_buddy_auth(gc, uid, QQ_MY_AUTH_APPROVE, NULL);
|
|
177 g_free(g);
|
|
178 }
|
|
179
|
|
180 void qq_do_nothing_with_gc_and_uid(gc_and_uid *g, const gchar *msg)
|
|
181 {
|
|
182 g_free(g);
|
|
183 }
|
|
184
|
|
185 /* we reject other's request of adding me as friend */
|
|
186 void qq_reject_add_request_with_gc_and_uid(gc_and_uid *g)
|
|
187 {
|
|
188 gint uid;
|
|
189 gchar *msg1, *msg2;
|
|
190 GaimConnection *gc;
|
|
191 gc_and_uid *g2;
|
|
192
|
|
193 g_return_if_fail(g != NULL);
|
|
194
|
|
195 gc = g->gc;
|
|
196 uid = g->uid;
|
|
197 g_return_if_fail(gc != NULL && uid != 0);
|
|
198
|
|
199 g_free(g);
|
|
200
|
|
201 g2 = g_new0(gc_and_uid, 1);
|
|
202 g2->gc = gc;
|
|
203 g2->uid = uid;
|
|
204
|
|
205 msg1 = g_strdup_printf(_("You rejected %d's request"), uid);
|
|
206 msg2 = g_strdup(_("Input your reason:"));
|
|
207
|
|
208 gaim_request_input(gc, _("Reject request"), msg1, msg2,
|
|
209 _("Sorry, you are not my type..."), TRUE, FALSE,
|
|
210 NULL, _("Reject"), G_CALLBACK(_qq_reject_add_request_real), _("Cancel"), NULL, g2);
|
|
211 }
|
|
212
|
|
213 void qq_add_buddy_with_gc_and_uid(gc_and_uid *g)
|
|
214 {
|
|
215 gint uid;
|
|
216 GaimConnection *gc;
|
|
217
|
|
218 g_return_if_fail(g != NULL);
|
|
219
|
|
220 gc = g->gc;
|
|
221 uid = g->uid;
|
|
222 g_return_if_fail(gc != NULL && uid != 0);
|
|
223
|
|
224 _qq_send_packet_add_buddy(gc, uid);
|
|
225 g_free(g);
|
|
226 }
|
|
227
|
|
228 void qq_block_buddy_with_gc_and_uid(gc_and_uid *g)
|
|
229 {
|
|
230 guint32 uid;
|
|
231 GaimConnection *gc;
|
|
232 GaimBuddy buddy;
|
|
233 GaimGroup group;
|
|
234
|
|
235 g_return_if_fail(g != NULL);
|
|
236
|
|
237 gc = g->gc;
|
|
238 uid = g->uid;
|
|
239 g_return_if_fail(gc != NULL && uid > 0);
|
|
240
|
|
241 buddy.name = uid_to_gaim_name(uid);
|
|
242 group.name = GAIM_GROUP_QQ_BLOCKED;
|
|
243
|
|
244 qq_remove_buddy(gc, &buddy, &group);
|
|
245 _qq_send_packet_remove_self_from(gc, uid);
|
|
246 }
|
|
247
|
|
248 /* process reply to add_buddy_auth request */
|
|
249 void qq_process_add_buddy_auth_reply(guint8 *buf, gint buf_len, GaimConnection *gc)
|
|
250 {
|
|
251 qq_data *qd;
|
|
252 gint len;
|
|
253 guint8 *data, *cursor, reply;
|
|
254 gchar **segments, *msg_utf8;
|
|
255
|
|
256 g_return_if_fail(gc != NULL && gc->proto_data != NULL);
|
|
257 g_return_if_fail(buf != NULL && buf_len != 0);
|
|
258
|
|
259 qd = (qq_data *) gc->proto_data;
|
|
260 len = buf_len;
|
|
261 data = g_newa(guint8, len);
|
|
262 cursor = data;
|
|
263
|
|
264 if (qq_crypt(DECRYPT, buf, buf_len, qd->session_key, data, &len)) {
|
|
265 read_packet_b(data, &cursor, len, &reply);
|
|
266 if (reply != QQ_ADD_BUDDY_AUTH_REPLY_OK) {
|
|
267 gaim_debug(GAIM_DEBUG_WARNING, "QQ", "Add buddy with auth request fails\n");
|
|
268 if (NULL == (segments = split_data(data, len, "\x1f", 2)))
|
|
269 return;
|
|
270 msg_utf8 = qq_to_utf8(segments[1], QQ_CHARSET_DEFAULT);
|
|
271 gaim_notify_error(gc, NULL, _("Add buddy with auth request fails"), msg_utf8);
|
|
272 g_free(msg_utf8);
|
|
273 } else {
|
|
274 gaim_debug(GAIM_DEBUG_INFO, "QQ", "Add buddy with auth request OK\n");
|
|
275 }
|
|
276 } else {
|
|
277 gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Error decrypt add buddy with auth reply\n");
|
|
278 }
|
|
279 }
|
|
280
|
|
281 /* process the server reply for my request to remove a buddy */
|
|
282 void qq_process_remove_buddy_reply(guint8 *buf, gint buf_len, GaimConnection *gc)
|
|
283 {
|
|
284 qq_data *qd;
|
|
285 gint len;
|
|
286 guint8 *data, *cursor, reply;
|
|
287
|
|
288 g_return_if_fail(gc != NULL && gc->proto_data != NULL);
|
|
289 g_return_if_fail(buf != NULL && buf_len != 0);
|
|
290
|
|
291 qd = (qq_data *) gc->proto_data;
|
|
292 len = buf_len;
|
|
293 data = g_newa(guint8, len);
|
|
294
|
|
295 if (qq_crypt(DECRYPT, buf, buf_len, qd->session_key, data, &len)) {
|
|
296 cursor = data;
|
|
297 read_packet_b(data, &cursor, len, &reply);
|
|
298 if (reply != QQ_REMOVE_BUDDY_REPLY_OK) {
|
|
299 /* there is no reason return from server */
|
|
300 gaim_debug(GAIM_DEBUG_WARNING, "QQ", "Remove buddy fails\n");
|
|
301 } else { /* if reply */
|
|
302 gaim_debug(GAIM_DEBUG_INFO, "QQ", "Remove buddy OK\n");
|
|
303 gaim_notify_info(gc, NULL, _("You have successfully removed a buddy"), NULL);
|
|
304 }
|
|
305 } else {
|
|
306 gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Error decrypt remove buddy reply\n");
|
|
307 }
|
|
308 }
|
|
309
|
|
310 /* process the server reply for my request to remove myself from a buddy */
|
|
311 void qq_process_remove_self_reply(guint8 *buf, gint buf_len, GaimConnection *gc)
|
|
312 {
|
|
313 qq_data *qd;
|
|
314 gint len;
|
|
315 guint8 *data, *cursor, reply;
|
|
316
|
|
317 g_return_if_fail(gc != NULL && gc->proto_data != NULL);
|
|
318 g_return_if_fail(buf != NULL && buf_len != 0);
|
|
319
|
|
320 qd = (qq_data *) gc->proto_data;
|
|
321 len = buf_len;
|
|
322 data = g_newa(guint8, len);
|
|
323
|
|
324 if (qq_crypt(DECRYPT, buf, buf_len, qd->session_key, data, &len)) {
|
|
325 cursor = data;
|
|
326 read_packet_b(data, &cursor, len, &reply);
|
|
327 if (reply != QQ_REMOVE_SELF_REPLY_OK)
|
|
328 /* there is no reason return from server */
|
|
329 gaim_debug(GAIM_DEBUG_WARNING, "QQ", "Remove self fails\n");
|
|
330 else { /* if reply */
|
|
331 gaim_debug(GAIM_DEBUG_INFO, "QQ", "Remove self from a buddy OK\n");
|
|
332 gaim_notify_info(gc, NULL, _("You have successfully removed yourself from a buddy"), NULL);
|
|
333 }
|
|
334 } else {
|
|
335 gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Error decrypt remove self reply\n");
|
|
336 }
|
|
337 }
|
|
338
|
|
339 void qq_process_add_buddy_reply(guint8 *buf, gint buf_len, guint16 seq, GaimConnection *gc)
|
|
340 {
|
|
341 qq_data *qd;
|
|
342 gint len, for_uid;
|
|
343 gchar *msg, **segments, *uid, *reply;
|
|
344 guint8 *data;
|
|
345 GList *list;
|
|
346 GaimBuddy *b;
|
|
347 gc_and_uid *g;
|
|
348 qq_add_buddy_request *req;
|
|
349
|
|
350 g_return_if_fail(gc != NULL && gc->proto_data != NULL);
|
|
351 g_return_if_fail(buf != NULL && buf_len != 0);
|
|
352
|
|
353 for_uid = 0;
|
|
354 qd = (qq_data *) gc->proto_data;
|
|
355 len = buf_len;
|
|
356
|
|
357 list = qd->add_buddy_request;
|
|
358 while (list != NULL) {
|
|
359 req = (qq_add_buddy_request *) list->data;
|
|
360 if (req->seq == seq) { /* reply to this */
|
|
361 for_uid = req->uid;
|
|
362 qd->add_buddy_request = g_list_remove(qd->add_buddy_request, qd->add_buddy_request->data);
|
|
363 g_free(req);
|
|
364 break;
|
|
365 }
|
|
366 list = list->next;
|
|
367 }
|
|
368
|
|
369 if (for_uid == 0) { /* we have no record for this */
|
|
370 gaim_debug(GAIM_DEBUG_ERROR, "QQ", "We have no record for add buddy reply [%d], discard\n", seq);
|
|
371 return;
|
|
372 } else {
|
|
373 gaim_debug(GAIM_DEBUG_INFO, "QQ", "Add buddy reply [%d] is for id [%d]\n", seq, for_uid);
|
|
374 }
|
|
375
|
|
376 data = g_newa(guint8, len);
|
|
377
|
|
378 if (qq_crypt(DECRYPT, buf, buf_len, qd->session_key, data, &len)) {
|
|
379 if (NULL == (segments = split_data(data, len, "\x1f", 2)))
|
|
380 return;
|
|
381 uid = segments[0];
|
|
382 reply = segments[1];
|
|
383 if (strtol(uid, NULL, 10) != qd->uid) { /* should not happen */
|
|
384 gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Add buddy reply is to [%s], not me!", uid);
|
|
385 g_strfreev(segments);
|
|
386 return;
|
|
387 }
|
|
388
|
|
389 if (strtol(reply, NULL, 10) > 0) { /* need auth */
|
|
390 gaim_debug(GAIM_DEBUG_WARNING, "QQ", "Add buddy attempt fails, need authentication\n");
|
|
391 b = gaim_find_buddy(gc->account, uid_to_gaim_name(for_uid));
|
|
392 if (b != NULL)
|
|
393 gaim_blist_remove_buddy(b);
|
|
394 g = g_new0(gc_and_uid, 1);
|
|
395 g->gc = gc;
|
|
396 g->uid = for_uid;
|
|
397 msg = g_strdup_printf(_("User %d needs authentication"), for_uid);
|
|
398 gaim_request_input(gc, NULL, msg,
|
|
399 _("Input request here"),
|
|
400 _("Would you be my friend?"),
|
|
401 TRUE, FALSE, NULL, _("Send"),
|
|
402 G_CALLBACK
|
|
403 (_qq_send_packet_add_buddy_auth_with_gc_and_uid),
|
|
404 _("Cancel"), G_CALLBACK(qq_do_nothing_with_gc_and_uid), g);
|
|
405 g_free(msg);
|
|
406 } else { /* add OK */
|
|
407 qq_add_buddy_by_recv_packet(gc, for_uid, TRUE, TRUE);
|
|
408 msg = g_strdup_printf(_("You have added %d in buddy list"), for_uid);
|
|
409 gaim_notify_info(gc, NULL, msg, NULL);
|
|
410 g_free(msg);
|
|
411 }
|
|
412 g_strfreev(segments);
|
|
413 } else {
|
|
414 gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Error decrypt add buddy reply\n");
|
|
415 }
|
|
416 }
|
|
417
|
|
418 GaimGroup *qq_get_gaim_group(const gchar *group_name)
|
|
419 {
|
|
420 GaimGroup *g;
|
|
421
|
|
422 g_return_val_if_fail(group_name != NULL, NULL);
|
|
423
|
|
424 g = gaim_find_group(group_name);
|
|
425 if (g == NULL) {
|
|
426 g = gaim_group_new(group_name);
|
|
427 gaim_blist_add_group(g, NULL);
|
|
428 gaim_debug(GAIM_DEBUG_WARNING, "QQ", "Add new group: %s\n", group_name);
|
|
429 }
|
|
430
|
|
431 return g;
|
|
432 }
|
|
433
|
|
434 /* we add new buddy, if the received packet is from someone not in my list
|
|
435 * return the GaimBuddy that is just created */
|
|
436 GaimBuddy *qq_add_buddy_by_recv_packet(GaimConnection *gc, guint32 uid, gboolean is_known, gboolean create)
|
|
437 {
|
|
438 GaimAccount *a;
|
|
439 GaimBuddy *b;
|
|
440 GaimGroup *g;
|
|
441 qq_data *qd;
|
|
442 qq_buddy *q_bud;
|
|
443 gchar *name, *group_name;
|
|
444
|
|
445 g_return_val_if_fail(gc != NULL && gc->proto_data != NULL, NULL);
|
|
446
|
|
447 a = gc->account;
|
|
448 qd = (qq_data *) gc->proto_data;
|
|
449 g_return_val_if_fail(a != NULL && uid != 0, NULL);
|
|
450
|
|
451 group_name = is_known ?
|
|
452 g_strdup_printf(GAIM_GROUP_QQ_FORMAT, gaim_account_get_username(a)) : g_strdup(GAIM_GROUP_QQ_UNKNOWN);
|
|
453
|
|
454 g = qq_get_gaim_group(group_name);
|
|
455
|
|
456 name = uid_to_gaim_name(uid);
|
|
457 b = gaim_find_buddy(gc->account, name);
|
|
458 /* remove old, we can not simply return here
|
|
459 * because there might be old local copy of this buddy */
|
|
460 if (b != NULL)
|
|
461 gaim_blist_remove_buddy(b);
|
|
462
|
|
463 b = gaim_buddy_new(a, name, NULL);
|
|
464
|
|
465 if (!create)
|
|
466 b->proto_data = NULL;
|
|
467 else {
|
|
468 q_bud = g_new0(qq_buddy, 1);
|
|
469 q_bud->uid = uid;
|
|
470 b->proto_data = q_bud;
|
|
471 qd->buddies = g_list_append(qd->buddies, q_bud);
|
|
472 qq_send_packet_get_info(gc, q_bud->uid, FALSE);
|
|
473 qq_send_packet_get_buddies_online(gc, QQ_FRIENDS_ONLINE_POSITION_START);
|
|
474 }
|
|
475
|
|
476 gaim_blist_add_buddy(b, NULL, g, NULL);
|
|
477 gaim_debug(GAIM_DEBUG_WARNING, "QQ", "Add new buddy: [%s]\n", name);
|
|
478
|
|
479 g_free(name);
|
|
480 g_free(group_name);
|
|
481
|
|
482 return b;
|
|
483 }
|
|
484
|
|
485 /* add a buddy and send packet to QQ server
|
|
486 * note that when gaim load local cached buddy list into its blist
|
|
487 * it also calls this funtion, so we have to
|
|
488 * define qd->logged_in=TRUE AFTER serv_finish_login(gc) */
|
|
489 void qq_add_buddy(GaimConnection *gc, GaimBuddy *buddy, GaimGroup *group)
|
|
490 {
|
|
491 qq_data *qd;
|
|
492 guint32 uid;
|
|
493 GaimBuddy *b;
|
|
494
|
|
495 g_return_if_fail(gc != NULL && gc->proto_data != NULL);
|
|
496
|
|
497 qd = (qq_data *) gc->proto_data;
|
|
498 if (!qd->logged_in)
|
|
499 return; /* IMPORTANT ! */
|
|
500
|
|
501 uid = gaim_name_to_uid(buddy->name);
|
|
502 if (uid > 0)
|
|
503 _qq_send_packet_add_buddy(gc, uid);
|
|
504 else {
|
|
505 b = gaim_find_buddy(gc->account, buddy->name);
|
|
506 if (b != NULL)
|
|
507 gaim_blist_remove_buddy(b);
|
|
508 gaim_notify_error(gc, NULL,
|
|
509 _("QQid Error"),
|
14319
|
510 _("Invalid QQid"));
|
14192
|
511 }
|
|
512 }
|
|
513
|
|
514 /* remove a buddy and send packet to QQ server accordingly */
|
|
515 void qq_remove_buddy(GaimConnection *gc, GaimBuddy *buddy, GaimGroup *group)
|
|
516 {
|
|
517 qq_data *qd;
|
|
518 GaimBuddy *b;
|
|
519 qq_buddy *q_bud;
|
|
520 guint32 uid;
|
|
521
|
|
522 g_return_if_fail(gc != NULL && gc->proto_data != NULL);
|
|
523
|
|
524 qd = (qq_data *) gc->proto_data;
|
|
525 uid = gaim_name_to_uid(buddy->name);
|
|
526
|
|
527 if (!qd->logged_in)
|
|
528 return;
|
|
529
|
|
530 if (uid > 0)
|
|
531 _qq_send_packet_remove_buddy(gc, uid);
|
|
532
|
|
533 b = gaim_find_buddy(gc->account, buddy->name);
|
|
534 if (b != NULL) {
|
|
535 q_bud = (qq_buddy *) b->proto_data;
|
|
536 if (q_bud != NULL)
|
|
537 qd->buddies = g_list_remove(qd->buddies, q_bud);
|
|
538 else
|
|
539 gaim_debug(GAIM_DEBUG_WARNING, "QQ", "We have no qq_buddy record for %s\n", buddy->name);
|
|
540 /* remove buddy on blist, this does not trigger qq_remove_buddy again
|
|
541 * do this only if the request comes from block request,
|
|
542 * otherwise gaim segmentation fault */
|
|
543 if (g_ascii_strcasecmp(group->name, GAIM_GROUP_QQ_BLOCKED) == 0)
|
|
544 gaim_blist_remove_buddy(b);
|
|
545 }
|
|
546 }
|
|
547
|
|
548 /* free add buddy request queue */
|
|
549 void qq_add_buddy_request_free(qq_data *qd)
|
|
550 {
|
|
551 gint i;
|
|
552 qq_add_buddy_request *p;
|
|
553
|
|
554 g_return_if_fail(qd != NULL);
|
|
555
|
|
556 i = 0;
|
|
557 while (qd->add_buddy_request) {
|
|
558 p = (qq_add_buddy_request *) (qd->add_buddy_request->data);
|
|
559 qd->add_buddy_request = g_list_remove(qd->add_buddy_request, p);
|
|
560 g_free(p);
|
|
561 i++;
|
|
562 }
|
|
563 gaim_debug(GAIM_DEBUG_INFO, "QQ", "%d add buddy requests are freed!\n", i);
|
|
564 }
|
|
565
|
|
566 /* free up all qq_buddy */
|
|
567 void qq_buddies_list_free(GaimAccount *account, qq_data *qd)
|
|
568 {
|
|
569 gint i;
|
|
570 qq_buddy *p;
|
|
571 gchar *name;
|
|
572 GaimBuddy *b;
|
|
573
|
|
574 g_return_if_fail(qd != NULL);
|
|
575
|
|
576 i = 0;
|
|
577 while (qd->buddies) {
|
|
578 p = (qq_buddy *) (qd->buddies->data);
|
|
579 qd->buddies = g_list_remove(qd->buddies, p);
|
|
580 name = uid_to_gaim_name(p->uid);
|
|
581 b = gaim_find_buddy(account, name);
|
|
582 if(b != NULL)
|
|
583 b->proto_data = NULL;
|
|
584 else
|
|
585 gaim_debug(GAIM_DEBUG_INFO, "QQ", "qq_buddy %s not found in gaim proto_data\n", name);
|
|
586 g_free(name);
|
|
587
|
|
588 g_free(p);
|
|
589 i++;
|
|
590 }
|
|
591 gaim_debug(GAIM_DEBUG_INFO, "QQ", "%d qq_buddy structures are freed!\n", i);
|
|
592 }
|