Archived
1
0

fix tools, use std::unique_ptr

This commit is contained in:
Jeff Becker 2018-05-04 08:38:34 -04:00
parent 7ccd554c2d
commit 7545efc8d3
No known key found for this signature in database
GPG Key ID: F357B3B42F6F9B05
3 changed files with 26 additions and 16 deletions

View File

@ -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)

View File

@ -21,9 +21,9 @@ int main(int argc, char *argv[])
nntpchan::Crypto crypto;
nntpchan::ev::Loop * loop = nntpchan::NewMainLoop();
std::unique_ptr<nntpchan::ev::Loop> loop(nntpchan::NewMainLoop());
nntpchan::NNTPServer * nntp = new nntpchan::NNTPServer(loop);
std::unique_ptr<nntpchan::NNTPServer> nntp = std::make_unique<nntpchan::NNTPServer>(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
{

View File

@ -1,5 +1,5 @@
#include "base64.hpp"
#include "crypto.hpp"
#include <nntpchan/base64.hpp>
#include <nntpchan/crypto.hpp>
#include <cassert>
#include <cstring>
@ -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<uint8_t, 8> 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;
}