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