java.lang.Object
net.i2p.i2ptunnel.irc.IRCFilter

abstract class IRCFilterextends Object
Static methods to filter individual lines. Moved from I2PTunnelIRCClient.java.
  • Field Details

    • ALLOW_ALL_DCC_IN

      private static final boolean ALLOW_ALL_DCC_IN
      Whether inbound DCC connections are allowed at all.
      See Also:
    • ALLOW_ALL_CTCP_IN

      private static final boolean ALLOW_ALL_CTCP_IN
      Does not override DCC handling.
      See Also:
    • ALLOW_ALL_CTCP_OUT

      private static final boolean ALLOW_ALL_CTCP_OUT
      Does not override DCC handling.
      See Also:
    • _allowedInbound

      private static final Set<String> _allowedInbound
      Commands accepted from the remote side.
    • _allowedOutbound

      private static final Set<String> _allowedOutbound
      Commands accepted from the local side.
  • Constructor Details

    • IRCFilter

      IRCFilter()
      Constructor for subclasses; the line filters in this base class are static.
  • Method Details

    • inboundFilter

      public static String inboundFilter(String s, StringBuffer expectedPong, DCCHelper helper)
      Modify or filter a single inbound line.
      Parameters:
      s - the single inbound line to filter, without its trailing newline
      expectedPong - holds the PONG token a three field PING expects back; reset on use
      helper - may be null
      Returns:
      the original or modified line, or null if it should be dropped.
    • outboundFilter

      public static String outboundFilter(String s, StringBuffer expectedPong, DCCHelper helper)
      Modify or filter a single outbound line.
      Parameters:
      s - the single outbound line to filter, without its trailing newline
      expectedPong - cleared, then filled by filterPing with the PONG a 3-field PING expects
      helper - may be null
      Returns:
      the original or modified line, or null if it should be dropped.
    • filterPing

      private static String filterPing(String[] field, int idx, StringBuffer expectedPong)
      Rewrite a PING so the server replies to a nonce we remember. Rewriting avoids sending our proxy's IP address in the PONG.
      Parameters:
      field - the split line
      idx - index of the command in field
      expectedPong - filled with the expected PONG for a 3-field PING
      Returns:
      the rewritten line, or null if it should be dropped
    • filterPrivmsgOrNotice

      private static String filterPrivmsgOrNotice(String s, String[] field, int idx, DCCHelper helper)
      Allow PRIVMSG/NOTICE, blocking CTCP (except ACTION, DCC, and XDCC).
      Parameters:
      s - the original line
      field - the split line
      idx - index of the command in field
      helper - may be null
      Returns:
      the original or rewritten line, or null if it should be dropped
    • filterUser

      private static String filterUser(String s, String[] field, int idx)
      Sanitize a USER line, replacing hostname and servername.
      Parameters:
      s - the original line
      field - the split line
      idx - index of the command in field
      Returns:
      the rewritten line
    • filterDCCIn

      private static String filterDCCIn(String pfx, String msg, DCCHelper helper)
       DCC CHAT chat xxx.b32.i2p i2p-port        -> DCC CHAT chat IP port
       DCC SEND file xxx.b32.i2p i2p-port length -> DCC SEND file IP port length
       DCC RESUME file i2p-port offset           -> DCC RESUME file port offset
       DCC ACCEPT file i2p-port offset           -> DCC ACCEPT file port offset
       DCC xxx                                   -> null.
      
      Parameters:
      pfx - the message through the "DCC " part
      msg - the message after the "DCC " part
      helper - may be null
      Returns:
      the sanitized message or null to block
    • filterDCCOut

      private static String filterDCCOut(String pfx, String msg, DCCHelper helper)
       DCC CHAT chat IP port        -> DCC CHAT chat xxx.b32.i2p i2p-port
       DCC SEND file IP port length -> DCC SEND file xxx.b32.i2p i2p-port length
       DCC RESUME file port offset  -> DCC RESUME file i2p-port offset
       DCC ACCEPT file port offset  -> DCC ACCEPT file i2p-port offset
       DCC xxx                      -> null.
      
      Parameters:
      pfx - the message through the "DCC " part
      msg - the message after the "DCC " part
      helper - may be null
      Returns:
      the sanitized message or null to block