mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-03 06:35:08 -04:00
Merge pull request #937 from csoler/v0.6-ImprovedNoGUI
V0.6 improved no gui
This commit is contained in:
commit
98b0585ba4
11 changed files with 602 additions and 421 deletions
|
@ -14,6 +14,8 @@
|
|||
|
||||
#include "GetPluginInterfaces.h"
|
||||
|
||||
//#define DEBUG_CONTROL_MODULE 1
|
||||
|
||||
namespace resource_api{
|
||||
|
||||
RsControlModule::RsControlModule(int argc, char **argv, StateTokenServer* sts, ApiServer *apiserver, bool full_control):
|
||||
|
@ -61,6 +63,9 @@ bool RsControlModule::processShouldExit()
|
|||
|
||||
bool RsControlModule::askForPassword(const std::string &title, const std::string &key_details, bool prev_is_bad, std::string &password, bool& cancelled)
|
||||
{
|
||||
#ifdef DEBUG_CONTROL_MODULE
|
||||
std::cerr << "RsControlModule::askForPassword(): current passwd is \"" << mPassword << "\"" << std::endl;
|
||||
#endif
|
||||
cancelled = false ;
|
||||
{
|
||||
RS_STACK_MUTEX(mDataMtx); // ********** LOCKED **********
|
||||
|
@ -114,7 +119,9 @@ bool RsControlModule::askForPassword(const std::string &title, const std::string
|
|||
|
||||
void RsControlModule::run()
|
||||
{
|
||||
#ifdef DEBUG_CONTROL_MODULE
|
||||
std::cerr << "RsControlModule: initialising libretroshare..." << std::endl;
|
||||
#endif
|
||||
|
||||
RsInit::InitRsConfig();
|
||||
int initResult = RsInit::InitRetroShare(argc, argv, true);
|
||||
|
@ -125,11 +132,11 @@ void RsControlModule::run()
|
|||
std::stringstream ss;
|
||||
switch (initResult) {
|
||||
case RS_INIT_AUTH_FAILED:
|
||||
ss << "RsInit::InitRetroShare AuthGPG::InitAuth failed" << std::endl;
|
||||
ss << "RsControlModule::run() AuthGPG::InitAuth failed" << std::endl;
|
||||
break;
|
||||
default:
|
||||
/* Unexpected return code */
|
||||
ss << "RsInit::InitRetroShare unexpected return code " << initResult << std::endl;
|
||||
ss << "ControlModule::run() unexpected return code " << initResult << std::endl;
|
||||
break;
|
||||
}
|
||||
// FATAL ERROR, we can't recover from this. Just send the message to the user.
|
||||
|
@ -141,33 +148,57 @@ void RsControlModule::run()
|
|||
RsControl::earlyInitNotificationSystem();
|
||||
rsNotify->registerNotifyClient(this);
|
||||
|
||||
#ifdef DEBUG_CONTROL_MODULE
|
||||
std::cerr << "RsControlModule::run() Entering login wait loop." << std::endl;
|
||||
#endif
|
||||
bool login_ok = false;
|
||||
while(!login_ok)
|
||||
{
|
||||
#ifdef DEBUG_CONTROL_MODULE
|
||||
std::cerr << "RsControlModule::run() reseting passwd." << std::endl;
|
||||
#endif
|
||||
{
|
||||
RsStackMutex stack(mDataMtx); // ********** LOCKED **********
|
||||
mPassword = "";
|
||||
}
|
||||
|
||||
// skip account selection if autologin is available
|
||||
if(initResult != RS_INIT_HAVE_ACCOUNT)
|
||||
setRunState(WAITING_ACCOUNT_SELECT);
|
||||
bool wait_for_account_select = (initResult != RS_INIT_HAVE_ACCOUNT);
|
||||
|
||||
// wait for login request
|
||||
bool auto_login = false;
|
||||
bool wait_for_account_select = (initResult != RS_INIT_HAVE_ACCOUNT);
|
||||
|
||||
if(wait_for_account_select)
|
||||
{
|
||||
#ifdef DEBUG_CONTROL_MODULE
|
||||
std::cerr << "RsControlModule::run() wait_for_account_select=true => setting run state to WAITING_ACCOUNT_SELECT." << std::endl;
|
||||
#endif
|
||||
setRunState(WAITING_ACCOUNT_SELECT);
|
||||
}
|
||||
|
||||
while(wait_for_account_select && !processShouldExit())
|
||||
{
|
||||
usleep(5*1000);
|
||||
#ifdef DEBUG_CONTROL_MODULE
|
||||
std::cerr << "RsControlModule::run() while(wait_for_account_select) mLoadPeerId=" << mLoadPeerId << std::endl;
|
||||
#endif
|
||||
usleep(500*1000);
|
||||
RsStackMutex stack(mDataMtx); // ********** LOCKED **********
|
||||
wait_for_account_select = mLoadPeerId.isNull();
|
||||
|
||||
if(!mLoadPeerId.isNull())
|
||||
{
|
||||
wait_for_account_select = wait_for_account_select && !RsAccounts::SelectAccount(mLoadPeerId);
|
||||
#ifdef DEBUG_CONTROL_MODULE
|
||||
std::cerr << "RsControlModule::run() mLoadPeerId != NULL, account selection result: " << !wait_for_account_select << std::endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
auto_login = mAutoLoginNextTime;
|
||||
if(!wait_for_account_select)
|
||||
{
|
||||
wait_for_account_select = !RsAccounts::SelectAccount(mLoadPeerId);
|
||||
if(wait_for_account_select)
|
||||
setRunState(WAITING_ACCOUNT_SELECT);
|
||||
}
|
||||
|
||||
//if(!wait_for_account_select)
|
||||
//{
|
||||
// if(wait_for_account_select)
|
||||
// setRunState(WAITING_ACCOUNT_SELECT);
|
||||
//}
|
||||
}
|
||||
|
||||
if(processShouldExit())
|
||||
|
@ -175,6 +206,9 @@ void RsControlModule::run()
|
|||
|
||||
bool autoLogin = (initResult == RS_INIT_HAVE_ACCOUNT) | auto_login;
|
||||
std::string lockFile;
|
||||
#ifdef DEBUG_CONTROL_MODULE
|
||||
std::cerr << "RsControlModule::run() trying to load certificate..." << std::endl;
|
||||
#endif
|
||||
int retVal = RsInit::LockAndLoadCertificates(autoLogin, lockFile);
|
||||
|
||||
std::string error_string;
|
||||
|
@ -199,16 +233,24 @@ void RsControlModule::run()
|
|||
std::cerr << "RsControlModule::run() LockAndLoadCertificates failed. Unexpected switch value: " << retVal << std::endl;
|
||||
break;
|
||||
}
|
||||
#ifdef DEBUG_CONTROL_MODULE
|
||||
std::cerr << "RsControlModule::run() Error string: \"" << error_string << "\"" << std::endl;
|
||||
#endif
|
||||
|
||||
{
|
||||
RsStackMutex stack(mDataMtx); // ********** LOCKED **********
|
||||
mLoadPeerId.clear();
|
||||
}
|
||||
}
|
||||
#ifdef DEBUG_CONTROL_MODULE
|
||||
std::cerr << "RsControlModule::run() login is ok. Starting up..." << std::endl;
|
||||
#endif
|
||||
|
||||
{
|
||||
RsStackMutex stack(mDataMtx); // ********** LOCKED **********
|
||||
mFixedPassword = mPassword;
|
||||
|
||||
std::cerr << "***Reseting mPasswd " << std::endl;
|
||||
mPassword = "";
|
||||
}
|
||||
|
||||
|
@ -331,13 +373,20 @@ void RsControlModule::handlePassword(Request &req, Response &resp)
|
|||
RsStackMutex stack(mDataMtx); // ********** LOCKED **********
|
||||
std::string passwd;
|
||||
req.mStream << makeKeyValueReference("password", passwd);
|
||||
if(passwd != "" && mWantPassword)
|
||||
if(passwd != "")// && mWantPassword)
|
||||
{
|
||||
// client sends password
|
||||
mPassword = passwd;
|
||||
mWantPassword = false;
|
||||
mStateTokenServer->replaceToken(mStateToken);
|
||||
#ifdef DEBUG_CONTROL_MODULE
|
||||
std::cerr << "RsControlModule::handlePassword(): setting mPasswd=\"" << mPassword << "\"" << std::endl;
|
||||
#endif
|
||||
}
|
||||
#ifdef DEBUG_CONTROL_MODULE
|
||||
else
|
||||
std::cerr << "RsControlModule::handlePassword(): not setting mPasswd=\"" << mPassword << "\"!!!" << std::endl;
|
||||
#endif
|
||||
|
||||
resp.mDataStream
|
||||
<< makeKeyValueReference("want_password", mWantPassword)
|
||||
|
|
|
@ -23,6 +23,8 @@ class ApiServer;
|
|||
class RsControlModule: public ResourceRouter, NotifyClient, private RsSingleJobThread
|
||||
{
|
||||
public:
|
||||
enum RunState { WAITING_INIT, FATAL_ERROR, WAITING_ACCOUNT_SELECT, WAITING_STARTUP, RUNNING_OK, RUNNING_OK_NO_FULL_CONTROL};
|
||||
|
||||
// ApiServer will be called once RS is started, to load additional api modules
|
||||
// full_control: set to true if this module should handle rsinit and login
|
||||
// set to false if rsinit is handled by the Qt gui
|
||||
|
@ -32,6 +34,9 @@ public:
|
|||
// returns true if the process should terminate
|
||||
bool processShouldExit();
|
||||
|
||||
// returns the current state of the software booting process
|
||||
RunState runState() const { return mRunState ; }
|
||||
|
||||
// from NotifyClient
|
||||
virtual bool askForPassword(const std::string &title, const std::string& key_details, bool prev_is_bad , std::string& password,bool& canceled) override;
|
||||
virtual bool askForDeferredSelfSignature(const void *data, const uint32_t len, unsigned char *sign, unsigned int *signlen,int& signature_result, std::string reason = "") override;
|
||||
|
@ -42,7 +47,6 @@ protected:
|
|||
virtual void run();
|
||||
|
||||
private:
|
||||
enum RunState { WAITING_INIT, FATAL_ERROR, WAITING_ACCOUNT_SELECT, WAITING_STARTUP, RUNNING_OK, RUNNING_OK_NO_FULL_CONTROL};
|
||||
void handleRunState(Request& req, Response& resp);
|
||||
void handleIdentities(Request& req, Response& resp);
|
||||
void handleLocations(Request& req, Response& resp);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue