diff options
author | joe <joe@jerkface.net> | 2014-03-05 20:51:25 -0500 |
---|---|---|
committer | joe <joe@jerkface.net> | 2014-03-05 20:51:25 -0500 |
commit | e2515cf8d4fe6e775fcec5863f87acca5295e92c (patch) | |
tree | 1db88e1287464202cd4cf0d423a14dde602ce99a /xmppServer.hs | |
parent | a9934d3ccc5ab92b345eda277472d88e7f7edad7 (diff) |
untested: inform clients about remote presences
Diffstat (limited to 'xmppServer.hs')
-rw-r--r-- | xmppServer.hs | 36 |
1 files changed, 31 insertions, 5 deletions
diff --git a/xmppServer.hs b/xmppServer.hs index 3899a258..8656c91f 100644 --- a/xmppServer.hs +++ b/xmppServer.hs | |||
@@ -221,16 +221,21 @@ rosterGetStuff what state k = forClient state k (return []) | |||
221 | peers <- atomically $ readTVar (associatedPeers state) | 221 | peers <- atomically $ readTVar (associatedPeers state) |
222 | addrs <- return $ addrs `Map.difference` peers | 222 | addrs <- return $ addrs `Map.difference` peers |
223 | sv <- atomically $ takeTMVar $ server state | 223 | sv <- atomically $ takeTMVar $ server state |
224 | -- Grok peers to associate with from the roster: | ||
224 | forM_ (Map.keys addrs) $ \addr -> do | 225 | forM_ (Map.keys addrs) $ \addr -> do |
225 | putStrLn $ "new addr: "++show addr | 226 | putStrLn $ "new addr: "++show addr |
226 | addPeer sv addr | 227 | addPeer sv addr |
228 | -- Update local set of associated peers | ||
227 | atomically $ do | 229 | atomically $ do |
228 | writeTVar (associatedPeers state) (addrs `Map.union` peers) | 230 | writeTVar (associatedPeers state) (addrs `Map.union` peers) |
229 | putTMVar (server state) sv | 231 | putTMVar (server state) sv |
230 | return jids | 232 | return jids |
231 | 233 | ||
232 | rosterGetBuddies :: PresenceState -> ConnectionKey -> IO [Text] | 234 | rosterGetBuddies :: PresenceState -> ConnectionKey -> IO [Text] |
233 | rosterGetBuddies = rosterGetStuff ConfigFiles.getBuddies | 235 | rosterGetBuddies state k = do |
236 | buds <- rosterGetStuff ConfigFiles.getBuddies state k | ||
237 | return buds | ||
238 | |||
234 | rosterGetSolicited = rosterGetStuff ConfigFiles.getSolicited | 239 | rosterGetSolicited = rosterGetStuff ConfigFiles.getSolicited |
235 | rosterGetOthers = rosterGetStuff ConfigFiles.getOthers | 240 | rosterGetOthers = rosterGetStuff ConfigFiles.getOthers |
236 | rosterGetSubscribers = rosterGetStuff ConfigFiles.getSubscribers | 241 | rosterGetSubscribers = rosterGetStuff ConfigFiles.getSubscribers |
@@ -413,23 +418,43 @@ informClientPresence state k stanza = do | |||
413 | flip (maybe $ return ()) mb $ \cstate -> do | 418 | flip (maybe $ return ()) mb $ \cstate -> do |
414 | writeTVar (clientStatus cstate) $ Just dup | 419 | writeTVar (clientStatus cstate) $ Just dup |
415 | 420 | ||
421 | informPeerPresence state k stanza = do | ||
422 | -- Presence must indicate full JID with resource... | ||
423 | flip (maybe $ return ()) (stanzaFrom stanza) $ \from -> do | ||
424 | let (muser,h,mresource) = splitJID from | ||
425 | flip (maybe $ return ()) mresource $ \resource -> do | ||
426 | flip (maybe $ return ()) muser $ \user -> do | ||
427 | |||
428 | clients <- atomically $ do | ||
429 | -- TODO: Store the stanza | ||
430 | -- For now, all clients: | ||
431 | -- (TODO: interested/authorized clients only.) | ||
432 | ktc <- readTVar (keyToChan state) | ||
433 | runTraversableT $ do | ||
434 | (k,client) <- liftMT $ fmap Map.toList $ readTVar (clients state) | ||
435 | con <- liftMaybe $ Map.lookup k ktc | ||
436 | return (k,con,client) | ||
437 | forM_ clients $ \(k,con,client) -> do | ||
438 | from' <- do | ||
439 | let ClientKey laddr = k | ||
440 | (_,trip) <- rewriteJIDForClient laddr from | ||
441 | return trip | ||
442 | sendModifiedStanzaToClient stanza (connChan con) | ||
443 | |||
416 | answerProbe state k stanza chan = do | 444 | answerProbe state k stanza chan = do |
417 | putStrLn $ "answerProbe! " ++ show (stanzaType stanza) | 445 | putStrLn $ "answerProbe! " ++ show (stanzaType stanza) |
418 | ktc <- atomically $ readTVar (keyToChan state) | 446 | ktc <- atomically $ readTVar (keyToChan state) |
419 | replies <- runTraversableT $ do | 447 | replies <- runTraversableT $ do |
420 | let liftMaybe = liftT . maybeToList | ||
421 | liftIOMaybe :: IO (Maybe a) -> TraversableT [] IO a | ||
422 | liftIOMaybe = liftMT . fmap maybeToList | ||
423 | to <- liftMaybe $ stanzaTo stanza | 448 | to <- liftMaybe $ stanzaTo stanza |
424 | conn <- liftMaybe $ Map.lookup k ktc | 449 | conn <- liftMaybe $ Map.lookup k ktc |
425 | let (mu,h,_) = splitJID to -- TODO: currently resource-id is ignored on presence | 450 | let (mu,h,_) = splitJID to -- TODO: currently resource-id is ignored on presence |
426 | -- probes. Is this correct? Check the spec. | 451 | -- probes. Is this correct? Check the spec. |
452 | liftIOMaybe $ guardPortStrippedAddress h (auxAddr conn) | ||
427 | u <- liftMaybe mu | 453 | u <- liftMaybe mu |
428 | cbu <- lift . atomically $ readTVar (clientsByUser state) | 454 | cbu <- lift . atomically $ readTVar (clientsByUser state) |
429 | lpres <- liftMaybe $ Map.lookup u cbu | 455 | lpres <- liftMaybe $ Map.lookup u cbu |
430 | clientState <- liftT $ Map.elems (networkClients lpres) | 456 | clientState <- liftT $ Map.elems (networkClients lpres) |
431 | stanza <- liftIOMaybe $ atomically (readTVar (clientStatus clientState)) | 457 | stanza <- liftIOMaybe $ atomically (readTVar (clientStatus clientState)) |
432 | -- TODO: from address!! | ||
433 | let jid = unsplitJID (Just $ clientUser clientState | 458 | let jid = unsplitJID (Just $ clientUser clientState |
434 | , ch | 459 | , ch |
435 | ,Just $ clientResource clientState) | 460 | ,Just $ clientResource clientState) |
@@ -472,6 +497,7 @@ main = runResourceT $ do | |||
472 | , xmppSubscribeToRoster = \k -> return () | 497 | , xmppSubscribeToRoster = \k -> return () |
473 | , xmppDeliverMessage = deliverMessage state | 498 | , xmppDeliverMessage = deliverMessage state |
474 | , xmppInformClientPresence = informClientPresence state | 499 | , xmppInformClientPresence = informClientPresence state |
500 | , xmppInformPeerPresence = informPeerPresence state | ||
475 | , xmppAnswerProbe = answerProbe state | 501 | , xmppAnswerProbe = answerProbe state |
476 | } | 502 | } |
477 | liftIO $ do | 503 | liftIO $ do |