Mercurial > pidgin
comparison libpurple/protocols/qq/qq_process.c @ 24134:bdfcfd71449c
patch 20080922 from ccpaging <ccpaging(at)gmail.com>
author | SHiNE CsyFeK <csyfek@gmail.com> |
---|---|
date | Wed, 22 Oct 2008 14:33:20 +0000 |
parents | d57928c9dd8f |
children | dbc7a9742f8d |
comparison
equal
deleted
inserted
replaced
24133:a3cd7c3d9da1 | 24134:bdfcfd71449c |
---|---|
40 #include "group_im.h" | 40 #include "group_im.h" |
41 #include "group_info.h" | 41 #include "group_info.h" |
42 #include "group_join.h" | 42 #include "group_join.h" |
43 #include "group_opt.h" | 43 #include "group_opt.h" |
44 | 44 |
45 #include "header_info.h" | 45 #include "qq_define.h" |
46 #include "qq_base.h" | 46 #include "qq_base.h" |
47 #include "im.h" | 47 #include "im.h" |
48 #include "qq_process.h" | 48 #include "qq_process.h" |
49 #include "packet_parse.h" | 49 #include "packet_parse.h" |
50 #include "qq_network.h" | 50 #include "qq_network.h" |
174 break; | 174 break; |
175 case QQ_SERVER_NOTICE: | 175 case QQ_SERVER_NOTICE: |
176 _qq_process_msg_sys_notice(gc, from, to, msg_utf8); | 176 _qq_process_msg_sys_notice(gc, from, to, msg_utf8); |
177 break; | 177 break; |
178 case QQ_SERVER_NEW_CLIENT: | 178 case QQ_SERVER_NEW_CLIENT: |
179 purple_debug_warning("QQ", | 179 purple_debug_warning("QQ", "QQ Server has newer client version\n"); |
180 "QQ Server has newer client than %s\n", qq_get_ver_desc(QQ_CLIENT)); | |
181 break; | 180 break; |
182 default: | 181 default: |
183 purple_debug_warning("QQ", "Recv unknown sys msg code: %s\nMsg: %s\n", code, msg_utf8); | 182 purple_debug_warning("QQ", "Recv unknown sys msg code: %s\nMsg: %s\n", code, msg_utf8); |
184 } | 183 } |
185 g_free(msg_utf8); | 184 g_free(msg_utf8); |
405 } | 404 } |
406 } | 405 } |
407 | 406 |
408 void qq_update_online(PurpleConnection *gc, guint16 cmd) | 407 void qq_update_online(PurpleConnection *gc, guint16 cmd) |
409 { | 408 { |
409 qq_data *qd; | |
410 g_return_if_fail (gc != NULL && gc->proto_data != NULL); | |
411 qd = (qq_data *) gc->proto_data; | |
412 | |
410 switch (cmd) { | 413 switch (cmd) { |
411 case 0: | 414 case 0: |
412 qq_request_get_buddies_online(gc, 0, QQ_CMD_CLASS_UPDATE_ONLINE); | 415 qq_request_get_buddies_online(gc, 0, QQ_CMD_CLASS_UPDATE_ONLINE); |
413 break; | 416 break; |
414 case QQ_CMD_GET_BUDDIES_ONLINE: | 417 case QQ_CMD_GET_BUDDIES_ONLINE: |
415 /* last command */ | 418 /* last command */ |
416 update_all_rooms_online(gc, 0, 0); | 419 update_all_rooms_online(gc, 0, 0); |
417 break; | 420 qd->online_last_update = time(NULL); |
418 default: | 421 break; |
419 break; | 422 default: |
420 } | 423 break; |
421 } | 424 } |
422 | 425 } |
423 void qq_proc_room_cmd(PurpleConnection *gc, guint16 seq, | 426 |
427 void qq_proc_room_cmds(PurpleConnection *gc, guint16 seq, | |
424 guint8 room_cmd, guint32 room_id, guint8 *rcved, gint rcved_len, | 428 guint8 room_cmd, guint32 room_id, guint8 *rcved, gint rcved_len, |
425 gint update_class, guint32 ship32) | 429 gint update_class, guint32 ship32) |
426 { | 430 { |
427 qq_data *qd; | 431 qq_data *qd; |
428 guint8 *data; | 432 guint8 *data; |
565 if (update_class == QQ_CMD_CLASS_UPDATE_ROOM) { | 569 if (update_class == QQ_CMD_CLASS_UPDATE_ROOM) { |
566 qq_update_room(gc, room_cmd, room_id); | 570 qq_update_room(gc, room_cmd, room_id); |
567 } | 571 } |
568 } | 572 } |
569 | 573 |
570 void qq_proc_login_cmd(PurpleConnection *gc, guint8 *rcved, gint rcved_len) | 574 guint8 qq_proc_login_cmds(PurpleConnection *gc, guint16 cmd, guint16 seq, |
571 { | 575 guint8 *rcved, gint rcved_len, gint update_class, guint32 ship32) |
572 qq_data *qd; | 576 { |
573 guint8 *data; | 577 qq_data *qd; |
574 gint data_len; | 578 guint8 *data = NULL; |
575 guint ret_8; | 579 gint data_len = 0; |
576 | 580 guint ret_8 = QQ_LOGIN_REPLY_ERR; |
577 g_return_if_fail (gc != NULL && gc->proto_data != NULL); | 581 |
578 qd = (qq_data *) gc->proto_data; | 582 g_return_val_if_fail (gc != NULL && gc->proto_data != NULL, QQ_LOGIN_REPLY_ERR); |
579 | 583 qd = (qq_data *) gc->proto_data; |
584 | |
585 g_return_val_if_fail(rcved_len > 0, QQ_LOGIN_REPLY_ERR); | |
580 data = g_newa(guint8, rcved_len); | 586 data = g_newa(guint8, rcved_len); |
581 /* May use password_twice_md5 in the past version like QQ2005*/ | 587 |
582 data_len = qq_decrypt(data, rcved, rcved_len, qd->inikey); | 588 switch (cmd) { |
583 if (data_len >= 0) { | 589 case QQ_CMD_TOKEN: |
584 purple_debug_warning("QQ", | 590 if (qq_process_token(gc, rcved, rcved_len) == QQ_LOGIN_REPLY_OK) { |
585 "Decrypt login reply packet with inikey, %d bytes\n", data_len); | 591 if (qd->is_above_2007) { |
586 } else { | 592 qq_request_token_ex(gc); |
587 data_len = qq_decrypt(data, rcved, rcved_len, qd->password_twice_md5); | 593 } else { |
588 if (data_len >= 0) { | 594 qq_request_login(gc); |
589 purple_debug_warning("QQ", | 595 } |
590 "Decrypt login reply packet with password_twice_md5, %d bytes\n", data_len); | 596 return QQ_LOGIN_REPLY_OK; |
591 } else { | 597 } |
592 purple_connection_error_reason(gc, PURPLE_CONNECTION_ERROR_NETWORK_ERROR, | 598 return QQ_LOGIN_REPLY_ERR; |
599 case QQ_CMD_GET_SERVER: | |
600 case QQ_CMD_TOKEN_EX: | |
601 data_len = qq_decrypt(data, rcved, rcved_len, qd->ld.init_key); | |
602 break; | |
603 default: | |
604 /* May use password_twice_md5 in the past version like QQ2005 */ | |
605 data_len = qq_decrypt(data, rcved, rcved_len, qd->ld.init_key); | |
606 if (data_len >= 0) { | |
607 purple_debug_warning("QQ", "Decrypt login packet by init_key, %d bytes\n", data_len); | |
608 } else { | |
609 data_len = qq_decrypt(data, rcved, rcved_len, qd->ld.pwd_twice_md5); | |
610 if (data_len >= 0) { | |
611 purple_debug_warning("QQ", "Decrypt login packet by password_twice_md5, %d bytes\n", data_len); | |
612 } | |
613 } | |
614 break; | |
615 } | |
616 | |
617 if (data_len < 0) { | |
618 purple_debug_warning("QQ", | |
619 "Can not decrypt login cmd, [%05d], 0x%04X %s, len %d\n", | |
620 seq, cmd, qq_get_cmd_desc(cmd), rcved_len); | |
621 qq_show_packet("Can not decrypted", rcved, rcved_len); | |
622 purple_connection_error_reason(gc, | |
623 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, | |
593 _("Can not decrypt login reply")); | 624 _("Can not decrypt login reply")); |
594 return; | 625 return QQ_LOGIN_REPLY_ERR_DECRYPT; |
595 } | 626 } |
596 } | 627 |
597 | 628 switch (cmd) { |
598 ret_8 = qq_process_login_reply(gc, data, data_len); | 629 case QQ_CMD_GET_SERVER: |
599 if (ret_8 != QQ_LOGIN_REPLY_OK) { | 630 ret_8 = qq_process_get_server(gc, data, data_len); |
600 return; | 631 if ( ret_8 == QQ_LOGIN_REPLY_OK) { |
601 } | 632 qq_request_token(gc); |
602 | 633 } else if ( ret_8 == QQ_LOGIN_REPLY_REDIRECT) { |
603 purple_debug_info("QQ", "Login repliess OK; everything is fine\n"); | 634 return QQ_LOGIN_REPLY_REDIRECT; |
604 | 635 } |
605 purple_connection_set_state(gc, PURPLE_CONNECTED); | 636 break; |
606 qd->is_login = TRUE; /* must be defined after sev_finish_login */ | 637 case QQ_CMD_TOKEN_EX: |
607 | 638 ret_8 = qq_process_token_ex(gc, data, data_len); |
608 /* now initiate QQ Qun, do it first as it may take longer to finish */ | 639 if (ret_8 == QQ_LOGIN_REPLY_OK) { |
609 qq_group_init(gc); | 640 //qq_request_check_password(gc); |
610 | 641 } else if (ret_8 == QQ_LOGIN_REPLY_NEXT_TOKEN_EX) { |
611 /* is_login, but we have packets before login */ | 642 qq_request_token_ex_next(gc); |
612 qq_trans_process_remained(gc); | 643 } else if (ret_8 == QQ_LOGIN_REPLY_CAPTCHA_DLG) { |
613 | 644 qq_captcha_input_dialog(gc, &(qd->captcha)); |
614 qq_update_all(gc, 0); | 645 g_free(qd->captcha.token); |
615 return; | 646 g_free(qd->captcha.data); |
616 } | 647 memset(&qd->captcha, 0, sizeof(qd->captcha)); |
617 | 648 } |
618 void qq_proc_client_cmd(PurpleConnection *gc, guint16 cmd, guint16 seq, | 649 break; |
650 case QQ_CMD_LOGIN: | |
651 ret_8 = qq_process_login(gc, data, data_len); | |
652 if (ret_8 != QQ_LOGIN_REPLY_OK) { | |
653 return ret_8; | |
654 } | |
655 | |
656 purple_debug_info("QQ", "Login repliess OK; everything is fine\n"); | |
657 purple_connection_set_state(gc, PURPLE_CONNECTED); | |
658 qd->is_login = TRUE; /* must be defined after sev_finish_login */ | |
659 | |
660 /* now initiate QQ Qun, do it first as it may take longer to finish */ | |
661 qq_group_init(gc); | |
662 | |
663 /* is_login, but we have packets before login */ | |
664 qq_trans_process_remained(gc); | |
665 | |
666 qq_update_all(gc, 0); | |
667 break; | |
668 default: | |
669 process_cmd_unknow(gc, _("Unknow LOGIN CMD"), data, data_len, cmd, seq); | |
670 return QQ_LOGIN_REPLY_ERR; | |
671 } | |
672 return QQ_LOGIN_REPLY_OK; | |
673 } | |
674 | |
675 void qq_proc_client_cmds(PurpleConnection *gc, guint16 cmd, guint16 seq, | |
619 guint8 *rcved, gint rcved_len, gint update_class, guint32 ship32) | 676 guint8 *rcved, gint rcved_len, gint update_class, guint32 ship32) |
620 { | 677 { |
621 qq_data *qd; | 678 qq_data *qd; |
622 | 679 |
623 guint8 *data; | 680 guint8 *data; |
708 return; | 765 return; |
709 } | 766 } |
710 purple_debug_info("QQ", "All buddies and groups received\n"); | 767 purple_debug_info("QQ", "All buddies and groups received\n"); |
711 break; | 768 break; |
712 default: | 769 default: |
713 process_cmd_unknow(gc, _("Unknow reply CMD"), data, data_len, cmd, seq); | 770 process_cmd_unknow(gc, _("Unknow CLIENT CMD"), data, data_len, cmd, seq); |
714 is_unknow = TRUE; | 771 is_unknow = TRUE; |
715 break; | 772 break; |
716 } | 773 } |
717 if (is_unknow) | 774 if (is_unknow) |
718 return; | 775 return; |