From 0d1120fd953249ad6292b8684a2accb8890fb4ef Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Thu, 5 May 2011 13:51:58 +0300 Subject: [PATCH] Compilation issues fixed --- projects/sgauthstress/main.cpp | 197 ++++--------------------- projects/sgauthstress/settings.cpp | 17 ++- projects/sgauthstress/settings.h | 2 +- projects/sgauthstress/store_loader.cpp | 9 +- projects/sgauthstress/store_loader.h | 5 +- 5 files changed, 47 insertions(+), 183 deletions(-) diff --git a/projects/sgauthstress/main.cpp b/projects/sgauthstress/main.cpp index 96c58203..3460457a 100644 --- a/projects/sgauthstress/main.cpp +++ b/projects/sgauthstress/main.cpp @@ -25,104 +25,45 @@ */ #include -#include -#include -#include #include -#include -#include #include -#include #include "stg/ia.h" #include "stg/common.h" -#include "web.h" -#include "settings_impl.h" -int mes; -char infoText[256]; -char messageText[256]; - -const int winKOI = 0; - -IA_CLIENT_PROT * clnp; -WEB * web = NULL; - -using namespace std; +#include "settings.h" time_t stgTime; +bool running; //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- void Usage() { -printf("sgauth \n"); +std::cout << "sgauth " << std::endl; } //----------------------------------------------------------------------------- -void SetDirName(const vector & dn, void *) +void StatUpdate(const LOADSTAT &, void *) { -for (int j = 0; j < DIR_NUM; j++) - { - if (winKOI) - { - string dir; - KOIToWin(dn[j], &dir); - if (web) - web->SetDirName(dir, j); - } - else - { - if (web) - web->SetDirName(dn[j], j); - } - } -} -//----------------------------------------------------------------------------- -void StatUpdate(const LOADSTAT & ls, void *) -{ -if (web) - web->UpdateStat(ls); } //----------------------------------------------------------------------------- void StatusChanged(int, void *) { } //----------------------------------------------------------------------------- -void ShowMessage(const string & message, int i, int, int, void *) -{ -if (web) - web->AddMessage(message, i); -} -//----------------------------------------------------------------------------- -void ShowError(const string & message, int, void *) +void ShowMessage(const string &, int, int, int, void *) { -if (web) - web->AddMessage(message, 0); } //----------------------------------------------------------------------------- -void CatchUSR1(int) +void ShowError(const string &, int, void *) { -if (clnp->GetAuthorized()) - { - cout << "Connect" << endl; - clnp->Connect(); - } -} -//----------------------------------------------------------------------------- -void CatchUSR2(int) -{ -cout << "Disconnect" << endl; -clnp->Disconnect(); } //----------------------------------------------------------------------------- void CatchTERM(int) { -cout << "Terminated" << endl; -clnp->Disconnect(); -sleep(2); -exit(0); +running = false; } //----------------------------------------------------------------------------- static void SetSignalHandlers() @@ -144,135 +85,51 @@ newsa.sa_mask = sigmask; newsa.sa_flags = 0; sigaction(SIGINT, &newsa, &oldsa); -sigemptyset(&sigmask); -sigaddset(&sigmask, SIGUSR1); -newsa.sa_handler = CatchUSR1; -newsa.sa_mask = sigmask; -newsa.sa_flags = 0; -sigaction(SIGUSR1, &newsa, &oldsa); - -sigemptyset(&sigmask); -sigaddset(&sigmask, SIGUSR2); -newsa.sa_handler = CatchUSR2; -newsa.sa_mask = sigmask; -newsa.sa_flags = 0; -sigaction(SIGUSR2, &newsa, &oldsa); - return; } //----------------------------------------------------------------------------- int main(int argc, char *argv[]) { -SETTINGS_IMPL settings; +SETTINGS settings; if (argc == 2) { settings.SetConfFile(argv[1]); } -else - { - // Usage - } if (settings.ReadSettings()) { - printf("ReadSettingsError\n"); - printf("%s\n", settings.GetStrError().c_str()); - exit(-1); + std::cerr << "Failed to read settings\n" + << settings.GetStrError() << std::endl; + Usage(); + return -1; } -settings.Print(); - -if (settings.GetDaemon()) - { - switch (fork()) - { - case -1: - exit(1); - break; - case 0: - setsid(); - break; - - default: - exit(0); - break; - } - } - -clnp = new IA_CLIENT_PROT(settings.GetServerName(), settings.GetServerPort(), settings.GetLocalPort()); - -if (!settings.GetNoWeb()) - { - web = new WEB(); - web->SetRefreshPagePeriod(settings.GetRefreshPeriod()); - web->SetListenAddr(settings.GetListenWebIP()); - web->Start(); - } - -clnp->SetLogin(settings.GetLogin()); -clnp->SetPassword(settings.GetPassword()); - -clnp->SetStatusChangedCb(StatusChanged, NULL); -clnp->SetInfoCb(ShowMessage, NULL); -clnp->SetErrorCb(ShowError, NULL); -clnp->SetDirNameCb(SetDirName, NULL); -clnp->SetStatChangedCb(StatUpdate, NULL); -clnp->SetReconnect(settings.GetReconnect()); +SetSignalHandlers(); -clnp->Start(); +IA_CLIENT_PROT proto(settings.GetServerName(), settings.GetServerPort(), settings.GetLocalPort()); -SetSignalHandlers(); +proto.SetLogin(settings.GetLogin()); +proto.SetPassword(settings.GetPassword()); -#ifdef LINUX -for (int i = 1; i < argc; i++) - memset(argv[i], 0, strlen(argv[i])); +proto.SetStatusChangedCb(StatusChanged, NULL); +proto.SetInfoCb(ShowMessage, NULL); +proto.SetErrorCb(ShowError, NULL); +proto.SetStatChangedCb(StatUpdate, NULL); -if(argc > 1) - strcpy(argv[1], "Connecting..."); -#endif +proto.Start(); -#ifdef FREEBSD -setproctitle("Connecting..."); -#endif -clnp->Connect(); +proto.Connect(); -while (1) +running = true; +while (running) { usleep(200000); + } - char state[20]; - - if (clnp->GetAuthorized()) - { - if (settings.GetShowPid()) - sprintf(state, "On %d", getpid()); - else - strcpy(state, "Online"); - } - else - { - if (settings.GetShowPid()) - sprintf(state, "Off %d", getpid()); - else - strcpy(state, "Offline"); - } - - #ifdef LINUX - for (int i = 1; i < argc; i++) - memset(argv[i], 0, strlen(argv[i])); - if(argc > 1) - strcpy(argv[1], state); - #endif - - #ifdef FREEBSD - setproctitle(state); - #endif +proto.Disconnect(); - #ifdef FREEBSD_5 - setproctitle(state); - #endif - } +proto.Stop(); return 0; } diff --git a/projects/sgauthstress/settings.cpp b/projects/sgauthstress/settings.cpp index 9055ceed..ce8fe864 100644 --- a/projects/sgauthstress/settings.cpp +++ b/projects/sgauthstress/settings.cpp @@ -35,7 +35,7 @@ SETTINGS::SETTINGS() { } //----------------------------------------------------------------------------- -int ParseYesNo(const string & value, bool * val) +int ParseYesNo(const std::string & value, bool * val) { if (0 == strcasecmp(value.c_str(), "yes")) { @@ -51,7 +51,7 @@ if (0 == strcasecmp(value.c_str(), "no")) return -1; } //----------------------------------------------------------------------------- -int ParseInt(const string & value, int * val) +int ParseInt(const std::string & value, int * val) { if (str2x(value, *val)) return -1; @@ -59,7 +59,7 @@ if (str2x(value, *val)) return 0; } //----------------------------------------------------------------------------- -int ParseUnsigned(const string & value, unsigned * val) +int ParseUnsigned(const std::string & value, unsigned * val) { if (str2x(value, *val)) return -1; @@ -67,7 +67,7 @@ if (str2x(value, *val)) return 0; } //----------------------------------------------------------------------------- -int ParseIntInRange(const string & value, int min, int max, int * val) +int ParseIntInRange(const std::string & value, int min, int max, int * val) { if (ParseInt(value, val) != 0) return -1; @@ -78,7 +78,7 @@ if (*val < min || *val > max) return 0; } //----------------------------------------------------------------------------- -int ParseUnsignedInRange(const string & value, unsigned min, unsigned max, unsigned * val) +int ParseUnsignedInRange(const std::string & value, unsigned min, unsigned max, unsigned * val) { if (ParseUnsigned(value, val) != 0) return -1; @@ -99,6 +99,7 @@ while (childNode) PARAM_VALUE pv; pv.param = childNode->getName(); int i = 0; + const char * value; while ((value = childNode->getValue(i++)) != NULL) pv.value.push_back(value); params->push_back(pv); @@ -116,7 +117,7 @@ const char * requiredOptions[] = { "Login", "Password", "ServerName", - "ServerPort" + "ServerPort", NULL }; @@ -144,19 +145,23 @@ while (node) else if (strcasecmp(node->getName(), "ServerName") == 0) serverName = node->getValue(0); else if (strcasecmp(node->getName(), "ServerPort") == 0) + { if (ParseIntInRange(node->getValue(0), 1, 65535, &port)) { strError = "Parameter 'ServerPort' is not valid."; printfd(__FILE__, "SETTINGS::ReadSettings() - %s\n", strError.c_str()); return -1; } + } else if (strcasecmp(node->getName(), "LocalPort") == 0) + { if (ParseIntInRange(node->getValue(0), 0, 65535, &localPort)) { strError = "Parameter 'LocalPort' is not valid."; printfd(__FILE__, "SETTINGS::ReadSettings() - %s\n", strError.c_str()); return -1; } + } else if (strcasecmp(node->getName(), "StoreModule") == 0) { if (node->getValue(1)) diff --git a/projects/sgauthstress/settings.h b/projects/sgauthstress/settings.h index b933fa74..01542086 100644 --- a/projects/sgauthstress/settings.h +++ b/projects/sgauthstress/settings.h @@ -24,8 +24,8 @@ #include #include "stg/os_int.h" +#include "stg/module_settings.h" -struct MODULE_SETTINGS; class DOTCONFDocumentNode; class SETTINGS { diff --git a/projects/sgauthstress/store_loader.cpp b/projects/sgauthstress/store_loader.cpp index c54bdb36..ab7291e2 100644 --- a/projects/sgauthstress/store_loader.cpp +++ b/projects/sgauthstress/store_loader.cpp @@ -31,17 +31,18 @@ #include #include "stg/common.h" +#include "stg/module_settings.h" #include "stg/store.h" #include "store_loader.h" -#include "settings_impl.h" -STORE_LOADER::STORE_LOADER(const SETTINGS_IMPL & settings) +STORE_LOADER::STORE_LOADER(const std::string & modulesPath, + const MODULE_SETTINGS & settings) : isLoaded(false), handle(NULL), plugin(NULL), errorStr(), - storeSettings(settings.GetStoreModuleSettings()), - pluginFileName(settings.GetModulesPath() + "/mod_" + storeSettings.moduleName + ".so") + storeSettings(settings), + pluginFileName(modulesPath + "/mod_" + storeSettings.moduleName + ".so") { } diff --git a/projects/sgauthstress/store_loader.h b/projects/sgauthstress/store_loader.h index c7911eea..91d6e7cf 100644 --- a/projects/sgauthstress/store_loader.h +++ b/projects/sgauthstress/store_loader.h @@ -37,11 +37,12 @@ #include "stg/noncopyable.h" class STORE; -class SETTINGS_IMPL; +class MODULE_SETTINGS; class STORE_LOADER : private NONCOPYABLE { public: - STORE_LOADER(const SETTINGS_IMPL & settings); + STORE_LOADER(const std::string & modulesPath, + const MODULE_SETTINGS & settings); ~STORE_LOADER(); bool Load(); -- 2.44.2