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