122 lines
3.7 KiB
C++
122 lines
3.7 KiB
C++
/*
|
|
Copyright© 2021 John Sennesael
|
|
|
|
UsenetSearch is free software: you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
(at your option) any later version.
|
|
|
|
UsenetSearch is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with UsenetSearch. If not, see <https://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#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::cout << "UsenetSearch - usenet search indexer" << std::endl;
|
|
std::cout << "Copyright© 2021 John Sennesael" << std::endl << std::endl;
|
|
|
|
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())
|
|
);
|
|
|
|
// BEGIN TEMPORARY TEST CODE
|
|
/*
|
|
const auto list = client.List();
|
|
db.UpdateNewsgroupList(list);
|
|
std::cout << "Number of newsgroups in newsgroup list (saved): "
|
|
<< list.size() << std::endl;
|
|
|
|
const auto listLoaded = db.LoadNewsgroupList();
|
|
std::cout << "Number of newsgroups in newsgroup list (loaded): "
|
|
<< listLoaded->size() << std::endl;
|
|
*/
|
|
const auto articles = client.ListGroup(L"comp.os.os2.comm");
|
|
std::cout << "Saving " << articles->size() << " articles." << std::endl;
|
|
db.UpdateArticleList(L"comp.os.os2.comm", *articles);
|
|
|
|
const auto loadedArticles = db.LoadArticleList(L"comp.os.os2.comm");
|
|
std::cout << "Loaded " << loadedArticles->size() << " artices." << std::endl;
|
|
|
|
// END TEMPORARY TEST CODE
|
|
|
|
}
|
|
catch (const usenetsearch::UsenetSearchException& e)
|
|
{
|
|
std::cerr << e.what() << std::endl;;
|
|
return 1;
|
|
}
|
|
return 0;
|
|
}
|