239 else |
239 else |
240 origin.send(st.error_reply(stanza, "cancel", "service-unavailable")); |
240 origin.send(st.error_reply(stanza, "cancel", "service-unavailable")); |
241 return true; |
241 return true; |
242 end |
242 end |
243 elseif stanza.name == "iq" and type == "set" then |
243 elseif stanza.name == "iq" and type == "set" then |
|
244 module:log("debug", "Received activation request from %s", stanza.attr.from); |
244 local reply, from, to, sid = set_activation(stanza); |
245 local reply, from, to, sid = set_activation(stanza); |
245 if reply ~= nil and from ~= nil and to ~= nil and sid ~= nil then |
246 if reply ~= nil and from ~= nil and to ~= nil and sid ~= nil then |
246 local sha = sha1(sid .. from .. to, true); |
247 local sha = sha1(sid .. from .. to, true); |
247 if transfers[sha] == nil then |
248 if transfers[sha] == nil then |
248 module:log("error", "transfers[sha]: nil"); |
249 module:log("error", "transfers[sha]: nil"); |
249 elseif(transfers[sha] ~= nil and transfers[sha].initiator ~= nil and transfers[sha].target ~= nil) then |
250 elseif(transfers[sha] ~= nil and transfers[sha].initiator ~= nil and transfers[sha].target ~= nil) then |
250 origin.send(reply); |
251 origin.send(reply); |
251 transfers[sha].activated = true; |
252 transfers[sha].activated = true; |
252 transfers[sha].target:lock_read(false); |
253 transfers[sha].target:lock_read(false); |
253 transfers[sha].initiator:lock_read(false); |
254 transfers[sha].initiator:lock_read(false); |
|
255 else |
|
256 module:log("debug", "Both parties were not yet connected"); |
|
257 local message = "Neither party is connected to the proxy"; |
|
258 if transfers[sha].initiator then |
|
259 message = "The recipient is not connected to the proxy"; |
|
260 elseif transfers[sha].target then |
|
261 message = "The sender (you) is not connected to the proxy"; |
|
262 end |
|
263 origin.send(st.error_reply(stanza, "cancel", "not-allowed", message)); |
254 end |
264 end |
255 else |
265 else |
256 module:log("error", "activation failed: sid: %s, initiator: %s, target: %s", tostring(sid), tostring(from), tostring(to)); |
266 module:log("error", "activation failed: sid: %s, initiator: %s, target: %s", tostring(sid), tostring(from), tostring(to)); |
257 end |
267 end |
258 end |
268 end |