commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bru...@apache.org
Subject cvs commit: jakarta-commons/net/src/java/org/apache/commons/net/telnet TelnetNotificationHandler.java Telnet.java TelnetClient.java
Date Sun, 10 Aug 2003 09:20:38 GMT
brudav      2003/08/10 02:20:38

  Modified:    net/src/java/org/apache/commons/net/telnet Telnet.java
                        TelnetClient.java
  Added:       net/src/java/org/apache/commons/net/telnet
                        TelnetNotificationHandler.java
  Log:
  Added option negotiation notification interface.
  
  Revision  Changes    Path
  1.7       +56 -0     jakarta-commons/net/src/java/org/apache/commons/net/telnet/Telnet.java
  
  Index: Telnet.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/net/src/java/org/apache/commons/net/telnet/Telnet.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- Telnet.java	8 May 2003 17:15:54 -0000	1.6
  +++ Telnet.java	10 Aug 2003 09:20:38 -0000	1.7
  @@ -163,6 +163,11 @@
        * The stream on which to spy
        ***/
       private OutputStream spyStream = null;
  +
  +    /***
  +     * The notification handler
  +     ***/
  +    private TelnetNotificationHandler __notifhand = null;
       /***
        * Empty Constructor
        ***/
  @@ -451,8 +456,17 @@
               System.err.println("RECEIVED DO: "
                   + TelnetOption.getOption(option));
           }
  +
  +        if (__notifhand != null)
  +        {
  +            __notifhand.receivedNegotiation(
  +                TelnetNotificationHandler.RECEIVED_DO,
  +                option);
  +        }
  +
           boolean acceptNewState = false;
   
  +
           /* open TelnetOptionHandler functionality (start)*/
           if (optionHandlers[option] != null)
           {
  @@ -540,6 +554,12 @@
               System.err.println("RECEIVED DONT: "
                   + TelnetOption.getOption(option));
           }
  +        if (__notifhand != null)
  +        {
  +            __notifhand.receivedNegotiation(
  +                TelnetNotificationHandler.RECEIVED_DONT,
  +                option);
  +        }
           if (_willResponse[option] > 0)
           {
               --_willResponse[option];
  @@ -588,6 +608,14 @@
               System.err.println("RECEIVED WILL: "
                   + TelnetOption.getOption(option));
           }
  +
  +        if (__notifhand != null)
  +        {
  +            __notifhand.receivedNegotiation(
  +                TelnetNotificationHandler.RECEIVED_WILL,
  +                option);
  +        }
  +
           boolean acceptNewState = false;
   
           /* open TelnetOptionHandler functionality (start)*/
  @@ -647,6 +675,14 @@
               System.err.println("RECEIVED WONT: "
                   + TelnetOption.getOption(option));
           }
  +
  +        if (__notifhand != null)
  +        {
  +            __notifhand.receivedNegotiation(
  +                TelnetNotificationHandler.RECEIVED_WONT,
  +                option);
  +        }
  +
           if (_doResponse[option] > 0)
           {
               --_doResponse[option];
  @@ -1313,4 +1349,24 @@
           }
       }
       /* Code Section added for supporting spystreams (end)*/
  +
  +    /***
  +     * Registers a notification handler to which will be sent
  +     * notifications of received telnet option negotiation commands.
  +     * <p>
  +     * @param notifhand - TelnetNotificationHandler to be registered
  +     ***/
  +    public void registerNotifHandler(TelnetNotificationHandler  notifhand)
  +    {
  +        __notifhand = notifhand;
  +    }
  +
  +    /***
  +     * Unregisters the current notification handler.
  +     * <p>
  +     ***/
  +    public void unregisterNotifHandler()
  +    {
  +        __notifhand = null;
  +    }
   }
  
  
  
  1.6       +20 -0     jakarta-commons/net/src/java/org/apache/commons/net/telnet/TelnetClient.java
  
  Index: TelnetClient.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/net/src/java/org/apache/commons/net/telnet/TelnetClient.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- TelnetClient.java	14 Apr 2003 12:53:34 -0000	1.5
  +++ TelnetClient.java	10 Aug 2003 09:20:38 -0000	1.6
  @@ -286,4 +286,24 @@
           super._stopSpyStream();
       }
       /* Code Section added for supporting spystreams (end)*/
  +
  +    /***
  +     * Registers a notification handler to which will be sent
  +     * notifications of received telnet option negotiation commands.
  +     * <p>
  +     * @param notifhand - TelnetNotificationHandler to be registered
  +     ***/
  +    public void registerNotifHandler(TelnetNotificationHandler  notifhand)
  +    {
  +        super.registerNotifHandler(notifhand);
  +    }
  +
  +    /***
  +     * Unregisters the current notification handler.
  +     * <p>
  +     ***/
  +    public void unregisterNotifHandler()
  +    {
  +        super.unregisterNotifHandler();
  +    }
   }
  
  
  
  1.1                  jakarta-commons/net/src/java/org/apache/commons/net/telnet/TelnetNotificationHandler.java
  
  Index: TelnetNotificationHandler.java
  ===================================================================
  package org.apache.commons.net.telnet;
  
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Commons" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  import java.io.BufferedInputStream;
  import java.io.IOException;
  import java.io.InputStream;
  import java.io.OutputStream;
  import org.apache.commons.net.io.FromNetASCIIInputStream;
  import org.apache.commons.net.io.ToNetASCIIOutputStream;
  
  /***
   * The TelnetNotificationHandler interface can be used to handle
   * notification of options negotiation commands received on a telnet
   * session.
   * <p>
   * The user can implement this interface and register a
   * TelnetNotificationHandler by using the registerNotificationHandler()
   * of TelnetClient to be notified of option negotiation commands.
   * <p>
   * <p>
   * @author Bruno D'Avanzo
   ***/
  
  public interface TelnetNotificationHandler
  {
      /***
       * The remote party sent a DO command.
       ***/
      public static final int RECEIVED_DO =   1;
  
      /***
       * The remote party sent a DONT command.
       ***/
      public static final int RECEIVED_DONT = 2;
  
      /***
       * The remote party sent a WILL command.
       ***/
      public static final int RECEIVED_WILL = 3;
  
      /***
       * The remote party sent a WONT command.
       ***/
      public static final int RECEIVED_WONT = 4;
  
      /***
       * Callback method called when TelnetClient receives an option
       * negotiation command.
       * <p>
       * @param negotiation_code - type of negotiation command received
       * (RECEIVED_DO, RECEIVED_DONT, RECEIVED_WILL, RECEIVED_WONT)
       * <p>
       * @param option_code - code of the option negotiated
       * <p>
       ***/
      public void receivedNegotiation(int negotiation_code, int option_code);
  }
  
  
  

Mime
View raw message