mirror of https://github.com/Icinga/icinga2.git
parent
461cf8dbc1
commit
1cb0231c05
|
@ -27,7 +27,7 @@
|
||||||
#include "base/utility.hpp"
|
#include "base/utility.hpp"
|
||||||
#include "base/exception.hpp"
|
#include "base/exception.hpp"
|
||||||
#include "base/convert.hpp"
|
#include "base/convert.hpp"
|
||||||
#include "base/scriptvariable.hpp"
|
#include "base/scriptglobal.hpp"
|
||||||
#include "base/context.hpp"
|
#include "base/context.hpp"
|
||||||
#include "base/console.hpp"
|
#include "base/console.hpp"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
@ -227,7 +227,7 @@ int Main(void)
|
||||||
key = define;
|
key = define;
|
||||||
value = "1";
|
value = "1";
|
||||||
}
|
}
|
||||||
ScriptVariable::Set(key, value);
|
ScriptGlobal::Set(key, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,8 +27,8 @@ set(base_SOURCES
|
||||||
convert.cpp debuginfo.cpp dictionary.cpp dictionary-script.cpp dynamicobject.cpp dynamicobject.thpp dynamictype.cpp
|
convert.cpp debuginfo.cpp dictionary.cpp dictionary-script.cpp dynamicobject.cpp dynamicobject.thpp dynamictype.cpp
|
||||||
exception.cpp fifo.cpp filelogger.cpp filelogger.thpp initialize.cpp json.cpp logger.cpp logger.thpp
|
exception.cpp fifo.cpp filelogger.cpp filelogger.thpp initialize.cpp json.cpp logger.cpp logger.thpp
|
||||||
netstring.cpp networkstream.cpp number.cpp number-script.cpp object.cpp object-script.cpp primitivetype.cpp process.cpp
|
netstring.cpp networkstream.cpp number.cpp number-script.cpp object.cpp object-script.cpp primitivetype.cpp process.cpp
|
||||||
ringbuffer.cpp scripterror.cpp scriptframe.cpp scriptfunction.cpp scriptfunctionwrapper.cpp scriptsignal.cpp
|
ringbuffer.cpp scripterror.cpp scriptframe.cpp scriptfunction.cpp scriptfunctionwrapper.cpp scriptglobal.cpp
|
||||||
scriptutils.cpp scriptvariable.cpp serializer.cpp socket.cpp stacktrace.cpp
|
scriptutils.cpp serializer.cpp socket.cpp stacktrace.cpp
|
||||||
statsfunction.cpp stdiostream.cpp stream.cpp streamlogger.cpp streamlogger.thpp string.cpp string-script.cpp
|
statsfunction.cpp stdiostream.cpp stream.cpp streamlogger.cpp streamlogger.thpp string.cpp string-script.cpp
|
||||||
sysloglogger.cpp sysloglogger.thpp tcpsocket.cpp thinmutex.cpp threadpool.cpp timer.cpp
|
sysloglogger.cpp sysloglogger.thpp tcpsocket.cpp thinmutex.cpp threadpool.cpp timer.cpp
|
||||||
tlsstream.cpp tlsutility.cpp type.cpp unixsocket.cpp utility.cpp value.cpp
|
tlsstream.cpp tlsutility.cpp type.cpp unixsocket.cpp utility.cpp value.cpp
|
||||||
|
|
|
@ -27,7 +27,7 @@
|
||||||
#include "base/debug.hpp"
|
#include "base/debug.hpp"
|
||||||
#include "base/type.hpp"
|
#include "base/type.hpp"
|
||||||
#include "base/convert.hpp"
|
#include "base/convert.hpp"
|
||||||
#include "base/scriptvariable.hpp"
|
#include "base/scriptglobal.hpp"
|
||||||
#include "base/process.hpp"
|
#include "base/process.hpp"
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <boost/algorithm/string/classification.hpp>
|
#include <boost/algorithm/string/classification.hpp>
|
||||||
|
@ -846,7 +846,7 @@ pid_t Application::ReadPidFile(const String& filename)
|
||||||
*/
|
*/
|
||||||
String Application::GetPrefixDir(void)
|
String Application::GetPrefixDir(void)
|
||||||
{
|
{
|
||||||
return ScriptVariable::Get("PrefixDir");
|
return ScriptGlobal::Get("PrefixDir");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -856,7 +856,7 @@ String Application::GetPrefixDir(void)
|
||||||
*/
|
*/
|
||||||
void Application::DeclarePrefixDir(const String& path)
|
void Application::DeclarePrefixDir(const String& path)
|
||||||
{
|
{
|
||||||
ScriptVariable::Set("PrefixDir", path, false);
|
ScriptGlobal::Set("PrefixDir", path);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -866,7 +866,7 @@ void Application::DeclarePrefixDir(const String& path)
|
||||||
*/
|
*/
|
||||||
String Application::GetSysconfDir(void)
|
String Application::GetSysconfDir(void)
|
||||||
{
|
{
|
||||||
return ScriptVariable::Get("SysconfDir");
|
return ScriptGlobal::Get("SysconfDir");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -876,7 +876,7 @@ String Application::GetSysconfDir(void)
|
||||||
*/
|
*/
|
||||||
void Application::DeclareSysconfDir(const String& path)
|
void Application::DeclareSysconfDir(const String& path)
|
||||||
{
|
{
|
||||||
ScriptVariable::Set("SysconfDir", path, false);
|
ScriptGlobal::Set("SysconfDir", path);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -886,7 +886,7 @@ void Application::DeclareSysconfDir(const String& path)
|
||||||
*/
|
*/
|
||||||
String Application::GetRunDir(void)
|
String Application::GetRunDir(void)
|
||||||
{
|
{
|
||||||
return ScriptVariable::Get("RunDir");
|
return ScriptGlobal::Get("RunDir");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -896,7 +896,7 @@ String Application::GetRunDir(void)
|
||||||
*/
|
*/
|
||||||
void Application::DeclareRunDir(const String& path)
|
void Application::DeclareRunDir(const String& path)
|
||||||
{
|
{
|
||||||
ScriptVariable::Set("RunDir", path, false);
|
ScriptGlobal::Set("RunDir", path);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -906,7 +906,7 @@ void Application::DeclareRunDir(const String& path)
|
||||||
*/
|
*/
|
||||||
String Application::GetLocalStateDir(void)
|
String Application::GetLocalStateDir(void)
|
||||||
{
|
{
|
||||||
return ScriptVariable::Get("LocalStateDir");
|
return ScriptGlobal::Get("LocalStateDir");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -916,7 +916,7 @@ String Application::GetLocalStateDir(void)
|
||||||
*/
|
*/
|
||||||
void Application::DeclareLocalStateDir(const String& path)
|
void Application::DeclareLocalStateDir(const String& path)
|
||||||
{
|
{
|
||||||
ScriptVariable::Set("LocalStateDir", path, false);
|
ScriptGlobal::Set("LocalStateDir", path);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -926,7 +926,7 @@ void Application::DeclareLocalStateDir(const String& path)
|
||||||
*/
|
*/
|
||||||
String Application::GetZonesDir(void)
|
String Application::GetZonesDir(void)
|
||||||
{
|
{
|
||||||
return ScriptVariable::Get("ZonesDir", &Empty);
|
return ScriptGlobal::Get("ZonesDir", &Empty);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -936,7 +936,7 @@ String Application::GetZonesDir(void)
|
||||||
*/
|
*/
|
||||||
void Application::DeclareZonesDir(const String& path)
|
void Application::DeclareZonesDir(const String& path)
|
||||||
{
|
{
|
||||||
ScriptVariable::Set("ZonesDir", path, false);
|
ScriptGlobal::Set("ZonesDir", path);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -947,7 +947,7 @@ void Application::DeclareZonesDir(const String& path)
|
||||||
String Application::GetPkgDataDir(void)
|
String Application::GetPkgDataDir(void)
|
||||||
{
|
{
|
||||||
String defaultValue = "";
|
String defaultValue = "";
|
||||||
return ScriptVariable::Get("PkgDataDir", &Empty);
|
return ScriptGlobal::Get("PkgDataDir", &Empty);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -957,7 +957,7 @@ String Application::GetPkgDataDir(void)
|
||||||
*/
|
*/
|
||||||
void Application::DeclarePkgDataDir(const String& path)
|
void Application::DeclarePkgDataDir(const String& path)
|
||||||
{
|
{
|
||||||
ScriptVariable::Set("PkgDataDir", path, false);
|
ScriptGlobal::Set("PkgDataDir", path);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -967,7 +967,7 @@ void Application::DeclarePkgDataDir(const String& path)
|
||||||
*/
|
*/
|
||||||
String Application::GetIncludeConfDir(void)
|
String Application::GetIncludeConfDir(void)
|
||||||
{
|
{
|
||||||
return ScriptVariable::Get("IncludeConfDir", &Empty);
|
return ScriptGlobal::Get("IncludeConfDir", &Empty);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -977,7 +977,7 @@ String Application::GetIncludeConfDir(void)
|
||||||
*/
|
*/
|
||||||
void Application::DeclareIncludeConfDir(const String& path)
|
void Application::DeclareIncludeConfDir(const String& path)
|
||||||
{
|
{
|
||||||
ScriptVariable::Set("IncludeConfDir", path, false);
|
ScriptGlobal::Set("IncludeConfDir", path);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -987,7 +987,7 @@ void Application::DeclareIncludeConfDir(const String& path)
|
||||||
*/
|
*/
|
||||||
String Application::GetStatePath(void)
|
String Application::GetStatePath(void)
|
||||||
{
|
{
|
||||||
return ScriptVariable::Get("StatePath", &Empty);
|
return ScriptGlobal::Get("StatePath", &Empty);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -997,7 +997,7 @@ String Application::GetStatePath(void)
|
||||||
*/
|
*/
|
||||||
void Application::DeclareStatePath(const String& path)
|
void Application::DeclareStatePath(const String& path)
|
||||||
{
|
{
|
||||||
ScriptVariable::Set("StatePath", path, false);
|
ScriptGlobal::Set("StatePath", path);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1007,7 +1007,7 @@ void Application::DeclareStatePath(const String& path)
|
||||||
*/
|
*/
|
||||||
String Application::GetObjectsPath(void)
|
String Application::GetObjectsPath(void)
|
||||||
{
|
{
|
||||||
return ScriptVariable::Get("ObjectsPath", &Empty);
|
return ScriptGlobal::Get("ObjectsPath", &Empty);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1017,7 +1017,7 @@ String Application::GetObjectsPath(void)
|
||||||
*/
|
*/
|
||||||
void Application::DeclareObjectsPath(const String& path)
|
void Application::DeclareObjectsPath(const String& path)
|
||||||
{
|
{
|
||||||
ScriptVariable::Set("ObjectsPath", path, false);
|
ScriptGlobal::Set("ObjectsPath", path);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1027,7 +1027,7 @@ void Application::DeclareObjectsPath(const String& path)
|
||||||
*/
|
*/
|
||||||
String Application::GetVarsPath(void)
|
String Application::GetVarsPath(void)
|
||||||
{
|
{
|
||||||
return ScriptVariable::Get("VarsPath", &Empty);
|
return ScriptGlobal::Get("VarsPath", &Empty);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1037,7 +1037,7 @@ String Application::GetVarsPath(void)
|
||||||
*/
|
*/
|
||||||
void Application::DeclareVarsPath(const String& path)
|
void Application::DeclareVarsPath(const String& path)
|
||||||
{
|
{
|
||||||
ScriptVariable::Set("VarsPath", path, false);
|
ScriptGlobal::Set("VarsPath", path);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1047,7 +1047,7 @@ void Application::DeclareVarsPath(const String& path)
|
||||||
*/
|
*/
|
||||||
String Application::GetPidPath(void)
|
String Application::GetPidPath(void)
|
||||||
{
|
{
|
||||||
return ScriptVariable::Get("PidPath", &Empty);
|
return ScriptGlobal::Get("PidPath", &Empty);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1057,7 +1057,7 @@ String Application::GetPidPath(void)
|
||||||
*/
|
*/
|
||||||
void Application::DeclarePidPath(const String& path)
|
void Application::DeclarePidPath(const String& path)
|
||||||
{
|
{
|
||||||
ScriptVariable::Set("PidPath", path, false);
|
ScriptGlobal::Set("PidPath", path);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1067,7 +1067,7 @@ void Application::DeclarePidPath(const String& path)
|
||||||
*/
|
*/
|
||||||
String Application::GetApplicationType(void)
|
String Application::GetApplicationType(void)
|
||||||
{
|
{
|
||||||
return ScriptVariable::Get("ApplicationType");
|
return ScriptGlobal::Get("ApplicationType");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1077,7 +1077,7 @@ String Application::GetApplicationType(void)
|
||||||
*/
|
*/
|
||||||
void Application::DeclareApplicationType(const String& type)
|
void Application::DeclareApplicationType(const String& type)
|
||||||
{
|
{
|
||||||
ScriptVariable::Set("ApplicationType", type, false);
|
ScriptGlobal::Set("ApplicationType", type);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1087,7 +1087,7 @@ void Application::DeclareApplicationType(const String& type)
|
||||||
*/
|
*/
|
||||||
String Application::GetRunAsUser(void)
|
String Application::GetRunAsUser(void)
|
||||||
{
|
{
|
||||||
return ScriptVariable::Get("RunAsUser");
|
return ScriptGlobal::Get("RunAsUser");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1097,7 +1097,7 @@ String Application::GetRunAsUser(void)
|
||||||
*/
|
*/
|
||||||
void Application::DeclareRunAsUser(const String& user)
|
void Application::DeclareRunAsUser(const String& user)
|
||||||
{
|
{
|
||||||
ScriptVariable::Set("RunAsUser", user, false);
|
ScriptGlobal::Set("RunAsUser", user);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1107,7 +1107,7 @@ void Application::DeclareRunAsUser(const String& user)
|
||||||
*/
|
*/
|
||||||
String Application::GetRunAsGroup(void)
|
String Application::GetRunAsGroup(void)
|
||||||
{
|
{
|
||||||
return ScriptVariable::Get("RunAsGroup");
|
return ScriptGlobal::Get("RunAsGroup");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1117,7 +1117,7 @@ String Application::GetRunAsGroup(void)
|
||||||
*/
|
*/
|
||||||
void Application::DeclareConcurrency(int ncpus)
|
void Application::DeclareConcurrency(int ncpus)
|
||||||
{
|
{
|
||||||
ScriptVariable::Set("Concurrency", ncpus, false);
|
ScriptGlobal::Set("Concurrency", ncpus);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1128,7 +1128,7 @@ void Application::DeclareConcurrency(int ncpus)
|
||||||
int Application::GetConcurrency(void)
|
int Application::GetConcurrency(void)
|
||||||
{
|
{
|
||||||
Value defaultConcurrency = boost::thread::hardware_concurrency();
|
Value defaultConcurrency = boost::thread::hardware_concurrency();
|
||||||
return ScriptVariable::Get("Concurrency", &defaultConcurrency);
|
return ScriptGlobal::Get("Concurrency", &defaultConcurrency);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1138,22 +1138,7 @@ int Application::GetConcurrency(void)
|
||||||
*/
|
*/
|
||||||
void Application::DeclareRunAsGroup(const String& group)
|
void Application::DeclareRunAsGroup(const String& group)
|
||||||
{
|
{
|
||||||
ScriptVariable::Set("RunAsGroup", group, false);
|
ScriptGlobal::Set("RunAsGroup", group);
|
||||||
}
|
|
||||||
|
|
||||||
void Application::MakeVariablesConstant(void)
|
|
||||||
{
|
|
||||||
ScriptVariable::GetByName("PrefixDir")->SetConstant(true);
|
|
||||||
ScriptVariable::GetByName("SysconfDir")->SetConstant(true);
|
|
||||||
ScriptVariable::GetByName("LocalStateDir")->SetConstant(true);
|
|
||||||
ScriptVariable::GetByName("RunDir")->SetConstant(true);
|
|
||||||
ScriptVariable::GetByName("PkgDataDir")->SetConstant(true);
|
|
||||||
ScriptVariable::GetByName("StatePath")->SetConstant(true);
|
|
||||||
ScriptVariable::GetByName("ObjectsPath")->SetConstant(true);
|
|
||||||
ScriptVariable::GetByName("PidPath")->SetConstant(true);
|
|
||||||
ScriptVariable::GetByName("ApplicationType")->SetConstant(true);
|
|
||||||
ScriptVariable::GetByName("RunAsUser")->SetConstant(true);
|
|
||||||
ScriptVariable::GetByName("RunAsGroup")->SetConstant(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -126,8 +126,6 @@ public:
|
||||||
static int GetConcurrency(void);
|
static int GetConcurrency(void);
|
||||||
static void DeclareConcurrency(int ncpus);
|
static void DeclareConcurrency(int ncpus);
|
||||||
|
|
||||||
static void MakeVariablesConstant(void);
|
|
||||||
|
|
||||||
static ThreadPool& GetTP(void);
|
static ThreadPool& GetTP(void);
|
||||||
|
|
||||||
static String GetVersion(void);
|
static String GetVersion(void);
|
||||||
|
|
|
@ -29,7 +29,6 @@
|
||||||
#include "base/exception.hpp"
|
#include "base/exception.hpp"
|
||||||
#include "base/scriptfunction.hpp"
|
#include "base/scriptfunction.hpp"
|
||||||
#include "base/initialize.hpp"
|
#include "base/initialize.hpp"
|
||||||
#include "base/scriptvariable.hpp"
|
|
||||||
#include "base/workqueue.hpp"
|
#include "base/workqueue.hpp"
|
||||||
#include "base/context.hpp"
|
#include "base/context.hpp"
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
#include "base/utility.hpp"
|
#include "base/utility.hpp"
|
||||||
#include "base/objectlock.hpp"
|
#include "base/objectlock.hpp"
|
||||||
#include "base/context.hpp"
|
#include "base/context.hpp"
|
||||||
#include "base/scriptvariable.hpp"
|
#include "base/scriptglobal.hpp"
|
||||||
#include <boost/foreach.hpp>
|
#include <boost/foreach.hpp>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
|
@ -41,11 +41,11 @@ LogSeverity Logger::m_ConsoleLogSeverity = LogInformation;
|
||||||
|
|
||||||
void Logger::StaticInitialize(void)
|
void Logger::StaticInitialize(void)
|
||||||
{
|
{
|
||||||
ScriptVariable::Set("LogDebug", LogDebug, true, true);
|
ScriptGlobal::Set("LogDebug", LogDebug);
|
||||||
ScriptVariable::Set("LogNotice", LogNotice, true, true);
|
ScriptGlobal::Set("LogNotice", LogNotice);
|
||||||
ScriptVariable::Set("LogInformation", LogInformation, true, true);
|
ScriptGlobal::Set("LogInformation", LogInformation);
|
||||||
ScriptVariable::Set("LogWarning", LogWarning, true, true);
|
ScriptGlobal::Set("LogWarning", LogWarning);
|
||||||
ScriptVariable::Set("LogCritical", LogCritical, true, true);
|
ScriptGlobal::Set("LogCritical", LogCritical);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
#include "base/initialize.hpp"
|
#include "base/initialize.hpp"
|
||||||
#include "base/logger.hpp"
|
#include "base/logger.hpp"
|
||||||
#include "base/utility.hpp"
|
#include "base/utility.hpp"
|
||||||
#include "base/scriptvariable.hpp"
|
#include "base/scriptglobal.hpp"
|
||||||
#include <boost/foreach.hpp>
|
#include <boost/foreach.hpp>
|
||||||
#include <boost/algorithm/string/join.hpp>
|
#include <boost/algorithm/string/join.hpp>
|
||||||
#include <boost/thread/once.hpp>
|
#include <boost/thread/once.hpp>
|
||||||
|
@ -510,7 +510,7 @@ void Process::Run(const boost::function<void(const ProcessResult&)>& callback)
|
||||||
m_ExtraEnvironment.reset();
|
m_ExtraEnvironment.reset();
|
||||||
|
|
||||||
#ifdef HAVE_VFORK
|
#ifdef HAVE_VFORK
|
||||||
Value use_vfork = ScriptVariable::Get("UseVfork");
|
Value use_vfork = ScriptGlobal::Get("UseVfork");
|
||||||
|
|
||||||
if (use_vfork.IsEmpty() || static_cast<bool>(use_vfork))
|
if (use_vfork.IsEmpty() || static_cast<bool>(use_vfork))
|
||||||
m_Process = vfork();
|
m_Process = vfork();
|
||||||
|
|
|
@ -18,7 +18,6 @@
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
|
|
||||||
#include "base/scriptfunction.hpp"
|
#include "base/scriptfunction.hpp"
|
||||||
#include "base/scriptvariable.hpp"
|
|
||||||
#include "base/primitivetype.hpp"
|
#include "base/primitivetype.hpp"
|
||||||
#include "base/dictionary.hpp"
|
#include "base/dictionary.hpp"
|
||||||
|
|
||||||
|
@ -46,25 +45,3 @@ Value ScriptFunction::Invoke(const std::vector<Value>& arguments)
|
||||||
return m_Callback(arguments);
|
return m_Callback(arguments);
|
||||||
}
|
}
|
||||||
|
|
||||||
ScriptFunction::Ptr ScriptFunction::GetByName(const String& name)
|
|
||||||
{
|
|
||||||
ScriptVariable::Ptr sv = ScriptVariable::GetByName(name);
|
|
||||||
|
|
||||||
if (!sv)
|
|
||||||
return ScriptFunction::Ptr();
|
|
||||||
|
|
||||||
return sv->GetData();
|
|
||||||
}
|
|
||||||
|
|
||||||
void ScriptFunction::Register(const String& name, const ScriptFunction::Ptr& function)
|
|
||||||
{
|
|
||||||
ScriptVariable::Ptr sv = ScriptVariable::Set(name, function);
|
|
||||||
sv->SetConstant(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ScriptFunction::Unregister(const String& name)
|
|
||||||
{
|
|
||||||
ScriptVariable::Unregister(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
#include "base/i2-base.hpp"
|
#include "base/i2-base.hpp"
|
||||||
#include "base/value.hpp"
|
#include "base/value.hpp"
|
||||||
#include "base/scriptfunctionwrapper.hpp"
|
#include "base/scriptfunctionwrapper.hpp"
|
||||||
|
#include "base/scriptglobal.hpp"
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <boost/function.hpp>
|
#include <boost/function.hpp>
|
||||||
|
|
||||||
|
@ -45,10 +46,6 @@ public:
|
||||||
|
|
||||||
Value Invoke(const std::vector<Value>& arguments);
|
Value Invoke(const std::vector<Value>& arguments);
|
||||||
|
|
||||||
static ScriptFunction::Ptr GetByName(const String& name);
|
|
||||||
static void Register(const String& name, const ScriptFunction::Ptr& function);
|
|
||||||
static void Unregister(const String& name);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Callback m_Callback;
|
Callback m_Callback;
|
||||||
};
|
};
|
||||||
|
@ -57,7 +54,7 @@ private:
|
||||||
namespace { namespace UNIQUE_NAME(sf) { namespace sf ## name { \
|
namespace { namespace UNIQUE_NAME(sf) { namespace sf ## name { \
|
||||||
void RegisterFunction(void) { \
|
void RegisterFunction(void) { \
|
||||||
ScriptFunction::Ptr sf = new icinga::ScriptFunction(WrapScriptFunction(callback)); \
|
ScriptFunction::Ptr sf = new icinga::ScriptFunction(WrapScriptFunction(callback)); \
|
||||||
ScriptFunction::Register(#name, sf); \
|
ScriptGlobal::Set(#name, sf); \
|
||||||
} \
|
} \
|
||||||
INITIALIZE_ONCE(RegisterFunction); \
|
INITIALIZE_ONCE(RegisterFunction); \
|
||||||
} } }
|
} } }
|
||||||
|
|
|
@ -17,89 +17,46 @@
|
||||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
|
|
||||||
#include "base/scriptvariable.hpp"
|
#include "base/scriptglobal.hpp"
|
||||||
#include "base/singleton.hpp"
|
#include "base/singleton.hpp"
|
||||||
#include "base/logger.hpp"
|
#include "base/logger.hpp"
|
||||||
#include "base/stdiostream.hpp"
|
#include "base/stdiostream.hpp"
|
||||||
#include "base/netstring.hpp"
|
#include "base/netstring.hpp"
|
||||||
#include "base/json.hpp"
|
#include "base/json.hpp"
|
||||||
#include "base/convert.hpp"
|
#include "base/convert.hpp"
|
||||||
|
#include "base/objectlock.hpp"
|
||||||
#include <boost/foreach.hpp>
|
#include <boost/foreach.hpp>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
|
||||||
using namespace icinga;
|
using namespace icinga;
|
||||||
|
|
||||||
ScriptVariable::ScriptVariable(const Value& data)
|
Dictionary::Ptr ScriptGlobal::m_Globals = new Dictionary();
|
||||||
: m_Data(data), m_Constant(false)
|
|
||||||
{ }
|
|
||||||
|
|
||||||
ScriptVariable::Ptr ScriptVariable::GetByName(const String& name)
|
Value ScriptGlobal::Get(const String& name, const Value *defaultValue)
|
||||||
{
|
{
|
||||||
return ScriptVariableRegistry::GetInstance()->GetItem(name);
|
if (!m_Globals->Contains(name)) {
|
||||||
}
|
|
||||||
|
|
||||||
void ScriptVariable::SetConstant(bool constant)
|
|
||||||
{
|
|
||||||
m_Constant = constant;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ScriptVariable::IsConstant(void) const
|
|
||||||
{
|
|
||||||
return m_Constant;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ScriptVariable::SetData(const Value& data)
|
|
||||||
{
|
|
||||||
m_Data = data;
|
|
||||||
}
|
|
||||||
|
|
||||||
Value ScriptVariable::GetData(void) const
|
|
||||||
{
|
|
||||||
return m_Data;
|
|
||||||
}
|
|
||||||
|
|
||||||
Value ScriptVariable::Get(const String& name, const Value *defaultValue)
|
|
||||||
{
|
|
||||||
ScriptVariable::Ptr sv = GetByName(name);
|
|
||||||
|
|
||||||
if (!sv) {
|
|
||||||
if (defaultValue)
|
if (defaultValue)
|
||||||
return *defaultValue;
|
return *defaultValue;
|
||||||
|
|
||||||
BOOST_THROW_EXCEPTION(std::invalid_argument("Tried to access undefined script variable '" + name + "'"));
|
BOOST_THROW_EXCEPTION(std::invalid_argument("Tried to access undefined script variable '" + name + "'"));
|
||||||
}
|
}
|
||||||
|
|
||||||
return sv->GetData();
|
return m_Globals->Get(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
ScriptVariable::Ptr ScriptVariable::Set(const String& name, const Value& value, bool overwrite, bool make_const)
|
void ScriptGlobal::Set(const String& name, const Value& value)
|
||||||
{
|
{
|
||||||
ScriptVariable::Ptr sv = GetByName(name);
|
m_Globals->Set(name, value);
|
||||||
|
|
||||||
if (!sv) {
|
|
||||||
sv = new ScriptVariable(value);
|
|
||||||
ScriptVariableRegistry::GetInstance()->Register(name, sv);
|
|
||||||
} else if (overwrite) {
|
|
||||||
if (sv->IsConstant())
|
|
||||||
BOOST_THROW_EXCEPTION(std::invalid_argument("Tried to modify read-only script variable '" + name + "'"));
|
|
||||||
|
|
||||||
sv->SetData(value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (make_const)
|
Dictionary::Ptr ScriptGlobal::GetGlobals(void)
|
||||||
sv->SetConstant(true);
|
|
||||||
|
|
||||||
return sv;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ScriptVariable::Unregister(const String& name)
|
|
||||||
{
|
{
|
||||||
ScriptVariableRegistry::GetInstance()->Unregister(name);
|
return m_Globals;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScriptVariable::WriteVariablesFile(const String& filename)
|
void ScriptGlobal::WriteToFile(const String& filename)
|
||||||
{
|
{
|
||||||
Log(LogInformation, "ScriptVariable")
|
Log(LogInformation, "ScriptGlobal")
|
||||||
<< "Dumping variables to file '" << filename << "'";
|
<< "Dumping variables to file '" << filename << "'";
|
||||||
|
|
||||||
String tempFilename = filename + ".tmp";
|
String tempFilename = filename + ".tmp";
|
||||||
|
@ -112,13 +69,13 @@ void ScriptVariable::WriteVariablesFile(const String& filename)
|
||||||
|
|
||||||
StdioStream::Ptr sfp = new StdioStream(&fp, false);
|
StdioStream::Ptr sfp = new StdioStream(&fp, false);
|
||||||
|
|
||||||
BOOST_FOREACH(const ScriptVariableRegistry::ItemMap::value_type& kv, ScriptVariableRegistry::GetInstance()->GetItems()) {
|
ObjectLock olock(m_Globals);
|
||||||
|
BOOST_FOREACH(const Dictionary::Pair& kv, m_Globals) {
|
||||||
Dictionary::Ptr persistentVariable = new Dictionary();
|
Dictionary::Ptr persistentVariable = new Dictionary();
|
||||||
|
|
||||||
persistentVariable->Set("name", kv.first);
|
persistentVariable->Set("name", kv.first);
|
||||||
|
|
||||||
ScriptVariable::Ptr sv = kv.second;
|
Value value = kv.second;
|
||||||
Value value = sv->GetData();
|
|
||||||
|
|
||||||
if (value.IsObject())
|
if (value.IsObject())
|
||||||
value = Convert::ToString(value);
|
value = Convert::ToString(value);
|
||||||
|
@ -146,8 +103,3 @@ void ScriptVariable::WriteVariablesFile(const String& filename)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ScriptVariableRegistry *ScriptVariableRegistry::GetInstance(void)
|
|
||||||
{
|
|
||||||
return Singleton<ScriptVariableRegistry>::GetInstance();
|
|
||||||
}
|
|
||||||
|
|
|
@ -17,40 +17,34 @@
|
||||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
|
|
||||||
#include "base/scriptsignal.hpp"
|
#ifndef SCRIPTGLOBAL_H
|
||||||
#include "base/scriptvariable.hpp"
|
#define SCRIPTGLOBAL_H
|
||||||
|
|
||||||
using namespace icinga;
|
#include "base/i2-base.hpp"
|
||||||
|
#include "base/dictionary.hpp"
|
||||||
|
|
||||||
void ScriptSignal::AddSlot(const Callback& slot)
|
namespace icinga
|
||||||
{
|
{
|
||||||
m_Slots.push_back(slot);
|
|
||||||
}
|
/**
|
||||||
|
* Global script variables.
|
||||||
void ScriptSignal::Invoke(const std::vector<Value>& arguments)
|
*
|
||||||
{
|
* @ingroup base
|
||||||
BOOST_FOREACH(const Callback& slot, m_Slots)
|
*/
|
||||||
slot(arguments);
|
class I2_BASE_API ScriptGlobal
|
||||||
}
|
{
|
||||||
|
public:
|
||||||
ScriptSignal::Ptr ScriptSignal::GetByName(const String& name)
|
static Value Get(const String& name, const Value *defaultValue = NULL);
|
||||||
{
|
static void Set(const String& name, const Value& value);
|
||||||
ScriptVariable::Ptr sv = ScriptVariable::GetByName(name);
|
|
||||||
|
static void WriteToFile(const String& filename);
|
||||||
if (!sv)
|
|
||||||
return ScriptSignal::Ptr();
|
static Dictionary::Ptr GetGlobals(void);
|
||||||
|
|
||||||
return sv->GetData();
|
private:
|
||||||
}
|
static Dictionary::Ptr m_Globals;
|
||||||
|
};
|
||||||
void ScriptSignal::Register(const String& name, const ScriptSignal::Ptr& function)
|
|
||||||
{
|
|
||||||
ScriptVariable::Ptr sv = ScriptVariable::Set(name, function);
|
|
||||||
sv->SetConstant(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ScriptSignal::Unregister(const String& name)
|
|
||||||
{
|
|
||||||
ScriptVariable::Unregister(name);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif /* SCRIPTGLOBAL_H */
|
|
@ -1,65 +0,0 @@
|
||||||
/******************************************************************************
|
|
||||||
* Icinga 2 *
|
|
||||||
* Copyright (C) 2012-2014 Icinga Development Team (http://www.icinga.org) *
|
|
||||||
* *
|
|
||||||
* This program is free software; you can redistribute it and/or *
|
|
||||||
* modify it under the terms of the GNU General Public License *
|
|
||||||
* as published by the Free Software Foundation; either version 2 *
|
|
||||||
* of the License, or (at your option) any later version. *
|
|
||||||
* *
|
|
||||||
* This program is distributed in the hope that it will be useful, *
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
||||||
* GNU General Public License for more details. *
|
|
||||||
* *
|
|
||||||
* You should have received a copy of the GNU General Public License *
|
|
||||||
* along with this program; if not, write to the Free Software Foundation *
|
|
||||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
|
|
||||||
******************************************************************************/
|
|
||||||
|
|
||||||
#ifndef SCRIPTSIGNAL_H
|
|
||||||
#define SCRIPTSIGNAL_H
|
|
||||||
|
|
||||||
#include "base/i2-base.hpp"
|
|
||||||
#include "base/value.hpp"
|
|
||||||
#include <vector>
|
|
||||||
#include <boost/function.hpp>
|
|
||||||
|
|
||||||
namespace icinga
|
|
||||||
{
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A signal that can be subscribed to by scripts.
|
|
||||||
*
|
|
||||||
* @ingroup base
|
|
||||||
*/
|
|
||||||
class I2_BASE_API ScriptSignal : public Object
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
DECLARE_PTR_TYPEDEFS(ScriptSignal);
|
|
||||||
|
|
||||||
typedef boost::function<void (const std::vector<Value>& arguments)> Callback;
|
|
||||||
|
|
||||||
void AddSlot(const Callback& slot);
|
|
||||||
void Invoke(const std::vector<Value>& arguments = std::vector<Value>());
|
|
||||||
|
|
||||||
static ScriptSignal::Ptr GetByName(const String& name);
|
|
||||||
static void Register(const String& name, const ScriptSignal::Ptr& signal);
|
|
||||||
static void Unregister(const String& name);
|
|
||||||
|
|
||||||
private:
|
|
||||||
std::vector<Callback> m_Slots;
|
|
||||||
};
|
|
||||||
|
|
||||||
#define REGISTER_SCRIPTSIGNAL(name) \
|
|
||||||
namespace { namespace UNIQUE_NAME(sig) { namespace sig ## name { \
|
|
||||||
void RegisterSignal(void) { \
|
|
||||||
ScriptSignal::Ptr sig = new icinga::ScriptSignal(); \
|
|
||||||
ScriptSignal::Register(#name, sig); \
|
|
||||||
} \
|
|
||||||
INITIALIZE_ONCE(RegisterSignal); \
|
|
||||||
} } }
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif /* SCRIPTSIGNAL_H */
|
|
|
@ -1,71 +0,0 @@
|
||||||
/******************************************************************************
|
|
||||||
* Icinga 2 *
|
|
||||||
* Copyright (C) 2012-2014 Icinga Development Team (http://www.icinga.org) *
|
|
||||||
* *
|
|
||||||
* This program is free software; you can redistribute it and/or *
|
|
||||||
* modify it under the terms of the GNU General Public License *
|
|
||||||
* as published by the Free Software Foundation; either version 2 *
|
|
||||||
* of the License, or (at your option) any later version. *
|
|
||||||
* *
|
|
||||||
* This program is distributed in the hope that it will be useful, *
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
||||||
* GNU General Public License for more details. *
|
|
||||||
* *
|
|
||||||
* You should have received a copy of the GNU General Public License *
|
|
||||||
* along with this program; if not, write to the Free Software Foundation *
|
|
||||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
|
|
||||||
******************************************************************************/
|
|
||||||
|
|
||||||
#ifndef SCRIPTVARIABLE_H
|
|
||||||
#define SCRIPTVARIABLE_H
|
|
||||||
|
|
||||||
#include "base/i2-base.hpp"
|
|
||||||
#include "base/registry.hpp"
|
|
||||||
#include "base/value.hpp"
|
|
||||||
|
|
||||||
namespace icinga
|
|
||||||
{
|
|
||||||
|
|
||||||
class ScriptVariable;
|
|
||||||
|
|
||||||
class I2_BASE_API ScriptVariableRegistry : public Registry<ScriptVariableRegistry, intrusive_ptr<ScriptVariable> >
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
static ScriptVariableRegistry *GetInstance(void);
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A script variables.
|
|
||||||
*
|
|
||||||
* @ingroup base
|
|
||||||
*/
|
|
||||||
class I2_BASE_API ScriptVariable : public Object
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
DECLARE_PTR_TYPEDEFS(ScriptVariable);
|
|
||||||
|
|
||||||
ScriptVariable(const Value& data);
|
|
||||||
|
|
||||||
void SetConstant(bool constant);
|
|
||||||
bool IsConstant(void) const;
|
|
||||||
|
|
||||||
void SetData(const Value& data);
|
|
||||||
Value GetData(void) const;
|
|
||||||
|
|
||||||
static ScriptVariable::Ptr GetByName(const String& name);
|
|
||||||
static void Unregister(const String& name);
|
|
||||||
|
|
||||||
static Value Get(const String& name, const Value *defaultValue = NULL);
|
|
||||||
static ScriptVariable::Ptr Set(const String& name, const Value& value, bool overwrite = true, bool make_const = false);
|
|
||||||
|
|
||||||
static void WriteVariablesFile(const String& filename);
|
|
||||||
|
|
||||||
private:
|
|
||||||
Value m_Data;
|
|
||||||
bool m_Constant;
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif /* SCRIPTVARIABLE_H */
|
|
|
@ -18,7 +18,7 @@
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
|
|
||||||
#include "base/type.hpp"
|
#include "base/type.hpp"
|
||||||
#include "base/scriptvariable.hpp"
|
#include "base/scriptglobal.hpp"
|
||||||
|
|
||||||
using namespace icinga;
|
using namespace icinga;
|
||||||
|
|
||||||
|
@ -31,17 +31,12 @@ void Type::Register(const Type::Ptr& type)
|
||||||
{
|
{
|
||||||
VERIFY(GetByName(type->GetName()) == NULL);
|
VERIFY(GetByName(type->GetName()) == NULL);
|
||||||
|
|
||||||
ScriptVariable::Set(type->GetName(), type, true, true);
|
ScriptGlobal::Set(type->GetName(), type);
|
||||||
}
|
}
|
||||||
|
|
||||||
Type::Ptr Type::GetByName(const String& name)
|
Type::Ptr Type::GetByName(const String& name)
|
||||||
{
|
{
|
||||||
ScriptVariable::Ptr svtype = ScriptVariable::GetByName(name);
|
Value ptype = ScriptGlobal::Get(name, &Empty);
|
||||||
|
|
||||||
if (!svtype)
|
|
||||||
return Type::Ptr();
|
|
||||||
|
|
||||||
Value ptype = svtype->GetData();
|
|
||||||
|
|
||||||
if (!ptype.IsObjectType<Type>())
|
if (!ptype.IsObjectType<Type>())
|
||||||
return Type::Ptr();
|
return Type::Ptr();
|
||||||
|
|
|
@ -28,9 +28,8 @@
|
||||||
#include "base/utility.hpp"
|
#include "base/utility.hpp"
|
||||||
#include "base/exception.hpp"
|
#include "base/exception.hpp"
|
||||||
#include "base/convert.hpp"
|
#include "base/convert.hpp"
|
||||||
#include "base/scriptvariable.hpp"
|
#include "base/scriptglobal.hpp"
|
||||||
#include "base/context.hpp"
|
#include "base/context.hpp"
|
||||||
#include "base/scriptsignal.hpp"
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include <boost/program_options.hpp>
|
#include <boost/program_options.hpp>
|
||||||
#include <boost/tuple/tuple.hpp>
|
#include <boost/tuple/tuple.hpp>
|
||||||
|
@ -43,7 +42,6 @@ namespace po = boost::program_options;
|
||||||
static po::variables_map g_AppParams;
|
static po::variables_map g_AppParams;
|
||||||
|
|
||||||
REGISTER_CLICOMMAND("daemon", DaemonCommand);
|
REGISTER_CLICOMMAND("daemon", DaemonCommand);
|
||||||
REGISTER_SCRIPTSIGNAL(onload);
|
|
||||||
|
|
||||||
static String LoadAppType(const String& typeSpec)
|
static String LoadAppType(const String& typeSpec)
|
||||||
{
|
{
|
||||||
|
@ -182,10 +180,7 @@ static bool LoadConfigFiles(const boost::program_options::variables_map& vm, con
|
||||||
|
|
||||||
ConfigCompilerContext::GetInstance()->FinishObjectsFile();
|
ConfigCompilerContext::GetInstance()->FinishObjectsFile();
|
||||||
|
|
||||||
ScriptVariable::WriteVariablesFile(varsfile);
|
ScriptGlobal::WriteToFile(varsfile);
|
||||||
|
|
||||||
ScriptSignal::Ptr loadSignal = ScriptSignal::GetByName("onload");
|
|
||||||
loadSignal->Invoke();
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -355,9 +350,7 @@ int DaemonCommand::Run(const po::variables_map& vm, const std::vector<std::strin
|
||||||
if (!vm.count("validate"))
|
if (!vm.count("validate"))
|
||||||
Logger::DisableTimestamp(false);
|
Logger::DisableTimestamp(false);
|
||||||
|
|
||||||
ScriptVariable::Set("UseVfork", true, false, true);
|
ScriptGlobal::Set("UseVfork", true);
|
||||||
|
|
||||||
Application::MakeVariablesConstant();
|
|
||||||
|
|
||||||
Log(LogInformation, "cli")
|
Log(LogInformation, "cli")
|
||||||
<< "Icinga application loader (version: " << Application::GetVersion()
|
<< "Icinga application loader (version: " << Application::GetVersion()
|
||||||
|
|
|
@ -25,7 +25,7 @@
|
||||||
#include "base/console.hpp"
|
#include "base/console.hpp"
|
||||||
#include "base/application.hpp"
|
#include "base/application.hpp"
|
||||||
#include "base/tlsutility.hpp"
|
#include "base/tlsutility.hpp"
|
||||||
#include "base/scriptvariable.hpp"
|
#include "base/scriptglobal.hpp"
|
||||||
#include <boost/foreach.hpp>
|
#include <boost/foreach.hpp>
|
||||||
#include <boost/algorithm/string/classification.hpp>
|
#include <boost/algorithm/string/classification.hpp>
|
||||||
#include <boost/algorithm/string/join.hpp>
|
#include <boost/algorithm/string/join.hpp>
|
||||||
|
@ -133,8 +133,8 @@ int NodeSetupCommand::SetupMaster(const boost::program_options::variables_map& v
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
String user = ScriptVariable::Get("RunAsUser");
|
String user = ScriptGlobal::Get("RunAsUser");
|
||||||
String group = ScriptVariable::Get("RunAsGroup");
|
String group = ScriptGlobal::Get("RunAsGroup");
|
||||||
|
|
||||||
if (!Utility::SetFileOwnership(pki_path, user, group)) {
|
if (!Utility::SetFileOwnership(pki_path, user, group)) {
|
||||||
Log(LogWarning, "cli")
|
Log(LogWarning, "cli")
|
||||||
|
@ -374,8 +374,8 @@ int NodeSetupCommand::SetupNode(const boost::program_options::variables_map& vm,
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
String user = ScriptVariable::Get("RunAsUser");
|
String user = ScriptGlobal::Get("RunAsUser");
|
||||||
String group = ScriptVariable::Get("RunAsGroup");
|
String group = ScriptGlobal::Get("RunAsGroup");
|
||||||
|
|
||||||
if (!Utility::SetFileOwnership(pki_path, user, group)) {
|
if (!Utility::SetFileOwnership(pki_path, user, group)) {
|
||||||
Log(LogWarning, "cli")
|
Log(LogWarning, "cli")
|
||||||
|
|
|
@ -24,7 +24,6 @@
|
||||||
#include "base/console.hpp"
|
#include "base/console.hpp"
|
||||||
#include "base/application.hpp"
|
#include "base/application.hpp"
|
||||||
#include "base/tlsutility.hpp"
|
#include "base/tlsutility.hpp"
|
||||||
#include "base/scriptvariable.hpp"
|
|
||||||
#include "base/json.hpp"
|
#include "base/json.hpp"
|
||||||
#include "base/objectlock.hpp"
|
#include "base/objectlock.hpp"
|
||||||
#include <boost/foreach.hpp>
|
#include <boost/foreach.hpp>
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
#include "base/tlsutility.hpp"
|
#include "base/tlsutility.hpp"
|
||||||
#include "base/convert.hpp"
|
#include "base/convert.hpp"
|
||||||
#include "base/utility.hpp"
|
#include "base/utility.hpp"
|
||||||
#include "base/scriptvariable.hpp"
|
#include "base/scriptglobal.hpp"
|
||||||
#include "base/json.hpp"
|
#include "base/json.hpp"
|
||||||
#include "base/netstring.hpp"
|
#include "base/netstring.hpp"
|
||||||
#include "base/stdiostream.hpp"
|
#include "base/stdiostream.hpp"
|
||||||
|
@ -61,8 +61,8 @@ void NodeUtility::CreateRepositoryPath(const String& path)
|
||||||
if (!Utility::PathExists(path))
|
if (!Utility::PathExists(path))
|
||||||
Utility::MkDirP(path, 0750);
|
Utility::MkDirP(path, 0750);
|
||||||
|
|
||||||
String user = ScriptVariable::Get("RunAsUser");
|
String user = ScriptGlobal::Get("RunAsUser");
|
||||||
String group = ScriptVariable::Get("RunAsGroup");
|
String group = ScriptGlobal::Get("RunAsGroup");
|
||||||
|
|
||||||
if (!Utility::SetFileOwnership(path, user, group)) {
|
if (!Utility::SetFileOwnership(path, user, group)) {
|
||||||
Log(LogWarning, "cli")
|
Log(LogWarning, "cli")
|
||||||
|
@ -374,8 +374,8 @@ bool NodeUtility::WriteNodeConfigObjects(const String& filename, const Array::Pt
|
||||||
|
|
||||||
Utility::MkDirP(path, 0755);
|
Utility::MkDirP(path, 0755);
|
||||||
|
|
||||||
String user = ScriptVariable::Get("RunAsUser");
|
String user = ScriptGlobal::Get("RunAsUser");
|
||||||
String group = ScriptVariable::Get("RunAsGroup");
|
String group = ScriptGlobal::Get("RunAsGroup");
|
||||||
|
|
||||||
if (!Utility::SetFileOwnership(path, user, group)) {
|
if (!Utility::SetFileOwnership(path, user, group)) {
|
||||||
Log(LogWarning, "cli")
|
Log(LogWarning, "cli")
|
||||||
|
|
|
@ -25,7 +25,7 @@
|
||||||
#include "base/console.hpp"
|
#include "base/console.hpp"
|
||||||
#include "base/application.hpp"
|
#include "base/application.hpp"
|
||||||
#include "base/tlsutility.hpp"
|
#include "base/tlsutility.hpp"
|
||||||
#include "base/scriptvariable.hpp"
|
#include "base/scriptglobal.hpp"
|
||||||
#include <boost/foreach.hpp>
|
#include <boost/foreach.hpp>
|
||||||
#include <boost/algorithm/string/join.hpp>
|
#include <boost/algorithm/string/join.hpp>
|
||||||
#include <boost/algorithm/string/replace.hpp>
|
#include <boost/algorithm/string/replace.hpp>
|
||||||
|
@ -233,8 +233,8 @@ wizard_master_host:
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
String user = ScriptVariable::Get("RunAsUser");
|
String user = ScriptGlobal::Get("RunAsUser");
|
||||||
String group = ScriptVariable::Get("RunAsGroup");
|
String group = ScriptGlobal::Get("RunAsGroup");
|
||||||
|
|
||||||
if (!Utility::SetFileOwnership(pki_path, user, group)) {
|
if (!Utility::SetFileOwnership(pki_path, user, group)) {
|
||||||
Log(LogWarning, "cli")
|
Log(LogWarning, "cli")
|
||||||
|
@ -418,8 +418,8 @@ wizard_ticket:
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
String user = ScriptVariable::Get("RunAsUser");
|
String user = ScriptGlobal::Get("RunAsUser");
|
||||||
String group = ScriptVariable::Get("RunAsGroup");
|
String group = ScriptGlobal::Get("RunAsGroup");
|
||||||
|
|
||||||
if (!Utility::SetFileOwnership(pki_path, user, group)) {
|
if (!Utility::SetFileOwnership(pki_path, user, group)) {
|
||||||
Log(LogWarning, "cli")
|
Log(LogWarning, "cli")
|
||||||
|
|
|
@ -25,7 +25,7 @@
|
||||||
#include "base/logger.hpp"
|
#include "base/logger.hpp"
|
||||||
#include "base/application.hpp"
|
#include "base/application.hpp"
|
||||||
#include "base/convert.hpp"
|
#include "base/convert.hpp"
|
||||||
#include "base/scriptvariable.hpp"
|
#include "base/scriptglobal.hpp"
|
||||||
#include "base/json.hpp"
|
#include "base/json.hpp"
|
||||||
#include "base/netstring.hpp"
|
#include "base/netstring.hpp"
|
||||||
#include "base/tlsutility.hpp"
|
#include "base/tlsutility.hpp"
|
||||||
|
@ -131,8 +131,8 @@ void RepositoryUtility::CreateRepositoryPath(const String& path)
|
||||||
if (!Utility::PathExists(path))
|
if (!Utility::PathExists(path))
|
||||||
Utility::MkDirP(path, 0750);
|
Utility::MkDirP(path, 0750);
|
||||||
|
|
||||||
String user = ScriptVariable::Get("RunAsUser");
|
String user = ScriptGlobal::Get("RunAsUser");
|
||||||
String group = ScriptVariable::Get("RunAsGroup");
|
String group = ScriptGlobal::Get("RunAsGroup");
|
||||||
|
|
||||||
if (!Utility::SetFileOwnership(path, user, group)) {
|
if (!Utility::SetFileOwnership(path, user, group)) {
|
||||||
Log(LogWarning, "cli")
|
Log(LogWarning, "cli")
|
||||||
|
|
|
@ -30,7 +30,7 @@
|
||||||
#include "base/debug.hpp"
|
#include "base/debug.hpp"
|
||||||
#include "base/objectlock.hpp"
|
#include "base/objectlock.hpp"
|
||||||
#include "base/console.hpp"
|
#include "base/console.hpp"
|
||||||
#include "base/scriptvariable.hpp"
|
#include "base/scriptglobal.hpp"
|
||||||
#include <boost/foreach.hpp>
|
#include <boost/foreach.hpp>
|
||||||
#include <boost/algorithm/string/join.hpp>
|
#include <boost/algorithm/string/join.hpp>
|
||||||
#include <boost/algorithm/string/replace.hpp>
|
#include <boost/algorithm/string/replace.hpp>
|
||||||
|
@ -72,7 +72,7 @@ int VariableGetCommand::GetMinArguments(void) const
|
||||||
int VariableGetCommand::Run(const boost::program_options::variables_map& vm, const std::vector<std::string>& ap) const
|
int VariableGetCommand::Run(const boost::program_options::variables_map& vm, const std::vector<std::string>& ap) const
|
||||||
{
|
{
|
||||||
if (vm.count("current")) {
|
if (vm.count("current")) {
|
||||||
std::cout << ScriptVariable::Get(ap[0], &Empty) << "\n";
|
std::cout << ScriptGlobal::Get(ap[0], &Empty) << "\n";
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,7 @@ using namespace icinga;
|
||||||
#include "config/config_parser.hh"
|
#include "config/config_parser.hh"
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
#define YYLTYPE icinga::DebugInfo
|
#define YYLTYPE icinga::CompilerDebugInfo
|
||||||
|
|
||||||
#define YY_EXTRA_TYPE ConfigCompiler *
|
#define YY_EXTRA_TYPE ConfigCompiler *
|
||||||
#define YY_USER_ACTION \
|
#define YY_USER_ACTION \
|
||||||
|
@ -177,8 +177,9 @@ library return T_LIBRARY;
|
||||||
null return T_NULL;
|
null return T_NULL;
|
||||||
true { yylval->boolean = 1; return T_BOOLEAN; }
|
true { yylval->boolean = 1; return T_BOOLEAN; }
|
||||||
false { yylval->boolean = 0; return T_BOOLEAN; }
|
false { yylval->boolean = 0; return T_BOOLEAN; }
|
||||||
const return T_CONST;
|
const return T_GLOBAL;
|
||||||
local return T_LOCAL;
|
local return T_LOCAL;
|
||||||
|
this return T_THIS;
|
||||||
global return T_GLOBAL;
|
global return T_GLOBAL;
|
||||||
use return T_USE;
|
use return T_USE;
|
||||||
apply return T_APPLY;
|
apply return T_APPLY;
|
||||||
|
@ -190,7 +191,6 @@ ignore return T_IGNORE;
|
||||||
function return T_FUNCTION;
|
function return T_FUNCTION;
|
||||||
return return T_RETURN;
|
return return T_RETURN;
|
||||||
for return T_FOR;
|
for return T_FOR;
|
||||||
signal return T_SIGNAL;
|
|
||||||
if return T_IF;
|
if return T_IF;
|
||||||
else return T_ELSE;
|
else return T_ELSE;
|
||||||
=\> return T_FOLLOWS;
|
=\> return T_FOLLOWS;
|
||||||
|
|
|
@ -31,7 +31,6 @@
|
||||||
#include "config/objectrule.hpp"
|
#include "config/objectrule.hpp"
|
||||||
#include "base/value.hpp"
|
#include "base/value.hpp"
|
||||||
#include "base/utility.hpp"
|
#include "base/utility.hpp"
|
||||||
#include "base/scriptvariable.hpp"
|
|
||||||
#include "base/exception.hpp"
|
#include "base/exception.hpp"
|
||||||
#include "base/dynamictype.hpp"
|
#include "base/dynamictype.hpp"
|
||||||
#include "base/scripterror.hpp"
|
#include "base/scripterror.hpp"
|
||||||
|
@ -39,7 +38,7 @@
|
||||||
#include <stack>
|
#include <stack>
|
||||||
#include <boost/foreach.hpp>
|
#include <boost/foreach.hpp>
|
||||||
|
|
||||||
#define YYLTYPE icinga::DebugInfo
|
#define YYLTYPE icinga::CompilerDebugInfo
|
||||||
#define YYERROR_VERBOSE
|
#define YYERROR_VERBOSE
|
||||||
|
|
||||||
#define YYLLOC_DEFAULT(Current, Rhs, N) \
|
#define YYLLOC_DEFAULT(Current, Rhs, N) \
|
||||||
|
@ -70,7 +69,7 @@ do { \
|
||||||
using namespace icinga;
|
using namespace icinga;
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
static void MakeRBinaryOp(Expression** result, Expression *left, Expression *right, DebugInfo& diLeft, DebugInfo& diRight)
|
static void MakeRBinaryOp(Expression** result, Expression *left, Expression *right, const DebugInfo& diLeft, const DebugInfo& diRight)
|
||||||
{
|
{
|
||||||
*result = new T(left, right, DebugInfoRange(diLeft, diRight));
|
*result = new T(left, right, DebugInfoRange(diLeft, diRight));
|
||||||
}
|
}
|
||||||
|
@ -82,6 +81,7 @@ static void MakeRBinaryOp(Expression** result, Expression *left, Expression *rig
|
||||||
%locations
|
%locations
|
||||||
%defines
|
%defines
|
||||||
%error-verbose
|
%error-verbose
|
||||||
|
%glr-parser
|
||||||
|
|
||||||
%parse-param { std::vector<Expression *> *elist }
|
%parse-param { std::vector<Expression *> *elist }
|
||||||
%parse-param { ConfigCompiler *context }
|
%parse-param { ConfigCompiler *context }
|
||||||
|
@ -170,7 +170,6 @@ static void MakeRBinaryOp(Expression** result, Expression *left, Expression *rig
|
||||||
%token T_FUNCTION "function (T_FUNCTION)"
|
%token T_FUNCTION "function (T_FUNCTION)"
|
||||||
%token T_RETURN "return (T_RETURN)"
|
%token T_RETURN "return (T_RETURN)"
|
||||||
%token T_FOR "for (T_FOR)"
|
%token T_FOR "for (T_FOR)"
|
||||||
%token T_SIGNAL "signal (T_SIGNAL)"
|
|
||||||
%token T_IF "if (T_IF)"
|
%token T_IF "if (T_IF)"
|
||||||
%token T_ELSE "else (T_ELSE)"
|
%token T_ELSE "else (T_ELSE)"
|
||||||
%token T_FOLLOWS "=> (T_FOLLOWS)"
|
%token T_FOLLOWS "=> (T_FOLLOWS)"
|
||||||
|
@ -180,9 +179,6 @@ static void MakeRBinaryOp(Expression** result, Expression *left, Expression *rig
|
||||||
%type <elist> rterm_items_inner
|
%type <elist> rterm_items_inner
|
||||||
%type <slist> identifier_items
|
%type <slist> identifier_items
|
||||||
%type <slist> identifier_items_inner
|
%type <slist> identifier_items_inner
|
||||||
%type <elist> indexer
|
|
||||||
%type <elist> indexer_items
|
|
||||||
%type <expr> indexer_item
|
|
||||||
%type <variant> typerulelist
|
%type <variant> typerulelist
|
||||||
%type <csop> combined_set_op
|
%type <csop> combined_set_op
|
||||||
%type <type> type
|
%type <type> type
|
||||||
|
@ -190,7 +186,6 @@ static void MakeRBinaryOp(Expression** result, Expression *left, Expression *rig
|
||||||
%type <elist> lterm_items
|
%type <elist> lterm_items
|
||||||
%type <elist> lterm_items_inner
|
%type <elist> lterm_items_inner
|
||||||
%type <expr> rterm
|
%type <expr> rterm
|
||||||
%type <expr> rterm_without_indexer
|
|
||||||
%type <expr> rterm_array
|
%type <expr> rterm_array
|
||||||
%type <expr> rterm_scope
|
%type <expr> rterm_scope
|
||||||
%type <expr> lterm
|
%type <expr> lterm
|
||||||
|
@ -206,10 +201,10 @@ static void MakeRBinaryOp(Expression** result, Expression *left, Expression *rig
|
||||||
|
|
||||||
%right T_FOLLOWS
|
%right T_FOLLOWS
|
||||||
%right T_INCLUDE T_INCLUDE_RECURSIVE T_OBJECT T_TEMPLATE T_APPLY T_IMPORT T_ASSIGN T_IGNORE T_WHERE
|
%right T_INCLUDE T_INCLUDE_RECURSIVE T_OBJECT T_TEMPLATE T_APPLY T_IMPORT T_ASSIGN T_IGNORE T_WHERE
|
||||||
%right T_FUNCTION T_SIGNAL T_FOR
|
%right T_FUNCTION T_FOR
|
||||||
%left T_LOGICAL_OR
|
%left T_LOGICAL_OR
|
||||||
%left T_LOGICAL_AND
|
%left T_LOGICAL_AND
|
||||||
%left T_GLOBAL T_LOCAL T_RETURN
|
%left T_RETURN
|
||||||
%left T_IDENTIFIER
|
%left T_IDENTIFIER
|
||||||
%left T_SET T_SET_ADD T_SET_SUBTRACT T_SET_MULTIPLY T_SET_DIVIDE T_SET_MODULO T_SET_XOR T_SET_BINARY_AND T_SET_BINARY_OR
|
%left T_SET T_SET_ADD T_SET_SUBTRACT T_SET_MULTIPLY T_SET_DIVIDE T_SET_MODULO T_SET_XOR T_SET_BINARY_AND T_SET_BINARY_OR
|
||||||
%nonassoc T_EQUAL T_NOT_EQUAL
|
%nonassoc T_EQUAL T_NOT_EQUAL
|
||||||
|
@ -224,12 +219,15 @@ static void MakeRBinaryOp(Expression** result, Expression *left, Expression *rig
|
||||||
%left UNARY_MINUS
|
%left UNARY_MINUS
|
||||||
%right '!' '~'
|
%right '!' '~'
|
||||||
%left '.' '(' '['
|
%left '.' '(' '['
|
||||||
|
%left T_LOCAL T_GLOBAL T_THIS
|
||||||
%right ';' ','
|
%right ';' ','
|
||||||
%right T_NEWLINE
|
%right T_NEWLINE
|
||||||
%{
|
%{
|
||||||
|
|
||||||
int yylex(YYSTYPE *lvalp, YYLTYPE *llocp, void *scanner);
|
int yylex(YYSTYPE *lvalp, YYLTYPE *llocp, void *scanner);
|
||||||
|
|
||||||
|
extern int yydebug;
|
||||||
|
|
||||||
void yyerror(YYLTYPE *locp, std::vector<Expression *> *, ConfigCompiler *, const char *err)
|
void yyerror(YYLTYPE *locp, std::vector<Expression *> *, ConfigCompiler *, const char *err)
|
||||||
{
|
{
|
||||||
BOOST_THROW_EXCEPTION(ScriptError(err, *locp));
|
BOOST_THROW_EXCEPTION(ScriptError(err, *locp));
|
||||||
|
@ -241,6 +239,8 @@ Expression *ConfigCompiler::Compile(void)
|
||||||
{
|
{
|
||||||
std::vector<Expression *> elist;
|
std::vector<Expression *> elist;
|
||||||
|
|
||||||
|
//yydebug = 1;
|
||||||
|
|
||||||
if (yyparse(&elist, this) != 0)
|
if (yyparse(&elist, this) != 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
@ -261,18 +261,10 @@ script: statements
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
statements: newlines lterm_items newlines
|
statements: newlines lterm_items
|
||||||
{
|
{
|
||||||
$$ = $2;
|
$$ = $2;
|
||||||
}
|
}
|
||||||
| newlines lterm_items
|
|
||||||
{
|
|
||||||
$$ = $2;
|
|
||||||
}
|
|
||||||
| lterm_items newlines
|
|
||||||
{
|
|
||||||
$$ = $1;
|
|
||||||
}
|
|
||||||
| lterm_items
|
| lterm_items
|
||||||
{
|
{
|
||||||
$$ = $1;
|
$$ = $1;
|
||||||
|
@ -287,7 +279,23 @@ lterm_items: /* empty */
|
||||||
{
|
{
|
||||||
$$ = $1;
|
$$ = $1;
|
||||||
}
|
}
|
||||||
| lterm_items_inner sep
|
| lterm_items_inner ','
|
||||||
|
{
|
||||||
|
$$ = $1;
|
||||||
|
}
|
||||||
|
| lterm_items_inner ',' newlines
|
||||||
|
{
|
||||||
|
$$ = $1;
|
||||||
|
}
|
||||||
|
| lterm_items_inner ';'
|
||||||
|
{
|
||||||
|
$$ = $1;
|
||||||
|
}
|
||||||
|
| lterm_items_inner ';' newlines
|
||||||
|
{
|
||||||
|
$$ = $1;
|
||||||
|
}
|
||||||
|
| lterm_items_inner newlines
|
||||||
{
|
{
|
||||||
$$ = $1;
|
$$ = $1;
|
||||||
}
|
}
|
||||||
|
@ -317,17 +325,6 @@ library: T_LIBRARY T_STRING
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
constant: T_CONST identifier T_SET rterm
|
|
||||||
{
|
|
||||||
ScriptFrame frame;
|
|
||||||
ScriptVariable::Ptr sv = ScriptVariable::Set($2, $4->Evaluate(frame));
|
|
||||||
free($2);
|
|
||||||
delete $4;
|
|
||||||
|
|
||||||
sv->SetConstant(true);
|
|
||||||
}
|
|
||||||
;
|
|
||||||
|
|
||||||
identifier: T_IDENTIFIER
|
identifier: T_IDENTIFIER
|
||||||
| T_STRING
|
| T_STRING
|
||||||
{
|
{
|
||||||
|
@ -491,7 +488,11 @@ object_declaration: T_OBJECT
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
identifier_items: identifier_items_inner
|
identifier_items: /* empty */
|
||||||
|
{
|
||||||
|
$$ = new std::vector<String>();
|
||||||
|
}
|
||||||
|
| identifier_items_inner
|
||||||
{
|
{
|
||||||
$$ = $1;
|
$$ = $1;
|
||||||
}
|
}
|
||||||
|
@ -501,11 +502,7 @@ identifier_items: identifier_items_inner
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
identifier_items_inner: /* empty */
|
identifier_items_inner: identifier
|
||||||
{
|
|
||||||
$$ = new std::vector<String>();
|
|
||||||
}
|
|
||||||
| identifier
|
|
||||||
{
|
{
|
||||||
$$ = new std::vector<String>();
|
$$ = new std::vector<String>();
|
||||||
$$->push_back($1);
|
$$->push_back($1);
|
||||||
|
@ -523,46 +520,6 @@ identifier_items_inner: /* empty */
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
indexer: rterm_without_indexer indexer_items
|
|
||||||
{
|
|
||||||
$$ = $2;
|
|
||||||
$$->insert($$->begin(), $1);
|
|
||||||
}
|
|
||||||
;
|
|
||||||
|
|
||||||
indexer_items: indexer_item
|
|
||||||
{
|
|
||||||
$$ = new std::vector<Expression *>();
|
|
||||||
$$->push_back($1);
|
|
||||||
}
|
|
||||||
| indexer_items indexer_item
|
|
||||||
{
|
|
||||||
$$ = $1;
|
|
||||||
$$->push_back($2);
|
|
||||||
}
|
|
||||||
;
|
|
||||||
|
|
||||||
indexer_item: '.' identifier
|
|
||||||
{
|
|
||||||
$$ = MakeLiteral($2);
|
|
||||||
free($2);
|
|
||||||
}
|
|
||||||
| '[' rterm ']'
|
|
||||||
{
|
|
||||||
$$ = $2;
|
|
||||||
}
|
|
||||||
;
|
|
||||||
|
|
||||||
scope_specifier: T_LOCAL
|
|
||||||
{
|
|
||||||
$$ = ScopeLocal;
|
|
||||||
}
|
|
||||||
| T_GLOBAL
|
|
||||||
{
|
|
||||||
$$ = ScopeGlobal;
|
|
||||||
}
|
|
||||||
;
|
|
||||||
|
|
||||||
combined_set_op: T_SET
|
combined_set_op: T_SET
|
||||||
| T_SET_ADD
|
| T_SET_ADD
|
||||||
| T_SET_SUBTRACT
|
| T_SET_SUBTRACT
|
||||||
|
@ -577,6 +534,20 @@ combined_set_op: T_SET
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
|
scope_specifier: T_LOCAL
|
||||||
|
{
|
||||||
|
$$ = ScopeLocal;
|
||||||
|
}
|
||||||
|
| T_GLOBAL
|
||||||
|
{
|
||||||
|
$$ = ScopeGlobal;
|
||||||
|
}
|
||||||
|
| T_THIS
|
||||||
|
{
|
||||||
|
$$ = ScopeThis;
|
||||||
|
}
|
||||||
|
;
|
||||||
|
|
||||||
lterm: type
|
lterm: type
|
||||||
{
|
{
|
||||||
$$ = MakeLiteral(); // ASTify this
|
$$ = MakeLiteral(); // ASTify this
|
||||||
|
@ -585,29 +556,11 @@ lterm: type
|
||||||
{
|
{
|
||||||
$$ = MakeLiteral(); // ASTify this
|
$$ = MakeLiteral(); // ASTify this
|
||||||
}
|
}
|
||||||
| constant
|
| rterm combined_set_op rterm
|
||||||
{
|
{
|
||||||
$$ = MakeLiteral(); // ASTify this
|
Expression *expr = $1;
|
||||||
}
|
BindToScope(expr, ScopeCurrent);
|
||||||
| indexer combined_set_op rterm
|
$$ = new SetExpression(expr, $2, $3, DebugInfoRange(@1, @3));
|
||||||
{
|
|
||||||
$$ = new SetExpression(ScopeCurrent, *$1, $2, $3, DebugInfoRange(@1, @3));
|
|
||||||
delete $1;
|
|
||||||
}
|
|
||||||
| identifier combined_set_op rterm
|
|
||||||
{
|
|
||||||
$$ = new SetExpression(ScopeCurrent, MakeIndexer($1), $2, $3, DebugInfoRange(@1, @3));
|
|
||||||
free($1);
|
|
||||||
}
|
|
||||||
| scope_specifier indexer combined_set_op rterm
|
|
||||||
{
|
|
||||||
$$ = new SetExpression($1, *$2, $3, $4, DebugInfoRange(@1, @4));
|
|
||||||
delete $2;
|
|
||||||
}
|
|
||||||
| scope_specifier identifier combined_set_op rterm
|
|
||||||
{
|
|
||||||
$$ = new SetExpression($1, MakeIndexer($2), $3, $4, DebugInfoRange(@1, @4));
|
|
||||||
free($2);
|
|
||||||
}
|
}
|
||||||
| T_INCLUDE T_STRING
|
| T_INCLUDE T_STRING
|
||||||
{
|
{
|
||||||
|
@ -672,11 +625,6 @@ lterm: type
|
||||||
{
|
{
|
||||||
$$ = $1;
|
$$ = $1;
|
||||||
}
|
}
|
||||||
| T_SIGNAL identifier T_SET_ADD rterm
|
|
||||||
{
|
|
||||||
$$ = new SlotExpression($2, $4, DebugInfoRange(@1, @4));
|
|
||||||
free($2);
|
|
||||||
}
|
|
||||||
| T_FOR '(' identifier T_FOLLOWS identifier T_IN rterm ')' rterm_scope
|
| T_FOR '(' identifier T_FOLLOWS identifier T_IN rterm ')' rterm_scope
|
||||||
{
|
{
|
||||||
DictExpression *aexpr = dynamic_cast<DictExpression *>($9);
|
DictExpression *aexpr = dynamic_cast<DictExpression *>($9);
|
||||||
|
@ -719,7 +667,7 @@ lterm: type
|
||||||
FunctionExpression *fexpr = new FunctionExpression(*$4, $6, aexpr, DebugInfoRange(@1, @7));
|
FunctionExpression *fexpr = new FunctionExpression(*$4, $6, aexpr, DebugInfoRange(@1, @7));
|
||||||
delete $4;
|
delete $4;
|
||||||
|
|
||||||
$$ = new SetExpression(ScopeCurrent, MakeIndexer($2), OpSetLiteral, fexpr, DebugInfoRange(@1, @7));
|
$$ = new SetExpression(MakeIndexer(ScopeCurrent, $2), OpSetLiteral, fexpr, DebugInfoRange(@1, @7));
|
||||||
free($2);
|
free($2);
|
||||||
}
|
}
|
||||||
| scope_specifier T_FUNCTION identifier '(' identifier_items ')' use_specifier rterm_scope
|
| scope_specifier T_FUNCTION identifier '(' identifier_items ')' use_specifier rterm_scope
|
||||||
|
@ -730,7 +678,7 @@ lterm: type
|
||||||
FunctionExpression *fexpr = new FunctionExpression(*$5, $7, aexpr, DebugInfoRange(@1, @8));
|
FunctionExpression *fexpr = new FunctionExpression(*$5, $7, aexpr, DebugInfoRange(@1, @8));
|
||||||
delete $5;
|
delete $5;
|
||||||
|
|
||||||
$$ = new SetExpression($1, MakeIndexer($3), OpSetLiteral, fexpr, DebugInfoRange(@1, @8));
|
$$ = new SetExpression(MakeIndexer($1, $3), OpSetLiteral, fexpr, DebugInfoRange(@1, @8));
|
||||||
free($3);
|
free($3);
|
||||||
}
|
}
|
||||||
| rterm
|
| rterm
|
||||||
|
@ -747,7 +695,15 @@ rterm_items: /* empty */
|
||||||
{
|
{
|
||||||
$$ = $1;
|
$$ = $1;
|
||||||
}
|
}
|
||||||
| rterm_items_inner arraysep
|
| rterm_items_inner ','
|
||||||
|
{
|
||||||
|
$$ = $1;
|
||||||
|
}
|
||||||
|
| rterm_items_inner ',' newlines
|
||||||
|
{
|
||||||
|
$$ = $1;
|
||||||
|
}
|
||||||
|
| rterm_items_inner newlines
|
||||||
{
|
{
|
||||||
$$ = $1;
|
$$ = $1;
|
||||||
}
|
}
|
||||||
|
@ -765,21 +721,11 @@ rterm_items_inner: rterm
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
rterm_array: '[' newlines rterm_items newlines ']'
|
rterm_array: '[' newlines rterm_items ']'
|
||||||
{
|
|
||||||
$$ = new ArrayExpression(*$3, DebugInfoRange(@1, @5));
|
|
||||||
delete $3;
|
|
||||||
}
|
|
||||||
| '[' newlines rterm_items ']'
|
|
||||||
{
|
{
|
||||||
$$ = new ArrayExpression(*$3, DebugInfoRange(@1, @4));
|
$$ = new ArrayExpression(*$3, DebugInfoRange(@1, @4));
|
||||||
delete $3;
|
delete $3;
|
||||||
}
|
}
|
||||||
| '[' rterm_items newlines ']'
|
|
||||||
{
|
|
||||||
$$ = new ArrayExpression(*$2, DebugInfoRange(@1, @4));
|
|
||||||
delete $2;
|
|
||||||
}
|
|
||||||
| '[' rterm_items ']'
|
| '[' rterm_items ']'
|
||||||
{
|
{
|
||||||
$$ = new ArrayExpression(*$2, DebugInfoRange(@1, @3));
|
$$ = new ArrayExpression(*$2, DebugInfoRange(@1, @3));
|
||||||
|
@ -794,18 +740,7 @@ rterm_scope: '{' statements '}'
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
rterm: rterm_without_indexer
|
rterm: T_STRING
|
||||||
{
|
|
||||||
$$ = $1;
|
|
||||||
}
|
|
||||||
| indexer
|
|
||||||
{
|
|
||||||
$$ = new IndexerExpression(*$1, @1);
|
|
||||||
delete $1;
|
|
||||||
}
|
|
||||||
;
|
|
||||||
|
|
||||||
rterm_without_indexer: T_STRING
|
|
||||||
{
|
{
|
||||||
$$ = MakeLiteral($1);
|
$$ = MakeLiteral($1);
|
||||||
free($1);
|
free($1);
|
||||||
|
@ -822,17 +757,20 @@ rterm_without_indexer: T_STRING
|
||||||
{
|
{
|
||||||
$$ = MakeLiteral();
|
$$ = MakeLiteral();
|
||||||
}
|
}
|
||||||
| indexer '(' rterm_items ')'
|
|
||||||
{
|
|
||||||
$$ = new FunctionCallExpression(*$1, NULL, *$3, DebugInfoRange(@1, @4));
|
|
||||||
delete $1;
|
|
||||||
delete $3;
|
|
||||||
}
|
|
||||||
| rterm '(' rterm_items ')'
|
| rterm '(' rterm_items ')'
|
||||||
{
|
{
|
||||||
$$ = new FunctionCallExpression(MakeIndexer("this"), $1, *$3, DebugInfoRange(@1, @4));
|
$$ = new FunctionCallExpression($1, *$3, DebugInfoRange(@1, @4));
|
||||||
delete $3;
|
delete $3;
|
||||||
}
|
}
|
||||||
|
| rterm '.' T_IDENTIFIER %dprec 2
|
||||||
|
{
|
||||||
|
$$ = new IndexerExpression($1, MakeLiteral($3), DebugInfoRange(@1, @3));
|
||||||
|
free($3);
|
||||||
|
}
|
||||||
|
| rterm '[' rterm ']'
|
||||||
|
{
|
||||||
|
$$ = new IndexerExpression($1, $3, DebugInfoRange(@1, @3));
|
||||||
|
}
|
||||||
| T_IDENTIFIER
|
| T_IDENTIFIER
|
||||||
{
|
{
|
||||||
$$ = new VariableExpression($1, @1);
|
$$ = new VariableExpression($1, @1);
|
||||||
|
@ -850,6 +788,16 @@ rterm_without_indexer: T_STRING
|
||||||
{
|
{
|
||||||
$$ = new SubtractExpression(MakeLiteral(0), $2, DebugInfoRange(@1, @2));
|
$$ = new SubtractExpression(MakeLiteral(0), $2, DebugInfoRange(@1, @2));
|
||||||
}
|
}
|
||||||
|
| scope_specifier
|
||||||
|
{
|
||||||
|
$$ = new GetScopeExpression($1);
|
||||||
|
}
|
||||||
|
| scope_specifier T_IDENTIFIER
|
||||||
|
{
|
||||||
|
Expression *scope = new GetScopeExpression($1);
|
||||||
|
$$ = new IndexerExpression(scope, MakeLiteral($2), DebugInfoRange(@1, @2));
|
||||||
|
free($2);
|
||||||
|
}
|
||||||
| rterm_array
|
| rterm_array
|
||||||
{
|
{
|
||||||
$$ = $1;
|
$$ = $1;
|
||||||
|
@ -907,7 +855,7 @@ rterm_without_indexer: T_STRING
|
||||||
|
|
||||||
$$ = new FunctionExpression(args, new std::map<String, Expression *>(), $3, DebugInfoRange(@1, @3));
|
$$ = new FunctionExpression(args, new std::map<String, Expression *>(), $3, DebugInfoRange(@1, @3));
|
||||||
}
|
}
|
||||||
| T_BINARY_OR identifier_items T_BINARY_OR T_FOLLOWS rterm
|
| '(' identifier_items ')' T_FOLLOWS rterm
|
||||||
{
|
{
|
||||||
DictExpression *aexpr = dynamic_cast<DictExpression *>($5);
|
DictExpression *aexpr = dynamic_cast<DictExpression *>($5);
|
||||||
if (aexpr)
|
if (aexpr)
|
||||||
|
|
|
@ -83,9 +83,9 @@ void *ConfigCompiler::GetScanner(void) const
|
||||||
*
|
*
|
||||||
* @returns The path.
|
* @returns The path.
|
||||||
*/
|
*/
|
||||||
String ConfigCompiler::GetPath(void) const
|
const char *ConfigCompiler::GetPath(void) const
|
||||||
{
|
{
|
||||||
return m_Path;
|
return m_Path.CStr();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConfigCompiler::SetZone(const String& zone)
|
void ConfigCompiler::SetZone(const String& zone)
|
||||||
|
|
|
@ -36,14 +36,28 @@ typedef void *yyscan_t;
|
||||||
|
|
||||||
namespace icinga
|
namespace icinga
|
||||||
{
|
{
|
||||||
class ConfigCompiler;
|
|
||||||
}
|
|
||||||
|
|
||||||
int yylex(YYSTYPE *context, icinga::DebugInfo *di, yyscan_t scanner);
|
struct CompilerDebugInfo
|
||||||
int yyparse(std::vector<icinga::Expression *> *elist, icinga::ConfigCompiler *context);
|
|
||||||
|
|
||||||
namespace icinga
|
|
||||||
{
|
{
|
||||||
|
const char *Path;
|
||||||
|
|
||||||
|
int FirstLine;
|
||||||
|
int FirstColumn;
|
||||||
|
|
||||||
|
int LastLine;
|
||||||
|
int LastColumn;
|
||||||
|
|
||||||
|
operator DebugInfo(void) const
|
||||||
|
{
|
||||||
|
DebugInfo di;
|
||||||
|
di.Path = Path;
|
||||||
|
di.FirstLine = FirstLine;
|
||||||
|
di.FirstColumn = FirstColumn;
|
||||||
|
di.LastLine = LastLine;
|
||||||
|
di.LastColumn = LastColumn;
|
||||||
|
return di;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The configuration compiler can be used to compile a configuration file
|
* The configuration compiler can be used to compile a configuration file
|
||||||
|
@ -65,7 +79,7 @@ public:
|
||||||
|
|
||||||
static void AddIncludeSearchDir(const String& dir);
|
static void AddIncludeSearchDir(const String& dir);
|
||||||
|
|
||||||
String GetPath(void) const;
|
const char *GetPath(void) const;
|
||||||
|
|
||||||
void SetZone(const String& zone);
|
void SetZone(const String& zone);
|
||||||
String GetZone(void) const;
|
String GetZone(void) const;
|
||||||
|
@ -88,6 +102,15 @@ private:
|
||||||
String m_Zone;
|
String m_Zone;
|
||||||
|
|
||||||
void *m_Scanner;
|
void *m_Scanner;
|
||||||
|
|
||||||
|
static std::vector<String> m_IncludeSearchDirs;
|
||||||
|
|
||||||
|
void InitializeScanner(void);
|
||||||
|
void DestroyScanner(void);
|
||||||
|
|
||||||
|
void CompileHelper(void);
|
||||||
|
|
||||||
|
public:
|
||||||
bool m_Eof;
|
bool m_Eof;
|
||||||
|
|
||||||
int m_IgnoreNewlines;
|
int m_IgnoreNewlines;
|
||||||
|
@ -105,15 +128,7 @@ private:
|
||||||
std::stack<String> m_FVVar;
|
std::stack<String> m_FVVar;
|
||||||
std::stack<Expression *> m_FTerm;
|
std::stack<Expression *> m_FTerm;
|
||||||
|
|
||||||
static std::vector<String> m_IncludeSearchDirs;
|
|
||||||
|
|
||||||
void InitializeScanner(void);
|
|
||||||
void DestroyScanner(void);
|
|
||||||
|
|
||||||
void CompileHelper(void);
|
|
||||||
|
|
||||||
friend int ::yylex(YYSTYPE *context, icinga::DebugInfo *di, yyscan_t scanner);
|
|
||||||
friend int ::yyparse(std::vector<icinga::Expression *> *elist, ConfigCompiler *context);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class I2_CONFIG_API ConfigFragmentRegistry : public Registry<ConfigFragmentRegistry, String>
|
class I2_CONFIG_API ConfigFragmentRegistry : public Registry<ConfigFragmentRegistry, String>
|
||||||
|
|
|
@ -100,7 +100,7 @@ ConfigItem::Ptr ConfigItemBuilder::Compile(void)
|
||||||
Array::Ptr templateArray = new Array();
|
Array::Ptr templateArray = new Array();
|
||||||
templateArray->Add(m_Name);
|
templateArray->Add(m_Name);
|
||||||
|
|
||||||
exprs.push_back(new SetExpression(ScopeCurrent, MakeIndexer("templates"), OpSetAdd,
|
exprs.push_back(new SetExpression(MakeIndexer(ScopeCurrent, "templates"), OpSetAdd,
|
||||||
new LiteralExpression(templateArray), m_DebugInfo));
|
new LiteralExpression(templateArray), m_DebugInfo));
|
||||||
|
|
||||||
DictExpression *dexpr = new DictExpression(m_Expressions, m_DebugInfo);
|
DictExpression *dexpr = new DictExpression(m_Expressions, m_DebugInfo);
|
||||||
|
|
|
@ -175,7 +175,7 @@ void ConfigType::ValidateObject(const Object::Ptr& object,
|
||||||
String validator = ruleList->GetValidator();
|
String validator = ruleList->GetValidator();
|
||||||
|
|
||||||
if (!validator.IsEmpty()) {
|
if (!validator.IsEmpty()) {
|
||||||
ScriptFunction::Ptr func = ScriptFunction::GetByName(validator);
|
ScriptFunction::Ptr func = ScriptGlobal::Get(validator, &Empty);
|
||||||
|
|
||||||
if (!func)
|
if (!func)
|
||||||
BOOST_THROW_EXCEPTION(std::invalid_argument("Validator function '" + validator + "' does not exist."));
|
BOOST_THROW_EXCEPTION(std::invalid_argument("Validator function '" + validator + "' does not exist."));
|
||||||
|
@ -234,7 +234,7 @@ void ConfigType::ValidateArray(const Array::Ptr& array,
|
||||||
String validator = ruleList->GetValidator();
|
String validator = ruleList->GetValidator();
|
||||||
|
|
||||||
if (!validator.IsEmpty()) {
|
if (!validator.IsEmpty()) {
|
||||||
ScriptFunction::Ptr func = ScriptFunction::GetByName(validator);
|
ScriptFunction::Ptr func = ScriptGlobal::Get(validator, &Empty);
|
||||||
|
|
||||||
if (!func)
|
if (!func)
|
||||||
BOOST_THROW_EXCEPTION(std::invalid_argument("Validator function '" + validator + "' does not exist."));
|
BOOST_THROW_EXCEPTION(std::invalid_argument("Validator function '" + validator + "' does not exist."));
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
#include "base/object.hpp"
|
#include "base/object.hpp"
|
||||||
#include "base/logger.hpp"
|
#include "base/logger.hpp"
|
||||||
#include "base/scripterror.hpp"
|
#include "base/scripterror.hpp"
|
||||||
|
#include "base/scriptglobal.hpp"
|
||||||
#include <boost/foreach.hpp>
|
#include <boost/foreach.hpp>
|
||||||
#include <boost/exception_ptr.hpp>
|
#include <boost/exception_ptr.hpp>
|
||||||
#include <boost/exception/errinfo_nested_exception.hpp>
|
#include <boost/exception/errinfo_nested_exception.hpp>
|
||||||
|
@ -55,17 +56,21 @@ Value Expression::Evaluate(ScriptFrame& frame, DebugHint *dhint) const
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Expression::GetReference(ScriptFrame& frame, bool init_dict, Value *parent, String *index, DebugHint **dhint) const
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
const DebugInfo& Expression::GetDebugInfo(void) const
|
const DebugInfo& Expression::GetDebugInfo(void) const
|
||||||
{
|
{
|
||||||
static DebugInfo debugInfo;
|
static DebugInfo debugInfo;
|
||||||
return debugInfo;
|
return debugInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<Expression *> icinga::MakeIndexer(const String& index1)
|
Expression *icinga::MakeIndexer(ScopeSpecifier scopeSpec, const String& index)
|
||||||
{
|
{
|
||||||
std::vector<Expression *> result;
|
Expression *scope = new GetScopeExpression(scopeSpec);
|
||||||
result.push_back(new VariableExpression(index1));
|
return new IndexerExpression(scope, MakeLiteral(index));
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DictExpression::MakeInline(void)
|
void DictExpression::MakeInline(void)
|
||||||
|
@ -92,6 +97,11 @@ Value VariableExpression::DoEvaluate(ScriptFrame& frame, DebugHint *dhint) const
|
||||||
return VMOps::Variable(frame, m_Variable, m_DebugInfo);
|
return VMOps::Variable(frame, m_Variable, m_DebugInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool VariableExpression::GetReference(ScriptFrame& frame, bool init_dict, Value *parent, String *index, DebugHint **dhint) const
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
Value NegateExpression::DoEvaluate(ScriptFrame& frame, DebugHint *dhint) const
|
Value NegateExpression::DoEvaluate(ScriptFrame& frame, DebugHint *dhint) const
|
||||||
{
|
{
|
||||||
return ~(long)m_Operand->Evaluate(frame);
|
return ~(long)m_Operand->Evaluate(frame);
|
||||||
|
@ -225,28 +235,11 @@ Value LogicalOrExpression::DoEvaluate(ScriptFrame& frame, DebugHint *dhint) cons
|
||||||
Value FunctionCallExpression::DoEvaluate(ScriptFrame& frame, DebugHint *dhint) const
|
Value FunctionCallExpression::DoEvaluate(ScriptFrame& frame, DebugHint *dhint) const
|
||||||
{
|
{
|
||||||
Value self, vfunc;
|
Value self, vfunc;
|
||||||
|
String index;
|
||||||
|
|
||||||
if (!m_IName.empty()) {
|
if (m_FName->GetReference(frame, false, &self, &index))
|
||||||
Value result = m_IName[0]->Evaluate(frame);
|
vfunc = VMOps::GetField(self, index);
|
||||||
|
else
|
||||||
if (m_IName.size() == 2)
|
|
||||||
self = result;
|
|
||||||
|
|
||||||
for (int i = 1; i < m_IName.size(); i++) {
|
|
||||||
if (result.IsEmpty())
|
|
||||||
return Empty;
|
|
||||||
|
|
||||||
Value index = m_IName[i]->Evaluate(frame);
|
|
||||||
result = VMOps::GetField(result, index, m_DebugInfo);
|
|
||||||
|
|
||||||
if (i == m_IName.size() - 2)
|
|
||||||
self = result;
|
|
||||||
}
|
|
||||||
|
|
||||||
vfunc= result;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m_FName)
|
|
||||||
vfunc = m_FName->Evaluate(frame);
|
vfunc = m_FName->Evaluate(frame);
|
||||||
|
|
||||||
if (!vfunc.IsObjectType<ScriptFunction>())
|
if (!vfunc.IsObjectType<ScriptFunction>())
|
||||||
|
@ -298,81 +291,35 @@ Value DictExpression::DoEvaluate(ScriptFrame& frame, DebugHint *dhint) const
|
||||||
return dframe->Self;
|
return dframe->Self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Value GetScopeExpression::DoEvaluate(ScriptFrame& frame, DebugHint *dhint) const
|
||||||
|
{
|
||||||
|
if (m_ScopeSpec == ScopeLocal)
|
||||||
|
return frame.Locals;
|
||||||
|
else if (m_ScopeSpec == ScopeCurrent)
|
||||||
|
return frame.Self;
|
||||||
|
else if (m_ScopeSpec == ScopeThis)
|
||||||
|
return frame.Self;
|
||||||
|
else if (m_ScopeSpec == ScopeGlobal)
|
||||||
|
return ScriptGlobal::GetGlobals();
|
||||||
|
else
|
||||||
|
ASSERT(!"Invalid scope.");
|
||||||
|
}
|
||||||
|
|
||||||
Value SetExpression::DoEvaluate(ScriptFrame& frame, DebugHint *dhint) const
|
Value SetExpression::DoEvaluate(ScriptFrame& frame, DebugHint *dhint) const
|
||||||
{
|
{
|
||||||
DebugHint *psdhint = dhint;
|
DebugHint *psdhint = dhint;
|
||||||
DebugHint sdhint;
|
|
||||||
|
|
||||||
Value parent, object;
|
Value parent;
|
||||||
String index;
|
String index;
|
||||||
|
|
||||||
for (Array::SizeType i = 0; i < m_Indexer.size(); i++) {
|
if (!m_Operand1->GetReference(frame, true, &parent, &index, &psdhint))
|
||||||
Expression *indexExpr = m_Indexer[i];
|
BOOST_THROW_EXCEPTION(ScriptError("Expression cannot be assigned to.", m_DebugInfo));
|
||||||
|
|
||||||
String tempindex;
|
|
||||||
|
|
||||||
if (i == 0) {
|
|
||||||
VariableExpression *vexpr = dynamic_cast<VariableExpression *>(indexExpr);
|
|
||||||
|
|
||||||
if (!vexpr) {
|
|
||||||
object = indexExpr->Evaluate(frame, dhint);
|
|
||||||
|
|
||||||
if (!object)
|
|
||||||
BOOST_THROW_EXCEPTION(ScriptError("Left-hand side argument must not be null.", m_DebugInfo));
|
|
||||||
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
tempindex = vexpr->GetVariable();
|
|
||||||
} else
|
|
||||||
tempindex = indexExpr->Evaluate(frame, dhint);
|
|
||||||
|
|
||||||
if (psdhint) {
|
|
||||||
sdhint = psdhint->GetChild(tempindex);
|
|
||||||
psdhint = &sdhint;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (i == 0) {
|
|
||||||
if (m_ScopeSpec == ScopeLocal)
|
|
||||||
parent = frame.Locals;
|
|
||||||
else if (m_ScopeSpec == ScopeCurrent)
|
|
||||||
parent = frame.Self;
|
|
||||||
else if (m_ScopeSpec == ScopeGlobal) {
|
|
||||||
ScriptVariable::Ptr sv = ScriptVariable::GetByName(tempindex);
|
|
||||||
|
|
||||||
Dictionary::Ptr fglobals = new Dictionary();
|
|
||||||
|
|
||||||
if (sv)
|
|
||||||
fglobals->Set(tempindex, sv->GetData());
|
|
||||||
|
|
||||||
parent = fglobals;
|
|
||||||
}
|
|
||||||
} else
|
|
||||||
parent = object;
|
|
||||||
|
|
||||||
if (i == m_Indexer.size() - 1) {
|
|
||||||
index = tempindex;
|
|
||||||
|
|
||||||
/* No need to look up the last indexer's value if this is a direct set */
|
|
||||||
if (m_Op == OpSetLiteral)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
object = VMOps::GetField(parent, tempindex, m_DebugInfo);
|
|
||||||
|
|
||||||
if (i != m_Indexer.size() - 1 && object.IsEmpty()) {
|
|
||||||
object = new Dictionary();
|
|
||||||
|
|
||||||
if (i == 0 && m_ScopeSpec == ScopeGlobal)
|
|
||||||
ScriptVariable::Set(tempindex, object);
|
|
||||||
else
|
|
||||||
VMOps::SetField(parent, tempindex, object, m_DebugInfo);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Value right = m_Operand2->Evaluate(frame, dhint);
|
Value right = m_Operand2->Evaluate(frame, dhint);
|
||||||
|
|
||||||
if (m_Op != OpSetLiteral) {
|
if (m_Op != OpSetLiteral) {
|
||||||
|
Value object = VMOps::GetField(parent, index);
|
||||||
|
|
||||||
Expression *lhs = MakeLiteral(object);
|
Expression *lhs = MakeLiteral(object);
|
||||||
Expression *rhs = MakeLiteral(right);
|
Expression *rhs = MakeLiteral(right);
|
||||||
|
|
||||||
|
@ -406,14 +353,15 @@ Value SetExpression::DoEvaluate(ScriptFrame& frame, DebugHint *dhint) const
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_Indexer.size() == 1 && m_ScopeSpec == ScopeGlobal)
|
|
||||||
ScriptVariable::Set(index, right);
|
|
||||||
else
|
|
||||||
VMOps::SetField(parent, index, right, m_DebugInfo);
|
VMOps::SetField(parent, index, right, m_DebugInfo);
|
||||||
|
|
||||||
if (psdhint)
|
if (psdhint) {
|
||||||
psdhint->AddMessage("=", m_DebugInfo);
|
psdhint->AddMessage("=", m_DebugInfo);
|
||||||
|
|
||||||
|
if (psdhint != dhint)
|
||||||
|
delete psdhint;
|
||||||
|
}
|
||||||
|
|
||||||
return right;
|
return right;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -434,7 +382,56 @@ Value ReturnExpression::DoEvaluate(ScriptFrame& frame, DebugHint *dhint) const
|
||||||
|
|
||||||
Value IndexerExpression::DoEvaluate(ScriptFrame& frame, DebugHint *dhint) const
|
Value IndexerExpression::DoEvaluate(ScriptFrame& frame, DebugHint *dhint) const
|
||||||
{
|
{
|
||||||
return VMOps::Indexer(frame, m_Indexer, m_DebugInfo);
|
Value object = m_Operand1->Evaluate(frame, dhint);
|
||||||
|
String index = m_Operand2->Evaluate(frame, dhint);
|
||||||
|
return VMOps::GetField(object, index);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool IndexerExpression::GetReference(ScriptFrame& frame, bool init_dict, Value *parent, String *index, DebugHint **dhint) const
|
||||||
|
{
|
||||||
|
Value vparent;
|
||||||
|
String vindex;
|
||||||
|
|
||||||
|
if (m_Operand1->GetReference(frame, init_dict, &vparent, &vindex, dhint)) {
|
||||||
|
if (init_dict && VMOps::GetField(vparent, vindex).IsEmpty())
|
||||||
|
VMOps::SetField(vparent, vindex, new Dictionary());
|
||||||
|
|
||||||
|
*parent = VMOps::GetField(vparent, vindex);
|
||||||
|
} else
|
||||||
|
*parent = m_Operand1->Evaluate(frame);
|
||||||
|
|
||||||
|
*index = m_Operand2->Evaluate(frame);
|
||||||
|
|
||||||
|
if (dhint && *dhint)
|
||||||
|
*dhint = new DebugHint((*dhint)->GetChild(*index));
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void icinga::BindToScope(Expression *& expr, ScopeSpecifier scopeSpec)
|
||||||
|
{
|
||||||
|
IndexerExpression *iexpr = dynamic_cast<IndexerExpression *>(expr);
|
||||||
|
|
||||||
|
if (iexpr) {
|
||||||
|
BindToScope(iexpr->m_Operand1, scopeSpec);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
LiteralExpression *lexpr = dynamic_cast<LiteralExpression *>(expr);
|
||||||
|
|
||||||
|
if (lexpr) {
|
||||||
|
Expression *scope = new GetScopeExpression(scopeSpec);
|
||||||
|
expr = new IndexerExpression(scope, lexpr, lexpr->GetDebugInfo());
|
||||||
|
}
|
||||||
|
|
||||||
|
VariableExpression *vexpr = dynamic_cast<VariableExpression *>(expr);
|
||||||
|
|
||||||
|
if (vexpr) {
|
||||||
|
Expression *scope = new GetScopeExpression(scopeSpec);
|
||||||
|
Expression *new_expr = new IndexerExpression(scope, MakeLiteral(vexpr->GetVariable()), vexpr->GetDebugInfo());
|
||||||
|
delete expr;
|
||||||
|
expr = new_expr;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Value ImportExpression::DoEvaluate(ScriptFrame& frame, DebugHint *dhint) const
|
Value ImportExpression::DoEvaluate(ScriptFrame& frame, DebugHint *dhint) const
|
||||||
|
@ -457,11 +454,6 @@ Value FunctionExpression::DoEvaluate(ScriptFrame& frame, DebugHint *dhint) const
|
||||||
return VMOps::NewFunction(frame, m_Args, m_ClosedVars, m_Expression);
|
return VMOps::NewFunction(frame, m_Args, m_ClosedVars, m_Expression);
|
||||||
}
|
}
|
||||||
|
|
||||||
Value SlotExpression::DoEvaluate(ScriptFrame& frame, DebugHint *dhint) const
|
|
||||||
{
|
|
||||||
return VMOps::NewSlot(frame, m_Signal, m_Slot->Evaluate(frame));
|
|
||||||
}
|
|
||||||
|
|
||||||
Value ApplyExpression::DoEvaluate(ScriptFrame& frame, DebugHint *dhint) const
|
Value ApplyExpression::DoEvaluate(ScriptFrame& frame, DebugHint *dhint) const
|
||||||
{
|
{
|
||||||
return VMOps::NewApply(frame, m_Type, m_Target, m_Name->Evaluate(frame), m_Filter,
|
return VMOps::NewApply(frame, m_Type, m_Target, m_Name->Evaluate(frame), m_Filter,
|
||||||
|
|
|
@ -110,6 +110,7 @@ enum ScopeSpecifier
|
||||||
{
|
{
|
||||||
ScopeLocal,
|
ScopeLocal,
|
||||||
ScopeCurrent,
|
ScopeCurrent,
|
||||||
|
ScopeThis,
|
||||||
ScopeGlobal
|
ScopeGlobal
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -143,12 +144,13 @@ public:
|
||||||
virtual ~Expression(void);
|
virtual ~Expression(void);
|
||||||
|
|
||||||
Value Evaluate(ScriptFrame& frame, DebugHint *dhint = NULL) const;
|
Value Evaluate(ScriptFrame& frame, DebugHint *dhint = NULL) const;
|
||||||
|
virtual bool GetReference(ScriptFrame& frame, bool init_dict, Value *parent, String *index, DebugHint **dhint = NULL) const;
|
||||||
|
virtual const DebugInfo& GetDebugInfo(void) const;
|
||||||
|
|
||||||
virtual Value DoEvaluate(ScriptFrame& frame, DebugHint *dhint) const = 0;
|
virtual Value DoEvaluate(ScriptFrame& frame, DebugHint *dhint) const = 0;
|
||||||
virtual const DebugInfo& GetDebugInfo(void) const;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
I2_CONFIG_API std::vector<Expression *> MakeIndexer(const String& index1);
|
I2_CONFIG_API Expression *MakeIndexer(ScopeSpecifier scopeSpec, const String& index);
|
||||||
|
|
||||||
class I2_CONFIG_API OwnedExpression : public Expression
|
class I2_CONFIG_API OwnedExpression : public Expression
|
||||||
{
|
{
|
||||||
|
@ -273,9 +275,12 @@ public:
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual Value DoEvaluate(ScriptFrame& frame, DebugHint *dhint) const;
|
virtual Value DoEvaluate(ScriptFrame& frame, DebugHint *dhint) const;
|
||||||
|
virtual bool GetReference(ScriptFrame& frame, bool init_dict, Value *parent, String *index, DebugHint **dhint) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
String m_Variable;
|
String m_Variable;
|
||||||
|
|
||||||
|
friend void BindToScope(Expression *& expr, ScopeSpecifier scopeSpec);
|
||||||
};
|
};
|
||||||
|
|
||||||
class I2_CONFIG_API NegateExpression : public UnaryExpression
|
class I2_CONFIG_API NegateExpression : public UnaryExpression
|
||||||
|
@ -523,15 +528,12 @@ protected:
|
||||||
class I2_CONFIG_API FunctionCallExpression : public DebuggableExpression
|
class I2_CONFIG_API FunctionCallExpression : public DebuggableExpression
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
FunctionCallExpression(const std::vector<Expression *> iname, Expression *fname, const std::vector<Expression *>& args, const DebugInfo& debugInfo = DebugInfo())
|
FunctionCallExpression(Expression *fname, const std::vector<Expression *>& args, const DebugInfo& debugInfo = DebugInfo())
|
||||||
: DebuggableExpression(debugInfo), m_IName(iname), m_FName(fname), m_Args(args)
|
: DebuggableExpression(debugInfo), m_FName(fname), m_Args(args)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
~FunctionCallExpression(void)
|
~FunctionCallExpression(void)
|
||||||
{
|
{
|
||||||
BOOST_FOREACH(Expression *expr, m_IName)
|
|
||||||
delete expr;
|
|
||||||
|
|
||||||
delete m_FName;
|
delete m_FName;
|
||||||
|
|
||||||
BOOST_FOREACH(Expression *expr, m_Args)
|
BOOST_FOREACH(Expression *expr, m_Args)
|
||||||
|
@ -542,7 +544,6 @@ protected:
|
||||||
virtual Value DoEvaluate(ScriptFrame& frame, DebugHint *dhint) const;
|
virtual Value DoEvaluate(ScriptFrame& frame, DebugHint *dhint) const;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
std::vector<Expression *> m_IName;
|
|
||||||
Expression *m_FName;
|
Expression *m_FName;
|
||||||
std::vector<Expression *> m_Args;
|
std::vector<Expression *> m_Args;
|
||||||
};
|
};
|
||||||
|
@ -590,30 +591,18 @@ private:
|
||||||
bool m_Inline;
|
bool m_Inline;
|
||||||
};
|
};
|
||||||
|
|
||||||
class I2_CONFIG_API SetExpression : public DebuggableExpression
|
class I2_CONFIG_API SetExpression : public BinaryExpression
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
SetExpression(ScopeSpecifier scopeSpec, const std::vector<Expression *>& indexer, CombinedSetOp op, Expression *operand2, const DebugInfo& debugInfo = DebugInfo())
|
SetExpression(Expression *operand1, CombinedSetOp op, Expression *operand2, const DebugInfo& debugInfo = DebugInfo())
|
||||||
: DebuggableExpression(debugInfo), m_ScopeSpec(scopeSpec), m_Op(op), m_Indexer(indexer), m_Operand2(operand2)
|
: BinaryExpression(operand1, operand2, debugInfo), m_Op(op)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
~SetExpression(void)
|
|
||||||
{
|
|
||||||
BOOST_FOREACH(Expression *expr, m_Indexer)
|
|
||||||
delete expr;
|
|
||||||
|
|
||||||
delete m_Operand2;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual Value DoEvaluate(ScriptFrame& frame, DebugHint *dhint) const;
|
virtual Value DoEvaluate(ScriptFrame& frame, DebugHint *dhint) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ScopeSpecifier m_ScopeSpec;
|
|
||||||
CombinedSetOp m_Op;
|
CombinedSetOp m_Op;
|
||||||
std::vector<Expression *> m_Indexer;
|
|
||||||
Expression *m_Operand2;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class I2_CONFIG_API ConditionalExpression : public DebuggableExpression
|
class I2_CONFIG_API ConditionalExpression : public DebuggableExpression
|
||||||
|
@ -650,26 +639,36 @@ protected:
|
||||||
virtual Value DoEvaluate(ScriptFrame& frame, DebugHint *dhint) const;
|
virtual Value DoEvaluate(ScriptFrame& frame, DebugHint *dhint) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
class I2_CONFIG_API IndexerExpression : public DebuggableExpression
|
class I2_CONFIG_API GetScopeExpression : public Expression
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
IndexerExpression(const std::vector<Expression *>& indexer, const DebugInfo& debugInfo = DebugInfo())
|
GetScopeExpression(ScopeSpecifier scopeSpec)
|
||||||
: DebuggableExpression(debugInfo), m_Indexer(indexer)
|
: m_ScopeSpec(scopeSpec)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
~IndexerExpression(void)
|
|
||||||
{
|
|
||||||
BOOST_FOREACH(Expression *expr, m_Indexer)
|
|
||||||
delete expr;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual Value DoEvaluate(ScriptFrame& frame, DebugHint *dhint) const;
|
virtual Value DoEvaluate(ScriptFrame& frame, DebugHint *dhint) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<Expression *> m_Indexer;
|
ScopeSpecifier m_ScopeSpec;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class I2_CONFIG_API IndexerExpression : public BinaryExpression
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
IndexerExpression(Expression *operand1, Expression *operand2, const DebugInfo& debugInfo = DebugInfo())
|
||||||
|
: BinaryExpression(operand1, operand2, debugInfo)
|
||||||
|
{ }
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual Value DoEvaluate(ScriptFrame& frame, DebugHint *dhint) const;
|
||||||
|
virtual bool GetReference(ScriptFrame& frame, bool init_dict, Value *parent, String *index, DebugHint **dhint) const;
|
||||||
|
|
||||||
|
friend void BindToScope(Expression *& expr, ScopeSpecifier scopeSpec);
|
||||||
|
};
|
||||||
|
|
||||||
|
I2_CONFIG_API void BindToScope(Expression *& expr, ScopeSpecifier scopeSpec);
|
||||||
|
|
||||||
class I2_CONFIG_API ImportExpression : public DebuggableExpression
|
class I2_CONFIG_API ImportExpression : public DebuggableExpression
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -706,21 +705,6 @@ private:
|
||||||
boost::shared_ptr<Expression> m_Expression;
|
boost::shared_ptr<Expression> m_Expression;
|
||||||
};
|
};
|
||||||
|
|
||||||
class I2_CONFIG_API SlotExpression : public DebuggableExpression
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
SlotExpression(const String& signal, Expression *slot, const DebugInfo& debugInfo = DebugInfo())
|
|
||||||
: DebuggableExpression(debugInfo), m_Signal(signal), m_Slot(slot)
|
|
||||||
{ }
|
|
||||||
|
|
||||||
protected:
|
|
||||||
virtual Value DoEvaluate(ScriptFrame& frame, DebugHint *dhint) const;
|
|
||||||
|
|
||||||
private:
|
|
||||||
String m_Signal;
|
|
||||||
Expression *m_Slot;
|
|
||||||
};
|
|
||||||
|
|
||||||
class I2_CONFIG_API ApplyExpression : public DebuggableExpression
|
class I2_CONFIG_API ApplyExpression : public DebuggableExpression
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -29,8 +29,7 @@
|
||||||
#include "base/array.hpp"
|
#include "base/array.hpp"
|
||||||
#include "base/dictionary.hpp"
|
#include "base/dictionary.hpp"
|
||||||
#include "base/scriptfunction.hpp"
|
#include "base/scriptfunction.hpp"
|
||||||
#include "base/scriptsignal.hpp"
|
#include "base/scriptglobal.hpp"
|
||||||
#include "base/scriptvariable.hpp"
|
|
||||||
#include "base/scripterror.hpp"
|
#include "base/scripterror.hpp"
|
||||||
#include "base/convert.hpp"
|
#include "base/convert.hpp"
|
||||||
#include "base/objectlock.hpp"
|
#include "base/objectlock.hpp"
|
||||||
|
@ -55,7 +54,7 @@ public:
|
||||||
else if (frame.Self.IsObject() && frame.Locals != static_cast<Object::Ptr>(frame.Self) && HasField(frame.Self, name))
|
else if (frame.Self.IsObject() && frame.Locals != static_cast<Object::Ptr>(frame.Self) && HasField(frame.Self, name))
|
||||||
return GetField(frame.Self, name, debugInfo);
|
return GetField(frame.Self, name, debugInfo);
|
||||||
else
|
else
|
||||||
return ScriptVariable::Get(name);
|
return ScriptGlobal::Get(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline Value FunctionCall(ScriptFrame& frame, const Value& self, const ScriptFunction::Ptr& func, const std::vector<Value>& arguments)
|
static inline Value FunctionCall(ScriptFrame& frame, const Value& self, const ScriptFunction::Ptr& func, const std::vector<Value>& arguments)
|
||||||
|
@ -70,21 +69,6 @@ public:
|
||||||
return func->Invoke(arguments);
|
return func->Invoke(arguments);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline Value Indexer(ScriptFrame& frame, const std::vector<Expression *>& indexer, const DebugInfo& debugInfo = DebugInfo())
|
|
||||||
{
|
|
||||||
Value result = indexer[0]->Evaluate(frame);
|
|
||||||
|
|
||||||
for (int i = 1; i < indexer.size(); i++) {
|
|
||||||
if (result.IsEmpty())
|
|
||||||
return Empty;
|
|
||||||
|
|
||||||
Value index = indexer[i]->Evaluate(frame);
|
|
||||||
result = GetField(result, index, debugInfo);
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline Value NewFunction(ScriptFrame& frame, const std::vector<String>& args,
|
static inline Value NewFunction(ScriptFrame& frame, const std::vector<String>& args,
|
||||||
std::map<String, Expression *> *closedVars, const boost::shared_ptr<Expression>& expression)
|
std::map<String, Expression *> *closedVars, const boost::shared_ptr<Expression>& expression)
|
||||||
{
|
{
|
||||||
|
@ -92,18 +76,6 @@ public:
|
||||||
EvaluateClosedVars(frame, closedVars), expression));
|
EvaluateClosedVars(frame, closedVars), expression));
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline Value NewSlot(ScriptFrame& frame, const String& signal, const Value& slot)
|
|
||||||
{
|
|
||||||
ScriptSignal::Ptr sig = ScriptSignal::GetByName(signal);
|
|
||||||
|
|
||||||
if (!sig)
|
|
||||||
BOOST_THROW_EXCEPTION(ScriptError("Signal '" + signal + "' does not exist."));
|
|
||||||
|
|
||||||
sig->AddSlot(boost::bind(SlotWrapper, slot, _1));
|
|
||||||
|
|
||||||
return Empty;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline Value NewApply(ScriptFrame& frame, const String& type, const String& target, const String& name, const boost::shared_ptr<Expression>& filter,
|
static inline Value NewApply(ScriptFrame& frame, const String& type, const String& target, const String& name, const boost::shared_ptr<Expression>& filter,
|
||||||
const String& fkvar, const String& fvvar, const boost::shared_ptr<Expression>& fterm, std::map<String, Expression *> *closedVars,
|
const String& fkvar, const String& fvvar, const boost::shared_ptr<Expression>& fterm, std::map<String, Expression *> *closedVars,
|
||||||
const boost::shared_ptr<Expression>& expression, const DebugInfo& debugInfo = DebugInfo())
|
const boost::shared_ptr<Expression>& expression, const DebugInfo& debugInfo = DebugInfo())
|
||||||
|
@ -340,21 +312,6 @@ private:
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void SlotWrapper(const Value& funcName, const std::vector<Value>& arguments)
|
|
||||||
{
|
|
||||||
ScriptFunction::Ptr func;
|
|
||||||
|
|
||||||
if (funcName.IsObjectType<ScriptFunction>())
|
|
||||||
func = funcName;
|
|
||||||
else
|
|
||||||
func = ScriptFunction::GetByName(funcName);
|
|
||||||
|
|
||||||
if (!func)
|
|
||||||
BOOST_THROW_EXCEPTION(ScriptError("Function '" + funcName + "' does not exist."));
|
|
||||||
|
|
||||||
func->Invoke(arguments);
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline Dictionary::Ptr EvaluateClosedVars(ScriptFrame& frame, std::map<String, Expression *> *closedVars)
|
static inline Dictionary::Ptr EvaluateClosedVars(ScriptFrame& frame, std::map<String, Expression *> *closedVars)
|
||||||
{
|
{
|
||||||
Dictionary::Ptr locals;
|
Dictionary::Ptr locals;
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
|
|
||||||
#include "db_ido/dbquery.hpp"
|
#include "db_ido/dbquery.hpp"
|
||||||
#include "base/initialize.hpp"
|
#include "base/initialize.hpp"
|
||||||
#include "base/scriptvariable.hpp"
|
#include "base/scriptglobal.hpp"
|
||||||
|
|
||||||
using namespace icinga;
|
using namespace icinga;
|
||||||
|
|
||||||
|
@ -27,20 +27,20 @@ INITIALIZE_ONCE(&DbQuery::StaticInitialize);
|
||||||
|
|
||||||
void DbQuery::StaticInitialize(void)
|
void DbQuery::StaticInitialize(void)
|
||||||
{
|
{
|
||||||
ScriptVariable::Set("DbCatConfig", DbCatConfig, true, true);
|
ScriptGlobal::Set("DbCatConfig", DbCatConfig);
|
||||||
ScriptVariable::Set("DbCatState", DbCatState, true, true);
|
ScriptGlobal::Set("DbCatState", DbCatState);
|
||||||
ScriptVariable::Set("DbCatAcknowledgement", DbCatAcknowledgement, true, true);
|
ScriptGlobal::Set("DbCatAcknowledgement", DbCatAcknowledgement);
|
||||||
ScriptVariable::Set("DbCatComment", DbCatComment, true, true);
|
ScriptGlobal::Set("DbCatComment", DbCatComment);
|
||||||
ScriptVariable::Set("DbCatDowntime", DbCatDowntime, true, true);
|
ScriptGlobal::Set("DbCatDowntime", DbCatDowntime);
|
||||||
ScriptVariable::Set("DbCatEventHandler", DbCatEventHandler, true, true);
|
ScriptGlobal::Set("DbCatEventHandler", DbCatEventHandler);
|
||||||
ScriptVariable::Set("DbCatExternalCommand", DbCatExternalCommand, true, true);
|
ScriptGlobal::Set("DbCatExternalCommand", DbCatExternalCommand);
|
||||||
ScriptVariable::Set("DbCatFlapping", DbCatFlapping, true, true);
|
ScriptGlobal::Set("DbCatFlapping", DbCatFlapping);
|
||||||
ScriptVariable::Set("DbCatCheck", DbCatCheck, true, true);
|
ScriptGlobal::Set("DbCatCheck", DbCatCheck);
|
||||||
ScriptVariable::Set("DbCatLog", DbCatLog, true, true);
|
ScriptGlobal::Set("DbCatLog", DbCatLog);
|
||||||
ScriptVariable::Set("DbCatNotification", DbCatNotification, true, true);
|
ScriptGlobal::Set("DbCatNotification", DbCatNotification);
|
||||||
ScriptVariable::Set("DbCatProgramStatus", DbCatProgramStatus, true, true);
|
ScriptGlobal::Set("DbCatProgramStatus", DbCatProgramStatus);
|
||||||
ScriptVariable::Set("DbCatRetention", DbCatRetention, true, true);
|
ScriptGlobal::Set("DbCatRetention", DbCatRetention);
|
||||||
ScriptVariable::Set("DbCatStateHistory", DbCatStateHistory, true, true);
|
ScriptGlobal::Set("DbCatStateHistory", DbCatStateHistory);
|
||||||
|
|
||||||
ScriptVariable::Set("DbCatEverything", ~(unsigned int)0, true, true);
|
ScriptGlobal::Set("DbCatEverything", ~(unsigned int)0);
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,16 +58,16 @@ void Dependency::EvaluateApplyRuleInstance(const Checkable::Ptr& checkable, cons
|
||||||
Service::Ptr service;
|
Service::Ptr service;
|
||||||
tie(host, service) = GetHostService(checkable);
|
tie(host, service) = GetHostService(checkable);
|
||||||
|
|
||||||
builder->AddExpression(new SetExpression(ScopeCurrent, MakeIndexer("parent_host_name"), OpSetLiteral, MakeLiteral(host->GetName()), di));
|
builder->AddExpression(new SetExpression(MakeIndexer(ScopeCurrent, "parent_host_name"), OpSetLiteral, MakeLiteral(host->GetName()), di));
|
||||||
builder->AddExpression(new SetExpression(ScopeCurrent, MakeIndexer("child_host_name"), OpSetLiteral, MakeLiteral(host->GetName()), di));
|
builder->AddExpression(new SetExpression(MakeIndexer(ScopeCurrent, "child_host_name"), OpSetLiteral, MakeLiteral(host->GetName()), di));
|
||||||
|
|
||||||
if (service)
|
if (service)
|
||||||
builder->AddExpression(new SetExpression(ScopeCurrent, MakeIndexer("child_service_name"), OpSetLiteral, MakeLiteral(service->GetShortName()), di));
|
builder->AddExpression(new SetExpression(MakeIndexer(ScopeCurrent, "child_service_name"), OpSetLiteral, MakeLiteral(service->GetShortName()), di));
|
||||||
|
|
||||||
String zone = checkable->GetZone();
|
String zone = checkable->GetZone();
|
||||||
|
|
||||||
if (!zone.IsEmpty())
|
if (!zone.IsEmpty())
|
||||||
builder->AddExpression(new SetExpression(ScopeCurrent, MakeIndexer("zone"), OpSetLiteral, MakeLiteral(zone), di));
|
builder->AddExpression(new SetExpression(MakeIndexer(ScopeCurrent, "zone"), OpSetLiteral, MakeLiteral(zone), di));
|
||||||
|
|
||||||
builder->AddExpression(new OwnedExpression(rule.GetExpression()));
|
builder->AddExpression(new OwnedExpression(rule.GetExpression()));
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
#include "base/debug.hpp"
|
#include "base/debug.hpp"
|
||||||
#include "base/utility.hpp"
|
#include "base/utility.hpp"
|
||||||
#include "base/timer.hpp"
|
#include "base/timer.hpp"
|
||||||
#include "base/scriptvariable.hpp"
|
#include "base/scriptglobal.hpp"
|
||||||
#include "base/initialize.hpp"
|
#include "base/initialize.hpp"
|
||||||
#include "base/statsfunction.hpp"
|
#include "base/statsfunction.hpp"
|
||||||
|
|
||||||
|
@ -39,12 +39,12 @@ INITIALIZE_ONCE(&IcingaApplication::StaticInitialize);
|
||||||
|
|
||||||
void IcingaApplication::StaticInitialize(void)
|
void IcingaApplication::StaticInitialize(void)
|
||||||
{
|
{
|
||||||
ScriptVariable::Set("EnableNotifications", true);
|
ScriptGlobal::Set("EnableNotifications", true);
|
||||||
ScriptVariable::Set("EnableEventHandlers", true);
|
ScriptGlobal::Set("EnableEventHandlers", true);
|
||||||
ScriptVariable::Set("EnableFlapping", true);
|
ScriptGlobal::Set("EnableFlapping", true);
|
||||||
ScriptVariable::Set("EnableHostChecks", true);
|
ScriptGlobal::Set("EnableHostChecks", true);
|
||||||
ScriptVariable::Set("EnableServiceChecks", true);
|
ScriptGlobal::Set("EnableServiceChecks", true);
|
||||||
ScriptVariable::Set("EnablePerfdata", true);
|
ScriptGlobal::Set("EnablePerfdata", true);
|
||||||
|
|
||||||
String node_name = Utility::GetFQDN();
|
String node_name = Utility::GetFQDN();
|
||||||
|
|
||||||
|
@ -58,7 +58,7 @@ void IcingaApplication::StaticInitialize(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ScriptVariable::Set("NodeName", node_name);
|
ScriptGlobal::Set("NodeName", node_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
REGISTER_STATSFUNCTION(IcingaApplicationStats, &IcingaApplication::StatsFunc);
|
REGISTER_STATSFUNCTION(IcingaApplicationStats, &IcingaApplication::StatsFunc);
|
||||||
|
@ -134,17 +134,12 @@ IcingaApplication::Ptr IcingaApplication::GetInstance(void)
|
||||||
|
|
||||||
Dictionary::Ptr IcingaApplication::GetVars(void) const
|
Dictionary::Ptr IcingaApplication::GetVars(void) const
|
||||||
{
|
{
|
||||||
ScriptVariable::Ptr sv = ScriptVariable::GetByName("Vars");
|
return ScriptGlobal::Get("Vars");
|
||||||
|
|
||||||
if (!sv)
|
|
||||||
return Dictionary::Ptr();
|
|
||||||
|
|
||||||
return sv->GetData();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
String IcingaApplication::GetNodeName(void) const
|
String IcingaApplication::GetNodeName(void) const
|
||||||
{
|
{
|
||||||
return ScriptVariable::Get("NodeName");
|
return ScriptGlobal::Get("NodeName");
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IcingaApplication::ResolveMacro(const String& macro, const CheckResult::Ptr&, Value *result) const
|
bool IcingaApplication::ResolveMacro(const String& macro, const CheckResult::Ptr&, Value *result) const
|
||||||
|
@ -242,7 +237,7 @@ bool IcingaApplication::GetEnableNotifications(void) const
|
||||||
if (!GetOverrideEnableNotifications().IsEmpty())
|
if (!GetOverrideEnableNotifications().IsEmpty())
|
||||||
return GetOverrideEnableNotifications();
|
return GetOverrideEnableNotifications();
|
||||||
else
|
else
|
||||||
return ScriptVariable::Get("EnableNotifications");
|
return ScriptGlobal::Get("EnableNotifications");
|
||||||
}
|
}
|
||||||
|
|
||||||
void IcingaApplication::SetEnableNotifications(bool enabled)
|
void IcingaApplication::SetEnableNotifications(bool enabled)
|
||||||
|
@ -260,7 +255,7 @@ bool IcingaApplication::GetEnableEventHandlers(void) const
|
||||||
if (!GetOverrideEnableEventHandlers().IsEmpty())
|
if (!GetOverrideEnableEventHandlers().IsEmpty())
|
||||||
return GetOverrideEnableEventHandlers();
|
return GetOverrideEnableEventHandlers();
|
||||||
else
|
else
|
||||||
return ScriptVariable::Get("EnableEventHandlers");
|
return ScriptGlobal::Get("EnableEventHandlers");
|
||||||
}
|
}
|
||||||
|
|
||||||
void IcingaApplication::SetEnableEventHandlers(bool enabled)
|
void IcingaApplication::SetEnableEventHandlers(bool enabled)
|
||||||
|
@ -278,7 +273,7 @@ bool IcingaApplication::GetEnableFlapping(void) const
|
||||||
if (!GetOverrideEnableFlapping().IsEmpty())
|
if (!GetOverrideEnableFlapping().IsEmpty())
|
||||||
return GetOverrideEnableFlapping();
|
return GetOverrideEnableFlapping();
|
||||||
else
|
else
|
||||||
return ScriptVariable::Get("EnableFlapping");
|
return ScriptGlobal::Get("EnableFlapping");
|
||||||
}
|
}
|
||||||
|
|
||||||
void IcingaApplication::SetEnableFlapping(bool enabled)
|
void IcingaApplication::SetEnableFlapping(bool enabled)
|
||||||
|
@ -296,7 +291,7 @@ bool IcingaApplication::GetEnableHostChecks(void) const
|
||||||
if (!GetOverrideEnableHostChecks().IsEmpty())
|
if (!GetOverrideEnableHostChecks().IsEmpty())
|
||||||
return GetOverrideEnableHostChecks();
|
return GetOverrideEnableHostChecks();
|
||||||
else
|
else
|
||||||
return ScriptVariable::Get("EnableHostChecks");
|
return ScriptGlobal::Get("EnableHostChecks");
|
||||||
}
|
}
|
||||||
|
|
||||||
void IcingaApplication::SetEnableHostChecks(bool enabled)
|
void IcingaApplication::SetEnableHostChecks(bool enabled)
|
||||||
|
@ -314,7 +309,7 @@ bool IcingaApplication::GetEnableServiceChecks(void) const
|
||||||
if (!GetOverrideEnableServiceChecks().IsEmpty())
|
if (!GetOverrideEnableServiceChecks().IsEmpty())
|
||||||
return GetOverrideEnableServiceChecks();
|
return GetOverrideEnableServiceChecks();
|
||||||
else
|
else
|
||||||
return ScriptVariable::Get("EnableServiceChecks");
|
return ScriptGlobal::Get("EnableServiceChecks");
|
||||||
}
|
}
|
||||||
|
|
||||||
void IcingaApplication::SetEnableServiceChecks(bool enabled)
|
void IcingaApplication::SetEnableServiceChecks(bool enabled)
|
||||||
|
@ -332,7 +327,7 @@ bool IcingaApplication::GetEnablePerfdata(void) const
|
||||||
if (!GetOverrideEnablePerfdata().IsEmpty())
|
if (!GetOverrideEnablePerfdata().IsEmpty())
|
||||||
return GetOverrideEnablePerfdata();
|
return GetOverrideEnablePerfdata();
|
||||||
else
|
else
|
||||||
return ScriptVariable::Get("EnablePerfdata");
|
return ScriptGlobal::Get("EnablePerfdata");
|
||||||
}
|
}
|
||||||
|
|
||||||
void IcingaApplication::SetEnablePerfdata(bool enabled)
|
void IcingaApplication::SetEnablePerfdata(bool enabled)
|
||||||
|
|
|
@ -58,15 +58,15 @@ void Notification::EvaluateApplyRuleInstance(const Checkable::Ptr& checkable, co
|
||||||
Service::Ptr service;
|
Service::Ptr service;
|
||||||
tie(host, service) = GetHostService(checkable);
|
tie(host, service) = GetHostService(checkable);
|
||||||
|
|
||||||
builder->AddExpression(new SetExpression(ScopeCurrent, MakeIndexer("host_name"), OpSetLiteral, MakeLiteral(host->GetName()), di));
|
builder->AddExpression(new SetExpression(MakeIndexer(ScopeCurrent, "host_name"), OpSetLiteral, MakeLiteral(host->GetName()), di));
|
||||||
|
|
||||||
if (service)
|
if (service)
|
||||||
builder->AddExpression(new SetExpression(ScopeCurrent, MakeIndexer("service_name"), OpSetLiteral, MakeLiteral(service->GetShortName()), di));
|
builder->AddExpression(new SetExpression(MakeIndexer(ScopeCurrent, "service_name"), OpSetLiteral, MakeLiteral(service->GetShortName()), di));
|
||||||
|
|
||||||
String zone = checkable->GetZone();
|
String zone = checkable->GetZone();
|
||||||
|
|
||||||
if (!zone.IsEmpty())
|
if (!zone.IsEmpty())
|
||||||
builder->AddExpression(new SetExpression(ScopeCurrent, MakeIndexer("zone"), OpSetLiteral, MakeLiteral(zone), di));
|
builder->AddExpression(new SetExpression(MakeIndexer(ScopeCurrent, "zone"), OpSetLiteral, MakeLiteral(zone), di));
|
||||||
|
|
||||||
builder->AddExpression(new OwnedExpression(rule.GetExpression()));
|
builder->AddExpression(new OwnedExpression(rule.GetExpression()));
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,7 @@
|
||||||
#include "base/convert.hpp"
|
#include "base/convert.hpp"
|
||||||
#include "base/exception.hpp"
|
#include "base/exception.hpp"
|
||||||
#include "base/initialize.hpp"
|
#include "base/initialize.hpp"
|
||||||
#include "base/scriptvariable.hpp"
|
#include "base/scriptglobal.hpp"
|
||||||
#include "base/scriptfunction.hpp"
|
#include "base/scriptfunction.hpp"
|
||||||
#include <boost/foreach.hpp>
|
#include <boost/foreach.hpp>
|
||||||
|
|
||||||
|
@ -58,22 +58,22 @@ String NotificationNameComposer::MakeName(const String& shortName, const Object:
|
||||||
|
|
||||||
void Notification::StaticInitialize(void)
|
void Notification::StaticInitialize(void)
|
||||||
{
|
{
|
||||||
ScriptVariable::Set("OK", StateFilterOK, true, true);
|
ScriptGlobal::Set("OK", StateFilterOK);
|
||||||
ScriptVariable::Set("Warning", StateFilterWarning, true, true);
|
ScriptGlobal::Set("Warning", StateFilterWarning);
|
||||||
ScriptVariable::Set("Critical", StateFilterCritical, true, true);
|
ScriptGlobal::Set("Critical", StateFilterCritical);
|
||||||
ScriptVariable::Set("Unknown", StateFilterUnknown, true, true);
|
ScriptGlobal::Set("Unknown", StateFilterUnknown);
|
||||||
ScriptVariable::Set("Up", StateFilterUp, true, true);
|
ScriptGlobal::Set("Up", StateFilterUp);
|
||||||
ScriptVariable::Set("Down", StateFilterDown, true, true);
|
ScriptGlobal::Set("Down", StateFilterDown);
|
||||||
|
|
||||||
ScriptVariable::Set("DowntimeStart", 1 << NotificationDowntimeStart, true, true);
|
ScriptGlobal::Set("DowntimeStart", 1 << NotificationDowntimeStart);
|
||||||
ScriptVariable::Set("DowntimeEnd", 1 << NotificationDowntimeEnd, true, true);
|
ScriptGlobal::Set("DowntimeEnd", 1 << NotificationDowntimeEnd);
|
||||||
ScriptVariable::Set("DowntimeRemoved", 1 << NotificationDowntimeRemoved, true, true);
|
ScriptGlobal::Set("DowntimeRemoved", 1 << NotificationDowntimeRemoved);
|
||||||
ScriptVariable::Set("Custom", 1 << NotificationCustom, true, true);
|
ScriptGlobal::Set("Custom", 1 << NotificationCustom);
|
||||||
ScriptVariable::Set("Acknowledgement", 1 << NotificationAcknowledgement, true, true);
|
ScriptGlobal::Set("Acknowledgement", 1 << NotificationAcknowledgement);
|
||||||
ScriptVariable::Set("Problem", 1 << NotificationProblem, true, true);
|
ScriptGlobal::Set("Problem", 1 << NotificationProblem);
|
||||||
ScriptVariable::Set("Recovery", 1 << NotificationRecovery, true, true);
|
ScriptGlobal::Set("Recovery", 1 << NotificationRecovery);
|
||||||
ScriptVariable::Set("FlappingStart", 1 << NotificationFlappingStart, true, true);
|
ScriptGlobal::Set("FlappingStart", 1 << NotificationFlappingStart);
|
||||||
ScriptVariable::Set("FlappingEnd", 1 << NotificationFlappingEnd, true, true);
|
ScriptGlobal::Set("FlappingEnd", 1 << NotificationFlappingEnd);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Notification::OnConfigLoaded(void)
|
void Notification::OnConfigLoaded(void)
|
||||||
|
|
|
@ -57,15 +57,15 @@ void ScheduledDowntime::EvaluateApplyRuleInstance(const Checkable::Ptr& checkabl
|
||||||
Service::Ptr service;
|
Service::Ptr service;
|
||||||
tie(host, service) = GetHostService(checkable);
|
tie(host, service) = GetHostService(checkable);
|
||||||
|
|
||||||
builder->AddExpression(new SetExpression(ScopeCurrent, MakeIndexer("host_name"), OpSetLiteral, MakeLiteral(host->GetName()), di));
|
builder->AddExpression(new SetExpression(MakeIndexer(ScopeCurrent, "host_name"), OpSetLiteral, MakeLiteral(host->GetName()), di));
|
||||||
|
|
||||||
if (service)
|
if (service)
|
||||||
builder->AddExpression(new SetExpression(ScopeCurrent, MakeIndexer("service_name"), OpSetLiteral, MakeLiteral(service->GetShortName()), di));
|
builder->AddExpression(new SetExpression(MakeIndexer(ScopeCurrent, "service_name"), OpSetLiteral, MakeLiteral(service->GetShortName()), di));
|
||||||
|
|
||||||
String zone = checkable->GetZone();
|
String zone = checkable->GetZone();
|
||||||
|
|
||||||
if (!zone.IsEmpty())
|
if (!zone.IsEmpty())
|
||||||
builder->AddExpression(new SetExpression(ScopeCurrent, MakeIndexer("zone"), OpSetLiteral, MakeLiteral(zone), di));
|
builder->AddExpression(new SetExpression(MakeIndexer(ScopeCurrent, "zone"), OpSetLiteral, MakeLiteral(zone), di));
|
||||||
|
|
||||||
builder->AddExpression(new OwnedExpression(rule.GetExpression()));
|
builder->AddExpression(new OwnedExpression(rule.GetExpression()));
|
||||||
|
|
||||||
|
|
|
@ -52,14 +52,14 @@ void Service::EvaluateApplyRuleInstance(const Host::Ptr& host, const String& nam
|
||||||
builder->SetName(name);
|
builder->SetName(name);
|
||||||
builder->SetScope(frame.Locals);
|
builder->SetScope(frame.Locals);
|
||||||
|
|
||||||
builder->AddExpression(new SetExpression(ScopeCurrent, MakeIndexer("host_name"), OpSetLiteral, MakeLiteral(host->GetName()), di));
|
builder->AddExpression(new SetExpression(MakeIndexer(ScopeCurrent, "host_name"), OpSetLiteral, MakeLiteral(host->GetName()), di));
|
||||||
|
|
||||||
builder->AddExpression(new SetExpression(ScopeCurrent, MakeIndexer("name"), OpSetLiteral, MakeLiteral(name), di));
|
builder->AddExpression(new SetExpression(MakeIndexer(ScopeCurrent, "name"), OpSetLiteral, MakeLiteral(name), di));
|
||||||
|
|
||||||
String zone = host->GetZone();
|
String zone = host->GetZone();
|
||||||
|
|
||||||
if (!zone.IsEmpty())
|
if (!zone.IsEmpty())
|
||||||
builder->AddExpression(new SetExpression(ScopeCurrent, MakeIndexer("zone"), OpSetLiteral, MakeLiteral(zone), di));
|
builder->AddExpression(new SetExpression(MakeIndexer(ScopeCurrent, "zone"), OpSetLiteral, MakeLiteral(zone), di));
|
||||||
|
|
||||||
builder->AddExpression(new OwnedExpression(rule.GetExpression()));
|
builder->AddExpression(new OwnedExpression(rule.GetExpression()));
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue