{- |
Copyright  : Will Thompson, Iñaki García Etxebarria and Jonas Platte
License    : LGPL-2.1
Maintainer : Iñaki García Etxebarria (garetxe@gmail.com)

The 'GI.Gio.Objects.Credentials.Credentials' type is a reference-counted wrapper for native
credentials. This information is typically used for identifying,
authenticating and authorizing other processes.

Some operating systems supports looking up the credentials of the
remote peer of a communication endpoint - see e.g.
'GI.Gio.Objects.Socket.socketGetCredentials'.

Some operating systems supports securely sending and receiving
credentials over a Unix Domain Socket, see
'GI.Gio.Objects.UnixCredentialsMessage.UnixCredentialsMessage', 'GI.Gio.Objects.UnixConnection.unixConnectionSendCredentials' and
'GI.Gio.Objects.UnixConnection.unixConnectionReceiveCredentials' for details.

On Linux, the native credential type is a struct ucred - see the
unix(7) man page for details. This corresponds to
'GI.Gio.Enums.CredentialsTypeLinuxUcred'.

On FreeBSD, Debian GNU\/kFreeBSD, and GNU\/Hurd, the native
credential type is a struct cmsgcred. This corresponds
to 'GI.Gio.Enums.CredentialsTypeFreebsdCmsgcred'.

On NetBSD, the native credential type is a struct unpcbid.
This corresponds to 'GI.Gio.Enums.CredentialsTypeNetbsdUnpcbid'.

On OpenBSD, the native credential type is a struct sockpeercred.
This corresponds to 'GI.Gio.Enums.CredentialsTypeOpenbsdSockpeercred'.

On Solaris (including OpenSolaris and its derivatives), the native
credential type is a ucred_t. This corresponds to
'GI.Gio.Enums.CredentialsTypeSolarisUcred'.

/Since: 2.26/
-}

#define ENABLE_OVERLOADING \
       (!defined(__HADDOCK_VERSION__))

module GI.Gio.Objects.Credentials
    ( 

-- * Exported types
    Credentials(..)                         ,
    IsCredentials                           ,
    toCredentials                           ,
    noCredentials                           ,


 -- * Methods
-- ** getUnixPid #method:getUnixPid#

#if ENABLE_OVERLOADING
    CredentialsGetUnixPidMethodInfo         ,
#endif
    credentialsGetUnixPid                   ,


-- ** getUnixUser #method:getUnixUser#

#if ENABLE_OVERLOADING
    CredentialsGetUnixUserMethodInfo        ,
#endif
    credentialsGetUnixUser                  ,


-- ** isSameUser #method:isSameUser#

#if ENABLE_OVERLOADING
    CredentialsIsSameUserMethodInfo         ,
#endif
    credentialsIsSameUser                   ,


-- ** new #method:new#

    credentialsNew                          ,


-- ** setNative #method:setNative#

#if ENABLE_OVERLOADING
    CredentialsSetNativeMethodInfo          ,
#endif
    credentialsSetNative                    ,


-- ** setUnixUser #method:setUnixUser#

#if ENABLE_OVERLOADING
    CredentialsSetUnixUserMethodInfo        ,
#endif
    credentialsSetUnixUser                  ,


-- ** toString #method:toString#

#if ENABLE_OVERLOADING
    CredentialsToStringMethodInfo           ,
#endif
    credentialsToString                     ,




    ) 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.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.Text as T
import qualified Data.ByteString.Char8 as B
import qualified Data.Map as Map
import qualified Foreign.Ptr as FP

import qualified GI.GObject.Objects.Object as GObject.Object
import {-# SOURCE #-} qualified GI.Gio.Enums as Gio.Enums

-- | Memory-managed wrapper type.
newtype Credentials = Credentials (ManagedPtr Credentials)
foreign import ccall "g_credentials_get_type"
    c_g_credentials_get_type :: IO GType

instance GObject Credentials where
    gobjectType :: Credentials -> IO GType
gobjectType _ = IO GType
c_g_credentials_get_type
    

-- | Type class for types which can be safely cast to `Credentials`, for instance with `toCredentials`.
class GObject o => IsCredentials o
#if MIN_VERSION_base(4,9,0)
instance {-# OVERLAPPABLE #-} (GObject a, O.UnknownAncestorError Credentials a) =>
    IsCredentials a
#endif
instance IsCredentials Credentials
instance GObject.Object.IsObject Credentials

-- | Cast to `Credentials`, for types for which this is known to be safe. For general casts, use `Data.GI.Base.ManagedPtr.castTo`.
toCredentials :: (MonadIO m, IsCredentials o) => o -> m Credentials
toCredentials :: o -> m Credentials
toCredentials = IO Credentials -> m Credentials
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Credentials -> m Credentials)
-> (o -> IO Credentials) -> o -> m Credentials
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ManagedPtr Credentials -> Credentials) -> o -> IO Credentials
forall o o'.
(HasCallStack, GObject o, GObject o') =>
(ManagedPtr o' -> o') -> o -> IO o'
unsafeCastTo ManagedPtr Credentials -> Credentials
Credentials

-- | A convenience alias for `Nothing` :: `Maybe` `Credentials`.
noCredentials :: Maybe Credentials
noCredentials :: Maybe Credentials
noCredentials = Maybe Credentials
forall a. Maybe a
Nothing

#if ENABLE_OVERLOADING
type family ResolveCredentialsMethod (t :: Symbol) (o :: *) :: * where
    ResolveCredentialsMethod "bindProperty" o = GObject.Object.ObjectBindPropertyMethodInfo
    ResolveCredentialsMethod "bindPropertyFull" o = GObject.Object.ObjectBindPropertyFullMethodInfo
    ResolveCredentialsMethod "forceFloating" o = GObject.Object.ObjectForceFloatingMethodInfo
    ResolveCredentialsMethod "freezeNotify" o = GObject.Object.ObjectFreezeNotifyMethodInfo
    ResolveCredentialsMethod "getv" o = GObject.Object.ObjectGetvMethodInfo
    ResolveCredentialsMethod "isFloating" o = GObject.Object.ObjectIsFloatingMethodInfo
    ResolveCredentialsMethod "isSameUser" o = CredentialsIsSameUserMethodInfo
    ResolveCredentialsMethod "notify" o = GObject.Object.ObjectNotifyMethodInfo
    ResolveCredentialsMethod "notifyByPspec" o = GObject.Object.ObjectNotifyByPspecMethodInfo
    ResolveCredentialsMethod "ref" o = GObject.Object.ObjectRefMethodInfo
    ResolveCredentialsMethod "refSink" o = GObject.Object.ObjectRefSinkMethodInfo
    ResolveCredentialsMethod "runDispose" o = GObject.Object.ObjectRunDisposeMethodInfo
    ResolveCredentialsMethod "stealData" o = GObject.Object.ObjectStealDataMethodInfo
    ResolveCredentialsMethod "stealQdata" o = GObject.Object.ObjectStealQdataMethodInfo
    ResolveCredentialsMethod "thawNotify" o = GObject.Object.ObjectThawNotifyMethodInfo
    ResolveCredentialsMethod "toString" o = CredentialsToStringMethodInfo
    ResolveCredentialsMethod "unref" o = GObject.Object.ObjectUnrefMethodInfo
    ResolveCredentialsMethod "watchClosure" o = GObject.Object.ObjectWatchClosureMethodInfo
    ResolveCredentialsMethod "getData" o = GObject.Object.ObjectGetDataMethodInfo
    ResolveCredentialsMethod "getProperty" o = GObject.Object.ObjectGetPropertyMethodInfo
    ResolveCredentialsMethod "getQdata" o = GObject.Object.ObjectGetQdataMethodInfo
    ResolveCredentialsMethod "getUnixPid" o = CredentialsGetUnixPidMethodInfo
    ResolveCredentialsMethod "getUnixUser" o = CredentialsGetUnixUserMethodInfo
    ResolveCredentialsMethod "setData" o = GObject.Object.ObjectSetDataMethodInfo
    ResolveCredentialsMethod "setNative" o = CredentialsSetNativeMethodInfo
    ResolveCredentialsMethod "setProperty" o = GObject.Object.ObjectSetPropertyMethodInfo
    ResolveCredentialsMethod "setUnixUser" o = CredentialsSetUnixUserMethodInfo
    ResolveCredentialsMethod l o = O.MethodResolutionFailed l o

instance (info ~ ResolveCredentialsMethod t Credentials, O.MethodInfo info Credentials p) => O.IsLabelProxy t (Credentials -> p) where
    fromLabelProxy _ = O.overloadedMethod (O.MethodProxy :: O.MethodProxy info)

#if MIN_VERSION_base(4,9,0)
instance (info ~ ResolveCredentialsMethod t Credentials, O.MethodInfo info Credentials p) => O.IsLabel t (Credentials -> p) where
#if MIN_VERSION_base(4,10,0)
    fromLabel = O.overloadedMethod (O.MethodProxy :: O.MethodProxy info)
#else
    fromLabel _ = O.overloadedMethod (O.MethodProxy :: O.MethodProxy info)
#endif
#endif

#endif

#if ENABLE_OVERLOADING
instance O.HasAttributeList Credentials
type instance O.AttributeList Credentials = CredentialsAttributeList
type CredentialsAttributeList = ('[ ] :: [(Symbol, *)])
#endif

#if ENABLE_OVERLOADING
#endif

#if ENABLE_OVERLOADING
type instance O.SignalList Credentials = CredentialsSignalList
type CredentialsSignalList = ('[ '("notify", GObject.Object.ObjectNotifySignalInfo)] :: [(Symbol, *)])

#endif

-- method Credentials::new
-- method type : Constructor
-- Args : []
-- Lengths : []
-- returnType : Just (TInterface (Name {namespace = "Gio", name = "Credentials"}))
-- throws : False
-- Skip return : False

foreign import ccall "g_credentials_new" g_credentials_new :: 
    IO (Ptr Credentials)

{- |
Creates a new 'GI.Gio.Objects.Credentials.Credentials' object with credentials matching the
the current process.

/Since: 2.26/
-}
credentialsNew ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    m Credentials
    {- ^ __Returns:__ A 'GI.Gio.Objects.Credentials.Credentials'. Free with 'GI.GObject.Objects.Object.objectUnref'. -}
credentialsNew :: m Credentials
credentialsNew  = IO Credentials -> m Credentials
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Credentials -> m Credentials)
-> IO Credentials -> m Credentials
forall a b. (a -> b) -> a -> b
$ do
    Ptr Credentials
result <- IO (Ptr Credentials)
g_credentials_new
    Text -> Ptr Credentials -> IO ()
forall a. HasCallStack => Text -> Ptr a -> IO ()
checkUnexpectedReturnNULL "credentialsNew" Ptr Credentials
result
    Credentials
result' <- ((ManagedPtr Credentials -> Credentials)
-> Ptr Credentials -> IO Credentials
forall a b.
(HasCallStack, GObject a, GObject b) =>
(ManagedPtr a -> a) -> Ptr b -> IO a
wrapObject ManagedPtr Credentials -> Credentials
Credentials) Ptr Credentials
result
    Credentials -> IO Credentials
forall (m :: * -> *) a. Monad m => a -> m a
return Credentials
result'

#if ENABLE_OVERLOADING
#endif

-- method Credentials::get_unix_pid
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "credentials", argType = TInterface (Name {namespace = "Gio", name = "Credentials"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "A #GCredentials", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TBasicType TInt)
-- throws : True
-- Skip return : False

foreign import ccall "g_credentials_get_unix_pid" g_credentials_get_unix_pid :: 
    Ptr Credentials ->                      -- credentials : TInterface (Name {namespace = "Gio", name = "Credentials"})
    Ptr (Ptr GError) ->                     -- error
    IO Int32

{- |
Tries to get the UNIX process identifier from /@credentials@/. This
method is only available on UNIX platforms.

This operation can fail if 'GI.Gio.Objects.Credentials.Credentials' is not supported on the
OS or if the native credentials type does not contain information
about the UNIX process ID.

/Since: 2.36/
-}
credentialsGetUnixPid ::
    (B.CallStack.HasCallStack, MonadIO m, IsCredentials a) =>
    a
    {- ^ /@credentials@/: A 'GI.Gio.Objects.Credentials.Credentials' -}
    -> m Int32
    {- ^ __Returns:__ The UNIX process ID, or -1 if /@error@/ is set. /(Can throw 'Data.GI.Base.GError.GError')/ -}
credentialsGetUnixPid :: a -> m Int32
credentialsGetUnixPid credentials :: a
credentials = IO Int32 -> m Int32
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Int32 -> m Int32) -> IO Int32 -> m Int32
forall a b. (a -> b) -> a -> b
$ do
    Ptr Credentials
credentials' <- a -> IO (Ptr Credentials)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr a
credentials
    IO Int32 -> IO () -> IO Int32
forall a b. IO a -> IO b -> IO a
onException (do
        Int32
result <- (Ptr (Ptr GError) -> IO Int32) -> IO Int32
forall a. (Ptr (Ptr GError) -> IO a) -> IO a
propagateGError ((Ptr (Ptr GError) -> IO Int32) -> IO Int32)
-> (Ptr (Ptr GError) -> IO Int32) -> IO Int32
forall a b. (a -> b) -> a -> b
$ Ptr Credentials -> Ptr (Ptr GError) -> IO Int32
g_credentials_get_unix_pid Ptr Credentials
credentials'
        a -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr a
credentials
        Int32 -> IO Int32
forall (m :: * -> *) a. Monad m => a -> m a
return Int32
result
     ) (do
        () -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
     )

#if ENABLE_OVERLOADING
data CredentialsGetUnixPidMethodInfo
instance (signature ~ (m Int32), MonadIO m, IsCredentials a) => O.MethodInfo CredentialsGetUnixPidMethodInfo a signature where
    overloadedMethod _ = credentialsGetUnixPid

#endif

-- method Credentials::get_unix_user
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "credentials", argType = TInterface (Name {namespace = "Gio", name = "Credentials"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "A #GCredentials", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TBasicType TUInt)
-- throws : True
-- Skip return : False

foreign import ccall "g_credentials_get_unix_user" g_credentials_get_unix_user :: 
    Ptr Credentials ->                      -- credentials : TInterface (Name {namespace = "Gio", name = "Credentials"})
    Ptr (Ptr GError) ->                     -- error
    IO Word32

{- |
Tries to get the UNIX user identifier from /@credentials@/. This
method is only available on UNIX platforms.

This operation can fail if 'GI.Gio.Objects.Credentials.Credentials' is not supported on the
OS or if the native credentials type does not contain information
about the UNIX user.

/Since: 2.26/
-}
credentialsGetUnixUser ::
    (B.CallStack.HasCallStack, MonadIO m, IsCredentials a) =>
    a
    {- ^ /@credentials@/: A 'GI.Gio.Objects.Credentials.Credentials' -}
    -> m Word32
    {- ^ __Returns:__ The UNIX user identifier or -1 if /@error@/ is set. /(Can throw 'Data.GI.Base.GError.GError')/ -}
credentialsGetUnixUser :: a -> m Word32
credentialsGetUnixUser credentials :: a
credentials = 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
    Ptr Credentials
credentials' <- a -> IO (Ptr Credentials)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr a
credentials
    IO Word32 -> IO () -> IO Word32
forall a b. IO a -> IO b -> IO a
onException (do
        Word32
result <- (Ptr (Ptr GError) -> IO Word32) -> IO Word32
forall a. (Ptr (Ptr GError) -> IO a) -> IO a
propagateGError ((Ptr (Ptr GError) -> IO Word32) -> IO Word32)
-> (Ptr (Ptr GError) -> IO Word32) -> IO Word32
forall a b. (a -> b) -> a -> b
$ Ptr Credentials -> Ptr (Ptr GError) -> IO Word32
g_credentials_get_unix_user Ptr Credentials
credentials'
        a -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr a
credentials
        Word32 -> IO Word32
forall (m :: * -> *) a. Monad m => a -> m a
return Word32
result
     ) (do
        () -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
     )

#if ENABLE_OVERLOADING
data CredentialsGetUnixUserMethodInfo
instance (signature ~ (m Word32), MonadIO m, IsCredentials a) => O.MethodInfo CredentialsGetUnixUserMethodInfo a signature where
    overloadedMethod _ = credentialsGetUnixUser

#endif

-- method Credentials::is_same_user
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "credentials", argType = TInterface (Name {namespace = "Gio", name = "Credentials"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "A #GCredentials.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "other_credentials", argType = TInterface (Name {namespace = "Gio", name = "Credentials"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "A #GCredentials.", 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 "g_credentials_is_same_user" g_credentials_is_same_user :: 
    Ptr Credentials ->                      -- credentials : TInterface (Name {namespace = "Gio", name = "Credentials"})
    Ptr Credentials ->                      -- other_credentials : TInterface (Name {namespace = "Gio", name = "Credentials"})
    Ptr (Ptr GError) ->                     -- error
    IO CInt

{- |
Checks if /@credentials@/ and /@otherCredentials@/ is the same user.

This operation can fail if 'GI.Gio.Objects.Credentials.Credentials' is not supported on the
the OS.

/Since: 2.26/
-}
credentialsIsSameUser ::
    (B.CallStack.HasCallStack, MonadIO m, IsCredentials a, IsCredentials b) =>
    a
    {- ^ /@credentials@/: A 'GI.Gio.Objects.Credentials.Credentials'. -}
    -> b
    {- ^ /@otherCredentials@/: A 'GI.Gio.Objects.Credentials.Credentials'. -}
    -> m ()
    {- ^ /(Can throw 'Data.GI.Base.GError.GError')/ -}
credentialsIsSameUser :: a -> b -> m ()
credentialsIsSameUser credentials :: a
credentials otherCredentials :: b
otherCredentials = 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 Credentials
credentials' <- a -> IO (Ptr Credentials)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr a
credentials
    Ptr Credentials
otherCredentials' <- b -> IO (Ptr Credentials)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr b
otherCredentials
    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 Credentials -> Ptr Credentials -> Ptr (Ptr GError) -> IO CInt
g_credentials_is_same_user Ptr Credentials
credentials' Ptr Credentials
otherCredentials'
        a -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr a
credentials
        b -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr b
otherCredentials
        () -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
     ) (do
        () -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
     )

#if ENABLE_OVERLOADING
data CredentialsIsSameUserMethodInfo
instance (signature ~ (b -> m ()), MonadIO m, IsCredentials a, IsCredentials b) => O.MethodInfo CredentialsIsSameUserMethodInfo a signature where
    overloadedMethod _ = credentialsIsSameUser

#endif

-- method Credentials::set_native
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "credentials", argType = TInterface (Name {namespace = "Gio", name = "Credentials"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "A #GCredentials.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "native_type", argType = TInterface (Name {namespace = "Gio", name = "CredentialsType"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "The type of native credentials to set.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "native", argType = TBasicType TPtr, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "A pointer to native credentials.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Nothing
-- throws : False
-- Skip return : False

foreign import ccall "g_credentials_set_native" g_credentials_set_native :: 
    Ptr Credentials ->                      -- credentials : TInterface (Name {namespace = "Gio", name = "Credentials"})
    CUInt ->                                -- native_type : TInterface (Name {namespace = "Gio", name = "CredentialsType"})
    Ptr () ->                               -- native : TBasicType TPtr
    IO ()

{- |
Copies the native credentials of type /@nativeType@/ from /@native@/
into /@credentials@/.

It is a programming error (which will cause a warning to be
logged) to use this method if there is no 'GI.Gio.Objects.Credentials.Credentials' support for
the OS or if /@nativeType@/ isn\'t supported by the OS.

/Since: 2.26/
-}
credentialsSetNative ::
    (B.CallStack.HasCallStack, MonadIO m, IsCredentials a) =>
    a
    {- ^ /@credentials@/: A 'GI.Gio.Objects.Credentials.Credentials'. -}
    -> Gio.Enums.CredentialsType
    {- ^ /@nativeType@/: The type of native credentials to set. -}
    -> Ptr ()
    {- ^ /@native@/: A pointer to native credentials. -}
    -> m ()
credentialsSetNative :: a -> CredentialsType -> Ptr () -> m ()
credentialsSetNative credentials :: a
credentials nativeType :: CredentialsType
nativeType native :: Ptr ()
native = 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 Credentials
credentials' <- a -> IO (Ptr Credentials)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr a
credentials
    let nativeType' :: CUInt
nativeType' = (Int -> CUInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> CUInt)
-> (CredentialsType -> Int) -> CredentialsType -> CUInt
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CredentialsType -> Int
forall a. Enum a => a -> Int
fromEnum) CredentialsType
nativeType
    Ptr Credentials -> CUInt -> Ptr () -> IO ()
g_credentials_set_native Ptr Credentials
credentials' CUInt
nativeType' Ptr ()
native
    a -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr a
credentials
    () -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()

#if ENABLE_OVERLOADING
data CredentialsSetNativeMethodInfo
instance (signature ~ (Gio.Enums.CredentialsType -> Ptr () -> m ()), MonadIO m, IsCredentials a) => O.MethodInfo CredentialsSetNativeMethodInfo a signature where
    overloadedMethod _ = credentialsSetNative

#endif

-- method Credentials::set_unix_user
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "credentials", argType = TInterface (Name {namespace = "Gio", name = "Credentials"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "A #GCredentials.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "uid", argType = TBasicType TUInt, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "The UNIX user identifier to set.", 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 "g_credentials_set_unix_user" g_credentials_set_unix_user :: 
    Ptr Credentials ->                      -- credentials : TInterface (Name {namespace = "Gio", name = "Credentials"})
    Word32 ->                               -- uid : TBasicType TUInt
    Ptr (Ptr GError) ->                     -- error
    IO CInt

{- |
Tries to set the UNIX user identifier on /@credentials@/. This method
is only available on UNIX platforms.

This operation can fail if 'GI.Gio.Objects.Credentials.Credentials' is not supported on the
OS or if the native credentials type does not contain information
about the UNIX user. It can also fail if the OS does not allow the
use of \"spoofed\" credentials.

/Since: 2.26/
-}
credentialsSetUnixUser ::
    (B.CallStack.HasCallStack, MonadIO m, IsCredentials a) =>
    a
    {- ^ /@credentials@/: A 'GI.Gio.Objects.Credentials.Credentials'. -}
    -> Word32
    {- ^ /@uid@/: The UNIX user identifier to set. -}
    -> m ()
    {- ^ /(Can throw 'Data.GI.Base.GError.GError')/ -}
credentialsSetUnixUser :: a -> Word32 -> m ()
credentialsSetUnixUser credentials :: a
credentials uid :: Word32
uid = 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 Credentials
credentials' <- a -> IO (Ptr Credentials)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr a
credentials
    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 Credentials -> Word32 -> Ptr (Ptr GError) -> IO CInt
g_credentials_set_unix_user Ptr Credentials
credentials' Word32
uid
        a -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr a
credentials
        () -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
     ) (do
        () -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
     )

#if ENABLE_OVERLOADING
data CredentialsSetUnixUserMethodInfo
instance (signature ~ (Word32 -> m ()), MonadIO m, IsCredentials a) => O.MethodInfo CredentialsSetUnixUserMethodInfo a signature where
    overloadedMethod _ = credentialsSetUnixUser

#endif

-- method Credentials::to_string
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "credentials", argType = TInterface (Name {namespace = "Gio", name = "Credentials"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "A #GCredentials object.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TBasicType TUTF8)
-- throws : False
-- Skip return : False

foreign import ccall "g_credentials_to_string" g_credentials_to_string :: 
    Ptr Credentials ->                      -- credentials : TInterface (Name {namespace = "Gio", name = "Credentials"})
    IO CString

{- |
Creates a human-readable textual representation of /@credentials@/
that can be used in logging and debug messages. The format of the
returned string may change in future GLib release.

/Since: 2.26/
-}
credentialsToString ::
    (B.CallStack.HasCallStack, MonadIO m, IsCredentials a) =>
    a
    {- ^ /@credentials@/: A 'GI.Gio.Objects.Credentials.Credentials' object. -}
    -> m T.Text
    {- ^ __Returns:__ A string that should be freed with 'GI.GLib.Functions.free'. -}
credentialsToString :: a -> m Text
credentialsToString credentials :: a
credentials = 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 Credentials
credentials' <- a -> IO (Ptr Credentials)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr a
credentials
    CString
result <- Ptr Credentials -> IO CString
g_credentials_to_string Ptr Credentials
credentials'
    Text -> CString -> IO ()
forall a. HasCallStack => Text -> Ptr a -> IO ()
checkUnexpectedReturnNULL "credentialsToString" CString
result
    Text
result' <- HasCallStack => CString -> IO Text
CString -> IO Text
cstringToText CString
result
    CString -> IO ()
forall a. Ptr a -> IO ()
freeMem CString
result
    a -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr a
credentials
    Text -> IO Text
forall (m :: * -> *) a. Monad m => a -> m a
return Text
result'

#if ENABLE_OVERLOADING
data CredentialsToStringMethodInfo
instance (signature ~ (m T.Text), MonadIO m, IsCredentials a) => O.MethodInfo CredentialsToStringMethodInfo a signature where
    overloadedMethod _ = credentialsToString

#endif