From cfc9bf6a35007ef2a62e2a668b8c659fd2b24992 Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Fri, 15 May 2009 06:23:55 +0500 Subject: util.events: event handlers can now return a result, which also interrupts further handling of the event --- util/events.lua | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/util/events.lua b/util/events.lua index b1f3811c..704d31a4 100644 --- a/util/events.lua +++ b/util/events.lua @@ -53,7 +53,8 @@ function new() if not h then h = {}; handlers[event] = h; end local dispatcher = function(data) for _, handler in ipairs(h) do - handler(data); + local ret = handler(data); + if ret ~= nil then return ret; end end end; dispatchers[event] = dispatcher; @@ -66,7 +67,8 @@ function new() local h = handlers[event]; if h then for _, handler in ipairs(h) do - handler(data); + local ret = handler(data); + if ret ~= nil then return ret; end end end end; -- cgit v1.2.3 From 5876adcc5e0d8700730ac6115fd30868836d6320 Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Fri, 15 May 2009 06:28:02 +0500 Subject: mod_presence: return true from the presence handler --- plugins/mod_presence.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/mod_presence.lua b/plugins/mod_presence.lua index 2fb976b5..415e5313 100644 --- a/plugins/mod_presence.lua +++ b/plugins/mod_presence.lua @@ -268,6 +268,7 @@ local function presence_handler(data) core_route_stanza(origin, stanza); end end + return true; end local add_handler = require "core.eventmanager2".add_handler; -- cgit v1.2.3 From d996755860a82374cccae4972a1b40cb295792ad Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Fri, 15 May 2009 06:31:32 +0500 Subject: stanza_router: Prevent further processing of a handled stanza --- core/stanza_router.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/stanza_router.lua b/core/stanza_router.lua index eb5bf410..cb76b29c 100644 --- a/core/stanza_router.lua +++ b/core/stanza_router.lua @@ -109,7 +109,7 @@ function core_process_stanza(origin, stanza) -- FIXME do stanzas not of jabber:client get handled by components? if (origin.type == "s2sin" or origin.type == "c2s" or origin.type == "component") and (not xmlns or xmlns == "jabber:server" or xmlns == "jabber:client") then local event_data = {origin=origin, stanza=stanza}; - fire_event(tostring(host or origin.host).."/"..stanza.name, event_data); + if fire_event(tostring(host or origin.host).."/"..stanza.name, event_data) then return; end if origin.type == "s2sin" and not origin.dummy then local host_status = origin.hosts[from_host]; if not host_status or not host_status.authed then -- remote server trying to impersonate some other server? -- cgit v1.2.3 From 669916fb93d1cbd6570e515290a7d3c934bd17b1 Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Fri, 15 May 2009 06:34:08 +0500 Subject: stanza_router: Remove unnecessary directed presence handling --- core/stanza_router.lua | 5 ----- 1 file changed, 5 deletions(-) diff --git a/core/stanza_router.lua b/core/stanza_router.lua index cb76b29c..43ba4547 100644 --- a/core/stanza_router.lua +++ b/core/stanza_router.lua @@ -117,11 +117,6 @@ function core_process_stanza(origin, stanza) return; -- FIXME what should we do here? does this work with subdomains? end end - if origin.type == "c2s" and stanza.name == "presence" and to ~= nil and not(origin.roster[to_bare] and (origin.roster[to_bare].subscription == "both" or origin.roster[to_bare].subscription == "from")) then -- directed presence - origin.directed = origin.directed or {}; - origin.directed[to] = true; - --t_insert(origin.directed, to); -- FIXME does it make more sense to add to_bare rather than to? - end if not to then core_handle_stanza(origin, stanza); elseif hosts[to] and hosts[to].type == "local" then -- directed at a local server -- cgit v1.2.3 From 6882c5dae0fb22e103df404bdff4b2926a6c968e Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Fri, 15 May 2009 06:34:42 +0500 Subject: mod_presence: Added a FIXME comment about directed presence --- plugins/mod_presence.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/mod_presence.lua b/plugins/mod_presence.lua index 415e5313..7c34eefa 100644 --- a/plugins/mod_presence.lua +++ b/plugins/mod_presence.lua @@ -252,7 +252,7 @@ local function presence_handler(data) if origin.type == "c2s" then if to ~= nil and not(origin.roster[to_bare] and (origin.roster[to_bare].subscription == "both" or origin.roster[to_bare].subscription == "from")) then -- directed presence origin.directed = origin.directed or {}; - origin.directed[to] = true; + origin.directed[to] = true; -- FIXME does it make more sense to add to_bare rather than to? end if stanza.attr.type ~= nil and stanza.attr.type ~= "unavailable" and stanza.attr.type ~= "error" then handle_outbound_presence_subscriptions_and_probes(origin, stanza, from_bare, to_bare, core_route_stanza); -- cgit v1.2.3 From fa8aeaf04f2737928eab4f0df383e292435e2159 Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Fri, 15 May 2009 06:39:53 +0500 Subject: util.stanza: Omit unused clone parameter from error_reply() --- util/stanza.lua | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/util/stanza.lua b/util/stanza.lua index 7e40dfa4..526bb2f0 100644 --- a/util/stanza.lua +++ b/util/stanza.lua @@ -258,10 +258,9 @@ function reply(orig) return stanza(orig.name, orig.attr and { to = orig.attr.from, from = orig.attr.to, id = orig.attr.id, type = ((orig.name == "iq" and "result") or orig.attr.type) }); end -function error_reply(orig, type, condition, message, clone) +function error_reply(orig, type, condition, message) local t = reply(orig); t.attr.type = "error"; - -- TODO use clone t:tag("error", {type = type}) :tag(condition, {xmlns = "urn:ietf:params:xml:ns:xmpp-stanzas"}):up(); if (message) then t:tag("text"):text(message):up(); end -- cgit v1.2.3 From 49f6299766454759ebc597e22881fda6329f380b Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Fri, 15 May 2009 07:04:41 +0500 Subject: stanza_router: Fixed an invalid stanza check --- core/stanza_router.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/stanza_router.lua b/core/stanza_router.lua index 43ba4547..963dffca 100644 --- a/core/stanza_router.lua +++ b/core/stanza_router.lua @@ -54,7 +54,7 @@ function core_process_stanza(origin, stanza) if not stanza.attr.xmlns then stanza.attr.xmlns = "jabber:client"; end -- FIXME Hack. This should be removed when we fix namespace handling. -- TODO verify validity of stanza (as well as JID validity) - if stanza.attr.xmlns == "error" and #stanza.tags == 0 then return; end -- TODO invalid stanza, log + if stanza.attr.type == "error" and #stanza.tags == 0 then return; end -- TODO invalid stanza, log if stanza.name == "iq" then if (stanza.attr.type == "set" or stanza.attr.type == "get") and #stanza.tags ~= 1 then origin.send(st.error_reply(stanza, "modify", "bad-request")); -- cgit v1.2.3 From 49f84f6dbfa8348b42268f0e5c2858e48308527c Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Fri, 15 May 2009 07:24:16 +0500 Subject: core.xmlhandlers: Removed unused variables --- core/xmlhandlers.lua | 6 ------ 1 file changed, 6 deletions(-) diff --git a/core/xmlhandlers.lua b/core/xmlhandlers.lua index 7e09921c..ed6f6a48 100644 --- a/core/xmlhandlers.lua +++ b/core/xmlhandlers.lua @@ -15,14 +15,8 @@ local tostring = tostring; local pairs = pairs; local ipairs = ipairs; local type = type; -local print = print; -local format = string.format; -local m_random = math.random; local t_insert = table.insert; -local t_remove = table.remove; local t_concat = table.concat; -local t_concatall = function (t, sep) local tt = {}; for _, s in ipairs(t) do t_insert(tt, tostring(s)); end return t_concat(tt, sep); end -local sm_destroy_session = import("core.sessionmanager", "destroy_session"); local default_log = require "util.logger".init("xmlhandlers"); -- cgit v1.2.3 From 7bfd9cc259b2ec3205464d6d679a31618360e9c8 Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Fri, 15 May 2009 07:27:03 +0500 Subject: xmlhandlers: Removed an unnecessary check --- core/xmlhandlers.lua | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/core/xmlhandlers.lua b/core/xmlhandlers.lua index ed6f6a48..fc070115 100644 --- a/core/xmlhandlers.lua +++ b/core/xmlhandlers.lua @@ -14,7 +14,6 @@ local st = stanza; local tostring = tostring; local pairs = pairs; local ipairs = ipairs; -local type = type; local t_insert = table.insert; local t_concat = table.concat; @@ -62,15 +61,13 @@ function init_xmlhandlers(session, stream_callbacks) -- FIXME !!!!! for i, k in ipairs(attr) do - if type(k) == "string" then - local ns, nm = k:match("^([^|]+)|?([^|]-)$") - if ns and nm then - ns = ns_prefixes[ns]; - if ns then - attr[ns..":"..nm] = attr[k]; - attr[i] = ns..":"..nm; - attr[k] = nil; - end + local ns, nm = k:match("^([^|]+)|?([^|]-)$") + if ns and nm then + ns = ns_prefixes[ns]; + if ns then + attr[ns..":"..nm] = attr[k]; + attr[i] = ns..":"..nm; + attr[k] = nil; end end end -- cgit v1.2.3 From b3c0964aa16905d911f619eb3f13b7dbed94e235 Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Fri, 15 May 2009 07:51:33 +0500 Subject: xmlhandlers: Removed another unnecessary check --- core/xmlhandlers.lua | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/core/xmlhandlers.lua b/core/xmlhandlers.lua index fc070115..573a9604 100644 --- a/core/xmlhandlers.lua +++ b/core/xmlhandlers.lua @@ -120,19 +120,17 @@ function init_xmlhandlers(session, stream_callbacks) cb_error(session, "parse-error", "unexpected-element-close", name); end end - if stanza then - if #chardata > 0 then - -- We have some character data in the buffer - stanza:text(t_concat(chardata)); - chardata = {}; - end - -- Complete stanza - if #stanza.last_add == 0 then - cb_handlestanza(session, stanza); - stanza = nil; - else - stanza:up(); - end + if #chardata > 0 then + -- We have some character data in the buffer + stanza:text(t_concat(chardata)); + chardata = {}; + end + -- Complete stanza + if #stanza.last_add == 0 then + cb_handlestanza(session, stanza); + stanza = nil; + else + stanza:up(); end end return xml_handlers; -- cgit v1.2.3 From ac714ae51b169c3a64041355b8d954a5adeaa5d8 Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Fri, 15 May 2009 08:30:48 +0500 Subject: stanza_router: Removed a FIXME --- core/stanza_router.lua | 1 - 1 file changed, 1 deletion(-) diff --git a/core/stanza_router.lua b/core/stanza_router.lua index 963dffca..75b477b4 100644 --- a/core/stanza_router.lua +++ b/core/stanza_router.lua @@ -106,7 +106,6 @@ function core_process_stanza(origin, stanza) return; -- FIXME what should we do here? end]] -- FIXME - -- FIXME do stanzas not of jabber:client get handled by components? if (origin.type == "s2sin" or origin.type == "c2s" or origin.type == "component") and (not xmlns or xmlns == "jabber:server" or xmlns == "jabber:client") then local event_data = {origin=origin, stanza=stanza}; if fire_event(tostring(host or origin.host).."/"..stanza.name, event_data) then return; end -- cgit v1.2.3 From d836e5c09de5c45af4c76cc8cc66458bc0c5deec Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Fri, 15 May 2009 08:42:53 +0500 Subject: stanza_router: Removed some unnecessary code --- core/stanza_router.lua | 2 -- 1 file changed, 2 deletions(-) diff --git a/core/stanza_router.lua b/core/stanza_router.lua index 75b477b4..8f3d2d1f 100644 --- a/core/stanza_router.lua +++ b/core/stanza_router.lua @@ -128,8 +128,6 @@ function core_process_stanza(origin, stanza) component_handle_stanza(origin, stanza); elseif hosts[host] and hosts[host].type == "component" then -- directed at a component component_handle_stanza(origin, stanza); - elseif origin.type == "c2s" and stanza.name == "presence" and stanza.attr.type ~= nil and stanza.attr.type ~= "unavailable" and stanza.attr.type ~= "error" then - handle_outbound_presence_subscriptions_and_probes(origin, stanza, from_bare, to_bare, core_route_stanza); elseif hosts[host] and hosts[host].type == "local" and stanza.name == "iq" and not resource then -- directed at bare JID core_handle_stanza(origin, stanza); else -- cgit v1.2.3