module Gnome.Keyring.Find
( Found (..)
, findItems
) where
import Control.Exception (bracket)
import Data.Text.Lazy (Text)
import Foreign
import Foreign.C
import Gnome.Keyring.ItemInfo.Internal
import Gnome.Keyring.Attribute.Internal
import Gnome.Keyring.Operation.Internal
import Gnome.Keyring.FFI
import Gnome.Keyring.Types
data Found = Found
{ foundKeyring :: KeyringName
, foundItemID :: ItemID
, foundAttributes :: [Attribute]
, foundSecret :: Text
}
deriving (Show, Eq)
peekFound :: Ptr () -> IO Found
peekFound f = do
keyring <- peekText =<< (\ptr -> do {peekByteOff ptr 0 ::IO (Ptr CChar)}) f
cItemID <- (\ptr -> do {peekByteOff ptr 4 ::IO CUInt}) f
attrs <- peekAttributeList =<< (\ptr -> do {peekByteOff ptr 8 ::IO (Ptr ())}) f
secret <- peekText =<< (\ptr -> do {peekByteOff ptr 12 ::IO (Ptr CChar)}) f
return $ Found keyring (ItemID (fromIntegral cItemID)) attrs secret
stealFoundList :: Ptr (Ptr ()) -> IO [Found]
stealFoundList ptr = bracket (peek ptr)
gnome_keyring_found_list_free
(mapGList peekFound)
data GetFoundListCallback = GetFoundListCallback GetListCallbackPtr
instance Callback GetFoundListCallback [Found] where
callbackToPtr (GetFoundListCallback x) = castFunPtr x
freeCallback (GetFoundListCallback x) = freeHaskellFunPtr x
buildCallback = mkListCallback GetFoundListCallback
peekFound
findItems :: ItemType -> [Attribute] -> Operation [Found]
findItems t as = operation
(find_items t as)
(find_items_sync t as)
find_items :: ItemType -> [Attribute] -> GetFoundListCallback -> Ptr () -> DestroyNotifyPtr -> IO (CancellationKey)
find_items a1 a2 a3 a4 a5 =
let {a1' = fromItemType a1} in
withAttributeList a2 $ \a2' ->
let {a3' = callbackToPtr a3} in
let {a4' = id a4} in
let {a5' = id a5} in
find_items'_ a1' a2' a3' a4' a5' >>= \res ->
let {res' = CancellationKey res} in
return (res')
find_items_sync :: ItemType -> [Attribute] -> IO (Result, [Found])
find_items_sync a1 a2 =
let {a1' = fromItemType a1} in
withAttributeList a2 $ \a2' ->
alloca $ \a3' ->
find_items_sync'_ a1' a2' a3' >>= \res ->
stealFoundList a3'>>= \a3'' ->
let {res' = result res} in
return (res', a3'')
foreign import ccall unsafe "Gnome/Keyring/Find.chs.h gnome_keyring_found_list_free"
gnome_keyring_found_list_free :: ((Ptr ()) -> (IO ()))
foreign import ccall safe "Gnome/Keyring/Find.chs.h gnome_keyring_find_items"
find_items'_ :: (CInt -> ((Ptr ()) -> ((FunPtr (CInt -> ((Ptr ()) -> ((Ptr ()) -> (IO ()))))) -> ((Ptr ()) -> ((FunPtr ((Ptr ()) -> (IO ()))) -> (IO (Ptr ())))))))
foreign import ccall unsafe "Gnome/Keyring/Find.chs.h gnome_keyring_find_items_sync"
find_items_sync'_ :: (CInt -> ((Ptr ()) -> ((Ptr (Ptr ())) -> (IO CInt))))