Mercurial > psgxs
view 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 |
line wrap: on
line source
var config = require('../configuration'); var storage = require('../storage'); var forms = require('../forms'); var errors = require('../errors'); var makeError = errors.makeError; var toBareJID = require('../util').toBareJID; var NS = require('../namespaces'); // SECTION 8.2: Configure a Node exports.getConfigure = { type: 'get', child: 'pubsub', ns: NS.PUBSUB_OWNER, pschild: 'configure', func: function(response, stanza, request, to) { if (!config.enabled('config-node')) return makeError(response, errors.owner.configure.node_configuration_not_supported.n); var nodeID = request.getAttribute('node'); if (!nodeID || nodeID == '') return makeError(response, errors.nodeid_required.n); if (!storage.existsNode(nodeID)) return makeError(response, errors.node_does_not_exist.n); var affil = storage.getAffiliation(toBareJID(to), nodeID); if (affil != 'super-owner' && affil != 'owner' && affil != 'publish-only') return makeError(response, errors.pub.publish.insufficient_privileges.n); response.c('pubsub', {xmlns: NS.PUBSUB_OWNER}); response.c('configure', {node: nodeID}); var form = forms.build('form', 'node_config', 'default', true); response.cnode(form); return response; } } // SECTION 8.3: Request Default Node Configuration Options exports.default = { type: 'get', child: 'pubsub', ns: NS.PUBSUB_OWNER, pschild: 'default', func: function(response) { if (!config.enabled('config-node')) return makeError(response, errors.owner.default_options.node_configuration_not_supported.n); response.c('pubsub', {xmlns: NS.PUBSUB_OWNER}); response.c('default'); var form = forms.build('node_config', service_configuration.node_config, null, true); response.cnode(form); return response; } } // SECTION 8.2.4: Form Submission exports.setConfigure = { type: 'set', child: 'pubsub', ns: NS.PUBSUB_OWNER, pschild: 'configure', func: function(response, stanza, request, to) { if (!config.enabled('config-node')) return makeError(response, errors.owner.configure.node_configuration_not_supported.n); var nodeID = request.getAttribute('node'); if (!nodeID) return makeError(response, errors.nodeid_required.n); if (!storage.existsNode(nodeID)) return makeError(response, errors.node_does_not_exist.n); var affil = storage.getAffiliation(toBareJID(to), nodeID); if (affil != 'super-owner' && affil != 'owner' && affil != 'publish-only') return makeError(response, errors.forbidden.n); var x = request.getChild('x', 'jabber:x:data'); if (!x) return makeError(response, errors.bad_request.n); var type = x.getAttribute('type'); if (type == 'cancel') { conn.send(response); return; } if (type != 'submit') return makeError(response, errors.bad_request.n); var form = forms.parse(x, true); if (typeof form == 'number') return makeError(response, form); var conf = form; var set = storage.configure(nodeID, conf); if (typeof set == 'number') return makeError(response, set); return response; } }