source: appstream-generator/build/girepo/gio/NetworkAddress.d @ 4841

Last change on this file since 4841 was 4841, checked in by Juanma, 2 years ago

Initial release

File size: 7.4 KB
Line 
1/*
2 * Licensed under the GNU Lesser General Public License Version 3
3 *
4 * This library is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation, either version 3 of the license, or
7 * (at your option) any later version.
8 *
9 * This software is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 * GNU Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with this library.  If not, see <http://www.gnu.org/licenses/>.
16 */
17
18// generated automatically - do not change
19
20
21module gio.NetworkAddress;
22
23private import gi.gio;
24public  import gi.giotypes;
25private import gio.SocketConnectableIF;
26private import gio.SocketConnectableT;
27private import glib.ConstructionException;
28private import glib.ErrorG;
29private import glib.GException;
30private import glib.Str;
31private import gobject.ObjectG;
32
33
34/**
35 * #GNetworkAddress provides an easy way to resolve a hostname and
36 * then attempt to connect to that host, handling the possibility of
37 * multiple IP addresses and multiple address families.
38 *
39 * See #GSocketConnectable for and example of using the connectable
40 * interface.
41 */
42public class NetworkAddress : ObjectG, SocketConnectableIF
43{
44        /** the main Gtk struct */
45        protected GNetworkAddress* gNetworkAddress;
46
47        /** Get the main Gtk struct */
48        public GNetworkAddress* getNetworkAddressStruct()
49        {
50                return gNetworkAddress;
51        }
52
53        /** the main Gtk struct as a void* */
54        protected override void* getStruct()
55        {
56                return cast(void*)gNetworkAddress;
57        }
58
59        protected override void setStruct(GObject* obj)
60        {
61                gNetworkAddress = cast(GNetworkAddress*)obj;
62                super.setStruct(obj);
63        }
64
65        /**
66         * Sets our main struct and passes it to the parent class.
67         */
68        public this (GNetworkAddress* gNetworkAddress, bool ownedRef = false)
69        {
70                this.gNetworkAddress = gNetworkAddress;
71                super(cast(GObject*)gNetworkAddress, ownedRef);
72        }
73
74        // add the SocketConnectable capabilities
75        mixin SocketConnectableT!(GNetworkAddress);
76
77
78        /** */
79        public static GType getType()
80        {
81                return g_network_address_get_type();
82        }
83
84        /**
85         * Creates a new #GSocketConnectable for connecting to the given
86         * @hostname and @port.
87         *
88         * Note that depending on the configuration of the machine, a
89         * @hostname of `localhost` may refer to the IPv4 loopback address
90         * only, or to both IPv4 and IPv6; use
91         * g_network_address_new_loopback() to create a #GNetworkAddress that
92         * is guaranteed to resolve to both addresses.
93         *
94         * Params:
95         *     hostname = the hostname
96         *     port = the port
97         *
98         * Returns: the new #GNetworkAddress
99         *
100         * Since: 2.22
101         *
102         * Throws: ConstructionException GTK+ fails to create the object.
103         */
104        public this(string hostname, ushort port)
105        {
106                auto p = g_network_address_new(Str.toStringz(hostname), port);
107               
108                if(p is null)
109                {
110                        throw new ConstructionException("null returned by new");
111                }
112               
113                this(cast(GNetworkAddress*) p, true);
114        }
115
116        /**
117         * Creates a new #GSocketConnectable for connecting to the local host
118         * over a loopback connection to the given @port. This is intended for
119         * use in connecting to local services which may be running on IPv4 or
120         * IPv6.
121         *
122         * The connectable will return IPv4 and IPv6 loopback addresses,
123         * regardless of how the host resolves `localhost`. By contrast,
124         * g_network_address_new() will often only return an IPv4 address when
125         * resolving `localhost`, and an IPv6 address for `localhost6`.
126         *
127         * g_network_address_get_hostname() will always return `localhost` for
128         * #GNetworkAddresses created with this constructor.
129         *
130         * Params:
131         *     port = the port
132         *
133         * Returns: the new #GNetworkAddress
134         *
135         * Since: 2.44
136         *
137         * Throws: ConstructionException GTK+ fails to create the object.
138         */
139        public this(ushort port)
140        {
141                auto p = g_network_address_new_loopback(port);
142               
143                if(p is null)
144                {
145                        throw new ConstructionException("null returned by new_loopback");
146                }
147               
148                this(cast(GNetworkAddress*) p, true);
149        }
150
151        /**
152         * Creates a new #GSocketConnectable for connecting to the given
153         * @hostname and @port. May fail and return %NULL in case
154         * parsing @host_and_port fails.
155         *
156         * @host_and_port may be in any of a number of recognised formats; an IPv6
157         * address, an IPv4 address, or a domain name (in which case a DNS
158         * lookup is performed). Quoting with [] is supported for all address
159         * types. A port override may be specified in the usual way with a
160         * colon.
161         *
162         * If no port is specified in @host_and_port then @default_port will be
163         * used as the port number to connect to.
164         *
165         * In general, @host_and_port is expected to be provided by the user
166         * (allowing them to give the hostname, and a port overide if necessary)
167         * and @default_port is expected to be provided by the application.
168         *
169         * (The port component of @host_and_port can also be specified as a
170         * service name rather than as a numeric port, but this functionality
171         * is deprecated, because it depends on the contents of /etc/services,
172         * which is generally quite sparse on platforms other than Linux.)
173         *
174         * Params:
175         *     hostAndPort = the hostname and optionally a port
176         *     defaultPort = the default port if not in @host_and_port
177         *
178         * Returns: the new
179         *     #GNetworkAddress, or %NULL on error
180         *
181         * Since: 2.22
182         *
183         * Throws: GException on failure.
184         */
185        public static NetworkAddress parse(string hostAndPort, ushort defaultPort)
186        {
187                GError* err = null;
188               
189                auto p = g_network_address_parse(Str.toStringz(hostAndPort), defaultPort, &err);
190               
191                if (err !is null)
192                {
193                        throw new GException( new ErrorG(err) );
194                }
195               
196                if(p is null)
197                {
198                        return null;
199                }
200               
201                return ObjectG.getDObject!(NetworkAddress)(cast(GNetworkAddress*) p, true);
202        }
203
204        /**
205         * Creates a new #GSocketConnectable for connecting to the given
206         * @uri. May fail and return %NULL in case parsing @uri fails.
207         *
208         * Using this rather than g_network_address_new() or
209         * g_network_address_parse() allows #GSocketClient to determine
210         * when to use application-specific proxy protocols.
211         *
212         * Params:
213         *     uri = the hostname and optionally a port
214         *     defaultPort = The default port if none is found in the URI
215         *
216         * Returns: the new
217         *     #GNetworkAddress, or %NULL on error
218         *
219         * Since: 2.26
220         *
221         * Throws: GException on failure.
222         */
223        public static NetworkAddress parseUri(string uri, ushort defaultPort)
224        {
225                GError* err = null;
226               
227                auto p = g_network_address_parse_uri(Str.toStringz(uri), defaultPort, &err);
228               
229                if (err !is null)
230                {
231                        throw new GException( new ErrorG(err) );
232                }
233               
234                if(p is null)
235                {
236                        return null;
237                }
238               
239                return ObjectG.getDObject!(NetworkAddress)(cast(GNetworkAddress*) p, true);
240        }
241
242        /**
243         * Gets @addr's hostname. This might be either UTF-8 or ASCII-encoded,
244         * depending on what @addr was created with.
245         *
246         * Returns: @addr's hostname
247         *
248         * Since: 2.22
249         */
250        public string getHostname()
251        {
252                return Str.toString(g_network_address_get_hostname(gNetworkAddress));
253        }
254
255        /**
256         * Gets @addr's port number
257         *
258         * Returns: @addr's port (which may be 0)
259         *
260         * Since: 2.22
261         */
262        public ushort getPort()
263        {
264                return g_network_address_get_port(gNetworkAddress);
265        }
266
267        /**
268         * Gets @addr's scheme
269         *
270         * Returns: @addr's scheme (%NULL if not built from URI)
271         *
272         * Since: 2.26
273         */
274        public string getScheme()
275        {
276                return Str.toString(g_network_address_get_scheme(gNetworkAddress));
277        }
278}
Note: See TracBrowser for help on using the repository browser.