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