{-# LANGUAGE TypeApplications #-}


-- | Copyright  : Will Thompson and Iñaki García Etxebarria
-- License    : LGPL-2.1
-- Maintainer : Iñaki García Etxebarria
-- 
-- A t'GI.Gio.Interfaces.Proxy.Proxy' handles connecting to a remote host via a given type of
-- proxy server. It is implemented by the \'gio-proxy\' extension point.
-- The extensions are named after their proxy protocol name. As an
-- example, a SOCKS5 proxy implementation can be retrieved with the
-- name \'socks5\' using the function
-- 'GI.Gio.Structs.IOExtensionPoint.iOExtensionPointGetExtensionByName'.
-- 
-- /Since: 2.26/

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

module GI.Gio.Interfaces.Proxy
    ( 

-- * Exported types
    Proxy(..)                               ,
    IsProxy                                 ,
    toProxy                                 ,


 -- * 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"), [connect]("GI.Gio.Interfaces.Proxy#g:method:connect"), [connectAsync]("GI.Gio.Interfaces.Proxy#g:method:connectAsync"), [connectFinish]("GI.Gio.Interfaces.Proxy#g:method:connectFinish"), [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"), [supportsHostname]("GI.Gio.Interfaces.Proxy#g:method:supportsHostname"), [thawNotify]("GI.GObject.Objects.Object#g:method:thawNotify"), [unref]("GI.GObject.Objects.Object#g:method:unref"), [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)
    ResolveProxyMethod                      ,
#endif

-- ** connect #method:connect#

#if defined(ENABLE_OVERLOADING)
    ProxyConnectMethodInfo                  ,
#endif
    proxyConnect                            ,


-- ** connectAsync #method:connectAsync#

#if defined(ENABLE_OVERLOADING)
    ProxyConnectAsyncMethodInfo             ,
#endif
    proxyConnectAsync                       ,


-- ** connectFinish #method:connectFinish#

#if defined(ENABLE_OVERLOADING)
    ProxyConnectFinishMethodInfo            ,
#endif
    proxyConnectFinish                      ,


-- ** getDefaultForProtocol #method:getDefaultForProtocol#

    proxyGetDefaultForProtocol              ,


-- ** supportsHostname #method:supportsHostname#

#if defined(ENABLE_OVERLOADING)
    ProxySupportsHostnameMethodInfo         ,
#endif
    proxySupportsHostname                   ,




    ) 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.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.GObject.Objects.Object as GObject.Object
import qualified GI.Gio.Callbacks as Gio.Callbacks
import {-# SOURCE #-} qualified GI.Gio.Interfaces.AsyncResult as Gio.AsyncResult
import {-# SOURCE #-} qualified GI.Gio.Objects.Cancellable as Gio.Cancellable
import {-# SOURCE #-} qualified GI.Gio.Objects.IOStream as Gio.IOStream
import {-# SOURCE #-} qualified GI.Gio.Objects.ProxyAddress as Gio.ProxyAddress

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

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

foreign import ccall "g_proxy_get_type"
    c_g_proxy_get_type :: IO B.Types.GType

instance B.Types.TypedObject Proxy where
    glibType :: IO GType
glibType = IO GType
c_g_proxy_get_type

instance B.Types.GObject Proxy

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

instance O.HasParentTypes Proxy
type instance O.ParentTypes Proxy = '[GObject.Object.Object]

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

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

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

#if defined(ENABLE_OVERLOADING)
#endif

#if defined(ENABLE_OVERLOADING)
type family ResolveProxyMethod (t :: Symbol) (o :: *) :: * where
    ResolveProxyMethod "bindProperty" o = GObject.Object.ObjectBindPropertyMethodInfo
    ResolveProxyMethod "bindPropertyFull" o = GObject.Object.ObjectBindPropertyFullMethodInfo
    ResolveProxyMethod "connect" o = ProxyConnectMethodInfo
    ResolveProxyMethod "connectAsync" o = ProxyConnectAsyncMethodInfo
    ResolveProxyMethod "connectFinish" o = ProxyConnectFinishMethodInfo
    ResolveProxyMethod "forceFloating" o = GObject.Object.ObjectForceFloatingMethodInfo
    ResolveProxyMethod "freezeNotify" o = GObject.Object.ObjectFreezeNotifyMethodInfo
    ResolveProxyMethod "getv" o = GObject.Object.ObjectGetvMethodInfo
    ResolveProxyMethod "isFloating" o = GObject.Object.ObjectIsFloatingMethodInfo
    ResolveProxyMethod "notify" o = GObject.Object.ObjectNotifyMethodInfo
    ResolveProxyMethod "notifyByPspec" o = GObject.Object.ObjectNotifyByPspecMethodInfo
    ResolveProxyMethod "ref" o = GObject.Object.ObjectRefMethodInfo
    ResolveProxyMethod "refSink" o = GObject.Object.ObjectRefSinkMethodInfo
    ResolveProxyMethod "runDispose" o = GObject.Object.ObjectRunDisposeMethodInfo
    ResolveProxyMethod "stealData" o = GObject.Object.ObjectStealDataMethodInfo
    ResolveProxyMethod "stealQdata" o = GObject.Object.ObjectStealQdataMethodInfo
    ResolveProxyMethod "supportsHostname" o = ProxySupportsHostnameMethodInfo
    ResolveProxyMethod "thawNotify" o = GObject.Object.ObjectThawNotifyMethodInfo
    ResolveProxyMethod "unref" o = GObject.Object.ObjectUnrefMethodInfo
    ResolveProxyMethod "watchClosure" o = GObject.Object.ObjectWatchClosureMethodInfo
    ResolveProxyMethod "getData" o = GObject.Object.ObjectGetDataMethodInfo
    ResolveProxyMethod "getProperty" o = GObject.Object.ObjectGetPropertyMethodInfo
    ResolveProxyMethod "getQdata" o = GObject.Object.ObjectGetQdataMethodInfo
    ResolveProxyMethod "setData" o = GObject.Object.ObjectSetDataMethodInfo
    ResolveProxyMethod "setDataFull" o = GObject.Object.ObjectSetDataFullMethodInfo
    ResolveProxyMethod "setProperty" o = GObject.Object.ObjectSetPropertyMethodInfo
    ResolveProxyMethod l o = O.MethodResolutionFailed l o

instance (info ~ ResolveProxyMethod t Proxy, O.OverloadedMethod info Proxy p) => OL.IsLabel t (Proxy -> 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 ~ ResolveProxyMethod t Proxy, O.OverloadedMethod info Proxy p, R.HasField t Proxy p) => R.HasField t Proxy p where
    getField = O.overloadedMethod @info

#endif

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

#endif

-- method Proxy::connect
-- method type : OrdinaryMethod
-- Args: [ Arg
--           { argCName = "proxy"
--           , argType = TInterface Name { namespace = "Gio" , name = "Proxy" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "a #GProxy" , sinceVersion = Nothing }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "connection"
--           , argType =
--               TInterface Name { namespace = "Gio" , name = "IOStream" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "a #GIOStream" , sinceVersion = Nothing }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "proxy_address"
--           , argType =
--               TInterface Name { namespace = "Gio" , name = "ProxyAddress" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "a #GProxyAddress" , sinceVersion = Nothing }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "cancellable"
--           , argType =
--               TInterface Name { namespace = "Gio" , name = "Cancellable" }
--           , direction = DirectionIn
--           , mayBeNull = True
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "a #GCancellable" , sinceVersion = Nothing }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       ]
-- Lengths: []
-- returnType: Just (TInterface Name { namespace = "Gio" , name = "IOStream" })
-- throws : True
-- Skip return : False

foreign import ccall "g_proxy_connect" g_proxy_connect :: 
    Ptr Proxy ->                            -- proxy : TInterface (Name {namespace = "Gio", name = "Proxy"})
    Ptr Gio.IOStream.IOStream ->            -- connection : TInterface (Name {namespace = "Gio", name = "IOStream"})
    Ptr Gio.ProxyAddress.ProxyAddress ->    -- proxy_address : TInterface (Name {namespace = "Gio", name = "ProxyAddress"})
    Ptr Gio.Cancellable.Cancellable ->      -- cancellable : TInterface (Name {namespace = "Gio", name = "Cancellable"})
    Ptr (Ptr GError) ->                     -- error
    IO (Ptr Gio.IOStream.IOStream)

-- | Given /@connection@/ to communicate with a proxy (eg, a
-- t'GI.Gio.Objects.SocketConnection.SocketConnection' that is connected to the proxy server), this
-- does the necessary handshake to connect to /@proxyAddress@/, and if
-- required, wraps the t'GI.Gio.Objects.IOStream.IOStream' to handle proxy payload.
-- 
-- /Since: 2.26/
proxyConnect ::
    (B.CallStack.HasCallStack, MonadIO m, IsProxy a, Gio.IOStream.IsIOStream b, Gio.ProxyAddress.IsProxyAddress c, Gio.Cancellable.IsCancellable d) =>
    a
    -- ^ /@proxy@/: a t'GI.Gio.Interfaces.Proxy.Proxy'
    -> b
    -- ^ /@connection@/: a t'GI.Gio.Objects.IOStream.IOStream'
    -> c
    -- ^ /@proxyAddress@/: a t'GI.Gio.Objects.ProxyAddress.ProxyAddress'
    -> Maybe (d)
    -- ^ /@cancellable@/: a t'GI.Gio.Objects.Cancellable.Cancellable'
    -> m Gio.IOStream.IOStream
    -- ^ __Returns:__ a t'GI.Gio.Objects.IOStream.IOStream' that will replace /@connection@/. This might
    --               be the same as /@connection@/, in which case a reference
    --               will be added. /(Can throw 'Data.GI.Base.GError.GError')/
proxyConnect :: forall (m :: * -> *) a b c d.
(HasCallStack, MonadIO m, IsProxy a, IsIOStream b,
 IsProxyAddress c, IsCancellable d) =>
a -> b -> c -> Maybe d -> m IOStream
proxyConnect a
proxy b
connection c
proxyAddress Maybe d
cancellable = forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$ do
    Ptr Proxy
proxy' <- forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr a
proxy
    Ptr IOStream
connection' <- forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr b
connection
    Ptr ProxyAddress
proxyAddress' <- forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr c
proxyAddress
    Ptr Cancellable
maybeCancellable <- case Maybe d
cancellable of
        Maybe d
Nothing -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a. Ptr a
nullPtr
        Just d
jCancellable -> do
            Ptr Cancellable
jCancellable' <- forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr d
jCancellable
            forall (m :: * -> *) a. Monad m => a -> m a
return Ptr Cancellable
jCancellable'
    forall a b. IO a -> IO b -> IO a
onException (do
        Ptr IOStream
result <- forall a. (Ptr (Ptr GError) -> IO a) -> IO a
propagateGError forall a b. (a -> b) -> a -> b
$ Ptr Proxy
-> Ptr IOStream
-> Ptr ProxyAddress
-> Ptr Cancellable
-> Ptr (Ptr GError)
-> IO (Ptr IOStream)
g_proxy_connect Ptr Proxy
proxy' Ptr IOStream
connection' Ptr ProxyAddress
proxyAddress' Ptr Cancellable
maybeCancellable
        forall a. HasCallStack => Text -> Ptr a -> IO ()
checkUnexpectedReturnNULL Text
"proxyConnect" Ptr IOStream
result
        IOStream
result' <- (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
        forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr a
proxy
        forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr b
connection
        forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr c
proxyAddress
        forall (m :: * -> *) a. Monad m => Maybe a -> (a -> m ()) -> m ()
whenJust Maybe d
cancellable forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr
        forall (m :: * -> *) a. Monad m => a -> m a
return IOStream
result'
     ) (do
        forall (m :: * -> *) a. Monad m => a -> m a
return ()
     )

#if defined(ENABLE_OVERLOADING)
data ProxyConnectMethodInfo
instance (signature ~ (b -> c -> Maybe (d) -> m Gio.IOStream.IOStream), MonadIO m, IsProxy a, Gio.IOStream.IsIOStream b, Gio.ProxyAddress.IsProxyAddress c, Gio.Cancellable.IsCancellable d) => O.OverloadedMethod ProxyConnectMethodInfo a signature where
    overloadedMethod = proxyConnect

instance O.OverloadedMethodInfo ProxyConnectMethodInfo a where
    overloadedMethodInfo = P.Just (O.ResolvedSymbolInfo {
        O.resolvedSymbolName = "GI.Gio.Interfaces.Proxy.proxyConnect",
        O.resolvedSymbolURL = "https://hackage.haskell.org/package/gi-gio-2.0.30/docs/GI-Gio-Interfaces-Proxy.html#v:proxyConnect"
        })


#endif

-- method Proxy::connect_async
-- method type : OrdinaryMethod
-- Args: [ Arg
--           { argCName = "proxy"
--           , argType = TInterface Name { namespace = "Gio" , name = "Proxy" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "a #GProxy" , sinceVersion = Nothing }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "connection"
--           , argType =
--               TInterface Name { namespace = "Gio" , name = "IOStream" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "a #GIOStream" , sinceVersion = Nothing }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "proxy_address"
--           , argType =
--               TInterface Name { namespace = "Gio" , name = "ProxyAddress" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "a #GProxyAddress" , sinceVersion = Nothing }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "cancellable"
--           , argType =
--               TInterface Name { namespace = "Gio" , name = "Cancellable" }
--           , direction = DirectionIn
--           , mayBeNull = True
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "a #GCancellable" , sinceVersion = Nothing }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "callback"
--           , argType =
--               TInterface Name { namespace = "Gio" , name = "AsyncReadyCallback" }
--           , direction = DirectionIn
--           , mayBeNull = True
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "a #GAsyncReadyCallback"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeAsync
--           , argClosure = 5
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "user_data"
--           , argType = TBasicType TPtr
--           , direction = DirectionIn
--           , mayBeNull = True
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "callback data" , sinceVersion = Nothing }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       ]
-- Lengths: []
-- returnType: Nothing
-- throws : False
-- Skip return : False

foreign import ccall "g_proxy_connect_async" g_proxy_connect_async :: 
    Ptr Proxy ->                            -- proxy : TInterface (Name {namespace = "Gio", name = "Proxy"})
    Ptr Gio.IOStream.IOStream ->            -- connection : TInterface (Name {namespace = "Gio", name = "IOStream"})
    Ptr Gio.ProxyAddress.ProxyAddress ->    -- proxy_address : TInterface (Name {namespace = "Gio", name = "ProxyAddress"})
    Ptr Gio.Cancellable.Cancellable ->      -- cancellable : TInterface (Name {namespace = "Gio", name = "Cancellable"})
    FunPtr Gio.Callbacks.C_AsyncReadyCallback -> -- callback : TInterface (Name {namespace = "Gio", name = "AsyncReadyCallback"})
    Ptr () ->                               -- user_data : TBasicType TPtr
    IO ()

-- | Asynchronous version of 'GI.Gio.Interfaces.Proxy.proxyConnect'.
-- 
-- /Since: 2.26/
proxyConnectAsync ::
    (B.CallStack.HasCallStack, MonadIO m, IsProxy a, Gio.IOStream.IsIOStream b, Gio.ProxyAddress.IsProxyAddress c, Gio.Cancellable.IsCancellable d) =>
    a
    -- ^ /@proxy@/: a t'GI.Gio.Interfaces.Proxy.Proxy'
    -> b
    -- ^ /@connection@/: a t'GI.Gio.Objects.IOStream.IOStream'
    -> c
    -- ^ /@proxyAddress@/: a t'GI.Gio.Objects.ProxyAddress.ProxyAddress'
    -> Maybe (d)
    -- ^ /@cancellable@/: a t'GI.Gio.Objects.Cancellable.Cancellable'
    -> Maybe (Gio.Callbacks.AsyncReadyCallback)
    -- ^ /@callback@/: a t'GI.Gio.Callbacks.AsyncReadyCallback'
    -> m ()
proxyConnectAsync :: forall (m :: * -> *) a b c d.
(HasCallStack, MonadIO m, IsProxy a, IsIOStream b,
 IsProxyAddress c, IsCancellable d) =>
a -> b -> c -> Maybe d -> Maybe AsyncReadyCallback -> m ()
proxyConnectAsync a
proxy b
connection c
proxyAddress Maybe d
cancellable Maybe AsyncReadyCallback
callback = forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$ do
    Ptr Proxy
proxy' <- forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr a
proxy
    Ptr IOStream
connection' <- forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr b
connection
    Ptr ProxyAddress
proxyAddress' <- forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr c
proxyAddress
    Ptr Cancellable
maybeCancellable <- case Maybe d
cancellable of
        Maybe d
Nothing -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a. Ptr a
nullPtr
        Just d
jCancellable -> do
            Ptr Cancellable
jCancellable' <- forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr d
jCancellable
            forall (m :: * -> *) a. Monad m => a -> m a
return Ptr Cancellable
jCancellable'
    FunPtr C_AsyncReadyCallback
maybeCallback <- case Maybe AsyncReadyCallback
callback of
        Maybe AsyncReadyCallback
Nothing -> forall (m :: * -> *) a. Monad m => a -> m a
return (forall a b. Ptr a -> FunPtr b
castPtrToFunPtr forall a. Ptr a
nullPtr)
        Just AsyncReadyCallback
jCallback -> do
            Ptr (FunPtr C_AsyncReadyCallback)
ptrcallback <- forall a. Storable a => IO (Ptr a)
callocMem :: IO (Ptr (FunPtr Gio.Callbacks.C_AsyncReadyCallback))
            FunPtr C_AsyncReadyCallback
jCallback' <- C_AsyncReadyCallback -> IO (FunPtr C_AsyncReadyCallback)
Gio.Callbacks.mk_AsyncReadyCallback (Maybe (Ptr (FunPtr C_AsyncReadyCallback))
-> AsyncReadyCallback_WithClosures -> C_AsyncReadyCallback
Gio.Callbacks.wrap_AsyncReadyCallback (forall a. a -> Maybe a
Just Ptr (FunPtr C_AsyncReadyCallback)
ptrcallback) (AsyncReadyCallback -> AsyncReadyCallback_WithClosures
Gio.Callbacks.drop_closures_AsyncReadyCallback AsyncReadyCallback
jCallback))
            forall a. Storable a => Ptr a -> a -> IO ()
poke Ptr (FunPtr C_AsyncReadyCallback)
ptrcallback FunPtr C_AsyncReadyCallback
jCallback'
            forall (m :: * -> *) a. Monad m => a -> m a
return FunPtr C_AsyncReadyCallback
jCallback'
    let userData :: Ptr a
userData = forall a. Ptr a
nullPtr
    Ptr Proxy
-> Ptr IOStream
-> Ptr ProxyAddress
-> Ptr Cancellable
-> FunPtr C_AsyncReadyCallback
-> Ptr ()
-> IO ()
g_proxy_connect_async Ptr Proxy
proxy' Ptr IOStream
connection' Ptr ProxyAddress
proxyAddress' Ptr Cancellable
maybeCancellable FunPtr C_AsyncReadyCallback
maybeCallback forall a. Ptr a
userData
    forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr a
proxy
    forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr b
connection
    forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr c
proxyAddress
    forall (m :: * -> *) a. Monad m => Maybe a -> (a -> m ()) -> m ()
whenJust Maybe d
cancellable forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr
    forall (m :: * -> *) a. Monad m => a -> m a
return ()

#if defined(ENABLE_OVERLOADING)
data ProxyConnectAsyncMethodInfo
instance (signature ~ (b -> c -> Maybe (d) -> Maybe (Gio.Callbacks.AsyncReadyCallback) -> m ()), MonadIO m, IsProxy a, Gio.IOStream.IsIOStream b, Gio.ProxyAddress.IsProxyAddress c, Gio.Cancellable.IsCancellable d) => O.OverloadedMethod ProxyConnectAsyncMethodInfo a signature where
    overloadedMethod = proxyConnectAsync

instance O.OverloadedMethodInfo ProxyConnectAsyncMethodInfo a where
    overloadedMethodInfo = P.Just (O.ResolvedSymbolInfo {
        O.resolvedSymbolName = "GI.Gio.Interfaces.Proxy.proxyConnectAsync",
        O.resolvedSymbolURL = "https://hackage.haskell.org/package/gi-gio-2.0.30/docs/GI-Gio-Interfaces-Proxy.html#v:proxyConnectAsync"
        })


#endif

-- method Proxy::connect_finish
-- method type : OrdinaryMethod
-- Args: [ Arg
--           { argCName = "proxy"
--           , argType = TInterface Name { namespace = "Gio" , name = "Proxy" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "a #GProxy" , sinceVersion = Nothing }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "result"
--           , argType =
--               TInterface Name { namespace = "Gio" , name = "AsyncResult" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "a #GAsyncResult" , sinceVersion = Nothing }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       ]
-- Lengths: []
-- returnType: Just (TInterface Name { namespace = "Gio" , name = "IOStream" })
-- throws : True
-- Skip return : False

foreign import ccall "g_proxy_connect_finish" g_proxy_connect_finish :: 
    Ptr Proxy ->                            -- proxy : TInterface (Name {namespace = "Gio", name = "Proxy"})
    Ptr Gio.AsyncResult.AsyncResult ->      -- result : TInterface (Name {namespace = "Gio", name = "AsyncResult"})
    Ptr (Ptr GError) ->                     -- error
    IO (Ptr Gio.IOStream.IOStream)

-- | See 'GI.Gio.Interfaces.Proxy.proxyConnect'.
-- 
-- /Since: 2.26/
proxyConnectFinish ::
    (B.CallStack.HasCallStack, MonadIO m, IsProxy a, Gio.AsyncResult.IsAsyncResult b) =>
    a
    -- ^ /@proxy@/: a t'GI.Gio.Interfaces.Proxy.Proxy'
    -> b
    -- ^ /@result@/: a t'GI.Gio.Interfaces.AsyncResult.AsyncResult'
    -> m Gio.IOStream.IOStream
    -- ^ __Returns:__ a t'GI.Gio.Objects.IOStream.IOStream'. /(Can throw 'Data.GI.Base.GError.GError')/
proxyConnectFinish :: forall (m :: * -> *) a b.
(HasCallStack, MonadIO m, IsProxy a, IsAsyncResult b) =>
a -> b -> m IOStream
proxyConnectFinish a
proxy b
result_ = forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$ do
    Ptr Proxy
proxy' <- forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr a
proxy
    Ptr AsyncResult
result_' <- forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr b
result_
    forall a b. IO a -> IO b -> IO a
onException (do
        Ptr IOStream
result <- forall a. (Ptr (Ptr GError) -> IO a) -> IO a
propagateGError forall a b. (a -> b) -> a -> b
$ Ptr Proxy
-> Ptr AsyncResult -> Ptr (Ptr GError) -> IO (Ptr IOStream)
g_proxy_connect_finish Ptr Proxy
proxy' Ptr AsyncResult
result_'
        forall a. HasCallStack => Text -> Ptr a -> IO ()
checkUnexpectedReturnNULL Text
"proxyConnectFinish" Ptr IOStream
result
        IOStream
result' <- (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
        forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr a
proxy
        forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr b
result_
        forall (m :: * -> *) a. Monad m => a -> m a
return IOStream
result'
     ) (do
        forall (m :: * -> *) a. Monad m => a -> m a
return ()
     )

#if defined(ENABLE_OVERLOADING)
data ProxyConnectFinishMethodInfo
instance (signature ~ (b -> m Gio.IOStream.IOStream), MonadIO m, IsProxy a, Gio.AsyncResult.IsAsyncResult b) => O.OverloadedMethod ProxyConnectFinishMethodInfo a signature where
    overloadedMethod = proxyConnectFinish

instance O.OverloadedMethodInfo ProxyConnectFinishMethodInfo a where
    overloadedMethodInfo = P.Just (O.ResolvedSymbolInfo {
        O.resolvedSymbolName = "GI.Gio.Interfaces.Proxy.proxyConnectFinish",
        O.resolvedSymbolURL = "https://hackage.haskell.org/package/gi-gio-2.0.30/docs/GI-Gio-Interfaces-Proxy.html#v:proxyConnectFinish"
        })


#endif

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

foreign import ccall "g_proxy_supports_hostname" g_proxy_supports_hostname :: 
    Ptr Proxy ->                            -- proxy : TInterface (Name {namespace = "Gio", name = "Proxy"})
    IO CInt

-- | Some proxy protocols expect to be passed a hostname, which they
-- will resolve to an IP address themselves. Others, like SOCKS4, do
-- not allow this. This function will return 'P.False' if /@proxy@/ is
-- implementing such a protocol. When 'P.False' is returned, the caller
-- should resolve the destination hostname first, and then pass a
-- t'GI.Gio.Objects.ProxyAddress.ProxyAddress' containing the stringified IP address to
-- 'GI.Gio.Interfaces.Proxy.proxyConnect' or 'GI.Gio.Interfaces.Proxy.proxyConnectAsync'.
-- 
-- /Since: 2.26/
proxySupportsHostname ::
    (B.CallStack.HasCallStack, MonadIO m, IsProxy a) =>
    a
    -- ^ /@proxy@/: a t'GI.Gio.Interfaces.Proxy.Proxy'
    -> m Bool
    -- ^ __Returns:__ 'P.True' if hostname resolution is supported.
proxySupportsHostname :: forall (m :: * -> *) a.
(HasCallStack, MonadIO m, IsProxy a) =>
a -> m Bool
proxySupportsHostname a
proxy = forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$ do
    Ptr Proxy
proxy' <- forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr a
proxy
    CInt
result <- Ptr Proxy -> IO CInt
g_proxy_supports_hostname Ptr Proxy
proxy'
    let result' :: Bool
result' = (forall a. Eq a => a -> a -> Bool
/= CInt
0) CInt
result
    forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr a
proxy
    forall (m :: * -> *) a. Monad m => a -> m a
return Bool
result'

#if defined(ENABLE_OVERLOADING)
data ProxySupportsHostnameMethodInfo
instance (signature ~ (m Bool), MonadIO m, IsProxy a) => O.OverloadedMethod ProxySupportsHostnameMethodInfo a signature where
    overloadedMethod = proxySupportsHostname

instance O.OverloadedMethodInfo ProxySupportsHostnameMethodInfo a where
    overloadedMethodInfo = P.Just (O.ResolvedSymbolInfo {
        O.resolvedSymbolName = "GI.Gio.Interfaces.Proxy.proxySupportsHostname",
        O.resolvedSymbolURL = "https://hackage.haskell.org/package/gi-gio-2.0.30/docs/GI-Gio-Interfaces-Proxy.html#v:proxySupportsHostname"
        })


#endif

-- method Proxy::get_default_for_protocol
-- method type : MemberFunction
-- Args: [ Arg
--           { argCName = "protocol"
--           , argType = TBasicType TUTF8
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText =
--                     Just "the proxy protocol name (e.g. http, socks, etc)"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       ]
-- Lengths: []
-- returnType: Just (TInterface Name { namespace = "Gio" , name = "Proxy" })
-- throws : False
-- Skip return : False

foreign import ccall "g_proxy_get_default_for_protocol" g_proxy_get_default_for_protocol :: 
    CString ->                              -- protocol : TBasicType TUTF8
    IO (Ptr Proxy)

-- | Find the @gio-proxy@ extension point for a proxy implementation that supports
-- the specified protocol.
-- 
-- /Since: 2.26/
proxyGetDefaultForProtocol ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    T.Text
    -- ^ /@protocol@/: the proxy protocol name (e.g. http, socks, etc)
    -> m (Maybe Proxy)
    -- ^ __Returns:__ return a t'GI.Gio.Interfaces.Proxy.Proxy' or NULL if protocol
    --               is not supported.
proxyGetDefaultForProtocol :: forall (m :: * -> *).
(HasCallStack, MonadIO m) =>
Text -> m (Maybe Proxy)
proxyGetDefaultForProtocol Text
protocol = forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$ do
    CString
protocol' <- Text -> IO CString
textToCString Text
protocol
    Ptr Proxy
result <- CString -> IO (Ptr Proxy)
g_proxy_get_default_for_protocol CString
protocol'
    Maybe Proxy
maybeResult <- forall a b. Ptr a -> (Ptr a -> IO b) -> IO (Maybe b)
convertIfNonNull Ptr Proxy
result forall a b. (a -> b) -> a -> b
$ \Ptr Proxy
result' -> do
        Proxy
result'' <- (forall a b.
(HasCallStack, GObject a, GObject b) =>
(ManagedPtr a -> a) -> Ptr b -> IO a
wrapObject ManagedPtr Proxy -> Proxy
Proxy) Ptr Proxy
result'
        forall (m :: * -> *) a. Monad m => a -> m a
return Proxy
result''
    forall a. Ptr a -> IO ()
freeMem CString
protocol'
    forall (m :: * -> *) a. Monad m => a -> m a
return Maybe Proxy
maybeResult

#if defined(ENABLE_OVERLOADING)
#endif

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

#endif