comparison modules/mod_retrieve.js @ 41:bc717575e66a

Much better handling of modules.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Sun, 20 Feb 2011 15:51:12 +0100
parents 4c808bfe0658
children 023f767662d3
comparison
equal deleted inserted replaced
40:741110cdcfcf 41:bc717575e66a
1 var config = require('../configuration');
2 var storage = require('../storage');
3 var errors = require('../errors');
4 var makeError = errors.makeError;
5 var toBareJID = require('../fdsq').toBareJID;
6 var NS = require('../namespaces');
7
8 console.log(require('sys').inspect(toBareJID, false, null));
9
10 // SECTION 5.6: Retrieve Subscriptions 1 // SECTION 5.6: Retrieve Subscriptions
11 exports.retrieveSubscriptions = { 2 exports.retrieveSubscriptions = {
12 type: 'get', 3 type: 'get',
13 child: 'pubsub', 4 child: 'pubsub',
14 ns: NS.PUBSUB, 5 ns: NS.PUBSUB,
23 return makeError(response, errors.node_does_not_exist.n); 14 return makeError(response, errors.node_does_not_exist.n);
24 var subs = storage.getSubscription(toBareJID(to), nodeID); 15 var subs = storage.getSubscription(toBareJID(to), nodeID);
25 } else 16 } else
26 var subs = storage.getSubscription(toBareJID(to)); 17 var subs = storage.getSubscription(toBareJID(to));
27 18
28 response.c('pubsub', {xmlns: NS.PUBSUB}); 19 response.c('pubsub', {xmlns: NS.PUBSUB})
29 response.c('subscriptions'); 20 .c('subscriptions');
30 21
31 for (i in subs) 22 for (i in subs)
32 response.c('subscription', {node: i, jid: to, subscription: subs[i].type, subid: subs[i].subid}).up(); 23 response.c('subscription', {node: i, jid: to, subscription: subs[i].type, subid: subs[i].subid}).up();
33 24
34 return response; 25 return response;
52 var affils = {}; 43 var affils = {};
53 affils[nodeID] = storage.getAffiliation(toBareJID(to), nodeID); 44 affils[nodeID] = storage.getAffiliation(toBareJID(to), nodeID);
54 } else 45 } else
55 var affils = storage.getAffiliationsFromJID(toBareJID(to)); 46 var affils = storage.getAffiliationsFromJID(toBareJID(to));
56 47
57 response.c('pubsub', {xmlns: NS.PUBSUB}); 48 response.c('pubsub', {xmlns: NS.PUBSUB})
58 response.c('affiliations'); 49 .c('affiliations');
59 50
60 for (i in affils) 51 for (i in affils)
61 response.c('affiliation', {node: i, affiliation: affils[i]}).up(); 52 response.c('affiliation', {node: i, affiliation: affils[i]}).up();
62 53
63 return response; 54 return response;
109 return makeError(response, j); 100 return makeError(response, j);
110 if (j == errors.success) 101 if (j == errors.success)
111 continue; 102 continue;
112 103
113 response.c('item', {id: item[i]}) 104 response.c('item', {id: item[i]})
114 response.cnode(j).up().up(); 105 .cnode(j).up().up();
115 } 106 }
116 } else { 107 } else {
117 response.c('items', {node: nodeID}); 108 response.c('items', {node: nodeID});
118 109
119 var j; 110 var j;