/usr/share/amsn/protocol.tcl is in amsn-data 0.98.9-1ubuntu3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 4782 4783 4784 4785 4786 4787 4788 4789 4790 4791 4792 4793 4794 4795 4796 4797 4798 4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825 4826 4827 4828 4829 4830 4831 4832 4833 4834 4835 4836 4837 4838 4839 4840 4841 4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 4865 4866 4867 4868 4869 4870 4871 4872 4873 4874 4875 4876 4877 4878 4879 4880 4881 4882 4883 4884 4885 4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 4896 4897 4898 4899 4900 4901 4902 4903 4904 4905 4906 4907 4908 4909 4910 4911 4912 4913 4914 4915 4916 4917 4918 4919 4920 4921 4922 4923 4924 4925 4926 4927 4928 4929 4930 4931 4932 4933 4934 4935 4936 4937 4938 4939 4940 4941 4942 4943 4944 4945 4946 4947 4948 4949 4950 4951 4952 4953 4954 4955 4956 4957 4958 4959 4960 4961 4962 4963 4964 4965 4966 4967 4968 4969 4970 4971 4972 4973 4974 4975 4976 4977 4978 4979 4980 4981 4982 4983 4984 4985 4986 4987 4988 4989 4990 4991 4992 4993 4994 4995 4996 4997 4998 4999 5000 5001 5002 5003 5004 5005 5006 5007 5008 5009 5010 5011 5012 5013 5014 5015 5016 5017 5018 5019 5020 5021 5022 5023 5024 5025 5026 5027 5028 5029 5030 5031 5032 5033 5034 5035 5036 5037 5038 5039 5040 5041 5042 5043 5044 5045 5046 5047 5048 5049 5050 5051 5052 5053 5054 5055 5056 5057 5058 5059 5060 5061 5062 5063 5064 5065 5066 5067 5068 5069 5070 5071 5072 5073 5074 5075 5076 5077 5078 5079 5080 5081 5082 5083 5084 5085 5086 5087 5088 5089 5090 5091 5092 5093 5094 5095 5096 5097 5098 5099 5100 5101 5102 5103 5104 5105 5106 5107 5108 5109 5110 5111 5112 5113 5114 5115 5116 5117 5118 5119 5120 5121 5122 5123 5124 5125 5126 5127 5128 5129 5130 5131 5132 5133 5134 5135 5136 5137 5138 5139 5140 5141 5142 5143 5144 5145 5146 5147 5148 5149 5150 5151 5152 5153 5154 5155 5156 5157 5158 5159 5160 5161 5162 5163 5164 5165 5166 5167 5168 5169 5170 5171 5172 5173 5174 5175 5176 5177 5178 5179 5180 5181 5182 5183 5184 5185 5186 5187 5188 5189 5190 5191 5192 5193 5194 5195 5196 5197 5198 5199 5200 5201 5202 5203 5204 5205 5206 5207 5208 5209 5210 5211 5212 5213 5214 5215 5216 5217 5218 5219 5220 5221 5222 5223 5224 5225 5226 5227 5228 5229 5230 5231 5232 5233 5234 5235 5236 5237 5238 5239 5240 5241 5242 5243 5244 5245 5246 5247 5248 5249 5250 5251 5252 5253 5254 5255 5256 5257 5258 5259 5260 5261 5262 5263 5264 5265 5266 5267 5268 5269 5270 5271 5272 5273 5274 5275 5276 5277 5278 5279 5280 5281 5282 5283 5284 5285 5286 5287 5288 5289 5290 5291 5292 5293 5294 5295 5296 5297 5298 5299 5300 5301 5302 5303 5304 5305 5306 5307 5308 5309 5310 5311 5312 5313 5314 5315 5316 5317 5318 5319 5320 5321 5322 5323 5324 5325 5326 5327 5328 5329 5330 5331 5332 5333 5334 5335 5336 5337 5338 5339 5340 5341 5342 5343 5344 5345 5346 5347 5348 5349 5350 5351 5352 5353 5354 5355 5356 5357 5358 5359 5360 5361 5362 5363 5364 5365 5366 5367 5368 5369 5370 5371 5372 5373 5374 5375 5376 5377 5378 5379 5380 5381 5382 5383 5384 5385 5386 5387 5388 5389 5390 5391 5392 5393 5394 5395 5396 5397 5398 5399 5400 5401 5402 5403 5404 5405 5406 5407 5408 5409 5410 5411 5412 5413 5414 5415 5416 5417 5418 5419 5420 5421 5422 5423 5424 5425 5426 5427 5428 5429 5430 5431 5432 5433 5434 5435 5436 5437 5438 5439 5440 5441 5442 5443 5444 5445 5446 5447 5448 5449 5450 5451 5452 5453 5454 5455 5456 5457 5458 5459 5460 5461 5462 5463 5464 5465 5466 5467 5468 5469 5470 5471 5472 5473 5474 5475 5476 5477 5478 5479 5480 5481 5482 5483 5484 5485 5486 5487 5488 5489 5490 5491 5492 5493 5494 5495 5496 5497 5498 5499 5500 5501 5502 5503 5504 5505 5506 5507 5508 5509 5510 5511 5512 5513 5514 5515 5516 5517 5518 5519 5520 5521 5522 5523 5524 5525 5526 5527 5528 5529 5530 5531 5532 5533 5534 5535 5536 5537 5538 5539 5540 5541 5542 5543 5544 5545 5546 5547 5548 5549 5550 5551 5552 5553 5554 5555 5556 5557 5558 5559 5560 5561 5562 5563 5564 5565 5566 5567 5568 5569 5570 5571 5572 5573 5574 5575 5576 5577 5578 5579 5580 5581 5582 5583 5584 5585 5586 5587 5588 5589 5590 5591 5592 5593 5594 5595 5596 5597 5598 5599 5600 5601 5602 5603 5604 5605 5606 5607 5608 5609 5610 5611 5612 5613 5614 5615 5616 5617 5618 5619 5620 5621 5622 5623 5624 5625 5626 5627 5628 5629 5630 5631 5632 5633 5634 5635 5636 5637 5638 5639 5640 5641 5642 5643 5644 5645 5646 5647 5648 5649 5650 5651 5652 5653 5654 5655 5656 5657 5658 5659 5660 5661 5662 5663 5664 5665 5666 5667 5668 5669 5670 5671 5672 5673 5674 5675 5676 5677 5678 5679 5680 5681 5682 5683 5684 5685 5686 5687 5688 5689 5690 5691 5692 5693 5694 5695 5696 5697 5698 5699 5700 5701 5702 5703 5704 5705 5706 5707 5708 5709 5710 5711 5712 5713 5714 5715 5716 5717 5718 5719 5720 5721 5722 5723 5724 5725 5726 5727 5728 5729 5730 5731 5732 5733 5734 5735 5736 5737 5738 5739 5740 5741 5742 5743 5744 5745 5746 5747 5748 5749 5750 5751 5752 5753 5754 5755 5756 5757 5758 5759 5760 5761 5762 5763 5764 5765 5766 5767 5768 5769 5770 5771 5772 5773 5774 5775 5776 5777 5778 5779 5780 5781 5782 5783 5784 5785 5786 5787 5788 5789 5790 5791 5792 5793 5794 5795 5796 5797 5798 5799 5800 5801 5802 5803 5804 5805 5806 5807 5808 5809 5810 5811 5812 5813 5814 5815 5816 5817 5818 5819 5820 5821 5822 5823 5824 5825 5826 5827 5828 5829 5830 5831 5832 5833 5834 5835 5836 5837 5838 5839 5840 5841 5842 5843 5844 5845 5846 5847 5848 5849 5850 5851 5852 5853 5854 5855 5856 5857 5858 5859 5860 5861 5862 5863 5864 5865 5866 5867 5868 5869 5870 5871 5872 5873 5874 5875 5876 5877 5878 5879 5880 5881 5882 5883 5884 5885 5886 5887 5888 5889 5890 5891 5892 5893 5894 5895 5896 5897 5898 5899 5900 5901 5902 5903 5904 5905 5906 5907 5908 5909 5910 5911 5912 5913 5914 5915 5916 5917 5918 5919 5920 5921 5922 5923 5924 5925 5926 5927 5928 5929 5930 5931 5932 5933 5934 5935 5936 5937 5938 5939 5940 5941 5942 5943 5944 5945 5946 5947 5948 5949 5950 5951 5952 5953 5954 5955 5956 5957 5958 5959 5960 5961 5962 5963 5964 5965 5966 5967 5968 5969 5970 5971 5972 5973 5974 5975 5976 5977 5978 5979 5980 5981 5982 5983 5984 5985 5986 5987 5988 5989 5990 5991 5992 5993 5994 5995 5996 5997 5998 5999 6000 6001 6002 6003 6004 6005 6006 6007 6008 6009 6010 6011 6012 6013 6014 6015 6016 6017 6018 6019 6020 6021 6022 6023 6024 6025 6026 6027 6028 6029 6030 6031 6032 6033 6034 6035 6036 6037 6038 6039 6040 6041 6042 6043 6044 6045 6046 6047 6048 6049 6050 6051 6052 6053 6054 6055 6056 6057 6058 6059 6060 6061 6062 6063 6064 6065 6066 6067 6068 6069 6070 6071 6072 6073 6074 6075 6076 6077 6078 6079 6080 6081 6082 6083 6084 6085 6086 6087 6088 6089 6090 6091 6092 6093 6094 6095 6096 6097 6098 6099 6100 6101 6102 6103 6104 6105 6106 6107 6108 6109 6110 6111 6112 6113 6114 6115 6116 6117 6118 6119 6120 6121 6122 6123 6124 6125 6126 6127 6128 6129 6130 6131 6132 6133 6134 6135 6136 6137 6138 6139 6140 6141 6142 6143 6144 6145 6146 6147 6148 6149 6150 6151 6152 6153 6154 6155 6156 6157 6158 6159 6160 6161 6162 6163 6164 6165 6166 6167 6168 6169 6170 6171 6172 6173 6174 6175 6176 6177 6178 6179 6180 6181 6182 6183 6184 6185 6186 6187 6188 6189 6190 6191 6192 6193 6194 6195 6196 6197 6198 6199 6200 6201 6202 6203 6204 6205 6206 6207 6208 6209 6210 6211 6212 6213 6214 6215 6216 6217 6218 6219 6220 6221 6222 6223 6224 6225 6226 6227 6228 6229 6230 6231 6232 6233 6234 6235 6236 6237 6238 6239 6240 6241 6242 6243 6244 6245 6246 6247 6248 6249 6250 6251 6252 6253 6254 6255 6256 6257 6258 6259 6260 6261 6262 6263 6264 6265 6266 6267 6268 6269 6270 6271 6272 6273 6274 6275 6276 6277 6278 6279 6280 6281 6282 6283 6284 6285 6286 6287 6288 6289 6290 6291 6292 6293 6294 6295 6296 6297 6298 6299 6300 6301 6302 6303 6304 6305 6306 6307 6308 6309 6310 6311 6312 6313 6314 6315 6316 6317 6318 6319 6320 6321 6322 6323 6324 6325 6326 6327 6328 6329 6330 6331 6332 6333 6334 6335 6336 6337 6338 6339 6340 6341 6342 6343 6344 6345 6346 6347 6348 6349 6350 6351 6352 6353 6354 6355 6356 6357 6358 6359 6360 6361 6362 6363 6364 6365 6366 6367 6368 6369 6370 6371 6372 6373 6374 6375 6376 6377 6378 6379 6380 6381 6382 6383 6384 6385 6386 6387 6388 6389 6390 6391 6392 6393 6394 6395 6396 6397 6398 6399 6400 6401 6402 6403 6404 6405 6406 6407 6408 6409 6410 6411 6412 6413 6414 6415 6416 6417 6418 6419 6420 6421 6422 6423 6424 6425 6426 6427 6428 6429 6430 6431 6432 6433 6434 6435 6436 6437 6438 6439 6440 6441 6442 6443 6444 6445 6446 6447 6448 6449 6450 6451 6452 6453 6454 6455 6456 6457 6458 6459 6460 6461 6462 6463 6464 6465 6466 6467 6468 6469 6470 6471 6472 6473 6474 6475 6476 6477 6478 6479 6480 6481 6482 6483 6484 6485 6486 6487 6488 6489 6490 6491 6492 6493 6494 6495 6496 6497 6498 6499 6500 6501 6502 6503 6504 6505 6506 6507 6508 6509 6510 6511 6512 6513 6514 6515 6516 6517 6518 6519 6520 6521 6522 6523 6524 6525 6526 6527 6528 6529 6530 6531 6532 6533 6534 6535 6536 6537 6538 6539 6540 6541 6542 6543 6544 6545 6546 6547 6548 6549 6550 6551 6552 6553 6554 6555 6556 6557 6558 6559 6560 6561 6562 6563 6564 6565 6566 6567 6568 6569 6570 6571 6572 6573 6574 6575 6576 6577 6578 6579 6580 6581 6582 6583 6584 6585 6586 6587 6588 6589 6590 6591 6592 6593 6594 6595 6596 6597 6598 6599 6600 6601 6602 6603 6604 6605 6606 6607 6608 6609 6610 6611 6612 6613 6614 6615 6616 6617 6618 6619 6620 6621 6622 6623 6624 6625 6626 6627 6628 6629 6630 6631 6632 6633 6634 6635 6636 6637 6638 6639 6640 6641 6642 6643 6644 6645 6646 6647 6648 6649 6650 6651 6652 6653 6654 6655 6656 6657 6658 6659 6660 6661 6662 6663 6664 6665 6666 6667 6668 6669 6670 6671 6672 6673 6674 6675 6676 6677 6678 6679 6680 6681 6682 6683 6684 6685 6686 6687 6688 6689 6690 6691 6692 6693 6694 6695 6696 6697 6698 6699 6700 6701 6702 6703 6704 6705 6706 6707 6708 6709 6710 6711 6712 6713 6714 6715 6716 6717 6718 6719 6720 6721 6722 6723 6724 6725 6726 6727 6728 6729 6730 6731 6732 6733 6734 6735 6736 6737 6738 6739 6740 6741 6742 6743 6744 6745 6746 6747 6748 6749 6750 6751 6752 6753 6754 6755 6756 6757 6758 6759 6760 6761 6762 6763 6764 6765 6766 6767 6768 6769 6770 6771 6772 6773 6774 6775 6776 6777 6778 6779 6780 6781 6782 6783 6784 6785 6786 6787 6788 6789 6790 6791 6792 6793 6794 6795 6796 6797 6798 6799 6800 6801 6802 6803 6804 6805 6806 6807 6808 6809 6810 6811 6812 6813 6814 6815 6816 6817 6818 6819 6820 6821 6822 6823 6824 6825 6826 6827 6828 6829 6830 6831 6832 6833 6834 6835 6836 6837 6838 6839 6840 6841 6842 6843 6844 6845 6846 6847 6848 6849 6850 6851 6852 6853 6854 6855 6856 6857 6858 6859 6860 6861 6862 6863 6864 6865 6866 6867 6868 6869 6870 6871 6872 6873 6874 6875 6876 6877 6878 6879 6880 6881 6882 6883 6884 6885 6886 6887 6888 6889 6890 6891 6892 6893 6894 6895 6896 6897 6898 6899 6900 6901 6902 6903 6904 6905 6906 6907 6908 6909 6910 6911 6912 6913 6914 6915 6916 6917 6918 6919 6920 6921 6922 6923 6924 6925 6926 6927 6928 6929 6930 6931 6932 6933 6934 6935 6936 6937 6938 6939 6940 6941 6942 6943 6944 6945 6946 6947 6948 6949 6950 6951 6952 6953 6954 6955 6956 6957 6958 6959 6960 6961 6962 6963 6964 6965 6966 6967 6968 6969 6970 6971 6972 6973 6974 6975 6976 6977 6978 6979 6980 6981 6982 6983 6984 6985 6986 6987 6988 6989 6990 6991 6992 6993 6994 6995 6996 6997 6998 6999 7000 7001 7002 7003 7004 7005 7006 7007 7008 7009 7010 7011 7012 7013 7014 7015 7016 7017 7018 7019 7020 7021 7022 7023 7024 7025 7026 7027 7028 7029 7030 7031 7032 7033 7034 7035 7036 7037 7038 7039 7040 7041 7042 7043 7044 7045 7046 7047 7048 7049 7050 7051 7052 7053 7054 7055 7056 7057 7058 7059 7060 7061 7062 7063 7064 7065 7066 7067 7068 7069 7070 7071 7072 7073 7074 7075 7076 7077 7078 7079 7080 7081 7082 7083 7084 7085 7086 7087 7088 7089 7090 7091 7092 7093 7094 7095 7096 7097 7098 7099 7100 7101 7102 7103 7104 7105 7106 7107 7108 7109 7110 7111 7112 7113 7114 7115 7116 7117 7118 7119 7120 7121 7122 7123 7124 7125 7126 7127 7128 7129 7130 7131 7132 7133 7134 7135 7136 7137 7138 7139 7140 7141 7142 7143 7144 7145 7146 7147 7148 7149 7150 7151 7152 7153 7154 7155 7156 7157 7158 7159 7160 7161 7162 7163 7164 7165 7166 7167 7168 7169 7170 7171 7172 7173 7174 7175 7176 7177 7178 7179 7180 7181 7182 7183 7184 7185 7186 7187 7188 7189 7190 7191 7192 7193 7194 7195 7196 7197 7198 7199 7200 7201 7202 7203 7204 7205 7206 7207 7208 7209 7210 7211 7212 7213 7214 7215 7216 7217 7218 7219 7220 7221 7222 7223 7224 7225 7226 7227 7228 7229 7230 7231 7232 7233 7234 7235 7236 7237 7238 7239 7240 7241 7242 7243 7244 7245 7246 7247 7248 7249 7250 7251 7252 7253 7254 7255 7256 7257 7258 7259 7260 7261 7262 7263 7264 7265 7266 7267 7268 7269 7270 7271 7272 7273 7274 7275 7276 7277 7278 7279 7280 7281 7282 7283 7284 7285 7286 7287 7288 7289 7290 7291 7292 7293 7294 7295 7296 7297 7298 7299 7300 7301 7302 7303 7304 7305 7306 7307 7308 7309 7310 7311 7312 7313 7314 7315 7316 7317 7318 7319 7320 7321 7322 7323 7324 7325 7326 7327 7328 7329 7330 7331 7332 7333 7334 7335 7336 7337 7338 7339 7340 7341 7342 7343 7344 7345 7346 7347 7348 7349 7350 7351 7352 7353 7354 7355 7356 7357 7358 7359 7360 7361 7362 7363 7364 7365 7366 7367 7368 7369 7370 7371 7372 7373 7374 7375 7376 7377 7378 7379 7380 7381 7382 7383 7384 7385 7386 7387 7388 7389 7390 7391 7392 7393 7394 7395 7396 7397 7398 7399 7400 7401 7402 7403 7404 7405 7406 7407 7408 7409 7410 7411 7412 7413 7414 7415 7416 7417 7418 7419 7420 7421 7422 7423 7424 7425 7426 7427 7428 7429 7430 7431 7432 7433 7434 7435 7436 7437 7438 7439 7440 7441 7442 7443 7444 7445 7446 7447 7448 7449 7450 7451 7452 7453 7454 7455 7456 7457 7458 7459 7460 7461 7462 7463 7464 7465 7466 7467 7468 7469 7470 7471 7472 7473 7474 7475 7476 7477 7478 7479 7480 7481 7482 7483 7484 7485 7486 7487 7488 7489 7490 7491 7492 7493 7494 7495 7496 7497 7498 7499 7500 7501 7502 7503 7504 7505 7506 7507 7508 7509 7510 7511 7512 7513 7514 7515 7516 7517 7518 7519 7520 7521 7522 7523 7524 7525 7526 7527 7528 7529 7530 7531 7532 7533 7534 7535 7536 7537 7538 7539 7540 7541 7542 7543 7544 7545 7546 7547 7548 7549 7550 7551 7552 7553 7554 7555 7556 7557 7558 7559 7560 7561 7562 7563 7564 7565 7566 7567 7568 7569 7570 7571 7572 7573 7574 7575 7576 7577 7578 7579 7580 7581 7582 7583 7584 7585 7586 7587 7588 7589 7590 7591 7592 7593 7594 7595 7596 7597 7598 7599 7600 7601 7602 7603 7604 7605 7606 7607 7608 7609 7610 7611 7612 7613 7614 7615 7616 7617 7618 7619 7620 7621 7622 7623 7624 7625 7626 7627 7628 7629 7630 7631 7632 7633 7634 7635 7636 7637 7638 7639 7640 7641 7642 7643 7644 7645 7646 7647 7648 7649 7650 7651 7652 7653 7654 7655 7656 7657 7658 7659 7660 7661 7662 7663 7664 7665 7666 7667 7668 7669 7670 7671 7672 7673 7674 7675 7676 7677 7678 7679 7680 7681 7682 7683 7684 7685 7686 7687 7688 7689 7690 7691 7692 7693 7694 7695 7696 7697 7698 7699 7700 7701 7702 7703 7704 7705 7706 7707 7708 7709 7710 7711 7712 7713 7714 7715 7716 7717 7718 7719 7720 7721 7722 7723 7724 7725 7726 7727 7728 7729 7730 7731 7732 7733 7734 7735 7736 7737 7738 7739 7740 7741 7742 7743 7744 7745 7746 7747 7748 7749 7750 7751 7752 7753 7754 7755 7756 7757 7758 7759 7760 7761 7762 7763 7764 7765 7766 7767 7768 7769 7770 7771 7772 7773 7774 7775 7776 7777 7778 7779 7780 7781 7782 7783 7784 7785 7786 7787 7788 7789 7790 7791 7792 7793 7794 7795 7796 7797 7798 7799 7800 7801 7802 7803 7804 7805 7806 7807 7808 7809 7810 7811 7812 7813 7814 7815 7816 7817 7818 7819 7820 7821 7822 7823 7824 7825 7826 7827 7828 7829 7830 7831 7832 7833 7834 7835 7836 7837 7838 7839 7840 7841 7842 7843 7844 7845 7846 7847 7848 7849 7850 7851 7852 7853 7854 7855 7856 7857 7858 7859 7860 7861 7862 7863 7864 7865 7866 7867 7868 7869 7870 7871 7872 7873 7874 7875 7876 7877 7878 7879 7880 7881 7882 7883 7884 7885 7886 7887 7888 7889 7890 7891 7892 7893 7894 7895 7896 7897 7898 7899 7900 7901 7902 7903 7904 7905 7906 7907 7908 7909 7910 7911 7912 7913 7914 7915 7916 7917 7918 7919 7920 7921 7922 7923 7924 7925 7926 7927 7928 7929 7930 7931 7932 7933 7934 7935 7936 7937 7938 7939 7940 7941 7942 7943 7944 7945 7946 7947 7948 7949 7950 7951 7952 7953 7954 7955 7956 7957 7958 7959 7960 7961 7962 7963 7964 7965 7966 7967 7968 7969 7970 7971 7972 7973 7974 7975 7976 7977 7978 7979 7980 7981 7982 7983 7984 7985 7986 7987 7988 7989 7990 7991 7992 7993 7994 7995 7996 7997 7998 7999 8000 8001 8002 8003 8004 8005 8006 8007 8008 8009 8010 8011 8012 8013 8014 8015 8016 8017 8018 8019 8020 8021 8022 8023 8024 8025 8026 8027 8028 8029 8030 8031 8032 8033 8034 8035 8036 8037 8038 8039 8040 8041 8042 8043 8044 8045 8046 8047 8048 8049 8050 8051 8052 8053 8054 8055 8056 8057 8058 8059 8060 8061 8062 8063 8064 8065 8066 8067 8068 8069 8070 8071 8072 8073 8074 8075 8076 8077 8078 8079 8080 8081 8082 8083 8084 8085 8086 8087 8088 8089 8090 8091 8092 8093 8094 8095 8096 8097 8098 8099 8100 8101 8102 8103 8104 8105 8106 8107 8108 8109 8110 8111 8112 8113 8114 8115 8116 8117 8118 8119 8120 8121 8122 8123 8124 8125 8126 8127 8128 8129 8130 8131 8132 8133 8134 8135 8136 8137 8138 8139 8140 8141 8142 8143 8144 8145 8146 8147 8148 8149 8150 8151 8152 8153 8154 8155 8156 8157 8158 8159 8160 8161 8162 8163 8164 8165 8166 8167 8168 8169 8170 8171 8172 8173 8174 8175 8176 8177 8178 8179 8180 8181 8182 8183 8184 8185 8186 8187 8188 8189 8190 8191 8192 8193 8194 8195 8196 8197 8198 8199 8200 8201 8202 8203 8204 8205 8206 8207 8208 8209 8210 8211 8212 8213 8214 8215 8216 8217 8218 8219 8220 8221 8222 8223 8224 8225 8226 8227 8228 8229 8230 8231 8232 8233 8234 8235 8236 8237 8238 8239 8240 8241 8242 8243 8244 8245 8246 8247 8248 8249 8250 8251 8252 8253 8254 8255 8256 8257 8258 8259 8260 8261 8262 8263 8264 8265 8266 8267 8268 8269 8270 8271 8272 8273 8274 8275 8276 8277 8278 8279 8280 8281 8282 8283 8284 8285 8286 8287 8288 8289 8290 8291 8292 8293 8294 8295 8296 8297 8298 8299 8300 8301 8302 8303 8304 8305 8306 8307 8308 8309 8310 8311 8312 8313 8314 8315 8316 8317 8318 8319 8320 8321 8322 8323 8324 8325 8326 8327 8328 8329 8330 8331 8332 8333 8334 8335 8336 8337 8338 8339 8340 8341 8342 8343 8344 8345 8346 8347 8348 8349 8350 8351 8352 8353 8354 8355 8356 8357 8358 8359 8360 8361 8362 8363 8364 8365 8366 8367 8368 8369 8370 8371 8372 8373 8374 8375 8376 8377 8378 8379 8380 8381 8382 8383 8384 8385 8386 8387 8388 8389 8390 8391 8392 8393 8394 8395 8396 8397 8398 8399 8400 8401 8402 8403 8404 8405 8406 8407 8408 8409 8410 8411 8412 8413 8414 8415 8416 8417 8418 8419 8420 8421 8422 8423 8424 8425 8426 8427 8428 8429 8430 8431 8432 8433 8434 8435 8436 8437 8438 8439 8440 8441 8442 8443 8444 8445 8446 8447 8448 8449 8450 8451 8452 8453 8454 8455 8456 8457 8458 8459 8460 8461 8462 8463 8464 8465 8466 8467 8468 8469 8470 8471 8472 8473 8474 8475 8476 8477 8478 8479 8480 8481 8482 8483 8484 8485 8486 8487 8488 8489 8490 8491 8492 8493 8494 8495 8496 8497 8498 8499 8500 8501 8502 8503 8504 8505 8506 8507 8508 8509 8510 8511 8512 8513 8514 8515 8516 8517 8518 8519 8520 8521 8522 8523 8524 8525 8526 8527 8528 8529 8530 8531 8532 8533 8534 8535 8536 8537 8538 8539 8540 8541 8542 8543 8544 8545 8546 8547 8548 8549 8550 8551 8552 8553 8554 8555 8556 8557 8558 8559 8560 8561 8562 8563 8564 8565 8566 8567 8568 8569 8570 8571 8572 8573 8574 8575 8576 8577 8578 8579 8580 8581 8582 8583 8584 8585 8586 8587 8588 8589 8590 8591 8592 8593 8594 8595 8596 8597 8598 8599 8600 8601 8602 8603 8604 8605 8606 8607 8608 8609 8610 8611 8612 8613 8614 8615 8616 8617 8618 8619 8620 8621 8622 8623 8624 8625 8626 8627 8628 8629 8630 8631 8632 8633 8634 8635 8636 8637 8638 8639 8640 8641 8642 8643 8644 8645 8646 8647 8648 8649 8650 8651 8652 8653 8654 8655 8656 8657 8658 8659 8660 8661 8662 8663 8664 8665 8666 8667 8668 8669 8670 8671 8672 8673 8674 8675 8676 8677 8678 8679 8680 8681 8682 8683 8684 8685 8686 8687 8688 8689 8690 8691 8692 8693 8694 8695 8696 8697 8698 8699 8700 8701 8702 8703 8704 8705 8706 8707 8708 8709 8710 8711 8712 8713 8714 8715 8716 8717 8718 8719 8720 8721 8722 8723 8724 8725 8726 8727 8728 8729 8730 8731 8732 8733 8734 8735 8736 8737 8738 8739 8740 8741 8742 8743 8744 8745 8746 8747 8748 8749 8750 8751 8752 8753 8754 8755 8756 8757 8758 8759 8760 8761 8762 8763 8764 8765 8766 8767 8768 8769 8770 8771 8772 8773 8774 8775 8776 8777 8778 8779 8780 8781 8782 8783 8784 8785 8786 8787 8788 8789 8790 8791 8792 8793 8794 8795 8796 8797 8798 8799 8800 8801 8802 8803 8804 8805 8806 8807 8808 8809 8810 8811 8812 8813 8814 8815 8816 8817 8818 8819 8820 8821 8822 8823 8824 8825 8826 8827 8828 8829 8830 8831 8832 8833 8834 8835 8836 8837 8838 8839 8840 8841 8842 8843 8844 8845 8846 8847 8848 8849 8850 8851 8852 8853 8854 8855 8856 8857 8858 8859 8860 8861 8862 8863 8864 8865 8866 8867 8868 8869 8870 8871 8872 8873 8874 8875 8876 8877 8878 8879 8880 8881 8882 8883 8884 8885 8886 8887 8888 8889 8890 8891 8892 8893 8894 8895 8896 8897 8898 8899 8900 8901 8902 8903 8904 8905 8906 8907 8908 8909 8910 8911 8912 8913 8914 8915 8916 8917 8918 8919 8920 8921 8922 8923 8924 8925 8926 8927 8928 8929 8930 8931 8932 8933 8934 8935 8936 8937 8938 8939 8940 8941 8942 8943 8944 8945 8946 8947 8948 8949 8950 8951 8952 8953 8954 8955 8956 8957 8958 8959 8960 8961 8962 8963 8964 8965 8966 8967 8968 8969 8970 8971 8972 8973 8974 8975 8976 8977 8978 8979 8980 8981 8982 8983 8984 8985 8986 8987 8988 8989 8990 8991 8992 8993 8994 8995 8996 8997 8998 8999 9000 9001 9002 9003 9004 9005 9006 9007 9008 9009 9010 9011 9012 9013 9014 9015 9016 9017 9018 9019 9020 9021 9022 9023 9024 9025 9026 9027 9028 9029 9030 9031 9032 9033 9034 9035 9036 9037 9038 9039 9040 9041 9042 9043 9044 9045 9046 9047 9048 9049 9050 9051 9052 9053 9054 9055 9056 9057 9058 9059 9060 9061 9062 9063 9064 9065 9066 9067 9068 9069 9070 9071 9072 9073 9074 9075 9076 9077 9078 9079 9080 9081 9082 9083 9084 9085 9086 9087 9088 9089 9090 9091 9092 9093 9094 9095 9096 9097 9098 9099 9100 9101 9102 9103 9104 9105 9106 9107 9108 9109 9110 9111 9112 9113 9114 9115 9116 9117 9118 9119 9120 9121 9122 9123 9124 9125 9126 9127 9128 9129 9130 9131 9132 9133 9134 9135 9136 9137 9138 9139 9140 9141 9142 9143 9144 9145 9146 9147 9148 9149 9150 9151 9152 9153 9154 9155 9156 9157 9158 9159 9160 9161 9162 9163 9164 9165 9166 9167 9168 9169 9170 9171 9172 9173 9174 9175 9176 9177 9178 9179 9180 9181 9182 9183 9184 9185 9186 9187 9188 9189 9190 9191 9192 9193 9194 9195 9196 9197 9198 9199 9200 9201 9202 9203 9204 9205 9206 9207 9208 9209 9210 9211 9212 9213 9214 9215 9216 9217 9218 9219 9220 9221 9222 9223 9224 9225 9226 9227 9228 9229 9230 9231 9232 9233 9234 9235 9236 9237 9238 9239 9240 9241 9242 9243 9244 9245 9246 9247 9248 9249 9250 9251 9252 9253 9254 9255 9256 9257 9258 9259 9260 9261 9262 9263 9264 9265 9266 9267 9268 9269 9270 9271 9272 9273 9274 9275 9276 9277 9278 9279 9280 9281 9282 9283 9284 9285 9286 9287 9288 9289 9290 9291 9292 9293 9294 9295 9296 9297 9298 9299 9300 9301 9302 9303 9304 9305 9306 9307 9308 9309 9310 9311 9312 9313 9314 9315 9316 9317 9318 9319 9320 9321 9322 9323 9324 9325 9326 9327 9328 9329 9330 9331 9332 9333 9334 9335 9336 9337 9338 9339 9340 9341 9342 9343 9344 9345 9346 9347 9348 9349 9350 9351 9352 9353 9354 9355 9356 9357 9358 9359 9360 9361 9362 9363 9364 9365 9366 9367 9368 9369 9370 9371 9372 9373 9374 9375 9376 9377 9378 9379 9380 9381 9382 9383 9384 9385 9386 9387 9388 9389 9390 9391 9392 9393 9394 9395 9396 9397 9398 9399 9400 9401 9402 9403 9404 9405 9406 9407 9408 9409 9410 9411 9412 9413 9414 9415 9416 9417 9418 9419 9420 9421 9422 9423 9424 9425 9426 9427 9428 9429 9430 9431 9432 9433 9434 9435 9436 9437 9438 9439 9440 9441 9442 9443 9444 9445 9446 9447 9448 9449 9450 9451 9452 9453 9454 9455 9456 9457 9458 9459 9460 9461 9462 9463 9464 9465 9466 9467 9468 9469 9470 9471 9472 9473 9474 9475 9476 9477 9478 9479 9480 9481 9482 9483 9484 9485 9486 9487 9488 9489 9490 9491 9492 9493 9494 9495 9496 9497 9498 9499 9500 9501 9502 9503 9504 9505 9506 9507 9508 9509 9510 9511 9512 9513 9514 9515 9516 9517 9518 9519 9520 9521 9522 9523 9524 9525 9526 9527 9528 9529 9530 9531 9532 9533 9534 9535 9536 9537 9538 9539 9540 9541 9542 9543 9544 9545 9546 9547 9548 9549 9550 9551 9552 9553 9554 9555 9556 9557 9558 9559 9560 9561 9562 9563 9564 9565 9566 9567 9568 9569 9570 9571 9572 9573 9574 9575 9576 9577 9578 9579 9580 9581 9582 9583 9584 9585 9586 9587 9588 9589 9590 9591 9592 9593 9594 9595 9596 9597 9598 9599 9600 9601 9602 9603 9604 9605 9606 9607 9608 9609 9610 9611 9612 9613 9614 9615 9616 9617 9618 9619 9620 9621 9622 9623 9624 9625 9626 9627 9628 9629 9630 9631 9632 9633 9634 9635 9636 9637 9638 9639 9640 9641 9642 9643 9644 9645 9646 9647 9648 9649 9650 9651 9652 9653 9654 9655 9656 9657 9658 9659 9660 9661 9662 9663 9664 9665 9666 9667 9668 9669 9670 9671 9672 9673 9674 9675 9676 9677 9678 9679 9680 9681 9682 9683 9684 9685 9686 9687 9688 9689 9690 9691 9692 9693 9694 9695 9696 9697 9698 9699 9700 9701 9702 9703 9704 9705 9706 9707 9708 9709 9710 9711 9712 9713 9714 9715 9716 9717 9718 9719 9720 9721 9722 9723 9724 9725 9726 9727 9728 9729 9730 9731 9732 9733 9734 9735 9736 9737 9738 9739 9740 9741 9742 9743 9744 9745 9746 9747 9748 9749 9750 9751 9752 9753 9754 9755 9756 9757 9758 | # Microsoft Messenger Protocol Implementation
#=======================================================================
::Version::setSubversionId {$Id: protocol.tcl 12387 2012-05-24 19:05:18Z vivia $}
if { $initialize_amsn == 1 } {
global list_BLP list_cmdhnd sb_list contactlist_loaded enable_sip
set contactlist_loaded 0
set enable_sip 0
#To be deprecated and replaced with ::abook thing
set list_BLP -1
#Clear all user infomation
::abook::clearData
set list_cmdhnd [list]
set sb_list [list]
package require base64
package require sha1
if { [version_vcompare [info patchlevel] 8.4.13] >= 0} {
package require snit
} else {
source utils/snit/snit.tcl
}
}
namespace eval ::MSNFT {
namespace export inviteFT acceptFT rejectFT
#TODO: Instead of using a list, use many variables: ft_name, ft_sockid...
# If type is = 1 then it's an MSNP2P file send
proc invitationReceived { filename filesize cookie chatid fromlogin {type "0"}} {
variable filedata
if { $type == 0 } {
set filedata($cookie) [list "$filename" $filesize $chatid $fromlogin "receivewait" "ipaddr"]
after 300000 "::MSNFT::DeleteFT $cookie"
SendMessageFIFO [list ::amsn::fileTransferRecv $filename $filesize $cookie $chatid $fromlogin] "::amsn::messages_stack($chatid)" "::amsn::messages_flushing($chatid)"
#set filetoreceive [list "$filename" $filesize]
} elseif { $type == 1 } {
set filedata($cookie) [list "$filename" $filesize $chatid $fromlogin]
}
}
proc acceptReceived {cookie chatid fromlogin message} {
variable filedata
#status_log "DATA: $cookie $chatid $fromlogin $message $body\n"
if {![info exists filedata($cookie)]} {
return
}
#set requestdata [string range $requestdata 0 [expr {[string length requestdata] -2}]]
set requestdata [$message getField Request-Data]
status_log "Ok, so here we have cookie=$cookie, requestdata=$requestdata\n" red
if { $requestdata != "IP-Address:" } {
status_log "Requested data is not IP-Address!!: $requestdata\n" red
return
}
set ipaddr [$message getField IP-Address]
#If IP field is blank, and we are sender, Send the File and requested IP (SendFile)
if { ($ipaddr == "") && ([getTransferType $cookie]=="send") } {
status_log "Invitation to filetransfer $cookie accepted\n" black
SendMessageFIFO [list ::amsn::acceptedFT $chatid $fromlogin [getFilename $cookie]] "::amsn::messages_stack($chatid)" "::amsn::messages_flushing($chatid)"
set newcookie [::md5::md5 "$cookie$fromlogin"]
set filedata($newcookie) $filedata($cookie)
SendFile $newcookie $cookie
#TODO: Show accept or reject messages from other users? (If transferType=="receive")
} elseif {($ipaddr == "") && ([getTransferType $cookie]!="send")} {
SendMessageFIFO [list ::amsn::acceptedFT $chatid $fromlogin [getFilename $cookie]] "::amsn::messages_stack($chatid)" "::amsn::messages_flushing($chatid)"
#If message comes from sender, and we are receiver, connect
} elseif { ($fromlogin == [lindex $filedata($cookie) 3]) && ([getTransferType $cookie]=="receive")} {
after cancel "::MSNFT::timeoutedFT $cookie"
set port [$message getField Port]
set authcookie [$message getField AuthCookie]
#status_log "Body: $body\n"
ConnectMSNFTP $ipaddr $port $authcookie $cookie
}
}
proc getUsername { cookie } {
variable filedata
if {[info exists filedata($cookie)]} {
return [lindex $filedata($cookie) 3]
}
return ""
}
proc getFilename { cookie } {
variable filedata
if {[info exists filedata($cookie)]} {
return [lindex $filedata($cookie) 0]
}
return ""
}
proc getTransferType { cookie } {
variable filedata
if {[info exists filedata($cookie)]} {
return [lindex $filedata($cookie) 4]
}
return ""
}
proc cancelFT { cookie } {
variable filedata
if {[info exists filedata($cookie)]} {
::amsn::FTProgress ca $cookie [lindex $filedata($cookie) 0]
set sockid [lindex $filedata($cookie) 6]
catch {puts $sockid "CCL\n"}
DeleteFT $cookie
status_log "File transfer manually canceled\n"
}
}
proc timeoutedFT { cookie } {
variable filedata
after cancel "::MSNFT::timeoutedFT $cookie"
if {[info exists filedata($cookie)]} {
::amsn::FTProgress e $cookie [lindex $filedata($cookie) 0]
DeleteFT $cookie
status_log "File transfer timeouted\n"
}
}
proc FinishedFT { cookie } {
variable filedata
set filename [file join [::config::getKey receiveddir] [lindex $filedata($cookie) 0] ]
set finishedname [filenoext $filename]
if { [string range $filename [expr [string length $filename] - 11] [string length $filename]] == ".incomplete" } {
if { [catch { file rename $filename $finishedname } ] } {
::amsn::infoMsg [trans couldnotrename $filename] warning
}
}
DeleteFT $cookie
status_log "File transfer finished ok\n"
}
proc DeleteFT { cookie } {
variable filedata
if {[info exists filedata($cookie)] } {
set sockid [lindex $filedata($cookie) 6]
set fileid [lindex $filedata($cookie) 7]
status_log "Closing FT socket $sockid\n"
catch {fileevent $sockid writable ""}
catch {fileevent $sockid readable ""}
catch {close $sockid}
status_log "Closing FT file $fileid\n"
catch {close $fileid}
unset filedata($cookie)
}
}
#################################
#All about receiving files
#################################
proc acceptFT {chatid cookie} {
#Send the acceptation for a file transfer, request IP
variable filedata
if { ![info exists filedata($cookie)]} {
return -1
}
after cancel "::MSNFT::DeleteFT $cookie"
set filedata($cookie) [lreplace $filedata($cookie) 4 4 "receive"]
set msg "MIME-Version: 1.0\r\nContent-Type: text/x-msmsgsinvite; charset=UTF-8\r\n\r\n"
set msg "${msg}Invitation-Command: ACCEPT\r\n"
set msg "${msg}Invitation-Cookie: $cookie\r\n"
set msg "${msg}Launch-Application: FALSE\r\n"
set msg "${msg}Request-Data: IP-Address:\r\n\r\n"
set msg [encoding convertto utf-8 $msg]
set msg_len [string length $msg]
set sbn [::MSN::SBFor $chatid]
if {$sbn == 0 } {
cancelFT $cookie
return 0
}
set sock [$sbn cget -sock]
::MSN::WriteSBNoNL $sbn "MSG" "U $msg_len\r\n$msg"
after 20000 "::MSNFT::timeoutedFT $cookie"
::amsn::FTProgress a $cookie [lindex $filedata($cookie) 0]
return 1
}
proc rejectFT {chatid cookie} {
set sbn [::MSN::SBFor $chatid]
if {$sbn == 0 } {
cancelFT $cookie
return 0
}
#Send the cancellation for a file transfer
set msg "MIME-Version: 1.0\r\nContent-Type: text/x-msmsgsinvite; charset=UTF-8\r\n\r\n"
set msg "${msg}Invitation-Command: CANCEL\r\n"
set msg "${msg}Invitation-Cookie: $cookie\r\n"
set msg "${msg}Cancel-Code: REJECT\r\n\r\n"
set msg [encoding convertto utf-8 $msg]
set msg_len [string length $msg]
::MSN::WriteSBNoNL $sbn "MSG" "U $msg_len\r\n$msg"
status_log "Rejecting filetransfer sent\n" red
cancelFT $cookie
}
proc ConnectMSNFTP {ipaddr port authcookie cookie} {
#I connect to a remote host to retrieve the file
variable filedata
if {![info exists filedata($cookie)]} {
status_log "ConnectMSNFTP: Ignoring file transfer, filedata($cookie) doesn't exists, cancelled\n" red
return
}
status_log "Connecting to $ipaddr port $port\n"
::amsn::FTProgress c $cookie [lindex $filedata($cookie) 0] $ipaddr $port
if { [catch {set sockid [socket -async $ipaddr $port]} res ]} {
set filename [lindex $filedata($cookie) 0]
cancelFT $cookie
::amsn::FTProgress e $cookie $filename
return
}
lappend filedata($cookie) $sockid
#TODO: What are we cancelling here?
after cancel "::MSNFT::cancelFT $cookie"
fconfigure $sockid -blocking 0 -translation {binary binary} -buffering line
fileevent $sockid writable "::MSNFT::ConnectedMSNFTP $sockid $authcookie $cookie"
}
proc ConnectedMSNFTP {sockid authcookie cookie} {
variable filedata
if {![info exists filedata($cookie)]} {
status_log "ConnectedMSNFTP: Ignoring file transfer, filedata($cookie) doesn't exists, cancelled\n" red
return
}
set error_msg [fconfigure $sockid -error]
if {$error_msg != ""} {
status_log "Can't connect to server: $error_msg!!\n" white
set filename [lindex $filedata($cookie) 0]
cancelFT $cookie
::amsn::FTProgress e $cookie $filename
return
}
fileevent $sockid writable ""
fileevent $sockid readable "::MSNFT::FTNegotiation $sockid $cookie 0 $authcookie"
status_log "Connected, going to give my identity\n"
::amsn::FTProgress i $cookie [lindex $filedata($cookie) 0]
status_log "I SEND: VER MSNFTP\r\n"
catch {puts $sockid "VER MSNFTP\r"}
}
proc FTNegotiation { sockid cookie state {authcookie ""}} {
variable filedata
if {![info exists filedata($cookie)]} {
status_log "ConnectedMSNFTP: Ignoring file transfer, filedata($cookie) doesn't exists, cancelled\n" red
return
}
if { [eof $sockid] } {
status_log "FTNegotiation:: EOF\n" white
set filename [lindex $filedata($cookie) 0]
cancelFT $cookie
::amsn::FTProgress l $cookie $filename
return
}
gets $sockid tmpdata
status_log "FTNegotiation: I RECEIVE: $tmpdata\n"
if { $tmpdata == "" } {
update idletasks
return
}
switch -- $state {
0 {
if {[string range $tmpdata 0 9] == "VER MSNFTP"} {
catch {fileevent $sockid readable "::MSNFT::FTNegotiation $sockid $cookie 1"}
catch {puts $sockid "USR [::config::getKey login] $authcookie\r"}
status_log "FTNegotiation: I SEND: USR [::config::getKey login] $authcookie\r\n"
} else {
status_log "FT failed in state 0\n" red
set filename [lindex $filedata($cookie) 0]
cancelFT $cookie
::amsn::FTProgress l $cookie $filename
}
}
1 {
if {[string range $tmpdata 0 2] == "FIL"} {
set filesize [string range $tmpdata 4 [expr {[string length $tmpdata]-2}]]
if { "$filesize" != "[lindex $filedata($cookie) 1]" } {
status_log "Filesize is now $filesize and was [lindex $filedata($cookie) 1] before!!\n" white
}
status_log "FTNegotiation: They send me file with size $filesize\n"
catch {puts $sockid "TFR\r"}
status_log "Receiving file...\n"
set filename [file join [::config::getKey receiveddir] [lindex $filedata($cookie) 0]]
set origfile $filename
set num 1
while { [file exists $filename] } {
set filename "[filenoext $origfile] $num[fileext $origfile]"
incr num
}
if {[catch {open $filename w} fileid]} {
# Cannot create this file. Abort.
status_log "Could not saved the file '$filename' (write-protected target directory?)\n" red
cancelFT $cookie
::amsn::FTProgress l $cookie $filename
::amsn::infoMsg [trans readonlymsgbox] warning
return
}
lappend filedata($cookie) $fileid
fconfigure $fileid -blocking 1 -buffering none -translation {binary binary}
#Receive the file
fconfigure $sockid -blocking 0 -translation {binary binary} -buffering full -buffersize 16384
catch {fileevent $sockid readable "::MSNFT::ReceivePacket $sockid $fileid $filesize $cookie"}
} else {
status_log "FT failed in state 1\n" red
set filename [lindex $filedata($cookie) 0]
cancelFT $cookie
::amsn::FTProgress l $cookie $filename
}
}
default {
status_log "FTNegotiation: Unknown state!!!\n" white
cancelFT $cookie
}
}
}
proc ReceivePacket { sockid fileid filesize cookie} {
#Get a packet from the file transfer
variable filedata
if {![info exists filedata($cookie)]} {
status_log "ConnectedMSNFTP: Ignoring file transfer, filedata($cookie) doesn't exists, cancelled\n" red
return
}
if { [eof $sockid] } {
status_log "ReveivePacket EOF\n" white
set filename [lindex $filedata($cookie) 0]
cancelFT $cookie
::amsn::FTProgress l $cookie $filename
return
}
fileevent $sockid readable ""
set recvbytes [tell $fileid]
set packetrest [expr {2045 - ($recvbytes % 2045)}]
if {$packetrest == 2045} {
#Need a full packet, header included
::amsn::FTProgress r $cookie [lindex $filedata($cookie) 0] $recvbytes $filesize
update idletasks
fconfigure $sockid -blocking 1
set header [read $sockid 3]
set packet1 1
binary scan $header ccc packet1 packet2 packet3
#If packet1 is 1 -- Transfer canceled by the other
if { ($packet1 != 0) } {
status_log "File transfer cancelled by remote with packet1=$packet1\n"
cancelFT $cookie
return
}
#If you want to cancel, send "CCL\n"
set packet2 [expr {($packet2 + 0x100) % 0x100}]
set packet3 [expr {($packet3 + 0x100) % 0x100}]
set packetsize [expr {$packet2 + ($packet3<<8)}]
set firstbyte [read $sockid 1]
catch {puts -nonewline $fileid $firstbyte}
fconfigure $sockid -blocking 0
set recvbytes [tell $fileid]
#::amsn::fileTransferProgress r $cookie $recvbytes $filesize
} else {
#A full packet didn't come the previous reading, read the rest
set thedata [read $sockid $packetrest]
catch {puts -nonewline $fileid $thedata}
set recvbytes [tell $fileid]
}
if { $recvbytes >= $filesize} {
#::amsn::fileTransferProgress r $cookie $recvbytes $filesize
catch {puts $sockid "BYE 16777989\r"}
status_log "File received\n"
::amsn::FTProgress fr $cookie [lindex $filedata($cookie) 0] $recvbytes $filesize
FinishedFT $cookie
} else {
fileevent $sockid readable "::MSNFT::ReceivePacket $sockid $fileid $filesize $cookie"
}
}
###################################
#All about sending files
###################################
proc supportsNewFT { clientid } {
# If a user chats with you while being as "Appear offline", his client ID will be empty, and we don't want a crash in that case.
# We assume the user supports new FT because only WLM 8.1+ allows you to chat while being as appear offline.
if { $clientid == [list] } {
status_log "supportsNewFT: Empty clientid for FT (user invisible/offline?)" white
return 1
}
if { [::MSN::hasCapability $clientid p2paware]} {
return 1
}
return 0
}
proc sendFTInvitation { chatid filename filesize ipaddr cookie} {
#Invitation to filetransfer, initial message
variable filedata
if {[supportsNewFT [::abook::getContactData $chatid clientid]]} {
#set sid [::MSN6FT::SendFT $chatid $filename $filesize]
#setObjOption $cookie msn6ftsid $sid
#setObjOption $sid theCookie $cookie
$::ft_handler request $chatid $filename $filesize "" "" $cookie
return 0
}
set sbn [::MSN::SBFor $chatid]
if {$sbn == 0 } {
return 0
}
status_log "sentFTInvitation: filename (not converted to utf-8) is [file tail $filename]\n" blue
status_log "sentFTInvitation: filename (converted to utf-8) is [encoding convertto utf-8 [file tail $filename]]\n" blue
set msg "MIME-Version: 1.0\r\nContent-Type: text/x-msmsgsinvite; charset=UTF-8\r\n\r\n"
set msg "${msg}Application-Name: File Transfer\r\n"
set msg "${msg}Application-GUID: {5D3E02AB-6190-11d3-BBBB-00C04F795683}\r\n"
set msg "${msg}Invitation-Command: INVITE\r\n"
set msg "${msg}Invitation-Cookie: $cookie\r\n"
set msg "${msg}Application-File: [file tail $filename]\r\n"
set msg "${msg}Application-FileSize: $filesize\r\n\r\n"
set msg [encoding convertto utf-8 $msg]
set msg_len [string length $msg]
::MSN::WriteSBNoNL $sbn "MSG" "U $msg_len\r\n$msg"
status_log "sentFTInvitation: Invitation to $filename sent: $msg\n" red
#Change to allow multiple filetransfer
#set filedata($cookie) [list $sbn "$filename" $filesize $cookie $ipaddr]
set filedata($cookie) [list "$filename" $filesize $chatid [::MSN::usersInChat $chatid] "send" $ipaddr]
after 300000 "::MSNFT::DeleteFT $cookie"
}
proc cancelFTInvitation { chatid cookie } {
set sid [getObjOption $cookie msn6ftsid]
if { $sid != "" } {
::MSN6FT::CancelFT $chatid $sid
DeleteFT $cookie
} else {
rejectFT $chatid $cookie
}
}
proc rejectedFT {chatid who cookie} {
variable filedata
if {![info exists filedata($cookie)]} {
return
}
SendMessageFIFO [list ::amsn::rejectedFT $chatid $who [getFilename $cookie] ] "::amsn::messages_stack($chatid)" "::amsn::messages_flushing($chatid)"
}
proc SendFile { cookie oldcookie} {
#File transfer accepted by remote, send final ACK
variable filedata
status_log "Here in sendfile\n" red
if {![info exists filedata($cookie)]} {
return
}
status_log "File transfer ok, begin\n"
set sbn [::MSN::SBFor [lindex $filedata($cookie) 2]]
if { $sbn == 0 } {
cancelFT $cookie
return
}
#Invitation accepted, send IP and Port to connect to
#option: possibility to enter IP address (firewalled connections)
set ipaddr [lindex $filedata($cookie) 5]
#if error ::AMSN::Error ...
if {![string is digit [::config::getKey initialftport]] || [string length [::config::getKey initialftport]] == 0} {
::config::setKey initialftport 6891
}
set port [::config::getKey initialftport]
#Random authcookie
set authcookie [expr {[clock clicks] % (65536 * 4)}]
while {[catch {set sockid [socket -server "::MSNFT::AcceptConnection $cookie $authcookie" $port]} res]} {
incr port
}
::abook::OpenUPnPPort $port
#TODO: More than one transfer? Don't create one listening socket for every person, just one for all,
# but that makes the authcookie thing difficult...
lappend filedata($oldcookie) $sockid
after 300000 "catch {close $sockid}; ::abook::CloseUPnPPort $port"
set msg "MIME-Version: 1.0\r\nContent-Type: text/x-msmsgsinvite; charset=UTF-8\r\n\r\n"
set msg "${msg}Invitation-Command: ACCEPT\r\n"
set msg "${msg}Invitation-Cookie: $oldcookie\r\n"
set msg "${msg}IP-Address: $ipaddr\r\n"
set msg "${msg}Port: $port\r\n"
set msg "${msg}AuthCookie: $authcookie\r\n"
set msg "${msg}Launch-Application: FALSE\r\n"
set msg "${msg}Request-Data: IP-Address:\r\n\r\n"
set msg [encoding convertto utf-8 $msg]
set msg_len [string length $msg]
::MSN::WriteSBNoNL $sbn "MSG" "U $msg_len\r\n$msg"
::amsn::FTProgress w $cookie [lindex $filedata($cookie) 0] $port
status_log "Listening on port $port for incoming connections...\n" red
}
proc AcceptConnection {cookie authcookie sockid hostaddr hostport} {
variable filedata
if {![info exists filedata($cookie)]} {
status_log "AcceptConnection: Ignoring file transfer, filedata($cookie) doesn't exists, cancelled\n" red
return
}
lappend filedata($cookie) $sockid
status_log "::MSNFT::AcceptConnection have connection from $hostaddr : $hostport\n" white
fconfigure $sockid -blocking 0 -buffering none -translation {binary binary}
fileevent $sockid readable "::MSNFT::FTSendNegotiation $sockid $cookie 0 $authcookie"
::amsn::FTProgress i $cookie [lindex $filedata($cookie) 0]
}
proc FTSendNegotiation { sockid cookie state {authcookie ""}} {
variable filedata
if {![info exists filedata($cookie)]} {
status_log "ConnectedMSNFTP: Ignoring file transfer, filedata($cookie) doesn't exists, cancelled\n" red
return
}
if { [eof $sockid] } {
status_log "FTSendNegotiation:: EOF\n" white
set filename [lindex $filedata($cookie) 0]
cancelFT $cookie
::amsn::FTProgress l $cookie $filename
return
}
gets $sockid tmpdata
status_log "FTNegotiation: I RECEIVE: $tmpdata\n"
if { $tmpdata == "" } {
update idletasks
return
}
switch -- $state {
0 {
if { [regexp "^VER\ ?\[0-9\]* MSNFTP" $tmpdata] } {
catch {fileevent $sockid readable "::MSNFT::FTSendNegotiation $sockid $cookie 1 $authcookie"}
catch {puts $sockid "VER MSNFTP\r"}
status_log "FTSendNegotiation: I SEND: VER MSNFTP\r\n"
} else {
status_log "FT failed in state 0\n" red
cancelFT $cookie
}
}
1 {
if {[string range $tmpdata 0 2] == "USR"} {
set filename [lindex $filedata($cookie) 0]
set filesize [lindex $filedata($cookie) 1]
catch {fileevent $sockid readable "::MSNFT::FTSendNegotiation $sockid $cookie 2"}
catch {puts $sockid "FIL $filesize\r"}
status_log "SENT: FIL $filesize\n"
} else {
status_log "FT failed in state 1\n" red
cancelFT $cookie
}
}
2 {
if {[string range $tmpdata 0 2] == "TFR"} {
set filename [lindex $filedata($cookie) 0]
set filesize [lindex $filedata($cookie) 1]
#Send the file
#TODO, what if not exists?
if {[catch {set fileid [open $filename r]} res]} {
return 0;
}
lappend filedata($cookie) $fileid
fconfigure $fileid -translation {binary binary} -blocking 1
status_log "Sending file $filename size $filesize\n"
fconfigure $sockid -blocking 0 -buffering full -buffersize 16384
fileevent $sockid writable "::MSNFT::SendPacket $sockid $fileid $filesize $cookie"
fileevent $sockid readable "::MSNFT::MonitorTransfer $sockid $cookie"
} else {
status_log "FT failed in state 2\n" red
cancelFT $cookie
}
}
default {
status_log "FTNegotiation: Unknown state!!!\n" white
cancelFT $cookie
}
}
}
proc SendPacket { sockid fileid filesize cookie } {
variable filedata
if {![info exists filedata($cookie)]} {
status_log "ConnectedMSNFTP: Ignoring file transfer, filedata($cookie) doesn't exists, cancelled\n" red
return
}
#Send a packet for the file transfer
fileevent $sockid writable ""
set sentbytes [tell $fileid]
set packetsize [expr {$filesize-$sentbytes}]
if {$packetsize > 2045} {
set packetsize 2045
}
if {$packetsize>0} {
set data [read $fileid $packetsize]
set byte1 [expr {$packetsize & 0xFF}]
set byte2 [expr {$packetsize >> 8}]
catch {puts -nonewline $sockid "\0[format %c $byte1][format %c $byte2]$data" ; flush $sockid }
set sentbytes [expr {$sentbytes + $packetsize}]
::amsn::FTProgress s $cookie [lindex $filedata($cookie) 0] $sentbytes $filesize
fileevent $sockid writable "::MSNFT::SendPacket $sockid $fileid $filesize $cookie"
}
}
proc MonitorTransfer { sockid cookie} {
#puts "Monitortransfer"
variable filedata
if {![info exists filedata($cookie)]} {
status_log "::MSNFT::MonitorTransfer: Ignoring file transfer, filedata($cookie) doesn't exists, cancelled\n" red
return
}
if { [eof $sockid] } {
status_log "MonitorTransfer EOF\n" white
cancelFT $cookie
return
}
fileevent $sockid readable ""
#Monitor messages from the receiving host in a file transfer
catch {fconfigure $sockid -blocking 1}
if {[catch {gets $sockid datos} res]} {
status_log "::MSNFT::MonitorTransfer: Transfer failed: $res\n"
cancelFT $cookie
return
}
status_log "Got from remote side: $datos\n"
if {[string range $datos 0 2] == "CCL"} {
status_log "::MSNFT::MonitorTransfer: Connection cancelled\n"
cancelFT $cookie
return
}
if {[string range $datos 0 2] == "BYE"} {
status_log "::MSNFT::MonitorTransfer: Connection finished\n"
::amsn::FTProgress fs $cookie [lindex $filedata($cookie) 0]
FinishedFT $cookie
return
}
cancelFT $cookie
}
}
namespace eval ::MSN {
#TODO: Export missing procedures (the one whose starts with lowercase)
namespace export changeName logout changeStatus connect blockUser \
unblockUser addUser removeUserFromGroup deleteUser login myStatusIs \
cancelReceiving cancelSending moveUser
if { $initialize_amsn == 1 } {
#Forward list
variable list_FL [list]
#Reverse List
variable list_RL [list]
#Accept List
variable list_AL [list]
#Block list
variable list_BL [list]
#Pending list (MSNP11)
variable list_PL [list]
#Email (Non-IM) list (MSNP15)
variable list_EL [list]
variable list_users ""
variable myStatus FLN
#Double array containing:
# CODE NAME COLOR ONLINE/OFFLINE SMALLIMAGE BIGIMAGE
variable list_states {
{NLN online #0000A0 online online bonline}
{IDL noactivity #008000 online away baway}
{BRB rightback #008080 online away baway}
{PHN onphone #008080 online busy bbusy}
{BSY busy #800000 online busy bbusy}
{AWY away #008000 online away baway}
{LUN gonelunch #008000 online away baway}
{HDN appearoff #404040 offline offline boffline}
{FLN offline #404040 offline offline boffline}
}
}
proc reconnect { error_msg } {
global reconnect_timer reconnect_timer_remaining
if {![info exists reconnect_timer] || $reconnect_timer < 5000} {
set reconnect_timer 5000
} else {
set reconnect_timer [expr {$reconnect_timer * 2}]
}
if {$reconnect_timer > 900000 } {
set reconnect_timer 900000
}
set reconnect_timer_remaining $reconnect_timer
cmsn_draw_reconnect $error_msg
after $reconnect_timer ::MSN::connect
}
proc saveOldStatus { {status "" } {amessage ""} } {
global oldstatus
global automessage
if {$status != "" } {
set oldstatus $status
} else {
set oldstatus [::MSN::myStatusIs]
}
if { $amessage == "" } {
if { [info exists automessage] } {
set automsg $automessage
} else {
set automsg -1
}
} else {
set automsg $amessage
}
if {$automsg != -1 } {
for {set idx 0} {$idx < [StateList size] } { incr idx } {
if { [StateList get $idx] == $automsg} {
set oldstatus $idx
}
}
}
}
proc cancelReconnect { } {
global reconnect_timer
set reconnect_timer 0
after cancel ::MSN::connect
after cancel cmsn_update_reconnect_timer
catch { unset ::oldstatus }
::MSN::logout
cmsn_draw_offline
}
proc connect { {passwd ""}} {
#Cancel any pending reconnect
after cancel ::MSN::connect
after cancel cmsn_update_reconnect_timer
if { [ns cget -stat] != "d" } {
return
}
set username [::config::getKey login]
if { $passwd == "" } {
global password
set passwd [set password]
}
if {$passwd == "" } {
return
}
if {[::config::getKey protocol] != 15 &&
[::config::getKey protocoloverride] != 1} {
::config::setKey protocol 15
}
::config::setKey clientid 0
::MSN::setClientCap msnc8
::MSN::setClientCap inkgif
::MSN::setClientCap multip
::MSN::setClientCap voice
if { [::config::getKey protocol] > 15 } {
::MSN::setClientCap p2pv2
}
if {[::config::getKey protocol] >= 15} {
global sso
if {[info exists sso] && $sso != "" } {
$sso destroy
set sso ""
}
}
::config::setKey start_ns_server [::config::getKey default_ns_server]
ns configure -stat "d" -sock "" \
-server [split [::config::getKey start_ns_server] ":"]
#Setup the conection
setup_connection ns
#@@@@@@@@@@@
if { ![info exists ::ses_mgr] } {
set ::ses_mgr [::p2p::P2PSessionManager %AUTO%]
set ::obj_stor [::p2p::MSNObjectStore %AUTO% -client $::ses_mgr]
$::ses_mgr register_handler $::obj_stor
set ::trsp_mgr [$::ses_mgr transport_manager]
set ::ft_handler [::p2p::FileTransferHandler %AUTO% -client $::ses_mgr]
$::ses_mgr register_handler $::ft_handler
set ::cam_handler [::p2p::WebcamHandler %AUTO% -client $::ses_mgr]
$::ses_mgr register_handler $::cam_handler
}
::plugins::PostEvent OnConnecting evPar
global tlsinstalled
#Check if we need to install the TLS module
if { $tlsinstalled == 0 && [checking_package_tls] == 0} {
::autoupdate::installTLS
return -1
}
#Call the pre authentication
set proxy [ns cget -proxy]
if { [::config::getKey protocol] < 13 } {
if { [$proxy authInit] < 0 } {
return -1
}
}
# Test if farsight is available to set the sip clientcap
# do it on every connect in case you changed protocol
# version used, or change profile, etc...
# Do it only if necessary (protocol >= 13)
global enable_sip
if {[::config::getKey protocol] >= 18} {
set enable_sip 1
status_log "SIP capabilities are enabled"
} else {
set enable_sip 0
status_log "SIP capabilities are disabled"
}
if { [::config::getKey protocol] >= 13 && $enable_sip} {
after 0 [list ::MSNSIP::TestFarsight]
} else {
if { [::config::getKey wanttosharecam] && \
[::CAMGUI::camPresent] == 1 } {
::MSN::setClientCap webcam
} else {
::MSN::setClientCap webcam 0
}
}
# Because of asyncresolver, the 'connect' could block but keep the UI updated,
# so we need to put the login screen into 'loggingIn' mode before...
::Event::fireEvent loggingIn protocol
cmsn_ns_connect $username $passwd
}
proc logoutEP { ep } {
set msg "goawyplzthxbye"
::MSN::WriteSBNoNL ns "UUN" "[::config::getKey login];$ep 4 [string length $msg]\r\n$msg"
}
proc logoutGtfo {} {
set msg "gtfo"
foreach ep [::abook::getEndPoints] {
if {![string equal -nocase $ep [::config::getGlobalKey machineguid]] } {
::MSN::WriteSBNoNL ns "UUN" "[::config::getKey login];$ep 4 [string length $msg]\r\n$msg"
}
}
logout
}
proc logout {} {
after cancel cmsn_update_reconnect_timer
::abook::lastSeen
::log::eventlogout
ns configure -stat "d"
::MSN::WriteSBRaw ns "OUT\r\n";
set proxy [ns cget -proxy]
$proxy finish ns
CloseSB ns
global automessage
ns configure -server [split [::config::getKey start_ns_server] ":"]
setMyStatus FLN
status_log "Loging out\n"
if {[::config::getKey enablebanner] && [::config::getKey adverts]} {
adv_pause
}
::groups::Disable
StopPolling
::abook::saveToDisk
global list_BLP emailBList
::MSN::clearList AL
::MSN::clearList BL
::MSN::clearList FL
::MSN::clearList RL
::MSN::clearList EL
set list_BLP -1
if { [info exists emailBList] } {
unset emailBList
}
::abook::unsetConsistent
#Try to update Preferences
catch {InitPref 1}
set automessage "-1"
::plugins::PostEvent OnDisconnect evPar
#an event to let the GUI know we are actually logged out now
::Event::fireEvent loggedOut protocol
set ::contactlist_loaded 0
#Set all CW users as offline
foreach user_name [::abook::getAllContacts] {
::abook::setVolatileData $user_name state "FLN"
}
::abook::clearEndPoints
foreach chat_id [::ChatWindow::getAllChatIds] {
::ChatWindow::TopUpdate $chat_id
}
#Alert dock of status change
send_dock "STATUS" "FLN"
# Remove mail icon once offline.
send_dock "MAIL" 0
}
#Callback procedure called when a UUX (PSM change) message is received
proc GotUUXResponse { recv } {
cmsn_draw_online 1 1
#an event used by guicontactlist to know when we changed our nick
::Event::fireEvent myNickChange protocol
}
#Callback procedure called when a ADC message is received
proc GotADCResponse { recv } {
set username ""
set nickname ""
set contactguid ""
set curr_list ""
set groups "0"
#We skip ADC TrID
foreach information [lrange $recv 2 end] {
set key [string toupper [string range $information 0 1]]
if { $key == "N=" } {
set username [string range $information 2 end]
} elseif { $key == "F=" } {
set nickname [urldecode [string range $information 2 end]]
} elseif { $key == "C=" } {
set contactguid [string range $information 2 end]
} elseif { $curr_list == "" } {
#We didn't get the list names yet
set curr_list $information
} elseif { $groups == "0" } {
#We didn't get the group list yet
set groups $information
}
}
#if { $curr_list == "RL" && [lsearch [::abook::getLists $username] "PL"] == -1 && [lsearch [::abook::getLists $username] "AL"] == -1 && [lsearch [::abook::getLists $username] "BL"] == -1 } {
# newcontact $username $nickname
#} else
if { $curr_list == "RL" && [lsearch [::abook::getLists $username] "PL"] != -1 && ( [lsearch [::abook::getLists $username] "AL"] != -1 || [lsearch [::abook::getLists $username] "BL"] != -1 ) } {
#Contact already in Allow List or Block List, so the notification window is useless, just silently remove from the PL:
::MSN::WriteSB ns "REM" "PL $username"
}
if { $curr_list == "FL" } {
status_log "Addition to FL"
if { $username == "" } {
#The server doesn't give the username so it gives the GUID
set username [::abook::getContactForGuid $contactguid]
} else {
#It's a new contact so we save its guid and its nick
::abook::setContactData $username contactguid $contactguid
::abook::setContactForGuid $contactguid $username
if {[::abook::getContactData $username nick ""] == ""} {
::abook::setContactData $username nick $nickname
}
}
status_log "$username was in groups [::abook::getGroups $username]"
if {[::abook::getGroups $username] != "" && $groups == 0} {
status_log "do nothing since a contact can't be in no group AND in a group"
} else {
::abook::addContactToGroup $username $groups
}
status_log "$username is in groups [::abook::getGroups $username]"
}
::abook::addContactToList $username $curr_list
::MSN::addToList $curr_list $username
::MSN::contactListChanged
set contactlist_loaded 1
::abook::setConsistent
::abook::saveToDisk
if { $curr_list != "FL" } {
#there isn't any group for other lists than FL
set groups ""
}
if { $curr_list == "FL" || $curr_list == "RL" } {
#Don't send the event for an addition to any other list
::Event::fireEvent contactAdded protocol $username $groups
}
}
proc GotREMResponse { recv } {
set list_sort [string toupper [lindex $recv 2]]
if { [lindex $recv 2] == "FL" } {
set userguid [lindex $recv 3]
set user [::abook::getContactForGuid $userguid]
if { [lindex $recv 4] == "" } {
#Remove from all groups!!
set affected_groups [::abook::getGroups $user]
::abook::emptyUserGroups $user
status_log "GotREMResponse: Contact $user isn't in any group, removing!!\n" blue
::MSN::deleteFromList FL $user
::abook::removeContactFromList $user FL
#The GUID is invalid if the contact is removed from the FL list
::abook::setContactForGuid $userguid ""
::abook::setContactData $user contactguid ""
::abook::clearVolatileData $user
} else {
#Remove fromonly one group
set affected_groups [list [lindex $recv 4]]
::abook::removeContactFromGroup $user [lindex $recv 4]
}
if { [::abook::getGroups $user] == [list 0] } {
#User is now on nogroup
::Event::fireEvent contactMoved protocol $user [linsert $affected_groups end 0]
::Event::fireEvent contactAdded protocol $user 0
} else {
#an event to let the GUI know a user is removed from a group / the list
::Event::fireEvent contactRemoved protocol $user $affected_groups
}
} else {
set user [lindex $recv 3]
::MSN::deleteFromList $list_sort $user
::abook::removeContactFromList $user $list_sort
#an event to let the GUI know a user is removed from a list
::Event::fireEvent contactListChange protocol $user
}
global contactlist_loaded
set contactlist_loaded 1
}
#Change a users nickname
proc changeName { newname {update 1}} {
#if email is not yet verified simply ignore the call
if {[::config::getKey emailVerified 1] == 0} {
return
}
set name [urlencode $newname]
::MSN::WriteSB ns "PRP" "MFN $name" [list ns handlePRPResponse "$name" $update]
}
#Change a users personal message
proc changePSM { newpsm {state ""} {update 1} {force 0} } {
#TODO: encode XML etc
if { $force || [::abook::getPersonal PSM] != $newpsm } {
::abook::setPersonal PSM $newpsm
if {$update && [info exists ::roaming] &&
[::config::getKey protocol] >= 15 } {
$::roaming UpdateProfile [list ns updateProfileCB] \
[::abook::getPersonal MFN] [::abook::getPersonal PSM]
}
# We catch because we might have a plugin changing
# the psm when we are offline and we don't want a bugreport
# if amsn hasn't finished loading
# We also can't check if the state is != "FLN" since we need to send
# the UUX data before the initial CHG
if {[::MSN::myStatusIs] != "FLN" } {
catch {sendUUXData $state}
}
save_config
::abook::saveToDisk
}
}
#changes the current media in the personal message
#type: can be one of: Music, Games or Office
#enabled: 0 or 1
#format: A formatter string ala .Net; For example: {0} - {1}
#args: list with the other things, first will match {0} in format
proc changeCurrentMedia { type enabled format args } {
if {$enabled == 1} {
set currentMedia "aMSN\\0$type\\01\\0$format\\0[join $args \\0]\\0"
} else {
set currentMedia ""
}
# Check if an update is necessary.
if { [::abook::getVolatileData myself currentMedia] != ${currentMedia} } {
::abook::setVolatileData myself currentMedia $currentMedia
if {[::MSN::myStatusIs] != "FLN" } {
catch {sendUUXData}
}
}
}
#Change a users personal message
proc changeEndPointName { newname } {
::config::setKey epname $newname
sendUUXData
save_config
::abook::saveToDisk
}
proc sendUUXData { {state ""} } {
# Send Endpoint data
if {[::config::getKey protocol] >= 18 } {
global idletime
if {$idletime >= [expr {[::config::getKey idletime] * 60}]} {
set idle "true"
} else {
set idle "false"
}
if {$state == "" } {
set state [::MSN::myStatusIs]
}
set epname [::config::getKey epname aMSN]
set epname [::sxml::xmlreplace $epname]
set epname [encoding convertto utf-8 $epname]
# ClientType info :
# 1 : Computer
# 2 : Website
# 3 : Mobile Device
# 4 : Xbox
# none, 0 or >= 5 : Other Device
set clienttype 1
if {[OnMaemo] } {
set clienttype 3
}
set endpoint "<EndpointData><Capabilities>[::config::getKey clientid]</Capabilities></EndpointData>"
set privateep "<PrivateEndpointData><EpName>$epname</EpName><Idle>$idle</Idle><State>$state</State><ClientType>$clienttype</ClientType></PrivateEndpointData>"
::MSN::WriteSBNoNL ns "UUX" "[string length $endpoint]\r\n$endpoint"
::MSN::WriteSBNoNL ns "UUX" "[string length $privateep]\r\n$privateep"
}
set psm [::abook::getPersonal PSM]
set psm [::sxml::xmlreplace $psm]
set psm [encoding convertto utf-8 $psm]
set currentMedia [::abook::getVolatileData myself currentMedia]
set currentMedia [::sxml::xmlreplace $currentMedia]
set currentMedia [encoding convertto utf-8 $currentMedia]
set machineguid [::config::getGlobalKey machineguid]
set machineguid [::sxml::xmlreplace $machineguid]
set data "<Data><PSM>$psm</PSM><CurrentMedia>$currentMedia</CurrentMedia><MachineGuid>$machineguid</MachineGuid>"
if {[::config::getKey protocol] >= 18} {
set signatureSound [::abook::getPersonal signatureSound]
set signatureSound [::sxml::xmlreplace $signatureSound]
set signatureSound [encoding convertto utf-8 $signatureSound]
append data "<SignatureSound>$signatureSound</SignatureSound>"
}
append data "</Data>"
::MSN::WriteSBNoNL ns "UUX" "[string length $data]\r\n$data"
}
proc updateDP { {step 0} } {
if {[::config::getKey protocol] >= 15 &&
[::config::getKey contentroaming 1] == 1} {
set dp [::config::getKey displaypic ""]
if {$dp == "" || $dp == "nopic.gif"} {
set dp ""
} else {
set dp [::skin::GetSkinFile displaypic [PathRelToAbs $dp]]
}
if {$step == 0} {
$::roaming GetProfile [list ns RoamingGetProfileCB [list ::MSN::updateDP 1]]
} else {
set dp_resourceid [::abook::getPersonal dp_resourceid]
set profile_resourceid [::abook::getPersonal profile_resourceid]
if {$dp_resourceid != ""} {
#delete old DP
if {$step == 1} {
$::roaming DeleteRelationships [list ns RoamingDeleteRelationshipsCB 2] $dp_resourceid
} elseif {$step == 2} {
$::roaming DeleteRelationships [list ns RoamingDeleteRelationshipsCB 3] $dp_resourceid $profile_resourceid
} elseif {$step == 4} {
#TODO: maybe we need to create a new relationship, WLM does, but it seems to work fine without that
#update last fetched resource id because we don't want to download the DP immediately after uploading it
::abook::setPersonal dp_last_resourceid $dp_resourceid
} else {
::abook::setPersonal dp_resourceid ""
set dp_resourceid ""
}
}
if {$dp_resourceid == ""} {
if {$dp != ""} {
#upload new DP
#TODO: error handling
set fd [open $dp r]
fconfigure $fd -translation binary
set content [read $fd]
close $fd
set dpfilename [filenoext [getfilename $dp]]
if {[string length $dpfilename] > 8 && [string range $dpfilename 0 7] == "roaming-"} {
set dpfilename [string range $dpfilename 8 end]
}
status_log "updateDP : uploading dp $dpfilename" blue
$::roaming CreateDocument [list ns RoamingCreateDocumentCB 4] $dpfilename [base64::encode $content]
}
}
}
}
}
proc downloadDP { {step 0} {token ""} } {
global HOME
if {[::config::getKey protocol] >= 15 &&
[::config::getKey contentroaming 1] == 1} {
if {$step == 0} {
status_log "downloadDP : fetching newest version of profile (GetProfile)" blue
$::roaming GetProfile [list ns RoamingGetProfileCB [list ::MSN::downloadDP 1]]
} else {
set dpfile [string tolower [::abook::getPersonal dp_filename]]
set dprid [::abook::getPersonal dp_resourceid]
set dpmimetype [::abook::getPersonal dp_mimetype]
set dplastrid [::abook::getPersonal dp_last_resourceid]
set dpurl [::abook::getPersonal dp_url]
set dpfile "$dpfile.png"
status_log "downloadDP : comparing $dprid with $dplastrid" blue
if {$dprid != $dplastrid} {
if {$dprid != ""} {
if {$step == 1} {
#download DP
if {[string range $dpurl 0 6] == "http://"} {
set dpfullurl $dpurl
} else {
set dpfullurl "http://byfiles.storage.msn.com"
append dpfullurl $dpurl
}
status_log "downloadDP : downloading $dpfile from $dpfullurl" blue
if {[ catch {set tok [::http::geturl $dpfullurl -command "::MSN::downloadDP 3"]} res ]} {
status_log "downloadDP : downloading failed" red
catch {::http::cleanup $tok}
}
} else {
if { [::http::status $token] == "ok" && [::http::ncode $token] >= 200 && [::http::ncode $token] < 300 || [::http::ncode $token] == 500} {
status_log "downloadDP : saving DP to file" blue
set dpfile "roaming-$dpfile"
set filename [file join $HOME displaypic $dpfile]
set filename2 "$filename.dat"
if {[file exists $filename]} {
#delete if file already exists
if {[catch {file delete $filename} res]} {
return
}
}
if {[file exists $filename2]} {
#delete if file already exists
if {[catch {file delete $filename2} res]} {
return
}
}
#TODO: error handling
set fd [open $filename w]
fconfigure $fd -translation binary
puts -nonewline $fd [::http::data $token]
flush $fd
close $fd
set fd [open $filename2 w]
puts $fd "[clock seconds]\n$dpfile"
close $fd
::http::cleanup $token
status_log "downloadDP : saving done, now setting new DP" blue
#update last roaming file
::abook::setPersonal dp_last_resourceid $dprid
#set new DP
::config::setKey displaypic $filename
load_my_pic
::MSN::changeStatus [::MSN::myStatusIs]
save_config
status_log "downloadDP : setting new DP done" blue
} else {
status_log "downloadDP : failed with status [::http::status $token] and code [::http::ncode $token]" blue
}
}
} else {
#update last roaming file
::abook::setPersonal dp_last_resourceid ""
#remove DP
status_log "downloadDP : removing DP" blue
clear_disp
}
}
}
}
}
#Procedure called to change our status
proc changeStatus {new_status} {
global autostatuschange chg_last_dp
if { $new_status == "FLN" } {
return
}
if {[::config::getKey displaypic] == "" } {
::config::setKey displaypic nopic.gif
}
set chg_last_dp [::config::getKey displaypic]
set filen [::skin::GetSkinFile displaypic [PathRelToAbs [::config::getKey displaypic]]]
set fd [open $filen r]
fconfigure $fd -translation {binary binary}
set data [read $fd]
close $fd
set msnobj [create_msnobj [::config::getKey login] 3 $filen]
set p2pmsnobj [::p2p::MSNObject parse $msnobj]
$p2pmsnobj configure -data $data
$::obj_stor publish $p2pmsnobj
if {[::MSN::myStatusIs] == "FLN" || [::MSN::myStatusIs] == "HDN" || [::config::getKey protocol] >= 18 } {
::MSN::sendUUXData $new_status
}
if { [::config::getKey displaypic] != "nopic.gif" } {
::MSN::WriteSB ns "CHG" "$new_status [::config::getKey clientid] [urlencode $msnobj]"
} else {
::MSN::WriteSB ns "CHG" "$new_status [::config::getKey clientid]"
}
#Reset automatic status change to 0
set autostatuschange 0
}
# set a capability of the client
# possiblities for cap are:
# mobile Mobile Device
# inkgif receive Ink as gif
# inkisf receive Ink as ISF
# webcam Webcam
# multip Multi-Packeting
# paging Paging
# drctpg Direct-Paging
# webmsn WebMessenger
# tgw Connected via TGW
# space User has an MSN Spaces
# mce Connected using Win XP Media Center Edition
# direct DirectIM
# winks Winks
# search Client supports Shared search
# bot Is Bot
# voice Client supports Voice Clips
# secure Client supports secure channel chatting
# sip Client supports SIP based communiation
# shared Client supports Shared Folders
# msnc1 This is the value for MSNC1 (MSN Msgr 6.0)
# msnc2 This is the value for MSNC2 (MSN Msgr 6.1)
# msnc3 This is the value for MSNC3 (MSN Msgr 6.2)
# msnc4 This is the value for MSNC4 (MSN Msgr 7.0)
# msnc5 This is the value for MSNC5 (MSN Msgr 7.5)
# msnc6 This is the value for MSNC6 (MSN Msgr 8.0)
# msnc7 This is the value for MSNC7 (MSN Msgr 8.1)
# msnc8 This is the value for MSNC8 (MSN Msgr 8.5)
# msnc9 This is the value for MSNC9 (WLM 9 Beta)
# msnc10 This is the value for MSNC10 (WLM 2009)
#
#switch==1 means turn on, 0 means turn off
#
# Reference : http://zoronax.spaces.live.com/?_c11_BlogPart_FullView=1&_c11_BlogPart_blogpart=blogview&_c=BlogPart&partqs=amonth%3d6%26ayear%3d2006
#
# From http://forums.fanatic.net.nz/index.php?showtopic=17639 thanks to Ole Andre
#define CapabilityMobileOnline 0x00000001
#define CapabilityMSN8User 0x00000002
#define CapabilityRendersGif 0x00000004
#define CapabilityRendersIsf 0x00000008
#define CapabilityWebCamDetected 0x00000010
#define CapabilitySupportsChunking 0x00000020
#define CapabilityWebIMClient 0x00000040
#// FIXME: the canonical meaning of 0x00000080 is missing
#define CapabilityWebIMClient 0x00000200
#define CapabiltiyConnectedViaTGW 0x00000800
#// FIXME: the canonical meaning of 0x00001000 is missing
#define CapabilityMCEUser 0x00002000
#define CapabilitySupportsDirectIM 0x00004000
#define CapabilitySupportsWinks 0x00008000
#define CapabilitySupportsSharedSearch 0x00010000
#define CapabilityIsBot 0x00020000
#define CapabilitySupportsVoiceIM 0x00040000
#define CapabilitySupportsSChannel 0x00080000
#define CapabilitySupportsSipInvite 0x00100000
#define CapabilitySupportsTunneledSip 0x00100000
#define CapabilitySupportsSDrive 0x00400000
#define CapabilityHasOnecare 0x01000000
#define CapabilityP2PSupportsTurn 0x02000000
#define CapabilityP2PBootstrapViaUUN 0x04000000
#define CapabilityMsgrVersion 0xf0000000
#define CapabilityP2PAware(id) ((id & CapabilityMsgrVersion) != 0)
proc getCapabilityFlag { cap } {
set flag 0
set extra 0
switch -- $cap {
mobile { set flag 0x000001 }
inkgif { set flag 0x000004 }
inkisf { set flag 0x000008 }
webcam { set flag 0x000010 }
multip { set flag 0x000020 }
paging { set flag 0x000040 }
drctpg { set flag 0x000080 }
webmsn { set flag 0x000200 }
tgw { set flag 0x000800 }
space { set flag 0x001000 }
mce { set flag 0x002000 }
direct { set flag 0x004000 }
winks { set flag 0x008000 }
search { set flag 0x010000 }
bot { set flag 0x020000 }
voice { set flag 0x040000 }
secure { set flag 0x080000 }
sip { set flag 0x100000 }
tunnelsip { set flag 0x200000 }
shared { set flag 0x400000 }
unknown { set flag 0x02000000 }
uun { set flag 0x04000000 }
msnc1 { set flag 0x10000000 }
msnc2 { set flag 0x20000000 }
msnc3 { set flag 0x30000000 }
msnc4 { set flag 0x40000000 }
msnc5 { set flag 0x50000000 }
msnc6 { set flag 0x60000000 }
msnc7 { set flag 0x70000000 }
msnc8 { set flag 0x80000000 }
msnc9 { set flag 0x90000000 }
msnc10 { set flag 0xA0000000 }
p2paware { set flag 0xF0000000 }
rtcvideo { set extra 0x00000010 }
unknown { set extra 0x00000020 }
p2pv2 { set extra 0x00000030 }
}
return [list $flag $extra]
}
proc setClientCap { cap { switch 1 } } {
set clientid [::config::getKey clientid 0]
set clientid [split $clientid ":"]
set extra [lindex $clientid 1]
set clientid [lindex $clientid 0]
if {$clientid == "" } {set clientid 0}
if {$extra == "" } { set extra 0}
set flags [getCapabilityFlag $cap]
set flag [lindex $flags 0]
set extra_flag [lindex $flags 1]
# WLM uses :
# inkgif, inkisf, multip, direct, winks, voice, secure,
# sip, tunnelsip, shared, rtcvideo, msnc10
# we are missing : inkisf, direct, secure, shared, rtcvideo
if { $switch } {
set clientid [expr {$clientid | $flag}]
set extra [expr {$extra | $extra_flag} ]
} else {
set clientid [expr {$clientid & (0xFFFFFFFF ^ $flag)} ]
set extra [expr {$extra & (0xFFFFFFFF ^ $extra_flag)} ]
}
::config::setKey clientid "$clientid:$extra"
return "$clientid:$extra"
}
proc hasCapability { clientcaps cap } {
set clientid [split $clientcaps ":"]
set extra [lindex $clientid 1]
set clientid [lindex $clientid 0]
if {$clientid == "" } {set clientid 0}
if {$extra == "" } { set extra 0}
set flags [getCapabilityFlag $cap]
set flag [lindex $flags 0]
set extra_flag [lindex $flags 1]
if {$cap == "p2paware"} {
return [expr {[clientCapsVersion $clientid] > 0}]
}
#if {$cap == "p2pv2" } {
# if {[llength [split $clientcaps ":"]] > 1} {
# return 1
# } else {
# return 0
# }
#}
if {$flag != 0} {
if {($clientid & $flag) == $flag} {
return 1
} else {
return 0
}
} elseif {$extra_flag != 0} {
if {($extra & $extra_flag) == $extra_flag} {
return 1
} else {
return 0
}
}
}
proc clientCapsVersion { clientid } {
set clientid [split $clientid ":"]
set extra [lindex $clientid 1]
set clientid [lindex $clientid 0]
if {$clientid == "" } {set clientid 0}
if {$extra == "" } { set extra 0}
return [expr {($clientid & 0xF0000000) >> 28}]
}
proc myStatusIs {} {
variable myStatus
return $myStatus
}
proc setMyStatus { status } {
variable myStatus
set myStatus $status
}
proc userIsNotIM {userlogin} {
if { [lsearch [::abook::getLists $userlogin] FL] == -1} {
return 1
}
return 0
}
proc userIsBlocked {userlogin} {
if { [lsearch [::abook::getLists $userlogin] BL] != -1} {
return 1
}
return 0
}
proc blockUser { userlogin } {
if {[::config::getKey protocol] >= 13} {
set users_to_delete [list]
set users_to_add [list]
foreach user $userlogin {
if {[lsearch [::abook::getContactData $user lists] "FL"] == -1 &&
[lsearch [::abook::getContactData $user lists] "RL"] == -1} {
continue
}
#Don't delete from AL, just add to BL... server will automatically remove from AL, otherwise it won't work
#if {[lsearch [::abook::getContactData $user lists] "AL"] != -1} {
# lappend users_to_delete $user
#}
if {[lsearch [::abook::getContactData $user lists] "BL"] == -1} {
lappend users_to_add $user
}
}
if {$users_to_delete != [list] } {
$::ab DeleteMember [list ::MSN::blockUserDeleteCB $users_to_delete $users_to_add] "BlockUnblock" $users_to_delete "Allow"
} elseif {$users_to_add != [list] } {
$::ab AddMember [list ::MSN::blockUserAddCB $users_to_delete $users_to_add] "BlockUnblock" $users_to_add "Block"
}
} else {
::MSN::WriteSB ns REM "AL $userlogin"
::MSN::WriteSB ns ADC "BL N=$userlogin"
#an event to let the GUI know a user is blocked
after 500 [list ::Event::fireEvent contactBlocked protocol $userlogin]
set evpar(userlogin) userlogin
::plugins::PostEvent contactBlocked evpar
}
}
proc blockUserDeleteCB { users_to_delete users_added fail } {
if {$fail == 0 || $fail == 2} {
$::ab AddMember [list ::MSN::blockUserAddCB $users_to_delete $users_added] "BlockUnblock" $users_to_delete "Block"
} else {
set blocked_users [concat $users_to_delete $users_added]
set blocked_users [lsort -unique $blocked_users]
if {[llength $blocked_users] > 1 } {
::MSN::blockUserGroupChained $blocked_users
}
}
}
proc blockUserGroupChained { users } {
set user [lindex $users 0]
set users [lreplace $users 0 0]
::MSN::blockUser $user
update
after 100 [list ::MSN::blockUserGroupChained $users]
}
proc blockUserAddCB { users_deleted users_added fail } {
if {$fail == 0 || $fail == 2} {
foreach userlogin $users_deleted {
set contact [split $userlogin "@"]
set user [lindex $contact 0]
set domain [lindex $contact 1]
set xml "<ml><d n=\"$domain\"><c n=\"$user\" l=\"2\" t=\"1\"/></d></ml>"
set xmllen [string length $xml]
::MSN::WriteSBNoNL ns "RML" "$xmllen\r\n$xml"
::abook::removeContactFromList $userlogin AL
::MSN::deleteFromList AL $userlogin
}
foreach userlogin $users_added {
set contact [split $userlogin "@"]
set user [lindex $contact 0]
set domain [lindex $contact 1]
set xml "<ml><d n=\"$domain\"><c n=\"$user\" l=\"4\" t=\"1\"/></d></ml>"
set xmlllen [string length $xml]
::MSN::WriteSBNoNL ns "ADL" "$xmlllen\r\n$xml" [list ns handleADLResponse]
::abook::addContactToList $userlogin BL
::MSN::addToList BL $userlogin
::MSN::contactListChanged
}
set blocked_users [concat $users_deleted $users_added]
set blocked_users [lsort -unique $blocked_users]
foreach userlogin $blocked_users {
#an event to let the GUI know a user is blocked
::Event::fireEvent contactBlocked protocol $userlogin
set evpar(userlogin) userlogin
::plugins::PostEvent contactBlocked evpar
}
} elseif {$users_deleted != [list] } {
$::ab DeleteMember [list ::MSN::blockUnblockUserFailureCB] "BlockUnblock" $users_deleted "Block"
}
}
proc unblockUser { userlogin } {
if {[::config::getKey protocol] >= 13} {
set users_to_delete [list]
set users_to_add [list]
foreach user $userlogin {
if {[lsearch [::abook::getContactData $user lists] "FL"] == -1 &&
[lsearch [::abook::getContactData $user lists] "RL"] == -1} {
continue
}
if {[lsearch [::abook::getContactData $user lists] "BL"] != -1} {
lappend users_to_delete $user
}
if {[lsearch [::abook::getContactData $user lists] "AL"] == -1} {
lappend users_to_add $user
}
}
if {$users_to_delete != [list] } {
$::ab DeleteMember [list ::MSN::unblockUserDeleteCB $users_to_delete $users_to_add] "BlockUnblock" $users_to_delete "Block"
} elseif {$users_to_add != [list] } {
$::ab AddMember [list ::MSN::unblockUserAddCB $users_to_delete $users_to_add] "BlockUnblock" $users_to_add "Allow"
}
} else {
::MSN::WriteSB ns REM "BL $userlogin"
::MSN::WriteSB ns ADC "AL N=$userlogin"
#an event to let the GUI know a user is unblocked
after 500 [list ::Event::fireEvent contactUnblocked protocol $userlogin]
set evpar(userlogin) userlogin
::plugins::PostEvent contactUnblocked evpar
}
}
proc unblockUserDeleteCB { users_to_delete users_added fail } {
if {$fail == 0 || $fail == 2} {
$::ab AddMember [list ::MSN::unblockUserAddCB $users_to_delete $users_added] "BlockUnblock" $users_to_delete "Allow"
} else {
set unblocked_users [concat $users_to_delete $users_added]
set unblocked_users [lsort -unique $unblocked_users]
if {[llength $unblocked_users] > 1 } {
::MSN::unblockUserGroupChained $unblocked_users
}
}
}
proc unblockUserGroupChained { users } {
set user [lindex $users 0]
set users [lreplace $users 0 0]
::MSN::unblockUser $user
update
after 100 [list ::MSN::unblockUserGroupChained $users]
}
proc unblockUserAddCB { users_deleted users_added fail } {
if {$fail == 0 || $fail == 2} {
foreach userlogin $users_deleted {
set contact [split $userlogin "@"]
set user [lindex $contact 0]
set domain [lindex $contact 1]
set xml "<ml><d n=\"$domain\"><c n=\"$user\" l=\"4\" t=\"1\"/></d></ml>"
set xmllen [string length $xml]
::MSN::WriteSBNoNL ns "RML" "$xmllen\r\n$xml"
::abook::removeContactFromList $userlogin BL
::MSN::deleteFromList BL $userlogin
}
foreach userlogin $users_added {
set contact [split $userlogin "@"]
set user [lindex $contact 0]
set domain [lindex $contact 1]
set xml "<ml><d n=\"$domain\"><c n=\"$user\" l=\"2\" t=\"1\"/></d></ml>"
set xmlllen [string length $xml]
::MSN::WriteSBNoNL ns "ADL" "$xmlllen\r\n$xml" [list ns handleADLResponse]
::abook::addContactToList $userlogin AL
::MSN::addToList AL $userlogin
::MSN::contactListChanged
}
set unblocked_users [concat $users_deleted $users_added]
set unblocked_users [lsort -unique $unblocked_users]
foreach userlogin $unblocked_users {
#an event to let the GUI know a user is blocked
::Event::fireEvent contactUnblocked protocol $userlogin
set evpar(userlogin) userlogin
::plugins::PostEvent contactUnblocked evpar
}
} elseif {$users_deleted != [list] } {
$::ab DeleteMember [list ::MSN::blockUnblockUserFailureCB] "BlockUnblock" $users_deleted "Allow"
}
}
proc blockUnblockUserFailureCB { fail } {
# Silently ignore anything here...
}
# Move user from one group to another group
proc moveUser { passport oldGid newGid {userName ""}} {
if { $userName == "" } {
set userName $passport
}
if { $oldGid == $newGid } {
return
}
set contactguid [::abook::getContactData $passport contactguid]
if {[::config::getKey protocol] >= 13 } {
$::ab ABGroupContactAdd [list ::MSN::moveUserCB $passport $newGid $oldGid] $newGid $contactguid
} else {
set atrid [::MSN::WriteSB ns "ADC" "FL C=$contactguid $newGid" "::MSN::MOVHandler $oldGid $contactguid $passport" ]
}
#an event to let the GUI know a user is moved between 2 groups
::Event::fireEvent contactMoved protocol $passport [list $oldGid $newGid]
}
proc moveUserCB { passport newGid oldGid fail} {
if {$fail == 0} {
set affected_groups $newGid
::abook::addContactToGroup $passport $newGid
if { $oldGid != "0" } {
set contactguid [::abook::getContactData $passport contactguid]
$::ab ABGroupContactDelete [list ::MSN::moveUserDoneCB $passport $newGid $oldGid] $oldGid $contactguid
} else {
lappend affected_groups 0
::abook::removeContactFromGroup $passport "0"
}
::Event::fireEvent contactAdded protocol $passport $affected_groups
}
}
proc moveUserDoneCB { passport newGid oldGid fail} {
if {$fail == 0} {
set affected_groups [::abook::getGroups $passport]
::abook::removeContactFromGroup $passport $oldGid
if { [::abook::getGroups $passport] == [list 0] } {
#User is now on nogroup
::Event::fireEvent contactMoved protocol $passport [linsert $affected_groups end 0]
::Event::fireEvent contactAdded protocol $passport 0
} else {
#an event to let the GUI know a user is removed from a group / the list
::Event::fireEvent contactRemoved protocol $passport $affected_groups
}
}
}
#Copy user from one group to another
proc copyUser { passport newGid {userName ""}} {
if { $userName == "" } {
set userName $passport
}
set contactguid [::abook::getContactData $passport contactguid]
if {[::config::getKey protocol] >= 13 } {
$::ab ABGroupContactAdd [list ::MSN::copyUserCB $passport $newGid] $newGid $contactguid
} else {
set atrid [::MSN::WriteSB ns "ADC" "FL C=$contactguid $newGid"]
}
}
proc copyUserCB { passport newGid fail} {
if {$fail == 0} {
set affected_groups $newGid
if { [::abook::getGroups $passport] == [list 0] } {
lappend affected_groups 0
::abook::addContactToGroup $passport $newGid
::abook::removeContactFromGroup $passport 0
} else {
::abook::addContactToGroup $passport $newGid
}
::Event::fireEvent contactAdded protocol $passport $affected_groups
}
}
#Add user to our Forward (contact) list
proc addUser { userlogin {username ""} {gid 0} } {
set userlogin [string map {" " ""} $userlogin]
if {[string match "*@*" $userlogin] < 1 } {
set domain "@hotmail.com"
set userlogin $userlogin$domain
}
set userlogin [string trim $userlogin]
set userlogin [string map { " " "" "\r" "" "\n" "" "\t" "" } $userlogin]
if { $username == "" } {
set username $userlogin
}
if {[::config::getKey protocol] >= 13} {
set cid [::abook::getContactData $userlogin contactguid]
# This is the WLM bug where you add someone but he doesn't get added correctly...
# if you delete someone from WLM, it will mark is "isMessengerUser = false", then if you add it again
# instead of updating it to "isMessengerUser = true", it does an ABContactAdd which results in the error
# ContactAlreadyExists.
if {[lsearch [::abook::getContactData $userlogin lists] "FL"] == -1 &&
[lsearch [::abook::getContactData $userlogin lists] "EL"] == -1 } {
$::ab ABContactAdd [list ::MSN::addUserCB $userlogin $gid 1] $userlogin
} else {
$::ab ABContactUpdate [list ::MSN::addUserCB $userlogin $gid 0 $cid] $userlogin [list isMessengerUser true] IsMessengerUser
}
} else {
::MSN::WriteSB ns "ADC" "FL N=$userlogin F=$username" "::MSN::ADCHandler $gid"
set evPar(userlogin) userlogin
::plugins::PostEvent addedUser evPar
}
}
proc addUserCB { email gid added cid fail } {
switch -- $fail {
2 -
0 {
set contact [split $email "@"]
set user [lindex $contact 0]
set domain [lindex $contact 1]
#It's a new contact so we save its guid and its nick
::abook::setContactData $email contactguid $cid
::abook::setContactForGuid $cid $email
# If we get a 'contactalreadyexists' on an ABContactAdd, then we must do
# an ABContactUpdate instead.. it should work now that we saved the contact guid...
if {$fail == 2 && $added == 1 } {
::MSN::addUser $email "" $gid
return
}
::abook::addContactToGroup $email 0
if {$added == 0} {
::abook::removeContactFromList $email "EL"
::MSN::deleteFromList "EL" $email
}
::abook::addContactToList $email "FL"
::MSN::addToList "FL" $email
set lists [::abook::getLists $email]
set mask 0
if {[lsearch $lists "FL"] != -1} {
incr mask 1
}
if {[lsearch $lists "AL"] != -1} {
incr mask 2
}
if {[lsearch $lists "BL"] != -1} {
incr mask 4
}
# If the contact was on AL or BL, it stays there, if it was in neither one, then
# it gets automatically added to AL..
if {$mask == 1} {
::abook::addContactToList $email "AL"
::MSN::addToList "AL" $email
incr mask 2
}
set xml "<ml><d n=\"$domain\"><c n=\"$user\" l=\"$mask\" t=\"1\"/></d></ml>"
set xmllen [string length $xml]
::MSN::WriteSBNoNL ns "ADL" "$xmllen\r\n$xml" [list ns handleADLResponse]
::MSN::contactListChanged
#an event to let the GUI know a user was added to a list
::Event::fireEvent contactListChange protocol $email
#an event to let the GUI know a user is copied/added to a group
::Event::fireEvent contactAdded protocol $email $gid
if { $gid != 0 } {
moveUser $email 0 $gid
}
msg_box "[trans contactadded]\n$email"
}
3 {
msg_box "[trans contactdoesnotexist]"
}
1 -
4 -
5 {
msg_box "[trans invalidusername]"
}
}
}
proc listToRole {list} {
switch -- $list {
"AL" {
set role "Allow"
}
"BL" {
set role "Block"
}
"PL" {
set role "Pending"
}
"RL" {
set role "Reverse"
}
default {
# error...
return ""
}
}
}
proc addUserToList { email list} {
$::ab AddMember [list ::MSN::addUserToListCB $email $list] \
"ContactSave" $email [listToRole $list]
}
proc addUserToListCB { userlogin list fail } {
switch -- $list {
"AL" {
set mask 2
}
"BL" {
set mask 4
}
default {
set mask 0
}
}
if {$mask != 0 } {
set contact [split $userlogin "@"]
set user [lindex $contact 0]
set domain [lindex $contact 1]
set xml "<ml><d n=\"$domain\"><c n=\"$user\" l=\"$mask\" t=\"1\"/></d></ml>"
set xmlllen [string length $xml]
::MSN::WriteSBNoNL ns "ADL" "$xmlllen\r\n$xml" [list ns handleADLResponse]
}
::abook::addContactToList $userlogin $list
::MSN::addToList $list $userlogin
::MSN::contactListChanged
#an event to let the GUI know a user's list changed
after 500 [list ::Event::fireEvent contactListChange protocol $userlogin]
}
proc removeUserFromList { email list} {
$::ab DeleteMember [list ::MSN::removeUserFromListCB $email $list] \
"ContactSave" $email [listToRole $list]
}
proc removeUserFromListCB { userlogin list fail } {
switch -- $list {
"AL" {
set mask 2
}
"BL" {
set mask 4
}
default {
set mask 0
}
}
if {$mask != 0 } {
set contact [split $userlogin "@"]
set user [lindex $contact 0]
set domain [lindex $contact 1]
set xml "<ml><d n=\"$domain\"><c n=\"$user\" l=\"$mask\" t=\"1\"/></d></ml>"
set xmlllen [string length $xml]
::MSN::WriteSBNoNL ns "RML" "$xmlllen\r\n$xml"
}
::abook::removeContactFromList $userlogin $list
::MSN::deleteFromList $list $userlogin
::MSN::contactListChanged
#an event to let the GUI know a user's list changed
after 500 [list ::Event::fireEvent contactListChange protocol $userlogin]
}
#Handler for the ADC message, to show the ADD messagebox, and to move a user to a group if gid != 0
proc ADCHandler { gid item } {
if { [lindex $item 2] == "FL"} {
set contact [urldecode [string range [lindex $item 3] 2 end]] ;# Email address
#an event to let the GUI know a user is copied/added to a group
::abook::setContactData $contact contactguid [string range [lindex $item 5] 2 end]
::abook::setContactForGuid [string range [lindex $item 5] 2 end] $contact
::Event::fireEvent contactAdded protocol $contact $gid
if { $gid != 0 } {
moveUser $contact 0 $gid
}
msg_box "[trans contactadded]\n$contact"
}
if { [lindex $item 0] == 500 } {
#Instead of disconnection, transform into error 201
ns handleCommand [lreplace $item 0 0 201]
return
}
ns handleCommand $item
}
proc MOVHandler { oldGid contactguid passport item } {
::MSN::GotADCResponse $item
if { $oldGid != "0" } {
set rtrid [::MSN::WriteSB ns "REM" "FL $contactguid $oldGid"]
} else {
::abook::removeContactFromGroup $passport "0"
}
}
#Remove user from a groups
proc removeUserFromGroup { userlogin grId } {
if {[::abook::getGroups $userlogin] == 0} {
return
}
if {[::config::getKey protocol] >= 13} {
$::ab ABGroupContactDelete [list ::MSN::removeUserFromGroupCB $userlogin $grId] $grId [::abook::getContactData $userlogin contactguid]
} else {
::MSN::WriteSB ns REM "FL [::abook::getContactData $userlogin contactguid] $grId"
}
}
proc removeUserFromGroupCB { userlogin grId fail} {
if {$fail == 0} {
set affected_groups [::abook::getGroups $userlogin]
::abook::removeContactFromGroup $userlogin $grId
if { [::abook::getGroups $userlogin] == [list 0] } {
#User is now on nogroup
::Event::fireEvent contactRemoved protocol $userlogin [linsert $affected_groups end 0]
::Event::fireEvent contactAdded protocol $userlogin 0
} else {
#an event to let the GUI know a user is removed from a group / the list
::Event::fireEvent contactRemoved protocol $userlogin $affected_groups
}
}
}
#Delete user totally
proc deleteUser { userlogin {full 0} } {
#We remove from everywhere
if { [::config::getKey protocol] >= 15 } {
if { [lsearch [::abook::getContactData $userlogin lists] "FL"] == -1 } {
$::ab ABContactDelete [list ::MSN::deleteUserFullCB $userlogin] $userlogin
} else {
$::ab ABContactUpdate [list ::MSN::deleteUserCB $userlogin $full] $userlogin [list isMessengerUser false] IsMessengerUser
}
} else {
::MSN::WriteSB ns REM "FL [::abook::getContactData $userlogin contactguid]"
foreach groupID [::abook::getGroups $userlogin] {
::MSN::WriteSB ns REM "FL [::abook::getContactData $userlogin contactguid] $groupID"
}
set evPar(userlogin) userlogin
::plugins::PostEvent deletedUser evPar
}
}
proc deleteUserCB { userlogin full err } {
if { $err == 0 || $err == 2 } {
set contact [split $userlogin "@"]
set user [lindex $contact 0]
set domain [lindex $contact 1]
set xml "<ml><d n=\"$domain\"><c n=\"$user\" l=\"1\" t=\"1\" /></d></ml>"
set xmllen [string length $xml]
::MSN::WriteSBNoNL ns "RML" "$xmllen\r\n$xml"
::abook::addContactToList $userlogin EL
::MSN::addToList EL $userlogin
::abook::removeContactFromList $userlogin FL
::MSN::deleteFromList FL $userlogin
::abook::setVolatileData $userlogin state FLN
::MSN::contactListChanged
#an event to let the GUI know a user is removed from a list
::Event::fireEvent contactListChange protocol $userlogin
set affected_groups [::abook::getGroups $userlogin]
if {$full} {
$::ab ABContactDelete [list ::MSN::deleteUserFullCB $userlogin] $userlogin
} else {
#an event to let the GUI know a user is removed from a group / the list
::Event::fireEvent contactRemoved protocol $userlogin $affected_groups
set evPar(userlogin) userlogin
::plugins::PostEvent deletedUser evPar
}
}
}
proc deleteUserFullCB { userlogin err } {
if { $err == 0 || $err == 2 } {
set affected_groups [::abook::getGroups $userlogin]
::abook::emptyUserGroups $userlogin
::abook::removeContactFromList $userlogin EL
::MSN::deleteFromList EL $userlogin
#The GUID is invalid if the contact is removed from the FL list
set userguid [::abook::getContactData $userlogin contactguid]
::abook::setContactForGuid $userguid ""
::abook::setContactData $userlogin contactguid ""
::abook::setContactData $userlogin cid ""
#an event to let the GUI know a user is removed from a group / the list
::Event::fireEvent contactRemoved protocol $userlogin $affected_groups
set evPar(userlogin) userlogin
::plugins::PostEvent deletedUser evPar
}
}
##################################################
#Internal procedures
##################################################
#Start the loop that will keep a keepalive (PNG) message every minute
proc StartPolling {} {
if {([::config::getKey keepalive] == 1) && ([::config::getKey connectiontype] == "direct")} {
variable pollstatus 0
after cancel "::MSN::PollConnection"
after 60000 "::MSN::PollConnection"
} else {
after cancel "::MSN::PollConnection"
}
}
#Stop sending the keepalive message
proc StopPolling {} {
after cancel "::MSN::PollConnection"
}
#Send a keepalive message
proc PollConnection {} {
variable pollstatus
#Let's try to keep the connection alive... sometimes it gets closed if we
#don't do send or receive something for a long time
if { [::MSN::myStatusIs] != "FLN" } {
::MSN::WriteSBRaw ns "PNG\r\n"
#Reconnect if necessary
if { $pollstatus > 1 && [::config::getKey reconnect] == 1 } {
::MSN::saveOldStatus
::MSN::logout
::MSN::reconnect "[trans connectionlost]"
} elseif { $pollstatus > 10 } {
::MSN::logout
}
incr pollstatus
}
after 60000 "::MSN::PollConnection"
}
if { $initialize_amsn == 1 } {
variable trid 0
}
#Write a string to the given SB, followed by a NewLine character, adding the transfer ID
proc WriteSB {sbn cmd param {handler ""}} {
WriteSBNoNL $sbn $cmd "$param\r\n" $handler
}
#Write a string to the given SB, with no NewLine, adding the transfer ID
proc WriteSBNoNL {sbn cmd param {handler ""}} {
variable trid
set msgid [incr trid]
set msgtxt "$cmd $msgid $param"
WriteSBRaw $sbn $msgtxt
if {$handler != ""} {
global list_cmdhnd
lappend list_cmdhnd [list $sbn $trid $handler]
}
if { $cmd == "MSG" } {
set ack_id [string range $param 0 0]
set noack [expr {$ack_id != "D" && $ack_id != "A"}]
} else {
set noack 1
}
if { $noack == 0 && [$sbn info vars unacked] != "" } {
$sbn add_unacked $msgid
}
return $msgid
}
proc WriteSBRaw {sbn cmd} {
if { $sbn == 0 } {
return
}
#Finally, to write, use a wrapper, so it's transparent to use
#a direct connection, a proxy, or anything
set proxy [$sbn cget -proxy]
catch {$proxy write $sbn $cmd} res
if { $res == 0 } {
if { $sbn != "ns" } {
catch {$sbn configure -last_activity [clock seconds] }
}
if {$sbn != "ns" } {
degt_protocol "->$sbn-[$sbn cget -sock] $cmd" sbsend
} else {
degt_protocol "->$sbn-[$sbn cget -sock] $cmd" nssend
}
} else {
::MSN::CloseSB $sbn
degt_protocol "->$sbn FAILED: $cmd" error
}
if { [info commands $sbn] == "" } { return }
if { $sbn != "ns" } {
if { [$sbn cget -killme] != "" } {
after cancel [$sbn cget -killme]
}
if { $cmd != "OUT\r\n" } {
$sbn configure -killme [after 60000 "::MSN::CloseInactiveSB $sbn"]
}
}
}
proc SendInk { chatid file } {
set maxchars 1202
set sb [::MSN::SBFor $chatid]
if { $sb == 0 } {
return
}
set fd [open $file r]
fconfigure $fd -translation {binary binary}
set data [read $fd]
close $fd
set data [::base64::encode $data]
set data [string map { "\n" ""} $data]
set data "base64:$data"
set chunks [expr {int( [string length $data] / $maxchars) + 1 } ]
status_log "Ink data : $data\nchunks : $chunks\n"
for {set i 0 } { $i < $chunks } { incr i } {
set chunk [string range $data [expr $i * $maxchars] [expr ($i * $maxchars) + $maxchars - 1]]
set msg ""
if { $i == 0 } {
set msg "MIME-Version: 1.0\r\nContent-Type: image/gif\r\n"
if { $chunks == 1 } {
set msg "${msg}\r\n$chunk"
} else {
set msgid "[format %X [myRand 4369 65450]][format %X [myRand 4369 65450]]-[format %X [myRand 4369 65450]]-[format %X [myRand 4369 65450]]-[format %X [expr { int([expr {rand() * 1000000}])%65450 } ] + 4369]-[format %X [myRand 4369 65450]][format %X [myRand 4369 65450]][format %X [myRand 4369 65450]]"
set msg "${msg}Message-ID: \{$msgid\}\r\nChunks: $chunks\r\n\r\n$chunk"
}
} else {
set msg "${msg}Message-ID: \{$msgid\}\r\nChunk: $i\r\n\r\n$chunk"
}
set msglen [string length $msg]
::MSN::WriteSBNoNL $sb "MSG" "N $msglen\r\n$msg"
}
}
# This method sends an Action to MSNP13+ users, datacast id 4 with Data being the action message, the messages look like emotes, in grey with no '$nick says' heading
proc SendAction {chatid action } {
set sbn [::MSN::SBFor $chatid]
set action [encoding convertto $action]
set msg "MIME-Version: 1.0\r\nContent-Type: text/x-msnmsgr-datacast\r\n\r\nID: 4\r\nData: $action\r\n\r\n"
set msg_len [string length $msg]
#Send the packet
::MSN::WriteSBNoNL $sbn "MSG" "U $msg_len\r\n$msg"
if {[::abook::getKeepLogs $chatid]} {
::log::WriteLog $chatid $action
}
}
########################################################################
# Check if the old closed preferred SB is still the preferred SB, or
# close it if not.
proc CheckKill { sb } {
#Kill any remaining timers
after cancel "::MSN::CheckKill $sb"
if { [catch {$sb cget -name}] } {
#The SB was destroyed
return
}
if { [$sb cget -stat] != "d" } {
#The SB is connected again, forget about killing
return
} else {
#Get the chatid
set chatid [::MSN::ChatFor $sb]
if { $chatid == 0 } {
#If SB is not in any chat, we can just kill it
status_log "Session $sb killed with no chatid associated\n"
::MSN::KillSB $sb
return 0
}
#If we're the preferred chatid
if { [::MSN::SBFor $chatid] == $sb } {
#It's the preferred SB, so keep it for the moment
set items [expr {[llength [$sb cget -users]] -1}]
status_log "Session $sb closed, there are [expr {$items+1}] users: [$sb cget -users]\n" blue
for {set idx $items} {$idx >= 0} {incr idx -1} {
set user_info [lindex [$sb cget -users] $idx]
$sb delUser $idx
amsn::userLeaves [::MSN::ChatFor $sb] [list $user_info] 0
}
#Try to kill it again in 5 minutes
after 300000 "::MSN::CheckKill $sb"
} else {
#It's not the preferred SB,so we can safely delete it from the
#chat and Kill it
DelSBFor $chatid $sb
KillSB $sb
}
}
}
#///////////////////////////////////////////////////////////////////////
# Usually called from anywhere when a problem is found when writing or
# reading a SB. It closes the sock.
# For NS connection, call only when an error happens. To manually log out,
# call ::MSN::logout
proc CloseSB { sb } {
status_log "::MSN::CloseSB $sb Called\n" green
catch {fileevent [$sb cget -sock] readable "" } res
catch {fileevent [$sb cget -sock] writable "" } res
catch {close $sock}
$sb configure -sock ""
ClearSB $sb
}
#///////////////////////////////////////////////////////////////////////
########################################################################
#Called when we find a "" (empty string) in the SB buffer. This means
#the SB is closed. Proceed to clear everything related to it
proc ClearSB { sb } {
status_log "::MSN::ClearSB $sb called\n" green
set oldstat [$sb cget -stat]
$sb configure -stat "d"
if { [string match -nocase "*ns*" $sb] } {
status_log "clearing sb $sb. oldstat=$oldstat"
catch {[$sb cget -proxy] finish $sb}
catch {close [$sb cget -sock]}
$sb configure -sock ""
set mystatus [::MSN::myStatusIs]
if { [info exists ::automessage] } {
set old_automessage $::automessage
} else {
set old_automessage ""
}
#If we were not disconnected or authenticating, logout
if { ("$oldstat" != "d") && ("$oldstat" != "u") } {
logout
}
#If we're not disconnected, connected, or authenticating, then
#we have a connection error.
if { ("$oldstat"!="d") && ("$oldstat" !="o") && ("$oldstat" !="u") && ("$oldstat" !="closed")} {
::config::setKey start_ns_server [::config::getKey default_ns_server]
::config::setKey start_gateway_server [::config::getKey default_gateway_server]
set error_msg [ns cget -error_msg]
#Reconnect if necessary
if { [::config::getKey reconnect] == 1 } {
::MSN::saveOldStatus $mystatus $old_automessage
if { $error_msg != "" } {
::MSN::reconnect "[trans connecterror]:\n[ns cget -error_msg]"
} else {
::MSN::reconnect "[trans connecterror]"
}
return
}
if { $error_msg != "" } {
msg_box "[trans connecterror]:\n[ns cget -error_msg]"
} else {
msg_box "[trans connecterror]"
}
}
#If we were connected, we have lost the connection
if { ("$oldstat"=="o") } {
::config::setKey start_ns_server [::config::getKey default_ns_server]
::config::setKey start_gateway_server [::config::getKey default_gateway_server]
set error_msg [ns cget -error_msg]
#Reconnect if necessary
if { [::config::getKey reconnect] == 1 } {
::MSN::saveOldStatus $mystatus $old_automessage
if { $error_msg != "" } {
::MSN::reconnect "[trans connectionlost]: [ns cget -error_msg]"
} else {
::MSN::reconnect "[trans connectionlost]"
}
return
}
if { $error_msg != "" } {
msg_box "[trans connectionlost]: [ns cget -error_msg]"
} else {
msg_box "[trans connectionlost]"
}
status_log "Connection lost\n" red
}
} else {
#Check if we can kill the SB (clear all related info
CheckKill $sb
if { [info commands $sb] == "" } { return }
if { [$sb cget -killme] != "" } {
after cancel [$sb cget -killme]
$sb configure -killme ""
}
}
}
#///////////////////////////////////////////////////////////////////////
########################################################################
#Answer the server challenge. This is a handler for CHL message
proc AnswerChallenge { item } {
if { [lindex $item 1] != 0 } {
status_log "Invalid challenge\n" red
} else {
set prodkey "PROD0090YUAUV\{2B"
set str [CreateQRYHash [lindex $item 2]]
::MSN::WriteSBNoNL ns "QRY" "$prodkey 32\r\n$str"
}
}
proc CreateQRYHash {chldata {prodid "PROD0090YUAUV\{2B"} {prodkey "YMM8C_H7KCQ2S_KL"}} {
# Create an MD5 hash out of the given data, then form 32 bit integers from it
set md5hash [::md5::md5 $chldata$prodkey]
set md5parts [MD5HashToInt $md5hash]
# Then create a valid productid string, divisable by 8, then form 32 bit integers from it
set nrPadZeros [expr {8 - [string length $chldata$prodid] % 8}]
set padZeros [string repeat 0 $nrPadZeros]
set chlprodid [CHLProdToInt $chldata$prodid$padZeros]
# Create the key we need to XOR
set key [KeyFromInt $md5parts $chlprodid]
set low 0x[string range $md5hash 0 15]
set high 0x[string range $md5hash 16 32]
set low [expr {$low ^ $key}]
set high [expr {$high ^ $key}]
set p1 [format %8.8x [expr {($low / 0x100000000) % 0x100000000}]]
set p2 [format %8.8x [expr {$low % 0x100000000}]]
set p3 [format %8.8x [expr {($high / 0x100000000) % 0x100000000}]]
set p4 [format %8.8x [expr {$high % 0x100000000}]]
return $p1$p2$p3$p4
}
proc KeyFromInt { md5parts chlprod } {
# Create a new series of numbers
set key_temp 0
set key_high 0
set key_low 0
# Then loop on the entries in the second array we got in the parameters
for {set i 0} {$i < [llength $chlprod]} {incr i 2} {
# Make $key_temp zero again and perform calculation as described in the documents
set key_temp [lindex $chlprod $i]
set key_temp [expr {(wide(0x0E79A9C1) * wide($key_temp)) % wide(0x7FFFFFFF)}]
set key_temp [expr {wide($key_temp) + wide($key_high)}]
set key_temp [expr {(wide([lindex $md5parts 0]) * wide($key_temp)) + wide([lindex $md5parts 1])}]
set key_temp [expr {wide($key_temp) % wide(0x7FFFFFFF)}]
set key_high [lindex $chlprod [expr {$i+1}]]
set key_high [expr {(wide($key_high) + wide($key_temp)) % wide(0x7FFFFFFF)}]
set key_high [expr {(wide([lindex $md5parts 2]) * wide($key_high)) + wide([lindex $md5parts 3])}]
set key_high [expr {wide($key_high) % wide(0x7FFFFFFF)}]
set key_low [expr {wide($key_low) + wide($key_temp) + wide($key_high)}]
}
set key_high [expr {(wide($key_high) + wide([lindex $md5parts 1])) % wide(0x7FFFFFFF)}]
set key_low [expr {(wide($key_low) + wide([lindex $md5parts 3])) % wide(0x7FFFFFFF)}]
set key_high 0x[byteInvert [format %8.8X $key_high]]
set key_low 0x[byteInvert [format %8.8X $key_low]]
set long_key [expr {(wide($key_high) << 32) + wide($key_low)}]
return $long_key
}
# Takes an CHLData + ProdID + Padded string and chops it in 4 bytes. Then converts to 32 bit integers
proc CHLProdToInt { CHLProd } {
set hexs {}
set result {}
while {[string length $CHLProd] > 0} {
lappend hexs [string range $CHLProd 0 3]
set CHLProd [string range $CHLProd 4 end]
}
for {set i 0} {$i < [llength $hexs]} {incr i} {
binary scan [lindex $hexs $i] H8 int
lappend result 0x[byteInvert $int]
}
return $result
}
# Takes an MD5 string and chops it in 4. Then "decodes" the HEX and converts to 32 bit integers. After that it ANDs
proc MD5HashToInt { md5hash } {
binary scan $md5hash a8a8a8a8 hash1 hash2 hash3 hash4
set hash1 [expr {"0x[byteInvert $hash1]" & 0x7FFFFFFF}]
set hash2 [expr {"0x[byteInvert $hash2]" & 0x7FFFFFFF}]
set hash3 [expr {"0x[byteInvert $hash3]" & 0x7FFFFFFF}]
set hash4 [expr {"0x[byteInvert $hash4]" & 0x7FFFFFFF}]
return [list $hash1 $hash2 $hash3 $hash4]
}
proc byteInvert { hex } {
set hexs {}
while {[string length $hex] > 0} {
lappend hexs [string range $hex 0 1]
set hex [string range $hex 2 end]
}
set hex ""
for {set i [expr [llength $hexs] -1]} {$i >= 0} {incr i -1} {
append hex [lindex $hexs $i]
}
return $hex
}
proc CALReceived {sb_name user item} {
switch -- [lindex $item 0] {
215 {
#if you try to begin a chat session with yourself
status_log "trying to chat with yourself"
set chatid [::MSN::ChatFor $sb_name]
::MSN::ClearQueue $chatid
::amsn::chatStatus $chatid "[trans useryourself]\n" miniwarning
}
216 {
# if you try to begin a chat session with someone who blocked you and is online
set chatid [::MSN::ChatFor $sb_name]
::MSN::ClearQueue $chatid
::amsn::chatStatus $chatid "$user: [trans userblocked]\n" miniwarning
}
217 {
#TODO: Check what we do with sb stat "?", disable chat window?
# this should be related to user state changes
#sb get $sb_name stat
set chatid [::MSN::ChatFor $sb_name]
::MSN::ClearQueue $chatid
# DO NOT cleanchat... it's needed for ::ChatWindow::TopUpdate
# ::MSN::CleanChat $chatid
::amsn::chatStatus $chatid "$user: [trans usernotonline]\n" miniwarning
# If the user goes offline, the servers should tell us so. If we receive a 217 error for a not-offline user, it's most probably a server error - YES it does happen - and it shouldn't make the user go offline on the CL...
#::abook::setVolatileData $user state "FLN"
::ChatWindow::TopUpdate $chatid
#msg_box "[trans usernotonline]"
}
713 {
status_log "CALReceived: 713 USER TOO ACTIVE\n" white
}
}
return 1
}
########################################################################
########################################################################
########################################################################
# CHAT RELATED PROCEDURES. SHOULD THEY HAVE THEIR OWN NAMESPACE??
########################################################################
########################################################################
########################################################################
########################################################################
#Send x-clientcaps packet, for third-party MSN client
proc clientCaps {chatid} {
set sbn [SBFor $chatid]
#If not connected to the user OR if user don't want to send clientCaps info, do nothing
if {$sbn == 0 || ![::config::getKey clientcaps]} {
return
}
set msg "MIME-Version: 1.0\r\nContent-Type: text/x-clientcaps\r\n\r\n"
#Add the aMSN version to the message
set msg "${msg}Client-Name: aMSN [set ::version]\r\n"
#Verify if the user keep logs or not
if {[::abook::getKeepLogs $chatid]} {
set chatlogging "Y"
} else {
set chatlogging "N"
}
#Add the log information to the $msg
set msg "${msg}Chat-Logging: $chatlogging\r\n"
#Jerome: I disable that feature because I'm not sure users will like to provide theses kinds of
#informations to everybody, but it can be useful later..
#Verify the platform (feel free to improve it if you want better details, like bsd, etc)
#if { [OnDarwin] } {
# set operatingsystem "Mac OS X"
#} elseif { [OnWin] } {
# set operatingsystem "Windows"
#} elseif { [OnLinux] } {
# set operatingsystem "Linux"
#}
#Add the operating system to the msg
#set msg "${msg}Operating-System: $operatingsystem\r\n\r\n"
#Send the packet
#set msg [encoding convertto utf-8 $msg]
set msg_len [string length $msg]
WriteSBNoNL $sbn "MSG" "U $msg_len\r\n$msg"
status_log "Send text/x-clientcaps\n" red
}
# Return a list of users in chat, or last user in chat if chat is closed
proc usersInChat { chatid } {
set sb [SBFor $chatid]
if { $sb == 0 || [catch {$sb cget -name}] } {
status_log "usersInChat: no SB for chat $chatid!! (shouldn't happen?)\nUser probably offline ?\n" white
return [list]
}
set user_list [$sb cget -users]
if { [llength $user_list] } {
return $user_list
} else {
return [list [$sb cget -last_user]]
}
}
########################################################################
#Set the given $typer as a typing user. He will be removed after 6
#seconds.
proc addSBTyper { sb typer } {
set chatid [::MSN::ChatFor $sb]
set idx [$sb search -typers $typer]
if {$idx == -1} {
#Add if not already typing
$sb addTyper $typer
set evPar(typer) typer
set evPar(chatid) chatid
::plugins::PostEvent add_typer evPar
}
#Cancel last DelSBTyper timer
after cancel [list ::MSN::DelSBTyper $sb $typer]
#Remove typer after 6 seconds without a new notification
after 6000 [list ::MSN::DelSBTyper $sb $typer]
#TODO: Call CHAT layer instead of GUI layer
if { $chatid != "" } {
if {[::ChatWindow::For $chatid] == 0} {
#Chat window not yet created so we make it and signal to the user that a contact has joined the convo
::amsn::userJoins $chatid $typer
}
::amsn::updateTypers $chatid
}
}
########################################################################
#Remove the given typer from the chat typers list
proc DelSBTyper {sb typer} {
after cancel [list ::MSN::DelSBTyper $sb $typer]
catch {
set chatid [::MSN::ChatFor $sb]
set idx [$sb search -typers $typer]
$sb delTyper $idx
set evPar(typer) typer
set evPar(chatid) chatid
::plugins::PostEvent remove_typer evPar
#TODO: Call CHAT layer instead of GUI layer
if { $chatid != "" } {
::amsn::updateTypers $chatid
}
}
}
########################################################################
#Return a list of users currently typing in the given chat
proc typersInChat { chatid } {
set sb [SBFor $chatid]
if { $sb == 0 } {
status_log "typersInChat: no SB for chat $chatid!!\n" white
return [list]
}
set num_typers [llength [$sb cget -typers]]
if {$num_typers > 0} {
return [$sb cget -typers]
} else {
return [list]
}
}
proc lastMessageTime { chatid } {
set sb [SBFor $chatid]
if {$sb != 0} {
return [$sb cget -lastmsgtime]
} else {
return 0
}
}
if { $initialize_amsn == 1 } {
variable sb_num 0
}
proc GetNewSB {} {
return [SB create %AUTO%]
}
proc chatTo { user } {
global sb_list
# set lowuser [string tolower ${user}]
set lowuser $user
#If there's already an existing chat for that user, and
#that chat is ready, return it as chatd
if { [chatReady $lowuser] } {
return $lowuser
}
#Get SB for that chatid, if it exists
set sb [SBFor $lowuser]
# Here we either have no SB, then we create one, or we have one but
# when we call cmsn_reconnect, the SB got closed, so we have to recreate it
if { $sb == 0 || [catch {cmsn_reconnect $sb}] } {
#If no SB exists, get a new one and
#configure it
set sb [GetNewSB]
status_log "::MSN::chatTo: Opening chat to user $user\n"
status_log "::MSN::chatTo: No SB available, creating new: $sb\n"
$sb configure -stat "d"
$sb configure -title [trans chat]
$sb configure -last_user $lowuser
AddSBFor $lowuser $sb
lappend sb_list "$sb"
# We call the cmsn_reconnect
cmsn_reconnect $sb
}
return $lowuser
}
########################################################################
proc CloseInactiveSB { sb } {
if { [info commands $sb] == "" } {
return
}
set chatid [::MSN::ChatFor $sb]
if {$chatid != 0} {
set user_list [::MSN::usersInChat $chatid]
if { [llength $user_list] > 1 } {
return
}
}
catch {$sb configure -killme ""}
if { [catch {WriteSBRaw $sb "OUT\r\n"} ] } {
return
}
catch {CloseSB $sb}
}
########################################################################
#Totally remove the given SB
proc KillSB { sb } {
global sb_list list_cmdhnd
status_log "::MSN::KillSB: Killing SB $sb\n"
set idx [lsearch -exact $sb_list $sb]
if {$idx == -1} {
return 0
}
#Remove the SB from sb_list
set sb_list [lreplace $sb_list $idx $idx ]
#Destroy th SB
status_log "Destroy the SB $sb in KillSB" red
$sb destroy
#Remove any handlers of the SB
set list_cmdhnd [lsearch -all -not -inline $list_cmdhnd "$sb *"]
}
########################################################################
#Totally clean a chat. Remove all associated SBs
proc CleanChat { chatid } {
status_log "::MSN::CleanChat: Cleaning chat $chatid\n"
while { [SBFor $chatid] != 0 } {
set sb [SBFor $chatid]
DelSBFor $chatid ${sb}
#We leave the switchboard if it exists
if {![catch {$sb cget -name}] } {
if {[$sb cget -stat] != "d"} {
WriteSBRaw $sb "OUT\r\n"
}
}
after 60000 [list ::MSN::KillSB ${sb}]
}
::amsn::chatDisabled $chatid
}
########################################################################
#Enqueue a -1 command to the chat Queue. This will produce a call
#to CleanChat only after all the chat queue is processed
proc leaveChat { chatid } {
ChatQueue $chatid -1
}
#///////////////////////////////////////////////////////////////////////////////
# chatReady (chatid)
# Returns 1 if the given chat 'chatid' is ready for delivering a message.
# Returns 0 if it's not ready.
proc chatReady { chatid } {
set sb [SBFor $chatid]
if { "$sb" == "0" || [catch {$sb cget -name}] } {
return 0
}
set sb_sock [$sb cget -sock]
if { "$sb_sock" == "" } {
return 0
}
# This next two are necessary because SBFor doesn't
# always return a ready SB
if { "[$sb cget -stat]" != "o" } {
return 0
}
if {[catch {eof $sb_sock} res]} {
status_log "::MSN::chatReady: Error in the EOF command for $sb socket($sb_sock): $res\n" red
::MSN::CloseSB $sb
return 0
}
if {[eof $sb_sock]} {
status_log "::MSN::chatReady: EOF in $sb socket($sb_sock)\n"
::MSN::CloseSB $sb
return 0
}
if {[llength [$sb cget -users]]} {
return 1
}
return 0
}
#///////////////////////////////////////////////////////////////////////////////
########################################################################
#Given a chatid, return the preferred SB to be used for that chat
proc SBFor { chatid } {
variable sb_chatid
if { [info exists sb_chatid($chatid)] } {
if { [llength $sb_chatid($chatid)] > 0 } {
#Try to find a connected SB, return it and move to front
set idx -1
foreach sb $sb_chatid($chatid) {
incr idx
if {![catch {$sb cget -stat} res ]} {
if { "[$sb cget -stat]" == "o" } {
set sb_sock [$sb cget -sock]
if { "$sb_sock" != "" } {
if {$idx!=0} {
set sb_chatid($chatid) [lreplace $sb_chatid($chatid) $idx $idx]
set sb_chatid($chatid) [linsert $sb_chatid($chatid) 0 $sb]
}
return $sb
}
}
}
}
#If not found, return first SB
#status_log "SBFor: Returned [lindex $sb_chatid($chatid) 0] as SB for $chatid\n" blue
return [lindex $sb_chatid($chatid) 0]
}
}
status_log "::MSN::SBFor: Requested SB for non existent chatid $chatid\n" blue
return 0
}
########################################################################
# Given a SB, return the chatid it's associated to
proc ChatFor { sb_name } {
variable chatid_sb
if {[info exists chatid_sb($sb_name)]} {
return $chatid_sb($sb_name)
}
status_log "::MSN::ChatFor: SB $sb_name is not associated to any chat\n" blue
return 0
}
########################################################################
# Add the given SB to the list of usable SBs for that chat
proc AddSBFor { chatid sb_name} {
variable sb_chatid
variable chatid_sb
if { $chatid == "" } {
status_log "::MNS::AddSBFor: BIG ERROR!!! chatid is blank. sb_name is $sb_name\n" white
return 0
}
if { $sb_name == "" } {
status_log "::MNS::AddSBFor: BIG ERROR!!! sb_name is blank. chatid is $chatid\n" white
return 0
}
if {![info exists sb_chatid($chatid)]} {
set sb_chatid($chatid) [list]
status_log "::MSN::AddSBFor: Creating sb_chatid list for $chatid\n"
}
set index [lsearch $sb_chatid($chatid) $sb_name]
set oldsb_chatid $sb_chatid($chatid);
set moved_to_beginning 0
if { $index == -1 } {
#Should we insert at the begining? Newer SB's are probably better
set sb_chatid($chatid) [linsert $sb_chatid($chatid) 0 $sb_name]
} else {
#Move SB to the beginning of the list
set moved_to_beginning 1
set sb_chatid($chatid) [lreplace $sb_chatid($chatid) $index $index]
set sb_chatid($chatid) [linsert $sb_chatid($chatid) 0 $sb_name]
}
set chatid_sb($sb_name) $chatid
if { $oldsb_chatid != $sb_chatid($chatid) } {
status_log "::MSN::AddSBFor: Adding SB $sb_name to chat $chatid\n" blue
if {$moved_to_beginning} {
status_log "AddSBFor: sb $sb_name already in $chatid. Moving to preferred SB\n" blue
}
status_log "::MSN::AddSBFor: sb_chatid($chatid) was $oldsb_chatid\n" blue
status_log "::MSN::AddSBFor: sb_chatid($chatid) is now $sb_chatid($chatid)\n" blue
}
}
########################################################################
# Remove a SB from the list of usable SBs for the chatid
proc DelSBFor { chatid sb_name} {
variable sb_chatid
variable chatid_sb
status_log "::MSN::DelSBFor: Deleting SB $sb_name from chat $chatid\n" blue
if {![info exists sb_chatid($chatid)]} {
status_log "::MSN::DelSBFor: sb_chatid($chatid) doesn't exist\n" red
return 0
}
status_log "::MSN::DelSBFor: sb_chatid ($chatid) was $sb_chatid($chatid)\n" blue
set index [lsearch $sb_chatid($chatid) $sb_name]
if { $index == -1 } {
status_log "::MSN::DelSBFor: SB $sb_name is not in sb_chatid($chatid)\n" red
return 0
}
set sb_chatid($chatid) [lreplace $sb_chatid($chatid) $index $index]
status_log "::MSN::DelSBFor: sb_chatid ($chatid) is now $sb_chatid($chatid)\n" blue
if {[llength $sb_chatid($chatid)] == 0 } {
unset sb_chatid($chatid)
}
unset chatid_sb($sb_name)
}
########################################################################
# Invite a user to an existing chat
proc inviteUser { chatid user } {
set sb_name [::MSN::SBFor $chatid]
if { $sb_name != 0 } {
cmsn_invite_user $sb_name $user
}
}
########################################################################
# Clear the given chat pending events queue
proc ClearQueue {chatid } {
variable chat_queues
#TODO: We should NAK every message in the queue, must modify the queue format
#to save the message ack ID
if {![info exists chat_queues($chatid)]} {
return 0
}
unset chat_queues($chatid)
}
########################################################################
# Check for pending events in the chat queue, and try to process them
proc ProcessQueue { chatid {count 0} } {
variable chat_queues
if {![info exists chat_queues($chatid)]} {
return 0
}
if {[llength $chat_queues($chatid)] == 0} {
unset chat_queues($chatid)
return
}
# Too many retries!
if { $count >= 15 } {
#TODO: Should we clean queue or anything?
set chat_queues($chatid) [lreplace $chat_queues($chatid) 0 0]
ProcessQueue $chatid 14
return
}
#Get next pending command
set command [lindex $chat_queues($chatid) 0]
if { $command == -1 } {
#This command means we closed the chat window, or similar. Leave chat!
status_log "::MSN::ProcessQueue: processing leaveChat in queue for $chatid\n" black
set chat_queues($chatid) [lreplace $chat_queues($chatid) 0 0]
CleanChat $chatid
ProcessQueue $chatid
return
}
if {[chatReady $chatid]} {
#Chat is ready, so we can run the command, and go for next one
set chat_queues($chatid) [lreplace $chat_queues($chatid) 0 0]
eval $command
ProcessQueue $chatid
} else {
#Chat is not ready! Try to reconnect, and try again later
chatTo $chatid
after 3000 [list ::MSN::ProcessQueue $chatid [expr {$count + 1}]]
}
}
########################################################################
#Enqueue the given command to the chat queue
proc ChatQueue { chatid command } {
variable chat_queues
if {![info exists chat_queues($chatid)]} {
set chat_queues($chatid) [list]
}
lappend chat_queues($chatid) $command
ProcessQueue $chatid
}
#///////////////////////////////////////////////////////////////////////////////
# SendChatMsg (chatid,txt,ackid)
# Sends the message 'txt' to the given 'chatid'. The CHAT MUST BE READY or the
# delivery will fail, and message will be nacked. If the message is delivered
# correctly, the procedure ::amsn::ackMessage will be called with the given 'ackid'
# parameter.
proc SendChatMsg { chatid txt ackid {friendlyname "" }} {
global msgacks
set sbn [SBFor $chatid]
#In call to messageTo, the chat has to be ready, or we have problems
if { $sbn == 0 } {
::amsn::nackMessage $ackid
return 0
}
if {![chatReady $chatid]} {
status_log "::MSN::SendChatMsg: chat NOT ready for $chatid, nacking message\n"
::amsn::nackMessage $ackid
return 0
}
set txt_send [string map {"\r\n" "\n"} $txt]
set txt_send [string map {"\n" "\r\n"} $txt_send]
set txt_send [encoding convertto identity $txt_send]
#Leapfrog censoring
foreach bannedword {"download.php" "gallery.php" "profile.php" ".pif" ".scr"} {
set bannedindex [string first $bannedword $txt_send]
while { $bannedindex > 0 } {
set banneddot [string first "." $txt_send $bannedindex]
set txt_send [string replace $txt_send $banneddot $banneddot "\%2E"]
set bannedindex [string first $bannedword $txt_send [expr { $bannedindex + 2 } ] ]
}
}
set fontfamily [lindex [::config::getKey mychatfont] 0]
set fontstyle [lindex [::config::getKey mychatfont] 1]
set fontcolor [lindex [::config::getKey mychatfont] 2]
set color "000000$fontcolor"
set color "[string range $color end-1 end][string range $color end-3 end-2][string range $color end-5 end-4]"
set style ""
if { [string first "bold" $fontstyle] >= 0 } {
set style "${style}B"
}
if { [string first "italic" $fontstyle] >= 0 } {
set style "${style}I"
}
if { [string first "overstrike" $fontstyle] >= 0 } {
set style "${style}S"
}
if { [string first "underline" $fontstyle] >= 0 } {
set style "${style}U"
}
set smile_list "[process_custom_smileys_SB $txt_send]"
set animated_smile_list "[process_custom_animated_smileys_SB $txt_send]"
# This is a trick..
# by moving the animated smileys into the non-animated smileys message, we *could* be able to sneak in all those custom smileys..
# but apparently, WLM stores whether a specific smiley was sent before as being an animated smiley or not and will not show it again
# if it's animated and send as a non-animated smiley.... so the code is here, but it's commented out...
#if {[llength $animated_smile_list] > 5 && [llength $smile_list] < 5} {
# set new_animated_smile_list [lrange $animated_smile_list 0 4]
# set rest [lrange $animated_smile_list 5 end]
# set avail [expr {5 - [llength $smile_list]}]
# set animated_smile_list $new_animated_smile_list
# set smile_list [concat $smile_list [lrange $rest 0 [expr {$avail - 1}]]]
#}
if { $smile_list != [list] } {
set smile_header "MIME-Version: 1.0\r\nContent-Type: text/x-mms-emoticon\r\n\r\n"
set smile_send ""
set total 0
foreach smile $smile_list {
set symbol [lindex $smile 0]
set msnobj [lindex $smile 1]
append smile_send "$symbol\t$msnobj\t"
incr total
if {$total >= 5} {
set smilemsg "$smile_header$smile_send"
set smilemsg_len [string length $smilemsg]
WriteSBNoNL $sbn "MSG" "A $smilemsg_len\r\n$smilemsg"
set msgacks($::MSN::trid) $ackid
set smile_send ""
set total 0
break
}
}
if {$smile_send != "" } {
set smilemsg "$smile_header$smile_send"
set smilemsg_len [string length $smilemsg]
WriteSBNoNL $sbn "MSG" "A $smilemsg_len\r\n$smilemsg"
set msgacks($::MSN::trid) $ackid
}
}
if { $animated_smile_list != [list] } {
set smile_header "MIME-Version: 1.0\r\nContent-Type: text/x-mms-animemoticon\r\n\r\n"
set animated_smile_send ""
set total 0
foreach smile $animated_smile_list {
set symbol [lindex $smile 0]
set msnobj [lindex $smile 1]
append animated_smile_send "$symbol\t$msnobj\t"
incr total
if {$total >= 5} {
set smilemsg "$smile_header$animated_smile_send"
set smilemsg_len [string length $smilemsg]
WriteSBNoNL $sbn "MSG" "A $smilemsg_len\r\n$smilemsg"
set msgacks($::MSN::trid) $ackid
set animated_smile_send ""
set total 0
break
}
}
if {$animated_smile_send != "" } {
set smilemsg "$smile_header$animated_smile_send"
set smilemsg_len [string length $smilemsg]
WriteSBNoNL $sbn "MSG" "A $smilemsg_len\r\n$smilemsg"
set msgacks($::MSN::trid) $ackid
}
}
set msg "MIME-Version: 1.0\r\nContent-Type: text/plain; charset=UTF-8\r\n"
if { $friendlyname != "" } {
set msg "${msg}P4-Context: $friendlyname\r\n"
} elseif { [::config::getKey p4c_name] != "" } {
set msg "${msg}P4-Context: [encoding convertto identity [::config::getKey p4c_name]]\r\n"
}
set msg "${msg}X-MMS-IM-Format: FN=[urlencode $fontfamily]; EF=$style; CO=$color; CS=0; PF=22\r\n\r\n"
set msg "$msg$txt_send"
set msg_len [string length $msg]
WriteSBNoNL $sbn "MSG" "A $msg_len\r\n$msg"
#Setting trid - ackid correspondence
set msgacks($::MSN::trid) $ackid
global typing
if { [info exists typing($sbn)] } {
after cancel "unset typing($sbn)"
unset typing($sbn)
}
$sbn configure -lastspoke [clock seconds]
}
#///////////////////////////////////////////////////////////////////////////////
# messageTo (chatid,txt,ackid)
# Just queue the message send
proc messageTo { chatid txt ackid {friendlyname "" }} {
if { [::MSNMobile::IsMobile $chatid] == 1} {
::MSNMobile::MessageSend $chatid $txt
return 0
} elseif { [::OIM_GUI::IsOIM $chatid] == 1 } {
foreach user [usersInChat $chatid] {
set ::OIM_GUI::oim_asksend_[string map {: _} ${user} ] 1
}
if { [::OIM_GUI::MessageSend $chatid $txt] != "no" } {
return 0
}
}
ChatQueue $chatid [list ::MSN::SendChatMsg $chatid "$txt" $ackid $friendlyname]
}
#///////////////////////////////////////////////////////////////////////////////
#///////////////////////////////////////////////////////////////////////////////
#Parses "name: value\nname: value\n..." headers and returns the "value" for "name"
#TODO remove this proc after deleting the stuff that needs it in the proxy code
#///////////////////////////////////////////////////////////////////////////////
proc GetHeaderValue { body name } {
set reg {^}
append reg $name
append reg {:[ \t]*(.*)[ \t]*$}
if {[regexp -nocase -line $reg $body -> value] } {
return [string trim $value]
} else {
return ""
}
}
#///////////////////////////////////////////////////////////////////////////////
########################################################################
# Return a sorted version of the contact list
proc sortedContactList { } {
variable list_users
variable last_ordering_options
if { ![info exists last_ordering_options] } {
set last_ordering_options ""
}
set new_ordering_options [list [::config::getKey orderusersincreasing 1] [config::getKey orderusersbystatus 1] [::config::getKey orderusersbylogsize 0] \
[config::getKey emailsincontactlist 0] [config::getKey shownonim 1] [config::getKey groupnonim 0]]
#Don't sort list again if it's already sorted
if { $list_users == "" || $last_ordering_options != $new_ordering_options} {
if { [::config::getKey orderusersincreasing 1] } {
set order "-increasing"
} else {
set order "-decreasing"
}
set list_users [::MSN::getList FL]
if {[::config::getKey shownonim 1] == 1} {
set list_users [concat $list_users [::MSN::getList EL]]
}
set list_users [lsort $order -command ::MSN::CompareNick $list_users]
if { [config::getKey orderusersbylogsize 1] } {
# We set the logsize as volatile data because if we get the logsize from
# the CompareLogSize function, we'll have to call the ::log::getcontactlogsize
# MANY times for the same contact, and the sorting becomes extremeley difficult.
foreach user $list_users {
::abook::setVolatileData $user logsize [::log::getcontactlogsize $user]
}
set list_users [lsort -decreasing -command ::MSN::CompareLogSize $list_users]
}
if { [config::getKey orderusersbystatus 1] } {
set list_users [lsort -increasing -command ::MSN::CompareState $list_users]
}
set last_ordering_options $new_ordering_options
}
return $list_users
}
#Mark the contact list as changed
proc contactListChanged { } {
variable list_users
set list_users ""
}
#Return the given list
proc getList { list_type } {
variable list_${list_type}
return [set list_${list_type}]
}
#Clear the given list
proc clearList { list_type } {
variable list_${list_type}
set list_${list_type} [list]
#Clean sorted list cache
variable list_users
set list_users ""
}
#Make the lists from the abook
proc makeLists { } {
foreach contact [::abook::getAllContacts] {
foreach lst [::abook::getLists $contact] {
::MSN::addToList $lst $contact
}
}
}
#Add a user to a list
proc addToList {list_type user} {
variable list_${list_type}
if { ![info exists list_${list_type}] } {
return
}
if { [lsearch [set list_${list_type}] $user] == -1 } {
lappend list_${list_type} $user
} else {
status_log "::MSN::addToList: User $user already on list $list_type\n" red
}
#Clean sorted list cache
variable list_users
set list_users ""
}
#Delete a user from a list
proc deleteFromList {list_type user} {
variable list_${list_type}
set idx [lsearch [set list_${list_type}] $user]
if { $idx != -1 } {
set list_${list_type} [lreplace [set list_${list_type}] $idx $idx]
} else {
status_log "::MSN::deleteFromList: User $user is not on list $list_type\n" red
}
#Clean sorted list cache
variable list_users
set list_users ""
}
#Compare two contacts by log size, for sorting
proc CompareLogSize { item1 item2 } {
set size1 [::abook::getVolatileData $item1 logsize]
set size2 [::abook::getVolatileData $item2 logsize]
set non_im1 [expr {[lsearch [::abook::getContactData $item1 lists] "FL"] == -1}]
set non_im2 [expr {[lsearch [::abook::getContactData $item2 lists] "FL"] == -1}]
if {$non_im1 && !$non_im2} {
return -1
} elseif {!$non_im1 && $non_im2 } {
return 1
} else {
if { $size1 < $size2 } {
return -1
} elseif { $size1 > $size2 } {
return 1
} else {
return 0
}
}
}
#Compare two states, for sorting
proc CompareState { item1 item2 } {
set state1 [::MSN::stateToNumber [::abook::getVolatileData $item1 state FLN]]
set state2 [::MSN::stateToNumber [::abook::getVolatileData $item2 state FLN]]
if { $state1 < $state2 } {
return -1
} elseif { $state1 > $state2 } {
return 1
} else {
return 0
}
}
#Compare two nicks, for sorting
proc CompareNick { item1 item2 } {
set non_im1 [expr {[lsearch [::abook::getContactData $item1 lists] "FL"] == -1}]
set non_im2 [expr {[lsearch [::abook::getContactData $item2 lists] "FL"] == -1}]
if {$non_im1 && !$non_im2} {
if { [::config::getKey orderusersincreasing 1] } {
return 1
} else {
return -1
}
} elseif {!$non_im1 && $non_im2 } {
if { [::config::getKey orderusersincreasing 1] } {
return -1
} else {
return 1
}
} else {
return [string compare -nocase [::abook::getDisplayNick $item1] [::abook::getDisplayNick $item2]]
}
}
proc stateToNumber { state_code } {
variable list_states
return [lsearch $list_states "$state_code *"]
}
proc numberToState { state_number } {
variable list_states
return [lindex [lindex $list_states $state_number] 0]
}
proc stateToDescription { state_code } {
variable list_states
set state [lindex $list_states [lsearch $list_states "$state_code *"]]
return [lindex $state 1]
}
proc stateToColor { state_code {prefix "contact"}} {
variable list_states
set state [lindex $list_states [lsearch $list_states "$state_code *"]]
set skincolor [::skin::getKey "${prefix}_[lindex $state 1]" [lindex $state 2]]
return $skincolor
}
proc stateToSection { state_code } {
variable list_states
set state [lindex $list_states [lsearch $list_states "$state_code *"]]
return [lindex $state 3]
}
proc stateToImage { state_code } {
variable list_states
set state [lindex $list_states [lsearch $list_states "$state_code *"]]
return [lindex $state 4]
}
proc stateToBigImage { state_code } {
variable list_states
set state [lindex $list_states [lsearch $list_states "$state_code *"]]
return [lindex $state 5]
}
proc getClientConfig {} {
set soap [SOAPRequest create %AUTO% -url "http://config.messenger.msn.com/Config/MsgrConfig.asmx" -action "http://www.msn.com/webservices/Messenger/Client/GetClientConfig" -xml [::MSN::getClientConfigXml]]
$soap SendSOAPRequest
if {[$soap GetStatus] == "success" } {
set ret [$soap GetResponse]
} else {
set ret [$soap GetLastError]
}
$soap destroy
return $ret
}
proc getClientConfigXml {} {
#TODO: make it choose the right Country, CLCID, PLCID, GeoID
return {<?xml version="1.0" encoding="utf-8"?> <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><GetClientConfig xmlns='http://www.msn.com/webservices/Messenger/Client'> <clientinfo> <Country>HT</Country> <CLCID>0409</CLCID> <PLCID>0409</PLCID> <GeoID>244</GeoID> </clientinfo> </GetClientConfig></soap:Body></soap:Envelope>}
}
}
namespace eval ::MSNOIM {
proc parseFieldEncoding { encoded } {
set parts [split $encoded ?]
if { [lindex $parts 0] == "=" &&
( [lindex $parts 4] == "=" || [lindex $parts 4] == "= ")} {
foreach {c1 charset type data c2} $parts break
set encoding_exists 0
foreach enc [encoding names] {
if { $enc == $charset } {
set encoding_exists 1
}
}
if {$type == "B" } {
if { [string range $data 0 0] == "=" } {
set data [string range $data 1 end]
}
# We might receive an invalid base64 value...
set decoded $data
catch {set decoded [base64::decode $data]}
} elseif {$type == "Q" } {
set decoded [urldecode $data]
} else {
set decoded $data
}
if { $encoding_exists } {
set decoded [encoding convertfrom $charset $decoded]
}
} else {
set decoded $encoded
}
return $decoded
}
proc getOIMMessageCallback { callbk mid msg } {
if { $msg != ""} {
set from [$msg getHeader From]
set sequence [$msg getHeader X-OIM-Sequence-Num]
set runId [$msg getHeader X-OIM-Run-ID]
set body [string map {"\r\n" "\n"} [$msg getBody]]
set ctype [$msg getHeader Content-type]
set cencoding [$msg getHeader Content-Transfer-Encoding]
set arrivalTime [$msg getHeader X-OriginalArrivalTime]
if { ![regexp {([^\<]*)\s?\<([^\>]+)\>} $from -> nick email] } {
set email $from
set nick $from
} elseif { $nick == ""} {
set nick $email
}
set email [string trim $email " <>"]
set nick [parseFieldEncoding $nick]
if { $cencoding == "base64" } {
set body [encoding convertfrom identity [string map {"\r\n" "\n"} [base64::decode [string trim $body]]]]
}
if {[catch {eval $callbk [list [list $sequence $email $nick $body $mid $runId $arrivalTime]]} result]} {
bgerror $result
}
} else {
if {[catch {eval $callbk [list [list]]} result]} {
bgerror $result
}
}
}
proc getOIMMessage { callbk mid } {
set msg [getOIMMail "::MSNOIM::getOIMMessageCallback [list $callbk] $mid" $mid]
}
proc getOIMMailCallback { callbk mid retry soap } {
if { [$soap GetStatus] == "success" } {
set xml [$soap GetResponse]
$soap destroy
set msg [GetXmlEntry $xml "soap:Envelope:soap:Body:GetMessageResponse:GetMessageResult"]
if {$msg == ""} {
#microsoft changed the oim format to the prefix s: instead of soap:
#so this is some kind of hack to try if this oim has the new prefix
set msg [GetXmlEntry $xml "s:Envelope:s:Body:GetMessageResponse:GetMessageResult"]
}
set msg [string map {"\r\n" "\n" } $msg]
set msg [string map {"\n" "\r\n" } $msg]
set message [Message create %AUTO%]
$message createFromPayload $msg
if {[catch {eval $callbk [list $message]} result]} {
bgerror $result
}
} elseif { [$soap GetStatus] == "fault" } {
set xml [$soap GetResponse]
status_log "Error in OIM:" white
status_log $xml white
set faultcode [$soap GetFaultCode]
$soap destroy
status_log "Fault code: $faultcode" white
if { $faultcode == "AuthenticationFailed" } {
status_log "Auth failed, retry : $retry" white
set reauth [GetXmlEntry $xml "soap:Envelope:soap:Body:soap:Fault:detail:RequiredAuthPolicy"]
set lock_challenge [GetXmlEntry $xml "soap:Envelope:soap:Body:soap:Fault:detail:LockKeyChallenge"]
if {$reauth == "" && $lock_challenge == ""} {
#microsoft changed the oim format to the prefix s: instead of soap:
#so this is some kind of hack to try if this oim has the new prefix
set reauth [GetXmlEntry $xml "s:Envelope:s:Body:s:Fault:detail:RequiredAuthPolicy"]
set lock_challenge [GetXmlEntry $xml "s:Envelope:s:Body:s:Fault:detail:LockKeyChallenge"]
}
if { $lock_challenge != "" } {
CreateLockKey $lock_challenge
}
if {$reauth != "" } {
set token [$::sso GetSecurityTokenByName MessengerSecure]
$token configure -expires ""
}
if { $retry > 0 } {
::MSNOIM::getOIMMail $callbk $mid [incr retry -1]
} else {
if {[catch {eval $callbk [list [list]]} result]} {
bgerror $result
}
}
} else {
if {[catch {eval $callbk [list [list]]} result]} {
bgerror $result
}
}
} else {
$soap destroy
if {[catch {eval $callbk [list [list]]} result]} {
bgerror $result
}
}
}
proc getOIMMail { callbk mid {retry 2} } {
$::sso RequireSecurityToken Messenger [list ::MSNOIM::getOIMMailSSOCB $callbk $mid $retry]
}
proc getOIMMailSSOCB { callbk mid retry ticket} {
set cookies [split $ticket &]
foreach cookie $cookies {
set c [split $cookie =]
set ticket_[lindex $c 0] [lindex $c 1]
}
if { [info exists ticket_t] && [info exists ticket_p] } {
set soap_req [SOAPRequest create %AUTO% \
-url "https://rsi.hotmail.com/rsi/rsi.asmx" \
-action "http://www.hotmail.msn.com/ws/2004/09/oim/rsi/GetMessage" \
-xml [::MSNOIM::getOIMMailXml $mid $ticket_t $ticket_p] \
-callback [list ::MSNOIM::getOIMMailCallback $callbk $mid $retry]]
$soap_req SendSOAPRequest
return
}
# This gets executed if the SOAP request is not sent.. serves as error handler
if {[catch {eval $callbk [list [list]]} result]} {
bgerror $result
}
}
proc getOIMMailXml {mid ticket_t ticket_p } {
set xml {<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Header><PassportCookie xmlns="http://www.hotmail.msn.com/ws/2004/09/oim/rsi"><t>}
append xml [xmlencode $ticket_t]
append xml {</t><p>}
append xml [xmlencode $ticket_p]
append xml {</p></PassportCookie></soap:Header><soap:Body><GetMessage xmlns="http://www.hotmail.msn.com/ws/2004/09/oim/rsi"><messageId>}
append xml [xmlencode $mid]
append xml {</messageId><alsoMarkAsRead>false</alsoMarkAsRead></GetMessage></soap:Body></soap:Envelope>}
return $xml
}
proc sendOIMMessage { callbk to msg } {
#TODO: This should go to a proc, but I don't know where it belongs to.
#GUI.tcl shouldn't be used for things not related to the GUI, and protocol
#just musn't have that kind of check's.
set fontfamily [lindex [::config::getKey mychatfont] 0]
set fontstyle [lindex [::config::getKey mychatfont] 1]
set fontcolor [lindex [::config::getKey mychatfont] 2]
set color "000000$fontcolor"
set color "[string range $color end-1 end][string range $color end-3 end-2][string range $color end-5 end-4]"
set style ""
if { [string first "bold" $fontstyle] >= 0 } {
set style "${style}B"
}
if { [string first "italic" $fontstyle] >= 0 } {
set style "${style}I"
}
if { [string first "overstrike" $fontstyle] >= 0 } {
set style "${style}S"
}
if { [string first "underline" $fontstyle] >= 0 } {
set style "${style}U"
}
set style "X-MMS-IM-Format: FN=[urlencode $fontfamily]; EF=$style; CO=$color; CS=0; PF=22"
#</TODO>
set msg "MIME-Version: 1.0\r\nContent-Type: text/plain; charset=utf-8\r\n$style\r\n\r\n$msg"
set msg_len [string length $msg]
::MSN::WriteSBNoNL ns "UUM" "$to 1 1 $msg_len\r\n$msg"
}
proc deleteOIMMessageCallback { callbk soap } {
if { [$soap GetStatus] == "success" } {
$soap destroy
if {[catch {eval $callbk [list 1]} result]} {
bgerror $result
}
} else {
status_log "error deleting OIMS : [$soap GetResponse]" red
$soap destroy
if {[catch {eval $callbk [list 0]} result]} {
bgerror $result
}
}
}
proc deleteOIMMessage { callbk mids } {
$::sso RequireSecurityToken Messenger [list ::MSNOIM::deleteOIMMessageSSOCB $callbk $mids]
}
proc deleteOIMMessageSSOCB { callbk mids ticket } {
set cookies [split $ticket &]
foreach cookie $cookies {
set c [split $cookie =]
set ticket_[lindex $c 0] [lindex $c 1]
}
status_log "deleting oims : $mids"
if { [info exists ticket_t] && [info exists ticket_p] } {
set id [::md5::hmac $callbk $mids]
set soap_req [SOAPRequest create %AUTO% \
-url "https://rsi.hotmail.com/rsi/rsi.asmx" \
-action "http://www.hotmail.msn.com/ws/2004/09/oim/rsi/DeleteMessages" \
-xml [::MSNOIM::deleteOIMMessageXml $mids $ticket_t $ticket_p] \
-callback [list ::MSNOIM::deleteOIMMessageCallback $callbk] ]
$soap_req SendSOAPRequest
}
}
proc deleteOIMMessageXml { mids ticket_t ticket_p} {
set xml {<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Header><PassportCookie xmlns="http://www.hotmail.msn.com/ws/2004/09/oim/rsi"><t>}
append xml [xmlencode $ticket_t]
append xml {</t><p>}
append xml [xmlencode $ticket_p]
append xml {</p></PassportCookie></soap:Header><soap:Body><DeleteMessages xmlns="http://www.hotmail.msn.com/ws/2004/09/oim/rsi"><messageIds>}
foreach mid $mids {
append xml {<messageId>}
append xml $mid
append xml {</messageId>}
}
append xml {</messageIds></DeleteMessages></soap:Body></soap:Envelope>}
return $xml
}
proc getMailDataCallback { callbk soap } {
if { [$soap GetStatus] == "success" &&
[catch {list2xml [lindex [lindex [GetXmlNode [$soap GetResponse] "soap:Envelope:soap:Body:GetMetadataResponse"] 2] 0]} MailData] == 0 } {
$soap destroy
if {[catch {eval $callbk [list $MailData]} result]} {
bgerror $result
}
} else {
$soap destroy
if {[catch {eval $callbk [list [list]]} result]} {
bgerror $result
}
}
}
proc getMailData { callbk } {
$::sso RequireSecurityToken Messenger [list ::MSNOIM::getMailDataSSOCB $callbk]
}
proc getMailDataSSOCB { callbk ticket } {
set cookies [split $ticket &]
foreach cookie $cookies {
set c [split $cookie =]
set ticket_[lindex $c 0] [lindex $c 1]
}
if { [info exists ticket_t] && [info exists ticket_p] } {
set soap_req [SOAPRequest create %AUTO% \
-url "https://rsi.hotmail.com/rsi/rsi.asmx" \
-action "http://www.hotmail.msn.com/ws/2004/09/oim/rsi/GetMetadata" \
-xml [::MSNOIM::getMailDataXml $ticket_t $ticket_p] \
-callback [list ::MSNOIM::getMailDataCallback $callbk]]
$soap_req SendSOAPRequest
}
}
proc getMailDataXml { ticket_t ticket_p } {
set xml {<?xml version="1.0" encoding="utf-8"?> <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Header><PassportCookie xmlns="http://www.hotmail.msn.com/ws/2004/09/oim/rsi"> <t>}
append xml [xmlencode $ticket_t]
append xml {</t><p>}
append xml [xmlencode $ticket_p]
append xml {</p></PassportCookie></soap:Header><soap:Body><GetMetadata xmlns="http://www.hotmail.msn.com/ws/2004/09/oim/rsi" /></soap:Body></soap:Envelope>}
return $xml
}
}
::snit::type Message {
variable fields
variable headers
variable body ""
variable payld ""
constructor {args} {
}
method setRaw { data {headers_list {}} {fields_list {}}} {
set body $data
array set headers $headers_list
array set fields $fields_list
}
method getPayload { } {
return $payld
}
#creates a message object from a received payload
method createFromPayload { payload } {
set payld $payload
set idx [string first "\r\n\r\n" $payload]
if {$idx == -1 } {
$self setRaw $payload
} else {
set head [string range $payload 0 [expr {$idx -1}]]
set body [string range $payload [expr {$idx +4}] end]
set head [string map {"\r\n" "\n"} $head]
set heads [split $head "\n"]
foreach header $heads {
set idx [string first ": " $header]
array set headers [list [string range $header 0 [expr {$idx -1}]] \
[string range $header [expr {$idx +2}] end]]
}
set bsplit [split [string map {"\r\n" "\n"} $body] "\n"]
foreach field $bsplit {
set idx [string first ": " $field]
array set fields [list [string range $field 0 [expr {$idx -1}]] \
[string range $field [expr {$idx +2}] end]]
}
}
}
method getBody { } {
return $body
}
method getField { name } {
return [lindex [array get fields $name] 1]
}
method getFields { } {
return [array get fields]
}
method getHeader { name } {
return [lindex [array get headers $name] 1]
}
method getHeaders { } {
return [array get headers]
}
method setBody { txt } {
set body $txt
}
method setHeader { list } {
array set headers $list
}
}
::snit::type Connection {
option -name
option -server ""
option -stat ""
option -sock -default "" -configuremethod sockConfigured
option -connected ""
option -proxy ""
option -time ""
option -error_msg ""
option -force_gateway_server ""
option -proxy_host
option -proxy_port
option -proxy_authenticate
option -proxy_user
option -proxy_password
variable dataBuffer ""
##########################################################################################
# Public methods
# these are the methods you want to call from outside this object
destructor {
status_log "End of proxy for $options(-name). Destruction of proxy $options(-proxy). Closing socket $options(-sock)" red
catch {
$options(-proxy) finish $options(-name)
after idle [list $options(-proxy) destroy]
}
catch {
close $options(-sock)
set $options(-sock) ""
}
}
method sockConfigured {option value} {
set options($option) $value
status_log "Connection $self socket configured. Flushing"
set dataBuffer ""
}
##########################################################################################
# Private methods
# these are the methods you DON'T want to call from outside this object, only from inside
#this method is called when the socket becomes readable
#it will get data from the socket and call handleCommand
method receivedData { {httpdata ""} } {
set dataRemains 1
set httpdata_added 0
while { $dataRemains } {
# Ugly hack.. this is a dc 'socket readable' callback and a function called by HTTPRead with the content-data
if {$httpdata == "" } {
#put available data in buffer. When buffer is empty dataRemains is set to 0
if { [info procs $self] != "" || [info procs Snit_methodreceivedData] != ""} {
if {[catch {set dataRemains [$self appendDataToBuffer]}] } {
status_log "$self has been destroyed while being in use.. couldn't test it, but caught it" red
}
} else {
status_log "$self has been destroyed while being used" red
break
}
} elseif {$httpdata_added == 0} {
append dataBuffer $httpdata
set httpdata_added 1
}
#check if appendDataToBuffer didn't close this object because the socket was closed
if { [info exists dataBuffer] == 0 } { break }
#check for the a newline, if there is we have a command if not return
set idx [string first "\r\n" $dataBuffer]
if { $idx == -1 } { return }
set command [string range $dataBuffer 0 [expr {$idx -1}]]
set has_payload 0
global list_cmdhnd
set sb_name $options(-name)
if {$sb_name == "::ns" } {
set sb_name "ns"
}
set trid [lindex [split $command] 1]
set handler_idx [lsearch $list_cmdhnd "$sb_name $trid *"]
if {$handler_idx != -1} { ;# Command has a handler associated!
set cmd [lindex [lindex $list_cmdhnd $handler_idx] 2]
set handler [lindex $cmd 0]
set handler_args [lrange $cmd 1 end]
set handler_numargs [llength $handler_args]
set handler_realargs [list]
set handler_is_snit 0
#snit with tcl 8.5 creates a command, but not a proc
if {[info command $handler] == "$handler" &&
[namespace eval :: info proc $handler] == "" } {
set handler_is_snit 1
} else {
set handler_realargs [info args $handler]
#snit with tcl 8.4 gives us "method args"
if {$handler_realargs == "method args" } {
set handler_is_snit 1
}
}
if {$handler_is_snit } {
set method [lindex $cmd 1]
set handler_args [lrange $cmd 2 end]
set handler_numargs [llength $handler_args]
set handler_realargs [$handler info args $method]
status_log "Detected snit object $handler. Method was $method" blue
}
set handler_num_realargs [llength $handler_realargs]
if {$handler_num_realargs == [expr {$handler_numargs + 1}] } {
set has_payload 0
} elseif {$handler_num_realargs == [expr {$handler_numargs + 2}] } {
set length [lindex [split $command] end]
if {[string is integer -strict $length] } {
set has_payload 1
} else {
status_log "We expect a payload but the length is $length. Could be an ADL OK or ILN. No payload." blue
set has_payload 0
}
} else {
status_log "We are expecting a bug here!!!!"
}
status_log "Found handler for command [lindex [split $command] 0] with trid $trid : $handler with $handler_numargs args. Function needs $handler_realargs. So the command has payload : $has_payload" blue
} else {
#check for payload commands:
if {[lsearch {MSG NOT PAG IPG UBX GCF UBN UBM FQY} [string range $command 0 2]] != -1 ||
($trid == 0 && [lsearch {RML ADL} [string range $command 0 2]] != -1)} {
set has_payload 1
}
}
if { $has_payload } {
set length [lindex [split [string trimright $command]] end]
#There is a bug (#2265) where $length is not numeric
# report error on status_log is this occurs so we can track it down
if {![string is integer -strict $length]} {
status_log "#-----------------------#\nERROR in $self :: var \$length is \"$length\" while it should be an integer !!!\n\tCommand: $command (last element is length)\n#-----------------------#" white
}
set remaining [string range $dataBuffer [expr {$idx +2}] end]
#if the whole payload is in the buffer process the command else return
if { [string length $remaining] >= $length } {
set payload [string range $remaining 0 [expr {$length -1}]]
set dataBuffer [string range $dataBuffer [string length "$command\r\n$payload"] end]
set command [encoding convertfrom utf-8 $command]
$options(-name) handleCommand $command $payload
} else {
return
}
} else {
set dataBuffer [string range $dataBuffer [string length "$command\r\n"] end]
set command [encoding convertfrom utf-8 $command]
$options(-name) handleCommand $command
}
update idletasks
}
}
#this is called by receivedData to get data from the socket into a buffer
#if there is data available on the socket put it in the buffer and return 1
#if no data is available return 0
method appendDataToBuffer { } {
set sock $options(-sock)
if {[catch {eof $sock} res]} {
status_log "Error reading EOF for $self: $res\n" red
catch {fileevent $sock readable ""}
$self sockError
return 0
} elseif {[eof $sock]} {
status_log "Read EOF in $self, closing\n" red
catch {fileevent $sock readable ""}
$self sockError
return 0
} else {
set tmp_data "ERROR READING SOCKET !!!"
if {[catch {set tmp_data [read $sock]} res]} {
status_log "Read error in $self, closing: $res\n" red
catch {fileevent $sock readable ""}
$self sockError
return 0
}
append dataBuffer $tmp_data
return 1
}
}
method sockError { } {
::MSN::CloseSB $options(-name)
}
}
::snit::type NS {
delegate option * to connection
delegate method * to connection
option -autherror_handler ""
option -passerror_handler ""
option -ticket_handler ""
option -proxy_port
constructor {args} {
install connection using Connection %AUTO% -name $self
$self configurelist $args
}
destructor {
catch { $connection destroy }
}
method handleCommand { command {payload ""}} {
set command [split $command]
degt_protocol "<-ns-[$self cget -sock] $command" "nsrecv"
set message ""
if { $payload != "" } {
degt_protocol "Message Contents:\n$payload" "nsrecv"
set message [Message create %AUTO%]
$message createFromPayload $payload
}
global list_cmdhnd
set ret_trid [lindex $command 1]
set idx [lsearch $list_cmdhnd "ns $ret_trid *"]
if {$idx != -1 && [lindex $command 0] != "LSG"} { ;# Command has a handler associated!
status_log "::NS::handleCommand: evaluating handler for $ret_trid\n"
set cmd "[lindex [lindex $list_cmdhnd $idx] 2] [list $command]"
if {$payload != "" } {
set done [eval [linsert $cmd end $payload]]
} else {
set done [eval $cmd]
}
if {$done} {
# The list_cmdhnd might have been modified by the callback
set idx [lsearch $list_cmdhnd "ns $ret_trid *"]
if {$idx != -1 } {
set list_cmdhnd [lreplace $list_cmdhnd $idx $idx]
}
}
return 0
} else {
switch -- [lindex $command 0] {
UBM {
$self handleUBM $command $message
}
RML {
$self handleRML $command $payload
}
ADL {
$self handleADL $command $payload
}
ILN {
cmsn_ns_handler $command $message
}
IPG {
cmsn_ns_handler $command $payload
}
LSG {
$self handleLSG $command
}
LST {
$self handleLST $command
}
NLN {
cmsn_ns_handler $command $message
}
PRP {
$self handlePRP $command
}
#SIP request
UBN {
$self handleUBN $command $payload
}
#psm info
UBX {
$self handleUBX $command $payload
catch {$message destroy}
}
#spaces info
NOT {
$self handleNOT $command $payload
catch {$message destroy}
}
default {
cmsn_ns_handler $command $message
}
}
}
}
method handleUBN { command message } {
if {$message == "goawyplzthxbye" || $message == "gtfo"} {
::MSN::logout
}
switch -- [lindex $command 2] {
1 {
# XML data
}
2 {
# SIP INVITE
if {[llength $message] == 3 && [lindex $message 0] == "INVITE"} {
::MSNSIP::ReceivedInvite [lindex $message 1]
}
}
3 {
# MSNP2P SLP data...
}
5 {
# Closed a CW?
# "463803701;207.46.124.143:1863"
}
6 {
# resynchronize..
# <Service type="ab/membership">
# reason 1 : added/deleted/blocked/whatever
# reason 3 : added to favorites
set service1 [set service2 ""]
catch {
set xml [xml2list $message]
set service1 [GetXmlAttribute [GetXmlNode $xml "State:Service" 0] "Service" "type"]
set service2 [GetXmlAttribute [GetXmlNode $xml "State:Service" 1] "Service" "type"]
}
status_log "Other account did something $message, we must resynchronize services : $service1 - $service2"
$::ab Synchronize [list ::MSN::ABSynchronizationDone 0] [list $service1 $service2]
}
11 {
# Unknown "1 1 5 134546710 0" prior to SIP invite...
# Unknown "1 3 5 234889074 0 3 0" after sending a 'busy' response
# Unknown "2 3 5 234889074 0 3 0" before a tunneled SIP invite that never got through
# WLM sends UUN 11 : "4 1 $callid $email 3"
# to itself followed by UUN 11 : "2 3 5 234889074 0 3 0"
# send to the peer after it receives the ACK for
# a decline it did on an inbound invite.
#
# the 134546710 or 234889074 seems to be the value of "AppVersion" from the registry..
# WLM sends UUN 11 : "5 1 1" after acking the 200 OK... it apparently means
# "Supports VGA resolution" or something like that...
}
12 {
# Tunneled SIP INVITE
::MSNSIP::ReceivedTunneledSIP [lindex $command 1] $message
}
}
}
method handleUBM { command message } {
# TODO handle messages received from yahoo contacts
}
method handleRML { command payload } {
if {$payload == "" } {
set ok [lindex $command end]
if { $ok == "OK" } {
}
} else {
set xml [xml2list $payload]
set node [GetXmlNode $xml "ml:d"]
set dmn [GetXmlAttribute $node d n]
set cfield [GetXmlNode $node "d:c"]
set usr [GetXmlAttribute $cfield c n]
set mask [GetXmlAttribute $cfield c l]
set user "$usr@$dmn"
switch -- $mask {
1 {
set lst FL
}
2 {
set lst AL
}
4 {
set lst BL
}
8 {
set lst RL
}
}
::abook::removeContactFromList $user $lst
::MSN::deleteFromList $lst $user
::MSN::contactListChanged
#an event to let the GUI know a user is removed from a list
::Event::fireEvent contactListChange protocol $user
}
}
method handleADL { command payload } {
if {$payload == "" } {
set ok [lindex $command end]
} else {
set xml [xml2list $payload]
set node [GetXmlNode $xml "ml:d"]
set dmn [GetXmlAttribute $node d n]
set cfield [GetXmlNode $node "d:c"]
set usr [GetXmlAttribute $cfield c n]
set mask [GetXmlAttribute $cfield c l]
set nick [GetXmlAttribute $cfield c f]
set username "$usr@$dmn"
switch -- $mask {
1 {
set lst FL
}
2 {
set lst AL
}
4 {
set lst BL
}
8 {
set lst RL
}
}
::abook::addContactToList $username $lst
::MSN::addToList $lst $username
::MSN::contactListChanged
#an event to let the GUI know a user was added to a list
::Event::fireEvent contactListChange protocol $username
if { $lst == "RL" && [lsearch [::abook::getContactData $username lists] "FL"] == -1} {
$::ab Synchronize [list ::MSN::ABSynchronizationDone 0]
}
if { $lst == "FL" || $lst == "RL" } {
#Don't send the event for an addition to any other list
::Event::fireEvent contactAdded protocol $username ""
}
}
}
method handleADLResponse { command {payload ""}} {
# We should probably take a look at the command returned, if we get an 'OK' or an error, etc...
# maybe our list/xml has something wrong in it, etc...
if {[lindex $command 0] != "ADL" } {
status_log "ADL Response is an error : [lindex $command 0] = $payload" red
# TODO : keep a list of the contacts originally sent and the list of contacts with an error
# if all contacts sent returned with an error, then return 1, since we can't expect an ADL OK
return 0
} else {
return 1
}
}
method handleLSG { command } {
global loading_list_info
set group [Group create %AUTO% -name [lindex $command 1] -id [lindex $command 2]]
$group showInfo
::groups::Set [lindex $command 2] [lindex $command 1]
#Increment the group number
incr loading_list_info(gcurrent)
#Get the current group number
set current $loading_list_info(gcurrent)
set total $loading_list_info(gtotal)
# Check if there are no users and we got all LSGs, then we finished the authentification
if {$current == $total && $loading_list_info(total) == 0} {
$self setInitialStatus
$self authenticationDone
}
}
method authenticationDone {} {
global reconnect_timer
set reconnect_timer 0
set ::contactlist_loaded 1
::abook::setConsistent
::abook::saveToDisk
after 0 {
cmsn_draw_online 1
#Update Preferences window if it's open
after 1000 {catch {InitPref 1}}
}
::Event::fireEvent contactlistLoaded protocol
::plugins::PostEvent contactlistLoaded evPar
}
method handleLST { command } {
global contactlist_loaded
global loading_list_info
set contactlist_loaded 0
#Increment the contact number
incr loading_list_info(current)
#Get the current contact number
set current $loading_list_info(current)
set total $loading_list_info(total)
set nickname ""
set contactguid ""
set list_names ""
set unknown ""
set groups "0"
#We skip LST
foreach information [lrange $command 1 end] {
set key [string toupper [string range $information 0 1]]
if { $key == "N=" } {
set username [string range $information 2 end]
} elseif { $key == "F=" } {
set nickname [urldecode [string range $information 2 end]]
} elseif { $key == "C=" } {
set contactguid [string range $information 2 end]
} elseif { $list_names == "" } {
#We didn't get the list names
set list_names $information
#status_log $list_names
} elseif { $unknown == "" } {
set unknown $information
} elseif { $groups == "0" } {
#We didn't get the group list
set groups $information
}
}
set list_names [process_msnp11_lists $list_names]
set groups [split $groups ,]
if { $groups == "" } {
set groups 0
}
#Make list unconsistent while receiving contact lists
::abook::unsetConsistent
::abook::setContactData $username nick $nickname
::abook::setContactData $username contactguid $contactguid
::abook::setContactForGuid $contactguid $username
foreach list_sort $list_names {
#If list is not empty, get user information
if {$current != 0} {
::abook::addContactToList $username $list_sort
::MSN::addToList $list_sort $username
#No need to set groups and set offline state if contact is not in FL
if { $list_sort == "FL" } {
::abook::setContactData $username group $groups
set loading_list_info(last) $username
::abook::setVolatileData $username state "FLN"
}
}
}
set lists [::abook::getLists $username]
if { [lsearch $lists PL] != -1 } {
if { [lsearch [::abook::getLists $username] "AL"] != -1 || [lsearch [::abook::getLists $username] "BL"] != -1 } {
#We already added it we only move it from PL to RL
#Just add to RL for now and let the handler remove it from PL... to be sure it's the correct order...
::MSN::WriteSB ns "ADC" "RL N=$username"
} else {
newcontact $username $nickname
}
}
::MSN::contactListChanged
#Last user in list
if {$current == $total} {
$self setInitialStatus
$self authenticationDone
}
}
method handlePRP { command } {
if { [llength $command] == 3 } {
#initial PRP without trID
::abook::setPersonal [lindex $command 1] [urldecode [lindex $command 2]]
if { ([lindex $command 1] == "MOB") && ([lindex $command 2] == "Y") } {
::MSN::setClientCap paging
}
} else {
#PRP in response to phone number change
::abook::setPersonal [lindex $command 2] [urldecode [lindex $command 3]]
}
}
#Callback procedure called when a PRP (Personal info like nick and phone change) message is received
method handlePRPResponse { newname update command } {
switch -- [lindex $command 0] {
PRP {
::abook::setPersonal [lindex $command 2] [urldecode [lindex $command 3]]
#TODO: put this here to be the same as the old REA response, should it be moved to abook?
if { [lindex $command 2] == "MFN" } {
cmsn_draw_online 1 1
send_dock STATUS [::MSN::myStatusIs]
if {$update && [::config::getKey protocol] >= 15 } {
$::roaming UpdateProfile [list $self updateProfileCB] [::abook::getPersonal MFN] [::abook::getPersonal PSM]
$::ab ABContactUpdate [list ::MSN::ABUpdateNicknameCB] "" [list contactType Me displayName [xmlencode [::abook::getPersonal MFN]]] DisplayName
}
#an event used by guicontactlist to know when we changed our nick
::Event::fireEvent myNickChange protocol
}
::abook::saveToDisk
}
209 {
#Nickname change illegal.
msg_box [trans invalidusername]
}
715 {
# passport account not verified
msg_box [trans passportnotverified]
}
default {
}
}
return 1
}
method updateProfileCB { fail } {
}
method handleUBX { command payload } {
set contact [lindex $command 1]
if {[::config::getKey protocol] >= 18} {
set temp [split $contact ":"]
set network [lindex $temp 0]
set contact [lindex $temp 1]
unset temp
}
status_log "Got UBX for contact $contact"
if {$payload != ""} {
if { [catch { set xml [xml2list $payload] } res] } {
status_log "Got invalid XML in UBX command : $res"
return
}
set psm [::sxml::replacexml [encoding convertfrom utf-8 [GetXmlEntry $xml "Data:PSM"]]]
set currentMedia [::sxml::replacexml [encoding convertfrom utf-8 [GetXmlEntry $xml "Data:CurrentMedia"]]]
set signatureSound [::sxml::replacexml [encoding convertfrom utf-8 [GetXmlEntry $xml "Data:SignatureSound"]]]
} else {
status_log "UBX payload is empty"
set psm ""
set currentMedia ""
set signatureSound ""
}
if {$currentMedia != "" &&
[::abook::getVolatileData $contact currentMedia] != $currentMedia} {
::log::eventpsm $contact $currentMedia
} elseif {[::abook::getVolatileData $contact PSM] != $psm} {
::log::eventpsm $contact $psm
}
::abook::setVolatileData $contact PSM $psm
::abook::setVolatileData $contact currentMedia $currentMedia
if {[config::getKey protocol] >= 18} {
::abook::setVolatileData $contact signatureSound $signatureSound
if { [config::getKey login] == $contact} {
::abook::setPersonal PSM $psm
::abook::setVolatileData myself currentMedia $currentMedia
::abook::setPersonal signatureSound $signatureSound
if {$payload != ""} {
if { ![catch { set xml [xml2list $payload] } ] } {
set i 0
::abook::clearEndPoints
while {1} {
set node [GetXmlNode $xml "Data:PrivateEndpointData" $i]
if {$node == "" } {
break
}
incr i
set ep [GetXmlAttribute $node "PrivateEndpointData" "id"]
set epname [::sxml::replacexml [encoding convertfrom utf-8 [GetXmlEntry $node "PrivateEndpointData:EpName"]]]
::abook::setEndPoint $ep $epname
}
}
}
cmsn_draw_online 1 1
}
}
foreach chat_id [::ChatWindow::getAllChatIds] {
if { $chat_id == $contact } {
::ChatWindow::TopUpdate $chat_id
} else {
foreach user_in_chat [::MSN::usersInChat $chat_id] {
if { $user_in_chat == $contact } {
::ChatWindow::TopUpdate $chat_id
break
}
}
}
}
::Event::fireEvent contactPSMChange protocol $contact
}
method handleNOT { command payload } {
#save the spaces notification here
set contact [lindex $command 1]
status_log "got spaces notification for $contact ($command)"
::abook::setVolatileData $contact space_updated 1
::Event::fireEvent contactSpaceChange protocol $contact
}
method setInitialStatus { } {
set newstate "NLN"
set newstate_custom $newstate
#Don't use oldstatus if it was "FLN" (disconnectd) or we will get a 201 error
if {[info exists ::oldstatus] && $::oldstatus != "FLN" } {
set newstate $::oldstatus
unset ::oldstatus
set newstate_custom $newstate
} elseif {![is_connectas_custom_state [::config::getKey connectas]]} {
#Protocol code to choose our state on connect
set number [get_state_list_idx [::config::getKey connectas]]
set goodstatecode "[::MSN::numberToState $number]"
if {$goodstatecode != ""} {
set newstate $goodstatecode
} else {
status_log "Not able to get choosen key: [::config::getKey connectas]"
set newstate "NLN"
}
set newstate_custom $newstate
} else {
set idx [get_custom_state_idx [::config::getKey connectas]]
set newstate_custom $idx
if { [lindex [StateList get $idx] 2] != "" } {
set newstate [::MSN::numberToState [lindex [StateList get $idx] 2]]
}
}
if {[::config::getKey protocol] >= 15 } {
$::roaming GetProfile [list $self setInitialNicknameCB $newstate $newstate_custom]
} else {
set_initial_nick
# Change status after sending the UUX stuff
ChCustomState $newstate_custom
send_dock "STATUS" $newstate
}
}
method setInitialNicknameCB { newstate newstate_custom nickname last_modif psm fail } {
global newstate_server
if {$fail == 0} {
status_log "GetProfile : Retrieved nickname from server : $nickname - psm : $psm"
::MSN::changePSM $psm $newstate 0 1
set lastchange [::abook::getPersonal info_lastchange]
set roaming_newer 1
set roaming_last_modif 0
set ab_last_modif 0
if { [regexp {(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})} $last_modif -> y m d h min s] } {
set roaming_last_modif [clock scan "${y}-${m}-${d} ${h}:${min}:${s}"]
}
if { [regexp {(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})} $lastchange -> y m d h min s] } {
set ab_last_modif [clock scan "${y}-${m}-${d} ${h}:${min}:${s}"]
}
status_log "Roaming last modif :$last_modif, AB last modif : $lastchange"
if {$nickname != "" } {
::MSN::changeName $nickname 0
} else {
::MSN::changeName [::abook::getPersonal MFN] 1
}
if { [::config::getKey getprofileoffline] } {
foreach username [::MSN::getList FL] {
after idle [list catch [list $::roaming GetProfile [list ::MSN::roaming_cl_get_profile_cb $username] $username]]
}
}
# Change status after sending the UUX stuff
#ChCustomState $newstate_custom
#send_dock "STATUS" $newstate
#trigger download DP
::MSN::downloadDP 1
} else {
set_initial_nick
# Change status after sending the UUX stuff
#ChCustomState $newstate_custom
#send_dock "STATUS" $newstate
}
if { [info exists newstate_server] && $newstate_server != $newstate_custom } {
set answer [::amsn::messageBox "[trans setbackinitialstate [trans [::MSN::stateToDescription $newstate_custom]] [trans [::MSN::stateToDescription $newstate_server]]]" yesno question "[trans confirm]"]
if { $answer == "no" } {
set newstate_custom $newstate_server
}
unset newstate_server
}
ChCustomState $newstate_custom
send_dock "STATUS" $newstate
if {$fail == 3 || $fail == 4} {
# ItemDoesNotExist
$::roaming CreateProfile [list $self RoamingProfileCreated]
}
}
method RoamingProfileCreated { rid fail } {
if {$rid == "" } {
set rid [::abook::getPersonal profile_resourceid]
}
if {$rid != "" } {
$::roaming ShareItem [list $self RoamingItemShared] $rid
}
}
method RoamingGetProfileCB { cmd nickname last_modif psm fail } {
if {$fail == 0} {
if {$cmd != ""} {
catch {eval $cmd}
}
}
}
method RoamingDeleteRelationshipsCB { updateDP_step fail } {
if {$fail == 0} {
::MSN::updateDP $updateDP_step
}
}
method RoamingCreateDocumentCB { updateDP_step dpid fail } {
if {$fail == 0} {
::abook::setPersonal dp_resourceid $dpid
::MSN::updateDP $updateDP_step
}
}
method RoamingItemShared { fail } {
$::ab AddMember [list $self RoamingMemberAdded] RoamingSeed "" ProfileExpression
}
method RoamingMemberAdded { fail } {
$::ab ABContactUpdate [list $self RoamingAnnotationAdded] "" [list contactType Me annotations "<Annotation><Name>MSN.IM.RoamLiveProperties</Name><Value>1</Value></Annotation>"] Annotation
}
method RoamingAnnotationAdded { fail } {
$::roaming UpdateProfile [list ns updateProfileCB] [::abook::getPersonal MFN] [::abook::getPersonal PSM]
}
}
::snit::type SB {
delegate option * to connection
delegate method * to connection
option -users [list]
option -typers [list]
option -lastmsgtime 0
option -title ""
option -last_user ""
option -invite ""
option -auth_cmd ""
option -auth_param ""
option -last_activity 0
option -lastspoke 0
option -killme ""
variable unacked [list]
constructor {args} {
install connection using Connection %AUTO% -name $self
$self configurelist $args
}
destructor {
catch { $connection destroy }
}
method add_unacked { id } {
set unacked [lappend unacked $id]
}
method get_unacked { } {
return [llength $unacked]
}
method addUser { user } {
lappend options(-users) $user
}
method delUser { idx } {
set options(-users) [lreplace $options(-users) $idx $idx]
}
method addTyper { typer } {
lappend options(-typers) $typer
}
method delTyper { idx } {
set options(-typers) [lreplace $options(-typers) $idx $idx]
}
method handleCommand { command {payload ""}} {
set command [split $command]
degt_protocol "<-$self-[$self cget -sock] $command" "sbrecv"
if { $payload != "" } {
degt_protocol "Message Contents:\n$payload" "sbrecv"
set message [Message create %AUTO%]
$message createFromPayload $payload
}
global list_cmdhnd msgacks
set ret_trid [lindex $command 1]
set idx [lsearch $list_cmdhnd "$self $ret_trid *"]
if {$idx != -1} { ;# Command has a handler associated!
status_log "sb::handleCommand: Evaluating handler for $ret_trid in SB $self\n"
set cmd "[lindex [lindex $list_cmdhnd $idx] 2] {$command}"
#status_log "command is $cmd"
if {[eval $cmd] } {
# The list_cmdhnd might have been modified by the callback
set idx [lsearch $list_cmdhnd "$self $ret_trid *"]
if {$idx != -1} {
set list_cmdhnd [lreplace $list_cmdhnd $idx $idx]
}
}
} else {
switch -- [lindex $command 0] {
MSG {
$self handleMSG $command $message
}
BYE -
JOI -
IRO {
cmsn_update_users $self $command
}
CAL {
#status_log "$self_name: [join $command]\n" green
}
ANS {
status_log "sb::handleCommand: ANS Chat started. [llength [$self cget -users]] users: [$self cget -users]\n" green
if { [llength [$self cget -users]] == 1 } {
set chatid [lindex [$self cget -users] 0]
} else {
set chatid $self
}
::MSN::AddSBFor $chatid $self
foreach usr_login [$self cget -users] {
::MSNP2P::loadUserPic $chatid $usr_login
::amsn::userJoins $chatid $usr_login 0
}
#Send x-clientcaps information
::MSN::clientCaps $chatid
}
NAK {
if { [info exists msgacks($ret_trid)]} {
set ackid $msgacks($ret_trid)
::amsn::nackMessage $ackid
#::MSN::retryMessage $ackid
unset msgacks($ret_trid)
}
}
ACK {
if { [info exists msgacks($ret_trid)]} {
set ackid $msgacks($ret_trid)
::amsn::ackMessage $ackid
unset msgacks($ret_trid)
}
set trid_ind [lsearch $unacked $ret_trid]
set unacked [lreplace $unacked $trid_ind $trid_ind]
::Event::fireEvent ackReceived $self $self
}
208 {
status_log "sb::handleCommand: invalid user name for chat\n" red
msg_box "[trans invalidusername]"
}
"" {
}
default {
if { "[$self cget -stat ]" == "d" } {
status_log "$self: UNKNOWN SB ENTRY! --> [join $command]\n" red
}
}
}
}
catch { set options(-last_activity) [clock seconds] }
}
method handleMSG { command message } {
set p4context [encoding convertfrom identity [$message getHeader P4-Context]]
set typer [string tolower [lindex $command 1]]
if { [::config::getKey displayp4context] !=1 || $p4context == "" } {
set nick [::abook::getDisplayNick $typer]
set p4c_enabled 0
} else {
set nick "[::config::getKey p4contextprefix]$p4context"
set p4c_enabled 1
}
#Notice that we're ignoring the nick sent in the own MSG command, and using the one in ::abook
set users_list $options(-users)
#Get the current chatid
set chatid [::MSN::ChatFor $self]
set message_id [$message getHeader Message-ID]
set chunks [$message getHeader Chunks]
set current_chunk [$message getHeader Chunk]
if { $message_id != "" && ($chunks != "" || $current_chunk != "" ) } {
if { $chunks != "" } {
status_log "chunked message : $chunks chunks - [$message getHeaders]" blue
set ::MSN::split_messages(${message_id}_total_chunks) $chunks
set ::MSN::split_messages(${message_id}_got_chunks) 1
set ::MSN::split_messages(${message_id}_chunk_0) [$message getBody]
set ::MSN::split_messages(${message_id}_headers) [$message getHeaders]
set ::MSN::split_messages(${message_id}_fields) [$message getFields]
} elseif {[info exists ::MSN::split_messages(${message_id}_got_chunks)]} {
status_log "chunked message : $chunks chunk - [$message getHeaders] - [set ::MSN::split_messages(${message_id}_headers)]" blue
incr ::MSN::split_messages(${message_id}_got_chunks)
set ::MSN::split_messages(${message_id}_chunk_${current_chunk}) [$message getBody]
array set headers [set ::MSN::split_messages(${message_id}_headers)]
array set headers [$message getHeaders]
set ::MSN::split_messages(${message_id}_headers) [array get headers]
array set fields [set ::MSN::split_messages(${message_id}_fields)]
array set fields [$message getFields]
set ::MSN::split_messages(${message_id}_fields) [array get fields]
}
if {[info exists ::MSN::split_messages(${message_id}_total_chunks)] &&
[set ::MSN::split_messages(${message_id}_total_chunks)] == [set ::MSN::split_messages(${message_id}_got_chunks)] } {
set body ""
for { set i 0 } { $i < [set ::MSN::split_messages(${message_id}_total_chunks)] } { incr i } {
append body [set ::MSN::split_messages(${message_id}_chunk_${i})]
unset ::MSN::split_messages(${message_id}_chunk_${i})
}
$message setRaw $body [set ::MSN::split_messages(${message_id}_headers)] [set ::MSN::split_messages(${message_id}_fields)]
unset ::MSN::split_messages(${message_id}_total_chunks)
unset ::MSN::split_messages(${message_id}_got_chunks)
unset ::MSN::split_messages(${message_id}_headers)
unset ::MSN::split_messages(${message_id}_fields)
} else {
# Ignore this message until you get the whole message
return
}
}
set contentType [lindex [split [$message getHeader Content-Type] ";"] 0]
switch -- $contentType {
text/plain {
::Event::fireEvent messageReceived $self $message
$message setBody [encoding convertfrom identity [string map {"\r\n" "\n"} [$message getBody]]]
::amsn::messageFrom $chatid $typer $nick $message user $p4c_enabled
catch {set options(-lastmsgtime) [clock format [clock seconds] -format %H:%M:%S]}
catch {set options(-lastspoke) [clock seconds]}
::abook::setContactData $typer last_msgedme [clock format [clock seconds] -format "%D - %H:%M:%S"]
#if alarm_onmsg is on run it
if { ( [::alarms::isEnabled $typer] == 1 )&& ( [::alarms::getAlarmItem $typer onmsg] == 1) } {
set username [::abook::getDisplayNick $typer]
run_alarm $typer $typer $username "[trans says $username]: [$message getBody]"
} elseif { ( [::alarms::isEnabled all] == 1 )&& ( [::alarms::getAlarmItem all onmsg] == 1) } {
set username [::abook::getDisplayNick $typer]
run_alarm all $typer $username "[trans says $username]: [$message getBody]"
}
global automessage automsgsent
# Send automessage once to each user
if { [info exists automessage] } {
if { $automessage != "-1" && [lindex $automessage 4] != ""} {
if { [info exists automsgsent($typer)] } {
if { $automsgsent($typer) != 1 } {
::amsn::MessageSend [::ChatWindow::For $chatid] 0 [parse_exec [lindex $automessage 4]] "[trans automessage]"
set automsgsent($typer) 1
}
} else {
::amsn::MessageSend [::ChatWindow::For $chatid] 0 [parse_exec [lindex $automessage 4]] "[trans automessage]"
set automsgsent($typer) 1
}
}
}
::MSN::DelSBTyper $self $typer
}
text/x-msmsgscontrol {
set typer_real [string tolower [$message getHeader TypingUser]]
if { ($typer == $typer_real) || ($typer_real == "") } {
::MSN::addSBTyper $self $typer
}
}
text/x-msmsgsinvite {
#File transfers or other invitations
set fromlogin [lindex $command 1]
#OK, what happens now is, we have to extract the info from the
#body, which looks like the MIME header. Therefore, we simply
#steal the code for extracting the headers, and replace
#getHeader with array get.
#The above is no longer true! the message object now has a function,
#getField, that works just like getHeader, except it gets... you
#guessed it - a field from the body.
set invcommand [$message getField Invitation-Command]
set cookie [$message getField Invitation-Cookie]
status_log "Command: $invcommand Message: $message\n" blue
#Do we need this? Looks a bit... untidy
#puts $invcommand
#puts $cookie
if {$invcommand == "INVITE" } {
#set guid [lindex [array get headers Application-GUID] 1]
set guid [$message getField Application-GUID]
#An invitation, generate invitation event
if { $guid == "{5D3E02AB-6190-11d3-BBBB-00C04F795683}" } {
#We have a file transfer here
set filename [$message getField Application-File]
set filesize [$message getField Application-FileSize]
::MSNFT::invitationReceived $filename $filesize $cookie $chatid $fromlogin
} elseif { $guid == "{02D3C01F-BF30-4825-A83A-DE7AF41648AA}" } {
# We got an audio only invitation or audio/video invitation
set context [$message getField Context-Data]
#Remove the # on the next line if you want to test audio/video feature (with Linphone, etc...)
#Ask Burger for more details..
SendMessageFIFO [list ::MSNAV::invitationReceived $cookie $context $chatid $fromlogin] "::amsn::messages_stack($chatid)" "::amsn::messages_flushing($chatid)"
}
} elseif { $invcommand == "ACCEPT" } {
# let's see if it's an A/V session cancel
if { [::MSNAV::CookieList get $cookie] != 0 } {
set ip [$message getField IP-Address]
::MSNAV::readAccept $cookie $ip $chatid
} else {
#Generate "accept" event
::MSNFT::acceptReceived $cookie $chatid $fromlogin $message
}
} elseif { $invcommand =="CANCEL" } {
# let's see if it's an A/V session cancel
if { [::MSNAV::CookieList get $cookie] != 0 } {
::MSNAV::cancelSession $cookie $chatid "TIMEOUT"
} else {
# prolly an FT
set cancelcode [$message getField Cancel-Code]
if { $cancelcode == "FTTIMEOUT" } {
::MSNFT::timeoutedFT $cookie
} elseif { $cancelcode == "REJECT" } {
::MSNFT::rejectedFT $chatid $fromlogin $cookie
}
}
} else {
#... other types of commands
}
}
application/x-msnmsgrp2p {
status_log "Received $message"
set msg [::p2p::Message create %AUTO%]
$msg parse [$message getPayload]
destroy $message
#@@@@@@@@@@p2pv2
set transport [$::trsp_mgr Get_transport $typer "" ""]
$transport On_message_received $msg
#set dest [$message getHeader "P2P-Dest"]
#set semic [string first ";" $dest]
#set destid ""
#if { $semic > 0 } {
# set destid [string range $dest [expr { $semic + 1}] end]
# set dest [string range $dest 0 [expr {$semic - 1}]]
# }
# if { [string compare -nocase $dest [::config::getKey login]] == 0 } {
# if { $destid == "" ||
# [string compare -nocase $destid [::config::getGlobalKey machineguid]] == 0 } {
# set p2pmessage [P2PMessage create %AUTO%]
# if {[catch {$p2pmessage createFromMessage $message}] } {
# status_log "ouch.. invalid data for p2p.. might be a WLM beta bug.."
# } else {
# ::MSNP2P::ReadData $p2pmessage $chatid
#status_log [$p2pmessage toString 1]
# }
# catch { $p2pmessage destroy }
# } else {
# status_log "Received an MSNP2P message not addressed to us... ignoring"
# }
#
# }
}
text/x-mms-emoticon -
text/x-mms-animemoticon {
upvar #0 [string map {: _} ${chatid}]_smileys chatsmileys
status_log "Got a custom smiley from peer\n" red
set chatsmileys(dummy) ""
parse_x_mms_emoticon [$message getBody] $chatid
status_log "got smileys : [array names chatsmileys]\n" blue
foreach smile [array names chatsmileys] {
if { $smile == "dummy" } { continue }
MSNP2P::loadUserSmiley $chatid $typer "[set chatsmileys($smile)]"
}
}
text/x-clientcaps {
#Packet we receive from 3rd party client (not by MSN)
xclientcaps_received $message $typer
}
image/gif {
set body [$message getBody]
if { [string first "base64:" $body] != -1 } {
set data [::base64::decode [string range $body 7 end]]
} else {
set data $body
}
# don't try to display it if the image is considered as invalid
if { [catch {set img [image create photo [TmpImgName] -data $data]}]} {
status_log "(protocol.tcl) receiving an invalid gif from $typer" red
} else {
SendMessageFIFO [list ::amsn::ShowInk $chatid $typer $nick $img ink $p4c_enabled] "::amsn::messages_stack($chatid)" "::amsn::messages_flushing($chatid)"
}
}
text/x-keepalive {
#kopete sends this to keep the SB open all time when the window is open, every 50 seconds. Generates a lot of network traffic + handling cpu power for nothing.
#if we didn't receive any message on this SB, close it
if {[$self cget -lastspoke] == 0} {
status_log "Closing the SB for an aggresive Kopete user: $chatid" white
::MSN::CloseSB $self
}
}
text/x-msnmsgr-datacast {
set body [$message getBody]
set lines [split $body "\r\n"]
# We set these because some clients (www.imhaha.com/webmsg/) can send datacast messages without anything in them...
set key ""
set value ""
foreach line $lines {
foreach {key value} [split $line ":"] break
if {$key == "ID"} {
set id $value
} elseif {$key == "Data"} {
set data $value
}
}
# Make sure it was a valid datacast packet...
if { [info exists id] } {
set evpar(chatid) chatid
set evpar(typer) typer
set evpar(nick) nick
set evpar(msg) message
set evpar(id) id
set evpar(data) data
::plugins::PostEvent DataCastPacketReceived evpar
if { [info exists id] && [info exists data] } {
if {$id == "3" } {
::MSNP2P::RequestObjectEx $chatid $typer $data "voice"
} elseif {$id == "4" } {
# Action messages...
::amsn::WinWrite $chatid "\n" gray
::amsn::WinWriteIcon $chatid greyline 3
::amsn::WinWrite $chatid "\n" gray
set font [lindex [::config::getGlobalKey basefont] 0]
if { $font == "" } { set font "Helvetica"}
set color 333333; #TODO: needs a skin key for this one
set customfont [list $font [list "italic"] $color]
::amsn::WinWrite $chatid [encoding convertfrom identity $data] "custom" $customfont
::amsn::WinWrite $chatid "\n" gray
::amsn::WinWriteIcon $chatid greyline 3
::amsn::WinWrite $chatid "\n" gray
if {[::abook::getKeepLogs $chatid]} {
::log::WriteLog $chatid $data
}
}
}
}
}
default {
status_log "$self handleMSG: === UNKNOWN MSG ===\n$command\n[$message getHeaders]\n[$message getBody]" red
#Postevent for others kinds of packet (like nudge)
set evpar(chatid) chatid
set evpar(typer) typer
set evpar(nick) nick
set evpar(msg) message
::plugins::PostEvent PacketReceived evpar
}
}
$message destroy
if { $options(-killme) != "" } {
after cancel $options(-killme)
}
$self configure -killme [after 60000 [list ::MSN::CloseInactiveSB $self]]
}
method search { option index } {
return [lsearch $options($option) $index]
}
}
# parse_exec(text)
#
# Split the specified text in lines then replace shell commands by their
# output. A line will be interpreted as a shell command if its first
# character is a pipe. When such a line is found, the text up to the end
# of line is passed to the shell to be executed and its output inserted
# in place.
proc parse_exec {text} {
foreach line [split $text "\n"] {
if {[string index $line 0] == "|"} {
set cmd [string range $line 1 [string length $line]]
if { [OnUnix] } {
catch {exec /bin/sh -c $cmd} output
} elseif { [OnWin] } {
catch {exec "c:\\windows\\system32\\cmd.exe" /c $cmd} output
}
append outtext "$output\n"
} else {
append outtext "$line\n"
}
}
return [string trimright $outtext "\n"]
}
proc cmsn_invite_user {sb user} {
if { ("[$sb cget -stat]" == "o") \
|| ("[$sb cget -stat]" == "n") \
|| ("[$sb cget -stat]" == "i")} {
::MSN::WriteSB $sb "CAL" $user "::MSN::CALReceived $sb $user"
} else {
status_log "cmsn_invite_user: Can't invite user to non connected SB!!\n" red
}
}
proc cmsn_rng {recv} {
global sb_list
set email [string tolower [lindex $recv 5]]
if {[::abook::getContactData $email ignored 0] != 0} { return 0 }
set sb [::MSN::GetNewSB]
#Init SB properly
if { [config::getKey protocol] == 11 ||
([config::getKey protocol] >= 13 && [lindex $recv 9] == "1") } {
$sb configure -force_gateway_server [lindex [split [lindex $recv 2] ":"] 0]
}
set auth_username [::config::getKey login]
if {[::config::getKey protocol] >= 18 } {
append auth_username ";[::config::getGlobalKey machineguid]"
}
$sb configure -stat ""
$sb configure -server [split [lindex $recv 2] ":"]
$sb configure -connected [list cmsn_conn_ans $sb]
$sb configure -auth_cmd "ANS"
$sb configure -auth_param "$auth_username [lindex $recv 4] [lindex $recv 1]"
lappend sb_list "$sb"
status_log "Accepting conversation from: [lindex $recv 5]... (Got ANS1 in SB $sb\n" green
setup_connection $sb
cmsn_socket $sb
return 0
}
proc cmsn_open_sb {sb recv} {
#if the sb doesn't exist return
if {[catch {$sb cget -name}]} {
return 1
}
#TODO: I hope this works. If stat is not "c" (trying to connect), ignore
if { [$sb cget -stat] != "c" } {
return 1
}
if {[lindex $recv 0] == "913"} {
#Not allowed when offline
set chatid [::MSN::ChatFor $sb]
::MSN::ClearQueue $chatid
::MSN::CleanChat $chatid
::amsn::chatStatus $chatid "[trans needonline]\n" miniwarning
#msg_box "[trans needonline]"
return 1
}
if {[lindex $recv 4] != "CKI"} {
status_log "cmsn_open_sb: SB $sb: Unknown SP requested!\n" red
return 1
}
status_log "cmsn_open_sb: Opening SB $sb\n" green
if { [config::getKey protocol] == 11 ||
([config::getKey protocol] >= 13 && [lindex $recv 8] == "1") } {
$sb configure -force_gateway_server [lindex [split [lindex $recv 3] ":"] 0]
}
set auth_username [::config::getKey login]
if {[::config::getKey protocol] >= 18 } {
append auth_username ";[::config::getGlobalKey machineguid]"
}
$sb configure -server [split [lindex $recv 3] ":"]
$sb configure -connected [list cmsn_conn_sb $sb]
$sb configure -auth_cmd "USR"
$sb configure -auth_param "$auth_username [lindex $recv 5]"
::amsn::chatStatus [::MSN::ChatFor $sb] "[trans sbcon]...\n" miniinfo ready
setup_connection $sb
cmsn_socket $sb
return 1
}
proc cmsn_conn_sb {sb sock} {
catch { fileevent $sock writable "" } res
#Reset timeout timer
$sb configure -time [clock seconds]
$sb configure -stat "a"
set cmd [$sb cget -auth_cmd]
set param [$sb cget -auth_param]
::MSN::WriteSB $sb $cmd $param "cmsn_auth_sb $sb"
::amsn::chatStatus [::MSN::ChatFor $sb] "[trans ident]...\n" miniinfo ready
}
proc cmsn_auth_sb { sb recv } {
set cmd [lindex $recv 0]
if { $cmd == [$sb cget -auth_cmd] } {
#We got a valid response
cmsn_connected_sb $sb $recv
} else {
switch -- $cmd {
911 {
#Authentication failed, server will disconnect us.
status_log "cmsn_auth_sb: SB authentication failed for $sb, reconnecting..." red
$sb configure -stat "af"
cmsn_reconnect $sb
}
default {
status_log "cmsn_auth_sb: unknown server reply on $sb: $recv" red
cmsn_reconnect $sb
}
}
}
return 1
}
proc cmsn_conn_ans {sb sock} {
#status_log "cmsn_conn_ans: Connected to invitation SB $name...\n" green
catch {fileevent $sock writable {}} res
$sb configure -time [clock seconds]
$sb configure -stat "a"
set cmd [$sb cget -auth_cmd]
set param [$sb cget -auth_param]
::MSN::WriteSB $sb $cmd $param
#status_log "cmsn_conn_ans: Authenticating in $name...\n" green
}
proc cmsn_connected_sb {sb recv} {
#status_log "cmsn_connected_sb: SB $name connected\n" green
$sb configure -time [clock seconds]
$sb configure -stat "i"
set invite [$sb cget -invite]
if {$invite != ""} {
if {[::config::getKey protocol] >= 18 } {
cmsn_invite_user $sb [::config::getKey login]
}
cmsn_invite_user $sb $invite
::amsn::chatStatus [::MSN::ChatFor $sb] "[trans willjoin $invite]...\n" miniinfo ready
} else {
status_log "cmsn_connected_sb: got SB $sb stat=i but no one to invite!!! CHECK!!\n" white
}
}
#SB stat values:
# "d" - Disconnected, the SB is not connected to the server
# "c" - The SB is going to get a socket to connect to the server.
# "cw" - "Connect wait" The SB is trying to connect to the server.
# "a" - Authenticating. The SB is authenticating to the server.
# "af" - Authentication failed.
# "i" - Inviting first person to the chat. Successive invitations will be while in "o" status
# "o" - Opened. The SB is connected and ready for chat
# "n" - Nobody. The SB is connected but there's nobody at the conversation
proc cmsn_reconnect { sb } {
switch -- [$sb cget -stat] {
"n" {
status_log "cmsn_reconnect: stat = n , SB= $sb, user=[$sb cget -last_user]\n" green
$sb configure -time [clock seconds]
$sb configure -stat "i"
if {[::config::getKey protocol] >= 18 } {
cmsn_invite_user $sb [::config::getKey login]
}
cmsn_invite_user $sb [$sb cget -last_user]
::amsn::chatStatus [::MSN::ChatFor $sb] \
"[trans willjoin [$sb cget -last_user]]..." miniinfo ready
}
"d" {
status_log "cmsn_reconnect: stat = d , SB= $sb, user=[$sb cget -last_user]\n" green
$sb configure -time [clock seconds]
catch {[$sb cget -proxy] finish $sb}
$sb configure -sock ""
#$sb configure -data [list]
$sb configure -users [list]
$sb configure -typers [list]
$sb configure -title [trans chat]
$sb configure -lastmsgtime 0
$sb configure -lastspoke 0
$sb configure -stat "c"
$sb configure -invite [$sb cget -last_user]
if { [ns cget -stat] != "o" } {
set chatid [::MSN::ChatFor $sb]
::MSN::ClearQueue $chatid
::MSN::CleanChat $chatid
::amsn::chatStatus $chatid "[trans needonline]\n" miniwarning
return
}
::MSN::WriteSB ns "XFR" "SB" "cmsn_open_sb $sb"
::amsn::chatStatus [::MSN::ChatFor $sb] "[trans chatreq]..." miniinfo ready
}
"i" {
#status_log "cmsn_reconnect: stat = i , SB= $sb\n" green
if { ([clock seconds] - [$sb cget -time]) > 15 } {
status_log "cmsn_reconnect: called again while inviting timeouted for sb $sb\n" red
set proxy [$sb cget -proxy]
$proxy finish $sb
$sb configure -stat "d"
cmsn_reconnect $sb
}
}
"c" {
#status_log "cmsn_reconnect: stat = c , SB= $sb\n" green
if { ([clock seconds] - [$sb cget -time]) > 10 } {
status_log "cmsn_reconnect: called again while reconnect timeouted for sb $sb\n" red
#set command [list "::[$name cget -connection_wrapper]::finish" $name]
#eval $command
$sb configure -stat "d"
cmsn_reconnect $sb
}
}
"cw" -
"pw" -
"a" {
#status_log "cmsn_reconnect: stat = \"[$sb cget -stat]\" , SB= $sb\n" green
if { ([clock seconds] - [$sb cget -time]) > 10 } {
status_log "cmsn_reconnect: called again while authentication timeouted for sb $sb\n" red
set proxy [$sb cget -proxy]
$proxy finish $sb
$sb configure -stat "d"
cmsn_reconnect $sb
}
}
"af" {
#status_log "cmsn_reconnect: stat = af , SB= $sb\n" green
set proxy [$sb cget -proxy]
$proxy finish $sb
$sb configure -stat "d"
cmsn_reconnect $sb
}
"" {
status_log "cmsn_reconnect: SB $sb stat is \"\". This is bad, should delete it and create a new one\n" red
catch {
set chatid [::MSN::ChatFor $sb]
::MSN::DelSBFor $chatid $sb
::MSN::KillSB $sb
::MSN::chatTo $chatid
}
}
default {
status_log "cmsn_reconnect: SB $sb stat is [$sb cget -stat]\n" red
}
}
}
#///////////////////////////////////////////////////////////////////////
proc sb_update_chatid {sb } {
set users_list [$sb cget -users]
#Look what should be our chatID, depending on the number of users
if { [llength $users_list] > 1 } {
set desiredchatid $sb ;#For conferences, use sb_name as chatid
} elseif { [llength $users_list] == 1 } {
set desiredchatid [lindex $users_list 0]
} else {
set desiredchatid [$sb cget -last_user]
}
set chatid [::MSN::ChatFor $sb]
if { $chatid != 0} {
if { !([::config::getKey protocol] >= 18 &&
$desiredchatid == [::config::getKey login] ) &&
"$chatid" != "$desiredchatid" } {
#Our chatid is different than the desired one!! try to change
status_log "sb_update_chatid: Trying to change chatid from $chatid to $desiredchatid for SB $sb\n"
set newchatid [::ChatWindow::Change $chatid $desiredchatid]
if { "$newchatid" != "$desiredchatid" } {
#The GUI doesn't accept the change, as there's another window for that chatid
status_log "sb_update_chatid: change NOT accepted\n"
} else {
#The GUI accepts the change, so let's change
status_log "sb_update_chatid: change accepted\n"
::MSN::DelSBFor $chatid $sb
set chatid $desiredchatid
::MSN::AddSBFor $chatid $sb
}
} else {
#Add it so it's moved to front
::MSN::AddSBFor $chatid $sb
}
} else {
status_log "cmsn_sb_msg: NO chatid in cmsn_sb_msg, please check this!!\n" white
set chatid $desiredchatid
::MSN::AddSBFor $chatid $sb
}
return $chatid
}
proc cmsn_update_users {sb recv} {
switch -- [lindex $recv 0] {
BYE {
set chatid [::MSN::ChatFor $sb]
set leaves [$sb search -users "[lindex $recv 1]"]
# Ignore double BYEs for protocol MSNP18
if {$leaves == -1 } {
return 0
}
$sb configure -last_user [lindex [$sb cget -users] $leaves]
$sb delUser $leaves
sb_update_chatid $sb
set usr_login [lindex [$sb cget -users] 0]
if { [llength [$sb cget -users]] > 1 } {
::ChatWindow::TopUpdate $chatid
}
if { [llength [$sb cget -users]] == 1 } {
#We were a conference! try to become a private
set desiredchatid $usr_login
set newchatid [::ChatWindow::Change $chatid $desiredchatid]
if { "$newchatid" != "$desiredchatid" } {
#The GUI doesn't accept the change, as there's another window for that chatid
status_log "cmsn_update_users: change NOT accepted from $chatid to $desiredchatid\n"
#We will close the conference window and return to the previous
set oldwindow [::ChatWindow::For $desiredchatid]
set container [::ChatWindow::GetContainerFromWindow $oldwindow]
if { $container != "" } {
::ChatWindow::SwitchToTab $container $oldwindow
raise $container
} else {
raise $oldwindow
}
set newwindow [::ChatWindow::For $chatid]
set container [::ChatWindow::GetContainerFromWindow $newwindow]
if { $container != "" } {
set tab [set ::ChatWindow::win2tab($newwindow)]
::ChatWindow::CloseTab $tab
} else {
::ChatWindow::Close $newwindow
}
} else {
#The GUI accepts the change, so let's change
status_log "cmsn_update_users: change accepted from $chatid to $desiredchatid\n"
::MSN::DelSBFor $chatid $sb
::MSN::AddSBFor $newchatid $sb
set chatid $newchatid
::ChatWindow::TopUpdate $chatid
}
} elseif { [llength [$sb cget -users]] == 0 && [$sb cget -stat] != "d" } {
$sb configure -stat "n"
}
#Another option for the condition:
# "$chatid" != "[lindex $recv 1]" || ![MSN::chatReady $chatid]
if { [::MSN::SBFor $chatid] == $sb } {
# the last argument to userLeaves means :
# 0 : closed for inactivity
# 1 : user leaves conversation
if { [lindex $recv 2] == "1" ||
([expr [clock seconds] - [$sb cget -last_activity]] > 50 &&
[expr [clock seconds] - [$sb cget -last_activity]] < 90)} {
::amsn::userLeaves $chatid [list [lindex $recv 1]] 0
} else {
::amsn::userLeaves $chatid [list [lindex $recv 1]] 1
}
}
if { [::ChatWindow::For $chatid] == 0 } {
::MSN::DelSBFor $chatid $sb
::MSN::KillSB $sb
}
}
IRO {
#You get an IRO message when you're invited to some chat. The chatid name won't be known
#until the first message comes
$sb configure -stat "o"
set usr_login [string tolower [lindex $recv 4]]
set usr_name [urldecode [lindex $recv 5]]
# Ignore our own user when on MSNP18
# And ignore duplicate users
if {[config::getKey protocol] >= 18 } {
foreach {usr_login machineguid} [split $usr_login ";"] break
if {$usr_login == [::config::getKey login] ||
[$sb search -users $usr_login] >= 0} {
return 0
}
}
$sb addUser [list $usr_login]
sb_update_chatid $sb
::abook::setContactData $usr_login nick $usr_name
$sb configure -last_user $usr_login
if {[config::getKey protocol] >= 15 } {
set clientid [lindex $recv 6]
add_Clientid $usr_login $clientid
}
}
JOI {
$sb configure -stat "o"
set usr_login [string tolower [lindex $recv 1]]
set usr_name [urldecode [lindex $recv 2]]
# Ignore our own user when on MSNP18
# And ignore duplicate users
if {[config::getKey protocol] >= 18 } {
foreach {usr_login machineguid} [split $usr_login ";"] break
if {$usr_login == [::config::getKey login] ||
[$sb search -users $usr_login] >= 0} {
return 0
}
}
$sb addUser [list $usr_login]
::abook::setContactData $usr_login nick $usr_name
if {[config::getKey protocol] >= 15 } {
set clientid [lindex $recv 3]
add_Clientid $usr_login $clientid
}
sb_update_chatid $sb
if { [llength [$sb cget -users]] == 1 } {
$sb configure -last_user $usr_login
set chatid $usr_login
::ChatWindow::TopUpdate $chatid
} else {
#More than 1 user, change into conference
#Procedure to change chatid-sb correspondences
set oldchatid [::MSN::ChatFor $sb]
if { $oldchatid == 0 } {
status_log "cmsn_update_users: JOI - VERY BAD ERROR, oldchatid = 0. CHECK!!\n" white
return 0
}
set chatid $sb
#Remove old chatid correspondence
::MSN::DelSBFor $oldchatid $sb
::MSN::AddSBFor $chatid $sb
status_log "cmsn_update_users: JOI - Another user joins, Now I'm chatid $chatid (I was $oldchatid)\n"
::ChatWindow::Change $oldchatid $chatid
::ChatWindow::TopUpdate $chatid
}
#Don't put it in status if we're not the preferred SB.
#It can happen that you invite a user to your sb,
#but just in that moment the user invites you,
#so you will connect to its sb and be able to chat, but after
#a while the user will join your old invitation,
#and get a fake "user joins" message if we don't check it
#TODO: This line makes DP resize to original when user joins conv even if we had resized it
global HOME
set filename [::abook::getContactData $usr_login displaypicfile ""]
set file "[file join $HOME displaypic cache $usr_login ${filename}].png"
if { $filename == "" || ![file readable "$file"] } {
::MSNP2P::loadUserPic $chatid $usr_login
}
#Send x-clientcaps information
::MSN::clientCaps $chatid
if {[::MSN::SBFor $chatid] == $sb} {
::amsn::userJoins $chatid $usr_login 0
}
}
}
}
#///////////////////////////////////////////////////////////////////////
#TODO: ::abook system
proc cmsn_change_state {recv} {
global remote_auth HOME
global newstate_server
global last_iln
if {$last_iln == 0 || [expr {[clock seconds] - $last_iln}] < 30} {
set initial_status 1
set last_iln [clock seconds]
} else {
set initial_status 0
}
if {[lindex $recv 0] == "FLN"} {
#User is going offline
set user [lindex $recv 1]
set evpar(user) user
if {[::config::getKey protocol] >= 18} {
set temp [split $user ":"]
set network [lindex $temp 0]
set user [lindex $temp 1]
unset temp
} elseif {[::config::getKey protocol] >= 14} {
set network [lindex $recv 2]
}
set user_name ""
set substate "FLN"
set evpar(substate) substate
set msnobj [::abook::getVolatileData $user msnobj ""]
# status_log "contactStateChange in protocol cmsn_change_state FLN"
} elseif {[lindex $recv 0] == "ILN"} {
#Initial status when we log in
set substate [lindex $recv 2]
set user [lindex $recv 3]
set idx 4
if {[::config::getKey protocol] >= 18} {
set temp [split $user ":"]
set network [lindex $temp 0]
set user [lindex $temp 1]
unset temp
} elseif {[::config::getKey protocol] >= 14} {
set network [lindex $recv 4]
incr idx
}
set encoded_user_name [lindex $recv $idx]
set user_name [urldecode [lindex $recv $idx]]
incr idx
#Add clientID to abook
set clientid [lindex $recv $idx]
add_Clientid $user $clientid
incr idx
set msnobj [urldecode [lindex $recv $idx]]
incr idx
if {[::config::getKey protocol] >= 18} {
set unknown_machineguid [lindex $recv $idx]
}
#Previous clientname info is now inaccurate
::abook::setContactData $user clientname ""
if {[::config::getKey protocol] >= 18 &&
$user == [::config::getKey login] } {
#ILN for ourself. We might want to change the status
set newstate_server $substate
}
} else {
#Coming online or changing state
set substate [lindex $recv 1]
set evpar(substate) substate
set user [lindex $recv 2]
set evpar(user) user
set idx 3
if {[::config::getKey protocol] >= 18} {
set temp [split $user ":"]
set network [lindex $temp 0]
set user [lindex $temp 1]
unset temp
} elseif {[::config::getKey protocol] >= 14} {
set network [lindex $recv 3]
incr idx
}
set encoded_user_name [lindex $recv $idx]
set user_name [urldecode [lindex $recv $idx]]
incr idx
#Add clientID to abook
set clientid [lindex $recv $idx]
add_Clientid $user $clientid
incr idx
set msnobj [urldecode [lindex $recv $idx]]
incr idx
if {[::config::getKey protocol] >= 18} {
set unknown_machineguid [lindex $recv $idx]
}
# status_log "contactStateChange in protocol cmsn_change_state $user"
}
if {$substate == "HDN"} {
set substate "FLN"
}
set oldstate [::abook::getVolatileData $user state]
if { $oldstate != $substate } {
set state_changed 1
} else {
set state_changed 0
}
if { $msnobj == "" } {
set msnobj -1
}
if {$user_name == ""} {
set user_name [::abook::getContactData $user nick]
set nick_changed 0
} elseif {$user_name != [::abook::getContactData $user nick]} {
#Nick differs from the one on our list, so change it
#in the server list too
::abook::setContactData $user nick $user_name
#an event used by guicontactlist to know when we changed our nick
::Event::fireEvent contactNickChange protocol $user
set nick_changed 1
if {[config::getKey protocol] < 13} {
# This check below is because today I received a NLN for a user
# who doesn't appear in ANY of my 5 MSN lists (RL,AL,BL,FL,PL)
# so amsn just sent the SBP with an empty string for the contactguid,
# which resulted in a wrongly formed SBP, which resulted in the msn server disconnecting me... :@
if { [::abook::getContactData $user contactguid] != "" } {
::MSN::WriteSB ns "SBP" "[::abook::getContactData $user contactguid] MFN [urlencode $user_name]"
}
} else {
# Update the contact's nickname in the server's abook as well
if { [::abook::getContactData $user contactguid] != "" } {
#after idle [list $::ab ABContactUpdate [list ::MSN::ABUpdateNicknameCB] $user [list displayName [xmlencode $user_name]] DisplayName]
}
}
::log::eventnick $user $user_name
} else {
set nick_changed 0
}
set custom_user_name [::abook::getDisplayNick $user]
if {!$initial_status && $state_changed} {
::plugins::PostEvent ChangeState evpar
#alarm system (that must replace the one that was before) - KNO
if {$substate == "FLN"} {
#User disconnected
if { ( [::alarms::isEnabled $user] == 1 )&& ( [::alarms::getAlarmItem $user ondisconnect] == 1) } {
run_alarm $user $user $custom_user_name [trans disconnect $custom_user_name]
} elseif { ( [::alarms::isEnabled all] == 1 )&& ( [::alarms::getAlarmItem all ondisconnect] == 1) } {
run_alarm all $user $custom_user_name [trans disconnect $custom_user_name]
}
} else {
set status "[trans [::MSN::stateToDescription $substate]]"
if { ( [::alarms::isEnabled $user] == 1 )&& ( [::alarms::getAlarmItem $user onstatus] == 1) } {
run_alarm $user $user $custom_user_name "[trans changestate $custom_user_name $status]"
} elseif { ( [::alarms::isEnabled all] == 1 )&& ( [::alarms::getAlarmItem all onstatus] == 1)} {
run_alarm all $user $custom_user_name "[trans changestate $custom_user_name $status]"
}
}
#end of alarm system
}
# Write remote the nick change if the state didn't change
if {$remote_auth == 1 && $nick_changed && !$state_changed &&
$substate != "FLN" && [::abook::getVolatileData $user state FLN] != "FLN" &&
!$initial_status } {
set nameToWriteRemote "$user_name ($user)"
write_remote "** [trans changestate $nameToWriteRemote [trans [::MSN::stateToDescription $substate]]]" event
}
if {$state_changed } {
#an event used by guicontactlist to know when a contact changed state
after 500 [list ::Event::fireEvent contactStateChange protocol $user]
set maxw [expr {([::skin::getKey notifwidth]-53)*2} ]
set font [::skin::getKey notify_font]
set short_name [trunc_list "[::abook::getDisplayNick $user 1]" . $maxw $font]
#User logsout
if {$substate == "FLN"} {
#Register last logout, last seen and notify it in the events
::abook::setAtomicContactData $user [list last_logout last_seen] \
[list [clock format [clock seconds] -format "%D - %H:%M:%S"] [clock format [clock seconds] -format "%D - %H:%M:%S"]]
::log::event disconnect $custom_user_name
# Added by Yoda-BZH
if {$remote_auth == 1} {
set nameToWriteRemote "$user_name ($user)"
write_remote "** $nameToWriteRemote [trans logsout]" event
}
if { (([::config::getKey notifyoffline] == 1 &&
[::abook::getContactData $user notifyoffline -1] != 0) ||
[::abook::getContactData $user notifyoffline -1] == 1) &&
([::config::getKey no_blocked_notif 0] == 0 || ![::MSN::userIsBlocked $user])} {
#Show notify window if globally enabled, and not locally disabled, or if just locally enabled
set msg $short_name
lappend msg [list "newline"]
lappend msg [list "text" "[trans logsout]."]
::amsn::notifyAdd $msg "" offline offline $user 1
}
# User was online before, so it's just a status change, and it's not
# an initial state notification
} elseif {[::abook::getVolatileData $user state FLN] != "FLN" &&
!$initial_status} {
#Notify in the events
::log::event state $custom_user_name [::MSN::stateToDescription $substate]
# Added by Yoda-BZH
if {$remote_auth == 1} {
set nameToWriteRemote "$user_name ($user)"
write_remote "** [trans changestate $nameToWriteRemote [trans [::MSN::stateToDescription $substate]]]" event
}
if { (([::config::getKey notifystate] == 1 &&
[::abook::getContactData $user notifystatus -1] != 0) ||
[::abook::getContactData $user notifystatus -1] == 1) &&
([::config::getKey no_blocked_notif 0] == 0 || ![::MSN::userIsBlocked $user])} {
set msg $short_name
lappend msg [list "newline"]
lappend msg [list "text" "[trans statechange]"]
lappend msg [list "newline"]
lappend msg [list "text" "[trans [::MSN::stateToDescription $substate]]."]
::amsn::notifyAdd $msg "::amsn::chatUser $user" state state $user 1
}
} elseif {[::abook::getVolatileData $user state FLN] == "FLN"} { ;# User was offline, now online
#Register last login and notify it in the events
::abook::setContactData $user last_login [clock format [clock seconds] -format "%D - %H:%M:%S"]
::log::event connect $custom_user_name
::abook::setVolatileData $user PSM ""
if {!$initial_status } {
#Register PostEvent "UserConnect" for Plugins, email = email user_name=custom nick
set evPar(user) user
set evPar(user_name) custom_user_name
#Reset clientname, if it's not M$N it will set it again
#later on with x-clientcaps
::abook::setContactData $user clientname ""
::plugins::PostEvent UserConnect evPar
# Added by Yoda-BZH
if {$remote_auth == 1} {
set nameToWriteRemote "$user_name ($user)"
write_remote "** $nameToWriteRemote [trans logsin]" event
}
if { (([::config::getKey notifyonline] == 1 &&
[::abook::getContactData $user notifyonline -1] != 0) ||
[::abook::getContactData $user notifyonline -1] == 1) &&
([::config::getKey no_blocked_notif 0] == 0 || ![::MSN::userIsBlocked $user]) } {
set msg $short_name
lappend msg [list "newline"]
lappend msg [list "text" "[trans logsin]."]
::amsn::notifyAdd $msg "::amsn::chatUser $user" online online $user 1
}
if { ( [::alarms::isEnabled $user] == 1 )&& ( [::alarms::getAlarmItem $user onconnect] == 1)} {
run_alarm $user $user $custom_user_name "$custom_user_name [trans logsin]"
} elseif { ( [::alarms::isEnabled all] == 1 )&& ( [::alarms::getAlarmItem all onstatus] == 1)} {
run_alarm all $user $custom_user_name "$custom_user_name [trans logsin]"
}
}
}
}
# Retreive the new display picture if it changed
# set oldmsnobj [::abook::getVolatileData $user msobj]
#set list_users [lreplace $list_users $idx $idx [list $user $user_name $state_no $msnobj]]
if {$state_changed} {
::abook::setVolatileData $user state $substate
}
::abook::setVolatileData $user msnobj $msnobj
set oldPic [::abook::getContactData $user displaypicfile]
set newPic [::MSNP2P::GetFilenameFromMSNOBJ $msnobj]
if { $oldPic != $newPic && $user != [::config::getKey login] } {
::abook::setContactData $user displaypicfile $newPic
if { $newPic == "" } {
::skin::getDisplayPicture $user 1
} else {
status_log "picture changed for user $user\n" white
if { [file readable "[file join $HOME displaypic cache $user ${newPic}].png"] } {
#it's possible that the user set again a DP that we already have in our cache so just load it again, even if we are HDN, or the user is blocked.
::Event::fireEvent contactDPChange protocol $user
::MSNP2P::loadUserPic "" $user
} elseif { [::MSN::myStatusIs] != "FLN" && [::MSN::myStatusIs] != "HDN" &&
![::config::getKey lazypicretrieval] && ![::MSN::userIsBlocked $user]} {
set chat_id [::MSN::chatTo $user]
::MSN::ChatQueue $chat_id [list ::MSNP2P::loadUserPic $chat_id $user]
} else {
global sb_list
foreach sb $sb_list {
set users_in_chat [$sb cget -users]
if { [lsearch $users_in_chat $user] != -1 } {
status_log "User changed image while image in use!! Updating!!\n" white
::MSNP2P::loadUserPic [::MSN::ChatFor $sb] $user
break
}
}
}
}
}
if { $state_changed || $nick_changed } {
::MSN::contactListChanged
foreach chat_id [::ChatWindow::getAllChatIds] {
if { $chat_id == $user } {
::ChatWindow::TopUpdate $chat_id
} else {
foreach user_in_chat [::MSN::usersInChat $chat_id] {
if { $user_in_chat == $user } {
::ChatWindow::TopUpdate $chat_id
break
}
}
}
}
}
}
proc cmsn_ns_handler {item {message ""}} {
global password chg_last_dp
switch -- [lindex $item 0] {
MSG {
cmsn_ns_msg $item $message
$message destroy
return 0
}
IPG {
::MSNMobile::MessageReceived "$message"
return 0
}
VER -
INF -
CVR -
USR {
return [cmsn_auth $item]
}
XFR {
if {[lindex $item 2] == "NS"} {
set tmp_ns [split [lindex $item 3] ":"]
if {[::config::getKey start_ns_server] == [lindex $item 3]} {
::config::setKey start_gateway_server [lindex $tmp_ns 0]
status_log "cmsn_ns_handler: got a NS transfer to the same NS, probably a gateway transfer, reconnecting to [lindex $tmp_ns 0]!\n" green
} else {
status_log "cmsn_ns_handler: got a NS transfer, reconnecting to [lindex $tmp_ns 0]!\n" green
}
::config::setKey start_ns_server [lindex $item 3]
ns configure -server $tmp_ns
cmsn_ns_connect [::config::getKey login] $password nosigin
set recon 1
return 0
} else {
status_log "cmsn_ns_handler: got an unknown transfer!!\n" red
return 0
}
}
RNG {
return [cmsn_rng $item]
}
UUX {
::MSN::GotUUXResponse $item
return 0
}
ADC {
::MSN::GotADCResponse $item
return 0
}
REM {
::MSN::GotREMResponse $item
return 0
}
FLN -
ILN -
NLN {
if {[::config::getKey protocol] >= 18 &&
[lindex [split [lindex $item 2] ":"] 1] == [::config::getKey login] &&
[lindex $item 0] == "NLN" &&
[lindex $item 1] != "IDL" } {
::abook::setPersonal MFN [urldecode [lindex $item 3]]
::MSN::setMyStatus [lindex $item 1]
cmsn_draw_online 1 1
#Alert dock of status change
send_dock "STATUS" [lindex $item 1]
}
cmsn_change_state $item
return 0
}
CHG {
if { [::MSN::myStatusIs] != [lindex $item 2] } {
::abook::setVolatileData myself msnobj [lindex $item 4]
::MSN::setMyStatus [lindex $item 2]
cmsn_draw_online 1 1
#Alert dock of status change
send_dock "STATUS" [lindex $item 2]
# If we had a new clientid change between the time we sent the CHG and
# the time we received the answer (in case we were FLN before),
# that new clientid will never get known, so we need to resend our
# status with new clientid (happens if farsight takes a long time to
# timeout the STUN discovery)
set clientid [lindex $item 3]
set myclientid [::config::getKey clientid 0]
if { [::config::getKey protocol] < 18} {
set myclientid [lindex [split $myclientid ":"] 0]
}
if { $myclientid != $clientid ||
![info exists chg_last_dp] || [::config::getKey displaypic] != $chg_last_dp } {
global autostatuschange
set tmp $autostatuschange
::MSN::changeStatus [::MSN::myStatusIs]
set autostatuschange $tmp
}
}
return 0
}
GTC {
#TODO: How we store this privacy information??
return 0
}
SYN {
global loading_list_info
::MSN::clearList FL
::MSN::clearList BL
::MSN::clearList RL
::MSN::clearList AL
::MSN::clearList PL
::MSN::clearList EL
new_contact_list "[lindex $item 2]" "[lindex $item 3]"
if { [llength $item] == 6 } {
status_log "Going to receive contact list\n" blue
#First contact in list
::groups::Reset
::groups::Set 0 [trans nogroup]
foreach username [::abook::getAllContacts] {
#Remove user from all lists while receiving List data
::abook::setContactData $username lists ""
}
set loading_list_info(cl_version) [lindex $item 2]
set loading_list_info(list_version) [lindex $item 3]
set loading_list_info(total) [lindex $item 4]
set loading_list_info(current) 0
set loading_list_info(gcurrent) 0
set loading_list_info(gtotal) [lindex $item 5]
# Check if there are no users and no groups, then we already finished authentification
if {$loading_list_info(gtotal) == 0 && $loading_list_info(total) == 0} {
ns setInitialStatus
ns authenticationDone
}
} else {
::MSN::makeLists
foreach username [::MSN::getList "FL"] {
::abook::setVolatileData $username state "FLN"
}
ns setInitialStatus
ns authenticationDone
}
return 0
}
BLP {
change_BLP_settings "[lindex $item 1]"
return 0
}
CHL {
status_log "Challenge received, answering\n" green
::MSN::AnswerChallenge $item
return 0
}
QRY {
status_log "Challenge accepted\n" green
return 0
}
BPR {
global loading_list_info
if { [string length [lindex $item 1]] == 3 } {
set var [lindex $item 1]
set value [urldecode [lindex $item 2]]
if {[string first "tel:" $value] == 0} {
set value [string range $value [string length "tel:"] end]
}
::abook::setContactData $loading_list_info(last) $var $value
} else {
#here the first element is the addres of the user, this is when it's not received on login.
set var [lindex $item 2]
set value [urldecode [lindex $item 3]]
::abook::setContactData [lindex $item 1] $var $value
}
return 0
}
REG { # Rename Group
#status_log "$item\n" blue
::groups::RenameCB [lrange $item 0 5]
return 0
}
ADG { # Add Group
#status_log "$item\n" blue
::groups::AddCB [lrange $item 0 5]
return 0
}
RMG { # Remove Group
#status_log "$item\n" blue
::groups::DeleteCB [lrange $item 0 5]
return 0
}
OUT {
if { [lindex $item 1] == "OTH"} {
::MSN::logout
msg_box "[trans loggedotherlocation]"
status_log "Logged other location\n" red
return 0
} else {
::config::setKey start_ns_server [::config::getKey default_ns_server]
::config::setKey start_gateway_server [::config::getKey default_gateway_server]
if { [::config::getKey reconnect] == 1 } {
::MSN::saveOldStatus
::MSN::logout
::MSN::reconnect "[trans servergoingdown]"
} else {
::MSN::logout
msg_box "[trans servergoingdown]"
}
return 0
}
}
URL {
::hotmail::gotURL [lindex $item 2] [lindex $item 3] [lindex $item 4]
return
}
QNG {
#Ping response
variable ::MSN::pollstatus 0
return 0
}
GCF {
catch {
set xml [xml2list [$message getBody]]
set i 0
while {1} {
if {[config::getKey protocol] >= 15} {
set subxml [GetXmlNode $xml "Policies:Policy:config:block:regexp:imtext" $i]
} else {
set subxml [GetXmlNode $xml "config:block:regexp:imtext" $i]
}
incr i
if {$subxml == "" } {
break
}
set censored_word [base64::decode [GetXmlAttribute $subxml imtext value]]
status_log "Found new censored regexp : $censored_word"
set evPar(regex) $censored_word
::plugins::PostEvent new_censored_regexp evPar
}
}
return 0
}
200 {
status_log "Error: Syntax error\n" red
msg_box "[trans syntaxerror]"
return 0
}
201 {
status_log "Error: Invalid parameter\n" red
msg_box "[trans invalidparameter]"
return 0
}
205 {
status_log "Warning: Invalid user $item\n" red
msg_box "[trans contactdoesnotexist]"
return 0
}
206 {
status_log "Warning: Domain name missing $item\n" red
msg_box "[trans contactdoesnotexist]"
return 0
}
208 {
status_log "Warning: Invalid username $item\n" red
msg_box "[trans invalidusername]"
return 0
}
209 {
status_log "Warning: Invalid username $item\n" red
#msg_box "[trans invalidusername]"
return 0
}
210 {
msg_box "[trans fullcontactlist]"
status_log "Warning: User list full $item\n" red
return 0
}
216 {
#status_log "Keeping connection alive\n" blue
return 0
}
224 {
#status_log "Warning: Invalid group" red
msg_box "[trans invalidgroup]"
}
416 {
msg_box [trans unavailablecountryserver]
return 0
}
500 {
::config::setKey start_ns_server [::config::getKey default_ns_server]
::config::setKey start_gateway_server [::config::getKey default_gateway_server]
if { [::config::getKey reconnect] == 1 } {
::MSN::saveOldStatus
::MSN::logout
::MSN::reconnect "[trans internalerror]"
} else {
::MSN::logout
::amsn::errorMsg "[trans internalerror]"
}
status_log "Error: Internal server error\n" red
return 0
}
600 {
::config::setKey start_ns_server [::config::getKey default_ns_server]
::config::setKey start_gateway_server [::config::getKey default_gateway_server]
if { [::config::getKey reconnect] == 1 } {
::MSN::saveOldStatus
::MSN::logout
::MSN::reconnect "[trans serverbusy]"
} else {
::MSN::logout
::amsn::errorMsg "[trans serverbusy]"
}
status_log "Error: Server is busy\n" red
return 0
}
601 {
::config::setKey start_ns_server [::config::getKey default_ns_server]
::config::setKey start_gateway_server [::config::getKey default_gateway_server]
if { [::config::getKey reconnect] == 1 } {
::MSN::saveOldStatus
::MSN::logout
::MSN::reconnect "[trans serverunavailable]"
} else {
::MSN::logout
::amsn::errorMsg "[trans serverunavailable]"
}
status_log "Error: Server is unavailable\n" red
return 0
}
715 {
#we get a weird character in PSM, need to reset it
status_log "Error: Weird PSM\n" red
::abook::setPersonal PSM ""
::MSN::logout
::MSN::reconnect ""
}
911 {
#set password ""
ns configure -stat "closed"
::MSN::logout
status_log "Error: User/Password\n" red
::amsn::errorMsg "[trans baduserpass]"
return 0
}
927 {
ns configure -stat "closed"
::MSN::logout
status_log "Error: Kids account"
::amsn::errorMsg "[trans accountkid]"
return 0
}
928 {
# Apparently, the server said invalid passport, so this server was probably cached and your account
# was moved to another server (http://www.amsn-project.net/forums/viewtopic.php?p=24823)
# We'll ask the default_ns_server for a new NS that accepts our passport.
status_log "Account was probably moved to a different server, NS says invalid passport, changing cached server to default"
::config::setKey start_ns_server [::config::getKey default_ns_server]
::config::setKey start_gateway_server [::config::getKey default_gateway_server]
::MSN::saveOldStatus
::MSN::logout
::MSN::reconnect "[trans serverunavailable]" ;#actually accountunavailable
}
931 { ;#this server doesn't know about that account
status_log "Account was moved to a different server, changing cached server to default"
::config::setKey start_ns_server [::config::getKey default_ns_server]
::config::setKey start_gateway_server [::config::getKey default_gateway_server]
::MSN::saveOldStatus
::MSN::logout
::MSN::reconnect "[trans serverunavailable]" ;#actually accountunavailable
return 0
}
"" {
return 0
}
default {
status_log "Got unknown NS input!! --> [lindex $item 0]\n\t$item" red
return 0
}
}
}
proc cmsn_ns_msg {recv message} {
if { [lindex $recv 1] != "Hotmail" && [lindex $recv 2] != "Hotmail"} {
status_log "cmsn_ns_msg: NS MSG From Unknown source ([lindex $recv 1] [lindex $recv 2]):\n$message\n" red
return
}
# Demographic Information about subscriber/user. Can be used
# for a variety of things.
set content [$message getHeader Content-Type]
if {[string range $content 0 19] == "text/x-msmsgsprofile"} {
status_log "Getting demographic and auth information\n" blue
# 1033 is English. See XXXX for info
set d(email_enabled) [$message getHeader EmailEnabled]
set d(langpreference) [$message getHeader lang_preference]
set d(preferredemail) [$message getHeader preferredEmail]
set d(country) [string toupper [$message getHeader country]]
set d(gender) [string toupper [$message getHeader Gender]]
set d(kids) [$message getHeader Kid]
set d(age) [$message getHeader Age]
#Used for authentication
set d(mspauth) [$message getHeader MSPAuth]
set d(kv) [$message getHeader kv]
set d(sid) [$message getHeader sid]
set d(sessionstart) [clock seconds]
set d(clientip) [$message getHeader ClientIP]
::abook::setDemographics d
::config::setKey myip $d(clientip)
status_log "My IP is [::config::getKey myip]\n"
# fetch localization-code from info as long as it wasn't detected/set before
if {$d(langpreference) != ""} {
::config::setKey localecode_autodetect $d(langpreference)
}
# Looks like MSN sends us whether this user has his emails enabled, so for non hotmail accounts we can automatically remove that inbox line from the CL
if { [::config::getKey checkemail] == 1 && $d(email_enabled) == 0} {
::config::setKey checkemail $d(email_enabled)
}
} else {
::hotmail::hotmail_procmsg $message
}
}
proc sso_authenticate {} {
global sso
if {[ns cget -stat] == "u" } {
set token [$sso GetSecurityTokenByName MessengerClear]
set nonce [$sso cget -nonce]
set proof [$token cget -proof]
set mbi [MBIAuthentication MBICrypt $nonce $proof]
set ticket [$token cget -ticket]
if {$ticket == "" || $proof == "" || $nonce == "" } {
eval [ns cget -autherror_handler]
return
}
if {[::config::getKey protocol] >= 18} {
::MSN::WriteSB ns "USR" "SSO S $ticket $mbi [::config::getGlobalKey machineguid]"
} else {
::MSN::WriteSB ns "USR" "SSO S $ticket $mbi"
}
ns configure -stat "us"
} elseif {[ns cget -stat] != "d" } {
status_log "Connection timeouted : state is [ns cget -stat]\n" white
::MSN::logout
::config::setKey start_ns_server [::config::getKey default_ns_server]
::config::setKey start_gateway_server [::config::getKey default_gateway_server]
#Reconnect if necessary
if { [::config::getKey reconnect] == 1 } {
::MSN::reconnect "[trans connecterror]:\nConnection timed out"
return
}
msg_box "[trans connecterror]:\nConnection timed out"
}
}
proc sso_authenticated { failed } {
global sso
if {$failed == 2} {
eval [ns cget -passerror_handler]
} elseif { $failed == 0 } {
$sso configure -done 1
if { [$sso cget -nonce] != "" } {
sso_authenticate
}
} elseif { $failed == 4 } {
global reconnect_timer
set reconnect_timer 0
status_log "Profile Accrual is required"
::MSN::logout
::amsn::errorMsg "[trans profileaccrualerror]"
launch_browser "https://accountservices.passport.net/"
} else {
eval [ns cget -autherror_handler]
}
}
proc cmsn_auth {{recv ""}} {
global HOME HOME2 info
status_log "cmsn_auth starting, stat=[ns cget -stat]\n" blue
switch -- [ns cget -stat] {
a {
#Send three first commands at same time, to be faster
if { [::config::getKey protocol] == 18 } {
::MSN::WriteSB ns "VER" "MSNP18 CVR0"
::MSN::WriteSB ns "CVR" "0x0409 winnt 5.1 i386 MSNMSGR 14.0.8050.1202 msmsgs [::config::getKey login]"
} elseif { [::config::getKey protocol] == 15 } {
::MSN::WriteSB ns "VER" "MSNP15 CVR0"
::MSN::WriteSB ns "CVR" "0x0409 winnt 5.1 i386 MSNMSGR 8.0.0812 msmsgs [::config::getKey login]"
} else {
::MSN::WriteSB ns "VER" "MSNP12 CVR0"
::MSN::WriteSB ns "CVR" "0x0409 winnt 5.1 i386 MSNMSGR 8.0.0812 msmsgs [::config::getKey login]"
}
if { [::config::getKey protocol] >= 15 } {
::MSN::WriteSB ns "USR" "SSO I [::config::getKey login]"
} else {
::MSN::WriteSB ns "USR" "TWN I [::config::getKey login]"
}
ns configure -stat "v"
return 0
}
v {
if { [::config::getKey protocol] == 18 } {
set ver "MSNP18"
} elseif { [::config::getKey protocol] == 15 } {
set ver "MSNP15"
} else {
set ver "MSNP12"
}
if {[lindex $recv 0] != "VER"} {
status_log "cmsn_auth: was expecting VER reply but got a [lindex $recv 0]\n" red
return 1
} elseif {[lsearch -exact $recv $ver] != -1} {
status_log "Logged in with protocol $ver"
ns configure -stat "i"
return 0
} else {
status_log "cmsn_auth: could not negotiate protocol!\n" red
return 1
}
}
i {
if {[lindex $recv 0] != "CVR"} {
status_log "cmsn_auth: was expecting CVR reply but got a [lindex $recv 0]\n" red
return 1
} else {
ns configure -stat "u"
if { [::config::getKey protocol] >= 15 } {
if {[info exists ::sso] && $::sso != "" } {
$::sso destroy
set ::sso ""
}
set ::sso [::SSOAuthentication create %AUTO% -username [::config::getKey login] -password $::password]
if {[info exists ::roaming] } {
catch {$::roaming destroy}
unset ::roaming
}
set ::roaming [::ContentRoaming create %AUTO%]
if {[info exists ::ab] } {
catch {$::ab destroy}
unset ::ab
}
set ::ab [::Addressbook create %AUTO%]
$::sso Authenticate [list sso_authenticated]
}
return 0
}
}
u {
if { [::config::getKey protocol] >= 15 } {
if {([lindex $recv 0] != "USR") || \
([lindex $recv 2] != "SSO") || \
([lindex $recv 3] != "S")} {
status_log "cmsn_auth: was expecting USR x SSO S xxxxx but got something else!\n" red
return 1
}
global sso
$sso configure -nonce [lindex $recv 5]
if { [$sso cget -done] } {
sso_authenticate
}
} else {
if {([lindex $recv 0] != "USR") || \
([lindex $recv 2] != "TWN") || \
([lindex $recv 3] != "S")} {
status_log "cmsn_auth: was expecting USR x TWN S xxxxx but got something else!\n" red
return 1
}
foreach x [split [lrange $recv 4 end] ","] { set info([lindex [split $x "="] 0]) [lindex [split $x "="] 1] }
set info(all) [lrange $recv 4 end]
global login_passport_url
if { $login_passport_url == 0 } {
status_log "cmsn_auth: Nexus didn't reply yet...\n"
set login_passport_url $info(all)
} else {
status_log "cmsn_auth: Nexus has replied so we have login URL...\n"
set proxy [ns cget -proxy]
$proxy authenticate $info(all) $login_passport_url
}
}
return 0
}
us {
if {[lindex $recv 0] != "USR"} {
status_log "cmsn_auth: was expecting USR reply but got a [lindex $recv 0]\n" red
return 1
}
if {[lindex $recv 2] != "OK"} {
status_log "cmsn_auth: error authenticating with server!\n" red
return 1
}
ns configure -stat "o"
save_config ;# CONFIG
::config::saveGlobal
set abook_cached 1
if { [::abook::loadFromDisk] < 0 } {
set abook_cached 0
::abook::clearData
::abook::setConsistent
}
#Don't use cached abook if using default profile
if { $HOME == $HOME2 } {
set abook_cached 0
}
::abook::setPersonal login [lindex $recv 3]
::config::setKey emailVerified [lindex $recv 4]
#We need to wait until the SYN reply comes, or we can send the CHG request before
#the server sends the list, and then it won't work (all contacts offline)
if { [config::getKey protocol] >= 13 } {
if {![info exists ::ab]} {
set ::ab [::Addressbook create %AUTO%]
}
if {$abook_cached} {
::MSN::makeLists
::MSN::ABSynchronizationDone 1 0
after 500 {$::ab Synchronize [list ::MSN::ABSynchronizationDone 0]}
} else {
::abook::setPersonal MFN ""
$::ab Synchronize [list ::MSN::ABSynchronizationDone 1]
}
} else {
set list_version [::abook::getContactData contactlist list_version]
#If the value is invalid, we will be disconnected from server
if { ![regexp {^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}.[0-9]+-[0-9]{2}:[0-9]{2}$} $list_version] } {
set list_version "0"
::abook::setContactData contactlist list_version "0"
}
set cl_version [::abook::getContactData contactlist cl_version]
if { ![regexp {^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}.[0-9]+-[0-9]{2}:[0-9]{2}$} $cl_version] } {
set cl_version "0"
::abook::setContactData contactlist cl_version "0"
}
::MSN::WriteSB ns "SYN" "$cl_version $list_version" initial_syn_handler
}
#Alert dock of status change
send_dock "MAIL" 0
#Send "loggedIn" core event
::Event::fireEvent loggedIn protocol
#Send event "OnConnect" to plugins when we connect
::plugins::PostEvent OnConnect evPar
return 0
}
}
return -1
}
proc ::MSN::ABSynchronizationDone { initial error } {
if {$error != -2 } {
if {$error != 0} {
::amsn::errorMsg "[trans abookerror]"
}
::MSN::contactListChanged
set contacts [::MSN::getList FL]
set contacts [concat $contacts [::MSN::getList AL]]
set contacts [concat $contacts [::MSN::getList BL]]
set contacts [lsort -unique $contacts]
set xml "<ml l=\"1\">"
array set domains {}
foreach contact $contacts {
set contact [split $contact "@"]
set user [lindex $contact 0]
set domain [lindex $contact 1]
lappend domains($domain) $user
}
foreach {domain users} [array get domains] {
append xml "<d n=\"$domain\">"
set added_users 0
foreach user $users {
set lists [::abook::getLists "$user@$domain"]
set mask 0
if {[lsearch $lists "FL"] != -1} {
incr mask 1
}
if {[lsearch $lists "AL"] != -1} {
incr mask 2
}
if {[lsearch $lists "BL"] != -1} {
incr mask 4
}
# Make sure we don't have a contact in AL and BL at the same time
if {[expr {$mask & 6}] == 6} {
after 0 [list ::MSN::removeUserFromList "$user@$domain" AL]
incr mask -2
}
if {$added_users > 0 && [expr {[string length $xml] + [string length "<c n=\"$user\" l=\"$mask\" t=\"1\" /></d></ml>"]}] > 7400} {
append xml "</d></ml>"
set xmllen [string length $xml]
::MSN::WriteSBNoNL ns "ADL" "$xmllen\r\n$xml" [list ns handleADLResponse]
set xml "<ml l=\"1\">"
append xml "<d n=\"$domain\">"
}
incr added_users
append xml "<c n=\"$user\" l=\"$mask\" t=\"1\" />"
}
append xml "</d>"
}
append xml "</ml>"
set xmllen [string length $xml]
::MSN::WriteSBNoNL ns "ADL" "$xmllen\r\n$xml" [list ns handleADLResponse]
foreach username [::MSN::getList PL] {
if { [lsearch [::abook::getLists $username] "AL"] != -1 || [lsearch [::abook::getLists $username] "BL"] != -1 } {
#We already added it we only move it from PL to RL
#Just add to RL for now and let the handler remove it from PL... to be sure it's the correct order...
::MSN::removeUserFromList $username PL
::MSN::addUserToList $username RL
} else {
set nickname [::abook::getContactData $username nick]
if {$nickname == "" } {
set nickname $username
}
newcontact $username $nickname
}
}
foreach username [::MSN::getList RL] {
if { [lsearch [::abook::getLists $username] "AL"] == -1 && [lsearch [::abook::getLists $username] "BL"] == -1 } {
set nickname [::abook::getContactData $username nick]
if {$nickname == "" } {
set nickname $username
}
#newcontact $username $nickname
}
}
::groups::Enable
if {$initial } {
ns setInitialStatus
}
ns authenticationDone
} elseif {$error == 2 } {
#ABDoesNotExist
$::ab ABAdd ::MSN::ABAddDone [::config::getKey login]
}
}
proc ::MSN::roaming_cl_get_profile_cb { email nick date psm fail } {
if { $fail == 0 && [::abook::getVolatileData $email state FLN] == "FLN"} {
variable get_profile_update_cl_after_id
::abook::setContactData $email nick $nick
::abook::setVolatileData $email PSM $psm
# Do not send the events for nick/psm updated because of GetProfile each time we get an answer,
# because it causes the contact list to queue the redraws for the initial status change notifications (ILN),
# so it makes the contact list show your online contacts a lot later than what it can, which makes the user think amsn got slower to connect...
if { [info exists get_profile_update_cl_after_id] } {
if {[catch {set cmd [lindex [after info $get_profile_update_cl_after_id] 0]}] } {
set get_profile_update_cl_after_id [after 1000 [list ::MSN::get_profile_update_cl $email]]
} else {
after cancel $get_profile_update_cl_after_id
lappend cmd $email
set get_profile_update_cl_after_id [after 1000 $cmd]
}
} else {
set get_profile_update_cl_after_id [after 1000 [list ::MSN::get_profile_update_cl $email]]
}
}
}
proc ::MSN::get_profile_update_cl { args } {
variable get_profile_update_cl_after_id
catch {unset get_profile_update_cl_after_id}
::Event::fireEvent contactNickChange protocol $args
::Event::fireEvent contactPSMChange protocol $args
}
proc ::MSN::ABAddDone { error } {
if {$error == 0 } {
::abook::setPersonal MFN [::config::getKey login]
$::ab ABContactUpdate [list ::MSN::ABUpdateNicknameCB] "" [list contactType Me displayName [xmlencode [::abook::getPersonal MFN]]] DisplayName
$::ab Synchronize [list ::MSN::ABSynchronizationDone 1]
} else {
::MSN::logout
::amsn::errorMsg "[trans internalerror]"
}
}
proc ::MSN::ABUpdateNicknameCB { fail } {
}
proc recreate_contact_lists {} {
#There's no need to recreate groups, as ::groups already gets all data
#from ::abook
foreach groupid [::groups::GetList] {
::groups::Set $groupid [::groups::GetName $groupid]
}
#Let's put every user in their contacts list and groups
::MSN::clearList AL
::MSN::clearList BL
::MSN::clearList FL
::MSN::clearList RL
::MSN::clearList EL
foreach user [::abook::getAllContacts] {
foreach list_name [::abook::getLists $user] {
if { $list_name == "FL" } {
::abook::setVolatileData $user state FLN
}
if { $list_name == "AL" || $list_name == "BL" || $list_name == "FL" || $list_name == "RL"} {
::MSN::addToList $list_name $user
}
}
}
}
proc set_initial_nick { } {
global HOME
set nick_changed 0
# Switch to our cached nickname if the server's one is different that ours
if { [file exists [file join ${HOME} "nick.cache"]] && [::config::getKey storename] } {
set nickcache [open [file join ${HOME} "nick.cache"] r]
fconfigure $nickcache -encoding utf-8
gets $nickcache storednick
gets $nickcache custom_nick
gets $nickcache stored_login
close $nickcache
set indexofnick [string first "\$nick" $custom_nick]
if { $indexofnick >= 0 } {
set custom_nick [string replace $custom_nick $indexofnick [expr {$indexofnick + 4}] $storednick]
}
if { ($custom_nick == [::abook::getPersonal MFN]) && ($stored_login == [::abook::getPersonal login]) && ($storednick != "") } {
::MSN::changeName $storednick
set nick_changed 1
}
}
catch { file delete [file join ${HOME} "nick.cache"] }
if {$nick_changed == 0 && [config::getKey protocol] >= 15 } {
# Send our nickname to the server because it doesn't know about it!
if { [::abook::getPersonal MFN] != "" } {
::MSN::changeName [::abook::getPersonal MFN]
}
}
if { [file exists [file join ${HOME} "psm.cache"]] && [::config::getKey storename] } {
set psmcache [open [file join ${HOME} "psm.cache"] r]
fconfigure $psmcache -encoding utf-8
gets $psmcache storedpsm
gets $psmcache custom_psm
gets $psmcache stored_login
close $psmcache
set indexofpsm [string first "\$psm" $custom_psm]
if { $indexofpsm >= 0 } {
set custom_psm [string replace $custom_psm $indexofpsm [expr {$indexofpsm + 3}] $storedpsm]
}
if { ($custom_psm == [::abook::getPersonal PSM]) && ($stored_login == [::abook::getPersonal login]) } {
::MSN::changePSM $storedpsm
}
}
catch { file delete [file join ${HOME} "psm.cache"] }
}
proc initial_syn_handler {recv} {
set_initial_nick
cmsn_ns_handler $recv
return 1
}
proc msnp11_userpass_error {} {
global reconnect_timer
set reconnect_timer 0
ns configure -stat "closed"
::MSN::logout
status_log "Error: User/Password\n" red
::amsn::errorMsg "[trans baduserpass]"
}
proc msnp11_auth_error {} {
global reconnect_timer
set reconnect_timer 0
status_log "Error connecting to server\n"
::MSN::logout
::amsn::errorMsg "[trans connecterror]"
}
proc msnp11_authenticate { ticket } {
if {[ns cget -stat] == "u" } {
::MSN::WriteSB ns "USR" "TWN S $ticket"
set ::authentication_ticket $ticket
ns configure -stat "us"
} elseif {[ns cget -stat] != "d" } {
status_log "Connection timeouted : state is [ns cget -stat]\n" white
::MSN::logout
::config::setKey start_ns_server [::config::getKey default_ns_server]
::config::setKey start_gateway_server [::config::getKey default_gateway_server]
#Reconnect if necessary
if { [::config::getKey reconnect] == 1 } {
::MSN::reconnect "[trans connecterror]:\nConnection timed out"
return
}
msg_box "[trans connecterror]:\nConnection timed out"
}
return
}
proc sb_change { chatid } {
global typing
set sb [::MSN::SBFor $chatid]
if { $sb == 0 } {
status_log "sb_change: VERY BAD ERROR - SB=0\n" error
return 0
}
if { ![info exists typing($sb)] } {
set typing($sb) 1
after 4000 "unset typing($sb)"
set sock [$sb cget -sock]
set msg "MIME-Version: 1.0\r\nContent-Type: text/x-msmsgscontrol\r\nTypingUser: [::config::getKey login]\r\n\r\n\r\n"
set msg_len [string length $msg]
#::MSN::WriteSB $sbn "MSG" "U $msg_len"
#::MSN::WriteSBRaw $sbn "$msg"
::MSN::WriteSBNoNL $sb "MSG" "U $msg_len\r\n$msg" ""
}
}
proc ::MSN::SendRecordingUserNotification { chatid } {
set sb [::MSN::SBFor $chatid]
if { $sb == 0 } {
status_log "SendRecordingUserNotification: VERY BAD ERROR - SB=0\n" error
return 0
}
set sock [$sb cget -sock]
set msg "MIME-Version: 1.0\r\nContent-Type: text/x-msmsgscontrol\r\nRecordingUser: [::config::getKey login]\r\n\r\n\r\n"
set msg_len [string length $msg]
::MSN::WriteSBNoNL $sb "MSG" "U $msg_len\r\n$msg"
}
###################### Other Features ###########################
proc ns_enter {} {
set command "[.status.enter get]"
.status.enter delete 0 end
status_log "Executing : $command\n"
if { [string range $command 0 0] == "/"} {
#puts -nonewline [ns cget -sock] "[string range $command 1 [string length $command]]\r\n"
::MSN::WriteSBRaw ns "[string range $command 1 [string length $command]]\r\n"
} elseif {$command != ""} {
if {[catch {eval $command} res]} {
::amsn::errorMsg "$res"
} else {
status_log "$res\n"
}
}
}
proc setup_connection {name} {
#This is the default read handler, if not changed by proxy
#This is the default procedure that should be called when an error is detected
#$name configure -error_handler [list ::MSN::CloseSB $name]
if {![catch {[$name cget -proxy] cget -name}]} {
#The connection already has a Proxy defined so we clean it
[$name cget -proxy] finish $name
[$name cget -proxy] destroy
}
$name configure -proxy [Proxy create %AUTO%]
if {[::config::getKey connectiontype] == "direct" } {
#$name configure -connection_wrapper DirectConnection
$name configure -proxy_host ""
$name configure -proxy_port ""
} elseif {[::config::getKey connectiontype] == "http"} {
#$name configure -connection_wrapper HTTPConnection
$name configure -proxy_host ""
$name configure -proxy_port ""
#status_log "cmsn_socket: Setting up http connection\n" green
#set tmp_serv "gateway.messenger.hotmail.com"
#set tmp_port 80
#::Proxy::Init "$tmp_serv:$tmp_port" "http"
#::Proxy::OnCallback "dropped" "proxy_callback"
#status_log "cmsn_socket: Calling proxy::Setup now\n" green
#::Proxy::Setup next readable_handler $name
} elseif { [::config::getKey connectiontype] == "proxy" && [::config::getKey proxytype] == "http" } {
#TODO: Right now it's always HTTP proxy!!
#$name configure -connection_wrapper HTTPConnection
set proxy [::config::getKey proxy]
$name configure -proxy_host [lindex $proxy 0]
$name configure -proxy_port [lindex $proxy 1]
$name configure -proxy_authenticate [::config::getKey proxyauthenticate]
$name configure -proxy_user [::config::getKey proxyuser]
$name configure -proxy_password [::config::getKey proxypass]
#set proxy [$name cget -proxy]
#status_log "cmsn_socket: Setting up Proxy connection (type=[::config::getKey proxytype])\n" green
#$proxy Init [::config::getKey proxy] [::config::getKey proxytype]
#$proxy LoginData [::config::getKey proxyauthenticate] [::config::getKey proxyuser] [::config::getKey proxypass]
#set proxy_serv [split [::config::getKey proxy] ":"]
#set tmp_serv [lindex $proxy_serv 0]
#set tmp_port [lindex $proxy_serv 1]
#$proxy OnCallback "dropped" "proxy_callback"
#status_log "cmsn_connect: Calling proxy::Setup now\n" green
#$proxy Setup next readable_handler $name
} elseif { [::config::getKey connectiontype] == "proxy" && [::config::getKey proxytype] == "socks5" } {
#We set the parameters for the SOCKS5 proxy
set proxy [::config::getKey proxy]
$name configure -proxy_host [lindex $proxy 0]
$name configure -proxy_port [lindex $proxy 1]
$name configure -proxy_authenticate [::config::getKey proxyauthenticate]
$name configure -proxy_user [::config::getKey proxyuser]
$name configure -proxy_password [::config::getKey proxypass]
} else {
#$name configure -connection_wrapper DirectConnection
::config::setKey connectiontype "direct"
$name configure -proxy_host ""
$name configure -proxy_port ""
}
}
proc cmsn_socket {name} {
$name configure -time [clock seconds]
$name configure -stat "cw"
$name configure -error_msg ""
set proxy [$name cget -proxy]
if {[catch {$proxy cget -name}] } {
#The proxy was deleted
$name configure -proxy [Proxy create %AUTO%]
}
if {[$proxy connect $name]<0} {
::MSN::CloseSB $name
}
degt_protocol "< Connected to: [$name cget -server] >"
}
proc cmsn_ns_connected {sock} {
fileevent $sock writable ""
set error_msg ""
set therewaserror [catch {set error_msg [fconfigure [ns cget -sock] -error]} res]
if { ($error_msg != "") || $therewaserror == 1 } {
ns configure -error_msg $error_msg
::config::setKey start_ns_server [::config::getKey default_ns_server]
::config::setKey start_gateway_server [::config::getKey default_gateway_server]
status_log "cmsn_ns_connected ERROR: $error_msg\n" red
::MSN::CloseSB ns
return
}
ns configure -stat "a"
cmsn_auth
if {[::config::getKey enablebanner] && [::config::getKey adverts]} {
adv_resume
}
}
#TODO: ::abook system
proc cmsn_ns_connect { username {password ""} {nosignin ""} } {
global last_iln
if { ($username == "") || ($password == "")} {
return -1
}
set last_iln 0
::MSN::clearList FL
::MSN::clearList AL
::MSN::clearList BL
::MSN::clearList RL
::MSN::clearList PL
::MSN::clearList EL
if {[ns cget -stat] != "d"} {
set proxy [ns cget -proxy]
$proxy finish ns
}
ns configure -stat "c"
if { $nosignin == "" } {
cmsn_draw_signin
}
::MSN::StartPolling
::groups::Reset
#TODO: Call "on connect" handlers, where hotmail will be registered.
set ::hotmail::unread 0
ns configure -autherror_handler "msnp11_auth_error"
ns configure -passerror_handler "msnp11_userpass_error"
ns configure -ticket_handler "msnp11_authenticate"
ns configure -connected "cmsn_ns_connected"
cmsn_socket ns
return 0
}
proc process_msnp11_lists { bin } {
set lists [list]
if { $bin == "" } {
status_log "process_msnp11_lists: No lists!!!\n" red
return $lists
}
if { $bin & 1 } {
lappend lists "FL"
}
if { $bin & 2 } {
lappend lists "AL"
}
if { $bin & 4 } {
lappend lists "BL"
}
if { $bin & 8 } {
lappend lists "RL"
}
if { $bin & 16 } {
lappend lists "PL"
}
return $lists
}
proc urldecode {str} {
#New version, no need of url_unmap
set str [encoding convertto utf-8 $str]
set begin 0
set end [string first "%" $str $begin]
set decode ""
while { $end >=0 } {
set decode "${decode}[string range $str $begin [expr {$end-1}]]"
#TODO: Here, why some nicks can have thins like %he ??? why is it allowed if they're encoded
# using ulrencode??? We "catch" the error and try another thing.
set hexvalue [string range $str [expr {$end+1}] [expr {$end+2}]]
if {[catch {set carval [format %d 0x$hexvalue]} res]} {
set decode "${decode}\%"
set begin [expr {$end+1}]
} else {
if {$carval > 128} {
set carval [expr { $carval - 0x100 }]
}
set car [binary format c $carval]
set decode "${decode}$car"
#if {[catch {set decode2 "${decode2}[format %c 0x[string range $str [expr {$end+1}] [expr {$end+2}]]]"} res]} {
# catch {set decode2 "${decode2}[format %c 0x[string range $str [expr {$end+1}] [expr {$end+1}]]]"} res
#}
set begin [expr {$end+3}]
}
set end [string first "%" $str $begin]
}
set decode ${decode}[string range $str $begin [string length $str]]
#status_log "urldecode: original:$str\n decoded=$decode\n un-utf-8=[encoding convertfrom utf-8 $decode]\n"
return [encoding convertfrom utf-8 $decode]
}
proc urlencode_all {str} {
set encode ""
set utfstr [encoding convertto utf-8 $str]
for {set i 0} {$i<[string length $utfstr]} {incr i} {
set character [string range $utfstr $i $i]
binary scan $character c charval
#binary scan $character s charval
set charval [expr {($charval + 0x100) % 0x100}]
#set charval [expr {( $charval + 0x10000 ) % 0x10000}]
if {$charval <= 0xFF} {
set encode "${encode}%[format %.2X $charval]"
} else {
status_log "urlencode_all: THIS SHOULDN'T HAPPEN, CHECK IT IN proc urlencode!!!\n" white
#set charval1 [expr {$charval & 0xFF} ]
#set charval2 [expr {$charval >> 8}]
#set encode "${encode}$character"
}
}
#status_log "urlencode: original=$str\n utf-8=$utfstr\n encoded=$encode\n"
if {[string length $encode] <=387 } {
return $encode
} else {
return [string range $encode 0 349]
}
}
proc urlencode {str} {
# global url_map
set encode ""
set utfstr [encoding convertto utf-8 $str]
for {set i 0} {$i<[string length $utfstr]} {incr i} {
set character [string range $utfstr $i $i]
if {[string match {[^a-zA-Z0-9()]} $character]==0} {
binary scan $character c charval
#binary scan $character s charval
set charval [expr {($charval + 0x100) % 0x100}]
#set charval [expr {( $charval + 0x10000 ) % 0x10000}]
if {$charval <= 0xFF} {
set encode "${encode}%[format %.2X $charval]"
} else {
status_log "urlencode: THIS SHOULDN'T HAPPEN, CHECK proc urlencode!!!\n" white
#set charval1 [expr {$charval & 0xFF} ]
#set charval2 [expr {$charval >> 8}]
#set encode "${encode}$character"
}
} else {
set encode "${encode}${character}"
}
}
#status_log "urlencode: original=$str\n utf-8=$utfstr\n encoded=$encode\n"
if {[string length $encode] <=387 } {
return $encode
} else {
return [string range $encode 0 349]
}
}
proc change_BLP_settings { state } {
global list_BLP
if { "$state" == "AL" } {
set list_BLP 1
} elseif { "$state" == "BL" } {
set list_BLP 0
} else {
set list_BLP -1
}
}
proc new_contact_list { cl_version list_version } {
global contactlist_loaded
set old_list_version [::abook::getContactData contactlist list_version]
set old_cl_version [::abook::getContactData contactlist cl_version]
status_log "new_contact_list: new contact list version : $list_version $cl_version --- previous was : $old_list_version $old_cl_version\n"
if { ($old_list_version eq $list_version) && ($old_cl_version eq $cl_version) } {
return 0
} else {
::abook::setContactData contactlist list_version $list_version
::abook::setContactData contactlist cl_version $cl_version
return 1
}
}
proc getCensoredWords { } {
catch {::MSN::WriteSB ns GCF Shields.xml}
}
proc checking_package_tls { } {
global tlsinstalled
if { [catch {package require tls}] } {
# Either tls is not installed, or $auto_path does not point to it.
# Should now never happen; the check for the presence of tls is made
# before this point.
# status_log "Could not find the package tls on this system.\n"
set tlsinstalled 0
return 0
} else {
set tlsinstalled 1
return 1
}
}
proc create_msnobj { Creator type filename {friendly "AAA="} {stamp ""}} {
global msnobjcontext
if { [file exists $filename] == 0 } { return "" }
set fd [open $filename r]
fconfigure $fd -translation binary
set data [read $fd]
close $fd
set file [filenoext [getfilename $filename]]
set size [string length $data]
set sha1d [::base64::encode [binary format H* [::sha1::sha1 $data]]]
set sha1c [::base64::encode [binary format H* [::sha1::sha1 "Creator${Creator}Size${size}Type${type}Location${file}.tmpFriendly${friendly}SHA1D${sha1d}"]]]
set msnobj "<msnobj Creator=\"$Creator\" Size=\"$size\" Type=\"$type\" Location=\"[urlencode $file].tmp\" Friendly=\"${friendly}\" SHA1D=\"$sha1d\" SHA1C=\"$sha1c\""
if { $stamp == "" } {
append msnobj "/>"
} else {
append msnobj " stamp=\"$stamp\"/>"
}
set msnobjcontext($msnobj) $filename
return $msnobj
}
proc getfilename { filename } {
return "[file tail $filename]"
}
proc filenoext { filename } {
if {[string last . $filename] != -1 } {
return "[string range $filename 0 [expr [string last . $filename] - 1]]"
} else {
return $filename
}
}
proc fileext { filename } {
if {[string last . $filename] != -1 } {
return "[string range $filename [string last . $filename] end]"
} else {
return ""
}
}
#############################################################
# xclientcaps_received msg chatid #
# ----------------------------------------------------------#
# Packets received from 3rd party client (not by MSN) #
# Add the information to ContactData #
# More information: #
# http://www.chat.solidhouse.com/msninterop/clientcaps.php #
#############################################################
proc xclientcaps_received {msg chatid} {
#Get String for Client-Name (Gaim, dMSN and others)
set clientname [$msg getHeader "Client-Name"]
if { $clientname == "" } {
set clientname [$msg getField "Client-Name"]
}
::abook::setContactData $chatid clientname $clientname
set chatlogging [$msg getHeader "Chat-Logging"]
if { $chatlogging == "" } {
set chatlogging [$msg getField "Chat-Logging"]
}
::abook::setContactData $chatid chatlogging $chatlogging
set operatingsystem [$msg getHeader "Operating-System"]
if { $clientname == "" } {
set operatingsystem [$msg getField "Operating-System"]
}
::abook::setContactData $chatid operatingsystem $operatingsystem
}
#################################################
# add_Clientid chatid clientid #
# --------------------------------------------- #
# Look for clientid information #
# Add it to ContactData #
# More information: #
# http://ceebuh.info/docs/?url=clientid.html #
#################################################
# id bit capability #
# 0x00000001 Mobile Device #
# 0x00000002 Unknown #
# 0x00000004 Ink Viewing #
# 0x00000008 Ink Creating #
# 0x00000010 Webcam #
# 0x00000020 Multi-Packeting #
# 0x00000040 Paging #
# 0x00000080 Direct-Paging #
# 0x00000200 WebMessenger #
# 0x00001000 Unknown (Msgr 7 always[?] sets it) #
# 0x00004000 DirectIM #
# 0x00008000 Winks #
#################################################
proc add_Clientid {chatid clientid} {
##First save the clientid (number)
::abook::setContactData $chatid clientid $clientid
##Find out how the client-program is called
set version [::MSN::clientCapsVersion $clientid]
if {$version == 10} {
set clientname "Windows Live Messenger 2009"
} elseif {$version == 9} {
set clientname "Windows Live Messenger 9 beta"
} elseif {$version == 8} {
set clientname "Windows Live Messenger 8.5"
} elseif {$version == 7} {
set clientname "Windows Live Messenger 8.1"
} elseif {$version == 6} {
set clientname "Windows Live Messenger 8.0"
} elseif {$version == 5} {
set clientname "MSN 7.5"
} elseif {$version == 4} {
set clientname "MSN 7.0"
} elseif {$version == 3} {
set clientname "MSN 6.2"
} elseif {$version == 2} {
set clientname "MSN 6.1"
} elseif {$version == 1} {
set clientname "MSN 6.0"
} elseif {[::MSN::hasCapability $clientid webmsn] } {
set clientname "Webmessenger"
} elseif {[::MSN::hasCapability $clientid tgw] } {
set clientname "Microsoft Office gateway"
} else {
set clientname "[trans unknown]"
}
##Store the name of the client this user uses in the adressbook
::abook::setContactData $chatid client $clientname
##Set the capability flags for this user##
::abook::setContactData $chatid webcam_shared [::MSN::hasCapability $clientid webcam]
}
###############################################
# system_message msg #
# ------------------------------------------- #
# Show an alert when the server send the #
# message that MSN going down for maintenance #
# in $minute minutes. #
###############################################
proc system_message {msg} {
if {[string first "Arg1:" $msg] != "-1"} {
#Find the minute variable
set minute [$message getHeader Arg1]
status_log "Server close for maintenance in -$minute- minutes"
#Show the alert
::amsn::messageBox [trans maintenance $minute] ok error
}
}
proc myRand { min max } {
return [expr {int($min + rand() * (1+$max-$min))}]
}
proc binword { word } {
if {$word == "" || [string is digit $word] == 0 } {
set word 0
}
return [binary format ii $word 0]
#return [binary format ii [expr $word % 4294967296] [expr ( $word - ( $word % 4294967296)) / 4294967296 ]]
}
proc ToLittleEndian { bin length } {
if { $::tcl_platform(byteOrder) == "littleEndian" } { return "$bin"}
if { $length == 2 } { set type s } elseif {$length == 4} { set type i } else { return "$bin"}
set binout ""
incr length -1
while { $bin != "" } {
set in [string range $bin 0 $length]
binary scan $in [string toupper $type] out
set out [binary format $type $out]
set binout "${binout}${out}"
set bin [string replace $bin 0 $length]
}
return $binout
}
proc ToBigEndian { bin length } {
if { $::tcl_platform(byteOrder) == "littleEndian" } { return "$bin"}
if { $length == 2 } { set type S } elseif {$length == 4} { set type I } else { return "$bin"}
set binout ""
incr length -1
while { [string length $bin] > $length } {
set in [string range $bin 0 $length]
binary scan $in [string tolower $type] out
set out [binary format $type $out]
set binout "${binout}${out}"
set bin [string replace $bin 0 $length]
}
return $binout
}
proc ToUnicode { text } {
#status_log "Converting $text to unicode\n" red
# set text [encoding convertfrom $text]
#status_log "text msg is : $text\n" red
set text [encoding convertto unicode $text]
#status_log "text msg is : $text\n" red
#set text [binary format a* $text]
#status_log "text msg is : $text\n" red
set text [ToLittleEndian $text 2]
#status_log "text msg is : $text\n" red
return $text
}
proc FromUnicode { text } {
#status_log "Converting $text from unicode\n" red
#binary scan $text A* text
#status_log "text msg is : $text\n" red
set text [ToBigEndian "$text" 2]
#status_log "text msg is : $text\n" red
set text [encoding convertfrom unicode "$text"]
#status_log "text msg is : $text\n" red
# set text [encoding convertto "$text"]
#status_log "text msg is : $text\n" red
return $text
}
proc int2word { int1 int2 } {
#if { $int2>0} {
# status_log "Warning!!!! int was a 64-bit integer!! Ignoring for tcl/tk 8.3 compatibility!!!!\n" white
#}
#return $int1
return [expr $int2 * 4294967296 + $int1]
}
namespace eval ::MSN6FT {
namespace export SendFT AcceptFT RejectFT handleMsnFT
proc SendFT { chatid filename filesize} {
global HOME
status_log "Sending File $filename with size $filesize to $chatid\n"
set sid [expr {int(rand() * 1000000000)%125000000 + 4}]
# Generate BranchID and CallID
set branchid "[format %X [myRand 4369 65450]][format %X [myRand 4369 65450]]-[format %X [myRand 4369 65450]]-[format %X [myRand 4369 65450]]-[format %X [myRand 4369 65450]]-[format %X [myRand 4369 65450]][format %X [myRand 4369 65450]][format %X [myRand 4369 65450]]"
set callid "[format %X [myRand 4369 65450]][format %X [myRand 4369 65450]]-[format %X [myRand 4369 65450]]-[format %X [myRand 4369 65450]]-[format %X [myRand 4369 65450]]-[format %X [myRand 4369 65450]][format %X [myRand 4369 65450]][format %X [myRand 4369 65450]]"
set dest [lindex [::MSN::usersInChat $chatid] 0]
# set session [::MSNP2P::Session %AUTO% -totalsize $filesize -dest $dest -callid $callid \
# -type "filetransfer" -filename $filename -branchid $branchid]
# ::MSNP2P::putSession $sid $session
# status_log "branchid : [::MSNP2P::$sessions($sid) cget -branchid]\n"
::MSNP2P::SessionList set $sid [list 0 $filesize 0 $dest 0 $callid 0 "filetransfer" "$filename" "$branchid"]
setObjOption $sid chatid $chatid
status_log "branchid : [lindex [::MSNP2P::SessionList get $sid] 9]\n"
set ext [string tolower [string range [fileext $filename] 1 end]]
if { $ext == "jpg" || $ext == "gif" || $ext == "png" || $ext == "bmp" || $ext == "jpeg" || $ext == "tga" } {
set nopreview 0
} else {
set nopreview 1
}
# If the advanced option to not send the preview is enabled, we force it not to send any preview
if {[::config::getKey noftpreview]} {
set nopreview 1
}
# TODO filesize is a QWORD not a DWORD followed by a 0 DWORD.
set context "[binary format i 574][binary format i 2][binary format i $filesize][binary format i 0][binary format i $nopreview]"
set file [ToUnicode [getfilename $filename]]
set file [binary format a550 $file]
set context "${context}${file}\xFF\xFF\xFF\xFF"
if { $nopreview == 0 } {
#Here we resize the picture and save it in /FT/cache for the preview (we send it and we see it)
create_dir [file join $HOME FT cache]
if {[catch {set image [image create photo [TmpImgName] -file $filename]}]} {
set image [::skin::getNoDisplayPicture]
}
if {[catch {::picture::ResizeWithRatio $image 96 96} res]} {
status_log $res
}
set file "[file join $HOME FT cache ${callid}.png]"
if {[catch {::picture::Save $image $file cxpng} res] } {
status_log $res
}
if {$image != [::skin::getNoDisplayPicture]} {
image delete $image
}
::skin::setPixmap ${callid}.png $file
if { [catch { open $file} fd] == 0 } {
fconfigure $fd -translation {binary binary }
set context "$context[read $fd]"
close $fd
}
#Show the preview picture in the window
if { [::skin::loadPixmap "${callid}.png"] != "" } {
::amsn::WinWrite $chatid "\n" green
::amsn::WinWriteIcon $chatid ${callid}.png 5 5
::amsn::WinWrite $chatid "\n" green
}
}
# Create and send our packet
set slpdata [::MSNP2P::MakeMSNSLP "INVITE" $dest [::config::getKey login] $branchid 0 $callid 0 0 "5D3E02AB-6190-11D3-BBBB-00C04F795683" $sid 2 \
[string map { "\n" "" } [::base64::encode "$context"]]]
::MSNP2P::SendPacketExt [::MSN::SBFor $chatid] $sid $slpdata 1
status_log "Sent an INVITE to [::MSN::usersInChat $chatid] on chatid $chatid for filetransfer of filename $filename\n" red
#added a return to be able to fetch sid...
return $sid
}
proc GotPhotoSharingInvitation {chatid} {
SendMessageFIFO [list ::MSN6FT::GotPhotoSharingInvitationWrapped $chatid] "::amsn::messages_stack($chatid)" "::amsn::messages_flushing($chatid)"
}
#Show a message when we receive a photo sharing invitation so the user isn't clueless
proc GotPhotoSharingInvitationWrapped {chatid} {
#Grey line
::amsn::WinWrite $chatid "\n" green
::amsn::WinWriteIcon $chatid greyline 3
::amsn::WinWrite $chatid " \n" green
#Description of the problem
::amsn::WinWrite $chatid "[timestamp] [trans photosharingrequest]\n" green
}
proc SharePhoto { chatid filename filesize} {
global HOME
status_log "Sending File $filename with size $filesize to $chatid\n"
set sid [expr {int(rand() * 1000000000)%125000000 + 4}]
# Generate BranchID and CallID
set branchid "[format %X [myRand 4369 65450]][format %X [myRand 4369 65450]]-[format %X [myRand 4369 65450]]-[format %X [myRand 4369 65450]]-[format %X [myRand 4369 65450]]-[format %X [myRand 4369 65450]][format %X [myRand 4369 65450]][format %X [myRand 4369 65450]]"
set callid "[format %X [myRand 4369 65450]][format %X [myRand 4369 65450]]-[format %X [myRand 4369 65450]]-[format %X [myRand 4369 65450]]-[format %X [myRand 4369 65450]]-[format %X [myRand 4369 65450]][format %X [myRand 4369 65450]][format %X [myRand 4369 65450]]"
set dest [lindex [::MSN::usersInChat $chatid] 0]
::MSNP2P::SessionList set $sid [list 0 $filesize 0 $dest 0 $callid 0 "photo" "$filename" "$branchid"]
setObjOption $sid chatid $chatid
status_log "branchid : [lindex [::MSNP2P::SessionList get $sid] 9]\n"
# Create and send our packet
set slpdata [::MSNP2P::MakeMSNSLP "INVITE" $dest [::config::getKey login] $branchid 0 $callid 0 0 "41D3E74E-04A2-4B37-96F8-08ACDB610874" $sid 35]
::MSNP2P::SendPacketExt [::MSN::SBFor $chatid] $sid $slpdata 1
status_log "Sent an INVITE to [::MSN::usersInChat $chatid] on chatid $chatid for filetransfer of filename $filename\n" red
#added a return to be able to fetch sid...
return $sid
}
proc SendFTInvite { sid chatid} {
# Remote user has just accepted our FT invitation
::amsn::DisableCancelText [getObjOption $sid theCookie] $chatid
set session [::MSNP2P::SessionList get $sid]
set branchid [lindex $session 9]
set callid [lindex $session 5]
set dest [lindex $session 3]
set filename [lindex $session 8]
status_log "branchid : $branchid\n" red
set netid [abook::getDemographicField netid]
set conntype [abook::getDemographicField conntype]
set upnp [abook::getDemographicField upnpnat]
if { $netid == "" || $conntype == "" } {
abook::getIPConfig
set netid [abook::getDemographicField netid]
set conntype [abook::getDemographicField conntype]
if { $netid == "" } { set netid 0 }
if { $conntype == "" } {set conntype "Firewall" }
}
::amsn::FTProgress a $sid $filename $dest 1000 $chatid
::MSNP2P::SessionList set $sid [list -1 -1 -1 -1 "INVITE1" -1 -1 -1 -1 -1]
set slpdata [::MSNP2P::MakeMSNSLP "INVITE" $dest [::config::getKey login] $branchid 0 $callid 0 1 "TCPv1 SBBridge" \
$netid $conntype $upnp "false"]
::MSNP2P::SendPacket [::MSN::SBFor $chatid] [::MSNP2P::MakePacket $sid $slpdata 1]
#after 5000 "::MSNP2P::SendDataFile $sid $chatid [list [lindex [::MSNP2P::SessionList get $sid] 8]] \"INVITE1\""
}
proc SendFTInvite2 { sid chatid} {
set session [::MSNP2P::SessionList get $sid]
set branchid [lindex $session 9]
set callid [lindex $session 5]
set dest [lindex $session 3]
set conntype [abook::getDemographicField conntype]
set listening [abook::getDemographicField listening]
#set listening "false"
if { [catch {set fd [open [lindex $session 8] "r"]}] } {
::MSN6FT::CancelFT $chatid $sid
::amsn::WinWriteRejectFT $chatid [trans filedoesnotexist]
return 0
}
fconfigure $fd -translation {binary binary}
::MSNP2P::SessionList set $sid [list -1 -1 -1 -1 "INVITE2" -1 $fd -1 -1 -1]
if {$listening == "true" } {
set nonce "[format %X [myRand 4369 65450]][format %X [myRand 4369 65450]]-[format %X [myRand 4369 65450]]-[format %X [myRand 4369 65450]]-[format %X [myRand 4369 65450]]-[format %X [myRand 4369 65450]][format %X [myRand 4369 65450]][format %X [myRand 4369 65450]]"
set port [OpenMsnFTPort [config::getKey initialftport] $nonce $sid 1]
set clientip [::abook::getDemographicField clientip]
set localip [::abook::getDemographicField localip]
} else {
set nonce "00000000-0000-0000-0000-000000000000"
set port ""
set clientip ""
set localip ""
}
if { $listening == "true" } {
set slpdata [::MSNP2P::MakeMSNSLP "INVITE" $dest [::config::getKey login] $branchid 1 $callid 0 2 "TCPv1" "$listening" "$nonce" "$clientip"\
"$port" "$localip" "$port"]
::MSNP2P::SendPacket [::MSN::SBFor $chatid] [::MSNP2P::MakePacket $sid $slpdata 1]
after 5000 "::MSNP2P::SendDataFile $sid $chatid [list [lindex [::MSNP2P::SessionList get $sid] 8]] \"INVITE2\""
} else {
after 5000 "::MSNP2P::SendDataFile $sid $chatid [list [lindex [::MSNP2P::SessionList get $sid] 8]] \"INVITE2\""
}
}
proc OpenMsnFTPort { port nonce sid sending} {
while { [catch {set sock [socket -server "::MSN6FT::handleMsnFT $nonce $sid $sending" $port] } ] } {
incr port
}
::abook::OpenUPnPPort $port
# TODO the server socket should be closed as soon as the user authenticated or whatever...
after 300000 "catch {close $sock}; ::abook::CloseUPnPPort $port"
::amsn::FTProgress w $sid "" $port
status_log "Opening server on port $port\n" red
return $port
}
proc handleMsnFT { nonce sid sending sock ip port } {
setObjOption $sid sending $sending
setObjOption $sock nonce $nonce
setObjOption $sock state "FOO"
setObjOption $sock server 1
setObjOption $sock sid $sid
status_log "Received connection from $ip on port $port - socket $sock\n"
fileevent $sock readable "::MSN6FT::ReadFromSock $sock"
#fileevent $sock writable "::MSN6FT::WriteToSock $sock"
fconfigure $sock -blocking 0 -buffering none -translation {binary binary}
}
proc ConnectSockets { sid nonce ip port sending } {
set ips [getObjOption $sid ips]
if { $ips == "" } {
set ips [list]
}
set nips [split $ip " "]
foreach connection $nips {
status_log "Trying to connect to $connection at port $port\n" red
set socket [connectMsnFTP $sid $nonce "$connection" $port]
if { $socket != 0 } {
lappend ips [list $connection $port $socket]
}
}
setObjOption $sid sending $sending
setObjOption $sid ips $ips
foreach connection $ips {
set sock [lindex $connection 2]
catch { fconfigure $sock -blocking 0 -buffering none -translation {binary binary} }
catch { fileevent $sock readable "::MSN6FT::CheckConnected $sid $sock " }
catch { fileevent $sock writable "::MSN6FT::CheckConnected $sid $sock " }
}
after cancel "::MSN6FT::CheckConnectSuccess $sid"
after 5000 "::MSN6FT::CheckConnectSuccess $sid"
}
proc CheckConnectSuccess { sid } {
set ips [getObjOption $sid ips]
set connected_ips [getObjOption $sid connected_ips]
status_log "we have $ips connecting sockets and $connected_ips connected sockets\n" red
after 5000 "::MSNP2P::SendDataFile $sid [getObjOption $sid chatid] [list [lindex [::MSNP2P::SessionList get $sid] 8]] \"INVITE2\""
if { [llength $ips] == 0 && [llength $connected_ips] == 0 } {
status_log "No socket was connected\n" red
#after 5000 "::MSNP2P::SendDataFile $sid [getObjOption $sid chatid] [list [lindex [::MSNP2P::SessionList get $sid] 8]] \"INVITE2\""
}
}
proc CheckConnected { sid socket} {
status_log "fileevent CheckConnectd for socket $socket\n"
fileevent $socket readable ""
fileevent $socket writable ""
if { [eof $socket] || [fconfigure $socket -error] != "" } {
status_log "Socket didn't connect $socket : [eof $socket] || [fconfigure $socket -error]\n" red
close $socket
set ips [getObjOption $sid ips]
setObjOption $sid ips [::MSNCAM::RemoveSocketFromList $ips $socket]
} else {
status_log "Connected on socket $socket : [eof $socket] || [fconfigure $socket -error]\n" red
set ips [getObjOption $sid ips]
for {set idx 0} { $idx < [llength $ips] } {incr idx } {
set connection [lindex $ips $idx]
set ip [lindex $connection 0]
set port [lindex $connection 1]
set sock [lindex $connection 2]
if {$sock == $socket } {
break
}
}
set connected_ips [getObjOption $sid connected_ips]
lappend connected_ips [list $ip $port $socket]
setObjOption $sid connected_ips $connected_ips
::amsn::FTProgress c $sid "" $ip $port
fileevent $socket readable "::MSN6FT::ReadFromSock $socket"
fileevent $socket writable "::MSN6FT::WriteToSock $socket"
CloseUnusedSockets $sid $socket
set ips [getObjOption $sid ips]
setObjOption $sid ips [::MSNCAM::RemoveSocketFromList $ips $socket]
}
# after 5000 "::MSN6FT::CheckConnectSuccess $sid"
}
proc CloseUnusedSockets { sid used_socket {list ""}} {
if { $list == "" } {
set ips [getObjOption $sid ips]
status_log "Closing ips $ips\n" red
if { $ips != "" } {
CloseUnusedSockets $sid $used_socket $ips
setObjOption $sid ips ""
}
set ips [getObjOption $sid connected_ips]
status_log "Closing connected_ips $ips\n" red
if { $ips != "" } {
CloseUnusedSockets $sid $used_socket $ips
}
status_log "resetting ips and connected_ipss\n red"
if { $used_socket != "" } {
set ips ""
if { ![catch {set ip [lindex [fconfigure $used_socket -peer] 0]
set port [lindex [fconfigure $used_socket -peer] 2]}] } {
lappend ips [list $ip $port $used_socket]
}
setObjOption $sid connected_ips $ips
}
} else {
status_log "Closing in $list of length [llength $list]\n" red
for {set idx 0 } { $idx < [llength $list] } {incr idx } {
set connection [lindex $list $idx]
set ip [lindex $connection 0]
set port [lindex $connection 1]
set sock [lindex $connection 2]
status_log "verifying $ip : $port on $sock \n" red
if {$sock == $used_socket } { continue }
status_log "Closing $sock\n" red
catch {
fileevent $sock readable ""
fileevent $sock writable ""
}
status_log "fileevents reset\n" red
catch {close $sock}
status_log "closed\n" red
}
}
status_log "Finished\n" red
}
proc connectMsnFTP { sid nonce ip port } {
if { [catch {set sock [socket -async $ip $port]}] } {
status_log "ERROR CONNECTING TO THE SERVER\n\n" red
return 0
} else {
setObjOption $sock nonce $nonce
setObjOption $sock state "FOO"
setObjOption $sock server 0
setObjOption $sock sid $sid
status_log "connectedto $ip on port $port - $sock\n"
return $sock
}
}
proc ReadFromSock { sock } {
set sid [getObjOption $sock sid]
set state [getObjOption $sock state]
set server [getObjOption $sock server]
set sending [getObjOption $sid sending]
set tmpsize 0
set data [getObjOption $sock buffer]
set size [getObjOption $sock size]
if { $sid == "" } {
status_log "Can't find sid for socket $sock!!! ERROR" red
close $sock
return
}
#Check if we have any data in the buffer
#If not we get size in next packet
if { $size == 0 || $size == "" } {
set size ""
while { $tmpsize < 4 && ![eof $sock] } {
update idletasks
set tmpdata [read $sock [expr {4 - $tmpsize}]]
append size $tmpdata
set tmpsize [string length $size]
}
if {$size == "" && [eof $sock] } {
status_log "FT Socket $sock closed\n"
close $sock
return
}
if { $size == "" } {
update idletasks
return
}
binary scan $size i size
setObjOption $sock size $size
set data ""
}
#We get the data
set tmpsize [string length $data]
if { $tmpsize < $size } {
set tmpdata [read $sock [expr {$size - $tmpsize}]]
append data $tmpdata
set tmpsize [string length $data]
}
if {$tmpsize == $size } {
#Data is complete we remove it from the buffer
setObjOption $sock size 0
setObjOption $sock buffer ""
if { $data == "" } {
update idletasks
return
}
switch -- $state {
"FOO"
{
if { $server && $data == "foo\x00" } {
setObjOption $sock state "NONCE_GET"
}
}
"NONCE_GET"
{
set nonce [getObjOption $sock nonce]
if { $nonce == [GetNonceFromData $data] } {
::MSNP2P::SessionList set $sid [list -1 -1 -1 -1 "DATASEND" -1 -1 -1 -1 -1]
if { $server } {
setObjOption $sock state "NONCE_SEND"
fileevent $sock writable "::MSN6FT::WriteToSock $sock"
} else {
setObjOption $sock state "CONNECTED"
if { $sending } {
fileevent $sock writable "::MSN6FT::WriteToSock $sock"
}
}
}
}
"CONNECTED"
{
set message [Message create %AUTO%]
$message setRaw $data
set p2pmessage [P2PMessage create %AUTO%]
if {[catch {$p2pmessage createFromMessage $message}] } {
status_log "ouch.. invalid data for p2p.. might be a WLM beta bug.."
} else {
if { [$p2pmessage cget -offset] == 0 } {
degt_protocol "<--DC-MSNP2P ([getObjOption $sid chatid]) $data" "sbrecv"
}
::MSNP2P::ReadData $p2pmessage [getObjOption $sid chatid]
}
catch { $p2pmessage destroy }
catch { $message destroy }
#if { [lindex [::MSNP2P::SessionList get $sid] 7] == "filetransfersuccessfull" } {
# catch { close $sock }
#}
}
default
{
catch {close $sock}
}
}
} else {
#The data we grabbed isn't integral we save actual data and we wait the next
setObjOption $sock buffer $data
}
}
proc WriteToSock { sock } {
set sid [getObjOption $sock sid]
set state [getObjOption $sock state]
set server [getObjOption $sock server]
set sending [getObjOption $sid sending]
if { $sid == "" } {
status_log "Can't find sid for socket $sock!!! ERROR" red
close $sock
return
}
fileevent $sock writable ""
set data ""
switch -- $state {
"FOO"
{
if { $server == 0 } {
set data "foo\x00"
setObjOption $sock state "NONCE_SEND"
fileevent $sock writable "::MSN6FT::WriteToSock $sock"
}
}
"NONCE_SEND"
{
set nonce [getObjOption $sock nonce]
set data "[GetDataFromNonce $nonce $sid]"
if { $server } {
setObjOption $sock state "CONNECTED"
if { $sending } {
fileevent $sock writable "::MSN6FT::WriteToSock $sock"
}
} else {
setObjOption $sock state "NONCE_GET"
}
}
"CONNECTED"
{
if { $sending && [SendFileToSock $sock] == "0" } {
setObjOption $sock sending 0
fileevent $sock writable ""
catch { close $sock }
} else {
after 5 [list fileevent $sock writable "::MSN6FT::WriteToSock $sock"]
}
}
}
if { $data != "" } {
# status_log "Writing Data on socket $sock with state $state : $data\n" red
puts -nonewline $sock "[binary format i [string length $data]]$data"
}
}
proc GetNonceFromData { data } {
set bnonce [string range $data 32 end]
binary scan $bnonce H2H2H2H2H2H2H2H2H4H* n1 n2 n3 n4 n5 n6 n7 n8 n9 n10
set nonce [string toupper "$n4$n3$n2$n1-$n6$n5-$n8$n7-$n9-$n10"]
status_log "Got NONCE : $nonce\n" red
return $nonce
}
proc GetDataFromNonce { nonce sid } {
status_log "GetDataFromNonce\n"
set n1 [string range $nonce 6 7]
set n2 [string range $nonce 4 5]
set n3 [string range $nonce 2 3]
set n4 [string range $nonce 0 1]
set n5 [string range $nonce 11 12]
set n6 [string range $nonce 9 10]
set n7 [string range $nonce 16 17]
set n8 [string range $nonce 14 15]
set n9 [string range $nonce 19 22]
set n10 [string range $nonce 24 end]
set nonce [string toupper "$n4$n3$n2$n1-$n6$n5-$n8$n7-$n9-$n10"]
status_log "Got NONCE : $nonce\n" red
set bnonce [binary format H2H2H2H2H2H2H2H2H4H* $n1 $n2 $n3 $n4 $n5 $n6 $n7 $n8 $n9 $n10]
status_log "got Binary NONCE : $bnonce\n" red
set MsgId [lindex [::MSNP2P::SessionList get $sid] 0]
incr MsgId
set data "[binary format iiiiiiii 0 $MsgId 0 0 0 0 0 256]$bnonce"
incr MsgId
status_log "Data blob ID is set to $MsgId\n" red
# Set the blob id of the current data to send
setObjOption $sid data_blob_id $MsgId
::MSNP2P::SessionList set $sid [list $MsgId -1 -1 -1 -1 -1 -1 -1 -1 -1]
return $data
}
proc CloseSocket { sock } {
#return
set sid [getObjOption $sock sid]
set MsgId [lindex [::MSNP2P::SessionList get $sid] 0]
set bheader [binary format ii 0 $MsgId][binword 0][binword 0][binary format iiii 0 4 [expr {int(rand() * 1000000000)%125000000 + 4}] 0][binword 0]
puts -nonewline $sock "[binary format i 48]$bheader"
status_log "Closing socket... \n" red
close $sock
}
proc SendFileToSock { sock } {
global msn6ft_test_nak_once
if {![info exists msn6ft_test_nak_once] } {
set msn6ft_test_nak_once 0
}
set sid [getObjOption $sock sid]
set fd [lindex [::MSNP2P::SessionList get $sid] 6]
if { [lindex [::MSNP2P::SessionList get $sid] 7] == "ftcanceled" } {
catch {close $fd }
return 0
}
if { $fd == 0 || $fd == "" } {
set filename [lindex [::MSNP2P::SessionList get $sid] 8]
set fd [open "${filename}"]
::MSNP2P::SessionList set $sid [list -1 [file size "${filename}"] -1 -1 -1 -1 $fd -1 -1 -1]
fconfigure $fd -translation {binary binary}
}
# status_log "Sending file with fd : $fd\n" red
# Take the MsgId from the session to make sure we use the same blob_id for all the file transfer
# Apparently, this could be the bug causing FTs being canceled during upload. WLM sends an MSNSLP
# message for renegociating ip/port or to notify us of out of sync, and we ack it,
# which will increment the MsgId and all subsequent data messages will use the new MsgId
# which WLM will not recognize and will not be able to link to the other data we sent.. then the FT
# times out and gets canceled.
# Thanks to the KMess team for finding this : http://www.codingdomain.com/blog/archives/16-KMess-file-transfer-fixes;-MSN-Protocol-goodies.html
set MsgId [getObjOption $sid data_blob_id]
set DataSize [lindex [::MSNP2P::SessionList get $sid] 1]
set Offset [lindex [::MSNP2P::SessionList get $sid] 2]
# We can receive a NAK to our data being sent.
# When a packet is lost for some reason, we get a nak with the position
# of the file that WLM wants to receive. If we got that, we simply reposition
# ourselves in the file and set the new offset.
if {[getObjOption $sid nak_pos ""] != "" } {
set new_pos [getObjOption $sid nak_pos]
set Offset $new_pos
seek $fd $new_pos
setObjOption $sid nak_pos ""
}
if {$DataSize == 0 } {
status_log "Correcting DataSize\n" green
set filename [lindex [::MSNP2P::SessionList get $sid] 8]
set DataSize [file size "${filename}"]
::MSNP2P::SessionList set $sid [list -1 $DataSize -1 -1 -1 -1 $fd -1 -1 -1]
}
set data [read $fd 1352]
set out "[binary format iiiiiiiiiiii $sid $MsgId $Offset 0 $DataSize 0 [string length $data] 16777264 [expr {int(rand() * 1000000000)%125000000 + 4}] 0 0 0]$data"
::amsn::FTProgress s $sid "" [expr {$Offset + [string length $data]}] $DataSize
#status_log "Writing file to socket $sock, send $Offset of $DataSize\n" red
set Offset [expr {$Offset + [string length $data]}]
::MSNP2P::SessionList set $sid [list -1 -1 $Offset -1 -1 -1 -1 -1 -1 -1]
if {$msn6ft_test_nak_once } {
set msn6ft_test_nak_once 0
SendFileToSock $sock
}
catch { puts -nonewline $sock "[binary format i [string length $out]]$out" }
# status_log "Sending : $out"
if { ($DataSize - $Offset) == 0} {
catch { close $fd }
::amsn::FTProgress fs $sid ""
}
return [expr {$DataSize - $Offset}]
}
proc GotFileTransferRequest { chatid dest branchuid cseq uid sid context } {
global HOME
binary scan [string range $context 0 3] i size
binary scan [string range $context 8 11] i filesize
binary scan [string range $context 16 19] i nopreview
set filename [FromUnicode [string range $context 20 569]]
#binary scan $filename A* filename <-- destroys encoding
set idx [string first "\x00" $filename]
if {$idx != -1 } {
set filename [string range $filename 0 [expr {$idx - 1}]]
}
if { $nopreview == 0 } {
set previewdata [string range $context $size end]
set dir [file join $HOME FT cache]
create_dir $dir
set fd [open "[file join $dir ${sid}.png ]" "w"]
fconfigure $fd -translation binary
puts -nonewline $fd "$previewdata"
close $fd
set file [file join $dir ${sid}.png]
if { $file != "" && ![catch {set img [image create photo [TmpImgName] -file $file]} res]} {
::skin::setPixmap FT_preview_${sid} "[file join $dir ${sid}.png]"
}
catch {image delete $img}
}
setObjOption $sid chatid $chatid
#status_log "context : $context \n size : $size \n filesize : $filesize \n nopreview : $nopreview \nfilename : $filename\n"
status_log "size : $size \n filesize : $filesize \n nopreview : $nopreview \nfilename : $filename\n"
::MSNFT::invitationReceived $filename $filesize $sid $chatid $dest 1
SendMessageFIFO [list ::amsn::GotFileTransferRequest $chatid $dest $branchuid $cseq $uid $sid $filename $filesize] "::amsn::messages_stack($chatid)" "::amsn::messages_flushing($chatid)"
}
proc answerFTInvite { sid chatid branchid conntype } {
::MSNP2P::SessionList set $sid [list -1 -1 -1 -1 -1 -1 -1 -1 -1 "$branchid" ]
set session [::MSNP2P::SessionList get $sid]
set dest [lindex $session 3]
set callid [lindex $session 5]
set conntype [abook::getDemographicField conntype]
set listening [abook::getDemographicField listening]
if {$listening == "true" } {
set nonce "[format %X [myRand 4369 65450]][format %X [myRand 4369 65450]]-[format %X [myRand 4369 65450]]-[format %X [myRand 4369 65450]]-[format %X [myRand 4369 65450]]-[format %X [myRand 4369 65450]][format %X [myRand 4369 65450]][format %X [myRand 4369 65450]]"
set port [OpenMsnFTPort [config::getKey initialftport] $nonce $sid 0]
set clientip [::abook::getDemographicField clientip]
set localip [::abook::getDemographicField localip]
} else {
set nonce "00000000-0000-0000-0000-000000000000"
set port ""
set clientip ""
set localip ""
}
set slpdata [::MSNP2P::MakeMSNSLP "OK" $dest [::config::getKey login] $branchid 1 $callid 0 2 "TCPv1" "$listening" "$nonce" "$clientip"\
"$port" "$localip" "$port"]
status_log "sending 200 OK packet for FT"
::MSNP2P::SendPacket [::MSN::SBFor $chatid] [::MSNP2P::MakePacket $sid $slpdata 1]
}
#//////////////////////////////////////////////////////////////////////////////
# AcceptFT ( chatid dest branchuid cseq uid sid filename1 )
# This function is called when a file transfer is accepted by the user
proc AcceptFT { chatid dest branchuid cseq uid sid filename1 } {
# Let's open the file
set filename [file join [::config::getKey receiveddir] $filename1]
set origfile $filename
set incompl "incomplete"
set num 1
while { [file exists $filename] || [file exists $filename.$incompl] } {
set filename "[filenoext $origfile] $num[fileext $origfile]"
#set filename "$origfile.$num"
incr num
}
status_log "Saving to file $filename\n" green
set filename $filename.$incompl
# If we can't create the file notify the user and reject the FT request
if {[catch {open $filename w} fileid]} {
# Cannot create this file. Abort.
status_log "Could not saved the file '$filename' (write-protected target directory?)\n" red
RejectFT $chatid $sid $branchuid $uid
::amsn::infoMsg [trans readonlymsgbox] warning
return
}
fconfigure $fileid -translation binary
::MSNP2P::SessionList set $sid [list -1 -1 -1 -1 -1 -1 $fileid -1 $filename -1]
# Let's make and send a 200 OK Message
set slpdata [::MSNP2P::MakeMSNSLP "OK" $dest [::config::getKey login] $branchuid [expr {$cseq + 1}] $uid 0 0 $sid]
::MSNP2P::SendPacket [::MSN::SBFor $chatid] [::MSNP2P::MakePacket $sid $slpdata 1]
::amsn::FTProgress a $sid $filename $dest 1000 $chatid
status_log "MSNP2P | $sid -> Sent 200 OK Message for File Transfer\n" red
}
#//////////////////////////////////////////////////////////////////////////////
# CancelFT ( chatid sid )
# This function is called when a file transfer is canceled by the user
proc CancelFT { chatid sid } {
set session_data [::MSNP2P::SessionList get $sid]
set user_login [lindex $session_data 3]
set fd [lindex [::MSNP2P::SessionList get $sid] 6]
catch {close $fd}
status_log "MSNP2P | $sid -> User canceled FT, sending BYE to chatid : $chatid and SB : [::MSN::SBFor $chatid]\n" red
# Change sid type to canceledft
::MSNP2P::SessionList set $sid [list -1 0 0 -1 "BYE" -1 0 "ftcanceled" -1 -1]
#Make packet shouldn't get from the sessionlist the fileds so I pass to it a null sid
::MSNP2P::SendPacket [::MSN::SBFor $chatid] [::MSNP2P::MakePacket $sid [::MSNP2P::MakeMSNSLP "BYE" $user_login [::config::getKey login] "19A50529-4196-4DE9-A561-D68B0BF1E83F" 0 [lindex $session_data 5] 0 0] 1]
::amsn::FTProgress ca $sid [lindex [::MSNP2P::SessionList get $sid] 6]
}
#//////////////////////////////////////////////////////////////////////////////
# RejectFT ( chatid sid branchuid uid )
# This function is called when a file transfer is rejected/canceled
proc RejectFT { chatid sid branchuid uid } {
# All we need to do is send a DECLINE
set slpdata [::MSNP2P::MakeMSNSLP "DECLINE" [lindex [::MSNP2P::SessionList get $sid] 3] [::config::getKey login] $branchuid 1 $uid 0 0 $sid]
::MSNP2P::SendPacket [::MSN::SBFor $chatid] [::MSNP2P::MakePacket $sid $slpdata 1]
# And we unset our sid vars
::MSNP2P::SessionList unset $sid
}
}
# all audio/video functions go here
namespace eval ::MSNAV {
namespace export invitationReceived acceptInvite cancelSession readAccept
#//////////////////////////////////////////////////////////////////////////////
# CookieList (action cookie [varlist])
# Data Structure for MSNAV Sessions, contains :
# 0 - Local Session ID
# 1 - Did we invite? 1 if yes, 0 if no
# 2 - Type of session either A or AV
# 2 - Remote Session ID will see if i need
# 3 - Local port will see if i need
# 4 - Remote port will see if i need
#
# action can be :
# get : This method returns a list with all the array info, 0 if non existent
# set : This method sets the variables for the given cookie, takes a list as argument.
# unset : This method removes the given cookie variables
proc CookieList {action cookie {varlist ""} } {
variable LocalSID
variable Invite
variable Type
switch -- $action {
get {
if { [info exists LocalSID($cookie)] } {
# Session found, return values
return [list $LocalSID($cookie) $Invite($cookie) $Type($cookie)]
} else {
# Session not found, return 0
return 0
}
}
set {
# This overwrites previous vars if they are set to something else than -1
if { [lindex $varlist 0] != -1 } {
set LocalSID($cookie) [lindex $varlist 0]
}
if { [lindex $varlist 1] != -1 } {
set Invite($cookie) [lindex $varlist 1]
}
if { [lindex $varlist 2] != -1 } {
set Type($cookie) [lindex $varlist 2]
}
}
unset {
if { [info exists LocalSID($cookie)] } {
unset LocalSID($cookie)
} else {
status_log "Trying to unset LocalSID($cookie) but do not exist\n" red
}
if { [info exists Invite($cookie)] } {
unset Invite($cookie)
} else {
status_log "Trying to unset Invite($cookie) but do not exist\n" red
}
if { [info exists Type($cookie)] } {
unset Type($cookie)
} else {
status_log "Trying to unset Type($cookie) but do not exist\n" red
}
}
}
}
#//////////////////////////////////////////////////////////////////////////////
# invitationReceived ( cookie context chatid fromlogin )
# This function is called when we received an A/V invitation
# cookie : invitation cookie
# context: Requested:SIP_A,SIP_V;Capabilities:SIP_A,SIP_V;
# dosen't return nothing
proc invitationReceived {cookie context chatid fromlogin} {
# Now we write the request to the screen
set fromname [::abook::getDisplayNick $fromlogin]
# Let's get the requested part from our context
set idx [expr [string first "Capabilities:" $context] - 1]
set requested [string range $context 0 $idx]
status_log "requested: $requested\n"
# Check if it's Audio only or AV
if { [string first "SIP_V" $requested] == -1 } {
set txt [trans agotinvitation $fromname]
CookieList set $cookie [list 0 0 "A"]
} else {
set txt [trans avgotinvitation $fromname]
CookieList set $cookie [list 0 0 "AV"]
}
set win_name [::ChatWindow::MakeFor $chatid $txt $fromlogin]
if { [OnDarwin] } {
::amsn::WinWrite $chatid "\nAudio/Video requests are not supported on Mac OS X, only Webcam" green
return
}
::amsn::WinWrite $chatid "\n----------\n" green
::amsn::WinWrite $chatid $txt green
::amsn::WinWrite $chatid " - (" green
::amsn::WinWriteClickable $chatid "[trans accept]" "::MSNAV::acceptInvite $cookie [list $requested] $chatid" avyes$cookie
::amsn::WinWrite $chatid " / " green
::amsn::WinWriteClickable $chatid "[trans reject]" "::MSNAV::cancelSession $cookie [list $requested] $chatid" avno$cookie
::amsn::WinWrite $chatid ")\n" green
::amsn::WinWrite $chatid "----------" green
#::MSNAV::acceptInvite $cookie [list $requested] $chatid
}
#//////////////////////////////////////////////////////////////////////////////
# acceptInvite ( cookie requested chatid )
# This function is called when we the user accepts an A/V invitation
# cookie : invitation cookie
# requested : Requested:SIP_A,SIP_V;
# dosen't return nothing
proc acceptInvite {cookie requested chatid} {
# let's fix the visuals
set win_name [::ChatWindow::For $chatid]
if { [::ChatWindow::For $chatid] == 0} {
return 0
}
[::ChatWindow::GetOutText ${win_name}] tag configure avyes$cookie \
-foreground #808080 -font bplainf -underline false
[::ChatWindow::GetOutText ${win_name}] tag bind avyes$cookie <Enter> ""
[::ChatWindow::GetOutText ${win_name}] tag bind avyes$cookie <Leave> ""
[::ChatWindow::GetOutText ${win_name}] tag bind avyes$cookie <<Button1>> ""
[::ChatWindow::GetOutText ${win_name}] tag configure avno$cookie \
-foreground #808080 -font bplainf -underline false
[::ChatWindow::GetOutText ${win_name}] tag bind avno$cookie <Enter> ""
[::ChatWindow::GetOutText ${win_name}] tag bind avno$cookie <Leave> ""
[::ChatWindow::GetOutText ${win_name}] tag bind avno$cookie <<Button1>> ""
[::ChatWindow::GetOutText ${win_name}] conf -cursor left_ptr
set txt [trans avaccepted]
SendMessageFIFO [list ::MSNAV::DisplayTxt $chatid $txt] "::amsn::messages_stack($chatid)" "::amsn::messages_flushing($chatid)"
# We accepted let's init linphone
set type [lindex [CookieList get $cookie] 2]
if { [prepareLinphone $chatid $type] == -1 } {
# Remove the catch here.. I added it because I'm too lazy to
# test if I made an error in the syntax or anything..
catch {cancelSession $cookie $chatid USER_CANCELED}
return
}
# Let's send our accept
acceptInvitationPacket $cookie $requested $chatid
}
#//////////////////////////////////////////////////////////////////////////////
# sendAcceptPacket ( cookie requested chatid )
# This function makes and sends the acceptance packet of an A/V invitation
# cookie : invitation cookie
# requested: Requested:SIP_A,SIP_V;
# returns -1 if something is missing
proc acceptInvitationPacket {cookie requested chatid} {
set sessionid "[format %X [myRand 4369 65450]][format %X [myRand 4369 65450]]-[format %X [myRand 4369 65450]]-[format %X [myRand 4369 65450]]-[format %X [myRand 4369 65450]]-[format %X [myRand 4369 65450]][format %X [myRand 4369 65450]][format %X [myRand 4369 65450]]"
CookieList set $cookie [list $sessionid -1 -1]
# we need the connection type
set conntype [::abook::getDemographicField conntype]
if { $conntype == "" } {
return -1
}
#set conntype "DIRECT-CONNECT"
set msg "MIME-Version: 1.0\r\nContent-Type: text/x-msmsgsinvite; charset=UTF-8\r\n\r\n"
set msg "${msg}Invitation-Command: ACCEPT\r\n"
set msg "${msg}Context-Data: $requested\r\n"
set msg "${msg}Invitation-Cookie: $cookie\r\n"
set msg "${msg}Session-ID: {$sessionid}\r\n"
set msg "${msg}Session-Protocol: SM1\r\n"
set msg "${msg}[MakeConnType $conntype]"
set msg "${msg}Launch-Application: TRUE\r\n"
set msg "${msg}Request-Data: IP-Address:\r\n"
set msg "${msg}[MakeIP]"
set msg [encoding convertto utf-8 $msg]
set msg_len [string length $msg]
::MSN::WriteSBNoNL [::MSN::SBFor $chatid] "MSG" "A $msg_len\r\n$msg"
}
#//////////////////////////////////////////////////////////////////////////////
# cancelSession ( cookie chatid code)
# This function cancels the A/V session of the given cookie
# cookie : session cookie
# code : the cancel code (TIMEOUT, REJECT, ..what else)
# returns nothing
proc cancelSession {cookie chatid code} {
set win_name [::ChatWindow::For $chatid]
if { [::ChatWindow::For $chatid] == 0} {
return 0
}
# Disable accept/Cancel
[::ChatWindow::GetOutText ${win_name}] tag configure avyes$cookie \
-foreground #808080 -font bplainf -underline false
[::ChatWindow::GetOutText ${win_name}] tag bind avyes$cookie <Enter> ""
[::ChatWindow::GetOutText ${win_name}] tag bind avyes$cookie <Leave> ""
[::ChatWindow::GetOutText ${win_name}] tag bind avyes$cookie <<Button1>> ""
[::ChatWindow::GetOutText ${win_name}] tag configure avno$cookie \
-foreground #808080 -font bplainf -underline false
[::ChatWindow::GetOutText ${win_name}] tag bind avno$cookie <Enter> ""
[::ChatWindow::GetOutText ${win_name}] tag bind avno$cookie <Leave> ""
[::ChatWindow::GetOutText ${win_name}] tag bind avno$cookie <<Button1>> ""
[::ChatWindow::GetOutText ${win_name}] conf -cursor left_ptr
# Show on screen
set txt [trans avcanceled]
SendMessageFIFO [list ::MSNAV::DisplayTxt $chatid $txt] "::amsn::messages_stack($chatid)" "::amsn::messages_flushing($chatid)"
set conntype [::abook::getDemographicField conntype]
#set conntype "Direct-Connect"
set msg "MIME-Version: 1.0\r\nContent-Type: text/x-msmsgsinvite; charset=UTF-8\r\n\r\n"
set msg "${msg}Invitation-Command: CANCEL\r\n"
#set msg "${msg}Cancel-Code: $code\r\n"
set msg "${msg}Cancel-Code: USER_CANCEL\r\n"
set msg "${msg}Invitation-Cookie: $cookie\r\n"
set msg "${msg}Session-ID: {[lindex [CookieList get $cookie] 0]}\r\n"
set msg "${msg}[MakeConnType $conntype]"
set msg [encoding convertto utf-8 $msg]
set msg_len [string length $msg]
::MSN::WriteSBNoNL [::MSN::SBFor $chatid] "MSG" "A $msg_len\r\n$msg"
# kill linphone
catch { lp_terminate_dialog }
catch { lp_uninit }
CookieList unset $cookie
}
#Used to diplay text on chatid's conversation : created for avoid interleaving in convo
proc DisplayTxt {chatid txt} {
::amsn::WinWrite $chatid "\n----------\n" green
::amsn::WinWrite $chatid " $txt\n" green
::amsn::WinWrite $chatid "----------" green
}
#//////////////////////////////////////////////////////////////////////////////
# readAccept ( cookie ip chatid )
# This function handles Accepts, there can be 2 kinds of ACCEPT
# we receive an ACCEPT after we invite
# we receive an ACCEPT after we accept a remote invitation
# cookie : session cookie
# ip : ip that shows on the ACCEPT
# returns nothing
proc readAccept {cookie ip chatid} {
# let's check our type
if { [lindex [CookieList get $cookie] 1] == 0 } {
# ok this is a 2nd accept
# now connect to him
lp_invite "<sip:${ip}>"
} else {
# ok so we invited, and this is his ACCEPT to our invite
# we need to send our own accept
# get our session id
set sessionid [lindex [CookieList get $cookie] 0]
# we need the connection type
set conntype [::abook::getDemographicField conntype]
#set conntype "Direct-Connect"
if { $conntype == "" } {
return -1
}
set msg "MIME-Version: 1.0\r\nContent-Type: text/x-msmsgsinvite; charset=UTF-8\r\n\r\n"
set msg "${msg}Invitation-Command: ACCEPT\r\n"
set msg "${msg}Invitation-Cookie: $cookie\r\n"
set msg "${msg}Session-ID: {$sessionid}\r\n"
set msg "${msg}[MakeConnType $conntype]"
set msg "${msg}Launch-Application: TRUE\r\n"
set msg "${msg}[MakeIP]"
set msg [encoding convertto utf-8 $msg]
set msg_len [string length $msg]
::MSN::WriteSBNoNL [::MSN::SBFor $chatid] "MSG" "A $msg_len\r\n$msg"
}
}
proc inviteComputerCall { chatid } {
# make new sessionid
set sessionid "[format %X [myRand 4369 65450]][format %X [myRand 4369 65450]]-[format %X [myRand 4369 65450]]-[format %X [myRand 4369 65450]]-[format %X [myRand 4369 65450]]-[format %X [myRand 4369 65450]][format %X [myRand 4369 65450]][format %X [myRand 4369 65450]]"
# make new cookie
set cookie [expr {([clock clicks]) % (65536 * 8)}]
CookieList set $cookie [list $sessionid 1 "voice"]
# we need the connection type
set conntype [::abook::getDemographicField conntype]
if { $conntype == "" } {
return -1
}
set msg "MIME-Version: 1.0\r\nContent-Type: text/x-msmsgsinvite; charset=UTF-8\r\n\r\n"
set msg "${msg}Application-Name: a Computer Call\r\n"
set msg "${msg}Application-GUID: {02D3C01F-BF30-4825-A83A-DE7AF41648AA}\r\n"
set msg "${msg}Session-Protocol: SM1\r\n"
set msg "${msg}Context-Data: Requested:SIP_A,;Capabilities:SIP_A,;\r\n"
set msg "${msg}Invitation-Command: INVITE\r\n"
set msg "${msg}Invitation-Cookie: $cookie\r\n"
set msg "${msg}Session-ID: {$sessionid}\r\n"
set msg "${msg}Conn-Type: $conntype\r\n"
set msg "${msg}Sip-Capability: 0\r\n"
# I don't really know what other conn types there are and what to do
# TODO test with other types of connections that direct and IP-Restricted-NAT
if { $conntype == "IP-Restrict-NAT" } {
set msg "${msg}Private-IP: [::abook::getDemographicField localip]\r\n"
set msg "${msg}Public-IP: [::abook::getDemographicField clientip]\r\n"
set msg "${msg}UPnP: [abook::getDemographicField upnpnat]\r\n"
}
set msg [encoding convertto utf-8 $msg]
set msg_len [string length $msg]
::MSN::WriteSBNoNL [::MSN::SBFor $chatid] "MSG" "S $msg_len\r\n$msg"
}
proc acceptComputerCall { chatid cookie } {
set conntype [::abook::getDemographicField conntype]
set msg "Invitation-Command: ACCEPT\r\n"
append msg "Context-Data: Requested:SIP_A,;Capabilities:SIP_A,;\r\n"
append msg "Invitation-Cookie: 374836\r\n"
append msg "Session-ID: {A4EE9D51-A7CA-4CD4-90EC-B234285B6D2F}\r\n"
append msg "Session-Protocol: SM1\r\n"
append msg "Conn-Type: Symmetric-NAT\r\n"
append msg "Sip-Capability: 1\r\n"
append msg "Public-IP: 65.210.205.254\r\n"
append msg "Private-IP: 10.27.95.174\r\n"
append msg "UPnP: FALSE\r\n"
append msg "Launch-Application: TRUE\r\n"
append msg "UsingRendezvous: FALSE\r\n"
append msg "Request-Data: IP-Address:\r\n"
append msg "IP-Address: 10.27.95.174:8348\r\n"
append msg "IP-Address-Enc64: MTAuMjcuOTUuMTc0OjgzNDg=\r\n"
}
#//////////////////////////////////////////////////////////////////////////////
# inviteAV ( chatid type )
# This function creates new invitations for A/V
# chatid : chatid to send invitation to
# type : A, AV
# returns nothing
proc inviteAV { chatid type } {
if { [prepareLinphone $chatid $type] == -1 } {
return
}
# make new sessionid
set sessionid "[format %X [myRand 4369 65450]][format %X [myRand 4369 65450]]-[format %X [myRand 4369 65450]]-[format %X [myRand 4369 65450]]-[format %X [myRand 4369 65450]]-[format %X [myRand 4369 65450]][format %X [myRand 4369 65450]][format %X [myRand 4369 65450]]"
# make new cookie
set cookie [expr {([clock clicks]) % (65536 * 8)}]
CookieList set $cookie [list $sessionid 1 $type]
# we need the connection type
set conntype [::abook::getDemographicField conntype]
if { $conntype == "" } {
return -1
}
set msg "MIME-Version: 1.0\r\nContent-Type: text/x-msmsgsinvite; charset=UTF-8\r\n\r\n"
set msg "${msg}Application-Name: an audio conversation\r\n"
set msg "${msg}Application-GUID: {02D3C01F-BF30-4825-A83A-DE7AF41648AA}\r\n"
set msg "${msg}Session-Protocol: SM1\r\n"
if { $type == "A" } {
set msg "${msg}Context-Data: Requested:SIP_A,;Capabilities:SIP_A,SIP_V,;\r\n"
} else {
set msg "${msg}Context-Data: Requested:SIP_A,SIP_V,;Capabilities:SIP_A,SIP_V,;\r\n"
}
set msg "${msg}Invitation-Command: INVITE\r\n"
set msg "${msg}Invitation-Cookie: $cookie\r\n"
set msg "${msg}Session-ID: {$sessionid}\r\n"
set msg "${msg}[MakeConnType $conntype]"
set msg [encoding convertto utf-8 $msg]
set msg_len [string length $msg]
::MSN::WriteSBNoNL [::MSN::SBFor $chatid] "MSG" "S $msg_len\r\n$msg"
}
proc MakeConnType { conntype } {
#set conntype "Direct-Connect"
set msg "Conn-Type: $conntype\r\n"
set msg "${msg}Sip-Capability: 1\r\n"
# I don't really know what other conn types there are and what to do
# TODO test with other types of connections that direct and IP-Restricted-NAT
if { $conntype == "IP-Restrict-NAT" } {
set msg "${msg}Private-IP: [::abook::getDemographicField localip]\r\n"
set msg "${msg}Public-IP: [::abook::getDemographicField clientip]\r\n"
set msg "${msg}UPnP: [abook::getDemographicField upnpnat]\r\n"
}
return $msg
}
proc MakeIP { } {
set msg "IP-Address: [::abook::getDemographicField clientip]:5060\r\n"
set msg "${msg}IP-Address-Enc64: [::base64::encode [::abook::getDemographicField clientip]:5060 ]\r\n\r\n"
#set msg "IP-Address: [::abook::getDemographicField localip]:5060\r\n"
#set msg "${msg}IP-Address-Enc64: [::base64::encode [::abook::getDemographicField localip]:5060 ]\r\n\r\n"
return $msg
}
proc prepareLinphone { chatid type } {
if { [LoadExtension] == 0 } {
DisplayError $chatid
return -1
}
catch { lp_init } res
# Check if init works good
if { $res == -1 } {
DisplayError $chatid
return -1
}
if { $type == "A" } {
lp_disable_video
lp_show_local_video 0
} else {
status_log "laaaaaaaaaaaaaaaaaaa"
lp_enable_video
lp_show_local_video 1
}
lp_set_sip_port 5060
lp_set_audio_port 7078
lp_set_video_port 9078
lp_set_primary_contact "sip:myusername@myhostname"
lp_set_nat_address [::abook::getDemographicField clientip]
#lp_set_nat_address [::abook::getDemographicField localip]
}
proc LoadExtension { } {
if { [ExtensionLoaded] == 0 } {
catch { load plugins/linphone/linphone.so}
}
return [ExtensionLoaded]
}
proc ExtensionLoaded { } {
foreach lib [info loaded] {
if { [lindex $lib 1] == "Linphone" } {
return 1
}
}
return 0
}
proc DisplayError { chatid } {
#display error
set win_name [::ChatWindow::For $chatid]
if { [::ChatWindow::For $chatid] == 0} {
return 0
}
# Show on screen
set txt [trans avinitfailed]
SendMessageFIFO [list ::MSNAV::DisplayTxt $chatid $txt] "::amsn::messages_stack($chatid)" "::amsn::messages_flushing($chatid)"
}
}
namespace eval ::MSNMobile {
namespace export IsMobile MessageSend MessageReceived OpenMobileWindow
variable user2chatid
proc IsMobile { chatid } {
if { [string first "@" $chatid] != [string last "@" $chatid] &&
[string first "mobile@" $chatid] == 0 } {
return 1
} else {
return 0
}
}
proc MessageSend { chatid txt } {
set name [string range $chatid 7 end]
set msg "<TEXT xml:space=\"preserve\" enc=\"utf-8\">$txt</TEXT>"
set msglen [string length $msg]
#set plen [string length $msg]
::MSN::WriteSBNoNL ns "PGD" "$name 1 $msglen\r\n$msg"
if {[::abook::getKeepLogs $chatid]} {
::log::PutLog $chatid [::abook::getPersonal login] $txt
}
}
proc MessageReceived { data } {
status_log "Got data : $data" red
set xml [xml2list $data]
set msg [GetXmlEntry $xml "NOTIFICATION:MSG:BODY:TEXT"]
set user [GetXmlAttribute $xml "NOTIFICATION:FROM" name]
set chatid [GetChatId $user]
if { $chatid == 0 } {
OpenMobileWindow $user
set chatid [GetChatId $user]
}
status_log "Writing mobile msg \"$msg\" on : $chatid\n" red
::amsn::WinWrite $chatid "\n[timestamp] [trans mobilesays $user] : \n" says
::amsn::WinWrite $chatid "$msg" user
if {[::abook::getKeepLogs $chatid]} {
::log::PutLog $chatid $user $msg
}
}
proc OpenMobileWindow { user } {
set chatid [GetChatId $user]
status_log "opening chat window for mobile messaging : $chatid\n" red
if { $chatid == 0 } {
set win [::ChatWindow::Open]
set chatid "mobile@$user"
::ChatWindow::SetFor $chatid $win
SetChatId $user $chatid
after 200 "::MSNMobile::UpdateWindow $win $user"
if { [winfo exists .bossmode] } {
set ::BossMode(${win_name}) "normal"
wm state $win withdraw
} else {
wm state $win normal
}
wm deiconify $win
} else {
set win [::ChatWindow::For $chatid]
if { [winfo exists .bossmode] } {
set ::BossMode(${win_name}) "normal"
wm state $win withdraw
} else {
wm state $win normal
}
wm deiconify $win
focus $win
}
}
proc UpdateWindow { win_name user_login } {
set top [::ChatWindow::GetTopFrame $win_name]
if { ![winfo exists $top] } { return }
$top itemconfigure to -text "[trans tomobile]:"
set toX [::skin::getKey topbarpadx]
set usrsX [expr {$toX + [font measure bplainf -displayof $top "[trans tomobile]:"] + 5}]
set txtY [::skin::getKey topbarpady]
$top coords text $usrsX [lindex [$top coords text] 1]
set title "[trans tomobile] : $user_login"
set user_name [string map {"\n" " "} [::abook::getDisplayNick $user_login]]
set state_code [::abook::getVolatileData $user_login state]
if { $state_code == "" } {
set user_state ""
set state_code FLN
} else {
set user_state [::MSN::stateToDescription $state_code]
}
set user_image [::MSN::stateToImage $state_code]
$top dchars text 0 end
if {[::config::getKey truncatenames]} {
#Calculate maximum string width
set maxw [expr { 0 - int([lindex [$top coords text] 0])}]
if { "$user_state" != "" && "$user_state" != "online" } {
incr maxw [expr {0-[font measure sboldf -displayof $top " \([trans $user_state]\)"]}]
}
incr maxw [expr {[winfo width $top] - [::skin::getKey topbarpadx] -[font measure sboldf -displayof $top " <${user_login}>"]}]
$top insert text end "[trunc ${user_name} ${win_name} $maxw sboldf] <${user_login}>"
} else {
$top insert text end "${user_name} <${user_login}>"
}
#TODO: When we have better, smaller and transparent images, uncomment this
if { "$user_state" != "" && "$user_state" != "online" } {
$top insert text end "\([trans $user_state]\)"
}
$top insert text end "\n"
#Change color of top background by the status of the contact
::ChatWindow::ChangeColorState $user_login $user_state $state_code ${win_name}
#Calculate number of lines, and set top text size
set size [$top index text end]
set ::ChatWindow::titles(${win_name}) ${title}
$top dchars text [expr {$size - 1}] end
$top configure -height [expr {[::ChatWindow::MeasureTextCanvas $top "text" "h"] + 2*[::skin::getKey topbarpady]}]
if { [info exists ::ChatWindow::new_message_on(${win_name})] && $::ChatWindow::new_message_on(${win_name}) == 1 } {
wm title ${win_name} "*${title}"
} else {
wm title ${win_name} ${title}
}
update idletasks
after cancel "::MSNMobile::UpdateWindow $win_name $user_login"
after 5000 "::MSNMobile::UpdateWindow $win_name $user_login"
}
proc GetChatId { user } {
variable user2chatid
if { [info exists user2chatid($user)] } {
set chatid [set user2chatid($user)]
set win [::ChatWindow::For $chatid]
if {$win != 0 && [winfo exists $win] } {
return $chatid
} else {
unset user2chatid($user)
return 0
}
} else {
return 0
}
}
proc SetChatId { user chatid } {
variable user2chatid
set user2chatid($user) $chatid
}
}
|