Mercurial > pidgin.yaz
diff libpurple/protocols/qq/qq_trans.c @ 23754:967344bc404d
applied changes from f12c8903079425d7850fa183df0b3f937b2952be
through 8cebefbc6cd5d84acb69c74e69e8821f11dd225d
Backport of 8cebefbc6cd5d84acb69c74e69e8821f11dd225d to avoid having other changes overwritten.
2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
* Rename group to room. If you used pidginqq before, this may create a new room with same title, you may
delete old one
* Replace purple_debug with purple_debug_info, purple_debug_warning, purple_debug_error
* Add server notice and server new, and two options to turn on/off
* Minor modify for reducing transaction's debug infor
* Minor modifies for system notice and QQ news.
* Add 4 new strings need translate compare with p10.
committer: Daniel Atallah <daniel.atallah@gmail.com>
author | SHiNE CsyFeK <csyfek@gmail.com> |
---|---|
date | Mon, 15 Sep 2008 02:59:23 +0000 |
parents | 5f454b975a99 |
children | 23cec4360d4a 25f62d21b3f8 |
line wrap: on
line diff
--- a/libpurple/protocols/qq/qq_trans.c Sun Aug 10 04:32:14 2008 +0000 +++ b/libpurple/protocols/qq/qq_trans.c Mon Sep 15 02:59:23 2008 +0000 @@ -37,8 +37,35 @@ #define QQ_RESEND_MAX 3 /* max resend per packet */ -qq_transaction *qq_trans_find_rcved(qq_data *qd, guint16 cmd, guint16 seq) +enum { + QQ_TRANS_IS_SERVER = 0x01, /* Is server command or client command */ + QQ_TRANS_IS_IMPORT = 0x02, /* Only notice if not get reply; or resend, disconn if reties get 0*/ + QQ_TRANS_BEFORE_LOGIN = 0x04, /* server command before login*/ +}; + +struct _qq_transaction { + guint8 flag; + guint16 seq; + guint16 cmd; + + guint8 room_cmd; + guint32 room_id; + + guint8 *data; + gint data_len; + + gint fd; + gint send_retries; + gint rcved_times; + gint scan_times; + + gint update_class; + guint32 ship32; +}; + +qq_transaction *qq_trans_find_rcved(PurpleConnection *gc, guint16 cmd, guint16 seq) { + qq_data *qd = (qq_data *)gc->proto_data; GList *curr; GList *next; qq_transaction *trans; @@ -50,19 +77,21 @@ next = qd->transactions; while( (curr = next) ) { next = curr->next; - + trans = (qq_transaction *) (curr->data); if(trans->cmd == cmd && trans->seq == seq) { if (trans->rcved_times == 0) { trans->scan_times = 0; } trans->rcved_times++; + /* server may not get our confirm reply before, send reply again*/ + /* only rcved buffer stored in transaction if (qq_trans_is_server(trans) && qq_trans_is_dup(trans)) { - /* server may not get our confirm reply before, send reply again*/ if (trans->data != NULL && trans->data_len > 0) { - qq_send_data(qd, trans->cmd, trans->seq, FALSE, trans->data, trans->data_len); + qq_send_cmd_encrypted(gc, trans->cmd, trans->seq, trans->data, trans->data_len, FALSE); } } + */ return trans; } } @@ -70,20 +99,20 @@ return NULL; } -gboolean qq_trans_is_server(qq_transaction *trans) +gboolean qq_trans_is_server(qq_transaction *trans) { g_return_val_if_fail(trans != NULL, FALSE); - + if (trans->flag & QQ_TRANS_IS_SERVER) return TRUE; else return FALSE; } -gboolean qq_trans_is_dup(qq_transaction *trans) +gboolean qq_trans_is_dup(qq_transaction *trans) { g_return_val_if_fail(trans != NULL, TRUE); - + if (trans->rcved_times > 1) return TRUE; else @@ -102,115 +131,122 @@ return trans->room_id; } -/* Remove a packet with seq from send trans */ -static void trans_remove(qq_data *qd, qq_transaction *trans) +gint qq_trans_get_class(qq_transaction *trans) +{ + g_return_val_if_fail(trans != NULL, QQ_CMD_CLASS_NONE); + return trans->update_class; +} + +gint qq_trans_get_ship(qq_transaction *trans) +{ + g_return_val_if_fail(trans != NULL, 0); + return trans->ship32; +} + +static qq_transaction *trans_create(PurpleConnection *gc, gint fd, + guint16 cmd, guint16 seq, guint8 *data, gint data_len, gint update_class, guint32 ship32) { + qq_data *qd; + qq_transaction *trans; + + g_return_val_if_fail(gc != NULL && gc->proto_data != NULL, NULL); + qd = (qq_data *) gc->proto_data; + + trans = g_new0(qq_transaction, 1); + + memset(trans, 0, sizeof(qq_transaction)); + trans->fd = fd; + trans->cmd = cmd; + trans->seq = seq; + + trans->data = NULL; + trans->data_len = 0; + if (data != NULL && data_len > 0) { + /* don't use g_strdup, may have 0x00 */ + trans->data = g_memdup(data, data_len); + trans->data_len = data_len; + } + + trans->update_class = update_class; + return trans; +} + +/* Remove a packet with seq from send trans */ +static void trans_remove(PurpleConnection *gc, qq_transaction *trans) +{ + qq_data *qd = (qq_data *)gc->proto_data; g_return_if_fail(qd != NULL && trans != NULL); - - purple_debug(PURPLE_DEBUG_INFO, "QQ_TRANS", + +#if 0 + purple_debug_info("QQ_TRANS", "Remove [%s%05d] retry %d rcved %d scan %d %s\n", (trans->flag & QQ_TRANS_IS_SERVER) ? "SRV-" : "", trans->seq, trans->send_retries, trans->rcved_times, trans->scan_times, qq_get_cmd_desc(trans->cmd)); - +#endif if (trans->data) g_free(trans->data); qd->transactions = g_list_remove(qd->transactions, trans); g_free(trans); } -void qq_trans_add_client_cmd(qq_data *qd, guint16 cmd, guint16 seq, guint8 *data, gint data_len) +void qq_trans_add_client_cmd(PurpleConnection *gc, + guint16 cmd, guint16 seq, guint8 *data, gint data_len, gint update_class, guint32 ship32) { - qq_transaction *trans = g_new0(qq_transaction, 1); + qq_data *qd = (qq_data *)gc->proto_data; + qq_transaction *trans = trans_create(gc, qd->fd, cmd, seq, data, data_len, update_class, ship32); - g_return_if_fail(trans != NULL); - - trans->flag = 0; if (cmd == QQ_CMD_TOKEN || cmd == QQ_CMD_LOGIN || cmd == QQ_CMD_KEEP_ALIVE) { - trans->flag |= QQ_TRANS_CLI_IMPORT; + trans->flag |= QQ_TRANS_IS_IMPORT; } - trans->fd = qd->fd; - trans->cmd = cmd; - trans->seq = seq; - trans->room_cmd = 0; - trans->room_id = 0; trans->send_retries = QQ_RESEND_MAX; - trans->rcved_times = 0; - trans->scan_times = 0; - - trans->data = NULL; - trans->data_len = 0; - if (data != NULL && data_len > 0) { - trans->data = g_memdup(data, data_len); /* don't use g_strdup, may have 0x00 */ - trans->data_len = data_len; - } - purple_debug(PURPLE_DEBUG_INFO, "QQ_TRANS", - "Add client cmd, seq = %d, data = %p, len = %d\n", +#if 0 + purple_debug_info("QQ_TRANS", "Add client cmd, seq %d, data %p, len %d\n", trans->seq, trans->data, trans->data_len); +#endif qd->transactions = g_list_append(qd->transactions, trans); } -void qq_trans_add_room_cmd(qq_data *qd, guint16 seq, guint8 room_cmd, guint32 room_id, - guint8 *data, gint data_len) +void qq_trans_add_room_cmd(PurpleConnection *gc, + guint16 seq, guint8 room_cmd, guint32 room_id, guint8 *data, gint data_len, + gint update_class, guint32 ship32) { - qq_transaction *trans = g_new0(qq_transaction, 1); + qq_data *qd = (qq_data *)gc->proto_data; + qq_transaction *trans = trans_create(gc, qd->fd, QQ_CMD_ROOM, seq, data, data_len, + update_class, ship32); - g_return_if_fail(trans != NULL); - - trans->flag = 0; - trans->fd = qd->fd; - trans->seq = seq; - trans->cmd = QQ_CMD_ROOM; trans->room_cmd = room_cmd; trans->room_id = room_id; trans->send_retries = QQ_RESEND_MAX; - trans->rcved_times = 0; - trans->scan_times = 0; - - trans->data = NULL; - trans->data_len = 0; - if (data != NULL && data_len > 0) { - trans->data = g_memdup(data, data_len); /* don't use g_strdup, may have 0x00 */ - trans->data_len = data_len; - } - purple_debug(PURPLE_DEBUG_INFO, "QQ_TRANS", - "Add room cmd, seq = %d, data = %p, len = %d\n", +#if 0 + purple_debug_info("QQ_TRANS", "Add room cmd, seq %d, data %p, len %d\n", trans->seq, trans->data, trans->data_len); +#endif qd->transactions = g_list_append(qd->transactions, trans); } -void qq_trans_add_server_cmd(qq_data *qd, guint16 cmd, guint16 seq, guint8 *data, gint data_len) +void qq_trans_add_server_cmd(PurpleConnection *gc, + guint16 cmd, guint16 seq, guint8 *data, gint data_len) { - qq_transaction *trans = g_new0(qq_transaction, 1); - - g_return_if_fail(trans != NULL); + qq_data *qd = (qq_data *)gc->proto_data; + qq_transaction *trans = trans_create(gc, qd->fd, cmd, seq, data, data_len, QQ_CMD_CLASS_NONE, 0); trans->flag = QQ_TRANS_IS_SERVER; - if ( !qd->logged_in ) { + if ( !qd->is_login ) { trans->flag |= QQ_TRANS_BEFORE_LOGIN; } - trans->fd = qd->fd; - trans->cmd = cmd; - trans->seq = seq; - trans->room_cmd = 0; - trans->room_id = 0; trans->send_retries = 0; trans->rcved_times = 1; - trans->scan_times = 0; - trans->data = NULL; - trans->data_len = 0; - if (data != NULL && data_len > 0) { - trans->data = g_memdup(data, data_len); /* don't use g_strdup, may have 0x00 */ - trans->data_len = data_len; - } - purple_debug(PURPLE_DEBUG_INFO, "QQ_TRANS", - "Add server cmd, seq = %d, data = %p, len = %d\n", +#if 0 + purple_debug_info("QQ_TRANS", "Add server cmd, seq %d, data %p, len %d\n", trans->seq, trans->data, trans->data_len); +#endif qd->transactions = g_list_append(qd->transactions, trans); } -void qq_trans_process_before_login(qq_data *qd) +void qq_trans_process_before_login(PurpleConnection *gc) { + qq_data *qd = (qq_data *)gc->proto_data; GList *curr; GList *next; qq_transaction *trans; @@ -221,42 +257,44 @@ while( (curr = next) ) { next = curr->next; trans = (qq_transaction *) (curr->data); - /* purple_debug(PURPLE_DEBUG_ERROR, "QQ_TRANS", "Scan [%d]\n", trans->seq); */ - +#if 0 + purple_debug_info("QQ_TRANS", "Scan [%d]\n", trans->seq); +#endif if ( !(trans->flag & QQ_TRANS_IS_SERVER) ) { continue; } if ( !(trans->flag & QQ_TRANS_BEFORE_LOGIN) ) { continue; } - // set QQ_TRANS_BEFORE_LOGIN off + /* set QQ_TRANS_BEFORE_LOGIN off */ trans->flag &= ~QQ_TRANS_BEFORE_LOGIN; - purple_debug(PURPLE_DEBUG_ERROR, "QQ_TRANS", + purple_debug_info("QQ_TRANS", "Process server cmd before login, seq %d, data %p, len %d, send_retries %d\n", trans->seq, trans->data, trans->data_len, trans->send_retries); - qq_proc_cmd_reply(qd->gc, trans->seq, trans->cmd, trans->data, trans->data_len); + qq_proc_cmd_reply(gc, trans->seq, trans->cmd, trans->data, trans->data_len, trans->update_class, trans->ship32); } - /* purple_debug(PURPLE_DEBUG_INFO, "QQ_TRANS", "Scan finished\n"); */ + /* purple_debug_info("QQ_TRANS", "Scan finished\n"); */ return; } -gboolean qq_trans_scan(qq_data *qd) +gboolean qq_trans_scan(PurpleConnection *gc) { + qq_data *qd = (qq_data *)gc->proto_data; GList *curr; GList *next; qq_transaction *trans; g_return_val_if_fail(qd != NULL, FALSE); - + next = qd->transactions; while( (curr = next) ) { next = curr->next; trans = (qq_transaction *) (curr->data); - /* purple_debug(PURPLE_DEBUG_INFO, "QQ_TRANS", "Scan [%d]\n", trans->seq); */ - + /* purple_debug_info("QQ_TRANS", "Scan [%d]\n", trans->seq); */ + if (trans->flag & QQ_TRANS_BEFORE_LOGIN) { /* keep server cmd before login*/ continue; @@ -270,67 +308,60 @@ if (trans->rcved_times > 0) { /* Has been received */ - trans_remove(qd, trans); + trans_remove(gc, trans); continue; } if (trans->flag & QQ_TRANS_IS_SERVER) { continue; } - + /* Never get reply */ trans->send_retries--; if (trans->send_retries <= 0) { - purple_debug(PURPLE_DEBUG_WARNING, "QQ_TRANS", + purple_debug_warning("QQ_TRANS", "[%d] %s is lost.\n", trans->seq, qq_get_cmd_desc(trans->cmd)); - if (trans->flag & QQ_TRANS_CLI_IMPORT) { + if (trans->flag & QQ_TRANS_IS_IMPORT) { return TRUE; } - purple_debug(PURPLE_DEBUG_ERROR, "QQ_TRANS", + purple_debug_error("QQ_TRANS", "Lost [%d] %s, data %p, len %d, retries %d\n", trans->seq, qq_get_cmd_desc(trans->cmd), trans->data, trans->data_len, trans->send_retries); - trans_remove(qd, trans); + trans_remove(gc, trans); continue; } - purple_debug(PURPLE_DEBUG_ERROR, "QQ_TRANS", + purple_debug_error("QQ_TRANS", "Resend [%d] %s data %p, len %d, send_retries %d\n", trans->seq, qq_get_cmd_desc(trans->cmd), trans->data, trans->data_len, trans->send_retries); - qq_send_data(qd, trans->cmd, trans->seq, FALSE, trans->data, trans->data_len); + qq_send_cmd_encrypted(gc, trans->cmd, trans->seq, trans->data, trans->data_len, FALSE); } - /* purple_debug(PURPLE_DEBUG_INFO, "QQ_TRANS", "Scan finished\n"); */ + /* purple_debug_info("QQ_TRANS", "Scan finished\n"); */ return FALSE; } /* clean up send trans and free all contents */ -void qq_trans_remove_all(qq_data *qd) +void qq_trans_remove_all(PurpleConnection *gc) { - GList *curr; - GList *next; + qq_data *qd = (qq_data *)gc->proto_data; qq_transaction *trans; gint count = 0; - curr = qd->transactions; - while(curr) { - next = curr->next; - - trans = (qq_transaction *) (curr->data); - /* - purple_debug(PURPLE_DEBUG_ERROR, "QQ_TRANS", - "Remove to transaction, seq = %d, buf = %p, len = %d\n", - trans->seq, trans->buf, trans->len); - */ - trans_remove(qd, trans); + while(qd->transactions != NULL) { + trans = (qq_transaction *) (qd->transactions->data); + qd->transactions = g_list_remove(qd->transactions, trans); + + if (trans->data) g_free(trans->data); + g_free(trans); count++; - curr = next; } - g_list_free(qd->transactions); - - purple_debug(PURPLE_DEBUG_INFO, "QQ_TRANS", "Free all %d packets\n", count); + if (count > 0) { + purple_debug_info("QQ_TRANS", "Free all %d packets\n", count); + } }