Changeset d05c3f0 in nscp for service/NSClient++.cpp


Ignore:
Timestamp:
11/15/09 17:20:03 (4 years ago)
Author:
Michael Medin <michael@…>
Branches:
master, 0.4.0, 0.4.1, 0.4.2
Children:
92c4b5b
Parents:
3eedfa6
Message:

Next major "milestone" we now have one working plugin (CheckHelpers) which loads and works both on Linux and Windows.
This is (as always) a broken build which many many features disabled and non functional...

File:
1 edited

Legend:

Unmodified
Added
Removed
  • service/NSClient++.cpp

    r818b54e rd05c3f0  
    8484 
    8585  static bool start(unsigned long  dwSessionId) { 
    86     std::wstring program = mainClient.getBasePath() +  _T("\\") +  
    87       SETTINGS_GET_STRING_CORE(settings_def::SYSTRAY_EXE); 
    88     std::wstring cmdln = _T("\"") + program + _T("\" -channel __") + strEx::itos(dwSessionId) + _T("__"); 
    89     return tray_starter::startTrayHelper(dwSessionId, program, cmdln); 
     86    boost::filesystem::wpath program = mainClient.getBasePath() / SETTINGS_GET_STRING_CORE(settings_def::SYSTRAY_EXE); 
     87    std::wstring cmdln = _T("\"") + program.string() + _T("\" -channel __") + strEx::itos(dwSessionId) + _T("__"); 
     88    return tray_starter::startTrayHelper(dwSessionId, program.string(), cmdln); 
    9089  } 
    9190 
     
    205204 
    206205 
    207 bool is_module( std::wstring file )  
     206bool is_module(boost::filesystem::wpath file )  
    208207{ 
    209   return boost::ends_with(file, _T(".dll")); 
     208  return boost::ends_with(file.string(), _T(".dll")) || boost::ends_with(file.string(), _T(".so")); 
    210209} 
    211210/** 
     
    390389      return 0; 
    391390    } else if ( wcscasecmp( _T("about"), argv[1]+1 ) == 0 ) { 
    392       g_bConsoleLog = true; 
    393       LOG_MESSAGE(SZAPPNAME _T(" (C) Michael Medin - michael<at>medin<dot>name")); 
    394       LOG_MESSAGE(_T("Version: ") SZVERSION); 
    395       LOG_MESSAGE(_T("Architecture: ") SZARCH); 
    396  
    397       std::wstring pluginPath = mainClient.getBasePath() + _T("modules\\"); 
    398       LOG_MESSAGE_STD(_T("Looking at plugins in: ") + pluginPath); 
    399  
    400       boost::filesystem::wdirectory_iterator end_itr; // default construction yields past-the-end 
    401       for ( boost::filesystem::wdirectory_iterator itr( pluginPath ); itr != end_itr; ++itr ) { 
    402         if ( !is_directory(itr->status()) ) { 
    403           std::wstring file= itr->leaf(); 
    404           if (is_module(pluginPath + _T("\\") + file)) { 
    405             NSCPlugin *plugin = new NSCPlugin(pluginPath + _T("\\") + file); 
    406             std::wstring name = _T("<unknown>"); 
    407             std::wstring description = _T("<unknown>"); 
    408             try { 
    409               plugin->load_dll(); 
    410               name = plugin->getName(); 
    411               description = plugin->getDescription(); 
    412             } catch(const NSPluginException& e) { 
    413               LOG_ERROR_STD(_T("Exception raised: ") + e.error_ + _T(" in module: ") + e.file_); 
    414             } catch (std::exception e) { 
    415               LOG_ERROR_STD(_T("exception loading plugin: ") + strEx::string_to_wstring(e.what())); 
    416             } catch (...) { 
    417               LOG_ERROR_STD(_T("Unknown exception loading plugin")); 
    418             } 
    419             LOG_MESSAGE_STD(_T("* ") + name + _T(" (") + file + _T(")")); 
    420             std::list<std::wstring> list = strEx::splitEx(description, _T("\n")); 
    421             for (std::list<std::wstring>::const_iterator cit = list.begin(); cit != list.end(); ++cit) { 
    422               LOG_MESSAGE_STD(_T("    ") + *cit); 
     391      try { 
     392        g_bConsoleLog = true; 
     393        LOG_MESSAGE(SZAPPNAME _T(" (C) Michael Medin - michael<at>medin<dot>name")); 
     394        LOG_MESSAGE(_T("Version: ") SZVERSION); 
     395        LOG_MESSAGE(_T("Architecture: ") SZARCH); 
     396 
     397        boost::filesystem::wpath pluginPath = (boost::filesystem::wpath)mainClient.getBasePath() / _T("modules"); 
     398        LOG_MESSAGE_STD(_T("Looking at plugins in: ") + pluginPath.string()); 
     399 
     400        boost::filesystem::wdirectory_iterator end_itr; // default construction yields past-the-end 
     401        for ( boost::filesystem::wdirectory_iterator itr( pluginPath ); itr != end_itr; ++itr ) { 
     402          if ( !is_directory(itr->status()) ) { 
     403            std::wstring file= itr->leaf(); 
     404            LOG_MESSAGE_STD(_T("Found: ") + file); 
     405            if (is_module(pluginPath / file)) { 
     406              NSCPlugin *plugin = new NSCPlugin(pluginPath / file); 
     407              std::wstring name = _T("<unknown>"); 
     408              std::wstring description = _T("<unknown>"); 
     409              try { 
     410                plugin->load_dll(); 
     411                name = plugin->getName(); 
     412                description = plugin->getDescription(); 
     413              } catch(const NSPluginException& e) { 
     414                LOG_ERROR_STD(_T("Exception raised: ") + e.error_ + _T(" in module: ") + e.file_); 
     415              } catch (std::exception e) { 
     416                LOG_ERROR_STD(_T("exception loading plugin: ") + strEx::string_to_wstring(e.what())); 
     417              } catch (...) { 
     418                LOG_ERROR_STD(_T("Unknown exception loading plugin")); 
     419              } 
     420              LOG_MESSAGE_STD(_T("* ") + name + _T(" (") + file + _T(")")); 
     421              std::list<std::wstring> list = strEx::splitEx(description, _T("\n")); 
     422              for (std::list<std::wstring>::const_iterator cit = list.begin(); cit != list.end(); ++cit) { 
     423                LOG_MESSAGE_STD(_T("    ") + *cit); 
     424              } 
    423425            } 
    424426          } 
    425427        } 
     428        LOG_MESSAGE_STD(_T("Done listing plugins from: ") + pluginPath.string()); 
     429        return true; 
     430      } catch (std::exception &e) { 
     431        LOG_ERROR_STD(_T("Exception: ") + to_wstring(e.what())); 
     432      } catch (...) { 
     433        LOG_ERROR_STD(_T("Unknown Exception: ")); 
    426434      } 
    427435      return false; 
     
    568576NSClientT::plugin_info_list NSClientT::get_all_plugins() { 
    569577  plugin_info_list ret; 
    570   std::wstring pluginPath = getBasePath() + _T("modules\\"); 
     578  boost::filesystem::wpath pluginPath = getBasePath() / boost::filesystem::wpath(_T("modules")); 
    571579  boost::filesystem::wdirectory_iterator end_itr; // default construction yields past-the-end 
    572580  for ( boost::filesystem::wdirectory_iterator itr( pluginPath ); itr != end_itr; ++itr ) { 
    573581    if ( !is_directory(itr->status()) ) { 
    574       std::wstring file= itr->leaf(); 
    575       if (is_module(pluginPath + _T("\\") + file)) { 
     582      boost::filesystem::wpath file= itr->leaf(); 
     583      if (is_module(pluginPath  / file)) { 
    576584        plugin_info_type info; 
    577585        info.dll = itr->leaf(); 
    578586        try { 
    579           LOG_DEBUG_STD(_T("Attempting to fake load: ") + file); 
    580           NSCPlugin plugin(pluginPath + _T("\\") + file); 
     587          LOG_DEBUG_STD(_T("Attempting to fake load: ") + file.string()); 
     588          NSCPlugin plugin(pluginPath / file); 
    581589          plugin.load_dll(); 
    582590          plugin.load_plugin(NSCAPI::dontStart); 
     
    587595          LOG_CRITICAL_STD(_T("Error loading: ") + e.file_ + _T(" root cause: ") + e.error_); 
    588596        } catch (...) { 
    589           LOG_CRITICAL_STD(_T("Unknown Error loading: ") + file); 
     597          LOG_CRITICAL_STD(_T("Unknown Error loading: ") + file.string()); 
    590598        } 
    591599        ret.push_back(info); 
     
    598606 
    599607void NSClientT::load_all_plugins(int mode) { 
    600   std::wstring modPath = getBasePath() + _T("modules\\"); 
     608  boost::filesystem::wpath modPath = getBasePath() / boost::filesystem::wpath(_T("modules")); 
    601609 
    602610  boost::filesystem::wdirectory_iterator end_itr; // default construction yields past-the-end 
    603611  for ( boost::filesystem::wdirectory_iterator itr( modPath ); itr != end_itr; ++itr ) { 
    604612    if ( !is_directory(itr->status()) ) { 
    605       std::wstring file= itr->leaf(); 
    606       if (is_module(modPath + _T("\\") + file)) { 
    607         if (settings_manager::get_settings()->has_key(MAIN_MODULES_SECTION, file)) { 
    608           if (settings_manager::get_settings()->get_string(MAIN_MODULES_SECTION, file) == _T("disabled")) { 
     613      boost::filesystem::wpath file= itr->leaf(); 
     614      if (is_module(modPath / file)) { 
     615        if (settings_manager::get_settings()->has_key(MAIN_MODULES_SECTION, file.string())) { 
     616          if (settings_manager::get_settings()->get_string(MAIN_MODULES_SECTION, file.string()) == _T("disabled")) { 
    609617            try { 
    610               LOG_DEBUG_STD(_T("Attempting to fake load: ") + file); 
    611               NSCPlugin plugin(modPath + file); 
     618              LOG_DEBUG_STD(_T("Attempting to fake load: ") + file.string()); 
     619              NSCPlugin plugin(modPath / file); 
    612620              plugin.load_dll(); 
    613621              plugin.load_plugin(mode); 
     
    616624              LOG_CRITICAL_STD(_T("Error loading: ") + e.file_ + _T(" root cause: ") + e.error_); 
    617625            } catch (...) { 
    618               LOG_CRITICAL_STD(_T("Unknown Error loading: ") + file); 
     626              LOG_CRITICAL_STD(_T("Unknown Error loading: ") + file.string()); 
    619627            } 
    620628          } 
     
    622630          std::wstring desc; 
    623631          try { 
    624             NSCPlugin plugin(modPath + file); 
     632            NSCPlugin plugin(modPath / file); 
    625633            plugin.load_dll(); 
    626634            plugin.load_plugin(mode); 
     
    633641          } catch (...) { 
    634642            desc += _T("unknown module"); 
    635             LOG_CRITICAL_STD(_T("Unknown Error loading: ") + file); 
     643            LOG_CRITICAL_STD(_T("Unknown Error loading: ") + file.string()); 
    636644          } 
    637           settings_manager::get_core()->register_key(MAIN_MODULES_SECTION, file, Settings::SettingsCore::key_string, desc, desc, _T("disabled"), false); 
     645          settings_manager::get_core()->register_key(MAIN_MODULES_SECTION, file.string(), Settings::SettingsCore::key_string, desc, desc, _T("disabled"), false); 
    638646        } 
    639647      } 
     
    846854        } 
    847855        try { 
    848           loadPlugin(getBasePath() + _T("modules\\") + (*cit)); 
     856          loadPlugin(getBasePath() / boost::filesystem::wpath(_T("modules")) / boost::filesystem::wpath(*cit)); 
    849857        } catch(const NSPluginException& e) { 
    850           LOG_ERROR_STD(_T("Exception raised: ") + e.error_ + _T(" in module: ") + e.file_); 
     858          LOG_ERROR_STD(_T("Exception raised: '") + e.error_ + _T("' in module: ") + e.file_); 
    851859          //return false; 
    852860        } catch (std::exception e) { 
     
    10681076  } 
    10691077  try { 
    1070     plugin_type plugin = loadPlugin(getBasePath() + _T("modules\\") + module); 
    1071     LOG_DEBUG_STD(_T("Loading plugin: ") + plugin->getName() + _T("...")); 
    1072     plugin->load_plugin(NSCAPI::dontStart); 
    1073     return plugin->commandLineExec(command, argLen, args); 
    1074   } catch (NSPluginException e) { 
    1075     LOG_MESSAGE_STD(_T("Module (") + e.file_ + _T(") was not found: ") + e.error_); 
    1076   } 
    1077   try { 
    1078     plugin_type plugin = loadPlugin(getBasePath() + _T("modules\\") + module + _T(".dll")); 
     1078    plugin_type plugin = loadPlugin(getBasePath() / boost::filesystem::wpath(_T("modules")) / boost::filesystem::wpath(module)); 
    10791079    LOG_DEBUG_STD(_T("Loading plugin: ") + plugin->getName() + _T("...")); 
    10801080    plugin->load_plugin(NSCAPI::dontStart); 
     
    12081208 * @param file The DLL file 
    12091209 */ 
    1210 NSClientT::plugin_type NSClientT::loadPlugin(const std::wstring file) { 
     1210NSClientT::plugin_type NSClientT::loadPlugin(const boost::filesystem::wpath file) { 
    12111211  return addPlugin(new NSCPlugin(file)); 
    12121212} 
     
    15221522  } 
    15231523} 
    1524 std::wstring NSClientT::getBasePath(void) { 
     1524boost::filesystem::wpath NSClientT::getBasePath(void) { 
    15251525  boost::unique_lock<boost::timed_mutex> lock(internalVariables, boost::get_system_time() + boost::posix_time::seconds(5)); 
    15261526  if (!lock.owns_lock()) { 
     
    15381538  basePath = path.substr(0, pos) + _T("\\"); 
    15391539  delete [] buffer; 
     1540#else  
     1541  basePath = to_wstring(boost::filesystem::initial_path().string()); 
    15401542#endif 
    15411543  try { 
Note: See TracChangeset for help on using the changeset viewer.