Kea 2.7.6
adaptor_host.cc
Go to the documentation of this file.
1// Copyright (C) 2018-2024 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;
20
21namespace isc {
22namespace yang {
23
24const string
26 "0123456789@ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-.@_";
27
28void
30 ConstElementPtr flex_id = host->get("flex-id");
31 if (!flex_id) {
32 return;
33 }
34 const string& id = flex_id->stringValue();
35 // Empty is allowed.
36 if (id.empty()) {
37 return;
38 }
39 // No special and no not printable characters?
40 if (id.find_first_not_of(STD_CHARACTERS) == string::npos) {
41 return;
42 }
43 // Quoted identifier?
44 vector<uint8_t> binary = str::quotedStringToBinary(id);
45 if (binary.empty()) {
46 binary.assign(id.begin(), id.end());
47 }
48 // Convert in hexadecimal (from DUID::toText()).
49 stringstream tmp;
50 tmp << hex;
51 bool delim = false;
52 for (auto const& it : binary) {
53 if (delim) {
54 tmp << ":";
55 }
56 tmp << setw(2) << setfill('0') << static_cast<unsigned int>(it);
57 delim = true;
58 }
59 host->set("flex-id", Element::create(tmp.str()));
60}
61
62} // namespace yang
63} // namespace isc
static ElementPtr create(const Position &pos=ZERO_POSITION())
Definition data.cc:249
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:29
boost::shared_ptr< Element > ElementPtr
Definition data.h:28
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.