{- | Copyright : Will Thompson, Iñaki García Etxebarria and Jonas Platte License : LGPL-2.1 Maintainer : Iñaki García Etxebarria (inaki@blueleaf.cc) 'GI.Gio.Objects.NetworkAddress.NetworkAddress' provides an easy way to resolve a hostname and then attempt to connect to that host, handling the possibility of multiple IP addresses and multiple address families. See 'GI.Gio.Interfaces.SocketConnectable.SocketConnectable' for an example of using the connectable interface. -} #define ENABLE_OVERLOADING (MIN_VERSION_haskell_gi_overloading(1,0,0) \ && !defined(__HADDOCK_VERSION__)) module GI.Gio.Objects.NetworkAddress ( -- * Exported types NetworkAddress(..) , IsNetworkAddress , toNetworkAddress , noNetworkAddress , -- * Methods -- ** getHostname #method:getHostname# #if ENABLE_OVERLOADING NetworkAddressGetHostnameMethodInfo , #endif networkAddressGetHostname , -- ** getPort #method:getPort# #if ENABLE_OVERLOADING NetworkAddressGetPortMethodInfo , #endif networkAddressGetPort , -- ** getScheme #method:getScheme# #if ENABLE_OVERLOADING NetworkAddressGetSchemeMethodInfo , #endif networkAddressGetScheme , -- ** new #method:new# networkAddressNew , -- ** newLoopback #method:newLoopback# networkAddressNewLoopback , -- ** parse #method:parse# networkAddressParse , -- ** parseUri #method:parseUri# networkAddressParseUri , -- * Properties -- ** hostname #attr:hostname# {- | /No description available in the introspection data./ -} #if ENABLE_OVERLOADING NetworkAddressHostnamePropertyInfo , #endif constructNetworkAddressHostname , getNetworkAddressHostname , #if ENABLE_OVERLOADING networkAddressHostname , #endif -- ** port #attr:port# {- | /No description available in the introspection data./ -} #if ENABLE_OVERLOADING NetworkAddressPortPropertyInfo , #endif constructNetworkAddressPort , getNetworkAddressPort , #if ENABLE_OVERLOADING networkAddressPort , #endif -- ** scheme #attr:scheme# {- | /No description available in the introspection data./ -} #if ENABLE_OVERLOADING NetworkAddressSchemePropertyInfo , #endif constructNetworkAddressScheme , getNetworkAddressScheme , #if ENABLE_OVERLOADING networkAddressScheme , #endif ) 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.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.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.GObject.Objects.Object as GObject.Object import {-# SOURCE #-} qualified GI.Gio.Interfaces.SocketConnectable as Gio.SocketConnectable -- | Memory-managed wrapper type. newtype NetworkAddress = NetworkAddress (ManagedPtr NetworkAddress) foreign import ccall "g_network_address_get_type" c_g_network_address_get_type :: IO GType instance GObject NetworkAddress where gobjectType = c_g_network_address_get_type -- | Type class for types which can be safely cast to `NetworkAddress`, for instance with `toNetworkAddress`. class (GObject o, O.IsDescendantOf NetworkAddress o) => IsNetworkAddress o instance (GObject o, O.IsDescendantOf NetworkAddress o) => IsNetworkAddress o instance O.HasParentTypes NetworkAddress type instance O.ParentTypes NetworkAddress = '[GObject.Object.Object, Gio.SocketConnectable.SocketConnectable] -- | Cast to `NetworkAddress`, for types for which this is known to be safe. For general casts, use `Data.GI.Base.ManagedPtr.castTo`. toNetworkAddress :: (MonadIO m, IsNetworkAddress o) => o -> m NetworkAddress toNetworkAddress = liftIO . unsafeCastTo NetworkAddress -- | A convenience alias for `Nothing` :: `Maybe` `NetworkAddress`. noNetworkAddress :: Maybe NetworkAddress noNetworkAddress = Nothing #if ENABLE_OVERLOADING type family ResolveNetworkAddressMethod (t :: Symbol) (o :: *) :: * where ResolveNetworkAddressMethod "bindProperty" o = GObject.Object.ObjectBindPropertyMethodInfo ResolveNetworkAddressMethod "bindPropertyFull" o = GObject.Object.ObjectBindPropertyFullMethodInfo ResolveNetworkAddressMethod "enumerate" o = Gio.SocketConnectable.SocketConnectableEnumerateMethodInfo ResolveNetworkAddressMethod "forceFloating" o = GObject.Object.ObjectForceFloatingMethodInfo ResolveNetworkAddressMethod "freezeNotify" o = GObject.Object.ObjectFreezeNotifyMethodInfo ResolveNetworkAddressMethod "getv" o = GObject.Object.ObjectGetvMethodInfo ResolveNetworkAddressMethod "isFloating" o = GObject.Object.ObjectIsFloatingMethodInfo ResolveNetworkAddressMethod "notify" o = GObject.Object.ObjectNotifyMethodInfo ResolveNetworkAddressMethod "notifyByPspec" o = GObject.Object.ObjectNotifyByPspecMethodInfo ResolveNetworkAddressMethod "proxyEnumerate" o = Gio.SocketConnectable.SocketConnectableProxyEnumerateMethodInfo ResolveNetworkAddressMethod "ref" o = GObject.Object.ObjectRefMethodInfo ResolveNetworkAddressMethod "refSink" o = GObject.Object.ObjectRefSinkMethodInfo ResolveNetworkAddressMethod "runDispose" o = GObject.Object.ObjectRunDisposeMethodInfo ResolveNetworkAddressMethod "stealData" o = GObject.Object.ObjectStealDataMethodInfo ResolveNetworkAddressMethod "stealQdata" o = GObject.Object.ObjectStealQdataMethodInfo ResolveNetworkAddressMethod "thawNotify" o = GObject.Object.ObjectThawNotifyMethodInfo ResolveNetworkAddressMethod "toString" o = Gio.SocketConnectable.SocketConnectableToStringMethodInfo ResolveNetworkAddressMethod "unref" o = GObject.Object.ObjectUnrefMethodInfo ResolveNetworkAddressMethod "watchClosure" o = GObject.Object.ObjectWatchClosureMethodInfo ResolveNetworkAddressMethod "getData" o = GObject.Object.ObjectGetDataMethodInfo ResolveNetworkAddressMethod "getHostname" o = NetworkAddressGetHostnameMethodInfo ResolveNetworkAddressMethod "getPort" o = NetworkAddressGetPortMethodInfo ResolveNetworkAddressMethod "getProperty" o = GObject.Object.ObjectGetPropertyMethodInfo ResolveNetworkAddressMethod "getQdata" o = GObject.Object.ObjectGetQdataMethodInfo ResolveNetworkAddressMethod "getScheme" o = NetworkAddressGetSchemeMethodInfo ResolveNetworkAddressMethod "setData" o = GObject.Object.ObjectSetDataMethodInfo ResolveNetworkAddressMethod "setProperty" o = GObject.Object.ObjectSetPropertyMethodInfo ResolveNetworkAddressMethod l o = O.MethodResolutionFailed l o instance (info ~ ResolveNetworkAddressMethod t NetworkAddress, O.MethodInfo info NetworkAddress p) => OL.IsLabel t (NetworkAddress -> p) where #if MIN_VERSION_base(4,10,0) fromLabel = O.overloadedMethod (O.MethodProxy :: O.MethodProxy info) #else fromLabel _ = O.overloadedMethod (O.MethodProxy :: O.MethodProxy info) #endif #endif -- VVV Prop "hostname" -- Type: TBasicType TUTF8 -- Flags: [PropertyReadable,PropertyWritable,PropertyConstructOnly] -- Nullable: (Just False,Nothing) {- | Get the value of the “@hostname@” property. When is enabled, this is equivalent to @ 'Data.GI.Base.Attributes.get' networkAddress #hostname @ -} getNetworkAddressHostname :: (MonadIO m, IsNetworkAddress o) => o -> m T.Text getNetworkAddressHostname obj = liftIO $ checkUnexpectedNothing "getNetworkAddressHostname" $ B.Properties.getObjectPropertyString obj "hostname" {- | Construct a `GValueConstruct` with valid value for the “@hostname@” property. This is rarely needed directly, but it is used by `Data.GI.Base.Constructible.new`. -} constructNetworkAddressHostname :: (IsNetworkAddress o) => T.Text -> IO (GValueConstruct o) constructNetworkAddressHostname val = B.Properties.constructObjectPropertyString "hostname" (Just val) #if ENABLE_OVERLOADING data NetworkAddressHostnamePropertyInfo instance AttrInfo NetworkAddressHostnamePropertyInfo where type AttrAllowedOps NetworkAddressHostnamePropertyInfo = '[ 'AttrConstruct, 'AttrGet, 'AttrClear] type AttrSetTypeConstraint NetworkAddressHostnamePropertyInfo = (~) T.Text type AttrBaseTypeConstraint NetworkAddressHostnamePropertyInfo = IsNetworkAddress type AttrGetType NetworkAddressHostnamePropertyInfo = T.Text type AttrLabel NetworkAddressHostnamePropertyInfo = "hostname" type AttrOrigin NetworkAddressHostnamePropertyInfo = NetworkAddress attrGet _ = getNetworkAddressHostname attrSet _ = undefined attrConstruct _ = constructNetworkAddressHostname attrClear _ = undefined #endif -- VVV Prop "port" -- Type: TBasicType TUInt -- Flags: [PropertyReadable,PropertyWritable,PropertyConstructOnly] -- Nullable: (Nothing,Nothing) {- | Get the value of the “@port@” property. When is enabled, this is equivalent to @ 'Data.GI.Base.Attributes.get' networkAddress #port @ -} getNetworkAddressPort :: (MonadIO m, IsNetworkAddress o) => o -> m Word32 getNetworkAddressPort obj = liftIO $ B.Properties.getObjectPropertyUInt32 obj "port" {- | Construct a `GValueConstruct` with valid value for the “@port@” property. This is rarely needed directly, but it is used by `Data.GI.Base.Constructible.new`. -} constructNetworkAddressPort :: (IsNetworkAddress o) => Word32 -> IO (GValueConstruct o) constructNetworkAddressPort val = B.Properties.constructObjectPropertyUInt32 "port" val #if ENABLE_OVERLOADING data NetworkAddressPortPropertyInfo instance AttrInfo NetworkAddressPortPropertyInfo where type AttrAllowedOps NetworkAddressPortPropertyInfo = '[ 'AttrConstruct, 'AttrGet] type AttrSetTypeConstraint NetworkAddressPortPropertyInfo = (~) Word32 type AttrBaseTypeConstraint NetworkAddressPortPropertyInfo = IsNetworkAddress type AttrGetType NetworkAddressPortPropertyInfo = Word32 type AttrLabel NetworkAddressPortPropertyInfo = "port" type AttrOrigin NetworkAddressPortPropertyInfo = NetworkAddress attrGet _ = getNetworkAddressPort attrSet _ = undefined attrConstruct _ = constructNetworkAddressPort attrClear _ = undefined #endif -- VVV Prop "scheme" -- Type: TBasicType TUTF8 -- Flags: [PropertyReadable,PropertyWritable,PropertyConstructOnly] -- Nullable: (Just False,Nothing) {- | Get the value of the “@scheme@” property. When is enabled, this is equivalent to @ 'Data.GI.Base.Attributes.get' networkAddress #scheme @ -} getNetworkAddressScheme :: (MonadIO m, IsNetworkAddress o) => o -> m T.Text getNetworkAddressScheme obj = liftIO $ checkUnexpectedNothing "getNetworkAddressScheme" $ B.Properties.getObjectPropertyString obj "scheme" {- | Construct a `GValueConstruct` with valid value for the “@scheme@” property. This is rarely needed directly, but it is used by `Data.GI.Base.Constructible.new`. -} constructNetworkAddressScheme :: (IsNetworkAddress o) => T.Text -> IO (GValueConstruct o) constructNetworkAddressScheme val = B.Properties.constructObjectPropertyString "scheme" (Just val) #if ENABLE_OVERLOADING data NetworkAddressSchemePropertyInfo instance AttrInfo NetworkAddressSchemePropertyInfo where type AttrAllowedOps NetworkAddressSchemePropertyInfo = '[ 'AttrConstruct, 'AttrGet, 'AttrClear] type AttrSetTypeConstraint NetworkAddressSchemePropertyInfo = (~) T.Text type AttrBaseTypeConstraint NetworkAddressSchemePropertyInfo = IsNetworkAddress type AttrGetType NetworkAddressSchemePropertyInfo = T.Text type AttrLabel NetworkAddressSchemePropertyInfo = "scheme" type AttrOrigin NetworkAddressSchemePropertyInfo = NetworkAddress attrGet _ = getNetworkAddressScheme attrSet _ = undefined attrConstruct _ = constructNetworkAddressScheme attrClear _ = undefined #endif #if ENABLE_OVERLOADING instance O.HasAttributeList NetworkAddress type instance O.AttributeList NetworkAddress = NetworkAddressAttributeList type NetworkAddressAttributeList = ('[ '("hostname", NetworkAddressHostnamePropertyInfo), '("port", NetworkAddressPortPropertyInfo), '("scheme", NetworkAddressSchemePropertyInfo)] :: [(Symbol, *)]) #endif #if ENABLE_OVERLOADING networkAddressHostname :: AttrLabelProxy "hostname" networkAddressHostname = AttrLabelProxy networkAddressPort :: AttrLabelProxy "port" networkAddressPort = AttrLabelProxy networkAddressScheme :: AttrLabelProxy "scheme" networkAddressScheme = AttrLabelProxy #endif #if ENABLE_OVERLOADING type instance O.SignalList NetworkAddress = NetworkAddressSignalList type NetworkAddressSignalList = ('[ '("notify", GObject.Object.ObjectNotifySignalInfo)] :: [(Symbol, *)]) #endif -- method NetworkAddress::new -- method type : Constructor -- Args : [Arg {argCName = "hostname", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the hostname", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "port", argType = TBasicType TUInt16, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the port", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}] -- Lengths : [] -- returnType : Just (TInterface (Name {namespace = "Gio", name = "NetworkAddress"})) -- throws : False -- Skip return : False foreign import ccall "g_network_address_new" g_network_address_new :: CString -> -- hostname : TBasicType TUTF8 Word16 -> -- port : TBasicType TUInt16 IO (Ptr NetworkAddress) {- | Creates a new 'GI.Gio.Interfaces.SocketConnectable.SocketConnectable' for connecting to the given /@hostname@/ and /@port@/. Note that depending on the configuration of the machine, a /@hostname@/ of @localhost@ may refer to the IPv4 loopback address only, or to both IPv4 and IPv6; use 'GI.Gio.Objects.NetworkAddress.networkAddressNewLoopback' to create a 'GI.Gio.Objects.NetworkAddress.NetworkAddress' that is guaranteed to resolve to both addresses. /Since: 2.22/ -} networkAddressNew :: (B.CallStack.HasCallStack, MonadIO m) => T.Text {- ^ /@hostname@/: the hostname -} -> Word16 {- ^ /@port@/: the port -} -> m NetworkAddress {- ^ __Returns:__ the new 'GI.Gio.Objects.NetworkAddress.NetworkAddress' -} networkAddressNew hostname port = liftIO $ do hostname' <- textToCString hostname result <- g_network_address_new hostname' port checkUnexpectedReturnNULL "networkAddressNew" result result' <- (wrapObject NetworkAddress) result freeMem hostname' return result' #if ENABLE_OVERLOADING #endif -- method NetworkAddress::new_loopback -- method type : Constructor -- Args : [Arg {argCName = "port", argType = TBasicType TUInt16, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the port", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}] -- Lengths : [] -- returnType : Just (TInterface (Name {namespace = "Gio", name = "NetworkAddress"})) -- throws : False -- Skip return : False foreign import ccall "g_network_address_new_loopback" g_network_address_new_loopback :: Word16 -> -- port : TBasicType TUInt16 IO (Ptr NetworkAddress) {- | Creates a new 'GI.Gio.Interfaces.SocketConnectable.SocketConnectable' for connecting to the local host over a loopback connection to the given /@port@/. This is intended for use in connecting to local services which may be running on IPv4 or IPv6. The connectable will return IPv4 and IPv6 loopback addresses, regardless of how the host resolves @localhost@. By contrast, 'GI.Gio.Objects.NetworkAddress.networkAddressNew' will often only return an IPv4 address when resolving @localhost@, and an IPv6 address for @localhost6@. 'GI.Gio.Objects.NetworkAddress.networkAddressGetHostname' will always return @localhost@ for @/GNetworkAddresses/@ created with this constructor. /Since: 2.44/ -} networkAddressNewLoopback :: (B.CallStack.HasCallStack, MonadIO m) => Word16 {- ^ /@port@/: the port -} -> m NetworkAddress {- ^ __Returns:__ the new 'GI.Gio.Objects.NetworkAddress.NetworkAddress' -} networkAddressNewLoopback port = liftIO $ do result <- g_network_address_new_loopback port checkUnexpectedReturnNULL "networkAddressNewLoopback" result result' <- (wrapObject NetworkAddress) result return result' #if ENABLE_OVERLOADING #endif -- method NetworkAddress::get_hostname -- method type : OrdinaryMethod -- Args : [Arg {argCName = "addr", argType = TInterface (Name {namespace = "Gio", name = "NetworkAddress"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GNetworkAddress", 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 "g_network_address_get_hostname" g_network_address_get_hostname :: Ptr NetworkAddress -> -- addr : TInterface (Name {namespace = "Gio", name = "NetworkAddress"}) IO CString {- | Gets /@addr@/\'s hostname. This might be either UTF-8 or ASCII-encoded, depending on what /@addr@/ was created with. /Since: 2.22/ -} networkAddressGetHostname :: (B.CallStack.HasCallStack, MonadIO m, IsNetworkAddress a) => a {- ^ /@addr@/: a 'GI.Gio.Objects.NetworkAddress.NetworkAddress' -} -> m T.Text {- ^ __Returns:__ /@addr@/\'s hostname -} networkAddressGetHostname addr = liftIO $ do addr' <- unsafeManagedPtrCastPtr addr result <- g_network_address_get_hostname addr' checkUnexpectedReturnNULL "networkAddressGetHostname" result result' <- cstringToText result touchManagedPtr addr return result' #if ENABLE_OVERLOADING data NetworkAddressGetHostnameMethodInfo instance (signature ~ (m T.Text), MonadIO m, IsNetworkAddress a) => O.MethodInfo NetworkAddressGetHostnameMethodInfo a signature where overloadedMethod _ = networkAddressGetHostname #endif -- method NetworkAddress::get_port -- method type : OrdinaryMethod -- Args : [Arg {argCName = "addr", argType = TInterface (Name {namespace = "Gio", name = "NetworkAddress"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GNetworkAddress", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}] -- Lengths : [] -- returnType : Just (TBasicType TUInt16) -- throws : False -- Skip return : False foreign import ccall "g_network_address_get_port" g_network_address_get_port :: Ptr NetworkAddress -> -- addr : TInterface (Name {namespace = "Gio", name = "NetworkAddress"}) IO Word16 {- | Gets /@addr@/\'s port number /Since: 2.22/ -} networkAddressGetPort :: (B.CallStack.HasCallStack, MonadIO m, IsNetworkAddress a) => a {- ^ /@addr@/: a 'GI.Gio.Objects.NetworkAddress.NetworkAddress' -} -> m Word16 {- ^ __Returns:__ /@addr@/\'s port (which may be 0) -} networkAddressGetPort addr = liftIO $ do addr' <- unsafeManagedPtrCastPtr addr result <- g_network_address_get_port addr' touchManagedPtr addr return result #if ENABLE_OVERLOADING data NetworkAddressGetPortMethodInfo instance (signature ~ (m Word16), MonadIO m, IsNetworkAddress a) => O.MethodInfo NetworkAddressGetPortMethodInfo a signature where overloadedMethod _ = networkAddressGetPort #endif -- method NetworkAddress::get_scheme -- method type : OrdinaryMethod -- Args : [Arg {argCName = "addr", argType = TInterface (Name {namespace = "Gio", name = "NetworkAddress"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GNetworkAddress", 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 "g_network_address_get_scheme" g_network_address_get_scheme :: Ptr NetworkAddress -> -- addr : TInterface (Name {namespace = "Gio", name = "NetworkAddress"}) IO CString {- | Gets /@addr@/\'s scheme /Since: 2.26/ -} networkAddressGetScheme :: (B.CallStack.HasCallStack, MonadIO m, IsNetworkAddress a) => a {- ^ /@addr@/: a 'GI.Gio.Objects.NetworkAddress.NetworkAddress' -} -> m T.Text {- ^ __Returns:__ /@addr@/\'s scheme ('Nothing' if not built from URI) -} networkAddressGetScheme addr = liftIO $ do addr' <- unsafeManagedPtrCastPtr addr result <- g_network_address_get_scheme addr' checkUnexpectedReturnNULL "networkAddressGetScheme" result result' <- cstringToText result touchManagedPtr addr return result' #if ENABLE_OVERLOADING data NetworkAddressGetSchemeMethodInfo instance (signature ~ (m T.Text), MonadIO m, IsNetworkAddress a) => O.MethodInfo NetworkAddressGetSchemeMethodInfo a signature where overloadedMethod _ = networkAddressGetScheme #endif -- method NetworkAddress::parse -- method type : MemberFunction -- Args : [Arg {argCName = "host_and_port", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the hostname and optionally a port", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "default_port", argType = TBasicType TUInt16, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the default port if not in @host_and_port", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}] -- Lengths : [] -- returnType : Just (TInterface (Name {namespace = "Gio", name = "NetworkAddress"})) -- throws : True -- Skip return : False foreign import ccall "g_network_address_parse" g_network_address_parse :: CString -> -- host_and_port : TBasicType TUTF8 Word16 -> -- default_port : TBasicType TUInt16 Ptr (Ptr GError) -> -- error IO (Ptr NetworkAddress) {- | Creates a new 'GI.Gio.Interfaces.SocketConnectable.SocketConnectable' for connecting to the given /@hostname@/ and /@port@/. May fail and return 'Nothing' in case parsing /@hostAndPort@/ fails. /@hostAndPort@/ may be in any of a number of recognised formats; an IPv6 address, an IPv4 address, or a domain name (in which case a DNS lookup is performed). Quoting with [] is supported for all address types. A port override may be specified in the usual way with a colon. If no port is specified in /@hostAndPort@/ then /@defaultPort@/ will be used as the port number to connect to. In general, /@hostAndPort@/ is expected to be provided by the user (allowing them to give the hostname, and a port override if necessary) and /@defaultPort@/ is expected to be provided by the application. (The port component of /@hostAndPort@/ can also be specified as a service name rather than as a numeric port, but this functionality is deprecated, because it depends on the contents of \/etc\/services, which is generally quite sparse on platforms other than Linux.) /Since: 2.22/ -} networkAddressParse :: (B.CallStack.HasCallStack, MonadIO m) => T.Text {- ^ /@hostAndPort@/: the hostname and optionally a port -} -> Word16 {- ^ /@defaultPort@/: the default port if not in /@hostAndPort@/ -} -> m NetworkAddress {- ^ __Returns:__ the new 'GI.Gio.Objects.NetworkAddress.NetworkAddress', or 'Nothing' on error /(Can throw 'Data.GI.Base.GError.GError')/ -} networkAddressParse hostAndPort defaultPort = liftIO $ do hostAndPort' <- textToCString hostAndPort onException (do result <- propagateGError $ g_network_address_parse hostAndPort' defaultPort checkUnexpectedReturnNULL "networkAddressParse" result result' <- (wrapObject NetworkAddress) result freeMem hostAndPort' return result' ) (do freeMem hostAndPort' ) #if ENABLE_OVERLOADING #endif -- method NetworkAddress::parse_uri -- method type : MemberFunction -- Args : [Arg {argCName = "uri", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the hostname and optionally a port", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "default_port", argType = TBasicType TUInt16, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "The default port if none is found in the URI", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}] -- Lengths : [] -- returnType : Just (TInterface (Name {namespace = "Gio", name = "NetworkAddress"})) -- throws : True -- Skip return : False foreign import ccall "g_network_address_parse_uri" g_network_address_parse_uri :: CString -> -- uri : TBasicType TUTF8 Word16 -> -- default_port : TBasicType TUInt16 Ptr (Ptr GError) -> -- error IO (Ptr NetworkAddress) {- | Creates a new 'GI.Gio.Interfaces.SocketConnectable.SocketConnectable' for connecting to the given /@uri@/. May fail and return 'Nothing' in case parsing /@uri@/ fails. Using this rather than 'GI.Gio.Objects.NetworkAddress.networkAddressNew' or 'GI.Gio.Objects.NetworkAddress.networkAddressParse' allows 'GI.Gio.Objects.SocketClient.SocketClient' to determine when to use application-specific proxy protocols. /Since: 2.26/ -} networkAddressParseUri :: (B.CallStack.HasCallStack, MonadIO m) => T.Text {- ^ /@uri@/: the hostname and optionally a port -} -> Word16 {- ^ /@defaultPort@/: The default port if none is found in the URI -} -> m NetworkAddress {- ^ __Returns:__ the new 'GI.Gio.Objects.NetworkAddress.NetworkAddress', or 'Nothing' on error /(Can throw 'Data.GI.Base.GError.GError')/ -} networkAddressParseUri uri defaultPort = liftIO $ do uri' <- textToCString uri onException (do result <- propagateGError $ g_network_address_parse_uri uri' defaultPort checkUnexpectedReturnNULL "networkAddressParseUri" result result' <- (wrapObject NetworkAddress) result freeMem uri' return result' ) (do freeMem uri' ) #if ENABLE_OVERLOADING #endif