build: switch to C++17
Change-Id: Ia147b22fbdee68d87f0289851683ffbbb4466caa
diff --git a/src/daemon/config-file.hpp b/src/daemon/config-file.hpp
index b17dfe6..29a0587 100644
--- a/src/daemon/config-file.hpp
+++ b/src/daemon/config-file.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2014-2020, Regents of the University of California,
+ * Copyright (c) 2014-2022, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -107,7 +107,7 @@
static T
parseNumber(const ConfigSection& node, const std::string& key, const std::string& sectionName)
{
- static_assert(std::is_arithmetic<T>::value, "T must be an arithmetic type");
+ static_assert(std::is_arithmetic_v<T>, "T must be an arithmetic type");
boost::optional<T> value = node.get_value_optional<T>();
if (value) {
diff --git a/src/daemon/db-mgr.cpp b/src/daemon/db-mgr.cpp
index e1ab0fc..3c20f94 100644
--- a/src/daemon/db-mgr.cpp
+++ b/src/daemon/db-mgr.cpp
@@ -27,7 +27,7 @@
NDNS_LOG_INIT(DbMgr);
-static const std::string NDNS_SCHEMA = R"SQL(
+const std::string NDNS_SCHEMA = R"SQL(
CREATE TABLE IF NOT EXISTS zones (
id INTEGER NOT NULL PRIMARY KEY,
name BLOB NOT NULL UNIQUE,
@@ -143,20 +143,19 @@
DbMgr::restoreName(sqlite3_stmt* stmt, int iCol)
{
Name name;
+ span buffer(static_cast<const uint8_t*>(sqlite3_column_blob(stmt, iCol)),
+ sqlite3_column_bytes(stmt, iCol));
- const uint8_t* buffer = static_cast<const uint8_t*>(sqlite3_column_blob(stmt, iCol));
- size_t nBytesLeft = sqlite3_column_bytes(stmt, iCol);
-
- while (nBytesLeft > 0) {
- bool hasDecodingSucceeded;
+ while (!buffer.empty()) {
name::Component component;
- std::tie(hasDecodingSucceeded, component) = Block::fromBuffer({buffer, nBytesLeft});
- if (!hasDecodingSucceeded) {
- NDN_THROW(Error("Error while decoding name from the database"));
+ try {
+ component.wireDecode(Block(buffer));
+ }
+ catch (const ndn::tlv::Error&) {
+ NDN_THROW_NESTED(Error("Error while decoding name from the database"));
}
name.append(component);
- buffer += component.size();
- nBytesLeft -= component.size();
+ buffer = buffer.subspan(component.size());
}
return name;
@@ -250,8 +249,8 @@
while (sqlite3_step(stmt) == SQLITE_ROW) {
const char* key = reinterpret_cast<const char*>(sqlite3_column_text(stmt, 0));
- rtn[string(key)] = Block(make_span(static_cast<const uint8_t*>(sqlite3_column_blob(stmt, 1)),
- sqlite3_column_bytes(stmt, 1)));
+ rtn[string(key)] = Block(span(static_cast<const uint8_t*>(sqlite3_column_blob(stmt, 1)),
+ sqlite3_column_bytes(stmt, 1)));
}
sqlite3_finalize(stmt);
@@ -410,10 +409,10 @@
if (sqlite3_step(stmt) == SQLITE_ROW) {
rrset.setId(sqlite3_column_int64(stmt, 0));
rrset.setTtl(time::seconds(sqlite3_column_int64(stmt, 1)));
- rrset.setVersion(Block(make_span(static_cast<const uint8_t*>(sqlite3_column_blob(stmt, 2)),
- sqlite3_column_bytes(stmt, 2))));
- rrset.setData(Block(make_span(static_cast<const uint8_t*>(sqlite3_column_blob(stmt, 3)),
- sqlite3_column_bytes(stmt, 3))));
+ rrset.setVersion(name::Component(Block(span(static_cast<const uint8_t*>(sqlite3_column_blob(stmt, 2)),
+ sqlite3_column_bytes(stmt, 2)))));
+ rrset.setData(Block(span(static_cast<const uint8_t*>(sqlite3_column_blob(stmt, 3)),
+ sqlite3_column_bytes(stmt, 3))));
}
else {
rrset.setId(0);
@@ -454,10 +453,10 @@
if (sqlite3_step(stmt) == SQLITE_ROW) {
rrset.setId(sqlite3_column_int64(stmt, 0));
rrset.setTtl(time::seconds(sqlite3_column_int64(stmt, 1)));
- rrset.setVersion(Block(make_span(static_cast<const uint8_t*>(sqlite3_column_blob(stmt, 2)),
- sqlite3_column_bytes(stmt, 2))));
- rrset.setData(Block(make_span(static_cast<const uint8_t*>(sqlite3_column_blob(stmt, 3)),
- sqlite3_column_bytes(stmt, 3))));
+ rrset.setVersion(name::Component(Block(span(static_cast<const uint8_t*>(sqlite3_column_blob(stmt, 2)),
+ sqlite3_column_bytes(stmt, 2)))));
+ rrset.setData(Block(span(static_cast<const uint8_t*>(sqlite3_column_blob(stmt, 3)),
+ sqlite3_column_bytes(stmt, 3))));
}
else {
rrset.setId(0);
@@ -493,13 +492,13 @@
rrset.setId(sqlite3_column_int64(stmt, 0));
rrset.setTtl(time::seconds(sqlite3_column_int64(stmt, 1)));
- rrset.setVersion(Block(make_span(static_cast<const uint8_t*>(sqlite3_column_blob(stmt, 2)),
- sqlite3_column_bytes(stmt, 2))));
- rrset.setData(Block(make_span(static_cast<const uint8_t*>(sqlite3_column_blob(stmt, 3)),
- sqlite3_column_bytes(stmt, 3))));
+ rrset.setVersion(name::Component(Block(span(static_cast<const uint8_t*>(sqlite3_column_blob(stmt, 2)),
+ sqlite3_column_bytes(stmt, 2)))));
+ rrset.setData(Block(span(static_cast<const uint8_t*>(sqlite3_column_blob(stmt, 3)),
+ sqlite3_column_bytes(stmt, 3))));
rrset.setLabel(restoreName(stmt, 4));
- rrset.setType(Block(make_span(static_cast<const uint8_t*>(sqlite3_column_blob(stmt, 5)),
- sqlite3_column_bytes(stmt, 5))));
+ rrset.setType(name::Component(Block(span(static_cast<const uint8_t*>(sqlite3_column_blob(stmt, 5)),
+ sqlite3_column_bytes(stmt, 5)))));
}
sqlite3_finalize(stmt);
diff --git a/src/daemon/db-mgr.hpp b/src/daemon/db-mgr.hpp
index 81ae5ad..747060f 100644
--- a/src/daemon/db-mgr.hpp
+++ b/src/daemon/db-mgr.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2014-2020, Regents of the University of California.
+ * Copyright (c) 2014-2022, Regents of the University of California.
*
* This file is part of NDNS (Named Data Networking Domain Name Service).
* See AUTHORS.md for complete list of NDNS authors and contributors.
@@ -196,8 +196,7 @@
* @brief remove all records of a specific type in a zone
*/
void
- removeRrsetsOfZoneByType(Zone& zone,
- const name::Component& type);
+ removeRrsetsOfZoneByType(Zone& zone, const name::Component& type);
/**
* @brief replace ttl, version, and Data with new values
@@ -220,10 +219,10 @@
* If @p name is not preserved until @p stmt is executed, @p isStatic must be
* set to `false`.
*/
- void
+ static void
saveName(const Name& name, sqlite3_stmt* stmt, int iCol, bool isStatic = true);
- Name
+ static Name
restoreName(sqlite3_stmt* stmt, int iCol);
private:
diff --git a/src/daemon/rrset-factory.cpp b/src/daemon/rrset-factory.cpp
index eed7ad0..41e93a1 100644
--- a/src/daemon/rrset-factory.cpp
+++ b/src/daemon/rrset-factory.cpp
@@ -98,7 +98,7 @@
rrset.setVersion(name.get(-1));
- return std::make_pair(rrset, name);
+ return {rrset, name};
}
bool
@@ -125,13 +125,10 @@
if (ttl == DEFAULT_RR_TTL)
ttl = m_zone.getTtl();
- std::pair<Rrset, Name> rrsetAndName = generateBaseRrset(label, label::NS_RR_TYPE, version, ttl);
- const Name& name = rrsetAndName.second;
- Rrset& rrset = rrsetAndName.first;
+ auto [rrset, name] = generateBaseRrset(label, label::NS_RR_TYPE, version, ttl);
Link link(name);
link.setDelegationList(std::move(delegations));
-
setContentType(link, NDNS_LINK, ttl);
sign(link);
rrset.setData(link.wireEncode());
@@ -152,19 +149,16 @@
if (ttl == DEFAULT_RR_TTL)
ttl = m_zone.getTtl();
- Name name;
- Rrset rrset;
- std::tie(rrset, name) = generateBaseRrset(label, label::TXT_RR_TYPE, version, ttl);
+ auto [rrset, name] = generateBaseRrset(label, label::TXT_RR_TYPE, version, ttl);
std::vector<Block> rrs;
rrs.reserve(strings.size());
for (const auto& item : strings) {
- rrs.push_back(makeBinaryBlock(ndns::tlv::RrData, item.data(), item.size()));
+ rrs.push_back(makeStringBlock(ndns::tlv::RrData, item));
}
Data data(name);
data.setContent(wireEncode(rrs));
-
setContentType(data, NDNS_RESP, ttl);
sign(data);
rrset.setData(data.wireEncode());
@@ -185,13 +179,10 @@
if (ttl == DEFAULT_RR_TTL)
ttl = m_zone.getTtl();
- Name name;
- Rrset rrset;
- std::tie(rrset, name) = generateBaseRrset(label, label::APPCERT_RR_TYPE, version, ttl);
+ auto [rrset, name] = generateBaseRrset(label, label::APPCERT_RR_TYPE, version, ttl);
Data data(name);
data.setContent(cert.wireEncode());
-
setContentType(data, NDNS_KEY, ttl);
sign(data);
rrset.setData(data.wireEncode());
@@ -211,12 +202,9 @@
if (ttl == DEFAULT_RR_TTL)
ttl = m_zone.getTtl();
- Name name;
- Rrset rrset;
- std::tie(rrset, name) = generateBaseRrset(label, label::NS_RR_TYPE, version, ttl);
+ auto [rrset, name] = generateBaseRrset(label, label::NS_RR_TYPE, version, ttl);
Data data(name);
-
setContentType(data, NDNS_AUTH, ttl);
sign(data);
rrset.setData(data.wireEncode());
@@ -238,9 +226,7 @@
if (ttl == DEFAULT_RR_TTL)
ttl = m_zone.getTtl();
- Name name;
- Rrset rrset;
- std::tie(rrset, name) = generateBaseRrset(label, label::DOE_RR_TYPE, version, ttl);
+ auto [rrset, name] = generateBaseRrset(label, label::DOE_RR_TYPE, version, ttl);
std::vector<Block> range;
range.push_back(lowerLabel.wireEncode());
@@ -303,12 +289,9 @@
{
std::vector<std::string> txts;
wire.parse();
-
for (const auto& e : wire.elements()) {
- txts.push_back(std::string(reinterpret_cast<const char*>(e.value()),
- e.value_size()));
+ txts.emplace_back(reinterpret_cast<const char*>(e.value()), e.value_size());
}
-
return txts;
}