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 
13 using namespace std;
14 using namespace isc::data;
15 using namespace isc::util;
16 
17 namespace isc {
18 namespace yang {
19 
20 const string
21 AdaptorHost::STD_CHARACTERS =
22  "0123456789@ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-.@_";
23 
24 AdaptorHost::AdaptorHost() {
25 }
26 
27 AdaptorHost::~AdaptorHost() {
28 }
29 
30 void
31 AdaptorHost::quoteIdentifier(ElementPtr host) {
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
boost::shared_ptr< Element > ElementPtr
Definition: data.h:20
Definition: edns.h:19
boost::shared_ptr< const Element > ConstElementPtr
Definition: data.h:23
std::vector< uint8_t > quotedStringToBinary(const std::string &quoted_string)
Converts a string in quotes into vector.
Definition: strutil.cc:196
Defines the logger used by the top-level component of kea-dhcp-ddns.