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