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

Add MQTT support for publishing retained messages #53

Merged
merged 4 commits into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 2 additions & 1 deletion include/mqtt.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,8 @@ int __cheri_compartment("MQTT") mqtt_publish(Timeout *t,
const char *topic,
size_t topicLength,
const void *payload,
size_t payloadLength);
size_t payloadLength,
bool retain = false);
hlef marked this conversation as resolved.
Show resolved Hide resolved

/**
* Subscribe on a given MQTT connection.
Expand Down
11 changes: 8 additions & 3 deletions lib/mqtt/mqtt.cc
Original file line number Diff line number Diff line change
Expand Up @@ -469,12 +469,15 @@ namespace
"are not set.");

// The payload and topic are only valid within the
// context of the callback: make them read-only and
// non-capturable.
// context of the callback: make them read-only,
// non-capturable, and limits to the length of the
// topic and payload.
Capability topic{publishInfo->pTopicName};
Capability payload{publishInfo->pPayload};
topic.permissions() &= CHERI::Permission::Load;
topic.bounds() = publishInfo->topicNameLength;
payload.permissions() &= CHERI::Permission::Load;
payload.bounds() = publishInfo->payloadLength;

publishCallback(topic,
publishInfo->topicNameLength,
Expand Down Expand Up @@ -815,7 +818,8 @@ int mqtt_publish(Timeout *t,
const char *topic,
size_t topicLength,
const void *payload,
size_t payloadLength)
size_t payloadLength,
bool retain)
{
if (!CHERI::check_pointer(topic, topicLength))
{
Expand Down Expand Up @@ -872,6 +876,7 @@ int mqtt_publish(Timeout *t,
publishInfo.topicNameLength = topicLength;
publishInfo.pPayload = payload;
publishInfo.payloadLength = payloadLength;
publishInfo.retain = retain;

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