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