Mercurial > pidgin.yaz
diff libpurple/protocols/qq/file_trans.c @ 24065: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 | bcfc98c7a55f |
children | dbc7a9742f8d |
line wrap: on
line diff
--- a/libpurple/protocols/qq/file_trans.c Wed Oct 22 14:28:17 2008 +0000 +++ b/libpurple/protocols/qq/file_trans.c Wed Oct 22 14:33:20 2008 +0000 @@ -30,7 +30,7 @@ #include "qq_crypt.h" #include "file_trans.h" -#include "header_info.h" +#include "qq_define.h" #include "im.h" #include "packet_parse.h" #include "proxy.h" @@ -81,7 +81,7 @@ const gint QQ_MAX_FILE_MD5_LENGTH = 10002432; g_return_if_fail(filename != NULL && md5 != NULL); - if (filelen > QQ_MAX_FILE_MD5_LENGTH) + if (filelen > QQ_MAX_FILE_MD5_LENGTH) filelen = QQ_MAX_FILE_MD5_LENGTH; fp = fopen(filename, "rb"); @@ -161,7 +161,7 @@ fd = open(purple_xfer_get_local_filename(xfer), O_RDONLY); info->buffer = mmap(0, purple_xfer_get_size(xfer), PROT_READ, MAP_PRIVATE, fd, 0); } - else + else { fd = open(purple_xfer_get_local_filename(xfer), O_RDWR|O_CREAT, 0644); info->buffer = mmap(0, purple_xfer_get_size(xfer), PROT_READ | PROT_WRITE, MAP_SHARED | MAP_FILE, fd, 0); @@ -248,7 +248,7 @@ file_key = _gen_file_key(); bytes += qq_put8(raw_data + bytes, packet_type); - bytes += qq_put16(raw_data + bytes, QQ_CLIENT); + bytes += qq_put16(raw_data + bytes, qd->client_version); bytes += qq_put8(raw_data + bytes, file_key & 0xff); bytes += qq_put32(raw_data + bytes, _encrypt_qq_uid(qd->uid, file_key)); bytes += qq_put32(raw_data + bytes, _encrypt_qq_uid(to_uid, file_key)); @@ -364,7 +364,7 @@ } /* send a file to udp channel with QQ_FILE_DATA_PACKET_TAG */ -static void _qq_send_file_data_packet(PurpleConnection *gc, guint16 packet_type, guint8 sub_type, +static void _qq_send_file_data_packet(PurpleConnection *gc, guint16 packet_type, guint8 sub_type, guint32 fragment_index, guint16 seq, guint8 *data, gint len) { guint8 *raw_data, filename_md5[QQ_KEY_LENGTH], file_md5[QQ_KEY_LENGTH]; @@ -402,11 +402,11 @@ _fill_file_md5(purple_xfer_get_local_filename(qd->xfer), purple_xfer_get_size(qd->xfer), file_md5); - + info->fragment_num = (filesize - 1) / QQ_FILE_FRAGMENT_MAXLEN + 1; info->fragment_len = QQ_FILE_FRAGMENT_MAXLEN; - purple_debug_info("QQ", + purple_debug_info("QQ", "start transfering data, %d fragments with %d length each\n", info->fragment_num, info->fragment_len); /* Unknown */ @@ -431,7 +431,7 @@ filename_len); break; case QQ_FILE_DATA_INFO: - purple_debug_info("QQ", + purple_debug_info("QQ", "sending %dth fragment with length %d, offset %d\n", fragment_index, len, (fragment_index-1)*fragment_size); /* bytes += qq_put16(raw_data + bytes, ++(qd->send_seq)); */ @@ -532,7 +532,7 @@ decryped_bytes = 0; qq_get_conn_info(info, decrypted_data + decryped_bytes); /* qq_send_file_ctl_packet(gc, QQ_FILE_CMD_PING, fh->sender_uid, 0); */ - qq_send_file_ctl_packet(gc, QQ_FILE_CMD_SENDER_SAY_HELLO, fh.sender_uid, 0); + qq_send_file_ctl_packet(gc, QQ_FILE_CMD_SENDER_SAY_HELLO, fh.sender_uid, 0); break; case QQ_FILE_CMD_SENDER_SAY_HELLO: /* I'm receiver, if we receive SAY_HELLO from sender, we send back the ACK */ @@ -573,8 +573,8 @@ ft_info *info = (ft_info *) xfer->data; guint32 mask; - purple_debug_info("QQ", - "receiving %dth fragment with length %d, slide window status %o, max_fragment_index %d\n", + purple_debug_info("QQ", + "receiving %dth fragment with length %d, slide window status %o, max_fragment_index %d\n", index, len, info->window, info->max_fragment_index); if (info->window == 0 && info->max_fragment_index == 0) { if (_qq_xfer_open_file(purple_xfer_get_local_filename(xfer), "wb", xfer) == -1) { @@ -605,7 +605,7 @@ if (mask & 0x8000) mask = 0x0001; else mask = mask << 1; } - purple_debug_info("QQ", "procceed %dth fragment, slide window status %o, max_fragment_index %d\n", + purple_debug_info("QQ", "procceed %dth fragment, slide window status %o, max_fragment_index %d\n", index, info->window, info->max_fragment_index); } @@ -650,10 +650,10 @@ PurpleXfer *xfer = qd->xfer; ft_info *info = (ft_info *) xfer->data; - purple_debug_info("QQ", - "receiving %dth fragment ack, slide window status %o, max_fragment_index %d\n", + purple_debug_info("QQ", + "receiving %dth fragment ack, slide window status %o, max_fragment_index %d\n", fragment_index, info->window, info->max_fragment_index); - if (fragment_index < info->max_fragment_index || + if (fragment_index < info->max_fragment_index || fragment_index >= info->max_fragment_index + sizeof(info->window)) { purple_debug_info("QQ", "duplicate %dth fragment, drop it!\n", fragment_index+1); return; @@ -681,7 +681,7 @@ info->window &= ~mask; buffer = g_newa(guint8, info->fragment_len); - readbytes = _qq_xfer_read_file(buffer, info->max_fragment_index + sizeof(info->window), + readbytes = _qq_xfer_read_file(buffer, info->max_fragment_index + sizeof(info->window), info->fragment_len, xfer); if (readbytes > 0) _qq_send_file_data_packet(gc, QQ_FILE_CMD_FILE_OP, QQ_FILE_DATA_INFO, @@ -692,8 +692,8 @@ else mask = mask << 1; } } - purple_debug_info("QQ", - "procceed %dth fragment ack, slide window status %o, max_fragment_index %d\n", + purple_debug_info("QQ", + "procceed %dth fragment ack, slide window status %o, max_fragment_index %d\n", fragment_index, info->window, info->max_fragment_index); } @@ -727,13 +727,13 @@ bytes += qq_get32(&info->fragment_num, data + bytes); bytes += qq_get32(&info->fragment_len, data + bytes); - /* FIXME: We must check the md5 here, - * if md5 doesn't match we will ignore + /* FIXME: We must check the md5 here, + * if md5 doesn't match we will ignore * the packet or send sth as error number */ info->max_fragment_index = 0; info->window = 0; - purple_debug_info("QQ", + purple_debug_info("QQ", "start receiving data, %d fragments with %d length each\n", info->fragment_num, info->fragment_len); _qq_send_file_data_packet(gc, QQ_FILE_CMD_FILE_OP_ACK, sub_type, @@ -743,7 +743,7 @@ bytes += qq_get32(&fragment_index, data + bytes); bytes += qq_get32(&fragment_offset, data + bytes); bytes += qq_get16(&fragment_len, data + bytes); - purple_debug_info("QQ", + purple_debug_info("QQ", "received %dth fragment with length %d, offset %d\n", fragment_index, fragment_len, fragment_offset);