Changeset f33c12f in nscp for include


Ignore:
Timestamp:
12/05/11 08:05:14 (18 months ago)
Author:
Michael Medin <michael@…>
Branches:
master, 0.4.0, 0.4.1, 0.4.2
Children:
9c06054
Parents:
9853bc3
Message:
  • Changed so Client interfaces no longer use "simple" interface meaning correct targets are now propagated (ie. calling NRPE -> NSCA will get correct host set automatically) (havent tested this yet, but now it builds at least, will test to night)
Location:
include
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • include/client/command_line_parser.cpp

    r96c1461 rf33c12f  
    5353 
    5454 
    55 int client::command_line_parser::commandLineExec(configuration &config, const std::wstring &command, std::list<std::wstring> &arguments, std::wstring &result) { 
     55int client::command_line_parser::do_execute_command_as_exec(configuration &config, const std::wstring &command, std::list<std::wstring> &arguments, std::string &result) { 
    5656  if (!config.validate()) 
    5757    throw cli_exception("Invalid data: " + config.to_string()); 
    5858  if (command == _T("help")) { 
    59     result = build_help(config); 
    60     return NSCAPI::returnUNKNOWN; 
     59    return nscapi::functions::create_simple_exec_response_unknown(command, build_help(config), result); 
    6160  } else if (command == _T("query")) { 
    6261    std::wstring msg, perf; 
    63     int ret = query(config, command, arguments, msg, perf); 
    64     if (perf.empty()) 
    65       result = msg; 
    66     else 
    67       result = msg + _T("|") + perf; 
     62    int ret = do_query(config, command, arguments, result); 
     63    nscapi::functions::make_exec_from_query(result); 
    6864    return ret; 
    6965  } else if (command == _T("exec")) { 
    70     return exec(config, command, arguments, result); 
     66    return do_exec(config, command, arguments, result); 
    7167  } else if (command == _T("submit")) { 
    72     boost::tuple<int,std::wstring> ret = simple_submit(config, command, arguments); 
    73     result = ret.get<1>(); 
    74     return ret.get<0>(); 
     68    int ret = do_submit(config, command, arguments, result); 
     69    nscapi::functions::make_exec_from_submit(result); 
     70    return ret; 
     71  } 
     72  return NSCAPI::returnIgnored; 
     73} 
     74 
     75int client::command_line_parser::do_execute_command_as_query(configuration &config, const std::wstring &command, std::list<std::wstring> &arguments, std::string &result) { 
     76  if (!config.validate()) 
     77    throw cli_exception("Invalid data: " + config.to_string()); 
     78  if (command == _T("help")) { 
     79    return nscapi::functions::create_simple_query_response_unknown(command, build_help(config), _T(""), result); 
     80  } else if (command == _T("query")) { 
     81    return do_query(config, command, arguments, result); 
     82  } else if (command == _T("exec")) { 
     83    int ret = do_exec(config, command, arguments, result); 
     84    nscapi::functions::make_query_from_exec(result); 
     85    return ret; 
     86  } else if (command == _T("submit")) { 
     87    int ret = do_submit(config, command, arguments, result); 
     88    nscapi::functions::make_query_from_submit(result); 
     89    return ret; 
    7590  } 
    7691  return NSCAPI::returnIgnored; 
     
    97112} 
    98113 
    99 int client::command_manager::exec_simple(configuration &config, const std::wstring &target, const std::wstring &command, std::list<std::wstring> &arguments, std::wstring &message, std::wstring &perf) { 
     114int client::command_manager::exec_simple(configuration &config, const std::wstring &target, const std::wstring &command, std::list<std::wstring> &arguments, std::string &response) { 
    100115  command_type::const_iterator cit = commands.find(command); 
    101116  if (cit == commands.end()) 
     
    112127  } 
    113128  // TODO: Add support for target here! 
    114   return client::command_line_parser::commandLineExec(config, ci.command, rendered_arguments, message); 
    115 } 
    116 int client::command_line_parser::query(configuration &config, const std::wstring &command, std::list<std::wstring> &arguments, std::wstring &msg, std::wstring &perf) { 
     129  return client::command_line_parser::do_execute_command_as_exec(config, ci.command, rendered_arguments, response); 
     130} 
     131int client::command_line_parser::do_query(configuration &config, const std::wstring &command, std::list<std::wstring> &arguments, std::string &response) { 
    117132  boost::program_options::variables_map vm; 
    118133 
     
    141156  nscapi::functions::append_simple_query_request_payload(message.add_payload(), config.data->command, config.data->arguments); 
    142157  std::string result; 
    143   int ret = config.handler->query(config.data, message.mutable_header(), message.SerializeAsString(), result); 
    144   nscapi::functions::parse_simple_query_response(result, msg, perf); 
    145   return ret; 
    146 } 
    147  
    148 int client::command_line_parser::exec(configuration &config, const std::wstring &command, std::list<std::wstring> &arguments, std::wstring &result) { 
     158  return config.handler->query(config.data, message.mutable_header(), message.SerializeAsString(), result); 
     159} 
     160 
     161int client::command_line_parser::do_exec(configuration &config, const std::wstring &command, std::list<std::wstring> &arguments, std::string &result) { 
    149162  boost::program_options::variables_map vm; 
    150163 
     
    173186  std::string response; 
    174187  nscapi::functions::append_simple_exec_request_payload(message.add_payload(), config.data->command, config.data->arguments); 
    175   int ret = config.handler->exec(config.data, message.mutable_header(), message.SerializeAsString(), response); 
    176   nscapi::functions::parse_simple_exec_result(response, result); 
    177   return ret; 
    178 } 
    179  
    180 boost::tuple<int,std::wstring> client::command_line_parser::simple_submit(configuration &config, const std::wstring &command, std::list<std::wstring> &arguments) { 
     188  return config.handler->exec(config.data, message.mutable_header(), message.SerializeAsString(), response); 
     189} 
     190 
     191int client::command_line_parser::do_submit(configuration &config, const std::wstring &command, std::list<std::wstring> &arguments, std::string &result) { 
    181192  boost::program_options::variables_map vm; 
    182193  po::options_description common("Common options"); 
     
    203214  nscapi::functions::append_simple_submit_request_payload(message.add_payload(), config.data->command, config.data->result, config.data->message); 
    204215 
    205   std::string response; 
    206   if (config.handler->submit(config.data, message.mutable_header(), message.SerializeAsString(), response) != NSCAPI::isSuccess) 
    207     return boost::make_tuple(NSCAPI::returnUNKNOWN, _T("Failed to submit command")); 
    208  
    209   std::wstring messages; 
    210   int ret = nscapi::functions::parse_simple_submit_response(response, messages); 
    211   return boost::make_tuple(ret, messages); 
     216  return config.handler->submit(config.data, message.mutable_header(), message.SerializeAsString(), result); 
    212217} 
    213218void client::command_line_parser::modify_header(configuration &config, ::Plugin::Common_Header* header, nscapi::functions::destination_container &recipient) { 
     
    225230} 
    226231 
    227 int client::command_line_parser::relay_submit(configuration &config, const std::string &request, std::string &response) { 
     232int client::command_line_parser::do_relay_submit(configuration &config, const std::string &request, std::string &response) { 
    228233  Plugin::SubmitRequestMessage message; 
    229234  message.ParseFromString(request); 
  • include/client/command_line_parser.hpp

    r96c1461 rf33c12f  
    120120 
    121121    std::wstring add_command(std::wstring name, std::wstring args); 
    122     int exec_simple(configuration &config, const std::wstring &target, const std::wstring &command, std::list<std::wstring> &arguments, std::wstring &message, std::wstring &perf); 
     122    int exec_simple(configuration &config, const std::wstring &target, const std::wstring &command, std::list<std::wstring> &arguments, std::string &response); 
    123123 
    124124    static std::wstring make_key(std::wstring key) { 
     
    137137    static std::wstring build_help(configuration &config); 
    138138 
    139     static int commandLineExec(configuration &config, const std::wstring &command, std::list<std::wstring> &arguments, std::wstring &result); 
    140     static int relay_submit(configuration &config, const std::string &request, std::string &response); 
    141  
    142     static boost::tuple<int,std::wstring> simple_submit(configuration &config, const std::wstring &command, std::list<std::wstring> &arguments); 
     139    static int do_execute_command_as_exec(configuration &config, const std::wstring &command, std::list<std::wstring> &arguments, std::string &result); 
     140    static int do_execute_command_as_query(configuration &config, const std::wstring &command, std::list<std::wstring> &arguments, std::string &result); 
     141    static int do_relay_submit(configuration &config, const std::string &request, std::string &response); 
    143142 
    144143    static std::wstring parse_command(std::wstring command, std::wstring prefix) { 
     
    163162    } 
    164163 
    165     static int query(configuration &config, const std::wstring &command, std::list<std::wstring> &arguments, std::wstring &msg, std::wstring &perf); 
    166     //static std::list<std::string> submit(configuration &config, const std::wstring &command, std::list<std::wstring> &arguments); 
    167     static int exec(configuration &config, const std::wstring &command, std::list<std::wstring> &arguments, std::wstring &result); 
     164    static int do_query(configuration &config, const std::wstring &command, std::list<std::wstring> &arguments, std::string &result); 
     165    static int do_exec(configuration &config, const std::wstring &command, std::list<std::wstring> &arguments, std::string &result); 
     166    static int do_submit(configuration &config, const std::wstring &command, std::list<std::wstring> &arguments, std::string &result); 
    168167 
    169168  private: 
  • include/nscapi/functions.hpp

    r96c1461 rf33c12f  
    4141 
    4242namespace nscapi { 
     43 
     44  namespace traits { 
     45 
     46    template<class T> 
     47    struct perf_data_consts { 
     48      static const T get_valid_perf_numbers(); 
     49      static const T get_replace_perf_coma_src(); 
     50      static const T get_replace_perf_coma_tgt(); 
     51    }; 
     52 
     53    template<> 
     54    struct perf_data_consts<std::wstring> { 
     55      static const std::wstring get_valid_perf_numbers() { 
     56        return _T("0123456789,."); 
     57      } 
     58      static const std::wstring get_replace_perf_coma_src() { 
     59        return _T(","); 
     60      } 
     61      static const std::wstring get_replace_perf_coma_tgt() { 
     62        return _T("."); 
     63      } 
     64    }; 
     65    template<> 
     66    struct perf_data_consts<std::string> { 
     67      static const std::string get_valid_perf_numbers() { 
     68        return "0123456789,."; 
     69      } 
     70      static const std::string get_replace_perf_coma_src() { 
     71        return ","; 
     72      } 
     73      static const std::string get_replace_perf_coma_tgt() { 
     74        return "."; 
     75      } 
     76    }; 
     77  } 
    4378  class functions { 
    4479  public: 
     
    71106      return NSCAPI::hasFailed; 
    72107    } 
     108    static Plugin::Common::ResultCode gbp_status_to_gbp_nagios(Plugin::Common::Status::StatusType ret) { 
     109      if (ret == Plugin::Common_Status_StatusType_OK) 
     110        return Plugin::Common_ResultCode_OK; 
     111      return Plugin::Common_ResultCode_UNKNOWN; 
     112    } 
     113    static Plugin::Common::Status::StatusType gbp_to_nagios_gbp_status(Plugin::Common::ResultCode ret) { 
     114      if (ret == Plugin::Common_ResultCode_UNKNOWN||ret == Plugin::Common_ResultCode_WARNING||ret == Plugin::Common_ResultCode_CRITCAL) 
     115        return Plugin::Common_Status_StatusType_CRITICAL; 
     116      return Plugin::Common_Status_StatusType_OK; 
     117    } 
     118     
    73119    static Plugin::LogEntry::Entry::Level log_to_gpb(NSCAPI::messageTypes ret) { 
    74120      if (ret == NSCAPI::critical) 
     
    98144    } 
    99145 
    100     static double trim_to_double(std::wstring s) { 
    101       std::wstring::size_type pend = s.find_first_not_of(_T("0123456789,.")); 
    102       if (pend != std::wstring::npos) 
     146 
     147    template<class T> 
     148    static double trim_to_double(T s) { 
     149      typename T::size_type pend = s.find_first_not_of(nscapi::traits::perf_data_consts<T>::get_valid_perf_numbers()); 
     150      if (pend != T::npos) 
    103151        s = s.substr(0,pend); 
    104       strEx::replace(s, _T(","), _T(".")); 
     152      strEx::replace(s, nscapi::traits::perf_data_consts<T>::get_replace_perf_coma_src(), nscapi::traits::perf_data_consts<T>::get_replace_perf_coma_tgt()); 
    105153      return strEx::stod(s); 
    106154    } 
     155 
     156     
    107157 
    108158    struct decoded_simple_command_data { 
     
    280330      Plugin::SubmitRequestMessage request; 
    281331      request.mutable_header()->CopyFrom(response.header()); 
     332      request.mutable_header()->set_source_id(request.mutable_header()->recipient_id()); 
    282333      request.set_channel(to_string(channel)); 
    283334      for (int i=0;i<response.payload_size();++i) { 
     
    287338      } 
    288339      message = request.SerializeAsString(); 
     340    } 
     341 
     342    static void make_query_from_exec(std::string &data) { 
     343      Plugin::ExecuteResponseMessage exec_response_message; 
     344      exec_response_message.ParseFromString(data); 
     345      Plugin::QueryResponseMessage query_response_message; 
     346      query_response_message.mutable_header()->CopyFrom(exec_response_message); 
     347      for (int i=0;i<exec_response_message.payload_size();++i) { 
     348        Plugin::ExecuteResponseMessage::Response p = exec_response_message.payload(i); 
     349        append_simple_query_response_payload(query_response_message.add_payload(), p.command(), p.result(), p.message()); 
     350      } 
     351      data = query_response_message.SerializeAsString(); 
     352    } 
     353    static void make_query_from_submit(std::string &data) { 
     354      Plugin::SubmitResponseMessage submit_response_message; 
     355      submit_response_message.ParseFromString(data); 
     356      Plugin::QueryResponseMessage query_response_message; 
     357      query_response_message.mutable_header()->CopyFrom(submit_response_message); 
     358      for (int i=0;i<submit_response_message.payload_size();++i) { 
     359        Plugin::SubmitResponseMessage::Response p = submit_response_message.payload(i); 
     360        append_simple_query_response_payload(query_response_message.add_payload(), p.command(), gbp_status_to_gbp_nagios(p.status().status()), p.status().message(), ""); 
     361      } 
     362      data = query_response_message.SerializeAsString(); 
     363    } 
     364 
     365    static void make_exec_from_submit(std::string &data) { 
     366      Plugin::SubmitResponseMessage submit_response_message; 
     367      submit_response_message.ParseFromString(data); 
     368      Plugin::ExecuteResponseMessage exec_response_message; 
     369      exec_response_message.mutable_header()->CopyFrom(submit_response_message); 
     370      for (int i=0;i<submit_response_message.payload_size();++i) { 
     371        Plugin::SubmitResponseMessage::Response p = submit_response_message.payload(i); 
     372        append_simple_exec_response_payload(exec_response_message.add_payload(), p.command(), gbp_status_to_gbp_nagios(p.status().status()), p.status().message()); 
     373      } 
     374      data = exec_response_message.SerializeAsString(); 
     375    } 
     376    static void make_exec_from_query(std::string &data) { 
     377      Plugin::QueryResponseMessage query_response_message; 
     378      query_response_message.ParseFromString(data); 
     379      Plugin::ExecuteResponseMessage exec_response_message; 
     380      exec_response_message.mutable_header()->CopyFrom(query_response_message); 
     381      for (int i=0;i<query_response_message.payload_size();++i) { 
     382        Plugin::QueryResponseMessage::Response p = query_response_message.payload(i); 
     383        std::string s = build_performance_data(p); 
     384        if (!s.empty()) 
     385          s = p.message() + "|" + s; 
     386        else 
     387          s = p.message(); 
     388        append_simple_exec_response_payload(exec_response_message.add_payload(), p.command(), p.result(), s); 
     389      } 
     390      data = exec_response_message.SerializeAsString(); 
     391    } 
     392 
     393 
     394    static void make_return_header(::Plugin::Common_Header *target, const ::Plugin::Common_Header &source) { 
     395      target->CopyFrom(source); 
     396      target->set_source_id(target->recipient_id()); 
    289397    } 
    290398 
     
    409517      return NSCAPI::returnUNKNOWN; 
    410518    } 
     519    static NSCAPI::nagiosReturn create_simple_query_response_unknown(std::wstring command, std::wstring msg, std::string &buffer) { 
     520      create_simple_query_response(command, NSCAPI::returnUNKNOWN, msg, _T(""), buffer); 
     521      return NSCAPI::returnUNKNOWN; 
     522    } 
    411523 
    412524    static void create_simple_query_response(std::wstring command, NSCAPI::nagiosReturn ret, std::wstring msg, std::wstring perf, std::string &buffer) { 
     
    436548    } 
    437549 
    438     static void append_simple_exec_response_payload(Plugin::ExecuteResponseMessage::Response *payload, std::wstring command, NSCAPI::nagiosReturn ret, std::wstring msg) { 
     550    template<class T> 
     551    static void append_response_payloads(T &target_message, std::string &payload) { 
     552      T source_message; 
     553      source_message.ParseFromString(payload); 
     554      for (int i=0;i<source_message.payload_size();++i) 
     555        target_message.add_payload()->CopyFrom(source_message.payload(i)); 
     556    } 
     557 
     558    static void append_simple_query_response_payload(Plugin::QueryResponseMessage::Response *payload, std::string command, NSCAPI::nagiosReturn ret, std::string msg, std::string perf = "") { 
    439559      payload->set_command(to_string(command)); 
    440560      payload->set_message(to_string(msg)); 
    441561      payload->set_result(nagios_status_to_gpb(ret)); 
     562      if (!perf.empty()) 
     563        parse_performance_data(payload, perf); 
     564    } 
     565/* 
     566    static void append_simple_exec_response_payload(Plugin::ExecuteResponseMessage::Response *payload, std::string command, Plugin::Common::ResultCode ret, std::string msg) { 
     567      payload->set_command(command); 
     568      payload->set_message(msg); 
     569      payload->set_result(ret); 
     570    } 
     571    */ 
     572    static void append_simple_exec_response_payload(Plugin::ExecuteResponseMessage::Response *payload, std::string command, int ret, std::string msg) { 
     573      payload->set_command(command); 
     574      payload->set_message(msg); 
     575      payload->set_result(nagios_status_to_gpb(ret)); 
     576    } 
     577    /* 
     578    static void append_simple_submit_response_payload(Plugin::SubmitResponseMessage::Response *payload, std::string command, Plugin::Common::ResultCode ret, std::string msg) { 
     579      payload->set_command(command); 
     580      payload->mutable_status()->set_status(gbp_to_nagios_gbp_status(ret)); 
     581      payload->mutable_status()->set_message(msg); 
     582    } 
     583    */ 
     584    static void append_simple_submit_response_payload(Plugin::SubmitResponseMessage::Response *payload, std::string command, int ret, std::string msg) { 
     585      payload->set_command(command); 
     586      payload->mutable_status()->set_status(status_to_gpb(ret)); 
     587      payload->mutable_status()->set_message(msg); 
    442588    } 
    443589 
     
    546692    } 
    547693 
    548     static void create_simple_exec_response(std::wstring command, NSCAPI::nagiosReturn ret, std::wstring result, std::string &response) { 
     694    template<class T> 
     695    static int create_simple_exec_response(T command, NSCAPI::nagiosReturn ret, T result, std::string &response) { 
    549696      Plugin::ExecuteResponseMessage message; 
    550697      create_simple_header(message.mutable_header()); 
     
    556703      payload->set_result(nagios_status_to_gpb(ret)); 
    557704      message.SerializeToString(&response); 
     705      return ret; 
     706    } 
     707    template<class T> 
     708    static int create_simple_exec_response_unknown(T command, T result, std::string &response) { 
     709      Plugin::ExecuteResponseMessage message; 
     710      create_simple_header(message.mutable_header()); 
     711 
     712      Plugin::ExecuteResponseMessage::Response *payload = message.add_payload(); 
     713      payload->set_command(to_string(command)); 
     714      payload->set_message(to_string(result)); 
     715 
     716      payload->set_result(nagios_status_to_gpb(NSCAPI::returnUNKNOWN)); 
     717      message.SerializeToString(&response); 
     718      return NSCAPI::returnUNKNOWN; 
    558719    } 
    559720    static decoded_simple_command_data parse_simple_exec_request(const wchar_t* char_command, const std::string &request) { 
     
    587748    ////////////////////////////////////////////////////////////////////////// 
    588749 
    589     static void parse_performance_data(Plugin::QueryResponseMessage::Response *payload, std::wstring &perf) { 
    590       boost::tokenizer<boost::escaped_list_separator<wchar_t>, std::wstring::const_iterator, std::wstring> tok(perf, boost::escaped_list_separator<wchar_t>(L'\\', L' ', L'\'')); 
    591       BOOST_FOREACH(std::wstring s, tok) { 
     750    template<class T, class U> 
     751    struct tokenizer_data { 
     752      boost::escaped_list_separator<U> separator; // \\, ' ', \' 
     753      T perf_item_splitter;           // ;  
     754      T perf_equal_sign;              // = 
     755      T perf_valid_number;            // 0123456789., 
     756 
     757    }; 
     758 
     759    template<class T, class U> 
     760    static void parse_performance_data(Plugin::QueryResponseMessage::Response *payload, T &perf, tokenizer_data<T, U> tokenizer_data) { 
     761      boost::tokenizer<boost::escaped_list_separator<U>, typename T::const_iterator, T> tok(perf, tokenizer_data.separator); 
     762      BOOST_FOREACH(const T s, tok) { 
    592763        if (s.size() == 0) 
    593764          break; 
    594         strEx::splitVector items = strEx::splitV(s, _T(";")); 
     765        std::vector<T> items = strEx::splitV(s, tokenizer_data.perf_item_splitter); 
    595766        if (items.size() < 1) { 
    596767          Plugin::Common::PerformanceData* perfData = payload->add_perf(); 
    597768          perfData->set_type(Plugin::Common_DataType_STRING); 
    598           std::pair<std::wstring,std::wstring> fitem = strEx::split(_T(""), _T("=")); 
     769          std::pair<T,T> fitem = strEx::split(T(), tokenizer_data.perf_equal_sign); 
    599770          perfData->set_alias("invalid"); 
    600771          Plugin::Common_PerformanceData_StringValue* stringPerfData = perfData->mutable_string_value(); 
     
    605776        Plugin::Common::PerformanceData* perfData = payload->add_perf(); 
    606777        perfData->set_type(Plugin::Common_DataType_FLOAT); 
    607         std::pair<std::wstring,std::wstring> fitem = strEx::split(items[0], _T("=")); 
     778        std::pair<T,T> fitem = strEx::split(items[0], tokenizer_data.perf_equal_sign); 
    608779        perfData->set_alias(to_string(fitem.first)); 
    609780        Plugin::Common_PerformanceData_FloatValue* floatPerfData = perfData->mutable_float_value(); 
    610781 
    611         std::wstring::size_type pend = fitem.second.find_first_not_of(_T("0123456789,.")); 
    612         if (pend == std::wstring::npos) { 
    613           floatPerfData->set_value(trim_to_double(fitem.second.c_str())); 
     782        typename T::size_type pend = fitem.second.find_first_not_of(tokenizer_data.perf_valid_number); 
     783        if (pend == T::npos) { 
     784          floatPerfData->set_value(trim_to_double(fitem.second)); 
    614785        } else { 
    615           floatPerfData->set_value(trim_to_double(fitem.second.substr(0,pend).c_str())); 
     786          floatPerfData->set_value(trim_to_double(fitem.second.substr(0,pend))); 
    616787          floatPerfData->set_unit(to_string(fitem.second.substr(pend))); 
    617788        } 
     
    625796        } 
    626797      } 
    627 //      std::wcout << _T("Converting performance data") << perf << _T(" -- ") << utf8::cvt<std::wstring>(build_performance_data(*resp)) << std::endl; 
    628     } 
     798    } 
     799    static void parse_performance_data(Plugin::QueryResponseMessage::Response *payload, std::wstring &perf) { 
     800      typedef std::wstring t_string; 
     801      typedef wchar_t t_char; 
     802      tokenizer_data<t_string, t_char> data; 
     803      data.separator = boost::escaped_list_separator<t_char>(L'\\', L' ', L'\''); 
     804      data.perf_equal_sign = _T("="); 
     805      data.perf_item_splitter = _T(";"); 
     806      data.perf_valid_number = _T("0123456789,."); 
     807      parse_performance_data<t_string, t_char>(payload, perf, data); 
     808    } 
     809    static void parse_performance_data(Plugin::QueryResponseMessage::Response *payload, std::string &perf) { 
     810      typedef std::string t_string; 
     811      typedef char t_char; 
     812      tokenizer_data<t_string, t_char> data; 
     813      data.separator = boost::escaped_list_separator<t_char>('\\', ' ', '\''); 
     814      data.perf_equal_sign = "="; 
     815      data.perf_item_splitter = ";"; 
     816      data.perf_valid_number = "0123456789,."; 
     817      parse_performance_data<t_string, t_char>(payload, perf, data); 
     818    } 
     819 
    629820    static std::string build_performance_data(Plugin::QueryResponseMessage::Response const &payload) { 
    630821      std::stringstream ss; 
  • include/strEx.h

    r96c1461 rf33c12f  
    548548    return boost::lexical_cast<int>(s.c_str()); 
    549549  } 
    550   inline double stod(std::wstring s) { 
     550  template<class T> 
     551  inline double stod(T s) { 
    551552    return boost::lexical_cast<double>(s.c_str()); 
    552553  } 
     
    749750  } 
    750751  typedef std::vector<std::wstring> splitVector; 
    751   inline splitVector splitV(const std::wstring str, const std::wstring key) { 
    752     splitVector ret; 
    753     std::wstring::size_type pos = 0, lpos = 0; 
    754     while ((pos = str.find(key, pos)) !=  std::wstring::npos) { 
     752  template<class T> 
     753  inline std::vector<T> splitV(const T str, const T key) { 
     754    std::vector<T> ret; 
     755    typename T::size_type pos = 0, lpos = 0; 
     756    while ((pos = str.find(key, pos)) !=  T::npos) { 
    755757      ret.push_back(str.substr(lpos, pos-lpos)); 
    756758      lpos = ++pos; 
     
    789791    return trim_left( trim_right( str , t) , t ); 
    790792  }  
    791   inline std::pair<std::wstring,std::wstring> split(std::wstring str, std::wstring key) { 
    792     std::wstring::size_type pos = str.find(key); 
    793     if (pos == std::wstring::npos) 
    794       return std::pair<std::wstring,std::wstring>(str, _T("")); 
    795     return std::pair<std::wstring,std::wstring>(str.substr(0, pos), str.substr(pos+key.length())); 
     793  template<class T> 
     794  inline std::pair<T,T> split(T str, T key) { 
     795    typename T::size_type pos = str.find(key); 
     796    if (pos == T::npos) 
     797      return std::pair<T,T>(str, T()); 
     798    return std::pair<T,T>(str.substr(0, pos), str.substr(pos+key.length())); 
    796799  } 
    797800  typedef std::pair<std::wstring,std::wstring> token; 
     
    10561059      return utf8::cvt<std::string>(arg); 
    10571060    } 
     1061    template <typename T> std::string to_string(const wchar_t* arg) { 
     1062      return utf8::cvt<std::string>(std::wstring(arg)); 
     1063    } 
    10581064    template <typename T> std::wstring to_wstring(const T& arg) { 
    10591065      try { 
  • include/utils.h

    r7443b58 rf33c12f  
    3131#define MAP_OPTIONS_BEGIN(args) \ 
    3232  for (std::list<std::wstring>::const_iterator cit__=args.begin();cit__!=args.end();++cit__) { \ 
    33   std::pair<std::wstring,std::wstring> p__ = strEx::split(*cit__,_T("=")); if (false) {} 
     33  std::pair<std::wstring,std::wstring> p__ = strEx::split(*cit__,std::wstring(_T("="))); if (false) {} 
    3434 
    3535#define MAP_OPTIONS_SHOWALL(obj) \ 
     
    108108#define MAP_OPTIONS_SECONDARY_BEGIN(splt, arg) \ 
    109109  else if (p__.first.find(splt) != std::wstring::npos) { \ 
    110   std::pair<std::wstring,std::wstring> arg = strEx::split(p__.first,splt); if (false) {} 
     110  std::pair<std::wstring,std::wstring> arg = strEx::split(p__.first,std::wstring(splt)); if (false) {} 
    111111 
    112112#define MAP_OPTIONS_SECONDARY_STR_AND(opt, value, objfirst, objsecond, extra) \ 
Note: See TracChangeset for help on using the changeset viewer.