ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/EV-ADNS/ADNS.pm
Revision: 1.15
Committed: Fri Oct 16 23:58:20 2015 UTC (8 years, 7 months ago) by root
Branch: MAIN
Changes since 1.14: +10 -2 lines
Log Message:
*** empty log message ***

File Contents

# Content
1 =head1 NAME
2
3 EV::ADNS - lightweight asynchronous dns queries using EV and libadns
4
5 =head1 SYNOPSIS
6
7 use EV;
8 use EV::ADNS;
9
10 EV::ADNS::submit "example.com", EV::ADNS::r_addr, EV::ADNS::qf_cname_loose, sub {
11 my ($status, $expires, @a) = @_;
12 warn $a[0]; # "127.13.166.3" etc.
13 };
14
15 EV::run;
16
17 =head1 DESCRIPTION
18
19 This is a simple interface to libadns (asynchronous dns) that
20 integrates well and automatically into the EV event loop. The
21 documentation for libadns is vital to understand this module, see
22 L<http://www.chiark.greenend.org.uk/~ian/adns/>.
23
24 You can use it only with EV (directly or indirectly, e.g. via
25 L<Glib::EV>). Apart from loading and using the C<submit> function you need
26 not do anything (except run an EV event loop).
27
28 =head1 OVERVIEW
29
30 All the constants/enums from F<adns.h> are available in the EV::ADNS
31 namespace, without the C<adns_> prefix, i.e. C<adns_r_a> becomes
32 C<EV::ADNS::r_a> and so on.
33
34 =head1 FUNCTIONS
35
36 =over 4
37
38 =item $query = EV::ADNS::submit "domain", $rrtype, $flags, $cb
39
40 Submits a new request to be handled. See the C<adns_submit> C function
41 description for more details. The function optionally returns a query
42 object which can be used to cancel an in-progress request. You do not need
43 to store the query object, even if you ignore it, the query will proceed.
44
45 The callback will be invoked with a result status, the time the resource
46 record validity expires and zero or more resource records, one scalar per
47 result record. Example:
48
49 sub adns_cb {
50 my ($status, $expires, @rr) = @_;
51 if ($status == EV::ADNS::s_ok) {
52 use JSON::XS;
53 warn encode_json \@rr;
54 }
55 }
56
57 The format of result records varies considerably, here is some cursory
58 documentation of how each record will look like, depending on the query
59 type:
60
61 =over 4
62
63 =item EV::ADNS::r_addr
64
65 IPv4 and/or IPV6 addresses in string form.
66
67 =item EV::ADNS::r_a
68
69 IPv4 addresses in dotted quad (string) form.
70
71 =item EV::ADNS::r_aaaa
72
73 IPv6 addresses in string form.
74
75 =item EV::ADNS::r_ns_raw, EV::ADNS::r_cname, EV::ADNS::r_ptr, EV::ADNS::r_ptr_raw
76
77 The resource record as a simple string.
78
79 =item EV::ADNS::r_txt
80
81 An arrayref of strings.
82
83 =item EV::ADNS::r_ns
84
85 A "host address", a hostname with any number of addresses (hint records).
86
87 The record will be an arrayref with domainname, adns status and any number
88 of associated addresses: C<< ["domain", adns_status, addr...] >>.
89
90 =item EV::ADNS::r_hinfo
91
92 An arrayref consisting of the two strings.
93
94 =item EV::ADNS::r_rp, EV::ADNS::r_rp_raw
95
96 An arrayref with two strings.
97
98 =item EV::ADNS::r_mx
99
100 An arrayref consisting of the priority and a "host address" (see
101 C<EV::ADNS::r_ns>). Example:
102
103 [10, [["alt3.aspmx.l.google.com", 0, "64.233.189.27", "2404:6800:4008:c07::1a"]]]
104
105 =item EV::ADNS::r_mx_raw
106
107 An arrayref consisting of the priority and the hostname, e.g. C<[10,
108 "mail.example.com"]>.
109
110 =item EV::ADNS::r_soa, EV::ADNS::r_soa_raw
111
112 An arrayref consisting of the primary nameserver, admin name, serial,
113 refresh, retry expire and minimum times, e.g.:
114
115 ["ns.example.net", "hostmaster@example.net", 2000001102, 86400, 21600, 2592000, 172800]
116
117 The "raw" form doesn't mangle the e-mail address.
118
119 =item EV::ADNS::r_srv_raw
120
121 An arrayref consisting of the priority, weight, port and hostname, e.g.:
122
123 [10, 10, 5060, "sip1.example.net"]
124
125 =item EV::ADNS::r_srv
126
127 The same as C<EV::ADNS::r_srv_raw>, but the hostname is replaced by a "host
128 address" (see C<EV::ADNS::r_ns>).
129
130 =item EV::ADNS::r_unknown
131
132 A single octet string with the raw contents.
133
134 =item anything else
135
136 Currently C<undef>.
137
138 =back
139
140 =item $query->cancel
141
142 Cancels a request that is in progress.
143
144 =item EV::ADNS::reinit undef, $resolvdata_or_undef
145
146 Cancels all outstanding queries, frees all adns state and reinitialises
147 it. It is highly recommended to only call this when there are no
148 outstanding requests.
149
150 The first argument must currently be specified as C<undef>.
151
152 The second argument can be missing or C<undef>; in which case the normal
153 initialisation is done (such as reading the F<resolv.conf>), or it might
154 be a stirng, in which case no config files or environment variables will
155 be read and the given string will be interpreted as the F<resolv.conf>
156 contents.
157
158 =back
159
160 =cut
161
162 package EV::ADNS;
163
164 use Carp ();
165 use EV ();
166
167 BEGIN {
168 $VERSION = '3.0';
169
170 require XSLoader;
171 XSLoader::load (EV::ADNS, $VERSION);
172 }
173
174 =head1 SEE ALSO
175
176 L<EV>, L<Net::ADNS> another interface to adns, maybe better, but without
177 real support to integrate it into other event loops.
178
179 =head1 AUTHOR
180
181 Marc Lehmann <schmorp@schmorp.de>
182 http://home.schmorp.de/
183
184 =cut
185
186 1
187