Mercurial > psgxs
annotate nodes.js @ 47:0d3f18bb1d36
Remove usage of fdsq.js in modules.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Thu, 10 Mar 2011 16:13:49 +0100 |
parents | 023f767662d3 |
children | 99bd1d1ac071 |
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 | |
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 | 22 require('./iso8601'); |
23 var errors = require('./errors'); | |
24 var config = require('./configuration'); | |
25 var service_configuration = config.service_configuration; | |
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 | 28 |
29 exports.Item = function() { | |
30 this.content = null; | |
31 this.date = new Date(); | |
32 return this; | |
33 }; | |
34 | |
35 exports.Node = function(params) { | |
36 this.items = {}; | |
37 if (config.enabled('subscribe')) | |
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 | 44 if (config.enabled('publisher-affiliation')) |
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 | 47 if (config.enabled('publish-only-affiliation')) |
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 | 50 if (config.enabled('member-affiliation')) |
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 | 53 if (config.enabled('outcast-affiliation')) |
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 | 56 if (config.enabled('meta-data')) |
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 | 59 if (config.enabled('config-node')) |
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 | 62 if (config.enabled('subscription-options')) |
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 | 65 return this; |
66 }; | |
67 | |
68 exports.Node.prototype = { | |
69 setItem: function(name, content) { | |
70 if (typeof content == 'undefined') { | |
71 if (this.items[name]) { | |
72 delete this.items[name]; | |
73 return errors.success; | |
74 } | |
75 return 42; //XXX | |
76 } | |
77 | |
78 if (!this.items[name]) | |
79 this.items[name] = new exports.Item(); | |
80 | |
81 this.items[name].content = content; | |
82 | |
83 return errors.success; | |
84 }, | |
85 | |
86 setSubscriber: function(jid, type, subid, params) { | |
87 if (type == 'none') { | |
88 delete this.subscribers[jid]; | |
89 this.metadata['pubsub#num_subscribers']--; | |
90 return errors.success; | |
91 } | |
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 | 99 |
100 this.subscribers[jid] = { | |
101 type: type, | |
102 subid: subid, | |
103 options: new Configuration(service_configuration.subscribe_options, params), | |
104 } | |
105 | |
106 this.metadata['pubsub#num_subscribers']++; | |
107 | |
108 return subid; | |
109 }, | |
110 }; |