Mercurial > pidgin
comparison libpurple/protocols/qq/qq_process.c @ 24135:dbc7a9742f8d
2008.09.26 - ccpaging <ccpaging(at)gmail.com>
* Added 'Request/Add/Remove Buddy' functions
author | SHiNE CsyFeK <csyfek@gmail.com> |
---|---|
date | Wed, 22 Oct 2008 14:35:05 +0000 |
parents | bdfcfd71449c |
children | 87e61a85f5dd |
comparison
equal
deleted
inserted
replaced
24134:bdfcfd71449c | 24135:dbc7a9742f8d |
---|---|
80 g_free(msg_utf8); | 80 g_free(msg_utf8); |
81 } | 81 } |
82 } | 82 } |
83 | 83 |
84 /* Send ACK if the sys message needs an ACK */ | 84 /* Send ACK if the sys message needs an ACK */ |
85 static void _qq_send_packet_ack_msg_sys(PurpleConnection *gc, guint8 code, guint32 from, guint16 seq) | 85 static void ack_server_msg(PurpleConnection *gc, guint8 code, guint32 from, guint16 seq) |
86 { | 86 { |
87 qq_data *qd; | 87 qq_data *qd; |
88 guint8 bar, *ack; | 88 guint8 bar, *ack; |
89 gchar *str; | 89 gchar *str; |
90 gint ack_len, bytes; | 90 gint ack_len, bytes; |
110 else | 110 else |
111 purple_debug_error("QQ", | 111 purple_debug_error("QQ", |
112 "Fail creating sys msg ACK, expect %d bytes, build %d bytes\n", ack_len, bytes); | 112 "Fail creating sys msg ACK, expect %d bytes, build %d bytes\n", ack_len, bytes); |
113 } | 113 } |
114 | 114 |
115 static void _qq_process_msg_sys_notice(PurpleConnection *gc, gchar *from, gchar *to, gchar *msg_utf8) | 115 static void process_server_notice(PurpleConnection *gc, gchar *from, gchar *to, gchar *msg_utf8) |
116 { | 116 { |
117 qq_data *qd = (qq_data *) gc->proto_data; | 117 qq_data *qd = (qq_data *) gc->proto_data; |
118 gchar *title, *content; | 118 gchar *title, *content; |
119 | 119 |
120 g_return_if_fail(from != NULL && to != NULL); | 120 g_return_if_fail(from != NULL && to != NULL); |
121 | 121 |
122 title = g_strdup_printf(_("From %s:"), from); | 122 title = g_strdup_printf(_("From %s:"), from); |
123 content = g_strdup_printf(_("%s"), msg_utf8); | 123 content = g_strdup_printf(_("Server notice From %s: \n%s"), from, msg_utf8); |
124 | 124 |
125 if (qd->is_show_notice) { | 125 if (qd->is_show_notice) { |
126 purple_notify_info(gc, _("QQ Server Notice"), title, content); | 126 qq_got_attention(gc, content); |
127 } else { | 127 } else { |
128 purple_debug_info("QQ", "QQ Server notice from %s:\n%s", from, msg_utf8); | 128 purple_debug_info("QQ", "QQ Server notice from %s:\n%s", from, msg_utf8); |
129 } | 129 } |
130 g_free(title); | 130 g_free(title); |
131 g_free(content); | 131 g_free(content); |
132 } | 132 } |
133 | 133 |
134 static void process_server_msg(guint8 *data, gint data_len, guint16 seq, PurpleConnection *gc) | 134 static void process_server_msg(guint8 *data, gint data_len, guint16 seq, PurpleConnection *gc) |
146 code = segments[0]; | 146 code = segments[0]; |
147 from = segments[1]; | 147 from = segments[1]; |
148 to = segments[2]; | 148 to = segments[2]; |
149 msg = segments[3]; | 149 msg = segments[3]; |
150 | 150 |
151 _qq_send_packet_ack_msg_sys(gc, code[0], strtol(from, NULL, 10), seq); | 151 ack_server_msg(gc, code[0], strtol(from, NULL, 10), seq); |
152 | 152 |
153 if (strtol(to, NULL, 10) != qd->uid) { /* not to me */ | 153 if (strtol(to, NULL, 10) != qd->uid) { /* not to me */ |
154 purple_debug_error("QQ", "Recv sys msg to [%s], not me!, discard\n", to); | 154 purple_debug_error("QQ", "Recv sys msg to [%s], not me!, discard\n", to); |
155 g_strfreev(segments); | 155 g_strfreev(segments); |
156 return; | 156 return; |
171 case QQ_SERVER_BUDDY_ADDED_ME: | 171 case QQ_SERVER_BUDDY_ADDED_ME: |
172 case QQ_SERVER_BUDDY_REJECTED_ME: | 172 case QQ_SERVER_BUDDY_REJECTED_ME: |
173 qq_process_buddy_from_server(gc, funct, from, to, msg_utf8); | 173 qq_process_buddy_from_server(gc, funct, from, to, msg_utf8); |
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 process_server_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", "QQ Server has newer client version\n"); | 179 purple_debug_warning("QQ", "QQ Server has newer client version\n"); |
180 break; | 180 break; |
181 default: | 181 default: |
182 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); |
183 break; | |
183 } | 184 } |
184 g_free(msg_utf8); | 185 g_free(msg_utf8); |
185 g_strfreev(segments); | 186 g_strfreev(segments); |
186 } | 187 } |
187 | 188 |
507 } | 508 } |
508 | 509 |
509 /* seems ok so far, so we process the reply according to sub_cmd */ | 510 /* seems ok so far, so we process the reply according to sub_cmd */ |
510 switch (reply_cmd) { | 511 switch (reply_cmd) { |
511 case QQ_ROOM_CMD_GET_INFO: | 512 case QQ_ROOM_CMD_GET_INFO: |
512 qq_process_room_cmd_get_info(data + bytes, data_len - bytes, gc); | 513 qq_process_room_cmd_get_info(data + bytes, data_len - bytes, ship32, gc); |
513 break; | 514 break; |
514 case QQ_ROOM_CMD_CREATE: | 515 case QQ_ROOM_CMD_CREATE: |
515 qq_group_process_create_group_reply(data + bytes, data_len - bytes, gc); | 516 qq_group_process_create_group_reply(data + bytes, data_len - bytes, gc); |
516 break; | 517 break; |
517 case QQ_ROOM_CMD_CHANGE_INFO: | 518 case QQ_ROOM_CMD_CHANGE_INFO: |
586 data = g_newa(guint8, rcved_len); | 587 data = g_newa(guint8, rcved_len); |
587 | 588 |
588 switch (cmd) { | 589 switch (cmd) { |
589 case QQ_CMD_TOKEN: | 590 case QQ_CMD_TOKEN: |
590 if (qq_process_token(gc, rcved, rcved_len) == QQ_LOGIN_REPLY_OK) { | 591 if (qq_process_token(gc, rcved, rcved_len) == QQ_LOGIN_REPLY_OK) { |
591 if (qd->is_above_2007) { | 592 if (qd->client_version > 2005) { |
592 qq_request_token_ex(gc); | 593 qq_request_token_ex(gc); |
593 } else { | 594 } else { |
594 qq_request_login(gc); | 595 qq_request_login(gc); |
595 } | 596 } |
596 return QQ_LOGIN_REPLY_OK; | 597 return QQ_LOGIN_REPLY_OK; |
597 } | 598 } |
598 return QQ_LOGIN_REPLY_ERR; | 599 return QQ_LOGIN_REPLY_ERR; |
599 case QQ_CMD_GET_SERVER: | 600 case QQ_CMD_GET_SERVER: |
600 case QQ_CMD_TOKEN_EX: | 601 case QQ_CMD_TOKEN_EX: |
601 data_len = qq_decrypt(data, rcved, rcved_len, qd->ld.init_key); | 602 data_len = qq_decrypt(data, rcved, rcved_len, qd->ld.random_key); |
602 break; | 603 break; |
603 default: | 604 case QQ_CMD_CHECK_PWD: |
604 /* May use password_twice_md5 in the past version like QQ2005 */ | 605 /* 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 data_len = qq_decrypt(data, rcved, rcved_len, qd->ld.random_key); |
606 if (data_len >= 0) { | 607 if (data_len >= 0) { |
607 purple_debug_warning("QQ", "Decrypt login packet by init_key, %d bytes\n", data_len); | 608 purple_debug_warning("QQ", "Decrypt login packet by random_key, %d bytes\n", data_len); |
608 } else { | 609 } else { |
609 data_len = qq_decrypt(data, rcved, rcved_len, qd->ld.pwd_twice_md5); | 610 data_len = qq_decrypt(data, rcved, rcved_len, qd->ld.pwd_4th_md5); |
610 if (data_len >= 0) { | 611 if (data_len >= 0) { |
611 purple_debug_warning("QQ", "Decrypt login packet by password_twice_md5, %d bytes\n", data_len); | 612 purple_debug_warning("QQ", "Decrypt login packet by pwd_4th_md5, %d bytes\n", data_len); |
613 } | |
614 } | |
615 break; | |
616 default: | |
617 /* May use password_twice_md5 in the past version like QQ2005 */ | |
618 data_len = qq_decrypt(data, rcved, rcved_len, qd->ld.random_key); | |
619 if (data_len >= 0) { | |
620 purple_debug_warning("QQ", "Decrypt login packet by random_key, %d bytes\n", data_len); | |
621 } else { | |
622 data_len = qq_decrypt(data, rcved, rcved_len, qd->ld.pwd_2nd_md5); | |
623 if (data_len >= 0) { | |
624 purple_debug_warning("QQ", "Decrypt login packet by pwd_2nd_md5, %d bytes\n", data_len); | |
612 } | 625 } |
613 } | 626 } |
614 break; | 627 break; |
615 } | 628 } |
616 | 629 |
618 purple_debug_warning("QQ", | 631 purple_debug_warning("QQ", |
619 "Can not decrypt login cmd, [%05d], 0x%04X %s, len %d\n", | 632 "Can not decrypt login cmd, [%05d], 0x%04X %s, len %d\n", |
620 seq, cmd, qq_get_cmd_desc(cmd), rcved_len); | 633 seq, cmd, qq_get_cmd_desc(cmd), rcved_len); |
621 qq_show_packet("Can not decrypted", rcved, rcved_len); | 634 qq_show_packet("Can not decrypted", rcved, rcved_len); |
622 purple_connection_error_reason(gc, | 635 purple_connection_error_reason(gc, |
623 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, | 636 PURPLE_CONNECTION_ERROR_ENCRYPTION_ERROR, |
624 _("Can not decrypt login reply")); | 637 _("Can not decrypt login reply")); |
625 return QQ_LOGIN_REPLY_ERR_DECRYPT; | 638 return QQ_LOGIN_REPLY_ERR; |
626 } | 639 } |
627 | 640 |
628 switch (cmd) { | 641 switch (cmd) { |
629 case QQ_CMD_GET_SERVER: | 642 case QQ_CMD_GET_SERVER: |
630 ret_8 = qq_process_get_server(gc, data, data_len); | 643 ret_8 = qq_process_get_server(gc, data, data_len); |
635 } | 648 } |
636 break; | 649 break; |
637 case QQ_CMD_TOKEN_EX: | 650 case QQ_CMD_TOKEN_EX: |
638 ret_8 = qq_process_token_ex(gc, data, data_len); | 651 ret_8 = qq_process_token_ex(gc, data, data_len); |
639 if (ret_8 == QQ_LOGIN_REPLY_OK) { | 652 if (ret_8 == QQ_LOGIN_REPLY_OK) { |
640 //qq_request_check_password(gc); | 653 if (qd->client_version == 2008) { |
654 qq_request_check_pwd_2008(gc); | |
655 } else { | |
656 qq_request_check_pwd_2007(gc); | |
657 } | |
641 } else if (ret_8 == QQ_LOGIN_REPLY_NEXT_TOKEN_EX) { | 658 } else if (ret_8 == QQ_LOGIN_REPLY_NEXT_TOKEN_EX) { |
642 qq_request_token_ex_next(gc); | 659 qq_request_token_ex_next(gc); |
643 } else if (ret_8 == QQ_LOGIN_REPLY_CAPTCHA_DLG) { | 660 } else if (ret_8 == QQ_LOGIN_REPLY_CAPTCHA_DLG) { |
644 qq_captcha_input_dialog(gc, &(qd->captcha)); | 661 qq_captcha_input_dialog(gc, &(qd->captcha)); |
645 g_free(qd->captcha.token); | 662 g_free(qd->captcha.token); |
646 g_free(qd->captcha.data); | 663 g_free(qd->captcha.data); |
647 memset(&qd->captcha, 0, sizeof(qd->captcha)); | 664 memset(&qd->captcha, 0, sizeof(qd->captcha)); |
648 } | 665 } |
649 break; | 666 break; |
667 case QQ_CMD_CHECK_PWD: | |
668 if (qd->client_version == 2008) { | |
669 ret_8 = qq_process_check_pwd_2008(gc, data, data_len); | |
670 } else { | |
671 ret_8 = qq_process_check_pwd_2007(gc, data, data_len); | |
672 } | |
673 if (ret_8 != QQ_LOGIN_REPLY_OK) { | |
674 return ret_8; | |
675 } | |
676 if (qd->client_version == 2008) { | |
677 qq_request_login_2008(gc); | |
678 } else { | |
679 qq_request_login_2007(gc); | |
680 } | |
681 break; | |
650 case QQ_CMD_LOGIN: | 682 case QQ_CMD_LOGIN: |
651 ret_8 = qq_process_login(gc, data, data_len); | 683 ret_8 = qq_process_login(gc, data, data_len); |
652 if (ret_8 != QQ_LOGIN_REPLY_OK) { | 684 if (ret_8 != QQ_LOGIN_REPLY_OK) { |
653 return ret_8; | 685 return ret_8; |
654 } | 686 } |