Class: Dnsruby::Classes

Inherits:
CodeMapper show all
Defined in:
lib/dnsruby/code_mappers.rb

Constant Summary collapse

IN =

RFC 1035

1
CH =

RFC 1035

3
HS =

CHAOS = 3 # RFC 1035

4
NONE =

HESIOD = 4 # RFC 1035

254
ANY =

RFC 2136

255

Instance Attribute Summary

Attributes inherited from CodeMapper

#code, #string

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from CodeMapper

#<=>, #==, add_pair, #hash, #initialize, #inspect, method_missing, regexp, #set_code, #set_string, strings, to_code, to_string, update

Constructor Details

This class inherits a constructor from Dnsruby::CodeMapper

Class Method Details

.classesbyname(name) ⇒ Object

classesbyval and classesbyname functions are wrappers around the

similarly named hashes. They are used for 'unknown' DNS RR classess
(RFC3597)
See typesbyval and typesbyname, these beasts have the same functionality


72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/dnsruby/code_mappers.rb', line 72

def Classes.classesbyname(name) #:nodoc: all
  name = name.upcase

  if to_code(name)
    return to_code(name)
  end

  if ((name =~/^\s*CLASS(\d+)\s*$/o) == nil)
    raise ArgumentError, "classesbyval() argument is not CLASS### (#{name})"
  end

  val = $1.to_i
  if val > 0xffff
    raise ArgumentError, 'classesbyval() argument larger than ' + 0xffff
  end

  return val;
end

.classesbyval(val) ⇒ Object

:nodoc: all

Raises:

  • (ArgumentError)


93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/dnsruby/code_mappers.rb', line 93

def Classes.classesbyval(val) #:nodoc: all
  if (val.class == String)
    if ((val =~ /^\s*0*([0-9]+)\s*$/) == nil)
      raise ArgumentError,  "classesbybal() argument is not numeric (#{val})" # unless  val.gsub!("^\s*0*([0-9]+)\s*$", "$1")
      #           val =~ s/^\s*0*([0-9]+)\s*$/$1/o;#
    end
    val = $1.to_i
  end

  return to_string(val) if to_string(val)

  raise ArgumentError,  'classesbyval() argument larger than ' + 0xffff if val > 0xffff;

  return "CLASS#{val}";
end

Instance Method Details

#unknown_code(arg) ⇒ Object



63
64
65
66
# File 'lib/dnsruby/code_mappers.rb', line 63

def unknown_code(arg)
  Classes.add_pair('CLASS' + arg.to_s, arg)
  set_code(arg)
end

#unknown_string(arg) ⇒ Object



54
55
56
57
58
59
60
61
# File 'lib/dnsruby/code_mappers.rb', line 54

def unknown_string(arg)
  if (arg=~/^CLASS/i)
    Classes.add_pair(arg, arg.gsub('CLASS', '').to_i)
    set_string(arg)
  else
    raise ArgumentError.new("String #{arg} not a member of #{self.class}")
  end
end