comparison libpurple/protocols/qq/buddy_opt.c @ 24066:dbc7a9742f8d

2008.09.26 - ccpaging <ccpaging(at)gmail.com> * Added 'Request/Add/Remove Buddy' functions
author SHiNE CsyFeK <csyfek@gmail.com>
date Wed, 22 Oct 2008 14:35:05 +0000
parents bdfcfd71449c
children dc112387190f
comparison
equal deleted inserted replaced
24065:bdfcfd71449c 24066:dbc7a9742f8d
38 #include "packet_parse.h" 38 #include "packet_parse.h"
39 #include "qq_network.h" 39 #include "qq_network.h"
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 #define PURPLE_GROUP_QQ_UNKNOWN "QQ Unknown" 43 #define PURPLE_GROUP_QQ_UNKNOWN "QQ Unknown"
44 #define PURPLE_GROUP_QQ_BLOCKED "QQ Blocked"
45 44
46 #define QQ_REMOVE_BUDDY_REPLY_OK 0x00 45 #define QQ_REMOVE_BUDDY_REPLY_OK 0x00
47 #define QQ_REMOVE_SELF_REPLY_OK 0x00 46 #define QQ_REMOVE_SELF_REPLY_OK 0x00
48 #define QQ_ADD_BUDDY_AUTH_REPLY_OK 0x30 /* ASCII value of "0" */ 47 #define QQ_ADD_BUDDY_AUTH_REPLY_OK 0x30 /* ASCII value of "0" */
49 48
235 234
236 b = purple_find_buddy(gc->account, buddy->name); 235 b = purple_find_buddy(gc->account, buddy->name);
237 if (b != NULL) { 236 if (b != NULL) {
238 purple_blist_remove_buddy(b); 237 purple_blist_remove_buddy(b);
239 } 238 }
240 purple_notify_error(gc, NULL, _("QQ Number Error"), _("Invalid QQ Number")); 239 purple_notify_error(gc, _("QQ Buddy"), _("QQ Number Error"), _("Invalid QQ Number"));
241 } 240 }
242 241
243 void qq_change_buddys_group(PurpleConnection *gc, const char *who, 242 void qq_change_buddys_group(PurpleConnection *gc, const char *who,
244 const char *old_group, const char *new_group) 243 const char *old_group, const char *new_group)
245 { 244 {
345 who = buddy->name; 344 who = buddy->name;
346 g_return_if_fail(who != NULL); 345 g_return_if_fail(who != NULL);
347 346
348 uid = purple_name_to_uid(who); 347 uid = purple_name_to_uid(who);
349 g_return_if_fail(uid > 0); 348 g_return_if_fail(uid > 0);
349
350 if (uid == qd->uid) {
351 return;
352 }
350 353
351 add_req = g_new0(qq_add_request, 1); 354 add_req = g_new0(qq_add_request, 1);
352 add_req->gc = gc; 355 add_req->gc = gc;
353 add_req->uid = uid; 356 add_req->uid = uid;
354 357
371 g_return_if_fail(data != NULL && data_len != 0); 374 g_return_if_fail(data != NULL && data_len != 0);
372 375
373 qd = (qq_data *) gc->proto_data; 376 qd = (qq_data *) gc->proto_data;
374 377
375 if (data[0] != QQ_ADD_BUDDY_AUTH_REPLY_OK) { 378 if (data[0] != QQ_ADD_BUDDY_AUTH_REPLY_OK) {
376 purple_debug_warning("QQ", "Add buddy with auth request failed\n"); 379 purple_debug_warning("QQ", "Failed authorizing of adding requestion\n");
377 if (NULL == (segments = split_data(data, data_len, "\x1f", 2))) { 380 if (NULL == (segments = split_data(data, data_len, "\x1f", 2))) {
378 return; 381 return;
379 } 382 }
380 msg_utf8 = qq_to_utf8(segments[1], QQ_CHARSET_DEFAULT); 383 msg_utf8 = qq_to_utf8(segments[1], QQ_CHARSET_DEFAULT);
381 purple_notify_error(gc, NULL, _("Add buddy with auth request failed"), msg_utf8); 384 purple_notify_error(gc, _("QQ Buddy"), _("Failed authorizing of adding requestion"), msg_utf8);
382 g_free(msg_utf8); 385 g_free(msg_utf8);
383 } else { 386 } else {
384 purple_debug_info("QQ", "Add buddy with auth request OK\n"); 387 qq_got_attention(gc, _("Successed authorizing of adding requestion"));
385 } 388 }
386 } 389 }
387 390
388 /* process the server reply for my request to remove a buddy */ 391 /* process the server reply for my request to remove a buddy */
389 void qq_process_buddy_remove(guint8 *data, gint data_len, PurpleConnection *gc) 392 void qq_process_buddy_remove(guint8 *data, gint data_len, PurpleConnection *gc)
397 if (data[0] != QQ_REMOVE_BUDDY_REPLY_OK) { 400 if (data[0] != QQ_REMOVE_BUDDY_REPLY_OK) {
398 /* there is no reason return from server */ 401 /* there is no reason return from server */
399 purple_debug_warning("QQ", "Remove buddy fails\n"); 402 purple_debug_warning("QQ", "Remove buddy fails\n");
400 purple_notify_info(gc, _("QQ Buddy"), _("Failed:"), _("Remove buddy")); 403 purple_notify_info(gc, _("QQ Buddy"), _("Failed:"), _("Remove buddy"));
401 } else { /* if reply */ 404 } else { /* if reply */
402 purple_debug_info("QQ", "Remove buddy OK\n"); 405 qq_got_attention(gc, _("Successed removing budy."));
403 /* TODO: We don't really need to notify the user about this, do we? */
404 purple_notify_info(gc, _("QQ Buddy"), _("Successed:"), _("Remove buddy"));
405 } 406 }
406 } 407 }
407 408
408 /* process the server reply for my request to remove myself from a buddy */ 409 /* process the server reply for my request to remove myself from a buddy */
409 void qq_process_buddy_remove_me(guint8 *data, gint data_len, PurpleConnection *gc) 410 void qq_process_buddy_remove_me(guint8 *data, gint data_len, PurpleConnection *gc)
417 if (data[0] != QQ_REMOVE_SELF_REPLY_OK) { 418 if (data[0] != QQ_REMOVE_SELF_REPLY_OK) {
418 /* there is no reason return from server */ 419 /* there is no reason return from server */
419 purple_debug_warning("QQ", "Remove self fails\n"); 420 purple_debug_warning("QQ", "Remove self fails\n");
420 purple_notify_info(gc, _("QQ Buddy"), _("Failed:"), _("Remove me from other's buddy list")); 421 purple_notify_info(gc, _("QQ Buddy"), _("Failed:"), _("Remove me from other's buddy list"));
421 } else { /* if reply */ 422 } else { /* if reply */
422 purple_debug_info("QQ", "Remove from a buddy OK\n"); 423 qq_got_attention(gc, _("Successed removing me from other's budy list."));
423 #if 0
424 purple_notify_info(gc, _("QQ Buddy"), _("Successed:"), _("Remove from other's buddy list"));
425 #endif
426 } 424 }
427 } 425 }
428 426
429 void qq_process_buddy_add_no_auth(guint8 *data, gint data_len, guint32 uid, PurpleConnection *gc) 427 void qq_process_buddy_add_no_auth(guint8 *data, gint data_len, guint32 uid, PurpleConnection *gc)
430 { 428 {
476 add_req); 474 add_req);
477 g_free(msg); 475 g_free(msg);
478 g_free(nombre); 476 g_free(nombre);
479 } else { /* add OK */ 477 } else { /* add OK */
480 qq_create_buddy(gc, uid, TRUE, TRUE); 478 qq_create_buddy(gc, uid, TRUE, TRUE);
481 msg = g_strdup_printf(_("Add into %d's buddy list"), uid); 479 msg = g_strdup_printf(_("Successed adding into %d's buddy list"), uid);
482 purple_notify_info(gc, _("QQ Buddy"), _("Successed:"), msg); 480 qq_got_attention(gc, msg);
483 g_free(msg); 481 g_free(msg);
484 } 482 }
485 g_strfreev(segments); 483 g_strfreev(segments);
486 } 484 }
487 485
512 gchar *buddy_name, *group_name; 510 gchar *buddy_name, *group_name;
513 511
514 g_return_val_if_fail(gc->account != NULL && uid != 0, NULL); 512 g_return_val_if_fail(gc->account != NULL && uid != 0, NULL);
515 qd = (qq_data *) gc->proto_data; 513 qd = (qq_data *) gc->proto_data;
516 514
517 if (is_known) { 515 if (is_known || uid == qd->uid) {
518 group_name = g_strdup_printf(PURPLE_GROUP_QQ_FORMAT, 516 group_name = g_strdup_printf(PURPLE_GROUP_QQ_FORMAT,
519 purple_account_get_username(gc->account)); 517 purple_account_get_username(gc->account));
520 } else { 518 } else {
521 group_name = g_strdup(PURPLE_GROUP_QQ_UNKNOWN); 519 group_name = g_strdup(PURPLE_GROUP_QQ_UNKNOWN);
522 } 520 }
529 * because there might be old local copy of this buddy */ 527 * because there might be old local copy of this buddy */
530 if (buddy != NULL) 528 if (buddy != NULL)
531 purple_blist_remove_buddy(buddy); 529 purple_blist_remove_buddy(buddy);
532 530
533 buddy = purple_buddy_new(gc->account, buddy_name, NULL); 531 buddy = purple_buddy_new(gc->account, buddy_name, NULL);
534 if ( !is_known ) { 532 if ( !is_known && uid != qd->uid) {
535 if (purple_privacy_check(gc->account, buddy_name)) { 533 if (purple_privacy_check(gc->account, buddy_name)) {
536 purple_privacy_deny(gc->account, buddy_name, TRUE, FALSE); 534 purple_privacy_deny(gc->account, buddy_name, TRUE, FALSE);
537 } else { 535 } else {
538 purple_privacy_deny_add(gc->account, buddy_name, TRUE); 536 purple_privacy_deny_add(gc->account, buddy_name, TRUE);
539 } 537 }
699 add_req, 3, 697 add_req, 3,
700 _("Cancel"), G_CALLBACK(buddy_cancel_cb), 698 _("Cancel"), G_CALLBACK(buddy_cancel_cb),
701 _("Add"), G_CALLBACK(buddy_add_no_auth_cb), 699 _("Add"), G_CALLBACK(buddy_add_no_auth_cb),
702 _("Search"), G_CALLBACK(buddy_add_check_info_cb)); 700 _("Search"), G_CALLBACK(buddy_add_check_info_cb));
703 } else { 701 } else {
704 message = g_strdup_printf(_("%s added you [%s] to buddy list"), from, to); 702 message = g_strdup_printf(_("Successed adding into %s's buddy list"), from);
705 purple_notify_info(gc, _("QQ Budy"), _("Successed:"), message); 703 qq_got_attention(gc, message);
706 } 704 }
707 705
708 g_free(name); 706 g_free(name);
709 g_free(message); 707 g_free(message);
710 } 708 }
711 709
712 /* the buddy approves your request of adding him/her as your friend */ 710 /* the buddy approves your request of adding him/her as your friend */
713 static void server_buddy_added_me(PurpleConnection *gc, gchar *from, gchar *to, gchar *msg_utf8) 711 static void server_buddy_added_me(PurpleConnection *gc, gchar *from, gchar *to, gchar *msg_utf8)
714 { 712 {
715 gchar *message; 713 PurpleAccount *account = purple_connection_get_account(gc);
716 qq_data *qd; 714 qq_data *qd;
717 715
718 g_return_if_fail(from != NULL && to != NULL); 716 g_return_if_fail(from != NULL && to != NULL);
719 717
720 qd = (qq_data *) gc->proto_data; 718 qd = (qq_data *) gc->proto_data;
721 qq_create_buddy(gc, strtol(from, NULL, 10), TRUE, TRUE); 719 qq_create_buddy(gc, strtol(from, NULL, 10), TRUE, TRUE);
722 720
723 message = g_strdup_printf(_("Requestion approved by %s"), from); 721 purple_account_notify_added(account, from, to, NULL, msg_utf8);
724 purple_notify_info(gc, _("QQ Buddy"), _("Notice:"), message);
725
726 g_free(message);
727 } 722 }
728 723
729 /* you are rejected by the person */ 724 /* you are rejected by the person */
730 static void server_buddy_rejected_me(PurpleConnection *gc, gchar *from, gchar *to, gchar *msg_utf8) 725 static void server_buddy_rejected_me(PurpleConnection *gc, gchar *from, gchar *to, gchar *msg_utf8)
731 { 726 {