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_get_info(gc, uid_to_gaim_name(qd->uid));
|
|
448 qq_prepare_modify_info(gc);
|
13870
|
449 }
|
|
450
|
14014
|
451 static void _qq_menu_change_password(GaimPluginAction * action)
|
|
452 {
|
14015
|
453 gaim_notify_uri(NULL, "https://password.qq.com");
|
14014
|
454 }
|
|
455
|
13870
|
456 /* remove a buddy from my list and remove myself from his list */
|
|
457 /* TODO: re-enable this
|
|
458 static void _qq_menu_block_buddy(GaimBlistNode * node)
|
|
459 {
|
|
460 guint32 uid;
|
|
461 gc_and_uid *g;
|
|
462 GaimBuddy *buddy;
|
|
463 GaimConnection *gc;
|
|
464 // const gchar *who = param_who; gfhuang
|
|
465 const gchar *who;
|
|
466
|
|
467 g_return_if_fail(GAIM_BLIST_NODE_IS_BUDDY(node));
|
|
468
|
|
469 buddy = (GaimBuddy *) node;
|
|
470 gc = gaim_account_get_connection(buddy->account);
|
|
471 who = buddy->name;
|
|
472 g_return_if_fail(gc != NULL && who != NULL);
|
|
473
|
|
474 uid = gaim_name_to_uid(who);
|
|
475 g_return_if_fail(uid > 0);
|
|
476
|
|
477 g = g_new0(gc_and_uid, 1);
|
|
478 g->gc = gc;
|
|
479 g->uid = uid;
|
|
480
|
|
481 gaim_request_action(gc, _("Block Buddy"),
|
|
482 _("Are you sure to block this buddy?"), NULL,
|
|
483 1, g, 2,
|
|
484 _("Cancel"),
|
|
485 G_CALLBACK(qq_do_nothing_with_gc_and_uid),
|
|
486 _("Block"), G_CALLBACK(qq_block_buddy_with_gc_and_uid));
|
|
487 }
|
|
488 */
|
|
489
|
|
490 /* show a brief summary of what we get from login packet */
|
|
491 static void _qq_menu_show_login_info(GaimPluginAction * action)
|
|
492 {
|
|
493 GaimConnection *gc = (GaimConnection *) action->context;
|
|
494 qq_data *qd;
|
|
495 GString *info;
|
|
496
|
|
497 g_return_if_fail(gc != NULL && gc->proto_data != NULL);
|
|
498
|
|
499 qd = (qq_data *) gc->proto_data;
|
|
500 info = g_string_new("<html><body>\n");
|
|
501
|
|
502 g_string_append_printf(info, _("<b>Current Online</b>: %d<br>\n"), qd->all_online);
|
|
503 g_string_append_printf(info, _("<b>Last Refresh</b>: %s<br>\n"), ctime(&qd->last_get_online));
|
|
504
|
|
505 g_string_append(info, "<hr>\n");
|
|
506
|
|
507 g_string_append_printf(info, _("<b>Connection Mode</b>: %s<br>\n"), qd->use_tcp ? "TCP" : "UDP");
|
|
508 g_string_append_printf(info, _("<b>Server IP</b>: %s: %d<br>\n"), qd->server_ip, qd->server_port);
|
|
509 g_string_append_printf(info, _("<b>My Public IP</b>: %s<br>\n"), qd->my_ip);
|
|
510
|
|
511 g_string_append(info, "<hr>\n");
|
|
512 g_string_append(info, "<i>Information below may not be accurate</i><br>\n");
|
|
513
|
|
514 g_string_append_printf(info, _("<b>Login Time</b>: %s<br>\n"), ctime(&qd->login_time));
|
|
515 g_string_append_printf(info, _("<b>Last Login IP</b>: %s<br>\n"), qd->last_login_ip);
|
|
516 g_string_append_printf(info, _("<b>Last Login Time</b>: %s\n"), ctime(&qd->last_login_time));
|
|
517
|
|
518 g_string_append(info, "</body></html>");
|
|
519
|
|
520 gaim_notify_formatted(gc, NULL, _("Login Information"), NULL, info->str, NULL, NULL);
|
|
521
|
|
522 g_string_free(info, TRUE);
|
|
523 }
|
|
524
|
13989
|
525 /*
|
13870
|
526 static void _qq_menu_locate_ip_cb(GaimConnection * gc, GaimRequestFields * fields)
|
|
527 {
|
|
528 GList *groups, *flds;
|
|
529 GaimRequestField *field;
|
|
530 const gchar *id, *value;
|
|
531 gchar *ip_str = NULL, *ip_dupstr = NULL;
|
|
532 guint8 *ip;
|
|
533 gchar *country, *country_utf8, *city, *city_utf8;
|
|
534 guint32 ip_value;
|
|
535
|
|
536 for (groups = gaim_request_fields_get_groups(fields); groups && !ip_str; groups = groups->next) {
|
|
537 for (flds = gaim_request_field_group_get_fields(groups->data); flds && !ip_str; flds = flds->next) {
|
|
538 field = flds->data;
|
|
539 id = gaim_request_field_get_id(field);
|
|
540 value = gaim_request_field_string_get_value(field);
|
|
541
|
|
542 if (!g_ascii_strcasecmp(id, "ip")) {
|
|
543 ip_str = g_strdup(value);
|
|
544 break;
|
|
545 }
|
|
546 }
|
|
547 }
|
|
548
|
|
549 if(ip_str) {
|
|
550 ip = str_ip_gen(ip_str);
|
|
551 ip_dupstr = gen_ip_str(ip);
|
|
552
|
|
553 ip_value = ntohl(*(guint32 *)ip);
|
|
554 if (qq_ip_get_location(ip_value, &country, &city)) {
|
|
555 country_utf8 = qq_to_utf8(country, QQ_CHARSET_DEFAULT);
|
|
556 city_utf8 = qq_to_utf8(city, QQ_CHARSET_DEFAULT);
|
|
557 gaim_notify_info(gc, ip_dupstr, country_utf8, city_utf8);
|
|
558 g_free(country);
|
|
559 g_free(city);
|
|
560 g_free(country_utf8);
|
|
561 g_free(city_utf8);
|
|
562 }
|
|
563 else
|
|
564 gaim_notify_info(gc, ip_dupstr, "IP not found", NULL);
|
|
565 g_free(ip);
|
|
566 g_free(ip_dupstr);
|
|
567 g_free(ip_str);
|
|
568 }
|
|
569 }
|
|
570
|
|
571 static void _qq_menu_locate_ip(GaimPluginAction *action)
|
|
572 {
|
|
573 GaimConnection *gc = (GaimConnection *) action->context;
|
|
574 GaimRequestField *field;
|
|
575 GaimRequestFields *fields;
|
|
576 GaimRequestFieldGroup *group;
|
|
577
|
|
578 g_return_if_fail(gc != NULL);
|
|
579
|
|
580 fields = gaim_request_fields_new();
|
|
581 group = gaim_request_field_group_new(NULL);
|
|
582 gaim_request_fields_add_group(fields, group);
|
|
583
|
|
584 field = gaim_request_field_string_new("ip", _("IP Address"), NULL, FALSE);
|
|
585 gaim_request_field_group_add_field(group, field);
|
|
586
|
|
587 gaim_request_fields(gc, _("Locate an IP"),
|
|
588 _("Locate an IP address"), NULL, fields,
|
|
589 _("Check"), G_CALLBACK(_qq_menu_locate_ip_cb), _("Cancel"), NULL, gc);
|
|
590 }
|
13989
|
591 */
|
13870
|
592
|
13989
|
593 /*
|
13870
|
594 static void _qq_menu_search_or_add_permanent_group(GaimPluginAction * action)
|
|
595 {
|
|
596 gaim_gtk_roomlist_dialog_show();
|
|
597 }
|
13989
|
598 */
|
13870
|
599
|
13989
|
600 /*
|
13870
|
601 static void _qq_menu_create_permanent_group(GaimPluginAction * action)
|
|
602 {
|
|
603 GaimConnection *gc = (GaimConnection *) action->context;
|
|
604 g_return_if_fail(gc != NULL);
|
|
605 gaim_request_input(gc, _("Create QQ Qun"),
|
|
606 _("Input Qun name here"),
|
|
607 _("Only QQ member can create permanent Qun"),
|
|
608 "OpenQ", FALSE, FALSE, NULL,
|
|
609 _("Create"), G_CALLBACK(qq_group_create_with_name), _("Cancel"), NULL, gc);
|
|
610 }
|
13989
|
611 */
|
13870
|
612
|
13989
|
613 /* XXX re-enable this
|
|
614 static void _qq_menu_unsubscribe_group(GaimBlistNode * node)
|
13870
|
615 {
|
|
616 GaimChat *chat = (GaimChat *)node;
|
|
617 GaimConnection *gc = gaim_account_get_connection(chat->account);
|
|
618 GHashTable *components = chat -> components;
|
|
619
|
|
620 g_return_if_fail(GAIM_BLIST_NODE_IS_CHAT(node));
|
|
621
|
|
622 g_return_if_fail(gc != NULL && components != NULL);
|
|
623 qq_group_exit(gc, components);
|
|
624 }
|
|
625
|
13989
|
626 // XXX re-enable this
|
|
627 static void _qq_menu_manage_group(GaimBlistNode * node)
|
13870
|
628 {
|
|
629 GaimChat *chat = (GaimChat *)node;
|
|
630 GaimConnection *gc = gaim_account_get_connection(chat->account);
|
|
631 GHashTable *components = chat -> components;
|
|
632
|
|
633 g_return_if_fail(GAIM_BLIST_NODE_IS_CHAT(node));
|
|
634
|
|
635 g_return_if_fail(gc != NULL && components != NULL);
|
|
636 qq_group_manage_group(gc, components);
|
|
637 }
|
13989
|
638 */
|
13870
|
639
|
13989
|
640 /*
|
13870
|
641 static void _qq_menu_show_system_message(GaimPluginAction *action)
|
|
642 {
|
|
643 GaimConnection *gc = (GaimConnection *) action->context;
|
|
644 g_return_if_fail ( gc != NULL );
|
|
645 gaim_gtk_log_show(GAIM_LOG_IM, "systemim", gaim_connection_get_account(gc));
|
|
646 }
|
13989
|
647 */
|
13870
|
648
|
|
649 /* TODO: re-enable this
|
|
650 static void _qq_menu_send_file(GaimBlistNode * node, gpointer ignored)
|
|
651 {
|
|
652 GaimBuddy *buddy;
|
|
653 GaimConnection *gc;
|
|
654 qq_buddy *q_bud;
|
|
655
|
|
656 g_return_if_fail (GAIM_BLIST_NODE_IS_BUDDY (node));
|
|
657 buddy = (GaimBuddy *) node;
|
|
658 q_bud = (qq_buddy *) buddy->proto_data;
|
|
659 // if (is_online (q_bud->status)) {
|
|
660 gc = gaim_account_get_connection (buddy->account);
|
|
661 g_return_if_fail (gc != NULL && gc->proto_data != NULL);
|
|
662 qq_send_file(gc, buddy->name, NULL);
|
|
663 // }
|
|
664 }
|
|
665 */
|
14015
|
666 /*
|
|
667 static void _qq_send_custom_packet(GaimConnection *gc, const gchar *packet)
|
|
668 {
|
|
669 guint16 cmd;
|
|
670 guint8 *buffer;
|
|
671 gint len;
|
|
672
|
|
673 if (!packet) {
|
|
674 gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Null packet inputted!\n");
|
|
675 return;
|
|
676 }
|
|
677 if (strlen(packet) > MAX_PACKET_SIZE * 2) {
|
|
678 gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Packet inputted is too large!\n");
|
|
679 return;
|
|
680 }
|
|
681 if (strlen(packet) < 4) {
|
|
682 gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Packet is impossibly short!\n");
|
|
683 return;
|
|
684 }
|
|
685
|
|
686 buffer = hex_str_to_bytes(packet);
|
|
687 if (!buffer) {
|
|
688 gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Invalid packet inputted!\n");
|
|
689 return;
|
|
690 }
|
|
691 // big endian
|
|
692 cmd = 256 * buffer[0] + buffer[1];
|
|
693 gaim_debug(GAIM_DEBUG_INFO, "QQ", "Inputted CMD: %d\n", cmd);
|
|
694
|
|
695 len = strlen(buffer) - 2;
|
|
696 packet = buffer + 2;
|
|
697
|
|
698 qq_send_cmd(gc, cmd, TRUE, 0, TRUE, packet, len);
|
|
699
|
|
700 g_free(buffer);
|
|
701 }
|
|
702 */
|
|
703
|
|
704 /* send a custom packet to the server - for protocol testing */
|
|
705 /*
|
|
706 static void _qq_menu_send_custom_packet(GaimPluginAction *action)
|
|
707 {
|
|
708 GaimConnection *gc = (GaimConnection *) action->context;
|
|
709 g_return_if_fail(gc != NULL);
|
|
710 gaim_request_input(gc, _("Send Custom Packet"),
|
|
711 _("Enter the packet in hex here"),
|
|
712 _("Include the command and everything following"),
|
|
713 NULL, FALSE, FALSE, NULL,
|
|
714 _("Send"), G_CALLBACK(_qq_send_custom_packet), _("Cancel"), NULL, gc);
|
|
715 }
|
|
716 */
|
13870
|
717
|
|
718 /* protocol related menus */
|
|
719 static GList *_qq_actions(GaimPlugin * plugin, gpointer context)
|
|
720 {
|
|
721 GList *m;
|
|
722 GaimPluginAction *act;
|
|
723
|
|
724 m = NULL;
|
13989
|
725 act = gaim_plugin_action_new(_("Modify My Information"), _qq_menu_modify_my_info);
|
13870
|
726 m = g_list_append(m, act);
|
|
727
|
14014
|
728 act = gaim_plugin_action_new(_("Change Password"), _qq_menu_change_password);
|
|
729 m = g_list_append(m, act);
|
|
730
|
13870
|
731 act = gaim_plugin_action_new(_("Show Login Information"), _qq_menu_show_login_info);
|
|
732 m = g_list_append(m, act);
|
|
733
|
14015
|
734 /*
|
|
735 act = gaim_plugin_action_new(_("Send Custom Packet"), _qq_menu_send_custom_packet);
|
|
736 m = g_list_append(m, act);
|
|
737 */
|
|
738
|
13989
|
739 /* XXX consider re-enabling this
|
13870
|
740 act = gaim_plugin_action_new(_("Show System Message"), _qq_menu_show_system_message);
|
|
741 m = g_list_append(m, act);
|
13989
|
742 */
|
13870
|
743
|
13989
|
744 /* XXX the old group gtk code needs to moved to the gaim UI before this can be used
|
13870
|
745 act = gaim_plugin_action_new(_("Qun: Search a permanent Qun"), _qq_menu_search_or_add_permanent_group);
|
|
746 m = g_list_append(m, act);
|
|
747
|
|
748 act = gaim_plugin_action_new(_("Qun: Create a permanent Qun"), _qq_menu_create_permanent_group);
|
|
749 m = g_list_append(m, act);
|
13989
|
750 */
|
13870
|
751
|
13989
|
752 /* XXX consider re-enabling this
|
13870
|
753 act = gaim_plugin_action_new(_("Locate an IP"), _qq_menu_locate_ip);
|
|
754 m = g_list_append(m, act);
|
13989
|
755 */
|
13870
|
756
|
|
757 return m;
|
|
758 }
|
|
759
|
|
760 /* chat-related (QQ Qun) menu shown up with right-click */
|
13989
|
761 /* XXX re-enable this
|
|
762 static GList *_qq_chat_menu(GaimBlistNode *node)
|
13870
|
763 {
|
|
764 GList *m;
|
|
765 GaimMenuAction *act;
|
|
766
|
|
767 m = NULL;
|
13989
|
768 act = gaim_menu_action_new(_("Exit this QQ Qun"), GAIM_CALLBACK(_qq_menu_unsubscribe_group), NULL, NULL);
|
13870
|
769 m = g_list_append(m, act);
|
|
770
|
13989
|
771 act = gaim_menu_action_new(_("Show Details"), GAIM_CALLBACK(_qq_menu_manage_group), NULL, NULL);
|
13870
|
772 m = g_list_append(m, act);
|
|
773
|
|
774 return m;
|
|
775 }
|
13989
|
776 */
|
13870
|
777 /* buddy-related menu shown up with right-click */
|
13989
|
778 /* XXX re-enable this
|
13870
|
779 static GList *_qq_buddy_menu(GaimBlistNode * node)
|
|
780 {
|
|
781 GList *m;
|
|
782
|
13989
|
783 if(GAIM_BLIST_NODE_IS_CHAT(node))
|
13870
|
784 return _qq_chat_menu(node);
|
|
785
|
|
786 m = NULL;
|
13989
|
787 */
|
13870
|
788 /* TODO : not working, temp commented out by gfhuang
|
|
789
|
|
790 act = gaim_menu_action_new(_("Block this buddy"), GAIM_CALLBACK(_qq_menu_block_buddy), NULL, NULL); //add NULL by gfhuang
|
|
791 m = g_list_append(m, act);
|
|
792 // if (q_bud && is_online(q_bud->status)) {
|
|
793 act = gaim_menu_action_new(_("Send File"), GAIM_CALLBACK(_qq_menu_send_file), NULL, NULL); //add NULL by gfhuang
|
|
794 m = g_list_append(m, act);
|
|
795 // }
|
|
796 */
|
13989
|
797 /*
|
13870
|
798 return m;
|
|
799 }
|
13989
|
800 */
|
13870
|
801
|
|
802
|
|
803 static void _qq_keep_alive(GaimConnection * gc)
|
|
804 {
|
|
805 qq_group *group;
|
|
806 qq_data *qd;
|
|
807 GList *list;
|
|
808
|
|
809 g_return_if_fail(gc != NULL);
|
|
810 if (NULL == (qd = (qq_data *) gc->proto_data))
|
|
811 return;
|
|
812
|
|
813 list = qd->groups;
|
|
814 while (list != NULL) {
|
|
815 group = (qq_group *) list->data;
|
|
816 if (group->my_status == QQ_GROUP_MEMBER_STATUS_IS_MEMBER ||
|
|
817 group->my_status == QQ_GROUP_MEMBER_STATUS_IS_ADMIN)
|
13989
|
818 // no need to get info time and time again, online members enough
|
13870
|
819 qq_send_cmd_group_get_online_member(gc, group);
|
|
820
|
|
821 list = list->next;
|
|
822 }
|
|
823
|
|
824 qq_send_packet_keep_alive(gc);
|
|
825
|
|
826 }
|
|
827
|
|
828 /* convert chat nickname to qq-uid to get this buddy info */
|
|
829 /* who is the nickname of buddy in QQ chat-room (Qun) */
|
|
830 static void _qq_get_chat_buddy_info(GaimConnection * gc, gint channel, const gchar * who)
|
|
831 {
|
|
832 gchar *gaim_name;
|
|
833 g_return_if_fail(gc != NULL && gc->proto_data != NULL && who != NULL);
|
|
834
|
|
835 gaim_name = qq_group_find_member_by_channel_and_nickname(gc, channel, who);
|
|
836 if (gaim_name != NULL)
|
|
837 _qq_get_info(gc, gaim_name);
|
|
838
|
|
839 }
|
|
840
|
|
841 /* convert chat nickname to qq-uid to invite individual IM to buddy */
|
|
842 /* who is the nickname of buddy in QQ chat-room (Qun) */
|
|
843 static gchar *_qq_get_chat_buddy_real_name(GaimConnection * gc, gint channel, const gchar * who)
|
|
844 {
|
|
845 g_return_val_if_fail(gc != NULL && gc->proto_data != NULL && who != NULL, NULL);
|
|
846 return qq_group_find_member_by_channel_and_nickname(gc, channel, who);
|
|
847
|
|
848 }
|
|
849
|
|
850 void qq_function_not_implemented(GaimConnection * gc)
|
|
851 {
|
|
852 gaim_notify_warning(gc, NULL, _("This function has not be implemented yet"), _("Please wait for new version"));
|
|
853 }
|
|
854
|
|
855 GaimPlugin *my_protocol = NULL;
|
|
856 static GaimPluginProtocolInfo prpl_info = {
|
|
857 OPT_PROTO_CHAT_TOPIC | OPT_PROTO_USE_POINTSIZE,
|
|
858 NULL, /* user_splits */
|
|
859 NULL, /* protocol_options */
|
|
860 NO_BUDDY_ICONS, /* icon_spec */
|
|
861 _qq_list_icon, /* list_icon */
|
|
862 _qq_list_emblems, /* list_emblems */
|
|
863 _qq_status_text, /* status_text */
|
|
864 _qq_tooltip_text, /* tooltip_text */
|
|
865 _qq_away_states, /* away_states */
|
13989
|
866 NULL, /* blist_node_menu */
|
13870
|
867 qq_chat_info, /* chat_info */
|
|
868 NULL, /* chat_info_defaults */
|
|
869 _qq_login, /* login */
|
|
870 _qq_close, /* close */
|
|
871 _qq_send_im, /* send_im */
|
|
872 NULL, /* set_info */
|
|
873 NULL, /* send_typing */
|
|
874 _qq_get_info, /* get_info */
|
|
875 _qq_set_away, /* set_away */
|
|
876 NULL, /* set_idle */
|
|
877 NULL, /* change_passwd */
|
|
878 qq_add_buddy, /* add_buddy */
|
|
879 NULL, /* add_buddies */
|
|
880 qq_remove_buddy, /* remove_buddy */
|
|
881 NULL, /* remove_buddies */
|
|
882 NULL, /* add_permit */
|
|
883 NULL, /* add_deny */
|
|
884 NULL, /* rem_permit */
|
|
885 NULL, /* rem_deny */
|
|
886 NULL, /* set_permit_deny */
|
|
887 qq_group_join, /* join_chat */
|
|
888 NULL, /* reject chat invite */
|
|
889 NULL, /* get_chat_name */
|
|
890 NULL, /* chat_invite */
|
|
891 NULL, /* chat_leave */
|
|
892 NULL, /* chat_whisper */
|
|
893 _qq_chat_send, /* chat_send */
|
|
894 _qq_keep_alive, /* keepalive */
|
|
895 NULL, /* register_user */
|
|
896 _qq_get_chat_buddy_info, /* get_cb_info */
|
|
897 NULL, /* get_cb_away */
|
|
898 NULL, /* alias_buddy */
|
|
899 NULL, /* group_buddy */
|
|
900 NULL, /* rename_group */
|
|
901 NULL, /* buddy_free */
|
|
902 NULL, /* convo_closed */
|
|
903 NULL, /* normalize */
|
|
904 NULL, /* set_buddy_icon */
|
|
905 NULL, /* remove_group */
|
|
906 _qq_get_chat_buddy_real_name, /* get_cb_real_name */
|
|
907 NULL, /* set_chat_topic */
|
|
908 NULL, /* find_blist_chat */
|
|
909 qq_roomlist_get_list, /* roomlist_get_list */
|
|
910 qq_roomlist_cancel, /* roomlist_cancel */
|
|
911 NULL, /* roomlist_expand_category */
|
13989
|
912 NULL, /* can_receive_file */
|
|
913 qq_send_file, /* send_file */
|
|
914 NULL, /* new xfer */
|
|
915 NULL, /* offline_message */
|
|
916 NULL, /* GaimWhiteboardPrplOps */
|
13870
|
917 };
|
|
918
|
|
919 static GaimPluginInfo info = {
|
|
920 GAIM_PLUGIN_MAGIC,
|
|
921 GAIM_MAJOR_VERSION,
|
|
922 GAIM_MINOR_VERSION,
|
|
923 GAIM_PLUGIN_PROTOCOL, /**< type */
|
|
924 NULL, /**< ui_requirement */
|
|
925 0, /**< flags */
|
|
926 NULL, /**< dependencies */
|
|
927 GAIM_PRIORITY_DEFAULT, /**< priority */
|
|
928
|
|
929 "prpl-qq", /**< id */
|
|
930 "QQ", /**< name */
|
|
931 VERSION, /**< version */
|
|
932 /** summary */
|
|
933 N_("QQ Protocol Plugin"),
|
|
934 /** description */
|
|
935 N_("QQ Protocol Plugin"),
|
|
936 OPENQ_AUTHOR, /**< author */
|
|
937 OPENQ_WEBSITE, /**< homepage */
|
|
938
|
|
939 NULL, /**< load */
|
|
940 NULL, /**< unload */
|
|
941 NULL, /**< destroy */
|
|
942
|
|
943 NULL, /**< ui_info */
|
|
944 &prpl_info, /**< extra_info */
|
|
945 NULL, /**< prefs_info */
|
|
946 _qq_actions
|
|
947 };
|
|
948
|
|
949
|
|
950 static void init_plugin(GaimPlugin * plugin)
|
|
951 {
|
|
952 GaimAccountOption *option;
|
|
953
|
|
954 bindtextdomain(PACKAGE, LOCALEDIR);
|
|
955 bind_textdomain_codeset(PACKAGE, "UTF-8");
|
|
956
|
|
957 option = gaim_account_option_bool_new(_("Login in TCP"), "use_tcp", FALSE);
|
|
958 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
|
|
959
|
|
960 option = gaim_account_option_bool_new(_("Login Hidden"), "hidden", FALSE);
|
|
961 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
|
|
962
|
|
963 option = gaim_account_option_string_new(_("QQ Server"), "server", NULL);
|
|
964 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
|
|
965
|
|
966 option = gaim_account_option_string_new(_("QQ Port"), "port", NULL);
|
|
967 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
|
|
968
|
|
969 my_protocol = plugin;
|
|
970
|
|
971 gaim_prefs_add_none("/plugins/prpl/qq");
|
|
972 gaim_prefs_add_string("/plugins/prpl/qq/ipfile", "");
|
|
973 gaim_prefs_add_bool("/plugins/prpl/qq/show_status_by_icon", TRUE);
|
|
974 gaim_prefs_add_bool("/plugins/prpl/qq/show_fake_video", FALSE);
|
|
975 gaim_prefs_add_string("/plugins/prpl/qq/datadir", DATADIR);
|
|
976 gaim_prefs_add_bool("/plugins/prpl/qq/prompt_for_missing_packet", TRUE);
|
|
977 gaim_prefs_add_bool("/plugins/prpl/qq/prompt_group_msg_on_recv", TRUE);
|
|
978 }
|
|
979
|
|
980 GAIM_INIT_PLUGIN(qq, init_plugin, info);
|