Replace tabs with spaces

This commit is contained in:
Norman Maurer 2011-11-04 19:28:15 +01:00
parent 5094bdc0cc
commit d176f4ae83
24 changed files with 1844 additions and 1865 deletions

View File

@ -57,6 +57,7 @@ public class PongWebSocketFrame extends WebSocketFrame {
this.setRsv(rsv); this.setRsv(rsv);
this.setBinaryData(binaryData); this.setBinaryData(binaryData);
} }
@Override @Override
public String toString() { public String toString() {
return getClass().getSimpleName() + "(data: " + getBinaryData() + ')'; return getClass().getSimpleName() + "(data: " + getBinaryData() + ')';

View File

@ -30,20 +30,12 @@ public class UTF8Output {
private static final int UTF8_ACCEPT = 0; private static final int UTF8_ACCEPT = 0;
private static final int UTF8_REJECT = 12; private static final int UTF8_REJECT = 12;
private static final byte[] TYPES = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, private static final byte[] TYPES = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 9, 9, 9, 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, 72, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 0, 12, 12, 12, 12, 12, 0, 12, 0, 12, 12, 12, 24, 12, 12, 12, 12, 12, 24, 12, 24, 12, 12, 12, 12, 12, 12, 12, 12, 12, 24, 12, 12, 12, 12, 12, 24, 12, 12, 12,
12, 12, 12, 12, 12, 12, 0, 12, 12, 12, 12, 12, 0, 12, 0, 12, 12, 12, 24, 12, 12, 12, 12, 12, 24, 12, 24, 12, 12, 12, 12, 24, 12, 12, 12, 12, 12, 12, 12, 12, 12, 36, 12, 36, 12, 12, 12, 36, 12, 12, 12, 12, 12, 36, 12, 36, 12, 12, 12, 36, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12 };
12, 12, 12, 12, 12, 12, 12, 12, 12, 24, 12, 12, 12, 12, 12, 24, 12, 12, 12, 12, 12, 12, 12, 24, 12, 12, 12,
12, 12, 12, 12, 12, 12, 36, 12, 36, 12, 12, 12, 36, 12, 12, 12, 12, 12, 36, 12, 36, 12, 12, 12, 36, 12, 12,
12, 12, 12, 12, 12, 12, 12, 12 };
private int state = UTF8_ACCEPT; private int state = UTF8_ACCEPT;
private int codep = 0; private int codep = 0;

View File

@ -61,8 +61,7 @@ public class WebSocket00FrameDecoder extends ReplayingDecoder<VoidEnum> {
} }
@Override @Override
protected Object decode(ChannelHandlerContext ctx, Channel channel, ChannelBuffer buffer, VoidEnum state) protected Object decode(ChannelHandlerContext ctx, Channel channel, ChannelBuffer buffer, VoidEnum state) throws Exception {
throws Exception {
// Discard all data received if closing handshake was received before. // Discard all data received if closing handshake was received before.
if (receivedClosingHandshake) { if (receivedClosingHandshake) {

View File

@ -46,8 +46,7 @@ public class WebSocket00FrameEncoder extends OneToOneEncoder {
if (frame instanceof TextWebSocketFrame) { if (frame instanceof TextWebSocketFrame) {
// Text frame // Text frame
ChannelBuffer data = frame.getBinaryData(); ChannelBuffer data = frame.getBinaryData();
ChannelBuffer encoded = channel.getConfig().getBufferFactory() ChannelBuffer encoded = channel.getConfig().getBufferFactory().getBuffer(data.order(), data.readableBytes() + 2);
.getBuffer(data.order(), data.readableBytes() + 2);
encoded.writeByte((byte) 0x00); encoded.writeByte((byte) 0x00);
encoded.writeBytes(data, data.readerIndex(), data.readableBytes()); encoded.writeBytes(data, data.readerIndex(), data.readableBytes());
encoded.writeByte((byte) 0xFF); encoded.writeByte((byte) 0xFF);

View File

@ -51,7 +51,8 @@ import org.jboss.netty.logging.InternalLoggerFactory;
/** /**
* Decodes a web socket frame from wire protocol version 8 format. This code was * Decodes a web socket frame from wire protocol version 8 format. This code was
* forked from <a href="https://github.com/joewalnes/webbit">webbit</a> and modified. * forked from <a href="https://github.com/joewalnes/webbit">webbit</a> and
* modified.
* *
* @author Aslak Hellesøy * @author Aslak Hellesøy
* @author <a href="http://www.veebsbraindump.com/">Vibul Imtarnasan</a> * @author <a href="http://www.veebsbraindump.com/">Vibul Imtarnasan</a>
@ -102,8 +103,7 @@ public class WebSocket08FrameDecoder extends ReplayingDecoder<WebSocket08FrameDe
} }
@Override @Override
protected Object decode(ChannelHandlerContext ctx, Channel channel, ChannelBuffer buffer, State state) protected Object decode(ChannelHandlerContext ctx, Channel channel, ChannelBuffer buffer, State state) throws Exception {
throws Exception {
// Discard all data received if closing handshake was received before. // Discard all data received if closing handshake was received before.
if (receivedClosingHandshake) { if (receivedClosingHandshake) {
@ -206,10 +206,10 @@ public class WebSocket08FrameDecoder extends ReplayingDecoder<WebSocket08FrameDe
framePayloadLength = framePayloadLen1; framePayloadLength = framePayloadLen1;
} }
//logger.debug("Frame length=" + framePayloadLength); // logger.debug("Frame length=" + framePayloadLength);
checkpoint(State.MASKING_KEY); checkpoint(State.MASKING_KEY);
case MASKING_KEY: case MASKING_KEY:
if (this.maskedPayload){ if (this.maskedPayload) {
maskingKey = buffer.readBytes(4); maskingKey = buffer.readBytes(4);
} }
checkpoint(State.PAYLOAD); checkpoint(State.PAYLOAD);
@ -220,7 +220,9 @@ public class WebSocket08FrameDecoder extends ReplayingDecoder<WebSocket08FrameDe
ChannelBuffer payloadBuffer = null; ChannelBuffer payloadBuffer = null;
int willHaveReadByteCount = framePayloadBytesRead + rbytes; int willHaveReadByteCount = framePayloadBytesRead + rbytes;
//logger.debug("Frame rbytes=" + rbytes + " willHaveReadByteCount=" + willHaveReadByteCount + " framePayloadLength=" + framePayloadLength); // logger.debug("Frame rbytes=" + rbytes + " willHaveReadByteCount="
// + willHaveReadByteCount + " framePayloadLength=" +
// framePayloadLength);
if (willHaveReadByteCount == framePayloadLength) { if (willHaveReadByteCount == framePayloadLength) {
// We have all our content so proceed to process // We have all our content so proceed to process
payloadBuffer = buffer.readBytes(rbytes); payloadBuffer = buffer.readBytes(rbytes);

View File

@ -52,7 +52,8 @@ import org.jboss.netty.logging.InternalLoggerFactory;
/** /**
* <p> * <p>
* Encodes a web socket frame into wire protocol version 8 format. This code was * Encodes a web socket frame into wire protocol version 8 format. This code was
* forked from <a href="https://github.com/joewalnes/webbit">webbit</a> and modified. * forked from <a href="https://github.com/joewalnes/webbit">webbit</a> and
* modified.
* </p> * </p>
* *
* @author Aslak Hellesøy * @author Aslak Hellesøy
@ -126,8 +127,7 @@ public class WebSocket08FrameEncoder extends OneToOneEncoder {
ChannelBuffer body; ChannelBuffer body;
if (opcode == OPCODE_PING && length > 125) { if (opcode == OPCODE_PING && length > 125) {
throw new TooLongFrameException("invalid payload for PING (payload length must be <= 125, was " throw new TooLongFrameException("invalid payload for PING (payload length must be <= 125, was " + length);
+ length);
} }
int maskLength = this.maskPayload ? 4 : 0; int maskLength = this.maskPayload ? 4 : 0;

View File

@ -131,8 +131,7 @@ public abstract class WebSocketClientHandshaker {
* @param response * @param response
* HTTP response containing the closing handshake details * HTTP response containing the closing handshake details
*/ */
public abstract void endOpeningHandshake(ChannelHandlerContext ctx, HttpResponse response) public abstract void endOpeningHandshake(ChannelHandlerContext ctx, HttpResponse response) throws WebSocketHandshakeException;
throws WebSocketHandshakeException;
/** /**
* Performs an MD5 hash * Performs an MD5 hash

View File

@ -178,8 +178,7 @@ public class WebSocketClientHandshaker00 extends WebSocketClientHandshaker {
* @throws WebSocketHandshakeException * @throws WebSocketHandshakeException
*/ */
@Override @Override
public void endOpeningHandshake(ChannelHandlerContext ctx, HttpResponse response) public void endOpeningHandshake(ChannelHandlerContext ctx, HttpResponse response) throws WebSocketHandshakeException {
throws WebSocketHandshakeException {
final HttpResponseStatus status = new HttpResponseStatus(101, "WebSocket Protocol Handshake"); final HttpResponseStatus status = new HttpResponseStatus(101, "WebSocket Protocol Handshake");
if (!response.getStatus().equals(status)) { if (!response.getStatus().equals(status)) {
@ -188,14 +187,12 @@ public class WebSocketClientHandshaker00 extends WebSocketClientHandshaker {
String upgrade = response.getHeader(Names.UPGRADE); String upgrade = response.getHeader(Names.UPGRADE);
if (upgrade == null || !upgrade.equals(Values.WEBSOCKET)) { if (upgrade == null || !upgrade.equals(Values.WEBSOCKET)) {
throw new WebSocketHandshakeException("Invalid handshake response upgrade: " throw new WebSocketHandshakeException("Invalid handshake response upgrade: " + response.getHeader(Names.UPGRADE));
+ response.getHeader(Names.UPGRADE));
} }
String connection = response.getHeader(Names.CONNECTION); String connection = response.getHeader(Names.CONNECTION);
if (connection == null || !connection.equals(Values.UPGRADE)) { if (connection == null || !connection.equals(Values.UPGRADE)) {
throw new WebSocketHandshakeException("Invalid handshake response connection: " throw new WebSocketHandshakeException("Invalid handshake response connection: " + response.getHeader(Names.CONNECTION));
+ response.getHeader(Names.CONNECTION));
} }
byte[] challenge = response.getContent().array(); byte[] challenge = response.getContent().array();

View File

@ -67,10 +67,10 @@ public class WebSocketClientHandshaker10 extends WebSocketClientHandshaker {
* @param subProtocol * @param subProtocol
* Sub protocol request sent to the server. * Sub protocol request sent to the server.
* @param allowExtensions * @param allowExtensions
* Allow extensions to be used in the reserved bits of the web socket frame * Allow extensions to be used in the reserved bits of the web
* socket frame
*/ */
public WebSocketClientHandshaker10(URI webSocketURL, WebSocketSpecificationVersion version, String subProtocol, public WebSocketClientHandshaker10(URI webSocketURL, WebSocketSpecificationVersion version, String subProtocol, boolean allowExtensions) {
boolean allowExtensions) {
super(webSocketURL, version, subProtocol); super(webSocketURL, version, subProtocol);
this.allowExtensions = allowExtensions; this.allowExtensions = allowExtensions;
return; return;
@ -116,8 +116,7 @@ public class WebSocketClientHandshaker10 extends WebSocketClientHandshaker {
this.expectedChallengeResponseString = base64Encode(sha1); this.expectedChallengeResponseString = base64Encode(sha1);
if (logger.isDebugEnabled()) { if (logger.isDebugEnabled()) {
logger.debug(String.format("HyBi10 Client Handshake key: %s. Expected response: %s.", key, logger.debug(String.format("HyBi10 Client Handshake key: %s. Expected response: %s.", key, this.expectedChallengeResponseString));
this.expectedChallengeResponseString));
} }
// Format request // Format request
@ -159,8 +158,7 @@ public class WebSocketClientHandshaker10 extends WebSocketClientHandshaker {
* @throws WebSocketHandshakeException * @throws WebSocketHandshakeException
*/ */
@Override @Override
public void endOpeningHandshake(ChannelHandlerContext ctx, HttpResponse response) public void endOpeningHandshake(ChannelHandlerContext ctx, HttpResponse response) throws WebSocketHandshakeException {
throws WebSocketHandshakeException {
final HttpResponseStatus status = new HttpResponseStatus(101, "Switching Protocols"); final HttpResponseStatus status = new HttpResponseStatus(101, "Switching Protocols");
if (!response.getStatus().equals(status)) { if (!response.getStatus().equals(status)) {
@ -169,20 +167,17 @@ public class WebSocketClientHandshaker10 extends WebSocketClientHandshaker {
String upgrade = response.getHeader(Names.UPGRADE); String upgrade = response.getHeader(Names.UPGRADE);
if (upgrade == null || !upgrade.equals(Values.WEBSOCKET.toLowerCase())) { if (upgrade == null || !upgrade.equals(Values.WEBSOCKET.toLowerCase())) {
throw new WebSocketHandshakeException("Invalid handshake response upgrade: " throw new WebSocketHandshakeException("Invalid handshake response upgrade: " + response.getHeader(Names.UPGRADE));
+ response.getHeader(Names.UPGRADE));
} }
String connection = response.getHeader(Names.CONNECTION); String connection = response.getHeader(Names.CONNECTION);
if (connection == null || !connection.equals(Values.UPGRADE)) { if (connection == null || !connection.equals(Values.UPGRADE)) {
throw new WebSocketHandshakeException("Invalid handshake response connection: " throw new WebSocketHandshakeException("Invalid handshake response connection: " + response.getHeader(Names.CONNECTION));
+ response.getHeader(Names.CONNECTION));
} }
String accept = response.getHeader(Names.SEC_WEBSOCKET_ACCEPT); String accept = response.getHeader(Names.SEC_WEBSOCKET_ACCEPT);
if (accept == null || !accept.equals(this.expectedChallengeResponseString)) { if (accept == null || !accept.equals(this.expectedChallengeResponseString)) {
throw new WebSocketHandshakeException(String.format("Invalid challenge. Actual: %s. Expected: %s", accept, throw new WebSocketHandshakeException(String.format("Invalid challenge. Actual: %s. Expected: %s", accept, this.expectedChallengeResponseString));
this.expectedChallengeResponseString));
} }
ctx.getPipeline().replace("decoder", "ws-decoder", new WebSocket08FrameDecoder(false, this.allowExtensions)); ctx.getPipeline().replace("decoder", "ws-decoder", new WebSocket08FrameDecoder(false, this.allowExtensions));

View File

@ -38,11 +38,11 @@ public class WebSocketClientHandshakerFactory {
* Sub protocol request sent to the server. Null if no * Sub protocol request sent to the server. Null if no
* sub-protocol support is required. * sub-protocol support is required.
* @param allowExtensions * @param allowExtensions
* Allow extensions to be used in the reserved bits of the web socket frame * Allow extensions to be used in the reserved bits of the web
* socket frame
* @throws WebSocketHandshakeException * @throws WebSocketHandshakeException
*/ */
public WebSocketClientHandshaker newHandshaker(URI webSocketURL, WebSocketSpecificationVersion version, public WebSocketClientHandshaker newHandshaker(URI webSocketURL, WebSocketSpecificationVersion version, String subProtocol, boolean allowExtensions) throws WebSocketHandshakeException {
String subProtocol, boolean allowExtensions) throws WebSocketHandshakeException {
if (version == WebSocketSpecificationVersion.V10) { if (version == WebSocketSpecificationVersion.V10) {
return new WebSocketClientHandshaker10(webSocketURL, version, subProtocol, allowExtensions); return new WebSocketClientHandshaker10(webSocketURL, version, subProtocol, allowExtensions);
} }

View File

@ -77,6 +77,4 @@ public abstract class WebSocketFrame {
this.rsv = rsv; this.rsv = rsv;
} }
} }

View File

@ -133,8 +133,7 @@ public class WebSocketServerHandshaker00 extends WebSocketServerHandshaker {
this.setVersion(WebSocketSpecificationVersion.V00); this.setVersion(WebSocketSpecificationVersion.V00);
// Serve the WebSocket handshake request. // Serve the WebSocket handshake request.
if (!Values.UPGRADE.equalsIgnoreCase(req.getHeader(CONNECTION)) if (!Values.UPGRADE.equalsIgnoreCase(req.getHeader(CONNECTION)) || !WEBSOCKET.equalsIgnoreCase(req.getHeader(Names.UPGRADE))) {
|| !WEBSOCKET.equalsIgnoreCase(req.getHeader(Names.UPGRADE))) {
return; return;
} }
@ -142,8 +141,7 @@ public class WebSocketServerHandshaker00 extends WebSocketServerHandshaker {
boolean isHixie76 = req.containsHeader(SEC_WEBSOCKET_KEY1) && req.containsHeader(SEC_WEBSOCKET_KEY2); boolean isHixie76 = req.containsHeader(SEC_WEBSOCKET_KEY1) && req.containsHeader(SEC_WEBSOCKET_KEY2);
// Create the WebSocket handshake response. // Create the WebSocket handshake response.
HttpResponse res = new DefaultHttpResponse(HTTP_1_1, new HttpResponseStatus(101, HttpResponse res = new DefaultHttpResponse(HTTP_1_1, new HttpResponseStatus(101, isHixie76 ? "WebSocket Protocol Handshake" : "Web Socket Protocol Handshake"));
isHixie76 ? "WebSocket Protocol Handshake" : "Web Socket Protocol Handshake"));
res.addHeader(Names.UPGRADE, WEBSOCKET); res.addHeader(Names.UPGRADE, WEBSOCKET);
res.addHeader(CONNECTION, Values.UPGRADE); res.addHeader(CONNECTION, Values.UPGRADE);

View File

@ -97,8 +97,7 @@ public class WebSocketServerHandshakerFactory {
* Context * Context
*/ */
public void sendUnsupportedWebSocketVersionResponse(ChannelHandlerContext ctx) { public void sendUnsupportedWebSocketVersionResponse(ChannelHandlerContext ctx) {
HttpResponse res = new DefaultHttpResponse(HttpVersion.HTTP_1_1, new HttpResponseStatus(101, HttpResponse res = new DefaultHttpResponse(HttpVersion.HTTP_1_1, new HttpResponseStatus(101, "Switching Protocols"));
"Switching Protocols"));
res.setStatus(HttpResponseStatus.UPGRADE_REQUIRED); res.setStatus(HttpResponseStatus.UPGRADE_REQUIRED);
res.setHeader(Names.SEC_WEBSOCKET_VERSION, "8"); res.setHeader(Names.SEC_WEBSOCKET_VERSION, "8");
ctx.getChannel().write(res); ctx.getChannel().write(res);