#include <util/str.h>
#include <legal_log_log.h>
#include <dhcpsrv/backend_store_factory.h>
+#include <rotating_file.h>
#include <subnets_user_context.h>
#include <sstream>
if (!getOptionalInt(arguments, "valid-lft", duration)) {
int64_t expire = 0;
if (getOptionalInt(arguments, "expire", expire)) {
- duration = expire - BackendStoreFactory::instance()->now().tv_sec;
+ duration = expire - BackendStoreFactory::instance(managerID())->now().tv_sec;
}
}
/// @param response The command response.
int handleLease4Cmds(string& name, ConstElementPtr& arguments,
ConstElementPtr& /*response*/) {
- if (!BackendStoreFactory::instance()) {
+ if (!BackendStoreFactory::instance(managerID())) {
LOG_ERROR(legal_log_logger,
LEGAL_LOG_COMMAND_NO_LEGAL_STORE);
return (1);
}
}
- BackendStoreFactory::instance()->writeln(os.str(), osa.str());
+ BackendStoreFactory::instance(managerID())->writeln(os.str(), osa.str());
} catch (const exception& ex) {
LOG_ERROR(legal_log_logger, LEGAL_LOG_COMMAND_WRITE_ERROR)
.arg(ex.what());
/// @param response The command response.
int handleLease6Cmds(string& name, ConstElementPtr& arguments,
ConstElementPtr& response) {
- if (!BackendStoreFactory::instance()) {
+ if (!BackendStoreFactory::instance(managerID())) {
LOG_ERROR(legal_log_logger,
LEGAL_LOG_COMMAND_NO_LEGAL_STORE);
return (1);
return (status);
}
- BackendStoreFactory::instance()->writeln(os.str(), osa.str());
+ BackendStoreFactory::instance(managerID())->writeln(os.str(), osa.str());
} catch (const exception& ex) {
LOG_ERROR(legal_log_logger, LEGAL_LOG_COMMAND_WRITE_ERROR)
.arg(ex.what());
///
/// @return 0 upon success, non-zero otherwise.
int command_processed(CalloutHandle& handle) {
- if (!BackendStoreFactory::instance()) {
+ if (!BackendStoreFactory::instance(managerID())) {
LOG_ERROR(legal_log_logger,
LEGAL_LOG_COMMAND_NO_LEGAL_STORE);
return (1);
#include <util/str.h>
#include <legal_log_log.h>
#include <dhcpsrv/backend_store_factory.h>
+#include <rotating_file.h>
#include <subnets_user_context.h>
#include <sstream>
const Lease4Ptr& /*lease*/, std::string& value) {
bool using_custom_format = false;
- auto expression = BackendStoreFactory::instance()->getRequestFormatExpression();
+ auto expression = BackendStoreFactory::instance(managerID())->getRequestFormatExpression();
if (expression && query) {
value = evaluateString(*expression, *query);
using_custom_format = true;
}
- expression = BackendStoreFactory::instance()->getResponseFormatExpression();
+ expression = BackendStoreFactory::instance(managerID())->getResponseFormatExpression();
if (expression && response) {
value += evaluateString(*expression, *response);
using_custom_format = true;
///
/// @return returns 0 upon success, non-zero otherwise
int legalLog4Handler(CalloutHandle& handle, const Action& action) {
- if (!BackendStoreFactory::instance()) {
+ if (!BackendStoreFactory::instance(managerID())) {
LOG_ERROR(legal_log_logger,
LEGAL_LOG_LEASE4_NO_LEGAL_STORE);
return (1);
ConstSubnet4Ptr subnet = cfg->getBySubnetId(lease->subnet_id_);
if (!isLoggingDisabled(subnet)) {
- BackendStoreFactory::instance()->writeln(genLease4Entry(query, response,
- lease, action),
- lease->addr_.toText());
+ BackendStoreFactory::instance(managerID())->writeln(genLease4Entry(query, response,
+ lease, action),
+ lease->addr_.toText());
}
} catch (const std::exception& ex) {
#include <util/str.h>
#include <legal_log_log.h>
#include <dhcpsrv/backend_store_factory.h>
+#include <rotating_file.h>
#include <subnets_user_context.h>
#include <sstream>
const Lease6Ptr& lease, std::string& value) {
bool using_custom_format = false;
- auto expression = BackendStoreFactory::instance()->getRequestFormatExpression();
+ auto expression = BackendStoreFactory::instance(managerID())->getRequestFormatExpression();
if (expression && query) {
replaceTokensForLease(expression, lease);
using_custom_format = true;
}
- expression = BackendStoreFactory::instance()->getResponseFormatExpression();
+ expression = BackendStoreFactory::instance(managerID())->getResponseFormatExpression();
if (expression && response) {
replaceTokensForLease(expression, lease);
///
/// @return returns 0 upon success, non-zero otherwise
int legalLog6Handler(CalloutHandle& handle, const Action& action) {
- if (!BackendStoreFactory::instance()) {
+ if (!BackendStoreFactory::instance(managerID())) {
LOG_ERROR(legal_log_logger, LEGAL_LOG_LEASE6_NO_LEGAL_STORE);
return (1);
}
ConstSubnet6Ptr subnet = cfg->getBySubnetId(lease->subnet_id_);
if (!isLoggingDisabled(subnet)) {
- BackendStoreFactory::instance()->writeln(genLease6Entry(query, response,
- lease, action),
- genLease6Addr(lease));
+ BackendStoreFactory::instance(managerID())->writeln(genLease6Entry(query, response,
+ lease, action),
+ genLease6Addr(lease));
}
} catch (const std::exception& ex) {
try {
BackendStore::parseConfig(parameters, map);
- BackendStoreFactory::addBackend(map);
+ BackendStoreFactory::addBackend(map, managerID());
} catch (const isc::db::DbOpenErrorWithRetry& err) {
string redacted;
try {
// Since it's "global" Let's explicitly destroy it now rather
// than indeterminately. Note, BackendStore destructor will close
// the store.
- BackendStoreFactory::instance().reset();
+ BackendStoreFactory::instance(managerID()).reset();
BackendStoreFactory::unregisterBackendFactory("logfile");
} catch (const std::exception& ex) {
namespace isc {
namespace legal_log {
+
+bool RotatingFile::test_mode_ = false;
+
+isc::dhcp::ManagerID managerID() {
+ static boost::shared_ptr<void*> id = boost::shared_ptr<void*>(new void*);
+ if (RotatingFile::test_mode_) {
+ id.reset();
+ }
+ return (reinterpret_cast<isc::dhcp::ManagerID>(id.get()));
+}
+
RotatingFile::RotatingFile(const DatabaseConnection::ParameterMap& parameters)
: BackendStore(parameters), time_unit_(TimeUnit::Day), count_(1), timestamp_(0) {
apply(parameters);
/// @return The Rotating File Store Backend.
static isc::dhcp::BackendStorePtr
factory(const isc::db::DatabaseConnection::ParameterMap& parameters);
+
+ /// @brief Test mode flag (default false).
+ static bool test_mode_;
};
/// @brief Initialization structure used to register and deregister RotateFile Forensic Store.
struct RotatingFileInit {
// Constructor registers
RotatingFileInit() {
+ RotatingFile::test_mode_ = true;
isc::dhcp::BackendStoreFactory::registerBackendFactory("logfile", RotatingFile::factory);
}
// Destructor deregisters
~RotatingFileInit() {
isc::dhcp::BackendStoreFactory::unregisterBackendFactory("logfile");
+ RotatingFile::test_mode_ = false;
}
};
+/// @brief Return library unique ManagerID.
+isc::dhcp::ManagerID managerID();
+
} // namespace legal_log
} // namespace isc