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