119 -- This function handles stanzas which are not routed any further, |
119 -- This function handles stanzas which are not routed any further, |
120 -- that is, they are handled by this server |
120 -- that is, they are handled by this server |
121 function core_handle_stanza(origin, stanza) |
121 function core_handle_stanza(origin, stanza) |
122 -- Handlers |
122 -- Handlers |
123 if modules_handle_stanza(stanza.attr.to or origin.host, origin, stanza) then return; end |
123 if modules_handle_stanza(stanza.attr.to or origin.host, origin, stanza) then return; end |
124 if origin.type == "c2s" or origin.type == "c2s_unauthed" then |
124 if origin.type == "c2s" or origin.type == "s2sin" then |
125 local session = origin; |
125 if origin.type == "c2s" then |
126 |
126 if stanza.name == "presence" and origin.roster then |
127 if stanza.name == "presence" and origin.roster then |
127 if stanza.attr.type == nil or stanza.attr.type == "unavailable" then |
128 if stanza.attr.type == nil or stanza.attr.type == "unavailable" then |
128 handle_normal_presence(origin, stanza, core_route_stanza); |
129 handle_normal_presence(origin, stanza, core_route_stanza); |
129 else |
|
130 log("warn", "Unhandled c2s presence: %s", tostring(stanza)); |
|
131 if (stanza.attr.xmlns == "jabber:client" or stanza.attr.xmlns == "jabber:server") and stanza.attr.type ~= "error" then |
|
132 origin.send(st.error_reply(stanza, "cancel", "service-unavailable")); -- FIXME correct error? |
|
133 end |
|
134 end |
130 else |
135 else |
131 log("warn", "Unhandled c2s presence: %s", tostring(stanza)); |
136 log("warn", "Unhandled c2s stanza: %s", tostring(stanza)); |
132 if (stanza.attr.xmlns == "jabber:client" or stanza.attr.xmlns == "jabber:server") and stanza.attr.type ~= "error" then |
137 if (stanza.attr.xmlns == "jabber:client" or stanza.attr.xmlns == "jabber:server") and stanza.attr.type ~= "error" and stanza.attr.type ~= "result" then |
133 origin.send(st.error_reply(stanza, "cancel", "service-unavailable")); -- FIXME correct error? |
138 origin.send(st.error_reply(stanza, "cancel", "service-unavailable")); -- FIXME correct error? |
134 end |
139 end |
135 end |
140 end |
136 else |
141 else -- s2s stanzas |
137 log("warn", "Unhandled c2s stanza: %s", tostring(stanza)); |
142 log("warn", "Unhandled s2s stanza: %s", tostring(stanza)); |
138 if (stanza.attr.xmlns == "jabber:client" or stanza.attr.xmlns == "jabber:server") and stanza.attr.type ~= "error" and stanza.attr.type ~= "result" then |
143 if (stanza.attr.xmlns == "jabber:client" or stanza.attr.xmlns == "jabber:server") and stanza.attr.type ~= "error" and stanza.attr.type ~= "result" then |
139 origin.send(st.error_reply(stanza, "cancel", "service-unavailable")); -- FIXME correct error? |
144 origin.send(st.error_reply(stanza, "cancel", "service-unavailable")); -- FIXME correct error? |
140 end |
145 end |
141 end -- TODO handle other stanzas |
146 end |
142 else |
147 else |
143 log("warn", "Unhandled origin: %s", origin.type); |
148 log("warn", "Unhandled %s stanza: %s", origin.type, tostring(stanza)); |
144 if (stanza.attr.xmlns == "jabber:client" or stanza.attr.xmlns == "jabber:server") and stanza.attr.type ~= "error" and stanza.attr.type ~= "result" then |
|
145 -- s2s stanzas can get here |
|
146 origin.send(st.error_reply(stanza, "cancel", "service-unavailable")); -- FIXME correct error? |
|
147 end |
|
148 end |
149 end |
149 end |
150 end |
150 |
151 |
151 function core_route_stanza(origin, stanza) |
152 function core_route_stanza(origin, stanza) |
152 -- Hooks |
153 -- Hooks |