Fix retroshare-service Android build

Cleanup retroshare-service and build options
This commit is contained in:
Gioacchino Mazzurco 2019-09-10 17:10:26 +02:00
parent 4f4b3bfcdb
commit 06840b86f5
No known key found for this signature in database
GPG Key ID: A1FBCA3872E87051
3 changed files with 231 additions and 110 deletions

View File

@ -38,7 +38,7 @@
#include <vector>
#include <retroshare/rstypes.h>
struct RsLoginHelper;
class RsLoginHelper;
/**
* Pointer to global instance of RsLoginHelper

View File

@ -1,6 +1,6 @@
/*
* RetroShare Service
* Copyright (C) 2016-2018 Gioacchino Mazzurco <gio@eigenlab.org>
* Copyright (C) 2016-2019 Gioacchino Mazzurco <gio@eigenlab.org>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
@ -25,7 +25,7 @@
#include "jsonapi/jsonapi.h"
#endif
CrashStackTrace gCrashStackTrace;
static CrashStackTrace gCrashStackTrace;
#include <cmath>
#include <csignal>
@ -43,22 +43,44 @@ CrashStackTrace gCrashStackTrace;
#include "retroshare/rsinit.h"
#include "retroshare/rsiface.h"
#include "util/rsdebug.h"
#ifdef RS_SERVICE_TERMINAL_LOGIN
class RsServiceNotify: public NotifyClient
{
public:
RsServiceNotify(){}
virtual ~RsServiceNotify() {}
RsServiceNotify() = default;
virtual ~RsServiceNotify() = default;
virtual bool askForPassword(const std::string& title, const std::string& question, bool prev_is_bad, std::string& password,bool& cancel)
virtual bool askForPassword(
const std::string& title, const std::string& question,
bool /*prev_is_bad*/, std::string& password, bool& cancel )
{
std::string question1=title + "\nPlease enter your PGP password for key:\n " + question + " :";
std::string question1 = title +
"\nPlease enter your PGP password for key:\n " +
question + " :";
password = RsUtil::rs_getpass(question1.c_str()) ;
cancel = false ;
return !password.empty();
}
};
#endif // def RS_SERVICE_TERMINAL_LOGIN
#ifdef __ANDROID__
void signalHandler(int /*signal*/) { QCoreApplication::exit(0); }
#else
static std::atomic<bool> keepRunning(true);
static int receivedSignal = 0;
void signalHandler(int signal)
{
if(RsControl::instance()->isReady())
RsControl::instance()->rsGlobalShutDown();
receivedSignal = signal;
keepRunning = false;
}
#endif // def __ANDROID__
int main(int argc, char* argv[])
@ -66,21 +88,21 @@ int main(int argc, char* argv[])
#ifdef __ANDROID__
AndroidStdIOCatcher dbg; (void) dbg;
QAndroidService app(argc, argv);
#endif // def __ANDROID__
signal(SIGINT, QCoreApplication::exit);
signal(SIGTERM, QCoreApplication::exit);
signal(SIGINT, signalHandler);
signal(SIGTERM, signalHandler);
#ifdef SIGBREAK
signal(SIGBREAK, QCoreApplication::exit);
signal(SIGBREAK, signalHandler);
#endif // ifdef SIGBREAK
#endif // def __ANDROID__
std::cerr << "+================================================================+" << std::endl;
std::cerr << "| o---o o |" << std::endl;
std::cerr << "| \\ / - Retroshare Service - / \\ |" << std::endl;
std::cerr << "| o o---o |" << std::endl;
std::cerr << "+================================================================+" << std::endl;
std::cerr << std::endl;
RsInfo() <<
"+================================================================+\n"
"| o---o o |\n"
"| \\ / - Retroshare Service - / \\ |\n"
"| o o---o |\n"
"+================================================================+"
<< std::endl << std::endl;
RsInit::InitRsConfig();
RsControl::earlyInitNotificationSystem();
@ -88,8 +110,8 @@ int main(int argc, char* argv[])
#ifdef __APPLE__
// TODO: is this still needed with argstream?
/* HACK to avoid stupid OSX Finder behaviour
* remove the commandline arguments - if we detect we are launched from Finder,
* and we have the unparsable "-psn_0_12332" option.
* remove the commandline arguments - if we detect we are launched from
* Finder, and we have the unparsable "-psn_0_12332" option.
* this is okay, as you cannot pass commandline arguments via Finder anyway
*/
if ((argc >= 2) && (0 == strncmp(argv[1], "-psn", 4))) argc = 1;
@ -99,95 +121,136 @@ int main(int argc, char* argv[])
RsConfigOptions conf;
argstream as(argc,argv);
as >> option('s',"stderr" ,conf.outStderr ,"output to stderr instead of log file." )
>> option('u',"udp" ,conf.udpListenerOnly ,"Only listen to UDP." )
>> parameter('c',"base-dir" ,conf.optBaseDir ,"directory", "Set base directory." ,false)
>> parameter('l',"log-file" ,conf.logfname ,"logfile" ,"Set Log filename." ,false)
>> parameter('d',"debug-level" ,conf.debugLevel ,"level" ,"Set debug level." ,false)
>> parameter('i',"ip-address" ,conf.forcedInetAddress,"nnn.nnn.nnn.nnn", "Force IP address to use (if cannot be detected)." ,false)
>> parameter('o',"opmode" ,conf.opModeStr ,"opmode" ,"Set Operating mode (Full, NoTurtle, Gaming, Minimal)." ,false)
>> parameter('p',"port" ,conf.forcedPort ,"port", "Set listenning port to use." ,false)
>> parameter('U',"user-id" ,prefUserString ,"ID", "[node Id] Selected account to use and asks for passphrase. Use \"-U list\" in order to list available accounts.",false);
as >> option( 's', "stderr", conf.outStderr,
"output to stderr instead of log file." )
>> option( 'u',"udp", conf.udpListenerOnly,
"Only listen to UDP." )
>> parameter( 'c',"base-dir", conf.optBaseDir, "directory",
"Set base directory.", false )
>> parameter( 'l', "log-file", conf.logfname, "logfile",
"Set Log filename.", false )
>> parameter( 'd', "debug-level", conf.debugLevel, "level",
"Set debug level.", false )
>> parameter( 'i', "ip-address", conf.forcedInetAddress, "IP",
"Force IP address to use (if cannot be detected).", false )
>> parameter( 'o', "opmode", conf.opModeStr, "opmode",
"Set Operating mode (Full, NoTurtle, Gaming, Minimal).",
false )
>> parameter( 'p', "port", conf.forcedPort, "port",
"Set listenning port to use.", false );
#ifdef RS_SERVICE_TERMINAL_LOGIN
as >> parameter( 'U', "user-id", prefUserString, "ID",
"[node Id] Selected account to use and asks for passphrase"
". Use \"-U list\" in order to list available accounts.",
false );
#endif // RS_SERVICE_TERMINAL_LOGIN
#ifdef RS_JSONAPI
as >> parameter('J', "jsonApiPort", conf.jsonApiPort, "jsonApiPort", "Enable JSON API on the specified port", false )
>> parameter('P', "jsonApiBindAddress", conf.jsonApiBindAddress, "jsonApiBindAddress", "JSON API Bind Address.", false);
#endif // ifdef RS_JSONAPI
as >> parameter( 'J', "jsonApiPort", conf.jsonApiPort, "TCP Port",
"Enable JSON API on the specified port", false )
>> parameter( 'P', "jsonApiBindAddress", conf.jsonApiBindAddress,
"TCP bind address", "JSON API Bind Address default "
"127.0.0.1.", false );
#endif // def RS_JSONAPI
#if defined(RS_JSONAPI) && defined(RS_WEBUI) \
&& defined(RS_SERVICE_TERMINAL_WEBUI_PASSWORD)
bool askWebUiPassword = false;
as >> option( 'W', "webui-password", askWebUiPassword,
"Ask WebUI password on the console." );
#endif /* defined(RS_JSONAPI) && defined(RS_WEBUI) \
&& defined(RS_SERVICE_TERMINAL_WEBUI_PASSWORD) */
#ifdef LOCALNET_TESTING
as >> parameter('R',"restrict-port" ,portRestrictions ,"port1-port2","Apply port restriction" ,false);
as >> parameter( 'R', "restrict-port" , portRestrictions, "port1-port2",
"Apply port restriction", false);
#endif // ifdef LOCALNET_TESTING
#ifdef RS_AUTOLOGIN
as >> option('a',"auto-login" ,conf.autoLogin ,"AutoLogin (Windows Only) + StartMinimised");
as >> option( 'a', "auto-login", conf.autoLogin,
"enable auto-login." );
#endif // ifdef RS_AUTOLOGIN
as >> help( 'h', "help", "Display this Help" );
as.defaultErrorHandling(true, true);
#if defined(RS_JSONAPI) && defined(RS_WEBUI) \
&& defined(RS_SERVICE_TERMINAL_WEBUI_PASSWORD)
std::string webui_pass1 = "Y";
if(!prefUserString.empty())
if(askWebUiPassword)
{
std::string webui_pass2 = "N";
for(;;)
while(keepRunning)
{
webui_pass1 = RsUtil::rs_getpass("Please register a password for the web interface: ");
webui_pass2 = RsUtil::rs_getpass("Please enter the same password again : ");
webui_pass1 = RsUtil::rs_getpass(
"Please register a password for the web interface: " );
webui_pass2 = RsUtil::rs_getpass(
"Please enter the same password again : " );
if(webui_pass1 != webui_pass2)
{
std::cerr << "Passwords do not match!" << std::endl;
std::cout << "Passwords do not match!" << std::endl;
continue;
}
if(webui_pass1.empty())
{
std::cerr << "Password cannot be empty!" << std::endl;
std::cout << "Password cannot be empty!" << std::endl;
continue;
}
break;
}
}
#endif /* defined(RS_JSONAPI) && defined(RS_WEBUI)
&& defined(RS_SERVICE_TERMINAL_WEBUI_PASSWORD) */
conf.main_executable_path = argv[0];
if(RS_INIT_OK != RsInit::InitRetroShare(conf))
int initResult = RsInit::InitRetroShare(conf);
if(initResult != RS_INIT_OK)
{
std::cerr << "Could not properly init Retroshare core." << std::endl;
return 1;
RsErr() << "Retroshare core initalization failed with: " << initResult
<< std::endl;
return -initResult;
}
// choose alternative account.
if(prefUserString != "")
#ifdef RS_SERVICE_TERMINAL_LOGIN
if(!prefUserString.empty()) // Login from terminal requested
{
if(prefUserString == "list")
{
std::cerr << "Available accounts:" << std::endl;
std::cout << std::endl << std::endl
<< "Available accounts:" << std::endl;
std::vector<RsLoginHelper::Location> locations;
rsLoginHelper->getLocations(locations);
int account_number_size = (int)ceil(log(locations.size())/log(10.0f)) ;
int accountCountDigits = static_cast<int>(
ceil(log(locations.size())/log(10.0)) );
for( uint32_t i=0; i<locations.size(); ++i )
std::cout << "[" << std::setw(account_number_size) << std::setfill('0')
<< i+1 << "] " << locations[i].mLocationId << " (" << locations[i].mPgpId << "): " << locations[i].mPgpName
<< " \t (" << locations[i].mLocationName << ")" << std::endl;
std::cout << "[" << std::setw(accountCountDigits)
<< std::setfill('0') << i+1 << "] "
<< locations[i].mLocationId << " ("
<< locations[i].mPgpId << "): "
<< locations[i].mPgpName
<< " \t (" << locations[i].mLocationName << ")"
<< std::endl;
int nacc=0;
while(nacc < 1 || nacc >= locations.size())
uint32_t nacc = 0;
while(keepRunning && (nacc < 1 || nacc >= locations.size()))
{
std::cout << "Please enter account number: ";
std::cout.flush();
std::string str;
std::getline(std::cin, str);
nacc = atoi(str.c_str())-1;
std::string inputStr;
std::getline(std::cin, inputStr);
if(nacc >= 0 && nacc < locations.size())
nacc = static_cast<uint32_t>(atoi(inputStr.c_str())-1);
if(nacc < locations.size())
{
prefUserString = locations[nacc].mLocationId.toStdString();
break;
@ -196,34 +259,51 @@ int main(int argc, char* argv[])
}
}
RsPeerId ssl_id(prefUserString);
RsPeerId ssl_id(prefUserString);
if(ssl_id.isNull())
{
std::cerr << "Invalid User location id: a hexadecimal ID is expected." << std::endl;
return 1;
RsErr() << "Invalid User location id: a hexadecimal ID is expected."
<< std::endl;
return -EINVAL;
}
RsServiceNotify* notify = new RsServiceNotify();
rsNotify->registerNotifyClient(notify);
RsInit::LoadCertificateStatus result = rsLoginHelper->attemptLogin(ssl_id,std::string()); // supply empty passwd so that it is properly asked 3 times on console
std::string lock_file_path = RsAccounts::AccountDirectory()+"/lock" ;
// supply empty passwd so that it is properly asked 3 times on console
RsInit::LoadCertificateStatus result =
rsLoginHelper->attemptLogin(ssl_id, "");
switch(result)
{
case RsInit::OK: break;
case RsInit::ERR_ALREADY_RUNNING: std::cerr << "Another RetroShare using the same profile is already running on your system. Please close "
"that instance first.\nLock file: " << RsInit::lockFilePath() << std::endl;
return 1;
case RsInit::ERR_CANT_ACQUIRE_LOCK: std::cerr << "An unexpected error occurred when Retroshare tried to acquire the single instance lock file. \nLock file: " << RsInit::lockFilePath() << std::endl;
return 1;
case RsInit::ERR_UNKNOWN:
default: std::cerr << "Cannot login. Check your passphrase." << std::endl << std::endl;
return 1;
case RsInit::ERR_ALREADY_RUNNING:
RsErr() << "Another RetroShare using the same profile is already "
"running on your system. Please close that instance "
"first." << std::endl << "Lock file: "
<< RsInit::lockFilePath() << std::endl;
return -RsInit::ERR_ALREADY_RUNNING;
case RsInit::ERR_CANT_ACQUIRE_LOCK:
RsErr() << "An unexpected error occurred when Retroshare tried to "
"acquire the single instance lock file." << std::endl
<< "Lock file: " << RsInit::lockFilePath() << std::endl;
return -RsInit::ERR_CANT_ACQUIRE_LOCK;
case RsInit::ERR_UNKNOWN: // Fall-throug
default:
RsErr() << "Cannot login. Check your passphrase." << std::endl
<< std::endl;
return -result;
}
}
#endif // def RS_SERVICE_TERMINAL_LOGIN
#if defined(RS_JSONAPI) && defined(RS_WEBUI) \
&& defined(RS_SERVICE_TERMINAL_WEBUI_PASSWORD)
if(jsonApiServer && !webui_pass1.empty())
jsonApiServer->authorizeToken("webui:"+webui_pass1);
#endif /* defined(RS_JSONAPI) && defined(RS_WEBUI) \
&& defined(RS_SERVICE_TERMINAL_WEBUI_PASSWORD) */
#ifdef __ANDROID__
rsControl->setShutdownCallback(QCoreApplication::exit);
@ -235,18 +315,12 @@ int main(int argc, char* argv[])
RsControl::instance()->rsGlobalShutDown(); } );
return app.exec();
#else
#ifdef RS_JSONAPI
if(jsonApiServer && !webui_pass1.empty())
jsonApiServer->authorizeToken("webui:"+webui_pass1);
#endif
std::atomic<bool> keepRunning(true);
#else // def __ANDROID__
rsControl->setShutdownCallback([&](int){keepRunning = false;});
while(keepRunning)
std::this_thread::sleep_for(std::chrono::seconds(2));
#endif
std::this_thread::sleep_for(std::chrono::milliseconds(500));
return 0;
#endif
}

View File

@ -1,9 +1,10 @@
################################################################################
# retroshare.pri #
# Copyright (C) 2018, Retroshare team <retroshare.team@gmailcom> #
# Copyright (C) 2004-2019, Retroshare Team <contact@retroshare.cc> #
# Copyright (C) 2016-2019, Gioacchino Mazzurco <gio@eigenlab.org> #
# #
# This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU Affero General Public License as #
# it under the terms of the GNU Lesser General Public License as #
# published by the Free Software Foundation, either version 3 of the #
# License, or (at your option) any later version. #
# #
@ -172,11 +173,26 @@ rs_deep_search:CONFIG -= no_rs_deep_search
CONFIG *= no_rs_use_native_dialogs
rs_use_native_dialogs:CONFIG -= no_rs_use_native_dialogs
# To disable broadcast discovery happend the following assignation to qmake
# To disable broadcast discovery append the following assignation to qmake
# command line "CONFIG+=no_rs_broadcast_discovery"
CONFIG *= rs_broadcast_discovery
no_rs_broadcast_discovery:CONFIG -= rs_broadcast_discovery
# To enable webui append the following assignation to qmake
# command line "CONFIG+=rs_webui"
CONFIG *= no_rs_webui
rs_webui:CONFIG -= no_rs_webui
# To enable webui append the following assignation to qmake
# command line "CONFIG+=rs_service_webui_terminal_password"
CONFIG *= no_rs_service_webui_terminal_password
rs_service_webui_terminal_password:CONFIG -= no_rs_service_webui_terminal_password
# To enable retroshare-service terminal login append the following assignation
# to qmake command line "CONFIG+=rs_service_terminal_login"
CONFIG *= no_rs_service_terminal_login
rs_service_terminal_login:CONFIG -= no_rs_service_terminal_login
# Specify host precompiled jsonapi-generator path, appending the following
# assignation to qmake command line
# 'JSONAPI_GENERATOR_EXE=/myBuildDir/jsonapi-generator'. Required for JSON API
@ -432,9 +448,9 @@ gxsdistsync:DEFINES *= RS_USE_GXS_DISTANT_SYNC
wikipoos:DEFINES *= RS_USE_WIKI
rs_gxs:DEFINES *= RS_ENABLE_GXS
rs_gxs_send_all:DEFINES *= RS_GXS_SEND_ALL
libresapilocalserver:DEFINES *= LIBRESAPI_LOCAL_SERVER
libresapi_settings:DEFINES *= LIBRESAPI_SETTINGS
libresapihttpserver:DEFINES *= ENABLE_WEBUI
rs_webui:DEFINES *= RS_WEBUI
rs_service_webui_terminal_password:DEFINES *= RS_SERVICE_TERMINAL_WEBUI_PASSWORD
rs_service_terminal_login:DEFINES *= RS_SERVICE_TERMINAL_LOGIN
sqlcipher {
DEFINES -= NO_SQLCIPHER
@ -447,7 +463,7 @@ no_sqlcipher {
rs_autologin {
DEFINES *= RS_AUTOLOGIN
RS_AUTOLOGIN_WARNING_MSG = \
RS_AUTOLOGIN_WARNING_MSG = QMAKE: \
You have enabled RetroShare auto-login, this is discouraged. The usage \
of auto-login on some linux distributions may allow someone having \
access to your session to steal the SSL keys of your node location and \
@ -470,7 +486,7 @@ no_rs_deprecatedwarning {
QMAKE_CXXFLAGS += -Wno-deprecated
QMAKE_CXXFLAGS += -Wno-deprecated-declarations
DEFINES *= RS_NO_WARN_DEPRECATED
message("QMAKE: You have disabled deprecated warnings.")
warning("QMAKE: You have disabled deprecated warnings.")
}
no_rs_cppwarning {
@ -478,7 +494,7 @@ no_rs_cppwarning {
QMAKE_CXXFLAGS += -Wno-inconsistent-missing-override
DEFINES *= RS_NO_WARN_CPP
message("QMAKE: You have disabled C preprocessor warnings.")
warning("QMAKE: You have disabled C preprocessor warnings.")
}
rs_gxs_trans {
@ -495,7 +511,7 @@ bitdht {
}
direct_chat {
warning("You have enabled RetroShare direct chat which is deprecated!")
warning("QMAKE: You have enabled RetroShare direct chat which is deprecated!")
DEFINES *= RS_DIRECT_CHAT
}
@ -515,6 +531,37 @@ to contain the path to an host executable jsonapi-generator")
DEFINES *= RS_JSONAPI
}
libresapilocalserver {
warning("QMAKE: you have enabled libresapilocalserver which is deprecated")
DEFINES *= LIBRESAPI_LOCAL_SERVER
}
libresapi_settings {
warning("QMAKE: you have enabled libresapi_settings which is deprecated")
DEFINES *= LIBRESAPI_SETTINGS
}
libresapihttpserver {
warning("QMAKE: you have enabled libresapihttpserver which is deprecated")
DEFINES *= ENABLE_WEBUI
}
retroshare_nogui {
warning("QMAKE: you have enabled retroshare_nogui which is deprecated")
}
retroshare_android_service {
warning("QMAKE: you have enabled retroshare_android_service which is deprecated")
}
retroshare_android_notify_service {
warning("QMAKE: you have enabled retroshare_android_notify_service which is deprecated")
}
retroshare_qml_app {
warning("QMAKE: you have enabled retroshare_qml_app which is deprecated")
}
rs_deep_search {
DEFINES *= RS_DEEP_SEARCH