# HG changeset patch # User Emmanuel Gil Peyrot # Date 1327726918 -3600 # Node ID b43ca01b9f6f564783d90625170d3e85eda6e06d # Parent bdfbd58b48350298c89448cc22026fc241bd3097 Add a plugin that respond an error to each get/set iq not handled. diff --git a/plugins/feature-not-implemented.js b/plugins/feature-not-implemented.js new file mode 100644 --- /dev/null +++ b/plugins/feature-not-implemented.js @@ -0,0 +1,51 @@ +'use strict'; + +/** + Copyright (c) 2012, Emmanuel Gil Peyrot + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ + +Lightstring.NS.xmpp_stanzas = 'urn:ietf:params:xml:ns:xmpp-stanzas'; + +function register_feature_not_implemented() { + var conn = this; + conn.on('iq', function callback(stanza) { + var type = stanza.DOM.getAttributeNS(null, 'type'); + if (type !== 'get' && type !== 'set') + return; + + var handlers = conn.handlers; + var events = [handlers['iq']]; + + var payload = stanza.DOM.firstChild; + if (payload) + events.push('iq/' + payload.namespaceURI + ':' + payload.localName); + + var only = events.every(function(handler) { + for (var i in handler) + if (callback !== handler[i]) + return false; + return true; + }); + + if (only) + conn.send("" + + "" + + "" + + "" + + ""); + }); +};