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