-- | Copyright  : Will Thompson, Iñaki García Etxebarria and Jonas Platte
-- License    : LGPL-2.1
-- Maintainer : Iñaki García Etxebarria

#if (MIN_VERSION_haskell_gi_overloading(1,0,0) && !defined(__HADDOCK_VERSION__))
#define ENABLE_OVERLOADING
#endif

module GI.Secret.Functions
    ( 

 -- * Methods
-- ** errorGetQuark #method:errorGetQuark#

    errorGetQuark                           ,


-- ** getSchema #method:getSchema#

    getSchema                               ,


-- ** passwordClear #method:passwordClear#

    passwordClear                           ,


-- ** passwordClearFinish #method:passwordClearFinish#

    passwordClearFinish                     ,


-- ** passwordClearSync #method:passwordClearSync#

    passwordClearSync                       ,


-- ** passwordLookup #method:passwordLookup#

    passwordLookup                          ,


-- ** passwordLookupFinish #method:passwordLookupFinish#

    passwordLookupFinish                    ,


-- ** passwordLookupSync #method:passwordLookupSync#

    passwordLookupSync                      ,


-- ** passwordStore #method:passwordStore#

    passwordStore                           ,


-- ** passwordStoreFinish #method:passwordStoreFinish#

    passwordStoreFinish                     ,


-- ** passwordStoreSync #method:passwordStoreSync#

    passwordStoreSync                       ,


-- ** passwordWipe #method:passwordWipe#

    passwordWipe                            ,




    ) where

import Data.GI.Base.ShortPrelude
import qualified Data.GI.Base.ShortPrelude as SP
import qualified Data.GI.Base.Overloading as O
import qualified Prelude as P

import qualified Data.GI.Base.Attributes as GI.Attributes
import qualified Data.GI.Base.ManagedPtr as B.ManagedPtr
import qualified Data.GI.Base.GClosure as B.GClosure
import qualified Data.GI.Base.GError as B.GError
import qualified Data.GI.Base.GVariant as B.GVariant
import qualified Data.GI.Base.GValue as B.GValue
import qualified Data.GI.Base.GParamSpec as B.GParamSpec
import qualified Data.GI.Base.CallStack as B.CallStack
import qualified Data.GI.Base.Properties as B.Properties
import qualified Data.GI.Base.Signals as B.Signals
import qualified Data.Text as T
import qualified Data.ByteString.Char8 as B
import qualified Data.Map as Map
import qualified Foreign.Ptr as FP
import qualified GHC.OverloadedLabels as OL

import qualified GI.Gio.Callbacks as Gio.Callbacks
import qualified GI.Gio.Interfaces.AsyncResult as Gio.AsyncResult
import qualified GI.Gio.Objects.Cancellable as Gio.Cancellable
import {-# SOURCE #-} qualified GI.Secret.Enums as Secret.Enums
import {-# SOURCE #-} qualified GI.Secret.Structs.Schema as Secret.Schema

-- function secret_password_wipe
-- Args: [ Arg
--           { argCName = "password"
--           , argType = TBasicType TUTF8
--           , direction = DirectionIn
--           , mayBeNull = True
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "password to clear" , sinceVersion = Nothing }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       ]
-- Lengths: []
-- returnType: Nothing
-- throws : False
-- Skip return : False

foreign import ccall "secret_password_wipe" secret_password_wipe :: 
    CString ->                              -- password : TBasicType TUTF8
    IO ()

-- | Clear the memory used by a password.
passwordWipe ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    Maybe (T.Text)
    -- ^ /@password@/: password to clear
    -> m ()
passwordWipe :: Maybe Text -> m ()
passwordWipe password :: Maybe Text
password = IO () -> m ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$ do
    Ptr CChar
maybePassword <- case Maybe Text
password of
        Nothing -> Ptr CChar -> IO (Ptr CChar)
forall (m :: * -> *) a. Monad m => a -> m a
return Ptr CChar
forall a. Ptr a
nullPtr
        Just jPassword :: Text
jPassword -> do
            Ptr CChar
jPassword' <- Text -> IO (Ptr CChar)
textToCString Text
jPassword
            Ptr CChar -> IO (Ptr CChar)
forall (m :: * -> *) a. Monad m => a -> m a
return Ptr CChar
jPassword'
    Ptr CChar -> IO ()
secret_password_wipe Ptr CChar
maybePassword
    Ptr CChar -> IO ()
forall a. Ptr a -> IO ()
freeMem Ptr CChar
maybePassword
    () -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()


-- function secret_password_storev_sync
-- Args: [ Arg
--           { argCName = "schema"
--           , argType =
--               TInterface Name { namespace = "Secret" , name = "Schema" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "the schema for attributes"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "attributes"
--           , argType = TGHash (TBasicType TUTF8) (TBasicType TUTF8)
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "the attribute keys and values"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "collection"
--           , argType = TBasicType TUTF8
--           , direction = DirectionIn
--           , mayBeNull = True
--           , argDoc =
--               Documentation
--                 { rawDocText =
--                     Just
--                       "a collection alias, or D-Bus object path of the collection where to store the secret"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "label"
--           , argType = TBasicType TUTF8
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "label for the secret"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "password"
--           , argType = TBasicType TUTF8
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "the null-terminated password to store"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "cancellable"
--           , argType =
--               TInterface Name { namespace = "Gio" , name = "Cancellable" }
--           , direction = DirectionIn
--           , mayBeNull = True
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "optional cancellation object"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       ]
-- Lengths: []
-- returnType: Just (TBasicType TBoolean)
-- throws : True
-- Skip return : False

foreign import ccall "secret_password_storev_sync" secret_password_storev_sync :: 
    Ptr Secret.Schema.Schema ->             -- schema : TInterface (Name {namespace = "Secret", name = "Schema"})
    Ptr (GHashTable CString CString) ->     -- attributes : TGHash (TBasicType TUTF8) (TBasicType TUTF8)
    CString ->                              -- collection : TBasicType TUTF8
    CString ->                              -- label : TBasicType TUTF8
    CString ->                              -- password : TBasicType TUTF8
    Ptr Gio.Cancellable.Cancellable ->      -- cancellable : TInterface (Name {namespace = "Gio", name = "Cancellable"})
    Ptr (Ptr GError) ->                     -- error
    IO CInt

-- | Store a password in the secret service.
-- 
-- The /@attributes@/ should be a set of key and value string pairs.
-- 
-- If the attributes match a secret item already stored in the collection, then
-- the item will be updated with these new values.
-- 
-- If /@collection@/ is 'P.Nothing', then the default collection will be
-- used. Use 'GI.Secret.Constants.COLLECTION_SESSION' to store the password in the session
-- collection, which doesn\'t get stored across login sessions.
-- 
-- This method may block indefinitely and should not be used in user interface
-- threads.
passwordStoreSync ::
    (B.CallStack.HasCallStack, MonadIO m, Gio.Cancellable.IsCancellable a) =>
    Secret.Schema.Schema
    -- ^ /@schema@/: the schema for attributes
    -> Map.Map T.Text T.Text
    -- ^ /@attributes@/: the attribute keys and values
    -> Maybe (T.Text)
    -- ^ /@collection@/: a collection alias, or D-Bus object path of the collection where to store the secret
    -> T.Text
    -- ^ /@label@/: label for the secret
    -> T.Text
    -- ^ /@password@/: the null-terminated password to store
    -> Maybe (a)
    -- ^ /@cancellable@/: optional cancellation object
    -> m ()
    -- ^ /(Can throw 'Data.GI.Base.GError.GError')/
passwordStoreSync :: Schema
-> Map Text Text -> Maybe Text -> Text -> Text -> Maybe a -> m ()
passwordStoreSync schema :: Schema
schema attributes :: Map Text Text
attributes collection :: Maybe Text
collection label :: Text
label password :: Text
password cancellable :: Maybe a
cancellable = IO () -> m ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$ do
    Ptr Schema
schema' <- Schema -> IO (Ptr Schema)
forall a. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr a)
unsafeManagedPtrGetPtr Schema
schema
    let attributes' :: [(Text, Text)]
attributes' = Map Text Text -> [(Text, Text)]
forall k a. Map k a -> [(k, a)]
Map.toList Map Text Text
attributes
    [(Ptr CChar, Text)]
attributes'' <- (Text -> IO (Ptr CChar))
-> [(Text, Text)] -> IO [(Ptr CChar, Text)]
forall (f :: * -> *) a c b.
Applicative f =>
(a -> f c) -> [(a, b)] -> f [(c, b)]
mapFirstA Text -> IO (Ptr CChar)
textToCString [(Text, Text)]
attributes'
    [(Ptr CChar, Ptr CChar)]
attributes''' <- (Text -> IO (Ptr CChar))
-> [(Ptr CChar, Text)] -> IO [(Ptr CChar, Ptr CChar)]
forall (f :: * -> *) b c a.
Applicative f =>
(b -> f c) -> [(a, b)] -> f [(a, c)]
mapSecondA Text -> IO (Ptr CChar)
textToCString [(Ptr CChar, Text)]
attributes''
    let attributes'''' :: [(PtrWrapped (Ptr CChar), Ptr CChar)]
attributes'''' = (Ptr CChar -> PtrWrapped (Ptr CChar))
-> [(Ptr CChar, Ptr CChar)]
-> [(PtrWrapped (Ptr CChar), Ptr CChar)]
forall a c b. (a -> c) -> [(a, b)] -> [(c, b)]
mapFirst Ptr CChar -> PtrWrapped (Ptr CChar)
cstringPackPtr [(Ptr CChar, Ptr CChar)]
attributes'''
    let attributes''''' :: [(PtrWrapped (Ptr CChar), PtrWrapped (Ptr CChar))]
attributes''''' = (Ptr CChar -> PtrWrapped (Ptr CChar))
-> [(PtrWrapped (Ptr CChar), Ptr CChar)]
-> [(PtrWrapped (Ptr CChar), PtrWrapped (Ptr CChar))]
forall b c a. (b -> c) -> [(a, b)] -> [(a, c)]
mapSecond Ptr CChar -> PtrWrapped (Ptr CChar)
cstringPackPtr [(PtrWrapped (Ptr CChar), Ptr CChar)]
attributes''''
    Ptr (GHashTable (Ptr CChar) (Ptr CChar))
attributes'''''' <- GHashFunc (Ptr CChar)
-> GEqualFunc (Ptr CChar)
-> Maybe (GDestroyNotify (Ptr CChar))
-> Maybe (GDestroyNotify (Ptr CChar))
-> [(PtrWrapped (Ptr CChar), PtrWrapped (Ptr CChar))]
-> IO (Ptr (GHashTable (Ptr CChar) (Ptr CChar)))
forall a b.
GHashFunc a
-> GEqualFunc a
-> Maybe (GDestroyNotify a)
-> Maybe (GDestroyNotify b)
-> [(PtrWrapped a, PtrWrapped b)]
-> IO (Ptr (GHashTable a b))
packGHashTable GHashFunc (Ptr CChar)
gStrHash GEqualFunc (Ptr CChar)
gStrEqual (GDestroyNotify (Ptr CChar) -> Maybe (GDestroyNotify (Ptr CChar))
forall a. a -> Maybe a
Just GDestroyNotify (Ptr CChar)
forall a. FunPtr (Ptr a -> IO ())
ptr_to_g_free) (GDestroyNotify (Ptr CChar) -> Maybe (GDestroyNotify (Ptr CChar))
forall a. a -> Maybe a
Just GDestroyNotify (Ptr CChar)
forall a. FunPtr (Ptr a -> IO ())
ptr_to_g_free) [(PtrWrapped (Ptr CChar), PtrWrapped (Ptr CChar))]
attributes'''''
    Ptr CChar
maybeCollection <- case Maybe Text
collection of
        Nothing -> Ptr CChar -> IO (Ptr CChar)
forall (m :: * -> *) a. Monad m => a -> m a
return Ptr CChar
forall a. Ptr a
nullPtr
        Just jCollection :: Text
jCollection -> do
            Ptr CChar
jCollection' <- Text -> IO (Ptr CChar)
textToCString Text
jCollection
            Ptr CChar -> IO (Ptr CChar)
forall (m :: * -> *) a. Monad m => a -> m a
return Ptr CChar
jCollection'
    Ptr CChar
label' <- Text -> IO (Ptr CChar)
textToCString Text
label
    Ptr CChar
password' <- Text -> IO (Ptr CChar)
textToCString Text
password
    Ptr Cancellable
maybeCancellable <- case Maybe a
cancellable of
        Nothing -> Ptr Cancellable -> IO (Ptr Cancellable)
forall (m :: * -> *) a. Monad m => a -> m a
return Ptr Cancellable
forall a. Ptr a
nullPtr
        Just jCancellable :: a
jCancellable -> do
            Ptr Cancellable
jCancellable' <- a -> IO (Ptr Cancellable)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr a
jCancellable
            Ptr Cancellable -> IO (Ptr Cancellable)
forall (m :: * -> *) a. Monad m => a -> m a
return Ptr Cancellable
jCancellable'
    IO () -> IO () -> IO ()
forall a b. IO a -> IO b -> IO a
onException (do
        CInt
_ <- (Ptr (Ptr GError) -> IO CInt) -> IO CInt
forall a. (Ptr (Ptr GError) -> IO a) -> IO a
propagateGError ((Ptr (Ptr GError) -> IO CInt) -> IO CInt)
-> (Ptr (Ptr GError) -> IO CInt) -> IO CInt
forall a b. (a -> b) -> a -> b
$ Ptr Schema
-> Ptr (GHashTable (Ptr CChar) (Ptr CChar))
-> Ptr CChar
-> Ptr CChar
-> Ptr CChar
-> Ptr Cancellable
-> Ptr (Ptr GError)
-> IO CInt
secret_password_storev_sync Ptr Schema
schema' Ptr (GHashTable (Ptr CChar) (Ptr CChar))
attributes'''''' Ptr CChar
maybeCollection Ptr CChar
label' Ptr CChar
password' Ptr Cancellable
maybeCancellable
        Schema -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr Schema
schema
        Maybe a -> (a -> IO ()) -> IO ()
forall (m :: * -> *) a. Monad m => Maybe a -> (a -> m ()) -> m ()
whenJust Maybe a
cancellable a -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr
        Ptr (GHashTable (Ptr CChar) (Ptr CChar)) -> IO ()
forall a b. Ptr (GHashTable a b) -> IO ()
unrefGHashTable Ptr (GHashTable (Ptr CChar) (Ptr CChar))
attributes''''''
        Ptr CChar -> IO ()
forall a. Ptr a -> IO ()
freeMem Ptr CChar
maybeCollection
        Ptr CChar -> IO ()
forall a. Ptr a -> IO ()
freeMem Ptr CChar
label'
        Ptr CChar -> IO ()
forall a. Ptr a -> IO ()
freeMem Ptr CChar
password'
        () -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
     ) (do
        Ptr (GHashTable (Ptr CChar) (Ptr CChar)) -> IO ()
forall a b. Ptr (GHashTable a b) -> IO ()
unrefGHashTable Ptr (GHashTable (Ptr CChar) (Ptr CChar))
attributes''''''
        Ptr CChar -> IO ()
forall a. Ptr a -> IO ()
freeMem Ptr CChar
maybeCollection
        Ptr CChar -> IO ()
forall a. Ptr a -> IO ()
freeMem Ptr CChar
label'
        Ptr CChar -> IO ()
forall a. Ptr a -> IO ()
freeMem Ptr CChar
password'
     )


-- function secret_password_store_finish
-- Args: [ Arg
--           { argCName = "result"
--           , argType =
--               TInterface Name { namespace = "Gio" , name = "AsyncResult" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText =
--                     Just "the asynchronous result passed to the callback"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       ]
-- Lengths: []
-- returnType: Just (TBasicType TBoolean)
-- throws : True
-- Skip return : False

foreign import ccall "secret_password_store_finish" secret_password_store_finish :: 
    Ptr Gio.AsyncResult.AsyncResult ->      -- result : TInterface (Name {namespace = "Gio", name = "AsyncResult"})
    Ptr (Ptr GError) ->                     -- error
    IO CInt

-- | Finish asynchronous operation to store a password in the secret service.
passwordStoreFinish ::
    (B.CallStack.HasCallStack, MonadIO m, Gio.AsyncResult.IsAsyncResult a) =>
    a
    -- ^ /@result@/: the asynchronous result passed to the callback
    -> m ()
    -- ^ /(Can throw 'Data.GI.Base.GError.GError')/
passwordStoreFinish :: a -> m ()
passwordStoreFinish result_ :: a
result_ = IO () -> m ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$ do
    Ptr AsyncResult
result_' <- a -> IO (Ptr AsyncResult)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr a
result_
    IO () -> IO () -> IO ()
forall a b. IO a -> IO b -> IO a
onException (do
        CInt
_ <- (Ptr (Ptr GError) -> IO CInt) -> IO CInt
forall a. (Ptr (Ptr GError) -> IO a) -> IO a
propagateGError ((Ptr (Ptr GError) -> IO CInt) -> IO CInt)
-> (Ptr (Ptr GError) -> IO CInt) -> IO CInt
forall a b. (a -> b) -> a -> b
$ Ptr AsyncResult -> Ptr (Ptr GError) -> IO CInt
secret_password_store_finish Ptr AsyncResult
result_'
        a -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr a
result_
        () -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
     ) (do
        () -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
     )


-- function secret_password_storev
-- Args: [ Arg
--           { argCName = "schema"
--           , argType =
--               TInterface Name { namespace = "Secret" , name = "Schema" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "the schema for attributes"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "attributes"
--           , argType = TGHash (TBasicType TUTF8) (TBasicType TUTF8)
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "the attribute keys and values"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "collection"
--           , argType = TBasicType TUTF8
--           , direction = DirectionIn
--           , mayBeNull = True
--           , argDoc =
--               Documentation
--                 { rawDocText =
--                     Just
--                       "a collection alias, or D-Bus object path of the collection where to store the secret"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "label"
--           , argType = TBasicType TUTF8
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "label for the secret"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "password"
--           , argType = TBasicType TUTF8
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "the null-terminated password to store"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "cancellable"
--           , argType =
--               TInterface Name { namespace = "Gio" , name = "Cancellable" }
--           , direction = DirectionIn
--           , mayBeNull = True
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "optional cancellation object"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "callback"
--           , argType =
--               TInterface Name { namespace = "Gio" , name = "AsyncReadyCallback" }
--           , direction = DirectionIn
--           , mayBeNull = True
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "called when the operation completes"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeAsync
--           , argClosure = 7
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "user_data"
--           , argType = TBasicType TPtr
--           , direction = DirectionIn
--           , mayBeNull = True
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "data to be passed to the callback"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       ]
-- Lengths: []
-- returnType: Nothing
-- throws : False
-- Skip return : False

foreign import ccall "secret_password_storev" secret_password_storev :: 
    Ptr Secret.Schema.Schema ->             -- schema : TInterface (Name {namespace = "Secret", name = "Schema"})
    Ptr (GHashTable CString CString) ->     -- attributes : TGHash (TBasicType TUTF8) (TBasicType TUTF8)
    CString ->                              -- collection : TBasicType TUTF8
    CString ->                              -- label : TBasicType TUTF8
    CString ->                              -- password : TBasicType TUTF8
    Ptr Gio.Cancellable.Cancellable ->      -- cancellable : TInterface (Name {namespace = "Gio", name = "Cancellable"})
    FunPtr Gio.Callbacks.C_AsyncReadyCallback -> -- callback : TInterface (Name {namespace = "Gio", name = "AsyncReadyCallback"})
    Ptr () ->                               -- user_data : TBasicType TPtr
    IO ()

-- | Store a password in the secret service.
-- 
-- The /@attributes@/ should be a set of key and value string pairs.
-- 
-- If the attributes match a secret item already stored in the collection, then
-- the item will be updated with these new values.
-- 
-- If /@collection@/ is 'P.Nothing', then the default collection will be
-- used. Use 'GI.Secret.Constants.COLLECTION_SESSION' to store the password in the session
-- collection, which doesn\'t get stored across login sessions.
-- 
-- This method will return immediately and complete asynchronously.
passwordStore ::
    (B.CallStack.HasCallStack, MonadIO m, Gio.Cancellable.IsCancellable a) =>
    Secret.Schema.Schema
    -- ^ /@schema@/: the schema for attributes
    -> Map.Map T.Text T.Text
    -- ^ /@attributes@/: the attribute keys and values
    -> Maybe (T.Text)
    -- ^ /@collection@/: a collection alias, or D-Bus object path of the collection where to store the secret
    -> T.Text
    -- ^ /@label@/: label for the secret
    -> T.Text
    -- ^ /@password@/: the null-terminated password to store
    -> Maybe (a)
    -- ^ /@cancellable@/: optional cancellation object
    -> Maybe (Gio.Callbacks.AsyncReadyCallback)
    -- ^ /@callback@/: called when the operation completes
    -> m ()
passwordStore :: Schema
-> Map Text Text
-> Maybe Text
-> Text
-> Text
-> Maybe a
-> Maybe AsyncReadyCallback
-> m ()
passwordStore schema :: Schema
schema attributes :: Map Text Text
attributes collection :: Maybe Text
collection label :: Text
label password :: Text
password cancellable :: Maybe a
cancellable callback :: Maybe AsyncReadyCallback
callback = IO () -> m ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$ do
    Ptr Schema
schema' <- Schema -> IO (Ptr Schema)
forall a. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr a)
unsafeManagedPtrGetPtr Schema
schema
    let attributes' :: [(Text, Text)]
attributes' = Map Text Text -> [(Text, Text)]
forall k a. Map k a -> [(k, a)]
Map.toList Map Text Text
attributes
    [(Ptr CChar, Text)]
attributes'' <- (Text -> IO (Ptr CChar))
-> [(Text, Text)] -> IO [(Ptr CChar, Text)]
forall (f :: * -> *) a c b.
Applicative f =>
(a -> f c) -> [(a, b)] -> f [(c, b)]
mapFirstA Text -> IO (Ptr CChar)
textToCString [(Text, Text)]
attributes'
    [(Ptr CChar, Ptr CChar)]
attributes''' <- (Text -> IO (Ptr CChar))
-> [(Ptr CChar, Text)] -> IO [(Ptr CChar, Ptr CChar)]
forall (f :: * -> *) b c a.
Applicative f =>
(b -> f c) -> [(a, b)] -> f [(a, c)]
mapSecondA Text -> IO (Ptr CChar)
textToCString [(Ptr CChar, Text)]
attributes''
    let attributes'''' :: [(PtrWrapped (Ptr CChar), Ptr CChar)]
attributes'''' = (Ptr CChar -> PtrWrapped (Ptr CChar))
-> [(Ptr CChar, Ptr CChar)]
-> [(PtrWrapped (Ptr CChar), Ptr CChar)]
forall a c b. (a -> c) -> [(a, b)] -> [(c, b)]
mapFirst Ptr CChar -> PtrWrapped (Ptr CChar)
cstringPackPtr [(Ptr CChar, Ptr CChar)]
attributes'''
    let attributes''''' :: [(PtrWrapped (Ptr CChar), PtrWrapped (Ptr CChar))]
attributes''''' = (Ptr CChar -> PtrWrapped (Ptr CChar))
-> [(PtrWrapped (Ptr CChar), Ptr CChar)]
-> [(PtrWrapped (Ptr CChar), PtrWrapped (Ptr CChar))]
forall b c a. (b -> c) -> [(a, b)] -> [(a, c)]
mapSecond Ptr CChar -> PtrWrapped (Ptr CChar)
cstringPackPtr [(PtrWrapped (Ptr CChar), Ptr CChar)]
attributes''''
    Ptr (GHashTable (Ptr CChar) (Ptr CChar))
attributes'''''' <- GHashFunc (Ptr CChar)
-> GEqualFunc (Ptr CChar)
-> Maybe (GDestroyNotify (Ptr CChar))
-> Maybe (GDestroyNotify (Ptr CChar))
-> [(PtrWrapped (Ptr CChar), PtrWrapped (Ptr CChar))]
-> IO (Ptr (GHashTable (Ptr CChar) (Ptr CChar)))
forall a b.
GHashFunc a
-> GEqualFunc a
-> Maybe (GDestroyNotify a)
-> Maybe (GDestroyNotify b)
-> [(PtrWrapped a, PtrWrapped b)]
-> IO (Ptr (GHashTable a b))
packGHashTable GHashFunc (Ptr CChar)
gStrHash GEqualFunc (Ptr CChar)
gStrEqual (GDestroyNotify (Ptr CChar) -> Maybe (GDestroyNotify (Ptr CChar))
forall a. a -> Maybe a
Just GDestroyNotify (Ptr CChar)
forall a. FunPtr (Ptr a -> IO ())
ptr_to_g_free) (GDestroyNotify (Ptr CChar) -> Maybe (GDestroyNotify (Ptr CChar))
forall a. a -> Maybe a
Just GDestroyNotify (Ptr CChar)
forall a. FunPtr (Ptr a -> IO ())
ptr_to_g_free) [(PtrWrapped (Ptr CChar), PtrWrapped (Ptr CChar))]
attributes'''''
    Ptr CChar
maybeCollection <- case Maybe Text
collection of
        Nothing -> Ptr CChar -> IO (Ptr CChar)
forall (m :: * -> *) a. Monad m => a -> m a
return Ptr CChar
forall a. Ptr a
nullPtr
        Just jCollection :: Text
jCollection -> do
            Ptr CChar
jCollection' <- Text -> IO (Ptr CChar)
textToCString Text
jCollection
            Ptr CChar -> IO (Ptr CChar)
forall (m :: * -> *) a. Monad m => a -> m a
return Ptr CChar
jCollection'
    Ptr CChar
label' <- Text -> IO (Ptr CChar)
textToCString Text
label
    Ptr CChar
password' <- Text -> IO (Ptr CChar)
textToCString Text
password
    Ptr Cancellable
maybeCancellable <- case Maybe a
cancellable of
        Nothing -> Ptr Cancellable -> IO (Ptr Cancellable)
forall (m :: * -> *) a. Monad m => a -> m a
return Ptr Cancellable
forall a. Ptr a
nullPtr
        Just jCancellable :: a
jCancellable -> do
            Ptr Cancellable
jCancellable' <- a -> IO (Ptr Cancellable)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr a
jCancellable
            Ptr Cancellable -> IO (Ptr Cancellable)
forall (m :: * -> *) a. Monad m => a -> m a
return Ptr Cancellable
jCancellable'
    FunPtr C_AsyncReadyCallback
maybeCallback <- case Maybe AsyncReadyCallback
callback of
        Nothing -> FunPtr C_AsyncReadyCallback -> IO (FunPtr C_AsyncReadyCallback)
forall (m :: * -> *) a. Monad m => a -> m a
return (Ptr Any -> FunPtr C_AsyncReadyCallback
forall a b. Ptr a -> FunPtr b
castPtrToFunPtr Ptr Any
forall a. Ptr a
nullPtr)
        Just jCallback :: AsyncReadyCallback
jCallback -> do
            Ptr (FunPtr C_AsyncReadyCallback)
ptrcallback <- IO (Ptr (FunPtr C_AsyncReadyCallback))
forall a. Storable a => IO (Ptr a)
callocMem :: IO (Ptr (FunPtr Gio.Callbacks.C_AsyncReadyCallback))
            FunPtr C_AsyncReadyCallback
jCallback' <- C_AsyncReadyCallback -> IO (FunPtr C_AsyncReadyCallback)
Gio.Callbacks.mk_AsyncReadyCallback (Maybe (Ptr (FunPtr C_AsyncReadyCallback))
-> AsyncReadyCallback_WithClosures -> C_AsyncReadyCallback
Gio.Callbacks.wrap_AsyncReadyCallback (Ptr (FunPtr C_AsyncReadyCallback)
-> Maybe (Ptr (FunPtr C_AsyncReadyCallback))
forall a. a -> Maybe a
Just Ptr (FunPtr C_AsyncReadyCallback)
ptrcallback) (AsyncReadyCallback -> AsyncReadyCallback_WithClosures
Gio.Callbacks.drop_closures_AsyncReadyCallback AsyncReadyCallback
jCallback))
            Ptr (FunPtr C_AsyncReadyCallback)
-> FunPtr C_AsyncReadyCallback -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke Ptr (FunPtr C_AsyncReadyCallback)
ptrcallback FunPtr C_AsyncReadyCallback
jCallback'
            FunPtr C_AsyncReadyCallback -> IO (FunPtr C_AsyncReadyCallback)
forall (m :: * -> *) a. Monad m => a -> m a
return FunPtr C_AsyncReadyCallback
jCallback'
    let userData :: Ptr a
userData = Ptr a
forall a. Ptr a
nullPtr
    Ptr Schema
-> Ptr (GHashTable (Ptr CChar) (Ptr CChar))
-> Ptr CChar
-> Ptr CChar
-> Ptr CChar
-> Ptr Cancellable
-> FunPtr C_AsyncReadyCallback
-> Ptr ()
-> IO ()
secret_password_storev Ptr Schema
schema' Ptr (GHashTable (Ptr CChar) (Ptr CChar))
attributes'''''' Ptr CChar
maybeCollection Ptr CChar
label' Ptr CChar
password' Ptr Cancellable
maybeCancellable FunPtr C_AsyncReadyCallback
maybeCallback Ptr ()
forall a. Ptr a
userData
    Schema -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr Schema
schema
    Maybe a -> (a -> IO ()) -> IO ()
forall (m :: * -> *) a. Monad m => Maybe a -> (a -> m ()) -> m ()
whenJust Maybe a
cancellable a -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr
    Ptr (GHashTable (Ptr CChar) (Ptr CChar)) -> IO ()
forall a b. Ptr (GHashTable a b) -> IO ()
unrefGHashTable Ptr (GHashTable (Ptr CChar) (Ptr CChar))
attributes''''''
    Ptr CChar -> IO ()
forall a. Ptr a -> IO ()
freeMem Ptr CChar
maybeCollection
    Ptr CChar -> IO ()
forall a. Ptr a -> IO ()
freeMem Ptr CChar
label'
    Ptr CChar -> IO ()
forall a. Ptr a -> IO ()
freeMem Ptr CChar
password'
    () -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()


-- function secret_password_lookupv_sync
-- Args: [ Arg
--           { argCName = "schema"
--           , argType =
--               TInterface Name { namespace = "Secret" , name = "Schema" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "the schema for attributes"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "attributes"
--           , argType = TGHash (TBasicType TUTF8) (TBasicType TUTF8)
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "the attribute keys and values"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "cancellable"
--           , argType =
--               TInterface Name { namespace = "Gio" , name = "Cancellable" }
--           , direction = DirectionIn
--           , mayBeNull = True
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "optional cancellation object"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       ]
-- Lengths: []
-- returnType: Just (TBasicType TUTF8)
-- throws : True
-- Skip return : False

foreign import ccall "secret_password_lookupv_sync" secret_password_lookupv_sync :: 
    Ptr Secret.Schema.Schema ->             -- schema : TInterface (Name {namespace = "Secret", name = "Schema"})
    Ptr (GHashTable CString CString) ->     -- attributes : TGHash (TBasicType TUTF8) (TBasicType TUTF8)
    Ptr Gio.Cancellable.Cancellable ->      -- cancellable : TInterface (Name {namespace = "Gio", name = "Cancellable"})
    Ptr (Ptr GError) ->                     -- error
    IO CString

-- | Lookup a password in the secret service.
-- 
-- The /@attributes@/ should be a set of key and value string pairs.
-- 
-- If no secret is found then 'P.Nothing' is returned.
-- 
-- This method may block indefinitely and should not be used in user interface
-- threads.
passwordLookupSync ::
    (B.CallStack.HasCallStack, MonadIO m, Gio.Cancellable.IsCancellable a) =>
    Secret.Schema.Schema
    -- ^ /@schema@/: the schema for attributes
    -> Map.Map T.Text T.Text
    -- ^ /@attributes@/: the attribute keys and values
    -> Maybe (a)
    -- ^ /@cancellable@/: optional cancellation object
    -> m T.Text
    -- ^ __Returns:__ a new password string which should be freed with
    --          @/secret_password_free()/@ or may be freed with 'GI.GLib.Functions.free' when done /(Can throw 'Data.GI.Base.GError.GError')/
passwordLookupSync :: Schema -> Map Text Text -> Maybe a -> m Text
passwordLookupSync schema :: Schema
schema attributes :: Map Text Text
attributes cancellable :: Maybe a
cancellable = IO Text -> m Text
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Text -> m Text) -> IO Text -> m Text
forall a b. (a -> b) -> a -> b
$ do
    Ptr Schema
schema' <- Schema -> IO (Ptr Schema)
forall a. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr a)
unsafeManagedPtrGetPtr Schema
schema
    let attributes' :: [(Text, Text)]
attributes' = Map Text Text -> [(Text, Text)]
forall k a. Map k a -> [(k, a)]
Map.toList Map Text Text
attributes
    [(Ptr CChar, Text)]
attributes'' <- (Text -> IO (Ptr CChar))
-> [(Text, Text)] -> IO [(Ptr CChar, Text)]
forall (f :: * -> *) a c b.
Applicative f =>
(a -> f c) -> [(a, b)] -> f [(c, b)]
mapFirstA Text -> IO (Ptr CChar)
textToCString [(Text, Text)]
attributes'
    [(Ptr CChar, Ptr CChar)]
attributes''' <- (Text -> IO (Ptr CChar))
-> [(Ptr CChar, Text)] -> IO [(Ptr CChar, Ptr CChar)]
forall (f :: * -> *) b c a.
Applicative f =>
(b -> f c) -> [(a, b)] -> f [(a, c)]
mapSecondA Text -> IO (Ptr CChar)
textToCString [(Ptr CChar, Text)]
attributes''
    let attributes'''' :: [(PtrWrapped (Ptr CChar), Ptr CChar)]
attributes'''' = (Ptr CChar -> PtrWrapped (Ptr CChar))
-> [(Ptr CChar, Ptr CChar)]
-> [(PtrWrapped (Ptr CChar), Ptr CChar)]
forall a c b. (a -> c) -> [(a, b)] -> [(c, b)]
mapFirst Ptr CChar -> PtrWrapped (Ptr CChar)
cstringPackPtr [(Ptr CChar, Ptr CChar)]
attributes'''
    let attributes''''' :: [(PtrWrapped (Ptr CChar), PtrWrapped (Ptr CChar))]
attributes''''' = (Ptr CChar -> PtrWrapped (Ptr CChar))
-> [(PtrWrapped (Ptr CChar), Ptr CChar)]
-> [(PtrWrapped (Ptr CChar), PtrWrapped (Ptr CChar))]
forall b c a. (b -> c) -> [(a, b)] -> [(a, c)]
mapSecond Ptr CChar -> PtrWrapped (Ptr CChar)
cstringPackPtr [(PtrWrapped (Ptr CChar), Ptr CChar)]
attributes''''
    Ptr (GHashTable (Ptr CChar) (Ptr CChar))
attributes'''''' <- GHashFunc (Ptr CChar)
-> GEqualFunc (Ptr CChar)
-> Maybe (GDestroyNotify (Ptr CChar))
-> Maybe (GDestroyNotify (Ptr CChar))
-> [(PtrWrapped (Ptr CChar), PtrWrapped (Ptr CChar))]
-> IO (Ptr (GHashTable (Ptr CChar) (Ptr CChar)))
forall a b.
GHashFunc a
-> GEqualFunc a
-> Maybe (GDestroyNotify a)
-> Maybe (GDestroyNotify b)
-> [(PtrWrapped a, PtrWrapped b)]
-> IO (Ptr (GHashTable a b))
packGHashTable GHashFunc (Ptr CChar)
gStrHash GEqualFunc (Ptr CChar)
gStrEqual (GDestroyNotify (Ptr CChar) -> Maybe (GDestroyNotify (Ptr CChar))
forall a. a -> Maybe a
Just GDestroyNotify (Ptr CChar)
forall a. FunPtr (Ptr a -> IO ())
ptr_to_g_free) (GDestroyNotify (Ptr CChar) -> Maybe (GDestroyNotify (Ptr CChar))
forall a. a -> Maybe a
Just GDestroyNotify (Ptr CChar)
forall a. FunPtr (Ptr a -> IO ())
ptr_to_g_free) [(PtrWrapped (Ptr CChar), PtrWrapped (Ptr CChar))]
attributes'''''
    Ptr Cancellable
maybeCancellable <- case Maybe a
cancellable of
        Nothing -> Ptr Cancellable -> IO (Ptr Cancellable)
forall (m :: * -> *) a. Monad m => a -> m a
return Ptr Cancellable
forall a. Ptr a
nullPtr
        Just jCancellable :: a
jCancellable -> do
            Ptr Cancellable
jCancellable' <- a -> IO (Ptr Cancellable)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr a
jCancellable
            Ptr Cancellable -> IO (Ptr Cancellable)
forall (m :: * -> *) a. Monad m => a -> m a
return Ptr Cancellable
jCancellable'
    IO Text -> IO () -> IO Text
forall a b. IO a -> IO b -> IO a
onException (do
        Ptr CChar
result <- (Ptr (Ptr GError) -> IO (Ptr CChar)) -> IO (Ptr CChar)
forall a. (Ptr (Ptr GError) -> IO a) -> IO a
propagateGError ((Ptr (Ptr GError) -> IO (Ptr CChar)) -> IO (Ptr CChar))
-> (Ptr (Ptr GError) -> IO (Ptr CChar)) -> IO (Ptr CChar)
forall a b. (a -> b) -> a -> b
$ Ptr Schema
-> Ptr (GHashTable (Ptr CChar) (Ptr CChar))
-> Ptr Cancellable
-> Ptr (Ptr GError)
-> IO (Ptr CChar)
secret_password_lookupv_sync Ptr Schema
schema' Ptr (GHashTable (Ptr CChar) (Ptr CChar))
attributes'''''' Ptr Cancellable
maybeCancellable
        Text -> Ptr CChar -> IO ()
forall a. HasCallStack => Text -> Ptr a -> IO ()
checkUnexpectedReturnNULL "passwordLookupSync" Ptr CChar
result
        Text
result' <- HasCallStack => Ptr CChar -> IO Text
Ptr CChar -> IO Text
cstringToText Ptr CChar
result
        Ptr CChar -> IO ()
forall a. Ptr a -> IO ()
freeMem Ptr CChar
result
        Schema -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr Schema
schema
        Maybe a -> (a -> IO ()) -> IO ()
forall (m :: * -> *) a. Monad m => Maybe a -> (a -> m ()) -> m ()
whenJust Maybe a
cancellable a -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr
        Ptr (GHashTable (Ptr CChar) (Ptr CChar)) -> IO ()
forall a b. Ptr (GHashTable a b) -> IO ()
unrefGHashTable Ptr (GHashTable (Ptr CChar) (Ptr CChar))
attributes''''''
        Text -> IO Text
forall (m :: * -> *) a. Monad m => a -> m a
return Text
result'
     ) (do
        Ptr (GHashTable (Ptr CChar) (Ptr CChar)) -> IO ()
forall a b. Ptr (GHashTable a b) -> IO ()
unrefGHashTable Ptr (GHashTable (Ptr CChar) (Ptr CChar))
attributes''''''
     )


-- function secret_password_lookup_finish
-- Args: [ Arg
--           { argCName = "result"
--           , argType =
--               TInterface Name { namespace = "Gio" , name = "AsyncResult" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText =
--                     Just "the asynchronous result passed to the callback"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       ]
-- Lengths: []
-- returnType: Just (TBasicType TUTF8)
-- throws : True
-- Skip return : False

foreign import ccall "secret_password_lookup_finish" secret_password_lookup_finish :: 
    Ptr Gio.AsyncResult.AsyncResult ->      -- result : TInterface (Name {namespace = "Gio", name = "AsyncResult"})
    Ptr (Ptr GError) ->                     -- error
    IO CString

-- | Finish an asynchronous operation to lookup a password in the secret service.
passwordLookupFinish ::
    (B.CallStack.HasCallStack, MonadIO m, Gio.AsyncResult.IsAsyncResult a) =>
    a
    -- ^ /@result@/: the asynchronous result passed to the callback
    -> m T.Text
    -- ^ __Returns:__ a new password string which should be freed with
    --          @/secret_password_free()/@ or may be freed with 'GI.GLib.Functions.free' when done /(Can throw 'Data.GI.Base.GError.GError')/
passwordLookupFinish :: a -> m Text
passwordLookupFinish result_ :: a
result_ = IO Text -> m Text
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Text -> m Text) -> IO Text -> m Text
forall a b. (a -> b) -> a -> b
$ do
    Ptr AsyncResult
result_' <- a -> IO (Ptr AsyncResult)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr a
result_
    IO Text -> IO () -> IO Text
forall a b. IO a -> IO b -> IO a
onException (do
        Ptr CChar
result <- (Ptr (Ptr GError) -> IO (Ptr CChar)) -> IO (Ptr CChar)
forall a. (Ptr (Ptr GError) -> IO a) -> IO a
propagateGError ((Ptr (Ptr GError) -> IO (Ptr CChar)) -> IO (Ptr CChar))
-> (Ptr (Ptr GError) -> IO (Ptr CChar)) -> IO (Ptr CChar)
forall a b. (a -> b) -> a -> b
$ Ptr AsyncResult -> Ptr (Ptr GError) -> IO (Ptr CChar)
secret_password_lookup_finish Ptr AsyncResult
result_'
        Text -> Ptr CChar -> IO ()
forall a. HasCallStack => Text -> Ptr a -> IO ()
checkUnexpectedReturnNULL "passwordLookupFinish" Ptr CChar
result
        Text
result' <- HasCallStack => Ptr CChar -> IO Text
Ptr CChar -> IO Text
cstringToText Ptr CChar
result
        Ptr CChar -> IO ()
forall a. Ptr a -> IO ()
freeMem Ptr CChar
result
        a -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr a
result_
        Text -> IO Text
forall (m :: * -> *) a. Monad m => a -> m a
return Text
result'
     ) (do
        () -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
     )


-- function secret_password_lookupv
-- Args: [ Arg
--           { argCName = "schema"
--           , argType =
--               TInterface Name { namespace = "Secret" , name = "Schema" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "the schema for attributes"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "attributes"
--           , argType = TGHash (TBasicType TUTF8) (TBasicType TUTF8)
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "the attribute keys and values"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "cancellable"
--           , argType =
--               TInterface Name { namespace = "Gio" , name = "Cancellable" }
--           , direction = DirectionIn
--           , mayBeNull = True
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "optional cancellation object"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "callback"
--           , argType =
--               TInterface Name { namespace = "Gio" , name = "AsyncReadyCallback" }
--           , direction = DirectionIn
--           , mayBeNull = True
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "called when the operation completes"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeAsync
--           , argClosure = 4
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "user_data"
--           , argType = TBasicType TPtr
--           , direction = DirectionIn
--           , mayBeNull = True
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "data to be passed to the callback"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       ]
-- Lengths: []
-- returnType: Nothing
-- throws : False
-- Skip return : False

foreign import ccall "secret_password_lookupv" secret_password_lookupv :: 
    Ptr Secret.Schema.Schema ->             -- schema : TInterface (Name {namespace = "Secret", name = "Schema"})
    Ptr (GHashTable CString CString) ->     -- attributes : TGHash (TBasicType TUTF8) (TBasicType TUTF8)
    Ptr Gio.Cancellable.Cancellable ->      -- cancellable : TInterface (Name {namespace = "Gio", name = "Cancellable"})
    FunPtr Gio.Callbacks.C_AsyncReadyCallback -> -- callback : TInterface (Name {namespace = "Gio", name = "AsyncReadyCallback"})
    Ptr () ->                               -- user_data : TBasicType TPtr
    IO ()

-- | Lookup a password in the secret service.
-- 
-- The /@attributes@/ should be a set of key and value string pairs.
-- 
-- If no secret is found then 'P.Nothing' is returned.
-- 
-- This method will return immediately and complete asynchronously.
passwordLookup ::
    (B.CallStack.HasCallStack, MonadIO m, Gio.Cancellable.IsCancellable a) =>
    Secret.Schema.Schema
    -- ^ /@schema@/: the schema for attributes
    -> Map.Map T.Text T.Text
    -- ^ /@attributes@/: the attribute keys and values
    -> Maybe (a)
    -- ^ /@cancellable@/: optional cancellation object
    -> Maybe (Gio.Callbacks.AsyncReadyCallback)
    -- ^ /@callback@/: called when the operation completes
    -> m ()
passwordLookup :: Schema
-> Map Text Text -> Maybe a -> Maybe AsyncReadyCallback -> m ()
passwordLookup schema :: Schema
schema attributes :: Map Text Text
attributes cancellable :: Maybe a
cancellable callback :: Maybe AsyncReadyCallback
callback = IO () -> m ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$ do
    Ptr Schema
schema' <- Schema -> IO (Ptr Schema)
forall a. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr a)
unsafeManagedPtrGetPtr Schema
schema
    let attributes' :: [(Text, Text)]
attributes' = Map Text Text -> [(Text, Text)]
forall k a. Map k a -> [(k, a)]
Map.toList Map Text Text
attributes
    [(Ptr CChar, Text)]
attributes'' <- (Text -> IO (Ptr CChar))
-> [(Text, Text)] -> IO [(Ptr CChar, Text)]
forall (f :: * -> *) a c b.
Applicative f =>
(a -> f c) -> [(a, b)] -> f [(c, b)]
mapFirstA Text -> IO (Ptr CChar)
textToCString [(Text, Text)]
attributes'
    [(Ptr CChar, Ptr CChar)]
attributes''' <- (Text -> IO (Ptr CChar))
-> [(Ptr CChar, Text)] -> IO [(Ptr CChar, Ptr CChar)]
forall (f :: * -> *) b c a.
Applicative f =>
(b -> f c) -> [(a, b)] -> f [(a, c)]
mapSecondA Text -> IO (Ptr CChar)
textToCString [(Ptr CChar, Text)]
attributes''
    let attributes'''' :: [(PtrWrapped (Ptr CChar), Ptr CChar)]
attributes'''' = (Ptr CChar -> PtrWrapped (Ptr CChar))
-> [(Ptr CChar, Ptr CChar)]
-> [(PtrWrapped (Ptr CChar), Ptr CChar)]
forall a c b. (a -> c) -> [(a, b)] -> [(c, b)]
mapFirst Ptr CChar -> PtrWrapped (Ptr CChar)
cstringPackPtr [(Ptr CChar, Ptr CChar)]
attributes'''
    let attributes''''' :: [(PtrWrapped (Ptr CChar), PtrWrapped (Ptr CChar))]
attributes''''' = (Ptr CChar -> PtrWrapped (Ptr CChar))
-> [(PtrWrapped (Ptr CChar), Ptr CChar)]
-> [(PtrWrapped (Ptr CChar), PtrWrapped (Ptr CChar))]
forall b c a. (b -> c) -> [(a, b)] -> [(a, c)]
mapSecond Ptr CChar -> PtrWrapped (Ptr CChar)
cstringPackPtr [(PtrWrapped (Ptr CChar), Ptr CChar)]
attributes''''
    Ptr (GHashTable (Ptr CChar) (Ptr CChar))
attributes'''''' <- GHashFunc (Ptr CChar)
-> GEqualFunc (Ptr CChar)
-> Maybe (GDestroyNotify (Ptr CChar))
-> Maybe (GDestroyNotify (Ptr CChar))
-> [(PtrWrapped (Ptr CChar), PtrWrapped (Ptr CChar))]
-> IO (Ptr (GHashTable (Ptr CChar) (Ptr CChar)))
forall a b.
GHashFunc a
-> GEqualFunc a
-> Maybe (GDestroyNotify a)
-> Maybe (GDestroyNotify b)
-> [(PtrWrapped a, PtrWrapped b)]
-> IO (Ptr (GHashTable a b))
packGHashTable GHashFunc (Ptr CChar)
gStrHash GEqualFunc (Ptr CChar)
gStrEqual (GDestroyNotify (Ptr CChar) -> Maybe (GDestroyNotify (Ptr CChar))
forall a. a -> Maybe a
Just GDestroyNotify (Ptr CChar)
forall a. FunPtr (Ptr a -> IO ())
ptr_to_g_free) (GDestroyNotify (Ptr CChar) -> Maybe (GDestroyNotify (Ptr CChar))
forall a. a -> Maybe a
Just GDestroyNotify (Ptr CChar)
forall a. FunPtr (Ptr a -> IO ())
ptr_to_g_free) [(PtrWrapped (Ptr CChar), PtrWrapped (Ptr CChar))]
attributes'''''
    Ptr Cancellable
maybeCancellable <- case Maybe a
cancellable of
        Nothing -> Ptr Cancellable -> IO (Ptr Cancellable)
forall (m :: * -> *) a. Monad m => a -> m a
return Ptr Cancellable
forall a. Ptr a
nullPtr
        Just jCancellable :: a
jCancellable -> do
            Ptr Cancellable
jCancellable' <- a -> IO (Ptr Cancellable)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr a
jCancellable
            Ptr Cancellable -> IO (Ptr Cancellable)
forall (m :: * -> *) a. Monad m => a -> m a
return Ptr Cancellable
jCancellable'
    FunPtr C_AsyncReadyCallback
maybeCallback <- case Maybe AsyncReadyCallback
callback of
        Nothing -> FunPtr C_AsyncReadyCallback -> IO (FunPtr C_AsyncReadyCallback)
forall (m :: * -> *) a. Monad m => a -> m a
return (Ptr Any -> FunPtr C_AsyncReadyCallback
forall a b. Ptr a -> FunPtr b
castPtrToFunPtr Ptr Any
forall a. Ptr a
nullPtr)
        Just jCallback :: AsyncReadyCallback
jCallback -> do
            Ptr (FunPtr C_AsyncReadyCallback)
ptrcallback <- IO (Ptr (FunPtr C_AsyncReadyCallback))
forall a. Storable a => IO (Ptr a)
callocMem :: IO (Ptr (FunPtr Gio.Callbacks.C_AsyncReadyCallback))
            FunPtr C_AsyncReadyCallback
jCallback' <- C_AsyncReadyCallback -> IO (FunPtr C_AsyncReadyCallback)
Gio.Callbacks.mk_AsyncReadyCallback (Maybe (Ptr (FunPtr C_AsyncReadyCallback))
-> AsyncReadyCallback_WithClosures -> C_AsyncReadyCallback
Gio.Callbacks.wrap_AsyncReadyCallback (Ptr (FunPtr C_AsyncReadyCallback)
-> Maybe (Ptr (FunPtr C_AsyncReadyCallback))
forall a. a -> Maybe a
Just Ptr (FunPtr C_AsyncReadyCallback)
ptrcallback) (AsyncReadyCallback -> AsyncReadyCallback_WithClosures
Gio.Callbacks.drop_closures_AsyncReadyCallback AsyncReadyCallback
jCallback))
            Ptr (FunPtr C_AsyncReadyCallback)
-> FunPtr C_AsyncReadyCallback -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke Ptr (FunPtr C_AsyncReadyCallback)
ptrcallback FunPtr C_AsyncReadyCallback
jCallback'
            FunPtr C_AsyncReadyCallback -> IO (FunPtr C_AsyncReadyCallback)
forall (m :: * -> *) a. Monad m => a -> m a
return FunPtr C_AsyncReadyCallback
jCallback'
    let userData :: Ptr a
userData = Ptr a
forall a. Ptr a
nullPtr
    Ptr Schema
-> Ptr (GHashTable (Ptr CChar) (Ptr CChar))
-> Ptr Cancellable
-> FunPtr C_AsyncReadyCallback
-> Ptr ()
-> IO ()
secret_password_lookupv Ptr Schema
schema' Ptr (GHashTable (Ptr CChar) (Ptr CChar))
attributes'''''' Ptr Cancellable
maybeCancellable FunPtr C_AsyncReadyCallback
maybeCallback Ptr ()
forall a. Ptr a
userData
    Schema -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr Schema
schema
    Maybe a -> (a -> IO ()) -> IO ()
forall (m :: * -> *) a. Monad m => Maybe a -> (a -> m ()) -> m ()
whenJust Maybe a
cancellable a -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr
    Ptr (GHashTable (Ptr CChar) (Ptr CChar)) -> IO ()
forall a b. Ptr (GHashTable a b) -> IO ()
unrefGHashTable Ptr (GHashTable (Ptr CChar) (Ptr CChar))
attributes''''''
    () -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()


-- function secret_password_clearv_sync
-- Args: [ Arg
--           { argCName = "schema"
--           , argType =
--               TInterface Name { namespace = "Secret" , name = "Schema" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "the schema for the attributes"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "attributes"
--           , argType = TGHash (TBasicType TUTF8) (TBasicType TUTF8)
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "the attribute keys and values"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "cancellable"
--           , argType =
--               TInterface Name { namespace = "Gio" , name = "Cancellable" }
--           , direction = DirectionIn
--           , mayBeNull = True
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "optional cancellation object"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       ]
-- Lengths: []
-- returnType: Just (TBasicType TBoolean)
-- throws : True
-- Skip return : False

foreign import ccall "secret_password_clearv_sync" secret_password_clearv_sync :: 
    Ptr Secret.Schema.Schema ->             -- schema : TInterface (Name {namespace = "Secret", name = "Schema"})
    Ptr (GHashTable CString CString) ->     -- attributes : TGHash (TBasicType TUTF8) (TBasicType TUTF8)
    Ptr Gio.Cancellable.Cancellable ->      -- cancellable : TInterface (Name {namespace = "Gio", name = "Cancellable"})
    Ptr (Ptr GError) ->                     -- error
    IO CInt

-- | Remove unlocked matching passwords from the secret service.
-- 
-- The /@attributes@/ should be a set of key and value string pairs.
-- 
-- All unlocked items that match the attributes will be deleted.
-- 
-- This method may block indefinitely and should not be used in user interface
-- threads.
passwordClearSync ::
    (B.CallStack.HasCallStack, MonadIO m, Gio.Cancellable.IsCancellable a) =>
    Secret.Schema.Schema
    -- ^ /@schema@/: the schema for the attributes
    -> Map.Map T.Text T.Text
    -- ^ /@attributes@/: the attribute keys and values
    -> Maybe (a)
    -- ^ /@cancellable@/: optional cancellation object
    -> m ()
    -- ^ /(Can throw 'Data.GI.Base.GError.GError')/
passwordClearSync :: Schema -> Map Text Text -> Maybe a -> m ()
passwordClearSync schema :: Schema
schema attributes :: Map Text Text
attributes cancellable :: Maybe a
cancellable = IO () -> m ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$ do
    Ptr Schema
schema' <- Schema -> IO (Ptr Schema)
forall a. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr a)
unsafeManagedPtrGetPtr Schema
schema
    let attributes' :: [(Text, Text)]
attributes' = Map Text Text -> [(Text, Text)]
forall k a. Map k a -> [(k, a)]
Map.toList Map Text Text
attributes
    [(Ptr CChar, Text)]
attributes'' <- (Text -> IO (Ptr CChar))
-> [(Text, Text)] -> IO [(Ptr CChar, Text)]
forall (f :: * -> *) a c b.
Applicative f =>
(a -> f c) -> [(a, b)] -> f [(c, b)]
mapFirstA Text -> IO (Ptr CChar)
textToCString [(Text, Text)]
attributes'
    [(Ptr CChar, Ptr CChar)]
attributes''' <- (Text -> IO (Ptr CChar))
-> [(Ptr CChar, Text)] -> IO [(Ptr CChar, Ptr CChar)]
forall (f :: * -> *) b c a.
Applicative f =>
(b -> f c) -> [(a, b)] -> f [(a, c)]
mapSecondA Text -> IO (Ptr CChar)
textToCString [(Ptr CChar, Text)]
attributes''
    let attributes'''' :: [(PtrWrapped (Ptr CChar), Ptr CChar)]
attributes'''' = (Ptr CChar -> PtrWrapped (Ptr CChar))
-> [(Ptr CChar, Ptr CChar)]
-> [(PtrWrapped (Ptr CChar), Ptr CChar)]
forall a c b. (a -> c) -> [(a, b)] -> [(c, b)]
mapFirst Ptr CChar -> PtrWrapped (Ptr CChar)
cstringPackPtr [(Ptr CChar, Ptr CChar)]
attributes'''
    let attributes''''' :: [(PtrWrapped (Ptr CChar), PtrWrapped (Ptr CChar))]
attributes''''' = (Ptr CChar -> PtrWrapped (Ptr CChar))
-> [(PtrWrapped (Ptr CChar), Ptr CChar)]
-> [(PtrWrapped (Ptr CChar), PtrWrapped (Ptr CChar))]
forall b c a. (b -> c) -> [(a, b)] -> [(a, c)]
mapSecond Ptr CChar -> PtrWrapped (Ptr CChar)
cstringPackPtr [(PtrWrapped (Ptr CChar), Ptr CChar)]
attributes''''
    Ptr (GHashTable (Ptr CChar) (Ptr CChar))
attributes'''''' <- GHashFunc (Ptr CChar)
-> GEqualFunc (Ptr CChar)
-> Maybe (GDestroyNotify (Ptr CChar))
-> Maybe (GDestroyNotify (Ptr CChar))
-> [(PtrWrapped (Ptr CChar), PtrWrapped (Ptr CChar))]
-> IO (Ptr (GHashTable (Ptr CChar) (Ptr CChar)))
forall a b.
GHashFunc a
-> GEqualFunc a
-> Maybe (GDestroyNotify a)
-> Maybe (GDestroyNotify b)
-> [(PtrWrapped a, PtrWrapped b)]
-> IO (Ptr (GHashTable a b))
packGHashTable GHashFunc (Ptr CChar)
gStrHash GEqualFunc (Ptr CChar)
gStrEqual (GDestroyNotify (Ptr CChar) -> Maybe (GDestroyNotify (Ptr CChar))
forall a. a -> Maybe a
Just GDestroyNotify (Ptr CChar)
forall a. FunPtr (Ptr a -> IO ())
ptr_to_g_free) (GDestroyNotify (Ptr CChar) -> Maybe (GDestroyNotify (Ptr CChar))
forall a. a -> Maybe a
Just GDestroyNotify (Ptr CChar)
forall a. FunPtr (Ptr a -> IO ())
ptr_to_g_free) [(PtrWrapped (Ptr CChar), PtrWrapped (Ptr CChar))]
attributes'''''
    Ptr Cancellable
maybeCancellable <- case Maybe a
cancellable of
        Nothing -> Ptr Cancellable -> IO (Ptr Cancellable)
forall (m :: * -> *) a. Monad m => a -> m a
return Ptr Cancellable
forall a. Ptr a
nullPtr
        Just jCancellable :: a
jCancellable -> do
            Ptr Cancellable
jCancellable' <- a -> IO (Ptr Cancellable)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr a
jCancellable
            Ptr Cancellable -> IO (Ptr Cancellable)
forall (m :: * -> *) a. Monad m => a -> m a
return Ptr Cancellable
jCancellable'
    IO () -> IO () -> IO ()
forall a b. IO a -> IO b -> IO a
onException (do
        CInt
_ <- (Ptr (Ptr GError) -> IO CInt) -> IO CInt
forall a. (Ptr (Ptr GError) -> IO a) -> IO a
propagateGError ((Ptr (Ptr GError) -> IO CInt) -> IO CInt)
-> (Ptr (Ptr GError) -> IO CInt) -> IO CInt
forall a b. (a -> b) -> a -> b
$ Ptr Schema
-> Ptr (GHashTable (Ptr CChar) (Ptr CChar))
-> Ptr Cancellable
-> Ptr (Ptr GError)
-> IO CInt
secret_password_clearv_sync Ptr Schema
schema' Ptr (GHashTable (Ptr CChar) (Ptr CChar))
attributes'''''' Ptr Cancellable
maybeCancellable
        Schema -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr Schema
schema
        Maybe a -> (a -> IO ()) -> IO ()
forall (m :: * -> *) a. Monad m => Maybe a -> (a -> m ()) -> m ()
whenJust Maybe a
cancellable a -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr
        Ptr (GHashTable (Ptr CChar) (Ptr CChar)) -> IO ()
forall a b. Ptr (GHashTable a b) -> IO ()
unrefGHashTable Ptr (GHashTable (Ptr CChar) (Ptr CChar))
attributes''''''
        () -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
     ) (do
        Ptr (GHashTable (Ptr CChar) (Ptr CChar)) -> IO ()
forall a b. Ptr (GHashTable a b) -> IO ()
unrefGHashTable Ptr (GHashTable (Ptr CChar) (Ptr CChar))
attributes''''''
     )


-- function secret_password_clear_finish
-- Args: [ Arg
--           { argCName = "result"
--           , argType =
--               TInterface Name { namespace = "Gio" , name = "AsyncResult" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText =
--                     Just "the asynchronous result passed to the callback"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       ]
-- Lengths: []
-- returnType: Just (TBasicType TBoolean)
-- throws : True
-- Skip return : False

foreign import ccall "secret_password_clear_finish" secret_password_clear_finish :: 
    Ptr Gio.AsyncResult.AsyncResult ->      -- result : TInterface (Name {namespace = "Gio", name = "AsyncResult"})
    Ptr (Ptr GError) ->                     -- error
    IO CInt

-- | Finish an asynchronous operation to remove passwords from the secret
-- service.
passwordClearFinish ::
    (B.CallStack.HasCallStack, MonadIO m, Gio.AsyncResult.IsAsyncResult a) =>
    a
    -- ^ /@result@/: the asynchronous result passed to the callback
    -> m ()
    -- ^ /(Can throw 'Data.GI.Base.GError.GError')/
passwordClearFinish :: a -> m ()
passwordClearFinish result_ :: a
result_ = IO () -> m ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$ do
    Ptr AsyncResult
result_' <- a -> IO (Ptr AsyncResult)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr a
result_
    IO () -> IO () -> IO ()
forall a b. IO a -> IO b -> IO a
onException (do
        CInt
_ <- (Ptr (Ptr GError) -> IO CInt) -> IO CInt
forall a. (Ptr (Ptr GError) -> IO a) -> IO a
propagateGError ((Ptr (Ptr GError) -> IO CInt) -> IO CInt)
-> (Ptr (Ptr GError) -> IO CInt) -> IO CInt
forall a b. (a -> b) -> a -> b
$ Ptr AsyncResult -> Ptr (Ptr GError) -> IO CInt
secret_password_clear_finish Ptr AsyncResult
result_'
        a -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr a
result_
        () -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
     ) (do
        () -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
     )


-- function secret_password_clearv
-- Args: [ Arg
--           { argCName = "schema"
--           , argType =
--               TInterface Name { namespace = "Secret" , name = "Schema" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "the schema for the attributes"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "attributes"
--           , argType = TGHash (TBasicType TUTF8) (TBasicType TUTF8)
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "the attribute keys and values"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "cancellable"
--           , argType =
--               TInterface Name { namespace = "Gio" , name = "Cancellable" }
--           , direction = DirectionIn
--           , mayBeNull = True
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "optional cancellation object"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "callback"
--           , argType =
--               TInterface Name { namespace = "Gio" , name = "AsyncReadyCallback" }
--           , direction = DirectionIn
--           , mayBeNull = True
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "called when the operation completes"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeAsync
--           , argClosure = 4
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "user_data"
--           , argType = TBasicType TPtr
--           , direction = DirectionIn
--           , mayBeNull = True
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "data to be passed to the callback"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       ]
-- Lengths: []
-- returnType: Nothing
-- throws : False
-- Skip return : False

foreign import ccall "secret_password_clearv" secret_password_clearv :: 
    Ptr Secret.Schema.Schema ->             -- schema : TInterface (Name {namespace = "Secret", name = "Schema"})
    Ptr (GHashTable CString CString) ->     -- attributes : TGHash (TBasicType TUTF8) (TBasicType TUTF8)
    Ptr Gio.Cancellable.Cancellable ->      -- cancellable : TInterface (Name {namespace = "Gio", name = "Cancellable"})
    FunPtr Gio.Callbacks.C_AsyncReadyCallback -> -- callback : TInterface (Name {namespace = "Gio", name = "AsyncReadyCallback"})
    Ptr () ->                               -- user_data : TBasicType TPtr
    IO ()

-- | Remove unlocked matching passwords from the secret service.
-- 
-- The /@attributes@/ should be a set of key and value string pairs.
-- 
-- All unlocked items that match the attributes will be deleted.
-- 
-- This method will return immediately and complete asynchronously.
passwordClear ::
    (B.CallStack.HasCallStack, MonadIO m, Gio.Cancellable.IsCancellable a) =>
    Secret.Schema.Schema
    -- ^ /@schema@/: the schema for the attributes
    -> Map.Map T.Text T.Text
    -- ^ /@attributes@/: the attribute keys and values
    -> Maybe (a)
    -- ^ /@cancellable@/: optional cancellation object
    -> Maybe (Gio.Callbacks.AsyncReadyCallback)
    -- ^ /@callback@/: called when the operation completes
    -> m ()
passwordClear :: Schema
-> Map Text Text -> Maybe a -> Maybe AsyncReadyCallback -> m ()
passwordClear schema :: Schema
schema attributes :: Map Text Text
attributes cancellable :: Maybe a
cancellable callback :: Maybe AsyncReadyCallback
callback = IO () -> m ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$ do
    Ptr Schema
schema' <- Schema -> IO (Ptr Schema)
forall a. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr a)
unsafeManagedPtrGetPtr Schema
schema
    let attributes' :: [(Text, Text)]
attributes' = Map Text Text -> [(Text, Text)]
forall k a. Map k a -> [(k, a)]
Map.toList Map Text Text
attributes
    [(Ptr CChar, Text)]
attributes'' <- (Text -> IO (Ptr CChar))
-> [(Text, Text)] -> IO [(Ptr CChar, Text)]
forall (f :: * -> *) a c b.
Applicative f =>
(a -> f c) -> [(a, b)] -> f [(c, b)]
mapFirstA Text -> IO (Ptr CChar)
textToCString [(Text, Text)]
attributes'
    [(Ptr CChar, Ptr CChar)]
attributes''' <- (Text -> IO (Ptr CChar))
-> [(Ptr CChar, Text)] -> IO [(Ptr CChar, Ptr CChar)]
forall (f :: * -> *) b c a.
Applicative f =>
(b -> f c) -> [(a, b)] -> f [(a, c)]
mapSecondA Text -> IO (Ptr CChar)
textToCString [(Ptr CChar, Text)]
attributes''
    let attributes'''' :: [(PtrWrapped (Ptr CChar), Ptr CChar)]
attributes'''' = (Ptr CChar -> PtrWrapped (Ptr CChar))
-> [(Ptr CChar, Ptr CChar)]
-> [(PtrWrapped (Ptr CChar), Ptr CChar)]
forall a c b. (a -> c) -> [(a, b)] -> [(c, b)]
mapFirst Ptr CChar -> PtrWrapped (Ptr CChar)
cstringPackPtr [(Ptr CChar, Ptr CChar)]
attributes'''
    let attributes''''' :: [(PtrWrapped (Ptr CChar), PtrWrapped (Ptr CChar))]
attributes''''' = (Ptr CChar -> PtrWrapped (Ptr CChar))
-> [(PtrWrapped (Ptr CChar), Ptr CChar)]
-> [(PtrWrapped (Ptr CChar), PtrWrapped (Ptr CChar))]
forall b c a. (b -> c) -> [(a, b)] -> [(a, c)]
mapSecond Ptr CChar -> PtrWrapped (Ptr CChar)
cstringPackPtr [(PtrWrapped (Ptr CChar), Ptr CChar)]
attributes''''
    Ptr (GHashTable (Ptr CChar) (Ptr CChar))
attributes'''''' <- GHashFunc (Ptr CChar)
-> GEqualFunc (Ptr CChar)
-> Maybe (GDestroyNotify (Ptr CChar))
-> Maybe (GDestroyNotify (Ptr CChar))
-> [(PtrWrapped (Ptr CChar), PtrWrapped (Ptr CChar))]
-> IO (Ptr (GHashTable (Ptr CChar) (Ptr CChar)))
forall a b.
GHashFunc a
-> GEqualFunc a
-> Maybe (GDestroyNotify a)
-> Maybe (GDestroyNotify b)
-> [(PtrWrapped a, PtrWrapped b)]
-> IO (Ptr (GHashTable a b))
packGHashTable GHashFunc (Ptr CChar)
gStrHash GEqualFunc (Ptr CChar)
gStrEqual (GDestroyNotify (Ptr CChar) -> Maybe (GDestroyNotify (Ptr CChar))
forall a. a -> Maybe a
Just GDestroyNotify (Ptr CChar)
forall a. FunPtr (Ptr a -> IO ())
ptr_to_g_free) (GDestroyNotify (Ptr CChar) -> Maybe (GDestroyNotify (Ptr CChar))
forall a. a -> Maybe a
Just GDestroyNotify (Ptr CChar)
forall a. FunPtr (Ptr a -> IO ())
ptr_to_g_free) [(PtrWrapped (Ptr CChar), PtrWrapped (Ptr CChar))]
attributes'''''
    Ptr Cancellable
maybeCancellable <- case Maybe a
cancellable of
        Nothing -> Ptr Cancellable -> IO (Ptr Cancellable)
forall (m :: * -> *) a. Monad m => a -> m a
return Ptr Cancellable
forall a. Ptr a
nullPtr
        Just jCancellable :: a
jCancellable -> do
            Ptr Cancellable
jCancellable' <- a -> IO (Ptr Cancellable)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr a
jCancellable
            Ptr Cancellable -> IO (Ptr Cancellable)
forall (m :: * -> *) a. Monad m => a -> m a
return Ptr Cancellable
jCancellable'
    FunPtr C_AsyncReadyCallback
maybeCallback <- case Maybe AsyncReadyCallback
callback of
        Nothing -> FunPtr C_AsyncReadyCallback -> IO (FunPtr C_AsyncReadyCallback)
forall (m :: * -> *) a. Monad m => a -> m a
return (Ptr Any -> FunPtr C_AsyncReadyCallback
forall a b. Ptr a -> FunPtr b
castPtrToFunPtr Ptr Any
forall a. Ptr a
nullPtr)
        Just jCallback :: AsyncReadyCallback
jCallback -> do
            Ptr (FunPtr C_AsyncReadyCallback)
ptrcallback <- IO (Ptr (FunPtr C_AsyncReadyCallback))
forall a. Storable a => IO (Ptr a)
callocMem :: IO (Ptr (FunPtr Gio.Callbacks.C_AsyncReadyCallback))
            FunPtr C_AsyncReadyCallback
jCallback' <- C_AsyncReadyCallback -> IO (FunPtr C_AsyncReadyCallback)
Gio.Callbacks.mk_AsyncReadyCallback (Maybe (Ptr (FunPtr C_AsyncReadyCallback))
-> AsyncReadyCallback_WithClosures -> C_AsyncReadyCallback
Gio.Callbacks.wrap_AsyncReadyCallback (Ptr (FunPtr C_AsyncReadyCallback)
-> Maybe (Ptr (FunPtr C_AsyncReadyCallback))
forall a. a -> Maybe a
Just Ptr (FunPtr C_AsyncReadyCallback)
ptrcallback) (AsyncReadyCallback -> AsyncReadyCallback_WithClosures
Gio.Callbacks.drop_closures_AsyncReadyCallback AsyncReadyCallback
jCallback))
            Ptr (FunPtr C_AsyncReadyCallback)
-> FunPtr C_AsyncReadyCallback -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke Ptr (FunPtr C_AsyncReadyCallback)
ptrcallback FunPtr C_AsyncReadyCallback
jCallback'
            FunPtr C_AsyncReadyCallback -> IO (FunPtr C_AsyncReadyCallback)
forall (m :: * -> *) a. Monad m => a -> m a
return FunPtr C_AsyncReadyCallback
jCallback'
    let userData :: Ptr a
userData = Ptr a
forall a. Ptr a
nullPtr
    Ptr Schema
-> Ptr (GHashTable (Ptr CChar) (Ptr CChar))
-> Ptr Cancellable
-> FunPtr C_AsyncReadyCallback
-> Ptr ()
-> IO ()
secret_password_clearv Ptr Schema
schema' Ptr (GHashTable (Ptr CChar) (Ptr CChar))
attributes'''''' Ptr Cancellable
maybeCancellable FunPtr C_AsyncReadyCallback
maybeCallback Ptr ()
forall a. Ptr a
userData
    Schema -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr Schema
schema
    Maybe a -> (a -> IO ()) -> IO ()
forall (m :: * -> *) a. Monad m => Maybe a -> (a -> m ()) -> m ()
whenJust Maybe a
cancellable a -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr
    Ptr (GHashTable (Ptr CChar) (Ptr CChar)) -> IO ()
forall a b. Ptr (GHashTable a b) -> IO ()
unrefGHashTable Ptr (GHashTable (Ptr CChar) (Ptr CChar))
attributes''''''
    () -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()


-- function secret_get_schema
-- Args: [ Arg
--           { argCName = "type"
--           , argType =
--               TInterface Name { namespace = "Secret" , name = "SchemaType" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "type of schema to get"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       ]
-- Lengths: []
-- returnType: Just (TInterface Name { namespace = "Secret" , name = "Schema" })
-- throws : False
-- Skip return : False

foreign import ccall "secret_get_schema" secret_get_schema :: 
    CUInt ->                                -- type : TInterface (Name {namespace = "Secret", name = "SchemaType"})
    IO (Ptr Secret.Schema.Schema)

-- | Get a secret storage schema of the given /@type@/.
-- 
-- C code may access the schemas (such as @/SECRET_SCHEMA_NOTE/@) directly, but
-- language bindings cannot, and must use this accessor.
-- 
-- /Since: 0.18.6/
getSchema ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    Secret.Enums.SchemaType
    -- ^ /@type@/: type of schema to get
    -> m Secret.Schema.Schema
    -- ^ __Returns:__ schema type
getSchema :: SchemaType -> m Schema
getSchema type_ :: SchemaType
type_ = IO Schema -> m Schema
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Schema -> m Schema) -> IO Schema -> m Schema
forall a b. (a -> b) -> a -> b
$ do
    let type_' :: CUInt
type_' = (Int -> CUInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> CUInt) -> (SchemaType -> Int) -> SchemaType -> CUInt
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SchemaType -> Int
forall a. Enum a => a -> Int
fromEnum) SchemaType
type_
    Ptr Schema
result <- CUInt -> IO (Ptr Schema)
secret_get_schema CUInt
type_'
    Text -> Ptr Schema -> IO ()
forall a. HasCallStack => Text -> Ptr a -> IO ()
checkUnexpectedReturnNULL "getSchema" Ptr Schema
result
    Schema
result' <- ((ManagedPtr Schema -> Schema) -> Ptr Schema -> IO Schema
forall a.
(HasCallStack, BoxedObject a) =>
(ManagedPtr a -> a) -> Ptr a -> IO a
newBoxed ManagedPtr Schema -> Schema
Secret.Schema.Schema) Ptr Schema
result
    Schema -> IO Schema
forall (m :: * -> *) a. Monad m => a -> m a
return Schema
result'


-- function secret_error_get_quark
-- Args: []
-- Lengths: []
-- returnType: Just (TBasicType TUInt32)
-- throws : False
-- Skip return : False

foreign import ccall "secret_error_get_quark" secret_error_get_quark :: 
    IO Word32

-- | /No description available in the introspection data./
errorGetQuark ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    m Word32
errorGetQuark :: m Word32
errorGetQuark  = IO Word32 -> m Word32
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Word32 -> m Word32) -> IO Word32 -> m Word32
forall a b. (a -> b) -> a -> b
$ do
    Word32
result <- IO Word32
secret_error_get_quark
    Word32 -> IO Word32
forall (m :: * -> *) a. Monad m => a -> m a
return Word32
result