# # file:: mccp2filter.rb # Author:: Craig Smith # $:.unshift "lib" if !$:.include? "lib" $:.unshift "vendor" if !$:.include? "vendor" require 'zlib' require 'network/protocol/filter' require 'network/protocol/telnetcodes' # The MCCP2 Filter - COMPRESS2 Implementation # This needs to be the base filter (Telnet talks to this one) # class Mccp2Filter < Filter include TelnetCodes logger 'DEBUG' # The filter_out method filters output data # [+str+] The string to be processed # [+return+] The filtered data def filter_out(str) return "" if str.nil? || str.empty? return str if not @pstack.terminal if @pstack.mccp2_on log.info "MCCP2 Compression Filter" @pstack.conn.sendmsg(IAC.chr + SB.chr + COMPRESS2.chr + IAC.chr + SE.chr) z = Zlib::Deflate.new(9) str = z.deflate(str, Zlib::FINISH) z.close end str end end