Permalink
Browse files

Fix a bunch of bugs

  • Loading branch information...
1 parent f1922a0 commit 2f979c726b601e1ca98801de4a6a9072c8da8e01 @meh committed Feb 18, 2012
View
@@ -81,7 +81,7 @@ def == (what)
elsif value.is_a? Integer
@internal == what
else
- @internal == what.value rescue false
+ @internal == what.to_i rescue false
end
end
View
@@ -30,7 +30,7 @@ def initialize (options = {})
@options = options
@servers = Servers.new
- @options[:servers].flatten.compact.each {|server|
+ [@options[:servers]].flatten.compact.each {|server|
@servers << server
}
@@ -21,13 +21,9 @@
require 'timeout'
require 'socket'
-require 'faildns/client/dispatcher/response'
+require 'faildns/client/response'
-module DNS
-
-class Client
-
-class Dispatcher
+module DNS; class Client
class Server
attr_reader :host, :port
@@ -96,8 +92,4 @@ def _recv (timeout, id = nil)
end
end
-end
-
-end
-
-end
+end; end
View
@@ -298,15 +298,15 @@ def pack
[
id,
- ( (type.value << 15) \
- | (klass.value << 14) \
+ ( (type.to_i << 15) \
+ | (klass.to_i << 14) \
| ((authoritative?) ? (1 << 10) : 0) \
| ((truncated?) ? (1 << 9) : 0) \
| ((recursive?) ? (1 << 8) : 0) \
| ((recursivable?) ? (1 << 7) : 0) \
| ((authentic?) ? (1 << 6) : 0) \
| ((checking?) ? (1 << 5) : 0) \
- | (status.value)),
+ | (status.to_i)),
questions,
answers,
@@ -321,4 +321,3 @@ def inspect
end
end
-
@@ -63,7 +63,7 @@ def initialize (value)
elsif value.is_a? Integer
@internal = value
else
- @internal = value.value rescue nil
+ @internal = value.to_i rescue nil
end
unless to_sym
@@ -79,7 +79,7 @@ def == (what)
elsif value.is_a? Integer
@internal == what
else
- @internal == what.value rescue false
+ @internal == what.to_i rescue false
end
end
@@ -91,7 +91,7 @@ def initialize (value)
elsif value.is_a? Integer
@internal = value
else
- @internal = value.value rescue nil
+ @internal = value.to_i rescue nil
end
unless to_sym
@@ -107,7 +107,7 @@ def == (what)
elsif value.is_a? Integer
@internal == what
else
- @internal == what.value rescue false
+ @internal == what.to_i rescue false
end
end
View
@@ -32,39 +32,45 @@ class Type
1 => :RESPONSE
}
- attr_reader :value
+ include DNS::Comparable
def initialize (value)
if value.is_a? Symbol
- @value = Values.key(value)
+ @internal = Values.key(value)
elsif value.is_a? Integer
- @value = value
+ @internal = value
else
- @value = value.value rescue nil
+ @internal = value.to_i rescue nil
end
unless to_sym
raise ArgumentError, 'the passed value is not a suitable type.'
end
end
+ hash_on :to_i
+
def == (what)
if what.is_a? Symbol
to_sym == what
elsif value.is_a? Integer
- @value == what
+ @internal == what
else
- @value == what.value rescue false
+ @internal == what.to_i rescue false
end
end
def to_sym
- Values[@value]
+ Values[@internal]
end
def to_s
to_sym.to_s
end
+
+ def to_i
+ @internal
+ end
end
end
@@ -46,7 +46,7 @@ module IN
class A < Data
def self._unpack (string, original)
- A.new(IP.parse(string))
+ A.new(IP.unpack(string))
end
attr_reader :ip
@@ -48,7 +48,7 @@ module IN
class AAAA < Data
def self._unpack (string, original)
- AAAA.new(IP.parse(string))
+ AAAA.new(IP.unpack(string))
end
attr_reader :ip
@@ -45,7 +45,7 @@ module IN
class CNAME < Data
def self._unpack (string, original)
- CNAME.new(DomainName.parse(string.clone, original))
+ CNAME.new(DomainName.unpack(string.clone, original))
end
attr_reader :domain
@@ -49,7 +49,7 @@ module IN
class MX < Data
def self._unpack (string, original)
- MX.new(string.unpack('n'), DomainName.parse(string[2, 255], original))
+ MX.new(string.unpack('n'), DomainName.unpack(string[2, 255], original))
end
attr_reader :preference, :exchange
@@ -52,7 +52,7 @@ module IN
class NS < Data
def self._unpack (string, original)
- NS.new(DomainName.parse(string.clone, original))
+ NS.new(DomainName.unpack(string.clone, original))
end
attr_reader :domain
@@ -44,7 +44,7 @@ module IN
class PTR < Data
def self._unpack (string, original)
- PTR.new(DomainName.parse(string.clone, original))
+ PTR.new(DomainName.unpack(string.clone, original))
end
attr_reader :domain
@@ -104,8 +104,8 @@ class SOA < Data
def self._unpack (string, original)
result = {}
- result[:MNAME] = DomainName.parse(string, original)
- result[:RNAME] = DomainName.parse(string, original)
+ result[:MNAME] = DomainName.unpack(string, original)
+ result[:RNAME] = DomainName.unpack(string, original)
[:SERIAL, :REFRESH, :RETRY, :EXPIRE, :MINIMUM].each {|value|
result[value] = string.unpack('N').first || 0; string[0, 4] = ''
View
@@ -171,7 +171,7 @@ def == (what)
elsif value.is_a? Integer
@internal == what
else
- @internal == what.value rescue false
+ @internal == what.to_i rescue false
end
end

0 comments on commit 2f979c7

Please sign in to comment.