Skip to content

Commit

Permalink
Release v0.5
Browse files Browse the repository at this point in the history
  • Loading branch information
arobenko committed Apr 27, 2024
2 parents 0953fd1 + da746df commit 84e275f
Show file tree
Hide file tree
Showing 62 changed files with 2,632 additions and 1,967 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ option (CC_MQTT5_CLIENT_LIB_FORCE_PIC "Force Position Independent Code (PIC) whe
option (CC_MQTT5_CLIENT_APPS "Build and install client applications" ${CC_MQTT5_CLIENT_DEFAULT_LIB})
option (CC_MQTT5_CLIENT_AFL_FUZZ "Build and install client AFL++ fuzzing application" OFF)
option (CC_MQTT5_WARN_AS_ERR "Treat warning as error" ON)
option (CC_MQTT5_USE_CCACHE "Use ccache on unix system" ON)
option (CC_MQTT5_USE_CCACHE "Use ccache" OFF)
option (CC_MQTT5_BUILD_UNIT_TESTS "Build unit tests" OFF)
option (CC_MQTT5_BUILD_INTEGRATION_TESTS "Build integration tests which require MQTT broker on local port 1883." OFF)
option (CC_MQTT5_WITH_DEFAULT_SANITIZERS "Build with sanitizers" OFF)
Expand All @@ -33,7 +33,7 @@ find_package(LibComms REQUIRED)
find_package(cc_mqtt5 REQUIRED)

include (${PROJECT_SOURCE_DIR}/cmake/Compile.cmake)
cc_mqttsn_compile ()
cc_mqtt5_compile ()

while (TRUE)
if ((NOT CC_MQTT5_BUILD_UNIT_TESTS) AND (NOT CC_MQTT5_BUILD_INTEGRATION_TESTS))
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Overview
This repository provides well documented and easy to use MQTT5 client library.
This repository provides well documented and easy to use MQTT v5 client library.
It is:

- single threaded
Expand All @@ -13,7 +13,7 @@ over the I/O link as well as perform extra manipulation on the exchanged
raw data (such as encryption or extra framing).

# Client Library
The MQTT5 **client** library is implemented
The MQTT v5 **client** library is implemented
using **C++(17)** programming language, but provides **C** interface. The library's
code doesn't use [RTTI](https://en.wikipedia.org/wiki/Run-time_type_information)
or exceptions, but by default
Expand Down Expand Up @@ -51,7 +51,7 @@ Detailed instructions on how to build and install all the components can be
found in [doc/BUILD.md](doc/BUILD.md) file.

# How to Fuzz Test
The provided MQTT5 client library as well as its dependencies from the
The provided MQTT v5 client library as well as its dependencies from the
[CommsChampion Ecosystem](https://commschamp.github.io/) have been designed with
reliability in mind and to be able to safely handle malformed data as well as
withstand unexpected behaviour from a MQTT broker. In order to
Expand Down
7 changes: 4 additions & 3 deletions client/afl_fuzz/AflFuzz.cpp.templ
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ public:
if (!cc_mqtt5_##NAME##client_is_network_disconnected(m_client.get())) {
infoLog() << "Insufficient data in buffer (" << dataLen << "), reporting network disconnected..." << std::endl;
cc_mqtt5_##NAME##client_notify_network_disconnected(m_client.get());
brokerDisconnectReportCb(this, nullptr);
brokerDisconnectReportCb(this, CC_Mqtt5BrokerDisconnectReason_ValuesLimit, nullptr);
continue;
}

Expand Down Expand Up @@ -194,6 +194,7 @@ public:
if (!cc_mqtt5_##NAME##client_is_network_disconnected(m_client.get())) {
infoLog() << "No data consumed and no more input, reporting network disconnected..." << std::endl;
cc_mqtt5_##NAME##client_notify_network_disconnected(m_client.get());
brokerDisconnectReportCb(this, CC_Mqtt5BrokerDisconnectReason_ValuesLimit, nullptr);
continue;
}

Expand Down Expand Up @@ -630,7 +631,7 @@ private:
}
}

static void brokerDisconnectReportCb(void* data, [[maybe_unused]] const CC_Mqtt5DisconnectInfo* info)
static void brokerDisconnectReportCb(void* data, [[maybe_unused]] CC_Mqtt5BrokerDisconnectReason reason, [[maybe_unused]] const CC_Mqtt5DisconnectInfo* info)
{
asThis(data)->m_logger.infoLog() << "Broker disconnected\n";
auto& state = asThis(data)->m_state;
Expand Down Expand Up @@ -664,7 +665,7 @@ private:
} while (false);

CC_Mqtt5ErrorCode ec = CC_Mqtt5ErrorCode_ValuesLimit;
auto* publish = ::cc_mqtt5_##NAME##client_publish_prepare(thisPtr->m_client.get(), &ec);
auto* publish = ::cc_mqtt5_##NAME##client_publish_prepare(client, &ec);
assert(ec == CC_Mqtt5ErrorCode_Success);
if (publish == nullptr) {
thisPtr->errorLog() << "Unexpected failure in publish allocation\n";
Expand Down
46 changes: 23 additions & 23 deletions client/app/common/AppClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,14 +184,14 @@ std::string AppClient::toString(CC_Mqtt5ErrorCode val)
std::string AppClient::toString(CC_Mqtt5AsyncOpStatus val)
{
static const std::string Map[] = {
"CC_Mqtt5AsyncOpStatus_Complete",
"CC_Mqtt5AsyncOpStatus_InternalError",
"CC_Mqtt5AsyncOpStatus_Timeout",
"CC_Mqtt5AsyncOpStatus_ProtocolError",
"CC_Mqtt5AsyncOpStatus_Aborted",
"CC_Mqtt5AsyncOpStatus_BrokerDisconnected",
"CC_Mqtt5AsyncOpStatus_OutOfMemory",
"CC_Mqtt5AsyncOpStatus_BadParam",
"Complete",
"Internal Error",
"Timeout",
"Protocol Error",
"Aborted",
"Broker Disconnected",
"Out Of Memory",
"Bad Param",
};
static constexpr std::size_t MapSize = std::extent<decltype(Map)>::value;
static_assert(MapSize == CC_Mqtt5AsyncOpStatus_ValuesLimit);
Expand Down Expand Up @@ -310,7 +310,7 @@ void AppClient::print(const CC_Mqtt5MessageInfo& info, bool printMessage)
if (printMessage) {
std::cout <<
"\tTopic: " << info.m_topic << '\n' <<
"\tData: " << toString(info.m_data, info.m_dataLen) << '\n';
"\tData: " << toString(info.m_data, info.m_dataLen, m_opts.subBinary()) << '\n';
}

printString("Response Topic", info.m_responseTopic);
Expand Down Expand Up @@ -389,7 +389,7 @@ bool AppClient::sendConnect(CC_Mqtt5ConnectHandle connect)
{
auto ec = ::cc_mqtt5_client_connect_send(connect, &AppClient::connectCompleteCb, this);
if (ec != CC_Mqtt5ErrorCode_Success) {
logError() << "Failed to send connect request with ec=" << toString(ec) << std::endl;
logError() << "Failed to send connect request: " << toString(ec) << std::endl;
return false;
}
return true;
Expand All @@ -411,7 +411,7 @@ void AppClient::doComplete()
auto ec = CC_Mqtt5ErrorCode_Success;
auto disconnect = ::cc_mqtt5_client_disconnect_prepare(m_client.get(), &ec);
if (disconnect == nullptr) {
logError() << "Failed to prepare disconnect with ec=" << toString(ec) << std::endl;
logError() << "Failed to prepare disconnect: " << toString(ec) << std::endl;
doTerminate();
return;
}
Expand All @@ -425,14 +425,14 @@ void AppClient::doComplete()

ec = ::cc_mqtt5_client_disconnect_config(disconnect, &config);
if (ec != CC_Mqtt5ErrorCode_Success) {
logError() << "Failed to apply disconnect configuration with ec=" << toString(ec) << std::endl;
logError() << "Failed to apply disconnect configuration: " << toString(ec) << std::endl;
doTerminate();
return;
}

ec = ::cc_mqtt5_client_disconnect_send(disconnect);
if (ec != CC_Mqtt5ErrorCode_Success) {
logError() << "Failed to send disconnect with ec=" << toString(ec) << std::endl;
logError() << "Failed to send disconnect: " << toString(ec) << std::endl;
doTerminate();
return;
}
Expand All @@ -450,7 +450,7 @@ bool AppClient::startImpl()
auto ec = CC_Mqtt5ErrorCode_Success;
auto connect = ::cc_mqtt5_client_connect_prepare(m_client.get(), &ec);
if (connect == nullptr) {
logError() << "Failed to prepare connect with ec=" << toString(ec) << std::endl;
logError() << "Failed to prepare connect: " << toString(ec) << std::endl;
return false;
}

Expand Down Expand Up @@ -478,7 +478,7 @@ bool AppClient::startImpl()

ec = ::cc_mqtt5_client_connect_config_basic(connect, &basicConfig);
if (ec != CC_Mqtt5ErrorCode_Success) {
logError() << "Failed to apply basic connect configuration with ec=" << toString(ec) << std::endl;
logError() << "Failed to apply basic connect configuration: " << toString(ec) << std::endl;
return false;
}

Expand Down Expand Up @@ -519,7 +519,7 @@ bool AppClient::startImpl()

ec = ::cc_mqtt5_client_connect_config_will(connect, &willConfig);
if (ec != CC_Mqtt5ErrorCode_Success) {
logError() << "Failed to apply will configuration with ec=" << toString(ec) << std::endl;
logError() << "Failed to apply will configuration: " << toString(ec) << std::endl;
return false;
}

Expand All @@ -531,7 +531,7 @@ bool AppClient::startImpl()

ec = ::cc_mqtt5_client_connect_add_will_user_prop(connect, &info);
if (ec != CC_Mqtt5ErrorCode_Success) {
logError() << "Failed to add connect user property with ec=" << toString(ec) << std::endl;
logError() << "Failed to add connect user property: " << toString(ec) << std::endl;
return false;
}
}
Expand All @@ -548,7 +548,7 @@ bool AppClient::startImpl()

ec = ::cc_mqtt5_client_connect_config_extra(connect, &extraConfig);
if (ec != CC_Mqtt5ErrorCode_Success) {
logError() << "Failed to apply extra connect configuration with ec=" << toString(ec) << std::endl;
logError() << "Failed to apply extra connect configuration: " << toString(ec) << std::endl;
return false;
}

Expand All @@ -560,7 +560,7 @@ bool AppClient::startImpl()

ec = ::cc_mqtt5_client_connect_add_user_prop(connect, &info);
if (ec != CC_Mqtt5ErrorCode_Success) {
logError() << "Failed to add connect user property with ec=" << toString(ec) << std::endl;
logError() << "Failed to add connect user property: " << toString(ec) << std::endl;
return false;
}
}
Expand All @@ -573,7 +573,7 @@ void AppClient::brokerConnectedImpl()
assert(false); // Expected to be overriden
}

void AppClient::brokerDisconnectedImpl(const CC_Mqtt5DisconnectInfo* info)
void AppClient::brokerDisconnectedImpl([[maybe_unused]] CC_Mqtt5BrokerDisconnectReason reason, const CC_Mqtt5DisconnectInfo* info)
{
logError() << "Broker disconnected." << std::endl;
doTerminate();
Expand Down Expand Up @@ -754,7 +754,7 @@ bool AppClient::createSession()
{
assert(m_client);
::cc_mqtt5_client_notify_network_disconnected(m_client.get());
brokerDisconnectedImpl(nullptr);
doTerminate();
}
);

Expand All @@ -771,9 +771,9 @@ void AppClient::sendDataCb(void* data, const unsigned char* buf, unsigned bufLen
asThis(data)->sendDataInternal(buf, bufLen);
}

void AppClient::brokerDisconnectedCb(void* data, const CC_Mqtt5DisconnectInfo* info)
void AppClient::brokerDisconnectedCb(void* data, CC_Mqtt5BrokerDisconnectReason reason, const CC_Mqtt5DisconnectInfo* info)
{
asThis(data)->brokerDisconnectedImpl(info);
asThis(data)->brokerDisconnectedImpl(reason, info);
}

void AppClient::messageReceivedCb(void* data, const CC_Mqtt5MessageInfo* info)
Expand Down
6 changes: 3 additions & 3 deletions client/app/common/AppClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class AppClient
static std::string toString(CC_Mqtt5ReasonCode val);
static std::string toString(const std::uint8_t* data, unsigned dataLen, bool forceBinary = false);
static void print(const CC_Mqtt5DisconnectInfo& info);
static void print(const CC_Mqtt5MessageInfo& info, bool printMessage = true);
void print(const CC_Mqtt5MessageInfo& info, bool printMessage = true);
static void print(const CC_Mqtt5ConnectResponse& response);
static void print(const CC_Mqtt5PublishResponse& response);
static void print(const CC_Mqtt5SubscribeResponse& response);
Expand Down Expand Up @@ -79,7 +79,7 @@ class AppClient

virtual bool startImpl();
virtual void brokerConnectedImpl();
virtual void brokerDisconnectedImpl(const CC_Mqtt5DisconnectInfo* info);
virtual void brokerDisconnectedImpl(CC_Mqtt5BrokerDisconnectReason reason, const CC_Mqtt5DisconnectInfo* info);
virtual void messageReceivedImpl(const CC_Mqtt5MessageInfo* info);
virtual void connectCompleteImpl(CC_Mqtt5AsyncOpStatus status, const CC_Mqtt5ConnectResponse* response);

Expand All @@ -98,7 +98,7 @@ class AppClient
bool createSession();

static void sendDataCb(void* data, const unsigned char* buf, unsigned bufLen);
static void brokerDisconnectedCb(void* data, const CC_Mqtt5DisconnectInfo* info);
static void brokerDisconnectedCb(void* data, CC_Mqtt5BrokerDisconnectReason reason, const CC_Mqtt5DisconnectInfo* info);
static void messageReceivedCb(void* data, const CC_Mqtt5MessageInfo* info);
static void logMessageCb(void* data, const char* msg);
static void nextTickProgramCb(void* data, unsigned duration);
Expand Down
2 changes: 1 addition & 1 deletion client/app/common/TcpSession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ void TcpSession::doRead()
}

assert(buf == &m_inData[0]);
m_buf.insert(m_buf.end(), m_inData.begin() + consumed, m_inData.end());
m_buf.insert(m_buf.end(), m_inData.begin() + consumed, m_inData.begin() + bytesCount);
} while (false);

doRead();
Expand Down
12 changes: 6 additions & 6 deletions client/app/pub/Pub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ void Pub::brokerConnectedImpl()
auto ec = CC_Mqtt5ErrorCode_InternalError;
auto* publish = ::cc_mqtt5_client_publish_prepare(client(), &ec);
if (publish == nullptr) {
logError() << "Failed to allocate publish message with ec=" << toString(ec) << std::endl;
logError() << "Failed to allocate publish message: " << toString(ec) << std::endl;
doTerminate();
return;
}

ec = ::cc_mqtt5_client_publish_config_basic(publish, &basicConfig);
if (ec != CC_Mqtt5ErrorCode_Success) {
logError() << "Failed to perform basic publish configuration with ec=" << toString(ec) << std::endl;
logError() << "Failed to perform basic publish configuration: " << toString(ec) << std::endl;
doTerminate();
return;
}
Expand All @@ -85,7 +85,7 @@ void Pub::brokerConnectedImpl()

ec = ::cc_mqtt5_client_publish_config_extra(publish, &extraConfig);
if (ec != CC_Mqtt5ErrorCode_Success) {
logError() << "Failed to perform extra publish configuration with ec=" << toString(ec) << std::endl;
logError() << "Failed to perform extra publish configuration: " << toString(ec) << std::endl;
doTerminate();
return;
}
Expand All @@ -98,15 +98,15 @@ void Pub::brokerConnectedImpl()

ec = ::cc_mqtt5_client_publish_add_user_prop(publish, &info);
if (ec != CC_Mqtt5ErrorCode_Success) {
logError() << "Failed to add publish user property with ec=" << toString(ec) << std::endl;
logError() << "Failed to add publish user property: " << toString(ec) << std::endl;
doTerminate();
return;
}
}

ec = ::cc_mqtt5_client_publish_send(publish, &Pub::publishCompleteCb, this);
if (ec != CC_Mqtt5ErrorCode_Success) {
logError() << "Failed to send PUBLISH message with ec=" << toString(ec) << std::endl;
logError() << "Failed to send PUBLISH message: " << toString(ec) << std::endl;
doTerminate();
return;
}
Expand All @@ -115,7 +115,7 @@ void Pub::brokerConnectedImpl()
void Pub::publishCompleteInternal([[maybe_unused]] CC_Mqtt5PublishHandle handle, CC_Mqtt5AsyncOpStatus status, const CC_Mqtt5PublishResponse* response)
{
if (status != CC_Mqtt5AsyncOpStatus_Complete) {
logError() << "Publish failed with status=" << toString(status) << std::endl;
logError() << "Publish failed: " << toString(status) << std::endl;
doTerminate();
return;
}
Expand Down
12 changes: 6 additions & 6 deletions client/app/sub/Sub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ void Sub::brokerConnectedImpl()
auto ec = CC_Mqtt5ErrorCode_InternalError;
auto* subscribe = ::cc_mqtt5_client_subscribe_prepare(client(), &ec);
if (subscribe == nullptr) {
logError() << "Failed to allocate subscribe message with ec=" << toString(ec) << std::endl;
logError() << "Failed to allocate subscribe message: " << toString(ec) << std::endl;
doTerminate();
return;
}
Expand All @@ -61,7 +61,7 @@ void Sub::brokerConnectedImpl()

ec = ::cc_mqtt5_client_subscribe_config_topic(subscribe, &topicConfig);
if (ec != CC_Mqtt5ErrorCode_Success) {
logError() << "Failed to configure topic \"" << topics[idx] << "\" with ec=" << toString(ec) << std::endl;
logError() << "Failed to configure topic \"" << topics[idx] << "\": " << toString(ec) << std::endl;
doTerminate();
return;
}
Expand All @@ -75,7 +75,7 @@ void Sub::brokerConnectedImpl()

ec = ::cc_mqtt5_client_subscribe_config_extra(subscribe, &extraConfig);
if (ec != CC_Mqtt5ErrorCode_Success) {
logError() << "Failed to configure extra subscribe properties with ec=" << toString(ec) << std::endl;
logError() << "Failed to configure extra subscribe properties: " << toString(ec) << std::endl;
doTerminate();
return;
}
Expand All @@ -89,15 +89,15 @@ void Sub::brokerConnectedImpl()

ec = ::cc_mqtt5_client_subscribe_add_user_prop(subscribe, &info);
if (ec != CC_Mqtt5ErrorCode_Success) {
logError() << "Failed to add subscribe user property with ec=" << toString(ec) << std::endl;
logError() << "Failed to add subscribe user property: " << toString(ec) << std::endl;
doTerminate();
return;
}
}

ec = ::cc_mqtt5_client_subscribe_send(subscribe, &Sub::subscribeCompleteCb, this);
if (ec != CC_Mqtt5ErrorCode_Success) {
logError() << "Failed to send SUBSCRIBE message with ec=" << toString(ec) << std::endl;
logError() << "Failed to send SUBSCRIBE message: " << toString(ec) << std::endl;
doTerminate();
return;
}
Expand All @@ -122,7 +122,7 @@ void Sub::subscribeCompleteInternal(
const CC_Mqtt5SubscribeResponse* response)
{
if (status != CC_Mqtt5AsyncOpStatus_Complete) {
logError() << "Subscribe failed with status=" << toString(status) << std::endl;
logError() << "Subscribe failed: " << toString(status) << std::endl;
doTerminate();
return;
}
Expand Down
4 changes: 2 additions & 2 deletions client/lib/doxygen/doxygen.conf
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ DOXYFILE_ENCODING = UTF-8
# title of most generated pages and in a few other places.
# The default value is: My Project.

PROJECT_NAME = "CommsChampion Ecosystem MQTT5 Client"
PROJECT_NAME = "CommsChampion Ecosystem MQTT v5 Client"

# The PROJECT_NUMBER tag can be used to enter a project or revision number. This
# could be handy for archiving the generated documentation or if some version
Expand All @@ -44,7 +44,7 @@ PROJECT_NUMBER =
# for a project that appears at the top of each page and should give viewer a
# quick idea about the purpose of the project. Keep the description short.

PROJECT_BRIEF = "MQTT5 Client Library."
PROJECT_BRIEF = "MQTT v5 Client Library."

# With the PROJECT_LOGO tag one can specify a logo or an icon that is included
# in the documentation. The maximum height of the logo should not exceed 55
Expand Down
Loading

0 comments on commit 84e275f

Please sign in to comment.