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