ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent/lib/AnyEvent/DNS.pm
(Generate patch)

Comparing AnyEvent/lib/AnyEvent/DNS.pm (file contents):
Revision 1.74 by root, Thu Aug 21 18:45:16 2008 UTC vs.
Revision 1.93 by root, Mon Jun 22 11:57:05 2009 UTC

35 35
36use AnyEvent (); 36use AnyEvent ();
37use AnyEvent::Handle (); 37use AnyEvent::Handle ();
38use AnyEvent::Util qw(AF_INET6); 38use AnyEvent::Util qw(AF_INET6);
39 39
40our $VERSION = 4.232; 40our $VERSION = 4.411;
41 41
42our @DNS_FALLBACK = (v208.67.220.220, v208.67.222.222); 42our @DNS_FALLBACK = (v208.67.220.220, v208.67.222.222);
43 43
44=item AnyEvent::DNS::a $domain, $cb->(@addrs) 44=item AnyEvent::DNS::a $domain, $cb->(@addrs)
45 45
295C<$ENV{PERL_ANYEVENT_EDNS0}>, but when set to C<1>, AnyEvent::DNS will use 295C<$ENV{PERL_ANYEVENT_EDNS0}>, but when set to C<1>, AnyEvent::DNS will use
296EDNS0 in all requests. 296EDNS0 in all requests.
297 297
298=cut 298=cut
299 299
300our $EDNS0 = $ENV{PERL_ANYEVENT_EDNS0} * 1; # set to 1 to enable (partial) edns0 300our $EDNS0 = $ENV{PERL_ANYEVENT_EDNS0}*1; # set to 1 to enable (partial) edns0
301 301
302our %opcode_id = ( 302our %opcode_id = (
303 query => 0, 303 query => 0,
304 iquery => 1, 304 iquery => 1,
305 status => 2, 305 status => 2,
352 mx => 15, 352 mx => 15,
353 txt => 16, 353 txt => 16,
354 aaaa => 28, 354 aaaa => 28,
355 srv => 33, 355 srv => 33,
356 naptr => 35, # rfc2915 356 naptr => 35, # rfc2915
357 dname => 39, # rfc2672
357 opt => 41, 358 opt => 41,
358 spf => 99, 359 spf => 99,
359 tkey => 249, 360 tkey => 249,
360 tsig => 250, 361 tsig => 250,
361 ixfr => 251, 362 ixfr => 251,
511 # requires perl 5.10, sorry 512 # requires perl 5.10, sorry
512 my ($order, $preference, $flags, $service, $regexp, $offset) = unpack "nn C/a* C/a* C/a* .", $_; 513 my ($order, $preference, $flags, $service, $regexp, $offset) = unpack "nn C/a* C/a* C/a* .", $_;
513 local $ofs = $ofs + $offset - length; 514 local $ofs = $ofs + $offset - length;
514 ($order, $preference, $flags, $service, $regexp, _dec_name) 515 ($order, $preference, $flags, $service, $regexp, _dec_name)
515 }, 516 },
517 39 => sub { local $ofs = $ofs - length; _dec_name }, # dname
516 99 => sub { unpack "(C/a*)*", $_ }, # spf 518 99 => sub { unpack "(C/a*)*", $_ }, # spf
517); 519);
518 520
519sub _dec_rr { 521sub _dec_rr {
520 my $name = _dec_name; 522 my $name = _dec_name;
653 655
654our $RESOLVER; 656our $RESOLVER;
655 657
656sub resolver() { 658sub resolver() {
657 $RESOLVER || do { 659 $RESOLVER || do {
658 $RESOLVER = new AnyEvent::DNS; 660 $RESOLVER = new AnyEvent::DNS untaint => 1;
659 $RESOLVER->os_config; 661 $RESOLVER->os_config;
660 $RESOLVER 662 $RESOLVER
661 } 663 }
662} 664}
663 665
701=item reuse => $seconds 703=item reuse => $seconds
702 704
703The number of seconds (default: C<300>) that a query id cannot be re-used 705The number of seconds (default: C<300>) that a query id cannot be re-used
704after a timeout. If there was no time-out then query ids can be reused 706after a timeout. If there was no time-out then query ids can be reused
705immediately. 707immediately.
708
709=item untaint => $boolean
710
711When true, then the resolver will automatically untaint results, and might
712also ignore certain environment variables.
706 713
707=back 714=back
708 715
709=cut 716=cut
710 717
820 $self->_compile; 827 $self->_compile;
821} 828}
822 829
823=item $resolver->os_config 830=item $resolver->os_config
824 831
825Tries so load and parse F</etc/resolv.conf> on portable operating systems. Tries various 832Tries so load and parse F</etc/resolv.conf> on portable operating
826egregious hacks on windows to force the DNS servers and searchlist out of the system. 833systems. Tries various egregious hacks on windows to force the DNS servers
834and searchlist out of the system.
827 835
828=cut 836=cut
829 837
830sub os_config { 838sub os_config {
831 my ($self) = @_; 839 my ($self) = @_;
937} 945}
938 946
939sub _feed { 947sub _feed {
940 my ($self, $res) = @_; 948 my ($self, $res) = @_;
941 949
950 ($res) = $res =~ /^(.*)$/s
951 if AnyEvent::TAINT && $self->{untaint};
952
942 $res = dns_unpack $res 953 $res = dns_unpack $res
943 or return; 954 or return;
944 955
945 my $id = $self->{id}{$res->{id}}; 956 my $id = $self->{id}{$res->{id}};
946 957
1116 1127
1117 push @{ $self->{queue} }, [dns_pack $req, $cb]; 1128 push @{ $self->{queue} }, [dns_pack $req, $cb];
1118 $self->_scheduler; 1129 $self->_scheduler;
1119} 1130}
1120 1131
1121=item $resolver->resolve ($qname, $qtype, %options, $cb->($rcode, @rr)) 1132=item $resolver->resolve ($qname, $qtype, %options, $cb->(@rr))
1122 1133
1123Queries the DNS for the given domain name C<$qname> of type C<$qtype>. 1134Queries the DNS for the given domain name C<$qname> of type C<$qtype>.
1124 1135
1125A C<$qtype> is either a numerical query type (e.g. C<1> for A records) or 1136A C<$qtype> is either a numerical query type (e.g. C<1> for A records) or
1126a lowercase name (you have to look at the source to see which aliases are 1137a lowercase name (you have to look at the source to see which aliases are
1131The callback will be invoked with a list of matching result records or 1142The callback will be invoked with a list of matching result records or
1132none on any error or if the name could not be found. 1143none on any error or if the name could not be found.
1133 1144
1134CNAME chains (although illegal) are followed up to a length of 10. 1145CNAME chains (although illegal) are followed up to a length of 10.
1135 1146
1136The callback will be invoked with an result code in string form (noerror, 1147The callback will be invoked with arraryefs of the form C<[$name, $type,
1137formerr, servfail, nxdomain, notimp, refused and so on), or numerical 1148$class, @data>], where C<$name> is the domain name, C<$type> a type string
1138form if the result code is not supported. The remaining arguments are 1149or number, C<$class> a class name and @data is resource-record-dependent
1139arraryefs of the form C<[$name, $type, $class, @data>], where C<$name> is 1150data. For C<a> records, this will be the textual IPv4 addresses, for C<ns>
1140the domain name, C<$type> a type string or number, C<$class> a class name 1151or C<cname> records this will be a domain name, for C<txt> records these
1141and @data is resource-record-dependent data. For C<a> records, this will 1152are all the strings and so on.
1142be the textual IPv4 addresses, for C<ns> or C<cname> records this will be
1143a domain name, for C<txt> records these are all the strings and so on.
1144 1153
1145All types mentioned in RFC 1035, C<aaaa>, C<srv>, C<naptr> and C<spf> are 1154All types mentioned in RFC 1035, C<aaaa>, C<srv>, C<naptr> and C<spf> are
1146decoded. All resource records not known to this module will have 1155decoded. All resource records not known to this module will have
1147the raw C<rdata> field as fourth entry. 1156the raw C<rdata> field as fourth entry.
1148 1157

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines