comparison libpurple/protocols/qq/buddy_opt.c @ 24092:7c0a56c5fea0

2008.10.14 - ccpaging <ccpaging(at)gmail.com> * 2007 remove buddy ok * Removed group_search.c/h
author SHiNE CsyFeK <csyfek@gmail.com>
date Tue, 28 Oct 2008 16:44:09 +0000
parents d35672443baa
children f4f29fac96c6
comparison
equal deleted inserted replaced
24091:d35672443baa 24092:7c0a56c5fea0
40 #include "utils.h" 40 #include "utils.h"
41 41
42 #define PURPLE_GROUP_QQ_FORMAT "QQ (%s)" 42 #define PURPLE_GROUP_QQ_FORMAT "QQ (%s)"
43 43
44 #define QQ_REMOVE_SELF_REPLY_OK 0x00 44 #define QQ_REMOVE_SELF_REPLY_OK 0x00
45 #define QQ_ADD_BUDDY_AUTH_REPLY_OK 0x30 /* ASCII value of "0" */
46 45
47 enum { 46 enum {
48 QQ_MY_AUTH_APPROVE = 0x30, /* ASCII value of "0" */ 47 QQ_MY_AUTH_APPROVE = 0x30, /* ASCII value of "0" */
49 QQ_MY_AUTH_REJECT = 0x31, /* ASCII value of "1" */ 48 QQ_MY_AUTH_REJECT = 0x31, /* ASCII value of "1" */
50 QQ_MY_AUTH_REQUEST = 0x32, /* ASCII value of "2" */ 49 QQ_MY_AUTH_REQUEST = 0x32, /* ASCII value of "2" */
200 g_snprintf(uid_str, sizeof(uid_str), "%d", uid); 199 g_snprintf(uid_str, sizeof(uid_str), "%d", uid);
201 bytes = strlen(uid_str); 200 bytes = strlen(uid_str);
202 qq_send_cmd_mess(gc, QQ_CMD_BUDDY_REMOVE, (guint8 *) uid_str, bytes, 0, uid); 201 qq_send_cmd_mess(gc, QQ_CMD_BUDDY_REMOVE, (guint8 *) uid_str, bytes, 0, uid);
203 } 202 }
204 203
204 static void request_buddy_remove_2007(PurpleConnection *gc,
205 guint32 uid, guint8 *auth, guint8 auth_len)
206 {
207 gint bytes;
208 guint8 *raw_data;
209 gchar uid_str[16];
210
211 g_return_if_fail(uid != 0);
212 g_return_if_fail(auth != NULL && auth_len > 0);
213
214 raw_data = g_newa(guint8, auth_len + sizeof(uid_str) );
215 bytes = 0;
216 bytes += qq_put8(raw_data + bytes, auth_len);
217 bytes += qq_putdata(raw_data + bytes, auth, auth_len);
218
219 g_snprintf(uid_str, sizeof(uid_str), "%d", uid);
220 bytes += qq_putdata(raw_data + bytes, (guint8 *)uid_str, strlen(uid_str));
221
222 qq_send_cmd_mess(gc, QQ_CMD_BUDDY_REMOVE, raw_data, bytes, 0, uid);
223 }
224
225 void qq_request_auth_info(PurpleConnection *gc, guint8 cmd, guint16 sub_cmd, guint32 uid)
226 {
227 guint8 raw_data[16];
228 gint bytes;
229
230 g_return_if_fail(uid > 0);
231 bytes = 0;
232 bytes += qq_put8(raw_data + bytes, cmd);
233 bytes += qq_put16(raw_data + bytes, sub_cmd);
234 bytes += qq_put32(raw_data + bytes, uid);
235
236 qq_send_cmd_mess(gc, QQ_CMD_AUTH_INFO, raw_data, bytes, 0, uid);
237 }
238
239 void qq_process_auth_info(PurpleConnection *gc, guint8 *data, gint data_len, guint32 uid)
240 {
241 qq_data *qd;
242 gint bytes;
243 guint8 cmd, reply;
244 guint16 sub_cmd;
245 guint8 *auth = NULL;
246 guint8 auth_len = 0;
247
248 g_return_if_fail(data != NULL && data_len != 0);
249 g_return_if_fail(uid != 0);
250
251 qd = (qq_data *) gc->proto_data;
252
253 qq_show_packet("qq_process_auth_info", data, data_len);
254 bytes = 0;
255 bytes += qq_get8(&cmd, data + bytes);
256 bytes += qq_get16(&sub_cmd, data + bytes);
257 bytes += qq_get8(&reply, data + bytes);
258 if (bytes + 2 <= data_len) {
259 bytes += 1; /* skip 1 byte, 0x00 */
260 bytes += qq_get8(&auth_len, data + bytes);
261 if (auth_len > 0) {
262 g_return_if_fail(bytes + auth_len <= data_len);
263 auth = g_newa(guint8, auth_len);
264 bytes += qq_getdata(auth, auth_len, data + bytes);
265 }
266 } else {
267 qq_show_packet("No auth info", data, data_len);
268 }
269
270 if (cmd == QQ_AUTH_INFO_BUDDY && sub_cmd == QQ_AUTH_INFO_REMOVE_BUDDY) {
271 g_return_if_fail(auth != NULL && auth_len > 0);
272 request_buddy_remove_2007(gc, uid, auth, auth_len);
273 }
274 if (cmd == QQ_AUTH_INFO_BUDDY && sub_cmd == QQ_AUTH_INFO_ADD_BUDDY) {
275 }
276 purple_debug_info("QQ", "Got auth info cmd 0x%x, sub 0x%x, reply 0x%x\n",
277 cmd, sub_cmd, reply);
278 }
279
205 /* try to remove myself from someone's buddy list */ 280 /* try to remove myself from someone's buddy list */
206 static void request_buddy_remove_me(PurpleConnection *gc, guint32 uid) 281 static void request_buddy_remove_me(PurpleConnection *gc, guint32 uid)
207 { 282 {
208 guint8 raw_data[16] = {0}; 283 guint8 raw_data[16] = {0};
209 gint bytes = 0; 284 gint bytes = 0;
278 353
279 request_buddy_auth(add_req->gc, add_req->uid, QQ_MY_AUTH_REJECT, reason); 354 request_buddy_auth(add_req->gc, add_req->uid, QQ_MY_AUTH_REJECT, reason);
280 g_free(add_req); 355 g_free(add_req);
281 } 356 }
282 357
358 static void buddy_add_deny_noreason_cb(qq_buddy_req *add_req)
359 {
360 buddy_add_deny_reason_cb(add_req, NULL);
361 }
362
283 /* we approve other's request of adding me as friend */ 363 /* we approve other's request of adding me as friend */
284 static void buddy_add_authorize_cb(qq_buddy_req *add_req) 364 static void buddy_add_authorize_cb(gpointer data)
285 { 365 {
286 g_return_if_fail(add_req != NULL); 366 qq_buddy_req *add_req = (qq_buddy_req *)data;
287 if (add_req->gc == NULL || add_req->uid != 0) {
288 g_free(add_req);
289 return;
290 }
291
292 request_buddy_auth(add_req->gc, add_req->uid, QQ_MY_AUTH_APPROVE, NULL);
293 g_free(add_req);
294 }
295
296 /* we reject other's request of adding me as friend */
297 static void buddy_add_deny_cb(qq_buddy_req *add_req)
298 {
299 gint uid;
300 gchar *msg1, *msg2;
301 PurpleConnection *gc;
302 gchar *purple_name;
303 367
304 g_return_if_fail(add_req != NULL); 368 g_return_if_fail(add_req != NULL);
305 if (add_req->gc == NULL || add_req->uid == 0) { 369 if (add_req->gc == NULL || add_req->uid == 0) {
306 g_free(add_req); 370 g_free(add_req);
307 return; 371 return;
308 } 372 }
309 373
310 gc = add_req->gc; 374 request_buddy_auth(add_req->gc, add_req->uid, QQ_MY_AUTH_APPROVE, NULL);
311 uid = add_req->uid; 375 g_free(add_req);
312 376 }
313 msg1 = g_strdup_printf(_("You rejected %d's request"), uid); 377
314 msg2 = g_strdup(_("Message:")); 378 /* we reject other's request of adding me as friend */
315 379 static void buddy_add_deny_cb(gpointer data)
316 purple_name = uid_to_purple_name(uid); 380 {
317 purple_request_input(gc, _("Reject request"), msg1, msg2, 381 qq_buddy_req *add_req = (qq_buddy_req *)data;
318 _("Sorry, you are not my style..."), TRUE, FALSE, 382 gchar *who = uid_to_purple_name(add_req->uid);
319 NULL, _("Reject"), G_CALLBACK(buddy_add_deny_reason_cb), _("Cancel"), NULL, 383 purple_request_input(add_req->gc, NULL, _("Authorization denied message:"),
320 purple_connection_get_account(gc), purple_name, NULL, 384 NULL, _("Sorry, You are not my style."), TRUE, FALSE, NULL,
385 _("OK"), G_CALLBACK(buddy_add_deny_reason_cb),
386 _("Cancel"), G_CALLBACK(buddy_add_deny_noreason_cb),
387 purple_connection_get_account(add_req->gc), who, NULL,
321 add_req); 388 add_req);
322 g_free(purple_name); 389 g_free(who);
323 }
324
325 /* suggested by rakescar@linuxsir, can still approve after search */
326 static void buddy_add_check_info_cb(qq_buddy_req *add_req)
327 {
328 PurpleConnection *gc;
329 guint32 uid;
330 gchar *purple_name;
331
332 g_return_if_fail(add_req != NULL);
333 if (add_req->gc == NULL || add_req->uid == 0) {
334 g_free(add_req);
335 return;
336 }
337
338 gc = add_req->gc;
339 uid = add_req->uid;
340
341 qq_request_buddy_info(gc, uid, 0, QQ_BUDDY_INFO_DISPLAY);
342
343 purple_name = uid_to_purple_name(uid);
344 purple_request_action
345 (gc, NULL, _("Do you approve the requestion?"), "",
346 PURPLE_DEFAULT_ACTION_NONE,
347 purple_connection_get_account(gc), purple_name, NULL,
348 add_req, 2,
349 _("Reject"), G_CALLBACK(buddy_add_deny_cb),
350 _("Approve"), G_CALLBACK(buddy_add_authorize_cb));
351 g_free(purple_name);
352 } 390 }
353 391
354 /* add a buddy and send packet to QQ server 392 /* add a buddy and send packet to QQ server
355 * note that when purple load local cached buddy list into its blist 393 * note that when purple load local cached buddy list into its blist
356 * it also calls this funtion, so we have to 394 * it also calls this funtion, so we have to
408 446
409 g_return_if_fail(data != NULL && data_len != 0); 447 g_return_if_fail(data != NULL && data_len != 0);
410 448
411 qd = (qq_data *) gc->proto_data; 449 qd = (qq_data *) gc->proto_data;
412 450
413 if (data[0] != QQ_ADD_BUDDY_AUTH_REPLY_OK) { 451 if (data[0] == '0') {
414 if (NULL == (segments = split_data(data, data_len, "\x1f", 2))) { 452 purple_debug_info("QQ", "Reply OK for sending authorize\n");
415 purple_notify_error(gc, _("QQ Buddy"), _("Failed sending authorize"), NULL); 453 return;
416 return; 454 }
417 } 455
418 msg_utf8 = qq_to_utf8(segments[1], QQ_CHARSET_DEFAULT); 456 if (NULL == (segments = split_data(data, data_len, "\x1f", 2))) {
419 purple_notify_error(gc, _("QQ Buddy"), _("Failed sending authorize"), msg_utf8); 457 purple_notify_error(gc, _("QQ Buddy"), _("Failed sending authorize"), NULL);
420 g_free(msg_utf8); 458 return;
421 } else { 459 }
422 qq_got_attention(gc, _("Successed sending authorize")); 460 msg_utf8 = qq_to_utf8(segments[1], QQ_CHARSET_DEFAULT);
423 } 461 purple_notify_error(gc, _("QQ Buddy"), _("Failed sending authorize"), msg_utf8);
462 g_free(msg_utf8);
424 } 463 }
425 464
426 /* process the server reply for my request to remove a buddy */ 465 /* process the server reply for my request to remove a buddy */
427 void qq_process_buddy_remove(PurpleConnection *gc, guint8 *data, gint data_len, guint32 uid) 466 void qq_process_buddy_remove(PurpleConnection *gc, guint8 *data, gint data_len, guint32 uid)
428 { 467 {
434 473
435 buddy = qq_buddy_find(gc, uid); 474 buddy = qq_buddy_find(gc, uid);
436 if (data[0] != 0) { 475 if (data[0] != 0) {
437 msg = g_strdup_printf(_("Failed removing buddy %d"), uid); 476 msg = g_strdup_printf(_("Failed removing buddy %d"), uid);
438 purple_notify_info(gc, _("QQ Buddy"), msg, NULL); 477 purple_notify_info(gc, _("QQ Buddy"), msg, NULL);
439 if (buddy == NULL) { 478 g_free(msg);
440 /* Add buddy with no-auth */ 479 }
441 qq_buddy_new(gc, uid); 480
442 } 481 purple_debug_info("QQ", "Reply OK for removing buddy\n");
443 } else { 482 /* remove buddy again */
444 msg = g_strdup_printf(_("Successed removing buddy %d"), uid); 483 if (buddy != NULL) {
445 qq_got_attention(gc, _("Successed removing budy.")); 484 qq_buddy_free(buddy);
446 if (buddy != NULL) { 485 }
447 /* remove buddy again */
448 qq_buddy_free(buddy);
449 }
450 }
451 g_free(msg);
452 } 486 }
453 487
454 /* process the server reply for my request to remove myself from a buddy */ 488 /* process the server reply for my request to remove myself from a buddy */
455 void qq_process_buddy_remove_me(PurpleConnection *gc, guint8 *data, gint data_len, guint32 uid) 489 void qq_process_buddy_remove_me(PurpleConnection *gc, guint8 *data, gint data_len, guint32 uid)
456 { 490 {
458 gchar *msg; 492 gchar *msg;
459 493
460 g_return_if_fail(data != NULL && data_len != 0); 494 g_return_if_fail(data != NULL && data_len != 0);
461 qd = (qq_data *) gc->proto_data; 495 qd = (qq_data *) gc->proto_data;
462 496
463 if (data[0] != 0) { 497 if (data[0] == 0) {
464 msg = g_strdup_printf(_("Failed removing me from %d's buddy list"), uid); 498 purple_debug_info("QQ", "Reply OK for removing me from %d's buddy list\n", uid);
465 purple_notify_info(gc, _("QQ Buddy"), msg, NULL); 499 return;
466 } else { 500 }
467 msg = g_strdup_printf(_("Successed removing me from %d's buddy list"), uid); 501 msg = g_strdup_printf(_("Failed removing me from %d's buddy list"), uid);
468 qq_got_attention(gc, msg); 502 purple_notify_info(gc, _("QQ Buddy"), msg, NULL);
469 }
470 g_free(msg); 503 g_free(msg);
471 } 504 }
472 505
473 void qq_process_buddy_add_no_auth(guint8 *data, gint data_len, guint32 uid, PurpleConnection *gc) 506 void qq_process_buddy_add_no_auth(guint8 *data, gint data_len, guint32 uid, PurpleConnection *gc)
474 { 507 {
480 513
481 g_return_if_fail(data != NULL && data_len != 0); 514 g_return_if_fail(data != NULL && data_len != 0);
482 515
483 qd = (qq_data *) gc->proto_data; 516 qd = (qq_data *) gc->proto_data;
484 517
485 if (uid == 0) { /* we have no record for this */ 518 if (uid == 0) {
486 purple_debug_error("QQ", "Process buddy add, unknow id\n"); 519 purple_debug_error("QQ", "Process buddy add, unknow id\n");
487 return; 520 return;
488 } 521 }
489 purple_debug_info("QQ", "Process buddy add for id [%d]\n", uid); 522 purple_debug_info("QQ", "Process buddy add for id [%d]\n", uid);
490 qq_show_packet("buddy_add_no_auth", data, data_len); 523 qq_show_packet("buddy_add_no_auth", data, data_len);
510 } else { 543 } else {
511 qq_request_get_level(gc, uid); 544 qq_request_get_level(gc, uid);
512 } 545 }
513 qq_request_get_buddies_online(gc, 0, 0); 546 qq_request_get_buddies_online(gc, 0, 0);
514 547
515 msg = g_strdup_printf(_("Successed adding into %d's buddy list"), uid); 548 purple_debug_info("QQ", "Successed adding into %d's buddy list", uid);
516 qq_got_attention(gc, msg);
517 g_free(msg);
518 g_strfreev(segments); 549 g_strfreev(segments);
519 return; 550 return;
520 } 551 }
521 552
522 /* need auth */ 553 /* need auth */
536 add_req = g_new0(qq_buddy_req, 1); 567 add_req = g_new0(qq_buddy_req, 1);
537 add_req->gc = gc; 568 add_req->gc = gc;
538 add_req->uid = uid; 569 add_req->uid = uid;
539 msg = g_strdup_printf(_("%d needs authentication"), uid); 570 msg = g_strdup_printf(_("%d needs authentication"), uid);
540 purple_request_input(gc, _("Add buddy authorize"), msg, 571 purple_request_input(gc, _("Add buddy authorize"), msg,
541 _("Input request here"), /* TODO: Awkward string to fix post string freeze - standardize auth dialogues? -evands */ 572 _("Input request here"),
542 _("Would you be my friend?"), 573 _("Would you be my friend?"),
543 TRUE, FALSE, NULL, _("Send"), 574 TRUE, FALSE, NULL,
544 G_CALLBACK(request_buddy_add_auth_cb), 575 _("Send"), G_CALLBACK(request_buddy_add_auth_cb),
545 _("Cancel"), G_CALLBACK(buddy_cancel_cb), 576 _("Cancel"), G_CALLBACK(buddy_cancel_cb),
546 purple_connection_get_account(gc), who, NULL, 577 purple_connection_get_account(gc), who, NULL,
547 add_req); 578 add_req);
548 579
549 g_free(msg); 580 g_free(msg);
563 qd = (qq_data *) gc->proto_data; 594 qd = (qq_data *) gc->proto_data;
564 if (!qd->is_login) 595 if (!qd->is_login)
565 return; 596 return;
566 597
567 uid = purple_name_to_uid(buddy->name); 598 uid = purple_name_to_uid(buddy->name);
568 if (uid > 0) { 599 if (uid > 0 && uid != qd->uid) {
569 request_buddy_remove(gc, uid); 600 if (qd->client_version > 2005) {
570 request_buddy_remove_me(gc, uid); 601 qq_request_auth_info(gc, QQ_AUTH_INFO_BUDDY, QQ_AUTH_INFO_REMOVE_BUDDY, uid);
602 } else {
603 request_buddy_remove(gc, uid);
604 request_buddy_remove_me(gc, uid);
605 }
571 } 606 }
572 607
573 if (buddy->proto_data) { 608 if (buddy->proto_data) {
574 qq_buddy_data_free(buddy->proto_data); 609 qq_buddy_data_free(buddy->proto_data);
575 buddy->proto_data = NULL; 610 buddy->proto_data = NULL;
580 /* Do not call purple_blist_remove_buddy, 615 /* Do not call purple_blist_remove_buddy,
581 * otherwise purple segmentation fault */ 616 * otherwise purple segmentation fault */
582 } 617 }
583 618
584 /* someone wants to add you to his buddy list */ 619 /* someone wants to add you to his buddy list */
585 static void server_buddy_add_request(PurpleConnection *gc, gchar *from, gchar *to, gchar *msg_utf8) 620 static void server_buddy_add_request(PurpleConnection *gc, gchar *from, gchar *to,
586 { 621 guint8 *data, gint data_len)
587 gchar *message, *reason; 622 {
588 guint32 uid; 623 PurpleAccount *account = purple_connection_get_account(gc);
589 qq_buddy_req *g, *g2; 624 qq_buddy_req *add_req;
590 PurpleBuddy *b; 625 gchar *who;
591 gchar *name; 626 gchar *msg, *reason;
592 627
593 g_return_if_fail(from != NULL && to != NULL); 628 g_return_if_fail(from != NULL && to != NULL);
594 629
595 uid = strtol(from, NULL, 10); 630 add_req = g_new0(qq_buddy_req, 1);
596 g = g_new0(qq_buddy_req, 1); 631 add_req->gc = gc;
597 g->gc = gc; 632 add_req->uid = strtol(from, NULL, 10);;
598 g->uid = uid; 633
599 634 if (purple_prefs_get_bool("/plugins/prpl/qq/auto_get_authorize_info")) {
600 name = uid_to_purple_name(uid); 635 qq_request_buddy_info(gc, add_req->uid, 0, QQ_BUDDY_INFO_DISPLAY);
601 636 }
602 /* TODO: this should go through purple_account_request_authorization() */ 637 who = uid_to_purple_name(add_req->uid);
603 message = g_strdup_printf(_("%s wants to add you [%s] as a friend"), from, to); 638
604 reason = g_strdup_printf(_("Message: %s"), msg_utf8); 639 if (data_len <= 0) {
605 640 reason = g_strdup( _("No reason given") );
606 purple_request_action 641 } else {
607 (gc, NULL, message, reason, PURPLE_DEFAULT_ACTION_NONE, 642 msg = g_strndup((gchar *)data, data_len);
608 purple_connection_get_account(gc), name, NULL, 643 reason = qq_to_utf8(msg, QQ_CHARSET_DEFAULT);
609 g, 3, 644 if (reason == NULL) reason = g_strdup( _("Unknown reason") );
610 _("Reject"), 645 g_free(msg);
611 G_CALLBACK(buddy_add_deny_cb), 646 }
612 _("Approve"), 647 purple_account_request_authorization(account,
613 G_CALLBACK(buddy_add_authorize_cb), 648 from, NULL,
614 _("Search"), G_CALLBACK(buddy_add_check_info_cb)); 649 NULL, reason,
615 650 purple_find_buddy(account, who) != NULL,
616 g_free(message); 651 buddy_add_authorize_cb,
652 buddy_add_deny_cb,
653 add_req);
654
617 g_free(reason); 655 g_free(reason);
618 656 g_free(who);
619 /* XXX: Is this needed once the above goes through purple_account_request_authorization()? */
620 b = purple_find_buddy(gc->account, name);
621 if (b == NULL) { /* the person is not in my list */
622 g2 = g_new0(qq_buddy_req, 1);
623 g2->gc = gc;
624 g2->uid = strtol(from, NULL, 10);
625 message = g_strdup_printf(_("%s is not in buddy list"), from);
626 purple_request_action(gc, NULL, message,
627 _("Would you add?"), PURPLE_DEFAULT_ACTION_NONE,
628 purple_connection_get_account(gc), name, NULL,
629 g2, 3,
630 _("Cancel"), NULL,
631 _("Add"), G_CALLBACK(buddy_add_no_auth_cb),
632 _("Search"), G_CALLBACK(buddy_add_check_info_cb));
633 g_free(message);
634 }
635
636 g_free(name);
637 } 657 }
638 658
639 /* when you are added by a person, QQ server will send sys message */ 659 /* when you are added by a person, QQ server will send sys message */
640 static void server_buddy_added(PurpleConnection *gc, gchar *from, gchar *to, gchar *msg_utf8) 660 static void server_buddy_added(PurpleConnection *gc, gchar *from, gchar *to,
641 { 661 guint8 *data, gint data_len)
642 gchar *message; 662 {
643 PurpleBuddy *b; 663 PurpleAccount *account = purple_connection_get_account(gc);
664 PurpleBuddy *buddy;
644 guint32 uid; 665 guint32 uid;
645 qq_buddy_req *add_req; 666 qq_buddy_req *add_req;
646 gchar *name; 667 gchar *who;
668 gchar *primary;
647 669
648 g_return_if_fail(from != NULL && to != NULL); 670 g_return_if_fail(from != NULL && to != NULL);
649 671
650 uid = strtol(from, NULL, 10); 672 uid = strtol(from, NULL, 10);
651 name = uid_to_purple_name(uid); 673 who = uid_to_purple_name(uid);
652 b = purple_find_buddy(gc->account, name); 674
653 675 buddy = purple_find_buddy(account, who);
654 if (b == NULL) { /* the person is not in my list */ 676 if (buddy != NULL) {
655 add_req = g_new0(qq_buddy_req, 1); 677 purple_account_notify_added(account, from, to, NULL, NULL);
656 add_req->gc = gc; 678 }
657 add_req->uid = uid; /* only need to get value */ 679
658 message = g_strdup_printf(_("You have been added by %s"), from); 680 add_req = g_new0(qq_buddy_req, 1);
659 purple_request_action(gc, NULL, message, 681 add_req->gc = gc;
660 _("Would you like to add him?"), 682 add_req->uid = uid; /* only need to get value */
661 PURPLE_DEFAULT_ACTION_NONE, 683 primary = g_strdup_printf(_("You have been added by %s"), from);
662 purple_connection_get_account(gc), name, NULL, 684 purple_request_action(gc, NULL, primary,
663 add_req, 3, 685 _("Would you like to add him?"),
664 _("Cancel"), G_CALLBACK(buddy_cancel_cb), 686 PURPLE_DEFAULT_ACTION_NONE,
665 _("Add"), G_CALLBACK(buddy_add_no_auth_cb), 687 purple_connection_get_account(gc), who, NULL,
666 _("Search"), G_CALLBACK(buddy_add_check_info_cb)); 688 add_req, 2,
667 } else { 689 _("Cancel"), G_CALLBACK(buddy_cancel_cb),
668 message = g_strdup_printf(_("Successed adding into %s's buddy list"), from); 690 _("Add"), G_CALLBACK(buddy_add_no_auth_cb));
669 qq_got_attention(gc, message); 691
670 } 692 g_free(who);
671 693 g_free(primary);
672 g_free(name);
673 g_free(message);
674 } 694 }
675 695
676 /* the buddy approves your request of adding him/her as your friend */ 696 /* the buddy approves your request of adding him/her as your friend */
677 static void server_buddy_added_me(PurpleConnection *gc, gchar *from, gchar *to, gchar *msg_utf8) 697 static void server_buddy_added_me(PurpleConnection *gc, gchar *from, gchar *to,
698 guint8 *data, gint data_len)
678 { 699 {
679 PurpleAccount *account = purple_connection_get_account(gc); 700 PurpleAccount *account = purple_connection_get_account(gc);
680 qq_data *qd; 701 qq_data *qd;
681 guint32 uid; 702 guint32 uid;
682 703
694 qq_request_get_level_2007(gc, uid); 715 qq_request_get_level_2007(gc, uid);
695 } else { 716 } else {
696 qq_request_get_level(gc, uid); 717 qq_request_get_level(gc, uid);
697 } 718 }
698 719
699 purple_account_notify_added(account, from, to, NULL, msg_utf8); 720 purple_account_notify_added(account, to, from, NULL, NULL);
700 } 721 }
701 722
702 /* you are rejected by the person */ 723 /* you are rejected by the person */
703 static void server_buddy_rejected_me(PurpleConnection *gc, gchar *from, gchar *to, gchar *msg_utf8) 724 static void server_buddy_rejected_me(PurpleConnection *gc, gchar *from, gchar *to,
704 { 725 guint8 *data, gint data_len)
705 gchar *message, *reason; 726 {
706 guint32 uid; 727 guint32 uid;
707 PurpleBuddy *buddy; 728 PurpleBuddy *buddy;
729 gchar *msg, *msg_utf8;
730 gchar *primary, *secondary;
708 731
709 g_return_if_fail(from != NULL && to != NULL); 732 g_return_if_fail(from != NULL && to != NULL);
710 733
711 message = g_strdup_printf(_("Requestion rejected by %s"), from); 734 if (data_len <= 0) {
712 reason = g_strdup_printf(_("Message: %s"), msg_utf8); 735 msg = g_strdup( _("No reason given") );
713 736 } else {
714 purple_notify_info(gc, _("QQ Buddy"), message, reason); 737 msg = g_strndup((gchar *)data, data_len);
715 g_free(message); 738 }
716 g_free(reason); 739 msg_utf8 = qq_to_utf8(msg, QQ_CHARSET_DEFAULT);
717 740 if (msg_utf8 == NULL) {
741 msg_utf8 = g_strdup( _("Unknown reason") );
742 }
743 g_free(msg);
744
745 primary = g_strdup_printf(_("Rejected by %s"), from);
746 secondary = g_strdup_printf(_("Message: %s"), msg_utf8);
747
748 purple_notify_info(gc, _("QQ Buddy"), primary, secondary);
749
750 g_free(msg_utf8);
751 g_free(primary);
752 g_free(secondary);
753
718 uid = strtol(from, NULL, 10); 754 uid = strtol(from, NULL, 10);
719 g_return_if_fail(uid != 0); 755 g_return_if_fail(uid != 0);
720 756
721 buddy = qq_buddy_find(gc, uid); 757 buddy = qq_buddy_find(gc, uid);
722 if (buddy != NULL && buddy->proto_data != NULL) { 758 if (buddy != NULL && buddy->proto_data != NULL) {
723 /* Not authorized now, free buddy data */ 759 /* Not authorized now, free buddy data */
724 qq_buddy_data_free(buddy->proto_data); 760 qq_buddy_data_free(buddy->proto_data);
725 buddy->proto_data = NULL; 761 buddy->proto_data = NULL;
726 } 762 }
727 } 763 }
728 764
729 void qq_process_buddy_from_server(PurpleConnection *gc, int funct, 765 void qq_process_buddy_from_server(PurpleConnection *gc, int funct,
730 gchar *from, gchar *to, gchar *msg_utf8) 766 gchar *from, gchar *to, guint8 *data, gint data_len)
731 { 767 {
732 switch (funct) { 768 switch (funct) {
733 case QQ_SERVER_BUDDY_ADDED: 769 case QQ_SERVER_BUDDY_ADDED:
734 server_buddy_added(gc, from, to, msg_utf8); 770 server_buddy_added(gc, from, to, data, data_len);
735 break; 771 break;
736 case QQ_SERVER_BUDDY_ADD_REQUEST: 772 case QQ_SERVER_BUDDY_ADD_REQUEST:
737 server_buddy_add_request(gc, from, to, msg_utf8); 773 server_buddy_add_request(gc, from, to, data, data_len);
774 break;
775 case QQ_MSG_SYS_ADD_FRIEND_REQUEST_EX:
776 // server_buddy_add_request_ex(gc, from, to, data, data_len);
738 break; 777 break;
739 case QQ_SERVER_BUDDY_ADDED_ME: 778 case QQ_SERVER_BUDDY_ADDED_ME:
740 server_buddy_added_me(gc, from, to, msg_utf8); 779 server_buddy_added_me(gc, from, to, data, data_len);
741 break; 780 break;
742 case QQ_SERVER_BUDDY_REJECTED_ME: 781 case QQ_SERVER_BUDDY_REJECTED_ME:
743 server_buddy_rejected_me(gc, from, to, msg_utf8); 782 server_buddy_rejected_me(gc, from, to, data, data_len);
744 break; 783 break;
745 default: 784 default:
746 purple_debug_warning("QQ", "Unknow buddy operate (%d) from server\n", funct); 785 purple_debug_warning("QQ", "Unknow buddy operate (%d) from server\n", funct);
747 break; 786 break;
748 } 787 }