comparison libpurple/protocols/qq/send_file.c @ 24134: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
comparison
equal deleted inserted replaced
24133:a3cd7c3d9da1 24134:bdfcfd71449c
29 #include "network.h" 29 #include "network.h"
30 #include "notify.h" 30 #include "notify.h"
31 31
32 #include "buddy_list.h" 32 #include "buddy_list.h"
33 #include "file_trans.h" 33 #include "file_trans.h"
34 #include "header_info.h" 34 #include "qq_define.h"
35 #include "im.h" 35 #include "im.h"
36 #include "qq_base.h" 36 #include "qq_base.h"
37 #include "packet_parse.h" 37 #include "packet_parse.h"
38 #include "qq_network.h" 38 #include "qq_network.h"
39 #include "utils.h" 39 #include "utils.h"
52 }; 52 };
53 53
54 static int _qq_in_same_lan(ft_info *info) 54 static int _qq_in_same_lan(ft_info *info)
55 { 55 {
56 if (info->remote_internet_ip == info->local_internet_ip) return 1; 56 if (info->remote_internet_ip == info->local_internet_ip) return 1;
57 purple_debug_info("QQ", 57 purple_debug_info("QQ",
58 "Not in the same LAN, remote internet ip[%x], local internet ip[%x]\n", 58 "Not in the same LAN, remote internet ip[%x], local internet ip[%x]\n",
59 info->remote_internet_ip 59 info->remote_internet_ip
60 , info->local_internet_ip); 60 , info->local_internet_ip);
61 return 0; 61 return 0;
62 } 62 }
63 63
85 gint r; 85 gint r;
86 86
87 info = (ft_info *) xfer->data; 87 info = (ft_info *) xfer->data;
88 sinlen = sizeof(sin); 88 sinlen = sizeof(sin);
89 r = recvfrom(info->recv_fd, buf, len, 0, (struct sockaddr *) &sin, &sinlen); 89 r = recvfrom(info->recv_fd, buf, len, 0, (struct sockaddr *) &sin, &sinlen);
90 purple_debug_info("QQ", 90 purple_debug_info("QQ",
91 "==> recv %d bytes from File UDP Channel, remote ip[%s], remote port[%d]\n", 91 "==> recv %d bytes from File UDP Channel, remote ip[%s], remote port[%d]\n",
92 r, inet_ntoa(sin.sin_addr), g_ntohs(sin.sin_port)); 92 r, inet_ntoa(sin.sin_addr), g_ntohs(sin.sin_port));
93 return r; 93 return r;
94 } 94 }
95 95
299 /* 000-003: receiver uid */ 299 /* 000-003: receiver uid */
300 bytes += qq_put32 (raw_data + bytes, qd->uid); 300 bytes += qq_put32 (raw_data + bytes, qd->uid);
301 /* 004-007: sender uid */ 301 /* 004-007: sender uid */
302 bytes += qq_put32 (raw_data + bytes, to_uid); 302 bytes += qq_put32 (raw_data + bytes, to_uid);
303 /* 008-009: sender client version */ 303 /* 008-009: sender client version */
304 bytes += qq_put16 (raw_data + bytes, QQ_CLIENT); 304 bytes += qq_put16 (raw_data + bytes, qd->client_version);
305 /* 010-013: receiver uid */ 305 /* 010-013: receiver uid */
306 bytes += qq_put32 (raw_data + bytes, qd->uid); 306 bytes += qq_put32 (raw_data + bytes, qd->uid);
307 /* 014-017: sender uid */ 307 /* 014-017: sender uid */
308 bytes += qq_put32 (raw_data + bytes, to_uid); 308 bytes += qq_put32 (raw_data + bytes, to_uid);
309 /* 018-033: md5 of (uid+session_key) */ 309 /* 018-033: md5 of (uid+session_key) */
378 } 378 }
379 #endif 379 #endif
380 380
381 static void _qq_xfer_init_socket(PurpleXfer *xfer) 381 static void _qq_xfer_init_socket(PurpleXfer *xfer)
382 { 382 {
383 gint sockfd, listen_port = 0, i; 383 gint sockfd, listen_port = 0, i;
384 socklen_t sin_len; 384 socklen_t sin_len;
385 struct sockaddr_in sin; 385 struct sockaddr_in sin;
386 ft_info *info; 386 ft_info *info;
387 387
388 g_return_if_fail(xfer != NULL); 388 g_return_if_fail(xfer != NULL);
389 g_return_if_fail(xfer->data != NULL); 389 g_return_if_fail(xfer->data != NULL);
390 info = (ft_info *) xfer->data; 390 info = (ft_info *) xfer->data;
391 391
392 /* debug 392 /* debug
393 info->local_real_ip = 0x7f000001; 393 info->local_real_ip = 0x7f000001;
394 */ 394 */
395 info->local_real_ip = g_ntohl(inet_addr(purple_network_get_my_ip(-1))); 395 info->local_real_ip = g_ntohl(inet_addr(purple_network_get_my_ip(-1)));
396 purple_debug_info("QQ", "local real ip is %x", info->local_real_ip); 396 purple_debug_info("QQ", "local real ip is %x", info->local_real_ip);
397 397
458 458
459 packet_len = 82 + filename_len + filelen_strlen; 459 packet_len = 82 + filename_len + filelen_strlen;
460 raw_data = g_newa(guint8, packet_len); 460 raw_data = g_newa(guint8, packet_len);
461 bytes = 0; 461 bytes = 0;
462 462
463 bytes += _qq_create_packet_file_header(raw_data + bytes, to_uid, 463 bytes += _qq_create_packet_file_header(raw_data + bytes, to_uid,
464 QQ_FILE_TRANS_REQ, qd, FALSE); 464 QQ_FILE_TRANS_REQ, qd, FALSE);
465 bytes += qq_fill_conn_info(raw_data + bytes, info); 465 bytes += qq_fill_conn_info(raw_data + bytes, info);
466 /* 079: 0x20 */ 466 /* 079: 0x20 */
467 bytes += qq_put8 (raw_data + bytes, 0x20); 467 bytes += qq_put8 (raw_data + bytes, 0x20);
468 /* 080: 0x1f */ 468 /* 080: 0x1f */
680 680
681 _qq_send_packet_file_accept(gc, purple_name_to_uid(xfer->who)); 681 _qq_send_packet_file_accept(gc, purple_name_to_uid(xfer->who));
682 } 682 }
683 683
684 /* process reject im for file transfer request */ 684 /* process reject im for file transfer request */
685 void qq_process_recv_file_reject (guint8 *data, gint data_len, 685 void qq_process_recv_file_reject (guint8 *data, gint data_len,
686 guint32 sender_uid, PurpleConnection *gc) 686 guint32 sender_uid, PurpleConnection *gc)
687 { 687 {
688 gchar *msg, *filename; 688 gchar *msg, *filename;
689 qq_data *qd; 689 qq_data *qd;
690 690
709 709
710 g_free (msg); 710 g_free (msg);
711 } 711 }
712 712
713 /* process cancel im for file transfer request */ 713 /* process cancel im for file transfer request */
714 void qq_process_recv_file_cancel (guint8 *data, gint data_len, 714 void qq_process_recv_file_cancel (guint8 *data, gint data_len,
715 guint32 sender_uid, PurpleConnection *gc) 715 guint32 sender_uid, PurpleConnection *gc)
716 { 716 {
717 gchar *msg, *filename; 717 gchar *msg, *filename;
718 qq_data *qd; 718 qq_data *qd;
719 719
783 info = g_newa(ft_info, 1); 783 info = g_newa(ft_info, 1);
784 info->local_internet_ip = qd->my_ip.s_addr; 784 info->local_internet_ip = qd->my_ip.s_addr;
785 info->local_internet_port = qd->my_port; 785 info->local_internet_port = qd->my_port;
786 info->local_real_ip = 0x00000000; 786 info->local_real_ip = 0x00000000;
787 info->to_uid = sender_uid; 787 info->to_uid = sender_uid;
788 788
789 if (data_len <= 2 + 30 + QQ_CONN_INFO_LEN) { 789 if (data_len <= 2 + 30 + QQ_CONN_INFO_LEN) {
790 purple_debug_warning("QQ", "Received file request message is empty\n"); 790 purple_debug_warning("QQ", "Received file request message is empty\n");
791 return; 791 return;
792 } 792 }
793 bytes = 0; 793 bytes = 0;
820 820
821 if(!is_online(q_bud->status)) { 821 if(!is_online(q_bud->status)) {
822 q_bud->status = QQ_BUDDY_ONLINE_INVISIBLE; 822 q_bud->status = QQ_BUDDY_ONLINE_INVISIBLE;
823 qq_update_buddy_contact(gc, q_bud); 823 qq_update_buddy_contact(gc, q_bud);
824 } 824 }
825 else 825 else
826 purple_debug_info("QQ", "buddy %d is already online\n", sender_uid); 826 purple_debug_info("QQ", "buddy %d is already online\n", sender_uid);
827 827
828 } 828 }
829 else 829 else
830 purple_debug_warning("QQ", "buddy %d is not in list\n", sender_uid); 830 purple_debug_warning("QQ", "buddy %d is not in list\n", sender_uid);
831 831
832 g_free(sender_name); 832 g_free(sender_name);
833 g_strfreev(fileinfo); 833 g_strfreev(fileinfo);
834 return; 834 return;
835 } 835 }
836 836
837 xfer = purple_xfer_new(purple_connection_get_account(gc), 837 xfer = purple_xfer_new(purple_connection_get_account(gc),
838 PURPLE_XFER_RECEIVE, 838 PURPLE_XFER_RECEIVE,
839 sender_name); 839 sender_name);
840 if (xfer) 840 if (xfer)
841 { 841 {
873 qq_send_file_ctl_packet(gc, QQ_FILE_CMD_NOTIFY_IP_ACK, info->to_uid, 0); 873 qq_send_file_ctl_packet(gc, QQ_FILE_CMD_NOTIFY_IP_ACK, info->to_uid, 0);
874 info->use_major = FALSE; 874 info->use_major = FALSE;
875 */ 875 */
876 } 876 }
877 877
878 void qq_process_recv_file_notify(guint8 *data, gint data_len, 878 void qq_process_recv_file_notify(guint8 *data, gint data_len,
879 guint32 sender_uid, PurpleConnection *gc) 879 guint32 sender_uid, PurpleConnection *gc)
880 { 880 {
881 gint bytes; 881 gint bytes;
882 qq_data *qd; 882 qq_data *qd;
883 ft_info *info; 883 ft_info *info;
890 info = (ft_info *) qd->xfer->data; 890 info = (ft_info *) qd->xfer->data;
891 if (data_len <= 2 + 30 + QQ_CONN_INFO_LEN) { 891 if (data_len <= 2 + 30 + QQ_CONN_INFO_LEN) {
892 purple_debug_warning("QQ", "Received file notify message is empty\n"); 892 purple_debug_warning("QQ", "Received file notify message is empty\n");
893 return; 893 return;
894 } 894 }
895 895
896 bytes = 0; 896 bytes = 0;
897 bytes += qq_get16(&(info->send_seq), data + bytes); 897 bytes += qq_get16(&(info->send_seq), data + bytes);
898 898
899 bytes += 18 + 12; 899 bytes += 18 + 12;
900 bytes += qq_get_conn_info(info, data + bytes); 900 bytes += qq_get_conn_info(info, data + bytes);