Kea 2.7.7
legal_log_mgr.h
Go to the documentation of this file.
1// Copyright (C) 2020-2023 Internet Systems Consortium, Inc. ("ISC")
2//
3// This Source Code Form is subject to the terms of the Mozilla Public
4// License, v. 2.0. If a copy of the MPL was not distributed with this
5// file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
7#ifndef LEGAL_LOG_MGR_H
8#define LEGAL_LOG_MGR_H
9
11
12#include <asiolink/io_service.h>
14#include <eval/token.h>
16
17#include <boost/shared_ptr.hpp>
18
19#include <fstream>
20#include <string>
21
22namespace isc {
23namespace dhcp {
24
27public:
28 LegalLogMgrError(const char* file, size_t line, const char* what) :
29 isc::Exception(file, line, what)
30 {}
31};
32
33class LegalLogMgr;
34
36typedef boost::shared_ptr<LegalLogMgr> LegalLogMgrPtr;
37
40public:
43 timestamp_format_("%Y-%m-%d %H:%M:%S %Z"),
44 parameters_(parameters) {
45 }
46
50 virtual ~LegalLogMgr() = default;
51
60
71
79
85
87 virtual void open() = 0;
88
90 virtual void close() = 0;
91
97 virtual void writeln(const std::string& text, const std::string& addr) = 0;
98
104 virtual std::string getType() const = 0;
105
109 virtual struct tm currentTimeInfo() const;
110
114 virtual struct timespec now() const;
115
125 virtual std::string getNowString() const;
126
139 virtual std::string getNowString(const std::string& format) const;
140
153 static std::string getTimeString(const struct timespec& time, const std::string& format);
154
170 static std::string genDurationString(const uint32_t secs);
171
178 static std::string vectorHexDump(const std::vector<uint8_t>& bytes,
179 const std::string& delimiter = ":");
180
186 static std::string vectorDump(const std::vector<uint8_t>& bytes);
187
191 void setRequestFormatExpression(const std::string& extended_format);
192
197 return (request_expression_);
198 }
199
203 void setResponseFormatExpression(const std::string& extended_format);
204
209 return (response_expression_);
210 }
211
217 void setTimestampFormat(const std::string& timestamp_format);
218
224 std::string getTimestampFormat() {
225 return (timestamp_format_);
226 }
227
234 return (parameters_);
235 }
236
243 parameters_ = parameters;
244 }
245
251 virtual bool isUnusable() {
252 return (false);
253 }
254
255private:
256
258 isc::dhcp::ExpressionPtr request_expression_;
259
261 isc::dhcp::ExpressionPtr response_expression_;
262
264 std::string timestamp_format_;
265
268};
269
271typedef uint64_t ManagerID;
272
274typedef std::map<ManagerID, std::pair<isc::db::DatabaseConnection::ParameterMap, LegalLogMgrPtr>> LegalLogMgrPool;
275
277enum class Action { ASSIGN, RELEASE };
278
283const std::string actionToVerb(Action action);
284
285} // namespace dhcp
286} // namespace isc
287
288#endif // LEGAL_LOG_MGR_H
This is a base class for exceptions thrown from the DNS library module.
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
std::map< std::string, std::string > ParameterMap
Database configuration parameter map.
Thrown if a LegalLogMgr encounters an error.
LegalLogMgrError(const char *file, size_t line, const char *what)
LegalLogMgr abstract class.
isc::dhcp::ExpressionPtr getResponseFormatExpression()
Gets response extended format expression for custom logging.
virtual struct tm currentTimeInfo() const
Returns the current local date and time.
void setRequestFormatExpression(const std::string &extended_format)
Sets request extended format expression for custom logging.
virtual bool isUnusable()
Flag which indicates if the forensic log backend has at least one unusable connection.
static void parseFile(const isc::data::ConstElementPtr &parameters, isc::db::DatabaseConnection::ParameterMap &map)
Parse file specification.
static std::string vectorHexDump(const std::vector< uint8_t > &bytes, const std::string &delimiter=":")
Creates a string of hex digit pairs from a vector of bytes.
virtual void setParameters(isc::db::DatabaseConnection::ParameterMap parameters)
Sets backend parameters.
virtual std::string getType() const =0
Return backend type.
virtual ~LegalLogMgr()=default
Destructor.
std::string getTimestampFormat()
Gets the timestamp format used for logging.
static void parseDatabase(const isc::data::ConstElementPtr &parameters, isc::db::DatabaseConnection::ParameterMap &map)
Parse database specification.
void setResponseFormatExpression(const std::string &extended_format)
Sets response extended format expression for custom logging.
virtual void writeln(const std::string &text, const std::string &addr)=0
Appends a string to the store with a timestamp and address.
static std::string genDurationString(const uint32_t secs)
Translates seconds into a text string of days, hours, minutes and seconds.
virtual struct timespec now() const
Returns the current system time.
static std::string getTimeString(const struct timespec &time, const std::string &format)
Returns a time as string.
virtual void close()=0
Closes the store.
virtual isc::db::DatabaseConnection::ParameterMap getParameters() const
Return backend parameters.
static std::string vectorDump(const std::vector< uint8_t > &bytes)
Creates a string from a vector of printable bytes.
LegalLogMgr(const isc::db::DatabaseConnection::ParameterMap parameters)
Constructor.
isc::dhcp::ExpressionPtr getRequestFormatExpression()
Gets request extended format expression for custom logging.
static void parseConfig(const isc::data::ConstElementPtr &parameters, isc::db::DatabaseConnection::ParameterMap &map)
Parse database specification.
void setTimestampFormat(const std::string &timestamp_format)
Sets the timestamp format used for logging.
static void parseExtraParameters(const isc::data::ConstElementPtr &parameters, isc::db::DatabaseConnection::ParameterMap &map)
Parse extra parameters which are not related to backend connection.
virtual void open()=0
Opens the store.
virtual std::string getNowString() const
Returns the current date and time as string.
boost::shared_ptr< const Element > ConstElementPtr
Definition data.h:29
boost::shared_ptr< LegalLogMgr > LegalLogMgrPtr
Defines a smart pointer to a LegalLogMgr.
const string actionToVerb(Action action)
Translates an Action into its corresponding verb.
boost::shared_ptr< Expression > ExpressionPtr
Definition token.h:31
std::map< ManagerID, std::pair< isc::db::DatabaseConnection::ParameterMap, LegalLogMgrPtr > > LegalLogMgrPool
LegalLogMgr pool.
uint64_t ManagerID
Manger ID used by hook libraries to retrieve respective LegalLogMgr instance.
Action
Describe what kind of event is being logged.
Defines the logger used by the top-level component of kea-lfc.