Kea 2.2.0
adaptor_host.cc
Go to the documentation of this file.
1// Copyright (C) 2018-2022 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 <util/encode/hex.h>
10#include <util/strutil.h>
11#include <yang/adaptor_host.h>
12#include <iomanip>
13#include <sstream>
14
15using namespace std;
16using namespace isc::data;
17using namespace isc::util;
18
19namespace isc {
20namespace yang {
21
22const string
24 "0123456789@ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-.@_";
25
27}
28
30}
31
32void
34 ConstElementPtr flex_id = host->get("flex-id");
35 if (!flex_id) {
36 return;
37 }
38 const string& id = flex_id->stringValue();
39 // Empty is allowed.
40 if (id.empty()) {
41 return;
42 }
43 // No special and no not printable characters?
44 if (id.find_first_not_of(STD_CHARACTERS) == string::npos) {
45 return;
46 }
47 // Quoted identifier?
48 vector<uint8_t> binary = str::quotedStringToBinary(id);
49 if (binary.empty()) {
50 binary.assign(id.begin(), id.end());
51 }
52 // Convert in hexadecimal (from DUID::toText()).
53 stringstream tmp;
54 tmp << hex;
55 bool delim = false;
56 for (vector<uint8_t>::const_iterator it = binary.begin();
57 it != binary.end(); ++it) {
58 if (delim) {
59 tmp << ":";
60 }
61 tmp << setw(2) << setfill('0') << static_cast<unsigned int>(*it);
62 delim = true;
63 }
64 host->set("flex-id", Element::create(tmp.str()));
65}
66
67} // end of namespace isc::yang
68} // end of namespace isc
AdaptorHost()
Constructor.
Definition: adaptor_host.cc:26
static void quoteIdentifier(isc::data::ElementPtr host)
Quote when needed a host identifier.
Definition: adaptor_host.cc:33
virtual ~AdaptorHost()
Destructor.
Definition: adaptor_host.cc:29
static const std::string STD_CHARACTERS
The string of standard (vs special or not printable) characters (digit, letters, -,...
Definition: adaptor_host.h:26
boost::shared_ptr< const Element > ConstElementPtr
Definition: data.h:27
boost::shared_ptr< Element > ElementPtr
Definition: data.h:24
std::vector< uint8_t > quotedStringToBinary(const std::string &quoted_string)
Converts a string in quotes into vector.
Definition: strutil.cc:196
Definition: edns.h:19
Defines the logger used by the top-level component of kea-lfc.