35 const ConstElementPtr& arg) {
36 if (status_code != 0 && text.empty()) {
40 ElementPtr answer = Element::createMap();
41 ElementPtr result = Element::create(status_code);
73 if (msg->getType() != Element::map) {
75 << Element::typeToName(msg->getType()) <<
" instead");
79 "invalid answer: does not contain mandatory '" <<
CONTROL_RESULT <<
"'");
83 if (result->getType() != Element::integer) {
85 <<
"' to be an integer, got "
86 << Element::typeToName(result->getType()) <<
" instead");
89 rcode = result->intValue();
100 if (msg->getType() != Element::map) {
102 << Element::typeToName(msg->getType()) <<
" instead");
106 "invalid answer: does not contain mandatory '" <<
CONTROL_RESULT <<
"'");
110 if (result->getType() != Element::integer) {
112 <<
"' to be an integer, got "
113 << Element::typeToName(result->getType()) <<
" instead");
116 rcode = result->intValue();
134 if (msg->getType() != Element::map) {
136 << Element::typeToName(msg->getType()) <<
" instead");
140 "invalid answer: does not contain mandatory '" <<
CONTROL_RESULT <<
"'");
144 if (result->getType() != Element::integer) {
146 <<
"' to be an integer, got " << Element::typeToName(result->getType())
151 int rcode = result->intValue();
155 txt <<
"failure(" << rcode <<
")";
161 txt <<
", text=" << txt_elem->stringValue();
185 const std::string& service) {
186 ElementPtr query = Element::createMap();
187 ElementPtr cmd = Element::create(command);
192 if (!service.empty()) {
193 ElementPtr services = Element::createList();
194 services->add(Element::create(service));
205 if (command->getType() != Element::map) {
207 << Element::typeToName(command->getType()) <<
" instead");
211 "invalid command: does not contain mandatory '" <<
CONTROL_COMMAND <<
"'");
215 auto const& command_params = command->mapValue();
216 for (
auto const& param : command_params) {
222 "invalid command: unsupported parameter '" << param.first <<
"'");
227 if (cmd->getType() != Element::string) {
230 << Element::typeToName(command->getType()) <<
" instead");
235 return (cmd->stringValue());
245 "invalid command '" << command_name <<
"': no arguments specified");
249 if (arg->getType() != Element::map) {
251 "invalid command '" << command_name <<
"': expected '"
253 << Element::typeToName(arg->getType()) <<
" instead");
257 if (arg->size() == 0) {
259 "invalid command '" << command_name <<
"': '"
263 return (command_name);
268 const ConstElementPtr& response2) {
272 if (!response1 && response2) {
275 }
else if (response1 && !response2) {
278 }
else if (!response1 && !response2) {
279 return (ConstElementPtr());
285 ConstElementPtr args1 =
parseAnswer(status_code, response1);
286 if (status_code != 0) {
290 ConstElementPtr args2 =
parseAnswer(status_code, response2);
291 if (status_code != 0) {
295 const std::vector<ElementPtr> vec1 = args1->listValue();
296 const std::vector<ElementPtr> vec2 = args2->listValue();
300 std::set<std::string> combined_set;
301 for (
auto const& v : vec1) {
302 combined_set.insert(v->stringValue());
304 for (
auto const& v : vec2) {
305 combined_set.insert(v->stringValue());
309 ElementPtr combined_list = Element::createList();
310 for (
auto const& s : combined_set) {
311 combined_list->add(Element::create(s));
A standard control channel exception that is thrown if a function is there is a problem with one of t...
The Element class represents a piece of data, used by the command channel and configuration parts.
A standard Data module exception that is thrown if a parse error is encountered when constructing an ...
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.
std::string parseCommandWithArgs(ConstElementPtr &arg, ConstElementPtr command)
ConstElementPtr parseAnswerText(int &rcode, const ConstElementPtr &msg)
const char * CONTROL_ARGUMENTS
String used for arguments map ("arguments")
const char * CONTROL_TEXT
String used for storing textual description ("text")
const char * CONTROL_COMMAND
String used for commands ("command")
ConstElementPtr createCommand(const std::string &command)
Creates a standard command message with no argument (of the form { "command": "my_command" })
const char * CONTROL_SERVICE
String used for service list ("service")
std::string parseCommand(ConstElementPtr &arg, ConstElementPtr command)
ConstElementPtr combineCommandsLists(const ConstElementPtr &response1, const ConstElementPtr &response2)
ConstElementPtr createAnswer()
Creates a standard config/command level success answer message (i.e.
ConstElementPtr parseAnswer(int &rcode, const ConstElementPtr &msg)
const char * CONTROL_REMOTE_ADDRESS
String used for remote address ("remote-address")
const char * CONTROL_RESULT
String used for result, i.e. integer status ("result")
const int CONTROL_RESULT_SUCCESS
Status code indicating a successful operation.
std::string answerToText(const ConstElementPtr &msg)
boost::shared_ptr< const Element > ConstElementPtr
boost::shared_ptr< Element > ElementPtr
Defines the logger used by the top-level component of kea-lfc.