Software / code / prosody
Comparison
plugins/mod_proxy65.lua @ 4375:81f5e83211dd
mod_proxy65: Some more cleanup.
| author | Waqas Hussain <waqas20@gmail.com> |
|---|---|
| date | Sat, 03 Sep 2011 00:37:37 +0500 |
| parent | 4374:c38f20f172b3 |
| child | 4376:99277a1abe58 |
comparison
equal
deleted
inserted
replaced
| 4374:c38f20f172b3 | 4375:81f5e83211dd |
|---|---|
| 156 | 156 |
| 157 module.unload = function() | 157 module.unload = function() |
| 158 connlisteners.deregister(module.host .. ':proxy65'); | 158 connlisteners.deregister(module.host .. ':proxy65'); |
| 159 end | 159 end |
| 160 | 160 |
| 161 local function set_activation(stanza) | 161 module:hook("iq-set/host/http://jabber.org/protocol/bytestreams:query", function(event) |
| 162 local to, reply; | 162 local origin, stanza = event.origin, event.stanza; |
| 163 local from = stanza.attr.from; | 163 |
| 164 local query = stanza.tags[1]; | 164 local query = stanza.tags[1]; |
| 165 local sid = query.attr.sid; | 165 local sid = query.attr.sid; |
| 166 if query.tags[1] and query.tags[1].name == "activate" then | 166 local from = stanza.attr.from; |
| 167 to = query.tags[1][1]; | 167 local to = query:get_child_text("activate"); |
| 168 end | 168 |
| 169 if from ~= nil and to ~= nil and sid ~= nil then | 169 module:log("debug", "received activation request from %s", stanza.attr.from); |
| 170 reply = st.iq({type="result", from=host, to=from}); | 170 if to and sid then |
| 171 reply.attr.id = stanza.attr.id; | |
| 172 end | |
| 173 return reply, from, to, sid; | |
| 174 end | |
| 175 | |
| 176 module:hook("iq-set/host/http://jabber.org/protocol/bytestreams:query", function(event) | |
| 177 local origin, stanza = event.origin, event.stanza; | |
| 178 | |
| 179 module:log("debug", "Received activation request from %s", stanza.attr.from); | |
| 180 local reply, from, to, sid = set_activation(stanza); | |
| 181 if reply ~= nil and from ~= nil and to ~= nil and sid ~= nil then | |
| 182 local sha = sha1(sid .. from .. to, true); | 171 local sha = sha1(sid .. from .. to, true); |
| 183 if transfers[sha] == nil then | 172 if transfers[sha] == nil then |
| 184 module:log("error", "transfers[sha]: nil"); | 173 module:log("error", "transfers[sha]: nil"); |
| 174 origin.send(st.error_reply(stanza, "modify", "item-not-found")); | |
| 185 elseif(transfers[sha] ~= nil and transfers[sha].initiator ~= nil and transfers[sha].target ~= nil) then | 175 elseif(transfers[sha] ~= nil and transfers[sha].initiator ~= nil and transfers[sha].target ~= nil) then |
| 186 origin.send(reply); | |
| 187 transfers[sha].activated = true; | 176 transfers[sha].activated = true; |
| 188 transfers[sha].target:lock_read(false); | 177 transfers[sha].target:lock_read(false); |
| 189 transfers[sha].initiator:lock_read(false); | 178 transfers[sha].initiator:lock_read(false); |
| 179 origin.send(st.reply(stanza)); | |
| 190 else | 180 else |
| 191 module:log("debug", "Both parties were not yet connected"); | 181 module:log("debug", "Both parties were not yet connected"); |
| 192 local message = "Neither party is connected to the proxy"; | 182 local message = "Neither party is connected to the proxy"; |
| 193 if transfers[sha].initiator then | 183 if transfers[sha].initiator then |
| 194 message = "The recipient is not connected to the proxy"; | 184 message = "The recipient is not connected to the proxy"; |
| 195 elseif transfers[sha].target then | 185 elseif transfers[sha].target then |
| 196 message = "The sender (you) is not connected to the proxy"; | 186 message = "The sender (you) is not connected to the proxy"; |
| 197 end | 187 end |
| 198 origin.send(st.error_reply(stanza, "cancel", "not-allowed", message)); | 188 origin.send(st.error_reply(stanza, "cancel", "not-allowed", message)); |
| 199 end | 189 end |
| 200 return true; | |
| 201 else | 190 else |
| 202 module:log("error", "activation failed: sid: %s, initiator: %s, target: %s", tostring(sid), tostring(from), tostring(to)); | 191 module:log("error", "activation failed: sid: %s, initiator: %s, target: %s", tostring(sid), tostring(from), tostring(to)); |
| 203 end | 192 origin.send(st.error_reply(stanza, "modify", "bad-request")); |
| 193 end | |
| 194 return true; | |
| 204 end); | 195 end); |
| 205 | 196 |
| 206 if not connlisteners.register(module.host .. ':proxy65', connlistener) then | 197 if not connlisteners.register(module.host .. ':proxy65', connlistener) then |
| 207 module:log("error", "mod_proxy65: Could not establish a connection listener. Check your configuration please."); | 198 module:log("error", "mod_proxy65: Could not establish a connection listener. Check your configuration please."); |
| 208 module:log("error", "Possibly two proxy65 components are configured to share the same port."); | 199 module:log("error", "Possibly two proxy65 components are configured to share the same port."); |