Add IMAP session logging as an option
Setting the "sslLogToConsole" parameter to True will now spit out the IMAP session log inline, prefixed with "HaskellNet-SSL".
This commit is contained in:
parent
3f2fb2c79b
commit
263bee1392
@ -8,10 +8,12 @@ import Network.Socket.Internal (PortNumber)
|
|||||||
data Settings = Settings
|
data Settings = Settings
|
||||||
{ sslPort :: PortNumber
|
{ sslPort :: PortNumber
|
||||||
, sslMaxLineLength :: Int
|
, sslMaxLineLength :: Int
|
||||||
|
, sslLogToConsole :: Bool
|
||||||
}
|
}
|
||||||
|
|
||||||
defaultSettingsWithPort :: PortNumber -> Settings
|
defaultSettingsWithPort :: PortNumber -> Settings
|
||||||
defaultSettingsWithPort p = Settings
|
defaultSettingsWithPort p = Settings
|
||||||
{ sslPort = p
|
{ sslPort = p
|
||||||
, sslMaxLineLength = 10000
|
, sslMaxLineLength = 10000
|
||||||
|
, sslLogToConsole = False
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,7 +3,6 @@ module Network.HaskellNet.SSL.Internal
|
|||||||
, connectPlain
|
, connectPlain
|
||||||
) where
|
) where
|
||||||
|
|
||||||
|
|
||||||
import Network.Connection
|
import Network.Connection
|
||||||
import Network.HaskellNet.SSL
|
import Network.HaskellNet.SSL
|
||||||
import Network.HaskellNet.BSStream
|
import Network.HaskellNet.BSStream
|
||||||
@ -11,6 +10,8 @@ import Network.HaskellNet.BSStream
|
|||||||
import qualified Data.ByteString.Char8 as B
|
import qualified Data.ByteString.Char8 as B
|
||||||
import Data.Default
|
import Data.Default
|
||||||
|
|
||||||
|
import Control.Monad ((>=>))
|
||||||
|
|
||||||
type STARTTLS = IO ()
|
type STARTTLS = IO ()
|
||||||
|
|
||||||
connectionGetBytes :: Connection -> Int -> IO B.ByteString
|
connectionGetBytes :: Connection -> Int -> IO B.ByteString
|
||||||
@ -21,13 +22,20 @@ connectionGetBytes = loop B.empty where
|
|||||||
|
|
||||||
connectionToStream :: Connection -> Settings -> BSStream
|
connectionToStream :: Connection -> Settings -> BSStream
|
||||||
connectionToStream c cfg = BSStream
|
connectionToStream c cfg = BSStream
|
||||||
{ bsGet = connectionGetBytes c
|
{ bsGet = connectionGetBytes c >=> withLog "RECV"
|
||||||
, bsPut = connectionPut c
|
, bsPut = withLog "SEND" >=> connectionPut c
|
||||||
, bsFlush = return ()
|
, bsFlush = return ()
|
||||||
, bsClose = connectionClose c
|
, bsClose = connectionClose c
|
||||||
, bsIsOpen = return True
|
, bsIsOpen = return True
|
||||||
, bsGetLine = connectionGetLine maxl c
|
, bsGetLine = connectionGetLine maxl c >>= withLog "RECV"
|
||||||
} where maxl = sslMaxLineLength cfg
|
} where maxl = sslMaxLineLength cfg
|
||||||
|
withLog = if sslLogToConsole cfg then logToConsole
|
||||||
|
else flip (const . return)
|
||||||
|
|
||||||
|
logToConsole :: String -> B.ByteString -> IO B.ByteString
|
||||||
|
logToConsole dir s = do
|
||||||
|
putStrLn $ "HaskellNet-SSL " ++ dir ++ ": " ++ show s
|
||||||
|
return s
|
||||||
|
|
||||||
connectSSL :: String -> Settings -> IO BSStream
|
connectSSL :: String -> Settings -> IO BSStream
|
||||||
connectSSL hostname cfg = do
|
connectSSL hostname cfg = do
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user