view configuration.js @ 26:f2e9365bc8ec

Can use differents backends for node storage. Writing directory-based backend in top of file-based backend.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Mon, 01 Nov 2010 02:39:58 +0100
parents 06abc804e2ab
children bc717575e66a
line wrap: on
line source

/*
 *  Copyright (C) 2010  Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
 *
 *  This file is part of PSĜS, a PubSub server written in JavaScript.
 *
 *  PSĜS is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU Affero General Public License as
 *  published by the Free Software Foundation, either version 3 of the
 *  License.
 *
 *  PSĜS is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Affero General Public License for more details.
 *
 *  You should have received a copy of the GNU Affero General Public License
 *  along with PSĜS.  If not, see <http://www.gnu.org/licenses/>.
 */

var config = exports;

config.jid = 'pubsub.example.org';
config.password = 'hellohello';
config.superOwner = ['you@example.com'];
config.version = '0.1';
config.os = 'GNU/Linux';
config.allowCreateNode = [/@example\.com$/]; // value is an array of RegExp JIDs. If only super-owner should be able to create nodes, use [].
config.backend = 'directory'; // Put backends in “backends” directory.
config.access = 'open'; // values include open, whitelist (by members) and authorize (owners of the node receive notification). presence and roster aren’t implemented yet.

config.activated = [
	'auto-create',
	//'auto-subscribe', // Impossible à utiliser dans un component
	//'collections', //TODO
	'config-node',
	'create-and-configure',
	'create-nodes',
	'delete-items',
	'delete-nodes',
	//'filtered-notifications', // Impossible à utiliser dans un component
	'get-pending',
	'instant-nodes',
	'item-ids',
	'last-published', // Impossible de se baser sur la présence dans un component
	//'leased-subscription', //TODO
	'manage-subscriptions',
	'member-affiliation',
	'meta-data',
	'modify-affiliations',
	//'multi-collection', //TODO
	//'multi-subscribe', //TODO
	'outcast-affiliation',
	'persistent-items',
	//'presence-notifications', // Impossible à utiliser dans un component
	//'presence-subscribe', // Impossible à utiliser dans un component
	'publish',
	'publish-options',
	'publish-only-affiliation',
	'publisher-affiliation',
	'purge-nodes',
	'retract-items',
	'retrieve-affiliations',
	'retrieve-default',
	'retrieve-default-sub',
	'retrieve-items',
	'retrieve-subscriptions',
	'subscribe',
	'subscription-options',
	'subscription-notifications',
];

config.service_configuration = {
	subscribe_authorization: {
		FORM_TYPE: {type: 'hidden', value: 'http://jabber.org/protocol/pubsub#subscribe_authorization'},
		_TITLE: 'PubSub subscriber request',
		_INSTRUCTIONS: 'To approve this entity’s subscription request,\nclick the OK button. To deny the request, click the\ncancel button.',
		'pubsub#allow': {type: 'boolean', label: 'Whether to allow the subscription', value: false},
		'pubsub#node': {type: 'text-single', label: 'The NodeID of the relevant node'},
		'pubsub#subid': {type: 'hidden'},
		'pubsub#subscriber_jid': {type: 'jid-single', label: 'The address (JID) of the subscriber'},
	},
	subscribe_options: {
		FORM_TYPE: {type: 'hidden', value: 'http://jabber.org/protocol/pubsub#subscribe_options'},
		'pubsub#deliver': {type: 'boolean', label: 'Whether an entity wants to receive or disable notifications', value: true},
		'pubsub#digest': {type: 'boolean', label: 'Whether an entity wants to receive digests (aggregations) of notifications or all notifications individually', value: false},
		'pubsub#digest_frequency': {type: 'text-single', label: 'The minimum number of milliseconds between sending any two notification digests', value: 24*60*60*1000},
//		'pubsub#expire': {type: 'text-single', label: 'The DateTime at which a leased subscription will end or has ended'},
//		'pubsub#include_body': {type: 'boolean', label: 'Whether an entity wants to receive an XMPP message body in addition to the payload format', value: false},
//		'pubsub#show-values': {type: 'list-multi', label: 'The presence states for which an entity wants to receive notifications', options: {
//			away: {label: 'XMPP Show Value of Away'},
//			chat: {label: 'XMPP Show Value of Chat'},
//			dnd: {label: 'XMPP Show Value of DND (Do Not Disturb)'},
//			online: {label: 'Mere Availability in XMPP (No Show Value)'},
//			xa: {label: 'XMPP Show Value of XA (Extended Away)'},
//		}, value: ['online', 'chat', 'away']},
//		'pubsub#subscription_type': {type: 'list-single', options: {
//			items: {label: 'Receive notification of new items only'},
//			nodes: {label: 'Receive notification of new nodes only'},
//		}},
//		'pubsub#subscription_depth': {type: 'list-single', options: {
//			'1': {label: 'Receive notification from direct child nodes only'},
//			all: {label: 'Receive notification from all descendent nodes'},
//		}},
	},
	node_metadata: {
		FORM_TYPE: {type: 'hidden', value: 'http://jabber.org/protocol/pubsub#meta-data'},
		'pubsub#contact': {type: 'jid-multi', label: 'The JIDs of those to contact with questions'},
		'pubsub#creation_date': {type: 'text-single', label: 'The datetime when the node was created', value: function(){return new Date();}},
		'pubsub#creator': {type: 'jid-single', label: 'The JID of the node creator'},
		'pubsub#description': {type: 'text-single', label: 'A description of the node'},
		'pubsub#language': {type: 'list-single', label: 'The default language of the node'},
		'pubsub#num_subscribers': {type: 'text-single', label: 'The number of subscribers to the node', value: 0},
		'pubsub#owner': {type: 'jid-multi', label: 'The JIDs of those with an affiliation of owner'},
		'pubsub#publisher': {type: 'jid-multi', label: 'The JIDs of those with an affiliation of publisher'},
		'pubsub#title': {type: 'text-single', label: 'The name of the node'},
		'pubsub#type': {type: 'text-single', label: 'Payload type'},
	},
	node_config: {
		FORM_TYPE: {type: 'hidden', value: 'http://jabber.org/protocol/pubsub#node_config'},
		'pubsub#access_model': {type: 'list-single', label: 'Who may subscribe and retrieve items', options: {
			authorize: {label: 'Subscription requests must be approved and only subscribers may retrieve items'},
			open: {label: 'Anyone may subscribe and retrieve items'},
//			presence: {label: 'Anyone with a presence subscription of both or from may subscribe and retrieve items'},
//			roster: {label: 'Anyone in the specified roster group(s) may subscribe and retrieve items'},
			whitelist: {label: 'Only those on a whitelist may subscribe and retrieve items'},
		}},
//		'pubsub#body_xslt': {type: 'text-single', label: 'The URL of an XSL transformation which can be applied to payloads in order to generate an appropriate message body element.'},
//		'pubsub#children_association_policy': {type: 'list-single', label: 'Who may associate leaf nodes with a collection', options: {
//			all: {label: 'Anyone may associate leaf nodes with the collection'},
//			owners: {label: 'Only collection node owners may associate leaf nodes with the collection'},
//			whitelist: {label: 'Only those on a whitelist may associate leaf nodes with the collection'},
//		}},
//		'pubsub#children_association_whitelist': {type: 'jid-multi', label: 'The list of JIDs that may associate leaf nodes with a collection'},
//		'pubsub#children': {type: 'text-multi', label: 'The child nodes (leaf or collection) associated with a collection'},
//		'pubsub#children_max': {type: 'text-single', label: 'The maximum number of child nodes that can be associated with a collection'},
//		'pubsub#collection': {type: 'text-multi', label: 'The collection(s) with which a node is affiliated'},
		'pubsub#contact': {type: 'jid-multi', label: 'The JIDs of those to contact with questions'},
//		'pubsub#dataform_xslt': {type: 'text-single', label: 'The URL of an XSL transformation which can be applied to the payload format in order to generate a valid Data Forms result that the client could display using a generic Data Forms rendering engine'},
		'pubsub#deliver_notifications': {type: 'boolean', label: 'Whether to deliver event notifications', value: true},
//		'pubsub#deliver_payloads': {type: 'boolean', label: 'Whether to deliver payloads with event notifications; applies only to leaf nodes'},
		'pubsub#description': {type: 'text-single', label: 'A description of the node'},
//		'pubsub#item_expire': {type: 'text-single', label: 'Number of seconds after which to automatically purge items'},
//		'pubsub#itemreply': {type: 'list-single', label: 'Whether owners or publisher should receive replies to items', options: {
//			owner: {label: 'Statically specify a replyto of the node owner(s)'},
//			publisher: {label: 'Dynamically specify a replyto of the item publisher'},
//		}},
		'pubsub#language': {type: 'list-single', label: 'The default language of the node'},
//		'pubsub#max_items': {type: 'text-single', label: 'The maximum number of items to persist'},
//		'pubsub#max_payload_size': {type: 'text-single', label: 'The maximum payload size in bytes'},
		'pubsub#node_type': {type: 'list-single', label: 'Whether the node is a leaf (default) or a collection', options: {
			leaf: {label: 'The node is a leaf node (default)'},
			collection: {label: 'The node is a collection node'},
		}, value: 'leaf'},
//		'pubsub#notification_type': {type: 'list-single', label: 'Specify the delivery style for notifications', options: {
//			normal: {label: 'Messages of type normal'},
//			headline: {label: 'Messages of type headline'},
//			iq: {label: 'IQ stanzas (works only with presence-based delivery)'},
//		}},
//		'pubsub#notify_config': {type: 'boolean', label: 'Whether to notify subscribers when the node configuration changes'},
//		'pubsub#notify_delete': {type: 'boolean', label: 'Whether to notify subscribers when the node is deleted'},
//		'pubsub#notify_retract': {type: 'boolean', label: 'Whether to notify subscribers when items are removed from the node'},
//		'pubsub#notify_sub': {type: 'boolean', label: 'Whether to notify owners about new subscribers and unsubscribes'},
//		'pubsub#persist_items': {type: 'boolean', label: 'Whether to persist items to storage'},
//		'pubsub#presence_based_delivery': {type: 'boolean', label: 'Whether to deliver notifications to available users only'},
		'pubsub#publish_model': {type: 'list-single', label: 'The publisher model', options: {
			publishers: {label: 'Only publishers may publish'},
			subscribers: {label: 'Subscribers may publish'},
			open: {label: 'Anyone may publish'},
		}, value: 'publishers'},
//		'pubsub#purge_offline': {type: 'boolean', label: 'Whether to purge all items when the relevant publisher goes offline'},
//		'pubsub#roster_groups_allowed': {type: 'list-multi', label: 'The roster group(s) allowed to subscribe and retrieve items'},
//		'pubsub#send_last_published_item': {type: 'list-single', label: 'When to send the last published item', options: {
//			never: {label: 'Never'},
//			on_sub: {label: 'When a new subscription is processed'},
//			on_sub_and_presence: {label: 'When a new subscription is processed and whenever a subscriber comes online'},
//		}, value: 'never'},
//		'pubsub#tempsub': {type: 'boolean', label: 'Whether to make all subscriptions temporary, based on subscriber presence'},
		'pubsub#subscribe': {type: 'boolean', label: 'Whether to allow subscriptions', value: true},
		'pubsub#title': {type: 'text-single', label: 'A friendly name for the node'},
		'pubsub#type': {type: 'text-single', label: 'The type of node data, usually specified by the namespace of the payload (if any)', value: 'http://www.w3.org/2005/Atom'},
	},
	'publish-options': {
		FORM_TYPE: {type: 'hidden', value: 'http://jabber.org/protocol/pubsub#publish-options'},
		'pubsub#access_model': {type: 'list-single', label: 'Precondition: node configuration with the specified access model', options: {
			authorize: {label: 'Access model of authorize'},
			open: {label: 'Access model of open'},
//			presence: {label: 'Access model of presence'},
//			roster: {label: 'Access model of roster'},
			whitelist: {label: 'Access model of whitelist'},
		}, value: 'open'},
	},
};

config.Configuration = function(def, params) {
	for (var i in def) {
		if (typeof (def[i].value) != 'undefined') {
			if (typeof (def[i].value) == 'function')
				this[i] = def[i].value();
			else
				this[i] = def[i].value;
		}
	}
	if (params)
		for (var i in params)
			if (typeof def[i] != 'undefined')
				this[i] = params[i];
};

config.enabled = function(feature) {
	for (var i in config.activated)
		if (typeof i == 'string' && feature == config.activated[i])
			return true;
	return false;
};

config.enable = function(feature) {
	config.activated.push(feature);
}

config.disable = function(feature) {
	if (typeof feature == 'string')
		config.activated.splice(config.activated.indexOf(feature), 1);
	else if (typeof feature == 'function') {
		for (var i in config.activated)
			if (feature(config.activated[i]))
				config.disable(config.activated[i]);
	}
}

if (config.access == 'whitelist') {
	config.disable(/access-.+/);
	config.enable('access-whitelist');
	config.service_configuration.node_config['pubsub#access_model'].value = 'whitelist';
	config.service_configuration['publish-options']['pubsub#access_model'].value = 'whitelist';
} else if (config.access == 'authorize') {
	config.disable(/access-.+/);
	config.enable('access-authorize');
	config.service_configuration.node_config['pubsub#access_model'].value = 'authorize';
	config.service_configuration['publish-options']['pubsub#access_model'].value = 'authorize';
} else if (config.access == 'open') {
	config.disable(/access-.+/);
	config.enable('access-open');
	config.service_configuration.node_config['pubsub#access_model'].value = 'open';
	config.service_configuration['publish-options']['pubsub#access_model'].value = 'open';
}