whois 0.8.0 → 0.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. data/CHANGELOG.rdoc +9 -0
  2. data/Manifest +15 -10
  3. data/Rakefile +4 -3
  4. data/lib/whois.rb +3 -3
  5. data/lib/whois/answer.rb +8 -1
  6. data/lib/whois/answer/contact.rb +1 -1
  7. data/lib/whois/answer/parser.rb +22 -3
  8. data/lib/whois/answer/parser/base.rb +38 -1
  9. data/lib/whois/answer/parser/blank.rb +1 -1
  10. data/lib/whois/answer/parser/whois.crsnic.net.rb +1 -1
  11. data/lib/whois/answer/parser/whois.denic.de.rb +15 -6
  12. data/lib/whois/answer/parser/whois.nic.it.rb +1 -1
  13. data/lib/whois/answer/parser/whois.publicinterestregistry.net.rb +1 -1
  14. data/lib/whois/answer/part.rb +1 -1
  15. data/lib/whois/answer/registrar.rb +1 -1
  16. data/lib/whois/answer/super_struct.rb +1 -1
  17. data/lib/whois/client.rb +1 -1
  18. data/lib/whois/errors.rb +1 -1
  19. data/lib/whois/server.rb +1 -1
  20. data/lib/whois/server/adapters/afilias.rb +1 -1
  21. data/lib/whois/server/adapters/arpa.rb +1 -1
  22. data/lib/whois/server/adapters/base.rb +1 -1
  23. data/lib/whois/server/adapters/formatted.rb +1 -1
  24. data/lib/whois/server/adapters/none.rb +1 -1
  25. data/lib/whois/server/adapters/not_implemented.rb +1 -1
  26. data/lib/whois/server/adapters/pir.rb +1 -1
  27. data/lib/whois/server/adapters/standard.rb +1 -1
  28. data/lib/whois/server/adapters/verisign.rb +3 -3
  29. data/lib/whois/server/adapters/web.rb +1 -1
  30. data/lib/whois/version.rb +2 -2
  31. data/lib/whois/whois.rb +1 -1
  32. data/test/answer/parser/base_test.rb +21 -1
  33. data/test/answer/parser/whois_denic_de_test.rb +235 -27
  34. data/test/answer/parser_test.rb +37 -4
  35. data/test/answer_test.rb +9 -4
  36. data/test/server/adapters/verisign_test.rb +16 -2
  37. data/test/testcases/referrals/crsnic.com_more_servers.txt +210 -0
  38. data/test/testcases/referrals/crsnic.com_one_server.txt +57 -0
  39. data/test/testcases/responses/whois.denic.de/1-10-0_available.txt +30 -0
  40. data/test/testcases/responses/whois.denic.de/1-10-0_registered.txt +77 -0
  41. data/test/testcases/responses/whois.denic.de/available.txt +29 -17
  42. data/test/testcases/responses/whois.denic.de/error_invalid_domain_name.txt +37 -0
  43. data/test/testcases/responses/whois.denic.de/registered.txt +50 -57
  44. data/whois.gemspec +6 -6
  45. metadata +27 -22
data/CHANGELOG.rdoc CHANGED
@@ -1,6 +1,15 @@
1
1
  = Changelog
2
2
 
3
3
 
4
+ == Release 0.8.1
5
+
6
+ * FIXED: Updated the whois.denic.de parser to the new format. Thanks to David Krentzlin (closes #314)
7
+
8
+ * FIXED: In case of thin server the client should select the closest whois server match (closes #264)
9
+
10
+ * ADDED: ability to check whether a property is supported via answer.supported? or parser.supported?
11
+
12
+
4
13
  == Release 0.8.0
5
14
 
6
15
  * FIXED: Server definition with :format doesn't use the Formatted adapter (closes #305)
data/Manifest CHANGED
@@ -1,24 +1,29 @@
1
- bin/ruby-whois
2
1
  CHANGELOG.rdoc
2
+ LICENSE.rdoc
3
+ Manifest
4
+ README.rdoc
5
+ Rakefile
6
+ bin/ruby-whois
3
7
  data/ip6_del_list
4
8
  data/ip_del_list
5
9
  data/make_ip6_del.pl
6
10
  data/make_ip_del.pl
7
11
  data/make_tld_serv.pl
8
12
  data/tld_serv_list
13
+ lib/whois.rb
14
+ lib/whois/answer.rb
9
15
  lib/whois/answer/contact.rb
16
+ lib/whois/answer/parser.rb
17
+ lib/whois/answer/parser/README.rdoc
10
18
  lib/whois/answer/parser/base.rb
11
19
  lib/whois/answer/parser/blank.rb
12
- lib/whois/answer/parser/README.rdoc
13
20
  lib/whois/answer/parser/whois.crsnic.net.rb
14
21
  lib/whois/answer/parser/whois.denic.de.rb
15
22
  lib/whois/answer/parser/whois.nic.it.rb
16
23
  lib/whois/answer/parser/whois.publicinterestregistry.net.rb
17
- lib/whois/answer/parser.rb
18
24
  lib/whois/answer/part.rb
19
25
  lib/whois/answer/registrar.rb
20
26
  lib/whois/answer/super_struct.rb
21
- lib/whois/answer.rb
22
27
  lib/whois/client.rb
23
28
  lib/whois/definitions/ipv4.rb
24
29
  lib/whois/definitions/ipv4.txt
@@ -27,6 +32,7 @@ lib/whois/definitions/ipv6.txt
27
32
  lib/whois/definitions/tlds.rb
28
33
  lib/whois/definitions/tlds.txt
29
34
  lib/whois/errors.rb
35
+ lib/whois/server.rb
30
36
  lib/whois/server/adapters/afilias.rb
31
37
  lib/whois/server/adapters/arpa.rb
32
38
  lib/whois/server/adapters/base.rb
@@ -37,14 +43,8 @@ lib/whois/server/adapters/pir.rb
37
43
  lib/whois/server/adapters/standard.rb
38
44
  lib/whois/server/adapters/verisign.rb
39
45
  lib/whois/server/adapters/web.rb
40
- lib/whois/server.rb
41
46
  lib/whois/version.rb
42
47
  lib/whois/whois.rb
43
- lib/whois.rb
44
- LICENSE.rdoc
45
- Manifest
46
- Rakefile
47
- README.rdoc
48
48
  tasks/server.rake
49
49
  test/answer/parser/base_test.rb
50
50
  test/answer/parser/blank_test.rb
@@ -70,12 +70,17 @@ test/server_test.rb
70
70
  test/test_helper.rb
71
71
  test/testcases/referrals/afilias.bz.txt
72
72
  test/testcases/referrals/crsnic.com.txt
73
+ test/testcases/referrals/crsnic.com_more_servers.txt
74
+ test/testcases/referrals/crsnic.com_one_server.txt
73
75
  test/testcases/referrals/niccc.cc.txt
74
76
  test/testcases/referrals/pir.org.txt
75
77
  test/testcases/responses/super_struct_test.rb
76
78
  test/testcases/responses/whois.crsnic.net/available.txt
77
79
  test/testcases/responses/whois.crsnic.net/registered.txt
80
+ test/testcases/responses/whois.denic.de/1-10-0_available.txt
81
+ test/testcases/responses/whois.denic.de/1-10-0_registered.txt
78
82
  test/testcases/responses/whois.denic.de/available.txt
83
+ test/testcases/responses/whois.denic.de/error_invalid_domain_name.txt
79
84
  test/testcases/responses/whois.denic.de/registered.txt
80
85
  test/testcases/responses/whois.nic.it/available.txt
81
86
  test/testcases/responses/whois.nic.it/registered.txt
data/Rakefile CHANGED
@@ -19,12 +19,13 @@ end
19
19
  Echoe.new(PKG_NAME, PKG_VERSION) do |p|
20
20
  p.author = "Simone Carletti"
21
21
  p.email = "weppos@weppos.net"
22
- p.summary = "An intelligent pure Ruby WHOIS client."
22
+ p.summary = "An intelligent pure Ruby WHOIS client and parser."
23
23
  p.url = "http://code.simonecarletti.com/whois"
24
24
  p.project = RUBYFORGE_PROJECT
25
25
  p.description = <<-EOD
26
- Whois is an intelligent WHOIS client written in pure Ruby. \
27
- It enables you to query registry data for ipv4, ipv6 and top level domains.
26
+ Whois is an intelligent WHOIS client and parser written in pure Ruby. \
27
+ It can query registry data for ipv4, ipv6 and top level domains, \
28
+ parse and convert responses into easy-to-use Ruby objects.
28
29
  EOD
29
30
 
30
31
  p.need_zip = true
data/lib/whois.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  #
2
2
  # = Ruby Whois
3
3
  #
4
- # An intelligent pure Ruby WHOIS client.
4
+ # An intelligent pure Ruby WHOIS client and parser.
5
5
  #
6
6
  #
7
7
  # Category:: Net
@@ -63,7 +63,7 @@ module Whois
63
63
  def self.available?(qstring)
64
64
  query(qstring).available?
65
65
  rescue ParserNotFound => e
66
- $stderr.puts "This method is not available for this kind of object.\n" +
66
+ $stderr.puts "This method is not supported for this kind of object.\n" +
67
67
  "Use Whois.query('#{qstring}') instead."
68
68
  nil
69
69
  end
@@ -87,7 +87,7 @@ module Whois
87
87
  def self.registered?(qstring)
88
88
  query(qstring).registered?
89
89
  rescue ParserNotFound => e
90
- $stderr.puts "This method is not available for this kind of object.\n" +
90
+ $stderr.puts "This method is not supported for this kind of object.\n" +
91
91
  "Use Whois.query('#{qstring}') instead."
92
92
  nil
93
93
  end
data/lib/whois/answer.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  #
2
2
  # = Ruby Whois
3
3
  #
4
- # An intelligent pure Ruby WHOIS client.
4
+ # An intelligent pure Ruby WHOIS client and parser.
5
5
  #
6
6
  #
7
7
  # Category:: Net
@@ -109,6 +109,13 @@ module Whois
109
109
  @parser ||= Parser.new(self)
110
110
  end
111
111
 
112
+ # Returns <tt>true</tt> if the <tt>property</tt> passed as symbol
113
+ # is supported by any available parser for this answer.
114
+ # See also <tt>Whois::Answer::Parser.supported?</tt>.
115
+ def supported?(property)
116
+ parser.supported?(property)
117
+ end
118
+
112
119
 
113
120
  protected
114
121
 
@@ -1,7 +1,7 @@
1
1
  #
2
2
  # = Ruby Whois
3
3
  #
4
- # An intelligent pure Ruby WHOIS client.
4
+ # An intelligent pure Ruby WHOIS client and parser.
5
5
  #
6
6
  #
7
7
  # Category:: Net
@@ -1,7 +1,7 @@
1
1
  #
2
2
  # = Ruby Whois
3
3
  #
4
- # An intelligent pure Ruby WHOIS client.
4
+ # An intelligent pure Ruby WHOIS client and parser.
5
5
  #
6
6
  #
7
7
  # Category:: Net
@@ -46,10 +46,20 @@ module Whois
46
46
  @answer = answer
47
47
  end
48
48
 
49
+ # Returns an array with all host-specific parsers initialized for the parts
50
+ # contained into this parser.
51
+ # The array is lazy-initialized.
49
52
  def parsers
50
53
  @parsers ||= init_parsers
51
54
  end
52
55
 
56
+ # Returns <tt>true</tt> if the <tt>property</tt> passed as symbol
57
+ # is supported by any available parser.
58
+ # See also <tt>Whois::Answer::Parser::Base.supported?</tt>.
59
+ def supported?(property)
60
+ parsers.any? { |parser| parser.supported?(property) }
61
+ end
62
+
53
63
 
54
64
  protected
55
65
 
@@ -70,12 +80,21 @@ module Whois
70
80
  # Loops through all answer parts, for each parts tries to guess
71
81
  # the appropriate Whois::Answer::Parser::<parser> if it exists
72
82
  # and returns the final array of server-specific parsers.
83
+ #
84
+ # Parsers are initialized in reverse order for performance reason.
85
+ # See also <tt>select_parser</tt>.
86
+ #
87
+ # parser.parts
88
+ # # => [whois.foo.com, whois.bar.com]
89
+ # parser.parsers
90
+ # # => [parser(whois.bar.com), parser(whois.foo.com)]
91
+ #
73
92
  def init_parsers
74
- answer.parts.map { |part| self.class.parser_for(part) }
93
+ answer.parts.reverse.map { |part| self.class.parser_for(part) }
75
94
  end
76
95
 
77
96
  def select_parser(method)
78
- parsers.reverse.each do |parser|
97
+ parsers.each do |parser|
79
98
  return parser if parser.method_registered?(method)
80
99
  end
81
100
  nil
@@ -1,7 +1,7 @@
1
1
  #
2
2
  # = Ruby Whois
3
3
  #
4
- # An intelligent pure Ruby WHOIS client.
4
+ # An intelligent pure Ruby WHOIS client and parser.
5
5
  #
6
6
  #
7
7
  # Category:: Net
@@ -50,6 +50,43 @@ module Whois
50
50
  end
51
51
  end
52
52
 
53
+ # Returns <tt>true</tt> if the <tt>property</tt> passed as symbol
54
+ # is supported by current parser.
55
+ #
56
+ # parser.supported? :disclaimer
57
+ # # => false
58
+ #
59
+ # parser.register_method(:disclaimer) {}
60
+ # parser.supported? :disclaimer
61
+ # # => true
62
+ #
63
+ # This method is different than <tt>respond_to?</tt>.
64
+ # While <tt>respond_to?</tt> always returns true for any registrable property,
65
+ # including those not effectively implemented,
66
+ # this method only returns <tt>true</tt> if the parser implements <tt>property</tt>.
67
+ # Also, <tt>supported?</tt> returns <tt>false</tt> if <tt>property</tt> exists as a method
68
+ # but it's not a property method.
69
+ #
70
+ # parser.respond_to?(:disclaimer)
71
+ # # => true
72
+ # parser.supported?(:disclaimer)
73
+ # # => false
74
+ #
75
+ # parser.register_method(:disclaimer) {}
76
+ # parser.respond_to?(:disclaimer)
77
+ # # => true
78
+ # parser.supported?(:disclaimer)
79
+ # # => true
80
+ #
81
+ # parser.respond_to?(:contact)
82
+ # # => true
83
+ # parser.supported?(:contact)
84
+ # # => false
85
+ #
86
+ def supported?(property)
87
+ method_registered?(property.to_s.to_sym)
88
+ end
89
+
53
90
 
54
91
  # This is an internal method primaly used as a common access point
55
92
  # to get the content to be parsed as a string.
@@ -1,7 +1,7 @@
1
1
  #
2
2
  # = Ruby Whois
3
3
  #
4
- # An intelligent pure Ruby WHOIS client.
4
+ # An intelligent pure Ruby WHOIS client and parser.
5
5
  #
6
6
  #
7
7
  # Category:: Net
@@ -1,7 +1,7 @@
1
1
  #
2
2
  # = Ruby Whois
3
3
  #
4
- # An intelligent pure Ruby WHOIS client.
4
+ # An intelligent pure Ruby WHOIS client and parser.
5
5
  #
6
6
  #
7
7
  # Category:: Net
@@ -1,12 +1,12 @@
1
1
  #
2
2
  # = Ruby Whois
3
3
  #
4
- # An intelligent pure Ruby WHOIS client.
4
+ # An intelligent pure Ruby WHOIS client and parser.
5
5
  #
6
6
  #
7
7
  # Category:: Net
8
8
  # Package:: Whois
9
- # Author:: Aaron Mueller <mail@aaron-mueller.de>
9
+ # Author:: Aaron Mueller <mail@aaron-mueller.de>, Simone Carletti <weppos@weppos.net>
10
10
  # License:: MIT License
11
11
  #
12
12
  #--
@@ -39,11 +39,11 @@ module Whois
39
39
  end
40
40
 
41
41
  register_method :registered? do
42
- !ast['NotFound']
42
+ !(ast['NotFound'] || ast['Invalid'])
43
43
  end
44
44
 
45
45
  register_method :available? do
46
- ast['NotFound']
46
+ ast['NotFound'] && !ast['Invalid']
47
47
  end
48
48
 
49
49
  register_method :created_on do
@@ -119,6 +119,7 @@ module Whois
119
119
 
120
120
  def parse_content
121
121
  parse_disclaimer ||
122
+ parse_invalid ||
122
123
  parse_not_found ||
123
124
  parse_pair(@ast) ||
124
125
  parse_contact ||
@@ -127,8 +128,8 @@ module Whois
127
128
  end
128
129
 
129
130
  def parse_disclaimer
130
- if @input.match?(/% Copyright \(c\)2008 by DENIC\n/)
131
- 8.times { @input.scan(/%(.*)\n/) } # strip junk
131
+ if @input.match?(/% Copyright \(c\) *\d{4} by DENIC\n/)
132
+ @input.scan_until(/% Terms and Conditions of Use\n/)
132
133
  lines = []
133
134
  while @input.match?(/%/) && @input.scan(/%(.*)\n/)
134
135
  lines << @input[1].strip unless @input[1].strip == ""
@@ -190,6 +191,14 @@ module Whois
190
191
  @ast['NotFound'] = false
191
192
  end
192
193
 
194
+ def parse_invalid
195
+ if @input.match?(/% ".*" is not a valid domain name\n/)
196
+ @input.scan(/%.*\n/)
197
+ return @ast['Invalid'] = true
198
+ end
199
+ @ast['Invalid'] = false
200
+ end
201
+
193
202
  def error(message)
194
203
  raise "#{message}: #{@input.peek(@input.string.length)}"
195
204
  end
@@ -1,7 +1,7 @@
1
1
  #
2
2
  # = Ruby Whois
3
3
  #
4
- # An intelligent pure Ruby WHOIS client.
4
+ # An intelligent pure Ruby WHOIS client and parser.
5
5
  #
6
6
  #
7
7
  # Category:: Net
@@ -1,7 +1,7 @@
1
1
  #
2
2
  # = Ruby Whois
3
3
  #
4
- # An intelligent pure Ruby WHOIS client.
4
+ # An intelligent pure Ruby WHOIS client and parser.
5
5
  #
6
6
  #
7
7
  # Category:: Net
@@ -1,7 +1,7 @@
1
1
  #
2
2
  # = Ruby Whois
3
3
  #
4
- # An intelligent pure Ruby WHOIS client.
4
+ # An intelligent pure Ruby WHOIS client and parser.
5
5
  #
6
6
  #
7
7
  # Category:: Net
@@ -1,7 +1,7 @@
1
1
  #
2
2
  # = Ruby Whois
3
3
  #
4
- # An intelligent pure Ruby WHOIS client.
4
+ # An intelligent pure Ruby WHOIS client and parser.
5
5
  #
6
6
  #
7
7
  # Category:: Net
@@ -1,7 +1,7 @@
1
1
  #
2
2
  # = Ruby Whois
3
3
  #
4
- # An intelligent pure Ruby WHOIS client.
4
+ # An intelligent pure Ruby WHOIS client and parser.
5
5
  #
6
6
  #
7
7
  # Category:: Net
data/lib/whois/client.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  #
2
2
  # = Ruby Whois
3
3
  #
4
- # An intelligent pure Ruby WHOIS client.
4
+ # An intelligent pure Ruby WHOIS client and parser.
5
5
  #
6
6
  #
7
7
  # Category:: Net
data/lib/whois/errors.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  #
2
2
  # = Ruby Whois
3
3
  #
4
- # An intelligent pure Ruby WHOIS client.
4
+ # An intelligent pure Ruby WHOIS client and parser.
5
5
  #
6
6
  #
7
7
  # Category:: Net
data/lib/whois/server.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  #
2
2
  # = Ruby Whois
3
3
  #
4
- # An intelligent pure Ruby WHOIS client.
4
+ # An intelligent pure Ruby WHOIS client and parser.
5
5
  #
6
6
  #
7
7
  # Category:: Net
@@ -1,7 +1,7 @@
1
1
  #
2
2
  # = Ruby Whois
3
3
  #
4
- # An intelligent pure Ruby WHOIS client.
4
+ # An intelligent pure Ruby WHOIS client and parser.
5
5
  #
6
6
  #
7
7
  # Category:: Net