is_set = true;
}
}
+ void maybeSet(value_type& dest) const
+ {
+ if (is_set)
+ dest = value;
+ }
private:
value_type value;
DIRPRICE_DATA GetData() const
{
DIRPRICE_DATA dd;
- dd.hDay = hDay.data();
- dd.hNight = hNight.data();
- dd.mDay = mDay.data();
- dd.mNight = mNight.data();
- dd.noDiscount = noDiscount.data();
- dd.priceDayA = priceDayA.data();
- dd.priceDayB = priceDayB.data();
-
- dd.priceNightA = priceNightA.data();
- dd.priceNightB = priceNightB.data();
- dd.singlePrice = singlePrice.data();
- dd.threshold = threshold.data();
+ hDay.maybeSet(dd.hDay);
+ hNight.maybeSet(dd.hNight);
+ mDay.maybeSet(dd.mDay);
+ mNight.maybeSet(dd.mNight);
+ noDiscount.maybeSet(dd.noDiscount);
+ priceDayA.maybeSet(dd.priceDayA);
+ priceDayB.maybeSet(dd.priceDayB);
+ priceNightA.maybeSet(dd.priceNightA);
+ priceNightB.maybeSet(dd.priceNightB);
+ singlePrice.maybeSet(dd.singlePrice);
+ threshold.maybeSet(dd.threshold);
return dd;
}
TARIFF_CONF GetData() const
{
TARIFF_CONF tc;
- tc.fee = fee.data();
- tc.free = free.data();
- tc.name = name.data();
- tc.passiveCost = passiveCost.data();
- tc.traffType = traffType.data();
- tc.period = period.data();
+ fee.maybeSet(tc.fee);
+ free.maybeSet(tc.free);
+ name.maybeSet(tc.name);
+ passiveCost.maybeSet(tc.passiveCost);
+ traffType.maybeSet(tc.traffType);
+ period.maybeSet(tc.period);
return tc;
}
inline
bool USER_IPS::OnlyOneIP() const
{
-if (ips.size() == 1 && ips.front().mask == 32)
+if (ips.size() == 1 && ips.front().mask == 32 && ips.front().ip != 0)
return true;
return false;
WriteServLog("+++++++++++++++++++++++++++++++++++++++++++++");
+manager.stop();
+
if (loop.Stop())
WriteServLog("Event loop not stopped.");
PluginManager::~PluginManager()
{
- std::sort(m_modules.begin(), m_modules.end(), StopModCmp);
- for (size_t i = 0; i < m_modules.size(); ++i)
- {
- PLUGIN & plugin = m_modules[i]->GetPlugin();
- if (m_modules[i]->Stop())
- {
- m_log("Failed to stop module '%s': '%s'", plugin.GetVersion().c_str(),
- plugin.GetStrError().c_str());
- printfd(__FILE__, "Failed to stop module '%s': '%s'\n", plugin.GetVersion().c_str(),
- plugin.GetStrError().c_str());
- }
- else
- {
- m_log("Module '%s' stopped successfully.", plugin.GetVersion().c_str());
- printfd(__FILE__, "Module '%s' stopped successfully.\n", plugin.GetVersion().c_str());
- }
- }
+ stop();
for (size_t i = 0; i < m_modules.size(); ++i)
delete m_modules[i];
}
}
}
}
+
+void PluginManager::stop()
+{
+ std::sort(m_modules.begin(), m_modules.end(), StopModCmp);
+ for (size_t i = 0; i < m_modules.size(); ++i)
+ {
+ if (!m_modules[i]->IsRunning())
+ continue;
+ PLUGIN & plugin = m_modules[i]->GetPlugin();
+ if (m_modules[i]->Stop())
+ {
+ m_log("Failed to stop module '%s': '%s'", plugin.GetVersion().c_str(),
+ plugin.GetStrError().c_str());
+ printfd(__FILE__, "Failed to stop module '%s': '%s'\n", plugin.GetVersion().c_str(),
+ plugin.GetStrError().c_str());
+ }
+ else
+ {
+ m_log("Module '%s' stopped successfully.", plugin.GetVersion().c_str());
+ printfd(__FILE__, "Module '%s' stopped successfully.\n", plugin.GetVersion().c_str());
+ }
+ }
+}
~PluginManager();
void reload(const SETTINGS_IMPL& settings);
+ void stop();
private:
std::vector<PLUGIN_RUNNER*> m_modules;
}
//-----------------------------------------------------------------------------
AUTH_AO::AUTH_AO()
- : errorStr(),
- users(NULL),
- usersList(),
+ : users(NULL),
isRunning(false),
- settings(),
- BeforeChgAONotifierList(),
- AfterChgAONotifierList(),
- BeforeChgIPNotifierList(),
- AfterChgIPNotifierList(),
onAddUserNotifier(*this),
onDelUserNotifier(*this),
logger(GetPluginLogger(GetStgLogger(), "auth_ao"))
///////////////////////////
pv.param = "Port";
pvi = find(s.moduleParams.begin(), s.moduleParams.end(), pv);
-if (pvi == s.moduleParams.end())
+if (pvi == s.moduleParams.end() || pvi->value.empty())
{
errorStr = "Parameter \'Port\' not found.";
printfd(__FILE__, "Parameter 'Port' not found\n");
///////////////////////////
pv.param = "UserDelay";
pvi = find(s.moduleParams.begin(), s.moduleParams.end(), pv);
-if (pvi == s.moduleParams.end())
+if (pvi == s.moduleParams.end() || pvi->value.empty())
{
errorStr = "Parameter \'UserDelay\' not found.";
printfd(__FILE__, "Parameter 'UserDelay' not found\n");
///////////////////////////
pv.param = "UserTimeout";
pvi = find(s.moduleParams.begin(), s.moduleParams.end(), pv);
-if (pvi == s.moduleParams.end())
+if (pvi == s.moduleParams.end() || pvi->value.empty())
{
errorStr = "Parameter \'UserTimeout\' not found.";
printfd(__FILE__, "Parameter 'UserTimeout' not found\n");
///////////////////////////
pv.param = "LogProtocolErrors";
pvi = find(s.moduleParams.begin(), s.moduleParams.end(), pv);
-if (pvi == s.moduleParams.end())
+if (pvi == s.moduleParams.end() || pvi->value.empty())
logProtocolErrors = false;
else if (ParseYesNo(pvi->value[0], &logProtocolErrors))
{
int n = 0;
pv.param = "FreeMb";
pvi = find(s.moduleParams.begin(), s.moduleParams.end(), pv);
-if (pvi == s.moduleParams.end())
+if (pvi == s.moduleParams.end() || pvi->value.empty())
{
errorStr = "Parameter \'FreeMb\' not found.";
printfd(__FILE__, "Parameter 'FreeMb' not found\n");
#ifdef IA_PHASE_DEBUG
IA_PHASE::IA_PHASE()
: phase(1),
- phaseTime(),
flog(NULL)
{
gettimeofday(&phaseTime, NULL);
}
#else
IA_PHASE::IA_PHASE()
- : phase(1),
- phaseTime()
+ : phase(1)
{
gettimeofday(&phaseTime, NULL);
}
NF_CAP::NF_CAP()
: traffCnt(NULL),
- settings(),
- tidTCP(),
- tidUDP(),
runningTCP(false),
runningUDP(false),
stoppedTCP(true),
portU(0),
sockTCP(-1),
sockUDP(-1),
- errorStr(),
logger(GetPluginLogger(GetStgLogger(), "cap_nf"))
{
}
std::vector<PARAM_VALUE>::iterator it;
for (it = settings.moduleParams.begin(); it != settings.moduleParams.end(); ++it)
{
- if (it->param == "TCPPort")
+ if (it->param == "TCPPort" && !it->value.empty())
{
if (str2x(it->value[0], portT))
{
}
continue;
}
- if (it->param == "UDPPort")
+ if (it->param == "UDPPort" && !it->value.empty())
{
if (str2x(it->value[0], portU))
{
}
//-----------------------------------------------------------------------------
DIVERT_CAP::DIVERT_CAP()
- : settings(),
- port(0),
+ : port(0),
disableForwarding(false),
- errorStr(),
- thread(),
nonstop(false),
isRunning(false),
traffCnt(NULL),
pv.param = "Port";
pvi = std::find(settings.moduleParams.begin(), settings.moduleParams.end(), pv);
-if (pvi == settings.moduleParams.end())
+if (pvi == settings.moduleParams.end() || pvi->value.empty())
{
p = 15701;
}
bool d = false;
pv.param = "DisableForwarding";
pvi = std::find(settings.moduleParams.begin(), settings.moduleParams.end(), pv);
-if (pvi == settings.moduleParams.end())
+if (pvi == settings.moduleParams.end() || pvi->value.empty())
{
disableForwarding = false;
}
}
//-----------------------------------------------------------------------------
BPF_CAP::BPF_CAP()
- : capSettings(),
- errorStr(),
- bpfData(),
- polld(),
- thread(),
- nonstop(false),
+ : nonstop(false),
isRunning(false),
capSock(-1),
- settings(),
traffCnt(NULL),
logger(GetPluginLogger(GetStgLogger(), "cap_bpf"))
{
}
//-----------------------------------------------------------------------------
ETHER_CAP::ETHER_CAP()
- : errorStr(),
- thread(),
- nonstop(false),
+ : nonstop(false),
isRunning(false),
capSock(-1),
traffCnt(NULL),
//-----------------------------------------------------------------------------
IPQ_CAP::IPQ_CAP()
: ipq_h(NULL),
- errorStr(),
- thread(),
nonstop(false),
isRunning(false),
capSock(-1),
traffCnt(NULL),
- buf(),
logger(GetPluginLogger(GetStgLogger(), "cap_ipq"))
{
memset(buf, 0, BUFSIZE);
}
//-----------------------------------------------------------------------------
NFQ_CAP::NFQ_CAP()
- : errorStr(),
- thread(),
- nonstop(false),
+ : nonstop(false),
isRunning(false),
queueNumber(0),
nfqHandle(NULL),
int NFQ_CAP::ParseSettings()
{
for (size_t i = 0; i < settings.moduleParams.size(); i++)
- if (settings.moduleParams[i].param == "queueNumber")
- if (str2x(settings.moduleParams[i].param, queueNumber) < 0)
+ if (settings.moduleParams[i].param == "queueNumber" && !settings.moduleParams[i].value.empty())
+ if (str2x(settings.moduleParams[i].value[0], queueNumber) < 0)
{
errorStr = "Queue number should be a number. Got: '" + settings.moduleParams[i].param + "'";
logger(errorStr);
extern "C" PLUGIN * GetPlugin();
RPC_CONFIG_SETTINGS::RPC_CONFIG_SETTINGS()
- : errorStr(),
- port(0),
+ : port(0),
cookieTimeout(0)
{
}
pv.param = "Port";
std::vector<PARAM_VALUE>::const_iterator pvi;
pvi = std::find(s.moduleParams.begin(), s.moduleParams.end(), pv);
-if (pvi == s.moduleParams.end())
+if (pvi == s.moduleParams.end() || pvi->value.empty())
{
errorStr = "Parameter \'Port\' not found.";
printfd(__FILE__, "Parameter 'Port' not found\n");
pv.param = "CookieTimeout";
pvi = std::find(s.moduleParams.begin(), s.moduleParams.end(), pv);
-if (pvi == s.moduleParams.end())
+if (pvi == s.moduleParams.end() || pvi->value.empty())
{
cookieTimeout = 1800; // 30 * 60
}
}
RPC_CONFIG::RPC_CONFIG()
- : errorStr(),
- rpcConfigSettings(),
- users(NULL),
+ : users(NULL),
admins(NULL),
tariffs(NULL),
store(NULL),
- settings(),
fd(-1),
- rpcRegistry(),
rpcServer(NULL),
running(false),
stopped(true),
- tid(),
- cookies(),
dayFee(0),
- dirNames(),
logger(GetPluginLogger(GetStgLogger(), "conf_rpc"))
{
}
m_bufferSize(sizeof(m_header)),
m_stream(NULL),
m_logger(logger),
+#ifdef DUMPCRYPTO
+ m_dataState(false, *this),
+ m_dumper(endpoint())
+#else
m_dataState(false, *this)
+#endif
{
if (m_xmlParser == NULL)
throw Error("Failed to create XML parser.");
if (res < 0)
{
m_state = ERROR;
- Log(__FILE__, "Failed to read data from " + inet_ntostring(IP()) + ":" + x2str(Port()) + ". Reason: '" + strerror(errno) + "'");
+ Log(__FILE__, "Failed to read data from " + endpoint() + ". Reason: '" + strerror(errno) + "'");
return false;
}
if (res == 0 && m_state != DATA) // EOF is ok for data.
{
m_state = ERROR;
- Log(__FILE__, "Failed to read data from " + inet_ntostring(IP()) + ":" + x2str(Port()) + ". Unexpected EOF.");
+ Log(__FILE__, "Failed to read data from " + endpoint() + ". Unexpected EOF.");
return false;
}
+#ifdef DUMPCRYPTO
+ m_dumper.write(m_buffer, res);
+#endif
m_bufferSize -= res;
+ m_buffer = static_cast<char*>(m_buffer) + res;
return HandleBuffer(res);
}
if (res < 0)
{
m_state = ERROR;
- Log(__FILE__, "Failed to write data to " + inet_ntostring(IP()) + ":" + x2str(Port()) + ". Reason: '" + strerror(errno) + "'.");
+ Log(__FILE__, "Failed to write data to " + endpoint() + ". Reason: '" + strerror(errno) + "'.");
return false;
}
return true;
{
if (strncmp(m_header, STG_HEADER, sizeof(m_header)) != 0)
{
- Log(__FILE__, "Received invalid header from " + inet_ntostring(IP()) + ":" + x2str(Port()) + ".");
+ Log(__FILE__, "Received invalid header from " + endpoint() + ".");
WriteAnswer(ERR_HEADER, sizeof(ERR_HEADER) - 1); // Without \0
m_state = ERROR;
return false;
if (m_admins.Find(m_login, &m_admin)) // ADMINS::Find returns true on error.
{
std::string login(m_login, strnlen(m_login, sizeof(m_login)));
- Log(__FILE__, "Received invalid login '" + ToPrintable(login) + "' from " + inet_ntostring(IP()) + ":" + x2str(Port()) + ".");
+ Log(__FILE__, "Received invalid login '" + ToPrintable(login) + "' from " + endpoint() + ".");
WriteAnswer(ERR_LOGIN, sizeof(ERR_LOGIN) - 1); // Without \0
m_state = ERROR;
return false;
if (strncmp(m_login, login, sizeof(login)) != 0)
{
- Log(__FILE__, "Attempt to connect with wrong password from " + m_admin->GetLogin() + "@" + inet_ntostring(IP()) + ":" + x2str(Port()) + ".");
+ Log(__FILE__, "Attempt to connect with wrong password from " + m_admin->GetLogin() + "@" + endpoint() + ".");
WriteAnswer(ERR_LOGINS, sizeof(ERR_LOGINS) - 1); // Without \0
m_state = ERROR;
return false;
bool Conn::HandleData(size_t size)
{
- m_stream->Put(m_buffer, size, size == 0 || memchr(m_buffer, 0, size) != NULL);
+ m_stream->Put(m_data, size, size == 0 || memchr(m_data, 0, size) != NULL);
+ m_buffer = m_data;
return m_stream->IsOk();
}
if (XML_Parse(state.conn.m_xmlParser, xml, length, state.final) == XML_STATUS_ERROR)
{
- state.conn.Log(__FILE__, "Received invalid XML from " + state.conn.m_admin->GetLogin() + "@" + inet_ntostring(state.conn.IP()) + ":" + x2str(state.conn.Port()) + ".");
+ state.conn.Log(__FILE__, "Received invalid XML from " + state.conn.m_admin->GetLogin() + "@" + state.conn.endpoint() + ".");
printfd(__FILE__, "XML parse error at line %d, %d: %s. Is final: %d\n",
static_cast<int>(XML_GetCurrentLineNumber(state.conn.m_xmlParser)),
static_cast<int>(XML_GetCurrentColumnNumber(state.conn.m_xmlParser)),
{
if (!state.conn.WriteResponse())
{
- state.conn.Log(__FILE__, "Failed to write response to " + state.conn.m_admin->GetLogin() + "@" + inet_ntostring(state.conn.IP()) + ":" + x2str(state.conn.Port()) + ".");
+ state.conn.Log(__FILE__, "Failed to write response to " + state.conn.m_admin->GetLogin() + "@" + state.conn.endpoint() + ".");
state.conn.m_state = ERROR;
return false;
}
if (conn.m_parser == NULL)
{
- conn.Log(__FILE__, "Received unknown command '" + std::string(el) + "' from " + conn.m_admin->GetLogin() + "@" + inet_ntostring(conn.IP()) + ":" + x2str(conn.Port()) + ".");
+ conn.Log(__FILE__, "Received unknown command '" + std::string(el) + "' from " + conn.m_admin->GetLogin() + "@" + conn.endpoint() + ".");
conn.m_state = ERROR;
return;
}
#include "parser.h"
+#include "dumphelpers.h"
+
#include "stg/os_int.h"
#include "stg/const.h"
uint32_t IP() const { return *(uint32_t *)(&m_addr.sin_addr); }
uint16_t Port() const { return ntohs(m_addr.sin_port); }
+ std::string endpoint() const { return inet_ntostring(IP()) + ":" + x2str(Port()); }
+
bool Read();
bool IsOk() const { return m_state != ERROR; }
Conn & conn;
} m_dataState;
+#ifdef DUMPCRYPTO
+ Dumper m_dumper;
+#endif
+
static bool DataCallback(const void * block, size_t size, void * data);
static void ParseXMLStart(void * data, const char * el, const char ** attr);
static void ParseXMLEnd(void * data, const char * el);
--- /dev/null
+#ifndef __STG_DUMP_HELPERS_H__
+#define __STG_DUMP_HELPERS_H__
+
+#include "stg/common.h"
+
+#include <string>
+#include <fstream>
+#include <sstream>
+#include <iomanip>
+
+#include <cstddef>
+#include <ctime>
+
+namespace STG
+{
+
+class Dumper
+{
+ public:
+ explicit Dumper(const std::string& tag)
+ : m_stream(getName(tag).c_str())
+ {
+ }
+ ~Dumper() {}
+
+ void write(const void* data, size_t size)
+ {
+ writePrefix();
+ m_stream << " ";
+ writeHEX(data, size);
+ }
+
+ private:
+ std::ofstream m_stream;
+
+ tm getTime() const
+ {
+ time_t now = time(NULL);
+ tm localTime;
+ localtime_r(&now, &localTime);
+ return localTime;
+ }
+
+ std::string getName(const std::string& tag) const
+ {
+ tm localTime = getTime();
+
+ std::ostringstream res;
+ res << tag
+ << "-" << (localTime.tm_year + 1900) << twoDigit(localTime.tm_mon + 1) << twoDigit(localTime.tm_mday)
+ << "-" << twoDigit(localTime.tm_hour) << twoDigit(localTime.tm_min) << twoDigit(localTime.tm_sec)
+ << ".data";
+
+ return res.str();
+ }
+
+ void writePrefix()
+ {
+ tm localTime = getTime();
+ m_stream << "[" << (localTime.tm_year + 1900) << "-" << twoDigit(localTime.tm_mon + 1) << "-" << twoDigit(localTime.tm_mday)
+ << " " << twoDigit(localTime.tm_hour) << ":" << twoDigit(localTime.tm_min) << ":" << twoDigit(localTime.tm_sec)
+ << "]";
+ }
+
+ void writeHEX(const void* data, size_t size)
+ {
+ m_stream << "(" << std::setw(4) << std::setfill(' ') << size << ") ";
+ const unsigned char* pos = static_cast<const unsigned char*>(data);
+ for (size_t i = 0; i < size; ++i)
+ m_stream << std::hex << std::setw(2) << std::setfill('0') << static_cast<unsigned int>(*pos++);
+ m_stream << std::dec << "\n";
+ }
+
+ std::string twoDigit(int value) const
+ {
+ std::string res = x2str(value);
+ if (res.length() < 2)
+ res = "0" + res;
+ return res;
+ }
+};
+
+} // namespace Caster
+
+#endif
utsn.machine + " " +
utsn.nodename;
- m_answer = GetOpenTag() + "<version value=\"" + SERVER_VERSION + "\"/>" +
+ m_answer = std::string("<ServerInfo><version value=\"") + SERVER_VERSION + "\"/>" +
"<tariff_num value=\"" + x2str(m_tariffs.Count()) + "\"/>" +
"<tariff value=\"2\"/>" +
"<user_num value=\"" + x2str(m_users.Count()) + "\"/>" +
for (size_t i = 0; i< DIR_NUM; i++)
m_answer += "<dir_name_" + x2str(i) + " value=\"" + Encode12str(m_settings.GetDirName(i)) + "\"/>";
- m_answer += GetCloseTag();
+ m_answer += "</ServerInfo>";
}
return res;
}
+template <typename T>
+bool str2res(const std::string& source, RESETABLE<T>& dest, T divisor)
+{
+ T value = 0;
+ if (str2x(source, value))
+ return false;
+ dest = value / divisor;
+ return true;
+}
+
template <typename A, typename C, typename F>
bool String2AOS(const std::string & source, A & array, size_t size, RESETABLE<F> C::* field, F divisor)
{
std::string::size_type pos = 0;
while (index < size && (pos = source.find('/', from)) != std::string::npos)
{
- if (str2x(source.substr(from, pos - from), (array[index].*field).data()))
+ if (!str2res(source.substr(from, pos - from), array[index].*field, divisor))
return false;
- (array[index].*field).data() /= divisor;
from = pos + 1;
++index;
}
- if (str2x(source.substr(from), (array[index].*field).data()))
+ if (str2res(source.substr(from), array[index].*field, divisor))
return false;
- (array[index].*field).data() /= divisor;
return true;
}
std::string answer;
if (loginInStart)
- answer += "<User result=\"ok\">";
+ answer += "<User login=\"" + user.GetLogin() + "\" result=\"ok\">";
else
- answer += "<User result=\"ok\" login=\"" + user.GetLogin() + "\">";
+ answer += "<User result=\"ok\">";
answer += "<Login value=\"" + user.GetLogin() + "\"/>";
///////////////////////////
pv.param = "Port";
pvi = std::find(s.moduleParams.begin(), s.moduleParams.end(), pv);
- if (pvi == s.moduleParams.end())
+ if (pvi == s.moduleParams.end() || pvi->value.empty())
{
errorStr = "Parameter \'Port\' is not found.";
printfd(__FILE__, "%s\n", errorStr.c_str());
pv.param = "BindAddress";
pvi = std::find(s.moduleParams.begin(), s.moduleParams.end(), pv);
- if (pvi != s.moduleParams.end())
+ if (pvi != s.moduleParams.end() && !pvi->value.empty())
m_bindAddress = pvi->value[0];
return true;
pv.param = "PingDelay";
pvi = std::find(s.moduleParams.begin(), s.moduleParams.end(), pv);
-if (pvi == s.moduleParams.end())
+if (pvi == s.moduleParams.end() || pvi->value.empty())
{
errorStr = "Parameter \'PingDelay\' not found.";
printfd(__FILE__, "Parameter 'PingDelay' not found\n");
}
//-----------------------------------------------------------------------------
PING::PING()
- : errorStr(),
- pingSettings(),
- settings(),
- users(NULL),
- usersList(),
- thread(),
- mutex(),
+ : users(NULL),
nonstop(false),
isRunning(false),
- pinger(),
- ChgCurrIPNotifierList(),
- ChgIPNotifierList(),
onAddUserNotifier(*this),
onDelUserNotifier(*this),
logger(GetPluginLogger(GetStgLogger(), "ping"))
//-----------------------------------------------------------------------------
RS::SETTINGS::SETTINGS()
: sendPeriod(0),
- port(0),
- errorStr(),
- netRouters(),
- userParams(),
- password(),
- subnetFile()
+ port(0)
{
}
//-----------------------------------------------------------------------------
///////////////////////////
pv.param = "Port";
pvi = find(s.moduleParams.begin(), s.moduleParams.end(), pv);
-if (pvi == s.moduleParams.end())
+if (pvi == s.moduleParams.end() || pvi->value.empty())
{
errorStr = "Parameter \'Port\' not found.";
printfd(__FILE__, "Parameter 'Port' not found\n");
///////////////////////////
pv.param = "SendPeriod";
pvi = find(s.moduleParams.begin(), s.moduleParams.end(), pv);
-if (pvi == s.moduleParams.end())
+if (pvi == s.moduleParams.end() || pvi->value.empty())
{
errorStr = "Parameter \'SendPeriod\' not found.";
printfd(__FILE__, "Parameter 'SendPeriod' not found\n");
///////////////////////////
pv.param = "UserParams";
pvi = find(s.moduleParams.begin(), s.moduleParams.end(), pv);
-if (pvi == s.moduleParams.end())
+if (pvi == s.moduleParams.end() || pvi->value.empty())
{
errorStr = "Parameter \'UserParams\' not found.";
printfd(__FILE__, "Parameter 'UserParams' not found\n");
///////////////////////////
pv.param = "Password";
pvi = find(s.moduleParams.begin(), s.moduleParams.end(), pv);
-if (pvi == s.moduleParams.end())
+if (pvi == s.moduleParams.end() || pvi->value.empty())
{
errorStr = "Parameter \'Password\' not found.";
printfd(__FILE__, "Parameter 'Password' not found\n");
///////////////////////////
pv.param = "SubnetFile";
pvi = find(s.moduleParams.begin(), s.moduleParams.end(), pv);
-if (pvi == s.moduleParams.end())
+if (pvi == s.moduleParams.end() || pvi->value.empty())
{
errorStr = "Parameter \'SubnetFile\' not found.";
printfd(__FILE__, "Parameter 'SubnetFile' not found\n");
{
PLUGIN_CREATOR<SMUX> smc;
-bool SPrefixLess(const Sensors::value_type & a,
- const Sensors::value_type & b);
-
bool SPrefixLess(const Sensors::value_type & a,
const Sensors::value_type & b)
{
pv.param = "Port";
pvi = std::find(s.moduleParams.begin(), s.moduleParams.end(), pv);
-if (pvi == s.moduleParams.end())
+if (pvi == s.moduleParams.end() || pvi->value.empty())
{
errorStr = "Parameter \'Port\' not found.";
printfd(__FILE__, "Parameter 'Port' not found\n");
pv.param = "Password";
pvi = std::find(s.moduleParams.begin(), s.moduleParams.end(), pv);
-if (pvi == s.moduleParams.end())
+if (pvi == s.moduleParams.end() || pvi->value.empty())
{
errorStr = "Parameter \'Password\' not found.";
printfd(__FILE__, "Parameter 'Password' not found\n");
pv.param = "Server";
pvi = std::find(s.moduleParams.begin(), s.moduleParams.end(), pv);
-if (pvi == s.moduleParams.end())
+if (pvi == s.moduleParams.end() || pvi->value.empty())
{
errorStr = "Parameter \'Server\' not found.";
printfd(__FILE__, "Parameter 'Server' not found\n");
//-----------------------------------------------------------------------------
FILES_STORE_SETTINGS::FILES_STORE_SETTINGS()
: settings(NULL),
- errorStr(),
- workDir(),
- usersDir(),
- adminsDir(),
- tariffsDir(),
statMode(0),
statUID(0),
statGID(0),
pv.param = owner;
std::vector<PARAM_VALUE>::const_iterator pvi;
pvi = find(moduleParams.begin(), moduleParams.end(), pv);
-if (pvi == moduleParams.end())
+if (pvi == moduleParams.end() || pvi->value.empty())
{
errorStr = "Parameter \'" + owner + "\' not found.";
printfd(__FILE__, "%s\n", errorStr.c_str());
pv.param = group;
std::vector<PARAM_VALUE>::const_iterator pvi;
pvi = find(moduleParams.begin(), moduleParams.end(), pv);
-if (pvi == moduleParams.end())
+if (pvi == moduleParams.end() || pvi->value.empty())
{
errorStr = "Parameter \'" + group + "\' not found.";
printfd(__FILE__, "%s\n", errorStr.c_str());
pv.param = modeStr;
std::vector<PARAM_VALUE>::const_iterator pvi;
pvi = find(moduleParams.begin(), moduleParams.end(), pv);
-if (pvi == moduleParams.end())
+if (pvi == moduleParams.end() || pvi->value.empty())
{
errorStr = "Parameter \'" + modeStr + "\' not found.";
printfd(__FILE__, "%s\n", errorStr.c_str());
PARAM_VALUE pv;
pv.param = "RemoveBak";
pvi = find(s.moduleParams.begin(), s.moduleParams.end(), pv);
-if (pvi == s.moduleParams.end())
+if (pvi == s.moduleParams.end() || pvi->value.empty())
{
removeBak = true;
}
pv.param = "ReadBak";
pvi = find(s.moduleParams.begin(), s.moduleParams.end(), pv);
-if (pvi == s.moduleParams.end())
+if (pvi == s.moduleParams.end() || pvi->value.empty())
{
readBak = false;
}
pv.param = "WorkDir";
pvi = find(s.moduleParams.begin(), s.moduleParams.end(), pv);
-if (pvi == s.moduleParams.end())
+if (pvi == s.moduleParams.end() || pvi->value.empty())
{
errorStr = "Parameter \'WorkDir\' not found.";
printfd(__FILE__, "Parameter 'WorkDir' not found\n");
//-----------------------------------------------------------------------------
FIREBIRD_STORE::FIREBIRD_STORE()
: version("firebird_store v.1.4"),
- strError(),
db_server("localhost"),
db_database("/var/stg/stargazer.fdb"),
db_user("stg"),
db_password("123456"),
- settings(),
- db(),
- mutex(),
til(IBPP::ilConcurrency),
tlr(IBPP::lrWait),
schemaVersion(0),
for(i = settings.moduleParams.begin(); i != settings.moduleParams.end(); ++i)
{
+ if (i->value.empty())
+ continue;
s = ToLower(i->param);
if (s == "server")
- db_server = *(i->value.begin());
+ db_server = i->value.front();
if (s == "database")
- db_database = *(i->value.begin());
+ db_database = i->value.front();
if (s == "user")
- db_user = *(i->value.begin());
+ db_user = i->value.front();
if (s == "password")
- db_password = *(i->value.begin());
+ db_password = i->value.front();
// Advanced settings block
if (s == "isolationLevel")
{
- if (*(i->value.begin()) == "Concurrency")
+ if (i->value.front() == "Concurrency")
til = IBPP::ilConcurrency;
- else if (*(i->value.begin()) == "DirtyRead")
+ else if (i->value.front() == "DirtyRead")
til = IBPP::ilReadDirty;
- else if (*(i->value.begin()) == "ReadCommitted")
+ else if (i->value.front() == "ReadCommitted")
til = IBPP::ilReadCommitted;
- else if (*(i->value.begin()) == "Consistency")
+ else if (i->value.front() == "Consistency")
til = IBPP::ilConsistency;
}
if (s == "lockResolution")
{
- if (*(i->value.begin()) == "Wait")
+ if (i->value.front() == "Wait")
tlr = IBPP::lrWait;
- else if (*(i->value.begin()) == "NoWait")
+ else if (i->value.front() == "NoWait")
tlr = IBPP::lrNoWait;
}
}
#include "firebird_store.h"
#include "stg/ibpp.h"
+namespace
+{
+
+const int pt_mega = 1024 * 1024;
+
+}
+
//-----------------------------------------------------------------------------
int FIREBIRD_STORE::GetTariffsList(std::vector<std::string> * tariffsList) const
{
st->Get(7, td->dirPrice[dir].priceNightB);
td->dirPrice[dir].priceNightB /= 1024*1024;
st->Get(8, td->dirPrice[dir].threshold);
- if (std::fabs(td->dirPrice[dir].priceDayA - td->dirPrice[dir].priceNightA) < 1.0e-3 &&
- std::fabs(td->dirPrice[dir].priceDayB - td->dirPrice[dir].priceNightB) < 1.0e-3)
+ if (std::fabs(td->dirPrice[dir].priceDayA - td->dirPrice[dir].priceNightA) < 1.0e-3 / pt_mega &&
+ std::fabs(td->dirPrice[dir].priceDayB - td->dirPrice[dir].priceNightB) < 1.0e-3 / pt_mega)
{
td->dirPrice[dir].singlePrice = true;
}
}
//-----------------------------------------------------------------------------
MYSQL_STORE_SETTINGS::MYSQL_STORE_SETTINGS()
- : settings(NULL),
- errorStr(),
- dbUser(),
- dbPass(),
- dbName(),
- dbHost()
+ : settings(NULL)
{
}
//-----------------------------------------------------------------------------
-int MYSQL_STORE_SETTINGS::ParseParam(const std::vector<PARAM_VALUE> & moduleParams,
- const std::string & name, std::string & result)
+int MYSQL_STORE_SETTINGS::ParseParam(const std::vector<PARAM_VALUE> & moduleParams,
+ const std::string & name, std::string & result)
{
PARAM_VALUE pv;
pv.param = name;
std::vector<PARAM_VALUE>::const_iterator pvi;
pvi = find(moduleParams.begin(), moduleParams.end(), pv);
-if (pvi == moduleParams.end())
+if (pvi == moduleParams.end() || pvi->value.empty())
{
errorStr = "Parameter \'" + name + "\' not found.";
return -1;
}
-
+
result = pvi->value[0];
return 0;
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
MYSQL_STORE::MYSQL_STORE()
- : errorStr(),
- version("mysql_store v.0.67"),
- storeSettings(),
- settings(),
+ : version("mysql_store v.0.67"),
schemaVersion(0),
logger(GetPluginLogger(GetStgLogger(), "store_mysql"))
{
//-----------------------------------------------------------------------------
POSTGRESQL_STORE::POSTGRESQL_STORE()
: versionString("postgresql_store v.1.3"),
- strError(),
server("localhost"),
database("stargazer"),
user("stg"),
password("123456"),
clientEncoding("KOI8"),
- settings(),
- mutex(),
version(0),
retries(3),
connection(NULL),
for(i = settings.moduleParams.begin(); i != settings.moduleParams.end(); ++i)
{
+ if (i->value.empty())
+ continue;
s = ToLower(i->param);
if (s == "server")
{
- server = *(i->value.begin());
+ server = i->value.front();
}
if (s == "database")
{
- database = *(i->value.begin());
+ database = i->value.front();
}
if (s == "user")
{
- user = *(i->value.begin());
+ user = i->value.front();
}
if (s == "password")
{
- password = *(i->value.begin());
+ password = i->value.front();
}
if (s == "retries")
{
- if (str2x(*(i->value.begin()), retries))
+ if (str2x(i->value.front(), retries))
{
strError = "Invalid 'retries' value";
printfd(__FILE__, "POSTGRESQL_STORE::ParseSettings(): '%s'\n", strError.c_str());
#include "postgresql_store.h"
#include "stg/locker.h"
+namespace
+{
+
+const int pt_mega = 1024 * 1024;
+
+}
+
//-----------------------------------------------------------------------------
int POSTGRESQL_STORE::GetTariffsList(std::vector<std::string> * tariffsList) const
{
tuple >> td->dirPrice[dir].mNight;
}
- if (std::fabs(td->dirPrice[dir].priceDayA - td->dirPrice[dir].priceNightA) > 1.0e-3 &&
- std::fabs(td->dirPrice[dir].priceDayB - td->dirPrice[dir].priceNightB) > 1.0e-3)
+ if (std::fabs(td->dirPrice[dir].priceDayA - td->dirPrice[dir].priceNightA) < 1.0e-3 / pt_mega &&
+ std::fabs(td->dirPrice[dir].priceDayB - td->dirPrice[dir].priceNightB) < 1.0e-3 / pt_mega)
{
td->dirPrice[dir].singlePrice = true;
}
lastDisconnectReason = reason;
lastIPForDisconnect = currIP;
currIP = 0; // DelUser in traffcounter
+ if (connected)
+ Disconnect(false, "not authorized");
return;
}
}
if (FindByNameNonLock(login, &iter))
{
WriteServLog("Attempt to unauthorize non-existant user '%s'", login.c_str());
+ printfd(__FILE__, "Attempt to unauthorize non-existant user '%s'", login.c_str());
return false;
}
stgUsleep(100000);
} //while (us->nonstop)
-user_iter ui = us->users.begin();
-while (ui != us->users.end())
- {
- us->DelUserFromIndexes(ui);
- ++ui;
- }
-
-std::list<USER_TO_DEL>::iterator iter;
-iter = us->usersToDelete.begin();
+std::list<USER_TO_DEL>::iterator iter(us->usersToDelete.begin());
while (iter != us->usersToDelete.end())
{
iter->delTime -= 2 * userDeleteDelayTime;
return 0;
}
+//---------------------------------------------------------------------------
+int str2x(const std::string & str, double & x)
+{
+return strtodouble2(str.c_str(), x);
+}
#ifndef WIN32
//---------------------------------------------------------------------------
int str2x(const std::string & str, int64_t & x)
//-----------------------------------------------------------------------------
int str2x(const std::string & str, int32_t & x);
int str2x(const std::string & str, uint32_t & x);
+int str2x(const std::string & str, double & x);
#ifndef WIN32
int str2x(const std::string & str, int64_t & x);
int str2x(const std::string & str, uint64_t & x);
char realpathBuf[PATH_MAX];
if(realpath(_fileName, realpathBuf) == NULL){
- error(0, _fileName, "realpath('%s') failed: %s", _fileName, strerror(errno));
+ error(0, _fileName, "%s", strerror(errno));
return -1;
}
char * buf = (char*)mempool->alloc(len);
if(lineNum)
- (void) snprintf(buf, len, "DOTCONF++: file '%s', line %d: %s\n", fileName, lineNum, msg);
+ (void) snprintf(buf, len, "File '%s', line %d: %s\n", fileName, lineNum, msg);
else
- (void) snprintf(buf, len, "DOTCONF++: file '%s': %s\n", fileName, msg);
+ (void) snprintf(buf, len, "File '%s': %s\n", fileName, msg);
if (errorCallback) {
errorCallback(errorCallbackData, buf);
ensure_equals("DecryptString(EncryptString(longTest)) == longTest", source, std::string(longTest));
}
+ template<>
+ template<>
+ void testobject::test<8>()
+ {
+ set_test_name("Check old string encryption");
+
+ BLOWFISH_CTX ctx;
+ InitContext("123456", 7, &ctx);
+ const unsigned char source[] = {0xe9, 0xfe, 0xcb, 0xc5, 0xad, 0x3e, 0x87, 0x39,
+ 0x3d, 0xd5, 0xf4, 0xed, 0xb0, 0x15, 0xe6, 0xcb,
+ 0x3d, 0xd5, 0xf4, 0xed, 0xb0, 0x15, 0xe6, 0xcb,
+ 0x3d, 0xd5, 0xf4, 0xed, 0xb0, 0x15, 0xe6, 0xcb};
+ char res[32];
+ DecryptString(res, source, 32, &ctx);
+
+ ensure_equals("DecryptString(...) == 'admin'", std::string(res), "admin");
+ }
+
+ template<>
+ template<>
+ void testobject::test<9>()
+ {
+ set_test_name("Check new string encryption");
+
+ BLOWFISH_CTX ctx;
+ InitContext("123456", 7, &ctx);
+ const unsigned char source[] = {0xe9, 0xfe, 0xcb, 0xc5, 0xad, 0x3e, 0x87, 0x39,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
+ char res[32];
+ DecryptString(res, source, 32, &ctx);
+
+ ensure_equals("DecryptString(...) == 'admin'", std::string(res), "admin");
+ }
+
}