7 #ifndef LEASE_FILE_LOADER_H 8 #define LEASE_FILE_LOADER_H 15 #include <boost/shared_ptr.hpp> 75 template<
typename LeaseObjectType,
typename LeaseFileType,
77 static void load(LeaseFileType& lease_file, StorageType& storage,
78 const uint32_t max_errors = 0xFFFFFFFF,
79 const bool close_file_on_exit =
true) {
82 .arg(lease_file.getFilename());
91 boost::shared_ptr<LeaseObjectType> lease;
96 if (!lease_file.next(lease)) {
98 .arg(lease_file.getReads())
99 .arg(lease_file.getReadMsg());
105 if (++errcnt > max_errors) {
114 " failures " << max_errors <<
" to read a lease" 115 " from the lease file " 116 << lease_file.getFilename());
125 DHCPSRV_MEMFILE_LEASE_LOAD)
126 .arg(lease->toText());
137 typename StorageType::iterator lease_it =
138 storage.find(lease->addr_);
141 if (lease_it == storage.end()) {
142 if (lease->valid_lft_ > 0) {
143 storage.insert(lease);
149 if (lease->valid_lft_ == 0) {
150 storage.erase(lease_it);
154 storage.replace(lease_it, lease);
165 if (lease_file.needsConversion()) {
167 (lease_file.getInputSchemaState()
169 ? DHCPSRV_MEMFILE_NEEDS_UPGRADING
170 : DHCPSRV_MEMFILE_NEEDS_DOWNGRADING))
171 .arg(lease_file.getFilename())
172 .arg(lease_file.getSchemaVersion());
175 if (close_file_on_exit) {
206 template<
typename LeaseObjectType,
typename LeaseFileType,
207 typename StorageType>
208 static void write(LeaseFileType& lease_file,
const StorageType& storage) {
215 for (
typename StorageType::const_iterator lease = storage.begin();
216 lease != storage.end();
219 lease_file.append(**lease);
235 #endif // LEASE_FILE_LOADER_H #define LOG_WARN(LOGGER, MESSAGE)
Macro to conveniently test warn output and log it.
const int DHCPSRV_DBG_TRACE_DETAIL_DATA
Additional information.
#define LOG_INFO(LOGGER, MESSAGE)
Macro to conveniently test info output and log it.
#define LOG_ERROR(LOGGER, MESSAGE)
Macro to conveniently test error output and log it.
Code used to conduct various sanity checks.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
This is a base class for exceptions thrown from the DNS library module.
Defines the logger used by the top-level component of kea-dhcp-ddns.
#define LOG_DEBUG(LOGGER, LEVEL, MESSAGE)
Macro to conveniently test debug output and log it.
isc::log::Logger dhcpsrv_logger("dhcpsrv")
DHCP server library Logger.
Utility class to manage bulk of leases in the lease files.
static void load(LeaseFileType &lease_file, StorageType &storage, const uint32_t max_errors=0xFFFFFFFF, const bool close_file_on_exit=true)
Load leases from the lease file into the specified storage.
void checkLease(Lease4Ptr &lease, bool current=true)
Sanity checks and possibly corrects an IPv4 lease.
static void write(LeaseFileType &lease_file, const StorageType &storage)
Write leases from the storage into a lease file.
Exception thrown when an error occurs during CSV file processing.