Browse Source

Suggested solution for #8

As I think the `SaslHandler's might change relatively frequently
depending on the value of `ConnectionState', I hereby suggest that the
handler value passed to `session' is changed from `[SaslHandler]' to
`(ConnectionState -> [SaslHandler]'.

Most people would probably just do `\_ -> scramSha1...', but I guess
the extra flexibility this provides makes up for the slightly more
complicated API.
master
Jon Kristensen 13 years ago
parent
commit
8a58fe9b08
  1. 1
      source/Network/Xmpp.hs
  2. 9
      source/Network/Xmpp/Concurrent.hs
  3. 1
      source/Network/Xmpp/Internal.hs

1
source/Network/Xmpp.hs

@ -167,6 +167,7 @@ module Network.Xmpp @@ -167,6 +167,7 @@ module Network.Xmpp
, AuthIllegalCredentials
, AuthOtherFailure )
, SaslHandler
, ConnectionState(..)
) where
import Network.Xmpp.Concurrent

9
source/Network/Xmpp/Concurrent.hs

@ -42,6 +42,8 @@ import Network.Xmpp.Tls @@ -42,6 +42,8 @@ import Network.Xmpp.Tls
import Network.Xmpp.Types
import Network.Xmpp.Utilities
import Control.Monad.State.Strict
runHandlers :: (TChan Stanza) -> [StanzaHandler] -> Stanza -> IO ()
runHandlers _ [] _ = return ()
runHandlers outC (h:hands) sta = do
@ -162,17 +164,18 @@ writeWorker stCh writeR = forever $ do @@ -162,17 +164,18 @@ writeWorker stCh writeR = forever $ do
-- third parameter is a 'Just' value, @session@ will attempt to authenticate and
-- acquire an XMPP resource.
session :: HostName -- ^ The hostname / realm
-> Maybe ([SaslHandler], Maybe Text) -- ^ SASL handlers and the desired
-- JID resource (or Nothing to let
-> Maybe (ConnectionState -> [SaslHandler] , Maybe Text)
-- ^ SASL handlers and the desired JID resource (or Nothing to let
-- the server decide)
-> SessionConfiguration -- ^ configuration details
-> IO (Either XmppFailure Session)
session realm mbSasl config = runErrorT $ do
stream <- ErrorT $ openStream realm (sessionStreamConfiguration config)
ErrorT $ tls stream
cs <- liftIO $ withStream (gets streamConnectionState) stream
mbAuthError <- case mbSasl of
Nothing -> return Nothing
Just (handlers, resource) -> ErrorT $ auth handlers resource stream
Just (handlers, resource) -> ErrorT $ auth (handlers cs) resource stream
case mbAuthError of
Nothing -> return ()
Just _ -> throwError XmppAuthFailure

1
source/Network/Xmpp/Internal.hs

@ -31,7 +31,6 @@ module Network.Xmpp.Internal @@ -31,7 +31,6 @@ module Network.Xmpp.Internal
, pushIQ
, SaslHandler
, StanzaID(..)
, ConnectionState(..)
, Stanza(..)
, TlsBehaviour(..)
)

Loading…
Cancel
Save