net-dns 0.5.3 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. data/.gitignore +6 -0
  2. data/AUTHORS.rdoc +7 -0
  3. data/CHANGELOG.rdoc +34 -0
  4. data/README.rdoc +26 -14
  5. data/Rakefile +23 -30
  6. data/{THANKS → THANKS.rdoc} +0 -0
  7. data/VERSION.yml +3 -2
  8. data/demo/check_soa.rb +6 -11
  9. data/lib/net/{dns/dns.rb → dns.rb} +5 -12
  10. data/lib/net/dns/core_ext.rb +52 -0
  11. data/lib/net/dns/header.rb +55 -49
  12. data/lib/net/dns/names/names.rb +20 -10
  13. data/lib/net/dns/packet.rb +33 -26
  14. data/lib/net/dns/question.rb +60 -27
  15. data/lib/net/dns/resolver.rb +101 -156
  16. data/lib/net/dns/resolver/timeouts.rb +71 -65
  17. data/lib/net/dns/rr.rb +131 -166
  18. data/lib/net/dns/rr/a.rb +20 -26
  19. data/lib/net/dns/rr/aaaa.rb +15 -20
  20. data/lib/net/dns/rr/classes.rb +1 -1
  21. data/lib/net/dns/rr/cname.rb +8 -14
  22. data/lib/net/dns/rr/hinfo.rb +8 -14
  23. data/lib/net/dns/rr/mr.rb +8 -14
  24. data/lib/net/dns/rr/mx.rb +11 -18
  25. data/lib/net/dns/rr/ns.rb +8 -14
  26. data/lib/net/dns/rr/null.rb +7 -14
  27. data/lib/net/dns/rr/ptr.rb +9 -15
  28. data/lib/net/dns/rr/soa.rb +9 -15
  29. data/lib/net/dns/rr/srv.rb +10 -19
  30. data/lib/net/dns/rr/txt.rb +9 -20
  31. data/lib/net/dns/rr/types.rb +51 -58
  32. data/lib/net/dns/version.rb +22 -0
  33. data/test/{net/dns/test_header.rb → header_test.rb} +20 -20
  34. data/test/{net/dns/test_packet.rb → packet_test.rb} +2 -2
  35. data/test/question_test.rb +84 -0
  36. data/test/resolver/timeouts_test.rb +109 -0
  37. data/test/{net/dns/test_resolver.rb → resolver_test.rb} +6 -6
  38. data/test/rr/a_test.rb +66 -0
  39. data/test/{net/dns/rr/test_classes.rb → rr/classes_test.rb} +5 -5
  40. data/test/rr/ns_test.rb +64 -0
  41. data/test/rr/types_test.rb +69 -0
  42. data/test/{net/dns/test_rr.rb → rr_test.rb} +10 -12
  43. data/test/test_helper.rb +4 -0
  44. metadata +50 -35
  45. data/AUTHORS +0 -10
  46. data/CHANGELOG +0 -7
  47. data/INSTALL +0 -8
  48. data/net-dns.gemspec +0 -92
  49. data/test/net/dns/resolver/test_timeouts.rb +0 -59
  50. data/test/net/dns/rr/test_a.rb +0 -72
  51. data/test/net/dns/rr/test_ns.rb +0 -66
  52. data/test/net/dns/rr/test_types.rb +0 -124
  53. data/test/net/dns/test_question.rb +0 -54
@@ -1,11 +1,3 @@
1
- ##
2
- #
3
- # Net::DNS::RR::PTR
4
- #
5
- # $Id: PTR.rb,v 1.5 2006/07/28 07:33:36 bluemonk Exp $
6
- #
7
- ##
8
-
9
1
  module Net
10
2
  module DNS
11
3
  class RR
@@ -26,7 +18,7 @@ module Net
26
18
  def check_ptr(str)
27
19
  IPAddr.new str
28
20
  rescue
29
- raise RRArgumentError, "PTR section not valid"
21
+ raise ArgumentError, "PTR section not valid"
30
22
  end
31
23
 
32
24
  def build_pack
@@ -34,10 +26,6 @@ module Net
34
26
  @rdlength = @ptrdname_pack.size
35
27
  end
36
28
 
37
- def set_type
38
- @type = Net::DNS::RR::Types.new("PTR")
39
- end
40
-
41
29
  def get_data
42
30
  @ptrdname_pack
43
31
  end
@@ -50,7 +38,7 @@ module Net
50
38
  if args.has_key? :ptrdname or args.has_key? :ptr
51
39
  @ptrdname = args[0][:ptrdname]
52
40
  else
53
- raise RRArgumentError, ":ptrdname or :ptr field is mandatory but missing"
41
+ raise ArgumentError, ":ptrdname or :ptr field is mandatory but missing"
54
42
  end
55
43
  end
56
44
 
@@ -62,7 +50,13 @@ module Net
62
50
  @ptrdname,offset = dn_expand(data,offset)
63
51
  return offset
64
52
  end
65
-
53
+
54
+ private
55
+
56
+ def set_type
57
+ @type = Net::DNS::RR::Types.new("PRT")
58
+ end
59
+
66
60
  end # class PTR
67
61
 
68
62
  end # class RR
@@ -1,11 +1,3 @@
1
- ##
2
- #
3
- # Net::DNS::RR::SOA
4
- #
5
- # $Id: SOA.rb,v 1.4 2006/07/28 07:33:36 bluemonk Exp $
6
- #
7
- ##
8
-
9
1
  module Net
10
2
  module DNS
11
3
  class RR
@@ -24,10 +16,6 @@ module Net
24
16
  @soa_pack += [@serial,@refresh,@retry,@expire,@minimum].pack("N5")
25
17
  end
26
18
 
27
- def set_type
28
- @type = Net::DNS::RR::Types.new("SOA")
29
- end
30
-
31
19
  def get_data
32
20
  @soa_pack
33
21
  end
@@ -41,7 +29,7 @@ module Net
41
29
  subclass_new_from_string(args[:rdata])
42
30
  else
43
31
  [:mname,:rname,:serial,:refresh,:retry,:expire,:minimum].each do |key|
44
- raise RRArgumentError, "Missing field :#{key}" unless args.has_key? key
32
+ raise ArgumentError, "Missing field :#{key}" unless args.has_key? key
45
33
  end
46
34
  @mname = args[:mname] if valid? args[:mname]
47
35
  @rname = args[:rname] if valid? args[:rname]
@@ -57,7 +45,7 @@ module Net
57
45
  if num.kind_of? Integer and num > 0
58
46
  true
59
47
  else
60
- raise RRArgumentError, "Wrong format field: #{num} not a number or less than zero"
48
+ raise ArgumentError, "Wrong format field: #{num} not a number or less than zero"
61
49
  end
62
50
  end
63
51
 
@@ -76,7 +64,13 @@ module Net
76
64
  @serial,@refresh,@retry,@expire,@minimum = data.unpack("@#{offset} N5")
77
65
  return offset + 5*Net::DNS::INT32SZ
78
66
  end
79
-
67
+
68
+ private
69
+
70
+ def set_type
71
+ @type = Net::DNS::RR::Types.new("SOA")
72
+ end
73
+
80
74
  end # class SOA
81
75
 
82
76
  end # class RR
@@ -1,12 +1,3 @@
1
- ##
2
- #
3
- # Net::DNS::RR::SRV
4
- #
5
- # $Id$
6
- #
7
- ##
8
-
9
-
10
1
  module Net
11
2
  module DNS
12
3
  class RR
@@ -24,10 +15,6 @@ module Net
24
15
  str = ""
25
16
  end
26
17
 
27
- def set_type
28
- @type = Net::DNS::RR::Types.new("SRV")
29
- end
30
-
31
18
  def subclass_new_from_binary(data,offset)
32
19
  off_end = offset + @rdlength
33
20
  @priority, @weight, @port = data.unpack("@#{offset} n n n")
@@ -44,14 +31,18 @@ module Net
44
31
  @host=@host.join(".")
45
32
  offset
46
33
  end
47
-
48
-
49
- end # class SRV
50
- end # class RR
51
34
 
35
+ private
36
+
37
+ def set_type
38
+ @type = Net::DNS::RR::Types.new("SRV")
39
+ end
40
+
41
+ end
42
+ end
52
43
 
53
- end # module DNS
54
- end # module Net
44
+ end
45
+ end
55
46
 
56
47
 
57
48
 
@@ -1,12 +1,3 @@
1
- ##
2
- #
3
- # Net::DNS::RR::TXT
4
- #
5
- # $Id: TXT.rb,v 1.4 2006/07/28 07:33:36 bluemonk Exp $
6
- #
7
- ##
8
-
9
-
10
1
  module Net
11
2
  module DNS
12
3
  class RR
@@ -27,10 +18,6 @@ module Net
27
18
  @txt_pack = str
28
19
  @rdlength = @txt_pack.size
29
20
  end
30
-
31
- def set_type
32
- @type = Net::DNS::RR::Types.new("TXT")
33
- end
34
21
 
35
22
  def get_data
36
23
  @txt_pack
@@ -40,7 +27,7 @@ module Net
40
27
  if args.has_key? :txt
41
28
  @txt = args[:txt].strip
42
29
  else
43
- raise RRArgumentError, ":txt field is mandatory but missing"
30
+ raise ArgumentError, ":txt field is mandatory but missing"
44
31
  end
45
32
  end
46
33
 
@@ -60,13 +47,15 @@ module Net
60
47
  end
61
48
  return offset
62
49
  end
63
-
50
+
51
+ private
52
+
53
+ def set_type
54
+ @type = Net::DNS::RR::Types.new("TXT")
55
+ end
56
+
64
57
  end # class TXT
65
58
 
66
59
  end # class RR
67
60
  end # module DNS
68
- end # module Net
69
-
70
-
71
-
72
-
61
+ end # module Net
@@ -3,13 +3,10 @@ module Net # :nodoc:
3
3
 
4
4
  class RR
5
5
 
6
- #
7
- # This is an auxiliary class to hadle RR type field in a DNS packet.
8
- #
6
+ # This is an auxiliary class to handle RR type field in a DNS packet.
9
7
  class Types
10
8
 
11
- # :nodoc:
12
- Types = { # :nodoc:
9
+ TYPES = {
13
10
  'SIGZERO' => 0, # RFC2931 consider this a pseudo type
14
11
  'A' => 1, # RFC 1035, Section 3.4.1
15
12
  'NS' => 2, # RFC 1035, Section 3.3.11
@@ -41,7 +38,7 @@ module Net # :nodoc:
41
38
  'GPOS' => 27, # RFC 1712 (obsolete)
42
39
  'AAAA' => 28, # RFC 1886, Section 2.1
43
40
  'LOC' => 29, # RFC 1876
44
- # The following RR is impemented in Net::DNS::SEC, TODO
41
+ # The following RR is implemented in Net::DNS::SEC, TODO
45
42
  'NXT' => 30, # RFC 2535, Section 5.2
46
43
  'EID' => 31, # draft-ietf-nimrod-dns-xx.txt
47
44
  'NIMLOC' => 32, # draft-ietf-nimrod-dns-xx.txt
@@ -52,7 +49,7 @@ module Net # :nodoc:
52
49
  'CERT' => 37, # RFC 2538
53
50
  'DNAME' => 39, # RFC 2672
54
51
  'OPT' => 41, # RFC 2671
55
- # The following 4 RRs are impemented in Net::DNS::SEC TODO
52
+ # The following 4 RRs are implemented in Net::DNS::SEC TODO
56
53
  'DS' => 43, # draft-ietf-dnsext-delegation-signer
57
54
  'SSHFP' => 44, # draft-ietf-secsh-dns (No RFC # yet at time of coding)
58
55
  'RRSIG' => 46, # draft-ietf-dnsext-dnssec-2535typecode-change
@@ -72,27 +69,27 @@ module Net # :nodoc:
72
69
  }
73
70
 
74
71
  # The default value when type is nil in Resource Records
75
- @@default = Types["A"]
72
+ @@default = TYPES["A"]
76
73
 
77
74
  # Be able to control the default type to assign when
78
75
  # type is +nil+. Default to +A+
79
76
  def self.default=(str)
80
- if Types.has_key? str
81
- @@default = Types[str]
77
+ if TYPES.has_key? str
78
+ @@default = TYPES[str]
82
79
  else
83
- raise TypeArgumentError, "Unknown type #{str}"
80
+ raise ArgumentError, "Unknown type #{str}"
84
81
  end
85
82
  end
86
83
 
87
84
  # Checks whether +type+ is a valid RR type.
88
85
  def self.valid?(type)
89
86
  case type
90
- when String
91
- return Types.has_key?(type)
92
- when Fixnum
93
- return Types.invert.has_key?(type)
94
- else
95
- raise TypeArgumentError, "Wrong type class: #{type.class}"
87
+ when String
88
+ TYPES.has_key?(type)
89
+ when Fixnum
90
+ TYPES.invert.has_key?(type)
91
+ else
92
+ raise ArgumentError, "Wrong type class: #{type.class}"
96
93
  end
97
94
  end
98
95
 
@@ -100,21 +97,22 @@ module Net # :nodoc:
100
97
  # given the numeric value
101
98
  def self.to_str(type)
102
99
  case type
103
- when Fixnum
104
- if Types.invert.has_key? type
105
- return Types.invert[type]
100
+ when Fixnum
101
+ if TYPES.invert.has_key? type
102
+ TYPES.invert[type]
103
+ else
104
+ raise ArgumentError, "Unknown type number #{type}"
105
+ end
106
106
  else
107
- raise TypeArgumentError, "Unknown type number #{type}"
108
- end
109
- else
110
- raise TypeArgumentError, "Wrong type class: #{type.class}"
107
+ raise ArgumentError, "Wrong type class: #{type.class}"
111
108
  end
112
109
  end
113
110
 
114
111
  # Gives in output the keys from the +Types+ hash
115
112
  # in a format suited for regexps
116
113
  def self.regexp
117
- Types.keys.sort.join("|")
114
+ # Longest ones go first, so the regex engine will match AAAA before A.
115
+ TYPES.keys.sort { |a,b| b.length <=> a.length }.join("|")
118
116
  end
119
117
 
120
118
  # Creates a new object representing an RR type. Performs some
@@ -130,10 +128,10 @@ module Net # :nodoc:
130
128
  new_from_num(type)
131
129
  when nil
132
130
  # default type, control with Types.default=
133
- @str = Types.invert[@@default]
131
+ @str = TYPES.invert[@@default]
134
132
  @num = @@default
135
133
  else
136
- raise TypeArgumentError, "Wrong type class: #{type.class}"
134
+ raise ArgumentError, "Wrong type class: #{type.class}"
137
135
  end
138
136
  end
139
137
 
@@ -155,46 +153,41 @@ module Net # :nodoc:
155
153
  @num.to_i
156
154
  end
157
155
 
158
- # Should be used only for testing purpouses
159
156
  def to_str
160
157
  @num.to_s
161
158
  end
162
159
 
160
+
163
161
  private
164
-
165
- # Constructor for string data type,
166
- # *PRIVATE* method
167
- def new_from_string(type)
168
- case type
169
- when /^TYPE\\d+/
170
- # TODO!!!
171
- else
172
- # String with name of type
173
- if Types.has_key? type
174
- @str = type
175
- @num = Types[type]
162
+
163
+ # Constructor for string data type.
164
+ def new_from_string(type)
165
+ case type
166
+ when /^TYPE\\d+/
167
+ # TODO!!!
176
168
  else
177
- raise TypeArgumentError, "Unknown type #{type}"
169
+ # String with name of type
170
+ if TYPES.has_key? type
171
+ @str = type
172
+ @num = TYPES[type]
173
+ else
174
+ raise ArgumentError, "Unknown type #{type}"
175
+ end
178
176
  end
179
177
  end
180
- end
181
178
 
182
- # Contructor for numeric data type
183
- # *PRIVATE* method
184
- def new_from_num(type)
185
- if Types.invert.has_key? type
186
- @num = type
187
- @str = Types.invert[type]
188
- else
189
- raise TypeArgumentError, "Unkown type number #{type}"
179
+ # Contructor for numeric data type.
180
+ def new_from_num(type)
181
+ if TYPES.invert.has_key? type
182
+ @num = type
183
+ @str = TYPES.invert[type]
184
+ else
185
+ raise ArgumentError, "Unkown type number #{type}"
186
+ end
190
187
  end
191
- end
192
188
 
193
- end # class Types
189
+ end
194
190
 
195
- end # class RR
196
- end # module DNS
197
- end # module Net
198
-
199
- class TypeArgumentError < ArgumentError # :nodoc:
200
- end
191
+ end
192
+ end
193
+ end
@@ -0,0 +1,22 @@
1
+ require 'yaml'
2
+
3
+
4
+ module Net # :nodoc:
5
+ module DNS
6
+ module Version
7
+
8
+ @@version = YAML.load_file(File.dirname(__FILE__) + '/../../../VERSION.yml')
9
+
10
+ MAJOR = @@version[:major]
11
+ MINOR = @@version[:minor]
12
+ PATCH = @@version[:patch]
13
+
14
+ STRING = [MAJOR, MINOR, PATCH].join('.')
15
+ end
16
+
17
+ VERSION = Version::STRING
18
+ STATUS = 'beta'
19
+ BUILD = nil
20
+
21
+ end
22
+ end
@@ -1,7 +1,7 @@
1
- require 'test/unit'
1
+ require 'test_helper'
2
2
  require 'net/dns/header'
3
3
 
4
- class Test_Header < Test::Unit::TestCase
4
+ class HeaderTest < Test::Unit::TestCase
5
5
  include Net::DNS
6
6
 
7
7
  def setup
@@ -110,58 +110,58 @@ class Test_Header < Test::Unit::TestCase
110
110
  assert_equal(@binary.nsCount, 3)
111
111
  assert_equal(@binary.arCount, 3)
112
112
 
113
- assert_raise(HeaderArgumentError) do
113
+ assert_raise(Header::ArgumentError) do
114
114
  Header.new(Array.new)
115
115
  end
116
- assert_raise(HeaderArgumentError) do
116
+ assert_raise(Header::ArgumentError) do
117
117
  Header.parse(Array.new)
118
118
  end
119
- assert_raise(HeaderArgumentError) do
119
+ assert_raise(Header::ArgumentError) do
120
120
  Header.parse("aa")
121
121
  end
122
- assert_raise(HeaderDuplicateID) do
122
+ assert_raise(Header::DuplicateIDError) do
123
123
  @default.id = 441
124
124
  end
125
- assert_raise(HeaderArgumentError) do
125
+ assert_raise(Header::ArgumentError) do
126
126
  @default.id = 1000000
127
127
  end
128
- assert_raise(HeaderArgumentError) do
128
+ assert_raise(Header::ArgumentError) do
129
129
  @default.qr=2
130
130
  end
131
- assert_raise(HeaderWrongOpcode) do
131
+ assert_raise(Header::WrongOpcodeError) do
132
132
  @default.opCode=4
133
133
  end
134
- assert_raise(HeaderArgumentError) do
134
+ assert_raise(Header::ArgumentError) do
135
135
  @default.aa=2
136
136
  end
137
- assert_raise(HeaderArgumentError) do
137
+ assert_raise(Header::ArgumentError) do
138
138
  @default.tc=2
139
139
  end
140
- assert_raise(HeaderWrongRecursive) do
140
+ assert_raise(Header::WrongRecursiveError) do
141
141
  @default.recursive=2
142
142
  end
143
- assert_raise(HeaderArgumentError) do
143
+ assert_raise(Header::ArgumentError) do
144
144
  @default.ra=2
145
145
  end
146
- assert_raise(HeaderArgumentError) do
146
+ assert_raise(Header::ArgumentError) do
147
147
  @default.cd=2
148
148
  end
149
- assert_raise(HeaderArgumentError) do
149
+ assert_raise(Header::ArgumentError) do
150
150
  @default.ad=2
151
151
  end
152
- assert_raise(HeaderArgumentError) do
152
+ assert_raise(Header::ArgumentError) do
153
153
  @default.rCode=46
154
154
  end
155
- assert_raise(HeaderWrongCount) do
155
+ assert_raise(Header::WrongCountError) do
156
156
  @default.qdCount=100000
157
157
  end
158
- assert_raise(HeaderWrongCount) do
158
+ assert_raise(Header::WrongCountError) do
159
159
  @default.anCount=100000
160
160
  end
161
- assert_raise(HeaderWrongCount) do
161
+ assert_raise(Header::WrongCountError) do
162
162
  @default.nsCount=100000
163
163
  end
164
- assert_raise(HeaderWrongCount) do
164
+ assert_raise(Header::WrongCountError) do
165
165
  @default.arCount=100000
166
166
  end
167
167
  end