Software /
code /
prosody
Annotate
plugins/mod_proxy65.lua @ 3691:07f789ac7e3c
mod_proxy65: Make some globals local.
author | Waqas Hussain <waqas20@gmail.com> |
---|---|
date | Fri, 03 Dec 2010 00:13:30 +0500 |
parent | 3690:8f9fac97e6e6 |
child | 3692:117778c5a7fe |
rev | line source |
---|---|
2137
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1 -- Copyright (C) 2009 Thilo Cestonaro |
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2 -- |
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3 -- This project is MIT/X11 licensed. Please see the |
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
4 -- COPYING file in the source package for more information. |
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
5 -- |
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
6 --[[ |
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
7 * to restart the proxy in the console: e.g. |
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
8 module:unload("proxy65"); |
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
9 > server.removeserver(<proxy65_port>); |
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
10 module:load("proxy65", <proxy65_jid>); |
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
11 ]]-- |
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
12 |
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
13 |
3691
07f789ac7e3c
mod_proxy65: Make some globals local.
Waqas Hussain <waqas20@gmail.com>
parents:
3690
diff
changeset
|
14 local module = module; |
07f789ac7e3c
mod_proxy65: Make some globals local.
Waqas Hussain <waqas20@gmail.com>
parents:
3690
diff
changeset
|
15 local tostring = tostring; |
3377
9328179c9c76
mod_proxy65: Use util.jid.compare() and remove some clutter
Kim Alvefur <zash@zash.se>
parents:
3006
diff
changeset
|
16 local jid_split, jid_join, jid_compare = require "util.jid".split, require "util.jid".join, require "util.jid".compare; |
2137
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
17 local st = require "util.stanza"; |
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
18 local connlisteners = require "net.connlisteners"; |
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
19 local sha1 = require "util.hashes".sha1; |
3004
c20b9fe1624b
mod_proxy65: Use new server.link to link proxied connections, now works with either connection backend
Matthew Wild <mwild1@gmail.com>
parents:
2729
diff
changeset
|
20 local server = require "net.server"; |
2137
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
21 |
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
22 local host, name = module:get_host(), "SOCKS5 Bytestreams Service"; |
3689
2ca76b4f6404
mod_proxy65: Allow loading on normal hosts.
Waqas Hussain <waqas20@gmail.com>
parents:
3688
diff
changeset
|
23 local sessions, transfers, replies_cache = {}, {}, {}; |
2137
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
24 |
3607
e1259b6d7560
mod_proxy65: Use module:get_option() instead of configmanager.
Waqas Hussain <waqas20@gmail.com>
parents:
3604
diff
changeset
|
25 local proxy_port = module:get_option("proxy65_port") or 5000; |
e1259b6d7560
mod_proxy65: Use module:get_option() instead of configmanager.
Waqas Hussain <waqas20@gmail.com>
parents:
3604
diff
changeset
|
26 local proxy_interface = module:get_option("proxy65_interface") or "*"; |
e1259b6d7560
mod_proxy65: Use module:get_option() instead of configmanager.
Waqas Hussain <waqas20@gmail.com>
parents:
3604
diff
changeset
|
27 local proxy_address = module:get_option("proxy65_address") or (proxy_interface ~= "*" and proxy_interface) or host; |
e1259b6d7560
mod_proxy65: Use module:get_option() instead of configmanager.
Waqas Hussain <waqas20@gmail.com>
parents:
3604
diff
changeset
|
28 local proxy_acl = module:get_option("proxy65_acl"); |
3004
c20b9fe1624b
mod_proxy65: Use new server.link to link proxied connections, now works with either connection backend
Matthew Wild <mwild1@gmail.com>
parents:
2729
diff
changeset
|
29 local max_buffer_size = 4096; |
2137
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
30 |
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
31 local connlistener = { default_port = proxy_port, default_interface = proxy_interface, default_mode = "*a" }; |
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
32 |
2244
730038d3e9e3
mod_proxy65: Update listener callback names for new server API
sjoerd.simons@collabora.co.uk
parents:
2138
diff
changeset
|
33 function connlistener.onincoming(conn, data) |
2137
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
34 local session = sessions[conn] or {}; |
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
35 |
3690
8f9fac97e6e6
mod_proxy65: :sub(n):byte() -> :byte(n).
Waqas Hussain <waqas20@gmail.com>
parents:
3689
diff
changeset
|
36 if session.setup == nil and data ~= nil and data:byte(1) == 0x05 and data:len() > 2 then |
8f9fac97e6e6
mod_proxy65: :sub(n):byte() -> :byte(n).
Waqas Hussain <waqas20@gmail.com>
parents:
3689
diff
changeset
|
37 local nmethods = data:byte(2); |
2137
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
38 local methods = data:sub(3); |
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
39 local supported = false; |
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
40 for i=1, nmethods, 1 do |
3690
8f9fac97e6e6
mod_proxy65: :sub(n):byte() -> :byte(n).
Waqas Hussain <waqas20@gmail.com>
parents:
3689
diff
changeset
|
41 if(methods:byte(i) == 0x00) then -- 0x00 == method: NO AUTH |
2137
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
42 supported = true; |
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
43 break; |
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
44 end |
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
45 end |
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
46 if(supported) then |
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
47 module:log("debug", "new session found ... ") |
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
48 session.setup = true; |
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
49 sessions[conn] = session; |
2138
8bb1a2d82896
mod_proxy65: Update for new net.server API, untested
Matthew Wild <mwild1@gmail.com>
parents:
2137
diff
changeset
|
50 conn:write(string.char(5, 0)); |
2137
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
51 end |
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
52 return; |
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
53 end |
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
54 if session.setup then |
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
55 if session.sha ~= nil and transfers[session.sha] ~= nil then |
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
56 local sha = session.sha; |
2310
e74c6740a42b
mod_proxy65: Make the proxying bidirectional
Sjoerd Simons <sjoerd.simons@collabora.co.uk>
parents:
2309
diff
changeset
|
57 if transfers[sha].activated == true and transfers[sha].target ~= nil then |
e74c6740a42b
mod_proxy65: Make the proxying bidirectional
Sjoerd Simons <sjoerd.simons@collabora.co.uk>
parents:
2309
diff
changeset
|
58 if transfers[sha].initiator == conn then |
e74c6740a42b
mod_proxy65: Make the proxying bidirectional
Sjoerd Simons <sjoerd.simons@collabora.co.uk>
parents:
2309
diff
changeset
|
59 transfers[sha].target:write(data); |
e74c6740a42b
mod_proxy65: Make the proxying bidirectional
Sjoerd Simons <sjoerd.simons@collabora.co.uk>
parents:
2309
diff
changeset
|
60 else |
e74c6740a42b
mod_proxy65: Make the proxying bidirectional
Sjoerd Simons <sjoerd.simons@collabora.co.uk>
parents:
2309
diff
changeset
|
61 transfers[sha].initiator:write(data); |
e74c6740a42b
mod_proxy65: Make the proxying bidirectional
Sjoerd Simons <sjoerd.simons@collabora.co.uk>
parents:
2309
diff
changeset
|
62 end |
2137
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
63 return; |
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
64 end |
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
65 end |
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
66 if data ~= nil and data:len() == 0x2F and -- 40 == length of SHA1 HASH, and 7 other bytes => 47 => 0x2F |
3690
8f9fac97e6e6
mod_proxy65: :sub(n):byte() -> :byte(n).
Waqas Hussain <waqas20@gmail.com>
parents:
3689
diff
changeset
|
67 data:byte(1) == 0x05 and -- SOCKS5 has 5 in first byte |
8f9fac97e6e6
mod_proxy65: :sub(n):byte() -> :byte(n).
Waqas Hussain <waqas20@gmail.com>
parents:
3689
diff
changeset
|
68 data:byte(2) == 0x01 and -- CMD must be 1 |
8f9fac97e6e6
mod_proxy65: :sub(n):byte() -> :byte(n).
Waqas Hussain <waqas20@gmail.com>
parents:
3689
diff
changeset
|
69 data:byte(3) == 0x00 and -- RSV must be 0 |
8f9fac97e6e6
mod_proxy65: :sub(n):byte() -> :byte(n).
Waqas Hussain <waqas20@gmail.com>
parents:
3689
diff
changeset
|
70 data:byte(4) == 0x03 and -- ATYP must be 3 |
8f9fac97e6e6
mod_proxy65: :sub(n):byte() -> :byte(n).
Waqas Hussain <waqas20@gmail.com>
parents:
3689
diff
changeset
|
71 data:byte(5) == 40 and -- SHA1 HASH length must be 40 (0x28) |
8f9fac97e6e6
mod_proxy65: :sub(n):byte() -> :byte(n).
Waqas Hussain <waqas20@gmail.com>
parents:
3689
diff
changeset
|
72 data:byte(-2) == 0x00 and -- PORT must be 0, size 2 byte |
8f9fac97e6e6
mod_proxy65: :sub(n):byte() -> :byte(n).
Waqas Hussain <waqas20@gmail.com>
parents:
3689
diff
changeset
|
73 data:byte(-1) == 0x00 |
2137
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
74 then |
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
75 local sha = data:sub(6, 45); -- second param is not count! it's the ending index (included!) |
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
76 if transfers[sha] == nil then |
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
77 transfers[sha] = {}; |
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
78 transfers[sha].activated = false; |
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
79 transfers[sha].target = conn; |
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
80 session.sha = sha; |
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
81 module:log("debug", "target connected ... "); |
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
82 elseif transfers[sha].target ~= nil then |
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
83 transfers[sha].initiator = conn; |
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
84 session.sha = sha; |
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
85 module:log("debug", "initiator connected ... "); |
3004
c20b9fe1624b
mod_proxy65: Use new server.link to link proxied connections, now works with either connection backend
Matthew Wild <mwild1@gmail.com>
parents:
2729
diff
changeset
|
86 server.link(conn, transfers[sha].target, max_buffer_size); |
c20b9fe1624b
mod_proxy65: Use new server.link to link proxied connections, now works with either connection backend
Matthew Wild <mwild1@gmail.com>
parents:
2729
diff
changeset
|
87 server.link(transfers[sha].target, conn, max_buffer_size); |
2137
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
88 end |
2138
8bb1a2d82896
mod_proxy65: Update for new net.server API, untested
Matthew Wild <mwild1@gmail.com>
parents:
2137
diff
changeset
|
89 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) |
2311
5fe837ebe542
mod_proxy65: Don't read data from the connection untill the proxying is activated
Sjoerd Simons <sjoerd.simons@collabora.co.uk>
parents:
2310
diff
changeset
|
90 conn:lock_read(true) |
2137
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
91 else |
2272
9c3564117b24
mod_proxy65: Fix log:module -> module:log :)
Matthew Wild <mwild1@gmail.com>
parents:
2249
diff
changeset
|
92 module:log("warn", "Neither data transfer nor initial connect of a participator of a transfer.") |
2729
7e0c35713bf5
mod_proxy65: Fix for old-style closing of connections (another source of tracebacks with libevent enabled)
Matthew Wild <mwild1@gmail.com>
parents:
2320
diff
changeset
|
93 conn:close(); |
2137
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
94 end |
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
95 else |
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
96 if data ~= nil then |
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
97 module:log("warn", "unknown connection with no authentication data -> closing it"); |
2729
7e0c35713bf5
mod_proxy65: Fix for old-style closing of connections (another source of tracebacks with libevent enabled)
Matthew Wild <mwild1@gmail.com>
parents:
2320
diff
changeset
|
98 conn:close(); |
2137
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
99 end |
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
100 end |
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
101 end |
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
102 |
2244
730038d3e9e3
mod_proxy65: Update listener callback names for new server API
sjoerd.simons@collabora.co.uk
parents:
2138
diff
changeset
|
103 function connlistener.ondisconnect(conn, err) |
2137
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
104 local session = sessions[conn]; |
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
105 if session then |
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
106 if session.sha and transfers[session.sha] then |
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
107 local initiator, target = transfers[session.sha].initiator, transfers[session.sha].target; |
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
108 if initiator == conn and target ~= nil then |
2729
7e0c35713bf5
mod_proxy65: Fix for old-style closing of connections (another source of tracebacks with libevent enabled)
Matthew Wild <mwild1@gmail.com>
parents:
2320
diff
changeset
|
109 target:close(); |
2137
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
110 elseif target == conn and initiator ~= nil then |
2729
7e0c35713bf5
mod_proxy65: Fix for old-style closing of connections (another source of tracebacks with libevent enabled)
Matthew Wild <mwild1@gmail.com>
parents:
2320
diff
changeset
|
111 initiator:close(); |
2137
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
112 end |
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
113 transfers[session.sha] = nil; |
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
114 end |
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
115 -- Clean up any session-related stuff here |
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
116 sessions[conn] = nil; |
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
117 end |
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
118 end |
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
119 |
3688
f7de887ea0be
mod_proxy65: Updated to use sub-events. Now only hooks what it needs to.
Waqas Hussain <waqas20@gmail.com>
parents:
3676
diff
changeset
|
120 module:hook("iq-get/host/http://jabber.org/protocol/disco#info:query", function(event) |
f7de887ea0be
mod_proxy65: Updated to use sub-events. Now only hooks what it needs to.
Waqas Hussain <waqas20@gmail.com>
parents:
3676
diff
changeset
|
121 local origin, stanza = event.origin, event.stanza; |
2137
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
122 local reply = replies_cache.disco_info; |
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
123 if reply == nil then |
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
124 reply = st.iq({type='result', from=host}):query("http://jabber.org/protocol/disco#info") |
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
125 :tag("identity", {category='proxy', type='bytestreams', name=name}):up() |
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
126 :tag("feature", {var="http://jabber.org/protocol/bytestreams"}); |
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
127 replies_cache.disco_info = reply; |
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
128 end |
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
129 |
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
130 reply.attr.id = stanza.attr.id; |
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
131 reply.attr.to = stanza.attr.from; |
3688
f7de887ea0be
mod_proxy65: Updated to use sub-events. Now only hooks what it needs to.
Waqas Hussain <waqas20@gmail.com>
parents:
3676
diff
changeset
|
132 origin.send(reply); |
f7de887ea0be
mod_proxy65: Updated to use sub-events. Now only hooks what it needs to.
Waqas Hussain <waqas20@gmail.com>
parents:
3676
diff
changeset
|
133 return true; |
f7de887ea0be
mod_proxy65: Updated to use sub-events. Now only hooks what it needs to.
Waqas Hussain <waqas20@gmail.com>
parents:
3676
diff
changeset
|
134 end, -1); |
2137
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
135 |
3688
f7de887ea0be
mod_proxy65: Updated to use sub-events. Now only hooks what it needs to.
Waqas Hussain <waqas20@gmail.com>
parents:
3676
diff
changeset
|
136 module:hook("iq-get/host/http://jabber.org/protocol/disco#items:query", function(event) |
f7de887ea0be
mod_proxy65: Updated to use sub-events. Now only hooks what it needs to.
Waqas Hussain <waqas20@gmail.com>
parents:
3676
diff
changeset
|
137 local origin, stanza = event.origin, event.stanza; |
2137
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
138 local reply = replies_cache.disco_items; |
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
139 if reply == nil then |
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
140 reply = st.iq({type='result', from=host}):query("http://jabber.org/protocol/disco#items"); |
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
141 replies_cache.disco_items = reply; |
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
142 end |
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
143 |
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
144 reply.attr.id = stanza.attr.id; |
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
145 reply.attr.to = stanza.attr.from; |
3688
f7de887ea0be
mod_proxy65: Updated to use sub-events. Now only hooks what it needs to.
Waqas Hussain <waqas20@gmail.com>
parents:
3676
diff
changeset
|
146 origin.send(reply); |
f7de887ea0be
mod_proxy65: Updated to use sub-events. Now only hooks what it needs to.
Waqas Hussain <waqas20@gmail.com>
parents:
3676
diff
changeset
|
147 return true; |
f7de887ea0be
mod_proxy65: Updated to use sub-events. Now only hooks what it needs to.
Waqas Hussain <waqas20@gmail.com>
parents:
3676
diff
changeset
|
148 end, -1); |
2137
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
149 |
3688
f7de887ea0be
mod_proxy65: Updated to use sub-events. Now only hooks what it needs to.
Waqas Hussain <waqas20@gmail.com>
parents:
3676
diff
changeset
|
150 module:hook("iq-get/host/http://jabber.org/protocol/bytestreams:query", function(event) |
f7de887ea0be
mod_proxy65: Updated to use sub-events. Now only hooks what it needs to.
Waqas Hussain <waqas20@gmail.com>
parents:
3676
diff
changeset
|
151 local origin, stanza = event.origin, event.stanza; |
2137
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
152 local reply = replies_cache.stream_host; |
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
153 local err_reply = replies_cache.stream_host_err; |
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
154 local sid = stanza.tags[1].attr.sid; |
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
155 local allow = false; |
3377
9328179c9c76
mod_proxy65: Use util.jid.compare() and remove some clutter
Kim Alvefur <zash@zash.se>
parents:
3006
diff
changeset
|
156 local jid = stanza.attr.from; |
2137
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
157 |
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
158 if proxy_acl and #proxy_acl > 0 then |
3377
9328179c9c76
mod_proxy65: Use util.jid.compare() and remove some clutter
Kim Alvefur <zash@zash.se>
parents:
3006
diff
changeset
|
159 for _, acl in ipairs(proxy_acl) do |
9328179c9c76
mod_proxy65: Use util.jid.compare() and remove some clutter
Kim Alvefur <zash@zash.se>
parents:
3006
diff
changeset
|
160 if jid_compare(jid, acl) then allow = true; end |
2137
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
161 end |
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
162 else |
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
163 allow = true; |
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
164 end |
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
165 if allow == true then |
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
166 if reply == nil then |
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
167 reply = st.iq({type="result", from=host}) |
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
168 :query("http://jabber.org/protocol/bytestreams") |
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
169 :tag("streamhost", {jid=host, host=proxy_address, port=proxy_port}); |
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
170 replies_cache.stream_host = reply; |
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
171 end |
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
172 else |
3377
9328179c9c76
mod_proxy65: Use util.jid.compare() and remove some clutter
Kim Alvefur <zash@zash.se>
parents:
3006
diff
changeset
|
173 module:log("warn", "Denying use of proxy for %s", tostring(jid)); |
2137
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
174 if err_reply == nil then |
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
175 err_reply = st.iq({type="error", from=host}) |
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
176 :query("http://jabber.org/protocol/bytestreams") |
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
177 :tag("error", {code='403', type='auth'}) |
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
178 :tag("forbidden", {xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'}); |
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
179 replies_cache.stream_host_err = err_reply; |
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
180 end |
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
181 reply = err_reply; |
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
182 end |
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
183 reply.attr.id = stanza.attr.id; |
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
184 reply.attr.to = stanza.attr.from; |
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
185 reply.tags[1].attr.sid = sid; |
3688
f7de887ea0be
mod_proxy65: Updated to use sub-events. Now only hooks what it needs to.
Waqas Hussain <waqas20@gmail.com>
parents:
3676
diff
changeset
|
186 origin.send(reply); |
f7de887ea0be
mod_proxy65: Updated to use sub-events. Now only hooks what it needs to.
Waqas Hussain <waqas20@gmail.com>
parents:
3676
diff
changeset
|
187 return true; |
f7de887ea0be
mod_proxy65: Updated to use sub-events. Now only hooks what it needs to.
Waqas Hussain <waqas20@gmail.com>
parents:
3676
diff
changeset
|
188 end); |
2137
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
189 |
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
190 module.unload = function() |
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
191 connlisteners.deregister(module.host .. ':proxy65'); |
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
192 end |
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
193 |
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
194 local function set_activation(stanza) |
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
195 local from, to, sid, reply = nil; |
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
196 from = stanza.attr.from; |
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
197 if stanza.tags[1] ~= nil and tostring(stanza.tags[1].name) == "query" then |
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
198 if stanza.tags[1].attr ~= nil then |
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
199 sid = stanza.tags[1].attr.sid; |
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
200 end |
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
201 if stanza.tags[1].tags[1] ~= nil and tostring(stanza.tags[1].tags[1].name) == "activate" then |
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
202 to = stanza.tags[1].tags[1][1]; |
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
203 end |
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
204 end |
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
205 if from ~= nil and to ~= nil and sid ~= nil then |
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
206 reply = st.iq({type="result", from=host, to=from}); |
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
207 reply.attr.id = stanza.attr.id; |
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
208 end |
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
209 return reply, from, to, sid; |
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
210 end |
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
211 |
3688
f7de887ea0be
mod_proxy65: Updated to use sub-events. Now only hooks what it needs to.
Waqas Hussain <waqas20@gmail.com>
parents:
3676
diff
changeset
|
212 module:hook("iq-set/host/http://jabber.org/protocol/bytestreams:query", function(event) |
3558
f1201ff060b7
mod_proxy65: Use "iq/host" event for hooking stanzas instead of the component stanza handler.
Waqas Hussain <waqas20@gmail.com>
parents:
3377
diff
changeset
|
213 local origin, stanza = event.origin, event.stanza; |
3688
f7de887ea0be
mod_proxy65: Updated to use sub-events. Now only hooks what it needs to.
Waqas Hussain <waqas20@gmail.com>
parents:
3676
diff
changeset
|
214 |
f7de887ea0be
mod_proxy65: Updated to use sub-events. Now only hooks what it needs to.
Waqas Hussain <waqas20@gmail.com>
parents:
3676
diff
changeset
|
215 module:log("debug", "Received activation request from %s", stanza.attr.from); |
f7de887ea0be
mod_proxy65: Updated to use sub-events. Now only hooks what it needs to.
Waqas Hussain <waqas20@gmail.com>
parents:
3676
diff
changeset
|
216 local reply, from, to, sid = set_activation(stanza); |
f7de887ea0be
mod_proxy65: Updated to use sub-events. Now only hooks what it needs to.
Waqas Hussain <waqas20@gmail.com>
parents:
3676
diff
changeset
|
217 if reply ~= nil and from ~= nil and to ~= nil and sid ~= nil then |
f7de887ea0be
mod_proxy65: Updated to use sub-events. Now only hooks what it needs to.
Waqas Hussain <waqas20@gmail.com>
parents:
3676
diff
changeset
|
218 local sha = sha1(sid .. from .. to, true); |
f7de887ea0be
mod_proxy65: Updated to use sub-events. Now only hooks what it needs to.
Waqas Hussain <waqas20@gmail.com>
parents:
3676
diff
changeset
|
219 if transfers[sha] == nil then |
f7de887ea0be
mod_proxy65: Updated to use sub-events. Now only hooks what it needs to.
Waqas Hussain <waqas20@gmail.com>
parents:
3676
diff
changeset
|
220 module:log("error", "transfers[sha]: nil"); |
f7de887ea0be
mod_proxy65: Updated to use sub-events. Now only hooks what it needs to.
Waqas Hussain <waqas20@gmail.com>
parents:
3676
diff
changeset
|
221 elseif(transfers[sha] ~= nil and transfers[sha].initiator ~= nil and transfers[sha].target ~= nil) then |
f7de887ea0be
mod_proxy65: Updated to use sub-events. Now only hooks what it needs to.
Waqas Hussain <waqas20@gmail.com>
parents:
3676
diff
changeset
|
222 origin.send(reply); |
f7de887ea0be
mod_proxy65: Updated to use sub-events. Now only hooks what it needs to.
Waqas Hussain <waqas20@gmail.com>
parents:
3676
diff
changeset
|
223 transfers[sha].activated = true; |
f7de887ea0be
mod_proxy65: Updated to use sub-events. Now only hooks what it needs to.
Waqas Hussain <waqas20@gmail.com>
parents:
3676
diff
changeset
|
224 transfers[sha].target:lock_read(false); |
f7de887ea0be
mod_proxy65: Updated to use sub-events. Now only hooks what it needs to.
Waqas Hussain <waqas20@gmail.com>
parents:
3676
diff
changeset
|
225 transfers[sha].initiator:lock_read(false); |
3559
0708d42ef0d4
mod_proxy65: Removed useless checks from the event handler.
Waqas Hussain <waqas20@gmail.com>
parents:
3558
diff
changeset
|
226 else |
3688
f7de887ea0be
mod_proxy65: Updated to use sub-events. Now only hooks what it needs to.
Waqas Hussain <waqas20@gmail.com>
parents:
3676
diff
changeset
|
227 module:log("debug", "Both parties were not yet connected"); |
f7de887ea0be
mod_proxy65: Updated to use sub-events. Now only hooks what it needs to.
Waqas Hussain <waqas20@gmail.com>
parents:
3676
diff
changeset
|
228 local message = "Neither party is connected to the proxy"; |
f7de887ea0be
mod_proxy65: Updated to use sub-events. Now only hooks what it needs to.
Waqas Hussain <waqas20@gmail.com>
parents:
3676
diff
changeset
|
229 if transfers[sha].initiator then |
f7de887ea0be
mod_proxy65: Updated to use sub-events. Now only hooks what it needs to.
Waqas Hussain <waqas20@gmail.com>
parents:
3676
diff
changeset
|
230 message = "The recipient is not connected to the proxy"; |
f7de887ea0be
mod_proxy65: Updated to use sub-events. Now only hooks what it needs to.
Waqas Hussain <waqas20@gmail.com>
parents:
3676
diff
changeset
|
231 elseif transfers[sha].target then |
f7de887ea0be
mod_proxy65: Updated to use sub-events. Now only hooks what it needs to.
Waqas Hussain <waqas20@gmail.com>
parents:
3676
diff
changeset
|
232 message = "The sender (you) is not connected to the proxy"; |
f7de887ea0be
mod_proxy65: Updated to use sub-events. Now only hooks what it needs to.
Waqas Hussain <waqas20@gmail.com>
parents:
3676
diff
changeset
|
233 end |
f7de887ea0be
mod_proxy65: Updated to use sub-events. Now only hooks what it needs to.
Waqas Hussain <waqas20@gmail.com>
parents:
3676
diff
changeset
|
234 origin.send(st.error_reply(stanza, "cancel", "not-allowed", message)); |
3559
0708d42ef0d4
mod_proxy65: Removed useless checks from the event handler.
Waqas Hussain <waqas20@gmail.com>
parents:
3558
diff
changeset
|
235 end |
3688
f7de887ea0be
mod_proxy65: Updated to use sub-events. Now only hooks what it needs to.
Waqas Hussain <waqas20@gmail.com>
parents:
3676
diff
changeset
|
236 return true; |
f7de887ea0be
mod_proxy65: Updated to use sub-events. Now only hooks what it needs to.
Waqas Hussain <waqas20@gmail.com>
parents:
3676
diff
changeset
|
237 else |
f7de887ea0be
mod_proxy65: Updated to use sub-events. Now only hooks what it needs to.
Waqas Hussain <waqas20@gmail.com>
parents:
3676
diff
changeset
|
238 module:log("error", "activation failed: sid: %s, initiator: %s, target: %s", tostring(sid), tostring(from), tostring(to)); |
2137
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
239 end |
3688
f7de887ea0be
mod_proxy65: Updated to use sub-events. Now only hooks what it needs to.
Waqas Hussain <waqas20@gmail.com>
parents:
3676
diff
changeset
|
240 end); |
2137
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
241 |
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
242 if not connlisteners.register(module.host .. ':proxy65', connlistener) then |
2305
7ddd00260808
mod_proxy65: Replace error() calls with module:log("error", ...)
Matthew Wild <mwild1@gmail.com>
parents:
2273
diff
changeset
|
243 module:log("error", "mod_proxy65: Could not establish a connection listener. Check your configuration please."); |
7ddd00260808
mod_proxy65: Replace error() calls with module:log("error", ...)
Matthew Wild <mwild1@gmail.com>
parents:
2273
diff
changeset
|
244 module:log("error", "Possibly two proxy65 components are configured to share the same port."); |
2137
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
245 end |
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
246 |
c5d87a3316f8
mod_proxy65: Import from prosody-modules, thanks Ephraim :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
247 connlisteners.start(module.host .. ':proxy65'); |