comparison libgaim/protocols/oscar/family_icbm.c @ 15090:033e1604cf63

[gaim-migrate @ 17875] Add a helper function byte_stream_new() that allocates memory for a bytestream in addition to just initializing the data structure. 9 files changed, 56 insertions(+), 91 deletions(-) committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Sat, 02 Dec 2006 10:17:13 +0000
parents 25c3a33c6485
children c9b56198e8db
comparison
equal deleted inserted replaced
15089:25c3a33c6485 15090:033e1604cf63
311 } else { 311 } else {
312 msgtlvlen += 2 /* 0101 */ + 2 /* block len */; 312 msgtlvlen += 2 /* 0101 */ + 2 /* block len */;
313 msgtlvlen += 4 /* charset */ + args->msglen; 313 msgtlvlen += 4 /* charset */ + args->msglen;
314 } 314 }
315 315
316 byte_stream_init(&data, g_malloc(msgtlvlen + 128), msgtlvlen + 128); 316 byte_stream_new(&data, msgtlvlen + 128);
317 317
318 /* Generate an ICBM cookie */ 318 /* Generate an ICBM cookie */
319 aim_icbm_makecookie(cookie); 319 aim_icbm_makecookie(cookie);
320 320
321 /* ICBM header */ 321 /* ICBM header */
450 aim_snacid_t snacid; 450 aim_snacid_t snacid;
451 IcbmCookie *msgcookie; 451 IcbmCookie *msgcookie;
452 struct aim_invite_priv *priv; 452 struct aim_invite_priv *priv;
453 guchar cookie[8]; 453 guchar cookie[8];
454 aim_tlvlist_t *otl = NULL, *itl = NULL; 454 aim_tlvlist_t *otl = NULL, *itl = NULL;
455 guint8 *hdr;
456 int hdrlen;
457 ByteStream hdrbs; 455 ByteStream hdrbs;
458 456
459 if (!od || !(conn = flap_connection_findbygroup(od, 0x0004))) 457 if (!od || !(conn = flap_connection_findbygroup(od, 0x0004)))
460 return -EINVAL; 458 return -EINVAL;
461 459
492 * Sigh. AOL was rather inconsistent right here. So we have 490 * Sigh. AOL was rather inconsistent right here. So we have
493 * to play some minor tricks. Right inside the type 5 is some 491 * to play some minor tricks. Right inside the type 5 is some
494 * raw data, followed by a series of TLVs. 492 * raw data, followed by a series of TLVs.
495 * 493 *
496 */ 494 */
497 hdrlen = 2+8+16+6+4+4+strlen(msg)+4+2+1+strlen(roomname)+2; 495 byte_stream_new(&hdrbs, 2+8+16+6+4+4+strlen(msg)+4+2+1+strlen(roomname)+2);
498 hdr = malloc(hdrlen);
499 byte_stream_init(&hdrbs, hdr, hdrlen);
500 496
501 byte_stream_put16(&hdrbs, 0x0000); /* Unknown! */ 497 byte_stream_put16(&hdrbs, 0x0000); /* Unknown! */
502 byte_stream_putraw(&hdrbs, cookie, sizeof(cookie)); /* I think... */ 498 byte_stream_putraw(&hdrbs, cookie, sizeof(cookie)); /* I think... */
503 byte_stream_putcaps(&hdrbs, OSCAR_CAPABILITY_CHAT); 499 byte_stream_putcaps(&hdrbs, OSCAR_CAPABILITY_CHAT);
504 500
506 aim_tlvlist_add_noval(&itl, 0x000f); 502 aim_tlvlist_add_noval(&itl, 0x000f);
507 aim_tlvlist_add_str(&itl, 0x000c, msg); 503 aim_tlvlist_add_str(&itl, 0x000c, msg);
508 aim_tlvlist_add_chatroom(&itl, 0x2711, exchange, roomname, instance); 504 aim_tlvlist_add_chatroom(&itl, 0x2711, exchange, roomname, instance);
509 aim_tlvlist_write(&hdrbs, &itl); 505 aim_tlvlist_write(&hdrbs, &itl);
510 506
511 aim_tlvlist_add_raw(&otl, 0x0005, byte_stream_curpos(&hdrbs), hdr); 507 aim_tlvlist_add_raw(&otl, 0x0005, byte_stream_curpos(&hdrbs), hdrbs.data);
508 g_free(hdrbs.data);
512 509
513 aim_tlvlist_write(&frame->data, &otl); 510 aim_tlvlist_write(&frame->data, &otl);
514 511
515 free(hdr);
516 aim_tlvlist_free(&itl); 512 aim_tlvlist_free(&itl);
517 aim_tlvlist_free(&otl); 513 aim_tlvlist_free(&otl);
518 514
519 flap_connection_send(conn, frame); 515 flap_connection_send(conn, frame);
520 516
692 OscarData *od; 688 OscarData *od;
693 FlapConnection *conn; 689 FlapConnection *conn;
694 FlapFrame *frame; 690 FlapFrame *frame;
695 aim_snacid_t snacid; 691 aim_snacid_t snacid;
696 aim_tlvlist_t *tl = NULL, *itl = NULL; 692 aim_tlvlist_t *tl = NULL, *itl = NULL;
697 int hdrlen;
698 guint8 *hdr;
699 ByteStream hdrbs; 693 ByteStream hdrbs;
700 694
701 od = peer_conn->od; 695 od = peer_conn->od;
702 conn = flap_connection_findbygroup(od, 0x0004); 696 conn = flap_connection_findbygroup(od, 0x0004);
703 if (conn == NULL) 697 if (conn == NULL)
711 /* ICBM header */ 705 /* ICBM header */
712 aim_im_puticbm(&frame->data, peer_conn->cookie, 0x0002, peer_conn->sn); 706 aim_im_puticbm(&frame->data, peer_conn->cookie, 0x0002, peer_conn->sn);
713 707
714 aim_tlvlist_add_noval(&tl, 0x0003); 708 aim_tlvlist_add_noval(&tl, 0x0003);
715 709
716 hdrlen = 64; 710 byte_stream_new(&hdrbs, 64);
717 hdr = malloc(hdrlen);
718 byte_stream_init(&hdrbs, hdr, hdrlen);
719 711
720 byte_stream_put16(&hdrbs, AIM_RENDEZVOUS_CANCEL); 712 byte_stream_put16(&hdrbs, AIM_RENDEZVOUS_CANCEL);
721 byte_stream_putraw(&hdrbs, peer_conn->cookie, 8); 713 byte_stream_putraw(&hdrbs, peer_conn->cookie, 8);
722 byte_stream_putcaps(&hdrbs, peer_conn->type); 714 byte_stream_putcaps(&hdrbs, peer_conn->type);
723 715
724 /* This TLV means "cancel!" */ 716 /* This TLV means "cancel!" */
725 aim_tlvlist_add_16(&itl, 0x000b, 0x0001); 717 aim_tlvlist_add_16(&itl, 0x000b, 0x0001);
726 aim_tlvlist_write(&hdrbs, &itl); 718 aim_tlvlist_write(&hdrbs, &itl);
727 719
728 aim_tlvlist_add_raw(&tl, 0x0005, byte_stream_curpos(&hdrbs), hdr); 720 aim_tlvlist_add_raw(&tl, 0x0005, byte_stream_curpos(&hdrbs), hdrbs.data);
721 g_free(hdrbs.data);
729 722
730 aim_tlvlist_write(&frame->data, &tl); 723 aim_tlvlist_write(&frame->data, &tl);
731 724
732 free(hdr);
733 aim_tlvlist_free(&itl); 725 aim_tlvlist_free(&itl);
734 aim_tlvlist_free(&tl); 726 aim_tlvlist_free(&tl);
735 727
736 flap_connection_send(conn, frame); 728 flap_connection_send(conn, frame);
737 } 729 }
782 { 774 {
783 FlapConnection *conn; 775 FlapConnection *conn;
784 FlapFrame *frame; 776 FlapFrame *frame;
785 aim_snacid_t snacid; 777 aim_snacid_t snacid;
786 aim_tlvlist_t *tl = NULL, *itl = NULL; 778 aim_tlvlist_t *tl = NULL, *itl = NULL;
787 int hdrlen;
788 guint8 *hdr;
789 ByteStream hdrbs; 779 ByteStream hdrbs;
790 780
791 conn = flap_connection_findbygroup(od, 0x0004); 781 conn = flap_connection_findbygroup(od, 0x0004);
792 if (conn == NULL) 782 if (conn == NULL)
793 return; 783 return;
800 /* ICBM header */ 790 /* ICBM header */
801 aim_im_puticbm(&frame->data, cookie, 0x0002, sn); 791 aim_im_puticbm(&frame->data, cookie, 0x0002, sn);
802 792
803 aim_tlvlist_add_noval(&tl, 0x0003); 793 aim_tlvlist_add_noval(&tl, 0x0003);
804 794
805 hdrlen = 128; 795 byte_stream_new(&hdrbs, 128);
806 hdr = malloc(hdrlen);
807 byte_stream_init(&hdrbs, hdr, hdrlen);
808 796
809 byte_stream_put16(&hdrbs, AIM_RENDEZVOUS_PROPOSE); 797 byte_stream_put16(&hdrbs, AIM_RENDEZVOUS_PROPOSE);
810 byte_stream_putraw(&hdrbs, cookie, 8); 798 byte_stream_putraw(&hdrbs, cookie, 8);
811 byte_stream_putcaps(&hdrbs, OSCAR_CAPABILITY_DIRECTIM); 799 byte_stream_putcaps(&hdrbs, OSCAR_CAPABILITY_DIRECTIM);
812 800
815 aim_tlvlist_add_16(&itl, 0x0005, port); 803 aim_tlvlist_add_16(&itl, 0x0005, port);
816 aim_tlvlist_add_16(&itl, 0x000a, requestnumber); 804 aim_tlvlist_add_16(&itl, 0x000a, requestnumber);
817 aim_tlvlist_add_noval(&itl, 0x000f); 805 aim_tlvlist_add_noval(&itl, 0x000f);
818 aim_tlvlist_write(&hdrbs, &itl); 806 aim_tlvlist_write(&hdrbs, &itl);
819 807
820 aim_tlvlist_add_raw(&tl, 0x0005, byte_stream_curpos(&hdrbs), hdr); 808 aim_tlvlist_add_raw(&tl, 0x0005, byte_stream_curpos(&hdrbs), hdrbs.data);
809 g_free(hdrbs.data);
821 810
822 aim_tlvlist_write(&frame->data, &tl); 811 aim_tlvlist_write(&frame->data, &tl);
823 812
824 free(hdr);
825 aim_tlvlist_free(&itl); 813 aim_tlvlist_free(&itl);
826 aim_tlvlist_free(&tl); 814 aim_tlvlist_free(&tl);
827 815
828 flap_connection_send(conn, frame); 816 flap_connection_send(conn, frame);
829 } 817 }
837 { 825 {
838 FlapConnection *conn; 826 FlapConnection *conn;
839 FlapFrame *frame; 827 FlapFrame *frame;
840 aim_snacid_t snacid; 828 aim_snacid_t snacid;
841 aim_tlvlist_t *tl = NULL, *itl = NULL; 829 aim_tlvlist_t *tl = NULL, *itl = NULL;
842 int hdrlen;
843 guint8 *hdr;
844 ByteStream hdrbs; 830 ByteStream hdrbs;
845 guint8 ip_comp[4]; 831 guint8 ip_comp[4];
846 832
847 conn = flap_connection_findbygroup(od, 0x0004); 833 conn = flap_connection_findbygroup(od, 0x0004);
848 if (conn == NULL) 834 if (conn == NULL)
856 /* ICBM header */ 842 /* ICBM header */
857 aim_im_puticbm(&frame->data, cookie, 0x0002, sn); 843 aim_im_puticbm(&frame->data, cookie, 0x0002, sn);
858 844
859 aim_tlvlist_add_noval(&tl, 0x0003); 845 aim_tlvlist_add_noval(&tl, 0x0003);
860 846
861 hdrlen = 128; 847 byte_stream_new(&hdrbs, 128);
862 hdr = malloc(hdrlen);
863 byte_stream_init(&hdrbs, hdr, hdrlen);
864 848
865 byte_stream_put16(&hdrbs, AIM_RENDEZVOUS_PROPOSE); 849 byte_stream_put16(&hdrbs, AIM_RENDEZVOUS_PROPOSE);
866 byte_stream_putraw(&hdrbs, cookie, 8); 850 byte_stream_putraw(&hdrbs, cookie, 8);
867 byte_stream_putcaps(&hdrbs, OSCAR_CAPABILITY_DIRECTIM); 851 byte_stream_putcaps(&hdrbs, OSCAR_CAPABILITY_DIRECTIM);
868 852
881 aim_tlvlist_add_raw(&itl, 0x0016, 4, ip_comp); 865 aim_tlvlist_add_raw(&itl, 0x0016, 4, ip_comp);
882 aim_tlvlist_add_16(&itl, 0x0017, ~pin); 866 aim_tlvlist_add_16(&itl, 0x0017, ~pin);
883 867
884 aim_tlvlist_write(&hdrbs, &itl); 868 aim_tlvlist_write(&hdrbs, &itl);
885 869
886 aim_tlvlist_add_raw(&tl, 0x0005, byte_stream_curpos(&hdrbs), hdr); 870 aim_tlvlist_add_raw(&tl, 0x0005, byte_stream_curpos(&hdrbs), hdrbs.data);
871 g_free(hdrbs.data);
887 872
888 aim_tlvlist_write(&frame->data, &tl); 873 aim_tlvlist_write(&frame->data, &tl);
889 874
890 free(hdr);
891 aim_tlvlist_free(&itl); 875 aim_tlvlist_free(&itl);
892 aim_tlvlist_free(&tl); 876 aim_tlvlist_free(&tl);
893 877
894 flap_connection_send(conn, frame); 878 flap_connection_send(conn, frame);
895 } 879 }
903 { 887 {
904 FlapConnection *conn; 888 FlapConnection *conn;
905 FlapFrame *frame; 889 FlapFrame *frame;
906 aim_snacid_t snacid; 890 aim_snacid_t snacid;
907 aim_tlvlist_t *tl = NULL, *itl = NULL; 891 aim_tlvlist_t *tl = NULL, *itl = NULL;
908 int hdrlen, buflen;
909 guint8 *hdr;
910 ByteStream hdrbs; 892 ByteStream hdrbs;
911 893
912 conn = flap_connection_findbygroup(od, 0x0004); 894 conn = flap_connection_findbygroup(od, 0x0004);
913 if (conn == NULL) 895 if (conn == NULL)
914 return; 896 return;
921 /* ICBM header */ 903 /* ICBM header */
922 aim_im_puticbm(&frame->data, cookie, 0x0002, sn); 904 aim_im_puticbm(&frame->data, cookie, 0x0002, sn);
923 905
924 aim_tlvlist_add_noval(&tl, 0x0003); 906 aim_tlvlist_add_noval(&tl, 0x0003);
925 907
926 hdrlen = 512; 908 byte_stream_new(&hdrbs, 512);
927 hdr = malloc(hdrlen);
928 byte_stream_init(&hdrbs, hdr, hdrlen);
929 909
930 byte_stream_put16(&hdrbs, AIM_RENDEZVOUS_PROPOSE); 910 byte_stream_put16(&hdrbs, AIM_RENDEZVOUS_PROPOSE);
931 byte_stream_putraw(&hdrbs, cookie, 8); 911 byte_stream_putraw(&hdrbs, cookie, 8);
932 byte_stream_putcaps(&hdrbs, OSCAR_CAPABILITY_SENDFILE); 912 byte_stream_putcaps(&hdrbs, OSCAR_CAPABILITY_SENDFILE);
933 913
952 if (filename != NULL) 932 if (filename != NULL)
953 { 933 {
954 ByteStream bs; 934 ByteStream bs;
955 935
956 /* Begin TLV t(2711) */ 936 /* Begin TLV t(2711) */
957 buflen = 2+2+4+strlen(filename)+1; 937 byte_stream_new(&bs, 2+2+4+strlen(filename)+1);
958 byte_stream_init(&bs, malloc(buflen), buflen);
959 byte_stream_put16(&bs, (numfiles > 1) ? 0x0002 : 0x0001); 938 byte_stream_put16(&bs, (numfiles > 1) ? 0x0002 : 0x0001);
960 byte_stream_put16(&bs, numfiles); 939 byte_stream_put16(&bs, numfiles);
961 byte_stream_put32(&bs, size); 940 byte_stream_put32(&bs, size);
962 941
963 /* Filename - NULL terminated, for some odd reason */ 942 /* Filename - NULL terminated, for some odd reason */
964 byte_stream_putstr(&bs, filename); 943 byte_stream_putstr(&bs, filename);
965 byte_stream_put8(&bs, 0x00); 944 byte_stream_put8(&bs, 0x00);
966 945
967 aim_tlvlist_add_raw(&itl, 0x2711, bs.len, bs.data); 946 aim_tlvlist_add_raw(&itl, 0x2711, bs.len, bs.data);
968 free(bs.data); 947 g_free(bs.data);
969 /* End TLV t(2711) */ 948 /* End TLV t(2711) */
970 } 949 }
971 950
972 aim_tlvlist_write(&hdrbs, &itl); 951 aim_tlvlist_write(&hdrbs, &itl);
973 aim_tlvlist_add_raw(&tl, 0x0005, byte_stream_curpos(&hdrbs), hdr); 952 aim_tlvlist_add_raw(&tl, 0x0005, byte_stream_curpos(&hdrbs), hdrbs.data);
953 g_free(hdrbs.data);
974 954
975 aim_tlvlist_write(&frame->data, &tl); 955 aim_tlvlist_write(&frame->data, &tl);
976 956
977 free(hdr);
978 aim_tlvlist_free(&itl); 957 aim_tlvlist_free(&itl);
979 aim_tlvlist_free(&tl); 958 aim_tlvlist_free(&tl);
980 959
981 flap_connection_send(conn, frame); 960 flap_connection_send(conn, frame);
982 } 961 }
990 { 969 {
991 FlapConnection *conn; 970 FlapConnection *conn;
992 FlapFrame *frame; 971 FlapFrame *frame;
993 aim_snacid_t snacid; 972 aim_snacid_t snacid;
994 aim_tlvlist_t *tl = NULL, *itl = NULL; 973 aim_tlvlist_t *tl = NULL, *itl = NULL;
995 int hdrlen, buflen;
996 guint8 *hdr;
997 ByteStream hdrbs; 974 ByteStream hdrbs;
998 guint8 ip_comp[4]; 975 guint8 ip_comp[4];
999 976
1000 conn = flap_connection_findbygroup(od, 0x0004); 977 conn = flap_connection_findbygroup(od, 0x0004);
1001 if (conn == NULL) 978 if (conn == NULL)
1009 /* ICBM header */ 986 /* ICBM header */
1010 aim_im_puticbm(&frame->data, cookie, 0x0002, sn); 987 aim_im_puticbm(&frame->data, cookie, 0x0002, sn);
1011 988
1012 aim_tlvlist_add_noval(&tl, 0x0003); 989 aim_tlvlist_add_noval(&tl, 0x0003);
1013 990
1014 hdrlen = 512; 991 byte_stream_new(&hdrbs, 512);
1015 hdr = malloc(hdrlen);
1016 byte_stream_init(&hdrbs, hdr, hdrlen);
1017 992
1018 byte_stream_put16(&hdrbs, AIM_RENDEZVOUS_PROPOSE); 993 byte_stream_put16(&hdrbs, AIM_RENDEZVOUS_PROPOSE);
1019 byte_stream_putraw(&hdrbs, cookie, 8); 994 byte_stream_putraw(&hdrbs, cookie, 8);
1020 byte_stream_putcaps(&hdrbs, OSCAR_CAPABILITY_SENDFILE); 995 byte_stream_putcaps(&hdrbs, OSCAR_CAPABILITY_SENDFILE);
1021 996
1048 if (filename != NULL) 1023 if (filename != NULL)
1049 { 1024 {
1050 ByteStream bs; 1025 ByteStream bs;
1051 1026
1052 /* Begin TLV t(2711) */ 1027 /* Begin TLV t(2711) */
1053 buflen = 2+2+4+strlen(filename)+1; 1028 byte_stream_new(&bs, 2+2+4+strlen(filename)+1);
1054 byte_stream_init(&bs, malloc(buflen), buflen);
1055 byte_stream_put16(&bs, (numfiles > 1) ? 0x0002 : 0x0001); 1029 byte_stream_put16(&bs, (numfiles > 1) ? 0x0002 : 0x0001);
1056 byte_stream_put16(&bs, numfiles); 1030 byte_stream_put16(&bs, numfiles);
1057 byte_stream_put32(&bs, size); 1031 byte_stream_put32(&bs, size);
1058 1032
1059 /* Filename - NULL terminated, for some odd reason */ 1033 /* Filename - NULL terminated, for some odd reason */
1060 byte_stream_putstr(&bs, filename); 1034 byte_stream_putstr(&bs, filename);
1061 byte_stream_put8(&bs, 0x00); 1035 byte_stream_put8(&bs, 0x00);
1062 1036
1063 aim_tlvlist_add_raw(&itl, 0x2711, bs.len, bs.data); 1037 aim_tlvlist_add_raw(&itl, 0x2711, bs.len, bs.data);
1064 free(bs.data); 1038 g_free(bs.data);
1065 /* End TLV t(2711) */ 1039 /* End TLV t(2711) */
1066 } 1040 }
1067 1041
1068 aim_tlvlist_write(&hdrbs, &itl); 1042 aim_tlvlist_write(&hdrbs, &itl);
1069 1043
1070 aim_tlvlist_add_raw(&tl, 0x0005, byte_stream_curpos(&hdrbs), hdr); 1044 aim_tlvlist_add_raw(&tl, 0x0005, byte_stream_curpos(&hdrbs), hdrbs.data);
1045 g_free(hdrbs.data);
1071 1046
1072 aim_tlvlist_write(&frame->data, &tl); 1047 aim_tlvlist_write(&frame->data, &tl);
1073 1048
1074 free(hdr);
1075 aim_tlvlist_free(&itl); 1049 aim_tlvlist_free(&itl);
1076 aim_tlvlist_free(&tl); 1050 aim_tlvlist_free(&tl);
1077 1051
1078 flap_connection_send(conn, frame); 1052 flap_connection_send(conn, frame);
1079 } 1053 }