13870
|
1 /**
|
|
2 * @file qq.c The QQ2003C protocol plugin
|
|
3 *
|
|
4 * 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 "internal.h"
|
|
24
|
|
25 #ifdef _WIN32
|
|
26 #define random rand
|
|
27 #endif
|
|
28
|
14021
|
29 #include "accountopt.h"
|
13870
|
30 #include "debug.h"
|
|
31 #include "notify.h"
|
|
32 #include "prefs.h"
|
14021
|
33 #include "prpl.h"
|
13870
|
34 #include "request.h"
|
14052
|
35 #include "roomlist.h"
|
13870
|
36 #include "server.h"
|
14021
|
37 #include "util.h"
|
13870
|
38
|
|
39 #include "buddy_info.h"
|
|
40 #include "buddy_opt.h"
|
|
41 #include "buddy_status.h"
|
|
42 #include "char_conv.h"
|
14021
|
43 #include "group.h"
|
|
44 #include "group_find.h"
|
|
45 #include "group_im.h"
|
|
46 #include "group_info.h"
|
|
47 #include "group_join.h"
|
|
48 #include "group_opt.h"
|
|
49 #include "header_info.h"
|
13870
|
50 #include "im.h"
|
|
51 #include "keep_alive.h"
|
|
52 #include "login_logout.h"
|
14021
|
53 #include "packet_parse.h"
|
|
54 #include "qq.h"
|
|
55 #include "qq_proxy.h"
|
13870
|
56 #include "send_core.h"
|
|
57 #include "send_file.h"
|
14021
|
58 #include "utils.h"
|
13870
|
59 #include "version.h"
|
|
60
|
|
61 #define OPENQ_AUTHOR "Puzzlebird"
|
|
62 #define OPENQ_WEBSITE "http://openq.sourceforge.net"
|
|
63 #define QQ_TCP_QUERY_PORT "8000"
|
|
64 #define QQ_UDP_PORT "8000"
|
|
65
|
|
66 const gchar *udp_server_list[] = {
|
14021
|
67 "sz.tencent.com", /* 61.144.238.145 */
|
|
68 "sz2.tencent.com", /* 61.144.238.146 */
|
|
69 "sz3.tencent.com", /* 202.104.129.251 */
|
|
70 "sz4.tencent.com", /* 202.104.129.254 */
|
|
71 "sz5.tencent.com", /* 61.141.194.203 */
|
|
72 "sz6.tencent.com", /* 202.104.129.252 */
|
|
73 "sz7.tencent.com", /* 202.104.129.253 */
|
13870
|
74 "202.96.170.64",
|
|
75 "64.144.238.155",
|
|
76 "202.104.129.254"
|
|
77 };
|
|
78 const gint udp_server_amount = (sizeof(udp_server_list) / sizeof(udp_server_list[0]));
|
|
79
|
|
80
|
|
81 const gchar *tcp_server_list[] = {
|
14021
|
82 "tcpconn.tencent.com", /* 218.17.209.23 */
|
|
83 "tcpconn2.tencent.com", /* 218.18.95.153 */
|
|
84 "tcpconn3.tencent.com", /* 218.17.209.23 */
|
|
85 "tcpconn4.tencent.com" /* 218.18.95.153 */
|
13870
|
86 };
|
|
87 const gint tcp_server_amount = (sizeof(tcp_server_list) / sizeof(tcp_server_list[0]));
|
|
88
|
14021
|
89 static void _qq_login(GaimAccount *account)
|
13870
|
90 {
|
|
91 const gchar *qq_server, *qq_port;
|
|
92 qq_data *qd;
|
|
93 GaimConnection *gc;
|
13989
|
94 GaimPresence *presence;
|
13870
|
95 gboolean login_hidden, use_tcp;
|
|
96
|
|
97 g_return_if_fail(account != NULL);
|
|
98
|
|
99 gc = gaim_account_get_connection(account);
|
|
100 g_return_if_fail(gc != NULL);
|
|
101
|
|
102 gc->flags |= GAIM_CONNECTION_HTML | GAIM_CONNECTION_NO_BGCOLOR | GAIM_CONNECTION_AUTO_RESP;
|
|
103
|
|
104 qd = g_new0(qq_data, 1);
|
|
105 gc->proto_data = qd;
|
|
106
|
|
107 qq_server = gaim_account_get_string(account, "server", NULL);
|
|
108 qq_port = gaim_account_get_string(account, "port", NULL);
|
|
109 use_tcp = gaim_account_get_bool(account, "use_tcp", FALSE);
|
|
110 presence = gaim_account_get_presence(account);
|
|
111 login_hidden = gaim_presence_is_status_primitive_active(presence, GAIM_STATUS_INVISIBLE);
|
|
112
|
|
113 qd->use_tcp = use_tcp;
|
|
114
|
|
115 if (login_hidden) {
|
|
116 qd->login_mode = QQ_LOGIN_MODE_HIDDEN;
|
|
117 gaim_debug(GAIM_DEBUG_INFO, "QQ", "Login in hidden mode\n");
|
14021
|
118 } else {
|
13870
|
119 qd->login_mode = QQ_LOGIN_MODE_NORMAL;
|
|
120 gaim_debug(GAIM_DEBUG_INFO, "QQ", "Login in normal mode\n");
|
|
121 }
|
|
122
|
|
123 if (qq_server == NULL || strlen(qq_server) == 0)
|
|
124 qq_server = use_tcp ?
|
|
125 tcp_server_list[random() % tcp_server_amount] : udp_server_list[random() % udp_server_amount];
|
|
126
|
|
127 if (qq_port == NULL || strtol(qq_port, NULL, 10) == 0)
|
|
128 qq_port = use_tcp ? QQ_TCP_QUERY_PORT : QQ_UDP_PORT;
|
|
129
|
|
130 gaim_connection_update_progress(gc, _("Connecting"), 0, QQ_CONNECT_STEPS);
|
|
131
|
|
132 if (qq_connect(account, qq_server, strtol(qq_port, NULL, 10), use_tcp, FALSE) < 0)
|
|
133 gaim_connection_error(gc, _("Unable to connect."));
|
|
134 }
|
|
135
|
|
136 /* directly goes for qq_disconnect */
|
14021
|
137 static void _qq_close(GaimConnection *gc)
|
13870
|
138 {
|
|
139 g_return_if_fail(gc != NULL);
|
|
140 qq_disconnect(gc);
|
|
141 }
|
|
142
|
|
143 /* returns the icon name for a buddy or protocol */
|
14021
|
144 static const gchar *_qq_list_icon(GaimAccount *a, GaimBuddy *b)
|
13870
|
145 {
|
13989
|
146 /* XXX temp commented out until we figure out what to do with
|
|
147 * status icons */
|
|
148 /*
|
13870
|
149 gchar *filename;
|
|
150 qq_buddy *q_bud;
|
|
151 gchar icon_suffix;
|
13989
|
152 */
|
13870
|
153
|
|
154 /* do not use g_return_val_if_fail, as it is not assertion */
|
|
155 if (b == NULL || b->proto_data == NULL)
|
|
156 return "qq";
|
|
157
|
13989
|
158 /*
|
13870
|
159 q_bud = (qq_buddy *) b->proto_data;
|
13989
|
160
|
13870
|
161 icon_suffix = get_suffix_from_status(q_bud->status);
|
|
162 filename = get_icon_name(q_bud->icon / 3 + 1, icon_suffix);
|
|
163
|
|
164 return filename;
|
13989
|
165 */
|
|
166 return "qq";
|
13870
|
167 }
|
|
168
|
|
169
|
|
170 /* a short status text beside buddy icon*/
|
|
171 static gchar *_qq_status_text(GaimBuddy *b)
|
|
172 {
|
|
173 qq_buddy *q_bud;
|
|
174 GString *status;
|
|
175 gchar *ret;
|
|
176
|
|
177 q_bud = (qq_buddy *) b->proto_data;
|
|
178 if (q_bud == NULL)
|
|
179 return NULL;
|
|
180
|
|
181 status = g_string_new("");
|
|
182
|
|
183 switch(q_bud->status) {
|
|
184 case QQ_BUDDY_OFFLINE:
|
|
185 g_string_append(status, "My Offline");
|
|
186 break;
|
|
187 case QQ_BUDDY_ONLINE_NORMAL:
|
|
188 return NULL;
|
|
189 break;
|
|
190 case QQ_BUDDY_ONLINE_OFFLINE:
|
|
191 g_string_append(status, "Online Offline");
|
|
192 break;
|
|
193 case QQ_BUDDY_ONLINE_AWAY:
|
|
194 g_string_append(status, "Away");
|
|
195 break;
|
|
196 case QQ_BUDDY_ONLINE_INVISIBLE:
|
|
197 g_string_append(status, "Invisible");
|
|
198 break;
|
|
199 default:
|
|
200 g_string_printf(status, "Unknown-%d", q_bud->status);
|
|
201 }
|
|
202 /*
|
|
203 switch (q_bud->gender) {
|
|
204 case QQ_BUDDY_GENDER_GG:
|
|
205 g_string_append(status, " GG");
|
|
206 break;
|
|
207 case QQ_BUDDY_GENDER_MM:
|
|
208 g_string_append(status, " MM");
|
|
209 break;
|
|
210 case QQ_BUDDY_GENDER_UNKNOWN:
|
|
211 g_string_append(status, "^_*");
|
|
212 break;
|
|
213 default:
|
|
214 g_string_append(status, "^_^");
|
|
215 }
|
|
216
|
|
217 g_string_append_printf(status, " Age: %d", q_bud->age);
|
|
218 g_string_append_printf(status, " Client: %04x", q_bud->client_version);
|
14021
|
219 having_video = q_bud->comm_flag & QQ_COMM_FLAG_VIDEO;
|
|
220 if (having_video)
|
|
221 g_string_append(status, " (video)");
|
13870
|
222 */
|
|
223
|
|
224 ret = status->str;
|
|
225 g_string_free(status, FALSE);
|
|
226
|
|
227 return ret;
|
|
228 }
|
|
229
|
|
230
|
|
231 /* a floating text when mouse is on the icon, show connection status here */
|
|
232 static void _qq_tooltip_text(GaimBuddy *b, GString *tooltip, gboolean full)
|
|
233 {
|
|
234 qq_buddy *q_bud;
|
14021
|
235 /* gchar *country, *country_utf8, *city, *city_utf8;
|
|
236 guint32 ip_value;
|
|
237 */
|
13870
|
238 gchar *ip_str;
|
|
239
|
|
240 g_return_if_fail(b != NULL);
|
|
241
|
|
242 q_bud = (qq_buddy *) b->proto_data;
|
14021
|
243 /* g_return_if_fail(q_bud != NULL); */
|
13870
|
244
|
13989
|
245 if (GAIM_BUDDY_IS_ONLINE(b) && q_bud != NULL)
|
13870
|
246 {
|
|
247 ip_str = gen_ip_str(q_bud->ip);
|
13989
|
248 if (strlen(ip_str) != 0) {
|
14051
|
249 g_string_append_printf(tooltip, "\n<b>%s Address:</b> %s:%d",
|
|
250 (q_bud->comm_flag & QQ_COMM_FLAG_TCP_MODE)
|
13870
|
251 ? "TCP" : "UDP", ip_str, q_bud->port);
|
13989
|
252 }
|
13870
|
253 g_free(ip_str);
|
|
254 g_string_append_printf(tooltip, "\n<b>Age:</b> %d", q_bud->age);
|
|
255 switch (q_bud->gender) {
|
|
256 case QQ_BUDDY_GENDER_GG:
|
|
257 g_string_append(tooltip, "\n<b>Gender:</b> GG");
|
|
258 break;
|
|
259 case QQ_BUDDY_GENDER_MM:
|
|
260 g_string_append(tooltip, "\n<b>Gender:</b> MM");
|
|
261 break;
|
|
262 case QQ_BUDDY_GENDER_UNKNOWN:
|
|
263 g_string_append(tooltip, "\n<b>Gender:</b> UNKNOWN");
|
|
264 break;
|
|
265 default:
|
|
266 g_string_append_printf(tooltip, "\n<b>Gender:</b> ERROR(%d)", q_bud->gender);
|
|
267 } /* switch gender */
|
|
268 g_string_append_printf(tooltip, "\n<b>Flag:</b> %01x", q_bud->flag1);
|
|
269 g_string_append_printf(tooltip, "\n<b>CommFlag:</b> %01x", q_bud->comm_flag);
|
|
270 g_string_append_printf(tooltip, "\n<b>Client:</b> %04x", q_bud->client_version);
|
|
271 }
|
|
272 }
|
|
273
|
|
274 /* we can show tiny icons on the four corners of buddy icon, */
|
14021
|
275 static void _qq_list_emblems(GaimBuddy *b, const char **se, const char **sw, const char **nw, const char **ne)
|
|
276 {
|
|
277 /* each char ** are refering to filename in pixmaps/gaim/status/default/ *png */
|
13870
|
278
|
|
279 qq_buddy *q_bud = b->proto_data;
|
|
280 const char *emblems[4] = { NULL, NULL, NULL, NULL };
|
|
281 int i = 0;
|
|
282
|
14021
|
283 if (q_bud == NULL) {
|
13870
|
284 emblems[0] = "offline";
|
14021
|
285 } else {
|
13870
|
286 if (q_bud->comm_flag & QQ_COMM_FLAG_QQ_MEMBER)
|
|
287 emblems[i++] = "qq_member";
|
|
288 if (q_bud->comm_flag & QQ_COMM_FLAG_BIND_MOBILE)
|
|
289 emblems[i++] = "wireless";
|
|
290 if (q_bud->comm_flag & QQ_COMM_FLAG_VIDEO)
|
|
291 emblems[i++] = "video";
|
|
292
|
|
293 }
|
|
294
|
|
295 *se = emblems[0];
|
|
296 *sw = emblems[1];
|
|
297 *nw = emblems[2];
|
|
298 *ne = emblems[3];
|
|
299
|
|
300 return;
|
|
301 }
|
|
302
|
|
303 /* QQ away status (used to initiate QQ away packet) */
|
|
304 static GList *_qq_away_states(GaimAccount *ga)
|
|
305 {
|
|
306 GaimStatusType *status;
|
|
307 GList *types = NULL;
|
|
308
|
|
309 status = gaim_status_type_new_full(GAIM_STATUS_AVAILABLE,
|
|
310 "available", _("QQ: Available"), FALSE, TRUE, FALSE);
|
|
311 types = g_list_append(types, status);
|
|
312
|
|
313 status = gaim_status_type_new_full(GAIM_STATUS_AWAY,
|
|
314 "away", _("QQ: Away"), FALSE, TRUE, FALSE);
|
|
315 types = g_list_append(types, status);
|
|
316
|
13989
|
317 status = gaim_status_type_new_full(GAIM_STATUS_INVISIBLE,
|
13870
|
318 "invisible", _("QQ: Invisible"), FALSE, TRUE, FALSE);
|
|
319 types = g_list_append(types, status);
|
|
320
|
|
321 status = gaim_status_type_new_full(GAIM_STATUS_OFFLINE,
|
|
322 "offline", _("QQ: Offline"), FALSE, TRUE, FALSE);
|
|
323 types = g_list_append(types, status);
|
|
324
|
|
325 return types;
|
|
326 }
|
|
327
|
|
328 /* initiate QQ away with proper change_status packet */
|
|
329 static void _qq_set_away(GaimAccount *account, GaimStatus *status)
|
|
330 {
|
|
331 GaimConnection *gc = gaim_account_get_connection(account);
|
|
332 const char *state = gaim_status_get_id(status);
|
|
333
|
|
334 qq_data *qd;
|
|
335
|
|
336
|
|
337 g_return_if_fail(gc != NULL && gc->proto_data != NULL);
|
|
338
|
|
339 qd = (qq_data *) gc->proto_data;
|
|
340
|
|
341 if(0 == strcmp(state, "available"))
|
|
342 qd->status = QQ_SELF_STATUS_AVAILABLE;
|
|
343 else if (0 == strcmp(state, "away"))
|
|
344 qd->status = QQ_SELF_STATUS_AWAY;
|
|
345 else if (0 == strcmp(state, "invisible"))
|
|
346 qd->status = QQ_SELF_STATUS_INVISIBLE;
|
|
347 else
|
|
348 qd->status = QQ_SELF_STATUS_AVAILABLE;
|
|
349
|
|
350 qq_send_packet_change_status(gc);
|
|
351 }
|
|
352
|
14021
|
353 /* IMPORTANT: GaimConvImFlags -> GaimMessageFlags */
|
|
354 /* send an instant msg to a buddy */
|
|
355 static gint _qq_send_im(GaimConnection *gc, const gchar *who, const gchar *message, GaimMessageFlags flags)
|
13870
|
356 {
|
|
357 gint type, to_uid;
|
|
358 gchar *msg, *msg_with_qq_smiley;
|
|
359 qq_data *qd;
|
|
360
|
|
361 g_return_val_if_fail(gc != NULL && gc->proto_data != NULL && who != NULL, -1);
|
|
362
|
|
363 qd = (qq_data *) gc->proto_data;
|
|
364
|
|
365 g_return_val_if_fail(strlen(message) <= QQ_MSG_IM_MAX, -E2BIG);
|
|
366
|
|
367 type = (flags == GAIM_MESSAGE_AUTO_RESP ? QQ_IM_AUTO_REPLY : QQ_IM_TEXT);
|
|
368 to_uid = gaim_name_to_uid(who);
|
|
369
|
|
370 /* if msg is to myself, bypass the network */
|
14021
|
371 if (to_uid == qd->uid) {
|
13870
|
372 serv_got_im(gc, who, message, flags, time(NULL));
|
14021
|
373 } else {
|
13870
|
374 msg = utf8_to_qq(message, QQ_CHARSET_DEFAULT);
|
|
375 msg_with_qq_smiley = gaim_smiley_to_qq(msg);
|
|
376 qq_send_packet_im(gc, to_uid, msg_with_qq_smiley, type);
|
|
377 g_free(msg);
|
|
378 g_free(msg_with_qq_smiley);
|
|
379 }
|
|
380
|
|
381 return 1;
|
|
382 }
|
|
383
|
|
384 /* send a chat msg to a QQ Qun */
|
13989
|
385 static int _qq_chat_send(GaimConnection *gc, int channel, const char *message, GaimMessageFlags flags)
|
13870
|
386 {
|
|
387 gchar *msg, *msg_with_qq_smiley;
|
|
388 qq_group *group;
|
|
389
|
|
390 g_return_val_if_fail(gc != NULL && message != NULL, -1);
|
|
391 g_return_val_if_fail(strlen(message) <= QQ_MSG_IM_MAX, -E2BIG);
|
|
392
|
|
393 group = qq_group_find_by_channel(gc, channel);
|
|
394 g_return_val_if_fail(group != NULL, -1);
|
|
395
|
|
396 msg = utf8_to_qq(message, QQ_CHARSET_DEFAULT);
|
|
397 msg_with_qq_smiley = gaim_smiley_to_qq(msg);
|
|
398 qq_send_packet_group_im(gc, group, msg_with_qq_smiley);
|
|
399 g_free(msg);
|
|
400 g_free(msg_with_qq_smiley);
|
|
401
|
|
402 return 1;
|
|
403 }
|
|
404
|
|
405 /* send packet to get who's detailed information */
|
14021
|
406 static void _qq_get_info(GaimConnection *gc, const gchar *who)
|
13870
|
407 {
|
|
408 guint32 uid;
|
|
409 qq_data *qd;
|
|
410
|
|
411 g_return_if_fail(gc != NULL && gc->proto_data != NULL);
|
|
412 qd = gc->proto_data;
|
|
413 uid = gaim_name_to_uid(who);
|
|
414
|
|
415 if (uid <= 0) {
|
|
416 gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Not valid QQid: %s\n", who);
|
|
417 gaim_notify_error(gc, NULL, _("Invalid name, please input in qq-xxxxxxxx format"), NULL);
|
|
418 return;
|
|
419 }
|
|
420
|
13989
|
421 qq_send_packet_get_info(gc, uid, TRUE);
|
13870
|
422 }
|
|
423
|
|
424 /* get my own information */
|
14021
|
425 static void _qq_menu_modify_my_info(GaimPluginAction *action)
|
13870
|
426 {
|
|
427 GaimConnection *gc = (GaimConnection *) action->context;
|
|
428 qq_data *qd;
|
|
429
|
|
430 g_return_if_fail(gc != NULL && gc->proto_data != NULL);
|
|
431
|
|
432 qd = (qq_data *) gc->proto_data;
|
13989
|
433 qq_prepare_modify_info(gc);
|
13870
|
434 }
|
|
435
|
14021
|
436 static void _qq_menu_change_password(GaimPluginAction *action)
|
14014
|
437 {
|
14015
|
438 gaim_notify_uri(NULL, "https://password.qq.com");
|
14014
|
439 }
|
|
440
|
13870
|
441 /* remove a buddy from my list and remove myself from his list */
|
|
442 /* TODO: re-enable this
|
|
443 static void _qq_menu_block_buddy(GaimBlistNode * node)
|
|
444 {
|
|
445 guint32 uid;
|
|
446 gc_and_uid *g;
|
|
447 GaimBuddy *buddy;
|
|
448 GaimConnection *gc;
|
|
449 // const gchar *who = param_who; gfhuang
|
|
450 const gchar *who;
|
|
451
|
|
452 g_return_if_fail(GAIM_BLIST_NODE_IS_BUDDY(node));
|
|
453
|
|
454 buddy = (GaimBuddy *) node;
|
|
455 gc = gaim_account_get_connection(buddy->account);
|
|
456 who = buddy->name;
|
|
457 g_return_if_fail(gc != NULL && who != NULL);
|
|
458
|
|
459 uid = gaim_name_to_uid(who);
|
|
460 g_return_if_fail(uid > 0);
|
|
461
|
|
462 g = g_new0(gc_and_uid, 1);
|
|
463 g->gc = gc;
|
|
464 g->uid = uid;
|
|
465
|
|
466 gaim_request_action(gc, _("Block Buddy"),
|
|
467 _("Are you sure to block this buddy?"), NULL,
|
|
468 1, g, 2,
|
|
469 _("Cancel"),
|
|
470 G_CALLBACK(qq_do_nothing_with_gc_and_uid),
|
|
471 _("Block"), G_CALLBACK(qq_block_buddy_with_gc_and_uid));
|
|
472 }
|
|
473 */
|
|
474
|
|
475 /* show a brief summary of what we get from login packet */
|
14021
|
476 static void _qq_menu_show_login_info(GaimPluginAction *action)
|
13870
|
477 {
|
|
478 GaimConnection *gc = (GaimConnection *) action->context;
|
|
479 qq_data *qd;
|
|
480 GString *info;
|
|
481
|
|
482 g_return_if_fail(gc != NULL && gc->proto_data != NULL);
|
|
483
|
|
484 qd = (qq_data *) gc->proto_data;
|
|
485 info = g_string_new("<html><body>\n");
|
|
486
|
|
487 g_string_append_printf(info, _("<b>Current Online</b>: %d<br>\n"), qd->all_online);
|
|
488 g_string_append_printf(info, _("<b>Last Refresh</b>: %s<br>\n"), ctime(&qd->last_get_online));
|
|
489
|
|
490 g_string_append(info, "<hr>\n");
|
|
491
|
|
492 g_string_append_printf(info, _("<b>Connection Mode</b>: %s<br>\n"), qd->use_tcp ? "TCP" : "UDP");
|
|
493 g_string_append_printf(info, _("<b>Server IP</b>: %s: %d<br>\n"), qd->server_ip, qd->server_port);
|
|
494 g_string_append_printf(info, _("<b>My Public IP</b>: %s<br>\n"), qd->my_ip);
|
|
495
|
|
496 g_string_append(info, "<hr>\n");
|
|
497 g_string_append(info, "<i>Information below may not be accurate</i><br>\n");
|
|
498
|
|
499 g_string_append_printf(info, _("<b>Login Time</b>: %s<br>\n"), ctime(&qd->login_time));
|
|
500 g_string_append_printf(info, _("<b>Last Login IP</b>: %s<br>\n"), qd->last_login_ip);
|
|
501 g_string_append_printf(info, _("<b>Last Login Time</b>: %s\n"), ctime(&qd->last_login_time));
|
|
502
|
|
503 g_string_append(info, "</body></html>");
|
|
504
|
|
505 gaim_notify_formatted(gc, NULL, _("Login Information"), NULL, info->str, NULL, NULL);
|
|
506
|
|
507 g_string_free(info, TRUE);
|
|
508 }
|
|
509
|
14052
|
510 static void _qq_menu_search_or_add_permanent_group(GaimPluginAction *action)
|
13870
|
511 {
|
14052
|
512 gaim_roomlist_show_with_account(NULL);
|
13870
|
513 }
|
|
514
|
13989
|
515 /*
|
13870
|
516 static void _qq_menu_create_permanent_group(GaimPluginAction * action)
|
|
517 {
|
|
518 GaimConnection *gc = (GaimConnection *) action->context;
|
|
519 g_return_if_fail(gc != NULL);
|
|
520 gaim_request_input(gc, _("Create QQ Qun"),
|
|
521 _("Input Qun name here"),
|
|
522 _("Only QQ member can create permanent Qun"),
|
|
523 "OpenQ", FALSE, FALSE, NULL,
|
|
524 _("Create"), G_CALLBACK(qq_group_create_with_name), _("Cancel"), NULL, gc);
|
|
525 }
|
13989
|
526 */
|
13870
|
527
|
13989
|
528 /* XXX re-enable this
|
|
529 static void _qq_menu_unsubscribe_group(GaimBlistNode * node)
|
13870
|
530 {
|
|
531 GaimChat *chat = (GaimChat *)node;
|
|
532 GaimConnection *gc = gaim_account_get_connection(chat->account);
|
|
533 GHashTable *components = chat -> components;
|
|
534
|
|
535 g_return_if_fail(GAIM_BLIST_NODE_IS_CHAT(node));
|
|
536
|
|
537 g_return_if_fail(gc != NULL && components != NULL);
|
|
538 qq_group_exit(gc, components);
|
|
539 }
|
|
540
|
13989
|
541 // XXX re-enable this
|
|
542 static void _qq_menu_manage_group(GaimBlistNode * node)
|
13870
|
543 {
|
|
544 GaimChat *chat = (GaimChat *)node;
|
|
545 GaimConnection *gc = gaim_account_get_connection(chat->account);
|
|
546 GHashTable *components = chat -> components;
|
|
547
|
|
548 g_return_if_fail(GAIM_BLIST_NODE_IS_CHAT(node));
|
|
549
|
|
550 g_return_if_fail(gc != NULL && components != NULL);
|
|
551 qq_group_manage_group(gc, components);
|
|
552 }
|
13989
|
553 */
|
13870
|
554
|
13989
|
555 /*
|
13870
|
556 static void _qq_menu_show_system_message(GaimPluginAction *action)
|
|
557 {
|
|
558 GaimConnection *gc = (GaimConnection *) action->context;
|
|
559 g_return_if_fail ( gc != NULL );
|
|
560 gaim_gtk_log_show(GAIM_LOG_IM, "systemim", gaim_connection_get_account(gc));
|
|
561 }
|
13989
|
562 */
|
13870
|
563
|
|
564 /* TODO: re-enable this
|
|
565 static void _qq_menu_send_file(GaimBlistNode * node, gpointer ignored)
|
|
566 {
|
|
567 GaimBuddy *buddy;
|
|
568 GaimConnection *gc;
|
|
569 qq_buddy *q_bud;
|
|
570
|
|
571 g_return_if_fail (GAIM_BLIST_NODE_IS_BUDDY (node));
|
|
572 buddy = (GaimBuddy *) node;
|
|
573 q_bud = (qq_buddy *) buddy->proto_data;
|
|
574 // if (is_online (q_bud->status)) {
|
|
575 gc = gaim_account_get_connection (buddy->account);
|
|
576 g_return_if_fail (gc != NULL && gc->proto_data != NULL);
|
|
577 qq_send_file(gc, buddy->name, NULL);
|
|
578 // }
|
|
579 }
|
|
580 */
|
14049
|
581
|
|
582 static gboolean _qq_parse_custom_packet_field(GaimRequestFields *fields,
|
|
583 const gchar *id, guint8 **value)
|
14015
|
584 {
|
14049
|
585 GaimRequestField *field;
|
|
586 const gchar *str;
|
|
587 gint len, i;
|
|
588 gboolean success;
|
|
589
|
|
590 success = FALSE;
|
|
591 field = gaim_request_fields_get_field(fields, id);
|
|
592 str = gaim_request_field_string_get_value(field);
|
|
593 if (str) {
|
|
594 success = TRUE;
|
|
595 if (strcmp(id, "uid") != 0) {
|
|
596 *value = hex_str_to_bytes(str, &len);
|
|
597 if (!*value || len != 2)
|
|
598 success = FALSE;
|
|
599 } else {
|
|
600 for (i = 0; i < strlen(str); i++) {
|
|
601 if (!g_ascii_isdigit(str[i])) {
|
|
602 success = FALSE;
|
|
603 break;
|
|
604 }
|
|
605 }
|
|
606 if (success) {
|
|
607 *(guint32 *) value = strtoul(str, NULL, 10);
|
|
608 if (errno == ERANGE)
|
|
609 success = FALSE;
|
|
610 }
|
|
611 }
|
|
612 }
|
|
613 if (!success)
|
|
614 gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Invalid entry: %s\n", id);
|
|
615 return success;
|
|
616 }
|
14015
|
617
|
14049
|
618 static gboolean _qq_parse_custom_packet_fields(GaimRequestFields *fields,
|
|
619 guint8 **client, guint8 **cmd, guint8 **seq, guint32 *uid,
|
|
620 guint8 **body, gint *body_len)
|
|
621 {
|
|
622 GaimRequestField *field;
|
|
623 gboolean success;
|
|
624
|
|
625 success = TRUE;
|
|
626 *client = *cmd = *seq = *body = NULL;
|
|
627 *uid = 0;
|
|
628 success = _qq_parse_custom_packet_field(fields, "client", client);
|
|
629 if (success)
|
|
630 success = _qq_parse_custom_packet_field(fields, "cmd", cmd);
|
|
631 if (success)
|
|
632 success = _qq_parse_custom_packet_field(fields, "uid", (guint8 **) uid);
|
|
633 if (success)
|
|
634 success = _qq_parse_custom_packet_field(fields, "seq", seq);
|
|
635 if (success) {
|
|
636 field = gaim_request_fields_get_field(fields, "body");
|
|
637 *body = hex_str_to_bytes(gaim_request_field_string_get_value(field),
|
|
638 body_len);
|
|
639 } else {
|
|
640 if (*client)
|
|
641 g_free(*client);
|
|
642 if (*cmd)
|
|
643 g_free(*cmd);
|
|
644 if (*seq)
|
|
645 g_free(*seq);
|
14015
|
646 }
|
14049
|
647 return success;
|
|
648 }
|
|
649
|
|
650 static void _qq_send_custom_packet_cb(GaimConnection *gc, GaimRequestFields *fields)
|
|
651 {
|
|
652 guint32 uid;
|
|
653 guint8 *buf, *client, *cmd, *seq, *body, *cursor;
|
|
654 gint bytes, len;
|
|
655 qq_data *qd;
|
|
656 gboolean success;
|
|
657
|
|
658 qd = (qq_data *) gc->proto_data;
|
|
659
|
|
660 success = _qq_parse_custom_packet_fields(fields, &client, &cmd,
|
|
661 &seq, &uid, &body, &len);
|
|
662 if (!success) {
|
|
663 gaim_notify_error(gc, _("Error"), _("Invalid packet entry"), NULL);
|
14015
|
664 return;
|
|
665 }
|
|
666
|
14049
|
667 if (body)
|
|
668 g_return_if_fail(len+12 <= MAX_PACKET_SIZE);
|
14015
|
669
|
14049
|
670 bytes = 0;
|
|
671 buf = g_newa(guint8, MAX_PACKET_SIZE);
|
|
672 cursor = buf;
|
|
673 /* QQ TCP packet has two bytes in the beginning to define packet length
|
|
674 * so I leave room here for size */
|
|
675 if (qd->use_tcp)
|
|
676 bytes += create_packet_w(buf, &cursor, 0x0000);
|
|
677 bytes += create_packet_b(buf, &cursor, QQ_PACKET_TAG);
|
|
678 bytes += create_packet_w(buf, &cursor, *(guint16 *) client);
|
|
679 bytes += create_packet_w(buf, &cursor, *(guint16 *) cmd);
|
|
680 bytes += create_packet_w(buf, &cursor, *(guint16 *) seq);
|
|
681 bytes += create_packet_dw(buf, &cursor, uid);
|
|
682 if (body) {
|
|
683 bytes += create_packet_data(buf, &cursor, body, len);
|
|
684 g_free(body);
|
|
685 }
|
|
686 bytes += create_packet_b(buf, &cursor, QQ_PACKET_TAIL);
|
14015
|
687
|
14049
|
688 gaim_debug(GAIM_DEBUG_INFO, "QQ", "Custom packet of length %i\n", bytes);
|
|
689 _qq_show_packet("Outgoing custom packet", buf, bytes);
|
|
690
|
|
691 _qq_send_packet(gc, buf, bytes, *(guint16 *) cmd);
|
|
692 g_free(client);
|
|
693 g_free(cmd);
|
|
694 g_free(seq);
|
14015
|
695 }
|
|
696
|
|
697 /* send a custom packet to the server - for protocol testing */
|
|
698 static void _qq_menu_send_custom_packet(GaimPluginAction *action)
|
|
699 {
|
14049
|
700 GaimConnection *gc;
|
|
701 GaimRequestFields *fields;
|
|
702 GaimRequestFieldGroup *group;
|
|
703 GaimRequestField *field;
|
|
704 gchar *tmp;
|
|
705 qq_data *qd;
|
|
706
|
|
707 gc = (GaimConnection *) action->context;
|
|
708 qd = (qq_data *) gc->proto_data;
|
|
709 g_return_if_fail(gc != NULL && qd != NULL);
|
|
710
|
|
711 fields = gaim_request_fields_new();
|
|
712 group = gaim_request_field_group_new(_("Packet Elements"));
|
|
713 gaim_request_fields_add_group(fields, group);
|
|
714 tmp = g_strdup_printf("%04X", QQ_CLIENT);
|
|
715 field = gaim_request_field_string_new("client", _("Client (hex)"), tmp, FALSE);
|
|
716 g_free(tmp);
|
|
717 gaim_request_field_group_add_field(group, field);
|
|
718 field = gaim_request_field_string_new("cmd", _("Command (hex)"), "0000", FALSE);
|
|
719 gaim_request_field_group_add_field(group, field);
|
|
720 field = gaim_request_field_string_new("seq", _("Sequence (hex)"), "0000", FALSE);
|
|
721 gaim_request_field_group_add_field(group, field);
|
|
722 tmp = g_strdup_printf("%u", qd->uid);
|
|
723 field = gaim_request_field_string_new("uid", _("QQ Number (decimal)"), tmp, FALSE);
|
|
724 g_free(tmp);
|
|
725 gaim_request_field_group_add_field(group, field);
|
|
726 field = gaim_request_field_string_new("body", _("Body (hex)"), NULL, FALSE);
|
|
727 gaim_request_field_group_add_field(group, field);
|
|
728
|
|
729 gaim_request_fields(gc, _("Send a custom packet"),
|
|
730 _("Send a custom packet"), NULL, fields,
|
|
731 _("Send"), G_CALLBACK(_qq_send_custom_packet_cb),
|
|
732 _("Cancel"), NULL,
|
|
733 gc);
|
14015
|
734 }
|
13870
|
735
|
|
736 /* protocol related menus */
|
14021
|
737 static GList *_qq_actions(GaimPlugin *plugin, gpointer context)
|
13870
|
738 {
|
|
739 GList *m;
|
|
740 GaimPluginAction *act;
|
|
741
|
|
742 m = NULL;
|
13989
|
743 act = gaim_plugin_action_new(_("Modify My Information"), _qq_menu_modify_my_info);
|
13870
|
744 m = g_list_append(m, act);
|
|
745
|
14014
|
746 act = gaim_plugin_action_new(_("Change Password"), _qq_menu_change_password);
|
|
747 m = g_list_append(m, act);
|
|
748
|
13870
|
749 act = gaim_plugin_action_new(_("Show Login Information"), _qq_menu_show_login_info);
|
|
750 m = g_list_append(m, act);
|
|
751
|
14049
|
752 /*
|
14015
|
753 act = gaim_plugin_action_new(_("Send Custom Packet"), _qq_menu_send_custom_packet);
|
|
754 m = g_list_append(m, act);
|
|
755 */
|
|
756
|
13989
|
757 /* XXX consider re-enabling this
|
13870
|
758 act = gaim_plugin_action_new(_("Show System Message"), _qq_menu_show_system_message);
|
|
759 m = g_list_append(m, act);
|
13989
|
760 */
|
13870
|
761
|
14049
|
762 /*
|
13870
|
763 act = gaim_plugin_action_new(_("Qun: Search a permanent Qun"), _qq_menu_search_or_add_permanent_group);
|
|
764 m = g_list_append(m, act);
|
|
765
|
|
766 act = gaim_plugin_action_new(_("Qun: Create a permanent Qun"), _qq_menu_create_permanent_group);
|
|
767 m = g_list_append(m, act);
|
13989
|
768 */
|
13870
|
769
|
|
770 return m;
|
|
771 }
|
|
772
|
|
773 /* chat-related (QQ Qun) menu shown up with right-click */
|
13989
|
774 /* XXX re-enable this
|
|
775 static GList *_qq_chat_menu(GaimBlistNode *node)
|
13870
|
776 {
|
|
777 GList *m;
|
|
778 GaimMenuAction *act;
|
|
779
|
|
780 m = NULL;
|
13989
|
781 act = gaim_menu_action_new(_("Exit this QQ Qun"), GAIM_CALLBACK(_qq_menu_unsubscribe_group), NULL, NULL);
|
13870
|
782 m = g_list_append(m, act);
|
|
783
|
13989
|
784 act = gaim_menu_action_new(_("Show Details"), GAIM_CALLBACK(_qq_menu_manage_group), NULL, NULL);
|
13870
|
785 m = g_list_append(m, act);
|
|
786
|
|
787 return m;
|
|
788 }
|
13989
|
789 */
|
13870
|
790 /* buddy-related menu shown up with right-click */
|
13989
|
791 /* XXX re-enable this
|
13870
|
792 static GList *_qq_buddy_menu(GaimBlistNode * node)
|
|
793 {
|
|
794 GList *m;
|
|
795
|
13989
|
796 if(GAIM_BLIST_NODE_IS_CHAT(node))
|
13870
|
797 return _qq_chat_menu(node);
|
|
798
|
|
799 m = NULL;
|
13989
|
800 */
|
13870
|
801 /* TODO : not working, temp commented out by gfhuang
|
|
802
|
|
803 act = gaim_menu_action_new(_("Block this buddy"), GAIM_CALLBACK(_qq_menu_block_buddy), NULL, NULL); //add NULL by gfhuang
|
|
804 m = g_list_append(m, act);
|
|
805 // if (q_bud && is_online(q_bud->status)) {
|
|
806 act = gaim_menu_action_new(_("Send File"), GAIM_CALLBACK(_qq_menu_send_file), NULL, NULL); //add NULL by gfhuang
|
|
807 m = g_list_append(m, act);
|
|
808 // }
|
|
809 */
|
13989
|
810 /*
|
13870
|
811 return m;
|
|
812 }
|
13989
|
813 */
|
13870
|
814
|
|
815
|
14021
|
816 static void _qq_keep_alive(GaimConnection *gc)
|
13870
|
817 {
|
|
818 qq_group *group;
|
|
819 qq_data *qd;
|
|
820 GList *list;
|
|
821
|
|
822 g_return_if_fail(gc != NULL);
|
|
823 if (NULL == (qd = (qq_data *) gc->proto_data))
|
|
824 return;
|
|
825
|
|
826 list = qd->groups;
|
|
827 while (list != NULL) {
|
|
828 group = (qq_group *) list->data;
|
|
829 if (group->my_status == QQ_GROUP_MEMBER_STATUS_IS_MEMBER ||
|
|
830 group->my_status == QQ_GROUP_MEMBER_STATUS_IS_ADMIN)
|
14021
|
831 /* no need to get info time and time again, online members enough */
|
13870
|
832 qq_send_cmd_group_get_online_member(gc, group);
|
|
833
|
|
834 list = list->next;
|
|
835 }
|
|
836
|
|
837 qq_send_packet_keep_alive(gc);
|
|
838
|
|
839 }
|
|
840
|
|
841 /* convert chat nickname to qq-uid to get this buddy info */
|
|
842 /* who is the nickname of buddy in QQ chat-room (Qun) */
|
14021
|
843 static void _qq_get_chat_buddy_info(GaimConnection *gc, gint channel, const gchar *who)
|
13870
|
844 {
|
|
845 gchar *gaim_name;
|
|
846 g_return_if_fail(gc != NULL && gc->proto_data != NULL && who != NULL);
|
|
847
|
|
848 gaim_name = qq_group_find_member_by_channel_and_nickname(gc, channel, who);
|
|
849 if (gaim_name != NULL)
|
|
850 _qq_get_info(gc, gaim_name);
|
|
851 }
|
|
852
|
|
853 /* convert chat nickname to qq-uid to invite individual IM to buddy */
|
|
854 /* who is the nickname of buddy in QQ chat-room (Qun) */
|
14021
|
855 static gchar *_qq_get_chat_buddy_real_name(GaimConnection *gc, gint channel, const gchar *who)
|
13870
|
856 {
|
|
857 g_return_val_if_fail(gc != NULL && gc->proto_data != NULL && who != NULL, NULL);
|
|
858 return qq_group_find_member_by_channel_and_nickname(gc, channel, who);
|
|
859 }
|
|
860
|
14021
|
861 void qq_function_not_implemented(GaimConnection *gc)
|
13870
|
862 {
|
14021
|
863 gaim_notify_warning(gc, NULL,
|
|
864 _("This function has not be implemented yet"), _("Please wait for new version"));
|
13870
|
865 }
|
|
866
|
|
867 GaimPlugin *my_protocol = NULL;
|
|
868 static GaimPluginProtocolInfo prpl_info = {
|
|
869 OPT_PROTO_CHAT_TOPIC | OPT_PROTO_USE_POINTSIZE,
|
|
870 NULL, /* user_splits */
|
|
871 NULL, /* protocol_options */
|
|
872 NO_BUDDY_ICONS, /* icon_spec */
|
|
873 _qq_list_icon, /* list_icon */
|
|
874 _qq_list_emblems, /* list_emblems */
|
|
875 _qq_status_text, /* status_text */
|
|
876 _qq_tooltip_text, /* tooltip_text */
|
|
877 _qq_away_states, /* away_states */
|
13989
|
878 NULL, /* blist_node_menu */
|
13870
|
879 qq_chat_info, /* chat_info */
|
|
880 NULL, /* chat_info_defaults */
|
|
881 _qq_login, /* login */
|
|
882 _qq_close, /* close */
|
|
883 _qq_send_im, /* send_im */
|
|
884 NULL, /* set_info */
|
|
885 NULL, /* send_typing */
|
|
886 _qq_get_info, /* get_info */
|
|
887 _qq_set_away, /* set_away */
|
|
888 NULL, /* set_idle */
|
|
889 NULL, /* change_passwd */
|
|
890 qq_add_buddy, /* add_buddy */
|
|
891 NULL, /* add_buddies */
|
|
892 qq_remove_buddy, /* remove_buddy */
|
|
893 NULL, /* remove_buddies */
|
|
894 NULL, /* add_permit */
|
|
895 NULL, /* add_deny */
|
|
896 NULL, /* rem_permit */
|
|
897 NULL, /* rem_deny */
|
|
898 NULL, /* set_permit_deny */
|
|
899 qq_group_join, /* join_chat */
|
|
900 NULL, /* reject chat invite */
|
|
901 NULL, /* get_chat_name */
|
|
902 NULL, /* chat_invite */
|
|
903 NULL, /* chat_leave */
|
|
904 NULL, /* chat_whisper */
|
|
905 _qq_chat_send, /* chat_send */
|
|
906 _qq_keep_alive, /* keepalive */
|
|
907 NULL, /* register_user */
|
|
908 _qq_get_chat_buddy_info, /* get_cb_info */
|
|
909 NULL, /* get_cb_away */
|
|
910 NULL, /* alias_buddy */
|
|
911 NULL, /* group_buddy */
|
|
912 NULL, /* rename_group */
|
|
913 NULL, /* buddy_free */
|
|
914 NULL, /* convo_closed */
|
|
915 NULL, /* normalize */
|
|
916 NULL, /* set_buddy_icon */
|
|
917 NULL, /* remove_group */
|
|
918 _qq_get_chat_buddy_real_name, /* get_cb_real_name */
|
|
919 NULL, /* set_chat_topic */
|
|
920 NULL, /* find_blist_chat */
|
|
921 qq_roomlist_get_list, /* roomlist_get_list */
|
|
922 qq_roomlist_cancel, /* roomlist_cancel */
|
|
923 NULL, /* roomlist_expand_category */
|
13989
|
924 NULL, /* can_receive_file */
|
|
925 qq_send_file, /* send_file */
|
|
926 NULL, /* new xfer */
|
|
927 NULL, /* offline_message */
|
|
928 NULL, /* GaimWhiteboardPrplOps */
|
13870
|
929 };
|
|
930
|
|
931 static GaimPluginInfo info = {
|
|
932 GAIM_PLUGIN_MAGIC,
|
|
933 GAIM_MAJOR_VERSION,
|
|
934 GAIM_MINOR_VERSION,
|
|
935 GAIM_PLUGIN_PROTOCOL, /**< type */
|
|
936 NULL, /**< ui_requirement */
|
|
937 0, /**< flags */
|
|
938 NULL, /**< dependencies */
|
|
939 GAIM_PRIORITY_DEFAULT, /**< priority */
|
|
940
|
|
941 "prpl-qq", /**< id */
|
|
942 "QQ", /**< name */
|
|
943 VERSION, /**< version */
|
|
944 /** summary */
|
|
945 N_("QQ Protocol Plugin"),
|
|
946 /** description */
|
|
947 N_("QQ Protocol Plugin"),
|
|
948 OPENQ_AUTHOR, /**< author */
|
|
949 OPENQ_WEBSITE, /**< homepage */
|
|
950
|
|
951 NULL, /**< load */
|
|
952 NULL, /**< unload */
|
|
953 NULL, /**< destroy */
|
|
954
|
|
955 NULL, /**< ui_info */
|
|
956 &prpl_info, /**< extra_info */
|
|
957 NULL, /**< prefs_info */
|
|
958 _qq_actions
|
|
959 };
|
|
960
|
|
961
|
14021
|
962 static void init_plugin(GaimPlugin *plugin)
|
13870
|
963 {
|
|
964 GaimAccountOption *option;
|
|
965
|
|
966 option = gaim_account_option_bool_new(_("Login in TCP"), "use_tcp", FALSE);
|
|
967 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
|
|
968
|
|
969 option = gaim_account_option_bool_new(_("Login Hidden"), "hidden", FALSE);
|
|
970 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
|
|
971
|
|
972 option = gaim_account_option_string_new(_("QQ Server"), "server", NULL);
|
|
973 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
|
|
974
|
|
975 option = gaim_account_option_string_new(_("QQ Port"), "port", NULL);
|
|
976 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
|
|
977
|
|
978 my_protocol = plugin;
|
|
979
|
|
980 gaim_prefs_add_none("/plugins/prpl/qq");
|
|
981 gaim_prefs_add_bool("/plugins/prpl/qq/show_status_by_icon", TRUE);
|
|
982 gaim_prefs_add_bool("/plugins/prpl/qq/show_fake_video", FALSE);
|
|
983 gaim_prefs_add_bool("/plugins/prpl/qq/prompt_for_missing_packet", TRUE);
|
|
984 gaim_prefs_add_bool("/plugins/prpl/qq/prompt_group_msg_on_recv", TRUE);
|
|
985 }
|
|
986
|
|
987 GAIM_INIT_PLUGIN(qq, init_plugin, info);
|