annotate nodes.js @ 48:c979c4d0932b

Little fixes for strict mode compatibility.
author Sonny Piers <sonny.piers@gmail.com>
date Sat, 19 Mar 2011 14:57:13 +0100
parents 023f767662d3
children 99bd1d1ac071
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 /*
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
2 * Copyright (C) 2010 Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
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 * 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
5 *
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
6 * PSĜS is free software: you can redistribute it and/or modify
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
7 * it under the terms of the GNU Affero General Public License as
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
8 * published by the Free Software Foundation, either version 3 of the
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
9 * License.
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
10 *
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
11 * PSĜS is distributed in the hope that it will be useful,
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
14 * GNU Affero General Public License for more details.
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
15 *
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
16 * 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
17 * along with PSĜS. If not, see <http://www.gnu.org/licenses/>.
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
18 */
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
19
43
023f767662d3 Fix compatibility with strict mode of node 0.4 and some files without licence header.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 35
diff changeset
20 'use strict';
023f767662d3 Fix compatibility with strict mode of node 0.4 and some files without licence header.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 35
diff changeset
21
0
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
22 require('./iso8601');
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
23 var errors = require('./errors');
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
24 var config = require('./configuration');
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
25 var service_configuration = config.service_configuration;
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
26 var Configuration = config.Configuration;
35
6697f394301f Replace util with fdsq to work around a stupid bug.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 16
diff changeset
27 var makeRandomId = require('./fdsq').makeRandomId;
0
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
28
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
29 exports.Item = function() {
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
30 this.content = null;
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
31 this.date = new Date();
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
32 return this;
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
33 };
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
34
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
35 exports.Node = function(params) {
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
36 this.items = {};
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
37 if (config.enabled('subscribe'))
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
38 this.subscribers = {};
4
4c93e76fa371 Ensure that the creator of a node is the default owner; don’t crash
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 1
diff changeset
39
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
40 this.owner = [];
4
4c93e76fa371 Ensure that the creator of a node is the default owner; don’t crash
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 1
diff changeset
41 if (params && params['pubsub#creator'])
4c93e76fa371 Ensure that the creator of a node is the default owner; don’t crash
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 1
diff changeset
42 this.owner.push(params['pubsub#creator']);
4c93e76fa371 Ensure that the creator of a node is the default owner; don’t crash
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 1
diff changeset
43
0
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
44 if (config.enabled('publisher-affiliation'))
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
45 this.publisher = [];
12
9a6b8b3357c6 Use new functions like console.log instead of sys.puts, and aerate a bit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 4
diff changeset
46
0
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
47 if (config.enabled('publish-only-affiliation'))
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
48 this.publishOnly = [];
12
9a6b8b3357c6 Use new functions like console.log instead of sys.puts, and aerate a bit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 4
diff changeset
49
0
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
50 if (config.enabled('member-affiliation'))
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
51 this.member = [];
12
9a6b8b3357c6 Use new functions like console.log instead of sys.puts, and aerate a bit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 4
diff changeset
52
0
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
53 if (config.enabled('outcast-affiliation'))
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
54 this.outcast = [];
12
9a6b8b3357c6 Use new functions like console.log instead of sys.puts, and aerate a bit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 4
diff changeset
55
0
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
56 if (config.enabled('meta-data'))
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
57 this.metadata = new Configuration(service_configuration.node_metadata, params);
12
9a6b8b3357c6 Use new functions like console.log instead of sys.puts, and aerate a bit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 4
diff changeset
58
0
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
59 if (config.enabled('config-node'))
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
60 this.configuration = new Configuration(service_configuration.node_config, params);
12
9a6b8b3357c6 Use new functions like console.log instead of sys.puts, and aerate a bit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 4
diff changeset
61
0
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
62 if (config.enabled('subscription-options'))
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
63 this.subsConfig = new Configuration(service_configuration.subscribe_options, params);
12
9a6b8b3357c6 Use new functions like console.log instead of sys.puts, and aerate a bit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 4
diff changeset
64
0
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
65 return this;
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
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
68 exports.Node.prototype = {
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
69 setItem: function(name, content) {
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
70 if (typeof content == 'undefined') {
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
71 if (this.items[name]) {
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
72 delete this.items[name];
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
73 return errors.success;
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
74 }
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
75 return 42; //XXX
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
76 }
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
77
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
78 if (!this.items[name])
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
79 this.items[name] = new exports.Item();
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
80
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
81 this.items[name].content = content;
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 return errors.success;
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
84 },
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
85
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
86 setSubscriber: function(jid, type, subid, params) {
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
87 if (type == 'none') {
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
88 delete this.subscribers[jid];
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
89 this.metadata['pubsub#num_subscribers']--;
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
90 return errors.success;
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
91 }
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
92
16
95fc43d1bd54 Don’t regenerate a subid if there is already one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 12
diff changeset
93 if (!subid) {
95fc43d1bd54 Don’t regenerate a subid if there is already one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 12
diff changeset
94 if (this.subscribers[jid])
95fc43d1bd54 Don’t regenerate a subid if there is already one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 12
diff changeset
95 subid = this.subscribers[jid].subid;
95fc43d1bd54 Don’t regenerate a subid if there is already one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 12
diff changeset
96 else
95fc43d1bd54 Don’t regenerate a subid if there is already one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 12
diff changeset
97 subid = makeRandomId();
95fc43d1bd54 Don’t regenerate a subid if there is already one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 12
diff changeset
98 }
0
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
99
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
100 this.subscribers[jid] = {
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
101 type: type,
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
102 subid: subid,
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
103 options: new Configuration(service_configuration.subscribe_options, params),
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
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
106 this.metadata['pubsub#num_subscribers']++;
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
107
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
108 return subid;
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
109 },
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
110 };