Fix due to the modified PayloadData.cs

This commit is contained in:
sta 2013-04-08 15:11:57 +09:00
parent 029d1f6d1d
commit 9bf4adfbab
24 changed files with 51 additions and 41 deletions

Binary file not shown.

View File

@ -1,4 +1,4 @@
#region MIT License #region License
/* /*
* CloseEventArgs.cs * CloseEventArgs.cs
* *
@ -49,7 +49,7 @@ namespace WebSocketSharp {
#endregion #endregion
#region Constructor #region Constructors
internal CloseEventArgs(PayloadData data) internal CloseEventArgs(PayloadData data)
: base(Opcode.CLOSE, data) : base(Opcode.CLOSE, data)
@ -110,7 +110,7 @@ namespace WebSocketSharp {
private ushort getCodeFrom(PayloadData data) private ushort getCodeFrom(PayloadData data)
{ {
return data.Length >= 2 return data.Length >= 2
? data.ToBytes().SubArray(0, 2).To<ushort>(ByteOrder.BIG) ? data.ToByteArray().SubArray(0, 2).To<ushort>(ByteOrder.BIG)
: (ushort)CloseStatusCode.NO_STATUS_CODE; : (ushort)CloseStatusCode.NO_STATUS_CODE;
} }
@ -119,7 +119,7 @@ namespace WebSocketSharp {
if (data.Length <= 2) if (data.Length <= 2)
return String.Empty; return String.Empty;
var buffer = data.ToBytes().SubArray(2, (int)(data.Length - 2)); var buffer = data.ToByteArray().SubArray(2, (int)(data.Length - 2));
return Encoding.UTF8.GetString(buffer); return Encoding.UTF8.GetString(buffer);
} }

View File

@ -1,4 +1,4 @@
#region MIT License #region License
/* /*
* MessageEventArgs.cs * MessageEventArgs.cs
* *
@ -48,7 +48,7 @@ namespace WebSocketSharp {
#endregion #endregion
#region Constructor #region Constructors
internal MessageEventArgs(Opcode type, PayloadData data) internal MessageEventArgs(Opcode type, PayloadData data)
{ {
@ -70,7 +70,7 @@ namespace WebSocketSharp {
get { get {
return ((Opcode.TEXT | Opcode.PING | Opcode.PONG) & _type) == _type return ((Opcode.TEXT | Opcode.PING | Opcode.PONG) & _type) == _type
? _data.Length > 0 ? _data.Length > 0
? Encoding.UTF8.GetString(_data.ToBytes()) ? Encoding.UTF8.GetString(_data.ToByteArray())
: String.Empty : String.Empty
: _type.ToString(); : _type.ToString();
} }
@ -84,7 +84,7 @@ namespace WebSocketSharp {
/// </value> /// </value>
public byte[] RawData { public byte[] RawData {
get { get {
return _data.ToBytes(); return _data.ToByteArray();
} }
} }

View File

@ -1,4 +1,4 @@
#region MIT License #region License
/* /*
* PayloadData.cs * PayloadData.cs
* *
@ -36,16 +36,16 @@ namespace WebSocketSharp {
internal class PayloadData : IEnumerable<byte> internal class PayloadData : IEnumerable<byte>
{ {
#region Field #region Fields
public const ulong MaxLength = long.MaxValue; public const ulong MaxLength = long.MaxValue;
#endregion #endregion
#region Public Constructors #region Constructors
public PayloadData(string appData) public PayloadData()
: this(Encoding.UTF8.GetBytes(appData)) : this(new byte[]{})
{ {
} }
@ -54,6 +54,11 @@ namespace WebSocketSharp {
{ {
} }
public PayloadData(string appData)
: this(Encoding.UTF8.GetBytes(appData))
{
}
public PayloadData(byte[] appData, bool masked) public PayloadData(byte[] appData, bool masked)
: this(new byte[]{}, appData, masked) : this(new byte[]{}, appData, masked)
{ {
@ -73,22 +78,23 @@ namespace WebSocketSharp {
throw new ArgumentNullException("appData"); throw new ArgumentNullException("appData");
if ((ulong)extData.LongLength + (ulong)appData.LongLength > MaxLength) if ((ulong)extData.LongLength + (ulong)appData.LongLength > MaxLength)
throw new ArgumentOutOfRangeException("Plus 'extData' length and 'appData' lenght must be less than MaxLength."); throw new ArgumentOutOfRangeException(
"The length of 'extData' plus 'appData' must be less than MaxLength.");
ExtensionData = extData; ExtensionData = extData;
ApplicationData = appData; ApplicationData = appData;
IsMasked = masked; IsMasked = masked;
} }
#endregion #endregion
#region Internal Property #region Internal Properties
internal bool ContainsReservedCloseStatusCode { internal bool ContainsReservedCloseStatusCode {
get { get {
if (Length >= 2) if (Length >= 2)
{ {
var code = ToBytes().SubArray(0, 2).To<ushort>(ByteOrder.BIG); var code = ToByteArray().SubArray(0, 2).To<ushort>(ByteOrder.BIG);
if (code == (ushort)CloseStatusCode.UNDEFINED || if (code == (ushort)CloseStatusCode.UNDEFINED ||
code == (ushort)CloseStatusCode.NO_STATUS_CODE || code == (ushort)CloseStatusCode.NO_STATUS_CODE ||
code == (ushort)CloseStatusCode.ABNORMAL || code == (ushort)CloseStatusCode.ABNORMAL ||
@ -104,10 +110,10 @@ namespace WebSocketSharp {
#region Public Properties #region Public Properties
public byte[] ExtensionData { get; private set; }
public byte[] ApplicationData { get; private set; } public byte[] ApplicationData { get; private set; }
public byte[] ExtensionData { get; private set; }
public bool IsMasked { get; private set; } public bool IsMasked { get; private set; }
public ulong Length { public ulong Length {
@ -120,12 +126,7 @@ namespace WebSocketSharp {
#region Private Methods #region Private Methods
IEnumerator IEnumerable.GetEnumerator() private static void mask(byte[] src, byte[] key)
{
return GetEnumerator();
}
private void mask(byte[] src, byte[] key)
{ {
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]);
@ -150,7 +151,7 @@ namespace WebSocketSharp {
throw new ArgumentNullException("maskingKey"); throw new ArgumentNullException("maskingKey");
if (maskingKey.Length != 4) if (maskingKey.Length != 4)
throw new ArgumentOutOfRangeException("maskingKey", "'maskingKey' length must be 4."); throw new ArgumentOutOfRangeException("maskingKey", "The length must be 4.");
if (ExtensionData.LongLength > 0) if (ExtensionData.LongLength > 0)
mask(ExtensionData, maskingKey); mask(ExtensionData, maskingKey);
@ -161,7 +162,7 @@ namespace WebSocketSharp {
IsMasked = !IsMasked; IsMasked = !IsMasked;
} }
public byte[] ToBytes() public byte[] ToByteArray()
{ {
return ExtensionData.LongLength > 0 return ExtensionData.LongLength > 0
? ExtensionData.Concat(ApplicationData).ToArray() ? ExtensionData.Concat(ApplicationData).ToArray()
@ -170,7 +171,16 @@ namespace WebSocketSharp {
public override string ToString() public override string ToString()
{ {
return BitConverter.ToString(ToBytes()); return BitConverter.ToString(ToByteArray());
}
#endregion
#region Explicitly Implemented Interface Members
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
} }
#endregion #endregion

View File

@ -1,4 +1,4 @@
#region MIT License #region License
/* /*
* WebSocket.cs * WebSocket.cs
* *
@ -84,7 +84,7 @@ namespace WebSocketSharp {
#endregion #endregion
#region Private Constructor #region Private Constructors
private WebSocket() private WebSocket()
{ {
@ -208,7 +208,7 @@ namespace WebSocketSharp {
#endregion #endregion
#region Internal Property #region Internal Properties
internal CookieCollection CookieCollection { internal CookieCollection CookieCollection {
get { get {
@ -759,7 +759,7 @@ namespace WebSocketSharp {
private void processFragments(WsFrame first) private void processFragments(WsFrame first)
{ {
var buffer = new List<byte>(first.PayloadData.ToBytes()); var buffer = new List<byte>(first.PayloadData.ToByteArray());
while (true) while (true)
{ {
var frame = readFrame(); var frame = readFrame();
@ -772,7 +772,7 @@ namespace WebSocketSharp {
// MORE & CONT // MORE & CONT
if (frame.Opcode == Opcode.CONT) if (frame.Opcode == Opcode.CONT)
{ {
buffer.AddRange(frame.PayloadData.ToBytes()); buffer.AddRange(frame.PayloadData.ToByteArray());
continue; continue;
} }
@ -784,7 +784,7 @@ namespace WebSocketSharp {
// FINAL & CONT // FINAL & CONT
if (frame.Opcode == Opcode.CONT) if (frame.Opcode == Opcode.CONT)
{ {
buffer.AddRange(frame.PayloadData.ToBytes()); buffer.AddRange(frame.PayloadData.ToByteArray());
break; break;
} }

View File

@ -1,4 +1,4 @@
#region MIT License #region License
/* /*
* WsFrame.cs * WsFrame.cs
* *
@ -36,13 +36,13 @@ namespace WebSocketSharp {
internal class WsFrame : IEnumerable<byte> internal class WsFrame : IEnumerable<byte>
{ {
#region Field #region Fields
private const int _readBufferLen = 1024; private const int _readBufferLen = 1024;
#endregion #endregion
#region Private Constructor #region Private Constructors
private WsFrame() private WsFrame()
{ {
@ -380,11 +380,11 @@ namespace WebSocketSharp {
Masked == Mask.UNMASK && Masked == Mask.UNMASK &&
PayloadLength > 0) PayloadLength > 0)
{ {
payloadData = Encoding.UTF8.GetString(PayloadData.ToBytes()); payloadData = Encoding.UTF8.GetString(PayloadData.ToByteArray());
} }
else else
{ {
payloadData = BitConverter.ToString(PayloadData.ToBytes()); payloadData = BitConverter.ToString(PayloadData.ToByteArray());
} }
headerFmt = @" headerFmt = @"
@ -491,7 +491,7 @@ namespace WebSocketSharp {
buffer.AddRange(MaskingKey); buffer.AddRange(MaskingKey);
if (PayloadLen > 0) if (PayloadLen > 0)
buffer.AddRange(PayloadData.ToBytes()); buffer.AddRange(PayloadData.ToByteArray());
return buffer.ToArray(); return buffer.ToArray();
} }

Binary file not shown.