{-# LANGUAGE TypeApplications #-}


-- | Copyright  : Will Thompson and Iñaki García Etxebarria
-- License    : LGPL-2.1
-- Maintainer : Iñaki García Etxebarria
-- 
-- HTTP client-side authentication handler.
-- 
-- t'GI.Soup.Objects.AuthManager.AuthManager' is the [iface/@sessionFeature@/] that handles HTTP
-- authentication for a [class/@session@/].
-- 
-- A t'GI.Soup.Objects.AuthManager.AuthManager' is added to the session by default, and normally
-- you don\'t need to worry about it at all. However, if you want to
-- disable HTTP authentication, you can remove the feature from the
-- session with [method/@session@/.remove_feature_by_type] or disable it on
-- individual requests with [method/@message@/.disable_feature].
-- 
-- You can use this with [method/@session@/.remove_feature_by_type] or
-- [method/@message@/.disable_feature].
-- 
-- (Although this type has only been publicly visible since libsoup 2.42, it has
-- always existed in the background, and you can use @g_type_from_name
-- (\"SoupAuthManager\")@ to get its [alias/@gLib@/.Type] in earlier releases.)

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

module GI.Soup.Objects.AuthManager
    ( 

-- * Exported types
    AuthManager(..)                         ,
    IsAuthManager                           ,
    toAuthManager                           ,


 -- * Methods
-- | 
-- 
--  === __Click to display all available methods, including inherited ones__
-- ==== Methods
-- [bindProperty]("GI.GObject.Objects.Object#g:method:bindProperty"), [bindPropertyFull]("GI.GObject.Objects.Object#g:method:bindPropertyFull"), [clearCachedCredentials]("GI.Soup.Objects.AuthManager#g:method:clearCachedCredentials"), [forceFloating]("GI.GObject.Objects.Object#g:method:forceFloating"), [freezeNotify]("GI.GObject.Objects.Object#g:method:freezeNotify"), [getv]("GI.GObject.Objects.Object#g:method:getv"), [isFloating]("GI.GObject.Objects.Object#g:method:isFloating"), [notify]("GI.GObject.Objects.Object#g:method:notify"), [notifyByPspec]("GI.GObject.Objects.Object#g:method:notifyByPspec"), [ref]("GI.GObject.Objects.Object#g:method:ref"), [refSink]("GI.GObject.Objects.Object#g:method:refSink"), [runDispose]("GI.GObject.Objects.Object#g:method:runDispose"), [stealData]("GI.GObject.Objects.Object#g:method:stealData"), [stealQdata]("GI.GObject.Objects.Object#g:method:stealQdata"), [thawNotify]("GI.GObject.Objects.Object#g:method:thawNotify"), [unref]("GI.GObject.Objects.Object#g:method:unref"), [useAuth]("GI.Soup.Objects.AuthManager#g:method:useAuth"), [watchClosure]("GI.GObject.Objects.Object#g:method:watchClosure").
-- 
-- ==== Getters
-- [getData]("GI.GObject.Objects.Object#g:method:getData"), [getProperty]("GI.GObject.Objects.Object#g:method:getProperty"), [getQdata]("GI.GObject.Objects.Object#g:method:getQdata").
-- 
-- ==== Setters
-- [setData]("GI.GObject.Objects.Object#g:method:setData"), [setDataFull]("GI.GObject.Objects.Object#g:method:setDataFull"), [setProperty]("GI.GObject.Objects.Object#g:method:setProperty").

#if defined(ENABLE_OVERLOADING)
    ResolveAuthManagerMethod                ,
#endif

-- ** clearCachedCredentials #method:clearCachedCredentials#

#if defined(ENABLE_OVERLOADING)
    AuthManagerClearCachedCredentialsMethodInfo,
#endif
    authManagerClearCachedCredentials       ,


-- ** useAuth #method:useAuth#

#if defined(ENABLE_OVERLOADING)
    AuthManagerUseAuthMethodInfo            ,
#endif
    authManagerUseAuth                      ,




    ) 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 GI.GLib.Structs.Uri as GLib.Uri
import qualified GI.GObject.Objects.Object as GObject.Object
import {-# SOURCE #-} qualified GI.Soup.Interfaces.SessionFeature as Soup.SessionFeature
import {-# SOURCE #-} qualified GI.Soup.Objects.Auth as Soup.Auth

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

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

foreign import ccall "soup_auth_manager_get_type"
    c_soup_auth_manager_get_type :: IO B.Types.GType

instance B.Types.TypedObject AuthManager where
    glibType :: IO GType
glibType = IO GType
c_soup_auth_manager_get_type

instance B.Types.GObject AuthManager

-- | Type class for types which can be safely cast to `AuthManager`, for instance with `toAuthManager`.
class (SP.GObject o, O.IsDescendantOf AuthManager o) => IsAuthManager o
instance (SP.GObject o, O.IsDescendantOf AuthManager o) => IsAuthManager o

instance O.HasParentTypes AuthManager
type instance O.ParentTypes AuthManager = '[GObject.Object.Object, Soup.SessionFeature.SessionFeature]

-- | Cast to `AuthManager`, for types for which this is known to be safe. For general casts, use `Data.GI.Base.ManagedPtr.castTo`.
toAuthManager :: (MIO.MonadIO m, IsAuthManager o) => o -> m AuthManager
toAuthManager :: forall (m :: * -> *) o.
(MonadIO m, IsAuthManager o) =>
o -> m AuthManager
toAuthManager = IO AuthManager -> m AuthManager
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
MIO.liftIO (IO AuthManager -> m AuthManager)
-> (o -> IO AuthManager) -> o -> m AuthManager
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ManagedPtr AuthManager -> AuthManager) -> o -> IO AuthManager
forall o o'.
(HasCallStack, ManagedPtrNewtype o, TypedObject o,
 ManagedPtrNewtype o', TypedObject o') =>
(ManagedPtr o' -> o') -> o -> IO o'
B.ManagedPtr.unsafeCastTo ManagedPtr AuthManager -> AuthManager
AuthManager

-- | Convert 'AuthManager' 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 AuthManager) where
    gvalueGType_ :: IO GType
gvalueGType_ = IO GType
c_soup_auth_manager_get_type
    gvalueSet_ :: Ptr GValue -> Maybe AuthManager -> IO ()
gvalueSet_ Ptr GValue
gv Maybe AuthManager
P.Nothing = Ptr GValue -> Ptr AuthManager -> IO ()
forall a. GObject a => Ptr GValue -> Ptr a -> IO ()
B.GValue.set_object Ptr GValue
gv (Ptr AuthManager
forall a. Ptr a
FP.nullPtr :: FP.Ptr AuthManager)
    gvalueSet_ Ptr GValue
gv (P.Just AuthManager
obj) = AuthManager -> (Ptr AuthManager -> IO ()) -> IO ()
forall a c.
(HasCallStack, ManagedPtrNewtype a) =>
a -> (Ptr a -> IO c) -> IO c
B.ManagedPtr.withManagedPtr AuthManager
obj (Ptr GValue -> Ptr AuthManager -> IO ()
forall a. GObject a => Ptr GValue -> Ptr a -> IO ()
B.GValue.set_object Ptr GValue
gv)
    gvalueGet_ :: Ptr GValue -> IO (Maybe AuthManager)
gvalueGet_ Ptr GValue
gv = do
        Ptr AuthManager
ptr <- Ptr GValue -> IO (Ptr AuthManager)
forall a. GObject a => Ptr GValue -> IO (Ptr a)
B.GValue.get_object Ptr GValue
gv :: IO (FP.Ptr AuthManager)
        if Ptr AuthManager
ptr Ptr AuthManager -> Ptr AuthManager -> Bool
forall a. Eq a => a -> a -> Bool
/= Ptr AuthManager
forall a. Ptr a
FP.nullPtr
        then AuthManager -> Maybe AuthManager
forall a. a -> Maybe a
P.Just (AuthManager -> Maybe AuthManager)
-> IO AuthManager -> IO (Maybe AuthManager)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (ManagedPtr AuthManager -> AuthManager)
-> Ptr AuthManager -> IO AuthManager
forall a b.
(HasCallStack, GObject a, GObject b) =>
(ManagedPtr a -> a) -> Ptr b -> IO a
B.ManagedPtr.newObject ManagedPtr AuthManager -> AuthManager
AuthManager Ptr AuthManager
ptr
        else Maybe AuthManager -> IO (Maybe AuthManager)
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe AuthManager
forall a. Maybe a
P.Nothing
        
    

#if defined(ENABLE_OVERLOADING)
type family ResolveAuthManagerMethod (t :: Symbol) (o :: DK.Type) :: DK.Type where
    ResolveAuthManagerMethod "bindProperty" o = GObject.Object.ObjectBindPropertyMethodInfo
    ResolveAuthManagerMethod "bindPropertyFull" o = GObject.Object.ObjectBindPropertyFullMethodInfo
    ResolveAuthManagerMethod "clearCachedCredentials" o = AuthManagerClearCachedCredentialsMethodInfo
    ResolveAuthManagerMethod "forceFloating" o = GObject.Object.ObjectForceFloatingMethodInfo
    ResolveAuthManagerMethod "freezeNotify" o = GObject.Object.ObjectFreezeNotifyMethodInfo
    ResolveAuthManagerMethod "getv" o = GObject.Object.ObjectGetvMethodInfo
    ResolveAuthManagerMethod "isFloating" o = GObject.Object.ObjectIsFloatingMethodInfo
    ResolveAuthManagerMethod "notify" o = GObject.Object.ObjectNotifyMethodInfo
    ResolveAuthManagerMethod "notifyByPspec" o = GObject.Object.ObjectNotifyByPspecMethodInfo
    ResolveAuthManagerMethod "ref" o = GObject.Object.ObjectRefMethodInfo
    ResolveAuthManagerMethod "refSink" o = GObject.Object.ObjectRefSinkMethodInfo
    ResolveAuthManagerMethod "runDispose" o = GObject.Object.ObjectRunDisposeMethodInfo
    ResolveAuthManagerMethod "stealData" o = GObject.Object.ObjectStealDataMethodInfo
    ResolveAuthManagerMethod "stealQdata" o = GObject.Object.ObjectStealQdataMethodInfo
    ResolveAuthManagerMethod "thawNotify" o = GObject.Object.ObjectThawNotifyMethodInfo
    ResolveAuthManagerMethod "unref" o = GObject.Object.ObjectUnrefMethodInfo
    ResolveAuthManagerMethod "useAuth" o = AuthManagerUseAuthMethodInfo
    ResolveAuthManagerMethod "watchClosure" o = GObject.Object.ObjectWatchClosureMethodInfo
    ResolveAuthManagerMethod "getData" o = GObject.Object.ObjectGetDataMethodInfo
    ResolveAuthManagerMethod "getProperty" o = GObject.Object.ObjectGetPropertyMethodInfo
    ResolveAuthManagerMethod "getQdata" o = GObject.Object.ObjectGetQdataMethodInfo
    ResolveAuthManagerMethod "setData" o = GObject.Object.ObjectSetDataMethodInfo
    ResolveAuthManagerMethod "setDataFull" o = GObject.Object.ObjectSetDataFullMethodInfo
    ResolveAuthManagerMethod "setProperty" o = GObject.Object.ObjectSetPropertyMethodInfo
    ResolveAuthManagerMethod l o = O.MethodResolutionFailed l o

instance (info ~ ResolveAuthManagerMethod t AuthManager, O.OverloadedMethod info AuthManager p) => OL.IsLabel t (AuthManager -> p) where
#if MIN_VERSION_base(4,10,0)
    fromLabel = O.overloadedMethod @info
#else
    fromLabel _ = O.overloadedMethod @info
#endif

#if MIN_VERSION_base(4,13,0)
instance (info ~ ResolveAuthManagerMethod t AuthManager, O.OverloadedMethod info AuthManager p, R.HasField t AuthManager p) => R.HasField t AuthManager p where
    getField = O.overloadedMethod @info

#endif

instance (info ~ ResolveAuthManagerMethod t AuthManager, O.OverloadedMethodInfo info AuthManager) => OL.IsLabel t (O.MethodProxy info AuthManager) where
#if MIN_VERSION_base(4,10,0)
    fromLabel = O.MethodProxy
#else
    fromLabel _ = O.MethodProxy
#endif

#endif

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

#if defined(ENABLE_OVERLOADING)
#endif

#if defined(ENABLE_OVERLOADING)
type instance O.SignalList AuthManager = AuthManagerSignalList
type AuthManagerSignalList = ('[ '("notify", GObject.Object.ObjectNotifySignalInfo)] :: [(Symbol, DK.Type)])

#endif

-- method AuthManager::clear_cached_credentials
-- method type : OrdinaryMethod
-- Args: [ Arg
--           { argCName = "manager"
--           , argType =
--               TInterface Name { namespace = "Soup" , name = "AuthManager" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "a #SoupAuthManager" , sinceVersion = Nothing }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       ]
-- Lengths: []
-- returnType: Nothing
-- throws : False
-- Skip return : False

foreign import ccall "soup_auth_manager_clear_cached_credentials" soup_auth_manager_clear_cached_credentials :: 
    Ptr AuthManager ->                      -- manager : TInterface (Name {namespace = "Soup", name = "AuthManager"})
    IO ()

-- | Clear all credentials cached by /@manager@/.
authManagerClearCachedCredentials ::
    (B.CallStack.HasCallStack, MonadIO m, IsAuthManager a) =>
    a
    -- ^ /@manager@/: a t'GI.Soup.Objects.AuthManager.AuthManager'
    -> m ()
authManagerClearCachedCredentials :: forall (m :: * -> *) a.
(HasCallStack, MonadIO m, IsAuthManager a) =>
a -> m ()
authManagerClearCachedCredentials a
manager = 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
    Ptr AuthManager
manager' <- a -> IO (Ptr AuthManager)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr a
manager
    Ptr AuthManager -> IO ()
soup_auth_manager_clear_cached_credentials Ptr AuthManager
manager'
    a -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr a
manager
    () -> IO ()
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return ()

#if defined(ENABLE_OVERLOADING)
data AuthManagerClearCachedCredentialsMethodInfo
instance (signature ~ (m ()), MonadIO m, IsAuthManager a) => O.OverloadedMethod AuthManagerClearCachedCredentialsMethodInfo a signature where
    overloadedMethod = authManagerClearCachedCredentials

instance O.OverloadedMethodInfo AuthManagerClearCachedCredentialsMethodInfo a where
    overloadedMethodInfo = P.Just (O.ResolvedSymbolInfo {
        O.resolvedSymbolName = "GI.Soup.Objects.AuthManager.authManagerClearCachedCredentials",
        O.resolvedSymbolURL = "https://hackage.haskell.org/package/gi-soup-3.0.2/docs/GI-Soup-Objects-AuthManager.html#v:authManagerClearCachedCredentials"
        })


#endif

-- method AuthManager::use_auth
-- method type : OrdinaryMethod
-- Args: [ Arg
--           { argCName = "manager"
--           , argType =
--               TInterface Name { namespace = "Soup" , name = "AuthManager" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "a #SoupAuthManager" , sinceVersion = Nothing }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "uri"
--           , argType = TInterface Name { namespace = "GLib" , name = "Uri" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "the #GUri under which @auth is to be used"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "auth"
--           , argType = TInterface Name { namespace = "Soup" , name = "Auth" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "the #SoupAuth to use"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       ]
-- Lengths: []
-- returnType: Nothing
-- throws : False
-- Skip return : False

foreign import ccall "soup_auth_manager_use_auth" soup_auth_manager_use_auth :: 
    Ptr AuthManager ->                      -- manager : TInterface (Name {namespace = "Soup", name = "AuthManager"})
    Ptr GLib.Uri.Uri ->                     -- uri : TInterface (Name {namespace = "GLib", name = "Uri"})
    Ptr Soup.Auth.Auth ->                   -- auth : TInterface (Name {namespace = "Soup", name = "Auth"})
    IO ()

-- | Records that /@auth@/ is to be used under /@uri@/, as though a
-- WWW-Authenticate header had been received at that URI.
-- 
-- This can be used to \"preload\" /@manager@/\'s auth cache, to avoid an extra HTTP
-- round trip in the case where you know ahead of time that a 401 response will
-- be returned.
-- 
-- This is only useful for authentication types where the initial
-- Authorization header does not depend on any additional information
-- from the server. (Eg, Basic or NTLM, but not Digest.)
authManagerUseAuth ::
    (B.CallStack.HasCallStack, MonadIO m, IsAuthManager a, Soup.Auth.IsAuth b) =>
    a
    -- ^ /@manager@/: a t'GI.Soup.Objects.AuthManager.AuthManager'
    -> GLib.Uri.Uri
    -- ^ /@uri@/: the t'GI.GLib.Structs.Uri.Uri' under which /@auth@/ is to be used
    -> b
    -- ^ /@auth@/: the t'GI.Soup.Objects.Auth.Auth' to use
    -> m ()
authManagerUseAuth :: forall (m :: * -> *) a b.
(HasCallStack, MonadIO m, IsAuthManager a, IsAuth b) =>
a -> Uri -> b -> m ()
authManagerUseAuth a
manager Uri
uri b
auth = 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
    Ptr AuthManager
manager' <- a -> IO (Ptr AuthManager)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr a
manager
    Ptr Uri
uri' <- Uri -> IO (Ptr Uri)
forall a. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr a)
unsafeManagedPtrGetPtr Uri
uri
    Ptr Auth
auth' <- b -> IO (Ptr Auth)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr b
auth
    Ptr AuthManager -> Ptr Uri -> Ptr Auth -> IO ()
soup_auth_manager_use_auth Ptr AuthManager
manager' Ptr Uri
uri' Ptr Auth
auth'
    a -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr a
manager
    Uri -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr Uri
uri
    b -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr b
auth
    () -> IO ()
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return ()

#if defined(ENABLE_OVERLOADING)
data AuthManagerUseAuthMethodInfo
instance (signature ~ (GLib.Uri.Uri -> b -> m ()), MonadIO m, IsAuthManager a, Soup.Auth.IsAuth b) => O.OverloadedMethod AuthManagerUseAuthMethodInfo a signature where
    overloadedMethod = authManagerUseAuth

instance O.OverloadedMethodInfo AuthManagerUseAuthMethodInfo a where
    overloadedMethodInfo = P.Just (O.ResolvedSymbolInfo {
        O.resolvedSymbolName = "GI.Soup.Objects.AuthManager.authManagerUseAuth",
        O.resolvedSymbolURL = "https://hackage.haskell.org/package/gi-soup-3.0.2/docs/GI-Soup-Objects-AuthManager.html#v:authManagerUseAuth"
        })


#endif