comparison src/protocols/qq/qq.c @ 14021:ef8490f9e823

[gaim-migrate @ 16618] Replaced all C++-style comments with C-style ones. Cleaned up some comments and implemented a more consistent formatting scheme. committer: Tailor Script <tailor@pidgin.im>
author Mark Huetsch <markhuetsch>
date Wed, 02 Aug 2006 15:35:36 +0000
parents 39d6d4128599
children 8bda65b88e49
comparison
equal deleted inserted replaced
14020:13e7ba964993 14021:ef8490f9e823
24 24
25 #ifdef _WIN32 25 #ifdef _WIN32
26 #define random rand 26 #define random rand
27 #endif 27 #endif
28 28
29 #include "accountopt.h"
29 #include "debug.h" 30 #include "debug.h"
30 #include "notify.h" 31 #include "notify.h"
31 #include "prefs.h" 32 #include "prefs.h"
33 #include "prpl.h"
32 #include "request.h" 34 #include "request.h"
33 #include "accountopt.h"
34 #include "prpl.h"
35 #include "server.h" 35 #include "server.h"
36 #include "util.h" /* GaimMenuAction, gaim_menu_action_new */ 36 #include "util.h"
37 37
38 #include "utils.h"
39 #include "buddy_info.h" 38 #include "buddy_info.h"
40 #include "buddy_opt.h" 39 #include "buddy_opt.h"
41 #include "buddy_status.h" 40 #include "buddy_status.h"
42 #include "char_conv.h" 41 #include "char_conv.h"
43 #include "group_find.h" /* qq_group_find_member_by_channel_and_nickname */ 42 #include "group.h"
44 #include "group_im.h" /* qq_send_packet_group_im */ 43 #include "group_find.h"
45 #include "group_info.h" /* qq_send_cmd_group_get_group_info */ 44 #include "group_im.h"
46 #include "group_join.h" /* qq_group_join */ 45 #include "group_info.h"
47 #include "group_opt.h" /* qq_group_manage_members */ 46 #include "group_join.h"
48 #include "group.h" /* chat_info, etc */ 47 #include "group_opt.h"
49 #include "header_info.h" /* qq_get_cmd_desc */ 48 #include "header_info.h"
50 #include "im.h" 49 #include "im.h"
50 #include "ip_location.h"
51 #include "keep_alive.h" 51 #include "keep_alive.h"
52 #include "ip_location.h" /* qq_ip_get_location */
53 #include "login_logout.h" 52 #include "login_logout.h"
54 #include "packet_parse.h" /* MAX_PACKET_SIZE */ 53 #include "packet_parse.h"
55 #include "qq_proxy.h" /* qq_connect, qq_disconnect */ 54 #include "qq.h"
55 #include "qq_proxy.h"
56 #include "send_core.h" 56 #include "send_core.h"
57 #include "qq.h"
58 #include "send_file.h" 57 #include "send_file.h"
58 #include "utils.h"
59 #include "version.h" 59 #include "version.h"
60 60
61 #define OPENQ_AUTHOR "Puzzlebird" 61 #define OPENQ_AUTHOR "Puzzlebird"
62 #define OPENQ_WEBSITE "http://openq.sourceforge.net" 62 #define OPENQ_WEBSITE "http://openq.sourceforge.net"
63 #define QQ_TCP_QUERY_PORT "8000" 63 #define QQ_TCP_QUERY_PORT "8000"
64 #define QQ_UDP_PORT "8000" 64 #define QQ_UDP_PORT "8000"
65 65
66 const gchar *udp_server_list[] = { 66 const gchar *udp_server_list[] = {
67 "sz.tencent.com", // 61.144.238.145 67 "sz.tencent.com", /* 61.144.238.145 */
68 "sz2.tencent.com", // 61.144.238.146 68 "sz2.tencent.com", /* 61.144.238.146 */
69 "sz3.tencent.com", // 202.104.129.251 69 "sz3.tencent.com", /* 202.104.129.251 */
70 "sz4.tencent.com", // 202.104.129.254 70 "sz4.tencent.com", /* 202.104.129.254 */
71 "sz5.tencent.com", // 61.141.194.203 71 "sz5.tencent.com", /* 61.141.194.203 */
72 "sz6.tencent.com", // 202.104.129.252 72 "sz6.tencent.com", /* 202.104.129.252 */
73 "sz7.tencent.com", // 202.104.129.253 73 "sz7.tencent.com", /* 202.104.129.253 */
74 "202.96.170.64", 74 "202.96.170.64",
75 "64.144.238.155", 75 "64.144.238.155",
76 "202.104.129.254" 76 "202.104.129.254"
77 }; 77 };
78 const gint udp_server_amount = (sizeof(udp_server_list) / sizeof(udp_server_list[0])); 78 const gint udp_server_amount = (sizeof(udp_server_list) / sizeof(udp_server_list[0]));
79 79
80 80
81 const gchar *tcp_server_list[] = { 81 const gchar *tcp_server_list[] = {
82 "tcpconn.tencent.com", // 218.17.209.23 82 "tcpconn.tencent.com", /* 218.17.209.23 */
83 "tcpconn2.tencent.com", // 218.18.95.153 83 "tcpconn2.tencent.com", /* 218.18.95.153 */
84 "tcpconn3.tencent.com", // 218.17.209.23 84 "tcpconn3.tencent.com", /* 218.17.209.23 */
85 "tcpconn4.tencent.com", // 218.18.95.153 85 "tcpconn4.tencent.com" /* 218.18.95.153 */
86 }; 86 };
87 const gint tcp_server_amount = (sizeof(tcp_server_list) / sizeof(tcp_server_list[0])); 87 const gint tcp_server_amount = (sizeof(tcp_server_list) / sizeof(tcp_server_list[0]));
88 88
89 static void _qq_login(GaimAccount * account) 89 static void _qq_login(GaimAccount *account)
90 { 90 {
91 const gchar *qq_server, *qq_port; 91 const gchar *qq_server, *qq_port;
92 qq_data *qd; 92 qq_data *qd;
93 GaimConnection *gc; 93 GaimConnection *gc;
94 GaimPresence *presence; 94 GaimPresence *presence;
113 qd->use_tcp = use_tcp; 113 qd->use_tcp = use_tcp;
114 114
115 if (login_hidden) { 115 if (login_hidden) {
116 qd->login_mode = QQ_LOGIN_MODE_HIDDEN; 116 qd->login_mode = QQ_LOGIN_MODE_HIDDEN;
117 gaim_debug(GAIM_DEBUG_INFO, "QQ", "Login in hidden mode\n"); 117 gaim_debug(GAIM_DEBUG_INFO, "QQ", "Login in hidden mode\n");
118 } 118 } else {
119 else {
120 qd->login_mode = QQ_LOGIN_MODE_NORMAL; 119 qd->login_mode = QQ_LOGIN_MODE_NORMAL;
121 gaim_debug(GAIM_DEBUG_INFO, "QQ", "Login in normal mode\n"); 120 gaim_debug(GAIM_DEBUG_INFO, "QQ", "Login in normal mode\n");
122 } 121 }
123 122
124 if (qq_server == NULL || strlen(qq_server) == 0) 123 if (qq_server == NULL || strlen(qq_server) == 0)
133 if (qq_connect(account, qq_server, strtol(qq_port, NULL, 10), use_tcp, FALSE) < 0) 132 if (qq_connect(account, qq_server, strtol(qq_port, NULL, 10), use_tcp, FALSE) < 0)
134 gaim_connection_error(gc, _("Unable to connect.")); 133 gaim_connection_error(gc, _("Unable to connect."));
135 } 134 }
136 135
137 /* directly goes for qq_disconnect */ 136 /* directly goes for qq_disconnect */
138 static void _qq_close(GaimConnection * gc) 137 static void _qq_close(GaimConnection *gc)
139 { 138 {
140 g_return_if_fail(gc != NULL); 139 g_return_if_fail(gc != NULL);
141 qq_disconnect(gc); 140 qq_disconnect(gc);
142 } 141 }
143 142
144 /* returns the icon name for a buddy or protocol */ 143 /* returns the icon name for a buddy or protocol */
145 static const gchar *_qq_list_icon(GaimAccount * a, GaimBuddy * b) 144 static const gchar *_qq_list_icon(GaimAccount *a, GaimBuddy *b)
146 { 145 {
147 /* XXX temp commented out until we figure out what to do with 146 /* XXX temp commented out until we figure out what to do with
148 * status icons */ 147 * status icons */
149 /* 148 /*
150 gchar *filename; 149 gchar *filename;
215 g_string_append(status, "^_^"); 214 g_string_append(status, "^_^");
216 } 215 }
217 216
218 g_string_append_printf(status, " Age: %d", q_bud->age); 217 g_string_append_printf(status, " Age: %d", q_bud->age);
219 g_string_append_printf(status, " Client: %04x", q_bud->client_version); 218 g_string_append_printf(status, " Client: %04x", q_bud->client_version);
219 having_video = q_bud->comm_flag & QQ_COMM_FLAG_VIDEO;
220 if (having_video)
221 g_string_append(status, " (video)");
220 */ 222 */
221 // having_video = q_bud->comm_flag & QQ_COMM_FLAG_VIDEO;
222 // if (having_video)
223 // g_string_append(status, " (video)");
224 223
225 ret = status->str; 224 ret = status->str;
226 g_string_free(status, FALSE); 225 g_string_free(status, FALSE);
227 226
228 return ret; 227 return ret;
231 230
232 /* a floating text when mouse is on the icon, show connection status here */ 231 /* 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) 232 static void _qq_tooltip_text(GaimBuddy *b, GString *tooltip, gboolean full)
234 { 233 {
235 qq_buddy *q_bud; 234 qq_buddy *q_bud;
236 //gchar *country, *country_utf8, *city, *city_utf8; 235 /* gchar *country, *country_utf8, *city, *city_utf8;
237 //guint32 ip_value; 236 guint32 ip_value;
237 */
238 gchar *ip_str; 238 gchar *ip_str;
239 239
240 g_return_if_fail(b != NULL); 240 g_return_if_fail(b != NULL);
241 241
242 q_bud = (qq_buddy *) b->proto_data; 242 q_bud = (qq_buddy *) b->proto_data;
243 //g_return_if_fail(q_bud != NULL); 243 /* g_return_if_fail(q_bud != NULL); */
244 244
245 if (GAIM_BUDDY_IS_ONLINE(b) && q_bud != NULL) 245 if (GAIM_BUDDY_IS_ONLINE(b) && q_bud != NULL)
246 { 246 {
247 /* 247 /*
248 ip_value = ntohl(*(guint32 *) (q_bud->ip)); 248 ip_value = ntohl(*(guint32 *) (q_bud->ip));
281 g_string_append_printf(tooltip, "\n<b>Client:</b> %04x", q_bud->client_version); 281 g_string_append_printf(tooltip, "\n<b>Client:</b> %04x", q_bud->client_version);
282 } 282 }
283 } 283 }
284 284
285 /* we can show tiny icons on the four corners of buddy icon, */ 285 /* we can show tiny icons on the four corners of buddy icon, */
286 static void _qq_list_emblems(GaimBuddy * b, const char **se, const char **sw, const char **nw, const char **ne) { 286 static void _qq_list_emblems(GaimBuddy *b, const char **se, const char **sw, const char **nw, const char **ne)
287 // each char ** are refering to filename in pixmaps/gaim/status/default/*png 287 {
288 /* each char ** are refering to filename in pixmaps/gaim/status/default/ *png */
288 289
289 qq_buddy *q_bud = b->proto_data; 290 qq_buddy *q_bud = b->proto_data;
290 const char *emblems[4] = { NULL, NULL, NULL, NULL }; 291 const char *emblems[4] = { NULL, NULL, NULL, NULL };
291 int i = 0; 292 int i = 0;
292 293
293 if (q_bud == NULL) 294 if (q_bud == NULL) {
294 {
295 emblems[0] = "offline"; 295 emblems[0] = "offline";
296 } 296 } else {
297 else
298 {
299 if (q_bud->comm_flag & QQ_COMM_FLAG_QQ_MEMBER) 297 if (q_bud->comm_flag & QQ_COMM_FLAG_QQ_MEMBER)
300 emblems[i++] = "qq_member"; 298 emblems[i++] = "qq_member";
301 if (q_bud->comm_flag & QQ_COMM_FLAG_BIND_MOBILE) 299 if (q_bud->comm_flag & QQ_COMM_FLAG_BIND_MOBILE)
302 emblems[i++] = "wireless"; 300 emblems[i++] = "wireless";
303 if (q_bud->comm_flag & QQ_COMM_FLAG_VIDEO) 301 if (q_bud->comm_flag & QQ_COMM_FLAG_VIDEO)
361 qd->status = QQ_SELF_STATUS_AVAILABLE; 359 qd->status = QQ_SELF_STATUS_AVAILABLE;
362 360
363 qq_send_packet_change_status(gc); 361 qq_send_packet_change_status(gc);
364 } 362 }
365 363
366 364 /* IMPORTANT: GaimConvImFlags -> GaimMessageFlags */
367 // IMPORTANT: GaimConvImFlags -> GaimMessageFlags 365 /* send an instant msg to a buddy */
368 /* send an instance msg to a buddy */ 366 static gint _qq_send_im(GaimConnection *gc, const gchar *who, const gchar *message, GaimMessageFlags flags)
369 static gint _qq_send_im(GaimConnection * gc, const gchar * who, const gchar * message, GaimMessageFlags flags)
370 { 367 {
371 gint type, to_uid; 368 gint type, to_uid;
372 gchar *msg, *msg_with_qq_smiley; 369 gchar *msg, *msg_with_qq_smiley;
373 qq_data *qd; 370 qq_data *qd;
374 371
380 377
381 type = (flags == GAIM_MESSAGE_AUTO_RESP ? QQ_IM_AUTO_REPLY : QQ_IM_TEXT); 378 type = (flags == GAIM_MESSAGE_AUTO_RESP ? QQ_IM_AUTO_REPLY : QQ_IM_TEXT);
382 to_uid = gaim_name_to_uid(who); 379 to_uid = gaim_name_to_uid(who);
383 380
384 /* if msg is to myself, bypass the network */ 381 /* if msg is to myself, bypass the network */
385 if (to_uid == qd->uid) 382 if (to_uid == qd->uid) {
386 serv_got_im(gc, who, message, flags, time(NULL)); 383 serv_got_im(gc, who, message, flags, time(NULL));
387 else { 384 } else {
388 msg = utf8_to_qq(message, QQ_CHARSET_DEFAULT); 385 msg = utf8_to_qq(message, QQ_CHARSET_DEFAULT);
389 msg_with_qq_smiley = gaim_smiley_to_qq(msg); 386 msg_with_qq_smiley = gaim_smiley_to_qq(msg);
390 qq_send_packet_im(gc, to_uid, msg_with_qq_smiley, type); 387 qq_send_packet_im(gc, to_uid, msg_with_qq_smiley, type);
391 g_free(msg); 388 g_free(msg);
392 g_free(msg_with_qq_smiley); 389 g_free(msg_with_qq_smiley);
415 412
416 return 1; 413 return 1;
417 } 414 }
418 415
419 /* send packet to get who's detailed information */ 416 /* send packet to get who's detailed information */
420 static void _qq_get_info(GaimConnection * gc, const gchar * who) 417 static void _qq_get_info(GaimConnection *gc, const gchar *who)
421 { 418 {
422 guint32 uid; 419 guint32 uid;
423 qq_data *qd; 420 qq_data *qd;
424 421
425 g_return_if_fail(gc != NULL && gc->proto_data != NULL); 422 g_return_if_fail(gc != NULL && gc->proto_data != NULL);
434 431
435 qq_send_packet_get_info(gc, uid, TRUE); 432 qq_send_packet_get_info(gc, uid, TRUE);
436 } 433 }
437 434
438 /* get my own information */ 435 /* get my own information */
439 static void _qq_menu_modify_my_info(GaimPluginAction * action) 436 static void _qq_menu_modify_my_info(GaimPluginAction *action)
440 { 437 {
441 GaimConnection *gc = (GaimConnection *) action->context; 438 GaimConnection *gc = (GaimConnection *) action->context;
442 qq_data *qd; 439 qq_data *qd;
443 440
444 g_return_if_fail(gc != NULL && gc->proto_data != NULL); 441 g_return_if_fail(gc != NULL && gc->proto_data != NULL);
445 442
446 qd = (qq_data *) gc->proto_data; 443 qd = (qq_data *) gc->proto_data;
447 qq_prepare_modify_info(gc); 444 qq_prepare_modify_info(gc);
448 } 445 }
449 446
450 static void _qq_menu_change_password(GaimPluginAction * action) 447 static void _qq_menu_change_password(GaimPluginAction *action)
451 { 448 {
452 gaim_notify_uri(NULL, "https://password.qq.com"); 449 gaim_notify_uri(NULL, "https://password.qq.com");
453 } 450 }
454 451
455 /* remove a buddy from my list and remove myself from his list */ 452 /* remove a buddy from my list and remove myself from his list */
485 _("Block"), G_CALLBACK(qq_block_buddy_with_gc_and_uid)); 482 _("Block"), G_CALLBACK(qq_block_buddy_with_gc_and_uid));
486 } 483 }
487 */ 484 */
488 485
489 /* show a brief summary of what we get from login packet */ 486 /* show a brief summary of what we get from login packet */
490 static void _qq_menu_show_login_info(GaimPluginAction * action) 487 static void _qq_menu_show_login_info(GaimPluginAction *action)
491 { 488 {
492 GaimConnection *gc = (GaimConnection *) action->context; 489 GaimConnection *gc = (GaimConnection *) action->context;
493 qq_data *qd; 490 qq_data *qd;
494 GString *info; 491 GString *info;
495 492
713 _("Send"), G_CALLBACK(_qq_send_custom_packet), _("Cancel"), NULL, gc); 710 _("Send"), G_CALLBACK(_qq_send_custom_packet), _("Cancel"), NULL, gc);
714 } 711 }
715 */ 712 */
716 713
717 /* protocol related menus */ 714 /* protocol related menus */
718 static GList *_qq_actions(GaimPlugin * plugin, gpointer context) 715 static GList *_qq_actions(GaimPlugin *plugin, gpointer context)
719 { 716 {
720 GList *m; 717 GList *m;
721 GaimPluginAction *act; 718 GaimPluginAction *act;
722 719
723 m = NULL; 720 m = NULL;
797 return m; 794 return m;
798 } 795 }
799 */ 796 */
800 797
801 798
802 static void _qq_keep_alive(GaimConnection * gc) 799 static void _qq_keep_alive(GaimConnection *gc)
803 { 800 {
804 qq_group *group; 801 qq_group *group;
805 qq_data *qd; 802 qq_data *qd;
806 GList *list; 803 GList *list;
807 804
812 list = qd->groups; 809 list = qd->groups;
813 while (list != NULL) { 810 while (list != NULL) {
814 group = (qq_group *) list->data; 811 group = (qq_group *) list->data;
815 if (group->my_status == QQ_GROUP_MEMBER_STATUS_IS_MEMBER || 812 if (group->my_status == QQ_GROUP_MEMBER_STATUS_IS_MEMBER ||
816 group->my_status == QQ_GROUP_MEMBER_STATUS_IS_ADMIN) 813 group->my_status == QQ_GROUP_MEMBER_STATUS_IS_ADMIN)
817 // no need to get info time and time again, online members enough 814 /* no need to get info time and time again, online members enough */
818 qq_send_cmd_group_get_online_member(gc, group); 815 qq_send_cmd_group_get_online_member(gc, group);
819 816
820 list = list->next; 817 list = list->next;
821 } 818 }
822 819
824 821
825 } 822 }
826 823
827 /* convert chat nickname to qq-uid to get this buddy info */ 824 /* convert chat nickname to qq-uid to get this buddy info */
828 /* who is the nickname of buddy in QQ chat-room (Qun) */ 825 /* who is the nickname of buddy in QQ chat-room (Qun) */
829 static void _qq_get_chat_buddy_info(GaimConnection * gc, gint channel, const gchar * who) 826 static void _qq_get_chat_buddy_info(GaimConnection *gc, gint channel, const gchar *who)
830 { 827 {
831 gchar *gaim_name; 828 gchar *gaim_name;
832 g_return_if_fail(gc != NULL && gc->proto_data != NULL && who != NULL); 829 g_return_if_fail(gc != NULL && gc->proto_data != NULL && who != NULL);
833 830
834 gaim_name = qq_group_find_member_by_channel_and_nickname(gc, channel, who); 831 gaim_name = qq_group_find_member_by_channel_and_nickname(gc, channel, who);
835 if (gaim_name != NULL) 832 if (gaim_name != NULL)
836 _qq_get_info(gc, gaim_name); 833 _qq_get_info(gc, gaim_name);
837
838 } 834 }
839 835
840 /* convert chat nickname to qq-uid to invite individual IM to buddy */ 836 /* convert chat nickname to qq-uid to invite individual IM to buddy */
841 /* who is the nickname of buddy in QQ chat-room (Qun) */ 837 /* who is the nickname of buddy in QQ chat-room (Qun) */
842 static gchar *_qq_get_chat_buddy_real_name(GaimConnection * gc, gint channel, const gchar * who) 838 static gchar *_qq_get_chat_buddy_real_name(GaimConnection *gc, gint channel, const gchar *who)
843 { 839 {
844 g_return_val_if_fail(gc != NULL && gc->proto_data != NULL && who != NULL, NULL); 840 g_return_val_if_fail(gc != NULL && gc->proto_data != NULL && who != NULL, NULL);
845 return qq_group_find_member_by_channel_and_nickname(gc, channel, who); 841 return qq_group_find_member_by_channel_and_nickname(gc, channel, who);
846 842 }
847 } 843
848 844 void qq_function_not_implemented(GaimConnection *gc)
849 void qq_function_not_implemented(GaimConnection * gc) 845 {
850 { 846 gaim_notify_warning(gc, NULL,
851 gaim_notify_warning(gc, NULL, _("This function has not be implemented yet"), _("Please wait for new version")); 847 _("This function has not be implemented yet"), _("Please wait for new version"));
852 } 848 }
853 849
854 GaimPlugin *my_protocol = NULL; 850 GaimPlugin *my_protocol = NULL;
855 static GaimPluginProtocolInfo prpl_info = { 851 static GaimPluginProtocolInfo prpl_info = {
856 OPT_PROTO_CHAT_TOPIC | OPT_PROTO_USE_POINTSIZE, 852 OPT_PROTO_CHAT_TOPIC | OPT_PROTO_USE_POINTSIZE,
944 NULL, /**< prefs_info */ 940 NULL, /**< prefs_info */
945 _qq_actions 941 _qq_actions
946 }; 942 };
947 943
948 944
949 static void init_plugin(GaimPlugin * plugin) 945 static void init_plugin(GaimPlugin *plugin)
950 { 946 {
951 GaimAccountOption *option; 947 GaimAccountOption *option;
952 948
953 bindtextdomain(PACKAGE, LOCALEDIR); 949 bindtextdomain(PACKAGE, LOCALEDIR);
954 bind_textdomain_codeset(PACKAGE, "UTF-8"); 950 bind_textdomain_codeset(PACKAGE, "UTF-8");