Merge with 0.6 on prosody.im 0.6.0

Wed, 25 Nov 2009 05:11:10 +0000

author
Matthew Wild <mwild1@gmail.com>
date
Wed, 25 Nov 2009 05:11:10 +0000
changeset 2168
1a99a3bf3ce6
parent 2165
529af807ba1a (current diff)
parent 2167
e41a6ea7fc0f (diff)
child 2169
c06fdb6b57bd

Merge with 0.6 on prosody.im

--- a/core/loggingmanager.lua	Wed Nov 25 03:30:00 2009 +0000
+++ b/core/loggingmanager.lua	Wed Nov 25 05:11:10 2009 +0000
@@ -17,6 +17,12 @@
 local os_date, os_getenv = os.date, os.getenv;
 local getstyle, getstring = require "util.termcolours".getstyle, require "util.termcolours".getstring;
 
+if os.getenv("__FLUSH_LOG") then
+	local io_flush = io.flush;
+	local _io_write = io_write;
+	io_write = function(...) _io_write(...); io_flush(); end
+end
+
 local config = require "core.configmanager";
 local eventmanager = require "core.eventmanager";
 local logger = require "util.logger";
--- a/core/sessionmanager.lua	Wed Nov 25 03:30:00 2009 +0000
+++ b/core/sessionmanager.lua	Wed Nov 25 05:11:10 2009 +0000
@@ -201,22 +201,32 @@
 end
 
 function send_to_available_resources(user, host, stanza)
+	local jid = user.."@"..host;
 	local count = 0;
-	local to = stanza.attr.to;
-	stanza.attr.to = nil;
-	local h = hosts[host];
-	if h and h.type == "local" then
-		local u = h.sessions[user];
-		if u then
-			for k, session in pairs(u.sessions) do
-				if session.presence then
-					session.send(stanza);
-					count = count + 1;
-				end
+	local user = bare_sessions[jid];
+	if user then
+		for k, session in pairs(user.sessions) do
+			if session.presence then
+				session.send(stanza);
+				count = count + 1;
 			end
 		end
 	end
-	stanza.attr.to = to;
+	return count;
+end
+
+function send_to_interested_resources(user, host, stanza)
+	local jid = user.."@"..host;
+	local count = 0;
+	local user = bare_sessions[jid];
+	if user then
+		for k, session in pairs(user.sessions) do
+			if session.interested then
+				session.send(stanza);
+				count = count + 1;
+			end
+		end
+	end
 	return count;
 end
 
--- a/net/xmppclient_listener.lua	Wed Nov 25 03:30:00 2009 +0000
+++ b/net/xmppclient_listener.lua	Wed Nov 25 05:11:10 2009 +0000
@@ -61,7 +61,7 @@
 		function session.data(conn, data)
 			local ok, err = parser:parse(data);
 			if ok then return; end
-			log("debug", "Received invalid XML (%s) %d bytes: %s", tostring(err), #data, data:sub(1, 300):gsub("[\r\n]+", " "));
+			log("debug", "Received invalid XML (%s) %d bytes: %s", tostring(err), #data, data:sub(1, 300):gsub("[\r\n]+", " "):gsub("[%z\1-\31]", "_"));
 			session:close("xml-not-well-formed");
 		end
 		
--- a/plugins/mod_presence.lua	Wed Nov 25 03:30:00 2009 +0000
+++ b/plugins/mod_presence.lua	Wed Nov 25 05:11:10 2009 +0000
@@ -233,6 +233,7 @@
 				-- TODO send last recieved unavailable presence (or we MAY do nothing, which is fine too)
 			end
 		else
+			core_route_stanza(origin, st.presence({from=to_bare, to=from_bare, type="unavailable"})); -- acknowledging receipt
 			if not rostermanager.is_contact_pending_in(node, host, from_bare) then
 				if rostermanager.set_contact_pending_in(node, host, from_bare) then
 					sessionmanager.send_to_available_resources(node, host, stanza);
@@ -241,14 +242,17 @@
 		end
 	elseif stanza.attr.type == "unsubscribe" then
 		if rostermanager.process_inbound_unsubscribe(node, host, from_bare) then
+			sessionmanager.send_to_interested_resources(node, host, stanza);
 			rostermanager.roster_push(node, host, from_bare);
 		end
 	elseif stanza.attr.type == "subscribed" then
 		if rostermanager.process_inbound_subscription_approval(node, host, from_bare) then
+			sessionmanager.send_to_interested_resources(node, host, stanza);
 			rostermanager.roster_push(node, host, from_bare);
 		end
 	elseif stanza.attr.type == "unsubscribed" then
 		if rostermanager.process_inbound_subscription_cancellation(node, host, from_bare) then
+			sessionmanager.send_to_interested_resources(node, host, stanza);
 			rostermanager.roster_push(node, host, from_bare);
 		end
 	end -- discard any other type
--- a/prosody	Wed Nov 25 03:30:00 2009 +0000
+++ b/prosody	Wed Nov 25 05:11:10 2009 +0000
@@ -14,7 +14,7 @@
 CFG_PLUGINDIR=os.getenv("PROSODY_PLUGINDIR");
 CFG_DATADIR=os.getenv("PROSODY_DATADIR");
 
--- -- -- -- -- -- -- ---- -- -- -- -- -- -- -- --
+-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
 
 if CFG_SOURCEDIR then
 	package.path = CFG_SOURCEDIR.."/?.lua;"..package.path;
@@ -58,7 +58,27 @@
 function read_config()
 	-- TODO: Check for other formats when we add support for them
 	-- Use lfs? Make a new conf/ dir?
-	local ok, level, err = config.load((CFG_CONFIGDIR or ".").."/prosody.cfg.lua");
+	local filenames = {};
+	
+	local filename;
+	if arg[1] == "--config" and arg[2] then
+		table.insert(filenames, arg[2]);
+		if CFG_CONFIGDIR then
+			table.insert(filenames, CFG_CONFIGDIR.."/"..arg[2]);
+		end
+	else
+		table.insert(filenames, (CFG_CONFIGDIR or ".").."/prosody.cfg.lua");
+	end
+	for _,_filename in ipairs(filenames) do
+		filename = _filename;
+		local file = io.open(filename);
+		if file then
+			file:close();
+			CFG_CONFIGDIR = filename:match("^(.*)[\\/][^\\/]*$");
+			break;
+		end
+	end
+	local ok, level, err = config.load(filename);
 	if not ok then
 		print("\n");
 		print("**************************");
@@ -82,13 +102,13 @@
 end
 
 function load_libraries()
-	--- Initialize logging
+	-- Initialize logging
 	require "core.loggingmanager"
 	
-	--- Check runtime dependencies
+	-- Check runtime dependencies
 	require "util.dependencies"
 	
-	--- Load socket framework
+	-- Load socket framework
 	server = require "net.server"
 end	
 
--- a/util/serialization.lua	Wed Nov 25 03:30:00 2009 +0000
+++ b/util/serialization.lua	Wed Nov 25 05:11:10 2009 +0000
@@ -13,6 +13,7 @@
 local t_concat = table.concat;
 local error = error;
 local pairs = pairs;
+local next = next;
 
 local debug_traceback = debug.traceback;
 local log = require "util.logger".init("serialization");
@@ -34,21 +35,25 @@
 	elseif type(o) == "string" then
 		func(t, (("%q"):format(o):gsub("\\\n", "\\n")));
 	elseif type(o) == "table" then
-		func(t, "{\n");
-		for k,v in pairs(o) do
-			func(t, indent(ind));
-			func(t, "[");
-			func(t, basicSerialize(k));
-			func(t, "] = ");
-			if ind == 0 then
-				_simplesave(v, 0, t, func);
-			else
-				_simplesave(v, ind+1, t, func);
+		if next(o) then
+			func(t, "{\n");
+			for k,v in pairs(o) do
+				func(t, indent(ind));
+				func(t, "[");
+				func(t, basicSerialize(k));
+				func(t, "] = ");
+				if ind == 0 then
+					_simplesave(v, 0, t, func);
+				else
+					_simplesave(v, ind+1, t, func);
+				end
+				func(t, ";\n");
 			end
-			func(t, ",\n");
+			func(t, indent(ind-1));
+			func(t, "}");
+		else
+			func(t, "{}");
 		end
-		func(t, indent(ind-1));
-		func(t, "}");
 	elseif type(o) == "boolean" then
 		func(t, (o and "true" or "false"));
 	else

mercurial