plugins/mod_proxy65.lua

changeset 3559
0708d42ef0d4
parent 3558
f1201ff060b7
child 3604
3e89f0509967
equal deleted inserted replaced
3558:f1201ff060b7 3559:0708d42ef0d4
207 return reply, from, to, sid; 207 return reply, from, to, sid;
208 end 208 end
209 209
210 function handle_to_domain(event) 210 function handle_to_domain(event)
211 local origin, stanza = event.origin, event.stanza; 211 local origin, stanza = event.origin, event.stanza;
212 local to_node, to_host, to_resource = jid_split(stanza.attr.to); 212 if stanza.attr.type == "get" then
213 if to_node == nil then 213 local xmlns = stanza.tags[1].attr.xmlns
214 local type = stanza.attr.type; 214 if xmlns == "http://jabber.org/protocol/disco#info" then
215 if type == "error" or type == "result" then return; end 215 origin.send(get_disco_info(stanza));
216 if stanza.name == "iq" and type == "get" then 216 return true;
217 local xmlns = stanza.tags[1].attr.xmlns 217 elseif xmlns == "http://jabber.org/protocol/disco#items" then
218 if xmlns == "http://jabber.org/protocol/disco#info" then 218 origin.send(get_disco_items(stanza));
219 origin.send(get_disco_info(stanza)); 219 return true;
220 return true; 220 elseif xmlns == "http://jabber.org/protocol/bytestreams" then
221 elseif xmlns == "http://jabber.org/protocol/disco#items" then 221 origin.send(get_stream_host(origin, stanza));
222 origin.send(get_disco_items(stanza)); 222 return true;
223 return true; 223 else
224 elseif xmlns == "http://jabber.org/protocol/bytestreams" then 224 origin.send(st.error_reply(stanza, "cancel", "service-unavailable"));
225 origin.send(get_stream_host(origin, stanza)); 225 return true;
226 return true; 226 end
227 else -- stanza.attr.type == "set"
228 module:log("debug", "Received activation request from %s", stanza.attr.from);
229 local reply, from, to, sid = set_activation(stanza);
230 if reply ~= nil and from ~= nil and to ~= nil and sid ~= nil then
231 local sha = sha1(sid .. from .. to, true);
232 if transfers[sha] == nil then
233 module:log("error", "transfers[sha]: nil");
234 elseif(transfers[sha] ~= nil and transfers[sha].initiator ~= nil and transfers[sha].target ~= nil) then
235 origin.send(reply);
236 transfers[sha].activated = true;
237 transfers[sha].target:lock_read(false);
238 transfers[sha].initiator:lock_read(false);
227 else 239 else
228 origin.send(st.error_reply(stanza, "cancel", "service-unavailable")); 240 module:log("debug", "Both parties were not yet connected");
229 return true; 241 local message = "Neither party is connected to the proxy";
230 end 242 if transfers[sha].initiator then
231 elseif stanza.name == "iq" and type == "set" then 243 message = "The recipient is not connected to the proxy";
232 module:log("debug", "Received activation request from %s", stanza.attr.from); 244 elseif transfers[sha].target then
233 local reply, from, to, sid = set_activation(stanza); 245 message = "The sender (you) is not connected to the proxy";
234 if reply ~= nil and from ~= nil and to ~= nil and sid ~= nil then
235 local sha = sha1(sid .. from .. to, true);
236 if transfers[sha] == nil then
237 module:log("error", "transfers[sha]: nil");
238 elseif(transfers[sha] ~= nil and transfers[sha].initiator ~= nil and transfers[sha].target ~= nil) then
239 origin.send(reply);
240 transfers[sha].activated = true;
241 transfers[sha].target:lock_read(false);
242 transfers[sha].initiator:lock_read(false);
243 else
244 module:log("debug", "Both parties were not yet connected");
245 local message = "Neither party is connected to the proxy";
246 if transfers[sha].initiator then
247 message = "The recipient is not connected to the proxy";
248 elseif transfers[sha].target then
249 message = "The sender (you) is not connected to the proxy";
250 end
251 origin.send(st.error_reply(stanza, "cancel", "not-allowed", message));
252 end 246 end
253 else 247 origin.send(st.error_reply(stanza, "cancel", "not-allowed", message));
254 module:log("error", "activation failed: sid: %s, initiator: %s, target: %s", tostring(sid), tostring(from), tostring(to)); 248 end
255 end 249 return true;
256 end 250 else
257 end 251 module:log("error", "activation failed: sid: %s, initiator: %s, target: %s", tostring(sid), tostring(from), tostring(to));
258 return; 252 end
253 end
259 end 254 end
260 module:hook("iq/host", handle_to_domain); 255 module:hook("iq/host", handle_to_domain);
261 256
262 if not connlisteners.register(module.host .. ':proxy65', connlistener) then 257 if not connlisteners.register(module.host .. ':proxy65', connlistener) then
263 module:log("error", "mod_proxy65: Could not establish a connection listener. Check your configuration please."); 258 module:log("error", "mod_proxy65: Could not establish a connection listener. Check your configuration please.");

mercurial