X-Git-Url: https://git.enpas.org/?a=blobdiff_plain;f=plugins%2Fmod_bosh.lua;h=66a79785dea936ba77779028c768039ccdb8fcb0;hb=1881612f6e77c771984d73b85704e89818a82977;hp=a747f3cbd4a09d121e08189c327faa13bb0dedf2;hpb=e73e59584aff8cd03ae76b35f5a97c292cb84c4f;p=prosody.git diff --git a/plugins/mod_bosh.lua b/plugins/mod_bosh.lua index a747f3cb..66a79785 100644 --- a/plugins/mod_bosh.lua +++ b/plugins/mod_bosh.lua @@ -10,33 +10,31 @@ module.host = "*" -- Global module local hosts = _G.hosts; local lxp = require "lxp"; -local new_xmpp_stream = require "util.xmppstream".new; +local init_xmlhandlers = require "core.xmlhandlers" +local server = require "net.server"; local httpserver = require "net.httpserver"; local sm = require "core.sessionmanager"; local sm_destroy_session = sm.destroy_session; local new_uuid = require "util.uuid".generate; -local fire_event = prosody.events.fire_event; +local fire_event = require "core.eventmanager".fire_event; local core_process_stanza = core_process_stanza; local st = require "util.stanza"; local logger = require "util.logger"; local log = logger.init("mod_bosh"); -local timer = require "util.timer"; -local xmlns_streams = "http://etherx.jabber.org/streams"; -local xmlns_xmpp_streams = "urn:ietf:params:xml:ns:xmpp-streams"; local xmlns_bosh = "http://jabber.org/protocol/httpbind"; -- (hard-coded into a literal in session.send) - -local stream_callbacks = { - stream_ns = xmlns_bosh, stream_tag = "body", default_ns = "jabber:client" }; +local stream_callbacks = { stream_ns = "http://jabber.org/protocol/httpbind", stream_tag = "body", default_ns = "jabber:client" }; local BOSH_DEFAULT_HOLD = tonumber(module:get_option("bosh_default_hold")) or 1; local BOSH_DEFAULT_INACTIVITY = tonumber(module:get_option("bosh_max_inactivity")) or 60; local BOSH_DEFAULT_POLLING = tonumber(module:get_option("bosh_max_polling")) or 5; local BOSH_DEFAULT_REQUESTS = tonumber(module:get_option("bosh_max_requests")) or 2; +local BOSH_DEFAULT_MAXPAUSE = tonumber(module:get_option("bosh_max_pause")) or 300; local consider_bosh_secure = module:get_option_boolean("consider_bosh_secure"); local default_headers = { ["Content-Type"] = "text/xml; charset=utf-8" }; +local session_close_reply = { headers = default_headers, body = st.stanza("body", { xmlns = xmlns_bosh, type = "terminate" }), attr = {} }; local cross_domain = module:get_option("cross_domain_bosh"); if cross_domain then @@ -54,22 +52,6 @@ if cross_domain then end end -local trusted_proxies = module:get_option_set("trusted_proxies", {"127.0.0.1"})._items; - -local function get_ip_from_request(request) - local ip = request.handler:ip(); - local forwarded_for = request.headers["x-forwarded-for"]; - if forwarded_for then - forwarded_for = forwarded_for..", "..ip; - for forwarded_ip in forwarded_for:gmatch("[^%s,]+") do - if not trusted_proxies[forwarded_ip] then - ip = forwarded_ip; - end - end - end - return ip; -end - local t_insert, t_remove, t_concat = table.insert, table.remove, table.concat; local os_time = os.time; @@ -101,10 +83,7 @@ end function handle_request(method, body, request) if (not body) or request.method ~= "POST" then if request.method == "OPTIONS" then - local headers = {}; - for k,v in pairs(default_headers) do headers[k] = v; end - headers["Content-Type"] = nil; - return { headers = headers, body = "" }; + return { headers = default_headers, body = "" }; else return "
You really don't look like a BOSH client to me... what do you want?"; end @@ -118,19 +97,12 @@ function handle_request(method, body, request) request.log = log; request.on_destroy = on_destroy_request; - local stream = new_xmpp_stream(request, stream_callbacks); - -- stream:feed() calls the stream_callbacks, so all stanzas in - -- the body are processed in this next line before it returns. - stream:feed(body); + local parser = lxp.new(init_xmlhandlers(request, stream_callbacks), "\1"); + + parser:parse(body); local session = sessions[request.sid]; if session then - -- Session was marked as inactive, since we have - -- a request open now, unmark it - if inactive_sessions[session] then - inactive_sessions[session] = nil; - end - local r = session.requests; log("debug", "Session %s has %d out of %d requests open", request.sid, #r, session.bosh_hold); log("debug", "and there are %d things in the send_buffer", #session.send_buffer); @@ -160,6 +132,11 @@ function handle_request(method, body, request) request.reply_before = os_time() + session.bosh_wait; waiting_requests[request] = true; end + if inactive_sessions[session] then + -- Session was marked as inactive, since we have + -- a request open now, unmark it + inactive_sessions[session] = nil; + end end return true; -- Inform httpserver we shall reply later @@ -169,42 +146,11 @@ end local function bosh_reset_stream(session) session.notopen = true; end -local stream_xmlns_attr = { xmlns = "urn:ietf:params:xml:ns:xmpp-streams" }; - local function bosh_close_stream(session, reason) (session.log or log)("info", "BOSH client disconnected"); - - local close_reply = st.stanza("body", { xmlns = xmlns_bosh, type = "terminate", - ["xmlns:streams"] = xmlns_streams }); - - - if reason then - close_reply.attr.condition = "remote-stream-error"; - if type(reason) == "string" then -- assume stream error - close_reply:tag("stream:error") - :tag(reason, {xmlns = xmlns_xmpp_streams}); - elseif type(reason) == "table" then - if reason.condition then - close_reply:tag("stream:error") - :tag(reason.condition, stream_xmlns_attr):up(); - if reason.text then - close_reply:tag("text", stream_xmlns_attr):text(reason.text):up(); - end - if reason.extra then - close_reply:add_child(reason.extra); - end - elseif reason.name then -- a stanza - close_reply = reason; - end - end - log("info", "Disconnecting client,