- if proxy_acl and #proxy_acl > 0 then
- for _, acl in ipairs(proxy_acl) do
- if jid_compare(jid, acl) then allow = true; end
- end
- else
- allow = true;
- end
- if allow == true then
- if reply == nil then
- reply = st.iq({type="result", from=host})
- :query("http://jabber.org/protocol/bytestreams")
- :tag("streamhost", {jid=host, host=proxy_address, port=proxy_port});
- replies_cache.stream_host = reply;
- end
- else
- module:log("warn", "Denying use of proxy for %s", tostring(jid));
- if err_reply == nil then
- err_reply = st.iq({type="error", from=host})
- :query("http://jabber.org/protocol/bytestreams")
- :tag("error", {code='403', type='auth'})
- :tag("forbidden", {xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'});
- replies_cache.stream_host_err = err_reply;
- end
- reply = err_reply;
- end
- reply.attr.id = stanza.attr.id;
- reply.attr.to = stanza.attr.from;
- reply.tags[1].attr.sid = sid;
- return reply;
-end
-
-module.unload = function()
- componentmanager.deregister_component(host);
- connlisteners.deregister(module.host .. ':proxy65');
-end
-
-local function set_activation(stanza)
- local from, to, sid, reply = nil;
- from = stanza.attr.from;
- if stanza.tags[1] ~= nil and tostring(stanza.tags[1].name) == "query" then
- if stanza.tags[1].attr ~= nil then
- sid = stanza.tags[1].attr.sid;
- end
- if stanza.tags[1].tags[1] ~= nil and tostring(stanza.tags[1].tags[1].name) == "activate" then
- to = stanza.tags[1].tags[1][1];
- end
- end
- if from ~= nil and to ~= nil and sid ~= nil then
- reply = st.iq({type="result", from=host, to=from});
- reply.attr.id = stanza.attr.id;
- end
- return reply, from, to, sid;
-end
-
-function handle_to_domain(event)
- local origin, stanza = event.origin, event.stanza;
- if stanza.attr.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" then
- origin.send(get_stream_host(origin, stanza));
- return true;
- else
- origin.send(st.error_reply(stanza, "cancel", "service-unavailable"));
+ module:hook("iq-get/host/http://jabber.org/protocol/disco#info:query", function(event)
+ local origin, stanza = event.origin, event.stanza;
+ origin.send(st.reply(stanza):query("http://jabber.org/protocol/disco#info")
+ :tag("identity", {category='proxy', type='bytestreams', name=name}):up()
+ :tag("feature", {var="http://jabber.org/protocol/bytestreams"}) );
+ return true;
+ end, -1);
+
+ module:hook("iq-get/host/http://jabber.org/protocol/disco#items:query", function(event)
+ local origin, stanza = event.origin, event.stanza;
+ origin.send(st.reply(stanza):query("http://jabber.org/protocol/disco#items"));
+ return true;
+ end, -1);
+
+ module:hook("iq-get/host/http://jabber.org/protocol/bytestreams:query", function(event)
+ local origin, stanza = event.origin, event.stanza;
+
+ -- check ACL
+ while proxy_acl and #proxy_acl > 0 do -- using 'while' instead of 'if' so we can break out of it
+ local jid = stanza.attr.from;
+ for _, acl in ipairs(proxy_acl) do
+ if jid_compare(jid, acl) then break; end
+ end
+ module:log("warn", "Denying use of proxy for %s", tostring(stanza.attr.from));
+ origin.send(st.error_reply(stanza, "auth", "forbidden"));