Comparison

mod_proxy65/mod_proxy65.lua @ 83:9d92db30235f

mod_proxy65: make it work from external initiators, too
author Thilo Cestonaro <thilo@cestona.ro>
date Sun, 01 Nov 2009 21:28:14 +0100
parent 82:608dc38b6580
child 95:e704834c5613
comparison
equal deleted inserted replaced
82:608dc38b6580 83:9d92db30235f
1 -- Copyright (C) 2009 Thilo Cestonaro 1 -- Copyright (C) 2009 Thilo Cestonaro
2 -- 2 --
3 -- This project is MIT/X11 licensed. Please see the 3 -- This project is MIT/X11 licensed. Please see the
4 -- COPYING file in the source package for more information. 4 -- COPYING file in the source package for more information.
5 -- 5 --
6 --[[
7 * to restart the proxy in the console: e.g.
8 module:unload("proxy65");
9 > server.removeserver(<proxy65_port>);
10 module:load("proxy65", <proxy65_jid>);
11 ]]--
6 12
7 if module:get_host_type() ~= "component" then 13 if module:get_host_type() ~= "component" then
8 error("proxy65 should be loaded as a component, please see http://prosody.im/doc/components", 0); 14 error("proxy65 should be loaded as a component, please see http://prosody.im/doc/components", 0);
9 end 15 end
10 16
74 transfers[sha].initiator = conn; 80 transfers[sha].initiator = conn;
75 session.sha = sha; 81 session.sha = sha;
76 module:log("debug", "initiator connected ... "); 82 module:log("debug", "initiator connected ... ");
77 end 83 end
78 conn.write(string.char(5, 0, 0, 3, sha:len()) .. sha .. string.char(0, 0)); -- VER, REP, RSV, ATYP, BND.ADDR (sha), BND.PORT (2 Byte) 84 conn.write(string.char(5, 0, 0, 3, sha:len()) .. sha .. string.char(0, 0)); -- VER, REP, RSV, ATYP, BND.ADDR (sha), BND.PORT (2 Byte)
85 else
86 log:module("warn", "Neither data transfer nor initial connect of a participator of a transfer.")
87 conn.close();
79 end 88 end
80 else 89 else
81 if data ~= nil then 90 if data ~= nil then
82 module:log("debug", "unknown connection with no authentication data -> closing it"); 91 module:log("warn", "unknown connection with no authentication data -> closing it");
83 conn.close(); 92 conn.close();
84 end 93 end
85 end 94 end
86 end 95 end
87 96
88 function connlistener.disconnect(conn, err) 97 function connlistener.disconnect(conn, err)
89 local session = sessions[conn]; 98 local session = sessions[conn];
90 if session then 99 if session then
91 if session.sha and transfers[session.sha] then 100 if session.sha and transfers[session.sha] then
92 local initiator, target = transfers[session.sha].initiator, transfers[session.sha].target; 101 local initiator, target = transfers[session.sha].initiator, transfers[session.sha].target;
93 if initiator == conn then 102 if initiator == conn and target ~= nil then
94 target.close(); 103 target.close();
95 elseif target == conn then 104 elseif target == conn and initiator ~= nil then
96 initiator.close(); 105 initiator.close();
97 end 106 end
98 end 107 end
99 -- Clean up any session-related stuff here 108 -- Clean up any session-related stuff here
100 sessions[conn] = nil; 109 sessions[conn] = nil;
173 :query("http://jabber.org/protocol/bytestreams") 182 :query("http://jabber.org/protocol/bytestreams")
174 :tag("streamhost", {jid=host, host=proxy_address, port=proxy_port}); 183 :tag("streamhost", {jid=host, host=proxy_address, port=proxy_port});
175 replies_cache.stream_host = reply; 184 replies_cache.stream_host = reply;
176 end 185 end
177 else 186 else
178 module:log("debug", "Denying use of proxy for %s", tostring(_jid_join(jid_node, jid_host, jid_resource))); 187 module:log("warn", "Denying use of proxy for %s", tostring(_jid_join(jid_node, jid_host, jid_resource)));
179 if err_reply == nil then 188 if err_reply == nil then
180 err_reply = st.iq({type="error", from=host}) 189 err_reply = st.iq({type="error", from=host})
181 :query("http://jabber.org/protocol/bytestreams") 190 :query("http://jabber.org/protocol/bytestreams")
182 :tag("error", {code='403', type='auth'}) 191 :tag("error", {code='403', type='auth'})
183 :tag("forbidden", {xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'}); 192 :tag("forbidden", {xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'});
206 if stanza.tags[1].tags[1] ~= nil and tostring(stanza.tags[1].tags[1].name) == "activate" then 215 if stanza.tags[1].tags[1] ~= nil and tostring(stanza.tags[1].tags[1].name) == "activate" then
207 to = stanza.tags[1].tags[1][1]; 216 to = stanza.tags[1].tags[1][1];
208 end 217 end
209 end 218 end
210 if from ~= nil and to ~= nil and sid ~= nil then 219 if from ~= nil and to ~= nil and sid ~= nil then
211 reply = st.iq({type="result", from=host}); 220 reply = st.iq({type="result", from=host, to=from});
212 reply.attr.id = stanza.attr.id; 221 reply.attr.id = stanza.attr.id;
213 end 222 end
214 return reply, from, to, sid; 223 return reply, from, to, sid;
215 end 224 end
216 225
239 module:log("error", "transfers[sha]: nil"); 248 module:log("error", "transfers[sha]: nil");
240 elseif(transfers[sha] ~= nil and transfers[sha].initiator ~= nil and transfers[sha].target ~= nil) then 249 elseif(transfers[sha] ~= nil and transfers[sha].initiator ~= nil and transfers[sha].target ~= nil) then
241 origin.send(reply); 250 origin.send(reply);
242 transfers[sha].activated = true; 251 transfers[sha].activated = true;
243 end 252 end
253 else
254 module:log("error", "activation failed: sid: %s, initiator: %s, target: %s", tostring(sid), tostring(from), tostring(to));
244 end 255 end
245 end 256 end
246 end 257 end
247 return; 258 return;
248 end 259 end