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/>.
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
;
546 if (len
== 0 || herr
== HOST_NOT_FOUND
|| herr
== NO_DATA
)
548 g_set_error (error
, G_RESOLVER_ERROR
, G_RESOLVER_ERROR_NOT_FOUND
,
549 _("No DNS record of the requested type for “%s”"), rrname
);
551 else if (herr
== TRY_AGAIN
)
553 g_set_error (error
, G_RESOLVER_ERROR
, G_RESOLVER_ERROR_TEMPORARY_FAILURE
,
554 _("Temporarily unable to resolve “%s”"), rrname
);
558 g_set_error (error
, G_RESOLVER_ERROR
, G_RESOLVER_ERROR_INTERNAL
,
559 _("Error resolving “%s”"), rrname
);
567 header
= (HEADER
*)answer
;
568 p
= answer
+ sizeof (HEADER
);
572 count
= ntohs (header
->qdcount
);
573 while (count
-- && p
< end
)
575 p
+= dn_expand (answer
, end
, p
, namebuf
, sizeof (namebuf
));
578 /* To silence gcc warnings */
579 namebuf
[0] = namebuf
[1];
583 count
= ntohs (header
->ancount
);
584 while (count
-- && p
< end
)
586 p
+= dn_expand (answer
, end
, p
, namebuf
, sizeof (namebuf
));
588 GETSHORT (qclass
, p
);
589 p
+= 4; /* ignore the ttl (type=long) value */
590 GETSHORT (rdlength
, p
);
592 if (type
!= rrtype
|| qclass
!= C_IN
)
601 record
= parse_res_srv (answer
, end
, &p
);
604 record
= parse_res_mx (answer
, end
, &p
);
607 record
= parse_res_soa (answer
, end
, &p
);
610 record
= parse_res_ns (answer
, end
, &p
);
613 record
= parse_res_txt (answer
, p
+ rdlength
, &p
);
616 g_warn_if_reached ();
622 records
= g_list_prepend (records
, record
);
627 g_set_error (error
, G_RESOLVER_ERROR
, G_RESOLVER_ERROR_NOT_FOUND
,
628 _("No DNS record of the requested type for “%s”"), rrname
);
636 #elif defined(G_OS_WIN32)
639 parse_dns_srv (DNS_RECORD
*rec
)
641 return g_variant_new ("(qqqs)",
642 (guint16
)rec
->Data
.SRV
.wPriority
,
643 (guint16
)rec
->Data
.SRV
.wWeight
,
644 (guint16
)rec
->Data
.SRV
.wPort
,
645 rec
->Data
.SRV
.pNameTarget
);
649 parse_dns_soa (DNS_RECORD
*rec
)
651 return g_variant_new ("(ssuuuuu)",
652 rec
->Data
.SOA
.pNamePrimaryServer
,
653 rec
->Data
.SOA
.pNameAdministrator
,
654 (guint32
)rec
->Data
.SOA
.dwSerialNo
,
655 (guint32
)rec
->Data
.SOA
.dwRefresh
,
656 (guint32
)rec
->Data
.SOA
.dwRetry
,
657 (guint32
)rec
->Data
.SOA
.dwExpire
,
658 (guint32
)rec
->Data
.SOA
.dwDefaultTtl
);
662 parse_dns_ns (DNS_RECORD
*rec
)
664 return g_variant_new ("(s)", rec
->Data
.NS
.pNameHost
);
668 parse_dns_mx (DNS_RECORD
*rec
)
670 return g_variant_new ("(qs)",
671 (guint16
)rec
->Data
.MX
.wPreference
,
672 rec
->Data
.MX
.pNameExchange
);
676 parse_dns_txt (DNS_RECORD
*rec
)
682 array
= g_ptr_array_new ();
683 for (i
= 0; i
< rec
->Data
.TXT
.dwStringCount
; i
++)
684 g_ptr_array_add (array
, rec
->Data
.TXT
.pStringArray
[i
]);
685 record
= g_variant_new ("(@as)",
686 g_variant_new_strv ((const gchar
**)array
->pdata
, array
->len
));
687 g_ptr_array_free (array
, TRUE
);
692 g_resolver_record_type_to_dnstype (GResolverRecordType type
)
696 case G_RESOLVER_RECORD_SRV
:
698 case G_RESOLVER_RECORD_TXT
:
699 return DNS_TYPE_TEXT
;
700 case G_RESOLVER_RECORD_SOA
:
702 case G_RESOLVER_RECORD_NS
:
704 case G_RESOLVER_RECORD_MX
:
707 g_return_val_if_reached (-1);
711 g_resolver_records_from_DnsQuery (const gchar
*rrname
,
721 if (status
!= ERROR_SUCCESS
)
723 if (status
== DNS_ERROR_RCODE_NAME_ERROR
)
725 g_set_error (error
, G_RESOLVER_ERROR
, G_RESOLVER_ERROR_NOT_FOUND
,
726 _("No DNS record of the requested type for “%s”"), rrname
);
728 else if (status
== DNS_ERROR_RCODE_SERVER_FAILURE
)
730 g_set_error (error
, G_RESOLVER_ERROR
, G_RESOLVER_ERROR_TEMPORARY_FAILURE
,
731 _("Temporarily unable to resolve “%s”"), rrname
);
735 g_set_error (error
, G_RESOLVER_ERROR
, G_RESOLVER_ERROR_INTERNAL
,
736 _("Error resolving “%s”"), rrname
);
743 for (rec
= results
; rec
; rec
= rec
->pNext
)
745 if (rec
->wType
!= dnstype
)
750 record
= parse_dns_srv (rec
);
753 record
= parse_dns_soa (rec
);
756 record
= parse_dns_ns (rec
);
759 record
= parse_dns_mx (rec
);
762 record
= parse_dns_txt (rec
);
765 g_warn_if_reached ();
770 records
= g_list_prepend (records
, g_variant_ref_sink (record
));
775 g_set_error (error
, G_RESOLVER_ERROR
, G_RESOLVER_ERROR_NOT_FOUND
,
776 _("No DNS record of the requested type for “%s”"), rrname
);
788 GResolverRecordType record_type
;
792 free_lookup_records_data (LookupRecordsData
*lrd
)
794 g_free (lrd
->rrname
);
795 g_slice_free (LookupRecordsData
, lrd
);
799 free_records (GList
*records
)
801 g_list_free_full (records
, (GDestroyNotify
) g_variant_unref
);
804 #if defined(G_OS_UNIX)
807 int res_query(const char *, int, int, u_char
*, int);
812 do_lookup_records (GTask
*task
,
813 gpointer source_object
,
815 GCancellable
*cancellable
)
817 LookupRecordsData
*lrd
= task_data
;
819 GError
*error
= NULL
;
821 #if defined(G_OS_UNIX)
827 rrtype
= g_resolver_record_type_to_rrtype (lrd
->record_type
);
828 answer
= g_byte_array_new ();
831 g_byte_array_set_size (answer
, len
* 2);
832 len
= res_query (lrd
->rrname
, C_IN
, rrtype
, answer
->data
, answer
->len
);
834 /* If answer fit in the buffer then we're done */
835 if (len
< 0 || len
< (gint
)answer
->len
)
839 * On overflow some res_query's return the length needed, others
840 * return the full length entered. This code works in either case.
845 records
= g_resolver_records_from_res_query (lrd
->rrname
, rrtype
, answer
->data
, len
, herr
, &error
);
846 g_byte_array_free (answer
, TRUE
);
851 DNS_RECORD
*results
= NULL
;
854 dnstype
= g_resolver_record_type_to_dnstype (lrd
->record_type
);
855 status
= DnsQuery_A (lrd
->rrname
, dnstype
, DNS_QUERY_STANDARD
, NULL
, &results
, NULL
);
856 records
= g_resolver_records_from_DnsQuery (lrd
->rrname
, dnstype
, status
, results
, &error
);
858 DnsRecordListFree (results
, DnsFreeRecordList
);
863 g_task_return_pointer (task
, records
, (GDestroyNotify
) free_records
);
865 g_task_return_error (task
, error
);
869 lookup_records (GResolver
*resolver
,
871 GResolverRecordType record_type
,
872 GCancellable
*cancellable
,
877 LookupRecordsData
*lrd
;
879 task
= g_task_new (resolver
, cancellable
, NULL
, NULL
);
880 g_task_set_source_tag (task
, lookup_records
);
882 lrd
= g_slice_new (LookupRecordsData
);
883 lrd
->rrname
= g_strdup (rrname
);
884 lrd
->record_type
= record_type
;
885 g_task_set_task_data (task
, lrd
, (GDestroyNotify
) free_lookup_records_data
);
887 g_task_set_return_on_cancel (task
, TRUE
);
888 g_task_run_in_thread_sync (task
, do_lookup_records
);
889 records
= g_task_propagate_pointer (task
, error
);
890 g_object_unref (task
);
896 lookup_records_async (GResolver
*resolver
,
898 GResolverRecordType record_type
,
899 GCancellable
*cancellable
,
900 GAsyncReadyCallback callback
,
904 LookupRecordsData
*lrd
;
906 task
= g_task_new (resolver
, cancellable
, callback
, user_data
);
907 g_task_set_source_tag (task
, lookup_records_async
);
909 lrd
= g_slice_new (LookupRecordsData
);
910 lrd
->rrname
= g_strdup (rrname
);
911 lrd
->record_type
= record_type
;
912 g_task_set_task_data (task
, lrd
, (GDestroyNotify
) free_lookup_records_data
);
914 g_task_set_return_on_cancel (task
, TRUE
);
915 g_task_run_in_thread (task
, do_lookup_records
);
916 g_object_unref (task
);
920 lookup_records_finish (GResolver
*resolver
,
921 GAsyncResult
*result
,
924 g_return_val_if_fail (g_task_is_valid (result
, resolver
), NULL
);
926 return g_task_propagate_pointer (G_TASK (result
), error
);
931 g_threaded_resolver_class_init (GThreadedResolverClass
*threaded_class
)
933 GResolverClass
*resolver_class
= G_RESOLVER_CLASS (threaded_class
);
935 resolver_class
->lookup_by_name
= lookup_by_name
;
936 resolver_class
->lookup_by_name_async
= lookup_by_name_async
;
937 resolver_class
->lookup_by_name_finish
= lookup_by_name_finish
;
938 resolver_class
->lookup_by_address
= lookup_by_address
;
939 resolver_class
->lookup_by_address_async
= lookup_by_address_async
;
940 resolver_class
->lookup_by_address_finish
= lookup_by_address_finish
;
941 resolver_class
->lookup_records
= lookup_records
;
942 resolver_class
->lookup_records_async
= lookup_records_async
;
943 resolver_class
->lookup_records_finish
= lookup_records_finish
;
945 /* Initialize addrinfo_hints */
947 addrinfo_hints
.ai_flags
|= AI_ADDRCONFIG
;
949 /* These two don't actually matter, they just get copied into the
950 * returned addrinfo structures (and then we ignore them). But if
951 * we leave them unset, we'll get back duplicate answers.
953 addrinfo_hints
.ai_socktype
= SOCK_STREAM
;
954 addrinfo_hints
.ai_protocol
= IPPROTO_TCP
;