22namespace ph = std::placeholders;
27struct BaseCommandMgrHooks {
28 int hook_index_command_processed_;
31 BaseCommandMgrHooks() {
40BaseCommandMgrHooks
Hooks;
48 registerCommand(
"list-commands", std::bind(&BaseCommandMgr::listCommandsHandler,
49 this, ph::_1, ph::_2));
58 HandlerContainer::const_iterator it =
handlers_.find(cmd);
61 <<
"' is already installed.");
66 handlers_.insert(make_pair(cmd, handlers));
73 ExtendedCommandHandler handler) {
78 HandlerContainer::const_iterator it =
handlers_.find(cmd);
81 <<
"' is already installed.");
86 handlers_.insert(make_pair(cmd, handlers));
93 if (cmd ==
"list-commands") {
95 "Can't uninstall internal command 'list-commands'");
98 HandlerContainer::iterator it =
handlers_.find(cmd);
115 std::bind(&BaseCommandMgr::listCommandsHandler,
this, ph::_1, ph::_2));
122 "Command processing failed: NULL command parameter"));
140 callout_handle->setArgument(
"name", name);
141 callout_handle->setArgument(
"arguments", arg);
142 callout_handle->setArgument(
"response", response);
150 callout_handle->getArgument(
"response", response);
158 std::string(
"Error during command processing: ")
171 "'" + cmd_name +
"' command not supported."));
175 if (it->second.handler) {
176 return (it->second.handler(cmd_name, params));
178 return (it->second.extended_handler(cmd_name, params, original_cmd));
182BaseCommandMgr::listCommandsHandler(
const std::string& ,
201 std::string config_txt = config->str();
210 std::vector<uint8_t> hash;
211 hash.resize(hash_data.getLength());
212 if (hash.size() > 0) {
213 memmove(&hash[0], hash_data.getData(), hash.size());
This is a base class for exceptions thrown from the DNS library module.
A generic exception that is thrown when an unexpected error condition occurs.
HandlerContainer handlers_
Container for command handlers.
virtual isc::data::ConstElementPtr processCommand(const isc::data::ConstElementPtr &cmd)
Triggers command processing.
void registerCommand(const std::string &cmd, CommandHandler handler)
Registers specified command handler for a given command.
BaseCommandMgr()
Constructor.
static std::string getHash(const isc::data::ConstElementPtr &config)
returns a hash of a given Element structure
void deregisterAll()
Auxiliary method that removes all installed commands.
void registerExtendedCommand(const std::string &cmd, ExtendedCommandHandler handler)
Registers specified command handler for a given command.
virtual isc::data::ConstElementPtr handleCommand(const std::string &cmd_name, const isc::data::ConstElementPtr ¶ms, const isc::data::ConstElementPtr &original_cmd)
Handles the command having a given name and arguments.
void deregisterCommand(const std::string &cmd)
Deregisters specified command handler.
Exception indicating that the handler specified is not valid.
Exception indicating that the command name is not valid.
static ElementPtr create(const Position &pos=ZERO_POSITION())
static ElementPtr createList(const Position &pos=ZERO_POSITION())
Creates an empty ListElement type ElementPtr.
static int registerHook(const std::string &name)
Register Hook.
static bool calloutsPresent(int index)
Are callouts present?
static boost::shared_ptr< CalloutHandle > createCalloutHandle()
Return callout handle.
static void callCallouts(int index, CalloutHandle &handle)
Calls the callouts for a given hook.
The OutputBuffer class is a buffer abstraction for manipulating mutable data.
This file contains several functions and constants that are used for handling commands and responses ...
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
#define LOG_INFO(LOGGER, MESSAGE)
Macro to conveniently test info output and log it.
#define LOG_WARN(LOGGER, MESSAGE)
Macro to conveniently test warn output and log it.
#define LOG_DEBUG(LOGGER, LEVEL, MESSAGE)
Macro to conveniently test debug output and log it.
const isc::log::MessageID COMMAND_EXTENDED_REGISTERED
const int CONTROL_RESULT_ERROR
Status code indicating a general failure.
const isc::log::MessageID COMMAND_DEREGISTERED
const isc::log::MessageID COMMAND_RECEIVED
std::string parseCommand(ConstElementPtr &arg, ConstElementPtr command)
ConstElementPtr createAnswer()
Creates a standard config/command level success answer message (i.e.
const isc::log::MessageID COMMAND_PROCESS_ERROR2
const int CONTROL_RESULT_COMMAND_UNSUPPORTED
Status code indicating that the specified command is not supported.
const isc::log::MessageID COMMAND_REGISTERED
const int CONTROL_RESULT_SUCCESS
Status code indicating a successful operation.
isc::log::Logger command_logger("commands")
Command processing Logger.
void digest(const void *data, const size_t data_len, const HashAlgorithm hash_algorithm, isc::util::OutputBuffer &result, size_t len)
Create an Hash digest for the given data.
boost::shared_ptr< const Element > ConstElementPtr
boost::shared_ptr< Element > ElementPtr
boost::shared_ptr< CalloutHandle > CalloutHandlePtr
A shared pointer to a CalloutHandle object.
string encodeHex(const vector< uint8_t > &binary)
Encode binary data in the base16 format.
Defines the logger used by the top-level component of kea-lfc.
ExtendedCommandHandler extended_handler