35 if (status_code != 0 && text.empty()) {
40 ElementPtr result = Element::create(status_code);
41 answer->set(CONTROL_RESULT, result);
44 answer->set(CONTROL_TEXT, Element::create(text));
47 answer->set(CONTROL_ARGUMENTS, arg);
72 if (msg->getType() != Element::map) {
74 "Invalid answer Element specified, expected map");
76 if (!msg->contains(CONTROL_RESULT)) {
78 "Invalid answer specified, does not contain mandatory 'result'");
82 if (result->getType() != Element::integer) {
84 "Result element in answer message is not a string");
87 rcode = result->intValue();
96 return (msg->get(CONTROL_TEXT));
104 if (msg->getType() != Element::map) {
106 "Invalid answer Element specified, expected map");
108 if (!msg->contains(CONTROL_RESULT)) {
110 "Invalid answer specified, does not contain mandatory 'result'");
114 if (result->getType() != Element::integer) {
116 "Result element in answer message is not a string");
120 int rcode = result->intValue();
124 txt <<
"failure(" << rcode <<
")";
130 txt <<
", text=" << txt_elem->stringValue();
154 const std::string& service) {
157 query->set(CONTROL_COMMAND, cmd);
159 query->set(CONTROL_ARGUMENTS, arg);
161 if (!service.empty()) {
163 services->add(Element::create(service));
164 query->set(CONTROL_SERVICE, services);
174 if (command->getType() != Element::map) {
177 if (!command->contains(CONTROL_COMMAND)) {
179 "Invalid answer specified, does not contain mandatory 'command'");
183 auto command_params = command->mapValue();
184 for (
auto param : command_params) {
185 if ((param.first != CONTROL_COMMAND) &&
186 (param.first != CONTROL_ARGUMENTS) &&
187 (param.first != CONTROL_SERVICE)) {
189 "parameter '" << param.first <<
"'");
194 if (cmd->getType() != Element::string) {
196 "'command' element in command message is not a string");
199 arg = command->get(CONTROL_ARGUMENTS);
201 return (cmd->stringValue());
211 "no arguments specified for the '" << command_name
216 if (arg->getType() != Element::map) {
218 <<
"' command are not a map");
222 if (arg->size() == 0) {
224 "the '" << command_name <<
"' command");
227 return (command_name);
236 if (!response1 && response2) {
239 }
else if (response1 && !response2) {
242 }
else if (!response1 && !response2) {
250 if (status_code != 0) {
255 if (status_code != 0) {
259 const std::vector<ElementPtr> vec1 = args1->listValue();
260 const std::vector<ElementPtr> vec2 = args2->listValue();
264 std::set<std::string> combined_set;
265 for (
auto v = vec1.cbegin(); v != vec1.cend(); ++v) {
266 combined_set.insert((*v)->stringValue());
268 for (
auto v = vec2.cbegin(); v != vec2.cend(); ++v) {
269 combined_set.insert((*v)->stringValue());
273 ElementPtr combined_list = Element::createList();
274 for (
auto s = combined_set.cbegin(); s != combined_set.cend(); ++s) {
275 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_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-dhcp-ddns.
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)