mirror of https://github.com/Icinga/icinga2.git
parent
103d95d0df
commit
c123210529
|
@ -62,10 +62,12 @@ Value MacroProcessor::ResolveMacros(const Value& str, const ResolverList& resolv
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MacroProcessor::ResolveMacro(const String& macro, const ResolverList& resolvers,
|
bool MacroProcessor::ResolveMacro(const String& macro, const ResolverList& resolvers,
|
||||||
const CheckResult::Ptr& cr, String *result)
|
const CheckResult::Ptr& cr, String *result, bool *user_macro)
|
||||||
{
|
{
|
||||||
CONTEXT("Resolving macro '" + macro + "'");
|
CONTEXT("Resolving macro '" + macro + "'");
|
||||||
|
|
||||||
|
*user_macro = false;
|
||||||
|
|
||||||
std::vector<String> tokens;
|
std::vector<String> tokens;
|
||||||
boost::algorithm::split(tokens, macro, boost::is_any_of("."));
|
boost::algorithm::split(tokens, macro, boost::is_any_of("."));
|
||||||
|
|
||||||
|
@ -87,6 +89,7 @@ bool MacroProcessor::ResolveMacro(const String& macro, const ResolverList& resol
|
||||||
|
|
||||||
if (vars && vars->Contains(macro)) {
|
if (vars && vars->Contains(macro)) {
|
||||||
*result = vars->Get(macro);
|
*result = vars->Get(macro);
|
||||||
|
*user_macro = true;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -132,6 +135,9 @@ bool MacroProcessor::ResolveMacro(const String& macro, const ResolverList& resol
|
||||||
}
|
}
|
||||||
|
|
||||||
if (valid) {
|
if (valid) {
|
||||||
|
if (tokens[0] == "vars")
|
||||||
|
*user_macro = true;
|
||||||
|
|
||||||
*result = ref;
|
*result = ref;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -161,7 +167,8 @@ String MacroProcessor::InternalResolveMacros(const String& str, const ResolverLi
|
||||||
String name = result.SubStr(pos_first + 1, pos_second - pos_first - 1);
|
String name = result.SubStr(pos_first + 1, pos_second - pos_first - 1);
|
||||||
|
|
||||||
String resolved_macro;
|
String resolved_macro;
|
||||||
bool found = ResolveMacro(name, resolvers, cr, &resolved_macro);
|
bool user_macro;
|
||||||
|
bool found = ResolveMacro(name, resolvers, cr, &resolved_macro, &user_macro);
|
||||||
|
|
||||||
/* $$ is an escape sequence for $. */
|
/* $$ is an escape sequence for $. */
|
||||||
if (name.IsEmpty()) {
|
if (name.IsEmpty()) {
|
||||||
|
@ -172,7 +179,8 @@ String MacroProcessor::InternalResolveMacros(const String& str, const ResolverLi
|
||||||
if (!found)
|
if (!found)
|
||||||
Log(LogWarning, "icinga", "Macro '" + name + "' is not defined.");
|
Log(LogWarning, "icinga", "Macro '" + name + "' is not defined.");
|
||||||
|
|
||||||
/* recursively resolve macros in the macro */
|
/* recursively resolve macros in the macro if it was a user macro */
|
||||||
|
if (user_macro)
|
||||||
resolved_macro = InternalResolveMacros(resolved_macro, resolvers, cr, EscapeCallback(), recursionLevel + 1);
|
resolved_macro = InternalResolveMacros(resolved_macro, resolvers, cr, EscapeCallback(), recursionLevel + 1);
|
||||||
|
|
||||||
if (escapeFn)
|
if (escapeFn)
|
||||||
|
|
|
@ -44,12 +44,12 @@ public:
|
||||||
|
|
||||||
static Value ResolveMacros(const Value& str, const ResolverList& resolvers,
|
static Value ResolveMacros(const Value& str, const ResolverList& resolvers,
|
||||||
const CheckResult::Ptr& cr, const EscapeCallback& escapeFn = EscapeCallback());
|
const CheckResult::Ptr& cr, const EscapeCallback& escapeFn = EscapeCallback());
|
||||||
static bool ResolveMacro(const String& macro, const ResolverList& resolvers,
|
|
||||||
const CheckResult::Ptr& cr, String *result);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
MacroProcessor(void);
|
MacroProcessor(void);
|
||||||
|
|
||||||
|
static bool ResolveMacro(const String& macro, const ResolverList& resolvers,
|
||||||
|
const CheckResult::Ptr& cr, String *result, bool *user_macro);
|
||||||
static String InternalResolveMacros(const String& str,
|
static String InternalResolveMacros(const String& str,
|
||||||
const ResolverList& resolvers, const CheckResult::Ptr& cr,
|
const ResolverList& resolvers, const CheckResult::Ptr& cr,
|
||||||
const EscapeCallback& escapeFn, int recursionLevel = 0);
|
const EscapeCallback& escapeFn, int recursionLevel = 0);
|
||||||
|
|
Loading…
Reference in New Issue