Compare commits
1038 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 771da0e1d6 | |||
| 75d8d8a43e | |||
| 80610e62f8 | |||
| fa9b8d63f9 | |||
| d4316558de | |||
| 690857e0d4 | |||
| 73705a3b2e | |||
| 7510a54f81 | |||
| 8235c9eea1 | |||
| 8cd32f9706 | |||
| b28b9686fe | |||
| 72b9d8b250 | |||
| 6abfea6d8d | |||
| d599aba9ca | |||
| 02f19c0c1d | |||
| 3181685158 | |||
| f93c6c2b35 | |||
| a134626849 | |||
| 31198d6c63 | |||
| 92dc45ad76 | |||
| 8a5b08e3f0 | |||
| 1a368436b4 | |||
| 59a19ca87a | |||
| e653598cd0 | |||
| 891c9610e9 | |||
| 9265c23e1a | |||
| 11130806f9 | |||
| 0d065dd021 | |||
| f5dc8d2f78 | |||
| 07e459d577 | |||
| aa791ad0c4 | |||
| 17fc992ba9 | |||
| 115392ff2d | |||
| b1545d1d7d | |||
| 9e2d614b41 | |||
| 917c5edfe5 | |||
| 1285bd52c9 | |||
| 597c1c87d4 | |||
| 58bed2cbff | |||
| 13fad04d14 | |||
| eb2ad7e699 | |||
| 511f73812d | |||
| a7d9fa7301 | |||
| bb77c39553 | |||
| a1a6bd79ac | |||
| cdb379a22c | |||
| 9336356efd | |||
| 8e9888c411 | |||
| 027418aba5 | |||
| f36da63a3a | |||
| 5bc9860f5d | |||
| c237570bc2 | |||
| 0dcbe10a22 | |||
| 581f011b28 | |||
| fb2c74c4aa | |||
| 8dbd6007ed | |||
| c9faa5bde7 | |||
| de6675a433 | |||
| 81d364a97a | |||
| 02b7ba50fe | |||
| e64d69350f | |||
| 2b48732de4 | |||
| 29e626bf80 | |||
| 2e13a56ca9 | |||
| 976baccceb | |||
| f8412d7c5d | |||
| 5a8d99232c | |||
| fe70217703 | |||
| 20f6e4714e | |||
| b76eba62ea | |||
| 5b6351577a | |||
| 894f0abdfa | |||
| c89944fe12 | |||
| fe1a4908b5 | |||
| d60ef4c212 | |||
| 5161a9d4e8 | |||
| eb0dc4f4ca | |||
| 6b9a523dc9 | |||
| 3e97054390 | |||
| 69d10702ee | |||
| 455107ff5f | |||
| 5ca3f221cc | |||
| 7ffe06c77f | |||
| bdea5d3598 | |||
| a07eb3e023 | |||
| c3ef12debb | |||
| 739412119e | |||
| 90d9ed1ee4 | |||
| 7d96d831c1 | |||
| b2eb9bc512 | |||
| 71fc696f81 | |||
| 234280ddc7 | |||
| 7a76cabe26 | |||
| a610d8b699 | |||
| 98a78b7955 | |||
| 493d3bc7aa | |||
| ac6ae9e8dd | |||
| a6c0a3d59b | |||
| 0b5bcaf74a | |||
| 3ee28ef7cc | |||
| 3f68689367 | |||
| 6fc578f2ee | |||
| cd4c730b9c | |||
| b0b66be747 | |||
| e04a690303 | |||
| bc44a3584f | |||
| 5e986442a2 | |||
| 19ad0eb238 | |||
| fe4944e031 | |||
| a51df8db6e | |||
| b605295f9d | |||
| dd69d47543 | |||
| 3b7449fb92 | |||
| 0514ccb047 | |||
| cab6ee9d86 | |||
| 63032e1397 | |||
| 8cef084bd2 | |||
| 6942d0bcc3 | |||
| 979c2b5a74 | |||
| a62a9b6460 | |||
| 67da88f0bd | |||
| 4fd7ec27f5 | |||
| 19a8b79342 | |||
| be111b6749 | |||
| b6711e407e | |||
| 3bcc60066e | |||
| 8d783bae15 | |||
| e0bdbcf063 | |||
| f32332cdfc | |||
| 399bb31e13 | |||
| eae5d1b764 | |||
| 1459cb8a56 | |||
| 53638d094a | |||
| 8d3fd94d7d | |||
| e27dda3ff1 | |||
| 1142cdad1b | |||
| 2028698336 | |||
| 5d1d797330 | |||
| a67539075f | |||
| 75053cf40d | |||
| cbf06b4785 | |||
| cc7ecfb39e | |||
| 04943ca469 | |||
| 89f99c4251 | |||
| 1a6c162371 | |||
| ead2655a62 | |||
| 526912756b | |||
| aa176917fa | |||
| be25c5ada7 | |||
| d2dee01f7c | |||
| b9e79aac6c | |||
| 2e9f3d3308 | |||
| 39e18e3738 | |||
| baef586581 | |||
| db17504c82 | |||
| 85e59c14d2 | |||
| d48b4f2438 | |||
| 6925f388e7 | |||
| bc1b4163a2 | |||
| 4e459b9466 | |||
| e3e888b8de | |||
| b1dfb4b5f2 | |||
| 2f372261d3 | |||
| 2187bccc38 | |||
| 6c0c30c032 | |||
| 166e742b3c | |||
| 76447a8810 | |||
| 0232f5958f | |||
| e042fdb111 | |||
| 01855b4e32 | |||
| 9275a0020e | |||
| fbc8466c3c | |||
| bd69e3ad6c | |||
| 3b963c4f18 | |||
| 72b2209c3e | |||
| 75c5803431 | |||
| d03eacd160 | |||
| c13df5645e | |||
| a76d3d46fc | |||
| e5535c80da | |||
| 41484213fd | |||
| a4cf03dbf0 | |||
| 8935da5b5c | |||
| 9c12790011 | |||
| bc963e7855 | |||
| 877a864ba3 | |||
| 033bec01e3 | |||
| 5f89f481e4 | |||
| 95057c1182 | |||
| f6e4d95c6f | |||
| 4409c49494 | |||
| f32b394a96 | |||
| c09df6cf93 | |||
| 497911fc5d | |||
| 46ac8f97eb | |||
| 0964724b2a | |||
| ccc684b095 | |||
| 2f075b7b77 | |||
| e1dd9ed875 | |||
| e7d70933ac | |||
| 611a9c0136 | |||
| 834ca8a08d | |||
| 34bc4da8d8 | |||
| 3727e2426d | |||
| 7aa5e8f435 | |||
| 6129065cfa | |||
| 86eebc21b4 | |||
| 56f5a7846f | |||
| bb4dae26da | |||
| 2afce7822f | |||
| e249a21f83 | |||
| 2331e23f49 | |||
| 110819525f | |||
| 3f6579ffbc | |||
| 92ec42565e | |||
| f84a1c88cf | |||
| a1205f347f | |||
| 674ee7f5f6 | |||
| 4d1dfe8914 | |||
| dc4d72cf77 | |||
| 57ffba34c2 | |||
| 2f97ef8b81 | |||
| 4548f2faf0 | |||
| f01dd3e942 | |||
| 53a5b602dc | |||
| b49dd8b8c4 | |||
| 4c147c5f29 | |||
| 9820880cd5 | |||
| 8713465df1 | |||
| cb9b97411b | |||
| 069ad5332d | |||
| 1d7daab4e8 | |||
| 6cdfec1284 | |||
| ab77bb5466 | |||
| c8f5585f3b | |||
| e117ce1b7b | |||
| b0d5ac0b33 | |||
| 5bb22101e2 | |||
| f70ebd6983 | |||
| 5cb10cf9fa | |||
| 3259c1c2ea | |||
| 58a4b594db | |||
| 7471d49b5a | |||
| 67cced15b9 | |||
| 7fffae5b1a | |||
| bda56552eb | |||
| d2104ba4e1 | |||
| 3581b137e1 | |||
| 44abf1ff28 | |||
| 7814527e0d | |||
| 57d5bc693c | |||
| b85b63018d | |||
| fd990cf4d8 | |||
| da50d95873 | |||
| 2f899ba76f | |||
| d11a715eda | |||
| 6d9094ceca | |||
| d50fc6728e | |||
| c316bfae25 | |||
| 37a23e69d7 | |||
| 13412129ec | |||
| 94257c3e4b | |||
| 4dc48da638 | |||
| 002104c62e | |||
| 3844883321 | |||
| fb64d79379 | |||
| 9d2fd3e52c | |||
| 7d497615a1 | |||
| fe40651b0d | |||
| 3c36cd64e3 | |||
| 7d97830ad7 | |||
| a1fe809197 | |||
| 236423d058 | |||
| c8c7169465 | |||
| 64f8cf8a9e | |||
| c99de764bc | |||
| c9463e3308 | |||
| 87beae3298 | |||
| 3e6acdfb4a | |||
| ebc82f2968 | |||
| 9890cc89b6 | |||
| 62ad40b1e4 | |||
| ca1ac76108 | |||
| ceb377621e | |||
| d70e92d781 | |||
| c0a0bae91e | |||
| e7c93ae68d | |||
| 55986739c9 | |||
| 8539a7d7ea | |||
| 23d008cd79 | |||
| 5a82e3ac70 | |||
| 4117a5e856 | |||
| 6cf078ae83 | |||
| 27be3b400e | |||
| fa4ebab036 | |||
| df2878739c | |||
| cab98b3fd5 | |||
| 60ffcd78f1 | |||
| 6557136426 | |||
| 50b0ef4db9 | |||
| 18074abfdd | |||
| d429ba812c | |||
| 0d09816c39 | |||
| 4caf4da9a6 | |||
| 961640bd2c | |||
| 5d92dce21d | |||
| 50f5356c89 | |||
| 3156cdf10e | |||
| 7a5ec47b58 | |||
| b22e8b706a | |||
| 0ddf0d10a5 | |||
| 0ed8ae5975 | |||
| 1283a59465 | |||
| ad1aec6cd1 | |||
| 7d7177a6af | |||
| f5e6c9a2a3 | |||
| 7cd5a04087 | |||
| bfff7d721d | |||
| aaff63da58 | |||
| 95a3cc88cd | |||
| 70c1a3f60b | |||
| c24af4ca63 | |||
| e31b2582b6 | |||
| 479e5cb107 | |||
| 887a65aa18 | |||
| e4a6d20328 | |||
| f5e1479afe | |||
| a10493976e | |||
| 4caac4a322 | |||
| e98df7acb1 | |||
| f20d2bb2ff | |||
| a5e4f34dbb | |||
| 1c9760f6d2 | |||
| 2b1ea7d85b | |||
| 1677603e59 | |||
| a95286d511 | |||
| 6e18e292f3 | |||
| 114dd4d9e7 | |||
| 0495112aab | |||
| f3483529a7 | |||
| ffc4f3dc48 | |||
| a9fba750fa | |||
| 13220d44f4 | |||
| 0c9e0168d5 | |||
| db4fe25274 | |||
| e948aafeca | |||
| 4639c0faf0 | |||
| 82cd0adb79 | |||
| 1bcd481fdc | |||
| 768ea20a3a | |||
| bb1ab19997 | |||
| dd159242e3 | |||
| f8886ee36c | |||
| 67af2908f9 | |||
| 9df6e1fe0a | |||
| a658348ac1 | |||
| 75ca3d8975 | |||
| b431a9099e | |||
| 7ed6614ad4 | |||
| 4fba4db32f | |||
| a0554183c5 | |||
| b1ad7ad0ba | |||
| 0537eea929 | |||
| cfc9089e51 | |||
| bb926f8f87 | |||
| c2f242b4a6 | |||
| 3f1c8f98ed | |||
| 7a3ce2e81a | |||
| 8c0cc95a55 | |||
| 38dfef923c | |||
| 89bceb959a | |||
| 8deb2b57af | |||
| 60915a7f21 | |||
| 69869f0446 | |||
| 1eb2b1f047 | |||
| a89b400c04 | |||
| 6f3aeead07 | |||
| 3da20486c1 | |||
| d911cd1124 | |||
| a7bd529dac | |||
| 857c87499a | |||
| 381dff1afc | |||
| 378a6b2ff2 | |||
| 5b782ad5a1 | |||
| 93ed18c2e2 | |||
| 95e96cc346 | |||
| 0e2cd7a8d0 | |||
| 332b474a9e | |||
| 7434234c27 | |||
| 848e72bcab | |||
| eb26edf5f5 | |||
| 440299656f | |||
| 4ac69edfe7 | |||
| 9ccdcfc849 | |||
| 514d5aab14 | |||
| 2a09bdad13 | |||
| dfa966a576 | |||
| 573ff2564b | |||
| 929022bc0f | |||
| 21a36819b0 | |||
| efd99f5b28 | |||
| 913684e5a5 | |||
| 40e06b55c0 | |||
| 182f4b008b | |||
| c3df4f3eb0 | |||
| 2c1b8b0930 | |||
| 3cca748bd5 | |||
| 2a05ca5f2b | |||
| 3173d9167f | |||
| f7b5afec51 | |||
| bc355eebaa | |||
| 78f9586839 | |||
| 040892d1a2 | |||
| 71cd4917d8 | |||
| b989297725 | |||
| cf6d842d45 | |||
| 733e84a4a8 | |||
| 9ac9a84ca7 | |||
| 4f369d048d | |||
| c1a7e30f12 | |||
| 4dcfde7737 | |||
| 0838514c27 | |||
| 29f3ef4716 | |||
| a8e5437271 | |||
| a363d988a7 | |||
| e1968b6b52 | |||
| 99a6f12026 | |||
| eca650efac | |||
| bde4b7b057 | |||
| a1e9b55ead | |||
| 1c4cc57e3f | |||
| 26cd3a78d2 | |||
| 3ed3c94a15 | |||
| ff338a0a62 | |||
| 5138a9709e | |||
| ae93cf2c28 | |||
| 1c2d639179 | |||
| 2078f9ae95 | |||
| 1fea1e3f4e | |||
| b2bd51d3e3 | |||
| 80a7f5123d | |||
| 8746175f1d | |||
| 236d8fa254 | |||
| 3872907f38 | |||
| 98f79f0c47 | |||
| 795992fb30 | |||
| 96504ffd88 | |||
| 5e7b217d6c | |||
| f07513c74b | |||
| 22fffb32ca | |||
| abcb3f22a8 | |||
| f7a5689c45 | |||
| bebc5a137a | |||
| 5625f7d984 | |||
| c889491e2f | |||
| cd09381efd | |||
| 306cff729c | |||
| 4083267cc9 | |||
| 12573ed8d2 | |||
| 6b4651fad6 | |||
| 0095f4fbf9 | |||
| 372658d299 | |||
| 227514c20c | |||
| 9a6c869cb8 | |||
| dce7b1430b | |||
| 162fbc2ef8 | |||
| 13b8940606 | |||
| f1b9f1fb63 | |||
| 861cc87272 | |||
| e5fb89731c | |||
| 2565a670b1 | |||
| 74cd5ffb02 | |||
| c3303ce364 | |||
| 2042ab090d | |||
| 13a231f6fa | |||
| 503defac73 | |||
| 2d41c81890 | |||
| 036095f37d | |||
| a2bb22a0e7 | |||
| 65926460b2 | |||
| f4e35033e7 | |||
| 75793f7cf4 | |||
| e36c530732 | |||
| 53edf861e0 | |||
| 24afead423 | |||
| 2f5211ab74 | |||
| b168cd7cf2 | |||
| 667fc07ec6 | |||
| e5a26b388f | |||
| 479b04a6a3 | |||
| b12b18d59f | |||
| b3955fca3a | |||
| bac5c30380 | |||
| 4ce2890af0 | |||
| 169a0471b9 | |||
| 6bdf4aa960 | |||
| 36676f0719 | |||
| bb1fca058d | |||
| b4c161e04a | |||
| 376741c9a1 | |||
| 04e86829e3 | |||
| 75dbcd5c68 | |||
| 283aa52b31 | |||
| 29b2da42f5 | |||
| 330a4c9452 | |||
| fa23b83dbb | |||
| 81f4644622 | |||
| 095cd6ce9b | |||
| f5eb9e3c9f | |||
| 98f93104a7 | |||
| 3940a6bab3 | |||
| de78508f45 | |||
| fab29f4cf0 | |||
| adfca08e43 | |||
| 35e8b95928 | |||
| f5091aa1ae | |||
| bb08207569 | |||
| 71e0d7d8e2 | |||
| 3b27670d4d | |||
| 944dd1cc7f | |||
| ba3a45452e | |||
| f7c5a4a15b | |||
| 4d5bfe2ee8 | |||
| a1a6469ed0 | |||
| fcf66c2e75 | |||
| b4f0bb65c6 | |||
| 938a4007b3 | |||
| 6470e6cc25 | |||
| 9769a17866 | |||
| 19355e947e | |||
| d9a8c89b5a | |||
| 6688b4ea78 | |||
| d05565c6e0 | |||
| ec26a28cd2 | |||
| 05755b9b09 | |||
| 007cafa7cd | |||
| a9ce2fc38a | |||
| 0175932d86 | |||
| 26cdea53c7 | |||
| e585b07d76 | |||
| 6eb5b544b4 | |||
| 9c0495b563 | |||
| 2c25db28c4 | |||
| 14464ab6cc | |||
| a4b2d032f9 | |||
| 3078c28d1a | |||
| cf90c8176e | |||
| 0a8bcf6530 | |||
| bf0dbeb8b3 | |||
| b453ee5e1f | |||
| 2e8fe6a1ab | |||
| e0be566491 | |||
| 936b2d4188 | |||
| 9a204593e1 | |||
| 6aa4bb9f08 | |||
| 562e63a3b0 | |||
| 663e29af89 | |||
| 4f6b67b190 | |||
| 1b85310f1a | |||
| 6aa3706bec | |||
| 92ad67a814 | |||
| 14399e3d57 | |||
| a321ab3653 | |||
| ce3fa18fb6 | |||
| 4064e933fe | |||
| f5868a0952 | |||
| 35c1c3774c | |||
| 628b03f3c0 | |||
| c6f3fbb82c | |||
| 504cc7b7dd | |||
| e6205e8f26 | |||
| 620a50223c | |||
| 646adbf186 | |||
| 73f2fc76d9 | |||
| 553969f0fd | |||
| ee142c5fe1 | |||
| 97dfcb9fb0 | |||
| 97ee31e751 | |||
| 338af10aaf | |||
| 020a3e6d6b | |||
| 5e05ad03bb | |||
| 8d988d1bd2 | |||
| f3db058fef | |||
| b49a15efeb | |||
| be5b35e999 | |||
| 30697ca0a1 | |||
| 0e19ca68b4 | |||
| f82131af15 | |||
| 16ca8d178d | |||
| cdac156f2e | |||
| ba335346f2 | |||
| 82b3790f85 | |||
| 52c0fd8f09 | |||
| e37b26e068 | |||
| 6ac4157fc1 | |||
| b9cbb7a72b | |||
| 0aca6920a7 | |||
| a6e8e10a3d | |||
| bfbc69e8f9 | |||
| 13c76c12f8 | |||
| 08ebf50480 | |||
| a6b5e6360b | |||
| b49f8a81a8 | |||
| ab5b66facc | |||
| 35c6ea68cc | |||
| b74cb8828b | |||
| a1b84c6fa3 | |||
| 3e3d01063d | |||
| c19cc61c48 | |||
| 5854edafdd | |||
| 2c33e72eea | |||
| 24ab5026c9 | |||
| c74ef80f79 | |||
| eeb11046d5 | |||
| 66f3f0f3de | |||
| a1bce24461 | |||
| 1c2d0afd95 | |||
| 6e52ca3f4e | |||
| 1d1f72fdc2 | |||
| d25bd8c1c6 | |||
| 3e0827deea | |||
| 481c7ea4e6 | |||
| 646477be08 | |||
| 3e2c626696 | |||
| 38ce8b494e | |||
| 292e2f6b69 | |||
| 94c3a384b1 | |||
| 5f07b4bf9b | |||
| 68754c4b5d | |||
| ff4ccc1d85 | |||
| d84a2f8215 | |||
| 86738e965f | |||
| 818f28d85f | |||
| 5f7356c16c | |||
| b0b708ddea | |||
| 4adf23b4e9 | |||
| 2f29e761c2 | |||
| 8aede81188 | |||
| c151da684d | |||
| bf4e927142 | |||
| 7cb0b1a911 | |||
| 6cbae7025c | |||
| 202bece16d | |||
| f07df01185 | |||
| 702978fa4b | |||
| b79473b2f5 | |||
| 80b59441d5 | |||
| f422ec457a | |||
| 5048b6bdaf | |||
| 01dc4611b9 | |||
| 5495516c30 | |||
| 2f8112b108 | |||
| 229c24e1f2 | |||
| 832d59803a | |||
| 197639a34b | |||
| bb229a3a0c | |||
| eca818be5a | |||
| 33896adf9d | |||
| f5223b1643 | |||
| ecc2bbd752 | |||
| d019405d51 | |||
| 7d62dff7e5 | |||
| dd8e4c620b | |||
| 77a62670d3 | |||
| 8e8b78a4c3 | |||
| 249ee4b318 | |||
| 226bcd1360 | |||
| 4956ed11f4 | |||
| b44a3c7650 | |||
| fa83147926 | |||
| 14afea1a20 | |||
| 4fdc4a2e06 | |||
| 0864e8a24f | |||
| 6af85aea18 | |||
| 0d4155b902 | |||
| 91193bf928 | |||
| b57248e822 | |||
| 487b80b9b0 | |||
| 818a70bdd7 | |||
| 940f5be35e | |||
| 88fd7b226a | |||
| 2f6cea2be3 | |||
| b4a1b4c8fb | |||
| 2f3963417f | |||
| 8de03275c3 | |||
| 60f52b2cd8 | |||
| dd101c99e5 | |||
| a45e6da3d0 | |||
| 2b6f45e4c1 | |||
| 332de67fe2 | |||
| ff3fd02115 | |||
| 437c9d07f5 | |||
| 9abe47f350 | |||
| 7a884ced32 | |||
| 0ace8bda8c | |||
| 15bc238297 | |||
| 1b94c7a8b3 | |||
| c31f99937f | |||
| 4258b99b2b | |||
| 29c0e17ca2 | |||
| d51d9e9fff | |||
| d5f2c41f26 | |||
| 7eb395b87d | |||
| 19d7d79229 | |||
| 526dc54173 | |||
| a136192db2 | |||
| 5dbc4f9954 | |||
| 447d3818f5 | |||
| 7c45f8f053 | |||
| 497d4d26bb | |||
| db6a8c2e05 | |||
| a16230c9ca | |||
| 0bbbf468f0 | |||
| 9bcba6c8b8 | |||
| a1fe76fb5b | |||
| dc613df3b1 | |||
| 45a8a0fb53 | |||
| aa210166c4 | |||
| 43a3fef7bb | |||
| 55bebb0f62 | |||
| 18ae44f930 | |||
| dc3899dfd9 | |||
| b6b4b0cdf9 | |||
| 8be73967fd | |||
| 2e26b6bf8b | |||
| b473862da6 | |||
| 0a9581a375 | |||
| 5bd67495ed | |||
| 23509c1688 | |||
| a63f548528 | |||
| ee8ed2828a | |||
| 35daf5df78 | |||
| 3ca2d4dab3 | |||
| c12b1870b7 | |||
| fd36726357 | |||
| 8dc1bb0659 | |||
| 38413dc236 | |||
| ef94ad36cd | |||
| e40e4298ca | |||
| 1d3947c0da | |||
| 69349925a3 | |||
| 921c7ede0d | |||
| e202ec009e | |||
| ced30acb20 | |||
| 3debaf99d8 | |||
| 2908e5da19 | |||
| 5afe7cfafb | |||
| d7829a76ce | |||
| ec779c001c | |||
| 028509c3a9 | |||
| fd5e312ed9 | |||
| 6710d66a58 | |||
| 1d44abfc8a | |||
| 0141779b9c | |||
| 92b1e9d9ac | |||
| 43b59911e2 | |||
| 240e37c387 | |||
| 39f71ab2ab | |||
| 6e37389145 | |||
| 554a9a72f1 | |||
| fd967d6976 | |||
| b451f07801 | |||
| 5ca560d0bd | |||
| 13fcbd6413 | |||
| 8782597c1a | |||
| ab4750ec1e | |||
| b519fdd3cb | |||
| 08cbaf8ccf | |||
| 6b2a838e24 | |||
| 854b448536 | |||
| 2195e433dc | |||
| d13be09524 | |||
| e34d6e3678 | |||
| 79247dad41 | |||
| 61691ac47d | |||
| 3e756f5d1c | |||
| 026c4a2711 | |||
| cd3556f195 | |||
| d0a6ae7855 | |||
| b245d68568 | |||
| 2c4effe6ce | |||
| 5ed381fc58 | |||
| 4c08e65fab | |||
| 4dde341c9d | |||
| ed3cae6f11 | |||
| 56c33e994d | |||
| d6820f2c2d | |||
| cf4b7b36ee | |||
| d23ebd354b | |||
| 66c60c4e6d | |||
| 19b803bb03 | |||
| 982f61774d | |||
| 7982492f50 | |||
| 7af7afc30e | |||
| ab2dc5877f | |||
| 592c98fd7a | |||
| facf17e689 | |||
| 1db9642e4c | |||
| 4df4527e77 | |||
| dbf0bb209d | |||
| 9a7c6b8be1 | |||
| 36fc43c364 | |||
| f80758f0de | |||
| 25ef60a2c1 | |||
| 5bfdb71b4c | |||
| 890b1c4f60 | |||
| 4046ecc99e | |||
| fe297e1dea | |||
| f0c0b2230a | |||
| 23ec55975e | |||
| 54da31e805 | |||
| b0f29b20db | |||
| c13ed8c625 | |||
| 79463d7f7d | |||
| 77ff657351 | |||
| 85412f0a41 | |||
| 54a6992ae0 | |||
| 2c35514537 | |||
| 7fea7b30b2 | |||
| f0d55c9a3f | |||
| 3336d66fc4 | |||
| 19d27258d9 | |||
| 58e4b98d61 | |||
| c73e87e9c8 | |||
| 6482c11f92 | |||
| f4a952032a | |||
| dd5a7bcd54 | |||
| 34f6de0c84 | |||
| 2678342c4a | |||
| 0f53fea903 | |||
| 9b1e5928bd | |||
| 31ef821e46 | |||
| 3119badb2b | |||
| acae6e20de | |||
| 7a17baccac | |||
| 4956259124 | |||
| a5f70e15a2 | |||
| 2df100213b | |||
| e989d41d50 | |||
| edc0a9ac87 | |||
| 5334a2d965 | |||
| 7c10f3422a | |||
| ea62092d6e | |||
| e977d099e2 | |||
| bf82bac328 | |||
| 25bd2bc7fe | |||
| 93b26d947c | |||
| 8290026940 | |||
| 4badd3b6ac | |||
| 69a2194efe | |||
| b5c8b99272 | |||
| 35926b96b4 | |||
| d1cf37bbec | |||
| 4c61d254cc | |||
| 9c68810c77 | |||
| 4417608b27 | |||
| a105dcb060 | |||
| 0cf0992f78 | |||
| 842ebfcca0 | |||
| 376ee2ed90 | |||
| 2f1397c50e | |||
| cdbb000638 | |||
| 8a413018c2 | |||
| 03f2de75f5 | |||
| 38c0f3cdc8 | |||
| 4d95ac08dd | |||
| fc77b48344 | |||
| ff500d8297 | |||
| e2ee44617c | |||
| 25009ff9f4 | |||
| bc51bd0dbd | |||
| 8a27b5446d | |||
| 2cc2039ad8 | |||
| 04f6a2be37 | |||
| 2538001b08 | |||
| e8f630b93a | |||
| 49210e3099 | |||
| 96c0ff44f9 | |||
| 56bccce713 | |||
| 89be1c2ede | |||
| c77f7e727b | |||
| 36080fb682 | |||
| 98f51dc91f | |||
| d2524b20d5 | |||
| 068c93e562 | |||
| e0e58711bb | |||
| 2cbd61f268 | |||
| 4827db4f56 | |||
| 1a44fe29b4 | |||
| e032a8c54f | |||
| 214ef31053 | |||
| 978adbbd94 | |||
| e6535dcc67 | |||
| d3ddf10839 | |||
| 69805f36fa | |||
| 6a3436b1c4 | |||
| 62f9f6e6c5 | |||
| 96aaba738b | |||
| f83fc51960 | |||
| e1575e3177 | |||
| 3d28a7837d | |||
| 44b4c29d08 | |||
| 9f2fda6060 | |||
| 3bfb2b5cc1 | |||
| 82b97b9639 | |||
| d01c24bd23 | |||
| 163d185776 | |||
| 6305ddca18 | |||
| b82b66fdf0 | |||
| b425093813 | |||
| f30d2b9f1c | |||
| 9e96043255 | |||
| bd300e870c | |||
| e06f533f6b | |||
| 7088ba88a9 | |||
| 0313adaec6 | |||
| 50b1e4c36f | |||
| a94caf218f | |||
| ab2b70f189 | |||
| 3190c0ed6c | |||
| 461a5eb315 | |||
| 01ef834b82 | |||
| 0211c8145d | |||
| 4a9892fa15 | |||
| 71bfefa788 | |||
| 071c858055 | |||
| 0244963935 | |||
| 3adb238b31 | |||
| e3100110f0 | |||
| 5224a796cc | |||
| 285b3858dd | |||
| 53bea055aa | |||
| 129b0e99cf | |||
| c0e4af9ac0 | |||
| ccd94bb734 | |||
| e1b3bd611d | |||
| 6ab7e339bd | |||
| 67a87af459 | |||
| aaecdc4b8a | |||
| 78466384c4 | |||
| ca7a0813b4 | |||
| bc0d8613ab | |||
| 0434c1424a | |||
| 3f8a303286 | |||
| 5ceffdd5a7 | |||
| 01da93bf70 | |||
| 028a3c2ded | |||
| 1698b8ec04 | |||
| 9e018532c8 | |||
| 24cb7cb039 | |||
| 7c28aba6a1 | |||
| 2309f9b8bc | |||
| ddcb94649d | |||
| 5f7e16eac3 | |||
| da034b3090 | |||
| 12d515a8fe | |||
| f5f3c85112 | |||
| d8153b702a | |||
| 9a4f5bb2d9 | |||
| 7624284070 | |||
| c32cbd90e8 | |||
| c068d20588 | |||
| c74ab439ef | |||
| 44c77364ce | |||
| 0dbbf53fbe | |||
| 052d006c88 | |||
| 0e91ea9e5f | |||
| 5803c51633 | |||
| 35a7342416 | |||
| e9d7ac68da | |||
| 56a0c8ed1d | |||
| 4eaa8e19c9 | |||
| 414948d822 | |||
| 02e6bf8759 | |||
| 8baed08641 | |||
| 4e39f4cab1 | |||
| 9f0d79da9a | |||
| 80fcd2eb56 | |||
| 5aead42964 | |||
| ab75683bc9 | |||
| d8c3aae412 | |||
| 5e78c53572 | |||
| 44d3e844a3 | |||
| 85c2097ece | |||
| cb20c9b0d7 | |||
| d9a493561b | |||
| 70956ece12 | |||
| adaf392156 | |||
| 37b99639d4 | |||
| a8ab6c1568 | |||
| 4a1e45070e | |||
| b33ac47228 | |||
| 6e91399922 | |||
| 75a8be230b | |||
| 07b1210b50 | |||
| 532e8ee228 | |||
| 574dbbfd08 | |||
| 332fb55e3a | |||
| 5610d00b4d | |||
| 8bfccb42a9 | |||
| 7ca5bebab3 | |||
| d5aa4be7e5 | |||
| 1a687a4f1a | |||
| 13b78b1ad2 | |||
| 48cf5cb84a | |||
| 5317dd64d7 | |||
| a25609f66b | |||
| d6e6432a46 | |||
| 094fa47f9f | |||
| 6f7cf2e58b | |||
| b08ae07347 | |||
| ffbf8d5faa | |||
| f55274c7fb | |||
| b9074097da | |||
| 83a33726ce | |||
| 8c33e12616 | |||
| 87218e1447 | |||
| 06965000a5 | |||
| cc033b3b98 | |||
| 290040ad9d | |||
| 264e72830b | |||
| d05c2ee8a1 | |||
| b32aba27c1 | |||
| 22e79490ff | |||
| 1a311a30b5 | |||
| 999f3233bb | |||
| 07651d712f | |||
| 6f931ce4fd | |||
| e93e846e16 | |||
| 4e2e68a3fb | |||
| e95df7999f | |||
| 2a43998444 | |||
| 06eea52ad8 | |||
| 389b5e6448 | |||
| a19f280fcc | |||
| e4646a6788 | |||
| 58bfea2ad1 | |||
| ad4a1c2a59 |
@@ -1,37 +0,0 @@
|
||||
#
|
||||
# You can add personal rules in your file .git/info/exclude
|
||||
*.swp
|
||||
*~
|
||||
/contrib/extract_translations/extract_translations.beam
|
||||
/doc/*.aux
|
||||
/doc/*.haux
|
||||
/doc/*.html
|
||||
/doc/*.htoc
|
||||
/doc/*.idx
|
||||
/doc/*.ilg
|
||||
/doc/*.ind
|
||||
/doc/*.log
|
||||
/doc/*.out
|
||||
/doc/*.pdf
|
||||
/doc/*.toc
|
||||
/doc/contributed_modules.tex
|
||||
/doc/version.tex
|
||||
/src/*.beam
|
||||
/src/*.so
|
||||
/src/*/*.beam
|
||||
/src/*/Makefile
|
||||
/src/Makefile
|
||||
/src/XmppAddr.asn1db
|
||||
/src/XmppAddr.erl
|
||||
/src/XmppAddr.hrl
|
||||
/src/aclocal.m4
|
||||
/src/autom4te.cache
|
||||
/src/config.log
|
||||
/src/config.status
|
||||
/src/ejabberd.init
|
||||
/src/ejabberdctl.example
|
||||
/src/eldap/ELDAPv3.asn1db
|
||||
/src/eldap/ELDAPv3.erl
|
||||
/src/eldap/ELDAPv3.hrl
|
||||
/src/eldap/eldap_filter_yecc.erl
|
||||
/src/epam
|
||||
@@ -8,19 +8,16 @@ Quickstart guide
|
||||
To compile ejabberd you need:
|
||||
- GNU Make
|
||||
- GCC
|
||||
- Libexpat 1.95 or higher
|
||||
- Erlang/OTP R10B-9 or higher. Recommended: R12B-5 and R13B04.
|
||||
Avoid R14A and R14B.
|
||||
- Erlang/OTP R12B-5 or higher.
|
||||
- exmpp 0.9.5 or higher
|
||||
- OpenSSL 0.9.8 or higher, for STARTTLS, SASL and SSL encryption.
|
||||
- Zlib 1.2.3 or higher, for Stream Compression support
|
||||
(XEP-0138). Optional.
|
||||
- Erlang mysql library. Optional. MySQL authentication/storage.
|
||||
- Erlang pgsql library. Optional. PostgreSQL authentication/storage.
|
||||
- PAM library. Optional. For Pluggable Authentication Modules (PAM).
|
||||
- GNU Iconv 1.8 or higher, for the IRC Transport
|
||||
(mod_irc). Optional. Not needed on systems with GNU Libc.
|
||||
- ESASL library. Optional. For SASL GSSAPI authentication.
|
||||
- ImageMagick's Convert program. Optional. For CAPTCHA challenges.
|
||||
- exmpp 0.9.2 or higher. Optional. For import/export XEP-0227 files.
|
||||
|
||||
|
||||
1. Compile and install on *nix systems
|
||||
|
||||
@@ -281,14 +281,14 @@ build_additional_translators(List) ->
|
||||
List).
|
||||
|
||||
print_translation(File, Line, Str, StrT) ->
|
||||
{ok, StrQ, _} = regexp:gsub(Str, "\"", "\\\""),
|
||||
{ok, StrTQ, _} = regexp:gsub(StrT, "\"", "\\\""),
|
||||
StrQ = re:replace(Str, "\\\"", "\\\\\\\"", [global, {return, list}]),
|
||||
StrTQ = re:replace(StrT, "\\\"", "\\\\\\\"", [global, {return, list}]),
|
||||
io:format("#: ~s:~p~nmsgid \"~s\"~nmsgstr \"~s\"~n~n", [File, Line, StrQ, StrTQ]).
|
||||
|
||||
print_translation_obsolete(Str, StrT) ->
|
||||
File = "unknown.erl",
|
||||
Line = 1,
|
||||
{ok, StrQ, _} = regexp:gsub(Str, "\"", "\\\""),
|
||||
{ok, StrTQ, _} = regexp:gsub(StrT, "\"", "\\\""),
|
||||
StrQ = re:replace(Str, "\\\"", "\\\\\\\"", [global, {return, list}]),
|
||||
StrTQ = re:replace(StrT, "\\\"", "\\\\\\\"", [global, {return, list}]),
|
||||
io:format("#: ~s:~p~n#~~ msgid \"~s\"~n#~~ msgstr \"~s\"~n~n", [File, Line, StrQ, StrTQ]).
|
||||
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
# $Id$
|
||||
|
||||
SHELL = /bin/bash
|
||||
|
||||
CONTRIBUTED_MODULES = ""
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
@author Mickael Remond <mickael.remond@process-one.net>
|
||||
[http://www.process-one.net/]
|
||||
@copyright 2007 ProcessOne
|
||||
@version {@vsn}, {@date} {@time}
|
||||
@title ejabberd Development API Documentation
|
||||
|
||||
@doc
|
||||
== Introduction ==
|
||||
|
||||
TODO: Insert content from Jerome documentation.
|
||||
@@ -2,7 +2,7 @@
|
||||
"http://www.w3.org/TR/REC-html40/loose.dtd">
|
||||
<HTML>
|
||||
<HEAD>
|
||||
<TITLE>Ejabberd 2.1.6 Developers Guide
|
||||
<TITLE>Ejabberd 3.0.0-prealpha Developers Guide
|
||||
</TITLE>
|
||||
|
||||
<META http-equiv="Content-Type" content="text/html; charset=US-ASCII">
|
||||
@@ -49,7 +49,7 @@ TD P{margin:0px;}
|
||||
<!--HEVEA command line is: /usr/bin/hevea -fix -pedantic dev.tex -->
|
||||
<!--CUT DEF section 1 --><P><A NAME="titlepage"></A>
|
||||
|
||||
</P><TABLE CLASS="title"><TR><TD><H1 CLASS="titlemain">Ejabberd 2.1.6 Developers Guide</H1><H3 CLASS="titlerest">Alexey Shchepin<BR>
|
||||
</P><TABLE CLASS="title"><TR><TD><H1 CLASS="titlemain">Ejabberd 3.0.0-prealpha Developers Guide</H1><H3 CLASS="titlerest">Alexey Shchepin<BR>
|
||||
<A HREF="mailto:alexey@sevcom.net"><TT>mailto:alexey@sevcom.net</TT></A><BR>
|
||||
<A HREF="xmpp:aleksey@jabber.ru"><TT>xmpp:aleksey@jabber.ru</TT></A></H3></TD></TR>
|
||||
</TABLE><DIV CLASS="center">
|
||||
@@ -98,7 +98,7 @@ Comprehensive documentation.
|
||||
</LI><LI CLASS="li-itemize">Capability to send announce messages.
|
||||
</LI></UL></LI><LI CLASS="li-itemize">Internationalized: <TT>ejabberd</TT> leads in internationalization. Hence it is very well suited in a globalized world. Related features are:
|
||||
<UL CLASS="itemize"><LI CLASS="li-itemize">
|
||||
Translated to 25 languages. </LI><LI CLASS="li-itemize">Support for <A HREF="http://www.ietf.org/rfc/rfc3490.txt">IDNA</A>.
|
||||
Translated to 24 languages. </LI><LI CLASS="li-itemize">Support for <A HREF="http://www.ietf.org/rfc/rfc3490.txt">IDNA</A>.
|
||||
</LI></UL></LI><LI CLASS="li-itemize">Open Standards: <TT>ejabberd</TT> is the first Open Source Jabber server claiming to fully comply to the XMPP standard.
|
||||
<UL CLASS="itemize"><LI CLASS="li-itemize">
|
||||
Fully XMPP compliant.
|
||||
@@ -141,7 +141,6 @@ Support for virtual hosting.
|
||||
</LI><LI CLASS="li-itemize"><A HREF="http://www.xmpp.org/extensions/xep-0045.html">Multi-User Chat</A> module with support for clustering and HTML logging. </LI><LI CLASS="li-itemize">Users Directory based on users vCards.
|
||||
</LI><LI CLASS="li-itemize"><A HREF="http://www.xmpp.org/extensions/xep-0060.html">Publish-Subscribe</A> component with support for <A HREF="http://www.xmpp.org/extensions/xep-0163.html">Personal Eventing via Pubsub</A>.
|
||||
</LI><LI CLASS="li-itemize">Support for web clients: <A HREF="http://www.xmpp.org/extensions/xep-0025.html">HTTP Polling</A> and <A HREF="http://www.xmpp.org/extensions/xep-0206.html">HTTP Binding (BOSH)</A> services.
|
||||
</LI><LI CLASS="li-itemize">IRC transport.
|
||||
</LI><LI CLASS="li-itemize">Component support: interface with networks such as AIM, ICQ and MSN installing special tranports.
|
||||
</LI></UL>
|
||||
</LI></UL><!--TOC section How it Works-->
|
||||
|
||||
@@ -15,4 +15,4 @@ clean:
|
||||
|
||||
docs:
|
||||
erl -noshell -run edoc_run application \
|
||||
"'$(APPNAME)'" '"$(SRCDIR)"' '[{dir,"$(DOCDIR)"},{packages, false},{todo,true},{private,true},{def,{vsn,"$(VSN)"}},{stylesheet,"process-one.css"},{overview,"$(DOCDIR)/overview.edoc"}]' -s init stop
|
||||
"'$(APPNAME)'" '"$(SRCDIR)"' '[{dir,"$(DOCDIR)"},{packages, false},{todo,false},{private,true},{def,{vsn,"$(VSN)"}},{stylesheet,"process-one.css"},{overview,"$(DOCDIR)/overview.edoc"}]' -s init stop
|
||||
|
After Width: | Height: | Size: 4.0 KiB |
|
After Width: | Height: | Size: 976 B |
|
After Width: | Height: | Size: 679 B |
@@ -0,0 +1,19 @@
|
||||
.comment {color: brown}
|
||||
.export {color: darkorchid}
|
||||
.import {color: darkorchid}
|
||||
.string {color: maroon}
|
||||
.builtin {color: dodgerblue}
|
||||
.guard {color: mediumturquoise}
|
||||
.function {color: blue}
|
||||
.variable {color: green}
|
||||
.macro {color: mediumpurple}
|
||||
.record {color: orangered}
|
||||
.call {color: purple}
|
||||
.attribute {color: firebrick}
|
||||
.error{color: red}
|
||||
.l {
|
||||
font-style: normal;
|
||||
font-weight: normal;
|
||||
text-decoration: none;
|
||||
color: gray;
|
||||
}
|
||||
@@ -0,0 +1,356 @@
|
||||
%%%-------------------------------------------------------------------
|
||||
%%% File : escobar_hiliter.erl
|
||||
%%% Author : Mats Cronqvist <mats.cronqvist@gmail.com>
|
||||
%%% Description :
|
||||
%%%
|
||||
%%% Created : 6 Jun 2005 by Mats Cronqvist <mats.cronqvist@gmail.com>
|
||||
%%%
|
||||
%%%
|
||||
%%% Escobar, Copyright (c) 2005-2009 Mats Cronqvist
|
||||
%%%
|
||||
%%% MIT License:
|
||||
%%%
|
||||
%%% Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
%%% of this software and associated documentation files (the "Software"), to deal
|
||||
%%% in the Software without restriction, including without limitation the rights
|
||||
%%% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
%%% copies of the Software, and to permit persons to whom the Software is
|
||||
%%% furnished to do so, subject to the following conditions:
|
||||
%%%
|
||||
%%% The above copyright notice and this permission notice shall be included in
|
||||
%%% all copies or substantial portions of the Software.
|
||||
%%%
|
||||
%%% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
%%% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
%%% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
%%% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
%%% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
%%% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
%%% THE SOFTWARE.
|
||||
%%%
|
||||
%%%-------------------------------------------------------------------
|
||||
|
||||
-module(escobar_hilite).
|
||||
|
||||
-export([file/1,tree/1,string/1,out/2]).
|
||||
|
||||
-define(LOG(T),escobar:log(process_info(self()),T)).
|
||||
|
||||
-import(erl_syntax,
|
||||
[get_ann/1,add_ann/2,subtrees/1,update_tree/2,type/1,get_pos/1,
|
||||
application/2,application_arguments/1,application_operator/1,
|
||||
arity_qualifier_argument/1,arity_qualifier_body/1,
|
||||
atom_name/1,atom_value/1,
|
||||
attribute/2,attribute_name/1,attribute_arguments/1,
|
||||
clause/3,clause_patterns/1,clause_guard/1,clause_body/1,
|
||||
comment/2,comment_text/1,comment_padding/1,
|
||||
function/2,function_name/1,function_clauses/1,function_arity/1,
|
||||
integer_literal/1,
|
||||
list/1,list_elements/1,
|
||||
macro/2,macro_name/1,macro_arguments/1,
|
||||
module_qualifier_body/1, module_qualifier_argument/1,
|
||||
string_value/1,string_literal/1,
|
||||
variable_literal/1,variable_name/1,
|
||||
record_access/3, record_access_argument/1,
|
||||
record_access_field/1,record_access_type/1,
|
||||
record_expr/3, record_expr_argument/1,
|
||||
record_expr_fields/1, record_expr_type/1,
|
||||
record_index_expr/2, record_index_expr_field/1,
|
||||
record_index_expr_type/1,
|
||||
form_list/1,
|
||||
get_precomments/1,get_postcomments/1,has_comments/1,
|
||||
copy_comments/2,remove_comments/1]).
|
||||
|
||||
-import(prettypr,
|
||||
[above/2,follow/2,beside/2,empty/0,
|
||||
null_text/1,break/1,floating/3,text/1,floating/1]).
|
||||
|
||||
-import(lists,[flatten/1,duplicate/2,keysearch/3,member/2,usort/1,reverse/1]).
|
||||
|
||||
-import(filename,[join/1,basename/1]).
|
||||
|
||||
out(File,HtmlString) ->
|
||||
{ok,FD}=file:open(File,[write]),
|
||||
try
|
||||
io:fwrite(FD,"<html>",[]),
|
||||
io:fwrite(FD,"<link rel=\"stylesheet\" type=\"text/css\"",[]),
|
||||
io:fwrite(FD,"href=\"escobar.css\"></link><body><pre>",[]),
|
||||
io:fwrite(FD,"~s",[HtmlString]),
|
||||
io:fwrite(FD,"</pre></body></html>",[])
|
||||
after
|
||||
file:close(FD)
|
||||
end.
|
||||
|
||||
string(Str) ->
|
||||
tree(form_list(scan_and_parse(Str,1,[]))).
|
||||
|
||||
scan_and_parse([],_Line,Forms) -> reverse(Forms);
|
||||
scan_and_parse(Text,Line,Forms) ->
|
||||
{done,{ok,Toks,NLine},Cont} = erl_scan:tokens([],Text,Line),
|
||||
{ok,Form} = erl_parse:parse_form(Toks),
|
||||
scan_and_parse(Cont,NLine,[Form|Forms]).
|
||||
|
||||
file(FileName) ->
|
||||
case filelib:is_regular(FileName) of
|
||||
true ->
|
||||
case filename:extension(FileName) of
|
||||
".beam"-> tree(get_tree_beam(FileName));
|
||||
".erl" -> tree(get_comm_tree_erl(FileName));
|
||||
".hrl" -> tree(get_comm_tree_erl(FileName));
|
||||
X -> erlang:error({unknown_extension,X})
|
||||
end;
|
||||
false->
|
||||
erlang:error({no_file,FileName})
|
||||
end.
|
||||
|
||||
get_comm_tree_erl(Filename) ->
|
||||
Comms = erl_comment_scan:file(Filename),
|
||||
Forms = get_forms_erl(Filename),
|
||||
erl_recomment:recomment_forms(Forms,Comms).
|
||||
|
||||
get_tree_beam(Filename) ->
|
||||
case beam_lib:chunks(Filename,["Abst"]) of
|
||||
{ok,{_,[{"Abst",AChunk}]}} ->
|
||||
{_,Forms} = binary_to_term(AChunk),
|
||||
form_list(Forms);
|
||||
_ ->
|
||||
erlang:error({no_debuginfo,Filename})
|
||||
end.
|
||||
|
||||
get_forms_erl(Filename) ->
|
||||
{ok,Fs} = epp_dodger:parse_file(Filename,[{no_fail, true}]),
|
||||
Fs.
|
||||
|
||||
%%% # tree
|
||||
%%% turn a syntax tree into html by annotating and pretty-printing
|
||||
%%% with a hook function
|
||||
|
||||
tree(Tree) ->
|
||||
pout(ann(type(Tree),Tree)).
|
||||
|
||||
%%lists:foldl(fun(Form,Acc) -> [pout(ann(Form))|Acc] end, [], Tree).
|
||||
|
||||
pout(Form) ->
|
||||
erl_prettypr:format(Form,[{hook,fun tag/3},{paper,90},{ribbon,650}]).
|
||||
|
||||
%%% ## formatting
|
||||
%%% ### 'tag' - the format hook function
|
||||
tag(Node,Ctxt,Cont) ->
|
||||
Tags = get_ann(Node),
|
||||
case member(has_comment,Tags) of
|
||||
true ->
|
||||
PreC = get_precomments(Node),
|
||||
PostC = get_postcomments(Node),
|
||||
Nod = remove_comments(Node),
|
||||
Doc0 = tagit(Tags--[has_comment],Cont(Nod,Ctxt)),
|
||||
postcomment(precomment(Doc0,PreC),PostC);
|
||||
false ->
|
||||
Doc0 = Cont(Node,Ctxt),
|
||||
tagit(Tags,Doc0)
|
||||
end.
|
||||
|
||||
tagit([],Doc0) ->
|
||||
Doc0;
|
||||
tagit(["binary"],{beside,_,{beside,Doc,_}}) ->
|
||||
beside(floating(text("<<")),beside(Doc,floating(text(">>"))));
|
||||
tagit([Tag],Doc0) ->
|
||||
beside(null_text(Tag),beside(Doc0,null_text(etag(Tag)))).
|
||||
|
||||
etag("<"++Tag) -> "</"++hd(string:tokens(Tag," "))++">".
|
||||
|
||||
%%%### comment stuff
|
||||
precomment(Doc,PreC) ->
|
||||
above(floating(break(stack(PreC)), -1, -1), Doc).
|
||||
postcomment(Doc,PostC) ->
|
||||
beside(Doc, floating(break(stack(PostC)), 1, 0)).
|
||||
|
||||
stack([]) -> empty();
|
||||
stack([Comm|Comms]) ->
|
||||
Doc = maybe_pad(stack_comment_lines(comment_text(Comm)),Comm),
|
||||
case Comms of
|
||||
[] -> Doc;
|
||||
_ -> above(Doc, stack(Comms))
|
||||
end.
|
||||
|
||||
maybe_pad(Doc,Comm) ->
|
||||
case comment_padding(Comm) of
|
||||
I when is_integer(I), 0 < I -> beside(text(duplicate(I,$ )), Doc);
|
||||
_ -> Doc
|
||||
end.
|
||||
|
||||
%%% stolen with pride from erl_prettypr
|
||||
%%% Stack lines of text above each other and prefix each string in
|
||||
%%% the list with a single `%' character.
|
||||
|
||||
stack_comment_lines([S | Ss]) ->
|
||||
D = tagit([dehtml('span', [{class,comment}])],text("%"++debracket(S))),
|
||||
case Ss of
|
||||
[] -> D;
|
||||
_ -> above(D, stack_comment_lines(Ss))
|
||||
end;
|
||||
stack_comment_lines([]) ->
|
||||
empty().
|
||||
|
||||
%%% annotate nodes that should be hilited
|
||||
%%% the annotation is put on the subtree that should be marked up
|
||||
%%% the annotation is;
|
||||
%%% has_comments|Markup
|
||||
%%% if a node already has an annotation the new one is dropped, except
|
||||
%%% if either the new or the old one is has_comments
|
||||
|
||||
ann(binary,Tree) ->
|
||||
new_tree(Tree,add_anno("binary",Tree));
|
||||
ann(application,Tree) ->
|
||||
Op = application_operator(Tree),
|
||||
Args = application_arguments(Tree),
|
||||
new_tree(Tree,application(add_anno(mu(application,Tree),Op),Args));
|
||||
ann(attribute,Tree) ->
|
||||
Name = attribute_name(Tree),
|
||||
case atom_value(Name) of
|
||||
export ->
|
||||
AQs = list_elements(hd(attribute_arguments(Tree))),
|
||||
Args = [list([add_anno(mu(export,Tree),AQ) || AQ <- AQs])];
|
||||
import ->
|
||||
[ImportMod,ImportFAs] = attribute_arguments(Tree),
|
||||
AQs = list_elements(ImportFAs),
|
||||
Args = [ImportMod,list([add_anno(mu(import,Tree),AQ) || AQ <- AQs])];
|
||||
define ->
|
||||
[Macro|Rest] = attribute_arguments(Tree),
|
||||
case type(Macro) of
|
||||
application ->
|
||||
Op = application_operator(Macro),
|
||||
As = application_arguments(Macro),
|
||||
Args = [application(add_anno(mu(macro,Tree),Op),As)|Rest];
|
||||
_ ->
|
||||
Args = [add_anno(mu(macro,Tree),Macro)|Rest]
|
||||
end;
|
||||
record ->
|
||||
[Rec|Rest] = attribute_arguments(Tree),
|
||||
Args = [add_anno(mu(record,Tree),Rec)|Rest];
|
||||
_ ->
|
||||
Args = attribute_arguments(Tree)
|
||||
end,
|
||||
new_tree(Tree,attribute(add_anno(mu(attribute,Tree),Name),Args));
|
||||
ann(record_access,Tree) ->
|
||||
Arg = record_access_argument(Tree),
|
||||
Type = record_access_type(Tree),
|
||||
Field = record_access_field(Tree),
|
||||
new_tree(Tree,record_access(Arg,add_anno(mu(record,Tree),Type),Field));
|
||||
ann(record_expr,Tree) ->
|
||||
Arg = record_expr_argument(Tree),
|
||||
Type = record_expr_type(Tree),
|
||||
Fields = record_expr_fields(Tree),
|
||||
new_tree(Tree,record_expr(Arg,add_anno(mu(record,Tree),Type),Fields));
|
||||
ann(record_index_expr,Tree) ->
|
||||
Type = record_index_expr_type(Tree),
|
||||
Field = record_index_expr_field(Tree),
|
||||
new_tree(Tree,record_index_expr(add_anno(mu(record,Tree),Type),Field));
|
||||
ann(function,Tree) ->
|
||||
Name = function_name(Tree),
|
||||
Clauses = function_clauses(Tree),
|
||||
new_tree(Tree,function(add_anno(mu(function,Tree),Name),Clauses));
|
||||
ann(macro,Tree) ->
|
||||
Name = macro_name(Tree),
|
||||
Args = macro_arguments(Tree),
|
||||
new_tree(Tree,macro(add_anno(mu(macro,Tree),Name), Args));
|
||||
ann(string,OTree) ->
|
||||
Tree = erl_syntax:string(debracket(string_value(OTree))),
|
||||
new_tree(OTree,add_anno(mu(string,OTree),Tree));
|
||||
ann(variable,Tree) ->
|
||||
new_tree(Tree,add_anno(mu(variable,Tree),Tree));
|
||||
ann(text,Tree) ->
|
||||
new_tree(Tree,add_anno(mu(error,Tree),Tree));
|
||||
ann(comment,OTree) ->
|
||||
Pad = comment_padding(OTree),
|
||||
Text = [debracket(S) || S <- comment_text(OTree)],
|
||||
Tree = comment(Pad,Text),
|
||||
new_tree(OTree,add_anno(mu(comment,OTree),Tree));
|
||||
ann(_Typ,Tree) ->
|
||||
new_tree(Tree,Tree).
|
||||
|
||||
new_tree(OTree,NTree) ->
|
||||
Tree =
|
||||
case has_comments(OTree) of
|
||||
true -> add_ann(has_comment,copy_comments(OTree,NTree));
|
||||
false -> NTree
|
||||
end,
|
||||
SubTrees = subtrees(Tree),
|
||||
case [[ann(type(SubT),SubT) || SubT<-Group] || Group<-SubTrees] of
|
||||
[] -> Tree;
|
||||
NSubtrees -> update_tree(Tree,NSubtrees)
|
||||
end.
|
||||
|
||||
debracket([]) -> [];
|
||||
debracket([$>|Str]) -> ">"++debracket(Str);
|
||||
debracket([$<|Str]) -> "<"++debracket(Str);
|
||||
debracket([C|Str]) -> [C|debracket(Str)].
|
||||
|
||||
add_anno(nil,Tree) -> Tree;
|
||||
add_anno(Ann,Tree) ->
|
||||
case get_ann(Tree) of
|
||||
[] -> add_ann(Ann,Tree);
|
||||
[has_comment] -> add_ann(Ann,Tree);
|
||||
_OAnn -> Tree
|
||||
end.
|
||||
|
||||
%%%### the markups
|
||||
mu(application,Node) ->
|
||||
Op = application_operator(Node),
|
||||
Ar = length(application_arguments(Node)),
|
||||
case type(Op) of
|
||||
%% variable ->
|
||||
%% dehtml('span', [{class,variable}]);
|
||||
atom ->
|
||||
case is_guard_or_builtin(atom_value(Op),Ar) of
|
||||
guard -> dehtml('span', [{class,guard}]);
|
||||
builtin->dehtml('span', [{class,builtin}]);
|
||||
neither->dehtml('span', [{class,call}])
|
||||
end;
|
||||
module_qualifier ->
|
||||
Mod = module_qualifier_argument(Op),
|
||||
Fun = module_qualifier_body(Op),
|
||||
case {type(Mod),type(Fun)} of
|
||||
{atom,atom} ->
|
||||
case atom_value(Mod) of
|
||||
erlang -> dehtml('span', [{class,builtin}]);
|
||||
_ -> dehtml('span', [{class,call}])
|
||||
end;
|
||||
_ ->
|
||||
nil
|
||||
end;
|
||||
_ ->
|
||||
nil
|
||||
end;
|
||||
mu(function = Class, {tree, function, _, {function, _, [{tree, clause, _, {clause, Vars, _, _}} | _]}}) ->
|
||||
dehtml('span', [{class,Class}, {arity,length(Vars)}]);
|
||||
mu(Class,_Node) ->
|
||||
dehtml('span', [{class,Class}]).
|
||||
|
||||
dehtml(Tag,Atts) ->
|
||||
flatten([$<,str(Tag),$ ,[[str(A),"=\"",str(V),"\" "]||{A,V}<-Atts],$>]).
|
||||
|
||||
str(I) when is_integer(I) -> integer_to_list(I);
|
||||
str(A) when is_atom(A) -> atom_to_list(A);
|
||||
str(L) when is_list(L) -> L.
|
||||
|
||||
is_guard_or_builtin(atom,1) ->guard;
|
||||
is_guard_or_builtin(binary,1) ->guard;
|
||||
is_guard_or_builtin(constant,1) ->guard;
|
||||
is_guard_or_builtin(float,1) ->guard;
|
||||
is_guard_or_builtin(function,1) ->guard;
|
||||
is_guard_or_builtin(function,2) ->guard;
|
||||
is_guard_or_builtin(integer,1) ->guard;
|
||||
is_guard_or_builtin(list,1) ->guard;
|
||||
is_guard_or_builtin(number,1) ->guard;
|
||||
is_guard_or_builtin(pid,1) ->guard;
|
||||
is_guard_or_builtin(port,1) ->guard;
|
||||
is_guard_or_builtin(reference,1) ->guard;
|
||||
is_guard_or_builtin(tuple,1) ->guard;
|
||||
is_guard_or_builtin(record,2) ->guard;
|
||||
is_guard_or_builtin(record,3) ->guard;
|
||||
is_guard_or_builtin(F,A) ->
|
||||
case erlang:function_exported(erlang,F,A) orelse
|
||||
erlang:is_builtin(erlang,F,A) of
|
||||
true -> builtin;
|
||||
false-> neither
|
||||
end.
|
||||
@@ -0,0 +1,54 @@
|
||||
%%%-------------------------------------------------------------------
|
||||
%%% File : escobar_run.erl
|
||||
%%% Author : Badlop <badlop@process-one.net>
|
||||
%%% Purpose : Frontend to run Escobar
|
||||
%%% Created : 16 Apr 2008 by Badlop <badlop@process-one.net>
|
||||
%%%-------------------------------------------------------------------
|
||||
-module(escobar_run).
|
||||
|
||||
%%% Download ejabberd_hilite.erl from http://code.google.com/p/erl-escobar/
|
||||
|
||||
%%% Example calls:
|
||||
%%% escobar_run:file("escobar_run.erl", "../ejascobar/").
|
||||
%%% escobar_run:dir(".", "../ejascobar/").
|
||||
%%% escobar_run:dir(".", "../doc/api/").
|
||||
%%% find ./ -type f -name '*.html' -exec sed -i 's/class="function" >\([a-z0-9]*\)</class="function" id="\1">\1</;' {} \;
|
||||
|
||||
-export([file/2, file/1, dir/1]).
|
||||
|
||||
file([F, OutDir]) ->
|
||||
file(F, OutDir).
|
||||
|
||||
file(F, OutDir) ->
|
||||
String = escobar_hilite:file(F),
|
||||
FB = filename:basename(F),
|
||||
FilenameHTML = filename:join(OutDir, FB ++ ".html"),
|
||||
escobar_hilite:out(FilenameHTML, String).
|
||||
|
||||
dir([SrcDir, OutDir]) ->
|
||||
SrcDirAbs = filename:absname(SrcDir),
|
||||
OutDirAbs = filename:absname(OutDir),
|
||||
Files = get_files([SrcDirAbs]),
|
||||
lists:foreach(
|
||||
fun(F) ->
|
||||
case filename:extension(F) of
|
||||
".erl" ->
|
||||
file(F, OutDirAbs);
|
||||
".hrl" ->
|
||||
file(F, OutDirAbs);
|
||||
_ ->
|
||||
ok
|
||||
end
|
||||
end,
|
||||
Files).
|
||||
|
||||
get_files([]) ->
|
||||
[];
|
||||
get_files([FHead | FTail]) ->
|
||||
case catch file:list_dir(FHead) of
|
||||
{ok, Files} ->
|
||||
FilesHead = [filename:join(FHead, FilesN) || FilesN <- Files],
|
||||
get_files(FilesHead ++ FTail);
|
||||
{error, enotdir} ->
|
||||
[FHead] ++ get_files(FTail)
|
||||
end.
|
||||
|
After Width: | Height: | Size: 318 B |
@@ -0,0 +1,522 @@
|
||||
%%%----------------------------------------------------------------------
|
||||
%%% File : funrelg.erl
|
||||
%%% Author : Badlop <badlop@process-one.net>
|
||||
%%% Purpose : Function Relation Graph
|
||||
%%% Created : 3 Apr 2007 by Badlop <badlop@process-one.net>
|
||||
%%%
|
||||
%%%
|
||||
%%% ejabberd, Copyright (C) 2002-2009 ProcessOne
|
||||
%%%
|
||||
%%% This program is free software; you can redistribute it and/or
|
||||
%%% modify it under the terms of the GNU General Public License as
|
||||
%%% published by the Free Software Foundation; either version 2 of the
|
||||
%%% License, or (at your option) any later version.
|
||||
%%%
|
||||
%%% This program is distributed in the hope that it will be useful,
|
||||
%%% but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
%%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
%%% General Public License for more details.
|
||||
%%%
|
||||
%%% You should have received a copy of the GNU General Public License
|
||||
%%% along with this program; if not, write to the Free Software
|
||||
%%% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||
%%% 02111-1307 USA
|
||||
%%%
|
||||
%%%----------------------------------------------------------------------
|
||||
|
||||
-module(funrelg).
|
||||
|
||||
-author('badlop@process-one.net').
|
||||
|
||||
-export([dir/1, file/1, g/0, g/1, gc/0, gc/1, d/0]).
|
||||
|
||||
-record(mfa, {mod, func, arity}).
|
||||
-record(arcs, {id, from, to, occ}).
|
||||
|
||||
%% The functions that are not in export and don't call anybody are not drawn
|
||||
%% The calls to this module that use Mod:Func are drawn as external calls
|
||||
|
||||
%%-----------------------------
|
||||
%% Module handlers
|
||||
%%-----------------------------
|
||||
|
||||
dir([SrcDir, OutDir]) ->
|
||||
SrcDirAbs = filename:absname(SrcDir),
|
||||
OutDirAbs = filename:absname(OutDir),
|
||||
Files = get_files([SrcDirAbs]),
|
||||
lists:foreach(
|
||||
fun(F) ->
|
||||
file(F, OutDirAbs)
|
||||
end,
|
||||
Files).
|
||||
|
||||
file([SrcDir, OutDir]) ->
|
||||
SrcFilAbs = filename:absname(SrcDir),
|
||||
OutDirAbs = filename:absname(OutDir),
|
||||
file(SrcFilAbs, OutDirAbs).
|
||||
|
||||
file(SrcFile, OutDir) ->
|
||||
case {filename:extension(SrcFile), filename:basename(SrcFile)} of
|
||||
%% The file must by *.erl, and the first character must be a-z
|
||||
{".erl", [FirstChar | _]} when (FirstChar >= 97) and (FirstChar =< 122) ->
|
||||
make_file(SrcFile, OutDir),
|
||||
d();
|
||||
_ ->
|
||||
ok
|
||||
end.
|
||||
|
||||
get_files([]) ->
|
||||
[];
|
||||
get_files([FHead | FTail]) ->
|
||||
case catch file:list_dir(FHead) of
|
||||
{ok, Files} ->
|
||||
FilesHead = [filename:join(FHead, FilesN) || FilesN <- Files],
|
||||
get_files(FilesHead ++ FTail);
|
||||
{error, enotdir} ->
|
||||
[FHead] ++ get_files(FTail)
|
||||
end.
|
||||
|
||||
make_file(File, OutDir) ->
|
||||
FB = filename:basename(File),
|
||||
FileDot = filename:join(OutDir, FB ++ ".dot"),
|
||||
Text = gc(File),
|
||||
{ok,FO}=file:open(FileDot,[write]),
|
||||
try
|
||||
io:fwrite(FO,"~s",[Text])
|
||||
after
|
||||
file:close(FO)
|
||||
end,
|
||||
FileSvg = filename:join(OutDir, filename:basename(File, ".erl") ++ ".svg"),
|
||||
case os:cmd("dot -Tsvg " ++ FileDot ++ " -o " ++ FileSvg) of
|
||||
"" -> ok;
|
||||
ShellResult ->
|
||||
io:format("Trying to run 'dot', we got this result:~n ~s~n"
|
||||
"Remember that you need to have Graphviz 'dot' installed.~n", [ShellResult])
|
||||
end,
|
||||
ok.
|
||||
|
||||
%%====================================================================
|
||||
%% Internal functions
|
||||
%%====================================================================
|
||||
|
||||
g() ->
|
||||
g("a.erl").
|
||||
g(Filename) ->
|
||||
gc(Filename),
|
||||
halt().
|
||||
|
||||
gc() ->
|
||||
gc("a.erl").
|
||||
gc(Filename) ->
|
||||
{ok, File} = epp_dodger:parse_file(Filename),
|
||||
|
||||
ets:new(arcs, [set, public, named_table, {keypos, 2}]),
|
||||
ets:new(mfa_conversion, [set, public, named_table, {keypos, 1}]),
|
||||
ets:new(counters, [set, public, named_table]),
|
||||
ets:insert(counters, {arcs_id, 0}),
|
||||
|
||||
ModuleName = get_module_name(File),
|
||||
Exports = lists:usort(get_exports(File)),
|
||||
Functions = get_functions(File),
|
||||
FunctionsParsed = lists:usort(parse_functions(Functions)), % side effects: stores on ets
|
||||
Privates = FunctionsParsed -- Exports,
|
||||
%%Externals = get_externals(),
|
||||
|
||||
MFAs = get_func_calls(),
|
||||
|
||||
AppModules1 = os:cmd("ls -1 ../doc/devdoc/*.html | tr \".\" \" \" | tr \"/\" \" \" | awk '{print $3}'"),
|
||||
AppModules = [list_to_atom(Str) || Str <- string:tokens(AppModules1, [10])],
|
||||
|
||||
ExternalTypes1 = [mfa_to_externaltype(MFA, ModuleName, AppModules, FunctionsParsed) || MFA <- MFAs],
|
||||
ExternalTypes = lists:usort(ExternalTypes1),
|
||||
AppExternals = [Function || {Type, Function} <- ExternalTypes, Type == app],
|
||||
ExmppExternals = [Function || {Type, Function} <- ExternalTypes, Type == exmpp],
|
||||
OTPExternals = [Function || {Type, Function} <- ExternalTypes, Type == other],
|
||||
|
||||
textize(ModuleName, Exports, Privates, AppExternals, ExmppExternals, OTPExternals).
|
||||
|
||||
get_arcs_id() ->
|
||||
ets:update_counter(counters, arcs_id, 1).
|
||||
|
||||
insert_arc_normal(FromFunc, FromArity, ToFunc, ToArity) ->
|
||||
From = #mfa{mod = -1, func = FromFunc, arity = FromArity},
|
||||
To = #mfa{mod = -1, func = ToFunc, arity = ToArity},
|
||||
insert_arc(From, To).
|
||||
|
||||
insert_arc_external(FromFunc, FromArity, ToMod, ToFunc, ToArity) ->
|
||||
From = #mfa{mod = -1, func = FromFunc, arity = FromArity},
|
||||
To = #mfa{mod = ToMod, func = ToFunc, arity = ToArity},
|
||||
insert_arc(From, To).
|
||||
|
||||
insert_arc(From, To) ->
|
||||
Match = #arcs{
|
||||
from = From,
|
||||
to = To,
|
||||
id='$1',
|
||||
_='_'},
|
||||
Select = [{Match, [], ['$1']}],
|
||||
Ids = ets:select(arcs, Select),
|
||||
case Ids of
|
||||
[] ->
|
||||
ets:insert(arcs,
|
||||
#arcs{
|
||||
id = get_arcs_id(),
|
||||
from = From,
|
||||
to = To,
|
||||
occ = 1
|
||||
}
|
||||
);
|
||||
[Id] ->
|
||||
[Arc] = ets:lookup(arcs, Id),
|
||||
Arc2 = Arc#arcs{occ = Arc#arcs.occ+1},
|
||||
ets:insert(arcs, Arc2)
|
||||
end.
|
||||
|
||||
read_arc(Id) ->
|
||||
ets:lookup(arcs, Id).
|
||||
|
||||
d() ->
|
||||
ets:delete(arcs),
|
||||
ets:delete(mfa_conversion),
|
||||
ets:delete(counters).
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
%% Get
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
get_module_name(File) ->
|
||||
Attributes = get_elements(attribute, File),
|
||||
get_attribute(module, Attributes).
|
||||
|
||||
get_exports(File) ->
|
||||
Attributes = get_elements(attribute, File),
|
||||
Exports = get_attribute(export, Attributes),
|
||||
parse_export(Exports).
|
||||
|
||||
get_functions(File) ->
|
||||
get_elements(function, File).
|
||||
|
||||
get_elements(Type, L) -> get_elements(Type, L, []).
|
||||
get_elements(_, [], Res) -> Res;
|
||||
get_elements(Type, [{tree, Type, _, A} | L], Res) ->
|
||||
get_elements(Type, L, Res++[A]);
|
||||
get_elements(Type, [_ | L], Res) ->
|
||||
get_elements(Type, L, Res).
|
||||
|
||||
get_attribute(_, []) -> [];
|
||||
get_attribute(Name, [{attribute, {tree, atom, _, Name}, [Al]} | As]) ->
|
||||
case Name of
|
||||
module ->
|
||||
{tree, atom, _, Mn} = Al,
|
||||
Mn;
|
||||
export ->
|
||||
{tree, list, _, {list, Exports, _}} = Al,
|
||||
Exports++get_attribute(Name, As);
|
||||
_ -> ok
|
||||
end;
|
||||
get_attribute(Name, [_ | As]) ->
|
||||
get_attribute(Name, As).
|
||||
|
||||
parse_export(Ex) ->
|
||||
lists:foldl(
|
||||
fun(Aq, Res) ->
|
||||
{tree, arity_qualifier, _, {arity_qualifier, Atom, Inte}} = Aq,
|
||||
{tree, atom, _, An} = Atom,
|
||||
{tree, integer, _, In} = Inte,
|
||||
Res++[{An, In}]
|
||||
end,
|
||||
[],
|
||||
Ex).
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
%% Parse
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
parse_functions(Functions) ->
|
||||
lists:map(
|
||||
fun(E) ->
|
||||
{function, {_, _, _, Fn}, Clauses} = E,
|
||||
Arity = get_function_arity(Clauses),
|
||||
parse_clauses(Fn, Clauses),
|
||||
{Fn, Arity}
|
||||
end,
|
||||
Functions).
|
||||
|
||||
parse_clauses(Fn, Clauses) ->
|
||||
lists:foreach(
|
||||
fun(E) ->
|
||||
{tree, clause, L, C} = E,
|
||||
{attr, _Ln, _, _} = L,
|
||||
{clause, Parameters, _, Contents} = C,
|
||||
Fa = length(Parameters),
|
||||
parse_contents({Fn, Fa}, Contents)
|
||||
end,
|
||||
Clauses).
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
%% OLD
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
parse_contents(F, Contents) ->
|
||||
{_, Res} = lists:foldl(
|
||||
fun(C, {Fu, R}) ->
|
||||
{Fu, R++parse_content(F, C)}
|
||||
end,
|
||||
{F, []},
|
||||
Contents),
|
||||
Res.
|
||||
|
||||
parse_content(F, {tree, application, L, A}) ->
|
||||
{attr, _Ln, _, _} = L,
|
||||
parse_application(F, A);
|
||||
parse_content(F, {tree, list, _, {list, [L], Ls}}) ->
|
||||
RL = parse_content(F, L),
|
||||
RL++parse_content(F, Ls);
|
||||
parse_content(F, {tree, tuple, _, T}) ->
|
||||
parse_contents(F, T);
|
||||
parse_content(F, {tree, match_expr, _, M}) ->
|
||||
{match_expr, _, Value} = M,
|
||||
parse_content(F, Value);
|
||||
parse_content(F, {tree, try_expr, _, T}) ->
|
||||
{try_expr, As, Bs, Cs, Ds} = T,
|
||||
RAs = parse_contents(F, As),
|
||||
RBs = parse_contents(F, Bs),
|
||||
RDs = parse_contents(F, Ds),
|
||||
RAs++RBs++RDs++parse_contents(F, Cs);
|
||||
parse_content(F, {tree, block_expr, _, Ts}) ->
|
||||
parse_contents(F, Ts);
|
||||
parse_content(F, {tree, catch_expr, _, C}) ->
|
||||
parse_content(F, C);
|
||||
parse_content(F, {tree, case_expr, _, C}) ->
|
||||
{case_expr, Case, Cases} = C,
|
||||
R2 = parse_content(F, Case),
|
||||
R2++parse_contents(F, Cases);
|
||||
parse_content(F, {tree, if_expr, _, Cases}) ->
|
||||
parse_contents(F, Cases);
|
||||
parse_content(F, {tree, disjunction, _, Cases}) ->
|
||||
parse_contents(F, Cases);
|
||||
parse_content(F, {tree, conjunction, _, Cases}) ->
|
||||
parse_contents(F, Cases);
|
||||
parse_content(F, {tree, list_comp, _, L}) ->
|
||||
{list_comp, A, Bs} = L,
|
||||
RA = parse_content(F, A),
|
||||
RA++parse_contents(F, Bs);
|
||||
parse_content(F, {tree, generator, _, G}) ->
|
||||
{generator, _, Gen} = G,
|
||||
parse_content(F, Gen);
|
||||
parse_content(F, {tree, clause, _, C}) ->
|
||||
{clause, Clause, When, Second} = C,
|
||||
R2 = parse_contents(F, Clause),
|
||||
R3 = parse_content(F, When),
|
||||
R2++R3++parse_contents(F, Second);
|
||||
parse_content(F, {tree, fun_expr, _, E}) ->
|
||||
parse_contents(F, E);
|
||||
parse_content(F, {tree, record_expr, _, E}) ->
|
||||
{record_expr, _, _, Records} = E,
|
||||
parse_contents(F, Records);
|
||||
parse_content(F, {tree, record_field, _, R}) ->
|
||||
{record_field, F1, F2} = R,
|
||||
R2 = parse_content(F, F1),
|
||||
R2++parse_content(F, F2);
|
||||
parse_content(F, {tree, receive_expr, _, E}) ->
|
||||
{receive_expr, E1, _, _} = E,
|
||||
parse_contents(F, E1);
|
||||
parse_content(F, {tree, infix_expr, _, I}) ->
|
||||
{infix_expr, _Operator, T1, T2} = I,
|
||||
R = parse_content(F, T1),
|
||||
R++parse_content(F, T2);
|
||||
parse_content(_F, {tree, prefix_expr, _, _P}) ->
|
||||
[];
|
||||
parse_content(_F, {tree, class_qualifier, _, _}) -> [];
|
||||
parse_content(_F, {tree, implicit_fun, _, _}) -> [];
|
||||
parse_content(_F, {tree, record_access, _, _}) -> [];
|
||||
parse_content(_F, {tree, record_index_expr, _, _}) -> [];
|
||||
parse_content(_F, {tree, macro, _, _}) -> [];
|
||||
parse_content(_F, {tree, binary, _, _}) -> [];
|
||||
parse_content(_F, {tree, binary_generator, _, _}) -> [];
|
||||
parse_content(_F, {tree, binary_comp, _, _}) -> [];
|
||||
parse_content(_F, {integer, _, _I}) -> [];
|
||||
parse_content(_F, {float, _, _I}) -> [];
|
||||
parse_content(_F, {string, _, _S}) -> [];
|
||||
parse_content(_F, {char, _, _S}) -> [];
|
||||
parse_content(_F, {atom, _, _A}) -> [];
|
||||
parse_content(_F, {var, _, _V}) -> [];
|
||||
parse_content(_F, {nil, _}) -> [];
|
||||
parse_content(_F, none) -> [];
|
||||
parse_content(_F, C) -> io:format("Unknown content: ~p~n", [C]), [].
|
||||
|
||||
parse_application({Fn, Fa}, {application, {atom, _, Name}, Valores}) ->
|
||||
Arity = length(Valores),
|
||||
insert_arc_normal(Fn, Fa, Name, Arity),
|
||||
Ra = [{arc_normal, Fn, Name}],
|
||||
Ra++parse_contents({Fn, Fa}, Valores);
|
||||
parse_application({Fn, Fa}, {application, {tree, module_qualifier, _, M}, Tree2}) ->
|
||||
case M of
|
||||
{module_qualifier, {_, _, Tf1}, {_, _, Tf2}} ->
|
||||
ToArity = length(Tree2),
|
||||
insert_arc_external(Fn, Fa, Tf1, Tf2, ToArity),
|
||||
parse_contents({Fn, Fa}, Tree2);
|
||||
_Other ->
|
||||
%%io:format("Unknown application module_qualifier: ~p~n", [M]),
|
||||
parse_contents({Fn, Fa}, Tree2)
|
||||
end;
|
||||
parse_application({Fn, Fa}, {application, {tree, record_access, _, _}, Tree2}) ->
|
||||
parse_contents({Fn, Fa}, Tree2);
|
||||
parse_application({Fn, Fa}, {application, {var, _, _}, Tree2}) ->
|
||||
parse_contents({Fn, Fa}, Tree2);
|
||||
parse_application({Fn, Fa}, {application, Other, Tree2}) ->
|
||||
io:format("Unknown application tree: ~p~n", [Other]),
|
||||
parse_contents({Fn, Fa}, Tree2).
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
%% Textize
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
textize(ModuleName, Exports, Privates, AppExternals, ExmppExternals, OTPExternals) ->
|
||||
ExportsS = textize_exports(Exports),
|
||||
PrivatesS = textize_exports(Privates),
|
||||
AppExternalsS = textize_externals(AppExternals),
|
||||
ExmppExternalsS = textize_externals(ExmppExternals),
|
||||
OTPExternalsS = textize_externals(OTPExternals),
|
||||
Arcs = textize_arcs(),
|
||||
io_lib:format(
|
||||
"digraph ~p {~n"++
|
||||
" label = \"Module ~p\";~n"++
|
||||
" labelloc = \"t\";~n"++
|
||||
" fontname = Helvetica;~n"++
|
||||
" rankdir = LR;~n"++
|
||||
" ratio = fill;~n"++
|
||||
%%" node [shape = box, style = filled, color = olivedrab1, fontsize=40];~s~n"++
|
||||
%%" node [shape = parallelogram, style = filled, color = rosybrown1, fontsize=40];~s~n"++
|
||||
%%" node [shape = ellipse, style = filled, color = slategray1, peripheries=3, fontsize=40];~n"++
|
||||
" node [shape = box, color=darkgreen, fillcolor=Honeydew, style=filled, href=\"PRI~p.html#\\N\"];~s~n"++
|
||||
" node [shape = box, color=darkgreen, fillcolor=PaleGreen, style=filled, href=\"EXP~p.html#\\N\"];~s~n"++
|
||||
" node [shape = box, color=darkgreen, fillcolor=Aquamarine, style=filled, href=\"APP\\N\"];~s~n"++
|
||||
" node [shape = box, color=darkblue, fillcolor=LightSkyBlue,style=filled, href=\"EXM\\N\"];~s~n"++
|
||||
" node [shape = box, color=darkred, fillcolor=PeachPuff, style=filled, href=\"OTP\\N\"];~s~n"++
|
||||
" node [shape = box];~n"++
|
||||
"~s"++
|
||||
"}~n",
|
||||
[ModuleName, ModuleName,
|
||||
ModuleName, PrivatesS,
|
||||
ModuleName, ExportsS,
|
||||
AppExternalsS,
|
||||
ExmppExternalsS,
|
||||
OTPExternalsS,
|
||||
Arcs]).
|
||||
|
||||
textize_exports(Exports) ->
|
||||
lists:foldl(
|
||||
fun({Func, Arity}, R) ->
|
||||
string:concat(R, io_lib:format(" \"~p/~p\";", [Func, Arity]))
|
||||
end,
|
||||
"",
|
||||
Exports).
|
||||
|
||||
textize_externals(Externals) ->
|
||||
lists:foldl(
|
||||
fun({Mod, Func, Arity}, R) ->
|
||||
string:concat(R, io_lib:format(" \"~p:~p/~p\";", [Mod, Func, Arity]));
|
||||
({Func, Arity}, R) ->
|
||||
string:concat(R, io_lib:format(" \"~p/~p\";", [Func, Arity]))
|
||||
end,
|
||||
"",
|
||||
Externals).
|
||||
|
||||
textize_arcs() ->
|
||||
Id = ets:first(arcs),
|
||||
textize_arcs(Id, []).
|
||||
|
||||
textize_arcs('$end_of_table', Res) -> Res;
|
||||
textize_arcs(Id, Res) ->
|
||||
[Arc] = read_arc(Id),
|
||||
From = mfa_prepare(Arc#arcs.from),
|
||||
To = mfa_prepare(Arc#arcs.to),
|
||||
Edge_attrs = check_loop(From, To)++check_occu(Arc#arcs.occ)++check_external(Arc#arcs.to),
|
||||
Res2 = io_lib:format(" ~s -> ~s~s;~n", [From, To, Edge_attrs]),
|
||||
Id_next = ets:next(arcs, Id),
|
||||
textize_arcs(Id_next, string:concat(Res2, Res)).
|
||||
|
||||
get_func_calls() ->
|
||||
Id = ets:first(arcs),
|
||||
get_func_calls(Id, []).
|
||||
|
||||
get_func_calls('$end_of_table', Res) -> Res;
|
||||
get_func_calls(Id, Res) ->
|
||||
[Arc] = read_arc(Id),
|
||||
MFA = Arc#arcs.to,
|
||||
Call = MFA,
|
||||
Id_next = ets:next(arcs, Id),
|
||||
get_func_calls(Id_next, [Call | Res]).
|
||||
|
||||
mfa_prepare(MFAinitial) ->
|
||||
MFA = try_mfa_conversion(MFAinitial),
|
||||
Mod = case MFA#mfa.mod of
|
||||
-1 -> "\"";
|
||||
M -> io_lib:format("\"~p:", [M])
|
||||
end,
|
||||
Func = io_lib:format("~p", [MFA#mfa.func]),
|
||||
Arity = case MFA#mfa.arity of
|
||||
-1 -> "\"";
|
||||
A -> io_lib:format("/~p\"", [A])
|
||||
end,
|
||||
string:concat(Mod, string:concat(Func, Arity)).
|
||||
|
||||
%% noexternal | app | exmpp | other
|
||||
mfa_to_externaltype(MFA, ModuleName, AppModules, Functions) ->
|
||||
case MFA of
|
||||
{mfa, -1, Fu, Ar} ->
|
||||
case {is_internal, lists:member({Fu, Ar}, Functions)} of
|
||||
{is_internal, true} ->
|
||||
{noexternal, {Fu, Ar}};
|
||||
{is_internal, false} ->
|
||||
store_mfa_conversion(MFA, {mfa, -1, Fu, Ar}),
|
||||
{other, {Fu, Ar}}
|
||||
end;
|
||||
{mfa, Mo, Fu, Ar} when Mo == ModuleName ->
|
||||
store_mfa_conversion(MFA, {mfa, -1, Fu, Ar}),
|
||||
{noexternal, {Fu, Ar}};
|
||||
{mfa, Mo, Fu, Ar} ->
|
||||
Type = case {is_app, lists:member(Mo, AppModules)} of
|
||||
{is_app, true} -> app;
|
||||
{is_app, false} ->
|
||||
case string:str(atom_to_list(Mo), "exmpp") of
|
||||
0 -> other;
|
||||
N when is_integer(N) -> exmpp
|
||||
end
|
||||
end,
|
||||
{Type, {Mo, Fu, Ar}}
|
||||
end.
|
||||
|
||||
get_function_arity([{tree, clause, _, {clause, Vars, _, _}} | _]) ->
|
||||
length(Vars);
|
||||
get_function_arity(E) ->
|
||||
io:format("Unknown function arity: ~p~n", [E]).
|
||||
|
||||
store_mfa_conversion(MFA1, MFA2) ->
|
||||
ets:insert(mfa_conversion, {MFA1, MFA2}).
|
||||
|
||||
try_mfa_conversion(MFA) ->
|
||||
case ets:lookup(mfa_conversion, MFA) of
|
||||
[{MFA,MFA2}] ->
|
||||
MFA2;
|
||||
[] ->
|
||||
MFA
|
||||
end.
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
%% Utils
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
%%check_loop(I, I) -> " [color = sandybrown]";
|
||||
check_loop(I, I) -> "";
|
||||
check_loop(_, _) -> "".
|
||||
|
||||
check_occu(1) -> "";
|
||||
check_occu(Occ) -> io_lib:format(" [label=\"~p\"]", [Occ]).
|
||||
|
||||
check_external(To) ->
|
||||
case To#mfa.mod of
|
||||
-1 -> " [style = bold]";
|
||||
_ -> ""
|
||||
end.
|
||||
@@ -1,3 +1,25 @@
|
||||
div.navbar table tr td a[target="_parent"] {
|
||||
background: transparent url("ejabberd-devdoc.png") no-repeat;
|
||||
display: block;
|
||||
font-size: 0%;
|
||||
top: 0;
|
||||
left: 0;
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
width: 192px;
|
||||
height: 42px;
|
||||
}
|
||||
|
||||
div.navbar table tr td a img {
|
||||
border: 0;
|
||||
padding: 0 0 0 10;
|
||||
float: right;
|
||||
}
|
||||
|
||||
p i {
|
||||
display: none;
|
||||
}
|
||||
|
||||
html, body {
|
||||
font-family: Verdana, sans-serif;
|
||||
color: #000;
|
||||
@@ -5,19 +27,20 @@ html, body {
|
||||
}
|
||||
|
||||
h1 {
|
||||
font-size: 20px;
|
||||
color: #4a5389;
|
||||
border-bottom: solid 1px #000;
|
||||
}
|
||||
|
||||
h2 {
|
||||
font-size: 24px;
|
||||
font-size: 18px;
|
||||
text-align: right;
|
||||
color: #4a5389;
|
||||
border-bottom: 1px solid #000;
|
||||
}
|
||||
|
||||
h3 {
|
||||
font-size: 18px;
|
||||
font-size: 16px;
|
||||
color: #900;
|
||||
}
|
||||
|
||||
|
After Width: | Height: | Size: 717 B |
@@ -2,7 +2,7 @@
|
||||
"http://www.w3.org/TR/REC-html40/loose.dtd">
|
||||
<HTML>
|
||||
<HEAD>
|
||||
<TITLE>Ejabberd 2.1.6 Feature Sheet
|
||||
<TITLE>Ejabberd 3.0.0-prealpha Feature Sheet
|
||||
</TITLE>
|
||||
|
||||
<META http-equiv="Content-Type" content="text/html; charset=US-ASCII">
|
||||
@@ -50,7 +50,7 @@ SPAN{width:20%; float:right; text-align:left; margin-left:auto;}
|
||||
<!--HEVEA command line is: /usr/bin/hevea -fix -pedantic features.tex -->
|
||||
<!--CUT DEF section 1 --><P><A NAME="titlepage"></A>
|
||||
|
||||
</P><TABLE CLASS="title"><TR><TD><H1 CLASS="titlemain">Ejabberd 2.1.6 Feature Sheet</H1><H3 CLASS="titlerest">Sander Devrieze<BR>
|
||||
</P><TABLE CLASS="title"><TR><TD><H1 CLASS="titlemain">Ejabberd 3.0.0-prealpha Feature Sheet</H1><H3 CLASS="titlerest">Sander Devrieze<BR>
|
||||
<A HREF="mailto:s.devrieze@pandora.be"><TT>mailto:s.devrieze@pandora.be</TT></A><BR>
|
||||
<A HREF="xmpp:sander@devrieze.dyndns.org"><TT>xmpp:sander@devrieze.dyndns.org</TT></A></H3></TD></TR>
|
||||
</TABLE><DIV CLASS="center">
|
||||
@@ -76,7 +76,7 @@ Comprehensive documentation.
|
||||
</LI><LI CLASS="li-itemize">Capability to send announce messages.
|
||||
</LI></UL></LI><LI CLASS="li-itemize"><B><FONT SIZE=4><FONT COLOR="#001376">Internationalized:</FONT></FONT></B> <TT>ejabberd</TT> leads in internationalization. Hence it is very well suited in a globalized world. Related features are:
|
||||
<UL CLASS="itemize"><LI CLASS="li-itemize">
|
||||
Translated to 25 languages. </LI><LI CLASS="li-itemize">Support for <A HREF="http://www.ietf.org/rfc/rfc3490.txt">IDNA</A>.
|
||||
Translated to 24 languages. </LI><LI CLASS="li-itemize">Support for <A HREF="http://www.ietf.org/rfc/rfc3490.txt">IDNA</A>.
|
||||
</LI></UL></LI><LI CLASS="li-itemize"><B><FONT SIZE=4><FONT COLOR="#001376">Open Standards:</FONT></FONT></B> <TT>ejabberd</TT> is the first Open Source Jabber server claiming to fully comply to the XMPP standard.
|
||||
<UL CLASS="itemize"><LI CLASS="li-itemize">
|
||||
Fully XMPP compliant.
|
||||
@@ -120,7 +120,6 @@ Support for virtual hosting.
|
||||
</LI><LI CLASS="li-itemize"><A HREF="http://www.xmpp.org/extensions/xep-0045.html">Multi-User Chat</A> module with support for clustering and HTML logging. </LI><LI CLASS="li-itemize">Users Directory based on users vCards.
|
||||
</LI><LI CLASS="li-itemize"><A HREF="http://www.xmpp.org/extensions/xep-0060.html">Publish-Subscribe</A> component with support for <A HREF="http://www.xmpp.org/extensions/xep-0163.html">Personal Eventing via Pubsub</A>.
|
||||
</LI><LI CLASS="li-itemize">Support for web clients: <A HREF="http://www.xmpp.org/extensions/xep-0025.html">HTTP Polling</A> and <A HREF="http://www.xmpp.org/extensions/xep-0206.html">HTTP Binding (BOSH)</A> services.
|
||||
</LI><LI CLASS="li-itemize">IRC transport.
|
||||
</LI><LI CLASS="li-itemize">Component support: interface with networks such as AIM, ICQ and MSN installing special tranports.
|
||||
</LI></UL>
|
||||
</LI></UL><!--CUT END -->
|
||||
|
||||
@@ -68,7 +68,7 @@ Peter Saint-Andr\'e, Executive Director of the Jabber Software Foundation}
|
||||
|
||||
\item \marking{Internationalized:} \ejabberd{} leads in internationalization. Hence it is very well suited in a globalized world. Related features are:
|
||||
\begin{itemize}
|
||||
\item Translated to 25 languages. %%\improved{}
|
||||
\item Translated to 24 languages. %%\improved{}
|
||||
\item Support for \footahref{http://www.ietf.org/rfc/rfc3490.txt}{IDNA}.
|
||||
\end{itemize}
|
||||
|
||||
@@ -127,7 +127,6 @@ Moreover, \ejabberd{} comes with a wide range of other state-of-the-art features
|
||||
\item Users Directory based on users vCards.
|
||||
\item \txepref{0060}{Publish-Subscribe} component with support for \txepref{0163}{Personal Eventing via Pubsub}.
|
||||
\item Support for web clients: \txepref{0025}{HTTP Polling} and \txepref{0206}{HTTP Binding (BOSH)} services.
|
||||
\item IRC transport.
|
||||
\item Component support: interface with networks such as AIM, ICQ and MSN installing special tranports.
|
||||
\end{itemize}
|
||||
\end{itemize}
|
||||
|
||||
|
Before Width: | Height: | Size: 140 KiB |
|
Before Width: | Height: | Size: 78 KiB |
|
Before Width: | Height: | Size: 23 KiB |
|
Before Width: | Height: | Size: 21 KiB |
@@ -6,7 +6,7 @@
|
||||
and includes several minor bugfixes and a few improvements.
|
||||
|
||||
Read more details about the changes in:
|
||||
http://redir.process-one.net/ejabberd-2.1.4
|
||||
http://redir.process-one.net/ejabberd-2.1.5
|
||||
|
||||
Download the source code and installers from:
|
||||
http://www.process-one.net/en/ejabberd/
|
||||
|
||||
@@ -1,67 +0,0 @@
|
||||
|
||||
Release Notes
|
||||
ejabberd 2.1.6
|
||||
|
||||
ejabberd 2.1.6 is the sixth release in ejabberd 2.1.x branch,
|
||||
and includes a lot of bugfixes and improvements.
|
||||
|
||||
Read more details about the changes in:
|
||||
http://redir.process-one.net/ejabberd-2.1.6
|
||||
|
||||
Download the source code and installers from:
|
||||
http://www.process-one.net/en/ejabberd/
|
||||
|
||||
|
||||
Some of the changes are:
|
||||
|
||||
* Account register
|
||||
- mod_register: New ip_access option restricts which IPs can register (EJAB-915)
|
||||
- mod_register: Default configuration allows registrations only from localhost
|
||||
- mod_register: New password_strength for entropy check (EJAB-1326)
|
||||
- mod_register: New captcha_protected option to require CAPTCHA (EJAB-1262)
|
||||
- mod_register_web: New module, with CAPTCHA support (EJAB-471)
|
||||
|
||||
* BOSH
|
||||
- Don't loop when there is nothing after a stream start (EJAB-1358)
|
||||
- Fix http-bind supervisor to support multiple vhosts (EJAB-1321)
|
||||
- Support to restart http-bind (EJAB-1318)
|
||||
- Support for X-Forwarded-For HTTP header (EJAB-1356)
|
||||
|
||||
* Erlang/OTP compatibility
|
||||
- R11: Fix detection of Erlang R11 and older (EJAB-1287)
|
||||
- R12B5: Fix compatibility in ejabberd_http_bind.erl (EJAB-1343)
|
||||
- R14A: Make xml.c correctly compile (EJAB-1288)
|
||||
- R14A, R14B: Disapprove the use of R14A and R14B due to the rwlock bug
|
||||
- R14B: Use pg2 from this version in systems with older ones (EJAB-1349)
|
||||
|
||||
* Listeners
|
||||
- Bind listener ports early and start accepting connections later
|
||||
- Fix a leak of ejabberd_receiver processes
|
||||
- Speed up ejabberd_s2s:is_service/2, allow_host/2 (EJAB-1319)
|
||||
- S2S: New option to require encryption (EJAB-495)
|
||||
- S2S: New option to reject connection if untrusted certificate (EJAB-464)
|
||||
- S2S: Include From attribute in the stream header of outgoing S2S connections
|
||||
- S2S: Fix domain_certfile tlsopts modifications for S2S connections (EJAB-1086)
|
||||
|
||||
* Pubsub/PEP/Caps
|
||||
- Fix pubsub cross domain eventing (EJAB-1340)
|
||||
- Use one_queue IQ discipline by default
|
||||
- Implement lifetime for broken hashes
|
||||
- New CAPS processing
|
||||
|
||||
* ODBC
|
||||
- Increase maximum restart strategy to handle some SQL timeouts
|
||||
- Support PostgreSQL 9.0 (EJAB-1359)
|
||||
- Use MEDIUMTEXT type for vcard avatars in MySQL schema (EJAB-1252)
|
||||
|
||||
* Miscellanea:
|
||||
- mod_shared_roster_ldap: New Shared Roster Groups using LDAP information
|
||||
- mod_privacy: Fix to allow block by group and subscription again
|
||||
- Support timezone West of UTC (EJAB-1301)
|
||||
- Support to change loglevel per module at runtime (EJAB-225)
|
||||
|
||||
|
||||
Bug reports
|
||||
|
||||
You can officially report bugs on ProcessOne support site:
|
||||
http://support.process-one.net/
|
||||
@@ -0,0 +1,104 @@
|
||||
|
||||
******************************************************************************
|
||||
* These are the preliminary release notes of ejabberd 3.0.0.
|
||||
*
|
||||
* The download page for preliminary releases is:
|
||||
* http://download.process-one.net/ejabberd/
|
||||
*
|
||||
* WARNING!!! PRELIMINARY DATABASE SCHEMA !!!
|
||||
* The database schema may change before ejabberd 3.0.0 is released,
|
||||
* and no migration code will be developed for this preliminary schema.
|
||||
* The only supported migrations are
|
||||
* from any ejabberd 0.9.0 ... 2.1.5 to the final 3.0.0.
|
||||
* Don't use this preliminary ejabberd release for a production server.
|
||||
* You can test this release with a blank database or with a copy of your
|
||||
* production database, but don't let your users connect to this copy
|
||||
* because their changes may get lost when you upgrade to the final 3.0.0.
|
||||
******************************************************************************
|
||||
|
||||
|
||||
Release Notes
|
||||
ejabberd 3.0.0
|
||||
|
||||
ejabberd 3.0.0 is the first release in the brand new 3.x.x branch,
|
||||
and includes several minor bugfixes and a few improvements.
|
||||
|
||||
Read more details about the changes in:
|
||||
http://redir.process-one.net/ejabberd-3.0.0
|
||||
|
||||
Download the source code and installers from:
|
||||
http://www.process-one.net/en/ejabberd/
|
||||
|
||||
|
||||
ejabberd 3.0.0 includes three major changes:
|
||||
|
||||
* exmpp is now extensively used in ejabberd for parsing stanzas, and many more.
|
||||
|
||||
* gen_storage (abbreviated GS) provides a database abstraction layer,
|
||||
which supports storage in Mnesia and in ODBC databases.
|
||||
Several ejabberd modules use GS, like mod_roster and ejabberd_auth_storage.
|
||||
The schema of the tables stored by those modules have changed,
|
||||
and ejabberd migrates automatically your mnesia and ODBC
|
||||
tables from previous ejabberd releases.
|
||||
|
||||
* Massive Hosting (abbreviated MH) is preliminary implemented in ejabberd,
|
||||
but it is still incomplete, untested and undocumented.
|
||||
|
||||
|
||||
This is a more detailed list of changes since ejabberd 2.1.5:
|
||||
|
||||
* Requirements
|
||||
- Erlang/OTP R12B-5 or higher is required
|
||||
- exmpp 0.9.5 or higher is required, not optional
|
||||
- ESASL library is optional, for SASL GSSAPI authentication
|
||||
- Libexpat not required by ejabberd, it uses exmpp now (EJAB-1111)
|
||||
- GNU Iconv not required, because mod_irc isn't included anymore (EJAB-954)
|
||||
- Only database migration from ejabberd 0.9.0 up to 2.1.5 is supported
|
||||
- ejabberd modules developed for previous releases need to be upgraded to exmpp
|
||||
|
||||
* Configuration
|
||||
- New option clusterid
|
||||
- New option that can't be used yet: static_modules
|
||||
- ejabberd_auth_storage: new option auth_storage
|
||||
- mod_muc_log: option spam_prevention is now link_nofollow (EJAB-1141)
|
||||
- mod_roster: new access option (EJAB-72)
|
||||
- S2S: allow definition of local address for outgoing connections (EJAB-418)
|
||||
|
||||
* Database
|
||||
- New gen_storage that provides a database storage abstraction layer (EJAB-1102)
|
||||
- mod_*_odbc are obsolete, use the normal ones with the option {backend, odbc}
|
||||
- New ejabberd_auth_storage that supports internal and odbc databases
|
||||
|
||||
* XEP support
|
||||
- Removed support for the deprecated XEP-0018 Invisible Presence (EJAB-810)
|
||||
- mod_multicast: service for XEP-0033: Extended Stanza Addressing (EJAB-265)
|
||||
- New ejabberd router for multicast packets (XEP-0033) (EJAB-329)
|
||||
- ejabberd_c2s uses XEP-0033 if mod_multicast is enabled (EJAB-267)
|
||||
- mod_muc uses XEP-0033 if mod_multicast is enabled (EJAB-266)
|
||||
|
||||
* Pubsub/PEP/Caps
|
||||
- Allow distinguish between leafs and items (EJAB-1027)
|
||||
- Enforce disco features results (EJAB-1033, EJAB-1228, EJAB-1238)
|
||||
- Enforce pubsub#presence_based_delivery (EJAB-1221)
|
||||
- Improve get_caps while still waiting for initial presence (EJAB-934)
|
||||
- Make nodetree_tree implicitly create parent node if required (EJAB-944)
|
||||
- Only use binary() instead of string() in Host and ServerHost (EJAB-1244)
|
||||
- Rename NodeId (pubsub_node.id) bindings to Nidx (EJAB-1000)
|
||||
- node_flat becomes default; it has the code instead of hometree (EJAB-1077)
|
||||
- pubsub#notify_sub node option (EJAB-1230)
|
||||
- pubsub#type node config and payload namespace (EJAB-1083)
|
||||
|
||||
* Miscellanea
|
||||
- Bugfix handling Service Discovery to contacts (EJAB-1207)
|
||||
- Bugfix: external contacts were offline after unavailable presence (EJAB-943)
|
||||
- Don't offer SASL auth before doing TLS if TLS is required
|
||||
- Experimental support for GSSAPI auth, requires esasl library (EJAB-831)
|
||||
- Use binaries instead of lists where possible (EJAB-17)
|
||||
- Windows ejabberdctl.cmd only handles up to 4 arguments (EJAB-1216)
|
||||
- ejabberdctl: when starting, check it isn't already running
|
||||
|
||||
|
||||
Bug reports
|
||||
|
||||
You can officially report bugs on ProcessOne support site:
|
||||
http://support.process-one.net/
|
||||
@@ -1,2 +1,2 @@
|
||||
% ejabberd version (automatically generated).
|
||||
\newcommand{\version}{2.1.6}
|
||||
\newcommand{\version}{3.0.0-alpha-x}
|
||||
|
||||
@@ -42,22 +42,6 @@ while(1)
|
||||
# password is null. Return 1 if the user $user\@$domain exitst.
|
||||
$result = 1;
|
||||
},last SWITCH;
|
||||
|
||||
$op eq 'tryregister' and do
|
||||
{
|
||||
$result = 1;
|
||||
},last SWITCH;
|
||||
|
||||
$op eq 'removeuser' and do
|
||||
{
|
||||
# password is null. Return 1 if the user $user\@$domain exitst.
|
||||
$result = 1;
|
||||
},last SWITCH;
|
||||
|
||||
$op eq 'removeuser3' and do
|
||||
{
|
||||
$result = 1;
|
||||
},last SWITCH;
|
||||
};
|
||||
my $out = pack "nn",2,$result ? 1 : 0;
|
||||
syswrite STDOUT,$out;
|
||||
|
||||
@@ -70,7 +70,7 @@ done
|
||||
echo '7. compile ejabberd'
|
||||
|
||||
gmake
|
||||
for A in mod_irc mod_muc mod_pubsub; do
|
||||
for A in mod_muc mod_pubsub; do
|
||||
(cd $A; gmake)
|
||||
done
|
||||
|
||||
|
||||
@@ -1,15 +1,11 @@
|
||||
# $Id$
|
||||
|
||||
CC = @CC@
|
||||
CFLAGS = @CFLAGS@
|
||||
CPPFLAGS = @CPPFLAGS@
|
||||
LDFLAGS = @LDFLAGS@
|
||||
LIBS = @LIBS@
|
||||
|
||||
EXPAT_CFLAGS = @EXPAT_CFLAGS@
|
||||
ERLANG_CFLAGS= @ERLANG_CFLAGS@
|
||||
|
||||
EXPAT_LIBS = @EXPAT_LIBS@
|
||||
ERLANG_LIBS = @ERLANG_LIBS@
|
||||
|
||||
ASN_FLAGS = -bber_bin +der +compact_bit_string +optimize +noobj
|
||||
@@ -30,15 +26,14 @@ else
|
||||
INIT_USER=$(INSTALLUSER)
|
||||
endif
|
||||
|
||||
EFLAGS += @ERLANG_SSLVER@ -pa .
|
||||
ERLANG_CFLAGS += @ERLANG_SSLVER@
|
||||
EFLAGS += -pa .
|
||||
|
||||
# make debug=true to compile Erlang module with debug informations.
|
||||
ifdef debug
|
||||
EFLAGS+=+debug_info +export_all
|
||||
endif
|
||||
|
||||
DEBUGTOOLS = p1_prof.erl
|
||||
DEBUGTOOLS = p1_prof.erl etop_tr.erl
|
||||
ifdef debugtools
|
||||
SOURCES+=$(DEBUGTOOLS)
|
||||
endif
|
||||
@@ -55,20 +50,10 @@ ifeq (@full_xml@, true)
|
||||
EFLAGS+=-DFULL_XML_SUPPORT
|
||||
endif
|
||||
|
||||
ifeq (@nif@, true)
|
||||
EFLAGS+=-DNIF
|
||||
ERLSHLIBS=xml.so
|
||||
endif
|
||||
|
||||
ifeq (@transient_supervisors@, false)
|
||||
EFLAGS+=-DNO_TRANSIENT_SUPERVISORS
|
||||
endif
|
||||
|
||||
ifeq (@md2@, true)
|
||||
EFLAGS+=-DHAVE_MD2
|
||||
ERLANG_CFLAGS += -DHAVE_MD2
|
||||
endif
|
||||
|
||||
INSTALL_EPAM=
|
||||
ifeq (@pam@, pam)
|
||||
INSTALL_EPAM=install -m 750 $(O_USER) epam $(PBINDIR)
|
||||
@@ -77,8 +62,8 @@ endif
|
||||
prefix = @prefix@
|
||||
exec_prefix = @exec_prefix@
|
||||
|
||||
SUBDIRS = @mod_irc@ @mod_pubsub@ @mod_muc@ @mod_proxy65@ @eldap@ @pam@ @web@ stringprep stun @tls@ @odbc@ @ejabberd_zlib@
|
||||
ERLSHLIBS += expat_erl.so
|
||||
SUBDIRS = stun @mod_pubsub@ @mod_muc@ @mod_proxy65@ @eldap@ @pam@ @web@ @tls@ @odbc@ @ejabberd_zlib@
|
||||
ERLSHLIBS =
|
||||
ERLBEHAVS = cyrsasl.erl gen_mod.erl p1_fsm.erl
|
||||
SOURCES_ALL = $(wildcard *.erl)
|
||||
SOURCES_MISC = $(ERLBEHAVS) $(DEBUGTOOLS)
|
||||
@@ -154,7 +139,7 @@ all-recursive: $(ERLBEHAVBEAMS)
|
||||
|
||||
|
||||
all-recursive install-recursive uninstall-recursive \
|
||||
clean-recursive distclean-recursive \
|
||||
clean-recursive distclean-recursive devdoc-recursive \
|
||||
mostlyclean-recursive maintainer-clean-recursive:
|
||||
@subdirs="$(SUBDIRS)"; for subdir in $$subdirs; do \
|
||||
target=`echo $@|sed 's,-recursive,,'`; \
|
||||
@@ -170,8 +155,6 @@ mostlyclean-recursive maintainer-clean-recursive:
|
||||
$(ERLSHLIBS): %.so: %.c
|
||||
$(CC) $(CFLAGS) $(LDFLAGS) $(LIBS) \
|
||||
$(subst ../,,$(subst .so,.c,$@)) \
|
||||
$(EXPAT_LIBS) \
|
||||
$(EXPAT_CFLAGS) \
|
||||
$(ERLANG_LIBS) \
|
||||
$(ERLANG_CFLAGS) \
|
||||
-o $@ \
|
||||
@@ -294,7 +277,7 @@ uninstall-all: uninstall-binary
|
||||
rm -rf $(CTLLOCKDIR)
|
||||
rm -rf $(LOGDIR)
|
||||
|
||||
clean: clean-recursive clean-local
|
||||
clean: clean-recursive clean-local clean-devdoc
|
||||
|
||||
clean-local:
|
||||
rm -f *.beam $(ERLSHLIBS) epam ejabberdctl.example
|
||||
@@ -304,7 +287,6 @@ distclean: distclean-recursive clean-local
|
||||
rm -f config.status
|
||||
rm -f config.log
|
||||
rm -f Makefile
|
||||
[ ! -f ../ChangeLog ] || rm -f ../ChangeLog
|
||||
|
||||
TAGS:
|
||||
etags *.erl
|
||||
@@ -313,3 +295,90 @@ Makefile: Makefile.in
|
||||
|
||||
dialyzer: $(BEAMS)
|
||||
@dialyzer -c .
|
||||
|
||||
## Devdoc definitions
|
||||
SRCDIR=.
|
||||
DDTDIR=.
|
||||
DEVDOCDIR=../doc/devdoc
|
||||
DEVDOC_ERLS = $(wildcard ../doc/devdoc/*.erl)
|
||||
DEVDOC_BEAMS = $(DEVDOC_ERLS:.erl=.beam)
|
||||
APPNAME = ejabberd
|
||||
VSN = $(shell sed '/vsn/!d;s/\(.*\)"\(.*\)"\(.*\)/\2/' ./ejabberd.app)
|
||||
.PHONY = all
|
||||
HTMLS = $(SOURCES:%.erl=../doc/devdoc/%.html)
|
||||
ERLHTMLS = $(SOURCES:%.erl=../doc/devdoc/%.erl.html)
|
||||
SVGS = $(SOURCES:%.erl=../doc/devdoc/%.svg)
|
||||
EDOCINDEX = $(DEVDOCDIR)/index.html
|
||||
|
||||
## Devdoc rules
|
||||
devdoc: compile-devdoc devdoc-root devdoc-recursive
|
||||
$(devdoc-customize)
|
||||
$(devdoc-move)
|
||||
devdoc-root: $(EDOCINDEX) $(HTMLS) $(ERLHTMLS) $(SVGS)
|
||||
|
||||
define devdoc-customize
|
||||
find $(DDTDIR) -type f -name '*.erl.html' -exec sed -i 's/<span class="attribute" >module<\/span>(\([A-Za-z0-9_]*\))/<span class="attribute" >module<\/span>(<a href="\1.html">\1<\/a>)/g;' {} \;
|
||||
find $(DDTDIR) -type f -name '*.erl.html' -exec sed -i 's/arity="\([0-9]*\)" >\([A-Za-z0-9_]*\)</><a class="function" id="\2-\1" href="EDOCFILENAME#\2-\1">\2<\/a></g;' {} \;
|
||||
find $(DDTDIR) -type f -name '*.erl.html' -exec sed -i 's/class="export" >\([A-Za-z0-9_]*\)\/\([0-9]*\)</class="export" ><a href="#\1-\2">\1\/\2<\/a></g;' {} \;
|
||||
for fn in *.erl.html; do \
|
||||
sed -i 's/EDOCFILENAME/'$${fn%.erl.html}.html'/g;' $${fn} ; \
|
||||
sed = $${fn} | sed 'N;s/\n/ /;s/^\([0-9_]*\)/<a href="#\1" name="\1" class="l">\1<\/a>/' >$${fn}.tmp ; \
|
||||
mv $${fn}.tmp $${fn} ; \
|
||||
sed -i 's/<a href="#1" name="1" class="l">1<\/a> <html><link rel="stylesheet" type="text\/css"href="escobar.css"><\/link><body><pre><span class="comment" >/<html><link rel="stylesheet" type="text\/css" href="escobar.css"><\/link><body><pre><span class="comment" ><a href="#1" name="1" class="l">1<\/a> /g;' $${fn} ; \
|
||||
done
|
||||
-mv *.erl.html $(DEVDOCDIR)
|
||||
|
||||
find $(DDTDIR) -type f -name '*.html' -exec sed -i 's/<a href="overview-summary.html" target="overviewFrame">/<a href="index.html" target="_parent">/g;' {} \;
|
||||
find $(DDTDIR) -type f -name '*.html' -exec sed -i 's/align=\"right\" border=\"0\" alt=\"erlang logo\"/alt=\"erlang logo\"><\/a><a href=\"http:\/\/www.ejabberd.im\/\"><img src=\"ejabberd-im.png\" alt=\"ejabberd Community\"><\/a><a href=\"http:\/\/www.process-one.net\/en\/ejabberd\/\"><img src=\"ejabberd-p1.png\" alt=\"ejabberd home\"><\/a><a href=\"http:\/\/www.process-one.net\/\"><img src=\"process-one.png\" alt=\"ProcessOne\"/g;' {} \;
|
||||
find $(DDTDIR) -type f -name '*.html' -exec sed -i 's/^<h1>Module \([A-Za-z0-9_]*\)<\/h1>/<h1>Module \1 [<a href="\1.erl.html">erl<\/a> <a href="\1.svg">svg<\/a>]<\/h1>/g;' {} \;
|
||||
find $(DDTDIR) -type f -name '*.html' -exec sed -i 's/class="function"><a name="\([A-Za-z0-9_]*\)-\([0-9_]*\)">/class="function"><a name="\1-\2" href="ESCOFILENAME#\1-\2">/g;' {} \;
|
||||
-for fn in *.html; do sed -i 's/ESCOFILENAME/'$${fn%.html}.erl.html'/g;' $${fn} ; done
|
||||
|
||||
find $(DDTDIR) -type f -name '*.svg' -exec sed -i 's/xlink:href="EXP\([A-Za-z0-9_]*\).html#\([A-Za-z0-9_]*\)\/\([0-9_]*\)"/xlink:href="\1.html#\2-\3"/g;' {} \;
|
||||
find $(DDTDIR) -type f -name '*.svg' -exec sed -i 's/xlink:href="PRI\([A-Za-z0-9_]*\).html#\([A-Za-z0-9_]*\)\/\([0-9_]*\)"/xlink:href="\1.html#\2-\3"/g;' {} \;
|
||||
find $(DDTDIR) -type f -name '*.svg' -exec sed -i 's/xlink:href="APP\([A-Za-z0-9_]*\):\([A-Za-z0-9_]*\)\/\([0-9_]*\)"/xlink:href="\1.html#\2-\3"/g;' {} \;
|
||||
find $(DDTDIR) -type f -name '*.svg' -exec sed -i 's/xlink:href="EXM\([A-Za-z0-9_]*\):\([A-Za-z0-9_]*\)\/\([0-9_]*\)"/xlink:href="http:\/\/www.process-one.net\/docs\/exmpp\/devdoc\/trunk\/\1.html#\2-\3"/g;' {} \;
|
||||
find $(DDTDIR) -type f -name '*.svg' -exec sed -i 's/xlink:href="OTP\([A-Za-z0-9_]*\):\([A-Za-z0-9_]*\)\/\([0-9_]*\)"/xlink:href="http:\/\/www.erlang.org\/doc\/man\/\1.html#\2-\3"/g;' {} \;
|
||||
find $(DDTDIR) -type f -name '*.svg' -exec sed -i 's/xlink:href="OTP\([A-Za-z0-9_]*\)\/\([0-9_]*\)"/xlink:href="http:\/\/www.erlang.org\/doc\/man\/erlang.html#\1-\2"/g;' {} \;
|
||||
endef
|
||||
|
||||
define devdoc-move
|
||||
-rm *.dot
|
||||
-mv *.html $(DEVDOCDIR)
|
||||
-mv *.svg $(DEVDOCDIR)
|
||||
endef
|
||||
|
||||
compile-devdoc: $(DEVDOC_BEAMS)
|
||||
[ ! -f funrelg.beam ] || mv funrelg.beam $(DEVDOCDIR)
|
||||
[ ! -f escobar_hilite.beam ] || mv escobar_hilite.beam $(DEVDOCDIR)
|
||||
[ ! -f escobar_run.beam ] || mv escobar_run.beam $(DEVDOCDIR)
|
||||
|
||||
$(EDOCINDEX):
|
||||
@ERL@ -noshell -run edoc_run application "'$(APPNAME)'" '"$(SRCDIR)"' \
|
||||
'[{dir,"$(DDTDIR)"},{packages,false},{todo,true},{private,true},{def,{vsn,"$(VSN)"}},{stylesheet,"process-one.css"},{overview,"overview.edoc"}]' -s init stop
|
||||
sed -i 's/<title>The ejabberd application<\/title>/<title>ejabberd devdoc<\/title><link rel="shortcut icon" href="favicon.ico" type="image\/x-icon"\/>/g;' $(DDTDIR)/index.html
|
||||
mv edoc-info $(DEVDOCDIR)
|
||||
mv *.png $(DEVDOCDIR)
|
||||
cp *.html $(DEVDOCDIR)
|
||||
@ERL@ -noshell -pa $(DEVDOCDIR) -run escobar_run dir $(SRCDIR) $(SRCDIR) -s init stop
|
||||
@ERL@ -noshell -pa $(DEVDOCDIR) -run funrelg dir $(SRCDIR) $(SRCDIR) -s init stop
|
||||
$(devdoc-customize)
|
||||
$(devdoc-move)
|
||||
|
||||
$(DEVDOCDIR)/%.erl.html: %.erl
|
||||
@ERL@ -noshell -pa $(DEVDOCDIR) -run escobar_run file $< $(SRCDIR) -s init stop
|
||||
|
||||
$(DEVDOCDIR)/%.html: %.erl
|
||||
@ERL@ -noshell -run edoc_run file $< \
|
||||
'[{dir,"$(DDTDIR)"},{packages,false},{todo,true},{private,true},{def,{vsn,"$(VSN)"}},{stylesheet,"process-one.css"},{overview,"overview.edoc"}]' -s init stop
|
||||
|
||||
$(DEVDOCDIR)/%.svg: %.erl
|
||||
@ERL@ -noshell -pa $(DEVDOCDIR) -run funrelg file $< $(SRCDIR) -s init stop
|
||||
|
||||
clean-devdoc:
|
||||
rm -f $(DEVDOCDIR)/edoc-info
|
||||
rm -f $(DEVDOCDIR)/erlang.png
|
||||
rm -f $(DEVDOCDIR)/*.beam
|
||||
rm -f $(DEVDOCDIR)/*.dot
|
||||
rm -f $(DEVDOCDIR)/*.html
|
||||
rm -f $(DEVDOCDIR)/*.svg
|
||||
|
||||
@@ -52,9 +52,6 @@ release : build release_clean
|
||||
mkdir $(SRC_DIR)\eldap
|
||||
copy eldap\eldap.* $(SRC_DIR)\eldap
|
||||
copy eldap\ELDAPv3.asn $(SRC_DIR)\eldap
|
||||
mkdir $(SRC_DIR)\mod_irc
|
||||
copy mod_irc\*.erl $(SRC_DIR)\mod_irc
|
||||
copy mod_irc\*.c $(SRC_DIR)\mod_irc
|
||||
mkdir $(SRC_DIR)\mod_muc
|
||||
copy mod_muc\*.erl $(SRC_DIR)\mod_muc
|
||||
mkdir $(SRC_DIR)\mod_pubsub
|
||||
@@ -85,17 +82,15 @@ release : build release_clean
|
||||
copy ..\doc\*.html $(DOC_DIR)
|
||||
copy ..\doc\*.png $(DOC_DIR)
|
||||
|
||||
SOURCE = expat_erl.c
|
||||
OBJECT = expat_erl.o
|
||||
DLL = expat_erl.dll
|
||||
SOURCE =
|
||||
OBJECT =
|
||||
DLL =
|
||||
|
||||
build : $(DLL) compile-beam all-recursive
|
||||
|
||||
all-recursive :
|
||||
cd eldap
|
||||
nmake -nologo -f Makefile.win32
|
||||
cd ..\mod_irc
|
||||
nmake -nologo -f Makefile.win32
|
||||
cd ..\mod_muc
|
||||
nmake -nologo -f Makefile.win32
|
||||
cd ..\mod_pubsub
|
||||
@@ -127,8 +122,6 @@ CLEAN : clean-recursive clean-local
|
||||
clean-local :
|
||||
-@erase $(OBJECT)
|
||||
-@erase $(DLL)
|
||||
-@erase expat_erl.exp
|
||||
-@erase expat_erl.lib
|
||||
-@erase *.beam
|
||||
-@erase XmppAddr.asn1db
|
||||
-@erase XmppAddr.erl
|
||||
@@ -137,8 +130,6 @@ clean-local :
|
||||
clean-recursive :
|
||||
cd eldap
|
||||
nmake -nologo -f Makefile.win32 clean
|
||||
cd ..\mod_irc
|
||||
nmake -nologo -f Makefile.win32 clean
|
||||
cd ..\mod_muc
|
||||
nmake -nologo -f Makefile.win32 clean
|
||||
cd ..\mod_pubsub
|
||||
@@ -164,10 +155,10 @@ distclean : release_clean clean
|
||||
-@erase Makefile.inc
|
||||
|
||||
CC=cl.exe
|
||||
CC_FLAGS=-nologo -D__WIN32__ -DWIN32 -DWINDOWS -D_WIN32 -DNT $(EXPAT_FLAG) -MD -Ox -I"$(ERLANG_DIR)\usr\include" -I"$(EI_DIR)\include" -I"$(EXPAT_DIR)\source\lib"
|
||||
CC_FLAGS=-nologo -D__WIN32__ -DWIN32 -DWINDOWS -D_WIN32 -DNT -MD -Ox -I"$(ERLANG_DIR)\usr\include" -I"$(EI_DIR)\include"
|
||||
|
||||
LD=link.exe
|
||||
LD_FLAGS=-release -nologo -incremental:no -dll "$(EI_DIR)\lib\ei_md.lib" "$(EI_DIR)\lib\erl_interface_md.lib" "$(EXPAT_LIB)" MSVCRT.LIB kernel32.lib advapi32.lib gdi32.lib user32.lib comctl32.lib comdlg32.lib shell32.lib
|
||||
LD_FLAGS=-release -nologo -incremental:no -dll "$(EI_DIR)\lib\ei_md.lib" "$(EI_DIR)\lib\erl_interface_md.lib" MSVCRT.LIB kernel32.lib advapi32.lib gdi32.lib user32.lib comctl32.lib comdlg32.lib shell32.lib
|
||||
|
||||
$(DLL) : $(OBJECT)
|
||||
$(LD) $(LD_FLAGS) -out:$(DLL) $(OBJECT)
|
||||
|
||||
@@ -32,13 +32,45 @@
|
||||
add/3,
|
||||
add_list/3,
|
||||
match_rule/3,
|
||||
for_host/1,
|
||||
% for debugging only
|
||||
match_acl/3]).
|
||||
|
||||
-include("ejabberd.hrl").
|
||||
-include_lib("stdlib/include/ms_transform.hrl").
|
||||
|
||||
%% @type aclspec() = all | JID_Exact | JID_Regexp | JID_Glob | Shared_Group
|
||||
%% JID_Exact = {user, U} | {user, U, S} | {server, S} | {resource, R}
|
||||
%% U = string()
|
||||
%% S = string()
|
||||
%% R = string()
|
||||
%% JID_Regexp = {user_regexp, UR} | {user_regexp, UR, S} | {server_regexp, SR} | {resource_regexp, RR} | {node_regexp, UR, SR}
|
||||
%% UR = string()
|
||||
%% SR = string()
|
||||
%% RR = string()
|
||||
%% JID_Glob = {user_glob, UG} | {user_glob, UG, S} | {server_glob, SG} | {resource_glob, RG} | {node_glob, UG, SG}
|
||||
%% UG = string()
|
||||
%% SG = string()
|
||||
%% RG = string()
|
||||
%% Shared_Group = {shared_group, G} | {shared_group, G, H}
|
||||
%% G = string()
|
||||
%% H = string().
|
||||
|
||||
%% @type acl() = {acl, ACLName, ACLSpec}
|
||||
%% ACLName = atom()
|
||||
%% ACLSpec = aclspec().
|
||||
%% Record in its Ejabberd-configuration-file variant.
|
||||
|
||||
%% @type storedacl() = {acl, {ACLName, Host}, ACLSpec}
|
||||
%% ACLName = atom()
|
||||
%% Host = global | string()
|
||||
%% ACLSpec = aclspec().
|
||||
%% Record in its Mnesia-table-record variant.
|
||||
|
||||
-record(acl, {aclname, aclspec}).
|
||||
|
||||
%% @spec () -> ok
|
||||
|
||||
start() ->
|
||||
mnesia:create_table(acl,
|
||||
[{disc_copies, [node()]},
|
||||
@@ -47,9 +79,20 @@ start() ->
|
||||
mnesia:add_table_copy(acl, node(), ram_copies),
|
||||
ok.
|
||||
|
||||
%% @spec (Host, ACLName, ACLSpec) -> storedacl()
|
||||
%% Host = global | string()
|
||||
%% ACLName = atom()
|
||||
%% ACLSpec = aclspec()
|
||||
|
||||
to_record(Host, ACLName, ACLSpec) ->
|
||||
#acl{aclname = {ACLName, Host}, aclspec = normalize_spec(ACLSpec)}.
|
||||
|
||||
%% @spec (Host, ACLName, ACLSpec) -> {atomic, ok} | {aborted, Reason}
|
||||
%% Host = global | string()
|
||||
%% ACLName = atom()
|
||||
%% ACLSpec = all | none | aclspec()
|
||||
%% Reason = term()
|
||||
|
||||
add(Host, ACLName, ACLSpec) ->
|
||||
F = fun() ->
|
||||
mnesia:write(#acl{aclname = {ACLName, Host},
|
||||
@@ -57,6 +100,11 @@ add(Host, ACLName, ACLSpec) ->
|
||||
end,
|
||||
mnesia:transaction(F).
|
||||
|
||||
%% @spec (Host, ACLs, Clear) -> ok | false
|
||||
%% Host = global | string()
|
||||
%% ACLs = [acl()]
|
||||
%% Clear = bool()
|
||||
|
||||
add_list(Host, ACLs, Clear) ->
|
||||
F = fun() ->
|
||||
if
|
||||
@@ -86,8 +134,17 @@ add_list(Host, ACLs, Clear) ->
|
||||
false
|
||||
end.
|
||||
|
||||
normalize(A) ->
|
||||
jlib:nodeprep(A).
|
||||
%% @spec (String) -> Prepd_String
|
||||
%% String = string()
|
||||
%% Prepd_String = string()
|
||||
|
||||
normalize(String) ->
|
||||
exmpp_stringprep:nodeprep(String).
|
||||
|
||||
%% @spec (ACLSpec) -> Normalized_ACLSpec
|
||||
%% ACLSpec = all | none | aclspec()
|
||||
%% Normalized_ACLSpec = aclspec()
|
||||
|
||||
normalize_spec({A, B}) ->
|
||||
{A, normalize(B)};
|
||||
normalize_spec({A, B, C}) ->
|
||||
@@ -99,6 +156,12 @@ normalize_spec(none) ->
|
||||
|
||||
|
||||
|
||||
%% @spec (Host, Rule, JID) -> Access
|
||||
%% Host = global | string()
|
||||
%% Rule = all | none | atom()
|
||||
%% JID = exmpp_jid:jid()
|
||||
%% Access = allow | deny | atom()
|
||||
|
||||
match_rule(global, Rule, JID) ->
|
||||
case Rule of
|
||||
all -> allow;
|
||||
@@ -143,23 +206,37 @@ match_rule(Host, Rule, JID) ->
|
||||
end
|
||||
end.
|
||||
|
||||
%% @spec (ACLs, JID, Host) -> Access
|
||||
%% ACLs = [{Access, ACLName}]
|
||||
%% Access = deny | atom()
|
||||
%% ACLName = atom()
|
||||
%% JID = exmpp_jid:jid()
|
||||
%% Host = string()
|
||||
|
||||
match_acls([], _, _Host) ->
|
||||
deny;
|
||||
match_acls([{Access, ACL} | ACLs], JID, Host) ->
|
||||
case match_acl(ACL, JID, Host) of
|
||||
match_acls([{Access, ACLName} | ACLs], JID, Host) ->
|
||||
case match_acl(ACLName, JID, Host) of
|
||||
true ->
|
||||
Access;
|
||||
_ ->
|
||||
match_acls(ACLs, JID, Host)
|
||||
end.
|
||||
|
||||
match_acl(ACL, JID, Host) ->
|
||||
case ACL of
|
||||
%% @spec (ACLName, JID, Host) -> bool()
|
||||
%% ACLName = all | none | atom()
|
||||
%% JID = exmpp_jid:jid()
|
||||
%% Host = string()
|
||||
|
||||
match_acl(ACLName, JID, Host) ->
|
||||
case ACLName of
|
||||
all -> true;
|
||||
none -> false;
|
||||
_ ->
|
||||
{User, Server, Resource} = jlib:jid_tolower(JID),
|
||||
lists:any(fun(#acl{aclspec = Spec}) ->
|
||||
User = exmpp_jid:prep_node_as_list(JID),
|
||||
Server = exmpp_jid:prep_domain_as_list(JID),
|
||||
Resource = exmpp_jid:prep_resource_as_list(JID),
|
||||
lists:any(fun(#acl{aclname=Name, aclspec = Spec}) ->
|
||||
case Spec of
|
||||
all ->
|
||||
true;
|
||||
@@ -168,17 +245,21 @@ match_acl(ACL, JID, Host) ->
|
||||
andalso
|
||||
((Host == Server) orelse
|
||||
((Host == global) andalso
|
||||
lists:member(Server, ?MYHOSTS)));
|
||||
?IS_MY_HOST(Server)));
|
||||
{user, U, S} ->
|
||||
(U == User) andalso (S == Server);
|
||||
{server, S} ->
|
||||
S == Server;
|
||||
{resource, R} ->
|
||||
R == Resource;
|
||||
{user_regexp, UR} when is_tuple(Name),
|
||||
element(2, Name) =:= global ->
|
||||
?IS_MY_HOST(Server)
|
||||
andalso is_regexp_match(User, UR);
|
||||
{user_regexp, UR} ->
|
||||
((Host == Server) orelse
|
||||
((Host == global) andalso
|
||||
lists:member(Server, ?MYHOSTS)))
|
||||
?IS_MY_HOST(Server)))
|
||||
andalso is_regexp_match(User, UR);
|
||||
{shared_group, G} ->
|
||||
mod_shared_roster:is_user_in_group({User, Server}, G, Host);
|
||||
@@ -197,7 +278,7 @@ match_acl(ACL, JID, Host) ->
|
||||
{user_glob, UR} ->
|
||||
((Host == Server) orelse
|
||||
((Host == global) andalso
|
||||
lists:member(Server, ?MYHOSTS)))
|
||||
?IS_MY_HOST(Server)))
|
||||
andalso
|
||||
is_glob_match(User, UR);
|
||||
{user_glob, UR, S} ->
|
||||
@@ -218,24 +299,41 @@ match_acl(ACL, JID, Host) ->
|
||||
false
|
||||
end
|
||||
end,
|
||||
ets:lookup(acl, {ACL, global}) ++
|
||||
ets:lookup(acl, {ACL, Host}))
|
||||
ets:lookup(acl, {ACLName, global}) ++
|
||||
ets:lookup(acl, {ACLName, Host}))
|
||||
end.
|
||||
|
||||
%% @spec (String, RegExp) -> bool()
|
||||
%% String = string() | undefined
|
||||
%% RegExp = string()
|
||||
|
||||
is_regexp_match(undefined, _RegExp) ->
|
||||
false;
|
||||
is_regexp_match(String, RegExp) ->
|
||||
case regexp:first_match(String, RegExp) of
|
||||
try re:run(String, RegExp, [{capture, none}]) of
|
||||
nomatch ->
|
||||
false;
|
||||
{match, _, _} ->
|
||||
true;
|
||||
{error, ErrDesc} ->
|
||||
match ->
|
||||
true
|
||||
catch
|
||||
_:ErrDesc ->
|
||||
?ERROR_MSG(
|
||||
"Wrong regexp ~p in ACL: ~p",
|
||||
[RegExp, lists:flatten(regexp:format_error(ErrDesc))]),
|
||||
"Wrong regexp ~p in ACL:~n~p",
|
||||
[RegExp, ErrDesc]),
|
||||
false
|
||||
end.
|
||||
|
||||
%% @spec (String, Glob) -> bool()
|
||||
%% String = string() | undefined
|
||||
%% Glob = string()
|
||||
|
||||
is_glob_match(String, Glob) ->
|
||||
is_regexp_match(String, regexp:sh_to_awk(Glob)).
|
||||
is_regexp_match(String, xmerl_regexp:sh_to_awk(Glob)).
|
||||
|
||||
|
||||
for_host(Host) ->
|
||||
mnesia:select(acl,
|
||||
ets:fun2ms(fun (#acl{aclname = {_ACLName, H}})
|
||||
when H =:= Host ->
|
||||
object()
|
||||
end)).
|
||||
|
||||
@@ -1,38 +1,4 @@
|
||||
AC_DEFUN([AM_WITH_EXPAT],
|
||||
[ AC_ARG_WITH(expat,
|
||||
[AC_HELP_STRING([--with-expat=PREFIX], [prefix where EXPAT is installed])])
|
||||
|
||||
EXPAT_CFLAGS=
|
||||
EXPAT_LIBS=
|
||||
if test x"$with_expat" != x; then
|
||||
EXPAT_CFLAGS="-I$with_expat/include"
|
||||
EXPAT_LIBS="-L$with_expat/lib"
|
||||
fi
|
||||
|
||||
AC_CHECK_LIB(expat, XML_ParserCreate,
|
||||
[ EXPAT_LIBS="$EXPAT_LIBS -lexpat"
|
||||
expat_found=yes ],
|
||||
[ expat_found=no ],
|
||||
"$EXPAT_LIBS")
|
||||
if test $expat_found = no; then
|
||||
AC_MSG_ERROR([Could not find development files of Expat library])
|
||||
fi
|
||||
expat_save_CFLAGS="$CFLAGS"
|
||||
CFLAGS="$CFLAGS $EXPAT_CFLAGS"
|
||||
expat_save_CPPFLAGS="$CPPFLAGS"
|
||||
CPPFLAGS="$CPPFLAGS $EXPAT_CFLAGS"
|
||||
AC_CHECK_HEADERS(expat.h, , expat_found=no)
|
||||
if test $expat_found = no; then
|
||||
AC_MSG_ERROR([Could not find expat.h])
|
||||
fi
|
||||
CFLAGS="$expat_save_CFLAGS"
|
||||
CPPFLAGS="$expat_save_CPPFLAGS"
|
||||
|
||||
AC_SUBST(EXPAT_CFLAGS)
|
||||
AC_SUBST(EXPAT_LIBS)
|
||||
])
|
||||
|
||||
AC_DEFUN([AM_WITH_ZLIB],
|
||||
AC_DEFUN(AM_WITH_ZLIB,
|
||||
[ AC_ARG_WITH(zlib,
|
||||
[AC_HELP_STRING([--with-zlib=PREFIX], [prefix where zlib is installed])])
|
||||
|
||||
@@ -68,7 +34,7 @@ if test x"$ejabberd_zlib" != x; then
|
||||
fi
|
||||
])
|
||||
|
||||
AC_DEFUN([AM_WITH_PAM],
|
||||
AC_DEFUN(AM_WITH_PAM,
|
||||
[ AC_ARG_WITH(pam,
|
||||
[AC_HELP_STRING([--with-pam=PREFIX], [prefix where PAM is installed])])
|
||||
if test x"$pam" != x; then
|
||||
@@ -103,7 +69,7 @@ if test x"$pam" != x; then
|
||||
fi
|
||||
])
|
||||
|
||||
AC_DEFUN([AM_WITH_ERLANG],
|
||||
AC_DEFUN(AM_WITH_ERLANG,
|
||||
[ AC_ARG_WITH(erlang,
|
||||
[AC_HELP_STRING([--with-erlang=PREFIX], [path to erlc and erl])])
|
||||
|
||||
@@ -125,18 +91,16 @@ AC_DEFUN([AM_WITH_ERLANG],
|
||||
start() ->
|
||||
EIDirS = code:lib_dir("erl_interface") ++ "\n",
|
||||
EILibS = libpath("erl_interface") ++ "\n",
|
||||
EXMPPDir = code:lib_dir("exmpp"),
|
||||
case EXMPPDir of
|
||||
{error, bad_name} -> exit("exmpp not found");
|
||||
_ -> ok
|
||||
end,
|
||||
EXMPPDirS = EXMPPDir ++ "\n",
|
||||
RootDirS = code:root_dir() ++ "\n",
|
||||
file:write_file("conftest.out", list_to_binary(EIDirS ++ EILibS ++ ssldef() ++ RootDirS)),
|
||||
file:write_file("conftest.out", list_to_binary(EIDirS ++ EILibS ++ EXMPPDirS ++ RootDirS)),
|
||||
halt().
|
||||
|
||||
ssldef() ->
|
||||
OTP = (catch erlang:system_info(otp_release)),
|
||||
if
|
||||
OTP >= "R14" -> "-DSSL40\n";
|
||||
OTP >= "R12" -> "-DSSL39\n";
|
||||
true -> "\n"
|
||||
end.
|
||||
|
||||
%% return physical architecture based on OS/Processor
|
||||
archname() ->
|
||||
ArchStr = erlang:system_info(system_architecture),
|
||||
@@ -185,7 +149,7 @@ _EOF
|
||||
# Second line
|
||||
ERLANG_EI_LIB=`cat conftest.out | head -n 2 | tail -n 1`
|
||||
# Third line
|
||||
ERLANG_SSLVER=`cat conftest.out | head -n 3 | tail -n 1`
|
||||
ERLANG_EXMPP=`cat conftest.out | head -n 3 | tail -n 1`
|
||||
# End line
|
||||
ERLANG_DIR=`cat conftest.out | tail -n 1`
|
||||
|
||||
@@ -194,12 +158,12 @@ _EOF
|
||||
|
||||
AC_SUBST(ERLANG_CFLAGS)
|
||||
AC_SUBST(ERLANG_LIBS)
|
||||
AC_SUBST(ERLANG_SSLVER)
|
||||
AC_SUBST(ERLANG_EXMPP)
|
||||
AC_SUBST(ERLC)
|
||||
AC_SUBST(ERL)
|
||||
])
|
||||
|
||||
AC_DEFUN([AC_MOD_ENABLE],
|
||||
AC_DEFUN(AC_MOD_ENABLE,
|
||||
[
|
||||
$1=
|
||||
make_$1=
|
||||
@@ -218,98 +182,8 @@ AC_SUBST(make_$1)
|
||||
|
||||
])
|
||||
|
||||
|
||||
dnl From Bruno Haible.
|
||||
|
||||
AC_DEFUN([AM_ICONV],
|
||||
[
|
||||
dnl Some systems have iconv in libc, some have it in libiconv (OSF/1 and
|
||||
dnl those with the standalone portable GNU libiconv installed).
|
||||
AC_ARG_WITH([libiconv-prefix],
|
||||
[AC_HELP_STRING([--with-libiconv-prefix=PREFIX], [prefix where libiconv is installed])], [
|
||||
for dir in `echo "$withval" | tr : ' '`; do
|
||||
if test -d $dir/include; then CPPFLAGS="$CPPFLAGS -I$dir/include"; fi
|
||||
if test -d $dir/include; then CFLAGS="$CFLAGS -I$dir/include"; fi
|
||||
if test -d $dir/lib; then LDFLAGS="$LDFLAGS -L$dir/lib"; fi
|
||||
done
|
||||
])
|
||||
|
||||
AC_CACHE_CHECK(for iconv, am_cv_func_iconv, [
|
||||
am_cv_func_iconv="no, consider installing GNU libiconv"
|
||||
am_cv_lib_iconv=no
|
||||
AC_TRY_LINK([#include <stdlib.h>
|
||||
#include <iconv.h>],
|
||||
[iconv_t cd = iconv_open("","");
|
||||
iconv(cd,NULL,NULL,NULL,NULL);
|
||||
iconv_close(cd);],
|
||||
am_cv_func_iconv=yes)
|
||||
if test "$am_cv_func_iconv" != yes; then
|
||||
am_save_LIBS="$LIBS"
|
||||
LIBS="$LIBS -liconv"
|
||||
AC_TRY_LINK([#include <stdlib.h>
|
||||
#include <iconv.h>],
|
||||
[iconv_t cd = iconv_open("","");
|
||||
iconv(cd,NULL,NULL,NULL,NULL);
|
||||
iconv_close(cd);],
|
||||
am_cv_lib_iconv=yes
|
||||
am_cv_func_iconv=yes)
|
||||
LIBS="$am_save_LIBS"
|
||||
fi
|
||||
dnl trying /usr/local
|
||||
if test "$am_cv_func_iconv" != yes; then
|
||||
am_save_LIBS="$LIBS"
|
||||
am_save_CFLAGS="$CFLAGS"
|
||||
am_save_LDFLAGS="$LDFLAGS"
|
||||
LIBS="$LIBS -liconv"
|
||||
LDFLAGS="$LDFLAGS -L/usr/local/lib"
|
||||
CFLAGS="$CFLAGS -I/usr/local/include"
|
||||
AC_TRY_LINK([#include <stdlib.h>
|
||||
#include <iconv.h>],
|
||||
[iconv_t cd = iconv_open("","");
|
||||
iconv(cd,NULL,NULL,NULL,NULL);
|
||||
iconv_close(cd);],
|
||||
am_cv_lib_iconv=yes
|
||||
am_cv_func_iconv=yes
|
||||
CPPFLAGS="$CPPFLAGS -I/usr/local/include",
|
||||
LDFLAGS="$am_save_LDFLAGS"
|
||||
CFLAGS="$am_save_CFLAGS")
|
||||
LIBS="$am_save_LIBS"
|
||||
fi
|
||||
|
||||
])
|
||||
if test "$am_cv_func_iconv" = yes; then
|
||||
AC_DEFINE(HAVE_ICONV, 1, [Define if you have the iconv() function.])
|
||||
AC_MSG_CHECKING([for iconv declaration])
|
||||
AC_CACHE_VAL(am_cv_proto_iconv, [
|
||||
AC_TRY_COMPILE([
|
||||
#include <stdlib.h>
|
||||
#include <iconv.h>
|
||||
extern
|
||||
#ifdef __cplusplus
|
||||
"C"
|
||||
#endif
|
||||
#if defined(__STDC__) || defined(__cplusplus)
|
||||
size_t iconv (iconv_t cd, char * *inbuf, size_t *inbytesleft, char * *outbuf, size_t *outbytesleft);
|
||||
#else
|
||||
size_t iconv();
|
||||
#endif
|
||||
], [], am_cv_proto_iconv_arg1="", am_cv_proto_iconv_arg1="const")
|
||||
am_cv_proto_iconv="extern size_t iconv (iconv_t cd, $am_cv_proto_iconv_arg1 char * *inbuf, size_t *inbytesleft, char * *outbuf, size_t *outbytesleft);"])
|
||||
am_cv_proto_iconv=`echo "[$]am_cv_proto_iconv" | tr -s ' ' | sed -e 's/( /(/'`
|
||||
AC_MSG_RESULT([$]{ac_t:-
|
||||
}[$]am_cv_proto_iconv)
|
||||
AC_DEFINE_UNQUOTED(ICONV_CONST, $am_cv_proto_iconv_arg1,
|
||||
[Define as const if the declaration of iconv() needs const.])
|
||||
fi
|
||||
LIBICONV=
|
||||
if test "$am_cv_lib_iconv" = yes; then
|
||||
LIBICONV="-liconv"
|
||||
fi
|
||||
AC_SUBST(LIBICONV)
|
||||
])
|
||||
|
||||
dnl <openssl>
|
||||
AC_DEFUN([AM_WITH_OPENSSL],
|
||||
AC_DEFUN(AM_WITH_OPENSSL,
|
||||
[ AC_ARG_WITH(openssl,
|
||||
[AC_HELP_STRING([--with-openssl=PREFIX], [prefix where OPENSSL is installed])])
|
||||
unset SSL_LIBS;
|
||||
@@ -31,48 +31,52 @@
|
||||
produce_response/2,
|
||||
produce_response/1]).
|
||||
|
||||
-include_lib("exmpp/include/exmpp.hrl").
|
||||
|
||||
-include("ejabberd.hrl").
|
||||
-include("jlib.hrl").
|
||||
-include("adhoc.hrl").
|
||||
|
||||
%% Parse an ad-hoc request. Return either an adhoc_request record or
|
||||
%% an {error, ErrorType} tuple.
|
||||
parse_request(#iq{type = set, lang = Lang, sub_el = SubEl, xmlns = ?NS_COMMANDS}) ->
|
||||
?DEBUG("entering parse_request...", []),
|
||||
Node = xml:get_tag_attr_s("node", SubEl),
|
||||
SessionID = xml:get_tag_attr_s("sessionid", SubEl),
|
||||
Action = xml:get_tag_attr_s("action", SubEl),
|
||||
XData = find_xdata_el(SubEl),
|
||||
{xmlelement, _, _, AllEls} = SubEl,
|
||||
Others = case XData of
|
||||
false ->
|
||||
AllEls;
|
||||
_ ->
|
||||
lists:delete(XData, AllEls)
|
||||
end,
|
||||
parse_request(#iq{type = Type, ns = NS, payload = SubEl, lang = Lang}) ->
|
||||
try
|
||||
case {Type, NS} of
|
||||
{set, ?NS_ADHOC} ->
|
||||
?DEBUG("entering parse_request...", []),
|
||||
Node = exmpp_xml:get_attribute_as_list(SubEl, 'node', ""),
|
||||
SessionID = exmpp_xml:get_attribute_as_list(SubEl, 'sessionid', ""),
|
||||
Action = exmpp_xml:get_attribute_as_list(SubEl, 'action', ""),
|
||||
XData = find_xdata_el(SubEl),
|
||||
AllEls = exmpp_xml:get_child_elements(SubEl),
|
||||
Others = case XData of
|
||||
false ->
|
||||
AllEls;
|
||||
_ ->
|
||||
lists:delete(XData, AllEls)
|
||||
end,
|
||||
|
||||
#adhoc_request{lang = Lang,
|
||||
node = Node,
|
||||
sessionid = SessionID,
|
||||
action = Action,
|
||||
xdata = XData,
|
||||
others = Others};
|
||||
parse_request(_) ->
|
||||
{error, ?ERR_BAD_REQUEST}.
|
||||
#adhoc_request{lang = Lang,
|
||||
node = Node,
|
||||
sessionid = SessionID,
|
||||
action = Action,
|
||||
xdata = XData,
|
||||
others = Others};
|
||||
_ ->
|
||||
{error, 'bad-request'}
|
||||
end
|
||||
catch
|
||||
_ ->
|
||||
{error, 'bad-request'}
|
||||
end.
|
||||
|
||||
%% Borrowed from mod_vcard.erl
|
||||
find_xdata_el({xmlelement, _Name, _Attrs, SubEls}) ->
|
||||
find_xdata_el(#xmlel{children = SubEls}) ->
|
||||
find_xdata_el1(SubEls).
|
||||
|
||||
find_xdata_el1([]) ->
|
||||
false;
|
||||
find_xdata_el1([{xmlelement, Name, Attrs, SubEls} | Els]) ->
|
||||
case xml:get_attr_s("xmlns", Attrs) of
|
||||
?NS_XDATA ->
|
||||
{xmlelement, Name, Attrs, SubEls};
|
||||
_ ->
|
||||
find_xdata_el1(Els)
|
||||
end;
|
||||
find_xdata_el1([#xmlel{ns = ?NS_DATA_FORMS} = El | _Els]) ->
|
||||
El;
|
||||
find_xdata_el1([_ | Els]) ->
|
||||
find_xdata_el1(Els).
|
||||
|
||||
@@ -110,20 +114,19 @@ produce_response(#adhoc_response{lang = _Lang,
|
||||
"" ->
|
||||
ActionsElAttrs = [];
|
||||
_ ->
|
||||
ActionsElAttrs = [{"execute", DefaultAction}]
|
||||
ActionsElAttrs = [?XMLATTR('execute', DefaultAction)]
|
||||
end,
|
||||
ActionsEls = [{xmlelement, "actions",
|
||||
ActionsElAttrs,
|
||||
[{xmlelement, Action, [], []} || Action <- Actions]}]
|
||||
ActionsEls = [#xmlel{ns = ?NS_ADHOC, name = 'actions', attrs =
|
||||
ActionsElAttrs, children =
|
||||
[#xmlel{ns = ?NS_ADHOC, name = Action} || Action <- Actions]}]
|
||||
end,
|
||||
NotesEls = lists:map(fun({Type, Text}) ->
|
||||
{xmlelement, "note",
|
||||
[{"type", Type}],
|
||||
[{xmlcdata, Text}]}
|
||||
#xmlel{ns = ?NS_ADHOC, name = 'note', attrs =
|
||||
[?XMLATTR('type', Type)],
|
||||
children = [#xmlcdata{cdata = list_to_binary(Text)}]}
|
||||
end, Notes),
|
||||
{xmlelement, "command",
|
||||
[{"xmlns", ?NS_COMMANDS},
|
||||
{"sessionid", SessionID},
|
||||
{"node", Node},
|
||||
{"status", atom_to_list(Status)}],
|
||||
#xmlel{ns = ?NS_ADHOC, name = 'command', attrs =
|
||||
[?XMLATTR('sessionid', SessionID),
|
||||
?XMLATTR('node', Node),
|
||||
?XMLATTR('status', Status)], children =
|
||||
ActionsEls ++ NotesEls ++ Elements}.
|
||||
|
||||
@@ -1,604 +0,0 @@
|
||||
%%%-------------------------------------------------------------------
|
||||
%%% File : cache_tab.erl
|
||||
%%% Author : Evgeniy Khramtsov <ekhramtsov@process-one.net>
|
||||
%%% Description : Caching key-value table
|
||||
%%%
|
||||
%%% Created : 29 Aug 2010 by Evgeniy Khramtsov <ekhramtsov@process-one.net>
|
||||
%%%
|
||||
%%%
|
||||
%%% ejabberd, Copyright (C) 2002-2010 ProcessOne
|
||||
%%%
|
||||
%%% This program is free software; you can redistribute it and/or
|
||||
%%% modify it under the terms of the GNU General Public License as
|
||||
%%% published by the Free Software Foundation; either version 2 of the
|
||||
%%% License, or (at your option) any later version.
|
||||
%%%
|
||||
%%% This program is distributed in the hope that it will be useful,
|
||||
%%% but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
%%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
%%% General Public License for more details.
|
||||
%%%
|
||||
%%% You should have received a copy of the GNU General Public License
|
||||
%%% along with this program; if not, write to the Free Software
|
||||
%%% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||
%%% 02111-1307 USA
|
||||
%%%
|
||||
%%%-------------------------------------------------------------------
|
||||
-module(cache_tab).
|
||||
|
||||
-define(GEN_SERVER, gen_server).
|
||||
|
||||
-behaviour(?GEN_SERVER).
|
||||
|
||||
%% API
|
||||
-export([start_link/4, new/2, delete/1, delete/3, lookup/3,
|
||||
insert/4, info/2, tab2list/1, setopts/2,
|
||||
dirty_lookup/3, dirty_insert/4, dirty_delete/3,
|
||||
all/0, test/0]).
|
||||
|
||||
%% gen_server callbacks
|
||||
-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
|
||||
terminate/2, code_change/3]).
|
||||
|
||||
-include("ejabberd.hrl").
|
||||
|
||||
-record(state, {tab = treap:empty(),
|
||||
name,
|
||||
size = 0,
|
||||
owner,
|
||||
max_size,
|
||||
life_time,
|
||||
warn,
|
||||
hits = 0,
|
||||
miss = 0,
|
||||
procs_num,
|
||||
cache_missed,
|
||||
lru,
|
||||
shrink_size}).
|
||||
|
||||
-define(PROCNAME, ?MODULE).
|
||||
-define(CALL_TIMEOUT, 60000).
|
||||
|
||||
%% Defaults
|
||||
-define(MAX_SIZE, 1000).
|
||||
-define(WARN, true).
|
||||
-define(CACHE_MISSED, true).
|
||||
-define(LRU, true).
|
||||
-define(LIFETIME, 600). %% 10 minutes
|
||||
|
||||
%%====================================================================
|
||||
%% API
|
||||
%%====================================================================
|
||||
start_link(Proc, Tab, Opts, Owner) ->
|
||||
?GEN_SERVER:start_link(
|
||||
{local, Proc}, ?MODULE, [Tab, Opts, get_proc_num(), Owner], []).
|
||||
|
||||
new(Tab, Opts) ->
|
||||
Res = lists:flatmap(
|
||||
fun(Proc) ->
|
||||
Spec = {{Tab, Proc},
|
||||
{?MODULE, start_link,
|
||||
[Proc, Tab, Opts, self()]},
|
||||
permanent,
|
||||
brutal_kill,
|
||||
worker,
|
||||
[?MODULE]},
|
||||
case supervisor:start_child(cache_tab_sup, Spec) of
|
||||
{ok, _Pid} ->
|
||||
[ok];
|
||||
R ->
|
||||
[R]
|
||||
end
|
||||
end, get_all_procs(Tab)),
|
||||
case lists:filter(fun(ok) -> false; (_) -> true end, Res) of
|
||||
[] ->
|
||||
ok;
|
||||
Err ->
|
||||
{error, Err}
|
||||
end.
|
||||
|
||||
delete(Tab) ->
|
||||
lists:foreach(
|
||||
fun(Proc) ->
|
||||
supervisor:terminate_child(cache_tab_sup, {Tab, Proc}),
|
||||
supervisor:delete_child(cache_tab_sup, {Tab, Proc})
|
||||
end, get_all_procs(Tab)).
|
||||
|
||||
delete(Tab, Key, F) ->
|
||||
?GEN_SERVER:call(
|
||||
get_proc_by_hash(Tab, Key), {delete, Key, F}, ?CALL_TIMEOUT).
|
||||
|
||||
dirty_delete(Tab, Key, F) ->
|
||||
F(),
|
||||
?GEN_SERVER:call(
|
||||
get_proc_by_hash(Tab, Key), {cache_delete, Key}, ?CALL_TIMEOUT).
|
||||
|
||||
lookup(Tab, Key, F) ->
|
||||
?GEN_SERVER:call(
|
||||
get_proc_by_hash(Tab, Key), {lookup, Key, F}, ?CALL_TIMEOUT).
|
||||
|
||||
dirty_lookup(Tab, Key, F) ->
|
||||
Proc = get_proc_by_hash(Tab, Key),
|
||||
case ?GEN_SERVER:call(Proc, {cache_lookup, Key}, ?CALL_TIMEOUT) of
|
||||
{ok, '$cached_mismatch'} ->
|
||||
error;
|
||||
{ok, Val} ->
|
||||
{ok, Val};
|
||||
_ ->
|
||||
{Result, NewVal} = case F() of
|
||||
{ok, Val} ->
|
||||
{{ok, Val}, Val};
|
||||
_ ->
|
||||
{error, '$cached_mismatch'}
|
||||
end,
|
||||
?GEN_SERVER:call(
|
||||
Proc, {cache_insert, Key, NewVal}, ?CALL_TIMEOUT),
|
||||
Result
|
||||
end.
|
||||
|
||||
insert(Tab, Key, Val, F) ->
|
||||
?GEN_SERVER:call(
|
||||
get_proc_by_hash(Tab, Key), {insert, Key, Val, F}, ?CALL_TIMEOUT).
|
||||
|
||||
dirty_insert(Tab, Key, Val, F) ->
|
||||
F(),
|
||||
?GEN_SERVER:call(
|
||||
get_proc_by_hash(Tab, Key), {cache_insert, Key, Val}, ?CALL_TIMEOUT).
|
||||
|
||||
info(Tab, Info) ->
|
||||
case lists:map(
|
||||
fun(Proc) ->
|
||||
?GEN_SERVER:call(Proc, {info, Info}, ?CALL_TIMEOUT)
|
||||
end, get_all_procs(Tab)) of
|
||||
Res when Info == size ->
|
||||
{ok, lists:sum(Res)};
|
||||
Res when Info == all ->
|
||||
{ok, Res};
|
||||
Res when Info == ratio ->
|
||||
{H, M} = lists:foldl(
|
||||
fun({Hits, Miss}, {HitsAcc, MissAcc}) ->
|
||||
{HitsAcc + Hits, MissAcc + Miss}
|
||||
end, {0, 0}, Res),
|
||||
{ok, [{hits, H}, {miss, M}]};
|
||||
_ ->
|
||||
{error, badarg}
|
||||
end.
|
||||
|
||||
setopts(Tab, Opts) ->
|
||||
lists:foreach(
|
||||
fun(Proc) ->
|
||||
?GEN_SERVER:call(Proc, {setopts, Opts}, ?CALL_TIMEOUT)
|
||||
end, get_all_procs(Tab)).
|
||||
|
||||
tab2list(Tab) ->
|
||||
lists:flatmap(
|
||||
fun(Proc) ->
|
||||
?GEN_SERVER:call(Proc, tab2list, ?CALL_TIMEOUT)
|
||||
end, get_all_procs(Tab)).
|
||||
|
||||
all() ->
|
||||
lists:usort(
|
||||
[Tab || {{Tab, _}, _, _, _} <- supervisor:which_children(cache_tab_sup)]).
|
||||
|
||||
%%====================================================================
|
||||
%% gen_server callbacks
|
||||
%%====================================================================
|
||||
init([Tab, Opts, N, Pid]) ->
|
||||
State = #state{procs_num = N,
|
||||
owner = Pid,
|
||||
name = Tab},
|
||||
{ok, do_setopts(State, Opts)}.
|
||||
|
||||
handle_call({lookup, Key, F}, _From, #state{tab = T} = State) ->
|
||||
CleanPrio = clean_priority(State#state.life_time),
|
||||
case treap:lookup(Key, T) of
|
||||
{ok, Prio, Val} when (State#state.lru == true) or (Prio =< CleanPrio) ->
|
||||
Hits = State#state.hits,
|
||||
NewState = treap_update(Key, Val, State#state{hits = Hits + 1}),
|
||||
case Val of
|
||||
'$cached_mismatch' ->
|
||||
{reply, error, NewState};
|
||||
_ ->
|
||||
{reply, {ok, Val}, NewState}
|
||||
end;
|
||||
_ ->
|
||||
case catch F() of
|
||||
{ok, Val} ->
|
||||
Miss = State#state.miss,
|
||||
NewState = treap_insert(Key, Val, State),
|
||||
{reply, {ok, Val}, NewState#state{miss = Miss + 1}};
|
||||
{'EXIT', Reason} ->
|
||||
print_error(lookup, [Key], Reason, State),
|
||||
{reply, error, State};
|
||||
_ ->
|
||||
Miss = State#state.miss,
|
||||
NewState = State#state{miss = Miss + 1},
|
||||
if State#state.cache_missed ->
|
||||
{reply, error,
|
||||
treap_insert(Key, '$cached_mismatch', NewState)};
|
||||
true ->
|
||||
{reply, error, NewState}
|
||||
end
|
||||
end
|
||||
end;
|
||||
handle_call({cache_lookup, Key}, _From, #state{tab = T} = State) ->
|
||||
CleanPrio = clean_priority(State#state.life_time),
|
||||
case treap:lookup(Key, T) of
|
||||
{ok, Prio, Val} when (State#state.lru == true) or (Prio =< CleanPrio) ->
|
||||
Hits = State#state.hits,
|
||||
NewState = treap_update(Key, Val, State#state{hits = Hits + 1}),
|
||||
{reply, {ok, Val}, NewState};
|
||||
_ ->
|
||||
Miss = State#state.miss,
|
||||
NewState = State#state{miss = Miss + 1},
|
||||
{reply, error, NewState}
|
||||
end;
|
||||
handle_call({insert, Key, Val, F}, _From, #state{tab = T} = State) ->
|
||||
case treap:lookup(Key, T) of
|
||||
{ok, _Prio, Val} ->
|
||||
{reply, ok, treap_update(Key, Val, State)};
|
||||
_ ->
|
||||
case catch F() of
|
||||
{'EXIT', Reason} ->
|
||||
print_error(insert, [Key, Val], Reason, State),
|
||||
{reply, ok, State};
|
||||
_ ->
|
||||
{reply, ok, treap_insert(Key, Val, State)}
|
||||
end
|
||||
end;
|
||||
handle_call({cache_insert, _, '$cached_mismatch'}, _From,
|
||||
#state{cache_missed = false} = State) ->
|
||||
{reply, ok, State};
|
||||
handle_call({cache_insert, Key, Val}, _From, State) ->
|
||||
{reply, ok, treap_insert(Key, Val, State)};
|
||||
handle_call({delete, Key, F}, _From, State) ->
|
||||
NewState = treap_delete(Key, State),
|
||||
case catch F() of
|
||||
{'EXIT', Reason} ->
|
||||
print_error(delete, [Key], Reason, State);
|
||||
_ ->
|
||||
ok
|
||||
end,
|
||||
{reply, ok, NewState};
|
||||
handle_call({cache_delete, Key}, _From, State) ->
|
||||
NewState = treap_delete(Key, State),
|
||||
{reply, ok, NewState};
|
||||
handle_call({info, Info}, _From, State) ->
|
||||
Res = case Info of
|
||||
size ->
|
||||
State#state.size;
|
||||
ratio ->
|
||||
{State#state.hits, State#state.miss};
|
||||
all ->
|
||||
[{max_size, State#state.max_size},
|
||||
{life_time, State#state.life_time},
|
||||
{shrink_size, State#state.shrink_size},
|
||||
{size, State#state.size},
|
||||
{owner, State#state.owner},
|
||||
{hits, State#state.hits},
|
||||
{miss, State#state.miss},
|
||||
{cache_missed, State#state.cache_missed},
|
||||
{lru, State#state.lru},
|
||||
{warn, State#state.warn}];
|
||||
_ ->
|
||||
badarg
|
||||
end,
|
||||
{reply, Res, State};
|
||||
handle_call(tab2list, _From, #state{tab = T} = State) ->
|
||||
Res = treap:fold(
|
||||
fun({Key, _, Val}, Acc) ->
|
||||
[{Key, Val}|Acc]
|
||||
end, [], T),
|
||||
{reply, Res, State};
|
||||
handle_call({setopts, Opts}, _From, State) ->
|
||||
{reply, ok, do_setopts(State, Opts)};
|
||||
handle_call(_Request, _From, State) ->
|
||||
Reply = ok,
|
||||
{reply, Reply, State}.
|
||||
|
||||
handle_cast(_Msg, State) ->
|
||||
{noreply, State}.
|
||||
|
||||
handle_info(_Info, State) ->
|
||||
{noreply, State}.
|
||||
|
||||
terminate(_Reason, _State) ->
|
||||
ok.
|
||||
|
||||
code_change(_OldVsn, State, _Extra) ->
|
||||
{ok, State}.
|
||||
|
||||
%%--------------------------------------------------------------------
|
||||
%%% Internal functions
|
||||
%%--------------------------------------------------------------------
|
||||
do_setopts(#state{procs_num = N} = State, Opts) ->
|
||||
MaxSize = case {proplists:get_value(max_size, Opts),
|
||||
State#state.max_size} of
|
||||
{MS, _} when is_integer(MS), MS > 0 ->
|
||||
round(MS/N);
|
||||
{unlimited, _} ->
|
||||
unlimited;
|
||||
{_, undefined} ->
|
||||
round(?MAX_SIZE/N);
|
||||
{_, MS} ->
|
||||
MS
|
||||
end,
|
||||
LifeTime = case {proplists:get_value(life_time, Opts),
|
||||
State#state.life_time} of
|
||||
{LT, _} when is_integer(LT), LT > 0 ->
|
||||
LT*1000*1000;
|
||||
{unlimited, _} ->
|
||||
unlimited;
|
||||
{_, undefined} ->
|
||||
?LIFETIME*1000*1000;
|
||||
{_, LT} ->
|
||||
LT
|
||||
end,
|
||||
ShrinkSize = case {proplists:get_value(shrink_size, Opts),
|
||||
State#state.shrink_size} of
|
||||
{SS, _} when is_integer(SS), SS > 0 ->
|
||||
round(SS/N);
|
||||
_ when is_integer(MaxSize) ->
|
||||
round(MaxSize/2);
|
||||
_ ->
|
||||
unlimited
|
||||
end,
|
||||
Warn = case {proplists:get_value(warn, Opts),
|
||||
State#state.warn} of
|
||||
{true, _} ->
|
||||
true;
|
||||
{false, _} ->
|
||||
false;
|
||||
{_, undefined} ->
|
||||
?WARN;
|
||||
{_, W} ->
|
||||
W
|
||||
end,
|
||||
CacheMissed = case proplists:get_value(
|
||||
cache_missed, Opts, State#state.cache_missed) of
|
||||
false ->
|
||||
false;
|
||||
true ->
|
||||
true;
|
||||
_ ->
|
||||
?CACHE_MISSED
|
||||
end,
|
||||
LRU = case proplists:get_value(
|
||||
lru, Opts, State#state.lru) of
|
||||
false ->
|
||||
false;
|
||||
true ->
|
||||
true;
|
||||
_ ->
|
||||
?LRU
|
||||
end,
|
||||
State#state{max_size = MaxSize,
|
||||
warn = Warn,
|
||||
life_time = LifeTime,
|
||||
cache_missed = CacheMissed,
|
||||
lru = LRU,
|
||||
shrink_size = ShrinkSize}.
|
||||
|
||||
get_proc_num() ->
|
||||
erlang:system_info(logical_processors).
|
||||
|
||||
get_proc_by_hash(Tab, Term) ->
|
||||
N = erlang:phash2(Term, get_proc_num()) + 1,
|
||||
get_proc(Tab, N).
|
||||
|
||||
get_proc(Tab, N) ->
|
||||
list_to_atom(atom_to_list(?PROCNAME) ++ "_" ++
|
||||
atom_to_list(Tab) ++ "_" ++ integer_to_list(N)).
|
||||
|
||||
get_all_procs(Tab) ->
|
||||
[get_proc(Tab, N) || N <- lists:seq(1, get_proc_num())].
|
||||
|
||||
now_priority() ->
|
||||
{MSec, Sec, USec} = now(),
|
||||
-((MSec*1000000 + Sec)*1000000 + USec).
|
||||
|
||||
clean_priority(LifeTime) ->
|
||||
if is_integer(LifeTime) ->
|
||||
now_priority() + LifeTime;
|
||||
true ->
|
||||
unlimited
|
||||
end.
|
||||
|
||||
treap_update(Key, Val, #state{tab = T, lru = LRU} = State) ->
|
||||
if LRU ->
|
||||
Priority = now_priority(),
|
||||
NewT = treap:insert(Key, Priority, Val, T),
|
||||
State#state{tab = NewT};
|
||||
true ->
|
||||
State
|
||||
end.
|
||||
|
||||
treap_insert(Key, Val, State) ->
|
||||
State1 = clean_treap(State),
|
||||
#state{size = Size} = State2 = shrink_treap(State1),
|
||||
T = State2#state.tab,
|
||||
case treap:lookup(Key, T) of
|
||||
{ok, _, Val} ->
|
||||
treap_update(Key, Val, State2);
|
||||
{ok, _, _} ->
|
||||
NewT = treap:insert(Key, now_priority(), Val, T),
|
||||
State2#state{tab = NewT};
|
||||
_ ->
|
||||
NewT = treap:insert(Key, now_priority(), Val, T),
|
||||
State2#state{tab = NewT, size = Size+1}
|
||||
end.
|
||||
|
||||
treap_delete(Key, #state{tab = T, size = Size} = State) ->
|
||||
case treap:lookup(Key, T) of
|
||||
{ok, _, _} ->
|
||||
NewT = treap:delete(Key, T),
|
||||
clean_treap(State#state{tab = NewT, size = Size-1});
|
||||
_ ->
|
||||
State
|
||||
end.
|
||||
|
||||
clean_treap(#state{tab = T, size = Size, life_time = LifeTime} = State) ->
|
||||
if is_integer(LifeTime) ->
|
||||
Priority = now_priority(),
|
||||
{Cleaned, NewT} = clean_treap(T, Priority + LifeTime, 0),
|
||||
State#state{size = Size - Cleaned, tab = NewT};
|
||||
true ->
|
||||
State
|
||||
end.
|
||||
|
||||
clean_treap(Treap, CleanPriority, N) ->
|
||||
case treap:is_empty(Treap) of
|
||||
true ->
|
||||
{N, Treap};
|
||||
false ->
|
||||
{_Key, Priority, _Value} = treap:get_root(Treap),
|
||||
if Priority > CleanPriority ->
|
||||
clean_treap(treap:delete_root(Treap), CleanPriority, N+1);
|
||||
true ->
|
||||
{N, Treap}
|
||||
end
|
||||
end.
|
||||
|
||||
shrink_treap(#state{tab = T,
|
||||
max_size = MaxSize,
|
||||
shrink_size = ShrinkSize,
|
||||
warn = Warn,
|
||||
size = Size} = State) when Size >= MaxSize ->
|
||||
if Warn ->
|
||||
?WARNING_MSG("shrinking table:~n"
|
||||
"** Table: ~p~n"
|
||||
"** Processes Number: ~p~n"
|
||||
"** Max Size: ~p items~n"
|
||||
"** Shrink Size: ~p items~n"
|
||||
"** Life Time: ~p microseconds~n"
|
||||
"** Hits/Miss: ~p/~p~n"
|
||||
"** Owner: ~p~n"
|
||||
"** Cache Missed: ~p~n"
|
||||
"** Instruction: you have to tune cacheing options"
|
||||
" if this message repeats too frequently",
|
||||
[State#state.name, State#state.procs_num,
|
||||
MaxSize, ShrinkSize, State#state.life_time,
|
||||
State#state.hits, State#state.miss,
|
||||
State#state.owner, State#state.cache_missed]);
|
||||
true ->
|
||||
ok
|
||||
end,
|
||||
{Shrinked, NewT} = shrink_treap(T, ShrinkSize, 0),
|
||||
State#state{tab = NewT, size = Size - Shrinked};
|
||||
shrink_treap(State) ->
|
||||
State.
|
||||
|
||||
shrink_treap(T, ShrinkSize, ShrinkSize) ->
|
||||
{ShrinkSize, T};
|
||||
shrink_treap(T, ShrinkSize, N) ->
|
||||
case treap:is_empty(T) of
|
||||
true ->
|
||||
{N, T};
|
||||
false ->
|
||||
shrink_treap(treap:delete_root(T), ShrinkSize, N+1)
|
||||
end.
|
||||
|
||||
print_error(Operation, Args, Reason, State) ->
|
||||
?ERROR_MSG("callback failed:~n"
|
||||
"** Tab: ~p~n"
|
||||
"** Owner: ~p~n"
|
||||
"** Operation: ~p~n"
|
||||
"** Args: ~p~n"
|
||||
"** Reason: ~p",
|
||||
[State#state.name, State#state.owner,
|
||||
Operation, Args, Reason]).
|
||||
|
||||
%%--------------------------------------------------------------------
|
||||
%%% Tests
|
||||
%%--------------------------------------------------------------------
|
||||
-define(lookup, dirty_lookup).
|
||||
-define(delete, dirty_delete).
|
||||
-define(insert, dirty_insert).
|
||||
%%-define(lookup, lookup).
|
||||
%%-define(delete, delete).
|
||||
%%-define(insert, insert).
|
||||
|
||||
test() ->
|
||||
LifeTime = 2,
|
||||
ok = new(test_tbl, [{life_time, LifeTime}, {max_size, unlimited}]),
|
||||
check([]),
|
||||
ok = ?insert(test_tbl, "key", "value", fun() -> ok end),
|
||||
check([{"key", "value"}]),
|
||||
{ok, "value"} = ?lookup(test_tbl, "key", fun() -> error end),
|
||||
check([{"key", "value"}]),
|
||||
io:format("** waiting for ~p seconds to check if LRU works fine...~n",
|
||||
[LifeTime+1]),
|
||||
timer:sleep(timer:seconds(LifeTime+1)),
|
||||
ok = ?insert(test_tbl, "key1", "value1", fun() -> ok end),
|
||||
check([{"key1", "value1"}]),
|
||||
ok = ?delete(test_tbl, "key1", fun() -> ok end),
|
||||
{ok, "value"} = ?lookup(test_tbl, "key", fun() -> {ok, "value"} end),
|
||||
check([{"key", "value"}]),
|
||||
ok = ?delete(test_tbl, "key", fun() -> ok end),
|
||||
check([]),
|
||||
%% io:format("** testing buggy callbacks...~n"),
|
||||
%% delete(test_tbl, "key", fun() -> erlang:error(badarg) end),
|
||||
%% insert(test_tbl, "key", "val", fun() -> erlang:error(badarg) end),
|
||||
%% lookup(test_tbl, "key", fun() -> erlang:error(badarg) end),
|
||||
check([]),
|
||||
delete(test_tbl),
|
||||
test1().
|
||||
|
||||
test1() ->
|
||||
MaxSize = 10,
|
||||
ok = new(test_tbl, [{max_size, MaxSize}, {shrink_size, 1}, {warn, false}]),
|
||||
lists:foreach(
|
||||
fun(N) ->
|
||||
ok = ?insert(test_tbl, N, N, fun() -> ok end)
|
||||
end, lists:seq(1, MaxSize*get_proc_num())),
|
||||
{ok, MaxSize} = info(test_tbl, size),
|
||||
delete(test_tbl),
|
||||
test2().
|
||||
|
||||
test2() ->
|
||||
LifeTime = 2,
|
||||
ok = new(test_tbl, [{life_time, LifeTime},
|
||||
{max_size, unlimited},
|
||||
{lru, false}]),
|
||||
check([]),
|
||||
ok = ?insert(test_tbl, "key", "value", fun() -> ok end),
|
||||
{ok, "value"} = ?lookup(test_tbl, "key", fun() -> error end),
|
||||
check([{"key", "value"}]),
|
||||
io:format("** waiting for ~p seconds to check if non-LRU works fine...~n",
|
||||
[LifeTime+1]),
|
||||
timer:sleep(timer:seconds(LifeTime+1)),
|
||||
error = ?lookup(test_tbl, "key", fun() -> error end),
|
||||
check([{"key", '$cached_mismatch'}]),
|
||||
ok = ?insert(test_tbl, "key", "value1", fun() -> ok end),
|
||||
check([{"key", "value1"}]),
|
||||
delete(test_tbl),
|
||||
io:format("** testing speed, this may take a while...~n"),
|
||||
test3(1000),
|
||||
test3(10000),
|
||||
test3(100000),
|
||||
test3(1000000).
|
||||
|
||||
test3(Iter) ->
|
||||
ok = new(test_tbl, [{max_size, unlimited}, {life_time, unlimited}]),
|
||||
L = lists:seq(1, Iter),
|
||||
T1 = now(),
|
||||
lists:foreach(
|
||||
fun(N) ->
|
||||
ok = ?insert(test_tbl, N, N, fun() -> ok end)
|
||||
end, L),
|
||||
io:format("** average insert (size = ~p): ~p usec~n",
|
||||
[Iter, round(timer:now_diff(now(), T1)/Iter)]),
|
||||
T2 = now(),
|
||||
lists:foreach(
|
||||
fun(N) ->
|
||||
{ok, N} = ?lookup(test_tbl, N, fun() -> ok end)
|
||||
end, L),
|
||||
io:format("** average lookup (size = ~p): ~p usec~n",
|
||||
[Iter, round(timer:now_diff(now(), T2)/Iter)]),
|
||||
{ok, Iter} = info(test_tbl, size),
|
||||
delete(test_tbl).
|
||||
|
||||
check(List) ->
|
||||
Size = length(List),
|
||||
{ok, Size} = info(test_tbl, size),
|
||||
List = tab2list(test_tbl).
|
||||
@@ -1,53 +0,0 @@
|
||||
%%%-------------------------------------------------------------------
|
||||
%%% File : cache_tab_sup.erl
|
||||
%%% Author : Evgeniy Khramtsov <ekhramtsov@process-one.net>
|
||||
%%% Description : Cache tables supervisor
|
||||
%%%
|
||||
%%% Created : 30 Aug 2010 by Evgeniy Khramtsov <ekhramtsov@process-one.net>
|
||||
%%%
|
||||
%%%
|
||||
%%% ejabberd, Copyright (C) 2002-2010 ProcessOne
|
||||
%%%
|
||||
%%% This program is free software; you can redistribute it and/or
|
||||
%%% modify it under the terms of the GNU General Public License as
|
||||
%%% published by the Free Software Foundation; either version 2 of the
|
||||
%%% License, or (at your option) any later version.
|
||||
%%%
|
||||
%%% This program is distributed in the hope that it will be useful,
|
||||
%%% but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
%%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
%%% General Public License for more details.
|
||||
%%%
|
||||
%%% You should have received a copy of the GNU General Public License
|
||||
%%% along with this program; if not, write to the Free Software
|
||||
%%% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||
%%% 02111-1307 USA
|
||||
%%%
|
||||
%%%-------------------------------------------------------------------
|
||||
-module(cache_tab_sup).
|
||||
|
||||
-behaviour(supervisor).
|
||||
|
||||
%% API
|
||||
-export([start_link/0]).
|
||||
|
||||
%% Supervisor callbacks
|
||||
-export([init/1]).
|
||||
|
||||
-define(SERVER, ?MODULE).
|
||||
|
||||
%%====================================================================
|
||||
%% API functions
|
||||
%%====================================================================
|
||||
start_link() ->
|
||||
supervisor:start_link({local, ?SERVER}, ?MODULE, []).
|
||||
|
||||
%%====================================================================
|
||||
%% Supervisor callbacks
|
||||
%%====================================================================
|
||||
init([]) ->
|
||||
{ok, {{one_for_one,10,1}, []}}.
|
||||
|
||||
%%====================================================================
|
||||
%% Internal functions
|
||||
%%====================================================================
|
||||
@@ -1,6 +1,6 @@
|
||||
#! /bin/sh
|
||||
# Guess values for system-dependent variables and create Makefiles.
|
||||
# Generated by GNU Autoconf 2.65 for ejabberd 2.1.x.
|
||||
# Generated by GNU Autoconf 2.65 for ejabberd 3.0.0-alpha-x.
|
||||
#
|
||||
# Report bugs to <ejabberd@process-one.net>.
|
||||
#
|
||||
@@ -552,11 +552,12 @@ MAKEFLAGS=
|
||||
# Identity of this package.
|
||||
PACKAGE_NAME='ejabberd'
|
||||
PACKAGE_TARNAME='ejabberd'
|
||||
PACKAGE_VERSION='2.1.x'
|
||||
PACKAGE_STRING='ejabberd 2.1.x'
|
||||
PACKAGE_VERSION='3.0.0-alpha-x'
|
||||
PACKAGE_STRING='ejabberd 3.0.0-alpha-x'
|
||||
PACKAGE_BUGREPORT='ejabberd@process-one.net'
|
||||
PACKAGE_URL=''
|
||||
|
||||
ac_default_prefix=/
|
||||
# Factoring default headers for most tests.
|
||||
ac_includes_default="\
|
||||
#include <stdio.h>
|
||||
@@ -593,7 +594,6 @@ ac_includes_default="\
|
||||
# include <unistd.h>
|
||||
#endif"
|
||||
|
||||
ac_default_prefix=/
|
||||
ac_subst_vars='LTLIBOBJS
|
||||
ERLCFLAGS
|
||||
target_os
|
||||
@@ -608,11 +608,9 @@ build_os
|
||||
build_vendor
|
||||
build_cpu
|
||||
build
|
||||
md2
|
||||
INSTALLUSER
|
||||
SSL_CFLAGS
|
||||
SSL_LIBS
|
||||
nif
|
||||
full_xml
|
||||
transient_supervisors
|
||||
db_type
|
||||
@@ -640,16 +638,11 @@ make_mod_proxy65
|
||||
mod_proxy65
|
||||
make_mod_muc
|
||||
mod_muc
|
||||
make_mod_irc
|
||||
mod_irc
|
||||
LIBOBJS
|
||||
EXPAT_LIBS
|
||||
EXPAT_CFLAGS
|
||||
EGREP
|
||||
GREP
|
||||
CPP
|
||||
LIBICONV
|
||||
ERLANG_SSLVER
|
||||
ERLANG_EXMPP
|
||||
ERLANG_LIBS
|
||||
ERLANG_CFLAGS
|
||||
ERL
|
||||
@@ -704,9 +697,6 @@ ac_subst_files=''
|
||||
ac_user_opts='
|
||||
enable_option_checking
|
||||
with_erlang
|
||||
with_libiconv_prefix
|
||||
with_expat
|
||||
enable_mod_irc
|
||||
enable_mod_muc
|
||||
enable_mod_proxy65
|
||||
enable_mod_pubsub
|
||||
@@ -723,7 +713,6 @@ enable_roster_gateway_workaround
|
||||
enable_mssql
|
||||
enable_transient_supervisors
|
||||
enable_full_xml
|
||||
enable_nif
|
||||
with_openssl
|
||||
enable_user
|
||||
'
|
||||
@@ -1279,7 +1268,7 @@ if test "$ac_init_help" = "long"; then
|
||||
# Omit some internal or obsolete options to make the list less imposing.
|
||||
# This message is too long to be a string in the A/UX 3.1 sh.
|
||||
cat <<_ACEOF
|
||||
\`configure' configures ejabberd 2.1.x to adapt to many kinds of systems.
|
||||
\`configure' configures ejabberd 3.0.0-alpha-x to adapt to many kinds of systems.
|
||||
|
||||
Usage: $0 [OPTION]... [VAR=VALUE]...
|
||||
|
||||
@@ -1345,7 +1334,7 @@ fi
|
||||
|
||||
if test -n "$ac_init_help"; then
|
||||
case $ac_init_help in
|
||||
short | recursive ) echo "Configuration of ejabberd 2.1.x:";;
|
||||
short | recursive ) echo "Configuration of ejabberd 3.0.0-alpha-x:";;
|
||||
esac
|
||||
cat <<\_ACEOF
|
||||
|
||||
@@ -1353,7 +1342,6 @@ Optional Features:
|
||||
--disable-option-checking ignore unrecognized --enable/--with options
|
||||
--disable-FEATURE do not include FEATURE (same as --enable-FEATURE=no)
|
||||
--enable-FEATURE[=ARG] include FEATURE [ARG=yes]
|
||||
--enable-mod_irc enable mod_irc (default: yes)
|
||||
--enable-mod_muc enable mod_muc (default: yes)
|
||||
--enable-mod_proxy65 enable mod_proxy65 (default: yes)
|
||||
--enable-mod_pubsub enable mod_pubsub (default: yes)
|
||||
@@ -1375,8 +1363,6 @@ Optional Features:
|
||||
(default: yes)
|
||||
--enable-full-xml use XML features in XMPP stream (ex: CDATA)
|
||||
(default: no, requires XML compliant clients)
|
||||
--enable-nif replace some functions with C equivalents. Requires
|
||||
Erlang R13B04 or higher (default: no)
|
||||
--enable-user[[[=USER]]]
|
||||
allow this system user to start ejabberd (default:
|
||||
no)
|
||||
@@ -1385,9 +1371,6 @@ Optional Packages:
|
||||
--with-PACKAGE[=ARG] use PACKAGE [ARG=yes]
|
||||
--without-PACKAGE do not use PACKAGE (same as --with-PACKAGE=no)
|
||||
--with-erlang=PREFIX path to erlc and erl
|
||||
--with-libiconv-prefix=PREFIX
|
||||
prefix where libiconv is installed
|
||||
--with-expat=PREFIX prefix where EXPAT is installed
|
||||
--with-zlib=PREFIX prefix where zlib is installed
|
||||
--with-pam=PREFIX prefix where PAM is installed
|
||||
--with-openssl=PREFIX prefix where OPENSSL is installed
|
||||
@@ -1470,7 +1453,7 @@ fi
|
||||
test -n "$ac_init_help" && exit $ac_status
|
||||
if $ac_init_version; then
|
||||
cat <<\_ACEOF
|
||||
ejabberd configure 2.1.x
|
||||
ejabberd configure 3.0.0-alpha-x
|
||||
generated by GNU Autoconf 2.65
|
||||
|
||||
Copyright (C) 2009 Free Software Foundation, Inc.
|
||||
@@ -1522,52 +1505,6 @@ fi
|
||||
|
||||
} # ac_fn_c_try_compile
|
||||
|
||||
# ac_fn_c_try_link LINENO
|
||||
# -----------------------
|
||||
# Try to link conftest.$ac_ext, and return whether this succeeded.
|
||||
ac_fn_c_try_link ()
|
||||
{
|
||||
as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
|
||||
rm -f conftest.$ac_objext conftest$ac_exeext
|
||||
if { { ac_try="$ac_link"
|
||||
case "(($ac_try" in
|
||||
*\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
|
||||
*) ac_try_echo=$ac_try;;
|
||||
esac
|
||||
eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
|
||||
$as_echo "$ac_try_echo"; } >&5
|
||||
(eval "$ac_link") 2>conftest.err
|
||||
ac_status=$?
|
||||
if test -s conftest.err; then
|
||||
grep -v '^ *+' conftest.err >conftest.er1
|
||||
cat conftest.er1 >&5
|
||||
mv -f conftest.er1 conftest.err
|
||||
fi
|
||||
$as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
|
||||
test $ac_status = 0; } && {
|
||||
test -z "$ac_c_werror_flag" ||
|
||||
test ! -s conftest.err
|
||||
} && test -s conftest$ac_exeext && {
|
||||
test "$cross_compiling" = yes ||
|
||||
$as_test_x conftest$ac_exeext
|
||||
}; then :
|
||||
ac_retval=0
|
||||
else
|
||||
$as_echo "$as_me: failed program was:" >&5
|
||||
sed 's/^/| /' conftest.$ac_ext >&5
|
||||
|
||||
ac_retval=1
|
||||
fi
|
||||
# Delete the IPA/IPO (Inter Procedural Analysis/Optimization) information
|
||||
# created by the PGI compiler (conftest_ipa8_conftest.oo), as it would
|
||||
# interfere with the next link command; also delete a directory that is
|
||||
# left behind by Apple's compiler. We do this before executing the actions.
|
||||
rm -rf conftest.dSYM conftest_ipa8_conftest.oo
|
||||
eval $as_lineno_stack; test "x$as_lineno_stack" = x && { as_lineno=; unset as_lineno;}
|
||||
as_fn_set_status $ac_retval
|
||||
|
||||
} # ac_fn_c_try_link
|
||||
|
||||
# ac_fn_c_try_cpp LINENO
|
||||
# ----------------------
|
||||
# Try to preprocess conftest.$ac_ext, and return whether this succeeded.
|
||||
@@ -1605,6 +1542,48 @@ fi
|
||||
|
||||
} # ac_fn_c_try_cpp
|
||||
|
||||
# ac_fn_c_try_run LINENO
|
||||
# ----------------------
|
||||
# Try to link conftest.$ac_ext, and return whether this succeeded. Assumes
|
||||
# that executables *can* be run.
|
||||
ac_fn_c_try_run ()
|
||||
{
|
||||
as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
|
||||
if { { ac_try="$ac_link"
|
||||
case "(($ac_try" in
|
||||
*\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
|
||||
*) ac_try_echo=$ac_try;;
|
||||
esac
|
||||
eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
|
||||
$as_echo "$ac_try_echo"; } >&5
|
||||
(eval "$ac_link") 2>&5
|
||||
ac_status=$?
|
||||
$as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
|
||||
test $ac_status = 0; } && { ac_try='./conftest$ac_exeext'
|
||||
{ { case "(($ac_try" in
|
||||
*\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
|
||||
*) ac_try_echo=$ac_try;;
|
||||
esac
|
||||
eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
|
||||
$as_echo "$ac_try_echo"; } >&5
|
||||
(eval "$ac_try") 2>&5
|
||||
ac_status=$?
|
||||
$as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
|
||||
test $ac_status = 0; }; }; then :
|
||||
ac_retval=0
|
||||
else
|
||||
$as_echo "$as_me: program exited with status $ac_status" >&5
|
||||
$as_echo "$as_me: failed program was:" >&5
|
||||
sed 's/^/| /' conftest.$ac_ext >&5
|
||||
|
||||
ac_retval=$ac_status
|
||||
fi
|
||||
rm -rf conftest.dSYM conftest_ipa8_conftest.oo
|
||||
eval $as_lineno_stack; test "x$as_lineno_stack" = x && { as_lineno=; unset as_lineno;}
|
||||
as_fn_set_status $ac_retval
|
||||
|
||||
} # ac_fn_c_try_run
|
||||
|
||||
# ac_fn_c_check_header_mongrel LINENO HEADER VAR INCLUDES
|
||||
# -------------------------------------------------------
|
||||
# Tests whether HEADER exists, giving a warning if it cannot be compiled using
|
||||
@@ -1698,48 +1677,6 @@ fi
|
||||
|
||||
} # ac_fn_c_check_header_mongrel
|
||||
|
||||
# ac_fn_c_try_run LINENO
|
||||
# ----------------------
|
||||
# Try to link conftest.$ac_ext, and return whether this succeeded. Assumes
|
||||
# that executables *can* be run.
|
||||
ac_fn_c_try_run ()
|
||||
{
|
||||
as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
|
||||
if { { ac_try="$ac_link"
|
||||
case "(($ac_try" in
|
||||
*\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
|
||||
*) ac_try_echo=$ac_try;;
|
||||
esac
|
||||
eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
|
||||
$as_echo "$ac_try_echo"; } >&5
|
||||
(eval "$ac_link") 2>&5
|
||||
ac_status=$?
|
||||
$as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
|
||||
test $ac_status = 0; } && { ac_try='./conftest$ac_exeext'
|
||||
{ { case "(($ac_try" in
|
||||
*\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
|
||||
*) ac_try_echo=$ac_try;;
|
||||
esac
|
||||
eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
|
||||
$as_echo "$ac_try_echo"; } >&5
|
||||
(eval "$ac_try") 2>&5
|
||||
ac_status=$?
|
||||
$as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
|
||||
test $ac_status = 0; }; }; then :
|
||||
ac_retval=0
|
||||
else
|
||||
$as_echo "$as_me: program exited with status $ac_status" >&5
|
||||
$as_echo "$as_me: failed program was:" >&5
|
||||
sed 's/^/| /' conftest.$ac_ext >&5
|
||||
|
||||
ac_retval=$ac_status
|
||||
fi
|
||||
rm -rf conftest.dSYM conftest_ipa8_conftest.oo
|
||||
eval $as_lineno_stack; test "x$as_lineno_stack" = x && { as_lineno=; unset as_lineno;}
|
||||
as_fn_set_status $ac_retval
|
||||
|
||||
} # ac_fn_c_try_run
|
||||
|
||||
# ac_fn_c_check_header_compile LINENO HEADER VAR INCLUDES
|
||||
# -------------------------------------------------------
|
||||
# Tests whether HEADER exists and can be compiled using the include files in
|
||||
@@ -1771,6 +1708,52 @@ $as_echo "$ac_res" >&6; }
|
||||
|
||||
} # ac_fn_c_check_header_compile
|
||||
|
||||
# ac_fn_c_try_link LINENO
|
||||
# -----------------------
|
||||
# Try to link conftest.$ac_ext, and return whether this succeeded.
|
||||
ac_fn_c_try_link ()
|
||||
{
|
||||
as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
|
||||
rm -f conftest.$ac_objext conftest$ac_exeext
|
||||
if { { ac_try="$ac_link"
|
||||
case "(($ac_try" in
|
||||
*\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
|
||||
*) ac_try_echo=$ac_try;;
|
||||
esac
|
||||
eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
|
||||
$as_echo "$ac_try_echo"; } >&5
|
||||
(eval "$ac_link") 2>conftest.err
|
||||
ac_status=$?
|
||||
if test -s conftest.err; then
|
||||
grep -v '^ *+' conftest.err >conftest.er1
|
||||
cat conftest.er1 >&5
|
||||
mv -f conftest.er1 conftest.err
|
||||
fi
|
||||
$as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
|
||||
test $ac_status = 0; } && {
|
||||
test -z "$ac_c_werror_flag" ||
|
||||
test ! -s conftest.err
|
||||
} && test -s conftest$ac_exeext && {
|
||||
test "$cross_compiling" = yes ||
|
||||
$as_test_x conftest$ac_exeext
|
||||
}; then :
|
||||
ac_retval=0
|
||||
else
|
||||
$as_echo "$as_me: failed program was:" >&5
|
||||
sed 's/^/| /' conftest.$ac_ext >&5
|
||||
|
||||
ac_retval=1
|
||||
fi
|
||||
# Delete the IPA/IPO (Inter Procedural Analysis/Optimization) information
|
||||
# created by the PGI compiler (conftest_ipa8_conftest.oo), as it would
|
||||
# interfere with the next link command; also delete a directory that is
|
||||
# left behind by Apple's compiler. We do this before executing the actions.
|
||||
rm -rf conftest.dSYM conftest_ipa8_conftest.oo
|
||||
eval $as_lineno_stack; test "x$as_lineno_stack" = x && { as_lineno=; unset as_lineno;}
|
||||
as_fn_set_status $ac_retval
|
||||
|
||||
} # ac_fn_c_try_link
|
||||
|
||||
# ac_fn_erl_try_run LINENO
|
||||
# ------------------------
|
||||
# Try to link conftest.$ac_ext, and return whether this succeeded. Assumes
|
||||
@@ -1816,7 +1799,7 @@ cat >config.log <<_ACEOF
|
||||
This file contains any messages produced by compilers while
|
||||
running configure, to aid debugging if configure makes a mistake.
|
||||
|
||||
It was created by ejabberd $as_me 2.1.x, which was
|
||||
It was created by ejabberd $as_me 3.0.0-alpha-x, which was
|
||||
generated by GNU Autoconf 2.65. Invocation command line was
|
||||
|
||||
$ $0 $@
|
||||
@@ -3216,18 +3199,16 @@ fi
|
||||
start() ->
|
||||
EIDirS = code:lib_dir("erl_interface") ++ "\n",
|
||||
EILibS = libpath("erl_interface") ++ "\n",
|
||||
EXMPPDir = code:lib_dir("exmpp"),
|
||||
case EXMPPDir of
|
||||
{error, bad_name} -> exit("exmpp not found");
|
||||
_ -> ok
|
||||
end,
|
||||
EXMPPDirS = EXMPPDir ++ "\n",
|
||||
RootDirS = code:root_dir() ++ "\n",
|
||||
file:write_file("conftest.out", list_to_binary(EIDirS ++ EILibS ++ ssldef() ++ RootDirS)),
|
||||
file:write_file("conftest.out", list_to_binary(EIDirS ++ EILibS ++ EXMPPDirS ++ RootDirS)),
|
||||
halt().
|
||||
|
||||
ssldef() ->
|
||||
OTP = (catch erlang:system_info(otp_release)),
|
||||
if
|
||||
OTP >= "R14" -> "-DSSL40\n";
|
||||
OTP >= "R12" -> "-DSSL39\n";
|
||||
true -> "\n"
|
||||
end.
|
||||
|
||||
%% return physical architecture based on OS/Processor
|
||||
archname() ->
|
||||
ArchStr = erlang:system_info(system_architecture),
|
||||
@@ -3276,7 +3257,7 @@ _EOF
|
||||
# Second line
|
||||
ERLANG_EI_LIB=`cat conftest.out | head -n 2 | tail -n 1`
|
||||
# Third line
|
||||
ERLANG_SSLVER=`cat conftest.out | head -n 3 | tail -n 1`
|
||||
ERLANG_EXMPP=`cat conftest.out | head -n 3 | tail -n 1`
|
||||
# End line
|
||||
ERLANG_DIR=`cat conftest.out | tail -n 1`
|
||||
|
||||
@@ -3289,172 +3270,97 @@ _EOF
|
||||
|
||||
|
||||
|
||||
#locating iconv
|
||||
|
||||
# Checks for typedefs, structures, and compiler characteristics.
|
||||
|
||||
|
||||
# Check whether --with-libiconv-prefix was given.
|
||||
if test "${with_libiconv_prefix+set}" = set; then :
|
||||
withval=$with_libiconv_prefix;
|
||||
for dir in `echo "$withval" | tr : ' '`; do
|
||||
if test -d $dir/include; then CPPFLAGS="$CPPFLAGS -I$dir/include"; fi
|
||||
if test -d $dir/include; then CFLAGS="$CFLAGS -I$dir/include"; fi
|
||||
if test -d $dir/lib; then LDFLAGS="$LDFLAGS -L$dir/lib"; fi
|
||||
done
|
||||
|
||||
fi
|
||||
|
||||
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for iconv" >&5
|
||||
$as_echo_n "checking for iconv... " >&6; }
|
||||
if test "${am_cv_func_iconv+set}" = set; then :
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for an ANSI C-conforming const" >&5
|
||||
$as_echo_n "checking for an ANSI C-conforming const... " >&6; }
|
||||
if test "${ac_cv_c_const+set}" = set; then :
|
||||
$as_echo_n "(cached) " >&6
|
||||
else
|
||||
|
||||
am_cv_func_iconv="no, consider installing GNU libiconv"
|
||||
am_cv_lib_iconv=no
|
||||
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
|
||||
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
|
||||
/* end confdefs.h. */
|
||||
#include <stdlib.h>
|
||||
#include <iconv.h>
|
||||
|
||||
int
|
||||
main ()
|
||||
{
|
||||
iconv_t cd = iconv_open("","");
|
||||
iconv(cd,NULL,NULL,NULL,NULL);
|
||||
iconv_close(cd);
|
||||
;
|
||||
return 0;
|
||||
}
|
||||
_ACEOF
|
||||
if ac_fn_c_try_link "$LINENO"; then :
|
||||
am_cv_func_iconv=yes
|
||||
fi
|
||||
rm -f core conftest.err conftest.$ac_objext \
|
||||
conftest$ac_exeext conftest.$ac_ext
|
||||
if test "$am_cv_func_iconv" != yes; then
|
||||
am_save_LIBS="$LIBS"
|
||||
LIBS="$LIBS -liconv"
|
||||
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
|
||||
/* end confdefs.h. */
|
||||
#include <stdlib.h>
|
||||
#include <iconv.h>
|
||||
int
|
||||
main ()
|
||||
{
|
||||
iconv_t cd = iconv_open("","");
|
||||
iconv(cd,NULL,NULL,NULL,NULL);
|
||||
iconv_close(cd);
|
||||
;
|
||||
return 0;
|
||||
}
|
||||
_ACEOF
|
||||
if ac_fn_c_try_link "$LINENO"; then :
|
||||
am_cv_lib_iconv=yes
|
||||
am_cv_func_iconv=yes
|
||||
fi
|
||||
rm -f core conftest.err conftest.$ac_objext \
|
||||
conftest$ac_exeext conftest.$ac_ext
|
||||
LIBS="$am_save_LIBS"
|
||||
fi
|
||||
if test "$am_cv_func_iconv" != yes; then
|
||||
am_save_LIBS="$LIBS"
|
||||
am_save_CFLAGS="$CFLAGS"
|
||||
am_save_LDFLAGS="$LDFLAGS"
|
||||
LIBS="$LIBS -liconv"
|
||||
LDFLAGS="$LDFLAGS -L/usr/local/lib"
|
||||
CFLAGS="$CFLAGS -I/usr/local/include"
|
||||
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
|
||||
/* end confdefs.h. */
|
||||
#include <stdlib.h>
|
||||
#include <iconv.h>
|
||||
int
|
||||
main ()
|
||||
{
|
||||
iconv_t cd = iconv_open("","");
|
||||
iconv(cd,NULL,NULL,NULL,NULL);
|
||||
iconv_close(cd);
|
||||
;
|
||||
return 0;
|
||||
}
|
||||
_ACEOF
|
||||
if ac_fn_c_try_link "$LINENO"; then :
|
||||
am_cv_lib_iconv=yes
|
||||
am_cv_func_iconv=yes
|
||||
CPPFLAGS="$CPPFLAGS -I/usr/local/include"
|
||||
else
|
||||
LDFLAGS="$am_save_LDFLAGS"
|
||||
CFLAGS="$am_save_CFLAGS"
|
||||
fi
|
||||
rm -f core conftest.err conftest.$ac_objext \
|
||||
conftest$ac_exeext conftest.$ac_ext
|
||||
LIBS="$am_save_LIBS"
|
||||
fi
|
||||
/* FIXME: Include the comments suggested by Paul. */
|
||||
#ifndef __cplusplus
|
||||
/* Ultrix mips cc rejects this. */
|
||||
typedef int charset[2];
|
||||
const charset cs;
|
||||
/* SunOS 4.1.1 cc rejects this. */
|
||||
char const *const *pcpcc;
|
||||
char **ppc;
|
||||
/* NEC SVR4.0.2 mips cc rejects this. */
|
||||
struct point {int x, y;};
|
||||
static struct point const zero = {0,0};
|
||||
/* AIX XL C 1.02.0.0 rejects this.
|
||||
It does not let you subtract one const X* pointer from another in
|
||||
an arm of an if-expression whose if-part is not a constant
|
||||
expression */
|
||||
const char *g = "string";
|
||||
pcpcc = &g + (g ? g-g : 0);
|
||||
/* HPUX 7.0 cc rejects these. */
|
||||
++pcpcc;
|
||||
ppc = (char**) pcpcc;
|
||||
pcpcc = (char const *const *) ppc;
|
||||
{ /* SCO 3.2v4 cc rejects this. */
|
||||
char *t;
|
||||
char const *s = 0 ? (char *) 0 : (char const *) 0;
|
||||
|
||||
|
||||
fi
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $am_cv_func_iconv" >&5
|
||||
$as_echo "$am_cv_func_iconv" >&6; }
|
||||
if test "$am_cv_func_iconv" = yes; then
|
||||
|
||||
$as_echo "#define HAVE_ICONV 1" >>confdefs.h
|
||||
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for iconv declaration" >&5
|
||||
$as_echo_n "checking for iconv declaration... " >&6; }
|
||||
if test "${am_cv_proto_iconv+set}" = set; then :
|
||||
$as_echo_n "(cached) " >&6
|
||||
else
|
||||
|
||||
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
|
||||
/* end confdefs.h. */
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <iconv.h>
|
||||
extern
|
||||
#ifdef __cplusplus
|
||||
"C"
|
||||
*t++ = 0;
|
||||
if (s) return 0;
|
||||
}
|
||||
{ /* Someone thinks the Sun supposedly-ANSI compiler will reject this. */
|
||||
int x[] = {25, 17};
|
||||
const int *foo = &x[0];
|
||||
++foo;
|
||||
}
|
||||
{ /* Sun SC1.0 ANSI compiler rejects this -- but not the above. */
|
||||
typedef const int *iptr;
|
||||
iptr p = 0;
|
||||
++p;
|
||||
}
|
||||
{ /* AIX XL C 1.02.0.0 rejects this saying
|
||||
"k.c", line 2.27: 1506-025 (S) Operand must be a modifiable lvalue. */
|
||||
struct s { int j; const int *ap[3]; };
|
||||
struct s *b; b->j = 5;
|
||||
}
|
||||
{ /* ULTRIX-32 V3.1 (Rev 9) vcc rejects this */
|
||||
const int foo = 10;
|
||||
if (!foo) return 0;
|
||||
}
|
||||
return !cs[0] && !zero.x;
|
||||
#endif
|
||||
#if defined(__STDC__) || defined(__cplusplus)
|
||||
size_t iconv (iconv_t cd, char * *inbuf, size_t *inbytesleft, char * *outbuf, size_t *outbytesleft);
|
||||
#else
|
||||
size_t iconv();
|
||||
#endif
|
||||
|
||||
int
|
||||
main ()
|
||||
{
|
||||
|
||||
;
|
||||
return 0;
|
||||
}
|
||||
_ACEOF
|
||||
if ac_fn_c_try_compile "$LINENO"; then :
|
||||
am_cv_proto_iconv_arg1=""
|
||||
ac_cv_c_const=yes
|
||||
else
|
||||
am_cv_proto_iconv_arg1="const"
|
||||
ac_cv_c_const=no
|
||||
fi
|
||||
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
|
||||
am_cv_proto_iconv="extern size_t iconv (iconv_t cd, $am_cv_proto_iconv_arg1 char * *inbuf, size_t *inbytesleft, char * *outbuf, size_t *outbytesleft);"
|
||||
fi
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_c_const" >&5
|
||||
$as_echo "$ac_cv_c_const" >&6; }
|
||||
if test $ac_cv_c_const = no; then
|
||||
|
||||
$as_echo "#define const /**/" >>confdefs.h
|
||||
|
||||
fi
|
||||
|
||||
am_cv_proto_iconv=`echo "$am_cv_proto_iconv" | tr -s ' ' | sed -e 's/( /(/'`
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: ${ac_t:-
|
||||
}$am_cv_proto_iconv" >&5
|
||||
$as_echo "${ac_t:-
|
||||
}$am_cv_proto_iconv" >&6; }
|
||||
|
||||
cat >>confdefs.h <<_ACEOF
|
||||
#define ICONV_CONST $am_cv_proto_iconv_arg1
|
||||
_ACEOF
|
||||
# Check Erlang headers are installed
|
||||
#AC_CHECK_HEADER(erl_driver.h,,[AC_MSG_ERROR([cannot find Erlang header files])])
|
||||
|
||||
fi
|
||||
LIBICONV=
|
||||
if test "$am_cv_lib_iconv" = yes; then
|
||||
LIBICONV="-liconv"
|
||||
fi
|
||||
# Change default prefix
|
||||
|
||||
|
||||
#locating libexpat
|
||||
# Checks for library functions.
|
||||
ac_ext=c
|
||||
ac_cpp='$CPP $CPPFLAGS'
|
||||
ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
|
||||
@@ -3853,183 +3759,6 @@ fi
|
||||
done
|
||||
|
||||
|
||||
|
||||
# Check whether --with-expat was given.
|
||||
if test "${with_expat+set}" = set; then :
|
||||
withval=$with_expat;
|
||||
fi
|
||||
|
||||
|
||||
EXPAT_CFLAGS=
|
||||
EXPAT_LIBS=
|
||||
if test x"$with_expat" != x; then
|
||||
EXPAT_CFLAGS="-I$with_expat/include"
|
||||
EXPAT_LIBS="-L$with_expat/lib"
|
||||
fi
|
||||
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for XML_ParserCreate in -lexpat" >&5
|
||||
$as_echo_n "checking for XML_ParserCreate in -lexpat... " >&6; }
|
||||
if test "${ac_cv_lib_expat_XML_ParserCreate+set}" = set; then :
|
||||
$as_echo_n "(cached) " >&6
|
||||
else
|
||||
ac_check_lib_save_LIBS=$LIBS
|
||||
LIBS="-lexpat "$EXPAT_LIBS" $LIBS"
|
||||
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
|
||||
/* end confdefs.h. */
|
||||
|
||||
/* Override any GCC internal prototype to avoid an error.
|
||||
Use char because int might match the return type of a GCC
|
||||
builtin and then its argument prototype would still apply. */
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
#endif
|
||||
char XML_ParserCreate ();
|
||||
int
|
||||
main ()
|
||||
{
|
||||
return XML_ParserCreate ();
|
||||
;
|
||||
return 0;
|
||||
}
|
||||
_ACEOF
|
||||
if ac_fn_c_try_link "$LINENO"; then :
|
||||
ac_cv_lib_expat_XML_ParserCreate=yes
|
||||
else
|
||||
ac_cv_lib_expat_XML_ParserCreate=no
|
||||
fi
|
||||
rm -f core conftest.err conftest.$ac_objext \
|
||||
conftest$ac_exeext conftest.$ac_ext
|
||||
LIBS=$ac_check_lib_save_LIBS
|
||||
fi
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_expat_XML_ParserCreate" >&5
|
||||
$as_echo "$ac_cv_lib_expat_XML_ParserCreate" >&6; }
|
||||
if test "x$ac_cv_lib_expat_XML_ParserCreate" = x""yes; then :
|
||||
EXPAT_LIBS="$EXPAT_LIBS -lexpat"
|
||||
expat_found=yes
|
||||
else
|
||||
expat_found=no
|
||||
fi
|
||||
|
||||
if test $expat_found = no; then
|
||||
as_fn_error "Could not find development files of Expat library" "$LINENO" 5
|
||||
fi
|
||||
expat_save_CFLAGS="$CFLAGS"
|
||||
CFLAGS="$CFLAGS $EXPAT_CFLAGS"
|
||||
expat_save_CPPFLAGS="$CPPFLAGS"
|
||||
CPPFLAGS="$CPPFLAGS $EXPAT_CFLAGS"
|
||||
for ac_header in expat.h
|
||||
do :
|
||||
ac_fn_c_check_header_mongrel "$LINENO" "expat.h" "ac_cv_header_expat_h" "$ac_includes_default"
|
||||
if test "x$ac_cv_header_expat_h" = x""yes; then :
|
||||
cat >>confdefs.h <<_ACEOF
|
||||
#define HAVE_EXPAT_H 1
|
||||
_ACEOF
|
||||
|
||||
else
|
||||
expat_found=no
|
||||
fi
|
||||
|
||||
done
|
||||
|
||||
if test $expat_found = no; then
|
||||
as_fn_error "Could not find expat.h" "$LINENO" 5
|
||||
fi
|
||||
CFLAGS="$expat_save_CFLAGS"
|
||||
CPPFLAGS="$expat_save_CPPFLAGS"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# Checks for typedefs, structures, and compiler characteristics.
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for an ANSI C-conforming const" >&5
|
||||
$as_echo_n "checking for an ANSI C-conforming const... " >&6; }
|
||||
if test "${ac_cv_c_const+set}" = set; then :
|
||||
$as_echo_n "(cached) " >&6
|
||||
else
|
||||
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
|
||||
/* end confdefs.h. */
|
||||
|
||||
int
|
||||
main ()
|
||||
{
|
||||
/* FIXME: Include the comments suggested by Paul. */
|
||||
#ifndef __cplusplus
|
||||
/* Ultrix mips cc rejects this. */
|
||||
typedef int charset[2];
|
||||
const charset cs;
|
||||
/* SunOS 4.1.1 cc rejects this. */
|
||||
char const *const *pcpcc;
|
||||
char **ppc;
|
||||
/* NEC SVR4.0.2 mips cc rejects this. */
|
||||
struct point {int x, y;};
|
||||
static struct point const zero = {0,0};
|
||||
/* AIX XL C 1.02.0.0 rejects this.
|
||||
It does not let you subtract one const X* pointer from another in
|
||||
an arm of an if-expression whose if-part is not a constant
|
||||
expression */
|
||||
const char *g = "string";
|
||||
pcpcc = &g + (g ? g-g : 0);
|
||||
/* HPUX 7.0 cc rejects these. */
|
||||
++pcpcc;
|
||||
ppc = (char**) pcpcc;
|
||||
pcpcc = (char const *const *) ppc;
|
||||
{ /* SCO 3.2v4 cc rejects this. */
|
||||
char *t;
|
||||
char const *s = 0 ? (char *) 0 : (char const *) 0;
|
||||
|
||||
*t++ = 0;
|
||||
if (s) return 0;
|
||||
}
|
||||
{ /* Someone thinks the Sun supposedly-ANSI compiler will reject this. */
|
||||
int x[] = {25, 17};
|
||||
const int *foo = &x[0];
|
||||
++foo;
|
||||
}
|
||||
{ /* Sun SC1.0 ANSI compiler rejects this -- but not the above. */
|
||||
typedef const int *iptr;
|
||||
iptr p = 0;
|
||||
++p;
|
||||
}
|
||||
{ /* AIX XL C 1.02.0.0 rejects this saying
|
||||
"k.c", line 2.27: 1506-025 (S) Operand must be a modifiable lvalue. */
|
||||
struct s { int j; const int *ap[3]; };
|
||||
struct s *b; b->j = 5;
|
||||
}
|
||||
{ /* ULTRIX-32 V3.1 (Rev 9) vcc rejects this */
|
||||
const int foo = 10;
|
||||
if (!foo) return 0;
|
||||
}
|
||||
return !cs[0] && !zero.x;
|
||||
#endif
|
||||
|
||||
;
|
||||
return 0;
|
||||
}
|
||||
_ACEOF
|
||||
if ac_fn_c_try_compile "$LINENO"; then :
|
||||
ac_cv_c_const=yes
|
||||
else
|
||||
ac_cv_c_const=no
|
||||
fi
|
||||
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
|
||||
fi
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_c_const" >&5
|
||||
$as_echo "$ac_cv_c_const" >&6; }
|
||||
if test $ac_cv_c_const = no; then
|
||||
|
||||
$as_echo "#define const /**/" >>confdefs.h
|
||||
|
||||
fi
|
||||
|
||||
|
||||
# Check Erlang headers are installed
|
||||
#AC_CHECK_HEADER(erl_driver.h,,[AC_MSG_ERROR([cannot find Erlang header files])])
|
||||
|
||||
# Change default prefix
|
||||
|
||||
|
||||
# Checks for library functions.
|
||||
for ac_header in stdlib.h
|
||||
do :
|
||||
ac_fn_c_check_header_mongrel "$LINENO" "stdlib.h" "ac_cv_header_stdlib_h" "$ac_includes_default"
|
||||
@@ -4211,28 +3940,6 @@ fi
|
||||
|
||||
|
||||
|
||||
mod_irc=
|
||||
make_mod_irc=
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether build mod_irc" >&5
|
||||
$as_echo_n "checking whether build mod_irc... " >&6; }
|
||||
# Check whether --enable-mod_irc was given.
|
||||
if test "${enable_mod_irc+set}" = set; then :
|
||||
enableval=$enable_mod_irc; mr_enable_mod_irc="$enableval"
|
||||
else
|
||||
mr_enable_mod_irc=yes
|
||||
fi
|
||||
|
||||
if test "$mr_enable_mod_irc" = "yes"; then
|
||||
mod_irc=mod_irc
|
||||
make_mod_irc=mod_irc/Makefile
|
||||
fi
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $mr_enable_mod_irc" >&5
|
||||
$as_echo "$mr_enable_mod_irc" >&6; }
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
mod_muc=
|
||||
make_mod_muc=
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether build mod_muc" >&5
|
||||
@@ -4677,20 +4384,7 @@ fi
|
||||
|
||||
|
||||
|
||||
# Check whether --enable-nif was given.
|
||||
if test "${enable_nif+set}" = set; then :
|
||||
enableval=$enable_nif; case "${enableval}" in
|
||||
yes) nif=true ;;
|
||||
no) nif=false ;;
|
||||
*) as_fn_error "bad value ${enableval} for --enable-nif" "$LINENO" 5 ;;
|
||||
esac
|
||||
else
|
||||
nif=false
|
||||
fi
|
||||
|
||||
|
||||
|
||||
ac_config_files="$ac_config_files Makefile $make_mod_irc $make_mod_muc $make_mod_pubsub $make_mod_proxy65 $make_eldap $make_pam $make_web stringprep/Makefile stun/Makefile $make_tls $make_odbc $make_ejabberd_zlib"
|
||||
ac_config_files="$ac_config_files Makefile $make_mod_muc $make_mod_pubsub $make_mod_proxy65 $make_eldap $make_pam $make_web stun/Makefile $make_tls $make_odbc $make_ejabberd_zlib"
|
||||
|
||||
#openssl
|
||||
|
||||
@@ -4823,16 +4517,6 @@ if test "$ENABLEUSER" != ""; then
|
||||
|
||||
fi
|
||||
|
||||
ac_fn_c_check_header_mongrel "$LINENO" "openssl/md2.h" "ac_cv_header_openssl_md2_h" "$ac_includes_default"
|
||||
if test "x$ac_cv_header_openssl_md2_h" = x""yes; then :
|
||||
md2=true
|
||||
else
|
||||
md2=false
|
||||
fi
|
||||
|
||||
|
||||
|
||||
|
||||
ac_aux_dir=
|
||||
for ac_dir in "$srcdir" "$srcdir/.." "$srcdir/../.."; do
|
||||
for ac_t in install-sh install.sh shtool; do
|
||||
@@ -5665,7 +5349,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
|
||||
# report actual input values of CONFIG_FILES etc. instead of their
|
||||
# values after options handling.
|
||||
ac_log="
|
||||
This file was extended by ejabberd $as_me 2.1.x, which was
|
||||
This file was extended by ejabberd $as_me 3.0.0-alpha-x, which was
|
||||
generated by GNU Autoconf 2.65. Invocation command line was
|
||||
|
||||
CONFIG_FILES = $CONFIG_FILES
|
||||
@@ -5718,7 +5402,7 @@ _ACEOF
|
||||
cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
|
||||
ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`"
|
||||
ac_cs_version="\\
|
||||
ejabberd config.status 2.1.x
|
||||
ejabberd config.status 3.0.0-alpha-x
|
||||
configured by $0, generated by GNU Autoconf 2.65,
|
||||
with options \\"\$ac_cs_config\\"
|
||||
|
||||
@@ -5823,14 +5507,12 @@ for ac_config_target in $ac_config_targets
|
||||
do
|
||||
case $ac_config_target in
|
||||
"Makefile") CONFIG_FILES="$CONFIG_FILES Makefile" ;;
|
||||
"$make_mod_irc") CONFIG_FILES="$CONFIG_FILES $make_mod_irc" ;;
|
||||
"$make_mod_muc") CONFIG_FILES="$CONFIG_FILES $make_mod_muc" ;;
|
||||
"$make_mod_pubsub") CONFIG_FILES="$CONFIG_FILES $make_mod_pubsub" ;;
|
||||
"$make_mod_proxy65") CONFIG_FILES="$CONFIG_FILES $make_mod_proxy65" ;;
|
||||
"$make_eldap") CONFIG_FILES="$CONFIG_FILES $make_eldap" ;;
|
||||
"$make_pam") CONFIG_FILES="$CONFIG_FILES $make_pam" ;;
|
||||
"$make_web") CONFIG_FILES="$CONFIG_FILES $make_web" ;;
|
||||
"stringprep/Makefile") CONFIG_FILES="$CONFIG_FILES stringprep/Makefile" ;;
|
||||
"stun/Makefile") CONFIG_FILES="$CONFIG_FILES stun/Makefile" ;;
|
||||
"$make_tls") CONFIG_FILES="$CONFIG_FILES $make_tls" ;;
|
||||
"$make_odbc") CONFIG_FILES="$CONFIG_FILES $make_odbc" ;;
|
||||
@@ -6273,3 +5955,12 @@ if test -n "$ac_unrecognized_opts" && test "$enable_option_checking" != no; then
|
||||
$as_echo "$as_me: WARNING: unrecognized options: $ac_unrecognized_opts" >&2;}
|
||||
fi
|
||||
|
||||
|
||||
echo
|
||||
echo "********************** WARNING ! ************************"
|
||||
echo "* ejabberd master is NOT ready for real usage yet, *"
|
||||
echo "* because it is still in heavy development. *"
|
||||
echo "* Don't use ejabberd master, it is still alpha code! *"
|
||||
echo "* Please use ejabberd 2.1.x branch instead. *"
|
||||
echo "*********************************************************"
|
||||
echo
|
||||
|
||||
@@ -14,10 +14,6 @@ fi
|
||||
|
||||
#locating erlang
|
||||
AM_WITH_ERLANG
|
||||
#locating iconv
|
||||
AM_ICONV
|
||||
#locating libexpat
|
||||
AM_WITH_EXPAT
|
||||
|
||||
# Checks for typedefs, structures, and compiler characteristics.
|
||||
AC_C_CONST
|
||||
@@ -32,7 +28,6 @@ AC_PREFIX_DEFAULT(/)
|
||||
AC_FUNC_MALLOC
|
||||
AC_HEADER_STDC
|
||||
|
||||
AC_MOD_ENABLE(mod_irc, yes)
|
||||
AC_MOD_ENABLE(mod_muc, yes)
|
||||
AC_MOD_ENABLE(mod_proxy65, yes)
|
||||
AC_MOD_ENABLE(mod_pubsub, yes)
|
||||
@@ -94,24 +89,13 @@ AC_ARG_ENABLE(full_xml,
|
||||
esac],[full_xml=false])
|
||||
AC_SUBST(full_xml)
|
||||
|
||||
AC_ARG_ENABLE(nif,
|
||||
[AC_HELP_STRING([--enable-nif], [replace some functions with C equivalents. Requires Erlang R13B04 or higher (default: no)])],
|
||||
[case "${enableval}" in
|
||||
yes) nif=true ;;
|
||||
no) nif=false ;;
|
||||
*) AC_MSG_ERROR(bad value ${enableval} for --enable-nif) ;;
|
||||
esac],[nif=false])
|
||||
AC_SUBST(nif)
|
||||
|
||||
AC_CONFIG_FILES([Makefile
|
||||
$make_mod_irc
|
||||
$make_mod_muc
|
||||
$make_mod_pubsub
|
||||
$make_mod_proxy65
|
||||
$make_eldap
|
||||
$make_pam
|
||||
$make_web
|
||||
stringprep/Makefile
|
||||
stun/Makefile
|
||||
$make_tls
|
||||
$make_odbc
|
||||
@@ -148,9 +132,6 @@ if test "$ENABLEUSER" != ""; then
|
||||
AC_SUBST([INSTALLUSER], [$ENABLEUSER])
|
||||
fi
|
||||
|
||||
AC_CHECK_HEADER(openssl/md2.h, md2=true, md2=false)
|
||||
AC_SUBST(md2)
|
||||
|
||||
AC_CANONICAL_SYSTEM
|
||||
#AC_DEFINE_UNQUOTED(CPU_VENDOR_OS, "$target")
|
||||
#AC_SUBST(target_os)
|
||||
@@ -179,3 +160,12 @@ LD_SHARED="$LD_SHARED $CBIT"
|
||||
echo "CBIT is set to '$CBIT'"
|
||||
|
||||
AC_OUTPUT
|
||||
|
||||
echo
|
||||
echo "********************** WARNING ! ************************"
|
||||
echo "* ejabberd master is NOT ready for real usage yet, *"
|
||||
echo "* because it is still in heavy development. *"
|
||||
echo "* Don't use ejabberd master, it is still alpha code! *"
|
||||
echo "* Please use ejabberd 2.1.x branch instead. *"
|
||||
echo "*********************************************************"
|
||||
echo
|
||||
|
||||
@@ -42,17 +42,9 @@ start() ->
|
||||
end,
|
||||
case Static of
|
||||
true ->
|
||||
ExpatLib = "EXPAT_LIB = $(EXPAT_DIR)\\StaticLibs\\libexpatMT.lib\n",
|
||||
ExpatFlag = "EXPAT_FLAG = -DXML_STATIC\n",
|
||||
IconvDir = "ICONV_DIR = c:\\sdk\\GnuWin32\n",
|
||||
IconvLib = "ICONV_LIB = $(ICONV_DIR)\\lib\\libiconv.lib\n",
|
||||
ZlibDir = "ZLIB_DIR = c:\\sdk\\GnuWin32\n",
|
||||
ZlibLib = "ZLIB_LIB = $(ZLIB_DIR)\\lib\\zlib.lib\n";
|
||||
false ->
|
||||
ExpatLib = "EXPAT_LIB = $(EXPAT_DIR)\\Libs\\libexpat.lib\n",
|
||||
ExpatFlag = "",
|
||||
IconvDir = "ICONV_DIR = c:\\sdk\\GnuWin32\n",
|
||||
IconvLib = "ICONV_LIB = $(ICONV_DIR)\\lib\\libiconv.lib\n",
|
||||
ZlibDir = "ZLIB_DIR = c:\\sdk\\GnuWin32\n",
|
||||
ZlibLib = "ZLIB_LIB = $(ZLIB_DIR)\\lib\\zlib.lib\n"
|
||||
end,
|
||||
@@ -63,7 +55,6 @@ start() ->
|
||||
%% Load the ejabberd application description so that ?VERSION can read the vsn key
|
||||
application:load(ejabberd),
|
||||
Version = "EJABBERD_VERSION = " ++ ?VERSION ++ "\n",
|
||||
ExpatDir = "EXPAT_DIR = c:\\sdk\\Expat-2.0.0\n",
|
||||
OpenSSLDir = "OPENSSL_DIR = c:\\sdk\\OpenSSL\n",
|
||||
DBType = "DBTYPE = generic\n", %% 'generic' or 'mssql'
|
||||
|
||||
@@ -79,11 +70,6 @@ start() ->
|
||||
StdLibDir ++
|
||||
OpenSSLDir ++
|
||||
DBType ++
|
||||
ExpatDir ++
|
||||
ExpatLib ++
|
||||
ExpatFlag ++
|
||||
IconvDir ++
|
||||
IconvLib ++
|
||||
ZlibDir ++
|
||||
ZlibLib)),
|
||||
halt().
|
||||
|
||||
@@ -30,22 +30,46 @@
|
||||
-export([start/0,
|
||||
register_mechanism/3,
|
||||
listmech/1,
|
||||
server_new/7,
|
||||
server_new/8,
|
||||
server_start/3,
|
||||
server_step/2]).
|
||||
|
||||
-include("cyrsasl.hrl").
|
||||
-include("ejabberd.hrl").
|
||||
|
||||
%% @type saslmechanism() = {sasl_mechanism, Mechanism, Module, Require_Plain}
|
||||
%% Mechanism = string()
|
||||
%% Module = atom()
|
||||
%% Require_Plain = bool().
|
||||
%% Registry entry of a supported SASL mechanism.
|
||||
|
||||
-record(sasl_mechanism, {mechanism, module, require_plain_password}).
|
||||
-record(sasl_state, {service, myname, realm,
|
||||
get_password, check_password, check_password_digest,
|
||||
mech_mod, mech_state}).
|
||||
|
||||
%% @type saslstate() = {sasl_state, Service, Myname, Realm, GetPassword, CheckPassword, CheckPasswordDigest, Mech_Mod, Mech_State}
|
||||
%% Service = string()
|
||||
%% Myname = string()
|
||||
%% Realm = string()
|
||||
%% GetPassword = function()
|
||||
%% CheckPassword = function()
|
||||
%% CheckPasswordDigest = any()
|
||||
%% Mech_Mod = atom()
|
||||
%% Mech_State = term().
|
||||
%% State of this process.
|
||||
|
||||
-record(sasl_state, {service, myname,
|
||||
mech_mod, mech_state, params}).
|
||||
|
||||
-export([behaviour_info/1]).
|
||||
|
||||
%% @hidden
|
||||
|
||||
behaviour_info(callbacks) ->
|
||||
[{mech_new, 4}, {mech_step, 2}];
|
||||
[{mech_new, 1}, {mech_step, 2}];
|
||||
behaviour_info(_Other) ->
|
||||
undefined.
|
||||
|
||||
%% @spec () -> ok
|
||||
|
||||
start() ->
|
||||
ets:new(sasl_mechanism, [named_table,
|
||||
public,
|
||||
@@ -53,49 +77,81 @@ start() ->
|
||||
cyrsasl_plain:start([]),
|
||||
cyrsasl_digest:start([]),
|
||||
cyrsasl_anonymous:start([]),
|
||||
maybe_try_start_gssapi(),
|
||||
ok.
|
||||
|
||||
maybe_try_start_gssapi() ->
|
||||
case os:getenv("KRB5_KTNAME") of
|
||||
false ->
|
||||
ok;
|
||||
_String ->
|
||||
try_start_gssapi()
|
||||
end.
|
||||
|
||||
try_start_gssapi() ->
|
||||
case code:load_file(esasl) of
|
||||
{module, _Module} ->
|
||||
cyrsasl_gssapi:start([]);
|
||||
{error, What} ->
|
||||
?ERROR_MSG("Support for GSSAPI not started because esasl.beam was not found: ~p", [What])
|
||||
end.
|
||||
|
||||
%% @spec (Mechanism, Module, Require_Plain) -> true
|
||||
%% Mechanism = string()
|
||||
%% Module = atom()
|
||||
%% Require_Plain = bool()
|
||||
|
||||
register_mechanism(Mechanism, Module, RequirePlainPassword) ->
|
||||
ets:insert(sasl_mechanism,
|
||||
#sasl_mechanism{mechanism = Mechanism,
|
||||
module = Module,
|
||||
require_plain_password = RequirePlainPassword}).
|
||||
|
||||
%%% TODO: use callbacks
|
||||
%%-include("ejabberd.hrl").
|
||||
%%-include("jlib.hrl").
|
||||
%%check_authzid(_State, Props) ->
|
||||
%% AuthzId = xml:get_attr_s(authzid, Props),
|
||||
%% case jlib:string_to_jid(AuthzId) of
|
||||
%% error ->
|
||||
%% {error, "invalid-authzid"};
|
||||
%% JID ->
|
||||
%% LUser = jlib:nodeprep(xml:get_attr_s(username, Props)),
|
||||
%% {U, S, R} = jlib:jid_tolower(JID),
|
||||
%% case R of
|
||||
%% "" ->
|
||||
%% {error, "invalid-authzid"};
|
||||
%% _ ->
|
||||
%% case {LUser, ?MYNAME} of
|
||||
%% {U, S} ->
|
||||
%% ok;
|
||||
%% _ ->
|
||||
%% {error, "invalid-authzid"}
|
||||
%% end
|
||||
%% end
|
||||
%% end.
|
||||
% TODO use callbacks
|
||||
%-include("ejabberd.hrl").
|
||||
%-include("jlib.hrl").
|
||||
%check_authzid(_State, Props) ->
|
||||
% AuthzId = xml:get_attr_s(authzid, Props),
|
||||
% case jlib:string_to_jid(AuthzId) of
|
||||
% error ->
|
||||
% {error, "invalid-authzid"};
|
||||
% JID ->
|
||||
% LUser = jlib:nodeprep(xml:get_attr_s(username, Props)),
|
||||
% {U, S, R} = jlib:short_prepd_jid(JID),
|
||||
% case R of
|
||||
% "" ->
|
||||
% {error, "invalid-authzid"};
|
||||
% _ ->
|
||||
% case {LUser, ?MYNAME} of
|
||||
% {U, S} ->
|
||||
% ok;
|
||||
% _ ->
|
||||
% {error, "invalid-authzid"}
|
||||
% end
|
||||
% end
|
||||
% end.
|
||||
|
||||
%% @spec (State, Props) -> ok | {error, 'not-authorized'}
|
||||
%% State = saslstate()
|
||||
%% Props = [{Key, Value}]
|
||||
%% Key = atom()
|
||||
%% Value = string()
|
||||
|
||||
check_credentials(_State, Props) ->
|
||||
User = xml:get_attr_s(username, Props),
|
||||
case jlib:nodeprep(User) of
|
||||
error ->
|
||||
{error, "not-authorized"};
|
||||
"" ->
|
||||
{error, "not-authorized"};
|
||||
_LUser ->
|
||||
ok
|
||||
case proplists:get_value(username, Props) of
|
||||
undefined ->
|
||||
{error, 'not-authorized'};
|
||||
User ->
|
||||
case exmpp_stringprep:is_node(User) of
|
||||
false -> {error, 'not-authorized'};
|
||||
true -> ok
|
||||
end
|
||||
end.
|
||||
|
||||
%% @spec (Host) -> [Mechanism]
|
||||
%% Host = string()
|
||||
%% Mechanism = string()
|
||||
|
||||
listmech(Host) ->
|
||||
RequirePlainPassword = ejabberd_auth:plain_password_required(Host),
|
||||
|
||||
@@ -112,35 +168,78 @@ listmech(Host) ->
|
||||
['$1']}]),
|
||||
filter_anonymous(Host, Mechs).
|
||||
|
||||
%% @spec (Service, ServerFQDN, UserRealm, SecFlags, GetPassword, CheckPassword, CheckPasswordDigest, Socket) -> saslstate()
|
||||
%% Service = string()
|
||||
%% ServerFQDN = string()
|
||||
%% UserRealm = string()
|
||||
%% SecFlags = [term()]
|
||||
%% GetPassword = function()
|
||||
%% CheckPassword = function()
|
||||
|
||||
server_new(Service, ServerFQDN, UserRealm, _SecFlags,
|
||||
GetPassword, CheckPassword, CheckPasswordDigest) ->
|
||||
GetPassword, CheckPassword, CheckPasswordDigest, Socket) ->
|
||||
Params = #sasl_params{
|
||||
host = ServerFQDN,
|
||||
realm = UserRealm,
|
||||
get_password = GetPassword,
|
||||
check_password = CheckPassword,
|
||||
check_password_digest= CheckPasswordDigest,
|
||||
socket = Socket
|
||||
},
|
||||
|
||||
#sasl_state{service = Service,
|
||||
myname = ServerFQDN,
|
||||
realm = UserRealm,
|
||||
get_password = GetPassword,
|
||||
check_password = CheckPassword,
|
||||
check_password_digest= CheckPasswordDigest}.
|
||||
params = Params}.
|
||||
|
||||
|
||||
%% @spec (State, Mech, ClientIn) -> Ok | Continue | Error
|
||||
%% State = saslstate()
|
||||
%% Mech = string()
|
||||
%% ClientIn = string()
|
||||
%% Ok = {ok, Props}
|
||||
%% Props = [Prop]
|
||||
%% Prop = [{Key, Value}]
|
||||
%% Key = atom()
|
||||
%% Value = string()
|
||||
%% Continue = {continue, ServerOut, New_State}
|
||||
%% ServerOut = string()
|
||||
%% New_State = saslstate()
|
||||
%% Error = {error, Reason} | {error, Username, Reason}
|
||||
%% Reason = term()
|
||||
%% Username = string()
|
||||
|
||||
server_start(State, Mech, ClientIn) ->
|
||||
case lists:member(Mech, listmech(State#sasl_state.myname)) of
|
||||
true ->
|
||||
case ets:lookup(sasl_mechanism, Mech) of
|
||||
[#sasl_mechanism{module = Module}] ->
|
||||
{ok, MechState} = Module:mech_new(
|
||||
State#sasl_state.myname,
|
||||
State#sasl_state.get_password,
|
||||
State#sasl_state.check_password,
|
||||
State#sasl_state.check_password_digest),
|
||||
{ok, MechState} =
|
||||
Module:mech_new(State#sasl_state.params),
|
||||
server_step(State#sasl_state{mech_mod = Module,
|
||||
mech_state = MechState},
|
||||
ClientIn);
|
||||
_ ->
|
||||
{error, "no-mechanism"}
|
||||
{error, 'invalid-mechanism'}
|
||||
end;
|
||||
false ->
|
||||
{error, "no-mechanism"}
|
||||
{error, 'invalid-mechanism'}
|
||||
end.
|
||||
|
||||
%% @spec (State, ClientIn) -> Ok | Continue | Error
|
||||
%% State = saslstate()
|
||||
%% ClientIn = string()
|
||||
%% Ok = {ok, Props}
|
||||
%% Props = [Prop]
|
||||
%% Prop = [{Key, Value}]
|
||||
%% Key = atom()
|
||||
%% Value = string()
|
||||
%% Continue = {continue, ServerOut, New_State}
|
||||
%% ServerOut = string()
|
||||
%% New_State = saslstate()
|
||||
%% Error = {error, Reason} | {error, Username, Reason}
|
||||
%% Reason = term()
|
||||
%% Username = string()
|
||||
|
||||
server_step(State, ClientIn) ->
|
||||
Module = State#sasl_state.mech_mod,
|
||||
MechState = State#sasl_state.mech_state,
|
||||
@@ -161,8 +260,15 @@ server_step(State, ClientIn) ->
|
||||
{error, Error}
|
||||
end.
|
||||
|
||||
%% Remove the anonymous mechanism from the list if not enabled for the given
|
||||
%% host
|
||||
%% @spec (Host, Mechs) -> [Filtered_Mechs]
|
||||
%% Host = string()
|
||||
%% Mechs = [Mech]
|
||||
%% Mech = string()
|
||||
%% Filtered_Mechs = [Mech]
|
||||
%%
|
||||
%% @doc Remove the anonymous mechanism from the list if not enabled for
|
||||
%% the given host.
|
||||
|
||||
filter_anonymous(Host, Mechs) ->
|
||||
case ejabberd_auth_anonymous:is_sasl_anonymous_enabled(Host) of
|
||||
true -> Mechs;
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
%% @type saslparams() = {sasl_params, Host, Realm, GetPassword, CheckPassword, CheckPasswordDigest}
|
||||
%% Host = string()
|
||||
%% Realm = string()
|
||||
%% GetPassword = function()
|
||||
%% CheckPassword = function()
|
||||
%% CheckPasswordDigest = any().
|
||||
%% Parameters for SASL.
|
||||
|
||||
-record(sasl_params, {
|
||||
host,
|
||||
realm,
|
||||
get_password,
|
||||
check_password,
|
||||
check_password_digest,
|
||||
socket}).
|
||||
@@ -27,22 +27,42 @@
|
||||
|
||||
-module(cyrsasl_anonymous).
|
||||
|
||||
-export([start/1, stop/0, mech_new/4, mech_step/2]).
|
||||
-export([start/1, stop/0, mech_new/1, mech_step/2]).
|
||||
|
||||
-include("cyrsasl.hrl").
|
||||
|
||||
-behaviour(cyrsasl).
|
||||
|
||||
%% @type mechstate() = {state, Server}
|
||||
%% Server = string().
|
||||
|
||||
-record(state, {server}).
|
||||
|
||||
%% @spec (Opts) -> true
|
||||
%% Opts = term()
|
||||
|
||||
start(_Opts) ->
|
||||
cyrsasl:register_mechanism("ANONYMOUS", ?MODULE, false),
|
||||
ok.
|
||||
|
||||
%% @spec () -> ok
|
||||
|
||||
stop() ->
|
||||
ok.
|
||||
|
||||
mech_new(Host, _GetPassword, _CheckPassword, _CheckPasswordDigest) ->
|
||||
mech_new(#sasl_params{host=Host}) ->
|
||||
{ok, #state{server = Host}}.
|
||||
|
||||
%% @spec (State, ClientIn) -> Ok | Error
|
||||
%% State = mechstate()
|
||||
%% ClientIn = string()
|
||||
%% Ok = {ok, Props}
|
||||
%% Props = [Prop]
|
||||
%% Prop = {username, Username} | {auth_module, AuthModule}
|
||||
%% Username = string()
|
||||
%% AuthModule = ejabberd_auth_anonymous
|
||||
%% Error = {error, 'not-authorized'}
|
||||
|
||||
mech_step(State, _ClientIn) ->
|
||||
%% We generate a random username:
|
||||
User = lists:concat([randoms:get_string() | tuple_to_list(now())]),
|
||||
@@ -50,7 +70,7 @@ mech_step(State, _ClientIn) ->
|
||||
|
||||
%% Checks that the username is available
|
||||
case ejabberd_auth:is_user_exists(User, Server) of
|
||||
true -> {error, "not-authorized"};
|
||||
true -> {error, 'not-authorized'};
|
||||
false -> {ok, [{username, User},
|
||||
{auth_module, ejabberd_auth_anonymous}]}
|
||||
end.
|
||||
|
||||
@@ -29,29 +29,60 @@
|
||||
|
||||
-export([start/1,
|
||||
stop/0,
|
||||
mech_new/4,
|
||||
mech_new/1,
|
||||
mech_step/2]).
|
||||
|
||||
-include("ejabberd.hrl").
|
||||
-include("cyrsasl.hrl").
|
||||
|
||||
-behaviour(cyrsasl).
|
||||
|
||||
%% @type mechstate() = {state, Step, Nonce, Username, AuthzId, GetPassword, CheckPassword, AuthModule, Host}
|
||||
%% Step = 1 | 3 | 5
|
||||
%% Nonce = string()
|
||||
%% Username = string()
|
||||
%% AuthzId = string()
|
||||
%% GetPassword = function()
|
||||
%% AuthModule = atom()
|
||||
%% Host = string().
|
||||
|
||||
-record(state, {step, nonce, username, authzid, get_password, check_password, auth_module,
|
||||
host}).
|
||||
|
||||
%% @spec (Opts) -> true
|
||||
%% Opts = term()
|
||||
|
||||
start(_Opts) ->
|
||||
cyrsasl:register_mechanism("DIGEST-MD5", ?MODULE, true).
|
||||
|
||||
%% @spec () -> ok
|
||||
|
||||
stop() ->
|
||||
ok.
|
||||
|
||||
mech_new(Host, GetPassword, _CheckPassword, CheckPasswordDigest) ->
|
||||
mech_new(#sasl_params{host=Host, get_password=GetPassword,
|
||||
check_password_digest=CheckPasswordDigest}) ->
|
||||
{ok, #state{step = 1,
|
||||
nonce = randoms:get_string(),
|
||||
host = Host,
|
||||
get_password = GetPassword,
|
||||
check_password = CheckPasswordDigest}}.
|
||||
|
||||
%% @spec (State, ClientIn) -> Ok | Continue | Error
|
||||
%% State = mechstate()
|
||||
%% ClientIn = string()
|
||||
%% Ok = {ok, Props}
|
||||
%% Props = [Prop]
|
||||
%% Prop = {username, Username} | {authzid, AuthzId} | {auth_module, AuthModule}
|
||||
%% Username = string()
|
||||
%% AuthzId = string()
|
||||
%% AuthModule = atom()
|
||||
%% Continue = {continue, ServerOut, New_State}
|
||||
%% ServerOut = string()
|
||||
%% New_State = mechstate()
|
||||
%% Error = {error, Reason} | {error, Reason, Username}
|
||||
%% Reason = term()
|
||||
|
||||
mech_step(#state{step = 1, nonce = Nonce} = State, _) ->
|
||||
{continue,
|
||||
"nonce=\"" ++ Nonce ++
|
||||
@@ -60,23 +91,23 @@ mech_step(#state{step = 1, nonce = Nonce} = State, _) ->
|
||||
mech_step(#state{step = 3, nonce = Nonce} = State, ClientIn) ->
|
||||
case parse(ClientIn) of
|
||||
bad ->
|
||||
{error, "bad-protocol"};
|
||||
{error, 'bad-protocol'};
|
||||
KeyVals ->
|
||||
DigestURI = xml:get_attr_s("digest-uri", KeyVals),
|
||||
UserName = xml:get_attr_s("username", KeyVals),
|
||||
DigestURI = proplists:get_value("digest-uri", KeyVals, ""),
|
||||
UserName = proplists:get_value("username", KeyVals, ""),
|
||||
case is_digesturi_valid(DigestURI, State#state.host) of
|
||||
false ->
|
||||
?DEBUG("User login not authorized because digest-uri "
|
||||
"seems invalid: ~p", [DigestURI]),
|
||||
{error, "not-authorized", UserName};
|
||||
{error, 'not-authorized', UserName};
|
||||
true ->
|
||||
AuthzId = xml:get_attr_s("authzid", KeyVals),
|
||||
AuthzId = proplists:get_value("authzid", KeyVals, ""),
|
||||
case (State#state.get_password)(UserName) of
|
||||
{false, _} ->
|
||||
{error, "not-authorized", UserName};
|
||||
{error, 'not-authorized', UserName};
|
||||
{Passwd, AuthModule} ->
|
||||
case (State#state.check_password)(UserName, "",
|
||||
xml:get_attr_s("response", KeyVals),
|
||||
proplists:get_value("response", KeyVals, ""),
|
||||
fun(PW) -> response(KeyVals, UserName, PW, Nonce, AuthzId,
|
||||
"AUTHENTICATE") end) of
|
||||
{true, _} ->
|
||||
@@ -90,9 +121,9 @@ mech_step(#state{step = 3, nonce = Nonce} = State, ClientIn) ->
|
||||
username = UserName,
|
||||
authzid = AuthzId}};
|
||||
false ->
|
||||
{error, "not-authorized", UserName};
|
||||
{error, 'not-authorized', UserName};
|
||||
{false, _} ->
|
||||
{error, "not-authorized", UserName}
|
||||
{error, 'not-authorized', UserName}
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -105,11 +136,18 @@ mech_step(#state{step = 5,
|
||||
{auth_module, AuthModule}]};
|
||||
mech_step(A, B) ->
|
||||
?DEBUG("SASL DIGEST: A ~p B ~p", [A,B]),
|
||||
{error, "bad-protocol"}.
|
||||
{error, 'bad-protocol'}.
|
||||
|
||||
%% @spec (S) -> [{Key, Value}] | bad
|
||||
%% S = string()
|
||||
%% Key = string()
|
||||
%% Value = string()
|
||||
|
||||
parse(S) ->
|
||||
parse1(S, "", []).
|
||||
|
||||
%% @hidden
|
||||
|
||||
parse1([$= | Cs], S, Ts) ->
|
||||
parse2(Cs, lists:reverse(S), "", Ts);
|
||||
parse1([$, | Cs], [], Ts) ->
|
||||
@@ -123,6 +161,8 @@ parse1([], [], T) ->
|
||||
parse1([], _S, _T) ->
|
||||
bad.
|
||||
|
||||
%% @hidden
|
||||
|
||||
parse2([$\" | Cs], Key, Val, Ts) ->
|
||||
parse3(Cs, Key, Val, Ts);
|
||||
parse2([C | Cs], Key, Val, Ts) ->
|
||||
@@ -130,6 +170,8 @@ parse2([C | Cs], Key, Val, Ts) ->
|
||||
parse2([], _, _, _) ->
|
||||
bad.
|
||||
|
||||
%% @hidden
|
||||
|
||||
parse3([$\" | Cs], Key, Val, Ts) ->
|
||||
parse4(Cs, Key, Val, Ts);
|
||||
parse3([$\\, C | Cs], Key, Val, Ts) ->
|
||||
@@ -139,6 +181,8 @@ parse3([C | Cs], Key, Val, Ts) ->
|
||||
parse3([], _, _, _) ->
|
||||
bad.
|
||||
|
||||
%% @hidden
|
||||
|
||||
parse4([$, | Cs], Key, Val, Ts) ->
|
||||
parse1(Cs, "", [{Key, lists:reverse(Val)} | Ts]);
|
||||
parse4([$\s | Cs], Key, Val, Ts) ->
|
||||
@@ -149,6 +193,10 @@ parse4([], Key, Val, Ts) ->
|
||||
parse1([], "", [{Key, lists:reverse(Val)} | Ts]).
|
||||
|
||||
|
||||
%% @spec (DigestURICase, JabberHost) -> bool()
|
||||
%% DigestURICase = string()
|
||||
%% JabberHost = string()
|
||||
%%
|
||||
%% @doc Check if the digest-uri is valid.
|
||||
%% RFC-2831 allows to provide the IP address in Host,
|
||||
%% however ejabberd doesn't allow that.
|
||||
@@ -156,8 +204,9 @@ parse4([], Key, Val, Ts) ->
|
||||
%% is provided by several hosts (being one of them server3.example.org),
|
||||
%% then digest-uri can be like xmpp/server3.example.org/jabber.example.org
|
||||
%% In that case, ejabberd only checks the service name, not the host.
|
||||
|
||||
is_digesturi_valid(DigestURICase, JabberHost) ->
|
||||
DigestURI = stringprep:tolower(DigestURICase),
|
||||
DigestURI = exmpp_stringprep:to_lower(DigestURICase),
|
||||
case catch string:tokens(DigestURI, "/") of
|
||||
["xmpp", Host] when Host == JabberHost ->
|
||||
true;
|
||||
@@ -170,14 +219,20 @@ is_digesturi_valid(DigestURICase, JabberHost) ->
|
||||
|
||||
|
||||
|
||||
%% @hidden
|
||||
|
||||
digit_to_xchar(D) when (D >= 0) and (D < 10) ->
|
||||
D + 48;
|
||||
digit_to_xchar(D) ->
|
||||
D + 87.
|
||||
|
||||
%% @hidden
|
||||
|
||||
hex(S) ->
|
||||
hex(S, []).
|
||||
|
||||
%% @hidden
|
||||
|
||||
hex([], Res) ->
|
||||
lists:reverse(Res);
|
||||
hex([N | Ns], Res) ->
|
||||
@@ -185,12 +240,22 @@ hex([N | Ns], Res) ->
|
||||
digit_to_xchar(N div 16) | Res]).
|
||||
|
||||
|
||||
%% @spec (KeyVals, User, Passwd, Nonce, AuthzId, A2Prefix) -> string()
|
||||
%% KeyVals = [{Key, Value}]
|
||||
%% Key = string()
|
||||
%% Value = string()
|
||||
%% User = string()
|
||||
%% Passwd = string()
|
||||
%% Nonce = string()
|
||||
%% AuthzId = nil() | string()
|
||||
%% A2Prefix = string()
|
||||
|
||||
response(KeyVals, User, Passwd, Nonce, AuthzId, A2Prefix) ->
|
||||
Realm = xml:get_attr_s("realm", KeyVals),
|
||||
CNonce = xml:get_attr_s("cnonce", KeyVals),
|
||||
DigestURI = xml:get_attr_s("digest-uri", KeyVals),
|
||||
NC = xml:get_attr_s("nc", KeyVals),
|
||||
QOP = xml:get_attr_s("qop", KeyVals),
|
||||
Realm = proplists:get_value("realm", KeyVals, ""),
|
||||
CNonce = proplists:get_value("cnonce", KeyVals, ""),
|
||||
DigestURI = proplists:get_value("digest-uri", KeyVals, ""),
|
||||
NC = proplists:get_value("nc", KeyVals, ""),
|
||||
QOP = proplists:get_value("qop", KeyVals, ""),
|
||||
A1 = case AuthzId of
|
||||
"" ->
|
||||
binary_to_list(
|
||||
|
||||
@@ -0,0 +1,164 @@
|
||||
%%%----------------------------------------------------------------------
|
||||
%%% File : cyrsasl_gssapi.erl
|
||||
%%% Author : Mikael Magnusson <mikma@users.sourceforge.net>
|
||||
%%% Purpose : GSSAPI SASL mechanism
|
||||
%%% Created : 1 June 2007 by Mikael Magnusson <mikma@users.sourceforge.net>
|
||||
%%%----------------------------------------------------------------------
|
||||
%%%
|
||||
%%% Copyright (C) 2007-2009 Mikael Magnusson <mikma@users.sourceforge.net>
|
||||
%%%
|
||||
%%% Permission is hereby granted, free of charge, to any person
|
||||
%%% obtaining a copy of this software and associated documentation
|
||||
%%% files (the "Software"), to deal in the Software without
|
||||
%%% restriction, including without limitation the rights to use, copy,
|
||||
%%% modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
%%% of the Software, and to permit persons to whom the Software is
|
||||
%%% furnished to do so, subject to the following conditions:
|
||||
%%%
|
||||
%%% The above copyright notice and this permission notice shall be
|
||||
%%% included in all copies or substantial portions of the Software.
|
||||
%%%
|
||||
%%% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
%%% EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
%%% MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
%%% NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
||||
%%% BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
||||
%%% ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
%%% CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
%%% SOFTWARE.
|
||||
%%%
|
||||
|
||||
%%%
|
||||
%%% configuration options:
|
||||
%%% {sasl_realm, "<Kerberos realm>"}.
|
||||
%%%
|
||||
%%% environment variables:
|
||||
%%% KRB5_KTNAME
|
||||
%%%
|
||||
|
||||
-module(cyrsasl_gssapi).
|
||||
-author('mikma@users.sourceforge.net').
|
||||
|
||||
-export([start/1,
|
||||
stop/0,
|
||||
mech_new/1,
|
||||
mech_step/2]).
|
||||
|
||||
-include("ejabberd.hrl").
|
||||
-include("cyrsasl.hrl").
|
||||
|
||||
-behaviour(cyrsasl).
|
||||
|
||||
-define(SERVER, ?MODULE).
|
||||
-define(SERVICE, "xmpp").
|
||||
|
||||
-record(state, {sasl,
|
||||
needsmore=true,
|
||||
step=0,
|
||||
host,
|
||||
realm,
|
||||
authid,
|
||||
authzid,
|
||||
authrealm,
|
||||
error}).
|
||||
|
||||
start(_Opts) ->
|
||||
ChildSpec =
|
||||
{?SERVER,
|
||||
{esasl, start_link, [{local, ?SERVER}]},
|
||||
transient,
|
||||
1000,
|
||||
worker,
|
||||
[esasl]},
|
||||
|
||||
case supervisor:start_child(ejabberd_sup, ChildSpec) of
|
||||
{ok, _Pid} ->
|
||||
cyrsasl:register_mechanism("GSSAPI", ?MODULE, false);
|
||||
{error, Error} = E ->
|
||||
?ERROR_MSG("esasl failed: ~p", [Error]),
|
||||
E
|
||||
end.
|
||||
|
||||
|
||||
stop() ->
|
||||
catch esasl:stop(?SERVER),
|
||||
supervisor:terminate_child(ejabberd_sup, ?SERVER),
|
||||
supervisor:delete_child(ejabberd_sup, ?SERVER).
|
||||
|
||||
mech_new(#sasl_params{host=Host, realm=Realm, socket=Socket}) ->
|
||||
case ejabberd_socket:gethostname(Socket) of
|
||||
{ok, FQDN} ->
|
||||
?DEBUG("mech_new ~p ~p ~p~n", [Host, Realm, FQDN]),
|
||||
case esasl:server_start(?SERVER, "GSSAPI", ?SERVICE, FQDN) of
|
||||
{ok, Sasl} ->
|
||||
{ok, #state{sasl=Sasl,host=Host,realm=Realm}};
|
||||
{error, {gsasl_error, Error}} ->
|
||||
{ok, Str} = esasl:str_error(?SERVER, Error),
|
||||
?DEBUG("esasl error: ~p", [Str]),
|
||||
{ok, #state{needsmore=error,error="internal-server-error"}};
|
||||
{error, Error} ->
|
||||
?DEBUG("esasl error: ~p", [Error]),
|
||||
{ok, #state{needsmore=error,error="internal-server-error"}}
|
||||
end;
|
||||
{error, Error} ->
|
||||
?DEBUG("gethostname error: ~p", [Error]),
|
||||
{ok, #state{needsmore=error,error="internal-server-error"}}
|
||||
end.
|
||||
|
||||
mech_step(State, ClientIn) when is_list(ClientIn) ->
|
||||
catch do_step(State, ClientIn).
|
||||
|
||||
do_step(#state{needsmore=error,error=Error}=_State, _) ->
|
||||
{error, Error};
|
||||
do_step(#state{needsmore=false}=State, _) ->
|
||||
check_user(State);
|
||||
do_step(#state{needsmore=true,sasl=Sasl,step=Step}=State, ClientIn) ->
|
||||
?DEBUG("mech_step~n", []),
|
||||
case esasl:step(Sasl, list_to_binary(ClientIn)) of
|
||||
{ok, RspAuth} ->
|
||||
?DEBUG("ok~n", []),
|
||||
{ok, Display_name} = esasl:property_get(Sasl, gssapi_display_name),
|
||||
{ok, Authzid} = esasl:property_get(Sasl, authzid),
|
||||
{Authid, [$@ | Auth_realm]} =
|
||||
lists:splitwith(fun(E)->E =/= $@ end, Display_name),
|
||||
State1 = State#state{authid=Authid,
|
||||
authzid=Authzid,
|
||||
authrealm=Auth_realm},
|
||||
handle_step_ok(State1, binary_to_list(RspAuth));
|
||||
{needsmore, RspAuth} ->
|
||||
?DEBUG("needsmore~n", []),
|
||||
if (Step > 0) and (ClientIn =:= []) and (RspAuth =:= <<>>) ->
|
||||
{error, "not-authorized"};
|
||||
true ->
|
||||
{continue, binary_to_list(RspAuth),
|
||||
State#state{step=Step+1}}
|
||||
end;
|
||||
{error, _} ->
|
||||
{error, "not-authorized"}
|
||||
end.
|
||||
|
||||
handle_step_ok(State, []) ->
|
||||
check_user(State);
|
||||
handle_step_ok(#state{step=Step}=State, RspAuth) ->
|
||||
?DEBUG("continue~n", []),
|
||||
{continue, RspAuth, State#state{needsmore=false,step=Step+1}}.
|
||||
|
||||
check_user(#state{authid=Authid,authzid=Authzid,
|
||||
authrealm=Auth_realm,host=Host,realm=Realm}) ->
|
||||
if Realm =/= Auth_realm ->
|
||||
?DEBUG("bad realm ~p (expected ~p)~n",[Auth_realm, Realm]),
|
||||
throw({error, "not-authorized"});
|
||||
true ->
|
||||
ok
|
||||
end,
|
||||
|
||||
case ejabberd_auth:is_user_exists(Authid, Host) of
|
||||
false ->
|
||||
?DEBUG("bad user ~p~n",[Authid]),
|
||||
throw({error, "not-authorized"});
|
||||
true ->
|
||||
ok
|
||||
end,
|
||||
|
||||
?DEBUG("GSSAPI authenticated ~p ~p~n", [Authid, Authzid]),
|
||||
{ok, [{username, Authid}, {authzid, Authzid}]}.
|
||||
@@ -27,22 +27,44 @@
|
||||
-module(cyrsasl_plain).
|
||||
-author('alexey@process-one.net').
|
||||
|
||||
-export([start/1, stop/0, mech_new/4, mech_step/2, parse/1]).
|
||||
-export([start/1, stop/0, mech_new/1, mech_step/2, parse/1]).
|
||||
|
||||
-include("cyrsasl.hrl").
|
||||
|
||||
-behaviour(cyrsasl).
|
||||
|
||||
%% @type mechstate() = {state, CheckPassword}
|
||||
%% CheckPassword = function().
|
||||
|
||||
-record(state, {check_password}).
|
||||
|
||||
%% @spec (Opts) -> true
|
||||
%% Opts = term()
|
||||
|
||||
start(_Opts) ->
|
||||
cyrsasl:register_mechanism("PLAIN", ?MODULE, false),
|
||||
ok.
|
||||
|
||||
%% @spec () -> ok
|
||||
|
||||
stop() ->
|
||||
ok.
|
||||
|
||||
mech_new(_Host, _GetPassword, CheckPassword, _CheckPasswordDigest) ->
|
||||
mech_new(#sasl_params{check_password = CheckPassword}) ->
|
||||
{ok, #state{check_password = CheckPassword}}.
|
||||
|
||||
%% @spec (State, ClientIn) -> Ok | Error
|
||||
%% State = mechstate()
|
||||
%% ClientIn = string()
|
||||
%% Ok = {ok, Props}
|
||||
%% Props = [Prop]
|
||||
%% Prop = {username, Username} | {authzid, AuthzId} | {auth_module, AuthModule}
|
||||
%% Username = string()
|
||||
%% AuthzId = string()
|
||||
%% AuthModule = atom()
|
||||
%% Error = {error, Reason} | {error, Reason, Username}
|
||||
%% Reason = term()
|
||||
|
||||
mech_step(State, ClientIn) ->
|
||||
case prepare(ClientIn) of
|
||||
[AuthzId, User, Password] ->
|
||||
@@ -51,10 +73,10 @@ mech_step(State, ClientIn) ->
|
||||
{ok, [{username, User}, {authzid, AuthzId},
|
||||
{auth_module, AuthModule}]};
|
||||
_ ->
|
||||
{error, "not-authorized", User}
|
||||
{error, 'not-authorized', User}
|
||||
end;
|
||||
_ ->
|
||||
{error, "bad-protocol"}
|
||||
{error, 'bad-protocol'}
|
||||
end.
|
||||
|
||||
prepare(ClientIn) ->
|
||||
@@ -76,9 +98,13 @@ prepare(ClientIn) ->
|
||||
end.
|
||||
|
||||
|
||||
%% @hidden
|
||||
|
||||
parse(S) ->
|
||||
parse1(S, "", []).
|
||||
|
||||
%% @hidden
|
||||
|
||||
parse1([0 | Cs], S, T) ->
|
||||
parse1(Cs, "", [lists:reverse(S) | T]);
|
||||
parse1([C | Cs], S, T) ->
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
%% $Id$
|
||||
|
||||
{application, ejabberd,
|
||||
[{description, "ejabberd"},
|
||||
{vsn, "2.1.6"},
|
||||
{vsn, "3.0.0-alpha-x"},
|
||||
{modules, [acl,
|
||||
adhoc,
|
||||
configure,
|
||||
@@ -15,10 +13,9 @@
|
||||
ejabberd_auth_anonymous,
|
||||
ejabberd_auth,
|
||||
ejabberd_auth_external,
|
||||
ejabberd_auth_internal,
|
||||
ejabberd_auth_ldap,
|
||||
ejabberd_auth_odbc,
|
||||
ejabberd_auth_pam,
|
||||
ejabberd_auth_storage,
|
||||
ejabberd,
|
||||
ejabberd_c2s,
|
||||
ejabberd_c2s_config,
|
||||
@@ -37,6 +34,7 @@
|
||||
ejabberd_rdbms,
|
||||
ejabberd_receiver,
|
||||
ejabberd_router,
|
||||
ejabberd_router_multicast,
|
||||
ejabberd_s2s,
|
||||
ejabberd_s2s_in,
|
||||
ejabberd_s2s_out,
|
||||
@@ -61,7 +59,6 @@
|
||||
gen_mod,
|
||||
gen_pubsub_node,
|
||||
gen_pubsub_nodetree,
|
||||
iconv,
|
||||
idna,
|
||||
jd2ejd,
|
||||
jlib,
|
||||
@@ -74,19 +71,13 @@
|
||||
mod_echo,
|
||||
mod_http_bind,
|
||||
mod_http_fileserver,
|
||||
mod_irc,
|
||||
mod_irc_connection,
|
||||
mod_last,
|
||||
mod_last_odbc,
|
||||
mod_muc,
|
||||
mod_muc_log,
|
||||
mod_muc_room,
|
||||
mod_offline,
|
||||
mod_offline_odbc,
|
||||
mod_privacy,
|
||||
mod_privacy_odbc,
|
||||
mod_private,
|
||||
mod_private_odbc,
|
||||
mod_proxy65,
|
||||
mod_proxy65_lib,
|
||||
mod_proxy65_service,
|
||||
@@ -95,14 +86,12 @@
|
||||
mod_pubsub,
|
||||
mod_register,
|
||||
mod_roster,
|
||||
mod_roster_odbc,
|
||||
mod_service_log,
|
||||
mod_shared_roster,
|
||||
mod_stats,
|
||||
mod_time,
|
||||
mod_vcard,
|
||||
mod_vcard_ldap,
|
||||
mod_vcard_odbc,
|
||||
mod_version,
|
||||
node_buddy,
|
||||
node_club,
|
||||
@@ -124,13 +113,13 @@
|
||||
tls,
|
||||
translate,
|
||||
xml,
|
||||
xml_stream,
|
||||
'XmppAddr'
|
||||
]},
|
||||
{registered, [ejabberd,
|
||||
ejabberd_sup,
|
||||
ejabberd_auth,
|
||||
ejabberd_router,
|
||||
ejabberd_router_multicast,
|
||||
ejabberd_sm,
|
||||
ejabberd_s2s,
|
||||
ejabberd_local,
|
||||
@@ -143,7 +132,6 @@
|
||||
ejabberd_mod_roster,
|
||||
ejabberd_mod_echo,
|
||||
ejabberd_mod_pubsub,
|
||||
ejabberd_mod_irc,
|
||||
ejabberd_mod_muc,
|
||||
ejabberd_offline,
|
||||
random_generator
|
||||
|
||||
@@ -80,14 +80,24 @@
|
||||
%%{watchdog_admins, ["bob@example.com"]}.
|
||||
|
||||
|
||||
%%%. =====================
|
||||
%%%' CLUSTER CONFIGURATION
|
||||
|
||||
%% clusterid: the integer id of the cluster of nodes this node will
|
||||
%% belong to.
|
||||
{clusterid, 1}.
|
||||
|
||||
|
||||
%%%. ================
|
||||
%%%' SERVED HOSTNAMES
|
||||
|
||||
%%
|
||||
%% hosts: Domains served by ejabberd.
|
||||
%% You can define one or several, for example:
|
||||
%% {hosts, ["example.net", "example.com", "example.org"]}.
|
||||
%% {hosts, ["localhost", "example.net", "example.com", "example.org"]}.
|
||||
%%
|
||||
%% Additional hosts will be discovered from the 'hosts' database table
|
||||
%% configured for the first host.
|
||||
{hosts, ["localhost"]}.
|
||||
|
||||
%%
|
||||
@@ -162,7 +172,6 @@
|
||||
captcha,
|
||||
http_bind,
|
||||
http_poll,
|
||||
%%register,
|
||||
web_admin
|
||||
]}
|
||||
|
||||
@@ -170,10 +179,10 @@
|
||||
|
||||
%%
|
||||
%% s2s_use_starttls: Enable STARTTLS + Dialback for S2S connections.
|
||||
%% Allowed values are: false optional required required_trusted
|
||||
%% Allowed values are: true or false.
|
||||
%% You must specify a certificate file.
|
||||
%%
|
||||
%%{s2s_use_starttls, optional}.
|
||||
%%{s2s_use_starttls, true}.
|
||||
|
||||
%%
|
||||
%% s2s_certfile: Specify a certificate file.
|
||||
@@ -213,11 +222,19 @@
|
||||
|
||||
%%
|
||||
%% auth_method: Method used to authenticate the users.
|
||||
%% The default method is the internal.
|
||||
%% The default method is the internal Mnesia database storage.
|
||||
%% If you want to use a different method,
|
||||
%% comment this line and enable the correct ones.
|
||||
%% comment those lines and enable the desired lines later.
|
||||
%%
|
||||
{auth_method, internal}.
|
||||
{auth_method, storage}.
|
||||
{auth_storage, mnesia}.
|
||||
|
||||
%%
|
||||
%% Authentication using ODBC
|
||||
%% Remember to setup a database in the next section.
|
||||
%%
|
||||
%%{auth_method, storage}.
|
||||
%%{auth_storage, odbc}.
|
||||
|
||||
%%
|
||||
%% Authentication using external script
|
||||
@@ -226,12 +243,6 @@
|
||||
%%{auth_method, external}.
|
||||
%%{extauth_program, "/path/to/authentication/script"}.
|
||||
|
||||
%%
|
||||
%% Authentication using ODBC
|
||||
%% Remember to setup a database in the next section.
|
||||
%%
|
||||
%%{auth_method, odbc}.
|
||||
|
||||
%%
|
||||
%% Authentication using PAM
|
||||
%%
|
||||
@@ -293,22 +304,32 @@
|
||||
%% you want to use other database backends.
|
||||
%% Please consult the ejabberd Guide for details on database creation.
|
||||
|
||||
%% Template host ODBC configuration.
|
||||
%% The host specified here will be used by default for all discovered vhosts.
|
||||
%% The actual ODBC server configuration must be provided in a host_config directive.
|
||||
{odbc_server, {host, "localhost"}}.
|
||||
|
||||
{host_config, "localhost",
|
||||
[
|
||||
%%
|
||||
%% MySQL server:
|
||||
%%
|
||||
%%{odbc_server, {mysql, "server", "database", "username", "password"}}.
|
||||
%%{odbc_server, {mysql, "server", "database", "username", "password"}}
|
||||
%%
|
||||
%% If you want to specify the port:
|
||||
%%{odbc_server, {mysql, "server", 1234, "database", "username", "password"}}.
|
||||
%%{odbc_server, {mysql, "server", 1234, "database", "username", "password"}}
|
||||
|
||||
%%
|
||||
%% PostgreSQL server:
|
||||
%%
|
||||
%%{odbc_server, {pgsql, "server", "database", "username", "password"}}.
|
||||
%%{odbc_server, {pgsql, "server", "database", "username", "password"}}
|
||||
%%
|
||||
%% If you want to specify the port:
|
||||
%%{odbc_server, {pgsql, "server", 1234, "database", "username", "password"}}.
|
||||
%%{odbc_server, {pgsql, "server", 1234, "database", "username", "password"}}
|
||||
%%
|
||||
]
|
||||
}.
|
||||
|
||||
%% If you use PostgreSQL, have a large database, and need a
|
||||
%% faster but inexact replacement for "select count(*) from users"
|
||||
%%
|
||||
@@ -450,6 +471,20 @@
|
||||
%%}.
|
||||
|
||||
|
||||
%%%. =======
|
||||
%%%' CAPTCHA
|
||||
|
||||
%%
|
||||
%% Full path to a script that generates the image.
|
||||
%%
|
||||
%%{captcha_cmd, "/lib/ejabberd/priv/bin/captcha.sh"}.
|
||||
|
||||
%%
|
||||
%% Host part of the URL sent to the user.
|
||||
%%
|
||||
%%{captcha_host, "example.org:5280"}.
|
||||
|
||||
|
||||
%%%. ================
|
||||
%%%' DEFAULT LANGUAGE
|
||||
|
||||
@@ -466,72 +501,50 @@
|
||||
%%}.
|
||||
|
||||
|
||||
%%%. =======
|
||||
%%%' CAPTCHA
|
||||
%%%. ================
|
||||
%%%' INSTANCE MODULES
|
||||
|
||||
%%
|
||||
%% Full path to a script that generates the image.
|
||||
%% Modules to start for every virtual host.
|
||||
%%
|
||||
%%{captcha_cmd, "/lib/ejabberd/priv/bin/captcha.sh"}.
|
||||
|
||||
%%
|
||||
%% Host part of the URL sent to the user.
|
||||
%%
|
||||
%%{captcha_host, "example.org:5280"}.
|
||||
|
||||
|
||||
%%%. =======
|
||||
%%%' MODULES
|
||||
|
||||
%%
|
||||
%% Modules enabled in all ejabberd virtual hosts.
|
||||
%% Note: One copy of each module will be started for each host.
|
||||
%%
|
||||
{modules,
|
||||
[
|
||||
{mod_adhoc, []},
|
||||
{mod_announce, [{access, announce}]}, % recommends mod_adhoc
|
||||
{mod_caps, []},
|
||||
{mod_caps, []}, % 1 proc/host
|
||||
{mod_configure,[]}, % requires mod_adhoc
|
||||
{mod_disco, []},
|
||||
%%{mod_echo, [{host, "echo.localhost"}]},
|
||||
{mod_irc, []},
|
||||
{mod_http_bind, []},
|
||||
%%{mod_http_fileserver, [
|
||||
%% {docroot, "/var/www"},
|
||||
%% {accesslog, "/var/log/ejabberd/access.log"}
|
||||
%% ]},
|
||||
{mod_last, []},
|
||||
{mod_muc, [
|
||||
%%{host, "conference.@HOST@"},
|
||||
{access, muc},
|
||||
{access_create, muc_create},
|
||||
{access_persistent, muc_create},
|
||||
{access_admin, muc_admin}
|
||||
]},
|
||||
{mod_muc, [ % 1 proc/host
|
||||
{host, "conference.@HOST@"},
|
||||
{access, muc},
|
||||
{access_create, muc_create},
|
||||
{access_persistent, muc_create},
|
||||
{access_admin, muc_admin}
|
||||
]},
|
||||
%%{mod_muc_log,[]},
|
||||
%%{mod_multicast,[]},
|
||||
{mod_offline, [{access_max_user_messages, max_user_offline_messages}]},
|
||||
{mod_ping, []},
|
||||
{mod_privacy, []},
|
||||
{mod_private, []},
|
||||
%%{mod_proxy65,[]},
|
||||
{mod_pubsub, [
|
||||
{access_createnode, pubsub_createnode},
|
||||
{ignore_pep_from_offline, true}, % reduces resource comsumption, but XEP incompliant
|
||||
%%{ignore_pep_from_offline, false}, % XEP compliant, but increases resource comsumption
|
||||
{last_item_cache, false},
|
||||
{plugins, ["flat", "hometree", "pep"]} % pep requires mod_caps
|
||||
]},
|
||||
%%{mod_pubsub, [ % 1 proc/host
|
||||
%% {access_createnode, pubsub_createnode},
|
||||
%% {ignore_pep_from_offline, true}, % reduces resource comsumption, but XEP incompliant
|
||||
%% %%{ignore_pep_from_offline, false}, % XEP compliant, but increases resource comsumption
|
||||
%% {last_item_cache, false},
|
||||
%% {plugins, ["flat", "pep"]} % pep requires mod_caps
|
||||
%% ]},
|
||||
{mod_register, [
|
||||
%%
|
||||
%% Protect In-Band account registrations with CAPTCHA.
|
||||
%%
|
||||
%%{captcha_protected, true},
|
||||
|
||||
%%
|
||||
%% Set the minimum informational entropy for passwords.
|
||||
%%
|
||||
%%{password_strength, 32},
|
||||
|
||||
%%
|
||||
%% After successful registration, the user receives
|
||||
%% a message with this subject and body.
|
||||
@@ -545,27 +558,35 @@
|
||||
%%
|
||||
%%{registration_watchers, ["admin1@example.org"]},
|
||||
|
||||
{ip_access, [{allow, "127.0.0.0/8"},
|
||||
{deny, "0.0.0.0/0"}]},
|
||||
|
||||
{access, register}
|
||||
]},
|
||||
%%{mod_register_web, [
|
||||
%%
|
||||
%% When a user registers, send a notification to
|
||||
%% these XMPP accounts.
|
||||
%%
|
||||
%%{registration_watchers, ["admin1@example.org"]}
|
||||
%% ]},
|
||||
{mod_roster, []},
|
||||
%%{mod_service_log,[]},
|
||||
{mod_shared_roster,[]},
|
||||
{mod_stats, []},
|
||||
{mod_time, []},
|
||||
{mod_vcard, []},
|
||||
{mod_vcard, []}, % 1 proc/host
|
||||
{mod_version, []}
|
||||
]}.
|
||||
|
||||
|
||||
%%%.
|
||||
%%%' STATIC MODULES
|
||||
|
||||
%%
|
||||
%% Modules to start for the global virtual host ("localhost").
|
||||
%%
|
||||
%% The functionality of these modules will be enabled in all ejabberd
|
||||
%% virtual hosts without consuming more resources.
|
||||
%%
|
||||
{static_modules,
|
||||
[
|
||||
]}.
|
||||
|
||||
|
||||
%%%.
|
||||
%%%' HOST SPECIFIC MODULES
|
||||
|
||||
%%
|
||||
%% Enable modules with custom options in a specific virtual host
|
||||
%%
|
||||
@@ -581,8 +602,6 @@
|
||||
%%%.
|
||||
%%%'
|
||||
|
||||
%%% $Id$
|
||||
|
||||
%%% Local Variables:
|
||||
%%% mode: erlang
|
||||
%%% End:
|
||||
|
||||
@@ -28,8 +28,14 @@
|
||||
-author('alexey@process-one.net').
|
||||
|
||||
-export([start/0, stop/0,
|
||||
get_pid_file/0,
|
||||
get_so_path/0, get_bin_path/0]).
|
||||
get_so_path/0,
|
||||
get_bin_path/0,
|
||||
get_pid_file/0,
|
||||
is_my_host/1,
|
||||
normalize_host/1
|
||||
]).
|
||||
|
||||
-include("ejabberd.hrl").
|
||||
|
||||
start() ->
|
||||
%%ejabberd_cover:start(),
|
||||
@@ -65,6 +71,33 @@ get_bin_path() ->
|
||||
Path
|
||||
end.
|
||||
|
||||
is_my_host([$* | _]) ->
|
||||
false;
|
||||
is_my_host(Host) ->
|
||||
case ejabberd_config:get_local_option({Host, host}) of
|
||||
undefined ->
|
||||
WCHost = re:replace(Host, "^[^.]*\.", "*.", [{return, list}]),
|
||||
case ejabberd_config:get_local_option({WCHost, host}) of
|
||||
undefined ->
|
||||
false;
|
||||
_ ->
|
||||
true
|
||||
end;
|
||||
_ ->
|
||||
true
|
||||
end.
|
||||
|
||||
normalize_host(global) ->
|
||||
global;
|
||||
normalize_host(Host) ->
|
||||
WCHost = re:replace(Host, "^[^.]*\.", "*.", [{return, list}]),
|
||||
case ejabberd_config:get_local_option({WCHost, host}) of
|
||||
undefined ->
|
||||
Host;
|
||||
_ ->
|
||||
WCHost
|
||||
end.
|
||||
|
||||
%% @spec () -> false | string()
|
||||
get_pid_file() ->
|
||||
case os:getenv("EJABBERD_PID_PATH") of
|
||||
|
||||
@@ -23,7 +23,8 @@
|
||||
%% If the ejabberd application description isn't loaded, returns atom: undefined
|
||||
-define(VERSION, element(2, application:get_key(ejabberd,vsn))).
|
||||
|
||||
-define(MYHOSTS, ejabberd_config:get_global_option(hosts)).
|
||||
-define(IS_MY_HOST(Host), ejabberd:is_my_host(Host)).
|
||||
-define(MYHOSTS, ejabberd_config:get_global_option(hosts)). %% Deprecated
|
||||
-define(MYNAME, hd(ejabberd_config:get_global_option(hosts))).
|
||||
-define(MYLANG, ejabberd_config:get_global_option(language)).
|
||||
|
||||
@@ -35,6 +36,8 @@
|
||||
|
||||
-define(S2STIMEOUT, 600000).
|
||||
|
||||
-define(PRIVACY_SUPPORT, true).
|
||||
|
||||
%%-define(DBGFSM, true).
|
||||
|
||||
%% ---------------------------------
|
||||
@@ -58,4 +61,3 @@
|
||||
|
||||
-define(CRITICAL_MSG(Format, Args),
|
||||
ejabberd_logger:critical_msg(?MODULE,?LINE,Format, Args)).
|
||||
|
||||
|
||||
@@ -36,6 +36,9 @@
|
||||
%% Accounts
|
||||
register/3, unregister/2,
|
||||
registered_users/1,
|
||||
%% For debugging gen_storage
|
||||
get_last_info/0,
|
||||
get_last_info/2,
|
||||
%% Migration jabberd1.4
|
||||
import_file/1, import_dir/1,
|
||||
%% Purge DB
|
||||
@@ -124,6 +127,21 @@ commands() ->
|
||||
args = [{host, string}],
|
||||
result = {users, {list, {username, string}}}},
|
||||
|
||||
#ejabberd_commands{name = gli, tags = [accounts],
|
||||
desc = "Get information about last access of an account",
|
||||
module = ?MODULE, function = get_last_info,
|
||||
args = [],
|
||||
result = {lastinfo, {tuple, [{timestamp, integer},
|
||||
{status, string}
|
||||
]}}},
|
||||
#ejabberd_commands{name = get_last_info, tags = [accounts],
|
||||
desc = "Get information about last access of an account",
|
||||
module = ?MODULE, function = get_last_info,
|
||||
args = [{user, string}, {host, string}],
|
||||
result = {lastinfo, {tuple, [{timestamp, integer},
|
||||
{status, string}
|
||||
]}}},
|
||||
|
||||
#ejabberd_commands{name = import_file, tags = [mnesia],
|
||||
desc = "Import user data from jabberd14 spool file",
|
||||
module = ?MODULE, function = import_file,
|
||||
@@ -155,11 +173,6 @@ commands() ->
|
||||
desc = "Delete offline messages older than DAYS",
|
||||
module = ?MODULE, function = delete_old_messages,
|
||||
args = [{days, integer}], result = {res, rescode}},
|
||||
|
||||
#ejabberd_commands{name = rename_default_nodeplugin, tags = [mnesia],
|
||||
desc = "Update PubSub table from old ejabberd trunk SVN to 2.1.0",
|
||||
module = mod_pubsub, function = rename_default_nodeplugin,
|
||||
args = [], result = {res, rescode}},
|
||||
|
||||
#ejabberd_commands{name = set_master, tags = [mnesia],
|
||||
desc = "Set master node of the clustered Mnesia tables",
|
||||
@@ -285,7 +298,8 @@ send_service_message_all_mucs(Subject, AnnouncementText) ->
|
||||
fun(ServerHost) ->
|
||||
MUCHost = gen_mod:get_module_opt_host(
|
||||
ServerHost, mod_muc, "conference.@HOST@"),
|
||||
mod_muc:broadcast_service_message(MUCHost, Message)
|
||||
MUCHostB = list_to_binary(MUCHost),
|
||||
mod_muc:broadcast_service_message(MUCHostB, Message)
|
||||
end,
|
||||
?MYHOSTS).
|
||||
|
||||
@@ -337,6 +351,12 @@ registered_users(Host) ->
|
||||
SUsers = lists:sort(Users),
|
||||
lists:map(fun({U, _S}) -> U end, SUsers).
|
||||
|
||||
get_last_info() -> get_last_info("badlop", "localhost").
|
||||
get_last_info(User, Server) ->
|
||||
case mod_last:get_last_info(User, Server) of
|
||||
{ok, TimeStamp, Status} -> {TimeStamp, Status};
|
||||
not_found -> {"never", ""}
|
||||
end.
|
||||
|
||||
%%%
|
||||
%%% Migration management
|
||||
|
||||
@@ -42,11 +42,10 @@ start(normal, _Args) ->
|
||||
ejabberd_loglevel:set(4),
|
||||
write_pid_file(),
|
||||
application:start(sasl),
|
||||
application:start(exmpp),
|
||||
randoms:start(),
|
||||
db_init(),
|
||||
sha:start(),
|
||||
stringprep_sup:start_link(),
|
||||
xml:start(),
|
||||
start(),
|
||||
translate:start(),
|
||||
acl:start(),
|
||||
@@ -68,6 +67,8 @@ start(normal, _Args) ->
|
||||
%ejabberd_debug:fprof_start(),
|
||||
maybe_add_nameservers(),
|
||||
start_modules(),
|
||||
ejabberd_cluster:announce(),
|
||||
ejabberd_node_groups:start(),
|
||||
ejabberd_listener:start_listeners(),
|
||||
?INFO_MSG("ejabberd ~s is started in the node ~p", [?VERSION, node()]),
|
||||
Sup;
|
||||
@@ -106,19 +107,7 @@ init() ->
|
||||
LogPath = get_log_path(),
|
||||
error_logger:add_report_handler(ejabberd_logger_h, LogPath),
|
||||
erl_ddll:load_driver(ejabberd:get_so_path(), tls_drv),
|
||||
case erl_ddll:load_driver(ejabberd:get_so_path(), expat_erl) of
|
||||
ok -> ok;
|
||||
{error, already_loaded} -> ok
|
||||
end,
|
||||
Port = open_port({spawn, expat_erl}, [binary]),
|
||||
loop(Port).
|
||||
|
||||
|
||||
loop(Port) ->
|
||||
receive
|
||||
_ ->
|
||||
loop(Port)
|
||||
end.
|
||||
ok.
|
||||
|
||||
db_init() ->
|
||||
case mnesia:system_info(extra_db_nodes) of
|
||||
@@ -132,6 +121,15 @@ db_init() ->
|
||||
|
||||
%% Start all the modules in all the hosts
|
||||
start_modules() ->
|
||||
case ejabberd_config:get_local_option({static_modules, global}) of
|
||||
undefined ->
|
||||
ok;
|
||||
StaticModules ->
|
||||
lists:foreach(
|
||||
fun({Module, Args}) ->
|
||||
gen_mod:start_module(global, Module, Args)
|
||||
end, StaticModules)
|
||||
end,
|
||||
lists:foreach(
|
||||
fun(Host) ->
|
||||
case ejabberd_config:get_local_option({modules, Host}) of
|
||||
|
||||
@@ -49,66 +49,122 @@
|
||||
is_user_exists_in_other_modules/3,
|
||||
remove_user/2,
|
||||
remove_user/3,
|
||||
plain_password_required/1,
|
||||
entropy/1
|
||||
plain_password_required/1
|
||||
]).
|
||||
|
||||
-export([start/1
|
||||
,start_module/2
|
||||
,stop_module/2
|
||||
,start_modules/2
|
||||
,start_method/2
|
||||
,stop_method/2
|
||||
,start_methods/2
|
||||
]).
|
||||
|
||||
-export([auth_modules/1]).
|
||||
|
||||
-include("ejabberd.hrl").
|
||||
|
||||
%% @type authmodule() = ejabberd_auth_anonymous | ejabberd_auth_external |
|
||||
%% ejabberd_auth_ldap | ejabberd_auth_pam |
|
||||
%% ejabberd_auth_storage | atom().
|
||||
|
||||
%%%----------------------------------------------------------------------
|
||||
%%% API
|
||||
%%%----------------------------------------------------------------------
|
||||
start() ->
|
||||
lists:foreach(
|
||||
fun(Host) ->
|
||||
lists:foreach(
|
||||
fun(M) ->
|
||||
M:start(Host)
|
||||
end, auth_modules(Host))
|
||||
end, ?MYHOSTS).
|
||||
|
||||
plain_password_required(Server) ->
|
||||
%% @spec () -> term()
|
||||
|
||||
start() ->
|
||||
?DEBUG("About to start auth modules. Hosts: ~p", ?MYHOSTS),
|
||||
lists:foreach(fun start/1, ?MYHOSTS).
|
||||
|
||||
start(Host) ->
|
||||
start_modules(Host, auth_modules(Host)).
|
||||
|
||||
start_modules(Host, Modules) when is_list(Modules) ->
|
||||
lists:foreach(fun (M) -> start_module(Host, M) end, Modules).
|
||||
start_module(Host, Module) when is_atom(Module) ->
|
||||
Module:start(Host).
|
||||
stop_module(Host, Module) when is_atom(Module) ->
|
||||
Module:stop(Host).
|
||||
|
||||
start_methods(Host, Methods) when is_list(Methods) ->
|
||||
lists:foreach(fun (M) -> start_method(Host, M) end, Methods).
|
||||
start_method(Host, Method) when is_atom(Method) ->
|
||||
start_module(Host, module_name(Method)).
|
||||
stop_method(Host, Method) when is_atom(Method) ->
|
||||
stop_module(Host, module_name(Method)).
|
||||
|
||||
|
||||
%% @spec (Server) -> bool()
|
||||
%% Server = string()
|
||||
|
||||
plain_password_required(Server) when is_list(Server) ->
|
||||
lists:any(
|
||||
fun(M) ->
|
||||
M:plain_password_required()
|
||||
end, auth_modules(Server)).
|
||||
|
||||
%% @spec (User, Server, Password) -> bool()
|
||||
%% User = string()
|
||||
%% Server = string()
|
||||
%% Password = string()
|
||||
%% @doc Check if the user and password can login in server.
|
||||
%% @spec (User::string(), Server::string(), Password::string()) ->
|
||||
%% true | false
|
||||
check_password(User, Server, Password) ->
|
||||
|
||||
check_password(User, Server, Password)
|
||||
when is_list(User), is_list(Server), is_list(Password) ->
|
||||
case check_password_with_authmodule(User, Server, Password) of
|
||||
{true, _AuthModule} -> true;
|
||||
false -> false
|
||||
end.
|
||||
|
||||
%% @spec (User, Server, Password, Digest, DigestGen) -> bool()
|
||||
%% User = string()
|
||||
%% Server = string()
|
||||
%% Password = string()
|
||||
%% Digest = string()
|
||||
%% DigestGen = function()
|
||||
%% @doc Check if the user and password can login in server.
|
||||
%% @spec (User::string(), Server::string(), Password::string(),
|
||||
%% Digest::string(), DigestGen::function()) ->
|
||||
%% true | false
|
||||
check_password(User, Server, Password, Digest, DigestGen) ->
|
||||
|
||||
check_password(User, Server, Password, Digest, DigestGen)
|
||||
when is_list(User), is_list(Server), is_list(Password),
|
||||
is_list(Digest), is_function(DigestGen) ->
|
||||
case check_password_with_authmodule(User, Server, Password,
|
||||
Digest, DigestGen) of
|
||||
{true, _AuthModule} -> true;
|
||||
false -> false
|
||||
end.
|
||||
|
||||
%% @spec (User, Server, Password) -> {true, AuthModule} | false
|
||||
%% User = string()
|
||||
%% Server = string()
|
||||
%% Password = string()
|
||||
%% AuthModule = authmodule()
|
||||
%% @doc Check if the user and password can login in server.
|
||||
%% The user can login if at least an authentication method accepts the user
|
||||
%% and the password.
|
||||
%% The first authentication method that accepts the credentials is returned.
|
||||
%% @spec (User::string(), Server::string(), Password::string()) ->
|
||||
%% {true, AuthModule} | false
|
||||
%% where
|
||||
%% AuthModule = ejabberd_auth_anonymous | ejabberd_auth_external
|
||||
%% | ejabberd_auth_internal | ejabberd_auth_ldap
|
||||
%% | ejabberd_auth_odbc | ejabberd_auth_pam
|
||||
check_password_with_authmodule(User, Server, Password) ->
|
||||
|
||||
check_password_with_authmodule(User, Server, Password)
|
||||
when is_list(User), is_list(Server), is_list(Password) ->
|
||||
check_password_loop(auth_modules(Server), [User, Server, Password]).
|
||||
|
||||
check_password_with_authmodule(User, Server, Password, Digest, DigestGen) ->
|
||||
%% @spec (User, Server, Password, Digest, DigestGen) -> {true, AuthModule} | false
|
||||
%% User = string()
|
||||
%% Server = string()
|
||||
%% Password = string() | undefined
|
||||
%% Digest = string() | undefined
|
||||
%% DigestGen = function()
|
||||
%% AuthModule = authmodule()
|
||||
%% @doc Check the password is valid and also return the authentication module that accepts it.
|
||||
%% The password is 'undefined' if the client
|
||||
%% authenticates using the digest method as defined in
|
||||
%% XEP-0078: Non-SASL Authentication
|
||||
|
||||
check_password_with_authmodule(User, Server, Password, Digest, DigestGen)
|
||||
when is_list(User), is_list(Server), (is_list(Password) orelse Password == 'undefined'),
|
||||
is_function(DigestGen), (is_list(Digest) orelse Digest == 'undefined')->
|
||||
check_password_loop(auth_modules(Server), [User, Server, Password,
|
||||
Digest, DigestGen]).
|
||||
|
||||
@@ -122,14 +178,16 @@ check_password_loop([AuthModule | AuthModules], Args) ->
|
||||
check_password_loop(AuthModules, Args)
|
||||
end.
|
||||
|
||||
|
||||
%% @spec (User::string(), Server::string(), Password::string()) ->
|
||||
%% ok | {error, ErrorType}
|
||||
%% where ErrorType = empty_password | not_allowed | invalid_jid
|
||||
%% @spec (User, Server, Password) -> ok | {error, ErrorType}
|
||||
%% User = string()
|
||||
%% Server = string()
|
||||
%% Password = string()
|
||||
%% ErrorType = empty_password | not_allowed | invalid_jid
|
||||
set_password(_User, _Server, "") ->
|
||||
%% We do not allow empty password
|
||||
{error, empty_password};
|
||||
set_password(User, Server, Password) ->
|
||||
set_password(User, Server, Password)
|
||||
when is_list(User), is_list(Server), is_list(Password) ->
|
||||
lists:foldl(
|
||||
fun(M, {error, _}) ->
|
||||
M:set_password(User, Server, Password);
|
||||
@@ -138,61 +196,87 @@ set_password(User, Server, Password) ->
|
||||
end, {error, not_allowed}, auth_modules(Server)).
|
||||
|
||||
%% @spec (User, Server, Password) -> {atomic, ok} | {atomic, exists} | {error, not_allowed}
|
||||
%% User = string()
|
||||
%% Server = string()
|
||||
%% Password = string() | nil()
|
||||
try_register(_User, _Server, "") ->
|
||||
%% We do not allow empty password
|
||||
{error, not_allowed};
|
||||
try_register(User, Server, Password) ->
|
||||
case is_user_exists(User,Server) of
|
||||
{error, not_allowed};
|
||||
try_register(User, Server, Password)
|
||||
when is_list(User), is_list(Server), is_list(Password) ->
|
||||
case is_user_exists(User, Server) of
|
||||
true ->
|
||||
{atomic, exists};
|
||||
false ->
|
||||
case lists:member(jlib:nameprep(Server), ?MYHOSTS) of
|
||||
case ?IS_MY_HOST(exmpp_stringprep:nameprep(Server)) of
|
||||
true ->
|
||||
Res = lists:foldl(
|
||||
fun(_M, {atomic, ok} = Res) ->
|
||||
Res;
|
||||
(M, _) ->
|
||||
M:try_register(User, Server, Password)
|
||||
end, {error, not_allowed}, auth_modules(Server)),
|
||||
case Res of
|
||||
{atomic, ok} ->
|
||||
ejabberd_hooks:run(register_user, Server,
|
||||
[User, Server]),
|
||||
{atomic, ok};
|
||||
_ -> Res
|
||||
end;
|
||||
fun (_M, {atomic, ok} = Res) ->
|
||||
Res;
|
||||
(M, _) ->
|
||||
M:try_register(User, Server, Password)
|
||||
end, {error, not_allowed}, auth_modules(Server)),
|
||||
trigger_register_hooks(Res, User, Server);
|
||||
false ->
|
||||
{error, not_allowed}
|
||||
end
|
||||
end.
|
||||
|
||||
%% Registered users list do not include anonymous users logged
|
||||
trigger_register_hooks({atomic, ok} = Res, User, Server) ->
|
||||
ejabberd_hooks:run(register_user, list_to_binary(Server),
|
||||
[User, Server]),
|
||||
Res;
|
||||
trigger_register_hooks(Res, _User, _Server) ->
|
||||
Res.
|
||||
|
||||
%% @spec () -> [{LUser, LServer}]
|
||||
%% LUser = string()
|
||||
%% LServer = string()
|
||||
%% @doc Registered users list do not include anonymous users logged.
|
||||
|
||||
dirty_get_registered_users() ->
|
||||
lists:flatmap(
|
||||
fun(M) ->
|
||||
M:dirty_get_registered_users()
|
||||
end, auth_modules()).
|
||||
|
||||
%% Registered users list do not include anonymous users logged
|
||||
get_vh_registered_users(Server) ->
|
||||
%% @spec (Server) -> [{LUser, LServer}]
|
||||
%% Server = string()
|
||||
%% LUser = string()
|
||||
%% LServer = string()
|
||||
%% @doc Registered users list do not include anonymous users logged.
|
||||
|
||||
get_vh_registered_users(Server) when is_list(Server) ->
|
||||
lists:flatmap(
|
||||
fun(M) ->
|
||||
M:get_vh_registered_users(Server)
|
||||
end, auth_modules(Server)).
|
||||
|
||||
get_vh_registered_users(Server, Opts) ->
|
||||
%% @spec (Server, Opts) -> [{LUser, LServer}]
|
||||
%% Server = string()
|
||||
%% Opts = [{Opt, Val}]
|
||||
%% Opt = atom()
|
||||
%% Val = term()
|
||||
%% LUser = string()
|
||||
%% LServer = string()
|
||||
|
||||
get_vh_registered_users(Server, Opts) when is_list(Server) ->
|
||||
lists:flatmap(
|
||||
fun(M) ->
|
||||
case erlang:function_exported(
|
||||
M, get_vh_registered_users, 2) of
|
||||
M, get_vh_registered_users_number, 2) of
|
||||
true ->
|
||||
M:get_vh_registered_users(Server, Opts);
|
||||
M:get_vh_registered_users_number(Server, Opts);
|
||||
false ->
|
||||
M:get_vh_registered_users(Server)
|
||||
M:get_vh_registered_users_number(Server)
|
||||
end
|
||||
end, auth_modules(Server)).
|
||||
|
||||
get_vh_registered_users_number(Server) ->
|
||||
%% @spec (Server) -> Users_Number
|
||||
%% Server = string()
|
||||
%% Users_Number = integer()
|
||||
|
||||
get_vh_registered_users_number(Server) when is_list(Server) ->
|
||||
lists:sum(
|
||||
lists:map(
|
||||
fun(M) ->
|
||||
@@ -205,7 +289,14 @@ get_vh_registered_users_number(Server) ->
|
||||
end
|
||||
end, auth_modules(Server))).
|
||||
|
||||
get_vh_registered_users_number(Server, Opts) ->
|
||||
%% @spec (Server, Opts) -> Users_Number
|
||||
%% Server = string()
|
||||
%% Opts = [{Opt, Val}]
|
||||
%% Opt = atom()
|
||||
%% Val = term()
|
||||
%% Users_Number = integer()
|
||||
|
||||
get_vh_registered_users_number(Server, Opts) when is_list(Server) ->
|
||||
lists:sum(
|
||||
lists:map(
|
||||
fun(M) ->
|
||||
@@ -218,9 +309,13 @@ get_vh_registered_users_number(Server, Opts) ->
|
||||
end
|
||||
end, auth_modules(Server))).
|
||||
|
||||
%% @spec (User, Server) -> Password | false
|
||||
%% User = string()
|
||||
%% Server = string()
|
||||
%% Password = string()
|
||||
%% @doc Get the password of the user.
|
||||
%% @spec (User::string(), Server::string()) -> Password::string()
|
||||
get_password(User, Server) ->
|
||||
|
||||
get_password(User, Server) when is_list(User), is_list(Server) ->
|
||||
lists:foldl(
|
||||
fun(M, false) ->
|
||||
M:get_password(User, Server);
|
||||
@@ -228,7 +323,13 @@ get_password(User, Server) ->
|
||||
Password
|
||||
end, false, auth_modules(Server)).
|
||||
|
||||
get_password_s(User, Server) ->
|
||||
%% @spec (User, Server) -> Password | nil()
|
||||
%% User = string()
|
||||
%% Server = string()
|
||||
%% Password = string()
|
||||
%% @doc Get the password of the user.
|
||||
|
||||
get_password_s(User, Server) when is_list(User), is_list(Server) ->
|
||||
case get_password(User, Server) of
|
||||
false ->
|
||||
"";
|
||||
@@ -236,10 +337,15 @@ get_password_s(User, Server) ->
|
||||
Password
|
||||
end.
|
||||
|
||||
%% @spec (User, Server) -> {Password, AuthModule} | {false, none}
|
||||
%% User = string()
|
||||
%% Server = string()
|
||||
%% Password = string()
|
||||
%% AuthModule = authmodule()
|
||||
%% @doc Get the password of the user and the auth module.
|
||||
%% @spec (User::string(), Server::string()) ->
|
||||
%% {Password::string(), AuthModule::atom()} | {false, none}
|
||||
get_password_with_authmodule(User, Server) ->
|
||||
|
||||
get_password_with_authmodule(User, Server)
|
||||
when is_list(User), is_list(Server) ->
|
||||
lists:foldl(
|
||||
fun(M, {false, _}) ->
|
||||
{M:get_password(User, Server), M};
|
||||
@@ -247,9 +353,13 @@ get_password_with_authmodule(User, Server) ->
|
||||
{Password, AuthModule}
|
||||
end, {false, none}, auth_modules(Server)).
|
||||
|
||||
%% Returns true if the user exists in the DB or if an anonymous user is logged
|
||||
%% under the given name
|
||||
is_user_exists(User, Server) ->
|
||||
%% @spec (User, Server) -> bool()
|
||||
%% User = string()
|
||||
%% Server = string()
|
||||
%% @doc Returns true if the user exists in the DB or if an anonymous
|
||||
%% user is logged under the given name.
|
||||
|
||||
is_user_exists(User, Server) when is_list(User), is_list(Server) ->
|
||||
lists:any(
|
||||
fun(M) ->
|
||||
case M:is_user_exists(User, Server) of
|
||||
@@ -264,10 +374,15 @@ is_user_exists(User, Server) ->
|
||||
end
|
||||
end, auth_modules(Server)).
|
||||
|
||||
%% Check if the user exists in all authentications module except the module
|
||||
%% passed as parameter
|
||||
%% @spec (Module::atom(), User, Server) -> true | false | maybe
|
||||
is_user_exists_in_other_modules(Module, User, Server) ->
|
||||
%% @spec (Module, User, Server) -> true | false | maybe
|
||||
%% Module = authmodule()
|
||||
%% User = string()
|
||||
%% Server = string()
|
||||
%% @doc Check if the user exists in all authentications module except
|
||||
%% the module passed as parameter.
|
||||
|
||||
is_user_exists_in_other_modules(Module, User, Server)
|
||||
when is_list(User), is_list(Server) ->
|
||||
is_user_exists_in_other_modules_loop(
|
||||
auth_modules(Server)--[Module],
|
||||
User, Server).
|
||||
@@ -288,25 +403,33 @@ is_user_exists_in_other_modules_loop([AuthModule|AuthModules], User, Server) ->
|
||||
|
||||
|
||||
%% @spec (User, Server) -> ok | error | {error, not_allowed}
|
||||
%% User = string()
|
||||
%% Server = string()
|
||||
%% @doc Remove user.
|
||||
%% Note: it may return ok even if there was some problem removing the user.
|
||||
remove_user(User, Server) ->
|
||||
%% TODO: Fix me: It always return ok even if there was some problem removing the user.
|
||||
%% dialyzer warning
|
||||
%% ejabberd_auth.erl:388: The variable _ can never match since previous clauses completely covered the type 'ok'
|
||||
|
||||
remove_user(User, Server) when is_list(User), is_list(Server) ->
|
||||
R = lists:foreach(
|
||||
fun(M) ->
|
||||
M:remove_user(User, Server)
|
||||
end, auth_modules(Server)),
|
||||
case R of
|
||||
ok -> ejabberd_hooks:run(remove_user, jlib:nameprep(Server), [User, Server]);
|
||||
_ -> none
|
||||
end,
|
||||
fun(M) ->
|
||||
M:remove_user(User, Server)
|
||||
end, auth_modules(Server)),
|
||||
ejabberd_hooks:run(remove_user, list_to_binary(exmpp_stringprep:nameprep(Server)),
|
||||
[list_to_binary(User), list_to_binary(Server)]),
|
||||
R.
|
||||
|
||||
%% @spec (User, Server, Password) -> ok | not_exists | not_allowed | bad_request | error
|
||||
%% User = string()
|
||||
%% Server = string()
|
||||
%% Password = string()
|
||||
%% @doc Try to remove user if the provided password is correct.
|
||||
%% The removal is attempted in each auth method provided:
|
||||
%% when one returns 'ok' the loop stops;
|
||||
%% if no method returns 'ok' then it returns the error message indicated by the last method attempted.
|
||||
remove_user(User, Server, Password) ->
|
||||
|
||||
remove_user(User, Server, Password)
|
||||
when is_list(User), is_list(Server), is_list(Password) ->
|
||||
R = lists:foldl(
|
||||
fun(_M, ok = Res) ->
|
||||
Res;
|
||||
@@ -314,40 +437,21 @@ remove_user(User, Server, Password) ->
|
||||
M:remove_user(User, Server, Password)
|
||||
end, error, auth_modules(Server)),
|
||||
case R of
|
||||
ok -> ejabberd_hooks:run(remove_user, jlib:nameprep(Server), [User, Server]);
|
||||
ok -> ejabberd_hooks:run(remove_user, list_to_binary(exmpp_stringprep:nameprep(Server)),
|
||||
[list_to_binary(User), list_to_binary(Server)]);
|
||||
_ -> none
|
||||
end,
|
||||
R.
|
||||
|
||||
%% @spec (IOList) -> non_negative_float()
|
||||
%% @doc Calculate informational entropy.
|
||||
entropy(IOList) ->
|
||||
case binary_to_list(iolist_to_binary(IOList)) of
|
||||
"" ->
|
||||
0.0;
|
||||
S ->
|
||||
Set = lists:foldl(
|
||||
fun(C, [Digit, Printable, LowLetter, HiLetter, Other]) ->
|
||||
if C >= $a, C =< $z ->
|
||||
[Digit, Printable, 26, HiLetter, Other];
|
||||
C >= $0, C =< $9 ->
|
||||
[9, Printable, LowLetter, HiLetter, Other];
|
||||
C >= $A, C =< $Z ->
|
||||
[Digit, Printable, LowLetter, 26, Other];
|
||||
C >= 16#21, C =< 16#7e ->
|
||||
[Digit, 33, LowLetter, HiLetter, Other];
|
||||
true ->
|
||||
[Digit, Printable, LowLetter, HiLetter, 128]
|
||||
end
|
||||
end, [0, 0, 0, 0, 0], S),
|
||||
length(S) * math:log(lists:sum(Set))/math:log(2)
|
||||
end.
|
||||
|
||||
%%%----------------------------------------------------------------------
|
||||
%%% Internal functions
|
||||
%%%----------------------------------------------------------------------
|
||||
%% Return the lists of all the auth modules actually used in the
|
||||
%% configuration
|
||||
|
||||
%% @spec () -> [authmodule()]
|
||||
%% @doc Return the lists of all the auth modules actually used in the
|
||||
%% configuration.
|
||||
|
||||
auth_modules() ->
|
||||
lists:usort(
|
||||
lists:flatmap(
|
||||
@@ -355,13 +459,19 @@ auth_modules() ->
|
||||
auth_modules(Server)
|
||||
end, ?MYHOSTS)).
|
||||
|
||||
%% Return the list of authenticated modules for a given host
|
||||
auth_modules(Server) ->
|
||||
LServer = jlib:nameprep(Server),
|
||||
Method = ejabberd_config:get_local_option({auth_method, LServer}),
|
||||
%% @spec (Server) -> [authmodule()]
|
||||
%% Server = string()
|
||||
%% @doc Return the list of authenticated modules for a given host.
|
||||
|
||||
auth_modules(Server) when is_list(Server) ->
|
||||
LServer = exmpp_stringprep:nameprep(Server),
|
||||
Method = ejabberd_config:get_local_option({auth_method, ejabberd:normalize_host(LServer)}),
|
||||
Methods = if
|
||||
Method == undefined -> [];
|
||||
is_list(Method) -> Method;
|
||||
is_atom(Method) -> [Method]
|
||||
end,
|
||||
[list_to_atom("ejabberd_auth_" ++ atom_to_list(M)) || M <- Methods].
|
||||
[module_name(M) || M <- Methods].
|
||||
|
||||
module_name(Method) when is_atom(Method) ->
|
||||
list_to_atom("ejabberd_auth_" ++ atom_to_list(Method)).
|
||||
|
||||
@@ -53,31 +53,46 @@
|
||||
remove_user/3,
|
||||
plain_password_required/0]).
|
||||
|
||||
-include_lib("exmpp/include/exmpp.hrl").
|
||||
|
||||
-include("ejabberd.hrl").
|
||||
-include("jlib.hrl").
|
||||
-record(anonymous, {us, sid}).
|
||||
|
||||
%% Create the anonymous table if at least one virtual host has anonymous features enabled
|
||||
%% Register to login / logout events
|
||||
start(Host) ->
|
||||
%% @spec (Host) -> ok
|
||||
%% Host = string()
|
||||
%% @doc Create the anonymous table if at least one virtual host has
|
||||
%% anonymous features enabled.
|
||||
%% Register to login / logout events.
|
||||
|
||||
start(Host) when is_list(Host) ->
|
||||
HostB = list_to_binary(Host),
|
||||
%% TODO: Check cluster mode
|
||||
update_tables(),
|
||||
mnesia:create_table(anonymous, [{ram_copies, [node()]},
|
||||
{type, bag},
|
||||
{attributes, record_info(fields, anonymous)}]),
|
||||
{type, bag}, {local_content, true},
|
||||
{attributes, record_info(fields, anonymous)}]),
|
||||
mnesia:add_table_copy(anonymous, node(), ram_copies),
|
||||
%% The hooks are needed to add / remove users from the anonymous tables
|
||||
ejabberd_hooks:add(sm_register_connection_hook, Host,
|
||||
ejabberd_hooks:add(sm_register_connection_hook, HostB,
|
||||
?MODULE, register_connection, 100),
|
||||
ejabberd_hooks:add(sm_remove_connection_hook, Host,
|
||||
ejabberd_hooks:add(sm_remove_connection_hook, HostB,
|
||||
?MODULE, unregister_connection, 100),
|
||||
ok.
|
||||
|
||||
%% Return true if anonymous is allowed for host or false otherwise
|
||||
allow_anonymous(Host) ->
|
||||
%% @spec (Host) -> bool()
|
||||
%% Host = string()
|
||||
%% @doc Return true if anonymous is allowed for host or false otherwise.
|
||||
|
||||
allow_anonymous(Host) when is_list(Host) ->
|
||||
lists:member(?MODULE, ejabberd_auth:auth_modules(Host)).
|
||||
|
||||
%% Return true if anonymous mode is enabled and if anonymous protocol is SASL
|
||||
%% anonymous protocol can be: sasl_anon|login_anon|both
|
||||
is_sasl_anonymous_enabled(Host) ->
|
||||
%% @spec (Host) -> bool()
|
||||
%% Host = string()
|
||||
%% @doc Return true if anonymous mode is enabled and if anonymous
|
||||
%% protocol is SASL anonymous.
|
||||
%% protocol can be: sasl_anon|login_anon|both
|
||||
|
||||
is_sasl_anonymous_enabled(Host) when is_list(Host) ->
|
||||
case allow_anonymous(Host) of
|
||||
false -> false;
|
||||
true ->
|
||||
@@ -88,10 +103,13 @@ is_sasl_anonymous_enabled(Host) ->
|
||||
end
|
||||
end.
|
||||
|
||||
%% Return true if anonymous login is enabled on the server
|
||||
%% @spec (Host) -> bool()
|
||||
%% Host = string()
|
||||
%% @doc Return true if anonymous login is enabled on the server.
|
||||
%% anonymous login can be use using standard authentication method (i.e. with
|
||||
%% clients that do not support anonymous login)
|
||||
is_login_anonymous_enabled(Host) ->
|
||||
|
||||
is_login_anonymous_enabled(Host) when is_list(Host) ->
|
||||
case allow_anonymous(Host) of
|
||||
false -> false;
|
||||
true ->
|
||||
@@ -102,9 +120,12 @@ is_login_anonymous_enabled(Host) ->
|
||||
end
|
||||
end.
|
||||
|
||||
%% Return the anonymous protocol to use: sasl_anon|login_anon|both
|
||||
%% @spec (Host) -> sasl_anon | login_anon | both
|
||||
%% Host = string()
|
||||
%% @doc Return the anonymous protocol to use: sasl_anon|login_anon|both.
|
||||
%% defaults to login_anon
|
||||
anonymous_protocol(Host) ->
|
||||
|
||||
anonymous_protocol(Host) when is_list(Host) ->
|
||||
case ejabberd_config:get_local_option({anonymous_protocol, Host}) of
|
||||
sasl_anon -> sasl_anon;
|
||||
login_anon -> login_anon;
|
||||
@@ -112,16 +133,24 @@ anonymous_protocol(Host) ->
|
||||
_Other -> sasl_anon
|
||||
end.
|
||||
|
||||
%% Return true if multiple connections have been allowed in the config file
|
||||
%% @spec (Host) -> bool()
|
||||
%% Host = string()
|
||||
%% @doc Return true if multiple connections have been allowed in the
|
||||
%% config file.
|
||||
%% defaults to false
|
||||
allow_multiple_connections(Host) ->
|
||||
|
||||
allow_multiple_connections(Host) when is_list(Host) ->
|
||||
ejabberd_config:get_local_option(
|
||||
{allow_multiple_connections, Host}) =:= true.
|
||||
|
||||
%% Check if user exist in the anonymus database
|
||||
anonymous_user_exist(User, Server) ->
|
||||
LUser = jlib:nodeprep(User),
|
||||
LServer = jlib:nameprep(Server),
|
||||
%% @spec (User, Server) -> bool()
|
||||
%% User = string()
|
||||
%% Server = string()
|
||||
%% @doc Check if user exist in the anonymous database.
|
||||
|
||||
anonymous_user_exist(User, Server) when is_list(User), is_list(Server) ->
|
||||
LUser = exmpp_stringprep:nodeprep(User),
|
||||
LServer = exmpp_stringprep:nameprep(Server),
|
||||
US = {LUser, LServer},
|
||||
case catch mnesia:dirty_read({anonymous, US}) of
|
||||
[] ->
|
||||
@@ -130,45 +159,75 @@ anonymous_user_exist(User, Server) ->
|
||||
true
|
||||
end.
|
||||
|
||||
%% Remove connection from Mnesia tables
|
||||
remove_connection(SID, LUser, LServer) ->
|
||||
%% @spec (SID, LUser, LServer) -> term()
|
||||
%% SID = term()
|
||||
%% LUser = string()
|
||||
%% LServer = string()
|
||||
%% @doc Remove connection from Mnesia tables.
|
||||
|
||||
remove_connection(SID, LUser, LServer) when is_list(LUser), is_list(LServer) ->
|
||||
US = {LUser, LServer},
|
||||
F = fun() ->
|
||||
mnesia:delete_object({anonymous, US, SID})
|
||||
end,
|
||||
mnesia:transaction(F).
|
||||
mnesia:async_dirty(F).
|
||||
|
||||
%% Register connection
|
||||
register_connection(SID, #jid{luser = LUser, lserver = LServer}, Info) ->
|
||||
AuthModule = xml:get_attr_s(auth_module, Info),
|
||||
case AuthModule == ?MODULE of
|
||||
true ->
|
||||
%% @spec (SID, JID, Info) -> term()
|
||||
%% SID = term()
|
||||
%% JID = exmpp_jid:jid()
|
||||
%% Info = [term()]
|
||||
%% @doc Register connection.
|
||||
|
||||
register_connection(SID, JID, Info) when ?IS_JID(JID) ->
|
||||
LUser = exmpp_jid:prep_node(JID),
|
||||
LServer = exmpp_jid:prep_domain(JID),
|
||||
case proplists:get_value(auth_module, Info) of
|
||||
undefined ->
|
||||
ok;
|
||||
?MODULE ->
|
||||
ejabberd_hooks:run(register_user, LServer, [LUser, LServer]),
|
||||
US = {LUser, LServer},
|
||||
mnesia:sync_dirty(
|
||||
mnesia:async_dirty(
|
||||
fun() -> mnesia:write(#anonymous{us = US, sid=SID})
|
||||
end);
|
||||
false ->
|
||||
ok
|
||||
_ ->
|
||||
ok
|
||||
end.
|
||||
|
||||
%% Remove an anonymous user from the anonymous users table
|
||||
unregister_connection(SID, #jid{luser = LUser, lserver = LServer}, _) ->
|
||||
%% @spec (SID, JID, Ignored) -> term()
|
||||
%% SID = term()
|
||||
%% JID = exmpp_jid:jid()
|
||||
%% Ignored = term()
|
||||
%% @doc Remove an anonymous user from the anonymous users table.
|
||||
|
||||
unregister_connection(SID, JID, _) when ?IS_JID(JID) ->
|
||||
LUser = exmpp_jid:prep_node_as_list(JID),
|
||||
LServer = exmpp_jid:prep_domain_as_list(JID),
|
||||
purge_hook(anonymous_user_exist(LUser, LServer),
|
||||
LUser, LServer),
|
||||
remove_connection(SID, LUser, LServer).
|
||||
|
||||
%% Launch the hook to purge user data only for anonymous users
|
||||
%% @spec (bool(), LUser, LServer) -> term()
|
||||
%% LUser = string()
|
||||
%% LServer = string()
|
||||
%% @doc Launch the hook to purge user data only for anonymous users.
|
||||
|
||||
purge_hook(false, _LUser, _LServer) ->
|
||||
ok;
|
||||
purge_hook(true, LUser, LServer) ->
|
||||
ejabberd_hooks:run(anonymous_purge_hook, LServer, [LUser, LServer]).
|
||||
purge_hook(true, LUser, LServer) when is_list(LUser), is_list(LServer) ->
|
||||
ejabberd_hooks:run(anonymous_purge_hook, list_to_binary(LServer), [LUser, LServer]).
|
||||
|
||||
%% ---------------------------------
|
||||
%% Specific anonymous auth functions
|
||||
%% ---------------------------------
|
||||
|
||||
%% When anonymous login is enabled, check the password for permenant users
|
||||
%% before allowing access
|
||||
%% @spec (User, Server, Password) -> bool()
|
||||
%% User = string()
|
||||
%% Server = string()
|
||||
%% Password = string()
|
||||
%% @doc When anonymous login is enabled, check the password for
|
||||
%% permenant users before allowing access.
|
||||
|
||||
check_password(User, Server, Password) ->
|
||||
check_password(User, Server, Password, undefined, undefined).
|
||||
check_password(User, Server, _Password, _Digest, _DigestGen) ->
|
||||
@@ -183,6 +242,10 @@ check_password(User, Server, _Password, _Digest, _DigestGen) ->
|
||||
false -> login(User, Server)
|
||||
end.
|
||||
|
||||
%% @spec (User, Server) -> bool()
|
||||
%% User = string()
|
||||
%% Server = string()
|
||||
|
||||
login(User, Server) ->
|
||||
case is_login_anonymous_enabled(Server) of
|
||||
false -> false;
|
||||
@@ -197,8 +260,13 @@ login(User, Server) ->
|
||||
end
|
||||
end.
|
||||
|
||||
%% When anonymous login is enabled, check that the user is permanent before
|
||||
%% changing its password
|
||||
%% @spec (User, Server, Password) -> ok | {error, not_allowed}
|
||||
%% User = string()
|
||||
%% Server = string()
|
||||
%% Password = string()
|
||||
%% @doc When anonymous login is enabled, check that the user is
|
||||
%% permanent before changing its password.
|
||||
|
||||
set_password(User, Server, _Password) ->
|
||||
case anonymous_user_exist(User, Server) of
|
||||
true ->
|
||||
@@ -207,22 +275,41 @@ set_password(User, Server, _Password) ->
|
||||
{error, not_allowed}
|
||||
end.
|
||||
|
||||
%% When anonymous login is enabled, check if permanent users are allowed on
|
||||
%% the server:
|
||||
%% @spec (User, Server, Password) -> {error, not_allowed}
|
||||
%% User = string()
|
||||
%% Server = string()
|
||||
%% Password = string()
|
||||
%% @doc When anonymous login is enabled, check if permanent users are
|
||||
%% allowed on the server:
|
||||
|
||||
try_register(_User, _Server, _Password) ->
|
||||
{error, not_allowed}.
|
||||
|
||||
%% @spec () -> nil()
|
||||
|
||||
dirty_get_registered_users() ->
|
||||
[].
|
||||
|
||||
get_vh_registered_users(_Server) ->
|
||||
[].
|
||||
%% @spec (Server) -> nil()
|
||||
%% Server = string()
|
||||
|
||||
get_vh_registered_users(Server) ->
|
||||
[{U, S} || {U, S, _R} <- ejabberd_sm:get_vh_session_list(list_to_binary(Server))].
|
||||
|
||||
%% @spec (User, Server) -> Password | false
|
||||
%% User = string()
|
||||
%% Server = string()
|
||||
%% Password = nil()
|
||||
%% @doc Return password of permanent user or false for anonymous users.
|
||||
|
||||
%% Return password of permanent user or false for anonymous users
|
||||
get_password(User, Server) ->
|
||||
get_password(User, Server, "").
|
||||
|
||||
%% @spec (User, Server, DefaultValue) -> DefaultValue | false
|
||||
%% User = string()
|
||||
%% Server = string()
|
||||
%% DefaultValue = string()
|
||||
|
||||
get_password(User, Server, DefaultValue) ->
|
||||
case anonymous_user_exist(User, Server) or login(User, Server) of
|
||||
%% We return the default value if the user is anonymous
|
||||
@@ -233,16 +320,39 @@ get_password(User, Server, DefaultValue) ->
|
||||
false
|
||||
end.
|
||||
|
||||
%% Returns true if the user exists in the DB or if an anonymous user is logged
|
||||
%% under the given name
|
||||
%% @spec (User, Server) -> bool()
|
||||
%% User = string()
|
||||
%% Server = string()
|
||||
%% @doc Returns true if the user exists in the DB or if an anonymous
|
||||
%% user is logged under the given name.
|
||||
|
||||
is_user_exists(User, Server) ->
|
||||
anonymous_user_exist(User, Server).
|
||||
|
||||
%% @spec (User, Server) -> {error, not_allowed}
|
||||
%% User = string()
|
||||
%% Server = string()
|
||||
|
||||
remove_user(_User, _Server) ->
|
||||
{error, not_allowed}.
|
||||
|
||||
%% @spec (User, Server, Password) -> {error, not_allowed}
|
||||
%% User = string()
|
||||
%% Server = string()
|
||||
%% Password = string()
|
||||
|
||||
remove_user(_User, _Server, _Password) ->
|
||||
not_allowed.
|
||||
|
||||
%% @spec () -> bool()
|
||||
|
||||
plain_password_required() ->
|
||||
false.
|
||||
|
||||
update_tables() ->
|
||||
case catch mnesia:table_info(anonymous, local_content) of
|
||||
false ->
|
||||
mnesia:delete_table(anonymous);
|
||||
_ ->
|
||||
ok
|
||||
end.
|
||||
|
||||
@@ -51,12 +51,16 @@
|
||||
%%%----------------------------------------------------------------------
|
||||
%%% API
|
||||
%%%----------------------------------------------------------------------
|
||||
|
||||
%% @spec (Host) -> ok
|
||||
%% Host = string()
|
||||
|
||||
start(Host) ->
|
||||
extauth:start(
|
||||
Host, ejabberd_config:get_local_option({extauth_program, Host})),
|
||||
case check_cache_last_options(Host) of
|
||||
cache ->
|
||||
ok = ejabberd_auth_internal:start(Host);
|
||||
ok = ejabberd_auth_storage:start(Host);
|
||||
no_cache ->
|
||||
ok
|
||||
end.
|
||||
@@ -66,7 +70,7 @@ check_cache_last_options(Server) ->
|
||||
case get_cache_option(Server) of
|
||||
false -> no_cache;
|
||||
{true, _CacheTime} ->
|
||||
case get_mod_last_configured(Server) of
|
||||
case get_mod_last_enabled(Server) of
|
||||
no_mod_last ->
|
||||
?ERROR_MSG("In host ~p extauth is used, extauth_cache is enabled but "
|
||||
"mod_last is not enabled.", [Server]),
|
||||
@@ -75,53 +79,93 @@ check_cache_last_options(Server) ->
|
||||
end
|
||||
end.
|
||||
|
||||
%% @spec () -> bool()
|
||||
|
||||
plain_password_required() ->
|
||||
true.
|
||||
|
||||
%% @spec (User, Server, Password) -> bool()
|
||||
%% User = string()
|
||||
%% Server = string()
|
||||
%% Password = string()
|
||||
|
||||
check_password(User, Server, Password) ->
|
||||
case get_cache_option(Server) of
|
||||
false -> check_password_extauth(User, Server, Password);
|
||||
{true, CacheTime} -> check_password_cache(User, Server, Password, CacheTime)
|
||||
end.
|
||||
|
||||
%% @spec (User, Server, Password, Digest, DigestGen) -> bool()
|
||||
%% User = string()
|
||||
%% Server = string()
|
||||
%% Password = string()
|
||||
%% Digest = string()
|
||||
%% DigestGen = function()
|
||||
|
||||
check_password(User, Server, Password, _Digest, _DigestGen) ->
|
||||
check_password(User, Server, Password).
|
||||
|
||||
%% @spec (User, Server, Password) -> ok | {error, unknown_problem}
|
||||
%% User = string()
|
||||
%% Server = string()
|
||||
%% Password = string()
|
||||
|
||||
set_password(User, Server, Password) ->
|
||||
case extauth:set_password(User, Server, Password) of
|
||||
true -> set_password_internal(User, Server, Password),
|
||||
true -> set_password_storage(User, Server, Password),
|
||||
ok;
|
||||
_ -> {error, unknown_problem}
|
||||
end.
|
||||
|
||||
%% @spec (User, Server, Password) -> {error, not_allowed}
|
||||
%% User = string()
|
||||
%% Server = string()
|
||||
%% Password = string()
|
||||
|
||||
try_register(User, Server, Password) ->
|
||||
case get_cache_option(Server) of
|
||||
false -> try_register_extauth(User, Server, Password);
|
||||
{true, _CacheTime} -> try_register_external_cache(User, Server, Password)
|
||||
end.
|
||||
|
||||
%% @spec () -> nil()
|
||||
%% @todo Write it.
|
||||
%% @doc Return the list of all users handled by external.
|
||||
|
||||
dirty_get_registered_users() ->
|
||||
ejabberd_auth_internal:dirty_get_registered_users().
|
||||
ejabberd_auth_storage:dirty_get_registered_users().
|
||||
|
||||
get_vh_registered_users(Server) ->
|
||||
ejabberd_auth_internal:get_vh_registered_users(Server).
|
||||
ejabberd_auth_storage:get_vh_registered_users(Server).
|
||||
|
||||
get_vh_registered_users(Server, Data) ->
|
||||
ejabberd_auth_internal:get_vh_registered_users(Server, Data).
|
||||
ejabberd_auth_storage:get_vh_registered_users(Server, Data).
|
||||
|
||||
%% @spec (Server) -> nil()
|
||||
%% Server = string()
|
||||
|
||||
get_vh_registered_users_number(Server) ->
|
||||
ejabberd_auth_internal:get_vh_registered_users_number(Server).
|
||||
ejabberd_auth_storage:get_vh_registered_users_number(Server).
|
||||
|
||||
get_vh_registered_users_number(Server, Data) ->
|
||||
ejabberd_auth_internal:get_vh_registered_users_number(Server, Data).
|
||||
ejabberd_auth_storage:get_vh_registered_users_number(Server, Data).
|
||||
|
||||
%% @spec (User, Server) -> bool()
|
||||
%% User = string()
|
||||
%% Server = string()
|
||||
%% @doc Get the user cached password, if possible.
|
||||
%% The password can only be returned if cache is enabled, cached info exists and is fresh enough.
|
||||
|
||||
get_password(User, Server) ->
|
||||
case get_cache_option(Server) of
|
||||
false -> false;
|
||||
{true, CacheTime} -> get_password_cache(User, Server, CacheTime)
|
||||
end.
|
||||
|
||||
%% @spec (User, Server) -> nil()
|
||||
%% User = string()
|
||||
%% Server = string()
|
||||
|
||||
get_password_s(User, Server) ->
|
||||
case get_password(User, Server) of
|
||||
false -> [];
|
||||
@@ -129,6 +173,9 @@ get_password_s(User, Server) ->
|
||||
end.
|
||||
|
||||
%% @spec (User, Server) -> true | false | {error, Error}
|
||||
%% User = string()
|
||||
%% Server = string()
|
||||
|
||||
is_user_exists(User, Server) ->
|
||||
try extauth:is_user_exists(User, Server) of
|
||||
Res -> Res
|
||||
@@ -136,6 +183,10 @@ is_user_exists(User, Server) ->
|
||||
_:Error -> {error, Error}
|
||||
end.
|
||||
|
||||
%% @spec (User, Server) -> {error, not_allowed}
|
||||
%% User = string()
|
||||
%% Server = string()
|
||||
|
||||
remove_user(User, Server) ->
|
||||
case extauth:remove_user(User, Server) of
|
||||
false -> false;
|
||||
@@ -143,10 +194,15 @@ remove_user(User, Server) ->
|
||||
case get_cache_option(Server) of
|
||||
false -> false;
|
||||
{true, _CacheTime} ->
|
||||
ejabberd_auth_internal:remove_user(User, Server)
|
||||
ejabberd_auth_storage:remove_user(User, Server)
|
||||
end
|
||||
end.
|
||||
|
||||
%% @spec (User, Server, Password) -> not_allowed
|
||||
%% User = string()
|
||||
%% Server = string()
|
||||
%% Password = string()
|
||||
|
||||
remove_user(User, Server, Password) ->
|
||||
case extauth:remove_user(User, Server, Password) of
|
||||
false -> false;
|
||||
@@ -154,7 +210,7 @@ remove_user(User, Server, Password) ->
|
||||
case get_cache_option(Server) of
|
||||
false -> false;
|
||||
{true, _CacheTime} ->
|
||||
ejabberd_auth_internal:remove_user(User, Server, Password)
|
||||
ejabberd_auth_storage:remove_user(User, Server, Password)
|
||||
end
|
||||
end.
|
||||
|
||||
@@ -180,7 +236,7 @@ try_register_extauth(User, Server, Password) ->
|
||||
check_password_cache(User, Server, Password, CacheTime) ->
|
||||
case get_last_access(User, Server) of
|
||||
online ->
|
||||
check_password_internal(User, Server, Password);
|
||||
check_password_storage(User, Server, Password);
|
||||
never ->
|
||||
check_password_external_cache(User, Server, Password);
|
||||
mod_last_required ->
|
||||
@@ -191,7 +247,7 @@ check_password_cache(User, Server, Password, CacheTime) ->
|
||||
case is_fresh_enough(TimeStamp, CacheTime) of
|
||||
%% If no need to refresh, check password against Mnesia
|
||||
true ->
|
||||
case check_password_internal(User, Server, Password) of
|
||||
case check_password_storage(User, Server, Password) of
|
||||
%% If password valid in Mnesia, accept it
|
||||
true ->
|
||||
true;
|
||||
@@ -205,14 +261,14 @@ check_password_cache(User, Server, Password, CacheTime) ->
|
||||
end
|
||||
end.
|
||||
|
||||
get_password_internal(User, Server) ->
|
||||
ejabberd_auth_internal:get_password(User, Server).
|
||||
get_password_storage(User, Server) ->
|
||||
ejabberd_auth_storage:get_password(User, Server).
|
||||
|
||||
%% @spec (User, Server, CacheTime) -> false | Password::string()
|
||||
%% @spec (User, Server, CacheTime) -> Password::string() | false
|
||||
get_password_cache(User, Server, CacheTime) ->
|
||||
case get_last_access(User, Server) of
|
||||
online ->
|
||||
get_password_internal(User, Server);
|
||||
get_password_storage(User, Server);
|
||||
never ->
|
||||
false;
|
||||
mod_last_required ->
|
||||
@@ -221,7 +277,7 @@ get_password_cache(User, Server, CacheTime) ->
|
||||
TimeStamp ->
|
||||
case is_fresh_enough(TimeStamp, CacheTime) of
|
||||
true ->
|
||||
get_password_internal(User, Server);
|
||||
get_password_storage(User, Server);
|
||||
false ->
|
||||
false
|
||||
end
|
||||
@@ -232,7 +288,7 @@ get_password_cache(User, Server, CacheTime) ->
|
||||
check_password_external_cache(User, Server, Password) ->
|
||||
case check_password_extauth(User, Server, Password) of
|
||||
true ->
|
||||
set_password_internal(User, Server, Password), true;
|
||||
set_password_storage(User, Server, Password), true;
|
||||
false ->
|
||||
false
|
||||
end.
|
||||
@@ -241,18 +297,18 @@ check_password_external_cache(User, Server, Password) ->
|
||||
try_register_external_cache(User, Server, Password) ->
|
||||
case try_register_extauth(User, Server, Password) of
|
||||
{atomic, ok} = R ->
|
||||
set_password_internal(User, Server, Password),
|
||||
set_password_storage(User, Server, Password),
|
||||
R;
|
||||
_ -> {error, not_allowed}
|
||||
end.
|
||||
|
||||
%% @spec (User, Server, Password) -> true | false
|
||||
check_password_internal(User, Server, Password) ->
|
||||
ejabberd_auth_internal:check_password(User, Server, Password).
|
||||
check_password_storage(User, Server, Password) ->
|
||||
ejabberd_auth_storage:check_password(User, Server, Password).
|
||||
|
||||
%% @spec (User, Server, Password) -> ok | {error, invalid_jid}
|
||||
set_password_internal(User, Server, Password) ->
|
||||
ejabberd_auth_internal:set_password(User, Server, Password).
|
||||
set_password_storage(User, Server, Password) ->
|
||||
ejabberd_auth_storage:set_password(User, Server, Password).
|
||||
|
||||
%% @spec (TimeLast, CacheTime) -> true | false
|
||||
%% TimeLast = online | never | integer()
|
||||
@@ -266,11 +322,13 @@ is_fresh_enough(TimeStampLast, CacheTime) ->
|
||||
Now = MegaSecs * 1000000 + Secs,
|
||||
(TimeStampLast + CacheTime > Now).
|
||||
|
||||
%% @spec (User, Server) -> online | never | mod_last_required | TimeStamp::integer()
|
||||
%% Code copied from mod_configure.erl
|
||||
%% Code copied from web/ejabberd_web_admin.erl
|
||||
%% TODO: Update time format to XEP-0202: Entity Time
|
||||
get_last_access(User, Server) ->
|
||||
%% @spec (User, Server) -> TimeStamp::integer() | online | never | mod_last_required
|
||||
get_last_access(UserS, ServerS) ->
|
||||
%% Code copied from mod_configure.erl
|
||||
%% Code copied from web/ejabberd_web_admin.erl
|
||||
%% TODO: Update time format to XEP-0202: Entity Time
|
||||
User = list_to_binary(UserS),
|
||||
Server = list_to_binary(ServerS),
|
||||
case ejabberd_sm:get_user_resources(User, Server) of
|
||||
[] ->
|
||||
_US = {User, Server},
|
||||
@@ -289,28 +347,15 @@ get_last_access(User, Server) ->
|
||||
get_last_info(User, Server) ->
|
||||
case get_mod_last_enabled(Server) of
|
||||
mod_last -> mod_last:get_last_info(User, Server);
|
||||
mod_last_odbc -> mod_last_odbc:get_last_info(User, Server);
|
||||
no_mod_last -> mod_last_required
|
||||
end.
|
||||
|
||||
%% @spec (Server) -> mod_last | mod_last_odbc | no_mod_last
|
||||
%% @spec (Server) -> mod_last | no_mod_last
|
||||
get_mod_last_enabled(ServerB) when is_binary(ServerB)->
|
||||
Server = binary_to_list(ServerB),
|
||||
get_mod_last_enabled(Server);
|
||||
get_mod_last_enabled(Server) ->
|
||||
ML = gen_mod:is_loaded(Server, mod_last),
|
||||
MLO = gen_mod:is_loaded(Server, mod_last_odbc),
|
||||
case {ML, MLO} of
|
||||
{true, _} -> mod_last;
|
||||
{false, true} -> mod_last_odbc;
|
||||
{false, false} -> no_mod_last
|
||||
case lists:member(mod_last, gen_mod:loaded_modules(Server)) of
|
||||
true -> mod_last;
|
||||
false -> no_mod_last
|
||||
end.
|
||||
|
||||
get_mod_last_configured(Server) ->
|
||||
ML = is_configured(Server, mod_last),
|
||||
MLO = is_configured(Server, mod_last_odbc),
|
||||
case {ML, MLO} of
|
||||
{true, _} -> mod_last;
|
||||
{false, true} -> mod_last_odbc;
|
||||
{false, false} -> no_mod_last
|
||||
end.
|
||||
|
||||
is_configured(Host, Module) ->
|
||||
lists:keymember(Module, 1, ejabberd_config:get_local_option({modules, Host})).
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
%%%----------------------------------------------------------------------
|
||||
%%% File : ejabberd_auth_internal.erl
|
||||
%%% Author : Alexey Shchepin <alexey@process-one.net>
|
||||
%%% Purpose : Authentification via mnesia
|
||||
%%% Purpose : Authentification via mnesia (obsolete)
|
||||
%%% Created : 12 Dec 2004 by Alexey Shchepin <alexey@process-one.net>
|
||||
%%%
|
||||
%%%
|
||||
@@ -54,6 +54,10 @@
|
||||
%%%----------------------------------------------------------------------
|
||||
%%% API
|
||||
%%%----------------------------------------------------------------------
|
||||
|
||||
%% @spec (Host) -> ok
|
||||
%% Host = string()
|
||||
|
||||
start(Host) ->
|
||||
mnesia:create_table(passwd, [{disc_copies, [node()]},
|
||||
{attributes, record_info(fields, passwd)}]),
|
||||
@@ -67,19 +71,26 @@ start(Host) ->
|
||||
update_reg_users_counter_table(Server) ->
|
||||
Set = get_vh_registered_users(Server),
|
||||
Size = length(Set),
|
||||
LServer = jlib:nameprep(Server),
|
||||
LServer = exmpp_jid:prep_domain(exmpp_jid:parse(Server)),
|
||||
F = fun() ->
|
||||
mnesia:write(#reg_users_counter{vhost = LServer,
|
||||
count = Size})
|
||||
end,
|
||||
mnesia:write(#reg_users_counter{vhost = LServer,
|
||||
count = Size})
|
||||
end,
|
||||
mnesia:sync_dirty(F).
|
||||
|
||||
%% @spec () -> bool()
|
||||
|
||||
plain_password_required() ->
|
||||
false.
|
||||
|
||||
%% @spec (User, Server, Password) -> bool()
|
||||
%% User = string()
|
||||
%% Server = string()
|
||||
%% Password = string()
|
||||
|
||||
check_password(User, Server, Password) ->
|
||||
LUser = jlib:nodeprep(User),
|
||||
LServer = jlib:nameprep(Server),
|
||||
LUser = exmpp_stringprep:nodeprep(User),
|
||||
LServer = exmpp_stringprep:nameprep(Server),
|
||||
US = {LUser, LServer},
|
||||
case catch mnesia:dirty_read({passwd, US}) of
|
||||
[#passwd{password = Password}] ->
|
||||
@@ -88,9 +99,16 @@ check_password(User, Server, Password) ->
|
||||
false
|
||||
end.
|
||||
|
||||
%% @spec (User, Server, Password, Digest, DigestGen) -> bool()
|
||||
%% User = string()
|
||||
%% Server = string()
|
||||
%% Password = string()
|
||||
%% Digest = string()
|
||||
%% DigestGen = function()
|
||||
|
||||
check_password(User, Server, Password, Digest, DigestGen) ->
|
||||
LUser = jlib:nodeprep(User),
|
||||
LServer = jlib:nameprep(Server),
|
||||
LUser = exmpp_stringprep:nodeprep(User),
|
||||
LServer = exmpp_stringprep:nameprep(Server),
|
||||
US = {LUser, LServer},
|
||||
case catch mnesia:dirty_read({passwd, US}) of
|
||||
[#passwd{password = Passwd}] ->
|
||||
@@ -109,16 +127,20 @@ check_password(User, Server, Password, Digest, DigestGen) ->
|
||||
false
|
||||
end.
|
||||
|
||||
%% @spec (User::string(), Server::string(), Password::string()) ->
|
||||
%% ok | {error, invalid_jid}
|
||||
%% @spec (User, Server, Password) -> ok | {error, invalid_jid}
|
||||
%% User = string()
|
||||
%% Server = string()
|
||||
%% Password = string()
|
||||
|
||||
set_password(User, Server, Password) ->
|
||||
LUser = jlib:nodeprep(User),
|
||||
LServer = jlib:nameprep(Server),
|
||||
US = {LUser, LServer},
|
||||
if
|
||||
(LUser == error) or (LServer == error) ->
|
||||
LUser = (catch exmpp_stringprep:nodeprep(User)),
|
||||
LServer = (catch exmpp_stringprep:nameprep(Server)),
|
||||
case {LUser, LServer} of
|
||||
{{stringprep, _, invalid_string, _}, _} ->
|
||||
{error, invalid_jid};
|
||||
true ->
|
||||
{_, {stringprep, _, invalid_string, _}} ->
|
||||
{error, invalid_jid};
|
||||
US ->
|
||||
F = fun() ->
|
||||
mnesia:write(#passwd{us = US,
|
||||
password = Password})
|
||||
@@ -128,14 +150,19 @@ set_password(User, Server, Password) ->
|
||||
end.
|
||||
|
||||
%% @spec (User, Server, Password) -> {atomic, ok} | {atomic, exists} | {error, invalid_jid} | {aborted, Reason}
|
||||
%% User = string()
|
||||
%% Server = string()
|
||||
%% Password = string()
|
||||
|
||||
try_register(User, Server, Password) ->
|
||||
LUser = jlib:nodeprep(User),
|
||||
LServer = jlib:nameprep(Server),
|
||||
US = {LUser, LServer},
|
||||
if
|
||||
(LUser == error) or (LServer == error) ->
|
||||
LUser = (catch exmpp_stringprep:nodeprep(User)),
|
||||
LServer = (catch exmpp_stringprep:nameprep(Server)),
|
||||
case {LUser, LServer} of
|
||||
{{stringprep, _, invalid_string, _}, _} ->
|
||||
{error, invalid_jid};
|
||||
true ->
|
||||
{_, {stringprep, _, invalid_string, _}} ->
|
||||
{error, invalid_jid};
|
||||
US ->
|
||||
F = fun() ->
|
||||
case mnesia:read({passwd, US}) of
|
||||
[] ->
|
||||
@@ -143,7 +170,7 @@ try_register(User, Server, Password) ->
|
||||
password = Password}),
|
||||
mnesia:dirty_update_counter(
|
||||
reg_users_counter,
|
||||
LServer, 1),
|
||||
exmpp_jid:prep_domain(exmpp_jid:parse(Server)), 1),
|
||||
ok;
|
||||
[_E] ->
|
||||
exists
|
||||
@@ -152,18 +179,45 @@ try_register(User, Server, Password) ->
|
||||
mnesia:transaction(F)
|
||||
end.
|
||||
|
||||
%% Get all registered users in Mnesia
|
||||
%% @spec () -> [{LUser, LServer}]
|
||||
%% LUser = string()
|
||||
%% LServer = string()
|
||||
%% @doc Get all registered users in Mnesia.
|
||||
|
||||
dirty_get_registered_users() ->
|
||||
mnesia:dirty_all_keys(passwd).
|
||||
|
||||
%% @spec (Server) -> [{LUser, LServer}]
|
||||
%% Server = string()
|
||||
%% LUser = string()
|
||||
%% LServer = string()
|
||||
|
||||
get_vh_registered_users(Server) ->
|
||||
LServer = jlib:nameprep(Server),
|
||||
LServer = exmpp_stringprep:nameprep(Server),
|
||||
mnesia:dirty_select(
|
||||
passwd,
|
||||
[{#passwd{us = '$1', _ = '_'},
|
||||
[{'==', {element, 2, '$1'}, LServer}],
|
||||
['$1']}]).
|
||||
|
||||
%% @spec (Server, Opts) -> [{LUser, LServer}]
|
||||
%% Server = string()
|
||||
%% Opts = [{Opt, Val}]
|
||||
%% Opt = atom()
|
||||
%% Val = term()
|
||||
%% LUser = string()
|
||||
%% LServer = string()
|
||||
%% @doc Return the registered users for the specified host.
|
||||
%%
|
||||
%% `Opts' can be one of the following:
|
||||
%% <ul>
|
||||
%% <li>`[{from, integer()}, {to, integer()}]'</li>
|
||||
%% <li>`[{limit, integer()}, {offset, integer()}]'</li>
|
||||
%% <li>`[{prefix, string()}]'</li>
|
||||
%% <li>`[{prefix, string()}, {from, integer()}, {to, integer()}]'</li>
|
||||
%% <li>`[{prefix, string()}, {limit, integer()}, {offset, integer()}]'</li>
|
||||
%% </ul>
|
||||
|
||||
get_vh_registered_users(Server, [{from, Start}, {to, End}])
|
||||
when is_integer(Start) and is_integer(End) ->
|
||||
get_vh_registered_users(Server, [{limit, End-Start+1}, {offset, Start}]);
|
||||
@@ -210,8 +264,12 @@ get_vh_registered_users(Server, [{prefix, Prefix}, {limit, Limit}, {offset, Offs
|
||||
get_vh_registered_users(Server, _) ->
|
||||
get_vh_registered_users(Server).
|
||||
|
||||
%% @spec (Server) -> Users_Number
|
||||
%% Server = string()
|
||||
%% Users_Number = integer()
|
||||
|
||||
get_vh_registered_users_number(Server) ->
|
||||
LServer = jlib:nameprep(Server),
|
||||
LServer = exmpp_jid:prep_domain(exmpp_jid:parse(Server)),
|
||||
Query = mnesia:dirty_select(
|
||||
reg_users_counter,
|
||||
[{#reg_users_counter{vhost = LServer, count = '$1'},
|
||||
@@ -223,6 +281,11 @@ get_vh_registered_users_number(Server) ->
|
||||
_ -> 0
|
||||
end.
|
||||
|
||||
%% @spec (Server, [{prefix, Prefix}]) -> Users_Number
|
||||
%% Server = string()
|
||||
%% Prefix = string()
|
||||
%% Users_Number = integer()
|
||||
|
||||
get_vh_registered_users_number(Server, [{prefix, Prefix}]) when is_list(Prefix) ->
|
||||
Set = [{U, S} || {U, S} <- get_vh_registered_users(Server), lists:prefix(Prefix, U)],
|
||||
length(Set);
|
||||
@@ -230,90 +293,139 @@ get_vh_registered_users_number(Server, [{prefix, Prefix}]) when is_list(Prefix)
|
||||
get_vh_registered_users_number(Server, _) ->
|
||||
get_vh_registered_users_number(Server).
|
||||
|
||||
%% @spec (User, Server) -> Password | false
|
||||
%% User = string()
|
||||
%% Server = string()
|
||||
%% Password = string()
|
||||
|
||||
get_password(User, Server) ->
|
||||
LUser = jlib:nodeprep(User),
|
||||
LServer = jlib:nameprep(Server),
|
||||
US = {LUser, LServer},
|
||||
case catch mnesia:dirty_read(passwd, US) of
|
||||
[#passwd{password = Password}] ->
|
||||
Password;
|
||||
try
|
||||
LUser = exmpp_stringprep:nodeprep(User),
|
||||
LServer = exmpp_stringprep:nameprep(Server),
|
||||
US = {LUser, LServer},
|
||||
case catch mnesia:dirty_read(passwd, US) of
|
||||
[#passwd{password = Password}] ->
|
||||
Password;
|
||||
_ ->
|
||||
false
|
||||
end
|
||||
catch
|
||||
_ ->
|
||||
false
|
||||
end.
|
||||
|
||||
%% @spec (User, Server) -> Password | nil()
|
||||
%% User = string()
|
||||
%% Server = string()
|
||||
%% Password = string()
|
||||
|
||||
get_password_s(User, Server) ->
|
||||
LUser = jlib:nodeprep(User),
|
||||
LServer = jlib:nameprep(Server),
|
||||
US = {LUser, LServer},
|
||||
case catch mnesia:dirty_read(passwd, US) of
|
||||
[#passwd{password = Password}] ->
|
||||
Password;
|
||||
try
|
||||
LUser = exmpp_stringprep:nodeprep(User),
|
||||
LServer = exmpp_stringprep:nameprep(Server),
|
||||
US = {LUser, LServer},
|
||||
case catch mnesia:dirty_read(passwd, US) of
|
||||
[#passwd{password = Password}] ->
|
||||
Password;
|
||||
_ ->
|
||||
[]
|
||||
end
|
||||
catch
|
||||
_ ->
|
||||
[]
|
||||
end.
|
||||
|
||||
%% @spec (User, Server) -> true | false | {error, Error}
|
||||
%% User = string()
|
||||
%% Server = string()
|
||||
|
||||
is_user_exists(User, Server) ->
|
||||
LUser = jlib:nodeprep(User),
|
||||
LServer = jlib:nameprep(Server),
|
||||
US = {LUser, LServer},
|
||||
case catch mnesia:dirty_read({passwd, US}) of
|
||||
[] ->
|
||||
false;
|
||||
[_] ->
|
||||
true;
|
||||
Other ->
|
||||
{error, Other}
|
||||
try
|
||||
LUser = exmpp_stringprep:nodeprep(User),
|
||||
LServer = exmpp_stringprep:nameprep(Server),
|
||||
US = {LUser, LServer},
|
||||
case catch mnesia:dirty_read({passwd, US}) of
|
||||
[] ->
|
||||
false;
|
||||
[_] ->
|
||||
true;
|
||||
Other ->
|
||||
{error, Other}
|
||||
end
|
||||
catch
|
||||
_ ->
|
||||
false
|
||||
end.
|
||||
|
||||
%% @spec (User, Server) -> ok
|
||||
%% User = string()
|
||||
%% Server = string()
|
||||
%% @doc Remove user.
|
||||
%% Note: it returns ok even if there was some problem removing the user.
|
||||
|
||||
remove_user(User, Server) ->
|
||||
LUser = jlib:nodeprep(User),
|
||||
LServer = jlib:nameprep(Server),
|
||||
US = {LUser, LServer},
|
||||
F = fun() ->
|
||||
mnesia:delete({passwd, US}),
|
||||
mnesia:dirty_update_counter(reg_users_counter,
|
||||
LServer, -1)
|
||||
end,
|
||||
mnesia:transaction(F),
|
||||
ok.
|
||||
try
|
||||
LUser = exmpp_stringprep:nodeprep(User),
|
||||
LServer = exmpp_stringprep:nameprep(Server),
|
||||
US = {LUser, LServer},
|
||||
F = fun() ->
|
||||
mnesia:delete({passwd, US}),
|
||||
mnesia:dirty_update_counter(reg_users_counter,
|
||||
exmpp_jid:prep_domain(exmpp_jid:parse(Server)), -1)
|
||||
end,
|
||||
mnesia:transaction(F),
|
||||
ok
|
||||
catch
|
||||
_ ->
|
||||
ok
|
||||
end.
|
||||
|
||||
%% @spec (User, Server, Password) -> ok | not_exists | not_allowed | bad_request
|
||||
%% User = string()
|
||||
%% Server = string()
|
||||
%% Password = string()
|
||||
%% @doc Remove user if the provided password is correct.
|
||||
|
||||
remove_user(User, Server, Password) ->
|
||||
LUser = jlib:nodeprep(User),
|
||||
LServer = jlib:nameprep(Server),
|
||||
US = {LUser, LServer},
|
||||
F = fun() ->
|
||||
case mnesia:read({passwd, US}) of
|
||||
[#passwd{password = Password}] ->
|
||||
mnesia:delete({passwd, US}),
|
||||
mnesia:dirty_update_counter(reg_users_counter,
|
||||
LServer, -1),
|
||||
ok;
|
||||
[_] ->
|
||||
not_allowed;
|
||||
_ ->
|
||||
not_exists
|
||||
end
|
||||
end,
|
||||
case mnesia:transaction(F) of
|
||||
{atomic, ok} ->
|
||||
ok;
|
||||
{atomic, Res} ->
|
||||
Res;
|
||||
try
|
||||
LUser = exmpp_stringprep:nodeprep(User),
|
||||
LServer = exmpp_stringprep:nameprep(Server),
|
||||
US = {LUser, LServer},
|
||||
F = fun() ->
|
||||
case mnesia:read({passwd, US}) of
|
||||
[#passwd{password = Password}] ->
|
||||
mnesia:delete({passwd, US}),
|
||||
mnesia:dirty_update_counter(reg_users_counter,
|
||||
exmpp_jid:prep_domain(exmpp_jid:parse(Server)), -1),
|
||||
ok;
|
||||
[_] ->
|
||||
not_allowed;
|
||||
_ ->
|
||||
not_exists
|
||||
end
|
||||
end,
|
||||
case mnesia:transaction(F) of
|
||||
{atomic, ok} ->
|
||||
ok;
|
||||
{atomic, Res} ->
|
||||
Res;
|
||||
_ ->
|
||||
bad_request
|
||||
end
|
||||
catch
|
||||
_ ->
|
||||
bad_request
|
||||
end.
|
||||
|
||||
%% @spec () -> term()
|
||||
|
||||
update_table() ->
|
||||
Fields = record_info(fields, passwd),
|
||||
case mnesia:table_info(passwd, attributes) of
|
||||
Fields ->
|
||||
% No conversion is needed when the table comes from an exmpp-less
|
||||
% Ejabberd because ejabberd_auth* modules use string() and not
|
||||
% binary().
|
||||
ok;
|
||||
[user, password] ->
|
||||
?INFO_MSG("Converting passwd table from "
|
||||
|
||||
@@ -72,7 +72,6 @@
|
||||
base,
|
||||
uids,
|
||||
ufilter,
|
||||
sfilter,
|
||||
lfilter, %% Local filter (performed by ejabberd, not LDAP)
|
||||
dn_filter,
|
||||
dn_filter_attrs
|
||||
@@ -95,48 +94,90 @@ handle_info(_Info, State) ->
|
||||
%%% API
|
||||
%%%----------------------------------------------------------------------
|
||||
|
||||
%% @spec (Host) -> term()
|
||||
%% Host = string()
|
||||
|
||||
start(Host) ->
|
||||
Proc = gen_mod:get_module_proc(Host, ?MODULE),
|
||||
ChildSpec = {
|
||||
Proc, {?MODULE, start_link, [Host]},
|
||||
transient, 1000, worker, [?MODULE]
|
||||
},
|
||||
supervisor:start_child(ejabberd_sup, ChildSpec).
|
||||
?DEBUG("Starting ~p for ~p.", [?MODULE, Host]),
|
||||
case ejabberd_config:get_host_option(Host, ldap_servers) of
|
||||
undefined -> check_bad_config(Host);
|
||||
{host, _Host} -> ok;
|
||||
_ ->
|
||||
Proc = gen_mod:get_module_proc(Host, ?MODULE),
|
||||
ChildSpec = {
|
||||
Proc, {?MODULE, start_link, [Host]},
|
||||
transient, 1000, worker, [?MODULE]
|
||||
},
|
||||
supervisor:start_child(ejabberd_sup, ChildSpec)
|
||||
end.
|
||||
|
||||
check_bad_config(Host) ->
|
||||
case ejabberd_config:get_local_option({ldap_servers, Host}) of
|
||||
undefined ->
|
||||
?ERROR_MSG("Can't start ~p for host ~p: missing ldap_servers configuration",
|
||||
[?MODULE, Host]),
|
||||
{error, bad_config};
|
||||
_ -> ok
|
||||
end.
|
||||
|
||||
%% @spec (Host) -> term()
|
||||
%% Host = string()
|
||||
|
||||
stop(Host) ->
|
||||
Proc = gen_mod:get_module_proc(Host, ?MODULE),
|
||||
gen_server:call(Proc, stop),
|
||||
supervisor:terminate_child(ejabberd_sup, Proc),
|
||||
supervisor:delete_child(ejabberd_sup, Proc).
|
||||
case ejabberd_config:get_host_option(Host, ldap_servers) of
|
||||
undefined -> ok;
|
||||
{host, _Host} -> ok;
|
||||
_ ->
|
||||
Proc = gen_mod:get_module_proc(Host, ?MODULE),
|
||||
gen_server:call(Proc, stop),
|
||||
supervisor:terminate_child(ejabberd_sup, Proc),
|
||||
supervisor:delete_child(ejabberd_sup, Proc)
|
||||
end.
|
||||
|
||||
%% @spec (Host) -> term()
|
||||
%% Host = string()
|
||||
|
||||
start_link(Host) ->
|
||||
Proc = gen_mod:get_module_proc(Host, ?MODULE),
|
||||
gen_server:start_link({local, Proc}, ?MODULE, Host, []).
|
||||
|
||||
%% @hidden
|
||||
|
||||
terminate(_Reason, _State) ->
|
||||
ok.
|
||||
|
||||
%% @spec (Host) -> {ok, State}
|
||||
%% Host = string()
|
||||
%% State = term()
|
||||
|
||||
init(Host) ->
|
||||
State = parse_options(Host),
|
||||
eldap_pool:start_link(State#state.eldap_id,
|
||||
State#state.servers,
|
||||
State#state.backups,
|
||||
State#state.port,
|
||||
State#state.dn,
|
||||
State#state.password,
|
||||
State#state.tls_options),
|
||||
State#state.servers,
|
||||
State#state.backups,
|
||||
State#state.port,
|
||||
State#state.dn,
|
||||
State#state.password,
|
||||
State#state.tls_options),
|
||||
eldap_pool:start_link(State#state.bind_eldap_id,
|
||||
State#state.servers,
|
||||
State#state.backups,
|
||||
State#state.port,
|
||||
State#state.dn,
|
||||
State#state.password,
|
||||
State#state.tls_options),
|
||||
State#state.servers,
|
||||
State#state.backups,
|
||||
State#state.port,
|
||||
State#state.dn,
|
||||
State#state.password,
|
||||
State#state.tls_options),
|
||||
{ok, State}.
|
||||
|
||||
%% @spec () -> true
|
||||
|
||||
plain_password_required() ->
|
||||
true.
|
||||
|
||||
%% @spec (User, Server, Password) -> bool()
|
||||
%% User = string()
|
||||
%% Server = string()
|
||||
%% Password = string()
|
||||
|
||||
check_password(User, Server, Password) ->
|
||||
%% In LDAP spec: empty password means anonymous authentication.
|
||||
%% As ejabberd is providing other anonymous authentication mechanisms
|
||||
@@ -150,12 +191,25 @@ check_password(User, Server, Password) ->
|
||||
end
|
||||
end.
|
||||
|
||||
%% @spec (User, Server, Password, Digest, DigestGen) -> bool()
|
||||
%% User = string()
|
||||
%% Server = string()
|
||||
%% Password = string()
|
||||
%% Digest = string()
|
||||
%% DigestGen = function()
|
||||
|
||||
check_password(User, Server, Password, _Digest, _DigestGen) ->
|
||||
check_password(User, Server, Password).
|
||||
|
||||
%% @spec (User, Server, Password) -> {error, Reason} | ok
|
||||
%% User = string()
|
||||
%% Server = string()
|
||||
%% Password = string()
|
||||
%% Reason = term()
|
||||
|
||||
set_password(User, Server, Password) ->
|
||||
{ok, State} = eldap_utils:get_state(Server, ?MODULE),
|
||||
case find_user_dn(User, State) of
|
||||
case find_user_dn(User, Server, State) of
|
||||
false ->
|
||||
{error, user_not_found};
|
||||
DN ->
|
||||
@@ -163,9 +217,17 @@ set_password(User, Server, Password) ->
|
||||
end.
|
||||
|
||||
%% @spec (User, Server, Password) -> {error, not_allowed}
|
||||
%% User = string()
|
||||
%% Server = string()
|
||||
%% Password = string()
|
||||
|
||||
try_register(_User, _Server, _Password) ->
|
||||
{error, not_allowed}.
|
||||
|
||||
%% @spec () -> [{LUser, LServer}]
|
||||
%% LUser = string()
|
||||
%% LServer = string()
|
||||
|
||||
dirty_get_registered_users() ->
|
||||
Servers = ejabberd_config:get_vh_by_auth_method(ldap),
|
||||
lists:flatmap(
|
||||
@@ -173,22 +235,42 @@ dirty_get_registered_users() ->
|
||||
get_vh_registered_users(Server)
|
||||
end, Servers).
|
||||
|
||||
%% @spec (Server) -> [{LUser, LServer}]
|
||||
%% Server = string()
|
||||
%% LUser = string()
|
||||
%% LServer = string()
|
||||
|
||||
get_vh_registered_users(Server) ->
|
||||
case catch get_vh_registered_users_ldap(Server) of
|
||||
{'EXIT', _} -> [];
|
||||
Result -> Result
|
||||
end.
|
||||
|
||||
%% @spec (Server) -> Users_Number
|
||||
%% Server = string()
|
||||
%% Users_Number = integer()
|
||||
|
||||
get_vh_registered_users_number(Server) ->
|
||||
length(get_vh_registered_users(Server)).
|
||||
|
||||
%% @spec (User, Server) -> bool()
|
||||
%% User = string()
|
||||
%% Server = string()
|
||||
|
||||
get_password(_User, _Server) ->
|
||||
false.
|
||||
|
||||
%% @spec (User, Server) -> nil()
|
||||
%% User = string()
|
||||
%% Server = string()
|
||||
|
||||
get_password_s(_User, _Server) ->
|
||||
"".
|
||||
|
||||
%% @spec (User, Server) -> true | false | {error, Error}
|
||||
%% User = string()
|
||||
%% Server = string()
|
||||
|
||||
is_user_exists(User, Server) ->
|
||||
case catch is_user_exists_ldap(User, Server) of
|
||||
{'EXIT', Error} ->
|
||||
@@ -197,18 +279,33 @@ is_user_exists(User, Server) ->
|
||||
Result
|
||||
end.
|
||||
|
||||
%% @spec (User, Server) -> {error, not_allowed}
|
||||
%% User = string()
|
||||
%% Server = string()
|
||||
|
||||
remove_user(_User, _Server) ->
|
||||
{error, not_allowed}.
|
||||
|
||||
%% @spec (User, Server, Password) -> not_allowed
|
||||
%% User = string()
|
||||
%% Server = string()
|
||||
%% Password = string()
|
||||
|
||||
remove_user(_User, _Server, _Password) ->
|
||||
not_allowed.
|
||||
|
||||
%%%----------------------------------------------------------------------
|
||||
%%% Internal functions
|
||||
%%%----------------------------------------------------------------------
|
||||
|
||||
%% @spec (User, Server, Password) -> bool()
|
||||
%% User = string()
|
||||
%% Server = string()
|
||||
%% Password = string()
|
||||
|
||||
check_password_ldap(User, Server, Password) ->
|
||||
{ok, State} = eldap_utils:get_state(Server, ?MODULE),
|
||||
case find_user_dn(User, State) of
|
||||
{ok, State} = get_state(Server),
|
||||
case find_user_dn(User, Server, State) of
|
||||
false ->
|
||||
false;
|
||||
DN ->
|
||||
@@ -216,15 +313,34 @@ check_password_ldap(User, Server, Password) ->
|
||||
ok -> true;
|
||||
_ -> false
|
||||
end
|
||||
end.
|
||||
end.
|
||||
|
||||
%% We need an ?MODULE server state to use for queries. This will
|
||||
%% either be Server if this is a statically configured host or the
|
||||
%% Server for a different host if this is a dynamically configured
|
||||
%% vhost.
|
||||
%% The {ldap_vhost, Server} -> Host. ejabberd config option specifies
|
||||
%% which actual ?MODULE server to use for a particular Host. The value
|
||||
%% of the option if it is defined or Server by default.
|
||||
get_state(Server) ->
|
||||
Host = case ejabberd_config:get_local_option({ldap_servers, Server}) of
|
||||
{host, H} -> H;
|
||||
_ -> Server
|
||||
end,
|
||||
eldap_utils:get_state(Host, ?MODULE).
|
||||
|
||||
%% @spec (Server) -> [{LUser, LServer}]
|
||||
%% Server = string()
|
||||
%% LUser = string()
|
||||
%% LServer = string()
|
||||
|
||||
get_vh_registered_users_ldap(Server) ->
|
||||
{ok, State} = eldap_utils:get_state(Server, ?MODULE),
|
||||
UIDs = State#state.uids,
|
||||
UIDs = eldap_utils:uids_domain_subst(Server, State#state.uids),
|
||||
Eldap_ID = State#state.eldap_id,
|
||||
Server = State#state.host,
|
||||
SearchFilter = build_sfilter(State, UIDs),
|
||||
ResAttrs = result_attrs(State),
|
||||
case eldap_filter:parse(State#state.sfilter) of
|
||||
case eldap_filter:parse(SearchFilter) of
|
||||
{ok, EldapFilter} ->
|
||||
case eldap_pool:search(Eldap_ID, [{base, State#state.base},
|
||||
{filter, EldapFilter},
|
||||
@@ -234,7 +350,7 @@ get_vh_registered_users_ldap(Server) ->
|
||||
lists:flatmap(
|
||||
fun(#eldap_entry{attributes = Attrs,
|
||||
object_name = DN}) ->
|
||||
case is_valid_dn(DN, Attrs, State) of
|
||||
case is_valid_dn(DN, Server, Attrs, State) of
|
||||
false -> [];
|
||||
_ ->
|
||||
case eldap_utils:find_ldap_attrs(UIDs, Attrs) of
|
||||
@@ -242,9 +358,11 @@ get_vh_registered_users_ldap(Server) ->
|
||||
{User, UIDFormat} ->
|
||||
case eldap_utils:get_user_part(User, UIDFormat) of
|
||||
{ok, U} ->
|
||||
case jlib:nodeprep(U) of
|
||||
error -> [];
|
||||
LU -> [{LU, jlib:nameprep(Server)}]
|
||||
try
|
||||
[{exmpp_stringprep:nodeprep(U), exmpp_stringprep:nameprep(Server)}]
|
||||
catch
|
||||
_ ->
|
||||
[]
|
||||
end;
|
||||
_ -> []
|
||||
end
|
||||
@@ -258,9 +376,13 @@ get_vh_registered_users_ldap(Server) ->
|
||||
[]
|
||||
end.
|
||||
|
||||
%% @spec (User, Server) -> bool()
|
||||
%% User = string()
|
||||
%% Server = string()
|
||||
|
||||
is_user_exists_ldap(User, Server) ->
|
||||
{ok, State} = eldap_utils:get_state(Server, ?MODULE),
|
||||
case find_user_dn(User, State) of
|
||||
case find_user_dn(User, Server, State) of
|
||||
false -> false;
|
||||
_DN -> true
|
||||
end.
|
||||
@@ -274,17 +396,17 @@ handle_call(stop, _From, State) ->
|
||||
handle_call(_Request, _From, State) ->
|
||||
{reply, bad_request, State}.
|
||||
|
||||
find_user_dn(User, State) ->
|
||||
find_user_dn(User, Server, State) ->
|
||||
ResAttrs = result_attrs(State),
|
||||
case eldap_filter:parse(State#state.ufilter, [{"%u", User}]) of
|
||||
UserFilter = build_ufilter(State, Server),
|
||||
case eldap_filter:parse(UserFilter, [{"%u", User}]) of
|
||||
{ok, Filter} ->
|
||||
case eldap_pool:search(State#state.eldap_id,
|
||||
[{base, State#state.base},
|
||||
{filter, Filter},
|
||||
{attributes, ResAttrs}]) of
|
||||
case eldap_pool:search(State#state.eldap_id, [{base, State#state.base},
|
||||
{filter, Filter},
|
||||
{attributes, ResAttrs}]) of
|
||||
#eldap_search_result{entries = [#eldap_entry{attributes = Attrs,
|
||||
object_name = DN} | _]} ->
|
||||
dn_filter(DN, Attrs, State);
|
||||
dn_filter(DN, Server, Attrs, State);
|
||||
_ ->
|
||||
false
|
||||
end;
|
||||
@@ -293,20 +415,20 @@ find_user_dn(User, State) ->
|
||||
end.
|
||||
|
||||
%% apply the dn filter and the local filter:
|
||||
dn_filter(DN, Attrs, State) ->
|
||||
dn_filter(DN, Server, Attrs, State) ->
|
||||
%% Check if user is denied access by attribute value (local check)
|
||||
case check_local_filter(Attrs, State) of
|
||||
false -> false;
|
||||
true -> is_valid_dn(DN, Attrs, State)
|
||||
true -> is_valid_dn(DN, Server, Attrs, State)
|
||||
end.
|
||||
|
||||
%% Check that the DN is valid, based on the dn filter
|
||||
is_valid_dn(DN, _, #state{dn_filter = undefined}) ->
|
||||
is_valid_dn(DN, _, _, #state{dn_filter = undefined}) ->
|
||||
DN;
|
||||
|
||||
is_valid_dn(DN, Attrs, State) ->
|
||||
is_valid_dn(DN, Server, Attrs, State) ->
|
||||
DNAttrs = State#state.dn_filter_attrs,
|
||||
UIDs = State#state.uids,
|
||||
UIDs = eldap_utils:uids_domain_subst(Server, State#state.uids),
|
||||
Values = [{"%s", eldap_utils:get_ldap_attr(Attr, Attrs), 1} || Attr <- DNAttrs],
|
||||
SubstValues = case eldap_utils:find_ldap_attrs(UIDs, Attrs) of
|
||||
"" -> Values;
|
||||
@@ -361,6 +483,22 @@ result_attrs(#state{uids = UIDs, dn_filter_attrs = DNFilterAttrs}) ->
|
||||
[UID | Acc]
|
||||
end, DNFilterAttrs, UIDs).
|
||||
|
||||
build_ufilter(State, VHost) ->
|
||||
UIDs = eldap_utils:uids_domain_subst(VHost, State#state.uids),
|
||||
SubFilter = lists:flatten(eldap_utils:generate_subfilter(UIDs)),
|
||||
case State#state.ufilter of
|
||||
"" -> SubFilter;
|
||||
F -> "(&" ++ SubFilter ++ F ++ ")"
|
||||
end.
|
||||
|
||||
build_sfilter(State, FormattedUIDs) ->
|
||||
SubFilter = lists:flatten(eldap_utils:generate_subfilter(FormattedUIDs)),
|
||||
UserFilter = case State#state.ufilter of
|
||||
"" -> SubFilter;
|
||||
F -> "(&" ++ SubFilter ++ F ++ ")"
|
||||
end,
|
||||
eldap_filter:do_sub(UserFilter, [{"%u", "*"}]).
|
||||
|
||||
%%%----------------------------------------------------------------------
|
||||
%%% Auxiliary functions
|
||||
%%%----------------------------------------------------------------------
|
||||
@@ -392,15 +530,12 @@ parse_options(Host) ->
|
||||
end,
|
||||
UIDs = case ejabberd_config:get_local_option({ldap_uids, Host}) of
|
||||
undefined -> [{"uid", "%u"}];
|
||||
UI -> eldap_utils:uids_domain_subst(Host, UI)
|
||||
UI -> UI
|
||||
end,
|
||||
SubFilter = lists:flatten(eldap_utils:generate_subfilter(UIDs)),
|
||||
UserFilter = case ejabberd_config:get_local_option({ldap_filter, Host}) of
|
||||
undefined -> SubFilter;
|
||||
"" -> SubFilter;
|
||||
F -> "(&" ++ SubFilter ++ F ++ ")"
|
||||
undefined -> "";
|
||||
F -> F
|
||||
end,
|
||||
SearchFilter = eldap_filter:do_sub(UserFilter, [{"%u", "*"}]),
|
||||
LDAPBase = ejabberd_config:get_local_option({ldap_base, Host}),
|
||||
{DNFilter, DNFilterAttrs} =
|
||||
case ejabberd_config:get_local_option({ldap_dn_filter, Host}) of
|
||||
@@ -425,7 +560,6 @@ parse_options(Host) ->
|
||||
base = LDAPBase,
|
||||
uids = UIDs,
|
||||
ufilter = UserFilter,
|
||||
sfilter = SearchFilter,
|
||||
lfilter = LocalFilter,
|
||||
dn_filter = DNFilter,
|
||||
dn_filter_attrs = DNFilterAttrs
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
%%%----------------------------------------------------------------------
|
||||
%%% File : ejabberd_auth_odbc.erl
|
||||
%%% Author : Alexey Shchepin <alexey@process-one.net>
|
||||
%%% Purpose : Authentification via ODBC
|
||||
%%% Purpose : Authentification via ODBC (obsolete)
|
||||
%%% Created : 12 Dec 2004 by Alexey Shchepin <alexey@process-one.net>
|
||||
%%%
|
||||
%%%
|
||||
@@ -29,6 +29,7 @@
|
||||
|
||||
%% External exports
|
||||
-export([start/1,
|
||||
stop/1,
|
||||
set_password/3,
|
||||
check_password/3,
|
||||
check_password/5,
|
||||
@@ -51,22 +52,36 @@
|
||||
%%%----------------------------------------------------------------------
|
||||
%%% API
|
||||
%%%----------------------------------------------------------------------
|
||||
start(_Host) ->
|
||||
ok.
|
||||
|
||||
%% @spec (Host) -> ok
|
||||
%% Host = string()
|
||||
|
||||
start(Host) ->
|
||||
case ejabberd_odbc:running(Host) of
|
||||
true -> ok;
|
||||
false -> ejabberd_rdbms:start_odbc(Host)
|
||||
end.
|
||||
|
||||
stop(Host) ->
|
||||
ejabberd_rdbms:stop_odbc(Host).
|
||||
|
||||
%% @spec () -> bool()
|
||||
|
||||
plain_password_required() ->
|
||||
false.
|
||||
|
||||
%% @spec (User, Server, Password) -> true | false | {error, Error}
|
||||
%% @spec (User, Server, Password) -> bool()
|
||||
%% User = string()
|
||||
%% Server = string()
|
||||
%% Password = string()
|
||||
|
||||
check_password(User, Server, Password) ->
|
||||
case jlib:nodeprep(User) of
|
||||
error ->
|
||||
false;
|
||||
LUser ->
|
||||
Username = ejabberd_odbc:escape(LUser),
|
||||
LServer = jlib:nameprep(Server),
|
||||
try odbc_queries:get_password(LServer, Username) of
|
||||
{selected, ["password"], [{Password}]} ->
|
||||
try
|
||||
LUser = exmpp_stringprep:nodeprep(User),
|
||||
Username = ejabberd_odbc:escape(LUser),
|
||||
LServer = exmpp_stringprep:nameprep(Server),
|
||||
try odbc_queries:get_password(LServer, Username) of
|
||||
{selected, ["password"], [{Password}]} ->
|
||||
Password /= ""; %% Password is correct, and not empty
|
||||
{selected, ["password"], [{_Password2}]} ->
|
||||
false; %% Password is not correct
|
||||
@@ -77,31 +92,38 @@ check_password(User, Server, Password) ->
|
||||
catch
|
||||
_:_ ->
|
||||
false %% Typical error is database not accessible
|
||||
end
|
||||
end
|
||||
catch
|
||||
_ ->
|
||||
false
|
||||
end.
|
||||
|
||||
%% @spec (User, Server, Password, Digest, DigestGen) -> true | false | {error, Error}
|
||||
%% @spec (User, Server, Password, Digest, DigestGen) -> bool()
|
||||
%% User = string()
|
||||
%% Server = string()
|
||||
%% Password = string()
|
||||
%% Digest = string()
|
||||
%% DigestGen = function()
|
||||
|
||||
check_password(User, Server, Password, Digest, DigestGen) ->
|
||||
case jlib:nodeprep(User) of
|
||||
error ->
|
||||
false;
|
||||
LUser ->
|
||||
Username = ejabberd_odbc:escape(LUser),
|
||||
LServer = jlib:nameprep(Server),
|
||||
try odbc_queries:get_password(LServer, Username) of
|
||||
try
|
||||
LUser = exmpp_stringprep:nodeprep(User),
|
||||
Username = ejabberd_odbc:escape(LUser),
|
||||
LServer = exmpp_stringprep:nameprep(Server),
|
||||
try odbc_queries:get_password(LServer, Username) of
|
||||
%% Account exists, check if password is valid
|
||||
{selected, ["password"], [{Passwd}]} ->
|
||||
DigRes = if
|
||||
Digest /= "" ->
|
||||
{selected, ["password"], [{Passwd}]} ->
|
||||
DigRes = if
|
||||
Digest /= "" ->
|
||||
Digest == DigestGen(Passwd);
|
||||
true ->
|
||||
false
|
||||
end,
|
||||
if DigRes ->
|
||||
true;
|
||||
true ->
|
||||
(Passwd == Password) and (Password /= "")
|
||||
end;
|
||||
true ->
|
||||
false
|
||||
end,
|
||||
if DigRes ->
|
||||
true;
|
||||
true ->
|
||||
(Passwd == Password) and (Password /= "")
|
||||
end;
|
||||
{selected, ["password"], []} ->
|
||||
false; %% Account does not exist
|
||||
{error, _Error} ->
|
||||
@@ -109,43 +131,59 @@ check_password(User, Server, Password, Digest, DigestGen) ->
|
||||
catch
|
||||
_:_ ->
|
||||
false %% Typical error is database not accessible
|
||||
end
|
||||
end
|
||||
catch
|
||||
_ ->
|
||||
false
|
||||
end.
|
||||
|
||||
%% @spec (User::string(), Server::string(), Password::string()) ->
|
||||
%% ok | {error, invalid_jid}
|
||||
%% @spec (User, Server, Password) -> ok | {error, invalid_jid}
|
||||
%% User = string()
|
||||
%% Server = string()
|
||||
%% Password = string()
|
||||
|
||||
set_password(User, Server, Password) ->
|
||||
case jlib:nodeprep(User) of
|
||||
error ->
|
||||
{error, invalid_jid};
|
||||
LUser ->
|
||||
Username = ejabberd_odbc:escape(LUser),
|
||||
Pass = ejabberd_odbc:escape(Password),
|
||||
LServer = jlib:nameprep(Server),
|
||||
case catch odbc_queries:set_password_t(LServer, Username, Pass) of
|
||||
{atomic, ok} -> ok;
|
||||
Other -> {error, Other}
|
||||
end
|
||||
try
|
||||
LUser = exmpp_stringprep:nodeprep(User),
|
||||
Username = ejabberd_odbc:escape(LUser),
|
||||
Pass = ejabberd_odbc:escape(Password),
|
||||
LServer = exmpp_stringprep:nameprep(Server),
|
||||
case catch odbc_queries:set_password_t(LServer, Username, Pass) of
|
||||
{atomic, ok} -> ok;
|
||||
Other -> {error, Other}
|
||||
end
|
||||
catch
|
||||
_ ->
|
||||
{error, invalid_jid}
|
||||
end.
|
||||
|
||||
|
||||
%% @spec (User, Server, Password) -> {atomic, ok} | {atomic, exists} | {error, invalid_jid}
|
||||
%% User = string()
|
||||
%% Server = string()
|
||||
%% Password = string()
|
||||
|
||||
try_register(User, Server, Password) ->
|
||||
case jlib:nodeprep(User) of
|
||||
error ->
|
||||
{error, invalid_jid};
|
||||
LUser ->
|
||||
Username = ejabberd_odbc:escape(LUser),
|
||||
Pass = ejabberd_odbc:escape(Password),
|
||||
LServer = jlib:nameprep(Server),
|
||||
case catch odbc_queries:add_user(LServer, Username, Pass) of
|
||||
{updated, 1} ->
|
||||
{atomic, ok};
|
||||
_ ->
|
||||
{atomic, exists}
|
||||
end
|
||||
try
|
||||
LUser = exmpp_stringprep:nodeprep(User),
|
||||
Username = ejabberd_odbc:escape(LUser),
|
||||
Pass = ejabberd_odbc:escape(Password),
|
||||
LServer = exmpp_stringprep:nameprep(Server),
|
||||
case catch odbc_queries:add_user(LServer, Username, Pass) of
|
||||
{updated, 1} ->
|
||||
{atomic, ok};
|
||||
_ ->
|
||||
{atomic, exists}
|
||||
end
|
||||
catch
|
||||
_ ->
|
||||
{error, invalid_jid}
|
||||
end.
|
||||
|
||||
%% @spec () -> [{LUser, LServer}]
|
||||
%% LUser = string()
|
||||
%% LServer = string()
|
||||
|
||||
dirty_get_registered_users() ->
|
||||
Servers = ejabberd_config:get_vh_by_auth_method(odbc),
|
||||
lists:flatmap(
|
||||
@@ -153,8 +191,13 @@ dirty_get_registered_users() ->
|
||||
get_vh_registered_users(Server)
|
||||
end, Servers).
|
||||
|
||||
%% @spec (Server) -> [{LUser, LServer}]
|
||||
%% Server = string()
|
||||
%% LUser = string()
|
||||
%% LServer = string()
|
||||
|
||||
get_vh_registered_users(Server) ->
|
||||
LServer = jlib:nameprep(Server),
|
||||
LServer = exmpp_stringprep:nameprep(Server),
|
||||
case catch odbc_queries:list_users(LServer) of
|
||||
{selected, ["username"], Res} ->
|
||||
[{U, LServer} || {U} <- Res];
|
||||
@@ -162,8 +205,16 @@ get_vh_registered_users(Server) ->
|
||||
[]
|
||||
end.
|
||||
|
||||
%% @spec (Server, Opts) -> [{LUser, LServer}]
|
||||
%% Server = string()
|
||||
%% Opts = [{Opt, Val}]
|
||||
%% Opt = atom()
|
||||
%% Val = term()
|
||||
%% LUser = string()
|
||||
%% LServer = string()
|
||||
|
||||
get_vh_registered_users(Server, Opts) ->
|
||||
LServer = jlib:nameprep(Server),
|
||||
LServer = exmpp_stringprep:nameprep(Server),
|
||||
case catch odbc_queries:list_users(LServer, Opts) of
|
||||
{selected, ["username"], Res} ->
|
||||
[{U, LServer} || {U} <- Res];
|
||||
@@ -171,8 +222,12 @@ get_vh_registered_users(Server, Opts) ->
|
||||
[]
|
||||
end.
|
||||
|
||||
%% @spec (Server) -> Users_Number
|
||||
%% Server = string()
|
||||
%% Users_Number = integer()
|
||||
|
||||
get_vh_registered_users_number(Server) ->
|
||||
LServer = jlib:nameprep(Server),
|
||||
LServer = exmpp_stringprep:nameprep(Server),
|
||||
case catch odbc_queries:users_number(LServer) of
|
||||
{selected, [_], [{Res}]} ->
|
||||
list_to_integer(Res);
|
||||
@@ -180,8 +235,15 @@ get_vh_registered_users_number(Server) ->
|
||||
0
|
||||
end.
|
||||
|
||||
%% @spec (Server, Opts) -> Users_Number
|
||||
%% Server = string()
|
||||
%% Opts = [{Opt, Val}]
|
||||
%% Opt = atom()
|
||||
%% Val = term()
|
||||
%% Users_Number = integer()
|
||||
|
||||
get_vh_registered_users_number(Server, Opts) ->
|
||||
LServer = jlib:nameprep(Server),
|
||||
LServer = exmpp_stringprep:nameprep(Server),
|
||||
case catch odbc_queries:users_number(LServer, Opts) of
|
||||
{selected, [_], [{Res}]} ->
|
||||
list_to_integer(Res);
|
||||
@@ -189,46 +251,59 @@ get_vh_registered_users_number(Server, Opts) ->
|
||||
0
|
||||
end.
|
||||
|
||||
%% @spec (User, Server) -> Password | false
|
||||
%% User = string()
|
||||
%% Server = string()
|
||||
%% Password = string()
|
||||
|
||||
get_password(User, Server) ->
|
||||
case jlib:nodeprep(User) of
|
||||
error ->
|
||||
false;
|
||||
LUser ->
|
||||
Username = ejabberd_odbc:escape(LUser),
|
||||
LServer = jlib:nameprep(Server),
|
||||
case catch odbc_queries:get_password(LServer, Username) of
|
||||
{selected, ["password"], [{Password}]} ->
|
||||
Password;
|
||||
_ ->
|
||||
false
|
||||
end
|
||||
try
|
||||
LUser = exmpp_stringprep:nodeprep(User),
|
||||
Username = ejabberd_odbc:escape(LUser),
|
||||
LServer = exmpp_stringprep:nameprep(Server),
|
||||
case catch odbc_queries:get_password(LServer, Username) of
|
||||
{selected, ["password"], [{Password}]} ->
|
||||
Password;
|
||||
_ ->
|
||||
false
|
||||
end
|
||||
catch
|
||||
_ ->
|
||||
false
|
||||
end.
|
||||
|
||||
%% @spec (User, Server) -> Password | nil()
|
||||
%% User = string()
|
||||
%% Server = string()
|
||||
%% Password = string()
|
||||
|
||||
get_password_s(User, Server) ->
|
||||
case jlib:nodeprep(User) of
|
||||
error ->
|
||||
"";
|
||||
LUser ->
|
||||
Username = ejabberd_odbc:escape(LUser),
|
||||
LServer = jlib:nameprep(Server),
|
||||
case catch odbc_queries:get_password(LServer, Username) of
|
||||
{selected, ["password"], [{Password}]} ->
|
||||
Password;
|
||||
_ ->
|
||||
""
|
||||
end
|
||||
try
|
||||
LUser = exmpp_stringprep:nodeprep(User),
|
||||
Username = ejabberd_odbc:escape(LUser),
|
||||
LServer = exmpp_stringprep:nameprep(Server),
|
||||
case catch odbc_queries:get_password(LServer, Username) of
|
||||
{selected, ["password"], [{Password}]} ->
|
||||
Password;
|
||||
_ ->
|
||||
""
|
||||
end
|
||||
catch
|
||||
_ ->
|
||||
""
|
||||
end.
|
||||
|
||||
%% @spec (User, Server) -> true | false | {error, Error}
|
||||
%% User = string()
|
||||
%% Server = string()
|
||||
|
||||
is_user_exists(User, Server) ->
|
||||
case jlib:nodeprep(User) of
|
||||
error ->
|
||||
false;
|
||||
LUser ->
|
||||
Username = ejabberd_odbc:escape(LUser),
|
||||
LServer = jlib:nameprep(Server),
|
||||
try odbc_queries:get_password(LServer, Username) of
|
||||
{selected, ["password"], [{_Password}]} ->
|
||||
try
|
||||
LUser = exmpp_stringprep:nodeprep(User),
|
||||
Username = ejabberd_odbc:escape(LUser),
|
||||
LServer = exmpp_stringprep:nameprep(Server),
|
||||
try odbc_queries:get_password(LServer, Username) of
|
||||
{selected, ["password"], [{_Password}]} ->
|
||||
true; %% Account exists
|
||||
{selected, ["password"], []} ->
|
||||
false; %% Account does not exist
|
||||
@@ -237,45 +312,57 @@ is_user_exists(User, Server) ->
|
||||
catch
|
||||
_:B ->
|
||||
{error, B} %% Typical error is database not accessible
|
||||
end
|
||||
end
|
||||
catch
|
||||
_ ->
|
||||
false
|
||||
end.
|
||||
|
||||
%% @spec (User, Server) -> ok | error
|
||||
%% User = string()
|
||||
%% Server = string()
|
||||
%% @doc Remove user.
|
||||
%% Note: it may return ok even if there was some problem removing the user.
|
||||
|
||||
remove_user(User, Server) ->
|
||||
case jlib:nodeprep(User) of
|
||||
error ->
|
||||
error;
|
||||
LUser ->
|
||||
Username = ejabberd_odbc:escape(LUser),
|
||||
LServer = jlib:nameprep(Server),
|
||||
catch odbc_queries:del_user(LServer, Username),
|
||||
ok
|
||||
try
|
||||
LUser = exmpp_stringprep:nodeprep(User),
|
||||
Username = ejabberd_odbc:escape(LUser),
|
||||
LServer = exmpp_stringprep:nameprep(Server),
|
||||
catch odbc_queries:del_user(LServer, Username),
|
||||
ok
|
||||
catch
|
||||
_ ->
|
||||
error
|
||||
end.
|
||||
|
||||
%% @spec (User, Server, Password) -> ok | error | not_exists | not_allowed
|
||||
%% User = string()
|
||||
%% Server = string()
|
||||
%% Password = string()
|
||||
%% @doc Remove user if the provided password is correct.
|
||||
|
||||
remove_user(User, Server, Password) ->
|
||||
case jlib:nodeprep(User) of
|
||||
error ->
|
||||
error;
|
||||
LUser ->
|
||||
Username = ejabberd_odbc:escape(LUser),
|
||||
Pass = ejabberd_odbc:escape(Password),
|
||||
LServer = jlib:nameprep(Server),
|
||||
F = fun() ->
|
||||
Result = odbc_queries:del_user_return_password(
|
||||
LServer, Username, Pass),
|
||||
case Result of
|
||||
{selected, ["password"], [{Password}]} ->
|
||||
ok;
|
||||
{selected, ["password"], []} ->
|
||||
not_exists;
|
||||
_ ->
|
||||
not_allowed
|
||||
end
|
||||
end,
|
||||
{atomic, Result} = odbc_queries:sql_transaction(LServer, F),
|
||||
Result
|
||||
try
|
||||
LUser = exmpp_stringprep:nodeprep(User),
|
||||
Username = ejabberd_odbc:escape(LUser),
|
||||
Pass = ejabberd_odbc:escape(Password),
|
||||
LServer = exmpp_stringprep:nameprep(Server),
|
||||
F = fun() ->
|
||||
Result = odbc_queries:del_user_return_password(
|
||||
LServer, Username, Pass),
|
||||
case Result of
|
||||
{selected, ["password"], [{Password}]} ->
|
||||
ok;
|
||||
{selected, ["password"], []} ->
|
||||
not_exists;
|
||||
_ ->
|
||||
not_allowed
|
||||
end
|
||||
end,
|
||||
{atomic, Result} = odbc_queries:sql_transaction(LServer, F),
|
||||
Result
|
||||
catch
|
||||
_ ->
|
||||
error
|
||||
end.
|
||||
|
||||
@@ -45,6 +45,10 @@
|
||||
%%====================================================================
|
||||
%% API
|
||||
%%====================================================================
|
||||
|
||||
%% @spec (Host) -> ok | term()
|
||||
%% Host = string()
|
||||
|
||||
start(_Host) ->
|
||||
case epam:start() of
|
||||
{ok, _} -> ok;
|
||||
@@ -52,65 +56,125 @@ start(_Host) ->
|
||||
Err -> Err
|
||||
end.
|
||||
|
||||
%% @spec (User, Server, Password) -> {error, not_allowed}
|
||||
%% User = string()
|
||||
%% Server = string()
|
||||
%% Password = string()
|
||||
|
||||
set_password(_User, _Server, _Password) ->
|
||||
{error, not_allowed}.
|
||||
|
||||
check_password(User, Server, Password, _Digest, _DigestGen) ->
|
||||
%% @spec (User, Server, Password, Digest, DigestGen) -> bool()
|
||||
%% User = string()
|
||||
%% Server = string()
|
||||
%% Password = string()
|
||||
%% Digest = string()
|
||||
%% DigestGen = function()
|
||||
|
||||
check_password(User, Server, Password, _StreamID, _Digest) ->
|
||||
check_password(User, Server, Password).
|
||||
|
||||
check_password(User, Host, Password) ->
|
||||
Service = get_pam_service(Host),
|
||||
UserInfo = case get_pam_userinfotype(Host) of
|
||||
%% @spec (User, Server, Password) -> bool()
|
||||
%% User = string()
|
||||
%% Server = string()
|
||||
%% Password = string()
|
||||
|
||||
check_password(User, Server, Password) ->
|
||||
Service = get_pam_service(Server),
|
||||
UserInfo = case get_pam_userinfotype(Server) of
|
||||
username -> User;
|
||||
jid -> User++"@"++Host
|
||||
jid -> User++"@"++Server
|
||||
end,
|
||||
case catch epam:authenticate(Service, UserInfo, Password) of
|
||||
true -> true;
|
||||
_ -> false
|
||||
end.
|
||||
|
||||
%% @spec (User, Server, Password) -> {error, not_allowed}
|
||||
%% User = string()
|
||||
%% Server = string()
|
||||
%% Password = string()
|
||||
|
||||
try_register(_User, _Server, _Password) ->
|
||||
{error, not_allowed}.
|
||||
|
||||
%% @spec () -> [{LUser, LServer}]
|
||||
%% LUser = string()
|
||||
%% LServer = string()
|
||||
|
||||
dirty_get_registered_users() ->
|
||||
[].
|
||||
|
||||
get_vh_registered_users(_Host) ->
|
||||
%% @spec (Server) -> [{LUser, LServer}]
|
||||
%% Server = string()
|
||||
%% LUser = string()
|
||||
%% LServer = string()
|
||||
|
||||
get_vh_registered_users(_Server) ->
|
||||
[].
|
||||
|
||||
%% @spec (User, Server) -> Password | false
|
||||
%% User = string()
|
||||
%% Server = string()
|
||||
%% Password = string()
|
||||
|
||||
get_password(_User, _Server) ->
|
||||
false.
|
||||
|
||||
%% @spec (User, Server) -> Password | nil()
|
||||
%% User = string()
|
||||
%% Server = string()
|
||||
%% Password = string()
|
||||
|
||||
get_password_s(_User, _Server) ->
|
||||
"".
|
||||
|
||||
%% @spec (User, Server) -> true | false | {error, Error}
|
||||
%% TODO: Improve this function to return an error instead of 'false' when connection to PAM failed
|
||||
is_user_exists(User, Host) ->
|
||||
Service = get_pam_service(Host),
|
||||
UserInfo = case get_pam_userinfotype(Host) of
|
||||
%% User = string()
|
||||
%% Server = string()
|
||||
%% TODO: Improve this function to return an error instead of 'false' when
|
||||
%% connection to PAM failed
|
||||
|
||||
is_user_exists(User, Server) ->
|
||||
Service = get_pam_service(Server),
|
||||
UserInfo = case get_pam_userinfotype(Server) of
|
||||
username -> User;
|
||||
jid -> User++"@"++Host
|
||||
jid -> User++"@"++Server
|
||||
end,
|
||||
case catch epam:acct_mgmt(Service, UserInfo) of
|
||||
true -> true;
|
||||
_ -> false
|
||||
end.
|
||||
|
||||
%% @spec (User, Server) -> {error, not_allowed}
|
||||
%% User = string()
|
||||
%% Server = string()
|
||||
|
||||
remove_user(_User, _Server) ->
|
||||
{error, not_allowed}.
|
||||
|
||||
%% @spec (User, Server, Password) -> not_allowed
|
||||
%% User = string()
|
||||
%% Server = string()
|
||||
%% Password = string()
|
||||
|
||||
remove_user(_User, _Server, _Password) ->
|
||||
not_allowed.
|
||||
|
||||
%% @spec () -> bool()
|
||||
|
||||
plain_password_required() ->
|
||||
true.
|
||||
|
||||
%%====================================================================
|
||||
%% Internal functions
|
||||
%%====================================================================
|
||||
get_pam_service(Host) ->
|
||||
case ejabberd_config:get_local_option({pam_service, Host}) of
|
||||
|
||||
%% @spec (Server) -> string()
|
||||
%% Server = string()
|
||||
|
||||
get_pam_service(Server) ->
|
||||
case ejabberd_config:get_local_option({pam_service, Server}) of
|
||||
undefined -> "ejabberd";
|
||||
Service -> Service
|
||||
end.
|
||||
|
||||
@@ -0,0 +1,475 @@
|
||||
%%%----------------------------------------------------------------------
|
||||
%%% File : ejabberd_auth_storage.erl
|
||||
%%% Author : Alexey Shchepin <alexey@process-one.net>, Stephan Maka
|
||||
%%% Purpose : Authentification via gen_storage
|
||||
%%% Created : 12 Dec 2004 by Alexey Shchepin <alexey@process-one.net>
|
||||
%%%
|
||||
%%%
|
||||
%%% ejabberd, Copyright (C) 2002-2010 ProcessOne
|
||||
%%%
|
||||
%%% This program is free software; you can redistribute it and/or
|
||||
%%% modify it under the terms of the GNU General Public License as
|
||||
%%% published by the Free Software Foundation; either version 2 of the
|
||||
%%% License, or (at your option) any later version.
|
||||
%%%
|
||||
%%% This program is distributed in the hope that it will be useful,
|
||||
%%% but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
%%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
%%% General Public License for more details.
|
||||
%%%
|
||||
%%% You should have received a copy of the GNU General Public License
|
||||
%%% along with this program; if not, write to the Free Software
|
||||
%%% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||
%%% 02111-1307 USA
|
||||
%%%
|
||||
%%%----------------------------------------------------------------------
|
||||
|
||||
%%% Database schema (version / storage / table)
|
||||
%%%
|
||||
%%% 2.1.x / mnesia / passwd
|
||||
%%% us = {Username::string(), Host::string()}
|
||||
%%% password = string()
|
||||
%%%
|
||||
%%% 2.1.x / odbc / users
|
||||
%%% username = varchar250
|
||||
%%% password = text
|
||||
%%%
|
||||
%%% 3.0.0-prealpha / mnesia / passwd
|
||||
%%% Same as 2.1.x
|
||||
%%%
|
||||
%%% 3.0.0-prealpha / odbc / users
|
||||
%%% Same as 2.1.x
|
||||
%%%
|
||||
%%% 3.0.0-alpha / mnesia / passwd
|
||||
%%% user_host = {Username::string(), Host::string()}
|
||||
%%% password = string()
|
||||
%%%
|
||||
%%% 3.0.0-alpha / odbc / passwd
|
||||
%%% user = varchar150
|
||||
%%% host = varchar150
|
||||
%%% password = text
|
||||
|
||||
-module(ejabberd_auth_storage).
|
||||
-author('alexey@process-one.net').
|
||||
|
||||
%% External exports
|
||||
-export([start/1,
|
||||
set_password/3,
|
||||
check_password/3,
|
||||
check_password/5,
|
||||
try_register/3,
|
||||
dirty_get_registered_users/0,
|
||||
get_vh_registered_users/1,
|
||||
get_vh_registered_users/2,
|
||||
get_vh_registered_users_number/1,
|
||||
get_vh_registered_users_number/2,
|
||||
get_password/2,
|
||||
get_password_s/2,
|
||||
is_user_exists/2,
|
||||
remove_user/2,
|
||||
remove_user/3,
|
||||
plain_password_required/0
|
||||
]).
|
||||
|
||||
-include("ejabberd.hrl").
|
||||
|
||||
-record(passwd, {user_host, password}).
|
||||
-record(reg_users_counter, {vhost, count}).
|
||||
|
||||
%%%----------------------------------------------------------------------
|
||||
%%% API
|
||||
%%%----------------------------------------------------------------------
|
||||
|
||||
%% @spec (Host) -> ok
|
||||
%% Host = string()
|
||||
|
||||
start(Host) ->
|
||||
Backend =
|
||||
case ejabberd_config:get_local_option({auth_storage, Host}) of
|
||||
undefined -> mnesia;
|
||||
B -> B
|
||||
end,
|
||||
HostB = list_to_binary(Host),
|
||||
gen_storage:create_table(Backend, HostB, passwd,
|
||||
[{odbc_host, Host},
|
||||
{disc_copies, [node()]},
|
||||
{attributes, record_info(fields, passwd)},
|
||||
{types, [{user_host, {text, text}}]}
|
||||
]),
|
||||
update_table(Host, Backend),
|
||||
mnesia:create_table(reg_users_counter,
|
||||
[{ram_copies, [node()]},
|
||||
{attributes, record_info(fields, reg_users_counter)}]),
|
||||
update_reg_users_counter_table(Host),
|
||||
ok.
|
||||
|
||||
update_reg_users_counter_table(Server) ->
|
||||
Set = get_vh_registered_users(Server),
|
||||
Size = length(Set),
|
||||
LServer = exmpp_jid:prep_domain(exmpp_jid:parse(Server)),
|
||||
F = fun() ->
|
||||
mnesia:write(#reg_users_counter{vhost = LServer,
|
||||
count = Size})
|
||||
end,
|
||||
mnesia:sync_dirty(F).
|
||||
|
||||
%% @spec () -> bool()
|
||||
|
||||
plain_password_required() ->
|
||||
false.
|
||||
|
||||
%% @spec (User, Server, Password) -> bool()
|
||||
%% User = string()
|
||||
%% Server = string()
|
||||
%% Password = string()
|
||||
|
||||
check_password(User, Server, Password) ->
|
||||
LUser = exmpp_stringprep:nodeprep(User),
|
||||
LServer = exmpp_stringprep:nameprep(Server),
|
||||
US = {LUser, LServer},
|
||||
case catch gen_storage:dirty_read(LServer, {passwd, US}) of
|
||||
[#passwd{password = Password}] ->
|
||||
Password /= "";
|
||||
_ ->
|
||||
false
|
||||
end.
|
||||
|
||||
%% @spec (User, Server, Password, Digest, DigestGen) -> bool()
|
||||
%% User = string()
|
||||
%% Server = string()
|
||||
%% Password = string()
|
||||
%% Digest = string()
|
||||
%% DigestGen = function()
|
||||
|
||||
check_password(User, Server, Password, Digest, DigestGen) ->
|
||||
LUser = exmpp_stringprep:nodeprep(User),
|
||||
LServer = exmpp_stringprep:nameprep(Server),
|
||||
US = {LUser, LServer},
|
||||
case catch gen_storage:dirty_read(LServer, {passwd, US}) of
|
||||
[#passwd{password = Passwd}] ->
|
||||
DigRes = if
|
||||
Digest /= "" ->
|
||||
Digest == DigestGen(Passwd);
|
||||
true ->
|
||||
false
|
||||
end,
|
||||
if DigRes ->
|
||||
true;
|
||||
true ->
|
||||
(Passwd == Password) and (Password /= "")
|
||||
end;
|
||||
_ ->
|
||||
false
|
||||
end.
|
||||
|
||||
%% @spec (User, Server, Password) -> ok | {error, invalid_jid}
|
||||
%% User = string()
|
||||
%% Server = string()
|
||||
%% Password = string()
|
||||
|
||||
set_password(User, Server, Password) ->
|
||||
LUser = (catch exmpp_stringprep:nodeprep(User)),
|
||||
LServer = (catch exmpp_stringprep:nameprep(Server)),
|
||||
case {LUser, LServer} of
|
||||
{{stringprep, _, invalid_string, _}, _} ->
|
||||
{error, invalid_jid};
|
||||
{_, {stringprep, _, invalid_string, _}} ->
|
||||
{error, invalid_jid};
|
||||
US ->
|
||||
%% TODO: why is this a transaction?
|
||||
F = fun() ->
|
||||
gen_storage:write(LServer,
|
||||
#passwd{user_host = US,
|
||||
password = Password})
|
||||
end,
|
||||
{atomic, ok} = gen_storage:transaction(LServer, passwd, F),
|
||||
ok
|
||||
end.
|
||||
|
||||
%% @spec (User, Server, Password) -> {atomic, ok} | {atomic, exists} | {error, invalid_jid} | {aborted, Reason}
|
||||
%% User = string()
|
||||
%% Server = string()
|
||||
%% Password = string()
|
||||
|
||||
try_register(User, Server, Password) ->
|
||||
LUser = (catch exmpp_stringprep:nodeprep(User)),
|
||||
LServer = (catch exmpp_stringprep:nameprep(Server)),
|
||||
case {LUser, LServer} of
|
||||
{{stringprep, _, invalid_string, _}, _} ->
|
||||
{error, invalid_jid};
|
||||
{_, {stringprep, _, invalid_string, _}} ->
|
||||
{error, invalid_jid};
|
||||
US ->
|
||||
F = fun() ->
|
||||
case gen_storage:read(LServer, {passwd, US}) of
|
||||
[] ->
|
||||
gen_storage:write(LServer,
|
||||
#passwd{user_host = US,
|
||||
password = Password}),
|
||||
mnesia:dirty_update_counter(
|
||||
reg_users_counter,
|
||||
exmpp_jid:prep_domain(exmpp_jid:parse(Server)), 1),
|
||||
ok;
|
||||
[_E] ->
|
||||
exists
|
||||
end
|
||||
end,
|
||||
%% TODO: transaction return value?
|
||||
gen_storage:transaction(LServer, passwd, F)
|
||||
end.
|
||||
|
||||
%% @spec () -> [{LUser, LServer}]
|
||||
%% LUser = string()
|
||||
%% LServer = string()
|
||||
%% @doc Get all registered users in Mnesia.
|
||||
|
||||
dirty_get_registered_users() ->
|
||||
%% TODO:
|
||||
exit(not_implemented).
|
||||
|
||||
%% @spec (Server) -> [{LUser, LServer}]
|
||||
%% Server = string()
|
||||
%% LUser = string()
|
||||
%% LServer = string()
|
||||
|
||||
get_vh_registered_users(Server) ->
|
||||
LServer = exmpp_stringprep:nameprep(Server),
|
||||
lists:map(fun(#passwd{user_host = US}) ->
|
||||
US
|
||||
end,
|
||||
gen_storage:dirty_select(LServer, passwd,
|
||||
[{'=', user_host, {'_', LServer}}])).
|
||||
|
||||
%% @spec (Server, Opts) -> [{LUser, LServer}]
|
||||
%% Server = string()
|
||||
%% Opts = [{Opt, Val}]
|
||||
%% Opt = atom()
|
||||
%% Val = term()
|
||||
%% LUser = string()
|
||||
%% LServer = string()
|
||||
%% @doc Return the registered users for the specified host.
|
||||
%%
|
||||
%% `Opts' can be one of the following:
|
||||
%% <ul>
|
||||
%% <li>`[{from, integer()}, {to, integer()}]'</li>
|
||||
%% <li>`[{limit, integer()}, {offset, integer()}]'</li>
|
||||
%% <li>`[{prefix, string()}]'</li>
|
||||
%% <li>`[{prefix, string()}, {from, integer()}, {to, integer()}]'</li>
|
||||
%% <li>`[{prefix, string()}, {limit, integer()}, {offset, integer()}]'</li>
|
||||
%% </ul>
|
||||
|
||||
get_vh_registered_users(Server, [{from, Start}, {to, End}])
|
||||
when is_integer(Start) and is_integer(End) ->
|
||||
get_vh_registered_users(Server, [{limit, End-Start+1}, {offset, Start}]);
|
||||
|
||||
get_vh_registered_users(Server, [{limit, Limit}, {offset, Offset}])
|
||||
when is_integer(Limit) and is_integer(Offset) ->
|
||||
case get_vh_registered_users(Server) of
|
||||
[] ->
|
||||
[];
|
||||
Users ->
|
||||
Set = lists:keysort(1, Users),
|
||||
L = length(Set),
|
||||
Start = if Offset < 1 -> 1;
|
||||
Offset > L -> L;
|
||||
true -> Offset
|
||||
end,
|
||||
lists:sublist(Set, Start, Limit)
|
||||
end;
|
||||
|
||||
get_vh_registered_users(Server, [{prefix, Prefix}])
|
||||
when is_list(Prefix) ->
|
||||
Set = [{U,S} || {U, S} <- get_vh_registered_users(Server), lists:prefix(Prefix, U)],
|
||||
lists:keysort(1, Set);
|
||||
|
||||
get_vh_registered_users(Server, [{prefix, Prefix}, {from, Start}, {to, End}])
|
||||
when is_list(Prefix) and is_integer(Start) and is_integer(End) ->
|
||||
get_vh_registered_users(Server, [{prefix, Prefix}, {limit, End-Start+1}, {offset, Start}]);
|
||||
|
||||
get_vh_registered_users(Server, [{prefix, Prefix}, {limit, Limit}, {offset, Offset}])
|
||||
when is_list(Prefix) and is_integer(Limit) and is_integer(Offset) ->
|
||||
case [{U,S} || {U, S} <- get_vh_registered_users(Server), lists:prefix(Prefix, U)] of
|
||||
[] ->
|
||||
[];
|
||||
Users ->
|
||||
Set = lists:keysort(1, Users),
|
||||
L = length(Set),
|
||||
Start = if Offset < 1 -> 1;
|
||||
Offset > L -> L;
|
||||
true -> Offset
|
||||
end,
|
||||
lists:sublist(Set, Start, Limit)
|
||||
end;
|
||||
|
||||
get_vh_registered_users(Server, _) ->
|
||||
get_vh_registered_users(Server).
|
||||
|
||||
%% @spec (Server) -> Users_Number
|
||||
%% Server = string()
|
||||
%% Users_Number = integer()
|
||||
|
||||
get_vh_registered_users_number(Server) ->
|
||||
LServer = exmpp_jid:prep_domain(exmpp_jid:parse(Server)),
|
||||
Query = mnesia:dirty_select(
|
||||
reg_users_counter,
|
||||
[{#reg_users_counter{vhost = LServer, count = '$1'},
|
||||
[],
|
||||
['$1']}]),
|
||||
case Query of
|
||||
[Count] ->
|
||||
Count;
|
||||
_ -> 0
|
||||
end.
|
||||
|
||||
%% @spec (Server, [{prefix, Prefix}]) -> Users_Number
|
||||
%% Server = string()
|
||||
%% Prefix = string()
|
||||
%% Users_Number = integer()
|
||||
|
||||
get_vh_registered_users_number(Server, [{prefix, Prefix}]) when is_list(Prefix) ->
|
||||
Set = [{U, S} || {U, S} <- get_vh_registered_users(Server), lists:prefix(Prefix, U)],
|
||||
length(Set);
|
||||
|
||||
get_vh_registered_users_number(Server, _) ->
|
||||
get_vh_registered_users_number(Server).
|
||||
|
||||
%% @spec (User, Server) -> Password | false
|
||||
%% User = string()
|
||||
%% Server = string()
|
||||
%% Password = string()
|
||||
|
||||
get_password(User, Server) ->
|
||||
try
|
||||
LUser = exmpp_stringprep:nodeprep(User),
|
||||
LServer = exmpp_stringprep:nameprep(Server),
|
||||
US = {LUser, LServer},
|
||||
case catch gen_storage:dirty_read(LServer, passwd, US) of
|
||||
[#passwd{password = Password}] ->
|
||||
Password;
|
||||
_ ->
|
||||
false
|
||||
end
|
||||
catch
|
||||
_ ->
|
||||
false
|
||||
end.
|
||||
|
||||
%% @spec (User, Server) -> Password | nil()
|
||||
%% User = string()
|
||||
%% Server = string()
|
||||
%% Password = string()
|
||||
|
||||
get_password_s(User, Server) ->
|
||||
try
|
||||
LUser = exmpp_stringprep:nodeprep(User),
|
||||
LServer = exmpp_stringprep:nameprep(Server),
|
||||
US = {LUser, LServer},
|
||||
case catch gen_storage:dirty_read(LServer, passwd, US) of
|
||||
[#passwd{password = Password}] ->
|
||||
Password;
|
||||
_ ->
|
||||
[]
|
||||
end
|
||||
catch
|
||||
_ ->
|
||||
[]
|
||||
end.
|
||||
|
||||
%% @spec (User, Server) -> true | false | {error, Error}
|
||||
%% User = string()
|
||||
%% Server = string()
|
||||
|
||||
is_user_exists(User, Server) ->
|
||||
try
|
||||
LUser = exmpp_stringprep:nodeprep(User),
|
||||
LServer = exmpp_stringprep:nameprep(Server),
|
||||
US = {LUser, LServer},
|
||||
case catch gen_storage:dirty_read(LServer, {passwd, US}) of
|
||||
[] ->
|
||||
false;
|
||||
[_] ->
|
||||
true;
|
||||
Other ->
|
||||
{error, Other}
|
||||
end
|
||||
catch
|
||||
_ ->
|
||||
false
|
||||
end.
|
||||
|
||||
%% @spec (User, Server) -> ok
|
||||
%% User = string()
|
||||
%% Server = string()
|
||||
%% @doc Remove user.
|
||||
%% Note: it returns ok even if there was some problem removing the user.
|
||||
|
||||
remove_user(User, Server) ->
|
||||
try
|
||||
LUser = exmpp_stringprep:nodeprep(User),
|
||||
LServer = exmpp_stringprep:nameprep(Server),
|
||||
US = {LUser, LServer},
|
||||
F = fun() ->
|
||||
gen_storage:delete(LServer, {passwd, US}),
|
||||
mnesia:dirty_update_counter(reg_users_counter,
|
||||
exmpp_jid:prep_domain(exmpp_jid:parse(Server)), -1)
|
||||
end,
|
||||
gen_storage:transaction(LServer, passwd, F),
|
||||
ok
|
||||
catch
|
||||
_ ->
|
||||
ok
|
||||
end.
|
||||
|
||||
%% @spec (User, Server, Password) -> ok | not_exists | not_allowed | bad_request
|
||||
%% User = string()
|
||||
%% Server = string()
|
||||
%% Password = string()
|
||||
%% @doc Remove user if the provided password is correct.
|
||||
|
||||
remove_user(User, Server, Password) ->
|
||||
try
|
||||
LUser = exmpp_stringprep:nodeprep(User),
|
||||
LServer = exmpp_stringprep:nameprep(Server),
|
||||
US = {LUser, LServer},
|
||||
F = fun() ->
|
||||
case gen_storage:read(LServer, {passwd, US}) of
|
||||
[#passwd{password = Password}] ->
|
||||
gen_storage:delete(LServer, {passwd, US}),
|
||||
mnesia:dirty_update_counter(reg_users_counter,
|
||||
exmpp_jid:prep_domain(exmpp_jid:parse(Server)), -1),
|
||||
ok;
|
||||
[_] ->
|
||||
not_allowed;
|
||||
_ ->
|
||||
not_exists
|
||||
end
|
||||
end,
|
||||
case gen_storage:transaction(LServer, passwd, F) of
|
||||
{atomic, ok} ->
|
||||
ok;
|
||||
{atomic, Res} ->
|
||||
Res;
|
||||
_ ->
|
||||
bad_request
|
||||
end
|
||||
catch
|
||||
_ ->
|
||||
bad_request
|
||||
end.
|
||||
|
||||
update_table(Host, mnesia) ->
|
||||
gen_storage_migration:migrate_mnesia(
|
||||
Host, passwd,
|
||||
[{passwd, [us, password],
|
||||
fun({passwd, {User, _Host}, Password}) ->
|
||||
#passwd{user_host = {User, Host},
|
||||
password = Password}
|
||||
end}]);
|
||||
update_table(Host, odbc) ->
|
||||
gen_storage_migration:migrate_odbc(
|
||||
Host, [passwd],
|
||||
[{"users", ["username", "password"],
|
||||
fun(_, User, Password) ->
|
||||
#passwd{user_host = {User, Host},
|
||||
password = Password}
|
||||
end}]).
|
||||
@@ -35,33 +35,41 @@
|
||||
-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
|
||||
terminate/2, code_change/3]).
|
||||
|
||||
-export([create_captcha/6, build_captcha_html/2, check_captcha/2,
|
||||
process_reply/1, process/2, is_feature_available/0,
|
||||
create_captcha_x/4, create_captcha_x/5]).
|
||||
-export([create_captcha/5, build_captcha_html/2, check_captcha/2,
|
||||
process_reply/1, process/2, is_feature_available/0]).
|
||||
|
||||
-include_lib("exmpp/include/exmpp.hrl").
|
||||
|
||||
-include("jlib.hrl").
|
||||
-include("ejabberd.hrl").
|
||||
-include("web/ejabberd_http.hrl").
|
||||
|
||||
-define(VFIELD(Type, Var, Value),
|
||||
{xmlelement, "field", [{"type", Type}, {"var", Var}],
|
||||
[{xmlelement, "value", [], [Value]}]}).
|
||||
#xmlel{name = 'field',
|
||||
attrs = [
|
||||
#xmlattr{
|
||||
name = 'type',
|
||||
value = Type
|
||||
},
|
||||
#xmlattr{
|
||||
name = 'var',
|
||||
value = Var
|
||||
}
|
||||
],
|
||||
children = [
|
||||
#xmlel{
|
||||
name = 'value',
|
||||
children = [Value]
|
||||
}
|
||||
]}).
|
||||
|
||||
-define(CAPTCHA_TEXT(Lang), translate:translate(Lang, "Enter the text you see")).
|
||||
-define(CAPTCHA_LIFETIME, 120000). % two minutes
|
||||
-define(RPC_TIMEOUT, 5000).
|
||||
|
||||
-record(state, {}).
|
||||
-record(captcha, {id, pid, key, tref, args}).
|
||||
|
||||
-define(T(S),
|
||||
case catch mnesia:transaction(fun() -> S end) of
|
||||
{atomic, Res} ->
|
||||
Res;
|
||||
{_, Reason} ->
|
||||
?ERROR_MSG("mnesia transaction failed: ~p", [Reason]),
|
||||
{error, Reason}
|
||||
end).
|
||||
|
||||
%%====================================================================
|
||||
%% API
|
||||
%%====================================================================
|
||||
@@ -72,97 +80,142 @@
|
||||
start_link() ->
|
||||
gen_server:start_link({local, ?MODULE}, ?MODULE, [], []).
|
||||
|
||||
create_captcha(Id, SID, From, To, Lang, Args)
|
||||
when is_list(Id), is_list(Lang), is_list(SID),
|
||||
is_record(From, jid), is_record(To, jid) ->
|
||||
create_captcha(SID, From, To, Lang, Args)
|
||||
when is_binary(Lang), is_list(SID) ->
|
||||
case create_image() of
|
||||
{ok, Type, Key, Image} ->
|
||||
Id = randoms:get_string() ++ "-" ++ ejabberd_cluster:node_id(),
|
||||
B64Image = jlib:encode_base64(binary_to_list(Image)),
|
||||
JID = jlib:jid_to_string(From),
|
||||
JID = exmpp_jid:to_list(From),
|
||||
CID = "sha1+" ++ sha:sha(Image) ++ "@bob.xmpp.org",
|
||||
Data = {xmlelement, "data",
|
||||
[{"xmlns", ?NS_BOB}, {"cid", CID},
|
||||
{"max-age", "0"}, {"type", Type}],
|
||||
[{xmlcdata, B64Image}]},
|
||||
% Data = {xmlelement, "data",
|
||||
% [{"xmlns", ?NS_BOB}, {"cid", CID},
|
||||
% {"max-age", "0"}, {"type", Type}],
|
||||
% [{xmlcdata, B64Image}]},
|
||||
Data =
|
||||
#xmlel{
|
||||
name = 'data',
|
||||
ns = ?NS_BOB,
|
||||
attrs = [
|
||||
#xmlattr{
|
||||
name = 'cid',
|
||||
value = CID
|
||||
},
|
||||
#xmlattr{
|
||||
name = 'max-age',
|
||||
value = "0"
|
||||
},
|
||||
#xmlattr{
|
||||
name = 'type',
|
||||
value = Type
|
||||
}
|
||||
],
|
||||
children = [#xmlcdata{cdata = B64Image}]},
|
||||
% {xmlelement, "captcha", [{"xmlns", ?NS_CAPTCHA}],
|
||||
% %% ?NS_DATA_FORMS is 'jabber:x:data'
|
||||
% [{xmlelement, "x", [{"xmlns", "jabber:x:data"}, {"type", "form"}],
|
||||
% [?VFIELD("hidden", "FORM_TYPE", {xmlcdata, ?NS_CAPTCHA}),
|
||||
% ?VFIELD("hidden", "from", {xmlcdata, exmpp_jid:to_list(To)}),
|
||||
% ?VFIELD("hidden", "challenge", {xmlcdata, Id}),
|
||||
% ?VFIELD("hidden", "sid", {xmlcdata, SID}),
|
||||
% {xmlelement, "field", [{"var", "ocr"}, {"label", ?CAPTCHA_TEXT(Lang)}],
|
||||
% [{xmlelement, "media", [{"xmlns", ?NS_DATA_FORMS_MEDIA_s}],
|
||||
% [{xmlelement, "uri", [{"type", Type}],
|
||||
% [{xmlcdata, "cid:" ++ CID}]}]}]}]}]},
|
||||
%% TODO : kael : write exmpp_captcha.erl
|
||||
Captcha =
|
||||
{xmlelement, "captcha", [{"xmlns", ?NS_CAPTCHA}],
|
||||
[{xmlelement, "x", [{"xmlns", ?NS_XDATA}, {"type", "form"}],
|
||||
[?VFIELD("hidden", "FORM_TYPE", {xmlcdata, ?NS_CAPTCHA}),
|
||||
?VFIELD("hidden", "from", {xmlcdata, jlib:jid_to_string(To)}),
|
||||
?VFIELD("hidden", "challenge", {xmlcdata, Id}),
|
||||
?VFIELD("hidden", "sid", {xmlcdata, SID}),
|
||||
{xmlelement, "field", [{"var", "ocr"}, {"label", ?CAPTCHA_TEXT(Lang)}],
|
||||
[{xmlelement, "required", [], []},
|
||||
{xmlelement, "media", [{"xmlns", ?NS_MEDIA}],
|
||||
[{xmlelement, "uri", [{"type", Type}],
|
||||
[{xmlcdata, "cid:" ++ CID}]}]}]}]}]},
|
||||
#xmlel{
|
||||
name = 'captcha',
|
||||
ns = ?NS_CAPTCHA,
|
||||
children = [
|
||||
#xmlel{
|
||||
name = 'x',
|
||||
ns = ?NS_DATA_FORMS_s,
|
||||
attrs = [
|
||||
#xmlattr{
|
||||
name = 'type',
|
||||
value = "form"
|
||||
}
|
||||
],
|
||||
children = [
|
||||
?VFIELD("hidden", "FORM_TYPE", #xmlcdata{cdata = ?NS_CAPTCHA}),
|
||||
?VFIELD("hidden", "from", #xmlcdata{cdata = exmpp_jid:to_list(To)}),
|
||||
?VFIELD("hidden", "challenge", #xmlcdata{cdata = Id}),
|
||||
?VFIELD("hidden", "sid", #xmlcdata{cdata = SID}),
|
||||
#xmlel{
|
||||
name = 'field',
|
||||
attrs = [
|
||||
#xmlattr{
|
||||
name = 'var',
|
||||
value = "ocr"
|
||||
},
|
||||
#xmlattr{
|
||||
name = 'label',
|
||||
value = ?CAPTCHA_TEXT(Lang)
|
||||
}
|
||||
],
|
||||
children = [
|
||||
#xmlel{
|
||||
name = 'media',
|
||||
ns = ?NS_DATA_FORMS_MEDIA_s,
|
||||
children = [
|
||||
#xmlel{
|
||||
name = 'uri',
|
||||
attrs = [
|
||||
#xmlattr{
|
||||
name = 'type',
|
||||
value = Type
|
||||
}
|
||||
],
|
||||
children = [
|
||||
#xmlcdata{cdata = "cid:" ++ CID}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
BodyString1 = translate:translate(Lang, "Your messages to ~s are being blocked. To unblock them, visit ~s"),
|
||||
BodyString = io_lib:format(BodyString1, [JID, get_url(Id)]),
|
||||
Body = {xmlelement, "body", [],
|
||||
[{xmlcdata, BodyString}]},
|
||||
OOB = {xmlelement, "x", [{"xmlns", ?NS_OOB}],
|
||||
[{xmlelement, "url", [], [{xmlcdata, get_url(Id)}]}]},
|
||||
Body =
|
||||
#xmlel{
|
||||
name = 'body',
|
||||
children = [
|
||||
#xmlcdata{
|
||||
cdata = BodyString
|
||||
}
|
||||
]
|
||||
},
|
||||
OOB =
|
||||
#xmlel{
|
||||
name = 'x',
|
||||
ns = ?NS_OOBD_X_s,
|
||||
children = [
|
||||
#xmlel{
|
||||
name = 'url',
|
||||
children = [
|
||||
#xmlcdata{
|
||||
cdata = get_url(Id)}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
%Body = {xmlelement, "body", [],
|
||||
% [{xmlcdata, BodyString}]},
|
||||
%OOB = {xmlelement, "x", [{"xmlns", ?NS_OOBD_X_s}],
|
||||
% [{xmlelement, "url", [], [{xmlcdata, get_url(Id)}]}]},
|
||||
Tref = erlang:send_after(?CAPTCHA_LIFETIME, ?MODULE, {remove_id, Id}),
|
||||
case ?T(mnesia:write(#captcha{id=Id, pid=self(), key=Key,
|
||||
tref=Tref, args=Args})) of
|
||||
ok ->
|
||||
{ok, [Body, OOB, Captcha, Data]};
|
||||
_Err ->
|
||||
error
|
||||
end;
|
||||
ets:insert(captcha, #captcha{id=Id, pid=self(), key=Key,
|
||||
tref=Tref, args=Args}),
|
||||
{ok, Id, [Body, OOB, Captcha, Data]};
|
||||
_Err ->
|
||||
error
|
||||
end.
|
||||
|
||||
create_captcha_x(SID, To, Lang, HeadEls) ->
|
||||
create_captcha_x(SID, To, Lang, HeadEls, []).
|
||||
|
||||
create_captcha_x(SID, To, Lang, HeadEls, TailEls) ->
|
||||
case create_image() of
|
||||
{ok, Type, Key, Image} ->
|
||||
Id = randoms:get_string(),
|
||||
B64Image = jlib:encode_base64(binary_to_list(Image)),
|
||||
CID = "sha1+" ++ sha:sha(Image) ++ "@bob.xmpp.org",
|
||||
Data = {xmlelement, "data",
|
||||
[{"xmlns", ?NS_BOB}, {"cid", CID},
|
||||
{"max-age", "0"}, {"type", Type}],
|
||||
[{xmlcdata, B64Image}]},
|
||||
HelpTxt = translate:translate(
|
||||
Lang,
|
||||
"If you don't see the CAPTCHA image here, "
|
||||
"visit the web page."),
|
||||
Imageurl = get_url(Id ++ "/image"),
|
||||
Captcha =
|
||||
{xmlelement, "x", [{"xmlns", ?NS_XDATA}, {"type", "form"}],
|
||||
[?VFIELD("hidden", "FORM_TYPE", {xmlcdata, ?NS_CAPTCHA}) | HeadEls] ++
|
||||
[{xmlelement, "field", [{"type", "fixed"}],
|
||||
[{xmlelement, "value", [], [{xmlcdata, HelpTxt}]}]},
|
||||
{xmlelement, "field", [{"type", "hidden"}, {"var", "captchahidden"}],
|
||||
[{xmlelement, "value", [], [{xmlcdata, "workaround-for-psi"}]}]},
|
||||
{xmlelement, "field",
|
||||
[{"type", "text-single"},
|
||||
{"label", translate:translate(Lang, "CAPTCHA web page")},
|
||||
{"var", "url"}],
|
||||
[{xmlelement, "value", [], [{xmlcdata, Imageurl}]}]},
|
||||
?VFIELD("hidden", "from", {xmlcdata, jlib:jid_to_string(To)}),
|
||||
?VFIELD("hidden", "challenge", {xmlcdata, Id}),
|
||||
?VFIELD("hidden", "sid", {xmlcdata, SID}),
|
||||
{xmlelement, "field", [{"var", "ocr"}, {"label", ?CAPTCHA_TEXT(Lang)}],
|
||||
[{xmlelement, "required", [], []},
|
||||
{xmlelement, "media", [{"xmlns", ?NS_MEDIA}],
|
||||
[{xmlelement, "uri", [{"type", Type}],
|
||||
[{xmlcdata, "cid:" ++ CID}]}]}]}] ++ TailEls},
|
||||
Tref = erlang:send_after(?CAPTCHA_LIFETIME, ?MODULE, {remove_id, Id}),
|
||||
case ?T(mnesia:write(#captcha{id=Id, key=Key, tref=Tref})) of
|
||||
ok ->
|
||||
{ok, [Captcha, Data]};
|
||||
_Err ->
|
||||
error
|
||||
end;
|
||||
_ ->
|
||||
error
|
||||
end.
|
||||
|
||||
%% @spec (Id::string(), Lang::string()) -> {FormEl, {ImgEl, TextEl, IdEl, KeyEl}} | captcha_not_found
|
||||
%% where FormEl = xmlelement()
|
||||
%% ImgEl = xmlelement()
|
||||
@@ -170,30 +223,127 @@ create_captcha_x(SID, To, Lang, HeadEls, TailEls) ->
|
||||
%% IdEl = xmlelement()
|
||||
%% KeyEl = xmlelement()
|
||||
build_captcha_html(Id, Lang) ->
|
||||
case mnesia:dirty_read(captcha, Id) of
|
||||
[#captcha{}] ->
|
||||
ImgEl = {xmlelement, "img", [{"src", get_url(Id ++ "/image")}], []},
|
||||
TextEl = {xmlcdata, ?CAPTCHA_TEXT(Lang)},
|
||||
IdEl = {xmlelement, "input", [{"type", "hidden"},
|
||||
{"name", "id"},
|
||||
{"value", Id}], []},
|
||||
KeyEl = {xmlelement, "input", [{"type", "text"},
|
||||
{"name", "key"},
|
||||
{"size", "10"}], []},
|
||||
FormEl = {xmlelement, "form", [{"action", get_url(Id)},
|
||||
{"name", "captcha"},
|
||||
{"method", "POST"}],
|
||||
[ImgEl,
|
||||
{xmlelement, "br", [], []},
|
||||
TextEl,
|
||||
{xmlelement, "br", [], []},
|
||||
IdEl,
|
||||
KeyEl,
|
||||
{xmlelement, "br", [], []},
|
||||
{xmlelement, "input", [{"type", "submit"},
|
||||
{"name", "enter"},
|
||||
{"value", "OK"}], []}
|
||||
]},
|
||||
case lookup_captcha(Id) of
|
||||
{ok, _} ->
|
||||
%ImgEl = {xmlelement, "img", [{"src", get_url(Id ++ "/image")}], []},
|
||||
ImgEl =
|
||||
#xmlel{
|
||||
name = 'img',
|
||||
attrs = [
|
||||
#xmlattr{
|
||||
name = 'src',
|
||||
value = get_url(Id ++ "/image")
|
||||
}
|
||||
]
|
||||
},
|
||||
%TextEl = {xmlcdata, ?CAPTCHA_TEXT(Lang)},
|
||||
TextEl = #xmlcdata{cdata = ?CAPTCHA_TEXT(Lang)},
|
||||
%IdEl = {xmlelement, "input", [{"type", "hidden"},
|
||||
% {"name", "id"},
|
||||
% {"value", Id}], []},
|
||||
IdEl =
|
||||
#xmlel{
|
||||
name = 'input',
|
||||
attrs = [
|
||||
#xmlattr{
|
||||
name = 'type',
|
||||
value = "hidden"
|
||||
},
|
||||
#xmlattr{
|
||||
name = 'name',
|
||||
value = "id"
|
||||
},
|
||||
#xmlattr{
|
||||
name = 'value',
|
||||
value = Id
|
||||
}
|
||||
]
|
||||
},
|
||||
%KeyEl = {xmlelement, "input", [{"type", "text"},
|
||||
% {"name", "key"},
|
||||
% {"size", "10"}], []},
|
||||
KeyEl =
|
||||
#xmlel{
|
||||
name = 'input',
|
||||
attrs = [
|
||||
#xmlattr{
|
||||
name = 'type',
|
||||
value = "text"
|
||||
},
|
||||
#xmlattr{
|
||||
name = 'name',
|
||||
value = "key"
|
||||
},
|
||||
#xmlattr{
|
||||
name = 'size',
|
||||
value = "10"
|
||||
}
|
||||
]
|
||||
},
|
||||
%FormEl = {xmlelement, "form", [{"action", get_url(Id)},
|
||||
% {"name", "captcha"},
|
||||
% {"method", "POST"}],
|
||||
% [ImgEl,
|
||||
% {xmlelement, "br", [], []},
|
||||
% TextEl,
|
||||
% {xmlelement, "br", [], []},
|
||||
% IdEl,
|
||||
% KeyEl,
|
||||
% {xmlelement, "br", [], []},
|
||||
% {xmlelement, "input", [{"type", "submit"},
|
||||
% {"name", "enter"},
|
||||
% {"value", "OK"}], []}
|
||||
% ]},
|
||||
FormEl =
|
||||
#xmlel{
|
||||
name = 'form',
|
||||
attrs = [
|
||||
#xmlattr{
|
||||
name = 'action',
|
||||
value = get_url(Id)
|
||||
},
|
||||
#xmlattr{
|
||||
name = 'name',
|
||||
value = "captcha"
|
||||
},
|
||||
#xmlattr{
|
||||
name = 'method',
|
||||
value = "POST"
|
||||
}
|
||||
],
|
||||
children = [
|
||||
ImgEl,
|
||||
#xmlel{
|
||||
name = 'br'
|
||||
},
|
||||
TextEl,
|
||||
#xmlel{
|
||||
name = 'br'
|
||||
},
|
||||
IdEl,
|
||||
KeyEl,
|
||||
#xmlel{
|
||||
name = 'br'
|
||||
},
|
||||
#xmlel{
|
||||
name = 'input',
|
||||
attrs = [
|
||||
#xmlattr{
|
||||
name = 'type',
|
||||
value = "submit"
|
||||
},
|
||||
#xmlattr{
|
||||
name = 'name',
|
||||
value = "enter"
|
||||
},
|
||||
#xmlattr{
|
||||
name = 'value',
|
||||
value = "OK"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{FormEl, {ImgEl, TextEl, IdEl, KeyEl}};
|
||||
_ ->
|
||||
captcha_not_found
|
||||
@@ -201,83 +351,76 @@ build_captcha_html(Id, Lang) ->
|
||||
|
||||
%% @spec (Id::string(), ProvidedKey::string()) -> captcha_valid | captcha_non_valid | captcha_not_found
|
||||
check_captcha(Id, ProvidedKey) ->
|
||||
?T(case mnesia:read(captcha, Id, write) of
|
||||
[#captcha{pid=Pid, args=Args, key=StoredKey, tref=Tref}] ->
|
||||
mnesia:delete({captcha, Id}),
|
||||
erlang:cancel_timer(Tref),
|
||||
if StoredKey == ProvidedKey ->
|
||||
if is_pid(Pid) ->
|
||||
Pid ! {captcha_succeed, Args};
|
||||
true ->
|
||||
ok
|
||||
end,
|
||||
captcha_valid;
|
||||
true ->
|
||||
if is_pid(Pid) ->
|
||||
Pid ! {captcha_failed, Args};
|
||||
true ->
|
||||
ok
|
||||
end,
|
||||
captcha_non_valid
|
||||
end;
|
||||
_ ->
|
||||
captcha_not_found
|
||||
end).
|
||||
case string:tokens(Id, "-") of
|
||||
[_, NodeID] ->
|
||||
case ejabberd_cluster:get_node_by_id(NodeID) of
|
||||
Node when Node == node() ->
|
||||
do_check_captcha(Id, ProvidedKey);
|
||||
Node ->
|
||||
case catch rpc:call(Node, ?MODULE, check_captcha,
|
||||
[Id, ProvidedKey], ?RPC_TIMEOUT) of
|
||||
{'EXIT', _} ->
|
||||
captcha_not_found;
|
||||
{badrpc, _} ->
|
||||
captcha_not_found;
|
||||
Res ->
|
||||
Res
|
||||
end
|
||||
end;
|
||||
_ ->
|
||||
captcha_not_found
|
||||
end.
|
||||
|
||||
|
||||
process_reply({xmlelement, _, _, _} = El) ->
|
||||
case xml:get_subtag(El, "x") of
|
||||
false ->
|
||||
process_reply(El) ->
|
||||
case {exmpp_xml:element_matches(El, captcha),
|
||||
exmpp_xml:get_element(El, x)} of
|
||||
{false, _} ->
|
||||
{error, malformed};
|
||||
Xdata ->
|
||||
{_, undefined} ->
|
||||
{error, malformed};
|
||||
{true, Xdata} ->
|
||||
Fields = jlib:parse_xdata_submit(Xdata),
|
||||
case catch {proplists:get_value("challenge", Fields),
|
||||
proplists:get_value("ocr", Fields)} of
|
||||
case {proplists:get_value("challenge", Fields),
|
||||
proplists:get_value("ocr", Fields)} of
|
||||
{[Id|_], [OCR|_]} ->
|
||||
?T(case mnesia:read(captcha, Id, write) of
|
||||
[#captcha{pid=Pid, args=Args, key=Key, tref=Tref}] ->
|
||||
mnesia:delete({captcha, Id}),
|
||||
erlang:cancel_timer(Tref),
|
||||
if OCR == Key ->
|
||||
if is_pid(Pid) ->
|
||||
Pid ! {captcha_succeed, Args};
|
||||
true ->
|
||||
ok
|
||||
end,
|
||||
ok;
|
||||
true ->
|
||||
if is_pid(Pid) ->
|
||||
Pid ! {captcha_failed, Args};
|
||||
true ->
|
||||
ok
|
||||
end,
|
||||
{error, bad_match}
|
||||
end;
|
||||
_ ->
|
||||
{error, not_found}
|
||||
end);
|
||||
case check_captcha(Id, OCR) of
|
||||
captcha_valid ->
|
||||
ok;
|
||||
captcha_non_valid ->
|
||||
{error, bad_match};
|
||||
captcha_not_found ->
|
||||
{error, not_found}
|
||||
end;
|
||||
_ ->
|
||||
{error, malformed}
|
||||
end
|
||||
end;
|
||||
process_reply(_) ->
|
||||
{error, malformed}.
|
||||
end.
|
||||
|
||||
|
||||
process(_Handlers, #request{method='GET', lang=Lang, path=[_, Id]}) ->
|
||||
case build_captcha_html(Id, Lang) of
|
||||
{FormEl, _} when is_tuple(FormEl) ->
|
||||
Form =
|
||||
{xmlelement, "div", [{"align", "center"}],
|
||||
[FormEl]},
|
||||
%{xmlelement, "div", [{"align", "center"}],
|
||||
%[FormEl]},
|
||||
#xmlel{
|
||||
name = 'div',
|
||||
attrs = [
|
||||
#xmlattr{
|
||||
name = 'align',
|
||||
value = "center"
|
||||
}
|
||||
],
|
||||
children = [FormEl]
|
||||
},
|
||||
ejabberd_web:make_xhtml([Form]);
|
||||
captcha_not_found ->
|
||||
ejabberd_web:error(not_found)
|
||||
end;
|
||||
|
||||
process(_Handlers, #request{method='GET', path=[_, Id, "image"]}) ->
|
||||
case mnesia:dirty_read(captcha, Id) of
|
||||
[#captcha{key=Key}] ->
|
||||
case lookup_captcha(Id) of
|
||||
{ok, #captcha{key=Key}} ->
|
||||
case create_image(Key) of
|
||||
{ok, Type, _, Img} ->
|
||||
{200,
|
||||
@@ -297,10 +440,17 @@ process(_Handlers, #request{method='POST', q=Q, lang=Lang, path=[_, Id]}) ->
|
||||
case check_captcha(Id, ProvidedKey) of
|
||||
captcha_valid ->
|
||||
Form =
|
||||
{xmlelement, "p", [],
|
||||
[{xmlcdata,
|
||||
translate:translate(Lang, "The captcha is valid.")
|
||||
}]},
|
||||
%{xmlelement, "p", [],
|
||||
% [{xmlcdata,
|
||||
% translate:translate(Lang, "The captcha is valid.")
|
||||
% }]},
|
||||
#xmlel{
|
||||
name = 'p',
|
||||
children = [
|
||||
#xmlcdata{
|
||||
cdata = translate:translate(Lang, "The captcha is valid.")}
|
||||
]
|
||||
},
|
||||
ejabberd_web:make_xhtml([Form]);
|
||||
captcha_non_valid ->
|
||||
ejabberd_web:error(not_allowed);
|
||||
@@ -311,15 +461,12 @@ process(_Handlers, #request{method='POST', q=Q, lang=Lang, path=[_, Id]}) ->
|
||||
process(_Handlers, _Request) ->
|
||||
ejabberd_web:error(not_found).
|
||||
|
||||
|
||||
%%====================================================================
|
||||
%% gen_server callbacks
|
||||
%%====================================================================
|
||||
init([]) ->
|
||||
mnesia:create_table(captcha,
|
||||
[{ram_copies, [node()]},
|
||||
{attributes, record_info(fields, captcha)}]),
|
||||
mnesia:add_table_copy(captcha, node(), ram_copies),
|
||||
mnesia:delete_table(captcha),
|
||||
ets:new(captcha, [named_table, public, {keypos, #captcha.id}]),
|
||||
check_captcha_setup(),
|
||||
{ok, #state{}}.
|
||||
|
||||
@@ -331,17 +478,13 @@ handle_cast(_Msg, State) ->
|
||||
|
||||
handle_info({remove_id, Id}, State) ->
|
||||
?DEBUG("captcha ~p timed out", [Id]),
|
||||
_ = ?T(case mnesia:read(captcha, Id, write) of
|
||||
[#captcha{args=Args, pid=Pid}] ->
|
||||
if is_pid(Pid) ->
|
||||
Pid ! {captcha_failed, Args};
|
||||
true ->
|
||||
ok
|
||||
end,
|
||||
mnesia:delete({captcha, Id});
|
||||
_ ->
|
||||
ok
|
||||
end),
|
||||
case ets:lookup(captcha, Id) of
|
||||
[#captcha{args=Args, pid=Pid}] ->
|
||||
Pid ! {captcha_failed, Args},
|
||||
ets:delete(captcha, Id);
|
||||
_ ->
|
||||
ok
|
||||
end,
|
||||
{noreply, State};
|
||||
|
||||
handle_info(_Info, State) ->
|
||||
@@ -485,3 +628,43 @@ check_captcha_setup() ->
|
||||
false ->
|
||||
ok
|
||||
end.
|
||||
|
||||
lookup_captcha(Id) ->
|
||||
case string:tokens(Id, "-") of
|
||||
[_, NodeID] ->
|
||||
case ejabberd_cluster:get_node_by_id(NodeID) of
|
||||
Node when Node == node() ->
|
||||
case ets:lookup(captcha, Id) of
|
||||
[C] ->
|
||||
{ok, C};
|
||||
_ ->
|
||||
{error, enoent}
|
||||
end;
|
||||
Node ->
|
||||
case catch rpc:call(Node, ets, lookup,
|
||||
[captcha, Id], ?RPC_TIMEOUT) of
|
||||
[C] ->
|
||||
{ok, C};
|
||||
_ ->
|
||||
{error, enoent}
|
||||
end
|
||||
end;
|
||||
_ ->
|
||||
{error, enoent}
|
||||
end.
|
||||
|
||||
do_check_captcha(Id, ProvidedKey) ->
|
||||
case ets:lookup(captcha, Id) of
|
||||
[#captcha{pid = Pid, args = Args, key = ValidKey, tref = Tref}] ->
|
||||
ets:delete(captcha, Id),
|
||||
erlang:cancel_timer(Tref),
|
||||
if ValidKey == ProvidedKey ->
|
||||
Pid ! {captcha_succeed, Args},
|
||||
captcha_valid;
|
||||
true ->
|
||||
Pid ! {captcha_failed, Args},
|
||||
captcha_non_valid
|
||||
end;
|
||||
_ ->
|
||||
captcha_not_found
|
||||
end.
|
||||
|
||||
@@ -46,6 +46,8 @@ config() ->
|
||||
check_database_modules() ->
|
||||
[check_database_module(M)||M<-get_db_used()].
|
||||
|
||||
check_database_module(host) ->
|
||||
ok;
|
||||
check_database_module(odbc) ->
|
||||
check_modules(odbc, [odbc, odbc_app, odbc_sup, ejabberd_odbc, ejabberd_odbc_sup, odbc_queries]);
|
||||
check_database_module(mysql) ->
|
||||
|
||||
@@ -0,0 +1,177 @@
|
||||
%%%-------------------------------------------------------------------
|
||||
%%% File : ejabberd_cluster.erl
|
||||
%%% Author : Evgeniy Khramtsov <ekhramtsov@process-one.net>
|
||||
%%% Description :
|
||||
%%%
|
||||
%%% Created : 2 Apr 2010 by Evgeniy Khramtsov <ekhramtsov@process-one.net>
|
||||
%%%-------------------------------------------------------------------
|
||||
-module(ejabberd_cluster).
|
||||
|
||||
-behaviour(gen_server).
|
||||
|
||||
%% API
|
||||
-export([start_link/0, get_node/1, get_node_new/1, announce/0,
|
||||
node_id/0, get_node_by_id/1, get_nodes/0, rehash_timeout/0]).
|
||||
|
||||
%% gen_server callbacks
|
||||
-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
|
||||
terminate/2, code_change/3]).
|
||||
|
||||
-include("ejabberd.hrl").
|
||||
|
||||
-define(HASHTBL, nodes_hash).
|
||||
-define(HASHTBL_NEW, nodes_hash_new).
|
||||
-define(POINTS, 16).
|
||||
-define(REHASH_TIMEOUT, 5000).
|
||||
|
||||
-record(state, {}).
|
||||
|
||||
%%====================================================================
|
||||
%% API
|
||||
%%====================================================================
|
||||
start_link() ->
|
||||
gen_server:start_link({local, ?MODULE}, ?MODULE, [], []).
|
||||
|
||||
get_node(Key) ->
|
||||
Hash = erlang:phash2(Key),
|
||||
get_node_by_hash(?HASHTBL, Hash).
|
||||
|
||||
get_node_new(Key) ->
|
||||
Hash = erlang:phash2(Key),
|
||||
get_node_by_hash(?HASHTBL_NEW, Hash).
|
||||
|
||||
get_nodes() ->
|
||||
%% TODO
|
||||
mnesia:system_info(running_db_nodes).
|
||||
|
||||
announce() ->
|
||||
gen_server:call(?MODULE, announce, infinity).
|
||||
|
||||
node_id() ->
|
||||
integer_to_list(erlang:phash2(node())).
|
||||
|
||||
rehash_timeout() ->
|
||||
?REHASH_TIMEOUT.
|
||||
|
||||
get_node_by_id(NodeID) when is_list(NodeID) ->
|
||||
case catch list_to_existing_atom(NodeID) of
|
||||
{'EXIT', _} ->
|
||||
node();
|
||||
Res ->
|
||||
get_node_by_id(Res)
|
||||
end;
|
||||
get_node_by_id(NodeID) ->
|
||||
case global:whereis_name(NodeID) of
|
||||
Pid when is_pid(Pid) ->
|
||||
node(Pid);
|
||||
_ ->
|
||||
node()
|
||||
end.
|
||||
|
||||
%%====================================================================
|
||||
%% gen_server callbacks
|
||||
%%====================================================================
|
||||
init([]) ->
|
||||
net_kernel:monitor_nodes(true, [{node_type, visible}]),
|
||||
ets:new(?HASHTBL, [named_table, public, ordered_set]),
|
||||
ets:new(?HASHTBL_NEW, [named_table, public, ordered_set]),
|
||||
register_node(),
|
||||
AllNodes = mnesia:system_info(running_db_nodes),
|
||||
OtherNodes = case AllNodes of
|
||||
[_] ->
|
||||
AllNodes;
|
||||
_ ->
|
||||
AllNodes -- [node()]
|
||||
end,
|
||||
append_nodes(?HASHTBL, OtherNodes),
|
||||
append_nodes(?HASHTBL_NEW, AllNodes),
|
||||
{ok, #state{}}.
|
||||
|
||||
handle_call(announce, _From, State) ->
|
||||
case mnesia:system_info(running_db_nodes) of
|
||||
[_MyNode] ->
|
||||
ok;
|
||||
Nodes ->
|
||||
OtherNodes = Nodes -- [node()],
|
||||
lists:foreach(
|
||||
fun(Node) ->
|
||||
{?MODULE, Node} ! {node_ready, node()}
|
||||
end, OtherNodes),
|
||||
?INFO_MSG("waiting for migration from nodes: ~w",
|
||||
[OtherNodes]),
|
||||
timer:sleep(?REHASH_TIMEOUT),
|
||||
append_node(?HASHTBL, node())
|
||||
end,
|
||||
{reply, ok, State};
|
||||
handle_call(_Request, _From, State) ->
|
||||
Reply = ok,
|
||||
{reply, Reply, State}.
|
||||
|
||||
handle_cast(_Msg, State) ->
|
||||
{noreply, State}.
|
||||
|
||||
handle_info({node_ready, Node}, State) ->
|
||||
?INFO_MSG("node ~p is ready, starting migration", [Node]),
|
||||
append_node(?HASHTBL_NEW, Node),
|
||||
ejabberd_hooks:run(node_hash_update, [?REHASH_TIMEOUT]),
|
||||
timer:sleep(?REHASH_TIMEOUT),
|
||||
?INFO_MSG("adding node ~p to hash", [Node]),
|
||||
append_node(?HASHTBL, Node),
|
||||
{noreply, State};
|
||||
handle_info({nodedown, Node, _}, State) ->
|
||||
?INFO_MSG("node ~p goes down", [Node]),
|
||||
delete_node(?HASHTBL, Node),
|
||||
delete_node(?HASHTBL_NEW, Node),
|
||||
{noreply, State};
|
||||
handle_info(_Info, State) ->
|
||||
{noreply, State}.
|
||||
|
||||
terminate(_Reason, _State) ->
|
||||
ok.
|
||||
|
||||
code_change(_OldVsn, State, _Extra) ->
|
||||
{ok, State}.
|
||||
|
||||
%%--------------------------------------------------------------------
|
||||
%% Internal functions
|
||||
%%--------------------------------------------------------------------
|
||||
append_nodes(Tab, Nodes) ->
|
||||
lists:foreach(
|
||||
fun(Node) ->
|
||||
append_node(Tab, Node)
|
||||
end, Nodes).
|
||||
|
||||
append_node(Tab, Node) ->
|
||||
lists:foreach(
|
||||
fun(I) ->
|
||||
Hash = erlang:phash2({I, Node}),
|
||||
ets:insert(Tab, {Hash, Node})
|
||||
end, lists:seq(1, ?POINTS)).
|
||||
|
||||
delete_node(Tab, Node) ->
|
||||
lists:foreach(
|
||||
fun(I) ->
|
||||
Hash = erlang:phash2({I, Node}),
|
||||
ets:delete(Tab, Hash)
|
||||
end, lists:seq(1, ?POINTS)).
|
||||
|
||||
get_node_by_hash(Tab, Hash) ->
|
||||
NodeHash = case ets:next(Tab, Hash) of
|
||||
'$end_of_table' ->
|
||||
ets:first(Tab);
|
||||
NH ->
|
||||
NH
|
||||
end,
|
||||
if NodeHash == '$end_of_table' ->
|
||||
erlang:error(no_running_nodes);
|
||||
true ->
|
||||
case ets:lookup(Tab, NodeHash) of
|
||||
[] ->
|
||||
get_node_by_hash(Tab, Hash);
|
||||
[{_, Node}] ->
|
||||
Node
|
||||
end
|
||||
end.
|
||||
|
||||
register_node() ->
|
||||
global:register_name(list_to_atom(node_id()), self()).
|
||||
@@ -398,7 +398,7 @@ check_access(all, _) ->
|
||||
check_access(Access, Auth) ->
|
||||
{ok, User, Server} = check_auth(Auth),
|
||||
%% Check this user has access permission
|
||||
case acl:match_rule(Server, Access, jlib:make_jid(User, Server, "")) of
|
||||
case acl:match_rule(Server, Access, exmpp_jid:make(User, Server, "")) of
|
||||
allow -> true;
|
||||
deny -> false
|
||||
end.
|
||||
|
||||
@@ -27,16 +27,32 @@
|
||||
-module(ejabberd_config).
|
||||
-author('alexey@process-one.net').
|
||||
|
||||
-export([start/0, load_file/1,
|
||||
-export([start/0, load_file/1, get_host_option/2,
|
||||
add_global_option/2, add_local_option/2,
|
||||
mne_add_local_option/2, mne_del_local_option/1,
|
||||
del_global_option/1, del_local_option/1,
|
||||
get_global_option/1, get_local_option/1]).
|
||||
|
||||
-export([for_host/1
|
||||
,configure_host/2
|
||||
,delete_host/1
|
||||
]).
|
||||
|
||||
-export([search/1]).
|
||||
|
||||
-export([get_vh_by_auth_method/1]).
|
||||
-export([is_file_readable/1]).
|
||||
|
||||
-include("ejabberd.hrl").
|
||||
-include("ejabberd_config.hrl").
|
||||
-include_lib("kernel/include/file.hrl").
|
||||
-include_lib("stdlib/include/ms_transform.hrl").
|
||||
|
||||
-record(state, {opts = [],
|
||||
hosts = [],
|
||||
override_local = false,
|
||||
override_global = false,
|
||||
override_acls = false}).
|
||||
|
||||
%% @type macro() = {macro_key(), macro_value()}
|
||||
|
||||
@@ -151,7 +167,16 @@ search_hosts(Term, State) ->
|
||||
end.
|
||||
|
||||
add_hosts_to_option(Hosts, State) ->
|
||||
PrepHosts = normalize_hosts(Hosts),
|
||||
PrepHosts1 = normalize_hosts(Hosts),
|
||||
PrepHosts = ensure_localhost_is_first(PrepHosts1),
|
||||
mnesia:transaction(
|
||||
fun() ->
|
||||
lists:foreach(
|
||||
fun(H) ->
|
||||
mnesia:write(#local_config{key = {H, host},
|
||||
value = []})
|
||||
end, PrepHosts)
|
||||
end),
|
||||
add_option(hosts, PrepHosts, State#state{hosts = PrepHosts}).
|
||||
|
||||
normalize_hosts(Hosts) ->
|
||||
@@ -159,15 +184,27 @@ normalize_hosts(Hosts) ->
|
||||
normalize_hosts([], PrepHosts) ->
|
||||
lists:reverse(PrepHosts);
|
||||
normalize_hosts([Host|Hosts], PrepHosts) ->
|
||||
case jlib:nodeprep(Host) of
|
||||
error ->
|
||||
try
|
||||
PrepHost = exmpp_stringprep:nodeprep(Host),
|
||||
normalize_hosts(Hosts, [PrepHost|PrepHosts])
|
||||
catch
|
||||
_ ->
|
||||
?ERROR_MSG("Can't load config file: "
|
||||
"invalid host name [~p]", [Host]),
|
||||
exit("invalid hostname");
|
||||
PrepHost ->
|
||||
normalize_hosts(Hosts, [PrepHost|PrepHosts])
|
||||
exit("invalid hostname")
|
||||
end.
|
||||
|
||||
ensure_localhost_is_first(["localhost" | _] = Hosts) ->
|
||||
Hosts;
|
||||
ensure_localhost_is_first(Hosts) ->
|
||||
case lists:member("localhost", Hosts) of
|
||||
true ->
|
||||
["localhost" | lists:delete("localhost", Hosts)];
|
||||
false ->
|
||||
?INFO_MSG("ejabberd added the default virtual host \"localhost\""
|
||||
" to the list of hosts.", []),
|
||||
["localhost" | Hosts]
|
||||
end.
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
%%% Errors reading the config file
|
||||
@@ -377,6 +414,8 @@ process_term(Term, State) ->
|
||||
{host_config, Host, Terms} ->
|
||||
lists:foldl(fun(T, S) -> process_host_term(T, Host, S) end,
|
||||
State, Terms);
|
||||
{clusterid, ClusterID} ->
|
||||
add_option(clusterid, ClusterID, State);
|
||||
{listen, Listeners} ->
|
||||
Listeners2 =
|
||||
lists:map(
|
||||
@@ -393,6 +432,8 @@ process_term(Term, State) ->
|
||||
add_option(outgoing_s2s_port, Port, State);
|
||||
{outgoing_s2s_options, Methods, Timeout} ->
|
||||
add_option(outgoing_s2s_options, {Methods, Timeout}, State);
|
||||
{outgoing_s2s_local_address, Addr} ->
|
||||
add_option(outgoing_s2s_local_address, Addr, State);
|
||||
{s2s_dns_options, PropList} ->
|
||||
add_option(s2s_dns_options, PropList, State);
|
||||
{s2s_use_starttls, Port} ->
|
||||
@@ -427,20 +468,19 @@ process_term(Term, State) ->
|
||||
add_option(watchdog_large_heap, LH, State);
|
||||
{registration_timeout, Timeout} ->
|
||||
add_option(registration_timeout, Timeout, State);
|
||||
{ejabberdctl_access_commands, ACs} ->
|
||||
add_option(ejabberdctl_access_commands, ACs, State);
|
||||
{captcha_cmd, Cmd} ->
|
||||
add_option(captcha_cmd, Cmd, State);
|
||||
{captcha_host, Host} ->
|
||||
add_option(captcha_host, Host, State);
|
||||
{ejabberdctl_access_commands, ACs} ->
|
||||
add_option(ejabberdctl_access_commands, ACs, State);
|
||||
{loglevel, Loglevel} ->
|
||||
ejabberd_loglevel:set(Loglevel),
|
||||
State;
|
||||
{max_fsm_queue, N} ->
|
||||
add_option(max_fsm_queue, N, State);
|
||||
{_Opt, _Val} ->
|
||||
lists:foldl(fun(Host, S) -> process_host_term(Term, Host, S) end,
|
||||
State, State#state.hosts)
|
||||
process_host_term(Term, global, State)
|
||||
end.
|
||||
|
||||
process_host_term(Term, Host, State) ->
|
||||
@@ -462,6 +502,15 @@ process_host_term(Term, Host, State) ->
|
||||
State;
|
||||
{odbc_server, ODBC_server} ->
|
||||
add_option({odbc_server, Host}, ODBC_server, State);
|
||||
{auth_method, Methods} ->
|
||||
{Methods2, StorageOption} = replace_storage_auth(Host, Methods),
|
||||
State2 = case StorageOption of
|
||||
{auth_storage, Storage} ->
|
||||
add_option({auth_storage, Host}, Storage, State);
|
||||
undefined ->
|
||||
State
|
||||
end,
|
||||
add_option({auth_method, Host}, Methods2, State2);
|
||||
{Opt, Val} ->
|
||||
add_option({Opt, Host}, Val, State)
|
||||
end.
|
||||
@@ -565,20 +614,47 @@ add_global_option(Opt, Val) ->
|
||||
end).
|
||||
|
||||
add_local_option(Opt, Val) ->
|
||||
mnesia:transaction(fun mne_add_local_option/2, [Opt, Val]).
|
||||
|
||||
mne_add_local_option(Opt, Val) ->
|
||||
mnesia:write(#local_config{key = Opt,
|
||||
value = Val}).
|
||||
|
||||
del_global_option(Opt) ->
|
||||
mnesia:transaction(fun() ->
|
||||
mnesia:write(#local_config{key = Opt,
|
||||
value = Val})
|
||||
mnesia:delete({config, Opt})
|
||||
end).
|
||||
|
||||
del_local_option(Opt) ->
|
||||
mnesia:transaction(fun() ->
|
||||
mnesia:delete({local_config, Opt})
|
||||
end).
|
||||
|
||||
|
||||
get_global_option({Opt1, Host} = Opt) when is_list(Host) ->
|
||||
case ets:lookup(config, Opt) of
|
||||
[#config{value = Val}] ->
|
||||
Val;
|
||||
_ ->
|
||||
get_global_option({Opt1, global})
|
||||
end;
|
||||
get_global_option(Opt) ->
|
||||
case ets:lookup(config, Opt) of
|
||||
[#config{value = Val}] when Opt == hosts ->
|
||||
ensure_localhost_is_first(Val);
|
||||
[#config{value = Val}] ->
|
||||
Val;
|
||||
_ ->
|
||||
undefined
|
||||
end.
|
||||
|
||||
get_local_option({Opt1, Host} = Opt) when is_list(Host) ->
|
||||
case ets:lookup(local_config, Opt) of
|
||||
[#local_config{value = Val}] ->
|
||||
Val;
|
||||
_ ->
|
||||
get_local_option({Opt1, global})
|
||||
end;
|
||||
get_local_option(Opt) ->
|
||||
case ets:lookup(local_config, Opt) of
|
||||
[#local_config{value = Val}] ->
|
||||
@@ -587,6 +663,17 @@ get_local_option(Opt) ->
|
||||
undefined
|
||||
end.
|
||||
|
||||
get_host_option(Host, Option) ->
|
||||
case ets:lookup(local_config, {Option, Host}) of
|
||||
[#local_config{value=V}] -> V;
|
||||
_ -> undefined
|
||||
end.
|
||||
|
||||
mne_del_local_option({_OptName, Host} = Opt) when is_list(Host) ->
|
||||
mnesia:delete({local_config, Opt});
|
||||
mne_del_local_option({Host, host} = Opt) when is_list(Host) ->
|
||||
mnesia:delete({local_config, Opt}).
|
||||
|
||||
%% Return the list of hosts handled by a given module
|
||||
get_vh_by_auth_method(AuthMethod) ->
|
||||
mnesia:dirty_select(local_config,
|
||||
@@ -605,3 +692,86 @@ is_file_readable(Path) ->
|
||||
{error, _Reason} ->
|
||||
false
|
||||
end.
|
||||
|
||||
search(Pattern) ->
|
||||
{atomic, Res} = mnesia:transaction(fun mnesia:select/2, [local_config, Pattern]),
|
||||
Res.
|
||||
|
||||
for_host(Host) ->
|
||||
mnesia:read({local_config, {Host, host}})
|
||||
++ mnesia:select(local_config,
|
||||
ets:fun2ms(fun (#local_config{key={_, H}})
|
||||
when H =:= Host ->
|
||||
object()
|
||||
end))
|
||||
++ acl:for_host(Host).
|
||||
|
||||
delete_host(Host) ->
|
||||
mnesia_delete_objects(for_host(Host)),
|
||||
ok.
|
||||
|
||||
configure_host(Host, Config) ->
|
||||
HostExistenceTerm = {{Host, host}, []},
|
||||
Records = host_terms_to_records(Host, [HostExistenceTerm | Config]),
|
||||
mnesia_write_objects(Records),
|
||||
ok.
|
||||
|
||||
host_terms_to_records(Host, Terms) ->
|
||||
lists:foldl(fun (Term, Acc) ->
|
||||
host_term_to_record(Term, Host, Acc)
|
||||
end, [], Terms).
|
||||
|
||||
host_term_to_record({acl, ACLName, ACLData}, Host, Acc) ->
|
||||
[acl:to_record(Host, ACLName, ACLData) | Acc];
|
||||
host_term_to_record({access, RuleName, Rules}, Host, Acc) ->
|
||||
[#config{key={access, RuleName, Host}, value=Rules} | Acc];
|
||||
host_term_to_record({shaper, Name, Data}, Host, Acc) ->
|
||||
[#config{key={shaper, Name, Host}, value=Data} | Acc];
|
||||
host_term_to_record({host, _}, _Host, Acc) -> Acc;
|
||||
host_term_to_record({hosts, _}, _Host, Acc) -> Acc;
|
||||
host_term_to_record({{Host, host}, []}, Host, Acc) ->
|
||||
[#local_config{key={Host, host}, value=[]} | Acc];
|
||||
host_term_to_record({Opt, Val}, Host, Acc) when is_atom(Opt) ->
|
||||
[#local_config{key={Opt, Host}, value=Val} | Acc].
|
||||
|
||||
|
||||
mnesia_delete_objects(List) when is_list(List) ->
|
||||
true = lists:all(fun (I) ->
|
||||
ok =:= mnesia:delete_object(I)
|
||||
end, List).
|
||||
mnesia_write_objects(List) when is_list(List) ->
|
||||
true = lists:all(fun (I) ->
|
||||
ok =:= mnesia:write(I)
|
||||
end, List).
|
||||
|
||||
%% Replace internal and odbc auth_methods with storage.
|
||||
%% Only one storage type can be used, either internal or odbc.
|
||||
replace_storage_auth(Host, Val) when not is_list(Val) ->
|
||||
replace_storage_auth(Host, [Val]);
|
||||
replace_storage_auth(Host, Val) ->
|
||||
replace_storage_auth(Host, Val, [], undefined).
|
||||
|
||||
replace_storage_auth(_Host, [], Val2, Storage) ->
|
||||
{lists:reverse(Val2), Storage};
|
||||
|
||||
replace_storage_auth(Host, [internal = Val | ValT], Val2, undefined) ->
|
||||
Storage = {auth_storage, mnesia},
|
||||
?WARNING_MSG("The auth method '~p' is deprecated.~nReplace it with 'storage'"
|
||||
" and also add this option: ~n~p.", [Val, Storage]),
|
||||
replace_storage_auth(Host, ValT, [storage | Val2], Storage);
|
||||
|
||||
replace_storage_auth(Host, [odbc = Val | ValT], Val2, undefined) ->
|
||||
Storage = {auth_storage, odbc},
|
||||
?WARNING_MSG("The auth method '~p' is deprecated.~nReplace it with 'storage'"
|
||||
" and also add this option: ~n~p.", [Val, Storage]),
|
||||
replace_storage_auth(Host, ValT, [storage | Val2], Storage);
|
||||
|
||||
replace_storage_auth(Host, [Val | ValT], Val2, Storage)
|
||||
when (Val /= internal) and (Val /= odbc) ->
|
||||
replace_storage_auth(Host, ValT, [Val | Val2], Storage);
|
||||
|
||||
replace_storage_auth(Host, [Val | _ValT], _Val2, Storage) ->
|
||||
?CRITICAL_MSG("The auth method '~p' conflicts with~n~p in the host \"~p\"."
|
||||
"~nOnly one of them can be used in each host.",
|
||||
[Val, Storage, Host]),
|
||||
throw({unacceptable_auth_conflict, Host, Val, Storage}).
|
||||
|
||||
@@ -21,8 +21,3 @@
|
||||
|
||||
-record(config, {key, value}).
|
||||
-record(local_config, {key, value}).
|
||||
-record(state, {opts = [],
|
||||
hosts = [],
|
||||
override_local = false,
|
||||
override_global = false,
|
||||
override_acls = false}).
|
||||
|
||||
@@ -190,7 +190,7 @@ process(["help" | Mode]) ->
|
||||
print_usage_help(MaxC, ShCode),
|
||||
?STATUS_SUCCESS;
|
||||
[CmdString | _] ->
|
||||
{ok, CmdStringU, _} = regexp:gsub(CmdString, "-", "_"),
|
||||
CmdStringU = re:replace(CmdString, "-", "_", [global, {return, list}]),
|
||||
print_usage_commands(CmdStringU, MaxC, ShCode),
|
||||
?STATUS_SUCCESS
|
||||
end;
|
||||
@@ -267,10 +267,8 @@ try_run_ctp(Args, Auth, AccessCommands) ->
|
||||
%% @spec (Args::[string()], Auth, AccessCommands) -> string() | integer() | {string(), integer()}
|
||||
try_call_command(Args, Auth, AccessCommands) ->
|
||||
try call_command(Args, Auth, AccessCommands) of
|
||||
{error, command_unknown} ->
|
||||
{io_lib:format("Error: command ~p not known.", [hd(Args)]), ?STATUS_ERROR};
|
||||
{error, wrong_number_parameters} ->
|
||||
{"Error: wrong number of parameters", ?STATUS_ERROR};
|
||||
{error, String} ->
|
||||
{String, ?STATUS_ERROR};
|
||||
Res ->
|
||||
Res
|
||||
catch
|
||||
@@ -279,13 +277,13 @@ try_call_command(Args, Auth, AccessCommands) ->
|
||||
{io_lib:format("Problem '~p ~p' occurred executing the command.~nStacktrace: ~p", [A, Why, Stack]), ?STATUS_ERROR}
|
||||
end.
|
||||
|
||||
%% @spec (Args::[string()], Auth, AccessCommands) -> string() | integer() | {string(), integer()} | {error, ErrorType}
|
||||
%% @spec (Args::[string()], Auth, AccessCommands) -> string() | integer() | {string(), integer()} | {error, string()}
|
||||
call_command([CmdString | Args], Auth, AccessCommands) ->
|
||||
{ok, CmdStringU, _} = regexp:gsub(CmdString, "-", "_"),
|
||||
CmdStringU = re:replace(CmdString, "-", "_", [global,{return,list}]),
|
||||
Command = list_to_atom(CmdStringU),
|
||||
case ejabberd_commands:get_command_format(Command) of
|
||||
{error, command_unknown} ->
|
||||
{error, command_unknown};
|
||||
{error, io_lib:format("Error: command ~p not known.", [hd(Args)])};
|
||||
{ArgsFormat, ResultFormat} ->
|
||||
case (catch format_args(Args, ArgsFormat)) of
|
||||
ArgsFormatted when is_list(ArgsFormatted) ->
|
||||
@@ -298,9 +296,8 @@ call_command([CmdString | Args], Auth, AccessCommands) ->
|
||||
{L1, L2} when L1 < L2 -> {L2-L1, "less argument"};
|
||||
{L1, L2} when L1 > L2 -> {L1-L2, "more argument"}
|
||||
end,
|
||||
{io_lib:format("Error: the command ~p requires ~p ~s.",
|
||||
[CmdString, NumCompa, TextCompa]),
|
||||
wrong_command_arguments}
|
||||
{error, io_lib:format("Error: the command ~p requires ~p ~s.",
|
||||
[CmdString, NumCompa, TextCompa])}
|
||||
end
|
||||
end.
|
||||
|
||||
@@ -614,26 +611,26 @@ print_usage_tags(Tag, MaxC, ShCode) ->
|
||||
|
||||
print_usage_help(MaxC, ShCode) ->
|
||||
LongDesc =
|
||||
["The special 'help' ejabberdctl command provides help of ejabberd commands.\n\n"
|
||||
"The format is:\n ", ?B("ejabberdctl"), " ", ?B("help"), " [", ?B("--tags"), " ", ?U("[tag]"), " | ", ?U("com?*"), "]\n\n"
|
||||
"The special 'help' ejabberdctl command provides help of ejabberd commands.\n\n"
|
||||
"The format is:\n "++?B("ejabberdctl")++" "++?B("help")++" ["++?B("--tags")++" "++?U("[tag]")++" | "++?U("com?*")++"]\n\n"
|
||||
"The optional arguments:\n"
|
||||
" ",?B("--tags")," Show all tags and the names of commands in each tag\n"
|
||||
" ",?B("--tags"), " ", ?U("tag")," Show description of commands in this tag\n"
|
||||
" ",?U("command")," Show detailed description of the command\n"
|
||||
" ",?U("com?*")," Show detailed description of commands that match this glob.\n"
|
||||
" "++?B("--tags")++" Show all tags and the names of commands in each tag\n"
|
||||
" "++?B("--tags")++" "++?U("tag")++" Show description of commands in this tag\n"
|
||||
" "++?U("command")++" Show detailed description of the command\n"
|
||||
" "++?U("com?*")++" Show detailed description of commands that match this glob.\n"
|
||||
" You can use ? to match a simple character,\n"
|
||||
" and * to match several characters.\n"
|
||||
"\n",
|
||||
"Some example usages:\n",
|
||||
" ejabberdctl help\n",
|
||||
" ejabberdctl help --tags\n",
|
||||
" ejabberdctl help --tags accounts\n",
|
||||
" ejabberdctl help register\n",
|
||||
" ejabberdctl help regist*\n",
|
||||
"\n",
|
||||
"Please note that 'ejabberdctl help' shows all ejabberd commands,\n",
|
||||
"even those that cannot be used in the shell with ejabberdctl.\n",
|
||||
"Those commands can be identified because the description starts with: *"],
|
||||
"\n"
|
||||
"Some example usages:\n"
|
||||
" ejabberdctl help\n"
|
||||
" ejabberdctl help --tags\n"
|
||||
" ejabberdctl help --tags accounts\n"
|
||||
" ejabberdctl help register\n"
|
||||
" ejabberdctl help regist*\n"
|
||||
"\n"
|
||||
"Please note that 'ejabberdctl help' shows all ejabberd commands,\n"
|
||||
"even those that cannot be used in the shell with ejabberdctl.\n"
|
||||
"Those commands can be identified because the description starts with: *",
|
||||
ArgsDef = [],
|
||||
C = #ejabberd_commands{
|
||||
desc = "Show help of ejabberd commands",
|
||||
@@ -678,13 +675,13 @@ filter_commands(All, SubString) ->
|
||||
end.
|
||||
|
||||
filter_commands_regexp(All, Glob) ->
|
||||
RegExp = regexp:sh_to_awk(Glob),
|
||||
RegExp = xmerl_regexp:sh_to_awk(Glob),
|
||||
lists:filter(
|
||||
fun(Command) ->
|
||||
case regexp:first_match(Command, RegExp) of
|
||||
{match, _, _} ->
|
||||
case re:run(Command, RegExp, [{capture, none}]) of
|
||||
match ->
|
||||
true;
|
||||
_ ->
|
||||
nomatch ->
|
||||
false
|
||||
end
|
||||
end,
|
||||
@@ -700,6 +697,7 @@ print_usage_command(Cmd, MaxC, ShCode) ->
|
||||
print_usage_command(Cmd, C, MaxC, ShCode)
|
||||
end.
|
||||
|
||||
%% @spec (Cmd::string(), C::ejabberd_commands(), MaxC::integer(), ShCode::boolean()) -> ok
|
||||
print_usage_command(Cmd, C, MaxC, ShCode) ->
|
||||
#ejabberd_commands{
|
||||
tags = TagsAtoms,
|
||||
@@ -741,10 +739,6 @@ print_usage_command(Cmd, C, MaxC, ShCode) ->
|
||||
|
||||
?PRINT(["\n", NameFmt, "\n", ArgsFmt, "\n", ReturnsFmt, "\n\n", XmlrpcFmt, TagsFmt, "\n\n", DescFmt, "\n\n", LongDescFmt, NoteEjabberdctl], []).
|
||||
|
||||
format_usage_ctype(Type, _Indentation)
|
||||
when (Type==atom) or (Type==integer) or (Type==string) or (Type==rescode) or (Type==restuple)->
|
||||
io_lib:format("~p", [Type]);
|
||||
|
||||
format_usage_ctype({Name, Type}, _Indentation)
|
||||
when (Type==atom) or (Type==integer) or (Type==string) or (Type==rescode) or (Type==restuple)->
|
||||
io_lib:format("~p::~p", [Name, Type]);
|
||||
|
||||
@@ -45,6 +45,8 @@
|
||||
get_peer_certificate/1,
|
||||
get_verify_result/1,
|
||||
close/1,
|
||||
setopts/2,
|
||||
change_controller/2,
|
||||
sockname/1, peername/1]).
|
||||
|
||||
%% gen_server callbacks
|
||||
@@ -94,18 +96,15 @@ start(Module, SockMod, Socket, Opts) ->
|
||||
todo
|
||||
end.
|
||||
|
||||
starttls(FsmRef, _TLSOpts) ->
|
||||
%% TODO: Frontend improvements planned by Aleksey
|
||||
%%gen_server:call(FsmRef, {starttls, TLSOpts}),
|
||||
FsmRef.
|
||||
starttls(FsmRef, TLSOpts) ->
|
||||
starttls(FsmRef, TLSOpts, undefined).
|
||||
|
||||
starttls(FsmRef, TLSOpts, Data) ->
|
||||
gen_server:call(FsmRef, {starttls, TLSOpts, Data}),
|
||||
FsmRef.
|
||||
|
||||
compress(FsmRef) ->
|
||||
gen_server:call(FsmRef, compress),
|
||||
FsmRef.
|
||||
compress(FsmRef, undefined).
|
||||
|
||||
compress(FsmRef, Data) ->
|
||||
gen_server:call(FsmRef, {compress, Data}),
|
||||
@@ -138,11 +137,14 @@ close(FsmRef) ->
|
||||
sockname(FsmRef) ->
|
||||
gen_server:call(FsmRef, sockname).
|
||||
|
||||
peername(_FsmRef) ->
|
||||
%% TODO: Frontend improvements planned by Aleksey
|
||||
%%gen_server:call(FsmRef, peername).
|
||||
{ok, {{0, 0, 0, 0}, 0}}.
|
||||
setopts(FsmRef, Opts) ->
|
||||
gen_server:call(FsmRef, {setopts, Opts}).
|
||||
|
||||
change_controller(FsmRef, C2SPid) ->
|
||||
gen_server:call(FsmRef, {change_controller, C2SPid}).
|
||||
|
||||
peername(FsmRef) ->
|
||||
gen_server:call(FsmRef, peername).
|
||||
|
||||
%%====================================================================
|
||||
%% gen_server callbacks
|
||||
@@ -158,9 +160,16 @@ peername(_FsmRef) ->
|
||||
init([Module, SockMod, Socket, Opts, Receiver]) ->
|
||||
%% TODO: monitor the receiver
|
||||
Node = ejabberd_node_groups:get_closest_node(backend),
|
||||
IP = case peername(SockMod, Socket) of
|
||||
{ok, IP1} ->
|
||||
IP1;
|
||||
_ ->
|
||||
undefined
|
||||
end,
|
||||
{SockMod2, Socket2} = check_starttls(SockMod, Socket, Receiver, Opts),
|
||||
{ok, Pid} =
|
||||
rpc:call(Node, Module, start, [{?MODULE, self()}, Opts]),
|
||||
rpc:call(Node, Module, start,
|
||||
[{?MODULE, self()}, [{frontend_ip, IP} | Opts]]),
|
||||
ejabberd_receiver:become_controller(Receiver, Pid),
|
||||
{ok, #state{sockmod = SockMod2,
|
||||
socket = Socket2,
|
||||
@@ -175,38 +184,16 @@ init([Module, SockMod, Socket, Opts, Receiver]) ->
|
||||
%% {stop, Reason, State}
|
||||
%% Description: Handling call messages
|
||||
%%--------------------------------------------------------------------
|
||||
handle_call({starttls, TLSOpts}, _From, State) ->
|
||||
{ok, TLSSocket} = tls:tcp_to_tls(State#state.socket, TLSOpts),
|
||||
ejabberd_receiver:starttls(State#state.receiver, TLSSocket),
|
||||
Reply = ok,
|
||||
{reply, Reply, State#state{socket = TLSSocket, sockmod = tls},
|
||||
?HIBERNATE_TIMEOUT};
|
||||
|
||||
handle_call({starttls, TLSOpts, Data}, _From, State) ->
|
||||
{ok, TLSSocket} = tls:tcp_to_tls(State#state.socket, TLSOpts),
|
||||
ejabberd_receiver:starttls(State#state.receiver, TLSSocket),
|
||||
catch (State#state.sockmod):send(
|
||||
State#state.socket, Data),
|
||||
{ok, TLSSocket} = ejabberd_receiver:starttls(
|
||||
State#state.receiver, TLSOpts, Data),
|
||||
Reply = ok,
|
||||
{reply, Reply, State#state{socket = TLSSocket, sockmod = tls},
|
||||
?HIBERNATE_TIMEOUT};
|
||||
|
||||
handle_call(compress, _From, State) ->
|
||||
{ok, ZlibSocket} = ejabberd_zlib:enable_zlib(
|
||||
State#state.sockmod,
|
||||
State#state.socket),
|
||||
ejabberd_receiver:compress(State#state.receiver, ZlibSocket),
|
||||
Reply = ok,
|
||||
{reply, Reply, State#state{socket = ZlibSocket, sockmod = ejabberd_zlib},
|
||||
?HIBERNATE_TIMEOUT};
|
||||
|
||||
handle_call({compress, Data}, _From, State) ->
|
||||
{ok, ZlibSocket} = ejabberd_zlib:enable_zlib(
|
||||
State#state.sockmod,
|
||||
State#state.socket),
|
||||
ejabberd_receiver:compress(State#state.receiver, ZlibSocket),
|
||||
catch (State#state.sockmod):send(
|
||||
State#state.socket, Data),
|
||||
{ok, ZlibSocket} = ejabberd_receiver:compress(
|
||||
State#state.receiver, Data),
|
||||
Reply = ok,
|
||||
{reply, Reply, State#state{socket = ZlibSocket, sockmod = ejabberd_zlib},
|
||||
?HIBERNATE_TIMEOUT};
|
||||
@@ -246,13 +233,7 @@ handle_call(close, _From, State) ->
|
||||
|
||||
handle_call(sockname, _From, State) ->
|
||||
#state{sockmod = SockMod, socket = Socket} = State,
|
||||
Reply =
|
||||
case SockMod of
|
||||
gen_tcp ->
|
||||
inet:sockname(Socket);
|
||||
_ ->
|
||||
SockMod:sockname(Socket)
|
||||
end,
|
||||
Reply = peername(SockMod, Socket),
|
||||
{reply, Reply, State, ?HIBERNATE_TIMEOUT};
|
||||
|
||||
handle_call(peername, _From, State) ->
|
||||
@@ -266,6 +247,14 @@ handle_call(peername, _From, State) ->
|
||||
end,
|
||||
{reply, Reply, State, ?HIBERNATE_TIMEOUT};
|
||||
|
||||
handle_call({setopts, Opts}, _From, State) ->
|
||||
ejabberd_receiver:setopts(State#state.receiver, Opts),
|
||||
{reply, ok, State, ?HIBERNATE_TIMEOUT};
|
||||
|
||||
handle_call({change_controller, Pid}, _From, State) ->
|
||||
ejabberd_receiver:change_controller(State#state.receiver, Pid),
|
||||
{reply, ok, State, ?HIBERNATE_TIMEOUT};
|
||||
|
||||
handle_call(_Request, _From, State) ->
|
||||
Reply = ok,
|
||||
{reply, Reply, State, ?HIBERNATE_TIMEOUT}.
|
||||
@@ -318,10 +307,16 @@ check_starttls(SockMod, Socket, Receiver, Opts) ->
|
||||
end, Opts),
|
||||
if
|
||||
TLSEnabled ->
|
||||
{ok, TLSSocket} = tls:tcp_to_tls(Socket, TLSOpts),
|
||||
ejabberd_receiver:starttls(Receiver, TLSSocket),
|
||||
{ok, TLSSocket} = ejabberd_receiver:starttls(Receiver, TLSOpts),
|
||||
{tls, TLSSocket};
|
||||
true ->
|
||||
{SockMod, Socket}
|
||||
end.
|
||||
|
||||
peername(SockMod, Socket) ->
|
||||
case SockMod of
|
||||
gen_tcp ->
|
||||
inet:peername(Socket);
|
||||
_ ->
|
||||
SockMod:peername(Socket)
|
||||
end.
|
||||
|
||||
@@ -0,0 +1,280 @@
|
||||
%%%----------------------------------------------------------------------
|
||||
%%% File : ejabberd_global_router.erl
|
||||
%%% Author : Geoff Cant <gcant@process-one.net>
|
||||
%%% Purpose : Router for virtual global routes
|
||||
%%% Created : 07 Aug 2002 by Geoff Cant <gcant@process-one.net>
|
||||
%%%
|
||||
%%%
|
||||
%%% ejabberd, Copyright (C) 2002-2009 ProcessOne
|
||||
%%%
|
||||
%%% This program is free software; you can redistribute it and/or
|
||||
%%% modify it under the terms of the GNU General Public License as
|
||||
%%% published by the Free Software Foundation; either version 2 of the
|
||||
%%% License, or (at your option) any later version.
|
||||
%%%
|
||||
%%% This program is distributed in the hope that it will be useful,
|
||||
%%% but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
%%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
%%% General Public License for more details.
|
||||
%%%
|
||||
%%% You should have received a copy of the GNU General Public License
|
||||
%%% along with this program; if not, write to the Free Software
|
||||
%%% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||
%%% 02111-1307 USA
|
||||
%%%
|
||||
%%%----------------------------------------------------------------------
|
||||
-module(ejabberd_global_router).
|
||||
|
||||
-behaviour(gen_server).
|
||||
|
||||
-include("ejabberd.hrl").
|
||||
-include("ejabberd_global_router.hrl").
|
||||
|
||||
%% API
|
||||
-export([start_link/0
|
||||
,route/3
|
||||
,route/4
|
||||
,find_route/1
|
||||
,register_route/1
|
||||
,register_route/2
|
||||
,unregister_route/1
|
||||
,unregister_route/2
|
||||
,expand_routes/1
|
||||
,all_prefixes/0
|
||||
,server_host/2
|
||||
]).
|
||||
|
||||
%% Eunit test exports.
|
||||
-export([remove_prefix/2
|
||||
,find_prefix/2
|
||||
]).
|
||||
|
||||
%% gen_server callbacks
|
||||
-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
|
||||
terminate/2, code_change/3]).
|
||||
|
||||
-record(state, {}).
|
||||
|
||||
%%====================================================================
|
||||
%% API
|
||||
%%====================================================================
|
||||
%%--------------------------------------------------------------------
|
||||
%% @spec start_link() -> {ok,Pid} | ignore | {error,Error}
|
||||
%% @doc Starts the server
|
||||
%% @end
|
||||
%%--------------------------------------------------------------------
|
||||
start_link() ->
|
||||
gen_server:start_link({local, ?MODULE}, ?MODULE, [], []).
|
||||
|
||||
route(From, To, Packet) ->
|
||||
case find_route(To) of
|
||||
Route = #global_route{} ->
|
||||
route(Route, From, To, Packet);
|
||||
no_route ->
|
||||
ok
|
||||
end.
|
||||
|
||||
route(#global_route{pids=Pids}, From, To, Packet) ->
|
||||
Pid = pick_route(Pids),
|
||||
Pid ! {route, From, To, Packet},
|
||||
ok.
|
||||
|
||||
find_route(Domain) ->
|
||||
case prefix_match(Domain, all_prefixes()) of
|
||||
nomatch ->
|
||||
no_route;
|
||||
Prefix when is_list(Prefix) ->
|
||||
dirty_get_route(Prefix)
|
||||
end.
|
||||
|
||||
register_route(Prefix) ->
|
||||
register_route(Prefix, self()).
|
||||
|
||||
register_route(Prefix, Pid) ->
|
||||
Route = #global_route{prefix=Prefix,
|
||||
pids=[Pid]},
|
||||
{atomic, ok} = mnesia:transaction(fun write_route/1,
|
||||
[Route]),
|
||||
ok.
|
||||
|
||||
unregister_route(Prefix) ->
|
||||
unregister_route(Prefix, self()).
|
||||
|
||||
unregister_route(Prefix, Pid) ->
|
||||
mnesia:transaction(fun delete_route/2, [Prefix, Pid]).
|
||||
|
||||
expand_routes(Domain) ->
|
||||
[expand_route(Prefix, Domain) || Prefix <- all_prefixes()].
|
||||
|
||||
expand_route(Prefix, Domain) ->
|
||||
lists:append([Prefix, ".", Domain]).
|
||||
|
||||
all_prefixes() ->
|
||||
mnesia:dirty_all_keys(global_route).
|
||||
|
||||
server_host(Host, Pid) ->
|
||||
#global_route{prefix=P,pids=Pids} = find_route(Host),
|
||||
true = lists:member(Pid, Pids),
|
||||
remove_prefix(P, Host).
|
||||
|
||||
%%====================================================================
|
||||
%% gen_server callbacks
|
||||
%%====================================================================
|
||||
|
||||
%%--------------------------------------------------------------------
|
||||
%% @private
|
||||
%% @spec init(Args) -> {ok, State} |
|
||||
%% {ok, State, Timeout} |
|
||||
%% ignore |
|
||||
%% {stop, Reason}
|
||||
%% @doc Initialises the server's state
|
||||
%% @end
|
||||
%%--------------------------------------------------------------------
|
||||
init([]) ->
|
||||
update_tables(),
|
||||
mnesia:create_table(global_route,
|
||||
[{ram_copies, [node()]},
|
||||
{type, set},
|
||||
{attributes,
|
||||
record_info(fields, global_route)}]),
|
||||
mnesia:add_table_copy(global_route, node(), ram_copies),
|
||||
{ok, #state{}}.
|
||||
|
||||
%%--------------------------------------------------------------------
|
||||
%% @private
|
||||
%% @spec
|
||||
%% handle_call(Request, From, State) -> {reply, Reply, State} |
|
||||
%% {reply, Reply, State, Timeout} |
|
||||
%% {noreply, State} |
|
||||
%% {noreply, State, Timeout} |
|
||||
%% {stop, Reason, Reply, State} |
|
||||
%% {stop, Reason, State}
|
||||
%% @doc Call message handler callbacks
|
||||
%% @end
|
||||
%%--------------------------------------------------------------------
|
||||
handle_call(Call, _From, State) ->
|
||||
?WARNING_MSG("Unexpected call ~p.", [Call]),
|
||||
{noreply, State}.
|
||||
|
||||
%%--------------------------------------------------------------------
|
||||
%% @private
|
||||
%% @spec
|
||||
%% handle_cast(Msg, State) -> {noreply, State} |
|
||||
%% {noreply, State, Timeout} |
|
||||
%% {stop, Reason, State}
|
||||
%% @doc Cast message handler callbacks
|
||||
%% @end
|
||||
%%--------------------------------------------------------------------
|
||||
handle_cast(Msg, State) ->
|
||||
?WARNING_MSG("Unexpected cast ~p", [Msg]),
|
||||
{noreply, State}.
|
||||
|
||||
%%--------------------------------------------------------------------
|
||||
%% @private
|
||||
%% @spec
|
||||
%% handle_info(Info, State) -> {noreply, State} |
|
||||
%% {noreply, State, Timeout} |
|
||||
%% {stop, Reason, State}
|
||||
%% @doc Non gen-server message handler callbacks
|
||||
%% @end
|
||||
%%--------------------------------------------------------------------
|
||||
handle_info(Info, State) ->
|
||||
?WARNING_MSG("Unexpected info ~p", [Info]),
|
||||
{noreply, State}.
|
||||
|
||||
%%--------------------------------------------------------------------
|
||||
%% @private
|
||||
%% @spec terminate(Reason, State) -> void()
|
||||
%% @doc This function is called by a gen_server when it is about to
|
||||
%% terminate. It should be the opposite of Module:init/1 and do any necessary
|
||||
%% cleaning up. When it returns, the gen_server terminates with Reason.
|
||||
%% The return value is ignored.
|
||||
%% @end
|
||||
%%--------------------------------------------------------------------
|
||||
terminate(_Reason, _State) ->
|
||||
ok.
|
||||
|
||||
%%--------------------------------------------------------------------
|
||||
%% @private
|
||||
%% @spec code_change(OldVsn, State, Extra) -> {ok, NewState}
|
||||
%% @doc Convert process state when code is changed
|
||||
%% @end
|
||||
%%--------------------------------------------------------------------
|
||||
code_change(_OldVsn, State, _Extra) ->
|
||||
{ok, State}.
|
||||
|
||||
pick_route(Pids) when is_list(Pids) ->
|
||||
pick_local_route(Pids).
|
||||
|
||||
pick_local_route(Pids) when is_list(Pids) ->
|
||||
case [Pid || Pid <- Pids,
|
||||
node(Pid) =:= node()] of
|
||||
[] -> pick_remote_route(Pids);
|
||||
LocalPids -> pick_one_route(LocalPids)
|
||||
end.
|
||||
|
||||
pick_remote_route(Pids) when is_list(Pids) -> pick_one_route(Pids).
|
||||
|
||||
pick_one_route(Pids) when is_list(Pids) ->
|
||||
hd(Pids). % should pick random pid?
|
||||
|
||||
|
||||
update_tables() ->
|
||||
CorrectAttributes = record_info(fields, global_route),
|
||||
case catch mnesia:table_info(global_route, attributes) of
|
||||
CorrectAttributes ->
|
||||
ok;
|
||||
IncorrectAttributes when is_list(IncorrectAttributes) ->
|
||||
mnesia:delete_table(global_route);
|
||||
{'EXIT', _} ->
|
||||
ok
|
||||
end.
|
||||
|
||||
write_route(R = #global_route{prefix=Prefix}) ->
|
||||
NewRoute = case mnesia:read({global_route, Prefix}) of
|
||||
[] -> R;
|
||||
[OldRoute] ->
|
||||
combine_routes(OldRoute, R)
|
||||
end,
|
||||
ok = mnesia:write(NewRoute).
|
||||
|
||||
delete_route(Prefix, Pid) ->
|
||||
case mnesia:read({global_route, Prefix}, write) of
|
||||
[] -> ok;
|
||||
[#global_route{pids=[Pid]}] ->
|
||||
mnesia:delete({global_route, Prefix});
|
||||
[Route = #global_route{pids=Pids}] ->
|
||||
mnesia:write(Route#global_route{pids=Pids -- [Pid]})
|
||||
end.
|
||||
|
||||
combine_routes(R = #global_route{prefix=P, pids=APids},
|
||||
#global_route{prefix=P, pids=BPids}) ->
|
||||
R#global_route{pids=lists:usort(APids ++ BPids)}.
|
||||
|
||||
prefix_match(Domain, Prefixes) ->
|
||||
case find_prefix(Domain, Prefixes) of
|
||||
[] -> nomatch;
|
||||
[Prefix] -> Prefix;
|
||||
_Prefixes ->
|
||||
erlang:error(multiple_prefix_matches)
|
||||
end.
|
||||
|
||||
dirty_get_route(Prefix) ->
|
||||
case mnesia:dirty_read({global_route, Prefix}) of
|
||||
[Route = #global_route{}] ->
|
||||
Route;
|
||||
_ -> no_route
|
||||
end.
|
||||
|
||||
find_prefix(Domain, PossiblePrefixes) ->
|
||||
[Prefix
|
||||
|| Prefix <- PossiblePrefixes,
|
||||
lists:prefix(Prefix, Domain)].
|
||||
|
||||
remove_prefix(Prefix, Domain) ->
|
||||
[$. | BareDomain] = Domain -- Prefix,
|
||||
BareDomain.
|
||||
|
||||
%%--------------------------------------------------------------------
|
||||
%%% Eunit Tests.
|
||||
%%--------------------------------------------------------------------
|
||||
@@ -0,0 +1,27 @@
|
||||
%%%----------------------------------------------------------------------
|
||||
%%% File : ejabberd_global_router.hrl
|
||||
%%% Author : Geoff Cant <gcant@process-one.net>
|
||||
%%% Purpose : Virtual global routes record definitions
|
||||
%%% Created : 08 Aug 2002 by Geoff Cant <gcant@process-one.net>
|
||||
%%%
|
||||
%%%
|
||||
%%% ejabberd, Copyright (C) 2002-2009 ProcessOne
|
||||
%%%
|
||||
%%% This program is free software; you can redistribute it and/or
|
||||
%%% modify it under the terms of the GNU General Public License as
|
||||
%%% published by the Free Software Foundation; either version 2 of the
|
||||
%%% License, or (at your option) any later version.
|
||||
%%%
|
||||
%%% This program is distributed in the hope that it will be useful,
|
||||
%%% but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
%%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
%%% General Public License for more details.
|
||||
%%%
|
||||
%%% You should have received a copy of the GNU General Public License
|
||||
%%% along with this program; if not, write to the Free Software
|
||||
%%% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||
%%% 02111-1307 USA
|
||||
%%%
|
||||
%%%----------------------------------------------------------------------
|
||||
|
||||
-record(global_route, {prefix, pids}).
|
||||
@@ -81,7 +81,8 @@ add(Hook, Host, Function, Seq) when is_function(Function) ->
|
||||
add(Hook, Module, Function, Seq) ->
|
||||
add(Hook, global, Module, Function, Seq).
|
||||
|
||||
add(Hook, Host, Module, Function, Seq) ->
|
||||
add(Hook, Host, Module, Function, Seq)
|
||||
when is_binary(Host) orelse is_atom(Host) ->
|
||||
gen_server:call(ejabberd_hooks, {add, Hook, Host, Module, Function, Seq}).
|
||||
|
||||
add_dist(Hook, Node, Module, Function, Seq) ->
|
||||
@@ -104,7 +105,8 @@ delete(Hook, Host, Function, Seq) when is_function(Function) ->
|
||||
delete(Hook, Module, Function, Seq) ->
|
||||
delete(Hook, global, Module, Function, Seq).
|
||||
|
||||
delete(Hook, Host, Module, Function, Seq) ->
|
||||
delete(Hook, Host, Module, Function, Seq)
|
||||
when is_binary(Host) orelse is_atom(Host) ->
|
||||
gen_server:call(ejabberd_hooks, {delete, Hook, Host, Module, Function, Seq}).
|
||||
|
||||
delete_dist(Hook, Node, Module, Function, Seq) ->
|
||||
@@ -117,14 +119,27 @@ delete_dist(Hook, Host, Node, Module, Function, Seq) ->
|
||||
%% @doc Run the calls of this hook in order, don't care about function results.
|
||||
%% If a call returns stop, no more calls are performed.
|
||||
run(Hook, Args) ->
|
||||
run(Hook, global, Args).
|
||||
runx(Hook, global, Args).
|
||||
|
||||
run(Hook, Host, Args) ->
|
||||
case ets:lookup(hooks, {Hook, Host}) of
|
||||
run(Hook, Host, Args) when is_binary(Host) ->
|
||||
case runx(Hook, Host, Args) of
|
||||
stop -> stop;
|
||||
_ -> runx(Hook, global, Args)
|
||||
end;
|
||||
run(Hook, Host, Args) when Host == global ->
|
||||
runx(Hook, Host, Args).
|
||||
|
||||
runx(Hook, Host, Args) when is_binary(Host) orelse is_atom(Host) ->
|
||||
case ets:lookup(hooks, {Hook, ejabberd:normalize_host(Host)}) of
|
||||
[{_, Ls}] ->
|
||||
run1(Ls, Hook, Args);
|
||||
[] ->
|
||||
ok
|
||||
case ets:lookup(hooks, {Hook, global}) of
|
||||
[{_, Ls}] ->
|
||||
run1(Ls, Hook, Args);
|
||||
[] ->
|
||||
ok
|
||||
end
|
||||
end.
|
||||
|
||||
%% @spec (Hook::atom(), Val, Args) -> Val | stopped | NewVal
|
||||
@@ -134,14 +149,29 @@ run(Hook, Host, Args) ->
|
||||
%% If a call returns 'stop', no more calls are performed and 'stopped' is returned.
|
||||
%% If a call returns {stopped, NewVal}, no more calls are performed and NewVal is returned.
|
||||
run_fold(Hook, Val, Args) ->
|
||||
run_fold(Hook, global, Val, Args).
|
||||
run_foldx(Hook, global, Val, Args).
|
||||
|
||||
run_fold(Hook, Host, Val, Args) ->
|
||||
case ets:lookup(hooks, {Hook, Host}) of
|
||||
%% @spec (Hook::atom(), Host, Val, Args) -> Val | stopped | NewVal
|
||||
%% Host = global | binary()
|
||||
run_fold(Hook, Host, Val, Args) when is_binary(Host) ->
|
||||
case run_foldx(Hook, Host, Val, Args) of
|
||||
stopped -> stopped;
|
||||
Val2 -> run_foldx(Hook, global, Val2, Args)
|
||||
end;
|
||||
run_fold(Hook, Host, Val, Args) when Host == global ->
|
||||
run_foldx(Hook, Host, Val, Args).
|
||||
|
||||
run_foldx(Hook, Host, Val, Args) ->
|
||||
case ets:lookup(hooks, {Hook, ejabberd:normalize_host(Host)}) of
|
||||
[{_, Ls}] ->
|
||||
run_fold1(Ls, Hook, Val, Args);
|
||||
[] ->
|
||||
Val
|
||||
case ets:lookup(hooks, {Hook, global}) of
|
||||
[{_, Ls}] ->
|
||||
run_fold1(Ls, Hook, Val, Args);
|
||||
[] ->
|
||||
Val
|
||||
end
|
||||
end.
|
||||
|
||||
%%%----------------------------------------------------------------------
|
||||
@@ -169,7 +199,8 @@ init([]) ->
|
||||
%% {stop, Reason, State} (terminate/2 is called)
|
||||
%%----------------------------------------------------------------------
|
||||
handle_call({add, Hook, Host, Module, Function, Seq}, _From, State) ->
|
||||
Reply = case ets:lookup(hooks, {Hook, Host}) of
|
||||
NHost = ejabberd:normalize_host(Host),
|
||||
Reply = case ets:lookup(hooks, {Hook, NHost}) of
|
||||
[{_, Ls}] ->
|
||||
El = {Seq, Module, Function},
|
||||
case lists:member(El, Ls) of
|
||||
@@ -177,12 +208,12 @@ handle_call({add, Hook, Host, Module, Function, Seq}, _From, State) ->
|
||||
ok;
|
||||
false ->
|
||||
NewLs = lists:merge(Ls, [El]),
|
||||
ets:insert(hooks, {{Hook, Host}, NewLs}),
|
||||
ets:insert(hooks, {{Hook, NHost}, NewLs}),
|
||||
ok
|
||||
end;
|
||||
[] ->
|
||||
NewLs = [{Seq, Module, Function}],
|
||||
ets:insert(hooks, {{Hook, Host}, NewLs}),
|
||||
ets:insert(hooks, {{Hook, NHost}, NewLs}),
|
||||
ok
|
||||
end,
|
||||
{reply, Reply, State};
|
||||
@@ -205,10 +236,11 @@ handle_call({add, Hook, Host, Node, Module, Function, Seq}, _From, State) ->
|
||||
end,
|
||||
{reply, Reply, State};
|
||||
handle_call({delete, Hook, Host, Module, Function, Seq}, _From, State) ->
|
||||
Reply = case ets:lookup(hooks, {Hook, Host}) of
|
||||
NHost = ejabberd:normalize_host(Host),
|
||||
Reply = case ets:lookup(hooks, {Hook, NHost}) of
|
||||
[{_, Ls}] ->
|
||||
NewLs = lists:delete({Seq, Module, Function}, Ls),
|
||||
ets:insert(hooks, {{Hook, Host}, NewLs}),
|
||||
ets:insert(hooks, {{Hook, NHost}, NewLs}),
|
||||
ok;
|
||||
[] ->
|
||||
ok
|
||||
@@ -295,7 +327,7 @@ run1([{_Seq, Module, Function} | Ls], Hook, Args) ->
|
||||
[Reason, {Hook, Args}]),
|
||||
run1(Ls, Hook, Args);
|
||||
stop ->
|
||||
ok;
|
||||
stop;
|
||||
_ ->
|
||||
run1(Ls, Hook, Args)
|
||||
end.
|
||||
|
||||
@@ -0,0 +1,436 @@
|
||||
%%%-------------------------------------------------------------------
|
||||
%%% File : ejabberd_hosts.erl
|
||||
%%% Author : Alexey Shchepin <alexey@process-one.net>
|
||||
%%% Description : Synchronises running VHosts with the hosts table in the Mnesia database.
|
||||
%%% Created : 16 Nov 2007 by Alexey Shchepin <alexey@process-one.net>
|
||||
%%%-------------------------------------------------------------------
|
||||
|
||||
%%% Database schema (version / storage / table)
|
||||
%%%
|
||||
%%% 3.0.0-alpha-x / mnesia / hosts
|
||||
%%% host = string()
|
||||
%%% clusterid = integer()
|
||||
%%% config = string()
|
||||
%%%
|
||||
%%% 3.0.0-alpha-x / odbc / hosts
|
||||
%%% host = varchar150
|
||||
%%% clusterid = integer
|
||||
%%% config = text
|
||||
|
||||
-module(ejabberd_hosts).
|
||||
|
||||
-behaviour(gen_server).
|
||||
|
||||
%% External API
|
||||
-export([start_link/0
|
||||
,reload/0
|
||||
]).
|
||||
|
||||
%% Host Registration API
|
||||
-export([register/1
|
||||
,register/2
|
||||
,registered/1
|
||||
,running/1
|
||||
,registered/0
|
||||
,remove/1
|
||||
]).
|
||||
|
||||
%% Host control API
|
||||
-export([start_host/1
|
||||
,start_hosts/1
|
||||
,stop_host/1
|
||||
,stop_hosts/1
|
||||
,load_host_cert/2
|
||||
]).
|
||||
|
||||
%% Private utility functions
|
||||
-export([get_hosts/1
|
||||
,config_from_string/2
|
||||
,get_host_config/2
|
||||
,diff_hosts/0
|
||||
,diff_hosts/1
|
||||
,diff_hosts/2
|
||||
,reload_hosts/0
|
||||
,delete_host_config/1
|
||||
]).
|
||||
|
||||
%% gen_server callbacks
|
||||
-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
|
||||
terminate/2, code_change/3]).
|
||||
|
||||
-include("ejabberd.hrl").
|
||||
-include("ejabberd_config.hrl").
|
||||
-include_lib("stdlib/include/ms_transform.hrl").
|
||||
|
||||
-record(state, {state=wait_odbc,
|
||||
backend=mnesia,
|
||||
odbc_wait_time=120}).
|
||||
-record(hosts, {host, clusterid, config}).
|
||||
|
||||
-define(RELOAD_INTERVAL, timer:seconds(60)).
|
||||
-define(ODBC_STARTUP_TIME, 120). % 2minute limit for ODBC startup.
|
||||
|
||||
%%====================================================================
|
||||
%% API
|
||||
%%====================================================================
|
||||
|
||||
reload() ->
|
||||
?MODULE ! reload.
|
||||
|
||||
%% Creates a vhost in the system.
|
||||
register(Host) when is_list(Host) -> ?MODULE:register(Host, "").
|
||||
register(Host, Config) when is_list(Host), is_list(Config) ->
|
||||
true = exmpp_stringprep:is_node(Host),
|
||||
ID = get_clusterid(),
|
||||
H = #hosts{host = Host, clusterid = ID, config = Config},
|
||||
ok = gen_storage:dirty_write(Host, H),
|
||||
reload(),
|
||||
ok.
|
||||
|
||||
%% Removes a vhost from the system,
|
||||
%% XXX deleting all ODBC data.
|
||||
remove(Host) when is_list(Host) ->
|
||||
true = exmpp_stringprep:is_node(Host),
|
||||
ID = get_clusterid(),
|
||||
gen_storage:dirty_delete_where(
|
||||
Host, hosts,
|
||||
[{'andalso',
|
||||
{'==', clusterid, ID},
|
||||
{'==', host, Host}}]),
|
||||
reload(),
|
||||
ok.
|
||||
|
||||
registered() ->
|
||||
mnesia:dirty_select(local_config,
|
||||
ets:fun2ms(fun (#local_config{key={Host, host}}) ->
|
||||
Host
|
||||
end)).
|
||||
|
||||
registered(Host) when is_list(Host) ->
|
||||
case mnesia:dirty_read({local_config, {Host, host}}) of
|
||||
[{local_config, {Host, host}, _}] -> true;
|
||||
[] -> false
|
||||
end.
|
||||
|
||||
running(global) -> true;
|
||||
running(Host) ->
|
||||
Routes = [H
|
||||
|| {H, _, {apply, ejabberd_local, route}} <- ejabberd_router:read_route(Host),
|
||||
H =:= Host],
|
||||
Routes =/= [].
|
||||
|
||||
|
||||
load_host_cert(Host, PemData) ->
|
||||
File = cert_filename(Host),
|
||||
ok = file:write_file(File, PemData),
|
||||
configure_host_cert(Host, File).
|
||||
|
||||
%%--------------------------------------------------------------------
|
||||
%% Function: start_link() -> {ok,Pid} | ignore | {error,Error}
|
||||
%% Description: Starts the server
|
||||
%%--------------------------------------------------------------------
|
||||
start_link() ->
|
||||
gen_server:start_link({local, ?MODULE}, ?MODULE, [], []).
|
||||
|
||||
%%====================================================================
|
||||
%% gen_server callbacks
|
||||
%%====================================================================
|
||||
|
||||
%%--------------------------------------------------------------------
|
||||
%% Function: init(Args) -> {ok, State} |
|
||||
%% {ok, State, Timeout} |
|
||||
%% ignore |
|
||||
%% {stop, Reason}
|
||||
%% Description: Initiates the server
|
||||
%%--------------------------------------------------------------------
|
||||
init([]) ->
|
||||
Backend = mnesia, %%+++ TODO: allow to configure this in ejabberd.cfg
|
||||
configure_static_hosts(),
|
||||
get_clusterid(), %% this is to report an error if the option wasn't configured
|
||||
%% Wait up to 120 seconds for odbc to start
|
||||
{ok, #state{state=wait_odbc,backend=Backend,odbc_wait_time=?ODBC_STARTUP_TIME}, timer:seconds(1)}.
|
||||
|
||||
%%--------------------------------------------------------------------
|
||||
%% Function: %% handle_call(Request, From, State) -> {reply, Reply, State} |
|
||||
%% {reply, Reply, State, Timeout} |
|
||||
%% {noreply, State} |
|
||||
%% {noreply, State, Timeout} |
|
||||
%% {stop, Reason, Reply, State} |
|
||||
%% {stop, Reason, State}
|
||||
%% Description: Handling call messages
|
||||
%%--------------------------------------------------------------------
|
||||
handle_call(_Request, _From, State) ->
|
||||
Reply = ok,
|
||||
{reply, Reply, State}.
|
||||
|
||||
%%--------------------------------------------------------------------
|
||||
%% Function: handle_cast(Msg, State) -> {noreply, State} |
|
||||
%% {noreply, State, Timeout} |
|
||||
%% {stop, Reason, State}
|
||||
%% Description: Handling cast messages
|
||||
%%--------------------------------------------------------------------
|
||||
handle_cast(_Msg, State) ->
|
||||
{noreply, State}.
|
||||
|
||||
%%--------------------------------------------------------------------
|
||||
%% Function: handle_info(Info, State) -> {noreply, State} |
|
||||
%% {noreply, State, Timeout} |
|
||||
%% {stop, Reason, State}
|
||||
%% Description: Handling all non call/cast messages
|
||||
%%--------------------------------------------------------------------
|
||||
%% Wait for odbc to start.
|
||||
handle_info(timeout, State = #state{state=wait_odbc,backend=Backend,odbc_wait_time=N}) when N > 0 ->
|
||||
case (Backend /= odbc) orelse ejabberd_odbc:running(?MYNAME) of
|
||||
true ->
|
||||
?DEBUG("ejabberd_hosts: odbc now running.",[]),
|
||||
|
||||
%% The table 'hosts' is defined in gen_storage as being for the "localhost" vhost
|
||||
Host = ?MYNAME,
|
||||
HostB = list_to_binary(Host),
|
||||
gen_storage:create_table(Backend, HostB, hosts,
|
||||
[{disc_only_copies, [node()]},
|
||||
{odbc_host, Host},
|
||||
{attributes, record_info(fields, hosts)},
|
||||
{types, [{host, text},
|
||||
{clusterid, int},
|
||||
{config, text}]}]),
|
||||
|
||||
%% Now let's add the default vhost: "localhost"
|
||||
gen_storage:dirty_write(Host, #hosts{host = Host,
|
||||
clusterid = 1,
|
||||
config = ""}),
|
||||
|
||||
self() ! reload,
|
||||
timer:send_interval(?RELOAD_INTERVAL, reload),
|
||||
{noreply, State#state{state=running,odbc_wait_time=0}};
|
||||
false ->
|
||||
{noreply,State#state{odbc_wait_time=N-1},timer:seconds(1)}
|
||||
end;
|
||||
handle_info(timeout, State=#state{state=running}) ->
|
||||
?WARNING_MSG("Spurious timeout message when odbc is already running.", []),
|
||||
{noreply, State};
|
||||
|
||||
handle_info(reload, State = #state{state=running}) ->
|
||||
try reload_hosts()
|
||||
catch
|
||||
Class:Error ->
|
||||
StackTrace = erlang:get_stacktrace(),
|
||||
?ERROR_MSG("~p while synchonising running vhosts with database: ~p~n~p", [Class, Error, StackTrace])
|
||||
end,
|
||||
{noreply, State};
|
||||
handle_info(reload, State = #state{state=wait_odbc}) ->
|
||||
?ERROR_MSG("Tried to reload vhosts while waiting for odbc startup.", []),
|
||||
handle_info(timeout, State);
|
||||
|
||||
handle_info(_Info, State) ->
|
||||
{noreply, State}.
|
||||
|
||||
%%--------------------------------------------------------------------
|
||||
%% Function: terminate(Reason, State) -> void()
|
||||
%% Description: This function is called by a gen_server when it is about to
|
||||
%% terminate. It should be the opposite of Module:init/1 and do any necessary
|
||||
%% cleaning up. When it returns, the gen_server terminates with Reason.
|
||||
%% The return value is ignored.
|
||||
%%--------------------------------------------------------------------
|
||||
terminate(_Reason, _State) ->
|
||||
ok.
|
||||
|
||||
%%--------------------------------------------------------------------
|
||||
%% Func: code_change(OldVsn, State, Extra) -> {ok, NewState}
|
||||
%% Description: Convert process state when code is changed
|
||||
%%--------------------------------------------------------------------
|
||||
code_change(_OldVsn, State, _Extra) ->
|
||||
{ok, State}.
|
||||
|
||||
%%--------------------------------------------------------------------
|
||||
%%% Internal functions
|
||||
%%--------------------------------------------------------------------
|
||||
|
||||
reload_hosts() ->
|
||||
reload_hosts(get_hosts(odbc)).
|
||||
|
||||
reload_hosts(NewHosts) ->
|
||||
{AddedHosts,RemovedHosts} = diff_hosts(NewHosts),
|
||||
%% Avoid removing permanent hosts (staticly configured hosts)
|
||||
DeletedHosts = [H || H <- RemovedHosts,
|
||||
ejabberd_config:get_host_option(H, permanent) =/= true],
|
||||
AddHostConfig = lists:map(fun (Host) ->
|
||||
{Host, get_host_config(odbc,Host)}
|
||||
end, AddedHosts),
|
||||
update_config(AddHostConfig,DeletedHosts),
|
||||
ejabberd_config:add_global_option(hosts, NewHosts), % overwrite hosts list
|
||||
stop_hosts(DeletedHosts),
|
||||
start_hosts(AddedHosts),
|
||||
ejabberd_local:refresh_iq_handlers(),
|
||||
{DeletedHosts, AddedHosts}.
|
||||
|
||||
%% Apply the vhost changes (new, removed vhosts, configuration) to mnesia
|
||||
update_config(AddHostConfig, RemoveHosts) ->
|
||||
F = fun() ->
|
||||
mnesia:write_lock_table(local_config),
|
||||
lists:foreach(fun configure_new_host/1, AddHostConfig),
|
||||
lists:foreach(fun delete_host_config/1, RemoveHosts),
|
||||
ok
|
||||
end,
|
||||
{atomic, ok} = mnesia:transaction(F).
|
||||
|
||||
%% Write the configuration data for a new vhost to mnesia (currently only modules)
|
||||
configure_new_host({H, Config}) when is_list(Config) ->
|
||||
reconfigure_host_cert(H),
|
||||
ejabberd_config:configure_host(H, Config).
|
||||
|
||||
%% Delete the mnesia config data for a vhost.
|
||||
%% Needs to mirror any data we insert in configure_new_host (currently only modules)
|
||||
delete_host_config(Host) ->
|
||||
ejabberd_config:delete_host(Host).
|
||||
|
||||
%% Startup a list of vhosts
|
||||
start_hosts([]) -> ok;
|
||||
start_hosts(AddHosts) when is_list(AddHosts) ->
|
||||
?DEBUG("ejabberd_hosts adding hosts: ~P", [AddHosts, 10]),
|
||||
lists:foreach(fun start_host/1, AddHosts).
|
||||
|
||||
%% Start a single vhost (route, modules)
|
||||
start_host(Host) ->
|
||||
?DEBUG("Starting host ~p", [Host]),
|
||||
ejabberd_router:register_route(Host, {apply, ejabberd_local, route}),
|
||||
case ejabberd_config:get_local_option({modules, Host}) of
|
||||
undefined -> ok;
|
||||
Modules when is_list(Modules) ->
|
||||
lists:foreach(
|
||||
fun({Module, Args}) ->
|
||||
gen_mod:start_module(Host, Module, Args)
|
||||
end, Modules)
|
||||
end,
|
||||
case auth_method(Host) of
|
||||
{host_method, HostMethod} ->
|
||||
ejabberd_auth:start_method(Host, HostMethod);
|
||||
_ -> ignore
|
||||
end,
|
||||
ok.
|
||||
|
||||
|
||||
%% Shut down a list of vhosts.
|
||||
stop_hosts([]) -> ok;
|
||||
stop_hosts(RemoveHosts) when is_list(RemoveHosts)->
|
||||
?DEBUG("ejabberd_hosts removing hosts: ~p", [RemoveHosts]),
|
||||
lists:foreach(fun stop_host/1, RemoveHosts).
|
||||
|
||||
%% Shut down a single vhost. (Routes, modules)
|
||||
stop_host(Host) ->
|
||||
?DEBUG("Stopping host ~p", [Host]),
|
||||
ejabberd_router:force_unregister_route(Host),
|
||||
lists:foreach(fun(Module) ->
|
||||
gen_mod:stop_module(Host, Module)
|
||||
end, gen_mod:loaded_modules(Host)),
|
||||
case auth_method(Host) of
|
||||
use_global_auth_method -> ok;
|
||||
{host_method, Method} ->
|
||||
ejabberd_auth:stop_method(Host, Method)
|
||||
end.
|
||||
|
||||
%% Get the current vhost list from a variety of sources (ODBC, internal)
|
||||
get_hosts(ejabberd) -> ?MYHOSTS;
|
||||
get_hosts(odbc) ->
|
||||
ClusterID = get_clusterid(),
|
||||
case gen_storage:dirty_select(?MYNAME, hosts, [{'=', clusterid, ClusterID}]) of
|
||||
Hosts when is_list(Hosts) ->
|
||||
lists:map(fun (#hosts{host = Host}) ->
|
||||
case exmpp_stringprep:nameprep(Host) of
|
||||
error ->
|
||||
erlang:error({bad_vhost_name, Host});
|
||||
Name ->
|
||||
Name
|
||||
end
|
||||
end, Hosts);
|
||||
E ->
|
||||
erlang:error({get_hosts_error, E})
|
||||
end.
|
||||
|
||||
%% Retreive the text format config for host Host from ODBC and covert
|
||||
%% it into a {host, Host, Config} tuple.
|
||||
get_host_config(odbc, Host) ->
|
||||
case gen_storage:dirty_read(?MYNAME, hosts, Host) of
|
||||
[] ->
|
||||
erlang:error({no_such_host, Host});
|
||||
[H] ->
|
||||
config_from_string(Host, H#hosts.config);
|
||||
E ->
|
||||
erlang:error({host_config_error, E})
|
||||
end.
|
||||
|
||||
%% Convert a plaintext string into a host config tuple.
|
||||
config_from_string(_Host, "") -> [];
|
||||
config_from_string(_Host, Config) ->
|
||||
{ok, Tokens, _} = erl_scan:string(Config),
|
||||
case erl_parse:parse_term(Tokens) of
|
||||
{ok, List} when is_list(List) ->
|
||||
List;
|
||||
E ->
|
||||
erlang:error({bad_host_config, Config, E})
|
||||
end.
|
||||
|
||||
diff_hosts() ->
|
||||
diff_hosts(get_hosts(odbc)).
|
||||
|
||||
diff_hosts(NewHosts) ->
|
||||
diff_hosts(NewHosts, get_hosts(ejabberd)).
|
||||
|
||||
%% Given the new list of vhosts and the old list, return the list of
|
||||
%% hosts added since last time and the list of hosts that have been
|
||||
%% removed.
|
||||
diff_hosts(NewHosts, OldHosts) ->
|
||||
RemoveHosts = OldHosts -- NewHosts,
|
||||
AddHosts = NewHosts -- OldHosts,
|
||||
{AddHosts,RemoveHosts}.
|
||||
|
||||
%% XXX - this should be part of auth, not hosts.
|
||||
auth_method(Host) ->
|
||||
case ejabberd_config:get_host_option(Host, auth_method) of
|
||||
undefined ->
|
||||
use_global_auth_method;
|
||||
Other ->
|
||||
{host_method, Other}
|
||||
end.
|
||||
|
||||
configure_static_hosts() ->
|
||||
?DEBUG("Node startup - configuring hosts: ~p", [?MYHOSTS]),
|
||||
%% Add a null configuration for all MYHOSTS - this ensures
|
||||
%% the 'I'm a host' term gets written to the config table.
|
||||
%% We don't need any configuration options because these are
|
||||
%% statically configured hosts already configured by ejabberd_config.
|
||||
F = fun () ->
|
||||
lists:foreach(fun (H) -> ejabberd_config:configure_host(H, [{permanent, true}]) end,
|
||||
?MYHOSTS)
|
||||
end,
|
||||
mnesia:transaction(F).
|
||||
|
||||
cert_filename(Host) ->
|
||||
Dir = ejabberd_config:get_local_option({domain_certdir, global}),
|
||||
filename:join(Dir, Host ++ ".pem").
|
||||
|
||||
configure_host_cert(Host, File) ->
|
||||
ejabberd_config:add_local_option({domain_certfile, Host}, File),
|
||||
ok.
|
||||
|
||||
reconfigure_host_cert(Host) ->
|
||||
File = cert_filename(Host),
|
||||
case ejabberd_config:is_file_readable(File) of
|
||||
true ->
|
||||
ejabberd_config:mne_add_local_option({domain_certfile, Host}, File),
|
||||
ok;
|
||||
false ->
|
||||
no_cert
|
||||
end.
|
||||
|
||||
get_clusterid() ->
|
||||
case ejabberd_config:get_local_option(clusterid) of
|
||||
ID when is_integer(ID) ->
|
||||
ID;
|
||||
undefined ->
|
||||
?ERROR_MSG("Please add to your ejabberd.cfg the line: ~n {clusterid, 1}.", []),
|
||||
1;
|
||||
Other ->
|
||||
?ERROR_MSG("Change your misconfigured {clusterid, ~p} to the value: ~p", [Other, 1]),
|
||||
1
|
||||
end.
|
||||
@@ -35,7 +35,8 @@
|
||||
stop_listener/2,
|
||||
parse_listener_portip/2,
|
||||
add_listener/3,
|
||||
delete_listener/2
|
||||
delete_listener/2,
|
||||
rate_limit/2
|
||||
]).
|
||||
|
||||
-include("ejabberd.hrl").
|
||||
@@ -48,42 +49,8 @@ start_link() ->
|
||||
|
||||
|
||||
init(_) ->
|
||||
ets:new(listen_sockets, [named_table, public]),
|
||||
bind_tcp_ports(),
|
||||
{ok, {{one_for_one, 10, 1}, []}}.
|
||||
|
||||
bind_tcp_ports() ->
|
||||
case ejabberd_config:get_local_option(listen) of
|
||||
undefined ->
|
||||
ignore;
|
||||
Ls ->
|
||||
lists:foreach(
|
||||
fun({Port, Module, Opts}) ->
|
||||
ModuleRaw = strip_frontend(Module),
|
||||
case ModuleRaw:socket_type() of
|
||||
independent -> ok;
|
||||
_ ->
|
||||
bind_tcp_port(Port, Module, Opts)
|
||||
end
|
||||
end, Ls)
|
||||
end.
|
||||
|
||||
bind_tcp_port(PortIP, Module, RawOpts) ->
|
||||
try check_listener_options(RawOpts) of
|
||||
ok ->
|
||||
{Port, IPT, IPS, IPV, Proto, OptsClean} = parse_listener_portip(PortIP, RawOpts),
|
||||
{_Opts, SockOpts} = prepare_opts(IPT, IPV, OptsClean),
|
||||
case Proto of
|
||||
udp -> ok;
|
||||
_ ->
|
||||
ListenSocket = listen_tcp(PortIP, Module, SockOpts, Port, IPS),
|
||||
ets:insert(listen_sockets, {PortIP, ListenSocket})
|
||||
end
|
||||
catch
|
||||
throw:{error, Error} ->
|
||||
?ERROR_MSG(Error, [])
|
||||
end.
|
||||
|
||||
start_listeners() ->
|
||||
case ejabberd_config:get_local_option(listen) of
|
||||
undefined ->
|
||||
@@ -133,7 +100,15 @@ start_dependent(Port, Module, Opts) ->
|
||||
|
||||
init(PortIP, Module, RawOpts) ->
|
||||
{Port, IPT, IPS, IPV, Proto, OptsClean} = parse_listener_portip(PortIP, RawOpts),
|
||||
{Opts, SockOpts} = prepare_opts(IPT, IPV, OptsClean),
|
||||
%% The first inet|inet6 and the last {ip, _} work,
|
||||
%% so overriding those in Opts
|
||||
Opts = [IPV | OptsClean] ++ [{ip, IPT}],
|
||||
SockOpts = lists:filter(fun({ip, _}) -> true;
|
||||
(inet6) -> true;
|
||||
(inet) -> true;
|
||||
({backlog, _}) -> true;
|
||||
(_) -> false
|
||||
end, Opts),
|
||||
if Proto == udp ->
|
||||
init_udp(PortIP, Module, Opts, SockOpts, Port, IPS);
|
||||
true ->
|
||||
@@ -154,39 +129,26 @@ init_udp(PortIP, Module, Opts, SockOpts, Port, IPS) ->
|
||||
end.
|
||||
|
||||
init_tcp(PortIP, Module, Opts, SockOpts, Port, IPS) ->
|
||||
ListenSocket = listen_tcp(PortIP, Module, SockOpts, Port, IPS),
|
||||
%% Inform my parent that this port was opened succesfully
|
||||
proc_lib:init_ack({ok, self()}),
|
||||
%% And now start accepting connection attempts
|
||||
accept(ListenSocket, Module, Opts).
|
||||
|
||||
listen_tcp(PortIP, Module, SockOpts, Port, IPS) ->
|
||||
case ets:lookup(listen_sockets, PortIP) of
|
||||
[{PortIP, ListenSocket}] ->
|
||||
?INFO_MSG("Reusing listening port for ~p", [Port]),
|
||||
ets:delete(listen_sockets, Port),
|
||||
ListenSocket;
|
||||
_ ->
|
||||
SockOpts2 = try erlang:system_info(otp_release) >= "R13B" of
|
||||
true -> [{send_timeout_close, true} | SockOpts];
|
||||
false -> SockOpts
|
||||
catch
|
||||
_:_ -> []
|
||||
end,
|
||||
Res = gen_tcp:listen(Port, [binary,
|
||||
{packet, 0},
|
||||
{active, false},
|
||||
{reuseaddr, true},
|
||||
{nodelay, true},
|
||||
{send_timeout, ?TCP_SEND_TIMEOUT},
|
||||
{keepalive, true} |
|
||||
SockOpts2]),
|
||||
case Res of
|
||||
{ok, ListenSocket} ->
|
||||
ListenSocket;
|
||||
{error, Reason} ->
|
||||
socket_error(Reason, PortIP, Module, SockOpts, Port, IPS)
|
||||
end
|
||||
SockOpts2 = case erlang:system_info(otp_release) >= "R13B" of
|
||||
true -> [{send_timeout_close, true} | SockOpts];
|
||||
false -> SockOpts
|
||||
end,
|
||||
Res = gen_tcp:listen(Port, [binary,
|
||||
{packet, 0},
|
||||
{active, false},
|
||||
{reuseaddr, true},
|
||||
{nodelay, true},
|
||||
{send_timeout, ?TCP_SEND_TIMEOUT},
|
||||
{keepalive, true} |
|
||||
SockOpts2]),
|
||||
case Res of
|
||||
{ok, ListenSocket} ->
|
||||
%% Inform my parent that this port was opened succesfully
|
||||
proc_lib:init_ack({ok, self()}),
|
||||
%% And now start accepting connection attempts
|
||||
accept(ListenSocket, Module, Opts);
|
||||
{error, Reason} ->
|
||||
socket_error(Reason, PortIP, Module, SockOpts, Port, IPS)
|
||||
end.
|
||||
|
||||
%% @spec (PortIP, Opts) -> {Port, IPT, IPS, IPV, OptsClean}
|
||||
@@ -231,18 +193,6 @@ parse_listener_portip(PortIP, Opts) ->
|
||||
end,
|
||||
{Port, IPT, IPS, IPV, Proto, OptsClean}.
|
||||
|
||||
prepare_opts(IPT, IPV, OptsClean) ->
|
||||
%% The first inet|inet6 and the last {ip, _} work,
|
||||
%% so overriding those in Opts
|
||||
Opts = [IPV | OptsClean] ++ [{ip, IPT}],
|
||||
SockOpts = lists:filter(fun({ip, _}) -> true;
|
||||
(inet6) -> true;
|
||||
(inet) -> true;
|
||||
({backlog, _}) -> true;
|
||||
(_) -> false
|
||||
end, Opts),
|
||||
{Opts, SockOpts}.
|
||||
|
||||
add_proto(Port, Opts) when is_integer(Port) ->
|
||||
{Port, get_proto(Opts)};
|
||||
add_proto({Port, Proto}, _Opts) when is_atom(Proto) ->
|
||||
@@ -274,6 +224,9 @@ get_ip_tuple(IPOpt, _IPVOpt) ->
|
||||
IPOpt.
|
||||
|
||||
accept(ListenSocket, Module, Opts) ->
|
||||
accept(ListenSocket, Module, Opts, 0).
|
||||
accept(ListenSocket, Module, Opts, Interval) ->
|
||||
NewInterval = check_rate_limit(Interval),
|
||||
case gen_tcp:accept(ListenSocket) of
|
||||
{ok, Socket} ->
|
||||
case {inet:sockname(Socket), inet:peername(Socket)} of
|
||||
@@ -288,11 +241,11 @@ accept(ListenSocket, Module, Opts) ->
|
||||
false -> ejabberd_socket
|
||||
end,
|
||||
CallMod:start(strip_frontend(Module), gen_tcp, Socket, Opts),
|
||||
accept(ListenSocket, Module, Opts);
|
||||
accept(ListenSocket, Module, Opts, NewInterval);
|
||||
{error, Reason} ->
|
||||
?INFO_MSG("(~w) Failed TCP accept: ~w",
|
||||
[ListenSocket, Reason]),
|
||||
accept(ListenSocket, Module, Opts)
|
||||
accept(ListenSocket, Module, Opts, NewInterval)
|
||||
end.
|
||||
|
||||
udp_recv(Socket, Module, Opts) ->
|
||||
@@ -520,3 +473,39 @@ format_error(Reason) ->
|
||||
ReasonStr ->
|
||||
ReasonStr
|
||||
end.
|
||||
|
||||
%% Set interval between two accepts on given port
|
||||
rate_limit([], _Interval) ->
|
||||
ok;
|
||||
rate_limit([Port|Ports], Interval) ->
|
||||
rate_limit(Port, Interval),
|
||||
rate_limit(Ports, Interval);
|
||||
rate_limit(Port, Interval) ->
|
||||
case get_listener_pid_by_port(Port) of
|
||||
undefined -> no_listener;
|
||||
Pid -> Pid ! {rate_limit, Interval}, ok
|
||||
end.
|
||||
|
||||
get_listener_pid_by_port(Port) ->
|
||||
ListenerPids = [Pid || {{P,_,_},Pid,_,_} <-
|
||||
supervisor:which_children(erlang:whereis(ejabberd_listeners)),
|
||||
P == Port],
|
||||
ListenerPid = case ListenerPids of
|
||||
[] -> undefined;
|
||||
[LPid|_] -> LPid
|
||||
end,
|
||||
ListenerPid.
|
||||
|
||||
check_rate_limit(Interval) ->
|
||||
NewInterval = receive
|
||||
{rate_limit, AcceptInterval} ->
|
||||
AcceptInterval
|
||||
after 0 ->
|
||||
Interval
|
||||
end,
|
||||
case NewInterval of
|
||||
0 -> ok;
|
||||
Ms ->
|
||||
timer:sleep(Ms)
|
||||
end,
|
||||
NewInterval.
|
||||
|
||||
@@ -48,8 +48,9 @@
|
||||
-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
|
||||
terminate/2, code_change/3]).
|
||||
|
||||
-include_lib("exmpp/include/exmpp.hrl").
|
||||
|
||||
-include("ejabberd.hrl").
|
||||
-include("jlib.hrl").
|
||||
|
||||
-record(state, {}).
|
||||
|
||||
@@ -60,6 +61,13 @@
|
||||
%% This value is used in SIP and Megaco for a transaction lifetime.
|
||||
-define(IQ_TIMEOUT, 32000).
|
||||
|
||||
% These are the namespace already declared by the stream opening. This is
|
||||
% used at serialization time.
|
||||
-define(DEFAULT_NS, ?NS_JABBER_CLIENT).
|
||||
-define(PREFIXED_NS, [
|
||||
{?NS_XMPP, ?NS_XMPP_pfx}, {?NS_DIALBACK, ?NS_DIALBACK_pfx}
|
||||
]).
|
||||
|
||||
%%====================================================================
|
||||
%% API
|
||||
%%====================================================================
|
||||
@@ -71,33 +79,38 @@ start_link() ->
|
||||
gen_server:start_link({local, ?MODULE}, ?MODULE, [], []).
|
||||
|
||||
process_iq(From, To, Packet) ->
|
||||
IQ = jlib:iq_query_info(Packet),
|
||||
case IQ of
|
||||
#iq{xmlns = XMLNS} ->
|
||||
Host = To#jid.lserver,
|
||||
case ets:lookup(?IQTABLE, {XMLNS, Host}) of
|
||||
case exmpp_iq:xmlel_to_iq(Packet) of
|
||||
#iq{kind = request, ns = XMLNS} = IQ_Rec ->
|
||||
Host = exmpp_jid:prep_domain(To),
|
||||
case ets:lookup(?IQTABLE, {XMLNS, ejabberd:normalize_host(Host)}) of
|
||||
[{_, Module, Function}] ->
|
||||
ResIQ = Module:Function(From, To, IQ),
|
||||
ResIQ = Module:Function(From, To, IQ_Rec),
|
||||
if
|
||||
ResIQ /= ignore ->
|
||||
ejabberd_router:route(
|
||||
To, From, jlib:iq_to_xml(ResIQ));
|
||||
Reply = exmpp_iq:iq_to_xmlel(ResIQ, To, From),
|
||||
ejabberd_router:route(To, From, Reply);
|
||||
true ->
|
||||
ok
|
||||
end;
|
||||
[{_, Module, Function, Opts}] ->
|
||||
gen_iq_handler:handle(Host, Module, Function, Opts,
|
||||
From, To, IQ);
|
||||
From, To, IQ_Rec);
|
||||
[] ->
|
||||
Err = jlib:make_error_reply(
|
||||
Packet, ?ERR_FEATURE_NOT_IMPLEMENTED),
|
||||
ejabberd_router:route(To, From, Err)
|
||||
case ets:lookup(?IQTABLE, {XMLNS, global}) of
|
||||
[{_, Module, Function, Opts}] ->
|
||||
gen_iq_handler:handle(
|
||||
global, Module, Function, Opts,
|
||||
From, To, IQ_Rec);
|
||||
[] ->
|
||||
Err = exmpp_iq:error(Packet, 'feature-not-implemented'),
|
||||
ejabberd_router:route(To, From, Err)
|
||||
end
|
||||
end;
|
||||
reply ->
|
||||
IQReply = jlib:iq_query_or_response_info(Packet),
|
||||
process_iq_reply(From, To, IQReply);
|
||||
#iq{kind = response} = IQReply ->
|
||||
%%IQReply = jlib:iq_query_or_response_info(IQ_Rec),
|
||||
process_iq_reply(From, To, IQReply);
|
||||
_ ->
|
||||
Err = jlib:make_error_reply(Packet, ?ERR_BAD_REQUEST),
|
||||
Err = exmpp_iq:error(Packet, 'bad-request'),
|
||||
ejabberd_router:route(To, From, Err),
|
||||
ok
|
||||
end.
|
||||
@@ -113,7 +126,18 @@ process_iq_reply(From, To, #iq{id = ID} = IQ) ->
|
||||
_ ->
|
||||
nothing
|
||||
end.
|
||||
|
||||
|
||||
%% #xmlelement{} used for retro-compatibility
|
||||
route(FromOld, ToOld, #xmlelement{} = PacketOld) ->
|
||||
catch throw(for_stacktrace), % To have a stacktrace.
|
||||
io:format("~nLOCAL: old #xmlelement:~n~p~n~p~n~n",
|
||||
[PacketOld, erlang:get_stacktrace()]),
|
||||
% XXX OLD FORMAT: From, To, Packet.
|
||||
From = jlib:from_old_jid(FromOld),
|
||||
To = jlib:from_old_jid(ToOld),
|
||||
Packet = exmpp_xml:xmlelement_to_xmlel(PacketOld, [?NS_JABBER_CLIENT],
|
||||
[{?NS_XMPP, ?NS_XMPP_pfx}]),
|
||||
route(From, To, Packet);
|
||||
route(From, To, Packet) ->
|
||||
case catch do_route(From, To, Packet) of
|
||||
{'EXIT', Reason} ->
|
||||
@@ -125,21 +149,21 @@ route(From, To, Packet) ->
|
||||
|
||||
route_iq(From, To, #iq{type = Type} = IQ, F) when is_function(F) ->
|
||||
Packet = if Type == set; Type == get ->
|
||||
ID = randoms:get_string(),
|
||||
Host = From#jid.lserver,
|
||||
ID = list_to_binary(ejabberd_router:make_id()),
|
||||
Host = exmpp_jid:prep_domain(From),
|
||||
register_iq_response_handler(Host, ID, undefined, F),
|
||||
jlib:iq_to_xml(IQ#iq{id = ID});
|
||||
exmpp_iq:iq_to_xmlel(IQ#iq{id = ID});
|
||||
true ->
|
||||
jlib:iq_to_xml(IQ)
|
||||
exmpp_iq:iq_to_xmlel(IQ)
|
||||
end,
|
||||
ejabberd_router:route(From, To, Packet).
|
||||
|
||||
register_iq_response_handler(_Host, ID, Module, Function) ->
|
||||
TRef = erlang:start_timer(?IQ_TIMEOUT, ejabberd_local, ID),
|
||||
mnesia:dirty_write(#iq_response{id = ID,
|
||||
module = Module,
|
||||
function = Function,
|
||||
timer = TRef}).
|
||||
ets:insert(iq_response, #iq_response{id = ID,
|
||||
module = Module,
|
||||
function = Function,
|
||||
timer = TRef}).
|
||||
|
||||
register_iq_handler(Host, XMLNS, Module, Fun) ->
|
||||
ejabberd_local ! {register_iq_handler, Host, XMLNS, Module, Fun}.
|
||||
@@ -158,7 +182,7 @@ refresh_iq_handlers() ->
|
||||
ejabberd_local ! refresh_iq_handlers.
|
||||
|
||||
bounce_resource_packet(From, To, Packet) ->
|
||||
Err = jlib:make_error_reply(Packet, ?ERR_ITEM_NOT_FOUND),
|
||||
Err = exmpp_stanza:reply_with_error(Packet, 'item-not-found'),
|
||||
ejabberd_router:route(To, From, Err),
|
||||
stop.
|
||||
|
||||
@@ -176,16 +200,14 @@ bounce_resource_packet(From, To, Packet) ->
|
||||
init([]) ->
|
||||
lists:foreach(
|
||||
fun(Host) ->
|
||||
ejabberd_router:register_route(Host, {apply, ?MODULE, route}),
|
||||
ejabberd_hooks:add(local_send_to_resource_hook, Host,
|
||||
?MODULE, bounce_resource_packet, 100)
|
||||
ejabberd_router:register_route(Host, {apply, ?MODULE, route})
|
||||
end, ?MYHOSTS),
|
||||
ejabberd_hooks:add(local_send_to_resource_hook, global,
|
||||
?MODULE, bounce_resource_packet, 100),
|
||||
catch ets:new(?IQTABLE, [named_table, public]),
|
||||
update_table(),
|
||||
mnesia:create_table(iq_response,
|
||||
[{ram_copies, [node()]},
|
||||
{attributes, record_info(fields, iq_response)}]),
|
||||
mnesia:add_table_copy(iq_response, node(), ram_copies),
|
||||
mnesia:delete_table(iq_response),
|
||||
catch ets:new(iq_response, [named_table, public,
|
||||
{keypos, #iq_response.id}]),
|
||||
{ok, #state{}}.
|
||||
|
||||
%%--------------------------------------------------------------------
|
||||
@@ -216,6 +238,18 @@ handle_cast(_Msg, State) ->
|
||||
%% {stop, Reason, State}
|
||||
%% Description: Handling all non call/cast messages
|
||||
%%--------------------------------------------------------------------
|
||||
|
||||
%% #xmlelement{} used for retro-compatibility
|
||||
handle_info({route, FromOld, ToOld, #xmlelement{} = PacketOld}, State) ->
|
||||
catch throw(for_stacktrace), % To have a stacktrace.
|
||||
io:format("~nLOCAL: old #xmlelement:~n~p~n~p~n~n",
|
||||
[PacketOld, erlang:get_stacktrace()]),
|
||||
% XXX OLD FORMAT: From, To, Packet.
|
||||
From = jlib:from_old_jid(FromOld),
|
||||
To = jlib:from_old_jid(ToOld),
|
||||
Packet = exmpp_xml:xmlelement_to_xmlel(PacketOld, [?NS_JABBER_CLIENT],
|
||||
[{?NS_XMPP, ?NS_XMPP_pfx}]),
|
||||
handle_info({route, From, To, Packet}, State);
|
||||
handle_info({route, From, To, Packet}, State) ->
|
||||
case catch do_route(From, To, Packet) of
|
||||
{'EXIT', Reason} ->
|
||||
@@ -226,21 +260,21 @@ handle_info({route, From, To, Packet}, State) ->
|
||||
end,
|
||||
{noreply, State};
|
||||
handle_info({register_iq_handler, Host, XMLNS, Module, Function}, State) ->
|
||||
ets:insert(?IQTABLE, {{XMLNS, Host}, Module, Function}),
|
||||
ets:insert(?IQTABLE, {{XMLNS, ejabberd:normalize_host(Host)}, Module, Function}),
|
||||
catch mod_disco:register_feature(Host, XMLNS),
|
||||
{noreply, State};
|
||||
handle_info({register_iq_handler, Host, XMLNS, Module, Function, Opts}, State) ->
|
||||
ets:insert(?IQTABLE, {{XMLNS, Host}, Module, Function, Opts}),
|
||||
ets:insert(?IQTABLE, {{XMLNS, ejabberd:normalize_host(Host)}, Module, Function, Opts}),
|
||||
catch mod_disco:register_feature(Host, XMLNS),
|
||||
{noreply, State};
|
||||
handle_info({unregister_iq_handler, Host, XMLNS}, State) ->
|
||||
case ets:lookup(?IQTABLE, {XMLNS, Host}) of
|
||||
case ets:lookup(?IQTABLE, {XMLNS, ejabberd:normalize_host(Host)}) of
|
||||
[{_, Module, Function, Opts}] ->
|
||||
gen_iq_handler:stop_iq_handler(Module, Function, Opts);
|
||||
_ ->
|
||||
ok
|
||||
end,
|
||||
ets:delete(?IQTABLE, {XMLNS, Host}),
|
||||
ets:delete(?IQTABLE, {XMLNS, ejabberd:normalize_host(Host)}),
|
||||
catch mod_disco:unregister_feature(Host, XMLNS),
|
||||
{noreply, State};
|
||||
handle_info(refresh_iq_handlers, State) ->
|
||||
@@ -257,7 +291,7 @@ handle_info(refresh_iq_handlers, State) ->
|
||||
end, ets:tab2list(?IQTABLE)),
|
||||
{noreply, State};
|
||||
handle_info({timeout, _TRef, ID}, State) ->
|
||||
process_iq_timeout(ID),
|
||||
spawn(fun() -> process_iq_timeout(ID) end),
|
||||
{noreply, State};
|
||||
handle_info(_Info, State) ->
|
||||
{noreply, State}.
|
||||
@@ -285,67 +319,50 @@ code_change(_OldVsn, State, _Extra) ->
|
||||
do_route(From, To, Packet) ->
|
||||
?DEBUG("local route~n\tfrom ~p~n\tto ~p~n\tpacket ~P~n",
|
||||
[From, To, Packet, 8]),
|
||||
|
||||
LNode = exmpp_jid:prep_node(To),
|
||||
LResource = exmpp_jid:prep_resource(To),
|
||||
if
|
||||
To#jid.luser /= "" ->
|
||||
LNode /= undefined ->
|
||||
ejabberd_sm:route(From, To, Packet);
|
||||
To#jid.lresource == "" ->
|
||||
{xmlelement, Name, _Attrs, _Els} = Packet,
|
||||
case Name of
|
||||
"iq" ->
|
||||
LResource == undefined ->
|
||||
case Packet of
|
||||
_ when ?IS_IQ(Packet) ->
|
||||
process_iq(From, To, Packet);
|
||||
"message" ->
|
||||
_ when ?IS_MESSAGE(Packet) ->
|
||||
ok;
|
||||
"presence" ->
|
||||
_ when ?IS_PRESENCE(Packet) ->
|
||||
ok;
|
||||
_ ->
|
||||
ok
|
||||
end;
|
||||
true ->
|
||||
{xmlelement, _Name, Attrs, _Els} = Packet,
|
||||
case xml:get_attr_s("type", Attrs) of
|
||||
"error" -> ok;
|
||||
"result" -> ok;
|
||||
case exmpp_stanza:get_type(Packet) of
|
||||
<<"error">> -> ok;
|
||||
<<"result">> -> ok;
|
||||
_ ->
|
||||
ejabberd_hooks:run(local_send_to_resource_hook,
|
||||
To#jid.lserver,
|
||||
exmpp_jid:prep_domain(To),
|
||||
[From, To, Packet])
|
||||
end
|
||||
end.
|
||||
|
||||
update_table() ->
|
||||
case catch mnesia:table_info(iq_response, attributes) of
|
||||
[id, module, function] ->
|
||||
mnesia:delete_table(iq_response);
|
||||
[id, module, function, timer] ->
|
||||
ok;
|
||||
{'EXIT', _} ->
|
||||
ok
|
||||
end.
|
||||
|
||||
get_iq_callback(ID) ->
|
||||
case mnesia:dirty_read(iq_response, ID) of
|
||||
case ets:lookup(iq_response, ID) of
|
||||
[#iq_response{module = Module, timer = TRef,
|
||||
function = Function}] ->
|
||||
cancel_timer(TRef),
|
||||
mnesia:dirty_delete(iq_response, ID),
|
||||
ets:delete(iq_response, ID),
|
||||
{ok, Module, Function};
|
||||
_ ->
|
||||
error
|
||||
end.
|
||||
|
||||
process_iq_timeout(ID) ->
|
||||
spawn(fun process_iq_timeout/0) ! ID.
|
||||
|
||||
process_iq_timeout() ->
|
||||
receive
|
||||
ID ->
|
||||
case get_iq_callback(ID) of
|
||||
{ok, undefined, Function} ->
|
||||
Function(timeout);
|
||||
_ ->
|
||||
ok
|
||||
end
|
||||
after 5000 ->
|
||||
case get_iq_callback(ID) of
|
||||
{ok, undefined, Function} ->
|
||||
Function(timeout);
|
||||
_ ->
|
||||
ok
|
||||
end.
|
||||
|
||||
|
||||
@@ -151,19 +151,6 @@ write_event(Fd, {Time, {info_msg, _GL, {Pid, Format, Args}}}) ->
|
||||
F = add_node("ERROR: ~p - ~p~n", Pid),
|
||||
file:write(Fd, io_lib:format(T ++ F, [Format,Args]))
|
||||
end;
|
||||
write_event(Fd, {Time, {warning_report, _GL, {Pid, std_warning, Rep}}}) ->
|
||||
T = write_time(Time, "WARNING REPORT"),
|
||||
S = format_report(Rep),
|
||||
file:write(Fd, io_lib:format(T ++ S ++ add_node("", Pid), []));
|
||||
write_event(Fd, {Time, {warning_msg, _GL, {Pid, Format, Args}}}) ->
|
||||
T = write_time(Time, "WARNING REPORT"),
|
||||
case catch io_lib:format(add_node(Format,Pid), Args) of
|
||||
S when is_list(S) ->
|
||||
file:write(Fd, io_lib:format(T ++ S, []));
|
||||
_ ->
|
||||
F = add_node("ERROR: ~p - ~p~n", Pid),
|
||||
file:write(Fd, io_lib:format(T ++ F, [Format,Args]))
|
||||
end;
|
||||
write_event(_, _) ->
|
||||
ok.
|
||||
|
||||
|
||||
@@ -31,59 +31,32 @@
|
||||
-module(ejabberd_loglevel).
|
||||
-author('mickael.remond@process-one.net').
|
||||
|
||||
-export([set/1,
|
||||
get/0,
|
||||
set_custom/2,
|
||||
clear_custom/0,
|
||||
clear_custom/1]).
|
||||
-export([set/1, get/0]).
|
||||
|
||||
-include("ejabberd.hrl").
|
||||
|
||||
-define(LOGMODULE, "error_logger").
|
||||
|
||||
%% Error levels:
|
||||
-record(loglevel, {ordinal,
|
||||
name,
|
||||
description,
|
||||
function = no_log,
|
||||
event_type = no_log,
|
||||
msg_prefix = no_log}).
|
||||
-define(LOG_LEVELS,[ {0, no_log, "No log"}
|
||||
,{1, critical, "Critical"}
|
||||
,{2, error, "Error"}
|
||||
,{3, warning, "Warning"}
|
||||
,{4, info, "Info"}
|
||||
,{5, debug, "Debug"}
|
||||
]).
|
||||
|
||||
-define(LOG_LEVELS,
|
||||
[#loglevel{ordinal = 0, name = no_log, description = "No log"},
|
||||
#loglevel{ordinal = 1, name = critical, description = "Critical",
|
||||
function = critical_msg, event_type = error, msg_prefix = "C"},
|
||||
#loglevel{ordinal = 2, name = error, description = "Error",
|
||||
function = error_msg, event_type = error, msg_prefix = "E"},
|
||||
#loglevel{ordinal = 3, name = warning, description = "Warning",
|
||||
function = warning_msg, event_type = warning_msg, msg_prefix = "W"},
|
||||
#loglevel{ordinal = 4, name = info, description = "Info",
|
||||
function = info_msg, event_type = info_msg, msg_prefix = "I"},
|
||||
#loglevel{ordinal = 5, name = debug, description = "Debug",
|
||||
function = debug_msg, event_type = info_msg, msg_prefix = "D"}]).
|
||||
|
||||
%% @type level() = integer() | atom().
|
||||
|
||||
%% @spec () -> {DefaultLevelOrdinal::integer(), [{Module::atom(), LevelOrdinal::integer()}]}
|
||||
%% @doc Get the default and all custom levels
|
||||
get() ->
|
||||
{DefaultLevel, _CustomLevels} = ejabberd_logger:get(),
|
||||
case lists:keysearch(DefaultLevel, #loglevel.ordinal, ?LOG_LEVELS) of
|
||||
{value, Result = #loglevel{}} ->
|
||||
{Result#loglevel.ordinal, Result#loglevel.name, Result#loglevel.description};
|
||||
_ ->
|
||||
erlang:error({no_such_loglevel, DefaultLevel})
|
||||
Level = ejabberd_logger:get(),
|
||||
case lists:keysearch(Level, 1, ?LOG_LEVELS) of
|
||||
{value, Result} -> Result;
|
||||
_ -> erlang:error({no_such_loglevel, Level})
|
||||
end.
|
||||
|
||||
%% @spec (DefaultLevel::level() | {DefaultLevel::level(), [{Module::atom(), Level::level()}]}) ->
|
||||
%% {module, ejabberd_logger}
|
||||
%% @doc Set the default and all custom levels
|
||||
set(DefaultLevel) when is_atom(DefaultLevel) orelse is_integer(DefaultLevel) ->
|
||||
set({DefaultLevel, []});
|
||||
set({DefaultLevel, CustomLevels}) when is_list(CustomLevels) ->
|
||||
DefaultInt = level_to_integer(DefaultLevel),
|
||||
CustomInts = [level_to_integer(C) || C <- CustomLevels],
|
||||
Loglevel = {DefaultInt, CustomInts},
|
||||
|
||||
set(LogLevel) when is_atom(LogLevel) ->
|
||||
set(level_to_integer(LogLevel));
|
||||
set(Loglevel) when is_integer(Loglevel) ->
|
||||
try
|
||||
{Mod,Code} = dynamic_compile:from_string(ejabberd_logger_src(Loglevel)),
|
||||
code:load_binary(Mod, ?LOGMODULE ++ ".erl", Code)
|
||||
@@ -91,45 +64,11 @@ set({DefaultLevel, CustomLevels}) when is_list(CustomLevels) ->
|
||||
Type:Error -> ?CRITICAL_MSG("Error compiling logger (~p): ~p~n", [Type, Error])
|
||||
end;
|
||||
set(_) ->
|
||||
exit("Invalid loglevel format").
|
||||
exit("Loglevel must be an integer").
|
||||
|
||||
%% @spec (Module::atom(), CustomLevel::level()) -> ok
|
||||
%% @doc Set a custom level
|
||||
set_custom(Module, Level) ->
|
||||
{DefaultLevel, CustomLevels} = ejabberd_logger:get(),
|
||||
case lists:keysearch(Module, 1, CustomLevels) of
|
||||
{value, {Module, Level}} ->
|
||||
ok;
|
||||
{value, _} ->
|
||||
set({DefaultLevel, lists:keyreplace(Module, 1, CustomLevels, {Module, Level})});
|
||||
_ ->
|
||||
set({DefaultLevel, [{Module, Level} | CustomLevels]})
|
||||
end.
|
||||
|
||||
%% @spec () -> ok
|
||||
%% @doc Clear all custom levels
|
||||
clear_custom() ->
|
||||
{DefaultLevel, _CustomLevels} = ejabberd_logger:get(),
|
||||
set({DefaultLevel, []}).
|
||||
|
||||
%% @spec (Module::atom()) -> ok
|
||||
%% @doc Clear a custom level
|
||||
clear_custom(Module) ->
|
||||
{DefaultLevel, CustomLevels} = ejabberd_logger:get(),
|
||||
case lists:keysearch(Module, 1, CustomLevels) of
|
||||
{value, _} ->
|
||||
set({DefaultLevel, lists:keydelete(Module, 1, CustomLevels)});
|
||||
_ ->
|
||||
ok
|
||||
end.
|
||||
|
||||
level_to_integer(Level) when is_integer(Level) ->
|
||||
Level;
|
||||
level_to_integer({Module, Level}) ->
|
||||
{Module, level_to_integer(Level)};
|
||||
level_to_integer(Level) ->
|
||||
case lists:keysearch(Level, #loglevel.name, ?LOG_LEVELS) of
|
||||
{value, #loglevel{ordinal = Int}} -> Int;
|
||||
case lists:keysearch(Level, 2, ?LOG_LEVELS) of
|
||||
{value, {Int, Level, _Desc}} -> Int;
|
||||
_ -> erlang:error({no_such_loglevel, Level})
|
||||
end.
|
||||
|
||||
@@ -138,12 +77,7 @@ level_to_integer(Level) ->
|
||||
%% This allows to dynamically change log level while keeping a
|
||||
%% very efficient code.
|
||||
ejabberd_logger_src(Loglevel) ->
|
||||
lists:flatten([header_src(),
|
||||
get_src(Loglevel),
|
||||
[log_src(Loglevel, LevelSpec) || LevelSpec <- ?LOG_LEVELS],
|
||||
notify_src()]).
|
||||
|
||||
header_src() ->
|
||||
L = integer_to_list(Loglevel),
|
||||
"-module(ejabberd_logger).
|
||||
-author('mickael.remond@process-one.net').
|
||||
|
||||
@@ -153,42 +87,42 @@ header_src() ->
|
||||
error_msg/4,
|
||||
critical_msg/4,
|
||||
get/0]).
|
||||
".
|
||||
|
||||
get_src(Loglevel) ->
|
||||
io_lib:format("get() -> ~w.
|
||||
", [Loglevel]).
|
||||
get() -> "++ L ++".
|
||||
|
||||
log_src(_Loglevel, #loglevel{function = no_log}) ->
|
||||
[];
|
||||
log_src({DefaultLevel, [{Module, Level} | Tail]}, Spec = #loglevel{ordinal = MinLevel})
|
||||
when Level < MinLevel andalso MinLevel =< DefaultLevel ->
|
||||
[atom_to_list(Spec#loglevel.function), "(", atom_to_list(Module), ", _, _, _) -> ok;
|
||||
", log_src({DefaultLevel, Tail}, Spec)];
|
||||
log_src({DefaultLevel, [{Module, Level} | Tail]}, Spec = #loglevel{ordinal = MinLevel})
|
||||
when DefaultLevel < MinLevel andalso MinLevel =< Level ->
|
||||
[atom_to_list(Spec#loglevel.function), "(", atom_to_list(Module), " = Module, Line, Format, Args) ->",
|
||||
log_notify_src(Spec), ";
|
||||
", log_src({DefaultLevel, Tail}, Spec)];
|
||||
log_src({DefaultLevel, [_Head | Tail]}, Spec = #loglevel{}) ->
|
||||
log_src({DefaultLevel, Tail}, Spec);
|
||||
log_src({DefaultLevel, []}, Spec = #loglevel{ordinal = MinLevel})
|
||||
when DefaultLevel < MinLevel ->
|
||||
[atom_to_list(Spec#loglevel.function), "(_, _, _, _) -> ok.
|
||||
"];
|
||||
log_src({_DefaultLevel, []}, Spec = #loglevel{}) ->
|
||||
[atom_to_list(Spec#loglevel.function), "(Module, Line, Format, Args) ->",
|
||||
log_notify_src(Spec), ".
|
||||
"].
|
||||
%% Helper functions
|
||||
debug_msg(Module, Line, Format, Args) when " ++ L ++ " >= 5 ->
|
||||
notify(info_msg,
|
||||
\"D(~p:~p:~p) : \"++Format++\"~n\",
|
||||
[self(), Module, Line]++Args);
|
||||
debug_msg(_,_,_,_) -> ok.
|
||||
|
||||
log_notify_src(Spec = #loglevel{}) ->
|
||||
["notify(", atom_to_list(Spec#loglevel.event_type), ",
|
||||
\"", Spec#loglevel.msg_prefix, "(~p:~p:~p) : \"++Format++\"~n\",
|
||||
[self(), Module, Line | Args])"].
|
||||
info_msg(Module, Line, Format, Args) when " ++ L ++ " >= 4 ->
|
||||
notify(info_msg,
|
||||
\"I(~p:~p:~p) : \"++Format++\"~n\",
|
||||
[self(), Module, Line]++Args);
|
||||
info_msg(_,_,_,_) -> ok.
|
||||
|
||||
warning_msg(Module, Line, Format, Args) when " ++ L ++ " >= 3 ->
|
||||
notify(error,
|
||||
\"W(~p:~p:~p) : \"++Format++\"~n\",
|
||||
[self(), Module, Line]++Args);
|
||||
warning_msg(_,_,_,_) -> ok.
|
||||
|
||||
error_msg(Module, Line, Format, Args) when " ++ L ++ " >= 2 ->
|
||||
notify(error,
|
||||
\"E(~p:~p:~p) : \"++Format++\"~n\",
|
||||
[self(), Module, Line]++Args);
|
||||
error_msg(_,_,_,_) -> ok.
|
||||
|
||||
critical_msg(Module, Line, Format, Args) when " ++ L ++ " >= 1 ->
|
||||
notify(error,
|
||||
\"C(~p:~p:~p) : \"++Format++\"~n\",
|
||||
[self(), Module, Line]++Args);
|
||||
critical_msg(_,_,_,_) -> ok.
|
||||
|
||||
notify_src() ->
|
||||
%% Distribute the message to the Erlang error logger
|
||||
"notify(Type, Format, Args) ->
|
||||
notify(Type, Format, Args) ->
|
||||
LoggerMsg = {Type, group_leader(), {self(), Format, Args}},
|
||||
gen_event:notify(error_logger, LoggerMsg).
|
||||
".
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
|
||||
%% API
|
||||
-export([start_link/0,
|
||||
start/0,
|
||||
join/1,
|
||||
leave/1,
|
||||
get_members/1,
|
||||
@@ -40,13 +41,7 @@
|
||||
-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
|
||||
terminate/2, code_change/3]).
|
||||
|
||||
-ifdef(SSL40).
|
||||
-define(PG2, pg2).
|
||||
-else.
|
||||
-define(PG2, pg2_backport).
|
||||
-endif.
|
||||
|
||||
-record(state, {}).
|
||||
-record(state, {groups = []}).
|
||||
|
||||
%%====================================================================
|
||||
%% API
|
||||
@@ -55,25 +50,34 @@
|
||||
%% Function: start_link() -> {ok,Pid} | ignore | {error,Error}
|
||||
%% Description: Starts the server
|
||||
%%--------------------------------------------------------------------
|
||||
start() ->
|
||||
ChildSpec = {?MODULE,
|
||||
{?MODULE, start_link, []},
|
||||
permanent,
|
||||
brutal_kill,
|
||||
worker,
|
||||
[?MODULE]},
|
||||
supervisor:start_child(ejabberd_sup, ChildSpec).
|
||||
|
||||
start_link() ->
|
||||
gen_server:start_link({local, ?MODULE}, ?MODULE, [], []).
|
||||
|
||||
join(Name) ->
|
||||
PG = {?MODULE, Name},
|
||||
?PG2:create(PG),
|
||||
?PG2:join(PG, whereis(?MODULE)).
|
||||
pg2:create(PG),
|
||||
pg2:join(PG, whereis(?MODULE)).
|
||||
|
||||
leave(Name) ->
|
||||
PG = {?MODULE, Name},
|
||||
?PG2:leave(PG, whereis(?MODULE)).
|
||||
pg2:leave(PG, whereis(?MODULE)).
|
||||
|
||||
get_members(Name) ->
|
||||
PG = {?MODULE, Name},
|
||||
[node(P) || P <- ?PG2:get_members(PG)].
|
||||
[node(P) || P <- pg2:get_members(PG)].
|
||||
|
||||
get_closest_node(Name) ->
|
||||
PG = {?MODULE, Name},
|
||||
node(?PG2:get_closest_pid(PG)).
|
||||
node(pg2:get_closest_pid(PG)).
|
||||
|
||||
%%====================================================================
|
||||
%% gen_server callbacks
|
||||
@@ -87,30 +91,19 @@ get_closest_node(Name) ->
|
||||
%% Description: Initiates the server
|
||||
%%--------------------------------------------------------------------
|
||||
init([]) ->
|
||||
{FE, BE} =
|
||||
Groups =
|
||||
case ejabberd_config:get_local_option(node_type) of
|
||||
frontend ->
|
||||
{true, false};
|
||||
[frontend];
|
||||
backend ->
|
||||
{false, true};
|
||||
[backend];
|
||||
generic ->
|
||||
{true, true};
|
||||
[frontend, backend];
|
||||
undefined ->
|
||||
{true, true}
|
||||
[frontend, backend]
|
||||
end,
|
||||
if
|
||||
FE ->
|
||||
join(frontend);
|
||||
true ->
|
||||
ok
|
||||
end,
|
||||
if
|
||||
BE ->
|
||||
join(backend);
|
||||
true ->
|
||||
ok
|
||||
end,
|
||||
{ok, #state{}}.
|
||||
lists:foreach(fun join/1, Groups),
|
||||
{ok, #state{groups = Groups}}.
|
||||
|
||||
%%--------------------------------------------------------------------
|
||||
%% Function: %% handle_call(Request, From, State) -> {reply, Reply, State} |
|
||||
@@ -150,7 +143,8 @@ handle_info(_Info, State) ->
|
||||
%% cleaning up. When it returns, the gen_server terminates with Reason.
|
||||
%% The return value is ignored.
|
||||
%%--------------------------------------------------------------------
|
||||
terminate(_Reason, _State) ->
|
||||
terminate(_Reason, #state{groups = Groups}) ->
|
||||
lists:foreach(fun leave/1, Groups),
|
||||
ok.
|
||||
|
||||
%%--------------------------------------------------------------------
|
||||
|
||||
@@ -25,7 +25,6 @@
|
||||
%%%----------------------------------------------------------------------
|
||||
|
||||
%%% Not implemented:
|
||||
%%% - write mod_piefxis with ejabberdctl commands
|
||||
%%% - Export from mod_offline_odbc.erl
|
||||
%%% - Export from mod_private_odbc.erl
|
||||
%%% - XEP-227: 6. Security Considerations
|
||||
@@ -41,45 +40,11 @@
|
||||
-record(parsing_state, {parser, host, dir}).
|
||||
|
||||
-include("ejabberd.hrl").
|
||||
|
||||
%%-include_lib("exmpp/include/exmpp.hrl").
|
||||
%%-include_lib("exmpp/include/exmpp_client.hrl").
|
||||
%% Copied from exmpp header files:
|
||||
-define(NS_ROSTER, "jabber:iq:roster").
|
||||
-define(NS_VCARD, "vcard-temp").
|
||||
-record(xmlcdata, {
|
||||
cdata = <<>>
|
||||
}).
|
||||
-record(xmlattr, {
|
||||
ns = undefined,
|
||||
name,
|
||||
value
|
||||
}).
|
||||
-record(xmlel, {
|
||||
ns = undefined,
|
||||
declared_ns = [],
|
||||
name,
|
||||
attrs = [],
|
||||
children = []
|
||||
}).
|
||||
-record(iq, {
|
||||
kind,
|
||||
type,
|
||||
id,
|
||||
ns,
|
||||
payload,
|
||||
error,
|
||||
lang,
|
||||
iq_ns
|
||||
}).
|
||||
-record(xmlendtag, {
|
||||
ns = undefined,
|
||||
name
|
||||
}).
|
||||
|
||||
-include_lib("exmpp/include/exmpp.hrl").
|
||||
-include_lib("exmpp/include/exmpp_client.hrl").
|
||||
|
||||
%% Copied from mod_private.erl
|
||||
-record(private_storage, {usns, xml}).
|
||||
-record(private_storage, {user_host_ns, xml}).
|
||||
|
||||
%%-define(ERROR_MSG(M,Args),io:format(M,Args)).
|
||||
%%-define(INFO_MSG(M,Args),ok).
|
||||
@@ -96,7 +61,6 @@
|
||||
%%%% Import file
|
||||
|
||||
import_file(FileName) ->
|
||||
_ = #xmlattr{}, %% this stupid line is only to prevent compilation warning about "recod xmlattr is unused"
|
||||
import_file(FileName, 2).
|
||||
|
||||
import_file(FileName, RootDepth) ->
|
||||
@@ -153,13 +117,13 @@ process_elements(Elements,State) ->
|
||||
process_element(El=#xmlel{name=user, ns=_XMLNS},
|
||||
State=#parsing_state{host=Host}) ->
|
||||
case add_user(El,Host) of
|
||||
ok -> ok;
|
||||
{error, _Other} -> error
|
||||
{error, _Other} -> error;
|
||||
_ -> ok
|
||||
end,
|
||||
State;
|
||||
|
||||
process_element(H=#xmlel{name=host},State) ->
|
||||
State#parsing_state{host=?BTL(exmpp_xml:get_attribute(H,"jid",none))};
|
||||
State#parsing_state{host=exmpp_xml:get_attribute(H,"jid",none)};
|
||||
|
||||
process_element(#xmlel{name='server-data'},State) ->
|
||||
State;
|
||||
@@ -198,47 +162,37 @@ add_user(El, Domain) ->
|
||||
Password = exmpp_xml:get_attribute(El,password,none),
|
||||
add_user(El, Domain, User, Password).
|
||||
|
||||
%% @spec (El::xmlel(), Domain::string(), User::binary(), Password::binary() | none)
|
||||
%% -> ok | {error, ErrorText::string()}
|
||||
%% @spec (El::xmlel(), Domain::string(), User::string(), Password::string())
|
||||
%% -> ok | {atomic, exists} | {error, not_allowed}
|
||||
%% @doc Add a new user to the database.
|
||||
%% If user already exists, it will be only updated.
|
||||
add_user(El, Domain, UserBinary, none) ->
|
||||
User = ?BTL(UserBinary),
|
||||
io:format("Account ~s@~s will not be created, updating it...~n",
|
||||
[User, Domain]),
|
||||
io:format(""),
|
||||
populate_user_with_elements(El, Domain, User),
|
||||
ok;
|
||||
add_user(El, Domain, UserBinary, PasswordBinary) ->
|
||||
User = ?BTL(UserBinary),
|
||||
Password = ?BTL(PasswordBinary),
|
||||
add_user(El, Domain, User, Password) ->
|
||||
case create_user(User,Password,Domain) of
|
||||
ok ->
|
||||
populate_user_with_elements(El, Domain, User),
|
||||
ok = exmpp_xml:foreach(
|
||||
fun(_,Child) ->
|
||||
populate_user(User,Domain,Child)
|
||||
end,
|
||||
El),
|
||||
ok;
|
||||
{atomic, exists} ->
|
||||
io:format("Account ~s@~s already exists, updating it...~n",
|
||||
[User, Domain]),
|
||||
io:format(""),
|
||||
populate_user_with_elements(El, Domain, User),
|
||||
ok;
|
||||
ok = exmpp_xml:foreach(
|
||||
fun(_,Child) ->
|
||||
populate_user(User,Domain,Child)
|
||||
end,
|
||||
El);
|
||||
{error, Other} ->
|
||||
?ERROR_MSG("Error adding user ~s@~s: ~p~n", [User, Domain, Other]),
|
||||
{error, Other}
|
||||
?ERROR_MSG("Error adding user ~s@~s: ~p~n", [User, Domain, Other])
|
||||
end.
|
||||
|
||||
populate_user_with_elements(El, Domain, User) ->
|
||||
exmpp_xml:foreach(
|
||||
fun (_,Child) ->
|
||||
populate_user(User,Domain,Child)
|
||||
end,
|
||||
El).
|
||||
|
||||
%% @spec (User::string(), Password::string(), Domain::string())
|
||||
%% -> ok | {atomic, exists} | {error, not_allowed}
|
||||
%% @doc Create a new user
|
||||
create_user(User,Password,Domain) ->
|
||||
case ejabberd_auth:try_register(User,Domain,Password) of
|
||||
case ejabberd_auth:try_register(?BTL(User),?BTL(Domain),?BTL(Password)) of
|
||||
{atomic,ok} -> ok;
|
||||
{atomic, exists} -> {atomic, exists};
|
||||
{error, not_allowed} -> {error, not_allowed};
|
||||
@@ -273,9 +227,9 @@ create_user(User,Password,Domain) ->
|
||||
|
||||
populate_user(User,Domain,El=#xmlel{name='query', ns='jabber:iq:roster'}) ->
|
||||
io:format("Trying to add/update roster list...",[]),
|
||||
case loaded_module(Domain,[mod_roster_odbc,mod_roster]) of
|
||||
case loaded_module(Domain,[mod_roster]) of
|
||||
{ok, M} ->
|
||||
case M:set_items(User, Domain, exmpp_xml:xmlel_to_xmlelement(El)) of
|
||||
case M:set_items(User, Domain, El) of
|
||||
{atomic, ok} ->
|
||||
io:format(" DONE.~n",[]),
|
||||
ok;
|
||||
@@ -286,7 +240,7 @@ populate_user(User,Domain,El=#xmlel{name='query', ns='jabber:iq:roster'}) ->
|
||||
{error, not_found}
|
||||
end;
|
||||
E -> io:format(" ERROR: ~p~n",[E]),
|
||||
?ERROR_MSG("No modules loaded [mod_roster, mod_roster_odbc] ~s ~n",
|
||||
?ERROR_MSG("Module not loaded: mod_roster ~s ~n",
|
||||
[exmpp_xml:document_to_list(El)]),
|
||||
{error, not_found}
|
||||
end;
|
||||
@@ -314,9 +268,9 @@ populate_user(User,Domain,El=#xmlel{name='query', ns='jabber:iq:roster'}) ->
|
||||
|
||||
populate_user(User,Domain,El=#xmlel{name='vCard', ns='vcard-temp'}) ->
|
||||
io:format("Trying to add/update vCards...",[]),
|
||||
case loaded_module(Domain,[mod_vcard,mod_vcard_odbc]) of
|
||||
{ok, M} -> FullUser = jid_to_old_jid(exmpp_jid:make(User, Domain)),
|
||||
IQ = iq_to_old_iq(#iq{type = set, payload = El}),
|
||||
case loaded_module(Domain,[mod_vcard]) of
|
||||
{ok, M} -> FullUser = exmpp_jid:make(User, Domain),
|
||||
IQ = #iq{kind=request, type = set, payload = El},
|
||||
case M:process_sm_iq(FullUser, FullUser , IQ) of
|
||||
{error,_Err} ->
|
||||
io:format(" ERROR.~n",[]),
|
||||
@@ -327,7 +281,7 @@ populate_user(User,Domain,El=#xmlel{name='vCard', ns='vcard-temp'}) ->
|
||||
end;
|
||||
_ ->
|
||||
io:format(" ERROR.~n",[]),
|
||||
?ERROR_MSG("No modules loaded [mod_vcard, mod_vcard_odbc] ~s ~n",
|
||||
?ERROR_MSG("Module not loaded: mod_vcard ~s ~n",
|
||||
[exmpp_xml:document_to_list(El)]),
|
||||
{error, not_found}
|
||||
end;
|
||||
@@ -340,22 +294,20 @@ populate_user(User,Domain,El=#xmlel{name='vCard', ns='vcard-temp'}) ->
|
||||
|
||||
populate_user(User,Domain,El=#xmlel{name='offline-messages'}) ->
|
||||
io:format("Trying to add/update offline-messages...",[]),
|
||||
case loaded_module(Domain, [mod_offline, mod_offline_odbc]) of
|
||||
case loaded_module(Domain, [mod_offline]) of
|
||||
{ok, M} ->
|
||||
ok = exmpp_xml:foreach(
|
||||
fun (_Element, {xmlcdata, _}) ->
|
||||
ok;
|
||||
(_Element, Child) ->
|
||||
From = exmpp_xml:get_attribute(Child,from,none),
|
||||
FullFrom = jid_to_old_jid(exmpp_jid:parse(From)),
|
||||
FullUser = jid_to_old_jid(exmpp_jid:make(User,
|
||||
Domain)),
|
||||
OldChild = exmpp_xml:xmlel_to_xmlelement(Child),
|
||||
_R = M:store_packet(FullFrom, FullUser, OldChild)
|
||||
FullFrom = exmpp_jid:parse(From),
|
||||
FullUser = exmpp_jid:make(User, Domain),
|
||||
_R = M:store_packet(FullFrom, FullUser, Child)
|
||||
end, El), io:format(" DONE.~n",[]);
|
||||
_ ->
|
||||
io:format(" ERROR.~n",[]),
|
||||
?ERROR_MSG("No modules loaded [mod_offline, mod_offline_odbc] ~s ~n",
|
||||
?ERROR_MSG("Module not loaded: mod_offline ~s ~n",
|
||||
[exmpp_xml:document_to_list(El)]),
|
||||
{error, not_found}
|
||||
end;
|
||||
@@ -368,14 +320,14 @@ populate_user(User,Domain,El=#xmlel{name='offline-messages'}) ->
|
||||
|
||||
populate_user(User,Domain,El=#xmlel{name='query', ns='jabber:iq:private'}) ->
|
||||
io:format("Trying to add/update private storage...",[]),
|
||||
case loaded_module(Domain,[mod_private_odbc,mod_private]) of
|
||||
case loaded_module(Domain,[mod_private]) of
|
||||
{ok, M} ->
|
||||
FullUser = jid_to_old_jid(exmpp_jid:make(User, Domain)),
|
||||
IQ = iq_to_old_iq(#iq{type = set,
|
||||
ns = 'jabber:iq:private',
|
||||
kind = request,
|
||||
iq_ns = 'jabberd:client',
|
||||
payload = El}),
|
||||
FullUser = exmpp_jid:make(User, Domain),
|
||||
IQ = #iq{type = set,
|
||||
ns = 'jabber:iq:private',
|
||||
kind = request,
|
||||
iq_ns = 'jabberd:client',
|
||||
payload = El},
|
||||
case M:process_sm_iq(FullUser, FullUser, IQ ) of
|
||||
{error, _Err} ->
|
||||
io:format(" ERROR.~n",[]),
|
||||
@@ -385,7 +337,7 @@ populate_user(User,Domain,El=#xmlel{name='query', ns='jabber:iq:private'}) ->
|
||||
end;
|
||||
_ ->
|
||||
io:format(" ERROR.~n",[]),
|
||||
?ERROR_MSG("No modules loaded [mod_private, mod_private_odbc] ~s ~n",
|
||||
?ERROR_MSG("Module not loaded: mod_private ~s~n",
|
||||
[exmpp_xml:document_to_list(El)]),
|
||||
{error, not_found}
|
||||
end;
|
||||
@@ -399,6 +351,8 @@ populate_user(_User, _Domain, _El) ->
|
||||
%%%==================================
|
||||
%%%% Utilities
|
||||
|
||||
loaded_module(Domain,Options) when is_binary(Domain) ->
|
||||
loaded_module(?BTL(Domain),Options);
|
||||
loaded_module(Domain,Options) ->
|
||||
LoadedModules = gen_mod:loaded_modules(Domain),
|
||||
case lists:filter(fun(Module) ->
|
||||
@@ -408,23 +362,6 @@ loaded_module(Domain,Options) ->
|
||||
[] -> {error,not_found}
|
||||
end.
|
||||
|
||||
jid_to_old_jid(Jid) ->
|
||||
{jid, to_list(exmpp_jid:node_as_list(Jid)),
|
||||
to_list(exmpp_jid:domain_as_list(Jid)),
|
||||
to_list(exmpp_jid:resource_as_list(Jid)),
|
||||
to_list(exmpp_jid:prep_node_as_list(Jid)),
|
||||
to_list(exmpp_jid:prep_domain_as_list(Jid)),
|
||||
to_list(exmpp_jid:prep_resource_as_list(Jid))}.
|
||||
|
||||
iq_to_old_iq(#iq{id = ID, type = Type, lang = Lang, ns= NS, payload = El }) ->
|
||||
{iq, to_list(ID), Type, to_list(NS), to_list(Lang),
|
||||
exmpp_xml:xmlel_to_xmlelement(El)}.
|
||||
|
||||
to_list(L) when is_list(L) -> L;
|
||||
to_list(B) when is_binary(B) -> binary_to_list(B);
|
||||
to_list(undefined) -> "";
|
||||
to_list(B) when is_atom(B) -> atom_to_list(B).
|
||||
|
||||
%%%==================================
|
||||
|
||||
%%%% Export hosts
|
||||
@@ -528,7 +465,7 @@ make_xinclude(Fn) ->
|
||||
%% @doc Extract user information and print it.
|
||||
export_user(Fd, Username, Host) ->
|
||||
try extract_user(Username, Host) of
|
||||
UserString ->
|
||||
UserString when is_list(UserString) ->
|
||||
print(Fd, UserString)
|
||||
catch
|
||||
E1:E2 ->
|
||||
@@ -545,62 +482,54 @@ extract_user(Username, Host) ->
|
||||
|
||||
%% @spec (InfoName::atom(), Username::string(), Host::string()) -> string()
|
||||
extract_user_info(roster, Username, Host) ->
|
||||
case loaded_module(Host,[mod_roster_odbc,mod_roster]) of
|
||||
case loaded_module(Host,[mod_roster]) of
|
||||
{ok, M} ->
|
||||
From = To = jlib:make_jid(Username, Host, ""),
|
||||
SubelGet = {xmlelement, "query", [{"xmlns",?NS_ROSTER}], []},
|
||||
%%IQGet = #iq{type=get, xmlns=?NS_ROSTER, payload=SubelGet}, % this is for 3.0.0 version
|
||||
IQGet = {iq, "", get, ?NS_ROSTER, "" , SubelGet},
|
||||
From = To = exmpp_jid:make(Username, Host, ""),
|
||||
SubelGet = exmpp_xml:element(?NS_ROSTER, 'query', [], []),
|
||||
IQGet = #iq{kind=request, type=get, ns=?NS_ROSTER, payload=SubelGet},
|
||||
Res = M:process_local_iq(From, To, IQGet),
|
||||
%%[El] = Res#iq.payload, % this is for 3.0.0 version
|
||||
{iq, _, result, _, _, Els} = Res,
|
||||
case Els of
|
||||
[El] -> exmpp_xml:document_to_list(El);
|
||||
[] -> ""
|
||||
case Res#iq.payload of
|
||||
undefined -> "";
|
||||
El -> exmpp_xml:document_to_list(El)
|
||||
end;
|
||||
_E ->
|
||||
""
|
||||
end;
|
||||
|
||||
extract_user_info(offline, Username, Host) ->
|
||||
case loaded_module(Host,[mod_offline,mod_offline_odbc]) of
|
||||
case loaded_module(Host,[mod_offline]) of
|
||||
{ok, mod_offline} ->
|
||||
Els = mnesia_pop_offline_messages([], Username, Host),
|
||||
case Els of
|
||||
[] -> "";
|
||||
Els ->
|
||||
OfEl = {xmlelement, "offline-messages", [], Els},
|
||||
OfEl = #xmlel{name = 'offline-messages',
|
||||
children = Els},
|
||||
%OfEl = {xmlelement, "offline-messages", [], Els},
|
||||
exmpp_xml:document_to_list(OfEl)
|
||||
end;
|
||||
{ok, mod_offline_odbc} ->
|
||||
"";
|
||||
_E ->
|
||||
""
|
||||
end;
|
||||
|
||||
extract_user_info(private, Username, Host) ->
|
||||
case loaded_module(Host,[mod_private,mod_private_odbc]) of
|
||||
case loaded_module(Host,[mod_private]) of
|
||||
{ok, mod_private} ->
|
||||
get_user_private_mnesia(Username, Host);
|
||||
{ok, mod_private_odbc} ->
|
||||
"";
|
||||
_E ->
|
||||
""
|
||||
end;
|
||||
|
||||
extract_user_info(vcard, Username, Host) ->
|
||||
case loaded_module(Host,[mod_vcard, mod_vcard_odbc, mod_vcard_odbc]) of
|
||||
case loaded_module(Host,[mod_vcard]) of
|
||||
{ok, M} ->
|
||||
From = To = jlib:make_jid(Username, Host, ""),
|
||||
SubelGet = {xmlelement, "vCard", [{"xmlns",?NS_VCARD}], []},
|
||||
%%IQGet = #iq{type=get, xmlns=?NS_VCARD, payload=SubelGet}, % this is for 3.0.0 version
|
||||
IQGet = {iq, "", get, ?NS_VCARD, "" , SubelGet},
|
||||
From = To = exmpp_jid:make(Username, Host, ""),
|
||||
SubelGet = exmpp_xml:element(?NS_VCARD, 'vCard', [], []),
|
||||
IQGet = #iq{kind=request, type=get, ns=?NS_VCARD, payload=SubelGet},
|
||||
Res = M:process_sm_iq(From, To, IQGet),
|
||||
%%[El] = Res#iq.payload, % this is for 3.0.0 version
|
||||
{iq, _, result, _, _, Els} = Res,
|
||||
case Els of
|
||||
[El] -> exmpp_xml:document_to_list(El);
|
||||
[] -> ""
|
||||
case Res#iq.payload of
|
||||
undefined -> "";
|
||||
El -> exmpp_xml:document_to_list(El)
|
||||
end;
|
||||
_E ->
|
||||
""
|
||||
@@ -610,53 +539,70 @@ extract_user_info(vcard, Username, Host) ->
|
||||
%%%% Interface with ejabberd offline storage
|
||||
|
||||
%% Copied from mod_offline.erl and customized
|
||||
-record(offline_msg, {us, timestamp, expire, from, to, packet}).
|
||||
-record(offline_msg, {user_host, timestamp, expire, from, to, packet}).
|
||||
mnesia_pop_offline_messages(Ls, User, Server) ->
|
||||
LUser = jlib:nodeprep(User),
|
||||
LServer = jlib:nameprep(Server),
|
||||
US = {LUser, LServer},
|
||||
F = fun() ->
|
||||
Rs = mnesia:wread({offline_msg, US}),
|
||||
%%mnesia:delete({offline_msg, US}),
|
||||
Rs
|
||||
end,
|
||||
case mnesia:transaction(F) of
|
||||
{atomic, Rs} ->
|
||||
TS = now(),
|
||||
Ls ++ lists:map(
|
||||
fun(R) ->
|
||||
{xmlelement, Name, Attrs, Els} = R#offline_msg.packet,
|
||||
FromString = jlib:jid_to_string(R#offline_msg.from),
|
||||
Attrs2 = lists:keystore("from", 1, Attrs, {"from", FromString}),
|
||||
Attrs3 = lists:keystore("xmlns", 1, Attrs2, {"xmlns", "jabber:client"}),
|
||||
{xmlelement, Name, Attrs3,
|
||||
Els ++
|
||||
[jlib:timestamp_to_xml(
|
||||
calendar:now_to_universal_time(
|
||||
R#offline_msg.timestamp))]}
|
||||
end,
|
||||
lists:filter(
|
||||
fun(R) ->
|
||||
case R#offline_msg.expire of
|
||||
never ->
|
||||
true;
|
||||
TimeStamp ->
|
||||
TS < TimeStamp
|
||||
end
|
||||
end,
|
||||
lists:keysort(#offline_msg.timestamp, Rs)));
|
||||
try
|
||||
LUser = User,
|
||||
LServer = Server,
|
||||
US = {LUser, LServer},
|
||||
F = fun() ->
|
||||
Rs = mnesia:wread({offline_msg, US}),
|
||||
%% mnesia:delete({offline_msg, US}),
|
||||
Rs
|
||||
end,
|
||||
case mnesia:transaction(F) of
|
||||
{atomic, Rs} ->
|
||||
TS = make_timestamp(),
|
||||
Ls ++ lists:map(
|
||||
fun(R) ->
|
||||
[Packet] = exmpp_xml:parse_document(R#offline_msg.packet, [names_as_atom]),
|
||||
FromString = exmpp_jid:prep_to_list(R#offline_msg.from),
|
||||
Packet2 = exmpp_xml:set_attribute(Packet, "from", FromString),
|
||||
Packet3 = Packet2#xmlel{ns = ?NS_JABBER_CLIENT},
|
||||
exmpp_xml:append_children(
|
||||
Packet3,
|
||||
[jlib:timestamp_to_xml(
|
||||
calendar:gregorian_seconds_to_datetime(
|
||||
R#offline_msg.timestamp),
|
||||
utc,
|
||||
exmpp_jid:make("", Server, ""),
|
||||
"Offline Storage"),
|
||||
%% TODO: Delete the next three lines once XEP-0091 is Obsolete
|
||||
jlib:timestamp_to_xml(
|
||||
calendar:gregorian_seconds_to_datetime(
|
||||
R#offline_msg.timestamp))]
|
||||
)
|
||||
end,
|
||||
lists:filter(
|
||||
fun(R) ->
|
||||
case R#offline_msg.expire of
|
||||
0 ->
|
||||
true;
|
||||
TimeStamp ->
|
||||
TS < TimeStamp
|
||||
end
|
||||
end,
|
||||
lists:keysort(#offline_msg.timestamp, Rs)));
|
||||
_ ->
|
||||
Ls
|
||||
end
|
||||
catch
|
||||
_ ->
|
||||
Ls
|
||||
end.
|
||||
|
||||
make_timestamp() ->
|
||||
{MegaSecs, Secs, _MicroSecs} = now(),
|
||||
MegaSecs * 1000000 + Secs.
|
||||
|
||||
%%%==================================
|
||||
%%%% Interface with ejabberd private storage
|
||||
|
||||
get_user_private_mnesia(Username, Host) ->
|
||||
ListNsEl = mnesia:dirty_select(private_storage,
|
||||
[{#private_storage{usns={Username, Host, '$1'}, xml = '$2'},
|
||||
[{#private_storage{user_host_ns={?LTB(Username), ?LTB(Host), '$1'}, xml = '$2'},
|
||||
[], ['$$']}]),
|
||||
Els = [exmpp_xml:document_to_list(El) || [_Ns, El] <- ListNsEl],
|
||||
Els = [lists:flatten(exmpp_xml:document_to_list(El)) || [_Ns, El] <- ListNsEl],
|
||||
case lists:flatten(Els) of
|
||||
"" -> "";
|
||||
ElsString ->
|
||||
|
||||
@@ -27,8 +27,15 @@
|
||||
-module(ejabberd_rdbms).
|
||||
-author('alexey@process-one.net').
|
||||
|
||||
-export([start/0]).
|
||||
-export([start/0
|
||||
,start_odbc/1
|
||||
,stop_odbc/1
|
||||
,running/1
|
||||
]).
|
||||
-include("ejabberd.hrl").
|
||||
-include("ejabberd_config.hrl").
|
||||
-include_lib("stdlib/include/ms_transform.hrl").
|
||||
-define(SUPERVISOR, ejabberd_sup).
|
||||
|
||||
start() ->
|
||||
%% Check if ejabberd has been compiled with ODBC
|
||||
@@ -52,27 +59,72 @@ start_hosts() ->
|
||||
|
||||
%% Start the ODBC module on the given host
|
||||
start_odbc(Host) ->
|
||||
Supervisor_name = gen_mod:get_module_proc(Host, ejabberd_odbc_sup),
|
||||
SupervisorName = sup_name(Host),
|
||||
ChildSpec =
|
||||
{Supervisor_name,
|
||||
{SupervisorName,
|
||||
{ejabberd_odbc_sup, start_link, [Host]},
|
||||
transient,
|
||||
infinity,
|
||||
supervisor,
|
||||
[ejabberd_odbc_sup]},
|
||||
case supervisor:start_child(ejabberd_sup, ChildSpec) of
|
||||
case supervisor:start_child(?SUPERVISOR, ChildSpec) of
|
||||
{ok, _PID} ->
|
||||
ok;
|
||||
_Error ->
|
||||
?ERROR_MSG("Start of supervisor ~p failed:~n~p~nRetrying...~n", [Supervisor_name, _Error]),
|
||||
?ERROR_MSG("Start of supervisor ~p failed:~n~p~nRetrying...~n", [SupervisorName, _Error]),
|
||||
start_odbc(Host)
|
||||
end.
|
||||
|
||||
stop_odbc(Host) ->
|
||||
SupervisorName = sup_name(Host),
|
||||
case running(Host) of
|
||||
false -> ok;
|
||||
true ->
|
||||
case [H || H <- dependent_hosts(Host), ejabberd_hosts:running(H)] of
|
||||
[] ->
|
||||
?INFO_MSG("About to terminate ~p", [SupervisorName]),
|
||||
ok = supervisor:terminate_child(?SUPERVISOR, SupervisorName),
|
||||
ok = supervisor:delete_child(?SUPERVISOR, SupervisorName);
|
||||
RunningHosts ->
|
||||
?WARNING_MSG("Not stopping ODBC for ~p because the virtual hosts ~p are still using it.",
|
||||
[Host, RunningHosts]),
|
||||
{error, still_in_use}
|
||||
end
|
||||
end.
|
||||
|
||||
%% Returns true if we have configured odbc_server for the given host
|
||||
needs_odbc(Host) ->
|
||||
LHost = jlib:nameprep(Host),
|
||||
case ejabberd_config:get_local_option({odbc_server, LHost}) of
|
||||
undefined ->
|
||||
false;
|
||||
_ -> true
|
||||
try
|
||||
LHost = exmpp_stringprep:nameprep(Host),
|
||||
case ejabberd_config:get_local_option({odbc_server, LHost}) of
|
||||
undefined ->
|
||||
false;
|
||||
{host, _} ->
|
||||
false;
|
||||
_ ->
|
||||
true
|
||||
end
|
||||
catch
|
||||
_ ->
|
||||
false
|
||||
end.
|
||||
|
||||
running(Host) ->
|
||||
Supervisors = supervisor:which_children(?SUPERVISOR),
|
||||
SupervisorName = gen_mod:get_module_proc(Host, ejabberd_odbc_sup),
|
||||
case lists:keysearch(SupervisorName, 1, Supervisors) of
|
||||
false -> false;
|
||||
{value, Cspec} when is_tuple(Cspec) -> true
|
||||
end.
|
||||
|
||||
|
||||
dependent_hosts(Host) ->
|
||||
MS = ets:fun2ms(fun (#local_config{key={odbc_server, DHost},
|
||||
value={host, H}})
|
||||
when H =:= Host ->
|
||||
DHost
|
||||
end),
|
||||
ejabberd_config:search(MS).
|
||||
|
||||
sup_name(Host) ->
|
||||
gen_mod:get_module_proc(Host, ejabberd_odbc_sup).
|
||||
|
||||
@@ -36,8 +36,12 @@
|
||||
change_shaper/2,
|
||||
reset_stream/1,
|
||||
starttls/2,
|
||||
starttls/3,
|
||||
compress/2,
|
||||
send/2,
|
||||
become_controller/2,
|
||||
change_controller/2,
|
||||
setopts/2,
|
||||
close/1]).
|
||||
|
||||
%% gen_server callbacks
|
||||
@@ -52,6 +56,7 @@
|
||||
c2s_pid,
|
||||
max_stanza_size,
|
||||
xml_stream_state,
|
||||
tref,
|
||||
timeout}).
|
||||
|
||||
-define(HIBERNATE_TIMEOUT, 90000).
|
||||
@@ -86,15 +91,32 @@ change_shaper(Pid, Shaper) ->
|
||||
reset_stream(Pid) ->
|
||||
gen_server:call(Pid, reset_stream).
|
||||
|
||||
starttls(Pid, TLSSocket) ->
|
||||
gen_server:call(Pid, {starttls, TLSSocket}).
|
||||
starttls(Pid, TLSOpts) ->
|
||||
starttls(Pid, TLSOpts, undefined).
|
||||
|
||||
compress(Pid, ZlibSocket) ->
|
||||
gen_server:call(Pid, {compress, ZlibSocket}).
|
||||
starttls(Pid, TLSOpts, Data) ->
|
||||
gen_server:call(Pid, {starttls, TLSOpts, Data}).
|
||||
|
||||
compress(Pid, Data) ->
|
||||
gen_server:call(Pid, {compress, Data}).
|
||||
|
||||
become_controller(Pid, C2SPid) ->
|
||||
gen_server:call(Pid, {become_controller, C2SPid}).
|
||||
|
||||
change_controller(Pid, C2SPid) ->
|
||||
gen_server:call(Pid, {change_controller, C2SPid}).
|
||||
|
||||
setopts(Pid, Opts) ->
|
||||
case lists:member({active, false}, Opts) of
|
||||
true ->
|
||||
gen_server:call(Pid, deactivate_socket);
|
||||
false ->
|
||||
ok
|
||||
end.
|
||||
|
||||
send(Pid, Data) ->
|
||||
gen_server:call(Pid, {send, Data}).
|
||||
|
||||
close(Pid) ->
|
||||
gen_server:cast(Pid, close).
|
||||
|
||||
@@ -132,52 +154,78 @@ init([Socket, SockMod, Shaper, MaxStanzaSize]) ->
|
||||
%% {stop, Reason, State}
|
||||
%% Description: Handling call messages
|
||||
%%--------------------------------------------------------------------
|
||||
handle_call({starttls, TLSSocket}, _From,
|
||||
#state{xml_stream_state = XMLStreamState,
|
||||
c2s_pid = C2SPid,
|
||||
max_stanza_size = MaxStanzaSize} = State) ->
|
||||
close_stream(XMLStreamState),
|
||||
NewXMLStreamState = xml_stream:new(C2SPid, MaxStanzaSize),
|
||||
handle_call({starttls, TLSOpts, Data}, _From, State) ->
|
||||
{ok, TLSSocket} = tls:tcp_to_tls(State#state.socket, TLSOpts),
|
||||
if Data /= undefined ->
|
||||
do_send(State, Data);
|
||||
true ->
|
||||
ok
|
||||
end,
|
||||
NewXMLStreamState = do_reset_stream(State),
|
||||
NewState = State#state{socket = TLSSocket,
|
||||
sock_mod = tls,
|
||||
xml_stream_state = NewXMLStreamState},
|
||||
case tls:recv_data(TLSSocket, "") of
|
||||
{ok, TLSData} ->
|
||||
{reply, ok, process_data(TLSData, NewState), ?HIBERNATE_TIMEOUT};
|
||||
{NextState, Hib} = process_data(TLSData, NewState),
|
||||
{reply, {ok, TLSSocket}, NextState, Hib};
|
||||
{error, _Reason} ->
|
||||
{stop, normal, ok, NewState}
|
||||
end;
|
||||
handle_call({compress, ZlibSocket}, _From,
|
||||
handle_call({compress, Data}, _From,
|
||||
#state{xml_stream_state = XMLStreamState,
|
||||
c2s_pid = C2SPid,
|
||||
max_stanza_size = MaxStanzaSize} = State) ->
|
||||
close_stream(XMLStreamState),
|
||||
NewXMLStreamState = xml_stream:new(C2SPid, MaxStanzaSize),
|
||||
sock_mod = SockMod,
|
||||
socket = Socket} = State) ->
|
||||
{ok, ZlibSocket} = ejabberd_zlib:enable_zlib(SockMod, Socket),
|
||||
if Data /= undefined ->
|
||||
do_send(State, Data);
|
||||
true ->
|
||||
ok
|
||||
end,
|
||||
NewXMLStreamState = exmpp_xmlstream:reset(XMLStreamState),
|
||||
NewState = State#state{socket = ZlibSocket,
|
||||
sock_mod = ejabberd_zlib,
|
||||
xml_stream_state = NewXMLStreamState},
|
||||
case ejabberd_zlib:recv_data(ZlibSocket, "") of
|
||||
{ok, ZlibData} ->
|
||||
{reply, ok, process_data(ZlibData, NewState), ?HIBERNATE_TIMEOUT};
|
||||
{NextState, Hib} = process_data(ZlibData, NewState),
|
||||
{reply, {ok, ZlibSocket}, NextState, Hib};
|
||||
{error, _Reason} ->
|
||||
{stop, normal, ok, NewState}
|
||||
end;
|
||||
handle_call(reset_stream, _From,
|
||||
#state{xml_stream_state = XMLStreamState,
|
||||
c2s_pid = C2SPid,
|
||||
max_stanza_size = MaxStanzaSize} = State) ->
|
||||
close_stream(XMLStreamState),
|
||||
NewXMLStreamState = xml_stream:new(C2SPid, MaxStanzaSize),
|
||||
#state{xml_stream_state = XMLStreamState} = State) ->
|
||||
NewXMLStreamState = exmpp_xmlstream:reset(XMLStreamState),
|
||||
Reply = ok,
|
||||
{reply, Reply, State#state{xml_stream_state = NewXMLStreamState},
|
||||
?HIBERNATE_TIMEOUT};
|
||||
handle_call({become_controller, C2SPid}, _From, State) ->
|
||||
XMLStreamState = xml_stream:new(C2SPid, State#state.max_stanza_size),
|
||||
erlang:monitor(process, C2SPid),
|
||||
close_stream(State#state.xml_stream_state),
|
||||
XMLStreamState = new_xmlstream(C2SPid, State#state.max_stanza_size),
|
||||
NewState = State#state{c2s_pid = C2SPid,
|
||||
xml_stream_state = XMLStreamState},
|
||||
activate_socket(NewState),
|
||||
Reply = ok,
|
||||
{reply, Reply, NewState, ?HIBERNATE_TIMEOUT};
|
||||
handle_call({change_controller, C2SPid}, _From, State) ->
|
||||
erlang:monitor(process, C2SPid),
|
||||
NewXMLStreamState = exmpp_xmlstream:change_callback(
|
||||
State#state.xml_stream_state, {gen_fsm, C2SPid}),
|
||||
NewState = State#state{c2s_pid = C2SPid,
|
||||
xml_stream_state = NewXMLStreamState},
|
||||
activate_socket(NewState),
|
||||
{reply, ok, NewState, ?HIBERNATE_TIMEOUT};
|
||||
handle_call({send, Data}, _From, State) ->
|
||||
case do_send(State, Data) of
|
||||
ok ->
|
||||
{reply, ok, State, ?HIBERNATE_TIMEOUT};
|
||||
{error, _Reason} = Err ->
|
||||
{stop, normal, Err, State}
|
||||
end;
|
||||
handle_call(deactivate_socket, _From, State) ->
|
||||
deactivate_socket(State),
|
||||
{reply, ok, State, ?HIBERNATE_TIMEOUT};
|
||||
handle_call(_Request, _From, State) ->
|
||||
Reply = ok,
|
||||
{reply, Reply, State, ?HIBERNATE_TIMEOUT}.
|
||||
@@ -210,21 +258,22 @@ handle_info({Tag, _TCPSocket, Data},
|
||||
tls ->
|
||||
case tls:recv_data(Socket, Data) of
|
||||
{ok, TLSData} ->
|
||||
{noreply, process_data(TLSData, State),
|
||||
?HIBERNATE_TIMEOUT};
|
||||
{NextState, Hib} = process_data(TLSData, State),
|
||||
{noreply, NextState, Hib};
|
||||
{error, _Reason} ->
|
||||
{stop, normal, State}
|
||||
end;
|
||||
ejabberd_zlib ->
|
||||
case ejabberd_zlib:recv_data(Socket, Data) of
|
||||
{ok, ZlibData} ->
|
||||
{noreply, process_data(ZlibData, State),
|
||||
?HIBERNATE_TIMEOUT};
|
||||
{NextState, Hib} = process_data(ZlibData, State),
|
||||
{noreply, NextState, Hib};
|
||||
{error, _Reason} ->
|
||||
{stop, normal, State}
|
||||
end;
|
||||
_ ->
|
||||
{noreply, process_data(Data, State), ?HIBERNATE_TIMEOUT}
|
||||
{NextState, Hib} = process_data(Data, State),
|
||||
{noreply, NextState, Hib}
|
||||
end;
|
||||
handle_info({Tag, _TCPSocket}, State)
|
||||
when (Tag == tcp_closed) or (Tag == ssl_closed) ->
|
||||
@@ -237,12 +286,15 @@ handle_info({Tag, _TCPSocket, Reason}, State)
|
||||
_ ->
|
||||
{stop, normal, State}
|
||||
end;
|
||||
handle_info({'DOWN', _MRef, process, C2SPid, _},
|
||||
#state{c2s_pid = C2SPid} = State) ->
|
||||
{stop, normal, State};
|
||||
handle_info({timeout, _Ref, activate}, State) ->
|
||||
activate_socket(State),
|
||||
{noreply, State, ?HIBERNATE_TIMEOUT};
|
||||
handle_info(timeout, State) ->
|
||||
proc_lib:hibernate(gen_server, enter_loop, [?MODULE, [], State]),
|
||||
{noreply, State, ?HIBERNATE_TIMEOUT};
|
||||
{noreply, State, hibernate};
|
||||
|
||||
handle_info(_Info, State) ->
|
||||
{noreply, State, ?HIBERNATE_TIMEOUT}.
|
||||
|
||||
@@ -294,14 +346,25 @@ activate_socket(#state{socket = Socket,
|
||||
ok
|
||||
end.
|
||||
|
||||
%% Data processing for connectors directly generating xmlelement in
|
||||
deactivate_socket(#state{socket = Socket,
|
||||
tref = TRef,
|
||||
sock_mod = SockMod}) ->
|
||||
cancel_timer(TRef),
|
||||
case SockMod of
|
||||
gen_tcp ->
|
||||
inet:setopts(Socket, [{active, false}]);
|
||||
_ ->
|
||||
SockMod:setopts(Socket, [{active, false}])
|
||||
end.
|
||||
|
||||
%% Data processing for connectors directly generating xmlel in
|
||||
%% Erlang data structure.
|
||||
%% WARNING: Shaper does not work with Erlang data structure.
|
||||
process_data([], State) ->
|
||||
activate_socket(State),
|
||||
State;
|
||||
process_data([Element|Els], #state{c2s_pid = C2SPid} = State)
|
||||
when element(1, Element) == xmlelement;
|
||||
when element(1, Element) == xmlel;
|
||||
element(1, Element) == xmlstreamstart;
|
||||
element(1, Element) == xmlstreamelement;
|
||||
element(1, Element) == xmlstreamend ->
|
||||
@@ -315,33 +378,76 @@ process_data([Element|Els], #state{c2s_pid = C2SPid} = State)
|
||||
%% Data processing for connectors receivind data as string.
|
||||
process_data(Data,
|
||||
#state{xml_stream_state = XMLStreamState,
|
||||
tref = TRef,
|
||||
shaper_state = ShaperState,
|
||||
c2s_pid = C2SPid} = State) ->
|
||||
?DEBUG("Received XML on stream = ~p", [binary_to_list(Data)]),
|
||||
XMLStreamState1 = xml_stream:parse(XMLStreamState, Data),
|
||||
?DEBUG("Received XML on stream = ~p", [Data]),
|
||||
{ok, XMLStreamState1} = exmpp_xmlstream:parse(XMLStreamState, Data),
|
||||
{NewShaperState, Pause} = shaper:update(ShaperState, size(Data)),
|
||||
if
|
||||
C2SPid == undefined ->
|
||||
ok;
|
||||
Pause > 0 ->
|
||||
erlang:start_timer(Pause, self(), activate);
|
||||
true ->
|
||||
activate_socket(State)
|
||||
end,
|
||||
State#state{xml_stream_state = XMLStreamState1,
|
||||
shaper_state = NewShaperState}.
|
||||
{NewTRef, HibTimeout} =
|
||||
if
|
||||
C2SPid == undefined ->
|
||||
{TRef, infinity};
|
||||
Pause > 0 ->
|
||||
{erlang:start_timer(Pause, self(), activate), hibernate};
|
||||
true ->
|
||||
activate_socket(State),
|
||||
{TRef, ?HIBERNATE_TIMEOUT}
|
||||
end,
|
||||
{State#state{xml_stream_state = XMLStreamState1,
|
||||
tref = NewTRef,
|
||||
shaper_state = NewShaperState}, HibTimeout}.
|
||||
|
||||
%% Element coming from XML parser are wrapped inside xmlstreamelement
|
||||
%% When we receive directly xmlelement tuple (from a socket module
|
||||
%% When we receive directly xmlel tuple (from a socket module
|
||||
%% speaking directly Erlang XML), we wrap it inside the same
|
||||
%% xmlstreamelement coming from the XML parser.
|
||||
element_wrapper(XMLElement)
|
||||
when element(1, XMLElement) == xmlelement ->
|
||||
{xmlstreamelement, XMLElement};
|
||||
element_wrapper(XmlEl)
|
||||
when element(1, XmlEl) == xmlel ->
|
||||
{xmlstreamelement, XmlEl};
|
||||
element_wrapper(Element) ->
|
||||
Element.
|
||||
|
||||
close_stream(undefined) ->
|
||||
ok;
|
||||
close_stream(XMLStreamState) ->
|
||||
xml_stream:close(XMLStreamState).
|
||||
exmpp_xml:stop_parser(exmpp_xmlstream:get_parser(XMLStreamState)),
|
||||
exmpp_xmlstream:stop(XMLStreamState).
|
||||
|
||||
do_send(State, Data) ->
|
||||
(State#state.sock_mod):send(State#state.socket, Data).
|
||||
|
||||
cancel_timer(TRef) when is_reference(TRef) ->
|
||||
case erlang:cancel_timer(TRef) of
|
||||
false ->
|
||||
receive
|
||||
{timeout, TRef, _} ->
|
||||
ok
|
||||
after 0 ->
|
||||
ok
|
||||
end;
|
||||
_ ->
|
||||
ok
|
||||
end;
|
||||
cancel_timer(_) ->
|
||||
ok.
|
||||
|
||||
do_reset_stream(#state{xml_stream_state = undefined, c2s_pid = C2SPid, max_stanza_size = MaxStanzaSize}) ->
|
||||
new_xmlstream(C2SPid, MaxStanzaSize);
|
||||
|
||||
do_reset_stream(#state{xml_stream_state = XMLStreamState}) ->
|
||||
exmpp_xmlstream:reset(XMLStreamState).
|
||||
|
||||
|
||||
new_xmlstream(C2SPid, MaxStanzaSize) ->
|
||||
Parser = exmpp_xml:start_parser([
|
||||
{names_as_atom, true},
|
||||
{check_nss, xmpp},
|
||||
{check_elems, xmpp},
|
||||
{check_attrs, xmpp},
|
||||
{max_size, MaxStanzaSize}
|
||||
]),
|
||||
exmpp_xmlstream:start(
|
||||
{gen_fsm, C2SPid}, Parser,
|
||||
[{xmlstreamstart, new}]
|
||||
).
|
||||
|
||||
@@ -36,9 +36,12 @@
|
||||
register_route/2,
|
||||
register_routes/1,
|
||||
unregister_route/1,
|
||||
force_unregister_route/1,
|
||||
unregister_routes/1,
|
||||
dirty_get_all_routes/0,
|
||||
dirty_get_all_domains/0
|
||||
dirty_get_all_domains/0,
|
||||
read_route/1,
|
||||
make_id/0
|
||||
]).
|
||||
|
||||
-export([start_link/0]).
|
||||
@@ -47,12 +50,16 @@
|
||||
-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
|
||||
terminate/2, code_change/3]).
|
||||
|
||||
-include_lib("exmpp/include/exmpp.hrl").
|
||||
|
||||
-include("ejabberd.hrl").
|
||||
-include("jlib.hrl").
|
||||
|
||||
-record(route, {domain, pid, local_hint}).
|
||||
-record(state, {}).
|
||||
|
||||
%% "rr" stands for Record-Route.
|
||||
-define(ROUTE_PREFIX, "rr-").
|
||||
|
||||
%%====================================================================
|
||||
%% API
|
||||
%%====================================================================
|
||||
@@ -63,9 +70,19 @@
|
||||
start_link() ->
|
||||
gen_server:start_link({local, ?MODULE}, ?MODULE, [], []).
|
||||
|
||||
|
||||
%% #xmlelement{} used for retro-compatibility
|
||||
route(FromOld, ToOld, #xmlelement{} = PacketOld) ->
|
||||
catch throw(for_stacktrace), % To have a stacktrace.
|
||||
io:format("~nROUTER: old #xmlelement:~n~p~n~p~n~n",
|
||||
[PacketOld, erlang:get_stacktrace()]),
|
||||
% XXX OLD FORMAT: From, To, Packet.
|
||||
From = jlib:from_old_jid(FromOld),
|
||||
To = jlib:from_old_jid(ToOld),
|
||||
Packet = exmpp_xml:xmlelement_to_xmlel(PacketOld, [?NS_JABBER_CLIENT],
|
||||
[{?NS_XMPP, ?NS_XMPP_pfx}]),
|
||||
route(From, To, Packet);
|
||||
route(From, To, Packet) ->
|
||||
case catch do_route(From, To, Packet) of
|
||||
case catch route_check_id(From, To, Packet) of
|
||||
{'EXIT', Reason} ->
|
||||
?ERROR_MSG("~p~nwhen processing: ~p",
|
||||
[Reason, {From, To, Packet}]);
|
||||
@@ -76,63 +93,32 @@ route(From, To, Packet) ->
|
||||
%% Route the error packet only if the originating packet is not an error itself.
|
||||
%% RFC3920 9.3.1
|
||||
route_error(From, To, ErrPacket, OrigPacket) ->
|
||||
{xmlelement, _Name, Attrs, _Els} = OrigPacket,
|
||||
case "error" == xml:get_attr_s("type", Attrs) of
|
||||
case exmpp_stanza:is_stanza_error(OrigPacket) of
|
||||
false ->
|
||||
route(From, To, ErrPacket);
|
||||
true ->
|
||||
ok
|
||||
end.
|
||||
|
||||
register_route(Domain) ->
|
||||
register_route({global, Prefix}) ->
|
||||
ejabberd_global_router:register_route(Prefix);
|
||||
register_route(Domain) when is_list(Domain) ->
|
||||
register_route(Domain, undefined).
|
||||
|
||||
register_route(Domain, LocalHint) ->
|
||||
case jlib:nameprep(Domain) of
|
||||
error ->
|
||||
erlang:error({invalid_domain, Domain});
|
||||
LDomain ->
|
||||
Pid = self(),
|
||||
case get_component_number(LDomain) of
|
||||
undefined ->
|
||||
F = fun() ->
|
||||
mnesia:write(#route{domain = LDomain,
|
||||
pid = Pid,
|
||||
local_hint = LocalHint})
|
||||
end,
|
||||
mnesia:transaction(F);
|
||||
N ->
|
||||
F = fun() ->
|
||||
case mnesia:wread({route, LDomain}) of
|
||||
[] ->
|
||||
mnesia:write(
|
||||
#route{domain = LDomain,
|
||||
pid = Pid,
|
||||
local_hint = 1}),
|
||||
lists:foreach(
|
||||
fun(I) ->
|
||||
mnesia:write(
|
||||
#route{domain = LDomain,
|
||||
pid = undefined,
|
||||
local_hint = I})
|
||||
end, lists:seq(2, N));
|
||||
Rs ->
|
||||
lists:any(
|
||||
fun(#route{pid = undefined,
|
||||
local_hint = I} = R) ->
|
||||
mnesia:write(
|
||||
#route{domain = LDomain,
|
||||
pid = Pid,
|
||||
local_hint = I}),
|
||||
mnesia:delete_object(R),
|
||||
true;
|
||||
(_) ->
|
||||
false
|
||||
end, Rs)
|
||||
end
|
||||
end,
|
||||
mnesia:transaction(F)
|
||||
end
|
||||
try
|
||||
LDomain = exmpp_stringprep:nameprep(Domain),
|
||||
LDomainB = list_to_binary(LDomain),
|
||||
Pid = self(),
|
||||
case get_component_number(LDomain) of
|
||||
undefined ->
|
||||
mnesia:transaction(fun register_simple_route/3, [LDomainB, Pid, LocalHint]);
|
||||
N ->
|
||||
mnesia:transaction(fun register_balanced_route/3, [LDomainB, Pid, N])
|
||||
end
|
||||
catch
|
||||
_ ->
|
||||
erlang:error({invalid_domain, Domain})
|
||||
end.
|
||||
|
||||
register_routes(Domains) ->
|
||||
@@ -140,44 +126,102 @@ register_routes(Domains) ->
|
||||
register_route(Domain)
|
||||
end, Domains).
|
||||
|
||||
unregister_route(Domain) ->
|
||||
register_simple_route(LDomain, Pid, LocalHint) ->
|
||||
mnesia:write(#route{domain = LDomain,
|
||||
pid = Pid,
|
||||
local_hint = LocalHint}).
|
||||
|
||||
register_balanced_route(LDomain, Pid, N) ->
|
||||
case mnesia:read({route, LDomain}) of
|
||||
[] ->
|
||||
mnesia:write(
|
||||
#route{domain = LDomain,
|
||||
pid = Pid,
|
||||
local_hint = 1}),
|
||||
lists:foreach(
|
||||
fun(I) ->
|
||||
mnesia:write(
|
||||
#route{domain = LDomain,
|
||||
pid = undefined,
|
||||
local_hint = I})
|
||||
end, lists:seq(2, N));
|
||||
Rs ->
|
||||
lists:any(
|
||||
fun(#route{pid = undefined,
|
||||
local_hint = I} = R) ->
|
||||
mnesia:write(
|
||||
#route{domain = LDomain,
|
||||
pid = Pid,
|
||||
local_hint = I}),
|
||||
mnesia:delete_object(R),
|
||||
true;
|
||||
(_) ->
|
||||
false
|
||||
end, Rs)
|
||||
end.
|
||||
|
||||
unregister_route({global, Prefix}) ->
|
||||
ejabberd_global_router:unregister_route(Prefix);
|
||||
unregister_route(Domain) when is_list(Domain) ->
|
||||
try
|
||||
LDomain = exmpp_stringprep:nameprep(Domain),
|
||||
LDomainB = list_to_binary(LDomain),
|
||||
Pid = self(),
|
||||
case get_component_number(LDomain) of
|
||||
undefined ->
|
||||
mnesia:transaction(fun delete_simple_route/2, [LDomainB, Pid]);
|
||||
_ ->
|
||||
mnesia:transaction(fun delete_balanced_route/2, [LDomainB, Pid])
|
||||
end
|
||||
catch
|
||||
_ ->
|
||||
erlang:error({invalid_domain, Domain})
|
||||
end.
|
||||
|
||||
delete_simple_route(LDomain, Pid) ->
|
||||
case mnesia:match_object(#route{domain = LDomain,
|
||||
pid = Pid,
|
||||
_ = '_'}) of
|
||||
[R] ->
|
||||
mnesia:delete_object(R);
|
||||
_ ->
|
||||
ok
|
||||
end.
|
||||
|
||||
delete_balanced_route(LDomain, Pid) ->
|
||||
case mnesia:match_object(#route{domain=LDomain,
|
||||
pid = Pid,
|
||||
_ = '_'}) of
|
||||
[R] ->
|
||||
I = R#route.local_hint,
|
||||
ok = mnesia:write(
|
||||
#route{domain = LDomain,
|
||||
pid = undefined,
|
||||
local_hint = I}),
|
||||
mnesia:delete_object(R);
|
||||
_ ->
|
||||
ok
|
||||
end.
|
||||
|
||||
|
||||
force_unregister_route(Domain) ->
|
||||
case jlib:nameprep(Domain) of
|
||||
error ->
|
||||
erlang:error({invalid_domain, Domain});
|
||||
LDomain ->
|
||||
Pid = self(),
|
||||
case get_component_number(LDomain) of
|
||||
undefined ->
|
||||
F = fun() ->
|
||||
case mnesia:match_object(
|
||||
#route{domain = LDomain,
|
||||
pid = Pid,
|
||||
_ = '_'}) of
|
||||
[R] ->
|
||||
mnesia:delete_object(R);
|
||||
_ ->
|
||||
ok
|
||||
end
|
||||
end,
|
||||
mnesia:transaction(F);
|
||||
_ ->
|
||||
F = fun() ->
|
||||
case mnesia:match_object(#route{domain=LDomain,
|
||||
pid = Pid,
|
||||
_ = '_'}) of
|
||||
[R] ->
|
||||
I = R#route.local_hint,
|
||||
mnesia:write(
|
||||
#route{domain = LDomain,
|
||||
pid = undefined,
|
||||
local_hint = I}),
|
||||
mnesia:delete_object(R);
|
||||
_ ->
|
||||
ok
|
||||
end
|
||||
end,
|
||||
mnesia:transaction(F)
|
||||
end
|
||||
F = fun() ->
|
||||
case mnesia:match_object(
|
||||
#route{domain = LDomain,
|
||||
_ = '_'}) of
|
||||
Rs when is_list(Rs) ->
|
||||
lists:foreach(fun(R) ->
|
||||
mnesia:delete_object(R)
|
||||
end, Rs);
|
||||
_ ->
|
||||
ok
|
||||
end
|
||||
end,
|
||||
mnesia:transaction(F)
|
||||
end.
|
||||
|
||||
unregister_routes(Domains) ->
|
||||
@@ -185,13 +229,22 @@ unregister_routes(Domains) ->
|
||||
unregister_route(Domain)
|
||||
end, Domains).
|
||||
|
||||
read_route(Domain) ->
|
||||
[{D,P,H}
|
||||
|| #route{domain=D, pid=P, local_hint=H} <- mnesia:dirty_read({route, Domain})].
|
||||
|
||||
dirty_get_all_routes() ->
|
||||
lists:usort(mnesia:dirty_all_keys(route)) -- ?MYHOSTS.
|
||||
lists:usort(
|
||||
lists:map(fun erlang:binary_to_list/1,
|
||||
mnesia:dirty_all_keys(route))) -- ?MYHOSTS.
|
||||
|
||||
dirty_get_all_domains() ->
|
||||
lists:usort(mnesia:dirty_all_keys(route)).
|
||||
lists:usort(
|
||||
lists:map(fun erlang:binary_to_list/1,
|
||||
mnesia:dirty_all_keys(route))).
|
||||
|
||||
make_id() ->
|
||||
?ROUTE_PREFIX ++ randoms:get_string() ++ "-" ++ ejabberd_cluster:node_id().
|
||||
|
||||
%%====================================================================
|
||||
%% gen_server callbacks
|
||||
@@ -248,6 +301,17 @@ handle_cast(_Msg, State) ->
|
||||
%% {stop, Reason, State}
|
||||
%% Description: Handling all non call/cast messages
|
||||
%%--------------------------------------------------------------------
|
||||
%% #xmlelement{} used for retro-compatibility
|
||||
handle_info({route, FromOld, ToOld, #xmlelement{} = PacketOld}, State) ->
|
||||
catch throw(for_stacktrace), % To have a stacktrace.
|
||||
io:format("~nROUTER: old #xmlelement:~n~p~n~p~n~n",
|
||||
[PacketOld, erlang:get_stacktrace()]),
|
||||
% XXX OLD FORMAT: From, To, Packet.
|
||||
From = jlib:from_old_jid(FromOld),
|
||||
To = jlib:from_old_jid(ToOld),
|
||||
Packet = exmpp_xml:xmlelement_to_xmlel(PacketOld, [?NS_JABBER_CLIENT],
|
||||
[{?NS_XMPP, ?NS_XMPP_pfx}]),
|
||||
handle_info({route, From, To, Packet}, State);
|
||||
handle_info({route, From, To, Packet}, State) ->
|
||||
case catch do_route(From, To, Packet) of
|
||||
{'EXIT', Reason} ->
|
||||
@@ -309,16 +373,48 @@ code_change(_OldVsn, State, _Extra) ->
|
||||
%%--------------------------------------------------------------------
|
||||
%%% Internal functions
|
||||
%%--------------------------------------------------------------------
|
||||
route_check_id(From, To, #xmlel{name = iq} = Packet) ->
|
||||
case exmpp_xml:get_attribute_as_list(Packet, 'id', "") of
|
||||
?ROUTE_PREFIX ++ Rest ->
|
||||
Type = exmpp_xml:get_attribute_as_list(Packet, 'type', ""),
|
||||
if Type == "error"; Type == "result" ->
|
||||
case string:tokens(Rest, "-") of
|
||||
[_, NodeID] ->
|
||||
case ejabberd_cluster:get_node_by_id(NodeID) of
|
||||
Node when Node == node() ->
|
||||
do_route(From, To, Packet);
|
||||
Node ->
|
||||
{ejabberd_router, Node} !
|
||||
{route, From, To, Packet}
|
||||
end;
|
||||
_ ->
|
||||
do_route(From, To, Packet)
|
||||
end;
|
||||
true ->
|
||||
do_route(From, To, Packet)
|
||||
end;
|
||||
_ ->
|
||||
do_route(From, To, Packet)
|
||||
end;
|
||||
route_check_id(From, To, Packet) ->
|
||||
do_route(From, To, Packet).
|
||||
|
||||
do_route(OrigFrom, OrigTo, OrigPacket) ->
|
||||
?DEBUG("route~n\tfrom ~p~n\tto ~p~n\tpacket ~p~n",
|
||||
[OrigFrom, OrigTo, OrigPacket]),
|
||||
case ejabberd_hooks:run_fold(filter_packet,
|
||||
{OrigFrom, OrigTo, OrigPacket}, []) of
|
||||
{From, To, Packet} ->
|
||||
LDstDomain = To#jid.lserver,
|
||||
case mnesia:dirty_read(route, LDstDomain) of
|
||||
LDstDomain = exmpp_jid:prep_domain_as_list(To),
|
||||
Destination = ejabberd:normalize_host(LDstDomain),
|
||||
case mnesia:dirty_read(route, list_to_binary(Destination)) of
|
||||
[] ->
|
||||
ejabberd_s2s:route(From, To, Packet);
|
||||
case ejabberd_global_router:find_route(Destination) of
|
||||
no_route ->
|
||||
ejabberd_s2s:route(From, To, Packet);
|
||||
Route ->
|
||||
ejabberd_global_router:route(Route, From, To, Packet)
|
||||
end;
|
||||
[R] ->
|
||||
Pid = R#route.pid,
|
||||
if
|
||||
@@ -339,14 +435,12 @@ do_route(OrigFrom, OrigTo, OrigPacket) ->
|
||||
{domain_balancing, LDstDomain}) of
|
||||
undefined -> now();
|
||||
random -> now();
|
||||
source -> jlib:jid_tolower(From);
|
||||
destination -> jlib:jid_tolower(To);
|
||||
source -> jlib:short_prepd_jid(From);
|
||||
destination -> jlib:short_prepd_jid(To);
|
||||
bare_source ->
|
||||
jlib:jid_remove_resource(
|
||||
jlib:jid_tolower(From));
|
||||
jlib:short_prepd_bare_jid(From);
|
||||
bare_destination ->
|
||||
jlib:jid_remove_resource(
|
||||
jlib:jid_tolower(To))
|
||||
jlib:short_prepd_bare_jid(To)
|
||||
end,
|
||||
case get_component_number(LDstDomain) of
|
||||
undefined ->
|
||||
@@ -413,4 +507,3 @@ update_tables() ->
|
||||
false ->
|
||||
ok
|
||||
end.
|
||||
|
||||
|
||||
@@ -0,0 +1,230 @@
|
||||
%%%----------------------------------------------------------------------
|
||||
%%% File : ejabberd_router_multicast.erl
|
||||
%%% Author : Badlop <badlop@process-one.net>
|
||||
%%% Purpose : Multicast router
|
||||
%%% Created : 11 Aug 2007 by Badlop <badlop@process-one.net>
|
||||
%%%
|
||||
%%%
|
||||
%%% ejabberd, Copyright (C) 2002-2010 ProcessOne
|
||||
%%%
|
||||
%%% This program is free software; you can redistribute it and/or
|
||||
%%% modify it under the terms of the GNU General Public License as
|
||||
%%% published by the Free Software Foundation; either version 2 of the
|
||||
%%% License, or (at your option) any later version.
|
||||
%%%
|
||||
%%% This program is distributed in the hope that it will be useful,
|
||||
%%% but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
%%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
%%% General Public License for more details.
|
||||
%%%
|
||||
%%% You should have received a copy of the GNU General Public License
|
||||
%%% along with this program; if not, write to the Free Software
|
||||
%%% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||
%%% 02111-1307 USA
|
||||
%%%
|
||||
%%%----------------------------------------------------------------------
|
||||
|
||||
-module(ejabberd_router_multicast).
|
||||
-author('badlop@process-one.net').
|
||||
|
||||
-behaviour(gen_server).
|
||||
|
||||
%% API
|
||||
-export([route_multicast/4,
|
||||
register_route/1,
|
||||
unregister_route/1
|
||||
]).
|
||||
|
||||
-export([start_link/0]).
|
||||
|
||||
%% gen_server callbacks
|
||||
-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
|
||||
terminate/2, code_change/3]).
|
||||
|
||||
-include_lib("exmpp/include/exmpp.hrl").
|
||||
|
||||
-include("ejabberd.hrl").
|
||||
|
||||
-record(route_multicast, {domain, pid}).
|
||||
-record(state, {}).
|
||||
|
||||
%%====================================================================
|
||||
%% API
|
||||
%%====================================================================
|
||||
%%--------------------------------------------------------------------
|
||||
%% Function: start_link() -> {ok,Pid} | ignore | {error,Error}
|
||||
%% Description: Starts the server
|
||||
%%--------------------------------------------------------------------
|
||||
start_link() ->
|
||||
gen_server:start_link({local, ?MODULE}, ?MODULE, [], []).
|
||||
|
||||
route_multicast(From, Domain, Destinations, Packet) ->
|
||||
case catch do_route(From, Domain, Destinations, Packet) of
|
||||
{'EXIT', Reason} ->
|
||||
?ERROR_MSG("~p~nwhen processing: ~p",
|
||||
[Reason, {From, Domain, Destinations, Packet}]);
|
||||
_ ->
|
||||
ok
|
||||
end.
|
||||
|
||||
register_route(Domain) ->
|
||||
try
|
||||
LDomain = exmpp_stringprep:nameprep(Domain),
|
||||
Pid = self(),
|
||||
F = fun() ->
|
||||
mnesia:write(#route_multicast{domain = LDomain,
|
||||
pid = Pid})
|
||||
end,
|
||||
mnesia:transaction(F)
|
||||
catch
|
||||
_ ->
|
||||
erlang:error({invalid_domain, Domain})
|
||||
end.
|
||||
|
||||
unregister_route(Domain) ->
|
||||
try
|
||||
LDomain = exmpp_stringprep:nameprep(Domain),
|
||||
LDomainB = list_to_binary(LDomain),
|
||||
Pid = self(),
|
||||
F = fun() ->
|
||||
case mnesia:match_object(
|
||||
#route_multicast{domain = LDomainB,
|
||||
pid = Pid,
|
||||
_ = '_'}) of
|
||||
[R] ->
|
||||
mnesia:delete_object(R);
|
||||
_ ->
|
||||
ok
|
||||
end
|
||||
end,
|
||||
mnesia:transaction(F)
|
||||
catch
|
||||
_ ->
|
||||
erlang:error({invalid_domain, Domain})
|
||||
end.
|
||||
|
||||
%%====================================================================
|
||||
%% gen_server callbacks
|
||||
%%====================================================================
|
||||
|
||||
%%--------------------------------------------------------------------
|
||||
%% Function: init(Args) -> {ok, State} |
|
||||
%% {ok, State, Timeout} |
|
||||
%% ignore |
|
||||
%% {stop, Reason}
|
||||
%% Description: Initiates the server
|
||||
%%--------------------------------------------------------------------
|
||||
init([]) ->
|
||||
mnesia:create_table(route_multicast,
|
||||
[{ram_copies, [node()]},
|
||||
{type, bag},
|
||||
{attributes,
|
||||
record_info(fields, route_multicast)}]),
|
||||
mnesia:add_table_copy(route_multicast, node(), ram_copies),
|
||||
mnesia:subscribe({table, route_multicast, simple}),
|
||||
lists:foreach(
|
||||
fun(Pid) ->
|
||||
erlang:monitor(process, Pid)
|
||||
end,
|
||||
mnesia:dirty_select(route_multicast,
|
||||
[{{route_multicast, '_', '$1'}, [], ['$1']}])),
|
||||
{ok, #state{}}.
|
||||
|
||||
%%--------------------------------------------------------------------
|
||||
%% Function: %% handle_call(Request, From, State) -> {reply, Reply, State} |
|
||||
%% {reply, Reply, State, Timeout} |
|
||||
%% {noreply, State} |
|
||||
%% {noreply, State, Timeout} |
|
||||
%% {stop, Reason, Reply, State} |
|
||||
%% {stop, Reason, State}
|
||||
%% Description: Handling call messages
|
||||
%%--------------------------------------------------------------------
|
||||
handle_call(_Request, _From, State) ->
|
||||
Reply = ok,
|
||||
{reply, Reply, State}.
|
||||
|
||||
%%--------------------------------------------------------------------
|
||||
%% Function: handle_cast(Msg, State) -> {noreply, State} |
|
||||
%% {noreply, State, Timeout} |
|
||||
%% {stop, Reason, State}
|
||||
%% Description: Handling cast messages
|
||||
%%--------------------------------------------------------------------
|
||||
handle_cast(_Msg, State) ->
|
||||
{noreply, State}.
|
||||
|
||||
%%--------------------------------------------------------------------
|
||||
%% Function: handle_info(Info, State) -> {noreply, State} |
|
||||
%% {noreply, State, Timeout} |
|
||||
%% {stop, Reason, State}
|
||||
%% Description: Handling all non call/cast messages
|
||||
%%--------------------------------------------------------------------
|
||||
handle_info({route_multicast, From, Domain, Destinations, Packet}, State) ->
|
||||
case catch do_route(From, Domain, Destinations, Packet) of
|
||||
{'EXIT', Reason} ->
|
||||
?ERROR_MSG("~p~nwhen processing: ~p",
|
||||
[Reason, {From, Domain, Destinations, Packet}]);
|
||||
_ ->
|
||||
ok
|
||||
end,
|
||||
{noreply, State};
|
||||
|
||||
handle_info({mnesia_table_event,
|
||||
{write, #route_multicast{pid = Pid}, _ActivityId}},
|
||||
State) ->
|
||||
erlang:monitor(process, Pid),
|
||||
{noreply, State};
|
||||
handle_info({'DOWN', _Ref, _Type, Pid, _Info}, State) ->
|
||||
F = fun() ->
|
||||
Es = mnesia:select(
|
||||
route_multicast,
|
||||
[{#route_multicast{pid = Pid, _ = '_'}, [], ['$_']}]),
|
||||
lists:foreach(
|
||||
fun(E) ->
|
||||
mnesia:delete_object(E)
|
||||
end, Es)
|
||||
end,
|
||||
mnesia:transaction(F),
|
||||
{noreply, State};
|
||||
handle_info(_Info, State) ->
|
||||
{noreply, State}.
|
||||
|
||||
%%--------------------------------------------------------------------
|
||||
%% Function: terminate(Reason, State) -> void()
|
||||
%% Description: This function is called by a gen_server when it is about to
|
||||
%% terminate. It should be the opposite of Module:init/1 and do any necessary
|
||||
%% cleaning up. When it returns, the gen_server terminates with Reason.
|
||||
%% The return value is ignored.
|
||||
%%--------------------------------------------------------------------
|
||||
terminate(_Reason, _State) ->
|
||||
ok.
|
||||
|
||||
%%--------------------------------------------------------------------
|
||||
%% Func: code_change(OldVsn, State, Extra) -> {ok, NewState}
|
||||
%% Description: Convert process state when code is changed
|
||||
%%--------------------------------------------------------------------
|
||||
code_change(_OldVsn, State, _Extra) ->
|
||||
{ok, State}.
|
||||
|
||||
%%--------------------------------------------------------------------
|
||||
%%% Internal functions
|
||||
%%--------------------------------------------------------------------
|
||||
%% From = #jid
|
||||
%% Destinations = [#jid]
|
||||
do_route(From, Domain, Destinations, Packet) ->
|
||||
?DEBUG("route_multicast~nfrom ~p~ndomain ~p~ndestinations ~p~npacket ~p~n",
|
||||
[From, Domain, Destinations, Packet]),
|
||||
%% Try to find an appropriate multicast service
|
||||
case mnesia:dirty_read(route_multicast, Domain) of
|
||||
%% If no multicast service is available in this server, send manually
|
||||
[] -> do_route_normal(From, Destinations, Packet);
|
||||
%% If available, send the packet using multicast service
|
||||
[R] ->
|
||||
case R#route_multicast.pid of
|
||||
Pid when is_pid(Pid) ->
|
||||
Pid ! {route_trusted, From, Destinations, Packet};
|
||||
_ -> do_route_normal(From, Destinations, Packet)
|
||||
end
|
||||
end.
|
||||
|
||||
do_route_normal(From, Destinations, Packet) ->
|
||||
[ejabberd_router:route(From, To, Packet) || To <- Destinations].
|
||||
@@ -37,11 +37,11 @@
|
||||
get_connections_pids/1,
|
||||
try_register/1,
|
||||
remove_connection/3,
|
||||
find_connection/2,
|
||||
dirty_get_connections/0,
|
||||
allow_host/2,
|
||||
incoming_s2s_number/0,
|
||||
outgoing_s2s_number/0
|
||||
outgoing_s2s_number/0,
|
||||
migrate/1
|
||||
]).
|
||||
|
||||
%% gen_server callbacks
|
||||
@@ -50,13 +50,21 @@
|
||||
%% ejabberd API
|
||||
-export([get_info_s2s_connections/1]).
|
||||
|
||||
-include_lib("exmpp/include/exmpp.hrl").
|
||||
|
||||
-include("ejabberd.hrl").
|
||||
-include("jlib.hrl").
|
||||
-include("ejabberd_commands.hrl").
|
||||
|
||||
-define(DEFAULT_MAX_S2S_CONNECTIONS_NUMBER, 1).
|
||||
-define(DEFAULT_MAX_S2S_CONNECTIONS_NUMBER_PER_NODE, 1).
|
||||
|
||||
% These are the namespace already declared by the stream opening. This is
|
||||
% used at serialization time.
|
||||
-define(DEFAULT_NS, ?NS_JABBER_CLIENT).
|
||||
-define(PREFIXED_NS, [
|
||||
{?NS_XMPP, ?NS_XMPP_pfx}, {?NS_DIALBACK, ?NS_DIALBACK_pfx}
|
||||
]).
|
||||
|
||||
-record(s2s, {fromto, pid, key}).
|
||||
-record(state, {}).
|
||||
|
||||
@@ -70,6 +78,17 @@
|
||||
start_link() ->
|
||||
gen_server:start_link({local, ?MODULE}, ?MODULE, [], []).
|
||||
|
||||
%% #xmlelement{} used for retro-compatibility
|
||||
route(FromOld, ToOld, #xmlelement{} = PacketOld) ->
|
||||
catch throw(for_stacktrace), % To have a stacktrace.
|
||||
io:format("~nS2S: old #xmlelement:~n~p~n~p~n~n",
|
||||
[PacketOld, erlang:get_stacktrace()]),
|
||||
% XXX OLD FORMAT: From, To, Packet.
|
||||
From = jlib:from_old_jid(FromOld),
|
||||
To = jlib:from_old_jid(ToOld),
|
||||
Packet = exmpp_xml:xmlelement_to_xmlel(PacketOld, [?NS_JABBER_CLIENT],
|
||||
[{?NS_XMPP, ?NS_XMPP_pfx}]),
|
||||
route(From, To, Packet);
|
||||
route(From, To, Packet) ->
|
||||
case catch do_route(From, To, Packet) of
|
||||
{'EXIT', Reason} ->
|
||||
@@ -95,30 +114,63 @@ remove_connection(FromTo, Pid, Key) ->
|
||||
end.
|
||||
|
||||
have_connection(FromTo) ->
|
||||
case catch mnesia:dirty_read(s2s, FromTo) of
|
||||
[_] ->
|
||||
true;
|
||||
_ ->
|
||||
false
|
||||
case ejabberd_cluster:get_node(FromTo) of
|
||||
Node when Node == node() ->
|
||||
case mnesia:dirty_read(s2s, FromTo) of
|
||||
[_] ->
|
||||
true;
|
||||
_ ->
|
||||
false
|
||||
end;
|
||||
Node ->
|
||||
case catch rpc:call(Node, mnesia, dirty_read,
|
||||
[s2s, FromTo], 5000) of
|
||||
[_] ->
|
||||
true;
|
||||
_ ->
|
||||
false
|
||||
end
|
||||
end.
|
||||
|
||||
has_key(FromTo, Key) ->
|
||||
case mnesia:dirty_select(s2s,
|
||||
[{#s2s{fromto = FromTo, key = Key, _ = '_'},
|
||||
[],
|
||||
['$_']}]) of
|
||||
[] ->
|
||||
false;
|
||||
_ ->
|
||||
true
|
||||
Query = [{#s2s{fromto = FromTo, key = Key, _ = '_'},
|
||||
[],
|
||||
['$_']}],
|
||||
case ejabberd_cluster:get_node(FromTo) of
|
||||
Node when Node == node() ->
|
||||
case mnesia:dirty_select(s2s, Query) of
|
||||
[] ->
|
||||
false;
|
||||
_ ->
|
||||
true
|
||||
end;
|
||||
Node ->
|
||||
case catch rpc:call(Node, mnesia, dirty_select,
|
||||
[s2s, Query], 5000) of
|
||||
[_|_] ->
|
||||
true;
|
||||
_ ->
|
||||
false
|
||||
end
|
||||
end.
|
||||
|
||||
get_connections_pids(FromTo) ->
|
||||
case catch mnesia:dirty_read(s2s, FromTo) of
|
||||
L when is_list(L) ->
|
||||
[Connection#s2s.pid || Connection <- L];
|
||||
_ ->
|
||||
[]
|
||||
case ejabberd_cluster:get_node(FromTo) of
|
||||
Node when Node == node() ->
|
||||
case catch mnesia:dirty_read(s2s, FromTo) of
|
||||
L when is_list(L) ->
|
||||
[Connection#s2s.pid || Connection <- L];
|
||||
_ ->
|
||||
[]
|
||||
end;
|
||||
Node ->
|
||||
case catch rpc:call(Node, mnesia, dirty_read,
|
||||
[s2s, FromTo], 5000) of
|
||||
L when is_list(L) ->
|
||||
[Connection#s2s.pid || Connection <- L];
|
||||
_ ->
|
||||
[]
|
||||
end
|
||||
end.
|
||||
|
||||
try_register(FromTo) ->
|
||||
@@ -149,7 +201,33 @@ try_register(FromTo) ->
|
||||
end.
|
||||
|
||||
dirty_get_connections() ->
|
||||
mnesia:dirty_all_keys(s2s).
|
||||
lists:flatmap(
|
||||
fun(Node) when Node == node() ->
|
||||
mnesia:dirty_all_keys(s2s);
|
||||
(Node) ->
|
||||
case catch rpc:call(Node, mnesia, dirty_all_keys, [s2s], 5000) of
|
||||
L when is_list(L) ->
|
||||
L;
|
||||
_ ->
|
||||
[]
|
||||
end
|
||||
end, ejabberd_cluster:get_nodes()).
|
||||
|
||||
migrate(After) ->
|
||||
Ss = mnesia:dirty_select(
|
||||
s2s,
|
||||
[{#s2s{fromto = '$1', pid = '$2', _ = '_'},
|
||||
[],
|
||||
['$$']}]),
|
||||
lists:foreach(
|
||||
fun([FromTo, Pid]) ->
|
||||
case ejabberd_cluster:get_node_new(FromTo) of
|
||||
Node when Node /= node() ->
|
||||
ejabberd_s2s_out:stop_connection(Pid, After * 2);
|
||||
_ ->
|
||||
ok
|
||||
end
|
||||
end, Ss).
|
||||
|
||||
%%====================================================================
|
||||
%% gen_server callbacks
|
||||
@@ -164,10 +242,11 @@ dirty_get_connections() ->
|
||||
%%--------------------------------------------------------------------
|
||||
init([]) ->
|
||||
update_tables(),
|
||||
mnesia:create_table(s2s, [{ram_copies, [node()]}, {type, bag},
|
||||
mnesia:create_table(s2s, [{ram_copies, [node()]},
|
||||
{type, bag}, {local_content, true},
|
||||
{attributes, record_info(fields, s2s)}]),
|
||||
mnesia:add_table_copy(s2s, node(), ram_copies),
|
||||
mnesia:subscribe(system),
|
||||
ejabberd_hooks:add(node_hash_update, ?MODULE, migrate, 100),
|
||||
ejabberd_commands:register_commands(commands()),
|
||||
{ok, #state{}}.
|
||||
|
||||
@@ -199,9 +278,17 @@ handle_cast(_Msg, State) ->
|
||||
%% {stop, Reason, State}
|
||||
%% Description: Handling all non call/cast messages
|
||||
%%--------------------------------------------------------------------
|
||||
handle_info({mnesia_system_event, {mnesia_down, Node}}, State) ->
|
||||
clean_table_from_bad_node(Node),
|
||||
{noreply, State};
|
||||
%% #xmlelement{} used for retro-compatibility
|
||||
handle_info({route, FromOld, ToOld, #xmlelement{} = PacketOld}, State) ->
|
||||
catch throw(for_stacktrace), % To have a stacktrace.
|
||||
io:format("~nS2S: old #xmlelement:~n~p~n~p~n~n",
|
||||
[PacketOld, erlang:get_stacktrace()]),
|
||||
% XXX OLD FORMAT: From, To, Packet.
|
||||
From = jlib:from_old_jid(FromOld),
|
||||
To = jlib:from_old_jid(ToOld),
|
||||
Packet = exmpp_xml:xmlelement_to_xmlel(PacketOld, [?NS_JABBER_CLIENT],
|
||||
[{?NS_XMPP, ?NS_XMPP_pfx}]),
|
||||
handle_info({route, From, To, Packet}, State);
|
||||
handle_info({route, From, To, Packet}, State) ->
|
||||
case catch do_route(From, To, Packet) of
|
||||
{'EXIT', Reason} ->
|
||||
@@ -222,6 +309,7 @@ handle_info(_Info, State) ->
|
||||
%% The return value is ignored.
|
||||
%%--------------------------------------------------------------------
|
||||
terminate(_Reason, _State) ->
|
||||
ejabberd_hooks:delete(node_hash_update, ?MODULE, migrate, 100),
|
||||
ejabberd_commands:unregister_commands(commands()),
|
||||
ok.
|
||||
|
||||
@@ -235,51 +323,46 @@ code_change(_OldVsn, State, _Extra) ->
|
||||
%%--------------------------------------------------------------------
|
||||
%%% Internal functions
|
||||
%%--------------------------------------------------------------------
|
||||
clean_table_from_bad_node(Node) ->
|
||||
F = fun() ->
|
||||
Es = mnesia:select(
|
||||
s2s,
|
||||
[{#s2s{pid = '$1', _ = '_'},
|
||||
[{'==', {node, '$1'}, Node}],
|
||||
['$_']}]),
|
||||
lists:foreach(fun(E) ->
|
||||
mnesia:delete_object(E)
|
||||
end, Es)
|
||||
end,
|
||||
mnesia:async_dirty(F).
|
||||
|
||||
do_route(From, To, Packet) ->
|
||||
?DEBUG("s2s manager~n\tfrom ~p~n\tto ~p~n\tpacket ~P~n",
|
||||
[From, To, Packet, 8]),
|
||||
FromTo = {exmpp_jid:prep_domain_as_list(From),
|
||||
exmpp_jid:prep_domain_as_list(To)},
|
||||
case ejabberd_cluster:get_node(FromTo) of
|
||||
Node when Node == node() ->
|
||||
do_route1(From, To, Packet);
|
||||
Node ->
|
||||
{?MODULE, Node} ! {route, From, To, Packet}
|
||||
end.
|
||||
|
||||
do_route1(From, To, Packet) ->
|
||||
case find_connection(From, To) of
|
||||
{atomic, Pid} when is_pid(Pid) ->
|
||||
?DEBUG("sending to process ~p~n", [Pid]),
|
||||
{xmlelement, Name, Attrs, Els} = Packet,
|
||||
NewAttrs = jlib:replace_from_to_attrs(jlib:jid_to_string(From),
|
||||
jlib:jid_to_string(To),
|
||||
Attrs),
|
||||
#jid{lserver = MyServer} = From,
|
||||
NewPacket1 = exmpp_stanza:set_sender(Packet, From),
|
||||
NewPacket = exmpp_stanza:set_recipient(NewPacket1, To),
|
||||
MyServer = exmpp_jid:prep_domain(From),
|
||||
ejabberd_hooks:run(
|
||||
s2s_send_packet,
|
||||
MyServer,
|
||||
[From, To, Packet]),
|
||||
send_element(Pid, {xmlelement, Name, NewAttrs, Els}),
|
||||
[From, To, NewPacket]),
|
||||
send_element(Pid, NewPacket),
|
||||
ok;
|
||||
{aborted, _Reason} ->
|
||||
case xml:get_tag_attr_s("type", Packet) of
|
||||
"error" -> ok;
|
||||
"result" -> ok;
|
||||
case exmpp_stanza:get_type(Packet) of
|
||||
<<"error">> -> ok;
|
||||
<<"result">> -> ok;
|
||||
_ ->
|
||||
Err = jlib:make_error_reply(
|
||||
Packet, ?ERR_SERVICE_UNAVAILABLE),
|
||||
Err = exmpp_stanza:reply_with_error(Packet,
|
||||
'service-unavailable'),
|
||||
ejabberd_router:route(To, From, Err)
|
||||
end,
|
||||
false
|
||||
end.
|
||||
|
||||
find_connection(From, To) ->
|
||||
#jid{lserver = MyServer} = From,
|
||||
#jid{lserver = Server} = To,
|
||||
MyServer = exmpp_jid:prep_domain_as_list(From),
|
||||
Server = exmpp_jid:prep_domain_as_list(To),
|
||||
FromTo = {MyServer, Server},
|
||||
MaxS2SConnectionsNumber = max_s2s_connections_number(FromTo),
|
||||
MaxS2SConnectionsNumberPerNode =
|
||||
@@ -332,7 +415,7 @@ choose_pid(From, Pids) ->
|
||||
% Use sticky connections based on the JID of the sender (whithout
|
||||
% the resource to ensure that a muc room always uses the same
|
||||
% connection)
|
||||
Pid = lists:nth(erlang:phash(jlib:jid_remove_resource(From), length(Pids1)),
|
||||
Pid = lists:nth(erlang:phash(exmpp_jid:bare(From), length(Pids1)),
|
||||
Pids1),
|
||||
?DEBUG("Using ejabberd_s2s_out ~p~n", [Pid]),
|
||||
Pid.
|
||||
@@ -383,14 +466,14 @@ new_connection(MyServer, Server, From, FromTo,
|
||||
|
||||
max_s2s_connections_number({From, To}) ->
|
||||
case acl:match_rule(
|
||||
From, max_s2s_connections, jlib:make_jid("", To, "")) of
|
||||
From, max_s2s_connections, exmpp_jid:make(To)) of
|
||||
Max when is_integer(Max) -> Max;
|
||||
_ -> ?DEFAULT_MAX_S2S_CONNECTIONS_NUMBER
|
||||
end.
|
||||
|
||||
max_s2s_connections_number_per_node({From, To}) ->
|
||||
case acl:match_rule(
|
||||
From, max_s2s_connections_per_node, jlib:make_jid("", To, "")) of
|
||||
From, max_s2s_connections_per_node, exmpp_jid:make(To)) of
|
||||
Max when is_integer(Max) -> Max;
|
||||
_ -> ?DEFAULT_MAX_S2S_CONNECTIONS_NUMBER_PER_NODE
|
||||
end.
|
||||
@@ -407,23 +490,24 @@ needed_connections_number(Ls, MaxS2SConnectionsNumber,
|
||||
%% service.
|
||||
%% --------------------------------------------------------------------
|
||||
is_service(From, To) ->
|
||||
LFromDomain = From#jid.lserver,
|
||||
LFromDomain = exmpp_jid:prep_domain_as_list(From),
|
||||
case ejabberd_config:get_local_option({route_subdomains, LFromDomain}) of
|
||||
s2s -> % bypass RFC 3920 10.3
|
||||
false;
|
||||
_ ->
|
||||
Hosts = ?MYHOSTS,
|
||||
P = fun(ParentDomain) -> lists:member(ParentDomain, Hosts) end,
|
||||
lists:any(P, parent_domains(To#jid.lserver))
|
||||
s2s -> % bypass RFC 3920 10.3
|
||||
false;
|
||||
_ ->
|
||||
LDstDomain = exmpp_jid:prep_domain_as_list(To),
|
||||
P = fun(Domain) -> is_subdomain(LDstDomain, Domain) end,
|
||||
lists:any(P, ?MYHOSTS)
|
||||
end.
|
||||
|
||||
parent_domains(Domain) ->
|
||||
lists:foldl(
|
||||
fun(Label, []) ->
|
||||
[Label];
|
||||
(Label, [Head | Tail]) ->
|
||||
[Label ++ "." ++ Head, Head | Tail]
|
||||
end, [], lists:reverse(string:tokens(Domain, "."))).
|
||||
%%--------------------------------------------------------------------
|
||||
%% Function: is_subdomain(Domain1, Domain2) -> true | false
|
||||
%% Description: Return true if Domain1 (a string representing an
|
||||
%% internet domain name) is a subdomain (or the same domain) of
|
||||
%% Domain2
|
||||
%% --------------------------------------------------------------------
|
||||
is_subdomain(Domain1, Domain2) ->
|
||||
lists:suffix(string:tokens(Domain2, "."), string:tokens(Domain1, ".")).
|
||||
|
||||
send_element(Pid, El) ->
|
||||
Pid ! {send_element, El}.
|
||||
@@ -482,15 +566,20 @@ update_tables() ->
|
||||
mnesia:delete_table(local_s2s);
|
||||
false ->
|
||||
ok
|
||||
end,
|
||||
case catch mnesia:table_info(s2s, local_content) of
|
||||
false ->
|
||||
mnesia:delete_table(s2s);
|
||||
_ ->
|
||||
ok
|
||||
end.
|
||||
|
||||
%% Check if host is in blacklist or white list
|
||||
allow_host(MyServer, S2SHost) ->
|
||||
Hosts = ?MYHOSTS,
|
||||
case lists:dropwhile(
|
||||
fun(ParentDomain) ->
|
||||
not lists:member(ParentDomain, Hosts)
|
||||
end, parent_domains(MyServer)) of
|
||||
case lists:filter(
|
||||
fun(Host) ->
|
||||
is_subdomain(MyServer, Host)
|
||||
end, ?MYHOSTS) of
|
||||
[MyHost|_] ->
|
||||
allow_host1(MyHost, S2SHost);
|
||||
[] ->
|
||||
@@ -505,7 +594,7 @@ allow_host1(MyHost, S2SHost) ->
|
||||
case ejabberd_config:get_local_option({s2s_default_policy, MyHost}) of
|
||||
deny -> false;
|
||||
_ ->
|
||||
case ejabberd_hooks:run_fold(s2s_allow_host, MyHost,
|
||||
case ejabberd_hooks:run_fold(s2s_allow_host, list_to_binary(MyHost),
|
||||
allow, [MyHost, S2SHost]) of
|
||||
deny -> false;
|
||||
allow -> true;
|
||||
|
||||
@@ -46,25 +46,13 @@
|
||||
handle_info/3,
|
||||
terminate/3]).
|
||||
|
||||
-include_lib("exmpp/include/exmpp.hrl").
|
||||
|
||||
-include("ejabberd.hrl").
|
||||
-include("jlib.hrl").
|
||||
-ifdef(SSL40).
|
||||
-include("XmppAddr.hrl").
|
||||
-include_lib("public_key/include/public_key.hrl").
|
||||
-define(PKIXEXPLICIT, 'OTP-PUB-KEY').
|
||||
-define(PKIXIMPLICIT, 'OTP-PUB-KEY').
|
||||
-else.
|
||||
-ifdef(SSL39).
|
||||
-include_lib("ssl/include/ssl_pkix.hrl").
|
||||
-define(PKIXEXPLICIT, 'OTP-PKIX').
|
||||
-define(PKIXIMPLICIT, 'OTP-PKIX').
|
||||
-else.
|
||||
-include_lib("ssl/include/PKIX1Explicit88.hrl").
|
||||
-include_lib("ssl/include/PKIX1Implicit88.hrl").
|
||||
-define(PKIXEXPLICIT, 'PKIX1Explicit88').
|
||||
-define(PKIXIMPLICIT, 'PKIX1Implicit88').
|
||||
-endif.
|
||||
-endif.
|
||||
-include("XmppAddr.hrl").
|
||||
|
||||
-define(DICT, dict).
|
||||
|
||||
@@ -74,10 +62,7 @@
|
||||
shaper,
|
||||
tls = false,
|
||||
tls_enabled = false,
|
||||
tls_required = false,
|
||||
tls_certverify = false,
|
||||
tls_options = [],
|
||||
server,
|
||||
authenticated = false,
|
||||
auth_domain,
|
||||
connections = ?DICT:new(),
|
||||
@@ -101,28 +86,12 @@
|
||||
[SockData, Opts])).
|
||||
-endif.
|
||||
|
||||
-define(STREAM_HEADER(Version),
|
||||
("<?xml version='1.0'?>"
|
||||
"<stream:stream "
|
||||
"xmlns:stream='http://etherx.jabber.org/streams' "
|
||||
"xmlns='jabber:server' "
|
||||
"xmlns:db='jabber:server:dialback' "
|
||||
"id='" ++ StateData#state.streamid ++ "'" ++ Version ++ ">")
|
||||
).
|
||||
|
||||
-define(STREAM_TRAILER, "</stream:stream>").
|
||||
|
||||
-define(INVALID_NAMESPACE_ERR,
|
||||
xml:element_to_string(?SERR_INVALID_NAMESPACE)).
|
||||
|
||||
-define(HOST_UNKNOWN_ERR,
|
||||
xml:element_to_string(?SERR_HOST_UNKNOWN)).
|
||||
|
||||
-define(INVALID_FROM_ERR,
|
||||
xml:element_to_string(?SERR_INVALID_FROM)).
|
||||
|
||||
-define(INVALID_XML_ERR,
|
||||
xml:element_to_string(?SERR_XML_NOT_WELL_FORMED)).
|
||||
% These are the namespace already declared by the stream opening. This is
|
||||
% used at serialization time.
|
||||
-define(DEFAULT_NS, ?NS_JABBER_SERVER).
|
||||
-define(PREFIXED_NS, [
|
||||
{?NS_XMPP, ?NS_XMPP_pfx}, {?NS_DIALBACK, ?NS_DIALBACK_pfx}
|
||||
]).
|
||||
|
||||
%%%----------------------------------------------------------------------
|
||||
%%% API
|
||||
@@ -153,16 +122,12 @@ init([{SockMod, Socket}, Opts]) ->
|
||||
{value, {_, S}} -> S;
|
||||
_ -> none
|
||||
end,
|
||||
{StartTLS, TLSRequired, TLSCertverify} = case ejabberd_config:get_local_option(s2s_use_starttls) of
|
||||
UseTls when (UseTls==undefined) or (UseTls==false) ->
|
||||
{false, false, false};
|
||||
UseTls when (UseTls==true) or (UseTls==optional) ->
|
||||
{true, false, false};
|
||||
required ->
|
||||
{true, true, false};
|
||||
required_trusted ->
|
||||
{true, true, true}
|
||||
end,
|
||||
StartTLS = case ejabberd_config:get_local_option(s2s_use_starttls) of
|
||||
undefined ->
|
||||
false;
|
||||
UseStartTLS ->
|
||||
UseStartTLS
|
||||
end,
|
||||
TLSOpts = case ejabberd_config:get_local_option(s2s_certfile) of
|
||||
undefined ->
|
||||
[];
|
||||
@@ -177,8 +142,6 @@ init([{SockMod, Socket}, Opts]) ->
|
||||
shaper = Shaper,
|
||||
tls = StartTLS,
|
||||
tls_enabled = false,
|
||||
tls_required = TLSRequired,
|
||||
tls_certverify = TLSCertverify,
|
||||
tls_options = TLSOpts,
|
||||
timer = Timer}}.
|
||||
|
||||
@@ -189,31 +152,30 @@ init([{SockMod, Socket}, Opts]) ->
|
||||
%% {stop, Reason, NewStateData}
|
||||
%%----------------------------------------------------------------------
|
||||
|
||||
wait_for_stream({xmlstreamstart, _Name, Attrs}, StateData) ->
|
||||
case {xml:get_attr_s("xmlns", Attrs),
|
||||
xml:get_attr_s("xmlns:db", Attrs),
|
||||
xml:get_attr_s("to", Attrs),
|
||||
xml:get_attr_s("version", Attrs) == "1.0"} of
|
||||
{"jabber:server", _, Server, true} when
|
||||
wait_for_stream({xmlstreamstart, Opening}, StateData) ->
|
||||
case {exmpp_stream:get_default_ns(Opening),
|
||||
exmpp_xml:is_ns_declared_here(Opening, ?NS_DIALBACK),
|
||||
exmpp_stream:get_receiving_entity(Opening),
|
||||
exmpp_stream:get_version(Opening) == {1, 0}} of
|
||||
{?NS_JABBER_SERVER, _, Server, true} when
|
||||
StateData#state.tls and (not StateData#state.authenticated) ->
|
||||
send_text(StateData, ?STREAM_HEADER(" version='1.0'")),
|
||||
Opening_Reply = exmpp_stream:opening_reply(Opening,
|
||||
StateData#state.streamid),
|
||||
send_element(StateData,
|
||||
exmpp_stream:set_dialback_support(Opening_Reply)),
|
||||
SASL =
|
||||
if
|
||||
StateData#state.tls_enabled ->
|
||||
case (StateData#state.sockmod):get_peer_certificate(
|
||||
StateData#state.socket) of
|
||||
{ok, Cert} ->
|
||||
case (StateData#state.sockmod):get_verify_result(StateData#state.socket) of
|
||||
{ok, _Cert} ->
|
||||
case (StateData#state.sockmod):get_verify_result(
|
||||
StateData#state.socket) of
|
||||
0 ->
|
||||
[{xmlelement, "mechanisms",
|
||||
[{"xmlns", ?NS_SASL}],
|
||||
[{xmlelement, "mechanism", [],
|
||||
[{xmlcdata, "EXTERNAL"}]}]}];
|
||||
CertVerifyRes ->
|
||||
case StateData#state.tls_certverify of
|
||||
true -> {error_cert_verif, CertVerifyRes, Cert};
|
||||
false -> []
|
||||
end
|
||||
[exmpp_server_sasl:feature(
|
||||
["EXTERNAL"])];
|
||||
_ ->
|
||||
[]
|
||||
end;
|
||||
error ->
|
||||
[]
|
||||
@@ -224,54 +186,44 @@ wait_for_stream({xmlstreamstart, _Name, Attrs}, StateData) ->
|
||||
StartTLS = if
|
||||
StateData#state.tls_enabled ->
|
||||
[];
|
||||
(not StateData#state.tls_enabled) and (not StateData#state.tls_required) ->
|
||||
[{xmlelement, "starttls", [{"xmlns", ?NS_TLS}], []}];
|
||||
(not StateData#state.tls_enabled) and StateData#state.tls_required ->
|
||||
[{xmlelement, "starttls", [{"xmlns", ?NS_TLS}],
|
||||
[{xmlelement, "required", [], []}]
|
||||
}]
|
||||
true ->
|
||||
[exmpp_server_tls:feature()]
|
||||
end,
|
||||
case SASL of
|
||||
{error_cert_verif, CertVerifyResult, Certificate} ->
|
||||
CertError = tls:get_cert_verify_string(CertVerifyResult, Certificate),
|
||||
RemoteServer = xml:get_attr_s("from", Attrs),
|
||||
?INFO_MSG("Closing s2s connection: ~s <--> ~s (~s)", [StateData#state.server, RemoteServer, CertError]),
|
||||
send_text(StateData, xml:element_to_string(?SERRT_POLICY_VIOLATION("en", CertError))),
|
||||
{atomic, Pid} = ejabberd_s2s:find_connection(jlib:make_jid("", Server, ""), jlib:make_jid("", RemoteServer, "")),
|
||||
ejabberd_s2s_out:stop_connection(Pid),
|
||||
|
||||
{stop, normal, StateData};
|
||||
_ ->
|
||||
send_element(StateData,
|
||||
{xmlelement, "stream:features", [],
|
||||
SASL ++ StartTLS ++
|
||||
ejabberd_hooks:run_fold(
|
||||
s2s_stream_features,
|
||||
Server,
|
||||
[], [Server])}),
|
||||
{next_state, wait_for_feature_request, StateData#state{server = Server}}
|
||||
end;
|
||||
{"jabber:server", _, Server, true} when
|
||||
Features = SASL ++ StartTLS ++ ejabberd_hooks:run_fold(
|
||||
c2s_stream_features,
|
||||
Server,
|
||||
[], [Server]),
|
||||
send_element(StateData, exmpp_stream:features(Features)),
|
||||
{next_state, wait_for_feature_request, StateData};
|
||||
{?NS_JABBER_SERVER, _, Server, true} when
|
||||
StateData#state.authenticated ->
|
||||
send_text(StateData, ?STREAM_HEADER(" version='1.0'")),
|
||||
Opening_Reply = exmpp_stream:opening_reply(Opening,
|
||||
StateData#state.streamid),
|
||||
send_element(StateData,
|
||||
{xmlelement, "stream:features", [],
|
||||
ejabberd_hooks:run_fold(
|
||||
s2s_stream_features,
|
||||
Server,
|
||||
[], [Server])}),
|
||||
exmpp_stream:set_dialback_support(Opening_Reply)),
|
||||
Features = ejabberd_hooks:run_fold(
|
||||
c2s_stream_features,
|
||||
Server,
|
||||
[], [Server]),
|
||||
send_element(StateData, exmpp_stream:features(Features)),
|
||||
{next_state, stream_established, StateData};
|
||||
{"jabber:server", "jabber:server:dialback", _Server, _} ->
|
||||
send_text(StateData, ?STREAM_HEADER("")),
|
||||
{?NS_JABBER_SERVER, true, _Server, _} ->
|
||||
Opening_Reply = exmpp_stream:opening_reply(Opening,
|
||||
StateData#state.streamid),
|
||||
send_element(StateData,
|
||||
exmpp_stream:set_dialback_support(Opening_Reply)),
|
||||
{next_state, stream_established, StateData};
|
||||
_ ->
|
||||
send_text(StateData, ?INVALID_NAMESPACE_ERR),
|
||||
send_element(StateData, exmpp_stream:error('invalid-namespace')),
|
||||
{stop, normal, StateData}
|
||||
end;
|
||||
|
||||
wait_for_stream({xmlstreamerror, _}, StateData) ->
|
||||
send_text(StateData,
|
||||
?STREAM_HEADER("") ++ ?INVALID_XML_ERR ++ ?STREAM_TRAILER),
|
||||
Opening_Reply = exmpp_stream:opening_reply(undefined, ?NS_JABBER_SERVER,
|
||||
"", StateData#state.streamid),
|
||||
send_element(StateData, Opening_Reply),
|
||||
send_element(StateData, exmpp_stream:error('xml-not-well-formed')),
|
||||
send_element(StateData, exmpp_stream:closing()),
|
||||
{stop, normal, StateData};
|
||||
|
||||
wait_for_stream(timeout, StateData) ->
|
||||
@@ -282,78 +234,64 @@ wait_for_stream(closed, StateData) ->
|
||||
|
||||
|
||||
wait_for_feature_request({xmlstreamelement, El}, StateData) ->
|
||||
{xmlelement, Name, Attrs, Els} = El,
|
||||
TLS = StateData#state.tls,
|
||||
TLSEnabled = StateData#state.tls_enabled,
|
||||
SockMod = (StateData#state.sockmod):get_sockmod(StateData#state.socket),
|
||||
case {xml:get_attr_s("xmlns", Attrs), Name} of
|
||||
{?NS_TLS, "starttls"} when TLS == true,
|
||||
case El of
|
||||
#xmlel{ns = ?NS_TLS, name = 'starttls'} when TLS == true,
|
||||
TLSEnabled == false,
|
||||
SockMod == gen_tcp ->
|
||||
?DEBUG("starttls", []),
|
||||
Socket = StateData#state.socket,
|
||||
TLSOpts = case ejabberd_config:get_local_option(
|
||||
{domain_certfile,
|
||||
StateData#state.server}) of
|
||||
undefined ->
|
||||
StateData#state.tls_options;
|
||||
CertFile ->
|
||||
[{certfile, CertFile} |
|
||||
lists:keydelete(
|
||||
certfile, 1,
|
||||
StateData#state.tls_options)]
|
||||
end,
|
||||
Proceed = exmpp_xml:node_to_list(
|
||||
exmpp_server_tls:proceed(), [?DEFAULT_NS], ?PREFIXED_NS),
|
||||
TLSOpts = StateData#state.tls_options,
|
||||
TLSSocket = (StateData#state.sockmod):starttls(
|
||||
Socket, TLSOpts,
|
||||
xml:element_to_binary(
|
||||
{xmlelement, "proceed", [{"xmlns", ?NS_TLS}], []})),
|
||||
Proceed),
|
||||
{next_state, wait_for_stream,
|
||||
StateData#state{socket = TLSSocket,
|
||||
streamid = new_id(),
|
||||
tls_enabled = true,
|
||||
tls_options = TLSOpts
|
||||
tls_enabled = true
|
||||
}};
|
||||
{?NS_SASL, "auth"} when TLSEnabled ->
|
||||
Mech = xml:get_attr_s("mechanism", Attrs),
|
||||
case Mech of
|
||||
"EXTERNAL" ->
|
||||
Auth = jlib:decode_base64(xml:get_cdata(Els)),
|
||||
AuthDomain = jlib:nameprep(Auth),
|
||||
AuthRes =
|
||||
case (StateData#state.sockmod):get_peer_certificate(
|
||||
#xmlel{ns = ?NS_SASL, name = 'auth'} when TLSEnabled ->
|
||||
case exmpp_server_sasl:next_step(El) of
|
||||
{auth, "EXTERNAL", Auth} ->
|
||||
{AuthDomain, AuthRes} = try
|
||||
AuthDomain0 = exmpp_stringprep:nameprep(Auth),
|
||||
AuthRes0 = case (StateData#state.sockmod):get_peer_certificate(
|
||||
StateData#state.socket) of
|
||||
{ok, Cert} ->
|
||||
case (StateData#state.sockmod):get_verify_result(
|
||||
StateData#state.socket) of
|
||||
0 ->
|
||||
case AuthDomain of
|
||||
error ->
|
||||
case idna:domain_utf8_to_ascii(AuthDomain0) of
|
||||
false ->
|
||||
false;
|
||||
_ ->
|
||||
case idna:domain_utf8_to_ascii(AuthDomain) of
|
||||
false ->
|
||||
false;
|
||||
PCAuthDomain ->
|
||||
lists:any(
|
||||
fun(D) ->
|
||||
match_domain(
|
||||
PCAuthDomain, D)
|
||||
end, get_cert_domains(Cert))
|
||||
end
|
||||
PCAuthDomain ->
|
||||
lists:any(
|
||||
fun(D) ->
|
||||
match_domain(
|
||||
PCAuthDomain, D)
|
||||
end, get_cert_domains(Cert))
|
||||
end;
|
||||
_ ->
|
||||
false
|
||||
end;
|
||||
error ->
|
||||
false
|
||||
{undefined, false}
|
||||
end,
|
||||
{AuthDomain0, AuthRes0}
|
||||
catch
|
||||
_ ->
|
||||
false
|
||||
end,
|
||||
if
|
||||
AuthRes ->
|
||||
(StateData#state.sockmod):reset_stream(
|
||||
StateData#state.socket),
|
||||
send_element(StateData,
|
||||
{xmlelement, "success",
|
||||
[{"xmlns", ?NS_SASL}], []}),
|
||||
exmpp_server_sasl:success()),
|
||||
?DEBUG("(~w) Accepted s2s authentication for ~s",
|
||||
[StateData#state.socket, AuthDomain]),
|
||||
{next_state, wait_for_stream,
|
||||
@@ -363,16 +301,14 @@ wait_for_feature_request({xmlstreamelement, El}, StateData) ->
|
||||
}};
|
||||
true ->
|
||||
send_element(StateData,
|
||||
{xmlelement, "failure",
|
||||
[{"xmlns", ?NS_SASL}], []}),
|
||||
send_text(StateData, ?STREAM_TRAILER),
|
||||
exmpp_server_sasl:failure()),
|
||||
send_element(StateData,
|
||||
exmpp_stream:closing()),
|
||||
{stop, normal, StateData}
|
||||
end;
|
||||
_ ->
|
||||
send_element(StateData,
|
||||
{xmlelement, "failure",
|
||||
[{"xmlns", ?NS_SASL}],
|
||||
[{xmlelement, "invalid-mechanism", [], []}]}),
|
||||
exmpp_server_sasl:failure('invalid-mechanism')),
|
||||
{stop, normal, StateData}
|
||||
end;
|
||||
_ ->
|
||||
@@ -380,11 +316,12 @@ wait_for_feature_request({xmlstreamelement, El}, StateData) ->
|
||||
end;
|
||||
|
||||
wait_for_feature_request({xmlstreamend, _Name}, StateData) ->
|
||||
send_text(StateData, ?STREAM_TRAILER),
|
||||
send_element(StateData, exmpp_stream:closing()),
|
||||
{stop, normal, StateData};
|
||||
|
||||
wait_for_feature_request({xmlstreamerror, _}, StateData) ->
|
||||
send_text(StateData, ?INVALID_XML_ERR ++ ?STREAM_TRAILER),
|
||||
send_element(StateData, exmpp_stream:error('xml-not-well-formed')),
|
||||
send_element(StateData, exmpp_stream:closing()),
|
||||
{stop, normal, StateData};
|
||||
|
||||
wait_for_feature_request(closed, StateData) ->
|
||||
@@ -397,62 +334,66 @@ stream_established({xmlstreamelement, El}, StateData) ->
|
||||
case is_key_packet(El) of
|
||||
{key, To, From, Id, Key} ->
|
||||
?DEBUG("GET KEY: ~p", [{To, From, Id, Key}]),
|
||||
LTo = jlib:nameprep(To),
|
||||
LFrom = jlib:nameprep(From),
|
||||
LTo = exmpp_stringprep:nameprep(To),
|
||||
LFrom = exmpp_stringprep:nameprep(From),
|
||||
%% Checks if the from domain is allowed and if the to
|
||||
%% domain is handled by this server:
|
||||
case {ejabberd_s2s:allow_host(LTo, LFrom),
|
||||
case {ejabberd_s2s:allow_host(To, From),
|
||||
lists:member(LTo, ejabberd_router:dirty_get_all_domains())} of
|
||||
{true, true} ->
|
||||
ejabberd_s2s_out:terminate_if_waiting_delay(LTo, LFrom),
|
||||
ejabberd_s2s_out:start(LTo, LFrom,
|
||||
ejabberd_s2s_out:terminate_if_waiting_delay(To, From),
|
||||
ejabberd_s2s_out:start(To, From,
|
||||
{verify, self(),
|
||||
Key, StateData#state.streamid}),
|
||||
Conns = ?DICT:store({LFrom, LTo}, wait_for_verification,
|
||||
StateData#state.connections),
|
||||
change_shaper(StateData, LTo, jlib:make_jid("", LFrom, "")),
|
||||
change_shaper(StateData, LTo,
|
||||
exmpp_jid:make(LFrom)),
|
||||
{next_state,
|
||||
stream_established,
|
||||
StateData#state{connections = Conns,
|
||||
timer = Timer}};
|
||||
{_, false} ->
|
||||
send_text(StateData, ?HOST_UNKNOWN_ERR),
|
||||
send_element(StateData, exmpp_stream:error('host-unknown')),
|
||||
{stop, normal, StateData};
|
||||
{false, _} ->
|
||||
send_text(StateData, ?INVALID_FROM_ERR),
|
||||
send_element(StateData, exmpp_stream:error('invalid-from')),
|
||||
{stop, normal, StateData}
|
||||
end;
|
||||
{verify, To, From, Id, Key} ->
|
||||
?DEBUG("VERIFY KEY: ~p", [{To, From, Id, Key}]),
|
||||
LTo = jlib:nameprep(To),
|
||||
LFrom = jlib:nameprep(From),
|
||||
Type = case ejabberd_s2s:has_key({LTo, LFrom}, Key) of
|
||||
true -> "valid";
|
||||
_ -> "invalid"
|
||||
end,
|
||||
%Type = if Key == Key1 -> "valid";
|
||||
% true -> "invalid"
|
||||
% end,
|
||||
send_element(StateData,
|
||||
{xmlelement,
|
||||
"db:verify",
|
||||
[{"from", To},
|
||||
{"to", From},
|
||||
{"id", Id},
|
||||
{"type", Type}],
|
||||
[]}),
|
||||
LTo = exmpp_stringprep:nameprep(To),
|
||||
LFrom = exmpp_stringprep:nameprep(From),
|
||||
send_element(StateData, exmpp_dialback:verify_response(
|
||||
El, ejabberd_s2s:has_key({LTo, LFrom}, Key))),
|
||||
{next_state, stream_established, StateData#state{timer = Timer}};
|
||||
_ ->
|
||||
NewEl = jlib:remove_attr("xmlns", El),
|
||||
{xmlelement, Name, Attrs, _Els} = NewEl,
|
||||
From_s = xml:get_attr_s("from", Attrs),
|
||||
From = jlib:string_to_jid(From_s),
|
||||
To_s = xml:get_attr_s("to", Attrs),
|
||||
To = jlib:string_to_jid(To_s),
|
||||
From = case exmpp_stanza:get_sender(El) of
|
||||
undefined ->
|
||||
error;
|
||||
F ->
|
||||
try
|
||||
exmpp_jid:parse(F)
|
||||
catch
|
||||
_Exception1 -> error
|
||||
end
|
||||
end,
|
||||
To = case exmpp_stanza:get_recipient(El) of
|
||||
undefined ->
|
||||
error;
|
||||
T ->
|
||||
try
|
||||
exmpp_jid:parse(T)
|
||||
catch
|
||||
_Exception2 -> error
|
||||
end
|
||||
end,
|
||||
% No namespace conversion (:server <-> :client) is done.
|
||||
% This is handled by C2S and S2S send_element functions.
|
||||
if
|
||||
(To /= error) and (From /= error) ->
|
||||
LFrom = From#jid.lserver,
|
||||
LTo = To#jid.lserver,
|
||||
LFrom = exmpp_jid:prep_domain_as_list(From),
|
||||
LTo = exmpp_jid:prep_domain_as_list(To),
|
||||
if
|
||||
StateData#state.authenticated ->
|
||||
case (LFrom == StateData#state.auth_domain)
|
||||
@@ -461,15 +402,16 @@ stream_established({xmlstreamelement, El}, StateData) ->
|
||||
LTo,
|
||||
ejabberd_router:dirty_get_all_domains()) of
|
||||
true ->
|
||||
if ((Name == "iq") or
|
||||
(Name == "message") or
|
||||
(Name == "presence")) ->
|
||||
Name = El#xmlel.name,
|
||||
if ((Name == 'iq') or
|
||||
(Name == 'message') or
|
||||
(Name == 'presence')) ->
|
||||
ejabberd_hooks:run(
|
||||
s2s_receive_packet,
|
||||
LTo,
|
||||
[From, To, NewEl]),
|
||||
exmpp_jid:prep_domain(To),
|
||||
[From, To, El]),
|
||||
ejabberd_router:route(
|
||||
From, To, NewEl);
|
||||
From, To, El);
|
||||
true ->
|
||||
error
|
||||
end;
|
||||
@@ -480,15 +422,16 @@ stream_established({xmlstreamelement, El}, StateData) ->
|
||||
case ?DICT:find({LFrom, LTo},
|
||||
StateData#state.connections) of
|
||||
{ok, established} ->
|
||||
if ((Name == "iq") or
|
||||
(Name == "message") or
|
||||
(Name == "presence")) ->
|
||||
Name = El#xmlel.name,
|
||||
if ((Name == 'iq') or
|
||||
(Name == 'message') or
|
||||
(Name == 'presence')) ->
|
||||
ejabberd_hooks:run(
|
||||
s2s_receive_packet,
|
||||
LTo,
|
||||
[From, To, NewEl]),
|
||||
exmpp_jid:prep_domain(To),
|
||||
[From, To, El]),
|
||||
ejabberd_router:route(
|
||||
From, To, NewEl);
|
||||
From, To, El);
|
||||
true ->
|
||||
error
|
||||
end;
|
||||
@@ -504,30 +447,19 @@ stream_established({xmlstreamelement, El}, StateData) ->
|
||||
end;
|
||||
|
||||
stream_established({valid, From, To}, StateData) ->
|
||||
send_element(StateData,
|
||||
{xmlelement,
|
||||
"db:result",
|
||||
[{"from", To},
|
||||
{"to", From},
|
||||
{"type", "valid"}],
|
||||
[]}),
|
||||
LFrom = jlib:nameprep(From),
|
||||
LTo = jlib:nameprep(To),
|
||||
send_element(StateData, exmpp_dialback:validate(From, To)),
|
||||
LFrom = exmpp_stringprep:nameprep(From),
|
||||
LTo = exmpp_stringprep:nameprep(To),
|
||||
NSD = StateData#state{
|
||||
connections = ?DICT:store({LFrom, LTo}, established,
|
||||
StateData#state.connections)},
|
||||
{next_state, stream_established, NSD};
|
||||
|
||||
stream_established({invalid, From, To}, StateData) ->
|
||||
send_element(StateData,
|
||||
{xmlelement,
|
||||
"db:result",
|
||||
[{"from", To},
|
||||
{"to", From},
|
||||
{"type", "invalid"}],
|
||||
[]}),
|
||||
LFrom = jlib:nameprep(From),
|
||||
LTo = jlib:nameprep(To),
|
||||
Valid = exmpp_dialback:validate(From, To),
|
||||
send_element(StateData, exmpp_stanza:set_type(Valid, "invalid")),
|
||||
LFrom = exmpp_stringprep:nameprep(From),
|
||||
LTo = exmpp_stringprep:nameprep(To),
|
||||
NSD = StateData#state{
|
||||
connections = ?DICT:erase({LFrom, LTo},
|
||||
StateData#state.connections)},
|
||||
@@ -537,8 +469,8 @@ stream_established({xmlstreamend, _Name}, StateData) ->
|
||||
{stop, normal, StateData};
|
||||
|
||||
stream_established({xmlstreamerror, _}, StateData) ->
|
||||
send_text(StateData,
|
||||
?INVALID_XML_ERR ++ ?STREAM_TRAILER),
|
||||
send_element(StateData, exmpp_stream:error('xml-not-well-formed')),
|
||||
send_element(StateData, exmpp_stream:closing()),
|
||||
{stop, normal, StateData};
|
||||
|
||||
stream_established(timeout, StateData) ->
|
||||
@@ -660,8 +592,11 @@ terminate(Reason, _StateName, StateData) ->
|
||||
send_text(StateData, Text) ->
|
||||
(StateData#state.sockmod):send(StateData#state.socket, Text).
|
||||
|
||||
|
||||
send_element(StateData, #xmlel{ns = ?NS_XMPP, name = 'stream'} = El) ->
|
||||
send_text(StateData, exmpp_stream:to_iolist(El));
|
||||
send_element(StateData, El) ->
|
||||
send_text(StateData, xml:element_to_binary(El)).
|
||||
send_text(StateData, exmpp_stanza:to_iolist(El)).
|
||||
|
||||
|
||||
change_shaper(StateData, Host, JID) ->
|
||||
@@ -682,18 +617,20 @@ cancel_timer(Timer) ->
|
||||
end.
|
||||
|
||||
|
||||
is_key_packet({xmlelement, Name, Attrs, Els}) when Name == "db:result" ->
|
||||
is_key_packet(#xmlel{ns = ?NS_DIALBACK, name = 'result',
|
||||
attrs = Attrs} = El) ->
|
||||
{key,
|
||||
xml:get_attr_s("to", Attrs),
|
||||
xml:get_attr_s("from", Attrs),
|
||||
xml:get_attr_s("id", Attrs),
|
||||
xml:get_cdata(Els)};
|
||||
is_key_packet({xmlelement, Name, Attrs, Els}) when Name == "db:verify" ->
|
||||
binary_to_list(exmpp_stanza:get_recipient_from_attrs(Attrs)),
|
||||
binary_to_list(exmpp_stanza:get_sender_from_attrs(Attrs)),
|
||||
exmpp_stanza:get_id_from_attrs(Attrs),
|
||||
exmpp_xml:get_cdata_as_list(El)};
|
||||
is_key_packet(#xmlel{ns = ?NS_DIALBACK, name = 'verify',
|
||||
attrs = Attrs} = El) ->
|
||||
{verify,
|
||||
xml:get_attr_s("to", Attrs),
|
||||
xml:get_attr_s("from", Attrs),
|
||||
xml:get_attr_s("id", Attrs),
|
||||
xml:get_cdata(Els)};
|
||||
binary_to_list(exmpp_stanza:get_recipient_from_attrs(Attrs)),
|
||||
binary_to_list(exmpp_stanza:get_sender_from_attrs(Attrs)),
|
||||
exmpp_stanza:get_id_from_attrs(Attrs),
|
||||
exmpp_xml:get_cdata_as_list(El)};
|
||||
is_key_packet(_) ->
|
||||
false.
|
||||
|
||||
@@ -715,10 +652,11 @@ get_cert_domains(Cert) ->
|
||||
end,
|
||||
if
|
||||
D /= error ->
|
||||
case jlib:string_to_jid(D) of
|
||||
#jid{luser = "",
|
||||
lserver = LD,
|
||||
lresource = ""} ->
|
||||
JID = exmpp_jid:parse(D),
|
||||
case {exmpp_jid:prep_node_as_list(JID),
|
||||
exmpp_jid:prep_domain_as_list(JID),
|
||||
exmpp_jid:prep_resource_as_list(JID)} of
|
||||
{undefined, LD, undefined} ->
|
||||
[LD];
|
||||
_ ->
|
||||
[]
|
||||
@@ -750,11 +688,11 @@ get_cert_domains(Cert) ->
|
||||
case 'XmppAddr':decode(
|
||||
'XmppAddr', XmppAddr) of
|
||||
{ok, D} when is_binary(D) ->
|
||||
case jlib:string_to_jid(
|
||||
binary_to_list(D)) of
|
||||
#jid{luser = "",
|
||||
lserver = LD,
|
||||
lresource = ""} ->
|
||||
JID2 = exmpp_jid:parse(binary_to_list(D)),
|
||||
case {exmpp_jid:prep_node_as_list(JID2),
|
||||
exmpp_jid:prep_domain_as_list(JID2),
|
||||
exmpp_jid:prep_resource_as_list(JID2)} of
|
||||
{ undefined, LD, undefined} ->
|
||||
case idna:domain_utf8_to_ascii(LD) of
|
||||
false ->
|
||||
[];
|
||||
@@ -768,10 +706,11 @@ get_cert_domains(Cert) ->
|
||||
[]
|
||||
end;
|
||||
({dNSName, D}) when is_list(D) ->
|
||||
case jlib:string_to_jid(D) of
|
||||
#jid{luser = "",
|
||||
lserver = LD,
|
||||
lresource = ""} ->
|
||||
JID3 = exmpp_jid:parse(D),
|
||||
case {exmpp_jid:prep_node_as_list(JID3),
|
||||
exmpp_jid:prep_domain_as_list(JID3),
|
||||
exmpp_jid:prep_resource_as_list(JID3)} of
|
||||
{undefined, LD, undefined} ->
|
||||
[LD];
|
||||
_ ->
|
||||
[]
|
||||
@@ -805,11 +744,11 @@ match_labels([DL | DLabels], [PL | PLabels]) ->
|
||||
orelse (C == $-) orelse (C == $*)
|
||||
end, PL) of
|
||||
true ->
|
||||
Regexp = regexp:sh_to_awk(PL),
|
||||
case regexp:match(DL, Regexp) of
|
||||
{match, _, _} ->
|
||||
Regexp = xmerl_regexp:sh_to_awk(PL),
|
||||
case re:run(DL, Regexp, [{capture, none}]) of
|
||||
match ->
|
||||
match_labels(DLabels, PLabels);
|
||||
_ ->
|
||||
nomatch ->
|
||||
false
|
||||
end;
|
||||
false ->
|
||||
|
||||
@@ -34,7 +34,8 @@
|
||||
start_link/3,
|
||||
start_connection/1,
|
||||
terminate_if_waiting_delay/2,
|
||||
stop_connection/1]).
|
||||
stop_connection/1,
|
||||
stop_connection/2]).
|
||||
|
||||
%% p1_fsm callbacks (same as gen_fsm)
|
||||
-export([init/1,
|
||||
@@ -44,7 +45,6 @@
|
||||
wait_for_features/2,
|
||||
wait_for_auth_result/2,
|
||||
wait_for_starttls_proceed/2,
|
||||
relay_to_bridge/2,
|
||||
reopen_socket/2,
|
||||
wait_before_retry/2,
|
||||
stream_established/2,
|
||||
@@ -52,13 +52,14 @@
|
||||
handle_sync_event/4,
|
||||
handle_info/3,
|
||||
terminate/3,
|
||||
print_state/1,
|
||||
code_change/4,
|
||||
print_state/1,
|
||||
test_get_addr_port/1,
|
||||
get_addr_port/1]).
|
||||
|
||||
-include_lib("exmpp/include/exmpp.hrl").
|
||||
|
||||
-include("ejabberd.hrl").
|
||||
-include("jlib.hrl").
|
||||
|
||||
-record(state, {socket,
|
||||
streamid,
|
||||
@@ -66,17 +67,16 @@
|
||||
tls = false,
|
||||
tls_required = false,
|
||||
tls_enabled = false,
|
||||
tls_options = [connect],
|
||||
tls_options = [],
|
||||
authenticated = false,
|
||||
db_enabled = true,
|
||||
try_auth = true,
|
||||
myname, server, queue,
|
||||
delay_to_retry = undefined_delay,
|
||||
new = false, verify = false,
|
||||
bridge,
|
||||
timer}).
|
||||
|
||||
%%-define(DBGFSM, true).
|
||||
%-define(DBGFSM, true).
|
||||
|
||||
-ifdef(DBGFSM).
|
||||
-define(FSMOPTS, [{debug, [trace]}]).
|
||||
@@ -86,10 +86,11 @@
|
||||
|
||||
%% Module start with or without supervisor:
|
||||
-ifdef(NO_TRANSIENT_SUPERVISORS).
|
||||
-define(SUPERVISOR_START, p1_fsm:start(ejabberd_s2s_out, [From, Host, Type],
|
||||
fsm_limit_opts() ++ ?FSMOPTS)).
|
||||
-define(SUPERVISOR_START, rpc:call(Node, p1_fsm, start,
|
||||
[ejabberd_s2s_out, [From, Host, Type],
|
||||
fsm_limit_opts() ++ ?FSMOPTS])).
|
||||
-else.
|
||||
-define(SUPERVISOR_START, supervisor:start_child(ejabberd_s2s_out_sup,
|
||||
-define(SUPERVISOR_START, supervisor:start_child({ejabberd_s2s_out_sup, Node},
|
||||
[From, Host, Type])).
|
||||
-endif.
|
||||
|
||||
@@ -102,26 +103,13 @@
|
||||
%% Specified in miliseconds. Default value is 5 minutes.
|
||||
-define(MAX_RETRY_DELAY, 300000).
|
||||
|
||||
-define(STREAM_HEADER,
|
||||
"<?xml version='1.0'?>"
|
||||
"<stream:stream "
|
||||
"xmlns:stream='http://etherx.jabber.org/streams' "
|
||||
"xmlns='jabber:server' "
|
||||
"xmlns:db='jabber:server:dialback' "
|
||||
"from='~s' "
|
||||
"to='~s'~s>"
|
||||
).
|
||||
% These are the namespace already declared by the stream opening. This is
|
||||
% used at serialization time.
|
||||
-define(DEFAULT_NS, ?NS_JABBER_SERVER).
|
||||
-define(PREFIXED_NS, [
|
||||
{?NS_XMPP, ?NS_XMPP_pfx}, {?NS_DIALBACK, ?NS_DIALBACK_pfx}
|
||||
]).
|
||||
|
||||
-define(STREAM_TRAILER, "</stream:stream>").
|
||||
|
||||
-define(INVALID_NAMESPACE_ERR,
|
||||
xml:element_to_string(?SERR_INVALID_NAMESPACE)).
|
||||
|
||||
-define(HOST_UNKNOWN_ERR,
|
||||
xml:element_to_string(?SERR_HOST_UNKNOWN)).
|
||||
|
||||
-define(INVALID_XML_ERR,
|
||||
xml:element_to_string(?SERR_XML_NOT_WELL_FORMED)).
|
||||
|
||||
-define(SOCKET_DEFAULT_RESULT, {error, badarg}).
|
||||
|
||||
@@ -129,6 +117,7 @@
|
||||
%%% API
|
||||
%%%----------------------------------------------------------------------
|
||||
start(From, Host, Type) ->
|
||||
Node = ejabberd_cluster:get_node({From, Host}),
|
||||
?SUPERVISOR_START.
|
||||
|
||||
start_link(From, Host, Type) ->
|
||||
@@ -141,6 +130,9 @@ start_connection(Pid) ->
|
||||
stop_connection(Pid) ->
|
||||
p1_fsm:send_event(Pid, closed).
|
||||
|
||||
stop_connection(Pid, Timeout) ->
|
||||
p1_fsm:send_all_state_event(Pid, {closed, Timeout}).
|
||||
|
||||
%%%----------------------------------------------------------------------
|
||||
%%% Callback functions from p1_fsm
|
||||
%%%----------------------------------------------------------------------
|
||||
@@ -155,18 +147,16 @@ stop_connection(Pid) ->
|
||||
init([From, Server, Type]) ->
|
||||
process_flag(trap_exit, true),
|
||||
?DEBUG("started: ~p", [{From, Server, Type}]),
|
||||
{TLS, TLSRequired} = case ejabberd_config:get_local_option(s2s_use_starttls) of
|
||||
UseTls when (UseTls==undefined) or (UseTls==false) ->
|
||||
{false, false};
|
||||
UseTls when (UseTls==true) or (UseTls==optional) ->
|
||||
{true, false};
|
||||
UseTls when (UseTls==required) or (UseTls==required_trusted) ->
|
||||
{true, true}
|
||||
TLS = case ejabberd_config:get_local_option(s2s_use_starttls) of
|
||||
undefined ->
|
||||
false;
|
||||
UseStartTLS ->
|
||||
UseStartTLS
|
||||
end,
|
||||
UseV10 = TLS,
|
||||
TLSOpts = case ejabberd_config:get_local_option(s2s_certfile) of
|
||||
undefined ->
|
||||
[connect];
|
||||
[];
|
||||
CertFile ->
|
||||
[{certfile, CertFile}, connect]
|
||||
end,
|
||||
@@ -180,7 +170,6 @@ init([From, Server, Type]) ->
|
||||
Timer = erlang:start_timer(?S2STIMEOUT, self(), []),
|
||||
{ok, open_socket, #state{use_v10 = UseV10,
|
||||
tls = TLS,
|
||||
tls_required = TLSRequired,
|
||||
tls_options = TLSOpts,
|
||||
queue = queue:new(),
|
||||
myname = From,
|
||||
@@ -220,33 +209,25 @@ open_socket(init, StateData) ->
|
||||
{ok, Socket} ->
|
||||
Version = if
|
||||
StateData#state.use_v10 ->
|
||||
" version='1.0'";
|
||||
"1.0";
|
||||
true ->
|
||||
""
|
||||
end,
|
||||
NewStateData = StateData#state{socket = Socket,
|
||||
tls_enabled = false,
|
||||
streamid = new_id()},
|
||||
send_text(NewStateData, io_lib:format(?STREAM_HEADER,
|
||||
[StateData#state.myname, StateData#state.server,
|
||||
Version])),
|
||||
Opening = exmpp_stream:opening(
|
||||
StateData#state.server,
|
||||
?NS_JABBER_SERVER,
|
||||
Version),
|
||||
send_element(NewStateData,
|
||||
exmpp_stream:set_dialback_support(Opening)),
|
||||
{next_state, wait_for_stream, NewStateData, ?FSMTIMEOUT};
|
||||
{error, _Reason} ->
|
||||
?INFO_MSG("s2s connection: ~s -> ~s (remote server not found)",
|
||||
[StateData#state.myname, StateData#state.server]),
|
||||
case ejabberd_hooks:run_fold(find_s2s_bridge,
|
||||
undefined,
|
||||
[StateData#state.myname,
|
||||
StateData#state.server]) of
|
||||
{Mod, Fun, Type} ->
|
||||
?INFO_MSG("found a bridge to ~s for: ~s -> ~s",
|
||||
[Type, StateData#state.myname,
|
||||
StateData#state.server]),
|
||||
NewStateData = StateData#state{bridge={Mod, Fun}},
|
||||
{next_state, relay_to_bridge, NewStateData};
|
||||
_ ->
|
||||
wait_before_reconnect(StateData)
|
||||
end
|
||||
wait_before_reconnect(StateData)
|
||||
%%{stop, normal, StateData}
|
||||
end;
|
||||
open_socket(stop, StateData) ->
|
||||
?INFO_MSG("s2s connection: ~s -> ~s (stopped in open socket)",
|
||||
@@ -284,16 +265,15 @@ open_socket1(Host, Port) ->
|
||||
open_socket2(Type, Addr, Port) ->
|
||||
?DEBUG("s2s_out: connecting to ~p:~p~n", [Addr, Port]),
|
||||
Timeout = outgoing_s2s_timeout(),
|
||||
SockOpts = try erlang:system_info(otp_release) >= "R13B" of
|
||||
true -> [{send_timeout_close, true}];
|
||||
false -> []
|
||||
catch
|
||||
_:_ -> []
|
||||
end,
|
||||
SockOpts = case erlang:system_info(otp_release) >= "R13B" of
|
||||
true -> [{send_timeout_close, true}];
|
||||
false -> []
|
||||
end,
|
||||
IpOpts = get_outgoing_local_address_opts(Type),
|
||||
case (catch ejabberd_socket:connect(Addr, Port,
|
||||
[binary, {packet, 0},
|
||||
{send_timeout, ?TCP_SEND_TIMEOUT},
|
||||
{active, false}, Type | SockOpts],
|
||||
{active, false}, Type | SockOpts]++IpOpts,
|
||||
Timeout)) of
|
||||
{ok, _Socket} = R -> R;
|
||||
{error, Reason} = R ->
|
||||
@@ -304,32 +284,66 @@ open_socket2(Type, Addr, Port) ->
|
||||
{error, Reason}
|
||||
end.
|
||||
|
||||
get_outgoing_local_address_opts(DestType) ->
|
||||
ListenerIp = get_incoming_local_address(),
|
||||
OutLocalIp = case ejabberd_config:get_local_option(
|
||||
outgoing_s2s_local_address) of
|
||||
undefined -> undefined;
|
||||
T when is_tuple(T) ->
|
||||
T;
|
||||
S when is_list(S) ->
|
||||
[S2 | _] = string:tokens(S, "/"),
|
||||
{ok, T} = inet_parse:address(S2),
|
||||
T
|
||||
end,
|
||||
case {OutLocalIp, ListenerIp, DestType} of
|
||||
{{_, _, _, _}, _, inet} ->
|
||||
[{ip, OutLocalIp}];
|
||||
{{_, _, _, _, _, _, _, _}, _, inet6} ->
|
||||
[{ip, OutLocalIp}];
|
||||
{undefined, any, _} ->
|
||||
[];
|
||||
{undefined, _, _} ->
|
||||
[{ip, ListenerIp}];
|
||||
_ ->
|
||||
[]
|
||||
end.
|
||||
|
||||
get_incoming_local_address() ->
|
||||
Ports = ejabberd_config:get_local_option(listen),
|
||||
case [IP || {{_Port, IP, _Prot}, ejabberd_s2s_in, _Opts} <- Ports] of
|
||||
[{0, 0, 0, 0}] -> any;
|
||||
[{0, 0, 0, 0, 0, 0, 0, 0}] -> any;
|
||||
[IP] -> IP;
|
||||
_ -> any
|
||||
end.
|
||||
|
||||
%%----------------------------------------------------------------------
|
||||
|
||||
|
||||
wait_for_stream({xmlstreamstart, _Name, Attrs}, StateData) ->
|
||||
case {xml:get_attr_s("xmlns", Attrs),
|
||||
xml:get_attr_s("xmlns:db", Attrs),
|
||||
xml:get_attr_s("version", Attrs) == "1.0"} of
|
||||
{"jabber:server", "jabber:server:dialback", false} ->
|
||||
wait_for_stream({xmlstreamstart, Opening}, StateData) ->
|
||||
case {exmpp_stream:get_default_ns(Opening),
|
||||
exmpp_xml:is_ns_declared_here(Opening, ?NS_DIALBACK),
|
||||
exmpp_stream:get_version(Opening) == {1, 0}} of
|
||||
{?NS_JABBER_SERVER, true, false} ->
|
||||
send_db_request(StateData);
|
||||
{"jabber:server", "jabber:server:dialback", true} when
|
||||
{?NS_JABBER_SERVER, true, true} when
|
||||
StateData#state.use_v10 ->
|
||||
{next_state, wait_for_features, StateData, ?FSMTIMEOUT};
|
||||
{"jabber:server", "", true} when StateData#state.use_v10 ->
|
||||
{?NS_JABBER_SERVER, false, true} when StateData#state.use_v10 ->
|
||||
{next_state, wait_for_features, StateData#state{db_enabled = false}, ?FSMTIMEOUT};
|
||||
{NSProvided, DB, _} ->
|
||||
send_text(StateData, ?INVALID_NAMESPACE_ERR),
|
||||
send_element(StateData, exmpp_stream:error('invalid-namespace')),
|
||||
?INFO_MSG("Closing s2s connection: ~s -> ~s (invalid namespace).~n"
|
||||
"Namespace provided: ~p~nNamespace expected: \"jabber:server\"~n"
|
||||
"xmlns:db provided: ~p~nAll attributes: ~p",
|
||||
[StateData#state.myname, StateData#state.server, NSProvided, DB, Attrs]),
|
||||
"xmlns:db provided: ~p~nFull packet: ~p",
|
||||
[StateData#state.myname, StateData#state.server, NSProvided, DB, Opening]),
|
||||
{stop, normal, StateData}
|
||||
end;
|
||||
|
||||
wait_for_stream({xmlstreamerror, _}, StateData) ->
|
||||
send_text(StateData,
|
||||
?INVALID_XML_ERR ++ ?STREAM_TRAILER),
|
||||
send_element(StateData, exmpp_stream:error('xml-not-well-formed')),
|
||||
send_element(StateData, exmpp_stream:closing()),
|
||||
?INFO_MSG("Closing s2s connection: ~s -> ~s (invalid xml)",
|
||||
[StateData#state.myname, StateData#state.server]),
|
||||
{stop, normal, StateData};
|
||||
@@ -355,8 +369,8 @@ wait_for_validation({xmlstreamelement, El}, StateData) ->
|
||||
case is_verify_res(El) of
|
||||
{result, To, From, Id, Type} ->
|
||||
?DEBUG("recv result: ~p", [{From, To, Id, Type}]),
|
||||
case {Type, StateData#state.tls_enabled, StateData#state.tls_required} of
|
||||
{"valid", Enabled, Required} when (Enabled==true) or (Required==false) ->
|
||||
case Type of
|
||||
"valid" ->
|
||||
send_queue(StateData, StateData#state.queue),
|
||||
?INFO_MSG("Connection established: ~s -> ~s with TLS=~p",
|
||||
[StateData#state.myname, StateData#state.server, StateData#state.tls_enabled]),
|
||||
@@ -365,11 +379,6 @@ wait_for_validation({xmlstreamelement, El}, StateData) ->
|
||||
StateData#state.server]),
|
||||
{next_state, stream_established,
|
||||
StateData#state{queue = queue:new()}};
|
||||
{"valid", Enabled, Required} when (Enabled==false) and (Required==true) ->
|
||||
%% TODO: bounce packets
|
||||
?INFO_MSG("Closing s2s connection: ~s -> ~s (TLS is required but unavailable)",
|
||||
[StateData#state.myname, StateData#state.server]),
|
||||
{stop, normal, StateData};
|
||||
_ ->
|
||||
%% TODO: bounce packets
|
||||
?INFO_MSG("Closing s2s connection: ~s -> ~s (invalid dialback key)",
|
||||
@@ -418,8 +427,8 @@ wait_for_validation({xmlstreamend, _Name}, StateData) ->
|
||||
wait_for_validation({xmlstreamerror, _}, StateData) ->
|
||||
?INFO_MSG("wait for validation: ~s -> ~s (xmlstreamerror)",
|
||||
[StateData#state.myname, StateData#state.server]),
|
||||
send_text(StateData,
|
||||
?INVALID_XML_ERR ++ ?STREAM_TRAILER),
|
||||
send_element(StateData, exmpp_stream:error('xml-not-well-formed')),
|
||||
send_element(StateData, exmpp_stream:closing()),
|
||||
{stop, normal, StateData};
|
||||
|
||||
wait_for_validation(timeout, #state{verify = {VPid, VKey, SID}} = StateData)
|
||||
@@ -443,41 +452,37 @@ wait_for_validation(closed, StateData) ->
|
||||
|
||||
wait_for_features({xmlstreamelement, El}, StateData) ->
|
||||
case El of
|
||||
{xmlelement, "stream:features", _Attrs, Els} ->
|
||||
#xmlel{ns = ?NS_XMPP, name = 'features'} = Features ->
|
||||
{SASLEXT, StartTLS, StartTLSRequired} =
|
||||
lists:foldl(
|
||||
fun({xmlelement, "mechanisms", Attrs1, Els1} = _El1,
|
||||
fun(#xmlel{ns = ?NS_SASL, name = 'mechanisms'},
|
||||
{_SEXT, STLS, STLSReq} = Acc) ->
|
||||
case xml:get_attr_s("xmlns", Attrs1) of
|
||||
?NS_SASL ->
|
||||
NewSEXT =
|
||||
lists:any(
|
||||
fun({xmlelement, "mechanism", _, Els2}) ->
|
||||
case xml:get_cdata(Els2) of
|
||||
"EXTERNAL" -> true;
|
||||
_ -> false
|
||||
end;
|
||||
(_) -> false
|
||||
end, Els1),
|
||||
{NewSEXT, STLS, STLSReq};
|
||||
_ ->
|
||||
try
|
||||
Mechs = exmpp_client_sasl:announced_mechanisms(
|
||||
El),
|
||||
NewSEXT = lists:member("EXTERNAL", Mechs),
|
||||
{NewSEXT, STLS, STLSReq}
|
||||
catch
|
||||
_Exception ->
|
||||
Acc
|
||||
end;
|
||||
({xmlelement, "starttls", Attrs1, _Els1} = El1,
|
||||
(#xmlel{ns = ?NS_TLS, name ='starttls'},
|
||||
{SEXT, _STLS, _STLSReq} = Acc) ->
|
||||
case xml:get_attr_s("xmlns", Attrs1) of
|
||||
?NS_TLS ->
|
||||
Req = case xml:get_subtag(El1, "required") of
|
||||
{xmlelement, _, _, _} -> true;
|
||||
false -> false
|
||||
end,
|
||||
{SEXT, true, Req};
|
||||
_ ->
|
||||
try
|
||||
Support = exmpp_client_tls:announced_support(
|
||||
El),
|
||||
case Support of
|
||||
none -> Acc;
|
||||
optional -> {SEXT, true, false};
|
||||
required -> {SEXT, true, true}
|
||||
end
|
||||
catch
|
||||
_Exception ->
|
||||
Acc
|
||||
end;
|
||||
(_, Acc) ->
|
||||
Acc
|
||||
end, {false, false, false}, Els),
|
||||
end, {false, false, false}, Features#xmlel.children),
|
||||
if
|
||||
(not SASLEXT) and (not StartTLS) and
|
||||
StateData#state.authenticated ->
|
||||
@@ -492,19 +497,14 @@ wait_for_features({xmlstreamelement, El}, StateData) ->
|
||||
SASLEXT and StateData#state.try_auth and
|
||||
(StateData#state.new /= false) ->
|
||||
send_element(StateData,
|
||||
{xmlelement, "auth",
|
||||
[{"xmlns", ?NS_SASL},
|
||||
{"mechanism", "EXTERNAL"}],
|
||||
[{xmlcdata,
|
||||
jlib:encode_base64(
|
||||
StateData#state.myname)}]}),
|
||||
exmpp_client_sasl:selected_mechanism("EXTERNAL",
|
||||
StateData#state.myname)),
|
||||
{next_state, wait_for_auth_result,
|
||||
StateData#state{try_auth = false}, ?FSMTIMEOUT};
|
||||
StartTLS and StateData#state.tls and
|
||||
(not StateData#state.tls_enabled) ->
|
||||
send_element(StateData,
|
||||
{xmlelement, "starttls",
|
||||
[{"xmlns", ?NS_TLS}], []}),
|
||||
exmpp_client_tls:starttls()),
|
||||
{next_state, wait_for_starttls_proceed, StateData,
|
||||
?FSMTIMEOUT};
|
||||
StartTLSRequired and (not StateData#state.tls) ->
|
||||
@@ -525,9 +525,8 @@ wait_for_features({xmlstreamelement, El}, StateData) ->
|
||||
use_v10 = false}, ?FSMTIMEOUT}
|
||||
end;
|
||||
_ ->
|
||||
send_text(StateData,
|
||||
xml:element_to_string(?SERR_BAD_FORMAT) ++
|
||||
?STREAM_TRAILER),
|
||||
send_element(StateData, exmpp_stream:error('bad-format')),
|
||||
send_element(StateData, exmpp_stream:closing()),
|
||||
?INFO_MSG("Closing s2s connection: ~s -> ~s (bad format)",
|
||||
[StateData#state.myname, StateData#state.server]),
|
||||
{stop, normal, StateData}
|
||||
@@ -538,8 +537,8 @@ wait_for_features({xmlstreamend, _Name}, StateData) ->
|
||||
{stop, normal, StateData};
|
||||
|
||||
wait_for_features({xmlstreamerror, _}, StateData) ->
|
||||
send_text(StateData,
|
||||
?INVALID_XML_ERR ++ ?STREAM_TRAILER),
|
||||
send_element(StateData, exmpp_stream:error('xml-not-well-formed')),
|
||||
send_element(StateData, exmpp_stream:closing()),
|
||||
?INFO_MSG("wait for features: xmlstreamerror", []),
|
||||
{stop, normal, StateData};
|
||||
|
||||
@@ -554,48 +553,29 @@ wait_for_features(closed, StateData) ->
|
||||
|
||||
wait_for_auth_result({xmlstreamelement, El}, StateData) ->
|
||||
case El of
|
||||
{xmlelement, "success", Attrs, _Els} ->
|
||||
case xml:get_attr_s("xmlns", Attrs) of
|
||||
?NS_SASL ->
|
||||
?DEBUG("auth: ~p", [{StateData#state.myname,
|
||||
StateData#state.server}]),
|
||||
ejabberd_socket:reset_stream(StateData#state.socket),
|
||||
send_text(StateData,
|
||||
io_lib:format(?STREAM_HEADER,
|
||||
[StateData#state.myname, StateData#state.server,
|
||||
" version='1.0'"])),
|
||||
{next_state, wait_for_stream,
|
||||
StateData#state{streamid = new_id(),
|
||||
authenticated = true
|
||||
}, ?FSMTIMEOUT};
|
||||
_ ->
|
||||
send_text(StateData,
|
||||
xml:element_to_string(?SERR_BAD_FORMAT) ++
|
||||
?STREAM_TRAILER),
|
||||
?INFO_MSG("Closing s2s connection: ~s -> ~s (bad format)",
|
||||
[StateData#state.myname, StateData#state.server]),
|
||||
{stop, normal, StateData}
|
||||
end;
|
||||
{xmlelement, "failure", Attrs, _Els} ->
|
||||
case xml:get_attr_s("xmlns", Attrs) of
|
||||
?NS_SASL ->
|
||||
?DEBUG("restarted: ~p", [{StateData#state.myname,
|
||||
StateData#state.server}]),
|
||||
ejabberd_socket:close(StateData#state.socket),
|
||||
{next_state, reopen_socket,
|
||||
StateData#state{socket = undefined}, ?FSMTIMEOUT};
|
||||
_ ->
|
||||
send_text(StateData,
|
||||
xml:element_to_string(?SERR_BAD_FORMAT) ++
|
||||
?STREAM_TRAILER),
|
||||
?INFO_MSG("Closing s2s connection: ~s -> ~s (bad format)",
|
||||
[StateData#state.myname, StateData#state.server]),
|
||||
{stop, normal, StateData}
|
||||
end;
|
||||
#xmlel{ns = ?NS_SASL, name = 'success'} ->
|
||||
?DEBUG("auth: ~p", [{StateData#state.myname,
|
||||
StateData#state.server}]),
|
||||
ejabberd_socket:reset_stream(StateData#state.socket),
|
||||
Opening = exmpp_stream:opening(
|
||||
StateData#state.server,
|
||||
?NS_JABBER_SERVER,
|
||||
"1.0"),
|
||||
send_element(StateData,
|
||||
exmpp_stream:set_dialback_support(Opening)),
|
||||
{next_state, wait_for_stream,
|
||||
StateData#state{streamid = new_id(),
|
||||
authenticated = true
|
||||
}, ?FSMTIMEOUT};
|
||||
#xmlel{ns = ?NS_SASL, name = 'failure'} ->
|
||||
?DEBUG("restarted: ~p", [{StateData#state.myname,
|
||||
StateData#state.server}]),
|
||||
ejabberd_socket:close(StateData#state.socket),
|
||||
{next_state, reopen_socket,
|
||||
StateData#state{socket = undefined}, ?FSMTIMEOUT};
|
||||
_ ->
|
||||
send_text(StateData,
|
||||
xml:element_to_string(?SERR_BAD_FORMAT) ++
|
||||
?STREAM_TRAILER),
|
||||
send_element(StateData, exmpp_stream:error('bad-format')),
|
||||
send_element(StateData, exmpp_stream:closing()),
|
||||
?INFO_MSG("Closing s2s connection: ~s -> ~s (bad format)",
|
||||
[StateData#state.myname, StateData#state.server]),
|
||||
{stop, normal, StateData}
|
||||
@@ -606,8 +586,8 @@ wait_for_auth_result({xmlstreamend, _Name}, StateData) ->
|
||||
{stop, normal, StateData};
|
||||
|
||||
wait_for_auth_result({xmlstreamerror, _}, StateData) ->
|
||||
send_text(StateData,
|
||||
?INVALID_XML_ERR ++ ?STREAM_TRAILER),
|
||||
send_element(StateData, exmpp_stream:error('xml-not-well-formed')),
|
||||
send_element(StateData, exmpp_stream:closing()),
|
||||
?INFO_MSG("wait for auth result: xmlstreamerror", []),
|
||||
{stop, normal, StateData};
|
||||
|
||||
@@ -622,43 +602,36 @@ wait_for_auth_result(closed, StateData) ->
|
||||
|
||||
wait_for_starttls_proceed({xmlstreamelement, El}, StateData) ->
|
||||
case El of
|
||||
{xmlelement, "proceed", Attrs, _Els} ->
|
||||
case xml:get_attr_s("xmlns", Attrs) of
|
||||
?NS_TLS ->
|
||||
?DEBUG("starttls: ~p", [{StateData#state.myname,
|
||||
StateData#state.server}]),
|
||||
Socket = StateData#state.socket,
|
||||
TLSOpts = case ejabberd_config:get_local_option(
|
||||
{domain_certfile,
|
||||
StateData#state.myname}) of
|
||||
undefined ->
|
||||
StateData#state.tls_options;
|
||||
CertFile ->
|
||||
[{certfile, CertFile} |
|
||||
lists:keydelete(
|
||||
certfile, 1,
|
||||
StateData#state.tls_options)]
|
||||
end,
|
||||
TLSSocket = ejabberd_socket:starttls(Socket, TLSOpts),
|
||||
NewStateData = StateData#state{socket = TLSSocket,
|
||||
streamid = new_id(),
|
||||
tls_enabled = true,
|
||||
tls_options = TLSOpts
|
||||
},
|
||||
send_text(NewStateData,
|
||||
io_lib:format(?STREAM_HEADER,
|
||||
[StateData#state.myname, StateData#state.server,
|
||||
" version='1.0'"])),
|
||||
{next_state, wait_for_stream, NewStateData, ?FSMTIMEOUT};
|
||||
_ ->
|
||||
send_text(StateData,
|
||||
xml:element_to_string(?SERR_BAD_FORMAT) ++
|
||||
?STREAM_TRAILER),
|
||||
?INFO_MSG("Closing s2s connection: ~s -> ~s (bad format)",
|
||||
[StateData#state.myname, StateData#state.server]),
|
||||
{stop, normal, StateData}
|
||||
end;
|
||||
#xmlel{ns = ?NS_TLS, name = 'proceed'} ->
|
||||
?DEBUG("starttls: ~p", [{StateData#state.myname,
|
||||
StateData#state.server}]),
|
||||
Socket = StateData#state.socket,
|
||||
TLSOpts = case ejabberd_config:get_local_option(
|
||||
{domain_certfile,
|
||||
StateData#state.server}) of
|
||||
undefined ->
|
||||
StateData#state.tls_options;
|
||||
CertFile ->
|
||||
[{certfile, CertFile} |
|
||||
lists:keydelete(
|
||||
certfile, 1,
|
||||
StateData#state.tls_options)]
|
||||
end,
|
||||
TLSSocket = ejabberd_socket:starttls(Socket, TLSOpts),
|
||||
NewStateData = StateData#state{socket = TLSSocket,
|
||||
streamid = new_id(),
|
||||
tls_enabled = true
|
||||
},
|
||||
Opening = exmpp_stream:opening(
|
||||
StateData#state.server,
|
||||
?NS_JABBER_SERVER,
|
||||
"1.0"),
|
||||
send_element(NewStateData,
|
||||
exmpp_stream:set_dialback_support(Opening)),
|
||||
{next_state, wait_for_stream, NewStateData, ?FSMTIMEOUT};
|
||||
_ ->
|
||||
send_element(StateData, exmpp_stream:error('bad-format')),
|
||||
send_element(StateData, exmpp_stream:closing()),
|
||||
?INFO_MSG("Closing s2s connection: ~s -> ~s (bad format)",
|
||||
[StateData#state.myname, StateData#state.server]),
|
||||
{stop, normal, StateData}
|
||||
@@ -669,8 +642,8 @@ wait_for_starttls_proceed({xmlstreamend, _Name}, StateData) ->
|
||||
{stop, normal, StateData};
|
||||
|
||||
wait_for_starttls_proceed({xmlstreamerror, _}, StateData) ->
|
||||
send_text(StateData,
|
||||
?INVALID_XML_ERR ++ ?STREAM_TRAILER),
|
||||
send_element(StateData, exmpp_stream:error('xml-not-well-formed')),
|
||||
send_element(StateData, exmpp_stream:closing()),
|
||||
?INFO_MSG("wait for starttls proceed: xmlstreamerror", []),
|
||||
{stop, normal, StateData};
|
||||
|
||||
@@ -700,15 +673,6 @@ reopen_socket(closed, StateData) ->
|
||||
wait_before_retry(_Event, StateData) ->
|
||||
{next_state, wait_before_retry, StateData, ?FSMTIMEOUT}.
|
||||
|
||||
relay_to_bridge(stop, StateData) ->
|
||||
wait_before_reconnect(StateData);
|
||||
relay_to_bridge(closed, StateData) ->
|
||||
?INFO_MSG("relay to bridge: ~s -> ~s (closed)",
|
||||
[StateData#state.myname, StateData#state.server]),
|
||||
{stop, normal, StateData};
|
||||
relay_to_bridge(_Event, StateData) ->
|
||||
{next_state, relay_to_bridge, StateData}.
|
||||
|
||||
stream_established({xmlstreamelement, El}, StateData) ->
|
||||
?DEBUG("s2S stream established", []),
|
||||
case is_verify_res(El) of
|
||||
@@ -742,8 +706,8 @@ stream_established({xmlstreamend, _Name}, StateData) ->
|
||||
{stop, normal, StateData};
|
||||
|
||||
stream_established({xmlstreamerror, _}, StateData) ->
|
||||
send_text(StateData,
|
||||
?INVALID_XML_ERR ++ ?STREAM_TRAILER),
|
||||
send_element(StateData, exmpp_stream:error('xml-not-well-formed')),
|
||||
send_element(StateData, exmpp_stream:closing()),
|
||||
?INFO_MSG("stream established: ~s -> ~s (xmlstreamerror)",
|
||||
[StateData#state.myname, StateData#state.server]),
|
||||
{stop, normal, StateData};
|
||||
@@ -779,6 +743,9 @@ stream_established(closed, StateData) ->
|
||||
%% {next_state, NextStateName, NextStateData, Timeout} |
|
||||
%% {stop, Reason, NewStateData}
|
||||
%%----------------------------------------------------------------------
|
||||
handle_event({closed, Timeout}, StateName, StateData) ->
|
||||
p1_fsm:send_event_after(Timeout, closed),
|
||||
{next_state, StateName, StateData};
|
||||
handle_event(_Event, StateName, StateData) ->
|
||||
{next_state, StateName, StateData, get_timeout_interval(StateName)}.
|
||||
|
||||
@@ -857,21 +824,8 @@ handle_info({send_element, El}, StateName, StateData) ->
|
||||
%% In this state we bounce all message: We are waiting before
|
||||
%% trying to reconnect
|
||||
wait_before_retry ->
|
||||
bounce_element(El, ?ERR_REMOTE_SERVER_NOT_FOUND),
|
||||
bounce_element(El, 'remote-server-not-found'),
|
||||
{next_state, StateName, StateData};
|
||||
relay_to_bridge ->
|
||||
%% In this state we relay all outbound messages
|
||||
%% to a foreign protocol bridge such as SMTP, SIP, etc.
|
||||
{Mod, Fun} = StateData#state.bridge,
|
||||
?DEBUG("relaying stanza via ~p:~p/1", [Mod, Fun]),
|
||||
case catch Mod:Fun(El) of
|
||||
{'EXIT', Reason} ->
|
||||
?ERROR_MSG("Error while relaying to bridge: ~p", [Reason]),
|
||||
bounce_element(El, ?ERR_INTERNAL_SERVER_ERROR),
|
||||
wait_before_reconnect(StateData);
|
||||
_ ->
|
||||
{next_state, StateName, StateData}
|
||||
end;
|
||||
_ ->
|
||||
Q = queue:in(El, StateData#state.queue),
|
||||
{next_state, StateName, StateData#state{queue = Q},
|
||||
@@ -912,8 +866,8 @@ terminate(Reason, StateName, StateData) ->
|
||||
{StateData#state.myname, StateData#state.server}, self(), Key)
|
||||
end,
|
||||
%% bounce queue manage by process and Erlang message queue
|
||||
bounce_queue(StateData#state.queue, ?ERR_REMOTE_SERVER_NOT_FOUND),
|
||||
bounce_messages(?ERR_REMOTE_SERVER_NOT_FOUND),
|
||||
bounce_queue(StateData#state.queue, 'remote-server-not-found'),
|
||||
bounce_messages('remote-server-not-found'),
|
||||
case StateData#state.socket of
|
||||
undefined ->
|
||||
ok;
|
||||
@@ -928,8 +882,7 @@ terminate(Reason, StateName, StateData) ->
|
||||
%% Returns: State to print
|
||||
%%----------------------------------------------------------------------
|
||||
print_state(State) ->
|
||||
State.
|
||||
|
||||
State.
|
||||
%%%----------------------------------------------------------------------
|
||||
%%% Internal functions
|
||||
%%%----------------------------------------------------------------------
|
||||
@@ -937,8 +890,10 @@ print_state(State) ->
|
||||
send_text(StateData, Text) ->
|
||||
ejabberd_socket:send(StateData#state.socket, Text).
|
||||
|
||||
send_element(StateData, #xmlel{ns = ?NS_XMPP, name = 'stream'} = El) ->
|
||||
send_text(StateData, exmpp_stream:to_iolist(El));
|
||||
send_element(StateData, El) ->
|
||||
send_text(StateData, xml:element_to_binary(El)).
|
||||
send_text(StateData, exmpp_stanza:to_iolist(El)).
|
||||
|
||||
send_queue(StateData, Q) ->
|
||||
case queue:out(Q) of
|
||||
@@ -949,24 +904,25 @@ send_queue(StateData, Q) ->
|
||||
ok
|
||||
end.
|
||||
|
||||
%% Bounce a single message (xmlelement)
|
||||
bounce_element(El, Error) ->
|
||||
{xmlelement, _Name, Attrs, _SubTags} = El,
|
||||
case xml:get_attr_s("type", Attrs) of
|
||||
"error" -> ok;
|
||||
"result" -> ok;
|
||||
%% Bounce a single message (xmlel)
|
||||
bounce_element(El, Condition) ->
|
||||
case exmpp_stanza:get_type(El) of
|
||||
<<"error">> -> ok;
|
||||
<<"result">> -> ok;
|
||||
_ ->
|
||||
Err = jlib:make_error_reply(El, Error),
|
||||
From = jlib:string_to_jid(xml:get_tag_attr_s("from", El)),
|
||||
To = jlib:string_to_jid(xml:get_tag_attr_s("to", El)),
|
||||
Err = exmpp_stanza:reply_with_error(El, Condition),
|
||||
From = exmpp_jid:parse(exmpp_stanza:get_sender(El)),
|
||||
To = exmpp_jid:parse(exmpp_stanza:get_recipient(El)),
|
||||
% No namespace conversion (:server <-> :client) is done.
|
||||
% This is handled by C2S and S2S send_element functions.
|
||||
ejabberd_router:route(To, From, Err)
|
||||
end.
|
||||
|
||||
bounce_queue(Q, Error) ->
|
||||
bounce_queue(Q, Condition) ->
|
||||
case queue:out(Q) of
|
||||
{{value, El}, Q1} ->
|
||||
bounce_element(El, Error),
|
||||
bounce_queue(Q1, Error);
|
||||
bounce_element(El, Condition),
|
||||
bounce_queue(Q1, Condition);
|
||||
{empty, _} ->
|
||||
ok
|
||||
end.
|
||||
@@ -983,11 +939,11 @@ cancel_timer(Timer) ->
|
||||
ok
|
||||
end.
|
||||
|
||||
bounce_messages(Error) ->
|
||||
bounce_messages(Condition) ->
|
||||
receive
|
||||
{send_element, El} ->
|
||||
bounce_element(El, Error),
|
||||
bounce_messages(Error)
|
||||
bounce_element(El, Condition),
|
||||
bounce_messages(Condition)
|
||||
after 0 ->
|
||||
ok
|
||||
end.
|
||||
@@ -1013,24 +969,16 @@ send_db_request(StateData) ->
|
||||
false ->
|
||||
ok;
|
||||
Key1 ->
|
||||
send_element(StateData,
|
||||
{xmlelement,
|
||||
"db:result",
|
||||
[{"from", StateData#state.myname},
|
||||
{"to", Server}],
|
||||
[{xmlcdata, Key1}]})
|
||||
send_element(StateData, exmpp_dialback:key(
|
||||
StateData#state.myname, Server, Key1))
|
||||
end,
|
||||
case StateData#state.verify of
|
||||
false ->
|
||||
ok;
|
||||
{_Pid, Key2, SID} ->
|
||||
send_element(StateData,
|
||||
{xmlelement,
|
||||
"db:verify",
|
||||
[{"from", StateData#state.myname},
|
||||
{"to", StateData#state.server},
|
||||
{"id", SID}],
|
||||
[{xmlcdata, Key2}]})
|
||||
send_element(StateData, exmpp_dialback:verify_request(
|
||||
StateData#state.myname,
|
||||
StateData#state.server, SID, Key2))
|
||||
end,
|
||||
{next_state, wait_for_validation, NewStateData, ?FSMTIMEOUT*6}
|
||||
catch
|
||||
@@ -1039,18 +987,20 @@ send_db_request(StateData) ->
|
||||
end.
|
||||
|
||||
|
||||
is_verify_res({xmlelement, Name, Attrs, _Els}) when Name == "db:result" ->
|
||||
is_verify_res(#xmlel{ns = ?NS_DIALBACK, name = 'result',
|
||||
attrs = Attrs}) ->
|
||||
{result,
|
||||
xml:get_attr_s("to", Attrs),
|
||||
xml:get_attr_s("from", Attrs),
|
||||
xml:get_attr_s("id", Attrs),
|
||||
xml:get_attr_s("type", Attrs)};
|
||||
is_verify_res({xmlelement, Name, Attrs, _Els}) when Name == "db:verify" ->
|
||||
exmpp_stanza:get_recipient_from_attrs(Attrs),
|
||||
exmpp_stanza:get_sender_from_attrs(Attrs),
|
||||
exmpp_stanza:get_id_from_attrs(Attrs),
|
||||
binary_to_list(exmpp_stanza:get_type_from_attrs(Attrs))};
|
||||
is_verify_res(#xmlel{ns = ?NS_DIALBACK, name = 'verify',
|
||||
attrs = Attrs}) ->
|
||||
{verify,
|
||||
xml:get_attr_s("to", Attrs),
|
||||
xml:get_attr_s("from", Attrs),
|
||||
xml:get_attr_s("id", Attrs),
|
||||
xml:get_attr_s("type", Attrs)};
|
||||
exmpp_stanza:get_recipient_from_attrs(Attrs),
|
||||
exmpp_stanza:get_sender_from_attrs(Attrs),
|
||||
exmpp_stanza:get_id_from_attrs(Attrs),
|
||||
binary_to_list(exmpp_stanza:get_type_from_attrs(Attrs))};
|
||||
is_verify_res(_) ->
|
||||
false.
|
||||
|
||||
@@ -1069,10 +1019,7 @@ get_addr_port(Server) ->
|
||||
{ok, HEnt} ->
|
||||
?DEBUG("srv lookup of '~s': ~p~n",
|
||||
[Server, HEnt#hostent.h_addr_list]),
|
||||
case HEnt#hostent.h_addr_list of
|
||||
[] ->
|
||||
[{Server, outgoing_s2s_port()}];
|
||||
AddrList ->
|
||||
AddrList = HEnt#hostent.h_addr_list,
|
||||
%% Probabilities are not exactly proportional to weights
|
||||
%% for simplicity (higher weigths are overvalued)
|
||||
{A1, A2, A3} = now(),
|
||||
@@ -1094,7 +1041,6 @@ get_addr_port(Server) ->
|
||||
end, lists:keysort(1, SortedList)),
|
||||
?DEBUG("srv lookup of '~s': ~p~n", [Server, List]),
|
||||
List
|
||||
end
|
||||
end
|
||||
end.
|
||||
|
||||
@@ -1220,8 +1166,8 @@ get_timeout_interval(StateName) ->
|
||||
%% function that want to wait for a reconnect delay before stopping.
|
||||
wait_before_reconnect(StateData) ->
|
||||
%% bounce queue manage by process and Erlang message queue
|
||||
bounce_queue(StateData#state.queue, ?ERR_REMOTE_SERVER_NOT_FOUND),
|
||||
bounce_messages(?ERR_REMOTE_SERVER_NOT_FOUND),
|
||||
bounce_queue(StateData#state.queue, 'remote-server-not-found'),
|
||||
bounce_messages('remote-server-not-found'),
|
||||
cancel_timer(StateData#state.timer),
|
||||
Delay = case StateData#state.delay_to_retry of
|
||||
undefined_delay ->
|
||||
|
||||
@@ -50,8 +50,9 @@
|
||||
terminate/3,
|
||||
print_state/1]).
|
||||
|
||||
-include_lib("exmpp/include/exmpp.hrl").
|
||||
|
||||
-include("ejabberd.hrl").
|
||||
-include("jlib.hrl").
|
||||
|
||||
-record(state, {socket, sockmod, streamid,
|
||||
hosts, password, access,
|
||||
@@ -65,36 +66,10 @@
|
||||
-define(FSMOPTS, []).
|
||||
-endif.
|
||||
|
||||
-define(STREAM_HEADER,
|
||||
"<?xml version='1.0'?>"
|
||||
"<stream:stream "
|
||||
"xmlns:stream='http://etherx.jabber.org/streams' "
|
||||
"xmlns='jabber:component:accept' "
|
||||
"id='~s' from='~s'>"
|
||||
).
|
||||
|
||||
-define(STREAM_TRAILER, "</stream:stream>").
|
||||
|
||||
-define(INVALID_HEADER_ERR,
|
||||
"<stream:stream "
|
||||
"xmlns:stream='http://etherx.jabber.org/streams'>"
|
||||
"<stream:error>Invalid Stream Header</stream:error>"
|
||||
"</stream:stream>"
|
||||
).
|
||||
|
||||
-define(INVALID_HANDSHAKE_ERR,
|
||||
"<stream:error>"
|
||||
"<not-authorized xmlns='urn:ietf:params:xml:ns:xmpp-streams'/>"
|
||||
"<text xmlns='urn:ietf:params:xml:ns:xmpp-streams' xml:lang='en'>"
|
||||
"Invalid Handshake</text>"
|
||||
"</stream:error>"
|
||||
"</stream:stream>"
|
||||
).
|
||||
|
||||
-define(INVALID_XML_ERR,
|
||||
xml:element_to_string(?SERR_XML_NOT_WELL_FORMED)).
|
||||
-define(INVALID_NS_ERR,
|
||||
xml:element_to_string(?SERR_INVALID_NAMESPACE)).
|
||||
% These are the namespace already declared by the stream opening. This is
|
||||
% used at serialization time.
|
||||
-define(DEFAULT_NS, ?NS_COMPONENT_ACCEPT).
|
||||
-define(PREFIXED_NS, [{?NS_XMPP, ?NS_XMPP_pfx}]).
|
||||
|
||||
%%%----------------------------------------------------------------------
|
||||
%%% API
|
||||
@@ -163,7 +138,7 @@ init([{SockMod, Socket}, Opts]) ->
|
||||
{ok, wait_for_stream, #state{socket = Socket,
|
||||
sockmod = SockMod,
|
||||
streamid = new_id(),
|
||||
hosts = Hosts,
|
||||
hosts = [list_to_binary(H) || H <- Hosts],
|
||||
password = Password,
|
||||
access = Access,
|
||||
check_from = CheckFrom
|
||||
@@ -176,28 +151,36 @@ init([{SockMod, Socket}, Opts]) ->
|
||||
%% {stop, Reason, NewStateData}
|
||||
%%----------------------------------------------------------------------
|
||||
|
||||
wait_for_stream({xmlstreamstart, _Name, Attrs}, StateData) ->
|
||||
case xml:get_attr_s("xmlns", Attrs) of
|
||||
"jabber:component:accept" ->
|
||||
wait_for_stream({xmlstreamstart, El = #xmlel{ns = _NS, attrs = Attrs}}, StateData) ->
|
||||
case exmpp_xml:is_ns_declared_here(El, ?NS_COMPONENT_ACCEPT) of
|
||||
true ->
|
||||
%% Note: XEP-0114 requires to check that destination is a Jabber
|
||||
%% component served by this Jabber server.
|
||||
%% However several transports don't respect that,
|
||||
%% so ejabberd doesn't check 'to' attribute (EJAB-717)
|
||||
To = xml:get_attr_s("to", Attrs),
|
||||
Header = io_lib:format(?STREAM_HEADER,
|
||||
[StateData#state.streamid, xml:crypt(To)]),
|
||||
send_text(StateData, Header),
|
||||
To = exmpp_stanza:get_recipient_from_attrs(Attrs),
|
||||
Opening_Reply = exmpp_stream:opening_reply(To,
|
||||
?NS_COMPONENT_ACCEPT,
|
||||
{0, 0}, StateData#state.streamid),
|
||||
send_element(StateData, Opening_Reply),
|
||||
{next_state, wait_for_handshake, StateData};
|
||||
_ ->
|
||||
send_text(StateData, ?INVALID_HEADER_ERR),
|
||||
false ->
|
||||
Error = #xmlel{ns = ?NS_XMPP, name = 'stream', children = [
|
||||
#xmlel{ns = ?NS_XMPP, name = 'error', children = [
|
||||
#xmlcdata{cdata = <<"Invalid Stream Header">>}
|
||||
]}
|
||||
]},
|
||||
send_element(StateData, Error),
|
||||
{stop, normal, StateData}
|
||||
end;
|
||||
|
||||
wait_for_stream({xmlstreamerror, _}, StateData) ->
|
||||
Header = io_lib:format(?STREAM_HEADER,
|
||||
["none", ?MYNAME]),
|
||||
send_text(StateData,
|
||||
Header ++ ?INVALID_XML_ERR ++ ?STREAM_TRAILER),
|
||||
Opening_Reply = exmpp_stream:opening_reply(?MYNAME,
|
||||
?NS_COMPONENT_ACCEPT,
|
||||
{0, 0}, "none"),
|
||||
send_element(StateData, Opening_Reply),
|
||||
send_element(StateData, exmpp_stream:error('xml-not-well-formed')),
|
||||
send_element(StateData, exmpp_stream:closing()),
|
||||
{stop, normal, StateData};
|
||||
|
||||
wait_for_stream(closed, StateData) ->
|
||||
@@ -205,21 +188,38 @@ wait_for_stream(closed, StateData) ->
|
||||
|
||||
|
||||
wait_for_handshake({xmlstreamelement, El}, StateData) ->
|
||||
{xmlelement, Name, _Attrs, Els} = El,
|
||||
case {Name, xml:get_cdata(Els)} of
|
||||
{"handshake", Digest} ->
|
||||
case {El#xmlel.name, exmpp_xml:get_cdata_as_list(El)} of
|
||||
{'handshake', Digest} ->
|
||||
case sha:sha(StateData#state.streamid ++
|
||||
StateData#state.password) of
|
||||
Digest ->
|
||||
send_text(StateData, "<handshake/>"),
|
||||
send_element(StateData,
|
||||
#xmlel{ns = ?NS_COMPONENT_ACCEPT, name = 'handshake'}),
|
||||
lists:foreach(
|
||||
fun(H) ->
|
||||
ejabberd_router:register_route(H),
|
||||
ejabberd_router:register_route(binary_to_list(H)),
|
||||
?INFO_MSG("Route registered for service ~p~n", [H])
|
||||
end, StateData#state.hosts),
|
||||
{next_state, stream_established, StateData};
|
||||
_ ->
|
||||
send_text(StateData, ?INVALID_HANDSHAKE_ERR),
|
||||
_ ->
|
||||
TextEl =
|
||||
#xmlel{ns = ?NS_STANZA_ERRORS,
|
||||
name = 'text',
|
||||
children =
|
||||
[#xmlcdata{cdata = <<"Invalid Handshake">>}]
|
||||
},
|
||||
NotAuthorizedEl =
|
||||
#xmlel{ns = ?NS_STANZA_ERRORS,
|
||||
name = 'not-authorized',
|
||||
children = [TextEl]
|
||||
},
|
||||
InvalidHandshakeEl =
|
||||
#xmlel{ns = ?NS_XMPP,
|
||||
name = 'error',
|
||||
children = [NotAuthorizedEl]
|
||||
},
|
||||
send_element(StateData, InvalidHandshakeEl),
|
||||
send_element(StateData, exmpp_stream:closing()),
|
||||
{stop, normal, StateData}
|
||||
end;
|
||||
_ ->
|
||||
@@ -230,7 +230,8 @@ wait_for_handshake({xmlstreamend, _Name}, StateData) ->
|
||||
{stop, normal, StateData};
|
||||
|
||||
wait_for_handshake({xmlstreamerror, _}, StateData) ->
|
||||
send_text(StateData, ?INVALID_XML_ERR ++ ?STREAM_TRAILER),
|
||||
send_element(StateData, exmpp_stream:error('xml-not-well-formed')),
|
||||
send_element(StateData, exmpp_stream:closing()),
|
||||
{stop, normal, StateData};
|
||||
|
||||
wait_for_handshake(closed, StateData) ->
|
||||
@@ -238,39 +239,34 @@ wait_for_handshake(closed, StateData) ->
|
||||
|
||||
|
||||
stream_established({xmlstreamelement, El}, StateData) ->
|
||||
NewEl = jlib:remove_attr("xmlns", El),
|
||||
{xmlelement, Name, Attrs, _Els} = NewEl,
|
||||
From = xml:get_attr_s("from", Attrs),
|
||||
From = exmpp_stanza:get_sender(El),
|
||||
FromJID = case StateData#state.check_from of
|
||||
%% If the admin does not want to check the from field
|
||||
%% when accept packets from any address.
|
||||
%% In this case, the component can send packet of
|
||||
%% behalf of the server users.
|
||||
false -> jlib:string_to_jid(From);
|
||||
false -> exmpp_jid:parse(From);
|
||||
%% The default is the standard behaviour in XEP-0114
|
||||
_ ->
|
||||
FromJID1 = jlib:string_to_jid(From),
|
||||
case FromJID1 of
|
||||
#jid{lserver = Server} ->
|
||||
case lists:member(Server, StateData#state.hosts) of
|
||||
FromJID1 = exmpp_jid:parse(From),
|
||||
Server = exmpp_jid:prep_domain(FromJID1),
|
||||
case lists:member(Server, StateData#state.hosts) of
|
||||
true -> FromJID1;
|
||||
false -> error
|
||||
end;
|
||||
_ -> error
|
||||
end
|
||||
end
|
||||
end,
|
||||
To = xml:get_attr_s("to", Attrs),
|
||||
To = exmpp_stanza:get_recipient(El),
|
||||
ToJID = case To of
|
||||
"" -> error;
|
||||
_ -> jlib:string_to_jid(To)
|
||||
undefined -> error;
|
||||
_ -> exmpp_jid:parse(To)
|
||||
end,
|
||||
if ((Name == "iq") or
|
||||
(Name == "message") or
|
||||
(Name == "presence")) and
|
||||
if ((El#xmlel.name == 'iq') or
|
||||
(El#xmlel.name == 'message') or
|
||||
(El#xmlel.name == 'presence')) and
|
||||
(ToJID /= error) and (FromJID /= error) ->
|
||||
ejabberd_router:route(FromJID, ToJID, NewEl);
|
||||
ejabberd_router:route(FromJID, ToJID, El);
|
||||
true ->
|
||||
Err = jlib:make_error_reply(NewEl, ?ERR_BAD_REQUEST),
|
||||
Err = exmpp_stanza:reply_with_error(El, 'bad-request'),
|
||||
send_element(StateData, Err),
|
||||
error
|
||||
end,
|
||||
@@ -281,7 +277,8 @@ stream_established({xmlstreamend, _Name}, StateData) ->
|
||||
{stop, normal, StateData};
|
||||
|
||||
stream_established({xmlstreamerror, _}, StateData) ->
|
||||
send_text(StateData, ?INVALID_XML_ERR ++ ?STREAM_TRAILER),
|
||||
send_element(StateData, exmpp_stream:error('xml-not-well-formed')),
|
||||
send_element(StateData, exmpp_stream:closing()),
|
||||
{stop, normal, StateData};
|
||||
|
||||
stream_established(closed, StateData) ->
|
||||
@@ -335,27 +332,23 @@ code_change(_OldVsn, StateName, StateData, _Extra) ->
|
||||
%% {stop, Reason, NewStateData}
|
||||
%%----------------------------------------------------------------------
|
||||
handle_info({send_text, Text}, StateName, StateData) ->
|
||||
% XXX OLD FORMAT: This clause should be removed.
|
||||
send_text(StateData, Text),
|
||||
{next_state, StateName, StateData};
|
||||
handle_info({send_element, El}, StateName, StateData) ->
|
||||
io:format("ejabberd_service send_element ~p~n",[ El]),
|
||||
send_element(StateData, El),
|
||||
{next_state, StateName, StateData};
|
||||
handle_info({route, From, To, Packet}, StateName, StateData) ->
|
||||
case acl:match_rule(global, StateData#state.access, From) of
|
||||
allow ->
|
||||
{xmlelement, Name, Attrs, Els} = Packet,
|
||||
Attrs2 = jlib:replace_from_to_attrs(jlib:jid_to_string(From),
|
||||
jlib:jid_to_string(To),
|
||||
Attrs),
|
||||
Text = xml:element_to_binary({xmlelement, Name, Attrs2, Els}),
|
||||
send_text(StateData, Text);
|
||||
El1 = exmpp_stanza:set_sender(Packet, From),
|
||||
El2 = exmpp_stanza:set_recipient(El1, To),
|
||||
send_element(StateData, El2);
|
||||
deny ->
|
||||
Err = jlib:make_error_reply(Packet, ?ERR_NOT_ALLOWED),
|
||||
Err = exmpp_stanza:reply_with_error(Packet, 'not-allowed'),
|
||||
ejabberd_router:route_error(To, From, Err, Packet)
|
||||
end,
|
||||
{next_state, StateName, StateData};
|
||||
handle_info(Info, StateName, StateData) ->
|
||||
?ERROR_MSG("Unexpected info: ~p", [Info]),
|
||||
{next_state, StateName, StateData}.
|
||||
|
||||
|
||||
@@ -370,7 +363,7 @@ terminate(Reason, StateName, StateData) ->
|
||||
stream_established ->
|
||||
lists:foreach(
|
||||
fun(H) ->
|
||||
ejabberd_router:unregister_route(H)
|
||||
ejabberd_router:unregister_route(binary_to_list(H))
|
||||
end, StateData#state.hosts);
|
||||
_ ->
|
||||
ok
|
||||
@@ -384,17 +377,20 @@ terminate(Reason, StateName, StateData) ->
|
||||
%% Returns: State to print
|
||||
%%----------------------------------------------------------------------
|
||||
print_state(State) ->
|
||||
State.
|
||||
State.
|
||||
|
||||
%%%----------------------------------------------------------------------
|
||||
%%% Internal functions
|
||||
%%%----------------------------------------------------------------------
|
||||
|
||||
send_text(StateData, Text) ->
|
||||
io:format(">>~n ~s ~n", [Text]),
|
||||
(StateData#state.sockmod):send(StateData#state.socket, Text).
|
||||
|
||||
send_element(StateData, #xmlel{ns = ?NS_XMPP, name = 'stream'} = El) ->
|
||||
send_text(StateData, exmpp_stream:to_iolist(El));
|
||||
send_element(StateData, El) ->
|
||||
send_text(StateData, xml:element_to_binary(El)).
|
||||
send_text(StateData, exmpp_stanza:to_iolist(El)).
|
||||
|
||||
new_id() ->
|
||||
randoms:get_string().
|
||||
|
||||
@@ -32,17 +32,21 @@
|
||||
%% API
|
||||
-export([start_link/0,
|
||||
route/3,
|
||||
open_session/5, close_session/4,
|
||||
set_session/4,
|
||||
open_session/3,
|
||||
open_session/4,
|
||||
close_session/2,
|
||||
check_in_subscription/6,
|
||||
bounce_offline_message/3,
|
||||
disconnect_removed_user/2,
|
||||
get_user_resources/2,
|
||||
set_presence/7,
|
||||
unset_presence/6,
|
||||
close_session_unset_presence/5,
|
||||
set_presence/5,
|
||||
unset_presence/4,
|
||||
close_session_unset_presence/3,
|
||||
dirty_get_sessions_list/0,
|
||||
dirty_get_my_sessions_list/0,
|
||||
get_vh_session_list/1,
|
||||
get_vh_my_session_list/1,
|
||||
get_vh_session_number/1,
|
||||
register_iq_handler/4,
|
||||
register_iq_handler/5,
|
||||
@@ -51,27 +55,38 @@
|
||||
connected_users/0,
|
||||
connected_users_number/0,
|
||||
user_resources/2,
|
||||
get_session_pid/3,
|
||||
get_session_pid/1,
|
||||
get_user_info/3,
|
||||
get_user_ip/3
|
||||
get_user_ip/1,
|
||||
migrate/1
|
||||
]).
|
||||
|
||||
%% gen_server callbacks
|
||||
-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
|
||||
terminate/2, code_change/3]).
|
||||
|
||||
-include_lib("exmpp/include/exmpp.hrl").
|
||||
|
||||
-include("ejabberd.hrl").
|
||||
-include("jlib.hrl").
|
||||
-include("ejabberd_commands.hrl").
|
||||
-include("mod_privacy.hrl").
|
||||
|
||||
-record(session, {sid, usr, us, priority, info}).
|
||||
-record(session_counter, {vhost, count}).
|
||||
-record(state, {}).
|
||||
|
||||
%% default value for the maximum number of user connections
|
||||
-define(MAX_USER_SESSIONS, infinity).
|
||||
|
||||
% These are the namespace already declared by the stream opening. This is
|
||||
% used at serialization time.
|
||||
-define(DEFAULT_NS, ?NS_JABBER_CLIENT).
|
||||
-define(PREFIXED_NS, [
|
||||
{?NS_XMPP, ?NS_XMPP_pfx}, {?NS_DIALBACK, ?NS_DIALBACK_pfx}
|
||||
]).
|
||||
|
||||
|
||||
-define(IS_BINARY_OR_UNDEF(X),
|
||||
(is_binary(X) orelse X == 'undefined')).
|
||||
%%====================================================================
|
||||
%% API
|
||||
%%====================================================================
|
||||
@@ -81,7 +96,17 @@
|
||||
%%--------------------------------------------------------------------
|
||||
start_link() ->
|
||||
gen_server:start_link({local, ?MODULE}, ?MODULE, [], []).
|
||||
|
||||
%% #xmlelement{} used for retro-compatibility
|
||||
route(FromOld, ToOld, #xmlelement{} = PacketOld) ->
|
||||
catch throw(for_stacktrace), % To have a stacktrace.
|
||||
io:format("~nSM: old #xmlelement:~n~p~n~p~n~n",
|
||||
[PacketOld, erlang:get_stacktrace()]),
|
||||
% XXX OLD FORMAT: From, To, Packet.
|
||||
From = jlib:from_old_jid(FromOld),
|
||||
To = jlib:from_old_jid(ToOld),
|
||||
Packet = exmpp_xml:xmlelement_to_xmlel(PacketOld, [?NS_JABBER_CLIENT],
|
||||
[{?NS_XMPP, ?NS_XMPP_pfx}]),
|
||||
route(From, To, Packet);
|
||||
route(From, To, Packet) ->
|
||||
case catch do_route(From, To, Packet) of
|
||||
{'EXIT', Reason} ->
|
||||
@@ -91,32 +116,30 @@ route(From, To, Packet) ->
|
||||
ok
|
||||
end.
|
||||
|
||||
open_session(SID, User, Server, Resource, Info) ->
|
||||
set_session(SID, User, Server, Resource, undefined, Info),
|
||||
mnesia:dirty_update_counter(session_counter,
|
||||
jlib:nameprep(Server), 1),
|
||||
check_for_sessions_to_replace(User, Server, Resource),
|
||||
JID = jlib:make_jid(User, Server, Resource),
|
||||
ejabberd_hooks:run(sm_register_connection_hook, JID#jid.lserver,
|
||||
open_session(SID, JID, Info) ->
|
||||
open_session(SID, JID, undefined, Info).
|
||||
|
||||
open_session(SID, JID, Priority, Info) when ?IS_JID(JID) ->
|
||||
set_session(SID, JID, Priority, Info),
|
||||
check_for_sessions_to_replace(JID),
|
||||
ejabberd_hooks:run(sm_register_connection_hook, exmpp_jid:prep_domain(JID),
|
||||
[SID, JID, Info]).
|
||||
|
||||
close_session(SID, User, Server, Resource) ->
|
||||
close_session(SID, JID ) when ?IS_JID(JID)->
|
||||
Info = case mnesia:dirty_read({session, SID}) of
|
||||
[] -> [];
|
||||
[#session{info=I}] -> I
|
||||
end,
|
||||
F = fun() ->
|
||||
mnesia:delete({session, SID}),
|
||||
mnesia:dirty_update_counter(session_counter,
|
||||
jlib:nameprep(Server), -1)
|
||||
mnesia:delete({session, SID})
|
||||
end,
|
||||
mnesia:sync_dirty(F),
|
||||
JID = jlib:make_jid(User, Server, Resource),
|
||||
ejabberd_hooks:run(sm_remove_connection_hook, JID#jid.lserver,
|
||||
ejabberd_hooks:run(sm_remove_connection_hook, exmpp_jid:prep_domain(JID),
|
||||
[SID, JID, Info]).
|
||||
|
||||
check_in_subscription(Acc, User, Server, _JID, _Type, _Reason) ->
|
||||
case ejabberd_auth:is_user_exists(User, Server) of
|
||||
check_in_subscription(Acc, User, Server, _JID, _Type, _Reason)
|
||||
when is_binary(User), is_binary(Server)->
|
||||
case ejabberd_auth:is_user_exists(binary_to_list(User), binary_to_list(Server)) of
|
||||
true ->
|
||||
Acc;
|
||||
false ->
|
||||
@@ -124,116 +147,166 @@ check_in_subscription(Acc, User, Server, _JID, _Type, _Reason) ->
|
||||
end.
|
||||
|
||||
bounce_offline_message(From, To, Packet) ->
|
||||
Err = jlib:make_error_reply(Packet, ?ERR_SERVICE_UNAVAILABLE),
|
||||
Err = exmpp_stanza:reply_with_error(Packet, 'service-unavailable'),
|
||||
ejabberd_router:route(To, From, Err),
|
||||
stop.
|
||||
|
||||
disconnect_removed_user(User, Server) ->
|
||||
ejabberd_sm:route(jlib:make_jid("", "", ""),
|
||||
jlib:make_jid(User, Server, ""),
|
||||
{xmlelement, "broadcast", [],
|
||||
[{exit, "User removed"}]}).
|
||||
ejabberd_sm:route(exmpp_jid:make(),
|
||||
exmpp_jid:make(User,
|
||||
Server),
|
||||
#xmlel{name = 'broadcast', ns = exit,
|
||||
attrs = [exmpp_xml:attribute(reason, "User removed")]}).
|
||||
|
||||
get_user_resources(User, Server) ->
|
||||
LUser = jlib:nodeprep(User),
|
||||
LServer = jlib:nameprep(Server),
|
||||
US = {LUser, LServer},
|
||||
case catch mnesia:dirty_index_read(session, US, #session.us) of
|
||||
{'EXIT', _Reason} ->
|
||||
[];
|
||||
Ss ->
|
||||
[element(3, S#session.usr) || S <- clean_session_list(Ss)]
|
||||
get_user_resources(User, Server)
|
||||
when is_binary(User), is_binary(Server) ->
|
||||
US = {User, Server},
|
||||
Ss = case ejabberd_cluster:get_node({User, Server}) of
|
||||
Node when Node == node() ->
|
||||
catch mnesia:dirty_index_read(session, US, #session.us);
|
||||
Node ->
|
||||
catch rpc:call(Node, mnesia, dirty_index_read,
|
||||
[session, US, #session.us], 5000)
|
||||
end,
|
||||
if is_list(Ss) ->
|
||||
[element(3, S#session.usr) || S <- clean_session_list(Ss)];
|
||||
true ->
|
||||
[]
|
||||
end.
|
||||
|
||||
get_user_ip(User, Server, Resource) ->
|
||||
LUser = jlib:nodeprep(User),
|
||||
LServer = jlib:nameprep(Server),
|
||||
LResource = jlib:resourceprep(Resource),
|
||||
USR = {LUser, LServer, LResource},
|
||||
case mnesia:dirty_index_read(session, USR, #session.usr) of
|
||||
[] ->
|
||||
undefined;
|
||||
Ss ->
|
||||
get_user_ip(JID) when ?IS_JID(JID) ->
|
||||
USR = {LUser = exmpp_jid:prep_node(JID),
|
||||
LServer = exmpp_jid:prep_domain(JID),
|
||||
exmpp_jid:prep_resource(JID)},
|
||||
Ss = case ejabberd_cluster:get_node({LUser, LServer}) of
|
||||
Node when Node == node() ->
|
||||
mnesia:dirty_index_read(session, USR, #session.usr);
|
||||
Node ->
|
||||
catch rpc:call(Node, mnesia, dirty_index_read,
|
||||
[session, USR, #session.usr], 5000)
|
||||
end,
|
||||
if is_list(Ss), Ss /= [] ->
|
||||
Session = lists:max(Ss),
|
||||
proplists:get_value(ip, Session#session.info)
|
||||
proplists:get_value(ip, Session#session.info);
|
||||
true ->
|
||||
undefined
|
||||
end.
|
||||
|
||||
get_user_info(User, Server, Resource) ->
|
||||
LUser = jlib:nodeprep(User),
|
||||
LServer = jlib:nameprep(Server),
|
||||
LResource = jlib:resourceprep(Resource),
|
||||
USR = {LUser, LServer, LResource},
|
||||
case mnesia:dirty_index_read(session, USR, #session.usr) of
|
||||
[] ->
|
||||
offline;
|
||||
Ss ->
|
||||
get_user_info(User, Server, Resource)
|
||||
when is_binary(User),
|
||||
is_binary(Server),
|
||||
is_binary(Resource) ->
|
||||
LUser = exmpp_stringprep:nodeprep(User),
|
||||
LServer = exmpp_stringprep:nameprep(Server),
|
||||
LResource = exmpp_stringprep:resourceprep(Resource),
|
||||
USR = {LUser,
|
||||
LServer,
|
||||
LResource},
|
||||
Ss = case ejabberd_cluster:get_node({LUser, LServer}) of
|
||||
Node when Node == node() ->
|
||||
mnesia:dirty_index_read(session, USR, #session.usr);
|
||||
Node ->
|
||||
catch rpc:call(Node, mnesia, dirty_index_read,
|
||||
[session, USR, #session.usr], 5000)
|
||||
end,
|
||||
if is_list(Ss), Ss /= [] ->
|
||||
Session = lists:max(Ss),
|
||||
Node = node(element(2, Session#session.sid)),
|
||||
N = node(element(2, Session#session.sid)),
|
||||
Conn = proplists:get_value(conn, Session#session.info),
|
||||
IP = proplists:get_value(ip, Session#session.info),
|
||||
[{node, Node}, {conn, Conn}, {ip, IP}]
|
||||
[{node, N}, {conn, Conn}, {ip, IP}];
|
||||
true ->
|
||||
offline
|
||||
end.
|
||||
|
||||
set_presence(SID, User, Server, Resource, Priority, Presence, Info) ->
|
||||
set_session(SID, User, Server, Resource, Priority, Info),
|
||||
ejabberd_hooks:run(set_presence_hook, jlib:nameprep(Server),
|
||||
[User, Server, Resource, Presence]).
|
||||
set_presence(SID, JID, Priority, Presence, Info) when ?IS_JID(JID) ->
|
||||
set_session(SID, JID, Priority, Info),
|
||||
ejabberd_hooks:run(set_presence_hook,
|
||||
exmpp_jid:prep_domain(JID),
|
||||
[exmpp_jid:prep_node(JID),
|
||||
exmpp_jid:prep_domain(JID),
|
||||
exmpp_jid:prep_resource(JID),
|
||||
Presence]).
|
||||
|
||||
unset_presence(SID, User, Server, Resource, Status, Info) ->
|
||||
set_session(SID, User, Server, Resource, undefined, Info),
|
||||
ejabberd_hooks:run(unset_presence_hook, jlib:nameprep(Server),
|
||||
[User, Server, Resource, Status]).
|
||||
unset_presence(SID, JID, Status, Info) when ?IS_JID(JID)->
|
||||
set_session(SID, JID, undefined, Info),
|
||||
ejabberd_hooks:run(unset_presence_hook,
|
||||
exmpp_jid:prep_domain(JID),
|
||||
[exmpp_jid:prep_node(JID),
|
||||
exmpp_jid:prep_domain(JID),
|
||||
exmpp_jid:prep_resource(JID),
|
||||
Status]).
|
||||
|
||||
close_session_unset_presence(SID, User, Server, Resource, Status) ->
|
||||
close_session(SID, User, Server, Resource),
|
||||
ejabberd_hooks:run(unset_presence_hook, jlib:nameprep(Server),
|
||||
[User, Server, Resource, Status]).
|
||||
close_session_unset_presence(SID, JID, Status) when ?IS_JID(JID) ->
|
||||
close_session(SID, JID),
|
||||
ejabberd_hooks:run(unset_presence_hook,
|
||||
exmpp_jid:prep_domain(JID),
|
||||
[exmpp_jid:prep_node(JID),
|
||||
exmpp_jid:prep_domain(JID),
|
||||
exmpp_jid:prep_resource(JID),
|
||||
Status]).
|
||||
|
||||
get_session_pid(User, Server, Resource) ->
|
||||
LUser = jlib:nodeprep(User),
|
||||
LServer = jlib:nameprep(Server),
|
||||
LResource = jlib:resourceprep(Resource),
|
||||
USR = {LUser, LServer, LResource},
|
||||
case catch mnesia:dirty_index_read(session, USR, #session.usr) of
|
||||
get_session_pid(JID) when ?IS_JID(JID) ->
|
||||
get_session_pid({exmpp_jid:prep_node(JID),
|
||||
exmpp_jid:prep_domain(JID),
|
||||
exmpp_jid:prep_resource(JID)});
|
||||
get_session_pid({LUser, LServer, _} = USR) ->
|
||||
Res = case ejabberd_cluster:get_node({LUser, LServer}) of
|
||||
Node when Node == node() ->
|
||||
mnesia:dirty_index_read(session, USR, #session.usr);
|
||||
Node ->
|
||||
catch rpc:call(Node, mnesia, dirty_index_read,
|
||||
[session, USR, #session.usr], 5000)
|
||||
end,
|
||||
case Res of
|
||||
[#session{sid = {_, Pid}}] -> Pid;
|
||||
_ -> none
|
||||
end.
|
||||
|
||||
dirty_get_sessions_list() ->
|
||||
mnesia:dirty_select(
|
||||
session,
|
||||
[{#session{usr = '$1', _ = '_'},
|
||||
[],
|
||||
['$1']}]).
|
||||
Match = [{#session{usr = '$1', _ = '_'}, [], ['$1']}],
|
||||
lists:flatmap(
|
||||
fun(Node) when Node == node() ->
|
||||
mnesia:dirty_select(session, Match);
|
||||
(Node) ->
|
||||
case catch rpc:call(Node, mnesia, dirty_select,
|
||||
[session, Match], 5000) of
|
||||
Ss when is_list(Ss) ->
|
||||
Ss;
|
||||
_ ->
|
||||
[]
|
||||
end
|
||||
end, ejabberd_cluster:get_nodes()).
|
||||
|
||||
dirty_get_my_sessions_list() ->
|
||||
mnesia:dirty_select(
|
||||
session,
|
||||
[{#session{sid = {'_', '$1'}, _ = '_'},
|
||||
[{'==', {node, '$1'}, node()}],
|
||||
['$_']}]).
|
||||
mnesia:dirty_match_object(#session{_ = '_'}).
|
||||
|
||||
get_vh_session_list(Server) ->
|
||||
LServer = jlib:nameprep(Server),
|
||||
get_vh_my_session_list(Server) when is_binary(Server) ->
|
||||
LServer = exmpp_stringprep:nameprep(Server),
|
||||
mnesia:dirty_select(
|
||||
session,
|
||||
[{#session{usr = '$1', _ = '_'},
|
||||
[{'==', {element, 2, '$1'}, LServer}],
|
||||
['$1']}]).
|
||||
|
||||
get_vh_session_list(Server) when is_binary(Server) ->
|
||||
lists:flatmap(
|
||||
fun(Node) when Node == node() ->
|
||||
get_vh_my_session_list(Server);
|
||||
(Node) ->
|
||||
case catch rpc:call(Node, ?MODULE, get_vh_my_session_list,
|
||||
[Server], 5000) of
|
||||
Ss when is_list(Ss) ->
|
||||
Ss;
|
||||
_ ->
|
||||
[]
|
||||
end
|
||||
end, ejabberd_cluster:get_nodes()).
|
||||
|
||||
get_vh_session_number(Server) ->
|
||||
LServer = jlib:nameprep(Server),
|
||||
Query = mnesia:dirty_select(
|
||||
session_counter,
|
||||
[{#session_counter{vhost = LServer, count = '$1'},
|
||||
[],
|
||||
['$1']}]),
|
||||
case Query of
|
||||
[Count] ->
|
||||
Count;
|
||||
_ -> 0
|
||||
end.
|
||||
|
||||
%% TODO
|
||||
length(get_vh_session_list(Server)).
|
||||
|
||||
register_iq_handler(Host, XMLNS, Module, Fun) ->
|
||||
ejabberd_sm ! {register_iq_handler, Host, XMLNS, Module, Fun}.
|
||||
|
||||
@@ -243,6 +316,21 @@ register_iq_handler(Host, XMLNS, Module, Fun, Opts) ->
|
||||
unregister_iq_handler(Host, XMLNS) ->
|
||||
ejabberd_sm ! {unregister_iq_handler, Host, XMLNS}.
|
||||
|
||||
migrate(After) ->
|
||||
Ss = mnesia:dirty_select(
|
||||
session,
|
||||
[{#session{us = '$1', sid = {'_', '$2'}, _ = '_'},
|
||||
[],
|
||||
['$$']}]),
|
||||
lists:foreach(
|
||||
fun([US, Pid]) ->
|
||||
case ejabberd_cluster:get_node_new(US) of
|
||||
Node when Node /= node() ->
|
||||
ejabberd_c2s:migrate(Pid, Node, After);
|
||||
_ ->
|
||||
ok
|
||||
end
|
||||
end, Ss).
|
||||
|
||||
%%====================================================================
|
||||
%% gen_server callbacks
|
||||
@@ -259,23 +347,27 @@ init([]) ->
|
||||
update_tables(),
|
||||
mnesia:create_table(session,
|
||||
[{ram_copies, [node()]},
|
||||
{local_content, true},
|
||||
{attributes, record_info(fields, session)}]),
|
||||
mnesia:create_table(session_counter,
|
||||
[{ram_copies, [node()]},
|
||||
{attributes, record_info(fields, session_counter)}]),
|
||||
mnesia:add_table_index(session, usr),
|
||||
mnesia:add_table_index(session, us),
|
||||
mnesia:add_table_copy(session, node(), ram_copies),
|
||||
mnesia:add_table_copy(session_counter, node(), ram_copies),
|
||||
mnesia:subscribe(system),
|
||||
ets:new(sm_iqtable, [named_table]),
|
||||
ejabberd_hooks:add(roster_in_subscription, global,
|
||||
ejabberd_sm, check_in_subscription, 20),
|
||||
ejabberd_hooks:add(offline_message_hook, global,
|
||||
ejabberd_sm, bounce_offline_message, 100),
|
||||
ejabberd_hooks:add(remove_user, global,
|
||||
ejabberd_sm, disconnect_removed_user, 100),
|
||||
ejabberd_hooks:add(node_hash_update, ?MODULE, migrate, 100),
|
||||
lists:foreach(
|
||||
fun(Host) ->
|
||||
ejabberd_hooks:add(roster_in_subscription, Host,
|
||||
HostB = list_to_binary(Host),
|
||||
ejabberd_hooks:add(roster_in_subscription, HostB,
|
||||
ejabberd_sm, check_in_subscription, 20),
|
||||
ejabberd_hooks:add(offline_message_hook, Host,
|
||||
ejabberd_hooks:add(offline_message_hook, HostB,
|
||||
ejabberd_sm, bounce_offline_message, 100),
|
||||
ejabberd_hooks:add(remove_user, Host,
|
||||
ejabberd_hooks:add(remove_user, HostB,
|
||||
ejabberd_sm, disconnect_removed_user, 100)
|
||||
end, ?MYHOSTS),
|
||||
ejabberd_commands:register_commands(commands()),
|
||||
@@ -310,6 +402,17 @@ handle_cast(_Msg, State) ->
|
||||
%% {stop, Reason, State}
|
||||
%% Description: Handling all non call/cast messages
|
||||
%%--------------------------------------------------------------------
|
||||
%% #xmlelement{} used for retro-compatibility
|
||||
handle_info({route, FromOld, ToOld, #xmlelement{} = PacketOld}, State) ->
|
||||
catch throw(for_stacktrace), % To have a stacktrace.
|
||||
io:format("~nSM: old #xmlelement:~n~p~n~p~n~n",
|
||||
[PacketOld, erlang:get_stacktrace()]),
|
||||
% XXX OLD FORMAT: From, To, Packet.
|
||||
From = jlib:from_old_jid(FromOld),
|
||||
To = jlib:from_old_jid(ToOld),
|
||||
Packet = exmpp_xml:xmlelement_to_xmlel(PacketOld, [?NS_JABBER_CLIENT],
|
||||
[{?NS_XMPP, ?NS_XMPP_pfx}]),
|
||||
handle_info({route, From, To, Packet}, State);
|
||||
handle_info({route, From, To, Packet}, State) ->
|
||||
case catch do_route(From, To, Packet) of
|
||||
{'EXIT', Reason} ->
|
||||
@@ -319,23 +422,20 @@ handle_info({route, From, To, Packet}, State) ->
|
||||
ok
|
||||
end,
|
||||
{noreply, State};
|
||||
handle_info({mnesia_system_event, {mnesia_down, Node}}, State) ->
|
||||
recount_session_table(Node),
|
||||
{noreply, State};
|
||||
handle_info({register_iq_handler, Host, XMLNS, Module, Function}, State) ->
|
||||
ets:insert(sm_iqtable, {{XMLNS, Host}, Module, Function}),
|
||||
ets:insert(sm_iqtable, {{XMLNS, ejabberd:normalize_host(Host)}, Module, Function}),
|
||||
{noreply, State};
|
||||
handle_info({register_iq_handler, Host, XMLNS, Module, Function, Opts}, State) ->
|
||||
ets:insert(sm_iqtable, {{XMLNS, Host}, Module, Function, Opts}),
|
||||
ets:insert(sm_iqtable, {{XMLNS, ejabberd:normalize_host(Host)}, Module, Function, Opts}),
|
||||
{noreply, State};
|
||||
handle_info({unregister_iq_handler, Host, XMLNS}, State) ->
|
||||
case ets:lookup(sm_iqtable, {XMLNS, Host}) of
|
||||
case ets:lookup(sm_iqtable, {XMLNS, ejabberd:normalize_host(Host)}) of
|
||||
[{_, Module, Function, Opts}] ->
|
||||
gen_iq_handler:stop_iq_handler(Module, Function, Opts);
|
||||
_ ->
|
||||
ok
|
||||
end,
|
||||
ets:delete(sm_iqtable, {XMLNS, Host}),
|
||||
ets:delete(sm_iqtable, {XMLNS, ejabberd:normalize_host(Host)}),
|
||||
{noreply, State};
|
||||
handle_info(_Info, State) ->
|
||||
{noreply, State}.
|
||||
@@ -348,6 +448,7 @@ handle_info(_Info, State) ->
|
||||
%% The return value is ignored.
|
||||
%%--------------------------------------------------------------------
|
||||
terminate(_Reason, _State) ->
|
||||
ejabberd_hooks:delete(node_hash_update, ?MODULE, migrate, 100),
|
||||
ejabberd_commands:unregister_commands(commands()),
|
||||
ok.
|
||||
|
||||
@@ -362,12 +463,11 @@ code_change(_OldVsn, State, _Extra) ->
|
||||
%%% Internal functions
|
||||
%%--------------------------------------------------------------------
|
||||
|
||||
set_session(SID, User, Server, Resource, Priority, Info) ->
|
||||
LUser = jlib:nodeprep(User),
|
||||
LServer = jlib:nameprep(Server),
|
||||
LResource = jlib:resourceprep(Resource),
|
||||
US = {LUser, LServer},
|
||||
USR = {LUser, LServer, LResource},
|
||||
set_session(SID, JID, Priority, Info) ->
|
||||
US = {exmpp_jid:prep_node(JID), exmpp_jid:prep_domain(JID)},
|
||||
USR = {exmpp_jid:prep_node(JID),
|
||||
exmpp_jid:prep_domain(JID),
|
||||
exmpp_jid:prep_resource(JID)},
|
||||
F = fun() ->
|
||||
mnesia:write(#session{sid = SID,
|
||||
usr = USR,
|
||||
@@ -377,127 +477,106 @@ set_session(SID, User, Server, Resource, Priority, Info) ->
|
||||
end,
|
||||
mnesia:sync_dirty(F).
|
||||
|
||||
%% Recalculates alive sessions when Node goes down
|
||||
%% and updates session and session_counter tables
|
||||
recount_session_table(Node) ->
|
||||
F = fun() ->
|
||||
Es = mnesia:select(
|
||||
session,
|
||||
[{#session{sid = {'_', '$1'}, _ = '_'},
|
||||
[{'==', {node, '$1'}, Node}],
|
||||
['$_']}]),
|
||||
lists:foreach(fun(E) ->
|
||||
mnesia:delete({session, E#session.sid})
|
||||
end, Es),
|
||||
%% reset session_counter table with active sessions
|
||||
mnesia:clear_table(session_counter),
|
||||
lists:foreach(fun(Server) ->
|
||||
LServer = jlib:nameprep(Server),
|
||||
Hs = mnesia:select(session,
|
||||
[{#session{usr = '$1', _ = '_'},
|
||||
[{'==', {element, 2, '$1'}, LServer}],
|
||||
['$1']}]),
|
||||
mnesia:write(
|
||||
#session_counter{vhost = LServer,
|
||||
count = length(Hs)})
|
||||
end, ?MYHOSTS)
|
||||
end,
|
||||
mnesia:async_dirty(F).
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
do_route(From, To, Packet) ->
|
||||
?DEBUG("session manager~n\tfrom ~p~n\tto ~p~n\tpacket ~P~n",
|
||||
[From, To, Packet, 8]),
|
||||
#jid{user = User, server = Server,
|
||||
luser = LUser, lserver = LServer, lresource = LResource} = To,
|
||||
{xmlelement, Name, Attrs, _Els} = Packet,
|
||||
case LResource of
|
||||
"" ->
|
||||
case Name of
|
||||
"presence" ->
|
||||
{U, S} = {exmpp_jid:prep_node(To), exmpp_jid:prep_domain(To)},
|
||||
case ejabberd_cluster:get_node({U, S}) of
|
||||
Node when Node /= node() ->
|
||||
{?MODULE, Node} ! {route, From, To, Packet};
|
||||
_ ->
|
||||
do_route1(From, To, Packet)
|
||||
end.
|
||||
|
||||
do_route1(From, To, Packet) ->
|
||||
case exmpp_jid:prep_resource(To) of
|
||||
undefined ->
|
||||
case Packet of
|
||||
_ when ?IS_PRESENCE(Packet) ->
|
||||
{Pass, _Subsc} =
|
||||
case xml:get_attr_s("type", Attrs) of
|
||||
"subscribe" ->
|
||||
Reason = xml:get_path_s(
|
||||
Packet,
|
||||
[{elem, "status"}, cdata]),
|
||||
case exmpp_presence:get_type(Packet) of
|
||||
'subscribe' ->
|
||||
Reason = exmpp_presence:get_status(Packet),
|
||||
{is_privacy_allow(From, To, Packet) andalso
|
||||
ejabberd_hooks:run_fold(
|
||||
roster_in_subscription,
|
||||
LServer,
|
||||
exmpp_jid:prep_domain(To),
|
||||
false,
|
||||
[User, Server, From, subscribe, Reason]),
|
||||
[exmpp_jid:prep_node(To), exmpp_jid:prep_domain(To), From, subscribe, Reason]),
|
||||
true};
|
||||
"subscribed" ->
|
||||
'subscribed' ->
|
||||
{is_privacy_allow(From, To, Packet) andalso
|
||||
ejabberd_hooks:run_fold(
|
||||
roster_in_subscription,
|
||||
LServer,
|
||||
exmpp_jid:prep_domain(To),
|
||||
false,
|
||||
[User, Server, From, subscribed, ""]),
|
||||
[exmpp_jid:prep_node(To), exmpp_jid:prep_domain(To), From, subscribed, <<>>]),
|
||||
true};
|
||||
"unsubscribe" ->
|
||||
'unsubscribe' ->
|
||||
{is_privacy_allow(From, To, Packet) andalso
|
||||
ejabberd_hooks:run_fold(
|
||||
roster_in_subscription,
|
||||
LServer,
|
||||
exmpp_jid:prep_domain(To),
|
||||
false,
|
||||
[User, Server, From, unsubscribe, ""]),
|
||||
[exmpp_jid:prep_node(To), exmpp_jid:prep_domain(To), From, unsubscribe, <<>>]),
|
||||
true};
|
||||
"unsubscribed" ->
|
||||
'unsubscribed' ->
|
||||
{is_privacy_allow(From, To, Packet) andalso
|
||||
ejabberd_hooks:run_fold(
|
||||
roster_in_subscription,
|
||||
LServer,
|
||||
exmpp_jid:prep_domain(To),
|
||||
false,
|
||||
[User, Server, From, unsubscribed, ""]),
|
||||
[exmpp_jid:prep_node(To), exmpp_jid:prep_domain(To), From, unsubscribed, <<>>]),
|
||||
true};
|
||||
_ ->
|
||||
{true, false}
|
||||
end,
|
||||
if Pass ->
|
||||
PResources = get_user_present_resources(
|
||||
LUser, LServer),
|
||||
exmpp_jid:prep_node(To), exmpp_jid:prep_domain(To)),
|
||||
lists:foreach(
|
||||
fun({_, R}) ->
|
||||
do_route(
|
||||
From,
|
||||
jlib:jid_replace_resource(To, R),
|
||||
exmpp_jid:full(To, R),
|
||||
Packet)
|
||||
end, PResources);
|
||||
true ->
|
||||
ok
|
||||
end;
|
||||
"message" ->
|
||||
_ when ?IS_MESSAGE(Packet) ->
|
||||
route_message(From, To, Packet);
|
||||
"iq" ->
|
||||
_ when ?IS_IQ(Packet) ->
|
||||
process_iq(From, To, Packet);
|
||||
"broadcast" ->
|
||||
#xmlel{name = 'broadcast'} ->
|
||||
lists:foreach(
|
||||
fun(R) ->
|
||||
do_route(From,
|
||||
jlib:jid_replace_resource(To, R),
|
||||
exmpp_jid:full(To, R),
|
||||
Packet)
|
||||
end, get_user_resources(User, Server));
|
||||
end, get_user_resources(exmpp_jid:prep_node(To),
|
||||
exmpp_jid:prep_domain(To)));
|
||||
_ ->
|
||||
ok
|
||||
end;
|
||||
_ ->
|
||||
USR = {LUser, LServer, LResource},
|
||||
USR = {exmpp_jid:prep_node(To),
|
||||
exmpp_jid:prep_domain(To),
|
||||
exmpp_jid:prep_resource(To)},
|
||||
case mnesia:dirty_index_read(session, USR, #session.usr) of
|
||||
[] ->
|
||||
case Name of
|
||||
"message" ->
|
||||
case Packet of
|
||||
_ when ?IS_MESSAGE(Packet) ->
|
||||
route_message(From, To, Packet);
|
||||
"iq" ->
|
||||
case xml:get_attr_s("type", Attrs) of
|
||||
"error" -> ok;
|
||||
"result" -> ok;
|
||||
_ when ?IS_IQ(Packet) ->
|
||||
case exmpp_iq:get_type(Packet) of
|
||||
'error' -> ok;
|
||||
'result' -> ok;
|
||||
_ ->
|
||||
Err =
|
||||
jlib:make_error_reply(
|
||||
Packet, ?ERR_SERVICE_UNAVAILABLE),
|
||||
exmpp_iq:error(Packet,
|
||||
'service-unavailable'),
|
||||
ejabberd_router:route(To, From, Err)
|
||||
end;
|
||||
_ ->
|
||||
@@ -516,8 +595,8 @@ do_route(From, To, Packet) ->
|
||||
%% for the target session/resource to which a stanza is addressed,
|
||||
%% or if there are no current sessions for the user.
|
||||
is_privacy_allow(From, To, Packet) ->
|
||||
User = To#jid.user,
|
||||
Server = To#jid.server,
|
||||
User = exmpp_jid:prep_node(To),
|
||||
Server = exmpp_jid:prep_domain(To),
|
||||
PrivacyList = ejabberd_hooks:run_fold(privacy_get_user_list, Server,
|
||||
#userlist{}, [User, Server]),
|
||||
is_privacy_allow(From, To, Packet, PrivacyList).
|
||||
@@ -525,8 +604,8 @@ is_privacy_allow(From, To, Packet) ->
|
||||
%% Check if privacy rules allow this delivery
|
||||
%% Function copied from ejabberd_c2s.erl
|
||||
is_privacy_allow(From, To, Packet, PrivacyList) ->
|
||||
User = To#jid.user,
|
||||
Server = To#jid.server,
|
||||
User = exmpp_jid:prep_node(To),
|
||||
Server = exmpp_jid:prep_domain(To),
|
||||
allow == ejabberd_hooks:run_fold(
|
||||
privacy_check_packet, Server,
|
||||
allow,
|
||||
@@ -537,8 +616,8 @@ is_privacy_allow(From, To, Packet, PrivacyList) ->
|
||||
in]).
|
||||
|
||||
route_message(From, To, Packet) ->
|
||||
LUser = To#jid.luser,
|
||||
LServer = To#jid.lserver,
|
||||
LUser = exmpp_jid:prep_node(To),
|
||||
LServer = exmpp_jid:prep_domain(To),
|
||||
PrioRes = get_user_present_resources(LUser, LServer),
|
||||
case catch lists:max(PrioRes) of
|
||||
{Priority, _R} when is_integer(Priority), Priority >= 0 ->
|
||||
@@ -546,8 +625,7 @@ route_message(From, To, Packet) ->
|
||||
%% Route messages to all priority that equals the max, if
|
||||
%% positive
|
||||
fun({P, R}) when P == Priority ->
|
||||
LResource = jlib:resourceprep(R),
|
||||
USR = {LUser, LServer, LResource},
|
||||
USR = {LUser, LServer, R},
|
||||
case mnesia:dirty_index_read(session, USR, #session.usr) of
|
||||
[] ->
|
||||
ok; % Race condition
|
||||
@@ -563,27 +641,28 @@ route_message(From, To, Packet) ->
|
||||
end,
|
||||
PrioRes);
|
||||
_ ->
|
||||
case xml:get_tag_attr_s("type", Packet) of
|
||||
"error" ->
|
||||
case exmpp_message:get_type(Packet) of
|
||||
'error' ->
|
||||
ok;
|
||||
"groupchat" ->
|
||||
'groupchat' ->
|
||||
bounce_offline_message(From, To, Packet);
|
||||
"headline" ->
|
||||
'headline' ->
|
||||
bounce_offline_message(From, To, Packet);
|
||||
_ ->
|
||||
case ejabberd_auth:is_user_exists(LUser, LServer) of
|
||||
case ejabberd_auth:is_user_exists(exmpp_jid:prep_node_as_list(To),
|
||||
exmpp_jid:prep_domain_as_list(To)) of
|
||||
true ->
|
||||
case is_privacy_allow(From, To, Packet) of
|
||||
true ->
|
||||
ejabberd_hooks:run(offline_message_hook,
|
||||
LServer,
|
||||
exmpp_jid:prep_domain(To),
|
||||
[From, To, Packet]);
|
||||
false ->
|
||||
ok
|
||||
end;
|
||||
_ ->
|
||||
Err = jlib:make_error_reply(
|
||||
Packet, ?ERR_SERVICE_UNAVAILABLE),
|
||||
Err = exmpp_stanza:reply_with_error(
|
||||
Packet, 'service-unaivailable'),
|
||||
ejabberd_router:route(To, From, Err)
|
||||
end
|
||||
end
|
||||
@@ -628,18 +707,16 @@ get_user_present_resources(LUser, LServer) ->
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
%% On new session, check if some existing connections need to be replace
|
||||
check_for_sessions_to_replace(User, Server, Resource) ->
|
||||
LUser = jlib:nodeprep(User),
|
||||
LServer = jlib:nameprep(Server),
|
||||
LResource = jlib:resourceprep(Resource),
|
||||
|
||||
check_for_sessions_to_replace(JID) ->
|
||||
%% TODO: Depending on how this is executed, there could be an unneeded
|
||||
%% replacement for max_sessions. We need to check this at some point.
|
||||
check_existing_resources(LUser, LServer, LResource),
|
||||
check_max_sessions(LUser, LServer).
|
||||
check_existing_resources(JID),
|
||||
check_max_sessions(JID).
|
||||
|
||||
check_existing_resources(LUser, LServer, LResource) ->
|
||||
USR = {LUser, LServer, LResource},
|
||||
check_existing_resources(JID) ->
|
||||
USR = {exmpp_jid:prep_node(JID),
|
||||
exmpp_jid:prep_domain(JID),
|
||||
exmpp_jid:prep_resource(JID)},
|
||||
%% A connection exist with the same resource. We replace it:
|
||||
SIDs = mnesia:dirty_select(
|
||||
session,
|
||||
@@ -655,14 +732,16 @@ check_existing_resources(LUser, LServer, LResource) ->
|
||||
end, SIDs)
|
||||
end.
|
||||
|
||||
check_max_sessions(LUser, LServer) ->
|
||||
check_max_sessions(JID) ->
|
||||
%% If the max number of sessions for a given is reached, we replace the
|
||||
%% first one
|
||||
SIDs = mnesia:dirty_select(
|
||||
session,
|
||||
[{#session{sid = '$1', us = {LUser, LServer}, _ = '_'}, [],
|
||||
[{#session{sid = '$1',
|
||||
us = {exmpp_jid:prep_node(JID), exmpp_jid:prep_domain(JID)},
|
||||
_ = '_'}, [],
|
||||
['$1']}]),
|
||||
MaxSessions = get_max_user_sessions(LUser, LServer),
|
||||
MaxSessions = get_max_user_sessions(JID),
|
||||
if
|
||||
length(SIDs) =< MaxSessions ->
|
||||
ok;
|
||||
@@ -676,9 +755,9 @@ check_max_sessions(LUser, LServer) ->
|
||||
%% This option defines the max number of time a given users are allowed to
|
||||
%% log in
|
||||
%% Defaults to infinity
|
||||
get_max_user_sessions(LUser, Host) ->
|
||||
get_max_user_sessions(JID) ->
|
||||
case acl:match_rule(
|
||||
Host, max_user_sessions, jlib:make_jid(LUser, Host, "")) of
|
||||
exmpp_jid:prep_domain_as_list(JID), max_user_sessions, exmpp_jid:bare(JID)) of
|
||||
Max when is_integer(Max) -> Max;
|
||||
infinity -> infinity;
|
||||
_ -> ?MAX_USER_SESSIONS
|
||||
@@ -687,32 +766,36 @@ get_max_user_sessions(LUser, Host) ->
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
process_iq(From, To, Packet) ->
|
||||
IQ = jlib:iq_query_info(Packet),
|
||||
case IQ of
|
||||
#iq{xmlns = XMLNS} ->
|
||||
Host = To#jid.lserver,
|
||||
case ets:lookup(sm_iqtable, {XMLNS, Host}) of
|
||||
case exmpp_iq:xmlel_to_iq(Packet) of
|
||||
#iq{kind = request, ns = XMLNS} = IQ_Rec ->
|
||||
LServer = exmpp_jid:prep_domain(To),
|
||||
case ets:lookup(sm_iqtable, {XMLNS, ejabberd:normalize_host(LServer)}) of
|
||||
[{_, Module, Function}] ->
|
||||
ResIQ = Module:Function(From, To, IQ),
|
||||
ResIQ = Module:Function(From, To, IQ_Rec),
|
||||
if
|
||||
ResIQ /= ignore ->
|
||||
ejabberd_router:route(To, From,
|
||||
jlib:iq_to_xml(ResIQ));
|
||||
Reply = exmpp_iq:iq_to_xmlel(ResIQ, To, From),
|
||||
ejabberd_router:route(To, From, Reply);
|
||||
true ->
|
||||
ok
|
||||
end;
|
||||
[{_, Module, Function, Opts}] ->
|
||||
gen_iq_handler:handle(Host, Module, Function, Opts,
|
||||
From, To, IQ);
|
||||
gen_iq_handler:handle(LServer,
|
||||
Module, Function, Opts, From, To, IQ_Rec);
|
||||
[] ->
|
||||
Err = jlib:make_error_reply(
|
||||
Packet, ?ERR_SERVICE_UNAVAILABLE),
|
||||
ejabberd_router:route(To, From, Err)
|
||||
case ets:lookup(sm_iqtable, {XMLNS, global}) of
|
||||
[{_, Module, Function, Opts}] ->
|
||||
gen_iq_handler:handle(global, Module, Function, Opts,
|
||||
From, To, IQ_Rec);
|
||||
[] ->
|
||||
Err = exmpp_iq:error(Packet, 'service-unavailable'),
|
||||
ejabberd_router:route(To, From, Err)
|
||||
end
|
||||
end;
|
||||
reply ->
|
||||
#iq{kind = response} ->
|
||||
ok;
|
||||
_ ->
|
||||
Err = jlib:make_error_reply(Packet, ?ERR_BAD_REQUEST),
|
||||
Err = exmpp_iq:error(Packet, 'bad-request'),
|
||||
ejabberd_router:route(To, From, Err),
|
||||
ok
|
||||
end.
|
||||
@@ -762,7 +845,8 @@ connected_users_number() ->
|
||||
length(dirty_get_sessions_list()).
|
||||
|
||||
user_resources(User, Server) ->
|
||||
Resources = get_user_resources(User, Server),
|
||||
Resources = get_user_resources(list_to_binary(User),
|
||||
list_to_binary(Server)),
|
||||
lists:sort(Resources).
|
||||
|
||||
|
||||
@@ -795,4 +879,11 @@ update_tables() ->
|
||||
mnesia:delete_table(local_session);
|
||||
false ->
|
||||
ok
|
||||
end,
|
||||
mnesia:delete_table(session_counter),
|
||||
case catch mnesia:table_info(session, local_content) of
|
||||
false ->
|
||||
mnesia:delete_table(session);
|
||||
_ ->
|
||||
ok
|
||||
end.
|
||||
|
||||
@@ -44,9 +44,12 @@
|
||||
get_peer_certificate/1,
|
||||
get_verify_result/1,
|
||||
close/1,
|
||||
change_controller/2,
|
||||
gethostname/1,
|
||||
sockname/1, peername/1]).
|
||||
|
||||
-include("ejabberd.hrl").
|
||||
-include_lib("kernel/include/inet.hrl").
|
||||
|
||||
-record(socket_state, {sockmod, socket, receiver}).
|
||||
|
||||
@@ -87,13 +90,7 @@ start(Module, SockMod, Socket, Opts) ->
|
||||
end,
|
||||
ReceiverMod:become_controller(Receiver, Pid);
|
||||
{error, _Reason} ->
|
||||
SockMod:close(Socket),
|
||||
case ReceiverMod of
|
||||
ejabberd_receiver ->
|
||||
ReceiverMod:close(Receiver);
|
||||
_ ->
|
||||
ok
|
||||
end
|
||||
SockMod:close(Socket)
|
||||
end;
|
||||
independent ->
|
||||
ok;
|
||||
@@ -135,29 +132,19 @@ connect(Addr, Port, Opts, Timeout) ->
|
||||
end.
|
||||
|
||||
starttls(SocketData, TLSOpts) ->
|
||||
{ok, TLSSocket} = tls:tcp_to_tls(SocketData#socket_state.socket, TLSOpts),
|
||||
ejabberd_receiver:starttls(SocketData#socket_state.receiver, TLSSocket),
|
||||
SocketData#socket_state{socket = TLSSocket, sockmod = tls}.
|
||||
starttls(SocketData, TLSOpts, undefined).
|
||||
|
||||
starttls(SocketData, TLSOpts, Data) ->
|
||||
{ok, TLSSocket} = tls:tcp_to_tls(SocketData#socket_state.socket, TLSOpts),
|
||||
ejabberd_receiver:starttls(SocketData#socket_state.receiver, TLSSocket),
|
||||
send(SocketData, Data),
|
||||
{ok, TLSSocket} = ejabberd_receiver:starttls(
|
||||
SocketData#socket_state.receiver, TLSOpts, Data),
|
||||
SocketData#socket_state{socket = TLSSocket, sockmod = tls}.
|
||||
|
||||
compress(SocketData) ->
|
||||
{ok, ZlibSocket} = ejabberd_zlib:enable_zlib(
|
||||
SocketData#socket_state.sockmod,
|
||||
SocketData#socket_state.socket),
|
||||
ejabberd_receiver:compress(SocketData#socket_state.receiver, ZlibSocket),
|
||||
SocketData#socket_state{socket = ZlibSocket, sockmod = ejabberd_zlib}.
|
||||
compress(SocketData, undefined).
|
||||
|
||||
compress(SocketData, Data) ->
|
||||
{ok, ZlibSocket} = ejabberd_zlib:enable_zlib(
|
||||
SocketData#socket_state.sockmod,
|
||||
SocketData#socket_state.socket),
|
||||
ejabberd_receiver:compress(SocketData#socket_state.receiver, ZlibSocket),
|
||||
send(SocketData, Data),
|
||||
{ok, ZlibSocket} = ejabberd_receiver:compress(
|
||||
SocketData#socket_state.receiver, Data),
|
||||
SocketData#socket_state{socket = ZlibSocket, sockmod = ejabberd_zlib}.
|
||||
|
||||
reset_stream(SocketData) when is_pid(SocketData#socket_state.receiver) ->
|
||||
@@ -166,10 +153,25 @@ reset_stream(SocketData) when is_atom(SocketData#socket_state.receiver) ->
|
||||
(SocketData#socket_state.receiver):reset_stream(
|
||||
SocketData#socket_state.socket).
|
||||
|
||||
change_controller(#socket_state{receiver = Recv}, Pid) when is_pid(Recv) ->
|
||||
ejabberd_receiver:setopts(Recv, [{active, false}]),
|
||||
sync_events(Pid),
|
||||
ejabberd_receiver:change_controller(Recv, Pid);
|
||||
change_controller(#socket_state{socket = Socket, receiver = Mod}, Pid) ->
|
||||
Mod:setopts(Socket, [{active, false}]),
|
||||
sync_events(Pid),
|
||||
Mod:change_controller(Socket, Pid).
|
||||
|
||||
%% sockmod=gen_tcp|tls|ejabberd_zlib
|
||||
send(SocketData, Data) ->
|
||||
case catch (SocketData#socket_state.sockmod):send(
|
||||
SocketData#socket_state.socket, Data) of
|
||||
Res = if node(SocketData#socket_state.receiver) == node() ->
|
||||
catch (SocketData#socket_state.sockmod):send(
|
||||
SocketData#socket_state.socket, Data);
|
||||
true ->
|
||||
catch ejabberd_receiver:send(
|
||||
SocketData#socket_state.receiver, Data)
|
||||
end,
|
||||
case Res of
|
||||
ok -> ok;
|
||||
{error, timeout} ->
|
||||
?INFO_MSG("Timeout on ~p:send",[SocketData#socket_state.sockmod]),
|
||||
@@ -228,6 +230,41 @@ peername(#socket_state{sockmod = SockMod, socket = Socket}) ->
|
||||
SockMod:peername(Socket)
|
||||
end.
|
||||
|
||||
gethostname(#socket_state{socket = Socket} = State) ->
|
||||
?DEBUG("gethostname ~p~n", [Socket]),
|
||||
|
||||
case sockname(State) of
|
||||
{ok, {Addr, _Port}} ->
|
||||
case inet:gethostbyaddr(Addr) of
|
||||
{ok, HostEnt} when is_record(HostEnt, hostent) ->
|
||||
?DEBUG("gethostname result ~p~n",
|
||||
[HostEnt#hostent.h_name]),
|
||||
{ok, HostEnt#hostent.h_name};
|
||||
{error, _Reason} = E ->
|
||||
E
|
||||
end;
|
||||
{error, _Reason} = E ->
|
||||
E
|
||||
end.
|
||||
|
||||
%%====================================================================
|
||||
%% Internal functions
|
||||
%%====================================================================
|
||||
%% dirty hack to relay queued messages from
|
||||
%% old owner to new owner. The idea is based
|
||||
%% on code of gen_tcp:controlling_process/2.
|
||||
sync_events(C2SPid) ->
|
||||
receive
|
||||
{'$gen_event', El} = Event when element(1, El) == xmlel;
|
||||
element(1, El) == xmlstreamstart;
|
||||
element(1, El) == xmlstreamelement;
|
||||
element(1, El) == xmlstreamend;
|
||||
element(1, El) == xmlstreamerror ->
|
||||
C2SPid ! Event,
|
||||
sync_events(C2SPid);
|
||||
closed ->
|
||||
C2SPid ! closed,
|
||||
sync_events(C2SPid)
|
||||
after 0 ->
|
||||
ok
|
||||
end.
|
||||
|
||||
@@ -42,20 +42,13 @@ init([]) ->
|
||||
brutal_kill,
|
||||
worker,
|
||||
[ejabberd_hooks]},
|
||||
NodeGroups =
|
||||
{ejabberd_node_groups,
|
||||
{ejabberd_node_groups, start_link, []},
|
||||
GlobalRouter =
|
||||
{ejabberd_global_router,
|
||||
{ejabberd_global_router, start_link, []},
|
||||
permanent,
|
||||
brutal_kill,
|
||||
worker,
|
||||
[ejabberd_node_groups]},
|
||||
SystemMonitor =
|
||||
{ejabberd_system_monitor,
|
||||
{ejabberd_system_monitor, start_link, []},
|
||||
permanent,
|
||||
brutal_kill,
|
||||
worker,
|
||||
[ejabberd_system_monitor]},
|
||||
[ejabberd_global_router]},
|
||||
Router =
|
||||
{ejabberd_router,
|
||||
{ejabberd_router, start_link, []},
|
||||
@@ -63,6 +56,13 @@ init([]) ->
|
||||
brutal_kill,
|
||||
worker,
|
||||
[ejabberd_router]},
|
||||
Router_multicast =
|
||||
{ejabberd_router_multicast,
|
||||
{ejabberd_router_multicast, start_link, []},
|
||||
permanent,
|
||||
brutal_kill,
|
||||
worker,
|
||||
[ejabberd_router_multicast]},
|
||||
SM =
|
||||
{ejabberd_sm,
|
||||
{ejabberd_sm, start_link, []},
|
||||
@@ -137,6 +137,13 @@ init([]) ->
|
||||
infinity,
|
||||
supervisor,
|
||||
[ejabberd_tmp_sup]},
|
||||
Hosts =
|
||||
{ejabberd_hosts,
|
||||
{ejabberd_hosts, start_link, []},
|
||||
permanent,
|
||||
brutal_kill,
|
||||
worker,
|
||||
[ejabberd_hosts]},
|
||||
HTTPSupervisor =
|
||||
{ejabberd_http_sup,
|
||||
{ejabberd_tmp_sup, start_link,
|
||||
@@ -177,18 +184,19 @@ init([]) ->
|
||||
infinity,
|
||||
supervisor,
|
||||
[ejabberd_tmp_sup]},
|
||||
CacheTabSupervisor =
|
||||
{cache_tab_sup,
|
||||
{cache_tab_sup, start_link, []},
|
||||
Cluster =
|
||||
{ejabberd_cluster,
|
||||
{ejabberd_cluster, start_link, []},
|
||||
permanent,
|
||||
infinity,
|
||||
supervisor,
|
||||
[cache_tab_sup]},
|
||||
brutal_kill,
|
||||
worker,
|
||||
[ejabberd_cluster]},
|
||||
{ok, {{one_for_one, 10, 1},
|
||||
[Hooks,
|
||||
NodeGroups,
|
||||
SystemMonitor,
|
||||
GlobalRouter,
|
||||
Cluster,
|
||||
Router,
|
||||
Router_multicast,
|
||||
SM,
|
||||
S2S,
|
||||
Local,
|
||||
@@ -198,12 +206,12 @@ init([]) ->
|
||||
S2SInSupervisor,
|
||||
S2SOutSupervisor,
|
||||
ServiceSupervisor,
|
||||
Hosts,
|
||||
HTTPSupervisor,
|
||||
HTTPPollSupervisor,
|
||||
IQSupervisor,
|
||||
STUNSupervisor,
|
||||
FrontendSocketSupervisor,
|
||||
CacheTabSupervisor,
|
||||
Listener]}}.
|
||||
|
||||
|
||||
|
||||
@@ -38,8 +38,9 @@
|
||||
-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
|
||||
terminate/2, code_change/3]).
|
||||
|
||||
-include_lib("exmpp/include/exmpp.hrl").
|
||||
|
||||
-include("ejabberd.hrl").
|
||||
-include("jlib.hrl").
|
||||
|
||||
-record(state, {}).
|
||||
|
||||
@@ -59,16 +60,16 @@ end,
|
||||
gen_server:start_link({local, ?MODULE}, ?MODULE, Opts, []).
|
||||
|
||||
process_command(From, To, Packet) ->
|
||||
case To of
|
||||
#jid{luser = "", lresource = "watchdog"} ->
|
||||
{xmlelement, Name, _Attrs, _Els} = Packet,
|
||||
case Name of
|
||||
"message" ->
|
||||
LFrom = jlib:jid_tolower(jlib:jid_remove_resource(From)),
|
||||
case lists:member(LFrom, get_admin_jids()) of
|
||||
case {exmpp_jid:prep_node(To), exmpp_jid:prep_resource(To) } of
|
||||
{undefined, <<"watchdog">>} ->
|
||||
case Packet#xmlel.name of
|
||||
'message' ->
|
||||
case lists:any(fun(J) ->
|
||||
exmpp_jid:compare(J,From)
|
||||
end, get_admin_jids()) of
|
||||
true ->
|
||||
Body = xml:get_path_s(
|
||||
Packet, [{elem, "body"}, cdata]),
|
||||
Body = exmpp_xml:get_path(
|
||||
Packet, [{element, 'body'}, cdata_as_list]),
|
||||
spawn(fun() ->
|
||||
process_flag(priority, high),
|
||||
process_command1(From, To, Body)
|
||||
@@ -101,7 +102,8 @@ init(Opts) ->
|
||||
erlang:system_monitor(self(), [{large_heap, LH}]),
|
||||
lists:foreach(
|
||||
fun(Host) ->
|
||||
ejabberd_hooks:add(local_send_to_resource_hook, Host,
|
||||
ejabberd_hooks:add(local_send_to_resource_hook,
|
||||
list_to_binary(Host),
|
||||
?MODULE, process_command, 50)
|
||||
end, ?MYHOSTS),
|
||||
{ok, #state{}}.
|
||||
@@ -188,13 +190,15 @@ process_large_heap(Pid, Info) ->
|
||||
"(~w) The process ~w is consuming too much memory:~n~p~n"
|
||||
"~s",
|
||||
[node(), Pid, Info, DetailedInfo]),
|
||||
From = jlib:make_jid("", Host, "watchdog"),
|
||||
From = exmpp_jid:make(undefined, Host, <<"watchdog">>),
|
||||
lists:foreach(
|
||||
fun(S) ->
|
||||
case jlib:string_to_jid(S) of
|
||||
error -> ok;
|
||||
JID ->
|
||||
send_message(From, JID, Body)
|
||||
try
|
||||
JID = exmpp_jid:parse(S),
|
||||
send_message(From, JID, Body)
|
||||
catch
|
||||
_ ->
|
||||
ok
|
||||
end
|
||||
end, JIDs);
|
||||
_ ->
|
||||
@@ -204,18 +208,21 @@ process_large_heap(Pid, Info) ->
|
||||
send_message(From, To, Body) ->
|
||||
ejabberd_router:route(
|
||||
From, To,
|
||||
{xmlelement, "message", [{"type", "chat"}],
|
||||
[{xmlelement, "body", [],
|
||||
[{xmlcdata, lists:flatten(Body)}]}]}).
|
||||
exmpp_message:chat(lists:flatten(Body))).
|
||||
|
||||
get_admin_jids() ->
|
||||
case ejabberd_config:get_local_option(watchdog_admins) of
|
||||
JIDs when is_list(JIDs) ->
|
||||
lists:flatmap(
|
||||
fun(S) ->
|
||||
case jlib:string_to_jid(S) of
|
||||
error -> [];
|
||||
JID -> [jlib:jid_tolower(JID)]
|
||||
try
|
||||
JID = exmpp_jid:parse(S),
|
||||
[{exmpp_jid:prep_node(JID),
|
||||
exmpp_jid:prep_domain(JID),
|
||||
exmpp_jid:prep_resource(JID)}]
|
||||
catch
|
||||
_ ->
|
||||
[]
|
||||
end
|
||||
end, JIDs);
|
||||
_ ->
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
# $Id$
|
||||
|
||||
CC = @CC@
|
||||
CFLAGS = @CFLAGS@
|
||||
CPPFLAGS = @CPPFLAGS@
|
||||
@@ -61,3 +59,23 @@ distclean: clean
|
||||
|
||||
TAGS:
|
||||
etags *.erl
|
||||
|
||||
|
||||
DEVDOCDIR=../../doc/devdoc
|
||||
DDTDIR=..
|
||||
HTMLS = $(SOURCES:%.erl=../../doc/devdoc/%.html)
|
||||
ERLHTMLS = $(SOURCES:%.erl=../../doc/devdoc/%.erl.html)
|
||||
SVGS = $(SOURCES:%.erl=../../doc/devdoc/%.svg)
|
||||
|
||||
devdoc: $(HTMLS) $(ERLHTMLS) $(SVGS)
|
||||
|
||||
$(DEVDOCDIR)/%.erl.html: %.erl
|
||||
@ERL@ -noshell -pa $(DEVDOCDIR) -run escobar_run file $< $(DDTDIR) -s init stop
|
||||
|
||||
$(DEVDOCDIR)/%.html: %.erl
|
||||
@ERL@ -noshell -run edoc_run file $< \
|
||||
'[{dir,"$(DDTDIR)"},{packages,false},{todo,true},{private,true},{def,{vsn,"$(VSN)"}},{stylesheet,"process-one.css"},{overview,"overview.edoc"}]' -s init stop
|
||||
|
||||
$(DEVDOCDIR)/%.svg: %.erl
|
||||
@ERL@ -noshell -pa $(DEVDOCDIR) -run funrelg dir $< $(DDTDIR) -s init stop
|
||||
|
||||
|
||||
@@ -63,7 +63,7 @@ init([]) ->
|
||||
ok -> ok;
|
||||
{error, already_loaded} -> ok
|
||||
end,
|
||||
Port = open_port({spawn, ejabberd_zlib_drv}, [binary]),
|
||||
Port = open_port({spawn, "ejabberd_zlib_drv"}, [binary]),
|
||||
{ok, Port}.
|
||||
|
||||
|
||||
@@ -99,7 +99,7 @@ enable_zlib(SockMod, Socket) ->
|
||||
ok -> ok;
|
||||
{error, already_loaded} -> ok
|
||||
end,
|
||||
Port = open_port({spawn, ejabberd_zlib_drv}, [binary]),
|
||||
Port = open_port({spawn, "ejabberd_zlib_drv"}, [binary]),
|
||||
{ok, #zlibsock{sockmod = SockMod, socket = Socket, zlibport = Port}}.
|
||||
|
||||
disable_zlib(#zlibsock{sockmod = SockMod, socket = Socket, zlibport = Port}) ->
|
||||
|
||||
@@ -32,15 +32,6 @@ typedef struct {
|
||||
z_stream *i_stream;
|
||||
} ejabberd_zlib_data;
|
||||
|
||||
static void* zlib_alloc(void* data, unsigned int items, unsigned int size)
|
||||
{
|
||||
return (void*) driver_alloc(items*size);
|
||||
}
|
||||
|
||||
static void zlib_free(void* data, void* addr)
|
||||
{
|
||||
driver_free(addr);
|
||||
}
|
||||
|
||||
static ErlDrvData ejabberd_zlib_drv_start(ErlDrvPort port, char *buff)
|
||||
{
|
||||
@@ -48,18 +39,18 @@ static ErlDrvData ejabberd_zlib_drv_start(ErlDrvPort port, char *buff)
|
||||
(ejabberd_zlib_data *)driver_alloc(sizeof(ejabberd_zlib_data));
|
||||
d->port = port;
|
||||
|
||||
d->d_stream = (z_stream *)driver_alloc(sizeof(z_stream));
|
||||
d->d_stream = (z_stream *)malloc(sizeof(z_stream));
|
||||
|
||||
d->d_stream->zalloc = zlib_alloc;
|
||||
d->d_stream->zfree = zlib_free;
|
||||
d->d_stream->zalloc = (alloc_func)0;
|
||||
d->d_stream->zfree = (free_func)0;
|
||||
d->d_stream->opaque = (voidpf)0;
|
||||
|
||||
deflateInit(d->d_stream, Z_DEFAULT_COMPRESSION);
|
||||
|
||||
d->i_stream = (z_stream *)driver_alloc(sizeof(z_stream));
|
||||
d->i_stream = (z_stream *)malloc(sizeof(z_stream));
|
||||
|
||||
d->i_stream->zalloc = zlib_alloc;
|
||||
d->i_stream->zfree = zlib_free;
|
||||
d->i_stream->zalloc = (alloc_func)0;
|
||||
d->i_stream->zfree = (free_func)0;
|
||||
d->i_stream->opaque = (voidpf)0;
|
||||
|
||||
inflateInit(d->i_stream);
|
||||
@@ -74,10 +65,10 @@ static void ejabberd_zlib_drv_stop(ErlDrvData handle)
|
||||
ejabberd_zlib_data *d = (ejabberd_zlib_data *)handle;
|
||||
|
||||
deflateEnd(d->d_stream);
|
||||
driver_free(d->d_stream);
|
||||
free(d->d_stream);
|
||||
|
||||
inflateEnd(d->i_stream);
|
||||
driver_free(d->i_stream);
|
||||
free(d->i_stream);
|
||||
|
||||
driver_free((char *)handle);
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@ while [ $# -ne 0 ] ; do
|
||||
--ctl-config) EJABBERDCTL_CONFIG_PATH=$1 ; shift ;;
|
||||
--logs) LOGS_DIR=$1 ; shift ;;
|
||||
--spool) SPOOLDIR=$1 ; shift ;;
|
||||
--erlargs) ERL_ARGS=$1 ; shift ;;
|
||||
*) ARGS="$ARGS $PARAM" ;;
|
||||
esac
|
||||
done
|
||||
@@ -56,8 +57,9 @@ if [ "$ERLANG_NODE_ARG" != "" ] ; then
|
||||
fi
|
||||
|
||||
# check the proper system user is used
|
||||
ID=`id -g`
|
||||
GIDS=`id -G`
|
||||
if [ `uname -s` = "SunOS" ]; then IDCMD=/usr/xpg4/bin/id; else IDCMD=id; fi
|
||||
ID=`$IDCMD -g`
|
||||
EJID=`$IDCMD -g $INSTALLUSER`
|
||||
EJID=`id -g $INSTALLUSER`
|
||||
EXEC_CMD="false"
|
||||
for GID in $GIDS; do
|
||||
@@ -76,10 +78,13 @@ fi
|
||||
NAME=-name
|
||||
[ "$ERLANG_NODE" = "${ERLANG_NODE%.*}" ] && NAME=-sname
|
||||
|
||||
if [ "$FIREWALL_WINDOW" = "" ] ; then
|
||||
KERNEL_OPTS=""
|
||||
else
|
||||
KERNEL_OPTS="-kernel inet_dist_listen_min ${FIREWALL_WINDOW%-*} inet_dist_listen_max ${FIREWALL_WINDOW#*-}"
|
||||
KERNEL_OPTS=""
|
||||
if [ "$FIREWALL_WINDOW" != "" ] ; then
|
||||
KERNEL_OPTS="${KERNEL_OPTS} -kernel inet_dist_listen_min ${FIREWALL_WINDOW%-*} inet_dist_listen_max ${FIREWALL_WINDOW#*-}"
|
||||
fi
|
||||
|
||||
if [ "$DIST_INTERFACE" != "" ] ; then
|
||||
KERNEL_OPTS="${KERNEL_OPTS} -kernel inet_dist_use_interface \"${DIST_INTERFACE}\""
|
||||
fi
|
||||
|
||||
ERLANG_OPTS="+K $POLL -smp $SMP +P $ERL_PROCESSES $ERL_OPTIONS"
|
||||
@@ -114,10 +119,6 @@ HOME=$SPOOLDIR
|
||||
# create the home dir with the proper user if doesn't exist, because it stores cookie file
|
||||
[ -d $HOME ] || $EXEC_CMD "mkdir -p $HOME"
|
||||
|
||||
# Change to a directory readable by INSTALLUSER to
|
||||
# prevent "File operation error: eacces." messages
|
||||
cd $HOME
|
||||
|
||||
# export global variables
|
||||
export EJABBERD_CONFIG_PATH
|
||||
export EJABBERD_MSGS_PATH
|
||||
@@ -140,6 +141,7 @@ export EXEC_CMD
|
||||
# start server
|
||||
start ()
|
||||
{
|
||||
check_start
|
||||
$EXEC_CMD "$ERL \
|
||||
$NAME $ERLANG_NODE \
|
||||
-noinput -detached \
|
||||
@@ -148,7 +150,7 @@ start ()
|
||||
$KERNEL_OPTS \
|
||||
-s ejabberd \
|
||||
-sasl sasl_error_logger \\{file,\\\"$SASL_LOG_PATH\\\"\\} \
|
||||
$ERLANG_OPTS $ARGS \"$@\""
|
||||
$ERLANG_OPTS -- $ARGS \"$@\" $ERL_ARGS"
|
||||
}
|
||||
|
||||
# attach to server
|
||||
@@ -178,14 +180,14 @@ debug ()
|
||||
$EXEC_CMD "$ERL \
|
||||
$NAME debug-${TTY}-${ERLANG_NODE} \
|
||||
-remsh $ERLANG_NODE \
|
||||
-hidden \
|
||||
$KERNEL_OPTS \
|
||||
$ERLANG_OPTS $ARGS \"$@\""
|
||||
$ERLANG_OPTS -- $ARGS \"$@\" $ERL_ARGS"
|
||||
}
|
||||
|
||||
# start interactive server
|
||||
live ()
|
||||
{
|
||||
check_start
|
||||
echo "--------------------------------------------------------------------"
|
||||
echo ""
|
||||
echo "IMPORTANT: ejabberd is going to start in LIVE (interactive) mode."
|
||||
@@ -211,7 +213,14 @@ live ()
|
||||
-mnesia dir \"\\\"$SPOOLDIR\\\"\" \
|
||||
$KERNEL_OPTS \
|
||||
-s ejabberd \
|
||||
$ERLANG_OPTS $ARGS \"$@\""
|
||||
$ERLANG_OPTS -- $ARGS \"$@\" $ERL_ARGS"
|
||||
}
|
||||
|
||||
etop()
|
||||
{
|
||||
$EXEC_CMD "$ERL \
|
||||
$NAME debug-${TTY}-${ERLANG_NODE} \
|
||||
-hidden -s etop -s erlang halt -output text -node $ERLANG_NODE"
|
||||
}
|
||||
|
||||
help ()
|
||||
@@ -229,6 +238,7 @@ help ()
|
||||
echo " --logs dir Directory for logs: $LOGS_DIR"
|
||||
echo " --spool dir Database spool dir: $SPOOLDIR"
|
||||
echo " --node nodename ejabberd node name: $ERLANG_NODE"
|
||||
echo " --erlargs \"\" erl arguments: $ERL_ARGS"
|
||||
echo ""
|
||||
}
|
||||
|
||||
@@ -334,6 +344,26 @@ stop_epmd()
|
||||
epmd -names | grep -q name || epmd -kill
|
||||
}
|
||||
|
||||
# make sure node not already running and node name unregistered
|
||||
check_start()
|
||||
{
|
||||
epmd -names | grep -q $NODE && {
|
||||
ps ux | grep -q $ERLANG_NODE && {
|
||||
echo "ejabberd is already running."
|
||||
exit 4
|
||||
} || {
|
||||
ps ux | grep beam | grep -v "grep beam" && {
|
||||
echo "ejabberd node is registered, but no ejabberd process has been found."
|
||||
echo "can not kill epmd as other erlang nodes are running."
|
||||
echo "please stop all erlang nodes, and call 'epmd -kill'."
|
||||
exit 5
|
||||
} || {
|
||||
epmd -kill
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# allow sync calls
|
||||
wait_for_status()
|
||||
{
|
||||
@@ -363,6 +393,7 @@ case $ARGS in
|
||||
' start') start;;
|
||||
' debug') debug;;
|
||||
' live') live;;
|
||||
' etop') etop;;
|
||||
' started') wait_for_status 0 30 2;; # wait 30x2s before timeout
|
||||
' stopped') wait_for_status 3 15 2; stop_epmd;; # wait 15x2s before timeout
|
||||
*) ctl $ARGS;;
|
||||
|
||||
@@ -30,20 +30,22 @@
|
||||
%% External exports
|
||||
-export([export_passwd/2,
|
||||
export_roster/2,
|
||||
export_roster_group/2,
|
||||
export_offline/2,
|
||||
export_last/2,
|
||||
export_vcard/2,
|
||||
export_vcard_search/2,
|
||||
export_private_storage/2]).
|
||||
|
||||
-include_lib("exmpp/include/exmpp.hrl").
|
||||
|
||||
-include("ejabberd.hrl").
|
||||
-include("jlib.hrl").
|
||||
-include("mod_roster.hrl").
|
||||
|
||||
-record(offline_msg, {us, timestamp, expire, from, to, packet}).
|
||||
-record(last_activity, {us, timestamp, status}).
|
||||
-record(vcard, {us, vcard}).
|
||||
-record(vcard_search, {us,
|
||||
-record(offline_msg, {user_host, timestamp, expire, from, to, packet}).
|
||||
-record(last_activity, {user_host, timestamp, status}).
|
||||
-record(vcard, {user_host, vcard}).
|
||||
-record(vcard_search, {user_host,
|
||||
user, luser,
|
||||
fn, lfn,
|
||||
family, lfamily,
|
||||
@@ -57,7 +59,7 @@
|
||||
orgname, lorgname,
|
||||
orgunit, lorgunit
|
||||
}).
|
||||
-record(private_storage, {usns, xml}).
|
||||
-record(private_storage, {user_host_ns, xml}).
|
||||
|
||||
-define(MAX_RECORDS_PER_TRANSACTION, 1000).
|
||||
|
||||
@@ -78,37 +80,47 @@ export_passwd(Server, Output) ->
|
||||
when LServer == Host ->
|
||||
Username = ejabberd_odbc:escape(LUser),
|
||||
Pass = ejabberd_odbc:escape(Password),
|
||||
["delete from users where username='", Username ,"';"
|
||||
"insert into users(username, password) "
|
||||
"values ('", Username, "', '", Pass, "');"];
|
||||
["delete from users where host='", Server, "' and username='", Username ,"';\n"
|
||||
"insert into users(host, username, password) "
|
||||
"values ('", Server, "', '", Username, "', '", Pass, "');\n"];
|
||||
(_Host, _R) ->
|
||||
[]
|
||||
end).
|
||||
|
||||
export_roster(Server, Output) ->
|
||||
export_roster(ServerS, Output) ->
|
||||
Server = list_to_binary(ServerS),
|
||||
export_common(
|
||||
Server, roster, Output,
|
||||
fun(Host, #roster{usj = {LUser, LServer, LJID}} = R)
|
||||
Server, rosteritem, Output,
|
||||
fun(Host, #rosteritem{user_host_jid = {LUser, LServer, {N, D, Res} = _LJID}} = R)
|
||||
when LServer == Host ->
|
||||
Username = ejabberd_odbc:escape(LUser),
|
||||
SJID = ejabberd_odbc:escape(jlib:jid_to_string(LJID)),
|
||||
ItemVals = record_to_string(R),
|
||||
ItemGroups = groups_to_string(R),
|
||||
SJID = ejabberd_odbc:escape(exmpp_jid:to_list(N, D, Res)),
|
||||
ItemVals = record_to_string(R, ServerS),
|
||||
["delete from rosterusers "
|
||||
" where username='", Username, "' "
|
||||
" and jid='", SJID, "';"
|
||||
" and jid='", SJID, "';\n"
|
||||
"insert into rosterusers("
|
||||
" username, jid, nick, "
|
||||
" host, username, jid, nick, "
|
||||
" subscription, ask, askmessage, "
|
||||
" server, subscribe, type) "
|
||||
" values ", ItemVals, ";"
|
||||
"delete from rostergroups "
|
||||
" where username='", Username, "' "
|
||||
" and jid='", SJID, "';",
|
||||
[["insert into rostergroups("
|
||||
" username, jid, grp) "
|
||||
" values ", ItemGroup, ";"] ||
|
||||
ItemGroup <- ItemGroups]];
|
||||
" values ", ItemVals, ";\n"];
|
||||
(_Host, _R) ->
|
||||
[]
|
||||
end).
|
||||
|
||||
export_roster_group(ServerS, Output) ->
|
||||
Server = list_to_binary(ServerS),
|
||||
export_common(
|
||||
Server, rostergroup, Output,
|
||||
fun(Host, #rostergroup{user_host_jid = {_LUser, LServer, _LJID}} = R)
|
||||
when LServer == Host ->
|
||||
ItemGroup = group_to_string(R, ServerS),
|
||||
[%%"delete from rostergroups"
|
||||
%%" where username='", Username, "'"
|
||||
%%" and host='", ServerS, "'"
|
||||
%%" and jid='", SJID, "';"
|
||||
"insert into rostergroups(host, username, jid, grp)"
|
||||
" values ", ItemGroup, ";\n"];
|
||||
(_Host, _R) ->
|
||||
[]
|
||||
end).
|
||||
@@ -116,53 +128,52 @@ export_roster(Server, Output) ->
|
||||
export_offline(Server, Output) ->
|
||||
export_common(
|
||||
Server, offline_msg, Output,
|
||||
fun(Host, #offline_msg{us = {LUser, LServer},
|
||||
fun(Host, #offline_msg{user_host = {LUser, LServer},
|
||||
timestamp = TimeStamp,
|
||||
from = From,
|
||||
to = To,
|
||||
packet = Packet})
|
||||
packet = PacketString})
|
||||
when LServer == Host ->
|
||||
Username = ejabberd_odbc:escape(LUser),
|
||||
{xmlelement, Name, Attrs, Els} = Packet,
|
||||
Attrs2 = jlib:replace_from_to_attrs(
|
||||
jlib:jid_to_string(From),
|
||||
jlib:jid_to_string(To),
|
||||
Attrs),
|
||||
NewPacket = {xmlelement, Name, Attrs2,
|
||||
Els ++
|
||||
[jlib:timestamp_to_xml(
|
||||
calendar:now_to_universal_time(TimeStamp),
|
||||
[Packet] = exmpp_xml:parse_document(PacketString, [names_as_atom]),
|
||||
Packet0 = exmpp_stanza:set_jids(Packet,
|
||||
exmpp_jid:to_list(From),
|
||||
exmpp_jid:to_list(To)),
|
||||
Packet0b = exmpp_xml:append_child(Packet0,
|
||||
jlib:timestamp_to_xml(
|
||||
calendar:gregorian_seconds_to_datetime(TimeStamp),
|
||||
utc,
|
||||
jlib:make_jid("", Server, ""),
|
||||
"Offline Storage"),
|
||||
%% TODO: Delete the next three lines once XEP-0091 is Obsolete
|
||||
jlib:timestamp_to_xml(
|
||||
calendar:now_to_universal_time(
|
||||
TimeStamp))]},
|
||||
exmpp_jid:make("", Server, ""),
|
||||
"Offline Storage")),
|
||||
%% TODO: Delete the next three lines once XEP-0091 is Obsolete
|
||||
Packet1 = exmpp_xml:append_child(Packet0b,
|
||||
jlib:timestamp_to_xml(
|
||||
calendar:gregorian_seconds_to_datetime(TimeStamp))),
|
||||
XML =
|
||||
ejabberd_odbc:escape(
|
||||
xml:element_to_binary(NewPacket)),
|
||||
["insert into spool(username, xml) "
|
||||
"values ('", Username, "', '",
|
||||
exmpp_xml:document_to_list(Packet1)),
|
||||
["insert into spool(host, username, xml) "
|
||||
"values ('", Server, "', '", Username, "', '",
|
||||
XML,
|
||||
"');"];
|
||||
"');\n"];
|
||||
(_Host, _R) ->
|
||||
[]
|
||||
end).
|
||||
|
||||
export_last(Server, Output) ->
|
||||
export_last(ServerS, Output) ->
|
||||
Server = list_to_binary(ServerS),
|
||||
export_common(
|
||||
Server, last_activity, Output,
|
||||
fun(Host, #last_activity{us = {LUser, LServer},
|
||||
fun(Host, #last_activity{user_host = {LUser, LServer},
|
||||
timestamp = TimeStamp,
|
||||
status = Status})
|
||||
when LServer == Host ->
|
||||
Username = ejabberd_odbc:escape(LUser),
|
||||
Seconds = ejabberd_odbc:escape(integer_to_list(TimeStamp)),
|
||||
State = ejabberd_odbc:escape(Status),
|
||||
["delete from last where username='", Username, "';"
|
||||
["delete from last where host='", ServerS, "' and username='", Username, "';\n"
|
||||
"insert into last(username, seconds, state) "
|
||||
"values ('", Username, "', '", Seconds, "', '", State, "');"];
|
||||
"values ('", Username, "', '", Seconds, "', '", State, "');\n"];
|
||||
(_Host, _R) ->
|
||||
[]
|
||||
end).
|
||||
@@ -170,15 +181,15 @@ export_last(Server, Output) ->
|
||||
export_vcard(Server, Output) ->
|
||||
export_common(
|
||||
Server, vcard, Output,
|
||||
fun(Host, #vcard{us = {LUser, LServer},
|
||||
fun(Host, #vcard{user_host = {LUser, LServer},
|
||||
vcard = VCARD})
|
||||
when LServer == Host ->
|
||||
Username = ejabberd_odbc:escape(LUser),
|
||||
SVCARD = ejabberd_odbc:escape(
|
||||
xml:element_to_binary(VCARD)),
|
||||
["delete from vcard where username='", Username, "';"
|
||||
"insert into vcard(username, vcard) "
|
||||
"values ('", Username, "', '", SVCARD, "');"];
|
||||
exmpp_xml:document_to_list(VCARD)),
|
||||
["delete from vcard where host='", Server,"' and username='", Username, "';\n"
|
||||
"insert into vcard(host, username, vcard) "
|
||||
"values ('", Server, "', '", Username, "', '", SVCARD, "');\n"];
|
||||
(_Host, _R) ->
|
||||
[]
|
||||
end).
|
||||
@@ -227,7 +238,7 @@ export_vcard_search(Server, Output) ->
|
||||
SOrgUnit = ejabberd_odbc:escape(OrgUnit),
|
||||
SLOrgUnit = ejabberd_odbc:escape(LOrgUnit),
|
||||
|
||||
["delete from vcard_search where lusername='", LUsername, "';"
|
||||
["delete from vcard_search where host='", Server, "' and lusername='", LUsername, "';\n"
|
||||
"insert into vcard_search("
|
||||
" username, lusername, fn, lfn, family, lfamily,"
|
||||
" given, lgiven, middle, lmiddle, nickname, lnickname,"
|
||||
@@ -245,22 +256,23 @@ export_vcard_search(Server, Output) ->
|
||||
" '", SLocality, "', '", SLLocality, "',"
|
||||
" '", SEMail, "', '", SLEMail, "',"
|
||||
" '", SOrgName, "', '", SLOrgName, "',"
|
||||
" '", SOrgUnit, "', '", SLOrgUnit, "');"];
|
||||
" '", SOrgUnit, "', '", SLOrgUnit, "');\n"];
|
||||
(_Host, _R) ->
|
||||
[]
|
||||
end).
|
||||
|
||||
export_private_storage(Server, Output) ->
|
||||
export_private_storage(ServerS, Output) ->
|
||||
Server = list_to_binary(ServerS),
|
||||
export_common(
|
||||
Server, private_storage, Output,
|
||||
fun(Host, #private_storage{usns = {LUser, LServer, XMLNS},
|
||||
fun(Host, #private_storage{user_host_ns = {LUser, LServer, XMLNS},
|
||||
xml = Data})
|
||||
when LServer == Host ->
|
||||
Username = ejabberd_odbc:escape(LUser),
|
||||
LXMLNS = ejabberd_odbc:escape(XMLNS),
|
||||
LXMLNS = ejabberd_odbc:escape(atom_to_list(XMLNS)),
|
||||
SData = ejabberd_odbc:escape(
|
||||
xml:element_to_binary(Data)),
|
||||
odbc_queries:set_private_data_sql(Username, LXMLNS, SData);
|
||||
exmpp_xml:document_to_list(Data)),
|
||||
odbc_queries:set_private_data_sql(LServer, Username, LXMLNS, SData);
|
||||
(_Host, _R) ->
|
||||
[]
|
||||
end).
|
||||
@@ -280,7 +292,7 @@ export_common(Server, Table, Output, ConvertFun) ->
|
||||
mnesia:transaction(
|
||||
fun() ->
|
||||
mnesia:read_lock_table(Table),
|
||||
LServer = jlib:nameprep(Server),
|
||||
LServer = exmpp_stringprep:nameprep(Server),
|
||||
{_N, SQLs} =
|
||||
mnesia:foldl(
|
||||
fun(R, {N, SQLs} = Acc) ->
|
||||
@@ -294,7 +306,7 @@ export_common(Server, Table, Output, ConvertFun) ->
|
||||
true ->
|
||||
%% Execute full SQL transaction
|
||||
output(LServer, IO,
|
||||
["begin;",
|
||||
["begin;\n",
|
||||
lists:reverse([SQL | SQLs]),
|
||||
"commit"]),
|
||||
{0, []}
|
||||
@@ -303,7 +315,7 @@ export_common(Server, Table, Output, ConvertFun) ->
|
||||
end, {0, []}, Table),
|
||||
%% Execute SQL transaction with remaining records
|
||||
output(LServer, IO,
|
||||
["begin;",
|
||||
["begin;\n",
|
||||
lists:reverse(SQLs),
|
||||
"commit"])
|
||||
end).
|
||||
@@ -316,13 +328,13 @@ output(LServer, IO, SQL) ->
|
||||
file:write(IO, [SQL, $;, $\n])
|
||||
end.
|
||||
|
||||
record_to_string(#roster{usj = {User, _Server, JID},
|
||||
record_to_string(#rosteritem{user_host_jid = {User, _Server, {N, D, R} = _JID},
|
||||
name = Name,
|
||||
subscription = Subscription,
|
||||
ask = Ask,
|
||||
askmessage = AskMessage}) ->
|
||||
askmessage = AskMessage}, ServerS) ->
|
||||
Username = ejabberd_odbc:escape(User),
|
||||
SJID = ejabberd_odbc:escape(jlib:jid_to_string(JID)),
|
||||
SJID = ejabberd_odbc:escape(exmpp_jid:to_list(N, D, R)),
|
||||
Nick = ejabberd_odbc:escape(Name),
|
||||
SSubscription = case Subscription of
|
||||
both -> "B";
|
||||
@@ -347,6 +359,7 @@ record_to_string(#roster{usj = {User, _Server, JID},
|
||||
SAM
|
||||
end,
|
||||
["("
|
||||
"'", ServerS, "',"
|
||||
"'", Username, "',"
|
||||
"'", SJID, "',"
|
||||
"'", Nick, "',"
|
||||
@@ -355,11 +368,12 @@ record_to_string(#roster{usj = {User, _Server, JID},
|
||||
"'", SAskMessage, "',"
|
||||
"'N', '', 'item')"].
|
||||
|
||||
groups_to_string(#roster{usj = {User, _Server, JID},
|
||||
groups = Groups}) ->
|
||||
group_to_string(#rostergroup{user_host_jid = {User, _Server, {N, D, R} = _JID},
|
||||
grp = Group}, ServerS) ->
|
||||
Username = ejabberd_odbc:escape(User),
|
||||
SJID = ejabberd_odbc:escape(jlib:jid_to_string(JID)),
|
||||
[["("
|
||||
SJID = ejabberd_odbc:escape(exmpp_jid:to_list(N, D, R)),
|
||||
["("
|
||||
"'", ServerS, "',"
|
||||
"'", Username, "',"
|
||||
"'", SJID, "',"
|
||||
"'", ejabberd_odbc:escape(Group), "')"] || Group <- Groups].
|
||||
"'", ejabberd_odbc:escape(Group), "')"].
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
# $Id: Makefile.in 2842 2009-12-29 19:10:52Z badlop $
|
||||
|
||||
CC = @CC@
|
||||
CFLAGS = @CFLAGS@
|
||||
CPPFLAGS = @CPPFLAGS@
|
||||
@@ -11,7 +9,6 @@ ASN_FLAGS = -bber_bin +optimize +driver
|
||||
ERLANG_CFLAGS = @ERLANG_CFLAGS@
|
||||
ERLANG_LIBS = @ERLANG_LIBS@
|
||||
|
||||
EFLAGS += @ERLANG_SSLVER@
|
||||
EFLAGS += -I ..
|
||||
EFLAGS += -pz ..
|
||||
|
||||
@@ -55,3 +52,24 @@ distclean: clean
|
||||
TAGS:
|
||||
etags *.erl
|
||||
|
||||
# Don't include ELDAPv3.erl in sources for Devdoc
|
||||
SOURCES = eldap.erl eldap_filter.erl eldap.hrl eldap_pool.erl eldap_utils.erl
|
||||
|
||||
DEVDOCDIR=../../doc/devdoc
|
||||
DDTDIR=..
|
||||
HTMLS = $(SOURCES:%.erl=../../doc/devdoc/%.html)
|
||||
ERLHTMLS = $(SOURCES:%.erl=../../doc/devdoc/%.erl.html)
|
||||
SVGS = $(SOURCES:%.erl=../../doc/devdoc/%.svg)
|
||||
|
||||
devdoc: $(HTMLS) $(ERLHTMLS) $(SVGS)
|
||||
|
||||
$(DEVDOCDIR)/%.erl.html: %.erl
|
||||
@ERL@ -noshell -pa $(DEVDOCDIR) -run escobar_run file $< $(DDTDIR) -s init stop
|
||||
|
||||
$(DEVDOCDIR)/%.html: %.erl
|
||||
@ERL@ -noshell -run edoc_run file $< \
|
||||
'[{dir,"$(DDTDIR)"},{packages,false},{todo,true},{private,true},{def,{vsn,"$(VSN)"}},{stylesheet,"process-one.css"},{overview,"overview.edoc"}]' -s init stop
|
||||
|
||||
$(DEVDOCDIR)/%.svg: %.erl
|
||||
@ERL@ -noshell -pa $(DEVDOCDIR) -run funrelg dir $< $(DDTDIR) -s init stop
|
||||
|
||||
|
||||
@@ -53,7 +53,6 @@
|
||||
%%% NOTICE: STARTTLS is not supported.
|
||||
|
||||
%%% --------------------------------------------------------------------
|
||||
-vc('$Id$ ').
|
||||
|
||||
|
||||
%%%----------------------------------------------------------------------
|
||||
|
||||
@@ -26,9 +26,6 @@
|
||||
%%%----------------------------------------------------------------------
|
||||
-module(eldap_filter).
|
||||
|
||||
%% TODO: remove this when new regexp module will be used
|
||||
-compile({nowarn_deprecated_function, {regexp, sub, 3}}).
|
||||
|
||||
-export([parse/1, parse/2, do_sub/2]).
|
||||
|
||||
%%====================================================================
|
||||
@@ -144,34 +141,36 @@ do_sub(S, [{RegExp, New, Times} | T]) ->
|
||||
do_sub(Result, T).
|
||||
|
||||
do_sub(S, {RegExp, New}, Iter) ->
|
||||
case regexp:sub(S, RegExp, New) of
|
||||
{ok, NewS, 0} ->
|
||||
try re:replace(S, RegExp, New, [{return, list}]) of
|
||||
NewS when NewS == S ->
|
||||
NewS;
|
||||
{ok, NewS, _} when Iter =< ?MAX_RECURSION ->
|
||||
NewS when Iter =< ?MAX_RECURSION ->
|
||||
do_sub(NewS, {RegExp, New}, Iter+1);
|
||||
{ok, _, _} when Iter > ?MAX_RECURSION ->
|
||||
erlang:error(max_substitute_recursion);
|
||||
_ ->
|
||||
erlang:error(bad_regexp)
|
||||
_ when Iter > ?MAX_RECURSION ->
|
||||
throw({regexp, max_substitute_recursion})
|
||||
catch
|
||||
_:_ ->
|
||||
throw({regexp, bad_regexp})
|
||||
end;
|
||||
|
||||
do_sub(S, {_, _, N}, _) when N<1 ->
|
||||
S;
|
||||
|
||||
do_sub(S, {RegExp, New, Times}, Iter) ->
|
||||
case regexp:sub(S, RegExp, New) of
|
||||
{ok, NewS, 0} ->
|
||||
try re:replace(S, RegExp, New, [{return, list}]) of
|
||||
NewS when NewS == S ->
|
||||
NewS;
|
||||
{ok, NewS, _} when Iter < Times ->
|
||||
NewS when Iter < Times ->
|
||||
do_sub(NewS, {RegExp, New, Times}, Iter+1);
|
||||
{ok, NewS, _} ->
|
||||
NewS;
|
||||
_ ->
|
||||
erlang:error(bad_regexp)
|
||||
NewS ->
|
||||
NewS
|
||||
catch
|
||||
_:_ ->
|
||||
throw({regexp, bad_regexp})
|
||||
end.
|
||||
|
||||
replace_amps(String) ->
|
||||
lists:flatmap(
|
||||
lists:map(
|
||||
fun($&) -> "\\&";
|
||||
(Chr) -> [Chr]
|
||||
(Chr) -> Chr
|
||||
end, String).
|
||||
|
||||