Mercurial > pidgin.yaz
comparison libpurple/protocols/qq/group_search.c @ 15374:5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
author | Sean Egan <seanegan@gmail.com> |
---|---|
date | Sat, 20 Jan 2007 02:32:10 +0000 |
parents | |
children | 32c366eeeb99 |
comparison
equal
deleted
inserted
replaced
15373:f79e0f4df793 | 15374:5fe8042783c1 |
---|---|
1 /** | |
2 * @file group_search.c | |
3 * | |
4 * gaim | |
5 * | |
6 * Gaim is the legal property of its developers, whose names are too numerous | |
7 * to list here. Please refer to the COPYRIGHT file distributed with this | |
8 * source distribution. | |
9 * | |
10 * This program is free software; you can redistribute it and/or modify | |
11 * it under the terms of the GNU General Public License as published by | |
12 * the Free Software Foundation; either version 2 of the License, or | |
13 * (at your option) any later version. | |
14 * | |
15 * This program is distributed in the hope that it will be useful, | |
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 * GNU General Public License for more details. | |
19 * | |
20 * You should have received a copy of the GNU General Public License | |
21 * along with this program; if not, write to the Free Software | |
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
23 */ | |
24 | |
25 #include "debug.h" | |
26 | |
27 #include "char_conv.h" | |
28 #include "group_find.h" | |
29 #include "group_free.h" | |
30 #include "group_internal.h" | |
31 #include "group_join.h" | |
32 #include "group_network.h" | |
33 #include "group_search.h" | |
34 #include "utils.h" | |
35 | |
36 enum { | |
37 QQ_GROUP_SEARCH_TYPE_BY_ID = 0x01, | |
38 QQ_GROUP_SEARCH_TYPE_DEMO = 0x02 | |
39 }; | |
40 | |
41 /* send packet to search for qq_group */ | |
42 void qq_send_cmd_group_search_group(GaimConnection *gc, guint32 external_group_id) | |
43 { | |
44 guint8 *raw_data, *cursor, type; | |
45 gint bytes, data_len; | |
46 | |
47 data_len = 6; | |
48 raw_data = g_newa(guint8, data_len); | |
49 cursor = raw_data; | |
50 type = (external_group_id == 0x00000000) ? QQ_GROUP_SEARCH_TYPE_DEMO : QQ_GROUP_SEARCH_TYPE_BY_ID; | |
51 | |
52 bytes = 0; | |
53 bytes += create_packet_b(raw_data, &cursor, QQ_GROUP_CMD_SEARCH_GROUP); | |
54 bytes += create_packet_b(raw_data, &cursor, type); | |
55 bytes += create_packet_dw(raw_data, &cursor, external_group_id); | |
56 | |
57 if (bytes != data_len) | |
58 gaim_debug(GAIM_DEBUG_ERROR, "QQ", | |
59 "Fail create packet for %s\n", qq_group_cmd_get_desc(QQ_GROUP_CMD_SEARCH_GROUP)); | |
60 else | |
61 qq_send_group_cmd(gc, NULL, raw_data, data_len); | |
62 } | |
63 | |
64 static void _qq_setup_roomlist(qq_data *qd, qq_group *group) | |
65 { | |
66 GaimRoomlistRoom *room; | |
67 gchar field[11]; | |
68 | |
69 room = gaim_roomlist_room_new(GAIM_ROOMLIST_ROOMTYPE_ROOM, group->group_name_utf8, NULL); | |
70 g_snprintf(field, sizeof(field), "%d", group->external_group_id); | |
71 gaim_roomlist_room_add_field(qd->roomlist, room, field); | |
72 g_snprintf(field, sizeof(field), "%d", group->creator_uid); | |
73 gaim_roomlist_room_add_field(qd->roomlist, room, field); | |
74 gaim_roomlist_room_add_field(qd->roomlist, room, group->group_desc_utf8); | |
75 g_snprintf(field, sizeof(field), "%d", group->internal_group_id); | |
76 gaim_roomlist_room_add_field(qd->roomlist, room, field); | |
77 g_snprintf(field, sizeof(field), "%d", group->group_type); | |
78 gaim_roomlist_room_add_field(qd->roomlist, room, field); | |
79 g_snprintf(field, sizeof(field), "%d", group->auth_type); | |
80 gaim_roomlist_room_add_field(qd->roomlist, room, field); | |
81 g_snprintf(field, sizeof(field), "%d", group->group_category); | |
82 gaim_roomlist_room_add_field(qd->roomlist, room, field); | |
83 gaim_roomlist_room_add_field(qd->roomlist, room, group->group_name_utf8); | |
84 gaim_roomlist_room_add(qd->roomlist, room); | |
85 | |
86 gaim_roomlist_set_in_progress(qd->roomlist, FALSE); | |
87 } | |
88 | |
89 /* process group cmd reply "search group" */ | |
90 void qq_process_group_cmd_search_group(guint8 *data, guint8 **cursor, gint len, GaimConnection *gc) | |
91 { | |
92 guint8 search_type; | |
93 guint16 unknown; | |
94 gint bytes, pascal_len; | |
95 qq_data *qd; | |
96 qq_group *group; | |
97 GSList *pending_id; | |
98 | |
99 g_return_if_fail(data != NULL && len > 0); | |
100 qd = (qq_data *) gc->proto_data; | |
101 | |
102 read_packet_b(data, cursor, len, &search_type); | |
103 group = g_newa(qq_group, 1); | |
104 | |
105 /* now it starts with group_info_entry */ | |
106 bytes = 0; | |
107 bytes += read_packet_dw(data, cursor, len, &(group->internal_group_id)); | |
108 bytes += read_packet_dw(data, cursor, len, &(group->external_group_id)); | |
109 bytes += read_packet_b(data, cursor, len, &(group->group_type)); | |
110 bytes += read_packet_w(data, cursor, len, &(unknown)); | |
111 bytes += read_packet_w(data, cursor, len, &(unknown)); | |
112 bytes += read_packet_dw(data, cursor, len, &(group->creator_uid)); | |
113 bytes += read_packet_w(data, cursor, len, &(unknown)); | |
114 bytes += read_packet_w(data, cursor, len, &(unknown)); | |
115 bytes += read_packet_w(data, cursor, len, &(unknown)); | |
116 bytes += read_packet_dw(data, cursor, len, &(group->group_category)); | |
117 pascal_len = convert_as_pascal_string(*cursor, &(group->group_name_utf8), QQ_CHARSET_DEFAULT); | |
118 bytes += pascal_len; | |
119 *cursor += pascal_len; | |
120 bytes += read_packet_w(data, cursor, len, &(unknown)); | |
121 bytes += read_packet_b(data, cursor, len, &(group->auth_type)); | |
122 pascal_len = convert_as_pascal_string(*cursor, &(group->group_desc_utf8), QQ_CHARSET_DEFAULT); | |
123 bytes += pascal_len; | |
124 *cursor += pascal_len; | |
125 /* end of one qq_group */ | |
126 if(*cursor != (data + len)) { | |
127 gaim_debug(GAIM_DEBUG_ERROR, "QQ", | |
128 "group_cmd_search_group: Dangerous error! maybe protocol changed, notify developers!"); | |
129 } | |
130 | |
131 pending_id = qq_get_pending_id(qd->joining_groups, group->external_group_id); | |
132 if (pending_id != NULL) { | |
133 qq_set_pending_id(&qd->joining_groups, group->external_group_id, FALSE); | |
134 if (qq_group_find_by_id(gc, group->internal_group_id, QQ_INTERNAL_ID) == NULL) | |
135 qq_group_create_internal_record(gc, | |
136 group->internal_group_id, group->external_group_id, group->group_name_utf8); | |
137 qq_send_cmd_group_join_group(gc, group); | |
138 } else { | |
139 _qq_setup_roomlist(qd, group); | |
140 } | |
141 } |