14192
|
1 /**
|
|
2 * The QQ2003C protocol plugin
|
|
3 *
|
|
4 * for gaim
|
|
5 *
|
|
6 * Copyright (C) 2004 Puzzlebird
|
|
7 *
|
|
8 * This program is free software; you can redistribute it and/or modify
|
|
9 * it under the terms of the GNU General Public License as published by
|
|
10 * the Free Software Foundation; either version 2 of the License, or
|
|
11 * (at your option) any later version.
|
|
12 *
|
|
13 * This program is distributed in the hope that it will be useful,
|
|
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
16 * GNU General Public License for more details.
|
|
17 *
|
|
18 * You should have received a copy of the GNU General Public License
|
|
19 * along with this program; if not, write to the Free Software
|
|
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
21 */
|
|
22
|
|
23 #include "debug.h"
|
|
24 #include "notify.h"
|
|
25
|
|
26 #include "char_conv.h"
|
|
27 #include "crypt.h"
|
|
28 #include "group_conv.h"
|
|
29 #include "group_find.h"
|
14404
|
30 #include "group_internal.h"
|
14192
|
31 #include "group_im.h"
|
|
32 #include "group_info.h"
|
|
33 #include "group_join.h"
|
|
34 #include "group_network.h"
|
|
35 #include "group_opt.h"
|
|
36 #include "group_search.h"
|
|
37 #include "header_info.h"
|
|
38 #include "send_core.h"
|
|
39 #include "utils.h"
|
|
40
|
|
41 enum {
|
|
42 QQ_GROUP_CMD_REPLY_OK = 0x00,
|
14404
|
43 QQ_GROUP_CMD_REPLY_SEARCH_ERROR = 0x02,
|
14192
|
44 QQ_GROUP_CMD_REPLY_NOT_MEMBER = 0x0a
|
|
45 };
|
|
46
|
|
47 const gchar *qq_group_cmd_get_desc(qq_group_cmd cmd)
|
|
48 {
|
|
49 switch (cmd) {
|
|
50 case QQ_GROUP_CMD_CREATE_GROUP:
|
|
51 return "QQ_GROUP_CMD_CREATE_GROUP";
|
|
52 case QQ_GROUP_CMD_MEMBER_OPT:
|
|
53 return "QQ_GROUP_CMD_MEMBER_OPT";
|
|
54 case QQ_GROUP_CMD_MODIFY_GROUP_INFO:
|
|
55 return "QQ_GROUP_CMD_MODIFY_GROUP_INFO";
|
|
56 case QQ_GROUP_CMD_GET_GROUP_INFO:
|
|
57 return "QQ_GROUP_CMD_GET_GROUP_INFO";
|
|
58 case QQ_GROUP_CMD_ACTIVATE_GROUP:
|
|
59 return "QQ_GROUP_CMD_ACTIVATE_GROUP";
|
|
60 case QQ_GROUP_CMD_SEARCH_GROUP:
|
|
61 return "QQ_GROUP_CMD_SEARCH_GROUP";
|
|
62 case QQ_GROUP_CMD_JOIN_GROUP:
|
|
63 return "QQ_GROUP_CMD_JOIN_GROUP";
|
|
64 case QQ_GROUP_CMD_JOIN_GROUP_AUTH:
|
|
65 return "QQ_GROUP_CMD_JOIN_GROUP_AUTH";
|
|
66 case QQ_GROUP_CMD_EXIT_GROUP:
|
|
67 return "QQ_GROUP_CMD_EXIT_GROUP";
|
|
68 case QQ_GROUP_CMD_SEND_MSG:
|
|
69 return "QQ_GROUP_CMD_SEND_MSG";
|
|
70 case QQ_GROUP_CMD_GET_ONLINE_MEMBER:
|
|
71 return "QQ_GROUP_CMD_GET_ONLINE_MEMBER";
|
|
72 case QQ_GROUP_CMD_GET_MEMBER_INFO:
|
|
73 return "QQ_GROUP_CMD_GET_MEMBER_INFO";
|
|
74 default:
|
|
75 return "Unknown QQ Group Command";
|
|
76 }
|
|
77 }
|
|
78
|
|
79 /* default process of reply error */
|
|
80 static void _qq_process_group_cmd_reply_error_default(guint8 reply, guint8 *cursor, gint len, GaimConnection *gc)
|
|
81 {
|
|
82 gchar *msg, *msg_utf8;
|
14629
|
83 g_return_if_fail(cursor != NULL && len > 0);
|
14192
|
84
|
|
85 msg = g_strndup((gchar *) cursor, len); /* it will append 0x00 */
|
|
86 msg_utf8 = qq_to_utf8(msg, QQ_CHARSET_DEFAULT);
|
|
87 g_free(msg);
|
|
88 msg = g_strdup_printf(_("Code [0x%02X]: %s"), reply, msg_utf8);
|
|
89 gaim_notify_error(gc, NULL, _("Group Operation Error"), msg);
|
|
90 g_free(msg);
|
|
91 g_free(msg_utf8);
|
|
92 }
|
|
93
|
|
94 /* default process, dump only */
|
|
95 static void _qq_process_group_cmd_reply_default(guint8 *data, guint8 **cursor, gint len, GaimConnection *gc)
|
|
96 {
|
14656
|
97 gchar *hex_dump;
|
14629
|
98 g_return_if_fail(data != NULL && len > 0);
|
14656
|
99
|
|
100 hex_dump = hex_dump_to_str(data, len);
|
|
101 gaim_debug(GAIM_DEBUG_INFO, "QQ", "Dump unprocessed group cmd reply:\n%s", hex_dump);
|
|
102 g_free(hex_dump);
|
14192
|
103 }
|
|
104
|
|
105 /* The lower layer command of send group cmd */
|
|
106 void qq_send_group_cmd(GaimConnection *gc, qq_group *group, guint8 *raw_data, gint data_len)
|
|
107 {
|
|
108 qq_data *qd;
|
|
109 group_packet *p;
|
|
110
|
|
111 g_return_if_fail(raw_data != NULL && data_len > 0);
|
|
112
|
|
113 qd = (qq_data *) gc->proto_data;
|
|
114
|
|
115 qq_send_cmd(gc, QQ_CMD_GROUP_CMD, TRUE, 0, TRUE, raw_data, data_len);
|
|
116
|
|
117 p = g_new0(group_packet, 1);
|
|
118
|
|
119 p->send_seq = qd->send_seq;
|
|
120 if (group == NULL)
|
|
121 p->internal_group_id = 0;
|
|
122 else
|
|
123 p->internal_group_id = group->internal_group_id;
|
|
124
|
|
125 qd->group_packets = g_list_append(qd->group_packets, p);
|
|
126 }
|
|
127
|
|
128 /* the main entry of group cmd processing, called by qq_recv_core.c */
|
|
129 void qq_process_group_cmd_reply(guint8 *buf, gint buf_len, guint16 seq, GaimConnection *gc)
|
|
130 {
|
|
131 qq_group *group;
|
|
132 qq_data *qd;
|
|
133 gint len, bytes;
|
|
134 guint32 internal_group_id;
|
|
135 guint8 *data, *cursor, sub_cmd, reply;
|
|
136
|
|
137 g_return_if_fail(buf != NULL && buf_len != 0);
|
|
138
|
|
139 qd = (qq_data *) gc->proto_data;
|
|
140 len = buf_len;
|
|
141 data = g_newa(guint8, len);
|
|
142
|
|
143 if (!qq_group_find_internal_group_id_by_seq(gc, seq, &internal_group_id)) {
|
|
144 gaim_debug(GAIM_DEBUG_WARNING, "QQ", "We have no record of group cmd, seq [%d]\n", seq);
|
|
145 return;
|
|
146 }
|
|
147
|
|
148 if (qq_crypt(DECRYPT, buf, buf_len, qd->session_key, data, &len)) {
|
|
149 if (len <= 2) {
|
|
150 gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Group cmd reply is too short, only %d bytes\n", len);
|
|
151 return;
|
|
152 }
|
|
153
|
|
154 bytes = 0;
|
|
155 cursor = data;
|
|
156 bytes += read_packet_b(data, &cursor, len, &sub_cmd);
|
|
157 bytes += read_packet_b(data, &cursor, len, &reply);
|
|
158
|
14404
|
159 group = qq_group_find_by_id(gc, internal_group_id, QQ_INTERNAL_ID);
|
14192
|
160
|
|
161 if (reply != QQ_GROUP_CMD_REPLY_OK) {
|
|
162 gaim_debug(GAIM_DEBUG_WARNING, "QQ",
|
|
163 "Group cmd reply says cmd %s fails\n", qq_group_cmd_get_desc(sub_cmd));
|
14404
|
164
|
|
165 if (group != NULL)
|
|
166 qq_set_pending_id(&qd->joining_groups, group->external_group_id, FALSE);
|
|
167
|
14192
|
168 switch (reply) { /* this should be all errors */
|
|
169 case QQ_GROUP_CMD_REPLY_NOT_MEMBER:
|
|
170 if (group != NULL) {
|
|
171 gaim_debug(GAIM_DEBUG_WARNING,
|
|
172 "QQ",
|
|
173 "You are not a member of group \"%s\"\n", group->group_name_utf8);
|
|
174 group->my_status = QQ_GROUP_MEMBER_STATUS_NOT_MEMBER;
|
|
175 qq_group_refresh(gc, group);
|
|
176 }
|
|
177 break;
|
14404
|
178 case QQ_GROUP_CMD_REPLY_SEARCH_ERROR:
|
|
179 if (qd->roomlist != NULL) {
|
|
180 if (gaim_roomlist_get_in_progress(qd->roomlist))
|
|
181 gaim_roomlist_set_in_progress(qd->roomlist, FALSE);
|
|
182 }
|
|
183 _qq_process_group_cmd_reply_error_default(reply, cursor, len - bytes, gc);
|
|
184 break;
|
14192
|
185 default:
|
|
186 _qq_process_group_cmd_reply_error_default(reply, cursor, len - bytes, gc);
|
|
187 }
|
|
188 return;
|
|
189 }
|
|
190
|
14404
|
191 /* seems ok so far, so we process the reply according to sub_cmd */
|
14192
|
192 switch (sub_cmd) {
|
|
193 case QQ_GROUP_CMD_GET_GROUP_INFO:
|
|
194 qq_process_group_cmd_get_group_info(data, &cursor, len, gc);
|
|
195 if (group != NULL) {
|
14404
|
196 qq_send_cmd_group_get_members_info(gc, group);
|
|
197 qq_send_cmd_group_get_online_members(gc, group);
|
14192
|
198 }
|
|
199 break;
|
|
200 case QQ_GROUP_CMD_CREATE_GROUP:
|
|
201 qq_group_process_create_group_reply(data, &cursor, len, gc);
|
|
202 break;
|
|
203 case QQ_GROUP_CMD_MODIFY_GROUP_INFO:
|
|
204 qq_group_process_modify_info_reply(data, &cursor, len, gc);
|
|
205 break;
|
|
206 case QQ_GROUP_CMD_MEMBER_OPT:
|
|
207 qq_group_process_modify_members_reply(data, &cursor, len, gc);
|
|
208 break;
|
|
209 case QQ_GROUP_CMD_ACTIVATE_GROUP:
|
|
210 qq_group_process_activate_group_reply(data, &cursor, len, gc);
|
|
211 break;
|
|
212 case QQ_GROUP_CMD_SEARCH_GROUP:
|
|
213 qq_process_group_cmd_search_group(data, &cursor, len, gc);
|
|
214 break;
|
|
215 case QQ_GROUP_CMD_JOIN_GROUP:
|
|
216 qq_process_group_cmd_join_group(data, &cursor, len, gc);
|
|
217 break;
|
|
218 case QQ_GROUP_CMD_JOIN_GROUP_AUTH:
|
|
219 qq_process_group_cmd_join_group_auth(data, &cursor, len, gc);
|
|
220 break;
|
|
221 case QQ_GROUP_CMD_EXIT_GROUP:
|
|
222 qq_process_group_cmd_exit_group(data, &cursor, len, gc);
|
|
223 break;
|
|
224 case QQ_GROUP_CMD_SEND_MSG:
|
|
225 qq_process_group_cmd_im(data, &cursor, len, gc);
|
|
226 break;
|
|
227 case QQ_GROUP_CMD_GET_ONLINE_MEMBER:
|
14404
|
228 qq_process_group_cmd_get_online_members(data, &cursor, len, gc);
|
14192
|
229 if (group != NULL)
|
|
230 qq_group_conv_refresh_online_member(gc, group);
|
|
231 break;
|
|
232 case QQ_GROUP_CMD_GET_MEMBER_INFO:
|
14404
|
233 qq_process_group_cmd_get_members_info(data, &cursor, len, gc);
|
14192
|
234 if (group != NULL)
|
|
235 qq_group_conv_refresh_online_member(gc, group);
|
|
236 break;
|
|
237 default:
|
|
238 gaim_debug(GAIM_DEBUG_WARNING, "QQ",
|
|
239 "Group cmd %s is processed by default\n", qq_group_cmd_get_desc(sub_cmd));
|
|
240 _qq_process_group_cmd_reply_default(data, &cursor, len, gc);
|
|
241 }
|
|
242
|
|
243 } else {
|
|
244 gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Error decrypt group cmd reply\n");
|
|
245 }
|
|
246 }
|