# HG changeset patch # User Thilo Cestonaro # Date 1255381723 -7200 # Node ID a0dfa3e5883c936d2d6f94fd3c9c2c6d6f71b25c # Parent fc4806a98fc4d0126387144f631a7a86e497a53d mod_proxy65: new component proxy65; currently only disco#info and disco#items done diff -r fc4806a98fc4 -r a0dfa3e5883c mod_proxy65/proxy65/mod_proxy65.lua --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mod_proxy65/proxy65/mod_proxy65.lua Mon Oct 12 23:08:43 2009 +0200 @@ -0,0 +1,116 @@ +-- Copyright (C) 2009 Thilo Cestonaro +-- +-- This project is MIT/X11 licensed. Please see the +-- COPYING file in the source package for more information. +-- + +if module:get_host_type() ~= "component" then + error("proxy65 should be loaded as a component, please see http://prosody.im/doc/components", 0); +end + +local _host = module:get_host(); +local _name = "SOCKS5 Bytestreams Service"; + +local jid_split = require "util.jid".split; +local st = require "util.stanza"; +local register_component = require "core.componentmanager".register_component; +local deregister_component = require "core.componentmanager".deregister_component; +local configmanager = require "core.configmanager"; + +local replies_cache = {}; + +--[[ + + + + + + +]]-- +local function get_disco_info(stanza) + local reply = replies_cache.disco_info; + if reply == nil then + reply = st.iq({type='result', from=_host}):query("http://jabber.org/protocol/disco#info") + :tag("identity", {category='proxy', type='bytestreams', name=_name}):up() + :tag("feature", {var="http://jabber.org/protocol/bytestreams"}); + replies_cache.disco_info = reply; + end + + reply.attr.id = stanza.attr.id; + reply.attr.to = stanza.attr.from; + return reply; +end + +local function get_disco_items(stanza) + local reply = replies_cache.disco_items; + if reply == nil then + reply = st.iq({type='result', from=_host}):query("http://jabber.org/protocol/disco#items"); + replies_cache.disco_info = reply; + end + + reply.attr.id = stanza.attr.id; + reply.attr.to = stanza.attr.from; + return reply; +end + +--[[ + + + sid='vxf9n471bn46'> + + + +]]-- +local function get_stream_host(stanza) + local reply = replies_cache.stream_host; + if reply == nil then + reply = st.iq({type="result", from=_host}) + :query("http://jabber.org/protocol/bytestreams") + :tag("streamhost", {jid=_host, host="24.24.24.1", zeroconf="_jabber.bytestreams"}); -- TODO get the correct data + replies_cache.stream_host = reply; + end + + reply.attr.id = stanza.attr.id; + reply.attr.to = stanza.attr.from; + reply.tags[1].attr.sid = stanza.tags[1].attr.sid; + return reply; +end + +module.unload = function() + deregister_component(_host); +end + +module:add_item("proxy", {jid=_host, name=_name}) + +component = register_component(_host, function(origin, stanza) + local to_node, to_host, to_resource = jid_split(stanza.attr.to); + if to_node == nil then + local type = stanza.attr.type; + if type == "error" or type == "result" then return; end + if stanza.name == "iq" and type == "get" then + local xmlns = stanza.tags[1].attr.xmlns + if xmlns == "http://jabber.org/protocol/disco#info" then + origin.send(get_disco_info(stanza)); + return true; + elseif xmlns == "http://jabber.org/protocol/disco#items" then + origin.send(get_disco_items(stanza)); + return true; + elseif xmlns == "http://jabber.org/protocol/bytestreams" and stanza.tags[1].attr.sid ~= nil then + origin.send(get_stream_host(stanza)); + return true; + end + end + end + return; +end); \ No newline at end of file