aboutsummaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorTobias Markmann <tm@ayena.de>2009-07-05 19:05:25 +0200
committerTobias Markmann <tm@ayena.de>2009-07-05 19:05:25 +0200
commitfa97be5e4dcd83cd57c51e764f6aa2a39b9833ba (patch)
tree04f1aa322632a0221c225ee6957b5863755a3b6d /plugins
parent4ce313959b678592a5fe0ef30b6813d058de45af (diff)
parent2c3ccf56744975a5f5acbc66d2e917e056467965 (diff)
downloadprosody-fa97be5e4dcd83cd57c51e764f6aa2a39b9833ba.tar.gz
prosody-fa97be5e4dcd83cd57c51e764f6aa2a39b9833ba.zip
Merge with main branch.
Diffstat (limited to 'plugins')
-rw-r--r--plugins/mod_console.lua13
-rw-r--r--plugins/mod_offline.lua47
-rw-r--r--plugins/mod_pep.lua9
-rw-r--r--plugins/mod_presence.lua212
4 files changed, 153 insertions, 128 deletions
diff --git a/plugins/mod_console.lua b/plugins/mod_console.lua
index 0f2c6711..966156f8 100644
--- a/plugins/mod_console.lua
+++ b/plugins/mod_console.lua
@@ -437,6 +437,8 @@ end
-------------
function printbanner(session)
+ local option = config.get("*", "core", "console_banner");
+if option == nil or option == "full" or option == "graphic" then
session.print [[
____ \ / _
| _ \ _ __ ___ ___ _-_ __| |_ _
@@ -446,7 +448,18 @@ session.print [[
A study in simplicity |___/
]]
+end
+if option == nil or option == "short" or option == "full" then
session.print("Welcome to the Prosody administration console. For a list of commands, type: help");
session.print("You may find more help on using this console in our online documentation at ");
session.print("http://prosody.im/doc/console\n");
end
+if option and option ~= "short" and option ~= "full" and option ~= "graphic" then
+ if type(option) == "string" then
+ session.print(option)
+ elseif type(option) == "function" then
+ setfenv(option, redirect_output(_G, session));
+ pcall(option, session);
+ end
+end
+end
diff --git a/plugins/mod_offline.lua b/plugins/mod_offline.lua
new file mode 100644
index 00000000..4fb82cc0
--- /dev/null
+++ b/plugins/mod_offline.lua
@@ -0,0 +1,47 @@
+
+local datamanager = require "util.datamanager";
+local st = require "util.stanza";
+local datetime = require "util.datetime";
+local ipairs = ipairs;
+
+module:add_feature("msgoffline");
+
+module:hook("message/offline/store", function(event)
+ local origin, stanza = event.origin, event.stanza;
+ local to = stanza.attr.to;
+ local node, host;
+ if to then
+ node, host = jid_split(to)
+ else
+ node, host = origin.username, origin.host;
+ end
+
+ stanza.attr.stamp, stanza.attr.stamp_legacy = datetime.datetime(), datetime.legacy();
+ local result = datamanager.list_append(node, host, "offline", st.preserialize(stanza));
+ stanza.attr.stamp, stanza.attr.stamp_legacy = nil, nil;
+
+ return true;
+end);
+
+module:hook("message/offline/broadcast", function(event)
+ local origin = event.origin;
+ local node, host = origin.username, origin.host;
+
+ local data = datamanager.list_load(node, host, "offline");
+ if not data then return true; end
+ for _, stanza in ipairs(data) do
+ stanza = st.deserialize(stanza);
+ stanza:tag("delay", {xmlns = "urn:xmpp:delay", from = host, stamp = stanza.attr.stamp}):up(); -- XEP-0203
+ stanza:tag("x", {xmlns = "jabber:x:delay", from = host, stamp = stanza.attr.stamp_legacy}):up(); -- XEP-0091 (deprecated)
+ stanza.attr.stamp, stanza.attr.stamp_legacy = nil, nil;
+ origin.send(stanza);
+ end
+ return true;
+end);
+
+module:hook("message/offline/delete", function(event)
+ local origin = event.origin;
+ local node, host = origin.username, origin.host;
+
+ return datamanager.list_store(node, host, "offline", nil);
+end);
diff --git a/plugins/mod_pep.lua b/plugins/mod_pep.lua
index 4a8300f1..0be681fb 100644
--- a/plugins/mod_pep.lua
+++ b/plugins/mod_pep.lua
@@ -54,8 +54,9 @@ local function publish_all(user, recipient, session)
local d = data[user];
local notify = recipients[user] and recipients[user][recipient];
if d and notify then
- for node, message in pairs(notify) do
- if d[node] then
+ for node in pairs(notify) do
+ local message = d[node];
+ if message then
message.attr.to = recipient;
session.send(message);
end
@@ -101,7 +102,7 @@ module:hook("presence/bare", function(event)
recipients[user] = recipients[user] or {};
if hash_map[hash] then
recipients[user][recipient] = hash_map[hash];
- publish_all(user, recipient);
+ publish_all(user, recipient, origin);
else
recipients[user][recipient] = hash;
origin.send(
@@ -192,7 +193,7 @@ module:hook("iq/bare/disco", function(event)
local notify = {};
for _, feature in pairs(disco.tags) do
if feature.name == "feature" and feature.attr.var then
- local nfeature = feature.attr.var:match("^(.*)+notify$");
+ local nfeature = feature.attr.var:match("^(.*)%+notify$");
if nfeature then notify[nfeature] = true; end
end
end
diff --git a/plugins/mod_presence.lua b/plugins/mod_presence.lua
index 80a2ecca..89136e3d 100644
--- a/plugins/mod_presence.lua
+++ b/plugins/mod_presence.lua
@@ -10,7 +10,7 @@ local log = module._log;
local require = require;
local pairs, ipairs = pairs, ipairs;
-local t_concat = table.concat;
+local t_concat, t_insert = table.concat, table.insert;
local s_find = string.find;
local tonumber = tonumber;
@@ -37,21 +37,6 @@ function core_route_stanza(origin, stanza)
_core_route_stanza(origin, stanza);
end
-function handle_presence(origin, stanza, from_bare, to_bare, core_route_stanza, inbound)
- local type = stanza.attr.type;
- if type and type ~= "unavailable" and type ~= "error" then
- if inbound then
- handle_inbound_presence_subscriptions_and_probes(origin, stanza, from_bare, to_bare, core_route_stanza);
- else
- handle_outbound_presence_subscriptions_and_probes(origin, stanza, from_bare, to_bare, core_route_stanza);
- end
- elseif not inbound and not stanza.attr.to then
- handle_normal_presence(origin, stanza, core_route_stanza);
- else
- core_route_stanza(origin, stanza);
- end
-end
-
local function select_top_resources(user)
local priority = 0;
local recipients = {};
@@ -76,93 +61,85 @@ local function recalc_resource_map(origin)
end
function handle_normal_presence(origin, stanza, core_route_stanza)
- if origin.roster then
- for jid in pairs(origin.roster) do -- broadcast to all interested contacts
- local subscription = origin.roster[jid].subscription;
- if subscription == "both" or subscription == "from" then
- stanza.attr.to = jid;
- core_route_stanza(origin, stanza);
- end
+ local roster = origin.roster;
+ local node, host = origin.username, origin.host;
+ for _, res in pairs(hosts[host].sessions[node].sessions) do -- broadcast to all resources
+ if res ~= origin and res.presence then -- to resource
+ stanza.attr.to = res.full_jid;
+ core_route_stanza(origin, stanza);
end
- local node, host = jid_split(stanza.attr.from);
- for _, res in pairs(hosts[host].sessions[node].sessions) do -- broadcast to all resources
- if res ~= origin and res.presence then -- to resource
- stanza.attr.to = res.full_jid;
- core_route_stanza(origin, stanza);
- end
+ end
+ for jid, item in pairs(roster) do -- broadcast to all interested contacts
+ if item.subscription == "both" or item.subscription == "from" then
+ stanza.attr.to = jid;
+ core_route_stanza(origin, stanza);
end
- if stanza.attr.type == nil and not origin.presence then -- initial presence
- local probe = st.presence({from = origin.full_jid, type = "probe"});
- for jid in pairs(origin.roster) do -- probe all contacts we are subscribed to
- local subscription = origin.roster[jid].subscription;
- if subscription == "both" or subscription == "to" then
- probe.attr.to = jid;
- core_route_stanza(origin, probe);
- end
- end
- for _, res in pairs(hosts[host].sessions[node].sessions) do -- broadcast from all available resources
- if res ~= origin and res.presence then
- res.presence.attr.to = origin.full_jid;
- core_route_stanza(res, res.presence);
- res.presence.attr.to = nil;
- end
- end
- if origin.roster.pending then -- resend incoming subscription requests
- for jid in pairs(origin.roster.pending) do
- origin.send(st.presence({type="subscribe", from=jid})); -- TODO add to attribute? Use original?
- end
+ end
+ if stanza.attr.type == nil and not origin.presence then -- initial presence
+ local probe = st.presence({from = origin.full_jid, type = "probe"});
+ for jid, item in pairs(roster) do -- probe all contacts we are subscribed to
+ if item.subscription == "both" or item.subscription == "to" then
+ probe.attr.to = jid;
+ core_route_stanza(origin, probe);
end
- local request = st.presence({type="subscribe", from=origin.username.."@"..origin.host});
- for jid, item in pairs(origin.roster) do -- resend outgoing subscription requests
- if item.ask then
- request.attr.to = jid;
- core_route_stanza(origin, request);
- end
+ end
+ for _, res in pairs(hosts[host].sessions[node].sessions) do -- broadcast from all available resources
+ if res ~= origin and res.presence then
+ res.presence.attr.to = origin.full_jid;
+ core_route_stanza(res, res.presence);
+ res.presence.attr.to = nil;
end
- local offline = offlinemanager.load(node, host);
- if offline then
- for _, msg in ipairs(offline) do
- origin.send(msg); -- FIXME do we need to modify to/from in any way?
- end
- offlinemanager.deleteAll(node, host);
+ end
+ if roster.pending then -- resend incoming subscription requests
+ for jid in pairs(roster.pending) do
+ origin.send(st.presence({type="subscribe", from=jid})); -- TODO add to attribute? Use original?
end
end
- if stanza.attr.type == "unavailable" then
- origin.presence = nil;
- if origin.priority then
- origin.priority = nil;
- recalc_resource_map(origin);
+ local request = st.presence({type="subscribe", from=origin.username.."@"..origin.host});
+ for jid, item in pairs(roster) do -- resend outgoing subscription requests
+ if item.ask then
+ request.attr.to = jid;
+ core_route_stanza(origin, request);
end
- if origin.directed then
- local old_from = stanza.attr.from;
- stanza.attr.from = origin.full_jid;
- for jid in pairs(origin.directed) do
- stanza.attr.to = jid;
- core_route_stanza(origin, stanza);
- end
- stanza.attr.from = old_from;
- origin.directed = nil;
+ end
+ local offline = offlinemanager.load(node, host);
+ if offline then
+ for _, msg in ipairs(offline) do
+ origin.send(msg); -- FIXME do we need to modify to/from in any way?
end
- else
- origin.presence = stanza;
- local priority = stanza:child_with_name("priority");
- if priority and #priority > 0 then
- priority = t_concat(priority);
- if s_find(priority, "^[+-]?[0-9]+$") then
- priority = tonumber(priority);
- if priority < -128 then priority = -128 end
- if priority > 127 then priority = 127 end
- else priority = 0; end
- else priority = 0; end
- if origin.priority ~= priority then
- origin.priority = priority;
- recalc_resource_map(origin);
+ offlinemanager.deleteAll(node, host);
+ end
+ end
+ if stanza.attr.type == "unavailable" then
+ origin.presence = nil;
+ if origin.priority then
+ origin.priority = nil;
+ recalc_resource_map(origin);
+ end
+ if origin.directed then
+ for jid in pairs(origin.directed) do
+ stanza.attr.to = jid;
+ core_route_stanza(origin, stanza);
end
+ origin.directed = nil;
end
- stanza.attr.to = nil; -- reset it
else
- log("warn", "presence recieved from client with no roster");
+ origin.presence = stanza;
+ local priority = stanza:child_with_name("priority");
+ if priority and #priority > 0 then
+ priority = t_concat(priority);
+ if s_find(priority, "^[+-]?[0-9]+$") then
+ priority = tonumber(priority);
+ if priority < -128 then priority = -128 end
+ if priority > 127 then priority = 127 end
+ else priority = 0; end
+ else priority = 0; end
+ if origin.priority ~= priority then
+ origin.priority = priority;
+ recalc_resource_map(origin);
+ end
end
+ stanza.attr.to = nil; -- reset it
end
function send_presence_of_available_resources(user, host, jid, recipient_session, core_route_stanza)
@@ -268,39 +245,6 @@ function handle_inbound_presence_subscriptions_and_probes(origin, stanza, from_b
stanza.attr.from, stanza.attr.to = st_from, st_to;
end
-local function presence_handler(data)
- local origin, stanza = data.origin, data.stanza;
- local to = stanza.attr.to;
- local node, host = jid_split(to);
- local to_bare = jid_bare(to);
- local from_bare = jid_bare(stanza.attr.from);
- if origin.type == "c2s" then
- if to ~= nil and not(origin.roster[to_bare] and (origin.roster[to_bare].subscription == "both" or origin.roster[to_bare].subscription == "from")) then -- directed presence
- origin.directed = origin.directed or {};
- origin.directed[to] = true; -- FIXME does it make more sense to add to_bare rather than to?
- end
- if stanza.attr.type ~= nil and stanza.attr.type ~= "unavailable" and stanza.attr.type ~= "error" then
- handle_outbound_presence_subscriptions_and_probes(origin, stanza, from_bare, to_bare, core_route_stanza);
- elseif not to then
- handle_normal_presence(origin, stanza, core_route_stanza);
- else
- core_route_stanza(origin, stanza);
- end
- elseif (origin.type == "s2sin" or origin.type == "component") and hosts[host] then
- if stanza.attr.type ~= nil and stanza.attr.type ~= "unavailable" and stanza.attr.type ~= "error" then
- handle_inbound_presence_subscriptions_and_probes(origin, stanza, from_bare, to_bare, core_route_stanza);
- else
- core_route_stanza(origin, stanza);
- end
- end
- return true;
-end
-
-prosody.events.add_handler(module:get_host().."/presence", presence_handler);
-module.unload = function()
- prosody.events.remove_handler(module:get_host().."/presence", presence_handler);
-end
-
local outbound_presence_handler = function(data)
-- outbound presence recieved
local origin, stanza = data.origin, data.stanza;
@@ -371,3 +315,23 @@ module:hook("presence/full", function(data)
end -- resource not online, discard
return true;
end);
+
+module:hook("resource-unbind", function(event)
+ local session, err = event.session, event.error;
+ -- Send unavailable presence
+ if session.presence then
+ local pres = st.presence{ type = "unavailable" };
+ if not(err) or err == "closed" then err = "connection closed"; end
+ pres:tag("status"):text("Disconnected: "..err):up();
+ session:dispatch_stanza(pres);
+ elseif session.directed then
+ local pres = st.presence{ type = "unavailable" };
+ if not(err) or err == "closed" then err = "connection closed"; end
+ pres:tag("status"):text("Disconnected: "..err):up();
+ for jid in pairs(session.directed) do
+ pres.attr.to = jid;
+ core_route_stanza(session, pres);
+ end
+ session.directed = nil;
+ end
+end);