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 #include "request.h"
|
|
26 #include "server.h"
|
|
27
|
|
28 #include "buddy_opt.h"
|
|
29 #include "char_conv.h"
|
|
30 #include "group_conv.h"
|
|
31 #include "group_find.h"
|
|
32 #include "group_free.h"
|
14404
|
33 #include "group_internal.h"
|
14192
|
34 #include "group_info.h"
|
|
35 #include "group_join.h"
|
|
36 #include "group_opt.h"
|
|
37 #include "group_network.h"
|
14404
|
38 #include "group_search.h"
|
14192
|
39
|
|
40 enum {
|
|
41 QQ_GROUP_JOIN_OK = 0x01,
|
|
42 QQ_GROUP_JOIN_NEED_AUTH = 0x02,
|
|
43 };
|
|
44
|
|
45 static void _qq_group_exit_with_gc_and_id(gc_and_uid *g)
|
|
46 {
|
|
47 GaimConnection *gc;
|
|
48 guint32 internal_group_id;
|
|
49 qq_group *group;
|
|
50
|
|
51 gc = g->gc;
|
|
52 internal_group_id = g->uid;
|
|
53
|
14404
|
54 group = qq_group_find_by_id(gc, internal_group_id, QQ_INTERNAL_ID);
|
14192
|
55 g_return_if_fail(group != NULL);
|
|
56
|
|
57 qq_send_cmd_group_exit_group(gc, group);
|
|
58 }
|
|
59
|
|
60 /* send packet to join a group without auth */
|
14404
|
61 void qq_send_cmd_group_join_group(GaimConnection *gc, qq_group *group)
|
14192
|
62 {
|
|
63 guint8 *raw_data, *cursor;
|
|
64 gint bytes, data_len;
|
|
65
|
14629
|
66 g_return_if_fail(group != NULL);
|
14404
|
67
|
14192
|
68 if (group->my_status == QQ_GROUP_MEMBER_STATUS_NOT_MEMBER) {
|
|
69 group->my_status = QQ_GROUP_MEMBER_STATUS_APPLYING;
|
|
70 qq_group_refresh(gc, group);
|
|
71 }
|
|
72
|
14404
|
73 switch (group->auth_type) {
|
|
74 case QQ_GROUP_AUTH_TYPE_NO_AUTH:
|
|
75 case QQ_GROUP_AUTH_TYPE_NEED_AUTH:
|
|
76 break;
|
|
77 case QQ_GROUP_AUTH_TYPE_NO_ADD:
|
|
78 gaim_notify_warning(gc, NULL, _("This group does not allow others to join"), NULL);
|
|
79 return;
|
|
80 default:
|
|
81 gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Unknown group auth type: %d\n", group->auth_type);
|
|
82 break;
|
|
83 }
|
|
84
|
14192
|
85 data_len = 5;
|
|
86 raw_data = g_newa(guint8, data_len);
|
|
87 cursor = raw_data;
|
|
88
|
|
89 bytes = 0;
|
|
90 bytes += create_packet_b(raw_data, &cursor, QQ_GROUP_CMD_JOIN_GROUP);
|
|
91 bytes += create_packet_dw(raw_data, &cursor, group->internal_group_id);
|
|
92
|
|
93 if (bytes != data_len)
|
|
94 gaim_debug(GAIM_DEBUG_ERROR, "QQ",
|
|
95 "Fail create packet for %s\n", qq_group_cmd_get_desc(QQ_GROUP_CMD_JOIN_GROUP));
|
|
96 else
|
|
97 qq_send_group_cmd(gc, group, raw_data, data_len);
|
|
98 }
|
|
99
|
|
100 static void _qq_group_join_auth_with_gc_and_id(gc_and_uid *g, const gchar *reason_utf8)
|
|
101 {
|
|
102 GaimConnection *gc;
|
|
103 qq_group *group;
|
|
104 guint32 internal_group_id;
|
|
105
|
|
106 gc = g->gc;
|
|
107 internal_group_id = g->uid;
|
|
108
|
14404
|
109 group = qq_group_find_by_id(gc, internal_group_id, QQ_INTERNAL_ID);
|
14192
|
110 if (group == NULL) {
|
|
111 gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Can not find qq_group by internal_id: %d\n", internal_group_id);
|
|
112 return;
|
|
113 } else { /* everything is OK */
|
|
114 qq_send_cmd_group_auth(gc, group, QQ_GROUP_AUTH_REQUEST_APPLY, 0, reason_utf8);
|
|
115 }
|
|
116 }
|
|
117
|
|
118 static void _qq_group_join_auth(GaimConnection *gc, qq_group *group)
|
|
119 {
|
|
120 gchar *msg;
|
|
121 gc_and_uid *g;
|
14629
|
122 g_return_if_fail(group != NULL);
|
14192
|
123
|
|
124 gaim_debug(GAIM_DEBUG_INFO, "QQ",
|
|
125 "Group (internal id: %d) needs authentication\n", group->internal_group_id);
|
|
126
|
|
127 msg = g_strdup_printf("Group \"%s\" needs authentication\n", group->group_name_utf8);
|
|
128 g = g_new0(gc_and_uid, 1);
|
|
129 g->gc = gc;
|
|
130 g->uid = group->internal_group_id;
|
|
131 gaim_request_input(gc, NULL, msg,
|
|
132 _("Input request here"),
|
|
133 _("Would you be my friend?"), TRUE, FALSE, NULL,
|
|
134 _("Send"),
|
|
135 G_CALLBACK(_qq_group_join_auth_with_gc_and_id),
|
|
136 _("Cancel"), G_CALLBACK(qq_do_nothing_with_gc_and_uid), g);
|
|
137 g_free(msg);
|
|
138 }
|
|
139
|
|
140 void qq_send_cmd_group_auth(GaimConnection *gc, qq_group *group, guint8 opt, guint32 uid, const gchar *reason_utf8)
|
|
141 {
|
|
142 guint8 *raw_data, *cursor;
|
|
143 gchar *reason_qq;
|
|
144 gint bytes, data_len;
|
|
145
|
14629
|
146 g_return_if_fail(group != NULL);
|
14192
|
147
|
|
148 if (reason_utf8 == NULL || strlen(reason_utf8) == 0)
|
|
149 reason_qq = g_strdup("");
|
|
150 else
|
|
151 reason_qq = utf8_to_qq(reason_utf8, QQ_CHARSET_DEFAULT);
|
|
152
|
|
153 if (opt == QQ_GROUP_AUTH_REQUEST_APPLY) {
|
|
154 group->my_status = QQ_GROUP_MEMBER_STATUS_APPLYING;
|
|
155 qq_group_refresh(gc, group);
|
|
156 uid = 0;
|
|
157 }
|
|
158
|
|
159 data_len = 10 + strlen(reason_qq) + 1;
|
|
160 raw_data = g_newa(guint8, data_len);
|
|
161 cursor = raw_data;
|
|
162
|
|
163 bytes = 0;
|
|
164 bytes += create_packet_b(raw_data, &cursor, QQ_GROUP_CMD_JOIN_GROUP_AUTH);
|
|
165 bytes += create_packet_dw(raw_data, &cursor, group->internal_group_id);
|
|
166 bytes += create_packet_b(raw_data, &cursor, opt);
|
|
167 bytes += create_packet_dw(raw_data, &cursor, uid);
|
|
168 bytes += create_packet_b(raw_data, &cursor, strlen(reason_qq));
|
|
169 bytes += create_packet_data(raw_data, &cursor, (guint8 *) reason_qq, strlen(reason_qq));
|
|
170
|
|
171 if (bytes != data_len)
|
|
172 gaim_debug(GAIM_DEBUG_ERROR, "QQ",
|
|
173 "Fail create packet for %s\n", qq_group_cmd_get_desc(QQ_GROUP_CMD_JOIN_GROUP_AUTH));
|
|
174 else
|
|
175 qq_send_group_cmd(gc, group, raw_data, data_len);
|
|
176 }
|
|
177
|
14404
|
178 /* send a packet to exit a group */
|
14192
|
179 void qq_send_cmd_group_exit_group(GaimConnection *gc, qq_group *group)
|
|
180 {
|
|
181 guint8 *raw_data, *cursor;
|
|
182 gint bytes, data_len;
|
|
183
|
14629
|
184 g_return_if_fail(group != NULL);
|
14192
|
185
|
|
186 data_len = 5;
|
|
187 raw_data = g_newa(guint8, data_len);
|
|
188 cursor = raw_data;
|
|
189
|
|
190 bytes = 0;
|
|
191 bytes += create_packet_b(raw_data, &cursor, QQ_GROUP_CMD_EXIT_GROUP);
|
|
192 bytes += create_packet_dw(raw_data, &cursor, group->internal_group_id);
|
|
193
|
|
194 if (bytes != data_len)
|
|
195 gaim_debug(GAIM_DEBUG_ERROR, "QQ",
|
|
196 "Fail create packet for %s\n", qq_group_cmd_get_desc(QQ_GROUP_CMD_EXIT_GROUP));
|
|
197 else
|
|
198 qq_send_group_cmd(gc, group, raw_data, data_len);
|
|
199 }
|
|
200
|
|
201 /* If comes here, cmd is OK already */
|
|
202 void qq_process_group_cmd_exit_group(guint8 *data, guint8 **cursor, gint len, GaimConnection *gc)
|
|
203 {
|
|
204 gint bytes, expected_bytes;
|
|
205 guint32 internal_group_id;
|
|
206 GaimChat *chat;
|
|
207 qq_group *group;
|
|
208 qq_data *qd;
|
|
209
|
|
210 g_return_if_fail(data != NULL && len > 0);
|
|
211 qd = (qq_data *) gc->proto_data;
|
|
212
|
|
213 bytes = 0;
|
|
214 expected_bytes = 4;
|
|
215 bytes += read_packet_dw(data, cursor, len, &internal_group_id);
|
|
216
|
|
217 if (bytes == expected_bytes) {
|
14404
|
218 group = qq_group_find_by_id(gc, internal_group_id, QQ_INTERNAL_ID);
|
14192
|
219 if (group != NULL) {
|
|
220 chat =
|
|
221 gaim_blist_find_chat
|
|
222 (gaim_connection_get_account(gc), g_strdup_printf("%d", group->external_group_id));
|
|
223 if (chat != NULL)
|
|
224 gaim_blist_remove_chat(chat);
|
14404
|
225 qq_group_delete_internal_record(qd, internal_group_id);
|
14192
|
226 }
|
14404
|
227 gaim_notify_info(gc, _("QQ Qun Operation"), _("You have successfully exited the group"), NULL);
|
14192
|
228 } else {
|
|
229 gaim_debug(GAIM_DEBUG_ERROR, "QQ",
|
|
230 "Invalid exit group reply, expect %d bytes, read %d bytes\n", expected_bytes, bytes);
|
|
231 }
|
|
232 }
|
|
233
|
|
234 /* Process the reply to group_auth subcmd */
|
|
235 void qq_process_group_cmd_join_group_auth(guint8 *data, guint8 **cursor, gint len, GaimConnection *gc)
|
|
236 {
|
|
237 gint bytes, expected_bytes;
|
|
238 guint32 internal_group_id;
|
|
239 qq_data *qd;
|
|
240
|
|
241 g_return_if_fail(data != NULL && len > 0);
|
|
242 qd = (qq_data *) gc->proto_data;
|
|
243
|
|
244 bytes = 0;
|
|
245 expected_bytes = 4;
|
|
246 bytes += read_packet_dw(data, cursor, len, &internal_group_id);
|
|
247 g_return_if_fail(internal_group_id > 0);
|
|
248
|
|
249 if (bytes == expected_bytes)
|
|
250 gaim_notify_info
|
14404
|
251 (gc, _("QQ Group Auth"),
|
|
252 _("Your authorization operation has been accepted by the QQ server"), NULL);
|
14192
|
253 else
|
|
254 gaim_debug(GAIM_DEBUG_ERROR, "QQ",
|
|
255 "Invalid join group reply, expect %d bytes, read %d bytes\n", expected_bytes, bytes);
|
|
256 }
|
|
257
|
|
258 /* process group cmd reply "join group" */
|
|
259 void qq_process_group_cmd_join_group(guint8 *data, guint8 **cursor, gint len, GaimConnection *gc)
|
|
260 {
|
|
261 gint bytes, expected_bytes;
|
|
262 guint32 internal_group_id;
|
|
263 guint8 reply;
|
|
264 qq_group *group;
|
|
265
|
14629
|
266 g_return_if_fail(data != NULL && len > 0);
|
14192
|
267
|
|
268 bytes = 0;
|
|
269 expected_bytes = 5;
|
|
270 bytes += read_packet_dw(data, cursor, len, &internal_group_id);
|
|
271 bytes += read_packet_b(data, cursor, len, &reply);
|
|
272
|
|
273 if (bytes != expected_bytes) {
|
|
274 gaim_debug(GAIM_DEBUG_ERROR, "QQ",
|
|
275 "Invalid join group reply, expect %d bytes, read %d bytes\n", expected_bytes, bytes);
|
|
276 return;
|
|
277 } else { /* join group OK */
|
14404
|
278 group = qq_group_find_by_id(gc, internal_group_id, QQ_INTERNAL_ID);
|
14192
|
279 /* need to check if group is NULL or not. */
|
|
280 g_return_if_fail(group != NULL);
|
|
281 switch (reply) {
|
|
282 case QQ_GROUP_JOIN_OK:
|
|
283 gaim_debug(GAIM_DEBUG_INFO, "QQ", "Succeed joining group \"%s\"\n", group->group_name_utf8);
|
|
284 group->my_status = QQ_GROUP_MEMBER_STATUS_IS_MEMBER;
|
|
285 qq_group_refresh(gc, group);
|
14404
|
286 /* this must be shown before getting online members */
|
14192
|
287 qq_group_conv_show_window(gc, group);
|
|
288 qq_send_cmd_group_get_group_info(gc, group);
|
|
289 break;
|
|
290 case QQ_GROUP_JOIN_NEED_AUTH:
|
|
291 gaim_debug(GAIM_DEBUG_INFO, "QQ",
|
|
292 "Fail joining group [%d] %s, needs authentication\n",
|
|
293 group->external_group_id, group->group_name_utf8);
|
|
294 group->my_status = QQ_GROUP_MEMBER_STATUS_NOT_MEMBER;
|
|
295 qq_group_refresh(gc, group);
|
|
296 _qq_group_join_auth(gc, group);
|
|
297 break;
|
|
298 default:
|
|
299 gaim_debug(GAIM_DEBUG_INFO, "QQ",
|
|
300 "Error joining group [%d] %s, unknown reply: 0x%02x\n",
|
|
301 group->external_group_id, group->group_name_utf8, reply);
|
|
302 }
|
|
303 }
|
|
304 }
|
|
305
|
14404
|
306 /* Attempt to join a group without auth */
|
14192
|
307 void qq_group_join(GaimConnection *gc, GHashTable *data)
|
|
308 {
|
14404
|
309 qq_data *qd;
|
|
310 gchar *external_group_id_ptr;
|
|
311 guint32 external_group_id;
|
14192
|
312 qq_group *group;
|
|
313
|
14629
|
314 g_return_if_fail(data != NULL);
|
14404
|
315 qd = (qq_data *) gc->proto_data;
|
14192
|
316
|
14404
|
317 external_group_id_ptr = g_hash_table_lookup(data, QQ_GROUP_KEY_EXTERNAL_ID);
|
|
318 g_return_if_fail(external_group_id_ptr != NULL);
|
|
319 errno = 0;
|
|
320 external_group_id = strtol(external_group_id_ptr, NULL, 10);
|
|
321 if (errno != 0) {
|
|
322 gaim_notify_error(gc, _("Error"),
|
|
323 _("You inputted a group id outside the acceptable range"), NULL);
|
|
324 return;
|
|
325 }
|
14192
|
326
|
14404
|
327 group = qq_group_find_by_id(gc, external_group_id, QQ_EXTERNAL_ID);
|
|
328 if (group) {
|
|
329 qq_send_cmd_group_join_group(gc, group);
|
|
330 } else {
|
|
331 qq_set_pending_id(&qd->joining_groups, external_group_id, TRUE);
|
|
332 qq_send_cmd_group_search_group(gc, external_group_id);
|
14192
|
333 }
|
|
334 }
|
|
335
|
|
336 void qq_group_exit(GaimConnection *gc, GHashTable *data)
|
|
337 {
|
|
338 gchar *internal_group_id_ptr;
|
|
339 guint32 internal_group_id;
|
|
340 gc_and_uid *g;
|
|
341
|
14629
|
342 g_return_if_fail(data != NULL);
|
14192
|
343
|
|
344 internal_group_id_ptr = g_hash_table_lookup(data, "internal_group_id");
|
|
345 internal_group_id = strtol(internal_group_id_ptr, NULL, 10);
|
|
346
|
|
347 g_return_if_fail(internal_group_id > 0);
|
|
348
|
|
349 g = g_new0(gc_and_uid, 1);
|
|
350 g->gc = gc;
|
|
351 g->uid = internal_group_id;
|
|
352
|
|
353 gaim_request_action(gc, _("QQ Qun Operation"),
|
|
354 _("Are you sure to exit this Qun?"),
|
|
355 _
|
|
356 ("Note, if you are the creator, \nthis operation will eventually remove this Qun."),
|
|
357 1, g, 2, _("Cancel"),
|
|
358 G_CALLBACK(qq_do_nothing_with_gc_and_uid),
|
|
359 _("Go ahead"), G_CALLBACK(_qq_group_exit_with_gc_and_id));
|
|
360 }
|