Commit 01d06c2d authored by Ronan's avatar Ronan

fix(Settings): save correctly turn credentials

parent ff2c34ef
......@@ -138,9 +138,16 @@ QVariantMap AccountSettingsModel::getProxyConfigDescription (const shared_ptr<li
natPolicy = proxyConfig->getCore()->createNatPolicy();
map["iceEnabled"] = natPolicy->iceEnabled();
map["turnEnabled"] = natPolicy->turnEnabled();
map["stunServer"] = Utils::coreStringToAppString(natPolicy->getStunServer());
map["turnUser"] = Utils::coreStringToAppString(natPolicy->getStunServerUsername());
shared_ptr<const linphone::AuthInfo> authInfo = proxyConfig->findAuthInfo();
const string &turnUser(natPolicy->getStunServerUsername());
const string &stunServer(natPolicy->getStunServer());
map["turnUser"] = Utils::coreStringToAppString(turnUser);
map["stunServer"] = Utils::coreStringToAppString(stunServer);
shared_ptr<const linphone::AuthInfo> authInfo = CoreManager::getInstance()->getCore()->findAuthInfo(
"", turnUser, stunServer
);
map["turnPassword"] = authInfo ? Utils::coreStringToAppString(authInfo->getPassword()) : QString("");
return map;
......@@ -233,29 +240,33 @@ bool AccountSettingsModel::addOrUpdateProxyConfig (
natPolicy = proxyConfig->getCore()->createNatPolicy();
natPolicy->enableIce(data["iceEnabled"].toBool());
natPolicy->enableStun(data["iceEnabled"].toBool());
const string turnUser(Utils::appStringToCoreString(data["turnUser"].toString()));
const string stunServer(Utils::appStringToCoreString(data["stunServer"].toString()));
natPolicy->enableTurn(data["turnEnabled"].toBool());
natPolicy->setStunServer(Utils::appStringToCoreString(data["stunServer"].toString()));
natPolicy->setStunServerUsername(Utils::appStringToCoreString(data["turnUser"].toString()));
natPolicy->setStunServerUsername(turnUser);
natPolicy->setStunServer(stunServer);
shared_ptr<const linphone::AuthInfo> authInfo = proxyConfig->findAuthInfo();
shared_ptr<linphone::Core> core = proxyConfig->getCore();
shared_ptr<linphone::Core> core(proxyConfig->getCore());
shared_ptr<const linphone::AuthInfo> authInfo(core->findAuthInfo("", turnUser, stunServer));
if (authInfo) {
shared_ptr<linphone::AuthInfo> clonedAuthInfo = authInfo->clone();
shared_ptr<linphone::AuthInfo> clonedAuthInfo(authInfo->clone());
clonedAuthInfo->setUserid(turnUser);
clonedAuthInfo->setUsername(turnUser);
clonedAuthInfo->setPassword(Utils::appStringToCoreString(data["turnPassword"].toString()));
core->removeAuthInfo(authInfo);
core->addAuthInfo(clonedAuthInfo);
} else {
authInfo = linphone::Factory::get()->createAuthInfo(
Utils::appStringToCoreString(data["turnUser"].toString()),
Utils::appStringToCoreString(data["turnUser"].toString()),
core->removeAuthInfo(authInfo);
} else
core->addAuthInfo(linphone::Factory::get()->createAuthInfo(
turnUser,
turnUser,
Utils::appStringToCoreString(data["turnPassword"].toString()),
"",
"",
""
);
core->addAuthInfo(authInfo);
}
));
return addOrUpdateProxyConfig(proxyConfig);
}
......
......@@ -799,30 +799,37 @@ void SettingsModel::setTurnUser (const QString &user) {
// -----------------------------------------------------------------------------
QString SettingsModel::getTurnPassword () const {
shared_ptr<linphone::Core> core = CoreManager::getInstance()->getCore();
shared_ptr<linphone::NatPolicy> natPolicy = core->getNatPolicy();
shared_ptr<const linphone::AuthInfo> authInfo = core->findAuthInfo(natPolicy->getStunServerUsername(), "", "");
shared_ptr<linphone::Core> core(CoreManager::getInstance()->getCore());
shared_ptr<linphone::NatPolicy> natPolicy(core->getNatPolicy());
shared_ptr<const linphone::AuthInfo> authInfo(core->findAuthInfo(
"",
natPolicy->getStunServerUsername(),
natPolicy->getStunServer()
));
return authInfo ? Utils::coreStringToAppString(authInfo->getPassword()) : QString("");
}
void SettingsModel::setTurnPassword (const QString &password) {
shared_ptr<linphone::Core> core = CoreManager::getInstance()->getCore();
shared_ptr<linphone::NatPolicy> natPolicy = core->getNatPolicy();
const string username = natPolicy->getStunServerUsername();
shared_ptr<const linphone::AuthInfo> authInfo = core->findAuthInfo(username, "", "");
shared_ptr<linphone::Core> core(CoreManager::getInstance()->getCore());
shared_ptr<linphone::NatPolicy> natPolicy(core->getNatPolicy());
const string &turnUser(natPolicy->getStunServerUsername());
shared_ptr<const linphone::AuthInfo> authInfo(core->findAuthInfo("", turnUser, natPolicy->getStunServer()));
if (authInfo) {
shared_ptr<linphone::AuthInfo> clonedAuthInfo = authInfo->clone();
shared_ptr<linphone::AuthInfo> clonedAuthInfo(authInfo->clone());
clonedAuthInfo->setPassword(Utils::appStringToCoreString(password));
core->removeAuthInfo(authInfo);
core->addAuthInfo(clonedAuthInfo);
} else {
authInfo = linphone::Factory::get()->createAuthInfo(username, username, Utils::appStringToCoreString(password), "", "", "");
core->addAuthInfo(authInfo);
}
core->removeAuthInfo(authInfo);
} else
core->addAuthInfo(linphone::Factory::get()->createAuthInfo(
turnUser,
turnUser,
Utils::appStringToCoreString(password),
"",
"",
""
));
emit turnPasswordChanged(password);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment