Fix due to the modified Ext.cs

This commit is contained in:
sta 2012-12-05 22:10:15 +09:00
parent 4424d1d809
commit daeaebcc4b
62 changed files with 802 additions and 339 deletions

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.

View File

@ -294,8 +294,8 @@ Please access [http://localhost:4649](http://localhost:4649) to do WebSocket Ech
**websocket-sharp** supports **[RFC 6455]**.
- **[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: hybi-00]** supports older draft-ietf-hybi-thewebsocketprotocol-00 ( **[hybi-00]** ).
- **[branch: draft75]** supports even more old draft-hixie-thewebsocketprotocol-75 ( **[hixie-75]** ).
## Reference ##

File diff suppressed because it is too large Load Diff

View File

@ -32,14 +32,53 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace WebSocketSharp.Frame
{
namespace WebSocketSharp.Frame {
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
@ -50,82 +89,25 @@ namespace WebSocketSharp.Frame
public bool IsMasked { get; private set; }
public ulong Length
{
get
{
public ulong Length {
get {
return (ulong)(ExtensionData.LongLength + ApplicationData.LongLength);
}
}
#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
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
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++)
{
src[i] = (byte)(src[i] ^ key[i % 4]);
}
}
#endregion
@ -135,45 +117,34 @@ namespace WebSocketSharp.Frame
public IEnumerator<byte> GetEnumerator()
{
foreach (byte b in ExtensionData)
{
yield return b;
}
foreach (byte b in ApplicationData)
{
yield return b;
}
}
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
{
return GetEnumerator();
foreach (byte b in ApplicationData)
yield return b;
}
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)
{
mask(ExtensionData, maskingKey);
}
if (ApplicationData.LongLength > 0)
{
mask(ApplicationData, maskingKey);
}
IsMasked = !IsMasked;
}
public byte[] ToBytes()
{
if (ExtensionData.LongLength > 0)
{
return ExtensionData.Concat(ApplicationData).ToArray();
}
else
{
return ApplicationData;
}
return ExtensionData.LongLength > 0
? ExtensionData.Concat(ApplicationData).ToArray()
: ApplicationData;
}
public override string ToString()

View File

@ -38,16 +38,7 @@ namespace WebSocketSharp.Frame {
{
#region Field
private static readonly int _readBufferLen;
#endregion
#region Static Constructor
static WsFrame()
{
_readBufferLen = 1024;
}
private const int _readBufferLen = 1024;
#endregion
@ -171,16 +162,18 @@ namespace WebSocketSharp.Frame {
{
var length = frame.PayloadLen <= 125
? 0
: frame.PayloadLen == 126 ? 2 : 8;
: frame.PayloadLen == 126
? 2
: 8;
if (length > 0)
{
var extLength = stream.ReadBytes(length);
if (extLength == null)
throw new IOException();
if (length == 0)
return;
frame.ExtPayloadLen = extLength;
}
var extLen = stream.ReadBytes(length);
if (extLen.Length != length)
throw new IOException();
frame.ExtPayloadLen = extLen;
}
private static WsFrame readHeader(byte[] header)
@ -213,14 +206,14 @@ namespace WebSocketSharp.Frame {
private static void readMaskingKey(Stream stream, WsFrame frame)
{
if (frame.Masked == Mask.MASK)
{
var maskingKey = stream.ReadBytes(4);
if (maskingKey == null)
throw new IOException();
if (frame.Masked == Mask.UNMASK)
return;
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)
@ -231,27 +224,31 @@ namespace WebSocketSharp.Frame {
? frame.ExtPayloadLen.To<ushort>(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
? stream.ReadBytes((int)length)
: stream.ReadBytes((long)length, _readBufferLen);
if (buffer == null)
if (buffer.LongLength != (long)length)
throw new IOException();
PayloadData payloadData;
if (frame.Masked == Mask.MASK)
var payloadData = frame.Masked == Mask.MASK
? new PayloadData(buffer, true)
: new PayloadData(buffer);
if (frame.Masked == Mask.MASK && unmask)
{
payloadData = new PayloadData(buffer, true);
if (unmask == true)
{
payloadData.Mask(frame.MaskingKey);
frame.Masked = Mask.UNMASK;
frame.MaskingKey = new byte[]{};
}
}
else
{
payloadData = new PayloadData(buffer);
payloadData.Mask(frame.MaskingKey);
frame.Masked = Mask.UNMASK;
frame.MaskingKey = new byte[]{};
}
frame.PayloadData = payloadData;
@ -462,7 +459,7 @@ namespace WebSocketSharp.Frame {
{
var buffer = new List<byte>();
int header = (int)Fin;
var header = (int)Fin;
header = (header << 1) + (int)Rsv1;
header = (header << 1) + (int)Rsv2;
header = (header << 1) + (int)Rsv3;

View File

@ -1,6 +1,6 @@
//
// HttpStatusCode.cs
// Copied from System.Net.HttpStatusCode
// Copied from System.Net.HttpStatusCode.cs
//
// This code was automatically generated from
// ECMA CLI XML Library Specification.
@ -34,6 +34,7 @@
namespace WebSocketSharp.Net {
public enum HttpStatusCode {
Continue = 100,
SwitchingProtocols = 101,
OK = 200,

Binary file not shown.