Software /
code /
prosody
Changeset
171:28f420d057a0
Inbound subscription approval
author | Waqas Hussain <waqas20@gmail.com> |
---|---|
date | Sat, 25 Oct 2008 02:16:29 +0500 |
parents | 170:e7bff9cfbb65 |
children | 172:71247788c7c7 |
files | core/rostermanager.lua core/stanza_router.lua |
diffstat | 2 files changed, 34 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/core/rostermanager.lua Sat Oct 25 01:48:34 2008 +0500 +++ b/core/rostermanager.lua Sat Oct 25 02:16:29 2008 +0500 @@ -83,7 +83,7 @@ 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 @@ 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
--- a/core/stanza_router.lua Sat Oct 25 01:48:34 2008 +0500 +++ b/core/stanza_router.lua Sat Oct 25 02:16:29 2008 +0500 @@ -12,6 +12,8 @@ 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 @@ 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 @@ -- 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