aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/componentmanager.lua7
-rw-r--r--core/stanza_router.lua41
2 files changed, 26 insertions, 22 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