Mercurial > eldonilo > lightstring
annotate plugins/roster.js @ 64:d9f5ae0b6d98
Support for DIGEST-MD5 authentication. (plugin)
author | Sonny Piers <sonny.piers@gmail.com> |
---|---|
date | Wed, 01 Feb 2012 19:47:49 +0100 |
parents | 48e2bd6b1885 |
children | 595be4a8584f |
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 //Roster// |
1506992c33e2
Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
21 ////////// |
52
48e2bd6b1885
Fix roster plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
35
diff
changeset
|
22 Lightstring.plugins['roster'] = { |
48e2bd6b1885
Fix roster plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
35
diff
changeset
|
23 namespaces: { |
48e2bd6b1885
Fix roster plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
35
diff
changeset
|
24 roster: 'jabber:iq:roster' |
48e2bd6b1885
Fix roster plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
35
diff
changeset
|
25 }, |
48e2bd6b1885
Fix roster plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
35
diff
changeset
|
26 stanzas: { |
48e2bd6b1885
Fix roster plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
35
diff
changeset
|
27 get: function() { |
48e2bd6b1885
Fix roster plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
35
diff
changeset
|
28 return "<iq type='get'>" + |
48e2bd6b1885
Fix roster plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
35
diff
changeset
|
29 "<query xmlns='" + Lightstring.NS.roster + "'/>" + |
48e2bd6b1885
Fix roster plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
35
diff
changeset
|
30 "</iq>"; |
48e2bd6b1885
Fix roster plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
35
diff
changeset
|
31 }, |
48e2bd6b1885
Fix roster plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
35
diff
changeset
|
32 add: function(aAddress, aGroups) { |
48e2bd6b1885
Fix roster plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
35
diff
changeset
|
33 var iq = "<iq type='set'>" + |
48e2bd6b1885
Fix roster plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
35
diff
changeset
|
34 "<query xmlns='" + Lightstring.NS.roster + "'>" + |
48e2bd6b1885
Fix roster plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
35
diff
changeset
|
35 "<item jid='" + aAddress + "'/>" + |
48e2bd6b1885
Fix roster plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
35
diff
changeset
|
36 "</query>" + |
48e2bd6b1885
Fix roster plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
35
diff
changeset
|
37 "</iq>"; |
48e2bd6b1885
Fix roster plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
35
diff
changeset
|
38 for (var i = 0; i < aGroups.length; i++) { |
48e2bd6b1885
Fix roster plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
35
diff
changeset
|
39 if (i === 0) |
48e2bd6b1885
Fix roster plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
35
diff
changeset
|
40 iq.querySelector('item').appendChild(document.createElement('group')); |
48e2bd6b1885
Fix roster plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
35
diff
changeset
|
41 iq.querySelector('group').appendChild(document.createElement(aGroups[i])); |
48e2bd6b1885
Fix roster plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
35
diff
changeset
|
42 } |
48e2bd6b1885
Fix roster plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
35
diff
changeset
|
43 return iq; |
48e2bd6b1885
Fix roster plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
35
diff
changeset
|
44 }, |
48e2bd6b1885
Fix roster plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
35
diff
changeset
|
45 remove: function(aAddress) { |
48e2bd6b1885
Fix roster plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
35
diff
changeset
|
46 return "<iq type='set'>" + |
48e2bd6b1885
Fix roster plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
35
diff
changeset
|
47 "<query xmlns='" + Lightstring.NS.roster + "'>" + |
48e2bd6b1885
Fix roster plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
35
diff
changeset
|
48 "<item jid='" + aAddress + "' subscription='remove'/>" + |
48e2bd6b1885
Fix roster plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
35
diff
changeset
|
49 "</query>" + |
48e2bd6b1885
Fix roster plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
35
diff
changeset
|
50 "</iq>"; |
48e2bd6b1885
Fix roster plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
35
diff
changeset
|
51 } |
30
1506992c33e2
Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
52 }, |
52
48e2bd6b1885
Fix roster plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
35
diff
changeset
|
53 methods: { |
48e2bd6b1885
Fix roster plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
35
diff
changeset
|
54 get: function(aResult, aError) { |
48e2bd6b1885
Fix roster plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
35
diff
changeset
|
55 this.send(this.stanza.roster.get(), function(stanza) { |
48e2bd6b1885
Fix roster plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
35
diff
changeset
|
56 var contacts = []; |
48e2bd6b1885
Fix roster plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
35
diff
changeset
|
57 |
48e2bd6b1885
Fix roster plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
35
diff
changeset
|
58 var children = stanza.DOM.firstChild.childNodes; |
48e2bd6b1885
Fix roster plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
35
diff
changeset
|
59 var length = children.length; |
48e2bd6b1885
Fix roster plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
35
diff
changeset
|
60 |
48e2bd6b1885
Fix roster plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
35
diff
changeset
|
61 for (var i = 0; i < length; i++) { |
48e2bd6b1885
Fix roster plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
35
diff
changeset
|
62 var item = children[i]; |
48e2bd6b1885
Fix roster plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
35
diff
changeset
|
63 var jid = item.getAttributeNS(null, 'jid'); |
48e2bd6b1885
Fix roster plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
35
diff
changeset
|
64 var name = item.getAttributeNS(null, 'name'); |
48e2bd6b1885
Fix roster plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
35
diff
changeset
|
65 var subscription = item.getAttributeNS(null, 'subscription'); |
48e2bd6b1885
Fix roster plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
35
diff
changeset
|
66 var groups = item.children; |
48e2bd6b1885
Fix roster plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
35
diff
changeset
|
67 var contact = {}; |
48e2bd6b1885
Fix roster plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
35
diff
changeset
|
68 if (name) |
48e2bd6b1885
Fix roster plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
35
diff
changeset
|
69 contact.name = name; |
48e2bd6b1885
Fix roster plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
35
diff
changeset
|
70 if (jid) |
48e2bd6b1885
Fix roster plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
35
diff
changeset
|
71 contact.jid = jid; |
48e2bd6b1885
Fix roster plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
35
diff
changeset
|
72 if (subscription) |
48e2bd6b1885
Fix roster plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
35
diff
changeset
|
73 contact.subscription = subscription; |
48e2bd6b1885
Fix roster plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
35
diff
changeset
|
74 if (groups.length > 0) { |
48e2bd6b1885
Fix roster plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
35
diff
changeset
|
75 contact.groups = []; |
48e2bd6b1885
Fix roster plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
35
diff
changeset
|
76 groups.forEach(function(group) { |
48e2bd6b1885
Fix roster plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
35
diff
changeset
|
77 contact.groups.push(group.textContent); |
48e2bd6b1885
Fix roster plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
35
diff
changeset
|
78 }); |
48e2bd6b1885
Fix roster plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
35
diff
changeset
|
79 } |
48e2bd6b1885
Fix roster plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
35
diff
changeset
|
80 |
48e2bd6b1885
Fix roster plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
35
diff
changeset
|
81 contacts.push(contact); |
48e2bd6b1885
Fix roster plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
35
diff
changeset
|
82 } |
48e2bd6b1885
Fix roster plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
35
diff
changeset
|
83 |
48e2bd6b1885
Fix roster plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
35
diff
changeset
|
84 if (aResult) |
48e2bd6b1885
Fix roster plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
35
diff
changeset
|
85 aResult(contacts); |
48e2bd6b1885
Fix roster plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
35
diff
changeset
|
86 }, aError); |
30
1506992c33e2
Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
87 } |
1506992c33e2
Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
88 } |
1506992c33e2
Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
89 }; |