1. /*
  2. * Copyright 2001-2004 The Apache Software Foundation
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package org.apache.commons.net.telnet;
  17. /**
  18. * The TelnetCommand class cannot be instantiated and only serves as a
  19. * storehouse for telnet command constants.
  20. * @author Daniel F. Savarese
  21. * @see org.apache.commons.net.telnet.Telnet
  22. * @see org.apache.commons.net.telnet.TelnetClient
  23. */
  24. public final class TelnetCommand
  25. {
  26. /*** The maximum value a command code can have. This value is 255. ***/
  27. public static final int MAX_COMMAND_VALUE = 255;
  28. /*** Interpret As Command code. Value is 255 according to RFC 854. ***/
  29. public static final int IAC = 255;
  30. /*** Don't use option code. Value is 254 according to RFC 854. ***/
  31. public static final int DONT = 254;
  32. /*** Request to use option code. Value is 253 according to RFC 854. ***/
  33. public static final int DO = 253;
  34. /*** Refuse to use option code. Value is 252 according to RFC 854. ***/
  35. public static final int WONT = 252;
  36. /*** Agree to use option code. Value is 251 according to RFC 854. ***/
  37. public static final int WILL = 251;
  38. /*** Start subnegotiation code. Value is 250 according to RFC 854. ***/
  39. public static final int SB = 250;
  40. /*** Go Ahead code. Value is 249 according to RFC 854. ***/
  41. public static final int GA = 249;
  42. /*** Erase Line code. Value is 248 according to RFC 854. ***/
  43. public static final int EL = 248;
  44. /*** Erase Character code. Value is 247 according to RFC 854. ***/
  45. public static final int EC = 247;
  46. /*** Are You There code. Value is 246 according to RFC 854. ***/
  47. public static final int AYT = 246;
  48. /*** Abort Output code. Value is 245 according to RFC 854. ***/
  49. public static final int AO = 245;
  50. /*** Interrupt Process code. Value is 244 according to RFC 854. ***/
  51. public static final int IP = 244;
  52. /*** Break code. Value is 243 according to RFC 854. ***/
  53. public static final int BREAK = 243;
  54. /*** Data mark code. Value is 242 according to RFC 854. ***/
  55. public static final int DM = 242;
  56. /*** No Operation code. Value is 241 according to RFC 854. ***/
  57. public static final int NOP = 241;
  58. /*** End subnegotiation code. Value is 240 according to RFC 854. ***/
  59. public static final int SE = 240;
  60. /*** End of record code. Value is 239. ***/
  61. public static final int EOR = 239;
  62. /*** Abort code. Value is 238. ***/
  63. public static final int ABORT = 238;
  64. /*** Suspend process code. Value is 237. ***/
  65. public static final int SUSP = 237;
  66. /*** End of file code. Value is 236. ***/
  67. public static final int EOF = 236;
  68. /*** Synchronize code. Value is 242. ***/
  69. public static final int SYNCH = 242;
  70. /*** String representations of commands. ***/
  71. private static final String __commandString[] = {
  72. "IAC", "DONT", "DO", "WONT", "WILL", "SB", "GA", "EL", "EC", "AYT",
  73. "AO", "IP", "BRK", "DMARK", "NOP", "SE", "EOR", "ABORT", "SUSP", "EOF"
  74. };
  75. private static final int __FIRST_COMMAND = IAC;
  76. private static final int __LAST_COMMAND = EOF;
  77. /***
  78. * Returns the string representation of the telnet protocol command
  79. * corresponding to the given command code.
  80. * <p>
  81. * @param code The command code of the telnet protocol command.
  82. * @return The string representation of the telnet protocol command.
  83. ***/
  84. public static final String getCommand(int code)
  85. {
  86. return __commandString[__FIRST_COMMAND - code];
  87. }
  88. /***
  89. * Determines if a given command code is valid. Returns true if valid,
  90. * false if not.
  91. * <p>
  92. * @param code The command code to test.
  93. * @return True if the command code is valid, false if not.
  94. **/
  95. public static final boolean isValidCommand(int code)
  96. {
  97. return (code <= __FIRST_COMMAND && code >= __LAST_COMMAND);
  98. }
  99. // Cannot be instantiated
  100. private TelnetCommand()
  101. { }
  102. }