@ -8,7 +8,6 @@ import Control.Monad
import Control.Monad.IO.Class
import Control.Monad.IO.Class
import Control.Monad.Trans.Class
import Control.Monad.Trans.Class
--import Control.Monad.Trans.Resource
--import Control.Monad.Trans.Resource
import Control.Concurrent
import qualified Control.Exception as Ex
import qualified Control.Exception as Ex
import Control.Monad.State.Strict
import Control.Monad.State.Strict
@ -69,38 +68,36 @@ pullStanza = do
xmppFromHandle :: Handle
xmppFromHandle :: Handle
-> Text
-> Text
-> Text
-> Maybe Text
-> XMPPConMonad a
-> XMPPConMonad a
-> IO ( a , XMPPConState )
-> IO ( a , XmppConnection )
xmppFromHandle handle hostname username res f = do
xmppFromHandle handle hostname f = do
liftIO $ hSetBuffering handle NoBuffering
liftIO $ hSetBuffering handle NoBuffering
let raw = sourceHandle handle
let raw = sourceHandle handle
let src = raw $= XP . parseBytes def
let src = raw $= XP . parseBytes def
let st = XMPPConState
let st = XmppConnection
src
src
( raw )
( raw )
( BS . hPut handle )
( BS . hPut handle )
( Just handle )
( Just handle )
( SF Nothing [] [] )
( SF Nothing [] [] )
False
XmppConnectionPlain
( Just hostname )
( Just hostname )
( Just username )
Nothing
res
Nothing
( hClose handle )
( hClose handle )
runStateT f st
runStateT f st
zeroSource :: Source IO output
zeroSource :: Source IO output
zeroSource = liftIO . forever $ threadDelay 10000000
zeroSource = liftIO . Ex . throwIO $ XmppNoConnection
xmppZeroConState :: XMPPConState
xmppNoConnection :: XmppConnection
xmppZeroConState = XMPPConState
xmppNoConnection = XmppConnection
{ sConSrc = zeroSource
{ sConSrc = zeroSource
, sRawSrc = zeroSource
, sRawSrc = zeroSource
, sConPushBS = ( \ _ -> return () )
, sConPushBS = \ _ -> Ex . throwIO $ XmppNoConnection
, sConHandle = Nothing
, sConHandle = Nothing
, sFeatures = SF Nothing [] []
, sFeatures = SF Nothing [] []
, sHaveTLS = False
, sConnectionState = XmppConnectionClosed
, sHostname = Nothing
, sHostname = Nothing
, sUsername = Nothing
, sUsername = Nothing
, sResource = Nothing
, sResource = Nothing
@ -116,29 +113,32 @@ xmppRawConnect host hostname = do
return con
return con
let raw = sourceHandle con
let raw = sourceHandle con
src <- liftIO . bufferSource $ raw $= XP . parseBytes def
src <- liftIO . bufferSource $ raw $= XP . parseBytes def
let st = XMPPConState
let st = XmppConnection
src
src
( raw )
( raw )
( BS . hPut con )
( BS . hPut con )
( Just con )
( Just con )
( SF Nothing [] [] )
( SF Nothing [] [] )
False
XmppConnectionPlain
( Just hostname )
( Just hostname )
uname
uname
Nothing
Nothing
( hClose con )
( hClose con )
put st
put st
xmppNewSession :: XMPPConMonad a -> IO ( a , XMPPConState )
xmppNewSession :: XMPPConMonad a -> IO ( a , XmppConnection )
xmppNewSession action = do
xmppNewSession action = do
runStateT action xmppZeroConState
runStateT action xmppNoConnection
xmppKillConnection :: XMPPConMonad ()
xmppKillConnection :: XMPPConMonad ()
xmppKillConnection = do
xmppKillConnection = do
cc <- gets sCloseConnection
cc <- gets sCloseConnection
void . liftIO $ ( Ex . try cc :: IO ( Either Ex . SomeException () ) )
void . liftIO $ ( Ex . try cc :: IO ( Either Ex . SomeException () ) )
put xmppZeroConState
put xmppNoConnection
xmppSendIQ' :: StanzaId -> Maybe JID -> IQRequestType
-> Maybe LangTag -> Element
-> XMPPConMonad ( Either IQError IQResult )
xmppSendIQ' iqID to tp lang body = do
xmppSendIQ' iqID to tp lang body = do
push . IQRequestS $ IQRequest iqID Nothing to lang tp body
push . IQRequestS $ IQRequest iqID Nothing to lang tp body
res <- pullPickle $ xpEither xpIQError xpIQResult
res <- pullPickle $ xpEither xpIQError xpIQResult