Mercurial > prosody-modules
annotate mod_proxy65/mod_proxy65.lua @ 64:853c3c7e9936
mod_proxy65: remove the proxy65 folder
author | Thilo Cestonaro <thilo@cestona.ro> |
---|---|
date | Mon, 26 Oct 2009 23:32:53 +0100 |
parents | |
children | a35eb0764ac6 |
rev | line source |
---|---|
64
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
1 -- Copyright (C) 2009 Thilo Cestonaro |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
2 -- |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
3 -- This project is MIT/X11 licensed. Please see the |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
4 -- COPYING file in the source package for more information. |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
5 -- |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
6 |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
7 if module:get_host_type() ~= "component" then |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
8 error("proxy65 should be loaded as a component, please see http://prosody.im/doc/components", 0); |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
9 end |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
10 |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
11 |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
12 local jid_split = require "util.jid".split; |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
13 local st = require "util.stanza"; |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
14 local component_register = require "core.componentmanager".register_component; |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
15 local component_deregister = require "core.componentmanager".deregister_component; |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
16 local configmanager = require "core.configmanager"; |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
17 local config_get = require "core.configmanager".get; |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
18 local connlisteners_register = require "net.connlisteners".register; |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
19 local connlisteners_deregister = require "net.connlisteners".deregister; |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
20 local adns, dns = require "net.adns", require "net.dns"; |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
21 local add_task = require "util.timer".add_task; |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
22 local max_dns_depth = config.get("*", "core", "dns_max_depth") or 3; |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
23 local dns_timeout = config.get("*", "core", "dns_timeout") or 60; |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
24 |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
25 local replies_cache = {}; |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
26 local _host = module:get_host(); |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
27 local _name = "SOCKS5 Bytestreams Service"; |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
28 local _config = config_get(_host, "core", "proxy65"); |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
29 local connlistener = {registered=false}; |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
30 local sessions = {}; |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
31 local component; |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
32 |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
33 if _config == nil then |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
34 _config = {}; |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
35 end |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
36 if _config.port == nil then |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
37 _config.port = 5000; |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
38 end |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
39 |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
40 local function register() |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
41 connlistener = { default_port = _config.port; default_interface = _config.interface }; |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
42 connlistener.registered = connlisteners_register('proxy65', connlistener); |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
43 if(connlistener.registered == false) then |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
44 error("Proxy65: Could not establish a connection listener. Check your configuration please."); |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
45 else |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
46 module:add_item("proxy65", {jid=_host, name=_name}) |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
47 component = component_register(_host, function(origin, stanza) |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
48 local to_node, to_host, to_resource = jid_split(stanza.attr.to); |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
49 if to_node == nil then |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
50 local type = stanza.attr.type; |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
51 if type == "error" or type == "result" then return; end |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
52 if stanza.name == "iq" and type == "get" then |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
53 local xmlns = stanza.tags[1].attr.xmlns |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
54 if xmlns == "http://jabber.org/protocol/disco#info" then |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
55 origin.send(get_disco_info(stanza)); |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
56 return true; |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
57 elseif xmlns == "http://jabber.org/protocol/disco#items" then |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
58 origin.send(get_disco_items(stanza)); |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
59 return true; |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
60 elseif xmlns == "http://jabber.org/protocol/bytestreams" and stanza.tags[1].attr.sid ~= nil then |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
61 origin.send(get_stream_host(stanza)); |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
62 return true; |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
63 end |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
64 end |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
65 end |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
66 return; |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
67 end); |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
68 end |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
69 end |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
70 |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
71 local function getDefaultIP(host) |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
72 local handle; |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
73 handle = adns.lookup(function (reply) |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
74 handle = nil; |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
75 |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
76 -- COMPAT: This is a compromise for all you CNAME-(ab)users :) |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
77 if not (reply and reply[#reply] and reply[#reply].a) then |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
78 local count = max_dns_depth; |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
79 reply = dns.peek(host, "CNAME", "IN"); |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
80 while count > 0 and reply and reply[#reply] and not reply[#reply].a and reply[#reply].cname do |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
81 module:log("debug", "Looking up %s (DNS depth is %d)", tostring(reply[#reply].cname), count); |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
82 reply = dns.peek(reply[#reply].cname, "A", "IN") or dns.peek(reply[#reply].cname, "CNAME", "IN"); |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
83 count = count - 1; |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
84 end |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
85 end |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
86 -- end of CNAME resolving |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
87 |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
88 if reply and reply[#reply] and reply[#reply].a then |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
89 module:log("debug", "DNS reply for %s gives us %s", host, reply[#reply].a); |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
90 _config.interface = reply[#reply].a |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
91 return register(); |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
92 else |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
93 module:log("debug", "DNS lookup failed to get a response for %s", host); |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
94 if host:find(".") ~= nil then |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
95 host = host:gsub("^[^%.]*%.", ""); |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
96 if host:find(".") ~= nil then -- still one dot left? |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
97 return getDefaultIP(host); |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
98 end |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
99 end |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
100 error("Proxy65: Could not get an interface to bind to. Please configure one."); |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
101 end |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
102 end, host, "A", "IN"); |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
103 |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
104 -- Set handler for DNS timeout |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
105 add_task(dns_timeout, function () |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
106 if handle then |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
107 adns.cancel(handle, true); |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
108 end |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
109 end); |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
110 return true; |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
111 end |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
112 |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
113 if _config.interface ~= nil then |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
114 register(); |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
115 else |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
116 getDefaultIP(_host); -- try to DNS lookup module:host() |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
117 end |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
118 |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
119 function new_session(conn) |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
120 local w = function(s) conn.write(s:gsub("\n", "\r\n")); end; |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
121 local session = { conn = conn; |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
122 send = function (t) w(tostring(t)); end; |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
123 print = function (t) w("| "..tostring(t).."\n"); end; |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
124 disconnect = function () conn.close(); end; |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
125 }; |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
126 |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
127 return session; |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
128 end |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
129 |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
130 function connlistener.listener(conn, data) |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
131 local session = sessions[conn]; |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
132 |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
133 if not session then |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
134 session = new_session(conn); |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
135 sessions[conn] = session; |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
136 end |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
137 if data then |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
138 end |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
139 end |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
140 |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
141 function connlistener.disconnect(conn, err) |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
142 |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
143 end |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
144 |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
145 local function get_disco_info(stanza) |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
146 local reply = replies_cache.disco_info; |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
147 if reply == nil then |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
148 reply = st.iq({type='result', from=_host}):query("http://jabber.org/protocol/disco#info") |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
149 :tag("identity", {category='proxy', type='bytestreams', name=_name}):up() |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
150 :tag("feature", {var="http://jabber.org/protocol/bytestreams"}); |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
151 replies_cache.disco_info = reply; |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
152 end |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
153 |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
154 reply.attr.id = stanza.attr.id; |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
155 reply.attr.to = stanza.attr.from; |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
156 return reply; |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
157 end |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
158 |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
159 local function get_disco_items(stanza) |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
160 local reply = replies_cache.disco_items; |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
161 if reply == nil then |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
162 reply = st.iq({type='result', from=_host}):query("http://jabber.org/protocol/disco#items"); |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
163 replies_cache.disco_info = reply; |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
164 end |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
165 |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
166 reply.attr.id = stanza.attr.id; |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
167 reply.attr.to = stanza.attr.from; |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
168 return reply; |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
169 end |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
170 |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
171 local function get_stream_host(stanza) |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
172 local reply = replies_cache.stream_host; |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
173 if reply == nil then |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
174 reply = st.iq({type="result", from=_host}) |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
175 :query("http://jabber.org/protocol/bytestreams") |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
176 :tag("streamhost", {jid=_host, host=_config.interface, port=_config.port}); -- TODO get the correct data |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
177 replies_cache.stream_host = reply; |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
178 end |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
179 |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
180 reply.attr.id = stanza.attr.id; |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
181 reply.attr.to = stanza.attr.from; |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
182 reply.tags[1].attr.sid = stanza.tags[1].attr.sid; |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
183 return reply; |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
184 end |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
185 |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
186 module.unload = function() |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
187 component_deregister(_host); |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
188 connlisteners_deregister("proxy65"); |
853c3c7e9936
mod_proxy65: remove the proxy65 folder
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff
changeset
|
189 end |