redns 0.1.15 → 0.1.16

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -5,6 +5,13 @@ Reactor-Ready DNS Library
5
5
  This library includes native Ruby encoder/decoder classes for typical
6
6
  DNS records that are specified in RFC1035.
7
7
 
8
+ In addition, RFC2671 extension mechanisms are also supported.
9
+
8
10
  == References
9
11
 
10
12
  [RFC1035](http://www.faqs.org/rfcs/rfc1035.html)
13
+ [RFC2671](http://www.faqs.org/rfcs/rfc2671.html)
14
+
15
+ == Copyright
16
+
17
+ (C) 2005-2012 Scott Tadman
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.15
1
+ 0.1.16
data/bin/redig ADDED
@@ -0,0 +1,49 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $LOAD_PATH << File.expand_path(File.join('..','lib'), File.dirname(__FILE__))
4
+
5
+ require 'optparse'
6
+
7
+ require 'redns'
8
+
9
+ # == Main ===================================================================
10
+
11
+ options = {
12
+ :query_type => :any,
13
+ }
14
+
15
+ op = OptionParser.new do |op|
16
+ op.on("-t", "--type=s") do |type|
17
+ options[:query_type] = type.to_sym
18
+ end
19
+ end
20
+
21
+ # Look for command-line arguments prefixed with '@' and push these into the
22
+ # options for nameservers.
23
+ queries = op.parse(*ARGV).select do |query|
24
+ case (query)
25
+ when /^@(.*)/
26
+ (options[:nameservers] ||= [ ]) << $1
27
+ false
28
+ else
29
+ true
30
+ end
31
+ end
32
+
33
+ resolver = ReDNS::Resolver.new do |resolver|
34
+ if (options[:nameservers])
35
+ resolver.servers = options[:nameservers]
36
+ end
37
+ end
38
+
39
+ queries.each do |query|
40
+ results = resolver.simple_query(options[:query_type], query)
41
+
42
+ if (results)
43
+ results.each do |result|
44
+ puts result.to_s
45
+ end
46
+ else
47
+ puts "No results"
48
+ end
49
+ end
data/lib/redns/buffer.rb CHANGED
@@ -3,7 +3,7 @@ class ReDNS::Buffer < String
3
3
 
4
4
  # == Properties ===========================================================
5
5
 
6
- alias_method :total_length, :length
6
+ alias_method :string_length, :length
7
7
  alias_method :total_size, :size
8
8
 
9
9
  attr_reader :offset
@@ -24,23 +24,27 @@ class ReDNS::Buffer < String
24
24
  super('')
25
25
 
26
26
  @offset = 0
27
- @size = total_length
27
+ @size = string_length
28
28
 
29
29
  contents.serialize(self)
30
30
  else
31
31
  super(contents || '')
32
32
 
33
33
  @offset = offset ? offset.to_i : 0
34
- @size = size ? size.to_i : total_length
34
+ @size = size ? size.to_i : string_length
35
35
  end
36
36
 
37
37
  advance(0)
38
38
  end
39
39
 
40
+ def empty?
41
+ @offset >= string_length
42
+ end
43
+
40
44
  def unpack(format)
41
45
  return [ ] if (@size <= 0)
42
46
 
43
- return if (@offset > total_length)
47
+ return if (@offset > string_length)
44
48
 
45
49
  data = to_s.unpack(format)
46
50
  advance(data.pack(format).length)
@@ -55,7 +59,7 @@ class ReDNS::Buffer < String
55
59
  end
56
60
 
57
61
  def slice(chars = 1)
58
- return if (@offset + chars > total_length)
62
+ return if (@offset + chars > string_length)
59
63
 
60
64
  result = to_str[@offset, chars]
61
65
  advance(chars)
@@ -64,7 +68,7 @@ class ReDNS::Buffer < String
64
68
  end
65
69
 
66
70
  def read(chars = 1)
67
- return if (@offset + chars > total_length)
71
+ return if (@offset + chars > string_length)
68
72
 
69
73
  result = to_str[@offset, chars]
70
74
  advance(chars)
@@ -95,18 +99,18 @@ class ReDNS::Buffer < String
95
99
  else
96
100
  @offset += chars
97
101
 
98
- if (@offset > total_length)
99
- @offset = total_length
102
+ if (@offset > string_length)
103
+ @offset = string_length
100
104
  end
101
105
 
102
- max_length = (total_length - @offset)
106
+ max_length = (string_length - @offset)
103
107
 
104
108
  if (!@size or @size > max_length)
105
109
  @size = max_length
106
110
  end
107
111
  end
108
112
 
109
- @size ||= total_length - @offset
113
+ @size ||= string_length - @offset
110
114
 
111
115
  self
112
116
  end
@@ -24,8 +24,12 @@ class ReDNS::Record::Null < ReDNS::Fragment
24
24
  end
25
25
 
26
26
  def deserialize(buffer)
27
- if (content_length = buffer.unpack('C')[0])
28
- self.contents = buffer.read(content_length)
27
+ self.contents = ''
28
+
29
+ while (!buffer.empty?)
30
+ if (content_length = buffer.unpack('C')[0])
31
+ self.contents << buffer.unpack("a#{content_length}")[0]
32
+ end
29
33
  end
30
34
 
31
35
  self
@@ -0,0 +1,2 @@
1
+ class ReDNS::Record::SPF < ReDNS::Record::Txt
2
+ end
@@ -0,0 +1,2 @@
1
+ class ReDNS::Record::TXT < ReDNS::Record::Null
2
+ end
data/lib/redns/record.rb CHANGED
@@ -4,4 +4,6 @@ class ReDNS::Record < ReDNS::Fragment
4
4
  autoload(:MX, 'redns/record/mx')
5
5
  autoload(:Null, 'redns/record/null')
6
6
  autoload(:SOA, 'redns/record/soa')
7
+ autoload(:SPF, 'redns/record/spf')
8
+ autoload(:TXT, 'redns/record/txt')
7
9
  end
@@ -216,6 +216,7 @@ class ReDNS::Resolver
216
216
 
217
217
  protected
218
218
  def expand_answers(r)
219
+
219
220
  unless (r and r.answers)
220
221
  return nil
221
222
  end
@@ -223,7 +224,16 @@ protected
223
224
  result = r.answers
224
225
  radd = (r.additional_records or [ ])
225
226
 
226
- result.reject { |rr| rr.rtype == :a }.each do |rr|
227
+ result.select do |rr|
228
+ case (rr.rtype)
229
+ when :ns
230
+ # These record types require further investigation if they are to
231
+ # be included in the result-set.
232
+ true
233
+ else
234
+ false
235
+ end
236
+ end.each do |rr|
227
237
  # Additional resource records may be related to the query, or they
228
238
  # might just be convenience records that are not directly helpful.
229
239
 
@@ -68,12 +68,16 @@ class ReDNS::Resource < ReDNS::Fragment
68
68
  self.rdata = ReDNS::Address.new(buffer)
69
69
  when :cname, :ptr, :ns
70
70
  self.rdata = ReDNS::Name.new(buffer)
71
+ when :mx
72
+ self.rdata = ReDNS::Record::MX.new(buffer)
71
73
  when :soa
72
74
  self.rdata = ReDNS::Record::SOA.new(buffer)
73
- when :txt, :null
75
+ when :null
74
76
  self.rdata = (rdata_length and ReDNS::Record::Null.new(buffer.slice(rdata_length)))
75
- when :mx
76
- self.rdata = ReDNS::Record::MX.new(buffer)
77
+ when :spf
78
+ self.rdata = (rdata_length and ReDNS::Record::SPF.new(buffer.slice(rdata_length)))
79
+ when :txt
80
+ self.rdata = (rdata_length and ReDNS::Record::TXT.new(buffer.slice(rdata_length)))
77
81
  else
78
82
  # FUTURE: Throw exception here when trying to decode invalid type
79
83
  nil
data/redns.gemspec CHANGED
@@ -4,14 +4,15 @@
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
- s.name = %q{redns}
8
- s.version = "0.1.15"
7
+ s.name = "redns"
8
+ s.version = "0.1.16"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = [%q{tadman}]
12
- s.date = %q{2011-08-10}
13
- s.description = %q{ReDNS is a pure Ruby DNS library with drivers for reactor-model engines such as EventMachine}
14
- s.email = %q{github@tadman.ca}
11
+ s.authors = ["tadman"]
12
+ s.date = "2012-02-13"
13
+ s.description = "ReDNS is a pure Ruby DNS library with drivers for reactor-model engines such as EventMachine"
14
+ s.email = "github@tadman.ca"
15
+ s.executables = ["redig"]
15
16
  s.extra_rdoc_files = [
16
17
  "README.rdoc"
17
18
  ]
@@ -20,6 +21,7 @@ Gem::Specification.new do |s|
20
21
  "README.rdoc",
21
22
  "Rakefile",
22
23
  "VERSION",
24
+ "bin/redig",
23
25
  "lib/redns.rb",
24
26
  "lib/redns/address.rb",
25
27
  "lib/redns/buffer.rb",
@@ -32,6 +34,8 @@ Gem::Specification.new do |s|
32
34
  "lib/redns/record/mx.rb",
33
35
  "lib/redns/record/null.rb",
34
36
  "lib/redns/record/soa.rb",
37
+ "lib/redns/record/spf.rb",
38
+ "lib/redns/record/txt.rb",
35
39
  "lib/redns/resolver.rb",
36
40
  "lib/redns/resource.rb",
37
41
  "lib/redns/support.rb",
@@ -49,10 +53,10 @@ Gem::Specification.new do |s|
49
53
  "test/test_redns_resource.rb",
50
54
  "test/test_redns_support.rb"
51
55
  ]
52
- s.homepage = %q{http://github.com/tadman/redns}
53
- s.require_paths = [%q{lib}]
54
- s.rubygems_version = %q{1.8.7}
55
- s.summary = %q{Ruby Reactor-Ready DNS Library}
56
+ s.homepage = "http://github.com/tadman/redns"
57
+ s.require_paths = ["lib"]
58
+ s.rubygems_version = "1.8.11"
59
+ s.summary = "Ruby Reactor-Ready DNS Library"
56
60
 
57
61
  if s.respond_to? :specification_version then
58
62
  s.specification_version = 3
@@ -13,6 +13,25 @@ class TestReDNSBuffer < Test::Unit::TestCase
13
13
 
14
14
  assert_equal nil, buffer.read
15
15
  end
16
+
17
+ def test_empty_state
18
+ buffer = ReDNS::Buffer.new('test')
19
+
20
+ assert_equal false, buffer.empty?
21
+
22
+ buffer.unpack('C4')
23
+
24
+ assert_equal true, buffer.empty?
25
+
26
+ assert_equal 4, buffer.offset
27
+
28
+ buffer.append('test')
29
+
30
+ assert_equal 4, buffer.offset
31
+ assert_equal 4, buffer.length
32
+
33
+ assert_equal false, buffer.empty?
34
+ end
16
35
 
17
36
  def test_simple_duplicate
18
37
  buffer = ReDNS::Buffer.new('example'.freeze, 1, 3)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redns
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.15
4
+ version: 0.1.16
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,12 +9,13 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-08-10 00:00:00.000000000Z
12
+ date: 2012-02-13 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: ReDNS is a pure Ruby DNS library with drivers for reactor-model engines
15
15
  such as EventMachine
16
16
  email: github@tadman.ca
17
- executables: []
17
+ executables:
18
+ - redig
18
19
  extensions: []
19
20
  extra_rdoc_files:
20
21
  - README.rdoc
@@ -23,6 +24,7 @@ files:
23
24
  - README.rdoc
24
25
  - Rakefile
25
26
  - VERSION
27
+ - bin/redig
26
28
  - lib/redns.rb
27
29
  - lib/redns/address.rb
28
30
  - lib/redns/buffer.rb
@@ -35,6 +37,8 @@ files:
35
37
  - lib/redns/record/mx.rb
36
38
  - lib/redns/record/null.rb
37
39
  - lib/redns/record/soa.rb
40
+ - lib/redns/record/spf.rb
41
+ - lib/redns/record/txt.rb
38
42
  - lib/redns/resolver.rb
39
43
  - lib/redns/resource.rb
40
44
  - lib/redns/support.rb
@@ -71,7 +75,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
71
75
  version: '0'
72
76
  requirements: []
73
77
  rubyforge_project:
74
- rubygems_version: 1.8.7
78
+ rubygems_version: 1.8.11
75
79
  signing_key:
76
80
  specification_version: 3
77
81
  summary: Ruby Reactor-Ready DNS Library