From bd5f800426c8bd7000e12e202bce48e30af2edd6 Mon Sep 17 00:00:00 2001 From: john30 Date: Wed, 4 Apr 2018 15:48:26 +0200 Subject: [PATCH] code style, missing initializers and imports --- src/ebusd/main.cpp | 21 ++++++++++++--------- src/ebusd/main.h | 1 + src/ebusd/mainloop.cpp | 2 +- src/ebusd/mqtthandler.cpp | 4 ++-- src/lib/ebus/filereader.cpp | 4 ++-- src/lib/ebus/filereader.h | 4 ++-- src/lib/ebus/message.cpp | 5 +++-- src/lib/ebus/message.h | 2 +- src/lib/utils/httpclient.cpp | 20 ++++++++++---------- 9 files changed, 34 insertions(+), 29 deletions(-) diff --git a/src/ebusd/main.cpp b/src/ebusd/main.cpp index 82e46b0a..23521281 100755 --- a/src/ebusd/main.cpp +++ b/src/ebusd/main.cpp @@ -130,7 +130,7 @@ static MessageMap* s_messageMap = NULL; /** the @a MainLoop instance, or NULL. */ static MainLoop* s_mainLoop = NULL; -/** the path prefix (including trailing "/") for retrieving configuration files from local file system (empty for HTTP). */ +/** the path prefix (including trailing "/") for retrieving configuration files from local files (empty for HTTP). */ static string s_configLocalPrefix; /** the URI prefix (including trailing "/") for retrieving configuration files from HTTP (empty for local files). */ @@ -183,7 +183,8 @@ static const struct argp_option argpoptions[] = { {"latency", O_DEVLAT, "USEC", 0, "Transfer latency in us [0 for USB, 10000 for IP]", 0 }, {NULL, 0, NULL, 0, "Message configuration options:", 2 }, - {"configpath", 'c', "PATH", 0, "Read CSV config files from PATH (local folder or HTTP URL) [" CONFIG_PATH "]", 0 }, + {"configpath", 'c', "PATH", 0, "Read CSV config files from PATH (local folder or HTTP URL) [" CONFIG_PATH + "]", 0 }, {"scanconfig", 's', "ADDR", OPTION_ARG_OPTIONAL, "Pick CSV config files matching initial scan (ADDR=" "\"none\" or empty for no initial scan message, \"full\" for full scan, or a single hex address to scan, " "default is broadcast ident message). If combined with --checkconfig, you can add scan message data as " @@ -733,12 +734,13 @@ void signalHandler(int sig) { * @return the result code. */ static result_t collectConfigFiles(const string& relPath, const string& prefix, const string& extension, - vector* files, const bool ignoreAddressPrefix = false, const string& query = "", vector* dirs = NULL, - bool* hasTemplates = NULL) { + vector* files, const bool ignoreAddressPrefix = false, const string& query = "", + vector* dirs = NULL, bool* hasTemplates = NULL) { const string relPathWithSlash = relPath.empty() ? "" : relPath + "/"; if (!s_configUriPrefix.empty()) { + string uri = s_configUriPrefix + relPathWithSlash + "?t=" + extension.substr(1) + query; string names; - if (!s_configHttpClient.get(s_configUriPrefix + relPathWithSlash + "?t=" + (extension.substr(1)) + query, "", names)) { + if (!s_configHttpClient.get(uri, "", names)) { return RESULT_ERR_NOTFOUND; } istringstream stream(names); @@ -929,7 +931,7 @@ void executeInstructions(MessageMap* messages, bool verbose) { result_t loadDefinitionsFromConfigPath(FileReader* reader, const string& filename, bool verbose, map* defaults, string* errorDescription) { istream* stream = NULL; - time_t mtime; + time_t mtime = 0; if (s_configUriPrefix.empty()) { stream = FileReader::openFile(s_configLocalPrefix + filename, errorDescription, &mtime); } else { @@ -1046,7 +1048,8 @@ result_t loadScanConfigFile(MessageMap* messages, symbol_t address, bool verbose // find files matching MANUFACTURER/ZZ.*csv in cfgpath string query; if (!fromLocal) { - out << "&a=" << addrStr << "&i=" << ident << "&h=" << dec << static_cast(hw) << "&s=" << dec << static_cast(sw);; + out << "&a=" << addrStr << "&i=" << ident << "&h=" << dec << static_cast(hw) << "&s=" << dec + << static_cast(sw);; query = out.str(); out.str(""); out.clear(); @@ -1058,8 +1061,8 @@ result_t loadScanConfigFile(MessageMap* messages, symbol_t address, bool verbose return result; } if (files.empty()) { - logError(lf_main, "unable to load scan config %2.2x: no file from %s with prefix %s found", address, manufStr.c_str(), - addrStr.c_str()); + logError(lf_main, "unable to load scan config %2.2x: no file from %s with prefix %s found", address, + manufStr.c_str(), addrStr.c_str()); return RESULT_ERR_NOTFOUND; } logDebug(lf_main, "found %d matching scan config files from %s with prefix %s: %s", files.size(), manufStr.c_str(), diff --git a/src/ebusd/main.h b/src/ebusd/main.h index 56aec8c1..213372f8 100755 --- a/src/ebusd/main.h +++ b/src/ebusd/main.h @@ -21,6 +21,7 @@ #include #include +#include #include "lib/ebus/data.h" #include "lib/ebus/message.h" #include "lib/ebus/result.h" diff --git a/src/ebusd/mainloop.cpp b/src/ebusd/mainloop.cpp index cd7f2250..63594433 100755 --- a/src/ebusd/mainloop.cpp +++ b/src/ebusd/mainloop.cpp @@ -128,7 +128,7 @@ MainLoop::MainLoop(const struct options& opt, Device *device, MessageMap* messag m_logRawLastSymbol = SYN; if (opt.aclFile[0]) { string errorDescription; - time_t mtime; + time_t mtime = 0; istream* stream = FileReader::openFile(opt.aclFile, &errorDescription, &mtime); if (stream) { result = m_userList.readFromStream(stream, opt.aclFile, mtime, false, NULL, &errorDescription); diff --git a/src/ebusd/mqtthandler.cpp b/src/ebusd/mqtthandler.cpp index 32ea72d5..9caa5d81 100755 --- a/src/ebusd/mqtthandler.cpp +++ b/src/ebusd/mqtthandler.cpp @@ -601,9 +601,9 @@ void MqttHandler::handleTraffic(bool allowReconnect) { if (m_mosquitto) { int ret; #if (LIBMOSQUITTO_MAJOR >= 1) - ret = mosquitto_loop(m_mosquitto, -1, 1); // waits up to 1 second for network traffic + ret = mosquitto_loop(m_mosquitto, -1, 1); // waits up to 1 second for network traffic #else - ret = mosquitto_loop(m_mosquitto, -1); // waits up to 1 second for network traffic + ret = mosquitto_loop(m_mosquitto, -1); // waits up to 1 second for network traffic #endif if (!m_connected && ret == MOSQ_ERR_NO_CONN && allowReconnect) { ret = mosquitto_reconnect(m_mosquitto); diff --git a/src/lib/ebus/filereader.cpp b/src/lib/ebus/filereader.cpp index 3fd5433c..702f4bfb 100755 --- a/src/lib/ebus/filereader.cpp +++ b/src/lib/ebus/filereader.cpp @@ -59,7 +59,7 @@ istream* FileReader::openFile(const string& filename, string* errorDescription, return stream; } -result_t FileReader::readFromStream(istream* stream, const string& filename, time_t& mtime, bool verbose, +result_t FileReader::readFromStream(istream* stream, const string& filename, const time_t& mtime, bool verbose, map* defaults, string* errorDescription, size_t* hash, size_t* size) { if (hash) { *hash = 0; @@ -241,7 +241,7 @@ const string MappedFileReader::normalizeLanguage(const string& lang) { return normLang; } -result_t MappedFileReader::readFromStream(istream* stream, const string& filename, time_t& mtime, bool verbose, +result_t MappedFileReader::readFromStream(istream* stream, const string& filename, const time_t& mtime, bool verbose, map* defaults, string* errorDescription, size_t* hash, size_t* size) { m_mutex.lock(); m_columnNames.clear(); diff --git a/src/lib/ebus/filereader.h b/src/lib/ebus/filereader.h index 307dc9b1..0a5cc18f 100755 --- a/src/lib/ebus/filereader.h +++ b/src/lib/ebus/filereader.h @@ -96,7 +96,7 @@ class FileReader { * @param size optional pointer to a @a size_t value for storing the normalized size of the file, or NULL. * @return @a RESULT_OK on success, or an error code. */ - virtual result_t readFromStream(istream* stream, const string& filename, time_t& mtime, bool verbose, + virtual result_t readFromStream(istream* stream, const string& filename, const time_t& mtime, bool verbose, map* defaults, string* errorDescription, size_t* hash = NULL, size_t* size = NULL); /** @@ -204,7 +204,7 @@ class MappedFileReader : public FileReader { static const string normalizeLanguage(const string& lang); // @copydoc - result_t readFromStream(istream* stream, const string& filename, time_t& mtime, bool verbose, + result_t readFromStream(istream* stream, const string& filename, const time_t& mtime, bool verbose, map* defaults, string* errorDescription, size_t* hash = NULL, size_t* size = NULL) override; /** diff --git a/src/lib/ebus/message.cpp b/src/lib/ebus/message.cpp index 0feb02dc..b9c8314f 100755 --- a/src/lib/ebus/message.cpp +++ b/src/lib/ebus/message.cpp @@ -2104,7 +2104,7 @@ bool MessageMap::extractDefaultsFromFilename(const string& filename, map* defaults, string* errorDescription, size_t* hash, size_t* size) { size_t localHash, localSize; if (!hash) { @@ -2113,7 +2113,8 @@ result_t MessageMap::readFromStream(istream* stream, const string& filename, tim if (!size) { size = &localSize; } - result_t result = MappedFileReader::readFromStream(stream, filename, mtime, verbose, defaults, errorDescription, hash, size); + result_t result = MappedFileReader::readFromStream(stream, filename, mtime, verbose, defaults, errorDescription, hash, + size); if (defaults) { string circuit = AttributedItem::pluck("circuit", defaults); if (!circuit.empty() && m_circuitData.find(circuit) == m_circuitData.end()) { diff --git a/src/lib/ebus/message.h b/src/lib/ebus/message.h index 2a69c866..f8963eeb 100755 --- a/src/lib/ebus/message.h +++ b/src/lib/ebus/message.h @@ -1261,7 +1261,7 @@ class MessageMap : public MappedFileReader { symbol_t* destAddress = NULL, unsigned int* software = NULL, unsigned int* hardware = NULL) const override; // @copydoc - result_t readFromStream(istream* stream, const string& filename, time_t& mtime, bool verbose, + result_t readFromStream(istream* stream, const string& filename, const time_t& mtime, bool verbose, map* defaults, string* errorDescription, size_t* hash = NULL, size_t* size = NULL) override; // @copydoc diff --git a/src/lib/utils/httpclient.cpp b/src/lib/utils/httpclient.cpp index fea8a5d3..83afba46 100755 --- a/src/lib/utils/httpclient.cpp +++ b/src/lib/utils/httpclient.cpp @@ -119,10 +119,10 @@ bool HttpClient::post(const string& uri, const string& body, string& response) { } const int indexToMonth[] = { - -1, -1, 2, 12, -1, -1, 1, -1, // 0-7 - -1, -1, -1, -1, 7, -1, 6, 8, // 8-15 - 9, 5, 3, -1, 10, -1, 11, -1, // 16-23 - -1, -1, 4, -1, -1, -1, -1, -1, // 24-31 + -1, -1, 2, 12, -1, -1, 1, -1, // 0-7 + -1, -1, -1, -1, 7, -1, 6, 8, // 8-15 + 9, 5, 3, -1, 10, -1, 11, -1, // 16-23 + -1, -1, 4, -1, -1, -1, -1, -1, // 24-31 }; bool HttpClient::request(const string& method, const string& uri, const string& body, string& response, time_t* time) { @@ -157,7 +157,7 @@ bool HttpClient::request(const string& method, const string& uri, const string& pos += sent; } string result; - size_t pos = readUntil(" ", 4 * 1024, result); // max 4k headers + size_t pos = readUntil(" ", 4 * 1024, result); // max 4k headers if (pos == string::npos || pos > 8 || result.substr(0, 5) != "HTTP/") { disconnect(); response = "receive error (headers)"; @@ -169,13 +169,13 @@ bool HttpClient::request(const string& method, const string& uri, const string& response = "receive error: " + result.substr(pos+1, endpos == string::npos ? endpos : endpos-pos-1); return false; } - pos = readUntil("\r\n\r\n", 4 * 1024, result); // max 4k headers + pos = readUntil("\r\n\r\n", 4 * 1024, result); // max 4k headers if (pos == string::npos) { disconnect(); response = "receive error (headers)"; return false; } - string headers = result.substr(0, pos+2); // including final \r\n + string headers = result.substr(0, pos+2); // including final \r\n const char* hdrs = headers.c_str(); response = result.substr(pos+4); if (time) { @@ -215,15 +215,15 @@ bool HttpClient::request(const string& method, const string& uri, const string& if (t.tm_mday > 0 && t.tm_mon >= 0 && t.tm_year >= 0 && t.tm_hour >= 0 && t.tm_min >=0 && t.tm_sec >= 0) { *time = timegm(&t); } - }; + } } - pos = headers.find("\r\nContent-Length: "); // 16 chars + pos = headers.find("\r\nContent-Length: "); if (pos == string::npos) { disconnect(); return true; } char* strEnd = NULL; - unsigned long length = strtoul(hdrs+pos+strlen("\r\nContent-Length: "), &strEnd, 10); + unsigned long length = strtoul(hdrs + pos + strlen("\r\nContent-Length: "), &strEnd, 10); if (strEnd == NULL || *strEnd != '\r') { disconnect(); response = "invalid content length ";