# HG changeset patch # User Matthew Wild # Date 1245534638 -3600 # Node ID ae88b9dc7890bbe5aceb6d4e41f759b4d5a9699c # Parent 120275376bbbbc22a18c625b2ef648dd0a46f1c5# Parent 13587cf24435ed622f1d979d19958790ea658aa5 Merge with Tobias diff -r 13587cf24435 -r ae88b9dc7890 core/componentmanager.lua --- a/core/componentmanager.lua Sat Jun 20 22:19:24 2009 +0200 +++ b/core/componentmanager.lua Sat Jun 20 22:50:38 2009 +0100 @@ -8,10 +8,9 @@ - +local prosody = prosody; local log = require "util.logger".init("componentmanager"); local configmanager = require "core.configmanager"; -local eventmanager = require "core.eventmanager"; local modulemanager = require "core.modulemanager"; local core_route_stanza = core_route_stanza; local jid_split = require "util.jid".split; @@ -34,7 +33,7 @@ end end); -require "core.eventmanager".add_event_hook("server-starting", function () core_route_stanza = _G.core_route_stanza; end); +prosody.events.add_handler("server-starting", function () core_route_stanza = _G.core_route_stanza; end); module "componentmanager" @@ -63,7 +62,7 @@ end end -eventmanager.add_event_hook("server-starting", load_enabled_components); +prosody.events.add_handler("server-starting", load_enabled_components); function handle_stanza(origin, stanza) local node, host = jid_split(stanza.attr.to); diff -r 13587cf24435 -r ae88b9dc7890 core/stanza_router.lua --- a/core/stanza_router.lua Sat Jun 20 22:19:24 2009 +0200 +++ b/core/stanza_router.lua Sat Jun 20 22:50:38 2009 +0100 @@ -48,15 +48,16 @@ end end - if origin.type == "c2s" and not origin.full_jid - and not(stanza.name == "iq" and stanza.attr.type == "set" and stanza.tags[1] and stanza.tags[1].name == "bind" - and stanza.tags[1].attr.xmlns == "urn:ietf:params:xml:ns:xmpp-bind") then - -- authenticated client isn't bound and current stanza is not a bind request - origin.send(st.error_reply(stanza, "auth", "not-authorized")); -- FIXME maybe allow stanzas to account or server - end + if origin.type == "c2s" then + if not origin.full_jid + and not(stanza.name == "iq" and stanza.attr.type == "set" and stanza.tags[1] and stanza.tags[1].name == "bind" + and stanza.tags[1].attr.xmlns == "urn:ietf:params:xml:ns:xmpp-bind") then + -- authenticated client isn't bound and current stanza is not a bind request + origin.send(st.error_reply(stanza, "auth", "not-authorized")); -- FIXME maybe allow stanzas to account or server + return; + end - -- TODO also, stanzas should be returned to their original state before the function ends - if origin.type == "c2s" then + -- TODO also, stanzas should be returned to their original state before the function ends stanza.attr.from = origin.full_jid; end local to, xmlns = stanza.attr.to, stanza.attr.xmlns; @@ -65,19 +66,23 @@ local from_node, from_host, from_resource; local to_bare, from_bare; if to then - node, host, resource = jid_prepped_split(to); - if not host then - log("warn", "Received stanza with invalid destination JID: %s", to); - if stanza.attr.type ~= "error" and stanza.attr.type ~= "result" then - origin.send(st.error_reply(stanza, "modify", "jid-malformed", "The destination address is invalid: "..to)); + if full_sessions[to] or bare_sessions[to] or hosts[to] then + node, host = jid_split(to); -- TODO only the host is needed, optimize + else + node, host, resource = jid_prepped_split(to); + if not host then + log("warn", "Received stanza with invalid destination JID: %s", to); + if stanza.attr.type ~= "error" and stanza.attr.type ~= "result" then + origin.send(st.error_reply(stanza, "modify", "jid-malformed", "The destination address is invalid: "..to)); + end + return; end - return; + to_bare = node and (node.."@"..host) or host; -- bare JID + if resource then to = to_bare.."/"..resource; else to = to_bare; end + stanza.attr.to = to; end - to_bare = node and (node.."@"..host) or host; -- bare JID - if resource then to = to_bare.."/"..resource; else to = to_bare; end - stanza.attr.to = to; end - if from then + if from and not origin.full_jid then -- We only stamp the 'from' on c2s stanzas, so we still need to check validity from_node, from_host, from_resource = jid_prepped_split(from); if not from_host then diff -r 13587cf24435 -r ae88b9dc7890 prosody --- a/prosody Sat Jun 20 22:19:24 2009 +0200 +++ b/prosody Sat Jun 20 22:50:38 2009 +0100 @@ -144,7 +144,7 @@ -- Function to reload the config file function prosody.reload_config() log("info", "Reloading configuration file"); - eventmanager.fire_event("reloading-config"); + prosody.events.fire_event("reloading-config"); local ok, level, err = config.load((rawget(_G, "CFG_CONFIGDIR") or ".").."/prosody.cfg.lua"); if not ok then if level == "parser" then @@ -159,17 +159,19 @@ function prosody.reopen_logfiles() log("info", "Re-opening log files"); eventmanager.fire_event("reopen-log-files"); -- Handled by appropriate log sinks + prosody.events.fire_event("reopen-log-files"); end -- Function to initiate prosody shutdown function prosody.shutdown(reason) log("info", "Shutting down: %s", reason or "unknown reason"); - eventmanager.fire_event("server-stopping", { reason = reason }); + prosody.events.fire_event("server-stopping", {reason = reason}); server.setquitting(true); end -- Signal to modules that we are ready to start eventmanager.fire_event("server-starting"); +prosody.events.fire_event("server-starting"); -- Load SSL settings from config, and create a ctx table local global_ssl_ctx = ssl and config.get("*", "core", "ssl"); @@ -227,6 +229,7 @@ prosody.lock_globals(); eventmanager.fire_event("server-started"); +prosody.events.fire_event("server-started"); -- Error handler for errors that make it this far local function catch_uncaught_error(err) @@ -240,7 +243,7 @@ log("error", "%s", traceback); end - eventmanager.fire_event("very-bad-error", "*", err, traceback); + prosody.events.fire_event("very-bad-error", {error = err, traceback = traceback}); end while select(2, xpcall(server.loop, catch_uncaught_error)) ~= "quitting" do @@ -248,7 +251,7 @@ end log("info", "Shutdown status: Cleaning up"); -eventmanager.fire_event("server-cleanup"); +prosody.events.fire_event("server-cleanup"); -- Ok, we're quitting I know, but we -- need to do some tidying before we go :) @@ -284,4 +287,5 @@ server.setquitting(true); eventmanager.fire_event("server-stopped"); +prosody.events.fire_event("server-stopped"); log("info", "Shutdown status: Complete!"); diff -r 13587cf24435 -r ae88b9dc7890 util/array.lua --- a/util/array.lua Sat Jun 20 22:19:24 2009 +0200 +++ b/util/array.lua Sat Jun 20 22:50:38 2009 +0100 @@ -5,6 +5,11 @@ return setmetatable(t or {}, array_mt); end +function array_mt.__add(a1, a2) + local res = new_array(); + return res:append(a1):append(a2); +end + setmetatable(array, { __call = new_array }); function array:map(func, t2) @@ -42,6 +47,7 @@ local r = math.random(i,len); self[i], self[r] = self[r], self[i]; end + return self; end function array:reverse() @@ -50,6 +56,15 @@ self:push(self[i]); self:pop(i); end + return self; +end + +function array:append(array) + local len,len2 = #self, #array; + for i=1,len2 do + self[len+i] = array[i]; + end + return self; end function array.collect(f, s, var)