Parent

Class Index [+]

Quicksearch

Dnsruby::RR::TXT

Class for DNS Text (TXT) resource records. RFC 1035 Section 3.3.14

Constants

TypeValue
ESCAPE_CHARS
ESCAPE_CODES

Attributes

strings[RW]

List of the individual elements

Public Class Methods

display(str, do_escapes = true) click to toggle source
     # File lib/Dnsruby/resource/TXT.rb, line 138
138:       def TXT.display(str, do_escapes = true)
139:         output = ""
140:         # Probably need to scan through each string manually

141:         # Make sure to remember to escape binary characters.

142:         # Go through copying to output, and adding "\" characters as necessary?

143:         str.each_byte {|c|
144:           if (c == 34) || (c == 92) # || (c == 59)

145:             if (do_escapes)
146:             output+='\'
147:             end
148:             output+=c.chr
149:           elsif (c < 32) # c is binary

150:             if (ESCAPE_CODES[c])
151:               output +=  c.chr
152:             else
153:               output+= '\'
154:               num = c.to_i.to_s
155:               (3-num.length).times {|i|
156:                 num="0"+num
157:               }
158:               output+= num # Need a 3 digit number here.

159:             end
160: 
161:           else
162:             output += c.chr
163:           end
164:         }
165:         return output
166:       end
parse(input) click to toggle source
     # File lib/Dnsruby/resource/TXT.rb, line 52
 52:       def TXT.parse(input)
 53:         # Need to look out for special characters.

 54:         # Need to split the input up into strings (which are defined by non-escaped " characters)

 55:         # Then need to fix up any \ escape characters (should just be " and ; and binary?)

 56:         # Sadly, it's going to be easiest just to scan through this character by character...

 57:         in_escaped = false
 58:         in_string = false
 59:         count = 1
 60:         strings = []
 61:         current_binary = ""
 62:         current_quote_char = '"'
 63:         unquoted = false
 64:         seen_strings = false
 65:         pos = 0
 66:         input.each_char {|c|
 67:           if (((c == "'") || (c == '"')) && (!in_escaped) && (!unquoted))
 68:             if (!in_string)
 69:               seen_strings = true
 70:               current_quote_char = c
 71:               in_string = true
 72:               count+=1
 73:               strings[count] = ""
 74:             else
 75:               if (c == current_quote_char)
 76:                 in_string = false
 77:               else
 78:                 strings[count]+=c
 79:               end
 80:             end
 81:           else
 82:             if (seen_strings && !in_string)
 83:               next
 84:             end
 85:             if (pos == 0)
 86:               unquoted = true
 87:               count+=1
 88:               strings[count] = ""
 89:             elsif (unquoted)
 90:               if (c == " ")
 91:                 count+=1
 92:                 strings[count] = ""
 93:                 pos += 1
 94:                 next
 95:               end
 96:             end
 97: 
 98:             if (c == "\\")
 99:               if (in_escaped)
100:                 in_escaped = false
101:                 strings[count]+=(c)
102:               else
103:                 in_escaped = true
104:               end
105:             else
106:               if (in_escaped)
107:                 # Build up the binary

108:                 if (c == ";") || (c == '"')
109:                   strings[count]+=c
110:                   in_escaped = false
111:                 elsif (ESCAPE_CHARS[c])
112:                   in_escaped=false
113:                   strings[count]+=ESCAPE_CHARS[c].chr
114:                 elsif (c<"0" || c>"9")
115:                   in_escaped = false
116:                   strings[count]+=c
117:                 else
118:                   # Must be building up three digit string to identify binary value?

119: #                  if (c >= "0" && c <= "9")

120:                     current_binary += c
121: #                  end

122:                   if ((current_binary.length == 3) ) # || (c < "0" || c > "9"))

123:                     strings[count]+=current_binary.to_i.chr
124:                     in_escaped = false
125:                     current_binary = ""
126:                   end
127:                 end
128:               else
129:                 strings[count]+=(c)
130:               end
131:             end
132:           end
133:           pos += 1
134:         }
135:         return strings
136:       end

Public Instance Methods

data() click to toggle source
    # File lib/Dnsruby/resource/TXT.rb, line 31
31:       def data
32:         @strings[0]
33:       end
from_data(data) click to toggle source
    # File lib/Dnsruby/resource/TXT.rb, line 35
35:       def from_data(data)
36:         @strings = data
37:       end
from_hash(hash) click to toggle source
    # File lib/Dnsruby/resource/TXT.rb, line 39
39:       def from_hash(hash)
40:         if (hash.has_key?:strings)
41:           from_string(hash[:strings])
42:         end
43:       end
from_string(input) click to toggle source
    # File lib/Dnsruby/resource/TXT.rb, line 48
48:       def from_string(input)
49:         @strings = TXT.parse(input)
50:       end
rdata_to_string() click to toggle source
     # File lib/Dnsruby/resource/TXT.rb, line 168
168:       def rdata_to_string
169:         if (defined?@strings)
170:           temp = []
171:           @strings.each {|str|
172:             output = TXT.display(str)
173:             temp.push("\"#{output}\"")
174:           }
175:           return temp.join(' ')
176:         end
177:         return ''
178:       end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.