fix tools, use std::unique_ptr
This commit is contained in:
parent
7ccd554c2d
commit
7545efc8d3
@ -51,7 +51,7 @@ EXE = $(REPO)/nntpd
|
|||||||
|
|
||||||
all: build
|
all: build
|
||||||
|
|
||||||
build: $(EXE) $(TOOLS)
|
build: $(EXE) tools
|
||||||
|
|
||||||
$(MUSTACHE_LIB): $(MUSTACHE_OBJ)
|
$(MUSTACHE_LIB): $(MUSTACHE_OBJ)
|
||||||
$(AR) -r $(MUSTACHE_LIB) $(MUSTACHE_OBJ)
|
$(AR) -r $(MUSTACHE_LIB) $(MUSTACHE_OBJ)
|
||||||
@ -62,8 +62,10 @@ $(NNTPCHAN_LIB): $(NNTPCHAN_OBJ)
|
|||||||
$(EXE): $(LIBS)
|
$(EXE): $(LIBS)
|
||||||
$(CXX) $(CXXFLAGS) $(DAEMON_SRC)/main.cpp $(LIBS) $(LD_FLAGS) -o $(EXE)
|
$(CXX) $(CXXFLAGS) $(DAEMON_SRC)/main.cpp $(LIBS) $(LD_FLAGS) -o $(EXE)
|
||||||
|
|
||||||
$(TOOLS): $(TOOL_SRC) $(LIBS)
|
tools: $(TOOLS)
|
||||||
$(CXX) $(CXXFLAGS) $< $(LIBS) $(LD_FLAGS) -o $@
|
|
||||||
|
$(TOOLS): $(LIBS)
|
||||||
|
$(CXX) $(CXXFLAGS) $@.cpp $(LIBS) $(LD_FLAGS) -o $@
|
||||||
|
|
||||||
build-test: $(LIBS)
|
build-test: $(LIBS)
|
||||||
$(CXX) -o $(TEST) $(CXXFLAGS) test.cpp $(LIBS) $(LD_FLAGS)
|
$(CXX) -o $(TEST) $(CXXFLAGS) test.cpp $(LIBS) $(LD_FLAGS)
|
||||||
|
@ -21,9 +21,9 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
nntpchan::Crypto crypto;
|
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]);
|
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;
|
std::cerr << "max_pages invalid value '" << frontconf["max_pages"] << "'" << std::endl;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
nntp->SetFrontend(new nntpchan::StaticFileFrontend(nntpchan::CreateTemplateEngine(frontconf["template_dialect"]),
|
auto & dialect = frontconf["template_dialect"];
|
||||||
frontconf["template_dir"], frontconf["out_dir"], maxPages));
|
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
|
else
|
||||||
{
|
{
|
||||||
@ -123,6 +129,10 @@ int main(int argc, char *argv[])
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
std::cerr << "no frontend configured, running without generating markup" << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
auto &a = nntpconf["bind"];
|
auto &a = nntpconf["bind"];
|
||||||
|
|
||||||
@ -145,7 +155,6 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
loop->Run();
|
loop->Run();
|
||||||
std::cerr << "Exiting" << std::endl;
|
std::cerr << "Exiting" << std::endl;
|
||||||
delete loop;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#include "base64.hpp"
|
#include <nntpchan/base64.hpp>
|
||||||
#include "crypto.hpp"
|
#include <nntpchan/crypto.hpp>
|
||||||
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
@ -12,8 +12,6 @@ static void print_help(const std::string &exename)
|
|||||||
std::cout << "usage: " << exename << " [help|gen|check]" << std::endl;
|
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)
|
static void gen_passwd(const std::string &username, const std::string &passwd)
|
||||||
{
|
{
|
||||||
std::array<uint8_t, 8> random;
|
std::array<uint8_t, 8> random;
|
||||||
@ -52,12 +50,12 @@ int main(int argc, char *argv[])
|
|||||||
if (argc == 1)
|
if (argc == 1)
|
||||||
{
|
{
|
||||||
print_help(argv[0]);
|
print_help(argv[0]);
|
||||||
return 1;
|
return 0;
|
||||||
}
|
}
|
||||||
std::string cmd(argv[1]);
|
std::string cmd(argv[1]);
|
||||||
if (cmd == "help")
|
if (cmd == "help")
|
||||||
{
|
{
|
||||||
print_long_help();
|
print_help(argv[0]);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (cmd == "gen")
|
if (cmd == "gen")
|
||||||
@ -70,7 +68,7 @@ int main(int argc, char *argv[])
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
std::cout << "usage: " << argv[0] << " gen username password" << std::endl;
|
std::cout << "usage: " << argv[0] << " gen username password" << std::endl;
|
||||||
return 1;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (cmd == "check")
|
if (cmd == "check")
|
||||||
@ -79,12 +77,14 @@ int main(int argc, char *argv[])
|
|||||||
std::cout << "credential: ";
|
std::cout << "credential: ";
|
||||||
if (!std::getline(std::cin, cred))
|
if (!std::getline(std::cin, cred))
|
||||||
{
|
{
|
||||||
|
std::cout << "read error" << std::endl;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
std::string passwd;
|
std::string passwd;
|
||||||
std::cout << "password: ";
|
std::cout << "password: ";
|
||||||
if (!std::getline(std::cin, passwd))
|
if (!std::getline(std::cin, passwd))
|
||||||
{
|
{
|
||||||
|
std::cout << "read error" << std::endl;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
if (check_cred(cred, passwd))
|
if (check_cred(cred, passwd))
|
||||||
@ -95,7 +95,6 @@ int main(int argc, char *argv[])
|
|||||||
std::cout << "bad login" << std::endl;
|
std::cout << "bad login" << std::endl;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
print_help(argv[0]);
|
print_help(argv[0]);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user