This commit is contained in:
crusader 2018-04-22 20:14:05 +09:00
parent f74352ab95
commit 1c35dd6024
14 changed files with 183 additions and 183 deletions

View File

@ -4,14 +4,14 @@ import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled; import io.netty.buffer.Unpooled;
/** /**
* Web Socket frame containing binary data * Socket frame containing binary data
*/ */
public class BinaryWebSocketFrame extends WebSocketFrame { public class BinarySocketFrame extends SocketFrame {
/** /**
* Creates a new empty binary frame. * Creates a new empty binary frame.
*/ */
public BinaryWebSocketFrame() { public BinarySocketFrame() {
super(Unpooled.buffer(0)); super(Unpooled.buffer(0));
} }
@ -21,7 +21,7 @@ public class BinaryWebSocketFrame extends WebSocketFrame {
* @param binaryData * @param binaryData
* the content of the frame. * the content of the frame.
*/ */
public BinaryWebSocketFrame(ByteBuf binaryData) { public BinarySocketFrame(ByteBuf binaryData) {
super(binaryData); super(binaryData);
} }
@ -35,50 +35,50 @@ public class BinaryWebSocketFrame extends WebSocketFrame {
* @param binaryData * @param binaryData
* the content of the frame. * the content of the frame.
*/ */
public BinaryWebSocketFrame(boolean finalFragment, int rsv, ByteBuf binaryData) { public BinarySocketFrame(boolean finalFragment, int rsv, ByteBuf binaryData) {
super(finalFragment, rsv, binaryData); super(finalFragment, rsv, binaryData);
} }
@Override @Override
public BinaryWebSocketFrame copy() { public BinarySocketFrame copy() {
return (BinaryWebSocketFrame) super.copy(); return (BinarySocketFrame) super.copy();
} }
@Override @Override
public BinaryWebSocketFrame duplicate() { public BinarySocketFrame duplicate() {
return (BinaryWebSocketFrame) super.duplicate(); return (BinarySocketFrame) super.duplicate();
} }
@Override @Override
public BinaryWebSocketFrame retainedDuplicate() { public BinarySocketFrame retainedDuplicate() {
return (BinaryWebSocketFrame) super.retainedDuplicate(); return (BinarySocketFrame) super.retainedDuplicate();
} }
@Override @Override
public BinaryWebSocketFrame replace(ByteBuf content) { public BinarySocketFrame replace(ByteBuf content) {
return new BinaryWebSocketFrame(isFinalFragment(), rsv(), content); return new BinarySocketFrame(isFinalFragment(), rsv(), content);
} }
@Override @Override
public BinaryWebSocketFrame retain() { public BinarySocketFrame retain() {
super.retain(); super.retain();
return this; return this;
} }
@Override @Override
public BinaryWebSocketFrame retain(int increment) { public BinarySocketFrame retain(int increment) {
super.retain(increment); super.retain(increment);
return this; return this;
} }
@Override @Override
public BinaryWebSocketFrame touch() { public BinarySocketFrame touch() {
super.touch(); super.touch();
return this; return this;
} }
@Override @Override
public BinaryWebSocketFrame touch(Object hint) { public BinarySocketFrame touch(Object hint) {
super.touch(hint); super.touch(hint);
return this; return this;
} }

View File

@ -6,14 +6,14 @@ import io.netty.util.CharsetUtil;
import io.netty.util.internal.StringUtil; import io.netty.util.internal.StringUtil;
/** /**
* Web Socket Frame for closing the connection * Socket Frame for closing the connection
*/ */
public class CloseWebSocketFrame extends WebSocketFrame { public class CloseSocketFrame extends SocketFrame {
/** /**
* Creates a new empty close frame. * Creates a new empty close frame.
*/ */
public CloseWebSocketFrame() { public CloseSocketFrame() {
super(Unpooled.buffer(0)); super(Unpooled.buffer(0));
} }
@ -26,7 +26,7 @@ public class CloseWebSocketFrame extends WebSocketFrame {
* @param reasonText * @param reasonText
* Reason text. Set to null if no text. * Reason text. Set to null if no text.
*/ */
public CloseWebSocketFrame(int statusCode, String reasonText) { public CloseSocketFrame(int statusCode, String reasonText) {
this(true, 0, statusCode, reasonText); this(true, 0, statusCode, reasonText);
} }
@ -38,7 +38,7 @@ public class CloseWebSocketFrame extends WebSocketFrame {
* @param rsv * @param rsv
* reserved bits used for protocol extensions * reserved bits used for protocol extensions
*/ */
public CloseWebSocketFrame(boolean finalFragment, int rsv) { public CloseSocketFrame(boolean finalFragment, int rsv) {
this(finalFragment, rsv, Unpooled.buffer(0)); this(finalFragment, rsv, Unpooled.buffer(0));
} }
@ -55,7 +55,7 @@ public class CloseWebSocketFrame extends WebSocketFrame {
* @param reasonText * @param reasonText
* Reason text. Set to null if no text. * Reason text. Set to null if no text.
*/ */
public CloseWebSocketFrame(boolean finalFragment, int rsv, int statusCode, String reasonText) { public CloseSocketFrame(boolean finalFragment, int rsv, int statusCode, String reasonText) {
super(finalFragment, rsv, newBinaryData(statusCode, reasonText)); super(finalFragment, rsv, newBinaryData(statusCode, reasonText));
} }
@ -84,7 +84,7 @@ public class CloseWebSocketFrame extends WebSocketFrame {
* @param binaryData * @param binaryData
* the content of the frame. Must be 2 byte integer followed by optional UTF-8 encoded string. * the content of the frame. Must be 2 byte integer followed by optional UTF-8 encoded string.
*/ */
public CloseWebSocketFrame(boolean finalFragment, int rsv, ByteBuf binaryData) { public CloseSocketFrame(boolean finalFragment, int rsv, ByteBuf binaryData) {
super(finalFragment, rsv, binaryData); super(finalFragment, rsv, binaryData);
} }
@ -123,45 +123,45 @@ public class CloseWebSocketFrame extends WebSocketFrame {
} }
@Override @Override
public CloseWebSocketFrame copy() { public CloseSocketFrame copy() {
return (CloseWebSocketFrame) super.copy(); return (CloseSocketFrame) super.copy();
} }
@Override @Override
public CloseWebSocketFrame duplicate() { public CloseSocketFrame duplicate() {
return (CloseWebSocketFrame) super.duplicate(); return (CloseSocketFrame) super.duplicate();
} }
@Override @Override
public CloseWebSocketFrame retainedDuplicate() { public CloseSocketFrame retainedDuplicate() {
return (CloseWebSocketFrame) super.retainedDuplicate(); return (CloseSocketFrame) super.retainedDuplicate();
} }
@Override @Override
public CloseWebSocketFrame replace(ByteBuf content) { public CloseSocketFrame replace(ByteBuf content) {
return new CloseWebSocketFrame(isFinalFragment(), rsv(), content); return new CloseSocketFrame(isFinalFragment(), rsv(), content);
} }
@Override @Override
public CloseWebSocketFrame retain() { public CloseSocketFrame retain() {
super.retain(); super.retain();
return this; return this;
} }
@Override @Override
public CloseWebSocketFrame retain(int increment) { public CloseSocketFrame retain(int increment) {
super.retain(increment); super.retain(increment);
return this; return this;
} }
@Override @Override
public CloseWebSocketFrame touch() { public CloseSocketFrame touch() {
super.touch(); super.touch();
return this; return this;
} }
@Override @Override
public CloseWebSocketFrame touch(Object hint) { public CloseSocketFrame touch(Object hint) {
super.touch(hint); super.touch(hint);
return this; return this;
} }

View File

@ -5,15 +5,15 @@ import io.netty.buffer.Unpooled;
import io.netty.util.CharsetUtil; import io.netty.util.CharsetUtil;
/** /**
* Web Socket continuation frame containing continuation text or binary data. This is used for * Socket continuation frame containing continuation text or binary data. This is used for
* fragmented messages where the contents of a messages is contained more than 1 frame. * fragmented messages where the contents of a messages is contained more than 1 frame.
*/ */
public class ContinuationWebSocketFrame extends WebSocketFrame { public class ContinuationSocketFrame extends SocketFrame {
/** /**
* Creates a new empty continuation frame. * Creates a new empty continuation frame.
*/ */
public ContinuationWebSocketFrame() { public ContinuationSocketFrame() {
this(Unpooled.buffer(0)); this(Unpooled.buffer(0));
} }
@ -23,7 +23,7 @@ public class ContinuationWebSocketFrame extends WebSocketFrame {
* *
* @param binaryData the content of the frame. * @param binaryData the content of the frame.
*/ */
public ContinuationWebSocketFrame(ByteBuf binaryData) { public ContinuationSocketFrame(ByteBuf binaryData) {
super(binaryData); super(binaryData);
} }
@ -37,7 +37,7 @@ public class ContinuationWebSocketFrame extends WebSocketFrame {
* @param binaryData * @param binaryData
* the content of the frame. * the content of the frame.
*/ */
public ContinuationWebSocketFrame(boolean finalFragment, int rsv, ByteBuf binaryData) { public ContinuationSocketFrame(boolean finalFragment, int rsv, ByteBuf binaryData) {
super(finalFragment, rsv, binaryData); super(finalFragment, rsv, binaryData);
} }
@ -51,7 +51,7 @@ public class ContinuationWebSocketFrame extends WebSocketFrame {
* @param text * @param text
* text content of the frame. * text content of the frame.
*/ */
public ContinuationWebSocketFrame(boolean finalFragment, int rsv, String text) { public ContinuationSocketFrame(boolean finalFragment, int rsv, String text) {
this(finalFragment, rsv, fromText(text)); this(finalFragment, rsv, fromText(text));
} }
@ -77,45 +77,45 @@ public class ContinuationWebSocketFrame extends WebSocketFrame {
} }
@Override @Override
public ContinuationWebSocketFrame copy() { public ContinuationSocketFrame copy() {
return (ContinuationWebSocketFrame) super.copy(); return (ContinuationSocketFrame) super.copy();
} }
@Override @Override
public ContinuationWebSocketFrame duplicate() { public ContinuationSocketFrame duplicate() {
return (ContinuationWebSocketFrame) super.duplicate(); return (ContinuationSocketFrame) super.duplicate();
} }
@Override @Override
public ContinuationWebSocketFrame retainedDuplicate() { public ContinuationSocketFrame retainedDuplicate() {
return (ContinuationWebSocketFrame) super.retainedDuplicate(); return (ContinuationSocketFrame) super.retainedDuplicate();
} }
@Override @Override
public ContinuationWebSocketFrame replace(ByteBuf content) { public ContinuationSocketFrame replace(ByteBuf content) {
return new ContinuationWebSocketFrame(isFinalFragment(), rsv(), content); return new ContinuationSocketFrame(isFinalFragment(), rsv(), content);
} }
@Override @Override
public ContinuationWebSocketFrame retain() { public ContinuationSocketFrame retain() {
super.retain(); super.retain();
return this; return this;
} }
@Override @Override
public ContinuationWebSocketFrame retain(int increment) { public ContinuationSocketFrame retain(int increment) {
super.retain(increment); super.retain(increment);
return this; return this;
} }
@Override @Override
public ContinuationWebSocketFrame touch() { public ContinuationSocketFrame touch() {
super.touch(); super.touch();
return this; return this;
} }
@Override @Override
public ContinuationWebSocketFrame touch(Object hint) { public ContinuationSocketFrame touch(Object hint) {
super.touch(hint); super.touch(hint);
return this; return this;
} }

View File

@ -4,14 +4,14 @@ import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled; import io.netty.buffer.Unpooled;
/** /**
* Web Socket frame containing binary data * Socket frame containing binary data
*/ */
public class PingWebSocketFrame extends WebSocketFrame { public class PingSocketFrame extends SocketFrame {
/** /**
* Creates a new empty ping frame. * Creates a new empty ping frame.
*/ */
public PingWebSocketFrame() { public PingSocketFrame() {
super(true, 0, Unpooled.buffer(0)); super(true, 0, Unpooled.buffer(0));
} }
@ -21,7 +21,7 @@ public class PingWebSocketFrame extends WebSocketFrame {
* @param binaryData * @param binaryData
* the content of the frame. * the content of the frame.
*/ */
public PingWebSocketFrame(ByteBuf binaryData) { public PingSocketFrame(ByteBuf binaryData) {
super(binaryData); super(binaryData);
} }
@ -35,50 +35,50 @@ public class PingWebSocketFrame extends WebSocketFrame {
* @param binaryData * @param binaryData
* the content of the frame. * the content of the frame.
*/ */
public PingWebSocketFrame(boolean finalFragment, int rsv, ByteBuf binaryData) { public PingSocketFrame(boolean finalFragment, int rsv, ByteBuf binaryData) {
super(finalFragment, rsv, binaryData); super(finalFragment, rsv, binaryData);
} }
@Override @Override
public PingWebSocketFrame copy() { public PingSocketFrame copy() {
return (PingWebSocketFrame) super.copy(); return (PingSocketFrame) super.copy();
} }
@Override @Override
public PingWebSocketFrame duplicate() { public PingSocketFrame duplicate() {
return (PingWebSocketFrame) super.duplicate(); return (PingSocketFrame) super.duplicate();
} }
@Override @Override
public PingWebSocketFrame retainedDuplicate() { public PingSocketFrame retainedDuplicate() {
return (PingWebSocketFrame) super.retainedDuplicate(); return (PingSocketFrame) super.retainedDuplicate();
} }
@Override @Override
public PingWebSocketFrame replace(ByteBuf content) { public PingSocketFrame replace(ByteBuf content) {
return new PingWebSocketFrame(isFinalFragment(), rsv(), content); return new PingSocketFrame(isFinalFragment(), rsv(), content);
} }
@Override @Override
public PingWebSocketFrame retain() { public PingSocketFrame retain() {
super.retain(); super.retain();
return this; return this;
} }
@Override @Override
public PingWebSocketFrame retain(int increment) { public PingSocketFrame retain(int increment) {
super.retain(increment); super.retain(increment);
return this; return this;
} }
@Override @Override
public PingWebSocketFrame touch() { public PingSocketFrame touch() {
super.touch(); super.touch();
return this; return this;
} }
@Override @Override
public PingWebSocketFrame touch(Object hint) { public PingSocketFrame touch(Object hint) {
super.touch(hint); super.touch(hint);
return this; return this;
} }

View File

@ -4,14 +4,14 @@ import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled; import io.netty.buffer.Unpooled;
/** /**
* Web Socket frame containing binary data * Socket frame containing binary data
*/ */
public class PongWebSocketFrame extends WebSocketFrame { public class PongSocketFrame extends SocketFrame {
/** /**
* Creates a new empty pong frame. * Creates a new empty pong frame.
*/ */
public PongWebSocketFrame() { public PongSocketFrame() {
super(Unpooled.buffer(0)); super(Unpooled.buffer(0));
} }
@ -21,7 +21,7 @@ public class PongWebSocketFrame extends WebSocketFrame {
* @param binaryData * @param binaryData
* the content of the frame. * the content of the frame.
*/ */
public PongWebSocketFrame(ByteBuf binaryData) { public PongSocketFrame(ByteBuf binaryData) {
super(binaryData); super(binaryData);
} }
@ -35,50 +35,50 @@ public class PongWebSocketFrame extends WebSocketFrame {
* @param binaryData * @param binaryData
* the content of the frame. * the content of the frame.
*/ */
public PongWebSocketFrame(boolean finalFragment, int rsv, ByteBuf binaryData) { public PongSocketFrame(boolean finalFragment, int rsv, ByteBuf binaryData) {
super(finalFragment, rsv, binaryData); super(finalFragment, rsv, binaryData);
} }
@Override @Override
public PongWebSocketFrame copy() { public PongSocketFrame copy() {
return (PongWebSocketFrame) super.copy(); return (PongSocketFrame) super.copy();
} }
@Override @Override
public PongWebSocketFrame duplicate() { public PongSocketFrame duplicate() {
return (PongWebSocketFrame) super.duplicate(); return (PongSocketFrame) super.duplicate();
} }
@Override @Override
public PongWebSocketFrame retainedDuplicate() { public PongSocketFrame retainedDuplicate() {
return (PongWebSocketFrame) super.retainedDuplicate(); return (PongSocketFrame) super.retainedDuplicate();
} }
@Override @Override
public PongWebSocketFrame replace(ByteBuf content) { public PongSocketFrame replace(ByteBuf content) {
return new PongWebSocketFrame(isFinalFragment(), rsv(), content); return new PongSocketFrame(isFinalFragment(), rsv(), content);
} }
@Override @Override
public PongWebSocketFrame retain() { public PongSocketFrame retain() {
super.retain(); super.retain();
return this; return this;
} }
@Override @Override
public PongWebSocketFrame retain(int increment) { public PongSocketFrame retain(int increment) {
super.retain(increment); super.retain(increment);
return this; return this;
} }
@Override @Override
public PongWebSocketFrame touch() { public PongSocketFrame touch() {
super.touch(); super.touch();
return this; return this;
} }
@Override @Override
public PongWebSocketFrame touch(Object hint) { public PongSocketFrame touch(Object hint) {
super.touch(hint); super.touch(hint);
return this; return this;
} }

View File

@ -15,16 +15,16 @@ import io.netty.util.internal.logging.InternalLogger;
import io.netty.util.internal.logging.InternalLoggerFactory; import io.netty.util.internal.logging.InternalLoggerFactory;
/** /**
* Decodes a web socket frame from wire protocol version 8 format. This code was forked from <a * Decodes a socket frame from wire protocol version 8 format. This code was forked from <a
* href="https://github.com/joewalnes/webbit">webbit</a> and modified. * href="https://github.com/joewalnes/webbit">webbit</a> and modified.
*/ */
public class WebSocket13FrameDecoder extends ByteToMessageDecoder implements WebSocketFrameDecoder { public class Socket13FrameDecoder extends ByteToMessageDecoder implements SocketFrameDecoder {
enum State { enum State {
READING_FIRST, READING_SECOND, READING_SIZE, MASKING_KEY, PAYLOAD, CORRUPT READING_FIRST, READING_SECOND, READING_SIZE, MASKING_KEY, PAYLOAD, CORRUPT
} }
private static final InternalLogger logger = InternalLoggerFactory.getInstance(WebSocket13FrameDecoder.class); private static final InternalLogger logger = InternalLoggerFactory.getInstance(Socket13FrameDecoder.class);
private static final byte OPCODE_CONT = 0x0; private static final byte OPCODE_CONT = 0x0;
private static final byte OPCODE_TEXT = 0x1; private static final byte OPCODE_TEXT = 0x1;
@ -52,7 +52,7 @@ public class WebSocket13FrameDecoder extends ByteToMessageDecoder implements Web
* Constructor * Constructor
* *
* @param expectMaskedFrames * @param expectMaskedFrames
* Web socket servers must set this to true processed incoming masked payload. Client implementations * Socket servers must set this to true processed incoming masked payload. Client implementations
* must set this to false. * must set this to false.
* @param allowExtensions * @param allowExtensions
* Flag to allow reserved extension bits to be used or not * Flag to allow reserved extension bits to be used or not
@ -60,7 +60,7 @@ public class WebSocket13FrameDecoder extends ByteToMessageDecoder implements Web
* Maximum length of a frame's payload. Setting this to an appropriate value for you application * Maximum length of a frame's payload. Setting this to an appropriate value for you application
* helps check for denial of services attacks. * helps check for denial of services attacks.
*/ */
public WebSocket13FrameDecoder(boolean expectMaskedFrames, boolean allowExtensions, int maxFramePayloadLength) { public Socket13FrameDecoder(boolean expectMaskedFrames, boolean allowExtensions, int maxFramePayloadLength) {
this(expectMaskedFrames, allowExtensions, maxFramePayloadLength, false); this(expectMaskedFrames, allowExtensions, maxFramePayloadLength, false);
} }
@ -68,7 +68,7 @@ public class WebSocket13FrameDecoder extends ByteToMessageDecoder implements Web
* Constructor * Constructor
* *
* @param expectMaskedFrames * @param expectMaskedFrames
* Web socket servers must set this to true processed incoming masked payload. Client implementations * Socket servers must set this to true processed incoming masked payload. Client implementations
* must set this to false. * must set this to false.
* @param allowExtensions * @param allowExtensions
* Flag to allow reserved extension bits to be used or not * Flag to allow reserved extension bits to be used or not
@ -79,7 +79,7 @@ public class WebSocket13FrameDecoder extends ByteToMessageDecoder implements Web
* When set to true, frames which are not masked properly according to the standard will still be * When set to true, frames which are not masked properly according to the standard will still be
* accepted. * accepted.
*/ */
public WebSocket13FrameDecoder(boolean expectMaskedFrames, boolean allowExtensions, int maxFramePayloadLength, public Socket13FrameDecoder(boolean expectMaskedFrames, boolean allowExtensions, int maxFramePayloadLength,
boolean allowMaskMismatch) { boolean allowMaskMismatch) {
this.expectMaskedFrames = expectMaskedFrames; this.expectMaskedFrames = expectMaskedFrames;
this.allowMaskMismatch = allowMaskMismatch; this.allowMaskMismatch = allowMaskMismatch;
@ -104,7 +104,7 @@ public class WebSocket13FrameDecoder extends ByteToMessageDecoder implements Web
frameOpcode = b & 0x0F; frameOpcode = b & 0x0F;
if (logger.isDebugEnabled()) { if (logger.isDebugEnabled()) {
logger.debug("Decoding WebSocket Frame opCode={}", frameOpcode); logger.debug("Decoding Socket Frame opCode={}", frameOpcode);
} }
state = State.READING_SECOND; state = State.READING_SECOND;
@ -209,7 +209,7 @@ public class WebSocket13FrameDecoder extends ByteToMessageDecoder implements Web
} }
if (logger.isDebugEnabled()) { if (logger.isDebugEnabled()) {
logger.debug("Decoding WebSocket Frame length={}", framePayloadLength); logger.debug("Decoding Socket Frame length={}", framePayloadLength);
} }
state = State.MASKING_KEY; state = State.MASKING_KEY;
@ -245,18 +245,18 @@ public class WebSocket13FrameDecoder extends ByteToMessageDecoder implements Web
// Processing ping/pong/close frames because they cannot be // Processing ping/pong/close frames because they cannot be
// fragmented // fragmented
if (frameOpcode == OPCODE_PING) { if (frameOpcode == OPCODE_PING) {
out.add(new PingWebSocketFrame(frameFinalFlag, frameRsv, payloadBuffer)); out.add(new PingSocketFrame(frameFinalFlag, frameRsv, payloadBuffer));
payloadBuffer = null; payloadBuffer = null;
return; return;
} }
if (frameOpcode == OPCODE_PONG) { if (frameOpcode == OPCODE_PONG) {
out.add(new PongWebSocketFrame(frameFinalFlag, frameRsv, payloadBuffer)); out.add(new PongSocketFrame(frameFinalFlag, frameRsv, payloadBuffer));
payloadBuffer = null; payloadBuffer = null;
return; return;
} }
if (frameOpcode == OPCODE_CLOSE) { if (frameOpcode == OPCODE_CLOSE) {
checkCloseFrameBody(ctx, payloadBuffer); checkCloseFrameBody(ctx, payloadBuffer);
out.add(new CloseWebSocketFrame(frameFinalFlag, frameRsv, payloadBuffer)); out.add(new CloseSocketFrame(frameFinalFlag, frameRsv, payloadBuffer));
payloadBuffer = null; payloadBuffer = null;
return; return;
} }
@ -276,19 +276,19 @@ public class WebSocket13FrameDecoder extends ByteToMessageDecoder implements Web
// Return the frame // Return the frame
if (frameOpcode == OPCODE_TEXT) { if (frameOpcode == OPCODE_TEXT) {
out.add(new TextWebSocketFrame(frameFinalFlag, frameRsv, payloadBuffer)); out.add(new TextSocketFrame(frameFinalFlag, frameRsv, payloadBuffer));
payloadBuffer = null; payloadBuffer = null;
return; return;
} else if (frameOpcode == OPCODE_BINARY) { } else if (frameOpcode == OPCODE_BINARY) {
out.add(new BinaryWebSocketFrame(frameFinalFlag, frameRsv, payloadBuffer)); out.add(new BinarySocketFrame(frameFinalFlag, frameRsv, payloadBuffer));
payloadBuffer = null; payloadBuffer = null;
return; return;
} else if (frameOpcode == OPCODE_CONT) { } else if (frameOpcode == OPCODE_CONT) {
out.add(new ContinuationWebSocketFrame(frameFinalFlag, frameRsv, payloadBuffer)); out.add(new ContinuationSocketFrame(frameFinalFlag, frameRsv, payloadBuffer));
payloadBuffer = null; payloadBuffer = null;
return; return;
} else { } else {
throw new UnsupportedOperationException("Cannot decode web socket frame with opcode: " + frameOpcode); throw new UnsupportedOperationException("Cannot decode socket frame with opcode: " + frameOpcode);
} }
} finally { } finally {
if (payloadBuffer != null) { if (payloadBuffer != null) {
@ -340,7 +340,7 @@ public class WebSocket13FrameDecoder extends ByteToMessageDecoder implements Web
private void protocolViolation(ChannelHandlerContext ctx, CorruptedFrameException ex) { private void protocolViolation(ChannelHandlerContext ctx, CorruptedFrameException ex) {
state = State.CORRUPT; state = State.CORRUPT;
if (ctx.channel().isActive()) { if (ctx.channel().isActive()) {
Object closeMessage = new CloseWebSocketFrame(1002, null); Object closeMessage = new CloseSocketFrame(1002, null);
ctx.writeAndFlush(closeMessage).addListener(ChannelFutureListener.CLOSE); ctx.writeAndFlush(closeMessage).addListener(ChannelFutureListener.CLOSE);
} }
throw ex; throw ex;

View File

@ -13,13 +13,13 @@ import java.util.List;
/** /**
* <p> * <p>
* Encodes a web socket frame into wire protocol version 8 format. This code was forked from <a * Encodes a socket frame into wire protocol version 8 format. This code was forked from <a
* href="https://github.com/joewalnes/webbit">webbit</a> and modified. * href="https://github.com/joewalnes/webbit">webbit</a> and modified.
* </p> * </p>
*/ */
public class WebSocket13FrameEncoder extends MessageToMessageEncoder<WebSocketFrame> implements WebSocketFrameEncoder { public class Socket13FrameEncoder extends MessageToMessageEncoder<SocketFrame> implements SocketFrameEncoder {
private static final InternalLogger logger = InternalLoggerFactory.getInstance(WebSocket13FrameEncoder.class); private static final InternalLogger logger = InternalLoggerFactory.getInstance(Socket13FrameEncoder.class);
private static final byte OPCODE_CONT = 0x0; private static final byte OPCODE_CONT = 0x0;
private static final byte OPCODE_TEXT = 0x1; private static final byte OPCODE_TEXT = 0x1;
@ -42,30 +42,30 @@ public class WebSocket13FrameEncoder extends MessageToMessageEncoder<WebSocketFr
* Constructor * Constructor
* *
* @param maskPayload * @param maskPayload
* Web socket clients must set this to true to mask payload. Server implementations must set this to * Socket clients must set this to true to mask payload. Server implementations must set this to
* false. * false.
*/ */
public WebSocket13FrameEncoder(boolean maskPayload) { public Socket13FrameEncoder(boolean maskPayload) {
this.maskPayload = maskPayload; this.maskPayload = maskPayload;
} }
@Override @Override
protected void encode(ChannelHandlerContext ctx, WebSocketFrame msg, List<Object> out) throws Exception { protected void encode(ChannelHandlerContext ctx, SocketFrame msg, List<Object> out) throws Exception {
final ByteBuf data = msg.content(); final ByteBuf data = msg.content();
byte[] mask; byte[] mask;
byte opcode; byte opcode;
if (msg instanceof TextWebSocketFrame) { if (msg instanceof TextSocketFrame) {
opcode = OPCODE_TEXT; opcode = OPCODE_TEXT;
} else if (msg instanceof PingWebSocketFrame) { } else if (msg instanceof PingSocketFrame) {
opcode = OPCODE_PING; opcode = OPCODE_PING;
} else if (msg instanceof PongWebSocketFrame) { } else if (msg instanceof PongSocketFrame) {
opcode = OPCODE_PONG; opcode = OPCODE_PONG;
} else if (msg instanceof CloseWebSocketFrame) { } else if (msg instanceof CloseSocketFrame) {
opcode = OPCODE_CLOSE; opcode = OPCODE_CLOSE;
} else if (msg instanceof BinaryWebSocketFrame) { } else if (msg instanceof BinarySocketFrame) {
opcode = OPCODE_BINARY; opcode = OPCODE_BINARY;
} else if (msg instanceof ContinuationWebSocketFrame) { } else if (msg instanceof ContinuationSocketFrame) {
opcode = OPCODE_CONT; opcode = OPCODE_CONT;
} else { } else {
throw new UnsupportedOperationException("Cannot encode frame of type: " + msg.getClass().getName()); throw new UnsupportedOperationException("Cannot encode frame of type: " + msg.getClass().getName());
@ -74,7 +74,7 @@ public class WebSocket13FrameEncoder extends MessageToMessageEncoder<WebSocketFr
int length = data.readableBytes(); int length = data.readableBytes();
if (logger.isDebugEnabled()) { if (logger.isDebugEnabled()) {
logger.debug("Encoding WebSocket Frame opCode=" + opcode + " length=" + length); logger.debug("Encoding Socket Frame opCode=" + opcode + " length=" + length);
} }
int b0 = 0; int b0 = 0;

View File

@ -5,9 +5,9 @@ import io.netty.buffer.DefaultByteBufHolder;
import io.netty.util.internal.StringUtil; import io.netty.util.internal.StringUtil;
/** /**
* Base class for web socket frames * Base class for socket frames
*/ */
public abstract class WebSocketFrame extends DefaultByteBufHolder { public abstract class SocketFrame extends DefaultByteBufHolder {
/** /**
* Flag to indicate if this frame is the final fragment in a message. The first fragment (frame) may also be the * Flag to indicate if this frame is the final fragment in a message. The first fragment (frame) may also be the
@ -20,11 +20,11 @@ public abstract class WebSocketFrame extends DefaultByteBufHolder {
*/ */
private final int rsv; private final int rsv;
protected WebSocketFrame(ByteBuf binaryData) { protected SocketFrame(ByteBuf binaryData) {
this(true, 0, binaryData); this(true, 0, binaryData);
} }
protected WebSocketFrame(boolean finalFragment, int rsv, ByteBuf binaryData) { protected SocketFrame(boolean finalFragment, int rsv, ByteBuf binaryData) {
super(binaryData); super(binaryData);
this.finalFragment = finalFragment; this.finalFragment = finalFragment;
this.rsv = rsv; this.rsv = rsv;
@ -46,22 +46,22 @@ public abstract class WebSocketFrame extends DefaultByteBufHolder {
} }
@Override @Override
public WebSocketFrame copy() { public SocketFrame copy() {
return (WebSocketFrame) super.copy(); return (SocketFrame) super.copy();
} }
@Override @Override
public WebSocketFrame duplicate() { public SocketFrame duplicate() {
return (WebSocketFrame) super.duplicate(); return (SocketFrame) super.duplicate();
} }
@Override @Override
public WebSocketFrame retainedDuplicate() { public SocketFrame retainedDuplicate() {
return (WebSocketFrame) super.retainedDuplicate(); return (SocketFrame) super.retainedDuplicate();
} }
@Override @Override
public abstract WebSocketFrame replace(ByteBuf content); public abstract SocketFrame replace(ByteBuf content);
@Override @Override
public String toString() { public String toString() {
@ -69,25 +69,25 @@ public abstract class WebSocketFrame extends DefaultByteBufHolder {
} }
@Override @Override
public WebSocketFrame retain() { public SocketFrame retain() {
super.retain(); super.retain();
return this; return this;
} }
@Override @Override
public WebSocketFrame retain(int increment) { public SocketFrame retain(int increment) {
super.retain(increment); super.retain(increment);
return this; return this;
} }
@Override @Override
public WebSocketFrame touch() { public SocketFrame touch() {
super.touch(); super.touch();
return this; return this;
} }
@Override @Override
public WebSocketFrame touch(Object hint) { public SocketFrame touch(Object hint) {
super.touch(hint); super.touch(hint);
return this; return this;
} }

View File

@ -4,9 +4,9 @@ import io.netty.channel.ChannelInboundHandler;
import io.netty.channel.ChannelPipeline; import io.netty.channel.ChannelPipeline;
/** /**
* Marker interface which all WebSocketFrame decoders need to implement. * Marker interface which all SocketFrame decoders need to implement.
* *
* This makes it easier to access the added encoder later in the {@link ChannelPipeline}. * This makes it easier to access the added encoder later in the {@link ChannelPipeline}.
*/ */
public interface WebSocketFrameDecoder extends ChannelInboundHandler { public interface SocketFrameDecoder extends ChannelInboundHandler {
} }

View File

@ -4,9 +4,9 @@ import io.netty.channel.ChannelOutboundHandler;
import io.netty.channel.ChannelPipeline; import io.netty.channel.ChannelPipeline;
/** /**
* Marker interface which all WebSocketFrame encoders need to implement. * Marker interface which all SocketFrame encoders need to implement.
* *
* This makes it easier to access the added encoder later in the {@link ChannelPipeline}. * This makes it easier to access the added encoder later in the {@link ChannelPipeline}.
*/ */
public interface WebSocketFrameEncoder extends ChannelOutboundHandler { public interface SocketFrameEncoder extends ChannelOutboundHandler {
} }

View File

@ -5,15 +5,15 @@ import io.netty.handler.codec.MessageToMessageDecoder;
import java.util.List; import java.util.List;
abstract class WebSocketProtocolHandler extends MessageToMessageDecoder<WebSocketFrame> { abstract class SocketProtocolHandler extends MessageToMessageDecoder<SocketFrame> {
@Override @Override
protected void decode(ChannelHandlerContext ctx, WebSocketFrame frame, List<Object> out) throws Exception { protected void decode(ChannelHandlerContext ctx, SocketFrame frame, List<Object> out) throws Exception {
if (frame instanceof PingWebSocketFrame) { if (frame instanceof PingSocketFrame) {
frame.content().retain(); frame.content().retain();
ctx.channel().writeAndFlush(new PongWebSocketFrame(frame.content())); ctx.channel().writeAndFlush(new PongSocketFrame(frame.content()));
return; return;
} }
if (frame instanceof PongWebSocketFrame) { if (frame instanceof PongSocketFrame) {
// Pong frames need to get ignored // Pong frames need to get ignored
return; return;
} }

View File

@ -9,37 +9,37 @@ import io.netty.channel.ChannelPipeline;
import java.util.List; import java.util.List;
/** /**
* This handler does all the heavy lifting for you to run a websocket server. * This handler does all the heavy lifting for you to run a socket server.
* *
* It takes care of websocket handshaking as well as processing of control frames (Close, Ping, Pong). Text and Binary * It takes care of socket handshaking as well as processing of control frames (Close, Ping, Pong). Text and Binary
* data frames are passed to the next handler in the pipeline (implemented by you) for processing. * data frames are passed to the next handler in the pipeline (implemented by you) for processing.
* *
* See <tt>io.netty.example.http.websocketx.html5.WebSocketServer</tt> for usage. * See <tt>io.netty.example.http.websocketx.html5.SocketServer</tt> for usage.
* *
* The implementation of this handler assumes that you just want to run a websocket server and not process other types * The implementation of this handler assumes that you just want to run a socket server and not process other types
* HTTP requests (like GET and POST). If you wish to support both HTTP requests and websockets in the one server, refer * HTTP requests (like GET and POST). If you wish to support both HTTP requests and sockets in the one server, refer
* to the <tt>io.netty.example.http.websocketx.server.WebSocketServer</tt> example. * to the <tt>io.netty.example.http.websocketx.server.SocketServer</tt> example.
* *
* To know once a handshake was done you can intercept the * To know once a handshake was done you can intercept the
* {@link ChannelInboundHandler#userEventTriggered(ChannelHandlerContext, Object)} and check if the event was instance * {@link ChannelInboundHandler#userEventTriggered(ChannelHandlerContext, Object)} and check if the event was instance
* of {@link HandshakeComplete}, the event will contain extra information about the handshake such as the request and * of {@link HandshakeComplete}, the event will contain extra information about the handshake such as the request and
* selected subprotocol. * selected subprotocol.
*/ */
public class WebSocketServerProtocolHandler extends WebSocketProtocolHandler { public class SocketServerProtocolHandler extends SocketProtocolHandler {
private final boolean allowExtensions; private final boolean allowExtensions;
private final int maxFramePayloadLength; private final int maxFramePayloadLength;
private final boolean allowMaskMismatch; private final boolean allowMaskMismatch;
public WebSocketServerProtocolHandler(boolean allowExtensions) { public SocketServerProtocolHandler(boolean allowExtensions) {
this(allowExtensions, 65536); this(allowExtensions, 65536);
} }
public WebSocketServerProtocolHandler(boolean allowExtensions, int maxFrameSize) { public SocketServerProtocolHandler(boolean allowExtensions, int maxFrameSize) {
this(allowExtensions, maxFrameSize, false); this(allowExtensions, maxFrameSize, false);
} }
public WebSocketServerProtocolHandler(boolean allowExtensions, int maxFrameSize, boolean allowMaskMismatch) { public SocketServerProtocolHandler(boolean allowExtensions, int maxFrameSize, boolean allowMaskMismatch) {
this.allowExtensions = allowExtensions; this.allowExtensions = allowExtensions;
maxFramePayloadLength = maxFrameSize; maxFramePayloadLength = maxFrameSize;
this.allowMaskMismatch = allowMaskMismatch; this.allowMaskMismatch = allowMaskMismatch;
@ -49,12 +49,12 @@ public class WebSocketServerProtocolHandler extends WebSocketProtocolHandler {
public void handlerAdded(ChannelHandlerContext ctx) { public void handlerAdded(ChannelHandlerContext ctx) {
ChannelPipeline cp = ctx.pipeline(); ChannelPipeline cp = ctx.pipeline();
WebSocketFrameDecoder decoder = new WebSocket13FrameDecoder(true, allowExtensions, maxFramePayloadLength, SocketFrameDecoder decoder = new Socket13FrameDecoder(true, allowExtensions, maxFramePayloadLength,
allowMaskMismatch); allowMaskMismatch);
WebSocketFrameEncoder encoder = new WebSocket13FrameEncoder(false); SocketFrameEncoder encoder = new Socket13FrameEncoder(false);
cp.addBefore(ctx.name(), WebSocketFrameDecoder.class.getName(), decoder); cp.addBefore(ctx.name(), SocketFrameDecoder.class.getName(), decoder);
cp.addBefore(ctx.name(), WebSocketFrameEncoder.class.getName(), encoder); cp.addBefore(ctx.name(), SocketFrameEncoder.class.getName(), encoder);
if (cp.get(Utf8FrameValidator.class) == null) { if (cp.get(Utf8FrameValidator.class) == null) {
// Add the UFT8 checking before this one. // Add the UFT8 checking before this one.
@ -63,8 +63,8 @@ public class WebSocketServerProtocolHandler extends WebSocketProtocolHandler {
} }
@Override @Override
protected void decode(ChannelHandlerContext ctx, WebSocketFrame frame, List<Object> out) throws Exception { protected void decode(ChannelHandlerContext ctx, SocketFrame frame, List<Object> out) throws Exception {
if (frame instanceof CloseWebSocketFrame) { if (frame instanceof CloseSocketFrame) {
ctx.writeAndFlush(Unpooled.EMPTY_BUFFER).addListener(ChannelFutureListener.CLOSE); ctx.writeAndFlush(Unpooled.EMPTY_BUFFER).addListener(ChannelFutureListener.CLOSE);
return; return;
} }

View File

@ -5,14 +5,14 @@ import io.netty.buffer.Unpooled;
import io.netty.util.CharsetUtil; import io.netty.util.CharsetUtil;
/** /**
* Web Socket text frame * Socket text frame
*/ */
public class TextWebSocketFrame extends WebSocketFrame { public class TextSocketFrame extends SocketFrame {
/** /**
* Creates a new empty text frame. * Creates a new empty text frame.
*/ */
public TextWebSocketFrame() { public TextSocketFrame() {
super(Unpooled.buffer(0)); super(Unpooled.buffer(0));
} }
@ -22,7 +22,7 @@ public class TextWebSocketFrame extends WebSocketFrame {
* @param text * @param text
* String to put in the frame * String to put in the frame
*/ */
public TextWebSocketFrame(String text) { public TextSocketFrame(String text) {
super(fromText(text)); super(fromText(text));
} }
@ -32,7 +32,7 @@ public class TextWebSocketFrame extends WebSocketFrame {
* @param binaryData * @param binaryData
* the content of the frame. * the content of the frame.
*/ */
public TextWebSocketFrame(ByteBuf binaryData) { public TextSocketFrame(ByteBuf binaryData) {
super(binaryData); super(binaryData);
} }
@ -46,7 +46,7 @@ public class TextWebSocketFrame extends WebSocketFrame {
* @param text * @param text
* String to put in the frame * String to put in the frame
*/ */
public TextWebSocketFrame(boolean finalFragment, int rsv, String text) { public TextSocketFrame(boolean finalFragment, int rsv, String text) {
super(finalFragment, rsv, fromText(text)); super(finalFragment, rsv, fromText(text));
} }
@ -68,7 +68,7 @@ public class TextWebSocketFrame extends WebSocketFrame {
* @param binaryData * @param binaryData
* the content of the frame. * the content of the frame.
*/ */
public TextWebSocketFrame(boolean finalFragment, int rsv, ByteBuf binaryData) { public TextSocketFrame(boolean finalFragment, int rsv, ByteBuf binaryData) {
super(finalFragment, rsv, binaryData); super(finalFragment, rsv, binaryData);
} }
@ -80,45 +80,45 @@ public class TextWebSocketFrame extends WebSocketFrame {
} }
@Override @Override
public TextWebSocketFrame copy() { public TextSocketFrame copy() {
return (TextWebSocketFrame) super.copy(); return (TextSocketFrame) super.copy();
} }
@Override @Override
public TextWebSocketFrame duplicate() { public TextSocketFrame duplicate() {
return (TextWebSocketFrame) super.duplicate(); return (TextSocketFrame) super.duplicate();
} }
@Override @Override
public TextWebSocketFrame retainedDuplicate() { public TextSocketFrame retainedDuplicate() {
return (TextWebSocketFrame) super.retainedDuplicate(); return (TextSocketFrame) super.retainedDuplicate();
} }
@Override @Override
public TextWebSocketFrame replace(ByteBuf content) { public TextSocketFrame replace(ByteBuf content) {
return new TextWebSocketFrame(isFinalFragment(), rsv(), content); return new TextSocketFrame(isFinalFragment(), rsv(), content);
} }
@Override @Override
public TextWebSocketFrame retain() { public TextSocketFrame retain() {
super.retain(); super.retain();
return this; return this;
} }
@Override @Override
public TextWebSocketFrame retain(int increment) { public TextSocketFrame retain(int increment) {
super.retain(increment); super.retain(increment);
return this; return this;
} }
@Override @Override
public TextWebSocketFrame touch() { public TextSocketFrame touch() {
super.touch(); super.touch();
return this; return this;
} }
@Override @Override
public TextWebSocketFrame touch(Object hint) { public TextSocketFrame touch(Object hint) {
super.touch(hint); super.touch(hint);
return this; return this;
} }

View File

@ -17,19 +17,19 @@ public class Utf8FrameValidator extends ChannelInboundHandlerAdapter {
@Override @Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
if (msg instanceof WebSocketFrame) { if (msg instanceof SocketFrame) {
WebSocketFrame frame = (WebSocketFrame) msg; SocketFrame frame = (SocketFrame) msg;
// Processing for possible fragmented messages for text and binary // Processing for possible fragmented messages for text and binary
// frames // frames
if (((WebSocketFrame) msg).isFinalFragment()) { if (((SocketFrame) msg).isFinalFragment()) {
// Final frame of the sequence. Apparently ping frames are // Final frame of the sequence. Apparently ping frames are
// allowed in the middle of a fragmented message // allowed in the middle of a fragmented message
if (!(frame instanceof PingWebSocketFrame)) { if (!(frame instanceof PingSocketFrame)) {
fragmentedFramesCount = 0; fragmentedFramesCount = 0;
// Check text for UTF8 correctness // Check text for UTF8 correctness
if ((frame instanceof TextWebSocketFrame) || (utf8Validator != null && utf8Validator.isChecking())) { if ((frame instanceof TextSocketFrame) || (utf8Validator != null && utf8Validator.isChecking())) {
// Check UTF-8 correctness for this payload // Check UTF-8 correctness for this payload
checkUTF8String(ctx, frame.content()); checkUTF8String(ctx, frame.content());
@ -43,7 +43,7 @@ public class Utf8FrameValidator extends ChannelInboundHandlerAdapter {
// fragmented sequence // fragmented sequence
if (fragmentedFramesCount == 0) { if (fragmentedFramesCount == 0) {
// First text or binary frame for a fragmented set // First text or binary frame for a fragmented set
if (frame instanceof TextWebSocketFrame) { if (frame instanceof TextSocketFrame) {
checkUTF8String(ctx, frame.content()); checkUTF8String(ctx, frame.content());
} }
} else { } else {