Mercurial > psgxs
view modules/mod_disco.js @ 57:addbf6bbfaa8
Various fixes for the migration to ltx.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Mon, 12 Sep 2011 23:45:00 +0200 |
parents | 99bd1d1ac071 |
children |
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/>. */ 'use strict'; // SECTION 5.1: Discover Features exports.disco_info = { type: 'get', child: 'query', ns: NS.DISCO_INFO, func: function(response, stanza, request) { var nodeID = request.getAttribute('node'); // SECTION 5.3: Discover Node Information if (nodeID) { if (!storage.existsNode(nodeID)) return makeError(response, errors.node_does_not_exist.n); var conf = storage.getConfiguration(nodeID); if (typeof conf == 'number') return makeError(response, conf); var type = 'leaf' if (conf['pubsub#node_type']) type = conf['pubsub#node_type']; var query = new Element('query', {xmlns: NS.DISCO_INFO, node: nodeID}) .c('identity', {category: 'pubsub', type: type}).up() .c('feature', {'var': NS.PUBSUB}).up(); response.cnode(query); // SECTION 5.4 if (config.enabled('meta-data')) { var x = forms.build('result', 'node_metadata', storage.getMetadata(nodeID), true); if (x) query.cnode(x); } // SECTION 5.1: Discover Features } else { var query = new Element('query', {xmlns: NS.DISCO_INFO}) .c('identity', {category: 'pubsub', type: 'service', name: 'PubSub JavaScript Server'}).up() .c('feature', {'var': NS.DISCO_INFO}).up() .c('feature', {'var': NS.DISCO_ITEMS}).up() .c('feature', {'var': NS.PUBSUB}).up() .c('feature', {'var': 'jabber:iq:version'}).up() .c('feature', {'var': NS.COMMANDS}).up(); response.cnode(query); for (var i in config.activated) if (typeof i == 'string') query.c('feature', {'var': 'http://jabber.org/protocol/pubsub#' + config.activated[i]}).up(); } return response; } } // SECTION 5.2: Discover Nodes exports.disco_items = { type: 'get', child: 'query', ns: NS.DISCO_ITEMS, func: function(response, stanza, request, to) { var children; var nodeID = request.getAttribute('node'); if (nodeID && nodeID !== '') { if (nodeID == NS.COMMANDS) { // XEP-0050: Ad-Hoc Commands var query = new Element('query', {xmlns: NS.DISCO_ITEMS, node: nodeID}) .c('item', {jid: config.jid, node: 'ping', name: 'Ping'}).up() .c('item', {jid: config.jid, node: 'reload', name: 'Reload'}).up(); response.cnode(query); return response; } if (!storage.existsNode(nodeID)) return makeError(response, errors.node_does_not_exist.n); var query = new Element('query', {xmlns: NS.DISCO_ITEMS, node: nodeID}); response.cnode(query); children = storage.getChildren(nodeID); if (typeof children == 'number') return makeError(response, children); } var query = new Element('query', {xmlns: NS.DISCO_ITEMS}); response.cnode(query); children = storage.getChildren(); if (typeof children == 'number') return makeError(response, children); for (var nodeID in children) { var attr = {jid: config.jid}; if (children[nodeID] == 'node') { if (config.enabled('meta-data')) { var metadata = storage.getMetadata(nodeID); if (metadata['pubsub#title']) attr.name = metadata['pubsub#title']; if (metadata['pubsub#creator']) attr.creator = metadata['pubsub#creator']; if (config.hideNonAccessibleNodes) { var configuration = storage.getConfiguration(nodeID); if (configuration['pubsub#access_model'] == 'whitelist') { var affils = storage.getAffiliationsFromNodeID(nodeID); var affil = affils[JID.toBare(to)]; if (!affil || affil == 'outcast') continue; } } } attr.node = nodeID; // SECTION 5.5: Discover Items for a Node } else attr.name = nodeID; query.c('item', attr).up(); } return response; } }