| 87 | } |
| 88 | |
| 89 | bool MacroProcessor::ResolveMacro(const String& macro, const ResolverList& resolvers, |
| 90 | const CheckResult::Ptr& cr, Value *result, bool *recursive_macro) |
| 91 | { |
| 92 | CONTEXT("Resolving macro '" << macro << "'"); |
| 93 | |
| 94 | *recursive_macro = false; |
| 95 | |
| 96 | std::vector<String> tokens = macro.Split("."); |
| 97 | |
| 98 | String objName; |
| 99 | if (tokens.size() > 1) { |
| 100 | objName = tokens[0]; |
| 101 | tokens.erase(tokens.begin()); |
| 102 | } |
| 103 | |
| 104 | const auto defaultResolvers (GetDefaultResolvers()); |
| 105 | |
| 106 | for (auto resolverList : {&resolvers, &defaultResolvers}) { |
| 107 | for (auto& resolver : *resolverList) { |
| 108 | if (!objName.IsEmpty() && objName != resolver.Name) |
| 109 | continue; |
| 110 | |
| 111 | if (objName.IsEmpty()) { |
| 112 | if (!resolver.ResolveShortMacros) |
| 113 | continue; |
| 114 | |
| 115 | Dictionary::Ptr vars; |
| 116 | CustomVarObject::Ptr dobj = dynamic_pointer_cast<CustomVarObject>(resolver.Obj); |
| 117 | |
| 118 | if (dobj) { |
| 119 | vars = dobj->GetVars(); |
| 120 | } else { |
| 121 | auto app (dynamic_pointer_cast<IcingaApplication>(resolver.Obj)); |
| 122 | |
| 123 | if (app) { |
| 124 | vars = app->GetVars(); |
| 125 | } |
| 126 | } |
| 127 | |
| 128 | if (vars && vars->Contains(macro)) { |
| 129 | *result = vars->Get(macro); |
| 130 | *recursive_macro = true; |
| 131 | return true; |
| 132 | } |
| 133 | } |
| 134 | |
| 135 | auto *mresolver = dynamic_cast<MacroResolver *>(resolver.Obj.get()); |
| 136 | |
| 137 | if (mresolver && mresolver->ResolveMacro(boost::algorithm::join(tokens, "."), cr, result)) |
| 138 | return true; |
| 139 | |
| 140 | Value ref = resolver.Obj; |
| 141 | bool valid = true; |
| 142 | |
| 143 | for (const String& token : tokens) { |
| 144 | if (ref.IsObjectType<Dictionary>()) { |
| 145 | Dictionary::Ptr dict = ref; |
| 146 | if (dict->Contains(token)) { |
nothing calls this directly
no test coverage detected