Kea 3.3.1
adaptor_host.cc
Go to the documentation of this file.
1// Copyright (C) 2018-2026 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
10#include <util/str.h>
11#include <yang/adaptor_host.h>
12
13#include <iomanip>
14#include <sstream>
15#include <vector>
16
17using namespace std;
18using namespace isc::data;
19using namespace isc::util;
20using namespace isc::util::str;
21
22namespace isc {
23namespace yang {
24
25const string
27 "0123456789@ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-.@_";
28
29void
31 ConstElementPtr flex_id = host->get("flex-id");
32 if (!flex_id) {
33 return;
34 }
35 const string& id = flex_id->stringValue();
36 // Empty is allowed.
37 if (id.empty()) {
38 return;
39 }
40 // No special and no not printable characters?
41 if (id.find_first_not_of(STD_CHARACTERS) == string::npos) {
42 return;
43 }
44 // Quoted identifier?
45 vector<uint8_t> binary = quotedStringToBinary(id);
46 if (binary.empty()) {
47 binary.assign(id.begin(), id.end());
48 }
49 // Convert in hexadecimal (from DUID::toText()).
50 host->set("flex-id", Element::create(dumpAsHex(binary)));
51}
52
53} // namespace yang
54} // namespace isc
static ElementPtr create(const Position &pos=ZERO_POSITION())
Create a NullElement.
Definition data.cc:300
static void quoteIdentifier(isc::data::ElementPtr host)
Quote when needed a host identifier.
static const std::string STD_CHARACTERS
The string of standard (vs special or not printable) characters (digit, letters, -,...
boost::shared_ptr< const Element > ConstElementPtr
Definition data.h:30
boost::shared_ptr< Element > ElementPtr
Definition data.h:29
string dumpAsHex(const uint8_t *data, size_t length)
Dumps a buffer of bytes as a string of hexadecimal digits.
Definition str.cc:330
vector< uint8_t > quotedStringToBinary(const string &quoted_string)
Converts a string in quotes into vector.
Definition str.cc:139
Defines the logger used by the top-level component of kea-lfc.