Comparison

core/stanza_router.lua @ 1172:490ff24d0ac5

stanza_router: Added global function core_post_stanza
author Waqas Hussain <waqas20@gmail.com>
date Sat, 16 May 2009 03:58:05 +0500
parent 1169:fdc68aec1d49
child 1178:f332c033bfc8
comparison
equal deleted inserted replaced
1171:be11dc0610d5 1172:490ff24d0ac5
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?
110 end 110 end
111 end 111 end
112 local event_data = {origin=origin, stanza=stanza}; 112 core_post_stanza(origin, stanza);
113 if fire_event(tostring(host or origin.host).."/"..stanza.name, event_data) then
114 -- event handled
115 elseif not to then
116 modules_handle_stanza(host or origin.host or origin.to_host, origin, stanza);
117 elseif hosts[to] and hosts[to].type == "local" then -- directed at a local server
118 modules_handle_stanza(host or origin.host or origin.to_host, origin, stanza);
119 elseif hosts[to_bare] and hosts[to_bare].type == "component" then -- hack to allow components to handle node@server
120 component_handle_stanza(origin, stanza);
121 elseif hosts[host] and hosts[host].type == "component" then -- directed at a component
122 component_handle_stanza(origin, stanza);
123 elseif hosts[host] and hosts[host].type == "local" and stanza.name == "iq" and not resource then -- directed at bare JID
124 modules_handle_stanza(host or origin.host or origin.to_host, origin, stanza);
125 else
126 core_route_stanza(origin, stanza);
127 end
128 else 113 else
129 modules_handle_stanza(host or origin.host or origin.to_host, origin, stanza); 114 modules_handle_stanza(host or origin.host or origin.to_host, origin, stanza);
115 end
116 end
117
118 function core_post_stanza(origin, stanza)
119 local to = stanza.attr.to;
120 local node, host, resource = jid_split(to);
121 local to_bare = node and (node.."@"..host) or host; -- bare JID
122
123 local event_data = {origin=origin, stanza=stanza};
124 if fire_event(tostring(host or origin.host).."/"..stanza.name, event_data) then
125 -- event handled
126 elseif not to then
127 modules_handle_stanza(host or origin.host or origin.to_host, origin, stanza);
128 elseif hosts[to] and hosts[to].type == "local" then -- directed at a local server
129 modules_handle_stanza(host or origin.host or origin.to_host, origin, stanza);
130 elseif hosts[to_bare] and hosts[to_bare].type == "component" then -- hack to allow components to handle node@server
131 component_handle_stanza(origin, stanza);
132 elseif hosts[host] and hosts[host].type == "component" then -- directed at a component
133 component_handle_stanza(origin, stanza);
134 elseif hosts[host] and hosts[host].type == "local" and stanza.name == "iq" and not resource then -- directed at bare JID
135 modules_handle_stanza(host or origin.host or origin.to_host, origin, stanza);
136 else
137 core_route_stanza(origin, stanza);
130 end 138 end
131 end 139 end
132 140
133 function core_route_stanza(origin, stanza) 141 function core_route_stanza(origin, stanza)
134 -- Hooks 142 -- Hooks