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