Mercurial > psgxs
changeset 33:62cbb1c49bc5
Fix publish; add owner metadata field; add HTTP module and Atom HTTP module.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Fri, 05 Nov 2010 14:01:45 +0100 |
parents | 8735fc6f6f53 |
children | dcf1f09f8cee |
files | backends/directory.js modules/http/mod_atom.js modules/mod_http.js modules/mod_publish.js namespaces.js storage.js |
diffstat | 6 files changed, 104 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/backends/directory.js +++ b/backends/directory.js @@ -117,7 +117,7 @@ backend.load = function(dir) { var file = files[i]; var nodeID = file.replace(/\.json$/, ''); - var data = fs.readFileSync(dir+'/'+file); + var data = fs.readFileSync(dir+'/'+file).toString(); var obj = eval('('+data+')'); backend.list[nodeID] = endParsing(obj);
new file mode 100644 --- /dev/null +++ b/modules/http/mod_atom.js @@ -0,0 +1,55 @@ +var config = require('../../configuration'); +var storage = require('../../storage'); +var forms = require('../../forms'); +var errors = require('../../errors'); +var makeError = errors.makeError; +var NS = require('../../namespaces'); +var xmpp = require('xmpp'); + +exports.atom = { + url: /^\/atom/, + func: function (req, res) { + var url = require('url').parse(req.url); + nodeID = url.pathname.substr(url.pathname.indexOf('/', 1)+1); + + var children; + if (nodeID && nodeID != '') { + var md = storage.getMetadata(nodeID); + if (md['pubsub#type'] != NS.ATOM) + return false; + + var response = xmpp.stanza('feed', {xmlns: 'http://www.w3.org/2005/Atom'}); + res.writeHead(200, {'Content-Type': 'text/xml'}); + if (!storage.existsNode(nodeID)) + return false; + + if (md['pubsub#title']) + response.c('title').t(md['pubsub#title']).up(); + if (md['pubsub#description']) + response.c('subtitle').t(md['pubsub#description']).up(); + if (md['pubsub#creation_date']) + response.c('published').t(md['pubsub#creation_date']).up(); + + children = storage.getItems(nodeID); + if (typeof children == 'number') + return false; + + for (var i in children) + response.cnode(children[i].content).up(); + } else { + res.writeHead(200, {'Content-Type': 'text/xml'}); + var response = xmpp.stanza('ul', {xmlns: 'http://www.w3.org/1999/xhtml'}); + + children = storage.getChildren(); + if (typeof children == 'number') + return false; + + for (var i in children) + response.c('li').c('a', {href: i}).t(i).up().up(); + } + + res.end(response.toString()); + + return true; + }, +}
new file mode 100644 --- /dev/null +++ b/modules/mod_http.js @@ -0,0 +1,37 @@ +var config = require('../configuration'); +var http = require('http'); + +var files = require('fs').readdirSync('modules/http'); +var regex = /^mod_.*\.js/; + +var sites = {}; + +for (var i in files) { + var file = files[i]; + if (!regex.test(file)) + continue; + + var module = require('./http/' + files[i]); + for (var j in module) { + if (typeof sites[j] != 'undefined') + console.log('WARNING: module '+j+' already loaded.'); + + sites[j] = module[j]; + } +} + +http.createServer(function (req, res) { + var sent = false; + for (var i in sites) { + var site = sites[i]; + if (!site.url.test(req.url)) + continue; + + sent = site.func(req, res); + return; + } + if (!sent) { + res.writeHead(404, {'Content-Type': 'text/plain'}); + res.end('Error 404'); + } +}).listen(8484);
--- a/modules/mod_publish.js +++ b/modules/mod_publish.js @@ -1,10 +1,11 @@ var config = require('../configuration'); var storage = require('../storage'); +var notifs = require('../notifs'); var toBareJID = require('../util').toBareJID; var NS = require('../namespaces'); // SECTION 7.1: Publish an Item to a Node -exports.retrieveSub = { +exports.publish = { type: 'set', child: 'pubsub', ns: NS.PUBSUB, @@ -41,7 +42,7 @@ exports.retrieveSub = { return makeError(response, errors.pub.publish.bad_payload.n); var conf = storage.getConfiguration(nodeID); - var publishOptions = pubsub.getChild('publish-options'); + /*var publishOptions = pubsub.getChild('publish-options'); if (publishOptions && config.enabled('publish-options')) { var x = publishOptions.getChild('x', 'jabber:x:data'); if (!x || x.getAttribute('type') != 'submit') @@ -50,11 +51,11 @@ exports.retrieveSub = { var form = forms.parse(x, true); if (form.access_model != conf['pubsub#access_model'] && !autocreate) return makeError(response, errors.pub.configuration.precondition.n); - } + }*/ if (!config.enabled('persistent-items')) { - var notifs = storage.purgeNode(nodeID); - if (typeof notifs == 'number') + var notifications = storage.purgeNode(nodeID); + if (typeof notifications == 'number') return makeError(response, r); } @@ -90,7 +91,7 @@ exports.retrieveSub = { } // SECTION 7.2: Delete an Item from a Node -exports.retrieveSub = { +exports.retract = { type: 'set', child: 'pubsub', ns: NS.PUBSUB,