module Network.SSH.Client.LibSSH2.Types
(Session,
KnownHosts,
Channel,
IsPointer (..),
CStringCLen,
Size, SSize,
withCStringLenIntConv,
peekCStringPtr,
peekMaybeCStringPtr
) where
import Foreign
import Foreign.Ptr
import Foreign.C.Types
import Foreign.C.String
import Data.Generics
type Size = (CUInt)
type SSize = (CInt)
type CStringCLen i = (CString, i)
withCStringLenIntConv :: (Integral i) => String -> (CStringCLen i -> IO a) -> IO a
withCStringLenIntConv str fn =
withCStringLen str (\(ptr, len) -> fn (ptr, fromIntegral len))
peekCStringPtr :: Ptr CString -> IO String
peekCStringPtr ptr = peekCAString =<< peek ptr
peekMaybeCStringPtr :: Ptr CString -> IO (Maybe String)
peekMaybeCStringPtr ptr = do
strPtr <- peek ptr
if strPtr == nullPtr
then return Nothing
else Just `fmap` peekCAString strPtr
class IsPointer p where
fromPointer :: Ptr () -> p
toPointer :: p -> Ptr ()
newtype Session = Session (Ptr (Session))
deriving instance Eq Session
deriving instance Data Session
deriving instance Typeable Session
instance Show Session where
show (Session p) = "<libssh2 session: " ++ show p ++ ">"
instance IsPointer Session where
fromPointer p = Session (castPtr p)
toPointer (Session p) = castPtr p
newtype KnownHosts = KnownHosts (Ptr (KnownHosts))
deriving instance Eq KnownHosts
deriving instance Data KnownHosts
deriving instance Typeable KnownHosts
instance Show KnownHosts where
show (KnownHosts p) = "<libssh2 known hosts: " ++ show p ++ ">"
instance IsPointer KnownHosts where
fromPointer p = KnownHosts (castPtr p)
toPointer (KnownHosts p) = castPtr p
newtype Channel = Channel (Ptr (Channel))
deriving instance Eq Channel
deriving instance Data Channel
deriving instance Typeable Channel
instance Show Channel where
show (Channel p) = "<libssh2 channel: " ++ show p ++ ">"
instance IsPointer Channel where
fromPointer p = Channel (castPtr p)
toPointer (Channel p) = castPtr p