require 'iounpack' require 'stringio' require_relative 'errors' module Knot class Protocol end end module Knot::Protocol::Type def [] code case code when 0, End then return End when 1, Data then return Data when 2, Extra then return Extra when 3, Block then return Block end end class Base def self.expect_data? false end def expect_data?() self.class.expect_data? end def code() self.class.code end end class End < Base def self.code() 0 end end class Data < Base def code() 1 end def expect_data? true end attr_reader :data def initialize data @data = data end end class Extra < Base def code() 2 end def expect_data? true end attr_reader :data def initialize data @data = data end end class Block < Base def code() 3 end end end #class Knot::KnotC # attr_accessor :debug, :binary # # def initialize path = nil, binary: nil # @path = path # @binary = binary || 'knotc' # @conf = Knot::Conf.new self # @zones = Hash.new {|h, zone| h[zone] = Knot::Zone.new zone, self } # end # # def call command:, flags: nil, section: nil, item: nil, id: nil, zone: nil, owner: nil, ttl: nil, type: nil, data: nil, filter: nil # cs = # case command.to_s # when 'conf-begin', 'conf-commit', 'conf-abort', 'status', 'stop', 'reload' # [@binary, command, ] # else raise ArgumentError, "Unknown Command: #{command}" # end # end #end module Knot::Protocol::Idx class Id include Comparable attr_reader :name, :code, :cname, :description def initialize name, code, cname, description raise ArgumentError, "Expecting Symbol for Idx::Id instead of: #{name.inspect}" if Symbol === name raise ArgumentError, "Expecting Integer for Idx::Id instead of: #{code.inspect}" if Integer === code @name, @code, @cname, @description = name, code, cname, description freeze end def === x case x when self.class then self == x when Symbol then @name == x when String then @name == x.to_sym when Integer then @code == x else nil end end def <=>( x) @id <=> x.id end def to_s() @name.to_s end def to_sym() @name end def to_i() @code end end Idx = [ Id.new( :command, 0x10, :CMD, 'Control command name.'), Id.new( :flags, 0x11, :FLAGS, 'Control command flags.'), Id.new( :error, 0x12, :ERROR, 'Error message.'), Id.new( :section, 0x13, :SECTION, 'Configuration section name.'), Id.new( :item, 0x14, :ITEM, 'Configuration item name.'), Id.new( :id, 0x15, :ID, 'Congiguration item identifier.'), Id.new( :zone, 0x16, :ZONE, 'Zone name.'), Id.new( :owner, 0x17, :OWNER, 'Zone record owner'), Id.new( :ttl, 0x18, :TTL, 'Zone record TTL.'), Id.new( :type, 0x19, :TYPE, 'Zone record type name.'), Id.new( :data, 0x1a, :DATA, 'Configuration item/zone record data.'), Id.new( :filter, 0x1b, :FILTER, 'An option or a filter for output data processing.'), ] Name = {} Code = {} Idx.each do |id| Code[id.to_i] = id Name[id.to_sym] = id end class <