Mercurial > eldonilo > lightstring
comparison plugins/feature-not-implemented.js @ 47:ea276b47c555
Fix feature-not-implemented plugin.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Wed, 01 Feb 2012 00:41:09 +0100 |
parents | b43ca01b9f6f |
children |
comparison
equal
deleted
inserted
replaced
46:f23e4741a7c5 | 47:ea276b47c555 |
---|---|
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | 14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | 15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | 16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
17 */ | 17 */ |
18 | 18 |
19 Lightstring.NS.xmpp_stanzas = 'urn:ietf:params:xml:ns:xmpp-stanzas'; | 19 Lightstring.plugins['feature-not-implemented'] = { |
20 namespaces: { | |
21 xmpp_stanzas: 'urn:ietf:params:xml:ns:xmpp-stanzas' | |
22 }, | |
23 handlers: { | |
24 'iq': function callback(stanza) { | |
25 var type = stanza.DOM.getAttributeNS(null, 'type'); | |
26 if (type !== 'get' && type !== 'set') | |
27 return; | |
20 | 28 |
21 function register_feature_not_implemented() { | 29 var handlers = conn.handlers; |
22 var conn = this; | 30 var events = [handlers['iq']]; |
23 conn.on('iq', function callback(stanza) { | |
24 var type = stanza.DOM.getAttributeNS(null, 'type'); | |
25 if (type !== 'get' && type !== 'set') | |
26 return; | |
27 | 31 |
28 var handlers = conn.handlers; | 32 var payload = stanza.DOM.firstChild; |
29 var events = [handlers['iq']]; | 33 if (payload) |
34 events.push('iq/' + payload.namespaceURI + ':' + payload.localName); | |
30 | 35 |
31 var payload = stanza.DOM.firstChild; | 36 var only = events.every(function(handler) { |
32 if (payload) | 37 for (var i in handler) |
33 events.push('iq/' + payload.namespaceURI + ':' + payload.localName); | 38 if (callback !== handler[i]) |
39 return false; | |
40 return true; | |
41 }); | |
34 | 42 |
35 var only = events.every(function(handler) { | 43 if (only) |
36 for (var i in handler) | 44 conn.send("<iq to='" + stanza.DOM.getAttributeNS(null, 'from') + "'" + |
37 if (callback !== handler[i]) | 45 " id='" + stanza.DOM.getAttributeNS(null, 'id') + "'" + |
38 return false; | 46 " type='error'>" + |
39 return true; | 47 "<error type='cancel'>" + |
40 }); | 48 "<feature-not-implemented xmlns='" + Lightstring.NS.xmpp_stanzas + "'/>" + |
41 | 49 "</error>" + |
42 if (only) | 50 "</iq>"); |
43 conn.send("<iq to='" + stanza.DOM.getAttributeNS(null, 'from') + "'" + | 51 } |
44 " id='" + stanza.DOM.getAttributeNS(null, 'id') + "'" + | 52 } |
45 " type='error'>" + | |
46 "<error type='cancel'>" + | |
47 "<feature-not-implemented xmlns='" + Lightstring.NS.xmpp_stanzas + "'/>" + | |
48 "</error>" + | |
49 "</iq>"); | |
50 }); | |
51 }; | 53 }; |