class ProtocolStack

The ProtocolStack class implements a stack of input and output filters. It also maintains some interesting state variables that are shared amongst filters.

Remarks

This should have its own configuration file.

Attributes

binary_on[RW]
color_on[RW]
conn[R]
echo_on[RW]
eorec_on[RW]
hide_on[RW]
terminal[RW]
theight[RW]
twidth[RW]
urgent_on[RW]
zmp_on[RW]

Public Class Methods

new(conn) click to toggle source

Construct a ProtocolStack

conn

The connection associated with this filter

# File lib/network/protocol/protocolstack.rb, line 38
def initialize(conn)
  @conn = conn
  @server = @conn.server
  @filters = []  # Filter order is critical as lowest level protocol is first.
  if @server.service_filters.include? :debugfilter
    @filters << DebugFilter.new(self)
  end
  if @server.service_filters.include? :telnetfilter
    @filters << TelnetFilter.new(self,@server)
  end
  if @server.service_filters.include? :terminalfilter
    @filters << TerminalFilter.new(self)
  end
  if @server.service_filters.include? :colorfilter
    @filters << ColorFilter.new(self)
  end
  if @server.service_filters.include? :filter
    @filters << Filter.new(self)
  end

  # Shared variables to facilitate inter-filter communication.
  @sga_on = false
  @echo_on = false
  @binary_on = false
  @zmp_on = false
  @eorec_on = false
  @color_on = false
  @urgent_on = false
  @hide_on = false
  @terminal = nil
  @twidth = 80
  @theight = 23
end

Public Instance Methods

filter_call(method, args) click to toggle source

A method is called on each filter in the stack in order.

method
args
# File lib/network/protocol/protocolstack.rb, line 76
def filter_call(method, args)
  case method
  when :filter_in, :init
    retval = args
    @filters.each do |v|
      retval = v.send(method,retval)
    end
  when :filter_out
    retval = args
    @filters.reverse_each do |v|
      retval = v.send(method,retval)
    end
  else
    log.error "(#{self.object_id}) ProtocolStack#filter_call unknown method '#{method}',a:#{args.inspect},r:#{retval.inspect}"
  end
  retval
end
query(attr) click to toggle source

The filter_query method returns state information for the filter.

attr

A symbol representing the attribute being queried.

return

An attr/value pair or false if not defined in this filter

# File lib/network/protocol/protocolstack.rb, line 97
def query(attr)
  case attr
  when :terminal
    retval =  @terminal
  when :termsize
    retval =  [@twidth, @theight]
  when :color
    retval =  @color_on
  when :zmp
    retval =  @zmp_on
  when :echo
    retval =  @echo_on
  when :binary
    retval =  @binary_on
  when :eorec
    retval =  @eorec_on
  when :urgent
    retval =  @urgent_on
  when :hide
    retval =  @hide_on
  when :ip
    retval =  @conn.addr
  when :host
    retval =  @conn.host
  else
    log.error "(#{self.object_id}) ProtocolStack#query unknown setting '#{pair.inspect}'"
    retval = false
  end
  log.debug "(#{self.object_id}) ProtocolStack#query called '#{attr}',r:#{retval.inspect}"
  retval
end
set(attr, value) click to toggle source

The filter_set method sets state information on the filter.

pair

An attr/value pair [:symbol, value]

return

true if attr not defined in this filter, false if not

# File lib/network/protocol/protocolstack.rb, line 132
def set(attr, value)
  case attr
  when :color
    @color_on = value
    true
  when :urgent
    @urgent_on = value
    true
  when :hide
    @hide_on = value
    true
  when :terminal
    @terminal = value
    true
  when :termsize
    @twidth = value[0]
    @theight = value[1]
    # telnet filter always first except when debugfilter on
    if @server.service_filters.include? :telnetfilter
      if @server.service_filters.include? :debugfilter
        @filters[1].send_naws
      else
        @filters[0].send_naws
      end
    end
    true
  when :init_subneg
    # telnet filter always first except when debugfilter on
    if @server.service_filters.include? :telnetfilter
      if @server.service_filters.include? :debugfilter
        @filters[1].init_subneg
      else
        @filters[0].init_subneg
      end
    end
    true
  else
    log.error "(#{self.object_id}) ProtocolStack#set unknown setting '#{attr}=#{value}'"
    false
  end
  log.debug "(#{self.object_id}) ProtocolStack#set called '#{attr}=#{value}'"
end