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 module gio.SocketClient;
26 
27 private import gio.AsyncResultIF;
28 private import gio.Cancellable;
29 private import gio.IOStream;
30 private import gio.ProxyResolver;
31 private import gio.ProxyResolverIF;
32 private import gio.SocketAddress;
33 private import gio.SocketConnectable;
34 private import gio.SocketConnectableIF;
35 private import gio.SocketConnection;
36 private import glib.ConstructionException;
37 private import glib.ErrorG;
38 private import glib.GException;
39 private import glib.Str;
40 private import gobject.ObjectG;
41 private import gobject.Signals;
42 private import gtkc.gio;
43 public  import gtkc.giotypes;
44 private import std.algorithm;
45 
46 
47 /**
48  * #GSocketClient is a lightweight high-level utility class for connecting to
49  * a network host using a connection oriented socket type.
50  * 
51  * You create a #GSocketClient object, set any options you want, and then
52  * call a sync or async connect operation, which returns a #GSocketConnection
53  * subclass on success.
54  * 
55  * The type of the #GSocketConnection object returned depends on the type of
56  * the underlying socket that is in use. For instance, for a TCP/IP connection
57  * it will be a #GTcpConnection.
58  * 
59  * As #GSocketClient is a lightweight object, you don't need to cache it. You
60  * can just create a new one any time you need one.
61  *
62  * Since: 2.22
63  */
64 public class SocketClient : ObjectG
65 {
66 	/** the main Gtk struct */
67 	protected GSocketClient* gSocketClient;
68 
69 	/** Get the main Gtk struct */
70 	public GSocketClient* getSocketClientStruct(bool transferOwnership = false)
71 	{
72 		if (transferOwnership)
73 			ownedRef = false;
74 		return gSocketClient;
75 	}
76 
77 	/** the main Gtk struct as a void* */
78 	protected override void* getStruct()
79 	{
80 		return cast(void*)gSocketClient;
81 	}
82 
83 	protected override void setStruct(GObject* obj)
84 	{
85 		gSocketClient = cast(GSocketClient*)obj;
86 		super.setStruct(obj);
87 	}
88 
89 	/**
90 	 * Sets our main struct and passes it to the parent class.
91 	 */
92 	public this (GSocketClient* gSocketClient, bool ownedRef = false)
93 	{
94 		this.gSocketClient = gSocketClient;
95 		super(cast(GObject*)gSocketClient, ownedRef);
96 	}
97 
98 
99 	/** */
100 	public static GType getType()
101 	{
102 		return g_socket_client_get_type();
103 	}
104 
105 	/**
106 	 * Creates a new #GSocketClient with the default options.
107 	 *
108 	 * Returns: a #GSocketClient.
109 	 *     Free the returned object with g_object_unref().
110 	 *
111 	 * Since: 2.22
112 	 *
113 	 * Throws: ConstructionException GTK+ fails to create the object.
114 	 */
115 	public this()
116 	{
117 		auto p = g_socket_client_new();
118 		
119 		if(p is null)
120 		{
121 			throw new ConstructionException("null returned by new");
122 		}
123 		
124 		this(cast(GSocketClient*) p, true);
125 	}
126 
127 	/**
128 	 * Enable proxy protocols to be handled by the application. When the
129 	 * indicated proxy protocol is returned by the #GProxyResolver,
130 	 * #GSocketClient will consider this protocol as supported but will
131 	 * not try to find a #GProxy instance to handle handshaking. The
132 	 * application must check for this case by calling
133 	 * g_socket_connection_get_remote_address() on the returned
134 	 * #GSocketConnection, and seeing if it's a #GProxyAddress of the
135 	 * appropriate type, to determine whether or not it needs to handle
136 	 * the proxy handshaking itself.
137 	 *
138 	 * This should be used for proxy protocols that are dialects of
139 	 * another protocol such as HTTP proxy. It also allows cohabitation of
140 	 * proxy protocols that are reused between protocols. A good example
141 	 * is HTTP. It can be used to proxy HTTP, FTP and Gopher and can also
142 	 * be use as generic socket proxy through the HTTP CONNECT method.
143 	 *
144 	 * When the proxy is detected as being an application proxy, TLS handshake
145 	 * will be skipped. This is required to let the application do the proxy
146 	 * specific handshake.
147 	 *
148 	 * Params:
149 	 *     protocol = The proxy protocol
150 	 */
151 	public void addApplicationProxy(string protocol)
152 	{
153 		g_socket_client_add_application_proxy(gSocketClient, Str.toStringz(protocol));
154 	}
155 
156 	/**
157 	 * Tries to resolve the @connectable and make a network connection to it.
158 	 *
159 	 * Upon a successful connection, a new #GSocketConnection is constructed
160 	 * and returned.  The caller owns this new object and must drop their
161 	 * reference to it when finished with it.
162 	 *
163 	 * The type of the #GSocketConnection object returned depends on the type of
164 	 * the underlying socket that is used. For instance, for a TCP/IP connection
165 	 * it will be a #GTcpConnection.
166 	 *
167 	 * The socket created will be the same family as the address that the
168 	 * @connectable resolves to, unless family is set with g_socket_client_set_family()
169 	 * or indirectly via g_socket_client_set_local_address(). The socket type
170 	 * defaults to %G_SOCKET_TYPE_STREAM but can be set with
171 	 * g_socket_client_set_socket_type().
172 	 *
173 	 * If a local address is specified with g_socket_client_set_local_address() the
174 	 * socket will be bound to this address before connecting.
175 	 *
176 	 * Params:
177 	 *     connectable = a #GSocketConnectable specifying the remote address.
178 	 *     cancellable = optional #GCancellable object, %NULL to ignore.
179 	 *
180 	 * Returns: a #GSocketConnection on success, %NULL on error.
181 	 *
182 	 * Since: 2.22
183 	 *
184 	 * Throws: GException on failure.
185 	 */
186 	public SocketConnection connect(SocketConnectableIF connectable, Cancellable cancellable)
187 	{
188 		GError* err = null;
189 		
190 		auto p = g_socket_client_connect(gSocketClient, (connectable is null) ? null : connectable.getSocketConnectableStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), &err);
191 		
192 		if (err !is null)
193 		{
194 			throw new GException( new ErrorG(err) );
195 		}
196 		
197 		if(p is null)
198 		{
199 			return null;
200 		}
201 		
202 		return ObjectG.getDObject!(SocketConnection)(cast(GSocketConnection*) p, true);
203 	}
204 
205 	/**
206 	 * This is the asynchronous version of g_socket_client_connect().
207 	 *
208 	 * When the operation is finished @callback will be
209 	 * called. You can then call g_socket_client_connect_finish() to get
210 	 * the result of the operation.
211 	 *
212 	 * Params:
213 	 *     connectable = a #GSocketConnectable specifying the remote address.
214 	 *     cancellable = a #GCancellable, or %NULL
215 	 *     callback = a #GAsyncReadyCallback
216 	 *     userData = user data for the callback
217 	 *
218 	 * Since: 2.22
219 	 */
220 	public void connectAsync(SocketConnectableIF connectable, Cancellable cancellable, GAsyncReadyCallback callback, void* userData)
221 	{
222 		g_socket_client_connect_async(gSocketClient, (connectable is null) ? null : connectable.getSocketConnectableStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData);
223 	}
224 
225 	/**
226 	 * Finishes an async connect operation. See g_socket_client_connect_async()
227 	 *
228 	 * Params:
229 	 *     result = a #GAsyncResult.
230 	 *
231 	 * Returns: a #GSocketConnection on success, %NULL on error.
232 	 *
233 	 * Since: 2.22
234 	 *
235 	 * Throws: GException on failure.
236 	 */
237 	public SocketConnection connectFinish(AsyncResultIF result)
238 	{
239 		GError* err = null;
240 		
241 		auto p = g_socket_client_connect_finish(gSocketClient, (result is null) ? null : result.getAsyncResultStruct(), &err);
242 		
243 		if (err !is null)
244 		{
245 			throw new GException( new ErrorG(err) );
246 		}
247 		
248 		if(p is null)
249 		{
250 			return null;
251 		}
252 		
253 		return ObjectG.getDObject!(SocketConnection)(cast(GSocketConnection*) p, true);
254 	}
255 
256 	/**
257 	 * This is a helper function for g_socket_client_connect().
258 	 *
259 	 * Attempts to create a TCP connection to the named host.
260 	 *
261 	 * @host_and_port may be in any of a number of recognized formats; an IPv6
262 	 * address, an IPv4 address, or a domain name (in which case a DNS
263 	 * lookup is performed).  Quoting with [] is supported for all address
264 	 * types.  A port override may be specified in the usual way with a
265 	 * colon.  Ports may be given as decimal numbers or symbolic names (in
266 	 * which case an /etc/services lookup is performed).
267 	 *
268 	 * If no port override is given in @host_and_port then @default_port will be
269 	 * used as the port number to connect to.
270 	 *
271 	 * In general, @host_and_port is expected to be provided by the user (allowing
272 	 * them to give the hostname, and a port override if necessary) and
273 	 * @default_port is expected to be provided by the application.
274 	 *
275 	 * In the case that an IP address is given, a single connection
276 	 * attempt is made.  In the case that a name is given, multiple
277 	 * connection attempts may be made, in turn and according to the
278 	 * number of address records in DNS, until a connection succeeds.
279 	 *
280 	 * Upon a successful connection, a new #GSocketConnection is constructed
281 	 * and returned.  The caller owns this new object and must drop their
282 	 * reference to it when finished with it.
283 	 *
284 	 * In the event of any failure (DNS error, service not found, no hosts
285 	 * connectable) %NULL is returned and @error (if non-%NULL) is set
286 	 * accordingly.
287 	 *
288 	 * Params:
289 	 *     hostAndPort = the name and optionally port of the host to connect to
290 	 *     defaultPort = the default port to connect to
291 	 *     cancellable = a #GCancellable, or %NULL
292 	 *
293 	 * Returns: a #GSocketConnection on success, %NULL on error.
294 	 *
295 	 * Since: 2.22
296 	 *
297 	 * Throws: GException on failure.
298 	 */
299 	public SocketConnection connectToHost(string hostAndPort, ushort defaultPort, Cancellable cancellable)
300 	{
301 		GError* err = null;
302 		
303 		auto p = g_socket_client_connect_to_host(gSocketClient, Str.toStringz(hostAndPort), defaultPort, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err);
304 		
305 		if (err !is null)
306 		{
307 			throw new GException( new ErrorG(err) );
308 		}
309 		
310 		if(p is null)
311 		{
312 			return null;
313 		}
314 		
315 		return ObjectG.getDObject!(SocketConnection)(cast(GSocketConnection*) p, true);
316 	}
317 
318 	/**
319 	 * This is the asynchronous version of g_socket_client_connect_to_host().
320 	 *
321 	 * When the operation is finished @callback will be
322 	 * called. You can then call g_socket_client_connect_to_host_finish() to get
323 	 * the result of the operation.
324 	 *
325 	 * Params:
326 	 *     hostAndPort = the name and optionally the port of the host to connect to
327 	 *     defaultPort = the default port to connect to
328 	 *     cancellable = a #GCancellable, or %NULL
329 	 *     callback = a #GAsyncReadyCallback
330 	 *     userData = user data for the callback
331 	 *
332 	 * Since: 2.22
333 	 */
334 	public void connectToHostAsync(string hostAndPort, ushort defaultPort, Cancellable cancellable, GAsyncReadyCallback callback, void* userData)
335 	{
336 		g_socket_client_connect_to_host_async(gSocketClient, Str.toStringz(hostAndPort), defaultPort, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData);
337 	}
338 
339 	/**
340 	 * Finishes an async connect operation. See g_socket_client_connect_to_host_async()
341 	 *
342 	 * Params:
343 	 *     result = a #GAsyncResult.
344 	 *
345 	 * Returns: a #GSocketConnection on success, %NULL on error.
346 	 *
347 	 * Since: 2.22
348 	 *
349 	 * Throws: GException on failure.
350 	 */
351 	public SocketConnection connectToHostFinish(AsyncResultIF result)
352 	{
353 		GError* err = null;
354 		
355 		auto p = g_socket_client_connect_to_host_finish(gSocketClient, (result is null) ? null : result.getAsyncResultStruct(), &err);
356 		
357 		if (err !is null)
358 		{
359 			throw new GException( new ErrorG(err) );
360 		}
361 		
362 		if(p is null)
363 		{
364 			return null;
365 		}
366 		
367 		return ObjectG.getDObject!(SocketConnection)(cast(GSocketConnection*) p, true);
368 	}
369 
370 	/**
371 	 * Attempts to create a TCP connection to a service.
372 	 *
373 	 * This call looks up the SRV record for @service at @domain for the
374 	 * "tcp" protocol.  It then attempts to connect, in turn, to each of
375 	 * the hosts providing the service until either a connection succeeds
376 	 * or there are no hosts remaining.
377 	 *
378 	 * Upon a successful connection, a new #GSocketConnection is constructed
379 	 * and returned.  The caller owns this new object and must drop their
380 	 * reference to it when finished with it.
381 	 *
382 	 * In the event of any failure (DNS error, service not found, no hosts
383 	 * connectable) %NULL is returned and @error (if non-%NULL) is set
384 	 * accordingly.
385 	 *
386 	 * Params:
387 	 *     domain = a domain name
388 	 *     service = the name of the service to connect to
389 	 *     cancellable = a #GCancellable, or %NULL
390 	 *
391 	 * Returns: a #GSocketConnection if successful, or %NULL on error
392 	 *
393 	 * Throws: GException on failure.
394 	 */
395 	public SocketConnection connectToService(string domain, string service, Cancellable cancellable)
396 	{
397 		GError* err = null;
398 		
399 		auto p = g_socket_client_connect_to_service(gSocketClient, Str.toStringz(domain), Str.toStringz(service), (cancellable is null) ? null : cancellable.getCancellableStruct(), &err);
400 		
401 		if (err !is null)
402 		{
403 			throw new GException( new ErrorG(err) );
404 		}
405 		
406 		if(p is null)
407 		{
408 			return null;
409 		}
410 		
411 		return ObjectG.getDObject!(SocketConnection)(cast(GSocketConnection*) p, true);
412 	}
413 
414 	/**
415 	 * This is the asynchronous version of
416 	 * g_socket_client_connect_to_service().
417 	 *
418 	 * Params:
419 	 *     domain = a domain name
420 	 *     service = the name of the service to connect to
421 	 *     cancellable = a #GCancellable, or %NULL
422 	 *     callback = a #GAsyncReadyCallback
423 	 *     userData = user data for the callback
424 	 *
425 	 * Since: 2.22
426 	 */
427 	public void connectToServiceAsync(string domain, string service, Cancellable cancellable, GAsyncReadyCallback callback, void* userData)
428 	{
429 		g_socket_client_connect_to_service_async(gSocketClient, Str.toStringz(domain), Str.toStringz(service), (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData);
430 	}
431 
432 	/**
433 	 * Finishes an async connect operation. See g_socket_client_connect_to_service_async()
434 	 *
435 	 * Params:
436 	 *     result = a #GAsyncResult.
437 	 *
438 	 * Returns: a #GSocketConnection on success, %NULL on error.
439 	 *
440 	 * Since: 2.22
441 	 *
442 	 * Throws: GException on failure.
443 	 */
444 	public SocketConnection connectToServiceFinish(AsyncResultIF result)
445 	{
446 		GError* err = null;
447 		
448 		auto p = g_socket_client_connect_to_service_finish(gSocketClient, (result is null) ? null : result.getAsyncResultStruct(), &err);
449 		
450 		if (err !is null)
451 		{
452 			throw new GException( new ErrorG(err) );
453 		}
454 		
455 		if(p is null)
456 		{
457 			return null;
458 		}
459 		
460 		return ObjectG.getDObject!(SocketConnection)(cast(GSocketConnection*) p, true);
461 	}
462 
463 	/**
464 	 * This is a helper function for g_socket_client_connect().
465 	 *
466 	 * Attempts to create a TCP connection with a network URI.
467 	 *
468 	 * @uri may be any valid URI containing an "authority" (hostname/port)
469 	 * component. If a port is not specified in the URI, @default_port
470 	 * will be used. TLS will be negotiated if #GSocketClient:tls is %TRUE.
471 	 * (#GSocketClient does not know to automatically assume TLS for
472 	 * certain URI schemes.)
473 	 *
474 	 * Using this rather than g_socket_client_connect() or
475 	 * g_socket_client_connect_to_host() allows #GSocketClient to
476 	 * determine when to use application-specific proxy protocols.
477 	 *
478 	 * Upon a successful connection, a new #GSocketConnection is constructed
479 	 * and returned.  The caller owns this new object and must drop their
480 	 * reference to it when finished with it.
481 	 *
482 	 * In the event of any failure (DNS error, service not found, no hosts
483 	 * connectable) %NULL is returned and @error (if non-%NULL) is set
484 	 * accordingly.
485 	 *
486 	 * Params:
487 	 *     uri = A network URI
488 	 *     defaultPort = the default port to connect to
489 	 *     cancellable = a #GCancellable, or %NULL
490 	 *
491 	 * Returns: a #GSocketConnection on success, %NULL on error.
492 	 *
493 	 * Since: 2.26
494 	 *
495 	 * Throws: GException on failure.
496 	 */
497 	public SocketConnection connectToUri(string uri, ushort defaultPort, Cancellable cancellable)
498 	{
499 		GError* err = null;
500 		
501 		auto p = g_socket_client_connect_to_uri(gSocketClient, Str.toStringz(uri), defaultPort, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err);
502 		
503 		if (err !is null)
504 		{
505 			throw new GException( new ErrorG(err) );
506 		}
507 		
508 		if(p is null)
509 		{
510 			return null;
511 		}
512 		
513 		return ObjectG.getDObject!(SocketConnection)(cast(GSocketConnection*) p, true);
514 	}
515 
516 	/**
517 	 * This is the asynchronous version of g_socket_client_connect_to_uri().
518 	 *
519 	 * When the operation is finished @callback will be
520 	 * called. You can then call g_socket_client_connect_to_uri_finish() to get
521 	 * the result of the operation.
522 	 *
523 	 * Params:
524 	 *     uri = a network uri
525 	 *     defaultPort = the default port to connect to
526 	 *     cancellable = a #GCancellable, or %NULL
527 	 *     callback = a #GAsyncReadyCallback
528 	 *     userData = user data for the callback
529 	 *
530 	 * Since: 2.26
531 	 */
532 	public void connectToUriAsync(string uri, ushort defaultPort, Cancellable cancellable, GAsyncReadyCallback callback, void* userData)
533 	{
534 		g_socket_client_connect_to_uri_async(gSocketClient, Str.toStringz(uri), defaultPort, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData);
535 	}
536 
537 	/**
538 	 * Finishes an async connect operation. See g_socket_client_connect_to_uri_async()
539 	 *
540 	 * Params:
541 	 *     result = a #GAsyncResult.
542 	 *
543 	 * Returns: a #GSocketConnection on success, %NULL on error.
544 	 *
545 	 * Since: 2.26
546 	 *
547 	 * Throws: GException on failure.
548 	 */
549 	public SocketConnection connectToUriFinish(AsyncResultIF result)
550 	{
551 		GError* err = null;
552 		
553 		auto p = g_socket_client_connect_to_uri_finish(gSocketClient, (result is null) ? null : result.getAsyncResultStruct(), &err);
554 		
555 		if (err !is null)
556 		{
557 			throw new GException( new ErrorG(err) );
558 		}
559 		
560 		if(p is null)
561 		{
562 			return null;
563 		}
564 		
565 		return ObjectG.getDObject!(SocketConnection)(cast(GSocketConnection*) p, true);
566 	}
567 
568 	/**
569 	 * Gets the proxy enable state; see g_socket_client_set_enable_proxy()
570 	 *
571 	 * Returns: whether proxying is enabled
572 	 *
573 	 * Since: 2.26
574 	 */
575 	public bool getEnableProxy()
576 	{
577 		return g_socket_client_get_enable_proxy(gSocketClient) != 0;
578 	}
579 
580 	/**
581 	 * Gets the socket family of the socket client.
582 	 *
583 	 * See g_socket_client_set_family() for details.
584 	 *
585 	 * Returns: a #GSocketFamily
586 	 *
587 	 * Since: 2.22
588 	 */
589 	public GSocketFamily getFamily()
590 	{
591 		return g_socket_client_get_family(gSocketClient);
592 	}
593 
594 	/**
595 	 * Gets the local address of the socket client.
596 	 *
597 	 * See g_socket_client_set_local_address() for details.
598 	 *
599 	 * Returns: a #GSocketAddress or %NULL. Do not free.
600 	 *
601 	 * Since: 2.22
602 	 */
603 	public SocketAddress getLocalAddress()
604 	{
605 		auto p = g_socket_client_get_local_address(gSocketClient);
606 		
607 		if(p is null)
608 		{
609 			return null;
610 		}
611 		
612 		return ObjectG.getDObject!(SocketAddress)(cast(GSocketAddress*) p);
613 	}
614 
615 	/**
616 	 * Gets the protocol name type of the socket client.
617 	 *
618 	 * See g_socket_client_set_protocol() for details.
619 	 *
620 	 * Returns: a #GSocketProtocol
621 	 *
622 	 * Since: 2.22
623 	 */
624 	public GSocketProtocol getProtocol()
625 	{
626 		return g_socket_client_get_protocol(gSocketClient);
627 	}
628 
629 	/**
630 	 * Gets the #GProxyResolver being used by @client. Normally, this will
631 	 * be the resolver returned by g_proxy_resolver_get_default(), but you
632 	 * can override it with g_socket_client_set_proxy_resolver().
633 	 *
634 	 * Returns: The #GProxyResolver being used by
635 	 *     @client.
636 	 *
637 	 * Since: 2.36
638 	 */
639 	public ProxyResolverIF getProxyResolver()
640 	{
641 		auto p = g_socket_client_get_proxy_resolver(gSocketClient);
642 		
643 		if(p is null)
644 		{
645 			return null;
646 		}
647 		
648 		return ObjectG.getDObject!(ProxyResolver, ProxyResolverIF)(cast(GProxyResolver*) p);
649 	}
650 
651 	/**
652 	 * Gets the socket type of the socket client.
653 	 *
654 	 * See g_socket_client_set_socket_type() for details.
655 	 *
656 	 * Returns: a #GSocketFamily
657 	 *
658 	 * Since: 2.22
659 	 */
660 	public GSocketType getSocketType()
661 	{
662 		return g_socket_client_get_socket_type(gSocketClient);
663 	}
664 
665 	/**
666 	 * Gets the I/O timeout time for sockets created by @client.
667 	 *
668 	 * See g_socket_client_set_timeout() for details.
669 	 *
670 	 * Returns: the timeout in seconds
671 	 *
672 	 * Since: 2.26
673 	 */
674 	public uint getTimeout()
675 	{
676 		return g_socket_client_get_timeout(gSocketClient);
677 	}
678 
679 	/**
680 	 * Gets whether @client creates TLS connections. See
681 	 * g_socket_client_set_tls() for details.
682 	 *
683 	 * Returns: whether @client uses TLS
684 	 *
685 	 * Since: 2.28
686 	 */
687 	public bool getTls()
688 	{
689 		return g_socket_client_get_tls(gSocketClient) != 0;
690 	}
691 
692 	/**
693 	 * Gets the TLS validation flags used creating TLS connections via
694 	 * @client.
695 	 *
696 	 * Returns: the TLS validation flags
697 	 *
698 	 * Since: 2.28
699 	 */
700 	public GTlsCertificateFlags getTlsValidationFlags()
701 	{
702 		return g_socket_client_get_tls_validation_flags(gSocketClient);
703 	}
704 
705 	/**
706 	 * Sets whether or not @client attempts to make connections via a
707 	 * proxy server. When enabled (the default), #GSocketClient will use a
708 	 * #GProxyResolver to determine if a proxy protocol such as SOCKS is
709 	 * needed, and automatically do the necessary proxy negotiation.
710 	 *
711 	 * See also g_socket_client_set_proxy_resolver().
712 	 *
713 	 * Params:
714 	 *     enable = whether to enable proxies
715 	 *
716 	 * Since: 2.26
717 	 */
718 	public void setEnableProxy(bool enable)
719 	{
720 		g_socket_client_set_enable_proxy(gSocketClient, enable);
721 	}
722 
723 	/**
724 	 * Sets the socket family of the socket client.
725 	 * If this is set to something other than %G_SOCKET_FAMILY_INVALID
726 	 * then the sockets created by this object will be of the specified
727 	 * family.
728 	 *
729 	 * This might be useful for instance if you want to force the local
730 	 * connection to be an ipv4 socket, even though the address might
731 	 * be an ipv6 mapped to ipv4 address.
732 	 *
733 	 * Params:
734 	 *     family = a #GSocketFamily
735 	 *
736 	 * Since: 2.22
737 	 */
738 	public void setFamily(GSocketFamily family)
739 	{
740 		g_socket_client_set_family(gSocketClient, family);
741 	}
742 
743 	/**
744 	 * Sets the local address of the socket client.
745 	 * The sockets created by this object will bound to the
746 	 * specified address (if not %NULL) before connecting.
747 	 *
748 	 * This is useful if you want to ensure that the local
749 	 * side of the connection is on a specific port, or on
750 	 * a specific interface.
751 	 *
752 	 * Params:
753 	 *     address = a #GSocketAddress, or %NULL
754 	 *
755 	 * Since: 2.22
756 	 */
757 	public void setLocalAddress(SocketAddress address)
758 	{
759 		g_socket_client_set_local_address(gSocketClient, (address is null) ? null : address.getSocketAddressStruct());
760 	}
761 
762 	/**
763 	 * Sets the protocol of the socket client.
764 	 * The sockets created by this object will use of the specified
765 	 * protocol.
766 	 *
767 	 * If @protocol is %0 that means to use the default
768 	 * protocol for the socket family and type.
769 	 *
770 	 * Params:
771 	 *     protocol = a #GSocketProtocol
772 	 *
773 	 * Since: 2.22
774 	 */
775 	public void setProtocol(GSocketProtocol protocol)
776 	{
777 		g_socket_client_set_protocol(gSocketClient, protocol);
778 	}
779 
780 	/**
781 	 * Overrides the #GProxyResolver used by @client. You can call this if
782 	 * you want to use specific proxies, rather than using the system
783 	 * default proxy settings.
784 	 *
785 	 * Note that whether or not the proxy resolver is actually used
786 	 * depends on the setting of #GSocketClient:enable-proxy, which is not
787 	 * changed by this function (but which is %TRUE by default)
788 	 *
789 	 * Params:
790 	 *     proxyResolver = a #GProxyResolver, or %NULL for the
791 	 *         default.
792 	 *
793 	 * Since: 2.36
794 	 */
795 	public void setProxyResolver(ProxyResolverIF proxyResolver)
796 	{
797 		g_socket_client_set_proxy_resolver(gSocketClient, (proxyResolver is null) ? null : proxyResolver.getProxyResolverStruct());
798 	}
799 
800 	/**
801 	 * Sets the socket type of the socket client.
802 	 * The sockets created by this object will be of the specified
803 	 * type.
804 	 *
805 	 * It doesn't make sense to specify a type of %G_SOCKET_TYPE_DATAGRAM,
806 	 * as GSocketClient is used for connection oriented services.
807 	 *
808 	 * Params:
809 	 *     type = a #GSocketType
810 	 *
811 	 * Since: 2.22
812 	 */
813 	public void setSocketType(GSocketType type)
814 	{
815 		g_socket_client_set_socket_type(gSocketClient, type);
816 	}
817 
818 	/**
819 	 * Sets the I/O timeout for sockets created by @client. @timeout is a
820 	 * time in seconds, or 0 for no timeout (the default).
821 	 *
822 	 * The timeout value affects the initial connection attempt as well,
823 	 * so setting this may cause calls to g_socket_client_connect(), etc,
824 	 * to fail with %G_IO_ERROR_TIMED_OUT.
825 	 *
826 	 * Params:
827 	 *     timeout = the timeout
828 	 *
829 	 * Since: 2.26
830 	 */
831 	public void setTimeout(uint timeout)
832 	{
833 		g_socket_client_set_timeout(gSocketClient, timeout);
834 	}
835 
836 	/**
837 	 * Sets whether @client creates TLS (aka SSL) connections. If @tls is
838 	 * %TRUE, @client will wrap its connections in a #GTlsClientConnection
839 	 * and perform a TLS handshake when connecting.
840 	 *
841 	 * Note that since #GSocketClient must return a #GSocketConnection,
842 	 * but #GTlsClientConnection is not a #GSocketConnection, this
843 	 * actually wraps the resulting #GTlsClientConnection in a
844 	 * #GTcpWrapperConnection when returning it. You can use
845 	 * g_tcp_wrapper_connection_get_base_io_stream() on the return value
846 	 * to extract the #GTlsClientConnection.
847 	 *
848 	 * If you need to modify the behavior of the TLS handshake (eg, by
849 	 * setting a client-side certificate to use, or connecting to the
850 	 * #GTlsConnection::accept-certificate signal), you can connect to
851 	 * @client's #GSocketClient::event signal and wait for it to be
852 	 * emitted with %G_SOCKET_CLIENT_TLS_HANDSHAKING, which will give you
853 	 * a chance to see the #GTlsClientConnection before the handshake
854 	 * starts.
855 	 *
856 	 * Params:
857 	 *     tls = whether to use TLS
858 	 *
859 	 * Since: 2.28
860 	 */
861 	public void setTls(bool tls)
862 	{
863 		g_socket_client_set_tls(gSocketClient, tls);
864 	}
865 
866 	/**
867 	 * Sets the TLS validation flags used when creating TLS connections
868 	 * via @client. The default value is %G_TLS_CERTIFICATE_VALIDATE_ALL.
869 	 *
870 	 * Params:
871 	 *     flags = the validation flags
872 	 *
873 	 * Since: 2.28
874 	 */
875 	public void setTlsValidationFlags(GTlsCertificateFlags flags)
876 	{
877 		g_socket_client_set_tls_validation_flags(gSocketClient, flags);
878 	}
879 
880 	protected class OnDelegateWrapper
881 	{
882 		static OnDelegateWrapper[] listeners;
883 		void delegate(GSocketClientEvent, SocketConnectableIF, IOStream, SocketClient) dlg;
884 		gulong handlerId;
885 		
886 		this(void delegate(GSocketClientEvent, SocketConnectableIF, IOStream, SocketClient) dlg)
887 		{
888 			this.dlg = dlg;
889 			this.listeners ~= this;
890 		}
891 		
892 		void remove(OnDelegateWrapper source)
893 		{
894 			foreach(index, wrapper; listeners)
895 			{
896 				if (wrapper.handlerId == source.handlerId)
897 				{
898 					listeners[index] = null;
899 					listeners = std.algorithm.remove(listeners, index);
900 					break;
901 				}
902 			}
903 		}
904 	}
905 
906 	/**
907 	 * Emitted when @client's activity on @connectable changes state.
908 	 * Among other things, this can be used to provide progress
909 	 * information about a network connection in the UI. The meanings of
910 	 * the different @event values are as follows:
911 	 *
912 	 * - %G_SOCKET_CLIENT_RESOLVING: @client is about to look up @connectable
913 	 * in DNS. @connection will be %NULL.
914 	 *
915 	 * - %G_SOCKET_CLIENT_RESOLVED:  @client has successfully resolved
916 	 * @connectable in DNS. @connection will be %NULL.
917 	 *
918 	 * - %G_SOCKET_CLIENT_CONNECTING: @client is about to make a connection
919 	 * to a remote host; either a proxy server or the destination server
920 	 * itself. @connection is the #GSocketConnection, which is not yet
921 	 * connected.  Since GLib 2.40, you can access the remote
922 	 * address via g_socket_connection_get_remote_address().
923 	 *
924 	 * - %G_SOCKET_CLIENT_CONNECTED: @client has successfully connected
925 	 * to a remote host. @connection is the connected #GSocketConnection.
926 	 *
927 	 * - %G_SOCKET_CLIENT_PROXY_NEGOTIATING: @client is about to negotiate
928 	 * with a proxy to get it to connect to @connectable. @connection is
929 	 * the #GSocketConnection to the proxy server.
930 	 *
931 	 * - %G_SOCKET_CLIENT_PROXY_NEGOTIATED: @client has negotiated a
932 	 * connection to @connectable through a proxy server. @connection is
933 	 * the stream returned from g_proxy_connect(), which may or may not
934 	 * be a #GSocketConnection.
935 	 *
936 	 * - %G_SOCKET_CLIENT_TLS_HANDSHAKING: @client is about to begin a TLS
937 	 * handshake. @connection is a #GTlsClientConnection.
938 	 *
939 	 * - %G_SOCKET_CLIENT_TLS_HANDSHAKED: @client has successfully completed
940 	 * the TLS handshake. @connection is a #GTlsClientConnection.
941 	 *
942 	 * - %G_SOCKET_CLIENT_COMPLETE: @client has either successfully connected
943 	 * to @connectable (in which case @connection is the #GSocketConnection
944 	 * that it will be returning to the caller) or has failed (in which
945 	 * case @connection is %NULL and the client is about to return an error).
946 	 *
947 	 * Each event except %G_SOCKET_CLIENT_COMPLETE may be emitted
948 	 * multiple times (or not at all) for a given connectable (in
949 	 * particular, if @client ends up attempting to connect to more than
950 	 * one address). However, if @client emits the #GSocketClient::event
951 	 * signal at all for a given connectable, that it will always emit
952 	 * it with %G_SOCKET_CLIENT_COMPLETE when it is done.
953 	 *
954 	 * Note that there may be additional #GSocketClientEvent values in
955 	 * the future; unrecognized @event values should be ignored.
956 	 *
957 	 * Params:
958 	 *     event = the event that is occurring
959 	 *     connectable = the #GSocketConnectable that @event is occurring on
960 	 *     connection = the current representation of the connection
961 	 *
962 	 * Since: 2.32
963 	 */
964 	gulong addOn(void delegate(GSocketClientEvent, SocketConnectableIF, IOStream, SocketClient) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
965 	{
966 		auto wrapper = new OnDelegateWrapper(dlg);
967 		wrapper.handlerId = Signals.connectData(
968 			this,
969 			"event",
970 			cast(GCallback)&callBack,
971 			cast(void*)wrapper,
972 			cast(GClosureNotify)&callBackDestroy,
973 			connectFlags);
974 		return wrapper.handlerId;
975 	}
976 	
977 	extern(C) static void callBack(GSocketClient* socketclientStruct, GSocketClientEvent event, GSocketConnectable* connectable, GIOStream* connection, OnDelegateWrapper wrapper)
978 	{
979 		wrapper.dlg(event, ObjectG.getDObject!(SocketConnectable, SocketConnectableIF)(connectable), ObjectG.getDObject!(IOStream)(connection), wrapper.outer);
980 	}
981 	
982 	extern(C) static void callBackDestroy(OnDelegateWrapper wrapper, GClosure* closure)
983 	{
984 		wrapper.remove(wrapper);
985 	}
986 }