summaryrefslogtreecommitdiff
path: root/Presence/XMPP.hs
diff options
context:
space:
mode:
authorJames Crayne <jim.crayne@gmail.com>2013-07-01 21:57:01 -0400
committerJames Crayne <jim.crayne@gmail.com>2013-07-01 21:57:01 -0400
commit43c4487e3763b741291c928e33f71aac0aa47358 (patch)
treee58c33cf0d3de3c96079161589a01698b61b9972 /Presence/XMPP.hs
parent35c063708a4e4465a0c0f8c89ff2338c79296210 (diff)
Added stubs for PresenceProbe message
Diffstat (limited to 'Presence/XMPP.hs')
-rw-r--r--Presence/XMPP.hs21
1 files changed, 15 insertions, 6 deletions
diff --git a/Presence/XMPP.hs b/Presence/XMPP.hs
index 86f2df44..0fd49c2b 100644
--- a/Presence/XMPP.hs
+++ b/Presence/XMPP.hs
@@ -7,8 +7,11 @@ module XMPP
7 , module SocketLike 7 , module SocketLike
8 , listenForXmppClients 8 , listenForXmppClients
9 , listenForRemotePeers 9 , listenForRemotePeers
10 , newServerConnections
10 , seekRemotePeers 11 , seekRemotePeers
11 , quitListening 12 , quitListening
13 , OutBoundMessage(..)
14 , sendMessage
12 ) where 15 ) where
13 16
14import ServerC 17import ServerC
@@ -80,9 +83,11 @@ import NestingXML
80import Data.Set as Set (Set) 83import Data.Set as Set (Set)
81import qualified Data.Set as Set 84import qualified Data.Set as Set
82import qualified Data.Map as Map 85import qualified Data.Map as Map
86import Data.Map as Map (Map)
83import GHC.Conc 87import GHC.Conc
84 ( threadStatus 88 ( threadStatus
85 , ThreadStatus(..) 89 , ThreadStatus(..)
90 , ThreadId
86 ) 91 )
87 92
88data Commands = Send [XML.Event] | QuitThread 93data Commands = Send [XML.Event] | QuitThread
@@ -573,10 +578,10 @@ seekRemotePeers config chan = do
573 return () 578 return ()
574-} 579-}
575 580
576data OutBoundMessage = OutBoundPresence Presence 581data OutBoundMessage = OutBoundPresence Presence | PresenceProbe JID
577 deriving Prelude.Show 582 deriving Prelude.Show
578 583
579newServerConnections = atomically $ newTVar Map.empty 584newServerConnections = newTVar Map.empty
580 585
581connect_to_server chan peer = (>> return ()) . runMaybeT $ do 586connect_to_server chan peer = (>> return ()) . runMaybeT $ do
582 let port = 5269 :: Int 587 let port = 5269 :: Int
@@ -600,6 +605,9 @@ connect_to_server chan peer = (>> return ()) . runMaybeT $ do
600 cached_map <- readIORef cached 605 cached_map <- readIORef cached
601 writeIORef cached (Map.insert jid st cached_map) 606 writeIORef cached (Map.insert jid st cached_map)
602 loop 607 loop
608 Left (PresenceProbe jid) -> do
609 liftIO $ putStrLn "Connection not ready, Discarding Presence Probe..."
610 loop
603 {- 611 {-
604 Left event -> do 612 Left event -> do
605 L.putStrLn $ "REMOTE-OUT DISCARDED: " <++> bshow event 613 L.putStrLn $ "REMOTE-OUT DISCARDED: " <++> bshow event
@@ -642,6 +650,8 @@ toPeer sock cache chan = do
642 OutBoundPresence p -> do 650 OutBoundPresence p -> do
643 r <- lift $ xmlifyPresenceForPeer sock p 651 r <- lift $ xmlifyPresenceForPeer sock p
644 send r 652 send r
653 PresenceProbe jid -> do
654 liftIO $ putStrLn ("Connection ready, PresenceProbe " ++ show jid ++ " (NOT IMPLEMENTED)")
645 loop 655 loop
646 send goodbyePeer 656 send goodbyePeer
647 657
@@ -686,7 +696,7 @@ connect' addr port = do
686 ) 696 )
687 697
688 698
689 699sendMessage :: TVar (Map Peer (TChan OutBoundMessage, ThreadId)) -> OutBoundMessage -> Peer -> IO ()
690sendMessage cons msg peer = do 700sendMessage cons msg peer = do
691 found <- atomically $ do 701 found <- atomically $ do
692 consmap <- readTVar cons 702 consmap <- readTVar cons
@@ -720,9 +730,8 @@ sendMessage cons msg peer = do
720 730
721 731
722seekRemotePeers :: XMPPConfig config => 732seekRemotePeers :: XMPPConfig config =>
723 config -> TChan Presence -> IO b0 733 config -> TChan Presence -> TVar (Map Peer (TChan OutBoundMessage, ThreadId)) -> IO b0
724seekRemotePeers config chan = do 734seekRemotePeers config chan server_connections = do
725 server_connections <- newServerConnections
726 fix $ \loop -> do 735 fix $ \loop -> do
727 event <- atomically $ readTChan chan 736 event <- atomically $ readTChan chan
728 case event of 737 case event of