Kea 2.7.8
unix_command_config.cc
Go to the documentation of this file.
1// Copyright (C) 2015-2025 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
11#include <config/command_mgr.h>
13#include <limits>
14
15using namespace isc;
16using namespace isc::asiolink;
17using namespace isc::config;
18using namespace isc::data;
19using namespace isc::dhcp;
20using namespace std;
21
22namespace isc {
23namespace config {
24
26 : socket_type_("unix"), socket_name_() {
27 if (config->getType() != Element::map) {
28 isc_throw(DhcpConfigError, "expected map type ("
29 << config->getPosition() << ")");
30 }
31 // Get socket type.
32 ConstElementPtr socket_type = config->get("socket-type");
33 if (socket_type) {
34 if (socket_type->getType() != Element::string) {
36 "invalid type specified for parameter 'socket-type' ("
37 << socket_type->getPosition() << ")");
38 }
39 socket_type_ = socket_type->stringValue();
40 if ((socket_type_ != "unix")) {
41 isc_throw(DhcpConfigError, "unsupported 'socket-type' '"
42 << socket_type_ << "' not 'unix'");
43 }
44 }
45 // Reject HTTP/HTTPS only socket-address.
46 if (config->contains("socket-address")) {
47 isc_throw(DhcpConfigError,
48 "parameter 'socket-address' is not supported by UNIX "
49 "control sockets");
50 }
51 // Get socket name.
52 ConstElementPtr socket_name = config->get("socket-name");
53 if (socket_name) {
54 if (socket_name->getType() != Element::string) {
56 "invalid type specified for parameter 'socket-name' ("
57 << socket_name->getPosition() << ")");
58 }
59 socket_name_ = socket_name->stringValue();
60 } else {
61 isc_throw(BadSocketInfo, "Mandatory 'socket-name' parameter missing");
62 }
63
64 // Get user context.
65 ConstElementPtr user_context = config->get("user-context");
66 if (user_context) {
67 setContext(user_context);
68 }
69}
70
74 // Set user-context.
75 contextToElement(result);
76 // Set socket type.
77 result->set("socket-type", Element::create(socket_type_));
78 // Set socket name.
79 result->set("socket-name", Element::create(socket_name_));
80 return (result);
81}
82
83} // end of isc::config
84} // end of isc
if(!(yy_init))
An exception indicating that specified socket parameters are invalid.
Definition command_mgr.h:17
UnixCommandConfig(isc::data::ConstElementPtr config)
Constructor.
virtual isc::data::ElementPtr toElement() const
Unparse a configuration object.
static ElementPtr create(const Position &pos=ZERO_POSITION())
Definition data.cc:249
static ElementPtr createMap(const Position &pos=ZERO_POSITION())
Creates an empty MapElement type ElementPtr.
Definition data.cc:304
To be removed. Please use ConfigError instead.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
boost::shared_ptr< const Element > ConstElementPtr
Definition data.h:29
boost::shared_ptr< Element > ElementPtr
Definition data.h:28
Defines the logger used by the top-level component of kea-lfc.
void contextToElement(data::ElementPtr map) const
Merge unparse a user_context object.
void setContext(const data::ConstElementPtr &ctx)
Sets user context.