diff options
Diffstat (limited to 'xmppServer.hs')
-rw-r--r-- | xmppServer.hs | 34 |
1 files changed, 20 insertions, 14 deletions
diff --git a/xmppServer.hs b/xmppServer.hs index 0f2b7c89..d450988c 100644 --- a/xmppServer.hs +++ b/xmppServer.hs | |||
@@ -4,6 +4,7 @@ import System.Posix.Signals | |||
4 | import Control.Concurrent.STM | 4 | import Control.Concurrent.STM |
5 | import Control.Concurrent.STM.TMVar | 5 | import Control.Concurrent.STM.TMVar |
6 | import Control.Monad.Trans.Resource (runResourceT) | 6 | import Control.Monad.Trans.Resource (runResourceT) |
7 | import Control.Monad.Trans | ||
7 | import Control.Monad.IO.Class (MonadIO, liftIO) | 8 | import Control.Monad.IO.Class (MonadIO, liftIO) |
8 | import Network.Socket | 9 | import Network.Socket |
9 | ( addrAddress | 10 | ( addrAddress |
@@ -240,21 +241,26 @@ getBuddies' = textAdapter ConfigFiles.getBuddies | |||
240 | getSolicited' :: Text -> IO [Text] | 241 | getSolicited' :: Text -> IO [Text] |
241 | getSolicited' = textAdapter ConfigFiles.getSolicited | 242 | getSolicited' = textAdapter ConfigFiles.getSolicited |
242 | 243 | ||
243 | sendProbesAndSolicitations state k chan = do | 244 | sendProbesAndSolicitations state k laddr chan = do |
244 | cbu <- atomically $ readTVar $ clientsByUser state | 245 | cbu <- atomically $ readTVar $ clientsByUser state |
245 | -- get all buddies & solicited matching k for all users | 246 | -- get all buddies & solicited matching k for all users |
246 | us <- runTraversableT $ do | 247 | runTraversableT $ do |
247 | user <- liftT $ Map.keys cbu | 248 | user <- liftT $ Map.keys cbu |
248 | (isbud,getter) <- liftT [(True ,getBuddies' ) | 249 | (isbud,getter) <- liftT [(True ,getBuddies' ) |
249 | ,(False,getSolicited')] | 250 | ,(False,getSolicited')] |
250 | bud <- liftMT $ getter user | 251 | bud <- liftMT $ getter user |
251 | let (u,h,r) = splitJID bud | 252 | let (u,h,r) = splitJID bud |
252 | addr <- liftMT $ resolvePeer h | 253 | addr <- liftMT $ resolvePeer h |
253 | liftT $ guard (PeerKey addr == k) | 254 | liftT $ guard (PeerKey addr == k) |
254 | return (isbud,u) | 255 | -- return (isbud,u) |
255 | 256 | let make = if isbud then presenceProbe | |
256 | let _ = us :: [(Bool,Maybe UserName)] | 257 | else presenceSolicitation |
257 | -- send probes for buddies, solicitations for solicited. | 258 | toh = peerKeyToText k |
259 | jid = unsplitJID (u,toh,r) | ||
260 | me = addrToText laddr | ||
261 | stanza <- lift $ make me jid | ||
262 | -- send probes for buddies, solicitations for solicited. | ||
263 | lift $ atomically $ writeTChan chan stanza | ||
258 | return () | 264 | return () |
259 | 265 | ||
260 | newConn state k addr outchan = do | 266 | newConn state k addr outchan = do |
@@ -262,7 +268,7 @@ newConn state k addr outchan = do | |||
262 | $ Map.insert k Conn { connChan = outchan | 268 | $ Map.insert k Conn { connChan = outchan |
263 | , auxAddr = addr } | 269 | , auxAddr = addr } |
264 | when (isPeerKey k) | 270 | when (isPeerKey k) |
265 | $ sendProbesAndSolicitations state k outchan | 271 | $ sendProbesAndSolicitations state k addr outchan |
266 | 272 | ||
267 | eofConn state k = atomically $ modifyTVar' (keyToChan state) $ Map.delete k | 273 | eofConn state k = atomically $ modifyTVar' (keyToChan state) $ Map.delete k |
268 | 274 | ||