13870
|
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
|
14021
|
23 #include "debug.h"
|
|
24 #include "notify.h"
|
13870
|
25
|
14021
|
26 #include "char_conv.h"
|
|
27 #include "crypt.h"
|
|
28 #include "group_conv.h"
|
|
29 #include "group_find.h"
|
|
30 #include "group_hash.h"
|
|
31 #include "group_im.h"
|
|
32 #include "group_info.h"
|
|
33 #include "group_join.h"
|
13870
|
34 #include "group_network.h"
|
14021
|
35 #include "group_opt.h"
|
|
36 #include "group_search.h"
|
|
37 #include "header_info.h"
|
|
38 #include "send_core.h"
|
|
39 #include "utils.h"
|
13870
|
40
|
|
41 enum {
|
|
42 QQ_GROUP_CMD_REPLY_OK = 0x00,
|
14021
|
43 QQ_GROUP_CMD_REPLY_NOT_MEMBER = 0x0a
|
13870
|
44 };
|
|
45
|
|
46 const gchar *qq_group_cmd_get_desc(qq_group_cmd cmd)
|
|
47 {
|
|
48 switch (cmd) {
|
|
49 case QQ_GROUP_CMD_CREATE_GROUP:
|
|
50 return "QQ_GROUP_CMD_CREATE_GROUP";
|
|
51 case QQ_GROUP_CMD_MEMBER_OPT:
|
|
52 return "QQ_GROUP_CMD_MEMBER_OPT";
|
|
53 case QQ_GROUP_CMD_MODIFY_GROUP_INFO:
|
|
54 return "QQ_GROUP_CMD_MODIFY_GROUP_INFO";
|
|
55 case QQ_GROUP_CMD_GET_GROUP_INFO:
|
|
56 return "QQ_GROUP_CMD_GET_GROUP_INFO";
|
|
57 case QQ_GROUP_CMD_ACTIVATE_GROUP:
|
|
58 return "QQ_GROUP_CMD_ACTIVATE_GROUP";
|
|
59 case QQ_GROUP_CMD_SEARCH_GROUP:
|
|
60 return "QQ_GROUP_CMD_SEARCH_GROUP";
|
|
61 case QQ_GROUP_CMD_JOIN_GROUP:
|
|
62 return "QQ_GROUP_CMD_JOIN_GROUP";
|
|
63 case QQ_GROUP_CMD_JOIN_GROUP_AUTH:
|
|
64 return "QQ_GROUP_CMD_JOIN_GROUP_AUTH";
|
|
65 case QQ_GROUP_CMD_EXIT_GROUP:
|
|
66 return "QQ_GROUP_CMD_EXIT_GROUP";
|
|
67 case QQ_GROUP_CMD_SEND_MSG:
|
|
68 return "QQ_GROUP_CMD_SEND_MSG";
|
|
69 case QQ_GROUP_CMD_GET_ONLINE_MEMBER:
|
|
70 return "QQ_GROUP_CMD_GET_ONLINE_MEMBER";
|
|
71 case QQ_GROUP_CMD_GET_MEMBER_INFO:
|
|
72 return "QQ_GROUP_CMD_GET_MEMBER_INFO";
|
|
73 default:
|
|
74 return "Unknown QQ Group Command";
|
14021
|
75 }
|
|
76 }
|
13870
|
77
|
14021
|
78 /* default process of reply error */
|
|
79 static void _qq_process_group_cmd_reply_error_default(guint8 reply, guint8 *cursor, gint len, GaimConnection *gc)
|
|
80 {
|
13870
|
81 gchar *msg, *msg_utf8;
|
|
82 g_return_if_fail(cursor != NULL && len > 0 && gc != NULL);
|
|
83
|
14058
|
84 msg = g_strndup((gchar *) cursor, len); /* it will append 0x00 */
|
13870
|
85 msg_utf8 = qq_to_utf8(msg, QQ_CHARSET_DEFAULT);
|
|
86 g_free(msg);
|
|
87 msg = g_strdup_printf(_("Code [0x%02X]: %s"), reply, msg_utf8);
|
|
88 gaim_notify_error(gc, NULL, _("Group Operation Error"), msg);
|
|
89 g_free(msg);
|
|
90 g_free(msg_utf8);
|
14021
|
91 }
|
13870
|
92
|
14021
|
93 /* default process, dump only */
|
|
94 static void _qq_process_group_cmd_reply_default(guint8 *data, guint8 **cursor, gint len, GaimConnection *gc)
|
|
95 {
|
13870
|
96 g_return_if_fail(gc != NULL && data != NULL && len > 0);
|
|
97 gaim_debug(GAIM_DEBUG_INFO, "QQ", "Dump unprocessed group cmd reply:\n%s", hex_dump_to_str(data, len));
|
14021
|
98 }
|
13870
|
99
|
14021
|
100 /* The lower layer command of send group cmd */
|
|
101 void qq_send_group_cmd(GaimConnection *gc, qq_group *group, guint8 *raw_data, gint data_len)
|
|
102 {
|
13870
|
103 qq_data *qd;
|
|
104 group_packet *p;
|
|
105
|
|
106 g_return_if_fail(gc != NULL);
|
|
107 g_return_if_fail(raw_data != NULL && data_len > 0);
|
|
108
|
|
109 qd = (qq_data *) gc->proto_data;
|
|
110 g_return_if_fail(qd != NULL);
|
|
111
|
|
112 qq_send_cmd(gc, QQ_CMD_GROUP_CMD, TRUE, 0, TRUE, raw_data, data_len);
|
|
113
|
|
114 p = g_new0(group_packet, 1);
|
|
115
|
|
116 p->send_seq = qd->send_seq;
|
|
117 if (group == NULL)
|
|
118 p->internal_group_id = 0;
|
|
119 else
|
|
120 p->internal_group_id = group->internal_group_id;
|
|
121
|
|
122 qd->group_packets = g_list_append(qd->group_packets, p);
|
14021
|
123 }
|
13870
|
124
|
14021
|
125 /* the main entry of group cmd processing, called by qq_recv_core.c */
|
|
126 void qq_process_group_cmd_reply(guint8 *buf, gint buf_len, guint16 seq, GaimConnection *gc)
|
|
127 {
|
13870
|
128 qq_group *group;
|
|
129 qq_data *qd;
|
|
130 gint len, bytes;
|
|
131 guint32 internal_group_id;
|
|
132 guint8 *data, *cursor, sub_cmd, reply;
|
|
133
|
|
134 g_return_if_fail(gc != NULL && gc->proto_data != NULL);
|
|
135 g_return_if_fail(buf != NULL && buf_len != 0);
|
|
136
|
|
137 qd = (qq_data *) gc->proto_data;
|
|
138 len = buf_len;
|
|
139 data = g_newa(guint8, len);
|
|
140
|
|
141 if (!qq_group_find_internal_group_id_by_seq(gc, seq, &internal_group_id)) {
|
|
142 gaim_debug(GAIM_DEBUG_WARNING, "QQ", "We have no record of group cmd, seq [%d]\n", seq);
|
|
143 return;
|
14021
|
144 }
|
13870
|
145
|
|
146 if (qq_crypt(DECRYPT, buf, buf_len, qd->session_key, data, &len)) {
|
|
147 if (len <= 2) {
|
|
148 gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Group cmd reply is too short, only %d bytes\n", len);
|
|
149 return;
|
14021
|
150 }
|
13870
|
151
|
|
152 bytes = 0;
|
|
153 cursor = data;
|
|
154 bytes += read_packet_b(data, &cursor, len, &sub_cmd);
|
|
155 bytes += read_packet_b(data, &cursor, len, &reply);
|
|
156
|
|
157 group = qq_group_find_by_internal_group_id(gc, internal_group_id);
|
|
158
|
|
159 if (reply != QQ_GROUP_CMD_REPLY_OK) {
|
|
160 gaim_debug(GAIM_DEBUG_WARNING, "QQ",
|
|
161 "Group cmd reply says cmd %s fails\n", qq_group_cmd_get_desc(sub_cmd));
|
14021
|
162 switch (reply) { /* this should be all errors */
|
13870
|
163 case QQ_GROUP_CMD_REPLY_NOT_MEMBER:
|
|
164 if (group != NULL) {
|
|
165 gaim_debug(GAIM_DEBUG_WARNING,
|
|
166 "QQ",
|
|
167 "You are not a member of group \"%s\"\n", group->group_name_utf8);
|
|
168 group->my_status = QQ_GROUP_MEMBER_STATUS_NOT_MEMBER;
|
|
169 qq_group_refresh(gc, group);
|
14021
|
170 }
|
13870
|
171 break;
|
|
172 default:
|
|
173 _qq_process_group_cmd_reply_error_default(reply, cursor, len - bytes, gc);
|
14021
|
174 }
|
13870
|
175 return;
|
14021
|
176 }
|
13870
|
177
|
14021
|
178 /* seems to ok so far, so we process the reply according to sub_cmd */
|
13870
|
179 switch (sub_cmd) {
|
|
180 case QQ_GROUP_CMD_GET_GROUP_INFO:
|
|
181 qq_process_group_cmd_get_group_info(data, &cursor, len, gc);
|
|
182 if (group != NULL) {
|
|
183 qq_send_cmd_group_get_member_info(gc, group);
|
|
184 qq_send_cmd_group_get_online_member(gc, group);
|
|
185 }
|
|
186 break;
|
|
187 case QQ_GROUP_CMD_CREATE_GROUP:
|
|
188 qq_group_process_create_group_reply(data, &cursor, len, gc);
|
|
189 break;
|
|
190 case QQ_GROUP_CMD_MODIFY_GROUP_INFO:
|
|
191 qq_group_process_modify_info_reply(data, &cursor, len, gc);
|
|
192 break;
|
|
193 case QQ_GROUP_CMD_MEMBER_OPT:
|
|
194 qq_group_process_modify_members_reply(data, &cursor, len, gc);
|
|
195 break;
|
|
196 case QQ_GROUP_CMD_ACTIVATE_GROUP:
|
|
197 qq_group_process_activate_group_reply(data, &cursor, len, gc);
|
|
198 break;
|
|
199 case QQ_GROUP_CMD_SEARCH_GROUP:
|
|
200 qq_process_group_cmd_search_group(data, &cursor, len, gc);
|
|
201 break;
|
|
202 case QQ_GROUP_CMD_JOIN_GROUP:
|
|
203 qq_process_group_cmd_join_group(data, &cursor, len, gc);
|
|
204 break;
|
|
205 case QQ_GROUP_CMD_JOIN_GROUP_AUTH:
|
|
206 qq_process_group_cmd_join_group_auth(data, &cursor, len, gc);
|
|
207 break;
|
|
208 case QQ_GROUP_CMD_EXIT_GROUP:
|
|
209 qq_process_group_cmd_exit_group(data, &cursor, len, gc);
|
|
210 break;
|
|
211 case QQ_GROUP_CMD_SEND_MSG:
|
|
212 qq_process_group_cmd_im(data, &cursor, len, gc);
|
|
213 break;
|
|
214 case QQ_GROUP_CMD_GET_ONLINE_MEMBER:
|
|
215 qq_process_group_cmd_get_online_member(data, &cursor, len, gc);
|
|
216 if (group != NULL)
|
|
217 qq_group_conv_refresh_online_member(gc, group);
|
|
218 break;
|
|
219 case QQ_GROUP_CMD_GET_MEMBER_INFO:
|
|
220 qq_process_group_cmd_get_member_info(data, &cursor, len, gc);
|
|
221 if (group != NULL)
|
|
222 qq_group_conv_refresh_online_member(gc, group);
|
|
223 break;
|
|
224 default:
|
|
225 gaim_debug(GAIM_DEBUG_WARNING, "QQ",
|
|
226 "Group cmd %s is processed by default\n", qq_group_cmd_get_desc(sub_cmd));
|
|
227 _qq_process_group_cmd_reply_default(data, &cursor, len, gc);
|
14021
|
228 }
|
13870
|
229
|
14021
|
230 } else {
|
|
231 gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Error decrypt group cmd reply\n");
|
|
232 }
|
|
233 }
|