Class: Net::DNS::RR::TXT

Inherits:
Net::DNS::RR show all
Defined in:
lib/Net/DNS/RR/TXT.rb

Overview

NAME

Net::DNS::RR::TXT - DNS TXT resource record

DESCRIPTION

Class for DNS Text (TXT) resource records.

FEATURES

The RR class 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.

TXTrr=Net::DNS::RR.create('txt2.t.net-dns.org.	60	IN

TXT “Test1 " ; more stuff” “Test2”‘)

would result in TXTrr.char_str_list()) containing ‘Test1 “ ; more stuff’ and TXTrr.char_str_list()) containing ‘Test2’

COPYRIGHT

Copyright © 1997-2002 Michael Fuhr.

Portions Copyright © 2002-2004 Chris Reinhardt. Portions Copyright © 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.

SEE ALSO

Net::DNS, Net::DNS::Resolver, Net::DNS::Packet, <Net::DNS::Header, Net::DNS::Question, Net::DNS::RR, RFC 1035 Section 3.3.14

Direct Known Subclasses

SPF

Constant Summary

Constants inherited from Net::DNS::RR

RRS

Instance Attribute Summary

Attributes inherited from Net::DNS::RR

#name, #rdata, #rdlength, #rrclass, #ttl, #type

Instance Method Summary collapse

Methods inherited from Net::DNS::RR

#_canonicalRdata, #_canonicaldata, _get_subclass, _name2wire, #_name2wire, build_regex, create, #create_rrsort_func, #data, #get_rrsort_func, #init, #init_rrsort_func, #inspect, new_from_data, new_from_hash, new_from_string, #set_rrsort_func

Instance Method Details

#_build_char_str_list(rdata_string) ⇒ Object



121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/Net/DNS/RR/TXT.rb', line 121

def _build_char_str_list(rdata_string)
  words = Shellwords.shellwords(rdata_string)
  
  init_char_str_list()
  
  if (words != nil)
    words.each { |string|
      string .gsub!(/\\"/, '"')
      @char_str_list.push(string)
    }
  end
end

#char_str_listObject

Returns a list of the individual <character-string> elements, as unquoted strings. Used by TXT->rdatastr and TXT->rr_rdata.

print “Individual <character-string> list: nt”,

rr.char_str_list().join("\n\t")


140
141
142
143
144
145
146
# File 'lib/Net/DNS/RR/TXT.rb', line 140

def char_str_list
  if (!defined?(@char_str_list))
    _build_char_str_list( @txtdata )
  end
  
  return @char_str_list # unquoted strings
end

#init_char_str_listObject



117
118
119
# File 'lib/Net/DNS/RR/TXT.rb', line 117

def init_char_str_list
  @char_str_list = []
end

#new_from_data(data, offset) ⇒ Object

attr_accessor :char_str_list



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/Net/DNS/RR/TXT.rb', line 68

def new_from_data(data, offset)
  init_char_str_list()
  if (@rdlength == nil || @rdlength == 0) 
    return
  end
  endpos = offset + @rdlength
  
  while (offset < endpos)
    strlen = data.unpack("\@#{offset} C")[0]
    offset += 1
    
    char_str = data[offset,strlen]
    offset += strlen
    
    @char_str_list.push(char_str)
  end
end

#new_from_hash(values) ⇒ Object



86
87
88
89
90
# File 'lib/Net/DNS/RR/TXT.rb', line 86

def new_from_hash(values)
  if (values.has_key?:txtdata)
    _build_char_str_list(values[:txtdata])
  end
end

#new_from_string(rdata_string) ⇒ Object



92
93
94
# File 'lib/Net/DNS/RR/TXT.rb', line 92

def new_from_string (rdata_string)
  _build_char_str_list(rdata_string)
end

#rdatastrObject



106
107
108
109
110
111
112
113
114
115
# File 'lib/Net/DNS/RR/TXT.rb', line 106

def rdatastr
  if (defined?@char_str_list)
    temp = @char_str_list.map {|str|
      str.gsub(/"/, '\\"')
      %<"#{str}">
    }
    return temp.join(' ')
  end          
  return ''
end

#rr_rdata(*args) ⇒ Object



148
149
150
151
152
153
154
155
156
157
158
# File 'lib/Net/DNS/RR/TXT.rb', line 148

def rr_rdata(*args)
  rdata = ''
  
  if (@char_str_list!=nil)
    @char_str_list.each { |string|
      rdata += [string.length].pack("C")
      rdata += string
    }
  end 
  return rdata
end

#txtdataObject

Returns the descriptive text as a single string, regardless of actual number of <character-string> elements. Of questionable value. Should be deprecated.

Use txt.rdatastr() or txt.char_str_list() instead.



102
103
104
# File 'lib/Net/DNS/RR/TXT.rb', line 102

def txtdata
  return @char_str_list.join(' ')
end