annotate psgxs.js @ 20:957550e2d5a1

Correct an error identifier and use an already defined variable.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Tue, 19 Oct 2010 18:55:53 +0200
parents 032090a13fe8
children e55b31f12f8c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1 #!/usr/bin/env node
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
2
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
3 /*
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
4 * Copyright (C) 2010 Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
5 *
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
6 * This file is part of PSĜS, a PubSub server written in JavaScript.
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
7 *
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
8 * PSĜS is free software: you can redistribute it and/or modify
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
9 * it under the terms of the GNU Affero General Public License as
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
10 * published by the Free Software Foundation, either version 3 of the
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
11 * License.
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
12 *
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
13 * PSĜS is distributed in the hope that it will be useful,
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
16 * GNU Affero General Public License for more details.
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
17 *
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
18 * You should have received a copy of the GNU Affero General Public License
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
19 * along with PSĜS. If not, see <http://www.gnu.org/licenses/>.
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
20 */
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
21
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
22 var xmpp = require('xmpp');
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
23 var sha1 = require('sha1');
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
24 require('./iso8601');
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
25 var storage = require('./storage');
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
26 var errors = require('./errors');
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
27 var utils = require('./util');
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
28 var toBareJID = utils.toBareJID;
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
29 var config = require('./configuration');
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
30 var forms = require('./forms');
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
31 var conn = new xmpp.Connection();
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
32
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
33 var service_configuration = config.service_configuration;
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
34 var componentJID = config.jid;
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
35 var componentPassword = config.password;
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
36
12
9a6b8b3357c6 Use new functions like console.log instead of sys.puts, and aerate a bit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 11
diff changeset
37 conn.log = function (_, m) { console.log(m); };
0
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
38
12
9a6b8b3357c6 Use new functions like console.log instead of sys.puts, and aerate a bit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 11
diff changeset
39 function _(obj, color) {
9a6b8b3357c6 Use new functions like console.log instead of sys.puts, and aerate a bit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 11
diff changeset
40 var str = require('sys').inspect(obj, false, null);
9a6b8b3357c6 Use new functions like console.log instead of sys.puts, and aerate a bit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 11
diff changeset
41 if (color)
9a6b8b3357c6 Use new functions like console.log instead of sys.puts, and aerate a bit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 11
diff changeset
42 console.log('\033['+c+';1m' + str + '\033[0m');
9a6b8b3357c6 Use new functions like console.log instead of sys.puts, and aerate a bit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 11
diff changeset
43 else
9a6b8b3357c6 Use new functions like console.log instead of sys.puts, and aerate a bit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 11
diff changeset
44 console.log(str);
0
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
45 };
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
46
11
0ed3c06c5191 Add an uncaught exceptions caughter to prevent the server from crashing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 10
diff changeset
47 process.addListener('uncaughtException', function (err) {
17
ec7cea92fe8a Show stack on unhandled error.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 12
diff changeset
48 console.log('\033[41;1mUncaught exception (' + err + '), this should never happen:\033[0m\n' + err.stack);
11
0ed3c06c5191 Add an uncaught exceptions caughter to prevent the server from crashing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 10
diff changeset
49 });
0ed3c06c5191 Add an uncaught exceptions caughter to prevent the server from crashing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 10
diff changeset
50
8
efe8dbd34780 Rename cx method to cnode and define it if xmpp.js didn’t.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 7
diff changeset
51 if (typeof xmpp.StanzaBuilder.cnode != 'function' || typeof xmpp.StanzaBuilder.prototype.cnode != 'function') {
efe8dbd34780 Rename cx method to cnode and define it if xmpp.js didn’t.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 7
diff changeset
52 xmpp.StanzaBuilder.prototype.cnode = function (stanza)
efe8dbd34780 Rename cx method to cnode and define it if xmpp.js didn’t.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 7
diff changeset
53 {
efe8dbd34780 Rename cx method to cnode and define it if xmpp.js didn’t.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 7
diff changeset
54 var parent = this;
efe8dbd34780 Rename cx method to cnode and define it if xmpp.js didn’t.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 7
diff changeset
55 parent.tags.push(stanza);
efe8dbd34780 Rename cx method to cnode and define it if xmpp.js didn’t.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 7
diff changeset
56 parent.children.push(stanza);
efe8dbd34780 Rename cx method to cnode and define it if xmpp.js didn’t.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 7
diff changeset
57 return this;
efe8dbd34780 Rename cx method to cnode and define it if xmpp.js didn’t.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 7
diff changeset
58 };
efe8dbd34780 Rename cx method to cnode and define it if xmpp.js didn’t.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 7
diff changeset
59 }
efe8dbd34780 Rename cx method to cnode and define it if xmpp.js didn’t.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 7
diff changeset
60
0
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
61 function onIq(stanza) {
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
62 var type = stanza.getAttribute('type');
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
63 var from = stanza.getAttribute('to');
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
64 var to = stanza.getAttribute('from');
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
65 var id = stanza.getAttribute('id');
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
66
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
67 var response;
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
68 if (id)
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
69 response = xmpp.iq({to: to, from: from, type: 'result', id: id});
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
70 else
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
71 response = xmpp.iq({to: to, from: from, type: 'result'});
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
72
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
73 if (type == 'get') {
1
c2954a9e5665 Add a super-owner that has power over all nodes; add support for
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 0
diff changeset
74
9
a6429f48e403 First implementation of XEP-0050 (ad-hoc commands).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8
diff changeset
75 // XEP-0092: Software Version
0
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
76 if (stanza.getChild('query', 'jabber:iq:version')) {
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
77 var query = xmpp.stanza('query', {xmlns: 'jabber:iq:version'})
1
c2954a9e5665 Add a super-owner that has power over all nodes; add support for
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 0
diff changeset
78 .s('name').t('PSĜS')
c2954a9e5665 Add a super-owner that has power over all nodes; add support for
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 0
diff changeset
79 .s('version').t(config.version)
c2954a9e5665 Add a super-owner that has power over all nodes; add support for
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 0
diff changeset
80 .s('os').t(config.os);
8
efe8dbd34780 Rename cx method to cnode and define it if xmpp.js didn’t.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 7
diff changeset
81 response.cnode(query);
0
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
82
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
83 // SECTION 5.1
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
84 } else if (stanza.getChild('query', 'http://jabber.org/protocol/disco#info')) {
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
85 var query = stanza.getChild('query', 'http://jabber.org/protocol/disco#info');
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
86 var nodeID = query.getAttribute('node');
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
87
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
88 // SECTION 5.3
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
89 if (nodeID && nodeID != '') {
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
90 if (!storage.existsNode(nodeID))
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
91 return makeError(response, errors.node_does_not_exist.n);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
92
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
93 var conf = storage.getConfiguration(nodeID);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
94 if (typeof conf == 'number')
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
95 return makeError(response, conf);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
96
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
97 var type = 'leaf'
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
98 if (conf['pubsub#node_type'])
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
99 type = conf['pubsub#node_type'];
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
100
6
2bcadb0531f4 A few changes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 4
diff changeset
101 var q = xmpp.stanza('query', {xmlns: 'http://jabber.org/protocol/disco#info', node: nodeID})
0
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
102 q.s('identity', {category: 'pubsub', type: type});
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
103 q.s('feature', {'var': 'http://jabber.org/protocol/pubsub'});
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
104
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
105 // SECTION 5.4
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
106 if (config.enabled('meta-data')) {
4
4c93e76fa371 Ensure that the creator of a node is the default owner; don’t crash
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 3
diff changeset
107 var x = forms.build('result', 'node_metadata', storage.getMetadata(nodeID), true);
0
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
108 if (x)
8
efe8dbd34780 Rename cx method to cnode and define it if xmpp.js didn’t.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 7
diff changeset
109 q.cnode(x);
0
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
110 }
8
efe8dbd34780 Rename cx method to cnode and define it if xmpp.js didn’t.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 7
diff changeset
111 response.cnode(q);
0
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
112
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
113 // SECTION 5.1
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
114 } else {
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
115 var q = xmpp.stanza('query', {xmlns: 'http://jabber.org/protocol/disco#info'})
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
116 .s('identity', {category: 'pubsub', type: 'service', name: 'PubSub JavaScript Server'})
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
117 .s('feature', {'var': 'http://jabber.org/protocol/disco#info'})
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
118 .s('feature', {'var': 'http://jabber.org/protocol/disco#items'})
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
119 .s('feature', {'var': 'http://jabber.org/protocol/pubsub'})
1
c2954a9e5665 Add a super-owner that has power over all nodes; add support for
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 0
diff changeset
120 .s('feature', {'var': 'jabber:iq:version'})
9
a6429f48e403 First implementation of XEP-0050 (ad-hoc commands).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8
diff changeset
121 .s('feature', {'var': 'http://jabber.org/protocol/commands'});
a6429f48e403 First implementation of XEP-0050 (ad-hoc commands).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8
diff changeset
122
a6429f48e403 First implementation of XEP-0050 (ad-hoc commands).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8
diff changeset
123 for (var i in config.activated)
a6429f48e403 First implementation of XEP-0050 (ad-hoc commands).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8
diff changeset
124 if (typeof i == 'string')
a6429f48e403 First implementation of XEP-0050 (ad-hoc commands).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8
diff changeset
125 q.s('feature', {'var': 'http://jabber.org/protocol/pubsub#' + config.activated[i]});
a6429f48e403 First implementation of XEP-0050 (ad-hoc commands).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8
diff changeset
126
8
efe8dbd34780 Rename cx method to cnode and define it if xmpp.js didn’t.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 7
diff changeset
127 response.cnode(q);
0
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
128 }
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
129
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
130 // SECTION 5.2
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
131 } else if (stanza.getChild('query', 'http://jabber.org/protocol/disco#items')) {
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
132 var query = stanza.getChild('query', 'http://jabber.org/protocol/disco#items');
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
133 var q;
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
134 var children;
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
135 var nodeID = query.getAttribute('node');
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
136 if (nodeID && nodeID != '') {
9
a6429f48e403 First implementation of XEP-0050 (ad-hoc commands).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8
diff changeset
137 if (nodeID == 'http://jabber.org/protocol/commands') {
a6429f48e403 First implementation of XEP-0050 (ad-hoc commands).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8
diff changeset
138 // XEP-0050: Ad-Hoc Commands
a6429f48e403 First implementation of XEP-0050 (ad-hoc commands).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8
diff changeset
139
a6429f48e403 First implementation of XEP-0050 (ad-hoc commands).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8
diff changeset
140 q = xmpp.stanza('query', {xmlns: 'http://jabber.org/protocol/disco#items', node: nodeID})
a6429f48e403 First implementation of XEP-0050 (ad-hoc commands).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8
diff changeset
141 .s('item', {jid: componentJID, node: 'ping', name: 'Ping'})
a6429f48e403 First implementation of XEP-0050 (ad-hoc commands).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8
diff changeset
142 .s('item', {jid: componentJID, node: 'reload', name: 'Reload'});
0
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
143
9
a6429f48e403 First implementation of XEP-0050 (ad-hoc commands).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8
diff changeset
144 response.cnode(q);
a6429f48e403 First implementation of XEP-0050 (ad-hoc commands).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8
diff changeset
145 return conn.send(response);
a6429f48e403 First implementation of XEP-0050 (ad-hoc commands).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8
diff changeset
146 } else {
a6429f48e403 First implementation of XEP-0050 (ad-hoc commands).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8
diff changeset
147 if (!storage.existsNode(nodeID))
a6429f48e403 First implementation of XEP-0050 (ad-hoc commands).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8
diff changeset
148 return makeError(response, errors.node_does_not_exist.n);
0
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
149
9
a6429f48e403 First implementation of XEP-0050 (ad-hoc commands).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8
diff changeset
150 q = xmpp.stanza('query', {xmlns: 'http://jabber.org/protocol/disco#items', node: nodeID});
a6429f48e403 First implementation of XEP-0050 (ad-hoc commands).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8
diff changeset
151
a6429f48e403 First implementation of XEP-0050 (ad-hoc commands).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8
diff changeset
152 children = storage.getChildren(nodeID);
a6429f48e403 First implementation of XEP-0050 (ad-hoc commands).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8
diff changeset
153 if (typeof children == 'number')
a6429f48e403 First implementation of XEP-0050 (ad-hoc commands).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8
diff changeset
154 return makeError(response, children);
a6429f48e403 First implementation of XEP-0050 (ad-hoc commands).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8
diff changeset
155 }
0
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
156 } else {
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
157 q = xmpp.stanza('query', {xmlns: 'http://jabber.org/protocol/disco#items'});
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
158
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
159 children = storage.getChildren();
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
160 if (typeof children == 'number')
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
161 return makeError(response, children);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
162 }
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
163
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
164 for (var i in children) {
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
165 var attr = {jid: componentJID};
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
166 if (children[i] == 'node') {
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
167 if (config.enabled('meta-data')) {
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
168 var metadata = storage.getMetadata(i);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
169 if (metadata['pubsub#title'])
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
170 attr.name = metadata['pubsub#title'];
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
171 }
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
172 attr.node = i;
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
173
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
174 // SECTION 5.5
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
175 } else
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
176 attr.name = i;
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
177
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
178 q.s('item', attr);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
179 }
8
efe8dbd34780 Rename cx method to cnode and define it if xmpp.js didn’t.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 7
diff changeset
180 response.cnode(q);
0
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
181 } else if (stanza.getChild('pubsub', 'http://jabber.org/protocol/pubsub')) {
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
182 var pubsub = stanza.getChild('pubsub', 'http://jabber.org/protocol/pubsub');
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
183
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
184 // SECTION 5.6
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
185 if (pubsub.getChild('subscriptions')) {
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
186 if (!config.enabled('retrieve-subscriptions'))
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
187 return makeError(response, errors.subscriptions_retrieval_not_supported.n);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
188
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
189 var subscriptions = pubsub.getChild('subscriptions');
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
190 var subs;
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
191
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
192 var nodeID = subscriptions.getAttribute('node');
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
193 if (nodeID && nodeID != '') {
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
194 if (!storage.existsNode(nodeID))
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
195 return makeError(response, errors.node_does_not_exist.n);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
196 subs = storage.getSubscription(toBareJID(to), node);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
197 } else
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
198 subs = storage.getSubscription(toBareJID(to));
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
199
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
200 var s = xmpp.stanza('subscriptions');
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
201 for (i in subs)
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
202 s.s('subscription', {node: i, jid: to, subscription: subs[i].type, subid: subs[i].subid});
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
203
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
204 var p = xmpp.stanza('pubsub', {xmlns: 'http://jabber.org/protocol/pubsub'});
8
efe8dbd34780 Rename cx method to cnode and define it if xmpp.js didn’t.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 7
diff changeset
205 p.cnode(s);
efe8dbd34780 Rename cx method to cnode and define it if xmpp.js didn’t.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 7
diff changeset
206 response.cnode(p);
0
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
207
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
208 // SECTION 5.7
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
209 } else if (pubsub.getChild('affiliations')) {
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
210 if (!config.enabled('retrieve-affiliations'))
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
211 return makeError(response, errors.affiliations_retrieval_not_supported.n);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
212
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
213 var affiliations = pubsub.getChild('affiliations');
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
214 var nodeID = affiliations.getAttribute('node');
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
215 var affils;
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
216 if (nodeID && nodeID != '') {
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
217 if (!storage.existsNode(nodeID))
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
218 return makeError(response, errors.node_does_not_exist.n);
6
2bcadb0531f4 A few changes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 4
diff changeset
219 affils = {};
2bcadb0531f4 A few changes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 4
diff changeset
220 affils[nodeID] = storage.getAffiliation(toBareJID(to), nodeID);
0
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
221 } else
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
222 affils = storage.getAffiliationsFromJID(toBareJID(to));
6
2bcadb0531f4 A few changes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 4
diff changeset
223
0
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
224 var s = xmpp.stanza('affiliations');
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
225 for (i in affils)
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
226 s.s('affiliation', {node: i, affiliation: affils[i]});
6
2bcadb0531f4 A few changes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 4
diff changeset
227
0
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
228 var p = xmpp.stanza('pubsub', {xmlns: 'http://jabber.org/protocol/pubsub'});
8
efe8dbd34780 Rename cx method to cnode and define it if xmpp.js didn’t.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 7
diff changeset
229 p.cnode(s);
efe8dbd34780 Rename cx method to cnode and define it if xmpp.js didn’t.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 7
diff changeset
230 response.cnode(p);
0
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
231
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
232 // SECTION 6.3.2
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
233 } else if (pubsub.getChild('options')) {
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
234 if (!config.enabled('subscription-options'))
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
235 return makeError(response, errors.sub.configure.subscription_options_not_supported.n);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
236
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
237 var options = pubsub.getChild('options');
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
238
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
239 var nodeID = options.getAttribute('node');
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
240 if (!nodeID || nodeID == '')
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
241 return makeError(response, errors.nodeid_required.n);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
242 if (!storage.existsNode(nodeID))
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
243 return makeError(response, errors.node_does_not_exist.n);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
244
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
245 var jid = options.getAttribute('jid');
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
246 if (!jid)
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
247 return makeError(response, errors.sub.configure.subscriber_jid_required.n);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
248 if (toBareJID(jid) != toBareJID(to))
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
249 return makeError(response, errors.sub.configure.insufficient_privileges.n);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
250
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
251 var subs = storage.getSubscription(jid, nodeID);
19
032090a13fe8 Can’t send subscription-options to non-subscribed people.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 18
diff changeset
252 if (!subs.subid) // FIXME: better test for empty object.
0
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
253 return makeError(response, errors.sub.configure.no_such_subscriber.n);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
254
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
255 var s = xmpp.stanza('options', {node: nodeID, jid: jid});
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
256 var p = xmpp.stanza('pubsub', {xmlns: 'http://jabber.org/protocol/pubsub'});
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
257 var form = forms.build('form', 'subscribe_options', subs.options, true);
8
efe8dbd34780 Rename cx method to cnode and define it if xmpp.js didn’t.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 7
diff changeset
258 s.cnode(form);
efe8dbd34780 Rename cx method to cnode and define it if xmpp.js didn’t.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 7
diff changeset
259 p.cnode(s);
efe8dbd34780 Rename cx method to cnode and define it if xmpp.js didn’t.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 7
diff changeset
260 response.cnode(p);
0
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
261
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
262 // SECTION 6.4
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
263 } else if (pubsub.getChild('default')) {
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
264 if (!config.enabled('retrieve-default-sub'))
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
265 return makeError(response, errors.sub.default_options.default_subscription_configuration_retrieval_not_supported.n);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
266
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
267 var def = pubsub.getChild('default');
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
268
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
269 var nodeID = def.getAttribute('node');
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
270 if (nodeID && !storage.existsNode(nodeID))
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
271 return makeError(response, errors.node_does_not_exist.n);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
272
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
273 var p = xmpp.stanza('pubsub', {xmlns: 'http://jabber.org/protocol/pubsub'});
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
274 var s;
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
275 if (nodeID)
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
276 s = xmpp.stanza('default', {node: nodeID});
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
277 else
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
278 s = xmpp.stanza('default');
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
279
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
280 var form = forms.build('form', 'subscribe_options', 'default', false);
8
efe8dbd34780 Rename cx method to cnode and define it if xmpp.js didn’t.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 7
diff changeset
281 s.cnode(form);
efe8dbd34780 Rename cx method to cnode and define it if xmpp.js didn’t.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 7
diff changeset
282 p.cnode(s);
efe8dbd34780 Rename cx method to cnode and define it if xmpp.js didn’t.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 7
diff changeset
283 response.cnode(p);
0
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
284
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
285 // SECTION 6.5
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
286 } else if (pubsub.getChild('items')) {
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
287 if (!config.enabled('retrieve-items'))
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
288 return makeError(response, errors.sub.default_options.node_configuration_not_supported.n);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
289
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
290 var items = pubsub.getChild('items');
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
291
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
292 var nodeID = items.getAttribute('node');
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
293 if (!nodeID || nodeID == '')
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
294 return makeError(response, errors.nodeid_required.n);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
295 if (!storage.existsNode(nodeID))
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
296 return makeError(response, errors.node_does_not_exist.n);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
297
6
2bcadb0531f4 A few changes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 4
diff changeset
298 var configuration = storage.getConfiguration(nodeID);
2bcadb0531f4 A few changes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 4
diff changeset
299 if (configuration['pubsub#access_model'] == 'whitelist') {
2bcadb0531f4 A few changes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 4
diff changeset
300 var affil = storage.getAffiliation(toBareJID(to), nodeID);
2bcadb0531f4 A few changes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 4
diff changeset
301 if (affil != 'super-owner' && affil != 'owner' && affil != 'publisher' && affil != 'member')
2bcadb0531f4 A few changes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 4
diff changeset
302 return makeError(response, errors.pub.publish.insufficient_privileges.n);
2bcadb0531f4 A few changes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 4
diff changeset
303 }
0
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
304
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
305 var item = [];
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
306 for (var i=0; i<items.children.length; i++) {
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
307 var j = items.children[i];
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
308 if (j.name == 'item' && j.attr['id'] && j.attr['id'] != '')
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
309 item.push(j.attr['id']);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
310 }
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
311
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
312 var max_items = items.getAttribute('max_items');
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
313 if (max_items)
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
314 max_items = Number (max_items);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
315
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
316 if (item.length) {
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
317 var s = xmpp.stanza('items', {node: nodeID});
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
318
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
319 for (var i=0; i<item.length; i++) {
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
320 var j = storage.getItem(nodeID, item[i]);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
321 if (typeof j == 'number')
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
322 return makeError(response, j);
10
44889cfb2f8c Fix getItem method.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 9
diff changeset
323 if (j == errors.success)
44889cfb2f8c Fix getItem method.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 9
diff changeset
324 continue;
0
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
325
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
326 var k = xmpp.stanza('item', {id: item[i]})
8
efe8dbd34780 Rename cx method to cnode and define it if xmpp.js didn’t.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 7
diff changeset
327 k.cnode(j);
efe8dbd34780 Rename cx method to cnode and define it if xmpp.js didn’t.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 7
diff changeset
328 s.cnode(k);
0
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
329 }
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
330 } else {
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
331 var s = xmpp.stanza('items', {node: nodeID});
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
332
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
333 var j;
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
334 if (max_items)
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
335 j = storage.getLastItem(nodeID, max_items);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
336 else
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
337 j = storage.getItems(nodeID);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
338 if (typeof j == 'number')
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
339 return makeError(response, j);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
340
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
341 var k = 0;
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
342 for (var i in j) {
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
343 var contentItem = xmpp.stanza('item', {id: i}).t(j[i].content);
8
efe8dbd34780 Rename cx method to cnode and define it if xmpp.js didn’t.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 7
diff changeset
344 s.cnode(contentItem);
0
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
345 }
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
346 }
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
347 var p = xmpp.stanza('pubsub', {xmlns: 'http://jabber.org/protocol/pubsub'});
8
efe8dbd34780 Rename cx method to cnode and define it if xmpp.js didn’t.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 7
diff changeset
348 p.cnode(s);
efe8dbd34780 Rename cx method to cnode and define it if xmpp.js didn’t.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 7
diff changeset
349 response.cnode(p);
0
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
350 } else
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
351 return makeError(response, errors.feature_not_implemented.n);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
352 } else if (stanza.getChild('pubsub', 'http://jabber.org/protocol/pubsub#owner')) {
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
353 var pubsub = stanza.getChild('pubsub', 'http://jabber.org/protocol/pubsub#owner');
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
354
1
c2954a9e5665 Add a super-owner that has power over all nodes; add support for
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 0
diff changeset
355 // SECTION 8.2
0
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
356 if (pubsub.getChild('configure')) {
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
357 if (!config.enabled('config-node'))
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
358 return makeError(response, errors.owner.configure.node_configuration_not_supported.n);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
359
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
360 var nodeID = pubsub.getChild('configure').getAttribute('node');
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
361 if (!nodeID || nodeID == '')
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
362 return makeError(response, errors.nodeid_required.n);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
363 if (!storage.existsNode(nodeID))
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
364 return makeError(response, errors.node_does_not_exist.n);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
365
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
366 var affil = storage.getAffiliation(toBareJID(to), nodeID);
1
c2954a9e5665 Add a super-owner that has power over all nodes; add support for
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 0
diff changeset
367 if (affil != 'super-owner' && affil != 'owner' && affil != 'publish-only')
0
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
368 return makeError(response, errors.pub.publish.insufficient_privileges.n);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
369
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
370 var p = xmpp.stanza('pubsub', {xmlns: 'http://jabber.org/protocol/pubsub#owner'});
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
371 var s = xmpp.stanza('configure', {node: nodeID});
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
372 var form = forms.build('form', 'node_config', 'default', true);
8
efe8dbd34780 Rename cx method to cnode and define it if xmpp.js didn’t.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 7
diff changeset
373 s.cnode(form);
efe8dbd34780 Rename cx method to cnode and define it if xmpp.js didn’t.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 7
diff changeset
374 p.cnode(s);
efe8dbd34780 Rename cx method to cnode and define it if xmpp.js didn’t.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 7
diff changeset
375 response.cnode(p);
0
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
376
1
c2954a9e5665 Add a super-owner that has power over all nodes; add support for
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 0
diff changeset
377 // SECTION 8.3
0
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
378 } else if (pubsub.getChild('default')) {
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
379 if (!config.enabled('config-node'))
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
380 return makeError(response, errors.owner.default_options.node_configuration_not_supported.n);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
381
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
382 var p = xmpp.stanza('pubsub', {xmlns: 'http://jabber.org/protocol/pubsub#owner'});
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
383 var s = xmpp.stanza('default');
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
384 var form = forms.build('node_config', service_configuration.node_config, null, true);
8
efe8dbd34780 Rename cx method to cnode and define it if xmpp.js didn’t.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 7
diff changeset
385 s.cnode(form);
efe8dbd34780 Rename cx method to cnode and define it if xmpp.js didn’t.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 7
diff changeset
386 p.cnode(s);
efe8dbd34780 Rename cx method to cnode and define it if xmpp.js didn’t.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 7
diff changeset
387 response.cnode(p);
0
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
388
1
c2954a9e5665 Add a super-owner that has power over all nodes; add support for
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 0
diff changeset
389 // SECTION 8.8
0
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
390 } else if (pubsub.getChild('subscriptions')) {
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
391 if (!config.enabled('manage-subscriptions'))
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
392 return makeError(response, errors.owner.manage_subscriptions.not_supported.n);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
393
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
394 var subscriptions = pubsub.getChild('subscriptions');
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
395
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
396 var nodeID = subscriptions.getAttribute('node');
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
397 if (!nodeID || nodeID == '')
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
398 return makeError(response, errors.nodeid_required.n);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
399 if (!storage.existsNode(nodeID))
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
400 return makeError(response, errors.node_does_not_exist.n);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
401
1
c2954a9e5665 Add a super-owner that has power over all nodes; add support for
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 0
diff changeset
402 var affil = storage.getAffiliation(toBareJID(to), nodeID);
c2954a9e5665 Add a super-owner that has power over all nodes; add support for
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 0
diff changeset
403 if (affil != 'super-owner' && affil != 'owner')
0
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
404 return makeError(response, errors.forbidden.n);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
405
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
406 var p = xmpp.stanza('pubsub', {xmlns: 'http://jabber.org/protocol/pubsub#owner'});
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
407 var s = xmpp.stanza('subscriptions', {node: nodeID});
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
408
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
409 var subs = storage.getSubscriptionsFromNodeID(nodeID)
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
410 for (var jid in subs)
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
411 s.s('subscription', {jid: jid, subscription: subs[jid].type, subid: subs[jid].subid})
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
412
8
efe8dbd34780 Rename cx method to cnode and define it if xmpp.js didn’t.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 7
diff changeset
413 p.cnode(s);
efe8dbd34780 Rename cx method to cnode and define it if xmpp.js didn’t.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 7
diff changeset
414 response.cnode(p);
0
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
415
1
c2954a9e5665 Add a super-owner that has power over all nodes; add support for
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 0
diff changeset
416 // SECTION 8.9
0
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
417 } else if (pubsub.getChild('affiliations')) {
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
418 if (!config.enabled('modify-affiliations'))
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
419 return makeError(response, errors.owner.manage_affiliations.not_supported.n);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
420
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
421 var affiliations = pubsub.getChild('affiliations');
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
422
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
423 var nodeID = affiliations.getAttribute('node');
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
424 if (!nodeID || nodeID == '')
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
425 return makeError(response, errors.nodeid_required.n);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
426 if (!storage.existsNode(nodeID))
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
427 return makeError(response, errors.node_does_not_exist.n);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
428
1
c2954a9e5665 Add a super-owner that has power over all nodes; add support for
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 0
diff changeset
429 var affils = storage.getAffiliationsFromNodeID(nodeID);
c2954a9e5665 Add a super-owner that has power over all nodes; add support for
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 0
diff changeset
430 var affil = affils[toBareJID(to)];
c2954a9e5665 Add a super-owner that has power over all nodes; add support for
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 0
diff changeset
431 if (affil != 'super-owner' && affil != 'owner')
0
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
432 return makeError(response, errors.owner.manage_affiliations.retrieve_list.entity_is_not_an_owner.n);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
433
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
434 var p = xmpp.stanza('pubsub', {xmlns: 'http://jabber.org/protocol/pubsub#owner'});
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
435 var s = xmpp.stanza('affiliations', {node: nodeID});
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
436
1
c2954a9e5665 Add a super-owner that has power over all nodes; add support for
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 0
diff changeset
437 for (var jid in affils)
c2954a9e5665 Add a super-owner that has power over all nodes; add support for
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 0
diff changeset
438 s.s('affiliation', {jid: jid, affiliation: affils[jid]})
0
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
439
8
efe8dbd34780 Rename cx method to cnode and define it if xmpp.js didn’t.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 7
diff changeset
440 p.cnode(s);
efe8dbd34780 Rename cx method to cnode and define it if xmpp.js didn’t.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 7
diff changeset
441 response.cnode(p);
0
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
442 } else
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
443 return makeError(response, errors.feature_not_implemented.n);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
444 } else
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
445 return makeError(response, errors.feature_not_implemented.n);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
446 } else if (type == 'set') {
9
a6429f48e403 First implementation of XEP-0050 (ad-hoc commands).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8
diff changeset
447 if (stanza.getChild('command', 'http://jabber.org/protocol/commands')) {
a6429f48e403 First implementation of XEP-0050 (ad-hoc commands).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8
diff changeset
448 // XEP-0050: Ad-Hoc Commands
a6429f48e403 First implementation of XEP-0050 (ad-hoc commands).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8
diff changeset
449 var command = stanza.getChild('command', 'http://jabber.org/protocol/commands');
a6429f48e403 First implementation of XEP-0050 (ad-hoc commands).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8
diff changeset
450
a6429f48e403 First implementation of XEP-0050 (ad-hoc commands).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8
diff changeset
451 var action = command.getAttribute('action');
a6429f48e403 First implementation of XEP-0050 (ad-hoc commands).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8
diff changeset
452 if (action != 'execute')
a6429f48e403 First implementation of XEP-0050 (ad-hoc commands).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8
diff changeset
453 return makeError(response, errors.bad_request.n);
a6429f48e403 First implementation of XEP-0050 (ad-hoc commands).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8
diff changeset
454
a6429f48e403 First implementation of XEP-0050 (ad-hoc commands).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8
diff changeset
455 var node = command.getAttribute('node');
a6429f48e403 First implementation of XEP-0050 (ad-hoc commands).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8
diff changeset
456 if (node == 'ping') {
a6429f48e403 First implementation of XEP-0050 (ad-hoc commands).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8
diff changeset
457 var cmd = xmpp.stanza('command', {xmlns: 'http://jabber.org/protocol/commands',
a6429f48e403 First implementation of XEP-0050 (ad-hoc commands).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8
diff changeset
458 // sessionid: 'list:20020923T213616Z-700',
a6429f48e403 First implementation of XEP-0050 (ad-hoc commands).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8
diff changeset
459 node: node,
a6429f48e403 First implementation of XEP-0050 (ad-hoc commands).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8
diff changeset
460 'status': 'completed'})
a6429f48e403 First implementation of XEP-0050 (ad-hoc commands).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8
diff changeset
461 .c('note', {type: 'info'}).t('pong');
a6429f48e403 First implementation of XEP-0050 (ad-hoc commands).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8
diff changeset
462 response.cnode(cmd);
a6429f48e403 First implementation of XEP-0050 (ad-hoc commands).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8
diff changeset
463 } else if (node == 'reload') {
a6429f48e403 First implementation of XEP-0050 (ad-hoc commands).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8
diff changeset
464 storage.load();
a6429f48e403 First implementation of XEP-0050 (ad-hoc commands).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8
diff changeset
465 response.c('command', {xmlns: 'http://jabber.org/protocol/commands',
a6429f48e403 First implementation of XEP-0050 (ad-hoc commands).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8
diff changeset
466 node: node,
a6429f48e403 First implementation of XEP-0050 (ad-hoc commands).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8
diff changeset
467 'status': 'completed'})
a6429f48e403 First implementation of XEP-0050 (ad-hoc commands).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8
diff changeset
468 .c('note', {type: 'info'}).t('The server has correctly reloaded.');
a6429f48e403 First implementation of XEP-0050 (ad-hoc commands).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8
diff changeset
469 } else
a6429f48e403 First implementation of XEP-0050 (ad-hoc commands).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8
diff changeset
470 return makeError(response, errors.bad_request.n);
a6429f48e403 First implementation of XEP-0050 (ad-hoc commands).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8
diff changeset
471 } else if (stanza.getChild('pubsub', 'http://jabber.org/protocol/pubsub')) {
0
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
472 var pubsub = stanza.getChild('pubsub', 'http://jabber.org/protocol/pubsub');
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
473
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
474 // SECTION 6.1
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
475 if (pubsub.getChild('subscribe')) {
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
476 if (!config.enabled('subscribe'))
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
477 return makeError(response, errors.sub.subscribe.not_supported.n);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
478
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
479 var subscribe = pubsub.getChild('subscribe');
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
480
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
481 var nodeID = subscribe.getAttribute('node');
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
482 if (!nodeID || nodeID == '')
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
483 return makeError(response, errors.nodeid_required.n);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
484 if (!storage.existsNode(nodeID))
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
485 return makeError(response, errors.node_does_not_exist.n);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
486
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
487 var configuration = storage.getConfiguration(nodeID);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
488 if (!configuration['pubsub#subscribe'])
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
489 return makeError(response, errors.sub.subscribe.not_supported.n);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
490
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
491 var affil = storage.getAffiliation(toBareJID(to), nodeID);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
492 if (affil == 'publish-only' || affil == 'outcast')
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
493 return makeError(response, errors.pub.publish.insufficient_privileges.n);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
494
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
495 var jid = subscribe.getAttribute('jid');
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
496 if (!jid || toBareJID(jid) != toBareJID(to))
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
497 return makeError(response, errors.sub.subscribe.jids_do_not_match.n);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
498
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
499 // SECTION 6.3.7
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
500 var options = pubsub.getChild('options');
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
501 if (options && config.enabled('subscription-options')) {
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
502 if (options.getAttribute('node') || options.getAttribute('jid'))
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
503 return makeError(response, errors.bad_request.n);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
504
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
505 var x = options.getChild('x', 'jabber:x:data');
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
506 if (!x || x.getAttribute('type') != 'submit')
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
507 return makeError(response, errors.bad_request.n);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
508
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
509 var form = forms.parse(x, true);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
510 if (typeof form == 'number')
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
511 return makeError(response, form);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
512
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
513 var conf = form;
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
514 }
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
515
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
516 var subID;
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
517 if (configuration['pubsub#access_model'] == 'open') {
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
518 subID = storage.subscribe(nodeID, jid, 'subscribe', conf);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
519 if (typeof subID == 'number')
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
520 return makeError(response, subID);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
521 } else if (configuration['pubsub#access_model'] == 'authorize') {
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
522 subID = storage.subscribe(nodeID, jid, 'pending', conf);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
523 if (typeof subID == 'number')
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
524 return makeError(response, subID);
18
75625771e410 Send subscription request only if node access_model is authorize.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 17
diff changeset
525
75625771e410 Send subscription request only if node access_model is authorize.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 17
diff changeset
526 var affiliates = storage.getAffiliationsFromNodeID(nodeID);
75625771e410 Send subscription request only if node access_model is authorize.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 17
diff changeset
527 var form = forms.build('form', 'subscribe_authorization', {allow: false, node: nodeID, subscriber_jid: jid}, true); //168
75625771e410 Send subscription request only if node access_model is authorize.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 17
diff changeset
528
75625771e410 Send subscription request only if node access_model is authorize.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 17
diff changeset
529 for (var i in affiliates) {
75625771e410 Send subscription request only if node access_model is authorize.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 17
diff changeset
530 if (affiliates[i] == 'super-owner' || affiliates[i] == 'owner') {
75625771e410 Send subscription request only if node access_model is authorize.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 17
diff changeset
531 var message = xmpp.message({to: i}).cnode(form);
75625771e410 Send subscription request only if node access_model is authorize.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 17
diff changeset
532 conn.send(message);
75625771e410 Send subscription request only if node access_model is authorize.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 17
diff changeset
533 }
75625771e410 Send subscription request only if node access_model is authorize.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 17
diff changeset
534 }
0
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
535 } else if (configuration['pubsub#access_model'] == 'whitelist') {
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
536 var affil = storage.getAffiliation(jid, nodeID);
1
c2954a9e5665 Add a super-owner that has power over all nodes; add support for
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 0
diff changeset
537 if (affil != 'super-owner' && affil != 'owner' && affil != 'publisher' && affil != 'member')
0
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
538 return makeError(response, errors.sub.subscribe.not_on_whitelist.n);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
539
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
540 subID = storage.subscribe(nodeID, jid, conf);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
541 if (typeof subID == 'number')
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
542 return makeError(response, subID);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
543 }
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
544
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
545 response.c('pubsub', {xmlns: 'http://jabber.org/protocol/pubsub'})
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
546 .c('subscription', {node: nodeID, jid: jid, subid: subID.subid, subscription: subID.type});
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
547
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
548 if (conf)
8
efe8dbd34780 Rename cx method to cnode and define it if xmpp.js didn’t.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 7
diff changeset
549 response.cnode(options);
0
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
550
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
551 if (config.enabled('last-published')) {
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
552 var last = storage.getLastItem(nodeID);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
553 if (typeof last != 'number') {
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
554 var item = storage.getItem(nodeID, last);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
555 if (typeof item != 'number') {
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
556 var attr = {};
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
557 attr[last] = {content: item};
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
558 sendNotifs(jid, 'items', nodeID, attr);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
559 }
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
560 }
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
561 }
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
562
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
563 // SECTION 6.2
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
564 } else if (pubsub.getChild('unsubscribe')) {
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
565 if (!config.enabled('subscribe'))
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
566 return makeError(response, errors.sub.subscribe.not_supported.n);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
567
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
568 var unsubscribe = pubsub.getChild('unsubscribe');
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
569 var nodeID = unsubscribe.getAttribute('node');
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
570 if (!nodeID || nodeID == '')
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
571 return makeError(response, errors.nodeid_required.n);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
572 if (!storage.existsNode(nodeID))
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
573 return makeError(response, errors.node_does_not_exist.n);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
574
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
575 var jid = unsubscribe.getAttribute('jid');
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
576 if (!jid || toBareJID(jid) != toBareJID(to))
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
577 return makeError(response, errors.sub.unsubscribe.insufficient_privileges.n);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
578
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
579 var subID = storage.subscribe(nodeID, jid, 'none');
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
580 if (typeof subID == 'number')
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
581 return makeError(response, subID);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
582
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
583 // SECTIONS 6.3.5
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
584 } else if (pubsub.getChild('options')) {
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
585 if (!config.enabled('subscription-options'))
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
586 return makeError(response, errors.sub.subscribe.not_supported.n);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
587
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
588 var options = pubsub.getChild('options');
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
589
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
590 var nodeID = unsubscribe.getAttribute('node');
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
591 if (!nodeID || nodeID == '')
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
592 return makeError(response, errors.nodeid_required.n);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
593 if (!storage.existsNode(nodeID))
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
594 return makeError(response, errors.node_does_not_exist.n);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
595
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
596 var jid = unsubscribe.getAttribute('jid');
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
597 if (!jid || toBareJID(jid) != toBareJID(to))
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
598 return makeError(response, errors.sub.unsubscribe.insufficient_privileges.n);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
599
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
600 var x = options.getChild('x', 'jabber:x:data');
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
601 if (!x || x.getAttribute(type) != 'submit')
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
602 return makeError(response, errors.bad_request);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
603
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
604 var form = forms.parse(x, true);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
605 if (typeof form == 'number')
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
606 return makeError(response, form);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
607
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
608 var set = storage.configureSubscription(nodeID, jid, form);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
609 if (typeof form == 'number')
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
610 return makeError(response, form);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
611
1
c2954a9e5665 Add a super-owner that has power over all nodes; add support for
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 0
diff changeset
612 // SECTION 7.1
0
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
613 } else if (pubsub.getChild('publish')) {
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
614 if (!config.enabled('publish'))
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
615 return makeError(response, errors.pub.publish.item_publication_not_supported.n);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
616
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
617 var publish = pubsub.getChild('publish');
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
618 var nodeID = publish.getAttribute('node');
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
619 if (!nodeID || nodeID == '')
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
620 return makeError(response, errors.nodeid_required.n);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
621
6
2bcadb0531f4 A few changes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 4
diff changeset
622 var autocreate = false;
2bcadb0531f4 A few changes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 4
diff changeset
623 if (!storage.existsNode(nodeID)) {
2bcadb0531f4 A few changes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 4
diff changeset
624 if (config.enabled('auto-create'))
2bcadb0531f4 A few changes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 4
diff changeset
625 autocreate = true;
2bcadb0531f4 A few changes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 4
diff changeset
626 else
2bcadb0531f4 A few changes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 4
diff changeset
627 return makeError(response, errors.node_does_not_exist.n);
2bcadb0531f4 A few changes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 4
diff changeset
628 }
2bcadb0531f4 A few changes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 4
diff changeset
629
0
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
630 var affil = storage.getAffiliation(toBareJID(to), nodeID);
6
2bcadb0531f4 A few changes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 4
diff changeset
631 if (typeof affil == 'number' && affil != errors.node_does_not_exist.n)
0
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
632 return makeError(response, affil);
6
2bcadb0531f4 A few changes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 4
diff changeset
633 if (!autocreate && affil != 'super-owner' && affil != 'owner' && affil != 'publisher' && affil != 'publish-only')
0
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
634 return makeError(response, errors.forbidden.n);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
635
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
636 var item = publish.getChild('item');
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
637 var itemID = item.getAttribute('id');
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
638 if (!config.enabled('item-ids') && itemID)
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
639 return makeError(response, errors.itemid_required.n);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
640 itemID = itemID? itemID: utils.makeRandomId();
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
641
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
642 if (item.tags.length != 1)
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
643 return makeError(response, errors.pub.publish.bad_payload.n);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
644
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
645 var conf = storage.getConfiguration(nodeID);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
646 var publishOptions = pubsub.getChild('publish-options');
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
647 if (publishOptions && config.enabled('publish-options')) {
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
648 var x = publishOptions.getChild('x', 'jabber:x:data');
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
649 if (!x || x.getAttribute('type') != 'submit')
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
650 return makeError(response, errors.bad_request.n);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
651
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
652 var form = forms.parse(x, true);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
653 if (form.access_model != conf['pubsub#access_model'] && !autocreate)
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
654 return makeError(response, errors.pub.configuration.precondition.n);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
655 }
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
656
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
657 if (!config.enabled('persistent-items')) {
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
658 var notifs = storage.purgeNode(nodeID);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
659 if (typeof notifs == 'number')
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
660 return makeError(response, r);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
661 }
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
662
1
c2954a9e5665 Add a super-owner that has power over all nodes; add support for
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 0
diff changeset
663 if (autocreate) {
c2954a9e5665 Add a super-owner that has power over all nodes; add support for
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 0
diff changeset
664 if (!form)
c2954a9e5665 Add a super-owner that has power over all nodes; add support for
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 0
diff changeset
665 form = {};
c2954a9e5665 Add a super-owner that has power over all nodes; add support for
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 0
diff changeset
666 form['pubsub#creator'] = toBareJID(to);
c2954a9e5665 Add a super-owner that has power over all nodes; add support for
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 0
diff changeset
667
c2954a9e5665 Add a super-owner that has power over all nodes; add support for
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 0
diff changeset
668 var r = storage.createNode(nodeID, form);
c2954a9e5665 Add a super-owner that has power over all nodes; add support for
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 0
diff changeset
669 if (typeof r == 'number')
c2954a9e5665 Add a super-owner that has power over all nodes; add support for
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 0
diff changeset
670 return makeError(response, r);
c2954a9e5665 Add a super-owner that has power over all nodes; add support for
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 0
diff changeset
671 }
0
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
672
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
673 var content = item.getChild();
1
c2954a9e5665 Add a super-owner that has power over all nodes; add support for
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 0
diff changeset
674
0
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
675 subscribers = storage.setItem(nodeID, itemID, content);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
676 if (typeof subscribers == 'number')
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
677 return makeError(response, subscribers);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
678
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
679 var attrs = {};
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
680 if (content)
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
681 attrs[itemID] = {content: content};
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
682 else
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
683 attrs[itemID] = {};
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
684 sendNotifs(subscribers, 'items', nodeID, attrs);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
685
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
686 response.c('pubsub', {xmlns: 'http://jabber.org/protocol/pubsub'})
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
687 .c('publish', {node: nodeID})
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
688 .c('item', {id: itemID});
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
689
1
c2954a9e5665 Add a super-owner that has power over all nodes; add support for
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 0
diff changeset
690 // SECTION 7.2
0
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
691 } else if (pubsub.getChild('retract')) {
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
692 if (!config.enabled('retract-items'))
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
693 return makeError(response, errors.pub.retract.item_deletion_not_supported.n);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
694
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
695 var retract = pubsub.getChild('retract');
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
696
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
697 var nodeID = retract.getAttribute('node');
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
698 if (!nodeID || nodeID == '')
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
699 return makeError(response, errors.nodeid_required.n);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
700 if (!storage.existsNode(nodeID))
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
701 return makeError(response, errors.node_does_not_exist.n);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
702
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
703 var item = retract.getChild('item');
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
704 if (!item)
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
705 return makeError(response, errors.pub.retract.item_or_itemid_required.n);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
706
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
707 var itemID = item.getAttribute('id')
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
708 if (!itemID || itemID == '')
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
709 return makeError(response, errors.pub.retract.item_or_itemid_required.n);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
710
6
2bcadb0531f4 A few changes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 4
diff changeset
711 var affil = storage.getAffiliation(toBareJID(to), nodeID);
2bcadb0531f4 A few changes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 4
diff changeset
712 if (affil != 'super-owner' && affil != 'owner' && affil != 'publish-only')
2bcadb0531f4 A few changes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 4
diff changeset
713 return makeError(response, errors.forbidden.n);
2bcadb0531f4 A few changes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 4
diff changeset
714
0
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
715 var subscribers = storage.deleteItem(nodeID, itemID);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
716 if (typeof subscribers == 'number')
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
717 return makeError(response, subscribers);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
718
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
719 var attrs = {};
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
720 attrs[itemID] = {};
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
721 sendNotifs(subscribers, 'items', nodeID, attrs, 'retract')
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
722
1
c2954a9e5665 Add a super-owner that has power over all nodes; add support for
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 0
diff changeset
723 // SECTION 8.1
0
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
724 } else if (pubsub.getChild('create')) {
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
725 if (!config.enabled('create-nodes'))
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
726 return makeError(response, errors.owner.create.node_creation_not_supported.n);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
727
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
728 var instant = false;
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
729
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
730 var nodeID = pubsub.getChild('create').getAttribute('node');
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
731 if (!nodeID || nodeID == '') {
4
4c93e76fa371 Ensure that the creator of a node is the default owner; don’t crash
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 3
diff changeset
732 if (!config.enabled('instant-nodes'))
0
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
733 return makeError(response, errors.owner.create.instant_nodes_not_supported.n);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
734 nodeID = utils.makeRandomId();
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
735 instant = true;
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
736 }
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
737 if (storage.existsNode(nodeID))
20
957550e2d5a1 Correct an error identifier and use an already defined variable.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 19
diff changeset
738 return makeError(response, errors.owner.create.nodeid_already_exists.n);
0
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
739
2
d3ae2f8b685d Make create node working.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 1
diff changeset
740 var bare = toBareJID(to);
d3ae2f8b685d Make create node working.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 1
diff changeset
741 var right = false;
7
781ac4f1e304 Allow others JIDs than super-owners to create nodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 6
diff changeset
742
781ac4f1e304 Allow others JIDs than super-owners to create nodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 6
diff changeset
743 // Check for super-owner
2
d3ae2f8b685d Make create node working.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 1
diff changeset
744 for (var i in config.owner)
d3ae2f8b685d Make create node working.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 1
diff changeset
745 if (config.owner[i] == bare)
d3ae2f8b685d Make create node working.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 1
diff changeset
746 right = true;
d3ae2f8b685d Make create node working.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 1
diff changeset
747
7
781ac4f1e304 Allow others JIDs than super-owners to create nodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 6
diff changeset
748 // Check for authorized user
781ac4f1e304 Allow others JIDs than super-owners to create nodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 6
diff changeset
749 for (var i in config.allowCreateNode)
781ac4f1e304 Allow others JIDs than super-owners to create nodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 6
diff changeset
750 if (config.allowCreateNode[i].exec(bare))
781ac4f1e304 Allow others JIDs than super-owners to create nodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 6
diff changeset
751 right = true;
781ac4f1e304 Allow others JIDs than super-owners to create nodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 6
diff changeset
752
2
d3ae2f8b685d Make create node working.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 1
diff changeset
753 if (!right)
0
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
754 return makeError(response, errors.forbidden.n);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
755
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
756 var configure = pubsub.getChild('configure');
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
757 if (configure && config.enabled('create-and-configure')) {
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
758 if (!config.enabled('config-node'))
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
759 return makeError(response, errors.owner.configure.node_configuration_not_supported.n);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
760
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
761 if (configure.getAttribute('node'))
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
762 return makeError(response, errors.bad_request.n);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
763
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
764 var x = configure.getChild('x', 'jabber:x:data');
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
765 if (!x || x.getAttribute('type') != 'submit')
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
766 return makeError(response, errors.bad_request.n);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
767
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
768 var form = forms.parse(x, true);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
769 if (typeof form == 'number')
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
770 return makeError(response, form);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
771
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
772 var conf = form;
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
773 }
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
774
1
c2954a9e5665 Add a super-owner that has power over all nodes; add support for
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 0
diff changeset
775 if (!conf)
c2954a9e5665 Add a super-owner that has power over all nodes; add support for
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 0
diff changeset
776 conf = {};
20
957550e2d5a1 Correct an error identifier and use an already defined variable.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 19
diff changeset
777 conf['pubsub#creator'] = bare;
12
9a6b8b3357c6 Use new functions like console.log instead of sys.puts, and aerate a bit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 11
diff changeset
778
0
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
779 var r = storage.createNode(nodeID, conf);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
780 if (typeof r == 'number')
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
781 return makeError(response, r);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
782
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
783 if (instant)
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
784 response.c('pubsub', {xmlns: 'http://jabber.org/protocol/pubsub'})
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
785 .c('create', {node: nodeID});
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
786 } else
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
787 return makeError(response, errors.feature_not_implemented.n);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
788 } else if (stanza.getChild('pubsub', 'http://jabber.org/protocol/pubsub#owner')) {
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
789 var pubsub = stanza.getChild('pubsub', 'http://jabber.org/protocol/pubsub#owner');
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
790
1
c2954a9e5665 Add a super-owner that has power over all nodes; add support for
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 0
diff changeset
791 // SECTION 8.2.4
0
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
792 if (pubsub.getChild('configure')) {
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
793 if (!config.enabled('config-node'))
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
794 return makeError(response, errors.owner.configure.node_configuration_not_supported.n);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
795
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
796 var nodeID = configure.getAttribute('node');
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
797 if (!nodeID)
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
798 return makeError(response, errors.nodeid_required.n);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
799 if (!storage.existsNode(nodeID))
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
800 return makeError(response, errors.node_does_not_exist.n);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
801
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
802 var affil = storage.getAffiliation(toBareJID(to), nodeID);
1
c2954a9e5665 Add a super-owner that has power over all nodes; add support for
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 0
diff changeset
803 if (affil != 'super-owner' && affil != 'owner' && affil != 'publish-only')
0
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
804 return makeError(response, errors.forbidden.n);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
805
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
806 var x = configure.getChild('x', 'jabber:x:data');
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
807 if (!x || x.getAttribute(type) != 'submit')
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
808 return makeError(response, errors.bad_request.n);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
809
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
810 var form = forms.parse(x, true);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
811 if (typeof form == 'number')
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
812 return makeError(response, form);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
813
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
814 var conf = form;
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
815
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
816 var set = storage.configure(nodeID, conf);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
817 if (typeof set == 'number')
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
818 return makeError(response, set);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
819
1
c2954a9e5665 Add a super-owner that has power over all nodes; add support for
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 0
diff changeset
820 // SECTION 8.4
0
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
821 } else if (pubsub.getChild('delete')) {
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
822 if (!config.enabled('delete-nodes'))
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
823 return makeError(response, errors.feature_not_implemented.n); //XXX
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
824
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
825 var del = pubsub.getChild('delete');
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
826
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
827 var nodeID = del.getAttribute('node');
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
828 if (!nodeID)
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
829 return makeError(response, errors.nodeid_required.n);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
830 if (!storage.existsNode(nodeID))
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
831 return makeError(response, errors.node_does_not_exist.n);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
832
1
c2954a9e5665 Add a super-owner that has power over all nodes; add support for
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 0
diff changeset
833 var affil = storage.getAffiliation(toBareJID(to), nodeID);
c2954a9e5665 Add a super-owner that has power over all nodes; add support for
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 0
diff changeset
834 if (affil != 'super-owner' && affil != 'owner')
0
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
835 return makeError(response, errors.forbidden.n);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
836
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
837 var notifs = storage.deleteNode(nodeID);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
838 if (typeof notifs == 'number')
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
839 return makeError(response, r);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
840
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
841 sendNotifs(notifs, 'delete', nodeID);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
842
1
c2954a9e5665 Add a super-owner that has power over all nodes; add support for
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 0
diff changeset
843 // SECTION 8.5
0
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
844 } else if (pubsub.getChild('purge')) {
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
845 if (!config.enabled('purge-nodes'))
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
846 return makeError(response, errors.owner.purge.node_purging_not_supported.n); //XXX
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
847
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
848 var purge = pubsub.getChild('purge');
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
849
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
850 var nodeID = purge.getAttribute('node');
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
851 if (!nodeID)
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
852 return makeError(response, errors.nodeid_required.n);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
853 if (!storage.existsNode(nodeID))
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
854 return makeError(response, errors.node_does_not_exist.n);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
855
1
c2954a9e5665 Add a super-owner that has power over all nodes; add support for
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 0
diff changeset
856 var affil = storage.getAffiliation(toBareJID(to), nodeID);
c2954a9e5665 Add a super-owner that has power over all nodes; add support for
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 0
diff changeset
857 if (affil != 'super-owner' && affil != 'owner')
0
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
858 return makeError(response, errors.forbidden.n);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
859
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
860 if (!config.enabled('persistent-items')) //FIXME: autre condition, supporté par le node
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
861 return makeError(response, errors.owner.purge.node_does_not_persist_items.n);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
862
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
863 var notifs = storage.purgeNode(nodeID);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
864 if (typeof notifs == 'number')
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
865 return makeError(response, r);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
866
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
867 sendNotifs(notifs, 'purge', nodeID);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
868
1
c2954a9e5665 Add a super-owner that has power over all nodes; add support for
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 0
diff changeset
869 // SECTION 8.8.2
0
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
870 } else if (pubsub.getChild('subscriptions')) {
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
871 if (!config.enabled('manage-subscriptions'))
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
872 return makeError(response, errors.owner.manage_subscriptions.not_supported.n); //XXX
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
873
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
874 var subscriptions = pubsub.getChild('subscriptions');
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
875
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
876 var nodeID = subscriptions.getAttribute('node');
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
877 if (!nodeID)
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
878 return makeError(response, errors.nodeid_required.n);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
879 if (!storage.existsNode(nodeID))
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
880 return makeError(response, errors.node_does_not_exist.n);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
881
1
c2954a9e5665 Add a super-owner that has power over all nodes; add support for
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 0
diff changeset
882 var affil = storage.getAffiliation(toBareJID(to), nodeID);
c2954a9e5665 Add a super-owner that has power over all nodes; add support for
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 0
diff changeset
883 if (affil != 'super-owner' && affil != 'owner')
0
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
884 return makeError(response, errors.forbidden.n);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
885
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
886 var e = false;
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
887 for (i in subscriptions.tags) {
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
888 var jid = subscriptions.tags[i].getAttribute('jid');
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
889 var subscription = subscriptions.tags[i].getAttribute('subscription');
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
890
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
891 var set = storage.subscribe(nodeID, jid, subscription);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
892 if (typeof set == 'number')
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
893 e = true;
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
894 else {
1
c2954a9e5665 Add a super-owner that has power over all nodes; add support for
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 0
diff changeset
895 // SECTION 8.8.4
0
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
896 sendNotifs(jid, 'subscription', nodeID, {jid: jid, subscription: subscription});
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
897 subscriptions.tags.splice(i, 1);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
898 }
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
899 }
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
900
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
901 if (e)
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
902 return makeError(response, errors.owner.manage_subscriptions.modify.multiple_simultaneous_modifications.n, pubsub);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
903
1
c2954a9e5665 Add a super-owner that has power over all nodes; add support for
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 0
diff changeset
904 // SECTION 8.9.2
0
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
905 } else if (pubsub.getChild('affiliations')) {
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
906 if (!config.enabled('modify-affiliations'))
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
907 return makeError(response, errors.owner.manage_affiliations.not_supported.n); //XXX
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
908
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
909 var affiliations = pubsub.getChild('affiliations');
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
910
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
911 var nodeID = affiliations.getAttribute('node');
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
912 if (!nodeID)
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
913 return makeError(response, errors.nodeid_required.n);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
914 if (!storage.existsNode(nodeID))
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
915 return makeError(response, errors.node_does_not_exist.n);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
916
1
c2954a9e5665 Add a super-owner that has power over all nodes; add support for
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 0
diff changeset
917 var affil = storage.getAffiliation(toBareJID(to), nodeID);
c2954a9e5665 Add a super-owner that has power over all nodes; add support for
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 0
diff changeset
918 if (affil != 'super-owner' && affil != 'owner')
0
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
919 return makeError(response, errors.forbidden.n);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
920
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
921 var e = false;
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
922 for (i in affiliations.children) {
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
923 var jid = affiliations.children[i].getAttribute('jid');
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
924 var affiliation = affiliations.children[i].getAttribute('affiliation');
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
925
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
926 var set = storage.setAffiliation(nodeID, jid, affiliation);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
927 if (typeof set == 'number')
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
928 e = true;
1
c2954a9e5665 Add a super-owner that has power over all nodes; add support for
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 0
diff changeset
929 else {
c2954a9e5665 Add a super-owner that has power over all nodes; add support for
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 0
diff changeset
930 // SECTION 8.9.4
c2954a9e5665 Add a super-owner that has power over all nodes; add support for
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 0
diff changeset
931 sendNotifs(jid, 'affiliations', nodeID, {jid: jid, affiliation: affiliation});
0
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
932 affiliations.children.splice(i, 1);
1
c2954a9e5665 Add a super-owner that has power over all nodes; add support for
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 0
diff changeset
933 }
0
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
934 }
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
935
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
936 if (e)
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
937 return makeError(response, errors.owner.manage_affiliations.modify.multiple_simultaneous_modifications.n, pubsub);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
938 } else
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
939 return makeError(response, errors.feature_not_implemented.n);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
940 } else
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
941 return makeError(response, errors.feature_not_implemented.n);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
942 } else
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
943 return makeError(response, errors.feature_not_implemented.n);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
944 conn.send(response);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
945 }
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
946
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
947 function onMessage(stanza) {
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
948 var from = stanza.getAttribute('to');
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
949 var to = stanza.getAttribute('from');
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
950 var id = stanza.getAttribute('id');
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
951
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
952 var response;
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
953 if (id)
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
954 response = xmpp.message({to: to, from: from, id: id});
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
955 else
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
956 response = xmpp.message({to: to, from: from});
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
957
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
958 var x = stanza.getChild('x', 'jabber:x:data');
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
959 if (x) {
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
960 var form = forms.parse(x);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
961 if (form.type == 'submit' && form.fields.FORM_TYPE.value == 'subscribe_authorization') {
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
962 if (form.fields.subid && form.fields.subid.value)
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
963 var subID = form.fields.subid.value;
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
964 if (form.fields.node && form.fields.node.value)
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
965 var nodeID = form.fields.node.value;
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
966 if (form.fields.subscriber_jid && form.fields.subscriber_jid.value)
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
967 var jid = form.fields.subscriber_jid.value;
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
968 if (form.fields.allow && form.fields.allow.value)
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
969 var allow = form.fields.allow.value;
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
970
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
971 var type = allow? 'subscribed': 'none';
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
972 var set = storage.subscribe(nodeID, jid, type)
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
973 //if (set.subid != subID) //TODO: support the multi-subscribe feature
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
974 sendNotifs(jid, 'subscription', nodeID, {jid: jid, subscription: type});
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
975 } else
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
976 return makeError(response, errors.feature_not_implemented.n);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
977 } else
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
978 return makeError(response, errors.feature_not_implemented.n);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
979 conn.send(response)
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
980 }
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
981
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
982 function onPresence(stanza) {
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
983 var from = stanza.getAttribute('to');
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
984 var to = stanza.getAttribute('from');
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
985 var id = stanza.getAttribute('id');
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
986
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
987 var response;
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
988 if (id)
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
989 response = xmpp.presence({to: to, from: from, id: id});
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
990 else
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
991 response = xmpp.presence({to: to, from: from});
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
992
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
993 makeError(response, errors.feature_not_implemented.n);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
994 }
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
995
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
996 function makeError(response, errorNumber, payload) {
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
997 response.attr.type = 'error';
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
998 if (payload)
8
efe8dbd34780 Rename cx method to cnode and define it if xmpp.js didn’t.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 7
diff changeset
999 response.cnode(payload);
0
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1000
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1001 var e = errors.reverse[errorNumber];
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1002 var error = xmpp.stanza('error', {type: e.type});
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1003
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1004 error.s(e.error, {xmlns: 'urn:ietf:params:xml:ns:xmpp-stanzas'})
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1005
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1006 if (e.reason) {
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1007 if (e.feature)
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1008 error.s(e.reason, {xmlns: 'http://jabber.org/protocol/pubsub#errors', feature: e.feature});
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1009 else
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1010 error.s(e.reason, {xmlns: 'http://jabber.org/protocol/pubsub#errors'});
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1011 }
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1012
8
efe8dbd34780 Rename cx method to cnode and define it if xmpp.js didn’t.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 7
diff changeset
1013 response.cnode(error);
0
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1014 conn.send(response);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1015 }
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1016
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1017 function sendNotifs(notifs, type, nodeID, a1, a2) {
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1018 var ev = xmpp.stanza('event', {xmlns: 'http://jabber.org/protocol/pubsub#event'});
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1019
1
c2954a9e5665 Add a super-owner that has power over all nodes; add support for
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 0
diff changeset
1020 if (type == 'affiliations') {
c2954a9e5665 Add a super-owner that has power over all nodes; add support for
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 0
diff changeset
1021 ev.attr.xmlns = 'http://jabber.org/protocol/pubsub';
c2954a9e5665 Add a super-owner that has power over all nodes; add support for
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 0
diff changeset
1022
c2954a9e5665 Add a super-owner that has power over all nodes; add support for
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 0
diff changeset
1023 var args = {};
c2954a9e5665 Add a super-owner that has power over all nodes; add support for
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 0
diff changeset
1024 for (i in a1) {
c2954a9e5665 Add a super-owner that has power over all nodes; add support for
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 0
diff changeset
1025 var attr = a1[i];
c2954a9e5665 Add a super-owner that has power over all nodes; add support for
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 0
diff changeset
1026 if (i == 'affiliation')
c2954a9e5665 Add a super-owner that has power over all nodes; add support for
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 0
diff changeset
1027 args.affiliation = attr;
c2954a9e5665 Add a super-owner that has power over all nodes; add support for
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 0
diff changeset
1028 else if (i == 'jid')
c2954a9e5665 Add a super-owner that has power over all nodes; add support for
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 0
diff changeset
1029 args.jid = attr;
c2954a9e5665 Add a super-owner that has power over all nodes; add support for
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 0
diff changeset
1030 }
3
80e607c0b39e Make affiliation notifications working.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 2
diff changeset
1031 var affiliations = xmpp.stanza('affiliations', {node: nodeID})
4
4c93e76fa371 Ensure that the creator of a node is the default owner; don’t crash
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 3
diff changeset
1032 .c('affiliation', args);
8
efe8dbd34780 Rename cx method to cnode and define it if xmpp.js didn’t.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 7
diff changeset
1033 ev.cnode(affiliations);
1
c2954a9e5665 Add a super-owner that has power over all nodes; add support for
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 0
diff changeset
1034 } else if (type == 'collection') {
0
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1035 var collection = xmpp.stanza('collection', {node: nodeID});
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1036 if (a1 == 'associate')
8
efe8dbd34780 Rename cx method to cnode and define it if xmpp.js didn’t.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 7
diff changeset
1037 collection.cnode('associate', {node: nodeID});
0
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1038 else
8
efe8dbd34780 Rename cx method to cnode and define it if xmpp.js didn’t.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 7
diff changeset
1039 collection.cnode('disassociate', {node: nodeID});
efe8dbd34780 Rename cx method to cnode and define it if xmpp.js didn’t.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 7
diff changeset
1040 ev.cnode(collection);
0
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1041 } else if (type == 'configuration') {
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1042 if (!config.enabled('config-node')) {
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1043 _('Error #4', 41)
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1044 return;
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1045 }
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1046
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1047 var configuration = xmpp.stanza('configuration', {node: nodeID});
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1048 if (a1) {
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1049 var x = forms.build('node_config', service_configuration.node_config, storage.getConfiguration(nodeID));
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1050 if (x)
8
efe8dbd34780 Rename cx method to cnode and define it if xmpp.js didn’t.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 7
diff changeset
1051 configuration.cnode(x); //TODO: voir exemple 150
0
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1052 }
8
efe8dbd34780 Rename cx method to cnode and define it if xmpp.js didn’t.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 7
diff changeset
1053 ev.cnode(configuration);
0
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1054 } else if (type == 'delete') {
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1055 var del = xmpp.stanza('delete', {node: nodeID});
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1056 if (a1)
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1057 del.c('redirect', {uri: a1});
8
efe8dbd34780 Rename cx method to cnode and define it if xmpp.js didn’t.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 7
diff changeset
1058 ev.cnode(del);
0
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1059 } else if (type == 'items') {
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1060 var items = xmpp.stanza(type, {node: nodeID});
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1061 if (a2 == 'retract')
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1062 for (var i in a1)
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1063 items.s('retract', {id: i});
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1064 else {
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1065 for (var i in a1) {
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1066 var item = a1[i];
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1067 var args = {};
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1068 if (i != '')
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1069 args.id = i;
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1070 if (item.node)
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1071 args.node = item.node;
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1072 if (item.publisher)
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1073 args.publisher = item.publisher;
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1074 var it = xmpp.stanza('item', args);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1075 if (item.content)
8
efe8dbd34780 Rename cx method to cnode and define it if xmpp.js didn’t.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 7
diff changeset
1076 it.cnode(item.content);
efe8dbd34780 Rename cx method to cnode and define it if xmpp.js didn’t.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 7
diff changeset
1077 items.cnode(it);
0
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1078 }
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1079 }
8
efe8dbd34780 Rename cx method to cnode and define it if xmpp.js didn’t.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 7
diff changeset
1080 ev.cnode(items);
0
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1081 } else if (type == 'purge') {
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1082 ev.c('purge', {node: nodeID});
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1083 } else if (type == 'subscription') {
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1084 if (!config.enabled('subscription-notifications'))
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1085 return;
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1086
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1087 var args = {node: nodeID};
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1088 for (i in a1) {
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1089 var attr = a1[i];
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1090 if (i == 'subscription') {
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1091 if (attr == 'none' || attr == 'pending' || attr == 'subscribed' || attr == 'unconfigured')
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1092 args[i] = attr;
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1093 else {
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1094 _('Error #3', 41)
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1095 return;
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1096 }
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1097 } else if (i == 'jid' || i == 'subid')
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1098 args[i] = attr;
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1099 else if (i == 'expiry')
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1100 args[i] = attr.toString();
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1101 }
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1102 if (!args.jid || args.jid == '') {
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1103 _('Error #2', 41)
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1104 return;
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1105 }
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1106 var sub = xmpp.stanza('subscription', args);
8
efe8dbd34780 Rename cx method to cnode and define it if xmpp.js didn’t.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 7
diff changeset
1107 ev.cnode(sub);
0
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1108 } else {
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1109 _('Error #1', 41)
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1110 return;
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1111 }
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1112
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1113 var subs;
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1114 if (typeof notifs == 'string') {
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1115 subs = {};
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1116 subs[notifs] = storage.getSubscription(notifs, nodeID);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1117 } else
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1118 subs = notifs;
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1119
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1120 for (var i in subs) {
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1121 var sub = subs[i];
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1122
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1123 if (sub.options) {
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1124 if (typeof sub.options['pubsub#deliver'] != 'undefined' && !sub.options['pubsub#deliver'])
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1125 continue;
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1126
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1127 if (typeof sub.options['pubsub#digest'] != 'undefined' && sub.options['pubsub#digest']) {
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1128 if (!sub.digest)
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1129 sub.digest = [];
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1130 sub.digest.push(ev)
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1131
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1132 if (sub.digestTimeout)
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1133 continue;
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1134
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1135 var freq;
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1136 if (typeof sub.options['pubsub#digest_frequency'] == 'undefined')
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1137 freq = 0;
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1138 else
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1139 freq = parseInt(sub.options['pubsub#digest_frequency']);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1140
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1141 if (freq == 0)
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1142 freq = 24*60*60*1000;
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1143
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1144 setTimeout(sendDigest, freq, notifs[i], nodeID);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1145 sub.digestTimeout = true;
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1146 continue;
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1147 }
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1148 }
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1149
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1150 var message = xmpp.message({to: i, from: componentJID, id: conn.getUniqueId()});
8
efe8dbd34780 Rename cx method to cnode and define it if xmpp.js didn’t.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 7
diff changeset
1151 message.cnode(ev);
0
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1152 conn.send(message);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1153 }
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1154 }
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1155
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1156 function sendDigest(jid, nodeID) {
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1157 var sub = storage.getSubscription(jid, nodeID);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1158 if (sub.digestTimeout)
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1159 sub.digestTimeout = false;
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1160
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1161 var message = xmpp.message({to: jid, from: componentJID, id: conn.getUniqueId()});
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1162 for (var i in sub.digest)
8
efe8dbd34780 Rename cx method to cnode and define it if xmpp.js didn’t.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 7
diff changeset
1163 message.cnode(sub.digest[i]);
0
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1164 conn.send(message);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1165 }
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1166
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1167 conn.connect(componentJID, componentPassword, function (status, condition) {
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1168 if (status == xmpp.Status.CONNECTED) {
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1169 conn.addHandler(onMessage, null, 'message', null, null, null);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1170 conn.addHandler(onIq, null, 'iq', null, null, null);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1171 conn.addHandler(onPresence, null, 'presence', null, null, null);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1172
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1173 if (process.argv.length >= 3)
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1174 storage.load(process.argv[2]);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1175 else
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1176 storage.load();
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1177
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1178 var stdin = process.openStdin();
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1179 stdin.setEncoding('utf8');
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1180 stdin.addListener('data', storage.debug);
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1181 } else
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1182 conn.log(xmpp.LogLevel.DEBUG, 'New connection status: ' + status + (condition? (' ('+condition+')'): ''));
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1183 });