Skip to content

Commit fc813ab

Browse files
committed
Add support for publishing retained messages
1 parent af597ab commit fc813ab

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

include/mqtt.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,8 @@ int __cheri_compartment("MQTT") mqtt_publish(Timeout *t,
170170
const char *topic,
171171
size_t topicLength,
172172
const void *payload,
173-
size_t payloadLength);
173+
size_t payloadLength,
174+
bool retain = false);
174175

175176
/**
176177
* Subscribe on a given MQTT connection.

lib/mqtt/mqtt.cc

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -469,12 +469,15 @@ namespace
469469
"are not set.");
470470

471471
// The payload and topic are only valid within the
472-
// context of the callback: make them read-only and
473-
// non-capturable.
472+
// context of the callback: make them read-only,
473+
// non-capturable, and limits to the length of the
474+
// topic and payload.
474475
Capability topic{publishInfo->pTopicName};
475476
Capability payload{publishInfo->pPayload};
476477
topic.permissions() &= CHERI::Permission::Load;
478+
topic.bounds() = publishInfo->topicNameLength;
477479
payload.permissions() &= CHERI::Permission::Load;
480+
payload.bounds() = publishInfo->payloadLength;
478481

479482
publishCallback(topic,
480483
publishInfo->topicNameLength,
@@ -815,7 +818,8 @@ int mqtt_publish(Timeout *t,
815818
const char *topic,
816819
size_t topicLength,
817820
const void *payload,
818-
size_t payloadLength)
821+
size_t payloadLength,
822+
bool retain)
819823
{
820824
if (!CHERI::check_pointer(topic, topicLength))
821825
{
@@ -872,6 +876,7 @@ int mqtt_publish(Timeout *t,
872876
publishInfo.topicNameLength = topicLength;
873877
publishInfo.pPayload = payload;
874878
publishInfo.payloadLength = payloadLength;
879+
publishInfo.retain = retain;
875880

876881
// Packet ID is needed for QoS > 0.
877882
int packetId = MQTT_GetPacketId(coreMQTTContext);

0 commit comments

Comments
 (0)