Mercurial > psgxs
annotate storage.js @ 58:b98e545a94f7 default tip
Always use children instead of tags. Might break something.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Tue, 13 Sep 2011 00:54:55 +0200 |
parents | 99bd1d1ac071 |
children |
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 |
26
f2e9365bc8ec
Can use differents backends for node storage. Writing directory-based backend in top of file-based backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
12
diff
changeset
|
22 var fs = require('fs'); |
0 | 23 require('./iso8601'); |
24 var errors = require('./errors'); | |
25 var config = require('./configuration'); | |
26 var service_configuration = config.service_configuration; | |
27 var Configuration = config.Configuration; | |
35
6697f394301f
Replace util with fdsq to work around a stupid bug.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
33
diff
changeset
|
28 var fdsq = require('./fdsq'); |
47
0d3f18bb1d36
Remove usage of fdsq.js in modules.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
43
diff
changeset
|
29 var toBare = fdsq.toBare; |
56
99bd1d1ac071
Migration to node-xmpp, done!
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
52
diff
changeset
|
30 var uuid = require('uuid'); |
0 | 31 |
32 var nodes = require('./nodes'); | |
33 var Node = nodes.Node; | |
34 var Item = nodes.Item; | |
35 | |
26
f2e9365bc8ec
Can use differents backends for node storage. Writing directory-based backend in top of file-based backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
12
diff
changeset
|
36 var storage = exports; |
0 | 37 |
26
f2e9365bc8ec
Can use differents backends for node storage. Writing directory-based backend in top of file-based backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
12
diff
changeset
|
38 var backend = require('./backends/' + config.backend); |
f2e9365bc8ec
Can use differents backends for node storage. Writing directory-based backend in top of file-based backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
12
diff
changeset
|
39 storage.load = backend.load; |
f2e9365bc8ec
Can use differents backends for node storage. Writing directory-based backend in top of file-based backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
12
diff
changeset
|
40 storage.save = backend.save; |
f2e9365bc8ec
Can use differents backends for node storage. Writing directory-based backend in top of file-based backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
12
diff
changeset
|
41 |
0 | 42 storage.createNode = function(nodeID, params) { |
26
f2e9365bc8ec
Can use differents backends for node storage. Writing directory-based backend in top of file-based backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
12
diff
changeset
|
43 for (var i in backend.list) |
0 | 44 if (i == nodeID) |
45 return errors.owner.create.nodeid_already_exists.n; | |
46 | |
26
f2e9365bc8ec
Can use differents backends for node storage. Writing directory-based backend in top of file-based backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
12
diff
changeset
|
47 backend.list[nodeID] = new Node(params); |
0 | 48 storage.save(); |
49 return errors.success; | |
50 }; | |
51 | |
52 storage.getMetadata = function(nodeID) { | |
53 var node = storage.getNode(nodeID); | |
54 if (typeof node == 'number') | |
55 return node; | |
56 | |
57 if (!config.enabled('meta-data')) | |
58 return {}; | |
59 | |
60 var md = {}; | |
61 for (var i in service_configuration.node_metadata) { | |
62 if (i == 'FORM_TYPE') | |
63 continue; | |
64 | |
65 if (node.configuration[i]) | |
66 md[i] = node.configuration[i]; | |
67 else if (node.metadata[i]) | |
68 md[i] = node.metadata[i]; | |
33
62cbb1c49bc5
Fix publish; add owner metadata field; add HTTP module and Atom HTTP module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
26
diff
changeset
|
69 else if (i == 'pubsub#owner') |
62cbb1c49bc5
Fix publish; add owner metadata field; add HTTP module and Atom HTTP module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
26
diff
changeset
|
70 md[i] = node.owner; |
0 | 71 } |
72 return md; | |
73 }; | |
74 | |
75 storage.getConfiguration = function(nodeID) { | |
76 var node = storage.getNode(nodeID); | |
77 if (typeof node == 'number') | |
78 return node; | |
79 | |
80 if (config.enabled('config-node')) | |
81 return node.configuration; | |
82 | |
83 return {}; //FIXME | |
84 }; | |
85 | |
86 storage.configure = function(nodeID, params) { | |
87 var node = storage.getNode(nodeID); | |
88 if (typeof node == 'number') | |
89 return node; | |
90 | |
91 if (!config.enabled('config-node')) | |
92 return 42; //FIXME | |
93 | |
94 for (var i in params) | |
95 if (service_configuration.node_config[i]) | |
96 node.configuration[i] = params[i]; | |
97 | |
98 storage.save(); | |
99 return errors.success; | |
100 }; | |
101 | |
102 storage.configureSubscription = function(nodeID, jid, params) { | |
103 var node = storage.getNode(nodeID); | |
104 if (typeof node == 'number') | |
105 return node; | |
106 | |
107 if (!config.enabled('subscription-options')) | |
108 return 42; //FIXME | |
109 | |
110 var options = node.subscribers[jid].options; | |
111 if (!options) | |
112 return 42; //FIXME | |
113 | |
114 for (var i in params) | |
115 if (service_configuration.subscribe_options[i]) | |
116 options[i] = params[i]; | |
117 | |
118 storage.save(); | |
119 return errors.success; | |
120 }; | |
121 | |
122 storage.getChildren = function(node) { | |
123 var n; | |
124 var items = {}; | |
125 if (node) | |
126 n = storage.getNode(node).items; | |
127 else | |
26
f2e9365bc8ec
Can use differents backends for node storage. Writing directory-based backend in top of file-based backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
12
diff
changeset
|
128 n = backend.list; |
0 | 129 |
130 for (var i in n) { | |
131 var type; | |
132 if (n[i].content) | |
133 type = 'item'; | |
134 else | |
135 type = 'node'; | |
136 items[i] = type; | |
137 } | |
138 return items; | |
139 }; | |
140 | |
141 storage.getNode = function(nodeID) { | |
26
f2e9365bc8ec
Can use differents backends for node storage. Writing directory-based backend in top of file-based backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
12
diff
changeset
|
142 if (backend.list[nodeID]) |
f2e9365bc8ec
Can use differents backends for node storage. Writing directory-based backend in top of file-based backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
12
diff
changeset
|
143 return backend.list[nodeID]; |
6 | 144 return errors.node_does_not_exist.n; |
0 | 145 }; |
146 | |
147 storage.existsNode = function(nodeID) { | |
26
f2e9365bc8ec
Can use differents backends for node storage. Writing directory-based backend in top of file-based backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
12
diff
changeset
|
148 if (backend.list[nodeID]) |
0 | 149 return true; |
150 return false; | |
151 }; | |
152 | |
153 storage.purgeNode = function(nodeID) { | |
154 var node = storage.getNode(nodeID); | |
155 if (typeof n == 'number') | |
156 return node; | |
157 | |
158 var notifs = storage.getSubscriptionsFromNodeID(nodeID); | |
159 | |
160 var item = storage.getLastItem(nodeID); | |
161 if (typeof item == 'number') { | |
162 node.items = {}; | |
163 } else { | |
164 items = node.items[item]; | |
165 node.items = {}; | |
166 node.items[item] = items; | |
167 } | |
168 | |
169 storage.save(); | |
170 return notifs; | |
171 }; | |
172 | |
173 storage.deleteNodeWithRedirect = function(nodeID, uri) { | |
174 var del = storage.deleteNode(nodeID); | |
175 if (typeof del == 'number') | |
176 return del; | |
177 | |
26
f2e9365bc8ec
Can use differents backends for node storage. Writing directory-based backend in top of file-based backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
12
diff
changeset
|
178 backend.list[nodeID] = uri; |
0 | 179 storage.save(); |
180 return errors.success; | |
181 }; | |
182 | |
183 storage.deleteNode = function(nodeID) { | |
184 var node = storage.getNode(nodeID); | |
185 if (typeof n == 'number') | |
186 return node; | |
187 | |
188 var notifs = {}; | |
189 for (var i in node.subscribers) | |
190 notifs[i] = {}; | |
191 for (var i in node.owner) | |
192 notifs[node.owner[i]] = {}; | |
193 if (config.enabled('publisher-affiliation')) | |
194 for (var i in node.publisher) | |
195 notifs[node.publisher[i]] = {}; | |
196 if (config.enabled('publish-only-affiliation')) | |
197 for (var i in node.publishOnly) | |
198 notifs[node.publishOnly[i]] = {}; | |
199 | |
26
f2e9365bc8ec
Can use differents backends for node storage. Writing directory-based backend in top of file-based backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
12
diff
changeset
|
200 delete backend.list[nodeID]; |
0 | 201 storage.save(); |
202 return notifs; | |
203 }; | |
204 | |
205 storage.setItem = function(nodeID, itemID, content) { | |
206 var node = storage.getNode(nodeID); | |
207 if (typeof node == 'number') | |
208 return node; | |
209 | |
210 if (typeof itemID != 'string') | |
56
99bd1d1ac071
Migration to node-xmpp, done!
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
52
diff
changeset
|
211 itemID = uuid(); |
0 | 212 |
48
c979c4d0932b
Little fixes for strict mode compatibility.
Sonny Piers <sonny.piers@gmail.com>
parents:
47
diff
changeset
|
213 var i = node.setItem(itemID, content); |
0 | 214 if (content) |
215 i.content = content; | |
216 | |
217 storage.save(); | |
218 return storage.getSubscriptionsFromNodeID(nodeID) | |
219 }; | |
220 | |
221 storage.deleteItem = function(nodeID, itemID) { | |
222 var node = storage.getNode(nodeID); | |
223 if (typeof node == 'number') | |
224 return node; | |
225 | |
226 if (typeof itemID != 'string') | |
227 return errors.pub.retract.item_or_itemid_required.n; | |
228 | |
48
c979c4d0932b
Little fixes for strict mode compatibility.
Sonny Piers <sonny.piers@gmail.com>
parents:
47
diff
changeset
|
229 var item = node.setItem(itemID); |
0 | 230 if (typeof item == 'number') |
231 return item; | |
232 | |
233 storage.save(); | |
234 return storage.getSubscriptionsFromNodeID(nodeID) | |
235 }; | |
236 | |
237 storage.getItems = function(nodeID) { | |
238 var node; | |
239 if (typeof nodeID == 'string') | |
240 node = storage.getNode(nodeID); | |
241 else | |
242 node = nodeID; | |
243 | |
244 if (typeof node == 'number') | |
245 return node; | |
246 | |
247 return node.items; | |
248 }; | |
249 | |
250 storage.getLastItem = function(nodeID, number) { | |
251 var items = storage.getItems(nodeID); | |
252 if (typeof items == 'number') | |
253 return items; | |
254 | |
255 if (items == {}) | |
256 return 42; //FIXME | |
257 | |
258 if (number) { | |
259 var last = []; | |
260 var j = 0; | |
261 for (var i in items) { | |
262 last.push({name: i, date: items[i].date, content: items[i].content}); | |
263 j++; | |
264 } | |
265 if (j < number) | |
266 return last; | |
267 | |
268 var cmp = function(a, b) { | |
269 return b.date - a.date; | |
270 } | |
271 last = last.sort(cmp).slice(0, number); | |
272 } else { | |
273 var last; | |
274 for (var i in items) | |
275 if ((typeof last == 'undefined') || (items[i].date >= items[last].date)) | |
276 last = i; | |
277 } | |
278 | |
279 if (last) | |
280 return last; | |
281 return 42; //FIXME | |
282 }; | |
283 | |
284 storage.existsItem = function(nodeID, itemID) { | |
285 var items = storage.getItems(nodeID); | |
286 if (typeof items == 'number') | |
287 return items; | |
288 | |
289 for (var i in items) | |
290 if (i == itemID) | |
291 return items[i]; | |
292 return false; | |
293 }; | |
294 | |
295 storage.getItem = function(nodeID, itemID) { | |
10
44889cfb2f8c
Fix getItem method.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
9
diff
changeset
|
296 var items = storage.getItems(nodeID); |
0 | 297 if (typeof items == 'number') |
298 return items; | |
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
|
299 |
10
44889cfb2f8c
Fix getItem method.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
9
diff
changeset
|
300 if (items[itemID]) |
44889cfb2f8c
Fix getItem method.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
9
diff
changeset
|
301 return items[itemID].content; |
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
|
302 |
10
44889cfb2f8c
Fix getItem method.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
9
diff
changeset
|
303 return errors.success; |
0 | 304 }; |
305 | |
306 storage.getSubscription = function(jid, nodeID) { | |
307 var subs = {}; | |
308 if (nodeID) { | |
309 var node = storage.getNode(nodeID); | |
310 for (var sub in node.subscribers) | |
47
0d3f18bb1d36
Remove usage of fdsq.js in modules.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
43
diff
changeset
|
311 if (toBare(sub) == jid) |
0 | 312 return node.subscribers[sub] |
313 } else { | |
26
f2e9365bc8ec
Can use differents backends for node storage. Writing directory-based backend in top of file-based backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
12
diff
changeset
|
314 for (var node in backend.list) { |
f2e9365bc8ec
Can use differents backends for node storage. Writing directory-based backend in top of file-based backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
12
diff
changeset
|
315 for (var sub in backend.list[node].subscribers) { |
47
0d3f18bb1d36
Remove usage of fdsq.js in modules.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
43
diff
changeset
|
316 if (toBare(sub) == jid) |
26
f2e9365bc8ec
Can use differents backends for node storage. Writing directory-based backend in top of file-based backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
12
diff
changeset
|
317 subs[node] = backend.list[node].subscribers[sub]; |
0 | 318 } |
319 } | |
320 } | |
321 return subs; | |
322 }; | |
323 | |
324 storage.getSubscriptionsFromNodeID = function(nodeID) { | |
325 var node; | |
326 if (typeof nodeID == 'string') { | |
327 node = storage.getNode(nodeID); | |
328 if (typeof node == 'number') | |
329 return node; | |
330 } else | |
331 node = nodeID; | |
332 | |
333 var subs = {}; | |
334 for (var sub in node.subscribers) { | |
335 if (typeof sub == 'string') { | |
336 var subscription = {subid: node.subscribers[sub].subid, type: node.subscribers[sub].type}; | |
337 if (node.subscribers[sub].options) | |
338 subscription.options = node.subscribers[sub].options; | |
339 subs[sub] = subscription; | |
340 } | |
341 } | |
342 return subs; | |
343 }; | |
344 | |
345 storage.subscribe = function(nodeID, jid, type, params) { | |
346 if (!config.enabled('subscribe')) | |
347 return errors.sub.subscribe.not_supported.n; | |
348 | |
349 var node = storage.getNode(nodeID); | |
350 if (typeof node == 'number') | |
351 return node; | |
352 | |
353 if (typeof type == 'undefined') | |
354 type = 'subscribed'; | |
355 | |
356 if (type == 'none') { | |
357 if (!node.subscribers[jid]) | |
358 return errors.sub.unsubscribe.no_such_subscriber.n; | |
359 } | |
360 | |
361 var subid = node.setSubscriber(jid, type, null, params); | |
362 storage.save(); | |
363 return {subid: subid, type: type}; | |
364 }; | |
365 | |
366 storage.setAffiliation = function(nodeID, jid, affil) { | |
367 var node = storage.getNode(nodeID); | |
368 if (typeof node == 'number') | |
369 return node; | |
370 | |
371 if (affil == 'owner') | |
372 node.owner.push(jid); | |
373 else if (config.enabled('publisher-affiliation') && affil == 'publisher') | |
374 node.publisher.push(jid); | |
375 else if (config.enabled('publish-only-affiliation') && affil == 'publish-only') | |
376 node.publishOnly.push(jid); | |
377 else if (config.enabled('member-affiliation') && affil == 'member') | |
378 node.member.push(jid); | |
379 else if (config.enabled('outcast-affiliation') && affil == 'outcast') | |
380 node.outcast.push(jid); | |
50
e6c2c66c2002
Handle 'none' on set affiliation bug #2246
Sonny Piers <sonny.piers@gmail.com>
parents:
48
diff
changeset
|
381 else if (affil == 'none') { |
e6c2c66c2002
Handle 'none' on set affiliation bug #2246
Sonny Piers <sonny.piers@gmail.com>
parents:
48
diff
changeset
|
382 (function() { |
e6c2c66c2002
Handle 'none' on set affiliation bug #2246
Sonny Piers <sonny.piers@gmail.com>
parents:
48
diff
changeset
|
383 for (var i in node.outcast) |
e6c2c66c2002
Handle 'none' on set affiliation bug #2246
Sonny Piers <sonny.piers@gmail.com>
parents:
48
diff
changeset
|
384 if(node.outcast[i] == jid) |
e6c2c66c2002
Handle 'none' on set affiliation bug #2246
Sonny Piers <sonny.piers@gmail.com>
parents:
48
diff
changeset
|
385 return node.outcast.splice(i, 1); |
e6c2c66c2002
Handle 'none' on set affiliation bug #2246
Sonny Piers <sonny.piers@gmail.com>
parents:
48
diff
changeset
|
386 for (var i in node.owner) |
e6c2c66c2002
Handle 'none' on set affiliation bug #2246
Sonny Piers <sonny.piers@gmail.com>
parents:
48
diff
changeset
|
387 if(node.owner[i] == jid) |
e6c2c66c2002
Handle 'none' on set affiliation bug #2246
Sonny Piers <sonny.piers@gmail.com>
parents:
48
diff
changeset
|
388 return node.owner.splice(i, 1); |
e6c2c66c2002
Handle 'none' on set affiliation bug #2246
Sonny Piers <sonny.piers@gmail.com>
parents:
48
diff
changeset
|
389 for (var i in node.publisher) |
e6c2c66c2002
Handle 'none' on set affiliation bug #2246
Sonny Piers <sonny.piers@gmail.com>
parents:
48
diff
changeset
|
390 if(node.publisher[i] == jid) |
e6c2c66c2002
Handle 'none' on set affiliation bug #2246
Sonny Piers <sonny.piers@gmail.com>
parents:
48
diff
changeset
|
391 return node.publisher.splice(i, 1); |
e6c2c66c2002
Handle 'none' on set affiliation bug #2246
Sonny Piers <sonny.piers@gmail.com>
parents:
48
diff
changeset
|
392 for (var i in node.publishOnly) |
e6c2c66c2002
Handle 'none' on set affiliation bug #2246
Sonny Piers <sonny.piers@gmail.com>
parents:
48
diff
changeset
|
393 if(node.publishOnly[i] == jid) |
e6c2c66c2002
Handle 'none' on set affiliation bug #2246
Sonny Piers <sonny.piers@gmail.com>
parents:
48
diff
changeset
|
394 return node.publishOnly.splice(i, 1); |
e6c2c66c2002
Handle 'none' on set affiliation bug #2246
Sonny Piers <sonny.piers@gmail.com>
parents:
48
diff
changeset
|
395 for (var i in node.member) |
e6c2c66c2002
Handle 'none' on set affiliation bug #2246
Sonny Piers <sonny.piers@gmail.com>
parents:
48
diff
changeset
|
396 if(node.member[i] == jid) |
e6c2c66c2002
Handle 'none' on set affiliation bug #2246
Sonny Piers <sonny.piers@gmail.com>
parents:
48
diff
changeset
|
397 return node.member.splice(i, 1); |
52
296de54c1c4b
Rollback last commit error and fix typo error.
Sonny Piers <sonny.piers@gmail.com>
parents:
50
diff
changeset
|
398 })(); |
50
e6c2c66c2002
Handle 'none' on set affiliation bug #2246
Sonny Piers <sonny.piers@gmail.com>
parents:
48
diff
changeset
|
399 } |
0 | 400 |
401 storage.save(); | |
402 return errors.success; | |
403 }; | |
404 | |
405 storage.getAffiliation = function(jid, nodeID) { | |
406 var node; | |
407 if (typeof nodeID == 'string') { | |
408 node = storage.getNode(nodeID); | |
409 if (typeof node == 'number') | |
410 return node; | |
411 } else | |
412 node = nodeID; | |
413 | |
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
|
414 for (var affil in config.owner) |
c2954a9e5665
Add a super-owner that has power over all nodes; add support for
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
0
diff
changeset
|
415 if (typeof affil == 'string' && node.owner[affil] == 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
|
416 return 'super-owner'; |
0 | 417 for (var affil in node.owner) |
418 if (typeof affil == 'string' && node.owner[affil] == jid) | |
419 return 'owner'; | |
420 if (config.enabled('publisher-affiliation')) | |
421 for (var affil in node.publisher) | |
422 if (typeof affil == 'string' && node.publisher[affil] == jid) | |
423 return 'publisher'; | |
424 if (config.enabled('publish-only-affiliation')) | |
425 for (var affil in node.publishOnly) | |
426 if (typeof affil == 'string' && node.publishOnly[affil] == jid) | |
427 return 'publish-only'; | |
6 | 428 if (config.enabled('member-affiliation')) |
429 for (var affil in node.member) | |
430 if (typeof affil == 'string' && node.member[affil] == jid) | |
431 return 'member'; | |
0 | 432 if (config.enabled('outcast-affiliation')) |
433 for (var affil in node.outcast) | |
434 if (typeof affil == 'string' && node.outcast[affil] == jid) | |
435 return 'outcast'; | |
436 return 'none'; | |
437 }; | |
438 | |
439 storage.getAffiliationsFromJID = function(jid) { | |
440 var affils = {}; | |
26
f2e9365bc8ec
Can use differents backends for node storage. Writing directory-based backend in top of file-based backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
12
diff
changeset
|
441 for (var nodeID in backend.list) { |
f2e9365bc8ec
Can use differents backends for node storage. Writing directory-based backend in top of file-based backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
12
diff
changeset
|
442 var node = backend.list[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
|
443 for (var affil in config.owner) |
c2954a9e5665
Add a super-owner that has power over all nodes; add support for
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
0
diff
changeset
|
444 if (typeof affil == 'string' && config.owner[affil] == 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
|
445 affils[nodeID] = 'super-owner'; |
c2954a9e5665
Add a super-owner that has power over all nodes; add support for
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
0
diff
changeset
|
446 break; |
c2954a9e5665
Add a super-owner that has power over all nodes; add support for
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
0
diff
changeset
|
447 } |
c2954a9e5665
Add a super-owner that has power over all nodes; add support for
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
0
diff
changeset
|
448 for (var affil in node.owner) |
c2954a9e5665
Add a super-owner that has power over all nodes; add support for
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
0
diff
changeset
|
449 if (typeof affil == 'string' && node.owner[affil] == 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
|
450 affils[nodeID] = 'owner'; |
0 | 451 break; |
452 } | |
453 if (config.enabled('publisher-affiliation')) | |
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
|
454 for (var affil in node.publisher) |
c2954a9e5665
Add a super-owner that has power over all nodes; add support for
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
0
diff
changeset
|
455 if (typeof affil == 'string' && node.publisher[affil] == 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
|
456 affils[nodeID] = 'publisher'; |
0 | 457 break; |
458 } | |
459 if (config.enabled('publish-only-affiliation')) | |
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
|
460 for (var affil in node.publishOnly) |
c2954a9e5665
Add a super-owner that has power over all nodes; add support for
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
0
diff
changeset
|
461 if (typeof affil == 'string' && node.publishOnly[affil] == 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
|
462 affils[nodeID] = 'publish-only'; |
0 | 463 break; |
464 } | |
6 | 465 if (config.enabled('member-affiliation')) |
466 for (var affil in node.member) | |
467 if (typeof affil == 'string' && node.member[affil] == jid) { | |
468 affils[nodeID] = 'member'; | |
469 break; | |
470 } | |
0 | 471 if (config.enabled('outcast-affiliation')) |
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
|
472 for (var affil in node.outcast) |
c2954a9e5665
Add a super-owner that has power over all nodes; add support for
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
0
diff
changeset
|
473 if (typeof affil == 'string' && node.outcast[affil] == 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
|
474 affils[nodeID] = 'outcast'; |
0 | 475 break; |
476 } | |
477 } | |
478 return affils; | |
479 }; | |
480 | |
481 storage.getAffiliationsFromNodeID = function(nodeID) { | |
482 var node; | |
483 if (typeof nodeID == 'string') { | |
484 node = storage.getNode(nodeID); | |
485 if (typeof node == 'number') | |
486 return node; | |
487 } else | |
488 node = nodeID; | |
489 | |
490 var affils = {}; | |
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
|
491 for (var jid in config.owner) |
c2954a9e5665
Add a super-owner that has power over all nodes; add support for
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
0
diff
changeset
|
492 if (typeof jid == 'string') |
c2954a9e5665
Add a super-owner that has power over all nodes; add support for
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
0
diff
changeset
|
493 affils[config.owner[jid]] = 'super-owner'; |
0 | 494 for (var jid in node.owner) |
495 if (typeof jid == 'string') | |
496 affils[node.owner[jid]] = 'owner'; | |
497 if (config.enabled('publisher-affiliation')) | |
498 for (var jid in node.publisher) | |
499 if (typeof jid == 'string') | |
500 affils[node.publisher[jid]] = 'publisher'; | |
501 if (config.enabled('publish-only-affiliation')) | |
502 for (var jid in node.publishOnly) | |
503 if (typeof jid == 'string') | |
504 affils[node.publishOnly[jid]] = 'publish-only'; | |
505 if (config.enabled('member-affiliation')) | |
506 for (var jid in node.member) | |
507 if (typeof jid == 'string') | |
508 affils[node.member[jid]] = 'member'; | |
509 if (config.enabled('outcast-affiliation')) | |
510 for (var jid in node.outcast) | |
511 if (typeof jid == 'string') | |
512 affils[node.outcast[jid]] = 'outcast'; | |
513 return affils; | |
514 }; | |
515 | |
516 storage.debug = function() { | |
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
|
517 console.log('\x1b[1;33m' + require('sys').inspect(backend.list, null, null) + '\x1b[0m'); |
0 | 518 }; |