From 5d8c9735d227f731cc7e045877d93850b73fc6c6 Mon Sep 17 00:00:00 2001 From: John Date: Tue, 1 Oct 2024 06:44:52 +0200 Subject: [PATCH] formatting, lint --- src/ebusd/bushandler.cpp | 3 ++- src/ebusd/knxhandler.cpp | 6 ++++-- src/ebusd/main_args.cpp | 9 +++++---- src/ebusd/mainloop.cpp | 10 ++++++---- src/ebusd/mqtthandler.cpp | 3 ++- src/ebusd/scan.cpp | 2 +- src/lib/ebus/data.cpp | 4 ++-- src/lib/ebus/device_trans.cpp | 2 +- src/lib/ebus/message.cpp | 5 +++-- src/lib/ebus/transport.cpp | 3 ++- src/lib/ebus/transport.h | 2 +- src/lib/utils/httpclient.cpp | 4 ++-- 12 files changed, 31 insertions(+), 22 deletions(-) diff --git a/src/ebusd/bushandler.cpp b/src/ebusd/bushandler.cpp index 5f31976e0..5dc2e0609 100644 --- a/src/ebusd/bushandler.cpp +++ b/src/ebusd/bushandler.cpp @@ -453,7 +453,8 @@ void BusHandler::notifyProtocolMessage(MessageDirection direction, const MasterS answer.push_back(command.dataAt(pos)); } answer.adjustHeader(); - m_protocol->setAnswer(SYN, getSlaveAddress(dstAddress), command[2], command[3], command.data() + 5, idLen, answer); + m_protocol->setAnswer(SYN, getSlaveAddress(dstAddress), command[2], command[3], command.data() + 5, idLen, + answer); // TODO could use loaded messages for identifying MM/MS message pair } } diff --git a/src/ebusd/knxhandler.cpp b/src/ebusd/knxhandler.cpp index 2bca8694d..d160f18dc 100644 --- a/src/ebusd/knxhandler.cpp +++ b/src/ebusd/knxhandler.cpp @@ -771,10 +771,12 @@ void KnxHandler::run() { continue; // not usable in absence of destination address } if (message->getCreateTime() <= definitionsSince // only newer defined - && (!message->isConditional() || message->getAvailableSinceTime() <= definitionsSince)) { // unless conditional + && (!message->isConditional() // unless conditional + || message->getAvailableSinceTime() <= definitionsSince)) { continue; } - logOtherDebug("knx", "checking association to %s %s", message->getCircuit().c_str(), message->getName().c_str()); + logOtherDebug("knx", "checking association to %s %s", message->getCircuit().c_str(), + message->getName().c_str()); bool isWrite = message->isWrite() && !message->isPassive(); // from KNX perspective ssize_t fieldCount = static_cast(message->getFieldCount()); if (isWrite && fieldCount > 1) { diff --git a/src/ebusd/main_args.cpp b/src/ebusd/main_args.cpp index f71498b5d..29e555dbb 100755 --- a/src/ebusd/main_args.cpp +++ b/src/ebusd/main_args.cpp @@ -165,12 +165,13 @@ static const argDef argDefs[] = { "Check and dump config files in FORMAT (\"json\" or \"csv\"), then stop"}, {"dumpconfigto", O_DMPCTO, "FILE", 0, "Dump config files to FILE"}, {"pollinterval", O_POLINT, "SEC", 0, "Poll for data every SEC seconds (0=disable) [5]"}, - {"inject", 'i', "stop", af_optional, "Inject remaining arguments as commands or already seen messages (e.g. " - "\"FF08070400/0AB5454850303003277201\"), optionally stop afterwards"}, - {nullptr, O_INJPOS, "INJECT", af_optional|af_multiple, "Commands and/or messages to inject (if --inject was given)"}, + {"inject", 'i', "stop", af_optional, "Inject remaining arguments as commands or already seen messages " + "(e.g. \"FF08070400/0AB5454850303003277201\"), optionally stop afterwards"}, + {nullptr, O_INJPOS, "INJECT", af_optional|af_multiple, "Commands and/or messages to inject " + "(if --inject was given)"}, #ifdef HAVE_SSL {"cafile", O_CAFILE, "FILE", 0, "Use CA FILE for checking certificates (uses defaults," - " \"#\" for insecure)"}, + " \"#\" for insecure)"}, {"capath", O_CAPATH, "PATH", 0, "Use CA PATH for checking certificates (uses defaults)"}, #endif // HAVE_SSL diff --git a/src/ebusd/mainloop.cpp b/src/ebusd/mainloop.cpp index 7a3635dbd..419b8f45e 100644 --- a/src/ebusd/mainloop.cpp +++ b/src/ebusd/mainloop.cpp @@ -749,7 +749,8 @@ result_t MainLoop::executeRead(const vector& args, const string& levels, " NAME NAME of the message to send\n" " FIELD only retrieve the field named FIELD\n" " N only retrieve the N'th field named FIELD (0-based)\n" - " -def read with explicit message definition (only if enabled, allow write direction if given more than once):\n" + " -def read with explicit message definition (only if enabled, allow write direction if given more" + " than once):\n" " DEFINITION message definition to use instead of known definition\n" " -h send hex read message (or answer from cache):\n" " ZZ destination address\n" @@ -849,7 +850,8 @@ result_t MainLoop::executeRead(const vector& args, const string& levels, return RESULT_OK; } deque messages; - m_newlyDefinedMessages->findAll("", "", levels, false, true, writeDirection, writeDirection, true, false, 0, 0, false, &messages); + m_newlyDefinedMessages->findAll("", "", levels, false, true, writeDirection, writeDirection, true, false, 0, 0, + false, &messages); if (messages.empty()) { *ostream << "ERR: bad definition: no read" << (writeDirection?"/write":"") << " message"; return RESULT_OK; @@ -874,8 +876,8 @@ result_t MainLoop::executeRead(const vector& args, const string& levels, if (verbosity & OF_NAMES) { *ostream << cacheMessage->getCircuit() << " " << cacheMessage->getName() << " "; } - ret = cacheMessage->decodeLastData(pt_any, false, fieldIndex == -2 ? nullptr : fieldName.c_str(), fieldIndex, verbosity, - ostream); + ret = cacheMessage->decodeLastData(pt_any, false, fieldIndex == -2 ? nullptr : fieldName.c_str(), fieldIndex, + verbosity, ostream); if (ret < RESULT_OK) { logError(lf_main, "read %s %s cached: decode %s", cacheMessage->getCircuit().c_str(), cacheMessage->getName().c_str(), getResultCode(ret)); diff --git a/src/ebusd/mqtthandler.cpp b/src/ebusd/mqtthandler.cpp index 56ff1cabc..acc6ec5ba 100755 --- a/src/ebusd/mqtthandler.cpp +++ b/src/ebusd/mqtthandler.cpp @@ -818,7 +818,8 @@ void MqttHandler::run() { } message->setDataHandlerState(1, true); } else if (message->getCreateTime() <= m_definitionsSince // only newer defined - && (!message->isConditional() || message->getAvailableSinceTime() <= m_definitionsSince)) { // unless conditional + && (!message->isConditional() // unless conditional + || message->getAvailableSinceTime() <= m_definitionsSince)) { continue; } if (!FileReader::matches(message->getCircuit(), filterCircuit, true, true) diff --git a/src/ebusd/scan.cpp b/src/ebusd/scan.cpp index 3ae6a5160..cb7228847 100644 --- a/src/ebusd/scan.cpp +++ b/src/ebusd/scan.cpp @@ -82,7 +82,7 @@ result_t ScanHelper::collectConfigFiles(const string& relPath, const string& pre if (!m_configHttpClient->get(uri, "", &names)) { return RESULT_ERR_NOTFOUND; } - } else if (!json && names[0]=='<') { // html + } else if (!json && names[0] == '<') { // html uri = m_configUriPrefix + relPathWithSlash + "index.json"; json = true; logDebug(lf_main, "trying index.json"); diff --git a/src/lib/ebus/data.cpp b/src/lib/ebus/data.cpp index 50011c574..ca7c36d58 100644 --- a/src/lib/ebus/data.cpp +++ b/src/lib/ebus/data.cpp @@ -203,7 +203,7 @@ bool isValidIdentifierChar(char ch, bool first, bool allowFirstDigit) { bool DataField::checkIdentifier(const string& name, bool allowFirstDigit) { for (size_t i = 0; i < name.size(); i++) { char ch = name[i]; - if (!isValidIdentifierChar(ch, i==0, allowFirstDigit)) { + if (!isValidIdentifierChar(ch, i == 0, allowFirstDigit)) { return false; } } @@ -213,7 +213,7 @@ bool DataField::checkIdentifier(const string& name, bool allowFirstDigit) { void DataField::normalizeIdentifier(string& name, bool allowFirstDigit) { for (size_t i = 0; i < name.size(); i++) { char ch = name[i]; - if (!isValidIdentifierChar(ch, i==0, allowFirstDigit)) { + if (!isValidIdentifierChar(ch, i == 0, allowFirstDigit)) { name[i] = '_'; } } diff --git a/src/lib/ebus/device_trans.cpp b/src/lib/ebus/device_trans.cpp index 1a855bac2..61a2ba781 100755 --- a/src/lib/ebus/device_trans.cpp +++ b/src/lib/ebus/device_trans.cpp @@ -616,7 +616,7 @@ void EnhancedDevice::notifyInfoRetrieved() { case 0x0107: stream << "rssi "; if (data[0]) { - stream << static_cast(((int8_t*)data)[0]) << " dBm"; + stream << static_cast(reinterpret_cast(data)[0]) << " dBm"; } else { stream << "unknown"; } diff --git a/src/lib/ebus/message.cpp b/src/lib/ebus/message.cpp index ab74a915d..5d2812260 100644 --- a/src/lib/ebus/message.cpp +++ b/src/lib/ebus/message.cpp @@ -70,7 +70,7 @@ using std::endl; #define POLL_PRIORITY_CONDITION 5 /** the field name constant for the message level. */ -static const char* FIELDNAME_LEVEL = "level";// +static const char* FIELDNAME_LEVEL = "level"; /** the known full length field names. */ static const char* knownFieldNamesFull[] = { @@ -1691,7 +1691,8 @@ void SimpleNumericCondition::dumpValuesJson(ostream* output) const { bool SimpleStringCondition::checkValue(const Message* message, const string& field) { ostringstream output; - result_t result = message->decodeLastData(pt_any, false, field.length() == 0 ? nullptr : field.c_str(), -1, OF_NONE, &output); + result_t result = message->decodeLastData(pt_any, false, field.length() == 0 ? nullptr : field.c_str(), -1, + OF_NONE, &output); if (result == RESULT_OK) { string value = output.str(); for (size_t i = 0; i < m_values.size(); i++) { diff --git a/src/lib/ebus/transport.cpp b/src/lib/ebus/transport.cpp index e95221627..c9cb1bc8c 100644 --- a/src/lib/ebus/transport.cpp +++ b/src/lib/ebus/transport.cpp @@ -325,7 +325,8 @@ void SerialTransport::checkDevice() { } result_t NetworkTransport::openInternal() { - m_fd = socketConnect(m_hostOrIp, m_port, m_udp ? IPPROTO_UDP : 0, nullptr, 5, 2); // wait up to 5 seconds for established connection + // wait up to 5 seconds for established connection + m_fd = socketConnect(m_hostOrIp, m_port, m_udp ? IPPROTO_UDP : 0, nullptr, 5, 2); if (m_fd < 0) { return RESULT_ERR_GENERIC_IO; } diff --git a/src/lib/ebus/transport.h b/src/lib/ebus/transport.h index 9a8542245..3c2e1f80f 100755 --- a/src/lib/ebus/transport.h +++ b/src/lib/ebus/transport.h @@ -300,7 +300,7 @@ class NetworkTransport : public FileTransport { */ ~NetworkTransport() override { if (m_hostOrIp) { - free((void*)m_hostOrIp); + free(const_cast(m_hostOrIp)); m_hostOrIp = nullptr; } } diff --git a/src/lib/utils/httpclient.cpp b/src/lib/utils/httpclient.cpp index cdaf0e1a1..b1648c1d8 100755 --- a/src/lib/utils/httpclient.cpp +++ b/src/lib/utils/httpclient.cpp @@ -302,7 +302,7 @@ SSLSocket* SSLSocket::connect(const string& host, const uint16_t& port, bool htt break; } if (strcmp(peerName, hostname) != 0) { - char* dotpos = strchr((char*)hostname, '.'); + char* dotpos = strchr(const_cast(hostname), '.'); if (peerName[0] == '*' && peerName[1] == '.' && dotpos && strcmp(peerName+2, dotpos+1) == 0) { // wildcard matches @@ -582,7 +582,7 @@ bool* repeatable, time_t* time, bool* jsonString) { } pos = readUntil("", length, response); disconnect(); - if (noLength ? pos<1 : pos != length) { + if (noLength ? pos < 1 : pos != length) { return false; } if (noLength) {