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