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