[Modify] Return bool
This commit is contained in:
parent
a2016d543a
commit
0d5b7d4553
@ -734,22 +734,42 @@ namespace WebSocketSharp
|
|||||||
: null;
|
: null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private string checkIfValidReceivedFrame (WebSocketFrame frame)
|
private bool checkIfValidReceivedFrame (WebSocketFrame frame, out string message)
|
||||||
{
|
{
|
||||||
|
message = null;
|
||||||
|
|
||||||
var masked = frame.IsMasked;
|
var masked = frame.IsMasked;
|
||||||
return _client && masked
|
if (_client && masked) {
|
||||||
? "A frame from the server is masked."
|
message = "A frame from the server is masked.";
|
||||||
: !_client && !masked
|
return false;
|
||||||
? "A frame from a client isn't masked."
|
}
|
||||||
: _inContinuation && frame.IsData
|
|
||||||
? "A data frame has been received while receiving continuation frames."
|
if (!_client && !masked) {
|
||||||
: frame.IsCompressed && _compression == CompressionMethod.None
|
message = "A frame from a client isn't masked.";
|
||||||
? "A compressed frame has been received without any agreement for it."
|
return false;
|
||||||
: frame.Rsv2 == Rsv.On
|
}
|
||||||
? "The RSV2 of a frame is non-zero without any negotiation for it."
|
|
||||||
: frame.Rsv3 == Rsv.On
|
if (_inContinuation && frame.IsData) {
|
||||||
? "The RSV3 of a frame is non-zero without any negotiation for it."
|
message = "A data frame has been received while receiving continuation frames.";
|
||||||
: null;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (frame.IsCompressed && _compression == CompressionMethod.None) {
|
||||||
|
message = "A compressed frame has been received without any agreement for it.";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (frame.Rsv2 == Rsv.On) {
|
||||||
|
message = "The RSV2 of a frame is non-zero without any negotiation for it.";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (frame.Rsv3 == Rsv.On) {
|
||||||
|
message = "The RSV3 of a frame is non-zero without any negotiation for it.";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void close (CloseEventArgs e, bool send, bool receive, bool received)
|
private void close (CloseEventArgs e, bool send, bool receive, bool received)
|
||||||
@ -1166,8 +1186,8 @@ namespace WebSocketSharp
|
|||||||
|
|
||||||
private bool processReceivedFrame (WebSocketFrame frame)
|
private bool processReceivedFrame (WebSocketFrame frame)
|
||||||
{
|
{
|
||||||
var msg = checkIfValidReceivedFrame (frame);
|
string msg;
|
||||||
if (msg != null)
|
if (!checkIfValidReceivedFrame (frame, out msg))
|
||||||
throw new WebSocketException (CloseStatusCode.ProtocolError, msg);
|
throw new WebSocketException (CloseStatusCode.ProtocolError, msg);
|
||||||
|
|
||||||
frame.Unmask ();
|
frame.Unmask ();
|
||||||
|
Loading…
Reference in New Issue
Block a user