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.Resolver; 26 27 private import gio.AsyncResultIF; 28 private import gio.Cancellable; 29 private import gio.InetAddress; 30 private import gio.c.functions; 31 public import gio.c.types; 32 private import glib.ErrorG; 33 private import glib.GException; 34 private import glib.ListG; 35 private import glib.Str; 36 private import gobject.ObjectG; 37 private import gobject.Signals; 38 public import gtkc.giotypes; 39 private import std.algorithm; 40 41 42 /** 43 * #GResolver provides cancellable synchronous and asynchronous DNS 44 * resolution, for hostnames (g_resolver_lookup_by_address(), 45 * g_resolver_lookup_by_name() and their async variants) and SRV 46 * (service) records (g_resolver_lookup_service()). 47 * 48 * #GNetworkAddress and #GNetworkService provide wrappers around 49 * #GResolver functionality that also implement #GSocketConnectable, 50 * making it easy to connect to a remote host/service. 51 */ 52 public class Resolver : ObjectG 53 { 54 /** the main Gtk struct */ 55 protected GResolver* gResolver; 56 57 /** Get the main Gtk struct */ 58 public GResolver* getResolverStruct(bool transferOwnership = false) 59 { 60 if (transferOwnership) 61 ownedRef = false; 62 return gResolver; 63 } 64 65 /** the main Gtk struct as a void* */ 66 protected override void* getStruct() 67 { 68 return cast(void*)gResolver; 69 } 70 71 /** 72 * Sets our main struct and passes it to the parent class. 73 */ 74 public this (GResolver* gResolver, bool ownedRef = false) 75 { 76 this.gResolver = gResolver; 77 super(cast(GObject*)gResolver, ownedRef); 78 } 79 80 81 /** */ 82 public static GType getType() 83 { 84 return g_resolver_get_type(); 85 } 86 87 /** 88 * Frees @addresses (which should be the return value from 89 * g_resolver_lookup_by_name() or g_resolver_lookup_by_name_finish()). 90 * (This is a convenience method; you can also simply free the results 91 * by hand.) 92 * 93 * Params: 94 * addresses = a #GList of #GInetAddress 95 * 96 * Since: 2.22 97 */ 98 public static void freeAddresses(ListG addresses) 99 { 100 g_resolver_free_addresses((addresses is null) ? null : addresses.getListGStruct()); 101 } 102 103 /** 104 * Frees @targets (which should be the return value from 105 * g_resolver_lookup_service() or g_resolver_lookup_service_finish()). 106 * (This is a convenience method; you can also simply free the 107 * results by hand.) 108 * 109 * Params: 110 * targets = a #GList of #GSrvTarget 111 * 112 * Since: 2.22 113 */ 114 public static void freeTargets(ListG targets) 115 { 116 g_resolver_free_targets((targets is null) ? null : targets.getListGStruct()); 117 } 118 119 /** 120 * Gets the default #GResolver. You should unref it when you are done 121 * with it. #GResolver may use its reference count as a hint about how 122 * many threads it should allocate for concurrent DNS resolutions. 123 * 124 * Returns: the default #GResolver. 125 * 126 * Since: 2.22 127 */ 128 public static Resolver getDefault() 129 { 130 auto __p = g_resolver_get_default(); 131 132 if(__p is null) 133 { 134 return null; 135 } 136 137 return ObjectG.getDObject!(Resolver)(cast(GResolver*) __p, true); 138 } 139 140 /** 141 * Synchronously reverse-resolves @address to determine its 142 * associated hostname. 143 * 144 * If the DNS resolution fails, @error (if non-%NULL) will be set to 145 * a value from #GResolverError. 146 * 147 * If @cancellable is non-%NULL, it can be used to cancel the 148 * operation, in which case @error (if non-%NULL) will be set to 149 * %G_IO_ERROR_CANCELLED. 150 * 151 * Params: 152 * address = the address to reverse-resolve 153 * cancellable = a #GCancellable, or %NULL 154 * 155 * Returns: a hostname (either ASCII-only, or in ASCII-encoded 156 * form), or %NULL on error. 157 * 158 * Since: 2.22 159 * 160 * Throws: GException on failure. 161 */ 162 public string lookupByAddress(InetAddress address, Cancellable cancellable) 163 { 164 GError* err = null; 165 166 auto retStr = g_resolver_lookup_by_address(gResolver, (address is null) ? null : address.getInetAddressStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), &err); 167 168 if (err !is null) 169 { 170 throw new GException( new ErrorG(err) ); 171 } 172 173 scope(exit) Str.freeString(retStr); 174 return Str.toString(retStr); 175 } 176 177 /** 178 * Begins asynchronously reverse-resolving @address to determine its 179 * associated hostname, and eventually calls @callback, which must 180 * call g_resolver_lookup_by_address_finish() to get the final result. 181 * 182 * Params: 183 * address = the address to reverse-resolve 184 * cancellable = a #GCancellable, or %NULL 185 * callback = callback to call after resolution completes 186 * userData = data for @callback 187 * 188 * Since: 2.22 189 */ 190 public void lookupByAddressAsync(InetAddress address, Cancellable cancellable, GAsyncReadyCallback callback, void* userData) 191 { 192 g_resolver_lookup_by_address_async(gResolver, (address is null) ? null : address.getInetAddressStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData); 193 } 194 195 /** 196 * Retrieves the result of a previous call to 197 * g_resolver_lookup_by_address_async(). 198 * 199 * If the DNS resolution failed, @error (if non-%NULL) will be set to 200 * a value from #GResolverError. If the operation was cancelled, 201 * @error will be set to %G_IO_ERROR_CANCELLED. 202 * 203 * Params: 204 * result = the result passed to your #GAsyncReadyCallback 205 * 206 * Returns: a hostname (either ASCII-only, or in ASCII-encoded 207 * form), or %NULL on error. 208 * 209 * Since: 2.22 210 * 211 * Throws: GException on failure. 212 */ 213 public string lookupByAddressFinish(AsyncResultIF result) 214 { 215 GError* err = null; 216 217 auto retStr = g_resolver_lookup_by_address_finish(gResolver, (result is null) ? null : result.getAsyncResultStruct(), &err); 218 219 if (err !is null) 220 { 221 throw new GException( new ErrorG(err) ); 222 } 223 224 scope(exit) Str.freeString(retStr); 225 return Str.toString(retStr); 226 } 227 228 /** 229 * Synchronously resolves @hostname to determine its associated IP 230 * address(es). @hostname may be an ASCII-only or UTF-8 hostname, or 231 * the textual form of an IP address (in which case this just becomes 232 * a wrapper around g_inet_address_new_from_string()). 233 * 234 * On success, g_resolver_lookup_by_name() will return a non-empty #GList of 235 * #GInetAddress, sorted in order of preference and guaranteed to not 236 * contain duplicates. That is, if using the result to connect to 237 * @hostname, you should attempt to connect to the first address 238 * first, then the second if the first fails, etc. If you are using 239 * the result to listen on a socket, it is appropriate to add each 240 * result using e.g. g_socket_listener_add_address(). 241 * 242 * If the DNS resolution fails, @error (if non-%NULL) will be set to a 243 * value from #GResolverError and %NULL will be returned. 244 * 245 * If @cancellable is non-%NULL, it can be used to cancel the 246 * operation, in which case @error (if non-%NULL) will be set to 247 * %G_IO_ERROR_CANCELLED. 248 * 249 * If you are planning to connect to a socket on the resolved IP 250 * address, it may be easier to create a #GNetworkAddress and use its 251 * #GSocketConnectable interface. 252 * 253 * Params: 254 * hostname = the hostname to look up 255 * cancellable = a #GCancellable, or %NULL 256 * 257 * Returns: a non-empty #GList 258 * of #GInetAddress, or %NULL on error. You 259 * must unref each of the addresses and free the list when you are 260 * done with it. (You can use g_resolver_free_addresses() to do this.) 261 * 262 * Since: 2.22 263 * 264 * Throws: GException on failure. 265 */ 266 public ListG lookupByName(string hostname, Cancellable cancellable) 267 { 268 GError* err = null; 269 270 auto __p = g_resolver_lookup_by_name(gResolver, Str.toStringz(hostname), (cancellable is null) ? null : cancellable.getCancellableStruct(), &err); 271 272 if (err !is null) 273 { 274 throw new GException( new ErrorG(err) ); 275 } 276 277 if(__p is null) 278 { 279 return null; 280 } 281 282 return new ListG(cast(GList*) __p, true); 283 } 284 285 /** 286 * Begins asynchronously resolving @hostname to determine its 287 * associated IP address(es), and eventually calls @callback, which 288 * must call g_resolver_lookup_by_name_finish() to get the result. 289 * See g_resolver_lookup_by_name() for more details. 290 * 291 * Params: 292 * hostname = the hostname to look up the address of 293 * cancellable = a #GCancellable, or %NULL 294 * callback = callback to call after resolution completes 295 * userData = data for @callback 296 * 297 * Since: 2.22 298 */ 299 public void lookupByNameAsync(string hostname, Cancellable cancellable, GAsyncReadyCallback callback, void* userData) 300 { 301 g_resolver_lookup_by_name_async(gResolver, Str.toStringz(hostname), (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData); 302 } 303 304 /** 305 * Retrieves the result of a call to 306 * g_resolver_lookup_by_name_async(). 307 * 308 * If the DNS resolution failed, @error (if non-%NULL) will be set to 309 * a value from #GResolverError. If the operation was cancelled, 310 * @error will be set to %G_IO_ERROR_CANCELLED. 311 * 312 * Params: 313 * result = the result passed to your #GAsyncReadyCallback 314 * 315 * Returns: a #GList 316 * of #GInetAddress, or %NULL on error. See g_resolver_lookup_by_name() 317 * for more details. 318 * 319 * Since: 2.22 320 * 321 * Throws: GException on failure. 322 */ 323 public ListG lookupByNameFinish(AsyncResultIF result) 324 { 325 GError* err = null; 326 327 auto __p = g_resolver_lookup_by_name_finish(gResolver, (result is null) ? null : result.getAsyncResultStruct(), &err); 328 329 if (err !is null) 330 { 331 throw new GException( new ErrorG(err) ); 332 } 333 334 if(__p is null) 335 { 336 return null; 337 } 338 339 return new ListG(cast(GList*) __p, true); 340 } 341 342 /** 343 * This differs from g_resolver_lookup_by_name() in that you can modify 344 * the lookup behavior with @flags. For example this can be used to limit 345 * results with #G_RESOLVER_NAME_LOOKUP_FLAGS_IPV4_ONLY. 346 * 347 * Params: 348 * hostname = the hostname to look up 349 * flags = extra #GResolverNameLookupFlags for the lookup 350 * cancellable = a #GCancellable, or %NULL 351 * 352 * Returns: a non-empty #GList 353 * of #GInetAddress, or %NULL on error. You 354 * must unref each of the addresses and free the list when you are 355 * done with it. (You can use g_resolver_free_addresses() to do this.) 356 * 357 * Since: 2.60 358 * 359 * Throws: GException on failure. 360 */ 361 public ListG lookupByNameWithFlags(string hostname, GResolverNameLookupFlags flags, Cancellable cancellable) 362 { 363 GError* err = null; 364 365 auto __p = g_resolver_lookup_by_name_with_flags(gResolver, Str.toStringz(hostname), flags, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err); 366 367 if (err !is null) 368 { 369 throw new GException( new ErrorG(err) ); 370 } 371 372 if(__p is null) 373 { 374 return null; 375 } 376 377 return new ListG(cast(GList*) __p, true); 378 } 379 380 /** 381 * Begins asynchronously resolving @hostname to determine its 382 * associated IP address(es), and eventually calls @callback, which 383 * must call g_resolver_lookup_by_name_with_flags_finish() to get the result. 384 * See g_resolver_lookup_by_name() for more details. 385 * 386 * Params: 387 * hostname = the hostname to look up the address of 388 * flags = extra #GResolverNameLookupFlags for the lookup 389 * cancellable = a #GCancellable, or %NULL 390 * callback = callback to call after resolution completes 391 * userData = data for @callback 392 * 393 * Since: 2.60 394 */ 395 public void lookupByNameWithFlagsAsync(string hostname, GResolverNameLookupFlags flags, Cancellable cancellable, GAsyncReadyCallback callback, void* userData) 396 { 397 g_resolver_lookup_by_name_with_flags_async(gResolver, Str.toStringz(hostname), flags, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData); 398 } 399 400 /** 401 * Retrieves the result of a call to 402 * g_resolver_lookup_by_name_with_flags_async(). 403 * 404 * If the DNS resolution failed, @error (if non-%NULL) will be set to 405 * a value from #GResolverError. If the operation was cancelled, 406 * @error will be set to %G_IO_ERROR_CANCELLED. 407 * 408 * Params: 409 * result = the result passed to your #GAsyncReadyCallback 410 * 411 * Returns: a #GList 412 * of #GInetAddress, or %NULL on error. See g_resolver_lookup_by_name() 413 * for more details. 414 * 415 * Since: 2.60 416 * 417 * Throws: GException on failure. 418 */ 419 public ListG lookupByNameWithFlagsFinish(AsyncResultIF result) 420 { 421 GError* err = null; 422 423 auto __p = g_resolver_lookup_by_name_with_flags_finish(gResolver, (result is null) ? null : result.getAsyncResultStruct(), &err); 424 425 if (err !is null) 426 { 427 throw new GException( new ErrorG(err) ); 428 } 429 430 if(__p is null) 431 { 432 return null; 433 } 434 435 return new ListG(cast(GList*) __p, true); 436 } 437 438 /** 439 * Synchronously performs a DNS record lookup for the given @rrname and returns 440 * a list of records as #GVariant tuples. See #GResolverRecordType for 441 * information on what the records contain for each @record_type. 442 * 443 * If the DNS resolution fails, @error (if non-%NULL) will be set to 444 * a value from #GResolverError and %NULL will be returned. 445 * 446 * If @cancellable is non-%NULL, it can be used to cancel the 447 * operation, in which case @error (if non-%NULL) will be set to 448 * %G_IO_ERROR_CANCELLED. 449 * 450 * Params: 451 * rrname = the DNS name to look up the record for 452 * recordType = the type of DNS record to look up 453 * cancellable = a #GCancellable, or %NULL 454 * 455 * Returns: a non-empty #GList of 456 * #GVariant, or %NULL on error. You must free each of the records and the list 457 * when you are done with it. (You can use g_list_free_full() with 458 * g_variant_unref() to do this.) 459 * 460 * Since: 2.34 461 * 462 * Throws: GException on failure. 463 */ 464 public ListG lookupRecords(string rrname, GResolverRecordType recordType, Cancellable cancellable) 465 { 466 GError* err = null; 467 468 auto __p = g_resolver_lookup_records(gResolver, Str.toStringz(rrname), recordType, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err); 469 470 if (err !is null) 471 { 472 throw new GException( new ErrorG(err) ); 473 } 474 475 if(__p is null) 476 { 477 return null; 478 } 479 480 return new ListG(cast(GList*) __p, true); 481 } 482 483 /** 484 * Begins asynchronously performing a DNS lookup for the given 485 * @rrname, and eventually calls @callback, which must call 486 * g_resolver_lookup_records_finish() to get the final result. See 487 * g_resolver_lookup_records() for more details. 488 * 489 * Params: 490 * rrname = the DNS name to look up the record for 491 * recordType = the type of DNS record to look up 492 * cancellable = a #GCancellable, or %NULL 493 * callback = callback to call after resolution completes 494 * userData = data for @callback 495 * 496 * Since: 2.34 497 */ 498 public void lookupRecordsAsync(string rrname, GResolverRecordType recordType, Cancellable cancellable, GAsyncReadyCallback callback, void* userData) 499 { 500 g_resolver_lookup_records_async(gResolver, Str.toStringz(rrname), recordType, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData); 501 } 502 503 /** 504 * Retrieves the result of a previous call to 505 * g_resolver_lookup_records_async(). Returns a non-empty list of records as 506 * #GVariant tuples. See #GResolverRecordType for information on what the 507 * records contain. 508 * 509 * If the DNS resolution failed, @error (if non-%NULL) will be set to 510 * a value from #GResolverError. If the operation was cancelled, 511 * @error will be set to %G_IO_ERROR_CANCELLED. 512 * 513 * Params: 514 * result = the result passed to your #GAsyncReadyCallback 515 * 516 * Returns: a non-empty #GList of 517 * #GVariant, or %NULL on error. You must free each of the records and the list 518 * when you are done with it. (You can use g_list_free_full() with 519 * g_variant_unref() to do this.) 520 * 521 * Since: 2.34 522 * 523 * Throws: GException on failure. 524 */ 525 public ListG lookupRecordsFinish(AsyncResultIF result) 526 { 527 GError* err = null; 528 529 auto __p = g_resolver_lookup_records_finish(gResolver, (result is null) ? null : result.getAsyncResultStruct(), &err); 530 531 if (err !is null) 532 { 533 throw new GException( new ErrorG(err) ); 534 } 535 536 if(__p is null) 537 { 538 return null; 539 } 540 541 return new ListG(cast(GList*) __p, true); 542 } 543 544 /** 545 * Synchronously performs a DNS SRV lookup for the given @service and 546 * @protocol in the given @domain and returns an array of #GSrvTarget. 547 * @domain may be an ASCII-only or UTF-8 hostname. Note also that the 548 * @service and @protocol arguments do not include the leading underscore 549 * that appears in the actual DNS entry. 550 * 551 * On success, g_resolver_lookup_service() will return a non-empty #GList of 552 * #GSrvTarget, sorted in order of preference. (That is, you should 553 * attempt to connect to the first target first, then the second if 554 * the first fails, etc.) 555 * 556 * If the DNS resolution fails, @error (if non-%NULL) will be set to 557 * a value from #GResolverError and %NULL will be returned. 558 * 559 * If @cancellable is non-%NULL, it can be used to cancel the 560 * operation, in which case @error (if non-%NULL) will be set to 561 * %G_IO_ERROR_CANCELLED. 562 * 563 * If you are planning to connect to the service, it is usually easier 564 * to create a #GNetworkService and use its #GSocketConnectable 565 * interface. 566 * 567 * Params: 568 * service = the service type to look up (eg, "ldap") 569 * protocol = the networking protocol to use for @service (eg, "tcp") 570 * domain = the DNS domain to look up the service in 571 * cancellable = a #GCancellable, or %NULL 572 * 573 * Returns: a non-empty #GList of 574 * #GSrvTarget, or %NULL on error. You must free each of the targets and the 575 * list when you are done with it. (You can use g_resolver_free_targets() to do 576 * this.) 577 * 578 * Since: 2.22 579 * 580 * Throws: GException on failure. 581 */ 582 public ListG lookupService(string service, string protocol, string domain, Cancellable cancellable) 583 { 584 GError* err = null; 585 586 auto __p = g_resolver_lookup_service(gResolver, Str.toStringz(service), Str.toStringz(protocol), Str.toStringz(domain), (cancellable is null) ? null : cancellable.getCancellableStruct(), &err); 587 588 if (err !is null) 589 { 590 throw new GException( new ErrorG(err) ); 591 } 592 593 if(__p is null) 594 { 595 return null; 596 } 597 598 return new ListG(cast(GList*) __p, true); 599 } 600 601 /** 602 * Begins asynchronously performing a DNS SRV lookup for the given 603 * @service and @protocol in the given @domain, and eventually calls 604 * @callback, which must call g_resolver_lookup_service_finish() to 605 * get the final result. See g_resolver_lookup_service() for more 606 * details. 607 * 608 * Params: 609 * service = the service type to look up (eg, "ldap") 610 * protocol = the networking protocol to use for @service (eg, "tcp") 611 * domain = the DNS domain to look up the service in 612 * cancellable = a #GCancellable, or %NULL 613 * callback = callback to call after resolution completes 614 * userData = data for @callback 615 * 616 * Since: 2.22 617 */ 618 public void lookupServiceAsync(string service, string protocol, string domain, Cancellable cancellable, GAsyncReadyCallback callback, void* userData) 619 { 620 g_resolver_lookup_service_async(gResolver, Str.toStringz(service), Str.toStringz(protocol), Str.toStringz(domain), (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData); 621 } 622 623 /** 624 * Retrieves the result of a previous call to 625 * g_resolver_lookup_service_async(). 626 * 627 * If the DNS resolution failed, @error (if non-%NULL) will be set to 628 * a value from #GResolverError. If the operation was cancelled, 629 * @error will be set to %G_IO_ERROR_CANCELLED. 630 * 631 * Params: 632 * result = the result passed to your #GAsyncReadyCallback 633 * 634 * Returns: a non-empty #GList of 635 * #GSrvTarget, or %NULL on error. See g_resolver_lookup_service() for more 636 * details. 637 * 638 * Since: 2.22 639 * 640 * Throws: GException on failure. 641 */ 642 public ListG lookupServiceFinish(AsyncResultIF result) 643 { 644 GError* err = null; 645 646 auto __p = g_resolver_lookup_service_finish(gResolver, (result is null) ? null : result.getAsyncResultStruct(), &err); 647 648 if (err !is null) 649 { 650 throw new GException( new ErrorG(err) ); 651 } 652 653 if(__p is null) 654 { 655 return null; 656 } 657 658 return new ListG(cast(GList*) __p, true); 659 } 660 661 /** 662 * Sets @resolver to be the application's default resolver (reffing 663 * @resolver, and unreffing the previous default resolver, if any). 664 * Future calls to g_resolver_get_default() will return this resolver. 665 * 666 * This can be used if an application wants to perform any sort of DNS 667 * caching or "pinning"; it can implement its own #GResolver that 668 * calls the original default resolver for DNS operations, and 669 * implements its own cache policies on top of that, and then set 670 * itself as the default resolver for all later code to use. 671 * 672 * Since: 2.22 673 */ 674 public void setDefault() 675 { 676 g_resolver_set_default(gResolver); 677 } 678 679 /** 680 * Emitted when the resolver notices that the system resolver 681 * configuration has changed. 682 */ 683 gulong addOnReload(void delegate(Resolver) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 684 { 685 return Signals.connect(this, "reload", dlg, connectFlags ^ ConnectFlags.SWAPPED); 686 } 687 }