Mercurial > psgxs
comparison nodes.js @ 0:9ee956af41e3
Initial commit
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Sun, 27 Jun 2010 22:05:12 +0200 |
parents | |
children | c2954a9e5665 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:9ee956af41e3 |
---|---|
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; | |
25 var makeRandomId = require('./util').makeRandomId; | |
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 = {}; | |
37 this.owner = ['lm@slam']; | |
38 if (config.enabled('publisher-affiliation')) | |
39 this.publisher = []; | |
40 if (config.enabled('publish-only-affiliation')) | |
41 this.publishOnly = []; | |
42 if (config.enabled('member-affiliation')) | |
43 this.member = []; | |
44 if (config.enabled('outcast-affiliation')) | |
45 this.outcast = []; | |
46 if (config.enabled('meta-data')) | |
47 this.metadata = new Configuration(service_configuration.node_metadata, params); | |
48 if (config.enabled('config-node')) | |
49 this.configuration = new Configuration(service_configuration.node_config, params); | |
50 if (config.enabled('subscription-options')) | |
51 this.subsConfig = new Configuration(service_configuration.subscribe_options, params); | |
52 return this; | |
53 }; | |
54 | |
55 exports.Node.prototype = { | |
56 setItem: function(name, content) { | |
57 if (typeof content == 'undefined') { | |
58 if (this.items[name]) { | |
59 delete this.items[name]; | |
60 return errors.success; | |
61 } | |
62 return 42; //XXX | |
63 } | |
64 | |
65 if (!this.items[name]) | |
66 this.items[name] = new exports.Item(); | |
67 | |
68 this.items[name].content = content; | |
69 | |
70 return errors.success; | |
71 }, | |
72 | |
73 setSubscriber: function(jid, type, subid, params) { | |
74 if (type == 'none') { | |
75 delete this.subscribers[jid]; | |
76 this.metadata['pubsub#num_subscribers']--; | |
77 return errors.success; | |
78 } | |
79 | |
80 if (!subid) | |
81 subid = makeRandomId(); | |
82 | |
83 this.subscribers[jid] = { | |
84 type: type, | |
85 subid: subid, | |
86 options: new Configuration(service_configuration.subscribe_options, params), | |
87 } | |
88 | |
89 this.metadata['pubsub#num_subscribers']++; | |
90 | |
91 return subid; | |
92 }, | |
93 }; |