Mercurial > psgxs
comparison modules/mod_disco.js @ 24:b80ab94da447
Add new modules files.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Mon, 01 Nov 2010 00:02:27 +0100 |
parents | |
children | bc717575e66a |
comparison
equal
deleted
inserted
replaced
23:5fc4ee90c1bc | 24:b80ab94da447 |
---|---|
1 var config = require('../configuration'); | |
2 var storage = require('../storage'); | |
3 var forms = require('../forms'); | |
4 var errors = require('../errors'); | |
5 var makeError = errors.makeError; | |
6 var NS = require('../namespaces'); | |
7 | |
8 // SECTION 5.1: Discover Features | |
9 exports.disco_info = { | |
10 type: 'get', | |
11 child: 'query', | |
12 ns: NS.DISCO_INFO, | |
13 func: function(response, stanza, request) { | |
14 var nodeID = request.getAttribute('node'); | |
15 | |
16 // SECTION 5.3: Discover Node Information | |
17 if (nodeID && nodeID != '') { | |
18 if (!storage.existsNode(nodeID)) | |
19 return makeError(response, errors.node_does_not_exist.n); | |
20 | |
21 var conf = storage.getConfiguration(nodeID); | |
22 if (typeof conf == 'number') | |
23 return makeError(response, conf); | |
24 | |
25 var type = 'leaf' | |
26 if (conf['pubsub#node_type']) | |
27 type = conf['pubsub#node_type']; | |
28 | |
29 response.c('query', {xmlns: NS.DISCO_INFO, node: nodeID}) | |
30 .c('identity', {category: 'pubsub', type: type}).up() | |
31 .c('feature', {'var': NS.PUBSUB}).up(); | |
32 | |
33 // SECTION 5.4 | |
34 if (config.enabled('meta-data')) { | |
35 var x = forms.build('result', 'node_metadata', storage.getMetadata(nodeID), true); | |
36 if (x) | |
37 response.cnode(x); | |
38 } | |
39 | |
40 // SECTION 5.1: Discover Features | |
41 } else { | |
42 response.c('query', {xmlns: NS.DISCO_INFO}) | |
43 .c('identity', {category: 'pubsub', type: 'service', name: 'PubSub JavaScript Server'}).up() | |
44 .c('feature', {'var': NS.DISCO_INFO}).up() | |
45 .c('feature', {'var': NS.DISCO_ITEMS}).up() | |
46 .c('feature', {'var': NS.PUBSUB}).up() | |
47 .c('feature', {'var': 'jabber:iq:version'}).up() | |
48 .c('feature', {'var': NS.COMMANDS}).up(); | |
49 | |
50 for (var i in config.activated) | |
51 if (typeof i == 'string') | |
52 response.c('feature', {'var': 'http://jabber.org/protocol/pubsub#' + config.activated[i]}).up(); | |
53 } | |
54 | |
55 return response; | |
56 } | |
57 } | |
58 | |
59 // SECTION 5.2: Discover Nodes | |
60 exports.disco_items = { | |
61 type: 'get', | |
62 child: 'query', | |
63 ns: NS.DISCO_ITEMS, | |
64 func: function(response, stanza, request) { | |
65 var children; | |
66 var nodeID = request.getAttribute('node'); | |
67 if (nodeID && nodeID != '') { | |
68 if (nodeID == NS.COMMANDS) { | |
69 // XEP-0050: Ad-Hoc Commands | |
70 | |
71 response.c('query', {xmlns: NS.DISCO_ITEMS, node: nodeID}) | |
72 .c('item', {jid: config.jid, node: 'ping', name: 'Ping'}).up() | |
73 .c('item', {jid: config.jid, node: 'reload', name: 'Reload'}).up(); | |
74 | |
75 return response; | |
76 } else { | |
77 if (!storage.existsNode(nodeID)) | |
78 return makeError(response, errors.node_does_not_exist.n); | |
79 | |
80 response.c('query', {xmlns: NS.DISCO_ITEMS, node: nodeID}); | |
81 | |
82 children = storage.getChildren(nodeID); | |
83 if (typeof children == 'number') | |
84 return makeError(response, children); | |
85 } | |
86 } else { | |
87 response.c('query', {xmlns: NS.DISCO_ITEMS}); | |
88 | |
89 children = storage.getChildren(); | |
90 if (typeof children == 'number') | |
91 return makeError(response, children); | |
92 } | |
93 | |
94 for (var i in children) { | |
95 var attr = {jid: config.jid}; | |
96 if (children[i] == 'node') { | |
97 if (config.enabled('meta-data')) { | |
98 var metadata = storage.getMetadata(i); | |
99 if (metadata['pubsub#title']) | |
100 attr.name = metadata['pubsub#title']; | |
101 } | |
102 attr.node = i; | |
103 | |
104 // SECTION 5.5: Discover Items for a Node | |
105 } else | |
106 attr.name = i; | |
107 | |
108 response.c('item', attr).up(); | |
109 } | |
110 | |
111 return response; | |
112 } | |
113 } |