From ed79a7176a865bfa404c118f98e4b0907d40651d Mon Sep 17 00:00:00 2001 From: sp5lg Date: Sun, 6 Oct 2019 16:15:25 +0200 Subject: [PATCH 1/8] DStar SelfOnly with WhiteList --- Conf.cpp | 20 +++++++++++++++++++- Conf.h | 2 ++ DStarControl.cpp | 7 ++++--- DStarControl.h | 3 ++- MMDVM.ini | 1 + MMDVMHost.cpp | 5 ++++- 6 files changed, 32 insertions(+), 6 deletions(-) diff --git a/Conf.cpp b/Conf.cpp index 746b50a..db52376 100644 --- a/Conf.cpp +++ b/Conf.cpp @@ -123,6 +123,7 @@ m_dstarEnabled(false), m_dstarModule("C"), m_dstarSelfOnly(false), m_dstarBlackList(), +m_dstarWhiteList(), m_dstarAckReply(true), m_dstarAckTime(750U), m_dstarAckMessage(false), @@ -513,7 +514,19 @@ bool CConf::read() } p = ::strtok(NULL, ",\r\n"); } - } else if (::strcmp(key, "AckReply") == 0) + } else if (::strcmp(key, "WhiteList") == 0) { + char* p = ::strtok(value, ",\r\n"); + while (p != NULL) { + if (::strlen(p) > 0U) { + for (unsigned int i = 0U; p[i] != 0; i++) + p[i] = ::toupper(p[i]); + std::string callsign = std::string(p); + callsign.resize(DSTAR_LONG_CALLSIGN_LENGTH, ' '); + m_dstarWhiteList.push_back(callsign); + } + p = ::strtok(NULL, ",\r\n"); + } + } else if (::strcmp(key, "AckReply") == 0) m_dstarAckReply = ::atoi(value) == 1; else if (::strcmp(key, "AckTime") == 0) m_dstarAckTime = (unsigned int)::atoi(value); @@ -1136,6 +1149,11 @@ std::vector CConf::getDStarBlackList() const return m_dstarBlackList; } +std::vector CConf::getDStarWhiteList() const +{ + return m_dstarWhiteList; +} + bool CConf::getDStarAckReply() const { return m_dstarAckReply; diff --git a/Conf.h b/Conf.h index 9629477..fd525ee 100644 --- a/Conf.h +++ b/Conf.h @@ -110,6 +110,7 @@ public: std::string getDStarModule() const; bool getDStarSelfOnly() const; std::vector getDStarBlackList() const; + std::vector getDStarWhiteList() const; bool getDStarAckReply() const; unsigned int getDStarAckTime() const; bool getDStarAckMessage() const; @@ -349,6 +350,7 @@ private: std::string m_dstarModule; bool m_dstarSelfOnly; std::vector m_dstarBlackList; + std::vector m_dstarWhiteList; bool m_dstarAckReply; unsigned int m_dstarAckTime; bool m_dstarAckMessage; diff --git a/DStarControl.cpp b/DStarControl.cpp index 9e08914..6c5b6cf 100644 --- a/DStarControl.cpp +++ b/DStarControl.cpp @@ -36,7 +36,7 @@ bool CallsignCompare(const std::string& arg, const unsigned char* my) // #define DUMP_DSTAR -CDStarControl::CDStarControl(const std::string& callsign, const std::string& module, bool selfOnly, bool ackReply, unsigned int ackTime, bool ackMessage, bool errorReply, const std::vector& blackList, CDStarNetwork* network, CDisplay* display, unsigned int timeout, bool duplex, bool remoteGateway, CRSSIInterpolator* rssiMapper) : +CDStarControl::CDStarControl(const std::string& callsign, const std::string& module, bool selfOnly, bool ackReply, unsigned int ackTime, bool ackMessage, bool errorReply, const std::vector& blackList, const std::vector& whiteList, CDStarNetwork* network, CDisplay* display, unsigned int timeout, bool duplex, bool remoteGateway, CRSSIInterpolator* rssiMapper) : m_callsign(NULL), m_gateway(NULL), m_selfOnly(selfOnly), @@ -45,6 +45,7 @@ m_ackMessage(ackMessage), m_errorReply(errorReply), m_remoteGateway(remoteGateway), m_blackList(blackList), +m_whiteList(whiteList), m_network(network), m_display(display), m_duplex(duplex), @@ -231,7 +232,7 @@ bool CDStarControl::writeModem(unsigned char *data, unsigned int len) return false; } - if (m_selfOnly && ::memcmp(my1, m_callsign, DSTAR_LONG_CALLSIGN_LENGTH - 1U) != 0) { + if (m_selfOnly && ::memcmp(my1, m_callsign, DSTAR_LONG_CALLSIGN_LENGTH - 1U) != 0 && !(std::find_if(m_whiteList.begin(), m_whiteList.end(), std::bind(CallsignCompare, std::placeholders::_1, my1)) != m_whiteList.end())) { LogMessage("D-Star, invalid access attempt from %8.8s", my1); m_rfState = RS_RF_REJECTED; return false; @@ -465,7 +466,7 @@ bool CDStarControl::writeModem(unsigned char *data, unsigned int len) return false; } - if (m_selfOnly && ::memcmp(my1, m_callsign, DSTAR_LONG_CALLSIGN_LENGTH - 1U) != 0) { + if (m_selfOnly && ::memcmp(my1, m_callsign, DSTAR_LONG_CALLSIGN_LENGTH - 1U) != 0 && !(std::find_if(m_whiteList.begin(), m_whiteList.end(), std::bind(CallsignCompare, std::placeholders::_1, my1)) != m_whiteList.end())) { LogMessage("D-Star, invalid access attempt from %8.8s", my1); m_rfState = RS_RF_REJECTED; delete header; diff --git a/DStarControl.h b/DStarControl.h index 1598df2..71fd9fc 100644 --- a/DStarControl.h +++ b/DStarControl.h @@ -37,7 +37,7 @@ class CDStarControl { public: - CDStarControl(const std::string& callsign, const std::string& module, bool selfOnly, bool ackReply, unsigned int ackTime, bool ackMessage, bool errorReply, const std::vector& blackList, CDStarNetwork* network, CDisplay* display, unsigned int timeout, bool duplex, bool remoteGateway, CRSSIInterpolator* rssiMapper); + CDStarControl(const std::string& callsign, const std::string& module, bool selfOnly, bool ackReply, unsigned int ackTime, bool ackMessage, bool errorReply, const std::vector& blackList, const std::vector& whiteList, CDStarNetwork* network, CDisplay* display, unsigned int timeout, bool duplex, bool remoteGateway, CRSSIInterpolator* rssiMapper); ~CDStarControl(); bool writeModem(unsigned char* data, unsigned int len); @@ -59,6 +59,7 @@ private: bool m_errorReply; bool m_remoteGateway; std::vector m_blackList; + std::vector m_whiteList; CDStarNetwork* m_network; CDisplay* m_display; bool m_duplex; diff --git a/MMDVM.ini b/MMDVM.ini index 56fe14e..a25edf3 100644 --- a/MMDVM.ini +++ b/MMDVM.ini @@ -91,6 +91,7 @@ AckMessage=0 ErrorReply=1 RemoteGateway=0 # ModeHang=10 +WhiteList= [DMR] Enable=1 diff --git a/MMDVMHost.cpp b/MMDVMHost.cpp index 969187a..9264211 100644 --- a/MMDVMHost.cpp +++ b/MMDVMHost.cpp @@ -402,6 +402,7 @@ int CMMDVMHost::run() std::string module = m_conf.getDStarModule(); bool selfOnly = m_conf.getDStarSelfOnly(); std::vector blackList = m_conf.getDStarBlackList(); + std::vector whiteList = m_conf.getDStarWhiteList(); bool ackReply = m_conf.getDStarAckReply(); unsigned int ackTime = m_conf.getDStarAckTime(); bool ackMessage = m_conf.getDStarAckMessage(); @@ -421,8 +422,10 @@ int CMMDVMHost::run() if (blackList.size() > 0U) LogInfo(" Black List: %u", blackList.size()); + if (whiteList.size() > 0U) + LogInfo(" White List: %u", whiteList.size()); - m_dstar = new CDStarControl(m_callsign, module, selfOnly, ackReply, ackTime, ackMessage, errorReply, blackList, m_dstarNetwork, m_display, m_timeout, m_duplex, remoteGateway, rssi); + m_dstar = new CDStarControl(m_callsign, module, selfOnly, ackReply, ackTime, ackMessage, errorReply, blackList, whiteList, m_dstarNetwork, m_display, m_timeout, m_duplex, remoteGateway, rssi); } CTimer dmrBeaconIntervalTimer(1000U); From bb0bd4bb46f3d8d9d71a1242cc0c5ae41d26879d Mon Sep 17 00:00:00 2001 From: sp5lg Date: Sun, 6 Oct 2019 16:29:57 +0200 Subject: [PATCH 2/8] DStar SelfOnly with WhiteList (beautyfied) --- Conf.cpp | 2 +- DStarControl.h | 2 +- MMDVMHost.cpp | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Conf.cpp b/Conf.cpp index db52376..fccfdb7 100644 --- a/Conf.cpp +++ b/Conf.cpp @@ -526,7 +526,7 @@ bool CConf::read() } p = ::strtok(NULL, ",\r\n"); } - } else if (::strcmp(key, "AckReply") == 0) + } else if (::strcmp(key, "AckReply") == 0) m_dstarAckReply = ::atoi(value) == 1; else if (::strcmp(key, "AckTime") == 0) m_dstarAckTime = (unsigned int)::atoi(value); diff --git a/DStarControl.h b/DStarControl.h index 71fd9fc..3d541d1 100644 --- a/DStarControl.h +++ b/DStarControl.h @@ -59,7 +59,7 @@ private: bool m_errorReply; bool m_remoteGateway; std::vector m_blackList; - std::vector m_whiteList; + std::vector m_whiteList; CDStarNetwork* m_network; CDisplay* m_display; bool m_duplex; diff --git a/MMDVMHost.cpp b/MMDVMHost.cpp index 9264211..16f1fa8 100644 --- a/MMDVMHost.cpp +++ b/MMDVMHost.cpp @@ -402,7 +402,7 @@ int CMMDVMHost::run() std::string module = m_conf.getDStarModule(); bool selfOnly = m_conf.getDStarSelfOnly(); std::vector blackList = m_conf.getDStarBlackList(); - std::vector whiteList = m_conf.getDStarWhiteList(); + std::vector whiteList = m_conf.getDStarWhiteList(); bool ackReply = m_conf.getDStarAckReply(); unsigned int ackTime = m_conf.getDStarAckTime(); bool ackMessage = m_conf.getDStarAckMessage(); @@ -422,8 +422,8 @@ int CMMDVMHost::run() if (blackList.size() > 0U) LogInfo(" Black List: %u", blackList.size()); - if (whiteList.size() > 0U) - LogInfo(" White List: %u", whiteList.size()); + if (whiteList.size() > 0U) + LogInfo(" White List: %u", whiteList.size()); m_dstar = new CDStarControl(m_callsign, module, selfOnly, ackReply, ackTime, ackMessage, errorReply, blackList, whiteList, m_dstarNetwork, m_display, m_timeout, m_duplex, remoteGateway, rssi); } From 1cc79413b7d09ad8b4972e271617e1806b91e7aa Mon Sep 17 00:00:00 2001 From: Sergei Date: Mon, 10 Aug 2020 15:36:12 +0300 Subject: [PATCH 3/8] Added a new address the id's list A new address with the id's list format optimized for pistar as well. Extra spaces in the line were removed. --- linux/DMRIDUpdateBM.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/linux/DMRIDUpdateBM.sh b/linux/DMRIDUpdateBM.sh index dfe4e86..ecf22db 100755 --- a/linux/DMRIDUpdateBM.sh +++ b/linux/DMRIDUpdateBM.sh @@ -92,7 +92,8 @@ then fi # Generate new file -curl 'http://registry.dstar.su/dmr/DMRIds.php' 2>/dev/null | sed -e 's/[[:space:]]\+/ /g' > ${DMRIDFILE} +#curl 'http://registry.dstar.su/dmr/DMRIds.php' 2>/dev/null | sed -e 's/[[:space:]]\+/ /g' > ${DMRIDFILE} +curl 'http://registry.dstar.su/dmr/DMRIds2.php' 2>/dev/null | sed -e 's/[[:space:]]\+/ /g' > ${DMRIDFILE} # Restart MMDVMHost eval ${RESTARTCOMMAND} From 630551f6fd76af806d20c5fab1f7c156f0a654d7 Mon Sep 17 00:00:00 2001 From: SASANO Takayoshi Date: Wed, 7 Oct 2020 19:09:14 +0900 Subject: [PATCH 4/8] CNetworkInfo::getNetworkInterface() FreeBSD support modified IPv4 default routing information request code to support FreeBSD --- NetworkInfo.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/NetworkInfo.cpp b/NetworkInfo.cpp index 7df2d3c..3b17168 100644 --- a/NetworkInfo.cpp +++ b/NetworkInfo.cpp @@ -26,13 +26,13 @@ #include #include -#if defined(__linux__) || defined(__OpenBSD__) || defined(__NetBSD__) +#if defined(__linux__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__FreeBSD__) #include #include #include #include #include -#if defined(__OpenBSD__) || defined(__NetBSD__) +#if defined(__OpenBSD__) || defined(__NetBSD__) || defined(__FreeBSD__) #include #include #include @@ -66,7 +66,7 @@ void CNetworkInfo::getNetworkInterface(unsigned char* info) ::strcpy((char*)info, "(address unknown)"); -#if defined(__linux__) || defined(__NetBSD__) || defined(__OpenBSD__) +#if defined(__linux__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__FreeBSD__) char* dflt = NULL; #if defined(__linux__) @@ -91,7 +91,7 @@ void CNetworkInfo::getNetworkInterface(unsigned char* info) ::fclose(fp); -#elif defined(__OpenBSD__) || defined(__NetBSD__) +#elif defined(__OpenBSD__) || defined(__NetBSD__) || defined(__FreeBSD__) const int mib[] = { CTL_NET, PF_ROUTE, @@ -99,7 +99,7 @@ void CNetworkInfo::getNetworkInterface(unsigned char* info) AF_INET, // IPv4 routing NET_RT_DUMP, 0, // show all routes -#if defined(__OpenBSD__) +#if defined(__OpenBSD__) || defined(__FreeBSD__) 0, // table id #endif }; @@ -126,7 +126,7 @@ void CNetworkInfo::getNetworkInterface(unsigned char* info) continue; #if defined(__OpenBSD__) struct sockaddr_in *sa = (struct sockaddr_in *)(p + rtm->rtm_hdrlen); -#elif defined(__NetBSD__) +#elif defined(__NetBSD__) || defined(__FreeBSD__) struct sockaddr_in *sa = (struct sockaddr_in *)(rtm + 1); #endif if (sa->sin_addr.s_addr == INADDR_ANY) { From 1f72bf16d85bc05c634654fb7f2d7aebfe46b256 Mon Sep 17 00:00:00 2001 From: SASANO Takayoshi Date: Sat, 10 Oct 2020 04:48:59 +0900 Subject: [PATCH 5/8] add OSX support to NetworkInfo.cpp (EXPERIMENTAL) --- NetworkInfo.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/NetworkInfo.cpp b/NetworkInfo.cpp index 3b17168..d21c780 100644 --- a/NetworkInfo.cpp +++ b/NetworkInfo.cpp @@ -26,13 +26,13 @@ #include #include -#if defined(__linux__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__FreeBSD__) +#if defined(__linux__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__FreeBSD__) || defined(__APPLE__) #include #include #include #include #include -#if defined(__OpenBSD__) || defined(__NetBSD__) || defined(__FreeBSD__) +#if defined(__OpenBSD__) || defined(__NetBSD__) || defined(__FreeBSD__) || defined(__APPLE__) #include #include #include @@ -66,7 +66,7 @@ void CNetworkInfo::getNetworkInterface(unsigned char* info) ::strcpy((char*)info, "(address unknown)"); -#if defined(__linux__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__FreeBSD__) +#if defined(__linux__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__FreeBSD__) || defined(__APPLE__) char* dflt = NULL; #if defined(__linux__) @@ -91,7 +91,7 @@ void CNetworkInfo::getNetworkInterface(unsigned char* info) ::fclose(fp); -#elif defined(__OpenBSD__) || defined(__NetBSD__) || defined(__FreeBSD__) +#elif defined(__OpenBSD__) || defined(__NetBSD__) || defined(__FreeBSD__) || defined(__APPLE__) const int mib[] = { CTL_NET, PF_ROUTE, @@ -126,7 +126,7 @@ void CNetworkInfo::getNetworkInterface(unsigned char* info) continue; #if defined(__OpenBSD__) struct sockaddr_in *sa = (struct sockaddr_in *)(p + rtm->rtm_hdrlen); -#elif defined(__NetBSD__) || defined(__FreeBSD__) +#elif defined(__NetBSD__) || defined(__FreeBSD__) || defined(__APPLE__) struct sockaddr_in *sa = (struct sockaddr_in *)(rtm + 1); #endif if (sa->sin_addr.s_addr == INADDR_ANY) { From 53ae146667866733095d03af319897f0b344a9a8 Mon Sep 17 00:00:00 2001 From: Jacob Schramm Date: Wed, 28 Oct 2020 23:19:24 +0100 Subject: [PATCH 6/8] Introducing RotateLog configuration option that allows disabling timestamps on the logfiles. --- .gitignore | 1 + Conf.cpp | 8 ++++++++ Conf.h | 2 ++ Log.cpp | 15 ++++++++++++--- Log.h | 2 +- MMDVM.ini | 1 + MMDVMHost.cpp | 4 ++-- RemoteCommand.cpp | 2 +- 8 files changed, 28 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index 14ab1c8..4009b5a 100644 --- a/.gitignore +++ b/.gitignore @@ -15,5 +15,6 @@ RemoteCommand *.user *.VC.db .vs +.vscode *.ambe GitVersion.h diff --git a/Conf.cpp b/Conf.cpp index 7491717..890dde5 100644 --- a/Conf.cpp +++ b/Conf.cpp @@ -82,6 +82,7 @@ m_logDisplayLevel(0U), m_logFileLevel(0U), m_logFilePath(), m_logFileRoot(), +m_logRotateLogs(1U), m_cwIdEnabled(false), m_cwIdTime(10U), m_cwIdCallsign(), @@ -453,6 +454,8 @@ bool CConf::read() m_logFileLevel = (unsigned int)::atoi(value); else if (::strcmp(key, "DisplayLevel") == 0) m_logDisplayLevel = (unsigned int)::atoi(value); + else if (::strcmp(key, "RotateLogs") == 0) + m_logRotateLogs = (unsigned int)::atoi(value); } else if (section == SECTION_CWID) { if (::strcmp(key, "Enable") == 0) m_cwIdEnabled = ::atoi(value) == 1; @@ -1074,6 +1077,11 @@ std::string CConf::getLogFileRoot() const return m_logFileRoot; } +unsigned int CConf::getLogRotateLogs() const +{ + return m_logRotateLogs; +} + bool CConf::getCWIdEnabled() const { return m_cwIdEnabled; diff --git a/Conf.h b/Conf.h index 335d461..0ea44a9 100644 --- a/Conf.h +++ b/Conf.h @@ -54,6 +54,7 @@ public: unsigned int getLogFileLevel() const; std::string getLogFilePath() const; std::string getLogFileRoot() const; + unsigned int getLogRotateLogs() const; // The CW ID section bool getCWIdEnabled() const; @@ -337,6 +338,7 @@ private: unsigned int m_logFileLevel; std::string m_logFilePath; std::string m_logFileRoot; + unsigned int m_logRotateLogs; bool m_cwIdEnabled; unsigned int m_cwIdTime; diff --git a/Log.cpp b/Log.cpp index 1d5ad29..6e573a8 100644 --- a/Log.cpp +++ b/Log.cpp @@ -41,6 +41,8 @@ static bool m_daemon = false; static unsigned int m_displayLevel = 2U; +static unsigned int m_rotateLogs = 1U; + static struct tm m_tm; static char LEVELS[] = " DMIWEF"; @@ -66,10 +68,16 @@ static bool LogOpen() } char filename[200U]; + char timestamp[37U] = ""; + + if (m_rotateLogs) { + ::sprintf(timestamp, "-%04d-%02d-%02d", tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday); + } + #if defined(_WIN32) || defined(_WIN64) - ::sprintf(filename, "%s\\%s-%04d-%02d-%02d.log", m_filePath.c_str(), m_fileRoot.c_str(), tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday); + ::sprintf(filename, "%s\\%s%s.log", m_filePath.c_str(), m_fileRoot.c_str(), timestamp); #else - ::sprintf(filename, "%s/%s-%04d-%02d-%02d.log", m_filePath.c_str(), m_fileRoot.c_str(), tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday); + ::sprintf(filename, "%s/%s%s.log", m_filePath.c_str(), m_fileRoot.c_str(), timestamp); #endif if ((m_fpLog = ::fopen(filename, "a+t")) != NULL) { @@ -86,12 +94,13 @@ static bool LogOpen() return status; } -bool LogInitialise(bool daemon, const std::string& filePath, const std::string& fileRoot, unsigned int fileLevel, unsigned int displayLevel) +bool LogInitialise(bool daemon, const std::string& filePath, const std::string& fileRoot, unsigned int fileLevel, unsigned int displayLevel, unsigned int rotateLogs) { m_filePath = filePath; m_fileRoot = fileRoot; m_fileLevel = fileLevel; m_displayLevel = displayLevel; + m_rotateLogs = rotateLogs; m_daemon = daemon; if (m_daemon) diff --git a/Log.h b/Log.h index 0d00653..0138a6c 100644 --- a/Log.h +++ b/Log.h @@ -30,7 +30,7 @@ extern void Log(unsigned int level, const char* fmt, ...); -extern bool LogInitialise(bool daemon, const std::string& filePath, const std::string& fileRoot, unsigned int fileLevel, unsigned int displayLevel); +extern bool LogInitialise(bool daemon, const std::string& filePath, const std::string& fileRoot, unsigned int fileLevel, unsigned int displayLevel, unsigned int rotateLogs); extern void LogFinalise(); #endif diff --git a/MMDVM.ini b/MMDVM.ini index ccc561b..2ad20f6 100644 --- a/MMDVM.ini +++ b/MMDVM.ini @@ -26,6 +26,7 @@ DisplayLevel=1 FileLevel=1 FilePath=. FileRoot=MMDVM +RotateLogs=1 [CW Id] Enable=1 diff --git a/MMDVMHost.cpp b/MMDVMHost.cpp index f174b83..512af87 100644 --- a/MMDVMHost.cpp +++ b/MMDVMHost.cpp @@ -242,9 +242,9 @@ int CMMDVMHost::run() #endif #if !defined(_WIN32) && !defined(_WIN64) - ret = ::LogInitialise(m_daemon, m_conf.getLogFilePath(), m_conf.getLogFileRoot(), m_conf.getLogFileLevel(), m_conf.getLogDisplayLevel()); + ret = ::LogInitialise(m_daemon, m_conf.getLogFilePath(), m_conf.getLogFileRoot(), m_conf.getLogFileLevel(), m_conf.getLogDisplayLevel(), m_conf.getLogRotateLogs()); #else - ret = ::LogInitialise(false, m_conf.getLogFilePath(), m_conf.getLogFileRoot(), m_conf.getLogFileLevel(), m_conf.getLogDisplayLevel()); + ret = ::LogInitialise(false, m_conf.getLogFilePath(), m_conf.getLogFileRoot(), m_conf.getLogFileLevel(), m_conf.getLogDisplayLevel(), m_conf.getLogRotateLogs()); #endif if (!ret) { ::fprintf(stderr, "MMDVMHost: unable to open the log file\n"); diff --git a/RemoteCommand.cpp b/RemoteCommand.cpp index fd96e46..33bd069 100644 --- a/RemoteCommand.cpp +++ b/RemoteCommand.cpp @@ -51,7 +51,7 @@ int main(int argc, char** argv) CRemoteCommand::CRemoteCommand(unsigned int port) : m_port(port) { - ::LogInitialise(false, ".", "RemoteCommand", 2U, 2U); + ::LogInitialise(false, ".", "RemoteCommand", 2U, 2U, 1U); } CRemoteCommand::~CRemoteCommand() From 7a5bbda2487947b15ecadacef9dbe7aa60da4ef2 Mon Sep 17 00:00:00 2001 From: Jacob Schramm Date: Thu, 29 Oct 2020 22:42:25 +0100 Subject: [PATCH 7/8] Changing RotateLogs to TimestampLogs --- Conf.cpp | 10 +++++----- Conf.h | 4 ++-- Log.cpp | 8 ++++---- Log.h | 2 +- MMDVM.ini | 2 +- MMDVMHost.cpp | 4 ++-- 6 files changed, 15 insertions(+), 15 deletions(-) diff --git a/Conf.cpp b/Conf.cpp index 890dde5..a056182 100644 --- a/Conf.cpp +++ b/Conf.cpp @@ -82,7 +82,7 @@ m_logDisplayLevel(0U), m_logFileLevel(0U), m_logFilePath(), m_logFileRoot(), -m_logRotateLogs(1U), +m_logTimestampLogs(1U), m_cwIdEnabled(false), m_cwIdTime(10U), m_cwIdCallsign(), @@ -454,8 +454,8 @@ bool CConf::read() m_logFileLevel = (unsigned int)::atoi(value); else if (::strcmp(key, "DisplayLevel") == 0) m_logDisplayLevel = (unsigned int)::atoi(value); - else if (::strcmp(key, "RotateLogs") == 0) - m_logRotateLogs = (unsigned int)::atoi(value); + else if (::strcmp(key, "TimestampLogs") == 0) + m_logTimestampLogs = (unsigned int)::atoi(value); } else if (section == SECTION_CWID) { if (::strcmp(key, "Enable") == 0) m_cwIdEnabled = ::atoi(value) == 1; @@ -1077,9 +1077,9 @@ std::string CConf::getLogFileRoot() const return m_logFileRoot; } -unsigned int CConf::getLogRotateLogs() const +unsigned int CConf::getLogTimestampLogs() const { - return m_logRotateLogs; + return m_logTimestampLogs; } bool CConf::getCWIdEnabled() const diff --git a/Conf.h b/Conf.h index 0ea44a9..c7b611a 100644 --- a/Conf.h +++ b/Conf.h @@ -54,7 +54,7 @@ public: unsigned int getLogFileLevel() const; std::string getLogFilePath() const; std::string getLogFileRoot() const; - unsigned int getLogRotateLogs() const; + unsigned int getLogTimestampLogs() const; // The CW ID section bool getCWIdEnabled() const; @@ -338,7 +338,7 @@ private: unsigned int m_logFileLevel; std::string m_logFilePath; std::string m_logFileRoot; - unsigned int m_logRotateLogs; + unsigned int m_logTimestampLogs; bool m_cwIdEnabled; unsigned int m_cwIdTime; diff --git a/Log.cpp b/Log.cpp index 6e573a8..c0a0162 100644 --- a/Log.cpp +++ b/Log.cpp @@ -41,7 +41,7 @@ static bool m_daemon = false; static unsigned int m_displayLevel = 2U; -static unsigned int m_rotateLogs = 1U; +static unsigned int m_timestampLogs = 1U; static struct tm m_tm; @@ -70,7 +70,7 @@ static bool LogOpen() char filename[200U]; char timestamp[37U] = ""; - if (m_rotateLogs) { + if (m_timestampLogs) { ::sprintf(timestamp, "-%04d-%02d-%02d", tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday); } @@ -94,13 +94,13 @@ static bool LogOpen() return status; } -bool LogInitialise(bool daemon, const std::string& filePath, const std::string& fileRoot, unsigned int fileLevel, unsigned int displayLevel, unsigned int rotateLogs) +bool LogInitialise(bool daemon, const std::string& filePath, const std::string& fileRoot, unsigned int fileLevel, unsigned int displayLevel, unsigned int timestampLogs) { m_filePath = filePath; m_fileRoot = fileRoot; m_fileLevel = fileLevel; m_displayLevel = displayLevel; - m_rotateLogs = rotateLogs; + m_timestampLogs = timestampLogs; m_daemon = daemon; if (m_daemon) diff --git a/Log.h b/Log.h index 0138a6c..f287f35 100644 --- a/Log.h +++ b/Log.h @@ -30,7 +30,7 @@ extern void Log(unsigned int level, const char* fmt, ...); -extern bool LogInitialise(bool daemon, const std::string& filePath, const std::string& fileRoot, unsigned int fileLevel, unsigned int displayLevel, unsigned int rotateLogs); +extern bool LogInitialise(bool daemon, const std::string& filePath, const std::string& fileRoot, unsigned int fileLevel, unsigned int displayLevel, unsigned int timestampLogs); extern void LogFinalise(); #endif diff --git a/MMDVM.ini b/MMDVM.ini index 2ad20f6..239cb94 100644 --- a/MMDVM.ini +++ b/MMDVM.ini @@ -26,7 +26,7 @@ DisplayLevel=1 FileLevel=1 FilePath=. FileRoot=MMDVM -RotateLogs=1 +TimestampLogs=1 [CW Id] Enable=1 diff --git a/MMDVMHost.cpp b/MMDVMHost.cpp index 512af87..5003cf9 100644 --- a/MMDVMHost.cpp +++ b/MMDVMHost.cpp @@ -242,9 +242,9 @@ int CMMDVMHost::run() #endif #if !defined(_WIN32) && !defined(_WIN64) - ret = ::LogInitialise(m_daemon, m_conf.getLogFilePath(), m_conf.getLogFileRoot(), m_conf.getLogFileLevel(), m_conf.getLogDisplayLevel(), m_conf.getLogRotateLogs()); + ret = ::LogInitialise(m_daemon, m_conf.getLogFilePath(), m_conf.getLogFileRoot(), m_conf.getLogFileLevel(), m_conf.getLogDisplayLevel(), m_conf.getLogTimestampLogs()); #else - ret = ::LogInitialise(false, m_conf.getLogFilePath(), m_conf.getLogFileRoot(), m_conf.getLogFileLevel(), m_conf.getLogDisplayLevel(), m_conf.getLogRotateLogs()); + ret = ::LogInitialise(false, m_conf.getLogFilePath(), m_conf.getLogFileRoot(), m_conf.getLogFileLevel(), m_conf.getLogDisplayLevel(), m_conf.getLogTimestampLogs()); #endif if (!ret) { ::fprintf(stderr, "MMDVMHost: unable to open the log file\n"); From 61afb194c5015fbe3e3e95851690e3788179726c Mon Sep 17 00:00:00 2001 From: Jonathan Naylor Date: Fri, 30 Oct 2020 13:34:13 +0000 Subject: [PATCH 8/8] Revert "Merge pull request #648 from xfxian/logrotate" This reverts commit 993239484087e69710298ad67ed32baa5b31ba40, reversing changes made to cfc313e5b901a26c2dc7d186beb4123e8c47fd11. --- .gitignore | 1 - Conf.cpp | 8 -------- Conf.h | 2 -- Log.cpp | 15 +++------------ Log.h | 2 +- MMDVM.ini | 1 - MMDVMHost.cpp | 4 ++-- RemoteCommand.cpp | 2 +- 8 files changed, 7 insertions(+), 28 deletions(-) diff --git a/.gitignore b/.gitignore index 4009b5a..14ab1c8 100644 --- a/.gitignore +++ b/.gitignore @@ -15,6 +15,5 @@ RemoteCommand *.user *.VC.db .vs -.vscode *.ambe GitVersion.h diff --git a/Conf.cpp b/Conf.cpp index a056182..7491717 100644 --- a/Conf.cpp +++ b/Conf.cpp @@ -82,7 +82,6 @@ m_logDisplayLevel(0U), m_logFileLevel(0U), m_logFilePath(), m_logFileRoot(), -m_logTimestampLogs(1U), m_cwIdEnabled(false), m_cwIdTime(10U), m_cwIdCallsign(), @@ -454,8 +453,6 @@ bool CConf::read() m_logFileLevel = (unsigned int)::atoi(value); else if (::strcmp(key, "DisplayLevel") == 0) m_logDisplayLevel = (unsigned int)::atoi(value); - else if (::strcmp(key, "TimestampLogs") == 0) - m_logTimestampLogs = (unsigned int)::atoi(value); } else if (section == SECTION_CWID) { if (::strcmp(key, "Enable") == 0) m_cwIdEnabled = ::atoi(value) == 1; @@ -1077,11 +1074,6 @@ std::string CConf::getLogFileRoot() const return m_logFileRoot; } -unsigned int CConf::getLogTimestampLogs() const -{ - return m_logTimestampLogs; -} - bool CConf::getCWIdEnabled() const { return m_cwIdEnabled; diff --git a/Conf.h b/Conf.h index c7b611a..335d461 100644 --- a/Conf.h +++ b/Conf.h @@ -54,7 +54,6 @@ public: unsigned int getLogFileLevel() const; std::string getLogFilePath() const; std::string getLogFileRoot() const; - unsigned int getLogTimestampLogs() const; // The CW ID section bool getCWIdEnabled() const; @@ -338,7 +337,6 @@ private: unsigned int m_logFileLevel; std::string m_logFilePath; std::string m_logFileRoot; - unsigned int m_logTimestampLogs; bool m_cwIdEnabled; unsigned int m_cwIdTime; diff --git a/Log.cpp b/Log.cpp index c0a0162..1d5ad29 100644 --- a/Log.cpp +++ b/Log.cpp @@ -41,8 +41,6 @@ static bool m_daemon = false; static unsigned int m_displayLevel = 2U; -static unsigned int m_timestampLogs = 1U; - static struct tm m_tm; static char LEVELS[] = " DMIWEF"; @@ -68,16 +66,10 @@ static bool LogOpen() } char filename[200U]; - char timestamp[37U] = ""; - - if (m_timestampLogs) { - ::sprintf(timestamp, "-%04d-%02d-%02d", tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday); - } - #if defined(_WIN32) || defined(_WIN64) - ::sprintf(filename, "%s\\%s%s.log", m_filePath.c_str(), m_fileRoot.c_str(), timestamp); + ::sprintf(filename, "%s\\%s-%04d-%02d-%02d.log", m_filePath.c_str(), m_fileRoot.c_str(), tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday); #else - ::sprintf(filename, "%s/%s%s.log", m_filePath.c_str(), m_fileRoot.c_str(), timestamp); + ::sprintf(filename, "%s/%s-%04d-%02d-%02d.log", m_filePath.c_str(), m_fileRoot.c_str(), tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday); #endif if ((m_fpLog = ::fopen(filename, "a+t")) != NULL) { @@ -94,13 +86,12 @@ static bool LogOpen() return status; } -bool LogInitialise(bool daemon, const std::string& filePath, const std::string& fileRoot, unsigned int fileLevel, unsigned int displayLevel, unsigned int timestampLogs) +bool LogInitialise(bool daemon, const std::string& filePath, const std::string& fileRoot, unsigned int fileLevel, unsigned int displayLevel) { m_filePath = filePath; m_fileRoot = fileRoot; m_fileLevel = fileLevel; m_displayLevel = displayLevel; - m_timestampLogs = timestampLogs; m_daemon = daemon; if (m_daemon) diff --git a/Log.h b/Log.h index f287f35..0d00653 100644 --- a/Log.h +++ b/Log.h @@ -30,7 +30,7 @@ extern void Log(unsigned int level, const char* fmt, ...); -extern bool LogInitialise(bool daemon, const std::string& filePath, const std::string& fileRoot, unsigned int fileLevel, unsigned int displayLevel, unsigned int timestampLogs); +extern bool LogInitialise(bool daemon, const std::string& filePath, const std::string& fileRoot, unsigned int fileLevel, unsigned int displayLevel); extern void LogFinalise(); #endif diff --git a/MMDVM.ini b/MMDVM.ini index 239cb94..ccc561b 100644 --- a/MMDVM.ini +++ b/MMDVM.ini @@ -26,7 +26,6 @@ DisplayLevel=1 FileLevel=1 FilePath=. FileRoot=MMDVM -TimestampLogs=1 [CW Id] Enable=1 diff --git a/MMDVMHost.cpp b/MMDVMHost.cpp index 5003cf9..f174b83 100644 --- a/MMDVMHost.cpp +++ b/MMDVMHost.cpp @@ -242,9 +242,9 @@ int CMMDVMHost::run() #endif #if !defined(_WIN32) && !defined(_WIN64) - ret = ::LogInitialise(m_daemon, m_conf.getLogFilePath(), m_conf.getLogFileRoot(), m_conf.getLogFileLevel(), m_conf.getLogDisplayLevel(), m_conf.getLogTimestampLogs()); + ret = ::LogInitialise(m_daemon, m_conf.getLogFilePath(), m_conf.getLogFileRoot(), m_conf.getLogFileLevel(), m_conf.getLogDisplayLevel()); #else - ret = ::LogInitialise(false, m_conf.getLogFilePath(), m_conf.getLogFileRoot(), m_conf.getLogFileLevel(), m_conf.getLogDisplayLevel(), m_conf.getLogTimestampLogs()); + ret = ::LogInitialise(false, m_conf.getLogFilePath(), m_conf.getLogFileRoot(), m_conf.getLogFileLevel(), m_conf.getLogDisplayLevel()); #endif if (!ret) { ::fprintf(stderr, "MMDVMHost: unable to open the log file\n"); diff --git a/RemoteCommand.cpp b/RemoteCommand.cpp index 33bd069..fd96e46 100644 --- a/RemoteCommand.cpp +++ b/RemoteCommand.cpp @@ -51,7 +51,7 @@ int main(int argc, char** argv) CRemoteCommand::CRemoteCommand(unsigned int port) : m_port(port) { - ::LogInitialise(false, ".", "RemoteCommand", 2U, 2U, 1U); + ::LogInitialise(false, ".", "RemoteCommand", 2U, 2U); } CRemoteCommand::~CRemoteCommand()