Kea 2.5.5
evaluate.cc
Go to the documentation of this file.
1// Copyright (C) 2015-2017 Internet Systems Consortium, Inc. ("ISC")
2//
3// This Source Code Form is subject to the terms of the Mozilla Public
4// License, v. 2.0. If a copy of the MPL was not distributed with this
5// file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
7#include <config.h>
8
9#include <eval/evaluate.h>
10
11namespace isc {
12namespace dhcp {
13
14bool evaluateBool(const Expression& expr, Pkt& pkt) {
15 ValueStack values;
16 for (Expression::const_iterator it = expr.begin();
17 it != expr.end(); ++it) {
18 (*it)->evaluate(pkt, values);
19 }
20 if (values.size() != 1) {
21 isc_throw(EvalBadStack, "Incorrect stack order. Expected exactly "
22 "1 value at the end of evaluation, got " << values.size());
23 }
24 return (Token::toBool(values.top()));
25}
26
27std::string
28evaluateString(const Expression& expr, Pkt& pkt) {
29 ValueStack values;
30 for (auto it = expr.begin(); it != expr.end(); ++it) {
31 (*it)->evaluate(pkt, values);
32 }
33 if (values.size() != 1) {
34 isc_throw(EvalBadStack, "Incorrect stack order. Expected exactly "
35 "1 value at the end of evaluation, got " << values.size());
36 }
37 return (values.top());
38}
39
40
41}; // end of isc::dhcp namespace
42}; // end of isc namespace
EvalBadStack is thrown when more or less parameters are on the stack than expected.
Definition: token.h:37
Base class for classes representing DHCP messages.
Definition: pkt.h:96
static bool toBool(std::string value)
Coverts a (string) value to a boolean.
Definition: token.h:89
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
std::string evaluateString(const Expression &expr, Pkt &pkt)
Definition: evaluate.cc:28
bool evaluateBool(const Expression &expr, Pkt &pkt)
Evaluate a RPN expression for a v4 or v6 packet and return a true or false decision.
Definition: evaluate.cc:14
std::vector< TokenPtr > Expression
This is a structure that holds an expression converted to RPN.
Definition: token.h:28
std::stack< std::string > ValueStack
Evaluated values are stored as a stack of strings.
Definition: token.h:33
Defines the logger used by the top-level component of kea-lfc.