Mercurial > psgxs
comparison modules/mod_manage.js @ 24:b80ab94da447
Add new modules files.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Mon, 01 Nov 2010 00:02:27 +0100 |
parents | |
children | b2faacfefb90 |
comparison
equal
deleted
inserted
replaced
23:5fc4ee90c1bc | 24:b80ab94da447 |
---|---|
1 var config = require('../configuration'); | |
2 var storage = require('../storage'); | |
3 var errors = require('../errors'); | |
4 var makeError = errors.makeError; | |
5 var toBareJID = require('../util').toBareJID; | |
6 var NS = require('../namespaces'); | |
7 | |
8 // SECTION 8.8.1: Retrieve Subscriptions List | |
9 exports.manageRetrieveSub = { | |
10 type: 'get', | |
11 child: 'pubsub', | |
12 ns: NS.PUBSUB_OWNER, | |
13 pschild: 'subscriptions', | |
14 func: function(response, stanza, request, to) { | |
15 if (!config.enabled('manage-subscriptions')) | |
16 return makeError(response, errors.owner.manage_subscriptions.not_supported.n); | |
17 | |
18 var nodeID = request.getAttribute('node'); | |
19 if (!nodeID || nodeID == '') | |
20 return makeError(response, errors.nodeid_required.n); | |
21 if (!storage.existsNode(nodeID)) | |
22 return makeError(response, errors.node_does_not_exist.n); | |
23 | |
24 var affil = storage.getAffiliation(toBareJID(to), nodeID); | |
25 if (affil != 'super-owner' && affil != 'owner') | |
26 return makeError(response, errors.forbidden.n); | |
27 | |
28 response.c('pubsub', {xmlns: NS.PUBSUB_OWNER}); | |
29 response.c('subscriptions', {node: nodeID}); | |
30 | |
31 var subs = storage.getSubscriptionsFromNodeID(nodeID) | |
32 for (var jid in subs) | |
33 response.c('subscription', {jid: jid, subscription: subs[jid].type, subid: subs[jid].subid}).up(); | |
34 | |
35 return response; | |
36 } | |
37 } | |
38 | |
39 // SECTION 8.9.1: Retrieve Affiliations List | |
40 exports.manageRetrieveAff = { | |
41 type: 'get', | |
42 child: 'pubsub', | |
43 ns: NS.PUBSUB_OWNER, | |
44 pschild: 'affiliations', | |
45 func: function(response, stanza, request, to) { | |
46 if (!config.enabled('modify-affiliations')) | |
47 return makeError(response, errors.owner.manage_affiliations.not_supported.n); | |
48 | |
49 var nodeID = request.getAttribute('node'); | |
50 if (!nodeID || nodeID == '') | |
51 return makeError(response, errors.nodeid_required.n); | |
52 if (!storage.existsNode(nodeID)) | |
53 return makeError(response, errors.node_does_not_exist.n); | |
54 | |
55 var affils = storage.getAffiliationsFromNodeID(nodeID); | |
56 var affil = affils[toBareJID(to)]; | |
57 if (affil != 'super-owner' && affil != 'owner') | |
58 return makeError(response, errors.owner.manage_affiliations.retrieve_list.entity_is_not_an_owner.n); | |
59 | |
60 response.c('pubsub', {xmlns: NS.PUBSUB_OWNER}); | |
61 response.c('affiliations', {node: nodeID}); | |
62 | |
63 for (var jid in affils) | |
64 response.c('affiliation', {jid: jid, affiliation: affils[jid]}).up(); | |
65 | |
66 return response; | |
67 } | |
68 } | |
69 | |
70 // SECTION 8.8.2: Modify Subscriptions | |
71 exports.modifySub = { | |
72 type: 'set', | |
73 child: 'pubsub', | |
74 ns: NS.PUBSUB_OWNER, | |
75 pschild: 'subscriptions', | |
76 func: function(response, stanza, request, to) { | |
77 if (!config.enabled('manage-subscriptions')) | |
78 return makeError(response, errors.owner.manage_subscriptions.not_supported.n); //XXX | |
79 | |
80 var nodeID = request.getAttribute('node'); | |
81 if (!nodeID) | |
82 return makeError(response, errors.nodeid_required.n); | |
83 if (!storage.existsNode(nodeID)) | |
84 return makeError(response, errors.node_does_not_exist.n); | |
85 | |
86 var affil = storage.getAffiliation(toBareJID(to), nodeID); | |
87 if (affil != 'super-owner' && affil != 'owner') | |
88 return makeError(response, errors.forbidden.n); | |
89 | |
90 var e = false; | |
91 var tags2 = []; | |
92 for (i in request.tags) { | |
93 var tag = request.tags[i]; | |
94 var jid = tag.getAttribute('jid'); | |
95 var sub = tag.getAttribute('subscription'); | |
96 | |
97 if (sub == 'none' || sub == 'pending' || sub == 'subscribed' || sub == 'unconfigured') { | |
98 var set = storage.subscribe(nodeID, jid, sub); | |
99 | |
100 if (typeof set == 'number') { | |
101 e = true; | |
102 tags2.push(tag); | |
103 } else { | |
104 // SECTION 8.8.4 | |
105 notifs.send(jid, 'subscription', nodeID, {jid: jid, subscription: sub}); | |
106 } | |
107 } else { | |
108 e = true; | |
109 tags2.push(tag); | |
110 } | |
111 } | |
112 | |
113 request.tags = tags2; | |
114 | |
115 if (e) | |
116 return makeError(response, errors.owner.manage_subscriptions.modify.multiple_simultaneous_modifications.n, pubsub); | |
117 | |
118 return response; | |
119 } | |
120 } | |
121 | |
122 // SECTION 8.9.2: Modify Affiliation | |
123 exports.modifyAff = { | |
124 type: 'set', | |
125 child: 'pubsub', | |
126 ns: NS.PUBSUB_OWNER, | |
127 pschild: 'affiliations', | |
128 func: function(response, stanza, request, to) { | |
129 if (!config.enabled('modify-affiliations')) | |
130 return makeError(response, errors.owner.manage_affiliations.not_supported.n); //XXX | |
131 | |
132 var nodeID = request.getAttribute('node'); | |
133 if (!nodeID) | |
134 return makeError(response, errors.nodeid_required.n); | |
135 if (!storage.existsNode(nodeID)) | |
136 return makeError(response, errors.node_does_not_exist.n); | |
137 | |
138 var affil = storage.getAffiliation(toBareJID(to), nodeID); | |
139 if (affil != 'super-owner' && affil != 'owner') | |
140 return makeError(response, errors.forbidden.n); | |
141 | |
142 var e = false; | |
143 for (i in request.children) { | |
144 var jid = request.children[i].getAttribute('jid'); | |
145 var affiliation = request.children[i].getAttribute('affiliation'); | |
146 | |
147 var set = storage.setAffiliation(nodeID, jid, affiliation); | |
148 if (typeof set == 'number') | |
149 e = true; | |
150 else { | |
151 // SECTION 8.9.4 | |
152 notifs.send(jid, 'affiliations', nodeID, {jid: jid, affiliation: affiliation}); | |
153 request.children.splice(i, 1); | |
154 } | |
155 } | |
156 | |
157 if (e) | |
158 return makeError(response, errors.owner.manage_affiliations.modify.multiple_simultaneous_modifications.n, pubsub); | |
159 | |
160 return response; | |
161 } | |
162 } |