{-# LANGUAGE TypeApplications #-}


-- | Copyright  : Will Thompson and Iñaki García Etxebarria
-- License    : LGPL-2.1
-- Maintainer : Iñaki García Etxebarria
-- 
-- t'GI.Gio.Interfaces.ProxyResolver.ProxyResolver' provides synchronous and asynchronous network proxy
-- resolution. t'GI.Gio.Interfaces.ProxyResolver.ProxyResolver' is used within t'GI.Gio.Objects.SocketClient.SocketClient' through
-- the method 'GI.Gio.Interfaces.SocketConnectable.socketConnectableProxyEnumerate'.
-- 
-- Implementations of t'GI.Gio.Interfaces.ProxyResolver.ProxyResolver' based on libproxy and GNOME settings can
-- be found in glib-networking. GIO comes with an implementation for use inside
-- Flatpak portals.
-- 
-- /Since: 2.26/

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

module GI.Gio.Interfaces.ProxyResolver
    ( 

-- * Exported types
    ProxyResolver(..)                       ,
    IsProxyResolver                         ,
    toProxyResolver                         ,


 -- * 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"), [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"), [isSupported]("GI.Gio.Interfaces.ProxyResolver#g:method:isSupported"), [lookup]("GI.Gio.Interfaces.ProxyResolver#g:method:lookup"), [lookupAsync]("GI.Gio.Interfaces.ProxyResolver#g:method:lookupAsync"), [lookupFinish]("GI.Gio.Interfaces.ProxyResolver#g:method:lookupFinish"), [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"), [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)
    ResolveProxyResolverMethod              ,
#endif

-- ** getDefault #method:getDefault#

    proxyResolverGetDefault                 ,


-- ** isSupported #method:isSupported#

#if defined(ENABLE_OVERLOADING)
    ProxyResolverIsSupportedMethodInfo      ,
#endif
    proxyResolverIsSupported                ,


-- ** lookup #method:lookup#

#if defined(ENABLE_OVERLOADING)
    ProxyResolverLookupMethodInfo           ,
#endif
    proxyResolverLookup                     ,


-- ** lookupAsync #method:lookupAsync#

#if defined(ENABLE_OVERLOADING)
    ProxyResolverLookupAsyncMethodInfo      ,
#endif
    proxyResolverLookupAsync                ,


-- ** lookupFinish #method:lookupFinish#

#if defined(ENABLE_OVERLOADING)
    ProxyResolverLookupFinishMethodInfo     ,
#endif
    proxyResolverLookupFinish               ,




    ) 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.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

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

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

foreign import ccall "g_proxy_resolver_get_type"
    c_g_proxy_resolver_get_type :: IO B.Types.GType

instance B.Types.TypedObject ProxyResolver where
    glibType :: IO GType
glibType = IO GType
c_g_proxy_resolver_get_type

instance B.Types.GObject ProxyResolver

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

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

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

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

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

#if defined(ENABLE_OVERLOADING)
#endif

#if defined(ENABLE_OVERLOADING)
type family ResolveProxyResolverMethod (t :: Symbol) (o :: *) :: * where
    ResolveProxyResolverMethod "bindProperty" o = GObject.Object.ObjectBindPropertyMethodInfo
    ResolveProxyResolverMethod "bindPropertyFull" o = GObject.Object.ObjectBindPropertyFullMethodInfo
    ResolveProxyResolverMethod "forceFloating" o = GObject.Object.ObjectForceFloatingMethodInfo
    ResolveProxyResolverMethod "freezeNotify" o = GObject.Object.ObjectFreezeNotifyMethodInfo
    ResolveProxyResolverMethod "getv" o = GObject.Object.ObjectGetvMethodInfo
    ResolveProxyResolverMethod "isFloating" o = GObject.Object.ObjectIsFloatingMethodInfo
    ResolveProxyResolverMethod "isSupported" o = ProxyResolverIsSupportedMethodInfo
    ResolveProxyResolverMethod "lookup" o = ProxyResolverLookupMethodInfo
    ResolveProxyResolverMethod "lookupAsync" o = ProxyResolverLookupAsyncMethodInfo
    ResolveProxyResolverMethod "lookupFinish" o = ProxyResolverLookupFinishMethodInfo
    ResolveProxyResolverMethod "notify" o = GObject.Object.ObjectNotifyMethodInfo
    ResolveProxyResolverMethod "notifyByPspec" o = GObject.Object.ObjectNotifyByPspecMethodInfo
    ResolveProxyResolverMethod "ref" o = GObject.Object.ObjectRefMethodInfo
    ResolveProxyResolverMethod "refSink" o = GObject.Object.ObjectRefSinkMethodInfo
    ResolveProxyResolverMethod "runDispose" o = GObject.Object.ObjectRunDisposeMethodInfo
    ResolveProxyResolverMethod "stealData" o = GObject.Object.ObjectStealDataMethodInfo
    ResolveProxyResolverMethod "stealQdata" o = GObject.Object.ObjectStealQdataMethodInfo
    ResolveProxyResolverMethod "thawNotify" o = GObject.Object.ObjectThawNotifyMethodInfo
    ResolveProxyResolverMethod "unref" o = GObject.Object.ObjectUnrefMethodInfo
    ResolveProxyResolverMethod "watchClosure" o = GObject.Object.ObjectWatchClosureMethodInfo
    ResolveProxyResolverMethod "getData" o = GObject.Object.ObjectGetDataMethodInfo
    ResolveProxyResolverMethod "getProperty" o = GObject.Object.ObjectGetPropertyMethodInfo
    ResolveProxyResolverMethod "getQdata" o = GObject.Object.ObjectGetQdataMethodInfo
    ResolveProxyResolverMethod "setData" o = GObject.Object.ObjectSetDataMethodInfo
    ResolveProxyResolverMethod "setDataFull" o = GObject.Object.ObjectSetDataFullMethodInfo
    ResolveProxyResolverMethod "setProperty" o = GObject.Object.ObjectSetPropertyMethodInfo
    ResolveProxyResolverMethod l o = O.MethodResolutionFailed l o

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

#endif

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

#endif

-- method ProxyResolver::is_supported
-- method type : OrdinaryMethod
-- Args: [ Arg
--           { argCName = "resolver"
--           , argType =
--               TInterface Name { namespace = "Gio" , name = "ProxyResolver" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "a #GProxyResolver" , 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_resolver_is_supported" g_proxy_resolver_is_supported :: 
    Ptr ProxyResolver ->                    -- resolver : TInterface (Name {namespace = "Gio", name = "ProxyResolver"})
    IO CInt

-- | Checks if /@resolver@/ can be used on this system. (This is used
-- internally; 'GI.Gio.Functions.proxyResolverGetDefault' will only return a proxy
-- resolver that returns 'P.True' for this method.)
-- 
-- /Since: 2.26/
proxyResolverIsSupported ::
    (B.CallStack.HasCallStack, MonadIO m, IsProxyResolver a) =>
    a
    -- ^ /@resolver@/: a t'GI.Gio.Interfaces.ProxyResolver.ProxyResolver'
    -> m Bool
    -- ^ __Returns:__ 'P.True' if /@resolver@/ is supported.
proxyResolverIsSupported :: forall (m :: * -> *) a.
(HasCallStack, MonadIO m, IsProxyResolver a) =>
a -> m Bool
proxyResolverIsSupported a
resolver = IO Bool -> m Bool
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Bool -> m Bool) -> IO Bool -> m Bool
forall a b. (a -> b) -> a -> b
$ do
    Ptr ProxyResolver
resolver' <- a -> IO (Ptr ProxyResolver)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr a
resolver
    CInt
result <- Ptr ProxyResolver -> IO CInt
g_proxy_resolver_is_supported Ptr ProxyResolver
resolver'
    let result' :: Bool
result' = (CInt -> CInt -> Bool
forall a. Eq a => a -> a -> Bool
/= CInt
0) CInt
result
    a -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr a
resolver
    Bool -> IO Bool
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
result'

#if defined(ENABLE_OVERLOADING)
data ProxyResolverIsSupportedMethodInfo
instance (signature ~ (m Bool), MonadIO m, IsProxyResolver a) => O.OverloadedMethod ProxyResolverIsSupportedMethodInfo a signature where
    overloadedMethod = proxyResolverIsSupported

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


#endif

-- method ProxyResolver::lookup
-- method type : OrdinaryMethod
-- Args: [ Arg
--           { argCName = "resolver"
--           , argType =
--               TInterface Name { namespace = "Gio" , name = "ProxyResolver" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "a #GProxyResolver" , sinceVersion = Nothing }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "uri"
--           , argType = TBasicType TUTF8
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText =
--                     Just "a URI representing the destination to connect to"
--                 , 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, or %NULL"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       ]
-- Lengths: []
-- returnType: Just (TCArray True (-1) (-1) (TBasicType TUTF8))
-- throws : True
-- Skip return : False

foreign import ccall "g_proxy_resolver_lookup" g_proxy_resolver_lookup :: 
    Ptr ProxyResolver ->                    -- resolver : TInterface (Name {namespace = "Gio", name = "ProxyResolver"})
    CString ->                              -- uri : TBasicType TUTF8
    Ptr Gio.Cancellable.Cancellable ->      -- cancellable : TInterface (Name {namespace = "Gio", name = "Cancellable"})
    Ptr (Ptr GError) ->                     -- error
    IO (Ptr CString)

-- | Looks into the system proxy configuration to determine what proxy,
-- if any, to use to connect to /@uri@/. The returned proxy URIs are of
-- the form @\<protocol>:\/\/[user[:password]\@]host:port@ or
-- @direct:\/\/@, where \<protocol> could be http, rtsp, socks
-- or other proxying protocol.
-- 
-- If you don\'t know what network protocol is being used on the
-- socket, you should use @none@ as the URI protocol.
-- In this case, the resolver might still return a generic proxy type
-- (such as SOCKS), but would not return protocol-specific proxy types
-- (such as http).
-- 
-- @direct:\/\/@ is used when no proxy is needed.
-- Direct connection should not be attempted unless it is part of the
-- returned array of proxies.
-- 
-- /Since: 2.26/
proxyResolverLookup ::
    (B.CallStack.HasCallStack, MonadIO m, IsProxyResolver a, Gio.Cancellable.IsCancellable b) =>
    a
    -- ^ /@resolver@/: a t'GI.Gio.Interfaces.ProxyResolver.ProxyResolver'
    -> T.Text
    -- ^ /@uri@/: a URI representing the destination to connect to
    -> Maybe (b)
    -- ^ /@cancellable@/: a t'GI.Gio.Objects.Cancellable.Cancellable', or 'P.Nothing'
    -> m [T.Text]
    -- ^ __Returns:__ A
    --               NULL-terminated array of proxy URIs. Must be freed
    --               with 'GI.GLib.Functions.strfreev'. /(Can throw 'Data.GI.Base.GError.GError')/
proxyResolverLookup :: forall (m :: * -> *) a b.
(HasCallStack, MonadIO m, IsProxyResolver a, IsCancellable b) =>
a -> Text -> Maybe b -> m [Text]
proxyResolverLookup a
resolver Text
uri Maybe b
cancellable = IO [Text] -> m [Text]
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO [Text] -> m [Text]) -> IO [Text] -> m [Text]
forall a b. (a -> b) -> a -> b
$ do
    Ptr ProxyResolver
resolver' <- a -> IO (Ptr ProxyResolver)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr a
resolver
    CString
uri' <- Text -> IO CString
textToCString Text
uri
    Ptr Cancellable
maybeCancellable <- case Maybe b
cancellable of
        Maybe b
Nothing -> Ptr Cancellable -> IO (Ptr Cancellable)
forall (m :: * -> *) a. Monad m => a -> m a
return Ptr Cancellable
forall a. Ptr a
nullPtr
        Just b
jCancellable -> do
            Ptr Cancellable
jCancellable' <- b -> IO (Ptr Cancellable)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr b
jCancellable
            Ptr Cancellable -> IO (Ptr Cancellable)
forall (m :: * -> *) a. Monad m => a -> m a
return Ptr Cancellable
jCancellable'
    IO [Text] -> IO () -> IO [Text]
forall a b. IO a -> IO b -> IO a
onException (do
        Ptr CString
result <- (Ptr (Ptr GError) -> IO (Ptr CString)) -> IO (Ptr CString)
forall a. (Ptr (Ptr GError) -> IO a) -> IO a
propagateGError ((Ptr (Ptr GError) -> IO (Ptr CString)) -> IO (Ptr CString))
-> (Ptr (Ptr GError) -> IO (Ptr CString)) -> IO (Ptr CString)
forall a b. (a -> b) -> a -> b
$ Ptr ProxyResolver
-> CString
-> Ptr Cancellable
-> Ptr (Ptr GError)
-> IO (Ptr CString)
g_proxy_resolver_lookup Ptr ProxyResolver
resolver' CString
uri' Ptr Cancellable
maybeCancellable
        Text -> Ptr CString -> IO ()
forall a. HasCallStack => Text -> Ptr a -> IO ()
checkUnexpectedReturnNULL Text
"proxyResolverLookup" Ptr CString
result
        [Text]
result' <- HasCallStack => Ptr CString -> IO [Text]
Ptr CString -> IO [Text]
unpackZeroTerminatedUTF8CArray Ptr CString
result
        (CString -> IO ()) -> Ptr CString -> IO ()
forall a b. (Ptr a -> IO b) -> Ptr (Ptr a) -> IO ()
mapZeroTerminatedCArray CString -> IO ()
forall a. Ptr a -> IO ()
freeMem Ptr CString
result
        Ptr CString -> IO ()
forall a. Ptr a -> IO ()
freeMem Ptr CString
result
        a -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr a
resolver
        Maybe b -> (b -> IO ()) -> IO ()
forall (m :: * -> *) a. Monad m => Maybe a -> (a -> m ()) -> m ()
whenJust Maybe b
cancellable b -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr
        CString -> IO ()
forall a. Ptr a -> IO ()
freeMem CString
uri'
        [Text] -> IO [Text]
forall (m :: * -> *) a. Monad m => a -> m a
return [Text]
result'
     ) (do
        CString -> IO ()
forall a. Ptr a -> IO ()
freeMem CString
uri'
     )

#if defined(ENABLE_OVERLOADING)
data ProxyResolverLookupMethodInfo
instance (signature ~ (T.Text -> Maybe (b) -> m [T.Text]), MonadIO m, IsProxyResolver a, Gio.Cancellable.IsCancellable b) => O.OverloadedMethod ProxyResolverLookupMethodInfo a signature where
    overloadedMethod = proxyResolverLookup

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


#endif

-- method ProxyResolver::lookup_async
-- method type : OrdinaryMethod
-- Args: [ Arg
--           { argCName = "resolver"
--           , argType =
--               TInterface Name { namespace = "Gio" , name = "ProxyResolver" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "a #GProxyResolver" , sinceVersion = Nothing }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "uri"
--           , argType = TBasicType TUTF8
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText =
--                     Just "a URI representing the destination to connect to"
--                 , 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, or %NULL"
--                 , 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 "callback to call after resolution completes"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeAsync
--           , argClosure = 4
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "user_data"
--           , argType = TBasicType TPtr
--           , direction = DirectionIn
--           , mayBeNull = True
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "data for @callback" , 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_resolver_lookup_async" g_proxy_resolver_lookup_async :: 
    Ptr ProxyResolver ->                    -- resolver : TInterface (Name {namespace = "Gio", name = "ProxyResolver"})
    CString ->                              -- uri : TBasicType TUTF8
    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 lookup of proxy. See 'GI.Gio.Interfaces.ProxyResolver.proxyResolverLookup' for more
-- details.
-- 
-- /Since: 2.26/
proxyResolverLookupAsync ::
    (B.CallStack.HasCallStack, MonadIO m, IsProxyResolver a, Gio.Cancellable.IsCancellable b) =>
    a
    -- ^ /@resolver@/: a t'GI.Gio.Interfaces.ProxyResolver.ProxyResolver'
    -> T.Text
    -- ^ /@uri@/: a URI representing the destination to connect to
    -> Maybe (b)
    -- ^ /@cancellable@/: a t'GI.Gio.Objects.Cancellable.Cancellable', or 'P.Nothing'
    -> Maybe (Gio.Callbacks.AsyncReadyCallback)
    -- ^ /@callback@/: callback to call after resolution completes
    -> m ()
proxyResolverLookupAsync :: forall (m :: * -> *) a b.
(HasCallStack, MonadIO m, IsProxyResolver a, IsCancellable b) =>
a -> Text -> Maybe b -> Maybe AsyncReadyCallback -> m ()
proxyResolverLookupAsync a
resolver Text
uri Maybe b
cancellable Maybe AsyncReadyCallback
callback = IO () -> m ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$ do
    Ptr ProxyResolver
resolver' <- a -> IO (Ptr ProxyResolver)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr a
resolver
    CString
uri' <- Text -> IO CString
textToCString Text
uri
    Ptr Cancellable
maybeCancellable <- case Maybe b
cancellable of
        Maybe b
Nothing -> Ptr Cancellable -> IO (Ptr Cancellable)
forall (m :: * -> *) a. Monad m => a -> m a
return Ptr Cancellable
forall a. Ptr a
nullPtr
        Just b
jCancellable -> do
            Ptr Cancellable
jCancellable' <- b -> IO (Ptr Cancellable)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr b
jCancellable
            Ptr Cancellable -> IO (Ptr Cancellable)
forall (m :: * -> *) a. Monad m => a -> m a
return Ptr Cancellable
jCancellable'
    FunPtr C_AsyncReadyCallback
maybeCallback <- case Maybe AsyncReadyCallback
callback of
        Maybe AsyncReadyCallback
Nothing -> FunPtr C_AsyncReadyCallback -> IO (FunPtr C_AsyncReadyCallback)
forall (m :: * -> *) a. Monad m => a -> m a
return (Ptr Any -> FunPtr C_AsyncReadyCallback
forall a b. Ptr a -> FunPtr b
castPtrToFunPtr Ptr Any
forall a. Ptr a
nullPtr)
        Just AsyncReadyCallback
jCallback -> do
            Ptr (FunPtr C_AsyncReadyCallback)
ptrcallback <- IO (Ptr (FunPtr C_AsyncReadyCallback))
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 (Ptr (FunPtr C_AsyncReadyCallback)
-> Maybe (Ptr (FunPtr C_AsyncReadyCallback))
forall a. a -> Maybe a
Just Ptr (FunPtr C_AsyncReadyCallback)
ptrcallback) (AsyncReadyCallback -> AsyncReadyCallback_WithClosures
Gio.Callbacks.drop_closures_AsyncReadyCallback AsyncReadyCallback
jCallback))
            Ptr (FunPtr C_AsyncReadyCallback)
-> FunPtr C_AsyncReadyCallback -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke Ptr (FunPtr C_AsyncReadyCallback)
ptrcallback FunPtr C_AsyncReadyCallback
jCallback'
            FunPtr C_AsyncReadyCallback -> IO (FunPtr C_AsyncReadyCallback)
forall (m :: * -> *) a. Monad m => a -> m a
return FunPtr C_AsyncReadyCallback
jCallback'
    let userData :: Ptr a
userData = Ptr a
forall a. Ptr a
nullPtr
    Ptr ProxyResolver
-> CString
-> Ptr Cancellable
-> FunPtr C_AsyncReadyCallback
-> Ptr ()
-> IO ()
g_proxy_resolver_lookup_async Ptr ProxyResolver
resolver' CString
uri' Ptr Cancellable
maybeCancellable FunPtr C_AsyncReadyCallback
maybeCallback Ptr ()
forall a. Ptr a
userData
    a -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr a
resolver
    Maybe b -> (b -> IO ()) -> IO ()
forall (m :: * -> *) a. Monad m => Maybe a -> (a -> m ()) -> m ()
whenJust Maybe b
cancellable b -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr
    CString -> IO ()
forall a. Ptr a -> IO ()
freeMem CString
uri'
    () -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()

#if defined(ENABLE_OVERLOADING)
data ProxyResolverLookupAsyncMethodInfo
instance (signature ~ (T.Text -> Maybe (b) -> Maybe (Gio.Callbacks.AsyncReadyCallback) -> m ()), MonadIO m, IsProxyResolver a, Gio.Cancellable.IsCancellable b) => O.OverloadedMethod ProxyResolverLookupAsyncMethodInfo a signature where
    overloadedMethod = proxyResolverLookupAsync

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


#endif

-- method ProxyResolver::lookup_finish
-- method type : OrdinaryMethod
-- Args: [ Arg
--           { argCName = "resolver"
--           , argType =
--               TInterface Name { namespace = "Gio" , name = "ProxyResolver" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "a #GProxyResolver" , 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 "the result passed to your #GAsyncReadyCallback"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       ]
-- Lengths: []
-- returnType: Just (TCArray True (-1) (-1) (TBasicType TUTF8))
-- throws : True
-- Skip return : False

foreign import ccall "g_proxy_resolver_lookup_finish" g_proxy_resolver_lookup_finish :: 
    Ptr ProxyResolver ->                    -- resolver : TInterface (Name {namespace = "Gio", name = "ProxyResolver"})
    Ptr Gio.AsyncResult.AsyncResult ->      -- result : TInterface (Name {namespace = "Gio", name = "AsyncResult"})
    Ptr (Ptr GError) ->                     -- error
    IO (Ptr CString)

-- | Call this function to obtain the array of proxy URIs when
-- 'GI.Gio.Interfaces.ProxyResolver.proxyResolverLookupAsync' is complete. See
-- 'GI.Gio.Interfaces.ProxyResolver.proxyResolverLookup' for more details.
-- 
-- /Since: 2.26/
proxyResolverLookupFinish ::
    (B.CallStack.HasCallStack, MonadIO m, IsProxyResolver a, Gio.AsyncResult.IsAsyncResult b) =>
    a
    -- ^ /@resolver@/: a t'GI.Gio.Interfaces.ProxyResolver.ProxyResolver'
    -> b
    -- ^ /@result@/: the result passed to your t'GI.Gio.Callbacks.AsyncReadyCallback'
    -> m [T.Text]
    -- ^ __Returns:__ A
    --               NULL-terminated array of proxy URIs. Must be freed
    --               with 'GI.GLib.Functions.strfreev'. /(Can throw 'Data.GI.Base.GError.GError')/
proxyResolverLookupFinish :: forall (m :: * -> *) a b.
(HasCallStack, MonadIO m, IsProxyResolver a, IsAsyncResult b) =>
a -> b -> m [Text]
proxyResolverLookupFinish a
resolver b
result_ = IO [Text] -> m [Text]
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO [Text] -> m [Text]) -> IO [Text] -> m [Text]
forall a b. (a -> b) -> a -> b
$ do
    Ptr ProxyResolver
resolver' <- a -> IO (Ptr ProxyResolver)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr a
resolver
    Ptr AsyncResult
result_' <- b -> IO (Ptr AsyncResult)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr b
result_
    IO [Text] -> IO () -> IO [Text]
forall a b. IO a -> IO b -> IO a
onException (do
        Ptr CString
result <- (Ptr (Ptr GError) -> IO (Ptr CString)) -> IO (Ptr CString)
forall a. (Ptr (Ptr GError) -> IO a) -> IO a
propagateGError ((Ptr (Ptr GError) -> IO (Ptr CString)) -> IO (Ptr CString))
-> (Ptr (Ptr GError) -> IO (Ptr CString)) -> IO (Ptr CString)
forall a b. (a -> b) -> a -> b
$ Ptr ProxyResolver
-> Ptr AsyncResult -> Ptr (Ptr GError) -> IO (Ptr CString)
g_proxy_resolver_lookup_finish Ptr ProxyResolver
resolver' Ptr AsyncResult
result_'
        Text -> Ptr CString -> IO ()
forall a. HasCallStack => Text -> Ptr a -> IO ()
checkUnexpectedReturnNULL Text
"proxyResolverLookupFinish" Ptr CString
result
        [Text]
result' <- HasCallStack => Ptr CString -> IO [Text]
Ptr CString -> IO [Text]
unpackZeroTerminatedUTF8CArray Ptr CString
result
        (CString -> IO ()) -> Ptr CString -> IO ()
forall a b. (Ptr a -> IO b) -> Ptr (Ptr a) -> IO ()
mapZeroTerminatedCArray CString -> IO ()
forall a. Ptr a -> IO ()
freeMem Ptr CString
result
        Ptr CString -> IO ()
forall a. Ptr a -> IO ()
freeMem Ptr CString
result
        a -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr a
resolver
        b -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr b
result_
        [Text] -> IO [Text]
forall (m :: * -> *) a. Monad m => a -> m a
return [Text]
result'
     ) (do
        () -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
     )

#if defined(ENABLE_OVERLOADING)
data ProxyResolverLookupFinishMethodInfo
instance (signature ~ (b -> m [T.Text]), MonadIO m, IsProxyResolver a, Gio.AsyncResult.IsAsyncResult b) => O.OverloadedMethod ProxyResolverLookupFinishMethodInfo a signature where
    overloadedMethod = proxyResolverLookupFinish

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


#endif

-- method ProxyResolver::get_default
-- method type : MemberFunction
-- Args: []
-- Lengths: []
-- returnType: Just
--               (TInterface Name { namespace = "Gio" , name = "ProxyResolver" })
-- throws : False
-- Skip return : False

foreign import ccall "g_proxy_resolver_get_default" g_proxy_resolver_get_default :: 
    IO (Ptr ProxyResolver)

-- | Gets the default t'GI.Gio.Interfaces.ProxyResolver.ProxyResolver' for the system.
-- 
-- /Since: 2.26/
proxyResolverGetDefault ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    m ProxyResolver
    -- ^ __Returns:__ the default t'GI.Gio.Interfaces.ProxyResolver.ProxyResolver', which
    --     will be a dummy object if no proxy resolver is available
proxyResolverGetDefault :: forall (m :: * -> *). (HasCallStack, MonadIO m) => m ProxyResolver
proxyResolverGetDefault  = IO ProxyResolver -> m ProxyResolver
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO ProxyResolver -> m ProxyResolver)
-> IO ProxyResolver -> m ProxyResolver
forall a b. (a -> b) -> a -> b
$ do
    Ptr ProxyResolver
result <- IO (Ptr ProxyResolver)
g_proxy_resolver_get_default
    Text -> Ptr ProxyResolver -> IO ()
forall a. HasCallStack => Text -> Ptr a -> IO ()
checkUnexpectedReturnNULL Text
"proxyResolverGetDefault" Ptr ProxyResolver
result
    ProxyResolver
result' <- ((ManagedPtr ProxyResolver -> ProxyResolver)
-> Ptr ProxyResolver -> IO ProxyResolver
forall a b.
(HasCallStack, GObject a, GObject b) =>
(ManagedPtr a -> a) -> Ptr b -> IO a
newObject ManagedPtr ProxyResolver -> ProxyResolver
ProxyResolver) Ptr ProxyResolver
result
    ProxyResolver -> IO ProxyResolver
forall (m :: * -> *) a. Monad m => a -> m a
return ProxyResolver
result'

#if defined(ENABLE_OVERLOADING)
#endif

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

#endif