started cleaning the mess with rsAccounts: only exposed useful functionality of rsAccount beyond a static class and removed all references to rsAccounts in the code

This commit is contained in:
csoler 2018-07-24 23:47:32 +02:00
parent e2bb3aef1b
commit 0f758902cd
No known key found for this signature in database
GPG key ID: 7BCA522266C0804C
19 changed files with 279 additions and 214 deletions

View file

@ -431,26 +431,10 @@ int RsInit::InitRetroShare(int argc, char **argv, bool /* strictCheck */)
AuthSSL::AuthSSLInit();
AuthSSL::getAuthSSL() -> InitAuth(NULL, NULL, NULL, "");
rsAccounts = new RsAccountsDetail();
int error_code ;
// first check config directories, and set bootstrap values.
if(!rsAccounts->setupBaseDirectory(opt_base_dir))
return RS_INIT_BASE_DIR_ERROR ;
// Setup PGP stuff.
std::string pgp_dir = rsAccounts->PathPGPDirectory();
if(!RsDirUtil::checkCreateDirectory(pgp_dir))
throw std::runtime_error("Cannot create pgp directory " + pgp_dir) ;
AuthGPG::init( pgp_dir + "/retroshare_public_keyring.gpg",
pgp_dir + "/retroshare_secret_keyring.gpg",
pgp_dir + "/retroshare_trustdb.gpg",
pgp_dir + "/lock");
// load Accounts.
if (!rsAccounts->loadAccounts())
return RS_INIT_NO_KEYRING ;
if(!RsAccounts::init(opt_base_dir,error_code))
return error_code ;
// choose alternative account.
if(prefUserString != "")
@ -464,7 +448,7 @@ int RsInit::InitRetroShare(int argc, char **argv, bool /* strictCheck */)
return RS_INIT_AUTH_FAILED ;
}
if(rsAccounts->selectId(ssl_id))
if(RsAccounts::SelectAccount(ssl_id))
{
std::cerr << "Auto-selectng account ID " << ssl_id << std::endl;
return RS_INIT_HAVE_ACCOUNT;
@ -474,7 +458,7 @@ int RsInit::InitRetroShare(int argc, char **argv, bool /* strictCheck */)
#ifdef RS_AUTOLOGIN
/* check that we have selected someone */
RsPeerId preferredId;
bool existingUser = rsAccounts->getPreferredAccountId(preferredId);
bool existingUser = RsAccounts::GetPreferredAccountId(preferredId);
if (existingUser)
{
@ -550,44 +534,43 @@ bool RsInit::LoadPassword(const std::string& inPwd)
*/
int RsInit::LockAndLoadCertificates(bool autoLoginNT, std::string& lockFilePath)
{
if (!rsAccounts->lockPreferredAccount())
try
{
return 3; // invalid PreferredAccount.
if (!RsAccounts::lockPreferredAccount())
throw 3; // invalid PreferredAccount.
// Logic that used to be external to RsInit...
RsPeerId accountId;
if (!RsAccounts::GetPreferredAccountId(accountId))
throw 3; // invalid PreferredAccount;
RsPgpId pgpId;
std::string pgpName, pgpEmail, location;
if(!RsAccounts::GetAccountDetails(accountId, pgpId, pgpName, pgpEmail, location))
throw 3; // invalid PreferredAccount;
if(0 == AuthGPG::getAuthGPG() -> GPGInit(pgpId))
throw 3; // PGP Error.
int retVal = LockConfigDirectory(RsAccounts::AccountDirectory(), lockFilePath);
if(retVal > 0)
throw retVal ;
if(LoadCertificates(autoLoginNT) != 1)
{
UnlockConfigDirectory();
throw 3;
}
return 0;
}
int retVal = 0;
// Logic that used to be external to RsInit...
RsPeerId accountId;
if (!rsAccounts->getPreferredAccountId(accountId))
{
retVal = 3; // invalid PreferredAccount;
}
RsPgpId pgpId;
std::string pgpName, pgpEmail, location;
if (retVal == 0 && !rsAccounts->getAccountDetails(accountId, pgpId, pgpName, pgpEmail, location))
retVal = 3; // invalid PreferredAccount;
if (retVal == 0 && !rsAccounts->SelectPGPAccount(pgpId))
retVal = 3; // PGP Error.
if(retVal == 0)
retVal = LockConfigDirectory(rsAccounts->PathAccountDirectory(), lockFilePath);
if(retVal == 0 && LoadCertificates(autoLoginNT) != 1)
{
UnlockConfigDirectory();
retVal = 3;
}
if(retVal != 0)
{
rsAccounts->unlockPreferredAccount();
}
return retVal;
catch(int retVal)
{
RsAccounts::unlockPreferredAccount();
return retVal ;
}
}
@ -603,20 +586,20 @@ int RsInit::LockAndLoadCertificates(bool autoLoginNT, std::string& lockFilePath
int RsInit::LoadCertificates(bool autoLoginNT)
{
RsPeerId preferredId;
if (!rsAccounts->getPreferredAccountId(preferredId))
if (!RsAccounts::GetPreferredAccountId(preferredId))
{
std::cerr << "No Account Selected" << std::endl;
return 0;
}
if (rsAccounts->PathCertFile() == "")
if (RsAccounts::AccountPathCertFile() == "")
{
std::cerr << "RetroShare needs a certificate" << std::endl;
return 0;
}
if (rsAccounts->PathKeyFile() == "")
if (RsAccounts::AccountPathKeyFile() == "")
{
std::cerr << "RetroShare needs a key" << std::endl;
return 0;
@ -638,9 +621,10 @@ int RsInit::LoadCertificates(bool autoLoginNT)
}
}
std::cerr << "rsAccounts->PathKeyFile() : " << rsAccounts->PathKeyFile() << std::endl;
std::cerr << "rsAccounts->PathKeyFile() : " << RsAccounts::AccountPathKeyFile() << std::endl;
if(0 == AuthSSL::getAuthSSL() -> InitAuth(rsAccounts->PathCertFile().c_str(), rsAccounts->PathKeyFile().c_str(), rsInitConfig->passwd.c_str(), rsAccounts->LocationName()))
if(0 == AuthSSL::getAuthSSL() -> InitAuth(RsAccounts::AccountPathCertFile().c_str(), RsAccounts::AccountPathKeyFile().c_str(), rsInitConfig->passwd.c_str(),
RsAccounts::AccountLocationName()))
{
std::cerr << "SSL Auth Failed!";
return 0 ;
@ -665,7 +649,7 @@ int RsInit::LoadCertificates(bool autoLoginNT)
rsInitConfig->gxs_passwd = rsInitConfig->passwd;
rsInitConfig->passwd = "";
rsAccounts->storePreferredAccount();
RsAccounts::storeSelectedAccount();
return 1;
}
@ -909,7 +893,7 @@ int RsServer::StartupRetroShare()
std::cerr << "set the debugging to crashMode." << std::endl;
if ((!rsInitConfig->haveLogFile) && (!rsInitConfig->outStderr))
{
std::string crashfile = rsAccounts->PathAccountDirectory();
std::string crashfile = RsAccounts::AccountDirectory();
crashfile += "/" + configLogFileName;
setDebugCrashMode(crashfile.c_str());
}
@ -921,7 +905,7 @@ int RsServer::StartupRetroShare()
}
/* check account directory */
if (!rsAccounts->checkAccountDirectory())
if (!RsAccounts::checkCreateAccountDirectory())
{
std::cerr << "RsServer::StartupRetroShare() - Fatal Error....." << std::endl;
std::cerr << "checkAccount failed!" << std::endl;
@ -933,8 +917,8 @@ int RsServer::StartupRetroShare()
// Load up Certificates, and Old Configuration (if present)
std::cerr << "Load up Certificates, and Old Configuration (if present)." << std::endl;
std::string emergencySaveDir = rsAccounts->PathAccountDirectory();
std::string emergencyPartialsDir = rsAccounts->PathAccountDirectory();
std::string emergencySaveDir = RsAccounts::AccountDirectory();
std::string emergencyPartialsDir = RsAccounts::AccountDirectory();
if (emergencySaveDir != "")
{
emergencySaveDir += "/";
@ -948,13 +932,15 @@ int RsServer::StartupRetroShare()
/**************************************************************************/
std::cerr << "Load Configuration" << std::endl;
mConfigMgr = new p3ConfigMgr(rsAccounts->PathAccountDirectory());
mConfigMgr = new p3ConfigMgr(RsAccounts::AccountDirectory());
mGeneralConfig = new p3GeneralConfig();
// Get configuration options from rsAccounts.
bool isHiddenNode = false;
bool isFirstTimeRun = false;
rsAccounts->getAccountOptions(isHiddenNode, isFirstTimeRun);
bool isTorAuto = false;
RsAccounts::getCurrentAccountOptions(isHiddenNode,isTorAuto, isFirstTimeRun);
/**************************************************************************/
/* setup classes / structures */
@ -1032,12 +1018,12 @@ int RsServer::StartupRetroShare()
#define BITDHT_FILTERED_IP_FILENAME "bdfilter.txt"
std::string bootstrapfile = rsAccounts->PathAccountDirectory();
std::string bootstrapfile = RsAccounts::AccountDirectory();
if (bootstrapfile != "")
bootstrapfile += "/";
bootstrapfile += BITDHT_BOOTSTRAP_FILENAME;
std::string filteredipfile = rsAccounts->PathAccountDirectory();
std::string filteredipfile = RsAccounts::AccountDirectory();
if (filteredipfile != "")
filteredipfile += "/";
filteredipfile += BITDHT_FILTERED_IP_FILENAME;
@ -1077,7 +1063,7 @@ int RsServer::StartupRetroShare()
bdbootRF.close();
}
#else
std::string installfile = rsAccounts->PathDataDirectory();
std::string installfile = RsAccounts::systemDataDirectory();
installfile += "/";
installfile += BITDHT_BOOTSTRAP_FILENAME;
@ -1208,7 +1194,7 @@ int RsServer::StartupRetroShare()
/****** New Ft Server **** !!! */
ftServer *ftserver = new ftServer(mPeerMgr, serviceCtrl);
ftserver->setConfigDirectory(rsAccounts->PathAccountDirectory());
ftserver->setConfigDirectory(RsAccounts::AccountDirectory());
ftserver->SetupFtServer() ;
@ -1229,7 +1215,7 @@ int RsServer::StartupRetroShare()
#if !defined(WINDOWS_SYS) && defined(PLUGIN_DIR)
plugins_directories.push_back(std::string(PLUGIN_DIR)) ;
#endif
std::string extensions_dir = rsAccounts->PathBaseDirectory() + "/extensions6/" ;
std::string extensions_dir = RsAccounts::ConfigDirectory() + "/extensions6/" ;
plugins_directories.push_back(extensions_dir) ;
if(!RsDirUtil::checkCreateDirectory(extensions_dir))
@ -1272,7 +1258,7 @@ int RsServer::StartupRetroShare()
#ifdef RS_ENABLE_GXS
std::string currGxsDir = rsAccounts->PathAccountDirectory() + "/gxs";
std::string currGxsDir = RsAccounts::AccountDirectory() + "/gxs";
RsDirUtil::checkCreateDirectory(currGxsDir);
RsNxsNetMgr* nxsMgr = new RsNxsNetMgrImpl(serviceCtrl);