Browse Source

rename XmppConnectionState to ConnectionState

master
Philipp Balzarek 13 years ago
parent
commit
a057326c13
  1. 2
      source/Network/Xmpp/Basic.hs
  2. 2
      source/Network/Xmpp/Concurrent/Threads.hs
  3. 4
      source/Network/Xmpp/Connection.hs
  4. 2
      source/Network/Xmpp/Sasl.hs
  5. 4
      source/Network/Xmpp/Stream.hs
  6. 8
      source/Network/Xmpp/TLS.hs
  7. 12
      source/Network/Xmpp/Types.hs

2
source/Network/Xmpp/Basic.hs

@ -1,6 +1,6 @@
module Network.Xmpp.Basic module Network.Xmpp.Basic
( Connection(..) ( Connection(..)
, XmppConnectionState(..) , ConnectionState(..)
, connectTcp , connectTcp
, simpleConnect , simpleConnect
, startTLS , startTLS

2
source/Network/Xmpp/Concurrent/Threads.hs

@ -34,7 +34,7 @@ readWorker onStanza onConnectionClosed stateRef =
s <- atomically $ do s <- atomically $ do
con@(Connection con_) <- readTMVar stateRef con@(Connection con_) <- readTMVar stateRef
state <- sConnectionState <$> readTMVar con_ state <- sConnectionState <$> readTMVar con_
when (state == XmppConnectionClosed) when (state == ConnectionClosed)
retry retry
return con return con
allowInterrupt allowInterrupt

4
source/Network/Xmpp/Connection.hs

@ -127,7 +127,7 @@ xmppNoConnection = Connection_
} }
, cEventSource = DCI.ResumableSource zeroSource (return ()) , cEventSource = DCI.ResumableSource zeroSource (return ())
, sFeatures = SF Nothing [] [] , sFeatures = SF Nothing [] []
, sConnectionState = XmppConnectionClosed , sConnectionState = ConnectionClosed
, sHostname = Nothing , sHostname = Nothing
, sJid = Nothing , sJid = Nothing
, sStreamLang = Nothing , sStreamLang = Nothing
@ -167,7 +167,7 @@ connectTcpRaw host port hostname = do
{ cHand = hand { cHand = hand
, cEventSource = eSource , cEventSource = eSource
, sFeatures = (SF Nothing [] []) , sFeatures = (SF Nothing [] [])
, sConnectionState = XmppConnectionPlain , sConnectionState = ConnectionPlain
, sHostname = (Just hostname) , sHostname = (Just hostname)
, sJid = Nothing , sJid = Nothing
, sPreferredLang = Nothing -- TODO: Allow user to set , sPreferredLang = Nothing -- TODO: Allow user to set

2
source/Network/Xmpp/Sasl.hs

@ -54,7 +54,7 @@ xmppSasl handlers = withConnection $ do
(_name, handler):_ -> runErrorT $ do (_name, handler):_ -> runErrorT $ do
cs <- gets sConnectionState cs <- gets sConnectionState
case cs of case cs of
XmppConnectionClosed -> throwError AuthConnectionError ConnectionClosed -> throwError AuthConnectionError
_ -> do _ -> do
r <- handler r <- handler
_ <- ErrorT $ left AuthStreamError <$> restartStream _ <- ErrorT $ left AuthStreamError <$> restartStream

4
source/Network/Xmpp/Stream.hs

@ -67,9 +67,9 @@ startStream = runErrorT $ do
state <- get state <- get
-- Set the `to' attribute depending on the state of the connection. -- Set the `to' attribute depending on the state of the connection.
let from = case sConnectionState state of let from = case sConnectionState state of
XmppConnectionPlain -> if sJidWhenPlain state ConnectionPlain -> if sJidWhenPlain state
then sJid state else Nothing then sJid state else Nothing
XmppConnectionSecured -> sJid state ConnectionSecured -> sJid state
case sHostname state of case sHostname state of
Nothing -> throwError StreamConnectionError Nothing -> throwError StreamConnectionError
Just hostname -> lift $ do Just hostname -> lift $ do

8
source/Network/Xmpp/TLS.hs

@ -93,9 +93,9 @@ startTLS params con = Ex.handle (return . Left . TLSError)
features <- lift $ gets sFeatures features <- lift $ gets sFeatures
state <- gets sConnectionState state <- gets sConnectionState
case state of case state of
XmppConnectionPlain -> return () ConnectionPlain -> return ()
XmppConnectionClosed -> throwError TLSNoConnection ConnectionClosed -> throwError TLSNoConnection
XmppConnectionSecured -> throwError TLSConnectionSecured ConnectionSecured -> throwError TLSConnectionSecured
con <- lift $ gets cHand con <- lift $ gets cHand
when (stls features == Nothing) $ throwError TLSNoServerSupport when (stls features == Nothing) $ throwError TLSNoServerSupport
lift $ pushElement starttlsE lift $ pushElement starttlsE
@ -115,5 +115,5 @@ startTLS params con = Ex.handle (return . Left . TLSError)
} }
lift $ modify ( \x -> x {cHand = newHand}) lift $ modify ( \x -> x {cHand = newHand})
either (lift . Ex.throwIO) return =<< lift restartStream either (lift . Ex.throwIO) return =<< lift restartStream
modify (\s -> s{sConnectionState = XmppConnectionSecured}) modify (\s -> s{sConnectionState = ConnectionSecured})
return () return ()

12
source/Network/Xmpp/Types.hs

@ -37,7 +37,7 @@ module Network.Xmpp.Types
, withConnection , withConnection
, withConnection' , withConnection'
, mkConnection , mkConnection
, XmppConnectionState(..) , ConnectionState(..)
, XmppStreamError(..) , XmppStreamError(..)
, langTag , langTag
, module Network.Xmpp.Jid , module Network.Xmpp.Jid
@ -740,10 +740,10 @@ data ServerFeatures = SF
, other :: ![Element] , other :: ![Element]
} deriving Show } deriving Show
data XmppConnectionState data ConnectionState
= XmppConnectionClosed -- ^ No connection at this point. = ConnectionClosed -- ^ No connection at this point.
| XmppConnectionPlain -- ^ Connection established, but not secured. | ConnectionPlain -- ^ Connection established, but not secured.
| XmppConnectionSecured -- ^ Connection established and secured via TLS. | ConnectionSecured -- ^ Connection established and secured via TLS.
deriving (Show, Eq, Typeable) deriving (Show, Eq, Typeable)
data HandleLike = Hand { cSend :: BS.ByteString -> IO Bool data HandleLike = Hand { cSend :: BS.ByteString -> IO Bool
@ -756,7 +756,7 @@ data HandleLike = Hand { cSend :: BS.ByteString -> IO Bool
} }
data Connection_ = Connection_ data Connection_ = Connection_
{ sConnectionState :: !XmppConnectionState -- ^ State of { sConnectionState :: !ConnectionState -- ^ State of
-- connection -- connection
, cHand :: HandleLike , cHand :: HandleLike
, cEventSource :: ResumableSource IO Event , cEventSource :: ResumableSource IO Event

Loading…
Cancel
Save