1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.commons.net.telnet;
17
18 /***
19 * Implements the telnet terminal type option RFC 1091.
20 * <p>
21 * @author Bruno D'Avanzo
22 ***/
23 public class TerminalTypeOptionHandler extends TelnetOptionHandler
24 {
25 /***
26 * Terminal type
27 ***/
28 private String termType = null;
29
30 /***
31 * Terminal type option
32 ***/
33 protected static final int TERMINAL_TYPE = 24;
34
35 /***
36 * Send (for subnegotiation)
37 ***/
38 protected static final int TERMINAL_TYPE_SEND = 1;
39
40 /***
41 * Is (for subnegotiation)
42 ***/
43 protected static final int TERMINAL_TYPE_IS = 0;
44
45 /***
46 * Constructor for the TerminalTypeOptionHandler. Allows defining desired
47 * initial setting for local/remote activation of this option and
48 * behaviour in case a local/remote activation request for this
49 * option is received.
50 * <p>
51 * @param termtype - terminal type that will be negotiated.
52 * @param initlocal - if set to true, a WILL is sent upon connection.
53 * @param initremote - if set to true, a DO is sent upon connection.
54 * @param acceptlocal - if set to true, any DO request is accepted.
55 * @param acceptremote - if set to true, any WILL request is accepted.
56 ***/
57 public TerminalTypeOptionHandler(String termtype,
58 boolean initlocal,
59 boolean initremote,
60 boolean acceptlocal,
61 boolean acceptremote)
62 {
63 super(TelnetOption.TERMINAL_TYPE, initlocal, initremote,
64 acceptlocal, acceptremote);
65 termType = termtype;
66 }
67
68 /***
69 * Constructor for the TerminalTypeOptionHandler. Initial and accept
70 * behaviour flags are set to false
71 * <p>
72 * @param termtype - terminal type that will be negotiated.
73 ***/
74 public TerminalTypeOptionHandler(String termtype)
75 {
76 super(TelnetOption.TERMINAL_TYPE, false, false, false, false);
77 termType = termtype;
78 }
79
80 /***
81 * Implements the abstract method of TelnetOptionHandler.
82 * <p>
83 * @param suboptionData - the sequence received, whithout IAC SB & IAC SE
84 * @param suboptionLength - the length of data in suboption_data
85 * <p>
86 * @return terminal type information
87 ***/
88 public int[] answerSubnegotiation(int suboptionData[], int suboptionLength)
89 {
90 if ((suboptionData != null) && (suboptionLength > 1)
91 && (termType != null))
92 {
93 if ((suboptionData[0] == TERMINAL_TYPE)
94 && (suboptionData[1] == TERMINAL_TYPE_SEND))
95 {
96 int response[] = new int[termType.length() + 2];
97
98 response[0] = TERMINAL_TYPE;
99 response[1] = TERMINAL_TYPE_IS;
100
101 for (int ii = 0; ii < termType.length(); ii++)
102 {
103 response[ii + 2] = (int) termType.charAt(ii);
104 }
105
106 return response;
107 }
108 }
109 return null;
110 }
111
112 /***
113 * Implements the abstract method of TelnetOptionHandler.
114 * <p>
115 * @return always null (no response to subnegotiation)
116 ***/
117 public int[] startSubnegotiationLocal()
118 {
119 return null;
120 }
121
122 /***
123 * Implements the abstract method of TelnetOptionHandler.
124 * <p>
125 * @return always null (no response to subnegotiation)
126 ***/
127 public int[] startSubnegotiationRemote()
128 {
129 return null;
130 }
131 }