annotate plugins/disco.js @ 36:b43ca01b9f6f

Add a plugin that respond an error to each get/set iq not handled.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Sat, 28 Jan 2012 06:01:58 +0100
parents bdfbd58b4835
children 6773e5bc2ca0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
30
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1 'use strict';
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
2
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
3 /**
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
4 Copyright (c) 2011, Sonny Piers <sonny at fastmail dot net>
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
5
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
6 Permission to use, copy, modify, and/or distribute this software for any
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
7 purpose with or without fee is hereby granted, provided that the above
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
8 copyright notice and this permission notice appear in all copies.
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
9
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
13 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
17 */
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
18
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
19 /////////
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
20 //Disco//
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
21 /////////
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
22 Lightstring.NS['disco#info'] = "http://jabber.org/protocol/disco#info";
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
23 Lightstring.NS['disco#items'] = "http://jabber.org/protocol/disco#items";
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
24 Lightstring.stanza.disco = {
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
25 items: function(aTo, aNode) {
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
26 if(aTo)
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
27 var iq = "<iq type='get' to='"+aTo+"'>";
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
28 else
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
29 var iq = "<iq type='get'>";
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
30
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
31 if(aNode)
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
32 var query = "<query xmlns='"+Lightstring.NS['disco#items']+"' node='"+aNode+"'/>";
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
33 else
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
34 var query = "<query xmlns='"+Lightstring.NS['disco#items']+"'/>";
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
35
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
36 return iq+query+"</iq>";
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
37 },
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
38 info: function(aTo, aNode) {
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
39 if(aTo)
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
40 var iq = "<iq type='get' to='"+aTo+"'>";
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
41 else
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
42 var iq = "<iq type='get'>";
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
43 if(aNode)
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
44 var query = "<query xmlns='"+Lightstring.NS['disco#info']+"' node='"+aNode+"'/>";
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
45 else
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
46 var query = "<query xmlns='"+Lightstring.NS['disco#info']+"'/>";
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
47
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
48 return iq+query+"</iq>";
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
49 }
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
50 };
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
51 Lightstring.discoItems = function(aConnection, aTo, aCallback) {
35
bdfbd58b4835 Fix plugins.
Sonny Piers <sonny.piers@gmail.com>
parents: 30
diff changeset
52 aConnection.send(Lightstring.stanza.disco.items(aTo), function(stanza){
30
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
53 var items = [];
35
bdfbd58b4835 Fix plugins.
Sonny Piers <sonny.piers@gmail.com>
parents: 30
diff changeset
54 var elms = stanza.DOM.querySelectorAll('item');
30
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
55 for(var i = 0; i < elms.length; i++) {
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
56 var node = elms[i];
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
57 var item = {
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
58 jid: node.getAttribute('jid'),
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
59 name: node.getAttribute('name'),
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
60 node: node.getAttribute('node')
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
61 }
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
62 items.push(item);
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
63 };
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
64 if(aCallback)
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
65 aCallback(items);
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
66 });
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
67 };
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
68 Lightstring.discoInfo = function(aConnection, aTo, aNode, aCallback) {
35
bdfbd58b4835 Fix plugins.
Sonny Piers <sonny.piers@gmail.com>
parents: 30
diff changeset
69 aConnection.send(Lightstring.stanza.disco.info(aTo, aNode), function(stanza){
30
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
70 var identities = [];
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
71 var features = [];
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
72
35
bdfbd58b4835 Fix plugins.
Sonny Piers <sonny.piers@gmail.com>
parents: 30
diff changeset
73 var children = stanza.DOM.firstChild.children;
30
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
74 var length = children.length;
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
75
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
76 for (var i = 0; i < length; i++) {
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
77 var child = children[i];
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
78
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
79 if (child.localName === 'feature')
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
80 features.push(child.getAttributeNS(null, 'var'));
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
81
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
82 else if (child.localName === 'identity') {
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
83 var identity = {
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
84 category: child.getAttributeNS(null, 'category'),
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
85 type: child.getAttributeNS(null, 'type')
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
86 };
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
87 var name = child.getAttributeNS(null, 'name');
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
88 if (name)
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
89 identity.name = name;
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
90 identities.push(identity);
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
91 }
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
92 }
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
93
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
94 aCallback({identities: identities, features: features});
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
95 });
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
96 };