1 /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
3 /* GIO - GLib Input, Output and Streaming Library
5 * Copyright (C) 2008 Red Hat, Inc.
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General
18 * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
25 #include "gresolver.h"
26 #include "gnetworkingprivate.h"
27 #include "gasyncresult.h"
28 #include "ginetaddress.h"
30 #include "gsrvtarget.h"
31 #include "gthreadedresolver.h"
43 * @short_description: Asynchronous and cancellable DNS resolver
46 * #GResolver provides cancellable synchronous and asynchronous DNS
47 * resolution, for hostnames (g_resolver_lookup_by_address(),
48 * g_resolver_lookup_by_name() and their async variants) and SRV
49 * (service) records (g_resolver_lookup_service()).
51 * #GNetworkAddress and #GNetworkService provide wrappers around
52 * #GResolver functionality that also implement #GSocketConnectable,
53 * making it easy to connect to a remote host/service.
61 static guint signals
[LAST_SIGNAL
] = { 0 };
63 struct _GResolverPrivate
{
65 time_t resolv_conf_timestamp
;
74 * The object that handles DNS resolution. Use g_resolver_get_default()
75 * to get the default resolver.
77 * This is an abstract type; subclasses of it implement different resolvers for
78 * different platforms and situations.
80 G_DEFINE_ABSTRACT_TYPE_WITH_CODE (GResolver
, g_resolver
, G_TYPE_OBJECT
,
81 G_ADD_PRIVATE (GResolver
)
82 g_networking_init ();)
85 srv_records_to_targets (GList
*records
)
87 const gchar
*hostname
;
88 guint16 port
, priority
, weight
;
92 for (l
= records
; l
!= NULL
; l
= g_list_next (l
))
94 g_variant_get (l
->data
, "(qqq&s)", &priority
, &weight
, &port
, &hostname
);
95 target
= g_srv_target_new (hostname
, port
, priority
, weight
);
96 g_variant_unref (l
->data
);
100 return g_srv_target_list_sort (records
);
104 g_resolver_real_lookup_service (GResolver
*resolver
,
106 GCancellable
*cancellable
,
111 records
= G_RESOLVER_GET_CLASS (resolver
)->lookup_records (resolver
,
113 G_RESOLVER_RECORD_SRV
,
117 return srv_records_to_targets (records
);
121 g_resolver_real_lookup_service_async (GResolver
*resolver
,
123 GCancellable
*cancellable
,
124 GAsyncReadyCallback callback
,
127 G_RESOLVER_GET_CLASS (resolver
)->lookup_records_async (resolver
,
129 G_RESOLVER_RECORD_SRV
,
136 g_resolver_real_lookup_service_finish (GResolver
*resolver
,
137 GAsyncResult
*result
,
142 records
= G_RESOLVER_GET_CLASS (resolver
)->lookup_records_finish (resolver
,
146 return srv_records_to_targets (records
);
150 g_resolver_class_init (GResolverClass
*resolver_class
)
152 /* Automatically pass these over to the lookup_records methods */
153 resolver_class
->lookup_service
= g_resolver_real_lookup_service
;
154 resolver_class
->lookup_service_async
= g_resolver_real_lookup_service_async
;
155 resolver_class
->lookup_service_finish
= g_resolver_real_lookup_service_finish
;
159 * @resolver: a #GResolver
161 * Emitted when the resolver notices that the system resolver
162 * configuration has changed.
165 g_signal_new (I_("reload"),
168 G_STRUCT_OFFSET (GResolverClass
, reload
),
170 g_cclosure_marshal_VOID__VOID
,
175 g_resolver_init (GResolver
*resolver
)
181 resolver
->priv
= g_resolver_get_instance_private (resolver
);
184 if (stat (_PATH_RESCONF
, &st
) == 0)
185 resolver
->priv
->resolv_conf_timestamp
= st
.st_mtime
;
189 G_LOCK_DEFINE_STATIC (default_resolver
);
190 static GResolver
*default_resolver
;
193 * g_resolver_get_default:
195 * Gets the default #GResolver. You should unref it when you are done
196 * with it. #GResolver may use its reference count as a hint about how
197 * many threads it should allocate for concurrent DNS resolutions.
199 * Returns: (transfer full): the default #GResolver.
204 g_resolver_get_default (void)
208 G_LOCK (default_resolver
);
209 if (!default_resolver
)
210 default_resolver
= g_object_new (G_TYPE_THREADED_RESOLVER
, NULL
);
211 ret
= g_object_ref (default_resolver
);
212 G_UNLOCK (default_resolver
);
218 * g_resolver_set_default:
219 * @resolver: the new default #GResolver
221 * Sets @resolver to be the application's default resolver (reffing
222 * @resolver, and unreffing the previous default resolver, if any).
223 * Future calls to g_resolver_get_default() will return this resolver.
225 * This can be used if an application wants to perform any sort of DNS
226 * caching or "pinning"; it can implement its own #GResolver that
227 * calls the original default resolver for DNS operations, and
228 * implements its own cache policies on top of that, and then set
229 * itself as the default resolver for all later code to use.
234 g_resolver_set_default (GResolver
*resolver
)
236 G_LOCK (default_resolver
);
237 if (default_resolver
)
238 g_object_unref (default_resolver
);
239 default_resolver
= g_object_ref (resolver
);
240 G_UNLOCK (default_resolver
);
243 /* Bionic has res_init() but it's not in any header */
249 g_resolver_maybe_reload (GResolver
*resolver
)
254 if (stat (_PATH_RESCONF
, &st
) == 0)
256 if (st
.st_mtime
!= resolver
->priv
->resolv_conf_timestamp
)
258 resolver
->priv
->resolv_conf_timestamp
= st
.st_mtime
;
262 g_signal_emit (resolver
, signals
[RELOAD
], 0);
268 /* filter out duplicates, cf. https://bugzilla.gnome.org/show_bug.cgi?id=631379 */
270 remove_duplicates (GList
*addrs
)
276 /* TODO: if this is too slow (it's O(n^2) but n is typically really
277 * small), we can do something more clever but note that we must not
278 * change the order of elements...
280 for (l
= addrs
; l
!= NULL
; l
= l
->next
)
282 GInetAddress
*address
= G_INET_ADDRESS (l
->data
);
283 for (ll
= l
->next
; ll
!= NULL
; ll
= lll
)
285 GInetAddress
*other_address
= G_INET_ADDRESS (ll
->data
);
287 if (g_inet_address_equal (address
, other_address
))
289 g_object_unref (other_address
);
290 /* we never return the first element */
291 g_warn_if_fail (g_list_delete_link (addrs
, ll
) == addrs
);
297 /* Note that this does not follow the "FALSE means @error is set"
298 * convention. The return value tells the caller whether it should
299 * return @addrs and @error to the caller right away, or if it should
300 * continue and trying to resolve the name as a hostname.
303 handle_ip_address (const char *hostname
,
310 struct in_addr ip4addr
;
313 addr
= g_inet_address_new_from_string (hostname
);
316 *addrs
= g_list_append (NULL
, addr
);
324 /* Reject IPv6 addresses that have brackets ('[' or ']') and/or port numbers,
325 * as no valid addresses should contain these at this point.
326 * Non-standard IPv4 addresses would be rejected during the call to
327 * getaddrinfo() later.
329 if (strrchr (hostname
, '[') != NULL
||
330 strrchr (hostname
, ']') != NULL
)
333 /* Reject non-standard IPv4 numbers-and-dots addresses.
334 * g_inet_address_new_from_string() will have accepted any "real" IP
335 * address, so if inet_aton() succeeds, then it's an address we want
338 if (inet_aton (hostname
, &ip4addr
))
341 g_set_error (error
, G_RESOLVER_ERROR
, G_RESOLVER_ERROR_NOT_FOUND
,
342 _("Error resolving “%s”: %s"),
343 hostname
, gai_strerror (EAI_NONAME
));
351 * g_resolver_lookup_by_name:
352 * @resolver: a #GResolver
353 * @hostname: the hostname to look up
354 * @cancellable: (nullable): a #GCancellable, or %NULL
355 * @error: return location for a #GError, or %NULL
357 * Synchronously resolves @hostname to determine its associated IP
358 * address(es). @hostname may be an ASCII-only or UTF-8 hostname, or
359 * the textual form of an IP address (in which case this just becomes
360 * a wrapper around g_inet_address_new_from_string()).
362 * On success, g_resolver_lookup_by_name() will return a non-empty #GList of
363 * #GInetAddress, sorted in order of preference and guaranteed to not
364 * contain duplicates. That is, if using the result to connect to
365 * @hostname, you should attempt to connect to the first address
366 * first, then the second if the first fails, etc. If you are using
367 * the result to listen on a socket, it is appropriate to add each
368 * result using e.g. g_socket_listener_add_address().
370 * If the DNS resolution fails, @error (if non-%NULL) will be set to a
371 * value from #GResolverError and %NULL will be returned.
373 * If @cancellable is non-%NULL, it can be used to cancel the
374 * operation, in which case @error (if non-%NULL) will be set to
375 * %G_IO_ERROR_CANCELLED.
377 * If you are planning to connect to a socket on the resolved IP
378 * address, it may be easier to create a #GNetworkAddress and use its
379 * #GSocketConnectable interface.
381 * Returns: (element-type GInetAddress) (transfer full): a non-empty #GList
382 * of #GInetAddress, or %NULL on error. You
383 * must unref each of the addresses and free the list when you are
384 * done with it. (You can use g_resolver_free_addresses() to do this.)
389 g_resolver_lookup_by_name (GResolver
*resolver
,
390 const gchar
*hostname
,
391 GCancellable
*cancellable
,
395 gchar
*ascii_hostname
= NULL
;
397 g_return_val_if_fail (G_IS_RESOLVER (resolver
), NULL
);
398 g_return_val_if_fail (hostname
!= NULL
, NULL
);
400 /* Check if @hostname is just an IP address */
401 if (handle_ip_address (hostname
, &addrs
, error
))
404 if (g_hostname_is_non_ascii (hostname
))
405 hostname
= ascii_hostname
= g_hostname_to_ascii (hostname
);
409 g_set_error_literal (error
, G_IO_ERROR
, G_IO_ERROR_FAILED
,
410 _("Invalid hostname"));
414 g_resolver_maybe_reload (resolver
);
415 addrs
= G_RESOLVER_GET_CLASS (resolver
)->
416 lookup_by_name (resolver
, hostname
, cancellable
, error
);
418 remove_duplicates (addrs
);
420 g_free (ascii_hostname
);
425 * g_resolver_lookup_by_name_async:
426 * @resolver: a #GResolver
427 * @hostname: the hostname to look up the address of
428 * @cancellable: (nullable): a #GCancellable, or %NULL
429 * @callback: (scope async): callback to call after resolution completes
430 * @user_data: (closure): data for @callback
432 * Begins asynchronously resolving @hostname to determine its
433 * associated IP address(es), and eventually calls @callback, which
434 * must call g_resolver_lookup_by_name_finish() to get the result.
435 * See g_resolver_lookup_by_name() for more details.
440 g_resolver_lookup_by_name_async (GResolver
*resolver
,
441 const gchar
*hostname
,
442 GCancellable
*cancellable
,
443 GAsyncReadyCallback callback
,
446 gchar
*ascii_hostname
= NULL
;
448 GError
*error
= NULL
;
450 g_return_if_fail (G_IS_RESOLVER (resolver
));
451 g_return_if_fail (hostname
!= NULL
);
453 /* Check if @hostname is just an IP address */
454 if (handle_ip_address (hostname
, &addrs
, &error
))
458 task
= g_task_new (resolver
, cancellable
, callback
, user_data
);
459 g_task_set_source_tag (task
, g_resolver_lookup_by_name_async
);
461 g_task_return_pointer (task
, addrs
, (GDestroyNotify
) g_resolver_free_addresses
);
463 g_task_return_error (task
, error
);
464 g_object_unref (task
);
468 if (g_hostname_is_non_ascii (hostname
))
469 hostname
= ascii_hostname
= g_hostname_to_ascii (hostname
);
475 g_set_error_literal (&error
, G_IO_ERROR
, G_IO_ERROR_FAILED
,
476 _("Invalid hostname"));
477 task
= g_task_new (resolver
, cancellable
, callback
, user_data
);
478 g_task_set_source_tag (task
, g_resolver_lookup_by_name_async
);
479 g_task_return_error (task
, error
);
480 g_object_unref (task
);
484 g_resolver_maybe_reload (resolver
);
485 G_RESOLVER_GET_CLASS (resolver
)->
486 lookup_by_name_async (resolver
, hostname
, cancellable
, callback
, user_data
);
488 g_free (ascii_hostname
);
492 * g_resolver_lookup_by_name_finish:
493 * @resolver: a #GResolver
494 * @result: the result passed to your #GAsyncReadyCallback
495 * @error: return location for a #GError, or %NULL
497 * Retrieves the result of a call to
498 * g_resolver_lookup_by_name_async().
500 * If the DNS resolution failed, @error (if non-%NULL) will be set to
501 * a value from #GResolverError. If the operation was cancelled,
502 * @error will be set to %G_IO_ERROR_CANCELLED.
504 * Returns: (element-type GInetAddress) (transfer full): a #GList
505 * of #GInetAddress, or %NULL on error. See g_resolver_lookup_by_name()
511 g_resolver_lookup_by_name_finish (GResolver
*resolver
,
512 GAsyncResult
*result
,
517 g_return_val_if_fail (G_IS_RESOLVER (resolver
), NULL
);
519 if (g_async_result_legacy_propagate_error (result
, error
))
521 else if (g_async_result_is_tagged (result
, g_resolver_lookup_by_name_async
))
523 /* Handle the stringified-IP-addr case */
524 return g_task_propagate_pointer (G_TASK (result
), error
);
527 addrs
= G_RESOLVER_GET_CLASS (resolver
)->
528 lookup_by_name_finish (resolver
, result
, error
);
530 remove_duplicates (addrs
);
536 * g_resolver_free_addresses: (skip)
537 * @addresses: a #GList of #GInetAddress
539 * Frees @addresses (which should be the return value from
540 * g_resolver_lookup_by_name() or g_resolver_lookup_by_name_finish()).
541 * (This is a convenience method; you can also simply free the results
547 g_resolver_free_addresses (GList
*addresses
)
551 for (a
= addresses
; a
; a
= a
->next
)
552 g_object_unref (a
->data
);
553 g_list_free (addresses
);
557 * g_resolver_lookup_by_address:
558 * @resolver: a #GResolver
559 * @address: the address to reverse-resolve
560 * @cancellable: (nullable): a #GCancellable, or %NULL
561 * @error: return location for a #GError, or %NULL
563 * Synchronously reverse-resolves @address to determine its
564 * associated hostname.
566 * If the DNS resolution fails, @error (if non-%NULL) will be set to
567 * a value from #GResolverError.
569 * If @cancellable is non-%NULL, it can be used to cancel the
570 * operation, in which case @error (if non-%NULL) will be set to
571 * %G_IO_ERROR_CANCELLED.
573 * Returns: a hostname (either ASCII-only, or in ASCII-encoded
574 * form), or %NULL on error.
579 g_resolver_lookup_by_address (GResolver
*resolver
,
580 GInetAddress
*address
,
581 GCancellable
*cancellable
,
584 g_return_val_if_fail (G_IS_RESOLVER (resolver
), NULL
);
585 g_return_val_if_fail (G_IS_INET_ADDRESS (address
), NULL
);
587 g_resolver_maybe_reload (resolver
);
588 return G_RESOLVER_GET_CLASS (resolver
)->
589 lookup_by_address (resolver
, address
, cancellable
, error
);
593 * g_resolver_lookup_by_address_async:
594 * @resolver: a #GResolver
595 * @address: the address to reverse-resolve
596 * @cancellable: (nullable): a #GCancellable, or %NULL
597 * @callback: (scope async): callback to call after resolution completes
598 * @user_data: (closure): data for @callback
600 * Begins asynchronously reverse-resolving @address to determine its
601 * associated hostname, and eventually calls @callback, which must
602 * call g_resolver_lookup_by_address_finish() to get the final result.
607 g_resolver_lookup_by_address_async (GResolver
*resolver
,
608 GInetAddress
*address
,
609 GCancellable
*cancellable
,
610 GAsyncReadyCallback callback
,
613 g_return_if_fail (G_IS_RESOLVER (resolver
));
614 g_return_if_fail (G_IS_INET_ADDRESS (address
));
616 g_resolver_maybe_reload (resolver
);
617 G_RESOLVER_GET_CLASS (resolver
)->
618 lookup_by_address_async (resolver
, address
, cancellable
, callback
, user_data
);
622 * g_resolver_lookup_by_address_finish:
623 * @resolver: a #GResolver
624 * @result: the result passed to your #GAsyncReadyCallback
625 * @error: return location for a #GError, or %NULL
627 * Retrieves the result of a previous call to
628 * g_resolver_lookup_by_address_async().
630 * If the DNS resolution failed, @error (if non-%NULL) will be set to
631 * a value from #GResolverError. If the operation was cancelled,
632 * @error will be set to %G_IO_ERROR_CANCELLED.
634 * Returns: a hostname (either ASCII-only, or in ASCII-encoded
635 * form), or %NULL on error.
640 g_resolver_lookup_by_address_finish (GResolver
*resolver
,
641 GAsyncResult
*result
,
644 g_return_val_if_fail (G_IS_RESOLVER (resolver
), NULL
);
646 if (g_async_result_legacy_propagate_error (result
, error
))
649 return G_RESOLVER_GET_CLASS (resolver
)->
650 lookup_by_address_finish (resolver
, result
, error
);
654 g_resolver_get_service_rrname (const char *service
,
655 const char *protocol
,
658 gchar
*rrname
, *ascii_domain
= NULL
;
660 if (g_hostname_is_non_ascii (domain
))
661 domain
= ascii_domain
= g_hostname_to_ascii (domain
);
665 rrname
= g_strdup_printf ("_%s._%s.%s", service
, protocol
, domain
);
667 g_free (ascii_domain
);
672 * g_resolver_lookup_service:
673 * @resolver: a #GResolver
674 * @service: the service type to look up (eg, "ldap")
675 * @protocol: the networking protocol to use for @service (eg, "tcp")
676 * @domain: the DNS domain to look up the service in
677 * @cancellable: (nullable): a #GCancellable, or %NULL
678 * @error: return location for a #GError, or %NULL
680 * Synchronously performs a DNS SRV lookup for the given @service and
681 * @protocol in the given @domain and returns an array of #GSrvTarget.
682 * @domain may be an ASCII-only or UTF-8 hostname. Note also that the
683 * @service and @protocol arguments do not include the leading underscore
684 * that appears in the actual DNS entry.
686 * On success, g_resolver_lookup_service() will return a non-empty #GList of
687 * #GSrvTarget, sorted in order of preference. (That is, you should
688 * attempt to connect to the first target first, then the second if
689 * the first fails, etc.)
691 * If the DNS resolution fails, @error (if non-%NULL) will be set to
692 * a value from #GResolverError and %NULL will be returned.
694 * If @cancellable is non-%NULL, it can be used to cancel the
695 * operation, in which case @error (if non-%NULL) will be set to
696 * %G_IO_ERROR_CANCELLED.
698 * If you are planning to connect to the service, it is usually easier
699 * to create a #GNetworkService and use its #GSocketConnectable
702 * Returns: (element-type GSrvTarget) (transfer full): a non-empty #GList of
703 * #GSrvTarget, or %NULL on error. You must free each of the targets and the
704 * list when you are done with it. (You can use g_resolver_free_targets() to do
710 g_resolver_lookup_service (GResolver
*resolver
,
711 const gchar
*service
,
712 const gchar
*protocol
,
714 GCancellable
*cancellable
,
720 g_return_val_if_fail (G_IS_RESOLVER (resolver
), NULL
);
721 g_return_val_if_fail (service
!= NULL
, NULL
);
722 g_return_val_if_fail (protocol
!= NULL
, NULL
);
723 g_return_val_if_fail (domain
!= NULL
, NULL
);
725 rrname
= g_resolver_get_service_rrname (service
, protocol
, domain
);
728 g_set_error_literal (error
, G_IO_ERROR
, G_IO_ERROR_FAILED
,
729 _("Invalid domain"));
733 g_resolver_maybe_reload (resolver
);
734 targets
= G_RESOLVER_GET_CLASS (resolver
)->
735 lookup_service (resolver
, rrname
, cancellable
, error
);
742 * g_resolver_lookup_service_async:
743 * @resolver: a #GResolver
744 * @service: the service type to look up (eg, "ldap")
745 * @protocol: the networking protocol to use for @service (eg, "tcp")
746 * @domain: the DNS domain to look up the service in
747 * @cancellable: (nullable): a #GCancellable, or %NULL
748 * @callback: (scope async): callback to call after resolution completes
749 * @user_data: (closure): data for @callback
751 * Begins asynchronously performing a DNS SRV lookup for the given
752 * @service and @protocol in the given @domain, and eventually calls
753 * @callback, which must call g_resolver_lookup_service_finish() to
754 * get the final result. See g_resolver_lookup_service() for more
760 g_resolver_lookup_service_async (GResolver
*resolver
,
761 const gchar
*service
,
762 const gchar
*protocol
,
764 GCancellable
*cancellable
,
765 GAsyncReadyCallback callback
,
770 g_return_if_fail (G_IS_RESOLVER (resolver
));
771 g_return_if_fail (service
!= NULL
);
772 g_return_if_fail (protocol
!= NULL
);
773 g_return_if_fail (domain
!= NULL
);
775 rrname
= g_resolver_get_service_rrname (service
, protocol
, domain
);
778 g_task_report_new_error (resolver
, callback
, user_data
,
779 g_resolver_lookup_service_async
,
780 G_IO_ERROR
, G_IO_ERROR_FAILED
,
781 _("Invalid domain"));
785 g_resolver_maybe_reload (resolver
);
786 G_RESOLVER_GET_CLASS (resolver
)->
787 lookup_service_async (resolver
, rrname
, cancellable
, callback
, user_data
);
793 * g_resolver_lookup_service_finish:
794 * @resolver: a #GResolver
795 * @result: the result passed to your #GAsyncReadyCallback
796 * @error: return location for a #GError, or %NULL
798 * Retrieves the result of a previous call to
799 * g_resolver_lookup_service_async().
801 * If the DNS resolution failed, @error (if non-%NULL) will be set to
802 * a value from #GResolverError. If the operation was cancelled,
803 * @error will be set to %G_IO_ERROR_CANCELLED.
805 * Returns: (element-type GSrvTarget) (transfer full): a non-empty #GList of
806 * #GSrvTarget, or %NULL on error. See g_resolver_lookup_service() for more
812 g_resolver_lookup_service_finish (GResolver
*resolver
,
813 GAsyncResult
*result
,
816 g_return_val_if_fail (G_IS_RESOLVER (resolver
), NULL
);
818 if (g_async_result_legacy_propagate_error (result
, error
))
821 return G_RESOLVER_GET_CLASS (resolver
)->
822 lookup_service_finish (resolver
, result
, error
);
826 * g_resolver_free_targets: (skip)
827 * @targets: a #GList of #GSrvTarget
829 * Frees @targets (which should be the return value from
830 * g_resolver_lookup_service() or g_resolver_lookup_service_finish()).
831 * (This is a convenience method; you can also simply free the
837 g_resolver_free_targets (GList
*targets
)
841 for (t
= targets
; t
; t
= t
->next
)
842 g_srv_target_free (t
->data
);
843 g_list_free (targets
);
847 * g_resolver_lookup_records:
848 * @resolver: a #GResolver
849 * @rrname: the DNS name to lookup the record for
850 * @record_type: the type of DNS record to lookup
851 * @cancellable: (nullable): a #GCancellable, or %NULL
852 * @error: return location for a #GError, or %NULL
854 * Synchronously performs a DNS record lookup for the given @rrname and returns
855 * a list of records as #GVariant tuples. See #GResolverRecordType for
856 * information on what the records contain for each @record_type.
858 * If the DNS resolution fails, @error (if non-%NULL) will be set to
859 * a value from #GResolverError and %NULL will be returned.
861 * If @cancellable is non-%NULL, it can be used to cancel the
862 * operation, in which case @error (if non-%NULL) will be set to
863 * %G_IO_ERROR_CANCELLED.
865 * Returns: (element-type GVariant) (transfer full): a non-empty #GList of
866 * #GVariant, or %NULL on error. You must free each of the records and the list
867 * when you are done with it. (You can use g_list_free_full() with
868 * g_variant_unref() to do this.)
873 g_resolver_lookup_records (GResolver
*resolver
,
875 GResolverRecordType record_type
,
876 GCancellable
*cancellable
,
881 g_return_val_if_fail (G_IS_RESOLVER (resolver
), NULL
);
882 g_return_val_if_fail (rrname
!= NULL
, NULL
);
884 g_resolver_maybe_reload (resolver
);
885 records
= G_RESOLVER_GET_CLASS (resolver
)->
886 lookup_records (resolver
, rrname
, record_type
, cancellable
, error
);
892 * g_resolver_lookup_records_async:
893 * @resolver: a #GResolver
894 * @rrname: the DNS name to lookup the record for
895 * @record_type: the type of DNS record to lookup
896 * @cancellable: (nullable): a #GCancellable, or %NULL
897 * @callback: (scope async): callback to call after resolution completes
898 * @user_data: (closure): data for @callback
900 * Begins asynchronously performing a DNS lookup for the given
901 * @rrname, and eventually calls @callback, which must call
902 * g_resolver_lookup_records_finish() to get the final result. See
903 * g_resolver_lookup_records() for more details.
908 g_resolver_lookup_records_async (GResolver
*resolver
,
910 GResolverRecordType record_type
,
911 GCancellable
*cancellable
,
912 GAsyncReadyCallback callback
,
915 g_return_if_fail (G_IS_RESOLVER (resolver
));
916 g_return_if_fail (rrname
!= NULL
);
918 g_resolver_maybe_reload (resolver
);
919 G_RESOLVER_GET_CLASS (resolver
)->
920 lookup_records_async (resolver
, rrname
, record_type
, cancellable
, callback
, user_data
);
924 * g_resolver_lookup_records_finish:
925 * @resolver: a #GResolver
926 * @result: the result passed to your #GAsyncReadyCallback
927 * @error: return location for a #GError, or %NULL
929 * Retrieves the result of a previous call to
930 * g_resolver_lookup_records_async(). Returns a non-empty list of records as
931 * #GVariant tuples. See #GResolverRecordType for information on what the
934 * If the DNS resolution failed, @error (if non-%NULL) will be set to
935 * a value from #GResolverError. If the operation was cancelled,
936 * @error will be set to %G_IO_ERROR_CANCELLED.
938 * Returns: (element-type GVariant) (transfer full): a non-empty #GList of
939 * #GVariant, or %NULL on error. You must free each of the records and the list
940 * when you are done with it. (You can use g_list_free_full() with
941 * g_variant_unref() to do this.)
946 g_resolver_lookup_records_finish (GResolver
*resolver
,
947 GAsyncResult
*result
,
950 g_return_val_if_fail (G_IS_RESOLVER (resolver
), NULL
);
951 return G_RESOLVER_GET_CLASS (resolver
)->
952 lookup_records_finish (resolver
, result
, error
);
956 g_resolver_get_serial (GResolver
*resolver
)
958 g_return_val_if_fail (G_IS_RESOLVER (resolver
), 0);
960 g_resolver_maybe_reload (resolver
);
963 return (guint64
) resolver
->priv
->resolv_conf_timestamp
;
970 * g_resolver_error_quark:
972 * Gets the #GResolver Error Quark.
974 * Returns: a #GQuark.
978 G_DEFINE_QUARK (g
-resolver
-error
-quark
, g_resolver_error
)