diff options
author | Francis Dupont <fdupont@isc.org> | 2018-09-16 12:41:06 +0200 |
---|---|---|
committer | Francis Dupont <fdupont@isc.org> | 2018-09-16 12:41:06 +0200 |
commit | 91d36d92c6455e1edec73d00904f1d8418863a1a (patch) | |
tree | b02831bce06ab61eeb0ce952f3765e42bc1a9515 /src/lib/eval/token.cc | |
parent | [master] Removed parsers/dbaccess_parser.{h,cc} which were moved to database (diff) | |
download | kea-91d36d92c6455e1edec73d00904f1d8418863a1a.tar.xz kea-91d36d92c6455e1edec73d00904f1d8418863a1a.zip |
[67-expressions-hexa-strings] checkpoint to update syntax
Diffstat (limited to 'src/lib/eval/token.cc')
-rw-r--r-- | src/lib/eval/token.cc | 40 |
1 files changed, 39 insertions, 1 deletions
diff --git a/src/lib/eval/token.cc b/src/lib/eval/token.cc index 7225d4bb1f..e223aa0b6d 100644 --- a/src/lib/eval/token.cc +++ b/src/lib/eval/token.cc @@ -1,4 +1,4 @@ -// Copyright (C) 2015-2017 Internet Systems Consortium, Inc. ("ISC") +// Copyright (C) 2015-2018 Internet Systems Consortium, Inc. ("ISC") // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this @@ -21,6 +21,8 @@ #include <dhcp/option_vendor_class.h> #include <cstring> #include <string> +#include <iomanip> +#include <sstream> using namespace isc::dhcp; using namespace isc::util; @@ -630,6 +632,42 @@ TokenIfElse::evaluate(Pkt& /*pkt*/, ValueStack& values) { } void +TokenToHexString::evaluate(Pkt& /*pkt*/, ValueStack& values) { + if (values.size() < 2) { + isc_throw(EvalBadStack, "Incorrect stack order. Expected at least " + "2 values for hexstring, got " << values.size()); + } + + string separator = values.top(); + values.pop(); + string binary = values.top(); + values.pop(); + + // Unknown separator is interpreted as none. + if ((separator != ":") && (separator != "-") && !separator.empty()) { + separator.clear(); + } + + bool first = true; + stringstream tmp; + tmp << hex; + for (size_t i = 0; i < binary.size(); ++i) { + if (!first) { + tmp << separator; + first = false; + } + tmp << setw(2) << setfill('0') << static_cast<unsigned>(binary[i]); + } + values.push(tmp.str()); + + // Log what we popped and pushed + LOG_DEBUG(eval_logger, EVAL_DBG_STACK, EVAL_DEBUG_TOHEXSTRING) + .arg(toHex(binary)) + .arg(separator) + .arg(tmp.str()); +} + +void TokenNot::evaluate(Pkt& /*pkt*/, ValueStack& values) { if (values.size() == 0) { |