Merge branch 'master' of github.com:netty/netty
This commit is contained in:
commit
b258a6de66
20
README.md
20
README.md
|
@ -19,16 +19,16 @@ Netty is an asynchronous event-driven network application framework for rapid de
|
|||
- Maven Repository:
|
||||
|
||||
```xml
|
||||
<dependencies>
|
||||
...
|
||||
<dependency>
|
||||
<groupId>io.netty</groupId>
|
||||
<artifactId>netty</artifactId>
|
||||
<version>X.Y.Z.Q</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
...
|
||||
</dependencies>
|
||||
<dependencies>
|
||||
...
|
||||
<dependency>
|
||||
<groupId>io.netty</groupId>
|
||||
<artifactId>netty</artifactId>
|
||||
<version>X.Y.Z.Q</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
...
|
||||
</dependencies>
|
||||
```
|
||||
|
||||
## Developer Information
|
||||
|
|
|
@ -345,8 +345,7 @@
|
|||
-group "Central interface for all I/O operations" io.netty.channel*
|
||||
-group "Client & Server bootstrapping utilities" io.netty.bootstrap*
|
||||
-group "Reusable I/O event interceptors" io.netty.handler*
|
||||
-group "Miscellaneous" io.netty.logging*:io.netty.util*:io.netty.monitor:io.netty.monitor.spi
|
||||
-group "Yammer monitoring support" io.netty.monitor.yammer*
|
||||
-group "Miscellaneous" io.netty.util*
|
||||
|
||||
-sourceclasspath ${project.build.outputDirectory}
|
||||
-nopackagediagram
|
||||
|
|
|
@ -54,7 +54,7 @@ import java.util.Map;
|
|||
* @see QueryStringEncoder
|
||||
*
|
||||
* @apiviz.stereotype utility
|
||||
* @apiviz.has io.netty.handler.codec.http.FullHttpRequest oneway - - decodes
|
||||
* @apiviz.has io.netty.handler.codec.http.HttpRequest oneway - - decodes URI
|
||||
*/
|
||||
public class QueryStringDecoder {
|
||||
|
||||
|
|
|
@ -36,7 +36,7 @@ import java.util.List;
|
|||
* @see QueryStringDecoder
|
||||
*
|
||||
* @apiviz.stereotype utility
|
||||
* @apiviz.has io.netty.handler.codec.http.FullHttpRequest oneway - - encodes
|
||||
* @apiviz.has io.netty.handler.codec.http.HttpRequest oneway - - encodes URI
|
||||
*/
|
||||
public class QueryStringEncoder {
|
||||
|
||||
|
@ -115,8 +115,9 @@ public class QueryStringEncoder {
|
|||
}
|
||||
|
||||
private static String encodeComponent(String s, Charset charset) {
|
||||
// TODO: Optimize me.
|
||||
try {
|
||||
return URLEncoder.encode(s, charset.name()).replaceAll("\\+", "%20");
|
||||
return URLEncoder.encode(s, charset.name()).replace("+", "%20");
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new UnsupportedCharsetException(charset.name());
|
||||
}
|
||||
|
|
|
@ -25,9 +25,6 @@ import io.netty.handler.codec.TooLongFrameException;
|
|||
* <p>
|
||||
* For the detailed instruction on adding add Web Socket support to your HTTP server, take a look into the
|
||||
* <tt>WebSocketServer</tt> example located in the {@code io.netty.example.http.websocket} package.
|
||||
*
|
||||
* @apiviz.landmark
|
||||
* @apiviz.uses io.netty.handler.codec.http.websocket.WebSocketFrame
|
||||
*/
|
||||
public class WebSocket00FrameDecoder extends ReplayingDecoder<Void> {
|
||||
|
||||
|
|
|
@ -25,9 +25,6 @@ import io.netty.handler.codec.MessageToByteEncoder;
|
|||
* <p>
|
||||
* For the detailed instruction on adding add Web Socket support to your HTTP server, take a look into the
|
||||
* <tt>WebSocketServer</tt> example located in the {@code io.netty.example.http.websocket} package.
|
||||
*
|
||||
* @apiviz.landmark
|
||||
* @apiviz.uses io.netty.handler.codec.http.websocket.WebSocketFrame
|
||||
*/
|
||||
@Sharable
|
||||
public class WebSocket00FrameEncoder extends MessageToByteEncoder<WebSocketFrame> {
|
||||
|
|
|
@ -59,8 +59,8 @@ import io.netty.channel.ChannelHandlerContext;
|
|||
import io.netty.handler.codec.CorruptedFrameException;
|
||||
import io.netty.handler.codec.ReplayingDecoder;
|
||||
import io.netty.handler.codec.TooLongFrameException;
|
||||
import io.netty.logging.InternalLogger;
|
||||
import io.netty.logging.InternalLoggerFactory;
|
||||
import io.netty.util.internal.InternalLogger;
|
||||
import io.netty.util.internal.InternalLoggerFactory;
|
||||
|
||||
/**
|
||||
* Decodes a web socket frame from wire protocol version 8 format. This code was forked from <a
|
||||
|
@ -93,7 +93,7 @@ public class WebSocket08FrameDecoder extends ReplayingDecoder<WebSocket08FrameDe
|
|||
private final boolean maskedPayload;
|
||||
private boolean receivedClosingHandshake;
|
||||
|
||||
public enum State {
|
||||
enum State {
|
||||
FRAME_START, MASKING_KEY, PAYLOAD, CORRUPT
|
||||
}
|
||||
|
||||
|
|
|
@ -58,8 +58,8 @@ import io.netty.buffer.Unpooled;
|
|||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.handler.codec.MessageToByteEncoder;
|
||||
import io.netty.handler.codec.TooLongFrameException;
|
||||
import io.netty.logging.InternalLogger;
|
||||
import io.netty.logging.InternalLoggerFactory;
|
||||
import io.netty.util.internal.InternalLogger;
|
||||
import io.netty.util.internal.InternalLoggerFactory;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
|
|
|
@ -31,9 +31,9 @@ import io.netty.handler.codec.http.HttpRequestEncoder;
|
|||
import io.netty.handler.codec.http.HttpResponseDecoder;
|
||||
import io.netty.handler.codec.http.HttpResponseStatus;
|
||||
import io.netty.handler.codec.http.HttpVersion;
|
||||
import io.netty.logging.InternalLogger;
|
||||
import io.netty.logging.InternalLoggerFactory;
|
||||
import io.netty.util.CharsetUtil;
|
||||
import io.netty.util.internal.InternalLogger;
|
||||
import io.netty.util.internal.InternalLoggerFactory;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
|
|
|
@ -31,9 +31,9 @@ import io.netty.handler.codec.http.HttpRequestEncoder;
|
|||
import io.netty.handler.codec.http.HttpResponseDecoder;
|
||||
import io.netty.handler.codec.http.HttpResponseStatus;
|
||||
import io.netty.handler.codec.http.HttpVersion;
|
||||
import io.netty.logging.InternalLogger;
|
||||
import io.netty.logging.InternalLoggerFactory;
|
||||
import io.netty.util.CharsetUtil;
|
||||
import io.netty.util.internal.InternalLogger;
|
||||
import io.netty.util.internal.InternalLoggerFactory;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
|
|
|
@ -31,9 +31,9 @@ import io.netty.handler.codec.http.HttpRequestEncoder;
|
|||
import io.netty.handler.codec.http.HttpResponseDecoder;
|
||||
import io.netty.handler.codec.http.HttpResponseStatus;
|
||||
import io.netty.handler.codec.http.HttpVersion;
|
||||
import io.netty.logging.InternalLogger;
|
||||
import io.netty.logging.InternalLoggerFactory;
|
||||
import io.netty.util.CharsetUtil;
|
||||
import io.netty.util.internal.InternalLogger;
|
||||
import io.netty.util.internal.InternalLoggerFactory;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
|
|
|
@ -22,7 +22,10 @@ import java.net.URI;
|
|||
import static io.netty.handler.codec.http.websocketx.WebSocketVersion.*;
|
||||
|
||||
/**
|
||||
* Instances the appropriate handshake class to use for clients
|
||||
* Creates a new {@link WebSocketClientHandshaker} of desired protocol version.
|
||||
*
|
||||
* @apiviz.landmark
|
||||
* @apiviz.has io.netty.handler.codec.http.websocketx.WebSocketClientHandshaker oneway - - creates
|
||||
*/
|
||||
public final class WebSocketClientHandshakerFactory {
|
||||
|
||||
|
|
|
@ -32,8 +32,8 @@ import io.netty.handler.codec.http.HttpObjectAggregator;
|
|||
import io.netty.handler.codec.http.HttpRequestDecoder;
|
||||
import io.netty.handler.codec.http.HttpResponseEncoder;
|
||||
import io.netty.handler.codec.http.HttpResponseStatus;
|
||||
import io.netty.logging.InternalLogger;
|
||||
import io.netty.logging.InternalLoggerFactory;
|
||||
import io.netty.util.internal.InternalLogger;
|
||||
import io.netty.util.internal.InternalLoggerFactory;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
|
|
|
@ -29,9 +29,9 @@ import io.netty.handler.codec.http.HttpObjectAggregator;
|
|||
import io.netty.handler.codec.http.HttpRequestDecoder;
|
||||
import io.netty.handler.codec.http.HttpResponseEncoder;
|
||||
import io.netty.handler.codec.http.HttpResponseStatus;
|
||||
import io.netty.logging.InternalLogger;
|
||||
import io.netty.logging.InternalLoggerFactory;
|
||||
import io.netty.util.CharsetUtil;
|
||||
import io.netty.util.internal.InternalLogger;
|
||||
import io.netty.util.internal.InternalLoggerFactory;
|
||||
|
||||
import static io.netty.handler.codec.http.HttpHeaders.Values.*;
|
||||
import static io.netty.handler.codec.http.HttpVersion.*;
|
||||
|
|
|
@ -29,9 +29,9 @@ import io.netty.handler.codec.http.HttpRequestDecoder;
|
|||
import io.netty.handler.codec.http.HttpResponse;
|
||||
import io.netty.handler.codec.http.HttpResponseEncoder;
|
||||
import io.netty.handler.codec.http.HttpResponseStatus;
|
||||
import io.netty.logging.InternalLogger;
|
||||
import io.netty.logging.InternalLoggerFactory;
|
||||
import io.netty.util.CharsetUtil;
|
||||
import io.netty.util.internal.InternalLogger;
|
||||
import io.netty.util.internal.InternalLoggerFactory;
|
||||
|
||||
import static io.netty.handler.codec.http.HttpHeaders.Values.*;
|
||||
import static io.netty.handler.codec.http.HttpVersion.*;
|
||||
|
|
|
@ -29,9 +29,9 @@ import io.netty.handler.codec.http.HttpRequestDecoder;
|
|||
import io.netty.handler.codec.http.HttpResponse;
|
||||
import io.netty.handler.codec.http.HttpResponseEncoder;
|
||||
import io.netty.handler.codec.http.HttpResponseStatus;
|
||||
import io.netty.logging.InternalLogger;
|
||||
import io.netty.logging.InternalLoggerFactory;
|
||||
import io.netty.util.CharsetUtil;
|
||||
import io.netty.util.internal.InternalLogger;
|
||||
import io.netty.util.internal.InternalLoggerFactory;
|
||||
|
||||
import static io.netty.handler.codec.http.HttpHeaders.Values.*;
|
||||
import static io.netty.handler.codec.http.HttpVersion.*;
|
||||
|
|
|
@ -24,7 +24,11 @@ import io.netty.handler.codec.http.HttpResponseStatus;
|
|||
import io.netty.handler.codec.http.HttpVersion;
|
||||
|
||||
/**
|
||||
* Instances the appropriate handshake class to use for servers
|
||||
* Auto-detects the version of the Web Socket protocol in use and creates a new proper
|
||||
* {@link WebSocketServerHandshaker}.
|
||||
*
|
||||
* @apiviz.landmark
|
||||
* @apiviz.has io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker oneway - - creates
|
||||
*/
|
||||
public class WebSocketServerHandshakerFactory {
|
||||
|
||||
|
|
|
@ -33,9 +33,9 @@
|
|||
* {@code io.netty.example.http.websocket} package.
|
||||
* </p>
|
||||
*
|
||||
* @apiviz.exclude OneToOne(Encoder|Decoder)$
|
||||
* @apiviz.exclude \.codec\.replay\.
|
||||
* @apiviz.exclude \.Default
|
||||
* @apiviz.exclude [0-9][0-9]
|
||||
* @apiviz.exclude Exception$
|
||||
* @apiviz.exclude Version$
|
||||
*/
|
||||
package io.netty.handler.codec.http.websocketx;
|
||||
|
||||
|
|
|
@ -33,16 +33,17 @@ import javax.net.ssl.SSLEngine;
|
|||
* {@link ChannelInboundByteHandler} which is responsible to setup the {@link ChannelPipeline} either for
|
||||
* HTTP or SPDY. This offers an easy way for users to support both at the same time while not care to
|
||||
* much about the low-level details.
|
||||
*
|
||||
*/
|
||||
public abstract class SpdyOrHttpChooser extends ChannelDuplexHandler implements ChannelInboundByteHandler {
|
||||
|
||||
// TODO: Replace with generic NPN handler
|
||||
|
||||
public enum SelectedProtocol {
|
||||
SpdyVersion2,
|
||||
SpdyVersion3,
|
||||
HttpVersion1_1,
|
||||
HttpVersion1_0,
|
||||
None
|
||||
SPDY_2,
|
||||
SPDY_3,
|
||||
HTTP_1_1,
|
||||
HTTP_1_0,
|
||||
UNKNOWN
|
||||
}
|
||||
|
||||
private final int maxSpdyContentLength;
|
||||
|
@ -55,7 +56,7 @@ public abstract class SpdyOrHttpChooser extends ChannelDuplexHandler implements
|
|||
|
||||
/**
|
||||
* Return the {@link SelectedProtocol} for the {@link SSLEngine}. If its not known yet implementations
|
||||
* MUST return {@link SelectedProtocol#None}.
|
||||
* MUST return {@link SelectedProtocol#UNKNOWN}.
|
||||
*
|
||||
*/
|
||||
protected abstract SelectedProtocol getProtocol(SSLEngine engine);
|
||||
|
@ -98,17 +99,17 @@ public abstract class SpdyOrHttpChooser extends ChannelDuplexHandler implements
|
|||
|
||||
SelectedProtocol protocol = getProtocol(handler.engine());
|
||||
switch (protocol) {
|
||||
case None:
|
||||
case UNKNOWN:
|
||||
// Not done with choosing the protocol, so just return here for now,
|
||||
return false;
|
||||
case SpdyVersion2:
|
||||
case SPDY_2:
|
||||
addSpdyHandlers(ctx, 2);
|
||||
break;
|
||||
case SpdyVersion3:
|
||||
case SPDY_3:
|
||||
addSpdyHandlers(ctx, 3);
|
||||
break;
|
||||
case HttpVersion1_0:
|
||||
case HttpVersion1_1:
|
||||
case HTTP_1_0:
|
||||
case HTTP_1_1:
|
||||
addHttpHandlers(ctx);
|
||||
break;
|
||||
default:
|
||||
|
@ -144,15 +145,15 @@ public abstract class SpdyOrHttpChooser extends ChannelDuplexHandler implements
|
|||
|
||||
/**
|
||||
* Create the {@link ChannelInboundMessageHandler} that is responsible for handling the http requests
|
||||
* when the {@link SelectedProtocol} was {@link SelectedProtocol#HttpVersion1_0} or
|
||||
* {@link SelectedProtocol#HttpVersion1_1}
|
||||
* when the {@link SelectedProtocol} was {@link SelectedProtocol#HTTP_1_0} or
|
||||
* {@link SelectedProtocol#HTTP_1_1}
|
||||
*/
|
||||
protected abstract ChannelInboundMessageHandler<?> createHttpRequestHandlerForHttp();
|
||||
|
||||
/**
|
||||
* Create the {@link ChannelInboundMessageHandler} that is responsible for handling the http responses
|
||||
* when the {@link SelectedProtocol} was {@link SelectedProtocol#SpdyVersion2} or
|
||||
* {@link SelectedProtocol#SpdyVersion3}.
|
||||
* when the {@link SelectedProtocol} was {@link SelectedProtocol#SPDY_2} or
|
||||
* {@link SelectedProtocol#SPDY_3}.
|
||||
*
|
||||
* Bye default this getMethod will just delecate to {@link #createHttpRequestHandlerForHttp()}, but
|
||||
* sub-classes may override this to change the behaviour.
|
||||
|
|
|
@ -18,8 +18,8 @@ package io.netty.handler.codec.spdy;
|
|||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.ChannelInboundMessageHandlerAdapter;
|
||||
import io.netty.channel.embedded.EmbeddedMessageChannel;
|
||||
import io.netty.logging.InternalLogger;
|
||||
import io.netty.logging.InternalLoggerFactory;
|
||||
import io.netty.util.internal.InternalLogger;
|
||||
import io.netty.util.internal.InternalLoggerFactory;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
/*
|
||||
* Copyright 2013 The Netty Project
|
||||
*
|
||||
* The Netty Project licenses this file to you under the Apache License,
|
||||
* version 2.0 (the "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at:
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package io.netty.handler.codec.socks;
|
||||
|
||||
public enum SocksAddressType {
|
||||
IPv4((byte) 0x01),
|
||||
DOMAIN((byte) 0x03),
|
||||
IPv6((byte) 0x04),
|
||||
UNKNOWN((byte) 0xff);
|
||||
|
||||
private final byte b;
|
||||
|
||||
SocksAddressType(byte b) {
|
||||
this.b = b;
|
||||
}
|
||||
|
||||
public static SocksAddressType fromByte(byte b) {
|
||||
for (SocksAddressType code : values()) {
|
||||
if (code.b == b) {
|
||||
return code;
|
||||
}
|
||||
}
|
||||
return UNKNOWN;
|
||||
}
|
||||
|
||||
public byte byteValue() {
|
||||
return b;
|
||||
}
|
||||
}
|
||||
|
|
@ -28,7 +28,7 @@ import java.nio.charset.CharsetEncoder;
|
|||
*/
|
||||
public final class SocksAuthRequest extends SocksRequest {
|
||||
private static final CharsetEncoder asciiEncoder = CharsetUtil.getEncoder(CharsetUtil.US_ASCII);
|
||||
private static final SubnegotiationVersion SUBNEGOTIATION_VERSION = SubnegotiationVersion.AUTH_PASSWORD;
|
||||
private static final SocksSubnegotiationVersion SUBNEGOTIATION_VERSION = SocksSubnegotiationVersion.AUTH_PASSWORD;
|
||||
private final String username;
|
||||
private final String password;
|
||||
|
||||
|
@ -74,7 +74,7 @@ public final class SocksAuthRequest extends SocksRequest {
|
|||
|
||||
@Override
|
||||
public void encodeAsByteBuf(ByteBuf byteBuf) {
|
||||
byteBuf.writeByte(SUBNEGOTIATION_VERSION.getByteValue());
|
||||
byteBuf.writeByte(SUBNEGOTIATION_VERSION.byteValue());
|
||||
byteBuf.writeByte(username.length());
|
||||
byteBuf.writeBytes(username.getBytes(CharsetUtil.US_ASCII));
|
||||
byteBuf.writeByte(password.length());
|
||||
|
|
|
@ -31,7 +31,7 @@ public class SocksAuthRequestDecoder extends ReplayingDecoder<SocksAuthRequestDe
|
|||
return name;
|
||||
}
|
||||
|
||||
private SocksMessage.SubnegotiationVersion version;
|
||||
private SocksSubnegotiationVersion version;
|
||||
private int fieldLength;
|
||||
private String username;
|
||||
private String password;
|
||||
|
@ -45,8 +45,8 @@ public class SocksAuthRequestDecoder extends ReplayingDecoder<SocksAuthRequestDe
|
|||
protected Object decode(ChannelHandlerContext ctx, ByteBuf byteBuf) throws Exception {
|
||||
switch (state()) {
|
||||
case CHECK_PROTOCOL_VERSION: {
|
||||
version = SocksMessage.SubnegotiationVersion.fromByte(byteBuf.readByte());
|
||||
if (version != SocksMessage.SubnegotiationVersion.AUTH_PASSWORD) {
|
||||
version = SocksSubnegotiationVersion.fromByte(byteBuf.readByte());
|
||||
if (version != SocksSubnegotiationVersion.AUTH_PASSWORD) {
|
||||
break;
|
||||
}
|
||||
checkpoint(State.READ_USERNAME);
|
||||
|
|
|
@ -24,10 +24,10 @@ import io.netty.buffer.ByteBuf;
|
|||
* @see SocksAuthResponseDecoder
|
||||
*/
|
||||
public final class SocksAuthResponse extends SocksResponse {
|
||||
private static final SubnegotiationVersion SUBNEGOTIATION_VERSION = SubnegotiationVersion.AUTH_PASSWORD;
|
||||
private final AuthStatus authStatus;
|
||||
private static final SocksSubnegotiationVersion SUBNEGOTIATION_VERSION = SocksSubnegotiationVersion.AUTH_PASSWORD;
|
||||
private final SocksAuthStatus authStatus;
|
||||
|
||||
public SocksAuthResponse(AuthStatus authStatus) {
|
||||
public SocksAuthResponse(SocksAuthStatus authStatus) {
|
||||
super(SocksResponseType.AUTH);
|
||||
if (authStatus == null) {
|
||||
throw new NullPointerException("authStatus");
|
||||
|
@ -36,17 +36,17 @@ public final class SocksAuthResponse extends SocksResponse {
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns the {@link AuthStatus} of this {@link SocksAuthResponse}
|
||||
* Returns the {@link SocksAuthStatus} of this {@link SocksAuthResponse}
|
||||
*
|
||||
* @return The {@link AuthStatus} of this {@link SocksAuthResponse}
|
||||
* @return The {@link SocksAuthStatus} of this {@link SocksAuthResponse}
|
||||
*/
|
||||
public AuthStatus authStatus() {
|
||||
public SocksAuthStatus authStatus() {
|
||||
return authStatus;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void encodeAsByteBuf(ByteBuf byteBuf) {
|
||||
byteBuf.writeByte(SUBNEGOTIATION_VERSION.getByteValue());
|
||||
byteBuf.writeByte(authStatus.getByteValue());
|
||||
byteBuf.writeByte(SUBNEGOTIATION_VERSION.byteValue());
|
||||
byteBuf.writeByte(authStatus.byteValue());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,8 +30,8 @@ public class SocksAuthResponseDecoder extends ReplayingDecoder<SocksAuthResponse
|
|||
return name;
|
||||
}
|
||||
|
||||
private SocksMessage.SubnegotiationVersion version;
|
||||
private SocksMessage.AuthStatus authStatus;
|
||||
private SocksSubnegotiationVersion version;
|
||||
private SocksAuthStatus authStatus;
|
||||
private SocksResponse msg = SocksCommonUtils.UNKNOWN_SOCKS_RESPONSE;
|
||||
|
||||
public SocksAuthResponseDecoder() {
|
||||
|
@ -42,14 +42,14 @@ public class SocksAuthResponseDecoder extends ReplayingDecoder<SocksAuthResponse
|
|||
protected Object decode(ChannelHandlerContext channelHandlerContext, ByteBuf byteBuf) throws Exception {
|
||||
switch (state()) {
|
||||
case CHECK_PROTOCOL_VERSION: {
|
||||
version = SocksMessage.SubnegotiationVersion.fromByte(byteBuf.readByte());
|
||||
if (version != SocksMessage.SubnegotiationVersion.AUTH_PASSWORD) {
|
||||
version = SocksSubnegotiationVersion.fromByte(byteBuf.readByte());
|
||||
if (version != SocksSubnegotiationVersion.AUTH_PASSWORD) {
|
||||
break;
|
||||
}
|
||||
checkpoint(State.READ_AUTH_RESPONSE);
|
||||
}
|
||||
case READ_AUTH_RESPONSE: {
|
||||
authStatus = SocksMessage.AuthStatus.fromByte(byteBuf.readByte());
|
||||
authStatus = SocksAuthStatus.fromByte(byteBuf.readByte());
|
||||
msg = new SocksAuthResponse(authStatus);
|
||||
}
|
||||
}
|
||||
|
@ -57,7 +57,7 @@ public class SocksAuthResponseDecoder extends ReplayingDecoder<SocksAuthResponse
|
|||
return msg;
|
||||
}
|
||||
|
||||
public enum State {
|
||||
enum State {
|
||||
CHECK_PROTOCOL_VERSION,
|
||||
READ_AUTH_RESPONSE
|
||||
}
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
/*
|
||||
* Copyright 2013 The Netty Project
|
||||
*
|
||||
* The Netty Project licenses this file to you under the Apache License,
|
||||
* version 2.0 (the "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at:
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package io.netty.handler.codec.socks;
|
||||
|
||||
public enum SocksAuthScheme {
|
||||
NO_AUTH((byte) 0x00),
|
||||
AUTH_GSSAPI((byte) 0x01),
|
||||
AUTH_PASSWORD((byte) 0x02),
|
||||
UNKNOWN((byte) 0xff);
|
||||
|
||||
private final byte b;
|
||||
|
||||
SocksAuthScheme(byte b) {
|
||||
this.b = b;
|
||||
}
|
||||
|
||||
public static SocksAuthScheme fromByte(byte b) {
|
||||
for (SocksAuthScheme code : values()) {
|
||||
if (code.b == b) {
|
||||
return code;
|
||||
}
|
||||
}
|
||||
return UNKNOWN;
|
||||
}
|
||||
|
||||
public byte byteValue() {
|
||||
return b;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,42 @@
|
|||
/*
|
||||
* Copyright 2013 The Netty Project
|
||||
*
|
||||
* The Netty Project licenses this file to you under the Apache License,
|
||||
* version 2.0 (the "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at:
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package io.netty.handler.codec.socks;
|
||||
|
||||
public enum SocksAuthStatus {
|
||||
SUCCESS((byte) 0x00),
|
||||
FAILURE((byte) 0xff);
|
||||
|
||||
private final byte b;
|
||||
|
||||
SocksAuthStatus(byte b) {
|
||||
this.b = b;
|
||||
}
|
||||
|
||||
public static SocksAuthStatus fromByte(byte b) {
|
||||
for (SocksAuthStatus code : values()) {
|
||||
if (code.b == b) {
|
||||
return code;
|
||||
}
|
||||
}
|
||||
return FAILURE;
|
||||
}
|
||||
|
||||
public byte byteValue() {
|
||||
return b;
|
||||
}
|
||||
}
|
||||
|
|
@ -28,12 +28,12 @@ import java.net.IDN;
|
|||
* @see SocksCmdRequestDecoder
|
||||
*/
|
||||
public final class SocksCmdRequest extends SocksRequest {
|
||||
private final CmdType cmdType;
|
||||
private final AddressType addressType;
|
||||
private final SocksCmdType cmdType;
|
||||
private final SocksAddressType addressType;
|
||||
private final String host;
|
||||
private final int port;
|
||||
|
||||
public SocksCmdRequest(CmdType cmdType, AddressType addressType, String host, int port) {
|
||||
public SocksCmdRequest(SocksCmdType cmdType, SocksAddressType addressType, String host, int port) {
|
||||
super(SocksRequestType.CMD);
|
||||
if (cmdType == null) {
|
||||
throw new NullPointerException("cmdType");
|
||||
|
@ -73,36 +73,36 @@ public final class SocksCmdRequest extends SocksRequest {
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns the {@link CmdType} of this {@link SocksCmdRequest}
|
||||
* Returns the {@link SocksCmdType} of this {@link SocksCmdRequest}
|
||||
*
|
||||
* @return The {@link CmdType} of this {@link SocksCmdRequest}
|
||||
* @return The {@link SocksCmdType} of this {@link SocksCmdRequest}
|
||||
*/
|
||||
public CmdType cmdType() {
|
||||
public SocksCmdType cmdType() {
|
||||
return cmdType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the {@link AddressType} of this {@link SocksCmdRequest}
|
||||
* Returns the {@link SocksAddressType} of this {@link SocksCmdRequest}
|
||||
*
|
||||
* @return The {@link AddressType} of this {@link SocksCmdRequest}
|
||||
* @return The {@link SocksAddressType} of this {@link SocksCmdRequest}
|
||||
*/
|
||||
public AddressType addressType() {
|
||||
public SocksAddressType addressType() {
|
||||
return addressType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns host that is used as a parameter in {@link CmdType}
|
||||
* Returns host that is used as a parameter in {@link SocksCmdType}
|
||||
*
|
||||
* @return host that is used as a parameter in {@link CmdType}
|
||||
* @return host that is used as a parameter in {@link SocksCmdType}
|
||||
*/
|
||||
public String host() {
|
||||
return IDN.toUnicode(host);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns port that is used as a parameter in {@link CmdType}
|
||||
* Returns port that is used as a parameter in {@link SocksCmdType}
|
||||
*
|
||||
* @return port that is used as a parameter in {@link CmdType}
|
||||
* @return port that is used as a parameter in {@link SocksCmdType}
|
||||
*/
|
||||
public int port() {
|
||||
return port;
|
||||
|
@ -110,10 +110,10 @@ public final class SocksCmdRequest extends SocksRequest {
|
|||
|
||||
@Override
|
||||
public void encodeAsByteBuf(ByteBuf byteBuf) {
|
||||
byteBuf.writeByte(protocolVersion().getByteValue());
|
||||
byteBuf.writeByte(cmdType.getByteValue());
|
||||
byteBuf.writeByte(protocolVersion().byteValue());
|
||||
byteBuf.writeByte(cmdType.byteValue());
|
||||
byteBuf.writeByte(0x00);
|
||||
byteBuf.writeByte(addressType.getByteValue());
|
||||
byteBuf.writeByte(addressType.byteValue());
|
||||
switch (addressType) {
|
||||
case IPv4: {
|
||||
byteBuf.writeBytes(NetUtil.createByteArrayFromIpAddressString(host));
|
||||
|
|
|
@ -31,10 +31,10 @@ public class SocksCmdRequestDecoder extends ReplayingDecoder<SocksCmdRequestDeco
|
|||
return name;
|
||||
}
|
||||
|
||||
private SocksMessage.ProtocolVersion version;
|
||||
private SocksProtocolVersion version;
|
||||
private int fieldLength;
|
||||
private SocksMessage.CmdType cmdType;
|
||||
private SocksMessage.AddressType addressType;
|
||||
private SocksCmdType cmdType;
|
||||
private SocksAddressType addressType;
|
||||
private byte reserved;
|
||||
private String host;
|
||||
private int port;
|
||||
|
@ -48,16 +48,16 @@ public class SocksCmdRequestDecoder extends ReplayingDecoder<SocksCmdRequestDeco
|
|||
protected Object decode(ChannelHandlerContext ctx, ByteBuf byteBuf) throws Exception {
|
||||
switch (state()) {
|
||||
case CHECK_PROTOCOL_VERSION: {
|
||||
version = SocksMessage.ProtocolVersion.fromByte(byteBuf.readByte());
|
||||
if (version != SocksMessage.ProtocolVersion.SOCKS5) {
|
||||
version = SocksProtocolVersion.fromByte(byteBuf.readByte());
|
||||
if (version != SocksProtocolVersion.SOCKS5) {
|
||||
break;
|
||||
}
|
||||
checkpoint(State.READ_CMD_HEADER);
|
||||
}
|
||||
case READ_CMD_HEADER: {
|
||||
cmdType = SocksMessage.CmdType.fromByte(byteBuf.readByte());
|
||||
cmdType = SocksCmdType.fromByte(byteBuf.readByte());
|
||||
reserved = byteBuf.readByte();
|
||||
addressType = SocksMessage.AddressType.fromByte(byteBuf.readByte());
|
||||
addressType = SocksAddressType.fromByte(byteBuf.readByte());
|
||||
checkpoint(State.READ_CMD_ADDRESS);
|
||||
}
|
||||
case READ_CMD_ADDRESS: {
|
||||
|
|
|
@ -24,9 +24,9 @@ import io.netty.buffer.ByteBuf;
|
|||
* @see SocksCmdResponseDecoder
|
||||
*/
|
||||
public final class SocksCmdResponse extends SocksResponse {
|
||||
private final CmdStatus cmdStatus;
|
||||
private final SocksCmdStatus cmdStatus;
|
||||
|
||||
private final AddressType addressType;
|
||||
private final SocksAddressType addressType;
|
||||
// All arrays are initialized on construction time to 0/false/null remove array Initialization
|
||||
private static final byte[] IPv4_HOSTNAME_ZEROED = {0x00, 0x00, 0x00, 0x00};
|
||||
private static final byte[] IPv6_HOSTNAME_ZEROED = {0x00, 0x00, 0x00, 0x00,
|
||||
|
@ -34,7 +34,7 @@ public final class SocksCmdResponse extends SocksResponse {
|
|||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00};
|
||||
|
||||
public SocksCmdResponse(CmdStatus cmdStatus, AddressType addressType) {
|
||||
public SocksCmdResponse(SocksCmdStatus cmdStatus, SocksAddressType addressType) {
|
||||
super(SocksResponseType.CMD);
|
||||
if (cmdStatus == null) {
|
||||
throw new NullPointerException("cmdStatus");
|
||||
|
@ -47,29 +47,29 @@ public final class SocksCmdResponse extends SocksResponse {
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns the {@link CmdStatus} of this {@link SocksCmdResponse}
|
||||
* Returns the {@link SocksCmdStatus} of this {@link SocksCmdResponse}
|
||||
*
|
||||
* @return The {@link CmdStatus} of this {@link SocksCmdResponse}
|
||||
* @return The {@link SocksCmdStatus} of this {@link SocksCmdResponse}
|
||||
*/
|
||||
public CmdStatus cmdStatus() {
|
||||
public SocksCmdStatus cmdStatus() {
|
||||
return cmdStatus;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the {@link AddressType} of this {@link SocksCmdResponse}
|
||||
* Returns the {@link SocksAddressType} of this {@link SocksCmdResponse}
|
||||
*
|
||||
* @return The {@link AddressType} of this {@link SocksCmdResponse}
|
||||
* @return The {@link SocksAddressType} of this {@link SocksCmdResponse}
|
||||
*/
|
||||
public AddressType addressType() {
|
||||
public SocksAddressType addressType() {
|
||||
return addressType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void encodeAsByteBuf(ByteBuf byteBuf) {
|
||||
byteBuf.writeByte(protocolVersion().getByteValue());
|
||||
byteBuf.writeByte(cmdStatus.getByteValue());
|
||||
byteBuf.writeByte(protocolVersion().byteValue());
|
||||
byteBuf.writeByte(cmdStatus.byteValue());
|
||||
byteBuf.writeByte(0x00);
|
||||
byteBuf.writeByte(addressType.getByteValue());
|
||||
byteBuf.writeByte(addressType.byteValue());
|
||||
switch (addressType) {
|
||||
case IPv4: {
|
||||
byteBuf.writeBytes(IPv4_HOSTNAME_ZEROED);
|
||||
|
|
|
@ -31,10 +31,10 @@ public class SocksCmdResponseDecoder extends ReplayingDecoder<SocksCmdResponseDe
|
|||
return name;
|
||||
}
|
||||
|
||||
private SocksMessage.ProtocolVersion version;
|
||||
private SocksProtocolVersion version;
|
||||
private int fieldLength;
|
||||
private SocksMessage.CmdStatus cmdStatus;
|
||||
private SocksMessage.AddressType addressType;
|
||||
private SocksCmdStatus cmdStatus;
|
||||
private SocksAddressType addressType;
|
||||
private byte reserved;
|
||||
private String host;
|
||||
private int port;
|
||||
|
@ -48,16 +48,16 @@ public class SocksCmdResponseDecoder extends ReplayingDecoder<SocksCmdResponseDe
|
|||
protected Object decode(ChannelHandlerContext ctx, ByteBuf byteBuf) throws Exception {
|
||||
switch (state()) {
|
||||
case CHECK_PROTOCOL_VERSION: {
|
||||
version = SocksMessage.ProtocolVersion.fromByte(byteBuf.readByte());
|
||||
if (version != SocksMessage.ProtocolVersion.SOCKS5) {
|
||||
version = SocksProtocolVersion.fromByte(byteBuf.readByte());
|
||||
if (version != SocksProtocolVersion.SOCKS5) {
|
||||
break;
|
||||
}
|
||||
checkpoint(State.READ_CMD_HEADER);
|
||||
}
|
||||
case READ_CMD_HEADER: {
|
||||
cmdStatus = SocksMessage.CmdStatus.fromByte(byteBuf.readByte());
|
||||
cmdStatus = SocksCmdStatus.fromByte(byteBuf.readByte());
|
||||
reserved = byteBuf.readByte();
|
||||
addressType = SocksMessage.AddressType.fromByte(byteBuf.readByte());
|
||||
addressType = SocksAddressType.fromByte(byteBuf.readByte());
|
||||
checkpoint(State.READ_CMD_ADDRESS);
|
||||
}
|
||||
case READ_CMD_ADDRESS: {
|
||||
|
@ -90,7 +90,7 @@ public class SocksCmdResponseDecoder extends ReplayingDecoder<SocksCmdResponseDe
|
|||
return msg;
|
||||
}
|
||||
|
||||
public enum State {
|
||||
enum State {
|
||||
CHECK_PROTOCOL_VERSION,
|
||||
READ_CMD_HEADER,
|
||||
READ_CMD_ADDRESS
|
||||
|
|
|
@ -0,0 +1,49 @@
|
|||
/*
|
||||
* Copyright 2013 The Netty Project
|
||||
*
|
||||
* The Netty Project licenses this file to you under the Apache License,
|
||||
* version 2.0 (the "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at:
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package io.netty.handler.codec.socks;
|
||||
|
||||
public enum SocksCmdStatus {
|
||||
SUCCESS((byte) 0x00),
|
||||
FAILURE((byte) 0x01),
|
||||
FORBIDDEN((byte) 0x02),
|
||||
NETWORK_UNREACHABLE((byte) 0x03),
|
||||
HOST_UNREACHABLE((byte) 0x04),
|
||||
REFUSED((byte) 0x05),
|
||||
TTL_EXPIRED((byte) 0x06),
|
||||
COMMAND_NOT_SUPPORTED((byte) 0x07),
|
||||
ADDRESS_NOT_SUPPORTED((byte) 0x08),
|
||||
UNASSIGNED((byte) 0xff);
|
||||
|
||||
private final byte b;
|
||||
|
||||
SocksCmdStatus(byte b) {
|
||||
this.b = b;
|
||||
}
|
||||
|
||||
public static SocksCmdStatus fromByte(byte b) {
|
||||
for (SocksCmdStatus code : values()) {
|
||||
if (code.b == b) {
|
||||
return code;
|
||||
}
|
||||
}
|
||||
return UNASSIGNED;
|
||||
}
|
||||
|
||||
public byte byteValue() {
|
||||
return b;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
/*
|
||||
* Copyright 2013 The Netty Project
|
||||
*
|
||||
* The Netty Project licenses this file to you under the Apache License,
|
||||
* version 2.0 (the "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at:
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package io.netty.handler.codec.socks;
|
||||
|
||||
public enum SocksCmdType {
|
||||
CONNECT((byte) 0x01),
|
||||
BIND((byte) 0x02),
|
||||
UDP((byte) 0x03),
|
||||
UNKNOWN((byte) 0xff);
|
||||
|
||||
private final byte b;
|
||||
|
||||
SocksCmdType(byte b) {
|
||||
this.b = b;
|
||||
}
|
||||
|
||||
public static SocksCmdType fromByte(byte b) {
|
||||
for (SocksCmdType code : values()) {
|
||||
if (code.b == b) {
|
||||
return code;
|
||||
}
|
||||
}
|
||||
return UNKNOWN;
|
||||
}
|
||||
|
||||
public byte byteValue() {
|
||||
return b;
|
||||
}
|
||||
}
|
||||
|
|
@ -27,9 +27,9 @@ import java.util.List;
|
|||
* @see SocksInitRequestDecoder
|
||||
*/
|
||||
public final class SocksInitRequest extends SocksRequest {
|
||||
private final List<AuthScheme> authSchemes;
|
||||
private final List<SocksAuthScheme> authSchemes;
|
||||
|
||||
public SocksInitRequest(List<AuthScheme> authSchemes) {
|
||||
public SocksInitRequest(List<SocksAuthScheme> authSchemes) {
|
||||
super(SocksRequestType.INIT);
|
||||
if (authSchemes == null) {
|
||||
throw new NullPointerException("authSchemes");
|
||||
|
@ -38,20 +38,20 @@ public final class SocksInitRequest extends SocksRequest {
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns the List<{@link AuthScheme}> of this {@link SocksInitRequest}
|
||||
* Returns the List<{@link SocksAuthScheme}> of this {@link SocksInitRequest}
|
||||
*
|
||||
* @return The List<{@link AuthScheme}> of this {@link SocksInitRequest}
|
||||
* @return The List<{@link SocksAuthScheme}> of this {@link SocksInitRequest}
|
||||
*/
|
||||
public List<AuthScheme> authSchemes() {
|
||||
public List<SocksAuthScheme> authSchemes() {
|
||||
return Collections.unmodifiableList(authSchemes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void encodeAsByteBuf(ByteBuf byteBuf) {
|
||||
byteBuf.writeByte(protocolVersion().getByteValue());
|
||||
byteBuf.writeByte(protocolVersion().byteValue());
|
||||
byteBuf.writeByte(authSchemes.size());
|
||||
for (AuthScheme authScheme : authSchemes) {
|
||||
byteBuf.writeByte(authScheme.getByteValue());
|
||||
for (SocksAuthScheme authScheme : authSchemes) {
|
||||
byteBuf.writeByte(authScheme.byteValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,8 +33,8 @@ public class SocksInitRequestDecoder extends ReplayingDecoder<SocksInitRequestDe
|
|||
return name;
|
||||
}
|
||||
|
||||
private final List<SocksMessage.AuthScheme> authSchemes = new ArrayList<SocksMessage.AuthScheme>();
|
||||
private SocksMessage.ProtocolVersion version;
|
||||
private final List<SocksAuthScheme> authSchemes = new ArrayList<SocksAuthScheme>();
|
||||
private SocksProtocolVersion version;
|
||||
private byte authSchemeNum;
|
||||
private SocksRequest msg = SocksCommonUtils.UNKNOWN_SOCKS_REQUEST;
|
||||
|
||||
|
@ -46,8 +46,8 @@ public class SocksInitRequestDecoder extends ReplayingDecoder<SocksInitRequestDe
|
|||
protected Object decode(ChannelHandlerContext ctx, ByteBuf byteBuf) throws Exception {
|
||||
switch (state()) {
|
||||
case CHECK_PROTOCOL_VERSION: {
|
||||
version = SocksMessage.ProtocolVersion.fromByte(byteBuf.readByte());
|
||||
if (version != SocksMessage.ProtocolVersion.SOCKS5) {
|
||||
version = SocksProtocolVersion.fromByte(byteBuf.readByte());
|
||||
if (version != SocksProtocolVersion.SOCKS5) {
|
||||
break;
|
||||
}
|
||||
checkpoint(State.READ_AUTH_SCHEMES);
|
||||
|
@ -56,7 +56,7 @@ public class SocksInitRequestDecoder extends ReplayingDecoder<SocksInitRequestDe
|
|||
authSchemes.clear();
|
||||
authSchemeNum = byteBuf.readByte();
|
||||
for (int i = 0; i < authSchemeNum; i++) {
|
||||
authSchemes.add(SocksMessage.AuthScheme.fromByte(byteBuf.readByte()));
|
||||
authSchemes.add(SocksAuthScheme.fromByte(byteBuf.readByte()));
|
||||
}
|
||||
msg = new SocksInitRequest(authSchemes);
|
||||
break;
|
||||
|
|
|
@ -24,9 +24,9 @@ import io.netty.buffer.ByteBuf;
|
|||
* @see SocksInitResponseDecoder
|
||||
*/
|
||||
public final class SocksInitResponse extends SocksResponse {
|
||||
private final AuthScheme authScheme;
|
||||
private final SocksAuthScheme authScheme;
|
||||
|
||||
public SocksInitResponse(AuthScheme authScheme) {
|
||||
public SocksInitResponse(SocksAuthScheme authScheme) {
|
||||
super(SocksResponseType.INIT);
|
||||
if (authScheme == null) {
|
||||
throw new NullPointerException("authScheme");
|
||||
|
@ -35,17 +35,17 @@ public final class SocksInitResponse extends SocksResponse {
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns the {@link AuthScheme} of this {@link SocksInitResponse}
|
||||
* Returns the {@link SocksAuthScheme} of this {@link SocksInitResponse}
|
||||
*
|
||||
* @return The {@link AuthScheme} of this {@link SocksInitResponse}
|
||||
* @return The {@link SocksAuthScheme} of this {@link SocksInitResponse}
|
||||
*/
|
||||
public AuthScheme authScheme() {
|
||||
public SocksAuthScheme authScheme() {
|
||||
return authScheme;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void encodeAsByteBuf(ByteBuf byteBuf) {
|
||||
byteBuf.writeByte(protocolVersion().getByteValue());
|
||||
byteBuf.writeByte(authScheme.getByteValue());
|
||||
byteBuf.writeByte(protocolVersion().byteValue());
|
||||
byteBuf.writeByte(authScheme.byteValue());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,8 +30,8 @@ public class SocksInitResponseDecoder extends ReplayingDecoder<SocksInitResponse
|
|||
return name;
|
||||
}
|
||||
|
||||
private SocksMessage.ProtocolVersion version;
|
||||
private SocksMessage.AuthScheme authScheme;
|
||||
private SocksProtocolVersion version;
|
||||
private SocksAuthScheme authScheme;
|
||||
|
||||
private SocksResponse msg = SocksCommonUtils.UNKNOWN_SOCKS_RESPONSE;
|
||||
|
||||
|
@ -43,14 +43,14 @@ public class SocksInitResponseDecoder extends ReplayingDecoder<SocksInitResponse
|
|||
protected SocksResponse decode(ChannelHandlerContext ctx, ByteBuf byteBuf) throws Exception {
|
||||
switch (state()) {
|
||||
case CHECK_PROTOCOL_VERSION: {
|
||||
version = SocksMessage.ProtocolVersion.fromByte(byteBuf.readByte());
|
||||
if (version != SocksMessage.ProtocolVersion.SOCKS5) {
|
||||
version = SocksProtocolVersion.fromByte(byteBuf.readByte());
|
||||
if (version != SocksProtocolVersion.SOCKS5) {
|
||||
break;
|
||||
}
|
||||
checkpoint(State.READ_PREFFERED_AUTH_TYPE);
|
||||
}
|
||||
case READ_PREFFERED_AUTH_TYPE: {
|
||||
authScheme = SocksMessage.AuthScheme.fromByte(byteBuf.readByte());
|
||||
authScheme = SocksAuthScheme.fromByte(byteBuf.readByte());
|
||||
msg = new SocksInitResponse(authScheme);
|
||||
break;
|
||||
}
|
||||
|
@ -59,7 +59,7 @@ public class SocksInitResponseDecoder extends ReplayingDecoder<SocksInitResponse
|
|||
return msg;
|
||||
}
|
||||
|
||||
public enum State {
|
||||
enum State {
|
||||
CHECK_PROTOCOL_VERSION,
|
||||
READ_PREFFERED_AUTH_TYPE
|
||||
}
|
||||
|
|
|
@ -26,10 +26,10 @@ import io.netty.buffer.ByteBuf;
|
|||
*/
|
||||
|
||||
public abstract class SocksMessage {
|
||||
private final MessageType type;
|
||||
private final ProtocolVersion protocolVersion = ProtocolVersion.SOCKS5;
|
||||
private final SocksMessageType type;
|
||||
private final SocksProtocolVersion protocolVersion = SocksProtocolVersion.SOCKS5;
|
||||
|
||||
protected SocksMessage(MessageType type) {
|
||||
protected SocksMessage(SocksMessageType type) {
|
||||
if (type == null) {
|
||||
throw new NullPointerException("type");
|
||||
}
|
||||
|
@ -37,209 +37,20 @@ public abstract class SocksMessage {
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns the {@link MessageType} of this {@link SocksMessage}
|
||||
* Returns the {@link SocksMessageType} of this {@link SocksMessage}
|
||||
*
|
||||
* @return The {@link MessageType} of this {@link SocksMessage}
|
||||
* @return The {@link SocksMessageType} of this {@link SocksMessage}
|
||||
*/
|
||||
public MessageType type() {
|
||||
public SocksMessageType type() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public enum MessageType {
|
||||
REQUEST,
|
||||
RESPONSE,
|
||||
UNKNOWN
|
||||
}
|
||||
|
||||
public enum AuthScheme {
|
||||
NO_AUTH((byte) 0x00),
|
||||
AUTH_GSSAPI((byte) 0x01),
|
||||
AUTH_PASSWORD((byte) 0x02),
|
||||
UNKNOWN((byte) 0xff);
|
||||
|
||||
private final byte b;
|
||||
|
||||
AuthScheme(byte b) {
|
||||
this.b = b;
|
||||
}
|
||||
|
||||
public static AuthScheme fromByte(byte b) {
|
||||
for (AuthScheme code : values()) {
|
||||
if (code.b == b) {
|
||||
return code;
|
||||
}
|
||||
}
|
||||
return UNKNOWN;
|
||||
}
|
||||
|
||||
public byte getByteValue() {
|
||||
return b;
|
||||
}
|
||||
}
|
||||
|
||||
public enum CmdType {
|
||||
CONNECT((byte) 0x01),
|
||||
BIND((byte) 0x02),
|
||||
UDP((byte) 0x03),
|
||||
UNKNOWN((byte) 0xff);
|
||||
|
||||
private final byte b;
|
||||
|
||||
CmdType(byte b) {
|
||||
this.b = b;
|
||||
}
|
||||
|
||||
public static CmdType fromByte(byte b) {
|
||||
for (CmdType code : values()) {
|
||||
if (code.b == b) {
|
||||
return code;
|
||||
}
|
||||
}
|
||||
return UNKNOWN;
|
||||
}
|
||||
|
||||
public byte getByteValue() {
|
||||
return b;
|
||||
}
|
||||
}
|
||||
|
||||
public enum AddressType {
|
||||
IPv4((byte) 0x01),
|
||||
DOMAIN((byte) 0x03),
|
||||
IPv6((byte) 0x04),
|
||||
UNKNOWN((byte) 0xff);
|
||||
|
||||
private final byte b;
|
||||
|
||||
AddressType(byte b) {
|
||||
this.b = b;
|
||||
}
|
||||
|
||||
public static AddressType fromByte(byte b) {
|
||||
for (AddressType code : values()) {
|
||||
if (code.b == b) {
|
||||
return code;
|
||||
}
|
||||
}
|
||||
return UNKNOWN;
|
||||
}
|
||||
|
||||
public byte getByteValue() {
|
||||
return b;
|
||||
}
|
||||
}
|
||||
|
||||
public enum AuthStatus {
|
||||
SUCCESS((byte) 0x00),
|
||||
FAILURE((byte) 0xff);
|
||||
|
||||
private final byte b;
|
||||
|
||||
AuthStatus(byte b) {
|
||||
this.b = b;
|
||||
}
|
||||
|
||||
public static AuthStatus fromByte(byte b) {
|
||||
for (AuthStatus code : values()) {
|
||||
if (code.b == b) {
|
||||
return code;
|
||||
}
|
||||
}
|
||||
return FAILURE;
|
||||
}
|
||||
|
||||
public byte getByteValue() {
|
||||
return b;
|
||||
}
|
||||
}
|
||||
|
||||
public enum CmdStatus {
|
||||
SUCCESS((byte) 0x00),
|
||||
FAILURE((byte) 0x01),
|
||||
FORBIDDEN((byte) 0x02),
|
||||
NETWORK_UNREACHABLE((byte) 0x03),
|
||||
HOST_UNREACHABLE((byte) 0x04),
|
||||
REFUSED((byte) 0x05),
|
||||
TTL_EXPIRED((byte) 0x06),
|
||||
COMMAND_NOT_SUPPORTED((byte) 0x07),
|
||||
ADDRESS_NOT_SUPPORTED((byte) 0x08),
|
||||
UNASSIGNED((byte) 0xff);
|
||||
|
||||
private final byte b;
|
||||
|
||||
CmdStatus(byte b) {
|
||||
this.b = b;
|
||||
}
|
||||
|
||||
public static CmdStatus fromByte(byte b) {
|
||||
for (CmdStatus code : values()) {
|
||||
if (code.b == b) {
|
||||
return code;
|
||||
}
|
||||
}
|
||||
return UNASSIGNED;
|
||||
}
|
||||
|
||||
public byte getByteValue() {
|
||||
return b;
|
||||
}
|
||||
}
|
||||
|
||||
public enum ProtocolVersion {
|
||||
SOCKS4a((byte) 0x04),
|
||||
SOCKS5((byte) 0x05),
|
||||
UNKNOWN((byte) 0xff);
|
||||
|
||||
private final byte b;
|
||||
|
||||
ProtocolVersion(byte b) {
|
||||
this.b = b;
|
||||
}
|
||||
|
||||
public static ProtocolVersion fromByte(byte b) {
|
||||
for (ProtocolVersion code : values()) {
|
||||
if (code.b == b) {
|
||||
return code;
|
||||
}
|
||||
}
|
||||
return UNKNOWN;
|
||||
}
|
||||
|
||||
public byte getByteValue() {
|
||||
return b;
|
||||
}
|
||||
}
|
||||
|
||||
public enum SubnegotiationVersion {
|
||||
AUTH_PASSWORD((byte) 0x01),
|
||||
UNKNOWN((byte) 0xff);
|
||||
|
||||
private final byte b;
|
||||
|
||||
SubnegotiationVersion(byte b) {
|
||||
this.b = b;
|
||||
}
|
||||
|
||||
public static SubnegotiationVersion fromByte(byte b) {
|
||||
for (SubnegotiationVersion code : values()) {
|
||||
if (code.b == b) {
|
||||
return code;
|
||||
}
|
||||
}
|
||||
return UNKNOWN;
|
||||
}
|
||||
|
||||
public byte getByteValue() {
|
||||
return b;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the {@link ProtocolVersion} of this {@link SocksMessage}
|
||||
* Returns the {@link SocksProtocolVersion} of this {@link SocksMessage}
|
||||
*
|
||||
* @return The {@link ProtocolVersion} of this {@link SocksMessage}
|
||||
* @return The {@link SocksProtocolVersion} of this {@link SocksMessage}
|
||||
*/
|
||||
public ProtocolVersion protocolVersion() {
|
||||
public SocksProtocolVersion protocolVersion() {
|
||||
return protocolVersion;
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
/*
|
||||
* Copyright 2013 The Netty Project
|
||||
*
|
||||
* The Netty Project licenses this file to you under the Apache License,
|
||||
* version 2.0 (the "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at:
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package io.netty.handler.codec.socks;
|
||||
|
||||
public enum SocksMessageType {
|
||||
REQUEST,
|
||||
RESPONSE,
|
||||
UNKNOWN
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
/*
|
||||
* Copyright 2013 The Netty Project
|
||||
*
|
||||
* The Netty Project licenses this file to you under the Apache License,
|
||||
* version 2.0 (the "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at:
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package io.netty.handler.codec.socks;
|
||||
|
||||
public enum SocksProtocolVersion {
|
||||
SOCKS4a((byte) 0x04),
|
||||
SOCKS5((byte) 0x05),
|
||||
UNKNOWN((byte) 0xff);
|
||||
|
||||
private final byte b;
|
||||
|
||||
SocksProtocolVersion(byte b) {
|
||||
this.b = b;
|
||||
}
|
||||
|
||||
public static SocksProtocolVersion fromByte(byte b) {
|
||||
for (SocksProtocolVersion code : values()) {
|
||||
if (code.b == b) {
|
||||
return code;
|
||||
}
|
||||
}
|
||||
return UNKNOWN;
|
||||
}
|
||||
|
||||
public byte byteValue() {
|
||||
return b;
|
||||
}
|
||||
}
|
|
@ -28,7 +28,7 @@ public abstract class SocksRequest extends SocksMessage {
|
|||
private final SocksRequestType requestType;
|
||||
|
||||
protected SocksRequest(SocksRequestType requestType) {
|
||||
super(MessageType.REQUEST);
|
||||
super(SocksMessageType.REQUEST);
|
||||
if (requestType == null) {
|
||||
throw new NullPointerException("requestType");
|
||||
}
|
||||
|
@ -43,14 +43,4 @@ public abstract class SocksRequest extends SocksMessage {
|
|||
public SocksRequestType requestType() {
|
||||
return requestType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Type of socks request
|
||||
*/
|
||||
public enum SocksRequestType {
|
||||
INIT,
|
||||
AUTH,
|
||||
CMD,
|
||||
UNKNOWN
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2012 The Netty Project
|
||||
* Copyright 2013 The Netty Project
|
||||
*
|
||||
* The Netty Project licenses this file to you under the Apache License,
|
||||
* version 2.0 (the "License"); you may not use this file except in compliance
|
||||
|
@ -14,10 +14,14 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
package io.netty.handler.codec.socks;
|
||||
|
||||
/**
|
||||
* Simplistic <em>internal-use-only</em> logging layer which allows a user to
|
||||
* decide what logging framework Netty should use.
|
||||
*
|
||||
* @apiviz.hidden
|
||||
* Type of socks request
|
||||
*/
|
||||
package io.netty.logging;
|
||||
public enum SocksRequestType {
|
||||
INIT,
|
||||
AUTH,
|
||||
CMD,
|
||||
UNKNOWN
|
||||
}
|
|
@ -28,7 +28,7 @@ public abstract class SocksResponse extends SocksMessage {
|
|||
private final SocksResponseType responseType;
|
||||
|
||||
protected SocksResponse(SocksResponseType responseType) {
|
||||
super(MessageType.RESPONSE);
|
||||
super(SocksMessageType.RESPONSE);
|
||||
if (responseType == null) {
|
||||
throw new NullPointerException("responseType");
|
||||
}
|
||||
|
@ -43,14 +43,4 @@ public abstract class SocksResponse extends SocksMessage {
|
|||
public SocksResponseType responseType() {
|
||||
return responseType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Type of socks response
|
||||
*/
|
||||
public enum SocksResponseType {
|
||||
INIT,
|
||||
AUTH,
|
||||
CMD,
|
||||
UNKNOWN
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2012 The Netty Project
|
||||
* Copyright 2013 The Netty Project
|
||||
*
|
||||
* The Netty Project licenses this file to you under the Apache License,
|
||||
* version 2.0 (the "License"); you may not use this file except in compliance
|
||||
|
@ -13,24 +13,15 @@
|
|||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package io.netty.handler.codec.socks;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
/**
|
||||
* An unknown socks message.
|
||||
*
|
||||
* @see UnknownSocksRequest
|
||||
* @see UnknownSocksResponse
|
||||
* Type of socks response
|
||||
*/
|
||||
public final class UnknownSocksMessage extends SocksMessage {
|
||||
|
||||
public UnknownSocksMessage() {
|
||||
super(MessageType.UNKNOWN);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void encodeAsByteBuf(ByteBuf byteBuf) {
|
||||
// NOOP
|
||||
}
|
||||
public enum SocksResponseType {
|
||||
INIT,
|
||||
AUTH,
|
||||
CMD,
|
||||
UNKNOWN
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
/*
|
||||
* Copyright 2013 The Netty Project
|
||||
*
|
||||
* The Netty Project licenses this file to you under the Apache License,
|
||||
* version 2.0 (the "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at:
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package io.netty.handler.codec.socks;
|
||||
|
||||
public enum SocksSubnegotiationVersion {
|
||||
AUTH_PASSWORD((byte) 0x01),
|
||||
UNKNOWN((byte) 0xff);
|
||||
|
||||
private final byte b;
|
||||
|
||||
SocksSubnegotiationVersion(byte b) {
|
||||
this.b = b;
|
||||
}
|
||||
|
||||
public static SocksSubnegotiationVersion fromByte(byte b) {
|
||||
for (SocksSubnegotiationVersion code : values()) {
|
||||
if (code.b == b) {
|
||||
return code;
|
||||
}
|
||||
}
|
||||
return UNKNOWN;
|
||||
}
|
||||
|
||||
public byte byteValue() {
|
||||
return b;
|
||||
}
|
||||
}
|
||||
|
|
@ -16,5 +16,8 @@
|
|||
|
||||
/**
|
||||
* Encoder, decoder and their related message types for Socks.
|
||||
*
|
||||
* @apiviz.exclude \.Socks.*(Type|Version|Status|Scheme)$
|
||||
*/
|
||||
package io.netty.handler.codec.socks;
|
||||
// TODO: Combine decoders into one.
|
||||
|
|
|
@ -24,7 +24,7 @@ import static org.junit.Assert.*;
|
|||
|
||||
public class SocksAuthResponseDecoderTest {
|
||||
private static final Logger logger = LoggerFactory.getLogger(SocksAuthResponseDecoderTest.class);
|
||||
private static void testSocksAuthResponseDecoderWithDifferentParams(SocksMessage.AuthStatus authStatus){
|
||||
private static void testSocksAuthResponseDecoderWithDifferentParams(SocksAuthStatus authStatus){
|
||||
logger.debug("Testing SocksAuthResponseDecoder with authStatus: "+ authStatus);
|
||||
SocksAuthResponse msg = new SocksAuthResponse(authStatus);
|
||||
SocksAuthResponseDecoder decoder = new SocksAuthResponseDecoder();
|
||||
|
@ -37,7 +37,7 @@ public class SocksAuthResponseDecoderTest {
|
|||
|
||||
@Test
|
||||
public void testSocksCmdResponseDecoder(){
|
||||
for (SocksMessage.AuthStatus authStatus: SocksMessage.AuthStatus.values()){
|
||||
for (SocksAuthStatus authStatus: SocksAuthStatus.values()){
|
||||
testSocksAuthResponseDecoderWithDifferentParams(authStatus);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,13 +26,13 @@ import static org.junit.Assert.*;
|
|||
public class SocksCmdRequestDecoderTest {
|
||||
private static final Logger logger = LoggerFactory.getLogger(SocksCmdRequestDecoderTest.class);
|
||||
|
||||
private static void testSocksCmdRequestDecoderWithDifferentParams(SocksMessage.CmdType cmdType, SocksMessage.AddressType addressType, String host, int port) {
|
||||
private static void testSocksCmdRequestDecoderWithDifferentParams(SocksCmdType cmdType, SocksAddressType addressType, String host, int port) {
|
||||
logger.debug("Testing cmdType: " + cmdType + " addressType: " + addressType + " host: " + host + " port: " + port);
|
||||
SocksCmdRequest msg = new SocksCmdRequest(cmdType, addressType, host, port);
|
||||
SocksCmdRequestDecoder decoder = new SocksCmdRequestDecoder();
|
||||
EmbeddedByteChannel embedder = new EmbeddedByteChannel(decoder);
|
||||
SocksCommonTestUtils.writeMessageIntoEmbedder(embedder, msg);
|
||||
if (msg.addressType() == SocksMessage.AddressType.UNKNOWN) {
|
||||
if (msg.addressType() == SocksAddressType.UNKNOWN) {
|
||||
assertTrue(embedder.readInbound() instanceof UnknownSocksRequest);
|
||||
} else {
|
||||
msg = (SocksCmdRequest) embedder.readInbound();
|
||||
|
@ -48,10 +48,10 @@ public class SocksCmdRequestDecoderTest {
|
|||
public void testCmdRequestDecoderIPv4() {
|
||||
String[] hosts = {"127.0.0.1",};
|
||||
int[] ports = {0, 32769, 65535 };
|
||||
for (SocksMessage.CmdType cmdType : SocksMessage.CmdType.values()) {
|
||||
for (SocksCmdType cmdType : SocksCmdType.values()) {
|
||||
for (String host : hosts) {
|
||||
for (int port : ports) {
|
||||
testSocksCmdRequestDecoderWithDifferentParams(cmdType, SocksMessage.AddressType.IPv4, host, port);
|
||||
testSocksCmdRequestDecoderWithDifferentParams(cmdType, SocksAddressType.IPv4, host, port);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -61,10 +61,10 @@ public class SocksCmdRequestDecoderTest {
|
|||
public void testCmdRequestDecoderIPv6() {
|
||||
String[] hosts = {SocksCommonUtils.ipv6toStr(IPAddressUtil.textToNumericFormatV6("::1"))};
|
||||
int[] ports = {0, 32769, 65535};
|
||||
for (SocksMessage.CmdType cmdType : SocksMessage.CmdType.values()) {
|
||||
for (SocksCmdType cmdType : SocksCmdType.values()) {
|
||||
for (String host : hosts) {
|
||||
for (int port : ports) {
|
||||
testSocksCmdRequestDecoderWithDifferentParams(cmdType, SocksMessage.AddressType.IPv6, host, port);
|
||||
testSocksCmdRequestDecoderWithDifferentParams(cmdType, SocksAddressType.IPv6, host, port);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -85,10 +85,10 @@ public class SocksCmdRequestDecoderTest {
|
|||
"실례.테스트",
|
||||
"உதாரணம்.பரிட்சை"};
|
||||
int[] ports = {0, 32769, 65535};
|
||||
for (SocksMessage.CmdType cmdType : SocksMessage.CmdType.values()) {
|
||||
for (SocksCmdType cmdType : SocksCmdType.values()) {
|
||||
for (String host : hosts) {
|
||||
for (int port : ports) {
|
||||
testSocksCmdRequestDecoderWithDifferentParams(cmdType, SocksMessage.AddressType.DOMAIN, host, port);
|
||||
testSocksCmdRequestDecoderWithDifferentParams(cmdType, SocksAddressType.DOMAIN, host, port);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -98,8 +98,8 @@ public class SocksCmdRequestDecoderTest {
|
|||
public void testCmdRequestDecoderUnknown() {
|
||||
String host = "google.com";
|
||||
int port = 80;
|
||||
for (SocksMessage.CmdType cmdType : SocksMessage.CmdType.values()) {
|
||||
testSocksCmdRequestDecoderWithDifferentParams(cmdType, SocksMessage.AddressType.UNKNOWN, host, port);
|
||||
for (SocksCmdType cmdType : SocksCmdType.values()) {
|
||||
testSocksCmdRequestDecoderWithDifferentParams(cmdType, SocksAddressType.UNKNOWN, host, port);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,25 +16,26 @@
|
|||
package io.netty.handler.codec.socks;
|
||||
|
||||
import org.junit.Test;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class SocksCmdRequestTest {
|
||||
@Test
|
||||
public void testConstructorParamsAreNotNull(){
|
||||
try {
|
||||
new SocksCmdRequest(null, SocksMessage.AddressType.UNKNOWN, "", 0);
|
||||
new SocksCmdRequest(null, SocksAddressType.UNKNOWN, "", 0);
|
||||
} catch (Exception e){
|
||||
assertTrue(e instanceof NullPointerException);
|
||||
}
|
||||
|
||||
try {
|
||||
new SocksCmdRequest(SocksMessage.CmdType.UNKNOWN, null, "", 0);
|
||||
new SocksCmdRequest(SocksCmdType.UNKNOWN, null, "", 0);
|
||||
} catch (Exception e){
|
||||
assertTrue(e instanceof NullPointerException);
|
||||
}
|
||||
|
||||
try {
|
||||
new SocksCmdRequest(SocksMessage.CmdType.UNKNOWN, SocksMessage.AddressType.UNKNOWN, null, 0);
|
||||
new SocksCmdRequest(SocksCmdType.UNKNOWN, SocksAddressType.UNKNOWN, null, 0);
|
||||
} catch (Exception e){
|
||||
assertTrue(e instanceof NullPointerException);
|
||||
}
|
||||
|
@ -43,7 +44,7 @@ public class SocksCmdRequestTest {
|
|||
@Test
|
||||
public void testIPv4CorrectAddress(){
|
||||
try {
|
||||
new SocksCmdRequest(SocksMessage.CmdType.BIND, SocksMessage.AddressType.IPv4, "54.54.1111.253", 0);
|
||||
new SocksCmdRequest(SocksCmdType.BIND, SocksAddressType.IPv4, "54.54.1111.253", 0);
|
||||
} catch (Exception e){
|
||||
assertTrue(e instanceof IllegalArgumentException);
|
||||
}
|
||||
|
@ -52,7 +53,7 @@ public class SocksCmdRequestTest {
|
|||
@Test
|
||||
public void testIPv6CorrectAddress(){
|
||||
try {
|
||||
new SocksCmdRequest(SocksMessage.CmdType.BIND, SocksMessage.AddressType.IPv6, "xxx:xxx:xxx", 0);
|
||||
new SocksCmdRequest(SocksCmdType.BIND, SocksAddressType.IPv6, "xxx:xxx:xxx", 0);
|
||||
} catch (Exception e){
|
||||
assertTrue(e instanceof IllegalArgumentException);
|
||||
}
|
||||
|
@ -61,7 +62,7 @@ public class SocksCmdRequestTest {
|
|||
@Test
|
||||
public void testIDNNotExceeds255CharsLimit(){
|
||||
try {
|
||||
new SocksCmdRequest(SocksMessage.CmdType.BIND, SocksMessage.AddressType.DOMAIN,
|
||||
new SocksCmdRequest(SocksCmdType.BIND, SocksAddressType.DOMAIN,
|
||||
"παράδειγμα.δοκιμήπαράδειγμα.δοκιμήπαράδειγμα.δοκιμήπαράδειγμα.δοκιμή" +
|
||||
"παράδειγμα.δοκιμήπαράδειγμα.δοκιμήπαράδειγμα.δοκιμήπαράδειγμα.δοκιμή" +
|
||||
"παράδειγμα.δοκιμήπαράδειγμα.δοκιμήπαράδειγμα.δοκιμήπαράδειγμα.δοκιμή" +
|
||||
|
@ -74,14 +75,14 @@ public class SocksCmdRequestTest {
|
|||
@Test
|
||||
public void testValidPortRange(){
|
||||
try {
|
||||
new SocksCmdRequest(SocksMessage.CmdType.BIND, SocksMessage.AddressType.DOMAIN,
|
||||
new SocksCmdRequest(SocksCmdType.BIND, SocksAddressType.DOMAIN,
|
||||
"παράδειγμα.δοκιμήπαράδει", -1);
|
||||
} catch (Exception e){
|
||||
assertTrue(e instanceof IllegalArgumentException);
|
||||
}
|
||||
|
||||
try {
|
||||
new SocksCmdRequest(SocksMessage.CmdType.BIND, SocksMessage.AddressType.DOMAIN,
|
||||
new SocksCmdRequest(SocksCmdType.BIND, SocksAddressType.DOMAIN,
|
||||
"παράδειγμα.δοκιμήπαράδει", 65536);
|
||||
} catch (Exception e){
|
||||
assertTrue(e instanceof IllegalArgumentException);
|
||||
|
|
|
@ -25,13 +25,13 @@ import static org.junit.Assert.*;
|
|||
public class SocksCmdResponseDecoderTest {
|
||||
private static final Logger logger = LoggerFactory.getLogger(SocksCmdResponseDecoderTest.class);
|
||||
|
||||
private static void testSocksCmdResponseDecoderWithDifferentParams(SocksMessage.CmdStatus cmdStatus, SocksMessage.AddressType addressType){
|
||||
private static void testSocksCmdResponseDecoderWithDifferentParams(SocksCmdStatus cmdStatus, SocksAddressType addressType){
|
||||
logger.debug("Testing cmdStatus: " + cmdStatus + " addressType: " + addressType);
|
||||
SocksResponse msg = new SocksCmdResponse(cmdStatus, addressType);
|
||||
SocksCmdResponseDecoder decoder = new SocksCmdResponseDecoder();
|
||||
EmbeddedByteChannel embedder = new EmbeddedByteChannel(decoder);
|
||||
SocksCommonTestUtils.writeMessageIntoEmbedder(embedder, msg);
|
||||
if (addressType == SocksMessage.AddressType.UNKNOWN){
|
||||
if (addressType == SocksAddressType.UNKNOWN){
|
||||
assertTrue(embedder.readInbound() instanceof UnknownSocksResponse);
|
||||
} else {
|
||||
msg = (SocksResponse) embedder.readInbound();
|
||||
|
@ -42,8 +42,8 @@ public class SocksCmdResponseDecoderTest {
|
|||
|
||||
@Test
|
||||
public void testSocksCmdResponseDecoder(){
|
||||
for (SocksMessage.CmdStatus cmdStatus: SocksMessage.CmdStatus.values()){
|
||||
for (SocksMessage.AddressType addressType: SocksMessage.AddressType.values()){
|
||||
for (SocksCmdStatus cmdStatus: SocksCmdStatus.values()){
|
||||
for (SocksAddressType addressType: SocksAddressType.values()){
|
||||
testSocksCmdResponseDecoderWithDifferentParams(cmdStatus, addressType);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,18 +16,19 @@
|
|||
package io.netty.handler.codec.socks;
|
||||
|
||||
import org.junit.Test;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class SocksCmdResponseTest {
|
||||
@Test
|
||||
public void testConstructorParamsAreNotNull() {
|
||||
try {
|
||||
new SocksCmdResponse(null, SocksMessage.AddressType.UNKNOWN);
|
||||
new SocksCmdResponse(null, SocksAddressType.UNKNOWN);
|
||||
} catch (Exception e) {
|
||||
assertTrue(e instanceof NullPointerException);
|
||||
}
|
||||
try {
|
||||
new SocksCmdResponse(SocksMessage.CmdStatus.UNASSIGNED, null);
|
||||
new SocksCmdResponse(SocksCmdStatus.UNASSIGNED, null);
|
||||
} catch (Exception e) {
|
||||
assertTrue(e instanceof NullPointerException);
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ import io.netty.buffer.MessageBuf;
|
|||
import io.netty.channel.ChannelHandler;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.ChannelPipeline;
|
||||
import io.netty.util.internal.Signal;
|
||||
import io.netty.util.Signal;
|
||||
|
||||
/**
|
||||
* A specialized variation of {@link ByteToMessageDecoder} which enables implementation
|
||||
|
|
|
@ -21,7 +21,7 @@ import io.netty.buffer.ByteBufAllocator;
|
|||
import io.netty.buffer.ByteBufIndexFinder;
|
||||
import io.netty.buffer.SwappedByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import io.netty.util.internal.Signal;
|
||||
import io.netty.util.Signal;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
|
|
|
@ -19,6 +19,10 @@ import java.lang.ref.Reference;
|
|||
import java.util.HashMap;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
*
|
||||
* @apiviz.has io.netty.handler.codec.serialization.ClassResolver oneway - - creates
|
||||
*/
|
||||
public final class ClassResolvers {
|
||||
|
||||
/**
|
||||
|
|
|
@ -19,7 +19,7 @@ import java.lang.ref.Reference;
|
|||
import java.lang.ref.SoftReference;
|
||||
import java.util.Map;
|
||||
|
||||
public class SoftReferenceMap<K, V> extends ReferenceMap<K, V> {
|
||||
final class SoftReferenceMap<K, V> extends ReferenceMap<K, V> {
|
||||
|
||||
public SoftReferenceMap(Map<K, Reference<V>> delegate) {
|
||||
super(delegate);
|
||||
|
|
|
@ -19,7 +19,7 @@ import java.lang.ref.Reference;
|
|||
import java.lang.ref.WeakReference;
|
||||
import java.util.Map;
|
||||
|
||||
public class WeakReferenceMap<K, V> extends ReferenceMap<K, V> {
|
||||
final class WeakReferenceMap<K, V> extends ReferenceMap<K, V> {
|
||||
|
||||
public WeakReferenceMap(Map<K, Reference<V>> delegate) {
|
||||
super(delegate);
|
||||
|
|
|
@ -18,7 +18,7 @@ package io.netty.handler.codec;
|
|||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import io.netty.util.CharsetUtil;
|
||||
import io.netty.util.internal.Signal;
|
||||
import io.netty.util.Signal;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
|
|
@ -19,6 +19,8 @@ package io.netty.util;
|
|||
* Holds {@link Attribute}s which can be accessed via {@link AttributeKey}.
|
||||
*
|
||||
* Implementations must be Thread-safe.
|
||||
*
|
||||
* @apiviz.composedOf io.netty.util.Attribute oneway - - creates
|
||||
*/
|
||||
public interface AttributeMap {
|
||||
/**
|
||||
|
|
|
@ -15,8 +15,8 @@
|
|||
*/
|
||||
package io.netty.util;
|
||||
|
||||
import io.netty.logging.InternalLogger;
|
||||
import io.netty.logging.InternalLoggerFactory;
|
||||
import io.netty.util.internal.InternalLogger;
|
||||
import io.netty.util.internal.InternalLoggerFactory;
|
||||
import io.netty.util.internal.PlatformDependent;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
|
|
@ -15,8 +15,8 @@
|
|||
*/
|
||||
package io.netty.util;
|
||||
|
||||
import io.netty.logging.InternalLogger;
|
||||
import io.netty.logging.InternalLoggerFactory;
|
||||
import io.netty.util.internal.InternalLogger;
|
||||
import io.netty.util.internal.InternalLoggerFactory;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.FileReader;
|
||||
|
|
|
@ -16,8 +16,8 @@
|
|||
|
||||
package io.netty.util;
|
||||
|
||||
import io.netty.logging.InternalLogger;
|
||||
import io.netty.logging.InternalLoggerFactory;
|
||||
import io.netty.util.internal.InternalLogger;
|
||||
import io.netty.util.internal.InternalLoggerFactory;
|
||||
import io.netty.util.internal.SystemPropertyUtil;
|
||||
|
||||
import java.lang.ref.PhantomReference;
|
||||
|
@ -26,6 +26,9 @@ import java.util.concurrent.ConcurrentHashMap;
|
|||
import java.util.concurrent.ConcurrentMap;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
/**
|
||||
* @apiviz.has io.netty.util.ResourceLeak oneway - - creates
|
||||
*/
|
||||
public final class ResourceLeakDetector<T> {
|
||||
|
||||
private static final boolean ENABLED = SystemPropertyUtil.getBoolean("io.netty.resourceLeakDetection", false);
|
||||
|
|
|
@ -13,18 +13,15 @@
|
|||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package io.netty.util.internal;
|
||||
package io.netty.util;
|
||||
|
||||
|
||||
import io.netty.util.UniqueName;
|
||||
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
|
||||
/**
|
||||
* A special {@link Error} which is used to signal some state via an {@link Error}.
|
||||
*
|
||||
* This instance will have no stacktrace filled or any cause set to safe the overhead.
|
||||
* A special {@link Error} which is used to signal some state or request by throwing it.
|
||||
* {@link Signal} has an empty stack trace and has no cause to save the instantiation overhead.
|
||||
*/
|
||||
public final class Signal extends Error {
|
||||
|
|
@ -13,7 +13,7 @@
|
|||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package io.netty.logging;
|
||||
package io.netty.util.internal;
|
||||
|
||||
import java.io.ObjectStreamException;
|
||||
import java.io.Serializable;
|
|
@ -37,7 +37,7 @@
|
|||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
package io.netty.logging;
|
||||
package io.netty.util.internal;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
|
|
@ -13,7 +13,7 @@
|
|||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package io.netty.logging;
|
||||
package io.netty.util.internal;
|
||||
|
||||
|
||||
import org.apache.commons.logging.LogFactory;
|
|
@ -37,7 +37,7 @@
|
|||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
package io.netty.logging;
|
||||
package io.netty.util.internal;
|
||||
|
||||
/**
|
||||
* Holds the results of formatting done by {@link MessageFormatter}.
|
|
@ -13,7 +13,7 @@
|
|||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package io.netty.logging;
|
||||
package io.netty.util.internal;
|
||||
|
||||
/**
|
||||
* The log level that {@link InternalLogger} can log at.
|
|
@ -37,7 +37,7 @@
|
|||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
package io.netty.logging;
|
||||
package io.netty.util.internal;
|
||||
|
||||
/**
|
||||
* <em>Internal-use-only</em> logger used by Netty. <strong>DO NOT</strong>
|
|
@ -13,7 +13,7 @@
|
|||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package io.netty.logging;
|
||||
package io.netty.util.internal;
|
||||
|
||||
/**
|
||||
* Creates an {@link InternalLogger} or changes the default factory
|
||||
|
@ -29,7 +29,7 @@ package io.netty.logging;
|
|||
* {@link #setDefaultFactory(InternalLoggerFactory)} should be called as early
|
||||
* as possible and shouldn't be called more than once.
|
||||
* @apiviz.landmark
|
||||
* @apiviz.has io.netty.logging.InternalLogger oneway - - creates
|
||||
* @apiviz.has io.netty.util.internal.InternalLogger oneway - - creates
|
||||
*/
|
||||
public abstract class InternalLoggerFactory {
|
||||
private static volatile InternalLoggerFactory defaultFactory;
|
|
@ -16,8 +16,6 @@
|
|||
|
||||
package io.netty.util.internal;
|
||||
|
||||
import io.netty.logging.InternalLogger;
|
||||
import io.netty.logging.InternalLoggerFactory;
|
||||
import javassist.ClassPool;
|
||||
import javassist.CtClass;
|
||||
import javassist.Modifier;
|
||||
|
|
|
@ -37,7 +37,7 @@
|
|||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
package io.netty.logging;
|
||||
package io.netty.util.internal;
|
||||
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.LogRecord;
|
|
@ -13,7 +13,7 @@
|
|||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package io.netty.logging;
|
||||
package io.netty.util.internal;
|
||||
|
||||
|
||||
import java.util.logging.Logger;
|
|
@ -37,7 +37,7 @@
|
|||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
package io.netty.logging;
|
||||
package io.netty.util.internal;
|
||||
|
||||
import org.apache.log4j.Level;
|
||||
import org.apache.log4j.Logger;
|
|
@ -13,7 +13,7 @@
|
|||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package io.netty.logging;
|
||||
package io.netty.util.internal;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
|
@ -37,7 +37,7 @@
|
|||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
package io.netty.logging;
|
||||
package io.netty.util.internal;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
import java.util.HashMap;
|
|
@ -13,7 +13,7 @@
|
|||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package io.netty.logging;
|
||||
package io.netty.util.internal;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
|
|
@ -13,7 +13,7 @@
|
|||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package io.netty.logging;
|
||||
package io.netty.util.internal;
|
||||
|
||||
|
||||
import org.slf4j.LoggerFactory;
|
|
@ -15,9 +15,6 @@
|
|||
*/
|
||||
package io.netty.util.internal;
|
||||
|
||||
import io.netty.logging.InternalLogger;
|
||||
import io.netty.logging.InternalLoggerFactory;
|
||||
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.regex.Pattern;
|
||||
|
|
|
@ -47,8 +47,8 @@ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
*/
|
||||
package io.netty.util.internal.jzlib;
|
||||
|
||||
import io.netty.logging.InternalLogger;
|
||||
import io.netty.logging.InternalLoggerFactory;
|
||||
import io.netty.util.internal.InternalLogger;
|
||||
import io.netty.util.internal.InternalLoggerFactory;
|
||||
import io.netty.util.internal.jzlib.JZlib.WrapperType;
|
||||
|
||||
public final class ZStream {
|
||||
|
|
|
@ -21,6 +21,6 @@
|
|||
* @apiviz.exclude ^java\.(lang|util)\.
|
||||
* @apiviz.exclude \.netty\.(?!util)[a-z0-9]+\.
|
||||
* @apiviz.exclude Util$
|
||||
* @apiviz.exclude \.EstimatableObjectWrapper$
|
||||
* @apiviz.exclude Exception$
|
||||
*/
|
||||
package io.netty.util;
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package io.netty.logging;
|
||||
package io.netty.util.internal;
|
||||
|
||||
import org.junit.Test;
|
||||
|
|
@ -13,14 +13,14 @@
|
|||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package io.netty.logging;
|
||||
|
||||
import static org.easymock.EasyMock.*;
|
||||
import static org.junit.Assert.*;
|
||||
package io.netty.util.internal;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.easymock.EasyMock.*;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class CommonsLoggerTest {
|
||||
private static final Exception e = new Exception();
|
||||
|
|
@ -13,7 +13,7 @@
|
|||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package io.netty.logging;
|
||||
package io.netty.util.internal;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
|
@ -13,7 +13,7 @@
|
|||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package io.netty.logging;
|
||||
package io.netty.util.internal;
|
||||
|
||||
import org.junit.Test;
|
||||
|
|
@ -13,7 +13,7 @@
|
|||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package io.netty.logging;
|
||||
package io.netty.util.internal;
|
||||
|
||||
import org.junit.Test;
|
||||
|
|
@ -13,7 +13,7 @@
|
|||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package io.netty.logging;
|
||||
package io.netty.util.internal;
|
||||
|
||||
import org.junit.Test;
|
||||
|
|
@ -13,7 +13,7 @@
|
|||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package io.netty.logging;
|
||||
package io.netty.util.internal;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
|
@ -1,2 +0,0 @@
|
|||
io.netty.monitor.support.SampleMonitorRegistryFactory
|
||||
io.netty.monitor.support.AnotherSampleMonitorRegistryFactory
|
|
@ -34,8 +34,6 @@ import io.netty.handler.codec.http.multipart.HttpDataFactory;
|
|||
import io.netty.handler.codec.http.multipart.HttpPostRequestEncoder;
|
||||
import io.netty.handler.codec.http.multipart.HttpPostRequestEncoder.ErrorDataEncoderException;
|
||||
import io.netty.handler.codec.http.multipart.InterfaceHttpData;
|
||||
import io.netty.logging.InternalLogger;
|
||||
import io.netty.logging.InternalLoggerFactory;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
|
@ -44,13 +42,15 @@ import java.net.URI;
|
|||
import java.net.URISyntaxException;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
* This class is meant to be run against {@link HttpUploadServer}.
|
||||
*/
|
||||
public class HttpUploadClient {
|
||||
|
||||
private static final InternalLogger logger = InternalLoggerFactory.getInstance(HttpUploadClient.class);
|
||||
private static final Logger logger = Logger.getLogger(HttpUploadClient.class.getName());
|
||||
|
||||
private final String baseUri;
|
||||
private final String filePath;
|
||||
|
@ -75,7 +75,7 @@ public class HttpUploadClient {
|
|||
try {
|
||||
uriSimple = new URI(postSimple);
|
||||
} catch (URISyntaxException e) {
|
||||
logger.error("Invalid URI syntax" + e.getCause());
|
||||
logger.log(Level.WARNING, "Invalid URI syntax", e);
|
||||
return;
|
||||
}
|
||||
String scheme = uriSimple.getScheme() == null ? "http" : uriSimple.getScheme();
|
||||
|
@ -90,7 +90,7 @@ public class HttpUploadClient {
|
|||
}
|
||||
|
||||
if (!"http".equalsIgnoreCase(scheme) && !"https".equalsIgnoreCase(scheme)) {
|
||||
logger.error("Only HTTP(S) is supported.");
|
||||
logger.log(Level.WARNING, "Only HTTP(S) is supported.");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -100,12 +100,12 @@ public class HttpUploadClient {
|
|||
try {
|
||||
uriFile = new URI(postFile);
|
||||
} catch (URISyntaxException e) {
|
||||
logger.error("Error: " + e.getMessage());
|
||||
logger.log(Level.WARNING, "Error: ", e);
|
||||
return;
|
||||
}
|
||||
File file = new File(filePath);
|
||||
if (!file.canRead()) {
|
||||
logger.error("A correct path is needed");
|
||||
logger.log(Level.WARNING, "A correct path is needed");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -172,7 +172,7 @@ public class HttpUploadClient {
|
|||
try {
|
||||
uriGet = new URI(encoder.toString());
|
||||
} catch (URISyntaxException e) {
|
||||
logger.error("Error: " + e.getMessage());
|
||||
logger.log(Level.WARNING, "Error: ", e);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
@ -21,16 +21,16 @@ import io.netty.handler.codec.http.HttpContent;
|
|||
import io.netty.handler.codec.http.HttpHeaders;
|
||||
import io.netty.handler.codec.http.HttpResponse;
|
||||
import io.netty.handler.codec.http.LastHttpContent;
|
||||
import io.netty.logging.InternalLogger;
|
||||
import io.netty.logging.InternalLoggerFactory;
|
||||
import io.netty.util.CharsetUtil;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
* Handler that just dumps the contents of the response from the server
|
||||
*/
|
||||
public class HttpUploadClientHandler extends ChannelInboundMessageHandlerAdapter<Object> {
|
||||
|
||||
private static final InternalLogger logger = InternalLoggerFactory.getInstance(HttpUploadClientHandler.class);
|
||||
private static final Logger logger = Logger.getLogger(HttpUploadClientHandler.class.getName());
|
||||
|
||||
private boolean readingChunks;
|
||||
|
||||
|
|
|
@ -45,8 +45,6 @@ import io.netty.handler.codec.http.multipart.HttpPostRequestDecoder.Incompatible
|
|||
import io.netty.handler.codec.http.multipart.HttpPostRequestDecoder.NotEnoughDataDecoderException;
|
||||
import io.netty.handler.codec.http.multipart.InterfaceHttpData;
|
||||
import io.netty.handler.codec.http.multipart.InterfaceHttpData.HttpDataType;
|
||||
import io.netty.logging.InternalLogger;
|
||||
import io.netty.logging.InternalLoggerFactory;
|
||||
import io.netty.util.CharsetUtil;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -56,13 +54,15 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import static io.netty.buffer.Unpooled.*;
|
||||
import static io.netty.handler.codec.http.HttpHeaders.Names.*;
|
||||
|
||||
public class HttpUploadServerHandler extends ChannelInboundMessageHandlerAdapter<Object> {
|
||||
|
||||
private static final InternalLogger logger = InternalLoggerFactory.getInstance(HttpUploadServerHandler.class);
|
||||
private static final Logger logger = Logger.getLogger(HttpUploadServerHandler.class.getName());
|
||||
|
||||
private HttpRequest request;
|
||||
|
||||
|
@ -422,7 +422,7 @@ public class HttpUploadServerHandler extends ChannelInboundMessageHandlerAdapter
|
|||
|
||||
@Override
|
||||
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
|
||||
logger.error(responseContent.toString(), cause);
|
||||
logger.log(Level.WARNING, responseContent.toString(), cause);
|
||||
ctx.channel().close();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,10 +33,11 @@ import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;
|
|||
import io.netty.handler.codec.http.websocketx.WebSocketFrame;
|
||||
import io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker;
|
||||
import io.netty.handler.codec.http.websocketx.WebSocketServerHandshakerFactory;
|
||||
import io.netty.logging.InternalLogger;
|
||||
import io.netty.logging.InternalLoggerFactory;
|
||||
import io.netty.util.CharsetUtil;
|
||||
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import static io.netty.handler.codec.http.HttpHeaders.*;
|
||||
import static io.netty.handler.codec.http.HttpMethod.*;
|
||||
import static io.netty.handler.codec.http.HttpResponseStatus.*;
|
||||
|
@ -46,7 +47,7 @@ import static io.netty.handler.codec.http.HttpVersion.*;
|
|||
* Handles handshakes and messages
|
||||
*/
|
||||
public class AutobahnServerHandler extends ChannelInboundMessageHandlerAdapter<Object> {
|
||||
private static final InternalLogger logger = InternalLoggerFactory.getInstance(AutobahnServerHandler.class);
|
||||
private static final Logger logger = Logger.getLogger(AutobahnServerHandler.class.getName());
|
||||
|
||||
private WebSocketServerHandshaker handshaker;
|
||||
|
||||
|
@ -84,9 +85,9 @@ public class AutobahnServerHandler extends ChannelInboundMessageHandlerAdapter<O
|
|||
}
|
||||
|
||||
private void handleWebSocketFrame(ChannelHandlerContext ctx, WebSocketFrame frame) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug(String.format("Channel %s received %s", ctx.channel().id(), frame.getClass()
|
||||
.getSimpleName()));
|
||||
if (logger.isLoggable(Level.FINE)) {
|
||||
logger.fine(String.format(
|
||||
"Channel %s received %s", ctx.channel().id(), frame.getClass().getSimpleName()));
|
||||
}
|
||||
|
||||
if (frame instanceof CloseWebSocketFrame) {
|
||||
|
|
|
@ -31,10 +31,11 @@ import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;
|
|||
import io.netty.handler.codec.http.websocketx.WebSocketFrame;
|
||||
import io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker;
|
||||
import io.netty.handler.codec.http.websocketx.WebSocketServerHandshakerFactory;
|
||||
import io.netty.logging.InternalLogger;
|
||||
import io.netty.logging.InternalLoggerFactory;
|
||||
import io.netty.util.CharsetUtil;
|
||||
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import static io.netty.handler.codec.http.HttpHeaders.Names.*;
|
||||
import static io.netty.handler.codec.http.HttpHeaders.*;
|
||||
import static io.netty.handler.codec.http.HttpMethod.*;
|
||||
|
@ -45,7 +46,7 @@ import static io.netty.handler.codec.http.HttpVersion.*;
|
|||
* Handles handshakes and messages
|
||||
*/
|
||||
public class WebSocketServerHandler extends ChannelInboundMessageHandlerAdapter<Object> {
|
||||
private static final InternalLogger logger = InternalLoggerFactory.getInstance(WebSocketServerHandler.class);
|
||||
private static final Logger logger = Logger.getLogger(WebSocketServerHandler.class.getName());
|
||||
|
||||
private static final String WEBSOCKET_PATH = "/websocket";
|
||||
|
||||
|
@ -121,8 +122,8 @@ public class WebSocketServerHandler extends ChannelInboundMessageHandlerAdapter<
|
|||
|
||||
// Send the uppercase string back.
|
||||
String request = ((TextWebSocketFrame) frame).text();
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug(String.format("Channel %s received %s", ctx.channel().id(), request));
|
||||
if (logger.isLoggable(Level.FINE)) {
|
||||
logger.fine(String.format("Channel %s received %s", ctx.channel().id(), request));
|
||||
}
|
||||
ctx.channel().write(new TextWebSocketFrame(request.toUpperCase()));
|
||||
}
|
||||
|
|
|
@ -32,10 +32,11 @@ import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;
|
|||
import io.netty.handler.codec.http.websocketx.WebSocketFrame;
|
||||
import io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker;
|
||||
import io.netty.handler.codec.http.websocketx.WebSocketServerHandshakerFactory;
|
||||
import io.netty.logging.InternalLogger;
|
||||
import io.netty.logging.InternalLoggerFactory;
|
||||
import io.netty.util.CharsetUtil;
|
||||
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import static io.netty.handler.codec.http.HttpHeaders.Names.*;
|
||||
import static io.netty.handler.codec.http.HttpHeaders.*;
|
||||
import static io.netty.handler.codec.http.HttpMethod.*;
|
||||
|
@ -46,7 +47,7 @@ import static io.netty.handler.codec.http.HttpVersion.*;
|
|||
* Handles handshakes and messages
|
||||
*/
|
||||
public class WebSocketSslServerHandler extends ChannelInboundMessageHandlerAdapter<Object> {
|
||||
private static final InternalLogger logger = InternalLoggerFactory.getInstance(WebSocketSslServerHandler.class);
|
||||
private static final Logger logger = Logger.getLogger(WebSocketSslServerHandler.class.getName());
|
||||
|
||||
private static final String WEBSOCKET_PATH = "/websocket";
|
||||
|
||||
|
@ -123,8 +124,8 @@ public class WebSocketSslServerHandler extends ChannelInboundMessageHandlerAdapt
|
|||
|
||||
// Send the uppercase string back.
|
||||
String request = ((TextWebSocketFrame) frame).text();
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug(String.format("Channel %s received %s", ctx.channel().id(), request));
|
||||
if (logger.isLoggable(Level.FINE)) {
|
||||
logger.fine(String.format("Channel %s received %s", ctx.channel().id(), request));
|
||||
}
|
||||
ctx.channel().write(new TextWebSocketFrame(request.toUpperCase()));
|
||||
}
|
||||
|
|
|
@ -15,21 +15,20 @@
|
|||
*/
|
||||
package io.netty.example.http.websocketx.sslserver;
|
||||
|
||||
import io.netty.logging.InternalLogger;
|
||||
import io.netty.logging.InternalLoggerFactory;
|
||||
|
||||
import javax.net.ssl.KeyManagerFactory;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import java.io.FileInputStream;
|
||||
import java.security.KeyStore;
|
||||
import java.security.Security;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
* Creates a {@link SSLContext} for just server certificates.
|
||||
*/
|
||||
public final class WebSocketSslServerSslContext {
|
||||
|
||||
private static final InternalLogger logger = InternalLoggerFactory.getInstance(WebSocketSslServerSslContext.class);
|
||||
private static final Logger logger = Logger.getLogger(WebSocketSslServerSslContext.class.getName());
|
||||
private static final String PROTOCOL = "TLS";
|
||||
private final SSLContext _serverContext;
|
||||
|
||||
|
@ -83,9 +82,7 @@ public final class WebSocketSslServerSslContext {
|
|||
throw new Error("Failed to initialize the server-side SSLContext", e);
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
if (logger.isErrorEnabled()) {
|
||||
logger.error("Error initializing SslContextManager. " + ex.getMessage(), ex);
|
||||
}
|
||||
logger.log(Level.WARNING, "Error initializing SslContextManager.", ex);
|
||||
System.exit(1);
|
||||
} finally {
|
||||
_serverContext = serverContext;
|
||||
|
|
|
@ -26,8 +26,7 @@ import io.netty.channel.ChannelOption;
|
|||
import io.netty.channel.socket.nio.NioSocketChannel;
|
||||
import io.netty.handler.codec.socks.SocksCmdRequest;
|
||||
import io.netty.handler.codec.socks.SocksCmdResponse;
|
||||
import io.netty.handler.codec.socks.SocksMessage;
|
||||
|
||||
import io.netty.handler.codec.socks.SocksCmdStatus;
|
||||
|
||||
@ChannelHandler.Sharable
|
||||
public final class SocksServerConnectHandler extends ChannelInboundMessageHandlerAdapter<SocksCmdRequest> {
|
||||
|
@ -44,7 +43,7 @@ public final class SocksServerConnectHandler extends ChannelInboundMessageHandle
|
|||
CallbackNotifier cb = new CallbackNotifier() {
|
||||
@Override
|
||||
public void onSuccess(final ChannelHandlerContext outboundCtx) {
|
||||
ctx.channel().write(new SocksCmdResponse(SocksMessage.CmdStatus.SUCCESS, request.addressType()))
|
||||
ctx.channel().write(new SocksCmdResponse(SocksCmdStatus.SUCCESS, request.addressType()))
|
||||
.addListener(new ChannelFutureListener() {
|
||||
@Override
|
||||
public void operationComplete(ChannelFuture channelFuture) throws Exception {
|
||||
|
@ -57,7 +56,7 @@ public final class SocksServerConnectHandler extends ChannelInboundMessageHandle
|
|||
|
||||
@Override
|
||||
public void onFailure(ChannelHandlerContext outboundCtx, Throwable cause) {
|
||||
ctx.channel().write(new SocksCmdResponse(SocksMessage.CmdStatus.FAILURE, request.addressType()));
|
||||
ctx.channel().write(new SocksCmdResponse(SocksCmdStatus.FAILURE, request.addressType()));
|
||||
SocksServerUtils.closeOnFlush(ctx.channel());
|
||||
}
|
||||
};
|
||||
|
|
|
@ -19,10 +19,12 @@ import io.netty.channel.ChannelHandler;
|
|||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.ChannelInboundMessageHandlerAdapter;
|
||||
import io.netty.handler.codec.socks.SocksAuthResponse;
|
||||
import io.netty.handler.codec.socks.SocksAuthScheme;
|
||||
import io.netty.handler.codec.socks.SocksAuthStatus;
|
||||
import io.netty.handler.codec.socks.SocksCmdRequest;
|
||||
import io.netty.handler.codec.socks.SocksCmdRequestDecoder;
|
||||
import io.netty.handler.codec.socks.SocksCmdType;
|
||||
import io.netty.handler.codec.socks.SocksInitResponse;
|
||||
import io.netty.handler.codec.socks.SocksMessage;
|
||||
import io.netty.handler.codec.socks.SocksRequest;
|
||||
|
||||
|
||||
|
@ -40,18 +42,18 @@ public final class SocksServerHandler extends ChannelInboundMessageHandlerAdapte
|
|||
case INIT: {
|
||||
// auth support example
|
||||
// ctx.pipeline().addFirst("socksAuthRequestDecoder",new SocksAuthRequestDecoder());
|
||||
// ctx.write(new SocksInitResponse(SocksMessage.AuthScheme.AUTH_PASSWORD));
|
||||
// ctx.write(new SocksInitResponse(SocksMessage.SocksAuthScheme.AUTH_PASSWORD));
|
||||
ctx.pipeline().addFirst(SocksCmdRequestDecoder.getName(), new SocksCmdRequestDecoder());
|
||||
ctx.write(new SocksInitResponse(SocksMessage.AuthScheme.NO_AUTH));
|
||||
ctx.write(new SocksInitResponse(SocksAuthScheme.NO_AUTH));
|
||||
break;
|
||||
}
|
||||
case AUTH:
|
||||
ctx.pipeline().addFirst(SocksCmdRequestDecoder.getName(), new SocksCmdRequestDecoder());
|
||||
ctx.write(new SocksAuthResponse(SocksMessage.AuthStatus.SUCCESS));
|
||||
ctx.write(new SocksAuthResponse(SocksAuthStatus.SUCCESS));
|
||||
break;
|
||||
case CMD:
|
||||
SocksCmdRequest req = (SocksCmdRequest) socksRequest;
|
||||
if (req.cmdType() == SocksMessage.CmdType.CONNECT) {
|
||||
if (req.cmdType() == SocksCmdType.CONNECT) {
|
||||
ctx.pipeline().addLast(SocksServerConnectHandler.getName(), new SocksServerConnectHandler());
|
||||
ctx.pipeline().remove(this);
|
||||
ctx.nextInboundMessageBuffer().add(socksRequest);
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
*/
|
||||
package io.netty.handler.logging;
|
||||
|
||||
import io.netty.logging.InternalLogLevel;
|
||||
import io.netty.util.internal.InternalLogLevel;
|
||||
|
||||
public enum LogLevel {
|
||||
TRACE(InternalLogLevel.TRACE),
|
||||
|
|
|
@ -20,15 +20,16 @@ import io.netty.channel.ChannelHandler;
|
|||
import io.netty.channel.ChannelHandler.Sharable;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.ChannelPromise;
|
||||
import io.netty.logging.InternalLogLevel;
|
||||
import io.netty.logging.InternalLogger;
|
||||
import io.netty.logging.InternalLoggerFactory;
|
||||
import io.netty.util.internal.InternalLogLevel;
|
||||
import io.netty.util.internal.InternalLogger;
|
||||
import io.netty.util.internal.InternalLoggerFactory;
|
||||
|
||||
import java.net.SocketAddress;
|
||||
|
||||
/**
|
||||
* A {@link ChannelHandler} that logs all events via {@link InternalLogger}.
|
||||
* A {@link ChannelHandler} that logs all events using a logging framework.
|
||||
* By default, all events are logged at <tt>DEBUG</tt> level.
|
||||
*
|
||||
* @apiviz.landmark
|
||||
*/
|
||||
@Sharable
|
||||
|
@ -115,7 +116,7 @@ public class LoggingHandler extends ChannelDuplexHandler {
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns the {@link InternalLogLevel} that this handler uses to log
|
||||
* Returns the {@link LogLevel} that this handler uses to log
|
||||
*/
|
||||
public LogLevel level() {
|
||||
return level;
|
||||
|
|
|
@ -15,8 +15,7 @@
|
|||
*/
|
||||
|
||||
/**
|
||||
* Logs a {@link io.netty.channel.ChannelEvent} for debugging purpose
|
||||
* using an {@link io.netty.logging.InternalLogger}.
|
||||
* Logs a {@link io.netty.channel.ChannelEvent} for debugging purpose.
|
||||
*
|
||||
* @apiviz.hidden
|
||||
* @apiviz.exclude \.channel\.
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user