Comparison

core/stanza_router.lua @ 1165:ec69bcc7ceb5

stanza_router: Cleaner namespace handling
author Waqas Hussain <waqas20@gmail.com>
date Sat, 16 May 2009 00:33:49 +0500
parent 1164:251954b07cae
child 1167:5620ea24be94
comparison
equal deleted inserted replaced
1164:251954b07cae 1165:ec69bcc7ceb5
99 --[[if to and not(hosts[to]) and not(hosts[to_bare]) and (hosts[host] and hosts[host].type ~= "local") then -- not for us? 99 --[[if to and not(hosts[to]) and not(hosts[to_bare]) and (hosts[host] and hosts[host].type ~= "local") then -- not for us?
100 log("warn", "stanza recieved for a non-local server"); 100 log("warn", "stanza recieved for a non-local server");
101 return; -- FIXME what should we do here? 101 return; -- FIXME what should we do here?
102 end]] -- FIXME 102 end]] -- FIXME
103 103
104 if (origin.type == "s2sin" or origin.type == "c2s" or origin.type == "component") and (not xmlns or xmlns == "jabber:server" or xmlns == "jabber:client") then 104 if (origin.type == "s2sin" or origin.type == "c2s" or origin.type == "component") and xmlns == "jabber:client" then
105 if origin.type == "s2sin" and not origin.dummy then 105 if origin.type == "s2sin" and not origin.dummy then
106 local host_status = origin.hosts[from_host]; 106 local host_status = origin.hosts[from_host];
107 if not host_status or not host_status.authed then -- remote server trying to impersonate some other server? 107 if not host_status or not host_status.authed then -- remote server trying to impersonate some other server?
108 log("warn", "Received a stanza claiming to be from %s, over a conn authed for %s!", from_host, origin.from_host); 108 log("warn", "Received a stanza claiming to be from %s, over a conn authed for %s!", from_host, origin.from_host);
109 return; -- FIXME what should we do here? does this work with subdomains? 109 return; -- FIXME what should we do here? does this work with subdomains?
114 -- event handled 114 -- event handled
115 elseif not to then 115 elseif not to then
116 core_handle_stanza(origin, stanza); 116 core_handle_stanza(origin, stanza);
117 elseif hosts[to] and hosts[to].type == "local" then -- directed at a local server 117 elseif hosts[to] and hosts[to].type == "local" then -- directed at a local server
118 core_handle_stanza(origin, stanza); 118 core_handle_stanza(origin, stanza);
119 elseif stanza.attr.xmlns and stanza.attr.xmlns ~= "jabber:client" and stanza.attr.xmlns ~= "jabber:server" then
120 modules_handle_stanza(host or origin.host or origin.to_host, origin, stanza);
121 elseif hosts[to] and hosts[to].type == "component" then -- hack to allow components to handle node@server/resource and server/resource 119 elseif hosts[to] and hosts[to].type == "component" then -- hack to allow components to handle node@server/resource and server/resource
122 component_handle_stanza(origin, stanza); 120 component_handle_stanza(origin, stanza);
123 elseif hosts[to_bare] and hosts[to_bare].type == "component" then -- hack to allow components to handle node@server 121 elseif hosts[to_bare] and hosts[to_bare].type == "component" then -- hack to allow components to handle node@server
124 component_handle_stanza(origin, stanza); 122 component_handle_stanza(origin, stanza);
125 elseif hosts[host] and hosts[host].type == "component" then -- directed at a component 123 elseif hosts[host] and hosts[host].type == "component" then -- directed at a component
137 -- This function handles stanzas which are not routed any further, 135 -- This function handles stanzas which are not routed any further,
138 -- that is, they are handled by this server 136 -- that is, they are handled by this server
139 function core_handle_stanza(origin, stanza) 137 function core_handle_stanza(origin, stanza)
140 if not modules_handle_stanza(select(2, jid_split(stanza.attr.to)) or origin.host or origin.to_host, origin, stanza) then 138 if not modules_handle_stanza(select(2, jid_split(stanza.attr.to)) or origin.host or origin.to_host, origin, stanza) then
141 log("warn", "Unhandled %s stanza: %s", origin.type, tostring(stanza)); 139 log("warn", "Unhandled %s stanza: %s", origin.type, tostring(stanza));
142 if (stanza.attr.xmlns == "jabber:client" or stanza.attr.xmlns == "jabber:server") then 140 if stanza.attr.xmlns == "jabber:client" then
143 if stanza.attr.type ~= "error" and stanza.attr.type ~= "result" then 141 if stanza.attr.type ~= "error" and stanza.attr.type ~= "result" then
144 origin.send(st.error_reply(stanza, "cancel", "service-unavailable")); 142 origin.send(st.error_reply(stanza, "cancel", "service-unavailable"));
145 end 143 end
146 else 144 else
147 origin:close("unsupported-stanza-type"); 145 origin:close("unsupported-stanza-type");