public override int Process(int lastLength, WebSocketDataFrame frame, out IDataFramePartReader nextPartReader) { int required = 2; if (frame.PayloadLenght == 126) required += 2; else required += 8; if (frame.Length < required) { nextPartReader = this; return -1; } if (frame.HasMask) nextPartReader = MaskKeyReader; else { if (frame.ActualPayloadLength == 0) { nextPartReader = null; return (int)((long)frame.Length - required); } nextPartReader = PayloadDataReader; } if (frame.Length > required) return nextPartReader.Process(required, frame, out nextPartReader); return 0; }
public override int Process(int lastLength, WebSocketDataFrame frame, out IDataFramePartReader nextPartReader) { if (frame.Length < 2) { nextPartReader = this; return -1; } if (frame.PayloadLenght < 126) { if (frame.HasMask) nextPartReader = MaskKeyReader; else { if (frame.ActualPayloadLength == 0) { nextPartReader = null; return (int)((long)frame.Length - 2); } nextPartReader = PayloadDataReader; } } else { nextPartReader = ExtendedLenghtReader; } if (frame.Length > 2) return nextPartReader.Process(2, frame, out nextPartReader); return 0; }
public override int Process( int lastLength, WebSocketDataFrame frame, out IDataFramePartReader nextPartReader) { int lastLength1 = lastLength + 4; if (frame.Length < lastLength1) { nextPartReader = (IDataFramePartReader)this; return(-1); } frame.MaskKey = frame.InnerData.ToArrayData(lastLength, 4); if (frame.ActualPayloadLength == 0L) { nextPartReader = (IDataFramePartReader)null; return((int)((long)frame.Length - (long)lastLength1)); } nextPartReader = (IDataFramePartReader) new PayloadDataReader(); if (frame.Length > lastLength1) { return(nextPartReader.Process(lastLength1, frame, out nextPartReader)); } return(0); }
// Token: 0x06000638 RID: 1592 RVA: 0x00019F24 File Offset: 0x00018124 public override int Process(int lastLength, WebSocketDataFrame frame, out IDataFramePartReader nextPartReader) { if (frame.Length < 2) { nextPartReader = this; return(-1); } if (frame.PayloadLenght < 126) { if (frame.HasMask) { nextPartReader = DataFramePartReader.MaskKeyReader; } else { if (frame.ActualPayloadLength == 0L) { nextPartReader = null; return((int)((long)frame.Length - 2L)); } nextPartReader = DataFramePartReader.PayloadDataReader; } } else { nextPartReader = DataFramePartReader.ExtendedLenghtReader; } if (frame.Length > 2) { return(nextPartReader.Process(2, frame, out nextPartReader)); } return(0); }
public override int Process( int lastLength, WebSocketDataFrame frame, out IDataFramePartReader nextPartReader) { int num = 2; int lastLength1 = frame.PayloadLenght != (sbyte)126 ? num + 8 : num + 2; if (frame.Length < lastLength1) { nextPartReader = (IDataFramePartReader)this; return(-1); } if (frame.HasMask) { nextPartReader = DataFramePartReader.MaskKeyReader; } else { if (frame.ActualPayloadLength == 0L) { nextPartReader = (IDataFramePartReader)null; return((int)((long)frame.Length - (long)lastLength1)); } nextPartReader = DataFramePartReader.PayloadDataReader; } if (frame.Length > lastLength1) { return(nextPartReader.Process(lastLength1, frame, out nextPartReader)); } return(0); }
public override int Process(int lastLength, WebSocketDataFrame frame, out IDataFramePartReader nextPartReader) { int required = lastLength + 4; if (frame.Length < required) { nextPartReader = this; return(-1); } frame.MaskKey = frame.InnerData.ToArrayData(lastLength, 4); if (frame.ActualPayloadLength == 0) { nextPartReader = null; return((int)((long)frame.Length - required)); } nextPartReader = new PayloadDataReader(); if (frame.Length > required) { return(nextPartReader.Process(required, frame, out nextPartReader)); } return(0); }
public override int Process(int lastLength, WebSocketDataFrame frame, out IDataFramePartReader nextPartReader) { int num = 2; num = ((frame.PayloadLenght != 126) ? (num + 8) : (num + 2)); if (frame.Length < num) { nextPartReader = this; return(-1); } if (frame.HasMask) { nextPartReader = DataFramePartReader.MaskKeyReader; } else { if (frame.ActualPayloadLength == 0L) { nextPartReader = null; return((int)((long)frame.Length - (long)num)); } nextPartReader = DataFramePartReader.PayloadDataReader; } if (frame.Length > num) { return(nextPartReader.Process(num, frame, out nextPartReader)); } return(0); }
public override int Process(int lastLength, WebSocketDataFrame frame, out IDataFramePartReader nextPartReader) { int required = lastLength + 4; if (frame.Length < required) { nextPartReader = this; return -1; } frame.MaskKey = frame.InnerData.ToArrayData(lastLength, 4); if (frame.ActualPayloadLength == 0) { nextPartReader = null; return (int)((long)frame.Length - required); } nextPartReader = new PayloadDataReader(); if (frame.Length > required) return nextPartReader.Process(required, frame, out nextPartReader); return 0; }
/// <summary> /// Initializes a new instance of the <see cref="WebSocketCommandInfo"/> class. /// </summary> /// <param name="frame">The frame.</param> /// <param name="left">The left.</param> public WebSocketCommandInfo(WebSocketDataFrame frame) { Key = frame.OpCode.ToString(); int length = (int)frame.ActualPayloadLength; int offset = frame.InnerData.Count - (int)frame.ActualPayloadLength; if (frame.HasMask && length > 0) { frame.InnerData.DecodeMask(frame.MaskKey, offset, length); } if (frame.OpCode == OpCode.Close) { if (length >= 2) { var closeStatusCode = frame.InnerData.ToArrayData(offset, 2); CloseStatusCode = (short)(closeStatusCode[0] * 256 + closeStatusCode[1]); if (length > 2) { Text = frame.InnerData.Decode(Encoding.UTF8, offset + 2, length - 2); } else { Text = string.Empty; } return; } } if (frame.OpCode != 2) { if (length > 0) { Text = frame.InnerData.Decode(Encoding.UTF8, offset, length); } else { Text = string.Empty; } } else { if (length > 0) { Data = frame.InnerData.ToArrayData(offset, length); } else { Data = new byte[0]; } } }
public override int Process(int lastLength, WebSocketDataFrame frame, out IDataFramePartReader nextPartReader) { long num = lastLength + frame.ActualPayloadLength; if (frame.Length < num) { nextPartReader = this; return(-1); } nextPartReader = null; return((int)(frame.Length - num)); }
/// <summary> /// Checks the control frame. /// </summary> /// <param name="frame">The frame.</param> /// <returns></returns> protected bool CheckControlFrame(WebSocketDataFrame frame) { if (!CheckFrame(frame)) return false; //http://tools.ietf.org/html/rfc6455#section-5.5 //All control frames MUST have a payload length of 125 bytes or less and MUST NOT be fragmented if (!frame.FIN || frame.ActualPayloadLength > 125) { return false; } return true; }
public override int Process(int lastLength, WebSocketDataFrame frame, out IDataFramePartReader nextPartReader) { long required = lastLength + frame.ActualPayloadLength; if (frame.Length < required) { nextPartReader = this; return -1; } nextPartReader = null; return (int)((long)frame.Length - required); }
// Token: 0x06000562 RID: 1378 RVA: 0x00018824 File Offset: 0x00016A24 public WebSocketCommandInfo(WebSocketDataFrame frame) { this.Key = frame.OpCode.ToString(); int num = (int)frame.ActualPayloadLength; int num2 = frame.InnerData.Count - (int)frame.ActualPayloadLength; if (frame.HasMask && num > 0) { frame.InnerData.DecodeMask(frame.MaskKey, num2, num); } if (frame.OpCode == 8 && num >= 2) { byte[] array = frame.InnerData.ToArrayData(num2, 2); this.CloseStatusCode = (short)((int)array[0] * 256 + (int)array[1]); if (num > 2) { this.Text = frame.InnerData.Decode(Encoding.UTF8, num2 + 2, num - 2); return; } this.Text = string.Empty; return; } else if (frame.OpCode != 2) { if (num > 0) { this.Text = frame.InnerData.Decode(Encoding.UTF8, num2, num); return; } this.Text = string.Empty; return; } else { if (num > 0) { this.Data = frame.InnerData.ToArrayData(num2, num); return; } this.Data = new byte[0]; return; } }
public WebSocketCommandInfo(WebSocketDataFrame frame) { this.Key = frame.OpCode.ToString(); int actualPayloadLength = (int)frame.ActualPayloadLength; int num = frame.InnerData.Count - (int)frame.ActualPayloadLength; if (frame.HasMask && actualPayloadLength > 0) { frame.InnerData.DecodeMask(frame.MaskKey, num, actualPayloadLength); } if (frame.OpCode == (sbyte)8 && actualPayloadLength >= 2) { byte[] arrayData = frame.InnerData.ToArrayData(num, 2); this.CloseStatusCode = (short)((int)arrayData[0] * 256 + (int)arrayData[1]); if (actualPayloadLength > 2) { this.Text = frame.InnerData.Decode(Encoding.UTF8, num + 2, actualPayloadLength - 2); } else { this.Text = string.Empty; } } else if (frame.OpCode != (sbyte)2) { if (actualPayloadLength > 0) { this.Text = frame.InnerData.Decode(Encoding.UTF8, num, actualPayloadLength); } else { this.Text = string.Empty; } } else if (actualPayloadLength > 0) { this.Data = frame.InnerData.ToArrayData(num, actualPayloadLength); } else { this.Data = new byte[0]; } }
/// <summary> /// Gets data from a websocket frame. /// </summary> /// <param name="frame">The frame.</param> /// <returns></returns> protected byte[] GetWebSocketData(WebSocketDataFrame frame) { int offset = frame.InnerData.Count - (int)frame.ActualPayloadLength; int length = (int)frame.ActualPayloadLength; if (frame.HasMask && length > 0) { frame.InnerData.DecodeMask(frame.MaskKey, offset, length); } byte[] data; if (length > 0) data = frame.InnerData.ToArrayData(offset, length); else data = new byte[0]; return data; }
public override int Process(int lastLength, WebSocketDataFrame frame, out IDataFramePartReader nextPartReader) { int required = 2; if (frame.PayloadLenght == 126) { required += 2; } else { required += 8; } if (frame.Length < required) { nextPartReader = this; return(-1); } if (frame.HasMask) { nextPartReader = MaskKeyReader; } else { if (frame.ActualPayloadLength == 0) { nextPartReader = null; return((int)((long)frame.Length - required)); } nextPartReader = PayloadDataReader; } if (frame.Length > required) { return(nextPartReader.Process(required, frame, out nextPartReader)); } return(0); }
/// <summary> /// Gets text string from a websocket frame. /// </summary> /// <param name="frame">The frame.</param> /// <returns></returns> protected string GetWebSocketText(WebSocketDataFrame frame) { int offset = frame.InnerData.Count - (int)frame.ActualPayloadLength; int length = (int)frame.ActualPayloadLength; if (frame.HasMask && length > 0) { frame.InnerData.DecodeMask(frame.MaskKey, offset, length); } string text; if (length > 0) { text = frame.InnerData.Decode(Utf8Encoding, offset, length); } else { text = string.Empty; } return(text); }
public WebSocketCommandInfo(IList <WebSocketDataFrame> frames) { sbyte opCode = frames[0].OpCode; this.Key = opCode.ToString(); switch (opCode) { case 2: byte[] to = new byte[frames.Sum <WebSocketDataFrame> ( (Func <WebSocketDataFrame, int>)(f => (int)f.ActualPayloadLength))]; int toIndex = 0; for (int index = 0; index < frames.Count; ++index) { WebSocketDataFrame frame = frames[index]; int num = frame.InnerData.Count - (int)frame.ActualPayloadLength; int actualPayloadLength = (int)frame.ActualPayloadLength; if (frame.HasMask) { frame.InnerData.DecodeMask(frame.MaskKey, num, actualPayloadLength); } frame.InnerData.CopyTo(to, num, toIndex, actualPayloadLength); toIndex += actualPayloadLength; } this.Data = to; break; case 8: WebSocketDataFrame frame1 = frames[0]; int actualPayloadLength1 = (int)frame1.ActualPayloadLength; int offset1 = frame1.InnerData.Count - actualPayloadLength1; StringBuilder stringBuilder1 = new StringBuilder(); if (actualPayloadLength1 >= 2) { int startIndex = frame1.InnerData.Count - actualPayloadLength1; byte[] arrayData = frame1.InnerData.ToArrayData(startIndex, 2); this.CloseStatusCode = (short)((int)arrayData[0] * 256 + (int)arrayData[1]); if (actualPayloadLength1 > 2) { stringBuilder1.Append(frame1.InnerData.Decode(Encoding.UTF8, startIndex + 2, actualPayloadLength1 - 2)); } } else if (actualPayloadLength1 > 0) { stringBuilder1.Append(frame1.InnerData.Decode(Encoding.UTF8, offset1, actualPayloadLength1)); } if (frames.Count > 1) { for (int index = 1; index < frames.Count; ++index) { WebSocketDataFrame frame2 = frames[index]; int offset2 = frame2.InnerData.Count - (int)frame2.ActualPayloadLength; int actualPayloadLength2 = (int)frame2.ActualPayloadLength; if (frame2.HasMask) { frame2.InnerData.DecodeMask(frame2.MaskKey, offset2, actualPayloadLength2); } stringBuilder1.Append(frame2.InnerData.Decode(Encoding.UTF8, offset2, actualPayloadLength2)); } } this.Text = stringBuilder1.ToString(); break; default: StringBuilder stringBuilder2 = new StringBuilder(); for (int index = 0; index < frames.Count; ++index) { WebSocketDataFrame frame2 = frames[index]; int offset2 = frame2.InnerData.Count - (int)frame2.ActualPayloadLength; int actualPayloadLength2 = (int)frame2.ActualPayloadLength; if (frame2.HasMask) { frame2.InnerData.DecodeMask(frame2.MaskKey, offset2, actualPayloadLength2); } stringBuilder2.Append(frame2.InnerData.Decode(Encoding.UTF8, offset2, actualPayloadLength2)); } this.Text = stringBuilder2.ToString(); break; } }
/// <summary> /// Checks the frame. /// </summary> /// <param name="frame">The frame.</param> /// <returns></returns> protected bool CheckFrame(WebSocketDataFrame frame) { //Check RSV return((frame.InnerData[0] & 0x70) == 0x00); }
public WebSocketCommandInfo(IList <WebSocketDataFrame> frames) { sbyte opCode = frames[0].OpCode; Key = opCode.ToString(); switch (opCode) { case 8: { WebSocketDataFrame webSocketDataFrame2 = frames[0]; int num3 = (int)webSocketDataFrame2.ActualPayloadLength; int num2 = webSocketDataFrame2.InnerData.Count - num3; StringBuilder stringBuilder = new StringBuilder(); if (num3 >= 2) { num2 = webSocketDataFrame2.InnerData.Count - num3; byte[] array2 = webSocketDataFrame2.InnerData.ToArrayData(num2, 2); CloseStatusCode = (short)(array2[0] * 256 + array2[1]); if (num3 > 2) { stringBuilder.Append(webSocketDataFrame2.InnerData.Decode(Encoding.UTF8, num2 + 2, num3 - 2)); } } else if (num3 > 0) { stringBuilder.Append(webSocketDataFrame2.InnerData.Decode(Encoding.UTF8, num2, num3)); } if (frames.Count > 1) { for (int j = 1; j < frames.Count; j++) { WebSocketDataFrame webSocketDataFrame3 = frames[j]; num2 = webSocketDataFrame3.InnerData.Count - (int)webSocketDataFrame3.ActualPayloadLength; num3 = (int)webSocketDataFrame3.ActualPayloadLength; if (webSocketDataFrame3.HasMask) { webSocketDataFrame3.InnerData.DecodeMask(webSocketDataFrame3.MaskKey, num2, num3); } stringBuilder.Append(webSocketDataFrame3.InnerData.Decode(Encoding.UTF8, num2, num3)); } } Text = stringBuilder.ToString(); return; } case 2: { byte[] array = new byte[frames.Sum((WebSocketDataFrame f) => (int)f.ActualPayloadLength)]; int num = 0; for (int i = 0; i < frames.Count; i++) { WebSocketDataFrame webSocketDataFrame = frames[i]; int num2 = webSocketDataFrame.InnerData.Count - (int)webSocketDataFrame.ActualPayloadLength; int num3 = (int)webSocketDataFrame.ActualPayloadLength; if (webSocketDataFrame.HasMask) { webSocketDataFrame.InnerData.DecodeMask(webSocketDataFrame.MaskKey, num2, num3); } webSocketDataFrame.InnerData.CopyTo(array, num2, num, num3); num += num3; } Data = array; return; } } StringBuilder stringBuilder2 = new StringBuilder(); for (int k = 0; k < frames.Count; k++) { WebSocketDataFrame webSocketDataFrame4 = frames[k]; int num2 = webSocketDataFrame4.InnerData.Count - (int)webSocketDataFrame4.ActualPayloadLength; int num3 = (int)webSocketDataFrame4.ActualPayloadLength; if (webSocketDataFrame4.HasMask) { webSocketDataFrame4.InnerData.DecodeMask(webSocketDataFrame4.MaskKey, num2, num3); } stringBuilder2.Append(webSocketDataFrame4.InnerData.Decode(Encoding.UTF8, num2, num3)); } Text = stringBuilder2.ToString(); }
public abstract int Process(int lastLength, WebSocketDataFrame frame, out IDataFramePartReader nextPartReader);
// Token: 0x06000561 RID: 1377 RVA: 0x00018584 File Offset: 0x00016784 public WebSocketCommandInfo(IList <WebSocketDataFrame> frames) { sbyte opCode = frames[0].OpCode; this.Key = opCode.ToString(); if (opCode == 8) { WebSocketDataFrame webSocketDataFrame = frames[0]; int num = (int)webSocketDataFrame.ActualPayloadLength; int num2 = webSocketDataFrame.InnerData.Count - num; StringBuilder stringBuilder = new StringBuilder(); if (num >= 2) { num2 = webSocketDataFrame.InnerData.Count - num; byte[] array = webSocketDataFrame.InnerData.ToArrayData(num2, 2); this.CloseStatusCode = (short)((int)array[0] * 256 + (int)array[1]); if (num > 2) { stringBuilder.Append(webSocketDataFrame.InnerData.Decode(Encoding.UTF8, num2 + 2, num - 2)); } } else if (num > 0) { stringBuilder.Append(webSocketDataFrame.InnerData.Decode(Encoding.UTF8, num2, num)); } if (frames.Count > 1) { for (int i = 1; i < frames.Count; i++) { WebSocketDataFrame webSocketDataFrame2 = frames[i]; num2 = webSocketDataFrame2.InnerData.Count - (int)webSocketDataFrame2.ActualPayloadLength; num = (int)webSocketDataFrame2.ActualPayloadLength; if (webSocketDataFrame2.HasMask) { webSocketDataFrame2.InnerData.DecodeMask(webSocketDataFrame2.MaskKey, num2, num); } stringBuilder.Append(webSocketDataFrame2.InnerData.Decode(Encoding.UTF8, num2, num)); } } this.Text = stringBuilder.ToString(); return; } if (opCode != 2) { StringBuilder stringBuilder2 = new StringBuilder(); for (int j = 0; j < frames.Count; j++) { WebSocketDataFrame webSocketDataFrame3 = frames[j]; int num2 = webSocketDataFrame3.InnerData.Count - (int)webSocketDataFrame3.ActualPayloadLength; int num = (int)webSocketDataFrame3.ActualPayloadLength; if (webSocketDataFrame3.HasMask) { webSocketDataFrame3.InnerData.DecodeMask(webSocketDataFrame3.MaskKey, num2, num); } stringBuilder2.Append(webSocketDataFrame3.InnerData.Decode(Encoding.UTF8, num2, num)); } this.Text = stringBuilder2.ToString(); return; } byte[] array2 = new byte[frames.Sum((WebSocketDataFrame f) => (int)f.ActualPayloadLength)]; int num3 = 0; for (int k = 0; k < frames.Count; k++) { WebSocketDataFrame webSocketDataFrame4 = frames[k]; int num2 = webSocketDataFrame4.InnerData.Count - (int)webSocketDataFrame4.ActualPayloadLength; int num = (int)webSocketDataFrame4.ActualPayloadLength; if (webSocketDataFrame4.HasMask) { webSocketDataFrame4.InnerData.DecodeMask(webSocketDataFrame4.MaskKey, num2, num); } webSocketDataFrame4.InnerData.CopyTo(array2, num2, num3, num); num3 += num; } this.Data = array2; }