From e09fb88cae3b0e7246bb74b4da2eb408bf4bc288 Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Wed, 10 Aug 2016 16:33:17 +0200 Subject: [PATCH] Make sure functions are registered with the correct prefix refs #12393 --- lib/base/function.hpp | 23 +++++++++++++++++++++++ lib/db_ido/idochecktask.cpp | 2 +- lib/icinga/legacytimeperiod.cpp | 2 +- lib/methods/clrchecktask.cpp | 2 +- lib/methods/clusterchecktask.cpp | 2 +- lib/methods/clusterzonechecktask.cpp | 2 +- lib/methods/exceptionchecktask.cpp | 2 +- lib/methods/icingachecktask.cpp | 2 +- lib/methods/nullchecktask.cpp | 2 +- lib/methods/nulleventtask.cpp | 2 +- lib/methods/pluginchecktask.cpp | 2 +- lib/methods/plugineventtask.cpp | 2 +- lib/methods/pluginnotificationtask.cpp | 2 +- lib/methods/randomchecktask.cpp | 2 +- lib/methods/timeperiodtask.cpp | 4 ++-- 15 files changed, 38 insertions(+), 15 deletions(-) diff --git a/lib/base/function.hpp b/lib/base/function.hpp index 223a94d2e..3d76f173e 100644 --- a/lib/base/function.hpp +++ b/lib/base/function.hpp @@ -76,6 +76,17 @@ private: } } } #define REGISTER_SCRIPTFUNCTION_NS(ns, name, callback) \ + namespace { namespace UNIQUE_NAME(sf) { namespace sf ## ns ## name { \ + void RegisterFunction(void) { \ + Function::Ptr sf = new icinga::Function(#ns "#" #name, WrapFunction(callback), false); \ + ScriptGlobal::Set(#ns "." #name, sf); \ + Function::Ptr dsf = new icinga::Function("__" #name " (deprecated)", WrapFunction(callback), false, true); \ + ScriptGlobal::Set("__" #name, dsf); \ + } \ + INITIALIZE_ONCE_WITH_PRIORITY(RegisterFunction, 10); \ + } } } + +#define REGISTER_SCRIPTFUNCTION_NS_DEPRECATED(ns, name, callback) \ namespace { namespace UNIQUE_NAME(sf) { namespace sf ## ns ## name { \ void RegisterFunction(void) { \ Function::Ptr sf = new icinga::Function(#ns "#" #name, WrapFunction(callback), false); \ @@ -96,6 +107,17 @@ private: } } } #define REGISTER_SAFE_SCRIPTFUNCTION_NS(ns, name, callback) \ + namespace { namespace UNIQUE_NAME(sf) { namespace sf ## ns ## name { \ + void RegisterFunction(void) { \ + Function::Ptr sf = new icinga::Function(#ns "#" #name, WrapFunction(callback), true); \ + ScriptGlobal::Set(#ns "." #name, sf); \ + Function::Ptr dsf = new icinga::Function("__" #name " (deprecated)", WrapFunction(callback), true, true); \ + ScriptGlobal::Set("__" #name, dsf); \ + } \ + INITIALIZE_ONCE_WITH_PRIORITY(RegisterFunction, 10); \ + } } } + +#define REGISTER_SAFE_SCRIPTFUNCTION_NS_DEPRECATED(ns, name, callback) \ namespace { namespace UNIQUE_NAME(sf) { namespace sf ## ns ## name { \ void RegisterFunction(void) { \ Function::Ptr sf = new icinga::Function(#ns "#" #name, WrapFunction(callback), true); \ @@ -105,6 +127,7 @@ private: } \ INITIALIZE_ONCE_WITH_PRIORITY(RegisterFunction, 10); \ } } } + } #endif /* SCRIPTFUNCTION_H */ diff --git a/lib/db_ido/idochecktask.cpp b/lib/db_ido/idochecktask.cpp index 4a63ba5b9..bcab7aa89 100644 --- a/lib/db_ido/idochecktask.cpp +++ b/lib/db_ido/idochecktask.cpp @@ -33,7 +33,7 @@ using namespace icinga; -REGISTER_SCRIPTFUNCTION_NS(Internal, IdoCheck, &IdoCheckTask::ScriptFunc); +REGISTER_SCRIPTFUNCTION_NS_DEPRECATED(Internal, IdoCheck, &IdoCheckTask::ScriptFunc); void IdoCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr, const Dictionary::Ptr& resolvedMacros, bool useResolvedMacros) diff --git a/lib/icinga/legacytimeperiod.cpp b/lib/icinga/legacytimeperiod.cpp index 3ab43f0c6..a00f24e18 100644 --- a/lib/icinga/legacytimeperiod.cpp +++ b/lib/icinga/legacytimeperiod.cpp @@ -31,7 +31,7 @@ using namespace icinga; -REGISTER_SCRIPTFUNCTION_NS(Internal, LegacyTimePeriod, &LegacyTimePeriod::ScriptFunc); +REGISTER_SCRIPTFUNCTION_NS_DEPRECATED(Internal, LegacyTimePeriod, &LegacyTimePeriod::ScriptFunc); bool LegacyTimePeriod::IsInTimeRange(tm *begin, tm *end, int stride, tm *reference) { diff --git a/lib/methods/clrchecktask.cpp b/lib/methods/clrchecktask.cpp index 6e3580c82..fcadd76a7 100644 --- a/lib/methods/clrchecktask.cpp +++ b/lib/methods/clrchecktask.cpp @@ -39,7 +39,7 @@ using namespace icinga; -REGISTER_SCRIPTFUNCTION_NS(Internal, ClrCheck, &ClrCheckTask::ScriptFunc); +REGISTER_SCRIPTFUNCTION_NS_DEPRECATED(Internal, ClrCheck, &ClrCheckTask::ScriptFunc); static boost::once_flag l_OnceFlag = BOOST_ONCE_INIT; diff --git a/lib/methods/clusterchecktask.cpp b/lib/methods/clusterchecktask.cpp index 99ebda29c..2068cdbd2 100644 --- a/lib/methods/clusterchecktask.cpp +++ b/lib/methods/clusterchecktask.cpp @@ -34,7 +34,7 @@ using namespace icinga; -REGISTER_SCRIPTFUNCTION_NS(Internal, ClusterCheck, &ClusterCheckTask::ScriptFunc); +REGISTER_SCRIPTFUNCTION_NS_DEPRECATED(Internal, ClusterCheck, &ClusterCheckTask::ScriptFunc); void ClusterCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr, const Dictionary::Ptr& resolvedMacros, bool useResolvedMacros) diff --git a/lib/methods/clusterzonechecktask.cpp b/lib/methods/clusterzonechecktask.cpp index b31444547..ca83ad648 100644 --- a/lib/methods/clusterzonechecktask.cpp +++ b/lib/methods/clusterzonechecktask.cpp @@ -30,7 +30,7 @@ using namespace icinga; -REGISTER_SCRIPTFUNCTION_NS(Internal, ClusterZoneCheck, &ClusterZoneCheckTask::ScriptFunc); +REGISTER_SCRIPTFUNCTION_NS_DEPRECATED(Internal, ClusterZoneCheck, &ClusterZoneCheckTask::ScriptFunc); void ClusterZoneCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr, const Dictionary::Ptr& resolvedMacros, bool useResolvedMacros) diff --git a/lib/methods/exceptionchecktask.cpp b/lib/methods/exceptionchecktask.cpp index 6e2fa7ade..1a759d902 100644 --- a/lib/methods/exceptionchecktask.cpp +++ b/lib/methods/exceptionchecktask.cpp @@ -29,7 +29,7 @@ using namespace icinga; -REGISTER_SCRIPTFUNCTION_NS(Internal, ExceptionCheck, &ExceptionCheckTask::ScriptFunc); +REGISTER_SCRIPTFUNCTION_NS_DEPRECATED(Internal, ExceptionCheck, &ExceptionCheckTask::ScriptFunc); void ExceptionCheckTask::ScriptFunc(const Checkable::Ptr& service, const CheckResult::Ptr& cr, const Dictionary::Ptr& resolvedMacros, bool useResolvedMacros) diff --git a/lib/methods/icingachecktask.cpp b/lib/methods/icingachecktask.cpp index 082881b1f..c08dce06d 100644 --- a/lib/methods/icingachecktask.cpp +++ b/lib/methods/icingachecktask.cpp @@ -30,7 +30,7 @@ using namespace icinga; -REGISTER_SCRIPTFUNCTION_NS(Internal, IcingaCheck, &IcingaCheckTask::ScriptFunc); +REGISTER_SCRIPTFUNCTION_NS_DEPRECATED(Internal, IcingaCheck, &IcingaCheckTask::ScriptFunc); void IcingaCheckTask::ScriptFunc(const Checkable::Ptr& service, const CheckResult::Ptr& cr, const Dictionary::Ptr& resolvedMacros, bool useResolvedMacros) diff --git a/lib/methods/nullchecktask.cpp b/lib/methods/nullchecktask.cpp index 9f7a85d60..10ee1e4f3 100644 --- a/lib/methods/nullchecktask.cpp +++ b/lib/methods/nullchecktask.cpp @@ -30,7 +30,7 @@ using namespace icinga; -REGISTER_SCRIPTFUNCTION_NS(Internal, NullCheck, &NullCheckTask::ScriptFunc); +REGISTER_SCRIPTFUNCTION_NS_DEPRECATED(Internal, NullCheck, &NullCheckTask::ScriptFunc); void NullCheckTask::ScriptFunc(const Checkable::Ptr& service, const CheckResult::Ptr& cr, const Dictionary::Ptr& resolvedMacros, bool useResolvedMacros) diff --git a/lib/methods/nulleventtask.cpp b/lib/methods/nulleventtask.cpp index e2bbff52b..65b81b04c 100644 --- a/lib/methods/nulleventtask.cpp +++ b/lib/methods/nulleventtask.cpp @@ -23,7 +23,7 @@ using namespace icinga; -REGISTER_SCRIPTFUNCTION_NS(Internal, NullEvent, &NullEventTask::ScriptFunc); +REGISTER_SCRIPTFUNCTION_NS_DEPRECATED(Internal, NullEvent, &NullEventTask::ScriptFunc); void NullEventTask::ScriptFunc(const Checkable::Ptr&, const Dictionary::Ptr& resolvedMacros, bool useResolvedMacros) { } diff --git a/lib/methods/pluginchecktask.cpp b/lib/methods/pluginchecktask.cpp index 83ad4610a..a0cd36957 100644 --- a/lib/methods/pluginchecktask.cpp +++ b/lib/methods/pluginchecktask.cpp @@ -34,7 +34,7 @@ using namespace icinga; -REGISTER_SCRIPTFUNCTION_NS(Internal, PluginCheck, &PluginCheckTask::ScriptFunc); +REGISTER_SCRIPTFUNCTION_NS_DEPRECATED(Internal, PluginCheck, &PluginCheckTask::ScriptFunc); void PluginCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr, const Dictionary::Ptr& resolvedMacros, bool useResolvedMacros) diff --git a/lib/methods/plugineventtask.cpp b/lib/methods/plugineventtask.cpp index 3e6f72f4f..4fb23d105 100644 --- a/lib/methods/plugineventtask.cpp +++ b/lib/methods/plugineventtask.cpp @@ -32,7 +32,7 @@ using namespace icinga; -REGISTER_SCRIPTFUNCTION_NS(Internal, PluginEvent, &PluginEventTask::ScriptFunc); +REGISTER_SCRIPTFUNCTION_NS_DEPRECATED(Internal, PluginEvent, &PluginEventTask::ScriptFunc); void PluginEventTask::ScriptFunc(const Checkable::Ptr& checkable, const Dictionary::Ptr& resolvedMacros, bool useResolvedMacros) diff --git a/lib/methods/pluginnotificationtask.cpp b/lib/methods/pluginnotificationtask.cpp index 28708684b..9f6af2a92 100644 --- a/lib/methods/pluginnotificationtask.cpp +++ b/lib/methods/pluginnotificationtask.cpp @@ -33,7 +33,7 @@ using namespace icinga; -REGISTER_SCRIPTFUNCTION_NS(Internal, PluginNotification, &PluginNotificationTask::ScriptFunc); +REGISTER_SCRIPTFUNCTION_NS_DEPRECATED(Internal, PluginNotification, &PluginNotificationTask::ScriptFunc); void PluginNotificationTask::ScriptFunc(const Notification::Ptr& notification, const User::Ptr& user, const CheckResult::Ptr& cr, int itype, diff --git a/lib/methods/randomchecktask.cpp b/lib/methods/randomchecktask.cpp index 3ace01ff8..1b42de591 100644 --- a/lib/methods/randomchecktask.cpp +++ b/lib/methods/randomchecktask.cpp @@ -30,7 +30,7 @@ using namespace icinga; -REGISTER_SCRIPTFUNCTION_NS(Internal, RandomCheck, &RandomCheckTask::ScriptFunc); +REGISTER_SCRIPTFUNCTION_NS_DEPRECATED(Internal, RandomCheck, &RandomCheckTask::ScriptFunc); void RandomCheckTask::ScriptFunc(const Checkable::Ptr& service, const CheckResult::Ptr& cr, const Dictionary::Ptr& resolvedMacros, bool useResolvedMacros) diff --git a/lib/methods/timeperiodtask.cpp b/lib/methods/timeperiodtask.cpp index 059877950..a0b59e838 100644 --- a/lib/methods/timeperiodtask.cpp +++ b/lib/methods/timeperiodtask.cpp @@ -22,8 +22,8 @@ using namespace icinga; -REGISTER_SCRIPTFUNCTION_NS(Internal, EmptyTimePeriod, &TimePeriodTask::EmptyTimePeriodUpdate); -REGISTER_SCRIPTFUNCTION_NS(Internal, EvenMinutesTimePeriod, &TimePeriodTask::EvenMinutesTimePeriodUpdate); +REGISTER_SCRIPTFUNCTION_NS_DEPRECATED(Internal, EmptyTimePeriod, &TimePeriodTask::EmptyTimePeriodUpdate); +REGISTER_SCRIPTFUNCTION_NS_DEPRECATED(Internal, EvenMinutesTimePeriod, &TimePeriodTask::EvenMinutesTimePeriodUpdate); Array::Ptr TimePeriodTask::EmptyTimePeriodUpdate(const TimePeriod::Ptr&, double, double) {