From f4a88fbbb879db85d55dfecf0a5437d8caf71bc5 Mon Sep 17 00:00:00 2001
From: Philipp Balzarek
Date: Fri, 8 Mar 2013 13:10:34 +0100
Subject: [PATCH] add StreamConfiguration parameter to session and rename
hardcodedTcpDetails to TcpDetails
---
source/Network/Xmpp.hs | 1 +
source/Network/Xmpp/Concurrent.hs | 7 ++++---
source/Network/Xmpp/Stream.hs | 12 +++++++-----
source/Network/Xmpp/Types.hs | 4 ++--
4 files changed, 14 insertions(+), 10 deletions(-)
diff --git a/source/Network/Xmpp.hs b/source/Network/Xmpp.hs
index e384f62..0da855a 100644
--- a/source/Network/Xmpp.hs
+++ b/source/Network/Xmpp.hs
@@ -27,6 +27,7 @@ module Network.Xmpp
( -- * Session management
Session
, session
+ , StreamConfiguration(..)
-- TODO: Close session, etc.
-- ** Authentication handlers
-- | The use of 'scramSha1' is /recommended/, but 'digestMd5' might be
diff --git a/source/Network/Xmpp/Concurrent.hs b/source/Network/Xmpp/Concurrent.hs
index 451bb97..61a9eff 100644
--- a/source/Network/Xmpp/Concurrent.hs
+++ b/source/Network/Xmpp/Concurrent.hs
@@ -132,7 +132,8 @@ writeWorker stCh writeR = forever $ do
-- value, @session@ will attempt to secure the connection with TLS. If the fifth
-- parameters is a 'Just' value, @session@ will attempt to authenticate and
-- acquire an XMPP resource.
-session :: Text -- ^ The realm host name
+session :: Text -- ^ The hostname / realm
+ -> StreamConfiguration -- ^ configuration details
-> Maybe TLS.TLSParams -- ^ TLS settings, if securing the
-- connection to the server is
-- desired
@@ -140,8 +141,8 @@ session :: Text -- ^ The realm host name
-- JID resource (or Nothing to let
-- the server decide)
-> IO (Either XmppFailure (Session, Maybe AuthFailure))
-session realm mbTls mbSasl = runErrorT $ do
- con <- ErrorT $ openStream realm def
+session host config mbTls mbSasl = runErrorT $ do
+ con <- ErrorT $ openStream host config
case mbTls of
Nothing -> return ()
Just tls -> ErrorT $ startTls tls con
diff --git a/source/Network/Xmpp/Stream.hs b/source/Network/Xmpp/Stream.hs
index c9ac138..b3d54ca 100644
--- a/source/Network/Xmpp/Stream.hs
+++ b/source/Network/Xmpp/Stream.hs
@@ -253,12 +253,14 @@ streamS expectedTo = do
-- | Connects to the XMPP server and opens the XMPP stream against the given
-- realm.
-openStream :: Text -> StreamConfiguration -> IO (Either XmppFailure (TMVar Stream))
-openStream realm config = runErrorT $ do
- (address, port) <- case hardcodedTcpDetails config of
- Nothing -> dnsLookup realm (resolvConf config)
+openStream :: Text
+ -> StreamConfiguration
+ -> IO (Either XmppFailure (TMVar Stream))
+openStream host config = runErrorT $ do
+ (address, port) <- case tcpDetails config of
+ Nothing -> dnsLookup host (resolvConf config)
Just (address, port) -> return (address, port)
- stream' <- connectTcp (Text.unpack address) port realm config
+ stream' <- connectTcp (Text.unpack address) port host config
result <- liftIO $ withStream startStream stream'
return stream'
diff --git a/source/Network/Xmpp/Types.hs b/source/Network/Xmpp/Types.hs
index 131c6b7..7624957 100644
--- a/source/Network/Xmpp/Types.hs
+++ b/source/Network/Xmpp/Types.hs
@@ -1024,7 +1024,7 @@ data StreamConfiguration =
-- | By specifying these details, Pontarius XMPP will
-- connect to the provided address and port, and will
-- not perform a DNS look-up
- , hardcodedTcpDetails :: Maybe (Text, PortID)
+ , tcpDetails :: Maybe (Text, PortID)
-- | DNS resolver configuration
, resolvConf :: ResolvConf
}
@@ -1033,6 +1033,6 @@ data StreamConfiguration =
instance Default StreamConfiguration where
def = StreamConfiguration { preferredLang = Nothing
, toJid = Nothing
- , hardcodedTcpDetails = Nothing
+ , tcpDetails = Nothing
, resolvConf = defaultResolvConf
}