Skip to content
Snippets Groups Projects
Commit 62d39d71 authored by Kateryna Kostiuk's avatar Kateryna Kostiuk
Browse files

account: do not load accounts and configurations when autoload not enabled

Change-Id: I89e11e723ab0cc53c8e025bb9aa4a0b8322ec82c
parent ff9e9bd4
No related branches found
No related tags found
No related merge requests found
......@@ -143,6 +143,8 @@ bool Manager::isIOSExtension = {false};
bool Manager::syncOnRegister = {true};
bool Manager::autoLoad = {true};
static void
copy_over(const std::filesystem::path& srcPath, const std::filesystem::path& destPath)
{
......@@ -818,11 +820,9 @@ Manager::init(const std::filesystem::path& config_file, libjami::InitFlag flags)
// So only create the SipLink once
pimpl_->sipLink_ = std::make_unique<SIPVoIPLink>();
check_rename(fileutils::get_cache_dir(PACKAGE_OLD),
fileutils::get_cache_dir());
check_rename(fileutils::get_cache_dir(PACKAGE_OLD), fileutils::get_cache_dir());
check_rename(fileutils::get_data_dir(PACKAGE_OLD), fileutils::get_data_dir());
check_rename(fileutils::get_config_dir(PACKAGE_OLD),
fileutils::get_config_dir());
check_rename(fileutils::get_config_dir(PACKAGE_OLD), fileutils::get_config_dir());
pimpl_->ice_tf_ = std::make_shared<dhtnet::IceTransportFactory>(Logger::dhtLogger());
......@@ -838,28 +838,33 @@ Manager::init(const std::filesystem::path& config_file, libjami::InitFlag flags)
// manager can restart without being recreated (Unit tests)
pimpl_->finished_ = false;
try {
no_errors = pimpl_->parseConfiguration();
} catch (const YAML::Exception& e) {
JAMI_ERR("%s", e.what());
no_errors = false;
}
// always back up last error-free configuration
if (no_errors) {
make_backup(pimpl_->path_);
if (libjami::LIBJAMI_FLAG_NO_AUTOLOAD & flags) {
autoLoad = false;
JAMI_DBG("LIBJAMI_FLAG_NO_AUTOLOAD is set, accounts will neither be loaded nor backed up");
} else {
// restore previous configuration
JAMI_WARNING("Restoring last working configuration");
try {
// remove accounts from broken configuration
removeAccounts();
restore_backup(pimpl_->path_);
pimpl_->parseConfiguration();
no_errors = pimpl_->parseConfiguration();
} catch (const YAML::Exception& e) {
JAMI_ERROR("{}", e.what());
JAMI_WARNING("Restoring backup failed");
JAMI_ERR("%s", e.what());
no_errors = false;
}
// always back up last error-free configuration
if (no_errors) {
make_backup(pimpl_->path_);
} else {
// restore previous configuration
JAMI_WARNING("Restoring last working configuration");
try {
// remove accounts from broken configuration
removeAccounts();
restore_backup(pimpl_->path_);
pimpl_->parseConfiguration();
} catch (const YAML::Exception& e) {
JAMI_ERROR("{}", e.what());
JAMI_WARNING("Restoring backup failed");
}
}
}
......@@ -3053,21 +3058,42 @@ Manager::setAccountActive(const std::string& accountID, bool active, bool shutdo
void
Manager::loadAccountAndConversation(const std::string& accountID, const std::string& convID)
{
if (const auto a = getAccount(accountID)) {
a->enableAutoLoadConversations(false);
if (a->getRegistrationState() == RegistrationState::UNLOADED) {
a->loadConfig();
}
a->setActive(true);
if (a->isUsable())
a->doRegister();
if (auto jamiAcc = std::dynamic_pointer_cast<JamiAccount>(a)) {
// load requests before loading conversation
if (auto convModule = jamiAcc->convModule()) {
convModule->reloadRequests();
auto account = getAccount(accountID);
if (!account && !autoLoad) {
/*
With the LIBJAMI_FLAG_NO_AUTOLOAD flag active, accounts are not
automatically created during manager initialization, nor are
their configurations set or backed up. This is because account
creation triggers the initialization of the certStore. There why
account creation now occurs here in response to a received notification.
*/
auto accountBaseDir = fileutils::get_data_dir();
auto configFile = accountBaseDir / accountID / "config.yml";
try {
if (account = accountFactory.createAccount(JamiAccount::ACCOUNT_TYPE, accountID)) {
account->enableAutoLoadConversations(false);
auto configNode = YAML::LoadFile(configFile.string());
auto config = account->buildConfig();
config->unserialize(configNode);
account->setConfig(std::move(config));
}
jamiAcc->loadConversation(convID);
} catch (const std::runtime_error& e) {
JAMI_WARN("Account loading failed: %s", e.what());
return;
}
}
if (!account) {
JAMI_WARN("Could not load account %s", accountID.c_str());
return;
}
if (auto jamiAcc = std::dynamic_pointer_cast<JamiAccount>(account)) {
jamiAcc->setActive(true);
if (jamiAcc->isUsable())
jamiAcc->doRegister();
if (auto convModule = jamiAcc->convModule()) {
convModule->reloadRequests();
}
jamiAcc->loadConversation(convID);
}
}
......
......@@ -124,6 +124,8 @@ public:
static bool syncOnRegister;
static bool autoLoad;
/**
* Initialisation of thread (sound) and map.
* Init a new VoIPLink, audio codec and audio driver.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment