-- GENERATED by C->Haskell Compiler, version 0.28.3 Switcheroo, 25 November 2017 (Haskell)
-- Edit the ORIGNAL .chs file instead!


{-# LINE 1 "src/Network/SSH/Client/LibSSH2/Errors.chs" #-}
{-# LANGUAGE ForeignFunctionInterface, DeriveDataTypeable, FlexibleInstances #-}






{-# LINE 12 "src/Network/SSH/Client/LibSSH2/Errors.chs" #-}


module Network.SSH.Client.LibSSH2.Errors
  (-- * Types
   ErrorCode (..),
   SftpErrorCode (..),
   NULL_POINTER,

   -- * Utilities
   IntResult (..),

   -- * Functions
   getLastError,
   getLastSftpError,
   handleInt,
   handleBool,
   handleNullPtr,
   int2error, error2int,
   int2sftperror, sftperror2int,
   blockedDirections,
   threadWaitSession
  ) where
import qualified Foreign.C.Types as C2HSImp
import qualified Foreign.Ptr as C2HSImp



import Control.Exception
import Data.Generics
import Foreign
import Foreign.C.Types

import Network.SSH.Client.LibSSH2.Types
import Network.SSH.Client.LibSSH2.WaitSocket

-- | Error codes returned by libssh2.
data ErrorCode =
    NONE
  | SOCKET_NONE
  | 
  | 
  | INVALID_MAC
  | KEX_FALIURE
  | ALLOC
  | SOCKET_SEND
  | KEY_EXCHANGE_FAILURE
  | TIMEOUT
  | HOSTKEY_INIT
  | HOSTKEY_SIGN
  | DECRYPT
  | SOCKET_DISCONNECT
  | PROTO
  | PASSWORD_EXPIRED
  | FILE
  | METHOD_NONE
  | AUTHENTICATION_FAILED
  | PUBLICKEY_UNVERIFIED
  | CHANNEL_OUTOFORDER
  | CHANNEL_FAILURE
  | CHANNEL_REQUEST_DENIED
  | CHANNEL_UNKNOWN
  | CHANNEL_WINDOW_EXCEEDED
  | CHANNEL_PACKET_EXCEEDED
  | CHANNEL_CLOSED
  | CHANNEL_EOF_SENT
  | SCP_PROTOCOL
  | ZLIB
  | SOCKET_TIMEOUT
  | SFTP_PROTOCOL
  | REQUEST_DENIED
  | METHOD_NOT_SUPPORTED
  | INVAL
  | INVALID_POLL_TYPE
  | PUBLICKEY_PROTOCOL
  | EAGAIN
  | BUFFER_TOO_SMALL
  | BAD_USE
  | COMPRESS
  | OUT_OF_BOUNDARY
  | AGENT_PROTOCOL
  | SOCKET_RECV
  | ENCRYPT
  | BAD_SOCKET
  | ERROR_KNOWN_HOSTS
  deriving (ErrorCode -> ErrorCode -> Bool
(ErrorCode -> ErrorCode -> Bool)
-> (ErrorCode -> ErrorCode -> Bool) -> Eq ErrorCode
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ErrorCode -> ErrorCode -> Bool
$c/= :: ErrorCode -> ErrorCode -> Bool
== :: ErrorCode -> ErrorCode -> Bool
$c== :: ErrorCode -> ErrorCode -> Bool
Eq, Int -> ErrorCode -> ShowS
[ErrorCode] -> ShowS
ErrorCode -> String
(Int -> ErrorCode -> ShowS)
-> (ErrorCode -> String)
-> ([ErrorCode] -> ShowS)
-> Show ErrorCode
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ErrorCode] -> ShowS
$cshowList :: [ErrorCode] -> ShowS
show :: ErrorCode -> String
$cshow :: ErrorCode -> String
showsPrec :: Int -> ErrorCode -> ShowS
$cshowsPrec :: Int -> ErrorCode -> ShowS
Show, Eq ErrorCode
Eq ErrorCode
-> (ErrorCode -> ErrorCode -> Ordering)
-> (ErrorCode -> ErrorCode -> Bool)
-> (ErrorCode -> ErrorCode -> Bool)
-> (ErrorCode -> ErrorCode -> Bool)
-> (ErrorCode -> ErrorCode -> Bool)
-> (ErrorCode -> ErrorCode -> ErrorCode)
-> (ErrorCode -> ErrorCode -> ErrorCode)
-> Ord ErrorCode
ErrorCode -> ErrorCode -> Bool
ErrorCode -> ErrorCode -> Ordering
ErrorCode -> ErrorCode -> ErrorCode
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: ErrorCode -> ErrorCode -> ErrorCode
$cmin :: ErrorCode -> ErrorCode -> ErrorCode
max :: ErrorCode -> ErrorCode -> ErrorCode
$cmax :: ErrorCode -> ErrorCode -> ErrorCode
>= :: ErrorCode -> ErrorCode -> Bool
$c>= :: ErrorCode -> ErrorCode -> Bool
> :: ErrorCode -> ErrorCode -> Bool
$c> :: ErrorCode -> ErrorCode -> Bool
<= :: ErrorCode -> ErrorCode -> Bool
$c<= :: ErrorCode -> ErrorCode -> Bool
< :: ErrorCode -> ErrorCode -> Bool
$c< :: ErrorCode -> ErrorCode -> Bool
compare :: ErrorCode -> ErrorCode -> Ordering
$ccompare :: ErrorCode -> ErrorCode -> Ordering
$cp1Ord :: Eq ErrorCode
Ord, Int -> ErrorCode
ErrorCode -> Int
ErrorCode -> [ErrorCode]
ErrorCode -> ErrorCode
ErrorCode -> ErrorCode -> [ErrorCode]
ErrorCode -> ErrorCode -> ErrorCode -> [ErrorCode]
(ErrorCode -> ErrorCode)
-> (ErrorCode -> ErrorCode)
-> (Int -> ErrorCode)
-> (ErrorCode -> Int)
-> (ErrorCode -> [ErrorCode])
-> (ErrorCode -> ErrorCode -> [ErrorCode])
-> (ErrorCode -> ErrorCode -> [ErrorCode])
-> (ErrorCode -> ErrorCode -> ErrorCode -> [ErrorCode])
-> Enum ErrorCode
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
enumFromThenTo :: ErrorCode -> ErrorCode -> ErrorCode -> [ErrorCode]
$cenumFromThenTo :: ErrorCode -> ErrorCode -> ErrorCode -> [ErrorCode]
enumFromTo :: ErrorCode -> ErrorCode -> [ErrorCode]
$cenumFromTo :: ErrorCode -> ErrorCode -> [ErrorCode]
enumFromThen :: ErrorCode -> ErrorCode -> [ErrorCode]
$cenumFromThen :: ErrorCode -> ErrorCode -> [ErrorCode]
enumFrom :: ErrorCode -> [ErrorCode]
$cenumFrom :: ErrorCode -> [ErrorCode]
fromEnum :: ErrorCode -> Int
$cfromEnum :: ErrorCode -> Int
toEnum :: Int -> ErrorCode
$ctoEnum :: Int -> ErrorCode
pred :: ErrorCode -> ErrorCode
$cpred :: ErrorCode -> ErrorCode
succ :: ErrorCode -> ErrorCode
$csucc :: ErrorCode -> ErrorCode
Enum, Typeable ErrorCode
DataType
Constr
Typeable ErrorCode
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> ErrorCode -> c ErrorCode)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c ErrorCode)
-> (ErrorCode -> Constr)
-> (ErrorCode -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c ErrorCode))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c ErrorCode))
-> ((forall b. Data b => b -> b) -> ErrorCode -> ErrorCode)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> ErrorCode -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> ErrorCode -> r)
-> (forall u. (forall d. Data d => d -> u) -> ErrorCode -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> ErrorCode -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> ErrorCode -> m ErrorCode)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> ErrorCode -> m ErrorCode)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> ErrorCode -> m ErrorCode)
-> Data ErrorCode
ErrorCode -> DataType
ErrorCode -> Constr
(forall b. Data b => b -> b) -> ErrorCode -> ErrorCode
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> ErrorCode -> c ErrorCode
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c ErrorCode
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> ErrorCode -> u
forall u. (forall d. Data d => d -> u) -> ErrorCode -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> ErrorCode -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> ErrorCode -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> ErrorCode -> m ErrorCode
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> ErrorCode -> m ErrorCode
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c ErrorCode
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> ErrorCode -> c ErrorCode
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c ErrorCode)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c ErrorCode)
$cERROR_KNOWN_HOSTS :: Constr
$cBAD_SOCKET :: Constr
$cENCRYPT :: Constr
$cSOCKET_RECV :: Constr
$cAGENT_PROTOCOL :: Constr
$cOUT_OF_BOUNDARY :: Constr
$cCOMPRESS :: Constr
$cBAD_USE :: Constr
$cBUFFER_TOO_SMALL :: Constr
$cEAGAIN :: Constr
$cPUBLICKEY_PROTOCOL :: Constr
$cINVALID_POLL_TYPE :: Constr
$cINVAL :: Constr
$cMETHOD_NOT_SUPPORTED :: Constr
$cREQUEST_DENIED :: Constr
$cSFTP_PROTOCOL :: Constr
$cSOCKET_TIMEOUT :: Constr
$cZLIB :: Constr
$cSCP_PROTOCOL :: Constr
$cCHANNEL_EOF_SENT :: Constr
$cCHANNEL_CLOSED :: Constr
$cCHANNEL_PACKET_EXCEEDED :: Constr
$cCHANNEL_WINDOW_EXCEEDED :: Constr
$cCHANNEL_UNKNOWN :: Constr
$cCHANNEL_REQUEST_DENIED :: Constr
$cCHANNEL_FAILURE :: Constr
$cCHANNEL_OUTOFORDER :: Constr
$cPUBLICKEY_UNVERIFIED :: Constr
$cAUTHENTICATION_FAILED :: Constr
$cMETHOD_NONE :: Constr
$cFILE :: Constr
$cPASSWORD_EXPIRED :: Constr
$cPROTO :: Constr
$cSOCKET_DISCONNECT :: Constr
$cDECRYPT :: Constr
$cHOSTKEY_SIGN :: Constr
$cHOSTKEY_INIT :: Constr
$cTIMEOUT :: Constr
$cKEY_EXCHANGE_FAILURE :: Constr
$cSOCKET_SEND :: Constr
$cALLOC :: Constr
$cKEX_FALIURE :: Constr
$cINVALID_MAC :: Constr
$cBANNER_SEND :: Constr
$cBANNER_RECV :: Constr
$cSOCKET_NONE :: Constr
$cNONE :: Constr
$tErrorCode :: DataType
gmapMo :: (forall d. Data d => d -> m d) -> ErrorCode -> m ErrorCode
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> ErrorCode -> m ErrorCode
gmapMp :: (forall d. Data d => d -> m d) -> ErrorCode -> m ErrorCode
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> ErrorCode -> m ErrorCode
gmapM :: (forall d. Data d => d -> m d) -> ErrorCode -> m ErrorCode
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> ErrorCode -> m ErrorCode
gmapQi :: Int -> (forall d. Data d => d -> u) -> ErrorCode -> u
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> ErrorCode -> u
gmapQ :: (forall d. Data d => d -> u) -> ErrorCode -> [u]
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> ErrorCode -> [u]
gmapQr :: (r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> ErrorCode -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> ErrorCode -> r
gmapQl :: (r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> ErrorCode -> r
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> ErrorCode -> r
gmapT :: (forall b. Data b => b -> b) -> ErrorCode -> ErrorCode
$cgmapT :: (forall b. Data b => b -> b) -> ErrorCode -> ErrorCode
dataCast2 :: (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c ErrorCode)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c ErrorCode)
dataCast1 :: (forall d. Data d => c (t d)) -> Maybe (c ErrorCode)
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c ErrorCode)
dataTypeOf :: ErrorCode -> DataType
$cdataTypeOf :: ErrorCode -> DataType
toConstr :: ErrorCode -> Constr
$ctoConstr :: ErrorCode -> Constr
gunfold :: (forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c ErrorCode
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c ErrorCode
gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> ErrorCode -> c ErrorCode
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> ErrorCode -> c ErrorCode
$cp1Data :: Typeable ErrorCode
Data, Typeable)

instance Exception ErrorCode

error2int :: (Num i) => ErrorCode -> i
error2int :: ErrorCode -> i
error2int = Int -> i
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> i) -> (ErrorCode -> Int) -> ErrorCode -> i
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Int
forall a. Num a => a -> a
negate (Int -> Int) -> (ErrorCode -> Int) -> ErrorCode -> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ErrorCode -> Int
forall a. Enum a => a -> Int
fromEnum

int2error :: (Integral i) => i -> ErrorCode
int2error :: i -> ErrorCode
int2error = Int -> ErrorCode
forall a. Enum a => Int -> a
toEnum (Int -> ErrorCode) -> (i -> Int) -> i -> ErrorCode
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Int
forall a. Num a => a -> a
negate (Int -> Int) -> (i -> Int) -> i -> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. i -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral

-- | Exception to throw when null pointer received
-- from libssh2.
data NULL_POINTER = NULL_POINTER
  deriving (NULL_POINTER -> NULL_POINTER -> Bool
(NULL_POINTER -> NULL_POINTER -> Bool)
-> (NULL_POINTER -> NULL_POINTER -> Bool) -> Eq NULL_POINTER
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: NULL_POINTER -> NULL_POINTER -> Bool
$c/= :: NULL_POINTER -> NULL_POINTER -> Bool
== :: NULL_POINTER -> NULL_POINTER -> Bool
$c== :: NULL_POINTER -> NULL_POINTER -> Bool
Eq, Int -> NULL_POINTER -> ShowS
[NULL_POINTER] -> ShowS
NULL_POINTER -> String
(Int -> NULL_POINTER -> ShowS)
-> (NULL_POINTER -> String)
-> ([NULL_POINTER] -> ShowS)
-> Show NULL_POINTER
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [NULL_POINTER] -> ShowS
$cshowList :: [NULL_POINTER] -> ShowS
show :: NULL_POINTER -> String
$cshow :: NULL_POINTER -> String
showsPrec :: Int -> NULL_POINTER -> ShowS
$cshowsPrec :: Int -> NULL_POINTER -> ShowS
Show, Typeable NULL_POINTER
DataType
Constr
Typeable NULL_POINTER
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> NULL_POINTER -> c NULL_POINTER)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c NULL_POINTER)
-> (NULL_POINTER -> Constr)
-> (NULL_POINTER -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c NULL_POINTER))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c NULL_POINTER))
-> ((forall b. Data b => b -> b) -> NULL_POINTER -> NULL_POINTER)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> NULL_POINTER -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> NULL_POINTER -> r)
-> (forall u. (forall d. Data d => d -> u) -> NULL_POINTER -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> NULL_POINTER -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> NULL_POINTER -> m NULL_POINTER)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> NULL_POINTER -> m NULL_POINTER)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> NULL_POINTER -> m NULL_POINTER)
-> Data NULL_POINTER
NULL_POINTER -> DataType
NULL_POINTER -> Constr
(forall b. Data b => b -> b) -> NULL_POINTER -> NULL_POINTER
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> NULL_POINTER -> c NULL_POINTER
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c NULL_POINTER
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> NULL_POINTER -> u
forall u. (forall d. Data d => d -> u) -> NULL_POINTER -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> NULL_POINTER -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> NULL_POINTER -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> NULL_POINTER -> m NULL_POINTER
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> NULL_POINTER -> m NULL_POINTER
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c NULL_POINTER
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> NULL_POINTER -> c NULL_POINTER
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c NULL_POINTER)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c NULL_POINTER)
$cNULL_POINTER :: Constr
$tNULL_POINTER :: DataType
gmapMo :: (forall d. Data d => d -> m d) -> NULL_POINTER -> m NULL_POINTER
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> NULL_POINTER -> m NULL_POINTER
gmapMp :: (forall d. Data d => d -> m d) -> NULL_POINTER -> m NULL_POINTER
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> NULL_POINTER -> m NULL_POINTER
gmapM :: (forall d. Data d => d -> m d) -> NULL_POINTER -> m NULL_POINTER
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> NULL_POINTER -> m NULL_POINTER
gmapQi :: Int -> (forall d. Data d => d -> u) -> NULL_POINTER -> u
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> NULL_POINTER -> u
gmapQ :: (forall d. Data d => d -> u) -> NULL_POINTER -> [u]
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> NULL_POINTER -> [u]
gmapQr :: (r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> NULL_POINTER -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> NULL_POINTER -> r
gmapQl :: (r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> NULL_POINTER -> r
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> NULL_POINTER -> r
gmapT :: (forall b. Data b => b -> b) -> NULL_POINTER -> NULL_POINTER
$cgmapT :: (forall b. Data b => b -> b) -> NULL_POINTER -> NULL_POINTER
dataCast2 :: (forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c NULL_POINTER)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c NULL_POINTER)
dataCast1 :: (forall d. Data d => c (t d)) -> Maybe (c NULL_POINTER)
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c NULL_POINTER)
dataTypeOf :: NULL_POINTER -> DataType
$cdataTypeOf :: NULL_POINTER -> DataType
toConstr :: NULL_POINTER -> Constr
$ctoConstr :: NULL_POINTER -> Constr
gunfold :: (forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c NULL_POINTER
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c NULL_POINTER
gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> NULL_POINTER -> c NULL_POINTER
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> NULL_POINTER -> c NULL_POINTER
$cp1Data :: Typeable NULL_POINTER
Data, Typeable)

instance Exception NULL_POINTER

class IntResult a where
  intResult :: a -> Int

instance IntResult Int where
  intResult :: Int -> Int
intResult = Int -> Int
forall a. a -> a
id

instance IntResult (Int, a) where
  intResult :: (Int, a) -> Int
intResult = (Int, a) -> Int
forall a b. (a, b) -> a
fst

instance IntResult (Int, a, b) where
  intResult :: (Int, a, b) -> Int
intResult = \(Int
i, a
_, b
_) -> Int
i

instance IntResult (Int, a, b, c) where
  intResult :: (Int, a, b, c) -> Int
intResult = \(Int
i, a
_, b
_, c
_) -> Int
i

instance IntResult CInt where
  intResult :: CInt -> Int
intResult = CInt -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral

instance IntResult CLong where
  intResult :: CLong -> Int
intResult = CLong -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral

instance IntResult CLLong where
  intResult :: CLLong -> Int
intResult = CLLong -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral

getLastError_ :: (Session) -> (Ptr Int) -> (Int) -> IO ((Int), (String))
getLastError_ :: Session -> Ptr Int -> Int -> IO (Int, String)
getLastError_ Session
a1 Ptr Int
a3 Int
a4 =
  let {a1' :: Ptr ()
a1' = Session -> Ptr ()
forall p. ToPointer p => p -> Ptr ()
toPointer Session
a1} in 
  (Ptr (Ptr CChar) -> IO (Int, String)) -> IO (Int, String)
forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca ((Ptr (Ptr CChar) -> IO (Int, String)) -> IO (Int, String))
-> (Ptr (Ptr CChar) -> IO (Int, String)) -> IO (Int, String)
forall a b. (a -> b) -> a -> b
$ \Ptr (Ptr CChar)
a2' -> 
  let {a3' :: Ptr b
a3' = Ptr Int -> Ptr b
forall a b. Ptr a -> Ptr b
castPtr Ptr Int
a3} in 
  let {a4' :: CInt
a4' = Int -> CInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
a4} in 
  Ptr () -> Ptr (Ptr CChar) -> Ptr CInt -> CInt -> IO CInt
getLastError_'_ Ptr ()
a1' Ptr (Ptr CChar)
a2' Ptr CInt
forall a. Ptr a
a3' CInt
a4' IO CInt -> (CInt -> IO (Int, String)) -> IO (Int, String)
>>= \res ->
  let {res' = fromIntegral res} in
  peekCStringPtr  a2'>>= \a2'' -> 
  return (res', a2'')

{-# LINE 137 "src/Network/SSH/Client/LibSSH2/Errors.chs" #-}


-- | Get last error information.
getLastError :: Session -> IO (Int, String)
getLastError s = getLastError_ s nullPtr 0

-- | Throw an exception if negative value passed,
-- or return unchanged value.
handleInt :: (IntResult a, SshCtx ctx) => Maybe ctx -> IO a -> IO a
handleInt s io = do
  x <- io
  let r = intResult x
  if r < 0
    then case int2error r of
           EAGAIN -> threadWaitSession s >> handleInt s io
           err    ->
             case s of
               Nothing  -> throw err
               Just ctx -> ctx -> ErrorCode -> IO a
forall a b. SshCtx a => a -> ErrorCode -> IO b
throwCtxSpecificError ctx
ctx ErrorCode
err
    else a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return a
x

handleBool :: CInt -> IO Bool
handleBool :: CInt -> IO Bool
handleBool CInt
x
  | CInt
x CInt -> CInt -> Bool
forall a. Eq a => a -> a -> Bool
== CInt
0 = Bool -> IO Bool
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
False
  | CInt
x CInt -> CInt -> Bool
forall a. Ord a => a -> a -> Bool
> CInt
0  = Bool -> IO Bool
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
True
  | Bool
otherwise = ErrorCode -> IO Bool
forall a e. Exception e => e -> a
throw (CInt -> ErrorCode
forall i. Integral i => i -> ErrorCode
int2error CInt
x)

-- | Throw an exception if null pointer passed,
-- or return it casted to right type.
handleNullPtr :: (SshCtx c) => Maybe c -> (Ptr () -> IO a) -> IO (Ptr ()) -> IO a
handleNullPtr :: Maybe c -> (Ptr () -> IO a) -> IO (Ptr ()) -> IO a
handleNullPtr Maybe c
m_ctx Ptr () -> IO a
fromPointer IO (Ptr ())
io = do
  Ptr ()
ptr <- IO (Ptr ())
io
  if Ptr ()
ptr Ptr () -> Ptr () -> Bool
forall a. Eq a => a -> a -> Bool
== Ptr ()
forall a. Ptr a
nullPtr
    then case Maybe c
m_ctx of
      Maybe c
Nothing  -> NULL_POINTER -> IO a
forall a e. Exception e => e -> a
throw NULL_POINTER
NULL_POINTER
      Just c
ctx -> do
        let session :: Session
session = c -> Session
forall a. SshCtx a => a -> Session
getSession c
ctx
        (Int
r, String
_) <- Session -> IO (Int, String)
getLastError Session
session
        case Int -> ErrorCode
forall i. Integral i => i -> ErrorCode
int2error Int
r of
          ErrorCode
EAGAIN -> Maybe Session -> IO ()
forall ctx. SshCtx ctx => Maybe ctx -> IO ()
threadWaitSession (Session -> Maybe Session
forall a. a -> Maybe a
Just Session
session) IO () -> IO a -> IO a
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Maybe c -> (Ptr () -> IO a) -> IO (Ptr ()) -> IO a
forall c a.
SshCtx c =>
Maybe c -> (Ptr () -> IO a) -> IO (Ptr ()) -> IO a
handleNullPtr Maybe c
m_ctx Ptr () -> IO a
fromPointer IO (Ptr ())
io
          ErrorCode
err    -> c -> ErrorCode -> IO a
forall a b. SshCtx a => a -> ErrorCode -> IO b
throwCtxSpecificError c
ctx ErrorCode
err
    else Ptr () -> IO a
fromPointer Ptr ()
ptr

-- | Get currently blocked directions
blockedDirections :: (Session) -> IO (([Direction]))
blockedDirections :: Session -> IO [Direction]
blockedDirections Session
a1 =
  let {a1' :: Ptr ()
a1' = Session -> Ptr ()
forall p. ToPointer p => p -> Ptr ()
toPointer Session
a1} in 
  Ptr () -> IO CInt
blockedDirections'_ Ptr ()
a1' IO CInt -> (CInt -> IO [Direction]) -> IO [Direction]
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \CInt
res ->
  let {res' :: [Direction]
res' = CInt -> [Direction]
forall a. (Eq a, Num a, Show a) => a -> [Direction]
int2dir CInt
res} in
  return (res')

{-# LINE 182 "src/Network/SSH/Client/LibSSH2/Errors.chs" #-}


threadWaitSession :: (SshCtx ctx) => Maybe ctx -> IO ()
threadWaitSession Nothing = error "EAGAIN thrown without session present"
threadWaitSession (Just ctx) = do
  let s = getSession ctx
  mSocket <- sessionGetSocket s
  case mSocket of
    Nothing -> error "EAGAIN thrown on session without socket"
    Just socket -> do
      dirs <- blockedDirections s
      if (OUTBOUND `elem` dirs)
        then threadWaitWrite socket
        else threadWaitRead socket

-- | Sftp

getLastSftpError_ :: (Sftp) -> IO ((Int))
getLastSftpError_ :: Sftp -> IO Int
getLastSftpError_ Sftp
a1 =
  let {a1' :: Ptr ()
a1' = Sftp -> Ptr ()
forall p. ToPointer p => p -> Ptr ()
toPointer Sftp
a1} in 
  Ptr () -> IO CULong
getLastSftpError_'_ Ptr ()
a1' IO CULong -> (CULong -> IO Int) -> IO Int
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \CULong
res ->
  let {res' :: Int
res' = CULong -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral CULong
res} in
  return (res')

{-# LINE 200 "src/Network/SSH/Client/LibSSH2/Errors.chs" #-}


-- | Get last sftp related error.
getLastSftpError :: Sftp -> IO Int
getLastSftpError sftp = getLastSftpError_ sftp

sftperror2int :: (Num i) => SftpErrorCode -> i
sftperror2int :: SftpErrorCode -> i
sftperror2int = Int -> i
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> i) -> (SftpErrorCode -> Int) -> SftpErrorCode -> i
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SftpErrorCode -> Int
forall a. Enum a => a -> Int
fromEnum

int2sftperror :: (Integral i) => i -> SftpErrorCode
int2sftperror :: i -> SftpErrorCode
int2sftperror = Int -> SftpErrorCode
forall a. Enum a => Int -> a
toEnum (Int -> SftpErrorCode) -> (i -> Int) -> i -> SftpErrorCode
forall b c a. (b -> c) -> (a -> b) -> a -> c
. i -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral

-- | Sftp error code returning from libssh2
data SftpErrorCode =
    FX_OK
  | FX_EOF
  | FX_NO_SUCH_FILE
  | FX_PERMISSION_DENIED
  | FX_FAILURE
  | FX_BAD_MESSAGE
  | FX_NO_CONNECTION
  | FX_CONNECTION_LOST
  | FX_OP_UNSUPPORTED
  | FX_INVALID_HANDLE
  | FX_NO_SUCH_PATH
  | FX_FILE_ALREADY_EXISTS
  | FX_WRITE_PROTECT
  | FX_NO_MEDIA
  | FX_NO_SPACE_ON_FILESYSTEM
  | FX_QUOTA_EXCEEDED
  | FX_UNKNOWN_PRINCIPAL
  | FX_LOCK_CONFLICT
  | FX_DIR_NOT_EMPTY
  | FX_NOT_A_DIRECTORY
  | FX_INVALID_FILENAME
  | FX_LINK_LOOP
  deriving (SftpErrorCode -> SftpErrorCode -> Bool
(SftpErrorCode -> SftpErrorCode -> Bool)
-> (SftpErrorCode -> SftpErrorCode -> Bool) -> Eq SftpErrorCode
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SftpErrorCode -> SftpErrorCode -> Bool
$c/= :: SftpErrorCode -> SftpErrorCode -> Bool
== :: SftpErrorCode -> SftpErrorCode -> Bool
$c== :: SftpErrorCode -> SftpErrorCode -> Bool
Eq, Int -> SftpErrorCode -> ShowS
[SftpErrorCode] -> ShowS
SftpErrorCode -> String
(Int -> SftpErrorCode -> ShowS)
-> (SftpErrorCode -> String)
-> ([SftpErrorCode] -> ShowS)
-> Show SftpErrorCode
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SftpErrorCode] -> ShowS
$cshowList :: [SftpErrorCode] -> ShowS
show :: SftpErrorCode -> String
$cshow :: SftpErrorCode -> String
showsPrec :: Int -> SftpErrorCode -> ShowS
$cshowsPrec :: Int -> SftpErrorCode -> ShowS
Show, Eq SftpErrorCode
Eq SftpErrorCode
-> (SftpErrorCode -> SftpErrorCode -> Ordering)
-> (SftpErrorCode -> SftpErrorCode -> Bool)
-> (SftpErrorCode -> SftpErrorCode -> Bool)
-> (SftpErrorCode -> SftpErrorCode -> Bool)
-> (SftpErrorCode -> SftpErrorCode -> Bool)
-> (SftpErrorCode -> SftpErrorCode -> SftpErrorCode)
-> (SftpErrorCode -> SftpErrorCode -> SftpErrorCode)
-> Ord SftpErrorCode
SftpErrorCode -> SftpErrorCode -> Bool
SftpErrorCode -> SftpErrorCode -> Ordering
SftpErrorCode -> SftpErrorCode -> SftpErrorCode
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: SftpErrorCode -> SftpErrorCode -> SftpErrorCode
$cmin :: SftpErrorCode -> SftpErrorCode -> SftpErrorCode
max :: SftpErrorCode -> SftpErrorCode -> SftpErrorCode
$cmax :: SftpErrorCode -> SftpErrorCode -> SftpErrorCode
>= :: SftpErrorCode -> SftpErrorCode -> Bool
$c>= :: SftpErrorCode -> SftpErrorCode -> Bool
> :: SftpErrorCode -> SftpErrorCode -> Bool
$c> :: SftpErrorCode -> SftpErrorCode -> Bool
<= :: SftpErrorCode -> SftpErrorCode -> Bool
$c<= :: SftpErrorCode -> SftpErrorCode -> Bool
< :: SftpErrorCode -> SftpErrorCode -> Bool
$c< :: SftpErrorCode -> SftpErrorCode -> Bool
compare :: SftpErrorCode -> SftpErrorCode -> Ordering
$ccompare :: SftpErrorCode -> SftpErrorCode -> Ordering
$cp1Ord :: Eq SftpErrorCode
Ord, Int -> SftpErrorCode
SftpErrorCode -> Int
SftpErrorCode -> [SftpErrorCode]
SftpErrorCode -> SftpErrorCode
SftpErrorCode -> SftpErrorCode -> [SftpErrorCode]
SftpErrorCode -> SftpErrorCode -> SftpErrorCode -> [SftpErrorCode]
(SftpErrorCode -> SftpErrorCode)
-> (SftpErrorCode -> SftpErrorCode)
-> (Int -> SftpErrorCode)
-> (SftpErrorCode -> Int)
-> (SftpErrorCode -> [SftpErrorCode])
-> (SftpErrorCode -> SftpErrorCode -> [SftpErrorCode])
-> (SftpErrorCode -> SftpErrorCode -> [SftpErrorCode])
-> (SftpErrorCode
    -> SftpErrorCode -> SftpErrorCode -> [SftpErrorCode])
-> Enum SftpErrorCode
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
enumFromThenTo :: SftpErrorCode -> SftpErrorCode -> SftpErrorCode -> [SftpErrorCode]
$cenumFromThenTo :: SftpErrorCode -> SftpErrorCode -> SftpErrorCode -> [SftpErrorCode]
enumFromTo :: SftpErrorCode -> SftpErrorCode -> [SftpErrorCode]
$cenumFromTo :: SftpErrorCode -> SftpErrorCode -> [SftpErrorCode]
enumFromThen :: SftpErrorCode -> SftpErrorCode -> [SftpErrorCode]
$cenumFromThen :: SftpErrorCode -> SftpErrorCode -> [SftpErrorCode]
enumFrom :: SftpErrorCode -> [SftpErrorCode]
$cenumFrom :: SftpErrorCode -> [SftpErrorCode]
fromEnum :: SftpErrorCode -> Int
$cfromEnum :: SftpErrorCode -> Int
toEnum :: Int -> SftpErrorCode
$ctoEnum :: Int -> SftpErrorCode
pred :: SftpErrorCode -> SftpErrorCode
$cpred :: SftpErrorCode -> SftpErrorCode
succ :: SftpErrorCode -> SftpErrorCode
$csucc :: SftpErrorCode -> SftpErrorCode
Enum, Typeable SftpErrorCode
DataType
Constr
Typeable SftpErrorCode
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> SftpErrorCode -> c SftpErrorCode)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c SftpErrorCode)
-> (SftpErrorCode -> Constr)
-> (SftpErrorCode -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c SftpErrorCode))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c SftpErrorCode))
-> ((forall b. Data b => b -> b) -> SftpErrorCode -> SftpErrorCode)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> SftpErrorCode -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> SftpErrorCode -> r)
-> (forall u. (forall d. Data d => d -> u) -> SftpErrorCode -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> SftpErrorCode -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> SftpErrorCode -> m SftpErrorCode)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> SftpErrorCode -> m SftpErrorCode)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> SftpErrorCode -> m SftpErrorCode)
-> Data SftpErrorCode
SftpErrorCode -> DataType
SftpErrorCode -> Constr
(forall b. Data b => b -> b) -> SftpErrorCode -> SftpErrorCode
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> SftpErrorCode -> c SftpErrorCode
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c SftpErrorCode
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> SftpErrorCode -> u
forall u. (forall d. Data d => d -> u) -> SftpErrorCode -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> SftpErrorCode -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> SftpErrorCode -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> SftpErrorCode -> m SftpErrorCode
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> SftpErrorCode -> m SftpErrorCode
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c SftpErrorCode
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> SftpErrorCode -> c SftpErrorCode
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c SftpErrorCode)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c SftpErrorCode)
$cFX_LINK_LOOP :: Constr
$cFX_INVALID_FILENAME :: Constr
$cFX_NOT_A_DIRECTORY :: Constr
$cFX_DIR_NOT_EMPTY :: Constr
$cFX_LOCK_CONFLICT :: Constr
$cFX_UNKNOWN_PRINCIPAL :: Constr
$cFX_QUOTA_EXCEEDED :: Constr
$cFX_NO_SPACE_ON_FILESYSTEM :: Constr
$cFX_NO_MEDIA :: Constr
$cFX_WRITE_PROTECT :: Constr
$cFX_FILE_ALREADY_EXISTS :: Constr
$cFX_NO_SUCH_PATH :: Constr
$cFX_INVALID_HANDLE :: Constr
$cFX_OP_UNSUPPORTED :: Constr
$cFX_CONNECTION_LOST :: Constr
$cFX_NO_CONNECTION :: Constr
$cFX_BAD_MESSAGE :: Constr
$cFX_FAILURE :: Constr
$cFX_PERMISSION_DENIED :: Constr
$cFX_NO_SUCH_FILE :: Constr
$cFX_EOF :: Constr
$cFX_OK :: Constr
$tSftpErrorCode :: DataType
gmapMo :: (forall d. Data d => d -> m d) -> SftpErrorCode -> m SftpErrorCode
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> SftpErrorCode -> m SftpErrorCode
gmapMp :: (forall d. Data d => d -> m d) -> SftpErrorCode -> m SftpErrorCode
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> SftpErrorCode -> m SftpErrorCode
gmapM :: (forall d. Data d => d -> m d) -> SftpErrorCode -> m SftpErrorCode
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> SftpErrorCode -> m SftpErrorCode
gmapQi :: Int -> (forall d. Data d => d -> u) -> SftpErrorCode -> u
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> SftpErrorCode -> u
gmapQ :: (forall d. Data d => d -> u) -> SftpErrorCode -> [u]
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> SftpErrorCode -> [u]
gmapQr :: (r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> SftpErrorCode -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> SftpErrorCode -> r
gmapQl :: (r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> SftpErrorCode -> r
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> SftpErrorCode -> r
gmapT :: (forall b. Data b => b -> b) -> SftpErrorCode -> SftpErrorCode
$cgmapT :: (forall b. Data b => b -> b) -> SftpErrorCode -> SftpErrorCode
dataCast2 :: (forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c SftpErrorCode)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c SftpErrorCode)
dataCast1 :: (forall d. Data d => c (t d)) -> Maybe (c SftpErrorCode)
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c SftpErrorCode)
dataTypeOf :: SftpErrorCode -> DataType
$cdataTypeOf :: SftpErrorCode -> DataType
toConstr :: SftpErrorCode -> Constr
$ctoConstr :: SftpErrorCode -> Constr
gunfold :: (forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c SftpErrorCode
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c SftpErrorCode
gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> SftpErrorCode -> c SftpErrorCode
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> SftpErrorCode -> c SftpErrorCode
$cp1Data :: Typeable SftpErrorCode
Data, Typeable)

instance Exception SftpErrorCode


class SshCtx a where
  getSession :: a -> Session
  throwCtxSpecificError :: a -> ErrorCode -> IO b

instance SshCtx Session where
  getSession :: Session -> Session
getSession = Session -> Session
forall a. a -> a
id
  throwCtxSpecificError :: Session -> ErrorCode -> IO b
throwCtxSpecificError Session
_ ErrorCode
er = ErrorCode -> IO b
forall a e. Exception e => e -> a
throw ErrorCode
er

instance SshCtx Sftp where
  getSession :: Sftp -> Session
getSession = Sftp -> Session
sftpSession

  throwCtxSpecificError :: Sftp -> ErrorCode -> IO b
throwCtxSpecificError Sftp
ctx ErrorCode
SFTP_PROTOCOL = do
    Int
er <- Sftp -> IO Int
getLastSftpError Sftp
ctx
    SftpErrorCode -> IO b
forall a e. Exception e => e -> a
throw (Int -> SftpErrorCode
forall i. Integral i => i -> SftpErrorCode
int2sftperror Int
er)
  throwCtxSpecificError Sftp
_ ErrorCode
er = ErrorCode -> IO b
forall a e. Exception e => e -> a
throw ErrorCode
er

instance SshCtx SftpHandle where
  getSession :: SftpHandle -> Session
getSession = Sftp -> Session
forall a. SshCtx a => a -> Session
getSession (Sftp -> Session) -> (SftpHandle -> Sftp) -> SftpHandle -> Session
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SftpHandle -> Sftp
sftpHandleSession

  throwCtxSpecificError :: SftpHandle -> ErrorCode -> IO b
throwCtxSpecificError SftpHandle
ctx =
    Sftp -> ErrorCode -> IO b
forall a b. SshCtx a => a -> ErrorCode -> IO b
throwCtxSpecificError (SftpHandle -> Sftp
sftpHandleSession SftpHandle
ctx)

instance SshCtx Agent where
  getSession :: Agent -> Session
getSession = Session -> Session
forall a. SshCtx a => a -> Session
getSession (Session -> Session) -> (Agent -> Session) -> Agent -> Session
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Agent -> Session
agentSession
  throwCtxSpecificError :: Agent -> ErrorCode -> IO b
throwCtxSpecificError Agent
_ ErrorCode
er = ErrorCode -> IO b
forall a e. Exception e => e -> a
throw ErrorCode
er
foreign import ccall safe "Network/SSH/Client/LibSSH2/Errors.chs.h libssh2_session_last_error"
  getLastError_'_ :: ((C2HSImp.Ptr ()) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> ((C2HSImp.Ptr C2HSImp.CInt) -> (C2HSImp.CInt -> (IO C2HSImp.CInt)))))

foreign import ccall safe "Network/SSH/Client/LibSSH2/Errors.chs.h libssh2_session_block_directions"
  blockedDirections'_ :: ((C2HSImp.Ptr ()) -> (IO C2HSImp.CInt))

foreign import ccall safe "Network/SSH/Client/LibSSH2/Errors.chs.h libssh2_sftp_last_error"
  getLastSftpError_'_ :: ((C2HSImp.Ptr ()) -> (IO C2HSImp.CULong))