Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MQTT v3.1 support #605

Merged
merged 5 commits into from
Jul 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions src/sp/protocol/mqtt/mqtt_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@

if (!str)
return ERR_INVAL;
if (len > 65536)
if (len > 65535)
return ERR_INVAL;

for (i = 0; i < (int) len; i++) {
Expand Down Expand Up @@ -564,7 +564,7 @@
// remaining length
len = (uint32_t) get_var_integer(packet + pos, &len_of_var);
pos += len_of_var;
log_trace("fix header length: %d", len_of_str);
log_trace("remaining length: %d", len);
// protocol name
cparam->pro_name.body =
(char *) copyn_utf8_str(packet, &pos, &len_of_str, max - pos);
Expand All @@ -578,6 +578,7 @@
log_trace("pro_name: %s", cparam->pro_name.body);
// protocol ver
cparam->pro_ver = packet[pos];
log_trace("pro_ver: %d", cparam->pro_ver);
pos++;
// connect flag
cparam->con_flag = packet[pos];
Expand All @@ -587,7 +588,8 @@
cparam->will_retain = (cparam->con_flag & 0x20) >> 5;
log_trace("conn flag:%x", cparam->con_flag);
if ((cparam->will_flag == 1 && cparam->will_qos > 2) ||
strncmp(cparam->pro_name.body, "MQTT", 4) != 0 ||
(strncmp(cparam->pro_name.body, MQTT_PROTOCOL_NAME, 4) != 0 &&
strncmp(cparam->pro_name.body, MQTT_PROTOCOL_NAME_v31, 6) != 0) ||

Check warning on line 592 in src/sp/protocol/mqtt/mqtt_parser.c

View check run for this annotation

Codecov / codecov/patch

src/sp/protocol/mqtt/mqtt_parser.c#L591-L592

Added lines #L591 - L592 were not covered by tests
cparam->pro_ver > 5 || cparam->pro_ver < 3)
return PROTOCOL_ERROR;
pos++;
Expand Down Expand Up @@ -633,6 +635,9 @@
cparam->assignedid = true;
} else if (len_of_str < 0) {
return (PROTOCOL_ERROR);
} else if (cparam->pro_ver == MQTT_PROTOCOL_VERSION_v31 &&
len_of_str > 23) {
return (CLIENT_IDENTIFIER_NOT_VALID);

Check warning on line 640 in src/sp/protocol/mqtt/mqtt_parser.c

View check run for this annotation

Codecov / codecov/patch

src/sp/protocol/mqtt/mqtt_parser.c#L638-L640

Added lines #L638 - L640 were not covered by tests
}
log_trace("clientid: [%s] [%d]", cparam->clientid.body, len_of_str);
log_trace("pos after clientid: [%d]", pos);
Expand Down
4 changes: 4 additions & 0 deletions src/sp/transport/mqtt/broker_tcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,8 @@
nmq_pipe_send_start_v4(p, msg, txaio);
else if (p->pro_ver == 5)
nmq_pipe_send_start_v5(p, msg, txaio);
else if (p->pro_ver == 3)
nmq_pipe_send_start_v4(p, msg, txaio);

Check warning on line 548 in src/sp/transport/mqtt/broker_tcp.c

View check run for this annotation

Codecov / codecov/patch

src/sp/transport/mqtt/broker_tcp.c#L547-L548

Added lines #L547 - L548 were not covered by tests
else {
log_error("msg with pro_ver that neither 4 nor 5 should not happened.");
nni_aio_finish_error(txaio, NNG_EPROTO);
Expand Down Expand Up @@ -1446,6 +1448,8 @@
nmq_pipe_send_start_v4(p, msg, aio);
} else if (p->pro_ver == 5) {
nmq_pipe_send_start_v5(p, msg, aio);
} else if (p->pro_ver == 3) {
nmq_pipe_send_start_v4(p, msg, aio);

Check warning on line 1452 in src/sp/transport/mqtt/broker_tcp.c

View check run for this annotation

Codecov / codecov/patch

src/sp/transport/mqtt/broker_tcp.c#L1451-L1452

Added lines #L1451 - L1452 were not covered by tests
} else {
nni_aio_finish_error(aio, NNG_EPROTO);
}
Expand Down
Loading