From 7d7eaa8dd35c23ed8de9112343ece3b5b7bdbd73 Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Tue, 21 Nov 2017 12:12:58 +0100 Subject: [PATCH 01/15] Replace boost::thread with std::thread --- icinga-app/icinga.cpp | 3 ++- lib/base/application.cpp | 5 +++-- lib/base/process.cpp | 3 ++- lib/base/socketevents-poll.cpp | 2 +- lib/base/socketevents.cpp | 4 ++-- lib/base/socketevents.hpp | 4 ++-- lib/base/threadpool.cpp | 2 +- lib/base/threadpool.hpp | 3 ++- lib/base/timer.cpp | 6 +++--- lib/base/utility.cpp | 3 ++- lib/checker/checkercomponent.cpp | 2 +- lib/checker/checkercomponent.hpp | 4 ++-- lib/compat/externalcommandlistener.cpp | 2 +- lib/compat/externalcommandlistener.hpp | 4 ++-- lib/compat/statusdatawriter.hpp | 1 - lib/livestatus/livestatuslistener.cpp | 4 ++-- lib/livestatus/livestatuslistener.hpp | 4 ++-- lib/remote/apilistener.cpp | 6 +++--- lib/remote/eventqueue.hpp | 1 - 19 files changed, 33 insertions(+), 30 deletions(-) diff --git a/icinga-app/icinga.cpp b/icinga-app/icinga.cpp index f5665c983..a0d75293c 100644 --- a/icinga-app/icinga.cpp +++ b/icinga-app/icinga.cpp @@ -35,6 +35,7 @@ #include "config.h" #include #include +#include #ifndef _WIN32 # include @@ -159,7 +160,7 @@ int Main(void) Application::DeclareRLimitProcesses(Application::GetDefaultRLimitProcesses()); Application::DeclareRLimitStack(Application::GetDefaultRLimitStack()); #endif /* __linux__ */ - Application::DeclareConcurrency(boost::thread::hardware_concurrency()); + Application::DeclareConcurrency(std::thread::hardware_concurrency()); ScriptGlobal::Set("AttachDebugger", false); diff --git a/lib/base/application.cpp b/lib/base/application.cpp index 43a69e893..23847c03b 100644 --- a/lib/base/application.cpp +++ b/lib/base/application.cpp @@ -40,6 +40,7 @@ #include #include #include +#include #ifdef __linux__ #include #endif /* __linux__ */ @@ -394,7 +395,7 @@ static void ReloadProcessCallback(const ProcessResult& pr) { l_Restarting = false; - boost::thread t(std::bind(&ReloadProcessCallbackInternal, pr)); + std::thread t(std::bind(&ReloadProcessCallbackInternal, pr)); t.detach(); } @@ -1508,7 +1509,7 @@ void Application::DeclareConcurrency(int ncpus) */ int Application::GetConcurrency(void) { - Value defaultConcurrency = boost::thread::hardware_concurrency(); + Value defaultConcurrency = std::thread::hardware_concurrency(); return ScriptGlobal::Get("Concurrency", &defaultConcurrency); } diff --git a/lib/base/process.cpp b/lib/base/process.cpp index 3d0cd5d3e..a8f354088 100644 --- a/lib/base/process.cpp +++ b/lib/base/process.cpp @@ -30,6 +30,7 @@ #include "base/json.hpp" #include #include +#include #include #ifndef _WIN32 @@ -539,7 +540,7 @@ void Process::ThreadInitialize(void) { /* Note to self: Make sure this runs _after_ we've daemonized. */ for (int tid = 0; tid < IOTHREADS; tid++) { - boost::thread t(std::bind(&Process::IOThreadProc, tid)); + std::thread t(std::bind(&Process::IOThreadProc, tid)); t.detach(); } } diff --git a/lib/base/socketevents-poll.cpp b/lib/base/socketevents-poll.cpp index 76c13cfc6..d141abe95 100644 --- a/lib/base/socketevents-poll.cpp +++ b/lib/base/socketevents-poll.cpp @@ -192,7 +192,7 @@ void SocketEventEnginePoll::ChangeEvents(SocketEvents *se, int events) it->second.Events = events; - if (se->m_EnginePrivate && boost::this_thread::get_id() == m_Threads[tid].get_id()) + if (se->m_EnginePrivate && std::this_thread::get_id() == m_Threads[tid].get_id()) ((pollfd *)se->m_EnginePrivate)->events = events; else m_FDChanged[tid] = true; diff --git a/lib/base/socketevents.cpp b/lib/base/socketevents.cpp index 00ca0c525..8b77da1a0 100644 --- a/lib/base/socketevents.cpp +++ b/lib/base/socketevents.cpp @@ -50,7 +50,7 @@ void SocketEventEngine::Start(void) InitializeThread(tid); - m_Threads[tid] = boost::thread(std::bind(&SocketEventEngine::ThreadProc, this, tid)); + m_Threads[tid] = std::thread(std::bind(&SocketEventEngine::ThreadProc, this, tid)); } } @@ -58,7 +58,7 @@ void SocketEventEngine::WakeUpThread(int sid, bool wait) { int tid = sid % SOCKET_IOTHREADS; - if (boost::this_thread::get_id() == m_Threads[tid].get_id()) + if (std::this_thread::get_id() == m_Threads[tid].get_id()) return; if (wait) { diff --git a/lib/base/socketevents.hpp b/lib/base/socketevents.hpp index b659cc321..c40d36430 100644 --- a/lib/base/socketevents.hpp +++ b/lib/base/socketevents.hpp @@ -22,7 +22,7 @@ #include "base/i2-base.hpp" #include "base/socket.hpp" -#include +#include #ifndef _WIN32 # include @@ -109,7 +109,7 @@ protected: virtual void Unregister(SocketEvents *se) = 0; virtual void ChangeEvents(SocketEvents *se, int events) = 0; - boost::thread m_Threads[SOCKET_IOTHREADS]; + std::thread m_Threads[SOCKET_IOTHREADS]; SOCKET m_EventFDs[SOCKET_IOTHREADS][2]; bool m_FDChanged[SOCKET_IOTHREADS]; boost::mutex m_EventMutex[SOCKET_IOTHREADS]; diff --git a/lib/base/threadpool.cpp b/lib/base/threadpool.cpp index 0c2925f9b..df5152d60 100644 --- a/lib/base/threadpool.cpp +++ b/lib/base/threadpool.cpp @@ -54,7 +54,7 @@ void ThreadPool::Start(void) for (size_t i = 0; i < sizeof(m_Queues) / sizeof(m_Queues[0]); i++) m_Queues[i].SpawnWorker(m_ThreadGroup); - m_MgmtThread = boost::thread(std::bind(&ThreadPool::ManagerThreadProc, this)); + m_MgmtThread = std::thread(std::bind(&ThreadPool::ManagerThreadProc, this)); } void ThreadPool::Stop(void) diff --git a/lib/base/threadpool.hpp b/lib/base/threadpool.hpp index d37ca8366..d49ffa414 100644 --- a/lib/base/threadpool.hpp +++ b/lib/base/threadpool.hpp @@ -26,6 +26,7 @@ #include #include #include +#include namespace icinga { @@ -121,7 +122,7 @@ private: boost::thread_group m_ThreadGroup; - boost::thread m_MgmtThread; + std::thread m_MgmtThread; boost::mutex m_MgmtMutex; boost::condition_variable m_MgmtCV; bool m_Stopped; diff --git a/lib/base/timer.cpp b/lib/base/timer.cpp index 9c1a2c4a1..3e6099da9 100644 --- a/lib/base/timer.cpp +++ b/lib/base/timer.cpp @@ -20,12 +20,12 @@ #include "base/timer.hpp" #include "base/debug.hpp" #include "base/utility.hpp" -#include #include #include #include #include #include +#include using namespace icinga; @@ -39,7 +39,7 @@ typedef boost::multi_index_container< static boost::mutex l_TimerMutex; static boost::condition_variable l_TimerCV; -static boost::thread l_TimerThread; +static std::thread l_TimerThread; static bool l_StopTimerThread; static TimerSet l_Timers; @@ -65,7 +65,7 @@ void Timer::Initialize(void) { boost::mutex::scoped_lock lock(l_TimerMutex); l_StopTimerThread = false; - l_TimerThread = boost::thread(&Timer::TimerThreadProc); + l_TimerThread = std::thread(&Timer::TimerThreadProc); } /** diff --git a/lib/base/utility.cpp b/lib/base/utility.cpp index d98aebbfb..02238f712 100644 --- a/lib/base/utility.cpp +++ b/lib/base/utility.cpp @@ -28,6 +28,7 @@ #include "base/objectlock.hpp" #include #include +#include #include #include #include @@ -1221,7 +1222,7 @@ String Utility::GetThreadName(void) if (!name) { std::ostringstream idbuf; - idbuf << boost::this_thread::get_id(); + idbuf << std::this_thread::get_id(); return idbuf.str(); } diff --git a/lib/checker/checkercomponent.cpp b/lib/checker/checkercomponent.cpp index a943872b9..406bca10b 100644 --- a/lib/checker/checkercomponent.cpp +++ b/lib/checker/checkercomponent.cpp @@ -79,7 +79,7 @@ void CheckerComponent::Start(bool runtimeCreated) << "'" << GetName() << "' started."; - m_Thread = boost::thread(std::bind(&CheckerComponent::CheckThreadProc, this)); + m_Thread = std::thread(std::bind(&CheckerComponent::CheckThreadProc, this)); m_ResultTimer = new Timer(); m_ResultTimer->SetInterval(5); diff --git a/lib/checker/checkercomponent.hpp b/lib/checker/checkercomponent.hpp index 988d3d180..2459e8958 100644 --- a/lib/checker/checkercomponent.hpp +++ b/lib/checker/checkercomponent.hpp @@ -25,12 +25,12 @@ #include "base/configobject.hpp" #include "base/timer.hpp" #include "base/utility.hpp" -#include #include #include #include #include #include +#include namespace icinga { @@ -91,7 +91,7 @@ private: boost::mutex m_Mutex; boost::condition_variable m_CV; bool m_Stopped; - boost::thread m_Thread; + std::thread m_Thread; CheckableSet m_IdleCheckables; CheckableSet m_PendingCheckables; diff --git a/lib/compat/externalcommandlistener.cpp b/lib/compat/externalcommandlistener.cpp index 040255160..b426f3563 100644 --- a/lib/compat/externalcommandlistener.cpp +++ b/lib/compat/externalcommandlistener.cpp @@ -54,7 +54,7 @@ void ExternalCommandListener::Start(bool runtimeCreated) << "'" << GetName() << "' started."; #ifndef _WIN32 - m_CommandThread = boost::thread(std::bind(&ExternalCommandListener::CommandPipeThread, this, GetCommandPath())); + m_CommandThread = std::thread(std::bind(&ExternalCommandListener::CommandPipeThread, this, GetCommandPath())); m_CommandThread.detach(); #endif /* _WIN32 */ } diff --git a/lib/compat/externalcommandlistener.hpp b/lib/compat/externalcommandlistener.hpp index 02df0ded3..b40a1c940 100644 --- a/lib/compat/externalcommandlistener.hpp +++ b/lib/compat/externalcommandlistener.hpp @@ -24,7 +24,7 @@ #include "base/objectlock.hpp" #include "base/timer.hpp" #include "base/utility.hpp" -#include +#include #include namespace icinga @@ -47,7 +47,7 @@ protected: private: #ifndef _WIN32 - boost::thread m_CommandThread; + std::thread m_CommandThread; void CommandPipeThread(const String& commandPath); #endif /* _WIN32 */ diff --git a/lib/compat/statusdatawriter.hpp b/lib/compat/statusdatawriter.hpp index 3a0460fd3..4b4e234d5 100644 --- a/lib/compat/statusdatawriter.hpp +++ b/lib/compat/statusdatawriter.hpp @@ -28,7 +28,6 @@ #include "icinga/compatutility.hpp" #include "base/timer.hpp" #include "base/utility.hpp" -#include #include namespace icinga diff --git a/lib/livestatus/livestatuslistener.cpp b/lib/livestatus/livestatuslistener.cpp index ae0cbc1e6..3fc7391ed 100644 --- a/lib/livestatus/livestatuslistener.cpp +++ b/lib/livestatus/livestatuslistener.cpp @@ -82,7 +82,7 @@ void LivestatusListener::Start(bool runtimeCreated) m_Listener = socket; - m_Thread = boost::thread(std::bind(&LivestatusListener::ServerThreadProc, this)); + m_Thread = std::thread(std::bind(&LivestatusListener::ServerThreadProc, this)); Log(LogInformation, "LivestatusListener") << "Created TCP socket listening on host '" << GetBindHost() << "' port '" << GetBindPort() << "'."; @@ -110,7 +110,7 @@ void LivestatusListener::Start(bool runtimeCreated) m_Listener = socket; - m_Thread = boost::thread(std::bind(&LivestatusListener::ServerThreadProc, this)); + m_Thread = std::thread(std::bind(&LivestatusListener::ServerThreadProc, this)); Log(LogInformation, "LivestatusListener") << "Created UNIX socket in '" << GetSocketPath() << "'."; diff --git a/lib/livestatus/livestatuslistener.hpp b/lib/livestatus/livestatuslistener.hpp index 56be37c05..6f23f6040 100644 --- a/lib/livestatus/livestatuslistener.hpp +++ b/lib/livestatus/livestatuslistener.hpp @@ -24,7 +24,7 @@ #include "livestatus/livestatuslistener.thpp" #include "livestatus/livestatusquery.hpp" #include "base/socket.hpp" -#include +#include using namespace icinga; @@ -56,7 +56,7 @@ private: void ClientHandler(const Socket::Ptr& client); Socket::Ptr m_Listener; - boost::thread m_Thread; + std::thread m_Thread; }; } diff --git a/lib/remote/apilistener.cpp b/lib/remote/apilistener.cpp index 60c75210d..b64b3c3dd 100644 --- a/lib/remote/apilistener.cpp +++ b/lib/remote/apilistener.cpp @@ -332,7 +332,7 @@ bool ApiListener::AddListener(const String& node, const String& service) return false; } - boost::thread thread(std::bind(&ApiListener::ListenerThreadProc, this, server)); + std::thread thread(std::bind(&ApiListener::ListenerThreadProc, this, server)); thread.detach(); m_Servers.insert(server); @@ -349,7 +349,7 @@ void ApiListener::ListenerThreadProc(const Socket::Ptr& server) for (;;) { try { Socket::Ptr client = server->Accept(); - boost::thread thread(std::bind(&ApiListener::NewClientHandler, this, client, String(), RoleServer)); + std::thread thread(std::bind(&ApiListener::NewClientHandler, this, client, String(), RoleServer)); thread.detach(); } catch (const std::exception&) { Log(LogCritical, "ApiListener", "Cannot accept new connection."); @@ -744,7 +744,7 @@ void ApiListener::ApiReconnectTimerHandler(void) continue; } - boost::thread thread(std::bind(&ApiListener::AddConnection, this, endpoint)); + std::thread thread(std::bind(&ApiListener::AddConnection, this, endpoint)); thread.detach(); } } diff --git a/lib/remote/eventqueue.hpp b/lib/remote/eventqueue.hpp index a9e66ee13..893fd8efe 100644 --- a/lib/remote/eventqueue.hpp +++ b/lib/remote/eventqueue.hpp @@ -23,7 +23,6 @@ #include "remote/httphandler.hpp" #include "base/object.hpp" #include "config/expression.hpp" -#include #include #include #include From 300d4244591d45e9f05d4a521190cad0d9dc2cdb Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Tue, 21 Nov 2017 12:28:09 +0100 Subject: [PATCH 02/15] Use std::promise instead of boost::promise --- lib/config/configcompiler.hpp | 3 ++- lib/config/expression.hpp | 1 - 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/config/configcompiler.hpp b/lib/config/configcompiler.hpp index cd5395c8d..ac9f38a5d 100644 --- a/lib/config/configcompiler.hpp +++ b/lib/config/configcompiler.hpp @@ -26,6 +26,7 @@ #include "base/registry.hpp" #include "base/initialize.hpp" #include "base/singleton.hpp" +#include #include #include @@ -127,7 +128,7 @@ public: static bool HasZoneConfigAuthority(const String& zoneName); private: - boost::promise > m_Promise; + std::promise > m_Promise; String m_Path; std::istream *m_Input; diff --git a/lib/config/expression.hpp b/lib/config/expression.hpp index bc90ef481..59a16f6e1 100644 --- a/lib/config/expression.hpp +++ b/lib/config/expression.hpp @@ -28,7 +28,6 @@ #include "base/exception.hpp" #include "base/scriptframe.hpp" #include "base/convert.hpp" -#include #include namespace icinga From 245feca0e7efb9f880f1de56d7ffa8b7fdd76a23 Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Tue, 21 Nov 2017 13:03:51 +0100 Subject: [PATCH 03/15] Move the Timer::Holder class to timer.cpp --- lib/base/timer.cpp | 35 ++++++++++++++++++++++++++++++++--- lib/base/timer.hpp | 28 +++------------------------- 2 files changed, 35 insertions(+), 28 deletions(-) diff --git a/lib/base/timer.cpp b/lib/base/timer.cpp index 3e6099da9..2a583b694 100644 --- a/lib/base/timer.cpp +++ b/lib/base/timer.cpp @@ -29,11 +29,40 @@ using namespace icinga; +namespace icinga { + +class TimerHolder { +public: + TimerHolder(Timer *timer) + : m_Timer(timer) + { } + + inline Timer *GetObject(void) const + { + return m_Timer; + } + + inline double GetNextUnlocked(void) const + { + return m_Timer->m_Next; + } + + operator Timer *(void) const + { + return m_Timer; + } + +private: + Timer *m_Timer; +}; + +} + typedef boost::multi_index_container< - Timer::Holder, + TimerHolder, boost::multi_index::indexed_by< - boost::multi_index::ordered_unique >, - boost::multi_index::ordered_non_unique > + boost::multi_index::ordered_unique >, + boost::multi_index::ordered_non_unique > > > TimerSet; diff --git a/lib/base/timer.hpp b/lib/base/timer.hpp index fbae485e8..d10d1dbe0 100644 --- a/lib/base/timer.hpp +++ b/lib/base/timer.hpp @@ -26,6 +26,8 @@ namespace icinga { +class TimerHolder; + /** * A timer that periodically triggers an event. * @@ -52,31 +54,6 @@ public: boost::signals2::signal OnTimerExpired; - class Holder { - public: - Holder(Timer *timer) - : m_Timer(timer) - { } - - inline Timer *GetObject(void) const - { - return m_Timer; - } - - inline double GetNextUnlocked(void) const - { - return m_Timer->m_Next; - } - - operator Timer *(void) const - { - return m_Timer; - } - - private: - Timer *m_Timer; - }; - private: double m_Interval; /**< The interval of the timer. */ double m_Next; /**< When the next event should happen. */ @@ -92,6 +69,7 @@ private: static void Uninitialize(void); friend class Application; + friend class TimerHolder; }; } From 6d09efc90705d79da9ec0bc0738024089a81afe8 Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Tue, 21 Nov 2017 13:20:55 +0100 Subject: [PATCH 04/15] Use std::shared_ptr instead of boost::shared_ptr --- lib/base/tlsstream.cpp | 12 +++---- lib/base/tlsstream.hpp | 8 ++--- lib/base/tlsutility.cpp | 42 ++++++++++++------------- lib/base/tlsutility.hpp | 25 +++++++-------- lib/cli/casigncommand.cpp | 4 +-- lib/cli/nodesetupcommand.cpp | 2 +- lib/cli/nodewizardcommand.cpp | 2 +- lib/cli/pkisavecertcommand.cpp | 2 +- lib/config/applyrule.cpp | 14 ++++----- lib/config/applyrule.hpp | 20 ++++++------ lib/config/configcompiler.hpp | 2 +- lib/config/configitem.cpp | 8 ++--- lib/config/configitem.hpp | 12 +++---- lib/config/configitembuilder.cpp | 5 ++- lib/config/configitembuilder.hpp | 4 +-- lib/config/expression.hpp | 16 +++++----- lib/config/vmops.hpp | 13 ++++---- lib/db_ido_mysql/idomysqlconnection.hpp | 2 +- lib/db_ido_pgsql/idopgsqlconnection.hpp | 2 +- lib/perfdata/elasticsearchwriter.cpp | 2 +- lib/perfdata/influxdbwriter.cpp | 2 +- lib/remote/apiclient.cpp | 8 ++--- lib/remote/apilistener.cpp | 10 +++--- lib/remote/apilistener.hpp | 2 +- lib/remote/httpclientconnection.cpp | 13 ++++---- lib/remote/httpclientconnection.hpp | 8 ++--- lib/remote/httprequest.cpp | 3 +- lib/remote/httprequest.hpp | 2 +- lib/remote/httpresponse.cpp | 3 +- lib/remote/httpresponse.hpp | 2 +- lib/remote/jsonrpcconnection-pki.cpp | 18 +++++------ lib/remote/pkiutility.cpp | 24 +++++++------- lib/remote/pkiutility.hpp | 8 ++--- plugins/check_nscp_api.cpp | 2 +- 34 files changed, 148 insertions(+), 154 deletions(-) diff --git a/lib/base/tlsstream.cpp b/lib/base/tlsstream.cpp index 4bb98f5cd..6f8f0664c 100644 --- a/lib/base/tlsstream.cpp +++ b/lib/base/tlsstream.cpp @@ -38,7 +38,7 @@ bool I2_EXPORT TlsStream::m_SSLIndexInitialized = false; * @param role The role of the client. * @param sslContext The SSL context for the client. */ -TlsStream::TlsStream(const Socket::Ptr& socket, const String& hostname, ConnectionRole role, const boost::shared_ptr& sslContext) +TlsStream::TlsStream(const Socket::Ptr& socket, const String& hostname, ConnectionRole role, const std::shared_ptr& sslContext) : SocketEvents(socket, this), m_Eof(false), m_HandshakeOK(false), m_VerifyOK(true), m_ErrorCode(0), m_ErrorOccurred(false), m_Socket(socket), m_Role(role), m_SendQ(new FIFO()), m_RecvQ(new FIFO()), m_CurrentAction(TlsActionNone), m_Retry(false), m_Shutdown(false) @@ -46,7 +46,7 @@ TlsStream::TlsStream(const Socket::Ptr& socket, const String& hostname, Connecti std::ostringstream msgbuf; char errbuf[120]; - m_SSL = boost::shared_ptr(SSL_new(sslContext.get()), SSL_free); + m_SSL = std::shared_ptr(SSL_new(sslContext.get()), SSL_free); if (!m_SSL) { msgbuf << "SSL_new() failed with code " << ERR_peek_error() << ", \"" << ERR_error_string(ERR_peek_error(), errbuf) << "\""; @@ -119,10 +119,10 @@ String TlsStream::GetVerifyError(void) const * * @returns The X509 certificate. */ -boost::shared_ptr TlsStream::GetClientCertificate(void) const +std::shared_ptr TlsStream::GetClientCertificate(void) const { boost::mutex::scoped_lock lock(m_Mutex); - return boost::shared_ptr(SSL_get_certificate(m_SSL.get()), &Utility::NullDeleter); + return std::shared_ptr(SSL_get_certificate(m_SSL.get()), &Utility::NullDeleter); } /** @@ -130,10 +130,10 @@ boost::shared_ptr TlsStream::GetClientCertificate(void) const * * @returns The X509 certificate. */ -boost::shared_ptr TlsStream::GetPeerCertificate(void) const +std::shared_ptr TlsStream::GetPeerCertificate(void) const { boost::mutex::scoped_lock lock(m_Mutex); - return boost::shared_ptr(SSL_get_peer_certificate(m_SSL.get()), X509_free); + return std::shared_ptr(SSL_get_peer_certificate(m_SSL.get()), X509_free); } void TlsStream::OnEvent(int revents) diff --git a/lib/base/tlsstream.hpp b/lib/base/tlsstream.hpp index 6f7f71738..8a5f23f9a 100644 --- a/lib/base/tlsstream.hpp +++ b/lib/base/tlsstream.hpp @@ -48,13 +48,13 @@ class I2_BASE_API TlsStream : public Stream, private SocketEvents public: DECLARE_PTR_TYPEDEFS(TlsStream); - TlsStream(const Socket::Ptr& socket, const String& hostname, ConnectionRole role, const boost::shared_ptr& sslContext = MakeSSLContext()); + TlsStream(const Socket::Ptr& socket, const String& hostname, ConnectionRole role, const std::shared_ptr& sslContext = MakeSSLContext()); ~TlsStream(void); Socket::Ptr GetSocket(void) const; - boost::shared_ptr GetClientCertificate(void) const; - boost::shared_ptr GetPeerCertificate(void) const; + std::shared_ptr GetClientCertificate(void) const; + std::shared_ptr GetPeerCertificate(void) const; void Handshake(void); @@ -74,7 +74,7 @@ public: String GetVerifyError(void) const; private: - boost::shared_ptr m_SSL; + std::shared_ptr m_SSL; bool m_Eof; mutable boost::mutex m_Mutex; mutable boost::condition_variable m_CV; diff --git a/lib/base/tlsutility.cpp b/lib/base/tlsutility.cpp index d1c316e58..215dc7de3 100644 --- a/lib/base/tlsutility.cpp +++ b/lib/base/tlsutility.cpp @@ -81,13 +81,13 @@ void InitializeOpenSSL(void) * @param cakey CA certificate chain file. * @returns An SSL context. */ -boost::shared_ptr MakeSSLContext(const String& pubkey, const String& privkey, const String& cakey) +std::shared_ptr MakeSSLContext(const String& pubkey, const String& privkey, const String& cakey) { char errbuf[120]; InitializeOpenSSL(); - boost::shared_ptr sslContext = boost::shared_ptr(SSL_CTX_new(SSLv23_method()), SSL_CTX_free); + std::shared_ptr sslContext = std::shared_ptr(SSL_CTX_new(SSLv23_method()), SSL_CTX_free); EC_KEY *ecdh = EC_KEY_new_by_curve_name(NID_secp384r1); @@ -174,7 +174,7 @@ boost::shared_ptr MakeSSLContext(const String& pubkey, const String& pr * @param context The ssl context. * @param cipherList The ciper list. **/ -void SetCipherListToSSLContext(const boost::shared_ptr& context, const String& cipherList) +void SetCipherListToSSLContext(const std::shared_ptr& context, const String& cipherList) { char errbuf[256]; @@ -198,7 +198,7 @@ void SetCipherListToSSLContext(const boost::shared_ptr& context, const * @param context The ssl context. * @param tlsProtocolmin The minimum TLS protocol version. */ -void SetTlsProtocolminToSSLContext(const boost::shared_ptr& context, const String& tlsProtocolmin) +void SetTlsProtocolminToSSLContext(const std::shared_ptr& context, const String& tlsProtocolmin) { long flags = SSL_CTX_get_options(context.get()); @@ -226,7 +226,7 @@ void SetTlsProtocolminToSSLContext(const boost::shared_ptr& context, co * @param context The SSL context. * @param crlPath The path to the CRL file. */ -void AddCRLToSSLContext(const boost::shared_ptr& context, const String& crlPath) +void AddCRLToSSLContext(const std::shared_ptr& context, const String& crlPath) { char errbuf[120]; X509_STORE *x509_store = SSL_CTX_get_cert_store(context.get()); @@ -281,7 +281,7 @@ static String GetX509NameCN(X509_NAME *name) * @param certificate The X509 certificate. * @returns The common name. */ -String GetCertificateCN(const boost::shared_ptr& certificate) +String GetCertificateCN(const std::shared_ptr& certificate) { return GetX509NameCN(X509_get_subject_name(certificate.get())); } @@ -292,7 +292,7 @@ String GetCertificateCN(const boost::shared_ptr& certificate) * @param pemfile The filename. * @returns An X509 certificate. */ -boost::shared_ptr GetX509Certificate(const String& pemfile) +std::shared_ptr GetX509Certificate(const String& pemfile) { char errbuf[120]; X509 *cert; @@ -327,7 +327,7 @@ boost::shared_ptr GetX509Certificate(const String& pemfile) BIO_free(fpcert); - return boost::shared_ptr(cert, X509_free); + return std::shared_ptr(cert, X509_free); } int MakeX509CSR(const String& cn, const String& keyfile, const String& csrfile, const String& certfile, bool ca) @@ -402,7 +402,7 @@ int MakeX509CSR(const String& cn, const String& keyfile, const String& csrfile, X509_NAME *subject = X509_NAME_new(); X509_NAME_add_entry_by_txt(subject, "CN", MBSTRING_ASC, (unsigned char *)cn.CStr(), -1, -1, 0); - boost::shared_ptr cert = CreateCert(key, subject, subject, key, ca); + std::shared_ptr cert = CreateCert(key, subject, subject, key, ca); X509_NAME_free(subject); @@ -491,7 +491,7 @@ int MakeX509CSR(const String& cn, const String& keyfile, const String& csrfile, return 1; } -boost::shared_ptr CreateCert(EVP_PKEY *pubkey, X509_NAME *subject, X509_NAME *issuer, EVP_PKEY *cakey, bool ca) +std::shared_ptr CreateCert(EVP_PKEY *pubkey, X509_NAME *subject, X509_NAME *issuer, EVP_PKEY *cakey, bool ca) { X509 *cert = X509_new(); X509_set_version(cert, 2); @@ -568,7 +568,7 @@ boost::shared_ptr CreateCert(EVP_PKEY *pubkey, X509_NAME *subject, X509_NA X509_sign(cert, cakey, EVP_sha256()); - return boost::shared_ptr(cert, X509_free); + return std::shared_ptr(cert, X509_free); } String GetIcingaCADir(void) @@ -576,7 +576,7 @@ String GetIcingaCADir(void) return Application::GetLocalStateDir() + "/lib/icinga2/ca"; } -boost::shared_ptr CreateCertIcingaCA(EVP_PKEY *pubkey, X509_NAME *subject) +std::shared_ptr CreateCertIcingaCA(EVP_PKEY *pubkey, X509_NAME *subject) { char errbuf[120]; @@ -589,7 +589,7 @@ boost::shared_ptr CreateCertIcingaCA(EVP_PKEY *pubkey, X509_NAME *subject) if (!cakeybio) { Log(LogCritical, "SSL") << "Could not open CA key file '" << cakeyfile << "': " << ERR_peek_error() << ", \"" << ERR_error_string(ERR_peek_error(), errbuf) << "\""; - return boost::shared_ptr(); + return std::shared_ptr(); } EVP_PKEY *privkey = PEM_read_bio_PrivateKey(cakeybio, NULL, NULL, NULL); @@ -597,25 +597,25 @@ boost::shared_ptr CreateCertIcingaCA(EVP_PKEY *pubkey, X509_NAME *subject) if (!privkey) { Log(LogCritical, "SSL") << "Could not read private key from CA key file '" << cakeyfile << "': " << ERR_peek_error() << ", \"" << ERR_error_string(ERR_peek_error(), errbuf) << "\""; - return boost::shared_ptr(); + return std::shared_ptr(); } BIO_free(cakeybio); String cacertfile = cadir + "/ca.crt"; - boost::shared_ptr cacert = GetX509Certificate(cacertfile); + std::shared_ptr cacert = GetX509Certificate(cacertfile); return CreateCert(pubkey, subject, X509_get_subject_name(cacert.get()), privkey, false); } -boost::shared_ptr CreateCertIcingaCA(const boost::shared_ptr& cert) +std::shared_ptr CreateCertIcingaCA(const std::shared_ptr& cert) { - boost::shared_ptr pkey = boost::shared_ptr(X509_get_pubkey(cert.get()), EVP_PKEY_free); + std::shared_ptr pkey = std::shared_ptr(X509_get_pubkey(cert.get()), EVP_PKEY_free); return CreateCertIcingaCA(pkey.get(), X509_get_subject_name(cert.get())); } -String CertificateToString(const boost::shared_ptr& cert) +String CertificateToString(const std::shared_ptr& cert) { BIO *mem = BIO_new(BIO_s_mem()); PEM_write_bio_X509(mem, cert.get()); @@ -630,7 +630,7 @@ String CertificateToString(const boost::shared_ptr& cert) return result; } -boost::shared_ptr StringToCertificate(const String& cert) +std::shared_ptr StringToCertificate(const String& cert) { BIO *bio = BIO_new(BIO_s_mem()); BIO_write(bio, (const void *)cert.CStr(), cert.GetLength()); @@ -642,7 +642,7 @@ boost::shared_ptr StringToCertificate(const String& cert) if (!rawCert) BOOST_THROW_EXCEPTION(std::invalid_argument("The specified X509 certificate is invalid.")); - return boost::shared_ptr(rawCert, X509_free); + return std::shared_ptr(rawCert, X509_free); } String PBKDF2_SHA1(const String& password, const String& salt, int iterations) @@ -762,7 +762,7 @@ String RandomString(int length) return result; } -bool VerifyCertificate(const boost::shared_ptr& caCertificate, const boost::shared_ptr& certificate) +bool VerifyCertificate(const std::shared_ptr& caCertificate, const std::shared_ptr& certificate) { X509_STORE *store = X509_STORE_new(); diff --git a/lib/base/tlsutility.hpp b/lib/base/tlsutility.hpp index c2191cc51..161907104 100644 --- a/lib/base/tlsutility.hpp +++ b/lib/base/tlsutility.hpp @@ -31,31 +31,30 @@ #include #include #include -#include #include namespace icinga { void I2_BASE_API InitializeOpenSSL(void); -boost::shared_ptr I2_BASE_API MakeSSLContext(const String& pubkey = String(), const String& privkey = String(), const String& cakey = String()); -void I2_BASE_API AddCRLToSSLContext(const boost::shared_ptr& context, const String& crlPath); -void I2_BASE_API SetCipherListToSSLContext(const boost::shared_ptr& context, const String& cipherList); -void I2_BASE_API SetTlsProtocolminToSSLContext(const boost::shared_ptr& context, const String& tlsProtocolmin); -String I2_BASE_API GetCertificateCN(const boost::shared_ptr& certificate); -boost::shared_ptr I2_BASE_API GetX509Certificate(const String& pemfile); +std::shared_ptr I2_BASE_API MakeSSLContext(const String& pubkey = String(), const String& privkey = String(), const String& cakey = String()); +void I2_BASE_API AddCRLToSSLContext(const std::shared_ptr& context, const String& crlPath); +void I2_BASE_API SetCipherListToSSLContext(const std::shared_ptr& context, const String& cipherList); +void I2_BASE_API SetTlsProtocolminToSSLContext(const std::shared_ptr& context, const String& tlsProtocolmin); +String I2_BASE_API GetCertificateCN(const std::shared_ptr& certificate); +std::shared_ptr I2_BASE_API GetX509Certificate(const String& pemfile); int I2_BASE_API MakeX509CSR(const String& cn, const String& keyfile, const String& csrfile = String(), const String& certfile = String(), bool ca = false); -boost::shared_ptr I2_BASE_API CreateCert(EVP_PKEY *pubkey, X509_NAME *subject, X509_NAME *issuer, EVP_PKEY *cakey, bool ca); +std::shared_ptr I2_BASE_API CreateCert(EVP_PKEY *pubkey, X509_NAME *subject, X509_NAME *issuer, EVP_PKEY *cakey, bool ca); String I2_BASE_API GetIcingaCADir(void); -String I2_BASE_API CertificateToString(const boost::shared_ptr& cert); -boost::shared_ptr I2_BASE_API StringToCertificate(const String& cert); -boost::shared_ptr I2_BASE_API CreateCertIcingaCA(EVP_PKEY *pubkey, X509_NAME *subject); -boost::shared_ptr I2_BASE_API CreateCertIcingaCA(const boost::shared_ptr& cert); +String I2_BASE_API CertificateToString(const std::shared_ptr& cert); +std::shared_ptr I2_BASE_API StringToCertificate(const String& cert); +std::shared_ptr I2_BASE_API CreateCertIcingaCA(EVP_PKEY *pubkey, X509_NAME *subject); +std::shared_ptr I2_BASE_API CreateCertIcingaCA(const std::shared_ptr& cert); String I2_BASE_API PBKDF2_SHA1(const String& password, const String& salt, int iterations); String I2_BASE_API SHA1(const String& s, bool binary = false); String I2_BASE_API SHA256(const String& s); String I2_BASE_API RandomString(int length); -bool I2_BASE_API VerifyCertificate(const boost::shared_ptr& caCertificate, const boost::shared_ptr& certificate); +bool I2_BASE_API VerifyCertificate(const std::shared_ptr& caCertificate, const std::shared_ptr& certificate); class I2_BASE_API openssl_error : virtual public std::exception, virtual public boost::exception { }; diff --git a/lib/cli/casigncommand.cpp b/lib/cli/casigncommand.cpp index e26061238..7b7e12792 100644 --- a/lib/cli/casigncommand.cpp +++ b/lib/cli/casigncommand.cpp @@ -69,14 +69,14 @@ int CASignCommand::Run(const boost::program_options::variables_map& vm, const st String certRequestText = request->Get("cert_request"); - boost::shared_ptr certRequest = StringToCertificate(certRequestText); + std::shared_ptr certRequest = StringToCertificate(certRequestText); if (!certRequest) { Log(LogCritical, "cli", "Certificate request is invalid. Could not parse X.509 certificate for the 'cert_request' attribute."); return 1; } - boost::shared_ptr certResponse = CreateCertIcingaCA(certRequest); + std::shared_ptr certResponse = CreateCertIcingaCA(certRequest); BIO *out = BIO_new(BIO_s_mem()); X509_NAME_print_ex(out, X509_get_subject_name(certRequest.get()), 0, XN_FLAG_ONELINE & ~ASN1_STRFLGS_ESC_MSB); diff --git a/lib/cli/nodesetupcommand.cpp b/lib/cli/nodesetupcommand.cpp index 4895898df..6d4617a97 100644 --- a/lib/cli/nodesetupcommand.cpp +++ b/lib/cli/nodesetupcommand.cpp @@ -291,7 +291,7 @@ int NodeSetupCommand::SetupNode(const boost::program_options::variables_map& vm, return 1; } - boost::shared_ptr trustedcert = GetX509Certificate(vm["trustedcert"].as()); + std::shared_ptr trustedcert = GetX509Certificate(vm["trustedcert"].as()); Log(LogInformation, "cli") << "Verifying trusted certificate file '" << vm["trustedcert"].as() << "'."; diff --git a/lib/cli/nodewizardcommand.cpp b/lib/cli/nodewizardcommand.cpp index 5d7b630b7..7ab4c2d0b 100644 --- a/lib/cli/nodewizardcommand.cpp +++ b/lib/cli/nodewizardcommand.cpp @@ -303,7 +303,7 @@ wizard_endpoint_loop_start: << "' on file '" << nodeKey << "'. Verify it yourself!"; } - boost::shared_ptr trustedParentCert; + std::shared_ptr trustedParentCert; /* Check whether we should connect to the parent node and present its trusted certificate. */ if (connectToParent) { diff --git a/lib/cli/pkisavecertcommand.cpp b/lib/cli/pkisavecertcommand.cpp index a25e266d5..6c66e6adc 100644 --- a/lib/cli/pkisavecertcommand.cpp +++ b/lib/cli/pkisavecertcommand.cpp @@ -85,7 +85,7 @@ int PKISaveCertCommand::Run(const boost::program_options::variables_map& vm, con Log(LogInformation, "cli") << "Retrieving X.509 certificate for '" << host << ":" << port << "'."; - boost::shared_ptr cert = PkiUtility::FetchCert(host, port); + std::shared_ptr cert = PkiUtility::FetchCert(host, port); if (!cert) { Log(LogCritical, "cli", "Failed to fetch certificate from host."); diff --git a/lib/config/applyrule.cpp b/lib/config/applyrule.cpp index 3f4f76859..4a008848c 100644 --- a/lib/config/applyrule.cpp +++ b/lib/config/applyrule.cpp @@ -26,8 +26,8 @@ using namespace icinga; ApplyRule::RuleMap ApplyRule::m_Rules; ApplyRule::TypeMap ApplyRule::m_Types; -ApplyRule::ApplyRule(const String& targetType, const String& name, const boost::shared_ptr& expression, - const boost::shared_ptr& filter, const String& package, const String& fkvar, const String& fvvar, const boost::shared_ptr& fterm, +ApplyRule::ApplyRule(const String& targetType, const String& name, const std::shared_ptr& expression, + const std::shared_ptr& filter, const String& package, const String& fkvar, const String& fvvar, const std::shared_ptr& fterm, bool ignoreOnError, const DebugInfo& di, const Dictionary::Ptr& scope) : m_TargetType(targetType), m_Name(name), m_Expression(expression), m_Filter(filter), m_Package(package), m_FKVar(fkvar), m_FVVar(fvvar), m_FTerm(fterm), m_IgnoreOnError(ignoreOnError), m_DebugInfo(di), m_Scope(scope), m_HasMatches(false) @@ -43,12 +43,12 @@ String ApplyRule::GetName(void) const return m_Name; } -boost::shared_ptr ApplyRule::GetExpression(void) const +std::shared_ptr ApplyRule::GetExpression(void) const { return m_Expression; } -boost::shared_ptr ApplyRule::GetFilter(void) const +std::shared_ptr ApplyRule::GetFilter(void) const { return m_Filter; } @@ -68,7 +68,7 @@ String ApplyRule::GetFVVar(void) const return m_FVVar; } -boost::shared_ptr ApplyRule::GetFTerm(void) const +std::shared_ptr ApplyRule::GetFTerm(void) const { return m_FTerm; } @@ -89,8 +89,8 @@ Dictionary::Ptr ApplyRule::GetScope(void) const } void ApplyRule::AddRule(const String& sourceType, const String& targetType, const String& name, - const boost::shared_ptr& expression, const boost::shared_ptr& filter, const String& package, const String& fkvar, - const String& fvvar, const boost::shared_ptr& fterm, bool ignoreOnError, const DebugInfo& di, const Dictionary::Ptr& scope) + const std::shared_ptr& expression, const std::shared_ptr& filter, const String& package, const String& fkvar, + const String& fvvar, const std::shared_ptr& fterm, bool ignoreOnError, const DebugInfo& di, const Dictionary::Ptr& scope) { m_Rules[sourceType].push_back(ApplyRule(targetType, name, expression, filter, package, fkvar, fvvar, fterm, ignoreOnError, di, scope)); } diff --git a/lib/config/applyrule.hpp b/lib/config/applyrule.hpp index 631d1e54f..80f57ae13 100644 --- a/lib/config/applyrule.hpp +++ b/lib/config/applyrule.hpp @@ -38,12 +38,12 @@ public: String GetTargetType(void) const; String GetName(void) const; - boost::shared_ptr GetExpression(void) const; - boost::shared_ptr GetFilter(void) const; + std::shared_ptr GetExpression(void) const; + std::shared_ptr GetFilter(void) const; String GetPackage(void) const; String GetFKVar(void) const; String GetFVVar(void) const; - boost::shared_ptr GetFTerm(void) const; + std::shared_ptr GetFTerm(void) const; bool GetIgnoreOnError(void) const; DebugInfo GetDebugInfo(void) const; Dictionary::Ptr GetScope(void) const; @@ -52,8 +52,8 @@ public: bool EvaluateFilter(ScriptFrame& frame) const; - static void AddRule(const String& sourceType, const String& targetType, const String& name, const boost::shared_ptr& expression, - const boost::shared_ptr& filter, const String& package, const String& fkvar, const String& fvvar, const boost::shared_ptr& fterm, + static void AddRule(const String& sourceType, const String& targetType, const String& name, const std::shared_ptr& expression, + const std::shared_ptr& filter, const String& package, const String& fkvar, const String& fvvar, const std::shared_ptr& fterm, bool ignoreOnError, const DebugInfo& di, const Dictionary::Ptr& scope); static std::vector& GetRules(const String& type); @@ -67,12 +67,12 @@ public: private: String m_TargetType; String m_Name; - boost::shared_ptr m_Expression; - boost::shared_ptr m_Filter; + std::shared_ptr m_Expression; + std::shared_ptr m_Filter; String m_Package; String m_FKVar; String m_FVVar; - boost::shared_ptr m_FTerm; + std::shared_ptr m_FTerm; bool m_IgnoreOnError; DebugInfo m_DebugInfo; Dictionary::Ptr m_Scope; @@ -81,8 +81,8 @@ private: static TypeMap m_Types; static RuleMap m_Rules; - ApplyRule(const String& targetType, const String& name, const boost::shared_ptr& expression, - const boost::shared_ptr& filter, const String& package, const String& fkvar, const String& fvvar, const boost::shared_ptr& fterm, + ApplyRule(const String& targetType, const String& name, const std::shared_ptr& expression, + const std::shared_ptr& filter, const String& package, const String& fkvar, const String& fvvar, const std::shared_ptr& fterm, bool ignoreOnError, const DebugInfo& di, const Dictionary::Ptr& scope); }; diff --git a/lib/config/configcompiler.hpp b/lib/config/configcompiler.hpp index ac9f38a5d..08d362c52 100644 --- a/lib/config/configcompiler.hpp +++ b/lib/config/configcompiler.hpp @@ -128,7 +128,7 @@ public: static bool HasZoneConfigAuthority(const String& zoneName); private: - std::promise > m_Promise; + std::promise > m_Promise; String m_Path; std::istream *m_Input; diff --git a/lib/config/configitem.cpp b/lib/config/configitem.cpp index f2bd6df57..0ab2a0712 100644 --- a/lib/config/configitem.cpp +++ b/lib/config/configitem.cpp @@ -60,8 +60,8 @@ REGISTER_SCRIPTFUNCTION_NS(Internal, run_with_activation_context, &ConfigItem::R * @param debuginfo Debug information. */ ConfigItem::ConfigItem(const Type::Ptr& type, const String& name, - bool abstract, const boost::shared_ptr& exprl, - const boost::shared_ptr& filter, bool defaultTmpl, bool ignoreOnError, + bool abstract, const std::shared_ptr& exprl, + const std::shared_ptr& filter, bool defaultTmpl, bool ignoreOnError, const DebugInfo& debuginfo, const Dictionary::Ptr& scope, const String& zone, const String& package) : m_Type(type), m_Name(name), m_Abstract(abstract), @@ -137,7 +137,7 @@ ConfigObject::Ptr ConfigItem::GetObject(void) const * * @returns The expression list. */ -boost::shared_ptr ConfigItem::GetExpression(void) const +std::shared_ptr ConfigItem::GetExpression(void) const { return m_Expression; } @@ -147,7 +147,7 @@ boost::shared_ptr ConfigItem::GetExpression(void) const * * @returns The filter expression. */ -boost::shared_ptr ConfigItem::GetFilter(void) const +std::shared_ptr ConfigItem::GetFilter(void) const { return m_Filter; } diff --git a/lib/config/configitem.hpp b/lib/config/configitem.hpp index df5c1cddd..e65b8ed32 100644 --- a/lib/config/configitem.hpp +++ b/lib/config/configitem.hpp @@ -41,8 +41,8 @@ public: DECLARE_PTR_TYPEDEFS(ConfigItem); ConfigItem(const Type::Ptr& type, const String& name, bool abstract, - const boost::shared_ptr& exprl, - const boost::shared_ptr& filter, + const std::shared_ptr& exprl, + const std::shared_ptr& filter, bool defaultTmpl, bool ignoreOnError, const DebugInfo& debuginfo, const Dictionary::Ptr& scope, const String& zone, const String& package); @@ -55,8 +55,8 @@ public: std::vector GetParents(void) const; - boost::shared_ptr GetExpression(void) const; - boost::shared_ptr GetFilter(void) const; + std::shared_ptr GetExpression(void) const; + std::shared_ptr GetFilter(void) const; void Register(void); void Unregister(void); @@ -84,8 +84,8 @@ private: String m_Name; /**< The name. */ bool m_Abstract; /**< Whether this is a template. */ - boost::shared_ptr m_Expression; - boost::shared_ptr m_Filter; + std::shared_ptr m_Expression; + std::shared_ptr m_Filter; bool m_DefaultTmpl; bool m_IgnoreOnError; DebugInfo m_DebugInfo; /**< Debug information. */ diff --git a/lib/config/configitembuilder.cpp b/lib/config/configitembuilder.cpp index 9e40c65b8..902d5187d 100644 --- a/lib/config/configitembuilder.cpp +++ b/lib/config/configitembuilder.cpp @@ -20,7 +20,6 @@ #include "config/configitembuilder.hpp" #include "base/configtype.hpp" #include -#include using namespace icinga; @@ -74,7 +73,7 @@ void ConfigItemBuilder::AddExpression(Expression *expr) m_Expressions.push_back(expr); } -void ConfigItemBuilder::SetFilter(const boost::shared_ptr& filter) +void ConfigItemBuilder::SetFilter(const std::shared_ptr& filter) { m_Filter = filter; } @@ -138,7 +137,7 @@ ConfigItem::Ptr ConfigItemBuilder::Compile(void) } #endif /* I2_DEBUG */ - boost::shared_ptr exprl = boost::make_shared(exprs, m_DebugInfo); + std::shared_ptr exprl = std::make_shared(exprs, m_DebugInfo); exprl->MakeInline(); return new ConfigItem(m_Type, m_Name, m_Abstract, exprl, m_Filter, diff --git a/lib/config/configitembuilder.hpp b/lib/config/configitembuilder.hpp index 6a406ac3e..c804ca377 100644 --- a/lib/config/configitembuilder.hpp +++ b/lib/config/configitembuilder.hpp @@ -52,7 +52,7 @@ public: void SetIgnoreOnError(bool ignoreOnError); void AddExpression(Expression *expr); - void SetFilter(const boost::shared_ptr& filter); + void SetFilter(const std::shared_ptr& filter); ConfigItem::Ptr Compile(void); @@ -61,7 +61,7 @@ private: String m_Name; /**< The name. */ bool m_Abstract; /**< Whether the item is abstract. */ std::vector m_Expressions; /**< Expressions for this item. */ - boost::shared_ptr m_Filter; /**< Filter expression. */ + std::shared_ptr m_Filter; /**< Filter expression. */ DebugInfo m_DebugInfo; /**< Debug information. */ Dictionary::Ptr m_Scope; /**< variable scope. */ String m_Zone; /**< The zone. */ diff --git a/lib/config/expression.hpp b/lib/config/expression.hpp index 59a16f6e1..dec6f1c75 100644 --- a/lib/config/expression.hpp +++ b/lib/config/expression.hpp @@ -216,7 +216,7 @@ I2_CONFIG_API Expression *MakeIndexer(ScopeSpecifier scopeSpec, const String& in class I2_CONFIG_API OwnedExpression : public Expression { public: - OwnedExpression(const boost::shared_ptr& expression) + OwnedExpression(const std::shared_ptr& expression) : m_Expression(expression) { } @@ -232,7 +232,7 @@ protected: } private: - boost::shared_ptr m_Expression; + std::shared_ptr m_Expression; }; class I2_CONFIG_API LiteralExpression : public Expression @@ -837,7 +837,7 @@ private: String m_Name; std::vector m_Args; std::map *m_ClosedVars; - boost::shared_ptr m_Expression; + std::shared_ptr m_Expression; }; class I2_CONFIG_API ApplyExpression : public DebuggableExpression @@ -874,14 +874,14 @@ private: String m_Type; String m_Target; Expression *m_Name; - boost::shared_ptr m_Filter; + std::shared_ptr m_Filter; String m_Package; String m_FKVar; String m_FVVar; - boost::shared_ptr m_FTerm; + std::shared_ptr m_FTerm; bool m_IgnoreOnError; std::map *m_ClosedVars; - boost::shared_ptr m_Expression; + std::shared_ptr m_Expression; }; class I2_CONFIG_API ObjectExpression : public DebuggableExpression @@ -916,13 +916,13 @@ private: bool m_Abstract; Expression *m_Type; Expression *m_Name; - boost::shared_ptr m_Filter; + std::shared_ptr m_Filter; String m_Zone; String m_Package; bool m_DefaultTmpl; bool m_IgnoreOnError; std::map *m_ClosedVars; - boost::shared_ptr m_Expression; + std::shared_ptr m_Expression; }; class I2_CONFIG_API ForExpression : public DebuggableExpression diff --git a/lib/config/vmops.hpp b/lib/config/vmops.hpp index 25999e60b..193a57ab5 100644 --- a/lib/config/vmops.hpp +++ b/lib/config/vmops.hpp @@ -33,7 +33,6 @@ #include "base/exception.hpp" #include "base/convert.hpp" #include "base/objectlock.hpp" -#include #include #include @@ -110,7 +109,7 @@ public: } static inline Value NewFunction(ScriptFrame& frame, const String& name, const std::vector& argNames, - std::map *closedVars, const boost::shared_ptr& expression) + std::map *closedVars, const std::shared_ptr& expression) { auto evaluatedClosedVars = EvaluateClosedVars(frame, closedVars); @@ -132,9 +131,9 @@ public: return new Function(name, wrapper, argNames); } - static inline Value NewApply(ScriptFrame& frame, const String& type, const String& target, const String& name, const boost::shared_ptr& filter, - const String& package, const String& fkvar, const String& fvvar, const boost::shared_ptr& fterm, std::map *closedVars, - bool ignoreOnError, const boost::shared_ptr& expression, const DebugInfo& debugInfo = DebugInfo()) + static inline Value NewApply(ScriptFrame& frame, const String& type, const String& target, const String& name, const std::shared_ptr& filter, + const String& package, const String& fkvar, const String& fvvar, const std::shared_ptr& fterm, std::map *closedVars, + bool ignoreOnError, const std::shared_ptr& expression, const DebugInfo& debugInfo = DebugInfo()) { ApplyRule::AddRule(type, target, name, expression, filter, package, fkvar, fvvar, fterm, ignoreOnError, debugInfo, EvaluateClosedVars(frame, closedVars)); @@ -142,8 +141,8 @@ public: return Empty; } - static inline Value NewObject(ScriptFrame& frame, bool abstract, const Type::Ptr& type, const String& name, const boost::shared_ptr& filter, - const String& zone, const String& package, bool defaultTmpl, bool ignoreOnError, std::map *closedVars, const boost::shared_ptr& expression, const DebugInfo& debugInfo = DebugInfo()) + static inline Value NewObject(ScriptFrame& frame, bool abstract, const Type::Ptr& type, const String& name, const std::shared_ptr& filter, + const String& zone, const String& package, bool defaultTmpl, bool ignoreOnError, std::map *closedVars, const std::shared_ptr& expression, const DebugInfo& debugInfo = DebugInfo()) { ConfigItemBuilder::Ptr item = new ConfigItemBuilder(debugInfo); diff --git a/lib/db_ido_mysql/idomysqlconnection.hpp b/lib/db_ido_mysql/idomysqlconnection.hpp index 5c6156acf..140b11a70 100644 --- a/lib/db_ido_mysql/idomysqlconnection.hpp +++ b/lib/db_ido_mysql/idomysqlconnection.hpp @@ -29,7 +29,7 @@ namespace icinga { -typedef boost::shared_ptr IdoMysqlResult; +typedef std::shared_ptr IdoMysqlResult; typedef std::function IdoAsyncCallback; diff --git a/lib/db_ido_pgsql/idopgsqlconnection.hpp b/lib/db_ido_pgsql/idopgsqlconnection.hpp index 424b44280..56965d832 100644 --- a/lib/db_ido_pgsql/idopgsqlconnection.hpp +++ b/lib/db_ido_pgsql/idopgsqlconnection.hpp @@ -29,7 +29,7 @@ namespace icinga { -typedef boost::shared_ptr IdoPgsqlResult; +typedef std::shared_ptr IdoPgsqlResult; /** * An IDO pgSQL database connection. diff --git a/lib/perfdata/elasticsearchwriter.cpp b/lib/perfdata/elasticsearchwriter.cpp index f1880269d..98c6c7357 100644 --- a/lib/perfdata/elasticsearchwriter.cpp +++ b/lib/perfdata/elasticsearchwriter.cpp @@ -528,7 +528,7 @@ Stream::Ptr ElasticsearchWriter::Connect(void) } if (GetEnableTls()) { - boost::shared_ptr sslContext; + std::shared_ptr sslContext; try { sslContext = MakeSSLContext(GetCertPath(), GetKeyPath(), GetCaPath()); diff --git a/lib/perfdata/influxdbwriter.cpp b/lib/perfdata/influxdbwriter.cpp index fa08a69f3..d40f88627 100644 --- a/lib/perfdata/influxdbwriter.cpp +++ b/lib/perfdata/influxdbwriter.cpp @@ -150,7 +150,7 @@ Stream::Ptr InfluxdbWriter::Connect() } if (GetSslEnable()) { - boost::shared_ptr sslContext; + std::shared_ptr sslContext; try { sslContext = MakeSSLContext(GetSslCert(), GetSslKey(), GetSslCaCert()); } catch (const std::exception& ex) { diff --git a/lib/remote/apiclient.cpp b/lib/remote/apiclient.cpp index 45cf06f6a..5ca690de8 100644 --- a/lib/remote/apiclient.cpp +++ b/lib/remote/apiclient.cpp @@ -46,7 +46,7 @@ void ApiClient::GetTypes(const TypesCompletionCallback& callback) const url->SetPath(path); try { - boost::shared_ptr req = m_Connection->NewRequest(); + std::shared_ptr req = m_Connection->NewRequest(); req->RequestMethod = "GET"; req->RequestUrl = url; req->AddHeader("Authorization", "Basic " + Base64::Encode(m_User + ":" + m_Password)); @@ -136,7 +136,7 @@ void ApiClient::GetObjects(const String& pluralType, const ObjectsCompletionCall url->SetQuery(params); try { - boost::shared_ptr req = m_Connection->NewRequest(); + std::shared_ptr req = m_Connection->NewRequest(); req->RequestMethod = "GET"; req->RequestUrl = url; req->AddHeader("Authorization", "Basic " + Base64::Encode(m_User + ":" + m_Password)); @@ -250,7 +250,7 @@ void ApiClient::ExecuteScript(const String& session, const String& command, bool url->SetQuery(params); try { - boost::shared_ptr req = m_Connection->NewRequest(); + std::shared_ptr req = m_Connection->NewRequest(); req->RequestMethod = "POST"; req->RequestUrl = url; req->AddHeader("Authorization", "Basic " + Base64::Encode(m_User + ":" + m_Password)); @@ -334,7 +334,7 @@ void ApiClient::AutocompleteScript(const String& session, const String& command, url->SetQuery(params); try { - boost::shared_ptr req = m_Connection->NewRequest(); + std::shared_ptr req = m_Connection->NewRequest(); req->RequestMethod = "POST"; req->RequestUrl = url; req->AddHeader("Authorization", "Basic " + Base64::Encode(m_User + ":" + m_Password)); diff --git a/lib/remote/apilistener.cpp b/lib/remote/apilistener.cpp index b64b3c3dd..fce03dfab 100644 --- a/lib/remote/apilistener.cpp +++ b/lib/remote/apilistener.cpp @@ -128,7 +128,7 @@ void ApiListener::OnConfigLoaded(void) } /* set up SSL context */ - boost::shared_ptr cert; + std::shared_ptr cert; try { cert = GetX509Certificate(defaultCertPath); } catch (const std::exception&) { @@ -151,7 +151,7 @@ void ApiListener::OnConfigLoaded(void) void ApiListener::UpdateSSLContext(void) { - boost::shared_ptr context; + std::shared_ptr context; try { context = MakeSSLContext(GetDefaultCertPath(), GetDefaultKeyPath(), GetDefaultCaPath()); @@ -312,7 +312,7 @@ bool ApiListener::AddListener(const String& node, const String& service) { ObjectLock olock(this); - boost::shared_ptr sslContext = m_SSLContext; + std::shared_ptr sslContext = m_SSLContext; if (!sslContext) { Log(LogCritical, "ApiListener", "SSL context is required for AddListener()"); @@ -367,7 +367,7 @@ void ApiListener::AddConnection(const Endpoint::Ptr& endpoint) { ObjectLock olock(this); - boost::shared_ptr sslContext = m_SSLContext; + std::shared_ptr sslContext = m_SSLContext; if (!sslContext) { Log(LogCritical, "ApiListener", "SSL context is required for AddConnection()"); @@ -455,7 +455,7 @@ void ApiListener::NewClientHandlerInternal(const Socket::Ptr& client, const Stri return; } - boost::shared_ptr cert = tlsStream->GetPeerCertificate(); + std::shared_ptr cert = tlsStream->GetPeerCertificate(); String identity; Endpoint::Ptr endpoint; bool verify_ok = false; diff --git a/lib/remote/apilistener.hpp b/lib/remote/apilistener.hpp index 1ce70316c..d258b6488 100644 --- a/lib/remote/apilistener.hpp +++ b/lib/remote/apilistener.hpp @@ -117,7 +117,7 @@ protected: virtual void ValidateTlsProtocolmin(const String& value, const ValidationUtils& utils) override; private: - boost::shared_ptr m_SSLContext; + std::shared_ptr m_SSLContext; std::set m_Servers; mutable boost::mutex m_AnonymousClientsLock; diff --git a/lib/remote/httpclientconnection.cpp b/lib/remote/httpclientconnection.cpp index 3caeb3057..e730ff2fa 100644 --- a/lib/remote/httpclientconnection.cpp +++ b/lib/remote/httpclientconnection.cpp @@ -28,7 +28,6 @@ #include "base/tcpsocket.hpp" #include "base/tlsstream.hpp" #include "base/networkstream.hpp" -#include using namespace icinga; @@ -104,14 +103,14 @@ bool HttpClientConnection::ProcessMessage(void) return false; } - const std::pair, HttpCompletionCallback>& currentRequest = *m_Requests.begin(); + const std::pair, HttpCompletionCallback>& currentRequest = *m_Requests.begin(); HttpRequest& request = *currentRequest.first.get(); const HttpCompletionCallback& callback = currentRequest.second; if (!m_CurrentResponse) - m_CurrentResponse = boost::make_shared(m_Stream, request); + m_CurrentResponse = std::make_shared(m_Stream, request); - boost::shared_ptr currentResponse = m_CurrentResponse; + std::shared_ptr currentResponse = m_CurrentResponse; HttpResponse& response = *currentResponse.get(); try { @@ -161,13 +160,13 @@ void HttpClientConnection::DataAvailableHandler(const Stream::Ptr& stream) m_Stream->Close(); } -boost::shared_ptr HttpClientConnection::NewRequest(void) +std::shared_ptr HttpClientConnection::NewRequest(void) { Reconnect(); - return boost::make_shared(m_Stream); + return std::make_shared(m_Stream); } -void HttpClientConnection::SubmitRequest(const boost::shared_ptr& request, +void HttpClientConnection::SubmitRequest(const std::shared_ptr& request, const HttpCompletionCallback& callback) { m_Requests.push_back(std::make_pair(request, callback)); diff --git a/lib/remote/httpclientconnection.hpp b/lib/remote/httpclientconnection.hpp index d8b820831..c7916bfa6 100644 --- a/lib/remote/httpclientconnection.hpp +++ b/lib/remote/httpclientconnection.hpp @@ -50,18 +50,18 @@ public: void Disconnect(void); - boost::shared_ptr NewRequest(void); + std::shared_ptr NewRequest(void); typedef std::function HttpCompletionCallback; - void SubmitRequest(const boost::shared_ptr& request, const HttpCompletionCallback& callback); + void SubmitRequest(const std::shared_ptr& request, const HttpCompletionCallback& callback); private: String m_Host; String m_Port; bool m_Tls; Stream::Ptr m_Stream; - std::deque, HttpCompletionCallback> > m_Requests; - boost::shared_ptr m_CurrentResponse; + std::deque, HttpCompletionCallback> > m_Requests; + std::shared_ptr m_CurrentResponse; boost::mutex m_DataHandlerMutex; StreamReadContext m_Context; diff --git a/lib/remote/httprequest.cpp b/lib/remote/httprequest.cpp index 43918c322..d5e2e6fc1 100644 --- a/lib/remote/httprequest.cpp +++ b/lib/remote/httprequest.cpp @@ -24,7 +24,6 @@ #include #include #include -#include using namespace icinga; @@ -101,7 +100,7 @@ bool HttpRequest::Parse(StreamReadContext& src, bool may_wait) } else if (m_State == HttpRequestBody) { if (Headers->Get("transfer-encoding") == "chunked") { if (!m_ChunkContext) - m_ChunkContext = boost::make_shared(boost::ref(src)); + m_ChunkContext = std::make_shared(boost::ref(src)); char *data; size_t size; diff --git a/lib/remote/httprequest.hpp b/lib/remote/httprequest.hpp index 5a98a2343..7ffce5351 100644 --- a/lib/remote/httprequest.hpp +++ b/lib/remote/httprequest.hpp @@ -71,7 +71,7 @@ public: private: Stream::Ptr m_Stream; - boost::shared_ptr m_ChunkContext; + std::shared_ptr m_ChunkContext; HttpRequestState m_State; FIFO::Ptr m_Body; diff --git a/lib/remote/httpresponse.cpp b/lib/remote/httpresponse.cpp index 7f77ed386..870e91e73 100644 --- a/lib/remote/httpresponse.cpp +++ b/lib/remote/httpresponse.cpp @@ -24,7 +24,6 @@ #include #include "base/application.hpp" #include "base/convert.hpp" -#include using namespace icinga; @@ -183,7 +182,7 @@ bool HttpResponse::Parse(StreamReadContext& src, bool may_wait) } else if (m_State == HttpResponseBody) { if (Headers->Get("transfer-encoding") == "chunked") { if (!m_ChunkContext) - m_ChunkContext = boost::make_shared(boost::ref(src)); + m_ChunkContext = std::make_shared(boost::ref(src)); char *data; size_t size; diff --git a/lib/remote/httpresponse.hpp b/lib/remote/httpresponse.hpp index da6afd66b..8e955fa1a 100644 --- a/lib/remote/httpresponse.hpp +++ b/lib/remote/httpresponse.hpp @@ -67,7 +67,7 @@ public: private: HttpResponseState m_State; - boost::shared_ptr m_ChunkContext; + std::shared_ptr m_ChunkContext; const HttpRequest& m_Request; Stream::Ptr m_Stream; FIFO::Ptr m_Body; diff --git a/lib/remote/jsonrpcconnection-pki.cpp b/lib/remote/jsonrpcconnection-pki.cpp index 048d6c1c1..6f5a5214d 100644 --- a/lib/remote/jsonrpcconnection-pki.cpp +++ b/lib/remote/jsonrpcconnection-pki.cpp @@ -45,7 +45,7 @@ Value RequestCertificateHandler(const MessageOrigin::Ptr& origin, const Dictiona String certText = params->Get("cert_request"); - boost::shared_ptr cert; + std::shared_ptr cert; Dictionary::Ptr result = new Dictionary(); @@ -56,7 +56,7 @@ Value RequestCertificateHandler(const MessageOrigin::Ptr& origin, const Dictiona cert = StringToCertificate(certText); ApiListener::Ptr listener = ApiListener::GetInstance(); - boost::shared_ptr cacert = GetX509Certificate(listener->GetDefaultCaPath()); + std::shared_ptr cacert = GetX509Certificate(listener->GetDefaultCaPath()); String cn = GetCertificateCN(cert); @@ -137,8 +137,8 @@ Value RequestCertificateHandler(const MessageOrigin::Ptr& origin, const Dictiona } } - boost::shared_ptr newcert; - boost::shared_ptr pubkey; + std::shared_ptr newcert; + std::shared_ptr pubkey; X509_NAME *subject; Dictionary::Ptr message; String ticket; @@ -172,7 +172,7 @@ Value RequestCertificateHandler(const MessageOrigin::Ptr& origin, const Dictiona } } - pubkey = boost::shared_ptr(X509_get_pubkey(cert.get()), EVP_PKEY_free); + pubkey = std::shared_ptr(X509_get_pubkey(cert.get()), EVP_PKEY_free); subject = X509_get_subject_name(cert.get()); newcert = CreateCertIcingaCA(pubkey.get(), subject); @@ -285,8 +285,8 @@ Value UpdateCertificateHandler(const MessageOrigin::Ptr& origin, const Dictionar if (!listener) return Empty; - boost::shared_ptr oldCert = GetX509Certificate(listener->GetDefaultCertPath()); - boost::shared_ptr newCert = StringToCertificate(cert); + std::shared_ptr oldCert = GetX509Certificate(listener->GetDefaultCertPath()); + std::shared_ptr newCert = StringToCertificate(cert); String cn = GetCertificateCN(newCert); @@ -294,8 +294,8 @@ Value UpdateCertificateHandler(const MessageOrigin::Ptr& origin, const Dictionar << "Received certificate update message for CN '" << cn << "'"; /* Check if this is a certificate update for a subordinate instance. */ - boost::shared_ptr oldKey = boost::shared_ptr(X509_get_pubkey(oldCert.get()), EVP_PKEY_free); - boost::shared_ptr newKey = boost::shared_ptr(X509_get_pubkey(newCert.get()), EVP_PKEY_free); + std::shared_ptr oldKey = std::shared_ptr(X509_get_pubkey(oldCert.get()), EVP_PKEY_free); + std::shared_ptr newKey = std::shared_ptr(X509_get_pubkey(newCert.get()), EVP_PKEY_free); if (X509_NAME_cmp(X509_get_subject_name(oldCert.get()), X509_get_subject_name(newCert.get())) != 0 || EVP_PKEY_cmp(oldKey.get(), newKey.get()) != 1) { diff --git a/lib/remote/pkiutility.cpp b/lib/remote/pkiutility.cpp index ab3685588..0457b6ed0 100644 --- a/lib/remote/pkiutility.cpp +++ b/lib/remote/pkiutility.cpp @@ -81,8 +81,8 @@ int PkiUtility::SignCsr(const String& csrfile, const String& certfile) BIO_free(csrbio); - boost::shared_ptr pubkey = boost::shared_ptr(X509_REQ_get_pubkey(req), EVP_PKEY_free); - boost::shared_ptr cert = CreateCertIcingaCA(pubkey.get(), X509_REQ_get_subject_name(req)); + std::shared_ptr pubkey = std::shared_ptr(X509_REQ_get_pubkey(req), EVP_PKEY_free); + std::shared_ptr cert = CreateCertIcingaCA(pubkey.get(), X509_REQ_get_subject_name(req)); X509_REQ_free(req); @@ -91,7 +91,7 @@ int PkiUtility::SignCsr(const String& csrfile, const String& certfile) return 0; } -boost::shared_ptr PkiUtility::FetchCert(const String& host, const String& port) +std::shared_ptr PkiUtility::FetchCert(const String& host, const String& port) { TcpSocket::Ptr client = new TcpSocket(); @@ -102,10 +102,10 @@ boost::shared_ptr PkiUtility::FetchCert(const String& host, const String& << "Cannot connect to host '" << host << "' on port '" << port << "'"; Log(LogDebug, "pki") << "Cannot connect to host '" << host << "' on port '" << port << "':\n" << DiagnosticInformation(ex); - return boost::shared_ptr(); + return std::shared_ptr(); } - boost::shared_ptr sslContext; + std::shared_ptr sslContext; try { sslContext = MakeSSLContext(); @@ -114,7 +114,7 @@ boost::shared_ptr PkiUtility::FetchCert(const String& host, const String& << "Cannot make SSL context."; Log(LogDebug, "pki") << "Cannot make SSL context:\n" << DiagnosticInformation(ex); - return boost::shared_ptr(); + return std::shared_ptr(); } TlsStream::Ptr stream = new TlsStream(client, host, RoleClient, sslContext); @@ -128,7 +128,7 @@ boost::shared_ptr PkiUtility::FetchCert(const String& host, const String& return stream->GetPeerCertificate(); } -int PkiUtility::WriteCert(const boost::shared_ptr& cert, const String& trustedfile) +int PkiUtility::WriteCert(const std::shared_ptr& cert, const String& trustedfile) { std::ofstream fpcert; fpcert.open(trustedfile.CStr()); @@ -155,7 +155,7 @@ int PkiUtility::GenTicket(const String& cn, const String& salt, std::ostream& ti } int PkiUtility::RequestCertificate(const String& host, const String& port, const String& keyfile, - const String& certfile, const String& cafile, const boost::shared_ptr& trustedCert, const String& ticket) + const String& certfile, const String& cafile, const std::shared_ptr& trustedCert, const String& ticket) { TcpSocket::Ptr client = new TcpSocket(); @@ -169,7 +169,7 @@ int PkiUtility::RequestCertificate(const String& host, const String& port, const return 1; } - boost::shared_ptr sslContext; + std::shared_ptr sslContext; try { sslContext = MakeSSLContext(certfile, keyfile); @@ -190,7 +190,7 @@ int PkiUtility::RequestCertificate(const String& host, const String& port, const return 1; } - boost::shared_ptr peerCert = stream->GetPeerCertificate(); + std::shared_ptr peerCert = stream->GetPeerCertificate(); if (X509_cmp(peerCert.get(), trustedCert.get())) { Log(LogCritical, "cli", "Peer certificate does not match trusted certificate."); @@ -326,7 +326,7 @@ int PkiUtility::RequestCertificate(const String& host, const String& port, const return 0; } -String PkiUtility::GetCertificateInformation(const boost::shared_ptr& cert) { +String PkiUtility::GetCertificateInformation(const std::shared_ptr& cert) { BIO *out = BIO_new(BIO_s_mem()); String pre; @@ -391,7 +391,7 @@ static void CollectRequestHandler(const Dictionary::Ptr& requests, const String& result->Set("cert_response", certResponseText); } - boost::shared_ptr certRequest = StringToCertificate(certRequestText); + std::shared_ptr certRequest = StringToCertificate(certRequestText); /* XXX (requires OpenSSL >= 1.0.0) time_t now; diff --git a/lib/remote/pkiutility.hpp b/lib/remote/pkiutility.hpp index 078722873..5cdb9165a 100644 --- a/lib/remote/pkiutility.hpp +++ b/lib/remote/pkiutility.hpp @@ -37,13 +37,13 @@ public: static int NewCa(void); static int NewCert(const String& cn, const String& keyfile, const String& csrfile, const String& certfile); static int SignCsr(const String& csrfile, const String& certfile); - static boost::shared_ptr FetchCert(const String& host, const String& port); - static int WriteCert(const boost::shared_ptr& cert, const String& trustedfile); + static std::shared_ptr FetchCert(const String& host, const String& port); + static int WriteCert(const std::shared_ptr& cert, const String& trustedfile); static int GenTicket(const String& cn, const String& salt, std::ostream& ticketfp); static int RequestCertificate(const String& host, const String& port, const String& keyfile, - const String& certfile, const String& cafile, const boost::shared_ptr& trustedcert, + const String& certfile, const String& cafile, const std::shared_ptr& trustedcert, const String& ticket = String()); - static String GetCertificateInformation(const boost::shared_ptr& certificate); + static String GetCertificateInformation(const std::shared_ptr& certificate); static Dictionary::Ptr GetCertificateRequests(void); private: diff --git a/plugins/check_nscp_api.cpp b/plugins/check_nscp_api.cpp index 71ae8623c..116120c6c 100644 --- a/plugins/check_nscp_api.cpp +++ b/plugins/check_nscp_api.cpp @@ -83,7 +83,7 @@ static Dictionary::Ptr QueryEndpoint(const String& host, const String& port, con boost::condition_variable cv; boost::mutex mtx; Dictionary::Ptr result; - boost::shared_ptr req = m_Connection->NewRequest(); + std::shared_ptr req = m_Connection->NewRequest(); req->RequestMethod = "GET"; // Url() will call Utillity::UnescapeString() which will thrown an exception if it finds a lonely % From 67390236785cb5b79cfa55cffe75f5f8648c6bd7 Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Tue, 21 Nov 2017 14:07:44 +0100 Subject: [PATCH 05/15] Dynamically create and destroy the timer thread --- lib/base/application.cpp | 4 -- lib/base/timer.cpp | 45 ++++++++++++---------- lib/base/timer.hpp | 6 +-- lib/icinga/comment.cpp | 20 +++++----- lib/icinga/comment.hpp | 2 - lib/icinga/downtime.cpp | 30 +++++++-------- lib/icinga/downtime.hpp | 2 - lib/icinga/externalcommandprocessor.cpp | 7 ++++ lib/icinga/scheduleddowntime.cpp | 21 +++++----- lib/icinga/scheduleddowntime.hpp | 2 - lib/icinga/timeperiod.cpp | 20 +++++----- lib/icinga/timeperiod.hpp | 2 - lib/remote/consolehandler.cpp | 22 ++++++++--- lib/remote/jsonrpcconnection-heartbeat.cpp | 9 ----- lib/remote/jsonrpcconnection.cpp | 6 +++ 15 files changed, 101 insertions(+), 97 deletions(-) diff --git a/lib/base/application.cpp b/lib/base/application.cpp index 23847c03b..58ef40b14 100644 --- a/lib/base/application.cpp +++ b/lib/base/application.cpp @@ -158,8 +158,6 @@ void Application::InitializeBase(void) /* make sure the thread pool gets initialized */ GetTP().Start(); - - Timer::Initialize(); } void Application::UninitializeBase(void) @@ -317,8 +315,6 @@ void Application::SetArgV(char **argv) */ void Application::RunEventLoop(void) { - Timer::Initialize(); - double lastLoop = Utility::GetTime(); mainloop: diff --git a/lib/base/timer.cpp b/lib/base/timer.cpp index 2a583b694..79f5ebeef 100644 --- a/lib/base/timer.cpp +++ b/lib/base/timer.cpp @@ -71,6 +71,7 @@ static boost::condition_variable l_TimerCV; static std::thread l_TimerThread; static bool l_StopTimerThread; static TimerSet l_Timers; +static int l_AliveTimers; /** * Constructor for the Timer class. @@ -87,29 +88,16 @@ Timer::~Timer(void) Stop(true); } -/** - * Initializes the timer sub-system. - */ -void Timer::Initialize(void) -{ - boost::mutex::scoped_lock lock(l_TimerMutex); - l_StopTimerThread = false; - l_TimerThread = std::thread(&Timer::TimerThreadProc); -} - -/** - * Disables the timer sub-system. - */ void Timer::Uninitialize(void) { - { - boost::mutex::scoped_lock lock(l_TimerMutex); - l_StopTimerThread = true; - l_TimerCV.notify_all(); - } + { + boost::mutex::scoped_lock lock(l_TimerMutex); + l_StopTimerThread = true; + l_TimerCV.notify_all(); + } - if (l_TimerThread.joinable()) - l_TimerThread.join(); + if (l_TimerThread.joinable()) + l_TimerThread.join(); } /** @@ -158,6 +146,11 @@ void Timer::Start(void) { boost::mutex::scoped_lock lock(l_TimerMutex); m_Started = true; + + if (l_AliveTimers++ == 0) { + l_StopTimerThread = false; + l_TimerThread = std::thread(&Timer::TimerThreadProc); + } } InternalReschedule(false); @@ -173,6 +166,18 @@ void Timer::Stop(bool wait) boost::mutex::scoped_lock lock(l_TimerMutex); + if (m_Started && --l_AliveTimers == 0) { + l_StopTimerThread = true; + l_TimerCV.notify_all(); + + lock.unlock(); + + if (l_TimerThread.joinable() && l_TimerThread.get_id() != std::this_thread::get_id()) + l_TimerThread.join(); + + lock.lock(); + } + m_Started = false; l_Timers.erase(this); diff --git a/lib/base/timer.hpp b/lib/base/timer.hpp index d10d1dbe0..37f530dad 100644 --- a/lib/base/timer.hpp +++ b/lib/base/timer.hpp @@ -41,6 +41,8 @@ public: Timer(void); ~Timer(void); + static void Uninitialize(void); + void SetInterval(double interval); double GetInterval(void) const; @@ -65,10 +67,6 @@ private: static void TimerThreadProc(void); - static void Initialize(void); - static void Uninitialize(void); - - friend class Application; friend class TimerHolder; }; diff --git a/lib/icinga/comment.cpp b/lib/icinga/comment.cpp index 497c9a015..84f862e21 100644 --- a/lib/icinga/comment.cpp +++ b/lib/icinga/comment.cpp @@ -26,6 +26,7 @@ #include "base/timer.hpp" #include #include +#include using namespace icinga; @@ -37,18 +38,8 @@ static Timer::Ptr l_CommentsExpireTimer; boost::signals2::signal Comment::OnCommentAdded; boost::signals2::signal Comment::OnCommentRemoved; -INITIALIZE_ONCE(&Comment::StaticInitialize); - REGISTER_TYPE(Comment); -void Comment::StaticInitialize(void) -{ - l_CommentsExpireTimer = new Timer(); - l_CommentsExpireTimer->SetInterval(60); - l_CommentsExpireTimer->OnTimerExpired.connect(std::bind(&Comment::CommentsExpireTimerHandler)); - l_CommentsExpireTimer->Start(); -} - String CommentNameComposer::MakeName(const String& shortName, const Object::Ptr& context) const { Comment::Ptr comment = dynamic_pointer_cast(context); @@ -106,6 +97,15 @@ void Comment::Start(bool runtimeCreated) { ObjectImpl::Start(runtimeCreated); + static boost::once_flag once = BOOST_ONCE_INIT; + + boost::call_once(once, []() { + l_CommentsExpireTimer = new Timer(); + l_CommentsExpireTimer->SetInterval(60); + l_CommentsExpireTimer->OnTimerExpired.connect(std::bind(&Comment::CommentsExpireTimerHandler)); + l_CommentsExpireTimer->Start(); + }); + { boost::mutex::scoped_lock lock(l_CommentMutex); diff --git a/lib/icinga/comment.hpp b/lib/icinga/comment.hpp index 67669ba08..d2ccfa848 100644 --- a/lib/icinga/comment.hpp +++ b/lib/icinga/comment.hpp @@ -56,8 +56,6 @@ public: static String GetCommentIDFromLegacyID(int id); - static void StaticInitialize(void); - protected: virtual void OnAllConfigLoaded(void) override; virtual void Start(bool runtimeCreated) override; diff --git a/lib/icinga/downtime.cpp b/lib/icinga/downtime.cpp index 9c9903484..bf8b6d214 100644 --- a/lib/icinga/downtime.cpp +++ b/lib/icinga/downtime.cpp @@ -27,6 +27,7 @@ #include "base/timer.hpp" #include #include +#include using namespace icinga; @@ -41,23 +42,8 @@ boost::signals2::signal Downtime::OnDowntimeRemoved boost::signals2::signal Downtime::OnDowntimeStarted; boost::signals2::signal Downtime::OnDowntimeTriggered; -INITIALIZE_ONCE(&Downtime::StaticInitialize); - REGISTER_TYPE(Downtime); -void Downtime::StaticInitialize(void) -{ - l_DowntimesStartTimer = new Timer(); - l_DowntimesStartTimer->SetInterval(5); - l_DowntimesStartTimer->OnTimerExpired.connect(std::bind(&Downtime::DowntimesStartTimerHandler)); - l_DowntimesStartTimer->Start(); - - l_DowntimesExpireTimer = new Timer(); - l_DowntimesExpireTimer->SetInterval(60); - l_DowntimesExpireTimer->OnTimerExpired.connect(std::bind(&Downtime::DowntimesExpireTimerHandler)); - l_DowntimesExpireTimer->Start(); -} - String DowntimeNameComposer::MakeName(const String& shortName, const Object::Ptr& context) const { Downtime::Ptr downtime = dynamic_pointer_cast(context); @@ -115,6 +101,20 @@ void Downtime::Start(bool runtimeCreated) { ObjectImpl::Start(runtimeCreated); + static boost::once_flag once = BOOST_ONCE_INIT; + + boost::call_once(once, []() { + l_DowntimesStartTimer = new Timer(); + l_DowntimesStartTimer->SetInterval(5); + l_DowntimesStartTimer->OnTimerExpired.connect(std::bind(&Downtime::DowntimesStartTimerHandler)); + l_DowntimesStartTimer->Start(); + + l_DowntimesExpireTimer = new Timer(); + l_DowntimesExpireTimer->SetInterval(60); + l_DowntimesExpireTimer->OnTimerExpired.connect(std::bind(&Downtime::DowntimesExpireTimerHandler)); + l_DowntimesExpireTimer->Start(); + }); + { boost::mutex::scoped_lock lock(l_DowntimeMutex); diff --git a/lib/icinga/downtime.hpp b/lib/icinga/downtime.hpp index eb5380b12..c5e0ef66e 100644 --- a/lib/icinga/downtime.hpp +++ b/lib/icinga/downtime.hpp @@ -65,8 +65,6 @@ public: static String GetDowntimeIDFromLegacyID(int id); - static void StaticInitialize(void); - protected: virtual void OnAllConfigLoaded(void) override; virtual void Start(bool runtimeCreated) override; diff --git a/lib/icinga/externalcommandprocessor.cpp b/lib/icinga/externalcommandprocessor.cpp index 32db49ec3..3ea5afe71 100644 --- a/lib/icinga/externalcommandprocessor.cpp +++ b/lib/icinga/externalcommandprocessor.cpp @@ -39,6 +39,7 @@ #include #include #include +#include using namespace icinga; @@ -111,6 +112,12 @@ void ExternalCommandProcessor::Execute(double time, const String& command, const { ExternalCommandInfo eci; + static boost::once_flag once = BOOST_ONCE_INIT; + + boost::call_once(once, []() { + RegisterCommands(); + }); + { boost::mutex::scoped_lock lock(GetMutex()); diff --git a/lib/icinga/scheduleddowntime.cpp b/lib/icinga/scheduleddowntime.cpp index be980e68f..305ab77b0 100644 --- a/lib/icinga/scheduleddowntime.cpp +++ b/lib/icinga/scheduleddowntime.cpp @@ -24,7 +24,6 @@ #include "icinga/service.hpp" #include "base/timer.hpp" #include "base/configtype.hpp" -#include "base/initialize.hpp" #include "base/utility.hpp" #include "base/objectlock.hpp" #include "base/convert.hpp" @@ -32,13 +31,12 @@ #include "base/exception.hpp" #include #include +#include using namespace icinga; REGISTER_TYPE(ScheduledDowntime); -INITIALIZE_ONCE(&ScheduledDowntime::StaticInitialize); - static Timer::Ptr l_Timer; String ScheduledDowntimeNameComposer::MakeName(const String& shortName, const Object::Ptr& context) const @@ -79,14 +77,6 @@ Dictionary::Ptr ScheduledDowntimeNameComposer::ParseName(const String& name) con return result; } -void ScheduledDowntime::StaticInitialize(void) -{ - l_Timer = new Timer(); - l_Timer->SetInterval(60); - l_Timer->OnTimerExpired.connect(std::bind(&ScheduledDowntime::TimerProc)); - l_Timer->Start(); -} - void ScheduledDowntime::OnAllConfigLoaded(void) { ObjectImpl::OnAllConfigLoaded(); @@ -99,6 +89,15 @@ void ScheduledDowntime::Start(bool runtimeCreated) { ObjectImpl::Start(runtimeCreated); + static boost::once_flag once = BOOST_ONCE_INIT; + + boost::call_once(once, []() { + l_Timer = new Timer(); + l_Timer->SetInterval(60); + l_Timer->OnTimerExpired.connect(std::bind(&ScheduledDowntime::TimerProc)); + l_Timer->Start(); + }); + Utility::QueueAsyncCallback(std::bind(&ScheduledDowntime::CreateNextDowntime, this)); } diff --git a/lib/icinga/scheduleddowntime.hpp b/lib/icinga/scheduleddowntime.hpp index 31f2fd58a..f171d8e11 100644 --- a/lib/icinga/scheduleddowntime.hpp +++ b/lib/icinga/scheduleddowntime.hpp @@ -44,8 +44,6 @@ public: DECLARE_OBJECT(ScheduledDowntime); DECLARE_OBJECTNAME(ScheduledDowntime); - static void StaticInitialize(void); - Checkable::Ptr GetCheckable(void) const; static void EvaluateApplyRules(const intrusive_ptr& host); diff --git a/lib/icinga/timeperiod.cpp b/lib/icinga/timeperiod.cpp index 004e67538..f0b8b6644 100644 --- a/lib/icinga/timeperiod.cpp +++ b/lib/icinga/timeperiod.cpp @@ -26,6 +26,7 @@ #include "base/logger.hpp" #include "base/timer.hpp" #include "base/utility.hpp" +#include using namespace icinga; @@ -33,20 +34,19 @@ REGISTER_TYPE(TimePeriod); static Timer::Ptr l_UpdateTimer; -INITIALIZE_ONCE(&TimePeriod::StaticInitialize); - -void TimePeriod::StaticInitialize(void) -{ - l_UpdateTimer = new Timer(); - l_UpdateTimer->SetInterval(300); - l_UpdateTimer->OnTimerExpired.connect(std::bind(&TimePeriod::UpdateTimerHandler)); - l_UpdateTimer->Start(); -} - void TimePeriod::Start(bool runtimeCreated) { ObjectImpl::Start(runtimeCreated); + static boost::once_flag once = BOOST_ONCE_INIT; + + boost::call_once(once, []() { + l_UpdateTimer = new Timer(); + l_UpdateTimer->SetInterval(300); + l_UpdateTimer->OnTimerExpired.connect(std::bind(&TimePeriod::UpdateTimerHandler)); + l_UpdateTimer->Start(); + }); + /* Pre-fill the time period for the next 24 hours. */ double now = Utility::GetTime(); UpdateRegion(now, now + 24 * 3600, true); diff --git a/lib/icinga/timeperiod.hpp b/lib/icinga/timeperiod.hpp index 2c0e7a574..23d6ab8db 100644 --- a/lib/icinga/timeperiod.hpp +++ b/lib/icinga/timeperiod.hpp @@ -37,8 +37,6 @@ public: DECLARE_OBJECT(TimePeriod); DECLARE_OBJECTNAME(TimePeriod); - static void StaticInitialize(void); - virtual void Start(bool runtimeCreated) override; void UpdateRegion(double begin, double end, bool clearExisting); diff --git a/lib/remote/consolehandler.cpp b/lib/remote/consolehandler.cpp index 953bb23b5..bf69d9559 100644 --- a/lib/remote/consolehandler.cpp +++ b/lib/remote/consolehandler.cpp @@ -29,6 +29,7 @@ #include "base/timer.hpp" #include "base/initialize.hpp" #include +#include #include using namespace icinga; @@ -57,12 +58,17 @@ static void ScriptFrameCleanupHandler(void) l_ApiScriptFrames.erase(key); } -INITIALIZE_ONCE([]() { - l_FrameCleanupTimer = new Timer(); - l_FrameCleanupTimer->OnTimerExpired.connect(std::bind(ScriptFrameCleanupHandler)); - l_FrameCleanupTimer->SetInterval(30); - l_FrameCleanupTimer->Start(); -}); +static void EnsureFrameCleanupTimer(void) +{ + static boost::once_flag once = BOOST_ONCE_INIT; + + boost::call_once(once, []() { + l_FrameCleanupTimer = new Timer(); + l_FrameCleanupTimer->OnTimerExpired.connect(std::bind(ScriptFrameCleanupHandler)); + l_FrameCleanupTimer->SetInterval(30); + l_FrameCleanupTimer->Start(); + }); +} bool ConsoleHandler::HandleRequest(const ApiUser::Ptr& user, HttpRequest& request, HttpResponse& response, const Dictionary::Ptr& params) { @@ -102,6 +108,8 @@ bool ConsoleHandler::ExecuteScriptHelper(HttpRequest& request, HttpResponse& res Log(LogNotice, "Console") << "Executing expression: " << command; + EnsureFrameCleanupTimer(); + ApiScriptFrame& lsf = l_ApiScriptFrames[session]; lsf.Seen = Utility::GetTime(); @@ -175,6 +183,8 @@ bool ConsoleHandler::AutocompleteScriptHelper(HttpRequest& request, HttpResponse Log(LogInformation, "Console") << "Auto-completing expression: " << command; + EnsureFrameCleanupTimer(); + ApiScriptFrame& lsf = l_ApiScriptFrames[session]; lsf.Seen = Utility::GetTime(); diff --git a/lib/remote/jsonrpcconnection-heartbeat.cpp b/lib/remote/jsonrpcconnection-heartbeat.cpp index 5485ca8d9..d71faa443 100644 --- a/lib/remote/jsonrpcconnection-heartbeat.cpp +++ b/lib/remote/jsonrpcconnection-heartbeat.cpp @@ -29,15 +29,6 @@ using namespace icinga; REGISTER_APIFUNCTION(Heartbeat, event, &JsonRpcConnection::HeartbeatAPIHandler); -static Timer::Ptr l_HeartbeatTimer; - -INITIALIZE_ONCE([]() { - l_HeartbeatTimer = new Timer(); - l_HeartbeatTimer->OnTimerExpired.connect(std::bind(&JsonRpcConnection::HeartbeatTimerHandler)); - l_HeartbeatTimer->SetInterval(10); - l_HeartbeatTimer->Start(); -}); - void JsonRpcConnection::HeartbeatTimerHandler(void) { for (const Endpoint::Ptr& endpoint : ConfigType::GetObjectsByType()) { diff --git a/lib/remote/jsonrpcconnection.cpp b/lib/remote/jsonrpcconnection.cpp index f3dd038b6..7309f8f39 100644 --- a/lib/remote/jsonrpcconnection.cpp +++ b/lib/remote/jsonrpcconnection.cpp @@ -39,6 +39,7 @@ static Timer::Ptr l_JsonRpcConnectionTimeoutTimer; static WorkQueue *l_JsonRpcConnectionWorkQueues; static size_t l_JsonRpcConnectionWorkQueueCount; static int l_JsonRpcConnectionNextID; +static Timer::Ptr l_HeartbeatTimer; JsonRpcConnection::JsonRpcConnection(const String& identity, bool authenticated, const TlsStream::Ptr& stream, ConnectionRole role) @@ -65,6 +66,11 @@ void JsonRpcConnection::StaticInitialize(void) for (size_t i = 0; i < l_JsonRpcConnectionWorkQueueCount; i++) { l_JsonRpcConnectionWorkQueues[i].SetName("JsonRpcConnection, #" + Convert::ToString(i)); } + + l_HeartbeatTimer = new Timer(); + l_HeartbeatTimer->OnTimerExpired.connect(std::bind(&JsonRpcConnection::HeartbeatTimerHandler)); + l_HeartbeatTimer->SetInterval(10); + l_HeartbeatTimer->Start(); } void JsonRpcConnection::Start(void) From f7b4e81ffdfb8b4d2c15b673e5e36b0ec850927e Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Tue, 21 Nov 2017 14:15:00 +0100 Subject: [PATCH 06/15] Make a few functions static --- icinga-app/icinga.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/icinga-app/icinga.cpp b/icinga-app/icinga.cpp index a0d75293c..8a36a9cbd 100644 --- a/icinga-app/icinga.cpp +++ b/icinga-app/icinga.cpp @@ -94,7 +94,7 @@ static std::vector GlobalArgumentCompletion(const String& argument, cons return std::vector(); } -int Main(void) +static int Main(void) { int argc = Application::GetArgC(); char **argv = Application::GetArgV(); @@ -701,7 +701,7 @@ static int SetupService(bool install, int argc, char **argv) return 0; } -VOID ReportSvcStatus(DWORD dwCurrentState, +static VOID ReportSvcStatus(DWORD dwCurrentState, DWORD dwWin32ExitCode, DWORD dwWaitHint) { @@ -725,7 +725,7 @@ VOID ReportSvcStatus(DWORD dwCurrentState, SetServiceStatus(l_SvcStatusHandle, &l_SvcStatus); } -VOID WINAPI ServiceControlHandler(DWORD dwCtrl) +static VOID WINAPI ServiceControlHandler(DWORD dwCtrl) { if (dwCtrl == SERVICE_CONTROL_STOP) { ReportSvcStatus(SERVICE_STOP_PENDING, NO_ERROR, 0); @@ -733,7 +733,7 @@ VOID WINAPI ServiceControlHandler(DWORD dwCtrl) } } -VOID WINAPI ServiceMain(DWORD argc, LPSTR *argv) +static VOID WINAPI ServiceMain(DWORD argc, LPSTR *argv) { l_SvcStatusHandle = RegisterServiceCtrlHandler( "icinga2", From 160ab21e596574c84c69cde201df3e14ca95fc8a Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Tue, 21 Nov 2017 14:15:29 +0100 Subject: [PATCH 07/15] Replace CheckResult::StaticInitialize with a lambda function --- lib/icinga/checkresult.cpp | 6 ++---- lib/icinga/checkresult.hpp | 2 -- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/lib/icinga/checkresult.cpp b/lib/icinga/checkresult.cpp index 8140db4bc..a577c4998 100644 --- a/lib/icinga/checkresult.cpp +++ b/lib/icinga/checkresult.cpp @@ -24,10 +24,8 @@ using namespace icinga; REGISTER_TYPE(CheckResult); -INITIALIZE_ONCE(&CheckResult::StaticInitialize); -void CheckResult::StaticInitialize(void) -{ +INITIALIZE_ONCE([]() { ScriptGlobal::Set("ServiceOK", ServiceOK); ScriptGlobal::Set("ServiceWarning", ServiceWarning); ScriptGlobal::Set("ServiceCritical", ServiceCritical); @@ -35,7 +33,7 @@ void CheckResult::StaticInitialize(void) ScriptGlobal::Set("HostUp", HostUp); ScriptGlobal::Set("HostDown", HostDown); -} +}) double CheckResult::CalculateExecutionTime(void) const { diff --git a/lib/icinga/checkresult.hpp b/lib/icinga/checkresult.hpp index 508d0ff7e..eeade11c8 100644 --- a/lib/icinga/checkresult.hpp +++ b/lib/icinga/checkresult.hpp @@ -38,8 +38,6 @@ public: double CalculateExecutionTime(void) const; double CalculateLatency(void) const; - - static void StaticInitialize(void); }; } From df8266631dcf3e1733143f40c4a950befbb1c028 Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Wed, 22 Nov 2017 12:05:36 +0100 Subject: [PATCH 08/15] Replace boost::tuple with std::tuple --- icinga-app/icinga.cpp | 1 - lib/base/object.hpp | 3 --- lib/icinga/service.cpp | 6 +++--- lib/icinga/service.hpp | 6 +++++- lib/perfdata/elasticsearchwriter.cpp | 2 +- lib/perfdata/graphitewriter.cpp | 2 +- lib/perfdata/influxdbwriter.cpp | 4 ++-- test/base-dictionary.cpp | 1 - test/base-json.cpp | 1 - test/base-serialize.cpp | 1 - test/base-type.cpp | 1 - 11 files changed, 12 insertions(+), 16 deletions(-) diff --git a/icinga-app/icinga.cpp b/icinga-app/icinga.cpp index 8a36a9cbd..597961ecc 100644 --- a/icinga-app/icinga.cpp +++ b/icinga-app/icinga.cpp @@ -34,7 +34,6 @@ #include "base/process.hpp" #include "config.h" #include -#include #include #ifndef _WIN32 diff --git a/lib/base/object.hpp b/lib/base/object.hpp index d3abc4648..5418722c7 100644 --- a/lib/base/object.hpp +++ b/lib/base/object.hpp @@ -31,9 +31,6 @@ using boost::intrusive_ptr; using boost::dynamic_pointer_cast; using boost::static_pointer_cast; -#include -using boost::tie; - namespace icinga { diff --git a/lib/icinga/service.cpp b/lib/icinga/service.cpp index 54fa55eb4..4426b35d7 100644 --- a/lib/icinga/service.cpp +++ b/lib/icinga/service.cpp @@ -267,13 +267,13 @@ bool Service::ResolveMacro(const String& macro, const CheckResult::Ptr& cr, Valu return false; } -boost::tuple icinga::GetHostService(const Checkable::Ptr& checkable) +std::pair icinga::GetHostService(const Checkable::Ptr& checkable) { Service::Ptr service = dynamic_pointer_cast(checkable); if (service) - return boost::make_tuple(service->GetHost(), service); + return std::make_pair(service->GetHost(), service); else - return boost::make_tuple(static_pointer_cast(checkable), Service::Ptr()); + return std::make_pair(static_pointer_cast(checkable), Service::Ptr()); } diff --git a/lib/icinga/service.hpp b/lib/icinga/service.hpp index 8b689cd33..78bae56b5 100644 --- a/lib/icinga/service.hpp +++ b/lib/icinga/service.hpp @@ -24,6 +24,10 @@ #include "icinga/service.thpp" #include "icinga/macroresolver.hpp" #include "icinga/host.hpp" +#include +#include + +using std::tie; namespace icinga { @@ -68,7 +72,7 @@ private: static bool EvaluateApplyRule(const Host::Ptr& host, const ApplyRule& rule); }; -I2_ICINGA_API boost::tuple GetHostService(const Checkable::Ptr& checkable); +I2_ICINGA_API std::pair GetHostService(const Checkable::Ptr& checkable); } diff --git a/lib/perfdata/elasticsearchwriter.cpp b/lib/perfdata/elasticsearchwriter.cpp index 98c6c7357..ce648cd54 100644 --- a/lib/perfdata/elasticsearchwriter.cpp +++ b/lib/perfdata/elasticsearchwriter.cpp @@ -190,7 +190,7 @@ void ElasticsearchWriter::InternalCheckResultHandler(const Checkable::Ptr& check Host::Ptr host; Service::Ptr service; - boost::tie(host, service) = GetHostService(checkable); + tie(host, service) = GetHostService(checkable); Dictionary::Ptr fields = new Dictionary(); diff --git a/lib/perfdata/graphitewriter.cpp b/lib/perfdata/graphitewriter.cpp index 04aad230a..86611393c 100644 --- a/lib/perfdata/graphitewriter.cpp +++ b/lib/perfdata/graphitewriter.cpp @@ -195,7 +195,7 @@ void GraphiteWriter::CheckResultHandlerInternal(const Checkable::Ptr& checkable, Host::Ptr host; Service::Ptr service; - boost::tie(host, service) = GetHostService(checkable); + tie(host, service) = GetHostService(checkable); MacroProcessor::ResolverList resolvers; if (service) diff --git a/lib/perfdata/influxdbwriter.cpp b/lib/perfdata/influxdbwriter.cpp index d40f88627..dc8e48955 100644 --- a/lib/perfdata/influxdbwriter.cpp +++ b/lib/perfdata/influxdbwriter.cpp @@ -190,7 +190,7 @@ void InfluxdbWriter::InternalCheckResultHandler(const Checkable::Ptr& checkable, Host::Ptr host; Service::Ptr service; - boost::tie(host, service) = GetHostService(checkable); + tie(host, service) = GetHostService(checkable); MacroProcessor::ResolverList resolvers; if (service) @@ -275,7 +275,7 @@ void InfluxdbWriter::SendPerfdata(const Dictionary::Ptr& tmpl, const Checkable:: if (GetEnableSendMetadata()) { Host::Ptr host; Service::Ptr service; - boost::tie(host, service) = GetHostService(checkable); + tie(host, service) = GetHostService(checkable); Dictionary::Ptr fields = new Dictionary(); diff --git a/test/base-dictionary.cpp b/test/base-dictionary.cpp index dcfdbeabd..8d8177ebd 100644 --- a/test/base-dictionary.cpp +++ b/test/base-dictionary.cpp @@ -21,7 +21,6 @@ #include "base/objectlock.hpp" #include "base/json.hpp" #include -#include using namespace icinga; diff --git a/test/base-json.cpp b/test/base-json.cpp index 48704f489..6f3adb025 100644 --- a/test/base-json.cpp +++ b/test/base-json.cpp @@ -21,7 +21,6 @@ #include "base/objectlock.hpp" #include "base/json.hpp" #include -#include using namespace icinga; diff --git a/test/base-serialize.cpp b/test/base-serialize.cpp index 4311e1f65..13bfacd2e 100644 --- a/test/base-serialize.cpp +++ b/test/base-serialize.cpp @@ -24,7 +24,6 @@ #include "base/array.hpp" #include "base/dictionary.hpp" #include -#include using namespace icinga; diff --git a/test/base-type.cpp b/test/base-type.cpp index 08cca02df..8d5a9c64a 100644 --- a/test/base-type.cpp +++ b/test/base-type.cpp @@ -23,7 +23,6 @@ #include "base/application.hpp" #include "base/type.hpp" #include -#include using namespace icinga; From 9ce950b0f1d70a03e59178ecc3935acd63ddd4de Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Thu, 23 Nov 2017 06:51:48 +0100 Subject: [PATCH 09/15] Replace boost::ref/boost::cref with std::ref/std::cref --- lib/base/scriptutils.cpp | 4 ++-- lib/base/threadpool.cpp | 3 +-- lib/base/utility.cpp | 2 +- lib/cli/consolecommand.cpp | 8 ++++---- lib/cli/daemonutility.cpp | 10 +++++----- lib/cli/featureutility.cpp | 6 +++--- lib/cli/troubleshootcommand.cpp | 4 ++-- lib/config/configcompiler.cpp | 8 ++++---- lib/icinga/icingaapplication.cpp | 2 +- lib/icinga/macroprocessor.cpp | 4 ++-- lib/livestatus/livestatuslogutility.cpp | 4 ++-- lib/livestatus/table.cpp | 2 +- lib/remote/apilistener-filesync.cpp | 2 +- lib/remote/apilistener.cpp | 4 ++-- lib/remote/configpackageutility.cpp | 6 +++--- lib/remote/filterutility.cpp | 4 ++-- lib/remote/httprequest.cpp | 2 +- lib/remote/httpresponse.cpp | 2 +- 18 files changed, 38 insertions(+), 39 deletions(-) diff --git a/lib/base/scriptutils.cpp b/lib/base/scriptutils.cpp index a35db87c3..e3a1b64a7 100644 --- a/lib/base/scriptutils.cpp +++ b/lib/base/scriptutils.cpp @@ -477,7 +477,7 @@ Value ScriptUtils::Glob(const std::vector& args) type = args[1]; std::vector paths; - Utility::Glob(pathSpec, std::bind(&GlobCallbackHelper, boost::ref(paths), _1), type); + Utility::Glob(pathSpec, std::bind(&GlobCallbackHelper, std::ref(paths), _1), type); return Array::FromVector(paths); } @@ -496,7 +496,7 @@ Value ScriptUtils::GlobRecursive(const std::vector& args) type = args[2]; std::vector paths; - Utility::GlobRecursive(path, pattern, std::bind(&GlobCallbackHelper, boost::ref(paths), _1), type); + Utility::GlobRecursive(path, pattern, std::bind(&GlobCallbackHelper, std::ref(paths), _1), type); return Array::FromVector(paths); } diff --git a/lib/base/threadpool.cpp b/lib/base/threadpool.cpp index df5152d60..8b9b4705c 100644 --- a/lib/base/threadpool.cpp +++ b/lib/base/threadpool.cpp @@ -23,7 +23,6 @@ #include "base/utility.hpp" #include "base/exception.hpp" #include "base/application.hpp" -#include #include using namespace icinga; @@ -337,7 +336,7 @@ void ThreadPool::Queue::SpawnWorker(boost::thread_group& group) Log(LogDebug, "ThreadPool", "Spawning worker thread."); Threads[i] = WorkerThread(ThreadIdle); - Threads[i].Thread = group.create_thread(boost::bind(&ThreadPool::WorkerThread::ThreadProc, boost::ref(Threads[i]), boost::ref(*this))); + Threads[i].Thread = group.create_thread(std::bind(&ThreadPool::WorkerThread::ThreadProc, std::ref(Threads[i]), std::ref(*this))); break; } diff --git a/lib/base/utility.cpp b/lib/base/utility.cpp index 02238f712..ce6aa572d 100644 --- a/lib/base/utility.cpp +++ b/lib/base/utility.cpp @@ -770,7 +770,7 @@ void Utility::MkDirP(const String& path, int mode) void Utility::RemoveDirRecursive(const String& path) { std::vector paths; - Utility::GlobRecursive(path, "*", std::bind(&Utility::CollectPaths, _1, boost::ref(paths)), GlobFile | GlobDirectory); + Utility::GlobRecursive(path, "*", std::bind(&Utility::CollectPaths, _1, std::ref(paths)), GlobFile | GlobDirectory); /* This relies on the fact that GlobRecursive lists the parent directory first before recursing into subdirectories. */ diff --git a/lib/cli/consolecommand.cpp b/lib/cli/consolecommand.cpp index 55b836eb3..89cb892bc 100644 --- a/lib/cli/consolecommand.cpp +++ b/lib/cli/consolecommand.cpp @@ -196,9 +196,9 @@ char *ConsoleCommand::ConsoleCompleteHelper(const char *word, int state) l_ApiClient->AutocompleteScript(l_Session, word, l_ScriptFrame->Sandboxed, std::bind(&ConsoleCommand::AutocompleteScriptCompletionHandler, - boost::ref(mutex), boost::ref(cv), boost::ref(ready), + std::ref(mutex), std::ref(cv), std::ref(ready), _1, _2, - boost::ref(suggestions))); + std::ref(suggestions))); { boost::mutex::scoped_lock lock(mutex); @@ -426,9 +426,9 @@ incomplete: l_ApiClient->ExecuteScript(l_Session, command, scriptFrame.Sandboxed, std::bind(&ConsoleCommand::ExecuteScriptCompletionHandler, - boost::ref(mutex), boost::ref(cv), boost::ref(ready), + std::ref(mutex), std::ref(cv), std::ref(ready), _1, _2, - boost::ref(result), boost::ref(eptr))); + std::ref(result), std::ref(eptr))); { boost::mutex::scoped_lock lock(mutex); diff --git a/lib/cli/daemonutility.cpp b/lib/cli/daemonutility.cpp index 903cca03f..d9c9ff67d 100644 --- a/lib/cli/daemonutility.cpp +++ b/lib/cli/daemonutility.cpp @@ -52,7 +52,7 @@ static void IncludeZoneDirRecursive(const String& path, const String& package, b ConfigCompiler::RegisterZoneDir("_etc", path, zoneName); std::vector expressions; - Utility::GlobRecursive(path, "*.conf", std::bind(&ConfigCompiler::CollectIncludes, boost::ref(expressions), _1, zoneName, package), GlobFile); + Utility::GlobRecursive(path, "*.conf", std::bind(&ConfigCompiler::CollectIncludes, std::ref(expressions), _1, zoneName, package), GlobFile); DictExpression expr(expressions); if (!ExecuteExpression(&expr)) success = false; @@ -75,7 +75,7 @@ static void IncludeNonLocalZone(const String& zonePath, const String& package, b } std::vector expressions; - Utility::GlobRecursive(zonePath, "*.conf", std::bind(&ConfigCompiler::CollectIncludes, boost::ref(expressions), _1, zoneName, package), GlobFile); + Utility::GlobRecursive(zonePath, "*.conf", std::bind(&ConfigCompiler::CollectIncludes, std::ref(expressions), _1, zoneName, package), GlobFile); DictExpression expr(expressions); if (!ExecuteExpression(&expr)) success = false; @@ -126,7 +126,7 @@ bool DaemonUtility::ValidateConfigFiles(const std::vector& configs, String zonesEtcDir = Application::GetZonesDir(); if (!zonesEtcDir.IsEmpty() && Utility::PathExists(zonesEtcDir)) - Utility::Glob(zonesEtcDir + "/*", std::bind(&IncludeZoneDirRecursive, _1, "_etc", boost::ref(success)), GlobDirectory); + Utility::Glob(zonesEtcDir + "/*", std::bind(&IncludeZoneDirRecursive, _1, "_etc", std::ref(success)), GlobDirectory); if (!success) return false; @@ -135,7 +135,7 @@ bool DaemonUtility::ValidateConfigFiles(const std::vector& configs, * are authoritative on this node and are checked in HasZoneConfigAuthority(). */ String packagesVarDir = Application::GetLocalStateDir() + "/lib/icinga2/api/packages"; if (Utility::PathExists(packagesVarDir)) - Utility::Glob(packagesVarDir + "/*", std::bind(&IncludePackage, _1, boost::ref(success)), GlobDirectory); + Utility::Glob(packagesVarDir + "/*", std::bind(&IncludePackage, _1, std::ref(success)), GlobDirectory); if (!success) return false; @@ -143,7 +143,7 @@ bool DaemonUtility::ValidateConfigFiles(const std::vector& configs, /* Load cluster synchronized configuration files */ String zonesVarDir = Application::GetLocalStateDir() + "/lib/icinga2/api/zones"; if (Utility::PathExists(zonesVarDir)) - Utility::Glob(zonesVarDir + "/*", std::bind(&IncludeNonLocalZone, _1, "_cluster", boost::ref(success)), GlobDirectory); + Utility::Glob(zonesVarDir + "/*", std::bind(&IncludeNonLocalZone, _1, "_cluster", std::ref(success)), GlobDirectory); if (!success) return false; diff --git a/lib/cli/featureutility.cpp b/lib/cli/featureutility.cpp index 4b4b9df8e..296d8fba7 100644 --- a/lib/cli/featureutility.cpp +++ b/lib/cli/featureutility.cpp @@ -200,11 +200,11 @@ bool FeatureUtility::GetFeatures(std::vector& features, bool get_disable /* disable = available-enabled */ String available_pattern = GetFeaturesAvailablePath() + "/*.conf"; std::vector available; - Utility::Glob(available_pattern, std::bind(&FeatureUtility::CollectFeatures, _1, boost::ref(available)), GlobFile); + Utility::Glob(available_pattern, std::bind(&FeatureUtility::CollectFeatures, _1, std::ref(available)), GlobFile); String enabled_pattern = GetFeaturesEnabledPath() + "/*.conf"; std::vector enabled; - Utility::Glob(enabled_pattern, std::bind(&FeatureUtility::CollectFeatures, _1, boost::ref(enabled)), GlobFile); + Utility::Glob(enabled_pattern, std::bind(&FeatureUtility::CollectFeatures, _1, std::ref(enabled)), GlobFile); std::sort(available.begin(), available.end()); std::sort(enabled.begin(), enabled.end()); @@ -217,7 +217,7 @@ bool FeatureUtility::GetFeatures(std::vector& features, bool get_disable /* all enabled features */ String enabled_pattern = GetFeaturesEnabledPath() + "/*.conf"; - Utility::Glob(enabled_pattern, std::bind(&FeatureUtility::CollectFeatures, _1, boost::ref(features)), GlobFile); + Utility::Glob(enabled_pattern, std::bind(&FeatureUtility::CollectFeatures, _1, std::ref(features)), GlobFile); } return true; diff --git a/lib/cli/troubleshootcommand.cpp b/lib/cli/troubleshootcommand.cpp index 01ae8644b..a8e5d4b42 100644 --- a/lib/cli/troubleshootcommand.cpp +++ b/lib/cli/troubleshootcommand.cpp @@ -375,8 +375,8 @@ bool TroubleshootCommand::PrintCrashReports(InfoLog& log) String bestFilename; try { - Utility::Glob(spath, std::bind(&GetLatestReport, _1, boost::ref(bestTimestamp), - boost::ref(bestFilename)), GlobFile); + Utility::Glob(spath, std::bind(&GetLatestReport, _1, std::ref(bestTimestamp), + std::ref(bestFilename)), GlobFile); } #ifdef _WIN32 catch (win32_error &ex) { diff --git a/lib/config/configcompiler.cpp b/lib/config/configcompiler.cpp index f1bec5c91..dbb6c0c01 100644 --- a/lib/config/configcompiler.cpp +++ b/lib/config/configcompiler.cpp @@ -155,7 +155,7 @@ Expression *ConfigCompiler::HandleInclude(const String& relativeBase, const Stri std::vector expressions; - if (!Utility::Glob(includePath, std::bind(&ConfigCompiler::CollectIncludes, boost::ref(expressions), _1, zone, package), GlobFile) && includePath.FindFirstOf("*?") == String::NPos) { + if (!Utility::Glob(includePath, std::bind(&ConfigCompiler::CollectIncludes, std::ref(expressions), _1, zone, package), GlobFile) && includePath.FindFirstOf("*?") == String::NPos) { std::ostringstream msgbuf; msgbuf << "Include file '" + path + "' does not exist"; BOOST_THROW_EXCEPTION(ScriptError(msgbuf.str(), debuginfo)); @@ -185,7 +185,7 @@ Expression *ConfigCompiler::HandleIncludeRecursive(const String& relativeBase, c ppath = relativeBase + "/" + path; std::vector expressions; - Utility::GlobRecursive(ppath, pattern, std::bind(&ConfigCompiler::CollectIncludes, boost::ref(expressions), _1, zone, package), GlobFile); + Utility::GlobRecursive(ppath, pattern, std::bind(&ConfigCompiler::CollectIncludes, std::ref(expressions), _1, zone, package), GlobFile); DictExpression *dict = new DictExpression(expressions); dict->MakeInline(); @@ -205,7 +205,7 @@ void ConfigCompiler::HandleIncludeZone(const String& relativeBase, const String& RegisterZoneDir(tag, ppath, zoneName); - Utility::GlobRecursive(ppath, pattern, std::bind(&ConfigCompiler::CollectIncludes, boost::ref(expressions), _1, zoneName, package), GlobFile); + Utility::GlobRecursive(ppath, pattern, std::bind(&ConfigCompiler::CollectIncludes, std::ref(expressions), _1, zoneName, package), GlobFile); } /** @@ -231,7 +231,7 @@ Expression *ConfigCompiler::HandleIncludeZones(const String& relativeBase, const } std::vector expressions; - Utility::Glob(ppath + "/*", std::bind(&ConfigCompiler::HandleIncludeZone, newRelativeBase, tag, _1, pattern, package, boost::ref(expressions)), GlobDirectory); + Utility::Glob(ppath + "/*", std::bind(&ConfigCompiler::HandleIncludeZone, newRelativeBase, tag, _1, pattern, package, std::ref(expressions)), GlobDirectory); return new DictExpression(expressions); } diff --git a/lib/icinga/icingaapplication.cpp b/lib/icinga/icingaapplication.cpp index 74a4a4c8d..86b5d82f1 100644 --- a/lib/icinga/icingaapplication.cpp +++ b/lib/icinga/icingaapplication.cpp @@ -166,7 +166,7 @@ void IcingaApplication::DumpModifiedAttributes(void) fp.exceptions(std::ofstream::failbit | std::ofstream::badbit); ConfigObject::Ptr previousObject; - ConfigObject::DumpModifiedAttributes(std::bind(&PersistModAttrHelper, boost::ref(fp), boost::ref(previousObject), _1, _2, _3)); + ConfigObject::DumpModifiedAttributes(std::bind(&PersistModAttrHelper, std::ref(fp), std::ref(previousObject), _1, _2, _3)); if (previousObject) { ConfigWriter::EmitRaw(fp, "\tobj.version = "); diff --git a/lib/icinga/macroprocessor.cpp b/lib/icinga/macroprocessor.cpp index c7755df27..c97bd1b67 100644 --- a/lib/icinga/macroprocessor.cpp +++ b/lib/icinga/macroprocessor.cpp @@ -216,10 +216,10 @@ Value MacroProcessor::EvaluateFunction(const Function::Ptr& func, const Resolver } resolvers_this->Set("macro", new Function("macro (temporary)", std::bind(&MacroProcessor::InternalResolveMacrosShim, - _1, boost::cref(resolvers), cr, MacroProcessor::EscapeCallback(), resolvedMacros, useResolvedMacros, + _1, std::cref(resolvers), cr, MacroProcessor::EscapeCallback(), resolvedMacros, useResolvedMacros, recursionLevel + 1), { "str" })); resolvers_this->Set("resolve_arguments", new Function("resolve_arguments (temporary)", std::bind(&MacroProcessor::InternalResolveArgumentsShim, - _1, boost::cref(resolvers), cr, resolvedMacros, useResolvedMacros, + _1, std::cref(resolvers), cr, resolvedMacros, useResolvedMacros, recursionLevel + 1))); std::vector args; diff --git a/lib/livestatus/livestatuslogutility.cpp b/lib/livestatus/livestatuslogutility.cpp index 21570cf94..768c80c96 100644 --- a/lib/livestatus/livestatuslogutility.cpp +++ b/lib/livestatus/livestatuslogutility.cpp @@ -39,8 +39,8 @@ using namespace icinga; void LivestatusLogUtility::CreateLogIndex(const String& path, std::map& index) { - Utility::Glob(path + "/icinga.log", std::bind(&LivestatusLogUtility::CreateLogIndexFileHandler, _1, boost::ref(index)), GlobFile); - Utility::Glob(path + "/archives/*.log", std::bind(&LivestatusLogUtility::CreateLogIndexFileHandler, _1, boost::ref(index)), GlobFile); + Utility::Glob(path + "/icinga.log", std::bind(&LivestatusLogUtility::CreateLogIndexFileHandler, _1, std::ref(index)), GlobFile); + Utility::Glob(path + "/archives/*.log", std::bind(&LivestatusLogUtility::CreateLogIndexFileHandler, _1, std::ref(index)), GlobFile); } void LivestatusLogUtility::CreateLogIndexFileHandler(const String& path, std::map& index) diff --git a/lib/livestatus/table.cpp b/lib/livestatus/table.cpp index 7e04b21c0..34659f18c 100644 --- a/lib/livestatus/table.cpp +++ b/lib/livestatus/table.cpp @@ -128,7 +128,7 @@ std::vector Table::FilterRows(const Filter::Ptr& filter, int { std::vector rs; - FetchRows(std::bind(&Table::FilteredAddRow, this, boost::ref(rs), filter, limit, _1, _2, _3)); + FetchRows(std::bind(&Table::FilteredAddRow, this, std::ref(rs), filter, limit, _1, _2, _3)); return rs; } diff --git a/lib/remote/apilistener-filesync.cpp b/lib/remote/apilistener-filesync.cpp index 7dd5e4502..0c16e3c9f 100644 --- a/lib/remote/apilistener-filesync.cpp +++ b/lib/remote/apilistener-filesync.cpp @@ -72,7 +72,7 @@ ConfigDirInformation ApiListener::LoadConfigDir(const String& dir) ConfigDirInformation config; config.UpdateV1 = new Dictionary(); config.UpdateV2 = new Dictionary(); - Utility::GlobRecursive(dir, "*", std::bind(&ApiListener::ConfigGlobHandler, boost::ref(config), dir, _1), GlobFile); + Utility::GlobRecursive(dir, "*", std::bind(&ApiListener::ConfigGlobHandler, std::ref(config), dir, _1), GlobFile); return config; } diff --git a/lib/remote/apilistener.cpp b/lib/remote/apilistener.cpp index fce03dfab..4c3d4d06e 100644 --- a/lib/remote/apilistener.cpp +++ b/lib/remote/apilistener.cpp @@ -631,7 +631,7 @@ void ApiListener::ApiTimerHandler(void) double now = Utility::GetTime(); std::vector files; - Utility::Glob(GetApiDir() + "log/*", std::bind(&ApiListener::LogGlobHandler, boost::ref(files), _1), GlobFile); + Utility::Glob(GetApiDir() + "log/*", std::bind(&ApiListener::LogGlobHandler, std::ref(files), _1), GlobFile); std::sort(files.begin(), files.end()); for (int ts : files) { @@ -1090,7 +1090,7 @@ void ApiListener::ReplayLog(const JsonRpcConnection::Ptr& client) count = 0; std::vector files; - Utility::Glob(GetApiDir() + "log/*", std::bind(&ApiListener::LogGlobHandler, boost::ref(files), _1), GlobFile); + Utility::Glob(GetApiDir() + "log/*", std::bind(&ApiListener::LogGlobHandler, std::ref(files), _1), GlobFile); std::sort(files.begin(), files.end()); for (int ts : files) { diff --git a/lib/remote/configpackageutility.cpp b/lib/remote/configpackageutility.cpp index c7a6670fa..61cf09139 100644 --- a/lib/remote/configpackageutility.cpp +++ b/lib/remote/configpackageutility.cpp @@ -60,7 +60,7 @@ std::vector ConfigPackageUtility::GetPackages(void) { std::vector packages; Utility::Glob(GetPackageDir() + "/*", std::bind(&ConfigPackageUtility::CollectDirNames, - _1, boost::ref(packages)), GlobDirectory); + _1, std::ref(packages)), GlobDirectory); return packages; } @@ -237,7 +237,7 @@ void ConfigPackageUtility::DeleteStage(const String& packageName, const String& std::vector ConfigPackageUtility::GetStages(const String& packageName) { std::vector stages; - Utility::Glob(GetPackageDir() + "/" + packageName + "/*", std::bind(&ConfigPackageUtility::CollectDirNames, _1, boost::ref(stages)), GlobDirectory); + Utility::Glob(GetPackageDir() + "/" + packageName + "/*", std::bind(&ConfigPackageUtility::CollectDirNames, _1, std::ref(stages)), GlobDirectory); return stages; } @@ -263,7 +263,7 @@ String ConfigPackageUtility::GetActiveStage(const String& packageName) std::vector > ConfigPackageUtility::GetFiles(const String& packageName, const String& stageName) { std::vector > paths; - Utility::GlobRecursive(GetPackageDir() + "/" + packageName + "/" + stageName, "*", std::bind(&ConfigPackageUtility::CollectPaths, _1, boost::ref(paths)), GlobDirectory | GlobFile); + Utility::GlobRecursive(GetPackageDir() + "/" + packageName + "/" + stageName, "*", std::bind(&ConfigPackageUtility::CollectPaths, _1, std::ref(paths)), GlobDirectory | GlobFile); return paths; } diff --git a/lib/remote/filterutility.cpp b/lib/remote/filterutility.cpp index 7d897745f..b9895928d 100644 --- a/lib/remote/filterutility.cpp +++ b/lib/remote/filterutility.cpp @@ -269,8 +269,8 @@ std::vector FilterUtility::GetFilterTargets(const QueryDescription& qd, c try { provider->FindTargets(type, std::bind(&FilteredAddTarget, - boost::ref(permissionFrame), permissionFilter, - boost::ref(frame), ufilter, boost::ref(result), variableName, _1)); + std::ref(permissionFrame), permissionFilter, + std::ref(frame), ufilter, std::ref(result), variableName, _1)); } catch (const std::exception& ex) { delete ufilter; throw; diff --git a/lib/remote/httprequest.cpp b/lib/remote/httprequest.cpp index d5e2e6fc1..a1be4bd45 100644 --- a/lib/remote/httprequest.cpp +++ b/lib/remote/httprequest.cpp @@ -100,7 +100,7 @@ bool HttpRequest::Parse(StreamReadContext& src, bool may_wait) } else if (m_State == HttpRequestBody) { if (Headers->Get("transfer-encoding") == "chunked") { if (!m_ChunkContext) - m_ChunkContext = std::make_shared(boost::ref(src)); + m_ChunkContext = std::make_shared(std::ref(src)); char *data; size_t size; diff --git a/lib/remote/httpresponse.cpp b/lib/remote/httpresponse.cpp index 870e91e73..587b58747 100644 --- a/lib/remote/httpresponse.cpp +++ b/lib/remote/httpresponse.cpp @@ -182,7 +182,7 @@ bool HttpResponse::Parse(StreamReadContext& src, bool may_wait) } else if (m_State == HttpResponseBody) { if (Headers->Get("transfer-encoding") == "chunked") { if (!m_ChunkContext) - m_ChunkContext = std::make_shared(boost::ref(src)); + m_ChunkContext = std::make_shared(std::ref(src)); char *data; size_t size; From 63fd6e3905b40442c90666bec09bee593a3d8cb0 Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Thu, 23 Nov 2017 09:31:39 +0100 Subject: [PATCH 10/15] Get rid of INITIALIZE_ONCE for the ExternalCommandProcessor --- lib/icinga/externalcommandprocessor.cpp | 59 +++++++++++-------------- lib/icinga/externalcommandprocessor.hpp | 18 +++++++- 2 files changed, 41 insertions(+), 36 deletions(-) diff --git a/lib/icinga/externalcommandprocessor.cpp b/lib/icinga/externalcommandprocessor.cpp index 3ea5afe71..d1c9f73e0 100644 --- a/lib/icinga/externalcommandprocessor.cpp +++ b/lib/icinga/externalcommandprocessor.cpp @@ -43,39 +43,7 @@ using namespace icinga; -INITIALIZE_ONCE(&ExternalCommandProcessor::StaticInitialize); - -typedef std::function& arguments)> ExternalCommandCallback; - -struct ExternalCommandInfo -{ - ExternalCommandCallback Callback; - size_t MinArgs; - size_t MaxArgs; -}; - -static boost::mutex& GetMutex(void) -{ - static boost::mutex mtx; - return mtx; -} -static std::map& GetCommands(void) -{ - static std::map commands; - return commands; -} - -boost::signals2::signal&)> ExternalCommandProcessor::OnNewExternalCommand; - -static void RegisterCommand(const String& command, const ExternalCommandCallback& callback, size_t minArgs = 0, size_t maxArgs = UINT_MAX) -{ - boost::mutex::scoped_lock lock(GetMutex()); - ExternalCommandInfo eci; - eci.Callback = callback; - eci.MinArgs = minArgs; - eci.MaxArgs = (maxArgs == UINT_MAX) ? minArgs : maxArgs; - GetCommands()[command] = eci; -} +boost::signals2::signal&)> ExternalCommandProcessor::OnNewExternalCommand; void ExternalCommandProcessor::Execute(const String& line) { @@ -156,7 +124,17 @@ void ExternalCommandProcessor::Execute(double time, const String& command, const eci.Callback(time, realArguments); } -void ExternalCommandProcessor::StaticInitialize(void) +void ExternalCommandProcessor::RegisterCommand(const String& command, const ExternalCommandCallback& callback, size_t minArgs, size_t maxArgs) +{ + boost::mutex::scoped_lock lock(GetMutex()); + ExternalCommandInfo eci; + eci.Callback = callback; + eci.MinArgs = minArgs; + eci.MaxArgs = (maxArgs == UINT_MAX) ? minArgs : maxArgs; + GetCommands()[command] = eci; +} + +void ExternalCommandProcessor::RegisterCommands(void) { RegisterCommand("PROCESS_HOST_CHECK_RESULT", &ExternalCommandProcessor::ProcessHostCheckResult, 3); RegisterCommand("PROCESS_SERVICE_CHECK_RESULT", &ExternalCommandProcessor::ProcessServiceCheckResult, 4); @@ -2254,3 +2232,16 @@ void ExternalCommandProcessor::DisableServicegroupSvcNotifications(double, const service->ModifyAttribute("enable_notifications", false); } } + +boost::mutex& ExternalCommandProcessor::GetMutex(void) +{ + static boost::mutex mtx; + return mtx; +} + +std::map& ExternalCommandProcessor::GetCommands(void) +{ + static std::map commands; + return commands; +} + diff --git a/lib/icinga/externalcommandprocessor.hpp b/lib/icinga/externalcommandprocessor.hpp index 07fbfa512..51cf2d291 100644 --- a/lib/icinga/externalcommandprocessor.hpp +++ b/lib/icinga/externalcommandprocessor.hpp @@ -29,13 +29,20 @@ namespace icinga { +typedef std::function& arguments)> ExternalCommandCallback; + +struct ExternalCommandInfo +{ + ExternalCommandCallback Callback; + size_t MinArgs; + size_t MaxArgs; +}; + class I2_ICINGA_API ExternalCommandProcessor { public: static void Execute(const String& line); static void Execute(double time, const String& command, const std::vector& arguments); - static void StaticInitialize(void); - static boost::signals2::signal&)> OnNewExternalCommand; private: @@ -165,6 +172,13 @@ private: private: static void ChangeCustomCommandVarInternal(const Command::Ptr& command, const String& name, const Value& value); + + static void RegisterCommand(const String& command, const ExternalCommandCallback& callback, size_t minArgs = 0, size_t maxArgs = UINT_MAX); + static void RegisterCommands(void); + + static boost::mutex& GetMutex(void); + static std::map& GetCommands(void); + }; } From ebc11d41a5fa530d98b40638519d526158a144c7 Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Thu, 23 Nov 2017 09:46:06 +0100 Subject: [PATCH 11/15] Tidy up INITIALIZE_ONCE use in console.cpp a bit --- lib/base/console.cpp | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/lib/base/console.cpp b/lib/base/console.cpp index 057807995..62dccd2df 100644 --- a/lib/base/console.cpp +++ b/lib/base/console.cpp @@ -25,8 +25,7 @@ using namespace icinga; static ConsoleType l_ConsoleType = Console_Dumb; -static void InitializeConsole(void) -{ +INITIALIZE_ONCE([]() { l_ConsoleType = Console_Dumb; #ifndef _WIN32 @@ -35,9 +34,7 @@ static void InitializeConsole(void) #else /* _WIN32 */ l_ConsoleType = Console_Windows; #endif /* _WIN32 */ -} - -INITIALIZE_ONCE(InitializeConsole); +}) ConsoleColorTag::ConsoleColorTag(int color, ConsoleType consoleType) : m_Color(color), m_ConsoleType(consoleType) From 2e87c280ed476dbc28d22955c886a14aa560cffe Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Thu, 23 Nov 2017 09:58:05 +0100 Subject: [PATCH 12/15] Use initializer lists instead of std::vector::push_back --- lib/base/process.cpp | 5 +---- lib/cli/nodesetupcommand.cpp | 22 ++++----------------- lib/cli/nodewizardcommand.cpp | 22 ++++----------------- lib/icinga/dependency-apply.cpp | 5 +---- lib/icinga/notification-apply.cpp | 5 +---- lib/icinga/scheduleddowntime-apply.cpp | 5 +---- lib/icinga/service-apply.cpp | 4 +--- lib/remote/apiclient.cpp | 27 ++++---------------------- 8 files changed, 17 insertions(+), 78 deletions(-) diff --git a/lib/base/process.cpp b/lib/base/process.cpp index a8f354088..2f8590f78 100644 --- a/lib/base/process.cpp +++ b/lib/base/process.cpp @@ -574,10 +574,7 @@ Process::Arguments Process::PrepareCommand(const Value& command) #ifdef _WIN32 return command; #else /* _WIN32 */ - args.push_back("sh"); - args.push_back("-c"); - args.push_back(command); - return args; + return { "sh", "-c", command }; #endif } diff --git a/lib/cli/nodesetupcommand.cpp b/lib/cli/nodesetupcommand.cpp index 6d4617a97..ebf4fb81e 100644 --- a/lib/cli/nodesetupcommand.cpp +++ b/lib/cli/nodesetupcommand.cpp @@ -159,12 +159,7 @@ int NodeSetupCommand::SetupMaster(const boost::program_options::variables_map& v /* write zones.conf and update with zone + endpoint information */ Log(LogInformation, "cli", "Generating zone and object configuration."); - std::vector globalZones; - - globalZones.push_back("global-templates"); - globalZones.push_back("director-global"); - - NodeUtility::GenerateNodeMasterIcingaConfig(globalZones); + NodeUtility::GenerateNodeMasterIcingaConfig({ "global-templates", "director-global" }); /* update the ApiListener config - SetupMaster() will always enable it */ Log(LogInformation, "cli", "Updating the APIListener feature."); @@ -362,17 +357,13 @@ int NodeSetupCommand::SetupNode(const boost::program_options::variables_map& vm, /* disable the notifications feature */ Log(LogInformation, "cli", "Disabling the Notification feature."); - std::vector disable; - disable.push_back("notification"); - FeatureUtility::DisableFeatures(disable); + FeatureUtility::DisableFeatures({ "notification" }); /* enable the ApiListener config */ Log(LogInformation, "cli", "Updating the ApiListener feature."); - std::vector enable; - enable.push_back("api"); - FeatureUtility::EnableFeatures(enable); + FeatureUtility::EnableFeatures({ "api" }); String apipath = FeatureUtility::GetFeaturesAvailablePath() + "/api.conf"; NodeUtility::CreateBackupFile(apipath); @@ -427,12 +418,7 @@ int NodeSetupCommand::SetupNode(const boost::program_options::variables_map& vm, Log(LogInformation, "cli", "Generating zone and object configuration."); - std::vector globalZones; - - globalZones.push_back("global-templates"); - globalZones.push_back("director-global"); - - NodeUtility::GenerateNodeIcingaConfig(vm["endpoint"].as >(), globalZones); + NodeUtility::GenerateNodeIcingaConfig(vm["endpoint"].as >(), { "global-templates", "director-global" }); /* update constants.conf with NodeName = CN */ if (cn != Utility::GetFQDN()) { diff --git a/lib/cli/nodewizardcommand.cpp b/lib/cli/nodewizardcommand.cpp index 7ab4c2d0b..c3668570d 100644 --- a/lib/cli/nodewizardcommand.cpp +++ b/lib/cli/nodewizardcommand.cpp @@ -457,15 +457,11 @@ wizard_ticket: /* disable the notifications feature on client nodes */ Log(LogInformation, "cli", "Disabling the Notification feature."); - std::vector disable; - disable.push_back("notification"); - FeatureUtility::DisableFeatures(disable); + FeatureUtility::DisableFeatures({ "notification" }); Log(LogInformation, "cli", "Enabling the ApiListener feature."); - std::vector enable; - enable.push_back("api"); - FeatureUtility::EnableFeatures(enable); + FeatureUtility::EnableFeatures({ "api" }); String apiConfPath = FeatureUtility::GetFeaturesAvailablePath() + "/api.conf"; NodeUtility::CreateBackupFile(apiConfPath); @@ -503,12 +499,7 @@ wizard_ticket: /* apilistener config */ Log(LogInformation, "cli", "Generating local zones.conf."); - std::vector globalZones; - - globalZones.push_back("global-templates"); - globalZones.push_back("director-global"); - - NodeUtility::GenerateNodeIcingaConfig(endpoints, globalZones); + NodeUtility::GenerateNodeIcingaConfig(endpoints, { "global-templates", "director-global" }); if (cn != Utility::GetFQDN()) { Log(LogWarning, "cli") @@ -604,12 +595,7 @@ int NodeWizardCommand::MasterSetup(void) const else std::cout << "'api' feature already enabled.\n"; - std::vector globalZones; - - globalZones.push_back("global-templates"); - globalZones.push_back("director-global"); - - NodeUtility::GenerateNodeMasterIcingaConfig(globalZones); + NodeUtility::GenerateNodeMasterIcingaConfig({ "global-templates", "director-global" }); /* apilistener config */ std::cout << ConsoleColorTag(Console_Bold) diff --git a/lib/icinga/dependency-apply.cpp b/lib/icinga/dependency-apply.cpp index 34b0cf93a..b4df4dd7d 100644 --- a/lib/icinga/dependency-apply.cpp +++ b/lib/icinga/dependency-apply.cpp @@ -31,10 +31,7 @@ using namespace icinga; INITIALIZE_ONCE([]() { - std::vector targets; - targets.push_back("Host"); - targets.push_back("Service"); - ApplyRule::RegisterType("Dependency", targets); + ApplyRule::RegisterType("Dependency", { "Host", "Service" }); }); bool Dependency::EvaluateApplyRuleInstance(const Checkable::Ptr& checkable, const String& name, ScriptFrame& frame, const ApplyRule& rule) diff --git a/lib/icinga/notification-apply.cpp b/lib/icinga/notification-apply.cpp index bf01d04fd..7f8930f4e 100644 --- a/lib/icinga/notification-apply.cpp +++ b/lib/icinga/notification-apply.cpp @@ -31,10 +31,7 @@ using namespace icinga; INITIALIZE_ONCE([]() { - std::vector targets; - targets.push_back("Host"); - targets.push_back("Service"); - ApplyRule::RegisterType("Notification", targets); + ApplyRule::RegisterType("Notification", { "Host", "Service" }); }); bool Notification::EvaluateApplyRuleInstance(const Checkable::Ptr& checkable, const String& name, ScriptFrame& frame, const ApplyRule& rule) diff --git a/lib/icinga/scheduleddowntime-apply.cpp b/lib/icinga/scheduleddowntime-apply.cpp index 60028fe7f..752ba36d7 100644 --- a/lib/icinga/scheduleddowntime-apply.cpp +++ b/lib/icinga/scheduleddowntime-apply.cpp @@ -30,10 +30,7 @@ using namespace icinga; INITIALIZE_ONCE([]() { - std::vector targets; - targets.push_back("Host"); - targets.push_back("Service"); - ApplyRule::RegisterType("ScheduledDowntime", targets); + ApplyRule::RegisterType("ScheduledDowntime", { "Host", "Service" }); }); bool ScheduledDowntime::EvaluateApplyRuleInstance(const Checkable::Ptr& checkable, const String& name, ScriptFrame& frame, const ApplyRule& rule) diff --git a/lib/icinga/service-apply.cpp b/lib/icinga/service-apply.cpp index 6c2e594d3..360285f3a 100644 --- a/lib/icinga/service-apply.cpp +++ b/lib/icinga/service-apply.cpp @@ -30,9 +30,7 @@ using namespace icinga; INITIALIZE_ONCE([]() { - std::vector targets; - targets.push_back("Host"); - ApplyRule::RegisterType("Service", targets); + ApplyRule::RegisterType("Service", { "Host" }); }); bool Service::EvaluateApplyRuleInstance(const Host::Ptr& host, const String& name, ScriptFrame& frame, const ApplyRule& rule) diff --git a/lib/remote/apiclient.cpp b/lib/remote/apiclient.cpp index 5ca690de8..b4cc25813 100644 --- a/lib/remote/apiclient.cpp +++ b/lib/remote/apiclient.cpp @@ -39,11 +39,7 @@ void ApiClient::GetTypes(const TypesCompletionCallback& callback) const url->SetScheme("https"); url->SetHost(m_Connection->GetHost()); url->SetPort(m_Connection->GetPort()); - - std::vector path; - path.push_back("v1"); - path.push_back("types"); - url->SetPath(path); + url->SetPath({ "v1", "types" }); try { std::shared_ptr req = m_Connection->NewRequest(); @@ -110,12 +106,7 @@ void ApiClient::GetObjects(const String& pluralType, const ObjectsCompletionCall url->SetScheme("https"); url->SetHost(m_Connection->GetHost()); url->SetPort(m_Connection->GetPort()); - - std::vector path; - path.push_back("v1"); - path.push_back("objects"); - path.push_back(pluralType); - url->SetPath(path); + url->SetPath({ "v1", "objects", pluralType }); std::map > params; @@ -236,12 +227,7 @@ void ApiClient::ExecuteScript(const String& session, const String& command, bool url->SetScheme("https"); url->SetHost(m_Connection->GetHost()); url->SetPort(m_Connection->GetPort()); - - std::vector path; - path.push_back("v1"); - path.push_back("console"); - path.push_back("execute-script"); - url->SetPath(path); + url->SetPath({ "v1", "console", "execute-script" }); std::map > params; params["session"].push_back(session); @@ -320,12 +306,7 @@ void ApiClient::AutocompleteScript(const String& session, const String& command, url->SetScheme("https"); url->SetHost(m_Connection->GetHost()); url->SetPort(m_Connection->GetPort()); - - std::vector path; - path.push_back("v1"); - path.push_back("console"); - path.push_back("auto-complete-script"); - url->SetPath(path); + url->SetPath({ "v1", "console", "auto-complete-script" }); std::map > params; params["session"].push_back(session); From 59fca5d5acb6da6d9d437c1abdd6b681a8d8f257 Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Thu, 23 Nov 2017 15:32:33 +0100 Subject: [PATCH 13/15] Use std::vector instead of std::set where appropriate --- lib/icinga/checkable-dependency.cpp | 10 +++++----- lib/icinga/checkable.hpp | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/icinga/checkable-dependency.cpp b/lib/icinga/checkable-dependency.cpp index 1d2625425..90714fc9d 100644 --- a/lib/icinga/checkable-dependency.cpp +++ b/lib/icinga/checkable-dependency.cpp @@ -35,10 +35,10 @@ void Checkable::RemoveDependency(const Dependency::Ptr& dep) m_Dependencies.erase(dep); } -std::set Checkable::GetDependencies(void) const +std::vector Checkable::GetDependencies(void) const { boost::mutex::scoped_lock lock(m_DependencyMutex); - return m_Dependencies; + return std::vector(m_Dependencies.begin(), m_Dependencies.end()); } void Checkable::AddReverseDependency(const Dependency::Ptr& dep) @@ -53,10 +53,10 @@ void Checkable::RemoveReverseDependency(const Dependency::Ptr& dep) m_ReverseDependencies.erase(dep); } -std::set Checkable::GetReverseDependencies(void) const +std::vector Checkable::GetReverseDependencies(void) const { boost::mutex::scoped_lock lock(m_DependencyMutex); - return m_ReverseDependencies; + return std::vector(m_ReverseDependencies.begin(), m_ReverseDependencies.end()); } bool Checkable::IsReachable(DependencyType dt, Dependency::Ptr *failedDependency, int rstack) const @@ -148,7 +148,7 @@ void Checkable::GetAllChildrenInternal(std::set& children, int l for (const Checkable::Ptr& checkable : children) { std::set cChildren = checkable->GetChildren(); - if (!checkable->GetChildren().empty()) { + if (!cChildren.empty()) { GetAllChildrenInternal(cChildren, level + 1); localChildren.insert(cChildren.begin(), cChildren.end()); } diff --git a/lib/icinga/checkable.hpp b/lib/icinga/checkable.hpp index 4060f1d00..b2d118c31 100644 --- a/lib/icinga/checkable.hpp +++ b/lib/icinga/checkable.hpp @@ -185,11 +185,11 @@ public: /* Dependencies */ void AddDependency(const intrusive_ptr& dep); void RemoveDependency(const intrusive_ptr& dep); - std::set > GetDependencies(void) const; + std::vector > GetDependencies(void) const; void AddReverseDependency(const intrusive_ptr& dep); void RemoveReverseDependency(const intrusive_ptr& dep); - std::set > GetReverseDependencies(void) const; + std::vector > GetReverseDependencies(void) const; virtual void ValidateCheckInterval(double value, const ValidationUtils& utils) override; virtual void ValidateMaxCheckAttempts(int value, const ValidationUtils& utils) override; From 3c60fbf75ddd89c618b535e8dab0902c9049d724 Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Thu, 30 Nov 2017 08:19:58 +0100 Subject: [PATCH 14/15] Use std::vector::emplace_back instead of std::vector::push_back --- lib/base/array-script.cpp | 26 +++++------------- lib/base/array.cpp | 2 +- lib/base/function-script.cpp | 4 +-- lib/base/function.cpp | 2 +- lib/base/function.hpp | 2 +- lib/base/socketevents-epoll.cpp | 2 +- lib/base/socketevents-poll.cpp | 2 +- lib/base/threadpool.cpp | 2 +- lib/base/typetype-script.cpp | 4 +-- lib/base/utility.cpp | 10 +++---- lib/cli/apisetuputility.cpp | 15 ++--------- lib/cli/daemoncommand.cpp | 2 +- lib/cli/troubleshootcommand.cpp | 5 +--- lib/compat/statusdatawriter.cpp | 14 +++++----- lib/config/config_parser.yy | 8 +++--- lib/config/configitem.cpp | 4 +-- lib/config/vmops.hpp | 2 +- lib/db_ido/dbconnection.cpp | 5 ++-- lib/db_ido/dbevents.cpp | 23 +++++++--------- lib/db_ido/dbobject.cpp | 12 +++------ lib/db_ido/hostdbobject.cpp | 30 +++++++-------------- lib/db_ido/idochecktask.cpp | 8 +++--- lib/db_ido/servicedbobject.cpp | 24 ++++++----------- lib/db_ido/userdbobject.cpp | 12 +++------ lib/db_ido_mysql/idomysqlconnection.cpp | 4 +-- lib/icinga/checkcommand.cpp | 12 ++++----- lib/icinga/eventcommand.cpp | 10 +++---- lib/icinga/macroprocessor.cpp | 5 ++-- lib/icinga/notificationcommand.cpp | 20 +++++++------- lib/icinga/timeperiod.cpp | 7 +---- lib/livestatus/hoststable.cpp | 28 ++++++++++--------- lib/livestatus/livestatusquery.cpp | 8 +++--- lib/livestatus/servicestable.cpp | 36 ++++++++++++++----------- lib/livestatus/table.cpp | 3 +-- lib/methods/clrchecktask.cpp | 8 +++--- lib/methods/clusterzonechecktask.cpp | 8 +++--- lib/methods/dummychecktask.cpp | 8 +++--- lib/methods/pluginchecktask.cpp | 8 +++--- lib/methods/plugineventtask.cpp | 8 +++--- lib/methods/pluginnotificationtask.cpp | 14 +++++----- lib/perfdata/elasticsearchwriter.cpp | 6 ++--- lib/perfdata/graphitewriter.cpp | 6 ++--- lib/perfdata/influxdbwriter.cpp | 6 ++--- lib/perfdata/perfdatawriter.cpp | 6 ++--- lib/remote/apiclient.cpp | 4 +-- lib/remote/apilistener.cpp | 2 +- lib/remote/configpackageutility.cpp | 7 +++-- lib/remote/filterutility.cpp | 4 +-- lib/remote/httpclientconnection.cpp | 2 +- lib/remote/httphandler.cpp | 2 +- lib/remote/httpresponse.cpp | 2 +- lib/remote/infohandler.cpp | 2 +- lib/remote/url.cpp | 13 +++------ 53 files changed, 201 insertions(+), 268 deletions(-) diff --git a/lib/base/array-script.cpp b/lib/base/array-script.cpp index dd9d5628d..54fb394ec 100644 --- a/lib/base/array-script.cpp +++ b/lib/base/array-script.cpp @@ -77,10 +77,7 @@ static void ArrayClear(void) static bool ArraySortCmp(const Function::Ptr& cmp, const Value& a, const Value& b) { - std::vector args; - args.push_back(a); - args.push_back(b); - return cmp->Invoke(args); + return cmp->Invoke({ a, b }); } static Array::Ptr ArraySort(const std::vector& args) @@ -154,9 +151,7 @@ static Array::Ptr ArrayMap(const Function::Ptr& function) ObjectLock olock(self); for (const Value& item : self) { - std::vector args; - args.push_back(item); - result->Add(function->Invoke(args)); + result->Add(function->Invoke({ item })); } return result; @@ -177,10 +172,7 @@ static Value ArrayReduce(const Function::Ptr& function) ObjectLock olock(self); for (size_t i = 1; i < self->GetLength(); i++) { - std::vector args; - args.push_back(result); - args.push_back(self->Get(i)); - result = function->Invoke(args); + result = function->Invoke({ result, self->Get(i) }); } return result; @@ -198,9 +190,7 @@ static Array::Ptr ArrayFilter(const Function::Ptr& function) ObjectLock olock(self); for (const Value& item : self) { - std::vector args; - args.push_back(item); - if (function->Invoke(args)) + if (function->Invoke({ item })) result->Add(item); } @@ -217,9 +207,7 @@ static bool ArrayAny(const Function::Ptr& function) ObjectLock olock(self); for (const Value& item : self) { - std::vector args; - args.push_back(item); - if (function->Invoke(args)) + if (function->Invoke({ item })) return true; } @@ -236,9 +224,7 @@ static bool ArrayAll(const Function::Ptr& function) ObjectLock olock(self); for (const Value& item : self) { - std::vector args; - args.push_back(item); - if (!function->Invoke(args)) + if (!function->Invoke({ item })) return false; } diff --git a/lib/base/array.cpp b/lib/base/array.cpp index 243f88ecd..a493e8177 100644 --- a/lib/base/array.cpp +++ b/lib/base/array.cpp @@ -90,7 +90,7 @@ void Array::Add(Value&& value) { ObjectLock olock(this); - m_Data.push_back(std::move(value)); + m_Data.emplace_back(std::move(value)); } /** diff --git a/lib/base/function-script.cpp b/lib/base/function-script.cpp index 09e85939d..2df59cc37 100644 --- a/lib/base/function-script.cpp +++ b/lib/base/function-script.cpp @@ -34,7 +34,7 @@ static Value FunctionCall(const std::vector& args) Function::Ptr self = static_cast(vframe->Self); std::vector uargs(args.begin() + 1, args.end()); - return self->Invoke(args[0], uargs); + return self->InvokeThis(args[0], uargs); } static Value FunctionCallV(const Value& thisArg, const Array::Ptr& args) @@ -49,7 +49,7 @@ static Value FunctionCallV(const Value& thisArg, const Array::Ptr& args) uargs = std::vector(args->Begin(), args->End()); } - return self->Invoke(thisArg, uargs); + return self->InvokeThis(thisArg, uargs); } diff --git a/lib/base/function.cpp b/lib/base/function.cpp index 8cc233774..cb34d835f 100644 --- a/lib/base/function.cpp +++ b/lib/base/function.cpp @@ -42,7 +42,7 @@ Value Function::Invoke(const std::vector& arguments) return m_Callback(arguments); } -Value Function::Invoke(const Value& otherThis, const std::vector& arguments) +Value Function::InvokeThis(const Value& otherThis, const std::vector& arguments) { ScriptFrame frame; frame.Self = otherThis; diff --git a/lib/base/function.hpp b/lib/base/function.hpp index 6f257863f..6dc070080 100644 --- a/lib/base/function.hpp +++ b/lib/base/function.hpp @@ -49,7 +49,7 @@ public: { } Value Invoke(const std::vector& arguments = std::vector()); - Value Invoke(const Value& otherThis, const std::vector& arguments = std::vector()); + Value InvokeThis(const Value& otherThis, const std::vector& arguments = std::vector()); inline bool IsSideEffectFree(void) const { diff --git a/lib/base/socketevents-epoll.cpp b/lib/base/socketevents-epoll.cpp index dadd40117..589fe789a 100644 --- a/lib/base/socketevents-epoll.cpp +++ b/lib/base/socketevents-epoll.cpp @@ -116,7 +116,7 @@ void SocketEventEngineEpoll::ThreadProc(int tid) event.LifesupportReference = event.Descriptor.LifesupportObject; VERIFY(event.LifesupportReference); - events.push_back(event); + events.emplace_back(std::move(event)); } } diff --git a/lib/base/socketevents-poll.cpp b/lib/base/socketevents-poll.cpp index d141abe95..3c9539cf0 100644 --- a/lib/base/socketevents-poll.cpp +++ b/lib/base/socketevents-poll.cpp @@ -108,7 +108,7 @@ void SocketEventEnginePoll::ThreadProc(int tid) event.LifesupportReference = event.Descriptor.LifesupportObject; VERIFY(event.LifesupportReference); - events.push_back(event); + events.emplace_back(std::move(event)); } } diff --git a/lib/base/threadpool.cpp b/lib/base/threadpool.cpp index 8b9b4705c..683a6b6dd 100644 --- a/lib/base/threadpool.cpp +++ b/lib/base/threadpool.cpp @@ -212,7 +212,7 @@ bool ThreadPool::Post(const ThreadPool::WorkFunction& callback, SchedulerPolicy if (policy == LowLatencyScheduler) queue.SpawnWorker(m_ThreadGroup); - queue.Items.push_back(wi); + queue.Items.emplace_back(std::move(wi)); queue.CV.notify_one(); } diff --git a/lib/base/typetype-script.cpp b/lib/base/typetype-script.cpp index 66452fdcc..21ef5d572 100644 --- a/lib/base/typetype-script.cpp +++ b/lib/base/typetype-script.cpp @@ -28,9 +28,7 @@ using namespace icinga; static void InvokeAttributeHandlerHelper(const Function::Ptr& callback, const Object::Ptr& object, const Value& cookie) { - std::vector arguments; - arguments.push_back(object); - callback->Invoke(arguments); + callback->Invoke({ object }); } static void TypeRegisterAttributeHandler(const String& fieldName, const Function::Ptr& callback) diff --git a/lib/base/utility.cpp b/lib/base/utility.cpp index ce6aa572d..fddc40cfc 100644 --- a/lib/base/utility.cpp +++ b/lib/base/utility.cpp @@ -976,31 +976,31 @@ String Utility::FormatDuration(double duration) if (duration >= 86400) { int days = duration / 86400; - tokens.push_back(Convert::ToString(days) + (days != 1 ? " days" : " day")); + tokens.emplace_back(Convert::ToString(days) + (days != 1 ? " days" : " day")); duration = static_cast(duration) % 86400; } if (duration >= 3600) { int hours = duration / 3600; - tokens.push_back(Convert::ToString(hours) + (hours != 1 ? " hours" : " hour")); + tokens.emplace_back(Convert::ToString(hours) + (hours != 1 ? " hours" : " hour")); duration = static_cast(duration) % 3600; } if (duration >= 60) { int minutes = duration / 60; - tokens.push_back(Convert::ToString(minutes) + (minutes != 1 ? " minutes" : " minute")); + tokens.emplace_back(Convert::ToString(minutes) + (minutes != 1 ? " minutes" : " minute")); duration = static_cast(duration) % 60; } if (duration >= 1) { int seconds = duration; - tokens.push_back(Convert::ToString(seconds) + (seconds != 1 ? " seconds" : " second")); + tokens.emplace_back(Convert::ToString(seconds) + (seconds != 1 ? " seconds" : " second")); } if (tokens.size() == 0) { int milliseconds = std::floor(duration * 1000); if (milliseconds >= 1) - tokens.push_back(Convert::ToString(milliseconds) + (milliseconds != 1 ? " milliseconds" : " millisecond")); + tokens.emplace_back(Convert::ToString(milliseconds) + (milliseconds != 1 ? " milliseconds" : " millisecond")); else tokens.push_back("less than 1 millisecond"); } diff --git a/lib/cli/apisetuputility.cpp b/lib/cli/apisetuputility.cpp index b658f9339..4186475d8 100644 --- a/lib/cli/apisetuputility.cpp +++ b/lib/cli/apisetuputility.cpp @@ -132,16 +132,7 @@ bool ApiSetupUtility::SetupMasterCertificates(const String& cn) Utility::CopyFile(ca, target_ca); /* fix permissions: root -> icinga daemon user */ - std::vector files; - files.push_back(ca_path); - files.push_back(ca); - files.push_back(ca_key); - files.push_back(target_ca); - files.push_back(key); - files.push_back(csr); - files.push_back(cert); - - for (const String& file : files) { + for (const String& file : { ca_path, ca, ca_key, target_ca, key, csr, cert }) { if (!Utility::SetFileOwnership(file, user, group)) { Log(LogWarning, "cli") << "Cannot set ownership for user '" << user << "' group '" << group << "' on file '" << file << "'."; @@ -201,9 +192,7 @@ bool ApiSetupUtility::SetupMasterEnableApi(void) { Log(LogInformation, "cli", "Enabling the 'api' feature."); - std::vector features; - features.push_back("api"); - FeatureUtility::EnableFeatures(features); + FeatureUtility::EnableFeatures({ "api" }); return true; } diff --git a/lib/cli/daemoncommand.cpp b/lib/cli/daemoncommand.cpp index 6459fe2fb..e9d0d60d6 100644 --- a/lib/cli/daemoncommand.cpp +++ b/lib/cli/daemoncommand.cpp @@ -234,7 +234,7 @@ int DaemonCommand::Run(const po::variables_map& vm, const std::vector configs; if (vm.count("config") > 0) - configs = vm["config"].as < std::vector >() ; + configs = vm["config"].as >(); else if (!vm.count("no-config")) configs.push_back(Application::GetSysconfDir() + "/icinga2/icinga2.conf"); diff --git a/lib/cli/troubleshootcommand.cpp b/lib/cli/troubleshootcommand.cpp index a8e5d4b42..28ea6cb72 100644 --- a/lib/cli/troubleshootcommand.cpp +++ b/lib/cli/troubleshootcommand.cpp @@ -444,10 +444,7 @@ bool TroubleshootCommand::PrintFile(InfoLog& log, const String& path) bool TroubleshootCommand::CheckConfig(void) { - std::vector configs; - configs.push_back(Application::GetSysconfDir() + "/icinga2/icinga2.conf"); - - return DaemonUtility::ValidateConfigFiles(configs, Application::GetObjectsPath()); + return DaemonUtility::ValidateConfigFiles({ Application::GetSysconfDir() + "/icinga2/icinga2.conf" }, Application::GetObjectsPath()); } //print is supposed allow the user to print the object file diff --git a/lib/compat/statusdatawriter.cpp b/lib/compat/statusdatawriter.cpp index d67258035..ec9c7c8c9 100644 --- a/lib/compat/statusdatawriter.cpp +++ b/lib/compat/statusdatawriter.cpp @@ -634,8 +634,8 @@ void StatusDataWriter::UpdateObjectsCache(void) for (const Service::Ptr& service : sg->GetMembers()) { Host::Ptr host = service->GetHost(); - sglist.push_back(host->GetName()); - sglist.push_back(service->GetShortName()); + sglist.emplace_back(host->GetName()); + sglist.emplace_back(service->GetShortName()); } DumpStringList(tempobjectfp, sglist); @@ -734,15 +734,15 @@ void StatusDataWriter::UpdateObjectsCache(void) int state_filter = dep->GetStateFilter(); std::vector failure_criteria; if (state_filter & StateFilterOK || state_filter & StateFilterUp) - failure_criteria.push_back("o"); + failure_criteria.emplace_back("o"); if (state_filter & StateFilterWarning) - failure_criteria.push_back("w"); + failure_criteria.emplace_back("w"); if (state_filter & StateFilterCritical) - failure_criteria.push_back("c"); + failure_criteria.emplace_back("c"); if (state_filter & StateFilterUnknown) - failure_criteria.push_back("u"); + failure_criteria.emplace_back("u"); if (state_filter & StateFilterDown) - failure_criteria.push_back("d"); + failure_criteria.emplace_back("d"); String criteria = boost::algorithm::join(failure_criteria, ","); diff --git a/lib/config/config_parser.yy b/lib/config/config_parser.yy index 36f972410..688429a53 100644 --- a/lib/config/config_parser.yy +++ b/lib/config/config_parser.yy @@ -328,13 +328,13 @@ lterm_items_inner: lterm %dprec 2 { $$ = new std::vector >(); EItemInfo info = { true, @1 }; - $$->push_back(std::make_pair($1, info)); + $$->emplace_back($1, info); } | rterm_no_side_effect { $$ = new std::vector >(); EItemInfo info = { false, @1 }; - $$->push_back(std::make_pair($1, info)); + $$->emplace_back($1, info); } | lterm_items_inner sep lterm %dprec 1 { @@ -345,7 +345,7 @@ lterm_items_inner: lterm %dprec 2 if ($3) { EItemInfo info = { true, @3 }; - $$->push_back(std::make_pair($3, info)); + $$->emplace_back($3, info); } } | lterm_items_inner sep rterm_no_side_effect %dprec 1 @@ -357,7 +357,7 @@ lterm_items_inner: lterm %dprec 2 if ($3) { EItemInfo info = { false, @3 }; - $$->push_back(std::make_pair($3, info)); + $$->emplace_back($3, info); } } ; diff --git a/lib/config/configitem.cpp b/lib/config/configitem.cpp index 0ab2a0712..edb0527ba 100644 --- a/lib/config/configitem.cpp +++ b/lib/config/configitem.cpp @@ -404,7 +404,7 @@ bool ConfigItem::CommitNewItems(const ActivationContext::Ptr& context, WorkQueue if (kv2.second->m_ActivationContext != context) continue; - items.push_back(std::make_pair(kv2.second, false)); + items.emplace_back(kv2.second, false); } } @@ -419,7 +419,7 @@ bool ConfigItem::CommitNewItems(const ActivationContext::Ptr& context, WorkQueue if (item->m_Abstract || item->m_Object) continue; - items.push_back(std::make_pair(item, true)); + items.emplace_back(item, true); } m_UnnamedItems.swap(newUnnamedItems); diff --git a/lib/config/vmops.hpp b/lib/config/vmops.hpp index 193a57ab5..4376f32d7 100644 --- a/lib/config/vmops.hpp +++ b/lib/config/vmops.hpp @@ -102,7 +102,7 @@ public: static inline Value FunctionCall(ScriptFrame& frame, const Value& self, const Function::Ptr& func, const std::vector& arguments) { if (!self.IsEmpty() || self.IsString()) - return func->Invoke(self, arguments); + return func->InvokeThis(self, arguments); else return func->Invoke(arguments); diff --git a/lib/db_ido/dbconnection.cpp b/lib/db_ido/dbconnection.cpp index 96a744fdc..a9b189ade 100644 --- a/lib/db_ido/dbconnection.cpp +++ b/lib/db_ido/dbconnection.cpp @@ -181,13 +181,12 @@ void DbConnection::UpdateProgramStatus(void) query1.Fields->Set("process_performance_data", (IcingaApplication::GetInstance()->GetEnablePerfdata() ? 1 : 0)); query1.WhereCriteria = new Dictionary(); query1.WhereCriteria->Set("instance_id", 0); /* DbConnection class fills in real ID */ - query1.Priority = PriorityHigh; - queries.push_back(query1); + queries.emplace_back(std::move(query1)); DbQuery query2; query2.Type = DbQueryNewTransaction; - queries.push_back(query2); + queries.emplace_back(std::move(query2)); DbObject::OnMultipleQueries(queries); diff --git a/lib/db_ido/dbevents.cpp b/lib/db_ido/dbevents.cpp index b14b19ce6..d67901c90 100644 --- a/lib/db_ido/dbevents.cpp +++ b/lib/db_ido/dbevents.cpp @@ -383,8 +383,7 @@ void DbEvents::AddCommentInternal(std::vector& queries, const Comment:: } query1.Category = DbCatComment; query1.Fields = fields1; - - queries.push_back(query1); + queries.emplace_back(std::move(query1)); } void DbEvents::RemoveComment(const Comment::Ptr& comment) @@ -409,7 +408,7 @@ void DbEvents::RemoveCommentInternal(std::vector& queries, const Commen query1.WhereCriteria->Set("object_id", checkable); query1.WhereCriteria->Set("entry_time", DbValue::FromTimestamp(entry_time)); query1.WhereCriteria->Set("name", comment->GetName()); - queries.push_back(query1); + queries.emplace_back(std::move(query1)); /* History - update deletion time for service/host */ double now = Utility::GetTime(); @@ -429,7 +428,7 @@ void DbEvents::RemoveCommentInternal(std::vector& queries, const Commen query2.WhereCriteria->Set("object_id", checkable); query2.WhereCriteria->Set("entry_time", DbValue::FromTimestamp(entry_time)); query2.WhereCriteria->Set("name", comment->GetName()); - queries.push_back(query2); + queries.emplace_back(std::move(query2)); } /* downtimes */ @@ -526,8 +525,7 @@ void DbEvents::AddDowntimeInternal(std::vector& queries, const Downtime query1.Category = DbCatDowntime; query1.Fields = fields1; - - queries.push_back(query1); + queries.emplace_back(std::move(query1)); /* host/service status */ if (!historical) { @@ -558,8 +556,7 @@ void DbEvents::AddDowntimeInternal(std::vector& queries, const Downtime query2.WhereCriteria->Set("host_object_id", host); query2.WhereCriteria->Set("instance_id", 0); /* DbConnection class fills in real ID */ - - queries.push_back(query2); + queries.emplace_back(std::move(query2)); } } @@ -587,7 +584,7 @@ void DbEvents::RemoveDowntimeInternal(std::vector& queries, const Downt query1.WhereCriteria->Set("scheduled_start_time", DbValue::FromTimestamp(downtime->GetStartTime())); query1.WhereCriteria->Set("scheduled_end_time", DbValue::FromTimestamp(downtime->GetEndTime())); query1.WhereCriteria->Set("name", downtime->GetName()); - queries.push_back(query1); + queries.emplace_back(std::move(query1)); /* History - update actual_end_time, was_cancelled for service (and host in case) */ double now = Utility::GetTime(); @@ -616,8 +613,7 @@ void DbEvents::RemoveDowntimeInternal(std::vector& queries, const Downt query3.WhereCriteria->Set("scheduled_start_time", DbValue::FromTimestamp(downtime->GetStartTime())); query3.WhereCriteria->Set("scheduled_end_time", DbValue::FromTimestamp(downtime->GetEndTime())); query3.WhereCriteria->Set("name", downtime->GetName()); - - queries.push_back(query3); + queries.emplace_back(std::move(query3)); /* host/service status */ Host::Ptr host; @@ -647,8 +643,7 @@ void DbEvents::RemoveDowntimeInternal(std::vector& queries, const Downt query4.WhereCriteria->Set("host_object_id", host); query4.WhereCriteria->Set("instance_id", 0); /* DbConnection class fills in real ID */ - - queries.push_back(query4); + queries.emplace_back(std::move(query4)); } void DbEvents::TriggerDowntime(const Downtime::Ptr& downtime) @@ -908,7 +903,7 @@ void DbEvents::AddNotificationHistory(const Notification::Ptr& notification, con fields2->Set("instance_id", 0); /* DbConnection class fills in real ID */ query2.Fields = fields2; - queries.push_back(query2); + queries.emplace_back(std::move(query2)); } DbObject::OnMultipleQueries(queries); diff --git a/lib/db_ido/dbobject.cpp b/lib/db_ido/dbobject.cpp index a40e7d775..a606a2e67 100644 --- a/lib/db_ido/dbobject.cpp +++ b/lib/db_ido/dbobject.cpp @@ -217,8 +217,7 @@ void DbObject::SendVarsConfigUpdateHeavy(void) query1.Category = DbCatConfig; query1.WhereCriteria = new Dictionary(); query1.WhereCriteria->Set("object_id", obj); - - queries.push_back(query1); + queries.emplace_back(std::move(query1)); DbQuery query2; query2.Table = "customvariablestatus"; @@ -226,8 +225,7 @@ void DbObject::SendVarsConfigUpdateHeavy(void) query2.Category = DbCatConfig; query2.WhereCriteria = new Dictionary(); query2.WhereCriteria->Set("object_id", obj); - - queries.push_back(query2); + queries.emplace_back(std::move(query2)); Dictionary::Ptr vars = CompatUtility::GetCustomAttributeConfig(custom_var_object); @@ -260,8 +258,7 @@ void DbObject::SendVarsConfigUpdateHeavy(void) query3.Type = DbQueryInsert; query3.Category = DbCatConfig; query3.Fields = fields; - - queries.push_back(query3); + queries.emplace_back(std::move(query3)); } } @@ -313,8 +310,7 @@ void DbObject::SendVarsStatusUpdate(void) query.WhereCriteria = new Dictionary(); query.WhereCriteria->Set("object_id", obj); query.WhereCriteria->Set("varname", kv.first); - - queries.push_back(query); + queries.emplace_back(std::move(query)); } OnMultipleQueries(queries); diff --git a/lib/db_ido/hostdbobject.cpp b/lib/db_ido/hostdbobject.cpp index aa1a32a08..eb5ae5741 100644 --- a/lib/db_ido/hostdbobject.cpp +++ b/lib/db_ido/hostdbobject.cpp @@ -191,8 +191,7 @@ void HostDbObject::OnConfigUpdateHeavy(void) query1.Category = DbCatConfig; query1.WhereCriteria = new Dictionary(); query1.WhereCriteria->Set("host_object_id", host); - - queries.push_back(query1); + queries.emplace_back(std::move(query1)); if (groups) { ObjectLock olock(groups); @@ -211,8 +210,7 @@ void HostDbObject::OnConfigUpdateHeavy(void) query2.WhereCriteria->Set("instance_id", 0); /* DbConnection class fills in real ID */ query2.WhereCriteria->Set("hostgroup_id", DbValue::FromObjectInsertID(group)); query2.WhereCriteria->Set("host_object_id", host); - - queries.push_back(query2); + queries.emplace_back(std::move(query2)); } } @@ -226,8 +224,7 @@ void HostDbObject::OnConfigUpdateHeavy(void) query2.Category = DbCatConfig; query2.WhereCriteria = new Dictionary(); query2.WhereCriteria->Set(GetType()->GetTable() + "_id", DbValue::FromObjectInsertID(GetObject())); - - queries.push_back(query2); + queries.emplace_back(std::move(query2)); /* parents */ for (const Checkable::Ptr& checkable : host->GetParents()) { @@ -250,8 +247,7 @@ void HostDbObject::OnConfigUpdateHeavy(void) query1.Type = DbQueryInsert; query1.Category = DbCatConfig; query1.Fields = fields1; - - queries.push_back(query1); + queries.emplace_back(std::move(query1)); } DbObject::OnMultipleQueries(queries); @@ -268,8 +264,7 @@ void HostDbObject::OnConfigUpdateHeavy(void) query3.Category = DbCatConfig; query3.WhereCriteria = new Dictionary(); query3.WhereCriteria->Set("dependent_host_object_id", host); - - queries.push_back(query3); + queries.emplace_back(std::move(query3)); for (const Dependency::Ptr& dep : host->GetDependencies()) { Checkable::Ptr parent = dep->GetParent(); @@ -299,8 +294,7 @@ void HostDbObject::OnConfigUpdateHeavy(void) query2.Type = DbQueryInsert; query2.Category = DbCatConfig; query2.Fields = fields2; - - queries.push_back(query2); + queries.emplace_back(std::move(query2)); } DbObject::OnMultipleQueries(queries); @@ -316,8 +310,7 @@ void HostDbObject::OnConfigUpdateHeavy(void) query4.Category = DbCatConfig; query4.WhereCriteria = new Dictionary(); query4.WhereCriteria->Set("host_id", DbValue::FromObjectInsertID(host)); - - queries.push_back(query4); + queries.emplace_back(std::move(query4)); for (const User::Ptr& user : CompatUtility::GetCheckableNotificationUsers(host)) { Log(LogDebug, "HostDbObject") @@ -333,8 +326,7 @@ void HostDbObject::OnConfigUpdateHeavy(void) query_contact.Type = DbQueryInsert; query_contact.Category = DbCatConfig; query_contact.Fields = fields_contact; - - queries.push_back(query_contact); + queries.emplace_back(std::move(query_contact)); } DbObject::OnMultipleQueries(queries); @@ -350,8 +342,7 @@ void HostDbObject::OnConfigUpdateHeavy(void) query5.Category = DbCatConfig; query5.WhereCriteria = new Dictionary(); query5.WhereCriteria->Set("host_id", DbValue::FromObjectInsertID(host)); - - queries.push_back(query5); + queries.emplace_back(std::move(query5)); for (const UserGroup::Ptr& usergroup : CompatUtility::GetCheckableNotificationUserGroups(host)) { Log(LogDebug, "HostDbObject") @@ -367,8 +358,7 @@ void HostDbObject::OnConfigUpdateHeavy(void) query_contact.Type = DbQueryInsert; query_contact.Category = DbCatConfig; query_contact.Fields = fields_contact; - - queries.push_back(query_contact); + queries.emplace_back(std::move(query_contact)); } DbObject::OnMultipleQueries(queries); diff --git a/lib/db_ido/idochecktask.cpp b/lib/db_ido/idochecktask.cpp index 707b1ed37..b3c11eefd 100644 --- a/lib/db_ido/idochecktask.cpp +++ b/lib/db_ido/idochecktask.cpp @@ -46,10 +46,10 @@ void IdoCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckResult MacroProcessor::ResolverList resolvers; if (service) - resolvers.push_back(std::make_pair("service", service)); - resolvers.push_back(std::make_pair("host", host)); - resolvers.push_back(std::make_pair("command", commandObj)); - resolvers.push_back(std::make_pair("icinga", IcingaApplication::GetInstance())); + resolvers.emplace_back("service", service); + resolvers.emplace_back("host", host); + resolvers.emplace_back("command", commandObj); + resolvers.emplace_back("icinga", IcingaApplication::GetInstance()); String idoType = MacroProcessor::ResolveMacros("$ido_type$", resolvers, checkable->GetLastCheckResult(), NULL, MacroProcessor::EscapeCallback(), resolvedMacros, useResolvedMacros); diff --git a/lib/db_ido/servicedbobject.cpp b/lib/db_ido/servicedbobject.cpp index 378d3f457..0086dc9ec 100644 --- a/lib/db_ido/servicedbobject.cpp +++ b/lib/db_ido/servicedbobject.cpp @@ -185,8 +185,7 @@ void ServiceDbObject::OnConfigUpdateHeavy(void) query1.Category = DbCatConfig; query1.WhereCriteria = new Dictionary(); query1.WhereCriteria->Set("service_object_id", service); - - queries.push_back(query1); + queries.emplace_back(std::move(query1)); if (groups) { ObjectLock olock(groups); @@ -205,8 +204,7 @@ void ServiceDbObject::OnConfigUpdateHeavy(void) query2.WhereCriteria->Set("instance_id", 0); /* DbConnection class fills in real ID */ query2.WhereCriteria->Set("servicegroup_id", DbValue::FromObjectInsertID(group)); query2.WhereCriteria->Set("service_object_id", service); - - queries.push_back(query2); + queries.emplace_back(std::move(query2)); } } @@ -224,8 +222,7 @@ void ServiceDbObject::OnConfigUpdateHeavy(void) query2.Category = DbCatConfig; query2.WhereCriteria = new Dictionary(); query2.WhereCriteria->Set("dependent_service_object_id", service); - - queries.push_back(query2); + queries.emplace_back(std::move(query2)); for (const Dependency::Ptr& dep : service->GetDependencies()) { Checkable::Ptr parent = dep->GetParent(); @@ -258,8 +255,7 @@ void ServiceDbObject::OnConfigUpdateHeavy(void) query1.Type = DbQueryInsert; query1.Category = DbCatConfig; query1.Fields = fields1; - - queries.push_back(query1); + queries.emplace_back(std::move(query1)); } DbObject::OnMultipleQueries(queries); @@ -276,8 +272,7 @@ void ServiceDbObject::OnConfigUpdateHeavy(void) query3.Category = DbCatConfig; query3.WhereCriteria = new Dictionary(); query3.WhereCriteria->Set("service_id", DbValue::FromObjectInsertID(service)); - - queries.push_back(query3); + queries.emplace_back(std::move(query3)); for (const User::Ptr& user : CompatUtility::GetCheckableNotificationUsers(service)) { Log(LogDebug, "ServiceDbObject") @@ -293,8 +288,7 @@ void ServiceDbObject::OnConfigUpdateHeavy(void) query_contact.Type = DbQueryInsert; query_contact.Category = DbCatConfig; query_contact.Fields = fields_contact; - - queries.push_back(query_contact); + queries.emplace_back(std::move(query_contact)); } DbObject::OnMultipleQueries(queries); @@ -310,8 +304,7 @@ void ServiceDbObject::OnConfigUpdateHeavy(void) query4.Category = DbCatConfig; query4.WhereCriteria = new Dictionary(); query4.WhereCriteria->Set("service_id", DbValue::FromObjectInsertID(service)); - - queries.push_back(query4); + queries.emplace_back(std::move(query4)); for (const UserGroup::Ptr& usergroup : CompatUtility::GetCheckableNotificationUserGroups(service)) { Log(LogDebug, "ServiceDbObject") @@ -327,8 +320,7 @@ void ServiceDbObject::OnConfigUpdateHeavy(void) query_contact.Type = DbQueryInsert; query_contact.Category = DbCatConfig; query_contact.Fields = fields_contact; - - queries.push_back(query_contact); + queries.emplace_back(std::move(query_contact)); } DbObject::OnMultipleQueries(queries); diff --git a/lib/db_ido/userdbobject.cpp b/lib/db_ido/userdbobject.cpp index 9e25b8be4..fae23d925 100644 --- a/lib/db_ido/userdbobject.cpp +++ b/lib/db_ido/userdbobject.cpp @@ -94,8 +94,7 @@ void UserDbObject::OnConfigUpdateHeavy(void) query1.Category = DbCatConfig; query1.WhereCriteria = new Dictionary(); query1.WhereCriteria->Set("contact_object_id", user); - - queries.push_back(query1); + queries.emplace_back(std::move(query1)); if (groups) { ObjectLock olock(groups); @@ -114,8 +113,7 @@ void UserDbObject::OnConfigUpdateHeavy(void) query2.WhereCriteria->Set("instance_id", 0); /* DbConnection class fills in real ID */ query2.WhereCriteria->Set("contactgroup_id", DbValue::FromObjectInsertID(group)); query2.WhereCriteria->Set("contact_object_id", user); - - queries.push_back(query2); + queries.emplace_back(std::move(query2)); } } @@ -129,8 +127,7 @@ void UserDbObject::OnConfigUpdateHeavy(void) query2.Category = DbCatConfig; query2.WhereCriteria = new Dictionary(); query2.WhereCriteria->Set("contact_id", DbValue::FromObjectInsertID(user)); - - queries.push_back(query2); + queries.emplace_back(std::move(query2)); Dictionary::Ptr vars = user->GetVars(); @@ -155,8 +152,7 @@ void UserDbObject::OnConfigUpdateHeavy(void) query.Table = "contact_addresses"; query.Category = DbCatConfig; query.Fields = fields; - - queries.push_back(query); + queries.emplace_back(std::move(query)); } } diff --git a/lib/db_ido_mysql/idomysqlconnection.cpp b/lib/db_ido_mysql/idomysqlconnection.cpp index bc737b166..1ed3a8c97 100644 --- a/lib/db_ido_mysql/idomysqlconnection.cpp +++ b/lib/db_ido_mysql/idomysqlconnection.cpp @@ -420,7 +420,7 @@ void IdoMysqlConnection::Reconnect(void) SetObjectActive(dbobj, active); if (active) - activeDbObjs.push_back(dbobj); + activeDbObjs.emplace_back(std::move(dbobj)); } SetIDCacheValid(true); @@ -489,7 +489,7 @@ void IdoMysqlConnection::AsyncQuery(const String& query, const std::function 25000) { FinishAsyncQueries(); diff --git a/lib/icinga/checkcommand.cpp b/lib/icinga/checkcommand.cpp index e300515b9..167701a2e 100644 --- a/lib/icinga/checkcommand.cpp +++ b/lib/icinga/checkcommand.cpp @@ -28,10 +28,10 @@ REGISTER_TYPE(CheckCommand); void CheckCommand::Execute(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr, const Dictionary::Ptr& resolvedMacros, bool useResolvedMacros) { - std::vector arguments; - arguments.push_back(checkable); - arguments.push_back(cr); - arguments.push_back(resolvedMacros); - arguments.push_back(useResolvedMacros); - GetExecute()->Invoke(arguments); + GetExecute()->Invoke({ + checkable, + cr, + resolvedMacros, + useResolvedMacros + }); } diff --git a/lib/icinga/eventcommand.cpp b/lib/icinga/eventcommand.cpp index 54d54851c..886c89203 100644 --- a/lib/icinga/eventcommand.cpp +++ b/lib/icinga/eventcommand.cpp @@ -27,9 +27,9 @@ REGISTER_TYPE(EventCommand); void EventCommand::Execute(const Checkable::Ptr& checkable, const Dictionary::Ptr& resolvedMacros, bool useResolvedMacros) { - std::vector arguments; - arguments.push_back(checkable); - arguments.push_back(resolvedMacros); - arguments.push_back(useResolvedMacros); - GetExecute()->Invoke(arguments); + GetExecute()->Invoke({ + checkable, + resolvedMacros, + useResolvedMacros + }); } diff --git a/lib/icinga/macroprocessor.cpp b/lib/icinga/macroprocessor.cpp index c97bd1b67..465667ed4 100644 --- a/lib/icinga/macroprocessor.cpp +++ b/lib/icinga/macroprocessor.cpp @@ -222,8 +222,7 @@ Value MacroProcessor::EvaluateFunction(const Function::Ptr& func, const Resolver _1, std::cref(resolvers), cr, resolvedMacros, useResolvedMacros, recursionLevel + 1))); - std::vector args; - return func->Invoke(resolvers_this, args); + return func->InvokeThis(resolvers_this); } Value MacroProcessor::InternalResolveMacros(const String& str, const ResolverList& resolvers, @@ -542,7 +541,7 @@ Value MacroProcessor::ResolveArguments(const Value& command, const Dictionary::P continue; } - args.push_back(arg); + args.emplace_back(std::move(arg)); } std::sort(args.begin(), args.end()); diff --git a/lib/icinga/notificationcommand.cpp b/lib/icinga/notificationcommand.cpp index fc99872f8..3313b76af 100644 --- a/lib/icinga/notificationcommand.cpp +++ b/lib/icinga/notificationcommand.cpp @@ -29,14 +29,14 @@ Dictionary::Ptr NotificationCommand::Execute(const Notification::Ptr& notificati const String& author, const String& comment, const Dictionary::Ptr& resolvedMacros, bool useResolvedMacros) { - std::vector arguments; - arguments.push_back(notification); - arguments.push_back(user); - arguments.push_back(cr); - arguments.push_back(type); - arguments.push_back(author); - arguments.push_back(comment); - arguments.push_back(resolvedMacros); - arguments.push_back(useResolvedMacros); - return GetExecute()->Invoke(arguments); + return GetExecute()->Invoke({ + notification, + user, + cr, + type, + author, + comment, + resolvedMacros, + useResolvedMacros, + }); } diff --git a/lib/icinga/timeperiod.cpp b/lib/icinga/timeperiod.cpp index f0b8b6644..ffb7fe864 100644 --- a/lib/icinga/timeperiod.cpp +++ b/lib/icinga/timeperiod.cpp @@ -244,12 +244,7 @@ void TimePeriod::UpdateRegion(double begin, double end, bool clearExisting) return; } - std::vector arguments; - arguments.push_back(this); - arguments.push_back(begin); - arguments.push_back(end); - - Array::Ptr segments = GetUpdate()->Invoke(arguments); + Array::Ptr segments = GetUpdate()->Invoke({ this, begin, end }); { ObjectLock olock(this); diff --git a/lib/livestatus/hoststable.cpp b/lib/livestatus/hoststable.cpp index ce4cb2a83..e98a1aa25 100644 --- a/lib/livestatus/hoststable.cpp +++ b/lib/livestatus/hoststable.cpp @@ -323,9 +323,10 @@ Value HostsTable::NotesExpandedAccessor(const Value& row) if (!host) return Empty; - MacroProcessor::ResolverList resolvers; - resolvers.push_back(std::make_pair("host", host)); - resolvers.push_back(std::make_pair("icinga", IcingaApplication::GetInstance())); + MacroProcessor::ResolverList resolvers { + { "host", host }, + { "icinga", IcingaApplication::GetInstance() } + }; return MacroProcessor::ResolveMacros(host->GetNotes(), resolvers, CheckResult::Ptr()); } @@ -347,9 +348,10 @@ Value HostsTable::NotesUrlExpandedAccessor(const Value& row) if (!host) return Empty; - MacroProcessor::ResolverList resolvers; - resolvers.push_back(std::make_pair("host", host)); - resolvers.push_back(std::make_pair("icinga", IcingaApplication::GetInstance())); + MacroProcessor::ResolverList resolvers { + { "host", host }, + { "icinga", IcingaApplication::GetInstance() } + }; return MacroProcessor::ResolveMacros(host->GetNotesUrl(), resolvers); } @@ -371,9 +373,10 @@ Value HostsTable::ActionUrlExpandedAccessor(const Value& row) if (!host) return Empty; - MacroProcessor::ResolverList resolvers; - resolvers.push_back(std::make_pair("host", host)); - resolvers.push_back(std::make_pair("icinga", IcingaApplication::GetInstance())); + MacroProcessor::ResolverList resolvers { + { "host", host }, + { "icinga", IcingaApplication::GetInstance() } + }; return MacroProcessor::ResolveMacros(host->GetActionUrl(), resolvers); } @@ -427,9 +430,10 @@ Value HostsTable::IconImageExpandedAccessor(const Value& row) if (!host) return Empty; - MacroProcessor::ResolverList resolvers; - resolvers.push_back(std::make_pair("host", host)); - resolvers.push_back(std::make_pair("icinga", IcingaApplication::GetInstance())); + MacroProcessor::ResolverList resolvers { + { "host", host }, + { "icinga", IcingaApplication::GetInstance() } + }; return MacroProcessor::ResolveMacros(host->GetIconImage(), resolvers); } diff --git a/lib/livestatus/livestatusquery.cpp b/lib/livestatus/livestatusquery.cpp index 3132fe532..6dbb52c9a 100644 --- a/lib/livestatus/livestatusquery.cpp +++ b/lib/livestatus/livestatusquery.cpp @@ -309,12 +309,12 @@ Filter::Ptr LivestatusQuery::ParseFilter(const String& params, unsigned long& fr break; } - tokens.push_back(temp_buffer.SubStr(0, sp_index)); + tokens.emplace_back(temp_buffer.SubStr(0, sp_index)); temp_buffer = temp_buffer.SubStr(sp_index + 1); } /* add the rest as value */ - tokens.push_back(temp_buffer); + tokens.emplace_back(std::move(temp_buffer)); if (tokens.size() == 2) tokens.push_back(""); @@ -490,7 +490,7 @@ void LivestatusQuery::ExecuteGetHelper(const Stream::Ptr& stream) column_objs.reserve(columns.size()); for (const String& columnName : columns) - column_objs.push_back(std::make_pair(columnName, table->GetColumn(columnName))); + column_objs.emplace_back(columnName, table->GetColumn(columnName)); for (const LivestatusRowValue& object : objects) { Array::Ptr row = new Array(); @@ -520,7 +520,7 @@ void LivestatusQuery::ExecuteGetHelper(const Stream::Ptr& stream) for (const String& columnName : m_Columns) { Column column = table->GetColumn(columnName); - statsKey.push_back(column.ExtractValue(object.Row, object.GroupByType, object.GroupByObject)); + statsKey.emplace_back(column.ExtractValue(object.Row, object.GroupByType, object.GroupByObject)); } auto it = allStats.find(statsKey); diff --git a/lib/livestatus/servicestable.cpp b/lib/livestatus/servicestable.cpp index d7583da2c..76baa3bca 100644 --- a/lib/livestatus/servicestable.cpp +++ b/lib/livestatus/servicestable.cpp @@ -375,10 +375,11 @@ Value ServicesTable::NotesExpandedAccessor(const Value& row) if (!service) return Empty; - MacroProcessor::ResolverList resolvers; - resolvers.push_back(std::make_pair("service", service)); - resolvers.push_back(std::make_pair("host", service->GetHost())); - resolvers.push_back(std::make_pair("icinga", IcingaApplication::GetInstance())); + MacroProcessor::ResolverList resolvers { + { "service", service }, + { "host", service->GetHost() }, + { "icinga", IcingaApplication::GetInstance() } + }; return MacroProcessor::ResolveMacros(service->GetNotes(), resolvers); } @@ -400,10 +401,11 @@ Value ServicesTable::NotesUrlExpandedAccessor(const Value& row) if (!service) return Empty; - MacroProcessor::ResolverList resolvers; - resolvers.push_back(std::make_pair("service", service)); - resolvers.push_back(std::make_pair("host", service->GetHost())); - resolvers.push_back(std::make_pair("icinga", IcingaApplication::GetInstance())); + MacroProcessor::ResolverList resolvers { + { "service", service }, + { "host", service->GetHost() }, + { "icinga", IcingaApplication::GetInstance() } + }; return MacroProcessor::ResolveMacros(service->GetNotesUrl(), resolvers); } @@ -425,10 +427,11 @@ Value ServicesTable::ActionUrlExpandedAccessor(const Value& row) if (!service) return Empty; - MacroProcessor::ResolverList resolvers; - resolvers.push_back(std::make_pair("service", service)); - resolvers.push_back(std::make_pair("host", service->GetHost())); - resolvers.push_back(std::make_pair("icinga", IcingaApplication::GetInstance())); + MacroProcessor::ResolverList resolvers { + { "service", service }, + { "host", service->GetHost() }, + { "icinga", IcingaApplication::GetInstance() } + }; return MacroProcessor::ResolveMacros(service->GetActionUrl(), resolvers); } @@ -450,10 +453,11 @@ Value ServicesTable::IconImageExpandedAccessor(const Value& row) if (!service) return Empty; - MacroProcessor::ResolverList resolvers; - resolvers.push_back(std::make_pair("service", service)); - resolvers.push_back(std::make_pair("host", service->GetHost())); - resolvers.push_back(std::make_pair("icinga", IcingaApplication::GetInstance())); + MacroProcessor::ResolverList resolvers { + { "service", service }, + { "host", service->GetHost() }, + { "icinga", IcingaApplication::GetInstance() } + }; return MacroProcessor::ResolveMacros(service->GetIconImage(), resolvers); } diff --git a/lib/livestatus/table.cpp b/lib/livestatus/table.cpp index 34659f18c..1e121ecb1 100644 --- a/lib/livestatus/table.cpp +++ b/lib/livestatus/table.cpp @@ -144,8 +144,7 @@ bool Table::FilteredAddRow(std::vector& rs, const Filter::Pt rval.GroupByType = groupByType; rval.GroupByObject = groupByObject; - rs.push_back(rval); - + rs.emplace_back(std::move(rval)); } return true; diff --git a/lib/methods/clrchecktask.cpp b/lib/methods/clrchecktask.cpp index 576538524..20640898b 100644 --- a/lib/methods/clrchecktask.cpp +++ b/lib/methods/clrchecktask.cpp @@ -156,10 +156,10 @@ void ClrCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckResult MacroProcessor::ResolverList resolvers; if (service) - resolvers.push_back(std::make_pair("service", service)); - resolvers.push_back(std::make_pair("host", host)); - resolvers.push_back(std::make_pair("command", commandObj)); - resolvers.push_back(std::make_pair("icinga", IcingaApplication::GetInstance())); + resolvers.emplace_back("service", service); + resolvers.emplace_back("host", host); + resolvers.emplace_back("command", commandObj); + resolvers.emplace_back("icinga", IcingaApplication::GetInstance()); Dictionary::Ptr envMacros = new Dictionary(); diff --git a/lib/methods/clusterzonechecktask.cpp b/lib/methods/clusterzonechecktask.cpp index 919e7fbed..80208b66d 100644 --- a/lib/methods/clusterzonechecktask.cpp +++ b/lib/methods/clusterzonechecktask.cpp @@ -52,10 +52,10 @@ void ClusterZoneCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const Che MacroProcessor::ResolverList resolvers; if (service) - resolvers.push_back(std::make_pair("service", service)); - resolvers.push_back(std::make_pair("host", host)); - resolvers.push_back(std::make_pair("command", commandObj)); - resolvers.push_back(std::make_pair("icinga", IcingaApplication::GetInstance())); + resolvers.emplace_back("service", service); + resolvers.emplace_back("host", host); + resolvers.emplace_back("command", commandObj); + resolvers.emplace_back("icinga", IcingaApplication::GetInstance()); String zoneName = MacroProcessor::ResolveMacros("$cluster_zone$", resolvers, checkable->GetLastCheckResult(), NULL, MacroProcessor::EscapeCallback(), resolvedMacros, useResolvedMacros); diff --git a/lib/methods/dummychecktask.cpp b/lib/methods/dummychecktask.cpp index 7f6b89a7c..652ef7e4a 100644 --- a/lib/methods/dummychecktask.cpp +++ b/lib/methods/dummychecktask.cpp @@ -44,10 +44,10 @@ void DummyCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckResu MacroProcessor::ResolverList resolvers; if (service) - resolvers.push_back(std::make_pair("service", service)); - resolvers.push_back(std::make_pair("host", host)); - resolvers.push_back(std::make_pair("command", commandObj)); - resolvers.push_back(std::make_pair("icinga", IcingaApplication::GetInstance())); + resolvers.emplace_back("service", service); + resolvers.emplace_back("host", host); + resolvers.emplace_back("command", commandObj); + resolvers.emplace_back("icinga", IcingaApplication::GetInstance()); int dummyState = MacroProcessor::ResolveMacros("$dummy_state$", resolvers, checkable->GetLastCheckResult(), NULL, MacroProcessor::EscapeCallback(), resolvedMacros, useResolvedMacros); diff --git a/lib/methods/pluginchecktask.cpp b/lib/methods/pluginchecktask.cpp index d2953b0dd..4507bd10a 100644 --- a/lib/methods/pluginchecktask.cpp +++ b/lib/methods/pluginchecktask.cpp @@ -46,10 +46,10 @@ void PluginCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckRes MacroProcessor::ResolverList resolvers; if (service) - resolvers.push_back(std::make_pair("service", service)); - resolvers.push_back(std::make_pair("host", host)); - resolvers.push_back(std::make_pair("command", commandObj)); - resolvers.push_back(std::make_pair("icinga", IcingaApplication::GetInstance())); + resolvers.emplace_back("service", service); + resolvers.emplace_back("host", host); + resolvers.emplace_back("command", commandObj); + resolvers.emplace_back("icinga", IcingaApplication::GetInstance()); PluginUtility::ExecuteCommand(commandObj, checkable, checkable->GetLastCheckResult(), resolvers, resolvedMacros, useResolvedMacros, diff --git a/lib/methods/plugineventtask.cpp b/lib/methods/plugineventtask.cpp index 51308f555..594451896 100644 --- a/lib/methods/plugineventtask.cpp +++ b/lib/methods/plugineventtask.cpp @@ -44,10 +44,10 @@ void PluginEventTask::ScriptFunc(const Checkable::Ptr& checkable, MacroProcessor::ResolverList resolvers; if (service) - resolvers.push_back(std::make_pair("service", service)); - resolvers.push_back(std::make_pair("host", host)); - resolvers.push_back(std::make_pair("command", commandObj)); - resolvers.push_back(std::make_pair("icinga", IcingaApplication::GetInstance())); + resolvers.emplace_back("service", service); + resolvers.emplace_back("host", host); + resolvers.emplace_back("command", commandObj); + resolvers.emplace_back("icinga", IcingaApplication::GetInstance()); PluginUtility::ExecuteCommand(commandObj, checkable, checkable->GetLastCheckResult(), resolvers, resolvedMacros, useResolvedMacros, diff --git a/lib/methods/pluginnotificationtask.cpp b/lib/methods/pluginnotificationtask.cpp index 3485c5c0f..b4ec80df2 100644 --- a/lib/methods/pluginnotificationtask.cpp +++ b/lib/methods/pluginnotificationtask.cpp @@ -55,14 +55,14 @@ void PluginNotificationTask::ScriptFunc(const Notification::Ptr& notification, tie(host, service) = GetHostService(checkable); MacroProcessor::ResolverList resolvers; - resolvers.push_back(std::make_pair("user", user)); - resolvers.push_back(std::make_pair("notification", notificationExtra)); - resolvers.push_back(std::make_pair("notification", notification)); + resolvers.emplace_back("user", user); + resolvers.emplace_back("notification", notificationExtra); + resolvers.emplace_back("notification", notification); if (service) - resolvers.push_back(std::make_pair("service", service)); - resolvers.push_back(std::make_pair("host", host)); - resolvers.push_back(std::make_pair("command", commandObj)); - resolvers.push_back(std::make_pair("icinga", IcingaApplication::GetInstance())); + resolvers.emplace_back("service", service); + resolvers.emplace_back("host", host); + resolvers.emplace_back("command", commandObj); + resolvers.emplace_back("icinga", IcingaApplication::GetInstance()); PluginUtility::ExecuteCommand(commandObj, checkable, cr, resolvers, resolvedMacros, useResolvedMacros, diff --git a/lib/perfdata/elasticsearchwriter.cpp b/lib/perfdata/elasticsearchwriter.cpp index ce648cd54..f113aef13 100644 --- a/lib/perfdata/elasticsearchwriter.cpp +++ b/lib/perfdata/elasticsearchwriter.cpp @@ -363,7 +363,7 @@ void ElasticsearchWriter::Enqueue(String type, const Dictionary::Ptr& fields, do Log(LogDebug, "ElasticsearchWriter") << "Add to fields to message list: '" << fieldsBody << "'."; - m_DataBuffer.push_back(indexBody + fieldsBody); + m_DataBuffer.emplace_back(indexBody + fieldsBody); /* Flush if we've buffered too much to prevent excessive memory use. */ if (static_cast(m_DataBuffer.size()) >= GetFlushThreshold()) { @@ -412,10 +412,10 @@ void ElasticsearchWriter::SendRequest(const String& body) /* Specify the index path. Best practice is a daily rotation. * Example: http://localhost:9200/icinga2-2017.09.11?pretty=1 */ - path.push_back(GetIndex() + "-" + Utility::FormatDateTime("%Y.%m.%d", Utility::GetTime())); + path.emplace_back(GetIndex() + "-" + Utility::FormatDateTime("%Y.%m.%d", Utility::GetTime())); /* Use the bulk message format. */ - path.push_back("_bulk"); + path.emplace_back("_bulk"); url->SetPath(path); diff --git a/lib/perfdata/graphitewriter.cpp b/lib/perfdata/graphitewriter.cpp index 86611393c..b87104358 100644 --- a/lib/perfdata/graphitewriter.cpp +++ b/lib/perfdata/graphitewriter.cpp @@ -199,9 +199,9 @@ void GraphiteWriter::CheckResultHandlerInternal(const Checkable::Ptr& checkable, MacroProcessor::ResolverList resolvers; if (service) - resolvers.push_back(std::make_pair("service", service)); - resolvers.push_back(std::make_pair("host", host)); - resolvers.push_back(std::make_pair("icinga", IcingaApplication::GetInstance())); + resolvers.emplace_back("service", service); + resolvers.emplace_back("host", host); + resolvers.emplace_back("icinga", IcingaApplication::GetInstance()); String prefix; diff --git a/lib/perfdata/influxdbwriter.cpp b/lib/perfdata/influxdbwriter.cpp index dc8e48955..e9636645c 100644 --- a/lib/perfdata/influxdbwriter.cpp +++ b/lib/perfdata/influxdbwriter.cpp @@ -194,9 +194,9 @@ void InfluxdbWriter::InternalCheckResultHandler(const Checkable::Ptr& checkable, MacroProcessor::ResolverList resolvers; if (service) - resolvers.push_back(std::make_pair("service", service)); - resolvers.push_back(std::make_pair("host", host)); - resolvers.push_back(std::make_pair("icinga", IcingaApplication::GetInstance())); + resolvers.emplace_back("service", service); + resolvers.emplace_back("host", host); + resolvers.emplace_back("icinga", IcingaApplication::GetInstance()); String prefix; diff --git a/lib/perfdata/perfdatawriter.cpp b/lib/perfdata/perfdatawriter.cpp index 3200252ff..cb2da1150 100644 --- a/lib/perfdata/perfdatawriter.cpp +++ b/lib/perfdata/perfdatawriter.cpp @@ -100,9 +100,9 @@ void PerfdataWriter::CheckResultHandler(const Checkable::Ptr& checkable, const C MacroProcessor::ResolverList resolvers; if (service) - resolvers.push_back(std::make_pair("service", service)); - resolvers.push_back(std::make_pair("host", host)); - resolvers.push_back(std::make_pair("icinga", IcingaApplication::GetInstance())); + resolvers.emplace_back("service", service); + resolvers.emplace_back("host", host); + resolvers.emplace_back("icinga", IcingaApplication::GetInstance()); if (service) { String line = MacroProcessor::ResolveMacros(GetServiceFormatTemplate(), resolvers, cr, NULL, &PerfdataWriter::EscapeMacroMetric); diff --git a/lib/remote/apiclient.cpp b/lib/remote/apiclient.cpp index b4cc25813..8e91669f5 100644 --- a/lib/remote/apiclient.cpp +++ b/lib/remote/apiclient.cpp @@ -87,7 +87,7 @@ void ApiClient::TypesHttpCompletionCallback(HttpRequest& request, HttpResponse& type->Name = typeInfo->Get("name"); type->PluralName = typeInfo->Get("plural_name"); // TODO: attributes - types.push_back(type); + types.emplace_back(std::move(type)); } callback(boost::exception_ptr(), types); @@ -204,7 +204,7 @@ void ApiClient::ObjectsHttpCompletionCallback(HttpRequest& request, ApiObjectReference ref; ref.Name = refInfo->Get("name"); ref.Type = refInfo->Get("type"); - object->UsedBy.push_back(ref); + object->UsedBy.emplace_back(std::move(ref)); } } diff --git a/lib/remote/apilistener.cpp b/lib/remote/apilistener.cpp index 4c3d4d06e..6e964c921 100644 --- a/lib/remote/apilistener.cpp +++ b/lib/remote/apilistener.cpp @@ -758,7 +758,7 @@ void ApiListener::ApiReconnectTimerHandler(void) std::vector names; for (const Endpoint::Ptr& endpoint : ConfigType::GetObjectsByType()) if (endpoint->GetConnected()) - names.push_back(endpoint->GetName() + " (" + Convert::ToString(endpoint->GetClients().size()) + ")"); + names.emplace_back(endpoint->GetName() + " (" + Convert::ToString(endpoint->GetClients().size()) + ")"); Log(LogNotice, "ApiListener") << "Connected endpoints: " << Utility::NaturalJoin(names); diff --git a/lib/remote/configpackageutility.cpp b/lib/remote/configpackageutility.cpp index 61cf09139..4bcff3504 100644 --- a/lib/remote/configpackageutility.cpp +++ b/lib/remote/configpackageutility.cpp @@ -66,8 +66,7 @@ std::vector ConfigPackageUtility::GetPackages(void) void ConfigPackageUtility::CollectDirNames(const String& path, std::vector& dirs) { - String name = Utility::BaseName(path); - dirs.push_back(name); + dirs.emplace_back(Utility::BaseName(path)); } bool ConfigPackageUtility::PackageExists(const String& name) @@ -279,7 +278,7 @@ void ConfigPackageUtility::CollectPaths(const String& path, std::vector FilterUtility::GetFilterTargets(const QueryDescription& qd, c if (!FilterUtility::EvaluateFilter(permissionFrame, permissionFilter, target, variableName)) BOOST_THROW_EXCEPTION(ScriptError("Access denied to object '" + name + "' of type '" + type + "'")); - result.push_back(target); + result.emplace_back(std::move(target)); } attr = provider->GetPluralName(type); @@ -228,7 +228,7 @@ std::vector FilterUtility::GetFilterTargets(const QueryDescription& qd, c if (!FilterUtility::EvaluateFilter(permissionFrame, permissionFilter, target, variableName)) BOOST_THROW_EXCEPTION(ScriptError("Access denied to object '" + name + "' of type '" + type + "'")); - result.push_back(target); + result.emplace_back(std::move(target)); } } } diff --git a/lib/remote/httpclientconnection.cpp b/lib/remote/httpclientconnection.cpp index e730ff2fa..8cb6bbfdd 100644 --- a/lib/remote/httpclientconnection.cpp +++ b/lib/remote/httpclientconnection.cpp @@ -169,7 +169,7 @@ std::shared_ptr HttpClientConnection::NewRequest(void) void HttpClientConnection::SubmitRequest(const std::shared_ptr& request, const HttpCompletionCallback& callback) { - m_Requests.push_back(std::make_pair(request, callback)); + m_Requests.emplace_back(request, callback); request->Finish(); } diff --git a/lib/remote/httphandler.cpp b/lib/remote/httphandler.cpp index 1273fe754..f0dd17426 100644 --- a/lib/remote/httphandler.cpp +++ b/lib/remote/httphandler.cpp @@ -72,7 +72,7 @@ void HttpHandler::ProcessRequest(const ApiUser::Ptr& user, HttpRequest& request, if (current_handlers) { ObjectLock olock(current_handlers); - for (const HttpHandler::Ptr current_handler : current_handlers) { + for (const HttpHandler::Ptr& current_handler : current_handlers) { handlers.push_back(current_handler); } } diff --git a/lib/remote/httpresponse.cpp b/lib/remote/httpresponse.cpp index 587b58747..5499d6d32 100644 --- a/lib/remote/httpresponse.cpp +++ b/lib/remote/httpresponse.cpp @@ -57,7 +57,7 @@ void HttpResponse::SetStatus(int code, const String& message) void HttpResponse::AddHeader(const String& key, const String& value) { - m_Headers.push_back(key + ": " + value + "\r\n"); + m_Headers.emplace_back(key + ": " + value + "\r\n"); } void HttpResponse::FinishHeaders(void) diff --git a/lib/remote/infohandler.cpp b/lib/remote/infohandler.cpp index ce8a6a1a3..89de1341a 100644 --- a/lib/remote/infohandler.cpp +++ b/lib/remote/infohandler.cpp @@ -62,7 +62,7 @@ bool InfoHandler::HandleRequest(const ApiUser::Ptr& user, HttpRequest& request, if (hasFilter) name += " (filtered)"; - permInfo.push_back(name); + permInfo.emplace_back(std::move(name)); } } diff --git a/lib/remote/url.cpp b/lib/remote/url.cpp index 16a0dbd88..2fe56d730 100644 --- a/lib/remote/url.cpp +++ b/lib/remote/url.cpp @@ -212,8 +212,7 @@ void Url::AddQueryElement(const String& name, const String& value) { auto it = m_Query.find(name); if (it == m_Query.end()) { - m_Query[name] = std::vector(); - m_Query[name].push_back(value); + m_Query[name] = std::vector { value }; } else m_Query[name].push_back(value); } @@ -363,9 +362,7 @@ bool Url::ParsePath(const String& path) if (!ValidateToken(token, ACPATHSEGMENT)) return false; - String decodedToken = Utility::UnescapeString(token); - - m_Path.push_back(decodedToken); + m_Path.emplace_back(Utility::UnescapeString(token)); } return true; @@ -411,11 +408,9 @@ bool Url::ParseQuery(const String& query) auto it = m_Query.find(key); if (it == m_Query.end()) { - m_Query[key] = std::vector(); - m_Query[key].push_back(value); + m_Query[key] = std::vector { std::move(value) }; } else - m_Query[key].push_back(value); - + m_Query[key].emplace_back(std::move(value)); } return true; From 325e4a2fb9a616bde86d0cdfb8e4dcaff7e2dbda Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Thu, 30 Nov 2017 08:36:35 +0100 Subject: [PATCH 15/15] Use nullptr instead of ::Ptr() --- lib/base/configobject.cpp | 2 +- lib/base/configtype.cpp | 2 +- lib/base/configwriter.hpp | 2 +- lib/base/objecttype.cpp | 2 +- lib/base/primitivetype.cpp | 2 +- lib/base/process.hpp | 2 +- lib/base/scriptutils.cpp | 2 +- lib/base/serializer.cpp | 4 ++-- lib/base/type.cpp | 4 ++-- lib/base/value.cpp | 2 +- lib/base/value.hpp | 3 +++ lib/cli/clicommand.cpp | 2 +- lib/config/activationcontext.hpp | 2 +- lib/config/configitem.cpp | 12 ++++++------ lib/config/expression.hpp | 2 +- lib/config/vmops.hpp | 2 +- lib/db_ido/commanddbobject.cpp | 2 +- lib/db_ido/dbobject.cpp | 2 +- lib/db_ido/dbtype.cpp | 4 ++-- lib/db_ido/hostgroupdbobject.cpp | 2 +- lib/db_ido/servicegroupdbobject.cpp | 2 +- lib/db_ido/usergroupdbobject.cpp | 2 +- lib/db_ido_mysql/idomysqlconnection.cpp | 4 ++-- lib/db_ido_pgsql/idopgsqlconnection.cpp | 2 +- lib/demo/demo.cpp | 2 +- lib/icinga/apiactions.cpp | 2 +- lib/icinga/apiactions.hpp | 2 +- lib/icinga/checkable-check.cpp | 6 +++--- lib/icinga/checkable-dependency.cpp | 4 ++-- lib/icinga/checkable.cpp | 6 +++--- lib/icinga/checkable.hpp | 12 ++++++------ lib/icinga/checkcommand.hpp | 2 +- lib/icinga/clusterevents.cpp | 6 +++--- lib/icinga/comment.cpp | 2 +- lib/icinga/comment.hpp | 4 ++-- lib/icinga/comment.ti | 2 +- lib/icinga/compatutility.cpp | 2 +- lib/icinga/dependency.ti | 4 ++-- lib/icinga/downtime.cpp | 2 +- lib/icinga/downtime.hpp | 4 ++-- lib/icinga/downtime.ti | 2 +- lib/icinga/eventcommand.hpp | 2 +- lib/icinga/externalcommandprocessor.cpp | 4 ++-- lib/icinga/host.cpp | 2 +- lib/icinga/legacytimeperiod.cpp | 2 +- lib/icinga/macroprocessor.cpp | 4 ++-- lib/icinga/macroprocessor.hpp | 4 ++-- lib/icinga/notification.cpp | 4 ++-- lib/icinga/notification.ti | 2 +- lib/icinga/notificationcommand.hpp | 2 +- lib/icinga/objectutils.cpp | 4 ++-- lib/icinga/scheduleddowntime.ti | 2 +- lib/icinga/service.cpp | 4 ++-- lib/livestatus/hoststable.cpp | 4 ++-- lib/livestatus/livestatusquery.cpp | 2 +- lib/livestatus/logtable.cpp | 10 +++++----- lib/livestatus/servicestable.cpp | 6 +++--- lib/livestatus/statehisttable.cpp | 4 ++-- lib/livestatus/table.cpp | 2 +- lib/remote/actionshandler.cpp | 2 +- lib/remote/apiclient.cpp | 4 ++-- lib/remote/apilistener-configsync.cpp | 2 +- lib/remote/apilistener.cpp | 6 +++--- lib/remote/apilistener.hpp | 4 ++-- lib/remote/apiuser.cpp | 2 +- lib/remote/configpackageutility.hpp | 2 +- lib/remote/endpoint.cpp | 2 +- lib/remote/eventqueue.cpp | 3 +-- lib/remote/filterutility.cpp | 4 ++-- lib/remote/httpserverconnection.cpp | 2 +- lib/remote/jsonrpcconnection-pki.cpp | 2 +- lib/remote/zone.cpp | 2 +- 72 files changed, 117 insertions(+), 115 deletions(-) diff --git a/lib/base/configobject.cpp b/lib/base/configobject.cpp index 55b780e13..ea8d106a1 100644 --- a/lib/base/configobject.cpp +++ b/lib/base/configobject.cpp @@ -706,7 +706,7 @@ ConfigObject::Ptr ConfigObject::GetObject(const String& type, const String& name ConfigType *ctype = dynamic_cast(ptype.get()); if (!ctype) - return ConfigObject::Ptr(); + return nullptr; return ctype->GetObject(name); } diff --git a/lib/base/configtype.cpp b/lib/base/configtype.cpp index b3b8e0a39..a21eb142c 100644 --- a/lib/base/configtype.cpp +++ b/lib/base/configtype.cpp @@ -33,7 +33,7 @@ ConfigObject::Ptr ConfigType::GetObject(const String& name) const auto nt = m_ObjectMap.find(name); if (nt == m_ObjectMap.end()) - return ConfigObject::Ptr(); + return nullptr; return nt->second; } diff --git a/lib/base/configwriter.hpp b/lib/base/configwriter.hpp index c39a046ca..9573050d0 100644 --- a/lib/base/configwriter.hpp +++ b/lib/base/configwriter.hpp @@ -61,7 +61,7 @@ public: static void EmitArray(std::ostream& fp, int indentLevel, const Array::Ptr& val); static void EmitArrayItems(std::ostream& fp, int indentLevel, const Array::Ptr& val); static void EmitScope(std::ostream& fp, int indentLevel, const Dictionary::Ptr& val, - const Array::Ptr& imports = Array::Ptr(), bool splitDot = false); + const Array::Ptr& imports = nullptr, bool splitDot = false); static void EmitValue(std::ostream& fp, int indentLevel, const Value& val); static void EmitRaw(std::ostream& fp, const String& val); static void EmitIndent(std::ostream& fp, int indentLevel); diff --git a/lib/base/objecttype.cpp b/lib/base/objecttype.cpp index a172cf23d..e5cdba372 100644 --- a/lib/base/objecttype.cpp +++ b/lib/base/objecttype.cpp @@ -39,7 +39,7 @@ String ObjectType::GetName(void) const Type::Ptr ObjectType::GetBaseType(void) const { - return Type::Ptr(); + return nullptr; } int ObjectType::GetAttributes(void) const diff --git a/lib/base/primitivetype.cpp b/lib/base/primitivetype.cpp index 6a31d1a69..6c4f37bfc 100644 --- a/lib/base/primitivetype.cpp +++ b/lib/base/primitivetype.cpp @@ -34,7 +34,7 @@ String PrimitiveType::GetName(void) const Type::Ptr PrimitiveType::GetBaseType(void) const { if (m_Base == "None") - return Type::Ptr(); + return nullptr; else return Type::GetByName(m_Base); } diff --git a/lib/base/process.hpp b/lib/base/process.hpp index 9414c68da..8e39e7998 100644 --- a/lib/base/process.hpp +++ b/lib/base/process.hpp @@ -66,7 +66,7 @@ public: static const std::deque::size_type MaxTasksPerThread = 512; - Process(const Arguments& arguments, const Dictionary::Ptr& extraEnvironment = Dictionary::Ptr()); + Process(const Arguments& arguments, const Dictionary::Ptr& extraEnvironment = nullptr); ~Process(void); void SetTimeout(double timeout); diff --git a/lib/base/scriptutils.cpp b/lib/base/scriptutils.cpp index e3a1b64a7..785b4b942 100644 --- a/lib/base/scriptutils.cpp +++ b/lib/base/scriptutils.cpp @@ -405,7 +405,7 @@ ConfigObject::Ptr ScriptUtils::GetObject(const Value& vtype, const String& name) ConfigType *ctype = dynamic_cast(ptype.get()); if (!ctype) - return ConfigObject::Ptr(); + return nullptr; return ctype->GetObject(name); } diff --git a/lib/base/serializer.cpp b/lib/base/serializer.cpp index 5485c12b4..f51493aea 100644 --- a/lib/base/serializer.cpp +++ b/lib/base/serializer.cpp @@ -55,7 +55,7 @@ static Object::Ptr SerializeObject(const Object::Ptr& input, int attributeTypes) Type::Ptr type = input->GetReflectionType(); if (!type) - return Object::Ptr(); + return nullptr; Dictionary::Ptr fields = new Dictionary(); @@ -168,7 +168,7 @@ Value icinga::Serialize(const Value& value, int attributeTypes) Value icinga::Deserialize(const Value& value, bool safe_mode, int attributeTypes) { - return Deserialize(Object::Ptr(), value, safe_mode, attributeTypes); + return Deserialize(nullptr, value, safe_mode, attributeTypes); } Value icinga::Deserialize(const Object::Ptr& object, const Value& value, bool safe_mode, int attributeTypes) diff --git a/lib/base/type.cpp b/lib/base/type.cpp index cb2b2e2fa..f58d6e193 100644 --- a/lib/base/type.cpp +++ b/lib/base/type.cpp @@ -49,12 +49,12 @@ Type::Ptr Type::GetByName(const String& name) Dictionary::Ptr typesNS = ScriptGlobal::Get("Types", &Empty); if (!typesNS) - return Type::Ptr(); + return nullptr; Value ptype = typesNS->Get(name); if (!ptype.IsObjectType()) - return Type::Ptr(); + return nullptr; return ptype; } diff --git a/lib/base/value.cpp b/lib/base/value.cpp index 6b1db8e8b..e219fd60e 100644 --- a/lib/base/value.cpp +++ b/lib/base/value.cpp @@ -100,7 +100,7 @@ Type::Ptr Value::GetReflectionType(void) const case ValueObject: return boost::get(m_Value)->GetReflectionType(); default: - return Type::Ptr(); + return nullptr; } } diff --git a/lib/base/value.hpp b/lib/base/value.hpp index 85f4aedde..bb32a9b0a 100644 --- a/lib/base/value.hpp +++ b/lib/base/value.hpp @@ -55,6 +55,9 @@ public: inline Value(void) { } + inline Value(std::nullptr_t) + { } + inline Value(int value) : m_Value(double(value)) { } diff --git a/lib/cli/clicommand.cpp b/lib/cli/clicommand.cpp index ec8a04e3a..6e4b8b2f2 100644 --- a/lib/cli/clicommand.cpp +++ b/lib/cli/clicommand.cpp @@ -130,7 +130,7 @@ CLICommand::Ptr CLICommand::GetByName(const std::vector& name) auto it = GetRegistry().find(name); if (it == GetRegistry().end()) - return CLICommand::Ptr(); + return nullptr; return it->second; } diff --git a/lib/config/activationcontext.hpp b/lib/config/activationcontext.hpp index 22ba22009..324be2b2b 100644 --- a/lib/config/activationcontext.hpp +++ b/lib/config/activationcontext.hpp @@ -49,7 +49,7 @@ private: class I2_CONFIG_API ActivationScope { public: - ActivationScope(const ActivationContext::Ptr& context = ActivationContext::Ptr()); + ActivationScope(const ActivationContext::Ptr& context = nullptr); ~ActivationScope(void); ActivationContext::Ptr GetContext(void) const; diff --git a/lib/config/configitem.cpp b/lib/config/configitem.cpp index edb0527ba..9227db3e6 100644 --- a/lib/config/configitem.cpp +++ b/lib/config/configitem.cpp @@ -185,7 +185,7 @@ ConfigObject::Ptr ConfigItem::Commit(bool discard) BOOST_THROW_EXCEPTION(ScriptError("Type '" + GetType() + "' does not exist.", m_DebugInfo)); if (IsAbstract()) - return ConfigObject::Ptr(); + return nullptr; ConfigObject::Ptr dobj = static_pointer_cast(type->Instantiate(std::vector())); @@ -211,7 +211,7 @@ ConfigObject::Ptr ConfigItem::Commit(bool discard) m_IgnoredItems.push_back(m_DebugInfo.Path); } - return ConfigObject::Ptr(); + return nullptr; } throw; @@ -263,7 +263,7 @@ ConfigObject::Ptr ConfigItem::Commit(bool discard) m_IgnoredItems.push_back(m_DebugInfo.Path); } - return ConfigObject::Ptr(); + return nullptr; } ex.SetDebugHint(dhint); @@ -282,7 +282,7 @@ ConfigObject::Ptr ConfigItem::Commit(bool discard) m_IgnoredItems.push_back(m_DebugInfo.Path); } - return ConfigObject::Ptr(); + return nullptr; } throw; @@ -378,12 +378,12 @@ ConfigItem::Ptr ConfigItem::GetByTypeAndName(const Type::Ptr& type, const String auto it = m_Items.find(type); if (it == m_Items.end()) - return ConfigItem::Ptr(); + return nullptr; auto it2 = it->second.find(name); if (it2 == it->second.end()) - return ConfigItem::Ptr(); + return nullptr; return it2->second; } diff --git a/lib/config/expression.hpp b/lib/config/expression.hpp index dec6f1c75..9c1509650 100644 --- a/lib/config/expression.hpp +++ b/lib/config/expression.hpp @@ -36,7 +36,7 @@ namespace icinga struct DebugHint { public: - DebugHint(const Dictionary::Ptr& hints = Dictionary::Ptr()) + DebugHint(const Dictionary::Ptr& hints = nullptr) : m_Hints(hints) { } diff --git a/lib/config/vmops.hpp b/lib/config/vmops.hpp index 4376f32d7..0c56fee71 100644 --- a/lib/config/vmops.hpp +++ b/lib/config/vmops.hpp @@ -152,7 +152,7 @@ public: NameComposer *nc = dynamic_cast(type.get()); if (nc) - checkName = nc->MakeName(name, Dictionary::Ptr()); + checkName = nc->MakeName(name, nullptr); } if (!checkName.IsEmpty()) { diff --git a/lib/db_ido/commanddbobject.cpp b/lib/db_ido/commanddbobject.cpp index 1b059d2aa..12e6d5869 100644 --- a/lib/db_ido/commanddbobject.cpp +++ b/lib/db_ido/commanddbobject.cpp @@ -45,5 +45,5 @@ Dictionary::Ptr CommandDbObject::GetConfigFields(void) const Dictionary::Ptr CommandDbObject::GetStatusFields(void) const { - return Dictionary::Ptr(); + return nullptr; } diff --git a/lib/db_ido/dbobject.cpp b/lib/db_ido/dbobject.cpp index a606a2e67..ab39a5eff 100644 --- a/lib/db_ido/dbobject.cpp +++ b/lib/db_ido/dbobject.cpp @@ -354,7 +354,7 @@ DbObject::Ptr DbObject::GetOrCreateByObject(const ConfigObject::Ptr& object) DbType::Ptr dbtype = DbType::GetByName(object->GetReflectionType()->GetName()); if (!dbtype) - return DbObject::Ptr(); + return nullptr; Service::Ptr service; String name1, name2; diff --git a/lib/db_ido/dbtype.cpp b/lib/db_ido/dbtype.cpp index 6baf2d2bc..9877c5746 100644 --- a/lib/db_ido/dbtype.cpp +++ b/lib/db_ido/dbtype.cpp @@ -68,7 +68,7 @@ DbType::Ptr DbType::GetByName(const String& name) auto it = GetTypes().find(typeName); if (it == GetTypes().end()) - return DbType::Ptr(); + return nullptr; return it->second; } @@ -82,7 +82,7 @@ DbType::Ptr DbType::GetByID(long tid) return kv.second; } - return DbType::Ptr(); + return nullptr; } DbObject::Ptr DbType::GetOrCreateObjectByName(const String& name1, const String& name2) diff --git a/lib/db_ido/hostgroupdbobject.cpp b/lib/db_ido/hostgroupdbobject.cpp index f9d919744..b16000068 100644 --- a/lib/db_ido/hostgroupdbobject.cpp +++ b/lib/db_ido/hostgroupdbobject.cpp @@ -47,5 +47,5 @@ Dictionary::Ptr HostGroupDbObject::GetConfigFields(void) const Dictionary::Ptr HostGroupDbObject::GetStatusFields(void) const { - return Dictionary::Ptr(); + return nullptr; } diff --git a/lib/db_ido/servicegroupdbobject.cpp b/lib/db_ido/servicegroupdbobject.cpp index 06068ce32..1cb529acb 100644 --- a/lib/db_ido/servicegroupdbobject.cpp +++ b/lib/db_ido/servicegroupdbobject.cpp @@ -46,5 +46,5 @@ Dictionary::Ptr ServiceGroupDbObject::GetConfigFields(void) const Dictionary::Ptr ServiceGroupDbObject::GetStatusFields(void) const { - return Dictionary::Ptr(); + return nullptr; } diff --git a/lib/db_ido/usergroupdbobject.cpp b/lib/db_ido/usergroupdbobject.cpp index 5954f16fe..60390325f 100644 --- a/lib/db_ido/usergroupdbobject.cpp +++ b/lib/db_ido/usergroupdbobject.cpp @@ -44,5 +44,5 @@ Dictionary::Ptr UserGroupDbObject::GetConfigFields(void) const Dictionary::Ptr UserGroupDbObject::GetStatusFields(void) const { - return Dictionary::Ptr(); + return nullptr; } diff --git a/lib/db_ido_mysql/idomysqlconnection.cpp b/lib/db_ido_mysql/idomysqlconnection.cpp index 1ed3a8c97..59be843ea 100644 --- a/lib/db_ido_mysql/idomysqlconnection.cpp +++ b/lib/db_ido_mysql/idomysqlconnection.cpp @@ -684,12 +684,12 @@ Dictionary::Ptr IdoMysqlConnection::FetchRow(const IdoMysqlResult& result) row = mysql_fetch_row(result.get()); if (!row) - return Dictionary::Ptr(); + return nullptr; lengths = mysql_fetch_lengths(result.get()); if (!lengths) - return Dictionary::Ptr(); + return nullptr; Dictionary::Ptr dict = new Dictionary(); diff --git a/lib/db_ido_pgsql/idopgsqlconnection.cpp b/lib/db_ido_pgsql/idopgsqlconnection.cpp index 035a9c9d0..2db019072 100644 --- a/lib/db_ido_pgsql/idopgsqlconnection.cpp +++ b/lib/db_ido_pgsql/idopgsqlconnection.cpp @@ -522,7 +522,7 @@ Dictionary::Ptr IdoPgsqlConnection::FetchRow(const IdoPgsqlResult& result, int r AssertOnWorkQueue(); if (row >= PQntuples(result.get())) - return Dictionary::Ptr(); + return nullptr; int columns = PQnfields(result.get()); diff --git a/lib/demo/demo.cpp b/lib/demo/demo.cpp index f54aa270b..d213515c0 100644 --- a/lib/demo/demo.cpp +++ b/lib/demo/demo.cpp @@ -54,7 +54,7 @@ void Demo::DemoTimerHandler(void) ApiListener::Ptr listener = ApiListener::GetInstance(); if (listener) { MessageOrigin::Ptr origin = new MessageOrigin(); - listener->RelayMessage(origin, ConfigObject::Ptr(), message, true); + listener->RelayMessage(origin, nullptr, message, true); Log(LogInformation, "Demo", "Sent demo::HelloWorld message"); } } diff --git a/lib/icinga/apiactions.cpp b/lib/icinga/apiactions.cpp index a44ebb29c..e4070324a 100644 --- a/lib/icinga/apiactions.cpp +++ b/lib/icinga/apiactions.cpp @@ -165,7 +165,7 @@ Dictionary::Ptr ApiActions::SendCustomNotification(const ConfigObject::Ptr& obje checkable->SetForceNextNotification(true); Checkable::OnNotificationsRequested(checkable, NotificationCustom, checkable->GetLastCheckResult(), - HttpUtility::GetLastParameter(params, "author"), HttpUtility::GetLastParameter(params, "comment"), MessageOrigin::Ptr()); + HttpUtility::GetLastParameter(params, "author"), HttpUtility::GetLastParameter(params, "comment"), nullptr); return ApiActions::CreateResult(200, "Successfully sent custom notification for object '" + checkable->GetName() + "'."); } diff --git a/lib/icinga/apiactions.hpp b/lib/icinga/apiactions.hpp index 8bfcd8a4e..9b037183f 100644 --- a/lib/icinga/apiactions.hpp +++ b/lib/icinga/apiactions.hpp @@ -48,7 +48,7 @@ public: static Dictionary::Ptr GenerateTicket(const ConfigObject::Ptr& object, const Dictionary::Ptr& params); private: - static Dictionary::Ptr CreateResult(int code, const String& status, const Dictionary::Ptr& additional = Dictionary::Ptr()); + static Dictionary::Ptr CreateResult(int code, const String& status, const Dictionary::Ptr& additional = nullptr); }; } diff --git a/lib/icinga/checkable-check.cpp b/lib/icinga/checkable-check.cpp index 893903ba4..61a4905a2 100644 --- a/lib/icinga/checkable-check.cpp +++ b/lib/icinga/checkable-check.cpp @@ -371,7 +371,7 @@ void Checkable::ProcessCheckResult(const CheckResult::Ptr& cr, const MessageOrig if (!in_downtime && !was_flapping && is_flapping) { /* FlappingStart notifications happen on state changes, not in downtimes */ if (!IsPaused()) - OnNotificationsRequested(this, NotificationFlappingStart, cr, "", "", MessageOrigin::Ptr()); + OnNotificationsRequested(this, NotificationFlappingStart, cr, "", "", nullptr); Log(LogNotice, "Checkable") << "Flapping Start: Checkable '" << GetName() << "' started flapping (Current flapping value " @@ -381,7 +381,7 @@ void Checkable::ProcessCheckResult(const CheckResult::Ptr& cr, const MessageOrig } else if (!in_downtime && was_flapping && !is_flapping) { /* FlappingEnd notifications are independent from state changes, must not happen in downtine */ if (!IsPaused()) - OnNotificationsRequested(this, NotificationFlappingEnd, cr, "", "", MessageOrigin::Ptr()); + OnNotificationsRequested(this, NotificationFlappingEnd, cr, "", "", nullptr); Log(LogNotice, "Checkable") << "Flapping Stop: Checkable '" << GetName() << "' stopped flapping (Current flapping value " @@ -392,7 +392,7 @@ void Checkable::ProcessCheckResult(const CheckResult::Ptr& cr, const MessageOrig if (send_notification && !is_flapping) { if (!IsPaused()) - OnNotificationsRequested(this, recovery ? NotificationRecovery : NotificationProblem, cr, "", "", MessageOrigin::Ptr()); + OnNotificationsRequested(this, recovery ? NotificationRecovery : NotificationProblem, cr, "", "", nullptr); } } diff --git a/lib/icinga/checkable-dependency.cpp b/lib/icinga/checkable-dependency.cpp index 90714fc9d..c567f474b 100644 --- a/lib/icinga/checkable-dependency.cpp +++ b/lib/icinga/checkable-dependency.cpp @@ -80,7 +80,7 @@ bool Checkable::IsReachable(DependencyType dt, Dependency::Ptr *failedDependency if (host && host->GetState() != HostUp && host->GetStateType() == StateTypeHard) { if (failedDependency) - *failedDependency = Dependency::Ptr(); + *failedDependency = nullptr; return false; } @@ -96,7 +96,7 @@ bool Checkable::IsReachable(DependencyType dt, Dependency::Ptr *failedDependency } if (failedDependency) - *failedDependency = Dependency::Ptr(); + *failedDependency = nullptr; return true; } diff --git a/lib/icinga/checkable.cpp b/lib/icinga/checkable.cpp index 1fbfa47ab..86cea0fc0 100644 --- a/lib/icinga/checkable.cpp +++ b/lib/icinga/checkable.cpp @@ -128,7 +128,7 @@ void Checkable::AcknowledgeProblem(const String& author, const String& comment, SetAcknowledgementExpiry(expiry); if (notify && !IsPaused()) - OnNotificationsRequested(this, NotificationAcknowledgement, GetLastCheckResult(), author, comment, MessageOrigin::Ptr()); + OnNotificationsRequested(this, NotificationAcknowledgement, GetLastCheckResult(), author, comment, nullptr); OnAcknowledgementSet(this, author, comment, type, notify, persistent, expiry, origin); } @@ -173,7 +173,7 @@ void Checkable::NotifyDowntimeInternal(const Downtime::Ptr& downtime) Checkable::Ptr checkable = downtime->GetCheckable(); if (!checkable->IsPaused()) - OnNotificationsRequested(checkable, NotificationDowntimeStart, checkable->GetLastCheckResult(), downtime->GetAuthor(), downtime->GetComment(), MessageOrigin::Ptr()); + OnNotificationsRequested(checkable, NotificationDowntimeStart, checkable->GetLastCheckResult(), downtime->GetAuthor(), downtime->GetComment(), nullptr); } void Checkable::NotifyDowntimeEnd(const Downtime::Ptr& downtime) @@ -185,7 +185,7 @@ void Checkable::NotifyDowntimeEnd(const Downtime::Ptr& downtime) Checkable::Ptr checkable = downtime->GetCheckable(); if (!checkable->IsPaused()) - OnNotificationsRequested(checkable, NotificationDowntimeEnd, checkable->GetLastCheckResult(), downtime->GetAuthor(), downtime->GetComment(), MessageOrigin::Ptr()); + OnNotificationsRequested(checkable, NotificationDowntimeEnd, checkable->GetLastCheckResult(), downtime->GetAuthor(), downtime->GetComment(), nullptr); } void Checkable::ValidateCheckInterval(double value, const ValidationUtils& utils) diff --git a/lib/icinga/checkable.hpp b/lib/icinga/checkable.hpp index b2d118c31..ca7b479ba 100644 --- a/lib/icinga/checkable.hpp +++ b/lib/icinga/checkable.hpp @@ -98,8 +98,8 @@ public: AcknowledgementType GetAcknowledgement(void); - void AcknowledgeProblem(const String& author, const String& comment, AcknowledgementType type, bool notify = true, bool persistent = false, double expiry = 0, const MessageOrigin::Ptr& origin = MessageOrigin::Ptr()); - void ClearAcknowledgement(const MessageOrigin::Ptr& origin = MessageOrigin::Ptr()); + void AcknowledgeProblem(const String& author, const String& comment, AcknowledgementType type, bool notify = true, bool persistent = false, double expiry = 0, const MessageOrigin::Ptr& origin = nullptr); + void ClearAcknowledgement(const MessageOrigin::Ptr& origin = nullptr); virtual int GetSeverity(void) const override; @@ -110,7 +110,7 @@ public: long GetSchedulingOffset(void); void SetSchedulingOffset(long offset); - void UpdateNextCheck(const MessageOrigin::Ptr& origin = MessageOrigin::Ptr()); + void UpdateNextCheck(const MessageOrigin::Ptr& origin = nullptr); bool HasBeenChecked(void) const; virtual bool IsStateOK(ServiceState state) = 0; @@ -121,9 +121,9 @@ public: static void UpdateStatistics(const CheckResult::Ptr& cr, CheckableType type); - void ExecuteRemoteCheck(const Dictionary::Ptr& resolvedMacros = Dictionary::Ptr()); + void ExecuteRemoteCheck(const Dictionary::Ptr& resolvedMacros = nullptr); void ExecuteCheck(); - void ProcessCheckResult(const CheckResult::Ptr& cr, const MessageOrigin::Ptr& origin = MessageOrigin::Ptr()); + void ProcessCheckResult(const CheckResult::Ptr& cr, const MessageOrigin::Ptr& origin = nullptr); Endpoint::Ptr GetCommandEndpoint(void) const; @@ -174,7 +174,7 @@ public: void ResetNotificationNumbers(void); /* Event Handler */ - void ExecuteEventHandler(const Dictionary::Ptr& resolvedMacros = Dictionary::Ptr(), + void ExecuteEventHandler(const Dictionary::Ptr& resolvedMacros = nullptr, bool useResolvedMacros = false); intrusive_ptr GetEventCommand(void) const; diff --git a/lib/icinga/checkcommand.hpp b/lib/icinga/checkcommand.hpp index 9be3521ec..91d8445ef 100644 --- a/lib/icinga/checkcommand.hpp +++ b/lib/icinga/checkcommand.hpp @@ -38,7 +38,7 @@ public: DECLARE_OBJECTNAME(CheckCommand); virtual void Execute(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr, - const Dictionary::Ptr& resolvedMacros = Dictionary::Ptr(), + const Dictionary::Ptr& resolvedMacros = nullptr, bool useResolvedMacros = false); }; diff --git a/lib/icinga/clusterevents.cpp b/lib/icinga/clusterevents.cpp index 57b4691e1..3262d881b 100644 --- a/lib/icinga/clusterevents.cpp +++ b/lib/icinga/clusterevents.cpp @@ -704,7 +704,7 @@ void ClusterEvents::SendNotificationsHandler(const Checkable::Ptr& checkable, No params->Set("author", author); params->Set("text", text); - listener->RelayMessage(origin, ConfigObject::Ptr(), message, true); + listener->RelayMessage(origin, nullptr, message, true); } Value ClusterEvents::SendNotificationsAPIHandler(const MessageOrigin::Ptr& origin, const Dictionary::Ptr& params) @@ -798,7 +798,7 @@ void ClusterEvents::NotificationSentUserHandler(const Notification::Ptr& notific message->Set("method", "event::NotificationSentUser"); message->Set("params", params); - listener->RelayMessage(origin, ConfigObject::Ptr(), message, true); + listener->RelayMessage(origin, nullptr, message, true); } Value ClusterEvents::NotificationSentUserAPIHandler(const MessageOrigin::Ptr& origin, const Dictionary::Ptr& params) @@ -914,7 +914,7 @@ void ClusterEvents::NotificationSentToAllUsersHandler(const Notification::Ptr& n message->Set("method", "event::NotificationSentToAllUsers"); message->Set("params", params); - listener->RelayMessage(origin, ConfigObject::Ptr(), message, true); + listener->RelayMessage(origin, nullptr, message, true); } Value ClusterEvents::NotificationSentToAllUsersAPIHandler(const MessageOrigin::Ptr& origin, const Dictionary::Ptr& params) diff --git a/lib/icinga/comment.cpp b/lib/icinga/comment.cpp index 84f862e21..3bc736f15 100644 --- a/lib/icinga/comment.cpp +++ b/lib/icinga/comment.cpp @@ -181,7 +181,7 @@ String Comment::AddComment(const Checkable::Ptr& checkable, CommentType entryTyp if (!zone.IsEmpty()) attrs->Set("zone", zone); - String config = ConfigObjectUtility::CreateObjectConfig(Comment::TypeInstance, fullName, true, Array::Ptr(), attrs); + String config = ConfigObjectUtility::CreateObjectConfig(Comment::TypeInstance, fullName, true, nullptr, attrs); Array::Ptr errors = new Array(); diff --git a/lib/icinga/comment.hpp b/lib/icinga/comment.hpp index d2ccfa848..26f824cec 100644 --- a/lib/icinga/comment.hpp +++ b/lib/icinga/comment.hpp @@ -50,9 +50,9 @@ public: static String AddComment(const intrusive_ptr& checkable, CommentType entryType, const String& author, const String& text, bool persistent, double expireTime, - const String& id = String(), const MessageOrigin::Ptr& origin = MessageOrigin::Ptr()); + const String& id = String(), const MessageOrigin::Ptr& origin = nullptr); - static void RemoveComment(const String& id, const MessageOrigin::Ptr& origin = MessageOrigin::Ptr()); + static void RemoveComment(const String& id, const MessageOrigin::Ptr& origin = nullptr); static String GetCommentIDFromLegacyID(int id); diff --git a/lib/icinga/comment.ti b/lib/icinga/comment.ti index aaf3e3986..093195beb 100644 --- a/lib/icinga/comment.ti +++ b/lib/icinga/comment.ti @@ -72,7 +72,7 @@ class Comment : ConfigObject < CommentNameComposer }}} navigate {{{ if (GetServiceName().IsEmpty()) - return Service::Ptr(); + return nullptr; Host::Ptr host = Host::GetByName(GetHostName()); return host->GetServiceByShortName(GetServiceName()); diff --git a/lib/icinga/compatutility.cpp b/lib/icinga/compatutility.cpp index b66f4b7b6..80a6a85ba 100644 --- a/lib/icinga/compatutility.cpp +++ b/lib/icinga/compatutility.cpp @@ -368,7 +368,7 @@ Dictionary::Ptr CompatUtility::GetCustomAttributeConfig(const CustomVarObject::P Dictionary::Ptr vars = object->GetVars(); if (!vars) - return Dictionary::Ptr(); + return nullptr; return vars; } diff --git a/lib/icinga/dependency.ti b/lib/icinga/dependency.ti index 79a17bfac..bb347a2c2 100644 --- a/lib/icinga/dependency.ti +++ b/lib/icinga/dependency.ti @@ -60,7 +60,7 @@ class Dependency : CustomVarObject < DependencyNameComposer }}} navigate {{{ if (GetChildServiceName().IsEmpty()) - return Service::Ptr(); + return nullptr; Host::Ptr host = Host::GetByName(GetChildHostName()); return host->GetServiceByShortName(GetChildServiceName()); @@ -87,7 +87,7 @@ class Dependency : CustomVarObject < DependencyNameComposer }}} navigate {{{ if (GetParentServiceName().IsEmpty()) - return Service::Ptr(); + return nullptr; Host::Ptr host = Host::GetByName(GetParentHostName()); return host->GetServiceByShortName(GetParentServiceName()); diff --git a/lib/icinga/downtime.cpp b/lib/icinga/downtime.cpp index bf8b6d214..6a873d3f8 100644 --- a/lib/icinga/downtime.cpp +++ b/lib/icinga/downtime.cpp @@ -255,7 +255,7 @@ String Downtime::AddDowntime(const Checkable::Ptr& checkable, const String& auth if (!zone.IsEmpty()) attrs->Set("zone", zone); - String config = ConfigObjectUtility::CreateObjectConfig(Downtime::TypeInstance, fullName, true, Array::Ptr(), attrs); + String config = ConfigObjectUtility::CreateObjectConfig(Downtime::TypeInstance, fullName, true, nullptr, attrs); Array::Ptr errors = new Array(); diff --git a/lib/icinga/downtime.hpp b/lib/icinga/downtime.hpp index c5e0ef66e..46de4a4d1 100644 --- a/lib/icinga/downtime.hpp +++ b/lib/icinga/downtime.hpp @@ -57,9 +57,9 @@ public: const String& comment, double startTime, double endTime, bool fixed, const String& triggeredBy, double duration, const String& scheduledDowntime = String(), const String& scheduledBy = String(), const String& id = String(), - const MessageOrigin::Ptr& origin = MessageOrigin::Ptr()); + const MessageOrigin::Ptr& origin = nullptr); - static void RemoveDowntime(const String& id, bool cancelled, bool expired = false, const MessageOrigin::Ptr& origin = MessageOrigin::Ptr()); + static void RemoveDowntime(const String& id, bool cancelled, bool expired = false, const MessageOrigin::Ptr& origin = nullptr); void TriggerDowntime(void); diff --git a/lib/icinga/downtime.ti b/lib/icinga/downtime.ti index a392ebb22..1ce92cef7 100644 --- a/lib/icinga/downtime.ti +++ b/lib/icinga/downtime.ti @@ -59,7 +59,7 @@ class Downtime : ConfigObject < DowntimeNameComposer }}} navigate {{{ if (GetServiceName().IsEmpty()) - return Service::Ptr(); + return nullptr; Host::Ptr host = Host::GetByName(GetHostName()); return host->GetServiceByShortName(GetServiceName()); diff --git a/lib/icinga/eventcommand.hpp b/lib/icinga/eventcommand.hpp index a0d327ecd..b762fae46 100644 --- a/lib/icinga/eventcommand.hpp +++ b/lib/icinga/eventcommand.hpp @@ -38,7 +38,7 @@ public: DECLARE_OBJECTNAME(EventCommand); virtual void Execute(const Checkable::Ptr& checkable, - const Dictionary::Ptr& resolvedMacros = Dictionary::Ptr(), + const Dictionary::Ptr& resolvedMacros = nullptr, bool useResolvedMacros = false); }; diff --git a/lib/icinga/externalcommandprocessor.cpp b/lib/icinga/externalcommandprocessor.cpp index d1c9f73e0..84d648458 100644 --- a/lib/icinga/externalcommandprocessor.cpp +++ b/lib/icinga/externalcommandprocessor.cpp @@ -1358,7 +1358,7 @@ void ExternalCommandProcessor::SendCustomHostNotification(double, const std::vec } Checkable::OnNotificationsRequested(host, NotificationCustom, - host->GetLastCheckResult(), arguments[2], arguments[3], MessageOrigin::Ptr()); + host->GetLastCheckResult(), arguments[2], arguments[3], nullptr); } void ExternalCommandProcessor::SendCustomSvcNotification(double, const std::vector& arguments) @@ -1378,7 +1378,7 @@ void ExternalCommandProcessor::SendCustomSvcNotification(double, const std::vect } Service::OnNotificationsRequested(service, NotificationCustom, - service->GetLastCheckResult(), arguments[3], arguments[4], MessageOrigin::Ptr()); + service->GetLastCheckResult(), arguments[3], arguments[4], nullptr); } void ExternalCommandProcessor::DelayHostNotification(double, const std::vector& arguments) diff --git a/lib/icinga/host.cpp b/lib/icinga/host.cpp index c84eddae2..f90a6038c 100644 --- a/lib/icinga/host.cpp +++ b/lib/icinga/host.cpp @@ -144,7 +144,7 @@ Service::Ptr Host::GetServiceByShortName(const Value& name) return it->second; } - return Service::Ptr(); + return nullptr; } else if (name.IsObjectType()) { Dictionary::Ptr dict = name; String short_name; diff --git a/lib/icinga/legacytimeperiod.cpp b/lib/icinga/legacytimeperiod.cpp index 6d89839ea..4a831901a 100644 --- a/lib/icinga/legacytimeperiod.cpp +++ b/lib/icinga/legacytimeperiod.cpp @@ -451,7 +451,7 @@ Dictionary::Ptr LegacyTimePeriod::FindNextSegment(const String& daydef, const St } while (tsiter < tsend); } - return Dictionary::Ptr(); + return nullptr; } Array::Ptr LegacyTimePeriod::ScriptFunc(const TimePeriod::Ptr& tp, double begin, double end) diff --git a/lib/icinga/macroprocessor.cpp b/lib/icinga/macroprocessor.cpp index 465667ed4..fb9f918f3 100644 --- a/lib/icinga/macroprocessor.cpp +++ b/lib/icinga/macroprocessor.cpp @@ -291,7 +291,7 @@ Value MacroProcessor::InternalResolveMacros(const String& str, const ResolverLis for (const Value& value : arr) { if (value.IsScalar()) { resolved_arr->Add(InternalResolveMacros(value, - resolvers, cr, missingMacro, EscapeCallback(), Dictionary::Ptr(), + resolvers, cr, missingMacro, EscapeCallback(), nullptr, false, recursionLevel + 1)); } else resolved_arr->Add(value); @@ -300,7 +300,7 @@ Value MacroProcessor::InternalResolveMacros(const String& str, const ResolverLis resolved_macro = resolved_arr; } else if (resolved_macro.IsString()) { resolved_macro = InternalResolveMacros(resolved_macro, - resolvers, cr, missingMacro, EscapeCallback(), Dictionary::Ptr(), + resolvers, cr, missingMacro, EscapeCallback(), nullptr, false, recursionLevel + 1); } } diff --git a/lib/icinga/macroprocessor.hpp b/lib/icinga/macroprocessor.hpp index bd5e0dac8..0adc5acbc 100644 --- a/lib/icinga/macroprocessor.hpp +++ b/lib/icinga/macroprocessor.hpp @@ -41,9 +41,9 @@ public: typedef std::vector ResolverList; static Value ResolveMacros(const Value& str, const ResolverList& resolvers, - const CheckResult::Ptr& cr = CheckResult::Ptr(), String *missingMacro = NULL, + const CheckResult::Ptr& cr = nullptr, String *missingMacro = NULL, const EscapeCallback& escapeFn = EscapeCallback(), - const Dictionary::Ptr& resolvedMacros = Dictionary::Ptr(), + const Dictionary::Ptr& resolvedMacros = nullptr, bool useResolvedMacros = false, int recursionLevel = 0); static Value ResolveArguments(const Value& command, const Dictionary::Ptr& arguments, diff --git a/lib/icinga/notification.cpp b/lib/icinga/notification.cpp index 1738bd359..fccd2cb9f 100644 --- a/lib/icinga/notification.cpp +++ b/lib/icinga/notification.cpp @@ -431,7 +431,7 @@ void Notification::BeginExecuteNotification(NotificationType type, const CheckRe notifiedProblemUsers->Clear(); /* used in db_ido for notification history */ - Service::OnNotificationSentToAllUsers(this, checkable, allNotifiedUsers, type, cr, author, text, MessageOrigin::Ptr()); + Service::OnNotificationSentToAllUsers(this, checkable, allNotifiedUsers, type, cr, author, text, nullptr); } bool Notification::CheckNotificationUserFilters(NotificationType type, const User::Ptr& user, bool force, bool reminder) @@ -518,7 +518,7 @@ void Notification::ExecuteNotificationHelper(NotificationType type, const User:: command->Execute(this, user, cr, type, author, text); /* required by compatlogger */ - Service::OnNotificationSentToUser(this, GetCheckable(), user, type, cr, author, text, command->GetName(), MessageOrigin::Ptr()); + Service::OnNotificationSentToUser(this, GetCheckable(), user, type, cr, author, text, command->GetName(), nullptr); Log(LogInformation, "Notification") << "Completed sending '" << NotificationTypeToStringInternal(type) diff --git a/lib/icinga/notification.ti b/lib/icinga/notification.ti index 442146ec5..d4a454aae 100644 --- a/lib/icinga/notification.ti +++ b/lib/icinga/notification.ti @@ -79,7 +79,7 @@ class Notification : CustomVarObject < NotificationNameComposer }}} navigate {{{ if (GetServiceName().IsEmpty()) - return Service::Ptr(); + return nullptr; Host::Ptr host = Host::GetByName(GetHostName()); return host->GetServiceByShortName(GetServiceName()); diff --git a/lib/icinga/notificationcommand.hpp b/lib/icinga/notificationcommand.hpp index c059aea3a..21cf6c390 100644 --- a/lib/icinga/notificationcommand.hpp +++ b/lib/icinga/notificationcommand.hpp @@ -42,7 +42,7 @@ public: virtual Dictionary::Ptr Execute(const intrusive_ptr& notification, const User::Ptr& user, const CheckResult::Ptr& cr, const NotificationType& type, const String& author, const String& comment, - const Dictionary::Ptr& resolvedMacros = Dictionary::Ptr(), + const Dictionary::Ptr& resolvedMacros = nullptr, bool useResolvedMacros = false); }; diff --git a/lib/icinga/objectutils.cpp b/lib/icinga/objectutils.cpp index bde6cfd9a..94332e097 100644 --- a/lib/icinga/objectutils.cpp +++ b/lib/icinga/objectutils.cpp @@ -51,7 +51,7 @@ Service::Ptr ObjectUtils::GetService(const Value& host, const String& name) hostObj = Host::GetByName(host); if (!hostObj) - return Service::Ptr(); + return nullptr; return hostObj->GetServiceByShortName(name); } @@ -66,7 +66,7 @@ Array::Ptr ObjectUtils::GetServices(const Value& host) hostObj = Host::GetByName(host); if (!hostObj) - return Array::Ptr(); + return nullptr; return Array::FromVector(hostObj->GetServices()); } diff --git a/lib/icinga/scheduleddowntime.ti b/lib/icinga/scheduleddowntime.ti index f949edd6c..de71ed861 100644 --- a/lib/icinga/scheduleddowntime.ti +++ b/lib/icinga/scheduleddowntime.ti @@ -58,7 +58,7 @@ class ScheduledDowntime : CustomVarObject < ScheduledDowntimeNameComposer }}} navigate {{{ if (GetServiceName().IsEmpty()) - return Service::Ptr(); + return nullptr; Host::Ptr host = Host::GetByName(GetHostName()); return host->GetServiceByShortName(GetServiceName()); diff --git a/lib/icinga/service.cpp b/lib/icinga/service.cpp index 4426b35d7..4b8f245ea 100644 --- a/lib/icinga/service.cpp +++ b/lib/icinga/service.cpp @@ -111,7 +111,7 @@ Service::Ptr Service::GetByNamePair(const String& hostName, const String& servic Host::Ptr host = Host::GetByName(hostName); if (!host) - return Service::Ptr(); + return nullptr; return host->GetServiceByShortName(serviceName); } else { @@ -274,6 +274,6 @@ std::pair icinga::GetHostService(const Checkable::Ptr& if (service) return std::make_pair(service->GetHost(), service); else - return std::make_pair(static_pointer_cast(checkable), Service::Ptr()); + return std::make_pair(static_pointer_cast(checkable), nullptr); } diff --git a/lib/livestatus/hoststable.cpp b/lib/livestatus/hoststable.cpp index e98a1aa25..9b10b8152 100644 --- a/lib/livestatus/hoststable.cpp +++ b/lib/livestatus/hoststable.cpp @@ -211,7 +211,7 @@ Object::Ptr HostsTable::HostGroupAccessor(const Value& row, LivestatusGroupByTyp if (groupByType == LivestatusGroupByHostGroup) return groupByObject; - return Object::Ptr(); + return nullptr; } Value HostsTable::NameAccessor(const Value& row) @@ -328,7 +328,7 @@ Value HostsTable::NotesExpandedAccessor(const Value& row) { "icinga", IcingaApplication::GetInstance() } }; - return MacroProcessor::ResolveMacros(host->GetNotes(), resolvers, CheckResult::Ptr()); + return MacroProcessor::ResolveMacros(host->GetNotes(), resolvers); } Value HostsTable::NotesUrlAccessor(const Value& row) diff --git a/lib/livestatus/livestatusquery.cpp b/lib/livestatus/livestatusquery.cpp index 6dbb52c9a..71d7402db 100644 --- a/lib/livestatus/livestatusquery.cpp +++ b/lib/livestatus/livestatusquery.cpp @@ -320,7 +320,7 @@ Filter::Ptr LivestatusQuery::ParseFilter(const String& params, unsigned long& fr tokens.push_back(""); if (tokens.size() < 3) - return Filter::Ptr(); + return nullptr; bool negate = false; String attr = tokens[0]; diff --git a/lib/livestatus/logtable.cpp b/lib/livestatus/logtable.cpp index 73cf8deaa..938660957 100644 --- a/lib/livestatus/logtable.cpp +++ b/lib/livestatus/logtable.cpp @@ -117,7 +117,7 @@ Object::Ptr LogTable::HostAccessor(const Value& row, const Column::ObjectAccesso String host_name = static_cast(row)->Get("host_name"); if (host_name.IsEmpty()) - return Object::Ptr(); + return nullptr; return Host::GetByName(host_name); } @@ -128,7 +128,7 @@ Object::Ptr LogTable::ServiceAccessor(const Value& row, const Column::ObjectAcce String service_description = static_cast(row)->Get("service_description"); if (service_description.IsEmpty() || host_name.IsEmpty()) - return Object::Ptr(); + return nullptr; return Service::GetByNamePair(host_name, service_description); } @@ -138,7 +138,7 @@ Object::Ptr LogTable::ContactAccessor(const Value& row, const Column::ObjectAcce String contact_name = static_cast(row)->Get("contact_name"); if (contact_name.IsEmpty()) - return Object::Ptr(); + return nullptr; return User::GetByName(contact_name); } @@ -148,7 +148,7 @@ Object::Ptr LogTable::CommandAccessor(const Value& row, const Column::ObjectAcce String command_name = static_cast(row)->Get("command_name"); if (command_name.IsEmpty()) - return Object::Ptr(); + return nullptr; CheckCommand::Ptr check_command = CheckCommand::GetByName(command_name); if (!check_command) { @@ -156,7 +156,7 @@ Object::Ptr LogTable::CommandAccessor(const Value& row, const Column::ObjectAcce if (!event_command) { NotificationCommand::Ptr notification_command = NotificationCommand::GetByName(command_name); if (!notification_command) - return Object::Ptr(); + return nullptr; else return notification_command; } else diff --git a/lib/livestatus/servicestable.cpp b/lib/livestatus/servicestable.cpp index 76baa3bca..b58d4c6ce 100644 --- a/lib/livestatus/servicestable.cpp +++ b/lib/livestatus/servicestable.cpp @@ -206,7 +206,7 @@ Object::Ptr ServicesTable::HostAccessor(const Value& row, const Column::ObjectAc Service::Ptr svc = static_cast(service); if (!svc) - return Object::Ptr(); + return nullptr; return svc->GetHost(); } @@ -220,7 +220,7 @@ Object::Ptr ServicesTable::ServiceGroupAccessor(const Value& row, LivestatusGrou if (groupByType == LivestatusGroupByServiceGroup) return groupByObject; - return Object::Ptr(); + return nullptr; } Object::Ptr ServicesTable::HostGroupAccessor(const Value& row, LivestatusGroupByType groupByType, const Object::Ptr& groupByObject) @@ -232,7 +232,7 @@ Object::Ptr ServicesTable::HostGroupAccessor(const Value& row, LivestatusGroupBy if (groupByType == LivestatusGroupByHostGroup) return groupByObject; - return Object::Ptr(); + return nullptr; } Value ServicesTable::ShortNameAccessor(const Value& row) diff --git a/lib/livestatus/statehisttable.cpp b/lib/livestatus/statehisttable.cpp index b8728472a..996464690 100644 --- a/lib/livestatus/statehisttable.cpp +++ b/lib/livestatus/statehisttable.cpp @@ -281,7 +281,7 @@ Object::Ptr StateHistTable::HostAccessor(const Value& row, const Column::ObjectA String host_name = static_cast(row)->Get("host_name"); if (host_name.IsEmpty()) - return Object::Ptr(); + return nullptr; return Host::GetByName(host_name); } @@ -292,7 +292,7 @@ Object::Ptr StateHistTable::ServiceAccessor(const Value& row, const Column::Obje String service_description = static_cast(row)->Get("service_description"); if (service_description.IsEmpty() || host_name.IsEmpty()) - return Object::Ptr(); + return nullptr; return Service::GetByNamePair(host_name, service_description); } diff --git a/lib/livestatus/table.cpp b/lib/livestatus/table.cpp index 1e121ecb1..dcb532374 100644 --- a/lib/livestatus/table.cpp +++ b/lib/livestatus/table.cpp @@ -84,7 +84,7 @@ Table::Ptr Table::GetByName(const String& name, const String& compat_log_path, c else if (name == "zones") return new ZonesTable(); - return Table::Ptr(); + return nullptr; } void Table::AddColumn(const String& name, const Column& column) diff --git a/lib/remote/actionshandler.cpp b/lib/remote/actionshandler.cpp index f6dcba79e..4995a1f04 100644 --- a/lib/remote/actionshandler.cpp +++ b/lib/remote/actionshandler.cpp @@ -69,7 +69,7 @@ bool ActionsHandler::HandleRequest(const ApiUser::Ptr& user, HttpRequest& reques } } else { FilterUtility::CheckPermission(user, permission); - objs.push_back(ConfigObject::Ptr()); + objs.push_back(nullptr); } Array::Ptr results = new Array(); diff --git a/lib/remote/apiclient.cpp b/lib/remote/apiclient.cpp index 8e91669f5..124c5b9d1 100644 --- a/lib/remote/apiclient.cpp +++ b/lib/remote/apiclient.cpp @@ -322,7 +322,7 @@ void ApiClient::AutocompleteScript(const String& session, const String& command, req->AddHeader("Accept", "application/json"); m_Connection->SubmitRequest(req, std::bind(AutocompleteScriptHttpCompletionCallback, _1, _2, callback)); } catch (const std::exception& ex) { - callback(boost::current_exception(), Array::Ptr()); + callback(boost::current_exception(), nullptr); } } @@ -363,6 +363,6 @@ void ApiClient::AutocompleteScriptHttpCompletionCallback(HttpRequest& request, callback(boost::exception_ptr(), suggestions); } catch (const std::exception& ex) { - callback(boost::current_exception(), Array::Ptr()); + callback(boost::current_exception(), nullptr); } } diff --git a/lib/remote/apilistener-configsync.cpp b/lib/remote/apilistener-configsync.cpp index c2065d87a..393459048 100644 --- a/lib/remote/apilistener-configsync.cpp +++ b/lib/remote/apilistener-configsync.cpp @@ -425,7 +425,7 @@ void ApiListener::SendRuntimeConfigObjects(const JsonRpcConnection::Ptr& aclient continue; /* send the config object to the connected client */ - UpdateConfigObject(object, MessageOrigin::Ptr(), aclient); + UpdateConfigObject(object, nullptr, aclient); } } diff --git a/lib/remote/apilistener.cpp b/lib/remote/apilistener.cpp index 6e964c921..0cf810868 100644 --- a/lib/remote/apilistener.cpp +++ b/lib/remote/apilistener.cpp @@ -279,7 +279,7 @@ Endpoint::Ptr ApiListener::GetMaster(void) const Zone::Ptr zone = Zone::GetLocalZone(); if (!zone) - return Endpoint::Ptr(); + return nullptr; std::vector names; @@ -568,10 +568,10 @@ void ApiListener::SyncClient(const JsonRpcConnection::Ptr& aclient, const Endpoi Log(LogInformation, "ApiListener") << "Requesting new certificate for this Icinga instance from endpoint '" << endpoint->GetName() << "'."; - JsonRpcConnection::SendCertificateRequest(aclient, MessageOrigin::Ptr(), String()); + JsonRpcConnection::SendCertificateRequest(aclient, nullptr, String()); if (Utility::PathExists(ApiListener::GetCertificateRequestsDir())) - Utility::Glob(ApiListener::GetCertificateRequestsDir() + "/*.json", std::bind(&JsonRpcConnection::SendCertificateRequest, aclient, MessageOrigin::Ptr(), _1), GlobFile); + Utility::Glob(ApiListener::GetCertificateRequestsDir() + "/*.json", std::bind(&JsonRpcConnection::SendCertificateRequest, aclient, nullptr, _1), GlobFile); } /* Make sure that the config updates are synced diff --git a/lib/remote/apilistener.hpp b/lib/remote/apilistener.hpp index d258b6488..052209319 100644 --- a/lib/remote/apilistener.hpp +++ b/lib/remote/apilistener.hpp @@ -176,9 +176,9 @@ private: /* configsync */ void UpdateConfigObject(const ConfigObject::Ptr& object, const MessageOrigin::Ptr& origin, - const JsonRpcConnection::Ptr& client = JsonRpcConnection::Ptr()); + const JsonRpcConnection::Ptr& client = nullptr); void DeleteConfigObject(const ConfigObject::Ptr& object, const MessageOrigin::Ptr& origin, - const JsonRpcConnection::Ptr& client = JsonRpcConnection::Ptr()); + const JsonRpcConnection::Ptr& client = nullptr); void SendRuntimeConfigObjects(const JsonRpcConnection::Ptr& aclient); void SyncClient(const JsonRpcConnection::Ptr& aclient, const Endpoint::Ptr& endpoint, bool needSync); diff --git a/lib/remote/apiuser.cpp b/lib/remote/apiuser.cpp index fd4aec9a5..7c0989834 100644 --- a/lib/remote/apiuser.cpp +++ b/lib/remote/apiuser.cpp @@ -32,5 +32,5 @@ ApiUser::Ptr ApiUser::GetByClientCN(const String& cn) return user; } - return ApiUser::Ptr(); + return nullptr; } diff --git a/lib/remote/configpackageutility.hpp b/lib/remote/configpackageutility.hpp index a06eb33f7..3561bdf79 100644 --- a/lib/remote/configpackageutility.hpp +++ b/lib/remote/configpackageutility.hpp @@ -46,7 +46,7 @@ public: static std::vector GetPackages(void); static bool PackageExists(const String& name); - static String CreateStage(const String& packageName, const Dictionary::Ptr& files = Dictionary::Ptr()); + static String CreateStage(const String& packageName, const Dictionary::Ptr& files = nullptr); static void DeleteStage(const String& packageName, const String& stageName); static std::vector GetStages(const String& packageName); static String GetActiveStage(const String& packageName); diff --git a/lib/remote/endpoint.cpp b/lib/remote/endpoint.cpp index e922cd09c..38aeb4fc3 100644 --- a/lib/remote/endpoint.cpp +++ b/lib/remote/endpoint.cpp @@ -113,7 +113,7 @@ Endpoint::Ptr Endpoint::GetLocalEndpoint(void) ApiListener::Ptr listener = ApiListener::GetInstance(); if (!listener) - return Endpoint::Ptr(); + return nullptr; return listener->GetLocalEndpoint(); } diff --git a/lib/remote/eventqueue.cpp b/lib/remote/eventqueue.cpp index 77c1eec0f..5681214a2 100644 --- a/lib/remote/eventqueue.cpp +++ b/lib/remote/eventqueue.cpp @@ -115,11 +115,10 @@ Dictionary::Ptr EventQueue::WaitForEvent(void *client, double timeout) } if (!m_CV.timed_wait(lock, boost::posix_time::milliseconds(timeout * 1000))) - return Dictionary::Ptr(); + return nullptr; } } - std::vector EventQueue::GetQueuesForType(const String& type) { EventQueueRegistry::ItemMap queues = EventQueueRegistry::GetInstance()->GetItems(); diff --git a/lib/remote/filterutility.cpp b/lib/remote/filterutility.cpp index 24881284b..fbe0e0f29 100644 --- a/lib/remote/filterutility.cpp +++ b/lib/remote/filterutility.cpp @@ -33,7 +33,7 @@ Type::Ptr FilterUtility::TypeFromPluralName(const String& pluralName) String uname = pluralName; boost::algorithm::to_lower(uname); - for (const Type::Ptr&type : Type::GetAllTypes()) { + for (const Type::Ptr& type : Type::GetAllTypes()) { String pname = type->GetPluralName(); boost::algorithm::to_lower(pname); @@ -41,7 +41,7 @@ Type::Ptr FilterUtility::TypeFromPluralName(const String& pluralName) return type; } - return Type::Ptr(); + return nullptr; } void ConfigObjectTargetProvider::FindTargets(const String& type, const std::function& addTarget) const diff --git a/lib/remote/httpserverconnection.cpp b/lib/remote/httpserverconnection.cpp index 53e6f7af7..43c8d0f27 100644 --- a/lib/remote/httpserverconnection.cpp +++ b/lib/remote/httpserverconnection.cpp @@ -82,7 +82,7 @@ void HttpServerConnection::Disconnect(void) listener->RemoveHttpClient(this); m_CurrentRequest.~HttpRequest(); - new (&m_CurrentRequest) HttpRequest(Stream::Ptr()); + new (&m_CurrentRequest) HttpRequest(nullptr); m_Stream->Close(); } diff --git a/lib/remote/jsonrpcconnection-pki.cpp b/lib/remote/jsonrpcconnection-pki.cpp index 6f5a5214d..0d108105e 100644 --- a/lib/remote/jsonrpcconnection-pki.cpp +++ b/lib/remote/jsonrpcconnection-pki.cpp @@ -215,7 +215,7 @@ delayed_request: Utility::SaveJsonFile(requestPath, 0600, request); - JsonRpcConnection::SendCertificateRequest(JsonRpcConnection::Ptr(), origin, requestPath); + JsonRpcConnection::SendCertificateRequest(nullptr, origin, requestPath); result->Set("status_code", 2); result->Set("error", "Certificate request for CN '" + cn + "' is pending. Waiting for approval from the parent Icinga instance."); diff --git a/lib/remote/zone.cpp b/lib/remote/zone.cpp index d4660fd75..bb48d1f0e 100644 --- a/lib/remote/zone.cpp +++ b/lib/remote/zone.cpp @@ -139,7 +139,7 @@ Zone::Ptr Zone::GetLocalZone(void) Endpoint::Ptr local = Endpoint::GetLocalEndpoint(); if (!local) - return Zone::Ptr(); + return nullptr; return local->GetZone(); }