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