36 if (status_code != 0 && text.empty()) {
41 ElementPtr result = Element::create(status_code);
42 answer->set(CONTROL_RESULT, result);
45 answer->set(CONTROL_TEXT, Element::create(text));
48 answer->set(CONTROL_ARGUMENTS, arg);
73 if (msg->getType() != Element::map) {
75 "Invalid answer Element specified, expected map");
77 if (!msg->contains(CONTROL_RESULT)) {
79 "Invalid answer specified, does not contain mandatory 'result'");
83 if (result->getType() != Element::integer) {
85 "Result element in answer message is not a string");
88 rcode = result->intValue();
97 return (msg->get(CONTROL_TEXT));
105 if (msg->getType() != Element::map) {
107 "Invalid answer Element specified, expected map");
109 if (!msg->contains(CONTROL_RESULT)) {
111 "Invalid answer specified, does not contain mandatory 'result'");
115 if (result->getType() != Element::integer) {
117 "Result element in answer message is not a string");
121 int rcode = result->intValue();
125 txt <<
"failure(" << rcode <<
")";
131 txt <<
", text=" << txt_elem->stringValue();
155 const std::string& service) {
158 query->set(CONTROL_COMMAND, cmd);
160 query->set(CONTROL_ARGUMENTS, arg);
162 if (!service.empty()) {
164 services->add(Element::create(service));
165 query->set(CONTROL_SERVICE, services);
175 if (command->getType() != Element::map) {
178 if (!command->contains(CONTROL_COMMAND)) {
180 "Invalid answer specified, does not contain mandatory 'command'");
184 auto command_params = command->mapValue();
185 for (
auto param : command_params) {
186 if ((param.first != CONTROL_COMMAND) &&
187 (param.first != CONTROL_ARGUMENTS) &&
188 (param.first != CONTROL_SERVICE) &&
189 (param.first != CONTROL_REMOTE_ADDRESS)) {
191 "parameter '" << param.first <<
"'");
196 if (cmd->getType() != Element::string) {
198 "'command' element in command message is not a string");
201 arg = command->get(CONTROL_ARGUMENTS);
203 return (cmd->stringValue());
213 "no arguments specified for the '" << command_name
218 if (arg->getType() != Element::map) {
220 <<
"' command are not a map");
224 if (arg->size() == 0) {
226 "the '" << command_name <<
"' command");
229 return (command_name);
238 if (!response1 && response2) {
241 }
else if (response1 && !response2) {
244 }
else if (!response1 && !response2) {
252 if (status_code != 0) {
257 if (status_code != 0) {
261 const std::vector<ElementPtr> vec1 = args1->listValue();
262 const std::vector<ElementPtr> vec2 = args2->listValue();
266 std::set<std::string> combined_set;
267 for (
auto v = vec1.cbegin(); v != vec1.cend(); ++v) {
268 combined_set.insert((*v)->stringValue());
270 for (
auto v = vec2.cbegin(); v != vec2.cend(); ++v) {
271 combined_set.insert((*v)->stringValue());
275 ElementPtr combined_list = Element::createList();
276 for (
auto s = combined_set.cbegin(); s != combined_set.cend(); ++s) {
277 combined_list->add(Element::create(*s));
ConstElementPtr createAnswer(const int status_code, const ConstElementPtr &arg)
const char * CONTROL_RESULT
String used for result, i.e. integer status ("result")
const int CONTROL_RESULT_SUCCESS
Status code indicating a successful operation.
A standard Data module exception that is thrown if a parse error is encountered when constructing an ...
const char * CONTROL_REMOTE_ADDRESS
String used for remote address ("remote-address")
const char * CONTROL_ARGUMENTS
String used for arguments map ("arguments")
std::string parseCommandWithArgs(ConstElementPtr &arg, ConstElementPtr command)
boost::shared_ptr< Element > ElementPtr
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
std::string answerToText(const ConstElementPtr &msg)
const char * CONTROL_TEXT
String used for storing textual description ("text")
boost::shared_ptr< const Element > ConstElementPtr
A standard control channel exception that is thrown if a function is there is a problem with one of t...
ConstElementPtr parseAnswer(int &rcode, const ConstElementPtr &msg)
Defines the logger used by the top-level component of kea-lfc.
std::string parseCommand(ConstElementPtr &arg, ConstElementPtr command)
This file contains several functions and constants that are used for handling commands and responses ...
const char * CONTROL_COMMAND
String used for commands ("command")
const char * CONTROL_SERVICE
String used for service list ("service")
ConstElementPtr combineCommandsLists(const ConstElementPtr &response1, const ConstElementPtr &response2)
The Element class represents a piece of data, used by the command channel and configuration parts...
ConstElementPtr createCommand(const std::string &command, ConstElementPtr arg, const std::string &service)