aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorWaqas Hussain <waqas20@gmail.com>2008-10-25 02:16:29 +0500
committerWaqas Hussain <waqas20@gmail.com>2008-10-25 02:16:29 +0500
commit17d7c83a7141e6d2142c9dece0845051c85ef592 (patch)
tree0cc596aa48b6a4f4505cee7271b268e631579ee7 /core
parentb1d1a87772aa583572642c2fc76fa5bba1ca8e9a (diff)
downloadprosody-17d7c83a7141e6d2142c9dece0845051c85ef592.tar.gz
prosody-17d7c83a7141e6d2142c9dece0845051c85ef592.zip
Inbound subscription approval
Diffstat (limited to 'core')
-rw-r--r--core/rostermanager.lua16
-rw-r--r--core/stanza_router.lua26
2 files changed, 34 insertions, 8 deletions
diff --git a/core/rostermanager.lua b/core/rostermanager.lua
index c39d28ed..a9be62aa 100644
--- a/core/rostermanager.lua
+++ b/core/rostermanager.lua
@@ -83,7 +83,7 @@ function load_roster(username, host)
return roster;
end
-- Attempt to load roster for non-loaded user
- -- TODO also support loading for offline user
+ return datamanager.load(username, host, "roster") or {};
end
function save_roster(username, host)
@@ -93,4 +93,18 @@ function save_roster(username, host)
return nil;
end
+function process_inbound_subscription_approval(username, host, jid)
+ local roster = load_roster(username, host);
+ local item = roster[jid];
+ if item and item.ask and (item.subscription == "none" or item.subscription == "from") then
+ if item.subscription == "none" then
+ item.subscription = "to";
+ else
+ item.subscription = "both";
+ end
+ item.ask = nil;
+ return datamanager.store(username, host, "roster", roster);
+ end
+end
+
return _M; \ No newline at end of file
diff --git a/core/stanza_router.lua b/core/stanza_router.lua
index 4b77b6b6..da7433c7 100644
--- a/core/stanza_router.lua
+++ b/core/stanza_router.lua
@@ -12,6 +12,8 @@ local send = require "core.sessionmanager".send_to_session;
local send_s2s = require "core.s2smanager".send_to_host;
local user_exists = require "core.usermanager".user_exists;
+local rostermanager = require "core.rostermanager";
+
local s2s_verify_dialback = require "core.s2smanager".verify_dialback;
local s2s_make_authenticated = require "core.s2smanager".make_authenticated;
local format = string.format;
@@ -194,15 +196,15 @@ function core_route_stanza(origin, stanza)
for k in pairs(user.sessions) do -- return presence for all resources
local pres = user.sessions[k].presence;
if pres then
- pres.attr.to = from; -- FIXME use from_bare?
+ pres.attr.to = from; -- FIXME use from_bare or from?
pres.attr.from = user.sessions[k].full_jid;
send(origin, pres);
- pres.attr.to = nil;
- pres.attr.from = nil;
end
end
+ pres.attr.to = nil;
+ pres.attr.from = nil;
else
- send(origin, st.presence({from=to_bare, to=origin.username.."@"..origin.host, type="unsubscribed"}));
+ send(origin, st.presence({from=to_bare, to=from_bare, type="unsubscribed"}));
end
elseif stanza.attr.type == "subscribe" then
-- TODO
@@ -210,9 +212,19 @@ function core_route_stanza(origin, stanza)
-- TODO
elseif stanza.attr.type == "subscribed" then
-- TODO
- -- sender.roster[recipient.bare_jid]. subscription = from or both
- -- sender.rosterpush recipient
- -- send presence for all sender resources to recipient.bare_jid
+ if rostermanager.process_inbound_subscription_approval(node, host, from_bare) then
+ rostermanager.roster_push(node, host, from_bare);
+ for k in pairs(user.sessions) do -- return presence for all resources
+ local pres = user.sessions[k].presence;
+ if pres then
+ pres.attr.to = from; -- FIXME use from_bare or from?
+ pres.attr.from = user.sessions[k].full_jid;
+ send(origin, pres);
+ end
+ end
+ pres.attr.to = nil;
+ pres.attr.from = nil;
+ end
elseif stanza.attr.type == "unsubscribed" then
-- TODO
end -- discard any other type