86 lines
2.3 KiB
C++
86 lines
2.3 KiB
C++
#include <iostream>
|
|
#include <memory>
|
|
|
|
#include "usenetsearch/Configuration.h"
|
|
#include "usenetsearch/Database.h"
|
|
#include "usenetsearch/Except.h"
|
|
#include "usenetsearch/StringUtils.h"
|
|
#include "usenetsearch/UsenetClient.h"
|
|
|
|
using usenetsearch::StringStartsWith;
|
|
|
|
void Usage(const std::string& programName)
|
|
{
|
|
std::cout << programName;
|
|
std::cout << "\t";
|
|
std::cout << "[-c <config filename>] ";
|
|
std::cout << "[-h] " << std::endl << std::endl;
|
|
std::cout << "-c <file>\tSets configuration file to use" << std::endl;
|
|
std::cout << "-h\tShow help (this text)." << std::endl;
|
|
std::cout << std::endl;
|
|
}
|
|
|
|
int main(int argc, char* argv[])
|
|
{
|
|
|
|
std::string configFile{"config.json"};
|
|
|
|
// Parse args.
|
|
for (int argn = 1; argn != argc; ++argn)
|
|
{
|
|
std::string curr_opt = argv[argn];
|
|
std::string next_opt = "";
|
|
if (argn+1 < argc) next_opt=argv[argn+1];
|
|
if (curr_opt == "-c")
|
|
{
|
|
if ((next_opt == "") or (StringStartsWith("-", next_opt)))
|
|
{
|
|
std::cerr << "Missing argument to -c option." << std::endl;
|
|
Usage(argv[0]);
|
|
return 1;
|
|
}
|
|
argn++;
|
|
configFile = argv[argn];
|
|
}
|
|
else if (curr_opt == "-h")
|
|
{
|
|
Usage(argv[0]);
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
// Read config, setup db
|
|
usenetsearch::Configuration config;
|
|
config.Open(configFile);
|
|
usenetsearch::Database db;
|
|
db.Open(config.DatabasePath());
|
|
|
|
// Start nntp client.
|
|
usenetsearch::UsenetClient client;
|
|
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> conv;
|
|
try
|
|
{
|
|
client.Connect(
|
|
config.NNTPServerHost(),
|
|
config.NNTPServerPort(),
|
|
config.NNTPServerSSL()
|
|
);
|
|
client.Authenticate(
|
|
conv.from_bytes(config.NNTPServerUser()),
|
|
conv.from_bytes(config.NNTPServerPassword())
|
|
);
|
|
|
|
// Just testing the list command for now.
|
|
const auto list = client.List();
|
|
db.UpdateNewsgroupList(list);
|
|
std::cout << "Number of newsgroups in newsgroup list: "
|
|
<< list.size() << std::endl;
|
|
}
|
|
catch (const usenetsearch::UsenetSearchException& e)
|
|
{
|
|
std::cerr << e.what() << std::endl;;
|
|
return 1;
|
|
}
|
|
return 0;
|
|
}
|