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