Diff

plugins/mod_bosh.lua @ 5189:7f6cc8ed2247

Merge 0.9->trunk
author Matthew Wild <mwild1@gmail.com>
date Thu, 22 Nov 2012 19:38:42 +0000
parent 5188:6689605f8591
child 5634:7298c9bbb30f
child 5639:7a0e19e649b7
line wrap: on
line diff
--- a/plugins/mod_bosh.lua	Thu Nov 22 17:42:14 2012 +0000
+++ b/plugins/mod_bosh.lua	Thu Nov 22 19:38:42 2012 +0000
@@ -18,6 +18,8 @@
 local st = require "util.stanza";
 local logger = require "util.logger";
 local log = logger.init("mod_bosh");
+local initialize_filters = require "util.filters".initialize;
+local math_min = math.min;
 
 local xmlns_streams = "http://etherx.jabber.org/streams";
 local xmlns_xmpp_streams = "urn:ietf:params:xml:ns:xmpp-streams";
@@ -30,10 +32,11 @@
 local BOSH_DEFAULT_INACTIVITY = module:get_option_number("bosh_max_inactivity", 60);
 local BOSH_DEFAULT_POLLING = module:get_option_number("bosh_max_polling", 5);
 local BOSH_DEFAULT_REQUESTS = module:get_option_number("bosh_max_requests", 2);
+local bosh_max_wait = module:get_option_number("bosh_max_wait", 120);
 
 local consider_bosh_secure = module:get_option_boolean("consider_bosh_secure");
 
-local default_headers = { ["Content-Type"] = "text/xml; charset=utf-8" };
+local default_headers = { ["Content-Type"] = "text/xml; charset=utf-8", ["Connection"] = "keep-alive" };
 
 local cross_domain = module:get_option("cross_domain_bosh", false);
 if cross_domain then
@@ -243,7 +246,7 @@
 		sid = new_uuid();
 		local session = {
 			type = "c2s_unauthed", conn = {}, sid = sid, rid = tonumber(attr.rid)-1, host = attr.to,
-			bosh_version = attr.ver, bosh_wait = attr.wait, streamid = sid,
+			bosh_version = attr.ver, bosh_wait = math_min(attr.wait, bosh_max_wait), streamid = sid,
 			bosh_hold = BOSH_DEFAULT_HOLD, bosh_max_inactive = BOSH_DEFAULT_INACTIVITY,
 			requests = { }, send_buffer = {}, reset_stream = bosh_reset_stream,
 			close = bosh_close_stream, dispatch_stanza = core_process_stanza, notopen = true,
@@ -252,6 +255,8 @@
 		};
 		sessions[sid] = session;
 		
+		local filter = initialize_filters(session);
+		
 		session.log("debug", "BOSH session created for request from %s", session.ip);
 		log("info", "New BOSH session, assigned it sid '%s'", sid);
 
@@ -265,6 +270,7 @@
 				s = st.clone(s);
 				s.attr.xmlns = "jabber:client";
 			end
+			s = filter("stanzas/out", s);
 			--log("debug", "Sending BOSH data: %s", tostring(s));
 			t_insert(session.send_buffer, tostring(s));
 
@@ -278,10 +284,10 @@
 					sid = sid;
 				};
 				if creating_session then
-					body_attr.wait = attr.wait;
 					body_attr.inactivity = tostring(BOSH_DEFAULT_INACTIVITY);
 					body_attr.polling = tostring(BOSH_DEFAULT_POLLING);
 					body_attr.requests = tostring(BOSH_DEFAULT_REQUESTS);
+					body_attr.wait = tostring(session.bosh_wait);
 					body_attr.hold = tostring(session.bosh_hold);
 					body_attr.authid = sid;
 					body_attr.secure = "true";
@@ -352,6 +358,7 @@
 		if stanza.attr.xmlns == xmlns_bosh then
 			stanza.attr.xmlns = nil;
 		end
+		stanza = session.filter("stanzas/in", stanza);
 		core_process_stanza(session, stanza);
 	end
 end