Merging SASL buggy client workaround with current tip.

Fri, 15 May 2009 17:33:04 +0200

author
Tobias Markmann <tm@ayena.de>
date
Fri, 15 May 2009 17:33:04 +0200
changeset 1162
bd1f0e6d50a7
parent 1161
5bc2b7b5b81d (current diff)
parent 1157
279f79389189 (diff)
child 1166
5499a028d4ae

Merging SASL buggy client workaround with current tip.

--- a/core/stanza_router.lua	Fri May 15 17:28:39 2009 +0200
+++ b/core/stanza_router.lua	Fri May 15 17:33:04 2009 +0200
@@ -54,7 +54,7 @@
 
 	if not stanza.attr.xmlns then stanza.attr.xmlns = "jabber:client"; end -- FIXME Hack. This should be removed when we fix namespace handling.
 	-- TODO verify validity of stanza (as well as JID validity)
-	if stanza.attr.xmlns == "error" and #stanza.tags == 0 then return; end -- TODO invalid stanza, log
+	if stanza.attr.type == "error" and #stanza.tags == 0 then return; end -- TODO invalid stanza, log
 	if stanza.name == "iq" then
 		if (stanza.attr.type == "set" or stanza.attr.type == "get") and #stanza.tags ~= 1 then
 			origin.send(st.error_reply(stanza, "modify", "bad-request"));
@@ -106,10 +106,9 @@
 		return; -- FIXME what should we do here?
 	end]] -- FIXME
 
-	-- FIXME do stanzas not of jabber:client get handled by components?
 	if (origin.type == "s2sin" or origin.type == "c2s" or origin.type == "component") and (not xmlns or xmlns == "jabber:server" or xmlns == "jabber:client") then			
 		local event_data = {origin=origin, stanza=stanza};
-		fire_event(tostring(host or origin.host).."/"..stanza.name, event_data);
+		if fire_event(tostring(host or origin.host).."/"..stanza.name, event_data) then return; end
 		if origin.type == "s2sin" and not origin.dummy then
 			local host_status = origin.hosts[from_host];
 			if not host_status or not host_status.authed then -- remote server trying to impersonate some other server?
@@ -117,11 +116,6 @@
 				return; -- FIXME what should we do here? does this work with subdomains?
 			end
 		end
-		if origin.type == "c2s" and stanza.name == "presence" and to ~= nil and not(origin.roster[to_bare] and (origin.roster[to_bare].subscription == "both" or origin.roster[to_bare].subscription == "from")) then -- directed presence
-			origin.directed = origin.directed or {};
-			origin.directed[to] = true;
-			--t_insert(origin.directed, to); -- FIXME does it make more sense to add to_bare rather than to?
-		end
 		if not to then
 			core_handle_stanza(origin, stanza);
 		elseif hosts[to] and hosts[to].type == "local" then -- directed at a local server
@@ -134,8 +128,6 @@
 			component_handle_stanza(origin, stanza);
 		elseif hosts[host] and hosts[host].type == "component" then -- directed at a component
 			component_handle_stanza(origin, stanza);
-		elseif origin.type == "c2s" and stanza.name == "presence" and stanza.attr.type ~= nil and stanza.attr.type ~= "unavailable" and stanza.attr.type ~= "error" then
-			handle_outbound_presence_subscriptions_and_probes(origin, stanza, from_bare, to_bare, core_route_stanza);
 		elseif hosts[host] and hosts[host].type == "local" and stanza.name == "iq" and not resource then -- directed at bare JID
 			core_handle_stanza(origin, stanza);
 		else
--- a/core/xmlhandlers.lua	Fri May 15 17:28:39 2009 +0200
+++ b/core/xmlhandlers.lua	Fri May 15 17:33:04 2009 +0200
@@ -14,15 +14,8 @@
 local tostring = tostring;
 local pairs = pairs;
 local ipairs = ipairs;
-local type = type;
-local print = print;
-local format = string.format;
-local m_random = math.random;
 local t_insert = table.insert;
-local t_remove = table.remove;
 local t_concat = table.concat;
-local t_concatall = function (t, sep) local tt = {}; for _, s in ipairs(t) do t_insert(tt, tostring(s)); end return t_concat(tt, sep); end
-local sm_destroy_session = import("core.sessionmanager", "destroy_session");
 
 local default_log = require "util.logger".init("xmlhandlers");
 
@@ -68,15 +61,13 @@
 			
 			-- FIXME !!!!!
 			for i, k in ipairs(attr) do
-				if type(k) == "string" then
-					local ns, nm = k:match("^([^|]+)|?([^|]-)$")
-					if ns and nm then
-						ns = ns_prefixes[ns]; 
-						if ns then 
-							attr[ns..":"..nm] = attr[k];
-							attr[i] = ns..":"..nm;
-							attr[k] = nil;
-						end
+				local ns, nm = k:match("^([^|]+)|?([^|]-)$")
+				if ns and nm then
+					ns = ns_prefixes[ns]; 
+					if ns then 
+						attr[ns..":"..nm] = attr[k];
+						attr[i] = ns..":"..nm;
+						attr[k] = nil;
 					end
 				end
 			end
@@ -129,19 +120,17 @@
 					cb_error(session, "parse-error", "unexpected-element-close", name);
 				end
 			end
-			if stanza then
-				if #chardata > 0 then
-					-- We have some character data in the buffer
-					stanza:text(t_concat(chardata));
-					chardata = {};
-				end
-				-- Complete stanza
-				if #stanza.last_add == 0 then
-					cb_handlestanza(session, stanza);
-					stanza = nil;
-				else
-					stanza:up();
-				end
+			if #chardata > 0 then
+				-- We have some character data in the buffer
+				stanza:text(t_concat(chardata));
+				chardata = {};
+			end
+			-- Complete stanza
+			if #stanza.last_add == 0 then
+				cb_handlestanza(session, stanza);
+				stanza = nil;
+			else
+				stanza:up();
 			end
 		end
 	return xml_handlers;
--- a/plugins/mod_presence.lua	Fri May 15 17:28:39 2009 +0200
+++ b/plugins/mod_presence.lua	Fri May 15 17:33:04 2009 +0200
@@ -252,7 +252,7 @@
 	if origin.type == "c2s" then
 		if to ~= nil and not(origin.roster[to_bare] and (origin.roster[to_bare].subscription == "both" or origin.roster[to_bare].subscription == "from")) then -- directed presence
 			origin.directed = origin.directed or {};
-			origin.directed[to] = true;
+			origin.directed[to] = true; -- FIXME does it make more sense to add to_bare rather than to?
 		end
 		if stanza.attr.type ~= nil and stanza.attr.type ~= "unavailable" and stanza.attr.type ~= "error" then
 			handle_outbound_presence_subscriptions_and_probes(origin, stanza, from_bare, to_bare, core_route_stanza);
@@ -268,6 +268,7 @@
 			core_route_stanza(origin, stanza);
 		end
 	end
+	return true;
 end
 
 local add_handler = require "core.eventmanager2".add_handler;
--- a/util/events.lua	Fri May 15 17:28:39 2009 +0200
+++ b/util/events.lua	Fri May 15 17:33:04 2009 +0200
@@ -53,7 +53,8 @@
 		if not h then h = {}; handlers[event] = h; end
 		local dispatcher = function(data)
 			for _, handler in ipairs(h) do
-				handler(data);
+				local ret = handler(data);
+				if ret ~= nil then return ret; end
 			end
 		end;
 		dispatchers[event] = dispatcher;
@@ -66,7 +67,8 @@
 		local h = handlers[event];
 		if h then
 			for _, handler in ipairs(h) do
-				handler(data);
+				local ret = handler(data);
+				if ret ~= nil then return ret; end
 			end
 		end
 	end;
--- a/util/stanza.lua	Fri May 15 17:28:39 2009 +0200
+++ b/util/stanza.lua	Fri May 15 17:33:04 2009 +0200
@@ -258,10 +258,9 @@
 	return stanza(orig.name, orig.attr and { to = orig.attr.from, from = orig.attr.to, id = orig.attr.id, type = ((orig.name == "iq" and "result") or orig.attr.type) });
 end
 
-function error_reply(orig, type, condition, message, clone)
+function error_reply(orig, type, condition, message)
 	local t = reply(orig);
 	t.attr.type = "error";
-	-- TODO use clone
 	t:tag("error", {type = type})
 		:tag(condition, {xmlns = "urn:ietf:params:xml:ns:xmpp-stanzas"}):up();
 	if (message) then t:tag("text"):text(message):up(); end

mercurial