blib/lib/Net/DNS/ToolKit/RR/TXT.pm

filter: Statementstmt 100% 44 / 44 Branchbran 70.0% 7 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 7 / 7 Podpod 0.0% 0 / 3 totaltotal 90.6% 58 / 64 CC 8 SCAR 11.1
CC
8
Cov
94%
put
5.1
parse
3.0
get
2.0
CRAP 3.0
« blib/lib/Net/DNS/ToolKit/RR.pm ↑ Summary blib/lib/Net/DNS/ToolKit/RR/NS.pm »
1 package Net::DNS::ToolKit::RR::TXT;
2  
3 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 #use warnings;
5 #use diagnostics;
6  
7 6 ▶use Net::DNS::ToolKit qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
8 get16
9 put16
10 get1char
11 put1char
12 dn_comp
13 dn_expand
14 putstring
15 getstring
16 6 );
17 6 ▶use Net::DNS::Codes qw(:constants);
Subroutine BEGIN: called CC=1 SCAR=0.0
18 6 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 6 $VERSION = do { my @r = (q$Revision: 0.03 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r };
21  
22 =head1 NAME
23  
24 Net::DNS::ToolKit::RR::TXT - Resource Record Handler
25  
26 =head1 SYNOPSIS
27  
28 DO NOT use Net::DNS::ToolKit::RR::TXT
29 DO NOT require Net::DNS::ToolKit::RR::TXT
30  
31 Net::DNS::ToolKit::RR::TXT is autoloaded by
32 class Net::DNS::ToolKit::RR and its methods
33 are instantiated in a 'special' manner.
34  
35 use Net::DNS::ToolKit::RR;
36 ($get,$put,$parse) = new Net::DNS::ToolKit::RR;
37  
38 ($newoff,$name,$type,$class,$ttl,$rdlength,
39 $textdata) = $get->TXT(\$buffer,$offset);
40  
41 Note: the $get->TXT method is normally called
42 via: @stuff = $get->next(\$buffer,$offset);
43  
44 ($newoff,@dnptrs)=$put->TXT(\$buffer,$offset,\@dnptrs,
45 $name,$type,$class,$ttl,$textdata,$textdata,$textdata,...);
46  
47 $NAME,$TYPE,$CLASS,$TTL,$rdlength,$textdata)
48 = $parse->TXT($name,$type,$class,$ttl,$rdlength,
49 $textdata);
50  
51 =head1 DESCRIPTION
52  
53 B<Net::DNS::ToolKit::RR:TXT> appends an TXT resource record to a DNS packet under
54 construction, recovers an TXT resource record from a packet being decoded, and
55 converts the numeric/binary portions of the resource record to human
56 readable form.
57  
58 Description from RFC1035.txt
59  
60 3.2.1. Format
61  
62 All RRs have the same top level format shown below:
63  
64 1 1 1 1 1 1
65 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
66 +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
67 | NAME |
68 +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
69 | TYPE |
70 +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
71 | CLASS |
72 +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
73 | TTL |
74 +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
75 | RDLENGTH |
76 +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--|
77 | RDATA |
78 +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
79  
80 NAME an owner name, i.e., the name of the node to which this
81 resource record pertains.
82  
83 TYPE two octets containing one of the RR TYPE codes.
84  
85 CLASS two octets containing one of the RR CLASS codes.
86  
87 TTL a 32 bit signed integer that specifies the time interval
88 that the resource record may be cached before the source
89 of the information should again be consulted. Zero
90 values are interpreted to mean that the RR can only be
91 used for the transaction in progress, and should not be
92 cached. For example, SOA records are always distributed
93 with a zero TTL to prohibit caching. Zero values can
94 also be used for extremely volatile data.
95  
96 RDLENGTH an unsigned 16 bit integer that specifies the length
97 in octets of the RDATA field.
98  
99 RDATA a variable length string of octets that describes the
100 resource. The format of this information varies
101 according to the TYPE and CLASS of the resource record.
102  
103 3.3.14. TXT RDATA format
104  
105 +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
106 / TXT-DATA /
107 +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
108  
109 where:
110  
111 TXT-DATA One or more <character-string>s.
112  
113 TXT RRs are used to hold descriptive text. The semantics of the text
114 depends on the domain where it is found.
115  
116 Note: Each character string consists of up to 255 characters.
117  
118 =over 4
119  
120 =item * @stuff = $get->TXT(\$buffer,$offset);
121  
122 Get the contents of the resource record.
123  
124 USE: @stuff = $get->next(\$buffer,$offset);
125  
126 where: @stuff = (
127 $newoff $name,$type,$class,$ttl,@textdata );
128  
129 All except the last item, B<$textdata>, is provided by
130 the class loader, B<Net::DNS::ToolKit::RR>. The code in this method knows
131 how to retrieve B<$textdata>.
132  
133 input: pointer to buffer,
134 offset into buffer
135 returns: offset to next resource,
136 @common RR elements,
137 text string(s)
138  
139 =cut
140  
141 4 ▶sub get {
Subroutine get: called CC=2 SCAR=6.9
Pod undocumented
142 4 my($self,$bp,$offset) = @_;
143 4 (my $rdend,$offset) = get16($bp,$offset); # get rdlength
144 4 $rdend += $offset; # end pointer
145 4 my @tdata;
146 4 ▶ while($offset < $rdend) {
Branch: 1 branch
BranchTrueFalseTotal
if ($offset < $rdend) 6 4 10
147 6 my $len = get1char($bp,$offset);
148 6 (my $string,$offset) = getstring($bp,$offset+1,$len);
149 6 push @tdata, $string;
150 }
151 4 return($offset,@tdata);
152 }
153  
154 =item * ($newoff,@dnptrs)=$put->TXT(\$buffer,$offset,\@dnptrs,
155 $name,$type,$class,$ttl,@textdata);
156  
157 Append a TXT record to $buffer.
158  
159 where @common = (
160 $name,$type,$class,$ttl);
161  
162 The method will insert the $rdlength and $textdata, then
163 pass through the updated pointer to the array of compressed names
164  
165 The class loader, B<Net::DNS::ToolKit::RR>, inserts the @common elements and
166 returns updated @dnptrs. This module knows how to insert its RDATA and
167 calculate the $rdlength.
168  
169 input: pointer to buffer,
170 offset (normally end of buffer),
171 pointer to compressed name array,
172 @common RR elements,
173 text string(s) =< 255 characters.
174 output: offset to next RR,
175 new compressed name pointer array,
176 or empty list () on error.
177  
178 Note: Double quotes embedded in the text
179 should be escaped. i.e. \"
180  
181 =cut
182  
183 7 ▶sub put {
Subroutine put: called CC=5 SCAR=16.3
Pod undocumented
184 7 ▶ return () unless @_; # always return on error
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 7 7
185 7 my($self,$bp,$off,$dnp,@textdata) = @_;
186 7 my $rdlp = $off; # save pointer to rdlength
187 7 my $doff;
188 7 ▶ return () unless # check for valid offset and get
Branch: 1 branch
BranchTrueFalseTotal
unless $off = $doff = put16($bp, $off, 0) 0 7 7
189 ($off = $doff = put16($bp,$off,0)); # offset to text string
190 7 foreach(0..$#textdata) {
191 9 $textdata[$_] =~ s/\\"/"/g; # unescape embedded quotes
192 9 my $len = length($textdata[$_]);
193 9 ▶ return () if $len > 255;
Branch: 1 branch
BranchTrueFalseTotal
if $len > 255 0 9 9
194 9 $off = put1char($bp,$off,$len);
195 9 $off = putstring($bp,$off,\$textdata[$_]);
196 }
197 # rdlength = new offset - previous offset
198 7 put16($bp,$rdlp, $off - $doff);
199 7 return($off,@$dnp);
200 }
201  
202 =item * (@COMMON,@textdata) = $parse->TXT(@common,@textdata);
203  
204 Converts binary/numeric field data into human readable form. The common RR
205 elements are supplied by the class loader, B<Net::DNS::ToolKit::RR>.
206 For TXT RR's, this returns the text strings, each surrounded by double quotes.
207  
208 input: text string(s)
209 returns: "text string(s)"
210  
211 =back
212  
213 =cut
214  
215 6 ▶sub parse {
Subroutine parse: called CC=3 SCAR=11.0
Pod undocumented
216 6 shift; # $self
217 6 my @ret;
218 6 foreach(@_) {
219 8 $_ =~ s/"/\\"/g; # escape embedded quotes
220 8 push @ret, '"'.$_.'"';
221 }
222 6 ▶ return wantarray ? @ret : $ret[0];
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 2 4 6
223 }
224  
225 =head1 DEPENDENCIES
226  
227 Net::DNS::ToolKit
228 Net::DNS::Codes
229  
230 =head1 EXPORT
231  
232 none
233  
234 =head1 AUTHOR
235  
236 Michael Robinton <michael@bizsystems.com>
237  
238 =head1 COPYRIGHT
239  
240 Copyright 2003 - 2011, Michael Robinton <michael@bizsystems.com>
241
242 Michael Robinton <michael@bizsystems.com>
243  
244 All rights reserved.
245  
246 This program is free software; you can redistribute it and/or modify
247 it under the terms of either:
248  
249 a) the GNU General Public License as published by the Free
250 Software Foundation; either version 2, or (at your option) any
251 later version, or
252  
253 b) the "Artistic License" which comes with this distribution.
254  
255 This program is distributed in the hope that it will be useful,
256 but WITHOUT ANY WARRANTY; without even the implied warranty of
257 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See either
258 the GNU General Public License or the Artistic License for more details.
259  
260 You should have received a copy of the Artistic License with this
261 distribution, in the file named "Artistic". If not, I'll be glad to provide
262 one.
263  
264 You should also have received a copy of the GNU General Public License
265 along with this program in the file named "Copying". If not, write to the
266  
267 Free Software Foundation, Inc.
268 59 Temple Place, Suite 330
269 Boston, MA 02111-1307, USA
270  
271 or visit their web page on the internet at:
272  
273 http://www.gnu.org/copyleft/gpl.html.
274  
275 =head1 See also:
276  
277 Net::DNS::Codes(3), Net::DNS::ToolKit(3)
278  
279 =cut
280  
281 6 1;
« blib/lib/Net/DNS/ToolKit/RR.pm ↑ Summary blib/lib/Net/DNS/ToolKit/RR/NS.pm »