Mercurial > eldonilo > lightstring
comparison lightstring.js @ 62:b1e75cdbb0ad
Don’t allow more than one iq handler to respond, and respond with an service-unavailable when not handled.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Wed, 01 Feb 2012 18:37:57 +0100 |
parents | 0e86fca6a596 |
children | 20da4fb67977 |
comparison
equal
deleted
inserted
replaced
61:d1ba6f0e2a92 | 62:b1e75cdbb0ad |
---|---|
41 " xmlns:stream='" + Lightstring.ns['streams'] + "'" + | 41 " xmlns:stream='" + Lightstring.ns['streams'] + "'" + |
42 " version='1.0'/>"; | 42 " version='1.0'/>"; |
43 }, | 43 }, |
44 close: function() { | 44 close: function() { |
45 return "</stream:stream>"; | 45 return "</stream:stream>"; |
46 } | |
47 }, | |
48 errors: { | |
49 iq: function(type, error) { | |
50 return "<iq to='" + stanza.DOM.getAttributeNS(null, 'from') + "'" + | |
51 " id='" + stanza.DOM.getAttributeNS(null, 'id') + "'" + | |
52 " type='error'>" + | |
53 "<error type='" + type + "'>" + | |
54 "<" + error + " xmlns='" + Lightstring.namespaces['xmpp_stanzas'] + "'/>" + //TODO: allow text content. | |
55 //TODO: allow text and payload. | |
56 "</error>" + | |
57 "</iq>"; | |
46 } | 58 } |
47 } | 59 } |
48 }, | 60 }, |
49 plugins: {}, | 61 plugins: {}, |
50 /** | 62 /** |
427 emit: function(aName, aData) { | 439 emit: function(aName, aData) { |
428 var handlers = this.handlers[aName]; | 440 var handlers = this.handlers[aName]; |
429 if (!handlers) | 441 if (!handlers) |
430 return; | 442 return; |
431 | 443 |
432 for (var i = 0; i < handlers.length; i++) | 444 if (aData.localName !== 'iq') { |
433 handlers[i].call(this, aData); | 445 for (var i = 0; i < handlers.length; i++) |
446 handlers[i].call(this, aData); | |
447 | |
448 return; | |
449 } | |
450 | |
451 var ret; | |
452 for (var i = 0; i < handlers.length; i++) { | |
453 ret = handlers[i].call(this, aData); | |
454 if (typeof ret !== 'boolean') | |
455 return; //TODO: emit a big error! | |
456 | |
457 if (ret) | |
458 return; | |
459 } | |
460 | |
461 conn.send(Lightstring.stanzas.errors.iq('cancel', 'service-unavailable')); | |
434 }, | 462 }, |
435 /** | 463 /** |
436 * @function Register an event handler. | 464 * @function Register an event handler. |
437 * @param {String} aName The event name. | 465 * @param {String} aName The event name. |
438 * @param {Function} aCallback The callback to call when the event is emitted. | 466 * @param {Function} aCallback The callback to call when the event is emitted. |