net-dns 0.6.1 → 0.7.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 +8 -6
  2. data/.travis.yml +14 -0
  3. data/CHANGELOG.md +79 -0
  4. data/Gemfile +4 -0
  5. data/Rakefile +56 -66
  6. data/demo/check_soa.rb +1 -1
  7. data/demo/threads.rb +1 -1
  8. data/lib/net/dns.rb +24 -22
  9. data/lib/net/dns/header.rb +77 -103
  10. data/lib/net/dns/{names/names.rb → names.rb} +19 -20
  11. data/lib/net/dns/packet.rb +231 -256
  12. data/lib/net/dns/question.rb +11 -40
  13. data/lib/net/dns/resolver.rb +248 -250
  14. data/lib/net/dns/resolver/socks.rb +6 -6
  15. data/lib/net/dns/resolver/timeouts.rb +1 -1
  16. data/lib/net/dns/rr.rb +112 -117
  17. data/lib/net/dns/rr/a.rb +98 -89
  18. data/lib/net/dns/rr/aaaa.rb +84 -68
  19. data/lib/net/dns/rr/classes.rb +91 -106
  20. data/lib/net/dns/rr/cname.rb +64 -45
  21. data/lib/net/dns/rr/hinfo.rb +90 -50
  22. data/lib/net/dns/rr/mr.rb +61 -44
  23. data/lib/net/dns/rr/mx.rb +73 -48
  24. data/lib/net/dns/rr/ns.rb +60 -46
  25. data/lib/net/dns/rr/null.rb +11 -12
  26. data/lib/net/dns/rr/ptr.rb +47 -34
  27. data/lib/net/dns/rr/soa.rb +5 -6
  28. data/lib/net/dns/rr/srv.rb +1 -4
  29. data/lib/net/dns/rr/txt.rb +14 -14
  30. data/lib/net/dns/rr/types.rb +13 -13
  31. data/lib/net/dns/version.rb +8 -14
  32. data/net-dns.gemspec +35 -0
  33. data/setup.rb +3 -2
  34. data/test/header_test.rb +18 -18
  35. data/test/names_test.rb +21 -0
  36. data/test/packet_test.rb +38 -31
  37. data/test/question_test.rb +23 -24
  38. data/test/resolver/timeouts_test.rb +13 -13
  39. data/test/resolver_test.rb +28 -20
  40. data/test/rr/a_test.rb +70 -23
  41. data/test/rr/aaaa_test.rb +109 -0
  42. data/test/rr/classes_test.rb +61 -49
  43. data/test/rr/cname_test.rb +97 -0
  44. data/test/rr/hinfo_test.rb +117 -0
  45. data/test/rr/mr_test.rb +105 -0
  46. data/test/rr/mx_test.rb +112 -0
  47. data/test/rr/ns_test.rb +34 -12
  48. data/test/rr/types_test.rb +4 -4
  49. data/test/rr_test.rb +1 -1
  50. metadata +77 -52
  51. data/AUTHORS.rdoc +0 -7
  52. data/CHANGELOG.rdoc +0 -46
  53. data/VERSION.yml +0 -5
@@ -1,7 +1,7 @@
1
- module Net
1
+ module Net # :nodoc:
2
2
  module DNS
3
3
  class RR
4
-
4
+
5
5
  #------------------------------------------------------------
6
6
  # RR type NULL
7
7
  #------------------------------------------------------------
@@ -9,7 +9,7 @@ module Net
9
9
  attr_reader :null
10
10
 
11
11
  private
12
-
12
+
13
13
  def build_pack
14
14
  @null_pack = @null
15
15
  @rdlength = @null_pack.size
@@ -22,7 +22,7 @@ module Net
22
22
  def get_inspect
23
23
  "#@null"
24
24
  end
25
-
25
+
26
26
  def subclass_new_from_hash(args)
27
27
  if args.has_key? :null
28
28
  @null = args[:null]
@@ -39,16 +39,15 @@ module Net
39
39
  @null = data[offset..offset+@rdlength]
40
40
  return offset + @rdlength
41
41
  end
42
-
42
+
43
43
  private
44
-
44
+
45
45
  def set_type
46
46
  @type = Net::DNS::RR::Types.new("NULL")
47
47
  end
48
-
49
- end # class NULL
50
-
51
- end # class RR
52
- end # module DNS
53
- end # module Net
54
48
 
49
+ end
50
+
51
+ end
52
+ end
53
+ end
@@ -1,7 +1,7 @@
1
1
  module Net
2
2
  module DNS
3
3
  class RR
4
-
4
+
5
5
  #
6
6
  # = Pointer Record (PTR)
7
7
  #
@@ -13,20 +13,26 @@ module Net
13
13
  #
14
14
  class PTR < RR
15
15
 
16
- # Getter for PTR resource
17
- def ptr
16
+ # Gets the PTR value.
17
+ #
18
+ # Returns a String.
19
+ def ptrdname
18
20
  @ptrdname.to_s
19
21
  end
20
- alias_method :ptrdname, :ptr
21
-
22
- private
23
-
24
- def check_ptr(str)
25
- IPAddr.new str
26
- rescue
27
- raise ArgumentError, "PTR section not valid"
22
+
23
+ alias_method :ptr, :ptrdname
24
+
25
+ # Gets the standardized value for this record,
26
+ # represented by the value of <tt>ptrdname</tt>.
27
+ #
28
+ # Returns a String.
29
+ def value
30
+ ptrdname.to_s
28
31
  end
29
-
32
+
33
+
34
+ private
35
+
30
36
  def build_pack
31
37
  @ptrdname_pack = pack_name(@ptrdname)
32
38
  @rdlength = @ptrdname_pack.size
@@ -36,35 +42,42 @@ module Net
36
42
  @ptrdname_pack
37
43
  end
38
44
 
39
- def get_inspect
40
- "#@ptrdname"
41
- end
42
-
43
45
  def subclass_new_from_hash(args)
44
- if args.has_key? :ptrdname or args.has_key? :ptr
45
- @ptrdname = args[0][:ptrdname]
46
+ if args.has_key?(:ptrdname) or args.has_key?(:ptr)
47
+ @ptrdname = args[:ptrdname]
46
48
  else
47
- raise ArgumentError, ":ptrdname or :ptr field is mandatory but missing"
49
+ raise ArgumentError, ":ptrdname or :ptr field is mandatory"
48
50
  end
49
51
  end
50
52
 
51
53
  def subclass_new_from_string(str)
52
- @ptrdname = check_ptr(str)
54
+ @ptrdname = check_name(str)
53
55
  end
54
56
 
55
- def subclass_new_from_binary(data,offset)
56
- @ptrdname,offset = dn_expand(data,offset)
57
- return offset
57
+ def subclass_new_from_binary(data, offset)
58
+ @ptrdname, offset = dn_expand(data, offset)
59
+ offset
58
60
  end
59
-
61
+
60
62
  private
61
-
62
- def set_type
63
- @type = Net::DNS::RR::Types.new("PTR")
64
- end
65
-
66
- end # class PTR
67
-
68
- end # class RR
69
- end # module DNS
70
- end # module Net
63
+
64
+ def set_type
65
+ @type = Net::DNS::RR::Types.new("PTR")
66
+ end
67
+
68
+ def get_inspect
69
+ value
70
+ end
71
+
72
+
73
+ def check_name(input)
74
+ IPAddr.new(str)
75
+ rescue
76
+ raise ArgumentError, "Invalid PTR Section `#{input}'"
77
+ end
78
+
79
+ end
80
+
81
+ end
82
+ end
83
+ end
@@ -1,4 +1,4 @@
1
- module Net
1
+ module Net # :nodoc:
2
2
  module DNS
3
3
  class RR
4
4
 
@@ -71,9 +71,8 @@ module Net
71
71
  @type = Net::DNS::RR::Types.new("SOA")
72
72
  end
73
73
 
74
- end # class SOA
74
+ end
75
75
 
76
- end # class RR
77
- end # module DNS
78
- end # module Net
79
-
76
+ end
77
+ end
78
+ end
@@ -1,4 +1,4 @@
1
- module Net
1
+ module Net # :nodoc:
2
2
  module DNS
3
3
  class RR
4
4
 
@@ -43,6 +43,3 @@ module Net
43
43
 
44
44
  end
45
45
  end
46
-
47
-
48
-
@@ -1,7 +1,7 @@
1
- module Net
1
+ module Net # :nodoc:
2
2
  module DNS
3
3
  class RR
4
-
4
+
5
5
  #------------------------------------------------------------
6
6
  # RR type TXT
7
7
  #------------------------------------------------------------
@@ -9,7 +9,7 @@ module Net
9
9
  attr_reader :txt
10
10
 
11
11
  private
12
-
12
+
13
13
  def build_pack
14
14
  str = ""
15
15
  @txt.split(" ").each do |txt|
@@ -30,11 +30,11 @@ module Net
30
30
  raise ArgumentError, ":txt field is mandatory but missing"
31
31
  end
32
32
  end
33
-
33
+
34
34
  def subclass_new_from_string(str)
35
35
  @txt = str.strip
36
36
  end
37
-
37
+
38
38
  def subclass_new_from_binary(data,offset)
39
39
  off_end = offset + @rdlength
40
40
  @txt = ""
@@ -46,16 +46,16 @@ module Net
46
46
  @txt << str << " "
47
47
  end
48
48
  return offset
49
- end
50
-
49
+ end
50
+
51
51
  private
52
-
52
+
53
53
  def set_type
54
54
  @type = Net::DNS::RR::Types.new("TXT")
55
55
  end
56
-
57
- end # class TXT
58
-
59
- end # class RR
60
- end # module DNS
61
- end # module Net
56
+
57
+ end
58
+
59
+ end
60
+ end
61
+ end
@@ -1,11 +1,11 @@
1
1
  module Net # :nodoc:
2
2
  module DNS
3
-
3
+
4
4
  class RR
5
-
5
+
6
6
  # This is an auxiliary class to handle RR type field in a DNS packet.
7
7
  class Types
8
-
8
+
9
9
  TYPES = {
10
10
  'SIGZERO' => 0, # RFC2931 consider this a pseudo type
11
11
  'A' => 1, # RFC 1035, Section 3.4.1
@@ -81,7 +81,7 @@ module Net # :nodoc:
81
81
  end
82
82
  end
83
83
 
84
- # Checks whether +type+ is a valid RR type.
84
+ # Checks whether +type+ is a valid RR type.
85
85
  def self.valid?(type)
86
86
  case type
87
87
  when String
@@ -92,7 +92,7 @@ module Net # :nodoc:
92
92
  raise ArgumentError, "Wrong type class: #{type.class}"
93
93
  end
94
94
  end
95
-
95
+
96
96
  # Returns the type in string format, as "A" or "NS",
97
97
  # given the numeric value
98
98
  def self.to_str(type)
@@ -122,10 +122,10 @@ module Net # :nodoc:
122
122
  case type
123
123
  when String
124
124
  # type in the form "A" or "NS"
125
- new_from_string(type.upcase)
125
+ new_from_string(type.upcase)
126
126
  when Fixnum
127
127
  # type in numeric form
128
- new_from_num(type)
128
+ new_from_num(type)
129
129
  when nil
130
130
  # default type, control with Types.default=
131
131
  @str = TYPES.invert[@@default]
@@ -134,8 +134,8 @@ module Net # :nodoc:
134
134
  raise ArgumentError, "Wrong type class: #{type.class}"
135
135
  end
136
136
  end
137
-
138
- # Returns the type in number format
137
+
138
+ # Returns the type in number format
139
139
  # (default for normal use)
140
140
  def inspect
141
141
  @num
@@ -152,7 +152,7 @@ module Net # :nodoc:
152
152
  def to_i
153
153
  @num.to_i
154
154
  end
155
-
155
+
156
156
  def to_str
157
157
  @num.to_s
158
158
  end
@@ -185,9 +185,9 @@ module Net # :nodoc:
185
185
  raise ArgumentError, "Unkown type number #{type}"
186
186
  end
187
187
  end
188
-
188
+
189
189
  end
190
-
190
+
191
191
  end
192
192
  end
193
- end
193
+ end
@@ -1,22 +1,16 @@
1
- require 'yaml'
2
-
3
-
4
- module Net # :nodoc:
5
- module DNS
1
+ module Net
2
+ module DNS
6
3
  module Version
7
-
8
- @@version = YAML.load_file(File.dirname(__FILE__) + '/../../../VERSION.yml')
9
4
 
10
- MAJOR = @@version[:major]
11
- MINOR = @@version[:minor]
12
- PATCH = @@version[:patch]
5
+ MAJOR = 0
6
+ MINOR = 7
7
+ PATCH = 0
8
+ BUILD = nil
13
9
 
14
- STRING = [MAJOR, MINOR, PATCH].join('.')
10
+ STRING = [MAJOR, MINOR, PATCH, BUILD].compact.join(".")
15
11
  end
16
12
 
17
- VERSION = Version::STRING
18
- STATUS = 'beta'
19
- BUILD = nil
13
+ VERSION = Version::STRING
20
14
 
21
15
  end
22
16
  end
@@ -0,0 +1,35 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = "net-dns"
5
+ s.version = "0.7.0"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Marco Ceresa", "Simone Carletti"]
9
+ s.date = "2012-05-02"
10
+ s.description = "Net::DNS is a pure Ruby DNS library, with a clean OO interface and an extensible API."
11
+ s.email = ["ceresa@gmail.com", "weppos@weppos.net"]
12
+ s.files = [".gitignore", ".travis.yml", "CHANGELOG.md", "Gemfile", "Gemfile.lock", "README.rdoc", "Rakefile", "THANKS.rdoc", "demo/check_soa.rb", "demo/threads.rb", "lib/net/dns.rb", "lib/net/dns/core_ext.rb", "lib/net/dns/header.rb", "lib/net/dns/names.rb", "lib/net/dns/packet.rb", "lib/net/dns/question.rb", "lib/net/dns/resolver.rb", "lib/net/dns/resolver/socks.rb", "lib/net/dns/resolver/timeouts.rb", "lib/net/dns/rr.rb", "lib/net/dns/rr/a.rb", "lib/net/dns/rr/aaaa.rb", "lib/net/dns/rr/classes.rb", "lib/net/dns/rr/cname.rb", "lib/net/dns/rr/hinfo.rb", "lib/net/dns/rr/mr.rb", "lib/net/dns/rr/mx.rb", "lib/net/dns/rr/ns.rb", "lib/net/dns/rr/null.rb", "lib/net/dns/rr/ptr.rb", "lib/net/dns/rr/soa.rb", "lib/net/dns/rr/srv.rb", "lib/net/dns/rr/txt.rb", "lib/net/dns/rr/types.rb", "lib/net/dns/version.rb", "net-dns.gemspec", "setup.rb", "test/header_test.rb", "test/names_test.rb", "test/packet_test.rb", "test/question_test.rb", "test/resolver/timeouts_test.rb", "test/resolver_test.rb", "test/rr/a_test.rb", "test/rr/aaaa_test.rb", "test/rr/classes_test.rb", "test/rr/cname_test.rb", "test/rr/hinfo_test.rb", "test/rr/mr_test.rb", "test/rr/mx_test.rb", "test/rr/ns_test.rb", "test/rr/types_test.rb", "test/rr_test.rb", "test/test_helper.rb"]
13
+ s.homepage = "http://github.com/bluemonk/net-dns"
14
+ s.require_paths = ["lib"]
15
+ s.required_ruby_version = Gem::Requirement.new(">= 1.8.7")
16
+ s.rubyforge_project = "net-dns"
17
+ s.rubygems_version = "1.8.21"
18
+ s.summary = "Pure Ruby DNS library."
19
+ s.test_files = ["test/header_test.rb", "test/names_test.rb", "test/packet_test.rb", "test/question_test.rb", "test/resolver/timeouts_test.rb", "test/resolver_test.rb", "test/rr/a_test.rb", "test/rr/aaaa_test.rb", "test/rr/classes_test.rb", "test/rr/cname_test.rb", "test/rr/hinfo_test.rb", "test/rr/mr_test.rb", "test/rr/mx_test.rb", "test/rr/ns_test.rb", "test/rr/types_test.rb", "test/rr_test.rb", "test/test_helper.rb"]
20
+
21
+ if s.respond_to? :specification_version then
22
+ s.specification_version = 3
23
+
24
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
25
+ s.add_development_dependency(%q<rake>, ["~> 0.9"])
26
+ s.add_development_dependency(%q<yard>, [">= 0"])
27
+ else
28
+ s.add_dependency(%q<rake>, ["~> 0.9"])
29
+ s.add_dependency(%q<yard>, [">= 0"])
30
+ end
31
+ else
32
+ s.add_dependency(%q<rake>, ["~> 0.9"])
33
+ s.add_dependency(%q<yard>, [">= 0"])
34
+ end
35
+ end
data/setup.rb CHANGED
@@ -256,7 +256,7 @@ class ConfigTable_class
256
256
 
257
257
  end
258
258
 
259
- c = ::Config::CONFIG
259
+ c = Object.const_get(defined?(RbConfig) ? :RbConfig : :Config)::CONFIG
260
260
 
261
261
  rubypath = c['bindir'] + '/' + c['ruby_install_name']
262
262
 
@@ -1245,8 +1245,9 @@ class Installer
1245
1245
  end
1246
1246
 
1247
1247
  def ruby_extentions(dir)
1248
+ c = Object.const_get(defined?(RbConfig) ? :RbConfig : :Config)::CONFIG
1248
1249
  Dir.open(dir) {|d|
1249
- ents = d.select {|fname| /\.#{::Config::CONFIG['DLEXT']}\z/ =~ fname }
1250
+ ents = d.select {|fname| /\.#{c['DLEXT']}\z/ =~ fname }
1250
1251
  if ents.empty?
1251
1252
  setup_rb_error "no ruby extention exists: 'ruby #{$0} setup' first"
1252
1253
  end
@@ -110,58 +110,58 @@ class HeaderTest < Test::Unit::TestCase
110
110
  assert_equal(@binary.nsCount, 3)
111
111
  assert_equal(@binary.arCount, 3)
112
112
 
113
- assert_raise(Header::ArgumentError) do
113
+ assert_raises(ArgumentError) do
114
114
  Header.new(Array.new)
115
115
  end
116
- assert_raise(Header::ArgumentError) do
116
+ assert_raises(ArgumentError) do
117
117
  Header.parse(Array.new)
118
118
  end
119
- assert_raise(Header::ArgumentError) do
119
+ assert_raises(ArgumentError) do
120
120
  Header.parse("aa")
121
121
  end
122
- assert_raise(Header::DuplicateIDError) do
122
+ assert_raises(Header::DuplicateIDError) do
123
123
  @default.id = 441
124
124
  end
125
- assert_raise(Header::ArgumentError) do
125
+ assert_raises(ArgumentError) do
126
126
  @default.id = 1000000
127
127
  end
128
- assert_raise(Header::ArgumentError) do
128
+ assert_raises(ArgumentError) do
129
129
  @default.qr=2
130
130
  end
131
- assert_raise(Header::WrongOpcodeError) do
131
+ assert_raises(Header::WrongOpcodeError) do
132
132
  @default.opCode=4
133
133
  end
134
- assert_raise(Header::ArgumentError) do
134
+ assert_raises(ArgumentError) do
135
135
  @default.aa=2
136
136
  end
137
- assert_raise(Header::ArgumentError) do
137
+ assert_raises(ArgumentError) do
138
138
  @default.tc=2
139
139
  end
140
- assert_raise(Header::WrongRecursiveError) do
140
+ assert_raises(Header::WrongRecursiveError) do
141
141
  @default.recursive=2
142
142
  end
143
- assert_raise(Header::ArgumentError) do
143
+ assert_raises(ArgumentError) do
144
144
  @default.ra=2
145
145
  end
146
- assert_raise(Header::ArgumentError) do
146
+ assert_raises(ArgumentError) do
147
147
  @default.cd=2
148
148
  end
149
- assert_raise(Header::ArgumentError) do
149
+ assert_raises(ArgumentError) do
150
150
  @default.ad=2
151
151
  end
152
- assert_raise(Header::ArgumentError) do
152
+ assert_raises(ArgumentError) do
153
153
  @default.rCode=46
154
154
  end
155
- assert_raise(Header::WrongCountError) do
155
+ assert_raises(Header::WrongCountError) do
156
156
  @default.qdCount=100000
157
157
  end
158
- assert_raise(Header::WrongCountError) do
158
+ assert_raises(Header::WrongCountError) do
159
159
  @default.anCount=100000
160
160
  end
161
- assert_raise(Header::WrongCountError) do
161
+ assert_raises(Header::WrongCountError) do
162
162
  @default.nsCount=100000
163
163
  end
164
- assert_raise(Header::WrongCountError) do
164
+ assert_raises(Header::WrongCountError) do
165
165
  @default.arCount=100000
166
166
  end
167
167
  end