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 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/>.
28 #include "gthreadedresolver.h"
29 #include "gnetworkingprivate.h"
31 #include "gcancellable.h"
32 #include "ginetaddress.h"
33 #include "ginetsocketaddress.h"
35 #include "gsocketaddress.h"
36 #include "gsrvtarget.h"
39 G_DEFINE_TYPE (GThreadedResolver
, g_threaded_resolver
, G_TYPE_RESOLVER
)
42 g_threaded_resolver_init (GThreadedResolver
*gtr
)
47 g_resolver_error_from_addrinfo_error (gint err
)
52 #if defined(EAI_NODATA) && (EAI_NODATA != EAI_NONAME)
56 return G_RESOLVER_ERROR_NOT_FOUND
;
59 return G_RESOLVER_ERROR_TEMPORARY_FAILURE
;
62 return G_RESOLVER_ERROR_INTERNAL
;
66 static struct addrinfo addrinfo_hints
;
69 do_lookup_by_name (GTask
*task
,
70 gpointer source_object
,
72 GCancellable
*cancellable
)
74 const char *hostname
= task_data
;
75 struct addrinfo
*res
= NULL
;
79 retval
= getaddrinfo (hostname
, NULL
, &addrinfo_hints
, &res
);
84 GSocketAddress
*sockaddr
;
88 for (ai
= res
; ai
; ai
= ai
->ai_next
)
90 sockaddr
= g_socket_address_new_from_native (ai
->ai_addr
, ai
->ai_addrlen
);
93 if (!G_IS_INET_SOCKET_ADDRESS (sockaddr
))
95 g_clear_object (&sockaddr
);
99 addr
= g_object_ref (g_inet_socket_address_get_address ((GInetSocketAddress
*)sockaddr
));
100 addresses
= g_list_prepend (addresses
, addr
);
101 g_object_unref (sockaddr
);
104 if (addresses
!= NULL
)
106 addresses
= g_list_reverse (addresses
);
107 g_task_return_pointer (task
, addresses
,
108 (GDestroyNotify
)g_resolver_free_addresses
);
112 /* All addresses failed to be converted to GSocketAddresses. */
113 g_task_return_new_error (task
,
115 G_RESOLVER_ERROR_NOT_FOUND
,
116 _("Error resolving “%s”: %s"),
118 _("No valid addresses were found"));
123 g_task_return_new_error (task
,
125 g_resolver_error_from_addrinfo_error (retval
),
126 _("Error resolving “%s”: %s"),
127 hostname
, gai_strerror (retval
));
135 lookup_by_name (GResolver
*resolver
,
136 const gchar
*hostname
,
137 GCancellable
*cancellable
,
143 task
= g_task_new (resolver
, cancellable
, NULL
, NULL
);
144 g_task_set_source_tag (task
, lookup_by_name
);
145 g_task_set_task_data (task
, g_strdup (hostname
), g_free
);
146 g_task_set_return_on_cancel (task
, TRUE
);
147 g_task_run_in_thread_sync (task
, do_lookup_by_name
);
148 addresses
= g_task_propagate_pointer (task
, error
);
149 g_object_unref (task
);
155 lookup_by_name_async (GResolver
*resolver
,
156 const gchar
*hostname
,
157 GCancellable
*cancellable
,
158 GAsyncReadyCallback callback
,
163 task
= g_task_new (resolver
, cancellable
, callback
, user_data
);
164 g_task_set_source_tag (task
, lookup_by_name_async
);
165 g_task_set_task_data (task
, g_strdup (hostname
), g_free
);
166 g_task_set_return_on_cancel (task
, TRUE
);
167 g_task_run_in_thread (task
, do_lookup_by_name
);
168 g_object_unref (task
);
172 lookup_by_name_finish (GResolver
*resolver
,
173 GAsyncResult
*result
,
176 g_return_val_if_fail (g_task_is_valid (result
, resolver
), NULL
);
178 return g_task_propagate_pointer (G_TASK (result
), error
);
183 do_lookup_by_address (GTask
*task
,
184 gpointer source_object
,
186 GCancellable
*cancellable
)
188 GInetAddress
*address
= task_data
;
189 struct sockaddr_storage sockaddr
;
191 GSocketAddress
*gsockaddr
;
192 gchar name
[NI_MAXHOST
];
195 gsockaddr
= g_inet_socket_address_new (address
, 0);
196 g_socket_address_to_native (gsockaddr
, (struct sockaddr
*)&sockaddr
,
197 sizeof (sockaddr
), NULL
);
198 sockaddr_size
= g_socket_address_get_native_size (gsockaddr
);
199 g_object_unref (gsockaddr
);
201 retval
= getnameinfo ((struct sockaddr
*)&sockaddr
, sockaddr_size
,
202 name
, sizeof (name
), NULL
, 0, NI_NAMEREQD
);
204 g_task_return_pointer (task
, g_strdup (name
), g_free
);
209 phys
= g_inet_address_to_string (address
);
210 g_task_return_new_error (task
,
212 g_resolver_error_from_addrinfo_error (retval
),
213 _("Error reverse-resolving “%s”: %s"),
214 phys
? phys
: "(unknown)",
215 gai_strerror (retval
));
221 lookup_by_address (GResolver
*resolver
,
222 GInetAddress
*address
,
223 GCancellable
*cancellable
,
229 task
= g_task_new (resolver
, cancellable
, NULL
, NULL
);
230 g_task_set_source_tag (task
, lookup_by_address
);
231 g_task_set_task_data (task
, g_object_ref (address
), g_object_unref
);
232 g_task_set_return_on_cancel (task
, TRUE
);
233 g_task_run_in_thread_sync (task
, do_lookup_by_address
);
234 name
= g_task_propagate_pointer (task
, error
);
235 g_object_unref (task
);
241 lookup_by_address_async (GResolver
*resolver
,
242 GInetAddress
*address
,
243 GCancellable
*cancellable
,
244 GAsyncReadyCallback callback
,
249 task
= g_task_new (resolver
, cancellable
, callback
, user_data
);
250 g_task_set_source_tag (task
, lookup_by_address_async
);
251 g_task_set_task_data (task
, g_object_ref (address
), g_object_unref
);
252 g_task_set_return_on_cancel (task
, TRUE
);
253 g_task_run_in_thread (task
, do_lookup_by_address
);
254 g_object_unref (task
);
258 lookup_by_address_finish (GResolver
*resolver
,
259 GAsyncResult
*result
,
262 g_return_val_if_fail (g_task_is_valid (result
, resolver
), NULL
);
264 return g_task_propagate_pointer (G_TASK (result
), error
);
268 #if defined(G_OS_UNIX)
270 #if defined __BIONIC__ && !defined BIND_4_COMPAT
271 /* Copy from bionic/libc/private/arpa_nameser_compat.h
272 * and bionic/libc/private/arpa_nameser.h */
274 unsigned id
:16; /* query identification number */
275 #if BYTE_ORDER == BIG_ENDIAN
276 /* fields in third byte */
277 unsigned qr
: 1; /* response flag */
278 unsigned opcode
: 4; /* purpose of message */
279 unsigned aa
: 1; /* authoritive answer */
280 unsigned tc
: 1; /* truncated message */
281 unsigned rd
: 1; /* recursion desired */
282 /* fields in fourth byte */
283 unsigned ra
: 1; /* recursion available */
284 unsigned unused
:1; /* unused bits (MBZ as of 4.9.3a3) */
285 unsigned ad
: 1; /* authentic data from named */
286 unsigned cd
: 1; /* checking disabled by resolver */
287 unsigned rcode
:4; /* response code */
289 #if BYTE_ORDER == LITTLE_ENDIAN || BYTE_ORDER == PDP_ENDIAN
290 /* fields in third byte */
291 unsigned rd
:1; /* recursion desired */
292 unsigned tc
:1; /* truncated message */
293 unsigned aa
:1; /* authoritive answer */
294 unsigned opcode
:4; /* purpose of message */
295 unsigned qr
:1; /* response flag */
296 /* fields in fourth byte */
297 unsigned rcode
:4; /* response code */
298 unsigned cd
: 1; /* checking disabled by resolver */
299 unsigned ad
: 1; /* authentic data from named */
300 unsigned unused
:1; /* unused bits (MBZ as of 4.9.3a3) */
301 unsigned ra
:1; /* recursion available */
303 /* remaining bytes */
304 unsigned qdcount
:16; /* number of question entries */
305 unsigned ancount
:16; /* number of answer entries */
306 unsigned nscount
:16; /* number of authority entries */
307 unsigned arcount
:16; /* number of resource entries */
310 #define NS_INT32SZ 4 /* #/bytes of data in a uint32_t */
311 #define NS_INT16SZ 2 /* #/bytes of data in a uint16_t */
313 #define NS_GET16(s, cp) do { \
314 const u_char *t_cp = (const u_char *)(cp); \
315 (s) = ((uint16_t)t_cp[0] << 8) \
316 | ((uint16_t)t_cp[1]) \
318 (cp) += NS_INT16SZ; \
319 } while (/*CONSTCOND*/0)
321 #define NS_GET32(l, cp) do { \
322 const u_char *t_cp = (const u_char *)(cp); \
323 (l) = ((uint32_t)t_cp[0] << 24) \
324 | ((uint32_t)t_cp[1] << 16) \
325 | ((uint32_t)t_cp[2] << 8) \
326 | ((uint32_t)t_cp[3]) \
328 (cp) += NS_INT32SZ; \
329 } while (/*CONSTCOND*/0)
331 #define GETSHORT NS_GET16
332 #define GETLONG NS_GET32
336 /* From bionic/libc/private/resolv_private.h */
337 int dn_expand(const u_char
*, const u_char
*, const u_char
*, char *, int);
338 #define dn_skipname __dn_skipname
339 int dn_skipname(const u_char
*, const u_char
*);
341 /* From bionic/libc/private/arpa_nameser_compat.h */
343 #define T_TXT ns_t_txt
344 #define T_SOA ns_t_soa
347 /* From bionic/libc/private/arpa_nameser.h */
348 typedef enum __ns_type
{
349 ns_t_invalid
= 0, /* Cookie. */
350 ns_t_a
= 1, /* Host address. */
351 ns_t_ns
= 2, /* Authoritative server. */
352 ns_t_md
= 3, /* Mail destination. */
353 ns_t_mf
= 4, /* Mail forwarder. */
354 ns_t_cname
= 5, /* Canonical name. */
355 ns_t_soa
= 6, /* Start of authority zone. */
356 ns_t_mb
= 7, /* Mailbox domain name. */
357 ns_t_mg
= 8, /* Mail group member. */
358 ns_t_mr
= 9, /* Mail rename name. */
359 ns_t_null
= 10, /* Null resource record. */
360 ns_t_wks
= 11, /* Well known service. */
361 ns_t_ptr
= 12, /* Domain name pointer. */
362 ns_t_hinfo
= 13, /* Host information. */
363 ns_t_minfo
= 14, /* Mailbox information. */
364 ns_t_mx
= 15, /* Mail routing information. */
365 ns_t_txt
= 16, /* Text strings. */
366 ns_t_rp
= 17, /* Responsible person. */
367 ns_t_afsdb
= 18, /* AFS cell database. */
368 ns_t_x25
= 19, /* X_25 calling address. */
369 ns_t_isdn
= 20, /* ISDN calling address. */
370 ns_t_rt
= 21, /* Router. */
371 ns_t_nsap
= 22, /* NSAP address. */
372 ns_t_nsap_ptr
= 23, /* Reverse NSAP lookup (deprecated). */
373 ns_t_sig
= 24, /* Security signature. */
374 ns_t_key
= 25, /* Security key. */
375 ns_t_px
= 26, /* X.400 mail mapping. */
376 ns_t_gpos
= 27, /* Geographical position (withdrawn). */
377 ns_t_aaaa
= 28, /* Ip6 Address. */
378 ns_t_loc
= 29, /* Location Information. */
379 ns_t_nxt
= 30, /* Next domain (security). */
380 ns_t_eid
= 31, /* Endpoint identifier. */
381 ns_t_nimloc
= 32, /* Nimrod Locator. */
382 ns_t_srv
= 33, /* Server Selection. */
383 ns_t_atma
= 34, /* ATM Address */
384 ns_t_naptr
= 35, /* Naming Authority PoinTeR */
385 ns_t_kx
= 36, /* Key Exchange */
386 ns_t_cert
= 37, /* Certification record */
387 ns_t_a6
= 38, /* IPv6 address (deprecates AAAA) */
388 ns_t_dname
= 39, /* Non-terminal DNAME (for IPv6) */
389 ns_t_sink
= 40, /* Kitchen sink (experimentatl) */
390 ns_t_opt
= 41, /* EDNS0 option (meta-RR) */
391 ns_t_apl
= 42, /* Address prefix list (RFC 3123) */
392 ns_t_tkey
= 249, /* Transaction key */
393 ns_t_tsig
= 250, /* Transaction signature. */
394 ns_t_ixfr
= 251, /* Incremental zone transfer. */
395 ns_t_axfr
= 252, /* Transfer zone of authority. */
396 ns_t_mailb
= 253, /* Transfer mailbox records. */
397 ns_t_maila
= 254, /* Transfer mail agent records. */
398 ns_t_any
= 255, /* Wildcard match. */
399 ns_t_zxfr
= 256, /* BIND-specific, nonstandard. */
403 #endif /* __BIONIC__ */
406 parse_res_srv (guchar
*answer
,
411 guint16 priority
, weight
, port
;
413 GETSHORT (priority
, *p
);
414 GETSHORT (weight
, *p
);
416 *p
+= dn_expand (answer
, end
, *p
, namebuf
, sizeof (namebuf
));
418 return g_variant_new ("(qqqs)",
426 parse_res_soa (guchar
*answer
,
430 gchar mnamebuf
[1024];
431 gchar rnamebuf
[1024];
432 guint32 serial
, refresh
, retry
, expire
, ttl
;
434 *p
+= dn_expand (answer
, end
, *p
, mnamebuf
, sizeof (mnamebuf
));
435 *p
+= dn_expand (answer
, end
, *p
, rnamebuf
, sizeof (rnamebuf
));
437 GETLONG (serial
, *p
);
438 GETLONG (refresh
, *p
);
440 GETLONG (expire
, *p
);
443 return g_variant_new ("(ssuuuuu)",
454 parse_res_ns (guchar
*answer
,
460 *p
+= dn_expand (answer
, end
, *p
, namebuf
, sizeof (namebuf
));
462 return g_variant_new ("(s)", namebuf
);
466 parse_res_mx (guchar
*answer
,
473 GETSHORT (preference
, *p
);
475 *p
+= dn_expand (answer
, end
, *p
, namebuf
, sizeof (namebuf
));
477 return g_variant_new ("(qs)",
483 parse_res_txt (guchar
*answer
,
492 array
= g_ptr_array_new_with_free_func (g_free
);
498 g_ptr_array_add (array
, g_strndup ((gchar
*)at
, len
));
503 record
= g_variant_new ("(@as)",
504 g_variant_new_strv ((const gchar
**)array
->pdata
, array
->len
));
505 g_ptr_array_free (array
, TRUE
);
510 g_resolver_record_type_to_rrtype (GResolverRecordType type
)
514 case G_RESOLVER_RECORD_SRV
:
516 case G_RESOLVER_RECORD_TXT
:
518 case G_RESOLVER_RECORD_SOA
:
520 case G_RESOLVER_RECORD_NS
:
522 case G_RESOLVER_RECORD_MX
:
525 g_return_val_if_reached (-1);
529 g_resolver_records_from_res_query (const gchar
*rrname
,
539 guint16 type
, qclass
, rdlength
;
547 if (len
== 0 || herr
== HOST_NOT_FOUND
|| herr
== NO_DATA
)
549 g_set_error (error
, G_RESOLVER_ERROR
, G_RESOLVER_ERROR_NOT_FOUND
,
550 _("No DNS record of the requested type for “%s”"), rrname
);
552 else if (herr
== TRY_AGAIN
)
554 g_set_error (error
, G_RESOLVER_ERROR
, G_RESOLVER_ERROR_TEMPORARY_FAILURE
,
555 _("Temporarily unable to resolve “%s”"), rrname
);
559 g_set_error (error
, G_RESOLVER_ERROR
, G_RESOLVER_ERROR_INTERNAL
,
560 _("Error resolving “%s”"), rrname
);
568 header
= (HEADER
*)answer
;
569 p
= answer
+ sizeof (HEADER
);
573 count
= ntohs (header
->qdcount
);
574 while (count
-- && p
< end
)
576 p
+= dn_expand (answer
, end
, p
, namebuf
, sizeof (namebuf
));
579 /* To silence gcc warnings */
580 namebuf
[0] = namebuf
[1];
584 count
= ntohs (header
->ancount
);
585 while (count
-- && p
< end
)
587 p
+= dn_expand (answer
, end
, p
, namebuf
, sizeof (namebuf
));
589 GETSHORT (qclass
, p
);
591 ttl
= ttl
; /* To avoid -Wunused-but-set-variable */
592 GETSHORT (rdlength
, p
);
594 if (type
!= rrtype
|| qclass
!= C_IN
)
603 record
= parse_res_srv (answer
, end
, &p
);
606 record
= parse_res_mx (answer
, end
, &p
);
609 record
= parse_res_soa (answer
, end
, &p
);
612 record
= parse_res_ns (answer
, end
, &p
);
615 record
= parse_res_txt (answer
, p
+ rdlength
, &p
);
618 g_warn_if_reached ();
624 records
= g_list_prepend (records
, record
);
629 g_set_error (error
, G_RESOLVER_ERROR
, G_RESOLVER_ERROR_NOT_FOUND
,
630 _("No DNS record of the requested type for “%s”"), rrname
);
638 #elif defined(G_OS_WIN32)
641 parse_dns_srv (DNS_RECORD
*rec
)
643 return g_variant_new ("(qqqs)",
644 (guint16
)rec
->Data
.SRV
.wPriority
,
645 (guint16
)rec
->Data
.SRV
.wWeight
,
646 (guint16
)rec
->Data
.SRV
.wPort
,
647 rec
->Data
.SRV
.pNameTarget
);
651 parse_dns_soa (DNS_RECORD
*rec
)
653 return g_variant_new ("(ssuuuuu)",
654 rec
->Data
.SOA
.pNamePrimaryServer
,
655 rec
->Data
.SOA
.pNameAdministrator
,
656 (guint32
)rec
->Data
.SOA
.dwSerialNo
,
657 (guint32
)rec
->Data
.SOA
.dwRefresh
,
658 (guint32
)rec
->Data
.SOA
.dwRetry
,
659 (guint32
)rec
->Data
.SOA
.dwExpire
,
660 (guint32
)rec
->Data
.SOA
.dwDefaultTtl
);
664 parse_dns_ns (DNS_RECORD
*rec
)
666 return g_variant_new ("(s)", rec
->Data
.NS
.pNameHost
);
670 parse_dns_mx (DNS_RECORD
*rec
)
672 return g_variant_new ("(qs)",
673 (guint16
)rec
->Data
.MX
.wPreference
,
674 rec
->Data
.MX
.pNameExchange
);
678 parse_dns_txt (DNS_RECORD
*rec
)
684 array
= g_ptr_array_new ();
685 for (i
= 0; i
< rec
->Data
.TXT
.dwStringCount
; i
++)
686 g_ptr_array_add (array
, rec
->Data
.TXT
.pStringArray
[i
]);
687 record
= g_variant_new ("(@as)",
688 g_variant_new_strv ((const gchar
**)array
->pdata
, array
->len
));
689 g_ptr_array_free (array
, TRUE
);
694 g_resolver_record_type_to_dnstype (GResolverRecordType type
)
698 case G_RESOLVER_RECORD_SRV
:
700 case G_RESOLVER_RECORD_TXT
:
701 return DNS_TYPE_TEXT
;
702 case G_RESOLVER_RECORD_SOA
:
704 case G_RESOLVER_RECORD_NS
:
706 case G_RESOLVER_RECORD_MX
:
709 g_return_val_if_reached (-1);
713 g_resolver_records_from_DnsQuery (const gchar
*rrname
,
723 if (status
!= ERROR_SUCCESS
)
725 if (status
== DNS_ERROR_RCODE_NAME_ERROR
)
727 g_set_error (error
, G_RESOLVER_ERROR
, G_RESOLVER_ERROR_NOT_FOUND
,
728 _("No DNS record of the requested type for “%s”"), rrname
);
730 else if (status
== DNS_ERROR_RCODE_SERVER_FAILURE
)
732 g_set_error (error
, G_RESOLVER_ERROR
, G_RESOLVER_ERROR_TEMPORARY_FAILURE
,
733 _("Temporarily unable to resolve “%s”"), rrname
);
737 g_set_error (error
, G_RESOLVER_ERROR
, G_RESOLVER_ERROR_INTERNAL
,
738 _("Error resolving “%s”"), rrname
);
745 for (rec
= results
; rec
; rec
= rec
->pNext
)
747 if (rec
->wType
!= dnstype
)
752 record
= parse_dns_srv (rec
);
755 record
= parse_dns_soa (rec
);
758 record
= parse_dns_ns (rec
);
761 record
= parse_dns_mx (rec
);
764 record
= parse_dns_txt (rec
);
767 g_warn_if_reached ();
772 records
= g_list_prepend (records
, g_variant_ref_sink (record
));
777 g_set_error (error
, G_RESOLVER_ERROR
, G_RESOLVER_ERROR_NOT_FOUND
,
778 _("No DNS record of the requested type for “%s”"), rrname
);
790 GResolverRecordType record_type
;
794 free_lookup_records_data (LookupRecordsData
*lrd
)
796 g_free (lrd
->rrname
);
797 g_slice_free (LookupRecordsData
, lrd
);
801 free_records (GList
*records
)
803 g_list_free_full (records
, (GDestroyNotify
) g_variant_unref
);
806 #if defined(G_OS_UNIX)
809 int res_query(const char *, int, int, u_char
*, int);
814 do_lookup_records (GTask
*task
,
815 gpointer source_object
,
817 GCancellable
*cancellable
)
819 LookupRecordsData
*lrd
= task_data
;
821 GError
*error
= NULL
;
823 #if defined(G_OS_UNIX)
829 rrtype
= g_resolver_record_type_to_rrtype (lrd
->record_type
);
830 answer
= g_byte_array_new ();
833 g_byte_array_set_size (answer
, len
* 2);
834 len
= res_query (lrd
->rrname
, C_IN
, rrtype
, answer
->data
, answer
->len
);
836 /* If answer fit in the buffer then we're done */
837 if (len
< 0 || len
< (gint
)answer
->len
)
841 * On overflow some res_query's return the length needed, others
842 * return the full length entered. This code works in either case.
847 records
= g_resolver_records_from_res_query (lrd
->rrname
, rrtype
, answer
->data
, len
, herr
, &error
);
848 g_byte_array_free (answer
, TRUE
);
853 DNS_RECORD
*results
= NULL
;
856 dnstype
= g_resolver_record_type_to_dnstype (lrd
->record_type
);
857 status
= DnsQuery_A (lrd
->rrname
, dnstype
, DNS_QUERY_STANDARD
, NULL
, &results
, NULL
);
858 records
= g_resolver_records_from_DnsQuery (lrd
->rrname
, dnstype
, status
, results
, &error
);
860 DnsRecordListFree (results
, DnsFreeRecordList
);
865 g_task_return_pointer (task
, records
, (GDestroyNotify
) free_records
);
867 g_task_return_error (task
, error
);
871 lookup_records (GResolver
*resolver
,
873 GResolverRecordType record_type
,
874 GCancellable
*cancellable
,
879 LookupRecordsData
*lrd
;
881 task
= g_task_new (resolver
, cancellable
, NULL
, NULL
);
882 g_task_set_source_tag (task
, lookup_records
);
884 lrd
= g_slice_new (LookupRecordsData
);
885 lrd
->rrname
= g_strdup (rrname
);
886 lrd
->record_type
= record_type
;
887 g_task_set_task_data (task
, lrd
, (GDestroyNotify
) free_lookup_records_data
);
889 g_task_set_return_on_cancel (task
, TRUE
);
890 g_task_run_in_thread_sync (task
, do_lookup_records
);
891 records
= g_task_propagate_pointer (task
, error
);
892 g_object_unref (task
);
898 lookup_records_async (GResolver
*resolver
,
900 GResolverRecordType record_type
,
901 GCancellable
*cancellable
,
902 GAsyncReadyCallback callback
,
906 LookupRecordsData
*lrd
;
908 task
= g_task_new (resolver
, cancellable
, callback
, user_data
);
909 g_task_set_source_tag (task
, lookup_records_async
);
911 lrd
= g_slice_new (LookupRecordsData
);
912 lrd
->rrname
= g_strdup (rrname
);
913 lrd
->record_type
= record_type
;
914 g_task_set_task_data (task
, lrd
, (GDestroyNotify
) free_lookup_records_data
);
916 g_task_set_return_on_cancel (task
, TRUE
);
917 g_task_run_in_thread (task
, do_lookup_records
);
918 g_object_unref (task
);
922 lookup_records_finish (GResolver
*resolver
,
923 GAsyncResult
*result
,
926 g_return_val_if_fail (g_task_is_valid (result
, resolver
), NULL
);
928 return g_task_propagate_pointer (G_TASK (result
), error
);
933 g_threaded_resolver_class_init (GThreadedResolverClass
*threaded_class
)
935 GResolverClass
*resolver_class
= G_RESOLVER_CLASS (threaded_class
);
937 resolver_class
->lookup_by_name
= lookup_by_name
;
938 resolver_class
->lookup_by_name_async
= lookup_by_name_async
;
939 resolver_class
->lookup_by_name_finish
= lookup_by_name_finish
;
940 resolver_class
->lookup_by_address
= lookup_by_address
;
941 resolver_class
->lookup_by_address_async
= lookup_by_address_async
;
942 resolver_class
->lookup_by_address_finish
= lookup_by_address_finish
;
943 resolver_class
->lookup_records
= lookup_records
;
944 resolver_class
->lookup_records_async
= lookup_records_async
;
945 resolver_class
->lookup_records_finish
= lookup_records_finish
;
947 /* Initialize addrinfo_hints */
949 addrinfo_hints
.ai_flags
|= AI_ADDRCONFIG
;
951 /* These two don't actually matter, they just get copied into the
952 * returned addrinfo structures (and then we ignore them). But if
953 * we leave them unset, we'll get back duplicate answers.
955 addrinfo_hints
.ai_socktype
= SOCK_STREAM
;
956 addrinfo_hints
.ai_protocol
= IPPROTO_TCP
;