module Gnome.Keyring.KeyringInfo.Internal where
import Foreign
import Foreign.C
import Gnome.Keyring.FFI
import Gnome.Keyring.Types
data KeyringInfo = KeyringInfo
{ keyringLockOnIdle :: Bool
, keyringLockTimeout :: Word32
, keyringMTime :: Integer
, keyringCTime :: Integer
, keyringIsLocked :: Bool
, keyringInfoPtr :: ForeignPtr ()
}
keyringSetLockOnIdle :: KeyringInfo -> Bool -> KeyringInfo
keyringSetLockOnIdle info x = info {keyringLockOnIdle = x}
keyringSetLockTimeout :: KeyringInfo -> Word32 -> KeyringInfo
keyringSetLockTimeout info x = info {keyringLockTimeout = x}
data GetKeyringInfoCallback = GetKeyringInfoCallback GetKeyringInfoCallbackPtr
instance Callback GetKeyringInfoCallback KeyringInfo where
callbackToPtr (GetKeyringInfoCallback x) = castFunPtr x
freeCallback (GetKeyringInfoCallback x) = freeHaskellFunPtr x
buildCallback onSuccess onError = do
funptr <- wrapGetKeyringInfoCallback $ \cres ptr _ -> do
case result cres of
RESULT_OK -> peekKeyringInfo ptr >>= onSuccess
x -> onError $ resultToError x
return $ GetKeyringInfoCallback funptr
type RawGetKeyringInfoCallback = CInt -> Ptr () -> Ptr () -> IO ()
type GetKeyringInfoCallbackPtr = FunPtr ((CInt -> ((Ptr ()) -> ((Ptr ()) -> (IO ())))))
foreign import ccall "wrapper"
wrapGetKeyringInfoCallback :: RawGetKeyringInfoCallback
-> IO GetKeyringInfoCallbackPtr
copyInfo :: Ptr () -> IO (ForeignPtr ())
copyInfo = (newForeignPtr finalizeKeyringInfo =<<) . c_copy
peekKeyringInfo :: Ptr () -> IO KeyringInfo
peekKeyringInfo ptr = do
lockOnIdle <- toBool `fmap` gnome_keyring_info_get_lock_on_idle ptr
timeout <- fromIntegral `fmap` gnome_keyring_info_get_lock_timeout ptr
mtime <- toInteger `fmap` gnome_keyring_info_get_mtime ptr
ctime <- toInteger `fmap` gnome_keyring_info_get_ctime ptr
isLocked <- toBool `fmap` gnome_keyring_info_get_is_locked ptr
copy <- copyInfo ptr
return $ KeyringInfo lockOnIdle timeout mtime ctime isLocked copy
stealKeyringInfoPtr :: Ptr (Ptr ()) -> IO KeyringInfo
stealKeyringInfoPtr ptr = do
infoPtr <- newForeignPtr finalizeKeyringInfo =<< peek ptr
withForeignPtr infoPtr peekKeyringInfo
withKeyringInfo :: KeyringInfo -> (Ptr () -> IO a) -> IO a
withKeyringInfo info io = do
copy <- withForeignPtr (keyringInfoPtr info) copyInfo
withForeignPtr copy $ \ptr -> do
gnome_keyring_info_set_lock_on_idle ptr . fromBool . keyringLockOnIdle $ info
gnome_keyring_info_set_lock_timeout ptr . fromIntegral . keyringLockTimeout $ info
io ptr
foreign import ccall "gnome-keyring.h &gnome_keyring_info_free"
finalizeKeyringInfo :: FunPtr (Ptr a -> IO ())
foreign import ccall unsafe "Gnome/Keyring/KeyringInfo/Internal.chs.h gnome_keyring_info_copy"
c_copy :: ((Ptr ()) -> (IO (Ptr ())))
foreign import ccall unsafe "Gnome/Keyring/KeyringInfo/Internal.chs.h gnome_keyring_info_get_lock_on_idle"
gnome_keyring_info_get_lock_on_idle :: ((Ptr ()) -> (IO CInt))
foreign import ccall unsafe "Gnome/Keyring/KeyringInfo/Internal.chs.h gnome_keyring_info_get_lock_timeout"
gnome_keyring_info_get_lock_timeout :: ((Ptr ()) -> (IO CUInt))
foreign import ccall unsafe "Gnome/Keyring/KeyringInfo/Internal.chs.h gnome_keyring_info_get_mtime"
gnome_keyring_info_get_mtime :: ((Ptr ()) -> (IO CLong))
foreign import ccall unsafe "Gnome/Keyring/KeyringInfo/Internal.chs.h gnome_keyring_info_get_ctime"
gnome_keyring_info_get_ctime :: ((Ptr ()) -> (IO CLong))
foreign import ccall unsafe "Gnome/Keyring/KeyringInfo/Internal.chs.h gnome_keyring_info_get_is_locked"
gnome_keyring_info_get_is_locked :: ((Ptr ()) -> (IO CInt))
foreign import ccall unsafe "Gnome/Keyring/KeyringInfo/Internal.chs.h gnome_keyring_info_set_lock_on_idle"
gnome_keyring_info_set_lock_on_idle :: ((Ptr ()) -> (CInt -> (IO ())))
foreign import ccall unsafe "Gnome/Keyring/KeyringInfo/Internal.chs.h gnome_keyring_info_set_lock_timeout"
gnome_keyring_info_set_lock_timeout :: ((Ptr ()) -> (CUInt -> (IO ())))