packages feed

uniform-io 1.0.0.0 → 1.0.1.0

raw patch · 8 files changed

+92/−147 lines, 8 filesdep ~basedep ~iproutedep ~uniform-ioPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

Dependency ranges changed: base, iproute, uniform-io

API changes (from Hackage documentation)

- System.IO.Uniform: [tlsCertificateChainFile] :: TlsSettings -> String
- System.IO.Uniform: [tlsDHParametersFile] :: TlsSettings -> String
- System.IO.Uniform: [tlsPrivateKeyFile] :: TlsSettings -> String
- System.IO.Uniform: data TlsIO
- System.IO.Uniform: instance Data.Default.Class.Default System.IO.Uniform.TlsSettings
- System.IO.Uniform: instance GHC.Read.Read System.IO.Uniform.TlsSettings
- System.IO.Uniform: instance GHC.Show.Show System.IO.Uniform.TlsSettings
- System.IO.Uniform: instance System.IO.Uniform.UniformIO System.IO.Uniform.External.TlsIO
- System.IO.Uniform: instance System.IO.Uniform.UniformIO System.IO.Uniform.SomeIO
- System.IO.Uniform.ByteString: instance System.IO.Uniform.UniformIO System.IO.Uniform.ByteString.ByteStringIO
- System.IO.Uniform.File: instance System.IO.Uniform.UniformIO System.IO.Uniform.External.FileIO
- System.IO.Uniform.Network: instance System.IO.Uniform.UniformIO System.IO.Uniform.External.SocketIO
- System.IO.Uniform.Std: instance System.IO.Uniform.UniformIO System.IO.Uniform.External.StdIO
- System.IO.Uniform.Streamline: instance (GHC.Base.Functor m, GHC.Base.Monad m) => GHC.Base.Applicative (System.IO.Uniform.Streamline.Streamline m)
- System.IO.Uniform.Streamline: instance Control.Monad.IO.Class.MonadIO m => Control.Monad.IO.Class.MonadIO (System.IO.Uniform.Streamline.Streamline m)
- System.IO.Uniform.Streamline: instance Control.Monad.Trans.Class.MonadTrans System.IO.Uniform.Streamline.Streamline
- System.IO.Uniform.Streamline: instance GHC.Base.Monad m => GHC.Base.Functor (System.IO.Uniform.Streamline.Streamline m)
- System.IO.Uniform.Streamline: instance GHC.Base.Monad m => GHC.Base.Monad (System.IO.Uniform.Streamline.Streamline m)
+ System.IO.Uniform: instance Default TlsSettings
+ System.IO.Uniform: instance Read TlsSettings
+ System.IO.Uniform: instance Show TlsSettings
+ System.IO.Uniform: instance UniformIO SomeIO
+ System.IO.Uniform: tlsCertificateChainFile :: TlsSettings -> String
+ System.IO.Uniform: tlsDHParametersFile :: TlsSettings -> String
+ System.IO.Uniform: tlsPrivateKeyFile :: TlsSettings -> String
+ System.IO.Uniform.ByteString: instance UniformIO ByteStringIO
+ System.IO.Uniform.File: instance UniformIO FileIO
+ System.IO.Uniform.Network: instance UniformIO SocketIO
+ System.IO.Uniform.Std: StdIO :: StdIO
+ System.IO.Uniform.Std: instance UniformIO StdIO
+ System.IO.Uniform.Streamline: instance (Functor m, Monad m) => Applicative (Streamline m)
+ System.IO.Uniform.Streamline: instance Monad m => Functor (Streamline m)
+ System.IO.Uniform.Streamline: instance Monad m => Monad (Streamline m)
+ System.IO.Uniform.Streamline: instance MonadIO m => MonadIO (Streamline m)
+ System.IO.Uniform.Streamline: instance MonadTrans Streamline
+ System.IO.Uniform.Streamline: send' :: MonadIO m => ByteString -> Streamline m ()
- System.IO.Uniform: mapOverInput :: forall a io. UniformIO io => io -> Int -> (a -> ByteString -> IO a) -> a -> IO a
+ System.IO.Uniform: mapOverInput :: UniformIO io => io -> Int -> (a -> ByteString -> IO a) -> a -> IO a
- System.IO.Uniform: startTls :: UniformIO a => TlsSettings -> a -> IO TlsIO
+ System.IO.Uniform: startTls :: UniformIO a => TlsSettings -> a -> IO a

Files

src/System/IO/Uniform.hs view
@@ -1,53 +1,35 @@ {-# LANGUAGE ExistentialQuantification #-}--- {-# LANGUAGE OverloadedStrings #-}--- {-# LANGUAGE ForeignFunctionInterface #-}--- {-# LANGUAGE InterruptibleFFI #-}--- {-# LANGUAGE EmptyDataDecls #-} --- |--- Uniform-IO provides a typeclass for uniform access of different types of targets,--- and implementations for abstracting standard streams, files and network connections.--- This module also provides TLS wraping over other IO targets.+{- |+Uniform-IO provides a typeclass for uniform access of different types of targets,+and implementations for abstracting standard streams, files and network connections.+This module also provides TLS wraping over other IO targets.+-} module System.IO.Uniform (   UniformIO(..),   TlsSettings(..),-  SomeIO(..), TlsIO,+  SomeIO(..),   mapOverInput   ) where -import System.IO.Uniform.External--import Foreign---import Foreign.C.Types---import Foreign.C.String-import Foreign.C.Error---import qualified Data.IP as IP import Data.ByteString (ByteString)-import qualified Data.ByteString as BS---import qualified Data.ByteString.Lazy as LBS---import qualified Data.ByteString.Builder as BSBuild---import qualified Data.List as L import Control.Exception import Control.Applicative ((<$>))---import Data.Monoid (mappend)---import qualified Network.Socket as Soc import System.IO.Error---import Control.Concurrent.MVar  import Data.Default.Class -import System.Posix.Types (Fd(..))---- |--- Typeclass for uniform IO targets.+-- | Typeclass for uniform IO targets. class UniformIO a where-  -- | uRead fd n-  ---  --  Reads a block of at most n bytes of data from the IO target.-  --  Reading will block if there's no data available, but will return immediately-  --  if any amount of data is availble.-  ---  --  Must thow System.IO.Error.EOFError if reading beihond EOF.+  {- |+  uRead fd n+  +  Reads a block of at most n bytes of data from the IO target.+  Reading will block if there's no data available, but will return immediately+  if any amount of data is availble.+    +  Must thow System.IO.Error.EOFError if reading beihond EOF.+  -}   uRead  :: a -> Int -> IO ByteString   -- | uPut fd text   --@@ -61,7 +43,7 @@   -- | startTLS fd   --   --  Starts a TLS connection over the IO target.-  startTls :: TlsSettings -> a -> IO TlsIO+  startTls :: TlsSettings -> a -> IO a   -- | isSecure fd   --   --  Indicates whether the data written or read from fd is secure at transport.@@ -74,7 +56,7 @@   uRead (SomeIO s) n = uRead s n   uPut (SomeIO s) t  = uPut s t   uClose (SomeIO s) = uClose s-  startTls set (SomeIO s) = startTls set s+  startTls set (SomeIO s) = SomeIO <$> startTls set s   isSecure (SomeIO s) = isSecure s  -- | Settings for starttls functions.@@ -83,38 +65,14 @@ instance Default TlsSettings where   def = TlsSettings "" "" ""   --- | UniformIO wrapper that applies TLS to communication on IO target.--- This type is constructed by calling startTls on other targets.-instance UniformIO TlsIO where-  uRead s n = do-    allocaArray n (-      \b -> do-        count <- c_recvTls (tls s) b $ fromIntegral n-        if count < 0-          then throwErrno "could not read"-          else BS.packCStringLen (b, fromIntegral count)-      )-  uPut s t = do-    BS.useAsCStringLen t (-      \(str, n) -> do-        count <- c_sendTls (tls s) str $ fromIntegral n-        if count < 0-          then throwErrno "could not write"-          else return ()-      )-  uClose s = do-    d <- c_closeTls (tls s)-    f <- Fd <$> c_prepareToClose d-    closeFd f-  startTls _ s = return s-  isSecure _ = True+{- |+mapOverInput io block_size f initial +Reads io untill the end of file, evaluating a(i) <- f a(i-1) read_data+where a(0) = initial and the last value after io reaches EOF is returned. --- | mapOverInput io block_size f initial---   Reads io untill the end of file, evaluating a(i) <- f a(i-1) read_data---   where a(0) = initial and the last value after io reaches EOF is returned.------   Notice that the length of read_data might not be equal block_size.+Notice that the length of read_data might not be equal block_size.+-} mapOverInput :: forall a io. UniformIO io => io -> Int -> (a -> ByteString -> IO a) -> a -> IO a mapOverInput io block f initial = do   a <- tryIOError $ uRead io block
src/System/IO/Uniform/ByteString.hs view
@@ -1,8 +1,4 @@--- {-# LANGUAGE OverloadedStrings #-}--- {-# LANGUAGE ExistentialQuantification #-}--- {-# LANGUAGE ForeignFunctionInterface #-}--- {-# LANGUAGE InterruptibleFFI #-}--- {-# LANGUAGE EmptyDataDecls #-}+{-# LANGUAGE OverloadedStrings #-}  module System.IO.Uniform.ByteString (   ByteStringIO,@@ -10,13 +6,7 @@   ) where  import System.IO.Uniform-import System.IO.Uniform.External -import Foreign---import Foreign.C.Types---import Foreign.C.String---import Foreign.C.Error--- import qualified Data.IP as IP import Data.ByteString (ByteString) import qualified Data.ByteString as BS import qualified Data.ByteString.Lazy as LBS@@ -52,7 +42,7 @@     let o' = mappend o $ BSBuild.byteString t     putMVar (bsiooutput s) o'   uClose _ = return ()-  startTls _ _ = return . TlsIO $ nullPtr+  startTls _ a = return a   isSecure _ = True  -- | withByteStringIO input f
src/System/IO/Uniform/External.hs view
@@ -1,6 +1,4 @@-{-# LANGUAGE ForeignFunctionInterface #-}-{-# LANGUAGE InterruptibleFFI #-}-{-# LANGUAGE EmptyDataDecls #-}+{-# LANGUAGE ForeignFunctionInterface, InterruptibleFFI, EmptyDataDecls #-}  module System.IO.Uniform.External where @@ -14,11 +12,13 @@ -- | A bounded IP port from where to accept SocketIO connections. newtype BoundedPort = BoundedPort {lis :: (Ptr Nethandler)} data Ds-newtype SocketIO = SocketIO {sock :: (Ptr Ds)}-newtype FileIO = FileIO {fd :: (Ptr Ds)} data TlsDs-newtype TlsIO = TlsIO {tls :: (Ptr TlsDs)}-data StdIO+-- | UniformIO IP connections.+data SocketIO = SocketIO {sock :: (Ptr Ds)} | TlsSocketIO {bio :: (Ptr TlsDs)}+-- | UniformIO type for file IO.+newtype FileIO = FileIO {fd :: (Ptr Ds)}+-- | UniformIO that reads from stdin and writes to stdout.+data StdIO = StdIO  closeFd :: Fd -> IO () closeFd (Fd f) = c_closeFd f
src/System/IO/Uniform/File.hs view
@@ -1,9 +1,3 @@--- {-# LANGUAGE OverloadedStrings #-}--- {-# LANGUAGE ExistentialQuantification #-}--- {-# LANGUAGE ForeignFunctionInterface #-}--- {-# LANGUAGE InterruptibleFFI #-}--- {-# LANGUAGE EmptyDataDecls #-}- module System.IO.Uniform.File (   FileIO,   openFile@@ -55,9 +49,8 @@   uClose s = do     f <- Fd <$> c_prepareToClose (fd s)     closeFd f-  -- Not implemented yet.-  startTls _ _ = return . TlsIO $ nullPtr-  isSecure _ = False+  startTls _ f = return f+  isSecure _ = True       -- | Open a file for bidirectional IO.
src/System/IO/Uniform/Network.hs view
@@ -1,9 +1,3 @@--- {-# LANGUAGE OverloadedStrings #-}--- {-# LANGUAGE ExistentialQuantification #-}--- {-# LANGUAGE ForeignFunctionInterface #-}--- {-# LANGUAGE InterruptibleFFI #-}--- {-# LANGUAGE EmptyDataDecls #-}- module System.IO.Uniform.Network (   SocketIO,   BoundedPort,@@ -41,37 +35,59 @@  -- | UniformIO IP connections. instance UniformIO SocketIO where-  uRead s n = do+  uRead (SocketIO s) n = do     allocaArray n (       \b -> do-        count <- c_recv (sock s) b (fromIntegral n)+        count <- c_recv s b (fromIntegral n)         if count < 0           then throwErrno "could not read"           else BS.packCStringLen (b, fromIntegral count)       )-  uPut s t = do+  uRead (TlsSocketIO s) n = do+    allocaArray n (+      \b -> do+        count <- c_recvTls s b $ fromIntegral n+        if count < 0+          then throwErrno "could not read"+          else BS.packCStringLen (b, fromIntegral count)+      )+  uPut (SocketIO s) t = do     BS.useAsCStringLen t (       \(str, n) -> do-        count <- c_send (sock s) str $ fromIntegral n+        count <- c_send s str $ fromIntegral n         if count < 0           then throwErrno "could not write"           else return ()       )-  uClose s = do-    f <- Fd <$> c_prepareToClose (sock s)+  uPut (TlsSocketIO s) t = do+    BS.useAsCStringLen t (+      \(str, n) -> do+        count <- c_sendTls s str $ fromIntegral n+        if count < 0+          then throwErrno "could not write"+          else return ()+      )+  uClose (SocketIO s) = do+    f <- Fd <$> c_prepareToClose s     closeFd f-  startTls st s = withCString (tlsCertificateChainFile st) (+  uClose (TlsSocketIO s) = do+    d <- c_closeTls s+    f <- Fd <$> c_prepareToClose d+    closeFd f+  startTls st (SocketIO s) = withCString (tlsCertificateChainFile st) (     \cert -> withCString (tlsPrivateKeyFile st) (       \key -> withCString (tlsDHParametersFile st) (         \para -> do-          r <- c_startSockTls (sock s) cert key para+          r <- c_startSockTls s cert key para           if r == nullPtr             then throwErrno "could not start TLS"-            else return . TlsIO $ r+            else return . TlsSocketIO $ r         )       )     )-  isSecure _ = False+  startTls _ s@(TlsSocketIO _) = return s+  isSecure (SocketIO _) = False+  isSecure (TlsSocketIO _) = True   -- | connectToHost hostName port
src/System/IO/Uniform/Std.hs view
@@ -1,36 +1,14 @@--- {-# LANGUAGE OverloadedStrings #-}--- {-# LANGUAGE ExistentialQuantification #-}--- {-# LANGUAGE ForeignFunctionInterface #-}--- {-# LANGUAGE InterruptibleFFI #-}--- {-# LANGUAGE EmptyDataDecls #-}- module System.IO.Uniform.Std (-  StdIO+  StdIO(StdIO)   ) where  import System.IO.Uniform import System.IO.Uniform.External  import Foreign---import Foreign.C.Types---import Foreign.C.String import Foreign.C.Error---import qualified Data.IP as IP---import Data.ByteString (ByteString) import qualified Data.ByteString as BS---import qualified Data.ByteString.Lazy as LBS---import qualified Data.ByteString.Builder as BSBuild---import qualified Data.List as L---import Control.Exception---import Control.Applicative ((<$>))---import Data.Monoid (mappend)---import qualified Network.Socket as Soc---import System.IO.Error---import Control.Concurrent.MVar ---import Data.Default.Class----import System.Posix.Types (Fd(..)) -- | UniformIO that reads from stdin and writes to stdout. instance UniformIO StdIO where   uRead _ n = do@@ -50,5 +28,5 @@           else return ()       )   uClose _ = return ()-  startTls _ _ = return . TlsIO $ nullPtr-  isSecure _ = False+  startTls _ a = return a+  isSecure _ = True
src/System/IO/Uniform/Streamline.hs view
@@ -3,7 +3,7 @@ -- | -- Streamline exports a monad that, given an uniform IO target, emulates -- character tream IO using high performance block IO.-module System.IO.Uniform.Streamline (Streamline, withClient, withServer, withTarget, send, receiveLine, lazyRecieveLine, lazyReceiveN, startTls, runAttoparsec, runAttoparsecAndReturn, isSecure, setTimeout, setEcho) where+module System.IO.Uniform.Streamline (Streamline, withClient, withServer, withTarget, send, send', receiveLine, lazyRecieveLine, lazyReceiveN, startTls, runAttoparsec, runAttoparsecAndReturn, isSecure, setTimeout, setEcho) where  import qualified System.IO.Uniform as S import qualified System.IO.Uniform.Network as N@@ -16,6 +16,7 @@ import System.IO.Error import Data.ByteString (ByteString) import qualified Data.ByteString as BS+import qualified Data.ByteString.Lazy as LBS import Data.Word8 (Word8) import Data.IP (IP) @@ -107,6 +108,13 @@ send :: MonadIO m => ByteString -> Streamline m () send r = Streamline $ \cl -> do   writeF cl r+  return ((), cl)++-- | Sends data from a lazy byte string+send' :: MonadIO m => LBS.ByteString -> Streamline m ()+send' r = Streamline $ \cl -> do+  let dd = LBS.toChunks r+  mapM (writeF cl) dd   return ((), cl)  -- | Receives a line from the streamlined IO target.
uniform-io.cabal view
@@ -10,7 +10,7 @@ -- PVP summary:      +-+------- breaking API changes --                   | | +----- non-breaking API additions --                   | | | +--- code changes with no API change-version:    1.0.0.0+version:    1.0.1.0  -- A short (one-line) description of the package. synopsis:   Uniform IO over files, network, anything.@@ -20,11 +20,11 @@     This library defines a typeclass for abstracting     the differences between the several IO channels available.     It also includes implementations for standard IO, files and-    network IO, and easy to use TLS wrapping of any of those.+    network IO, and easy to use TLS wrapping of network data,+    with an extensible interface for user supplied instances. -    Currently TLS only wraps sockets, and there's no support-    for TLS certificate verification. Those are planned-    to be added soon.+    Currently there's no support for TLS certificate verification.+    That is planned to be added soon.      Requires a '-threaded' compiler switch. @@ -70,7 +70,7 @@ source-repository this   type:     git   location: https://sealgram.com/git/haskell/uniform-io-  tag:   1.0.0.0+  tag:   1.0.1.0  library   -- Modules exported by the library.@@ -90,13 +90,15 @@    -- LANGUAGE extensions used by modules in this package.   other-extensions:-      OverloadedStrings,-      ExistentialQuantification,+      OverloadedStrings+      ExistentialQuantification       ForeignFunctionInterface+      InterruptibleFFI+      EmptyDataDecls      -- Other library packages from which modules are imported.   build-depends:-      base >=4.7 && <5.0,+      base >=4.7 && <4.8,       iproute >=1.4 && <2.0,       bytestring >=0.10 && <1.0,       network >=2.4 && <3.0,@@ -126,7 +128,7 @@     base >=4.7 && <5.0,     Cabal >= 1.9.2,     bytestring >=0.10 && <1.0,-    uniform-io == 1.0.0.0+    uniform-io   ghc-options: -Wall -fno-warn-unused-do-bind -fwarn-incomplete-patterns -threaded   default-language: Haskell2010 @@ -140,6 +142,6 @@     Cabal >= 1.9.2,     bytestring >=0.10 && <1.0,     attoparsec >=0.10 && <1.0,-    uniform-io == 1.0.0.0+    uniform-io   ghc-options: -Wall -fno-warn-unused-do-bind -fwarn-incomplete-patterns -threaded   default-language: Haskell2010