{-# LANGUAGE TypeApplications #-}


-- | Copyright  : Will Thompson and Iñaki García Etxebarria
-- License    : LGPL-2.1
-- Maintainer : Iñaki García Etxebarria
-- 
-- A value containing a secret
-- 
-- A t'GI.Secret.Structs.Value.Value' contains a password or other secret value.
-- 
-- Use [method/@value@/.get] to get the actual secret data, such as a password.
-- The secret data is not necessarily null-terminated, unless the content type
-- is \"text\/plain\".
-- 
-- Each t'GI.Secret.Structs.Value.Value' has a content type. For passwords, this is @text\/plain@.
-- Use [method/@value@/.get_content_type] to look at the content type.
-- 
-- t'GI.Secret.Structs.Value.Value' is reference counted and immutable. The secret data is only
-- freed when all references have been released via [method/@value@/.unref].

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

module GI.Secret.Structs.Value
    ( 

-- * Exported types
    Value(..)                               ,


 -- * Methods
-- | 
-- 
--  === __Click to display all available methods, including inherited ones__
-- ==== Methods
-- [get]("GI.Secret.Structs.Value#g:method:get"), [ref]("GI.Secret.Structs.Value#g:method:ref"), [unref]("GI.Secret.Structs.Value#g:method:unref"), [unrefToPassword]("GI.Secret.Structs.Value#g:method:unrefToPassword").
-- 
-- ==== Getters
-- [getContentType]("GI.Secret.Structs.Value#g:method:getContentType"), [getText]("GI.Secret.Structs.Value#g:method:getText").
-- 
-- ==== Setters
-- /None/.

#if defined(ENABLE_OVERLOADING)
    ResolveValueMethod                      ,
#endif

-- ** get #method:get#

#if defined(ENABLE_OVERLOADING)
    ValueGetMethodInfo                      ,
#endif
    valueGet                                ,


-- ** getContentType #method:getContentType#

#if defined(ENABLE_OVERLOADING)
    ValueGetContentTypeMethodInfo           ,
#endif
    valueGetContentType                     ,


-- ** getText #method:getText#

#if defined(ENABLE_OVERLOADING)
    ValueGetTextMethodInfo                  ,
#endif
    valueGetText                            ,


-- ** new #method:new#

    valueNew                                ,


-- ** newFull #method:newFull#

    valueNewFull                            ,


-- ** ref #method:ref#

#if defined(ENABLE_OVERLOADING)
    ValueRefMethodInfo                      ,
#endif
    valueRef                                ,


-- ** unref #method:unref#

#if defined(ENABLE_OVERLOADING)
    ValueUnrefMethodInfo                    ,
#endif
    valueUnref                              ,


-- ** unrefToPassword #method:unrefToPassword#

#if defined(ENABLE_OVERLOADING)
    ValueUnrefToPasswordMethodInfo          ,
#endif
    valueUnrefToPassword                    ,




    ) 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.BasicTypes as B.Types
import qualified Data.GI.Base.ManagedPtr as B.ManagedPtr
import qualified Data.GI.Base.GArray as B.GArray
import qualified Data.GI.Base.GClosure as B.GClosure
import qualified Data.GI.Base.GError as B.GError
import qualified Data.GI.Base.GHashTable as B.GHT
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 Control.Monad.IO.Class as MIO
import qualified Data.Coerce as Coerce
import qualified Data.Text as T
import qualified Data.Kind as DK
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 GHC.Records as R
import qualified Data.Word as DW
import qualified Data.Int as DI
import qualified System.Posix.Types as SPT
import qualified Foreign.C.Types as FCT

-- Workaround for https://gitlab.haskell.org/ghc/ghc/-/issues/23392
#if MIN_VERSION_base(4,18,0)
import qualified GI.GLib.Callbacks as GLib.Callbacks

#else
import qualified GI.GLib.Callbacks as GLib.Callbacks

#endif

-- | Memory-managed wrapper type.
newtype Value = Value (SP.ManagedPtr Value)
    deriving (Value -> Value -> Bool
(Value -> Value -> Bool) -> (Value -> Value -> Bool) -> Eq Value
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Value -> Value -> Bool
== :: Value -> Value -> Bool
$c/= :: Value -> Value -> Bool
/= :: Value -> Value -> Bool
Eq)

instance SP.ManagedPtrNewtype Value where
    toManagedPtr :: Value -> ManagedPtr Value
toManagedPtr (Value ManagedPtr Value
p) = ManagedPtr Value
p

foreign import ccall "secret_value_get_type" c_secret_value_get_type :: 
    IO GType

type instance O.ParentTypes Value = '[]
instance O.HasParentTypes Value

instance B.Types.TypedObject Value where
    glibType :: IO GType
glibType = IO GType
c_secret_value_get_type

instance B.Types.GBoxed Value

-- | Convert t'Value' to and from 'Data.GI.Base.GValue.GValue'. See 'Data.GI.Base.GValue.toGValue' and 'Data.GI.Base.GValue.fromGValue'.
instance B.GValue.IsGValue (Maybe Value) where
    gvalueGType_ :: IO GType
gvalueGType_ = IO GType
c_secret_value_get_type
    gvalueSet_ :: Ptr GValue -> Maybe Value -> IO ()
gvalueSet_ Ptr GValue
gv Maybe Value
P.Nothing = Ptr GValue -> Ptr Value -> IO ()
forall a. Ptr GValue -> Ptr a -> IO ()
B.GValue.set_boxed Ptr GValue
gv (Ptr Value
forall a. Ptr a
FP.nullPtr :: FP.Ptr Value)
    gvalueSet_ Ptr GValue
gv (P.Just Value
obj) = Value -> (Ptr Value -> IO ()) -> IO ()
forall a c.
(HasCallStack, ManagedPtrNewtype a) =>
a -> (Ptr a -> IO c) -> IO c
B.ManagedPtr.withManagedPtr Value
obj (Ptr GValue -> Ptr Value -> IO ()
forall a. Ptr GValue -> Ptr a -> IO ()
B.GValue.set_boxed Ptr GValue
gv)
    gvalueGet_ :: Ptr GValue -> IO (Maybe Value)
gvalueGet_ Ptr GValue
gv = do
        ptr <- Ptr GValue -> IO (Ptr Value)
forall b. Ptr GValue -> IO (Ptr b)
B.GValue.get_boxed Ptr GValue
gv :: IO (Ptr Value)
        if ptr /= FP.nullPtr
        then P.Just <$> B.ManagedPtr.newBoxed Value ptr
        else return P.Nothing
        
    


#if defined(ENABLE_OVERLOADING)
instance O.HasAttributeList Value
type instance O.AttributeList Value = ValueAttributeList
type ValueAttributeList = ('[ ] :: [(Symbol, DK.Type)])
#endif

-- method Value::new
-- method type : Constructor
-- Args: [ Arg
--           { argCName = "secret"
--           , argType = TBasicType TUTF8
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "the secret data" , sinceVersion = Nothing }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , argCallbackUserData = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "length"
--           , argType = TBasicType TSSize
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "the length of the data"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , argCallbackUserData = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "content_type"
--           , argType = TBasicType TUTF8
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "the content type of the data"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , argCallbackUserData = False
--           , transfer = TransferNothing
--           }
--       ]
-- Lengths: []
-- returnType: Just (TInterface Name { namespace = "Secret" , name = "Value" })
-- throws : False
-- Skip return : False

foreign import ccall "secret_value_new" secret_value_new :: 
    CString ->                              -- secret : TBasicType TUTF8
    DI.Int64 ->                             -- length : TBasicType TSSize
    CString ->                              -- content_type : TBasicType TUTF8
    IO (Ptr Value)

-- | Create a t'GI.Secret.Structs.Value.Value' for the secret data passed in.
-- 
-- The secret data is copied into non-pageable \'secure\' memory.
-- 
-- If the length is less than zero, then /@secret@/ is assumed to be
-- null-terminated.
valueNew ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    T.Text
    -- ^ /@secret@/: the secret data
    -> DI.Int64
    -- ^ /@length@/: the length of the data
    -> T.Text
    -- ^ /@contentType@/: the content type of the data
    -> m Value
    -- ^ __Returns:__ the new t'GI.Secret.Structs.Value.Value'
valueNew :: forall (m :: * -> *).
(HasCallStack, MonadIO m) =>
Text -> Int64 -> Text -> m Value
valueNew Text
secret Int64
length_ Text
contentType = IO Value -> m Value
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Value -> m Value) -> IO Value -> m Value
forall a b. (a -> b) -> a -> b
$ do
    secret' <- Text -> IO CString
textToCString Text
secret
    contentType' <- textToCString contentType
    result <- secret_value_new secret' length_ contentType'
    checkUnexpectedReturnNULL "valueNew" result
    result' <- (wrapBoxed Value) result
    freeMem secret'
    freeMem contentType'
    return result'

#if defined(ENABLE_OVERLOADING)
#endif

-- method Value::new_full
-- method type : Constructor
-- Args: [ Arg
--           { argCName = "secret"
--           , argType = TBasicType TUTF8
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "the secret data" , sinceVersion = Nothing }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , argCallbackUserData = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "length"
--           , argType = TBasicType TSSize
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "the length of the data"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , argCallbackUserData = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "content_type"
--           , argType = TBasicType TUTF8
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "the content type of the data"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , argCallbackUserData = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "destroy"
--           , argType =
--               TInterface Name { namespace = "GLib" , name = "DestroyNotify" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "function to call to free the secret data"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeAsync
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , argCallbackUserData = False
--           , transfer = TransferNothing
--           }
--       ]
-- Lengths: []
-- returnType: Just (TInterface Name { namespace = "Secret" , name = "Value" })
-- throws : False
-- Skip return : False

foreign import ccall "secret_value_new_full" secret_value_new_full :: 
    CString ->                              -- secret : TBasicType TUTF8
    DI.Int64 ->                             -- length : TBasicType TSSize
    CString ->                              -- content_type : TBasicType TUTF8
    FunPtr GLib.Callbacks.C_DestroyNotify -> -- destroy : TInterface (Name {namespace = "GLib", name = "DestroyNotify"})
    IO (Ptr Value)

-- | Create a t'GI.Secret.Structs.Value.Value' for the secret data passed in.
-- 
-- The secret data is not copied, and will later be freed with the /@destroy@/
-- function.
-- 
-- If the length is less than zero, then /@secret@/ is assumed to be
-- null-terminated.
valueNewFull ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    T.Text
    -- ^ /@secret@/: the secret data
    -> DI.Int64
    -- ^ /@length@/: the length of the data
    -> T.Text
    -- ^ /@contentType@/: the content type of the data
    -> GLib.Callbacks.DestroyNotify
    -- ^ /@destroy@/: function to call to free the secret data
    -> m Value
    -- ^ __Returns:__ the new t'GI.Secret.Structs.Value.Value'
valueNewFull :: forall (m :: * -> *).
(HasCallStack, MonadIO m) =>
Text -> Int64 -> Text -> DestroyNotify -> m Value
valueNewFull Text
secret Int64
length_ Text
contentType DestroyNotify
destroy = IO Value -> m Value
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Value -> m Value) -> IO Value -> m Value
forall a b. (a -> b) -> a -> b
$ do
    secret' <- Text -> IO CString
textToCString Text
secret
    contentType' <- textToCString contentType
    ptrdestroy <- callocMem :: IO (Ptr (FunPtr GLib.Callbacks.C_DestroyNotify))
    destroy' <- GLib.Callbacks.mk_DestroyNotify (GLib.Callbacks.wrap_DestroyNotify (Just ptrdestroy) destroy)
    poke ptrdestroy destroy'
    result <- secret_value_new_full secret' length_ contentType' destroy'
    checkUnexpectedReturnNULL "valueNewFull" result
    result' <- (wrapBoxed Value) result
    freeMem secret'
    freeMem contentType'
    return result'

#if defined(ENABLE_OVERLOADING)
#endif

-- method Value::get
-- method type : OrdinaryMethod
-- Args: [ Arg
--           { argCName = "value"
--           , argType =
--               TInterface Name { namespace = "Secret" , name = "Value" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "the value" , sinceVersion = Nothing }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , argCallbackUserData = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "length"
--           , argType = TBasicType TSize
--           , direction = DirectionOut
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "the length of the secret"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , argCallbackUserData = False
--           , transfer = TransferEverything
--           }
--       ]
-- Lengths: [ Arg
--              { argCName = "length"
--              , argType = TBasicType TSize
--              , direction = DirectionOut
--              , mayBeNull = False
--              , argDoc =
--                  Documentation
--                    { rawDocText = Just "the length of the secret"
--                    , sinceVersion = Nothing
--                    }
--              , argScope = ScopeTypeInvalid
--              , argClosure = -1
--              , argDestroy = -1
--              , argCallerAllocates = False
--              , argCallbackUserData = False
--              , transfer = TransferEverything
--              }
--          ]
-- returnType: Just (TCArray False (-1) 1 (TBasicType TUInt8))
-- throws : False
-- Skip return : False

foreign import ccall "secret_value_get" secret_value_get :: 
    Ptr Value ->                            -- value : TInterface (Name {namespace = "Secret", name = "Value"})
    Ptr FCT.CSize ->                        -- length : TBasicType TSize
    IO (Ptr Word8)

-- | Get the secret data in the t'GI.Secret.Structs.Value.Value'.
-- 
-- The value is not necessarily null-terminated unless it was created with
-- [ctor/@value@/.new] or a null-terminated string was passed to
-- [ctor/@value@/.new_full].
valueGet ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    Value
    -- ^ /@value@/: the value
    -> m ByteString
    -- ^ __Returns:__ the secret data
valueGet :: forall (m :: * -> *).
(HasCallStack, MonadIO m) =>
Value -> m ByteString
valueGet Value
value = IO ByteString -> m ByteString
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO ByteString -> m ByteString) -> IO ByteString -> m ByteString
forall a b. (a -> b) -> a -> b
$ do
    value' <- Value -> IO (Ptr Value)
forall a. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr a)
unsafeManagedPtrGetPtr Value
value
    length_ <- allocMem :: IO (Ptr FCT.CSize)
    result <- secret_value_get value' length_
    length_' <- peek length_
    checkUnexpectedReturnNULL "valueGet" result
    result' <- (unpackByteStringWithLength length_') result
    touchManagedPtr value
    freeMem length_
    return result'

#if defined(ENABLE_OVERLOADING)
data ValueGetMethodInfo
instance (signature ~ (m ByteString), MonadIO m) => O.OverloadedMethod ValueGetMethodInfo Value signature where
    overloadedMethod :: Value -> signature
overloadedMethod = Value -> signature
Value -> m ByteString
forall (m :: * -> *).
(HasCallStack, MonadIO m) =>
Value -> m ByteString
valueGet

instance O.OverloadedMethodInfo ValueGetMethodInfo Value where
    overloadedMethodInfo :: Maybe ResolvedSymbolInfo
overloadedMethodInfo = ResolvedSymbolInfo -> Maybe ResolvedSymbolInfo
forall a. a -> Maybe a
P.Just (O.ResolvedSymbolInfo {
        resolvedSymbolName :: Text
O.resolvedSymbolName = Text
"GI.Secret.Structs.Value.valueGet",
        resolvedSymbolURL :: Text
O.resolvedSymbolURL = Text
"https://hackage.haskell.org/package/gi-secret-0.0.20/docs/GI-Secret-Structs-Value.html#v:valueGet"
        })


#endif

-- method Value::get_content_type
-- method type : OrdinaryMethod
-- Args: [ Arg
--           { argCName = "value"
--           , argType =
--               TInterface Name { namespace = "Secret" , name = "Value" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "the value" , sinceVersion = Nothing }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , argCallbackUserData = False
--           , transfer = TransferNothing
--           }
--       ]
-- Lengths: []
-- returnType: Just (TBasicType TUTF8)
-- throws : False
-- Skip return : False

foreign import ccall "secret_value_get_content_type" secret_value_get_content_type :: 
    Ptr Value ->                            -- value : TInterface (Name {namespace = "Secret", name = "Value"})
    IO CString

-- | Get the content type of the secret value, such as
-- @text\/plain@.
valueGetContentType ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    Value
    -- ^ /@value@/: the value
    -> m T.Text
    -- ^ __Returns:__ the content type
valueGetContentType :: forall (m :: * -> *). (HasCallStack, MonadIO m) => Value -> m Text
valueGetContentType Value
value = IO Text -> m Text
forall a. IO a -> m a
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
    value' <- Value -> IO (Ptr Value)
forall a. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr a)
unsafeManagedPtrGetPtr Value
value
    result <- secret_value_get_content_type value'
    checkUnexpectedReturnNULL "valueGetContentType" result
    result' <- cstringToText result
    touchManagedPtr value
    return result'

#if defined(ENABLE_OVERLOADING)
data ValueGetContentTypeMethodInfo
instance (signature ~ (m T.Text), MonadIO m) => O.OverloadedMethod ValueGetContentTypeMethodInfo Value signature where
    overloadedMethod :: Value -> signature
overloadedMethod = Value -> signature
Value -> m Text
forall (m :: * -> *). (HasCallStack, MonadIO m) => Value -> m Text
valueGetContentType

instance O.OverloadedMethodInfo ValueGetContentTypeMethodInfo Value where
    overloadedMethodInfo :: Maybe ResolvedSymbolInfo
overloadedMethodInfo = ResolvedSymbolInfo -> Maybe ResolvedSymbolInfo
forall a. a -> Maybe a
P.Just (O.ResolvedSymbolInfo {
        resolvedSymbolName :: Text
O.resolvedSymbolName = Text
"GI.Secret.Structs.Value.valueGetContentType",
        resolvedSymbolURL :: Text
O.resolvedSymbolURL = Text
"https://hackage.haskell.org/package/gi-secret-0.0.20/docs/GI-Secret-Structs-Value.html#v:valueGetContentType"
        })


#endif

-- method Value::get_text
-- method type : OrdinaryMethod
-- Args: [ Arg
--           { argCName = "value"
--           , argType =
--               TInterface Name { namespace = "Secret" , name = "Value" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "the value" , sinceVersion = Nothing }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , argCallbackUserData = False
--           , transfer = TransferNothing
--           }
--       ]
-- Lengths: []
-- returnType: Just (TBasicType TUTF8)
-- throws : False
-- Skip return : False

foreign import ccall "secret_value_get_text" secret_value_get_text :: 
    Ptr Value ->                            -- value : TInterface (Name {namespace = "Secret", name = "Value"})
    IO CString

-- | Get the secret data in the t'GI.Secret.Structs.Value.Value' if it contains a textual
-- value.
-- 
-- The content type must be @text\/plain@.
valueGetText ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    Value
    -- ^ /@value@/: the value
    -> m (Maybe T.Text)
    -- ^ __Returns:__ the content type
valueGetText :: forall (m :: * -> *).
(HasCallStack, MonadIO m) =>
Value -> m (Maybe Text)
valueGetText Value
value = IO (Maybe Text) -> m (Maybe Text)
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (Maybe Text) -> m (Maybe Text))
-> IO (Maybe Text) -> m (Maybe Text)
forall a b. (a -> b) -> a -> b
$ do
    value' <- Value -> IO (Ptr Value)
forall a. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr a)
unsafeManagedPtrGetPtr Value
value
    result <- secret_value_get_text value'
    maybeResult <- convertIfNonNull result $ \CString
result' -> do
        result'' <- HasCallStack => CString -> IO Text
CString -> IO Text
cstringToText CString
result'
        return result''
    touchManagedPtr value
    return maybeResult

#if defined(ENABLE_OVERLOADING)
data ValueGetTextMethodInfo
instance (signature ~ (m (Maybe T.Text)), MonadIO m) => O.OverloadedMethod ValueGetTextMethodInfo Value signature where
    overloadedMethod :: Value -> signature
overloadedMethod = Value -> signature
Value -> m (Maybe Text)
forall (m :: * -> *).
(HasCallStack, MonadIO m) =>
Value -> m (Maybe Text)
valueGetText

instance O.OverloadedMethodInfo ValueGetTextMethodInfo Value where
    overloadedMethodInfo :: Maybe ResolvedSymbolInfo
overloadedMethodInfo = ResolvedSymbolInfo -> Maybe ResolvedSymbolInfo
forall a. a -> Maybe a
P.Just (O.ResolvedSymbolInfo {
        resolvedSymbolName :: Text
O.resolvedSymbolName = Text
"GI.Secret.Structs.Value.valueGetText",
        resolvedSymbolURL :: Text
O.resolvedSymbolURL = Text
"https://hackage.haskell.org/package/gi-secret-0.0.20/docs/GI-Secret-Structs-Value.html#v:valueGetText"
        })


#endif

-- method Value::ref
-- method type : OrdinaryMethod
-- Args: [ Arg
--           { argCName = "value"
--           , argType =
--               TInterface Name { namespace = "Secret" , name = "Value" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "value to reference" , sinceVersion = Nothing }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , argCallbackUserData = False
--           , transfer = TransferNothing
--           }
--       ]
-- Lengths: []
-- returnType: Just (TInterface Name { namespace = "Secret" , name = "Value" })
-- throws : False
-- Skip return : False

foreign import ccall "secret_value_ref" secret_value_ref :: 
    Ptr Value ->                            -- value : TInterface (Name {namespace = "Secret", name = "Value"})
    IO (Ptr Value)

-- | Add another reference to the t'GI.Secret.Structs.Value.Value'.
-- 
-- For each reference [method/@value@/.unref] should be called to unreference the
-- value.
valueRef ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    Value
    -- ^ /@value@/: value to reference
    -> m Value
    -- ^ __Returns:__ the value
valueRef :: forall (m :: * -> *). (HasCallStack, MonadIO m) => Value -> m Value
valueRef Value
value = IO Value -> m Value
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Value -> m Value) -> IO Value -> m Value
forall a b. (a -> b) -> a -> b
$ do
    value' <- Value -> IO (Ptr Value)
forall a. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr a)
unsafeManagedPtrGetPtr Value
value
    result <- secret_value_ref value'
    checkUnexpectedReturnNULL "valueRef" result
    result' <- (wrapBoxed Value) result
    touchManagedPtr value
    return result'

#if defined(ENABLE_OVERLOADING)
data ValueRefMethodInfo
instance (signature ~ (m Value), MonadIO m) => O.OverloadedMethod ValueRefMethodInfo Value signature where
    overloadedMethod :: Value -> signature
overloadedMethod = Value -> signature
Value -> m Value
forall (m :: * -> *). (HasCallStack, MonadIO m) => Value -> m Value
valueRef

instance O.OverloadedMethodInfo ValueRefMethodInfo Value where
    overloadedMethodInfo :: Maybe ResolvedSymbolInfo
overloadedMethodInfo = ResolvedSymbolInfo -> Maybe ResolvedSymbolInfo
forall a. a -> Maybe a
P.Just (O.ResolvedSymbolInfo {
        resolvedSymbolName :: Text
O.resolvedSymbolName = Text
"GI.Secret.Structs.Value.valueRef",
        resolvedSymbolURL :: Text
O.resolvedSymbolURL = Text
"https://hackage.haskell.org/package/gi-secret-0.0.20/docs/GI-Secret-Structs-Value.html#v:valueRef"
        })


#endif

-- method Value::unref
-- method type : OrdinaryMethod
-- Args: [ Arg
--           { argCName = "value"
--           , argType =
--               TInterface Name { namespace = "Secret" , name = "Value" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "value to unreference"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , argCallbackUserData = False
--           , transfer = TransferNothing
--           }
--       ]
-- Lengths: []
-- returnType: Nothing
-- throws : False
-- Skip return : False

foreign import ccall "secret_value_unref" secret_value_unref :: 
    Ptr Value ->                            -- value : TInterface (Name {namespace = "Secret", name = "Value"})
    IO ()

-- | Unreference a t'GI.Secret.Structs.Value.Value'.
-- 
-- When the last reference is gone, then the value will be freed.
valueUnref ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    Value
    -- ^ /@value@/: value to unreference
    -> m ()
valueUnref :: forall (m :: * -> *). (HasCallStack, MonadIO m) => Value -> m ()
valueUnref Value
value = IO () -> m ()
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$ do
    value' <- Value -> IO (Ptr Value)
forall a. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr a)
unsafeManagedPtrGetPtr Value
value
    secret_value_unref value'
    touchManagedPtr value
    return ()

#if defined(ENABLE_OVERLOADING)
data ValueUnrefMethodInfo
instance (signature ~ (m ()), MonadIO m) => O.OverloadedMethod ValueUnrefMethodInfo Value signature where
    overloadedMethod :: Value -> signature
overloadedMethod = Value -> signature
Value -> m ()
forall (m :: * -> *). (HasCallStack, MonadIO m) => Value -> m ()
valueUnref

instance O.OverloadedMethodInfo ValueUnrefMethodInfo Value where
    overloadedMethodInfo :: Maybe ResolvedSymbolInfo
overloadedMethodInfo = ResolvedSymbolInfo -> Maybe ResolvedSymbolInfo
forall a. a -> Maybe a
P.Just (O.ResolvedSymbolInfo {
        resolvedSymbolName :: Text
O.resolvedSymbolName = Text
"GI.Secret.Structs.Value.valueUnref",
        resolvedSymbolURL :: Text
O.resolvedSymbolURL = Text
"https://hackage.haskell.org/package/gi-secret-0.0.20/docs/GI-Secret-Structs-Value.html#v:valueUnref"
        })


#endif

-- method Value::unref_to_password
-- method type : OrdinaryMethod
-- Args: [ Arg
--           { argCName = "value"
--           , argType =
--               TInterface Name { namespace = "Secret" , name = "Value" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "the value" , sinceVersion = Nothing }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , argCallbackUserData = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "length"
--           , argType = TBasicType TSize
--           , direction = DirectionInout
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "the length of the secret"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , argCallbackUserData = False
--           , transfer = TransferEverything
--           }
--       ]
-- Lengths: []
-- returnType: Just (TBasicType TUTF8)
-- throws : False
-- Skip return : False

foreign import ccall "secret_value_unref_to_password" secret_value_unref_to_password :: 
    Ptr Value ->                            -- value : TInterface (Name {namespace = "Secret", name = "Value"})
    Ptr FCT.CSize ->                        -- length : TBasicType TSize
    IO CString

-- | Unreference a t'GI.Secret.Structs.Value.Value' and steal the secret data in
-- t'GI.Secret.Structs.Value.Value' as nonpageable memory.
-- 
-- /Since: 0.19.0/
valueUnrefToPassword ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    Value
    -- ^ /@value@/: the value
    -> FCT.CSize
    -- ^ /@length@/: the length of the secret
    -> m ((T.Text, FCT.CSize))
    -- ^ __Returns:__ a new password string stored in nonpageable memory
    --   which must be freed with [func/@passwordFree@/] when done
valueUnrefToPassword :: forall (m :: * -> *).
(HasCallStack, MonadIO m) =>
Value -> CSize -> m (Text, CSize)
valueUnrefToPassword Value
value CSize
length_ = IO (Text, CSize) -> m (Text, CSize)
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (Text, CSize) -> m (Text, CSize))
-> IO (Text, CSize) -> m (Text, CSize)
forall a b. (a -> b) -> a -> b
$ do
    value' <- Value -> IO (Ptr Value)
forall a. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr a)
unsafeManagedPtrGetPtr Value
value
    length_' <- allocMem :: IO (Ptr FCT.CSize)
    poke length_' length_
    result <- secret_value_unref_to_password value' length_'
    checkUnexpectedReturnNULL "valueUnrefToPassword" result
    result' <- cstringToText result
    freeMem result
    length_'' <- peek length_'
    touchManagedPtr value
    freeMem length_'
    return (result', length_'')

#if defined(ENABLE_OVERLOADING)
data ValueUnrefToPasswordMethodInfo
instance (signature ~ (FCT.CSize -> m ((T.Text, FCT.CSize))), MonadIO m) => O.OverloadedMethod ValueUnrefToPasswordMethodInfo Value signature where
    overloadedMethod :: Value -> signature
overloadedMethod = Value -> signature
Value -> CSize -> m (Text, CSize)
forall (m :: * -> *).
(HasCallStack, MonadIO m) =>
Value -> CSize -> m (Text, CSize)
valueUnrefToPassword

instance O.OverloadedMethodInfo ValueUnrefToPasswordMethodInfo Value where
    overloadedMethodInfo :: Maybe ResolvedSymbolInfo
overloadedMethodInfo = ResolvedSymbolInfo -> Maybe ResolvedSymbolInfo
forall a. a -> Maybe a
P.Just (O.ResolvedSymbolInfo {
        resolvedSymbolName :: Text
O.resolvedSymbolName = Text
"GI.Secret.Structs.Value.valueUnrefToPassword",
        resolvedSymbolURL :: Text
O.resolvedSymbolURL = Text
"https://hackage.haskell.org/package/gi-secret-0.0.20/docs/GI-Secret-Structs-Value.html#v:valueUnrefToPassword"
        })


#endif

#if defined(ENABLE_OVERLOADING)
type family ResolveValueMethod (t :: Symbol) (o :: DK.Type) :: DK.Type where
    ResolveValueMethod "get" o = ValueGetMethodInfo
    ResolveValueMethod "ref" o = ValueRefMethodInfo
    ResolveValueMethod "unref" o = ValueUnrefMethodInfo
    ResolveValueMethod "unrefToPassword" o = ValueUnrefToPasswordMethodInfo
    ResolveValueMethod "getContentType" o = ValueGetContentTypeMethodInfo
    ResolveValueMethod "getText" o = ValueGetTextMethodInfo
    ResolveValueMethod l o = O.MethodResolutionFailed l o

instance (info ~ ResolveValueMethod t Value, O.OverloadedMethod info Value p) => OL.IsLabel t (Value -> p) where
#if MIN_VERSION_base(4,10,0)
    fromLabel :: Value -> p
fromLabel = forall {k} (i :: k) o s. OverloadedMethod i o s => o -> s
forall i o s. OverloadedMethod i o s => o -> s
O.overloadedMethod @info
#else
    fromLabel _ = O.overloadedMethod @info
#endif

#if MIN_VERSION_base(4,13,0)
instance (info ~ ResolveValueMethod t Value, O.OverloadedMethod info Value p, R.HasField t Value p) => R.HasField t Value p where
    getField :: Value -> p
getField = forall {k} (i :: k) o s. OverloadedMethod i o s => o -> s
forall i o s. OverloadedMethod i o s => o -> s
O.overloadedMethod @info

#endif

instance (info ~ ResolveValueMethod t Value, O.OverloadedMethodInfo info Value) => OL.IsLabel t (O.MethodProxy info Value) where
#if MIN_VERSION_base(4,10,0)
    fromLabel :: MethodProxy info Value
fromLabel = MethodProxy info Value
forall info obj. MethodProxy info obj
O.MethodProxy
#else
    fromLabel _ = O.MethodProxy
#endif

#endif