diff options
author | Mike Buland <eichlan@xagasoft.com> | 2007-04-03 03:49:53 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2007-04-03 03:49:53 +0000 |
commit | f4c20290509d7ed3a8fd5304577e7a4cc0b9d974 (patch) | |
tree | 13cdf64f7cf134f397a7165b7a3fe0807e37026b /src/protocoltelnet.cpp | |
parent | 74d4c8cd27334fc7204d5a8773deb3d424565778 (diff) | |
download | libbu++-f4c20290509d7ed3a8fd5304577e7a4cc0b9d974.tar.gz libbu++-f4c20290509d7ed3a8fd5304577e7a4cc0b9d974.tar.bz2 libbu++-f4c20290509d7ed3a8fd5304577e7a4cc0b9d974.tar.xz libbu++-f4c20290509d7ed3a8fd5304577e7a4cc0b9d974.zip |
Ok, no code is left in src, it's all in src/old. We'll gradually move code back
into src as it's fixed and re-org'd. This includes tests, which, I may write a
unit test system into libbu++ just to make my life easier.
Diffstat (limited to 'src/protocoltelnet.cpp')
-rw-r--r-- | src/protocoltelnet.cpp | 316 |
1 files changed, 0 insertions, 316 deletions
diff --git a/src/protocoltelnet.cpp b/src/protocoltelnet.cpp deleted file mode 100644 index b169a51..0000000 --- a/src/protocoltelnet.cpp +++ /dev/null | |||
@@ -1,316 +0,0 @@ | |||
1 | #include "protocoltelnet.h" | ||
2 | #include <string.h> | ||
3 | |||
4 | ProtocolTelnet::ProtocolTelnet() | ||
5 | { | ||
6 | nTermType = termUnInited; | ||
7 | bEchoOn = true; | ||
8 | } | ||
9 | |||
10 | ProtocolTelnet::~ProtocolTelnet() | ||
11 | { | ||
12 | } | ||
13 | |||
14 | bool ProtocolTelnet::onNewConnection() | ||
15 | { | ||
16 | Connection *pCon = getConnection(); | ||
17 | |||
18 | pCon->appendOutput( (char)IAC ); | ||
19 | pCon->appendOutput( (char)WILL ); | ||
20 | pCon->appendOutput( (char)SUPPRESSGA ); | ||
21 | |||
22 | pCon->appendOutput( (char)IAC ); | ||
23 | pCon->appendOutput( (char)DO ); | ||
24 | pCon->appendOutput( (char)SUPPRESSGA ); | ||
25 | |||
26 | pCon->appendOutput( (char)IAC ); | ||
27 | pCon->appendOutput( (char)DONT ); | ||
28 | pCon->appendOutput( (char)TERMTYPE ); | ||
29 | |||
30 | // pCon->appendOutput( IAC ); | ||
31 | // pCon->appendOutput( SB ); | ||
32 | // pCon->appendOutput( TERMTYPE ); | ||
33 | // pCon->appendOutput( 1 ); | ||
34 | // pCon->appendOutput( IAC ); | ||
35 | // pCon->appendOutput( SE ); | ||
36 | |||
37 | pCon->appendOutput( (char)IAC ); | ||
38 | pCon->appendOutput( (char)DONT ); | ||
39 | pCon->appendOutput( (char)ECHO ); | ||
40 | |||
41 | pCon->appendOutput( (char)IAC ); | ||
42 | pCon->appendOutput( (char)WILL ); | ||
43 | pCon->appendOutput( (char)ECHO ); | ||
44 | |||
45 | // 255(IAC),251(WILL),3 | ||
46 | return true; | ||
47 | } | ||
48 | |||
49 | bool ProtocolTelnet::onNewData() | ||
50 | { | ||
51 | Connection *pCon = getConnection(); | ||
52 | if( !pCon->hasInput() ) | ||
53 | { | ||
54 | return true; | ||
55 | } | ||
56 | |||
57 | int nInSize = pCon->getInputAmnt(); | ||
58 | char *lpInStr = (char *)pCon->getInput(); | ||
59 | |||
60 | // Here we interpret the basic commands and un-encapsulate them, so to | ||
61 | // speak. We'll allow this, even if the terminal is in raw mode, we | ||
62 | // just won't send anything in response... | ||
63 | for( int j = 0; j < nInSize; j++ ) | ||
64 | { | ||
65 | switch( (unsigned char)lpInStr[j] ) | ||
66 | { | ||
67 | case '\r': | ||
68 | fbEdited.appendData('\n'); | ||
69 | if( bEchoOn ) pCon->appendOutput("\n\r"); | ||
70 | break; | ||
71 | |||
72 | case '\n': | ||
73 | break; | ||
74 | |||
75 | case '\177': // backspace | ||
76 | if( fbEdited.getLength() > 0 ) | ||
77 | { | ||
78 | fbEdited.usedData( -1 ); // Delete one char from the end | ||
79 | if( bEchoOn ) pCon->appendOutput(ESC "[D"); // Move the cursor back one | ||
80 | if( bEchoOn ) pCon->appendOutput(ESC "[P"); // Delete one character | ||
81 | } | ||
82 | break; | ||
83 | |||
84 | case '\x1B': // escape sequence | ||
85 | if( (unsigned char)lpInStr[j+1] == '[' ) | ||
86 | { | ||
87 | switch( (unsigned char)lpInStr[j+2] ) | ||
88 | { | ||
89 | case 'A': // Up | ||
90 | break; | ||
91 | |||
92 | case 'B': // Down | ||
93 | break; | ||
94 | |||
95 | case 'C': // Right | ||
96 | break; | ||
97 | |||
98 | case 'D': // Left | ||
99 | break; | ||
100 | } | ||
101 | j+=2; | ||
102 | } | ||
103 | break; | ||
104 | |||
105 | case 0: // NOP: No operation | ||
106 | break; | ||
107 | |||
108 | case IAC: // IAC: Interpret as command | ||
109 | switch( lpInStr[j+1] ) | ||
110 | { | ||
111 | case SE: // SE: End of subnegotiation parameters. | ||
112 | break; | ||
113 | |||
114 | case NOP: // NOP: No operation | ||
115 | break; | ||
116 | |||
117 | case DM: // DM: Data mark. Indicates the position of a Synch event within the data stream. This should always be accompanied by a TCP urgent notification. | ||
118 | break; | ||
119 | |||
120 | case BRK: // BRK: Break. Indicates that the "break" or "attention" key was hit. | ||
121 | break; | ||
122 | |||
123 | case IP: // IP: Suspend, interrupt or abort the process to which the NVT is connected. | ||
124 | break; | ||
125 | |||
126 | case AO: // AO: Abort output. Allows the current process to run to completion but do not send its output to the user. | ||
127 | break; | ||
128 | |||
129 | case AYT: // AYT: Are you there. Send back to the NVT some visible evidence that the AYT was received. | ||
130 | break; | ||
131 | |||
132 | case EC: // EC: Erase character. The receiver should delete the last preceding undeleted character from the data stream. | ||
133 | break; | ||
134 | |||
135 | case EL: // EL: Erase line. Delete characters from the data stream back to but not including the previous CRLF. | ||
136 | break; | ||
137 | |||
138 | case GA: // GA: Go ahead. Used, under certain circumstances, to tell the other end that it can transmit. | ||
139 | break; | ||
140 | |||
141 | case SB: // SB: Subnegotiation of the indicated option follows. | ||
142 | switch( lpInStr[j+2] ) | ||
143 | { | ||
144 | case TERMTYPE: | ||
145 | if( lpInStr[j+3] == 0 ) | ||
146 | { | ||
147 | for( int k = 0; j+4+k < nInSize; k++ ) | ||
148 | { | ||
149 | if( (unsigned char)lpInStr[j+4+k] == IAC && | ||
150 | (unsigned char)lpInStr[j+5+k] == SE ) | ||
151 | { | ||
152 | lpInStr[j+4+k] = 0; | ||
153 | //@TODO: Do something with the term type... | ||
154 | printf("Term type: %s\n", &lpInStr[j+4] ); | ||
155 | j += 5+k; | ||
156 | } | ||
157 | } | ||
158 | } | ||
159 | else | ||
160 | { | ||
161 | } | ||
162 | break; | ||
163 | |||
164 | default: | ||
165 | //printf("unknown subnegotiation parameters! (%d)\n", lpInStr[j+2] ); | ||
166 | break; | ||
167 | } | ||
168 | break; | ||
169 | |||
170 | case WILL: // WILL: Indicates the desire to begin performing | ||
171 | switch( lpInStr[j+2] ) | ||
172 | { | ||
173 | case SUPPRESSGA: | ||
174 | j += 2; | ||
175 | // pCon->usedInput( 3 ); | ||
176 | break; | ||
177 | |||
178 | case TERMTYPE: | ||
179 | j += 2; | ||
180 | // pCon->usedInput( 3 ); | ||
181 | break; | ||
182 | |||
183 | case ECHO: | ||
184 | j += 2; | ||
185 | // pCon->usedInput( 3 ); | ||
186 | break; | ||
187 | |||
188 | case NAWS: | ||
189 | default: | ||
190 | pCon->appendOutput( (char)ESC[0] ); | ||
191 | pCon->appendOutput( (char)DONT ); | ||
192 | pCon->appendOutput( lpInStr[j+2] ); | ||
193 | //printf("unknown will command used! (%d)\n", lpInStr[j+2] ); | ||
194 | j += 2; | ||
195 | break; | ||
196 | } | ||
197 | break; | ||
198 | |||
199 | case WONT: // WONT: Indicates the refusal to perform | ||
200 | switch( lpInStr[j+2] ) | ||
201 | { | ||
202 | case ECHO: | ||
203 | j += 2; | ||
204 | // pCon->usedInput( 3 ); | ||
205 | break; | ||
206 | |||
207 | default: | ||
208 | //printf("unknown wont command used! (%d)\n", lpInStr[j+2] ); | ||
209 | j += 2; | ||
210 | break; | ||
211 | } | ||
212 | break; | ||
213 | |||
214 | case DO: // DO: Indicates the request that the other party perform | ||
215 | switch( lpInStr[j+2] ) | ||
216 | { | ||
217 | case ECHO: | ||
218 | j += 2; | ||
219 | break; | ||
220 | |||
221 | case SUPPRESSGA: | ||
222 | j += 2; | ||
223 | break; | ||
224 | |||
225 | default: | ||
226 | pCon->appendOutput( (char)ESC[0] ); | ||
227 | pCon->appendOutput( (char)DONT ); | ||
228 | pCon->appendOutput( lpInStr[j+2] ); | ||
229 | //printf("unknown do command used! (%d)\n", lpInStr[j+2] ); | ||
230 | j += 2; | ||
231 | break; | ||
232 | } | ||
233 | // pCon->usedInput( 3 ); | ||
234 | break; | ||
235 | |||
236 | case DONT: // DONT: Indicates the demand that the other party stop performing | ||
237 | switch( lpInStr[j+2] ) | ||
238 | { | ||
239 | case ECHO: | ||
240 | j += 2; | ||
241 | // pCon->usedInput( 3 ); | ||
242 | break; | ||
243 | |||
244 | default: | ||
245 | printf("unknown dont command used! (%d)\n", lpInStr[j+2] ); | ||
246 | j += 2; | ||
247 | break; | ||
248 | } | ||
249 | break; | ||
250 | } | ||
251 | break; | ||
252 | |||
253 | default: | ||
254 | fbEdited.appendData( lpInStr[j] ); | ||
255 | if( bEchoOn ) pCon->appendOutput( lpInStr[j] ); | ||
256 | break; | ||
257 | } | ||
258 | } | ||
259 | |||
260 | pCon->usedInput( pCon->getInputAmnt() ); | ||
261 | |||
262 | return true; | ||
263 | } | ||
264 | |||
265 | char *ProtocolTelnet::getLine( bool bFullOnly ) | ||
266 | { | ||
267 | int i = fbEdited.findChar('\n'); | ||
268 | |||
269 | if( i < 0 ) | ||
270 | { | ||
271 | if( bFullOnly == false ) | ||
272 | { | ||
273 | i = fbEdited.getLength(); | ||
274 | } | ||
275 | else | ||
276 | { | ||
277 | return NULL; | ||
278 | } | ||
279 | } | ||
280 | |||
281 | char *lpStr = new char[i+1]; | ||
282 | strncpy( lpStr, fbEdited.getData(), i ); | ||
283 | lpStr[i] = '\0'; | ||
284 | |||
285 | fbEdited.usedData( i+1 ); | ||
286 | |||
287 | return lpStr; | ||
288 | } | ||
289 | |||
290 | char *ProtocolTelnet::peekLine( bool bFullOnly ) | ||
291 | { | ||
292 | int i = fbEdited.findChar('\n'); | ||
293 | |||
294 | if( i < 0 ) | ||
295 | { | ||
296 | if( bFullOnly == false ) | ||
297 | { | ||
298 | i = fbEdited.getLength(); | ||
299 | } | ||
300 | else | ||
301 | { | ||
302 | return NULL; | ||
303 | } | ||
304 | } | ||
305 | |||
306 | char *lpStr = new char[i+1]; | ||
307 | strncpy( lpStr, fbEdited.getData(), i ); | ||
308 | lpStr[i] = '\0'; | ||
309 | |||
310 | return lpStr; | ||
311 | } | ||
312 | |||
313 | void ProtocolTelnet::setEcho( bool bEchoOn ) | ||
314 | { | ||
315 | this->bEchoOn = bEchoOn; | ||
316 | } | ||