Skip to content

Commit

Permalink
Merge pull request #139 from denisw/master
Browse files Browse the repository at this point in the history
Add support for Node.js v0.10
  • Loading branch information
Denis Washington committed Oct 7, 2013
2 parents d8b2462 + dba6440 commit 10abf70
Show file tree
Hide file tree
Showing 11 changed files with 53 additions and 251 deletions.
8 changes: 8 additions & 0 deletions config.js.example
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,11 @@ exports.production = {
// }*/
//]
};

// Test suite settings
exports.testing = {
port: 19123,
xmppDomain: 'localhost',
xmppHost: '127.0.0.1',
xmppPort: 15222,
};
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
"dependencies": {
"connect": "2.4.x",
"express": "3.x",
"libxmljs": "0.5.x",
"ltx": "0.2.x",
"node-expat": "1.6.x",
"node-stringprep": "0.1.x",
"node-xmpp": "0.3.2",
"libxmljs": "~0.8.1",
"ltx": "~0.3.0",
"node-expat": "~2.0.0",
"node-stringprep": "~0.1.8",
"node-xmpp": "~0.7.0",
"jwt-simple": "0.1.x",
"iso8601": "1.1.1",
"pubcontrol": "0.3.1",
Expand Down
3 changes: 1 addition & 2 deletions src/metadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ exports.setup = function(app) {
function getNodeMetadata(req, res) {
var channel = req.params.channel;
var node = req.params.node;

requestNodeMetadata(req, res, channel, node, function(reply) {
var body = replyToJSON(reply);
res.contentType('json');
Expand Down Expand Up @@ -86,7 +85,7 @@ function getOption(reply, name) {
function setNodeMetadata(req, res) {
var channel = req.params.channel;
var node = req.params.node;
var fields = JSON.parse(req.body);
var fields = JSON.parse(req.body.toString() || '{}');

configureNode(req, res, channel, node, fields, function() {
res.send(200);
Expand Down
31 changes: 6 additions & 25 deletions src/subscriptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,15 +158,15 @@ function extractSubscriptionCommand(body) {

function subscribe(req, res, channel, node, callback) {
var nodeId = pubsub.channelNodeId(channel, node);
var bareJid = req.user.split('/', 2)[0];
var iq = pubsub.subscribeIq(nodeId, bareJid);
var jid = req.user;
var iq = pubsub.subscribeIq(nodeId, jid);
api.sendQuery(req, res, iq, callback);
}

function unsubscribe(req, res, channel, node, callback) {
var nodeId = pubsub.channelNodeId(channel, node);
var bareJid = req.user.split('/', 2)[0];
var iq = pubsub.unsubscribeIq(nodeId, bareJid);
var jid = req.user;
var iq = pubsub.unsubscribeIq(nodeId, jid);
api.sendQuery(req, res, iq, callback);
}

Expand All @@ -177,27 +177,8 @@ function getNodeSubscriptions(req, res) {
var node = req.params.node;
requestNodeAffiliations(req, res, channel, node, function(reply) {
var body = replyToJSON(reply, 'node');
if (!body[req.session.jid]) {
var nodeId = pubsub.channelNodeId(channel, node);
console.log(req.session.jid + " is not subscribed to " + nodeId + ", creating temporary subscription");
req.session.subscribe(nodeId, function(sub) {
res.contentType('json');
res.send(body);
}, function(errstr) {
if (errstr == 'registration-required') {
if (req.user) {
res.send(403);
} else {
api.sendUnauthorized(res);
}
} else {
res.send(500);
}
});
} else {
res.contentType('json');
res.send(body);
}
res.contentType('json');
res.send(body);
});
}

Expand Down
2 changes: 1 addition & 1 deletion src/util/atom.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ exports.fromJSON = function(entry) {

var content = '';
if (entry.content) {
content = escapeText(entry.content);
content = entry.content;
}
entrydoc.root().
node('content', content).
Expand Down
11 changes: 9 additions & 2 deletions src/util/pubsub.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,10 @@ exports.userSubscriptionsIq = function() {
*/
exports.subscribeIq = function(nodeId, jid, isTemp) {
var query = iq({type: 'set'});
query.c('subscribe', {node: nodeId, jid: jid});
query.c('subscribe', {
node: nodeId,
jid: bareJid(jid)
});
if (isTemp) {
var form = query.c('options').
c('x', {xmlns: 'jabber:x:data', type: 'submit'});
Expand All @@ -202,10 +205,14 @@ exports.subscribeIq = function(nodeId, jid, isTemp) {
*/
exports.unsubscribeIq = function(nodeId, jid) {
return iq({type: 'set'}).
c('unsubscribe', {node: nodeId, jid: jid}).
c('unsubscribe', {node: nodeId, jid: bareJid(jid)}).
root();
};

function bareJid(jid) {
return (jid.indexOf('/') != -1) ? jid.split('/', 2)[0] : jid;
}

/**
* Creates a Pub-Sub <configure/> IQ which sets a node's configuration.
*/
Expand Down
6 changes: 3 additions & 3 deletions src/util/session.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ function createSession(req, res, next) {
// FIXME: Checking the error type bassed on the error message
// is fragile, but this is the only information that node-xmpp
// gives us.
console.log(err);
console.error(err);
sessionCache.remove(req.credentials);
for (var n = 0; n < session.waitingReqs.length; ++n) {
var wr = session.waitingReqs[n];
Expand Down Expand Up @@ -126,7 +126,7 @@ function xmppConnectionOptions(req) {
jid: '@' + domain,
host: host,
port: port,
preferredSaslMechanism: 'ANONYMOUS'
//preferredSaslMechanism: 'ANONYMOUS'
};
}
}
Expand Down Expand Up @@ -430,4 +430,4 @@ Session.prototype.subscribe = function(nodeId, onsub, onerror) {
}
}
});
}
}
1 change: 1 addition & 0 deletions test/metadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ describe('Node Metadata', function() {
res.statusCode.should.equal(200);

delete options.body;
delete options.method;
tutil.get(options, function(res, body) {
res.statusCode.should.equal(200);
var metadata = JSON.parse(body);
Expand Down
213 changes: 0 additions & 213 deletions test/session.js

This file was deleted.

Loading

0 comments on commit 10abf70

Please sign in to comment.