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 018package org.apache.commons.net.telnet; 019 020/** 021 * The TelnetOption class cannot be instantiated and only serves as a storehouse for telnet option constants. 022 * <p> 023 * Details regarding Telnet option specification can be found in RFC 855. 024 * </p> 025 * 026 * @see org.apache.commons.net.telnet.Telnet 027 * @see org.apache.commons.net.telnet.TelnetClient 028 */ 029public class TelnetOption { 030 /** The maximum value an option code can have. This value is 255. */ 031 public static final int MAX_OPTION_VALUE = 255; 032 033 public static final int BINARY = 0; 034 035 public static final int ECHO = 1; 036 037 public static final int PREPARE_TO_RECONNECT = 2; 038 039 public static final int SUPPRESS_GO_AHEAD = 3; 040 041 public static final int APPROXIMATE_MESSAGE_SIZE = 4; 042 043 public static final int STATUS = 5; 044 045 public static final int TIMING_MARK = 6; 046 047 public static final int REMOTE_CONTROLLED_TRANSMISSION = 7; 048 049 public static final int NEGOTIATE_OUTPUT_LINE_WIDTH = 8; 050 051 public static final int NEGOTIATE_OUTPUT_PAGE_SIZE = 9; 052 053 public static final int NEGOTIATE_CARRIAGE_RETURN = 10; 054 055 public static final int NEGOTIATE_HORIZONTAL_TAB_STOP = 11; 056 057 public static final int NEGOTIATE_HORIZONTAL_TAB = 12; 058 059 public static final int NEGOTIATE_FORMFEED = 13; 060 061 public static final int NEGOTIATE_VERTICAL_TAB_STOP = 14; 062 063 public static final int NEGOTIATE_VERTICAL_TAB = 15; 064 065 public static final int NEGOTIATE_LINEFEED = 16; 066 067 public static final int EXTENDED_ASCII = 17; 068 069 public static final int FORCE_LOGOUT = 18; 070 071 public static final int BYTE_MACRO = 19; 072 073 public static final int DATA_ENTRY_TERMINAL = 20; 074 075 public static final int SUPDUP = 21; 076 077 public static final int SUPDUP_OUTPUT = 22; 078 079 public static final int SEND_LOCATION = 23; 080 081 public static final int TERMINAL_TYPE = 24; 082 083 public static final int END_OF_RECORD = 25; 084 085 public static final int TACACS_USER_IDENTIFICATION = 26; 086 087 public static final int OUTPUT_MARKING = 27; 088 089 public static final int TERMINAL_LOCATION_NUMBER = 28; 090 091 public static final int REGIME_3270 = 29; 092 093 public static final int X3_PAD = 30; 094 095 public static final int WINDOW_SIZE = 31; 096 097 public static final int TERMINAL_SPEED = 32; 098 099 public static final int REMOTE_FLOW_CONTROL = 33; 100 101 public static final int LINEMODE = 34; 102 103 public static final int X_DISPLAY_LOCATION = 35; 104 105 public static final int OLD_ENVIRONMENT_VARIABLES = 36; 106 107 public static final int AUTHENTICATION = 37; 108 109 public static final int ENCRYPTION = 38; 110 111 public static final int NEW_ENVIRONMENT_VARIABLES = 39; 112 113 public static final int EXTENDED_OPTIONS_LIST = 255; 114 115 @SuppressWarnings("unused") 116 private static final int FIRST_OPTION = BINARY; 117 private static final int LAST_OPTION = EXTENDED_OPTIONS_LIST; 118 119 private static final String[] optionString = { "BINARY", "ECHO", "RCP", "SUPPRESS GO AHEAD", "NAME", "STATUS", "TIMING MARK", "RCTE", "NAOL", "NAOP", 120 "NAOCRD", "NAOHTS", "NAOHTD", "NAOFFD", "NAOVTS", "NAOVTD", "NAOLFD", "EXTEND ASCII", "LOGOUT", "BYTE MACRO", "DATA ENTRY TERMINAL", "SUPDUP", 121 "SUPDUP OUTPUT", "SEND LOCATION", "TERMINAL TYPE", "END OF RECORD", "TACACS UID", "OUTPUT MARKING", "TTYLOC", "3270 REGIME", "X.3 PAD", "NAWS", 122 "TSPEED", "LFLOW", "LINEMODE", "XDISPLOC", "OLD-ENVIRON", "AUTHENTICATION", "ENCRYPT", "NEW-ENVIRON", "TN3270E", "XAUTH", "CHARSET", "RSP", 123 "Com Port Control", "Suppress Local Echo", "Start TLS", "KERMIT", "SEND-URL", "FORWARD_X", "", "", "", "", "", "", "", "", "", "", "", "", "", "", 124 "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", 125 "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", 126 "TELOPT PRAGMA LOGON", "TELOPT SSPI LOGON", "TELOPT PRAGMA HEARTBEAT", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", 127 "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", 128 "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", 129 "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "Extended-Options-List" }; 130 131 /** 132 * Returns the string representation of the telnet protocol option corresponding to the given option code. 133 * 134 * @param code The option code of the telnet protocol option 135 * @return The string representation of the telnet protocol option. 136 */ 137 public static final String getOption(final int code) { 138 if (optionString[code].isEmpty()) { 139 return "UNASSIGNED"; 140 } 141 return optionString[code]; 142 } 143 144 /** 145 * Determines if a given option code is valid. Returns true if valid, false if not. 146 * 147 * @param code The option code to test. 148 * @return True if the option code is valid, false if not. 149 **/ 150 public static final boolean isValidOption(final int code) { 151 return code <= LAST_OPTION; 152 } 153 154 /** Cannot be instantiated. */ 155 private TelnetOption() { 156 } 157}