Commit d5625354feb7fe1fc60f8b64bec841b9f53e9abd

Authored by Wiebe Cazemier
1 parent 52efbdc7

Publish argument is now const again

mqttpacket.cpp
@@ -61,7 +61,7 @@ std::shared_ptr<MqttPacket> MqttPacket::getCopy(char new_max_qos) const @@ -61,7 +61,7 @@ std::shared_ptr<MqttPacket> MqttPacket::getCopy(char new_max_qos) const
61 // has to do with the Session::writePacket() and Session::sendPendingQosMessages() logic. 61 // has to do with the Session::writePacket() and Session::sendPendingQosMessages() logic.
62 assert((first_byte & 0b00001000) == 0); 62 assert((first_byte & 0b00001000) == 0);
63 63
64 - if (publish.qos > 0 && new_max_qos == 0) 64 + if (publishData.qos > 0 && new_max_qos == 0)
65 { 65 {
66 // if shrinking the packet doesn't alter the amount of bytes in the 'remaining length' part of the header, we can 66 // if shrinking the packet doesn't alter the amount of bytes in the 'remaining length' part of the header, we can
67 // just memmove+shrink the packet. This is because the packet id always is two bytes before the payload, so we just move the payload 67 // just memmove+shrink the packet. This is because the packet id always is two bytes before the payload, so we just move the payload
@@ -79,7 +79,7 @@ std::shared_ptr<MqttPacket> MqttPacket::getCopy(char new_max_qos) const @@ -79,7 +79,7 @@ std::shared_ptr<MqttPacket> MqttPacket::getCopy(char new_max_qos) const
79 std::memmove(&p->bites[packet_id_pos], &p->bites[packet_id_pos+2], payloadLen); 79 std::memmove(&p->bites[packet_id_pos], &p->bites[packet_id_pos+2], payloadLen);
80 p->bites.erase(p->bites.end() - 2, p->bites.end()); 80 p->bites.erase(p->bites.end() - 2, p->bites.end());
81 p->packet_id_pos = 0; 81 p->packet_id_pos = 0;
82 - p->publish.qos = 0; 82 + p->publishData.qos = 0;
83 p->payloadStart -= 2; 83 p->payloadStart -= 2;
84 if (pos > p->bites.size()) // pos can possible be set elsewhere, so we only set it back if it was after the payload. 84 if (pos > p->bites.size()) // pos can possible be set elsewhere, so we only set it back if it was after the payload.
85 p->pos -= 2; 85 p->pos -= 2;
@@ -97,7 +97,7 @@ std::shared_ptr<MqttPacket> MqttPacket::getCopy(char new_max_qos) const @@ -97,7 +97,7 @@ std::shared_ptr<MqttPacket> MqttPacket::getCopy(char new_max_qos) const
97 return p; 97 return p;
98 } 98 }
99 99
100 - Publish pub(publish.topic, getPayloadCopy(), new_max_qos); 100 + Publish pub(publishData.topic, getPayloadCopy(), new_max_qos);
101 pub.retain = getRetain(); 101 pub.retain = getRetain();
102 std::shared_ptr<MqttPacket> copyPacket(new MqttPacket(ProtocolVersion::Mqtt311, pub)); // TODO: don't hard-code the protocol version. 102 std::shared_ptr<MqttPacket> copyPacket(new MqttPacket(ProtocolVersion::Mqtt311, pub)); // TODO: don't hard-code the protocol version.
103 return copyPacket; 103 return copyPacket;
@@ -105,7 +105,7 @@ std::shared_ptr&lt;MqttPacket&gt; MqttPacket::getCopy(char new_max_qos) const @@ -105,7 +105,7 @@ std::shared_ptr&lt;MqttPacket&gt; MqttPacket::getCopy(char new_max_qos) const
105 105
106 std::shared_ptr<MqttPacket> copyPacket(new MqttPacket(*this)); 106 std::shared_ptr<MqttPacket> copyPacket(new MqttPacket(*this));
107 copyPacket->sender.reset(); 107 copyPacket->sender.reset();
108 - if (publish.qos != new_max_qos) 108 + if (publishData.qos != new_max_qos)
109 copyPacket->setQos(new_max_qos); 109 copyPacket->setQos(new_max_qos);
110 return copyPacket; 110 return copyPacket;
111 } 111 }
@@ -163,29 +163,29 @@ size_t MqttPacket::getRequiredSizeForPublish(const ProtocolVersion protocolVersi @@ -163,29 +163,29 @@ size_t MqttPacket::getRequiredSizeForPublish(const ProtocolVersion protocolVersi
163 return result; 163 return result;
164 } 164 }
165 165
166 -MqttPacket::MqttPacket(const ProtocolVersion protocolVersion, Publish &_publish) : 166 +MqttPacket::MqttPacket(const ProtocolVersion protocolVersion, const Publish &_publish) :
167 bites(getRequiredSizeForPublish(protocolVersion, _publish)) 167 bites(getRequiredSizeForPublish(protocolVersion, _publish))
168 { 168 {
169 - if (publish.topic.length() > 0xFFFF) 169 + if (publishData.topic.length() > 0xFFFF)
170 { 170 {
171 throw ProtocolError("Topic path too long."); 171 throw ProtocolError("Topic path too long.");
172 } 172 }
173 173
174 this->protocolVersion = protocolVersion; 174 this->protocolVersion = protocolVersion;
175 175
176 - this->publish.topic = _publish.topic;  
177 - splitTopic(this->publish.topic, this->publish.subtopics); // TODO: I think I can make this conditional, because the (planned) use will already have used the subtopics. 176 + this->publishData.topic = _publish.topic;
  177 + splitTopic(this->publishData.topic, this->publishData.subtopics); // TODO: I think I can make this conditional, because the (planned) use will already have used the subtopics.
178 178
179 packetType = PacketType::PUBLISH; 179 packetType = PacketType::PUBLISH;
180 - this->publish.qos = _publish.qos; 180 + this->publishData.qos = _publish.qos;
181 first_byte = static_cast<char>(packetType) << 4; 181 first_byte = static_cast<char>(packetType) << 4;
182 first_byte |= (_publish.qos << 1); 182 first_byte |= (_publish.qos << 1);
183 first_byte |= (static_cast<char>(_publish.retain) & 0b00000001); 183 first_byte |= (static_cast<char>(_publish.retain) & 0b00000001);
184 184
185 - writeUint16(publish.topic.length());  
186 - writeBytes(publish.topic.c_str(), publish.topic.length()); 185 + writeUint16(publishData.topic.length());
  186 + writeBytes(publishData.topic.c_str(), publishData.topic.length());
187 187
188 - if (publish.qos) 188 + if (publishData.qos)
189 { 189 {
190 // Reserve the space for the packet id, which will be assigned later. 190 // Reserve the space for the packet id, which will be assigned later.
191 packet_id_pos = pos; 191 packet_id_pos = pos;
@@ -769,22 +769,22 @@ void MqttPacket::handlePublish() @@ -769,22 +769,22 @@ void MqttPacket::handlePublish()
769 769
770 if (qos > 2) 770 if (qos > 2)
771 throw ProtocolError("QoS 3 is a protocol violation."); 771 throw ProtocolError("QoS 3 is a protocol violation.");
772 - this->publish.qos = qos; 772 + this->publishData.qos = qos;
773 773
774 if (qos == 0 && dup) 774 if (qos == 0 && dup)
775 throw ProtocolError("Duplicate flag is set for QoS 0 packet. This is illegal."); 775 throw ProtocolError("Duplicate flag is set for QoS 0 packet. This is illegal.");
776 776
777 - publish.topic = std::string(readBytes(variable_header_length), variable_header_length);  
778 - splitTopic(publish.topic, publish.subtopics); 777 + publishData.topic = std::string(readBytes(variable_header_length), variable_header_length);
  778 + splitTopic(publishData.topic, publishData.subtopics);
779 779
780 - if (!isValidUtf8(publish.topic, true)) 780 + if (!isValidUtf8(publishData.topic, true))
781 { 781 {
782 logger->logf(LOG_WARNING, "Client '%s' published a message with invalid UTF8 or $/+/# in it. Dropping.", sender->repr().c_str()); 782 logger->logf(LOG_WARNING, "Client '%s' published a message with invalid UTF8 or $/+/# in it. Dropping.", sender->repr().c_str());
783 return; 783 return;
784 } 784 }
785 785
786 #ifndef NDEBUG 786 #ifndef NDEBUG
787 - logger->logf(LOG_DEBUG, "Publish received, topic '%s'. QoS=%d. Retain=%d, dup=%d", publish.topic.c_str(), qos, retain, dup); 787 + logger->logf(LOG_DEBUG, "Publish received, topic '%s'. QoS=%d. Retain=%d, dup=%d", publishData.topic.c_str(), qos, retain, dup);
788 #endif 788 #endif
789 789
790 sender->getThreadData()->incrementReceivedMessageCount(); 790 sender->getThreadData()->incrementReceivedMessageCount();
@@ -831,23 +831,23 @@ void MqttPacket::handlePublish() @@ -831,23 +831,23 @@ void MqttPacket::handlePublish()
831 while (pos < prop_end_at) 831 while (pos < prop_end_at)
832 { 832 {
833 const Mqtt5Properties prop = static_cast<Mqtt5Properties>(readByte()); 833 const Mqtt5Properties prop = static_cast<Mqtt5Properties>(readByte());
834 - publish.propertyBuilder = std::make_shared<Mqtt5PropertyBuilder>(); 834 + publishData.propertyBuilder = std::make_shared<Mqtt5PropertyBuilder>();
835 835
836 switch (prop) 836 switch (prop)
837 { 837 {
838 case Mqtt5Properties::PayloadFormatIndicator: 838 case Mqtt5Properties::PayloadFormatIndicator:
839 - publish.propertyBuilder->writePayloadFormatIndicator(readByte()); 839 + publishData.propertyBuilder->writePayloadFormatIndicator(readByte());
840 break; 840 break;
841 case Mqtt5Properties::MessageExpiryInterval: 841 case Mqtt5Properties::MessageExpiryInterval:
842 - publish.createdAt = std::chrono::steady_clock::now();  
843 - publish.expiresAfter = std::chrono::seconds(readFourBytesToUint32()); 842 + publishData.createdAt = std::chrono::steady_clock::now();
  843 + publishData.expiresAfter = std::chrono::seconds(readFourBytesToUint32());
844 case Mqtt5Properties::TopicAlias: 844 case Mqtt5Properties::TopicAlias:
845 break; 845 break;
846 case Mqtt5Properties::ResponseTopic: 846 case Mqtt5Properties::ResponseTopic:
847 { 847 {
848 const uint16_t len = readTwoBytesToUInt16(); 848 const uint16_t len = readTwoBytesToUInt16();
849 const std::string responseTopic(readBytes(len), len); 849 const std::string responseTopic(readBytes(len), len);
850 - publish.propertyBuilder->writeResponseTopic(responseTopic); 850 + publishData.propertyBuilder->writeResponseTopic(responseTopic);
851 break; 851 break;
852 } 852 }
853 case Mqtt5Properties::CorrelationData: 853 case Mqtt5Properties::CorrelationData:
@@ -860,7 +860,7 @@ void MqttPacket::handlePublish() @@ -860,7 +860,7 @@ void MqttPacket::handlePublish()
860 { 860 {
861 const uint16_t len = readTwoBytesToUInt16(); 861 const uint16_t len = readTwoBytesToUInt16();
862 const std::string contentType(readBytes(len), len); 862 const std::string contentType(readBytes(len), len);
863 - publish.propertyBuilder->writeContentType(contentType); 863 + publishData.propertyBuilder->writeContentType(contentType);
864 break; 864 break;
865 } 865 }
866 default: 866 default:
@@ -873,12 +873,12 @@ void MqttPacket::handlePublish() @@ -873,12 +873,12 @@ void MqttPacket::handlePublish()
873 payloadStart = pos; 873 payloadStart = pos;
874 874
875 Authentication &authentication = *ThreadGlobals::getAuth(); 875 Authentication &authentication = *ThreadGlobals::getAuth();
876 - if (authentication.aclCheck(sender->getClientId(), sender->getUsername(), publish.topic, publish.subtopics, AclAccess::write, qos, retain) == AuthResult::success) 876 + if (authentication.aclCheck(sender->getClientId(), sender->getUsername(), publishData.topic, publishData.subtopics, AclAccess::write, qos, retain) == AuthResult::success)
877 { 877 {
878 if (retain) 878 if (retain)
879 { 879 {
880 std::string payload(readBytes(payloadLen), payloadLen); 880 std::string payload(readBytes(payloadLen), payloadLen);
881 - sender->getThreadData()->getSubscriptionStore()->setRetainedMessage(publish.topic, publish.subtopics, payload, qos); 881 + sender->getThreadData()->getSubscriptionStore()->setRetainedMessage(publishData.topic, publishData.subtopics, payload, qos);
882 } 882 }
883 883
884 // Set dup flag to 0, because that must not be propagated [MQTT-3.3.1-3]. 884 // Set dup flag to 0, because that must not be propagated [MQTT-3.3.1-3].
@@ -948,7 +948,7 @@ void MqttPacket::setPacketId(uint16_t packet_id) @@ -948,7 +948,7 @@ void MqttPacket::setPacketId(uint16_t packet_id)
948 assert(fixed_header_length == 0 || first_byte == bites[0]); 948 assert(fixed_header_length == 0 || first_byte == bites[0]);
949 assert(packet_id_pos > 0); 949 assert(packet_id_pos > 0);
950 assert(packetType == PacketType::PUBLISH); 950 assert(packetType == PacketType::PUBLISH);
951 - assert(publish.qos > 0); 951 + assert(publishData.qos > 0);
952 952
953 this->packet_id = packet_id; 953 this->packet_id = packet_id;
954 pos = packet_id_pos; 954 pos = packet_id_pos;
@@ -957,7 +957,7 @@ void MqttPacket::setPacketId(uint16_t packet_id) @@ -957,7 +957,7 @@ void MqttPacket::setPacketId(uint16_t packet_id)
957 957
958 uint16_t MqttPacket::getPacketId() const 958 uint16_t MqttPacket::getPacketId() const
959 { 959 {
960 - assert(publish.qos > 0); 960 + assert(publishData.qos > 0);
961 return packet_id; 961 return packet_id;
962 } 962 }
963 963
@@ -965,7 +965,7 @@ uint16_t MqttPacket::getPacketId() const @@ -965,7 +965,7 @@ uint16_t MqttPacket::getPacketId() const
965 void MqttPacket::setDuplicate() 965 void MqttPacket::setDuplicate()
966 { 966 {
967 assert(packetType == PacketType::PUBLISH); 967 assert(packetType == PacketType::PUBLISH);
968 - assert(publish.qos > 0); 968 + assert(publishData.qos > 0);
969 assert(fixed_header_length == 0 || first_byte == bites[0]); 969 assert(fixed_header_length == 0 || first_byte == bites[0]);
970 970
971 first_byte |= 0b00001000; 971 first_byte |= 0b00001000;
@@ -1010,12 +1010,12 @@ size_t MqttPacket::getSizeIncludingNonPresentHeader() const @@ -1010,12 +1010,12 @@ size_t MqttPacket::getSizeIncludingNonPresentHeader() const
1010 void MqttPacket::setQos(const char new_qos) 1010 void MqttPacket::setQos(const char new_qos)
1011 { 1011 {
1012 // You can't change to a QoS level that would remove the packet identifier. 1012 // You can't change to a QoS level that would remove the packet identifier.
1013 - assert((publish.qos == 0 && new_qos == 0) || (publish.qos > 0 && new_qos > 0)); 1013 + assert((publishData.qos == 0 && new_qos == 0) || (publishData.qos > 0 && new_qos > 0));
1014 assert(new_qos > 0 && packet_id_pos > 0); 1014 assert(new_qos > 0 && packet_id_pos > 0);
1015 1015
1016 - publish.qos = new_qos; 1016 + publishData.qos = new_qos;
1017 first_byte &= 0b11111001; 1017 first_byte &= 0b11111001;
1018 - first_byte |= (publish.qos << 1); 1018 + first_byte |= (publishData.qos << 1);
1019 1019
1020 if (fixed_header_length > 0) 1020 if (fixed_header_length > 0)
1021 { 1021 {
@@ -1026,7 +1026,7 @@ void MqttPacket::setQos(const char new_qos) @@ -1026,7 +1026,7 @@ void MqttPacket::setQos(const char new_qos)
1026 1026
1027 const std::string &MqttPacket::getTopic() const 1027 const std::string &MqttPacket::getTopic() const
1028 { 1028 {
1029 - return this->publish.topic; 1029 + return this->publishData.topic;
1030 } 1030 }
1031 1031
1032 /** 1032 /**
@@ -1035,7 +1035,7 @@ const std::string &amp;MqttPacket::getTopic() const @@ -1035,7 +1035,7 @@ const std::string &amp;MqttPacket::getTopic() const
1035 */ 1035 */
1036 const std::vector<std::string> &MqttPacket::getSubtopics() const 1036 const std::vector<std::string> &MqttPacket::getSubtopics() const
1037 { 1037 {
1038 - return this->publish.subtopics; 1038 + return this->publishData.subtopics;
1039 } 1039 }
1040 1040
1041 1041
@@ -1200,15 +1200,15 @@ void MqttPacket::setRetain() @@ -1200,15 +1200,15 @@ void MqttPacket::setRetain()
1200 1200
1201 Publish *MqttPacket::getPublish() 1201 Publish *MqttPacket::getPublish()
1202 { 1202 {
1203 - if (payloadLen > 0 && publish.payload.empty())  
1204 - publish.payload = getPayloadCopy(); 1203 + if (payloadLen > 0 && publishData.payload.empty())
  1204 + publishData.payload = getPayloadCopy();
1205 1205
1206 - return &publish; 1206 + return &publishData;
1207 } 1207 }
1208 1208
1209 void MqttPacket::readIntoBuf(CirBuf &buf) const 1209 void MqttPacket::readIntoBuf(CirBuf &buf) const
1210 { 1210 {
1211 - assert(packetType != PacketType::PUBLISH || (first_byte & 0b00000110) >> 1 == publish.qos); 1211 + assert(packetType != PacketType::PUBLISH || (first_byte & 0b00000110) >> 1 == publishData.qos);
1212 1212
1213 buf.ensureFreeSpace(getSizeIncludingNonPresentHeader()); 1213 buf.ensureFreeSpace(getSizeIncludingNonPresentHeader());
1214 1214
mqttpacket.h
@@ -43,7 +43,7 @@ class MqttPacket @@ -43,7 +43,7 @@ class MqttPacket
43 #endif 43 #endif
44 44
45 std::vector<char> bites; 45 std::vector<char> bites;
46 - Publish publish; 46 + Publish publishData;
47 size_t fixed_header_length = 0; // if 0, this packet does not contain the bytes of the fixed header. 47 size_t fixed_header_length = 0; // if 0, this packet does not contain the bytes of the fixed header.
48 VariableByteInt remainingLength; 48 VariableByteInt remainingLength;
49 std::shared_ptr<Client> sender; 49 std::shared_ptr<Client> sender;
@@ -80,13 +80,13 @@ public: @@ -80,13 +80,13 @@ public:
80 80
81 std::shared_ptr<MqttPacket> getCopy(char new_max_qos) const; 81 std::shared_ptr<MqttPacket> getCopy(char new_max_qos) const;
82 82
83 - size_t getRequiredSizeForPublish(const ProtocolVersion protocolVersion, const Publish &publish) const; 83 + size_t getRequiredSizeForPublish(const ProtocolVersion protocolVersion, const Publish &publishData) const;
84 84
85 // Constructor for outgoing packets. These may not allocate room for the fixed header, because we don't (always) know the length in advance. 85 // Constructor for outgoing packets. These may not allocate room for the fixed header, because we don't (always) know the length in advance.
86 MqttPacket(const ConnAck &connAck); 86 MqttPacket(const ConnAck &connAck);
87 MqttPacket(const SubAck &subAck); 87 MqttPacket(const SubAck &subAck);
88 MqttPacket(const UnsubAck &unsubAck); 88 MqttPacket(const UnsubAck &unsubAck);
89 - MqttPacket(const ProtocolVersion protocolVersion, Publish &_publish); 89 + MqttPacket(const ProtocolVersion protocolVersion, const Publish &_publish);
90 MqttPacket(const PubAck &pubAck); 90 MqttPacket(const PubAck &pubAck);
91 MqttPacket(const PubRec &pubRec); 91 MqttPacket(const PubRec &pubRec);
92 MqttPacket(const PubComp &pubComp); 92 MqttPacket(const PubComp &pubComp);
@@ -108,7 +108,7 @@ public: @@ -108,7 +108,7 @@ public:
108 108
109 size_t getSizeIncludingNonPresentHeader() const; 109 size_t getSizeIncludingNonPresentHeader() const;
110 const std::vector<char> &getBites() const { return bites; } 110 const std::vector<char> &getBites() const { return bites; }
111 - char getQos() const { return publish.qos; } 111 + char getQos() const { return publishData.qos; }
112 void setQos(const char new_qos); 112 void setQos(const char new_qos);
113 ProtocolVersion getProtocolVersion() const { return protocolVersion;} 113 ProtocolVersion getProtocolVersion() const { return protocolVersion;}
114 const std::string &getTopic() const; 114 const std::string &getTopic() const;
qospacketqueue.cpp
@@ -16,7 +16,7 @@ uint16_t QueuedPublish::getPacketId() const @@ -16,7 +16,7 @@ uint16_t QueuedPublish::getPacketId() const
16 return this->packet_id; 16 return this->packet_id;
17 } 17 }
18 18
19 -Publish &QueuedPublish::getPublish() 19 +const Publish &QueuedPublish::getPublish() const
20 { 20 {
21 return publish; 21 return publish;
22 } 22 }
@@ -79,12 +79,12 @@ void QoSPublishQueue::queuePublish(Publish &amp;&amp;pub, uint16_t id) @@ -79,12 +79,12 @@ void QoSPublishQueue::queuePublish(Publish &amp;&amp;pub, uint16_t id)
79 qosQueueBytes += queue.back().getApproximateMemoryFootprint(); 79 qosQueueBytes += queue.back().getApproximateMemoryFootprint();
80 } 80 }
81 81
82 -std::list<QueuedPublish>::iterator QoSPublishQueue::begin() 82 +std::list<QueuedPublish>::const_iterator QoSPublishQueue::begin() const
83 { 83 {
84 return queue.begin(); 84 return queue.begin();
85 } 85 }
86 86
87 -std::list<QueuedPublish>::iterator QoSPublishQueue::end() 87 +std::list<QueuedPublish>::const_iterator QoSPublishQueue::end() const
88 { 88 {
89 return queue.end(); 89 return queue.end();
90 } 90 }
qospacketqueue.h
@@ -21,7 +21,7 @@ public: @@ -21,7 +21,7 @@ public:
21 21
22 size_t getApproximateMemoryFootprint() const; 22 size_t getApproximateMemoryFootprint() const;
23 uint16_t getPacketId() const; 23 uint16_t getPacketId() const;
24 - Publish &getPublish(); 24 + const Publish &getPublish() const;
25 }; 25 };
26 26
27 class QoSPublishQueue 27 class QoSPublishQueue
@@ -36,8 +36,8 @@ public: @@ -36,8 +36,8 @@ public:
36 void queuePublish(PublishCopyFactory &copyFactory, uint16_t id, char new_max_qos); 36 void queuePublish(PublishCopyFactory &copyFactory, uint16_t id, char new_max_qos);
37 void queuePublish(Publish &&pub, uint16_t id); 37 void queuePublish(Publish &&pub, uint16_t id);
38 38
39 - std::list<QueuedPublish>::iterator begin();  
40 - std::list<QueuedPublish>::iterator end(); 39 + std::list<QueuedPublish>::const_iterator begin() const;
  40 + std::list<QueuedPublish>::const_iterator end() const;
41 }; 41 };
42 42
43 #endif // QOSPACKETQUEUE_H 43 #endif // QOSPACKETQUEUE_H
session.cpp
@@ -257,7 +257,7 @@ uint64_t Session::sendPendingQosMessages() @@ -257,7 +257,7 @@ uint64_t Session::sendPendingQosMessages()
257 if (c) 257 if (c)
258 { 258 {
259 std::lock_guard<std::mutex> locker(qosQueueMutex); 259 std::lock_guard<std::mutex> locker(qosQueueMutex);
260 - for (QueuedPublish &queuedPublish : qosPacketQueue) 260 + for (const QueuedPublish &queuedPublish : qosPacketQueue)
261 { 261 {
262 MqttPacket p(c->getProtocolVersion(), queuedPublish.getPublish()); 262 MqttPacket p(c->getProtocolVersion(), queuedPublish.getPublish());
263 p.setDuplicate(); 263 p.setDuplicate();
sessionsandsubscriptionsdb.cpp
@@ -215,9 +215,9 @@ void SessionsAndSubscriptionsDB::saveData(const std::vector&lt;std::unique_ptr&lt;Sess @@ -215,9 +215,9 @@ void SessionsAndSubscriptionsDB::saveData(const std::vector&lt;std::unique_ptr&lt;Sess
215 size_t qosPacketsCounted = 0; 215 size_t qosPacketsCounted = 0;
216 writeUint32(qosPacketsExpected); 216 writeUint32(qosPacketsExpected);
217 217
218 - for (QueuedPublish &p: ses->qosPacketQueue) 218 + for (const QueuedPublish &p: ses->qosPacketQueue)
219 { 219 {
220 - Publish &pub = p.getPublish(); 220 + const Publish &pub = p.getPublish();
221 221
222 logger->logf(LOG_DEBUG, "Saving QoS %d message for topic '%s'.", pub.qos, pub.topic.c_str()); 222 logger->logf(LOG_DEBUG, "Saving QoS %d message for topic '%s'.", pub.qos, pub.topic.c_str());
223 223