Fix due to the modified Ext.cs
This commit is contained in:
parent
4424d1d809
commit
daeaebcc4b
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -294,8 +294,8 @@ Please access [http://localhost:4649](http://localhost:4649) to do WebSocket Ech
|
|||||||
|
|
||||||
**websocket-sharp** supports **[RFC 6455]**.
|
**websocket-sharp** supports **[RFC 6455]**.
|
||||||
|
|
||||||
- **[branch: hybi-00]** supports older draft-ietf-hybi-thewebsocketprotocol-00 (**[hybi-00]**).
|
- **[branch: hybi-00]** supports older draft-ietf-hybi-thewebsocketprotocol-00 ( **[hybi-00]** ).
|
||||||
- **[branch: draft75]** supports even more old draft-hixie-thewebsocketprotocol-75 (**[hixie-75]**).
|
- **[branch: draft75]** supports even more old draft-hixie-thewebsocketprotocol-75 ( **[hixie-75]** ).
|
||||||
|
|
||||||
## Reference ##
|
## Reference ##
|
||||||
|
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -32,14 +32,53 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
namespace WebSocketSharp.Frame
|
namespace WebSocketSharp.Frame {
|
||||||
{
|
|
||||||
public class PayloadData : IEnumerable<byte>
|
public class PayloadData : IEnumerable<byte>
|
||||||
{
|
{
|
||||||
|
#region Field
|
||||||
|
|
||||||
#region Public Static Fields
|
public const ulong MaxLength = long.MaxValue;
|
||||||
|
|
||||||
public static readonly ulong MaxLength;
|
#endregion
|
||||||
|
|
||||||
|
#region Public Constructors
|
||||||
|
|
||||||
|
public PayloadData(string appData)
|
||||||
|
: this(Encoding.UTF8.GetBytes(appData))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public PayloadData(byte[] appData)
|
||||||
|
: this(new byte[]{}, appData)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public PayloadData(byte[] appData, bool masked)
|
||||||
|
: this(new byte[]{}, appData, masked)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public PayloadData(byte[] extData, byte[] appData)
|
||||||
|
: this(extData, appData, false)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public PayloadData(byte[] extData, byte[] appData, bool masked)
|
||||||
|
{
|
||||||
|
if (extData.IsNull())
|
||||||
|
throw new ArgumentNullException("extData");
|
||||||
|
|
||||||
|
if (appData.IsNull())
|
||||||
|
throw new ArgumentNullException("appData");
|
||||||
|
|
||||||
|
if ((ulong)extData.LongLength + (ulong)appData.LongLength > MaxLength)
|
||||||
|
throw new ArgumentOutOfRangeException("Plus 'extData' length and 'appData' lenght must be less than MaxLength.");
|
||||||
|
|
||||||
|
ExtensionData = extData;
|
||||||
|
ApplicationData = appData;
|
||||||
|
IsMasked = masked;
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@ -50,82 +89,25 @@ namespace WebSocketSharp.Frame
|
|||||||
|
|
||||||
public bool IsMasked { get; private set; }
|
public bool IsMasked { get; private set; }
|
||||||
|
|
||||||
public ulong Length
|
public ulong Length {
|
||||||
{
|
get {
|
||||||
get
|
|
||||||
{
|
|
||||||
return (ulong)(ExtensionData.LongLength + ApplicationData.LongLength);
|
return (ulong)(ExtensionData.LongLength + ApplicationData.LongLength);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Static Constructor
|
|
||||||
|
|
||||||
static PayloadData()
|
|
||||||
{
|
|
||||||
MaxLength = long.MaxValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Public Constructors
|
|
||||||
|
|
||||||
public PayloadData(string appData)
|
|
||||||
: this(Encoding.UTF8.GetBytes(appData))
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public PayloadData(byte[] appData)
|
|
||||||
: this(new byte[]{}, appData)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public PayloadData(byte[] appData, bool masked)
|
|
||||||
: this(new byte[]{}, appData, masked)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public PayloadData(byte[] extData, byte[] appData)
|
|
||||||
: this(extData, appData, false)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public PayloadData(byte[] extData, byte[] appData, bool masked)
|
|
||||||
{
|
|
||||||
Func<string, Action> func = s => () =>
|
|
||||||
{
|
|
||||||
string message = String.Format("{0} must not be null.", s);
|
|
||||||
throw new ArgumentNullException(message);
|
|
||||||
};
|
|
||||||
extData.IsNullDo(func("extData"));
|
|
||||||
appData.IsNullDo(func("appData"));
|
|
||||||
|
|
||||||
if ((ulong)extData.LongLength + (ulong)appData.LongLength > MaxLength)
|
|
||||||
{
|
|
||||||
throw new ArgumentOutOfRangeException("Plus extData length and appData lenght must be less than MaxLength.");
|
|
||||||
}
|
|
||||||
|
|
||||||
ExtensionData = extData;
|
|
||||||
ApplicationData = appData;
|
|
||||||
IsMasked = masked;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Private Methods
|
#region Private Methods
|
||||||
|
|
||||||
|
IEnumerator IEnumerable.GetEnumerator()
|
||||||
|
{
|
||||||
|
return GetEnumerator();
|
||||||
|
}
|
||||||
|
|
||||||
private void mask(byte[] src, byte[] key)
|
private void mask(byte[] src, byte[] key)
|
||||||
{
|
{
|
||||||
if (key.Length != 4)
|
|
||||||
{
|
|
||||||
throw new ArgumentOutOfRangeException("key length must be 4.");
|
|
||||||
}
|
|
||||||
|
|
||||||
for (long i = 0; i < src.LongLength; i++)
|
for (long i = 0; i < src.LongLength; i++)
|
||||||
{
|
|
||||||
src[i] = (byte)(src[i] ^ key[i % 4]);
|
src[i] = (byte)(src[i] ^ key[i % 4]);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
@ -135,45 +117,34 @@ namespace WebSocketSharp.Frame
|
|||||||
public IEnumerator<byte> GetEnumerator()
|
public IEnumerator<byte> GetEnumerator()
|
||||||
{
|
{
|
||||||
foreach (byte b in ExtensionData)
|
foreach (byte b in ExtensionData)
|
||||||
{
|
|
||||||
yield return b;
|
yield return b;
|
||||||
}
|
|
||||||
foreach (byte b in ApplicationData)
|
|
||||||
{
|
|
||||||
yield return b;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
|
foreach (byte b in ApplicationData)
|
||||||
{
|
yield return b;
|
||||||
return GetEnumerator();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Mask(byte[] maskingKey)
|
public void Mask(byte[] maskingKey)
|
||||||
{
|
{
|
||||||
|
if (maskingKey.IsNull())
|
||||||
|
throw new ArgumentNullException("maskingKey");
|
||||||
|
|
||||||
|
if (maskingKey.Length != 4)
|
||||||
|
throw new ArgumentOutOfRangeException("maskingKey", "'maskingKey' length must be 4.");
|
||||||
|
|
||||||
if (ExtensionData.LongLength > 0)
|
if (ExtensionData.LongLength > 0)
|
||||||
{
|
|
||||||
mask(ExtensionData, maskingKey);
|
mask(ExtensionData, maskingKey);
|
||||||
}
|
|
||||||
|
|
||||||
if (ApplicationData.LongLength > 0)
|
if (ApplicationData.LongLength > 0)
|
||||||
{
|
|
||||||
mask(ApplicationData, maskingKey);
|
mask(ApplicationData, maskingKey);
|
||||||
}
|
|
||||||
|
|
||||||
IsMasked = !IsMasked;
|
IsMasked = !IsMasked;
|
||||||
}
|
}
|
||||||
|
|
||||||
public byte[] ToBytes()
|
public byte[] ToBytes()
|
||||||
{
|
{
|
||||||
if (ExtensionData.LongLength > 0)
|
return ExtensionData.LongLength > 0
|
||||||
{
|
? ExtensionData.Concat(ApplicationData).ToArray()
|
||||||
return ExtensionData.Concat(ApplicationData).ToArray();
|
: ApplicationData;
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return ApplicationData;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
|
@ -38,16 +38,7 @@ namespace WebSocketSharp.Frame {
|
|||||||
{
|
{
|
||||||
#region Field
|
#region Field
|
||||||
|
|
||||||
private static readonly int _readBufferLen;
|
private const int _readBufferLen = 1024;
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Static Constructor
|
|
||||||
|
|
||||||
static WsFrame()
|
|
||||||
{
|
|
||||||
_readBufferLen = 1024;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@ -171,16 +162,18 @@ namespace WebSocketSharp.Frame {
|
|||||||
{
|
{
|
||||||
var length = frame.PayloadLen <= 125
|
var length = frame.PayloadLen <= 125
|
||||||
? 0
|
? 0
|
||||||
: frame.PayloadLen == 126 ? 2 : 8;
|
: frame.PayloadLen == 126
|
||||||
|
? 2
|
||||||
|
: 8;
|
||||||
|
|
||||||
if (length > 0)
|
if (length == 0)
|
||||||
{
|
return;
|
||||||
var extLength = stream.ReadBytes(length);
|
|
||||||
if (extLength == null)
|
|
||||||
throw new IOException();
|
|
||||||
|
|
||||||
frame.ExtPayloadLen = extLength;
|
var extLen = stream.ReadBytes(length);
|
||||||
}
|
if (extLen.Length != length)
|
||||||
|
throw new IOException();
|
||||||
|
|
||||||
|
frame.ExtPayloadLen = extLen;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static WsFrame readHeader(byte[] header)
|
private static WsFrame readHeader(byte[] header)
|
||||||
@ -213,14 +206,14 @@ namespace WebSocketSharp.Frame {
|
|||||||
|
|
||||||
private static void readMaskingKey(Stream stream, WsFrame frame)
|
private static void readMaskingKey(Stream stream, WsFrame frame)
|
||||||
{
|
{
|
||||||
if (frame.Masked == Mask.MASK)
|
if (frame.Masked == Mask.UNMASK)
|
||||||
{
|
return;
|
||||||
var maskingKey = stream.ReadBytes(4);
|
|
||||||
if (maskingKey == null)
|
|
||||||
throw new IOException();
|
|
||||||
|
|
||||||
frame.MaskingKey = maskingKey;
|
var maskingKey = stream.ReadBytes(4);
|
||||||
}
|
if (maskingKey.Length != 4)
|
||||||
|
throw new IOException();
|
||||||
|
|
||||||
|
frame.MaskingKey = maskingKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void readPayloadData(Stream stream, WsFrame frame, bool unmask)
|
private static void readPayloadData(Stream stream, WsFrame frame, bool unmask)
|
||||||
@ -231,27 +224,31 @@ namespace WebSocketSharp.Frame {
|
|||||||
? frame.ExtPayloadLen.To<ushort>(ByteOrder.BIG)
|
? frame.ExtPayloadLen.To<ushort>(ByteOrder.BIG)
|
||||||
: frame.ExtPayloadLen.To<ulong>(ByteOrder.BIG);
|
: frame.ExtPayloadLen.To<ulong>(ByteOrder.BIG);
|
||||||
|
|
||||||
|
if (length == 0)
|
||||||
|
{
|
||||||
|
frame.PayloadData = new PayloadData(new byte[]{});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (frame.PayloadLen > 126 && length > PayloadData.MaxLength)
|
||||||
|
throw new WsReceivedTooBigMessageException();
|
||||||
|
|
||||||
var buffer = length <= (ulong)_readBufferLen
|
var buffer = length <= (ulong)_readBufferLen
|
||||||
? stream.ReadBytes((int)length)
|
? stream.ReadBytes((int)length)
|
||||||
: stream.ReadBytes((long)length, _readBufferLen);
|
: stream.ReadBytes((long)length, _readBufferLen);
|
||||||
|
|
||||||
if (buffer == null)
|
if (buffer.LongLength != (long)length)
|
||||||
throw new IOException();
|
throw new IOException();
|
||||||
|
|
||||||
PayloadData payloadData;
|
var payloadData = frame.Masked == Mask.MASK
|
||||||
if (frame.Masked == Mask.MASK)
|
? new PayloadData(buffer, true)
|
||||||
|
: new PayloadData(buffer);
|
||||||
|
|
||||||
|
if (frame.Masked == Mask.MASK && unmask)
|
||||||
{
|
{
|
||||||
payloadData = new PayloadData(buffer, true);
|
payloadData.Mask(frame.MaskingKey);
|
||||||
if (unmask == true)
|
frame.Masked = Mask.UNMASK;
|
||||||
{
|
frame.MaskingKey = new byte[]{};
|
||||||
payloadData.Mask(frame.MaskingKey);
|
|
||||||
frame.Masked = Mask.UNMASK;
|
|
||||||
frame.MaskingKey = new byte[]{};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
payloadData = new PayloadData(buffer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
frame.PayloadData = payloadData;
|
frame.PayloadData = payloadData;
|
||||||
@ -462,7 +459,7 @@ namespace WebSocketSharp.Frame {
|
|||||||
{
|
{
|
||||||
var buffer = new List<byte>();
|
var buffer = new List<byte>();
|
||||||
|
|
||||||
int header = (int)Fin;
|
var header = (int)Fin;
|
||||||
header = (header << 1) + (int)Rsv1;
|
header = (header << 1) + (int)Rsv1;
|
||||||
header = (header << 1) + (int)Rsv2;
|
header = (header << 1) + (int)Rsv2;
|
||||||
header = (header << 1) + (int)Rsv3;
|
header = (header << 1) + (int)Rsv3;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
//
|
//
|
||||||
// HttpStatusCode.cs
|
// HttpStatusCode.cs
|
||||||
// Copied from System.Net.HttpStatusCode
|
// Copied from System.Net.HttpStatusCode.cs
|
||||||
//
|
//
|
||||||
// This code was automatically generated from
|
// This code was automatically generated from
|
||||||
// ECMA CLI XML Library Specification.
|
// ECMA CLI XML Library Specification.
|
||||||
@ -34,6 +34,7 @@
|
|||||||
namespace WebSocketSharp.Net {
|
namespace WebSocketSharp.Net {
|
||||||
|
|
||||||
public enum HttpStatusCode {
|
public enum HttpStatusCode {
|
||||||
|
|
||||||
Continue = 100,
|
Continue = 100,
|
||||||
SwitchingProtocols = 101,
|
SwitchingProtocols = 101,
|
||||||
OK = 200,
|
OK = 200,
|
||||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue
Block a user