Mercurial > pidgin
comparison libpurple/protocols/qq/file_trans.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 | 73a30365c293 33921125348d |
comparison
equal
deleted
inserted
replaced
24134:bdfcfd71449c | 24135:dbc7a9742f8d |
---|---|
246 | 246 |
247 raw_data = g_newa(guint8, MAX_PACKET_SIZE); | 247 raw_data = g_newa(guint8, MAX_PACKET_SIZE); |
248 file_key = _gen_file_key(); | 248 file_key = _gen_file_key(); |
249 | 249 |
250 bytes += qq_put8(raw_data + bytes, packet_type); | 250 bytes += qq_put8(raw_data + bytes, packet_type); |
251 bytes += qq_put16(raw_data + bytes, qd->client_version); | 251 bytes += qq_put16(raw_data + bytes, qd->client_tag); |
252 bytes += qq_put8(raw_data + bytes, file_key & 0xff); | 252 bytes += qq_put8(raw_data + bytes, file_key & 0xff); |
253 bytes += qq_put32(raw_data + bytes, _encrypt_qq_uid(qd->uid, file_key)); | 253 bytes += qq_put32(raw_data + bytes, _encrypt_qq_uid(qd->uid, file_key)); |
254 bytes += qq_put32(raw_data + bytes, _encrypt_qq_uid(to_uid, file_key)); | 254 bytes += qq_put32(raw_data + bytes, _encrypt_qq_uid(to_uid, file_key)); |
255 bytes += qq_putdata(raw_data + bytes, data, len); | 255 bytes += qq_putdata(raw_data + bytes, data, len); |
256 | 256 |
264 /* send a file to udp channel with QQ_FILE_CONTROL_PACKET_TAG */ | 264 /* send a file to udp channel with QQ_FILE_CONTROL_PACKET_TAG */ |
265 void qq_send_file_ctl_packet(PurpleConnection *gc, guint16 packet_type, guint32 to_uid, guint8 hellobyte) | 265 void qq_send_file_ctl_packet(PurpleConnection *gc, guint16 packet_type, guint32 to_uid, guint8 hellobyte) |
266 { | 266 { |
267 qq_data *qd; | 267 qq_data *qd; |
268 gint bytes, bytes_expected, encrypted_len; | 268 gint bytes, bytes_expected, encrypted_len; |
269 guint8 *raw_data, *encrypted_data; | 269 guint8 *raw_data, *encrypted; |
270 time_t now; | 270 time_t now; |
271 ft_info *info; | 271 ft_info *info; |
272 | 272 |
273 qd = (qq_data *) gc->proto_data; | 273 qd = (qq_data *) gc->proto_data; |
274 info = (ft_info *) qd->xfer->data; | 274 info = (ft_info *) qd->xfer->data; |
332 | 332 |
333 qq_hex_dump(PURPLE_DEBUG_INFO, "QQ", | 333 qq_hex_dump(PURPLE_DEBUG_INFO, "QQ", |
334 raw_data, bytes, | 334 raw_data, bytes, |
335 "sending packet[%s]:", qq_get_file_cmd_desc(packet_type)); | 335 "sending packet[%s]:", qq_get_file_cmd_desc(packet_type)); |
336 | 336 |
337 encrypted_data = g_newa(guint8, bytes + 16); | 337 encrypted = g_newa(guint8, bytes + 16); |
338 encrypted_len = qq_encrypt(encrypted_data, raw_data, bytes, info->file_session_key); | 338 encrypted_len = qq_encrypt(encrypted, raw_data, bytes, info->file_session_key); |
339 /*debug: try to decrypt it */ | 339 /*debug: try to decrypt it */ |
340 | 340 |
341 #if 0 | 341 #if 0 |
342 guint8 *buf; | 342 guint8 *buf; |
343 int buflen; | 343 int buflen; |
344 hex_dump = hex_dump_to_str(encrypted_data, encrypted_len); | 344 hex_dump = hex_dump_to_str(encrypted, encrypted_len); |
345 purple_debug_info("QQ", "encrypted packet: \n%s", hex_dump); | 345 purple_debug_info("QQ", "encrypted packet: \n%s", hex_dump); |
346 g_free(hex_dump); | 346 g_free(hex_dump); |
347 buf = g_newa(guint8, MAX_PACKET_SIZE); | 347 buf = g_newa(guint8, MAX_PACKET_SIZE); |
348 buflen = encrypted_len; | 348 buflen = encrypted_len; |
349 if (qq_crypt(DECRYPT, encrypted_data, encrypted_len, info->file_session_key, buf, &buflen)) { | 349 if (qq_crypt(DECRYPT, encrypted, encrypted_len, info->file_session_key, buf, &buflen)) { |
350 purple_debug_info("QQ", "decrypt success\n"); | 350 purple_debug_info("QQ", "decrypt success\n"); |
351 if (buflen == bytes && memcmp(raw_data, buf, buflen) == 0) | 351 if (buflen == bytes && memcmp(raw_data, buf, buflen) == 0) |
352 purple_debug_info("QQ", "checksum ok\n"); | 352 purple_debug_info("QQ", "checksum ok\n"); |
353 | 353 |
354 hex_dump = hex_dump_to_str(buf, buflen); | 354 hex_dump = hex_dump_to_str(buf, buflen); |
358 purple_debug_info("QQ", "decrypt fail\n"); | 358 purple_debug_info("QQ", "decrypt fail\n"); |
359 } | 359 } |
360 #endif | 360 #endif |
361 | 361 |
362 purple_debug_info("QQ", "<== send %s packet\n", qq_get_file_cmd_desc(packet_type)); | 362 purple_debug_info("QQ", "<== send %s packet\n", qq_get_file_cmd_desc(packet_type)); |
363 _qq_send_file(gc, encrypted_data, encrypted_len, QQ_FILE_CONTROL_PACKET_TAG, info->to_uid); | 363 _qq_send_file(gc, encrypted, encrypted_len, QQ_FILE_CONTROL_PACKET_TAG, info->to_uid); |
364 } | 364 } |
365 | 365 |
366 /* send a file to udp channel with QQ_FILE_DATA_PACKET_TAG */ | 366 /* send a file to udp channel with QQ_FILE_DATA_PACKET_TAG */ |
367 static void _qq_send_file_data_packet(PurpleConnection *gc, guint16 packet_type, guint8 sub_type, | 367 static void _qq_send_file_data_packet(PurpleConnection *gc, guint16 packet_type, guint8 sub_type, |
368 guint32 fragment_index, guint16 seq, guint8 *data, gint len) | 368 guint32 fragment_index, guint16 seq, guint8 *data, gint len) |