Fix for BINARY handshake with SyncTerm

This commit is contained in:
mysticbbs 2013-02-17 17:36:24 -05:00
parent e14b8aadaa
commit 95b48236cd
1 changed files with 67 additions and 2 deletions

View File

@ -2,6 +2,8 @@ Unit m_io_Sockets;
{$I M_OPS.PAS} {$I M_OPS.PAS}
{.$DEFINE TNDEBUG}
Interface Interface
Uses Uses
@ -97,6 +99,43 @@ Const
FPSENDOPT = 0; FPSENDOPT = 0;
FPRECVOPT = 0; FPRECVOPT = 0;
{$IFDEF TNDEBUG}
Function CommandType (C: Char) : String;
Begin
Case C of
TELNET_WILL : Result := 'WILL';
TELNET_WONT : Result := 'WONT';
TELNET_DO : Result := 'DO';
TELNET_DONT : Result := 'DONT';
TELNET_SB : Result := 'SB';
Telnet_IAC : Result := 'IAC';
Telnet_BINARY : Result := 'BINARY';
Telnet_ECHO : Result := 'ECHO';
Telnet_SE : Result := 'SE';
Telnet_TERM : Result := 'TERM';
Telnet_SGA : Result := 'SGA';
Else
Result := 'UNKNOWN';
End;
Result := Result + ' Ord:' + strI2S(Ord(C));
End;
Procedure TNLOG (Str: String);
Var
T : Text;
Begin
Assign (T, 'tnlog.txt');
{$I-} Append(T); {$I+}
If IoResult <> 0 Then ReWrite(T);
WriteLn(T, Str);
Close(T);
End;
{$ENDIF}
Constructor TIOSocket.Create; Constructor TIOSocket.Create;
Begin Begin
Inherited Create; Inherited Create;
@ -263,6 +302,10 @@ Procedure TIOSocket.TelnetInBuffer (Var Buf: TIOBuffer; Var Len: LongInt);
Reply[3] := CmdType; Reply[3] := CmdType;
fpSend (FSocketHandle, @Reply[1], 3, FPSENDOPT); fpSend (FSocketHandle, @Reply[1], 3, FPSENDOPT);
{$IFDEF TNDEBUG}
TNLOG ('InBuffer -> Sending response: ' + CommandType(YesNo) + ' ' + CommandType(CmdType));
{$ENDIF}
End; End;
Procedure SendData (CmdType: Char; Data: String); Procedure SendData (CmdType: Char; Data: String);
@ -283,6 +326,10 @@ Procedure TIOSocket.TelnetInBuffer (Var Buf: TIOBuffer; Var Len: LongInt);
Reply[7 + DataLen] := Telnet_SE; Reply[7 + DataLen] := Telnet_SE;
fpSend (FSocketHandle, @Reply[1], 7 + DataLen, FPSENDOPT); fpSend (FSocketHandle, @Reply[1], 7 + DataLen, FPSENDOPT);
{$IFDEF TNDEBUG}
TNLOG ('InBuffer -> Sending data response');
{$ENDIF}
End; End;
Var Var
@ -300,6 +347,10 @@ Begin
FTelnetState := 0; FTelnetState := 0;
Temp[TempPos] := Telnet_IAC; Temp[TempPos] := Telnet_IAC;
Inc (TempPos); Inc (TempPos);
{$IFDEF TNDEBUG}
TNLOG ('InBuffer -> Escaped IAC (2x255) to 1 character');
{$ENDIF}
End Else Begin End Else Begin
Inc (FTelnetState); Inc (FTelnetState);
FTelnetCmd := Buf[Count]; FTelnetCmd := Buf[Count];
@ -307,6 +358,10 @@ Begin
2 : Begin 2 : Begin
FTelnetState := 0; FTelnetState := 0;
{$IFDEF TNDEBUG}
TNLOG ('InBuffer -> Received telnet command: ' + CommandType(FTelnetCmd) + ' ' + CommandType(Buf[Count]));
{$ENDIF}
Case FTelnetCmd of Case FTelnetCmd of
Telnet_WONT : Begin Telnet_WONT : Begin
// FTelnetSubCmd := Telnet_DONT; // FTelnetSubCmd := Telnet_DONT;
@ -346,6 +401,7 @@ Begin
Case Buf[Count] of Case Buf[Count] of
Telnet_ECHO : FTelnetEcho := True; Telnet_ECHO : FTelnetEcho := True;
Telnet_SGA : ; Telnet_SGA : ;
Telnet_BINARY : ;
Else Else
SendCommand(ReplyBad, Buf[Count]); SendCommand(ReplyBad, Buf[Count]);
End; End;
@ -573,6 +629,15 @@ Begin
TELNET_IAC + TELNET_WILL + TELNET_SGA + TELNET_IAC + TELNET_WILL + TELNET_SGA +
TELNET_IAC + TELNET_DO + TELNET_BINARY); TELNET_IAC + TELNET_DO + TELNET_BINARY);
{$IFDEF TNDEBUG}
If FTelnetServer Then Begin
TNLOG('New server connection');
TNLOG('Sending: IAC WILL ECHO');
TNLOG('Sending: IAC WILL SGA');
TNLOG('Sending: IAC DO BINARY');
End;
{$ENDIF}
Result := Client; Result := Client;
End; End;