virtual int Start() = 0;
virtual int Stop() = 0;
- virtual int Reload() = 0;
+ virtual int Reload(const MODULE_SETTINGS &) = 0;
virtual bool IsRunning() = 0;
virtual const std::string & GetStrError() const = 0;
virtual std::string GetVersion() const = 0;
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;
PIDFile pidFile(settings.GetPIDFileName());
+struct sigaction sa;
+memset(&sa, 0, sizeof(sa));
+sa.sa_handler = SIG_DFL;
+sigaction(SIGHUP, &sa, NULL); // Apparently FreeBSD ignores SIGHUP by default when launched from rc.d at bot time.
+
sigset_t signalSet;
sigfillset(&signalSet);
pthread_sigmask(SIG_BLOCK, &signalSet, NULL);
switch (sig)
{
case SIGHUP:
+ {
+ SETTINGS_IMPL newSettings(settings);
+ if (newSettings.ReadSettings())
+ WriteServLog("ReadSettings error. %s", newSettings.GetStrError().c_str());
+ else
+ settings = newSettings;
+ WriteServLog.SetLogFileName(settings.GetLogFileName());
traffCnt.Reload();
- manager.reload();
+ manager.reload(settings);
+ }
break;
case SIGTERM:
running = false;
WriteServLog("+++++++++++++++++++++++++++++++++++++++++++++");
+manager.stop();
+
if (loop.Stop())
WriteServLog("Event loop not stopped.");
const std::vector<MODULE_SETTINGS> & modSettings(settings.GetModulesSettings());
for (size_t i = 0; i < modSettings.size(); i++)
{
- std::string modulePath = basePath + "/mod_" + modSettings[i].moduleName + ".so";
+ std::string moduleName = modSettings[i].moduleName;
+ std::string modulePath = basePath + "/mod_" + moduleName + ".so";
printfd(__FILE__, "Module: %s\n", modulePath.c_str());
try
{
m_modules.push_back(
- new PLUGIN_RUNNER(modulePath, modSettings[i], admins, tariffs,
+ new PLUGIN_RUNNER(modulePath, moduleName, modSettings[i], admins, tariffs,
users, services, corporations, traffcounter,
store, settings)
);
}
PluginManager::~PluginManager()
+{
+ stop();
+ for (size_t i = 0; i < m_modules.size(); ++i)
+ delete m_modules[i];
+}
+
+void PluginManager::reload(const SETTINGS_IMPL& settings)
+{
+ const std::vector<MODULE_SETTINGS> & modSettings(settings.GetModulesSettings());
+ for (size_t i = 0; i < m_modules.size(); ++i)
+ {
+ for (size_t j = 0; j < modSettings.size(); j++)
+ {
+ if (modSettings[j].moduleName == m_modules[i]->GetName())
+ {
+ PLUGIN & plugin = m_modules[i]->GetPlugin();
+ if (m_modules[i]->Reload(modSettings[j]))
+ {
+ m_log("Error reloading module '%s': '%s'", plugin.GetVersion().c_str(),
+ plugin.GetStrError().c_str());
+ printfd(__FILE__, "Error reloading module '%s': '%s'\n", plugin.GetVersion().c_str(),
+ plugin.GetStrError().c_str());
+ }
+ break;
+ }
+ }
+ }
+}
+
+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());
+ plugin.GetStrError().c_str());
}
else
{
printfd(__FILE__, "Module '%s' stopped successfully.\n", plugin.GetVersion().c_str());
}
}
- for (size_t i = 0; i < m_modules.size(); ++i)
- delete m_modules[i];
-}
-
-void PluginManager::reload()
-{
- for (size_t i = 0; i < m_modules.size(); ++i)
- {
- PLUGIN & plugin = m_modules[i]->GetPlugin();
- if (m_modules[i]->Reload())
- {
- m_log("Error reloading module '%s': '%s'", plugin.GetVersion().c_str(),
- plugin.GetStrError().c_str());
- printfd(__FILE__, "Error reloading module '%s': '%s'\n", plugin.GetVersion().c_str(),
- plugin.GetStrError().c_str());
- }
- }
}
USERS_IMPL& users, TRAFFCOUNTER_IMPL& traffcounter);
~PluginManager();
- void reload();
+ void reload(const SETTINGS_IMPL& settings);
+ void stop();
private:
std::vector<PLUGIN_RUNNER*> m_modules;
//-----------------------------------------------------------------------------
PLUGIN_RUNNER::PLUGIN_RUNNER(const std::string & fileName,
+ const std::string & name,
const MODULE_SETTINGS & ms,
ADMINS & admins,
TARIFFS & tariffs,
STORE & store,
const SETTINGS & settings)
: pluginFileName(fileName),
+ pluginName(name),
libHandle(NULL),
m_plugin(Load(ms, admins, tariffs, users, services, corporations,
traffcounter, store, settings))
return res;
}
//-----------------------------------------------------------------------------
-int PLUGIN_RUNNER::Reload()
+int PLUGIN_RUNNER::Reload(const MODULE_SETTINGS & ms)
{
-int res = m_plugin.Reload();
+int res = m_plugin.Reload(ms);
errorStr = m_plugin.GetStrError();
return res;
}
};
PLUGIN_RUNNER(const std::string & pluginFileName,
+ const std::string & pluginName,
const MODULE_SETTINGS & ms,
ADMINS & admins,
TARIFFS & tariffs,
int Start();
int Stop();
- int Reload();
+ int Reload(const MODULE_SETTINGS & ms);
int Restart();
bool IsRunning() { return m_plugin.IsRunning(); }
const std::string & GetStrError() const { return errorStr; }
PLUGIN & GetPlugin() { return m_plugin; }
const std::string & GetFileName() const { return pluginFileName; }
+ const std::string & GetName() const { return pluginName; }
uint16_t GetStartPosition() const { return m_plugin.GetStartPosition(); }
uint16_t GetStopPosition() const { return m_plugin.GetStopPosition(); }
const SETTINGS & settings);
std::string pluginFileName;
+ std::string pluginName;
void * libHandle;
PLUGIN & m_plugin;
}
//-----------------------------------------------------------------------------
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"))
int Start();
int Stop();
- int Reload() { return 0; }
+ int Reload(const MODULE_SETTINGS & /*ms*/) { return 0; }
bool IsRunning() { return isRunning; }
void SetSettings(const MODULE_SETTINGS &) {}
int ParseSettings() { return 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 = "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);
}
return ret;
}
//-----------------------------------------------------------------------------
+int AUTH_IA::Reload(const MODULE_SETTINGS & ms)
+{
+AUTH_IA_SETTINGS newIaSettings;
+if (newIaSettings.ParseSettings(ms))
+ {
+ printfd(__FILE__, "AUTH_IA::Reload() - Failed to reload InetAccess.\n");
+ logger("AUTH_IA: Cannot reload InetAccess. Errors found.");
+ return -1;
+ }
+
+printfd(__FILE__, "AUTH_IA::Reload() - Reloaded InetAccess successfully.\n");
+logger("AUTH_IA: Reloaded InetAccess successfully.");
+iaSettings = newIaSettings;
+return 0;
+}
+//-----------------------------------------------------------------------------
int AUTH_IA::PrepareNet()
{
struct sockaddr_in listenAddr;
int Start();
int Stop();
- int Reload() { return 0; }
+ int Reload(const MODULE_SETTINGS & ms);
bool IsRunning() { return isRunningRunTimeouter || isRunningRun; }
const std::string & GetStrError() const { return errorStr; }
int Start();
int Stop();
- int Reload() { return 0; }
+ int Reload(const MODULE_SETTINGS & /*ms*/) { return 0; }
bool IsRunning();
void SetSettings(const MODULE_SETTINGS & s);
int ParseSettings();
int Start();
int Stop();
- int Reload() { return 0; }
+ int Reload(const MODULE_SETTINGS & /*ms*/) { return 0; }
int ParseSettings() { return 0; }
bool IsRunning();
const std::string & GetStrError() const;
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))
{
int Start();
int Stop();
- int Reload() { return 0; }
+ int Reload(const MODULE_SETTINGS & /*ms*/) { return 0; }
bool IsRunning() { return runningTCP || runningUDP; }
const std::string & GetStrError() const { return errorStr; }
std::string GetVersion() const { return VERSION; }
}
//-----------------------------------------------------------------------------
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;
}
int Start();
int Stop();
- int Reload() { return 0; }
+ int Reload(const MODULE_SETTINGS & /*ms*/) { return 0; }
bool IsRunning() { return isRunning; }
void SetSettings(const MODULE_SETTINGS & s) { settings = s; }
}
//-----------------------------------------------------------------------------
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"))
{
int Start();
int Stop();
- int Reload() { return 0; }
+ int Reload(const MODULE_SETTINGS & /*ms*/) { return 0; }
bool IsRunning() { return isRunning; }
void SetSettings(const MODULE_SETTINGS & s) { settings = s; }
}
//-----------------------------------------------------------------------------
ETHER_CAP::ETHER_CAP()
- : errorStr(),
- thread(),
- nonstop(false),
+ : nonstop(false),
isRunning(false),
capSock(-1),
traffCnt(NULL),
int Start();
int Stop();
- int Reload() { return 0; }
+ int Reload(const MODULE_SETTINGS & /*ms*/) { return 0; }
bool IsRunning() { return isRunning; }
int ParseSettings() { return 0; }
//-----------------------------------------------------------------------------
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);
int Start();
int Stop();
- int Reload() { return 0; }
+ int Reload(const MODULE_SETTINGS & /*ms*/) { return 0; }
bool IsRunning() { return isRunning; }
int ParseSettings() { return 0; }
}
//-----------------------------------------------------------------------------
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);
int Start();
int Stop();
- int Reload() { return 0; }
+ int Reload(const MODULE_SETTINGS & /*ms*/) { return 0; }
bool IsRunning() { return isRunning; }
void SetSettings(const MODULE_SETTINGS & s) { settings = s; }
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"))
{
}
int Start();
int Stop();
- int Reload() { return 0; }
+ int Reload(const MODULE_SETTINGS & /*ms*/) { return 0; }
bool IsRunning() { return running && !stopped; }
const std::string & GetStrError() const { return errorStr; }
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;
int Start();
int Stop();
- int Reload() { return 0; }
+ int Reload(const MODULE_SETTINGS & /*ms*/) { return 0; }
bool IsRunning() { return isRunning; }
const std::string & GetStrError() const { return errorStr; }
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"))
int Start();
int Stop();
- int Reload() { return 0; }
+ int Reload(const MODULE_SETTINGS & /*ms*/) { return 0; }
bool IsRunning();
const std::string & GetStrError() const { return errorStr; }
int Start();
int Stop();
- int Reload() { return 0; }
+ int Reload(const MODULE_SETTINGS & /*ms*/) { return 0; }
bool IsRunning() { return isRunning; }
const std::string & GetStrError() const { return errorStr; }
//-----------------------------------------------------------------------------
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");
return 0;
}
//-----------------------------------------------------------------------------
-int REMOTE_SCRIPT::Reload()
+int REMOTE_SCRIPT::Reload(const MODULE_SETTINGS & /*ms*/)
{
NRMapParser nrMapParser;
int Start();
int Stop();
- int Reload();
+ int Reload(const MODULE_SETTINGS & ms);
bool IsRunning() { return isRunning; }
const std::string & GetStrError() const { return errorStr; }
{
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");
return 0;
}
-int SMUX::Reload()
+int SMUX::Reload(const MODULE_SETTINGS & /*ms*/)
{
if (Stop())
return -1;
int Start();
int Stop();
- int Reload();
+ int Reload(const MODULE_SETTINGS & ms);
bool IsRunning() { return running && !stopped; }
const std::string & GetStrError() const { return errorStr; }
//-----------------------------------------------------------------------------
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;
}
{
}
//-----------------------------------------------------------------------------
+SETTINGS_IMPL & SETTINGS_IMPL::operator=(const SETTINGS_IMPL & rhs)
+{
+ modulesPath = rhs.modulesPath;
+ dirName = rhs.dirName;
+ confDir = rhs.confDir;
+ scriptsDir = rhs.scriptsDir;
+ rules = rhs.rules;
+ logFile = rhs.logFile;
+ pidFile = rhs.pidFile;
+ monitorDir = rhs.monitorDir;
+ scriptParams = rhs.scriptParams;
+ monitoring = rhs.monitoring;
+ detailStatWritePeriod = rhs.detailStatWritePeriod;
+ statWritePeriod = rhs.statWritePeriod;
+ stgExecMsgKey = rhs.stgExecMsgKey;
+ executersNum = rhs.executersNum;
+ fullFee = rhs.fullFee;
+ dayFee = rhs.dayFee;
+ dayResetTraff = rhs.dayResetTraff;
+ spreadFee = rhs.spreadFee;
+ freeMbAllowInet = rhs.freeMbAllowInet;
+ dayFeeIsLastDay = rhs.dayFeeIsLastDay;
+ writeFreeMbTraffCost = rhs.writeFreeMbTraffCost;
+ showFeeInCash = rhs.showFeeInCash;
+ messageTimeout = rhs.messageTimeout;
+ feeChargeType = rhs.feeChargeType;
+ reconnectOnTariffChange = rhs.reconnectOnTariffChange;
+
+ modulesSettings = rhs.modulesSettings;
+ storeModuleSettings = rhs.storeModuleSettings;
+ return *this;
+}
+//-----------------------------------------------------------------------------
int SETTINGS_IMPL::ParseModuleSettings(const DOTCONFDocumentNode * node, std::vector<PARAM_VALUE> * params)
{
const DOTCONFDocumentNode * childNode;
#include "stg/settings.h"
#include "stg/common.h"
-#include "stg/logger.h"
#include "stg/module_settings.h"
//-----------------------------------------------------------------------------
SETTINGS_IMPL(const std::string &);
SETTINGS_IMPL(const SETTINGS_IMPL &);
virtual ~SETTINGS_IMPL() {}
+ SETTINGS_IMPL & operator=(const SETTINGS_IMPL &);
+
int Reload() { return ReadSettings(); }
int ReadSettings();
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);
mutable pthread_mutex_t mutex;
};
//-----------------------------------------------------------------------------
-class PLUGIN_LOGGER : private STG_LOGGER
+class PLUGIN_LOGGER
{
-friend PLUGIN_LOGGER GetPluginLogger(const STG_LOGGER & logger, const std::string & pluginName);
+friend PLUGIN_LOGGER GetPluginLogger(const STG_LOGGER& logger, const std::string& pluginName);
public:
- PLUGIN_LOGGER(const PLUGIN_LOGGER & rhs);
- void operator()(const char * fmt, ...) const;
- void operator()(const std::string & line) const;
+ PLUGIN_LOGGER(const PLUGIN_LOGGER& rhs) : m_parent(rhs.m_parent), m_pluginName(rhs.m_pluginName) {}
+ void operator()(const char* fmt, ...) const;
+ void operator()(const std::string& line) const;
private:
PLUGIN_LOGGER(const STG_LOGGER & logger, const std::string & pn);
- std::string pluginName;
+ const STG_LOGGER& m_parent;
+ std::string m_pluginName;
};
PLUGIN_LOGGER GetPluginLogger(const STG_LOGGER & logger, const std::string & pluginName);
}
}
//-----------------------------------------------------------------------------
-PLUGIN_LOGGER::PLUGIN_LOGGER(const STG_LOGGER & logger, const std::string & pn)
- : STG_LOGGER(),
- pluginName(pn)
+PLUGIN_LOGGER::PLUGIN_LOGGER(const STG_LOGGER& logger, const std::string& pn)
+ : m_parent(logger),
+ m_pluginName(pn)
{
- SetLogFileName(logger.fileName);
-}
-//-----------------------------------------------------------------------------
-PLUGIN_LOGGER::PLUGIN_LOGGER(const PLUGIN_LOGGER & rhs)
- : STG_LOGGER(),
- pluginName(rhs.pluginName)
-{
- SetLogFileName(fileName);
}
//-----------------------------------------------------------------------------
void PLUGIN_LOGGER::operator()(const char * fmt, ...) const
vsnprintf(buff, sizeof(buff), fmt, vl);
va_end(vl);
-STG_LOGGER::operator()("[%s] %s", pluginName.c_str(), buff);
+m_parent("[%s] %s", m_pluginName.c_str(), buff);
}
//-----------------------------------------------------------------------------
void PLUGIN_LOGGER::operator()(const std::string & line) const
{
-STG_LOGGER::operator()("[%s] %s", pluginName.c_str(), line.c_str());
+m_parent("[%s] %s", m_pluginName.c_str(), line.c_str());
}
//-----------------------------------------------------------------------------
PLUGIN_LOGGER GetPluginLogger(const STG_LOGGER & logger, const std::string & pluginName)
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");
+ }
+
}