Mercurial > psgxs
comparison psgxs.js @ 9:a6429f48e403
First implementation of XEP-0050 (ad-hoc commands).
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Fri, 27 Aug 2010 00:39:03 +0200 |
parents | efe8dbd34780 |
children | 44889cfb2f8c |
comparison
equal
deleted
inserted
replaced
8:efe8dbd34780 | 9:a6429f48e403 |
---|---|
68 else | 68 else |
69 response = xmpp.iq({to: to, from: from, type: 'result'}); | 69 response = xmpp.iq({to: to, from: from, type: 'result'}); |
70 | 70 |
71 if (type == 'get') { | 71 if (type == 'get') { |
72 | 72 |
73 // XEP-0092 | 73 // XEP-0092: Software Version |
74 if (stanza.getChild('query', 'jabber:iq:version')) { | 74 if (stanza.getChild('query', 'jabber:iq:version')) { |
75 var query = xmpp.stanza('query', {xmlns: 'jabber:iq:version'}) | 75 var query = xmpp.stanza('query', {xmlns: 'jabber:iq:version'}) |
76 .s('name').t('PSĜS') | 76 .s('name').t('PSĜS') |
77 .s('version').t(config.version) | 77 .s('version').t(config.version) |
78 .s('os').t(config.os); | 78 .s('os').t(config.os); |
114 .s('identity', {category: 'pubsub', type: 'service', name: 'PubSub JavaScript Server'}) | 114 .s('identity', {category: 'pubsub', type: 'service', name: 'PubSub JavaScript Server'}) |
115 .s('feature', {'var': 'http://jabber.org/protocol/disco#info'}) | 115 .s('feature', {'var': 'http://jabber.org/protocol/disco#info'}) |
116 .s('feature', {'var': 'http://jabber.org/protocol/disco#items'}) | 116 .s('feature', {'var': 'http://jabber.org/protocol/disco#items'}) |
117 .s('feature', {'var': 'http://jabber.org/protocol/pubsub'}) | 117 .s('feature', {'var': 'http://jabber.org/protocol/pubsub'}) |
118 .s('feature', {'var': 'jabber:iq:version'}) | 118 .s('feature', {'var': 'jabber:iq:version'}) |
119 // .s('feature', {'var': 'http://jabber.org/protocol/commands'}) | 119 .s('feature', {'var': 'http://jabber.org/protocol/commands'}); |
120 for (var i in config.activated) | 120 |
121 if (typeof i == 'string') | 121 for (var i in config.activated) |
122 q.s('feature', {'var': 'http://jabber.org/protocol/pubsub#' + config.activated[i]}); | 122 if (typeof i == 'string') |
123 q.s('feature', {'var': 'http://jabber.org/protocol/pubsub#' + config.activated[i]}); | |
124 | |
123 response.cnode(q); | 125 response.cnode(q); |
124 } | 126 } |
125 | 127 |
126 // SECTION 5.2 | 128 // SECTION 5.2 |
127 } else if (stanza.getChild('query', 'http://jabber.org/protocol/disco#items')) { | 129 } else if (stanza.getChild('query', 'http://jabber.org/protocol/disco#items')) { |
128 var query = stanza.getChild('query', 'http://jabber.org/protocol/disco#items'); | 130 var query = stanza.getChild('query', 'http://jabber.org/protocol/disco#items'); |
129 var q; | 131 var q; |
130 var children; | 132 var children; |
131 var nodeID = query.getAttribute('node'); | 133 var nodeID = query.getAttribute('node'); |
132 if (nodeID && nodeID != '') { | 134 if (nodeID && nodeID != '') { |
133 if (!storage.existsNode(nodeID)) | 135 if (nodeID == 'http://jabber.org/protocol/commands') { |
134 return makeError(response, errors.node_does_not_exist.n); | 136 // XEP-0050: Ad-Hoc Commands |
135 | 137 |
136 q = xmpp.stanza('query', {xmlns: 'http://jabber.org/protocol/disco#items', node: nodeID}); | 138 q = xmpp.stanza('query', {xmlns: 'http://jabber.org/protocol/disco#items', node: nodeID}) |
137 | 139 .s('item', {jid: componentJID, node: 'ping', name: 'Ping'}) |
138 children = storage.getChildren(nodeID); | 140 .s('item', {jid: componentJID, node: 'reload', name: 'Reload'}); |
139 if (typeof children == 'number') | 141 |
140 return makeError(response, children); | 142 response.cnode(q); |
143 return conn.send(response); | |
144 } else { | |
145 if (!storage.existsNode(nodeID)) | |
146 return makeError(response, errors.node_does_not_exist.n); | |
147 | |
148 q = xmpp.stanza('query', {xmlns: 'http://jabber.org/protocol/disco#items', node: nodeID}); | |
149 | |
150 children = storage.getChildren(nodeID); | |
151 if (typeof children == 'number') | |
152 return makeError(response, children); | |
153 } | |
141 } else { | 154 } else { |
142 q = xmpp.stanza('query', {xmlns: 'http://jabber.org/protocol/disco#items'}); | 155 q = xmpp.stanza('query', {xmlns: 'http://jabber.org/protocol/disco#items'}); |
143 | 156 |
144 children = storage.getChildren(); | 157 children = storage.getChildren(); |
145 if (typeof children == 'number') | 158 if (typeof children == 'number') |
425 } else | 438 } else |
426 return makeError(response, errors.feature_not_implemented.n); | 439 return makeError(response, errors.feature_not_implemented.n); |
427 } else | 440 } else |
428 return makeError(response, errors.feature_not_implemented.n); | 441 return makeError(response, errors.feature_not_implemented.n); |
429 } else if (type == 'set') { | 442 } else if (type == 'set') { |
430 if (stanza.getChild('pubsub', 'http://jabber.org/protocol/pubsub')) { | 443 if (stanza.getChild('command', 'http://jabber.org/protocol/commands')) { |
444 // XEP-0050: Ad-Hoc Commands | |
445 var command = stanza.getChild('command', 'http://jabber.org/protocol/commands'); | |
446 | |
447 var action = command.getAttribute('action'); | |
448 if (action != 'execute') | |
449 return makeError(response, errors.bad_request.n); | |
450 | |
451 var node = command.getAttribute('node'); | |
452 if (node == 'ping') { | |
453 var cmd = xmpp.stanza('command', {xmlns: 'http://jabber.org/protocol/commands', | |
454 // sessionid: 'list:20020923T213616Z-700', | |
455 node: node, | |
456 'status': 'completed'}) | |
457 .c('note', {type: 'info'}).t('pong'); | |
458 response.cnode(cmd); | |
459 } else if (node == 'reload') { | |
460 storage.load(); | |
461 response.c('command', {xmlns: 'http://jabber.org/protocol/commands', | |
462 node: node, | |
463 'status': 'completed'}) | |
464 .c('note', {type: 'info'}).t('The server has correctly reloaded.'); | |
465 } else | |
466 return makeError(response, errors.bad_request.n); | |
467 } else if (stanza.getChild('pubsub', 'http://jabber.org/protocol/pubsub')) { | |
431 var pubsub = stanza.getChild('pubsub', 'http://jabber.org/protocol/pubsub'); | 468 var pubsub = stanza.getChild('pubsub', 'http://jabber.org/protocol/pubsub'); |
432 | 469 |
433 // SECTION 6.1 | 470 // SECTION 6.1 |
434 if (pubsub.getChild('subscribe')) { | 471 if (pubsub.getChild('subscribe')) { |
435 if (!config.enabled('subscribe')) | 472 if (!config.enabled('subscribe')) |