From ad1af38d22bcc00f93e135ddbbca6af4ddb20989 Mon Sep 17 00:00:00 2001 From: Julien Wadel Date: Tue, 7 Sep 2021 16:10:25 +0200 Subject: [PATCH] Fix authentification request when there are no proxy config related. --- .../src/components/core/CoreHandlers.cpp | 428 +++++++++--------- .../settings/AccountSettingsModel.cpp | 30 +- 2 files changed, 239 insertions(+), 219 deletions(-) diff --git a/linphone-app/src/components/core/CoreHandlers.cpp b/linphone-app/src/components/core/CoreHandlers.cpp index 7a8f979f6..7b8ebc649 100644 --- a/linphone-app/src/components/core/CoreHandlers.cpp +++ b/linphone-app/src/components/core/CoreHandlers.cpp @@ -42,7 +42,7 @@ using namespace std; // ----------------------------------------------------------------------------- CoreHandlers::CoreHandlers (CoreManager *coreManager) { - Q_UNUSED(coreManager) + Q_UNUSED(coreManager) } CoreHandlers::~CoreHandlers () { @@ -50,267 +50,273 @@ CoreHandlers::~CoreHandlers () { // ----------------------------------------------------------------------------- void CoreHandlers::onAuthenticationRequested ( - const shared_ptr & core, - const shared_ptr &authInfo, - linphone::AuthMethod method -) { - Q_UNUSED(core) - Q_UNUSED(method) - if( authInfo ) { - emit authenticationRequested(authInfo); - } + const shared_ptr & core, + const shared_ptr &authInfo, + linphone::AuthMethod method + ) { + Q_UNUSED(method) + if( authInfo ) { + auto configList = core->getProxyConfigList(); + auto config = configList.begin() ; + std::string username = authInfo->getUsername(); + std::string domain = authInfo->getDomain(); + while(config != configList.end() && ((*config)->getContact()->getUsername() != username || (*config)->getContact()->getDomain() != domain)) + ++config; + if( config != configList.end() ) + emit authenticationRequested(authInfo);// Send authentification request only if a proxy still exists + } } void CoreHandlers::onCallEncryptionChanged ( - const shared_ptr &, - const shared_ptr &call, - bool, - const string & -) { - emit callEncryptionChanged(call); + const shared_ptr &, + const shared_ptr &call, + bool, + const string & + ) { + emit callEncryptionChanged(call); } void CoreHandlers::onCallStateChanged ( - const shared_ptr &, - const shared_ptr &call, - linphone::Call::State state, - const string & -) { - emit callStateChanged(call, state); - - SettingsModel *settingsModel = CoreManager::getInstance()->getSettingsModel(); - if ( - call->getState() == linphone::Call::State::IncomingReceived && ( - !settingsModel->getAutoAnswerStatus() || - settingsModel->getAutoAnswerDelay() > 0 - ) - ) - App::getInstance()->getNotifier()->notifyReceivedCall(call); + const shared_ptr &, + const shared_ptr &call, + linphone::Call::State state, + const string & + ) { + emit callStateChanged(call, state); + + SettingsModel *settingsModel = CoreManager::getInstance()->getSettingsModel(); + if ( + call->getState() == linphone::Call::State::IncomingReceived && ( + !settingsModel->getAutoAnswerStatus() || + settingsModel->getAutoAnswerDelay() > 0 + ) + ) + App::getInstance()->getNotifier()->notifyReceivedCall(call); } void CoreHandlers::onCallStatsUpdated ( - const shared_ptr &, - const shared_ptr &call, - const shared_ptr &stats -) { - call->getData("call-model").updateStats(stats); + const shared_ptr &, + const shared_ptr &call, + const shared_ptr &stats + ) { + call->getData("call-model").updateStats(stats); } void CoreHandlers::onCallCreated(const shared_ptr &, - const shared_ptr &call) { - emit callCreated(call); + const shared_ptr &call) { + emit callCreated(call); } void CoreHandlers::onChatRoomStateChanged( - const std::shared_ptr & core, - const std::shared_ptr & chatRoom, - linphone::ChatRoom::State state -) { + const std::shared_ptr & core, + const std::shared_ptr & chatRoom, + linphone::ChatRoom::State state + ) { emit chatRoomStateChanged(chatRoom, state); } void CoreHandlers::onConfiguringStatus( - const std::shared_ptr & core, - linphone::ConfiguringState status, - const std::string & message){ - Q_UNUSED(core) - emit setLastRemoteProvisioningState(status); - if(status == linphone::ConfiguringState::Failed){ - qWarning() << "Remote provisioning has failed and was removed : "<< QString::fromStdString(message); - core->setProvisioningUri(""); - } + const std::shared_ptr & core, + linphone::ConfiguringState status, + const std::string & message){ + Q_UNUSED(core) + emit setLastRemoteProvisioningState(status); + if(status == linphone::ConfiguringState::Failed){ + qWarning() << "Remote provisioning has failed and was removed : "<< QString::fromStdString(message); + core->setProvisioningUri(""); + } } void CoreHandlers::onDtmfReceived( - const std::shared_ptr & lc, - const std::shared_ptr & call, - int dtmf) { - Q_UNUSED(lc) - Q_UNUSED(call) - CoreManager::getInstance()->getCore()->playDtmf((char)dtmf, CallModel::DtmfSoundDelay); + const std::shared_ptr & lc, + const std::shared_ptr & call, + int dtmf) { + Q_UNUSED(lc) + Q_UNUSED(call) + CoreManager::getInstance()->getCore()->playDtmf((char)dtmf, CallModel::DtmfSoundDelay); } void CoreHandlers::onGlobalStateChanged ( - const shared_ptr &core, - linphone::GlobalState gstate, - const string & message -) { - Q_UNUSED(core) - Q_UNUSED(message) - switch(gstate){ - case linphone::GlobalState::On : - qInfo() << "Core is running " << QString::fromStdString(message); - emit coreStarted(); - break; - case linphone::GlobalState::Off : - qInfo() << "Core is stopped " << QString::fromStdString(message); - emit coreStopped(); - break; - case linphone::GlobalState::Startup : // Usefull to start core iterations - qInfo() << "Core is starting " << QString::fromStdString(message); - emit coreStarting(); - break; - default:{} - } + const shared_ptr &core, + linphone::GlobalState gstate, + const string & message + ) { + Q_UNUSED(core) + Q_UNUSED(message) + switch(gstate){ + case linphone::GlobalState::On : + qInfo() << "Core is running " << QString::fromStdString(message); + emit coreStarted(); + break; + case linphone::GlobalState::Off : + qInfo() << "Core is stopped " << QString::fromStdString(message); + emit coreStopped(); + break; + case linphone::GlobalState::Startup : // Usefull to start core iterations + qInfo() << "Core is starting " << QString::fromStdString(message); + emit coreStarting(); + break; + default:{} + } } void CoreHandlers::onIsComposingReceived ( - const shared_ptr &, - const shared_ptr &room -) { - emit isComposingChanged(room); + const shared_ptr &, + const shared_ptr &room + ) { + emit isComposingChanged(room); } void CoreHandlers::onLogCollectionUploadStateChanged ( - const shared_ptr &, - linphone::Core::LogCollectionUploadState state, - const string &info -) { - emit logsUploadStateChanged(state, info); + const shared_ptr &, + linphone::Core::LogCollectionUploadState state, + const string &info + ) { + emit logsUploadStateChanged(state, info); } void CoreHandlers::onLogCollectionUploadProgressIndication ( - const shared_ptr &, - size_t, - size_t -) { - // TODO; + const shared_ptr &, + size_t, + size_t + ) { + // TODO; } void CoreHandlers::onMessageReceived ( - const shared_ptr &core, - const shared_ptr &chatRoom, - const shared_ptr &message -) { - const string contentType = message->getContentType(); - - if (contentType == "text/plain" || contentType == "application/vnd.gsma.rcs-ft-http+xml") { - emit messageReceived(message); - - // 1. Do not notify if chat is not activated. - CoreManager *coreManager = CoreManager::getInstance(); - SettingsModel *settingsModel = coreManager->getSettingsModel(); - if (!settingsModel->getChatEnabled()) - return; - - // 2. Notify with Notification popup. - const App *app = App::getInstance(); - if (!app->hasFocus() || !chatRoom->getLocalAddress()->weakEqual(coreManager->getAccountSettingsModel()->getUsedSipAddress())) - app->getNotifier()->notifyReceivedMessage(message); - - // 3. Notify with sound. - if (!settingsModel->getChatNotificationSoundEnabled()) - return; - - if ( - !app->hasFocus() || - !CoreManager::getInstance()->getTimelineListModel()->getChatRoomModel(chatRoom, false) - /* - !CoreManager::getInstance()->chatRoomModelExists( - Utils::coreStringToAppString(chatRoom->getPeerAddress()->asStringUriOnly()), - Utils::coreStringToAppString(chatRoom->getLocalAddress()->asStringUriOnly()), - chatRoom->getSecurityLevel() == linphone::ChatRoomSecurityLevel::Encrypted - || chatRoom->getSecurityLevel() == linphone::ChatRoomSecurityLevel::Safe - - )*/ - ) - core->playLocal(Utils::appStringToCoreString(settingsModel->getChatNotificationSoundPath())); - } + const shared_ptr &core, + const shared_ptr &chatRoom, + const shared_ptr &message + ) { + const string contentType = message->getContentType(); + + if (contentType == "text/plain" || contentType == "application/vnd.gsma.rcs-ft-http+xml") { + emit messageReceived(message); + + // 1. Do not notify if chat is not activated. + CoreManager *coreManager = CoreManager::getInstance(); + SettingsModel *settingsModel = coreManager->getSettingsModel(); + if (!settingsModel->getChatEnabled()) + return; + + // 2. Notify with Notification popup. + const App *app = App::getInstance(); + if (!app->hasFocus() || !chatRoom->getLocalAddress()->weakEqual(coreManager->getAccountSettingsModel()->getUsedSipAddress())) + app->getNotifier()->notifyReceivedMessage(message); + + // 3. Notify with sound. + if (!settingsModel->getChatNotificationSoundEnabled()) + return; + + if ( + !app->hasFocus() || + !CoreManager::getInstance()->getTimelineListModel()->getChatRoomModel(chatRoom, false) + /* + !CoreManager::getInstance()->chatRoomModelExists( + Utils::coreStringToAppString(chatRoom->getPeerAddress()->asStringUriOnly()), + Utils::coreStringToAppString(chatRoom->getLocalAddress()->asStringUriOnly()), + chatRoom->getSecurityLevel() == linphone::ChatRoomSecurityLevel::Encrypted + || chatRoom->getSecurityLevel() == linphone::ChatRoomSecurityLevel::Safe + + )*/ + ) + core->playLocal(Utils::appStringToCoreString(settingsModel->getChatNotificationSoundPath())); + } } void CoreHandlers::onNotifyPresenceReceivedForUriOrTel ( - const shared_ptr &, - const shared_ptr &, - const string &uriOrTel, - const shared_ptr &presenceModel -) { - emit presenceReceived(Utils::coreStringToAppString(uriOrTel), presenceModel); + const shared_ptr &, + const shared_ptr &, + const string &uriOrTel, + const shared_ptr &presenceModel + ) { + emit presenceReceived(Utils::coreStringToAppString(uriOrTel), presenceModel); } void CoreHandlers::onNotifyPresenceReceived ( - const shared_ptr &, - const shared_ptr &linphoneFriend -) { - // Ignore friend without vcard because the `contact-model` data doesn't exist. - if (linphoneFriend->getVcard() && linphoneFriend->dataExists("contact-model")) - linphoneFriend->getData("contact-model").refreshPresence(); - emit presenceStatusReceived(linphoneFriend); + const shared_ptr &, + const shared_ptr &linphoneFriend + ) { + // Ignore friend without vcard because the `contact-model` data doesn't exist. + if (linphoneFriend->getVcard() && linphoneFriend->dataExists("contact-model")) + linphoneFriend->getData("contact-model").refreshPresence(); + emit presenceStatusReceived(linphoneFriend); } void CoreHandlers::onRegistrationStateChanged ( - const shared_ptr &, - const shared_ptr &proxyConfig, - linphone::RegistrationState state, - const string & -) { - emit registrationStateChanged(proxyConfig, state); + const shared_ptr &, + const shared_ptr &proxyConfig, + linphone::RegistrationState state, + const string & + ) { + emit registrationStateChanged(proxyConfig, state); } void CoreHandlers::onTransferStateChanged ( - const shared_ptr &, - const shared_ptr &call, - linphone::Call::State state -) { - switch (state) { - case linphone::Call::State::EarlyUpdatedByRemote: - case linphone::Call::State::EarlyUpdating: - case linphone::Call::State::Idle: - case linphone::Call::State::IncomingEarlyMedia: - case linphone::Call::State::IncomingReceived: - case linphone::Call::State::OutgoingEarlyMedia: - case linphone::Call::State::OutgoingRinging: - case linphone::Call::State::Paused: - case linphone::Call::State::PausedByRemote: - case linphone::Call::State::Pausing: - case linphone::Call::State::PushIncomingReceived: - case linphone::Call::State::Referred: - case linphone::Call::State::Released: - case linphone::Call::State::Resuming: - case linphone::Call::State::StreamsRunning: - case linphone::Call::State::UpdatedByRemote: - case linphone::Call::State::Updating: - break; // Nothing. - - // 1. Init. - case linphone::Call::State::OutgoingInit: - qInfo() << QStringLiteral("Call transfer init."); - break; - - // 2. In progress. - case linphone::Call::State::OutgoingProgress: - qInfo() << QStringLiteral("Call transfer in progress."); - break; - - // 3. Done. - case linphone::Call::State::Connected: - qInfo() << QStringLiteral("Call transfer succeeded."); - emit callTransferSucceeded(call); - break; - - // 4. Error. - case linphone::Call::State::End: - case linphone::Call::State::Error: - qWarning() << QStringLiteral("Call transfer failed."); - emit callTransferFailed(call); - break; - } + const shared_ptr &, + const shared_ptr &call, + linphone::Call::State state + ) { + switch (state) { + case linphone::Call::State::EarlyUpdatedByRemote: + case linphone::Call::State::EarlyUpdating: + case linphone::Call::State::Idle: + case linphone::Call::State::IncomingEarlyMedia: + case linphone::Call::State::IncomingReceived: + case linphone::Call::State::OutgoingEarlyMedia: + case linphone::Call::State::OutgoingRinging: + case linphone::Call::State::Paused: + case linphone::Call::State::PausedByRemote: + case linphone::Call::State::Pausing: + case linphone::Call::State::PushIncomingReceived: + case linphone::Call::State::Referred: + case linphone::Call::State::Released: + case linphone::Call::State::Resuming: + case linphone::Call::State::StreamsRunning: + case linphone::Call::State::UpdatedByRemote: + case linphone::Call::State::Updating: + break; // Nothing. + + // 1. Init. + case linphone::Call::State::OutgoingInit: + qInfo() << QStringLiteral("Call transfer init."); + break; + + // 2. In progress. + case linphone::Call::State::OutgoingProgress: + qInfo() << QStringLiteral("Call transfer in progress."); + break; + + // 3. Done. + case linphone::Call::State::Connected: + qInfo() << QStringLiteral("Call transfer succeeded."); + emit callTransferSucceeded(call); + break; + + // 4. Error. + case linphone::Call::State::End: + case linphone::Call::State::Error: + qWarning() << QStringLiteral("Call transfer failed."); + emit callTransferFailed(call); + break; + } } void CoreHandlers::onVersionUpdateCheckResultReceived ( - const shared_ptr &, - linphone::VersionUpdateCheckResult result, - const string &version, - const string &url -) { - if (result == linphone::VersionUpdateCheckResult::NewVersionAvailable) - App::getInstance()->getNotifier()->notifyNewVersionAvailable( - Utils::coreStringToAppString(version), - Utils::coreStringToAppString(url) - ); + const shared_ptr &, + linphone::VersionUpdateCheckResult result, + const string &version, + const string &url + ) { + if (result == linphone::VersionUpdateCheckResult::NewVersionAvailable) + App::getInstance()->getNotifier()->notifyNewVersionAvailable( + Utils::coreStringToAppString(version), + Utils::coreStringToAppString(url) + ); } void CoreHandlers::onEcCalibrationResult( - const std::shared_ptr &, - linphone::EcCalibratorStatus status, - int delayMs - ) { - emit ecCalibrationResult(status, delayMs); + const std::shared_ptr &, + linphone::EcCalibratorStatus status, + int delayMs + ) { + emit ecCalibrationResult(status, delayMs); } diff --git a/linphone-app/src/components/settings/AccountSettingsModel.cpp b/linphone-app/src/components/settings/AccountSettingsModel.cpp index 2101f4a60..0ea4b9834 100644 --- a/linphone-app/src/components/settings/AccountSettingsModel.cpp +++ b/linphone-app/src/components/settings/AccountSettingsModel.cpp @@ -19,6 +19,7 @@ */ #include +#include #include "config.h" @@ -205,14 +206,19 @@ void AccountSettingsModel::removeProxyConfig (const shared_ptr> allProxies = coreManager->getCore()->getProxyConfigList(); - std::shared_ptr proxyAddress = proxyConfig->getIdentityAddress(); + std::shared_ptr newProxy = nullptr; + if( proxyConfig == coreManager->getCore()->getDefaultProxyConfig()){ + std::list> allProxies = coreManager->getCore()->getProxyConfigList(); + for(auto proxy : allProxies){ + if( proxy != proxyConfig ){ + newProxy = proxy; + break; + } + } + setDefaultProxyConfig(newProxy); + } coreManager->getCore()->removeProxyConfig(proxyConfig);// Remove first to avoid requesting password when deleting it - if(proxyConfig->findAuthInfo()) - coreManager->getCore()->removeAuthInfo(proxyConfig->findAuthInfo());// Remove passwords - - coreManager->getSettingsModel()->configureRlsUri(); emit accountSettingsUpdated(); } @@ -446,8 +452,16 @@ void AccountSettingsModel::handleRegistrationStateChanged ( ) { Q_UNUSED(proxy) Q_UNUSED(state) - shared_ptr core = CoreManager::getInstance()->getCore(); - shared_ptr defaultProxyConfig = core->getDefaultProxyConfig(); + auto coreManager = CoreManager::getInstance(); + shared_ptr defaultProxyConfig = coreManager->getCore()->getDefaultProxyConfig(); + if( state == linphone::RegistrationState::Cleared){ + auto authInfo = proxy->findAuthInfo(); + if(authInfo) + QTimer::singleShot(60000, [authInfo](){// 60s is just to be sure. proxy_update remove deleted proxy only after 32s + CoreManager::getInstance()->getCore()->removeAuthInfo(authInfo); + }); + coreManager->getSettingsModel()->configureRlsUri(); + } if(defaultProxyConfig == proxy) emit defaultRegistrationChanged(); emit accountSettingsUpdated();