Expose the HaskellNet.SSL module for Settings
Moved the private stuff into HaskellNet.SSL.Internal, so that HaskellNet.SSL only exports Settings. Updated minor version number for this quickfix release.
This commit is contained in:
parent
f0c2d09122
commit
c99470b2c1
@ -1,6 +1,6 @@
|
||||
name: HaskellNet-SSL
|
||||
synopsis: Helpers to connect to SSL/TLS mail servers with HaskellNet
|
||||
version: 0.2
|
||||
version: 0.2.1
|
||||
description: This package ties together the HaskellNet and connection
|
||||
packages to make it easy to open IMAP and SMTP connections
|
||||
over SSL.
|
||||
@ -25,7 +25,8 @@ library
|
||||
exposed-modules: Network.HaskellNet.IMAP.SSL
|
||||
Network.HaskellNet.POP3.SSL
|
||||
Network.HaskellNet.SMTP.SSL
|
||||
other-modules: Network.HaskellNet.SSL
|
||||
Network.HaskellNet.SSL
|
||||
other-modules: Network.HaskellNet.SSL.Internal
|
||||
build-depends: base >= 4 && < 5,
|
||||
HaskellNet >= 0.3.1,
|
||||
tls >= 1.1.2,
|
||||
|
||||
@ -8,6 +8,8 @@ import Network.HaskellNet.IMAP.Connection
|
||||
import Network.HaskellNet.IMAP
|
||||
import Network.HaskellNet.SSL
|
||||
|
||||
import Network.HaskellNet.SSL.Internal
|
||||
|
||||
connectIMAPSSL :: String -> IO IMAPConnection
|
||||
connectIMAPSSL hostname = connectIMAPSSLWithSettings hostname cfg
|
||||
where cfg = defaultSettingsWithPort 993
|
||||
|
||||
@ -8,6 +8,8 @@ import Network.HaskellNet.POP3.Connection
|
||||
import Network.HaskellNet.POP3
|
||||
import Network.HaskellNet.SSL
|
||||
|
||||
import Network.HaskellNet.SSL.Internal
|
||||
|
||||
connectPop3SSL :: String -> IO POP3Connection
|
||||
connectPop3SSL hostname = connectPop3SSLWithSettings hostname cfg
|
||||
where cfg = defaultSettingsWithPort 995
|
||||
|
||||
@ -14,6 +14,8 @@ module Network.HaskellNet.SMTP.SSL
|
||||
import Network.HaskellNet.SMTP
|
||||
import Network.HaskellNet.SSL
|
||||
|
||||
import Network.HaskellNet.SSL.Internal
|
||||
|
||||
import Network.HaskellNet.BSStream
|
||||
import Network.BSD (getHostName)
|
||||
|
||||
|
||||
@ -1,19 +1,10 @@
|
||||
module Network.HaskellNet.SSL
|
||||
( Settings (..)
|
||||
, defaultSettingsWithPort
|
||||
, connectSSL
|
||||
, connectPlain
|
||||
) where
|
||||
|
||||
import Network.Connection
|
||||
import Network.HaskellNet.BSStream
|
||||
import Network.Socket.Internal (PortNumber)
|
||||
|
||||
import qualified Data.ByteString.Char8 as B
|
||||
import Data.Default
|
||||
|
||||
type STARTTLS = IO ()
|
||||
|
||||
data Settings = Settings
|
||||
{ sslPort :: PortNumber
|
||||
, sslMaxLineLength :: Int
|
||||
@ -24,34 +15,3 @@ defaultSettingsWithPort p = Settings
|
||||
{ sslPort = p
|
||||
, sslMaxLineLength = 10000
|
||||
}
|
||||
|
||||
connectionGetBytes :: Connection -> Int -> IO B.ByteString
|
||||
connectionGetBytes = loop B.empty where
|
||||
loop buf _ 0 = return buf
|
||||
loop buf c l = connectionGet c l >>= nextIteration
|
||||
where nextIteration b = loop (buf `B.append` b) c $ l - B.length b
|
||||
|
||||
connectionToStream :: Connection -> Settings -> BSStream
|
||||
connectionToStream c cfg = BSStream
|
||||
{ bsGet = connectionGetBytes c
|
||||
, bsPut = connectionPut c
|
||||
, bsFlush = return ()
|
||||
, bsClose = connectionClose c
|
||||
, bsIsOpen = return True
|
||||
, bsGetLine = connectionGetLine maxl c
|
||||
} where maxl = sslMaxLineLength cfg
|
||||
|
||||
connectSSL :: String -> Settings -> IO BSStream
|
||||
connectSSL hostname cfg = do
|
||||
c <- initConnectionContext >>= flip connectTo params
|
||||
return $ connectionToStream c cfg
|
||||
where params = ConnectionParams hostname port (Just def) Nothing
|
||||
port = sslPort cfg
|
||||
|
||||
connectPlain :: String -> Settings -> IO (BSStream, STARTTLS)
|
||||
connectPlain hostname cfg = do
|
||||
ctx <- initConnectionContext
|
||||
c <- connectTo ctx params
|
||||
return (connectionToStream c cfg, connectionSetSecure ctx c def)
|
||||
where params = ConnectionParams hostname port Nothing Nothing
|
||||
port = sslPort cfg
|
||||
|
||||
45
src/Network/HaskellNet/SSL/Internal.hs
Normal file
45
src/Network/HaskellNet/SSL/Internal.hs
Normal file
@ -0,0 +1,45 @@
|
||||
module Network.HaskellNet.SSL.Internal
|
||||
( connectSSL
|
||||
, connectPlain
|
||||
) where
|
||||
|
||||
|
||||
import Network.Connection
|
||||
import Network.HaskellNet.SSL
|
||||
import Network.HaskellNet.BSStream
|
||||
|
||||
import qualified Data.ByteString.Char8 as B
|
||||
import Data.Default
|
||||
|
||||
type STARTTLS = IO ()
|
||||
|
||||
connectionGetBytes :: Connection -> Int -> IO B.ByteString
|
||||
connectionGetBytes = loop B.empty where
|
||||
loop buf _ 0 = return buf
|
||||
loop buf c l = connectionGet c l >>= nextIteration
|
||||
where nextIteration b = loop (buf `B.append` b) c $ l - B.length b
|
||||
|
||||
connectionToStream :: Connection -> Settings -> BSStream
|
||||
connectionToStream c cfg = BSStream
|
||||
{ bsGet = connectionGetBytes c
|
||||
, bsPut = connectionPut c
|
||||
, bsFlush = return ()
|
||||
, bsClose = connectionClose c
|
||||
, bsIsOpen = return True
|
||||
, bsGetLine = connectionGetLine maxl c
|
||||
} where maxl = sslMaxLineLength cfg
|
||||
|
||||
connectSSL :: String -> Settings -> IO BSStream
|
||||
connectSSL hostname cfg = do
|
||||
c <- initConnectionContext >>= flip connectTo params
|
||||
return $ connectionToStream c cfg
|
||||
where params = ConnectionParams hostname port (Just def) Nothing
|
||||
port = sslPort cfg
|
||||
|
||||
connectPlain :: String -> Settings -> IO (BSStream, STARTTLS)
|
||||
connectPlain hostname cfg = do
|
||||
ctx <- initConnectionContext
|
||||
c <- connectTo ctx params
|
||||
return (connectionToStream c cfg, connectionSetSecure ctx c def)
|
||||
where params = ConnectionParams hostname port Nothing Nothing
|
||||
port = sslPort cfg
|
||||
Loading…
Reference in New Issue
Block a user