- if stanza.attr.to ~= nil and stanza.attr.from ~= nil then
- if privacy_lists.lists == nil or
- (session.activePrivacyList == nil or session.activePrivacyList == "") and
- (privacy_lists.default == nil or privacy_lists.default == "")
- then
- return; -- Nothing to block, default is Allow all
- end
- if jid_bare(stanza.attr.from) == bare_jid and jid_bare(stanza.attr.to) == bare_jid then
- module:log("debug", "Never block communications from one of a user's resources to another.");
- return; -- from one of a user's resource to another => HANDS OFF!
- end
-
- local idx;
- local list;
- local item;
- local listname = session.activePrivacyList;
- if listname == nil or listname == "" then
- listname = privacy_lists.default; -- no active list selected, use default list
- end
- idx = findNamedList(privacy_lists, listname);
- if idx == nil then
- module:log("error", "given privacy listname not found. name: %s", listname);
- return;
- end
- list = privacy_lists.lists[idx];
- if list == nil then
- module:log("info", "privacy list index wrong. index: %d", idx);
- return;
- end
- for _,item in ipairs(list.items) do
- local apply = false;
- local block = false;
- if (
- (stanza.name == "message" and item.message) or
- (stanza.name == "iq" and item.iq) or
- (stanza.name == "presence" and jid_bare(stanza.attr.to) == bare_jid and item["presence-in"]) or
- (stanza.name == "presence" and not stanza.attr.from or not stanza.attr.to or jid_bare(stanza.attr.from) == bare_jid and item["presence-out"]) or
- (item.message == false and item.iq == false and item["presence-in"] == false and item["presence-out"] == false)
- ) then
- apply = true;
+ local is_to_user = bare_jid == jid_bare(to);
+ local is_from_user = bare_jid == jid_bare(from);
+
+ module:log("debug", "stanza: %s, to: %s, from: %s", tostring(stanza.name), tostring(to), tostring(from));
+
+ if privacy_lists.lists == nil or
+ not (session.activePrivacyList or privacy_lists.default)
+ then
+ return; -- Nothing to block, default is Allow all
+ end
+ if is_from_user and is_to_user then
+ module:log("debug", "Not blocking communications between user's resources");
+ return; -- from one of a user's resource to another => HANDS OFF!
+ end
+
+ local item;
+ local listname = session.activePrivacyList;
+ if listname == nil then
+ listname = privacy_lists.default; -- no active list selected, use default list
+ end
+ local list = privacy_lists.lists[listname];
+ if not list then
+ module:log("debug", "given privacy list not found. name: %s", listname);
+ return;
+ end
+ for _,item in ipairs(list.items) do
+ local apply = false;
+ local block = false;
+ if (
+ (stanza.name == "message" and item.message) or
+ (stanza.name == "iq" and item.iq) or
+ (stanza.name == "presence" and is_to_user and item["presence-in"]) or
+ (stanza.name == "presence" and is_from_user and item["presence-out"]) or
+ (item.message == false and item.iq == false and item["presence-in"] == false and item["presence-out"] == false)
+ ) then
+ apply = true;
+ end
+ if apply then
+ local evilJid = {};
+ apply = false;
+ if is_to_user then
+ module:log("debug", "evil jid is (from): %s", from);
+ evilJid.node, evilJid.host, evilJid.resource = jid_split(from);
+ else
+ module:log("debug", "evil jid is (to): %s", to);
+ evilJid.node, evilJid.host, evilJid.resource = jid_split(to);