14 #include <boost/foreach.hpp>
15 #include <boost/scoped_ptr.hpp>
16 #include <boost/algorithm/string/predicate.hpp>
31 CfgControlSocket::CfgControlSocket(
Type type,
const string& name,
33 : type_(type),
name_(name), url_(url) {
42 return (CfgControlSocket::Type::UNIX);
43 }
else if (type ==
"http") {
44 return (CfgControlSocket::Type::HTTP);
45 }
else if (type ==
"stdout") {
46 return (CfgControlSocket::Type::STDOUT);
55 case CfgControlSocket::Type::UNIX:
57 case CfgControlSocket::Type::HTTP:
59 case CfgControlSocket::Type::STDOUT:
72 result->set(
"socket-type", Element::create(
typeToString(type_)));
74 result->set(
"socket-name", Element::create(name_));
76 result->set(
"socket-url", Element::create(url_.
toText()));
82 : model_(model), boot_update_(true), subscribe_changes_(true),
83 validate_changes_(true), control_socket_(ctrl_sock) {
92 s <<
"model: " << model_ <<
", control socker: ";
93 if (!control_socket_) {
96 switch (control_socket_->getType()) {
97 case CfgControlSocket::Type::UNIX:
98 s <<
"UNIX:'" << control_socket_->getName() <<
"'";
100 case CfgControlSocket::Type::HTTP:
101 s <<
"HTTP:'" << control_socket_->getUrl().toText() <<
"'";
103 case CfgControlSocket::Type::STDOUT:
117 result->set(
"model", Element::create(model_));
119 result->set(
"boot-update", Element::create(boot_update_));
121 result->set(
"subscribe-changes", Element::create(subscribe_changes_));
123 result->set(
"validate-changes", Element::create(validate_changes_));
125 if (control_socket_) {
126 result->set(
"control-socket", control_socket_->toElement());
144 string type_str =
getString(ctrl_sock_config,
"socket-type");
145 string name =
getString(ctrl_sock_config,
"socket-name");
146 string url_str =
getString(ctrl_sock_config,
"socket-url");
153 }
catch (
const std::exception& ex) {
155 <<
getPosition(
"socket-type", ctrl_sock_config) <<
")");
163 <<
getPosition(
"socket-url", ctrl_sock_config) <<
")");
169 }
catch (
const std::exception& ex) {
171 << ctrl_sock_config->getPosition() <<
")");
176 result->setContext(user_context);
187 string model =
getString(server_config,
"model");
189 ConstElementPtr ctrl_sock_config = server_config->get(
"control-socket");
191 if (ctrl_sock_config) {
193 ctrl_sock = parser.
parse(ctrl_sock_config);
196 result.reset(
new CfgServer(model, ctrl_sock));
197 }
catch (
const std::exception& ex) {
199 << server_config->getPosition() <<
")");
203 result->setBootUpdate(
getBoolean(server_config,
"boot-update"));
204 result->setSubscribeChanges(
getBoolean(server_config,
"subscribe-changes"));
205 result->setValidateChanges(
getBoolean(server_config,
"validate-changes"));
209 result->setContext(user_context);
static bool getBoolean(isc::data::ConstElementPtr scope, const std::string &name)
Returns a boolean parameter from a scope.
CfgServer(const std::string &model, CfgControlSocketPtr ctrl_sock)
Constructor.
static const std::string typeToString(CfgControlSocket::Type type)
Converts CfgControlSocket::Type to string.
virtual isc::data::ElementPtr toElement() const
Unparse a configuration object.
Parser for CfgControlSocket.
std::string toText() const
Returns a text representation for the server.
boost::shared_ptr< Element > ElementPtr
boost::shared_ptr< CfgServer > CfgServerPtr
Defines a pointer for CfgServer instances.
static Type stringToType(const std::string &type)
Converts socket type name to CfgControlSocket::Type.
std::string toText() const
Returns textual representation of the URL.
void contextToElement(data::ElementPtr map) const
Merge unparse a user_context object.
bool isValid() const
Checks if the URL is valid.
CfgControlSocketPtr parse(data::ConstElementPtr ctrl_sock_config)
Performs the actual parsing of the given "control-socket" element.
An exception that is thrown if an error occurs while configuring any server.
#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...
boost::shared_ptr< const Element > ConstElementPtr
std::string getErrorMessage() const
Returns parsing error message.
Type
Defines the list of possible constrol socket types.
static std::string getString(isc::data::ConstElementPtr scope, const std::string &name)
Returns a string parameter from a scope.
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
static const data::Element::Position & getPosition(const std::string &name, const data::ConstElementPtr parent)
Utility method that returns position of an element.
Defines the logger used by the top-level component of kea-dhcp-ddns.
virtual ~CfgServer()
Destructor (doing nothing).
Represents a Control Socket.
virtual ~CfgControlSocket()
Destructor (doing nothing).
Contains declarations for loggers used by the Kea netconf agent.
Represents a Managed CfgServer.
virtual isc::data::ElementPtr toElement() const
Unparse a configuration object.
ostream & operator<<(ostream &os, const CfgServer &server)
Dumps the contents of a CfgServer as text to a output stream.
boost::shared_ptr< CfgControlSocket > CfgControlSocketPtr
Defines a pointer for CfgControlSocket instances.
CfgServerPtr parse(data::ConstElementPtr server_config)
Performs the actual parsing of the given value from the "managed-servers" map.