From d30b423c07f17c07da2bcd2caf31d113e995cb6c Mon Sep 17 00:00:00 2001 From: Aron Budea Date: Wed, 3 Aug 2022 04:04:49 +0200 Subject: [PATCH] Replace #ifdef-s with #if-s, and enable -Wundef ...for variables coming from configure.ac. Signed-off-by: Aron Budea Change-Id: I39ebd21c4cb56d2a3bd38fdc35dc59b5f1fd4b49 --- common/SigUtil.cpp | 4 ++-- common/Util.hpp | 2 ++ configure.ac | 8 +++++--- kit/ChildSession.cpp | 8 ++++---- kit/ChildSession.hpp | 2 +- net/HttpRequest.hpp | 2 +- wsd/COOLWSD.cpp | 12 ++++++------ wsd/ClientSession.cpp | 4 ++-- wsd/ClientSession.hpp | 2 +- wsd/DocumentBroker.cpp | 2 +- wsd/HostUtil.cpp | 6 +++--- wsd/Storage.cpp | 4 ++-- 12 files changed, 30 insertions(+), 26 deletions(-) diff --git a/common/SigUtil.cpp b/common/SigUtil.cpp index ff10d68c4..64334cab7 100644 --- a/common/SigUtil.cpp +++ b/common/SigUtil.cpp @@ -267,7 +267,7 @@ namespace SigUtil #ifdef SIGSTKFLT CASE(STKFLT); #endif -#if defined(SIGIO) && SIGIO != SIGPOLL +#if defined(SIGIO) && defined(SIGPOLL) && SIGIO != SIGPOLL CASE(IO); #endif #ifdef SIGPWR @@ -277,7 +277,7 @@ namespace SigUtil CASE(LOST); #endif CASE(WINCH); -#if defined(SIGINFO) && SIGINFO != SIGPWR +#if defined(SIGINFO) && defined(SIGPWR) && SIGINFO != SIGPWR CASE(INFO); #endif #undef CASE diff --git a/common/Util.hpp b/common/Util.hpp index 49600dbbf..b164e0ec8 100644 --- a/common/Util.hpp +++ b/common/Util.hpp @@ -7,6 +7,8 @@ #pragma once +#include + #include #include #include diff --git a/configure.ac b/configure.ac index b5c4d2ec8..086743a10 100644 --- a/configure.ac +++ b/configure.ac @@ -835,7 +835,7 @@ AC_SUBST(VEREIGN_URL) # Test for build environment AS_IF([test "$ENABLE_GTKAPP" != true], -[CXXFLAGS="$CXXFLAGS -Wall -Wextra -Wshadow"]) +[CXXFLAGS="$CXXFLAGS -Wall -Wextra -Wshadow -Wundef"]) CFLAGS="$CFLAGS -Wall -Wextra" @@ -1379,7 +1379,8 @@ else fi AS_IF([test "$enable_feature_lock" = "yes"], - [AC_DEFINE([ENABLE_FEATURE_LOCK],1,[Whether to compile and enable feature locking])]) + [AC_DEFINE([ENABLE_FEATURE_LOCK],1,[Whether to compile and enable feature locking])], + [AC_DEFINE([ENABLE_FEATURE_LOCK],0,[Whether to compile and enable feature locking])]) LOCKED_COMMANDS= if test "$enable_feature_lock" = "yes"; then @@ -1493,7 +1494,8 @@ AC_SUBST(UNLOCK_LINK_PER_HOST) AM_SUBST_NOTMAKE(UNLOCK_LINK_PER_HOST) AS_IF([test "$enable_feature_restriction" = "yes"], - [AC_DEFINE([ENABLE_FEATURE_RESTRICTION],1,[Whether to compile and enable feature restrictions])]) + [AC_DEFINE([ENABLE_FEATURE_RESTRICTION],1,[Whether to compile and enable feature restrictions])], + [AC_DEFINE([ENABLE_FEATURE_RESTRICTION],0,[Whether to compile and enable feature restrictions])]) FEATURE_RESTRICTION_CONFIGURATION= if test "$enable_feature_restriction" = "yes"; then diff --git a/kit/ChildSession.cpp b/kit/ChildSession.cpp index 704f9235c..9b2e00c1e 100644 --- a/kit/ChildSession.cpp +++ b/kit/ChildSession.cpp @@ -298,7 +298,7 @@ bool ChildSession::_handleInput(const char *buffer, int length) } else if (tokens.equals(0, "blockingcommandstatus")) { -#if defined(ENABLE_FEATURE_LOCK) || defined(ENABLE_FEATURE_RESTRICTION) +#if ENABLE_FEATURE_LOCK || ENABLE_FEATURE_RESTRICTION return updateBlockingCommandStatus(tokens); #endif } @@ -706,7 +706,7 @@ bool ChildSession::loadDocument(const StringVector& tokens) assert(!getDocURL().empty()); assert(!getJailedFilePath().empty()); -#if defined(ENABLE_DEBUG) && !MOBILEAPP +#if ENABLE_DEBUG && !MOBILEAPP if (std::getenv("PAUSEFORDEBUGGER")) { std::cerr << getDocURL() << " paused waiting for a debugger to attach: " << getpid() << std::endl; @@ -2726,7 +2726,7 @@ int ChildSession::getSpeed() return _cursorInvalidatedEvent.size(); } -#if defined(ENABLE_FEATURE_LOCK) || defined(ENABLE_FEATURE_RESTRICTION) +#if ENABLE_FEATURE_LOCK || ENABLE_FEATURE_RESTRICTION bool ChildSession::updateBlockingCommandStatus(const StringVector& tokens) { std::string lockStatus, restrictedStatus; @@ -3089,7 +3089,7 @@ void ChildSession::loKitCallback(const int type, const std::string& payload) break; case LOK_COMMAND_BLOCKED: { -#if defined(ENABLE_FEATURE_LOCK) || defined(ENABLE_FEATURE_RESTRICTION) +#if ENABLE_FEATURE_LOCK || ENABLE_FEATURE_RESTRICTION LOG_INF("COMMAND_BLOCKED: " << payload); Parser parser; Poco::Dynamic::Var var = parser.parse(payload); diff --git a/kit/ChildSession.hpp b/kit/ChildSession.hpp index 4ad7be4fd..d77ec4383 100644 --- a/kit/ChildSession.hpp +++ b/kit/ChildSession.hpp @@ -302,7 +302,7 @@ private: bool exportSignAndUploadDocument(const char* buffer, int length, const StringVector& tokens); bool renderShapeSelection(const StringVector& tokens); bool removeTextContext(const StringVector& tokens); -#if defined(ENABLE_FEATURE_LOCK) || defined(ENABLE_FEATURE_RESTRICTION) +#if ENABLE_FEATURE_LOCK || ENABLE_FEATURE_RESTRICTION bool updateBlockingCommandStatus(const StringVector& tokens); std::string getBlockedCommandType(std::string command); #endif diff --git a/net/HttpRequest.hpp b/net/HttpRequest.hpp index b90ae5092..844358822 100644 --- a/net/HttpRequest.hpp +++ b/net/HttpRequest.hpp @@ -866,7 +866,7 @@ private: { assert(!_host.empty() && portNumber > 0 && !_port.empty() && "Invalid hostname and portNumber for http::Sesssion"); -#ifdef ENABLE_DEBUG +#if ENABLE_DEBUG std::string scheme; std::string hostString; std::string portString; diff --git a/wsd/COOLWSD.cpp b/wsd/COOLWSD.cpp index 39e56c8d2..26f1e8f85 100644 --- a/wsd/COOLWSD.cpp +++ b/wsd/COOLWSD.cpp @@ -1185,7 +1185,7 @@ public: fetchAliasGroups(newAppConfig, remoteJson); -#ifdef ENABLE_FEATURE_LOCK +#if ENABLE_FEATURE_LOCK fetchLockedHostPatterns(newAppConfig, remoteJson); fetchLockedTranslations(newAppConfig, remoteJson); fetchUnlockImageUrl(newAppConfig, remoteJson); @@ -1198,7 +1198,7 @@ public: HostUtil::parseWopiHost(conf); -#ifdef ENABLE_FEATURE_LOCK +#if ENABLE_FEATURE_LOCK CommandControl::LockManager::parseLockedHost(conf); #endif @@ -1369,7 +1369,7 @@ public: newAppConfig.insert(std::make_pair(path + ".host", host)); newAppConfig.insert(std::make_pair(path + ".host[@allow]", booleanToString(allow))); -#ifdef ENABLE_FEATURE_LOCK +#if ENABLE_FEATURE_LOCK std::string unlockLink; JsonUtil::findJSONValue(group, "unlock_link", unlockLink); newAppConfig.insert(std::make_pair(path + ".unlock_link", unlockLink)); @@ -1950,7 +1950,7 @@ void COOLWSD::innerInitialize(Application& self) { "welcome.enable", "false" }, { "home_mode.enable", "false" }, { "feedback.show", "true" }, -#ifdef ENABLE_FEATURE_LOCK +#if ENABLE_FEATURE_LOCK { "feature_lock.locked_hosts[@allow]", "false"}, { "feature_lock.locked_hosts.fallback[@read_only]", "false"}, { "feature_lock.locked_hosts.fallback[@disabled_commands]", "false"}, @@ -1967,7 +1967,7 @@ void COOLWSD::innerInitialize(Application& self) { "feature_lock.impress_unlock_highlights", IMPRESS_UNLOCK_HIGHLIGHTS }, { "feature_lock.draw_unlock_highlights", DRAW_UNLOCK_HIGHLIGHTS }, #endif -#ifdef ENABLE_FEATURE_RESTRICTION +#if ENABLE_FEATURE_RESTRICTION { "restricted_commands", "" }, #endif { "user_interface.mode", "default" }, @@ -3608,7 +3608,7 @@ private: uri.substr(pos + ProxyRemoteLen), socket, ProxyRequestHandler::getProxyRatingServer()); } -#ifdef ENABLE_FEATURE_LOCK +#if ENABLE_FEATURE_LOCK else { const Poco::URI unlockImageUri = diff --git a/wsd/ClientSession.cpp b/wsd/ClientSession.cpp index 58b93befd..f81a283fc 100644 --- a/wsd/ClientSession.cpp +++ b/wsd/ClientSession.cpp @@ -1142,7 +1142,7 @@ bool ClientSession::loadDocument(const char* /*buffer*/, int /*length*/, { oss << " batch=" << getBatchMode(); } -#ifdef ENABLE_FEATURE_LOCK +#if ENABLE_FEATURE_LOCK sendLockedInfo(); #endif return forwardToChild(oss.str(), docBroker); @@ -1155,7 +1155,7 @@ bool ClientSession::loadDocument(const char* /*buffer*/, int /*length*/, return false; } -#ifdef ENABLE_FEATURE_LOCK +#if ENABLE_FEATURE_LOCK void ClientSession::sendLockedInfo() { Poco::JSON::Object::Ptr lockInfo = new Poco::JSON::Object(); diff --git a/wsd/ClientSession.hpp b/wsd/ClientSession.hpp index 172162238..747a0b0b9 100644 --- a/wsd/ClientSession.hpp +++ b/wsd/ClientSession.hpp @@ -233,7 +233,7 @@ public: /// Generate an access token for this session via proxy protocol. const std::string &getOrCreateProxyAccess(); -#ifdef ENABLE_FEATURE_LOCK +#if ENABLE_FEATURE_LOCK void sendLockedInfo(); #endif diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp index 623c959ed..67bbeaa4d 100644 --- a/wsd/DocumentBroker.cpp +++ b/wsd/DocumentBroker.cpp @@ -845,7 +845,7 @@ bool DocumentBroker::download(const std::shared_ptr& session, con } } -#ifdef ENABLE_FEATURE_RESTRICTION +#if ENABLE_FEATURE_RESTRICTION Object::Ptr restrictionInfo = new Object(); restrictionInfo->set("IsRestrictedUser", CommandControl::RestrictionManager::isRestrictedUser()); diff --git a/wsd/HostUtil.cpp b/wsd/HostUtil.cpp index 6155e3fbb..b3d5a10e4 100644 --- a/wsd/HostUtil.cpp +++ b/wsd/HostUtil.cpp @@ -80,7 +80,7 @@ void HostUtil::parseAliases(Poco::Util::LayeredConfiguration& conf) } AliasHosts.clear(); -#ifdef ENABLE_FEATURE_LOCK +#if ENABLE_FEATURE_LOCK CommandControl::LockManager::unlockLinkMap.clear(); #endif @@ -102,7 +102,7 @@ void HostUtil::parseAliases(Poco::Util::LayeredConfiguration& conf) try { const Poco::URI realUri(uri); -#ifdef ENABLE_FEATURE_LOCK +#if ENABLE_FEATURE_LOCK CommandControl::LockManager::mapUnlockLink(realUri.getHost(), path); #endif HostUtil::hostList.insert(realUri.getHost()); @@ -137,7 +137,7 @@ void HostUtil::parseAliases(Poco::Util::LayeredConfiguration& conf) const Poco::URI aUri(aliasUri.getScheme() + "://" + x + ':' + std::to_string(aliasUri.getPort())); AliasHosts.insert({ aUri.getAuthority(), realUri.getAuthority() }); -#ifdef ENABLE_FEATURE_LOCK +#if ENABLE_FEATURE_LOCK CommandControl::LockManager::mapUnlockLink(aUri.getHost(), path); #endif HostUtil::addWopiHost(aUri.getHost(), allow); diff --git a/wsd/Storage.cpp b/wsd/Storage.cpp index 6f967ebd4..4b05a8bed 100644 --- a/wsd/Storage.cpp +++ b/wsd/Storage.cpp @@ -96,7 +96,7 @@ void StorageBase::initialize() HostUtil::parseWopiHost(app.config()); } -#ifdef ENABLE_FEATURE_LOCK +#if ENABLE_FEATURE_LOCK CommandControl::LockManager::parseLockedHost(app.config()); #endif @@ -860,7 +860,7 @@ WopiStorage::WOPIFileInfo::WOPIFileInfo(const FileInfo &fileInfo, JsonUtil::findJSONValue(object, "BreadcrumbDocName", _breadcrumbDocName); JsonUtil::findJSONValue(object, "FileUrl", _fileUrl); -#ifdef ENABLE_FEATURE_LOCK +#if ENABLE_FEATURE_LOCK bool isUserLocked = false; JsonUtil::findJSONValue(object, "IsUserLocked", isUserLocked);