mirror of
https://github.com/traccar/traccar.git
synced 2026-05-19 06:02:22 -04:00
Limit for custom frame decoders
This commit is contained in:
@@ -19,16 +19,29 @@ import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.handler.codec.ByteToMessageDecoder;
|
||||
import io.netty.handler.codec.TooLongFrameException;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public abstract class BaseFrameDecoder extends ByteToMessageDecoder {
|
||||
|
||||
private final int maxFrameLength;
|
||||
|
||||
protected BaseFrameDecoder() {
|
||||
this(BaseProtocol.MAX_FRAME_LENGTH);
|
||||
}
|
||||
|
||||
protected BaseFrameDecoder(int maxFrameLength) {
|
||||
this.maxFrameLength = maxFrameLength;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
|
||||
Object decoded = decode(ctx, ctx != null ? ctx.channel() : null, in);
|
||||
if (decoded != null) {
|
||||
out.add(decoded);
|
||||
} else if (in.readableBytes() > maxFrameLength) {
|
||||
throw new TooLongFrameException("Frame exceeds " + maxFrameLength + " bytes");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -19,9 +19,14 @@ import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import org.traccar.BaseFrameDecoder;
|
||||
import org.traccar.BaseProtocol;
|
||||
|
||||
public class AdmFrameDecoder extends BaseFrameDecoder {
|
||||
|
||||
public AdmFrameDecoder() {
|
||||
super(BaseProtocol.MAX_FRAME_LENGTH_LARGE);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object decode(
|
||||
ChannelHandlerContext ctx, Channel channel, ByteBuf buf) throws Exception {
|
||||
|
||||
@@ -19,6 +19,7 @@ import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import org.traccar.BaseFrameDecoder;
|
||||
import org.traccar.BaseProtocol;
|
||||
import org.traccar.helper.BufferUtil;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
@@ -27,6 +28,10 @@ public class AtrackFrameDecoder extends BaseFrameDecoder {
|
||||
|
||||
private static final int KEEPALIVE_LENGTH = 12;
|
||||
|
||||
public AtrackFrameDecoder() {
|
||||
super(BaseProtocol.MAX_FRAME_LENGTH_LARGE);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object decode(
|
||||
ChannelHandlerContext ctx, Channel channel, ByteBuf buf) throws Exception {
|
||||
|
||||
@@ -19,11 +19,16 @@ import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import org.traccar.BaseFrameDecoder;
|
||||
import org.traccar.BaseProtocol;
|
||||
|
||||
public class DualcamFrameDecoder extends BaseFrameDecoder {
|
||||
|
||||
private static final int MESSAGE_MINIMUM_LENGTH = 4;
|
||||
|
||||
public DualcamFrameDecoder() {
|
||||
super(BaseProtocol.MAX_FRAME_LENGTH_LARGE);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object decode(
|
||||
ChannelHandlerContext ctx, Channel channel, ByteBuf buf) throws Exception {
|
||||
|
||||
@@ -19,11 +19,16 @@ import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import org.traccar.BaseFrameDecoder;
|
||||
import org.traccar.BaseProtocol;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
public class FifotrackFrameDecoder extends BaseFrameDecoder {
|
||||
|
||||
public FifotrackFrameDecoder() {
|
||||
super(BaseProtocol.MAX_FRAME_LENGTH_LARGE);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object decode(
|
||||
ChannelHandlerContext ctx, Channel channel, ByteBuf buf) throws Exception {
|
||||
|
||||
@@ -19,11 +19,16 @@ import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import org.traccar.BaseFrameDecoder;
|
||||
import org.traccar.BaseProtocol;
|
||||
|
||||
public class GalileoFrameDecoder extends BaseFrameDecoder {
|
||||
|
||||
private static final int MESSAGE_MINIMUM_LENGTH = 6;
|
||||
|
||||
public GalileoFrameDecoder() {
|
||||
super(BaseProtocol.MAX_FRAME_LENGTH_LARGE);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object decode(
|
||||
ChannelHandlerContext ctx, Channel channel, ByteBuf buf) throws Exception {
|
||||
|
||||
@@ -19,9 +19,14 @@ import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import org.traccar.BaseFrameDecoder;
|
||||
import org.traccar.BaseProtocol;
|
||||
|
||||
public class Gt06FrameDecoder extends BaseFrameDecoder {
|
||||
|
||||
public Gt06FrameDecoder() {
|
||||
super(BaseProtocol.MAX_FRAME_LENGTH_LARGE);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object decode(
|
||||
ChannelHandlerContext ctx, Channel channel, ByteBuf buf) throws Exception {
|
||||
|
||||
@@ -19,10 +19,15 @@ import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import org.traccar.BaseFrameDecoder;
|
||||
import org.traccar.BaseProtocol;
|
||||
import org.traccar.helper.BitUtil;
|
||||
|
||||
public class Jt1078FrameDecoder extends BaseFrameDecoder {
|
||||
|
||||
public Jt1078FrameDecoder() {
|
||||
super(BaseProtocol.MAX_FRAME_LENGTH_LARGE);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object decode(ChannelHandlerContext ctx, Channel channel, ByteBuf buf) throws Exception {
|
||||
|
||||
|
||||
@@ -20,9 +20,14 @@ import io.netty.buffer.Unpooled;
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import org.traccar.BaseFrameDecoder;
|
||||
import org.traccar.BaseProtocol;
|
||||
|
||||
public class Jt808FrameDecoder extends BaseFrameDecoder {
|
||||
|
||||
public Jt808FrameDecoder() {
|
||||
super(BaseProtocol.MAX_FRAME_LENGTH_LARGE);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object decode(
|
||||
ChannelHandlerContext ctx, Channel channel, ByteBuf buf) throws Exception {
|
||||
|
||||
@@ -19,11 +19,16 @@ import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import org.traccar.BaseFrameDecoder;
|
||||
import org.traccar.BaseProtocol;
|
||||
|
||||
public class MeiligaoFrameDecoder extends BaseFrameDecoder {
|
||||
|
||||
private static final int MESSAGE_HEADER = 4;
|
||||
|
||||
public MeiligaoFrameDecoder() {
|
||||
super(BaseProtocol.MAX_FRAME_LENGTH_LARGE);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object decode(
|
||||
ChannelHandlerContext ctx, Channel channel, ByteBuf buf) throws Exception {
|
||||
|
||||
@@ -19,11 +19,16 @@ import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import org.traccar.BaseFrameDecoder;
|
||||
import org.traccar.BaseProtocol;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
public class MeitrackFrameDecoder extends BaseFrameDecoder {
|
||||
|
||||
public MeitrackFrameDecoder() {
|
||||
super(BaseProtocol.MAX_FRAME_LENGTH_LARGE);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object decode(
|
||||
ChannelHandlerContext ctx, Channel channel, ByteBuf buf) throws Exception {
|
||||
|
||||
@@ -19,6 +19,7 @@ import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import org.traccar.BaseFrameDecoder;
|
||||
import org.traccar.BaseProtocol;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
@@ -26,6 +27,10 @@ public class Pt502FrameDecoder extends BaseFrameDecoder {
|
||||
|
||||
private static final int BINARY_HEADER = 5;
|
||||
|
||||
public Pt502FrameDecoder() {
|
||||
super(BaseProtocol.MAX_FRAME_LENGTH_LARGE);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object decode(
|
||||
ChannelHandlerContext ctx, Channel channel, ByteBuf buf) throws Exception {
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
package org.traccar.protocol;
|
||||
|
||||
import org.traccar.BaseFrameDecoder;
|
||||
import org.traccar.BaseProtocol;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.Channel;
|
||||
@@ -25,6 +26,10 @@ public class TeltonikaFrameDecoder extends BaseFrameDecoder {
|
||||
|
||||
private static final int MESSAGE_MINIMUM_LENGTH = 12;
|
||||
|
||||
public TeltonikaFrameDecoder() {
|
||||
super(BaseProtocol.MAX_FRAME_LENGTH_LARGE);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object decode(
|
||||
ChannelHandlerContext ctx, Channel channel, ByteBuf buf) throws Exception {
|
||||
|
||||
@@ -20,9 +20,14 @@ import io.netty.buffer.Unpooled;
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import org.traccar.BaseFrameDecoder;
|
||||
import org.traccar.BaseProtocol;
|
||||
|
||||
public class WatchFrameDecoder extends BaseFrameDecoder {
|
||||
|
||||
public WatchFrameDecoder() {
|
||||
super(BaseProtocol.MAX_FRAME_LENGTH_LARGE);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object decode(
|
||||
ChannelHandlerContext ctx, Channel channel, ByteBuf buf) throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user