Mercurial > pidgin.yaz
comparison libpurple/protocols/qq/qq.c @ 24568:af645355ea20
Code clean
author | Hu Yong <ccpaging@gmail.com> |
---|---|
date | Tue, 11 Nov 2008 07:17:48 +0000 |
parents | d971d5369b43 |
children | 807ff8a4b47b |
comparison
equal
deleted
inserted
replaced
24567:7aecbc973329 | 24568:af645355ea20 |
---|---|
92 static void server_list_create(PurpleAccount *account) | 92 static void server_list_create(PurpleAccount *account) |
93 { | 93 { |
94 PurpleConnection *gc; | 94 PurpleConnection *gc; |
95 qq_data *qd; | 95 qq_data *qd; |
96 PurpleProxyInfo *gpi; | 96 PurpleProxyInfo *gpi; |
97 const gchar *user_server; | 97 const gchar *custom_server; |
98 | 98 |
99 gc = purple_account_get_connection(account); | 99 gc = purple_account_get_connection(account); |
100 g_return_if_fail(gc != NULL && gc->proto_data != NULL); | 100 g_return_if_fail(gc != NULL && gc->proto_data != NULL); |
101 qd = gc->proto_data; | 101 qd = gc->proto_data; |
102 | 102 |
103 gpi = purple_proxy_get_setup(account); | 103 gpi = purple_proxy_get_setup(account); |
104 | 104 |
105 qd->use_tcp = purple_account_get_bool(account, "use_tcp", TRUE); | 105 qd->use_tcp = purple_account_get_bool(account, "use_tcp", TRUE); |
106 | 106 |
107 user_server = purple_account_get_string(account, "server", NULL); | 107 custom_server = purple_account_get_string(account, "server", NULL); |
108 purple_debug_info("QQ", "Select server '%s'\n", user_server); | 108 purple_debug_info("QQ", "Select server '%s'\n", custom_server); |
109 if ( (user_server != NULL && strlen(user_server) > 0) && strcasecmp(user_server, "auto") != 0) { | 109 if ( (custom_server != NULL && strlen(custom_server) > 0) && strcasecmp(custom_server, "auto") != 0) { |
110 qd->servers = g_list_append(qd->servers, g_strdup(user_server)); | 110 qd->servers = g_list_append(qd->servers, g_strdup(custom_server)); |
111 return; | 111 return; |
112 } | 112 } |
113 | 113 |
114 if (qd->use_tcp) { | 114 if (qd->use_tcp) { |
115 qd->servers = server_list_build('T'); | 115 qd->servers = server_list_build('T'); |
438 static void qq_change_status(PurpleAccount *account, PurpleStatus *status) | 438 static void qq_change_status(PurpleAccount *account, PurpleStatus *status) |
439 { | 439 { |
440 PurpleConnection *gc = purple_account_get_connection(account); | 440 PurpleConnection *gc = purple_account_get_connection(account); |
441 | 441 |
442 qq_request_change_status(gc, 0); | 442 qq_request_change_status(gc, 0); |
443 } | |
444 | |
445 static void qq_add_deny(PurpleConnection *gc, const char *who) | |
446 { | |
447 qq_data *qd; | |
448 g_return_if_fail(NULL != gc && NULL != gc->proto_data); | |
449 | |
450 qd = (qq_data *) gc->proto_data; | |
451 if (!qd->is_login) | |
452 return; | |
453 | |
454 if (!who || who[0] == '\0') | |
455 return; | |
456 | |
457 purple_debug_info("QQ", "Add deny for %s\n", who); | |
458 } | |
459 | |
460 static void qq_rem_deny(PurpleConnection *gc, const char *who) | |
461 { | |
462 qq_data *qd; | |
463 g_return_if_fail(NULL != gc && NULL != gc->proto_data); | |
464 | |
465 qd = (qq_data *) gc->proto_data; | |
466 if (!qd->is_login) | |
467 return; | |
468 | |
469 if (!who || who[0] == '\0') | |
470 return; | |
471 | |
472 purple_debug_info("QQ", "Rem deny for %s\n", who); | |
473 } | |
474 | |
475 static void qq_set_permit_deny(PurpleConnection *gc) | |
476 { | |
477 PurpleAccount *account; | |
478 GSList *deny; | |
479 | |
480 purple_debug_info("QQ", "Set permit deny\n"); | |
481 account = purple_connection_get_account(gc); | |
482 switch (account->perm_deny) | |
483 { | |
484 case PURPLE_PRIVACY_ALLOW_ALL: | |
485 for (deny = account->deny; deny; deny = deny->next) | |
486 qq_rem_deny(gc, deny->data); | |
487 break; | |
488 | |
489 case PURPLE_PRIVACY_ALLOW_BUDDYLIST: | |
490 case PURPLE_PRIVACY_ALLOW_USERS: | |
491 case PURPLE_PRIVACY_DENY_USERS: | |
492 case PURPLE_PRIVACY_DENY_ALL: | |
493 for (deny = account->deny; deny; deny = deny->next) | |
494 qq_add_deny(gc, deny->data); | |
495 break; | |
496 } | |
497 } | |
498 | |
499 /* IMPORTANT: PurpleConvImFlags -> PurpleMessageFlags */ | |
500 /* send an instant msg to a buddy */ | |
501 static gint qq_send_im(PurpleConnection *gc, const gchar *who, const gchar *message, PurpleMessageFlags flags) | |
502 { | |
503 gint type, uid_to; | |
504 gchar *msg, *msg_with_qq_smiley; | |
505 qq_data *qd; | |
506 | |
507 g_return_val_if_fail(who != NULL, -1); | |
508 | |
509 qd = (qq_data *) gc->proto_data; | |
510 | |
511 g_return_val_if_fail(strlen(message) <= QQ_MSG_IM_MAX, -E2BIG); | |
512 | |
513 type = (flags == PURPLE_MESSAGE_AUTO_RESP ? QQ_IM_AUTO_REPLY : QQ_IM_TEXT); | |
514 uid_to = purple_name_to_uid(who); | |
515 | |
516 /* if msg is to myself, bypass the network */ | |
517 if (uid_to == qd->uid) { | |
518 serv_got_im(gc, who, message, flags, time(NULL)); | |
519 } else { | |
520 msg = utf8_to_qq(message, QQ_CHARSET_DEFAULT); | |
521 msg_with_qq_smiley = purple_smiley_to_qq(msg); | |
522 qq_request_send_im(gc, uid_to, msg_with_qq_smiley, type); | |
523 g_free(msg); | |
524 g_free(msg_with_qq_smiley); | |
525 } | |
526 | |
527 return 1; | |
528 } | |
529 | |
530 /* send a chat msg to a QQ Qun */ | |
531 static int qq_chat_send(PurpleConnection *gc, int id, const char *message, PurpleMessageFlags flags) | |
532 { | |
533 gchar *msg, *msg_with_qq_smiley; | |
534 guint32 room_id = id; | |
535 | |
536 g_return_val_if_fail(message != NULL, -1); | |
537 g_return_val_if_fail(strlen(message) <= QQ_MSG_IM_MAX, -E2BIG); | |
538 | |
539 purple_debug_info("QQ_MESG", "Send qun mesg in utf8: %s\n", message); | |
540 msg = utf8_to_qq(message, QQ_CHARSET_DEFAULT); | |
541 msg_with_qq_smiley = purple_smiley_to_qq(msg); | |
542 qq_request_room_send_im(gc, room_id, msg_with_qq_smiley); | |
543 g_free(msg); | |
544 g_free(msg_with_qq_smiley); | |
545 | |
546 return 1; | |
547 } | 443 } |
548 | 444 |
549 /* send packet to get who's detailed information */ | 445 /* send packet to get who's detailed information */ |
550 static void qq_show_buddy_info(PurpleConnection *gc, const gchar *who) | 446 static void qq_show_buddy_info(PurpleConnection *gc, const gchar *who) |
551 { | 447 { |
807 g_return_if_fail(PURPLE_BLIST_NODE_IS_CHAT(node)); | 703 g_return_if_fail(PURPLE_BLIST_NODE_IS_CHAT(node)); |
808 | 704 |
809 g_return_if_fail(components != NULL); | 705 g_return_if_fail(components != NULL); |
810 | 706 |
811 num_str = g_hash_table_lookup(components, QQ_ROOM_KEY_INTERNAL_ID); | 707 num_str = g_hash_table_lookup(components, QQ_ROOM_KEY_INTERNAL_ID); |
812 room_id = strtol(num_str, NULL, 10); | 708 room_id = strtoul(num_str, NULL, 10); |
813 g_return_if_fail(room_id != 0); | 709 g_return_if_fail(room_id != 0); |
814 | 710 |
815 qq_room_quit(gc, room_id); | 711 qq_room_quit(gc, room_id); |
816 } | 712 } |
817 | 713 |
826 g_return_if_fail(PURPLE_BLIST_NODE_IS_CHAT(node)); | 722 g_return_if_fail(PURPLE_BLIST_NODE_IS_CHAT(node)); |
827 | 723 |
828 g_return_if_fail(components != NULL); | 724 g_return_if_fail(components != NULL); |
829 | 725 |
830 num_str = g_hash_table_lookup(components, QQ_ROOM_KEY_INTERNAL_ID); | 726 num_str = g_hash_table_lookup(components, QQ_ROOM_KEY_INTERNAL_ID); |
831 room_id = strtol(num_str, NULL, 10); | 727 room_id = strtoul(num_str, NULL, 10); |
832 g_return_if_fail(room_id != 0); | 728 g_return_if_fail(room_id != 0); |
833 | 729 |
834 qq_send_room_cmd_mess(gc, QQ_ROOM_CMD_GET_INFO, room_id, NULL, 0, | 730 qq_send_room_cmd_mess(gc, QQ_ROOM_CMD_GET_INFO, room_id, NULL, 0, |
835 0, QQ_ROOM_INFO_DISPLAY); | 731 0, QQ_ROOM_INFO_DISPLAY); |
836 } | 732 } |
1039 qq_status_text, /* status_text */ | 935 qq_status_text, /* status_text */ |
1040 qq_tooltip_text, /* tooltip_text */ | 936 qq_tooltip_text, /* tooltip_text */ |
1041 qq_status_types, /* away_states */ | 937 qq_status_types, /* away_states */ |
1042 qq_blist_node_menu, /* blist_node_menu */ | 938 qq_blist_node_menu, /* blist_node_menu */ |
1043 qq_chat_info, /* chat_info */ | 939 qq_chat_info, /* chat_info */ |
1044 qq_chat_info_defaults, /* chat_info_defaults */ | 940 qq_chat_info_defaults, /* chat_info_defaults */ |
1045 qq_login, /* open */ | 941 qq_login, /* open */ |
1046 qq_close, /* close */ | 942 qq_close, /* close */ |
1047 qq_send_im, /* send_im */ | 943 qq_send_im, /* send_im */ |
1048 NULL, /* set_info */ | 944 NULL, /* set_info */ |
1049 NULL, /* send_typing */ | 945 NULL, /* send_typing */ |
1050 qq_show_buddy_info, /* get_info */ | 946 qq_show_buddy_info, /* get_info */ |
1051 qq_change_status, /* change status */ | 947 qq_change_status, /* change status */ |
1052 NULL, /* set_idle */ | 948 NULL, /* set_idle */ |
1053 NULL, /* change_passwd */ | 949 NULL, /* change_passwd */ |
1054 qq_add_buddy, /* add_buddy */ | 950 qq_add_buddy, /* add_buddy */ |
1055 NULL, /* add_buddies */ | 951 NULL, /* add_buddies */ |
1056 qq_remove_buddy, /* remove_buddy */ | 952 qq_remove_buddy, /* remove_buddy */ |
1057 NULL, /* remove_buddies */ | 953 NULL, /* remove_buddies */ |
1058 NULL, /* add_permit */ | 954 NULL, /* add_permit */ |
1059 qq_add_deny, /* add_deny */ | 955 NULL, /* add_deny */ |
1060 NULL, /* rem_permit */ | 956 NULL, /* rem_permit */ |
1061 NULL, /* rem_deny */ | 957 NULL, /* rem_deny */ |
1062 qq_set_permit_deny, /* set_permit_deny */ | 958 NULL, /* set_permit_deny */ |
1063 qq_group_join, /* join_chat */ | 959 qq_group_join, /* join_chat */ |
1064 NULL, /* reject chat invite */ | 960 NULL, /* reject chat invite */ |
1065 NULL, /* get_chat_name */ | 961 NULL, /* get_chat_name */ |
1066 NULL, /* chat_invite */ | 962 NULL, /* chat_invite */ |
1067 NULL, /* chat_leave */ | 963 NULL, /* chat_leave */ |
1068 NULL, /* chat_whisper */ | 964 NULL, /* chat_whisper */ |
1077 NULL, /* buddy_free */ | 973 NULL, /* buddy_free */ |
1078 NULL, /* convo_closed */ | 974 NULL, /* convo_closed */ |
1079 NULL, /* normalize */ | 975 NULL, /* normalize */ |
1080 qq_set_custom_icon, | 976 qq_set_custom_icon, |
1081 NULL, /* remove_group */ | 977 NULL, /* remove_group */ |
1082 qq_get_chat_buddy_real_name, /* get_cb_real_name */ | 978 qq_get_chat_buddy_real_name, /* get_cb_real_name */ |
1083 NULL, /* set_chat_topic */ | 979 NULL, /* set_chat_topic */ |
1084 NULL, /* find_blist_chat */ | 980 NULL, /* find_blist_chat */ |
1085 qq_roomlist_get_list, /* roomlist_get_list */ | 981 qq_roomlist_get_list, /* roomlist_get_list */ |
1086 qq_roomlist_cancel, /* roomlist_cancel */ | 982 qq_roomlist_cancel, /* roomlist_cancel */ |
1087 NULL, /* roomlist_expand_category */ | 983 NULL, /* roomlist_expand_category */ |
1088 NULL, /* can_receive_file */ | 984 NULL, /* can_receive_file */ |
1089 NULL, /* qq_send_file send_file */ | 985 NULL, /* qq_send_file send_file */ |
1090 NULL, /* new xfer */ | 986 NULL, /* new xfer */ |
1091 NULL, /* offline_message */ | 987 NULL, /* offline_message */ |
1211 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); | 1107 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); |
1212 | 1108 |
1213 purple_prefs_add_none("/plugins/prpl/qq"); | 1109 purple_prefs_add_none("/plugins/prpl/qq"); |
1214 purple_prefs_add_bool("/plugins/prpl/qq/show_status_by_icon", TRUE); | 1110 purple_prefs_add_bool("/plugins/prpl/qq/show_status_by_icon", TRUE); |
1215 purple_prefs_add_bool("/plugins/prpl/qq/show_fake_video", FALSE); | 1111 purple_prefs_add_bool("/plugins/prpl/qq/show_fake_video", FALSE); |
1216 purple_prefs_add_bool("/plugins/prpl/qq/auto_popup_conversation", FALSE); | 1112 purple_prefs_add_bool("/plugins/prpl/qq/auto_popup_conversation", TRUE); |
1217 purple_prefs_add_bool("/plugins/prpl/qq/auto_get_authorize_info", TRUE); | 1113 purple_prefs_add_bool("/plugins/prpl/qq/auto_get_authorize_info", TRUE); |
1218 purple_prefs_add_int("/plugins/prpl/qq/resend_interval", 3); | 1114 purple_prefs_add_int("/plugins/prpl/qq/resend_interval", 3); |
1219 purple_prefs_add_int("/plugins/prpl/qq/resend_times", 10); | 1115 purple_prefs_add_int("/plugins/prpl/qq/resend_times", 10); |
1220 } | 1116 } |
1221 | 1117 |