Mercurial > psgxs
diff psgxs.js @ 30:b2faacfefb90
Rewrite of the module manager; fix of some modules; fix of the directory backend.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Thu, 04 Nov 2010 17:50:52 +0100 |
parents | c774f2ffb271 |
children | 13011b26181c |
line wrap: on
line diff
--- a/psgxs.js +++ b/psgxs.js @@ -77,40 +77,64 @@ function onIq(stanza) { else response = xmpp.iq({to: to, from: from, type: 'result'}); - var sent = false; + var send = false; + + for (var i in stanza.tags) { + var child1 = stanza.tags[i]; + if (child1.name == 'pubsub') { + for (var j in child1.tags) { + var child2 = child1.tags[j]; + + for (var k in modules) { + var module = modules[k]; - for (var i in modules) { - var module = modules[i]; - if (module.type && (type != module.type)) - continue; + if (module.type && (module.type != type)) + continue; + + if (module.child2 && (module.child2 != child2.name)) + continue; - for (var j in stanza.tags) { - var child = stanza.tags[j]; - if (module.child && (child.name != module.child)) - continue; + if (module.ns && (module.ns != child2.attr.xmlns)) + continue; + + if (module.number && (module.number != j)) + continue; - if (module.ns && (child.attr.xmlns != module.ns)) - continue; + var toSend = module.func(response, stanza, child2, to); + if (toSend) { + response = toSend; + send = true; + delete toSend; + } + } + } + } else { + for (var k in modules) { + var module = modules[k]; - if (module.child == 'pubsub') { - var child2 = child.getChild(module.pschild, child.attr.xmlns); - if (child2) - child = child2; + if (module.type && (module.type != type)) + continue; - if (module.pschild && (!child || module.pschild != child.name)) + if (module.child && (module.child != child1.name)) continue; - } + + if (module.ns && (module.ns != child1.attr.xmlns)) + continue; - var toSend = module.func(response, stanza, child, to); - if (toSend) { - conn.send(toSend); - sent = true; + if (module.number && (module.number != k)) + continue; + + var toSend = module.func(response, stanza, child2, to); + if (toSend) { + response = toSend; + send = true; + delete toSend; + } } } } - if (!sent) - conn.send(makeError(response, errors.feature_not_implemented.n)); + conn.send(send? response: makeError(response, errors.feature_not_implemented.n)); } function onMessage(stanza) {