Skip to content

Commit 511c7e0

Browse files
committed
Fix f-2751 V5 client use server connack props
1 parent e691614 commit 511c7e0

1 file changed

Lines changed: 35 additions & 2 deletions

File tree

src/mqtt_client.c

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,34 @@ int MqttClient_RespList_Find(MqttClient *client,
535535
#endif /* WOLFMQTT_MULTITHREAD */
536536

537537
#ifdef WOLFMQTT_V5
538+
/* Populate client fields from CONNACK server properties so that the
539+
* publish/packet-size guards are effective without requiring the
540+
* application to register a property callback. */
541+
static void Handle_ConnectAck_Props(MqttClient* client, MqttProp* props)
542+
{
543+
MqttProp* prop;
544+
545+
for (prop = props; prop != NULL; prop = prop->next) {
546+
if (prop->type == MQTT_PROP_MAX_QOS) {
547+
client->max_qos = prop->data_byte;
548+
}
549+
else if (prop->type == MQTT_PROP_RETAIN_AVAIL) {
550+
client->retain_avail = prop->data_byte;
551+
}
552+
else if (prop->type == MQTT_PROP_MAX_PACKET_SZ) {
553+
if ((prop->data_int > 0) &&
554+
(prop->data_int <= MQTT_PACKET_SZ_MAX)) {
555+
/* Honor the smaller of the client's existing cap
556+
* (0 means unset) and the server's limit. */
557+
if ((client->packet_sz_max == 0) ||
558+
(prop->data_int < client->packet_sz_max)) {
559+
client->packet_sz_max = prop->data_int;
560+
}
561+
}
562+
}
563+
}
564+
}
565+
538566
static int Handle_Props(MqttClient* client, MqttProp* props, byte use_cb,
539567
byte free_props)
540568
{
@@ -624,8 +652,13 @@ static int MqttClient_DecodePacket(MqttClient* client, byte* rx_buf,
624652
rc = MqttDecode_ConnectAck(rx_buf, rx_len, p_connect_ack);
625653
#ifdef WOLFMQTT_V5
626654
if (rc >= 0 && doProps) {
627-
int tmp = Handle_Props(client, p_connect_ack->props,
628-
(packet_obj != NULL), 1);
655+
int tmp;
656+
/* Auto-populate server property fields so that publish and
657+
* packet-size guards are effective even when the
658+
* application has not registered a property callback. */
659+
Handle_ConnectAck_Props(client, p_connect_ack->props);
660+
tmp = Handle_Props(client, p_connect_ack->props,
661+
(packet_obj != NULL), 1);
629662
p_connect_ack->props = NULL;
630663
if (tmp != MQTT_CODE_SUCCESS) {
631664
rc = tmp;

0 commit comments

Comments
 (0)