Added check of reserved flags for PUBREL message
This commit is contained in:
@@ -15,6 +15,13 @@
|
||||
*/
|
||||
package org.dna.mqtt.moquette.parser.netty;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.handler.codec.CorruptedFrameException;
|
||||
import io.netty.util.AttributeMap;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.List;
|
||||
import org.dna.mqtt.moquette.proto.messages.AbstractMessage;
|
||||
import org.dna.mqtt.moquette.proto.messages.MessageIDMessage;
|
||||
import org.dna.mqtt.moquette.proto.messages.PubRelMessage;
|
||||
|
||||
@@ -22,11 +29,31 @@ import org.dna.mqtt.moquette.proto.messages.PubRelMessage;
|
||||
*
|
||||
* @author andrea
|
||||
*/
|
||||
class PubRelDecoder extends MessageIDDecoder {
|
||||
|
||||
class PubRelDecoder extends DemuxDecoder {
|
||||
|
||||
@Override
|
||||
protected MessageIDMessage createMessage() {
|
||||
return new PubRelMessage();
|
||||
void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws UnsupportedEncodingException {
|
||||
decode((AttributeMap)ctx, in, out);
|
||||
}
|
||||
|
||||
// @Override
|
||||
void decode(AttributeMap ctx, ByteBuf in, List<Object> out) throws UnsupportedEncodingException {
|
||||
in.resetReaderIndex();
|
||||
//Common decoding part
|
||||
MessageIDMessage message = new PubRelMessage();
|
||||
if (!decodeCommonHeader(message, in)) {
|
||||
in.resetReaderIndex();
|
||||
return;
|
||||
}
|
||||
|
||||
//if 3.1.1, check the flags (dup, retain and qos == 0)
|
||||
if (message.isDupFlag() || message.isRetainFlag() || message.getQos() != AbstractMessage.QOSType.LEAST_ONE) {
|
||||
throw new CorruptedFrameException("Received a PURREL with fixed header flags != b0010");
|
||||
}
|
||||
|
||||
//read messageIDs
|
||||
message.setMessageID(in.readUnsignedShort());
|
||||
out.add(message);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user