annotate modules/mod_options.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 6697f394301f
children 023f767662d3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
24
b80ab94da447 Add new modules files.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1 // SECTION 6.3.2: Configure Subscription Options (Request)
30
b2faacfefb90 Rewrite of the module manager; fix of some modules; fix of the directory backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 24
diff changeset
2 exports.getConfigureSub = {
24
b80ab94da447 Add new modules files.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
3 type: 'get',
b80ab94da447 Add new modules files.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
4 child: 'pubsub',
b80ab94da447 Add new modules files.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
5 ns: NS.PUBSUB,
30
b2faacfefb90 Rewrite of the module manager; fix of some modules; fix of the directory backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 24
diff changeset
6 child2: 'options',
24
b80ab94da447 Add new modules files.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
7 func: function(response, stanza, request, to) {
b80ab94da447 Add new modules files.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
8 if (!config.enabled('subscription-options'))
b80ab94da447 Add new modules files.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
9 return makeError(response, errors.sub.configure.subscription_options_not_supported.n);
b80ab94da447 Add new modules files.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
10
b80ab94da447 Add new modules files.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
11 var nodeID = request.getAttribute('node');
b80ab94da447 Add new modules files.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
12 if (!nodeID || nodeID == '')
b80ab94da447 Add new modules files.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
13 return makeError(response, errors.nodeid_required.n);
b80ab94da447 Add new modules files.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
14 if (!storage.existsNode(nodeID))
b80ab94da447 Add new modules files.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
15 return makeError(response, errors.node_does_not_exist.n);
b80ab94da447 Add new modules files.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
16
b80ab94da447 Add new modules files.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
17 var jid = request.getAttribute('jid');
b80ab94da447 Add new modules files.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
18 if (!jid)
b80ab94da447 Add new modules files.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
19 return makeError(response, errors.sub.configure.subscriber_jid_required.n);
b80ab94da447 Add new modules files.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
20 if (toBareJID(jid) != toBareJID(to))
b80ab94da447 Add new modules files.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
21 return makeError(response, errors.sub.configure.insufficient_privileges.n);
b80ab94da447 Add new modules files.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
22
b80ab94da447 Add new modules files.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
23 var subs = storage.getSubscription(jid, nodeID);
b80ab94da447 Add new modules files.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
24 if (!subs.subid) // FIXME: better test for empty object.
b80ab94da447 Add new modules files.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
25 return makeError(response, errors.sub.configure.no_such_subscriber.n);
b80ab94da447 Add new modules files.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
26
41
bc717575e66a Much better handling of modules.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 35
diff changeset
27 response.c('pubsub', {xmlns: NS.PUBSUB})
bc717575e66a Much better handling of modules.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 35
diff changeset
28 .c('options', {node: nodeID, jid: jid});
24
b80ab94da447 Add new modules files.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
29
b80ab94da447 Add new modules files.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
30 var form = forms.build('form', 'subscribe_options', subs.options, true);
b80ab94da447 Add new modules files.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
31 response.cnode(form);
b80ab94da447 Add new modules files.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
32
b80ab94da447 Add new modules files.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
33 return response;
b80ab94da447 Add new modules files.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
34 }
b80ab94da447 Add new modules files.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
35 }
b80ab94da447 Add new modules files.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
36
b80ab94da447 Add new modules files.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
37 // SECTIONS 6.3.5: Form Submission
b80ab94da447 Add new modules files.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
38 exports.configureSub = {
b80ab94da447 Add new modules files.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
39 type: 'set',
b80ab94da447 Add new modules files.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
40 child: 'pubsub',
b80ab94da447 Add new modules files.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
41 ns: NS.PUBSUB,
30
b2faacfefb90 Rewrite of the module manager; fix of some modules; fix of the directory backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 24
diff changeset
42 child2: 'options',
24
b80ab94da447 Add new modules files.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
43 func: function(response, stanza, request, to) {
b80ab94da447 Add new modules files.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
44 if (!config.enabled('subscription-options'))
b80ab94da447 Add new modules files.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
45 return makeError(response, errors.sub.subscribe.not_supported.n);
b80ab94da447 Add new modules files.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
46
b80ab94da447 Add new modules files.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
47 var nodeID = unsubscribe.getAttribute('node');
b80ab94da447 Add new modules files.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
48 if (!nodeID || nodeID == '')
b80ab94da447 Add new modules files.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
49 return makeError(response, errors.nodeid_required.n);
b80ab94da447 Add new modules files.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
50 if (!storage.existsNode(nodeID))
b80ab94da447 Add new modules files.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
51 return makeError(response, errors.node_does_not_exist.n);
b80ab94da447 Add new modules files.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
52
b80ab94da447 Add new modules files.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
53 var jid = unsubscribe.getAttribute('jid');
b80ab94da447 Add new modules files.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
54 if (!jid || toBareJID(jid) != toBareJID(to))
b80ab94da447 Add new modules files.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
55 return makeError(response, errors.sub.unsubscribe.insufficient_privileges.n);
b80ab94da447 Add new modules files.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
56
b80ab94da447 Add new modules files.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
57 var x = request.getChild('x', 'jabber:x:data');
b80ab94da447 Add new modules files.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
58 if (!x || x.getAttribute(type) != 'submit')
b80ab94da447 Add new modules files.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
59 return makeError(response, errors.bad_request);
b80ab94da447 Add new modules files.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
60
b80ab94da447 Add new modules files.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
61 var form = forms.parse(x, true);
b80ab94da447 Add new modules files.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
62 if (typeof form == 'number')
b80ab94da447 Add new modules files.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
63 return makeError(response, form);
b80ab94da447 Add new modules files.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
64
b80ab94da447 Add new modules files.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
65 var set = storage.configureSubscription(nodeID, jid, form);
b80ab94da447 Add new modules files.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
66 if (typeof form == 'number')
b80ab94da447 Add new modules files.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
67 return makeError(response, form);
b80ab94da447 Add new modules files.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
68
b80ab94da447 Add new modules files.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
69 return response;
b80ab94da447 Add new modules files.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
70 }
b80ab94da447 Add new modules files.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
71 }
b80ab94da447 Add new modules files.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
72
b80ab94da447 Add new modules files.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
73 // SECTION 6.4: Request Default Subscription Configuration Options
b80ab94da447 Add new modules files.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
74 exports.defaultSub = {
b80ab94da447 Add new modules files.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
75 type: 'get',
b80ab94da447 Add new modules files.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
76 child: 'pubsub',
b80ab94da447 Add new modules files.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
77 ns: NS.PUBSUB,
30
b2faacfefb90 Rewrite of the module manager; fix of some modules; fix of the directory backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 24
diff changeset
78 child2: 'default',
24
b80ab94da447 Add new modules files.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
79 func: function(response, stanza, request) {
b80ab94da447 Add new modules files.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
80 if (!config.enabled('retrieve-default-sub'))
b80ab94da447 Add new modules files.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
81 return makeError(response, errors.sub.default_options.default_subscription_configuration_retrieval_not_supported.n);
b80ab94da447 Add new modules files.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
82
b80ab94da447 Add new modules files.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
83 var nodeID = request.getAttribute('node');
b80ab94da447 Add new modules files.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
84 if (nodeID && !storage.existsNode(nodeID))
b80ab94da447 Add new modules files.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
85 return makeError(response, errors.node_does_not_exist.n);
b80ab94da447 Add new modules files.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
86
b80ab94da447 Add new modules files.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
87 response.c('pubsub', {xmlns: NS.PUBSUB});
b80ab94da447 Add new modules files.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
88 var s;
b80ab94da447 Add new modules files.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
89 if (nodeID)
b80ab94da447 Add new modules files.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
90 response.c('default', {node: nodeID});
b80ab94da447 Add new modules files.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
91 else
b80ab94da447 Add new modules files.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
92 response.c('default');
b80ab94da447 Add new modules files.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
93
b80ab94da447 Add new modules files.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
94 var form = forms.build('form', 'subscribe_options', 'default', false);
b80ab94da447 Add new modules files.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
95 response.cnode(form);
b80ab94da447 Add new modules files.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
96
b80ab94da447 Add new modules files.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
97 return response;
b80ab94da447 Add new modules files.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
98 }
b80ab94da447 Add new modules files.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
99 }