comparison libpurple/protocols/qq/send_file.c @ 24095:25f62d21b3f8

disapproval of revision '8cebefbc6cd5d84acb69c74e69e8821f11dd225d'
author Daniel Atallah <daniel.atallah@gmail.com>
date Mon, 15 Sep 2008 03:04:07 +0000
parents 147ada94a1d8
children bcfc98c7a55f
comparison
equal deleted inserted replaced
24088:147ada94a1d8 24095:25f62d21b3f8
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(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 }
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(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
119 sin.sin_addr.s_addr = g_htonl(info->remote_real_ip); 119 sin.sin_addr.s_addr = g_htonl(info->remote_real_ip);
120 } else { 120 } else {
121 sin.sin_port = g_htons(info->remote_minor_port); 121 sin.sin_port = g_htons(info->remote_minor_port);
122 sin.sin_addr.s_addr = g_htonl(info->remote_real_ip); 122 sin.sin_addr.s_addr = g_htonl(info->remote_real_ip);
123 } 123 }
124 purple_debug_info("QQ", "sending to channel: %d.%d.%d.%d:%d\n", 124 purple_debug(PURPLE_DEBUG_INFO, "QQ", "sending to channel: %d.%d.%d.%d:%d\n",
125 sin.sin_addr.s_addr & 0xff, 125 (int)sin.sin_addr.s_addr & 0xff,
126 (sin.sin_addr.s_addr >> 8) & 0xff, 126 (int)(sin.sin_addr.s_addr >> 8) & 0xff,
127 (sin.sin_addr.s_addr >> 16) & 0xff, 127 (int)(sin.sin_addr.s_addr >> 16) & 0xff,
128 sin.sin_addr.s_addr >> 24, 128 (int)sin.sin_addr.s_addr >> 24,
129 g_ntohs(sin.sin_port) 129 (int)g_ntohs(sin.sin_port)
130 ); 130 );
131 return sendto(info->sender_fd, buf, len, 0, (struct sockaddr *) &sin, sizeof(sin)); 131 return sendto(info->sender_fd, buf, len, 0, (struct sockaddr *) &sin, sizeof(sin));
132 } 132 }
133 133
134 /* user-defined functions for purple_xfer_read and purple_xfer_write */ 134 /* user-defined functions for purple_xfer_read and purple_xfer_write */
205 info = (ft_info *) xfer->data; 205 info = (ft_info *) xfer->data;
206 206
207 qq_xfer_close_file(xfer); 207 qq_xfer_close_file(xfer);
208 if (info->dest_fp != NULL) { 208 if (info->dest_fp != NULL) {
209 fclose(info->dest_fp); 209 fclose(info->dest_fp);
210 purple_debug_info("QQ", "file closed\n"); 210 purple_debug(PURPLE_DEBUG_INFO, "QQ", "file closed\n");
211 } 211 }
212 if (info->major_fd != 0) { 212 if (info->major_fd != 0) {
213 close(info->major_fd); 213 close(info->major_fd);
214 purple_debug_info("QQ", "major port closed\n"); 214 purple_debug(PURPLE_DEBUG_INFO, "QQ", "major port closed\n");
215 } 215 }
216 if (info->minor_fd != 0) { 216 if (info->minor_fd != 0) {
217 close(info->minor_fd); 217 close(info->minor_fd);
218 purple_debug_info("QQ", "minor port closed\n"); 218 purple_debug(PURPLE_DEBUG_INFO, "QQ", "minor port closed\n");
219 } 219 }
220 /* 220 /*
221 if (info->buffer != NULL) { 221 if (info->buffer != NULL) {
222 munmap(info->buffer, purple_xfer_get_size(xfer)); 222 munmap(info->buffer, purple_xfer_get_size(xfer));
223 purple_debug_info("QQ", "file mapping buffer is freed.\n"); 223 purple_debug(PURPLE_DEBUG_INFO, "QQ", "file mapping buffer is freed.\n");
224 } 224 }
225 */ 225 */
226 g_free(info); 226 g_free(info);
227 } 227 }
228 228
233 233
234 ip = g_htonl(info->remote_real_ip); 234 ip = g_htonl(info->remote_real_ip);
235 real_ip_str = gen_ip_str((guint8 *) &ip); 235 real_ip_str = gen_ip_str((guint8 *) &ip);
236 ip = g_htonl(info->remote_internet_ip); 236 ip = g_htonl(info->remote_internet_ip);
237 internet_ip_str = gen_ip_str((guint8 *) &ip); 237 internet_ip_str = gen_ip_str((guint8 *) &ip);
238 purple_debug_info("QQ", "remote internet ip[%s:%d], major port[%d], real ip[%s], minor port[%d]\n", 238 purple_debug(PURPLE_DEBUG_INFO, "QQ", "remote internet ip[%s:%d], major port[%d], real ip[%s], minor port[%d]\n",
239 internet_ip_str, info->remote_internet_port, 239 internet_ip_str, info->remote_internet_port,
240 info->remote_major_port, real_ip_str, info->remote_minor_port 240 info->remote_major_port, real_ip_str, info->remote_minor_port
241 ); 241 );
242 g_free(real_ip_str); 242 g_free(real_ip_str);
243 g_free(internet_ip_str); 243 g_free(internet_ip_str);
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(PURPLE_DEBUG_INFO, "QQ", "local real ip is %x", info->local_real_ip);
397 397
398 for (i = 0; i < 2; i++) { 398 for (i = 0; i < 2; i++) {
399 sockfd = socket(PF_INET, SOCK_DGRAM, 0); 399 sockfd = socket(PF_INET, SOCK_DGRAM, 0);
400 g_return_if_fail(sockfd >= 0); 400 g_return_if_fail(sockfd >= 0);
401 401
410 410
411 switch (i) { 411 switch (i) {
412 case 0: 412 case 0:
413 info->local_major_port = listen_port; 413 info->local_major_port = listen_port;
414 info->major_fd = sockfd; 414 info->major_fd = sockfd;
415 purple_debug_info("QQ", "UDP Major Channel created on port[%d]\n", 415 purple_debug(PURPLE_DEBUG_INFO, "QQ", "UDP Major Channel created on port[%d]\n",
416 info->local_major_port); 416 info->local_major_port);
417 break; 417 break;
418 case 1: 418 case 1:
419 info->local_minor_port = listen_port; 419 info->local_minor_port = listen_port;
420 info->minor_fd = sockfd; 420 info->minor_fd = sockfd;
421 purple_debug_info("QQ", "UDP Minor Channel created on port[%d]\n", 421 purple_debug(PURPLE_DEBUG_INFO, "QQ", "UDP Minor Channel created on port[%d]\n",
422 info->local_minor_port); 422 info->local_minor_port);
423 break; 423 break;
424 } 424 }
425 } 425 }
426 426
473 bytes += qq_put8 (raw_data + bytes, 0x1f); 473 bytes += qq_put8 (raw_data + bytes, 0x1f);
474 /* file length */ 474 /* file length */
475 bytes += qq_putdata (raw_data + bytes, (guint8 *) filelen_str, filelen_strlen); 475 bytes += qq_putdata (raw_data + bytes, (guint8 *) filelen_str, filelen_strlen);
476 476
477 if (packet_len == bytes) 477 if (packet_len == bytes)
478 qq_send_cmd(gc, QQ_CMD_SEND_IM, raw_data, bytes); 478 qq_send_cmd (qd, QQ_CMD_SEND_IM, raw_data, bytes);
479 else 479 else
480 purple_debug_info("qq_send_packet_file_request", 480 purple_debug (PURPLE_DEBUG_INFO, "qq_send_packet_file_request",
481 "%d bytes expected but got %d bytes\n", 481 "%d bytes expected but got %d bytes\n",
482 packet_len, bytes); 482 packet_len, bytes);
483 483
484 g_free (filelen_str); 484 g_free (filelen_str);
485 } 485 }
495 ft_info *info; 495 ft_info *info;
496 496
497 qd = (qq_data *) gc->proto_data; 497 qd = (qq_data *) gc->proto_data;
498 info = (ft_info *) qd->xfer->data; 498 info = (ft_info *) qd->xfer->data;
499 499
500 purple_debug_info("QQ", "I've accepted the file transfer request from %d\n", to_uid); 500 purple_debug(PURPLE_DEBUG_INFO, "QQ", "I've accepted the file transfer request from %d\n", to_uid);
501 _qq_xfer_init_socket(qd->xfer); 501 _qq_xfer_init_socket(qd->xfer);
502 502
503 packet_len = 79; 503 packet_len = 79;
504 raw_data = g_newa (guint8, packet_len); 504 raw_data = g_newa (guint8, packet_len);
505 bytes = 0; 505 bytes = 0;
514 514
515 info->local_minor_port = minor_port; 515 info->local_minor_port = minor_port;
516 info->local_real_ip = real_ip; 516 info->local_real_ip = real_ip;
517 517
518 if (packet_len == bytes) 518 if (packet_len == bytes)
519 qq_send_cmd(gc, QQ_CMD_SEND_IM, raw_data, bytes); 519 qq_send_cmd (qd, QQ_CMD_SEND_IM, raw_data, bytes);
520 else 520 else
521 purple_debug_info("qq_send_packet_file_accept", 521 purple_debug (PURPLE_DEBUG_INFO, "qq_send_packet_file_accept",
522 "%d bytes expected but got %d bytes\n", 522 "%d bytes expected but got %d bytes\n",
523 packet_len, bytes); 523 packet_len, bytes);
524 } 524 }
525 525
526 static void _qq_send_packet_file_notifyip(PurpleConnection *gc, guint32 to_uid) 526 static void _qq_send_packet_file_notifyip(PurpleConnection *gc, guint32 to_uid)
537 537
538 packet_len = 79; 538 packet_len = 79;
539 raw_data = g_newa (guint8, packet_len); 539 raw_data = g_newa (guint8, packet_len);
540 bytes = 0; 540 bytes = 0;
541 541
542 purple_debug_info("QQ", "<== sending qq file notify ip packet\n"); 542 purple_debug(PURPLE_DEBUG_INFO, "QQ", "<== sending qq file notify ip packet\n");
543 bytes += _qq_create_packet_file_header(raw_data + bytes, to_uid, QQ_FILE_TRANS_NOTIFY, qd, TRUE); 543 bytes += _qq_create_packet_file_header(raw_data + bytes, to_uid, QQ_FILE_TRANS_NOTIFY, qd, TRUE);
544 bytes += qq_fill_conn_info(raw_data + bytes, info); 544 bytes += qq_fill_conn_info(raw_data + bytes, info);
545 if (packet_len == bytes) 545 if (packet_len == bytes)
546 qq_send_cmd(gc, QQ_CMD_SEND_IM, raw_data, bytes); 546 qq_send_cmd (qd, QQ_CMD_SEND_IM, raw_data, bytes);
547 else 547 else
548 purple_debug_info("qq_send_packet_file_notify", 548 purple_debug (PURPLE_DEBUG_INFO, "qq_send_packet_file_notify",
549 "%d bytes expected but got %d bytes\n", 549 "%d bytes expected but got %d bytes\n",
550 packet_len, bytes); 550 packet_len, bytes);
551 551
552 if (xfer->watcher) purple_input_remove(xfer->watcher); 552 if (xfer->watcher) purple_input_remove(xfer->watcher);
553 xfer->watcher = purple_input_add(info->recv_fd, PURPLE_INPUT_READ, _qq_xfer_recv_packet, xfer); 553 xfer->watcher = purple_input_add(info->recv_fd, PURPLE_INPUT_READ, _qq_xfer_recv_packet, xfer);
559 { 559 {
560 qq_data *qd; 560 qq_data *qd;
561 guint8 *raw_data; 561 guint8 *raw_data;
562 gint packet_len, bytes; 562 gint packet_len, bytes;
563 563
564 purple_debug_info("_qq_send_packet_file_reject", "start"); 564 purple_debug(PURPLE_DEBUG_INFO, "_qq_send_packet_file_reject", "start");
565 qd = (qq_data *) gc->proto_data; 565 qd = (qq_data *) gc->proto_data;
566 566
567 packet_len = 64; 567 packet_len = 64;
568 raw_data = g_newa (guint8, packet_len); 568 raw_data = g_newa (guint8, packet_len);
569 bytes = 0; 569 bytes = 0;
570 570
571 bytes += _qq_create_packet_file_header(raw_data + bytes, to_uid, QQ_FILE_TRANS_DENY_UDP, qd, TRUE); 571 bytes += _qq_create_packet_file_header(raw_data + bytes, to_uid, QQ_FILE_TRANS_DENY_UDP, qd, TRUE);
572 572
573 if (packet_len == bytes) 573 if (packet_len == bytes)
574 qq_send_cmd(gc, QQ_CMD_SEND_IM, raw_data, bytes); 574 qq_send_cmd (qd, QQ_CMD_SEND_IM, raw_data, bytes);
575 else 575 else
576 purple_debug_info("qq_send_packet_file", 576 purple_debug (PURPLE_DEBUG_INFO, "qq_send_packet_file",
577 "%d bytes expected but got %d bytes\n", 577 "%d bytes expected but got %d bytes\n",
578 packet_len, bytes); 578 packet_len, bytes);
579 } 579 }
580 580
581 /* tell the buddy to cancel transfer */ 581 /* tell the buddy to cancel transfer */
583 { 583 {
584 qq_data *qd; 584 qq_data *qd;
585 guint8 *raw_data; 585 guint8 *raw_data;
586 gint packet_len, bytes; 586 gint packet_len, bytes;
587 587
588 purple_debug_info("_qq_send_packet_file_cancel", "start\n"); 588 purple_debug(PURPLE_DEBUG_INFO, "_qq_send_packet_file_cancel", "start\n");
589 qd = (qq_data *) gc->proto_data; 589 qd = (qq_data *) gc->proto_data;
590 590
591 packet_len = 64; 591 packet_len = 64;
592 raw_data = g_newa (guint8, packet_len); 592 raw_data = g_newa (guint8, packet_len);
593 bytes = 0; 593 bytes = 0;
594 594
595 purple_debug_info("_qq_send_packet_file_cancel", "before create header\n"); 595 purple_debug(PURPLE_DEBUG_INFO, "_qq_send_packet_file_cancel", "before create header\n");
596 bytes += _qq_create_packet_file_header(raw_data + bytes, to_uid, QQ_FILE_TRANS_CANCEL, qd, TRUE); 596 bytes += _qq_create_packet_file_header(raw_data + bytes, to_uid, QQ_FILE_TRANS_CANCEL, qd, TRUE);
597 purple_debug_info("_qq_send_packet_file_cancel", "end create header\n"); 597 purple_debug(PURPLE_DEBUG_INFO, "_qq_send_packet_file_cancel", "end create header\n");
598 598
599 if (packet_len == bytes) { 599 if (packet_len == bytes) {
600 purple_debug_info("_qq_send_packet_file_cancel", "before send cmd\n"); 600 purple_debug(PURPLE_DEBUG_INFO, "_qq_send_packet_file_cancel", "before send cmd\n");
601 qq_send_cmd(gc, QQ_CMD_SEND_IM, raw_data, bytes); 601 qq_send_cmd (qd, QQ_CMD_SEND_IM, raw_data, bytes);
602 } 602 }
603 else 603 else
604 purple_debug_info("qq_send_packet_file", 604 purple_debug (PURPLE_DEBUG_INFO, "qq_send_packet_file",
605 "%d bytes expected but got %d bytes\n", 605 "%d bytes expected but got %d bytes\n",
606 packet_len, bytes); 606 packet_len, bytes);
607 607
608 purple_debug_info("qq_send_packet_file_cancel", "end\n"); 608 purple_debug (PURPLE_DEBUG_INFO, "qq_send_packet_file_cancel", "end\n");
609 } 609 }
610 610
611 /* request to send a file */ 611 /* request to send a file */
612 static void 612 static void
613 _qq_xfer_init (PurpleXfer * xfer) 613 _qq_xfer_init (PurpleXfer * xfer)
692 qd = (qq_data *) gc->proto_data; 692 qd = (qq_data *) gc->proto_data;
693 g_return_if_fail (qd->xfer != NULL); 693 g_return_if_fail (qd->xfer != NULL);
694 694
695 /* border has been checked before 695 /* border has been checked before
696 if (*cursor >= (data + data_len - 1)) { 696 if (*cursor >= (data + data_len - 1)) {
697 purple_debug_warning("QQ", 697 purple_debug (PURPLE_DEBUG_WARNING, "QQ",
698 "Received file reject message is empty\n"); 698 "Received file reject message is empty\n");
699 return; 699 return;
700 } 700 }
701 */ 701 */
702 filename = strrchr(purple_xfer_get_local_filename(qd->xfer), '/') + 1; 702 filename = strrchr(purple_xfer_get_local_filename(qd->xfer), '/') + 1;
722 g_return_if_fail (qd->xfer != NULL 722 g_return_if_fail (qd->xfer != NULL
723 && purple_xfer_get_filename(qd->xfer) != NULL); 723 && purple_xfer_get_filename(qd->xfer) != NULL);
724 724
725 /* border has been checked before 725 /* border has been checked before
726 if (*cursor >= (data + data_len - 1)) { 726 if (*cursor >= (data + data_len - 1)) {
727 purple_debug_warning("QQ", "Received file reject message is empty\n"); 727 purple_debug (PURPLE_DEBUG_WARNING, "QQ",
728 "Received file reject message is empty\n");
728 return; 729 return;
729 } 730 }
730 */ 731 */
731 filename = strrchr(purple_xfer_get_local_filename(qd->xfer), '/') + 1; 732 filename = strrchr(purple_xfer_get_local_filename(qd->xfer), '/') + 1;
732 msg = g_strdup_printf 733 msg = g_strdup_printf
752 qd = (qq_data *) gc->proto_data; 753 qd = (qq_data *) gc->proto_data;
753 xfer = qd->xfer; 754 xfer = qd->xfer;
754 info = (ft_info *) qd->xfer->data; 755 info = (ft_info *) qd->xfer->data;
755 756
756 if (data_len <= 30 + QQ_CONN_INFO_LEN) { 757 if (data_len <= 30 + QQ_CONN_INFO_LEN) {
757 purple_debug_warning("QQ", "Received file reject message is empty\n"); 758 purple_debug (PURPLE_DEBUG_WARNING, "QQ",
759 "Received file reject message is empty\n");
758 return; 760 return;
759 } 761 }
760 762
761 bytes = 18 + 12; /* skip 30 bytes */ 763 bytes = 18 + 12; /* skip 30 bytes */
762 qq_get_conn_info(info, data + bytes); 764 qq_get_conn_info(info, data + bytes);
785 info->local_internet_port = qd->my_port; 787 info->local_internet_port = qd->my_port;
786 info->local_real_ip = 0x00000000; 788 info->local_real_ip = 0x00000000;
787 info->to_uid = sender_uid; 789 info->to_uid = sender_uid;
788 790
789 if (data_len <= 2 + 30 + QQ_CONN_INFO_LEN) { 791 if (data_len <= 2 + 30 + QQ_CONN_INFO_LEN) {
790 purple_debug_warning("QQ", "Received file request message is empty\n"); 792 purple_debug (PURPLE_DEBUG_WARNING, "QQ",
793 "Received file request message is empty\n");
791 return; 794 return;
792 } 795 }
793 bytes = 0; 796 bytes = 0;
794 bytes += qq_get16(&(info->send_seq), data + bytes); 797 bytes += qq_get16(&(info->send_seq), data + bytes);
795 798
801 804
802 sender_name = uid_to_purple_name(sender_uid); 805 sender_name = uid_to_purple_name(sender_uid);
803 806
804 /* FACE from IP detector, ignored by gfhuang */ 807 /* FACE from IP detector, ignored by gfhuang */
805 if(g_ascii_strcasecmp(fileinfo[0], "FACE") == 0) { 808 if(g_ascii_strcasecmp(fileinfo[0], "FACE") == 0) {
806 purple_debug_warning("QQ", 809 purple_debug(PURPLE_DEBUG_WARNING, "QQ",
807 "Received a FACE ip detect from qq-%d, so he/she must be online :)\n", sender_uid); 810 "Received a FACE ip detect from qq-%d, so he/she must be online :)\n", sender_uid);
808 811
809 b = purple_find_buddy(gc->account, sender_name); 812 b = purple_find_buddy(gc->account, sender_name);
810 q_bud = (b == NULL) ? NULL : (qq_buddy *) b->proto_data; 813 q_bud = (b == NULL) ? NULL : (qq_buddy *) b->proto_data;
811 if (q_bud) { 814 if (q_bud) {
821 if(!is_online(q_bud->status)) { 824 if(!is_online(q_bud->status)) {
822 q_bud->status = QQ_BUDDY_ONLINE_INVISIBLE; 825 q_bud->status = QQ_BUDDY_ONLINE_INVISIBLE;
823 qq_update_buddy_contact(gc, q_bud); 826 qq_update_buddy_contact(gc, q_bud);
824 } 827 }
825 else 828 else
826 purple_debug_info("QQ", "buddy %d is already online\n", sender_uid); 829 purple_debug(PURPLE_DEBUG_INFO, "QQ", "buddy %d is already online\n", sender_uid);
827 830
828 } 831 }
829 else 832 else
830 purple_debug_warning("QQ", "buddy %d is not in list\n", sender_uid); 833 purple_debug(PURPLE_DEBUG_WARNING, "QQ", "buddy %d is not in list\n", sender_uid);
831 834
832 g_free(sender_name); 835 g_free(sender_name);
833 g_strfreev(fileinfo); 836 g_strfreev(fileinfo);
834 return; 837 return;
835 } 838 }
887 qd = (qq_data *) gc->proto_data; 890 qd = (qq_data *) gc->proto_data;
888 891
889 xfer = qd->xfer; 892 xfer = qd->xfer;
890 info = (ft_info *) qd->xfer->data; 893 info = (ft_info *) qd->xfer->data;
891 if (data_len <= 2 + 30 + QQ_CONN_INFO_LEN) { 894 if (data_len <= 2 + 30 + QQ_CONN_INFO_LEN) {
892 purple_debug_warning("QQ", "Received file notify message is empty\n"); 895 purple_debug (PURPLE_DEBUG_WARNING, "QQ",
896 "Received file notify message is empty\n");
893 return; 897 return;
894 } 898 }
895 899
896 bytes = 0; 900 bytes = 0;
897 bytes += qq_get16(&(info->send_seq), data + bytes); 901 bytes += qq_get16(&(info->send_seq), data + bytes);