view modules/mod_adhoc.js @ 41:bc717575e66a

Much better handling of modules.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Sun, 20 Feb 2011 15:51:12 +0100
parents 4c808bfe0658
children 023f767662d3
line wrap: on
line source

// XEP-0050: Ad-Hoc Commands
exports.adHoc = {
	type: 'set',
	child: 'command',
	ns: NS.COMMANDS,
	func: function(response, stanza, request, to) {
		var action = request.getAttribute('action');
		if (action != 'execute')
			return makeError(response, errors.bad_request.n);

		var node = request.getAttribute('node');
		if (node == 'ping') {
			var cmd = xmpp.stanza('command', {xmlns: NS.COMMANDS,
	//				      sessionid: 'list:20020923T213616Z-700',
					      node: node,
					      'status': 'completed'})
				.c('note', {type: 'info'}).t('pong');
			response.cnode(cmd);
		} else if (node == 'reload') {
			storage.load();
			response.c('command', {xmlns: NS.COMMANDS,
					       node: node,
					       'status': 'completed'})
				.c('note', {type: 'info'}).t('The server has correctly reloaded.');
		} else
			return makeError(response, errors.bad_request.n);

		return response;
	}
}