Mercurial > psgxs
comparison psgxs.js @ 6:2bcadb0531f4
A few changes.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Mon, 23 Aug 2010 14:41:55 +0200 |
parents | 4c93e76fa371 |
children | 781ac4f1e304 |
comparison
equal
deleted
inserted
replaced
5:d8a98540d749 | 6:2bcadb0531f4 |
---|---|
84 | 84 |
85 var type = 'leaf' | 85 var type = 'leaf' |
86 if (conf['pubsub#node_type']) | 86 if (conf['pubsub#node_type']) |
87 type = conf['pubsub#node_type']; | 87 type = conf['pubsub#node_type']; |
88 | 88 |
89 var q = xmpp.stanza('query', {xmlns: 'http://jabber.org/protocol/disco#info'}) | 89 var q = xmpp.stanza('query', {xmlns: 'http://jabber.org/protocol/disco#info', node: nodeID}) |
90 q.s('identity', {category: 'pubsub', type: type}); | 90 q.s('identity', {category: 'pubsub', type: type}); |
91 q.s('feature', {'var': 'http://jabber.org/protocol/pubsub'}); | 91 q.s('feature', {'var': 'http://jabber.org/protocol/pubsub'}); |
92 | 92 |
93 // SECTION 5.4 | 93 // SECTION 5.4 |
94 if (config.enabled('meta-data')) { | 94 if (config.enabled('meta-data')) { |
189 var nodeID = affiliations.getAttribute('node'); | 189 var nodeID = affiliations.getAttribute('node'); |
190 var affils; | 190 var affils; |
191 if (nodeID && nodeID != '') { | 191 if (nodeID && nodeID != '') { |
192 if (!storage.existsNode(nodeID)) | 192 if (!storage.existsNode(nodeID)) |
193 return makeError(response, errors.node_does_not_exist.n); | 193 return makeError(response, errors.node_does_not_exist.n); |
194 affils = storage.getAffiliation(toBareJID(to), nodeID); | 194 affils = {}; |
195 affils[nodeID] = storage.getAffiliation(toBareJID(to), nodeID); | |
195 } else | 196 } else |
196 affils = storage.getAffiliationsFromJID(toBareJID(to)); | 197 affils = storage.getAffiliationsFromJID(toBareJID(to)); |
198 | |
197 var s = xmpp.stanza('affiliations'); | 199 var s = xmpp.stanza('affiliations'); |
198 for (i in affils) | 200 for (i in affils) |
199 s.s('affiliation', {node: i, affiliation: affils[i]}); | 201 s.s('affiliation', {node: i, affiliation: affils[i]}); |
202 | |
200 var p = xmpp.stanza('pubsub', {xmlns: 'http://jabber.org/protocol/pubsub'}); | 203 var p = xmpp.stanza('pubsub', {xmlns: 'http://jabber.org/protocol/pubsub'}); |
201 p.cx(s); | 204 p.cx(s); |
202 response.cx(p); | 205 response.cx(p); |
203 | 206 |
204 // SECTION 6.3.2 | 207 // SECTION 6.3.2 |
265 if (!nodeID || nodeID == '') | 268 if (!nodeID || nodeID == '') |
266 return makeError(response, errors.nodeid_required.n); | 269 return makeError(response, errors.nodeid_required.n); |
267 if (!storage.existsNode(nodeID)) | 270 if (!storage.existsNode(nodeID)) |
268 return makeError(response, errors.node_does_not_exist.n); | 271 return makeError(response, errors.node_does_not_exist.n); |
269 | 272 |
270 var affil = storage.getAffiliation(toBareJID(to), nodeID); | 273 var configuration = storage.getConfiguration(nodeID); |
271 if (affil != 'super-owner' && affil != 'owner' && affil != 'publisher' && affil != 'member') | 274 if (configuration['pubsub#access_model'] == 'whitelist') { |
272 return makeError(response, errors.pub.publish.insufficient_privileges.n); | 275 var affil = storage.getAffiliation(toBareJID(to), nodeID); |
276 if (affil != 'super-owner' && affil != 'owner' && affil != 'publisher' && affil != 'member') | |
277 return makeError(response, errors.pub.publish.insufficient_privileges.n); | |
278 } | |
273 | 279 |
274 var item = []; | 280 var item = []; |
275 for (var i=0; i<items.children.length; i++) { | 281 for (var i=0; i<items.children.length; i++) { |
276 var j = items.children[i]; | 282 var j = items.children[i]; |
277 if (j.name == 'item' && j.attr['id'] && j.attr['id'] != '') | 283 if (j.name == 'item' && j.attr['id'] && j.attr['id'] != '') |
561 var publish = pubsub.getChild('publish'); | 567 var publish = pubsub.getChild('publish'); |
562 var nodeID = publish.getAttribute('node'); | 568 var nodeID = publish.getAttribute('node'); |
563 if (!nodeID || nodeID == '') | 569 if (!nodeID || nodeID == '') |
564 return makeError(response, errors.nodeid_required.n); | 570 return makeError(response, errors.nodeid_required.n); |
565 | 571 |
566 var affil = storage.getAffiliation(toBareJID(to), nodeID); | |
567 if (typeof affil == 'number') | |
568 return makeError(response, affil); | |
569 if (affil != 'super-owner' && affil != 'owner' && affil != 'publisher' && affil != 'publish-only') | |
570 return makeError(response, errors.forbidden.n); | |
571 | |
572 var item = publish.getChild('item'); | |
573 var itemID = item.getAttribute('id'); | |
574 if (!config.enabled('item-ids') && itemID) | |
575 return makeError(response, errors.itemid_required.n); | |
576 itemID = itemID? itemID: utils.makeRandomId(); | |
577 | |
578 if (item.tags.length != 1) | |
579 return makeError(response, errors.pub.publish.bad_payload.n); | |
580 | |
581 var autocreate = false; | 572 var autocreate = false; |
582 if (!storage.existsNode(nodeID)) { | 573 if (!storage.existsNode(nodeID)) { |
583 if (config.enabled('auto-create')) | 574 if (config.enabled('auto-create')) |
584 autocreate = true; | 575 autocreate = true; |
585 else | 576 else |
586 return makeError(response, errors.node_does_not_exist.n); | 577 return makeError(response, errors.node_does_not_exist.n); |
587 } | 578 } |
588 | 579 |
580 var affil = storage.getAffiliation(toBareJID(to), nodeID); | |
581 if (typeof affil == 'number' && affil != errors.node_does_not_exist.n) | |
582 return makeError(response, affil); | |
583 if (!autocreate && affil != 'super-owner' && affil != 'owner' && affil != 'publisher' && affil != 'publish-only') | |
584 return makeError(response, errors.forbidden.n); | |
585 | |
586 var item = publish.getChild('item'); | |
587 var itemID = item.getAttribute('id'); | |
588 if (!config.enabled('item-ids') && itemID) | |
589 return makeError(response, errors.itemid_required.n); | |
590 itemID = itemID? itemID: utils.makeRandomId(); | |
591 | |
592 if (item.tags.length != 1) | |
593 return makeError(response, errors.pub.publish.bad_payload.n); | |
594 | |
589 var conf = storage.getConfiguration(nodeID); | 595 var conf = storage.getConfiguration(nodeID); |
590 var publishOptions = pubsub.getChild('publish-options'); | 596 var publishOptions = pubsub.getChild('publish-options'); |
591 if (publishOptions && config.enabled('publish-options')) { | 597 if (publishOptions && config.enabled('publish-options')) { |
592 var x = publishOptions.getChild('x', 'jabber:x:data'); | 598 var x = publishOptions.getChild('x', 'jabber:x:data'); |
593 if (!x || x.getAttribute('type') != 'submit') | 599 if (!x || x.getAttribute('type') != 'submit') |
649 return makeError(response, errors.pub.retract.item_or_itemid_required.n); | 655 return makeError(response, errors.pub.retract.item_or_itemid_required.n); |
650 | 656 |
651 var itemID = item.getAttribute('id') | 657 var itemID = item.getAttribute('id') |
652 if (!itemID || itemID == '') | 658 if (!itemID || itemID == '') |
653 return makeError(response, errors.pub.retract.item_or_itemid_required.n); | 659 return makeError(response, errors.pub.retract.item_or_itemid_required.n); |
660 | |
661 var affil = storage.getAffiliation(toBareJID(to), nodeID); | |
662 if (affil != 'super-owner' && affil != 'owner' && affil != 'publish-only') | |
663 return makeError(response, errors.forbidden.n); | |
654 | 664 |
655 var subscribers = storage.deleteItem(nodeID, itemID); | 665 var subscribers = storage.deleteItem(nodeID, itemID); |
656 if (typeof subscribers == 'number') | 666 if (typeof subscribers == 'number') |
657 return makeError(response, subscribers); | 667 return makeError(response, subscribers); |
658 | 668 |