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 * Description 86 * GResolver provides cancellable synchronous and asynchronous DNS 87 * resolution, for hostnames (g_resolver_lookup_by_address(), 88 * g_resolver_lookup_by_name() and their async variants) and SRV 89 * (service) records (g_resolver_lookup_service()). 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/processes, etc it should allocate for concurrent DNS 165 * resolutions. 166 * Since 2.22 167 * Returns: the default GResolver. [transfer full] 168 */ 169 public static Resolver getDefault() 170 { 171 // GResolver * g_resolver_get_default (void); 172 auto p = g_resolver_get_default(); 173 174 if(p is null) 175 { 176 return null; 177 } 178 179 return ObjectG.getDObject!(Resolver)(cast(GResolver*) p); 180 } 181 182 /** 183 * Sets resolver to be the application's default resolver (reffing 184 * resolver, and unreffing the previous default resolver, if any). 185 * Future calls to g_resolver_get_default() will return this resolver. 186 * This can be used if an application wants to perform any sort of DNS 187 * caching or "pinning"; it can implement its own GResolver that 188 * calls the original default resolver for DNS operations, and 189 * implements its own cache policies on top of that, and then set 190 * itself as the default resolver for all later code to use. 191 * Since 2.22 192 */ 193 public void setDefault() 194 { 195 // void g_resolver_set_default (GResolver *resolver); 196 g_resolver_set_default(gResolver); 197 } 198 199 /** 200 * Synchronously resolves hostname to determine its associated IP 201 * address(es). hostname may be an ASCII-only or UTF-8 hostname, or 202 * the textual form of an IP address (in which case this just becomes 203 * a wrapper around g_inet_address_new_from_string()). 204 * On success, g_resolver_lookup_by_name() will return a GList of 205 * GInetAddress, sorted in order of preference. (That is, you should 206 * attempt to connect to the first address first, then the second if 207 * the first fails, etc.) 208 * If the DNS resolution fails, error (if non-NULL) will be set to a 209 * value from GResolverError. 210 * If cancellable is non-NULL, it can be used to cancel the 211 * operation, in which case error (if non-NULL) will be set to 212 * G_IO_ERROR_CANCELLED. 213 * If you are planning to connect to a socket on the resolved IP 214 * address, it may be easier to create a GNetworkAddress and use its 215 * GSocketConnectable interface. 216 * Since 2.22 217 * Params: 218 * hostname = the hostname to look up 219 * cancellable = a GCancellable, or NULL. [allow-none] 220 * 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] 221 * Throws: GException on failure. 222 */ 223 public ListG lookupByName(string hostname, Cancellable cancellable) 224 { 225 // GList * g_resolver_lookup_by_name (GResolver *resolver, const gchar *hostname, GCancellable *cancellable, GError **error); 226 GError* err = null; 227 228 auto p = g_resolver_lookup_by_name(gResolver, Str.toStringz(hostname), (cancellable is null) ? null : cancellable.getCancellableStruct(), &err); 229 230 if (err !is null) 231 { 232 throw new GException( new ErrorG(err) ); 233 } 234 235 236 if(p is null) 237 { 238 return null; 239 } 240 241 return ObjectG.getDObject!(ListG)(cast(GList*) p); 242 } 243 244 /** 245 * Begins asynchronously resolving hostname to determine its 246 * associated IP address(es), and eventually calls callback, which 247 * must call g_resolver_lookup_by_name_finish() to get the result. 248 * See g_resolver_lookup_by_name() for more details. 249 * Since 2.22 250 * Params: 251 * hostname = the hostname to look up the address of 252 * cancellable = a GCancellable, or NULL. [allow-none] 253 * callback = callback to call after resolution completes. [scope async] 254 * userData = data for callback. [closure] 255 */ 256 public void lookupByNameAsync(string hostname, Cancellable cancellable, GAsyncReadyCallback callback, void* userData) 257 { 258 // void g_resolver_lookup_by_name_async (GResolver *resolver, const gchar *hostname, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data); 259 g_resolver_lookup_by_name_async(gResolver, Str.toStringz(hostname), (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData); 260 } 261 262 /** 263 * Retrieves the result of a call to 264 * g_resolver_lookup_by_name_async(). 265 * If the DNS resolution failed, error (if non-NULL) will be set to 266 * a value from GResolverError. If the operation was cancelled, 267 * error will be set to G_IO_ERROR_CANCELLED. 268 * Since 2.22 269 * Params: 270 * result = the result passed to your GAsyncReadyCallback 271 * Returns: a GList of GInetAddress, or NULL on error. See g_resolver_lookup_by_name() for more details. [element-type GInetAddress][transfer full] 272 * Throws: GException on failure. 273 */ 274 public ListG lookupByNameFinish(AsyncResultIF result) 275 { 276 // GList * g_resolver_lookup_by_name_finish (GResolver *resolver, GAsyncResult *result, GError **error); 277 GError* err = null; 278 279 auto p = g_resolver_lookup_by_name_finish(gResolver, (result is null) ? null : result.getAsyncResultTStruct(), &err); 280 281 if (err !is null) 282 { 283 throw new GException( new ErrorG(err) ); 284 } 285 286 287 if(p is null) 288 { 289 return null; 290 } 291 292 return ObjectG.getDObject!(ListG)(cast(GList*) p); 293 } 294 295 /** 296 * Frees addresses (which should be the return value from 297 * g_resolver_lookup_by_name() or g_resolver_lookup_by_name_finish()). 298 * (This is a convenience method; you can also simply free the results 299 * by hand.) 300 * Since 2.22 301 * Params: 302 * addresses = a GList of GInetAddress 303 */ 304 public static void freeAddresses(ListG addresses) 305 { 306 // void g_resolver_free_addresses (GList *addresses); 307 g_resolver_free_addresses((addresses is null) ? null : addresses.getListGStruct()); 308 } 309 310 /** 311 * Synchronously reverse-resolves address to determine its 312 * associated hostname. 313 * If the DNS resolution fails, error (if non-NULL) will be set to 314 * a value from GResolverError. 315 * If cancellable is non-NULL, it can be used to cancel the 316 * operation, in which case error (if non-NULL) will be set to 317 * G_IO_ERROR_CANCELLED. 318 * Since 2.22 319 * Params: 320 * address = the address to reverse-resolve 321 * cancellable = a GCancellable, or NULL. [allow-none] 322 * Returns: a hostname (either ASCII-only, or in ASCII-encoded form), or NULL on error. 323 * Throws: GException on failure. 324 */ 325 public string lookupByAddress(GInetAddress* address, Cancellable cancellable) 326 { 327 // gchar * g_resolver_lookup_by_address (GResolver *resolver, GInetAddress *address, GCancellable *cancellable, GError **error); 328 GError* err = null; 329 330 auto p = g_resolver_lookup_by_address(gResolver, address, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err); 331 332 if (err !is null) 333 { 334 throw new GException( new ErrorG(err) ); 335 } 336 337 return Str.toString(p); 338 } 339 340 /** 341 * Begins asynchronously reverse-resolving address to determine its 342 * associated hostname, and eventually calls callback, which must 343 * call g_resolver_lookup_by_address_finish() to get the final result. 344 * Since 2.22 345 * Params: 346 * address = the address to reverse-resolve 347 * cancellable = a GCancellable, or NULL. [allow-none] 348 * callback = callback to call after resolution completes. [scope async] 349 * userData = data for callback. [closure] 350 */ 351 public void lookupByAddressAsync(GInetAddress* address, Cancellable cancellable, GAsyncReadyCallback callback, void* userData) 352 { 353 // void g_resolver_lookup_by_address_async (GResolver *resolver, GInetAddress *address, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data); 354 g_resolver_lookup_by_address_async(gResolver, address, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData); 355 } 356 357 /** 358 * Retrieves the result of a previous call to 359 * g_resolver_lookup_by_address_async(). 360 * If the DNS resolution failed, error (if non-NULL) will be set to 361 * a value from GResolverError. If the operation was cancelled, 362 * error will be set to G_IO_ERROR_CANCELLED. 363 * Since 2.22 364 * Params: 365 * result = the result passed to your GAsyncReadyCallback 366 * Returns: a hostname (either ASCII-only, or in ASCII-encoded form), or NULL on error. 367 * Throws: GException on failure. 368 */ 369 public string lookupByAddressFinish(AsyncResultIF result) 370 { 371 // gchar * g_resolver_lookup_by_address_finish (GResolver *resolver, GAsyncResult *result, GError **error); 372 GError* err = null; 373 374 auto p = g_resolver_lookup_by_address_finish(gResolver, (result is null) ? null : result.getAsyncResultTStruct(), &err); 375 376 if (err !is null) 377 { 378 throw new GException( new ErrorG(err) ); 379 } 380 381 return Str.toString(p); 382 } 383 384 /** 385 * Synchronously performs a DNS SRV lookup for the given service and 386 * protocol in the given domain and returns an array of GSrvTarget. 387 * domain may be an ASCII-only or UTF-8 hostname. Note also that the 388 * service and protocol arguments do not 389 * include the leading underscore that appears in the actual DNS 390 * entry. 391 * On success, g_resolver_lookup_service() will return a GList of 392 * GSrvTarget, sorted in order of preference. (That is, you should 393 * attempt to connect to the first target first, then the second if 394 * the first fails, etc.) 395 * If the DNS resolution fails, error (if non-NULL) will be set to 396 * a value from GResolverError. 397 * If cancellable is non-NULL, it can be used to cancel the 398 * operation, in which case error (if non-NULL) will be set to 399 * G_IO_ERROR_CANCELLED. 400 * If you are planning to connect to the service, it is usually easier 401 * to create a GNetworkService and use its GSocketConnectable 402 * interface. 403 * Since 2.22 404 * Params: 405 * service = the service type to look up (eg, "ldap") 406 * protocol = the networking protocol to use for service (eg, "tcp") 407 * domain = the DNS domain to look up the service in 408 * cancellable = a GCancellable, or NULL. [allow-none] 409 * 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] 410 * Throws: GException on failure. 411 */ 412 public ListG lookupService(string service, string protocol, string domain, Cancellable cancellable) 413 { 414 // GList * g_resolver_lookup_service (GResolver *resolver, const gchar *service, const gchar *protocol, const gchar *domain, GCancellable *cancellable, GError **error); 415 GError* err = null; 416 417 auto p = g_resolver_lookup_service(gResolver, Str.toStringz(service), Str.toStringz(protocol), Str.toStringz(domain), (cancellable is null) ? null : cancellable.getCancellableStruct(), &err); 418 419 if (err !is null) 420 { 421 throw new GException( new ErrorG(err) ); 422 } 423 424 425 if(p is null) 426 { 427 return null; 428 } 429 430 return ObjectG.getDObject!(ListG)(cast(GList*) p); 431 } 432 433 /** 434 * Begins asynchronously performing a DNS SRV lookup for the given 435 * service and protocol in the given domain, and eventually calls 436 * callback, which must call g_resolver_lookup_service_finish() to 437 * get the final result. See g_resolver_lookup_service() for more 438 * details. 439 * Since 2.22 440 * Params: 441 * service = the service type to look up (eg, "ldap") 442 * protocol = the networking protocol to use for service (eg, "tcp") 443 * domain = the DNS domain to look up the service in 444 * cancellable = a GCancellable, or NULL. [allow-none] 445 * callback = callback to call after resolution completes. [scope async] 446 * userData = data for callback. [closure] 447 */ 448 public void lookupServiceAsync(string service, string protocol, string domain, Cancellable cancellable, GAsyncReadyCallback callback, void* userData) 449 { 450 // void g_resolver_lookup_service_async (GResolver *resolver, const gchar *service, const gchar *protocol, const gchar *domain, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data); 451 g_resolver_lookup_service_async(gResolver, Str.toStringz(service), Str.toStringz(protocol), Str.toStringz(domain), (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData); 452 } 453 454 /** 455 * Retrieves the result of a previous call to 456 * g_resolver_lookup_service_async(). 457 * If the DNS resolution failed, error (if non-NULL) will be set to 458 * a value from GResolverError. If the operation was cancelled, 459 * error will be set to G_IO_ERROR_CANCELLED. 460 * Since 2.22 461 * Params: 462 * result = the result passed to your GAsyncReadyCallback 463 * Returns: a GList of GSrvTarget, or NULL on error. See g_resolver_lookup_service() for more details. [element-type GSrvTarget][transfer full] 464 * Throws: GException on failure. 465 */ 466 public ListG lookupServiceFinish(AsyncResultIF result) 467 { 468 // GList * g_resolver_lookup_service_finish (GResolver *resolver, GAsyncResult *result, GError **error); 469 GError* err = null; 470 471 auto p = g_resolver_lookup_service_finish(gResolver, (result is null) ? null : result.getAsyncResultTStruct(), &err); 472 473 if (err !is null) 474 { 475 throw new GException( new ErrorG(err) ); 476 } 477 478 479 if(p is null) 480 { 481 return null; 482 } 483 484 return ObjectG.getDObject!(ListG)(cast(GList*) p); 485 } 486 487 /** 488 * Frees targets (which should be the return value from 489 * g_resolver_lookup_service() or g_resolver_lookup_service_finish()). 490 * (This is a convenience method; you can also simply free the 491 * results by hand.) 492 * Since 2.22 493 * Params: 494 * targets = a GList of GSrvTarget 495 */ 496 public static void freeTargets(ListG targets) 497 { 498 // void g_resolver_free_targets (GList *targets); 499 g_resolver_free_targets((targets is null) ? null : targets.getListGStruct()); 500 } 501 }