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

A #SoupClientContext provides additional information about the
client making a particular request. In particular, you can use
soup_client_context_get_auth_domain() and
soup_client_context_get_auth_user() to determine if HTTP
authentication was used successfully.

soup_client_context_get_remote_address() and/or
soup_client_context_get_host() can be used to get information for
logging or debugging purposes. soup_client_context_get_gsocket() may
also be of use in some situations (eg, tracking when multiple
requests are made on the same connection).
-}

module GI.Soup.Structs.ClientContext
    ( 

-- * Exported types
    ClientContext(..)                       ,
    noClientContext                         ,


 -- * Methods
-- ** clientContextGetAddress
    clientContextGetAddress                 ,


-- ** clientContextGetAuthDomain
    clientContextGetAuthDomain              ,


-- ** clientContextGetAuthUser
    clientContextGetAuthUser                ,


-- ** clientContextGetGsocket
    clientContextGetGsocket                 ,


-- ** clientContextGetHost
    clientContextGetHost                    ,


-- ** clientContextGetLocalAddress
    clientContextGetLocalAddress            ,


-- ** clientContextGetRemoteAddress
    clientContextGetRemoteAddress           ,


-- ** clientContextGetSocket
    clientContextGetSocket                  ,


-- ** clientContextStealConnection
    clientContextStealConnection            ,




    ) where

import Prelude ()
import Data.GI.Base.ShortPrelude

import qualified Data.Text as T
import qualified Data.ByteString.Char8 as B
import qualified Data.Map as Map

import GI.Soup.Types
import GI.Soup.Callbacks
import qualified GI.Gio as Gio

newtype ClientContext = ClientContext (ForeignPtr ClientContext)
foreign import ccall "soup_client_context_get_type" c_soup_client_context_get_type :: 
    IO GType

instance BoxedObject ClientContext where
    boxedType _ = c_soup_client_context_get_type

noClientContext :: Maybe ClientContext
noClientContext = Nothing

-- method ClientContext::get_address
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "Soup" "ClientContext", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "Soup" "ClientContext", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TInterface "Soup" "Address"
-- throws : False
-- Skip return : False

foreign import ccall "soup_client_context_get_address" soup_client_context_get_address :: 
    Ptr ClientContext ->                    -- _obj : TInterface "Soup" "ClientContext"
    IO (Ptr Address)

{-# DEPRECATED clientContextGetAddress ["Use soup_client_context_get_remote_address(), which returns","a #GSocketAddress."]#-}
clientContextGetAddress ::
    (MonadIO m) =>
    ClientContext ->                        -- _obj
    m Address
clientContextGetAddress _obj = liftIO $ do
    let _obj' = unsafeManagedPtrGetPtr _obj
    result <- soup_client_context_get_address _obj'
    checkUnexpectedReturnNULL "soup_client_context_get_address" result
    result' <- (newObject Address) result
    touchManagedPtr _obj
    return result'

-- method ClientContext::get_auth_domain
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "Soup" "ClientContext", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "Soup" "ClientContext", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TInterface "Soup" "AuthDomain"
-- throws : False
-- Skip return : False

foreign import ccall "soup_client_context_get_auth_domain" soup_client_context_get_auth_domain :: 
    Ptr ClientContext ->                    -- _obj : TInterface "Soup" "ClientContext"
    IO (Ptr AuthDomain)


clientContextGetAuthDomain ::
    (MonadIO m) =>
    ClientContext ->                        -- _obj
    m AuthDomain
clientContextGetAuthDomain _obj = liftIO $ do
    let _obj' = unsafeManagedPtrGetPtr _obj
    result <- soup_client_context_get_auth_domain _obj'
    checkUnexpectedReturnNULL "soup_client_context_get_auth_domain" result
    result' <- (newObject AuthDomain) result
    touchManagedPtr _obj
    return result'

-- method ClientContext::get_auth_user
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "Soup" "ClientContext", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "Soup" "ClientContext", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TBasicType TUTF8
-- throws : False
-- Skip return : False

foreign import ccall "soup_client_context_get_auth_user" soup_client_context_get_auth_user :: 
    Ptr ClientContext ->                    -- _obj : TInterface "Soup" "ClientContext"
    IO CString


clientContextGetAuthUser ::
    (MonadIO m) =>
    ClientContext ->                        -- _obj
    m T.Text
clientContextGetAuthUser _obj = liftIO $ do
    let _obj' = unsafeManagedPtrGetPtr _obj
    result <- soup_client_context_get_auth_user _obj'
    checkUnexpectedReturnNULL "soup_client_context_get_auth_user" result
    result' <- cstringToText result
    touchManagedPtr _obj
    return result'

-- method ClientContext::get_gsocket
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "Soup" "ClientContext", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "Soup" "ClientContext", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TInterface "Gio" "Socket"
-- throws : False
-- Skip return : False

foreign import ccall "soup_client_context_get_gsocket" soup_client_context_get_gsocket :: 
    Ptr ClientContext ->                    -- _obj : TInterface "Soup" "ClientContext"
    IO (Ptr Gio.Socket)


clientContextGetGsocket ::
    (MonadIO m) =>
    ClientContext ->                        -- _obj
    m Gio.Socket
clientContextGetGsocket _obj = liftIO $ do
    let _obj' = unsafeManagedPtrGetPtr _obj
    result <- soup_client_context_get_gsocket _obj'
    checkUnexpectedReturnNULL "soup_client_context_get_gsocket" result
    result' <- (newObject Gio.Socket) result
    touchManagedPtr _obj
    return result'

-- method ClientContext::get_host
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "Soup" "ClientContext", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "Soup" "ClientContext", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TBasicType TUTF8
-- throws : False
-- Skip return : False

foreign import ccall "soup_client_context_get_host" soup_client_context_get_host :: 
    Ptr ClientContext ->                    -- _obj : TInterface "Soup" "ClientContext"
    IO CString


clientContextGetHost ::
    (MonadIO m) =>
    ClientContext ->                        -- _obj
    m T.Text
clientContextGetHost _obj = liftIO $ do
    let _obj' = unsafeManagedPtrGetPtr _obj
    result <- soup_client_context_get_host _obj'
    checkUnexpectedReturnNULL "soup_client_context_get_host" result
    result' <- cstringToText result
    touchManagedPtr _obj
    return result'

-- method ClientContext::get_local_address
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "Soup" "ClientContext", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "Soup" "ClientContext", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TInterface "Gio" "SocketAddress"
-- throws : False
-- Skip return : False

foreign import ccall "soup_client_context_get_local_address" soup_client_context_get_local_address :: 
    Ptr ClientContext ->                    -- _obj : TInterface "Soup" "ClientContext"
    IO (Ptr Gio.SocketAddress)


clientContextGetLocalAddress ::
    (MonadIO m) =>
    ClientContext ->                        -- _obj
    m Gio.SocketAddress
clientContextGetLocalAddress _obj = liftIO $ do
    let _obj' = unsafeManagedPtrGetPtr _obj
    result <- soup_client_context_get_local_address _obj'
    checkUnexpectedReturnNULL "soup_client_context_get_local_address" result
    result' <- (newObject Gio.SocketAddress) result
    touchManagedPtr _obj
    return result'

-- method ClientContext::get_remote_address
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "Soup" "ClientContext", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "Soup" "ClientContext", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TInterface "Gio" "SocketAddress"
-- throws : False
-- Skip return : False

foreign import ccall "soup_client_context_get_remote_address" soup_client_context_get_remote_address :: 
    Ptr ClientContext ->                    -- _obj : TInterface "Soup" "ClientContext"
    IO (Ptr Gio.SocketAddress)


clientContextGetRemoteAddress ::
    (MonadIO m) =>
    ClientContext ->                        -- _obj
    m Gio.SocketAddress
clientContextGetRemoteAddress _obj = liftIO $ do
    let _obj' = unsafeManagedPtrGetPtr _obj
    result <- soup_client_context_get_remote_address _obj'
    checkUnexpectedReturnNULL "soup_client_context_get_remote_address" result
    result' <- (newObject Gio.SocketAddress) result
    touchManagedPtr _obj
    return result'

-- method ClientContext::get_socket
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "Soup" "ClientContext", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "Soup" "ClientContext", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TInterface "Soup" "Socket"
-- throws : False
-- Skip return : False

foreign import ccall "soup_client_context_get_socket" soup_client_context_get_socket :: 
    Ptr ClientContext ->                    -- _obj : TInterface "Soup" "ClientContext"
    IO (Ptr Socket)

{-# DEPRECATED clientContextGetSocket ["use soup_client_context_get_gsocket(), which returns","a #GSocket."]#-}
clientContextGetSocket ::
    (MonadIO m) =>
    ClientContext ->                        -- _obj
    m Socket
clientContextGetSocket _obj = liftIO $ do
    let _obj' = unsafeManagedPtrGetPtr _obj
    result <- soup_client_context_get_socket _obj'
    checkUnexpectedReturnNULL "soup_client_context_get_socket" result
    result' <- (newObject Socket) result
    touchManagedPtr _obj
    return result'

-- method ClientContext::steal_connection
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "Soup" "ClientContext", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "Soup" "ClientContext", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TInterface "Gio" "IOStream"
-- throws : False
-- Skip return : False

foreign import ccall "soup_client_context_steal_connection" soup_client_context_steal_connection :: 
    Ptr ClientContext ->                    -- _obj : TInterface "Soup" "ClientContext"
    IO (Ptr Gio.IOStream)


clientContextStealConnection ::
    (MonadIO m) =>
    ClientContext ->                        -- _obj
    m Gio.IOStream
clientContextStealConnection _obj = liftIO $ do
    let _obj' = unsafeManagedPtrGetPtr _obj
    result <- soup_client_context_steal_connection _obj'
    checkUnexpectedReturnNULL "soup_client_context_steal_connection" result
    result' <- (wrapObject Gio.IOStream) result
    touchManagedPtr _obj
    return result'