Ignore:
Timestamp:
06/05/12 07:35:30 (12 months ago)
Author:
Michael Medin <michael@…>
Branches:
master, 0.4.1, 0.4.2
Children:
742b035
Parents:
695f240
Message:

2012-06-05 MickeM

  • Tweaked all servers to use the new internals and added first testcase for NSCP socket

2012-05-24 MickeM

  • Reworked real time event log support to be a lot more flexible You can now specify all options on a "filter" level.
  • WARNING* Old syntax NOT supported (and will not upgrade) but hopefully not to many will be affected.
  • Added support for ipv6 allowed hosts validation

2012-05-21 MickeM

  • Sofia Born (My second daughter)
File:
1 edited

Legend:

Unmodified
Added
Removed
  • modules/NSCPServer/handler_impl.cpp

    r7515d00 r465866c  
    77#include "handler_impl.hpp" 
    88 
     9 
     10 
     11nscp::packet handler_impl::process(const nscp::packet &packet) { 
     12  if (nscp::checks::is_query_request(packet)) { 
     13    Plugin::QueryRequestMessage msg; 
     14    msg.ParseFromString(packet.payload); 
     15    std::wstring command = _T("todo: fixme");//utf8::cvt<std::wstring>(msg.command()); 
     16 
     17    std::string reply; 
     18    try { 
     19      NSCAPI::nagiosReturn returncode = handle_query_request(packet.payload, msg, reply); 
     20      if (returncode == NSCAPI::returnIgnored) 
     21        nscapi::functions::create_simple_query_response_unknown(command, _T("Command was not found: ") + command, _T(""), reply); 
     22    } catch (const nscp::nscp_exception &e) { 
     23      nscapi::functions::create_simple_query_response_unknown(command, _T("Processing error: ") + command + _T(": ") + utf8::cvt<std::wstring>(e.what()), _T(""), reply); 
     24    } catch (const std::exception &e) { 
     25      nscapi::functions::create_simple_query_response_unknown(command, _T("Unknown error processing: ") + command + _T(": ") + utf8::cvt<std::wstring>(e.what()), _T(""), reply); 
     26    } 
     27    return nscp::factory::create_query_response(reply); 
     28  } else if (nscp::checks::is_submit_request(packet)) { 
     29    Plugin::SubmitRequestMessage msg; 
     30    msg.ParseFromString(packet.payload); 
     31    try { 
     32      std::string reply; 
     33      NSCAPI::nagiosReturn returncode = handle_submission_request(packet.payload, msg, reply); 
     34      return nscp::factory::create_submission_response(reply); 
     35    } catch (const nscp::nscp_exception &e) { 
     36      return nscp::factory::create_error(_T("Exception processing message: ") + to_wstring(e.what())); 
     37    } catch (const std::exception &e) { 
     38      return nscp::factory::create_error(_T("Exception processing message: ") + to_wstring(e.what())); 
     39    } 
     40  } else if (nscp::checks::is_exec_request(packet)) { 
     41    Plugin::ExecuteRequestMessage msg; 
     42    msg.ParseFromString(packet.payload); 
     43    try { 
     44      std::string reply; 
     45      NSCAPI::nagiosReturn returncode = handle_exec_request(packet.payload, msg, reply); 
     46      return nscp::factory::create_submission_response(reply); 
     47    } catch (const nscp::nscp_exception &e) { 
     48      return nscp::factory::create_error(_T("Exception processing message: ") + to_wstring(e.what())); 
     49    } catch (const std::exception &e) { 
     50      return nscp::factory::create_error(_T("Exception processing message: ") + to_wstring(e.what())); 
     51    } 
     52  } else { 
     53    this->log_error("nscp:handler", __FILE__, __LINE__, "Unknown packet: " + packet.to_string()); 
     54    return nscp::factory::create_error(_T("Unknown packet: ") + packet.to_wstring()); 
     55  } 
     56  return nscp::factory::create_error(_T("Unknown error...")); 
     57} 
    958NSCAPI::nagiosReturn handler_impl::handle_query_request(const std::string &request, Plugin::QueryRequestMessage &msg, std::string &reply) { 
    1059  Plugin::Common::Header hdr; 
     
    2675      nscapi::functions::create_simple_query_response_unknown(command, _T("Arguments not allowed for command: ") + command, _T(""), outBuffer); 
    2776    } else { 
    28       bool ok = true; 
    29       if (!allowNasty_) { 
    30         for (int j=0;j<payload.arguments_size();j++) { 
    31           if (payload.arguments(j).find_first_of(NASTY_METACHARS) != std::wstring::npos) { 
    32             ok = false; 
    33             break; 
    34           } 
    35         } 
    36       } 
    37       if (ok) { 
    38         std::string tmpBuffer; 
    39         Plugin::QueryRequestMessage tmp; 
    40         tmp.mutable_header()->CopyFrom(hdr); 
    41         tmp.add_payload()->CopyFrom(payload); 
    42         tmp.SerializeToString(&tmpBuffer); 
    43         NSCAPI::nagiosReturn returncode = nscapi::plugin_singleton->get_core()->query(command, tmpBuffer, outBuffer); 
    44         if (returncode == NSCAPI::returnIgnored) { 
    45           nscapi::functions::create_simple_query_response_unknown(command, _T("Command was not found: ") + command, _T(""), outBuffer); 
    46         } 
    47       } else { 
    48         nscapi::functions::create_simple_query_response_unknown(command, _T("Nasty arguments not allowed for command: ") + command, _T(""), outBuffer); 
     77      std::string tmpBuffer; 
     78      Plugin::QueryRequestMessage tmp; 
     79      tmp.mutable_header()->CopyFrom(hdr); 
     80      tmp.add_payload()->CopyFrom(payload); 
     81      tmp.SerializeToString(&tmpBuffer); 
     82      NSCAPI::nagiosReturn returncode = nscapi::plugin_singleton->get_core()->query(command, tmpBuffer, outBuffer); 
     83      if (returncode == NSCAPI::returnIgnored) { 
     84        nscapi::functions::create_simple_query_response_unknown(command, _T("Command was not found: ") + command, _T(""), outBuffer); 
    4985      } 
    5086      Plugin::QueryResponseMessage tmpResponse; 
Note: See TracChangeset for help on using the changeset viewer.