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

module GI.Soup.Objects.AuthDomainDigest
    ( 

-- * Exported types
    AuthDomainDigest(..)                    ,
    IsAuthDomainDigest                      ,
    toAuthDomainDigest                      ,
    noAuthDomainDigest                      ,


 -- * Methods
-- ** encodePassword #method:encodePassword#
    authDomainDigestEncodePassword          ,




 -- * Properties
-- ** authCallback #attr:authCallback#
    AuthDomainDigestAuthCallbackPropertyInfo,
    authDomainDigestAuthCallback            ,
    constructAuthDomainDigestAuthCallback   ,
    getAuthDomainDigestAuthCallback         ,
    setAuthDomainDigestAuthCallback         ,


-- ** authData #attr:authData#
    AuthDomainDigestAuthDataPropertyInfo    ,
    authDomainDigestAuthData                ,
    constructAuthDomainDigestAuthData       ,
    getAuthDomainDigestAuthData             ,
    setAuthDomainDigestAuthData             ,




    ) 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.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.Soup.Objects.AuthDomain as Soup.AuthDomain

newtype AuthDomainDigest = AuthDomainDigest (ManagedPtr AuthDomainDigest)
foreign import ccall "soup_auth_domain_digest_get_type"
    c_soup_auth_domain_digest_get_type :: IO GType

instance GObject AuthDomainDigest where
    gobjectType _ = c_soup_auth_domain_digest_get_type
    

class GObject o => IsAuthDomainDigest o
#if MIN_VERSION_base(4,9,0)
instance {-# OVERLAPPABLE #-} (GObject a, O.UnknownAncestorError AuthDomainDigest a) =>
    IsAuthDomainDigest a
#endif
instance IsAuthDomainDigest AuthDomainDigest
instance Soup.AuthDomain.IsAuthDomain AuthDomainDigest
instance GObject.Object.IsObject AuthDomainDigest

toAuthDomainDigest :: IsAuthDomainDigest o => o -> IO AuthDomainDigest
toAuthDomainDigest = unsafeCastTo AuthDomainDigest

noAuthDomainDigest :: Maybe AuthDomainDigest
noAuthDomainDigest = Nothing

type family ResolveAuthDomainDigestMethod (t :: Symbol) (o :: *) :: * where
    ResolveAuthDomainDigestMethod "accepts" o = Soup.AuthDomain.AuthDomainAcceptsMethodInfo
    ResolveAuthDomainDigestMethod "addPath" o = Soup.AuthDomain.AuthDomainAddPathMethodInfo
    ResolveAuthDomainDigestMethod "basicSetAuthCallback" o = Soup.AuthDomain.AuthDomainBasicSetAuthCallbackMethodInfo
    ResolveAuthDomainDigestMethod "bindProperty" o = GObject.Object.ObjectBindPropertyMethodInfo
    ResolveAuthDomainDigestMethod "bindPropertyFull" o = GObject.Object.ObjectBindPropertyFullMethodInfo
    ResolveAuthDomainDigestMethod "challenge" o = Soup.AuthDomain.AuthDomainChallengeMethodInfo
    ResolveAuthDomainDigestMethod "checkPassword" o = Soup.AuthDomain.AuthDomainCheckPasswordMethodInfo
    ResolveAuthDomainDigestMethod "covers" o = Soup.AuthDomain.AuthDomainCoversMethodInfo
    ResolveAuthDomainDigestMethod "digestSetAuthCallback" o = Soup.AuthDomain.AuthDomainDigestSetAuthCallbackMethodInfo
    ResolveAuthDomainDigestMethod "forceFloating" o = GObject.Object.ObjectForceFloatingMethodInfo
    ResolveAuthDomainDigestMethod "freezeNotify" o = GObject.Object.ObjectFreezeNotifyMethodInfo
    ResolveAuthDomainDigestMethod "isFloating" o = GObject.Object.ObjectIsFloatingMethodInfo
    ResolveAuthDomainDigestMethod "notify" o = GObject.Object.ObjectNotifyMethodInfo
    ResolveAuthDomainDigestMethod "notifyByPspec" o = GObject.Object.ObjectNotifyByPspecMethodInfo
    ResolveAuthDomainDigestMethod "ref" o = GObject.Object.ObjectRefMethodInfo
    ResolveAuthDomainDigestMethod "refSink" o = GObject.Object.ObjectRefSinkMethodInfo
    ResolveAuthDomainDigestMethod "removePath" o = Soup.AuthDomain.AuthDomainRemovePathMethodInfo
    ResolveAuthDomainDigestMethod "replaceData" o = GObject.Object.ObjectReplaceDataMethodInfo
    ResolveAuthDomainDigestMethod "replaceQdata" o = GObject.Object.ObjectReplaceQdataMethodInfo
    ResolveAuthDomainDigestMethod "runDispose" o = GObject.Object.ObjectRunDisposeMethodInfo
    ResolveAuthDomainDigestMethod "stealData" o = GObject.Object.ObjectStealDataMethodInfo
    ResolveAuthDomainDigestMethod "stealQdata" o = GObject.Object.ObjectStealQdataMethodInfo
    ResolveAuthDomainDigestMethod "thawNotify" o = GObject.Object.ObjectThawNotifyMethodInfo
    ResolveAuthDomainDigestMethod "tryGenericAuthCallback" o = Soup.AuthDomain.AuthDomainTryGenericAuthCallbackMethodInfo
    ResolveAuthDomainDigestMethod "unref" o = GObject.Object.ObjectUnrefMethodInfo
    ResolveAuthDomainDigestMethod "watchClosure" o = GObject.Object.ObjectWatchClosureMethodInfo
    ResolveAuthDomainDigestMethod "getData" o = GObject.Object.ObjectGetDataMethodInfo
    ResolveAuthDomainDigestMethod "getProperty" o = GObject.Object.ObjectGetPropertyMethodInfo
    ResolveAuthDomainDigestMethod "getQdata" o = GObject.Object.ObjectGetQdataMethodInfo
    ResolveAuthDomainDigestMethod "getRealm" o = Soup.AuthDomain.AuthDomainGetRealmMethodInfo
    ResolveAuthDomainDigestMethod "setData" o = GObject.Object.ObjectSetDataMethodInfo
    ResolveAuthDomainDigestMethod "setFilter" o = Soup.AuthDomain.AuthDomainSetFilterMethodInfo
    ResolveAuthDomainDigestMethod "setGenericAuthCallback" o = Soup.AuthDomain.AuthDomainSetGenericAuthCallbackMethodInfo
    ResolveAuthDomainDigestMethod "setProperty" o = GObject.Object.ObjectSetPropertyMethodInfo
    ResolveAuthDomainDigestMethod l o = O.MethodResolutionFailed l o

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

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

-- VVV Prop "auth-callback"
   -- Type: TBasicType TPtr
   -- Flags: [PropertyReadable,PropertyWritable]
   -- Nullable: (Nothing,Nothing)

getAuthDomainDigestAuthCallback :: (MonadIO m, IsAuthDomainDigest o) => o -> m (Ptr ())
getAuthDomainDigestAuthCallback obj = liftIO $ getObjectPropertyPtr obj "auth-callback"

setAuthDomainDigestAuthCallback :: (MonadIO m, IsAuthDomainDigest o) => o -> Ptr () -> m ()
setAuthDomainDigestAuthCallback obj val = liftIO $ setObjectPropertyPtr obj "auth-callback" val

constructAuthDomainDigestAuthCallback :: (IsAuthDomainDigest o) => Ptr () -> IO (GValueConstruct o)
constructAuthDomainDigestAuthCallback val = constructObjectPropertyPtr "auth-callback" val

data AuthDomainDigestAuthCallbackPropertyInfo
instance AttrInfo AuthDomainDigestAuthCallbackPropertyInfo where
    type AttrAllowedOps AuthDomainDigestAuthCallbackPropertyInfo = '[ 'AttrSet, 'AttrConstruct, 'AttrGet]
    type AttrSetTypeConstraint AuthDomainDigestAuthCallbackPropertyInfo = (~) (Ptr ())
    type AttrBaseTypeConstraint AuthDomainDigestAuthCallbackPropertyInfo = IsAuthDomainDigest
    type AttrGetType AuthDomainDigestAuthCallbackPropertyInfo = (Ptr ())
    type AttrLabel AuthDomainDigestAuthCallbackPropertyInfo = "auth-callback"
    type AttrOrigin AuthDomainDigestAuthCallbackPropertyInfo = AuthDomainDigest
    attrGet _ = getAuthDomainDigestAuthCallback
    attrSet _ = setAuthDomainDigestAuthCallback
    attrConstruct _ = constructAuthDomainDigestAuthCallback
    attrClear _ = undefined

-- VVV Prop "auth-data"
   -- Type: TBasicType TPtr
   -- Flags: [PropertyReadable,PropertyWritable]
   -- Nullable: (Nothing,Nothing)

getAuthDomainDigestAuthData :: (MonadIO m, IsAuthDomainDigest o) => o -> m (Ptr ())
getAuthDomainDigestAuthData obj = liftIO $ getObjectPropertyPtr obj "auth-data"

setAuthDomainDigestAuthData :: (MonadIO m, IsAuthDomainDigest o) => o -> Ptr () -> m ()
setAuthDomainDigestAuthData obj val = liftIO $ setObjectPropertyPtr obj "auth-data" val

constructAuthDomainDigestAuthData :: (IsAuthDomainDigest o) => Ptr () -> IO (GValueConstruct o)
constructAuthDomainDigestAuthData val = constructObjectPropertyPtr "auth-data" val

data AuthDomainDigestAuthDataPropertyInfo
instance AttrInfo AuthDomainDigestAuthDataPropertyInfo where
    type AttrAllowedOps AuthDomainDigestAuthDataPropertyInfo = '[ 'AttrSet, 'AttrConstruct, 'AttrGet]
    type AttrSetTypeConstraint AuthDomainDigestAuthDataPropertyInfo = (~) (Ptr ())
    type AttrBaseTypeConstraint AuthDomainDigestAuthDataPropertyInfo = IsAuthDomainDigest
    type AttrGetType AuthDomainDigestAuthDataPropertyInfo = (Ptr ())
    type AttrLabel AuthDomainDigestAuthDataPropertyInfo = "auth-data"
    type AttrOrigin AuthDomainDigestAuthDataPropertyInfo = AuthDomainDigest
    attrGet _ = getAuthDomainDigestAuthData
    attrSet _ = setAuthDomainDigestAuthData
    attrConstruct _ = constructAuthDomainDigestAuthData
    attrClear _ = undefined

instance O.HasAttributeList AuthDomainDigest
type instance O.AttributeList AuthDomainDigest = AuthDomainDigestAttributeList
type AuthDomainDigestAttributeList = ('[ '("addPath", Soup.AuthDomain.AuthDomainAddPathPropertyInfo), '("authCallback", AuthDomainDigestAuthCallbackPropertyInfo), '("authData", AuthDomainDigestAuthDataPropertyInfo), '("filter", Soup.AuthDomain.AuthDomainFilterPropertyInfo), '("filterData", Soup.AuthDomain.AuthDomainFilterDataPropertyInfo), '("genericAuthCallback", Soup.AuthDomain.AuthDomainGenericAuthCallbackPropertyInfo), '("genericAuthData", Soup.AuthDomain.AuthDomainGenericAuthDataPropertyInfo), '("proxy", Soup.AuthDomain.AuthDomainProxyPropertyInfo), '("realm", Soup.AuthDomain.AuthDomainRealmPropertyInfo), '("removePath", Soup.AuthDomain.AuthDomainRemovePathPropertyInfo)] :: [(Symbol, *)])

authDomainDigestAuthCallback :: AttrLabelProxy "authCallback"
authDomainDigestAuthCallback = AttrLabelProxy

authDomainDigestAuthData :: AttrLabelProxy "authData"
authDomainDigestAuthData = AttrLabelProxy

type instance O.SignalList AuthDomainDigest = AuthDomainDigestSignalList
type AuthDomainDigestSignalList = ('[ '("notify", GObject.Object.ObjectNotifySignalInfo)] :: [(Symbol, *)])

-- method AuthDomainDigest::encode_password
-- method type : MemberFunction
-- Args : [Arg {argCName = "username", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a username", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "realm", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "an auth realm name", 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 password for @username in @realm", 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 "soup_auth_domain_digest_encode_password" soup_auth_domain_digest_encode_password :: 
    CString ->                              -- username : TBasicType TUTF8
    CString ->                              -- realm : TBasicType TUTF8
    CString ->                              -- password : TBasicType TUTF8
    IO CString

{- |
Encodes the username\/realm\/password triplet for Digest
authentication. (That is, it returns a stringified MD5 hash of
/@username@/, /@realm@/, and /@password@/ concatenated together). This is
the form that is needed as the return value of
'GI.Soup.Objects.AuthDomainDigest.AuthDomainDigest'\'s auth handler.

For security reasons, you should store the encoded hash, rather
than storing the cleartext password itself and calling this method
only when you need to verify it. This way, if your server is
compromised, the attackers will not gain access to cleartext
passwords which might also be usable at other sites. (Note also
that the encoded password returned by this method is identical to
the encoded password stored in an Apache .htdigest file.)
-}
authDomainDigestEncodePassword ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    T.Text
    {- ^ /@username@/: a username -}
    -> T.Text
    {- ^ /@realm@/: an auth realm name -}
    -> T.Text
    {- ^ /@password@/: the password for /@username@/ in /@realm@/ -}
    -> m T.Text
    {- ^ __Returns:__ the encoded password -}
authDomainDigestEncodePassword username realm password = liftIO $ do
    username' <- textToCString username
    realm' <- textToCString realm
    password' <- textToCString password
    result <- soup_auth_domain_digest_encode_password username' realm' password'
    checkUnexpectedReturnNULL "authDomainDigestEncodePassword" result
    result' <- cstringToText result
    freeMem result
    freeMem username'
    freeMem realm'
    freeMem password'
    return result'