-end
-
-function core_handle_stanza(origin, stanza)
- -- Handlers
- if origin.type == "c2s" or origin.type == "c2s_unauthed" then
- local session = origin;
- stanza.attr.from = session.full_jid;
-
- log("debug", "Routing stanza");
- -- Stanza has no to attribute
- --local to_node, to_host, to_resource = jid_split(stanza.attr.to);
- --if not to_host then error("Invalid destination JID: "..string.format("{ %q, %q, %q } == %q", to_node or "", to_host or "", to_resource or "", stanza.attr.to or "nil")); end
-
- -- Stanza is to this server, or a user on this server
- log("debug", "Routing stanza to local");
- handle_stanza(session, stanza);
- end
-end
-
-function core_route_stanza(origin, stanza)
- -- Hooks
- --- ...later
-
- -- Deliver
- local node, host, resource = jid_split(stanza.attr.to);
- local host_session = hosts[host]
- if host_session and host_session.type == "local" then
- -- Local host
- local user = host_session.sessions[node];
- if user then
- local res = user.sessions[resource];
- -- TODO do something about presence broadcast
- if not res then
- -- if we get here, resource was not specified or was unavailable
- for k in pairs(user.sessions) do
- res = user.sessions[k];
- break;
- end
- -- TODO find resource with greatest priority
- end
- stanza.attr.to = res.full_jid;
- send(res, stanza); -- Yay \o/
- else
- -- user not found
- send(origin, st.error_reply(stanza, "cancel", "service-unavailable"));
- end
- else
- -- Remote host
- if host_session then
- -- Send to session
- else
- -- Need to establish the connection
+ local to, xmlns = stanza.attr.to, stanza.attr.xmlns;
+ local from = stanza.attr.from;
+ local node, host, resource;
+ 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
+ error("Invalid to JID");