diff options
author | joe <joe@jerkface.net> | 2014-03-09 21:05:25 -0400 |
---|---|---|
committer | joe <joe@jerkface.net> | 2014-03-09 21:05:25 -0400 |
commit | e16e496a95392f6b62bb1f0d1eddaf40f0f99327 (patch) | |
tree | a836eedc396305ae0000fd3a4375df25c6175ab2 /xmppServer.hs | |
parent | c071d6c0395c5cbc1d34f4bec82cf702f6f84744 (diff) |
Send whitelist= attribute on probe replies
Diffstat (limited to 'xmppServer.hs')
-rw-r--r-- | xmppServer.hs | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/xmppServer.hs b/xmppServer.hs index fb056445..598ffe72 100644 --- a/xmppServer.hs +++ b/xmppServer.hs | |||
@@ -15,7 +15,7 @@ import Network.Socket | |||
15 | , SockAddr(..) | 15 | , SockAddr(..) |
16 | ) | 16 | ) |
17 | import System.Endian (fromBE32) | 17 | import System.Endian (fromBE32) |
18 | import Data.List (nub, (\\), intersect ) | 18 | import Data.List (nub, (\\), intersect, groupBy, sort ) |
19 | import Data.Monoid ( (<>) ) | 19 | import Data.Monoid ( (<>) ) |
20 | import qualified Data.Text as Text | 20 | import qualified Data.Text as Text |
21 | import qualified Data.Text.IO as Text | 21 | import qualified Data.Text.IO as Text |
@@ -590,11 +590,20 @@ answerProbe state mto k chan = do | |||
590 | 590 | ||
591 | flip (maybe $ return ()) muser $ \(u,conn,ch) -> do | 591 | flip (maybe $ return ()) muser $ \(u,conn,ch) -> do |
592 | 592 | ||
593 | -- only subscribed peers should get probe replies | 593 | resolved_subs <- resolvedFromRoster ConfigFiles.getSubscribers u |
594 | addrs <- subscribedPeers u | 594 | let gaddrs = groupBy (\a b -> snd a == snd b) (sort resolved_subs) |
595 | whitelist = do | ||
596 | xs <- gaddrs | ||
597 | x <- take 1 xs | ||
598 | guard $ snd x==k | ||
599 | mapMaybe fst xs | ||
600 | |||
601 | -- -- only subscribed peers should get probe replies | ||
602 | -- addrs <- subscribedPeers u | ||
603 | |||
595 | -- TODO: notify remote peer that they are unsubscribed? | 604 | -- TODO: notify remote peer that they are unsubscribed? |
596 | -- reply <- makeInformSubscription "jabber:server" to from False | 605 | -- reply <- makeInformSubscription "jabber:server" to from False |
597 | when (k `elem` map PeerKey addrs) $ do | 606 | when (not $ null whitelist) $ do |
598 | 607 | ||
599 | replies <- runTraversableT $ do | 608 | replies <- runTraversableT $ do |
600 | cbu <- lift . atomically $ readTVar (clientsByUser state) | 609 | cbu <- lift . atomically $ readTVar (clientsByUser state) |
@@ -605,7 +614,10 @@ answerProbe state mto k chan = do | |||
605 | let jid = unsplitJID (Just $ clientUser clientState | 614 | let jid = unsplitJID (Just $ clientUser clientState |
606 | , ch | 615 | , ch |
607 | ,Just $ clientResource clientState) | 616 | ,Just $ clientResource clientState) |
608 | return stanza { stanzaFrom = Just jid } | 617 | return stanza { stanzaFrom = Just jid |
618 | , stanzaType = (stanzaType stanza) | ||
619 | { presenceWhiteList = whitelist } | ||
620 | } | ||
609 | 621 | ||
610 | forM_ replies $ \reply -> do | 622 | forM_ replies $ \reply -> do |
611 | sendModifiedStanzaToPeer reply chan | 623 | sendModifiedStanzaToPeer reply chan |
@@ -739,7 +751,7 @@ resolvedFromRoster doit u = do | |||
739 | subs <- configText doit u | 751 | subs <- configText doit u |
740 | runTraversableT $ do | 752 | runTraversableT $ do |
741 | (mu,h,_) <- liftT $ splitJID `fmap` subs | 753 | (mu,h,_) <- liftT $ splitJID `fmap` subs |
742 | addr <- liftMT $ resolvePeer h | 754 | addr <- liftMT $ fmap nub $ resolvePeer h |
743 | return (mu,PeerKey addr) | 755 | return (mu,PeerKey addr) |
744 | 756 | ||
745 | clientCons state ktc u = do | 757 | clientCons state ktc u = do |