changeset 6:2bcadb0531f4

A few changes.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Mon, 23 Aug 2010 14:41:55 +0200
parents d8a98540d749
children 781ac4f1e304
files psgxs.js storage.js
diffstat 2 files changed, 36 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/psgxs.js
+++ b/psgxs.js
@@ -86,7 +86,7 @@ function onIq(stanza) {
 				if (conf['pubsub#node_type'])
 					type = conf['pubsub#node_type'];
 
-				var q = xmpp.stanza('query', {xmlns: 'http://jabber.org/protocol/disco#info'})
+				var q = xmpp.stanza('query', {xmlns: 'http://jabber.org/protocol/disco#info', node: nodeID})
 				q.s('identity', {category: 'pubsub', type: type});
 				q.s('feature', {'var': 'http://jabber.org/protocol/pubsub'});
 
@@ -191,12 +191,15 @@ function onIq(stanza) {
 				if (nodeID && nodeID != '') {
 					if (!storage.existsNode(nodeID))
 						return makeError(response, errors.node_does_not_exist.n);
-					affils = storage.getAffiliation(toBareJID(to), nodeID);
+					affils = {};
+					affils[nodeID] = storage.getAffiliation(toBareJID(to), nodeID);
 				} else
 					affils = storage.getAffiliationsFromJID(toBareJID(to));
+
 				var s = xmpp.stanza('affiliations');
 				for (i in affils)
 					s.s('affiliation', {node: i, affiliation: affils[i]});
+
 				var p = xmpp.stanza('pubsub', {xmlns: 'http://jabber.org/protocol/pubsub'});
 				p.cx(s);
 				response.cx(p);
@@ -267,9 +270,12 @@ function onIq(stanza) {
 				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 != 'publisher' && affil != 'member')
-					return makeError(response, errors.pub.publish.insufficient_privileges.n);
+				var configuration = storage.getConfiguration(nodeID);
+				if (configuration['pubsub#access_model'] == 'whitelist') {
+					var affil = storage.getAffiliation(toBareJID(to), nodeID);
+					if (affil != 'super-owner' && affil != 'owner' && affil != 'publisher' && affil != 'member')
+						return makeError(response, errors.pub.publish.insufficient_privileges.n);
+				}
 
 				var item = [];
 				for (var i=0; i<items.children.length; i++) {
@@ -563,10 +569,18 @@ function onIq(stanza) {
 				if (!nodeID || nodeID == '')
 					return makeError(response, errors.nodeid_required.n);
 
+				var autocreate = false;
+				if (!storage.existsNode(nodeID)) {
+					if (config.enabled('auto-create'))
+						autocreate = true;
+					else
+						return makeError(response, errors.node_does_not_exist.n);
+				}
+
 				var affil = storage.getAffiliation(toBareJID(to), nodeID);
-				if (typeof affil == 'number')
+				if (typeof affil == 'number' && affil != errors.node_does_not_exist.n)
 					return makeError(response, affil);
-				if (affil != 'super-owner' && affil != 'owner' && affil != 'publisher' && affil != 'publish-only')
+				if (!autocreate && affil != 'super-owner' && affil != 'owner' && affil != 'publisher' && affil != 'publish-only')
 					return makeError(response, errors.forbidden.n);
 
 				var item = publish.getChild('item');
@@ -578,14 +592,6 @@ function onIq(stanza) {
 				if (item.tags.length != 1)
 					return makeError(response, errors.pub.publish.bad_payload.n);
 
-				var autocreate = false;
-				if (!storage.existsNode(nodeID)) {
-					if (config.enabled('auto-create'))
-						autocreate = true;
-					else
-						return makeError(response, errors.node_does_not_exist.n);
-				}
-
 				var conf = storage.getConfiguration(nodeID);
 				var publishOptions = pubsub.getChild('publish-options');
 				if (publishOptions && config.enabled('publish-options')) {
@@ -652,6 +658,10 @@ function onIq(stanza) {
 				if (!itemID || itemID == '')
 					return makeError(response, errors.pub.retract.item_or_itemid_required.n);
 
+				var affil = storage.getAffiliation(toBareJID(to), nodeID);
+				if (affil != 'super-owner' && affil != 'owner' && affil != 'publish-only')
+					return makeError(response, errors.forbidden.n);
+
 				var subscribers = storage.deleteItem(nodeID, itemID);
 				if (typeof subscribers == 'number')
 					return makeError(response, subscribers);
--- a/storage.js
+++ b/storage.js
@@ -136,7 +136,7 @@ storage.getChildren = function(node) {
 storage.getNode = function(nodeID) {
 	if (list[nodeID])
 		return list[nodeID];
-	return errors.sub.subscribe.node_does_not_exist.n;
+	return errors.node_does_not_exist.n;
 };
 
 storage.existsNode = function(nodeID) {
@@ -404,6 +404,10 @@ storage.getAffiliation = function(jid, n
 		for (var affil in node.publishOnly)
 			if (typeof affil == 'string' && node.publishOnly[affil] == jid)
 				return 'publish-only';
+	if (config.enabled('member-affiliation'))
+		for (var affil in node.member)
+			if (typeof affil == 'string' && node.member[affil] == jid)
+				return 'member';
 	if (config.enabled('outcast-affiliation'))
 		for (var affil in node.outcast)
 			if (typeof affil == 'string' && node.outcast[affil] == jid)
@@ -437,6 +441,12 @@ storage.getAffiliationsFromJID = functio
 					affils[nodeID] = 'publish-only';
 					break;
 				}
+		if (config.enabled('member-affiliation'))
+			for (var affil in node.member)
+				if (typeof affil == 'string' && node.member[affil] == jid) {
+					affils[nodeID] = 'member';
+					break;
+				}
 		if (config.enabled('outcast-affiliation'))
 			for (var affil in node.outcast)
 				if (typeof affil == 'string' && node.outcast[affil] == jid) {