comparison modules/mod_configure.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 b2faacfefb90
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 toBareJID = require('../util').toBareJID;
7 var NS = require('../namespaces');
8
9 // SECTION 8.2: Configure a Node
10 exports.getConfigure = {
11 type: 'get',
12 child: 'pubsub',
13 ns: NS.PUBSUB_OWNER,
14 pschild: 'configure',
15 func: function(response, stanza, request, to) {
16 if (!config.enabled('config-node'))
17 return makeError(response, errors.owner.configure.node_configuration_not_supported.n);
18
19 var nodeID = request.getAttribute('node');
20 if (!nodeID || nodeID == '')
21 return makeError(response, errors.nodeid_required.n);
22 if (!storage.existsNode(nodeID))
23 return makeError(response, errors.node_does_not_exist.n);
24
25 var affil = storage.getAffiliation(toBareJID(to), nodeID);
26 if (affil != 'super-owner' && affil != 'owner' && affil != 'publish-only')
27 return makeError(response, errors.pub.publish.insufficient_privileges.n);
28
29 response.c('pubsub', {xmlns: NS.PUBSUB_OWNER});
30 response.c('configure', {node: nodeID});
31
32 var form = forms.build('form', 'node_config', 'default', true);
33 response.cnode(form);
34
35 return response;
36 }
37 }
38
39 // SECTION 8.3: Request Default Node Configuration Options
40 exports.default = {
41 type: 'get',
42 child: 'pubsub',
43 ns: NS.PUBSUB_OWNER,
44 pschild: 'default',
45 func: function(response) {
46 if (!config.enabled('config-node'))
47 return makeError(response, errors.owner.default_options.node_configuration_not_supported.n);
48
49 response.c('pubsub', {xmlns: NS.PUBSUB_OWNER});
50 response.c('default');
51
52 var form = forms.build('node_config', service_configuration.node_config, null, true);
53 response.cnode(form);
54
55 return response;
56 }
57 }
58
59 // SECTION 8.2.4: Form Submission
60 exports.setConfigure = {
61 type: 'set',
62 child: 'pubsub',
63 ns: NS.PUBSUB_OWNER,
64 pschild: 'configure',
65 func: function(response, stanza, request, to) {
66 if (!config.enabled('config-node'))
67 return makeError(response, errors.owner.configure.node_configuration_not_supported.n);
68
69 var nodeID = request.getAttribute('node');
70 if (!nodeID)
71 return makeError(response, errors.nodeid_required.n);
72 if (!storage.existsNode(nodeID))
73 return makeError(response, errors.node_does_not_exist.n);
74
75 var affil = storage.getAffiliation(toBareJID(to), nodeID);
76 if (affil != 'super-owner' && affil != 'owner' && affil != 'publish-only')
77 return makeError(response, errors.forbidden.n);
78
79 var x = request.getChild('x', 'jabber:x:data');
80 if (!x)
81 return makeError(response, errors.bad_request.n);
82
83 var type = x.getAttribute('type');
84 if (type == 'cancel') {
85 conn.send(response);
86 return;
87 }
88 if (type != 'submit')
89 return makeError(response, errors.bad_request.n);
90
91 var form = forms.parse(x, true);
92 if (typeof form == 'number')
93 return makeError(response, form);
94
95 var conf = form;
96
97 var set = storage.configure(nodeID, conf);
98 if (typeof set == 'number')
99 return makeError(response, set);
100
101 return response;
102 }
103 }