Reverted back to older version
This commit is contained in:
parent
379523d459
commit
3894f706ca
|
@ -79,69 +79,24 @@ Type
|
||||||
|
|
||||||
Implementation
|
Implementation
|
||||||
|
|
||||||
{.$DEFINE SOCKETLOG}
|
|
||||||
|
|
||||||
{ TELNET NEGOTIATION CONSTANTS }
|
{ TELNET NEGOTIATION CONSTANTS }
|
||||||
|
|
||||||
Const
|
Const
|
||||||
Telnet_IAC = #255;
|
Telnet_IAC = #255;
|
||||||
Telnet_DONT = #254;
|
Telnet_DONT = #254;
|
||||||
Telnet_DO = #253;
|
Telnet_DO = #253;
|
||||||
Telnet_WONT = #252;
|
Telnet_WONT = #252;
|
||||||
Telnet_WILL = #251;
|
Telnet_WILL = #251;
|
||||||
Telnet_SB = #250;
|
Telnet_SB = #250;
|
||||||
Telnet_BINARY = #000;
|
Telnet_BINARY = #000;
|
||||||
Telnet_ECHO = #001;
|
Telnet_ECHO = #001;
|
||||||
Telnet_SE = #240;
|
Telnet_SE = #240;
|
||||||
Telnet_TERM = #24;
|
Telnet_TERM = #24;
|
||||||
Telnet_SGA = #003;
|
Telnet_SGA = #003;
|
||||||
Telnet_WINSIZE = #31;
|
|
||||||
Telnet_SPEED = #32;
|
|
||||||
Telnet_FLOW = #33;
|
|
||||||
Telnet_LINEMODE = #34;
|
|
||||||
|
|
||||||
FPSENDOPT = 0;
|
FPSENDOPT = 0;
|
||||||
FPRECVOPT = 0;
|
FPRECVOPT = 0;
|
||||||
|
|
||||||
{$IFDEF SOCKETLOG}
|
|
||||||
Function sCmd (C: Char) : String;
|
|
||||||
Begin
|
|
||||||
Case C of
|
|
||||||
Telnet_IAC : Result := ' IAC ';
|
|
||||||
Telnet_DONT : Result := ' DONT ';
|
|
||||||
Telnet_DO : Result := ' DO ';
|
|
||||||
Telnet_WONT : Result := ' WONT ';
|
|
||||||
Telnet_WILL : Result := ' WILL ';
|
|
||||||
Telnet_SB : Result := ' SB ';
|
|
||||||
Telnet_BINARY : Result := ' BINARY ';
|
|
||||||
Telnet_ECHO : Result := ' ECHO ';
|
|
||||||
Telnet_SE : Result := ' SE ';
|
|
||||||
Telnet_TERM : Result := ' TERM ';
|
|
||||||
Telnet_SGA : Result := ' SGA ';
|
|
||||||
Telnet_WINSIZE : Result := ' WINSIZE ';
|
|
||||||
Telnet_SPEED : Result := ' SPEED ';
|
|
||||||
Telnet_FLOW : Result := ' FLOW ';
|
|
||||||
Telnet_LINEMODE : Result := ' LINEMODE ';
|
|
||||||
Else
|
|
||||||
Result := ' UNKNOWN ' + strI2S(Ord(C)) + ' ';
|
|
||||||
End;
|
|
||||||
End;
|
|
||||||
|
|
||||||
Procedure sLog (S: String);
|
|
||||||
Var
|
|
||||||
T : Text;
|
|
||||||
Begin
|
|
||||||
Assign (T, 'socket.log');
|
|
||||||
Append (T);
|
|
||||||
|
|
||||||
If IoResult <> 0 Then ReWrite(T);
|
|
||||||
|
|
||||||
WriteLn(T, S);
|
|
||||||
|
|
||||||
Close(T);
|
|
||||||
End;
|
|
||||||
{$ENDIF}
|
|
||||||
|
|
||||||
Constructor TIOSocket.Create;
|
Constructor TIOSocket.Create;
|
||||||
Begin
|
Begin
|
||||||
Inherited Create;
|
Inherited Create;
|
||||||
|
@ -154,7 +109,7 @@ Begin
|
||||||
FInBufEnd := 0;
|
FInBufEnd := 0;
|
||||||
FOutBufPos := 0;
|
FOutBufPos := 0;
|
||||||
FTelnetState := 0;
|
FTelnetState := 0;
|
||||||
FTelnetEcho := True;
|
FTelnetEcho := False;
|
||||||
FTelnetClient := False;
|
FTelnetClient := False;
|
||||||
FTelnetServer := False;
|
FTelnetServer := False;
|
||||||
FDisconnect := True;
|
FDisconnect := True;
|
||||||
|
@ -188,9 +143,6 @@ Begin
|
||||||
Result := fpSend(FSocketHandle, @Buf, Len, FPSENDOPT);
|
Result := fpSend(FSocketHandle, @Buf, Len, FPSENDOPT);
|
||||||
|
|
||||||
While (Result = -1) and (SocketError = ESOCKEWOULDBLOCK) Do Begin
|
While (Result = -1) and (SocketError = ESOCKEWOULDBLOCK) Do Begin
|
||||||
|
|
||||||
{$IFDEF SOCKETLOG} sLog('WriteBuf Blocking'); {$ENDIF}
|
|
||||||
|
|
||||||
WaitMS(10);
|
WaitMS(10);
|
||||||
|
|
||||||
Result := fpSend(FSocketHandle, @Buf, Len, FPSENDOPT);
|
Result := fpSend(FSocketHandle, @Buf, Len, FPSENDOPT);
|
||||||
|
@ -294,8 +246,6 @@ Begin
|
||||||
Result := fpSend(FSocketHandle, @Temp, TempPos, FPSENDOPT);
|
Result := fpSend(FSocketHandle, @Temp, TempPos, FPSENDOPT);
|
||||||
|
|
||||||
While (Result = -1) and (SocketError = ESOCKEWOULDBLOCK) Do Begin
|
While (Result = -1) and (SocketError = ESOCKEWOULDBLOCK) Do Begin
|
||||||
{$IFDEF SOCKETLOG} sLog('WriteBuf Blocking'); {$ENDIF}
|
|
||||||
|
|
||||||
WaitMS(10);
|
WaitMS(10);
|
||||||
|
|
||||||
Result := fpSend(FSocketHandle, @Temp, TempPos, FPSENDOPT);
|
Result := fpSend(FSocketHandle, @Temp, TempPos, FPSENDOPT);
|
||||||
|
@ -313,8 +263,6 @@ 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 SOCKETLOG} sLog('Sending cmd: ' + sCmd(YesNo) + sCmd(CmdType)); sLog(''); {$ENDIF}
|
|
||||||
End;
|
End;
|
||||||
|
|
||||||
Procedure SendData (CmdType: Char; Data: String);
|
Procedure SendData (CmdType: Char; Data: String);
|
||||||
|
@ -335,8 +283,6 @@ 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 SOCKETLOG} sLog('Sending data: ' + sCmd(CmdType) + Data); {$ENDIF}
|
|
||||||
End;
|
End;
|
||||||
|
|
||||||
Var
|
Var
|
||||||
|
@ -349,8 +295,6 @@ Begin
|
||||||
TempPos := 0;
|
TempPos := 0;
|
||||||
|
|
||||||
For Count := 0 to Len - 1 Do Begin
|
For Count := 0 to Len - 1 Do Begin
|
||||||
{$IFDEF SOCKETLOG} sLog('State loop: ' + strI2S(FTelnetState) + ' Cmd: ' + sCmd(Buf[Count]));{$ENDIF}
|
|
||||||
|
|
||||||
Case FTelnetState of
|
Case FTelnetState of
|
||||||
1 : If Buf[Count] = Telnet_IAC Then Begin
|
1 : If Buf[Count] = Telnet_IAC Then Begin
|
||||||
FTelnetState := 0;
|
FTelnetState := 0;
|
||||||
|
@ -361,7 +305,7 @@ Begin
|
||||||
FTelnetCmd := Buf[Count];
|
FTelnetCmd := Buf[Count];
|
||||||
End;
|
End;
|
||||||
2 : Begin
|
2 : Begin
|
||||||
FTelnetState := 0; // reset state after command
|
FTelnetState := 0;
|
||||||
|
|
||||||
Case FTelnetCmd of
|
Case FTelnetCmd of
|
||||||
Telnet_WONT : Begin
|
Telnet_WONT : Begin
|
||||||
|
@ -386,17 +330,26 @@ Begin
|
||||||
ReplyBad := Telnet_DONT;
|
ReplyBad := Telnet_DONT;
|
||||||
End;
|
End;
|
||||||
|
|
||||||
Case Buf[Count] of
|
If FTelnetClient Then Begin
|
||||||
Telnet_BINARY,
|
Case Buf[Count] of
|
||||||
Telnet_ECHO,
|
Telnet_BINARY,
|
||||||
Telnet_SGA,
|
Telnet_ECHO,
|
||||||
Telnet_TERM : SendCommand(ReplyGood, Buf[Count])
|
Telnet_SGA,
|
||||||
Else
|
Telnet_TERM : SendCommand(ReplyGood, Buf[Count])
|
||||||
SendCommand(ReplyBad, Buf[Count]);
|
Else
|
||||||
End;
|
SendCommand(ReplyBad, Buf[Count]);
|
||||||
|
End;
|
||||||
|
|
||||||
If Buf[Count] = Telnet_Echo Then
|
If Buf[Count] = Telnet_Echo Then
|
||||||
FTelnetEcho := False;
|
FTelnetEcho := False;//(FTelnetCmd = Telnet_DO);
|
||||||
|
End Else Begin
|
||||||
|
Case Buf[Count] of
|
||||||
|
Telnet_ECHO : FTelnetEcho := True;
|
||||||
|
Telnet_SGA : ;
|
||||||
|
Else
|
||||||
|
SendCommand(ReplyBad, Buf[Count]);
|
||||||
|
End;
|
||||||
|
End;
|
||||||
End;
|
End;
|
||||||
End;
|
End;
|
||||||
End;
|
End;
|
||||||
|
@ -412,10 +365,9 @@ Begin
|
||||||
FTelnetSubData := FTelnetSubData + Buf[Count];
|
FTelnetSubData := FTelnetSubData + Buf[Count];
|
||||||
Else
|
Else
|
||||||
If Buf[Count] = Telnet_IAC Then Begin
|
If Buf[Count] = Telnet_IAC Then Begin
|
||||||
Inc (FTelnetState); // might need to make this := 1;
|
Inc (FTelnetState);
|
||||||
End Else Begin
|
End Else Begin
|
||||||
Temp[TempPos] := Buf[Count];
|
Temp[TempPos] := Buf[Count];
|
||||||
|
|
||||||
Inc (TempPos);
|
Inc (TempPos);
|
||||||
End;
|
End;
|
||||||
End;
|
End;
|
||||||
|
@ -442,12 +394,7 @@ End;
|
||||||
Function TIOSocket.ReadBuf (Var Buf; Len: LongInt) : LongInt;
|
Function TIOSocket.ReadBuf (Var Buf; Len: LongInt) : LongInt;
|
||||||
Begin
|
Begin
|
||||||
If FInBufPos = FInBufEnd Then Begin
|
If FInBufPos = FInBufEnd Then Begin
|
||||||
{$IFDEF OS2}
|
FInBufEnd := fpRecv(FSocketHandle, @FInBuf, TIOBufferSize, FPRECVOPT);
|
||||||
FInBufEnd := Winsock.Recv(FSocketHandle, @FInBuf, TIOBufferSize, FPRECVOPT);
|
|
||||||
{$ELSE}
|
|
||||||
FInBufEnd := fpRecv(FSocketHandle, @FInBuf, TIOBufferSize, FPRECVOPT);
|
|
||||||
{$ENDIF}
|
|
||||||
|
|
||||||
FInBufPos := 0;
|
FInBufPos := 0;
|
||||||
|
|
||||||
If FInBufEnd <= 0 Then Begin
|
If FInBufEnd <= 0 Then Begin
|
||||||
|
@ -497,7 +444,7 @@ Begin
|
||||||
Exit;
|
Exit;
|
||||||
End;
|
End;
|
||||||
|
|
||||||
// Data := Ord(Not Block);
|
// Data := Ord(Not Block);
|
||||||
// Result := ioctlSocket(FSocketHandle, FIONBIO, Data);
|
// Result := ioctlSocket(FSocketHandle, FIONBIO, Data);
|
||||||
End;
|
End;
|
||||||
|
|
||||||
|
@ -594,12 +541,7 @@ Begin
|
||||||
If fpListen(FSocketHandle, 5) = -1 Then Exit;
|
If fpListen(FSocketHandle, 5) = -1 Then Exit;
|
||||||
|
|
||||||
Temp := SizeOf(SIN);
|
Temp := SizeOf(SIN);
|
||||||
|
Sock := fpAccept(FSocketHandle, @SIN, @Temp);
|
||||||
{$IFDEF OS2}
|
|
||||||
Sock := Winsock.Accept(FSocketHandle, @SIN, @Temp);
|
|
||||||
{$ELSE}
|
|
||||||
Sock := fpAccept(FSocketHandle, @SIN, @Temp);
|
|
||||||
{$ENDIF}
|
|
||||||
|
|
||||||
If Sock = -1 Then Exit;
|
If Sock = -1 Then Exit;
|
||||||
|
|
||||||
|
@ -626,14 +568,10 @@ Begin
|
||||||
Client.FTelnetServer := FTelnetServer;
|
Client.FTelnetServer := FTelnetServer;
|
||||||
Client.FTelnetClient := FTelnetClient;
|
Client.FTelnetClient := FTelnetClient;
|
||||||
|
|
||||||
If FTelnetServer Then Begin
|
If FTelnetServer Then
|
||||||
{$IFDEF SOCKETLOG} sLog('Sending cmd: DO ECHO'); {$ENDIF}
|
|
||||||
{$IFDEF SOCKETLOG} sLog('Sending cmd: WILL SGA'); {$ENDIF}
|
|
||||||
|
|
||||||
Client.WriteStr (TELNET_IAC + TELNET_WILL + TELNET_ECHO +
|
Client.WriteStr (TELNET_IAC + TELNET_WILL + TELNET_ECHO +
|
||||||
TELNET_IAC + TELNET_WILL + TELNET_SGA +
|
TELNET_IAC + TELNET_WILL + TELNET_SGA +
|
||||||
TELNET_IAC + TELNET_DO + TELNET_BINARY);
|
TELNET_IAC + TELNET_DO + TELNET_BINARY);
|
||||||
End;
|
|
||||||
|
|
||||||
Result := Client;
|
Result := Client;
|
||||||
End;
|
End;
|
||||||
|
|
Loading…
Reference in New Issue