summaryrefslogtreecommitdiff
path: root/Presence
diff options
context:
space:
mode:
authorjoe <joe@jerkface.net>2018-06-20 16:08:42 -0400
committerjoe <joe@jerkface.net>2018-06-20 17:24:19 -0400
commitc8f7f30885f14b6239fac2a8b3157866494ae775 (patch)
tree78436d01af46d61515cf380a65460e899ad5ada5 /Presence
parent9ee162744e9f03f8a3c1ab0e5b3688f9dc534241 (diff)
Export non-ResourceT interface to xmppServer.
Diffstat (limited to 'Presence')
-rw-r--r--Presence/Presence.hs1
-rw-r--r--Presence/XMPPServer.hs29
2 files changed, 17 insertions, 13 deletions
diff --git a/Presence/Presence.hs b/Presence/Presence.hs
index adae567a..2f59a52f 100644
--- a/Presence/Presence.hs
+++ b/Presence/Presence.hs
@@ -12,7 +12,6 @@ import System.Posix.Signals
12import Control.Concurrent (threadDelay,forkIO,forkOS,killThread,throwTo) 12import Control.Concurrent (threadDelay,forkIO,forkOS,killThread,throwTo)
13import Control.Concurrent.STM 13import Control.Concurrent.STM
14import Control.Concurrent.STM.TMVar 14import Control.Concurrent.STM.TMVar
15import Control.Monad.Trans.Resource (runResourceT)
16import Control.Monad.Trans 15import Control.Monad.Trans
17import Control.Monad.IO.Class (MonadIO, liftIO) 16import Control.Monad.IO.Class (MonadIO, liftIO)
18import Network.Socket ( SockAddr(..), PortNumber ) 17import Network.Socket ( SockAddr(..), PortNumber )
diff --git a/Presence/XMPPServer.hs b/Presence/XMPPServer.hs
index 774fe886..a1221b6c 100644
--- a/Presence/XMPPServer.hs
+++ b/Presence/XMPPServer.hs
@@ -3,8 +3,10 @@
3{-# LANGUAGE RankNTypes #-} 3{-# LANGUAGE RankNTypes #-}
4{-# LANGUAGE FlexibleInstances #-} -- instance for TChan Event 4{-# LANGUAGE FlexibleInstances #-} -- instance for TChan Event
5{-# LANGUAGE DoAndIfThenElse #-} 5{-# LANGUAGE DoAndIfThenElse #-}
6{-# LANGUAGE ExistentialQuantification #-}
6module XMPPServer 7module XMPPServer
7 ( xmppServer 8 ( xmppServer
9 , quitXmpp
8 , ConnectionKey(..) 10 , ConnectionKey(..)
9 , XMPPServerParameters(..) 11 , XMPPServerParameters(..)
10 , XMPPServer 12 , XMPPServer
@@ -47,7 +49,6 @@ import Blaze.ByteString.Builder (Builder)
47 49
48import Debug.Trace 50import Debug.Trace
49import System.IO (hFlush,stdout) 51import System.IO (hFlush,stdout)
50import Control.Monad.Trans.Resource
51import Control.Monad.Trans (lift) 52import Control.Monad.Trans (lift)
52import Control.Monad.IO.Class (MonadIO, liftIO) 53import Control.Monad.IO.Class (MonadIO, liftIO)
53import Control.Monad.Fix (fix) 54import Control.Monad.Fix (fix)
@@ -72,6 +73,7 @@ import Data.Conduit
72import qualified Data.Conduit.List as CL 73import qualified Data.Conduit.List as CL
73import qualified Data.Conduit.Binary as CB 74import qualified Data.Conduit.Binary as CB
74import Data.Conduit.Blaze (builderToByteStringFlush) 75import Data.Conduit.Blaze (builderToByteStringFlush)
76import Control.Monad.Catch (MonadThrow)
75 77
76import qualified Text.XML.Stream.Render as XML hiding (content) 78import qualified Text.XML.Stream.Render as XML hiding (content)
77import qualified Text.XML.Stream.Parse as XML 79import qualified Text.XML.Stream.Parse as XML
@@ -895,7 +897,7 @@ makePong namespace mid to from =
895 ] 897 ]
896 898
897 899
898xmppInbound :: Server ConnectionKey SockAddr ReleaseKey XML.Event 900xmppInbound :: Server ConnectionKey SockAddr releaseKey XML.Event
899 -> XMPPServerParameters 901 -> XMPPServerParameters
900 -> ConnectionKey 902 -> ConnectionKey
901 -> SockAddr 903 -> SockAddr
@@ -1243,7 +1245,7 @@ slotsToSource slots nesting lastStanza needsFlush rdone =
1243 ,readTMVar rdone >> return (return ()) 1245 ,readTMVar rdone >> return (return ())
1244 ] 1246 ]
1245 1247
1246forkConnection :: Server ConnectionKey SockAddr ReleaseKey XML.Event 1248forkConnection :: Server ConnectionKey SockAddr releaseKey XML.Event
1247 -> XMPPServerParameters 1249 -> XMPPServerParameters
1248 -> ConnectionKey 1250 -> ConnectionKey
1249 -> SockAddr 1251 -> SockAddr
@@ -1481,7 +1483,7 @@ sendRoster query xmpp clientKey replyto = do
1481 -} 1483 -}
1482 1484
1483 1485
1484socketFromKey :: Server ConnectionKey SockAddr ReleaseKey XML.Event -> ConnectionKey -> IO SockAddr 1486socketFromKey :: Server ConnectionKey SockAddr releaseKey XML.Event -> ConnectionKey -> IO SockAddr
1485socketFromKey sv k = do 1487socketFromKey sv k = do
1486 map <- atomically $ readTVar (conmap sv) 1488 map <- atomically $ readTVar (conmap sv)
1487 let mcd = Map.lookup k map 1489 let mcd = Map.lookup k map
@@ -1651,7 +1653,7 @@ makeErrorStanza stanza = do
1651 ] 1653 ]
1652 1654
1653monitor :: 1655monitor ::
1654 Server ConnectionKey SockAddr ReleaseKey XML.Event 1656 Server ConnectionKey SockAddr releaseKey XML.Event
1655 -> ConnectionParameters ConnectionKey SockAddr 1657 -> ConnectionParameters ConnectionKey SockAddr
1656 -> XMPPServerParameters 1658 -> XMPPServerParameters
1657 -> IO b 1659 -> IO b
@@ -1817,7 +1819,8 @@ monitor sv params xmpp = do
1817 _ = str :: String 1819 _ = str :: String
1818 1820
1819data XMPPServer 1821data XMPPServer
1820 = XMPPServer { _xmpp_sv :: Server ConnectionKey SockAddr ReleaseKey XML.Event 1822 = forall releaseKey.
1823 XMPPServer { _xmpp_sv :: Server ConnectionKey SockAddr releaseKey XML.Event
1821 , _xmpp_peer_params :: ConnectionParameters ConnectionKey SockAddr 1824 , _xmpp_peer_params :: ConnectionParameters ConnectionKey SockAddr
1822 } 1825 }
1823 1826
@@ -1825,18 +1828,20 @@ grokPeer :: XMPPServer -> ConnectionKey -> (SockAddr, ConnectionParameters Conne
1825grokPeer sv (PeerKey addr) = (addr, _xmpp_peer_params sv, 10000) 1828grokPeer sv (PeerKey addr) = (addr, _xmpp_peer_params sv, 10000)
1826 1829
1827xmppConnections :: XMPPServer -> IO (Connection.Manager TCPStatus Text) 1830xmppConnections :: XMPPServer -> IO (Connection.Manager TCPStatus Text)
1828xmppConnections sv = tcpManager (grokPeer sv) (Just . Text.pack) resolvPeer (_xmpp_sv sv) 1831xmppConnections xsv@XMPPServer{_xmpp_sv=sv} = tcpManager (grokPeer xsv) (Just . Text.pack) resolvPeer sv
1829 where 1832 where
1830 resolvPeer :: Text -> IO (Maybe ConnectionKey) 1833 resolvPeer :: Text -> IO (Maybe ConnectionKey)
1831 resolvPeer str = fmap PeerKey <$> listToMaybe <$> resolvePeer str 1834 resolvPeer str = fmap PeerKey <$> listToMaybe <$> resolvePeer str
1832 1835
1833xmppEventChannel :: XMPPServer -> TChan ((ConnectionKey, SockAddr), ConnectionEvent Event) 1836xmppEventChannel :: XMPPServer -> TChan ((ConnectionKey, SockAddr), ConnectionEvent Event)
1834xmppEventChannel sv = serverEvent $ _xmpp_sv sv 1837xmppEventChannel XMPPServer{_xmpp_sv=sv} = serverEvent sv
1835 1838
1836xmppServer :: ( MonadResource m 1839quitXmpp :: XMPPServer -> IO ()
1837 , MonadIO m 1840quitXmpp XMPPServer{_xmpp_sv=sv} = control sv Quit
1838 ) => XMPPServerParameters -> m XMPPServer 1841
1839xmppServer xmpp = do 1842xmppServer :: MonadIO m =>
1843 Allocate releaseKey m -> XMPPServerParameters -> m XMPPServer
1844xmppServer allocate xmpp = do
1840 sv <- server allocate xmlStream 1845 sv <- server allocate xmlStream
1841 -- some fuzz helps avoid simultaneity 1846 -- some fuzz helps avoid simultaneity
1842 pingfuzz <- liftIO $ do 1847 pingfuzz <- liftIO $ do