diff --git a/cabal.project b/cabal.project new file mode 100644 index 0000000..17c0fd3 --- /dev/null +++ b/cabal.project @@ -0,0 +1,2 @@ +packages: ./libssh2 + ./libssh2-conduit diff --git a/libssh2/libssh2.cabal b/libssh2/libssh2.cabal index 987f6eb..160ea29 100644 --- a/libssh2/libssh2.cabal +++ b/libssh2/libssh2.cabal @@ -61,7 +61,7 @@ Library Includes: include/libssh2_local.h Build-depends: base >= 4 && < 5, - network >= 2.3 && < 3.0, + network >= 2.3 && < 3.2, syb >= 0.3.3, time >= 1.2, bytestring >= 0.9, unix diff --git a/libssh2/src/Network/SSH/Client/LibSSH2/Foreign.chs b/libssh2/src/Network/SSH/Client/LibSSH2/Foreign.chs index 52bd77f..c4d30fb 100644 --- a/libssh2/src/Network/SSH/Client/LibSSH2/Foreign.chs +++ b/libssh2/src/Network/SSH/Client/LibSSH2/Foreign.chs @@ -76,7 +76,11 @@ import Foreign hiding (void) import Foreign.C.Types import Foreign.C.String import System.IO +#if MIN_VERSION_network(3,0,0) +import Network.Socket (Socket, withFdSocket) +#else import Network.Socket (Socket(MkSocket), isReadable) +#endif import qualified Data.ByteString as BSS import qualified Data.ByteString.Unsafe as BSS @@ -144,6 +148,24 @@ init_crypto :: Bool -> CInt init_crypto False = 1 init_crypto True = 0 +#if MIN_VERSION_network(3,0,0) +ssh2socket :: Socket +#ifdef mingw32_HOST_OS + #ifdef x86_64_HOST_ARCH + -> CULLong + #else + -> IO CUInt + #endif +#else + -> IO CInt +#endif +ssh2socket s = +#ifdef mingw32_HOST_OS + fromIntegral <$> withFdSocket s pure +#else + withFdSocket s pure +#endif +#else ssh2socket :: Socket #ifdef mingw32_HOST_OS #ifdef x86_64_HOST_ARCH @@ -153,7 +175,7 @@ ssh2socket :: Socket #endif #else -> CInt -#endif +#endif /* mingw32_HOST_OS */ ssh2socket (MkSocket s _ _ _ _) = #ifdef mingw32_HOST_OS (fromIntegral s) @@ -161,6 +183,8 @@ ssh2socket (MkSocket s _ _ _ _) = s #endif +#endif /* MIN_VERSION_network(3,0,0) */ + {# fun init as initialize_ { init_crypto `Bool' } -> `Int' #} @@ -209,14 +233,24 @@ bool2int :: Bool -> CInt bool2int True = 1 bool2int False = 0 +#if MIN_VERSION_network(3,0,0) +{# fun session_handshake + { `Ptr ()', `CInt' } -> `Int' #} + +handshake_ :: Session -> Socket -> IO Int +handshake_ session socket = do + session_handshake (toPointer session) =<< ssh2socket socket +#else {# fun session_handshake as handshake_ { toPointer `Session', ssh2socket `Socket' } -> `Int' #} +#endif -- | Run SSH handshake on network socket. handshake :: Session -> Socket -> IO () handshake session socket = do sessionSetSocket session (Just socket) - void . handleInt (Just session) $ handshake_ session socket + void $ handleInt (Just session) + $ handshake_ session socket {# fun knownhost_init as initKnownHosts_ { toPointer `Session' } -> `Ptr ()' id #} @@ -543,7 +577,11 @@ pollChannelRead ch = do mbSocket <- sessionGetSocket (channelSession ch) case mbSocket of Nothing -> error "pollChannelRead without socket present" +#if MIN_VERSION_network(3,0,0) + Just _ -> pure True +#else Just socket -> isReadable socket +#endif -- -- | Sftp support @@ -893,4 +931,4 @@ agentAuthenticate login agent = do isAuthenticationFailed _ = Nothing withAgentPublicKeyVoidPtr :: AgentPublicKey -> (Ptr () -> IO a) -> IO a -withAgentPublicKeyVoidPtr p f = withAgentPublicKey p $ \pp -> f (castPtr pp) \ No newline at end of file +withAgentPublicKeyVoidPtr p f = withAgentPublicKey p $ \pp -> f (castPtr pp) diff --git a/libssh2/src/Network/SSH/Client/LibSSH2/WaitSocket.hs b/libssh2/src/Network/SSH/Client/LibSSH2/WaitSocket.hs index 1932a80..0829dfd 100644 --- a/libssh2/src/Network/SSH/Client/LibSSH2/WaitSocket.hs +++ b/libssh2/src/Network/SSH/Client/LibSSH2/WaitSocket.hs @@ -11,7 +11,13 @@ module Network.SSH.Client.LibSSH2.WaitSocket , threadWaitWrite ) where -import Network.Socket(Socket,fdSocket) +import Network.Socket(Socket) +#if MIN_VERSION_network(3,0,0) +import Network.Socket(withFdSocket) +#else +import Network.Socket(fdSocket) +#endif + import System.Posix.Types(Fd(Fd)) #ifdef mingw32_HOST_OS @@ -26,10 +32,18 @@ import qualified GHC.Conc (threadWaitRead, threadWaitWrite) #endif threadWaitRead :: Socket -> IO () +#if MIN_VERSION_network(3,0,0) +threadWaitRead = flip withFdSocket (threadWaitRead_ . Fd) +#else threadWaitRead = threadWaitRead_ . Fd . fdSocket +#endif threadWaitWrite :: Socket -> IO () +#if MIN_VERSION_network(3,0,0) +threadWaitWrite = flip withFdSocket (threadWaitWrite_ . Fd) +#else threadWaitWrite = threadWaitWrite_ . Fd . fdSocket +#endif -- | Block the current thread until data is available to read on the -- given file descriptor (GHC only).