comparison libpurple/protocols/qq/qq.c @ 24135: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 87e61a85f5dd
comparison
equal deleted inserted replaced
24134:bdfcfd71449c 24135:dbc7a9742f8d
42 #include "group_find.h" 42 #include "group_find.h"
43 #include "group_im.h" 43 #include "group_im.h"
44 #include "group_info.h" 44 #include "group_info.h"
45 #include "group_join.h" 45 #include "group_join.h"
46 #include "group_opt.h" 46 #include "group_opt.h"
47 #include "group_internal.h"
47 #include "qq_define.h" 48 #include "qq_define.h"
48 #include "im.h" 49 #include "im.h"
49 #include "qq_process.h" 50 #include "qq_process.h"
50 #include "qq_base.h" 51 #include "qq_base.h"
51 #include "packet_parse.h" 52 #include "packet_parse.h"
154 155
155 server_list_create(account); 156 server_list_create(account);
156 purple_debug_info("QQ", "Server list has %d\n", g_list_length(qd->servers)); 157 purple_debug_info("QQ", "Server list has %d\n", g_list_length(qd->servers));
157 158
158 version_str = purple_account_get_string(account, "client_version", NULL); 159 version_str = purple_account_get_string(account, "client_version", NULL);
159 qd->client_version = QQ_CLIENT_0D55; /* set default as QQ2005 */ 160 qd->client_tag = QQ_CLIENT_0D55; /* set default as QQ2005 */
160 qd->is_above_2007 = FALSE; 161 qd->client_version = 2005;
161 if (version_str != NULL && strlen(version_str) != 0) { 162 if (version_str != NULL && strlen(version_str) != 0) {
162 if (strcmp(version_str, "qq2007") == 0) { 163 if (strcmp(version_str, "qq2007") == 0) {
163 qd->client_version = QQ_CLIENT_111D; 164 qd->client_tag = QQ_CLIENT_111D;
164 qd->is_above_2007 = TRUE; 165 qd->client_version = 2007;
166 } else if (strcmp(version_str, "qq2008") == 0) {
167 qd->client_tag = QQ_CLIENT_115B;
168 qd->client_version = 2008;
165 } 169 }
166 } 170 }
167 171
168 qd->is_show_notice = purple_account_get_bool(account, "show_notice", TRUE); 172 qd->is_show_notice = purple_account_get_bool(account, "show_notice", TRUE);
169 qd->is_show_news = purple_account_get_bool(account, "show_news", TRUE); 173 qd->is_show_news = purple_account_get_bool(account, "show_news", TRUE);
214 } 218 }
215 219
216 qq_disconnect(gc); 220 qq_disconnect(gc);
217 221
218 if (qd->ld.token) g_free(qd->ld.token); 222 if (qd->ld.token) g_free(qd->ld.token);
223 if (qd->ld.token_ex) g_free(qd->ld.token_ex);
219 if (qd->captcha.token) g_free(qd->captcha.token); 224 if (qd->captcha.token) g_free(qd->captcha.token);
220 if (qd->captcha.data) g_free(qd->captcha.data); 225 if (qd->captcha.data) g_free(qd->captcha.data);
221 226
222 server_list_remove_all(qd); 227 server_list_remove_all(qd);
223 228
224 g_free(qd); 229 g_free(qd);
225 gc->proto_data = NULL; 230 gc->proto_data = NULL;
226 } 231 }
227 232
228 /* returns the icon name for a buddy or protocol */ 233 /* returns the icon name for a buddy or protocol */
229 static const gchar *_qq_list_icon(PurpleAccount *a, PurpleBuddy *b) 234 static const gchar *qq_list_icon(PurpleAccount *a, PurpleBuddy *b)
230 { 235 {
231 return "qq"; 236 return "qq";
232 } 237 }
233 238
234 239
235 /* a short status text beside buddy icon*/ 240 /* a short status text beside buddy icon*/
236 static gchar *_qq_status_text(PurpleBuddy *b) 241 static gchar *qq_status_text(PurpleBuddy *b)
237 { 242 {
238 qq_buddy *q_bud; 243 qq_buddy *q_bud;
239 GString *status; 244 GString *status;
240 245
241 q_bud = (qq_buddy *) b->proto_data; 246 q_bud = (qq_buddy *) b->proto_data;
268 return g_string_free(status, FALSE); 273 return g_string_free(status, FALSE);
269 } 274 }
270 275
271 276
272 /* a floating text when mouse is on the icon, show connection status here */ 277 /* a floating text when mouse is on the icon, show connection status here */
273 static void _qq_tooltip_text(PurpleBuddy *b, PurpleNotifyUserInfo *user_info, gboolean full) 278 static void qq_tooltip_text(PurpleBuddy *b, PurpleNotifyUserInfo *user_info, gboolean full)
274 { 279 {
275 qq_buddy *q_bud; 280 qq_buddy *q_bud;
276 gchar *tmp; 281 gchar *tmp;
277 GString *str; 282 GString *str;
278 283
347 352
348 g_string_free(str, TRUE); 353 g_string_free(str, TRUE);
349 354
350 #ifdef DEBUG 355 #ifdef DEBUG
351 tmp = g_strdup_printf( "%s (%04X)", 356 tmp = g_strdup_printf( "%s (%04X)",
352 qq_get_ver_desc(q_bud->client_version), 357 qq_get_ver_desc(q_bud->client_tag),
353 q_bud->client_version ); 358 q_bud->client_tag );
354 purple_notify_user_info_add_pair(user_info, _("Ver"), tmp); 359 purple_notify_user_info_add_pair(user_info, _("Ver"), tmp);
355 g_free(tmp); 360 g_free(tmp);
356 361
357 tmp = g_strdup_printf( "Ext 0x%X, Comm 0x%X", 362 tmp = g_strdup_printf( "Ext 0x%X, Comm 0x%X",
358 q_bud->ext_flag, q_bud->comm_flag ); 363 q_bud->ext_flag, q_bud->comm_flag );
360 g_free(tmp); 365 g_free(tmp);
361 #endif 366 #endif
362 } 367 }
363 368
364 /* we can show tiny icons on the four corners of buddy icon, */ 369 /* we can show tiny icons on the four corners of buddy icon, */
365 static const char *_qq_list_emblem(PurpleBuddy *b) 370 static const char *qq_list_emblem(PurpleBuddy *b)
366 { 371 {
367 /* each char** are refering to a filename in pixmaps/purple/status/default/ */ 372 /* each char** are refering to a filename in pixmaps/purple/status/default/ */
368 qq_buddy *q_bud; 373 qq_buddy *q_bud;
369 374
370 if (!b || !(q_bud = b->proto_data)) { 375 if (!b || !(q_bud = b->proto_data)) {
380 385
381 return NULL; 386 return NULL;
382 } 387 }
383 388
384 /* QQ away status (used to initiate QQ away packet) */ 389 /* QQ away status (used to initiate QQ away packet) */
385 static GList *_qq_away_states(PurpleAccount *ga) 390 static GList *qq_status_types(PurpleAccount *ga)
386 { 391 {
387 PurpleStatusType *status; 392 PurpleStatusType *status;
388 GList *types = NULL; 393 GList *types = NULL;
389 394
390 status = purple_status_type_new_full(PURPLE_STATUS_AVAILABLE, 395 status = purple_status_type_new_full(PURPLE_STATUS_AVAILABLE,
409 414
410 return types; 415 return types;
411 } 416 }
412 417
413 /* initiate QQ away with proper change_status packet */ 418 /* initiate QQ away with proper change_status packet */
414 static void _qq_change_status(PurpleAccount *account, PurpleStatus *status) 419 static void qq_change_status(PurpleAccount *account, PurpleStatus *status)
415 { 420 {
416 PurpleConnection *gc = purple_account_get_connection(account); 421 PurpleConnection *gc = purple_account_get_connection(account);
417 422
418 qq_request_change_status(gc, 0); 423 qq_request_change_status(gc, 0);
419 } 424 }
420 425
421 /* IMPORTANT: PurpleConvImFlags -> PurpleMessageFlags */ 426 /* IMPORTANT: PurpleConvImFlags -> PurpleMessageFlags */
422 /* send an instant msg to a buddy */ 427 /* send an instant msg to a buddy */
423 static gint _qq_send_im(PurpleConnection *gc, const gchar *who, const gchar *message, PurpleMessageFlags flags) 428 static gint qq_send_im(PurpleConnection *gc, const gchar *who, const gchar *message, PurpleMessageFlags flags)
424 { 429 {
425 gint type, to_uid; 430 gint type, to_uid;
426 gchar *msg, *msg_with_qq_smiley; 431 gchar *msg, *msg_with_qq_smiley;
427 qq_data *qd; 432 qq_data *qd;
428 433
448 453
449 return 1; 454 return 1;
450 } 455 }
451 456
452 /* send a chat msg to a QQ Qun */ 457 /* send a chat msg to a QQ Qun */
453 static int _qq_chat_send(PurpleConnection *gc, int channel, const char *message, PurpleMessageFlags flags) 458 static int qq_chat_send(PurpleConnection *gc, int channel, const char *message, PurpleMessageFlags flags)
454 { 459 {
455 gchar *msg, *msg_with_qq_smiley; 460 gchar *msg, *msg_with_qq_smiley;
456 qq_group *group; 461 qq_group *group;
457 462
458 g_return_val_if_fail(message != NULL, -1); 463 g_return_val_if_fail(message != NULL, -1);
559 g_string_append_printf(info, _("<b>Last Refresh</b>: %s<br>\n"), ctime(&qd->online_last_update)); 564 g_string_append_printf(info, _("<b>Last Refresh</b>: %s<br>\n"), ctime(&qd->online_last_update));
560 565
561 g_string_append(info, "<hr>"); 566 g_string_append(info, "<hr>");
562 567
563 g_string_append_printf(info, _("<b>Server</b>: %s<br>\n"), qd->curr_server); 568 g_string_append_printf(info, _("<b>Server</b>: %s<br>\n"), qd->curr_server);
564 g_string_append_printf(info, _("<b>Client Version</b>: %s<br>\n"), qq_get_ver_desc(qd->client_version)); 569 g_string_append_printf(info, _("<b>Client Tag</b>: %s<br>\n"), qq_get_ver_desc(qd->client_tag));
565 g_string_append_printf(info, _("<b>Connection Mode</b>: %s<br>\n"), qd->use_tcp ? "TCP" : "UDP"); 570 g_string_append_printf(info, _("<b>Connection Mode</b>: %s<br>\n"), qd->use_tcp ? "TCP" : "UDP");
566 g_string_append_printf(info, _("<b>My Internet IP</b>: %s<br>\n"), inet_ntoa(qd->my_ip)); 571 g_string_append_printf(info, _("<b>My Internet IP</b>: %s<br>\n"), inet_ntoa(qd->my_ip));
567 572
568 g_string_append(info, "<hr>"); 573 g_string_append(info, "<hr>");
569 g_string_append(info, "<i>Network Status</i><br>\n"); 574 g_string_append(info, "<i>Network Status</i><br>\n");
603 "OpenQ", FALSE, FALSE, NULL, 608 "OpenQ", FALSE, FALSE, NULL,
604 _("Create"), G_CALLBACK(qq_room_create_new), _("Cancel"), NULL, gc); 609 _("Create"), G_CALLBACK(qq_room_create_new), _("Cancel"), NULL, gc);
605 } 610 }
606 */ 611 */
607 612
608 static void _qq_menu_unsubscribe_group(PurpleBlistNode * node) 613 static void action_chat_quit(PurpleBlistNode * node)
609 { 614 {
610 PurpleChat *chat = (PurpleChat *)node; 615 PurpleChat *chat = (PurpleChat *)node;
611 PurpleConnection *gc = purple_account_get_connection(chat->account); 616 PurpleConnection *gc = purple_account_get_connection(chat->account);
612 GHashTable *components = chat -> components; 617 GHashTable *components = chat -> components;
613 618
614 g_return_if_fail(PURPLE_BLIST_NODE_IS_CHAT(node)); 619 g_return_if_fail(PURPLE_BLIST_NODE_IS_CHAT(node));
615 620
616 g_return_if_fail(components != NULL); 621 g_return_if_fail(components != NULL);
617 qq_group_exit(gc, components); 622 qq_room_quit(gc, components);
618 } 623 }
619 624
620 /* 625 static void action_chat_get_info(PurpleBlistNode * node)
621 static void _qq_menu_manage_group(PurpleBlistNode * node)
622 { 626 {
623 PurpleChat *chat = (PurpleChat *)node; 627 PurpleChat *chat = (PurpleChat *)node;
624 PurpleConnection *gc = purple_account_get_connection(chat->account); 628 PurpleConnection *gc = purple_account_get_connection(chat->account);
625 GHashTable *components = chat -> components; 629 GHashTable *components = chat -> components;
630 gchar *uid_str;
631 guint32 uid;
632 qq_group *group;
626 633
627 g_return_if_fail(PURPLE_BLIST_NODE_IS_CHAT(node)); 634 g_return_if_fail(PURPLE_BLIST_NODE_IS_CHAT(node));
628 635
629 g_return_if_fail(components != NULL); 636 g_return_if_fail(components != NULL);
630 qq_group_manage_group(gc, components); 637
631 } 638 uid_str = g_hash_table_lookup(components, QQ_ROOM_KEY_INTERNAL_ID);
632 */ 639 uid = strtol(uid_str, NULL, 10);
640
641 group = qq_room_search_id(gc, uid);
642 if (group == NULL) {
643 return;
644 }
645 g_return_if_fail(group->id > 0);
646
647 qq_send_room_cmd_mess(gc, QQ_ROOM_CMD_GET_INFO, group->id, NULL, 0,
648 QQ_CMD_CLASS_UPDATE_ROOM, QQ_ROOM_INFO_DISPLAY);
649 }
633 650
634 #if 0 651 #if 0
635 /* TODO: re-enable this */ 652 /* TODO: re-enable this */
636 static void _qq_menu_send_file(PurpleBlistNode * node, gpointer ignored) 653 static void _qq_menu_send_file(PurpleBlistNode * node, gpointer ignored)
637 { 654 {
688 705
689 return m; 706 return m;
690 } 707 }
691 708
692 /* chat-related (QQ Qun) menu shown up with right-click */ 709 /* chat-related (QQ Qun) menu shown up with right-click */
693 static GList *_qq_chat_menu(PurpleBlistNode *node) 710 static GList *qq_chat_menu(PurpleBlistNode *node)
694 { 711 {
695 GList *m; 712 GList *m;
696 PurpleMenuAction *act; 713 PurpleMenuAction *act;
697 714
698 m = NULL; 715 m = NULL;
699 act = purple_menu_action_new(_("Leave the QQ Qun"), PURPLE_CALLBACK(_qq_menu_unsubscribe_group), NULL, NULL); 716 act = purple_menu_action_new(_("Get Info"), PURPLE_CALLBACK(action_chat_get_info), NULL, NULL);
700 m = g_list_append(m, act); 717 m = g_list_append(m, act);
701 718
702 /* TODO: enable this 719 act = purple_menu_action_new(_("Quit Qun"), PURPLE_CALLBACK(action_chat_quit), NULL, NULL);
703 act = purple_menu_action_new(_("Show Details"), PURPLE_CALLBACK(_qq_menu_manage_group), NULL, NULL); 720 m = g_list_append(m, act);
704 m = g_list_append(m, act);
705 */
706
707 return m; 721 return m;
708 } 722 }
709 723
710 /* buddy-related menu shown up with right-click */ 724 /* buddy-related menu shown up with right-click */
711 static GList *_qq_buddy_menu(PurpleBlistNode * node) 725 static GList *qq_buddy_menu(PurpleBlistNode * node)
712 { 726 {
713 GList *m; 727 GList *m;
714 PurpleMenuAction *act; 728 PurpleMenuAction *act;
715 729
716 if(PURPLE_BLIST_NODE_IS_CHAT(node)) 730 if(PURPLE_BLIST_NODE_IS_CHAT(node))
717 return _qq_chat_menu(node); 731 return qq_chat_menu(node);
718 732
719 m = NULL; 733 m = NULL;
720 734
721 act = purple_menu_action_new(_("Remove both side"), PURPLE_CALLBACK(qq_remove_buddy_and_me), NULL, NULL); /* add NULL by gfhuang */ 735 act = purple_menu_action_new(_("Remove both side"), PURPLE_CALLBACK(qq_remove_buddy_and_me), NULL, NULL); /* add NULL by gfhuang */
722 m = g_list_append(m, act); 736 m = g_list_append(m, act);
730 #endif 744 #endif
731 745
732 return m; 746 return m;
733 } 747 }
734 748
735 /* convert chat nickname to qq-uid to get this buddy info */ 749 /* convert chat nickname to uid to get this buddy info */
736 /* who is the nickname of buddy in QQ chat-room (Qun) */ 750 /* who is the nickname of buddy in QQ chat-room (Qun) */
737 static void _qq_get_chat_buddy_info(PurpleConnection *gc, gint channel, const gchar *who) 751 static void qq_get_chat_buddy_info(PurpleConnection *gc, gint channel, const gchar *who)
738 { 752 {
739 gchar *purple_name; 753 gchar *purple_name;
740 g_return_if_fail(who != NULL); 754 g_return_if_fail(who != NULL);
741 755
742 purple_name = chat_name_to_purple_name(who); 756 purple_name = chat_name_to_purple_name(who);
743 if (purple_name != NULL) 757 if (purple_name != NULL)
744 qq_show_buddy_info(gc, purple_name); 758 qq_show_buddy_info(gc, purple_name);
745 } 759 }
746 760
747 /* convert chat nickname to qq-uid to invite individual IM to buddy */ 761 /* convert chat nickname to uid to invite individual IM to buddy */
748 /* who is the nickname of buddy in QQ chat-room (Qun) */ 762 /* who is the nickname of buddy in QQ chat-room (Qun) */
749 static gchar *_qq_get_chat_buddy_real_name(PurpleConnection *gc, gint channel, const gchar *who) 763 static gchar *qq_get_chat_buddy_real_name(PurpleConnection *gc, gint channel, const gchar *who)
750 { 764 {
751 g_return_val_if_fail(who != NULL, NULL); 765 g_return_val_if_fail(who != NULL, NULL);
752 return chat_name_to_purple_name(who); 766 return chat_name_to_purple_name(who);
753 } 767 }
754 768
756 { 770 {
757 OPT_PROTO_CHAT_TOPIC | OPT_PROTO_USE_POINTSIZE, 771 OPT_PROTO_CHAT_TOPIC | OPT_PROTO_USE_POINTSIZE,
758 NULL, /* user_splits */ 772 NULL, /* user_splits */
759 NULL, /* protocol_options */ 773 NULL, /* protocol_options */
760 {"png", 96, 96, 96, 96, 0, PURPLE_ICON_SCALE_SEND}, /* icon_spec */ 774 {"png", 96, 96, 96, 96, 0, PURPLE_ICON_SCALE_SEND}, /* icon_spec */
761 _qq_list_icon, /* list_icon */ 775 qq_list_icon, /* list_icon */
762 _qq_list_emblem, /* list_emblems */ 776 qq_list_emblem, /* list_emblems */
763 _qq_status_text, /* status_text */ 777 qq_status_text, /* status_text */
764 _qq_tooltip_text, /* tooltip_text */ 778 qq_tooltip_text, /* tooltip_text */
765 _qq_away_states, /* away_states */ 779 qq_status_types, /* away_states */
766 _qq_buddy_menu, /* blist_node_menu */ 780 qq_buddy_menu, /* blist_node_menu */
767 qq_chat_info, /* chat_info */ 781 qq_chat_info, /* chat_info */
768 qq_chat_info_defaults, /* chat_info_defaults */ 782 qq_chat_info_defaults, /* chat_info_defaults */
769 qq_login, /* open */ 783 qq_login, /* open */
770 qq_close, /* close */ 784 qq_close, /* close */
771 _qq_send_im, /* send_im */ 785 qq_send_im, /* send_im */
772 NULL, /* set_info */ 786 NULL, /* set_info */
773 NULL, /* send_typing */ 787 NULL, /* send_typing */
774 qq_show_buddy_info, /* get_info */ 788 qq_show_buddy_info, /* get_info */
775 _qq_change_status, /* change status */ 789 qq_change_status, /* change status */
776 NULL, /* set_idle */ 790 NULL, /* set_idle */
777 NULL, /* change_passwd */ 791 NULL, /* change_passwd */
778 qq_add_buddy, /* add_buddy */ 792 qq_add_buddy, /* add_buddy */
779 NULL, /* add_buddies */ 793 NULL, /* add_buddies */
780 qq_remove_buddy, /* remove_buddy */ 794 qq_remove_buddy, /* remove_buddy */
788 NULL, /* reject chat invite */ 802 NULL, /* reject chat invite */
789 NULL, /* get_chat_name */ 803 NULL, /* get_chat_name */
790 NULL, /* chat_invite */ 804 NULL, /* chat_invite */
791 NULL, /* chat_leave */ 805 NULL, /* chat_leave */
792 NULL, /* chat_whisper */ 806 NULL, /* chat_whisper */
793 _qq_chat_send, /* chat_send */ 807 qq_chat_send, /* chat_send */
794 NULL, /* keepalive */ 808 NULL, /* keepalive */
795 NULL, /* register_user */ 809 NULL, /* register_user */
796 _qq_get_chat_buddy_info, /* get_cb_info */ 810 qq_get_chat_buddy_info, /* get_cb_info */
797 NULL, /* get_cb_away */ 811 NULL, /* get_cb_away */
798 NULL, /* alias_buddy */ 812 NULL, /* alias_buddy */
799 qq_change_buddys_group, /* group_buddy */ 813 qq_change_buddys_group, /* group_buddy */
800 NULL, /* rename_group */ 814 NULL, /* rename_group */
801 NULL, /* buddy_free */ 815 NULL, /* buddy_free */
802 NULL, /* convo_closed */ 816 NULL, /* convo_closed */
803 NULL, /* normalize */ 817 NULL, /* normalize */
804 qq_set_buddy_icon, /* set_buddy_icon */ 818 qq_set_buddy_icon, /* set_buddy_icon */
805 NULL, /* remove_group */ 819 NULL, /* remove_group */
806 _qq_get_chat_buddy_real_name, /* get_cb_real_name */ 820 qq_get_chat_buddy_real_name, /* get_cb_real_name */
807 NULL, /* set_chat_topic */ 821 NULL, /* set_chat_topic */
808 NULL, /* find_blist_chat */ 822 NULL, /* find_blist_chat */
809 qq_roomlist_get_list, /* roomlist_get_list */ 823 qq_roomlist_get_list, /* roomlist_get_list */
810 qq_roomlist_cancel, /* roomlist_cancel */ 824 qq_roomlist_cancel, /* roomlist_cancel */
811 NULL, /* roomlist_expand_category */ 825 NULL, /* roomlist_expand_category */
906 kvp = g_new0(PurpleKeyValuePair, 1); 920 kvp = g_new0(PurpleKeyValuePair, 1);
907 kvp->key = g_strdup(_("QQ2007")); 921 kvp->key = g_strdup(_("QQ2007"));
908 kvp->value = g_strdup("qq2007"); 922 kvp->value = g_strdup("qq2007");
909 version_kv_list = g_list_append(version_kv_list, kvp); 923 version_kv_list = g_list_append(version_kv_list, kvp);
910 924
925 kvp = g_new0(PurpleKeyValuePair, 1);
926 kvp->key = g_strdup(_("QQ2008"));
927 kvp->value = g_strdup("qq2008");
928 version_kv_list = g_list_append(version_kv_list, kvp);
929
911 option = purple_account_option_list_new(_("Client Version"), "client_version", version_kv_list); 930 option = purple_account_option_list_new(_("Client Version"), "client_version", version_kv_list);
912 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); 931 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
913 #endif 932 #endif
914 933
915 option = purple_account_option_bool_new(_("Connect by TCP"), "use_tcp", TRUE); 934 option = purple_account_option_bool_new(_("Connect by TCP"), "use_tcp", TRUE);