-SETTINGS::SETTINGS()
- : port(0),
- localPort(0),
- listenWebIP(0),
- refreshPeriod(0),
- daemon(false),
- noWeb(false),
- reconnect(false),
- showPid(false)
-{
-confFile = "/etc/sgauth.conf";
-}
-//-----------------------------------------------------------------------------
-void SETTINGS::SetConfFile(string confFile)
-{
-SETTINGS::confFile = confFile;
-}
-//-----------------------------------------------------------------------------
-int SETTINGS::ReadSettings()
-{
-CONFIGFILE * cf;
-
-cf = new CONFIGFILE(confFile);
-string tmp;
-int e = cf->Error();
-
-if (e)
- {
- printf("Cannot read file.\n");
- delete cf;
- return -1;
- }
-
-cf->ReadString("Login", &login, "/?--?--?*");
-if (login == "/?--?--?*")
- {
- strError = "Parameter \'Login\' not found.";
- delete cf;
- return -1;
- }
-
-cf->ReadString("Password", &password, "/?--?--?*");
-if (login == "/?--?--?*")
- {
- strError = "Parameter \'Password\' not found.";
- delete cf;
- return -1;
- }
-
-cf->ReadString("ServerName", &serverName, "?*?*?");
-if (serverName == "?*?*?")
- {
- strError = "Parameter \'ServerName\' not found.";
- delete cf;
- return -1;
- }
-
-cf->ReadString("ListenWebIP", &tmp, "127.0.0.1");
-listenWebIP = inet_addr(tmp.c_str());
-if (listenWebIP == INADDR_NONE)
- {
- strError = "Parameter \'ListenWebIP\' is not valid.";
- delete cf;
- return -1;
- }
-
-cf->ReadString("ServerPort", &tmp, "5555");
-if (ParseIntInRange(tmp, 1, 65535, &port))
- {
- strError = "Parameter \'ServerPort\' is not valid.";
- delete cf;
- return -1;
- }
-
-cf->ReadString("LocalPort", &tmp, "0");
-if (ParseIntInRange(tmp, 0, 65535, &localPort))
- {
- strError = "Parameter \'LocalPort\' is not valid.";
- delete cf;
- return -1;
- }
-
-printf("LocalPort=%d\n", localPort);
-
-cf->ReadString("RefreshPeriod", &tmp, "5");
-if (ParseIntInRange(tmp, 1, 24*3600, &refreshPeriod))
- {
- strError = "Parameter \'RefreshPeriod\' is not valid.";
- delete cf;
- return -1;
- }
-
-cf->ReadString("Reconnect", &tmp, "yes");
-if (ParseYesNo(tmp, &reconnect))
- {
- strError = "Parameter \'Reconnect\' is not valid.";
- delete cf;
- return -1;
- }
-
-cf->ReadString("Daemon", &tmp, "yes");
-if (ParseYesNo(tmp, &daemon))
- {
- strError = "Parameter \'Daemon\' is not valid.";
- delete cf;
- return -1;
- }
-
-cf->ReadString("ShowPid", &tmp, "no");
-if (ParseYesNo(tmp, &showPid))
- {
- strError = "Parameter \'ShowPid\' is not valid.";
- delete cf;
- return -1;
- }
-
-cf->ReadString("DisableWeb", &tmp, "no");
-if (ParseYesNo(tmp, &noWeb))
- {
- strError = "Parameter \'DisableWeb\' is not valid.";
- delete cf;
- return -1;
- }
-
-delete cf;
-return 0;
-}
-//-----------------------------------------------------------------------------
-string SETTINGS::GetStrError() const
-{
-return strError;
-}
-//-----------------------------------------------------------------------------
-string SETTINGS::GetLogin() const
-{
-return login;
-}
-//-----------------------------------------------------------------------------
-string SETTINGS::GetPassword() const
-{
-return password;
-}
-//-----------------------------------------------------------------------------
-string SETTINGS::GetServerName() const
-{
-return serverName;
-}
-//-----------------------------------------------------------------------------
-uint16_t SETTINGS::GetServerPort() const
-{
-return port;
-}
-//-----------------------------------------------------------------------------
-uint16_t SETTINGS::GetLocalPort() const
-{
-return localPort;
-}
-//-----------------------------------------------------------------------------
-int SETTINGS::GetRefreshPeriod() const
-{
-return refreshPeriod;
-}
-//-----------------------------------------------------------------------------
-bool SETTINGS::GetDaemon() const
-{
-return daemon;
-}
-//-----------------------------------------------------------------------------
-bool SETTINGS::GetNoWeb() const
-{
-return noWeb;
-}
-//-----------------------------------------------------------------------------
-bool SETTINGS::GetShowPid() const
-{
-return showPid;
-}
-//-----------------------------------------------------------------------------
-bool SETTINGS::GetReconnect() const
-{
-return reconnect;
-}
-//-----------------------------------------------------------------------------
-uint32_t SETTINGS::GetListenWebIP() const
-{
-return listenWebIP;
-}
-//-----------------------------------------------------------------------------
-void SETTINGS::Print() const
-{
-cout << "login = " << login << endl;
-cout << "password = " << password << endl;
-cout << "ip = " << serverName << endl;
-cout << "port = " << port << endl;
-cout << "localPort = " << localPort << endl;
-cout << "listenWebIP = " << inet_ntostring(listenWebIP) << endl;
-cout << "DisableWeb = " << noWeb << endl;
-cout << "refreshPeriod = " << refreshPeriod << endl;
-cout << "daemon = " << daemon << endl;
-cout << "reconnect = " << reconnect << endl;
-}