net.httpserver: Catch errors thrown in HTTP handlers.
[prosody.git] / plugins / mod_privacy.lua
index ca5d51fa0a5b850ff3689363c95de87761ebbd72..d5842e26c74d81509c7ef7308808ebe1786cbe68 100644 (file)
@@ -7,6 +7,8 @@
 -- COPYING file in the source package for more information.
 --
 
+module:add_feature("jabber:iq:privacy");
+
 local prosody = prosody;
 local st = require "util.stanza";
 local datamanager = require "util.datamanager";
@@ -93,8 +95,10 @@ function activateList(privacy_lists, origin, stanza, which, name)
        elseif which == "active" and list then
                origin.activePrivacyList = name;
                origin.send(st.reply(stanza));
+       elseif not list then
+               return {"cancel", "item-not-found", "No such list: "..name};
        else
-               return {"modify", "bad-request", "Either not active or default given or unknown list name specified."};
+               return {"modify", "bad-request", "No list chosen to be active or default."};
        end
        return true;
 end
@@ -199,7 +203,7 @@ function getList(privacy_lists, origin, stanza, name)
 
        if name == nil then
                if privacy_lists.lists then
-                       if origin.ActivePrivacyList then
+                       if origin.activePrivacyList then
                                reply:tag("active", {name=origin.activePrivacyList}):up();
                        end
                        if privacy_lists.default then
@@ -301,7 +305,7 @@ function checkIfNeedToBeBlocked(e, session)
        local origin, stanza = e.origin, e.stanza;
        local privacy_lists = datamanager.load(session.username, session.host, "privacy") or {};
        local bare_jid = session.username.."@"..session.host;
-       local to = stanza.attr.to;
+       local to = stanza.attr.to or bare_jid;
        local from = stanza.attr.from;
        
        local is_to_user = bare_jid == jid_bare(to);
@@ -438,7 +442,9 @@ function preCheckOutgoing(e)
                        e.stanza.attr.from = e.stanza.attr.from .. "/" .. session.resource;
                end
        end
-       return checkIfNeedToBeBlocked(e, session);
+       if session.username then -- FIXME do properly
+               return checkIfNeedToBeBlocked(e, session);
+       end
 end
 
 module:hook("pre-message/full", preCheckOutgoing, 500);