Kea  1.9.9-git
server_tag.cc
Go to the documentation of this file.
1 // Copyright (C) 2019-2020 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 <cc/server_tag.h>
10 #include <exceptions/exceptions.h>
11 #include <util/strutil.h>
12 #include <boost/algorithm/string.hpp>
13 
14 namespace isc {
15 namespace data {
16 
17 std::string ServerTag::ALL = "all";
18 
20  : tag_(ALL) {
21 }
22 
23 ServerTag::ServerTag(const std::string& tag)
24  : tag_(util::str::trim(tag)) {
25  if (tag_.empty()) {
26  isc_throw(BadValue, "server-tag must not be empty");
27 
28  } else if (tag_.length() > 256) {
29  isc_throw(BadValue, "server-tag must not be longer than 256 characters");
30  }
31 
32  boost::algorithm::to_lower(tag_);
33 
34  // ANY has a defined meaning for server selector and must not be used as
35  // a server tag.
36  if (tag_ == "any") {
37  isc_throw(BadValue, "'any' is reserved and must not be used as a server-tag");
38  }
39 }
40 
41 bool
43  return (tag_ == ALL);
44 }
45 
46 std::ostream&
47 operator<<(std::ostream& os, const ServerTag& server_tag) {
48  os << server_tag.get();
49  return (os);
50 }
51 
52 } // end of namespace isc::data
53 } // end of namespace isc
std::string get() const
Returns server tag as string.
Definition: server_tag.h:51
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
Represents a server tag.
Definition: server_tag.h:25
std::ostream & operator<<(std::ostream &out, const Element::Position &pos)
Insert Element::Position as a string into stream.
Definition: data.cc:45
bool amAll() const
Checks if the server tag is set to "all servers".
Definition: server_tag.cc:42
ServerTag()
Default constructor.
Definition: server_tag.cc:19
Defines the logger used by the top-level component of kea-dhcp-ddns.
static std::string ALL
Server tag for all servers as text.
Definition: server_tag.h:29
string trim(const string &instring)
Trim Leading and Trailing Spaces.
Definition: strutil.cc:53