{-# LANGUAGE TypeApplications #-}


-- | Copyright  : Will Thompson, Iñaki García Etxebarria and Jonas Platte
-- License    : LGPL-2.1
-- Maintainer : Iñaki García Etxebarria
-- 
-- A t'GI.Soup.Structs.ClientContext.ClientContext' provides additional information about the
-- client making a particular request. In particular, you can use
-- 'GI.Soup.Structs.ClientContext.clientContextGetAuthDomain' and
-- 'GI.Soup.Structs.ClientContext.clientContextGetAuthUser' to determine if HTTP
-- authentication was used successfully.
-- 
-- 'GI.Soup.Structs.ClientContext.clientContextGetRemoteAddress' and\/or
-- 'GI.Soup.Structs.ClientContext.clientContextGetHost' can be used to get information for
-- logging or debugging purposes. 'GI.Soup.Structs.ClientContext.clientContextGetGsocket' may
-- also be of use in some situations (eg, tracking when multiple
-- requests are made on the same connection).

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

module GI.Soup.Structs.ClientContext
    ( 

-- * Exported types
    ClientContext(..)                       ,


 -- * Methods
-- ** Overloaded methods #method:Overloaded methods#

#if defined(ENABLE_OVERLOADING)
    ResolveClientContextMethod              ,
#endif


-- ** getAddress #method:getAddress#

#if defined(ENABLE_OVERLOADING)
    ClientContextGetAddressMethodInfo       ,
#endif
    clientContextGetAddress                 ,


-- ** getAuthDomain #method:getAuthDomain#

#if defined(ENABLE_OVERLOADING)
    ClientContextGetAuthDomainMethodInfo    ,
#endif
    clientContextGetAuthDomain              ,


-- ** getAuthUser #method:getAuthUser#

#if defined(ENABLE_OVERLOADING)
    ClientContextGetAuthUserMethodInfo      ,
#endif
    clientContextGetAuthUser                ,


-- ** getGsocket #method:getGsocket#

#if defined(ENABLE_OVERLOADING)
    ClientContextGetGsocketMethodInfo       ,
#endif
    clientContextGetGsocket                 ,


-- ** getHost #method:getHost#

#if defined(ENABLE_OVERLOADING)
    ClientContextGetHostMethodInfo          ,
#endif
    clientContextGetHost                    ,


-- ** getLocalAddress #method:getLocalAddress#

#if defined(ENABLE_OVERLOADING)
    ClientContextGetLocalAddressMethodInfo  ,
#endif
    clientContextGetLocalAddress            ,


-- ** getRemoteAddress #method:getRemoteAddress#

#if defined(ENABLE_OVERLOADING)
    ClientContextGetRemoteAddressMethodInfo ,
#endif
    clientContextGetRemoteAddress           ,


-- ** getSocket #method:getSocket#

#if defined(ENABLE_OVERLOADING)
    ClientContextGetSocketMethodInfo        ,
#endif
    clientContextGetSocket                  ,


-- ** stealConnection #method:stealConnection#

#if defined(ENABLE_OVERLOADING)
    ClientContextStealConnectionMethodInfo  ,
#endif
    clientContextStealConnection            ,




    ) 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.GClosure as B.GClosure
import qualified Data.GI.Base.GError as B.GError
import qualified Data.GI.Base.GVariant as B.GVariant
import qualified Data.GI.Base.GValue as B.GValue
import qualified Data.GI.Base.GParamSpec as B.GParamSpec
import qualified Data.GI.Base.CallStack as B.CallStack
import qualified Data.GI.Base.Properties as B.Properties
import qualified Data.GI.Base.Signals as B.Signals
import qualified Control.Monad.IO.Class as MIO
import qualified Data.Text as T
import qualified Data.ByteString.Char8 as B
import qualified Data.Map as Map
import qualified Foreign.Ptr as FP
import qualified GHC.OverloadedLabels as OL

import qualified GI.Gio.Objects.IOStream as Gio.IOStream
import qualified GI.Gio.Objects.Socket as Gio.Socket
import qualified GI.Gio.Objects.SocketAddress as Gio.SocketAddress
import {-# SOURCE #-} qualified GI.Soup.Objects.Address as Soup.Address
import {-# SOURCE #-} qualified GI.Soup.Objects.AuthDomain as Soup.AuthDomain
import {-# SOURCE #-} qualified GI.Soup.Objects.Socket as Soup.Socket

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

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

foreign import ccall "soup_client_context_get_type" c_soup_client_context_get_type :: 
    IO GType

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

instance B.Types.TypedObject ClientContext where
    glibType :: IO GType
glibType = IO GType
c_soup_client_context_get_type

instance B.Types.GBoxed ClientContext

-- | Convert 'ClientContext' to and from 'Data.GI.Base.GValue.GValue' with 'Data.GI.Base.GValue.toGValue' and 'Data.GI.Base.GValue.fromGValue'.
instance B.GValue.IsGValue ClientContext where
    toGValue :: ClientContext -> IO GValue
toGValue ClientContext
o = do
        GType
gtype <- IO GType
c_soup_client_context_get_type
        ClientContext -> (Ptr ClientContext -> IO GValue) -> IO GValue
forall a c.
(HasCallStack, ManagedPtrNewtype a) =>
a -> (Ptr a -> IO c) -> IO c
B.ManagedPtr.withManagedPtr ClientContext
o (GType
-> (GValue -> Ptr ClientContext -> IO ())
-> Ptr ClientContext
-> IO GValue
forall a. GType -> (GValue -> a -> IO ()) -> a -> IO GValue
B.GValue.buildGValue GType
gtype GValue -> Ptr ClientContext -> IO ()
forall a. GValue -> Ptr a -> IO ()
B.GValue.set_boxed)
        
    fromGValue :: GValue -> IO ClientContext
fromGValue GValue
gv = do
        Ptr ClientContext
ptr <- GValue -> IO (Ptr ClientContext)
forall b. GValue -> IO (Ptr b)
B.GValue.get_boxed GValue
gv :: IO (Ptr ClientContext)
        (ManagedPtr ClientContext -> ClientContext)
-> Ptr ClientContext -> IO ClientContext
forall a.
(HasCallStack, GBoxed a) =>
(ManagedPtr a -> a) -> Ptr a -> IO a
B.ManagedPtr.newBoxed ManagedPtr ClientContext -> ClientContext
ClientContext Ptr ClientContext
ptr
        
    


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

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

foreign import ccall "soup_client_context_get_address" soup_client_context_get_address :: 
    Ptr ClientContext ->                    -- client : TInterface (Name {namespace = "Soup", name = "ClientContext"})
    IO (Ptr Soup.Address.Address)

{-# DEPRECATED clientContextGetAddress ["Use 'GI.Soup.Structs.ClientContext.clientContextGetRemoteAddress', which returns","a t'GI.Gio.Objects.SocketAddress.SocketAddress'."] #-}
-- | Retrieves the t'GI.Soup.Objects.Address.Address' associated with the remote end
-- of a connection.
clientContextGetAddress ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    ClientContext
    -- ^ /@client@/: a t'GI.Soup.Structs.ClientContext.ClientContext'
    -> m (Maybe Soup.Address.Address)
    -- ^ __Returns:__ the t'GI.Soup.Objects.Address.Address'
    -- associated with the remote end of a connection, it may be
    -- 'P.Nothing' if you used 'GI.Soup.Objects.Server.serverAcceptIostream'.
clientContextGetAddress :: ClientContext -> m (Maybe Address)
clientContextGetAddress ClientContext
client = IO (Maybe Address) -> m (Maybe Address)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (Maybe Address) -> m (Maybe Address))
-> IO (Maybe Address) -> m (Maybe Address)
forall a b. (a -> b) -> a -> b
$ do
    Ptr ClientContext
client' <- ClientContext -> IO (Ptr ClientContext)
forall a. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr a)
unsafeManagedPtrGetPtr ClientContext
client
    Ptr Address
result <- Ptr ClientContext -> IO (Ptr Address)
soup_client_context_get_address Ptr ClientContext
client'
    Maybe Address
maybeResult <- Ptr Address -> (Ptr Address -> IO Address) -> IO (Maybe Address)
forall a b. Ptr a -> (Ptr a -> IO b) -> IO (Maybe b)
convertIfNonNull Ptr Address
result ((Ptr Address -> IO Address) -> IO (Maybe Address))
-> (Ptr Address -> IO Address) -> IO (Maybe Address)
forall a b. (a -> b) -> a -> b
$ \Ptr Address
result' -> do
        Address
result'' <- ((ManagedPtr Address -> Address) -> Ptr Address -> IO Address
forall a b.
(HasCallStack, GObject a, GObject b) =>
(ManagedPtr a -> a) -> Ptr b -> IO a
newObject ManagedPtr Address -> Address
Soup.Address.Address) Ptr Address
result'
        Address -> IO Address
forall (m :: * -> *) a. Monad m => a -> m a
return Address
result''
    ClientContext -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr ClientContext
client
    Maybe Address -> IO (Maybe Address)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe Address
maybeResult

#if defined(ENABLE_OVERLOADING)
data ClientContextGetAddressMethodInfo
instance (signature ~ (m (Maybe Soup.Address.Address)), MonadIO m) => O.MethodInfo ClientContextGetAddressMethodInfo ClientContext signature where
    overloadedMethod = clientContextGetAddress

#endif

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

foreign import ccall "soup_client_context_get_auth_domain" soup_client_context_get_auth_domain :: 
    Ptr ClientContext ->                    -- client : TInterface (Name {namespace = "Soup", name = "ClientContext"})
    IO (Ptr Soup.AuthDomain.AuthDomain)

-- | Checks whether the request associated with /@client@/ has been
-- authenticated, and if so returns the t'GI.Soup.Objects.AuthDomain.AuthDomain' that
-- authenticated it.
clientContextGetAuthDomain ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    ClientContext
    -- ^ /@client@/: a t'GI.Soup.Structs.ClientContext.ClientContext'
    -> m (Maybe Soup.AuthDomain.AuthDomain)
    -- ^ __Returns:__ a t'GI.Soup.Objects.AuthDomain.AuthDomain', or
    -- 'P.Nothing' if the request was not authenticated.
clientContextGetAuthDomain :: ClientContext -> m (Maybe AuthDomain)
clientContextGetAuthDomain ClientContext
client = IO (Maybe AuthDomain) -> m (Maybe AuthDomain)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (Maybe AuthDomain) -> m (Maybe AuthDomain))
-> IO (Maybe AuthDomain) -> m (Maybe AuthDomain)
forall a b. (a -> b) -> a -> b
$ do
    Ptr ClientContext
client' <- ClientContext -> IO (Ptr ClientContext)
forall a. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr a)
unsafeManagedPtrGetPtr ClientContext
client
    Ptr AuthDomain
result <- Ptr ClientContext -> IO (Ptr AuthDomain)
soup_client_context_get_auth_domain Ptr ClientContext
client'
    Maybe AuthDomain
maybeResult <- Ptr AuthDomain
-> (Ptr AuthDomain -> IO AuthDomain) -> IO (Maybe AuthDomain)
forall a b. Ptr a -> (Ptr a -> IO b) -> IO (Maybe b)
convertIfNonNull Ptr AuthDomain
result ((Ptr AuthDomain -> IO AuthDomain) -> IO (Maybe AuthDomain))
-> (Ptr AuthDomain -> IO AuthDomain) -> IO (Maybe AuthDomain)
forall a b. (a -> b) -> a -> b
$ \Ptr AuthDomain
result' -> do
        AuthDomain
result'' <- ((ManagedPtr AuthDomain -> AuthDomain)
-> Ptr AuthDomain -> IO AuthDomain
forall a b.
(HasCallStack, GObject a, GObject b) =>
(ManagedPtr a -> a) -> Ptr b -> IO a
newObject ManagedPtr AuthDomain -> AuthDomain
Soup.AuthDomain.AuthDomain) Ptr AuthDomain
result'
        AuthDomain -> IO AuthDomain
forall (m :: * -> *) a. Monad m => a -> m a
return AuthDomain
result''
    ClientContext -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr ClientContext
client
    Maybe AuthDomain -> IO (Maybe AuthDomain)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe AuthDomain
maybeResult

#if defined(ENABLE_OVERLOADING)
data ClientContextGetAuthDomainMethodInfo
instance (signature ~ (m (Maybe Soup.AuthDomain.AuthDomain)), MonadIO m) => O.MethodInfo ClientContextGetAuthDomainMethodInfo ClientContext signature where
    overloadedMethod = clientContextGetAuthDomain

#endif

-- method ClientContext::get_auth_user
-- method type : OrdinaryMethod
-- Args: [ Arg
--           { argCName = "client"
--           , argType =
--               TInterface Name { namespace = "Soup" , name = "ClientContext" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "a #SoupClientContext"
--                 , 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_client_context_get_auth_user" soup_client_context_get_auth_user :: 
    Ptr ClientContext ->                    -- client : TInterface (Name {namespace = "Soup", name = "ClientContext"})
    IO CString

-- | Checks whether the request associated with /@client@/ has been
-- authenticated, and if so returns the username that the client
-- authenticated as.
clientContextGetAuthUser ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    ClientContext
    -- ^ /@client@/: a t'GI.Soup.Structs.ClientContext.ClientContext'
    -> m (Maybe T.Text)
    -- ^ __Returns:__ the authenticated-as user, or 'P.Nothing' if
    -- the request was not authenticated.
clientContextGetAuthUser :: ClientContext -> m (Maybe Text)
clientContextGetAuthUser ClientContext
client = IO (Maybe Text) -> m (Maybe Text)
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
    Ptr ClientContext
client' <- ClientContext -> IO (Ptr ClientContext)
forall a. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr a)
unsafeManagedPtrGetPtr ClientContext
client
    CString
result <- Ptr ClientContext -> IO CString
soup_client_context_get_auth_user Ptr ClientContext
client'
    Maybe Text
maybeResult <- CString -> (CString -> IO Text) -> IO (Maybe Text)
forall a b. Ptr a -> (Ptr a -> IO b) -> IO (Maybe b)
convertIfNonNull CString
result ((CString -> IO Text) -> IO (Maybe Text))
-> (CString -> IO Text) -> IO (Maybe Text)
forall a b. (a -> b) -> a -> b
$ \CString
result' -> do
        Text
result'' <- HasCallStack => CString -> IO Text
CString -> IO Text
cstringToText CString
result'
        Text -> IO Text
forall (m :: * -> *) a. Monad m => a -> m a
return Text
result''
    ClientContext -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr ClientContext
client
    Maybe Text -> IO (Maybe Text)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe Text
maybeResult

#if defined(ENABLE_OVERLOADING)
data ClientContextGetAuthUserMethodInfo
instance (signature ~ (m (Maybe T.Text)), MonadIO m) => O.MethodInfo ClientContextGetAuthUserMethodInfo ClientContext signature where
    overloadedMethod = clientContextGetAuthUser

#endif

-- method ClientContext::get_gsocket
-- method type : OrdinaryMethod
-- Args: [ Arg
--           { argCName = "client"
--           , argType =
--               TInterface Name { namespace = "Soup" , name = "ClientContext" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "a #SoupClientContext"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       ]
-- Lengths: []
-- returnType: Just (TInterface Name { namespace = "Gio" , name = "Socket" })
-- throws : False
-- Skip return : False

foreign import ccall "soup_client_context_get_gsocket" soup_client_context_get_gsocket :: 
    Ptr ClientContext ->                    -- client : TInterface (Name {namespace = "Soup", name = "ClientContext"})
    IO (Ptr Gio.Socket.Socket)

-- | Retrieves the t'GI.Gio.Objects.Socket.Socket' that /@client@/ is associated with.
-- 
-- If you are using this method to observe when multiple requests are
-- made on the same persistent HTTP connection (eg, as the ntlm-test
-- test program does), you will need to pay attention to socket
-- destruction as well (eg, by using weak references), so that you do
-- not get fooled when the allocator reuses the memory address of a
-- previously-destroyed socket to represent a new socket.
-- 
-- /Since: 2.48/
clientContextGetGsocket ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    ClientContext
    -- ^ /@client@/: a t'GI.Soup.Structs.ClientContext.ClientContext'
    -> m (Maybe Gio.Socket.Socket)
    -- ^ __Returns:__ the t'GI.Gio.Objects.Socket.Socket' that /@client@/ is
    -- associated with, 'P.Nothing' if you used 'GI.Soup.Objects.Server.serverAcceptIostream'.
clientContextGetGsocket :: ClientContext -> m (Maybe Socket)
clientContextGetGsocket ClientContext
client = IO (Maybe Socket) -> m (Maybe Socket)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (Maybe Socket) -> m (Maybe Socket))
-> IO (Maybe Socket) -> m (Maybe Socket)
forall a b. (a -> b) -> a -> b
$ do
    Ptr ClientContext
client' <- ClientContext -> IO (Ptr ClientContext)
forall a. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr a)
unsafeManagedPtrGetPtr ClientContext
client
    Ptr Socket
result <- Ptr ClientContext -> IO (Ptr Socket)
soup_client_context_get_gsocket Ptr ClientContext
client'
    Maybe Socket
maybeResult <- Ptr Socket -> (Ptr Socket -> IO Socket) -> IO (Maybe Socket)
forall a b. Ptr a -> (Ptr a -> IO b) -> IO (Maybe b)
convertIfNonNull Ptr Socket
result ((Ptr Socket -> IO Socket) -> IO (Maybe Socket))
-> (Ptr Socket -> IO Socket) -> IO (Maybe Socket)
forall a b. (a -> b) -> a -> b
$ \Ptr Socket
result' -> do
        Socket
result'' <- ((ManagedPtr Socket -> Socket) -> Ptr Socket -> IO Socket
forall a b.
(HasCallStack, GObject a, GObject b) =>
(ManagedPtr a -> a) -> Ptr b -> IO a
newObject ManagedPtr Socket -> Socket
Gio.Socket.Socket) Ptr Socket
result'
        Socket -> IO Socket
forall (m :: * -> *) a. Monad m => a -> m a
return Socket
result''
    ClientContext -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr ClientContext
client
    Maybe Socket -> IO (Maybe Socket)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe Socket
maybeResult

#if defined(ENABLE_OVERLOADING)
data ClientContextGetGsocketMethodInfo
instance (signature ~ (m (Maybe Gio.Socket.Socket)), MonadIO m) => O.MethodInfo ClientContextGetGsocketMethodInfo ClientContext signature where
    overloadedMethod = clientContextGetGsocket

#endif

-- method ClientContext::get_host
-- method type : OrdinaryMethod
-- Args: [ Arg
--           { argCName = "client"
--           , argType =
--               TInterface Name { namespace = "Soup" , name = "ClientContext" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "a #SoupClientContext"
--                 , 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_client_context_get_host" soup_client_context_get_host :: 
    Ptr ClientContext ->                    -- client : TInterface (Name {namespace = "Soup", name = "ClientContext"})
    IO CString

-- | Retrieves the IP address associated with the remote end of a
-- connection.
clientContextGetHost ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    ClientContext
    -- ^ /@client@/: a t'GI.Soup.Structs.ClientContext.ClientContext'
    -> m (Maybe T.Text)
    -- ^ __Returns:__ the IP address associated with the remote
    -- end of a connection, it may be 'P.Nothing' if you used
    -- 'GI.Soup.Objects.Server.serverAcceptIostream'.
clientContextGetHost :: ClientContext -> m (Maybe Text)
clientContextGetHost ClientContext
client = IO (Maybe Text) -> m (Maybe Text)
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
    Ptr ClientContext
client' <- ClientContext -> IO (Ptr ClientContext)
forall a. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr a)
unsafeManagedPtrGetPtr ClientContext
client
    CString
result <- Ptr ClientContext -> IO CString
soup_client_context_get_host Ptr ClientContext
client'
    Maybe Text
maybeResult <- CString -> (CString -> IO Text) -> IO (Maybe Text)
forall a b. Ptr a -> (Ptr a -> IO b) -> IO (Maybe b)
convertIfNonNull CString
result ((CString -> IO Text) -> IO (Maybe Text))
-> (CString -> IO Text) -> IO (Maybe Text)
forall a b. (a -> b) -> a -> b
$ \CString
result' -> do
        Text
result'' <- HasCallStack => CString -> IO Text
CString -> IO Text
cstringToText CString
result'
        Text -> IO Text
forall (m :: * -> *) a. Monad m => a -> m a
return Text
result''
    ClientContext -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr ClientContext
client
    Maybe Text -> IO (Maybe Text)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe Text
maybeResult

#if defined(ENABLE_OVERLOADING)
data ClientContextGetHostMethodInfo
instance (signature ~ (m (Maybe T.Text)), MonadIO m) => O.MethodInfo ClientContextGetHostMethodInfo ClientContext signature where
    overloadedMethod = clientContextGetHost

#endif

-- method ClientContext::get_local_address
-- method type : OrdinaryMethod
-- Args: [ Arg
--           { argCName = "client"
--           , argType =
--               TInterface Name { namespace = "Soup" , name = "ClientContext" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "a #SoupClientContext"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       ]
-- Lengths: []
-- returnType: Just
--               (TInterface Name { namespace = "Gio" , name = "SocketAddress" })
-- throws : False
-- Skip return : False

foreign import ccall "soup_client_context_get_local_address" soup_client_context_get_local_address :: 
    Ptr ClientContext ->                    -- client : TInterface (Name {namespace = "Soup", name = "ClientContext"})
    IO (Ptr Gio.SocketAddress.SocketAddress)

-- | Retrieves the t'GI.Gio.Objects.SocketAddress.SocketAddress' associated with the local end
-- of a connection.
-- 
-- /Since: 2.48/
clientContextGetLocalAddress ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    ClientContext
    -- ^ /@client@/: a t'GI.Soup.Structs.ClientContext.ClientContext'
    -> m (Maybe Gio.SocketAddress.SocketAddress)
    -- ^ __Returns:__ the t'GI.Gio.Objects.SocketAddress.SocketAddress'
    -- associated with the local end of a connection, it may be
    -- 'P.Nothing' if you used 'GI.Soup.Objects.Server.serverAcceptIostream'.
clientContextGetLocalAddress :: ClientContext -> m (Maybe SocketAddress)
clientContextGetLocalAddress ClientContext
client = IO (Maybe SocketAddress) -> m (Maybe SocketAddress)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (Maybe SocketAddress) -> m (Maybe SocketAddress))
-> IO (Maybe SocketAddress) -> m (Maybe SocketAddress)
forall a b. (a -> b) -> a -> b
$ do
    Ptr ClientContext
client' <- ClientContext -> IO (Ptr ClientContext)
forall a. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr a)
unsafeManagedPtrGetPtr ClientContext
client
    Ptr SocketAddress
result <- Ptr ClientContext -> IO (Ptr SocketAddress)
soup_client_context_get_local_address Ptr ClientContext
client'
    Maybe SocketAddress
maybeResult <- Ptr SocketAddress
-> (Ptr SocketAddress -> IO SocketAddress)
-> IO (Maybe SocketAddress)
forall a b. Ptr a -> (Ptr a -> IO b) -> IO (Maybe b)
convertIfNonNull Ptr SocketAddress
result ((Ptr SocketAddress -> IO SocketAddress)
 -> IO (Maybe SocketAddress))
-> (Ptr SocketAddress -> IO SocketAddress)
-> IO (Maybe SocketAddress)
forall a b. (a -> b) -> a -> b
$ \Ptr SocketAddress
result' -> do
        SocketAddress
result'' <- ((ManagedPtr SocketAddress -> SocketAddress)
-> Ptr SocketAddress -> IO SocketAddress
forall a b.
(HasCallStack, GObject a, GObject b) =>
(ManagedPtr a -> a) -> Ptr b -> IO a
newObject ManagedPtr SocketAddress -> SocketAddress
Gio.SocketAddress.SocketAddress) Ptr SocketAddress
result'
        SocketAddress -> IO SocketAddress
forall (m :: * -> *) a. Monad m => a -> m a
return SocketAddress
result''
    ClientContext -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr ClientContext
client
    Maybe SocketAddress -> IO (Maybe SocketAddress)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe SocketAddress
maybeResult

#if defined(ENABLE_OVERLOADING)
data ClientContextGetLocalAddressMethodInfo
instance (signature ~ (m (Maybe Gio.SocketAddress.SocketAddress)), MonadIO m) => O.MethodInfo ClientContextGetLocalAddressMethodInfo ClientContext signature where
    overloadedMethod = clientContextGetLocalAddress

#endif

-- method ClientContext::get_remote_address
-- method type : OrdinaryMethod
-- Args: [ Arg
--           { argCName = "client"
--           , argType =
--               TInterface Name { namespace = "Soup" , name = "ClientContext" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "a #SoupClientContext"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       ]
-- Lengths: []
-- returnType: Just
--               (TInterface Name { namespace = "Gio" , name = "SocketAddress" })
-- throws : False
-- Skip return : False

foreign import ccall "soup_client_context_get_remote_address" soup_client_context_get_remote_address :: 
    Ptr ClientContext ->                    -- client : TInterface (Name {namespace = "Soup", name = "ClientContext"})
    IO (Ptr Gio.SocketAddress.SocketAddress)

-- | Retrieves the t'GI.Gio.Objects.SocketAddress.SocketAddress' associated with the remote end
-- of a connection.
-- 
-- /Since: 2.48/
clientContextGetRemoteAddress ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    ClientContext
    -- ^ /@client@/: a t'GI.Soup.Structs.ClientContext.ClientContext'
    -> m (Maybe Gio.SocketAddress.SocketAddress)
    -- ^ __Returns:__ the t'GI.Gio.Objects.SocketAddress.SocketAddress'
    -- associated with the remote end of a connection, it may be
    -- 'P.Nothing' if you used 'GI.Soup.Objects.Server.serverAcceptIostream'.
clientContextGetRemoteAddress :: ClientContext -> m (Maybe SocketAddress)
clientContextGetRemoteAddress ClientContext
client = IO (Maybe SocketAddress) -> m (Maybe SocketAddress)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (Maybe SocketAddress) -> m (Maybe SocketAddress))
-> IO (Maybe SocketAddress) -> m (Maybe SocketAddress)
forall a b. (a -> b) -> a -> b
$ do
    Ptr ClientContext
client' <- ClientContext -> IO (Ptr ClientContext)
forall a. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr a)
unsafeManagedPtrGetPtr ClientContext
client
    Ptr SocketAddress
result <- Ptr ClientContext -> IO (Ptr SocketAddress)
soup_client_context_get_remote_address Ptr ClientContext
client'
    Maybe SocketAddress
maybeResult <- Ptr SocketAddress
-> (Ptr SocketAddress -> IO SocketAddress)
-> IO (Maybe SocketAddress)
forall a b. Ptr a -> (Ptr a -> IO b) -> IO (Maybe b)
convertIfNonNull Ptr SocketAddress
result ((Ptr SocketAddress -> IO SocketAddress)
 -> IO (Maybe SocketAddress))
-> (Ptr SocketAddress -> IO SocketAddress)
-> IO (Maybe SocketAddress)
forall a b. (a -> b) -> a -> b
$ \Ptr SocketAddress
result' -> do
        SocketAddress
result'' <- ((ManagedPtr SocketAddress -> SocketAddress)
-> Ptr SocketAddress -> IO SocketAddress
forall a b.
(HasCallStack, GObject a, GObject b) =>
(ManagedPtr a -> a) -> Ptr b -> IO a
newObject ManagedPtr SocketAddress -> SocketAddress
Gio.SocketAddress.SocketAddress) Ptr SocketAddress
result'
        SocketAddress -> IO SocketAddress
forall (m :: * -> *) a. Monad m => a -> m a
return SocketAddress
result''
    ClientContext -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr ClientContext
client
    Maybe SocketAddress -> IO (Maybe SocketAddress)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe SocketAddress
maybeResult

#if defined(ENABLE_OVERLOADING)
data ClientContextGetRemoteAddressMethodInfo
instance (signature ~ (m (Maybe Gio.SocketAddress.SocketAddress)), MonadIO m) => O.MethodInfo ClientContextGetRemoteAddressMethodInfo ClientContext signature where
    overloadedMethod = clientContextGetRemoteAddress

#endif

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

foreign import ccall "soup_client_context_get_socket" soup_client_context_get_socket :: 
    Ptr ClientContext ->                    -- client : TInterface (Name {namespace = "Soup", name = "ClientContext"})
    IO (Ptr Soup.Socket.Socket)

{-# DEPRECATED clientContextGetSocket ["use 'GI.Soup.Structs.ClientContext.clientContextGetGsocket', which returns","a t'GI.Gio.Objects.Socket.Socket'."] #-}
-- | Retrieves the t'GI.Soup.Objects.Socket.Socket' that /@client@/ is associated with.
-- 
-- If you are using this method to observe when multiple requests are
-- made on the same persistent HTTP connection (eg, as the ntlm-test
-- test program does), you will need to pay attention to socket
-- destruction as well (either by using weak references, or by
-- connecting to the [disconnected]("GI.Soup.Objects.Socket#g:signal:disconnected") signal), so that you do
-- not get fooled when the allocator reuses the memory address of a
-- previously-destroyed socket to represent a new socket.
clientContextGetSocket ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    ClientContext
    -- ^ /@client@/: a t'GI.Soup.Structs.ClientContext.ClientContext'
    -> m Soup.Socket.Socket
    -- ^ __Returns:__ the t'GI.Soup.Objects.Socket.Socket' that /@client@/ is
    -- associated with.
clientContextGetSocket :: ClientContext -> m Socket
clientContextGetSocket ClientContext
client = IO Socket -> m Socket
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Socket -> m Socket) -> IO Socket -> m Socket
forall a b. (a -> b) -> a -> b
$ do
    Ptr ClientContext
client' <- ClientContext -> IO (Ptr ClientContext)
forall a. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr a)
unsafeManagedPtrGetPtr ClientContext
client
    Ptr Socket
result <- Ptr ClientContext -> IO (Ptr Socket)
soup_client_context_get_socket Ptr ClientContext
client'
    Text -> Ptr Socket -> IO ()
forall a. HasCallStack => Text -> Ptr a -> IO ()
checkUnexpectedReturnNULL Text
"clientContextGetSocket" Ptr Socket
result
    Socket
result' <- ((ManagedPtr Socket -> Socket) -> Ptr Socket -> IO Socket
forall a b.
(HasCallStack, GObject a, GObject b) =>
(ManagedPtr a -> a) -> Ptr b -> IO a
newObject ManagedPtr Socket -> Socket
Soup.Socket.Socket) Ptr Socket
result
    ClientContext -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr ClientContext
client
    Socket -> IO Socket
forall (m :: * -> *) a. Monad m => a -> m a
return Socket
result'

#if defined(ENABLE_OVERLOADING)
data ClientContextGetSocketMethodInfo
instance (signature ~ (m Soup.Socket.Socket), MonadIO m) => O.MethodInfo ClientContextGetSocketMethodInfo ClientContext signature where
    overloadedMethod = clientContextGetSocket

#endif

-- method ClientContext::steal_connection
-- method type : OrdinaryMethod
-- Args: [ Arg
--           { argCName = "client"
--           , argType =
--               TInterface Name { namespace = "Soup" , name = "ClientContext" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "a #SoupClientContext"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       ]
-- Lengths: []
-- returnType: Just (TInterface Name { namespace = "Gio" , name = "IOStream" })
-- throws : False
-- Skip return : False

foreign import ccall "soup_client_context_steal_connection" soup_client_context_steal_connection :: 
    Ptr ClientContext ->                    -- client : TInterface (Name {namespace = "Soup", name = "ClientContext"})
    IO (Ptr Gio.IOStream.IOStream)

-- | \"Steals\" the HTTP connection associated with /@client@/ from its
-- t'GI.Soup.Objects.Server.Server'. This happens immediately, regardless of the current
-- state of the connection; if the response to the current
-- t'GI.Soup.Objects.Message.Message' has not yet finished being sent, then it will be
-- discarded; you can steal the connection from a
-- t'GI.Soup.Objects.Message.Message':@/wrote-informational/@ or t'GI.Soup.Objects.Message.Message':@/wrote-body/@ signal
-- handler if you need to wait for part or all of the response to be
-- sent.
-- 
-- Note that when calling this function from C, /@client@/ will most
-- likely be freed as a side effect.
-- 
-- /Since: 2.50/
clientContextStealConnection ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    ClientContext
    -- ^ /@client@/: a t'GI.Soup.Structs.ClientContext.ClientContext'
    -> m Gio.IOStream.IOStream
    -- ^ __Returns:__ the t'GI.Gio.Objects.IOStream.IOStream' formerly associated
    --   with /@client@/ (or 'P.Nothing' if /@client@/ was no longer associated with a
    --   connection). No guarantees are made about what kind of t'GI.Gio.Objects.IOStream.IOStream'
    --   is returned.
clientContextStealConnection :: ClientContext -> m IOStream
clientContextStealConnection ClientContext
client = IO IOStream -> m IOStream
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO IOStream -> m IOStream) -> IO IOStream -> m IOStream
forall a b. (a -> b) -> a -> b
$ do
    Ptr ClientContext
client' <- ClientContext -> IO (Ptr ClientContext)
forall a. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr a)
unsafeManagedPtrGetPtr ClientContext
client
    Ptr IOStream
result <- Ptr ClientContext -> IO (Ptr IOStream)
soup_client_context_steal_connection Ptr ClientContext
client'
    Text -> Ptr IOStream -> IO ()
forall a. HasCallStack => Text -> Ptr a -> IO ()
checkUnexpectedReturnNULL Text
"clientContextStealConnection" Ptr IOStream
result
    IOStream
result' <- ((ManagedPtr IOStream -> IOStream) -> Ptr IOStream -> IO IOStream
forall a b.
(HasCallStack, GObject a, GObject b) =>
(ManagedPtr a -> a) -> Ptr b -> IO a
wrapObject ManagedPtr IOStream -> IOStream
Gio.IOStream.IOStream) Ptr IOStream
result
    ClientContext -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr ClientContext
client
    IOStream -> IO IOStream
forall (m :: * -> *) a. Monad m => a -> m a
return IOStream
result'

#if defined(ENABLE_OVERLOADING)
data ClientContextStealConnectionMethodInfo
instance (signature ~ (m Gio.IOStream.IOStream), MonadIO m) => O.MethodInfo ClientContextStealConnectionMethodInfo ClientContext signature where
    overloadedMethod = clientContextStealConnection

#endif

#if defined(ENABLE_OVERLOADING)
type family ResolveClientContextMethod (t :: Symbol) (o :: *) :: * where
    ResolveClientContextMethod "stealConnection" o = ClientContextStealConnectionMethodInfo
    ResolveClientContextMethod "getAddress" o = ClientContextGetAddressMethodInfo
    ResolveClientContextMethod "getAuthDomain" o = ClientContextGetAuthDomainMethodInfo
    ResolveClientContextMethod "getAuthUser" o = ClientContextGetAuthUserMethodInfo
    ResolveClientContextMethod "getGsocket" o = ClientContextGetGsocketMethodInfo
    ResolveClientContextMethod "getHost" o = ClientContextGetHostMethodInfo
    ResolveClientContextMethod "getLocalAddress" o = ClientContextGetLocalAddressMethodInfo
    ResolveClientContextMethod "getRemoteAddress" o = ClientContextGetRemoteAddressMethodInfo
    ResolveClientContextMethod "getSocket" o = ClientContextGetSocketMethodInfo
    ResolveClientContextMethod l o = O.MethodResolutionFailed l o

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

#endif