aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/protocol/WatchProtocolDecoder.java
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2018-03-27 00:55:44 +1300
committerAnton Tananaev <anton.tananaev@gmail.com>2018-03-27 00:55:44 +1300
commitcf619556709df6d5481d2e4f712ddd6eeebab89d (patch)
tree29db1b3c291a4463ceb76685d86fbaecdcb11c07 /src/org/traccar/protocol/WatchProtocolDecoder.java
parent094a9acabf8f0b94d1c62f77a409dbf7e3b137f6 (diff)
downloadtrackermap-server-cf619556709df6d5481d2e4f712ddd6eeebab89d.tar.gz
trackermap-server-cf619556709df6d5481d2e4f712ddd6eeebab89d.tar.bz2
trackermap-server-cf619556709df6d5481d2e4f712ddd6eeebab89d.zip
Improve Watch data decoding
Diffstat (limited to 'src/org/traccar/protocol/WatchProtocolDecoder.java')
-rw-r--r--src/org/traccar/protocol/WatchProtocolDecoder.java10
1 files changed, 6 insertions, 4 deletions
diff --git a/src/org/traccar/protocol/WatchProtocolDecoder.java b/src/org/traccar/protocol/WatchProtocolDecoder.java
index c57279296..41cd957ae 100644
--- a/src/org/traccar/protocol/WatchProtocolDecoder.java
+++ b/src/org/traccar/protocol/WatchProtocolDecoder.java
@@ -171,8 +171,8 @@ public class WatchProtocolDecoder extends BaseProtocolDecoder {
String manufacturer = buf.readBytes(2).toString(StandardCharsets.US_ASCII);
buf.skipBytes(1); // delimiter
- int idLength = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) '*') - buf.readerIndex();
- String id = buf.readBytes(idLength).toString(StandardCharsets.US_ASCII);
+ int idIndex = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) '*');
+ String id = buf.readBytes(idIndex - buf.readerIndex()).toString(StandardCharsets.US_ASCII);
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, id);
if (deviceSession == null) {
return null;
@@ -181,7 +181,9 @@ public class WatchProtocolDecoder extends BaseProtocolDecoder {
buf.skipBytes(1); // delimiter
String index = null;
- if (idLength > 10) {
+ int contentIndex = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) '*');
+ if (contentIndex + 5 < buf.writerIndex() && buf.getByte(contentIndex + 5) == '*'
+ && buf.toString(contentIndex + 1, 4, StandardCharsets.US_ASCII).matches("\\p{XDigit}+")) {
int indexLength = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) '*') - buf.readerIndex();
index = buf.readBytes(indexLength).toString(StandardCharsets.US_ASCII);
buf.skipBytes(1); // delimiter
@@ -192,7 +194,7 @@ public class WatchProtocolDecoder extends BaseProtocolDecoder {
buf.writerIndex(buf.writerIndex() - 1); // ignore ending
- int contentIndex = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) ',');
+ contentIndex = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) ',');
if (contentIndex < 0) {
contentIndex = buf.writerIndex();
}