Mercurial > pidgin
comparison src/protocols/oscar/im.c @ 5146:ac9ca88d4b25
[gaim-migrate @ 5510]
I guess I'm gonna go ahead and commit this... I don't think there's any
real functionality change. AIM file transfer might work a little better,
I guess. I probably fixed a bug or two. Like, filenames>64 characters
won't cause infinite loopage.
Changed AIM file transfer a bit with the following two goals:
-Move some code from oscar.c to libfaim. Should make it easier for 3rd
parties to use libfaim for file transfer.
-Allow for easier code reuse with "get file" (in the works)
committer: Tailor Script <tailor@pidgin.im>
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Thu, 17 Apr 2003 03:28:21 +0000 |
parents | ad589b887af9 |
children | 8ab1875e6d09 |
comparison
equal
deleted
inserted
replaced
5145:fc09679bffbe | 5146:ac9ca88d4b25 |
---|---|
665 | 665 |
666 /** | 666 /** |
667 * Subtype 0x0006 - Send an "I want to send you this file" message | 667 * Subtype 0x0006 - Send an "I want to send you this file" message |
668 * | 668 * |
669 */ | 669 */ |
670 faim_export int aim_im_sendch2_sendfile_ask(aim_session_t *sess, fu8_t *cookie, const char *sn, const fu8_t *ip, fu16_t port, const char *filename, fu16_t numfiles, fu32_t totsize) | 670 faim_export int aim_im_sendch2_sendfile_ask(aim_session_t *sess, struct aim_oft_info *oft_info) |
671 { | 671 { |
672 aim_conn_t *conn; | 672 aim_conn_t *conn; |
673 aim_frame_t *fr; | 673 aim_frame_t *fr; |
674 aim_snacid_t snacid; | 674 aim_snacid_t snacid; |
675 aim_tlvlist_t *tl=NULL, *subtl=NULL; | 675 aim_tlvlist_t *tl=NULL, *subtl=NULL; |
676 fu8_t *ck; | |
677 int i; | 676 int i; |
678 | 677 |
679 if (!sess || !(conn = aim_conn_findbygroup(sess, 0x0004))) | 678 if (!sess || !(conn = aim_conn_findbygroup(sess, 0x0004)) || !oft_info) |
680 return -EINVAL; | 679 return -EINVAL; |
681 | 680 |
682 if (!sn || !filename) | |
683 return -EINVAL; | |
684 | |
685 /* XXX - Should be like "21CBF95" and null terminated */ | 681 /* XXX - Should be like "21CBF95" and null terminated */ |
686 ck = (fu8_t *)malloc(8*sizeof(fu8_t)); | |
687 for (i = 0; i < 7; i++) | 682 for (i = 0; i < 7; i++) |
688 ck[i] = 0x30 + ((fu8_t)rand() % 10); | 683 oft_info->cookie[i] = 0x30 + ((fu8_t)rand() % 10); |
689 ck[7] = '\0'; | 684 oft_info->cookie[7] = '\0'; |
690 if (cookie) | |
691 memcpy(cookie, ck, 8); | |
692 | 685 |
693 { /* Create the subTLV chain */ | 686 { /* Create the subTLV chain */ |
694 fu8_t *buf; | 687 fu8_t *buf; |
695 int buflen; | 688 int buflen; |
696 aim_bstream_t bs; | 689 aim_bstream_t bs; |
698 aim_addtlvtochain16(&subtl, 0x000a, 0x0001); | 691 aim_addtlvtochain16(&subtl, 0x000a, 0x0001); |
699 aim_addtlvtochain_noval(&subtl, 0x000f); | 692 aim_addtlvtochain_noval(&subtl, 0x000f); |
700 /* aim_addtlvtochain_raw(&subtl, 0x000e, 2, "en"); | 693 /* aim_addtlvtochain_raw(&subtl, 0x000e, 2, "en"); |
701 aim_addtlvtochain_raw(&subtl, 0x000d, 8, "us-ascii"); | 694 aim_addtlvtochain_raw(&subtl, 0x000d, 8, "us-ascii"); |
702 aim_addtlvtochain_raw(&subtl, 0x000c, 24, "Please accept this file."); */ | 695 aim_addtlvtochain_raw(&subtl, 0x000c, 24, "Please accept this file."); */ |
703 if (ip[0]) | 696 if (oft_info->clientip) { |
697 fu8_t ip[4]; | |
698 char *nexttoken; | |
699 int i = 0; | |
700 nexttoken = strtok(oft_info->clientip, "."); | |
701 while (nexttoken && i<4) { | |
702 ip[i] = atoi(nexttoken); | |
703 nexttoken = strtok(NULL, "."); | |
704 i++; | |
705 } | |
704 aim_addtlvtochain_raw(&subtl, 0x0003, 4, ip); | 706 aim_addtlvtochain_raw(&subtl, 0x0003, 4, ip); |
705 aim_addtlvtochain16(&subtl, 0x0005, port); | 707 } |
708 aim_addtlvtochain16(&subtl, 0x0005, oft_info->port); | |
706 | 709 |
707 /* TLV t(2711) */ | 710 /* TLV t(2711) */ |
708 buflen = 2+2+4+63; | 711 buflen = 2+2+4+strlen(oft_info->fh.name)+1; |
709 buf = malloc(buflen); | 712 buf = malloc(buflen); |
710 aim_bstream_init(&bs, buf, buflen); | 713 aim_bstream_init(&bs, buf, buflen); |
711 aimbs_put16(&bs, (numfiles > 1) ? 0x0002 : 0x0001); | 714 aimbs_put16(&bs, (oft_info->fh.totfiles > 1) ? 0x0002 : 0x0001); |
712 aimbs_put16(&bs, numfiles); | 715 aimbs_put16(&bs, oft_info->fh.totfiles); |
713 aimbs_put32(&bs, totsize); | 716 aimbs_put32(&bs, oft_info->fh.totsize); |
714 | 717 |
715 /* Filename is a fixed size of 63 bytes, so pad with 0's */ | 718 /* Filename - NULL terminated, for some odd reason */ |
716 aimbs_putraw(&bs, filename, strlen(filename)); | 719 aimbs_putraw(&bs, oft_info->fh.name, strlen(oft_info->fh.name)); |
717 for (i=0; i<(63-strlen(filename)); i++) | 720 aimbs_put8(&bs, 0x00); |
718 aimbs_put8(&bs, 0x00); | |
719 | 721 |
720 aim_addtlvtochain_raw(&subtl, 0x2711, bs.len, bs.data); | 722 aim_addtlvtochain_raw(&subtl, 0x2711, bs.len, bs.data); |
721 free(buf); | 723 free(buf); |
722 } | 724 } |
723 | 725 |
729 /* TLV t(0005) - Encompasses everything from above. Gee. */ | 731 /* TLV t(0005) - Encompasses everything from above. Gee. */ |
730 buflen = 2+8+16+aim_sizetlvchain(&subtl); | 732 buflen = 2+8+16+aim_sizetlvchain(&subtl); |
731 buf = malloc(buflen); | 733 buf = malloc(buflen); |
732 aim_bstream_init(&bs, buf, buflen); | 734 aim_bstream_init(&bs, buf, buflen); |
733 aimbs_put16(&bs, AIM_RENDEZVOUS_PROPOSE); | 735 aimbs_put16(&bs, AIM_RENDEZVOUS_PROPOSE); |
734 aimbs_putraw(&bs, ck, 8); | 736 aimbs_putraw(&bs, oft_info->cookie, 8); |
735 aim_putcap(&bs, AIM_CAPS_SENDFILE); | 737 aim_putcap(&bs, AIM_CAPS_SENDFILE); |
736 aim_writetlvchain(&bs, &subtl); | 738 aim_writetlvchain(&bs, &subtl); |
737 aim_freetlvchain(&subtl); | 739 aim_freetlvchain(&subtl); |
738 aim_addtlvtochain_raw(&tl, 0x0005, bs.len, bs.data); | 740 aim_addtlvtochain_raw(&tl, 0x0005, bs.len, bs.data); |
739 free(buf); | 741 free(buf); |
740 | 742 |
741 /* TLV t(0003) - Request an ack */ | 743 /* TLV t(0003) - Request an ack */ |
742 aim_addtlvtochain_noval(&tl, 0x0003); | 744 aim_addtlvtochain_noval(&tl, 0x0003); |
743 } | 745 } |
744 | 746 |
745 if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10 + 11+strlen(sn) + aim_sizetlvchain(&tl)))) | 747 if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10 + 11+strlen(oft_info->sn) + aim_sizetlvchain(&tl)))) |
746 return -ENOMEM; | 748 return -ENOMEM; |
747 | 749 |
748 snacid = aim_cachesnac(sess, 0x0004, 0x0006, AIM_SNACFLAGS_DESTRUCTOR, ck, sizeof(ck)); | 750 snacid = aim_cachesnac(sess, 0x0004, 0x0006, AIM_SNACFLAGS_DESTRUCTOR, oft_info->cookie, sizeof(oft_info->cookie)); |
749 aim_putsnac(&fr->data, 0x0004, 0x0006, 0x0000, snacid); | 751 aim_putsnac(&fr->data, 0x0004, 0x0006, 0x0000, snacid); |
750 | 752 |
751 /* ICBM header */ | 753 /* ICBM header */ |
752 aim_im_puticbm(&fr->data, ck, 0x0002, sn); | 754 aim_im_puticbm(&fr->data, oft_info->cookie, 0x0002, oft_info->sn); |
753 | 755 |
754 /* All that crap from above (the 0x0005 TLV and the 0x0003 TLV) */ | 756 /* All that crap from above (the 0x0005 TLV and the 0x0003 TLV) */ |
755 aim_writetlvchain(&fr->data, &tl); | 757 aim_writetlvchain(&fr->data, &tl); |
756 aim_freetlvchain(&tl); | 758 aim_freetlvchain(&tl); |
757 | 759 |
763 /** | 765 /** |
764 * Subtype 0x0006 - Send an "I will accept this file" message? | 766 * Subtype 0x0006 - Send an "I will accept this file" message? |
765 * | 767 * |
766 * @param rendid Capability type (AIM_CAPS_GETFILE or AIM_CAPS_SENDFILE) | 768 * @param rendid Capability type (AIM_CAPS_GETFILE or AIM_CAPS_SENDFILE) |
767 */ | 769 */ |
768 faim_export int aim_im_sendch2_sendfile_accept(aim_session_t *sess, const fu8_t *cookie, const char *sn, fu16_t rendid) | 770 faim_export int aim_im_sendch2_sendfile_accept(aim_session_t *sess, struct aim_oft_info *oft_info) |
769 { | 771 { |
770 aim_conn_t *conn; | 772 aim_conn_t *conn; |
771 aim_frame_t *fr; | 773 aim_frame_t *fr; |
772 aim_snacid_t snacid; | 774 aim_snacid_t snacid; |
773 | 775 |
774 if (!sess || !(conn = aim_conn_findbygroup(sess, 0x0004)) || !cookie || !sn) | 776 if (!sess || !(conn = aim_conn_findbygroup(sess, 0x0004)) || !oft_info) |
775 return -EINVAL; | 777 return -EINVAL; |
776 | 778 |
777 if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10 + 11+strlen(sn) + 4+2+8+16))) | 779 if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10 + 11+strlen(oft_info->sn) + 4+2+8+16))) |
778 return -ENOMEM; | 780 return -ENOMEM; |
779 | 781 |
780 snacid = aim_cachesnac(sess, 0x0004, 0x0006, 0x0000, NULL, 0); | 782 snacid = aim_cachesnac(sess, 0x0004, 0x0006, 0x0000, NULL, 0); |
781 aim_putsnac(&fr->data, 0x0004, 0x0006, 0x0000, snacid); | 783 aim_putsnac(&fr->data, 0x0004, 0x0006, 0x0000, snacid); |
782 | 784 |
783 /* ICBM header */ | 785 /* ICBM header */ |
784 aim_im_puticbm(&fr->data, cookie, 0x0002, sn); | 786 aim_im_puticbm(&fr->data, oft_info->cookie, 0x0002, oft_info->sn); |
785 | 787 |
786 aimbs_put16(&fr->data, 0x0005); | 788 aimbs_put16(&fr->data, 0x0005); |
787 aimbs_put16(&fr->data, 0x001a); | 789 aimbs_put16(&fr->data, 0x001a); |
788 aimbs_put16(&fr->data, AIM_RENDEZVOUS_ACCEPT); | 790 aimbs_put16(&fr->data, AIM_RENDEZVOUS_ACCEPT); |
789 aimbs_putraw(&fr->data, cookie, 8); | 791 aimbs_putraw(&fr->data, oft_info->cookie, 8); |
790 aim_putcap(&fr->data, rendid); | 792 aim_putcap(&fr->data, AIM_CAPS_SENDFILE); |
791 | 793 |
792 aim_tx_enqueue(sess, fr); | 794 aim_tx_enqueue(sess, fr); |
793 | 795 |
794 return 0; | 796 return 0; |
795 } | 797 } |
796 | 798 |
797 /** | 799 /** |
798 * Subtype 0x0006 - Send a "cancel this file transfer" message? | 800 * Subtype 0x0006 - Send a "cancel this file transfer" message? |
799 * | 801 * |
800 */ | 802 */ |
801 faim_export int aim_im_sendch2_sendfile_cancel(aim_session_t *sess, const fu8_t *cookie, const char *sn, fu16_t rendid) | 803 faim_export int aim_im_sendch2_sendfile_cancel(aim_session_t *sess, struct aim_oft_info *oft_info) |
802 { | 804 { |
803 aim_conn_t *conn; | 805 aim_conn_t *conn; |
804 aim_frame_t *fr; | 806 aim_frame_t *fr; |
805 aim_snacid_t snacid; | 807 aim_snacid_t snacid; |
806 | 808 |
807 if (!sess || !(conn = aim_conn_findbygroup(sess, 0x0004)) || !cookie || !sn) | 809 if (!sess || !(conn = aim_conn_findbygroup(sess, 0x0004)) || !oft_info) |
808 return -EINVAL; | 810 return -EINVAL; |
809 | 811 |
810 if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10 + 11+strlen(sn) + 4+2+8+16))) | 812 if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10 + 11+strlen(oft_info->sn) + 4+2+8+16))) |
811 return -ENOMEM; | 813 return -ENOMEM; |
812 | 814 |
813 snacid = aim_cachesnac(sess, 0x0004, 0x0006, 0x0000, NULL, 0); | 815 snacid = aim_cachesnac(sess, 0x0004, 0x0006, 0x0000, NULL, 0); |
814 aim_putsnac(&fr->data, 0x0004, 0x0006, 0x0000, snacid); | 816 aim_putsnac(&fr->data, 0x0004, 0x0006, 0x0000, snacid); |
815 | 817 |
816 /* ICBM header */ | 818 /* ICBM header */ |
817 aim_im_puticbm(&fr->data, cookie, 0x0002, sn); | 819 aim_im_puticbm(&fr->data, oft_info->cookie, 0x0002, oft_info->sn); |
818 | 820 |
819 aimbs_put16(&fr->data, 0x0005); | 821 aimbs_put16(&fr->data, 0x0005); |
820 aimbs_put16(&fr->data, 0x001a); | 822 aimbs_put16(&fr->data, 0x001a); |
821 aimbs_put16(&fr->data, AIM_RENDEZVOUS_CANCEL); | 823 aimbs_put16(&fr->data, AIM_RENDEZVOUS_CANCEL); |
822 aimbs_putraw(&fr->data, cookie, 8); | 824 aimbs_putraw(&fr->data, oft_info->cookie, 8); |
823 aim_putcap(&fr->data, rendid); | 825 aim_putcap(&fr->data, AIM_CAPS_SENDFILE); |
824 | 826 |
825 aim_tx_enqueue(sess, fr); | 827 aim_tx_enqueue(sess, fr); |
826 | 828 |
827 return 0; | 829 return 0; |
828 } | 830 } |
1767 if (aim_gettlv(list2, 0x000e, 1)) | 1769 if (aim_gettlv(list2, 0x000e, 1)) |
1768 args.language = aim_gettlv_str(list2, 0x000e, 1); | 1770 args.language = aim_gettlv_str(list2, 0x000e, 1); |
1769 | 1771 |
1770 /* | 1772 /* |
1771 * Unknown -- no value | 1773 * Unknown -- no value |
1774 * | |
1775 * Maybe means we should connect directly to transfer the file? | |
1772 */ | 1776 */ |
1773 if (aim_gettlv(list2, 0x000f, 1)) | 1777 if (aim_gettlv(list2, 0x000f, 1)) |
1774 ; | 1778 ; |
1775 | 1779 |
1776 /* | 1780 /* |