MCPcopy Create free account
hub / github.com/Icinga/icinga2 / EvaluateFilter

Method EvaluateFilter

lib/remote/filterutility.cpp:187–233  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

185}
186
187bool FilterUtility::EvaluateFilter(ScriptFrame& frame, Expression *filter,
188 const Object::Ptr& target, const String& variableName)
189{
190 if (!filter)
191 return true;
192
193 Type::Ptr type = target->GetReflectionType();
194 String varName;
195
196 if (variableName.IsEmpty())
197 varName = type->GetName().ToLower();
198 else
199 varName = variableName;
200
201 Namespace::Ptr frameNS;
202
203 if (frame.Self.IsEmpty()) {
204 frameNS = new Namespace();
205 frame.Self = frameNS;
206 } else {
207 /* Enforce a namespace object for 'frame.self'. */
208 ASSERT(frame.Self.IsObjectType<Namespace>());
209
210 frameNS = frame.Self;
211
212 ASSERT(frameNS != ScriptGlobal::GetGlobals());
213 }
214
215 frameNS->Set("obj", target);
216 frameNS->Set(varName, target);
217
218 for (int fid = 0; fid < type->GetFieldCount(); fid++) {
219 Field field = type->GetFieldInfo(fid);
220
221 if ((field.Attributes & FANavigation) == 0)
222 continue;
223
224 Object::Ptr joinedObj = target->NavigateField(fid);
225
226 if (field.NavigationName)
227 frameNS->Set(field.NavigationName, joinedObj);
228 else
229 frameNS->Set(field.Name, joinedObj);
230 }
231
232 return Convert::ToBool(filter->Evaluate(frame));
233}
234
235static void FilteredAddTarget(ScriptFrame& permissionFrame, Expression *permissionFilter,
236 ScriptFrame& frame, Expression *ufilter, std::vector<Value>& result, const String& variableName, const Object::Ptr& target)

Callers

nothing calls this directly

Calls 9

ToLowerMethod · 0.80
NavigateFieldMethod · 0.80
EvaluateMethod · 0.80
GetReflectionTypeMethod · 0.45
IsEmptyMethod · 0.45
GetNameMethod · 0.45
SetMethod · 0.45
GetFieldCountMethod · 0.45
GetFieldInfoMethod · 0.45

Tested by

no test coverage detected