1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
|
package Net::DNS::RR::TXT;
#
# $Id: TXT.pm 582 2006-04-25 07:12:19Z olaf $
#
use strict;
BEGIN {
eval { require bytes; }
}
use vars qw(@ISA $VERSION);
use Text::ParseWords;
@ISA = qw(Net::DNS::RR);
$VERSION = (qw$LastChangedRevision: 582 $)[1];
sub new {
my ($class, $self, $data, $offset) = @_;
my $rdlength = $self->{'rdlength'} or return bless $self, $class;
my $end = $offset + $rdlength;
while ($offset < $end) {
my $strlen = unpack("\@$offset C", $$data);
++$offset;
my $char_str = substr($$data, $offset, $strlen);
$offset += $strlen;
push(@{$self->{'char_str_list'}}, $char_str);
}
return bless $self, $class;
}
sub new_from_string {
my ( $class, $self, $rdata_string ) = @_ ;
bless $self, $class;
$self->_build_char_str_list($rdata_string);
return $self;
}
sub txtdata {
my $self = shift;
return join(' ', $self->char_str_list());
}
sub rdatastr {
my $self = shift;
if ($self->char_str_list) {
return join(' ', map {
my $str = $_;
$str =~ s/"/\\"/g;
qq("$str");
} @{$self->{'char_str_list'}});
}
return '';
}
sub _build_char_str_list {
my ($self, $rdata_string) = @_;
my @words;
@words= shellwords($rdata_string) if $rdata_string;
$self->{'char_str_list'} = [];
if (@words) {
foreach my $string (@words) {
$string =~ s/\\"/"/g;
push(@{$self->{'char_str_list'}}, $string);
}
}
}
sub char_str_list {
my $self = shift;
if (not $self->{'char_str_list'}) {
$self->_build_char_str_list( $self->{'txtdata'} );
}
return @{$self->{'char_str_list'}}; # unquoted strings
}
sub rr_rdata {
my $self = shift;
my $rdata = '';
foreach my $string ($self->char_str_list) {
$rdata .= pack("C", length $string );
$rdata .= $string;
}
return $rdata;
}
1;
__END__
=head1 NAME
Net::DNS::RR::TXT - DNS TXT resource record
=head1 SYNOPSIS
C<use Net::DNS::RR>;
=head1 DESCRIPTION
Class for DNS Text (TXT) resource records.
=head1 METHODS
=head2 txtdata
print "txtdata = ", $rr->txtdata, "\n";
Returns the descriptive text as a single string, regardless of actual
number of <character-string> elements. Of questionable value. Should
be deprecated.
Use C<< $txt->rdatastr() >> or C<< $txt->char_str_list() >> instead.
=head2 char_str_list
print "Individual <character-string> list: \n\t",
join("\n\t", $rr->char_str_list());
Returns a list of the individual <character-string> elements,
as unquoted strings. Used by TXT->rdatastr and TXT->rr_rdata.
=head1 FEATURES
The RR.pm module accepts semi-colons as a start of a comment. This is
to allow the RR.pm to deal with RFC1035 specified zonefile format.
For some applications of the TXT RR the semicolon is relevant, you
will need to escape it on input.
Also note that you should specify the several character strings
separately. The easiest way to do so is to include the whole argument
in single quotes and the several character strings in double
quotes. Double quotes inside the character strings will need to be
escaped.
my $TXTrr=Net::DNS::RR->new('txt2.t.net-dns.org. 60 IN
TXT "Test1 \" \; more stuff" "Test2"');
would result in
$TXTrr->char_str_list())[0] containing 'Test1 " ; more stuff'
and
$TXTrr->char_str_list())[1] containing 'Test2'
=head1 COPYRIGHT
Copyright (c) 1997-2002 Michael Fuhr.
Portions Copyright (c) 2002-2004 Chris Reinhardt.
Portions Copyright (c) 2005 Olaf Kolkman (NLnet Labs)
All rights reserved. This program is free software; you may redistribute
it and/or modify it under the same terms as Perl itself.
=head1 SEE ALSO
L<perl(1)>, L<Net::DNS>, L<Net::DNS::Resolver>, L<Net::DNS::Packet>,
L<Net::DNS::Header>, L<Net::DNS::Question>, L<Net::DNS::RR>,
RFC 1035 Section 3.3.14
=cut
|