Kea  1.9.9-git
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 
11 namespace isc {
12 namespace dhcp {
13 
14 bool 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 
27 std::string
28 evaluateString(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
std::string evaluateString(const Expression &expr, Pkt &pkt)
Definition: evaluate.cc:28
Base class for classes representing DHCP messages.
Definition: pkt.h:90
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
std::stack< std::string > ValueStack
Evaluated values are stored as a stack of strings.
Definition: token.h:33
static bool toBool(std::string value)
Coverts a (string) value to a boolean.
Definition: token.h:90
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
Defines the logger used by the top-level component of kea-dhcp-ddns.
std::vector< TokenPtr > Expression
This is a structure that holds an expression converted to RPN.
Definition: token.h:28
EvalBadStack is thrown when more or less parameters are on the stack than expected.
Definition: token.h:37