@ -36,6 +36,7 @@ import Data.XML.Pickle
@@ -36,6 +36,7 @@ import Data.XML.Pickle
import Data.XML.Types
import qualified GHC.IO.Exception as GIE
import Network
import Network.TLS
import Network.DNS hiding ( encode , lookup )
import Network.Xmpp.Marshal
import Network.Xmpp.Types
@ -517,7 +518,7 @@ createStream :: HostName -> StreamConfiguration -> ErrorT XmppFailure IO (Stream
@@ -517,7 +518,7 @@ createStream :: HostName -> StreamConfiguration -> ErrorT XmppFailure IO (Stream
createStream realm config = do
result <- connect realm config
case result of
Just hand -> ErrorT $ do
Just ( host , hand ) -> ErrorT $ do
debugM " Pontarius.Xmpp " " Acquired handle. "
debugM " Pontarius.Xmpp " " Setting NoBuffering mode on handle. "
eSource <- liftIO . bufferSrc $
@ -533,7 +534,7 @@ createStream realm config = do
@@ -533,7 +534,7 @@ createStream realm config = do
, streamId = Nothing
, streamLang = Nothing
, streamJid = Nothing
, streamConfiguration = config
, streamConfiguration = setCertificateHost host config
}
stream' <- mkStream stream
return $ Right stream'
@ -546,10 +547,17 @@ createStream realm config = do
@@ -546,10 +547,17 @@ createStream realm config = do
liftIO . debugM " Pontarius.Xmpp " $ " In: " ++ ( BSC8 . unpack d ) ++
" . "
return d
setCertificateHost host conf =
conf { tlsParams =
( tlsParams conf ) { clientServerIdentification =
case clientServerIdentification ( tlsParams conf ) of
( _ , blob ) -> ( host , blob ) } }
-- Connects using the specified method. Returns the Handle acquired, if any.
connect :: HostName -> StreamConfiguration -> ErrorT XmppFailure IO
( Maybe StreamHandle )
connect :: HostName
-> StreamConfiguration
-> ErrorT XmppFailure IO ( Maybe ( HostName , StreamHandle ) )
connect realm config = do
case connectionDetails config of
UseHost host port -> lift $ do
@ -559,24 +567,26 @@ connect realm config = do
@@ -559,24 +567,26 @@ connect realm config = do
Nothing -> return Nothing
Just h' -> do
liftIO $ hSetBuffering h' NoBuffering
return . Just $ handleToStreamHandle h'
return . Just $ ( host , handleToStreamHandle h' )
UseSrv host -> do
h <- connectSrv ( resolvConf config ) host
case h of
Nothing -> return Nothing
Just h' -> do
Just ( hn , h' ) -> do
liftIO $ hSetBuffering h' NoBuffering
return . Just $ handleToStreamHandle h'
return . Just $ ( hn , handleToStreamHandle h' )
UseRealm -> do
h <- connectSrv ( resolvConf config ) realm
case h of
Nothing -> return Nothing
Just h' -> do
Just ( hn , h' ) -> do
liftIO $ hSetBuffering h' NoBuffering
return . Just $ handleToStreamHandle h'
return $ Just ( hn , handleToStreamHandle h' )
UseConnection mkC -> Just <$> mkC
connectSrv :: ResolvConf -> String -> ErrorT XmppFailure IO ( Maybe Handle )
connectSrv :: ResolvConf
-> String
-> ErrorT XmppFailure IO ( Maybe ( HostName , Handle ) )
connectSrv config host = do
case checkHostName ( Text . pack host ) of
Just host' -> do
@ -587,8 +597,9 @@ connectSrv config host = do
@@ -587,8 +597,9 @@ connectSrv config host = do
Nothing -> do
lift $ debugM " Pontarius.Xmpp "
" No SRV records, using fallback process. "
lift $ resolvAndConnectTcp resolvSeed ( BSC8 . pack $ host )
h <- lift $ resolvAndConnectTcp resolvSeed ( BSC8 . pack $ host )
5222
return $ ( \ h' -> ( host , h' ) ) <$> h
Just srvRecords' -> do
lift $ debugM " Pontarius.Xmpp "
" SRV records found, performing A/AAAA lookups. "
@ -668,12 +679,17 @@ resolvAndConnectTcp resolvSeed domain port = do
@@ -668,12 +679,17 @@ resolvAndConnectTcp resolvSeed domain port = do
-- Tries `resolvAndConnectTcp' for every SRV record, stopping if a handle is
-- acquired.
resolvSrvsAndConnectTcp :: ResolvSeed -> [ ( Domain , Int ) ] -> IO ( Maybe Handle )
resolvSrvsAndConnectTcp :: ResolvSeed
-> [ ( Domain , Int ) ]
-> IO ( Maybe ( HostName , Handle ) )
resolvSrvsAndConnectTcp _ [] = return Nothing
resolvSrvsAndConnectTcp resolvSeed ( ( domain , port ) : remaining ) = do
result <- resolvAndConnectTcp resolvSeed domain port
case result of
Just handle -> return $ Just handle
-- The last character of the target is always a dot in SRV records, so
-- we drop it. (Presumably the dns library should do that?)
Just handle -> return $ Just ( init . Text . unpack $ Text . decodeUtf8 $ domain
, handle )
Nothing -> resolvSrvsAndConnectTcp resolvSeed remaining