18 CSVLeaseFile4::CSVLeaseFile4(
const std::string& filename)
26 VersionedCSVFile::open(seek_to_end);
48 <<
" has neither hardware address or client id");
75 VersionedCSVFile::append(row);
76 }
catch (
const std::exception&) {
98 VersionedCSVFile::next(row);
100 if (row == CSVFile::EMPTY_ROW()) {
112 std::vector<uint8_t> client_id_vec;
114 client_id_vec = client_id->getClientId();
116 size_t client_id_len = client_id_vec.size();
120 HWAddr hwaddr = readHWAddr(row);
121 uint32_t state = readState(row);
123 if ((hwaddr.
hwaddr_.empty()) && (client_id_vec.empty()) &&
127 <<
" has neither hardware address or client id");
133 lease.reset(
new Lease4(addr,
135 client_id_vec.empty() ? NULL : &client_id_vec[0],
143 lease->state_ = state;
146 lease->setContext(ctx);
149 }
catch (
const std::exception& ex) {
167 CSVLeaseFile4::initColumns() {
184 CSVLeaseFile4::readAddress(
const CSVRow& row) {
190 CSVLeaseFile4::readHWAddr(
const CSVRow& row) {
196 CSVLeaseFile4::readClientId(
const CSVRow& row) {
199 if (client_id.empty()) {
207 CSVLeaseFile4::readValid(
const CSVRow& row) {
214 CSVLeaseFile4::readCltt(
const CSVRow& row) {
222 CSVLeaseFile4::readSubnetID(
const CSVRow& row) {
229 CSVLeaseFile4::readFqdnFwd(
const CSVRow& row) {
235 CSVLeaseFile4::readFqdnRev(
const CSVRow& row) {
241 CSVLeaseFile4::readHostname(
const CSVRow& row) {
247 CSVLeaseFile4::readState(
const util::CSVRow& row) {
248 uint32_t state = row.readAndConvertAt<uint32_t>(
getColumnIndex(
"state"));
253 CSVLeaseFile4::readContext(
const util::CSVRow& row) {
254 std::string user_context = row.readAtEscaped(
getColumnIndex(
"user_context"));
255 if (user_context.empty()) {
259 if (!ctx || (ctx->getType() != Element::map)) {
261 <<
"' is not a JSON map");
uint32_t state_
Holds the lease state(s).
static ClientIdPtr fromText(const std::string &text)
Create client identifier from the textual format.
HWAddrPtr hwaddr_
Client's MAC/hardware address.
size_t getColumnCount() const
Returns the number of columns in the file.
Structure that holds a lease for IPv4 address.
bool fqdn_rev_
Reverse zone updated?
uint32_t reads_
Number of attempts to read a lease.
boost::shared_ptr< HWAddr > HWAddrPtr
Shared pointer to a hardware address structure.
bool next(Lease4Ptr &lease)
Reads next lease from the CSV file.
void writeAtEscaped(const size_t at, const std::string &value)
Replaces the value at the specified index with a value that has had special characters escaped...
time_t cltt_
Client last transmission time.
bool fqdn_fwd_
Forward zone updated?
uint32_t writes_
Number of attempts to write a lease.
std::vector< uint8_t > hwaddr_
uint32_t write_leases_
Number of lease written.
std::string hostname_
Client hostname.
SubnetID subnet_id_
Subnet identifier.
std::string readAt(const size_t at) const
Retrieves a value from the internal container.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
boost::shared_ptr< Lease4 > Lease4Ptr
Pointer to a Lease4 structure.
void setMinimumValidColumns(const std::string &column_name)
Sets the minimum number of valid columns based on a given column.
boost::shared_ptr< const Element > ConstElementPtr
Represents a single row of the CSV file.
void setReadMsg(const std::string &read_msg)
Sets error message after row validation.
ClientIdPtr client_id_
Client identifier.
size_t getColumnIndex(const std::string &col_name) const
Returns the index of the column having specified name.
data::ConstElementPtr getContext() const
Returns const pointer to the user context.
boost::shared_ptr< ClientId > ClientIdPtr
Shared pointer to a Client ID.
void clearStatistics()
Clears the statistics.
uint32_t write_errs_
Number of errors when writing.
Defines the logger used by the top-level component of kea-dhcp-ddns.
void addColumn(const std::string &col_name, const std::string &version, const std::string &default_value="")
Adds metadata for a single column to the schema.
Implements a CSV file that supports multiple versions of the file's "schema".
std::string readAtEscaped(const size_t at) const
Retrieves a value from the internal container, free of escaped characters.
static HWAddr fromText(const std::string &text, const uint16_t htype=HTYPE_ETHER)
Creates instance of the hardware address from textual format.
static std::string basicStatesToText(const uint32_t state)
Returns name(s) of the basic lease state(s).
std::string toText() const
Convert the address to a string.
T readAndConvertAt(const size_t at) const
Retrieves a value from the internal container.
Hardware type that represents information from DHCPv4 packet.
void append(const Lease4 &lease)
Appends the lease record to the CSV file.
isc::asiolink::IOAddress addr_
IPv4 ot IPv6 address.
void writeAt(const size_t at, const char *value)
Replaces the value at specified index.
static const uint32_t STATE_DECLINED
Declined lease.
uint32_t read_leases_
Number of leases read.
virtual void open(const bool seek_to_end=false)
Opens a lease file.
uint32_t valid_lft_
Valid lifetime.
The IOAddress class represents an IP addresses (version agnostic)
uint32_t read_errs_
Number of errors when reading.
uint32_t SubnetID
Unique identifier for a subnet (both v4 and v6)