1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319
|
/*
* Family 0x0002 - Locate.
*
* The functions here are responsible for requesting and parsing information-
* gathering SNACs. Or something like that. This family contains the SNACs
* for getting and setting info, away messages, directory profile thingy, etc.
*/
#define FAIM_INTERNAL
#include <aim.h>
#ifdef _WIN32
#include "win32dep.h"
#endif
/*
* Capability blocks.
*
* These are CLSIDs. They should actually be of the form:
*
* {0x0946134b, 0x4c7f, 0x11d1,
* {0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}}},
*
* But, eh.
*/
static const struct {
fu32_t flag;
fu8_t data[16];
} aim_caps[] = {
/*
* These are in ascending numerical order.
*/
/*
* Perhaps better called AIM_CAPS_SHORTCAPS
*/
{AIM_CAPS_ICHAT,
{0x09, 0x46, 0x00, 0x00, 0x4c, 0x7f, 0x11, 0xd1,
0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}},
{AIM_CAPS_SECUREIM,
{0x09, 0x46, 0x00, 0x01, 0x4c, 0x7f, 0x11, 0xd1,
0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}},
{AIM_CAPS_VIDEO,
{0x09, 0x46, 0x01, 0x00, 0x4c, 0x7f, 0x11, 0xd1,
0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}},
/*
* Not really sure about this one. In an email from
* 26 Sep 2003, Matthew Sachs suggested that, "this
* is probably the capability for the SMS features."
*/
{AIM_CAPS_SMS,
{0x09, 0x46, 0x01, 0xff, 0x4c, 0x7f, 0x11, 0xd1,
0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}},
{AIM_CAPS_GENERICUNKNOWN,
{0x09, 0x46, 0xf0, 0x03, 0x4c, 0x7f, 0x11, 0xd1,
0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}},
{AIM_CAPS_GENERICUNKNOWN,
{0x09, 0x46, 0xf0, 0x04, 0x4c, 0x7f, 0x11, 0xd1,
0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}},
{AIM_CAPS_GENERICUNKNOWN,
{0x09, 0x46, 0xf0, 0x05, 0x4c, 0x7f, 0x11, 0xd1,
0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}},
{AIM_CAPS_HIPTOP,
{0x09, 0x46, 0x13, 0x23, 0x4c, 0x7f, 0x11, 0xd1,
0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}},
{AIM_CAPS_VOICE,
{0x09, 0x46, 0x13, 0x41, 0x4c, 0x7f, 0x11, 0xd1,
0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}},
{AIM_CAPS_SENDFILE,
{0x09, 0x46, 0x13, 0x43, 0x4c, 0x7f, 0x11, 0xd1,
0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}},
{AIM_CAPS_ICQ_DIRECT,
{0x09, 0x46, 0x13, 0x44, 0x4c, 0x7f, 0x11, 0xd1,
0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}},
{AIM_CAPS_DIRECTIM,
{0x09, 0x46, 0x13, 0x45, 0x4c, 0x7f, 0x11, 0xd1,
0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}},
{AIM_CAPS_BUDDYICON,
{0x09, 0x46, 0x13, 0x46, 0x4c, 0x7f, 0x11, 0xd1,
0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}},
/*
* Windows AIM calls this "Add-ins," which is probably more accurate
*/
{AIM_CAPS_SAVESTOCKS,
{0x09, 0x46, 0x13, 0x47, 0x4c, 0x7f, 0x11, 0xd1,
0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}},
{AIM_CAPS_GETFILE,
{0x09, 0x46, 0x13, 0x48, 0x4c, 0x7f, 0x11, 0xd1,
0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}},
{AIM_CAPS_ICQSERVERRELAY,
{0x09, 0x46, 0x13, 0x49, 0x4c, 0x7f, 0x11, 0xd1,
0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}},
/*
* Indeed, there are two of these. The former appears to be correct,
* but in some versions of winaim, the second one is set. Either they
* forgot to fix endianness, or they made a typo. It really doesn't
* matter which.
*/
{AIM_CAPS_GAMES,
{0x09, 0x46, 0x13, 0x4a, 0x4c, 0x7f, 0x11, 0xd1,
0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}},
{AIM_CAPS_GAMES2,
{0x09, 0x46, 0x13, 0x4a, 0x4c, 0x7f, 0x11, 0xd1,
0x22, 0x82, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}},
{AIM_CAPS_SENDBUDDYLIST,
{0x09, 0x46, 0x13, 0x4b, 0x4c, 0x7f, 0x11, 0xd1,
0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}},
/*
* Setting this lets AIM users receive messages from ICQ users, and ICQ
* users receive messages from AIM users. It also lets ICQ users show
* up in buddy lists for AIM users, and AIM users show up in buddy lists
* for ICQ users. And ICQ privacy/invisibility acts like AIM privacy,
* in that if you add a user to your deny list, you will not be able to
* see them as online (previous you could still see them, but they
* couldn't see you.
*/
{AIM_CAPS_INTEROPERATE,
{0x09, 0x46, 0x13, 0x4d, 0x4c, 0x7f, 0x11, 0xd1,
0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}},
{AIM_CAPS_ICQUTF8,
{0x09, 0x46, 0x13, 0x4e, 0x4c, 0x7f, 0x11, 0xd1,
0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}},
{AIM_CAPS_ICQUTF8OLD,
{0x2e, 0x7a, 0x64, 0x75, 0xfa, 0xdf, 0x4d, 0xc8,
0x88, 0x6f, 0xea, 0x35, 0x95, 0xfd, 0xb6, 0xdf}},
/*
* Chat is oddball.
*/
{AIM_CAPS_CHAT,
{0x74, 0x8f, 0x24, 0x20, 0x62, 0x87, 0x11, 0xd1,
0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}},
/*
{AIM_CAPS_ICQ2GO,
{0x56, 0x3f, 0xc8, 0x09, 0x0b, 0x6f, 0x41, 0xbd,
0x9f, 0x79, 0x42, 0x26, 0x09, 0xdf, 0xa2, 0xf3}},
*/
{AIM_CAPS_ICQRTF,
{0x97, 0xb1, 0x27, 0x51, 0x24, 0x3c, 0x43, 0x34,
0xad, 0x22, 0xd6, 0xab, 0xf7, 0x3f, 0x14, 0x92}},
/* This is added by the servers and it only shows up for ourselves... */
{AIM_CAPS_GENERICUNKNOWN,
{0x97, 0xb1, 0x27, 0x51, 0x24, 0x3c, 0x43, 0x34,
0xad, 0x22, 0xd6, 0xab, 0xf7, 0x3f, 0x14, 0x09}},
{AIM_CAPS_APINFO,
{0xaa, 0x4a, 0x32, 0xb5, 0xf8, 0x84, 0x48, 0xc6,
0xa3, 0xd7, 0x8c, 0x50, 0x97, 0x19, 0xfd, 0x5b}},
{AIM_CAPS_TRILLIANCRYPT,
{0xf2, 0xe7, 0xc7, 0xf4, 0xfe, 0xad, 0x4d, 0xfb,
0xb2, 0x35, 0x36, 0x79, 0x8b, 0xdf, 0x00, 0x00}},
{AIM_CAPS_EMPTY,
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}},
{AIM_CAPS_LAST}
};
/*
* Add the userinfo to our linked list. If we already have userinfo
* for this buddy, then just overwrite parts of the old data.
* @param userinfo Contains the new information for the buddy.
*/
static void aim_locate_adduserinfo(aim_session_t *sess, aim_userinfo_t *userinfo) {
aim_userinfo_t *cur;
cur = aim_locate_finduserinfo(sess, userinfo->sn);
if (cur == NULL) {
cur = (aim_userinfo_t *)calloc(1, sizeof(aim_userinfo_t));
cur->sn = strdup(userinfo->sn);
cur->next = sess->locate.userinfo;
sess->locate.userinfo = cur;
}
cur->warnlevel = userinfo->warnlevel;
cur->idletime = userinfo->idletime;
if (userinfo->flags != 0)
cur->flags = userinfo->flags;
if (userinfo->createtime != 0)
cur->createtime = userinfo->createtime;
if (userinfo->membersince != 0)
cur->membersince = userinfo->membersince;
if (userinfo->onlinesince != 0)
cur->onlinesince = userinfo->onlinesince;
if (userinfo->sessionlen != 0)
cur->sessionlen = userinfo->sessionlen;
if (userinfo->capabilities != 0)
cur->capabilities = userinfo->capabilities;
cur->present |= userinfo->present;
if (userinfo->iconcsumlen > 0) {
free(cur->iconcsum);
cur->iconcsum = (fu8_t *)malloc(userinfo->iconcsumlen);
memcpy(cur->iconcsum, userinfo->iconcsum, userinfo->iconcsumlen);
cur->iconcsumlen = userinfo->iconcsumlen;
}
if (userinfo->info != NULL) {
free(cur->info);
free(cur->info_encoding);
cur->info = (char *)malloc(userinfo->info_len);
memcpy(cur->info, userinfo->info, userinfo->info_len);
cur->info_encoding = strdup(userinfo->info_encoding);
cur->info_len = userinfo->info_len;
}
if (userinfo->away != NULL) {
free(cur->away);
free(cur->away_encoding);
cur->away = (char *)malloc(userinfo->away_len);
memcpy(cur->away, userinfo->away, userinfo->away_len);
cur->away_encoding = strdup(userinfo->away_encoding);
cur->away_len = userinfo->away_len;
}
}
static void aim_locate_dorequest(aim_session_t *sess) {
struct userinfo_node *cur = sess->locate.torequest;
if (cur == NULL)
return;
if (sess->locate.waiting_for_response == TRUE)
return;
sess->locate.waiting_for_response = TRUE;
aim_locate_getinfoshort(sess, cur->sn, 0x00000003);
/* Move this node to the "requested" queue */
sess->locate.torequest = cur->next;
cur->next = sess->locate.requested;
sess->locate.requested = cur;
}
/**
* Remove this screen name from our queue. If this info was resquested
* by our info request queue, then pop the next element off of the queue.
*
* @param sess The aim session.
* @param sn Screen name of the info we just received.
* @return True if the request was explicit (client requested the info),
* false if the request was implicit (libfaim request the info).
*/
static int aim_locate_gotuserinfo(aim_session_t *sess, const char *sn) {
struct userinfo_node *cur, *del;
int was_explicit = TRUE;
while ((sess->locate.requested != NULL) && (aim_sncmp(sn, sess->locate.requested->sn) == 0)) {
del = sess->locate.requested;
sess->locate.requested = del->next;
was_explicit = FALSE;
free(del->sn);
free(del);
}
cur = sess->locate.requested;
while ((cur != NULL) && (cur->next != NULL)) {
if (aim_sncmp(sn, cur->next->sn) == 0) {
del = cur->next;
cur->next = del->next;
was_explicit = FALSE;
free(del->sn);
free(del);
} else
cur = cur->next;
}
if (!was_explicit) {
sess->locate.waiting_for_response = FALSE;
aim_locate_dorequest(sess);
}
return was_explicit;
}
faim_internal void aim_locate_requestuserinfo(aim_session_t *sess, const char *sn) {
struct userinfo_node *cur;
/* Make sure we aren't already requesting info for this buddy */
cur = sess->locate.torequest;
while (cur != NULL) {
if (aim_sncmp(sn, cur->sn) == 0)
return;
cur = cur->next;
}
/* Add a new node to our request queue */
cur = (struct userinfo_node *)malloc(sizeof(struct userinfo_node));
cur->sn = strdup(sn);
cur->next = sess->locate.torequest;
sess->locate.torequest = cur;
/* Actually request some info up in this piece */
aim_locate_dorequest(sess);
}
faim_export aim_userinfo_t *aim_locate_finduserinfo(aim_session_t *sess, const char *sn) {
aim_userinfo_t *cur = sess->locate.userinfo;
while (cur != NULL) {
if (aim_sncmp(cur->sn, sn) == 0)
return cur;
cur = cur->next;
}
return NULL;
}
faim_internal fu32_t aim_locate_getcaps(aim_session_t *sess, aim_bstream_t *bs, int len)
{
fu32_t flags = 0;
int offset;
for (offset = 0; aim_bstream_empty(bs) && (offset < len); offset += 0x10) {
fu8_t *cap;
int i, identified;
cap = aimbs_getraw(bs, 0x10);
for (i = 0, identified = 0; !(aim_caps[i].flag & AIM_CAPS_LAST); i++) {
if (memcmp(&aim_caps[i].data, cap, 0x10) == 0) {
flags |= aim_caps[i].flag;
identified++;
break; /* should only match once... */
}
}
if (!identified)
faimdprintf(sess, 0, "unknown capability: {%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x}\n",
cap[0], cap[1], cap[2], cap[3],
cap[4], cap[5],
cap[6], cap[7],
cap[8], cap[9],
cap[10], cap[11], cap[12], cap[13],
cap[14], cap[15]);
free(cap);
}
return flags;
}
faim_internal fu32_t aim_locate_getcaps_short(aim_session_t *sess, aim_bstream_t *bs, int len)
{
fu32_t flags = 0;
int offset;
for (offset = 0; aim_bstream_empty(bs) && (offset < len); offset += 0x02) {
fu8_t *cap;
int i, identified;
cap = aimbs_getraw(bs, 0x02);
for (i = 0, identified = 0; !(aim_caps[i].flag & AIM_CAPS_LAST); i++) {
if (memcmp(&aim_caps[i].data[2], cap, 0x02) == 0) {
flags |= aim_caps[i].flag;
identified++;
break; /* should only match once... */
}
}
if (!identified)
faimdprintf(sess, 0, "unknown short capability: {%02x%02x}\n", cap[0], cap[1]);
free(cap);
}
return flags;
}
faim_internal int aim_putcap(aim_bstream_t *bs, fu32_t caps)
{
int i;
if (!bs)
return -EINVAL;
for (i = 0; aim_bstream_empty(bs); i++) {
if (aim_caps[i].flag == AIM_CAPS_LAST)
break;
if (caps & aim_caps[i].flag)
aimbs_putraw(bs, aim_caps[i].data, 0x10);
}
return 0;
}
static void dumptlv(aim_session_t *sess, fu16_t type, aim_bstream_t *bs, fu8_t len)
{
int i;
if (!sess || !bs || !len)
return;
faimdprintf(sess, 0, "userinfo: type =0x%04x\n", type);
faimdprintf(sess, 0, "userinfo: length=0x%04x\n", len);
faimdprintf(sess, 0, "userinfo: value:\n");
for (i = 0; i < len; i++) {
if ((i % 8) == 0)
faimdprintf(sess, 0, "\nuserinfo: ");
faimdprintf(sess, 0, "0x%2x ", aimbs_get8(bs));
}
faimdprintf(sess, 0, "\n");
return;
}
faim_internal void aim_info_free(aim_userinfo_t *info)
{
free(info->sn);
free(info->iconcsum);
free(info->info);
free(info->info_encoding);
free(info->avail);
free(info->avail_encoding);
free(info->away);
free(info->away_encoding);
}
/*
* AIM is fairly regular about providing user info. This is a generic
* routine to extract it in its standard form.
*/
faim_internal int aim_info_extract(aim_session_t *sess, aim_bstream_t *bs, aim_userinfo_t *outinfo)
{
int curtlv, tlvcnt;
fu8_t snlen;
if (!bs || !outinfo)
return -EINVAL;
/* Clear out old data first */
memset(outinfo, 0x00, sizeof(aim_userinfo_t));
/*
* Screen name. Stored as an unterminated string prepended with a
* byte containing its length.
*/
snlen = aimbs_get8(bs);
outinfo->sn = aimbs_getstr(bs, snlen);
/*
* Warning Level. Stored as an unsigned short.
*/
outinfo->warnlevel = aimbs_get16(bs);
/*
* TLV Count. Unsigned short representing the number of
* Type-Length-Value triples that follow.
*/
tlvcnt = aimbs_get16(bs);
/*
* Parse out the Type-Length-Value triples as they're found.
*/
for (curtlv = 0; curtlv < tlvcnt; curtlv++) {
int endpos;
fu16_t type, length;
type = aimbs_get16(bs);
length = aimbs_get16(bs);
endpos = aim_bstream_curpos(bs) + length;
if (type == 0x0001) {
/*
* Type = 0x0001: User flags
*
* Specified as any of the following ORed together:
* 0x0001 Trial (user less than 60days)
* 0x0002 Unknown bit 2
* 0x0004 AOL Main Service user
* 0x0008 Unknown bit 4
* 0x0010 Free (AIM) user
* 0x0020 Away
* 0x0400 ActiveBuddy
*
*/
outinfo->flags = aimbs_get16(bs);
outinfo->present |= AIM_USERINFO_PRESENT_FLAGS;
} else if (type == 0x0002) {
/*
* Type = 0x0002: Account creation time.
*
* The time/date that the user originally registered for
* the service, stored in time_t format.
*
* I'm not sure how this differs from type 5 ("member
* since").
*
* Note: This is the field formerly known as "member
* since". All these years and I finally found out
* that I got the name wrong.
*/
outinfo->createtime = aimbs_get32(bs);
outinfo->present |= AIM_USERINFO_PRESENT_CREATETIME;
} else if (type == 0x0003) {
/*
* Type = 0x0003: On-Since date.
*
* The time/date that the user started their current
* session, stored in time_t format.
*/
outinfo->onlinesince = aimbs_get32(bs);
outinfo->present |= AIM_USERINFO_PRESENT_ONLINESINCE;
} else if (type == 0x0004) {
/*
* Type = 0x0004: Idle time.
*
* Number of minutes since the user actively used the
* service.
*
* Note that the client tells the server when to start
* counting idle times, so this may or may not be
* related to reality.
*/
outinfo->idletime = aimbs_get16(bs);
outinfo->present |= AIM_USERINFO_PRESENT_IDLE;
} else if (type == 0x0005) {
/*
* Type = 0x0005: Member since date.
*
* The time/date that the user originally registered for
* the service, stored in time_t format.
*
* This is sometimes sent instead of type 2 ("account
* creation time"), particularly in the self-info.
* And particularly for ICQ?
*/
outinfo->membersince = aimbs_get32(bs);
outinfo->present |= AIM_USERINFO_PRESENT_MEMBERSINCE;
} else if (type == 0x0006) {
/*
* Type = 0x0006: ICQ Online Status
*
* ICQ's Away/DND/etc "enriched" status. Some decoding
* of values done by Scott <darkagl@pcnet.com>
*/
aimbs_get16(bs);
outinfo->icqinfo.status = aimbs_get16(bs);
outinfo->present |= AIM_USERINFO_PRESENT_ICQEXTSTATUS;
} else if (type == 0x0008) {
/*
* Type = 0x0008
*
* Client type, or some such.
*/
} else if (type == 0x000a) {
/*
* Type = 0x000a
*
* ICQ User IP Address.
* Ahh, the joy of ICQ security.
*/
outinfo->icqinfo.ipaddr = aimbs_get32(bs);
outinfo->present |= AIM_USERINFO_PRESENT_ICQIPADDR;
} else if (type == 0x000c) {
/*
* Type = 0x000c
*
* random crap containing the IP address,
* apparently a port number, and some Other Stuff.
*
* Format is:
* 4 bytes - Our IP address, 0xc0 a8 01 2b for 192.168.1.43
*
*
*/
aimbs_getrawbuf(bs, outinfo->icqinfo.crap, 0x25);
outinfo->present |= AIM_USERINFO_PRESENT_ICQDATA;
} else if (type == 0x000d) {
/*
* Type = 0x000d
*
* OSCAR Capability information.
*
*/
outinfo->capabilities |= aim_locate_getcaps(sess, bs, length);
outinfo->present |= AIM_USERINFO_PRESENT_CAPABILITIES;
} else if (type == 0x000e) {
/*
* Type = 0x000e
*
* AOL capability information.
*
*/
} else if ((type == 0x000f) || (type == 0x0010)) {
/*
* Type = 0x000f: Session Length. (AIM)
* Type = 0x0010: Session Length. (AOL)
*
* The duration, in seconds, of the user's current
* session.
*
* Which TLV type this comes in depends on the
* service the user is using (AIM or AOL).
*
*/
outinfo->sessionlen = aimbs_get32(bs);
outinfo->present |= AIM_USERINFO_PRESENT_SESSIONLEN;
} else if (type == 0x0019) {
/*
* Type = 0x0019
*
* OSCAR short capability information. A shortened
* form of the normal capabilities.
*/
outinfo->capabilities |= aim_locate_getcaps_short(sess, bs, length);
outinfo->present |= AIM_USERINFO_PRESENT_CAPABILITIES;
} else if (type == 0x001b) {
/*
* Type = 0x001a
*
* AOL short capability information. A shortened
* form of the normal capabilities.
*/
} else if (type == 0x001b) {
/*
* Type = 0x0019
*
* Encryption certification MD5 checksum.
*/
} else if (type == 0x001d) {
/*
* Type = 0x001d
*
* Buddy icon information and available messages.
*
* This almost seems like the AIM protocol guys gave
* the iChat guys a Type, and the iChat guys tried to
* cram as much cool shit into it as possible. Then
* the Windows AIM guys were like, "hey, that's
* pretty neat, let's copy those prawns."
*
* In that spirit, this can contain a custom message,
* kind of like an away message, but you're not away
* (it's called an "available" message). Or it can
* contain information about the buddy icon the user
* has stored on the server.
*/
int type2, number, length2;
while (aim_bstream_curpos(bs) < endpos) {
type2 = aimbs_get16(bs);
number = aimbs_get8(bs);
length2 = aimbs_get8(bs);
switch (type2) {
case 0x0000: { /* This is an official buddy icon? */
/* This is always 5 bytes of "0x02 01 d2 04 72"? */
aim_bstream_advance(bs, length2);
} break;
case 0x0001: { /* A buddy icon checksum */
if ((length2 > 0) && (number == 0x01)) {
free(outinfo->iconcsum);
outinfo->iconcsum = aimbs_getraw(bs, length2);
outinfo->iconcsumlen = length2;
} else
aim_bstream_advance(bs, length2);
} break;
case 0x0002: { /* An available message */
if (length2 > 4) {
free(outinfo->avail);
outinfo->avail_len = aimbs_get16(bs);
outinfo->avail = aimbs_getstr(bs, outinfo->avail_len);
if (aimbs_get16(bs) == 0x0001) { /* We have an encoding */
aimbs_get16(bs);
outinfo->avail_encoding = aimbs_getstr(bs, aimbs_get16(bs));
} else {
/* No explicit encoding, client should use UTF-8 */
outinfo->avail_encoding = NULL;
}
} else
aim_bstream_advance(bs, length2);
} break;
default: {
aim_bstream_advance(bs, length2);
} break;
}
}
} else if (type == 0x001e) {
/*
* Type 30: Unknown.
*
* Always four bytes, but it doesn't look like an int.
*/
} else if (type == 0x001f) {
/*
* Type 31: Unknown.
*
* Seen on a buddy using DeadAIM. Data was 4 bytes:
* 0x00 00 00 10
*/
} else {
/*
* Reaching here indicates that either AOL has
* added yet another TLV for us to deal with,
* or the parsing has gone Terribly Wrong.
*
* Either way, inform the owner and attempt
* recovery.
*
*/
faimdprintf(sess, 0, "userinfo: **warning: unexpected TLV:\n");
faimdprintf(sess, 0, "userinfo: sn =%s\n", outinfo->sn);
dumptlv(sess, type, bs, length);
}
/* Save ourselves. */
aim_bstream_setpos(bs, endpos);
}
aim_locate_adduserinfo(sess, outinfo);
return 0;
}
/*
* Inverse of aim_info_extract()
*/
faim_internal int aim_putuserinfo(aim_bstream_t *bs, aim_userinfo_t *info)
{
aim_tlvlist_t *tlvlist = NULL;
if (!bs || !info)
return -EINVAL;
aimbs_put8(bs, strlen(info->sn));
aimbs_putraw(bs, info->sn, strlen(info->sn));
aimbs_put16(bs, info->warnlevel);
if (info->present & AIM_USERINFO_PRESENT_FLAGS)
aim_tlvlist_add_16(&tlvlist, 0x0001, info->flags);
if (info->present & AIM_USERINFO_PRESENT_MEMBERSINCE)
aim_tlvlist_add_32(&tlvlist, 0x0002, info->membersince);
if (info->present & AIM_USERINFO_PRESENT_ONLINESINCE)
aim_tlvlist_add_32(&tlvlist, 0x0003, info->onlinesince);
if (info->present & AIM_USERINFO_PRESENT_IDLE)
aim_tlvlist_add_16(&tlvlist, 0x0004, info->idletime);
/* XXX - So, ICQ_OSCAR_SUPPORT is never defined anywhere... */
#if ICQ_OSCAR_SUPPORT
if (atoi(info->sn) != 0) {
if (info->present & AIM_USERINFO_PRESENT_ICQEXTSTATUS)
aim_tlvlist_add_16(&tlvlist, 0x0006, info->icqinfo.status);
if (info->present & AIM_USERINFO_PRESENT_ICQIPADDR)
aim_tlvlist_add_32(&tlvlist, 0x000a, info->icqinfo.ipaddr);
}
#endif
if (info->present & AIM_USERINFO_PRESENT_CAPABILITIES)
aim_tlvlist_add_caps(&tlvlist, 0x000d, info->capabilities);
if (info->present & AIM_USERINFO_PRESENT_SESSIONLEN)
aim_tlvlist_add_32(&tlvlist, (fu16_t)((info->flags & AIM_FLAG_AOL) ? 0x0010 : 0x000f), info->sessionlen);
aimbs_put16(bs, aim_tlvlist_count(&tlvlist));
aim_tlvlist_write(bs, &tlvlist);
aim_tlvlist_free(&tlvlist);
return 0;
}
/*
* Subtype 0x0001
*/
static int error(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs)
{
int ret = 0;
aim_rxcallback_t userfunc;
aim_snac_t *snac2;
fu16_t reason;
char *sn;
int was_explicit;
if (!(snac2 = aim_remsnac(sess, snac->id))) {
faimdprintf(sess, 0, "faim: locate.c, error(): received response from unknown request!\n");
return 0;
}
if ((snac2->family != 0x0002) && (snac2->type != 0x0015)) {
faimdprintf(sess, 0, "faim: locate.c, error(): received response from invalid request! %d\n", snac2->family);
return 0;
}
if (!(sn = snac2->data)) {
faimdprintf(sess, 0, "faim: locate.c, error(): received response from request without a screen name!\n");
return 0;
}
reason = aimbs_get16(bs);
/*
* Remove this screen name from our queue. If the client requested
* this buddy's info explicitly, then notify them that we do not have
* info for this buddy.
*/
was_explicit = aim_locate_gotuserinfo(sess, sn);
if (was_explicit == TRUE)
if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
ret = userfunc(sess, rx, reason, sn);
if (snac2)
free(snac2->data);
free(snac2);
return ret;
}
/*
* Subtype 0x0002
*
* Request Location services rights.
*
*/
faim_export int aim_locate_reqrights(aim_session_t *sess)
{
aim_conn_t *conn;
if (!sess || !(conn = aim_conn_findbygroup(sess, AIM_CB_FAM_LOC)))
return -EINVAL;
return aim_genericreq_n_snacid(sess, conn, AIM_CB_FAM_LOC, AIM_CB_LOC_REQRIGHTS);
}
/*
* Subtype 0x0003
*
* Normally contains:
* t(0001) - short containing max profile length (value = 1024)
* t(0002) - short - unknown (value = 16) [max MIME type length?]
* t(0003) - short - unknown (value = 10)
* t(0004) - short - unknown (value = 2048) [ICQ only?]
*/
static int rights(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs)
{
aim_tlvlist_t *tlvlist;
aim_rxcallback_t userfunc;
int ret = 0;
fu16_t maxsiglen = 0;
tlvlist = aim_tlvlist_read(bs);
if (aim_tlv_gettlv(tlvlist, 0x0001, 1))
maxsiglen = aim_tlv_get16(tlvlist, 0x0001, 1);
if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
ret = userfunc(sess, rx, maxsiglen);
aim_tlvlist_free(&tlvlist);
return ret;
}
/*
* Subtype 0x0004
*
* Gives BOS your profile.
*
* profile_encoding and awaymsg_encoding MUST be set if profile or
* away are set, respectively, and their value may or may not be
* restricted to a few choices. I am currently aware of:
*
* us-ascii Just that
* unicode-2-0 UCS2-BE
*
* profile_len and awaymsg_len MUST be set similarly, and they MUST
* be the length of their respective strings in bytes.
*
* To get the previous behavior of awaymsg == "" un-setting the away
* message, set awaymsg non-NULL and awaymsg_len to 0 (this is the
* obvious equivalent).
*
*/
faim_export int aim_locate_setprofile(aim_session_t *sess,
const char *profile_encoding, const char *profile, const int profile_len,
const char *awaymsg_encoding, const char *awaymsg, const int awaymsg_len)
{
aim_conn_t *conn;
aim_frame_t *fr;
aim_snacid_t snacid;
aim_tlvlist_t *tl = NULL;
char *encoding;
static const char defencoding[] = {"text/aolrtf; charset=\"%s\""};
if (!sess || !(conn = aim_conn_findbygroup(sess, AIM_CB_FAM_LOC)))
return -EINVAL;
if (!profile && !awaymsg)
return -EINVAL;
if ((profile && profile_encoding == NULL) || (awaymsg && awaymsg_len && awaymsg_encoding == NULL)) {
return -EINVAL;
}
/* Build the packet first to get real length */
if (profile) {
/* no + 1 here because of %s */
encoding = malloc(strlen(defencoding) + strlen(profile_encoding));
if (encoding == NULL) {
return -ENOMEM;
}
snprintf(encoding, strlen(defencoding) + strlen(profile_encoding), defencoding, profile_encoding);
aim_tlvlist_add_raw(&tl, 0x0001, strlen(encoding), encoding);
aim_tlvlist_add_raw(&tl, 0x0002, profile_len, profile);
free(encoding);
}
/*
* So here's how this works:
* - You are away when you have a non-zero-length type 4 TLV stored.
* - You become unaway when you clear the TLV with a zero-length
* type 4 TLV.
* - If you do not send the type 4 TLV, your status does not change
* (that is, if you were away, you'll remain away).
*/
if (awaymsg) {
if (awaymsg_len) {
encoding = malloc(strlen(defencoding) + strlen(awaymsg_encoding));
if (encoding == NULL) {
return -ENOMEM;
}
snprintf(encoding, strlen(defencoding) + strlen(awaymsg_encoding), defencoding, awaymsg_encoding);
aim_tlvlist_add_raw(&tl, 0x0003, strlen(encoding), encoding);
aim_tlvlist_add_raw(&tl, 0x0004, awaymsg_len, awaymsg);
free(encoding);
} else
aim_tlvlist_add_noval(&tl, 0x0004);
}
if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10 + aim_tlvlist_size(&tl))))
return -ENOMEM;
snacid = aim_cachesnac(sess, 0x0002, 0x0004, 0x0000, NULL, 0);
aim_putsnac(&fr->data, 0x0002, 0x004, 0x0000, snacid);
aim_tlvlist_write(&fr->data, &tl);
aim_tlvlist_free(&tl);
aim_tx_enqueue(sess, fr);
return 0;
}
/*
* Subtype 0x0004 - Set your client's capabilities.
*/
faim_export int aim_locate_setcaps(aim_session_t *sess, fu32_t caps)
{
aim_conn_t *conn;
aim_frame_t *fr;
aim_snacid_t snacid;
aim_tlvlist_t *tl = NULL;
if (!sess || !(conn = aim_conn_findbygroup(sess, AIM_CB_FAM_LOC)))
return -EINVAL;
aim_tlvlist_add_caps(&tl, 0x0005, caps);
if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10 + aim_tlvlist_size(&tl))))
return -ENOMEM;
snacid = aim_cachesnac(sess, 0x0002, 0x0004, 0x0000, NULL, 0);
aim_putsnac(&fr->data, 0x0002, 0x004, 0x0000, snacid);
aim_tlvlist_write(&fr->data, &tl);
aim_tlvlist_free(&tl);
aim_tx_enqueue(sess, fr);
return 0;
}
/*
* Subtype 0x0005 - Request info of another AIM user.
*
* @param sn The screenname whose info you wish to request.
* @param infotype The type of info you wish to request.
* 0x0001 - Info/profile
* 0x0003 - Away message
* 0x0004 - Capabilities
*/
faim_export int aim_locate_getinfo(aim_session_t *sess, const char *sn, fu16_t infotype)
{
aim_conn_t *conn;
aim_frame_t *fr;
aim_snacid_t snacid;
if (!sess || !(conn = aim_conn_findbygroup(sess, AIM_CB_FAM_LOC)) || !sn)
return -EINVAL;
if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 12+1+strlen(sn))))
return -ENOMEM;
snacid = aim_cachesnac(sess, 0x0002, 0x0005, 0x0000, NULL, 0);
aim_putsnac(&fr->data, 0x0002, 0x0005, 0x0000, snacid);
aimbs_put16(&fr->data, infotype);
aimbs_put8(&fr->data, strlen(sn));
aimbs_putraw(&fr->data, sn, strlen(sn));
aim_tx_enqueue(sess, fr);
return 0;
}
/* Subtype 0x0006 */
static int userinfo(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs)
{
int ret = 0;
aim_rxcallback_t userfunc;
aim_userinfo_t *userinfo, *userinfo2;
aim_tlvlist_t *tlvlist;
aim_tlv_t *tlv = NULL;
int was_explicit;
userinfo = (aim_userinfo_t *)malloc(sizeof(aim_userinfo_t));
aim_info_extract(sess, bs, userinfo);
tlvlist = aim_tlvlist_read(bs);
/* Profile will be 1 and 2 */
userinfo->info_encoding = aim_tlv_getstr(tlvlist, 0x0001, 1);
if ((tlv = aim_tlv_gettlv(tlvlist, 0x0002, 1))) {
userinfo->info = (char *)malloc(tlv->length);
memcpy(userinfo->info, tlv->value, tlv->length);
userinfo->info_len = tlv->length;
}
/* Away message will be 3 and 4 */
userinfo->away_encoding = aim_tlv_getstr(tlvlist, 0x0003, 1);
if ((tlv = aim_tlv_gettlv(tlvlist, 0x0004, 1))) {
userinfo->away = (char *)malloc(tlv->length);
memcpy(userinfo->away, tlv->value, tlv->length);
userinfo->away_len = tlv->length;
}
/* Caps will be 5 */
if ((tlv = aim_tlv_gettlv(tlvlist, 0x0005, 1))) {
aim_bstream_t cbs;
aim_bstream_init(&cbs, tlv->value, tlv->length);
userinfo->capabilities = aim_locate_getcaps(sess, &cbs, tlv->length);
userinfo->present = AIM_USERINFO_PRESENT_CAPABILITIES;
}
aim_tlvlist_free(&tlvlist);
aim_locate_adduserinfo(sess, userinfo);
userinfo2 = aim_locate_finduserinfo(sess, userinfo->sn);
aim_info_free(userinfo);
free(userinfo);
/*
* Remove this screen name from our queue. If the client requested
* this buddy's info explicitly, then notify them that we have info
* for this buddy.
*/
was_explicit = aim_locate_gotuserinfo(sess, userinfo2->sn);
if (was_explicit == TRUE)
if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
ret = userfunc(sess, rx, userinfo2);
return ret;
}
/*
* Subtype 0x0009 - Set directory profile data.
*
* This is not the same as aim_location_setprofile!
* privacy: 1 to allow searching, 0 to disallow.
*
*/
faim_export int aim_locate_setdirinfo(aim_session_t *sess, const char *first, const char *middle, const char *last, const char *maiden, const char *nickname, const char *street, const char *city, const char *state, const char *zip, int country, fu16_t privacy)
{
aim_conn_t *conn;
aim_frame_t *fr;
aim_snacid_t snacid;
aim_tlvlist_t *tl = NULL;
if (!sess || !(conn = aim_conn_findbygroup(sess, AIM_CB_FAM_LOC)))
return -EINVAL;
aim_tlvlist_add_16(&tl, 0x000a, privacy);
if (first)
aim_tlvlist_add_raw(&tl, 0x0001, strlen(first), first);
if (last)
aim_tlvlist_add_raw(&tl, 0x0002, strlen(last), last);
if (middle)
aim_tlvlist_add_raw(&tl, 0x0003, strlen(middle), middle);
if (maiden)
aim_tlvlist_add_raw(&tl, 0x0004, strlen(maiden), maiden);
if (state)
aim_tlvlist_add_raw(&tl, 0x0007, strlen(state), state);
if (city)
aim_tlvlist_add_raw(&tl, 0x0008, strlen(city), city);
if (nickname)
aim_tlvlist_add_raw(&tl, 0x000c, strlen(nickname), nickname);
if (zip)
aim_tlvlist_add_raw(&tl, 0x000d, strlen(zip), zip);
if (street)
aim_tlvlist_add_raw(&tl, 0x0021, strlen(street), street);
if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+aim_tlvlist_size(&tl))))
return -ENOMEM;
snacid = aim_cachesnac(sess, 0x0002, 0x0009, 0x0000, NULL, 0);
aim_putsnac(&fr->data, 0x0002, 0x0009, 0x0000, snacid);
aim_tlvlist_write(&fr->data, &tl);
aim_tlvlist_free(&tl);
aim_tx_enqueue(sess, fr);
return 0;
}
/*
* Subtype 0x000b - Huh? What is this?
*/
faim_export int aim_locate_000b(aim_session_t *sess, const char *sn)
{
aim_conn_t *conn;
aim_frame_t *fr;
aim_snacid_t snacid;
return -EINVAL;
if (!sess || !(conn = aim_conn_findbygroup(sess, AIM_CB_FAM_LOC)) || !sn)
return -EINVAL;
if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+1+strlen(sn))))
return -ENOMEM;
snacid = aim_cachesnac(sess, 0x0002, 0x000b, 0x0000, NULL, 0);
aim_putsnac(&fr->data, 0x0002, 0x000b, 0x0000, snacid);
aimbs_put8(&fr->data, strlen(sn));
aimbs_putraw(&fr->data, sn, strlen(sn));
aim_tx_enqueue(sess, fr);
return 0;
}
/*
* Subtype 0x000f
*
* XXX pass these in better
*
*/
faim_export int aim_locate_setinterests(aim_session_t *sess, const char *interest1, const char *interest2, const char *interest3, const char *interest4, const char *interest5, fu16_t privacy)
{
aim_conn_t *conn;
aim_frame_t *fr;
aim_snacid_t snacid;
aim_tlvlist_t *tl = NULL;
if (!sess || !(conn = aim_conn_findbygroup(sess, AIM_CB_FAM_LOC)))
return -EINVAL;
/* ?? privacy ?? */
aim_tlvlist_add_16(&tl, 0x000a, privacy);
if (interest1)
aim_tlvlist_add_raw(&tl, 0x0000b, strlen(interest1), interest1);
if (interest2)
aim_tlvlist_add_raw(&tl, 0x0000b, strlen(interest2), interest2);
if (interest3)
aim_tlvlist_add_raw(&tl, 0x0000b, strlen(interest3), interest3);
if (interest4)
aim_tlvlist_add_raw(&tl, 0x0000b, strlen(interest4), interest4);
if (interest5)
aim_tlvlist_add_raw(&tl, 0x0000b, strlen(interest5), interest5);
if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+aim_tlvlist_size(&tl))))
return -ENOMEM;
snacid = aim_cachesnac(sess, 0x0002, 0x000f, 0x0000, NULL, 0);
aim_putsnac(&fr->data, 0x0002, 0x000f, 0x0000, 0);
aim_tlvlist_write(&fr->data, &tl);
aim_tlvlist_free(&tl);
aim_tx_enqueue(sess, fr);
return 0;
}
/*
* Subtype 0x0015 - Request the info a user using the short method. This is
* what iChat uses. It normally is VERY leniently rate limited.
*
* @param sn The screen name whose info you wish to request.
* @param flags The bitmask which specifies the type of info you wish to request.
* 0x00000001 - Info/profile.
* 0x00000002 - Away message.
* 0x00000004 - Capabilities.
* 0x00000008 - Certification.
* @return Return 0 if no errors, otherwise return the error number.
*/
faim_export int aim_locate_getinfoshort(aim_session_t *sess, const char *sn, fu32_t flags)
{
aim_conn_t *conn;
aim_frame_t *fr;
aim_snacid_t snacid;
if (!sess || !(conn = aim_conn_findbygroup(sess, AIM_CB_FAM_LOC)) || !sn)
return -EINVAL;
if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+4+1+strlen(sn))))
return -ENOMEM;
snacid = aim_cachesnac(sess, 0x0002, 0x0015, 0x0000, sn, strlen(sn)+1);
aim_putsnac(&fr->data, 0x0002, 0x0015, 0x0000, snacid);
aimbs_put32(&fr->data, flags);
aimbs_put8(&fr->data, strlen(sn));
aimbs_putraw(&fr->data, sn, strlen(sn));
aim_tx_enqueue(sess, fr);
return 0;
}
static int snachandler(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs)
{
if (snac->subtype == 0x0001)
return error(sess, mod, rx, snac, bs);
else if (snac->subtype == 0x0003)
return rights(sess, mod, rx, snac, bs);
else if (snac->subtype == 0x0006)
return userinfo(sess, mod, rx, snac, bs);
return 0;
}
static void locate_shutdown(aim_session_t *sess, aim_module_t *mod)
{
aim_userinfo_t *del;
while (sess->locate.userinfo) {
del = sess->locate.userinfo;
sess->locate.userinfo = sess->locate.userinfo->next;
aim_info_free(del);
free(del);
}
}
faim_internal int locate_modfirst(aim_session_t *sess, aim_module_t *mod)
{
mod->family = AIM_CB_FAM_LOC;
mod->version = 0x0001;
mod->toolid = 0x0110;
mod->toolversion = 0x0629;
mod->flags = 0;
strncpy(mod->name, "locate", sizeof(mod->name));
mod->snachandler = snachandler;
mod->shutdown = locate_shutdown;
return 0;
}
|