Added processing of reserved opcodes.

This commit is contained in:
Yuri Silver 2022-01-07 16:37:29 +03:00
parent 11ac750e87
commit f3a0bdd232

View File

@ -40,6 +40,7 @@ Const
DefaultWebSocketVersion = 13; DefaultWebSocketVersion = 13;
// Opcodes // Opcodes
FlagReserved = $F;
FlagContinuation = $0; FlagContinuation = $0;
FlagText = $1; FlagText = $1;
FlagBinary = $2; FlagBinary = $2;
@ -76,7 +77,7 @@ type
EWebSocket = Class(Exception); EWebSocket = Class(Exception);
EWSHandShake = class(EWebSocket); EWSHandShake = class(EWebSocket);
TFrameType = (ftContinuation,ftText,ftBinary,ftClose,ftPing,ftPong); TFrameType = (ftContinuation,ftText,ftBinary,ftClose,ftPing,ftPong,ftReserved);
TFrameTypes = Set of TFrameType; TFrameTypes = Set of TFrameType;
@ -484,7 +485,7 @@ uses strutils, sha1,base64;
function TFrameTypeHelper.GetAsFlag: Byte; function TFrameTypeHelper.GetAsFlag: Byte;
Const Const
Flags : Array[TFrameType] of byte = (FlagContinuation,FlagText,FlagBinary,FlagClose,FlagPing,FlagPong); Flags : Array[TFrameType] of byte = (FlagContinuation,FlagText,FlagBinary,FlagClose,FlagPing,FlagPong,FlagReserved);
begin begin
Result:=Flags[Self]; Result:=Flags[Self];
@ -500,7 +501,8 @@ begin
FlagPing : Self:=ftPing; FlagPing : Self:=ftPing;
FlagPong : Self:=ftPong; FlagPong : Self:=ftPong;
else else
Raise EConvertError.CreateFmt(SErrInvalidFrameType,[aValue]); Self:=ftReserved;
//Raise EConvertError.CreateFmt(SErrInvalidFrameType,[aValue]);
end; end;
end; end;
@ -1258,7 +1260,7 @@ Function TWSConnection.HandleIncoming(aFrame : TWSFrame) : Boolean;
begin begin
Result:=True; Result:=True;
// check Reserved // check Reserved bits
if aFrame.Reserved<>0 then if aFrame.Reserved<>0 then
begin begin
Close('', CLOSE_PROTOCOL_ERROR); Close('', CLOSE_PROTOCOL_ERROR);
@ -1266,7 +1268,14 @@ begin
Result:=false; Result:=false;
Exit; Exit;
end; end;
// check Reserved opcode
if aFrame.FrameType = ftReserved then
begin
Close('', CLOSE_PROTOCOL_ERROR);
UpdateCloseState;
Result:=false;
Exit;
end;
// here we handle payload. // here we handle payload.
if aFrame.FrameType<>ftContinuation then if aFrame.FrameType<>ftContinuation then
FInitialOpcode:=aFrame.FrameType; FInitialOpcode:=aFrame.FrameType;