Software /
code /
prosody
Comparison
plugins/mod_privacy.lua @ 3069:c3df9053e0a9
mod_privacy: Fix several possible tracebacks when either the contact is a host JID, or the contact isn't in your roster and you have roster group/subscription rules in place
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Fri, 21 May 2010 19:20:21 +0100 |
parent | 3068:fc7c693e094a |
child | 3085:cf01b0725272 |
comparison
equal
deleted
inserted
replaced
3068:fc7c693e094a | 3069:c3df9053e0a9 |
---|---|
11 local st = require "util.stanza"; | 11 local st = require "util.stanza"; |
12 local datamanager = require "util.datamanager"; | 12 local datamanager = require "util.datamanager"; |
13 local bare_sessions, full_sessions = bare_sessions, full_sessions; | 13 local bare_sessions, full_sessions = bare_sessions, full_sessions; |
14 local util_Jid = require "util.jid"; | 14 local util_Jid = require "util.jid"; |
15 local jid_bare = util_Jid.bare; | 15 local jid_bare = util_Jid.bare; |
16 local jid_split = util_Jid.split; | 16 local jid_split, jid_join = util_Jid.split, util_Jid.join; |
17 local load_roster = require "core.rostermanager".load_roster; | 17 local load_roster = require "core.rostermanager".load_roster; |
18 local to_number = tonumber; | 18 local to_number = tonumber; |
19 | 19 |
20 function isListUsed(origin, name, privacy_lists) | 20 function isListUsed(origin, name, privacy_lists) |
21 local user = bare_sessions[origin.username.."@"..origin.host]; | 21 local user = bare_sessions[origin.username.."@"..origin.host]; |
358 (evilJid.host and item.value == evilJid.host) then | 358 (evilJid.host and item.value == evilJid.host) then |
359 apply = true; | 359 apply = true; |
360 block = (item.action == "deny"); | 360 block = (item.action == "deny"); |
361 elseif item.type == "group" then | 361 elseif item.type == "group" then |
362 local roster = load_roster(session.username, session.host); | 362 local roster = load_roster(session.username, session.host); |
363 local groups = roster[evilJid.node .. "@" .. evilJid.host].groups; | 363 local roster_entry = roster[jid_join(evilJid.node, evilJid.host)]; |
364 for group in pairs(groups) do | 364 if roster_entry then |
365 if group == item.value then | 365 local groups = roster_entry.groups; |
366 apply = true; | 366 for group in pairs(groups) do |
367 block = (item.action == "deny"); | 367 if group == item.value then |
368 break; | 368 apply = true; |
369 block = (item.action == "deny"); | |
370 break; | |
371 end | |
369 end | 372 end |
370 end | 373 end |
371 elseif item.type == "subscription" and evilJid.node ~= nil and evilJid.host ~= nil then -- we need a valid bare evil jid | 374 elseif item.type == "subscription" then -- we need a valid bare evil jid |
372 local roster = load_roster(session.username, session.host); | 375 local roster = load_roster(session.username, session.host); |
373 if roster[evilJid.node .. "@" .. evilJid.host].subscription == item.value then | 376 local roster_entry = roster[jid_join(evilJid.node, evilJid.host)]; |
377 if (not(roster_entry) and item.value == "none") | |
378 or (roster_entry and roster_entry.subscription == item.value) then | |
374 apply = true; | 379 apply = true; |
375 block = (item.action == "deny"); | 380 block = (item.action == "deny"); |
376 end | 381 end |
377 elseif item.type == nil then | 382 elseif item.type == nil then |
378 apply = true; | 383 apply = true; |