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;
|
|
83 g_return_if_fail(cursor != NULL && len > 0 && gc != NULL);
|
|
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 {
|
|
97 g_return_if_fail(gc != NULL && data != NULL && len > 0);
|
|
98 gaim_debug(GAIM_DEBUG_INFO, "QQ", "Dump unprocessed group cmd reply:\n%s", hex_dump_to_str(data, len));
|
|
99 }
|
|
100
|
|
101 /* The lower layer command of send group cmd */
|
|
102 void qq_send_group_cmd(GaimConnection *gc, qq_group *group, guint8 *raw_data, gint data_len)
|
|
103 {
|
|
104 qq_data *qd;
|
|
105 group_packet *p;
|
|
106
|
|
107 g_return_if_fail(gc != NULL);
|
|
108 g_return_if_fail(raw_data != NULL && data_len > 0);
|
|
109
|
|
110 qd = (qq_data *) gc->proto_data;
|
|
111 g_return_if_fail(qd != NULL);
|
|
112
|
|
113 qq_send_cmd(gc, QQ_CMD_GROUP_CMD, TRUE, 0, TRUE, raw_data, data_len);
|
|
114
|
|
115 p = g_new0(group_packet, 1);
|
|
116
|
|
117 p->send_seq = qd->send_seq;
|
|
118 if (group == NULL)
|
|
119 p->internal_group_id = 0;
|
|
120 else
|
|
121 p->internal_group_id = group->internal_group_id;
|
|
122
|
|
123 qd->group_packets = g_list_append(qd->group_packets, p);
|
|
124 }
|
|
125
|
|
126 /* the main entry of group cmd processing, called by qq_recv_core.c */
|
|
127 void qq_process_group_cmd_reply(guint8 *buf, gint buf_len, guint16 seq, GaimConnection *gc)
|
|
128 {
|
|
129 qq_group *group;
|
|
130 qq_data *qd;
|
|
131 gint len, bytes;
|
|
132 guint32 internal_group_id;
|
|
133 guint8 *data, *cursor, sub_cmd, reply;
|
|
134
|
|
135 g_return_if_fail(gc != NULL && gc->proto_data != NULL);
|
|
136 g_return_if_fail(buf != NULL && buf_len != 0);
|
|
137
|
|
138 qd = (qq_data *) gc->proto_data;
|
|
139 len = buf_len;
|
|
140 data = g_newa(guint8, len);
|
|
141
|
|
142 if (!qq_group_find_internal_group_id_by_seq(gc, seq, &internal_group_id)) {
|
|
143 gaim_debug(GAIM_DEBUG_WARNING, "QQ", "We have no record of group cmd, seq [%d]\n", seq);
|
|
144 return;
|
|
145 }
|
|
146
|
|
147 if (qq_crypt(DECRYPT, buf, buf_len, qd->session_key, data, &len)) {
|
|
148 if (len <= 2) {
|
|
149 gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Group cmd reply is too short, only %d bytes\n", len);
|
|
150 return;
|
|
151 }
|
|
152
|
|
153 bytes = 0;
|
|
154 cursor = data;
|
|
155 bytes += read_packet_b(data, &cursor, len, &sub_cmd);
|
|
156 bytes += read_packet_b(data, &cursor, len, &reply);
|
|
157
|
14404
|
158 group = qq_group_find_by_id(gc, internal_group_id, QQ_INTERNAL_ID);
|
14192
|
159
|
|
160 if (reply != QQ_GROUP_CMD_REPLY_OK) {
|
|
161 gaim_debug(GAIM_DEBUG_WARNING, "QQ",
|
|
162 "Group cmd reply says cmd %s fails\n", qq_group_cmd_get_desc(sub_cmd));
|
14404
|
163
|
|
164 if (group != NULL)
|
|
165 qq_set_pending_id(&qd->joining_groups, group->external_group_id, FALSE);
|
|
166
|
14192
|
167 switch (reply) { /* this should be all errors */
|
|
168 case QQ_GROUP_CMD_REPLY_NOT_MEMBER:
|
|
169 if (group != NULL) {
|
|
170 gaim_debug(GAIM_DEBUG_WARNING,
|
|
171 "QQ",
|
|
172 "You are not a member of group \"%s\"\n", group->group_name_utf8);
|
|
173 group->my_status = QQ_GROUP_MEMBER_STATUS_NOT_MEMBER;
|
|
174 qq_group_refresh(gc, group);
|
|
175 }
|
|
176 break;
|
14404
|
177 case QQ_GROUP_CMD_REPLY_SEARCH_ERROR:
|
|
178 if (qd->roomlist != NULL) {
|
|
179 if (gaim_roomlist_get_in_progress(qd->roomlist))
|
|
180 gaim_roomlist_set_in_progress(qd->roomlist, FALSE);
|
|
181 }
|
|
182 _qq_process_group_cmd_reply_error_default(reply, cursor, len - bytes, gc);
|
|
183 break;
|
14192
|
184 default:
|
|
185 _qq_process_group_cmd_reply_error_default(reply, cursor, len - bytes, gc);
|
|
186 }
|
|
187 return;
|
|
188 }
|
|
189
|
14404
|
190 /* seems ok so far, so we process the reply according to sub_cmd */
|
14192
|
191 switch (sub_cmd) {
|
|
192 case QQ_GROUP_CMD_GET_GROUP_INFO:
|
|
193 qq_process_group_cmd_get_group_info(data, &cursor, len, gc);
|
|
194 if (group != NULL) {
|
14404
|
195 qq_send_cmd_group_get_members_info(gc, group);
|
|
196 qq_send_cmd_group_get_online_members(gc, group);
|
14192
|
197 }
|
|
198 break;
|
|
199 case QQ_GROUP_CMD_CREATE_GROUP:
|
|
200 qq_group_process_create_group_reply(data, &cursor, len, gc);
|
|
201 break;
|
|
202 case QQ_GROUP_CMD_MODIFY_GROUP_INFO:
|
|
203 qq_group_process_modify_info_reply(data, &cursor, len, gc);
|
|
204 break;
|
|
205 case QQ_GROUP_CMD_MEMBER_OPT:
|
|
206 qq_group_process_modify_members_reply(data, &cursor, len, gc);
|
|
207 break;
|
|
208 case QQ_GROUP_CMD_ACTIVATE_GROUP:
|
|
209 qq_group_process_activate_group_reply(data, &cursor, len, gc);
|
|
210 break;
|
|
211 case QQ_GROUP_CMD_SEARCH_GROUP:
|
|
212 qq_process_group_cmd_search_group(data, &cursor, len, gc);
|
|
213 break;
|
|
214 case QQ_GROUP_CMD_JOIN_GROUP:
|
|
215 qq_process_group_cmd_join_group(data, &cursor, len, gc);
|
|
216 break;
|
|
217 case QQ_GROUP_CMD_JOIN_GROUP_AUTH:
|
|
218 qq_process_group_cmd_join_group_auth(data, &cursor, len, gc);
|
|
219 break;
|
|
220 case QQ_GROUP_CMD_EXIT_GROUP:
|
|
221 qq_process_group_cmd_exit_group(data, &cursor, len, gc);
|
|
222 break;
|
|
223 case QQ_GROUP_CMD_SEND_MSG:
|
|
224 qq_process_group_cmd_im(data, &cursor, len, gc);
|
|
225 break;
|
|
226 case QQ_GROUP_CMD_GET_ONLINE_MEMBER:
|
14404
|
227 qq_process_group_cmd_get_online_members(data, &cursor, len, gc);
|
14192
|
228 if (group != NULL)
|
|
229 qq_group_conv_refresh_online_member(gc, group);
|
|
230 break;
|
|
231 case QQ_GROUP_CMD_GET_MEMBER_INFO:
|
14404
|
232 qq_process_group_cmd_get_members_info(data, &cursor, len, gc);
|
14192
|
233 if (group != NULL)
|
|
234 qq_group_conv_refresh_online_member(gc, group);
|
|
235 break;
|
|
236 default:
|
|
237 gaim_debug(GAIM_DEBUG_WARNING, "QQ",
|
|
238 "Group cmd %s is processed by default\n", qq_group_cmd_get_desc(sub_cmd));
|
|
239 _qq_process_group_cmd_reply_default(data, &cursor, len, gc);
|
|
240 }
|
|
241
|
|
242 } else {
|
|
243 gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Error decrypt group cmd reply\n");
|
|
244 }
|
|
245 }
|