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 TelnetOption class cannot be instantiated and only serves as a
  19. * storehouse for telnet option constants.
  20. * <p>
  21. * Details regarding Telnet option specification can be found in RFC 855.
  22. * <p>
  23. * <p>
  24. * @author Daniel F. Savarese
  25. * @see org.apache.commons.net.telnet.Telnet
  26. * @see org.apache.commons.net.telnet.TelnetClient
  27. ***/
  28. public class TelnetOption
  29. {
  30. /*** The maximum value an option code can have. This value is 255. ***/
  31. public static final int MAX_OPTION_VALUE = 255;
  32. public static int BINARY = 0;
  33. public static int ECHO = 1;
  34. public static int PREPARE_TO_RECONNECT = 2;
  35. public static int SUPPRESS_GO_AHEAD = 3;
  36. public static int APPROXIMATE_MESSAGE_SIZE = 4;
  37. public static int STATUS = 5;
  38. public static int TIMING_MARK = 6;
  39. public static int REMOTE_CONTROLLED_TRANSMISSION = 7;
  40. public static int NEGOTIATE_OUTPUT_LINE_WIDTH = 8;
  41. public static int NEGOTIATE_OUTPUT_PAGE_SIZE = 9;
  42. public static int NEGOTIATE_CARRIAGE_RETURN = 10;
  43. public static int NEGOTIATE_HORIZONTAL_TAB_STOP = 11;
  44. public static int NEGOTIATE_HORIZONTAL_TAB = 12;
  45. public static int NEGOTIATE_FORMFEED = 13;
  46. public static int NEGOTIATE_VERTICAL_TAB_STOP = 14;
  47. public static int NEGOTIATE_VERTICAL_TAB = 15;
  48. public static int NEGOTIATE_LINEFEED = 16;
  49. public static int EXTENDED_ASCII = 17;
  50. public static int FORCE_LOGOUT = 18;
  51. public static int BYTE_MACRO = 19;
  52. public static int DATA_ENTRY_TERMINAL = 20;
  53. public static int SUPDUP = 21;
  54. public static int SUPDUP_OUTPUT = 22;
  55. public static int SEND_LOCATION = 23;
  56. public static int TERMINAL_TYPE = 24;
  57. public static int END_OF_RECORD = 25;
  58. public static int TACACS_USER_IDENTIFICATION = 26;
  59. public static int OUTPUT_MARKING = 27;
  60. public static int TERMINAL_LOCATION_NUMBER = 28;
  61. public static int REGIME_3270 = 29;
  62. public static int X3_PAD = 30;
  63. public static int WINDOW_SIZE = 31;
  64. public static int TERMINAL_SPEED = 32;
  65. public static int REMOTE_FLOW_CONTROL = 33;
  66. public static int LINEMODE = 34;
  67. public static int X_DISPLAY_LOCATION = 35;
  68. public static int OLD_ENVIRONMENT_VARIABLES = 36;
  69. public static int AUTHENTICATION = 37;
  70. public static int ENCRYPTION = 38;
  71. public static int NEW_ENVIRONMENT_VARIABLES = 39;
  72. public static int EXTENDED_OPTIONS_LIST = 255;
  73. private static int __FIRST_OPTION = BINARY;
  74. private static int __LAST_OPTION = EXTENDED_OPTIONS_LIST;
  75. private static final String __optionString[] = {
  76. "BINARY", "ECHO", "RCP", "SUPPRESS GO AHEAD", "NAME", "STATUS",
  77. "TIMING MARK", "RCTE", "NAOL", "NAOP", "NAOCRD", "NAOHTS", "NAOHTD",
  78. "NAOFFD", "NAOVTS", "NAOVTD", "NAOLFD", "EXTEND ASCII", "LOGOUT",
  79. "BYTE MACRO", "DATA ENTRY TERMINAL", "SUPDUP", "SUPDUP OUTPUT",
  80. "SEND LOCATION", "TERMINAL TYPE", "END OF RECORD", "TACACS UID",
  81. "OUTPUT MARKING", "TTYLOC", "3270 REGIME", "X.3 PAD", "NAWS", "TSPEED",
  82. "LFLOW", "LINEMODE", "XDISPLOC", "OLD-ENVIRON", "AUTHENTICATION",
  83. "ENCRYPT", "NEW-ENVIRON", "TN3270E", "XAUTH", "CHARSET", "RSP",
  84. "Com Port Control", "Suppress Local Echo", "Start TLS",
  85. "KERMIT", "SEND-URL", "FORWARD_X", "", "", "",
  86. "", "", "", "", "", "", "", "", "", "",
  87. "", "", "", "", "", "", "", "", "", "",
  88. "", "", "", "", "", "", "", "", "", "",
  89. "", "", "", "", "", "", "", "", "", "",
  90. "", "", "", "", "", "", "", "", "", "",
  91. "", "", "", "", "", "", "", "", "", "",
  92. "", "", "", "", "", "", "", "", "", "",
  93. "", "", "", "", "", "", "", "", "", "",
  94. "", "", "", "", "", "TELOPT PRAGMA LOGON", "TELOPT SSPI LOGON",
  95. "TELOPT PRAGMA HEARTBEAT", "", "", "", "",
  96. "", "", "", "", "", "", "", "", "", "",
  97. "", "", "", "", "", "", "", "", "", "",
  98. "", "", "", "", "", "", "", "", "", "",
  99. "", "", "", "", "", "", "", "", "", "",
  100. "", "", "", "", "", "", "", "", "", "",
  101. "", "", "", "", "", "", "", "", "", "",
  102. "", "", "", "", "", "", "", "", "", "",
  103. "", "", "", "", "", "", "", "", "", "",
  104. "", "", "", "", "", "", "", "", "", "",
  105. "", "", "", "", "", "", "", "", "", "",
  106. "", "", "", "", "", "", "", "", "", "",
  107. "Extended-Options-List"
  108. };
  109. /***
  110. * Returns the string representation of the telnet protocol option
  111. * corresponding to the given option code.
  112. * <p>
  113. * @param code The option code of the telnet protocol option
  114. * @return The string representation of the telnet protocol option.
  115. ***/
  116. public static final String getOption(int code)
  117. {
  118. if(__optionString[code].length() == 0)
  119. {
  120. return "UNASSIGNED";
  121. }
  122. else
  123. {
  124. return __optionString[code];
  125. }
  126. }
  127. /***
  128. * Determines if a given option code is valid. Returns true if valid,
  129. * false if not.
  130. * <p>
  131. * @param code The option code to test.
  132. * @return True if the option code is valid, false if not.
  133. **/
  134. public static final boolean isValidOption(int code)
  135. {
  136. return (code <= __LAST_OPTION);
  137. }
  138. // Cannot be instantiated
  139. private TelnetOption()
  140. { }
  141. }