Merge with Paul

Sun, 03 Jan 2010 17:54:26 +0000

author
Matthew Wild <mwild1@gmail.com>
date
Sun, 03 Jan 2010 17:54:26 +0000
changeset 2417
70f65a48f05e
parent 2416
89be536aae25 (diff)
parent 2415
eb383f58624b (current diff)
child 2418
c35deaea53b9

Merge with Paul

--- a/plugins/muc/muc.lib.lua	Sun Jan 03 09:51:01 2010 -0800
+++ b/plugins/muc/muc.lib.lua	Sun Jan 03 17:54:26 2010 +0000
@@ -402,9 +402,23 @@
 			:tag("field", {type='boolean', label='Make Room Publicly Searchable?', var='muc#roomconfig_publicroom'})
 				:tag("value"):text(self._data.hidden and "0" or "1"):up()
 			:up()
+			:tag("field", {type='list-single', label='Who May Discover Real JIDs?', var='muc#roomconfig_whois'})
+			    :tag("value"):text(self._data.whois or 'moderators'):up()
+			    :tag("option", {label = 'Moderators Only'})
+				:tag("value"):text('moderators'):up()
+				:up()
+			    :tag("option", {label = 'Anyone'})
+				:tag("value"):text('anyone'):up()
+				:up()
+			:up()
 	);
 end
 
+local valid_whois = {
+    moderators = true,
+    anyone = true,
+}
+
 function room_mt:process_form(origin, stanza)
 	local query = stanza.tags[1];
 	local form;
@@ -420,19 +434,47 @@
 	end
 	if fields.FORM_TYPE ~= "http://jabber.org/protocol/muc#roomconfig" then origin.send(st.error_reply(stanza, "cancel", "bad-request")); return; end
 
+	local dirty = false
+
 	local persistent = fields['muc#roomconfig_persistentroom'];
 	if persistent == "0" or persistent == "false" then persistent = nil; elseif persistent == "1" or persistent == "true" then persistent = true;
 	else origin.send(st.error_reply(stanza, "cancel", "bad-request")); return; end
+	dirty = dirty or (self._data.persistent ~= persistent)
 	self._data.persistent = persistent;
 	module:log("debug", "persistent=%s", tostring(persistent));
 
 	local public = fields['muc#roomconfig_publicroom'];
 	if public == "0" or public == "false" then public = nil; elseif public == "1" or public == "true" then public = true;
 	else origin.send(st.error_reply(stanza, "cancel", "bad-request")); return; end
+	dirty = dirty or (self._data.hidden ~= (not public and true or nil))
 	self._data.hidden = not public and true or nil;
 
+	local whois = fields['muc#roomconfig_whois'];
+	if not valid_whois[whois] then
+	    origin.send(st.error_reply(stanza, 'cancel', 'bad-request'));
+	    return;
+	end
+	local whois_changed = self._data.whois ~= whois
+	self._data.whois = whois
+	module:log('debug', 'whois=%s', tostring(whois))
+
 	if self.save then self:save(true); end
 	origin.send(st.reply(stanza));
+
+	if dirty or whois_changed then
+	    local msg = st.message({type='groupchat', from=self.jid})
+		    :tag('x', {xmlns='http://jabber.org/protocol/muc#user'}):up()
+
+	    if dirty then
+		msg.tags[1]:tag('status', {code = '104'})
+	    end
+	    if whois_changed then
+		local code = (whois == 'moderators') and 173 or 172
+		msg.tags[1]:tag('status', {code = code})
+	    end
+
+	    self:broadcast_message(msg, false)
+	end
 end
 
 function room_mt:destroy(newjid, reason, password)
@@ -741,13 +783,11 @@
 	local from_occupant = self._occupants[stanza.attr.from];
 	if stanza.name == "presence" then
 		if to_occupant and from_occupant then
-			if to_occupant.role == "moderator" or jid_bare(to_occupant.jid) == jid_bare(from_occupant.jid) then
-				for i=#stanza.tags,1,-1 do
-					local tag = stanza.tags[i];
-					if tag.name == "x" and tag.attr.xmlns == "http://jabber.org/protocol/muc#user" then
-						muc_child = tag;
-						break;
-					end
+			if self._data.whois == 'anyone' then
+			    muc_child = stanza:get_child("x", "http://jabber.org/protocol/muc#user");
+			else
+				if to_occupant.role == "moderator" or jid_bare(to_occupant.jid) == jid_bare(from_occupant.jid) then
+					muc_child = stanza:get_child("x", "http://jabber.org/protocol/muc#user");
 				end
 			end
 		end
@@ -762,6 +802,9 @@
 				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
@@ -780,7 +823,9 @@
 		jid = jid;
 		_jid_nick = {};
 		_occupants = {};
-		_data = {};
+		_data = {
+		    whois = 'moderators',
+		};
 		_affiliations = {};
 	}, room_mt);
 end
--- a/prosodyctl	Sun Jan 03 09:51:01 2010 -0800
+++ b/prosodyctl	Sun Jan 03 17:54:26 2010 +0000
@@ -137,18 +137,33 @@
 end
 
 local function getchar(n)
-	os.execute("stty raw -echo");
-	local ok, char = pcall(io.read, n or 1);
-	os.execute("stty sane");
+	local stty_ret = os.execute("stty raw -echo 2>/dev/null");
+	local ok, char;
+	if stty_ret == 0 then
+		ok, char = pcall(io.read, n or 1);
+		os.execute("stty sane");
+	else
+		ok, char = pcall(io.read, "*l");
+		if ok then
+			char = char:sub(1, n or 1);
+		end
+	end
 	if ok then
 		return char;
 	end
 end
 	
 local function getpass()
-	os.execute("stty -echo");
+	local stty_ret = os.execute("stty -echo 2>/dev/null");
+	if stty_ret ~= 0 then
+		io.write("\027[08m"); -- ANSI 'hidden' text attribute
+	end
 	local ok, pass = pcall(io.read, "*l");
-	os.execute("stty sane");
+	if stty_ret == 0 then
+		os.execute("stty sane");
+	else
+		io.write("\027[00m");
+	end
 	io.write("\n");
 	if ok then
 		return pass;

mercurial