Class: Dnsruby::RR::TXT

### Home Classes Methods

### In Files

- lib/dnsruby/resource/TXT.rb

### Parent

Dnsruby::RR

### Methods

- ::display
- ::parse
- #data
- #from_data
- #from_hash
- #from_string
- #rdata_to_string

### Files

- DNSSEC
- EVENTMACHINE
- EXAMPLES

### Class/Module Index

Quicksearch

- Dnsruby
- Dnsruby::Algorithms
- Dnsruby::BitMapping
- Dnsruby::Bitmap
- Dnsruby::Classes
- Dnsruby::CodeMapper
- Dnsruby::Config
- Dnsruby::DNS
- Dnsruby::DecodeError
- Dnsruby::Dnssec
- Dnsruby::Dnssec::ValidationPolicy
- Dnsruby::EncodeError
- Dnsruby::ExtendedRCode
- Dnsruby::FormErr
- Dnsruby::Header
- Dnsruby::Hosts
- Dnsruby::IPv4
- Dnsruby::IPv6
- Dnsruby::Message
- Dnsruby::Message::SecurityLevel
- Dnsruby::MetaTypes
- Dnsruby::Modes
- Dnsruby::NXDomain
- Dnsruby::NXRRSet
- Dnsruby::Name
- Dnsruby::Name::Label
- Dnsruby::NotAuth
- Dnsruby::NotImp
- Dnsruby::NotZone
- Dnsruby::Nsec3HashAlgorithms
- Dnsruby::OpCode
- Dnsruby::OtherResolvError
- Dnsruby::QTypes
- Dnsruby::Question
- Dnsruby::RCode
- Dnsruby::RR
- Dnsruby::RR::ANY
- Dnsruby::RR::CERT
- Dnsruby::RR::CERT::CertificateTypes
- Dnsruby::RR::CNAME
- Dnsruby::RR::DHCID
- Dnsruby::RR::DLV
- Dnsruby::RR::DNAME
- Dnsruby::RR::DNSKEY
- Dnsruby::RR::DS
- Dnsruby::RR::DS::DigestTypes
- Dnsruby::RR::DomainName
- Dnsruby::RR::GPOS
- Dnsruby::RR::Generic
- Dnsruby::RR::HINFO
- Dnsruby::RR::HIP
- Dnsruby::RR::IN
- Dnsruby::RR::IN::A
- Dnsruby::RR::IN::AAAA
- Dnsruby::RR::IN::AFSDB
- Dnsruby::RR::IN::PX
- Dnsruby::RR::IN::SRV
- Dnsruby::RR::IN::WKS
- Dnsruby::RR::IPSECKEY
- Dnsruby::RR::ISDN
- Dnsruby::RR::KX
- Dnsruby::RR::LOC
- Dnsruby::RR::MB
- Dnsruby::RR::MG
- Dnsruby::RR::MINFO
- Dnsruby::RR::MR
- Dnsruby::RR::MX
- Dnsruby::RR::NAPTR
- Dnsruby::RR::NS
- Dnsruby::RR::NSAP
- Dnsruby::RR::NSEC
- Dnsruby::RR::NSEC3
- Dnsruby::RR::NSEC3PARAM
- Dnsruby::RR::NXT
- Dnsruby::RR::NXT::NxtTypes
- Dnsruby::RR::NXT::TypeBitmap
- Dnsruby::RR::OPT
- Dnsruby::RR::PTR
- Dnsruby::RR::RP
- Dnsruby::RR::RRSIG
- Dnsruby::RR::RT
- Dnsruby::RR::SOA
- Dnsruby::RR::SPF
- Dnsruby::RR::SSHFP
- Dnsruby::RR::SSHFP::Algorithms
- Dnsruby::RR::SSHFP::FpTypes
- Dnsruby::RR::TKEY
- Dnsruby::RR::TSIG
- Dnsruby::RR::TXT
- Dnsruby::RR::X25
- Dnsruby::RRSet
- Dnsruby::Recursor
- Dnsruby::Refused
- Dnsruby::Resolv
- Dnsruby::ResolvError
- Dnsruby::ResolvTimeout
- Dnsruby::Resolver
- Dnsruby::Resolver::EventType
- Dnsruby::Section
- Dnsruby::SelectThread
- Dnsruby::ServFail
- Dnsruby::SingleResolver
- Dnsruby::SocketEofResolvError
- Dnsruby::TheLog
- Dnsruby::TsigError
- Dnsruby::TsigNotSignedResponseError
- Dnsruby::Types
- Dnsruby::Update
- Dnsruby::VerifyError
- Dnsruby::YXDomain
- Dnsruby::YXRRSet
- Dnsruby::ZoneReader
- Dnsruby::ZoneReader::ParseException
- Dnsruby::ZoneSerialError
- Dnsruby::ZoneTransfer
- Dnsruby::ZoneTransfer::Delta
- Base32
- Object

No matching classes.

# Dnsruby::RR::TXT

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

### Constants

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 140
    def TXT.display(str, do_escapes = true)
      output = ""
      #  Probably need to scan through each string manually
      #  Make sure to remember to escape binary characters.
      #  Go through copying to output, and adding "\" characters as necessary?
      str.each_byte {|c|
        if (c == 34) || (c == 92) # || (c == 59)
          if (do_escapes)
          output+='\'
          end
          output+=c.chr
        elsif (c < 32) # c is binary
          if (ESCAPE_CODES[c])
            output +=  c.chr
          else
            output+= '\'
            num = c.to_i.to_s
            (3-num.length).times {|i|
              num="0"+num
            }
            output+= num # Need a 3 digit number here.
          end

        else
          output += c.chr
        end
      }
      return output
    end

parse(input) click to toggle source

    # File lib/dnsruby/resource/TXT.rb, line 52
          def TXT.parse(input)
            #  Need to look out for special characters.
            #  Need to split the input up into strings (which are defined by non-escaped " characters)
            #  Then need to fix up any \ escape characters (should just be " and ; and binary?)
            #  Sadly, it's going to be easiest just to scan through this character by character...
            in_escaped = false
            in_string = false
            count = -1
            strings = []
            current_binary = ""
            current_quote_char = '"'
            unquoted = false
            seen_strings = false
            pos = 0
            input.sub!(/^\s*\(\s*/, "")
            input.sub!(/\s*\)\s*$/, "")
            input.each_char {|c|
              if (((c == "'") || (c == '"')) && (!in_escaped) && (!unquoted))
                if (!in_string)
                  seen_strings = true
                  current_quote_char = c
                  in_string = true
                  count+=1
                  strings[count] = ""
                else
                  if (c == current_quote_char)
                    in_string = false
                  else
                    strings[count]+=c
                  end
                end
              else
                if (seen_strings && !in_string)
                  next
                end
                if (pos == 0)
                  unquoted = true
                  count+=1
                  strings[count] = ""
                elsif (unquoted)
                  if (c == " ")
                    count+=1
                    strings[count] = ""
                    pos += 1
                    next
                  end
                end

                if (c == "\\")
                  if (in_escaped)
                    in_escaped = false
                    strings[count]+=(c)
                  else
                    in_escaped = true
                  end
                else
                  if (in_escaped)
                    #  Build up the binary
                    if (c == ";") || (c == '"')
                      strings[count]+=c
                      in_escaped = false
                    elsif (ESCAPE_CHARS[c])
                      in_escaped=false
                      strings[count]+=ESCAPE_CHARS[c].chr
                    elsif (c<"0" || c>"9")
                      in_escaped = false
                      strings[count]+=c
                    else
                      #  Must be building up three digit string to identify binary value?
    #                  if (c >= "0" && c <= "9")
                        current_binary += c
    #                  end
                      if ((current_binary.length == 3) ) # || (c < "0" || c > "9"))
                        strings[count]+=current_binary.to_i.chr
                        in_escaped = false
                        current_binary = ""
                      end
                    end
                  else
                    strings[count]+=(c)
                  end
                end
              end
              pos += 1
            }
            return strings
          end

### Public Instance Methods

data() click to toggle source

    # File lib/dnsruby/resource/TXT.rb, line 31
    def data
      @strings[0]
    end

from_data(data) click to toggle source

    # File lib/dnsruby/resource/TXT.rb, line 35
    def from_data(data)
      @strings = data
    end

from_hash(hash) click to toggle source

    # File lib/dnsruby/resource/TXT.rb, line 39
    def from_hash(hash)
      if (hash.has_key?:strings)
        from_string(hash[:strings])
      end
    end

from_string(input) click to toggle source

    # File lib/dnsruby/resource/TXT.rb, line 48
    def from_string(input)
      @strings = TXT.parse(input)
    end

rdata_to_string() click to toggle source

    # File lib/dnsruby/resource/TXT.rb, line 170
    def rdata_to_string
      if (defined?@strings)
        temp = []
        @strings.each {|str|
          output = TXT.display(str)
          temp.push("\"#{output}\"")
        }
        return temp.join(' ')
      end
      return ''
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.