Mercurial > pidgin
diff libpurple/protocols/qq/group_info.c @ 24157:1ee91ff0d5fe
2008.10.09 - ccpaging <ccpaging(at)gmail.com>
* Update 'group' protocol
* Functions of group_find, group_free, group_search merged into group_join and group_internal
* Removed group_find.c/h, group_free.c/h, group_search.c/h
author | SHiNE CsyFeK <csyfek@gmail.com> |
---|---|
date | Tue, 28 Oct 2008 16:38:16 +0000 |
parents | 3c52353b83ae |
children | 967a6efce7cf |
line wrap: on
line diff
--- a/libpurple/protocols/qq/group_info.c Tue Oct 28 16:35:06 2008 +0000 +++ b/libpurple/protocols/qq/group_info.c Tue Oct 28 16:38:16 2008 +0000 @@ -29,7 +29,6 @@ #include "char_conv.h" #include "group_im.h" -#include "group_find.h" #include "group_internal.h" #include "group_info.h" #include "buddy_list.h" @@ -51,13 +50,13 @@ /* this is done when we receive the reply to get_online_members sub_cmd * all member are set offline, and then only those in reply packets are online */ -static void set_all_offline(qq_group *group) +static void set_all_offline(qq_room_data *rmd) { GList *list; qq_buddy_data *bd; - g_return_if_fail(group != NULL); + g_return_if_fail(rmd != NULL); - list = group->members; + list = rmd->members; while (list != NULL) { bd = (qq_buddy_data *) list->data; bd->status = QQ_BUDDY_CHANGE_TO_OFFLINE; @@ -66,15 +65,20 @@ } /* send packet to get info for each group member */ -gint qq_request_room_get_buddies(PurpleConnection *gc, qq_group *group, gint update_class) +gint qq_request_room_get_buddies(PurpleConnection *gc, guint32 room_id, gint update_class) { guint8 *raw_data; gint bytes, num; GList *list; + qq_room_data *rmd; qq_buddy_data *bd; - g_return_val_if_fail(group != NULL, 0); - for (num = 0, list = group->members; list != NULL; list = list->next) { + g_return_val_if_fail(room_id > 0, 0); + + rmd = qq_room_data_find(gc, room_id); + g_return_val_if_fail(rmd != NULL, 0); + + for (num = 0, list = rmd->members; list != NULL; list = list->next) { bd = (qq_buddy_data *) list->data; if (check_update_interval(bd)) num++; @@ -89,7 +93,7 @@ bytes = 0; - list = group->members; + list = rmd->members; while (list != NULL) { bd = (qq_buddy_data *) list->data; if (check_update_interval(bd)) @@ -97,7 +101,7 @@ list = list->next; } - qq_send_room_cmd_mess(gc, QQ_ROOM_CMD_GET_BUDDIES, group->id, raw_data, bytes, + qq_send_room_cmd_mess(gc, QQ_ROOM_CMD_GET_BUDDIES, rmd->id, raw_data, bytes, update_class, 0); return num; } @@ -125,38 +129,38 @@ return g_strdup(role_desc); } -static void room_info_display(PurpleConnection *gc, qq_group *group) +static void room_info_display(PurpleConnection *gc, qq_room_data *rmd) { PurpleNotifyUserInfo *room_info; gchar *utf8_value; - g_return_if_fail(group != NULL && group->id > 0); + g_return_if_fail(rmd != NULL && rmd->id > 0); room_info = purple_notify_user_info_new(); - purple_notify_user_info_add_pair(room_info, _("Title"), group->title_utf8); - purple_notify_user_info_add_pair(room_info, _("Notice"), group->notice_utf8); - purple_notify_user_info_add_pair(room_info, _("Detail"), group->desc_utf8); + purple_notify_user_info_add_pair(room_info, _("Title"), rmd->title_utf8); + purple_notify_user_info_add_pair(room_info, _("Notice"), rmd->notice_utf8); + purple_notify_user_info_add_pair(room_info, _("Detail"), rmd->desc_utf8); purple_notify_user_info_add_section_break(room_info); - utf8_value = g_strdup_printf(("%d"), group->creator_uid); + utf8_value = g_strdup_printf(("%d"), rmd->creator_uid); purple_notify_user_info_add_pair(room_info, _("Creator"), utf8_value); g_free(utf8_value); - utf8_value = get_role_desc(group->my_role); + utf8_value = get_role_desc(rmd->my_role); purple_notify_user_info_add_pair(room_info, _("About me"), utf8_value); g_free(utf8_value); - utf8_value = g_strdup_printf(("%d"), group->category); + utf8_value = g_strdup_printf(("%d"), rmd->category); purple_notify_user_info_add_pair(room_info, _("Category"), utf8_value); g_free(utf8_value); - utf8_value = g_strdup_printf(("%d"), group->auth_type); + utf8_value = g_strdup_printf(("%d"), rmd->auth_type); purple_notify_user_info_add_pair(room_info, _("Authorize"), utf8_value); g_free(utf8_value); - utf8_value = g_strdup_printf(("%d"), group->ext_id); + utf8_value = g_strdup_printf(("%d"), rmd->ext_id); purple_notify_userinfo(gc, utf8_value, room_info, NULL, NULL); g_free(utf8_value); @@ -165,9 +169,10 @@ void qq_process_room_cmd_get_info(guint8 *data, gint data_len, guint32 action, PurpleConnection *gc) { - qq_group *group; + qq_data *qd; + qq_room_data *rmd; qq_buddy_data *bd; - qq_data *qd; + PurpleChat *chat; PurpleConversation *conv; guint8 organization, role; guint16 unknown, max_members; @@ -190,20 +195,18 @@ bytes += qq_get32(&ext_id, data + bytes); g_return_if_fail(ext_id > 0); - if (action == QQ_ROOM_INFO_CREATE ) { - qq_group_create_internal_record(gc, id, ext_id, NULL); - } + chat = qq_room_find_or_new(gc, id, ext_id); + g_return_if_fail(chat != NULL); + rmd = qq_room_data_find(gc, id); + g_return_if_fail(rmd != NULL); - group = qq_room_search_id(gc, id); - g_return_if_fail(group != NULL); - - bytes += qq_get8(&(group->type8), data + bytes); + bytes += qq_get8(&(rmd->type8), data + bytes); bytes += qq_get32(&unknown4, data + bytes); /* unknown 4 bytes */ - bytes += qq_get32(&(group->creator_uid), data + bytes); - bytes += qq_get8(&(group->auth_type), data + bytes); + bytes += qq_get32(&(rmd->creator_uid), data + bytes); + bytes += qq_get8(&(rmd->auth_type), data + bytes); bytes += qq_get32(&unknown4, data + bytes); /* oldCategory */ bytes += qq_get16(&unknown, data + bytes); - bytes += qq_get32(&(group->category), data + bytes); + bytes += qq_get32(&(rmd->category), data + bytes); bytes += qq_get16(&max_members, data + bytes); bytes += qq_get8(&unknown1, data + bytes); /* the following, while Eva: @@ -212,7 +215,7 @@ * qunDestLen(qunDestcontent)) */ bytes += qq_get8(&unknown1, data + bytes); purple_debug_info("QQ", "type=%u creatorid=%u category=%u maxmembers=%u\n", - group->type8, group->creator_uid, group->category, max_members); + rmd->type8, rmd->creator_uid, rmd->category, max_members); if (qd->client_version >= 2007) { /* skip 7 bytes unknow in qq2007 0x(00 00 01 00 00 00 fc)*/ @@ -220,13 +223,13 @@ } /* qq_show_packet("Room Info", data + bytes, data_len - bytes); */ /* strlen + <str content> */ - bytes += qq_get_vstr(&(group->title_utf8), QQ_CHARSET_DEFAULT, data + bytes); + bytes += qq_get_vstr(&(rmd->title_utf8), QQ_CHARSET_DEFAULT, data + bytes); bytes += qq_get16(&unknown, data + bytes); /* 0x0000 */ bytes += qq_get_vstr(¬ice, QQ_CHARSET_DEFAULT, data + bytes); - bytes += qq_get_vstr(&(group->desc_utf8), QQ_CHARSET_DEFAULT, data + bytes); + bytes += qq_get_vstr(&(rmd->desc_utf8), QQ_CHARSET_DEFAULT, data + bytes); purple_debug_info("QQ", "room [%s] notice [%s] desc [%s] unknow 0x%04X\n", - group->title_utf8, notice, group->desc_utf8, unknown); + rmd->title_utf8, notice, rmd->desc_utf8, unknown); num = 0; /* now comes the member list separated by 0x00 */ @@ -242,7 +245,7 @@ } #endif - bd = qq_group_find_or_add_member(gc, group, member_uid); + bd = qq_room_buddy_find_or_new(gc, rmd, member_uid); if (bd != NULL) bd->role = role; } @@ -251,30 +254,30 @@ "group_cmd_get_group_info: Dangerous error! maybe protocol changed, notify me!"); } - purple_debug_info("QQ", "group \"%s\" has %d members\n", group->title_utf8, num); + purple_debug_info("QQ", "group \"%s\" has %d members\n", rmd->title_utf8, num); - if (group->creator_uid == qd->uid) - group->my_role = QQ_ROOM_ROLE_ADMIN; + if (rmd->creator_uid == qd->uid) + rmd->my_role = QQ_ROOM_ROLE_ADMIN; /* filter \r\n in notice */ qq_filter_str(notice); - group->notice_utf8 = strdup(notice); + rmd->notice_utf8 = strdup(notice); g_free(notice); - qq_group_refresh(gc, group); + qq_room_update_chat_info(chat, rmd); if (action == QQ_ROOM_INFO_DISPLAY) { - room_info_display(gc, group); + room_info_display(gc, rmd); } conv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_CHAT, - group->title_utf8, purple_connection_get_account(gc)); + rmd->title_utf8, purple_connection_get_account(gc)); if(NULL == conv) { - purple_debug_warning("QQ", "Conversation \"%s\" is not opened\n", group->title_utf8); + purple_debug_warning("QQ", "Conversation \"%s\" is not opened\n", rmd->title_utf8); return; } - topic_utf8 = g_strdup_printf("%d %s", group->ext_id, group->notice_utf8); + topic_utf8 = g_strdup_printf("%d %s", rmd->ext_id, rmd->notice_utf8); purple_debug_info("QQ", "Set chat topic to %s\n", topic_utf8); purple_conv_chat_set_topic(PURPLE_CONV_CHAT(conv), NULL, topic_utf8); g_free(topic_utf8); @@ -285,7 +288,7 @@ guint32 id, member_uid; guint8 unknown; gint bytes, num; - qq_group *group; + qq_room_data *rmd; qq_buddy_data *bd; g_return_if_fail(data != NULL && len > 0); @@ -300,19 +303,19 @@ bytes += qq_get8(&unknown, data + bytes); /* 0x3c ?? */ g_return_if_fail(id > 0); - group = qq_room_search_id(gc, id); - if (group == NULL) { + rmd = qq_room_data_find(gc, id); + if (rmd == NULL) { purple_debug_error("QQ", "We have no group info for internal id [%d]\n", id); return; } /* set all offline first, then update those online */ - set_all_offline(group); + set_all_offline(rmd); num = 0; while (bytes < len) { bytes += qq_get32(&member_uid, data + bytes); num++; - bd = qq_group_find_or_add_member(gc, group, member_uid); + bd = qq_room_buddy_find_or_new(gc, rmd, member_uid); if (bd != NULL) bd->status = QQ_BUDDY_ONLINE_NORMAL; } @@ -321,8 +324,8 @@ "group_cmd_get_online_members: Dangerous error! maybe protocol changed, notify developers!"); } - purple_debug_info("QQ", "Group \"%s\" has %d online members\n", group->title_utf8, num); - qq_room_conv_set_onlines(gc, group); + purple_debug_info("QQ", "Group \"%s\" has %d online members\n", rmd->title_utf8, num); + qq_room_conv_set_onlines(gc, rmd); } /* process the reply to get_members_info packet */ @@ -332,7 +335,7 @@ gint num; guint32 id, member_uid; guint16 unknown; - qq_group *group; + qq_room_data *rmd; qq_buddy_data *bd; gchar *nick; @@ -344,15 +347,15 @@ bytes += qq_get32(&id, data + bytes); g_return_if_fail(id > 0); - group = qq_room_search_id(gc, id); - g_return_if_fail(group != NULL); + rmd = qq_room_data_find(gc, id); + g_return_if_fail(rmd != NULL); num = 0; /* now starts the member info, as get buddy list reply */ while (bytes < len) { bytes += qq_get32(&member_uid, data + bytes); g_return_if_fail(member_uid > 0); - bd = qq_group_find_member_by_uid(group, member_uid); + bd = qq_room_buddy_find_or_new(gc, rmd, member_uid); g_return_if_fail(bd != NULL); num++; @@ -381,9 +384,9 @@ purple_debug_error("QQ", "group_cmd_get_members_info: Dangerous error! maybe protocol changed, notify developers!"); } - purple_debug_info("QQ", "Group \"%s\" obtained %d member info\n", group->title_utf8, num); + purple_debug_info("QQ", "Group \"%s\" obtained %d member info\n", rmd->title_utf8, num); - group->is_got_buddies = TRUE; - qq_room_conv_set_onlines(gc, group); + rmd->is_got_buddies = TRUE; + qq_room_conv_set_onlines(gc, rmd); }