annotate mod_proxy65/proxy65/mod_proxy65.lua @ 31:a0dfa3e5883c

mod_proxy65: new component proxy65; currently only disco#info and disco#items done
author Thilo Cestonaro <thilo@cestona.ro>
date Mon, 12 Oct 2009 23:08:43 +0200
parents
children d0f5a16e7a66
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
31
a0dfa3e5883c mod_proxy65: new component proxy65; currently only disco#info and disco#items done
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
1 -- Copyright (C) 2009 Thilo Cestonaro
a0dfa3e5883c mod_proxy65: new component proxy65; currently only disco#info and disco#items done
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
2 --
a0dfa3e5883c mod_proxy65: new component proxy65; currently only disco#info and disco#items done
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
3 -- This project is MIT/X11 licensed. Please see the
a0dfa3e5883c mod_proxy65: new component proxy65; currently only disco#info and disco#items done
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
4 -- COPYING file in the source package for more information.
a0dfa3e5883c mod_proxy65: new component proxy65; currently only disco#info and disco#items done
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
5 --
a0dfa3e5883c mod_proxy65: new component proxy65; currently only disco#info and disco#items done
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
6
a0dfa3e5883c mod_proxy65: new component proxy65; currently only disco#info and disco#items done
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
7 if module:get_host_type() ~= "component" then
a0dfa3e5883c mod_proxy65: new component proxy65; currently only disco#info and disco#items done
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);
a0dfa3e5883c mod_proxy65: new component proxy65; currently only disco#info and disco#items done
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
9 end
a0dfa3e5883c mod_proxy65: new component proxy65; currently only disco#info and disco#items done
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
10
a0dfa3e5883c mod_proxy65: new component proxy65; currently only disco#info and disco#items done
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
11 local _host = module:get_host();
a0dfa3e5883c mod_proxy65: new component proxy65; currently only disco#info and disco#items done
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
12 local _name = "SOCKS5 Bytestreams Service";
a0dfa3e5883c mod_proxy65: new component proxy65; currently only disco#info and disco#items done
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
13
a0dfa3e5883c mod_proxy65: new component proxy65; currently only disco#info and disco#items done
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
14 local jid_split = require "util.jid".split;
a0dfa3e5883c mod_proxy65: new component proxy65; currently only disco#info and disco#items done
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
15 local st = require "util.stanza";
a0dfa3e5883c mod_proxy65: new component proxy65; currently only disco#info and disco#items done
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
16 local register_component = require "core.componentmanager".register_component;
a0dfa3e5883c mod_proxy65: new component proxy65; currently only disco#info and disco#items done
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
17 local deregister_component = require "core.componentmanager".deregister_component;
a0dfa3e5883c mod_proxy65: new component proxy65; currently only disco#info and disco#items done
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
18 local configmanager = require "core.configmanager";
a0dfa3e5883c mod_proxy65: new component proxy65; currently only disco#info and disco#items done
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
19
a0dfa3e5883c mod_proxy65: new component proxy65; currently only disco#info and disco#items done
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
20 local replies_cache = {};
a0dfa3e5883c mod_proxy65: new component proxy65; currently only disco#info and disco#items done
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
21
a0dfa3e5883c mod_proxy65: new component proxy65; currently only disco#info and disco#items done
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
22 --[[
a0dfa3e5883c mod_proxy65: new component proxy65; currently only disco#info and disco#items done
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
23 <iq type='result'
a0dfa3e5883c mod_proxy65: new component proxy65; currently only disco#info and disco#items done
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
24 from='streamhostproxy.example.net'
a0dfa3e5883c mod_proxy65: new component proxy65; currently only disco#info and disco#items done
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
25 to='initiator@example.com/foo'
a0dfa3e5883c mod_proxy65: new component proxy65; currently only disco#info and disco#items done
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
26 id='proxy_info'>
a0dfa3e5883c mod_proxy65: new component proxy65; currently only disco#info and disco#items done
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
27 <query xmlns='http://jabber.org/protocol/disco#info'>
a0dfa3e5883c mod_proxy65: new component proxy65; currently only disco#info and disco#items done
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
28 <identity category='proxy'
a0dfa3e5883c mod_proxy65: new component proxy65; currently only disco#info and disco#items done
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
29 type='bytestreams'
a0dfa3e5883c mod_proxy65: new component proxy65; currently only disco#info and disco#items done
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
30 name='SOCKS5 Bytestreams Service'/>
a0dfa3e5883c mod_proxy65: new component proxy65; currently only disco#info and disco#items done
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
31 <feature var='http://jabber.org/protocol/bytestreams'/>
a0dfa3e5883c mod_proxy65: new component proxy65; currently only disco#info and disco#items done
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
32 </query>
a0dfa3e5883c mod_proxy65: new component proxy65; currently only disco#info and disco#items done
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
33 </iq>
a0dfa3e5883c mod_proxy65: new component proxy65; currently only disco#info and disco#items done
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
34 ]]--
a0dfa3e5883c mod_proxy65: new component proxy65; currently only disco#info and disco#items done
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
35 local function get_disco_info(stanza)
a0dfa3e5883c mod_proxy65: new component proxy65; currently only disco#info and disco#items done
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
36 local reply = replies_cache.disco_info;
a0dfa3e5883c mod_proxy65: new component proxy65; currently only disco#info and disco#items done
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
37 if reply == nil then
a0dfa3e5883c mod_proxy65: new component proxy65; currently only disco#info and disco#items done
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
38 reply = st.iq({type='result', from=_host}):query("http://jabber.org/protocol/disco#info")
a0dfa3e5883c mod_proxy65: new component proxy65; currently only disco#info and disco#items done
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
39 :tag("identity", {category='proxy', type='bytestreams', name=_name}):up()
a0dfa3e5883c mod_proxy65: new component proxy65; currently only disco#info and disco#items done
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
40 :tag("feature", {var="http://jabber.org/protocol/bytestreams"});
a0dfa3e5883c mod_proxy65: new component proxy65; currently only disco#info and disco#items done
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
41 replies_cache.disco_info = reply;
a0dfa3e5883c mod_proxy65: new component proxy65; currently only disco#info and disco#items done
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
42 end
a0dfa3e5883c mod_proxy65: new component proxy65; currently only disco#info and disco#items done
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
43
a0dfa3e5883c mod_proxy65: new component proxy65; currently only disco#info and disco#items done
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
44 reply.attr.id = stanza.attr.id;
a0dfa3e5883c mod_proxy65: new component proxy65; currently only disco#info and disco#items done
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
45 reply.attr.to = stanza.attr.from;
a0dfa3e5883c mod_proxy65: new component proxy65; currently only disco#info and disco#items done
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
46 return reply;
a0dfa3e5883c mod_proxy65: new component proxy65; currently only disco#info and disco#items done
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
47 end
a0dfa3e5883c mod_proxy65: new component proxy65; currently only disco#info and disco#items done
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
48
a0dfa3e5883c mod_proxy65: new component proxy65; currently only disco#info and disco#items done
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
49 local function get_disco_items(stanza)
a0dfa3e5883c mod_proxy65: new component proxy65; currently only disco#info and disco#items done
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
50 local reply = replies_cache.disco_items;
a0dfa3e5883c mod_proxy65: new component proxy65; currently only disco#info and disco#items done
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
51 if reply == nil then
a0dfa3e5883c mod_proxy65: new component proxy65; currently only disco#info and disco#items done
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
52 reply = st.iq({type='result', from=_host}):query("http://jabber.org/protocol/disco#items");
a0dfa3e5883c mod_proxy65: new component proxy65; currently only disco#info and disco#items done
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
53 replies_cache.disco_info = reply;
a0dfa3e5883c mod_proxy65: new component proxy65; currently only disco#info and disco#items done
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
54 end
a0dfa3e5883c mod_proxy65: new component proxy65; currently only disco#info and disco#items done
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
55
a0dfa3e5883c mod_proxy65: new component proxy65; currently only disco#info and disco#items done
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
56 reply.attr.id = stanza.attr.id;
a0dfa3e5883c mod_proxy65: new component proxy65; currently only disco#info and disco#items done
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
57 reply.attr.to = stanza.attr.from;
a0dfa3e5883c mod_proxy65: new component proxy65; currently only disco#info and disco#items done
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
58 return reply;
a0dfa3e5883c mod_proxy65: new component proxy65; currently only disco#info and disco#items done
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
59 end
a0dfa3e5883c mod_proxy65: new component proxy65; currently only disco#info and disco#items done
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
60
a0dfa3e5883c mod_proxy65: new component proxy65; currently only disco#info and disco#items done
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
61 --[[
a0dfa3e5883c mod_proxy65: new component proxy65; currently only disco#info and disco#items done
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
62 <iq type='result'
a0dfa3e5883c mod_proxy65: new component proxy65; currently only disco#info and disco#items done
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
63 from='streamhostproxy.example.net'
a0dfa3e5883c mod_proxy65: new component proxy65; currently only disco#info and disco#items done
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
64 to='initiator@example.com/foo'
a0dfa3e5883c mod_proxy65: new component proxy65; currently only disco#info and disco#items done
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
65 id='discover'>
a0dfa3e5883c mod_proxy65: new component proxy65; currently only disco#info and disco#items done
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
66 <query xmlns='http://jabber.org/protocol/bytestreams'>
a0dfa3e5883c mod_proxy65: new component proxy65; currently only disco#info and disco#items done
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
67 sid='vxf9n471bn46'>
a0dfa3e5883c mod_proxy65: new component proxy65; currently only disco#info and disco#items done
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
68 <streamhost
a0dfa3e5883c mod_proxy65: new component proxy65; currently only disco#info and disco#items done
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
69 jid='streamhostproxy.example.net'
a0dfa3e5883c mod_proxy65: new component proxy65; currently only disco#info and disco#items done
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
70 host='24.24.24.1'
a0dfa3e5883c mod_proxy65: new component proxy65; currently only disco#info and disco#items done
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
71 zeroconf='_jabber.bytestreams'/>
a0dfa3e5883c mod_proxy65: new component proxy65; currently only disco#info and disco#items done
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
72 </query>
a0dfa3e5883c mod_proxy65: new component proxy65; currently only disco#info and disco#items done
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
73 </iq>
a0dfa3e5883c mod_proxy65: new component proxy65; currently only disco#info and disco#items done
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
74 ]]--
a0dfa3e5883c mod_proxy65: new component proxy65; currently only disco#info and disco#items done
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
75 local function get_stream_host(stanza)
a0dfa3e5883c mod_proxy65: new component proxy65; currently only disco#info and disco#items done
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
76 local reply = replies_cache.stream_host;
a0dfa3e5883c mod_proxy65: new component proxy65; currently only disco#info and disco#items done
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
77 if reply == nil then
a0dfa3e5883c mod_proxy65: new component proxy65; currently only disco#info and disco#items done
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
78 reply = st.iq({type="result", from=_host})
a0dfa3e5883c mod_proxy65: new component proxy65; currently only disco#info and disco#items done
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
79 :query("http://jabber.org/protocol/bytestreams")
a0dfa3e5883c mod_proxy65: new component proxy65; currently only disco#info and disco#items done
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
80 :tag("streamhost", {jid=_host, host="24.24.24.1", zeroconf="_jabber.bytestreams"}); -- TODO get the correct data
a0dfa3e5883c mod_proxy65: new component proxy65; currently only disco#info and disco#items done
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
81 replies_cache.stream_host = reply;
a0dfa3e5883c mod_proxy65: new component proxy65; currently only disco#info and disco#items done
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
82 end
a0dfa3e5883c mod_proxy65: new component proxy65; currently only disco#info and disco#items done
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
83
a0dfa3e5883c mod_proxy65: new component proxy65; currently only disco#info and disco#items done
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
84 reply.attr.id = stanza.attr.id;
a0dfa3e5883c mod_proxy65: new component proxy65; currently only disco#info and disco#items done
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
85 reply.attr.to = stanza.attr.from;
a0dfa3e5883c mod_proxy65: new component proxy65; currently only disco#info and disco#items done
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
86 reply.tags[1].attr.sid = stanza.tags[1].attr.sid;
a0dfa3e5883c mod_proxy65: new component proxy65; currently only disco#info and disco#items done
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
87 return reply;
a0dfa3e5883c mod_proxy65: new component proxy65; currently only disco#info and disco#items done
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
88 end
a0dfa3e5883c mod_proxy65: new component proxy65; currently only disco#info and disco#items done
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
89
a0dfa3e5883c mod_proxy65: new component proxy65; currently only disco#info and disco#items done
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
90 module.unload = function()
a0dfa3e5883c mod_proxy65: new component proxy65; currently only disco#info and disco#items done
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
91 deregister_component(_host);
a0dfa3e5883c mod_proxy65: new component proxy65; currently only disco#info and disco#items done
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
92 end
a0dfa3e5883c mod_proxy65: new component proxy65; currently only disco#info and disco#items done
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
93
a0dfa3e5883c mod_proxy65: new component proxy65; currently only disco#info and disco#items done
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
94 module:add_item("proxy", {jid=_host, name=_name})
a0dfa3e5883c mod_proxy65: new component proxy65; currently only disco#info and disco#items done
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
95
a0dfa3e5883c mod_proxy65: new component proxy65; currently only disco#info and disco#items done
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
96 component = register_component(_host, function(origin, stanza)
a0dfa3e5883c mod_proxy65: new component proxy65; currently only disco#info and disco#items done
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
97 local to_node, to_host, to_resource = jid_split(stanza.attr.to);
a0dfa3e5883c mod_proxy65: new component proxy65; currently only disco#info and disco#items done
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
98 if to_node == nil then
a0dfa3e5883c mod_proxy65: new component proxy65; currently only disco#info and disco#items done
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
99 local type = stanza.attr.type;
a0dfa3e5883c mod_proxy65: new component proxy65; currently only disco#info and disco#items done
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
100 if type == "error" or type == "result" then return; end
a0dfa3e5883c mod_proxy65: new component proxy65; currently only disco#info and disco#items done
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
101 if stanza.name == "iq" and type == "get" then
a0dfa3e5883c mod_proxy65: new component proxy65; currently only disco#info and disco#items done
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
102 local xmlns = stanza.tags[1].attr.xmlns
a0dfa3e5883c mod_proxy65: new component proxy65; currently only disco#info and disco#items done
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
103 if xmlns == "http://jabber.org/protocol/disco#info" then
a0dfa3e5883c mod_proxy65: new component proxy65; currently only disco#info and disco#items done
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
104 origin.send(get_disco_info(stanza));
a0dfa3e5883c mod_proxy65: new component proxy65; currently only disco#info and disco#items done
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
105 return true;
a0dfa3e5883c mod_proxy65: new component proxy65; currently only disco#info and disco#items done
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
106 elseif xmlns == "http://jabber.org/protocol/disco#items" then
a0dfa3e5883c mod_proxy65: new component proxy65; currently only disco#info and disco#items done
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
107 origin.send(get_disco_items(stanza));
a0dfa3e5883c mod_proxy65: new component proxy65; currently only disco#info and disco#items done
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
108 return true;
a0dfa3e5883c mod_proxy65: new component proxy65; currently only disco#info and disco#items done
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
109 elseif xmlns == "http://jabber.org/protocol/bytestreams" and stanza.tags[1].attr.sid ~= nil then
a0dfa3e5883c mod_proxy65: new component proxy65; currently only disco#info and disco#items done
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
110 origin.send(get_stream_host(stanza));
a0dfa3e5883c mod_proxy65: new component proxy65; currently only disco#info and disco#items done
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
111 return true;
a0dfa3e5883c mod_proxy65: new component proxy65; currently only disco#info and disco#items done
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
112 end
a0dfa3e5883c mod_proxy65: new component proxy65; currently only disco#info and disco#items done
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
113 end
a0dfa3e5883c mod_proxy65: new component proxy65; currently only disco#info and disco#items done
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
114 end
a0dfa3e5883c mod_proxy65: new component proxy65; currently only disco#info and disco#items done
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
115 return;
a0dfa3e5883c mod_proxy65: new component proxy65; currently only disco#info and disco#items done
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
116 end);