ReactOS 0.4.16-dev-125-g798ea90
TTelnetHandler Class Reference

#include <ttelhndl.h>

Collaboration diagram for TTelnetHandler:

Public Member Functions

 TTelnetHandler (TNetwork &RefNetwork, TConsole &RefConsole, TParser &RefParser)
 
 ~TTelnetHandler ()
 
DWORD Go (LPVOID pvParams)
 
int get_term ()
 

Private Member Functions

void init ()
 
int escapeIAC (char *buf, int length)
 
void SendIAC (char c)
 
void SendIAC (char c1, char c2)
 
void SendIACParams (char c)
 
void SendIACParams (char c1, char c2)
 
void print_telopt (const char *s, int d)
 
charParseBuffer (char *pszBuffer, char *pszBufferEnd)
 
charParseIAC (char *pszBuffer, char *pszBufferEnd)
 
void do_naws (int width, int height)
 

Private Attributes

int iTermSet
 
int bInBinaryRx
 
int bInBinaryTx
 
int bInEchoTx
 
int bInEchoRx
 
int iWillSGA
 
TNetworkNetwork
 
TConsoleConsole
 
TParserParser
 
charszBuffer
 
chartmpBuffer
 
charansiBufferStart
 
charansiBufferEnd
 
int dwBuffer
 

Detailed Description

Definition at line 8 of file ttelhndl.h.

Constructor & Destructor Documentation

◆ TTelnetHandler()

TTelnetHandler::TTelnetHandler ( TNetwork RefNetwork,
TConsole RefConsole,
TParser RefParser 
)

Definition at line 75 of file ttelhndl.cpp.

76 :
77Network(RefNetwork), Console(RefConsole), Parser(RefParser) {
78 init();
79
80 // Paul Brannan 9/13/98
82 szBuffer = new char [dwBuffer];
84}
int get_buffer_size() const
Definition: tnconfig.h:62
void SetNawsFunc(Naws_func_t func)
Definition: tnetwork.h:31
char * szBuffer
Definition: ttelhndl.h:34
TNetwork & Network
Definition: ttelhndl.h:26
TConsole & Console
Definition: ttelhndl.h:27
TParser & Parser
Definition: ttelhndl.h:28
#define NULL
Definition: types.h:112
TConfig ini
Definition: tnconfig.cpp:45

◆ ~TTelnetHandler()

TTelnetHandler::~TTelnetHandler ( )

Definition at line 95 of file ttelhndl.cpp.

95 {
96 delete[] szBuffer;
97}

Member Function Documentation

◆ do_naws()

void TTelnetHandler::do_naws ( int  width,
int  height 
)
private

◆ escapeIAC()

int TTelnetHandler::escapeIAC ( char buf,
int  length 
)
private

Definition at line 99 of file ttelhndl.cpp.

99 {
100 // The size of buffer must be greater than 2 * length to ensure no memory
101 // out of bounds errors. The 0xff is escaped into 0xff 0xff.
102 char * temp;
103 temp = new char [length * 2];
104 int current=0;
105 for (int x=0; x < length; x++){
106 if (buf[x] == (signed char)IAC)
107 temp[current++]=(char)IAC;
108 temp[current++]=buf[x];
109 }
111 delete [] temp;
112 return current;
113}
unsigned char
Definition: typeof.h:29
#define IAC
Definition: ftp_var.h:13
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
GLuint GLsizei GLsizei * length
Definition: glext.h:6040
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
struct task_struct * current
Definition: linux.c:32
static calc_node_t temp
Definition: rpn_ieee.c:38

Referenced by SendIACParams().

◆ get_term()

int TTelnetHandler::get_term ( )
inline

Definition at line 47 of file ttelhndl.h.

47{return iTermSet;}

◆ Go()

DWORD TTelnetHandler::Go ( LPVOID  pvParams)

Definition at line 485 of file ttelhndl.cpp.

486{
487 NetParams *pParams = (NetParams *)pvParams;
488
489 // No longer a need to copy pParams-> socket and create an instance
490 // of TANSIParser (Paul Brannan 6/15/98)
491
492 Console.sync(); // Sync with the parser so the cursor is positioned
493
494 Parser.Init(); // Reset the parser (Paul Brannan 9/19/98)
495 init(); // Turn on local echo (Paul Brannan 9/19/98)
496
497 *pParams->bNetFinished = 0;
498 char* pszHead = szBuffer;
499 char* pszTail = szBuffer;
500 while (!*pParams->bNetFinish) {
501 // Get data from Socket
502 *pParams->bNetPaused = 1; //Pause
503 int Result = Network.ReadString(pszTail, (szBuffer + dwBuffer) - pszTail);
504
505 // Speed up mouse by not going into loop (Paul Brannan 8/10/98)
506 // while(*pParams->bNetPause && !*pParams->bNetFinish) *pParams->bNetPaused = 1; //Pause
507 if(WaitForSingleObject(pParams->hPause, 0) == WAIT_OBJECT_0)
509
510 *pParams->bNetPaused = 0; //UnPause
511
512 if (Result <= 0 || Result > dwBuffer ){
513 break;
514 }
515 pszTail += Result;
516
517 // Process the buffer
518 char* pszNewHead = pszHead;
519 do {
520 // Speed up mouse by not going into loop (Paul Brannan 8/10/98)
521 if(WaitForSingleObject(pParams->hPause, 0) == WAIT_OBJECT_0) {
522 *pParams->bNetPaused = 1;
524 *pParams->bNetPaused = 0;
525 }
526
527 pszHead = pszNewHead;
528 pszNewHead = ParseBuffer(pszHead, pszTail); // Parse buffer
529 } while ((pszNewHead != pszHead) && (pszNewHead < pszTail) && !*pParams->bNetFinish);
530 pszHead = pszNewHead;
531
532 // When we reach the end of the buffer, move contents to the
533 // beginning of the buffer to get free space at the end.
534 if (pszTail == (szBuffer + dwBuffer)) {
535 memmove(szBuffer, pszHead, pszTail - pszHead);
536 pszTail = szBuffer + (pszTail - pszHead);
537 pszHead = szBuffer;
538 }
539 }
540 SetEvent(pParams->hExit);
541
543 *pParams->bNetPaused = 1; //Pause
544 *pParams->bNetFinished = 1;
545 return 0;
546}
#define MSG_TERMBYREM
Definition: resource.h:15
void sync()
Definition: tconsole.cpp:109
int ReadString(char *str, const int length)
Definition: tnetwork.cpp:67
virtual void Init()=0
char * ParseBuffer(char *pszBuffer, char *pszBufferEnd)
Definition: ttelhndl.cpp:430
#define FALSE
Definition: types.h:117
#define INFINITE
Definition: serial.h:102
#define memmove(s1, s2, n)
Definition: mkisofs.h:881
volatile int * bNetPaused
Definition: tparams.h:8
HANDLE hExit
Definition: tparams.h:6
volatile int * bNetFinish
Definition: tparams.h:10
HANDLE hPause
Definition: tparams.h:7
volatile int * bNetFinished
Definition: tparams.h:9
HANDLE hUnPause
Definition: tparams.h:7
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
BOOL WINAPI DECLSPEC_HOTPATCH SetEvent(IN HANDLE hEvent)
Definition: synch.c:733
int printm(LPTSTR szModule, BOOL fSystem, DWORD dwMessageId,...)
Definition: tnerror.cpp:84
#define WAIT_OBJECT_0
Definition: winbase.h:406
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:409

Referenced by telProcessNetwork().

◆ init()

void TTelnetHandler::init ( )
private

Definition at line 86 of file ttelhndl.cpp.

86 {
87 iTermSet = 0;
88 bInBinaryRx = 0;
89 bInBinaryTx = 0;
90 bInEchoTx = 0;
91 bInEchoRx = 0;
93}
void set_local_echo(BOOL b)
Definition: tnetwork.h:41
int bInBinaryRx
Definition: ttelhndl.h:11
int bInBinaryTx
Definition: ttelhndl.h:11

Referenced by Go(), and TTelnetHandler().

◆ ParseBuffer()

char * TTelnetHandler::ParseBuffer ( char pszBuffer,
char pszBufferEnd 
)
private

Definition at line 430 of file ttelhndl.cpp.

430 {
431 char *pszResult;
432 char *pszHead = pszBuffer;
433
435 while (pszBuffer < pszBufferEnd) {
436 // if IAC then parse IAC
437 if((unsigned char) *pszBuffer == IAC) {
438
439 // check for escaped IAC
440 if((pszBufferEnd >= pszBuffer + 1) &&
441 (unsigned char)*(pszBuffer + 1) == IAC) {
442 // we move data at the front of the buffer to the end so
443 // that if we only have IACs we won't return pszBuffer
444 // even though we did parse something. Returning
445 // pszBuffer is an error condition.
446 memmove(pszHead + 1, pszHead, pszBuffer - pszHead);
447 pszBuffer+=2;
448 pszHead++;
449 }
450 // parse the IAC
451 else {
452 pszResult = ParseIAC(pszBuffer, pszBufferEnd);
453 if(pszBuffer == pszResult) return pszBuffer;
454 // see above regarding moving from front to end.
455 memmove(pszHead + (pszResult - pszBuffer), pszHead,
456 pszBuffer - pszHead);
457 pszHead += (pszResult - pszBuffer);
458 pszBuffer = pszResult;
459 }
460 }
461 // else copy char over to ANSI buffer
462 else {
463 pszBuffer++;
464 }
465 }
466
467 // Not a socket connection, so don't parse out IACs.
468 // (Paul Brannan 3/19/99)
469 } else {
470 pszBuffer = pszBufferEnd;
471 }
472
473 return(Parser.ParseBuffer(pszHead, pszBuffer));
474}
NetworkType get_net_type()
Definition: tnetwork.h:35
virtual char * ParseBuffer(char *pszBuffer, char *pszBufferEnd)=0
char * ParseIAC(char *pszBuffer, char *pszBufferEnd)
Definition: ttelhndl.cpp:182
@ TN_NETSOCKET
Definition: tnetwork.h:8

Referenced by Go().

◆ ParseIAC()

char * TTelnetHandler::ParseIAC ( char pszBuffer,
char pszBufferEnd 
)
private

Definition at line 182 of file ttelhndl.cpp.

183{
184 // int n,l;
185 // char szResponse[40];
186 // Ioannou 29 May 1998 : I prefer the union redefinitions
187 // than the typecasting (used with them from Pascal and Cobol :-) )
188 // FIX ME !!!! Shall we use the winsock routines instead ?
189
190 union {
191 char szResponse[2];
192 int n;
193 };
194
195 // Added support for user-defined term name (Paul Brannan 5/13/98)
196#define LASTTERM 4
197 const char *pszTerms[] = {ini.get_term(), "ANSI","DEC-VT100","DEC-VT52","UNKNOWN"};
198 if(!iTermSet && (pszTerms[0] == 0 || *pszTerms[0] == 0)) iTermSet++;
199
200 if (pszBuffer + 2 < pszBufferEnd) {
201 switch ((unsigned char)pszBuffer[1]) {
202
204 case DO:
205 {
206 switch (pszBuffer[2]){
207 case TELOPT_BINARY:
208 TELOPT_PRINTD("RCVD DO TELOPT_BINARY\n");
209 if (!bInBinaryRx){
211 bInBinaryRx = 1;
212 TELOPT_PRINTD("SENT WILL TELOPT_BINARY\n");
213 }
214 break;
215 case TELOPT_ECHO:
216 // we shouldn't echo for the server! (Paul Brannan 5/30/98)
217 TELOPT_PRINTD2("RCVD DO TELOPT_ECHO", pszBuffer[2]);
219 TELOPT_PRINTD("SENT WONT TELOPT_ECHO\n");
220 break;
221 case TELOPT_TTYPE:
222 TELOPT_PRINTD("RCVD DO TELOPT_TTYPE\n");
224 TELOPT_PRINTD("SENT WILL TELOPT_TTYPE\n");
225 break;
226 case TELOPT_NAWS:
227 TELOPT_PRINTD("RCVD DO TELOPT_NAWS\n");
230
232
233 n = Console.GetWidth();
234 SendIACParams(szResponse[1],szResponse [0]);
235
236 n = Console.GetHeight();
237 SendIACParams(szResponse[1],szResponse[0]);
238
239 SendIAC(SE);
240 TELOPT_PRINTD("SENT WILL TELOPT_NAWS\n");
241 break;
242 case TELOPT_XDISPLOC:
243 TELOPT_PRINTD("RCVD DO TELOPT_XDISPLOC\n");
245 TELOPT_PRINTD("SENT WILL TELOPT_XDISPLOC\n");
246 printit("Retrieving IP...");
247 break;
248 default:
249 TELOPT_PRINTD2("RCVD DO", pszBuffer[2]);
250 SendIAC(WONT, pszBuffer[2]);
251 TELOPT_PRINTD2("SENT WONT", pszBuffer[2]);
252 break;
253 }
254 if (pszBuffer + 2 < pszBufferEnd)
255 pszBuffer += 3;
256 break;
257 }
258
260 case WILL:
261 {
262 switch ((unsigned char)pszBuffer[2]){
263 case TELOPT_BINARY:
264 TELOPT_PRINTD("RCVD WILL TELOPT_BINARY\n");
265 if (!bInBinaryTx){
267 bInBinaryTx = 1;
268 TELOPT_PRINTD("SENT DO TELOPT_BINARY\n");
269 }
270 break;
271 case TELOPT_ECHO:
272 TELOPT_PRINTD2("RCVD WILL TELOPT_ECHO", pszBuffer[2]);
273 if(!bInEchoRx) {
275 bInEchoRx = 1;
276 Network.set_local_echo(0); // Paul Brannan 8/25/98
278 TELOPT_PRINTD2("SENT DO TELOPT_ECHO", pszBuffer[2]);
280 }
281 break;
282
283 // Suppress Go Ahead (Paul Brannan 12/31/98)
284 case TELOPT_SGA:
285 TELOPT_PRINTD("RCVD WILL TELOPT_SGA\n");
286 if(!iWillSGA) {
289 iWillSGA = 1;
290 TELOPT_PRINTD("SENT DO TELOPT_SGA\n");
291 }
292 break;
293
295 default:
296 TELOPT_PRINTD2("RCVD WILL", pszBuffer[2]);
297 SendIAC(DONT, pszBuffer[2]);
298 TELOPT_PRINTD2("SENT DONT", pszBuffer[2]);
299 break;
301 }
302 if (pszBuffer + 2 < pszBufferEnd)
303 pszBuffer += 3;
304 break;
305 }
306
308 case WONT:
309 {
310 switch ((unsigned char)pszBuffer[2]){
311 case TELOPT_ECHO:
312 TELOPT_PRINTD("RCVD WONT TELOPT_ECHO\n");
313 if (bInEchoRx){
315 // bInBinaryRx = 0;
316 bInEchoRx = 0; // Paul Brannan 8/25/98
319 TELOPT_PRINTD("SENT DONT TELOPT_ECHO\n");
320 }
321 break;
322
323 // Suppress Go Ahead (Paul Brannan 12/31/98)
324 case TELOPT_SGA:
325 TELOPT_PRINTD("RCVD WONT TELOPT_SGA\n");
326 if(iWillSGA) {
329 iWillSGA = 0;
330 TELOPT_PRINTD("SENT DONT TELOPT_SGA\n");
331 }
332 break;
333
334 default:
335 TELOPT_PRINTD2("RCVD WONT", pszBuffer[2]);
336 break;
337 }
338 if (pszBuffer + 2 < pszBufferEnd)
339 pszBuffer += 3;
340 break;
341 }
342
344 case DONT:
345 {
346 switch ((unsigned char)pszBuffer[2]){
347 case TELOPT_ECHO:
348 TELOPT_PRINTD("RCVD DONT TELOPT_ECHO\n");
349 if (bInEchoTx){
351 bInEchoTx = 0;
352 TELOPT_PRINTD("SENT WONT TELOPT_ECHO\n");
353 }
354 break;
355 case TELOPT_NAWS:
356 TELOPT_PRINTD("RCVD DONT TELOPT_NAWS\n");
359 TELOPT_PRINTD("SENT WONT TELOPT_NAWS\n");
360 break;
361 default:
362 TELOPT_PRINTD2("RCVD DONT", pszBuffer[2]);
363 break;
364 }
365 if (pszBuffer + 2 < pszBufferEnd)
366 pszBuffer += 3;
367 break;
368 }
369
371 case SB:
372 {
373 switch ((unsigned char)pszBuffer[2]){
374 case TELOPT_TTYPE:
375 if (pszBuffer + 5 < pszBufferEnd) {
376 TELOPT_PRINTD("RCVD SB TELOPT_TTYPE\n");
377 if (pszBuffer[3] == 1){
378 TELOPT_PRINTD("SENT SB TT");
379 TELOPT_PRINTD(pszTerms[iTermSet]);
380 TELOPT_PRINTD("\n");
382 SendIACParams(0);
383 Network.WriteString(pszTerms[iTermSet], strlen(pszTerms[iTermSet]));
384 SendIAC(SE);
385
386 if (iTermSet < LASTTERM )
387 iTermSet+=1;
388 }
389 if (pszBuffer + 5 < pszBufferEnd)
390 pszBuffer += 6;
391 }
392 break;
393 case TELOPT_XDISPLOC:
394 if(pszBuffer + 5 < pszBufferEnd) {
395 TELOPT_PRINTD("RCVD SB XDISPLOC\n");
397 TELOPT_PRINTD("SENT SB XDISPLOC");
398 SendIACParams(0);
402 TELOPT_PRINTD("\n");
403 SendIAC(SE);
404 if (pszBuffer + 5 < pszBufferEnd)
405 pszBuffer += 6;
406 }
407 break;
408 default: break;
409 }
410 break;
411 }
412 default:
413 pszBuffer += 2;
414 break;
415 }
416 }
417 return pszBuffer;
418}
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
const char * get_term() const
Definition: tnconfig.h:37
int GetWidth()
Definition: tconsole.h:81
int GetHeight()
Definition: tconsole.h:82
void set_line_mode(BOOL b)
Definition: tnetwork.h:44
int WriteString(const char *str, const int length)
Definition: tnetwork.cpp:53
BOOL get_local_echo()
Definition: tnetwork.h:40
const char * GetLocalAddress()
Definition: tnetwork.h:33
void SendIACParams(char c)
Definition: ttelhndl.cpp:126
void SendIAC(char c)
Definition: ttelhndl.cpp:116
#define SE
Definition: ftp_var.h:28
#define WONT
Definition: ftp_var.h:16
#define WILL
Definition: ftp_var.h:17
#define SB
Definition: ftp_var.h:18
#define DO
Definition: ftp_var.h:15
#define DONT
Definition: ftp_var.h:14
GLdouble n
Definition: glext.h:7729
#define TELOPT_BINARY
Definition: telnet.h:70
#define TELOPT_SGA
Definition: telnet.h:73
#define TELOPT_TTYPE
Definition: telnet.h:94
#define TELOPT_XDISPLOC
Definition: telnet.h:105
#define TELOPT_NAWS
Definition: telnet.h:101
#define TELOPT_ECHO
Definition: telnet.h:71
int printit(const char *it)
Definition: tnerror.cpp:58
#define TELOPT_PRINTD(x)
Definition: ttelhndl.cpp:59
#define TELOPT_PRINTD2(x, n)
Definition: ttelhndl.cpp:60
#define LASTTERM
int naws_string(char *buf, int width, int height)
Definition: ttelhndl.cpp:139

Referenced by ParseBuffer().

◆ print_telopt()

void TTelnetHandler::print_telopt ( const char s,
int  d 
)
private

◆ SendIAC() [1/2]

void TTelnetHandler::SendIAC ( char  c)
private

Definition at line 116 of file ttelhndl.cpp.

116 {
117 static char buf[2] = {IAC};
118 buf[1] = c;
120}
#define c
Definition: ke_i.h:80

Referenced by ParseIAC().

◆ SendIAC() [2/2]

void TTelnetHandler::SendIAC ( char  c1,
char  c2 
)
private

Definition at line 121 of file ttelhndl.cpp.

121 {
122 static char buf[3] = {IAC};
123 buf[1] = c1; buf[2] = c2;
125}

◆ SendIACParams() [1/2]

void TTelnetHandler::SendIACParams ( char  c)
private

Definition at line 126 of file ttelhndl.cpp.

126 {
127 static char buf[2];
128 buf[0] = c;
129 static int length = escapeIAC(buf, 1);
131}
int escapeIAC(char *buf, int length)
Definition: ttelhndl.cpp:99

Referenced by ParseIAC().

◆ SendIACParams() [2/2]

void TTelnetHandler::SendIACParams ( char  c1,
char  c2 
)
private

Definition at line 132 of file ttelhndl.cpp.

132 {
133 static char buf[4];
134 buf[0] = c1; buf[1] = c2;
135 static int length = escapeIAC(buf, 2);
137}

Member Data Documentation

◆ ansiBufferEnd

char * TTelnetHandler::ansiBufferEnd
private

Definition at line 35 of file ttelhndl.h.

◆ ansiBufferStart

char* TTelnetHandler::ansiBufferStart
private

Definition at line 35 of file ttelhndl.h.

◆ bInBinaryRx

int TTelnetHandler::bInBinaryRx
private

Definition at line 11 of file ttelhndl.h.

Referenced by init(), and ParseIAC().

◆ bInBinaryTx

int TTelnetHandler::bInBinaryTx
private

Definition at line 11 of file ttelhndl.h.

Referenced by init(), and ParseIAC().

◆ bInEchoRx

int TTelnetHandler::bInEchoRx
private

Definition at line 12 of file ttelhndl.h.

Referenced by init(), and ParseIAC().

◆ bInEchoTx

int TTelnetHandler::bInEchoTx
private

Definition at line 12 of file ttelhndl.h.

Referenced by init(), and ParseIAC().

◆ Console

TConsole& TTelnetHandler::Console
private

Definition at line 27 of file ttelhndl.h.

Referenced by Go(), and ParseIAC().

◆ dwBuffer

int TTelnetHandler::dwBuffer
private

Definition at line 36 of file ttelhndl.h.

Referenced by Go(), and TTelnetHandler().

◆ iTermSet

int TTelnetHandler::iTermSet
private

Definition at line 10 of file ttelhndl.h.

Referenced by get_term(), init(), and ParseIAC().

◆ iWillSGA

int TTelnetHandler::iWillSGA
private

Definition at line 13 of file ttelhndl.h.

Referenced by ParseIAC().

◆ Network

TNetwork& TTelnetHandler::Network
private

Definition at line 26 of file ttelhndl.h.

Referenced by Go(), init(), ParseBuffer(), ParseIAC(), SendIAC(), SendIACParams(), and TTelnetHandler().

◆ Parser

TParser& TTelnetHandler::Parser
private

Definition at line 28 of file ttelhndl.h.

Referenced by Go(), and ParseBuffer().

◆ szBuffer

char* TTelnetHandler::szBuffer
private

Definition at line 34 of file ttelhndl.h.

Referenced by Go(), TTelnetHandler(), and ~TTelnetHandler().

◆ tmpBuffer

char * TTelnetHandler::tmpBuffer
private

Definition at line 34 of file ttelhndl.h.


The documentation for this class was generated from the following files: