challenge+tools: minor simplifications
Change-Id: I4c5446fe31969741de0fd71a589832492256950f
diff --git a/src/challenge/challenge-email.cpp b/src/challenge/challenge-email.cpp
index d6765a3..0c78b74 100644
--- a/src/challenge/challenge-email.cpp
+++ b/src/challenge/challenge-email.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2017-2024, Regents of the University of California.
+ * Copyright (c) 2017-2025, Regents of the University of California.
*
* This file is part of ndncert, a certificate management system based on NDN.
*
@@ -155,8 +155,9 @@
bool
ChallengeEmail::isValidEmailAddress(const std::string& emailAddress)
{
- const std::string pattern = R"_REGEX_((^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+.[a-zA-Z0-9\-\.]+$))_REGEX_";
- static const std::regex emailPattern(pattern);
+ static const std::regex emailPattern = [] {
+ return std::regex(R"_RE_((^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+.[a-zA-Z0-9\-\.]+$))_RE_");
+ }();
return std::regex_match(emailAddress, emailPattern);
}
@@ -168,13 +169,12 @@
command += " \"" + emailAddress + "\" \"" + secret + "\" \"" +
request.caPrefix.toUri() + "\" \"" +
request.cert.getName().toUri() + "\"";
- boost::process::child child(command);
- child.wait();
- if (child.exit_code() != 0) {
- NDN_LOG_ERROR("Email sending script " + m_sendEmailScript + " failed");
+ int ret = boost::process::system(command, boost::process::std_in < boost::process::null);
+ if (ret == 0) {
+ NDN_LOG_TRACE("Sent email to " << emailAddress);
}
else {
- NDN_LOG_TRACE("Email sending script " + m_sendEmailScript + " succeeded");
+ NDN_LOG_ERROR("Failed to send email to " << emailAddress);
}
}
diff --git a/tools/ndncert-client.cpp b/tools/ndncert-client.cpp
index 01d8fba..7f1273c 100644
--- a/tools/ndncert-client.cpp
+++ b/tools/ndncert-client.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2017-2024, Regents of the University of California.
+ * Copyright (c) 2017-2025, Regents of the University of California.
*
* This file is part of ndncert, a certificate management system based on NDN.
*
@@ -624,18 +624,19 @@
terminateSignals.add(SIGTERM);
terminateSignals.async_wait(handleSignal);
+ std::string configFilePath(NDNCERT_SYSCONFDIR "/ndncert/client.conf");
+
namespace po = boost::program_options;
- std::string configFilePath = std::string(NDNCERT_SYSCONFDIR) + "/ndncert/client.conf";
- po::options_description description("Usage: ndncert-client [-h] [-c FILE]\n");
- description.add_options()
- ("help,h", "produce help message")
- ("config-file,c", po::value<std::string>(&configFilePath), "configuration file name")
+ po::options_description optsDesc("Usage: ndncert-client [-h] [-c FILE]\n");
+ optsDesc.add_options()
+ ("help,h", "print help message and exit")
+ ("config-file,c", po::value<std::string>(&configFilePath)->default_value(configFilePath),
+ "path to configuration file")
;
- po::positional_options_description p;
po::variables_map vm;
try {
- po::store(po::command_line_parser(argc, argv).options(description).positional(p).run(), vm);
+ po::store(po::parse_command_line(argc, argv, optsDesc), vm);
po::notify(vm);
}
catch (const std::exception& e) {
@@ -644,7 +645,7 @@
}
if (vm.count("help") != 0) {
- std::cerr << description << std::endl;
+ std::cerr << optsDesc << std::endl;
return 0;
}