annotate plugins/feature-not-implemented.js @ 52:48e2bd6b1885

Fix roster plugin.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Wed, 01 Feb 2012 03:51:12 +0100
parents ea276b47c555
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
36
b43ca01b9f6f Add a plugin that respond an error to each get/set iq not handled.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1 'use strict';
b43ca01b9f6f Add a plugin that respond an error to each get/set iq not handled.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
2
b43ca01b9f6f Add a plugin that respond an error to each get/set iq not handled.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
3 /**
b43ca01b9f6f Add a plugin that respond an error to each get/set iq not handled.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
4 Copyright (c) 2012, Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
b43ca01b9f6f Add a plugin that respond an error to each get/set iq not handled.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
5
b43ca01b9f6f Add a plugin that respond an error to each get/set iq not handled.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
6 Permission to use, copy, modify, and/or distribute this software for any
b43ca01b9f6f Add a plugin that respond an error to each get/set iq not handled.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
7 purpose with or without fee is hereby granted, provided that the above
b43ca01b9f6f Add a plugin that respond an error to each get/set iq not handled.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
8 copyright notice and this permission notice appear in all copies.
b43ca01b9f6f Add a plugin that respond an error to each get/set iq not handled.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
9
b43ca01b9f6f Add a plugin that respond an error to each get/set iq not handled.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
b43ca01b9f6f Add a plugin that respond an error to each get/set iq not handled.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
b43ca01b9f6f Add a plugin that respond an error to each get/set iq not handled.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
b43ca01b9f6f Add a plugin that respond an error to each get/set iq not handled.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
13 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
b43ca01b9f6f Add a plugin that respond an error to each get/set iq not handled.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
b43ca01b9f6f Add a plugin that respond an error to each get/set iq not handled.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
b43ca01b9f6f Add a plugin that respond an error to each get/set iq not handled.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
b43ca01b9f6f Add a plugin that respond an error to each get/set iq not handled.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
17 */
b43ca01b9f6f Add a plugin that respond an error to each get/set iq not handled.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
18
47
ea276b47c555 Fix feature-not-implemented plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 36
diff changeset
19 Lightstring.plugins['feature-not-implemented'] = {
ea276b47c555 Fix feature-not-implemented plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 36
diff changeset
20 namespaces: {
ea276b47c555 Fix feature-not-implemented plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 36
diff changeset
21 xmpp_stanzas: 'urn:ietf:params:xml:ns:xmpp-stanzas'
ea276b47c555 Fix feature-not-implemented plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 36
diff changeset
22 },
ea276b47c555 Fix feature-not-implemented plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 36
diff changeset
23 handlers: {
ea276b47c555 Fix feature-not-implemented plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 36
diff changeset
24 'iq': function callback(stanza) {
ea276b47c555 Fix feature-not-implemented plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 36
diff changeset
25 var type = stanza.DOM.getAttributeNS(null, 'type');
ea276b47c555 Fix feature-not-implemented plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 36
diff changeset
26 if (type !== 'get' && type !== 'set')
ea276b47c555 Fix feature-not-implemented plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 36
diff changeset
27 return;
36
b43ca01b9f6f Add a plugin that respond an error to each get/set iq not handled.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
28
47
ea276b47c555 Fix feature-not-implemented plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 36
diff changeset
29 var handlers = conn.handlers;
ea276b47c555 Fix feature-not-implemented plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 36
diff changeset
30 var events = [handlers['iq']];
36
b43ca01b9f6f Add a plugin that respond an error to each get/set iq not handled.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
31
47
ea276b47c555 Fix feature-not-implemented plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 36
diff changeset
32 var payload = stanza.DOM.firstChild;
ea276b47c555 Fix feature-not-implemented plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 36
diff changeset
33 if (payload)
ea276b47c555 Fix feature-not-implemented plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 36
diff changeset
34 events.push('iq/' + payload.namespaceURI + ':' + payload.localName);
36
b43ca01b9f6f Add a plugin that respond an error to each get/set iq not handled.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
35
47
ea276b47c555 Fix feature-not-implemented plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 36
diff changeset
36 var only = events.every(function(handler) {
ea276b47c555 Fix feature-not-implemented plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 36
diff changeset
37 for (var i in handler)
ea276b47c555 Fix feature-not-implemented plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 36
diff changeset
38 if (callback !== handler[i])
ea276b47c555 Fix feature-not-implemented plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 36
diff changeset
39 return false;
ea276b47c555 Fix feature-not-implemented plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 36
diff changeset
40 return true;
ea276b47c555 Fix feature-not-implemented plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 36
diff changeset
41 });
36
b43ca01b9f6f Add a plugin that respond an error to each get/set iq not handled.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
42
47
ea276b47c555 Fix feature-not-implemented plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 36
diff changeset
43 if (only)
ea276b47c555 Fix feature-not-implemented plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 36
diff changeset
44 conn.send("<iq to='" + stanza.DOM.getAttributeNS(null, 'from') + "'" +
ea276b47c555 Fix feature-not-implemented plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 36
diff changeset
45 " id='" + stanza.DOM.getAttributeNS(null, 'id') + "'" +
ea276b47c555 Fix feature-not-implemented plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 36
diff changeset
46 " type='error'>" +
ea276b47c555 Fix feature-not-implemented plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 36
diff changeset
47 "<error type='cancel'>" +
ea276b47c555 Fix feature-not-implemented plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 36
diff changeset
48 "<feature-not-implemented xmlns='" + Lightstring.NS.xmpp_stanzas + "'/>" +
ea276b47c555 Fix feature-not-implemented plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 36
diff changeset
49 "</error>" +
ea276b47c555 Fix feature-not-implemented plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 36
diff changeset
50 "</iq>");
ea276b47c555 Fix feature-not-implemented plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 36
diff changeset
51 }
ea276b47c555 Fix feature-not-implemented plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 36
diff changeset
52 }
36
b43ca01b9f6f Add a plugin that respond an error to each get/set iq not handled.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
53 };