2009-06-20
stanza_router: Skip prepping 'to' in many common cases - #optimization
| core/stanza_router.lua | file | annotate | diff | revisions |
1.1 --- a/core/stanza_router.lua Sat Jun 20 18:08:57 2009 +0500 1.2 +++ b/core/stanza_router.lua Sat Jun 20 18:18:38 2009 +0500 1.3 @@ -66,17 +66,21 @@ 1.4 local from_node, from_host, from_resource; 1.5 local to_bare, from_bare; 1.6 if to then 1.7 - node, host, resource = jid_prepped_split(to); 1.8 - if not host then 1.9 - log("warn", "Received stanza with invalid destination JID: %s", to); 1.10 - if stanza.attr.type ~= "error" and stanza.attr.type ~= "result" then 1.11 - origin.send(st.error_reply(stanza, "modify", "jid-malformed", "The destination address is invalid: "..to)); 1.12 + if full_sessions[to] or bare_sessions[to] or hosts[to] then 1.13 + node, host = jid_split(to); -- TODO only the host is needed, optimize 1.14 + else 1.15 + node, host, resource = jid_prepped_split(to); 1.16 + if not host then 1.17 + log("warn", "Received stanza with invalid destination JID: %s", to); 1.18 + if stanza.attr.type ~= "error" and stanza.attr.type ~= "result" then 1.19 + origin.send(st.error_reply(stanza, "modify", "jid-malformed", "The destination address is invalid: "..to)); 1.20 + end 1.21 + return; 1.22 end 1.23 - return; 1.24 + to_bare = node and (node.."@"..host) or host; -- bare JID 1.25 + if resource then to = to_bare.."/"..resource; else to = to_bare; end 1.26 + stanza.attr.to = to; 1.27 end 1.28 - to_bare = node and (node.."@"..host) or host; -- bare JID 1.29 - if resource then to = to_bare.."/"..resource; else to = to_bare; end 1.30 - stanza.attr.to = to; 1.31 end 1.32 if from and not origin.full_jid then 1.33 -- We only stamp the 'from' on c2s stanzas, so we still need to check validity