aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2016-12-10 02:55:38 +0100
committerKim Alvefur <zash@zash.se>2016-12-10 02:55:38 +0100
commit10a290e111c447b2062e103397058ce6ca8c7cfc (patch)
tree0c45bcdafed730fb0e14edfd08a8f649bf100fa6
parent4688968fe15623c69158d4ceef63d83e3ef2ddb2 (diff)
parentae46d59b51d61f816e70c128717e9fd1b9b02baf (diff)
downloadprosody-10a290e111c447b2062e103397058ce6ca8c7cfc.tar.gz
prosody-10a290e111c447b2062e103397058ce6ca8c7cfc.zip
Merge 0.10->trunk
-rw-r--r--.hgignore1
-rw-r--r--core/rostermanager.lua13
-rw-r--r--plugins/mod_blocklist.lua56
-rw-r--r--plugins/mod_carbons.lua10
-rw-r--r--plugins/mod_presence.lua4
5 files changed, 51 insertions, 33 deletions
diff --git a/.hgignore b/.hgignore
index 7937da24..1c17b0f7 100644
--- a/.hgignore
+++ b/.hgignore
@@ -1,5 +1,6 @@
syntax: glob
.hgignore
+.luacheckcache
data
local
www_files
diff --git a/core/rostermanager.lua b/core/rostermanager.lua
index 58d1f16e..88bd1e66 100644
--- a/core/rostermanager.lua
+++ b/core/rostermanager.lua
@@ -234,6 +234,18 @@ local function is_contact_subscribed(username, host, jid)
local item = roster[jid];
return item and (item.subscription == "from" or item.subscription == "both"), err;
end
+local function is_user_subscribed(username, host, jid)
+ do
+ local selfjid = username.."@"..host;
+ local user_subscription = _get_online_roster_subscription(selfjid, jid);
+ if user_subscription then return (user_subscription == "both" or user_subscription == "to"); end
+ local contact_subscription = _get_online_roster_subscription(jid, selfjid);
+ if contact_subscription then return (contact_subscription == "both" or contact_subscription == "from"); end
+ end
+ local roster, err = load_roster(username, host);
+ local item = roster[jid];
+ return item and (item.subscription == "to" or item.subscription == "both"), err;
+end
function is_contact_pending_in(username, host, jid)
local roster = load_roster(username, host);
@@ -350,6 +362,7 @@ return {
process_inbound_subscription_cancellation = process_inbound_subscription_cancellation;
process_inbound_unsubscribe = process_inbound_unsubscribe;
is_contact_subscribed = is_contact_subscribed;
+ is_user_subscribed = is_user_subscribed;
is_contact_pending_in = is_contact_pending_in;
set_contact_pending_in = set_contact_pending_in;
is_contact_pending_out = is_contact_pending_out;
diff --git a/plugins/mod_blocklist.lua b/plugins/mod_blocklist.lua
index 9083dda4..283d52fa 100644
--- a/plugins/mod_blocklist.lua
+++ b/plugins/mod_blocklist.lua
@@ -54,26 +54,21 @@ end
-- Migrates from the old mod_privacy storage
local function migrate_privacy_list(username)
- local migrated_data = { [false] = "not empty" };
local legacy_data = module:open_store("privacy"):get(username);
- if legacy_data and legacy_data.lists and legacy_data.default then
- legacy_data = legacy_data.lists[legacy_data.default];
- legacy_data = legacy_data and legacy_data.items;
- else
- return migrated_data;
- end
- if legacy_data then
- module:log("info", "Migrating blocklist from mod_privacy storage for user '%s'", username);
- local item, jid;
- for i = 1, #legacy_data do
- item = legacy_data[i];
- if item.type == "jid" and item.action == "deny" then
- jid = jid_prep(item.value);
- if not jid then
- module:log("warn", "Invalid JID in privacy store for user '%s' not migrated: %s", username, tostring(item.value));
- else
- migrated_data[jid] = true;
- end
+ if not legacy_data or not legacy_data.lists or not legacy_data.default then return; end
+ local default_list = legacy_data.lists[legacy_data.default];
+ if not default_list or not default_list.items then return; end
+
+ local migrated_data = { [false] = { created = os.time(); migrated = "privacy" }};
+
+ module:log("info", "Migrating blocklist from mod_privacy storage for user '%s'", username);
+ for _, item in ipairs(default_list.items) do
+ if item.type == "jid" and item.action == "deny" then
+ local jid = jid_prep(item.value);
+ if not jid then
+ module:log("warn", "Invalid JID in privacy store for user '%s' not migrated: %s", username, tostring(item.value));
+ else
+ migrated_data[jid] = true;
end
end
end
@@ -82,10 +77,7 @@ local function migrate_privacy_list(username)
end
local function get_blocklist(username)
- local blocklist = cache[username];
- if not blocklist then
- blocklist = cache2:get(username);
- end
+ local blocklist = cache2:get(username);
if not blocklist then
if not user_exists(username, module.host) then
return null_blocklist;
@@ -94,6 +86,9 @@ local function get_blocklist(username)
if not blocklist then
blocklist = migrate_privacy_list(username);
end
+ if not blocklist then
+ blocklist = { [false] = { created = os.time(); }; };
+ end
cache2:set(username, blocklist);
end
cache[username] = blocklist;
@@ -104,7 +99,7 @@ module:hook("iq-get/self/urn:xmpp:blocking:blocklist", function (event)
local origin, stanza = event.origin, event.stanza;
local username = origin.username;
local reply = st.reply(stanza):tag("blocklist", { xmlns = "urn:xmpp:blocking" });
- local blocklist = get_blocklist(username);
+ local blocklist = cache[username] or get_blocklist(username);
for jid in pairs(blocklist) do
if jid then
reply:tag("item", { jid = jid }):up();
@@ -158,20 +153,25 @@ local function edit_blocklist(event)
return true;
end
- local blocklist = get_blocklist(username);
+ local blocklist = cache[username] or get_blocklist(username);
- local new_blocklist = {};
+ local new_blocklist = {
+ -- We set the [false] key to someting as a signal not to migrate privacy lists
+ [false] = blocklist[false] or { created = os.time(); };
+ };
+ if type(blocklist[false]) == "table" then
+ new_blocklist[false].modified = os.time();
+ end
if is_blocking or next(new) then
for jid in pairs(blocklist) do
- new_blocklist[jid] = true;
+ if jid then new_blocklist[jid] = true; end
end
for jid in pairs(new) do
new_blocklist[jid] = is_blocking;
end
-- else empty the blocklist
end
- new_blocklist[false] = "not empty"; -- In order to avoid doing the migration thing twice
local ok, err = set_blocklist(username, new_blocklist);
if ok then
diff --git a/plugins/mod_carbons.lua b/plugins/mod_carbons.lua
index 4984b908..cb7d9233 100644
--- a/plugins/mod_carbons.lua
+++ b/plugins/mod_carbons.lua
@@ -24,21 +24,23 @@ local function message_handler(event, c2s)
local origin, stanza = event.origin, event.stanza;
local orig_type = stanza.attr.type or "normal";
local orig_from = stanza.attr.from;
+ local bare_from = jid_bare(orig_from);
local orig_to = stanza.attr.to;
-
+ local bare_to = jid_bare(orig_to);
+
if not(orig_type == "chat" or (orig_type == "normal" and stanza:get_child("body"))) then
return -- Only chat type messages
end
-- Stanza sent by a local client
- local bare_jid = jid_bare(orig_from);
+ local bare_jid = bare_from; -- JID of the local user
local target_session = origin;
local top_priority = false;
- local user_sessions = bare_sessions[bare_jid];
+ local user_sessions = bare_sessions[bare_from];
-- Stanza about to be delivered to a local client
if not c2s then
- bare_jid = jid_bare(orig_to);
+ bare_jid = bare_to;
target_session = full_sessions[orig_to];
user_sessions = bare_sessions[bare_jid];
if not target_session and user_sessions then
diff --git a/plugins/mod_presence.lua b/plugins/mod_presence.lua
index e4a317bc..2acc7db2 100644
--- a/plugins/mod_presence.lua
+++ b/plugins/mod_presence.lua
@@ -178,7 +178,9 @@ function handle_outbound_presence_subscriptions_and_probes(origin, stanza, from_
end
core_post_stanza(origin, stanza);
send_presence_of_available_resources(node, host, to_bare, origin);
- core_post_stanza(origin, st.presence({ type = "probe", from = from_bare, to = to_bare }));
+ if rostermanager.is_user_subscribed(node, host, to_bare) then
+ core_post_stanza(origin, st.presence({ type = "probe", from = from_bare, to = to_bare }));
+ end
elseif stanza.attr.type == "unsubscribed" then
-- 1. send unavailable
-- 2. route stanza