    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 TelnetCommand class cannot be instantiated and only serves as a
    022     * storehouse for telnet command constants.
    023     * @author Daniel F. Savarese
    024     * @see org.apache.commons.net.telnet.Telnet
    025     * @see org.apache.commons.net.telnet.TelnetClient
    026     */
    027
    028    public final class TelnetCommand
    029    {
    030        /*** The maximum value a command code can have.  This value is 255. ***/
    031        public static final int MAX_COMMAND_VALUE = 255;
    032
    033        /*** Interpret As Command code.  Value is 255 according to RFC 854. ***/
    034        public static final int IAC = 255;
    035
    036        /*** Don't use option code.  Value is 254 according to RFC 854. ***/
    037        public static final int DONT = 254;
    038
    039        /*** Request to use option code.  Value is 253 according to RFC 854. ***/
    040        public static final int DO = 253;
    041
    042        /*** Refuse to use option code.  Value is 252 according to RFC 854. ***/
    043        public static final int WONT = 252;
    044
    045        /*** Agree to use option code.  Value is 251 according to RFC 854. ***/
    046        public static final int WILL = 251;
    047
    048        /*** Start subnegotiation code.  Value is 250 according to RFC 854. ***/
    049        public static final int SB = 250;
    050
    051        /*** Go Ahead code.  Value is 249 according to RFC 854. ***/
    052        public static final int GA = 249;
    053
    054        /*** Erase Line code.  Value is 248 according to RFC 854. ***/
    055        public static final int EL = 248;
    056
    057        /*** Erase Character code.  Value is 247 according to RFC 854. ***/
    058        public static final int EC = 247;
    059
    060        /*** Are You There code.  Value is 246 according to RFC 854. ***/
    061        public static final int AYT = 246;
    062
    063        /*** Abort Output code.  Value is 245 according to RFC 854. ***/
    064        public static final int AO = 245;
    065
    066        /*** Interrupt Process code.  Value is 244 according to RFC 854. ***/
    067        public static final int IP = 244;
    068
    069        /*** Break code.  Value is 243 according to RFC 854. ***/
    070        public static final int BREAK = 243;
    071
    072        /*** Data mark code.  Value is 242 according to RFC 854. ***/
    073        public static final int DM = 242;
    074
    075        /*** No Operation code.  Value is 241 according to RFC 854. ***/
    076        public static final int NOP = 241;
    077
    078        /*** End subnegotiation code.  Value is 240 according to RFC 854. ***/
    079        public static final int SE = 240;
    080
    081        /*** End of record code.  Value is 239. ***/
    082        public static final int EOR = 239;
    083
    084        /*** Abort code.  Value is 238. ***/
    085        public static final int ABORT = 238;
    086
    087        /*** Suspend process code.  Value is 237. ***/
    088        public static final int SUSP = 237;
    089
    090        /*** End of file code.  Value is 236. ***/
    091        public static final int EOF = 236;
    092
    093        /*** Synchronize code.  Value is 242. ***/
    094        public static final int SYNCH = 242;
    095
    096        /*** String representations of commands. ***/
    097        private static final String __commandString[] = {
    098                    "IAC", "DONT", "DO", "WONT", "WILL", "SB", "GA", "EL", "EC", "AYT",
    099                    "AO", "IP", "BRK", "DMARK", "NOP", "SE", "EOR", "ABORT", "SUSP", "EOF"
    100                };
    101
    102        private static final int __FIRST_COMMAND = IAC;
    103        private static final int __LAST_COMMAND = EOF;
    104
    105        /***
    106         * Returns the string representation of the telnet protocol command
    107         * corresponding to the given command code.
    108         * <p>
    109         * @param code The command code of the telnet protocol command.
    110         * @return The string representation of the telnet protocol command.
    111         ***/
    112        public static final String getCommand(int code)
    113        {
    114            return __commandString[__FIRST_COMMAND - code];
    115        }
    116
    117        /***
    118         * Determines if a given command code is valid.  Returns true if valid,
    119         * false if not.
    120         * <p>
    121         * @param code  The command code to test.
    122         * @return True if the command code is valid, false if not.
    123         **/
    124        public static final boolean isValidCommand(int code)
    125        {
    126            return (code <= __FIRST_COMMAND && code >= __LAST_COMMAND);
    127        }
    128
    129        // Cannot be instantiated
    130        private TelnetCommand()
    131        { }
    132    }