1 /*
2  * This file is part of gtkD.
3  *
4  * gtkD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * gtkD is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with gtkD; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19  
20 // generated automatically - do not change
21 // find conversion definition on APILookup.txt
22 // implement new conversion functionalities on the wrap.utils pakage
23 
24 /*
25  * Conversion parameters:
26  * inFile  = GNetworkAddress.html
27  * outPack = gio
28  * outFile = NetworkAddress
29  * strct   = GNetworkAddress
30  * realStrct=
31  * ctorStrct=GSocketConnectable
32  * clss    = NetworkAddress
33  * interf  = 
34  * class Code: Yes
35  * interface Code: No
36  * template for:
37  * extend  = 
38  * implements:
39  * 	- SocketConnectableIF
40  * prefixes:
41  * 	- g_network_address_
42  * omit structs:
43  * omit prefixes:
44  * omit code:
45  * 	- g_network_address_parse
46  * omit signals:
47  * imports:
48  * 	- glib.Str
49  * 	- glib.ErrorG
50  * 	- glib.GException
51  * 	- gio.SocketConnectable
52  * 	- gio.SocketConnectableIF
53  * 	- gio.SocketConnectableT
54  * structWrap:
55  * 	- GSocketConnectable* -> SocketConnectableIF
56  * module aliases:
57  * local aliases:
58  * overrides:
59  */
60 
61 module gio.NetworkAddress;
62 
63 public  import gtkc.giotypes;
64 
65 private import gtkc.gio;
66 private import glib.ConstructionException;
67 private import gobject.ObjectG;
68 
69 private import glib.Str;
70 private import glib.ErrorG;
71 private import glib.GException;
72 private import gio.SocketConnectable;
73 private import gio.SocketConnectableIF;
74 private import gio.SocketConnectableT;
75 
76 
77 private import gobject.ObjectG;
78 
79 /**
80  * GNetworkAddress provides an easy way to resolve a hostname and
81  * then attempt to connect to that host, handling the possibility of
82  * multiple IP addresses and multiple address families.
83  *
84  * See GSocketConnectable for and example of using the connectable
85  * interface.
86  */
87 public class NetworkAddress : ObjectG, SocketConnectableIF
88 {
89 	
90 	/** the main Gtk struct */
91 	protected GNetworkAddress* gNetworkAddress;
92 	
93 	
94 	/** Get the main Gtk struct */
95 	public GNetworkAddress* getNetworkAddressStruct()
96 	{
97 		return gNetworkAddress;
98 	}
99 	
100 	
101 	/** the main Gtk struct as a void* */
102 	protected override void* getStruct()
103 	{
104 		return cast(void*)gNetworkAddress;
105 	}
106 	
107 	/**
108 	 * Sets our main struct and passes it to the parent class
109 	 */
110 	public this (GNetworkAddress* gNetworkAddress)
111 	{
112 		super(cast(GObject*)gNetworkAddress);
113 		this.gNetworkAddress = gNetworkAddress;
114 	}
115 	
116 	protected override void setStruct(GObject* obj)
117 	{
118 		super.setStruct(obj);
119 		gNetworkAddress = cast(GNetworkAddress*)obj;
120 	}
121 	
122 	// add the SocketConnectable capabilities
123 	mixin SocketConnectableT!(GNetworkAddress);
124 	
125 	/**
126 	 * Creates a new GSocketConnectable for connecting to the given
127 	 * hostname and port. May fail and return NULL in case
128 	 * parsing host_and_port fails.
129 	 * host_and_port may be in any of a number of recognised formats: an IPv6
130 	 * address, an IPv4 address, or a domain name (in which case a DNS
131 	 * lookup is performed). Quoting with [] is supported for all address
132 	 * types. A port override may be specified in the usual way with a
133 	 * colon. Ports may be given as decimal numbers or symbolic names (in
134 	 * which case an /etc/services lookup is performed).
135 	 * If no port is specified in host_and_port then default_port will be
136 	 * used as the port number to connect to.
137 	 * In general, host_and_port is expected to be provided by the user
138 	 * (allowing them to give the hostname, and a port overide if necessary)
139 	 * and default_port is expected to be provided by the application.
140 	 * Since 2.22
141 	 * Params:
142 	 * hostAndPort =  the hostname and optionally a port
143 	 * defaultPort =  the default port if not in host_and_port
144 	 * Returns: the new GNetworkAddress, or NULL on error
145 	 * Throws: GException on failure.
146 	 */
147 	public static SocketConnectableIF parse(string hostAndPort, ushort defaultPort)
148 	{
149 		// GSocketConnectable * g_network_address_parse (const gchar *host_and_port,  guint16 default_port,  GError **error);
150 		GError* err = null;
151 		
152 		auto p = g_network_address_parse(Str.toStringz(hostAndPort), defaultPort, &err);
153 		
154 		if (err !is null)
155 		{
156 			throw new GException( new ErrorG(err) );
157 		}
158 		
159 		if(p is null)
160 		{
161 			return null;
162 		}
163 		return new NetworkAddress(cast(GNetworkAddress*) p);
164 	}
165 	
166 	/**
167 	 */
168 	
169 	/**
170 	 * Creates a new GSocketConnectable for connecting to the given
171 	 * hostname and port.
172 	 * Since 2.22
173 	 * Params:
174 	 * hostname = the hostname
175 	 * port = the port
176 	 * Throws: ConstructionException GTK+ fails to create the object.
177 	 */
178 	public this (string hostname, ushort port)
179 	{
180 		// GSocketConnectable * g_network_address_new (const gchar *hostname,  guint16 port);
181 		auto p = g_network_address_new(Str.toStringz(hostname), port);
182 		if(p is null)
183 		{
184 			throw new ConstructionException("null returned by g_network_address_new(Str.toStringz(hostname), port)");
185 		}
186 		this(cast(GNetworkAddress*) p);
187 	}
188 	
189 	/**
190 	 * Gets addr's hostname. This might be either UTF-8 or ASCII-encoded,
191 	 * depending on what addr was created with.
192 	 * Since 2.22
193 	 * Returns: addr's hostname
194 	 */
195 	public string getHostname()
196 	{
197 		// const gchar * g_network_address_get_hostname (GNetworkAddress *addr);
198 		return Str.toString(g_network_address_get_hostname(gNetworkAddress));
199 	}
200 	
201 	/**
202 	 * Gets addr's port number
203 	 * Since 2.22
204 	 * Returns: addr's port (which may be 0)
205 	 */
206 	public ushort getPort()
207 	{
208 		// guint16 g_network_address_get_port (GNetworkAddress *addr);
209 		return g_network_address_get_port(gNetworkAddress);
210 	}
211 	
212 	/**
213 	 * Gets addr's scheme
214 	 * Since 2.26
215 	 * Returns: addr's scheme (NULL if not built from URI)
216 	 */
217 	public string getScheme()
218 	{
219 		// const gchar * g_network_address_get_scheme (GNetworkAddress *addr);
220 		return Str.toString(g_network_address_get_scheme(gNetworkAddress));
221 	}
222 	
223 	/**
224 	 * Creates a new GSocketConnectable for connecting to the given
225 	 * uri. May fail and return NULL in case parsing uri fails.
226 	 * Using this rather than g_network_address_new() or
227 	 * g_network_address_parse() allows GSocketClient to determine
228 	 * when to use application-specific proxy protocols.
229 	 * Since 2.26
230 	 * Params:
231 	 * uri = the hostname and optionally a port
232 	 * defaultPort = The default port if none is found in the URI
233 	 * Returns: the new GNetworkAddress, or NULL on error. [transfer full]
234 	 * Throws: GException on failure.
235 	 */
236 	public static SocketConnectableIF parseUri(string uri, ushort defaultPort)
237 	{
238 		// GSocketConnectable * g_network_address_parse_uri (const gchar *uri,  guint16 default_port,  GError **error);
239 		GError* err = null;
240 		
241 		auto p = g_network_address_parse_uri(Str.toStringz(uri), defaultPort, &err);
242 		
243 		if (err !is null)
244 		{
245 			throw new GException( new ErrorG(err) );
246 		}
247 		
248 		
249 		if(p is null)
250 		{
251 			return null;
252 		}
253 		
254 		return ObjectG.getDObject!(SocketConnectable, SocketConnectableIF)(cast(GSocketConnectable*) p);
255 	}
256 }