Skip to content

Commit

Permalink
Attempt to fix Windows build with C++20 standard.
Browse files Browse the repository at this point in the history
  • Loading branch information
arobenko committed Dec 5, 2023
1 parent 306ac04 commit 2a52615
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 48 deletions.
86 changes: 38 additions & 48 deletions client/src/op/ConnectOp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -757,27 +757,27 @@ void ConnectOp::handle(AuthMsg& msg)
{
m_timer.cancel();

auto protocolErrorCompletion =
[this](DisconnectReason reason = DisconnectReason::ProtocolError)
{
sendDisconnectWithReason(reason);
completeOpInternal(CC_Mqtt5AsyncOpStatus_ProtocolError);
};
auto disconnectReason = DisconnectReason::ProtocolError;
auto opStatus = CC_Mqtt5AsyncOpStatus_ProtocolError;
auto disconnectAndCompleteOnError =
comms::util::makeScopeGuard(
[this, &disconnectReason, &opStatus]()
{
sendDisconnectWithReason(disconnectReason);
completeOpInternal(opStatus);
});

if (!msg.doValid()) {
errorLog("Invalid flags received in AUTH message");
protocolErrorCompletion(DisconnectReason::MalformedPacket);
// No members access after this point, the op will be deleted
return;
disconnectReason = DisconnectReason::MalformedPacket;
return; // Disconnect is sent and op is competed
}

if ((m_authMethod.empty()) ||
(msg.field_reasonCode().isMissing()) ||
(msg.field_reasonCode().field().value() != AuthMsg::Field_reasonCode::Field::ValueType::ContinueAuth)) {
errorLog("Invalid reason code received received in AUTH message");
protocolErrorCompletion();
// No members access after this point, the op will be deleted
return;
return; // Disconnect is sent and op is competed
}

UserPropsList userProps; // Will be referenced in inInfo
Expand All @@ -791,16 +791,12 @@ void ConnectOp::handle(AuthMsg& msg)
}

if (propsHandler.isProtocolError()) {
protocolErrorCompletion();
// No members access after this point, the op will be deleted
return;
return; // Disconnect is sent and op is competed
}

if ((propsHandler.m_authMethod == nullptr) ||
(m_authMethod != propsHandler.m_authMethod->field_value().value().c_str())) {
protocolErrorCompletion();
// No members access after this point, the op will be deleted
return;
return; // Disconnect is sent and op is competed
}

if (propsHandler.m_authData != nullptr) {
Expand All @@ -814,8 +810,7 @@ void ConnectOp::handle(AuthMsg& msg)
if (propsHandler.m_reasonStr != nullptr) {
if (!m_requestProblemInfo) {
errorLog("Received reason string in AUTH when \"problem information\" was disabled in CONNECT.");
protocolErrorCompletion();
return;
return; // Disconnect is sent and op is competed
}

inInfo.m_reasonStr = propsHandler.m_reasonStr->field_value().value().c_str();
Expand All @@ -825,8 +820,7 @@ void ConnectOp::handle(AuthMsg& msg)
if (!propsHandler.m_userProps.empty()) {
if (!m_requestProblemInfo) {
errorLog("Received user properties in AUTH when \"problem information\" was disabled in CONNECT.");
protocolErrorCompletion();
return;
return; // Disconnect is sent and op is competed
}


Expand All @@ -837,23 +831,19 @@ void ConnectOp::handle(AuthMsg& msg)
}
}

disconnectAndCompleteOnError.release(); // No more automatic disconnect and completion

auto outInfo = CC_Mqtt5AuthInfo();
auto authEc = m_authCb(m_authCbData, &inInfo, &outInfo);
if (authEc == CC_Mqtt5AuthErrorCode_Disconnect) {
sendDisconnectWithReason(DisconnectReason::NotAuthorized);
completeOpInternal(CC_Mqtt5AsyncOpStatus_Aborted);
// No members access after this point, the op will be deleted
return;
disconnectReason = DisconnectReason::NotAuthorized;
opStatus = CC_Mqtt5AsyncOpStatus_Aborted;
return; // Disconnect is sent and op is competed
}

auto termStatus = CC_Mqtt5AsyncOpStatus_OutOfMemory;
auto termConnectOnExit =
comms::util::makeScopeGuard(
[this, &termStatus]()
{
sendDisconnectWithReason(DisconnectReason::UnspecifiedError);
completeOpInternal(termStatus);
});
// Change the completion on error defaults
disconnectReason = DisconnectReason::UnspecifiedError;
opStatus = CC_Mqtt5AsyncOpStatus_OutOfMemory;

AuthMsg respMsg;
respMsg.field_reasonCode().setExists();
Expand All @@ -864,7 +854,7 @@ void ConnectOp::handle(AuthMsg& msg)
{
if (!canAddProp(propsField)) {
errorLog("Cannot add connect auth property, reached available limit.");
return;
return; // Disconnect is sent and op is competed
}

auto& propVar = addProp(propsField);
Expand All @@ -875,13 +865,13 @@ void ConnectOp::handle(AuthMsg& msg)

if (outInfo.m_authDataLen > 0U) {
if (outInfo.m_authData == nullptr) {
termStatus = CC_Mqtt5AsyncOpStatus_BadParam;
return;
opStatus = CC_Mqtt5AsyncOpStatus_BadParam;
return; // Disconnect is sent and op is competed
}

if (!canAddProp(propsField)) {
errorLog("Cannot add connect auth property, reached available limit.");
return;
return; // Disconnect is sent and op is competed
}

auto& propVar = addProp(propsField);
Expand All @@ -892,15 +882,15 @@ void ConnectOp::handle(AuthMsg& msg)
if (maxStringLen() < valueField.value().size()) {
errorLog("Auth data value is too long");
discardLastProp(propsField);
termStatus = CC_Mqtt5AsyncOpStatus_BadParam;
return;
opStatus = CC_Mqtt5AsyncOpStatus_BadParam;
return; // Disconnect is sent and op is competed
}
}

if (outInfo.m_reasonStr != nullptr) {
if (!canAddProp(propsField)) {
errorLog("Cannot add connect auth property, reached available limit.");
return;
return; // Disconnect is sent and op is competed
}

auto& propVar = addProp(propsField);
Expand All @@ -911,15 +901,15 @@ void ConnectOp::handle(AuthMsg& msg)
if (maxStringLen() < valueField.value().size()) {
errorLog("Reason string in CONNECT auth info too long");
discardLastProp(propsField);
termStatus = CC_Mqtt5AsyncOpStatus_BadParam;
return;
opStatus = CC_Mqtt5AsyncOpStatus_BadParam;
return; // Disconnect is sent and op is competed
}
}

if (outInfo.m_userPropsCount > 0U) {
if (outInfo.m_userProps == nullptr) {
termStatus = CC_Mqtt5AsyncOpStatus_BadParam;
return;
opStatus = CC_Mqtt5AsyncOpStatus_BadParam;
return; // Disconnect is sent and op is competed
}

for (auto idx = 0U; idx < outInfo.m_userPropsCount; ++idx) {
Expand All @@ -944,15 +934,15 @@ void ConnectOp::handle(AuthMsg& msg)
});

if (errorIter != std::end(Map)) {
termStatus = errorIter->second;
return;
opStatus = errorIter->second;
return; // Disconnect is sent and op is competed
}

COMMS_ASSERT(false); // Should not happen
}
}

termConnectOnExit.release();
disconnectAndCompleteOnError.release();
restartTimer();
client().sendMessage(respMsg);
}
Expand Down
8 changes: 8 additions & 0 deletions script/full_release_build_gcc12.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

export CC=gcc-12
export CXX=g++-12

SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
${SCRIPT_DIR}/full_release_build.sh "$@"

0 comments on commit 2a52615

Please sign in to comment.