# # file:: mxpfilter.rb # Author:: Craig Smith # $:.unshift "lib" if !$:.include? "lib" $:.unshift "vendor" if !$:.include? "vendor" require 'network/protocol/filter' require 'network/protocol/mxpcodes' # The MxpFilter class implements MXP Protocol # # A Filter can keep state and partial data class MxpFilter < Filter include MXPCodes 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? # Don't interfere with terminal negotiations. So just pass data # if @pstack.terminal has not yet been determined return str if not @pstack.terminal if @pstack.mxp_on newstr = "" intag = false str.each_byte do |c| if intag if c == MXP_ENDc intag = false newstr << ">" else newstr << c end else if c == MXP_BEGc intag = true newstr << "<" elsif c == AMPc # & newstr << "&" elsif c == LTc # < newstr << "<" elsif c == GTc # > newstr << ">" else newstr << c end end end str = newstr else newstr = "" intag = false inamp = false str.each_byte do |c| if intag if c == MXP_ENDc intag = false end elsif inamp if c == 59 inamp = false end else if c == MXP_BEGc intag = true elsif c == MXP_AMPc inamp = true else newstr << c end end end str = newstr end str end end