aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--core/componentmanager.lua7
-rw-r--r--core/stanza_router.lua41
-rwxr-xr-xprosody12
-rw-r--r--util/array.lua15
4 files changed, 49 insertions, 26 deletions
diff --git a/core/componentmanager.lua b/core/componentmanager.lua
index fe4a6999..eb18fced 100644
--- a/core/componentmanager.lua
+++ b/core/componentmanager.lua
@@ -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 @@ require "core.discomanager".addDiscoItemsHandler("*host", function(reply, to, fr
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 @@ function load_enabled_components(config)
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 --git a/core/stanza_router.lua b/core/stanza_router.lua
index cf4257c5..e5454119 100644
--- a/core/stanza_router.lua
+++ b/core/stanza_router.lua
@@ -48,15 +48,16 @@ function core_process_stanza(origin, stanza)
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
-
- -- TODO also, stanzas should be returned to their original state before the function ends
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
stanza.attr.from = origin.full_jid;
end
local to, xmlns = stanza.attr.to, stanza.attr.xmlns;
@@ -65,19 +66,23 @@ function core_process_stanza(origin, stanza)
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 --git a/prosody b/prosody
index 08ee6cf0..0fd0b735 100755
--- a/prosody
+++ b/prosody
@@ -144,7 +144,7 @@ end);
-- 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 @@ end
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 @@ end
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 @@ local function catch_uncaught_error(err)
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 @@ while select(2, xpcall(server.loop, catch_uncaught_error)) ~= "quitting" do
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.closeall();
server.setquitting(true);
eventmanager.fire_event("server-stopped");
+prosody.events.fire_event("server-stopped");
log("info", "Shutdown status: Complete!");
diff --git a/util/array.lua b/util/array.lua
index 072b24a7..05e035df 100644
--- a/util/array.lua
+++ b/util/array.lua
@@ -5,6 +5,11 @@ local function new_array(_, t)
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 @@ function array:shuffle()
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 @@ function array:reverse()
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)