From fe97859d274301e014cf8fc137cb8688075cc195 Mon Sep 17 00:00:00 2001
From: Waqas Hussain <waqas20@gmail.com>
Date: Wed, 14 Apr 2010 17:54:33 +0500
Subject: MUC: Allow moderators which are not owners to change roles.

---
 plugins/muc/muc.lib.lua | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/plugins/muc/muc.lib.lua b/plugins/muc/muc.lib.lua
index 1ec2349a..75289cc1 100644
--- a/plugins/muc/muc.lib.lua
+++ b/plugins/muc/muc.lib.lua
@@ -673,7 +673,7 @@ end
 function room_mt:set_role(actor, occupant_jid, role, callback, reason)
 	if role == "none" then role = nil; end
 	if role and role ~= "moderator" and role ~= "participant" and role ~= "visitor" then return nil, "modify", "not-acceptable"; end
-	if self:get_affiliation(actor) ~= "owner" then return nil, "cancel", "not-allowed"; end
+	if self:get_role(self._jid_nick[actor]) ~= "moderator" then return nil, "cancel", "not-allowed"; end
 	local occupant = self._occupants[occupant_jid];
 	if not occupant then return nil, "modify", "not-acceptable"; end
 	if occupant.affiliation == "owner" or occupant.affiliation == "admin" then return nil, "cancel", "not-allowed"; end
-- 
cgit v1.2.3


From 61d1f2e0481cdbaa7367bb0448200000ff77439c Mon Sep 17 00:00:00 2001
From: Matthew Wild <mwild1@gmail.com>
Date: Wed, 14 Apr 2010 12:59:46 +0100
Subject: configmanager: Add VirtualHost as an alias for Host

---
 core/configmanager.lua | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/core/configmanager.lua b/core/configmanager.lua
index b974d2f2..6350d80b 100644
--- a/core/configmanager.lua
+++ b/core/configmanager.lua
@@ -103,7 +103,7 @@ do
 	function parsers.lua.load(data, filename)
 		local env;
 		-- The ' = true' are needed so as not to set off __newindex when we assign the functions below
-		env = setmetatable({ Host = true; host = true; Component = true, component = true,
+		env = setmetatable({ Host = true, host = true, VirtualHost = true, Component = true, component = true,
 							Include = true, include = true, RunScript = dofile }, { __index = function (t, k)
 												return rawget(_G, k) or
 														function (settings_table)
@@ -115,7 +115,7 @@ do
 										end});
 		
 		rawset(env, "__currenthost", "*") -- Default is global
-		function env.Host(name)
+		function env.VirtualHost(name)
 			if rawget(config, name) and rawget(config[name].core, "component_module") then
 				error(format("Host %q clashes with previously defined %s Component %q, for services use a sub-domain like conference.%s",
 					name, config[name].core.component_module:gsub("^%a+$", { component = "external", muc = "MUC"}), name, name), 0);
@@ -124,7 +124,7 @@ do
 			-- Needs at least one setting to logically exist :)
 			set(name or "*", "core", "defined", true);
 		end
-		env.host = env.Host;
+		env.Host, env.host = env.VirtualHost, env.VirtualHost;
 		
 		function env.Component(name)
 			if rawget(config, name) and rawget(config[name].core, "defined") and not rawget(config[name].core, "component_module") then
-- 
cgit v1.2.3


From 6d9cc727833025746953ae08357b44e62d140cf5 Mon Sep 17 00:00:00 2001
From: Matthew Wild <mwild1@gmail.com>
Date: Wed, 14 Apr 2010 13:00:24 +0100
Subject: hostmanager: Re-word log messages in line with config changes

---
 core/hostmanager.lua | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/core/hostmanager.lua b/core/hostmanager.lua
index 445291d8..b549e6f7 100644
--- a/core/hostmanager.lua
+++ b/core/hostmanager.lua
@@ -43,7 +43,7 @@ local function load_enabled_hosts(config)
 	end
 	
 	if not activated_any_host then
-		log("error", "No hosts defined in the config file. This may cause unexpected behaviour as no modules will be loaded.");
+		log("error", "No active VirtualHost entries in the config file. This may cause unexpected behaviour as no modules will be loaded.");
 	end
 	
 	eventmanager.fire_event("hosts-activated", defined_hosts);
@@ -60,8 +60,8 @@ function activate(host, host_config)
 	                     and (configmanager.get(host, "core", "disallow_s2s") ~= false))
 	              };
 	for option_name in pairs(host_config.core) do
-		if option_name:match("_ports$") then
-			log("warn", "%s: Option '%s' has no effect for virtual hosts - put it in global Host \"*\" instead", host, option_name);
+		if option_name:match("_ports$") or option_name:match("_interface$") then
+			log("warn", "%s: Option '%s' has no effect for virtual hosts - put it in the server-wide section instead", host, option_name);
 		end
 	end
 	
-- 
cgit v1.2.3


From 078ab0a198eeff33a5155ead9eb8c2af22beab92 Mon Sep 17 00:00:00 2001
From: Matthew Wild <mwild1@gmail.com>
Date: Wed, 14 Apr 2010 13:01:10 +0100
Subject: prosody.cfg.lua.dist: Refactor the default config file based on
 feedback from confused users

---
 prosody.cfg.lua.dist | 170 +++++++++++++++++++++++++--------------------------
 1 file changed, 82 insertions(+), 88 deletions(-)

diff --git a/prosody.cfg.lua.dist b/prosody.cfg.lua.dist
index 04a1ce5e..c43d1131 100644
--- a/prosody.cfg.lua.dist
+++ b/prosody.cfg.lua.dist
@@ -1,101 +1,86 @@
--- Prosody Example Configuration File 
+-- Prosody Example Configuration File
 -- 
--- If it wasn't already obvious, -- starts a comment, and all 
--- text after it on a line is ignored by Prosody.
---
--- The config is split into sections, a global section, and one 
--- for each defined host that we serve. You can add as many host 
--- sections as you like.
---
--- Lists are written { "like", "this", "one" } 
--- Lists can also be of { 1, 2, 3 } numbers, and other things. 
--- Either commas, or semi-colons; may be used
--- as seperators.
---
--- A table is a list of values, except each value has a name. An 
--- example table would be:
---
--- ssl = { key = "keyfile.key", certificate = "certificate.cert" }
---
--- Whitespace (that is tabs, spaces, line breaks) is mostly insignificant, so 
--- can 
--- be placed anywhere that 	you deem fitting.
---
--- Tip: You can check that the syntax of this file is correct when you have finished
--- by running: luac -p prosody.cfg.lua
--- If there are any errors, it will let you know what and where they are, otherwise it 
--- will keep quiet.
+-- Information on configuring Prosody can be found on our
+-- website at http://prosody.im/doc/configure
+-- 
+-- Tip: You can check that the syntax of this file is correct
+-- when you have finished by running: luac -p prosody.cfg.lua
+-- If there are any errors, it will let you know what and where
+-- they are, otherwise it will keep quiet.
 --
--- The only thing left to do is rename this file to remove the .dist ending, and fill in the 
+-- The only thing left to do is rename this file to remove the .dist ending, and fill in the
 -- blanks. Good luck, and happy Jabbering!
 
--- Server-wide settings go in this section
-Host "*"
+
+---------- Server-wide settings ----------
+-- Settings in this section apply to the whole server and are the default settings
+-- for any virtual hosts
+
+-- This is a (by default, empty) list of accounts that are admins
+-- for the server. Note that you must create the accounts separately
+-- (see http://prosody.im/doc/creating_accounts for info)
+-- Example: admins = { "user1@example.com", "user2@example.net" }
+admins = { }
+
+-- This is the list of modules Prosody will load on startup.
+-- It looks for mod_modulename.lua in the plugins folder, so make sure that exists too.
+modules_enabled = {
+
+	-- Generally required
+		"roster"; -- Allow users to have a roster. Recommended ;)
+		"saslauth"; -- Authentication for clients and servers. Recommended if you want to log in.
+		"tls"; -- Add support for secure TLS on c2s/s2s connections
+		"dialback"; -- s2s dialback support
+		"disco"; -- Service discovery
 	
-	-- This is a (by default, empty) list of accounts that are admins 
-	-- for the server. Note that you must create the accounts separately
-	-- (see http://prosody.im/doc/creating_accounts for info)
-	-- Example: admins = { "user1@example.com", "user2@example.net" }
-	admins = { }
+	-- Not essential, but recommended
+		"private"; -- Private XML storage (for room bookmarks, etc.)
+		"vcard"; -- Allow users to set vCards
 	
-	-- This is the list of modules Prosody will load on startup.
-	-- It looks for mod_modulename.lua in the plugins folder, so make sure that exists too.
-	modules_enabled = {
-			-- Generally required
-				"roster"; -- Allow users to have a roster. Recommended ;)
-				"saslauth"; -- Authentication for clients and servers. Recommended if you want to log in.
-				"tls"; -- Add support for secure TLS on c2s/s2s connections
-				"dialback"; -- s2s dialback support
-			  	"disco"; -- Service discovery
-			
-			-- Not essential, but recommended
-				"private"; -- Private XML storage (for room bookmarks, etc.)
-				"vcard"; -- Allow users to set vCards
-			
-			-- Nice to have
-				"legacyauth"; -- Legacy authentication. Only used by some old clients and bots.
-				"version"; -- Replies to server version requests
-			  	"uptime"; -- Report how long server has been running
-			  	"time"; -- Let others know the time here on this server
-			  	"ping"; -- Replies to XMPP pings with pongs
-			  	"pep"; -- Enables users to publish their mood, activity, playing music and more
-				"register"; -- Allow users to register on this server using a client and change passwords
-
-			-- Other specific functionality
-				--"posix"; -- POSIX functionality, sends server to background, enables syslog, etc.
-			  	--"console"; -- Opens admin telnet interface on localhost port 5582
-				--"bosh"; -- Enable BOSH clients, aka "Jabber over HTTP"
-				--"httpserver"; -- Serve static files from a directory over HTTP
-			  };
+	-- Nice to have
+		"legacyauth"; -- Legacy authentication. Only used by some old clients and bots.
+		"version"; -- Replies to server version requests
+		"uptime"; -- Report how long server has been running
+		"time"; -- Let others know the time here on this server
+		"ping"; -- Replies to XMPP pings with pongs
+		"pep"; -- Enables users to publish their mood, activity, playing music and more
+		"register"; -- Allow users to register on this server using a client and change passwords
 	
-	-- These modules are auto-loaded, should you
-	-- for (for some mad reason) want to disable
-	-- them then uncomment them below
-	modules_disabled = {
-			-- "presence";
-			-- "message";
-			-- "iq";
-	};
+	-- Other specific functionality
+		--"posix"; -- POSIX functionality, sends server to background, enables syslog, etc.
+		--"console"; -- Opens admin telnet interface on localhost port 5582
+		--"bosh"; -- Enable BOSH clients, aka "Jabber over HTTP"
+		--"httpserver"; -- Serve static files from a directory over HTTP
+};
+
+-- These modules are auto-loaded, should you
+-- for (for some mad reason) want to disable
+-- them then uncomment them below
+modules_disabled = {
+	-- "presence";
+	-- "message";
+	-- "iq";
+};
 
-	-- Disable account creation by default, for security
-	-- For more information see http://prosody.im/doc/creating_accounts
-	allow_registration = false;
+-- Disable account creation by default, for security
+-- For more information see http://prosody.im/doc/creating_accounts
+allow_registration = false;
 	
-	-- These are the SSL/TLS-related settings. If you don't want
-	-- to use SSL/TLS, you may comment or remove this
-	ssl = { 
-		key = "certs/localhost.key";
-		certificate = "certs/localhost.cert";
-		}
+-- These are the SSL/TLS-related settings. If you don't want
+-- to use SSL/TLS, you may comment or remove this
+ssl = {
+	key = "certs/localhost.key";
+	certificate = "certs/localhost.cert";
+}
 
--- This allows clients to connect to localhost. No harm in it.
-Host "localhost"
+----------- Virtual hosts -----------
+-- You need to add a VirtualHost entry for each domain you wish Prosody to serve.
+-- Settings under each VirtualHost entry apply *only* to that host.
 
--- Section for example.com
--- (replace example.com with your domain name)
-Host "example.com"
+VirtualHost "localhost"
 
-	enabled = false -- This will disable the host, preserving the config, but denying connections
+VirtualHost "example.com"
+	enabled = false -- Remove this line to enable this host
 
 	-- Assign this host a certificate for TLS, otherwise it would use the one
 	-- set in the global section (if any).
@@ -106,5 +91,14 @@ Host "example.com"
 		certificate = "certs/example.com.crt";
 		}
 
--- Set up a MUC (multi-user chat) room server on conference.example.com:
-Component "conference.example.com" "muc"
+------ Components ------
+-- You can specify components to add hosts that provide special services,
+-- like multi-user conferences, and transports.
+-- For more information on components, see http://prosody.im/doc/components
+
+---Set up a MUC (multi-user chat) room server on conference.example.com:
+--Component "conference.example.com" "muc"
+
+---Set up an external component (default component port is 5347)
+--Component "gateway.example.com"
+--	component_secret = "password"
-- 
cgit v1.2.3

-- 
cgit v1.2.3


From 5455626d0a09235b73f698a19d5a7ce9d41545be Mon Sep 17 00:00:00 2001
From: Waqas Hussain <waqas20@gmail.com>
Date: Mon, 19 Apr 2010 18:28:12 +0500
Subject: prosody: Set metatable on functions to allow easy access to upvalues.

---
 prosody | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/prosody b/prosody
index 46f3331f..c7f91456 100755
--- a/prosody
+++ b/prosody
@@ -123,6 +123,29 @@ function sandbox_require()
 	end
 end
 
+function set_function_metatable()
+	local mt = {};
+	function mt.__index(f, upvalue)
+		local i, name, value = 0;
+		repeat
+			i = i + 1;
+			name, value = debug.getupvalue(f, i);
+		until name == upvalue or name == nil;
+		return value;
+	end
+	function mt.__newindex(f, upvalue, value)
+		local i, name = 0;
+		repeat
+			i = i + 1;
+			name = debug.getupvalue(f, i);
+		until name == upvalue or name == nil;
+		if name then
+			debug.setupvalue(f, i, value);
+		end
+	end
+	debug.setmetatable(function() end, mt);
+end
+
 function init_global_state()
 	bare_sessions = {};
 	full_sessions = {};
@@ -418,6 +441,7 @@ read_config();
 init_logging();
 check_dependencies();
 sandbox_require();
+set_function_metatable();
 load_libraries();
 init_global_state();
 read_version();
-- 
cgit v1.2.3


From daf1f01bda7e8a1ae3b6c6255d0cb31cc5b3b12f Mon Sep 17 00:00:00 2001
From: Waqas Hussain <waqas20@gmail.com>
Date: Mon, 19 Apr 2010 18:29:10 +0500
Subject: modulemanager: Log proper tracebacks on errors during module
 load/unload.

---
 core/modulemanager.lua | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/core/modulemanager.lua b/core/modulemanager.lua
index 5e9eaedd..8e62aecb 100644
--- a/core/modulemanager.lua
+++ b/core/modulemanager.lua
@@ -19,7 +19,7 @@ local pluginloader = require "util.pluginloader";
 local hosts = hosts;
 local prosody = prosody;
 
-local loadfile, pcall = loadfile, pcall;
+local loadfile, pcall, xpcall = loadfile, pcall, xpcall;
 local setmetatable, setfenv, getfenv = setmetatable, setfenv, getfenv;
 local pairs, ipairs = pairs, ipairs;
 local t_insert, t_concat = table.insert, table.concat;
@@ -29,6 +29,14 @@ local rawget = rawget;
 local error = error;
 local tostring, tonumber = tostring, tonumber;
 
+local debug_traceback = debug.traceback;
+local unpack, select = unpack, select;
+pcall = function(f, ...)
+	local n = select("#", ...);
+	local params = {...};
+	return xpcall(function() f(unpack(params, 1, n)) end, function(e) return tostring(e).."\n"..debug_traceback(); end);
+end
+
 local array, set = require "util.array", require "util.set";
 
 local autoload_modules = {"presence", "message", "iq"};
-- 
cgit v1.2.3


From 2d68866021180ac35c77b6022e717bc727280177 Mon Sep 17 00:00:00 2001
From: Waqas Hussain <waqas20@gmail.com>
Date: Mon, 19 Apr 2010 18:30:59 +0500
Subject: MUC: Include <status code='100'/> in a message, not in presence.
 Fixes various issues.

---
 plugins/muc/muc.lib.lua | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/plugins/muc/muc.lib.lua b/plugins/muc/muc.lib.lua
index 1cc001bb..1081c5ff 100644
--- a/plugins/muc/muc.lib.lua
+++ b/plugins/muc/muc.lib.lua
@@ -319,6 +319,11 @@ function room_mt:handle_to_occupant(origin, stanza) -- PM, vCards, etc
 								:tag("item", {affiliation=affiliation or "none", role=role or "none"}):up()
 								:tag("status", {code='110'}));
 						end
+						if self._data.whois == 'anyone' then -- non-anonymous?
+							self:_route_stanza(st.stanza("message", {from=to, to=from, type='groupchat'})
+								:tag("x", {xmlns='http://jabber.org/protocol/muc#user'})
+								:tag("status", {code='100'}));
+						end
 						self:send_history(from);
 					else -- banned
 						local reply = st.error_reply(stanza, "auth", "forbidden"):up();
@@ -799,9 +804,6 @@ function room_mt:_route_stanza(stanza)
 				end
 			end
 		end
-		if self._data.whois == 'anyone' then
-		    muc_child:tag('status', { code = '100' });
-		end
 	end
 	self:route_stanza(stanza);
 	if muc_child then
-- 
cgit v1.2.3