001: /*
002: * Copyright 2003-2004 The Apache Software Foundation
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.apache.commons.net.telnet;
017:
018: /***
019: * Implements the telnet terminal type option RFC 1091.
020: * <p>
021: * @author Bruno D'Avanzo
022: ***/
023: public class TerminalTypeOptionHandler extends TelnetOptionHandler {
024: /***
025: * Terminal type
026: ***/
027: private String termType = null;
028:
029: /***
030: * Terminal type option
031: ***/
032: protected static final int TERMINAL_TYPE = 24;
033:
034: /***
035: * Send (for subnegotiation)
036: ***/
037: protected static final int TERMINAL_TYPE_SEND = 1;
038:
039: /***
040: * Is (for subnegotiation)
041: ***/
042: protected static final int TERMINAL_TYPE_IS = 0;
043:
044: /***
045: * Constructor for the TerminalTypeOptionHandler. Allows defining desired
046: * initial setting for local/remote activation of this option and
047: * behaviour in case a local/remote activation request for this
048: * option is received.
049: * <p>
050: * @param termtype - terminal type that will be negotiated.
051: * @param initlocal - if set to true, a WILL is sent upon connection.
052: * @param initremote - if set to true, a DO is sent upon connection.
053: * @param acceptlocal - if set to true, any DO request is accepted.
054: * @param acceptremote - if set to true, any WILL request is accepted.
055: ***/
056: public TerminalTypeOptionHandler(String termtype,
057: boolean initlocal, boolean initremote, boolean acceptlocal,
058: boolean acceptremote) {
059: super (TelnetOption.TERMINAL_TYPE, initlocal, initremote,
060: acceptlocal, acceptremote);
061: termType = termtype;
062: }
063:
064: /***
065: * Constructor for the TerminalTypeOptionHandler. Initial and accept
066: * behaviour flags are set to false
067: * <p>
068: * @param termtype - terminal type that will be negotiated.
069: ***/
070: public TerminalTypeOptionHandler(String termtype) {
071: super (TelnetOption.TERMINAL_TYPE, false, false, false, false);
072: termType = termtype;
073: }
074:
075: /***
076: * Implements the abstract method of TelnetOptionHandler.
077: * <p>
078: * @param suboptionData - the sequence received, whithout IAC SB & IAC SE
079: * @param suboptionLength - the length of data in suboption_data
080: * <p>
081: * @return terminal type information
082: ***/
083: public int[] answerSubnegotiation(int suboptionData[],
084: int suboptionLength) {
085: if ((suboptionData != null) && (suboptionLength > 1)
086: && (termType != null)) {
087: if ((suboptionData[0] == TERMINAL_TYPE)
088: && (suboptionData[1] == TERMINAL_TYPE_SEND)) {
089: int response[] = new int[termType.length() + 2];
090:
091: response[0] = TERMINAL_TYPE;
092: response[1] = TERMINAL_TYPE_IS;
093:
094: for (int ii = 0; ii < termType.length(); ii++) {
095: response[ii + 2] = (int) termType.charAt(ii);
096: }
097:
098: return response;
099: }
100: }
101: return null;
102: }
103:
104: /***
105: * Implements the abstract method of TelnetOptionHandler.
106: * <p>
107: * @return always null (no response to subnegotiation)
108: ***/
109: public int[] startSubnegotiationLocal() {
110: return null;
111: }
112:
113: /***
114: * Implements the abstract method of TelnetOptionHandler.
115: * <p>
116: * @return always null (no response to subnegotiation)
117: ***/
118: public int[] startSubnegotiationRemote() {
119: return null;
120: }
121: }
|