Avoid deprecated ndn-cxx functions
Change-Id: Ib9220786a724327b89dcc328c8f34a5c8fe1fdd9
diff --git a/src/clients/response.cpp b/src/clients/response.cpp
index b183b1d..48b8a7d 100644
--- a/src/clients/response.cpp
+++ b/src/clients/response.cpp
@@ -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.
@@ -20,6 +20,8 @@
#include "response.hpp"
#include "logger.hpp"
+#include <ndn-cxx/encoding/block-helpers.hpp>
+
namespace ndn {
namespace ndns {
@@ -39,13 +41,13 @@
{
}
-template<encoding::Tag T>
+template<encoding::Tag TAG>
size_t
-Response::wireEncode(EncodingImpl<T>& block) const
+Response::wireEncode(EncodingImpl<TAG>& encoder) const
{
if (m_contentType == NDNS_BLOB || m_contentType == NDNS_KEY) {
// Raw application content
- return block.prependBlock(m_appContent);
+ return prependBlock(encoder, m_appContent);
}
// Content :: = CONTENT-TYPE TLV-LENGTH
@@ -53,16 +55,15 @@
size_t totalLength = 0;
for (auto iter = m_rrs.rbegin(); iter != m_rrs.rend(); ++iter) {
- totalLength += block.prependBlock(*iter);
+ totalLength += prependBlock(encoder, *iter);
}
- totalLength += block.prependVarNumber(totalLength);
- totalLength += block.prependVarNumber(::ndn::tlv::Content);
-
+ totalLength += encoder.prependVarNumber(totalLength);
+ totalLength += encoder.prependVarNumber(ndn::tlv::Content);
return totalLength;
}
-const Block
+Block
Response::wireEncode() const
{
if (m_contentType == NDNS_BLOB || m_contentType == NDNS_KEY) {
@@ -86,7 +87,7 @@
wire.parse();
- Block::element_const_iterator iter = wire.elements().begin();
+ auto iter = wire.elements().begin();
for (; iter != wire.elements().end(); ++iter) {
m_rrs.push_back(*iter);
}
@@ -99,7 +100,7 @@
if (wire.elements().size() != 2) {
NDN_THROW(Error("Unexpected number of elements while decoding DOE record"));
}
- return std::make_pair(Name(wire.elements().front()), Name(wire.elements().back()));
+ return {Name(wire.elements().front()), Name(wire.elements().back())};
}
bool
diff --git a/src/clients/response.hpp b/src/clients/response.hpp
index a97fb76..4e8f335 100644
--- a/src/clients/response.hpp
+++ b/src/clients/response.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2014-2018, 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.
@@ -24,16 +24,9 @@
#include "ndns-enum.hpp"
#include "ndns-label.hpp"
-
-#include <ndn-cxx/face.hpp>
-#include <ndn-cxx/name.hpp>
#include <ndn-cxx/data.hpp>
-#include <ndn-cxx/encoding/block-helpers.hpp>
-#include <ndn-cxx/encoding/block.hpp>
#include <ndn-cxx/meta-info.hpp>
-#include <vector>
-
namespace ndn {
namespace ndns {
@@ -102,7 +95,7 @@
/**
* @brief encode the app-level data
*/
- const Block
+ Block
wireEncode() const;
/**
@@ -116,15 +109,12 @@
*/
template<encoding::Tag T>
size_t
- wireEncode(EncodingImpl<T>& block) const;
+ wireEncode(EncodingImpl<T>& encoder) const;
static std::pair<Name, Name>
wireDecodeDoe(const Block& wire);
-public:
- ///////////////////////////////////////////////
- // getter and setter
-
+public: // getter and setter
const Name&
getZone() const
{
diff --git a/src/daemon/db-mgr.cpp b/src/daemon/db-mgr.cpp
index 27c7332..e1ab0fc 100644
--- a/src/daemon/db-mgr.cpp
+++ b/src/daemon/db-mgr.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2014-2021, 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.
@@ -150,7 +150,7 @@
while (nBytesLeft > 0) {
bool hasDecodingSucceeded;
name::Component component;
- std::tie(hasDecodingSucceeded, component) = Block::fromBuffer(buffer, nBytesLeft);
+ std::tie(hasDecodingSucceeded, component) = Block::fromBuffer({buffer, nBytesLeft});
if (!hasDecodingSucceeded) {
NDN_THROW(Error("Error while decoding name from the database"));
}
@@ -213,8 +213,8 @@
}
sqlite3_bind_int(stmt, 1, zone.getId());
- sqlite3_bind_text(stmt, 2, key.data(), key.length(), SQLITE_STATIC);
- sqlite3_bind_blob(stmt, 3, value.wire(), value.size(), SQLITE_STATIC);
+ sqlite3_bind_text(stmt, 2, key.data(), key.length(), SQLITE_STATIC);
+ sqlite3_bind_blob(stmt, 3, value.data(), value.size(), SQLITE_STATIC);
rc = sqlite3_step(stmt);
if (rc != SQLITE_DONE) {
@@ -250,8 +250,8 @@
while (sqlite3_step(stmt) == SQLITE_ROW) {
const char* key = reinterpret_cast<const char*>(sqlite3_column_text(stmt, 0));
- rtn[string(key)] = Block(static_cast<const uint8_t*>(sqlite3_column_blob(stmt, 1)),
- sqlite3_column_bytes(stmt, 1));
+ rtn[string(key)] = Block(make_span(static_cast<const uint8_t*>(sqlite3_column_blob(stmt, 1)),
+ sqlite3_column_bytes(stmt, 1)));
}
sqlite3_finalize(stmt);
@@ -364,10 +364,10 @@
sqlite3_bind_int64(stmt, 1, rrset.getZone()->getId());
saveName(rrset.getLabel(), stmt, 2);
- sqlite3_bind_blob(stmt, 3, rrset.getType().wire(), rrset.getType().size(), SQLITE_STATIC);
- sqlite3_bind_blob(stmt, 4, rrset.getVersion().wire(), rrset.getVersion().size(), SQLITE_STATIC);
+ sqlite3_bind_blob(stmt, 3, rrset.getType().data(), rrset.getType().size(), SQLITE_STATIC);
+ sqlite3_bind_blob(stmt, 4, rrset.getVersion().data(), rrset.getVersion().size(), SQLITE_STATIC);
sqlite3_bind_int64(stmt, 5, rrset.getTtl().count());
- sqlite3_bind_blob(stmt, 6, rrset.getData().wire(), rrset.getData().size(), SQLITE_STATIC);
+ sqlite3_bind_blob(stmt, 6, rrset.getData().data(), rrset.getData().size(), SQLITE_STATIC);
rc = sqlite3_step(stmt);
if (rc != SQLITE_DONE) {
@@ -405,15 +405,15 @@
sqlite3_bind_int64(stmt, 1, rrset.getZone()->getId());
saveName(rrset.getLabel(), stmt, 2);
- sqlite3_bind_blob(stmt, 3, rrset.getType().wire(), rrset.getType().size(), SQLITE_STATIC);
+ sqlite3_bind_blob(stmt, 3, rrset.getType().data(), rrset.getType().size(), SQLITE_STATIC);
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(static_cast<const uint8_t*>(sqlite3_column_blob(stmt, 2)),
- sqlite3_column_bytes(stmt, 2)));
- rrset.setData(Block(static_cast<const uint8_t*>(sqlite3_column_blob(stmt, 3)),
- sqlite3_column_bytes(stmt, 3)));
+ 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))));
}
else {
rrset.setId(0);
@@ -449,15 +449,15 @@
sqlite3_bind_int64(stmt, 1, rrset.getZone()->getId());
saveName(rrset.getLabel(), stmt, 2);
- sqlite3_bind_blob(stmt, 3, rrset.getType().wire(), rrset.getType().size(), SQLITE_STATIC);
+ sqlite3_bind_blob(stmt, 3, rrset.getType().data(), rrset.getType().size(), SQLITE_STATIC);
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(static_cast<const uint8_t*>(sqlite3_column_blob(stmt, 2)),
- sqlite3_column_bytes(stmt, 2)));
- rrset.setData(Block(static_cast<const uint8_t*>(sqlite3_column_blob(stmt, 3)),
- sqlite3_column_bytes(stmt, 3)));
+ 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))));
}
else {
rrset.setId(0);
@@ -493,13 +493,13 @@
rrset.setId(sqlite3_column_int64(stmt, 0));
rrset.setTtl(time::seconds(sqlite3_column_int64(stmt, 1)));
- rrset.setVersion(Block(static_cast<const uint8_t*>(sqlite3_column_blob(stmt, 2)),
- sqlite3_column_bytes(stmt, 2)));
- rrset.setData(Block(static_cast<const uint8_t*>(sqlite3_column_blob(stmt, 3)),
- sqlite3_column_bytes(stmt, 3)));
+ 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.setLabel(restoreName(stmt, 4));
- rrset.setType(Block(static_cast<const uint8_t*>(sqlite3_column_blob(stmt, 5)),
- sqlite3_column_bytes(stmt, 5)));
+ rrset.setType(Block(make_span(static_cast<const uint8_t*>(sqlite3_column_blob(stmt, 5)),
+ sqlite3_column_bytes(stmt, 5))));
}
sqlite3_finalize(stmt);
@@ -523,7 +523,7 @@
}
sqlite3_bind_int64(stmt, 1, zone.getId());
- sqlite3_bind_blob(stmt, 2, type.wire(), type.size(), SQLITE_STATIC);
+ sqlite3_bind_blob(stmt, 2, type.data(), type.size(), SQLITE_STATIC);
rc = sqlite3_step(stmt);
if (rc != SQLITE_DONE) {
@@ -578,8 +578,8 @@
}
sqlite3_bind_int64(stmt, 1, rrset.getTtl().count());
- sqlite3_bind_blob(stmt, 2, rrset.getVersion().wire(), rrset.getVersion().size(), SQLITE_STATIC);
- sqlite3_bind_blob(stmt, 3, rrset.getData().wire(), rrset.getData().size(), SQLITE_STATIC);
+ sqlite3_bind_blob(stmt, 2, rrset.getVersion().data(), rrset.getVersion().size(), SQLITE_STATIC);
+ sqlite3_bind_blob(stmt, 3, rrset.getData().data(), rrset.getData().size(), SQLITE_STATIC);
sqlite3_bind_int64(stmt, 4, rrset.getId());
sqlite3_step(stmt);
diff --git a/src/daemon/rrset-factory.cpp b/src/daemon/rrset-factory.cpp
index cded8e0..eed7ad0 100644
--- a/src/daemon/rrset-factory.cpp
+++ b/src/daemon/rrset-factory.cpp
@@ -60,7 +60,7 @@
RrsetFactory::onlyCheckZone()
{
if (m_checked) {
- return ;
+ return;
}
m_checked = true;
@@ -71,7 +71,6 @@
}
}
-
std::pair<Rrset, Name>
RrsetFactory::generateBaseRrset(const Name& label,
const name::Component& type,
@@ -158,10 +157,9 @@
std::tie(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.c_str(),
- item.size()));
+ rrs.push_back(makeBinaryBlock(ndns::tlv::RrData, item.data(), item.size()));
}
Data data(name);
@@ -274,24 +272,23 @@
}
template<encoding::Tag TAG>
-inline size_t
-RrsetFactory::wireEncode(EncodingImpl<TAG>& block, const std::vector<Block>& rrs) const
+size_t
+RrsetFactory::wireEncode(EncodingImpl<TAG>& encoder, const std::vector<Block>& rrs) const
{
// Content :: = CONTENT-TYPE TLV-LENGTH
// Block*
size_t totalLength = 0;
for (auto iter = rrs.rbegin(); iter != rrs.rend(); ++iter) {
- totalLength += block.prependBlock(*iter);
+ totalLength += prependBlock(encoder, *iter);
}
- totalLength += block.prependVarNumber(totalLength);
- totalLength += block.prependVarNumber(::ndn::tlv::Content);
-
+ totalLength += encoder.prependVarNumber(totalLength);
+ totalLength += encoder.prependVarNumber(ndn::tlv::Content);
return totalLength;
}
-const Block
+Block
RrsetFactory::wireEncode(const std::vector<Block>& rrs) const
{
EncodingEstimator estimator;
@@ -315,6 +312,5 @@
return txts;
}
-
} // namespace ndns
} // namespace ndn
diff --git a/src/daemon/rrset-factory.hpp b/src/daemon/rrset-factory.hpp
index bffb093..0daa27f 100644
--- a/src/daemon/rrset-factory.hpp
+++ b/src/daemon/rrset-factory.hpp
@@ -106,18 +106,17 @@
matchCertificate(const Name& certName, const Name& identity);
template<encoding::Tag TAG>
- inline size_t
- wireEncode(EncodingImpl<TAG>& block, const std::vector<Block>& rrs) const;
+ size_t
+ wireEncode(EncodingImpl<TAG>& encoder, const std::vector<Block>& rrs) const;
- const Block
+ Block
wireEncode(const std::vector<Block>& rrs) const;
void
sign(Data& data);
void
- setContentType(Data& data, NdnsContentType contentType,
- const time::seconds& ttl);
+ setContentType(Data& data, NdnsContentType contentType, const time::seconds& ttl);
private:
KeyChain& m_keyChain;
diff --git a/src/mgmt/management-tool.cpp b/src/mgmt/management-tool.cpp
index 02299c9..9ac88cf 100644
--- a/src/mgmt/management-tool.cpp
+++ b/src/mgmt/management-tool.cpp
@@ -217,7 +217,6 @@
shared_ptr<Regex> regex = make_shared<Regex>("(<>*)<NDNS>(<>+)<CERT><>");
if (!regex->match(certName)) {
NDN_THROW(Error("Certificate name is illegal"));
- return;
}
Name zoneName = regex->expand("\\1");
@@ -482,7 +481,7 @@
os << std::endl;
}
else {
- bufferSource(rrs[i].wire(), rrs[i].size()) >> base64Encode() >> streamSink(os);
+ bufferSource(rrs[i]) >> base64Encode() >> streamSink(os);
}
}
}
@@ -504,7 +503,7 @@
// cert.printCertificate(istream);
}
else {
- bufferSource(re.getAppContent().wire(), re.getAppContent().size()) >> base64Encode() >> streamSink(os);
+ bufferSource(re.getAppContent()) >> base64Encode() >> streamSink(os);
}
}
os << std::endl;
@@ -572,7 +571,7 @@
return;
}
- bufferSource(rrset.getData().wire(), rrset.getData().size()) >> base64Encode() >> streamSink(os);
+ bufferSource(rrset.getData()) >> base64Encode() >> streamSink(os);
}
void
@@ -624,11 +623,12 @@
ManagementTool::matchCertificate(const Name& certName, const Name& identity)
{
security::Identity id = m_keyChain.getPib().getIdentity(identity);
- for (const security::Key& key: id.getKeys()) {
+ for (const security::Key& key : id.getKeys()) {
try {
key.getCertificate(certName);
return true;
- } catch (const std::exception&) {
+ }
+ catch (const std::exception&) {
}
}
return false;
diff --git a/src/ndns-enum.cpp b/src/ndns-enum.cpp
index 37a5b7d..e8351a1 100644
--- a/src/ndns-enum.cpp
+++ b/src/ndns-enum.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2014-2018, 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.
@@ -23,7 +23,7 @@
namespace ndns {
std::ostream&
-operator<<(std::ostream& os, const NdnsContentType ndnsType)
+operator<<(std::ostream& os, NdnsContentType ndnsType)
{
switch (ndnsType) {
case NDNS_BLOB:
diff --git a/src/ndns-enum.hpp b/src/ndns-enum.hpp
index eb4ea35..f7ced20 100644
--- a/src/ndns-enum.hpp
+++ b/src/ndns-enum.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2014-2018, 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.
@@ -27,7 +27,7 @@
namespace ndns {
/**
- * @brief contentType of response
+ * @brief ContentType of response
*/
enum NdnsContentType {
NDNS_BLOB = ndn::tlv::ContentType_Blob,
@@ -41,10 +41,10 @@
};
std::ostream&
-operator<<(std::ostream& os, const NdnsContentType contentType);
+operator<<(std::ostream& os, NdnsContentType contentType);
/**
- * @brief define Return code of Update's Response
+ * @brief Return code of Update response
*/
enum UpdateReturnCode {
UPDATE_OK = 0, ///< Update succeeds
diff --git a/src/util/cert-helper.cpp b/src/util/cert-helper.cpp
index ae33e00..3e52f21 100644
--- a/src/util/cert-helper.cpp
+++ b/src/util/cert-helper.cpp
@@ -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.
@@ -108,7 +108,7 @@
certificate.setFreshnessPeriod(time::hours(1));
// set content
- certificate.setContent(key.getPublicKey().data(), key.getPublicKey().size());
+ certificate.setContent(key.getPublicKey());
// set signature-info
// to overcome the round-up issue in ndn-cxx setPeriod (notBefore is round up to the the next whole second)
diff --git a/src/util/util.cpp b/src/util/util.cpp
index 8466733..d576311 100644
--- a/src/util/util.cpp
+++ b/src/util/util.cpp
@@ -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.
@@ -47,7 +47,7 @@
else if (str == "link")
return NDNS_LINK;
else if (str == "key")
- return NDNS_LINK;
+ return NDNS_KEY;
else
return NDNS_UNKNOWN;
}
@@ -61,7 +61,7 @@
const Block& block = data.wireEncode();
if (!isPretty) {
- bufferSource(block.wire(), block.size()) >> base64Encode() >> streamSink(os);
+ bufferSource(block) >> base64Encode() >> streamSink(os);
}
else {
os << "Name: " << data.getName() << std::endl;
@@ -69,7 +69,7 @@
if (kl) {
os << "KeyLocator: " << kl->getName() << std::endl;
}
- bufferSource(block.wire(), block.size()) >> base64Encode() >> streamSink(os);
+ bufferSource(block) >> base64Encode() >> streamSink(os);
os << std::endl;
}
}