Bugfix: Some packets need fixed flags in header, missed that in the spec

This commit is contained in:
Johannes Schriewer 2018-07-30 02:54:37 +02:00
parent 05b939dfea
commit 31cf6d965d
3 changed files with 25 additions and 14 deletions

View file

@ -376,6 +376,17 @@ Buffer *make_buffer_for_header(size_t sz, MQTTControlPacketType type) {
Buffer *buffer = buffer_allocate(sz); Buffer *buffer = buffer_allocate(sz);
buffer->data[0] = type << 4; buffer->data[0] = type << 4;
// MQTT Spec means we should set a bit in the flags field for some packet types
switch (type) {
case PacketTypePubRel:
case PacketTypeSubscribe:
case PacketTypeUnsubscribe:
buffer->data[0] |= 0x02;
break;
default:
break;
}
buffer->position += 1; buffer->position += 1;
variable_length_int_encode(sz - 2, buffer); variable_length_int_encode(sz - 2, buffer);

View file

@ -299,7 +299,7 @@ TestResult test_decode_pubrec(void) {
TestResult test_decode_pubrel(void) { TestResult test_decode_pubrel(void) {
char data[] = { char data[] = {
0x60, 0x02, // header 0x62, 0x02, // header
0x00, 0x0a // packet id 0x00, 0x0a // packet id
}; };
Buffer *buffer = buffer_from_data_copy(data, sizeof(data)); Buffer *buffer = buffer_from_data_copy(data, sizeof(data));
@ -339,7 +339,7 @@ TestResult test_decode_pubcomp(void) {
TestResult test_decode_subscribe(void) { TestResult test_decode_subscribe(void) {
char data[] = { char data[] = {
0x80, 0x0f, // header 0x82, 0x0f, // header
0x00, 0x0a, // packet id 0x00, 0x0a, // packet id
0x00, 0x0a, 't', 'e', 's', 't', '/', 't', 'o', 'p', 'i', 'c', 0x00, 0x0a, 't', 'e', 's', 't', '/', 't', 'o', 'p', 'i', 'c',
0x01 // qos 0x01 // qos
@ -385,7 +385,7 @@ TestResult test_decode_suback(void) {
TestResult test_decode_unsubscribe(void) { TestResult test_decode_unsubscribe(void) {
char data[] = { char data[] = {
0xa0, 0x0e, // header 0xa2, 0x0e, // header
0x00, 0x0a, // packet id 0x00, 0x0a, // packet id
0x00, 0x0a, 't', 'e', 's', 't', '/', 't', 'o', 'p', 'i', 'c', 0x00, 0x0a, 't', 'e', 's', 't', '/', 't', 'o', 'p', 'i', 'c',
}; };

View file

@ -337,7 +337,7 @@ TestResult test_encode_pubrec(void) {
TestResult test_encode_pubrel(void) { TestResult test_encode_pubrel(void) {
char data[] = { char data[] = {
0x60, 0x02, // header 0x62, 0x02, // header
0x00, 0x0a // packet id 0x00, 0x0a // packet id
}; };
PubRelPayload *payload = calloc(1, sizeof(PubRelPayload)); PubRelPayload *payload = calloc(1, sizeof(PubRelPayload));
@ -373,7 +373,7 @@ TestResult test_encode_pubcomp(void) {
TestResult test_encode_subscribe(void) { TestResult test_encode_subscribe(void) {
char data[] = { char data[] = {
0x80, 0x0f, // header 0x82, 0x0f, // header
0x00, 0x0a, // packet id 0x00, 0x0a, // packet id
0x00, 0x0a, 't', 'e', 's', 't', '/', 't', 'o', 'p', 'i', 'c', 0x00, 0x0a, 't', 'e', 's', 't', '/', 't', 'o', 'p', 'i', 'c',
0x01 // qos 0x01 // qos
@ -415,7 +415,7 @@ TestResult test_encode_suback(void) {
TestResult test_encode_unsubscribe(void) { TestResult test_encode_unsubscribe(void) {
char data[] = { char data[] = {
0xa0, 0x0e, // header 0xa2, 0x0e, // header
0x00, 0x0a, // packet id 0x00, 0x0a, // packet id
0x00, 0x0a, 't', 'e', 's', 't', '/', 't', 'o', 'p', 'i', 'c', 0x00, 0x0a, 't', 'e', 's', 't', '/', 't', 'o', 'p', 'i', 'c',
}; };