| Kea 3.0.2-git

server_tag.cc
Go to the documentation of this file.
1// Copyright (C) 2019-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
9#include <cc/server_tag.h>
10#include <exceptions/exceptions.h>
11#include <util/str.h>
12#include <boost/algorithm/string.hpp>
13
14 namespace isc {
15 namespace data {
16
17std::string ServerTag::ALL = "all";
18
19 ServerTag::ServerTag()
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
42 ServerTag::amAll() const {
43 return (tag_ == ALL);
44}
45
46std::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
if
if(!(yy_init))
Definition agent_lexer.cc:1900
isc::BadValue
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
Definition exceptions/exceptions.h:132
isc::data::ServerTag
Represents a server tag.
Definition server_tag.h:25
isc::data::ServerTag::ALL
static std::string ALL
Server tag for all servers as text.
Definition server_tag.h:29
isc::data::ServerTag::amAll
bool amAll() const
Checks if the server tag is set to "all servers".
Definition server_tag.cc:42
isc::data::ServerTag::get
std::string get() const
Returns server tag as string.
Definition server_tag.h:51
isc::data::ServerTag::ServerTag
ServerTag()
Default constructor.
Definition server_tag.cc:19
exceptions.h
isc_throw
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
Definition exceptions/exceptions.h:210
isc::data
Definition base_stamped_element.cc:12
isc::data::operator<<
std::ostream & operator<<(std::ostream &out, const Element::Position &pos)
Insert Element::Position as a string into stream.
Definition data.cc:48
isc::util
Definition time_utils.cc:43
isc
Defines the logger used by the top-level component of kea-lfc.
Definition agent_parser.cc:148
server_tag.h
str.h