changeset 47:0d3f18bb1d36

Remove usage of fdsq.js in modules.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Thu, 10 Mar 2011 16:13:49 +0100
parents 3126f8d6a5e3
children c979c4d0932b
files fdsq.js modules.js modules/mod_configure.js modules/mod_disco.js modules/mod_http.js modules/mod_manage.js modules/mod_options.js modules/mod_owner.js modules/mod_publish.js modules/mod_publish_message.js modules/mod_retrieve.js modules/mod_subscribe.js psgxs.js storage.js
diffstat 14 files changed, 42 insertions(+), 37 deletions(-) [+]
line wrap: on
line diff
--- a/fdsq.js
+++ b/fdsq.js
@@ -48,7 +48,7 @@ var JID = function(jid) {
 	this.bare = jid;
 };
 
-fdsq.toBareJID = function(jid) {
+fdsq.toBare = function(jid) {
 	var j = new JID(jid);
 	return j.bare;
 };
--- a/modules.js
+++ b/modules.js
@@ -27,6 +27,7 @@ var files = fs.readdirSync(dir);
 var regex = /^mod_.*\.js/;
 
 var Script = process.binding('evals').Script;
+var fdsq = require('./fdsq');
 var sandbox = {
 	process: process,
 	config: require('./configuration'),
@@ -38,7 +39,11 @@ var sandbox = {
 	NS: require('./namespaces'),
 	require: require,
 	storage: require('./storage'),
-	toBareJID: require('./fdsq').toBareJID,
+	makeRandomId: fdsq.makeRandomId,
+	JID: {
+		toBare: fdsq.toBare,
+		toResource: fdsq.toResource
+	},
 	exports: {}
 };
 
--- a/modules/mod_configure.js
+++ b/modules/mod_configure.js
@@ -35,7 +35,7 @@ exports.getConfigure = {
 		if (!storage.existsNode(nodeID))
 			return makeError(response, errors.node_does_not_exist.n);
 
-		var affil = storage.getAffiliation(toBareJID(to), nodeID);
+		var affil = storage.getAffiliation(JID.toBare(to), nodeID);
 		if (affil != 'super-owner' && affil != 'owner' && affil != 'publish-only')
 			return makeError(response, errors.pub.publish.insufficient_privileges.n);
 
@@ -89,7 +89,7 @@ exports.setConfigure = {
 		if (!storage.existsNode(nodeID))
 			return makeError(response, errors.node_does_not_exist.n);
 
-		var affil = storage.getAffiliation(toBareJID(to), nodeID);
+		var affil = storage.getAffiliation(JID.toBare(to), nodeID);
 		if (affil != 'super-owner' && affil != 'owner' && affil != 'publish-only')
 			return makeError(response, errors.forbidden.n);
 
@@ -137,7 +137,7 @@ exports.setConfigure2 = {
 		if (!storage.existsNode(nodeID))
 			return makeError(response, errors.node_does_not_exist.n);
 
-		var affil = storage.getAffiliation(toBareJID(to), nodeID);
+		var affil = storage.getAffiliation(JID.toBare(to), nodeID);
 		if (affil != 'super-owner' && affil != 'owner' && affil != 'publish-only')
 			return makeError(response, errors.forbidden.n);
 
--- a/modules/mod_disco.js
+++ b/modules/mod_disco.js
@@ -117,7 +117,7 @@ exports.disco_items = {
 						var configuration = storage.getConfiguration(nodeID);
 						if (configuration['pubsub#access_model'] == 'whitelist') {
 							var affils = storage.getAffiliationsFromNodeID(nodeID);
-							var affil = affils[toBareJID(to)];
+							var affil = affils[JID.toBare(to)];
 							if (!affil || affil == 'outcast')
 								continue;
 						}
--- a/modules/mod_http.js
+++ b/modules/mod_http.js
@@ -39,7 +39,7 @@ var sandbox = {
 	NS: require('./namespaces'),
 	require: require,
 	storage: require('./storage'),
-	toBareJID: require('./fdsq').toBareJID,
+	toBare: JID.toBare,
 	exports: {}
 };
 
--- a/modules/mod_manage.js
+++ b/modules/mod_manage.js
@@ -35,7 +35,7 @@ exports.manageRetrieveSub = {
 		if (!storage.existsNode(nodeID))
 			return makeError(response, errors.node_does_not_exist.n);
 
-		var affil = storage.getAffiliation(toBareJID(to), nodeID);
+		var affil = storage.getAffiliation(JID.toBare(to), nodeID);
 		if (affil != 'super-owner' && affil != 'owner')
 			return makeError(response, errors.forbidden.n);
 
@@ -67,7 +67,7 @@ exports.manageRetrieveAff = {
 			return makeError(response, errors.node_does_not_exist.n);
 
 		var affils = storage.getAffiliationsFromNodeID(nodeID);
-		var affil = affils[toBareJID(to)];
+		var affil = affils[JID.toBare(to)];
 		if (affil != 'super-owner' && affil != 'owner')
 			return makeError(response, errors.owner.manage_affiliations.retrieve_list.entity_is_not_an_owner.n);
 
@@ -97,7 +97,7 @@ exports.modifySub = {
 		if (!storage.existsNode(nodeID))
 			return makeError(response, errors.node_does_not_exist.n);
 
-		var affil = storage.getAffiliation(toBareJID(to), nodeID);
+		var affil = storage.getAffiliation(JID.toBare(to), nodeID);
 		if (affil != 'super-owner' && affil != 'owner')
 			return makeError(response, errors.forbidden.n);
 
@@ -149,7 +149,7 @@ exports.modifyAff = {
 		if (!storage.existsNode(nodeID))
 			return makeError(response, errors.node_does_not_exist.n);
 
-		var affil = storage.getAffiliation(toBareJID(to), nodeID);
+		var affil = storage.getAffiliation(JID.toBare(to), nodeID);
 		if (affil != 'super-owner' && affil != 'owner')
 			return makeError(response, errors.forbidden.n);
 
--- a/modules/mod_options.js
+++ b/modules/mod_options.js
@@ -38,7 +38,7 @@ exports.getConfigureSub = {
 		var jid = request.getAttribute('jid');
 		if (!jid)
 			return makeError(response, errors.sub.configure.subscriber_jid_required.n);
-		if (toBareJID(jid) != toBareJID(to))
+		if (JID.toBare(jid) != JID.toBare(to))
 			return makeError(response, errors.sub.configure.insufficient_privileges.n);
 
 		var subs = storage.getSubscription(jid, nodeID);
@@ -72,7 +72,7 @@ exports.configureSub = {
 			return makeError(response, errors.node_does_not_exist.n);
 
 		var jid = unsubscribe.getAttribute('jid');
-		if (!jid || toBareJID(jid) != toBareJID(to))
+		if (!jid || JID.toBare(jid) != JID.toBare(to))
 			return makeError(response, errors.sub.unsubscribe.insufficient_privileges.n);
 
 		var x = request.getChild('x', 'jabber:x:data');
--- a/modules/mod_owner.js
+++ b/modules/mod_owner.js
@@ -35,13 +35,13 @@ exports.create = {
 		if (!nodeID || nodeID == '') {
 			if (!config.enabled('instant-nodes'))
 				return makeError(response, errors.owner.create.instant_nodes_not_supported.n);
-			nodeID = fdsq.makeRandomId();
+			nodeID = makeRandomId();
 			instant = true;
 		}
 		if (storage.existsNode(nodeID))
 			return makeError(response, errors.owner.create.nodeid_already_exists.n);
 
-		var bare = toBareJID(to);
+		var bare = JID.toBare(to);
 		var right = false;
 
 		// Check for super-owner
@@ -88,7 +88,7 @@ exports['delete'] = {
 		if (!storage.existsNode(nodeID))
 			return makeError(response, errors.node_does_not_exist.n);
 
-		var affil = storage.getAffiliation(toBareJID(to), nodeID);
+		var affil = storage.getAffiliation(JID.toBare(to), nodeID);
 		if (affil != 'super-owner' && affil != 'owner')
 			return makeError(response, errors.forbidden.n);
 
@@ -118,7 +118,7 @@ exports.purge = {
 		if (!storage.existsNode(nodeID))
 			return makeError(response, errors.node_does_not_exist.n);
 
-		var affil = storage.getAffiliation(toBareJID(to), nodeID);
+		var affil = storage.getAffiliation(JID.toBare(to), nodeID);
 		if (affil != 'super-owner' && affil != 'owner')
 			return makeError(response, errors.forbidden.n);
 
--- a/modules/mod_publish.js
+++ b/modules/mod_publish.js
@@ -41,7 +41,7 @@ exports.publish = {
 				return makeError(response, errors.node_does_not_exist.n);
 		}
 
-		var affil = storage.getAffiliation(toBareJID(to), nodeID);
+		var affil = storage.getAffiliation(JID.toBare(to), nodeID);
 		if (typeof affil == 'number' && affil != errors.node_does_not_exist.n)
 			return makeError(response, affil);
 		if (!autocreate && affil != 'super-owner' && affil != 'owner' && affil != 'publisher' && affil != 'publish-only')
@@ -51,7 +51,7 @@ exports.publish = {
 		var itemID = item.getAttribute('id');
 		if (!config.enabled('item-ids') && itemID)
 			return makeError(response, errors.itemid_required.n);
-		itemID = itemID? itemID: fdsq.makeRandomId();
+		itemID = itemID? itemID: makeRandomId();
 
 		if (item.tags.length != 1)
 			return makeError(response, errors.pub.publish.bad_payload.n);
@@ -77,7 +77,7 @@ exports.publish = {
 		if (autocreate) {
 			if (!form)
 				form = {};
-			form['pubsub#creator'] = toBareJID(to);
+			form['pubsub#creator'] = JID.toBare(to);
 
 			var r = storage.createNode(nodeID, form);
 			if (typeof r == 'number')
@@ -129,7 +129,7 @@ exports.retract = {
 		if (!itemID || itemID == '')
 			return makeError(response, errors.pub.retract.item_or_itemid_required.n);
 
-		var affil = storage.getAffiliation(toBareJID(to), nodeID);
+		var affil = storage.getAffiliation(JID.toBare(to), nodeID);
 		if (affil != 'super-owner' && affil != 'owner' && affil != 'publish-only')
 			return makeError(response, errors.forbidden.n);
 
--- a/modules/mod_publish_message.js
+++ b/modules/mod_publish_message.js
@@ -26,7 +26,7 @@ exports.publishMessage = {
 		if (!config.enabled('publish'))
 			return makeError(response, errors.pub.publish.item_publication_not_supported.n);
 
-		var nodeID = fdsq.toResource(from);
+		var nodeID = JID.toResource(from);
 		if (!nodeID || nodeID == '')
 			return makeError(response, errors.nodeid_required.n);
 
@@ -38,7 +38,7 @@ exports.publishMessage = {
 				return makeError(response, errors.node_does_not_exist.n);
 		}
 
-		var affil = storage.getAffiliation(toBareJID(to), nodeID);
+		var affil = storage.getAffiliation(JID.toBare(to), nodeID);
 		if (typeof affil == 'number' && affil != errors.node_does_not_exist.n)
 			return makeError(response, affil);
 		if (!autocreate && affil != 'super-owner' && affil != 'owner' && affil != 'publisher' && affil != 'publish-only')
@@ -46,7 +46,7 @@ exports.publishMessage = {
 
 		if (!config.enabled('item-ids'))
 			return makeError(response, errors.itemid_required.n);
-		var itemID = fdsq.makeRandomId();
+		var itemID = makeRandomId();
 
 		var now = new Date();
 
@@ -68,7 +68,7 @@ exports.publishMessage = {
 		if (autocreate) {
 			if (!form)
 				form = {};
-			form['pubsub#creator'] = toBareJID(to);
+			form['pubsub#creator'] = JID.toBare(to);
 
 			var r = storage.createNode(nodeID, form);
 			if (typeof r == 'number')
--- a/modules/mod_retrieve.js
+++ b/modules/mod_retrieve.js
@@ -33,9 +33,9 @@ exports.retrieveSubscriptions = {
 		if (nodeID && nodeID != '') {
 			if (!storage.existsNode(nodeID))
 				return makeError(response, errors.node_does_not_exist.n);
-			var subs = storage.getSubscription(toBareJID(to), nodeID);
+			var subs = storage.getSubscription(JID.toBare(to), nodeID);
 		} else
-			var subs = storage.getSubscription(toBareJID(to));
+			var subs = storage.getSubscription(JID.toBare(to));
 
 		response.c('pubsub', {xmlns: NS.PUBSUB})
 			.c('subscriptions');
@@ -62,9 +62,9 @@ exports.retrieveAffiliations = {
 			if (!storage.existsNode(nodeID))
 				return makeError(response, errors.node_does_not_exist.n);
 			var affils = {};
-			affils[nodeID] = storage.getAffiliation(toBareJID(to), nodeID);
+			affils[nodeID] = storage.getAffiliation(JID.toBare(to), nodeID);
 		} else
-			var affils = storage.getAffiliationsFromJID(toBareJID(to));
+			var affils = storage.getAffiliationsFromJID(JID.toBare(to));
 
 		response.c('pubsub', {xmlns: NS.PUBSUB})
 			.c('affiliations');
@@ -94,7 +94,7 @@ exports.retrieveItems = {
 
 		var configuration = storage.getConfiguration(nodeID);
 		if (configuration['pubsub#access_model'] == 'whitelist') {
-			var affil = storage.getAffiliation(toBareJID(to), nodeID);
+			var affil = storage.getAffiliation(JID.toBare(to), nodeID);
 			if (affil != 'super-owner' && affil != 'owner' && affil != 'publisher' && affil != 'member')
 				return makeError(response, errors.pub.publish.insufficient_privileges.n);
 		}
--- a/modules/mod_subscribe.js
+++ b/modules/mod_subscribe.js
@@ -39,12 +39,12 @@ exports.subscribe = {
 		if (!configuration['pubsub#subscribe'])
 			return makeError(response, errors.sub.subscribe.not_supported.n);
 
-		var affil = storage.getAffiliation(toBareJID(to), nodeID);
+		var affil = storage.getAffiliation(JID.toBare(to), nodeID);
 		if (affil == 'publish-only' || affil == 'outcast')
 			return makeError(response, errors.pub.publish.insufficient_privileges.n);
 
 		var jid = request.getAttribute('jid');
-		if (!jid || toBareJID(jid) != toBareJID(to))
+		if (!jid || JID.toBare(jid) != JID.toBare(to))
 			return makeError(response, errors.sub.subscribe.jids_do_not_match.n);
 
 		/*
@@ -130,7 +130,7 @@ exports.unsubscribe = {
 			return makeError(response, errors.node_does_not_exist.n);
 
 		var jid = request.getAttribute('jid');
-		if (!jid || toBareJID(jid) != toBareJID(to))
+		if (!jid || JID.toBare(jid) != JID.toBare(to))
 			return makeError(response, errors.sub.unsubscribe.insufficient_privileges.n);
 
 		var subID = storage.subscribe(nodeID, jid, 'none');
--- a/psgxs.js
+++ b/psgxs.js
@@ -28,7 +28,7 @@ var storage = require('./storage');
 var errors = require('./errors');
 var makeError = errors.makeError;
 var fdsq = require('./fdsq');
-var toBareJID = fdsq.toBareJID;
+var toBare = fdsq.toBare;
 var config = require('./configuration');
 var forms = require('./forms');
 var conn = new xmpp.Connection(config.host, config.port);
--- a/storage.js
+++ b/storage.js
@@ -27,7 +27,7 @@ var config = require('./configuration');
 var service_configuration = config.service_configuration;
 var Configuration = config.Configuration;
 var fdsq = require('./fdsq');
-var toBareJID = fdsq.toBareJID;
+var toBare = fdsq.toBare;
 
 var nodes = require('./nodes');
 var Node = nodes.Node;
@@ -308,12 +308,12 @@ storage.getSubscription = function(jid, 
 	if (nodeID) {
 		var node = storage.getNode(nodeID);
 		for (var sub in node.subscribers)
-			if (toBareJID(sub) == jid)
+			if (toBare(sub) == jid)
 				return node.subscribers[sub]
 	} else {
 		for (var node in backend.list) {
 			for (var sub in backend.list[node].subscribers) {
-				if (toBareJID(sub) == jid)
+				if (toBare(sub) == jid)
 					subs[node] = backend.list[node].subscribers[sub];
 			}
 		}