Mercurial > pidgin.yaz
diff src/protocols/qq/recv_core.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 | 983fd420e86b |
children | 8294485b79db |
line wrap: on
line diff
--- a/src/protocols/qq/recv_core.c Wed Aug 02 13:37:13 2006 +0000 +++ b/src/protocols/qq/recv_core.c Wed Aug 02 15:35:36 2006 +0000 @@ -20,28 +20,26 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -// START OF FILE -/*****************************************************************************/ -#include "debug.h" // gaim_debug -#include "internal.h" // _("get_text") +#include "debug.h" +#include "internal.h" -#include "utils.h" // hex_dump_to_str -#include "packet_parse.h" // MAX_PACKET_SIZE -#include "buddy_info.h" // qq_process_modify_info_reply -#include "buddy_list.h" // qq_process_get_buddies_list_reply -#include "buddy_opt.h" // qq_process_add_buddy_reply -#include "buddy_status.h" // qq_process_friend_change_status -#include "char_conv.h" // qq_to_utf8 -#include "crypt.h" // qq_crypt -#include "group_network.h" // qq_process_group_cmd_reply -#include "header_info.h" // cmd alias -#include "keep_alive.h" // qq_process_keep_alive_reply -#include "im.h" // qq_process_send_im_reply -#include "login_logout.h" // qq_process_login_reply -#include "qq_proxy.h" // qq_proxy_read +#include "buddy_info.h" +#include "buddy_list.h" +#include "buddy_opt.h" +#include "buddy_status.h" +#include "char_conv.h" +#include "crypt.h" +#include "group_network.h" +#include "header_info.h" +#include "keep_alive.h" +#include "im.h" +#include "login_logout.h" +#include "packet_parse.h" +#include "qq_proxy.h" #include "recv_core.h" -#include "sendqueue.h" // qq_sendqueue_remove -#include "sys_msg.h" // qq_process_msg_sys +#include "sendqueue.h" +#include "sys_msg.h" +#include "utils.h" typedef struct _packet_before_login packet_before_login; typedef struct _qq_recv_msg_header qq_recv_msg_header; @@ -55,13 +53,12 @@ guint8 header_tag; guint16 source_tag; guint16 cmd; - guint16 seq; // can be ack_seq or send_seq, depends on cmd + guint16 seq; /* can be ack_seq or send_seq, depends on cmd */ }; -/*****************************************************************************/ -// check whether one sequence number is duplicated or not -// return TRUE if it is duplicated, otherwise FALSE -static gboolean _qq_check_packet_set_window(guint16 seq, GaimConnection * gc) +/* check whether one sequence number is duplicated or not + * return TRUE if it is duplicated, otherwise FALSE */ +static gboolean _qq_check_packet_set_window(guint16 seq, GaimConnection *gc) { qq_data *qd; gchar *byte, mask; @@ -72,15 +69,14 @@ mask = (1 << (seq % 8)); if ((*byte) & mask) - return TRUE; // check mask + return TRUE; /* check mask */ (*byte) |= mask; - return FALSE; // set mask -} // _qq_check_packet_set_window + return FALSE; /* set mask */ +} /* _qq_check_packet_set_window */ -/*****************************************************************************/ -// default process, decrypt and dump -static void _qq_process_packet_default(guint8 * buf, gint buf_len, guint16 cmd, guint16 seq, GaimConnection * gc) { - +/* default process, decrypt and dump */ +static void _qq_process_packet_default(guint8 *buf, gint buf_len, guint16 cmd, guint16 seq, GaimConnection *gc) +{ qq_data *qd; guint8 *data; gchar *msg_utf8; @@ -99,18 +95,17 @@ ">>> [%d] %s, %d bytes -> [default] decrypt and dump\n%s", seq, qq_get_cmd_desc(cmd), buf_len, hex_dump_to_str(data, len)); try_dump_as_gbk(data, len); - } else + } else { gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Fail decrypt packet with default process\n"); + } +} -} // _qq_process_packet_default - -/*****************************************************************************/ -// process the incoming packet from qq_pending -static void _qq_packet_process(guint8 * buf, gint buf_len, GaimConnection * gc) +/* process the incoming packet from qq_pending */ +static void _qq_packet_process(guint8 *buf, gint buf_len, GaimConnection *gc) { qq_data *qd; gint len, bytes_expected, bytes_read; - guint16 buf_len_read; // two bytes in the begining of TCP packet + guint16 buf_len_read; /* two bytes in the begining of TCP packet */ guint8 *cursor; qq_recv_msg_header header; packet_before_login *b4_packet; @@ -126,95 +121,96 @@ "QQ", "Received packet is too short, dump and drop\n%s", hex_dump_to_str(buf, buf_len)); return; } - // initialize + /* initialize */ cursor = buf; bytes_read = 0; - // QQ TCP packet returns first 2 bytes the length of this packet + /* QQ TCP packet returns first 2 bytes the length of this packet */ if (qd->use_tcp) { bytes_read += read_packet_w(buf, &cursor, buf_len, &buf_len_read); - if (buf_len_read != buf_len) { // wrong + if (buf_len_read != buf_len) { /* wrong */ gaim_debug (GAIM_DEBUG_ERROR, "QQ", "TCP read %d bytes, header says %d bytes, use header anyway\n", buf_len, buf_len_read); - buf_len = buf_len_read; // we believe header is more accurate - } // if buf_len_read - } // if use_tcp + buf_len = buf_len_read; /* we believe header is more accurate */ + } + } - // now goes the normal QQ packet as UDP packet + /* now goes the normal QQ packet as UDP packet */ bytes_read += read_packet_b(buf, &cursor, buf_len, &header.header_tag); bytes_read += read_packet_w(buf, &cursor, buf_len, &header.source_tag); bytes_read += read_packet_w(buf, &cursor, buf_len, &header.cmd); bytes_read += read_packet_w(buf, &cursor, buf_len, &header.seq); - if (bytes_read != bytes_expected) { // read error + if (bytes_read != bytes_expected) { /* read error */ gaim_debug(GAIM_DEBUG_ERROR, "QQ", - "Fail reading packet header, expect %d bytes, read %d bytes\n", bytes_expected, bytes_read); + "Fail reading packet header, expect %d bytes, read %d bytes\n", + bytes_expected, bytes_read); return; - } // if bytes_read + } if ((buf[buf_len - 1] != QQ_PACKET_TAIL) || (header.header_tag != QQ_PACKET_TAG)) { gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Unknown QQ proctocol, dump and drop\n%s", hex_dump_to_str(buf, buf_len)); return; - } // if header_tag + } if (QQ_DEBUG) gaim_debug(GAIM_DEBUG_INFO, "QQ", "==> [%05d] %s, from (%s)\n", header.seq, qq_get_cmd_desc(header.cmd), qq_get_source_str(header.source_tag)); - if (header.cmd != QQ_CMD_LOGIN && header.cmd != QQ_CMD_REQUEST_LOGIN_TOKEN /* gfhuang */) { - if (!qd->logged_in) { // packets before login + if (header.cmd != QQ_CMD_LOGIN && header.cmd != QQ_CMD_REQUEST_LOGIN_TOKEN) { + if (!qd->logged_in) { /* packets before login */ b4_packet = g_new0(packet_before_login, 1); - // must duplicate, buffer will be freed after exiting this function + /* must duplicate, buffer will be freed after exiting this function */ b4_packet->buf = g_memdup(buf, buf_len); b4_packet->len = buf_len; if (qd->before_login_packets == NULL) qd->before_login_packets = g_queue_new(); g_queue_push_head(qd->before_login_packets, b4_packet); - return; // do not process it now + return; /* do not process it now */ } else if (!g_queue_is_empty(qd->before_login_packets)) { - // logged_in, but we have packets before login + /* logged_in, but we have packets before login */ b4_packet = (packet_before_login *) g_queue_pop_head(qd->before_login_packets); _qq_packet_process(b4_packet->buf, b4_packet->len, gc); - // in fact this is a recursive call, - // all packets before login will be processed before goes on - g_free(b4_packet->buf); // the buf is duplicated, need to be freed + /* in fact this is a recursive call, + * all packets before login will be processed before goes on */ + g_free(b4_packet->buf); /* the buf is duplicated, need to be freed */ g_free(b4_packet); - } // if logged_in - } //if header.cmd != QQ_CMD_LOGIN + } + } - // this is the length of all the encrypted data (also remove tail tag + /* this is the length of all the encrypted data (also remove tail tag */ len = buf_len - (bytes_read) - 1; - // whether it is an ack + /* whether it is an ack */ switch (header.cmd) { case QQ_CMD_RECV_IM: case QQ_CMD_RECV_MSG_SYS: case QQ_CMD_RECV_MSG_FRIEND_CHANGE_STATUS: - // server intiated packet, we need to send ack and check duplicaion - // this must be put after processing b4_packet - // as these packets will be passed in twice + /* server intiated packet, we need to send ack and check duplicaion + * this must be put after processing b4_packet + * as these packets will be passed in twice */ if (_qq_check_packet_set_window(header.seq, gc)) { gaim_debug(GAIM_DEBUG_WARNING, "QQ", "dup [%05d] %s, discard...\n", header.seq, qq_get_cmd_desc(header.cmd)); return; } break; - default:{ // ack packet, we need to update sendqueue - // we do not check duplication for server ack + default:{ /* ack packet, we need to update sendqueue */ + /* we do not check duplication for server ack */ qq_sendqueue_remove(qd, header.seq); if (QQ_DEBUG) gaim_debug(GAIM_DEBUG_INFO, "QQ", "ack [%05d] %s, remove from sendqueue\n", header.seq, qq_get_cmd_desc(header.cmd)); - } // default - } // switch header.cmd + } + } - // now process the packet + /* now process the packet */ switch (header.cmd) { case QQ_CMD_KEEP_ALIVE: qq_process_keep_alive_reply(cursor, len, gc); @@ -258,10 +254,10 @@ case QQ_CMD_GROUP_CMD: qq_process_group_cmd_reply(cursor, len, header.seq, gc); break; - case QQ_CMD_GET_ALL_LIST_WITH_GROUP: //added by gfhuang + case QQ_CMD_GET_ALL_LIST_WITH_GROUP: qq_process_get_all_list_with_group_reply(cursor, len, gc); break; - case QQ_CMD_REQUEST_LOGIN_TOKEN: //added by gfhuang + case QQ_CMD_REQUEST_LOGIN_TOKEN: qq_process_request_login_token_reply(cursor, len, gc); break; case QQ_CMD_RECV_MSG_SYS: @@ -273,26 +269,24 @@ default: _qq_process_packet_default(cursor, len, header.cmd, header.seq, gc); break; - } // switch header.cmd -} // _qq_packet_process + } +} -/*****************************************************************************/ -// clean up the packets before login -void qq_b4_packets_free(qq_data * qd) +/* clean up the packets before login */ +void qq_b4_packets_free(qq_data *qd) { packet_before_login *b4_packet; g_return_if_fail(qd != NULL); - // now clean up my own data structures + /* now clean up my own data structures */ if (qd->before_login_packets != NULL) { while (NULL != (b4_packet = g_queue_pop_tail(qd->before_login_packets))) { g_free(b4_packet->buf); g_free(b4_packet); } g_queue_free(qd->before_login_packets); - } // if -} // qq_b4_packets_free + } +} -/*****************************************************************************/ void qq_input_pending(gpointer data, gint source, GaimInputCondition cond) { GaimConnection *gc; @@ -304,18 +298,14 @@ g_return_if_fail(gc != NULL && gc->proto_data != NULL && cond == GAIM_INPUT_READ); qd = (qq_data *) gc->proto_data; - // according to glib manual memory allocated by g_newa could be - // automatically freed when the current stack frame is cleaned up buf = g_newa(guint8, MAX_PACKET_SIZE); - // here we have UDP proxy suppport + /* here we have UDP proxy suppport */ len = qq_proxy_read(qd, buf, MAX_PACKET_SIZE); if (len <= 0) { gaim_connection_error(gc, _("Unable to read from socket")); return; - } else + } else { _qq_packet_process(buf, len, gc); -} // qq_input_pending - -/*****************************************************************************/ -// END OF FILE + } +}