26 #include <boost/algorithm/string.hpp>
39 static std::optional<std::string>
42 auto signerTag = interest.getTag<
SignerTag>();
43 if (signerTag ==
nullptr) {
47 return signerTag->get().toUri();
52 ndn::security::ValidatorConfig& validator,
54 Lsdb& lsdb,
const std::string& configFileName)
56 , m_validator(validator)
57 , m_confFileNameDynamic(configFileName)
70 ndn::mgmt::Authorization
71 PrefixUpdateProcessor::makeAuthorization()
73 return [=] (
const ndn::Name& prefix,
const ndn::Interest& interest,
74 const ndn::mgmt::ControlParametersBase* params,
75 const ndn::mgmt::AcceptContinuation& accept,
76 const ndn::mgmt::RejectContinuation& reject) {
77 m_validator.validate(interest,
78 [accept] (
const ndn::Interest& request) {
80 std::string signer = signer1.value_or(
"*");
81 NLSR_LOG_DEBUG(
"accept " << request.getName() <<
" signer=" << signer);
84 [reject] (
const ndn::Interest& request,
const ndn::security::ValidationError& error) {
87 reject(ndn::mgmt::RejectReply::STATUS403);
94 const std::string& filename)
96 m_validator.load(section, filename);
103 std::fstream fp(m_confFileNameDynamic);
104 if (!fp.good() || !fp.is_open()) {
110 if (line == prefix) {
120 std::string value =
" prefix " + prefix.toUri();
121 std::string fileString;
123 std::string trimedLine;
124 std::fstream input(m_confFileNameDynamic, input.in);
125 if (!input.good() || !input.is_open()) {
133 NLSR_LOG_ERROR(
"Prefix already exists in the configuration file");
136 while (!input.eof()) {
137 getline(input, line);
139 fileString.append(line +
"\n");
140 if (line ==
"advertising") {
141 getline(input, line);
142 fileString.append(line +
"\n" + value +
"\n");
149 NLSR_LOG_ERROR(
"Prefix doesn't exists in the configuration file");
153 while (!input.eof()) {
154 getline(input, line);
156 std::string trimLine = line;
157 boost::trim(trimLine);
158 if (trimLine != value) {
159 fileString.append(line +
"\n");
165 std::ofstream output(m_confFileNameDynamic);
166 output << fileString;
ndn::mgmt::Dispatcher & m_dispatcher
void advertiseAndInsertPrefix(const ndn::mgmt::ControlParametersBase ¶meters, const ndn::mgmt::CommandContinuation &done)
Add desired name prefix to the advertised name prefix list or insert a prefix into the FIB if paramet...
void withdrawAndRemovePrefix(const ndn::mgmt::ControlParametersBase ¶meters, const ndn::mgmt::CommandContinuation &done)
Remove desired name prefix from the advertised name prefix list or remove a prefix from the FIB if pa...
void loadValidator(ConfigSection section, const std::string &filename)
Load the validator's configuration from a section of a configuration file.
std::optional< bool > afterAdvertise(const ndn::Name &prefix) override
Save an advertised prefix to the nlsr configuration file.
PrefixUpdateProcessor(ndn::mgmt::Dispatcher &dispatcher, ndn::security::ValidatorConfig &validator, NamePrefixList &namePrefixList, Lsdb &lsdb, const std::string &configFileName)
bool addOrDeletePrefix(const ndn::Name &prefix, bool addPrefix)
Add or delete an advertise or withdrawn prefix to the nlsr configuration file.
std::optional< bool > afterWithdraw(const ndn::Name &prefix) override
Save an advertised prefix to the nlsr configuration file.
bool checkForPrefixInFile(const std::string prefix)
Check if a prefix exists in the nlsr configuration file.
Copyright (c) 2014-2018, The University of Memphis, Regents of the University of California.
#define NLSR_LOG_DEBUG(x)
#define INIT_LOGGER(name)
#define NLSR_LOG_ERROR(x)
ndn::SimpleTag< ndn::Name, 20 > SignerTag
an Interest tag to indicate command signer
static std::optional< std::string > getSignerFromTag(const ndn::Interest &interest)
obtain signer from SignerTag attached to Interest, if available