Hello community,

here is the log from the commit of package ghc-connection for openSUSE:Factory 
checked in at 2016-08-25 09:57:56
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Comparing /work/SRC/openSUSE:Factory/ghc-connection (Old)
 and      /work/SRC/openSUSE:Factory/.ghc-connection.new (New)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Package is "ghc-connection"

Changes:
--------
--- /work/SRC/openSUSE:Factory/ghc-connection/ghc-connection.changes    
2016-07-20 09:20:11.000000000 +0200
+++ /work/SRC/openSUSE:Factory/.ghc-connection.new/ghc-connection.changes       
2016-08-25 09:57:58.000000000 +0200
@@ -1,0 +2,5 @@
+Wed Aug 17 18:28:09 UTC 2016 - [email protected]
+
+- Update to version 0.2.6 revision 0 with cabal2obs.
+
+-------------------------------------------------------------------

Old:
----
  connection-0.2.5.tar.gz

New:
----
  connection-0.2.6.tar.gz

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Other differences:
------------------
++++++ ghc-connection.spec ++++++
--- /var/tmp/diff_new_pack.riO8XG/_old  2016-08-25 09:57:58.000000000 +0200
+++ /var/tmp/diff_new_pack.riO8XG/_new  2016-08-25 09:57:58.000000000 +0200
@@ -18,15 +18,14 @@
 
 %global pkg_name connection
 Name:           ghc-%{pkg_name}
-Version:        0.2.5
+Version:        0.2.6
 Release:        0
 Summary:        Simple and easy network connections API
 License:        BSD-3-Clause
-Group:          System/Libraries
+Group:          Development/Languages/Other
 Url:            https://hackage.haskell.org/package/%{pkg_name}
 Source0:        
https://hackage.haskell.org/package/%{pkg_name}-%{version}/%{pkg_name}-%{version}.tar.gz
 BuildRequires:  ghc-Cabal-devel
-# Begin cabal-rpm deps:
 BuildRequires:  ghc-byteable-devel
 BuildRequires:  ghc-bytestring-devel
 BuildRequires:  ghc-containers-devel
@@ -40,7 +39,6 @@
 BuildRequires:  ghc-x509-system-devel
 BuildRequires:  ghc-x509-validation-devel
 BuildRoot:      %{_tmppath}/%{name}-%{version}-build
-# End cabal-rpm deps
 
 %description
 Simple network library for all your connection need.
@@ -64,15 +62,12 @@
 %prep
 %setup -q -n %{pkg_name}-%{version}
 
-
 %build
 %ghc_lib_build
 
-
 %install
 %ghc_lib_install
 
-
 %post devel
 %ghc_pkg_recache
 

++++++ connection-0.2.5.tar.gz -> connection-0.2.6.tar.gz ++++++
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/connection-0.2.5/Network/Connection/Types.hs 
new/connection-0.2.6/Network/Connection/Types.hs
--- old/connection-0.2.5/Network/Connection/Types.hs    2015-06-19 
22:32:33.000000000 +0200
+++ new/connection-0.2.6/Network/Connection/Types.hs    2016-08-12 
08:23:14.000000000 +0200
@@ -17,13 +17,14 @@
 import Data.ByteString (ByteString)
 
 import Network.BSD (HostName)
-import Network.Socket (PortNumber)
+import Network.Socket (PortNumber, Socket)
 import qualified Network.TLS as TLS
 
 import System.IO (Handle)
 
 -- | Simple backend enumeration, either using a raw connection or a tls 
connection.
 data ConnectionBackend = ConnectionStream Handle
+                       | ConnectionSocket Socket
                        | ConnectionTLS TLS.Context
 
 -- | Connection Parameters to establish a Connection.
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/connection-0.2.5/Network/Connection.hs 
new/connection-0.2.6/Network/Connection.hs
--- old/connection-0.2.5/Network/Connection.hs  2015-06-19 22:32:33.000000000 
+0200
+++ new/connection-0.2.6/Network/Connection.hs  2016-08-12 08:23:14.000000000 
+0200
@@ -22,6 +22,8 @@
 
     -- * Exceptions
     , LineTooLong(..)
+    , HostNotResolved(..)
+    , HostCannotConnect(..)
 
     -- * Library initialization
     , initConnectionContext
@@ -29,11 +31,13 @@
 
     -- * Connection operation
     , connectFromHandle
+    , connectFromSocket
     , connectTo
     , connectionClose
 
     -- * Sending and receiving data
     , connectionGet
+    , connectionGetExact
     , connectionGetChunk
     , connectionGetChunk'
     , connectionGetLine
@@ -57,6 +61,10 @@
 
 import Network.Socks5
 import qualified Network as N
+import Network.Socket
+import Network.BSD (getProtocolNumber)
+import qualified Network.Socket as N (close)
+import qualified Network.Socket.ByteString as N
 
 import Data.Default.Class
 import Data.Data
@@ -77,7 +85,15 @@
 -- the line in ConnectionGetLine.
 data LineTooLong = LineTooLong deriving (Show,Typeable)
 
+-- | Exception raised when there's no resolution for a specific host
+data HostNotResolved = HostNotResolved String deriving (Show,Typeable)
+
+-- | Exception raised when the connect failed
+data HostCannotConnect = HostCannotConnect String [E.IOException] deriving 
(Show,Typeable)
+
 instance E.Exception LineTooLong
+instance E.Exception HostNotResolved
+instance E.Exception HostCannotConnect
 
 connectionSessionManager :: Manager -> TLS.SessionManager
 connectionSessionManager mvar = TLS.SessionManager
@@ -135,6 +151,19 @@
           withSecurity (Just tlsSettings) = tlsEstablish h (makeTLSParams cg 
cid tlsSettings) >>= connectionNew cid . ConnectionTLS
           cid = (connectionHostname p, connectionPort p)
 
+-- | Use an already established handle to create a connection object.
+--
+-- if the TLS Settings is set, it will do the handshake with the server.
+-- The SOCKS settings have no impact here, as the handle is already established
+connectFromSocket :: ConnectionContext
+                  -> Socket
+                  -> ConnectionParams
+                  -> IO Connection
+connectFromSocket cg sock p = withSecurity (connectionUseSecure p)
+    where withSecurity Nothing            = connectionNew cid $ 
ConnectionSocket sock
+          withSecurity (Just tlsSettings) = tlsEstablish sock (makeTLSParams 
cg cid tlsSettings) >>= connectionNew cid . ConnectionTLS
+          cid = (connectionHostname p, connectionPort p)
+
 -- | connect to a destination using the parameter
 connectTo :: ConnectionContext -- ^ The global context of this connection.
           -> ConnectionParams  -- ^ The parameters for this connection (where 
to connect, and such).
@@ -142,22 +171,22 @@
 connectTo cg cParams = do
     conFct <- getConFct (connectionUseSocks cParams)
     h      <- conFct (connectionHostname cParams) (N.PortNumber $ 
connectionPort cParams)
-    connectFromHandle cg h cParams
+    connectFromSocket cg h cParams
   where
-        getConFct Nothing                            = return N.connectTo
-        getConFct (Just (OtherProxy h p))            = return $ \_ _ -> 
N.connectTo h (N.PortNumber p)
-        getConFct (Just (SockSettingsSimple h p))    = return $ socksConnectTo 
h (N.PortNumber p)
+        getConFct Nothing                            = return resolve'
+        getConFct (Just (OtherProxy h p))            = return $ \_ _ -> 
resolve' h (N.PortNumber p)
+        getConFct (Just (SockSettingsSimple h p))    = return $ 
socksConnectTo' h (N.PortNumber p)
         getConFct (Just (SockSettingsEnvironment v)) = do
             -- if we can't get the environment variable or that the variable 
cannot be parsed
             -- we connect directly.
             let name = maybe "SOCKS_SERVER" id v
             evar <- E.try (getEnv name)
             case evar of
-                Left (_ :: E.IOException) -> return N.connectTo
+                Left (_ :: E.IOException) -> return resolve'
                 Right var                 ->
                     case parseSocks var of
-                        Nothing             -> return N.connectTo
-                        Just (sHost, sPort) -> return $ socksConnectTo sHost 
(N.PortNumber $ fromIntegral (sPort :: Int))
+                        Nothing             -> return resolve'
+                        Just (sHost, sPort) -> return $ socksConnectTo' sHost 
(N.PortNumber $ fromIntegral (sPort :: Int))
 
         -- Try to parse "host:port" or "host"
         parseSocks s =
@@ -169,12 +198,57 @@
                         _            -> Nothing
                 _                  -> Nothing
 
+        resolve' host portid = do
+            let serv = case portid of
+                            N.Service serv -> serv
+                            N.PortNumber n -> show n
+                            _              -> error "cannot resolve service" 
+            proto <- getProtocolNumber "tcp"
+            let hints = defaultHints { addrFlags = [AI_ADDRCONFIG]
+                                     , addrProtocol = proto
+                                     , addrSocketType = Stream }
+            addrs <- getAddrInfo (Just hints) (Just host) (Just serv)
+            firstSuccessful $ map tryToConnect addrs
+          where
+            tryToConnect addr =
+                E.bracketOnError
+                    (socket (addrFamily addr) (addrSocketType addr) 
(addrProtocol addr))
+                    (N.close)
+                    (\sock -> connect sock (addrAddress addr) >> return sock)
+            firstSuccessful = go []
+              where
+                go :: [E.IOException] -> [IO a] -> IO a
+                go []      [] = E.throwIO $ HostNotResolved host
+                go l@(_:_) [] = E.throwIO $ HostCannotConnect host l
+                go acc     (act:followingActs) = do
+                    er <- E.try act
+                    case er of
+                        Left err -> go (err:acc) followingActs
+                        Right r  -> return r
+
 -- | Put a block of data in the connection.
 connectionPut :: Connection -> ByteString -> IO ()
 connectionPut connection content = withBackend doWrite connection
     where doWrite (ConnectionStream h) = B.hPut h content >> hFlush h
+          doWrite (ConnectionSocket s) = N.sendAll s content
           doWrite (ConnectionTLS ctx)  = TLS.sendData ctx $ L.fromChunks 
[content]
 
+-- | Get exact count of bytes from a connection.
+--
+-- The size argument is the exact amount that must be returned to the user.
+-- The call will wait until all data is available.  Hence, it behaves like
+-- 'B.hGet'.
+--
+-- On end of input, 'connectionGetExact' will throw an 'E.isEOFError'
+-- exception.
+connectionGetExact :: Connection -> Int -> IO ByteString
+connectionGetExact conn x = loop B.empty 0
+  where loop bs y
+          | y == x = return bs
+          | otherwise = do
+            next <- connectionGet conn (x - y)
+            loop (B.append bs next) (y + (B.length next))
+
 -- | Get some bytes from a connection.
 --
 -- The size argument is just the maximum that could be returned to the user.
@@ -214,6 +288,7 @@
                   updateBuf buf
   where
     getMoreData (ConnectionTLS tlsctx) = TLS.recvData tlsctx
+    getMoreData (ConnectionSocket sock) = N.recv sock 1500
     getMoreData (ConnectionStream h)   = B.hGetSome h (16 * 1024)
 
     updateBuf buf = case f buf of (a, !buf') -> return (Just buf', a)
@@ -278,6 +353,7 @@
 connectionClose :: Connection -> IO ()
 connectionClose = withBackend backendClose
     where backendClose (ConnectionTLS ctx)  = TLS.bye ctx >> TLS.contextClose 
ctx
+          backendClose (ConnectionSocket sock) = N.close sock
           backendClose (ConnectionStream h) = hClose h
 
 -- | Activate secure layer using the parameters specified.
@@ -298,15 +374,18 @@
         case backend of
             (ConnectionStream h) -> do ctx <- tlsEstablish h (makeTLSParams cg 
(connectionID connection) params)
                                        return (ConnectionTLS ctx, Just B.empty)
+            (ConnectionSocket s) -> do ctx <- tlsEstablish s (makeTLSParams cg 
(connectionID connection) params)
+                                       return (ConnectionTLS ctx, Just B.empty)
             (ConnectionTLS _)    -> return (backend, b)
 
 -- | Returns if the connection is establish securely or not.
 connectionIsSecure :: Connection -> IO Bool
 connectionIsSecure conn = withBackend isSecure conn
     where isSecure (ConnectionStream _) = return False
+          isSecure (ConnectionSocket _) = return False
           isSecure (ConnectionTLS _)    = return True
 
-tlsEstablish :: Handle -> TLS.ClientParams -> IO TLS.Context
+tlsEstablish :: TLS.HasBackend backend => backend -> TLS.ClientParams -> IO 
TLS.Context
 tlsEstablish handle tlsParams = do
     ctx <- TLS.contextNew handle tlsParams
     TLS.handshake ctx
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/connection-0.2.5/connection.cabal 
new/connection-0.2.6/connection.cabal
--- old/connection-0.2.5/connection.cabal       2015-06-19 22:32:33.000000000 
+0200
+++ new/connection-0.2.6/connection.cabal       2016-08-12 08:23:14.000000000 
+0200
@@ -1,5 +1,5 @@
 Name:                connection
-Version:             0.2.5
+Version:             0.2.6
 Description:
     Simple network library for all your connection need.
     .
@@ -29,7 +29,7 @@
                    , data-default-class
                    , network >= 2.3
                    , tls >= 1.3
-                   , socks >= 0.4
+                   , socks >= 0.5.5
                    , x509 >= 1.5
                    , x509-store >= 1.5
                    , x509-system >= 1.5
@@ -40,4 +40,4 @@
 
 source-repository head
   type: git
-  location: git://github.com/vincenthz/hs-connection
+  location: https://github.com/vincenthz/hs-connection


Reply via email to