From 7545efc8d39c761ebcb71fa85cd99525a2cf87d6 Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Fri, 4 May 2018 08:38:34 -0400 Subject: [PATCH] fix tools, use std::unique_ptr --- contrib/backends/nntpchan-daemon/Makefile | 8 +++++--- .../backends/nntpchan-daemon/daemon/main.cpp | 19 ++++++++++++++----- .../nntpchan-daemon/tools/authtool.cpp | 15 +++++++-------- 3 files changed, 26 insertions(+), 16 deletions(-) diff --git a/contrib/backends/nntpchan-daemon/Makefile b/contrib/backends/nntpchan-daemon/Makefile index 3f61ae4..f20d477 100644 --- a/contrib/backends/nntpchan-daemon/Makefile +++ b/contrib/backends/nntpchan-daemon/Makefile @@ -51,7 +51,7 @@ EXE = $(REPO)/nntpd all: build -build: $(EXE) $(TOOLS) +build: $(EXE) tools $(MUSTACHE_LIB): $(MUSTACHE_OBJ) $(AR) -r $(MUSTACHE_LIB) $(MUSTACHE_OBJ) @@ -62,8 +62,10 @@ $(NNTPCHAN_LIB): $(NNTPCHAN_OBJ) $(EXE): $(LIBS) $(CXX) $(CXXFLAGS) $(DAEMON_SRC)/main.cpp $(LIBS) $(LD_FLAGS) -o $(EXE) -$(TOOLS): $(TOOL_SRC) $(LIBS) - $(CXX) $(CXXFLAGS) $< $(LIBS) $(LD_FLAGS) -o $@ +tools: $(TOOLS) + +$(TOOLS): $(LIBS) + $(CXX) $(CXXFLAGS) $@.cpp $(LIBS) $(LD_FLAGS) -o $@ build-test: $(LIBS) $(CXX) -o $(TEST) $(CXXFLAGS) test.cpp $(LIBS) $(LD_FLAGS) diff --git a/contrib/backends/nntpchan-daemon/daemon/main.cpp b/contrib/backends/nntpchan-daemon/daemon/main.cpp index a362b33..92e71e8 100644 --- a/contrib/backends/nntpchan-daemon/daemon/main.cpp +++ b/contrib/backends/nntpchan-daemon/daemon/main.cpp @@ -21,9 +21,9 @@ int main(int argc, char *argv[]) nntpchan::Crypto crypto; - nntpchan::ev::Loop * loop = nntpchan::NewMainLoop(); + std::unique_ptr loop(nntpchan::NewMainLoop()); - nntpchan::NNTPServer * nntp = new nntpchan::NNTPServer(loop); + std::unique_ptr nntp = std::make_unique(loop.get()); std::string fname(argv[1]); @@ -114,8 +114,14 @@ int main(int argc, char *argv[]) std::cerr << "max_pages invalid value '" << frontconf["max_pages"] << "'" << std::endl; return 1; } - nntp->SetFrontend(new nntpchan::StaticFileFrontend(nntpchan::CreateTemplateEngine(frontconf["template_dialect"]), - frontconf["template_dir"], frontconf["out_dir"], maxPages)); + auto & dialect = frontconf["template_dialect"]; + auto templateEngine = nntpchan::CreateTemplateEngine(dialect); + if(templateEngine == nullptr) + { + std::cerr << "invalid template dialect '" << dialect << "'" << std::endl; + return 1; + } + nntp->SetFrontend(new nntpchan::StaticFileFrontend(templateEngine, frontconf["template_dir"], frontconf["out_dir"], maxPages)); } else { @@ -123,6 +129,10 @@ int main(int argc, char *argv[]) return 1; } } + else + { + std::cerr << "no frontend configured, running without generating markup" << std::endl; + } auto &a = nntpconf["bind"]; @@ -145,7 +155,6 @@ int main(int argc, char *argv[]) loop->Run(); std::cerr << "Exiting" << std::endl; - delete loop; } else { diff --git a/contrib/backends/nntpchan-daemon/tools/authtool.cpp b/contrib/backends/nntpchan-daemon/tools/authtool.cpp index 7d7fe16..b1aa3df 100644 --- a/contrib/backends/nntpchan-daemon/tools/authtool.cpp +++ b/contrib/backends/nntpchan-daemon/tools/authtool.cpp @@ -1,5 +1,5 @@ -#include "base64.hpp" -#include "crypto.hpp" +#include +#include #include #include @@ -12,8 +12,6 @@ static void print_help(const std::string &exename) std::cout << "usage: " << exename << " [help|gen|check]" << std::endl; } -static void print_long_help() {} - static void gen_passwd(const std::string &username, const std::string &passwd) { std::array random; @@ -52,12 +50,12 @@ int main(int argc, char *argv[]) if (argc == 1) { print_help(argv[0]); - return 1; + return 0; } std::string cmd(argv[1]); if (cmd == "help") { - print_long_help(); + print_help(argv[0]); return 0; } if (cmd == "gen") @@ -70,7 +68,7 @@ int main(int argc, char *argv[]) else { std::cout << "usage: " << argv[0] << " gen username password" << std::endl; - return 1; + return 0; } } if (cmd == "check") @@ -79,12 +77,14 @@ int main(int argc, char *argv[]) std::cout << "credential: "; if (!std::getline(std::cin, cred)) { + std::cout << "read error" << std::endl; return 1; } std::string passwd; std::cout << "password: "; if (!std::getline(std::cin, passwd)) { + std::cout << "read error" << std::endl; return 1; } if (check_cred(cred, passwd)) @@ -95,7 +95,6 @@ int main(int argc, char *argv[]) std::cout << "bad login" << std::endl; return 1; } - print_help(argv[0]); return 1; }