core/stanza_router.lua

changeset 1167
5620ea24be94
parent 1165
ec69bcc7ceb5
child 1168
dd523bfc9ea9
equal deleted inserted replaced
1166:5499a028d4ae 1167:5620ea24be94
111 end 111 end
112 local event_data = {origin=origin, stanza=stanza}; 112 local event_data = {origin=origin, stanza=stanza};
113 if fire_event(tostring(host or origin.host).."/"..stanza.name, event_data) then 113 if fire_event(tostring(host or origin.host).."/"..stanza.name, event_data) then
114 -- event handled 114 -- event handled
115 elseif not to then 115 elseif not to then
116 core_handle_stanza(origin, stanza); 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 117 elseif hosts[to] and hosts[to].type == "local" then -- directed at a local server
118 core_handle_stanza(origin, stanza); 118 modules_handle_stanza(host or origin.host or origin.to_host, origin, stanza);
119 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
120 component_handle_stanza(origin, stanza); 120 component_handle_stanza(origin, stanza);
121 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
122 component_handle_stanza(origin, stanza); 122 component_handle_stanza(origin, stanza);
123 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
124 component_handle_stanza(origin, stanza); 124 component_handle_stanza(origin, stanza);
125 elseif hosts[host] and hosts[host].type == "local" and stanza.name == "iq" and not resource then -- directed at bare JID 125 elseif hosts[host] and hosts[host].type == "local" and stanza.name == "iq" and not resource then -- directed at bare JID
126 core_handle_stanza(origin, stanza); 126 modules_handle_stanza(host or origin.host or origin.to_host, origin, stanza);
127 else 127 else
128 core_route_stanza(origin, stanza); 128 core_route_stanza(origin, stanza);
129 end 129 end
130 else 130 else
131 core_handle_stanza(origin, stanza); 131 modules_handle_stanza(host or origin.host or origin.to_host, origin, stanza);
132 end
133 end
134
135 -- This function handles stanzas which are not routed any further,
136 -- that is, they are handled by this server
137 function core_handle_stanza(origin, stanza)
138 if not modules_handle_stanza(select(2, jid_split(stanza.attr.to)) or origin.host or origin.to_host, origin, stanza) then
139 log("warn", "Unhandled %s stanza: %s", origin.type, tostring(stanza));
140 if stanza.attr.xmlns == "jabber:client" then
141 if stanza.attr.type ~= "error" and stanza.attr.type ~= "result" then
142 origin.send(st.error_reply(stanza, "cancel", "service-unavailable"));
143 end
144 else
145 origin:close("unsupported-stanza-type");
146 end
147 end 132 end
148 end 133 end
149 134
150 function core_route_stanza(origin, stanza) 135 function core_route_stanza(origin, stanza)
151 -- Hooks 136 -- Hooks

mercurial