mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-06-21 04:44:25 -04:00
Implement JSON API HTTP Basic authentication
jsonapi-generator is now capable of generating API for headers outside retroshare/ directory jsonapi-generator do a bit of methods parameter sanity check JsonApiServer is now integrated in the rsinit hell like other services Add *::exportGPGKeyPairToString to a bunch of classes in cascade RsControl is now capable of calling back a function when retroshare is almost completely stopped, this is useful when running retroshare toghether with externally managed runloop such as QCoreApplication Expose a bunch of methods through JSON API retroshare-nogui remove some dead code and fix stopping from the RetroShare API
This commit is contained in:
parent
ac9350d375
commit
eb77f921ec
32 changed files with 816 additions and 398 deletions
|
@ -90,6 +90,7 @@ int main(int argc, char *argv[])
|
|||
RsInit::InitRsConfig();
|
||||
RsInit::InitRetroShare(argc, argv, true);
|
||||
RsControl::earlyInitNotificationSystem();
|
||||
rsControl->setShutdownCallback(QCoreApplication::exit);
|
||||
QObject::connect(
|
||||
&app, &QCoreApplication::aboutToQuit,
|
||||
[](){
|
||||
|
@ -97,71 +98,5 @@ int main(int argc, char *argv[])
|
|||
RsControl::instance()->rsGlobalShutDown(); } );
|
||||
#endif // ifdef LIBRESAPI_LOCAL_SERVER
|
||||
|
||||
#ifdef RS_JSONAPI
|
||||
uint16_t jsonApiPort = 9092;
|
||||
std::string jsonApiBindAddress = "127.0.0.1";
|
||||
|
||||
{
|
||||
QCommandLineOption jsonApiPortOpt(
|
||||
"jsonApiPort", "JSON API listening port.", "port", "9092");
|
||||
QCommandLineOption jsonApiBindAddressOpt(
|
||||
"jsonApiBindAddress", "JSON API Bind Address.",
|
||||
"IP Address", "127.0.0.1");
|
||||
|
||||
QCommandLineParser cmdParser;
|
||||
cmdParser.addHelpOption();
|
||||
cmdParser.addOption(jsonApiPortOpt);
|
||||
cmdParser.addOption(jsonApiBindAddressOpt);
|
||||
|
||||
cmdParser.parse(app.arguments());
|
||||
|
||||
if(cmdParser.isSet(jsonApiPortOpt))
|
||||
{
|
||||
QString jsonApiPortStr = cmdParser.value(jsonApiPortOpt);
|
||||
bool portOk;
|
||||
jsonApiPort = jsonApiPortStr.toUShort(&portOk);
|
||||
if(!portOk)
|
||||
{
|
||||
std::cerr << "ERROR: jsonApiPort option value must be a valid "
|
||||
<< "TCP port!" << std::endl;
|
||||
cmdParser.showHelp();
|
||||
QCoreApplication::exit(EINVAL);
|
||||
}
|
||||
}
|
||||
|
||||
if(cmdParser.isSet(jsonApiBindAddressOpt))
|
||||
{
|
||||
sockaddr_storage tmp;
|
||||
jsonApiBindAddress =
|
||||
cmdParser.value(jsonApiBindAddressOpt).toStdString();
|
||||
if(!sockaddr_storage_inet_pton(tmp, jsonApiBindAddress))
|
||||
{
|
||||
std::cerr << "ERROR: jsonApiBindAddress option value must "
|
||||
<< "be a valid IP address!" << std::endl;
|
||||
cmdParser.showHelp();
|
||||
QCoreApplication::exit(EINVAL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
JsonApiServer jas( jsonApiPort, jsonApiBindAddress,
|
||||
[](int ec) { QCoreApplication::exit(ec); } );
|
||||
jas.start();
|
||||
|
||||
{
|
||||
sockaddr_storage tmp;
|
||||
sockaddr_storage_inet_pton(tmp, jsonApiBindAddress);
|
||||
sockaddr_storage_setport(tmp, jsonApiPort);
|
||||
sockaddr_storage_ipv6_to_ipv4(tmp);
|
||||
RsUrl tmpUrl(sockaddr_storage_tostring(tmp));
|
||||
tmpUrl.setScheme("http");
|
||||
|
||||
std::cerr << "JSON API listening on "
|
||||
<< tmpUrl.toString()
|
||||
<< std::endl;
|
||||
}
|
||||
|
||||
#endif // ifdef RS_JSONAPI
|
||||
|
||||
return app.exec();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue