lib/net/dns/header.rb in net-dns-0.5.3 vs lib/net/dns/header.rb in net-dns-0.6.0
- old
+ new
@@ -1,10 +1,7 @@
-#---
-# $Id: Header.rb,v 1.5 2006/07/30 16:54:28 bluemonk Exp $
-#+++
+require 'net/dns'
-require 'net/dns/dns'
module Net # :nodoc:
module DNS
#
@@ -55,27 +52,52 @@
#
# Some error classes has been defined for the Net::DNS::Header class,
# which are listed here to keep a light and browsable main documentation.
# We have:
#
- # * HeaderArgumentError: canonical argument error
- # * HeaderWrongCount: a wrong +count+ parameter has been passed
- # * HeaderWrongRecursive: a wrong +recursive+ parameter has been passed
- # * HeaderWrongOpcode: a not valid +opCode+ has been specified
- # * HeaderDuplicateID: the requested ID is already in use
+ # ArgumentError:: Argument Error for class Net::DNS::Packet
+ # WrongCountError:: A wrong +count+ parameter has been passed
+ # WrongRecursiveError:: A wrong +recursive+ parameter has been passed
+ # WrongOpcodeError:: A not valid +opCode+ has been specified
+ # DuplicateIDError:: The requested ID is already in use
#
# =Copyright
#
# Copyright (c) 2006 Marco Ceresa
#
# All rights reserved. This program is free software; you may redistribute
# it and/or modify it under the same terms as Ruby itself.
#
class Header
-
+
+ # Argument Error for class Net::DNS::Header.
+ class ArgumentError < ArgumentError
+ end
+
+ # A wrong +count+ parameter has been passed-
+ class WrongCountError < ArgumentError
+ end
+
+ # A wrong +recursive+ parameter has been passed-
+ class WrongRecursiveError < ArgumentError
+ end
+
+ # An invalid +opCode+ has been specified.
+ class WrongOpcodeError < ArgumentError
+ end
+
+ # Base error class.
+ class Error < StandardError
+ end
+
+ # The requested ID is already in use.
+ class DuplicateIDError < Error
+ end
+
+
#
- # =Name
+ # = Name
#
# Net::DNS::Header::RCode - DNS Header RCode handling class
#
# =Synopsis
#
@@ -98,11 +120,11 @@
# * 2 Server failure - The name server was
# unable to process this query due to a
# problem with the name server.
# * 3 Name Error - Meaningful only for
# responses from an authoritative name
- # server, this code signifies that the
+ # server, this code means that the
# domain name referenced in the query does
# not exist.
# * 4 Not Implemented - The name server does
# not support the requested kind of query.
# * 5 Refused - The name server refuses to
@@ -164,11 +186,11 @@
if (0..10).include? code
@code = code
@type = RCodeType[code]
@explanation = RCodeErrorString[code]
else
- raise HeaderArgumentError, "RCode #{code} out of range"
+ raise ArgumentError, "RCode `#{code}' out of range"
end
end
def to_s
@code.to_s
@@ -238,11 +260,11 @@
#
def initialize(arg = {})
if arg.kind_of? Hash
new_from_hash(arg)
else
- raise HeaderArgumentError, "Wrong argument class: #{arg.class}"
+ raise ArgumentError, "Wrong argument class `#{arg.class}'"
end
end
# Creates a new Net::DNS::Header object from binary data, which is
# passed as a string object as argument.
@@ -260,11 +282,11 @@
if arg.kind_of? String
o = allocate
o.send(:new_from_binary, arg)
o
else
- raise HeaderArgumentError, "Wrong argument class: #{arg.class}"
+ raise ArgumentError, "Wrong argument class `#{arg.class}'"
end
end
# Inspect method, prints out all the options and relative values.
#
@@ -360,17 +382,17 @@
# Set the ID for the current header. Useful when
# performing security tests.
#
def id=(val)
if @@id_arr.include? val
- raise HeaderDuplicateID, "ID #{val} already used"
+ raise DuplicateIDError, "ID `#{val}' already used"
end
if (1..65535).include? val
@id = val
@@id_arr.push val
else
- raise HeaderArgumentError, "ID #{val} out of range"
+ raise ArgumentError, "ID `#{val}' out of range"
end
end
# Checks whether the header is a query (+qr+ bit set to 0)
#
@@ -391,11 +413,11 @@
when false
@qr = 0
when 0,1
@qr = val
else
- raise HeaderArgumentError, ":qr must be true(or 1) or false(or 0)"
+ raise ArgumentError, ":qr must be true(or 1) or false(or 0)"
end
end
# Checks whether the header is a response
# (+qr+ bit set to 1)
@@ -429,11 +451,11 @@
#
def opCode=(val)
if (0..2).include? val
@opCode = val
else
- raise HeaderWrongOpcode, "Wrong opCode value (#{val}), must be QUERY, IQUERY or STATUS"
+ raise WrongOpcodeError, "Wrong opCode value (#{val}), must be QUERY, IQUERY or STATUS"
end
end
# Checks whether the response is authoritative
#
@@ -463,11 +485,11 @@
when false
@aa = 0
when 0,1
@aa = val
else
- raise HeaderArgumentError, ":aa must be true(or 1) or false(or 0)"
+ raise ArgumentError, ":aa must be true(or 1) or false(or 0)"
end
end
# Checks whether the packet was truncated
#
@@ -501,11 +523,11 @@
when false
@tc = 0
when 0,1
@tc = val
else
- raise HeaderArgumentError, ":tc must be true(or 1) or false(or 0)"
+ raise ArgumentError, ":tc must be true(or 1) or false(or 0)"
end
end
# Checks whether the packet has a recursion bit
# set, meaning that recursion is desired
@@ -533,11 +555,11 @@
when 1
@rd = 1
when 0
@rd = 0
else
- raise HeaderWrongRecursive, "Wrong value (#{val}), please specify true (1) or false (0)"
+ raise WrongRecursiveError, "Wrong value (#{val}), please specify true (1) or false (0)"
end
end
# Alias for Header#recursive= to keep compatibility
# with the Perl version.
@@ -566,11 +588,11 @@
when false
@ra = 0
when 0,1
@ra = val
else
- raise HeaderArgumentError, ":ra must be true(or 1) or false(or 0)"
+ raise ArgumentError, ":ra must be true(or 1) or false(or 0)"
end
end
# Checks whether checking is enabled or disabled.
#
@@ -590,11 +612,11 @@
when false
@cd = 0
when 0,1
@cd = val
else
- raise HeaderArgumentError, ":cd must be true(or 1) or false(or 0)"
+ raise ArgumentError, ":cd must be true(or 1) or false(or 0)"
end
end
# Checks whether +ad+ flag has been set.
#
@@ -618,11 +640,11 @@
when false
@ad = 0
when 0,1
@ad = val
else
- raise HeaderArgumentError, ":ad must be true(or 1) or false(or 0)"
+ raise ArgumentError, ":ad must be true(or 1) or false(or 0)"
end
end
# Returns an error array for the header response code, or
# +nil+ if no error is generated.
@@ -657,41 +679,41 @@
#
def qdCount=(val)
if (0..65535).include? val
@qdCount = val
else
- raise HeaderWrongCount, "Wrong number of count (#{val}), must be 0-65535"
+ raise WrongCountError, "Wrong number of count (#{val}), must be 0-65535"
end
end
# Sets the number of RRs in an answer section
#
def anCount=(val)
if (0..65535).include? val
@anCount = val
else
- raise HeaderWrongCount, "Wrong number of count (#{val}), must be 0-65535"
+ raise WrongCountError, "Wrong number of count (#{val}), must be 0-65535"
end
end
# Sets the number of RRs in an authority section
#
def nsCount=(val)
if (0..65535).include? val
@nsCount = val
else
- raise HeaderWrongCount, "Wrong number of count (#{val}), must be 0-65535"
+ raise WrongCountError, "Wrong number of count (#{val}), must be 0-65535"
end
end
# Sets the number of RRs in an addictional section
#
def arCount=(val)
if (0..65535).include? val
@arCount = val
else
- raise HeaderWrongCount, "Wrong number of count (#{val}), must be 0-65535"
+ raise WrongCountError, "Wrong number of count: `#{val}' must be 0-65535"
end
end
private
@@ -704,11 +726,11 @@
@opCode = QUERY # standard query, default message
end
def new_from_binary(str)
unless str.size == Net::DNS::HFIXEDSZ
- raise HeaderArgumentError, "Header binary data has wrong size: #{str.size} bytes"
+ raise ArgumentError, "Header binary data has wrong size: `#{str.size}' bytes"
end
arr = str.unpack("n C2 n4")
@id = arr[0]
@qr = (arr[1] >> 7) & 0x01
@opCode = (arr[1] >> 3) & 0x0F
@@ -737,25 +759,9 @@
end
@@id_arr.push(q)
q
end
- end # class Header
+ end
- end # class DNS
-end # module Net
-
-
-class HeaderArgumentError < ArgumentError # :nodoc: all
-end
-
-class HeaderWrongCount < ArgumentError # :nodoc: all
-end
-
-class HeaderWrongRecursive < ArgumentError # :nodoc: all
-end
-
-class HeaderWrongOpcode < ArgumentError # :nodoc: all
-end
-
-class HeaderDuplicateID < ArgumentError # :nodoc: all
-end
+ end
+end
\ No newline at end of file