001    /*
002     * Copyright 2001-2005 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     * The TelnetOption class cannot be instantiated and only serves as a
020     * storehouse for telnet option constants.
021     * <p>
022     * Details regarding Telnet option specification can be found in RFC 855.
023     * <p>
024     * <p>
025     * @author Daniel F. Savarese
026     * @see org.apache.commons.net.telnet.Telnet
027     * @see org.apache.commons.net.telnet.TelnetClient
028     ***/
029    
030    public class TelnetOption
031    {
032        /*** The maximum value an option code can have.  This value is 255. ***/
033        public static final int MAX_OPTION_VALUE = 255;
034    
035        public static int BINARY = 0;
036    
037        public static int ECHO = 1;
038    
039        public static int PREPARE_TO_RECONNECT = 2;
040    
041        public static int SUPPRESS_GO_AHEAD = 3;
042    
043        public static int APPROXIMATE_MESSAGE_SIZE = 4;
044    
045        public static int STATUS = 5;
046    
047        public static int TIMING_MARK = 6;
048    
049        public static int REMOTE_CONTROLLED_TRANSMISSION = 7;
050    
051        public static int NEGOTIATE_OUTPUT_LINE_WIDTH = 8;
052    
053        public static int NEGOTIATE_OUTPUT_PAGE_SIZE = 9;
054    
055        public static int NEGOTIATE_CARRIAGE_RETURN = 10;
056    
057        public static int NEGOTIATE_HORIZONTAL_TAB_STOP = 11;
058    
059        public static int NEGOTIATE_HORIZONTAL_TAB = 12;
060    
061        public static int NEGOTIATE_FORMFEED = 13;
062    
063        public static int NEGOTIATE_VERTICAL_TAB_STOP = 14;
064    
065        public static int NEGOTIATE_VERTICAL_TAB = 15;
066    
067        public static int NEGOTIATE_LINEFEED = 16;
068    
069        public static int EXTENDED_ASCII = 17;
070    
071        public static int FORCE_LOGOUT = 18;
072    
073        public static int BYTE_MACRO = 19;
074    
075        public static int DATA_ENTRY_TERMINAL = 20;
076    
077        public static int SUPDUP = 21;
078    
079        public static int SUPDUP_OUTPUT = 22;
080    
081        public static int SEND_LOCATION = 23;
082    
083        public static int TERMINAL_TYPE = 24;
084    
085        public static int END_OF_RECORD = 25;
086    
087        public static int TACACS_USER_IDENTIFICATION = 26;
088    
089        public static int OUTPUT_MARKING = 27;
090    
091        public static int TERMINAL_LOCATION_NUMBER = 28;
092    
093        public static int REGIME_3270 = 29;
094    
095        public static int X3_PAD = 30;
096    
097        public static int WINDOW_SIZE = 31;
098    
099        public static int TERMINAL_SPEED = 32;
100    
101        public static int REMOTE_FLOW_CONTROL = 33;
102    
103        public static int LINEMODE = 34;
104    
105        public static int X_DISPLAY_LOCATION = 35;
106    
107        public static int OLD_ENVIRONMENT_VARIABLES = 36;
108    
109        public static int AUTHENTICATION = 37;
110    
111        public static int ENCRYPTION = 38;
112    
113        public static int NEW_ENVIRONMENT_VARIABLES = 39;
114    
115        public static int EXTENDED_OPTIONS_LIST = 255;
116    
117        private static int __FIRST_OPTION = BINARY;
118        private static int __LAST_OPTION = EXTENDED_OPTIONS_LIST;
119    
120        private static final String __optionString[] = {
121                    "BINARY", "ECHO", "RCP", "SUPPRESS GO AHEAD", "NAME", "STATUS",
122                    "TIMING MARK", "RCTE", "NAOL", "NAOP", "NAOCRD", "NAOHTS", "NAOHTD",
123                    "NAOFFD", "NAOVTS", "NAOVTD", "NAOLFD", "EXTEND ASCII", "LOGOUT",
124                    "BYTE MACRO", "DATA ENTRY TERMINAL", "SUPDUP", "SUPDUP OUTPUT",
125                    "SEND LOCATION", "TERMINAL TYPE", "END OF RECORD", "TACACS UID",
126                    "OUTPUT MARKING", "TTYLOC", "3270 REGIME", "X.3 PAD", "NAWS", "TSPEED",
127                    "LFLOW", "LINEMODE", "XDISPLOC", "OLD-ENVIRON", "AUTHENTICATION",
128                    "ENCRYPT", "NEW-ENVIRON", "TN3270E", "XAUTH", "CHARSET", "RSP",
129                    "Com Port Control", "Suppress Local Echo", "Start TLS",
130                    "KERMIT", "SEND-URL", "FORWARD_X", "", "", "",
131                    "", "", "", "", "", "", "", "", "", "",
132                    "", "", "", "", "", "", "", "", "", "",
133                    "", "", "", "", "", "", "", "", "", "",
134                    "", "", "", "", "", "", "", "", "", "",
135                    "", "", "", "", "", "", "", "", "", "",
136                    "", "", "", "", "", "", "", "", "", "",
137                    "", "", "", "", "", "", "", "", "", "",
138                    "", "", "", "", "", "", "", "", "", "",
139                    "", "", "", "", "", "TELOPT PRAGMA LOGON", "TELOPT SSPI LOGON",
140                    "TELOPT PRAGMA HEARTBEAT", "", "", "", "",
141                    "", "", "", "", "", "", "", "", "", "",
142                    "", "", "", "", "", "", "", "", "", "",
143                    "", "", "", "", "", "", "", "", "", "",
144                    "", "", "", "", "", "", "", "", "", "",
145                    "", "", "", "", "", "", "", "", "", "",
146                    "", "", "", "", "", "", "", "", "", "",
147                    "", "", "", "", "", "", "", "", "", "",
148                    "", "", "", "", "", "", "", "", "", "",
149                    "", "", "", "", "", "", "", "", "", "",
150                    "", "", "", "", "", "", "", "", "", "",
151                    "", "", "", "", "", "", "", "", "", "",
152                    "Extended-Options-List"
153                };
154    
155    
156        /***
157         * Returns the string representation of the telnet protocol option
158         * corresponding to the given option code.
159         * <p>
160         * @param code The option code of the telnet protocol option
161         * @return The string representation of the telnet protocol option.
162         ***/
163        public static final String getOption(int code)
164        {
165            if(__optionString[code].length() == 0)
166            {
167                return "UNASSIGNED";
168            }
169            else
170            {
171                return __optionString[code];
172            }
173        }
174    
175    
176        /***
177         * Determines if a given option code is valid.  Returns true if valid,
178         * false if not.
179         * <p>
180         * @param code  The option code to test.
181         * @return True if the option code is valid, false if not.
182         **/
183        public static final boolean isValidOption(int code)
184        {
185            return (code <= __LAST_OPTION);
186        }
187    
188        // Cannot be instantiated
189        private TelnetOption()
190        { }
191    }