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 #include "request.h" // gaim_request_input
|
|
28 #include "server.h" // serv_got_joined_chat
|
|
29
|
|
30 #include "buddy_opt.h" // gc_and_uid
|
|
31 #include "char_conv.h" // QQ_CHARSET_DEFAULT
|
|
32 #include "group_conv.h" // qq_group_conv_show_window
|
|
33 #include "group_find.h" // qq_group_find_by_internal_group_id
|
|
34 #include "group_free.h" // qq_group_remove_by_internal_group_id
|
|
35 #include "group_hash.h" // qq_group_refresh
|
|
36 #include "group_info.h" // qq_send_cmd_group_get_group_info
|
|
37 #include "group_join.h"
|
|
38 #include "group_opt.h" // qq_send_cmd_group_auth
|
|
39 #include "group_network.h" // qq_send_group_cmd
|
|
40
|
|
41 enum {
|
|
42 QQ_GROUP_JOIN_OK = 0x01,
|
|
43 QQ_GROUP_JOIN_NEED_AUTH = 0x02,
|
|
44 };
|
|
45
|
|
46 /*****************************************************************************/
|
|
47 static void _qq_group_exit_with_gc_and_id(gc_and_uid * g)
|
|
48 {
|
|
49 GaimConnection *gc;
|
|
50 guint32 internal_group_id;
|
|
51 qq_group *group;
|
|
52
|
|
53 g_return_if_fail(g != NULL && g->gc != NULL && g->uid > 0);
|
|
54 gc = g->gc;
|
|
55 internal_group_id = g->uid;
|
|
56
|
|
57 group = qq_group_find_by_internal_group_id(gc, internal_group_id);
|
|
58 g_return_if_fail(group != NULL);
|
|
59
|
|
60 qq_send_cmd_group_exit_group(gc, group);
|
|
61 } // _qq_group_exist_with_gc_and_id
|
|
62
|
|
63 /*****************************************************************************/
|
|
64 // send packet to join a group without auth
|
|
65 static void _qq_send_cmd_group_join_group(GaimConnection * gc, qq_group * group)
|
|
66 {
|
|
67 guint8 *raw_data, *cursor;
|
|
68 gint bytes, data_len;
|
|
69
|
|
70 g_return_if_fail(gc != NULL && group != NULL);
|
|
71 if (group->my_status == QQ_GROUP_MEMBER_STATUS_NOT_MEMBER) {
|
|
72 group->my_status = QQ_GROUP_MEMBER_STATUS_APPLYING;
|
|
73 qq_group_refresh(gc, group);
|
|
74 } // if group->my_status
|
|
75
|
|
76 data_len = 5;
|
|
77 raw_data = g_newa(guint8, data_len);
|
|
78 cursor = raw_data;
|
|
79
|
|
80 bytes = 0;
|
|
81 bytes += create_packet_b(raw_data, &cursor, QQ_GROUP_CMD_JOIN_GROUP);
|
|
82 bytes += create_packet_dw(raw_data, &cursor, group->internal_group_id);
|
|
83
|
|
84 if (bytes != data_len)
|
|
85 gaim_debug(GAIM_DEBUG_ERROR, "QQ",
|
|
86 "Fail create packet for %s\n", qq_group_cmd_get_desc(QQ_GROUP_CMD_JOIN_GROUP));
|
|
87 else
|
|
88 qq_send_group_cmd(gc, group, raw_data, data_len);
|
|
89 } // _qq_send_cmd_group_join_group
|
|
90
|
|
91 /*****************************************************************************/
|
|
92 static void _qq_group_join_auth_with_gc_and_id(gc_and_uid * g, const gchar * reason_utf8)
|
|
93 {
|
|
94 GaimConnection *gc;
|
|
95 qq_group *group;
|
|
96 guint32 internal_group_id;
|
|
97
|
|
98 g_return_if_fail(g != NULL && g->gc != NULL && g->uid > 0);
|
|
99 gc = g->gc;
|
|
100 internal_group_id = g->uid;
|
|
101
|
|
102 group = qq_group_find_by_internal_group_id(gc, internal_group_id);
|
|
103 if (group == NULL) {
|
|
104 gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Can not find qq_group by internal_id: %d\n", internal_group_id);
|
|
105 return;
|
|
106 } else // everything is OK
|
|
107 qq_send_cmd_group_auth(gc, group, QQ_GROUP_AUTH_REQUEST_APPLY, 0, reason_utf8);
|
|
108
|
|
109 } // _qq_group_join_auth_with_gc_and_id
|
|
110
|
|
111 /*****************************************************************************/
|
|
112 static void _qq_group_join_auth(GaimConnection * gc, qq_group * group)
|
|
113 {
|
|
114 gchar *msg;
|
|
115 gc_and_uid *g;
|
|
116 g_return_if_fail(gc != NULL && group != NULL);
|
|
117
|
|
118 gaim_debug(GAIM_DEBUG_INFO, "QQ", "Group (internal id: %d) needs authentication\n", group->internal_group_id);
|
|
119
|
|
120 msg = g_strdup_printf("Group \"%s\" needs authentication\n", group->group_name_utf8);
|
|
121 g = g_new0(gc_and_uid, 1);
|
|
122 g->gc = gc;
|
|
123 g->uid = group->internal_group_id;
|
|
124 gaim_request_input(gc, NULL, msg,
|
|
125 _("Input request here"),
|
|
126 _("Would you be my friend?"), TRUE, FALSE, NULL,
|
|
127 _("Send"),
|
|
128 G_CALLBACK(_qq_group_join_auth_with_gc_and_id),
|
|
129 _("Cancel"), G_CALLBACK(qq_do_nothing_with_gc_and_uid), g);
|
|
130 g_free(msg);
|
|
131 } // _qq_group_join_auth
|
|
132
|
|
133 /*****************************************************************************/
|
|
134 void qq_send_cmd_group_auth(GaimConnection * gc, qq_group * group, guint8 opt, guint32 uid, const gchar * reason_utf8) {
|
|
135 guint8 *raw_data, *cursor;
|
|
136 gchar *reason_qq;
|
|
137 gint bytes, data_len;
|
|
138
|
|
139 g_return_if_fail(gc != NULL && group != NULL);
|
|
140
|
|
141 if (reason_utf8 == NULL || strlen(reason_utf8) == 0)
|
|
142 reason_qq = g_strdup("");
|
|
143 else
|
|
144 reason_qq = utf8_to_qq(reason_utf8, QQ_CHARSET_DEFAULT);
|
|
145
|
|
146 if (opt == QQ_GROUP_AUTH_REQUEST_APPLY) {
|
|
147 group->my_status = QQ_GROUP_MEMBER_STATUS_APPLYING;
|
|
148 qq_group_refresh(gc, group);
|
|
149 uid = 0;
|
|
150 } // if (opt == QQ_GROUP_AUTH_REQUEST_APPLY)
|
|
151
|
|
152 data_len = 10 + strlen(reason_qq) + 1;
|
|
153 raw_data = g_newa(guint8, data_len);
|
|
154 cursor = raw_data;
|
|
155
|
|
156 bytes = 0;
|
|
157 bytes += create_packet_b(raw_data, &cursor, QQ_GROUP_CMD_JOIN_GROUP_AUTH);
|
|
158 bytes += create_packet_dw(raw_data, &cursor, group->internal_group_id);
|
|
159 bytes += create_packet_b(raw_data, &cursor, opt);
|
|
160 bytes += create_packet_dw(raw_data, &cursor, uid);
|
|
161 bytes += create_packet_b(raw_data, &cursor, strlen(reason_qq));
|
|
162 bytes += create_packet_data(raw_data, &cursor, reason_qq, strlen(reason_qq));
|
|
163
|
|
164 if (bytes != data_len)
|
|
165 gaim_debug(GAIM_DEBUG_ERROR, "QQ",
|
|
166 "Fail create packet for %s\n", qq_group_cmd_get_desc(QQ_GROUP_CMD_JOIN_GROUP_AUTH));
|
|
167 else
|
|
168 qq_send_group_cmd(gc, group, raw_data, data_len);
|
|
169 } // qq_send_packet_group_auth
|
|
170
|
|
171 /*****************************************************************************/
|
|
172 // send packet to exit one group
|
|
173 // In fact, this will never be used for GAIM
|
|
174 // when we remove a GaimChat node, there is no user controlable callback
|
|
175 // so we only remove the GaimChat node,
|
|
176 // but we never use this cmd to update the server side
|
|
177 // anyway, it is function, as when we remove the GaimChat node,
|
|
178 // user has no way to start up the chat conversation window
|
|
179 // therefore even we are still in it,
|
|
180 // the group IM will not show up to bother us. (Limited by GAIM)
|
|
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 } // qq_send_cmd_group_get_group_info
|
|
202
|
|
203 /*****************************************************************************/
|
|
204 // If comes here, cmd is OK already
|
|
205 void qq_process_group_cmd_exit_group(guint8 * data, guint8 ** cursor, gint len, GaimConnection * gc) {
|
|
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) {
|
|
221 group = qq_group_find_by_internal_group_id(gc, internal_group_id);
|
|
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);
|
|
228 qq_group_remove_by_internal_group_id(qd, internal_group_id);
|
|
229 } // if group
|
|
230 gaim_notify_info(gc, _("QQ Qun Operation"), _("You have successfully exit group"), NULL);
|
|
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 } // qq_process_group_cmd_exit_group
|
|
236
|
|
237 /*****************************************************************************/
|
|
238 // Process the reply to group_auth subcmd
|
|
239 void qq_process_group_cmd_join_group_auth(guint8 * data, guint8 ** cursor, gint len, GaimConnection * gc) {
|
|
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
|
|
255 (gc, _("QQ Group Auth"), _("You authorization operation has been accepted by QQ server"), NULL);
|
|
256 else
|
|
257 gaim_debug(GAIM_DEBUG_ERROR, "QQ",
|
|
258 "Invalid join group reply, expect %d bytes, read %d bytes\n", expected_bytes, bytes);
|
|
259
|
|
260 } // qq_process_group_cmd_group_auth
|
|
261
|
|
262 /*****************************************************************************/
|
|
263 // process group cmd reply "join group"
|
|
264 void qq_process_group_cmd_join_group(guint8 * data, guint8 ** cursor, gint len, GaimConnection * gc) {
|
|
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
|
|
282 group = qq_group_find_by_internal_group_id(gc, internal_group_id);
|
|
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);
|
|
290 // this must be show before getting online member
|
|
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 } // switch reply
|
|
307 } // if bytes != expected_bytes
|
|
308 } // qq_process_group_cmd_join_group
|
|
309
|
|
310 /*****************************************************************************/
|
|
311 // Apply to join one group without auth
|
|
312 void qq_group_join(GaimConnection * gc, GHashTable * data)
|
|
313 {
|
|
314 gchar *internal_group_id_ptr;
|
|
315 guint32 internal_group_id;
|
|
316 qq_group *group;
|
|
317
|
|
318 g_return_if_fail(gc != NULL && data != NULL);
|
|
319
|
|
320 internal_group_id_ptr = g_hash_table_lookup(data, "internal_group_id");
|
|
321 internal_group_id = strtol(internal_group_id_ptr, NULL, 10);
|
|
322
|
|
323 g_return_if_fail(internal_group_id > 0);
|
|
324
|
|
325 // for those we have subscribed, they should have been put into
|
|
326 // qd->groups in qq_group_init subroutine
|
|
327 group = qq_group_find_by_internal_group_id(gc, internal_group_id);
|
|
328 if (group == NULL)
|
|
329 group = qq_group_from_hashtable(gc, data);
|
|
330
|
|
331 g_return_if_fail(group != NULL);
|
|
332
|
|
333 switch (group->auth_type) {
|
|
334 case QQ_GROUP_AUTH_TYPE_NO_AUTH:
|
|
335 case QQ_GROUP_AUTH_TYPE_NEED_AUTH:
|
|
336 _qq_send_cmd_group_join_group(gc, group);
|
|
337 break;
|
|
338 case QQ_GROUP_AUTH_TYPE_NO_ADD:
|
|
339 gaim_notify_warning(gc, NULL, _("This group does not allow others to join"), NULL);
|
|
340 break;
|
|
341 default:
|
|
342 gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Unknown group auth type: %d\n", group->auth_type);
|
|
343 } // switch auth_type
|
|
344 } // qq_group_join
|
|
345
|
|
346 /*****************************************************************************/
|
|
347 void qq_group_exit(GaimConnection * gc, GHashTable * data)
|
|
348 {
|
|
349 gchar *internal_group_id_ptr;
|
|
350 guint32 internal_group_id;
|
|
351 gc_and_uid *g;
|
|
352
|
|
353 g_return_if_fail(gc != NULL && data != NULL);
|
|
354
|
|
355 internal_group_id_ptr = g_hash_table_lookup(data, "internal_group_id");
|
|
356 internal_group_id = strtol(internal_group_id_ptr, NULL, 10);
|
|
357
|
|
358 g_return_if_fail(internal_group_id > 0);
|
|
359
|
|
360 g = g_new0(gc_and_uid, 1);
|
|
361 g->gc = gc;
|
|
362 g->uid = internal_group_id;
|
|
363
|
|
364 gaim_request_action(gc, _("QQ Qun Operation"),
|
|
365 _("Are you sure to exit this Qun?"),
|
|
366 _
|
|
367 ("Note, if you are the creator, \nthis operation will eventually remove this Qun."),
|
|
368 1, g, 2, _("Cancel"),
|
|
369 G_CALLBACK(qq_do_nothing_with_gc_and_uid),
|
|
370 _("Go ahead"), G_CALLBACK(_qq_group_exit_with_gc_and_id));
|
|
371
|
|
372 } // qq_group_exit
|
|
373
|
|
374 /*****************************************************************************/
|
|
375 // END OF FILE
|