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