Comparison

mod_privacy/mod_privacy.lua @ 39:b84b2b026eb4

mod_privacy: never block communications from one of a user's resources to another.
author Thilo Cestonaro <thilo@cestona.ro>
date Tue, 13 Oct 2009 23:03:58 +0200
parent 27:d91cb13ef0ee
child 41:0381d5d38c37
comparison
equal deleted inserted replaced
38:b9bf8a35b064 39:b84b2b026eb4
329 end 329 end
330 return false; 330 return false;
331 end, 500); 331 end, 500);
332 332
333 function checkIfNeedToBeBlocked(e, session) 333 function checkIfNeedToBeBlocked(e, session)
334
335 local origin, stanza = e.origin, e.stanza; 334 local origin, stanza = e.origin, e.stanza;
336 local privacy_lists = datamanager.load(session.username, session.host, "privacy") or {}; 335 local privacy_lists = datamanager.load(session.username, session.host, "privacy") or {};
337 local bare_jid = session.username.."@"..session.host; 336 local bare_jid = session.username.."@"..session.host;
338 337
339 -- module:log("debug", "Where are we from: %s", debug.traceback())
340 module:log("debug", "checkIfNeedToBeBlocked: username: %s, host: %s", session.username, session.host); 338 module:log("debug", "checkIfNeedToBeBlocked: username: %s, host: %s", session.username, session.host);
341 module:log("debug", "stanza: %s, to: %s, form: %s", stanza.name, stanza.attr.to or "nil", stanza.attr.from or "nil"); 339 module:log("debug", "stanza: %s, to: %s, form: %s", stanza.name, stanza.attr.to or "nil", stanza.attr.from or "nil");
342 340
343 if stanza.attr.to ~= nil and stanza.attr.from ~= nil then 341 if stanza.attr.to ~= nil and stanza.attr.from ~= nil then
344 module:log("debug", "privacy_lists.lists: %s", tostring(privacy_lists.lists)); 342 module:log("debug", "privacy_lists.lists: %s", tostring(privacy_lists.lists));
349 (privacy_lists.default == nil or privacy_lists.default == "") 347 (privacy_lists.default == nil or privacy_lists.default == "")
350 then 348 then
351 module:log("debug", "neither active nor default list set (both are nil) or privacy_lists totally nil. So nothing to do => default is Allow All."); 349 module:log("debug", "neither active nor default list set (both are nil) or privacy_lists totally nil. So nothing to do => default is Allow All.");
352 return; -- Nothing to block, default is Allow all 350 return; -- Nothing to block, default is Allow all
353 end 351 end
354 352 if jid_bare(stanza.attr.from) == bare_jid and jid_bare(stanza.attr.to) == bare_jid then
353 module:log("debug", "Never block communications from one of a user's resources to another.");
354 return; -- from one of a user's resource to another => HANDS OFF!
355 end
356
355 local idx; 357 local idx;
356 local list; 358 local list;
357 local item; 359 local item;
358 local listname = session.activePrivacyList; 360 local listname = session.activePrivacyList;
359 if listname == nil or listname == "" then 361 if listname == nil or listname == "" then
480 end 482 end
481 return; 483 return;
482 end 484 end
483 485
484 function preCheckOutgoing(e) 486 function preCheckOutgoing(e)
485 local session; 487 local session = e.origin;
486 if e.stanza.attr.from ~= nil then 488 if e.stanza.attr.from == nil then
487 local node, host, resource = jid_split(e.stanza.attr.from); 489 e.stanza.attr.form = session.username .. "@" .. session.host;
488 if node == nil or host == nil then 490 if session.resource ~= nil then
489 return; 491 e.stanza.attr.from = e.stanza.attr.form .. "/" .. session.resource;
490 end 492 end
491 if resource == nil then 493 end
492 local prio = 0; 494 return checkIfNeedToBeBlocked(e, session);
493 local session_;
494 if bare_sessions[node.."@"..host] ~= nil then
495 for resource, session_ in pairs(bare_sessions[node.."@"..host].sessions) do
496 if session_.priority > prio then
497 session = session_;
498 prio = session_.priority;
499 end
500 end
501 end
502 else
503 session = full_sessions[node.."@"..host.."/"..resource];
504 end
505 if session ~= nil then
506 return checkIfNeedToBeBlocked(e, session);
507 else
508 module:log("debug", "preCheckOutgoing: Couldn't get session for jid: %s@%s/%s", node or "nil", host or "nil", resource or "nil")
509 end
510 end
511 return;
512 end 495 end
513 496
514 497
515 module:hook("pre-message/full", preCheckOutgoing, 500); 498 module:hook("pre-message/full", preCheckOutgoing, 500);
516 module:hook("pre-message/bare", preCheckOutgoing, 500); 499 module:hook("pre-message/bare", preCheckOutgoing, 500);