aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/protocol
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2018-08-20 14:49:27 +1200
committerAnton Tananaev <anton.tananaev@gmail.com>2018-08-20 14:49:27 +1200
commit73ca03b412e5f10dccd9153c1244aa53ccbd388b (patch)
treeea8199cd9c6c68811b7ea671825d49ffd7ee3863 /src/org/traccar/protocol
parentc815113b89067b6772f63ff8548b59367145bf46 (diff)
downloadtraccar-server-73ca03b412e5f10dccd9153c1244aa53ccbd388b.tar.gz
traccar-server-73ca03b412e5f10dccd9153c1244aa53ccbd388b.tar.bz2
traccar-server-73ca03b412e5f10dccd9153c1244aa53ccbd388b.zip
Improve Atrack frame decoder
Diffstat (limited to 'src/org/traccar/protocol')
-rw-r--r--src/org/traccar/protocol/AtrackFrameDecoder.java23
1 files changed, 20 insertions, 3 deletions
diff --git a/src/org/traccar/protocol/AtrackFrameDecoder.java b/src/org/traccar/protocol/AtrackFrameDecoder.java
index 3d33d9862..f071e2d97 100644
--- a/src/org/traccar/protocol/AtrackFrameDecoder.java
+++ b/src/org/traccar/protocol/AtrackFrameDecoder.java
@@ -21,6 +21,8 @@ import io.netty.channel.ChannelHandlerContext;
import org.traccar.BaseFrameDecoder;
import org.traccar.helper.BufferUtil;
+import java.nio.charset.StandardCharsets;
+
public class AtrackFrameDecoder extends BaseFrameDecoder {
private static final int KEEPALIVE_LENGTH = 12;
@@ -48,9 +50,24 @@ public class AtrackFrameDecoder extends BaseFrameDecoder {
} else {
- int endIndex = BufferUtil.indexOf("\r\n", buf);
- if (endIndex > 0) {
- return buf.readRetainedSlice(endIndex - buf.readerIndex() + 2);
+ int lengthStart = buf.indexOf(buf.readerIndex() + 3, buf.writerIndex(), (byte) ',') + 1;
+ if (lengthStart > 0) {
+ int lengthEnd = buf.indexOf(lengthStart, buf.writerIndex(), (byte) ',');
+ if (lengthEnd > 0) {
+ int length = lengthEnd + Integer.parseInt(buf.toString(
+ lengthStart, lengthEnd - lengthStart, StandardCharsets.US_ASCII));
+ if (buf.readableBytes() > length && buf.getByte(buf.readerIndex() + length) == '\n') {
+ length += 1;
+ }
+ if (buf.readableBytes() >= length) {
+ return buf.readRetainedSlice(length);
+ }
+ }
+ } else {
+ int endIndex = BufferUtil.indexOf("\r\n", buf);
+ if (endIndex > 0) {
+ return buf.readRetainedSlice(endIndex - buf.readerIndex() + 2);
+ }
}
}