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"
|
|
54 #include "qq_proxy.h" /* qq_connect, qq_disconnect */
|
|
55 #include "send_core.h"
|
|
56 #include "qq.h"
|
|
57 #include "send_file.h"
|
|
58 #include "version.h"
|
|
59
|
|
60 #define OPENQ_AUTHOR "Puzzlebird"
|
|
61 #define OPENQ_WEBSITE "http://openq.sourceforge.net"
|
|
62 #define QQ_TCP_QUERY_PORT "8000"
|
|
63 #define QQ_UDP_PORT "8000"
|
|
64
|
|
65 const gchar *udp_server_list[] = {
|
|
66 "sz.tencent.com", // 61.144.238.145
|
|
67 "sz2.tencent.com", // 61.144.238.146
|
|
68 "sz3.tencent.com", // 202.104.129.251
|
|
69 "sz4.tencent.com", // 202.104.129.254
|
|
70 "sz5.tencent.com", // 61.141.194.203
|
|
71 "sz6.tencent.com", // 202.104.129.252
|
|
72 "sz7.tencent.com", // 202.104.129.253
|
|
73 "202.96.170.64",
|
|
74 "64.144.238.155",
|
|
75 "202.104.129.254"
|
|
76 };
|
|
77 const gint udp_server_amount = (sizeof(udp_server_list) / sizeof(udp_server_list[0]));
|
|
78
|
|
79
|
|
80 const gchar *tcp_server_list[] = {
|
|
81 "tcpconn.tencent.com", // 218.17.209.23
|
|
82 "tcpconn2.tencent.com", // 218.18.95.153
|
|
83 "tcpconn3.tencent.com", // 218.17.209.23
|
|
84 "tcpconn4.tencent.com", // 218.18.95.153
|
|
85 };
|
|
86 const gint tcp_server_amount = (sizeof(tcp_server_list) / sizeof(tcp_server_list[0]));
|
|
87
|
|
88 static void _qq_login(GaimAccount * account)
|
|
89 {
|
|
90 const gchar *qq_server, *qq_port;
|
|
91 qq_data *qd;
|
|
92 GaimConnection *gc;
|
13989
|
93 GaimPresence *presence;
|
13870
|
94 gboolean login_hidden, use_tcp;
|
|
95
|
|
96 g_return_if_fail(account != NULL);
|
|
97
|
|
98 gc = gaim_account_get_connection(account);
|
|
99 g_return_if_fail(gc != NULL);
|
|
100
|
|
101 gc->flags |= GAIM_CONNECTION_HTML | GAIM_CONNECTION_NO_BGCOLOR | GAIM_CONNECTION_AUTO_RESP;
|
|
102
|
|
103 qd = g_new0(qq_data, 1);
|
|
104 gc->proto_data = qd;
|
|
105
|
|
106 qq_server = gaim_account_get_string(account, "server", NULL);
|
|
107 qq_port = gaim_account_get_string(account, "port", NULL);
|
|
108 use_tcp = gaim_account_get_bool(account, "use_tcp", FALSE);
|
|
109 presence = gaim_account_get_presence(account);
|
|
110 login_hidden = gaim_presence_is_status_primitive_active(presence, GAIM_STATUS_INVISIBLE);
|
|
111
|
|
112 qd->use_tcp = use_tcp;
|
|
113
|
|
114 if (login_hidden) {
|
|
115 qd->login_mode = QQ_LOGIN_MODE_HIDDEN;
|
|
116 gaim_debug(GAIM_DEBUG_INFO, "QQ", "Login in hidden mode\n");
|
|
117 }
|
|
118 else {
|
|
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 */
|
|
137 static void _qq_close(GaimConnection * gc)
|
|
138 {
|
|
139 g_return_if_fail(gc != NULL);
|
|
140 qq_disconnect(gc);
|
|
141 }
|
|
142
|
|
143 /* returns the icon name for a buddy or protocol */
|
|
144 static const gchar *_qq_list_icon(GaimAccount * a, GaimBuddy * b)
|
|
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);
|
|
219 */
|
|
220 // having_video = q_bud->comm_flag & QQ_COMM_FLAG_VIDEO;
|
|
221 // if (having_video)
|
|
222 // g_string_append(status, " (video)");
|
|
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;
|
13989
|
235 //gchar *country, *country_utf8, *city, *city_utf8;
|
|
236 //guint32 ip_value;
|
13870
|
237 gchar *ip_str;
|
|
238
|
|
239 g_return_if_fail(b != NULL);
|
|
240
|
|
241 q_bud = (qq_buddy *) b->proto_data;
|
13989
|
242 //g_return_if_fail(q_bud != NULL);
|
13870
|
243
|
13989
|
244 if (GAIM_BUDDY_IS_ONLINE(b) && q_bud != NULL)
|
13870
|
245 {
|
13989
|
246 /*
|
13870
|
247 ip_value = ntohl(*(guint32 *) (q_bud->ip));
|
|
248 if (qq_ip_get_location(ip_value, &country, &city)) {
|
|
249 country_utf8 = qq_to_utf8(country, QQ_CHARSET_DEFAULT);
|
|
250 city_utf8 = qq_to_utf8(city, QQ_CHARSET_DEFAULT);
|
|
251 g_string_append_printf(tooltip, "\n%s, %s", country_utf8, city_utf8);
|
|
252 g_free(country);
|
|
253 g_free(city);
|
|
254 g_free(country_utf8);
|
|
255 g_free(city_utf8);
|
|
256 }
|
13989
|
257 */
|
13870
|
258 ip_str = gen_ip_str(q_bud->ip);
|
13989
|
259 if (strlen(ip_str) != 0) {
|
|
260 g_string_append_printf(tooltip, "\n<b>%s Address:</b> %s:%d", (q_bud->comm_flag & QQ_COMM_FLAG_TCP_MODE)
|
13870
|
261 ? "TCP" : "UDP", ip_str, q_bud->port);
|
13989
|
262 }
|
13870
|
263 g_free(ip_str);
|
|
264 g_string_append_printf(tooltip, "\n<b>Age:</b> %d", q_bud->age);
|
|
265 switch (q_bud->gender) {
|
|
266 case QQ_BUDDY_GENDER_GG:
|
|
267 g_string_append(tooltip, "\n<b>Gender:</b> GG");
|
|
268 break;
|
|
269 case QQ_BUDDY_GENDER_MM:
|
|
270 g_string_append(tooltip, "\n<b>Gender:</b> MM");
|
|
271 break;
|
|
272 case QQ_BUDDY_GENDER_UNKNOWN:
|
|
273 g_string_append(tooltip, "\n<b>Gender:</b> UNKNOWN");
|
|
274 break;
|
|
275 default:
|
|
276 g_string_append_printf(tooltip, "\n<b>Gender:</b> ERROR(%d)", q_bud->gender);
|
|
277 } /* switch gender */
|
|
278 g_string_append_printf(tooltip, "\n<b>Flag:</b> %01x", q_bud->flag1);
|
|
279 g_string_append_printf(tooltip, "\n<b>CommFlag:</b> %01x", q_bud->comm_flag);
|
|
280 g_string_append_printf(tooltip, "\n<b>Client:</b> %04x", q_bud->client_version);
|
|
281 }
|
|
282 }
|
|
283
|
|
284 /* we can show tiny icons on the four corners of buddy icon, */
|
13989
|
285 static void _qq_list_emblems(GaimBuddy * b, const char **se, const char **sw, const char **nw, const char **ne) {
|
13870
|
286 // each char ** are refering to filename in pixmaps/gaim/status/default/*png
|
|
287
|
|
288 qq_buddy *q_bud = b->proto_data;
|
|
289 const char *emblems[4] = { NULL, NULL, NULL, NULL };
|
|
290 int i = 0;
|
|
291
|
|
292 if (q_bud == NULL)
|
|
293 {
|
|
294 emblems[0] = "offline";
|
|
295 }
|
|
296 else
|
|
297 {
|
|
298 if (q_bud->comm_flag & QQ_COMM_FLAG_QQ_MEMBER)
|
|
299 emblems[i++] = "qq_member";
|
|
300 if (q_bud->comm_flag & QQ_COMM_FLAG_BIND_MOBILE)
|
|
301 emblems[i++] = "wireless";
|
|
302 if (q_bud->comm_flag & QQ_COMM_FLAG_VIDEO)
|
|
303 emblems[i++] = "video";
|
|
304
|
|
305 }
|
|
306
|
|
307 *se = emblems[0];
|
|
308 *sw = emblems[1];
|
|
309 *nw = emblems[2];
|
|
310 *ne = emblems[3];
|
|
311
|
|
312 return;
|
|
313 }
|
|
314
|
|
315 /* QQ away status (used to initiate QQ away packet) */
|
|
316 static GList *_qq_away_states(GaimAccount *ga)
|
|
317 {
|
|
318 GaimStatusType *status;
|
|
319 GList *types = NULL;
|
|
320
|
|
321 status = gaim_status_type_new_full(GAIM_STATUS_AVAILABLE,
|
|
322 "available", _("QQ: Available"), FALSE, TRUE, FALSE);
|
|
323 types = g_list_append(types, status);
|
|
324
|
|
325 status = gaim_status_type_new_full(GAIM_STATUS_AWAY,
|
|
326 "away", _("QQ: Away"), FALSE, TRUE, FALSE);
|
|
327 types = g_list_append(types, status);
|
|
328
|
13989
|
329 status = gaim_status_type_new_full(GAIM_STATUS_INVISIBLE,
|
13870
|
330 "invisible", _("QQ: Invisible"), FALSE, TRUE, FALSE);
|
|
331 types = g_list_append(types, status);
|
|
332
|
|
333 status = gaim_status_type_new_full(GAIM_STATUS_OFFLINE,
|
|
334 "offline", _("QQ: Offline"), FALSE, TRUE, FALSE);
|
|
335 types = g_list_append(types, status);
|
|
336
|
|
337 return types;
|
|
338 }
|
|
339
|
|
340 /* initiate QQ away with proper change_status packet */
|
|
341 static void _qq_set_away(GaimAccount *account, GaimStatus *status)
|
|
342 {
|
|
343 GaimConnection *gc = gaim_account_get_connection(account);
|
|
344 const char *state = gaim_status_get_id(status);
|
|
345
|
|
346 qq_data *qd;
|
|
347
|
|
348
|
|
349 g_return_if_fail(gc != NULL && gc->proto_data != NULL);
|
|
350
|
|
351 qd = (qq_data *) gc->proto_data;
|
|
352
|
|
353 if(0 == strcmp(state, "available"))
|
|
354 qd->status = QQ_SELF_STATUS_AVAILABLE;
|
|
355 else if (0 == strcmp(state, "away"))
|
|
356 qd->status = QQ_SELF_STATUS_AWAY;
|
|
357 else if (0 == strcmp(state, "invisible"))
|
|
358 qd->status = QQ_SELF_STATUS_INVISIBLE;
|
|
359 else
|
|
360 qd->status = QQ_SELF_STATUS_AVAILABLE;
|
|
361
|
|
362 qq_send_packet_change_status(gc);
|
|
363 }
|
|
364
|
|
365
|
13989
|
366 // IMPORTANT: GaimConvImFlags -> GaimMessageFlags
|
13870
|
367 /* send an instance msg to a buddy */
|
|
368 static gint _qq_send_im(GaimConnection * gc, const gchar * who, const gchar * message, GaimMessageFlags flags)
|
|
369 {
|
|
370 gint type, to_uid;
|
|
371 gchar *msg, *msg_with_qq_smiley;
|
|
372 qq_data *qd;
|
|
373
|
|
374 g_return_val_if_fail(gc != NULL && gc->proto_data != NULL && who != NULL, -1);
|
|
375
|
|
376 qd = (qq_data *) gc->proto_data;
|
|
377
|
|
378 g_return_val_if_fail(strlen(message) <= QQ_MSG_IM_MAX, -E2BIG);
|
|
379
|
|
380 type = (flags == GAIM_MESSAGE_AUTO_RESP ? QQ_IM_AUTO_REPLY : QQ_IM_TEXT);
|
|
381 to_uid = gaim_name_to_uid(who);
|
|
382
|
|
383 /* if msg is to myself, bypass the network */
|
|
384 if (to_uid == qd->uid)
|
|
385 serv_got_im(gc, who, message, flags, time(NULL));
|
|
386 else {
|
|
387 msg = utf8_to_qq(message, QQ_CHARSET_DEFAULT);
|
|
388 msg_with_qq_smiley = gaim_smiley_to_qq(msg);
|
|
389 qq_send_packet_im(gc, to_uid, msg_with_qq_smiley, type);
|
|
390 g_free(msg);
|
|
391 g_free(msg_with_qq_smiley);
|
|
392 }
|
|
393
|
|
394 return 1;
|
|
395 }
|
|
396
|
|
397 /* send a chat msg to a QQ Qun */
|
13989
|
398 static int _qq_chat_send(GaimConnection *gc, int channel, const char *message, GaimMessageFlags flags)
|
13870
|
399 {
|
|
400 gchar *msg, *msg_with_qq_smiley;
|
|
401 qq_group *group;
|
|
402
|
|
403 g_return_val_if_fail(gc != NULL && message != NULL, -1);
|
|
404 g_return_val_if_fail(strlen(message) <= QQ_MSG_IM_MAX, -E2BIG);
|
|
405
|
|
406 group = qq_group_find_by_channel(gc, channel);
|
|
407 g_return_val_if_fail(group != NULL, -1);
|
|
408
|
|
409 msg = utf8_to_qq(message, QQ_CHARSET_DEFAULT);
|
|
410 msg_with_qq_smiley = gaim_smiley_to_qq(msg);
|
|
411 qq_send_packet_group_im(gc, group, msg_with_qq_smiley);
|
|
412 g_free(msg);
|
|
413 g_free(msg_with_qq_smiley);
|
|
414
|
|
415 return 1;
|
|
416 }
|
|
417
|
|
418 /* send packet to get who's detailed information */
|
|
419 static void _qq_get_info(GaimConnection * gc, const gchar * who)
|
|
420 {
|
|
421 guint32 uid;
|
|
422 qq_data *qd;
|
|
423
|
|
424 g_return_if_fail(gc != NULL && gc->proto_data != NULL);
|
|
425 qd = gc->proto_data;
|
|
426 uid = gaim_name_to_uid(who);
|
|
427
|
|
428 if (uid <= 0) {
|
|
429 gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Not valid QQid: %s\n", who);
|
|
430 gaim_notify_error(gc, NULL, _("Invalid name, please input in qq-xxxxxxxx format"), NULL);
|
|
431 return;
|
|
432 }
|
|
433
|
13989
|
434 qq_send_packet_get_info(gc, uid, TRUE);
|
13870
|
435 }
|
|
436
|
|
437 /* get my own information */
|
13989
|
438 static void _qq_menu_modify_my_info(GaimPluginAction * action)
|
13870
|
439 {
|
|
440 GaimConnection *gc = (GaimConnection *) action->context;
|
|
441 qq_data *qd;
|
|
442
|
|
443 g_return_if_fail(gc != NULL && gc->proto_data != NULL);
|
|
444
|
|
445 qd = (qq_data *) gc->proto_data;
|
13989
|
446 //_qq_get_info(gc, uid_to_gaim_name(qd->uid));
|
|
447 qq_prepare_modify_info(gc);
|
13870
|
448 }
|
|
449
|
14014
|
450
|
|
451 static void _qq_menu_change_password(GaimPluginAction * action)
|
|
452 {
|
|
453 gaim_notify_uri(NULL, "https://password.qq.com");
|
|
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 */
|
|
666
|
|
667 /* protocol related menus */
|
|
668 static GList *_qq_actions(GaimPlugin * plugin, gpointer context)
|
|
669 {
|
|
670 GList *m;
|
|
671 GaimPluginAction *act;
|
|
672
|
|
673 m = NULL;
|
13989
|
674 act = gaim_plugin_action_new(_("Modify My Information"), _qq_menu_modify_my_info);
|
13870
|
675 m = g_list_append(m, act);
|
|
676
|
14014
|
677 act = gaim_plugin_action_new(_("Change Password"), _qq_menu_change_password);
|
|
678 m = g_list_append(m, act);
|
|
679
|
13870
|
680 act = gaim_plugin_action_new(_("Show Login Information"), _qq_menu_show_login_info);
|
|
681 m = g_list_append(m, act);
|
|
682
|
13989
|
683 /* XXX consider re-enabling this
|
13870
|
684 act = gaim_plugin_action_new(_("Show System Message"), _qq_menu_show_system_message);
|
|
685 m = g_list_append(m, act);
|
13989
|
686 */
|
13870
|
687
|
13989
|
688 /* XXX the old group gtk code needs to moved to the gaim UI before this can be used
|
13870
|
689 act = gaim_plugin_action_new(_("Qun: Search a permanent Qun"), _qq_menu_search_or_add_permanent_group);
|
|
690 m = g_list_append(m, act);
|
|
691
|
|
692 act = gaim_plugin_action_new(_("Qun: Create a permanent Qun"), _qq_menu_create_permanent_group);
|
|
693 m = g_list_append(m, act);
|
13989
|
694 */
|
13870
|
695
|
13989
|
696 /* XXX consider re-enabling this
|
13870
|
697 act = gaim_plugin_action_new(_("Locate an IP"), _qq_menu_locate_ip);
|
|
698 m = g_list_append(m, act);
|
13989
|
699 */
|
13870
|
700
|
|
701 return m;
|
|
702 }
|
|
703
|
|
704 /* chat-related (QQ Qun) menu shown up with right-click */
|
13989
|
705 /* XXX re-enable this
|
|
706 static GList *_qq_chat_menu(GaimBlistNode *node)
|
13870
|
707 {
|
|
708 GList *m;
|
|
709 GaimMenuAction *act;
|
|
710
|
|
711 m = NULL;
|
13989
|
712 act = gaim_menu_action_new(_("Exit this QQ Qun"), GAIM_CALLBACK(_qq_menu_unsubscribe_group), NULL, NULL);
|
13870
|
713 m = g_list_append(m, act);
|
|
714
|
13989
|
715 act = gaim_menu_action_new(_("Show Details"), GAIM_CALLBACK(_qq_menu_manage_group), NULL, NULL);
|
13870
|
716 m = g_list_append(m, act);
|
|
717
|
|
718 return m;
|
|
719 }
|
13989
|
720 */
|
13870
|
721 /* buddy-related menu shown up with right-click */
|
13989
|
722 /* XXX re-enable this
|
13870
|
723 static GList *_qq_buddy_menu(GaimBlistNode * node)
|
|
724 {
|
|
725 GList *m;
|
|
726
|
13989
|
727 if(GAIM_BLIST_NODE_IS_CHAT(node))
|
13870
|
728 return _qq_chat_menu(node);
|
|
729
|
|
730 m = NULL;
|
13989
|
731 */
|
13870
|
732 /* TODO : not working, temp commented out by gfhuang
|
|
733
|
|
734 act = gaim_menu_action_new(_("Block this buddy"), GAIM_CALLBACK(_qq_menu_block_buddy), NULL, NULL); //add NULL by gfhuang
|
|
735 m = g_list_append(m, act);
|
|
736 // if (q_bud && is_online(q_bud->status)) {
|
|
737 act = gaim_menu_action_new(_("Send File"), GAIM_CALLBACK(_qq_menu_send_file), NULL, NULL); //add NULL by gfhuang
|
|
738 m = g_list_append(m, act);
|
|
739 // }
|
|
740 */
|
13989
|
741 /*
|
13870
|
742 return m;
|
|
743 }
|
13989
|
744 */
|
13870
|
745
|
|
746
|
|
747 static void _qq_keep_alive(GaimConnection * gc)
|
|
748 {
|
|
749 qq_group *group;
|
|
750 qq_data *qd;
|
|
751 GList *list;
|
|
752
|
|
753 g_return_if_fail(gc != NULL);
|
|
754 if (NULL == (qd = (qq_data *) gc->proto_data))
|
|
755 return;
|
|
756
|
|
757 list = qd->groups;
|
|
758 while (list != NULL) {
|
|
759 group = (qq_group *) list->data;
|
|
760 if (group->my_status == QQ_GROUP_MEMBER_STATUS_IS_MEMBER ||
|
|
761 group->my_status == QQ_GROUP_MEMBER_STATUS_IS_ADMIN)
|
13989
|
762 // no need to get info time and time again, online members enough
|
13870
|
763 qq_send_cmd_group_get_online_member(gc, group);
|
|
764
|
|
765 list = list->next;
|
|
766 }
|
|
767
|
|
768 qq_send_packet_keep_alive(gc);
|
|
769
|
|
770 }
|
|
771
|
|
772 /* convert chat nickname to qq-uid to get this buddy info */
|
|
773 /* who is the nickname of buddy in QQ chat-room (Qun) */
|
|
774 static void _qq_get_chat_buddy_info(GaimConnection * gc, gint channel, const gchar * who)
|
|
775 {
|
|
776 gchar *gaim_name;
|
|
777 g_return_if_fail(gc != NULL && gc->proto_data != NULL && who != NULL);
|
|
778
|
|
779 gaim_name = qq_group_find_member_by_channel_and_nickname(gc, channel, who);
|
|
780 if (gaim_name != NULL)
|
|
781 _qq_get_info(gc, gaim_name);
|
|
782
|
|
783 }
|
|
784
|
|
785 /* convert chat nickname to qq-uid to invite individual IM to buddy */
|
|
786 /* who is the nickname of buddy in QQ chat-room (Qun) */
|
|
787 static gchar *_qq_get_chat_buddy_real_name(GaimConnection * gc, gint channel, const gchar * who)
|
|
788 {
|
|
789 g_return_val_if_fail(gc != NULL && gc->proto_data != NULL && who != NULL, NULL);
|
|
790 return qq_group_find_member_by_channel_and_nickname(gc, channel, who);
|
|
791
|
|
792 }
|
|
793
|
|
794 void qq_function_not_implemented(GaimConnection * gc)
|
|
795 {
|
|
796 gaim_notify_warning(gc, NULL, _("This function has not be implemented yet"), _("Please wait for new version"));
|
|
797 }
|
|
798
|
|
799 GaimPlugin *my_protocol = NULL;
|
|
800 static GaimPluginProtocolInfo prpl_info = {
|
|
801 OPT_PROTO_CHAT_TOPIC | OPT_PROTO_USE_POINTSIZE,
|
|
802 NULL, /* user_splits */
|
|
803 NULL, /* protocol_options */
|
|
804 NO_BUDDY_ICONS, /* icon_spec */
|
|
805 _qq_list_icon, /* list_icon */
|
|
806 _qq_list_emblems, /* list_emblems */
|
|
807 _qq_status_text, /* status_text */
|
|
808 _qq_tooltip_text, /* tooltip_text */
|
|
809 _qq_away_states, /* away_states */
|
13989
|
810 NULL, /* blist_node_menu */
|
13870
|
811 qq_chat_info, /* chat_info */
|
|
812 NULL, /* chat_info_defaults */
|
|
813 _qq_login, /* login */
|
|
814 _qq_close, /* close */
|
|
815 _qq_send_im, /* send_im */
|
|
816 NULL, /* set_info */
|
|
817 NULL, /* send_typing */
|
|
818 _qq_get_info, /* get_info */
|
|
819 _qq_set_away, /* set_away */
|
|
820 NULL, /* set_idle */
|
|
821 NULL, /* change_passwd */
|
|
822 qq_add_buddy, /* add_buddy */
|
|
823 NULL, /* add_buddies */
|
|
824 qq_remove_buddy, /* remove_buddy */
|
|
825 NULL, /* remove_buddies */
|
|
826 NULL, /* add_permit */
|
|
827 NULL, /* add_deny */
|
|
828 NULL, /* rem_permit */
|
|
829 NULL, /* rem_deny */
|
|
830 NULL, /* set_permit_deny */
|
|
831 qq_group_join, /* join_chat */
|
|
832 NULL, /* reject chat invite */
|
|
833 NULL, /* get_chat_name */
|
|
834 NULL, /* chat_invite */
|
|
835 NULL, /* chat_leave */
|
|
836 NULL, /* chat_whisper */
|
|
837 _qq_chat_send, /* chat_send */
|
|
838 _qq_keep_alive, /* keepalive */
|
|
839 NULL, /* register_user */
|
|
840 _qq_get_chat_buddy_info, /* get_cb_info */
|
|
841 NULL, /* get_cb_away */
|
|
842 NULL, /* alias_buddy */
|
|
843 NULL, /* group_buddy */
|
|
844 NULL, /* rename_group */
|
|
845 NULL, /* buddy_free */
|
|
846 NULL, /* convo_closed */
|
|
847 NULL, /* normalize */
|
|
848 NULL, /* set_buddy_icon */
|
|
849 NULL, /* remove_group */
|
|
850 _qq_get_chat_buddy_real_name, /* get_cb_real_name */
|
|
851 NULL, /* set_chat_topic */
|
|
852 NULL, /* find_blist_chat */
|
|
853 qq_roomlist_get_list, /* roomlist_get_list */
|
|
854 qq_roomlist_cancel, /* roomlist_cancel */
|
|
855 NULL, /* roomlist_expand_category */
|
13989
|
856 NULL, /* can_receive_file */
|
|
857 qq_send_file, /* send_file */
|
|
858 NULL, /* new xfer */
|
|
859 NULL, /* offline_message */
|
|
860 NULL, /* GaimWhiteboardPrplOps */
|
13870
|
861 };
|
|
862
|
|
863 static GaimPluginInfo info = {
|
|
864 GAIM_PLUGIN_MAGIC,
|
|
865 GAIM_MAJOR_VERSION,
|
|
866 GAIM_MINOR_VERSION,
|
|
867 GAIM_PLUGIN_PROTOCOL, /**< type */
|
|
868 NULL, /**< ui_requirement */
|
|
869 0, /**< flags */
|
|
870 NULL, /**< dependencies */
|
|
871 GAIM_PRIORITY_DEFAULT, /**< priority */
|
|
872
|
|
873 "prpl-qq", /**< id */
|
|
874 "QQ", /**< name */
|
|
875 VERSION, /**< version */
|
|
876 /** summary */
|
|
877 N_("QQ Protocol Plugin"),
|
|
878 /** description */
|
|
879 N_("QQ Protocol Plugin"),
|
|
880 OPENQ_AUTHOR, /**< author */
|
|
881 OPENQ_WEBSITE, /**< homepage */
|
|
882
|
|
883 NULL, /**< load */
|
|
884 NULL, /**< unload */
|
|
885 NULL, /**< destroy */
|
|
886
|
|
887 NULL, /**< ui_info */
|
|
888 &prpl_info, /**< extra_info */
|
|
889 NULL, /**< prefs_info */
|
|
890 _qq_actions
|
|
891 };
|
|
892
|
|
893
|
|
894 static void init_plugin(GaimPlugin * plugin)
|
|
895 {
|
|
896 GaimAccountOption *option;
|
|
897
|
|
898 bindtextdomain(PACKAGE, LOCALEDIR);
|
|
899 bind_textdomain_codeset(PACKAGE, "UTF-8");
|
|
900
|
|
901 option = gaim_account_option_bool_new(_("Login in TCP"), "use_tcp", FALSE);
|
|
902 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
|
|
903
|
|
904 option = gaim_account_option_bool_new(_("Login Hidden"), "hidden", FALSE);
|
|
905 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
|
|
906
|
|
907 option = gaim_account_option_string_new(_("QQ Server"), "server", NULL);
|
|
908 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
|
|
909
|
|
910 option = gaim_account_option_string_new(_("QQ Port"), "port", NULL);
|
|
911 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
|
|
912
|
|
913 my_protocol = plugin;
|
|
914
|
|
915 gaim_prefs_add_none("/plugins/prpl/qq");
|
|
916 gaim_prefs_add_string("/plugins/prpl/qq/ipfile", "");
|
|
917 gaim_prefs_add_bool("/plugins/prpl/qq/show_status_by_icon", TRUE);
|
|
918 gaim_prefs_add_bool("/plugins/prpl/qq/show_fake_video", FALSE);
|
|
919 gaim_prefs_add_string("/plugins/prpl/qq/datadir", DATADIR);
|
|
920 gaim_prefs_add_bool("/plugins/prpl/qq/prompt_for_missing_packet", TRUE);
|
|
921 gaim_prefs_add_bool("/plugins/prpl/qq/prompt_group_msg_on_recv", TRUE);
|
|
922 }
|
|
923
|
|
924 GAIM_INIT_PLUGIN(qq, init_plugin, info);
|