Methods Summary |
---|
protected void | _connectAction_()Called upon connection.
/* (start). BUGFIX: clean the option info for each connection*/
for (int ii = 0; ii < TelnetOption.MAX_OPTION_VALUE + 1; ii++)
{
_doResponse[ii] = 0;
_willResponse[ii] = 0;
_options[ii] = 0;
if (optionHandlers[ii] != null)
{
optionHandlers[ii].setDo(false);
optionHandlers[ii].setWill(false);
}
}
/* (end). BUGFIX: clean the option info for each connection*/
super._connectAction_();
_input_ = new BufferedInputStream(_input_);
_output_ = new BufferedOutputStream(_output_);
/* open TelnetOptionHandler functionality (start)*/
for (int ii = 0; ii < TelnetOption.MAX_OPTION_VALUE + 1; ii++)
{
if (optionHandlers[ii] != null)
{
if (optionHandlers[ii].getInitLocal())
{
try
{
_requestWill(optionHandlers[ii].getOptionCode());
}
catch (IOException e)
{
System.err.println(
"Exception while initializing option: "
+ e.getMessage());
}
}
if (optionHandlers[ii].getInitRemote())
{
try
{
_requestDo(optionHandlers[ii].getOptionCode());
}
catch (IOException e)
{
System.err.println(
"Exception while initializing option: "
+ e.getMessage());
}
}
}
}
/* open TelnetOptionHandler functionality (end)*/
|
final synchronized void | _processAYTResponse()Processes the response of an AYT
if (!aytFlag)
{
synchronized (aytMonitor)
{
aytFlag = true;
try
{
aytMonitor.notifyAll();
}
catch (Exception e)
{
System.err.println("Exception notifying:" + e.getMessage());
}
}
}
|
void | _processDo(int option)Processes a DO request.
if (debugoptions)
{
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)
{
acceptNewState = optionHandlers[option].getAcceptLocal();
}
else
{
/* open TelnetOptionHandler functionality (end)*/
/* TERMINAL-TYPE option (start)*/
if (option == TERMINAL_TYPE)
{
if ((terminalType != null) && (terminalType.length() > 0))
{
acceptNewState = true;
}
}
/* TERMINAL-TYPE option (end)*/
/* open TelnetOptionHandler functionality (start)*/
}
/* open TelnetOptionHandler functionality (end)*/
if (_willResponse[option] > 0)
{
--_willResponse[option];
if (_willResponse[option] > 0 && _stateIsWill(option))
{
--_willResponse[option];
}
}
if (_willResponse[option] == 0)
{
if (_requestedWont(option))
{
switch (option)
{
default:
break;
}
if (acceptNewState)
{
_setWantWill(option);
_sendWill(option);
}
else
{
++_willResponse[option];
_sendWont(option);
}
}
else
{
// Other end has acknowledged option.
switch (option)
{
default:
break;
}
}
}
_setWill(option);
|
void | _processDont(int option)Processes a DONT request.
if (debugoptions)
{
System.err.println("RECEIVED DONT: "
+ TelnetOption.getOption(option));
}
if (__notifhand != null)
{
__notifhand.receivedNegotiation(
TelnetNotificationHandler.RECEIVED_DONT,
option);
}
if (_willResponse[option] > 0)
{
--_willResponse[option];
if (_willResponse[option] > 0 && _stateIsWont(option))
{
--_willResponse[option];
}
}
if (_willResponse[option] == 0 && _requestedWill(option))
{
switch (option)
{
default:
break;
}
/* FIX for a BUG in the negotiation (start)*/
if ((_stateIsWill(option)) || (_requestedWill(option)))
{
_sendWont(option);
}
_setWantWont(option);
/* FIX for a BUG in the negotiation (end)*/
}
_setWont(option);
|
void | _processSuboption(int[] suboption, int suboptionLength)Processes a suboption negotiation.
if (debug)
{
System.err.println("PROCESS SUBOPTION.");
}
/* open TelnetOptionHandler functionality (start)*/
if (suboptionLength > 0)
{
if (optionHandlers[suboption[0]] != null)
{
int responseSuboption[] =
optionHandlers[suboption[0]].answerSubnegotiation(suboption,
suboptionLength);
_sendSubnegotiation(responseSuboption);
}
else
{
if (suboptionLength > 1)
{
if (debug)
{
for (int ii = 0; ii < suboptionLength; ii++)
{
System.err.println("SUB[" + ii + "]: "
+ suboption[ii]);
}
}
if ((suboption[0] == TERMINAL_TYPE)
&& (suboption[1] == TERMINAL_TYPE_SEND))
{
_sendTerminalType();
}
}
}
}
/* open TelnetOptionHandler functionality (end)*/
|
void | _processWill(int option)Processes a WILL request.
if (debugoptions)
{
System.err.println("RECEIVED WILL: "
+ TelnetOption.getOption(option));
}
if (__notifhand != null)
{
__notifhand.receivedNegotiation(
TelnetNotificationHandler.RECEIVED_WILL,
option);
}
boolean acceptNewState = false;
/* open TelnetOptionHandler functionality (start)*/
if (optionHandlers[option] != null)
{
acceptNewState = optionHandlers[option].getAcceptRemote();
}
/* open TelnetOptionHandler functionality (end)*/
if (_doResponse[option] > 0)
{
--_doResponse[option];
if (_doResponse[option] > 0 && _stateIsDo(option))
{
--_doResponse[option];
}
}
if (_doResponse[option] == 0 && _requestedDont(option))
{
switch (option)
{
default:
break;
}
if (acceptNewState)
{
_setWantDo(option);
_sendDo(option);
}
else
{
++_doResponse[option];
_sendDont(option);
}
}
_setDo(option);
|
void | _processWont(int option)Processes a WONT request.
if (debugoptions)
{
System.err.println("RECEIVED WONT: "
+ TelnetOption.getOption(option));
}
if (__notifhand != null)
{
__notifhand.receivedNegotiation(
TelnetNotificationHandler.RECEIVED_WONT,
option);
}
if (_doResponse[option] > 0)
{
--_doResponse[option];
if (_doResponse[option] > 0 && _stateIsDont(option))
{
--_doResponse[option];
}
}
if (_doResponse[option] == 0 && _requestedDo(option))
{
switch (option)
{
default:
break;
}
/* FIX for a BUG in the negotiation (start)*/
if ((_stateIsDo(option)) || (_requestedDo(option)))
{
_sendDont(option);
}
_setWantDont(option);
/* FIX for a BUG in the negotiation (end)*/
}
_setDont(option);
|
void | _registerSpyStream(java.io.OutputStream spystream)Registers an OutputStream for spying what's going on in
the Telnet session.
spyStream = spystream;
|
final synchronized void | _requestDo(int option)Requests a DO.
if ((_doResponse[option] == 0 && _stateIsDo(option))
|| _requestedDo(option))
{
return ;
}
_setWantDo(option);
++_doResponse[option];
_sendDo(option);
|
final synchronized void | _requestDont(int option)Requests a DONT.
if ((_doResponse[option] == 0 && _stateIsDont(option))
|| _requestedDont(option))
{
return ;
}
_setWantDont(option);
++_doResponse[option];
_sendDont(option);
|
final synchronized void | _requestWill(int option)Requests a WILL.
if ((_willResponse[option] == 0 && _stateIsWill(option))
|| _requestedWill(option))
{
return ;
}
_setWantWill(option);
++_doResponse[option];
_sendWill(option);
|
final synchronized void | _requestWont(int option)Requests a WONT.
if ((_willResponse[option] == 0 && _stateIsWont(option))
|| _requestedWont(option))
{
return ;
}
_setWantWont(option);
++_doResponse[option];
_sendWont(option);
|
boolean | _requestedDo(int option)Looks for the state of the option.
return ((_options[option] & _REQUESTED_DO_MASK) != 0);
|
boolean | _requestedDont(int option)Looks for the state of the option.
return !_requestedDo(option);
|
boolean | _requestedWill(int option)Looks for the state of the option.
return ((_options[option] & _REQUESTED_WILL_MASK) != 0);
|
boolean | _requestedWont(int option)Looks for the state of the option.
return !_requestedWill(option);
|
final boolean | _sendAYT(long timeout)Sends an Are You There sequence and waits for the result.
boolean retValue = false;
synchronized (aytMonitor)
{
synchronized (this)
{
aytFlag = false;
_output_.write(_COMMAND_AYT);
_output_.flush();
}
try
{
aytMonitor.wait(timeout);
if (aytFlag == false)
{
retValue = false;
aytFlag = true;
}
else
{
retValue = true;
}
}
catch (IllegalMonitorStateException e)
{
System.err.println("Exception processing AYT:"
+ e.getMessage());
}
}
return (retValue);
|
final synchronized void | _sendByte(int b)Sends a byte.
_output_.write(b);
/* Code Section added for supporting spystreams (start)*/
_spyWrite(b);
/* Code Section added for supporting spystreams (end)*/
|
final synchronized void | _sendDo(int option)Sends a DO.
if (debug || debugoptions)
{
System.err.println("DO: " + TelnetOption.getOption(option));
}
_output_.write(_COMMAND_DO);
_output_.write(option);
/* Code Section added for sending the negotiation ASAP (start)*/
_output_.flush();
/* Code Section added for sending the negotiation ASAP (end)*/
|
final synchronized void | _sendDont(int option)Sends a DONT.
if (debug || debugoptions)
{
System.err.println("DONT: " + TelnetOption.getOption(option));
}
_output_.write(_COMMAND_DONT);
_output_.write(option);
/* Code Section added for sending the negotiation ASAP (start)*/
_output_.flush();
/* Code Section added for sending the negotiation ASAP (end)*/
|
final synchronized void | _sendSubnegotiation(int[] subn)Manages subnegotiation for Terminal Type.
if (debug)
{
System.err.println("SEND SUBNEGOTIATION: ");
if (subn != null)
{
for (int ii = 0; ii < subn.length; ii++)
{
System.err.println("subn[" + ii + "]=" + subn[ii]);
}
}
}
if (subn != null)
{
byte byteresp[] = new byte[subn.length];
for (int ii = 0; ii < subn.length; ii++)
{
byteresp[ii] = (byte) subn[ii];
}
_output_.write(_COMMAND_SB);
_output_.write(byteresp);
_output_.write(_COMMAND_SE);
/* Code Section added for sending the negotiation ASAP (start)*/
_output_.flush();
/* Code Section added for sending the negotiation ASAP (end)*/
}
|
final synchronized void | _sendTerminalType()Sends terminal type information.
if (debug)
{
System.err.println("SEND TERMINAL-TYPE: " + terminalType);
}
if (terminalType != null)
{
_output_.write(_COMMAND_SB);
_output_.write(_COMMAND_IS);
_output_.write(terminalType.getBytes());
_output_.write(_COMMAND_SE);
_output_.flush();
}
|
final synchronized void | _sendWill(int option)Sends a WILL.
if (debug || debugoptions)
{
System.err.println("WILL: " + TelnetOption.getOption(option));
}
_output_.write(_COMMAND_WILL);
_output_.write(option);
/* Code Section added for sending the negotiation ASAP (start)*/
_output_.flush();
/* Code Section added for sending the negotiation ASAP (end)*/
|
final synchronized void | _sendWont(int option)Sends a WONT.
if (debug || debugoptions)
{
System.err.println("WONT: " + TelnetOption.getOption(option));
}
_output_.write(_COMMAND_WONT);
_output_.write(option);
/* Code Section added for sending the negotiation ASAP (start)*/
_output_.flush();
/* Code Section added for sending the negotiation ASAP (end)*/
|
void | _setDo(int option)Sets the state of the option.
_options[option] |= _DO_MASK;
/* open TelnetOptionHandler functionality (start)*/
if (_requestedDo(option))
{
if (optionHandlers[option] != null)
{
optionHandlers[option].setDo(true);
int subneg[] =
optionHandlers[option].startSubnegotiationRemote();
if (subneg != null)
{
try
{
_sendSubnegotiation(subneg);
}
catch (Exception e)
{
System.err.println("Exception in option subnegotiation"
+ e.getMessage());
}
}
}
}
/* open TelnetOptionHandler functionality (end)*/
|
void | _setDont(int option)Sets the state of the option.
_options[option] &= ~_DO_MASK;
/* open TelnetOptionHandler functionality (start)*/
if (optionHandlers[option] != null)
{
optionHandlers[option].setDo(false);
}
/* open TelnetOptionHandler functionality (end)*/
|
void | _setWantDo(int option)Sets the state of the option.
_options[option] |= _REQUESTED_DO_MASK;
|
void | _setWantDont(int option)Sets the state of the option.
_options[option] &= ~_REQUESTED_DO_MASK;
|
void | _setWantWill(int option)Sets the state of the option.
_options[option] |= _REQUESTED_WILL_MASK;
|
void | _setWantWont(int option)Sets the state of the option.
_options[option] &= ~_REQUESTED_WILL_MASK;
|
void | _setWill(int option)Sets the state of the option.
_options[option] |= _WILL_MASK;
/* open TelnetOptionHandler functionality (start)*/
if (_requestedWill(option))
{
if (optionHandlers[option] != null)
{
optionHandlers[option].setWill(true);
int subneg[] =
optionHandlers[option].startSubnegotiationLocal();
if (subneg != null)
{
try
{
_sendSubnegotiation(subneg);
}
catch (Exception e)
{
System.err.println(
"Exception in option subnegotiation"
+ e.getMessage());
}
}
}
}
/* open TelnetOptionHandler functionality (end)*/
|
void | _setWont(int option)Sets the state of the option.
_options[option] &= ~_WILL_MASK;
/* open TelnetOptionHandler functionality (start)*/
if (optionHandlers[option] != null)
{
optionHandlers[option].setWill(false);
}
/* open TelnetOptionHandler functionality (end)*/
|
void | _spyRead(int ch)Sends a read char on the spy stream.
if (spyStream != null)
{
try
{
if (ch != (int) '\r")
{
spyStream.write(ch);
if (ch == (int) '\n")
{
spyStream.write((int) '\r");
}
spyStream.flush();
}
}
catch (Exception e)
{
spyStream = null;
}
}
|
void | _spyWrite(int ch)Sends a written char on the spy stream.
if (!(_stateIsDo(TelnetOption.ECHO)
&& _requestedDo(TelnetOption.ECHO)))
{
if (spyStream != null)
{
try
{
spyStream.write(ch);
spyStream.flush();
}
catch (Exception e)
{
spyStream = null;
}
}
}
|
boolean | _stateIsDo(int option)Looks for the state of the option.
return ((_options[option] & _DO_MASK) != 0);
|
boolean | _stateIsDont(int option)Looks for the state of the option.
return !_stateIsDo(option);
|
boolean | _stateIsWill(int option)Looks for the state of the option.
return ((_options[option] & _WILL_MASK) != 0);
|
boolean | _stateIsWont(int option)Looks for the state of the option.
return !_stateIsWill(option);
|
void | _stopSpyStream()Stops spying this Telnet.
spyStream = null;
|
void | addOptionHandler(TelnetOptionHandler opthand)Registers a new TelnetOptionHandler for this telnet to use.
int optcode = opthand.getOptionCode();
if (TelnetOption.isValidOption(optcode))
{
if (optionHandlers[optcode] == null)
{
optionHandlers[optcode] = opthand;
if (isConnected())
{
if (opthand.getInitLocal())
{
try
{
_requestWill(optcode);
}
catch (IOException e)
{
System.err.println(
"Exception while initializing option: "
+ e.getMessage());
}
}
if (opthand.getInitRemote())
{
try
{
_requestDo(optcode);
}
catch (IOException e)
{
System.err.println(
"Exception while initializing option: "
+ e.getMessage());
}
}
}
}
else
{
throw (new InvalidTelnetOptionException(
"Already registered option", optcode));
}
}
else
{
throw (new InvalidTelnetOptionException(
"Invalid Option Code", optcode));
}
|
void | deleteOptionHandler(int optcode)Unregisters a TelnetOptionHandler.
if (TelnetOption.isValidOption(optcode))
{
if (optionHandlers[optcode] == null)
{
throw (new InvalidTelnetOptionException(
"Unregistered option", optcode));
}
else
{
TelnetOptionHandler opthand = optionHandlers[optcode];
optionHandlers[optcode] = null;
if (opthand.getWill())
{
try
{
_requestWont(optcode);
}
catch (IOException e)
{
System.err.println(
"Exception while turning off option: "
+ e.getMessage());
}
}
if (opthand.getDo())
{
try
{
_requestDont(optcode);
}
catch (IOException e)
{
System.err.println(
"Exception while turning off option: "
+ e.getMessage());
}
}
}
}
else
{
throw (new InvalidTelnetOptionException(
"Invalid Option Code", optcode));
}
|
public void | registerNotifHandler(TelnetNotificationHandler notifhand)Registers a notification handler to which will be sent
notifications of received telnet option negotiation commands.
__notifhand = notifhand;
|
public void | unregisterNotifHandler()Unregisters the current notification handler.
__notifhand = null;
|