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