View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      https://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  
18  package org.apache.commons.net.telnet;
19  
20  /**
21   * The TelnetOption class cannot be instantiated and only serves as a storehouse for Telnet option constants.
22   * <p>
23   * Details regarding Telnet option specification can be found in RFC 855.
24   * </p>
25   *
26   * @see org.apache.commons.net.telnet.Telnet
27   * @see org.apache.commons.net.telnet.TelnetClient
28   */
29  public class TelnetOption {
30  
31      /** The maximum value an option code can have. This value is 255. */
32      public static final int MAX_OPTION_VALUE = 255;
33  
34      /**
35       * {@value}
36       */
37      public static final int BINARY = 0;
38  
39      /**
40       * {@value}
41       */
42      public static final int ECHO = 1;
43  
44      /**
45       * {@value}
46       */
47      public static final int PREPARE_TO_RECONNECT = 2;
48  
49      /**
50       * {@value}
51       */
52      public static final int SUPPRESS_GO_AHEAD = 3;
53  
54      /**
55       * {@value}
56       */
57      public static final int APPROXIMATE_MESSAGE_SIZE = 4;
58  
59      /**
60       * {@value}
61       */
62      public static final int STATUS = 5;
63  
64      /**
65       * {@value}
66       */
67      public static final int TIMING_MARK = 6;
68  
69      /**
70       * {@value}
71       */
72      public static final int REMOTE_CONTROLLED_TRANSMISSION = 7;
73  
74      /**
75       * {@value}
76       */
77      public static final int NEGOTIATE_OUTPUT_LINE_WIDTH = 8;
78  
79      /**
80       * {@value}
81       */
82      public static final int NEGOTIATE_OUTPUT_PAGE_SIZE = 9;
83  
84      /**
85       * {@value}
86       */
87      public static final int NEGOTIATE_CARRIAGE_RETURN = 10;
88  
89      /**
90       * {@value}
91       */
92      public static final int NEGOTIATE_HORIZONTAL_TAB_STOP = 11;
93  
94      /**
95       * {@value}
96       */
97      public static final int NEGOTIATE_HORIZONTAL_TAB = 12;
98  
99      /**
100      * {@value}
101      */
102     public static final int NEGOTIATE_FORMFEED = 13;
103 
104     /**
105      * {@value}
106      */
107     public static final int NEGOTIATE_VERTICAL_TAB_STOP = 14;
108 
109     /**
110      * {@value}
111      */
112     public static final int NEGOTIATE_VERTICAL_TAB = 15;
113 
114     /**
115      * {@value}
116      */
117     public static final int NEGOTIATE_LINEFEED = 16;
118 
119     /**
120      * {@value}
121      */
122     public static final int EXTENDED_ASCII = 17;
123 
124     /**
125      * {@value}
126      */
127     public static final int FORCE_LOGOUT = 18;
128 
129     /**
130      * {@value}
131      */
132     public static final int BYTE_MACRO = 19;
133 
134     /**
135      * {@value}
136      */
137     public static final int DATA_ENTRY_TERMINAL = 20;
138 
139     /**
140      * {@value}
141      */
142     public static final int SUPDUP = 21;
143 
144     /**
145      * {@value}
146      */
147     public static final int SUPDUP_OUTPUT = 22;
148 
149     /**
150      * {@value}
151      */
152     public static final int SEND_LOCATION = 23;
153 
154     /**
155      * {@value}
156      */
157     public static final int TERMINAL_TYPE = 24;
158 
159     /**
160      * {@value}
161      */
162     public static final int END_OF_RECORD = 25;
163 
164     /**
165      * {@value}
166      */
167     public static final int TACACS_USER_IDENTIFICATION = 26;
168 
169     /**
170      * {@value}
171      */
172     public static final int OUTPUT_MARKING = 27;
173 
174     /**
175      * {@value}
176      */
177     public static final int TERMINAL_LOCATION_NUMBER = 28;
178 
179     /**
180      * {@value}
181      */
182     public static final int REGIME_3270 = 29;
183 
184     /**
185      * {@value}
186      */
187     public static final int X3_PAD = 30;
188 
189     /**
190      * {@value}
191      */
192     public static final int WINDOW_SIZE = 31;
193 
194     /**
195      * {@value}
196      */
197     public static final int TERMINAL_SPEED = 32;
198 
199     /**
200      * {@value}
201      */
202     public static final int REMOTE_FLOW_CONTROL = 33;
203 
204     /**
205      * {@value}
206      */
207     public static final int LINEMODE = 34;
208 
209     /**
210      * {@value}
211      */
212     public static final int X_DISPLAY_LOCATION = 35;
213 
214     /**
215      * {@value}
216      */
217     public static final int OLD_ENVIRONMENT_VARIABLES = 36;
218 
219     /**
220      * {@value}
221      */
222     public static final int AUTHENTICATION = 37;
223 
224     /**
225      * {@value}
226      */
227     public static final int ENCRYPTION = 38;
228 
229     /**
230      * {@value}
231      */
232     public static final int NEW_ENVIRONMENT_VARIABLES = 39;
233 
234     /**
235      * {@value}
236      */
237     public static final int EXTENDED_OPTIONS_LIST = 255;
238 
239     /**
240      * {@value}
241      */
242     @SuppressWarnings("unused")
243     private static final int FIRST_OPTION = BINARY;
244 
245     /**
246      * {@value}
247      */
248     private static final int LAST_OPTION = EXTENDED_OPTIONS_LIST;
249 
250     /**
251      * {@value}
252      */
253     private static final String[] optionString = { "BINARY", "ECHO", "RCP", "SUPPRESS GO AHEAD", "NAME", "STATUS", "TIMING MARK", "RCTE", "NAOL", "NAOP",
254             "NAOCRD", "NAOHTS", "NAOHTD", "NAOFFD", "NAOVTS", "NAOVTD", "NAOLFD", "EXTEND ASCII", "LOGOUT", "BYTE MACRO", "DATA ENTRY TERMINAL", "SUPDUP",
255             "SUPDUP OUTPUT", "SEND LOCATION", "TERMINAL TYPE", "END OF RECORD", "TACACS UID", "OUTPUT MARKING", "TTYLOC", "3270 REGIME", "X.3 PAD", "NAWS",
256             "TSPEED", "LFLOW", "LINEMODE", "XDISPLOC", "OLD-ENVIRON", "AUTHENTICATION", "ENCRYPT", "NEW-ENVIRON", "TN3270E", "XAUTH", "CHARSET", "RSP",
257             "Com Port Control", "Suppress Local Echo", "Start TLS", "KERMIT", "SEND-URL", "FORWARD_X", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
258             "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
259             "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
260             "TELOPT PRAGMA LOGON", "TELOPT SSPI LOGON", "TELOPT PRAGMA HEARTBEAT", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
261             "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
262             "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
263             "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "Extended-Options-List" };
264 
265     /**
266      * Returns the string representation of the Telnet protocol option corresponding to the given option code.
267      *
268      * @param code The option code of the Telnet protocol option
269      * @return The string representation of the Telnet protocol option.
270      */
271     public static final String getOption(final int code) {
272         if (optionString[code].isEmpty()) {
273             return "UNASSIGNED";
274         }
275         return optionString[code];
276     }
277 
278     /**
279      * Determines if a given option code is valid. Returns true if valid, false if not.
280      *
281      * @param code The option code to test.
282      * @return True if the option code is valid, false if not.
283      **/
284     public static final boolean isValidOption(final int code) {
285         return code <= LAST_OPTION;
286     }
287 
288     /** Cannot be instantiated. */
289     private TelnetOption() {
290     }
291 }