Mercurial > psgxs
annotate nodes.js @ 38:5395a501c991
Use internal toISOString method of Data.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Tue, 16 Nov 2010 19:00:15 +0100 |
parents | 6697f394301f |
children | 023f767662d3 |
rev | line source |
---|---|
0 | 1 /* |
2 * Copyright (C) 2010 Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> | |
3 * | |
4 * This file is part of PSĜS, a PubSub server written in JavaScript. | |
5 * | |
6 * PSĜS is free software: you can redistribute it and/or modify | |
7 * it under the terms of the GNU Affero General Public License as | |
8 * published by the Free Software Foundation, either version 3 of the | |
9 * License. | |
10 * | |
11 * PSĜS is distributed in the hope that it will be useful, | |
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 * GNU Affero General Public License for more details. | |
15 * | |
16 * You should have received a copy of the GNU Affero General Public License | |
17 * along with PSĜS. If not, see <http://www.gnu.org/licenses/>. | |
18 */ | |
19 | |
20 require('./iso8601'); | |
21 var errors = require('./errors'); | |
22 var config = require('./configuration'); | |
23 var service_configuration = config.service_configuration; | |
24 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
|
25 var makeRandomId = require('./fdsq').makeRandomId; |
0 | 26 |
27 exports.Item = function() { | |
28 this.content = null; | |
29 this.date = new Date(); | |
30 return this; | |
31 }; | |
32 | |
33 exports.Node = function(params) { | |
34 this.items = {}; | |
35 if (config.enabled('subscribe')) | |
36 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
|
37 |
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
|
38 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
|
39 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
|
40 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
|
41 |
0 | 42 if (config.enabled('publisher-affiliation')) |
43 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
|
44 |
0 | 45 if (config.enabled('publish-only-affiliation')) |
46 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
|
47 |
0 | 48 if (config.enabled('member-affiliation')) |
49 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
|
50 |
0 | 51 if (config.enabled('outcast-affiliation')) |
52 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
|
53 |
0 | 54 if (config.enabled('meta-data')) |
55 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
|
56 |
0 | 57 if (config.enabled('config-node')) |
58 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
|
59 |
0 | 60 if (config.enabled('subscription-options')) |
61 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
|
62 |
0 | 63 return this; |
64 }; | |
65 | |
66 exports.Node.prototype = { | |
67 setItem: function(name, content) { | |
68 if (typeof content == 'undefined') { | |
69 if (this.items[name]) { | |
70 delete this.items[name]; | |
71 return errors.success; | |
72 } | |
73 return 42; //XXX | |
74 } | |
75 | |
76 if (!this.items[name]) | |
77 this.items[name] = new exports.Item(); | |
78 | |
79 this.items[name].content = content; | |
80 | |
81 return errors.success; | |
82 }, | |
83 | |
84 setSubscriber: function(jid, type, subid, params) { | |
85 if (type == 'none') { | |
86 delete this.subscribers[jid]; | |
87 this.metadata['pubsub#num_subscribers']--; | |
88 return errors.success; | |
89 } | |
90 | |
16
95fc43d1bd54
Don’t regenerate a subid if there is already one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
12
diff
changeset
|
91 if (!subid) { |
95fc43d1bd54
Don’t regenerate a subid if there is already one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
12
diff
changeset
|
92 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
|
93 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
|
94 else |
95fc43d1bd54
Don’t regenerate a subid if there is already one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
12
diff
changeset
|
95 subid = makeRandomId(); |
95fc43d1bd54
Don’t regenerate a subid if there is already one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
12
diff
changeset
|
96 } |
0 | 97 |
98 this.subscribers[jid] = { | |
99 type: type, | |
100 subid: subid, | |
101 options: new Configuration(service_configuration.subscribe_options, params), | |
102 } | |
103 | |
104 this.metadata['pubsub#num_subscribers']++; | |
105 | |
106 return subid; | |
107 }, | |
108 }; |