void client::configuration::i_do_query(destination_container &s, destination_container &d, std::string command, const Plugin::QueryRequestMessage &request, Plugin::QueryResponseMessage &response, bool use_header) { try { boost::program_options::variables_map vm; bool custom_command = false; command_type::const_iterator cit = commands.find(command); if (cit != commands.end()) { command = cit->second.command; custom_command = true; // TODO: Build argument vector here! } if (command.substr(0,8) == "forward_" || command.substr(command.size()-8, 8) == "_forward") { BOOST_FOREACH(const Plugin::QueryRequestMessage::Request &p, request.payload()) { if (p.arguments_size() > 0) { BOOST_FOREACH(const std::string &a, p.arguments()) { if (a == "help-pb") { ::Plugin::Registry::ParameterDetails details; ::Plugin::Registry::ParameterDetail *d = details.add_parameter(); d->set_name("*"); d->set_short_description("This command will forward all arguments to remote system"); nscapi::protobuf::functions::set_response_good_wdata(*response.add_payload(), details.SerializeAsString()); return; } } } } if (!handler->query(s, d, request, response)) nscapi::protobuf::functions::set_response_bad(*response.add_payload(), command + " failed"); } else {
void client::configuration::do_query(const Plugin::QueryRequestMessage &request, Plugin::QueryResponseMessage &response) { Plugin::QueryResponseMessage local_response; std::string target = "default"; if (request.header().has_recipient_id()) target = request.header().recipient_id(); else if (request.header().has_destination_id()) target = request.header().destination_id(); BOOST_FOREACH(const std::string t, strEx::s::splitEx(target, std::string(","))) { destination_container d; destination_container s; // If we have a target, apply it object_handler_type::object_instance op = targets.find_object(t); if (op) d.apply(op); else { object_handler_type::object_instance op = targets.find_object("default"); if (op) d.apply(op); } // Next apply the header object d.apply(t, request.header()); s.apply(request.header().sender_id(), request.header()); std::string command = request.header().command(); if (!command.empty()) { // If we have a header command treat the data as a batch i_do_query(s, d, command, request, response, true); } else { // Parse each objects command and execute them for (int i=0;i<request.payload_size();i++) { ::Plugin::QueryRequestMessage local_request_message; const ::Plugin::QueryRequestMessage::Request &local_request = request.payload(i); local_request_message.mutable_header()->CopyFrom(request.header()); local_request_message.add_payload()->CopyFrom(local_request); std::string command = local_request.command(); ::Plugin::QueryResponseMessage local_response_message; i_do_query(s, d, command, local_request_message, local_response_message, false); for (int j=0;j<local_response_message.payload_size();j++) { response.add_payload()->CopyFrom(local_response_message.payload(j)); } } } } }